annotate uip/sendmail.c @ 17:76d91e545ea8 default tip

addrsbr and dtimep fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 24 Nov 2014 14:49:25 +0900
parents 441a2190cfae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
1 /* sendmail.c - */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
2 #ifndef lint
12
441a2190cfae Lion fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
3 static char Id[] = "$Id: sendmail.c,v 1.1.1.1 2005/04/18 14:46:07 kono Exp $";
0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
4 #endif
bce86c4163a3 Initial revision
kono
parents:
diff changeset
5 /*
bce86c4163a3 Initial revision
kono
parents:
diff changeset
6 ** A Sendmail fake.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
7 *
bce86c4163a3 Initial revision
kono
parents:
diff changeset
8 * Contributed by Scott Erickson <erickson@ics.uci.edu>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
9 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
10 /* Include files glommed from post.c */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
11
bce86c4163a3 Initial revision
kono
parents:
diff changeset
12 #include "../h/mh.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
13 #include "../h/addrsbr.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
14 #include "../h/aliasbr.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
15 #include "../h/dropsbr.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
16 #include "../zotnet/tws.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
17 #ifndef MMDFMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
18 #include <ctype.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
19 #include <errno.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
20 #include <setjmp.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
21 #include <stdio.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
22 #include <sys/types.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
23 #else MMDFMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
24 #include "../mts/mmdf/util.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
25 #include "../mts/mmdf/mmdf.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
26 #endif MMDFMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
27 #include "../zotnet/mts.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
28 #ifdef MHMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
29 #ifndef V7
bce86c4163a3 Initial revision
kono
parents:
diff changeset
30 #include <sys/ioctl.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
31 #endif not V7
bce86c4163a3 Initial revision
kono
parents:
diff changeset
32 #include <sys/stat.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
33 #endif MHMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
34 #ifdef SENDMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
35 #include "../mts/sendmail/smail.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
36 #undef MF
bce86c4163a3 Initial revision
kono
parents:
diff changeset
37 #endif SENDMTS
bce86c4163a3 Initial revision
kono
parents:
diff changeset
38 #include <signal.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
39 #ifdef LOCALE
bce86c4163a3 Initial revision
kono
parents:
diff changeset
40 #include <locale.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
41 #endif
bce86c4163a3 Initial revision
kono
parents:
diff changeset
42
bce86c4163a3 Initial revision
kono
parents:
diff changeset
43 char *SMTPSRVR = "smtpsrvr";
bce86c4163a3 Initial revision
kono
parents:
diff changeset
44
bce86c4163a3 Initial revision
kono
parents:
diff changeset
45 char msgfname[50]; /* name of message file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
46 char *FullName; /* sender's full name */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
47 char *from; /* sender's mail address */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
48 int verbose;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
49 int verify;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
50 int extract;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
51 int dodist;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
52 int rewritefrom;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
53 int status; /* return value from procedures */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
54 static int childid; /* id from smtp child process */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
55 TYPESIG die();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
56 time_t lclock = 0L; /* the time we started (more or less) */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
57
bce86c4163a3 Initial revision
kono
parents:
diff changeset
58
bce86c4163a3 Initial revision
kono
parents:
diff changeset
59 FILE *fp; /* file pointer for message file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
60 extern FILE *tmpfile();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
61
bce86c4163a3 Initial revision
kono
parents:
diff changeset
62 static struct swit switches[] = {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
63 #define ARPASW 0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
64 "ba", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
65 #define DAEMONSW 1
bce86c4163a3 Initial revision
kono
parents:
diff changeset
66 "bd", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
67 #define INITALSW 2
bce86c4163a3 Initial revision
kono
parents:
diff changeset
68 "bi", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
69 #define DELIVSW 3
bce86c4163a3 Initial revision
kono
parents:
diff changeset
70 "bm", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
71 #define QSUMSW 4
bce86c4163a3 Initial revision
kono
parents:
diff changeset
72 "bp", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
73 #define SMTPSW 5
bce86c4163a3 Initial revision
kono
parents:
diff changeset
74 "bs", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
75 #define ADRTSTSW 6
bce86c4163a3 Initial revision
kono
parents:
diff changeset
76 "bt", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
77 #define ADRVRFSW 7
bce86c4163a3 Initial revision
kono
parents:
diff changeset
78 "bv", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
79 #define CFGFRZSW 8
bce86c4163a3 Initial revision
kono
parents:
diff changeset
80 "bz", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
81 #define ALTCFGSW 9
bce86c4163a3 Initial revision
kono
parents:
diff changeset
82 "C", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
83 #define DBGVALSW 10
bce86c4163a3 Initial revision
kono
parents:
diff changeset
84 "d", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
85 #define FULLSW 11
bce86c4163a3 Initial revision
kono
parents:
diff changeset
86 "F", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
87 #define FROMSW 12
bce86c4163a3 Initial revision
kono
parents:
diff changeset
88 "f", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
89 #define HOPCNTSW 13
bce86c4163a3 Initial revision
kono
parents:
diff changeset
90 "h", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
91 #define MSGIDSW 14
bce86c4163a3 Initial revision
kono
parents:
diff changeset
92 "M", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
93 #define NOALISW 15
bce86c4163a3 Initial revision
kono
parents:
diff changeset
94 "n", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
95 #define QTIMESW 16
bce86c4163a3 Initial revision
kono
parents:
diff changeset
96 "q", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
97 #define OBSFRMSW 17
bce86c4163a3 Initial revision
kono
parents:
diff changeset
98 "r", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
99 #define EXTHDRSW 18
bce86c4163a3 Initial revision
kono
parents:
diff changeset
100 "t", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
101 #define VERBSW 19
bce86c4163a3 Initial revision
kono
parents:
diff changeset
102 "v", -1,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
103 #define ALTALISW 20
bce86c4163a3 Initial revision
kono
parents:
diff changeset
104 "oA", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
105 #define NOCONSW 21
bce86c4163a3 Initial revision
kono
parents:
diff changeset
106 "oc", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
107 #define DLVMODSW 22
bce86c4163a3 Initial revision
kono
parents:
diff changeset
108 "od", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
109 #define NEWALISW 23
bce86c4163a3 Initial revision
kono
parents:
diff changeset
110 "oD", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
111 #define ERRMODSW 24
bce86c4163a3 Initial revision
kono
parents:
diff changeset
112 "oe", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
113 #define TMPMODSW 25
bce86c4163a3 Initial revision
kono
parents:
diff changeset
114 "oF", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
115 #define UFROMSW 26
bce86c4163a3 Initial revision
kono
parents:
diff changeset
116 "of", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
117 #define GIDSW 27
bce86c4163a3 Initial revision
kono
parents:
diff changeset
118 "og", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
119 #define HLPFILSW 28
bce86c4163a3 Initial revision
kono
parents:
diff changeset
120 "oH", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
121 #define NODOTSW 29
bce86c4163a3 Initial revision
kono
parents:
diff changeset
122 "oi", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
123 #define LOGLEVSW 30
bce86c4163a3 Initial revision
kono
parents:
diff changeset
124 "oL", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
125 #define MEOKSW 31
bce86c4163a3 Initial revision
kono
parents:
diff changeset
126 "om", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
127 #define OLDHDRSW 32
bce86c4163a3 Initial revision
kono
parents:
diff changeset
128 "oo", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
129 #define QDIRSW 33
bce86c4163a3 Initial revision
kono
parents:
diff changeset
130 "oQ", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
131 #define RTMOUTSW 34
bce86c4163a3 Initial revision
kono
parents:
diff changeset
132 "or", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
133 #define SFILESW 35
bce86c4163a3 Initial revision
kono
parents:
diff changeset
134 "oS", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
135 #define QMSGSW 36
bce86c4163a3 Initial revision
kono
parents:
diff changeset
136 "os", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
137 #define MTMOUTSW 37
bce86c4163a3 Initial revision
kono
parents:
diff changeset
138 "oT", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
139 #define TZSW 38
bce86c4163a3 Initial revision
kono
parents:
diff changeset
140 "ot", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
141 #define UIDSW 39
bce86c4163a3 Initial revision
kono
parents:
diff changeset
142 "ou", -2,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
143
bce86c4163a3 Initial revision
kono
parents:
diff changeset
144 NULL, 0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
145 };
bce86c4163a3 Initial revision
kono
parents:
diff changeset
146
bce86c4163a3 Initial revision
kono
parents:
diff changeset
147 #if !defined(POSIX) && !defined(_POSIX_SOURCE)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
148 extern char *mktemp();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
149 #endif
bce86c4163a3 Initial revision
kono
parents:
diff changeset
150
bce86c4163a3 Initial revision
kono
parents:
diff changeset
151 static void removemsg();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
152 static int isheader(), sendfile();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
153
bce86c4163a3 Initial revision
kono
parents:
diff changeset
154 /*ARGSUSED*/
bce86c4163a3 Initial revision
kono
parents:
diff changeset
155 main (argc, argv)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
156 int argc;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
157 char **argv;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
158 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
159 register char *cp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
160 char **argp = argv + 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
161
bce86c4163a3 Initial revision
kono
parents:
diff changeset
162 #ifdef LOCALE
bce86c4163a3 Initial revision
kono
parents:
diff changeset
163 setlocale(LC_ALL, "");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
164 #endif
bce86c4163a3 Initial revision
kono
parents:
diff changeset
165 #ifdef JAPAN
bce86c4163a3 Initial revision
kono
parents:
diff changeset
166 ml_init();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
167 #endif /* JAPAN */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
168 invo_name = r1bindex (argv[0], '/');
bce86c4163a3 Initial revision
kono
parents:
diff changeset
169 mts_init(argv[0]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
170
bce86c4163a3 Initial revision
kono
parents:
diff changeset
171 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
172 (void) signal(SIGINT, die);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
173 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
174 (void) signal(SIGHUP, die);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
175 (void) signal(SIGTERM, die);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
176 (void) signal(SIGPIPE, die);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
177
bce86c4163a3 Initial revision
kono
parents:
diff changeset
178 FullName = getfullname();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
179 from = adrsprintf(NULLCP,NULLCP);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
180 (void) time (&lclock);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
181
bce86c4163a3 Initial revision
kono
parents:
diff changeset
182 while ( (cp = *argp) && *cp == '-' ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
183 argp++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
184 switch (smatch ( ++cp, switches )) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
185 case ARPASW: /* smtp on stdin */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
186 case SMTPSW: /* smtp on stdin */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
187 smtp();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
188 exit(98); /* should never happen */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
189
bce86c4163a3 Initial revision
kono
parents:
diff changeset
190 case DELIVSW: /* just send mail */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
191 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
192
bce86c4163a3 Initial revision
kono
parents:
diff changeset
193 case ADRVRFSW: /* verify mode */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
194 verify = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
195 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
196
bce86c4163a3 Initial revision
kono
parents:
diff changeset
197 case FROMSW: /* from address */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
198 case OBSFRMSW: /* obsolete -f flag */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
199 if (*(++cp) == '\0' &&
bce86c4163a3 Initial revision
kono
parents:
diff changeset
200 (!(cp = *argp++) || *cp == '-'))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
201 adios (NULLCP, "missing argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
202 /* At this point, cp points to the from name */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
203 if (rewritefrom) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
204 adios (NULLCP, "More than one \"from\" person");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
205 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
206 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
207 from = cp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
208 rewritefrom = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
209 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
210
bce86c4163a3 Initial revision
kono
parents:
diff changeset
211 case EXTHDRSW: /* read recipients from message */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
212 extract = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
213 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
214
bce86c4163a3 Initial revision
kono
parents:
diff changeset
215 case VERBSW: /* give blow-by-blow description */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
216 verbose = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
217 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
218
bce86c4163a3 Initial revision
kono
parents:
diff changeset
219 /* These switches have no args. */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
220 case QMSGSW: /* always queue the message */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
221 case DAEMONSW: /* run as a daemon & wait for SMTP */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
222 case INITALSW: /* initialize the alias database */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
223 case QSUMSW: /* print summary of mail queue */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
224 case ADRTSTSW: /* test the addresses to debug config file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
225 case CFGFRZSW: /* create the configuration freeze file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
226 case NOALISW: /* do not do aliasing */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
227 case NOCONSW: /* do not initiate immediate host connection */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
228 case NEWALISW: /* run newaliases to rebuild db */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
229 case UFROMSW: /* save UNIX-style From lines at front of msg*/
bce86c4163a3 Initial revision
kono
parents:
diff changeset
230 case NODOTSW: /* dots on line are not msg terminators */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
231 case MEOKSW: /* ok to send to me if I'm in an alias */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
232 case OLDHDRSW: /* msg may have old-style headers */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
233 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
234
bce86c4163a3 Initial revision
kono
parents:
diff changeset
235 /* These switches have string args. */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
236 case ALTALISW: /* use alternate alias file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
237 case ALTCFGSW: /* use alternate configuration file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
238 case DBGVALSW: /* set the debug value */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
239 case FULLSW: /* set full name */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
240 case MSGIDSW: /* try to deliver queued msg with msg-id */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
241 case QTIMESW: /* interval between queue passes */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
242 case DLVMODSW: /* set the delivery mode */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
243 case ERRMODSW: /* set the error mode */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
244 case TMPMODSW: /* the mode to use when creating tmp files */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
245 case HLPFILSW: /* the SMTP help file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
246 case QDIRSW: /* directory into which to queue messages */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
247 case RTMOUTSW: /* timeout on reads */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
248 case SFILESW: /* save statistics in this file */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
249 case MTMOUTSW: /* timeout on messages in the queue */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
250 case TZSW: /* set the name of the timezone */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
251 if (*(++cp) == '\0' &&
bce86c4163a3 Initial revision
kono
parents:
diff changeset
252 (!(cp = *argp++) || *cp == '-'))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
253 adios (NULLCP, "missing argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
254 /* At this point, cp points to the argument */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
255 continue; /* Ignore */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
256
bce86c4163a3 Initial revision
kono
parents:
diff changeset
257 /* These switches have numeric args. */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
258 case HOPCNTSW: /* hop count */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
259 case GIDSW: /* gid when calling mailers */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
260 case LOGLEVSW: /* the log level */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
261 case UIDSW: /* uid when calling mailers */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
262 if (*(++cp) == '\0' &&
bce86c4163a3 Initial revision
kono
parents:
diff changeset
263 (!(cp = *argp++) || *cp == '-'))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
264 adios (NULLCP, "missing argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
265 /* At this point, cp points to the numeric arg */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
266 if (!isdigit(*cp))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
267 adios (NULLCP, "non-numeric argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
268 continue; /* Ignore */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
269 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
270 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
271
bce86c4163a3 Initial revision
kono
parents:
diff changeset
272 (void) setuid(getuid());
bce86c4163a3 Initial revision
kono
parents:
diff changeset
273
bce86c4163a3 Initial revision
kono
parents:
diff changeset
274 if (verify && extract)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
275 adios (NULLCP, "mode not supported on header components");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
276
bce86c4163a3 Initial revision
kono
parents:
diff changeset
277 if (*argp == NULL && !extract)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
278 adios (NULLCP, "usage: ", sendmail, " [flags] addr...");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
279
bce86c4163a3 Initial revision
kono
parents:
diff changeset
280 strcpy (msgfname, "/tmp/sendmhXXXXXX");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
281 if ( mktemp(msgfname) == NULL )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
282 adios (msgfname, "can't create msg file ");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
283
bce86c4163a3 Initial revision
kono
parents:
diff changeset
284 if ( (fp = fopen(msgfname,"w") ) == NULL ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
285 adios (msgfname, "error opening ");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
286 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
287
bce86c4163a3 Initial revision
kono
parents:
diff changeset
288 doheader(argp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
289 if ( verify ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
290 (void) fclose(fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
291 status = doverify();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
292 removemsg();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
293 exit ( status ) ;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
294 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
295 dobody();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
296 status = sendfile();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
297 removemsg();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
298 exit ( status );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
299 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
300
bce86c4163a3 Initial revision
kono
parents:
diff changeset
301 static void removemsg()
bce86c4163a3 Initial revision
kono
parents:
diff changeset
302 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
303 if ( unlink(msgfname) != 0 )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
304 perror("unlink");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
305 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
306
bce86c4163a3 Initial revision
kono
parents:
diff changeset
307 doheader(argp)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
308 char **argp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
309 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
310 char line[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
311 int gotdate, gotfrom, gotsender, gotto;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
312
bce86c4163a3 Initial revision
kono
parents:
diff changeset
313 /* if we're not extracting the headers from the message, then we
bce86c4163a3 Initial revision
kono
parents:
diff changeset
314 * need to check to see if we need to do a "send" or a "dist".
bce86c4163a3 Initial revision
kono
parents:
diff changeset
315 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
316
bce86c4163a3 Initial revision
kono
parents:
diff changeset
317 if ( !extract ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
318 /* If we're doing a verify, just create a "To:" header. */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
319 if ( ! verify ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
320 gotdate = gotfrom = gotto = gotsender = dodist = 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
321 while (fgets (line, BUFSIZ, stdin) != NULL) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
322 if (line[0] == '\n') /* end of header */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
323 break;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
324 if ( !isheader(line) )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
325 break;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
326
bce86c4163a3 Initial revision
kono
parents:
diff changeset
327 /* if any of the following headers are present, then we
bce86c4163a3 Initial revision
kono
parents:
diff changeset
328 * want to do a dist.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
329 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
330 if ( !gotdate && uprf(line, "date") )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
331 gotdate = dodist = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
332
bce86c4163a3 Initial revision
kono
parents:
diff changeset
333 else if ( !gotto && (uprf(line, "to") || uprf(line, "cc")) )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
334 gotto = dodist = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
335
bce86c4163a3 Initial revision
kono
parents:
diff changeset
336 else if ( uprf(line, "message-id") )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
337 dodist = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
338
bce86c4163a3 Initial revision
kono
parents:
diff changeset
339 else if ( !gotsender && uprf(line, "sender") )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
340 gotsender = dodist = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
341
bce86c4163a3 Initial revision
kono
parents:
diff changeset
342 else if ( uprf ( line, "resent-" ) ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
343 dodist = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
344 (void) fputs("Prev-", fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
345 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
346
bce86c4163a3 Initial revision
kono
parents:
diff changeset
347 /* See if we are re-writing the from line */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
348 if ( uprf(line, "from") ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
349 gotfrom = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
350 if ( rewritefrom )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
351 dofrom();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
352 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
353 (void) fputs(line,fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
354 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
355 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
356 (void) fputs(line,fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
357 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
358 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
359 /* Now, generate a "to" line. The first line is easy.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
360 * Write the rest of the lines with a newline/tab so that we
bce86c4163a3 Initial revision
kono
parents:
diff changeset
361 * don't accidentally write a line that's too long to be parsed
bce86c4163a3 Initial revision
kono
parents:
diff changeset
362 * by post.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
363 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
364 (void) fprintf (fp, "%sTo: %s", (dodist ? "Resent-" : "" ), *argp++);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
365 while ( *argp )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
366 (void) fprintf ( fp, ",\n\t%s", *argp++ );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
367 (void) fputs("\n",fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
368
bce86c4163a3 Initial revision
kono
parents:
diff changeset
369 /* If we're doing a dist, we must have a "Date:" and "From:" field.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
370 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
371 if ( dodist ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
372 if ( !gotdate )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
373 (void) fprintf (fp, "Date: %s\n", dtime (&lclock));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
374 if ( !gotfrom )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
375 dofrom();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
376 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
377 #ifdef MMDFI /* sigh */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
378 if ( !gotsender )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
379 (void) fprintf (fp, "Sender: %s\n", from);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
380 #endif MMDFI
bce86c4163a3 Initial revision
kono
parents:
diff changeset
381 } else { /* we're verifying, so just pass everything through */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
382 while (fgets (line, BUFSIZ, stdin) != NULL) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
383 if (line[0] == '\n') /* end of header */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
384 break;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
385
bce86c4163a3 Initial revision
kono
parents:
diff changeset
386 if ( rewritefrom && uprf(line, "from"))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
387 dofrom();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
388 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
389 (void) fputs(line,fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
390 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
391 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
392 /* At this point, line is either a newline (end of header) or the
bce86c4163a3 Initial revision
kono
parents:
diff changeset
393 * first line of the body (poorly formatted message). If line
bce86c4163a3 Initial revision
kono
parents:
diff changeset
394 * contains a line of body from a poorly formatted message, then
bce86c4163a3 Initial revision
kono
parents:
diff changeset
395 * print a newline to separate the header correctly, then print
bce86c4163a3 Initial revision
kono
parents:
diff changeset
396 * the body line.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
397 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
398 if ( line[0] != '\n' ) /* i.e. a "body" line */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
399 (void) fputc('\n', fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
400 (void) fputs(line, fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
401 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
402
bce86c4163a3 Initial revision
kono
parents:
diff changeset
403 static int isheader(s)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
404 char *s;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
405 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
406 register char *cp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
407
bce86c4163a3 Initial revision
kono
parents:
diff changeset
408 /* If the first character is a space, assume a continuation of a header */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
409 if ( isspace(*s) )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
410 return 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
411
bce86c4163a3 Initial revision
kono
parents:
diff changeset
412 /* If there's no ':', it's not a header */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
413 if ( (cp = index(s,':')) == NULL )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
414 return 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
415
bce86c4163a3 Initial revision
kono
parents:
diff changeset
416 /* If there's a space between BOL and ':', it's not a header */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
417 while ( s < cp ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
418 if ( isspace(*s) )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
419 return 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
420 s++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
421 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
422 return 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
423 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
424
bce86c4163a3 Initial revision
kono
parents:
diff changeset
425 /* This procedure does the verify and returns the status */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
426 doverify() {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
427 char *command, buf[BUFSIZ], *bp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
428 FILE *verfp, *popen();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
429
bce86c4163a3 Initial revision
kono
parents:
diff changeset
430 /* set up the command line for post */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
431 if ( (command = (char *)malloc((strlen(postproc) +
bce86c4163a3 Initial revision
kono
parents:
diff changeset
432 strlen(" -whom -check -verbose ") +
bce86c4163a3 Initial revision
kono
parents:
diff changeset
433 strlen(msgfname) + 1 )*sizeof(char)))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
434 == NULL ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
435 perror("malloc");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
436 return NOTOK;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
437 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
438
bce86c4163a3 Initial revision
kono
parents:
diff changeset
439 (void) strcpy(command,postproc);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
440 (void) strcat(command," -whom -check ");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
441 if ( verbose )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
442 (void) strcat(command, "-verbose " );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
443 (void) strcat(command, msgfname);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
444
bce86c4163a3 Initial revision
kono
parents:
diff changeset
445 /* open up the pipe */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
446 if ( (verfp = popen(command,"r")) == NULL )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
447 return NOTOK;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
448
bce86c4163a3 Initial revision
kono
parents:
diff changeset
449 while ( fgets(buf, BUFSIZ, verfp) != NULL )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
450 /* sendmail returns:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
451 * address: result
bce86c4163a3 Initial revision
kono
parents:
diff changeset
452 * so we need to strip the extra post headers.
bce86c4163a3 Initial revision
kono
parents:
diff changeset
453 */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
454 if ( verbose ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
455 bp = buf;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
456 while (isspace(*bp))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
457 bp++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
458 if ( *bp != '-' )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
459 (void) fputs(bp,stdout);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
460 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
461
bce86c4163a3 Initial revision
kono
parents:
diff changeset
462 /* return the error status of post */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
463 return( pclose(verfp) >> 8 );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
464 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
465
bce86c4163a3 Initial revision
kono
parents:
diff changeset
466 static int sendfile()
bce86c4163a3 Initial revision
kono
parents:
diff changeset
467 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
468 char *command, buf[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
469 FILE *verfp, *popen();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
470
bce86c4163a3 Initial revision
kono
parents:
diff changeset
471 /* set up the command line for post */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
472 if ( (command = (char *)malloc((strlen(postproc) +
bce86c4163a3 Initial revision
kono
parents:
diff changeset
473 strlen(" -dist -verbose ") +
bce86c4163a3 Initial revision
kono
parents:
diff changeset
474 strlen(msgfname) + 1 )*sizeof(char)))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
475 == NULL ) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
476 perror("malloc");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
477 return NOTOK;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
478 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
479
bce86c4163a3 Initial revision
kono
parents:
diff changeset
480 (void) strcpy(command,postproc);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
481 (void) strcat(command," ");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
482 if ( verbose )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
483 (void) strcat(command, "-verbose " );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
484 if ( dodist )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
485 (void) strcat(command, "-dist " );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
486 (void) strcat(command, msgfname);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
487
bce86c4163a3 Initial revision
kono
parents:
diff changeset
488 /* open up the pipe */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
489 if ( (verfp = popen(command,"r")) == NULL )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
490 return NOTOK;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
491
bce86c4163a3 Initial revision
kono
parents:
diff changeset
492 while ( fgets(buf, BUFSIZ, verfp) != NULL )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
493 (void) fputs(buf,stdout);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
494
bce86c4163a3 Initial revision
kono
parents:
diff changeset
495 /* return the error status of post */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
496 return( pclose(verfp) >> 8 );
bce86c4163a3 Initial revision
kono
parents:
diff changeset
497 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
498
bce86c4163a3 Initial revision
kono
parents:
diff changeset
499 dofrom() {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
500 char line[128];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
501
bce86c4163a3 Initial revision
kono
parents:
diff changeset
502 if (FullName)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
503 (void) sprintf(line, "From: %s <%s>\n", FullName, from);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
504 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
505 (void) sprintf(line, "From: %s\n", from);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
506 (void) fputs(line, fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
507 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
508
bce86c4163a3 Initial revision
kono
parents:
diff changeset
509 dobody() {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
510 register int i;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
511 char buffer[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
512
bce86c4163a3 Initial revision
kono
parents:
diff changeset
513 while (!feof (stdin) && !ferror (stdin) &&
bce86c4163a3 Initial revision
kono
parents:
diff changeset
514 (i = fread (buffer, sizeof (char), sizeof (buffer), stdin)) > 0)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
515 if (fwrite (buffer, sizeof (char), i , fp) != i )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
516 adios (NULLCP, "Problem writing body");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
517
bce86c4163a3 Initial revision
kono
parents:
diff changeset
518 if (ferror (stdin))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
519 adios (NULLCP, "Problem reading body");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
520
bce86c4163a3 Initial revision
kono
parents:
diff changeset
521 if ( fclose(fp) != 0 )
bce86c4163a3 Initial revision
kono
parents:
diff changeset
522 adios (NULLCP, "problem ending submission");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
523 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
524
bce86c4163a3 Initial revision
kono
parents:
diff changeset
525 TYPESIG silentdie();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
526
bce86c4163a3 Initial revision
kono
parents:
diff changeset
527 smtp()
bce86c4163a3 Initial revision
kono
parents:
diff changeset
528 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
529 int sd,len;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
530 char buf[BUFSIZ], response[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
531
bce86c4163a3 Initial revision
kono
parents:
diff changeset
532 if ((sd = client(NULLCP, "tcp", "smtp", 0, response)) == NOTOK)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
533 adios (NULLCP, "cannot open smtp client process");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
534
bce86c4163a3 Initial revision
kono
parents:
diff changeset
535 (void) signal(SIGCHLD, silentdie);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
536
bce86c4163a3 Initial revision
kono
parents:
diff changeset
537 switch ((childid = fork())) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
538 case NOTOK:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
539 adios (NULLCP, "unable to fork smtp process");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
540
bce86c4163a3 Initial revision
kono
parents:
diff changeset
541 case OK: /* i.e. child */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
542 (void) dup2(sd,0);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
543 break;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
544
bce86c4163a3 Initial revision
kono
parents:
diff changeset
545 default: /* i.e. parent */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
546 (void) dup2(sd,1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
547 break;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
548 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
549 while ( (len = read(0, buf, BUFSIZ)) > 0)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
550 (void) write (1, buf, len);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
551
bce86c4163a3 Initial revision
kono
parents:
diff changeset
552 if (childid)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
553 (void) kill(childid, SIGHUP);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
554
bce86c4163a3 Initial revision
kono
parents:
diff changeset
555 exit(9);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
556 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
557
bce86c4163a3 Initial revision
kono
parents:
diff changeset
558 /* ARGSUSED */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
559 TYPESIG die(sig)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
560 int sig;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
561 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
562 if (fp) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
563 (void) fclose(fp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
564 (void) unlink(msgfname);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
565 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
566 if (sig != SIGHUP)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
567 (void) fprintf(stderr, "sendmail: dying from signal %d\n", sig);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
568 exit(99);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
569 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
570
bce86c4163a3 Initial revision
kono
parents:
diff changeset
571 /* ARGSUSED */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
572
bce86c4163a3 Initial revision
kono
parents:
diff changeset
573 TYPESIG silentdie(sig)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
574 int sig;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
575 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
576 pidwait (childid, OK);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
577 exit(0);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
578 }