Debianization for 1.01-2
[qmail] / sendmail.c
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 int flagh;
17 char *sender;
18
19 void main(argc,argv)
20 int argc;
21 char **argv;
22 {
23 int opt;
24 char **qiargv;
25 char **arg;
26 int i;
27
28 if (chdir(auto_qmail) == -1)
29 {
30 substdio_putsflush(subfderr,"sendmail: fatal: unable to switch to qmail home directory\n");
31 _exit(111);
32 }
33
34 flagh = 0;
35 sender = 0;
36 while ((opt = getopt(argc,argv,"vimte:f:p:o:B:F:EJx")) != opteof)
37 switch(opt)
38 {
39 case 'B': break;
40 case 't': flagh = 1; break;
41 case 'f': sender = optarg; break;
42 case 'F': if (!env_put2("MAILNAME",optarg)) nomem(); break;
43 case 'p': break; /* could generate a Received line from optarg */
44 case 'v': break;
45 case 'i': break; /* what an absurd concept */
46 case 'x': break; /* SVR4 stupidity */
47 case 'm': break; /* twisted-paper-path blindness, incompetent design */
48 case 'e': break; /* qmail has only one error mode */
49 case 'o':
50 switch(optarg[0])
51 {
52 case 'd': break; /* qmail has only one delivery mode */
53 case 'e': break; /* see 'e' above */
54 case 'i': break; /* see 'i' above */
55 case 'm': break; /* see 'm' above */
56 }
57 break;
58 case 'E': case 'J': /* Sony NEWS-OS */
59 while (argv[optind][optpos]) ++optpos; /* skip optional argument */
60 break;
61 default:
62 _exit(100);
63 }
64 argc -= optind;
65 argv += optind;
66
67 if (str_equal(optprogname,"mailq"))
68 {
69 substdio_putsflush(subfderr,"sendmail: fatal: please use qmail-qread instead\n");
70 _exit(100);
71 }
72
73 if (str_equal(optprogname,"newaliases"))
74 {
75 substdio_putsflush(subfderr,"sendmail: fatal: please use the qmsmac newaliases instead\n");
76 _exit(100);
77 }
78
79 qiargv = (char **) alloc((argc + 10) * sizeof(char *));
80 if (!qiargv) nomem();
81
82 arg = qiargv;
83 *arg++ = "/usr/sbin/qmail-inject";
84 *arg++ = (flagh ? "-H" : "-a");
85 if (sender)
86 {
87 *arg++ = "-f";
88 *arg++ = sender;
89 }
90 *arg++ = "--";
91 for (i = 0;i < argc;++i) *arg++ = argv[i];
92 *arg = 0;
93
94 execv(*qiargv,qiargv);
95
96 substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n");
97 _exit(111);
98 }