|
1 #include "sgetopt.h" |
|
2 #include "substdio.h" |
|
3 #include "subfd.h" |
|
4 #include "alloc.h" |
|
5 #include "auto_qmail.h" |
|
6 #include "exit.h" |
|
7 #include "env.h" |
|
8 #include "str.h" |
|
9 |
|
10 void nomem() |
|
11 { |
|
12 substdio_putsflush(subfderr,"sendmail: fatal: out of memory\n"); |
|
13 _exit(111); |
|
14 } |
|
15 |
|
16 void die_usage() |
|
17 { |
|
18 substdio_putsflush(subfderr,"sendmail: usage: sendmail [ -t ] [ -fsender ] [ -Fname ] [ -bp ] [ -bs ] [ arg ... ]\n"); |
|
19 _exit(100); |
|
20 } |
|
21 |
|
22 char *smtpdarg[] = { "bin/qmail-smtpd", 0 }; |
|
23 void smtpd() |
|
24 { |
|
25 if (!env_get("PROTO")) { |
|
26 if (!env_put("RELAYCLIENT=")) nomem(); |
|
27 if (!env_put("DATABYTES=0")) nomem(); |
|
28 if (!env_put("PROTO=TCP")) nomem(); |
|
29 if (!env_put("TCPLOCALIP=127.0.0.1")) nomem(); |
|
30 if (!env_put("TCPLOCALHOST=localhost")) nomem(); |
|
31 if (!env_put("TCPREMOTEIP=127.0.0.1")) nomem(); |
|
32 if (!env_put("TCPREMOTEHOST=localhost")) nomem(); |
|
33 if (!env_put("TCPREMOTEINFO=sendmail-bs")) nomem(); |
|
34 } |
|
35 execv(*smtpdarg,smtpdarg); |
|
36 substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-smtpd\n"); |
|
37 _exit(111); |
|
38 } |
|
39 |
|
40 char *qreadarg[] = { "bin/qmail-qread", 0 }; |
|
41 void mailq() |
|
42 { |
|
43 execv(*qreadarg,qreadarg); |
|
44 substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-qread\n"); |
|
45 _exit(111); |
|
46 } |
|
47 |
|
48 int flagh; |
|
49 char *sender; |
|
50 |
|
51 void main(argc,argv) |
|
52 int argc; |
|
53 char **argv; |
|
54 { |
|
55 int opt; |
|
56 char **qiargv; |
|
57 char **arg; |
|
58 int i; |
|
59 |
|
60 if (chdir(auto_qmail) == -1) { |
|
61 substdio_putsflush(subfderr,"sendmail: fatal: unable to switch to qmail home directory\n"); |
|
62 _exit(111); |
|
63 } |
|
64 |
|
65 flagh = 0; |
|
66 sender = 0; |
|
67 while ((opt = getopt(argc,argv,"vimte:f:p:o:B:F:EJxb:")) != opteof) |
|
68 switch(opt) { |
|
69 case 'B': break; |
|
70 case 't': flagh = 1; break; |
|
71 case 'f': sender = optarg; break; |
|
72 case 'F': if (!env_put2("MAILNAME",optarg)) nomem(); break; |
|
73 case 'p': break; /* could generate a Received line from optarg */ |
|
74 case 'v': break; |
|
75 case 'i': break; /* what an absurd concept */ |
|
76 case 'x': break; /* SVR4 stupidity */ |
|
77 case 'm': break; /* twisted-paper-path blindness, incompetent design */ |
|
78 case 'e': break; /* qmail has only one error mode */ |
|
79 case 'o': |
|
80 switch(optarg[0]) { |
|
81 case 'd': break; /* qmail has only one delivery mode */ |
|
82 case 'e': break; /* see 'e' above */ |
|
83 case 'i': break; /* see 'i' above */ |
|
84 case 'm': break; /* see 'm' above */ |
|
85 } |
|
86 break; |
|
87 case 'E': case 'J': /* Sony NEWS-OS */ |
|
88 while (argv[optind][optpos]) ++optpos; /* skip optional argument */ |
|
89 break; |
|
90 case 'b': |
|
91 switch(optarg[0]) { |
|
92 case 'm': break; |
|
93 case 'p': mailq(); |
|
94 case 's': smtpd(); |
|
95 default: die_usage(); |
|
96 } |
|
97 break; |
|
98 default: |
|
99 die_usage(); |
|
100 } |
|
101 argc -= optind; |
|
102 argv += optind; |
|
103 |
|
104 if (str_equal(optprogname,"mailq")) |
|
105 mailq(); |
|
106 |
|
107 if (str_equal(optprogname,"newaliases")) { |
|
108 substdio_putsflush(subfderr,"sendmail: fatal: please use fastforward/newaliases instead\n"); |
|
109 _exit(100); |
|
110 } |
|
111 |
|
112 qiargv = (char **) alloc((argc + 10) * sizeof(char *)); |
|
113 if (!qiargv) nomem(); |
|
114 |
|
115 arg = qiargv; |
|
116 *arg++ = "bin/qmail-inject"; |
|
117 *arg++ = (flagh ? "-H" : "-a"); |
|
118 if (sender) { |
|
119 *arg++ = "-f"; |
|
120 *arg++ = sender; |
|
121 } |
|
122 *arg++ = "--"; |
|
123 for (i = 0;i < argc;++i) *arg++ = argv[i]; |
|
124 *arg = 0; |
|
125 |
|
126 execv(*qiargv,qiargv); |
|
127 substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); |
|
128 _exit(111); |
|
129 } |