s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
sendmail.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "getoptb.h"
3#include "buffer.h"
4#include "alloc.h"
5#include "auto_qmail.h"
6#include "exit.h"
7#include "env.h"
8#include "str.h"
9#include "logmsg.h"
10
11#define WHO "sendmail"
12
13void nomem()
14{
15 logmsg(WHO,111,FATAL,"out of memory\n");
16}
17
19{
20 logmsg(WHO,100,USAGE,"sendmail [ -t ] [ -fsender ] [ -Fname ] [ -bp ] [ -bs ] [ arg ... ]\n");
21}
22
23char *smtpdarg[] = { "bin/qmail-smtpd", 0 };
24
25void smtpd()
26{
27 if (!env_get("PROTO")) {
28 if (!env_puts("RELAYCLIENT=")) nomem();
29 if (!env_puts("DATABYTES=0")) nomem();
30 if (!env_puts("PROTO=TCP")) nomem();
31 if (!env_puts("TCP6LOCALIP=::1")) nomem();
32 if (!env_puts("TCPLOCALIP=127.0.0.1")) nomem();
33 if (!env_puts("TCPLOCALHOST=localhost")) nomem();
34 if (!env_puts("TCPREMOTEIP=127.0.0.1")) nomem();
35 if (!env_puts("TCP6REMOTEIP=::1")) nomem();
36 if (!env_puts("TCPREMOTEHOST=localhost")) nomem();
37 if (!env_puts("TCPREMOTEINFO=sendmail-bs")) nomem();
38 }
39 execv(*smtpdarg,smtpdarg);
40 logmsg(WHO,111,FATAL,"unable to run qmail-smtpd\n");
41}
42
43char *qreadarg[] = { "bin/qmail-qread", 0 };
44void mailq()
45{
46 execv(*qreadarg,qreadarg);
47 logmsg(WHO,111,FATAL,"unable to run qmail-qread\n");
48}
49
50void do_sender(const char *s)
51{
52 char *x;
53 int n;
54 int a;
55 int i;
56
57 env_unset("QMAILNAME");
58 env_unset("MAILNAME");
59 env_unset("NAME");
60 env_unset("QMAILHOST");
61 env_unset("MAILHOST");
62
63 n = str_len(s);
64 a = str_rchr(s,'@');
65 if (a == n)
66 {
67 env_put("QMAILUSER",s);
68 return;
69 }
70 env_put("QMAILHOST",s + a + 1);
71
72 x = (char *) alloc((a + 1) * sizeof(char));
73 if (!x) nomem();
74 for (i = 0; i < a; i++)
75 x[i] = s[i];
76 x[i] = 0;
77 env_put("QMAILUSER",x);
78 alloc_free(x);
79}
80
82char *sender;
83
84int main(int argc, char **argv)
85{
86 int opt;
87 char **qiargv;
88 char **arg;
89 int i;
90
91 if (chdir(auto_qmail) == -1) {
92 buffer_putsflush(buffer_2,"sendmail: fatal: unable to switch to qmail home directory\n");
93 _exit(111);
94 }
95
96 flagh = 0;
97 sender = 0;
98 while ((opt = getopt(argc,argv,"vimte:f:p:o:B:F:EJxb:")) != opteof) {
99 switch (opt) {
100 case 'N': break; /* ignore DSN option */
101 case 'B': break;
102 case 't': flagh = 1; break;
103 case 'f': sender = optarg; break;
104 case 'F': if (!env_put("MAILNAME",optarg)) nomem(); break;
105 case 'p': break; /* could generate a Received line from optarg */
106 case 'v': break;
107 case 'i': break; /* what an absurd concept */
108 case 'x': break; /* SVR4 stupidity */
109 case 'm': break; /* twisted-paper-path blindness, incompetent design */
110 case 'e': break; /* qmail has only one error mode */
111 case 'o':
112 switch (optarg[0]) {
113 case 'd': break; /* qmail has only one delivery mode */
114 case 'e': break; /* see 'e' above */
115 case 'i': break; /* see 'i' above */
116 case 'm': break; /* see 'm' above */
117 }
118 break;
119 case 'E': case 'J': /* Sony NEWS-OS */
120 while (argv[optind][optpos]) ++optpos; /* skip optional argument */
121 break;
122 case 'b':
123 switch (optarg[0]) {
124 case 'm': break;
125 case 'p': mailq();
126 case 's': smtpd();
127 default: die_usage();
128 }
129 break;
130 default:
131 die_usage();
132 }
133 }
134 argc -= optind;
135 argv += optind;
136
137 if (str_equal(optprogname,"mailq"))
138 mailq();
139
140 if (str_equal(optprogname,"newaliases")) {
141 logmsg(WHO,100,FATAL,"please use fastforward/newaliases instead\n");
142 }
143
144 qiargv = (char **) alloc((argc + 10) * sizeof(char *));
145 if (!qiargv) nomem();
146
147 arg = qiargv;
148 *arg++ = "bin/qmail-inject";
149 *arg++ = (flagh ? "-H" : "-a");
150 if (sender) {
151 *arg++ = "-f";
152 *arg++ = sender;
154 }
155 *arg++ = "--";
156 for (i = 0; i < argc; ++i) *arg++ = argv[i];
157 *arg = 0;
158
159 execv(*qiargv,qiargv);
160 logmsg(WHO,111,FATAL,"unable to run qmail-inject\n");
161}
char auto_qmail[]
int main()
Definition: chkshsgr.c:6
void _exit()
void mailq()
Definition: sendmail.c:44
char * qreadarg[]
Definition: sendmail.c:43
void die_usage()
Definition: sendmail.c:18
void do_sender(const char *s)
Definition: sendmail.c:50
void smtpd()
Definition: sendmail.c:25
void nomem()
Definition: sendmail.c:13
char * sender
Definition: sendmail.c:82
int flagh
Definition: sendmail.c:81
#define WHO
Definition: sendmail.c:11
char * smtpdarg[]
Definition: sendmail.c:23