1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 # include "sendmail.h"
10 
11 #ifndef lint
12 #ifdef SMTP
13 static char sccsid[] = "@(#)srvrsmtp.c	6.35.1.1 (Berkeley) 03/30/93 (with SMTP)";
14 #else
15 static char sccsid[] = "@(#)srvrsmtp.c	6.35.1.1 (Berkeley) 03/30/93 (without SMTP)";
16 #endif
17 #endif /* not lint */
18 
19 # include <errno.h>
20 # include <signal.h>
21 
22 # ifdef SMTP
23 
24 /*
25 **  SMTP -- run the SMTP protocol.
26 **
27 **	Parameters:
28 **		none.
29 **
30 **	Returns:
31 **		never.
32 **
33 **	Side Effects:
34 **		Reads commands from the input channel and processes
35 **			them.
36 */
37 
38 struct cmd
39 {
40 	char	*cmdname;	/* command name */
41 	int	cmdcode;	/* internal code, see below */
42 };
43 
44 /* values for cmdcode */
45 # define CMDERROR	0	/* bad command */
46 # define CMDMAIL	1	/* mail -- designate sender */
47 # define CMDRCPT	2	/* rcpt -- designate recipient */
48 # define CMDDATA	3	/* data -- send message text */
49 # define CMDRSET	4	/* rset -- reset state */
50 # define CMDVRFY	5	/* vrfy -- verify address */
51 # define CMDEXPN	6	/* expn -- expand address */
52 # define CMDNOOP	7	/* noop -- do nothing */
53 # define CMDQUIT	8	/* quit -- close connection and die */
54 # define CMDHELO	9	/* helo -- be polite */
55 # define CMDHELP	10	/* help -- give usage info */
56 # define CMDEHLO	11	/* ehlo -- extended helo (RFC 1425) */
57 /* non-standard commands */
58 # define CMDONEX	16	/* onex -- sending one transaction only */
59 # define CMDVERB	17	/* verb -- go into verbose mode */
60 /* debugging-only commands, only enabled if SMTPDEBUG is defined */
61 # define CMDDBGQSHOW	24	/* showq -- show send queue */
62 # define CMDDBGDEBUG	25	/* debug -- set debug mode */
63 
64 static struct cmd	CmdTab[] =
65 {
66 	"mail",		CMDMAIL,
67 	"rcpt",		CMDRCPT,
68 	"data",		CMDDATA,
69 	"rset",		CMDRSET,
70 	"vrfy",		CMDVRFY,
71 	"expn",		CMDEXPN,
72 	"help",		CMDHELP,
73 	"noop",		CMDNOOP,
74 	"quit",		CMDQUIT,
75 	"helo",		CMDHELO,
76 	"ehlo",		CMDEHLO,
77 	"verb",		CMDVERB,
78 	"onex",		CMDONEX,
79 	/*
80 	 * remaining commands are here only
81 	 * to trap and log attempts to use them
82 	 */
83 	"showq",	CMDDBGQSHOW,
84 	"debug",	CMDDBGDEBUG,
85 	NULL,		CMDERROR,
86 };
87 
88 bool	InChild = FALSE;		/* true if running in a subprocess */
89 bool	OneXact = FALSE;		/* one xaction only this run */
90 
91 #define EX_QUIT		22		/* special code for QUIT command */
92 
93 smtp(e)
94 	register ENVELOPE *e;
95 {
96 	register char *p;
97 	register struct cmd *c;
98 	char *cmd;
99 	static char *skipword();
100 	auto ADDRESS *vrfyqueue;
101 	ADDRESS *a;
102 	char *sendinghost;
103 	bool gotmail;			/* mail command received */
104 	bool gothello;			/* helo command received */
105 	bool vrfy;			/* set if this is a vrfy command */
106 	char *protocol;			/* sending protocol */
107 	long msize;			/* approximate maximum message size */
108 	auto char *delimptr;
109 	char *id;
110 	char inp[MAXLINE];
111 	char cmdbuf[MAXLINE];
112 	char hostbuf[MAXNAME];
113 	extern char Version[];
114 	extern char *macvalue();
115 	extern ADDRESS *recipient();
116 	extern ENVELOPE BlankEnvelope;
117 	extern ENVELOPE *newenvelope();
118 	extern char *anynet_ntoa();
119 
120 	if (OutChannel != stdout)
121 	{
122 		/* arrange for debugging output to go to remote host */
123 		(void) close(1);
124 		(void) dup(fileno(OutChannel));
125 	}
126 	settime(e);
127 	CurHostName = RealHostName;
128 	setproctitle("srvrsmtp %s", CurHostName);
129 	expand("\201e", inp, &inp[sizeof inp], e);
130 	message("220 %s", inp);
131 	SmtpPhase = "startup";
132 	sendinghost = NULL;
133 	protocol = NULL;
134 	gothello = FALSE;
135 	gotmail = FALSE;
136 	for (;;)
137 	{
138 		/* arrange for backout */
139 		if (setjmp(TopFrame) > 0 && InChild)
140 			finis();
141 		QuickAbort = FALSE;
142 		HoldErrs = FALSE;
143 		LogUsrErrs = FALSE;
144 		e->e_flags &= ~EF_VRFYONLY;
145 
146 		/* setup for the read */
147 		e->e_to = NULL;
148 		Errors = 0;
149 		(void) fflush(stdout);
150 
151 		/* read the input line */
152 		p = sfgets(inp, sizeof inp, InChannel, TimeOuts.to_nextcommand);
153 
154 		/* handle errors */
155 		if (p == NULL)
156 		{
157 			/* end of file, just die */
158 			message("421 %s Lost input channel from %s",
159 				MyHostName, CurHostName);
160 #ifdef LOG
161 			if (LogLevel > 1)
162 				syslog(LOG_NOTICE, "lost input channel from %s",
163 					CurHostName);
164 #endif
165 			if (InChild)
166 				ExitStat = EX_QUIT;
167 			finis();
168 		}
169 
170 		/* clean up end of line */
171 		fixcrlf(inp, TRUE);
172 
173 		/* echo command to transcript */
174 		if (e->e_xfp != NULL)
175 			fprintf(e->e_xfp, "<<< %s\n", inp);
176 
177 		/* break off command */
178 		for (p = inp; isascii(*p) && isspace(*p); p++)
179 			continue;
180 		cmd = cmdbuf;
181 		while (*p != '\0' &&
182 		       !(isascii(*p) && isspace(*p)) &&
183 		       cmd < &cmdbuf[sizeof cmdbuf - 2])
184 			*cmd++ = *p++;
185 		*cmd = '\0';
186 
187 		/* throw away leading whitespace */
188 		while (isascii(*p) && isspace(*p))
189 			p++;
190 
191 		/* decode command */
192 		for (c = CmdTab; c->cmdname != NULL; c++)
193 		{
194 			if (!strcasecmp(c->cmdname, cmdbuf))
195 				break;
196 		}
197 
198 		/* reset errors */
199 		errno = 0;
200 
201 		/* process command */
202 		switch (c->cmdcode)
203 		{
204 		  case CMDHELO:		/* hello -- introduce yourself */
205 		  case CMDEHLO:		/* extended hello */
206 			if (c->cmdcode == CMDEHLO)
207 			{
208 				protocol = "ESMTP";
209 				SmtpPhase = "EHLO";
210 			}
211 			else
212 			{
213 				protocol = "SMTP";
214 				SmtpPhase = "HELO";
215 			}
216 			setproctitle("%s: %s", CurHostName, inp);
217 			if (strcasecmp(p, MyHostName) == 0)
218 			{
219 				/*
220 				**  Didn't know about alias or MX,
221 				**  or connected to an echo server
222 				*/
223 
224 				message("553 %s config error: mail loops back to myself",
225 					MyHostName);
226 				break;
227 			}
228 			(void) strcpy(hostbuf, p);
229 			(void) strcat(hostbuf, " (");
230 			(void) strcat(hostbuf, anynet_ntoa(&RealHostAddr));
231 			if (strcasecmp(p, RealHostName) != 0)
232 			{
233 				auth_warning(e, "Host %s claimed to be %s",
234 					RealHostName, p);
235 				(void) strcat(hostbuf, "; ");
236 				(void) strcat(hostbuf, RealHostName);
237 			}
238 			(void) strcat(hostbuf, ")");
239 			sendinghost = newstr(hostbuf);
240 
241 			/* send ext. message -- old systems must ignore */
242 			message("250-%s Hello %s, pleased to meet you",
243 				MyHostName, sendinghost);
244 			if (!bitset(PRIV_NOEXPN, PrivacyFlags))
245 				message("250-EXPN");
246 			message("250-SIZE");
247 			message("250 HELP");
248 			gothello = TRUE;
249 			break;
250 
251 		  case CMDMAIL:		/* mail -- designate sender */
252 			SmtpPhase = "MAIL";
253 
254 			/* force a sending host even if no HELO given */
255 			if (sendinghost == NULL && macvalue('s', e) == NULL)
256 				sendinghost = RealHostName;
257 
258 			/* check for validity of this command */
259 			if (!gothello)
260 			{
261 				if (bitset(PRIV_NEEDMAILHELO, PrivacyFlags))
262 				{
263 					message("503 Polite people say HELO first");
264 					break;
265 				}
266 				else
267 				{
268 					auth_warning(e,
269 						"Host %s didn't use HELO protocol",
270 						RealHostName);
271 				}
272 			}
273 			if (gotmail)
274 			{
275 				message("503 Sender already specified");
276 				break;
277 			}
278 			if (InChild)
279 			{
280 				errno = 0;
281 				syserr("503 Nested MAIL command: MAIL %s", p);
282 				finis();
283 			}
284 
285 			/* fork a subprocess to process this command */
286 			if (runinchild("SMTP-MAIL", e) > 0)
287 				break;
288 			if (sendinghost != NULL)
289 				define('s', sendinghost, e);
290 			if (protocol == NULL)
291 				protocol = "SMTP";
292 			define('r', protocol, e);
293 			initsys(e);
294 			setproctitle("%s %s: %s", e->e_id, CurHostName, inp);
295 
296 			/* child -- go do the processing */
297 			p = skipword(p, "from");
298 			if (p == NULL)
299 				break;
300 			if (setjmp(TopFrame) > 0)
301 			{
302 				/* this failed -- undo work */
303 				if (InChild)
304 					finis();
305 				break;
306 			}
307 			QuickAbort = TRUE;
308 
309 			/* must parse sender first */
310 			delimptr = NULL;
311 			setsender(p, e, &delimptr, FALSE);
312 			p = delimptr;
313 			if (p != NULL && *p != '\0')
314 				*p++ = '\0';
315 
316 			/* now parse ESMTP arguments */
317 			msize = 0;
318 			for (; p != NULL && *p != '\0'; p++)
319 			{
320 				char *kp;
321 				char *vp;
322 
323 				/* locate the beginning of the keyword */
324 				while (isascii(*p) && isspace(*p))
325 					p++;
326 				if (*p == '\0')
327 					break;
328 				kp = p;
329 
330 				/* skip to the value portion */
331 				while (isascii(*p) && isalnum(*p) || *p == '-')
332 					p++;
333 				if (*p == '=')
334 				{
335 					*p++ = '\0';
336 					vp = p;
337 
338 					/* skip to the end of the value */
339 					while (*p != '\0' && *p != ' ' &&
340 					       !(isascii(*p) && iscntrl(*p)) &&
341 					       *p != '=')
342 						p++;
343 				}
344 
345 				if (*p != '\0')
346 					*p++ = '\0';
347 
348 				if (tTd(19, 1))
349 					printf("MAIL: got arg %s=%s\n", kp,
350 						vp == NULL ? "<null>" : vp);
351 
352 				if (strcasecmp(kp, "size") == 0)
353 				{
354 					if (kp == NULL)
355 					{
356 						usrerr("501 SIZE requires a value");
357 						/* NOTREACHED */
358 					}
359 					msize = atol(vp);
360 				}
361 				else
362 				{
363 					usrerr("501 %s parameter unrecognized", kp);
364 					/* NOTREACHED */
365 				}
366 			}
367 
368 			if (!enoughspace(msize))
369 			{
370 				message("452 Insufficient disk space; try again later");
371 				break;
372 			}
373 			message("250 Sender ok");
374 			gotmail = TRUE;
375 			break;
376 
377 		  case CMDRCPT:		/* rcpt -- designate recipient */
378 			if (!gotmail)
379 			{
380 				usrerr("503 Need MAIL before RCPT");
381 				break;
382 			}
383 			SmtpPhase = "RCPT";
384 			setproctitle("%s %s: %s", e->e_id, CurHostName, inp);
385 			if (setjmp(TopFrame) > 0)
386 			{
387 				e->e_flags &= ~EF_FATALERRS;
388 				break;
389 			}
390 			QuickAbort = TRUE;
391 			LogUsrErrs = TRUE;
392 
393 			p = skipword(p, "to");
394 			if (p == NULL)
395 				break;
396 			a = parseaddr(p, (ADDRESS *) NULL, 1, ' ', NULL, e);
397 			if (a == NULL)
398 				break;
399 			a->q_flags |= QPRIMARY;
400 			if (!Verbose)
401 				e->e_flags |= EF_VRFYONLY;
402 			a = recipient(a, &e->e_sendqueue, e);
403 			if (Errors != 0)
404 				break;
405 
406 			/* no errors during parsing, but might be a duplicate */
407 			e->e_to = p;
408 			if (!bitset(QBADADDR, a->q_flags))
409 				message("250 Recipient ok");
410 			else
411 			{
412 				/* punt -- should keep message in ADDRESS.... */
413 				message("550 Addressee unknown");
414 			}
415 			e->e_to = NULL;
416 			break;
417 
418 		  case CMDDATA:		/* data -- text of mail */
419 			SmtpPhase = "DATA";
420 			if (!gotmail)
421 			{
422 				message("503 Need MAIL command");
423 				break;
424 			}
425 			else if (e->e_nrcpts <= 0)
426 			{
427 				message("503 Need RCPT (recipient)");
428 				break;
429 			}
430 
431 			/* collect the text of the message */
432 			SmtpPhase = "collect";
433 			setproctitle("%s %s: %s", e->e_id, CurHostName, inp);
434 			collect(TRUE, e);
435 			if (Errors != 0)
436 				break;
437 
438 			/*
439 			**  Arrange to send to everyone.
440 			**	If sending to multiple people, mail back
441 			**		errors rather than reporting directly.
442 			**	In any case, don't mail back errors for
443 			**		anything that has happened up to
444 			**		now (the other end will do this).
445 			**	Truncate our transcript -- the mail has gotten
446 			**		to us successfully, and if we have
447 			**		to mail this back, it will be easier
448 			**		on the reader.
449 			**	Then send to everyone.
450 			**	Finally give a reply code.  If an error has
451 			**		already been given, don't mail a
452 			**		message back.
453 			**	We goose error returns by clearing error bit.
454 			*/
455 
456 			SmtpPhase = "delivery";
457 			if (e->e_nrcpts != 1)
458 			{
459 				HoldErrs = TRUE;
460 				e->e_errormode = EM_MAIL;
461 			}
462 			e->e_flags &= ~EF_FATALERRS;
463 			e->e_xfp = freopen(queuename(e, 'x'), "w", e->e_xfp);
464 			id = e->e_id;
465 
466 			/* send to all recipients */
467 			sendall(e, Verbose ? SM_DELIVER : SM_QUEUE);
468 			e->e_to = NULL;
469 
470 			/* save statistics */
471 			markstats(e, (ADDRESS *) NULL);
472 
473 			unlockqueue(e);
474 
475 			/* issue success if appropriate and reset */
476 			if (Errors == 0 || HoldErrs)
477 				message("250 %s Message accepted for delivery", id);
478 			else
479 				e->e_flags &= ~EF_FATALERRS;
480 
481 			/* now make it really happen */
482 			if (!Verbose && e->e_sendmode != SM_QUEUE)
483 				dowork(id, TRUE, e);
484 
485 			/* if in a child, pop back to our parent */
486 			if (InChild)
487 				finis();
488 
489 			/* clean up a bit */
490 			gotmail = FALSE;
491 			dropenvelope(e);
492 			CurEnv = e = newenvelope(e, CurEnv);
493 			e->e_flags = BlankEnvelope.e_flags;
494 			break;
495 
496 		  case CMDRSET:		/* rset -- reset state */
497 			message("250 Reset state");
498 			if (InChild)
499 				finis();
500 
501 			/* clean up a bit */
502 			gotmail = FALSE;
503 			dropenvelope(e);
504 			CurEnv = e = newenvelope(e, CurEnv);
505 			break;
506 
507 		  case CMDVRFY:		/* vrfy -- verify address */
508 		  case CMDEXPN:		/* expn -- expand address */
509 			vrfy = c->cmdcode == CMDVRFY;
510 			if (bitset(vrfy ? PRIV_NOVRFY : PRIV_NOEXPN,
511 						PrivacyFlags))
512 			{
513 				if (vrfy)
514 					message("252 Who's to say?");
515 				else
516 					message("502 That's none of your business");
517 				break;
518 			}
519 			else if (!gothello &&
520 				 bitset(vrfy ? PRIV_NEEDVRFYHELO : PRIV_NEEDEXPNHELO,
521 						PrivacyFlags))
522 			{
523 				message("503 I demand that you introduce yourself first");
524 				break;
525 			}
526 			if (runinchild(vrfy ? "SMTP-VRFY" : "SMTP-EXPN", e) > 0)
527 				break;
528 			setproctitle("%s: %s", CurHostName, inp);
529 #ifdef LOG
530 			if (LogLevel > 5)
531 				syslog(LOG_INFO, "%s: %s", CurHostName, inp);
532 #endif
533 			vrfyqueue = NULL;
534 			QuickAbort = TRUE;
535 			if (vrfy)
536 				e->e_flags |= EF_VRFYONLY;
537 			(void) sendtolist(p, (ADDRESS *) NULL, &vrfyqueue, e);
538 			if (Errors != 0)
539 			{
540 				if (InChild)
541 					finis();
542 				break;
543 			}
544 			while (vrfyqueue != NULL)
545 			{
546 				register ADDRESS *a = vrfyqueue->q_next;
547 				char *code;
548 
549 				while (a != NULL && bitset(QDONTSEND|QBADADDR, a->q_flags))
550 					a = a->q_next;
551 
552 				if (!bitset(QDONTSEND|QBADADDR, vrfyqueue->q_flags))
553 					printvrfyaddr(vrfyqueue, a == NULL);
554 				else if (a == NULL)
555 					message("554 Self destructive alias loop");
556 				vrfyqueue = a;
557 			}
558 			if (InChild)
559 				finis();
560 			break;
561 
562 		  case CMDHELP:		/* help -- give user info */
563 			help(p);
564 			break;
565 
566 		  case CMDNOOP:		/* noop -- do nothing */
567 			message("200 OK");
568 			break;
569 
570 		  case CMDQUIT:		/* quit -- leave mail */
571 			message("221 %s closing connection", MyHostName);
572 			if (InChild)
573 				ExitStat = EX_QUIT;
574 			finis();
575 
576 		  case CMDVERB:		/* set verbose mode */
577 			Verbose = TRUE;
578 			e->e_sendmode = SM_DELIVER;
579 			message("200 Verbose mode");
580 			break;
581 
582 		  case CMDONEX:		/* doing one transaction only */
583 			OneXact = TRUE;
584 			message("200 Only one transaction");
585 			break;
586 
587 # ifdef SMTPDEBUG
588 		  case CMDDBGQSHOW:	/* show queues */
589 			printf("Send Queue=");
590 			printaddr(e->e_sendqueue, TRUE);
591 			break;
592 
593 		  case CMDDBGDEBUG:	/* set debug mode */
594 			tTsetup(tTdvect, sizeof tTdvect, "0-99.1");
595 			tTflag(p);
596 			message("200 Debug set");
597 			break;
598 
599 # else /* not SMTPDEBUG */
600 
601 		  case CMDDBGQSHOW:	/* show queues */
602 		  case CMDDBGDEBUG:	/* set debug mode */
603 # ifdef LOG
604 			if (LogLevel > 0)
605 				syslog(LOG_NOTICE,
606 				    "\"%s\" command from %s (%s)",
607 				    c->cmdname, RealHostName,
608 				    anynet_ntoa(&RealHostAddr));
609 # endif
610 			/* FALL THROUGH */
611 # endif /* SMTPDEBUG */
612 
613 		  case CMDERROR:	/* unknown command */
614 			message("500 Command unrecognized");
615 			break;
616 
617 		  default:
618 			errno = 0;
619 			syserr("500 smtp: unknown code %d", c->cmdcode);
620 			break;
621 		}
622 	}
623 }
624 /*
625 **  SKIPWORD -- skip a fixed word.
626 **
627 **	Parameters:
628 **		p -- place to start looking.
629 **		w -- word to skip.
630 **
631 **	Returns:
632 **		p following w.
633 **		NULL on error.
634 **
635 **	Side Effects:
636 **		clobbers the p data area.
637 */
638 
639 static char *
640 skipword(p, w)
641 	register char *p;
642 	char *w;
643 {
644 	register char *q;
645 
646 	/* find beginning of word */
647 	while (isascii(*p) && isspace(*p))
648 		p++;
649 	q = p;
650 
651 	/* find end of word */
652 	while (*p != '\0' && *p != ':' && !(isascii(*p) && isspace(*p)))
653 		p++;
654 	while (isascii(*p) && isspace(*p))
655 		*p++ = '\0';
656 	if (*p != ':')
657 	{
658 	  syntax:
659 		message("501 Syntax error");
660 		Errors++;
661 		return (NULL);
662 	}
663 	*p++ = '\0';
664 	while (isascii(*p) && isspace(*p))
665 		p++;
666 
667 	/* see if the input word matches desired word */
668 	if (strcasecmp(q, w))
669 		goto syntax;
670 
671 	return (p);
672 }
673 /*
674 **  PRINTVRFYADDR -- print an entry in the verify queue
675 **
676 **	Parameters:
677 **		a -- the address to print
678 **		last -- set if this is the last one.
679 **
680 **	Returns:
681 **		none.
682 **
683 **	Side Effects:
684 **		Prints the appropriate 250 codes.
685 */
686 
687 printvrfyaddr(a, last)
688 	register ADDRESS *a;
689 	bool last;
690 {
691 	char fmtbuf[20];
692 
693 	strcpy(fmtbuf, "250");
694 	fmtbuf[3] = last ? ' ' : '-';
695 
696 	if (strchr(a->q_paddr, '<') != NULL)
697 		strcpy(&fmtbuf[4], "%s");
698 	else if (a->q_fullname == NULL)
699 		strcpy(&fmtbuf[4], "<%s>");
700 	else
701 	{
702 		strcpy(&fmtbuf[4], "%s <%s>");
703 		message(fmtbuf, a->q_fullname, a->q_paddr);
704 		return;
705 	}
706 	message(fmtbuf, a->q_paddr);
707 }
708 /*
709 **  HELP -- implement the HELP command.
710 **
711 **	Parameters:
712 **		topic -- the topic we want help for.
713 **
714 **	Returns:
715 **		none.
716 **
717 **	Side Effects:
718 **		outputs the help file to message output.
719 */
720 
721 help(topic)
722 	char *topic;
723 {
724 	register FILE *hf;
725 	int len;
726 	char buf[MAXLINE];
727 	bool noinfo;
728 
729 	if (HelpFile == NULL || (hf = fopen(HelpFile, "r")) == NULL)
730 	{
731 		/* no help */
732 		errno = 0;
733 		message("502 HELP not implemented");
734 		return;
735 	}
736 
737 	if (topic == NULL || *topic == '\0')
738 		topic = "smtp";
739 	else
740 		makelower(topic);
741 
742 	len = strlen(topic);
743 	noinfo = TRUE;
744 
745 	while (fgets(buf, sizeof buf, hf) != NULL)
746 	{
747 		if (strncmp(buf, topic, len) == 0)
748 		{
749 			register char *p;
750 
751 			p = strchr(buf, '\t');
752 			if (p == NULL)
753 				p = buf;
754 			else
755 				p++;
756 			fixcrlf(p, TRUE);
757 			message("214-%s", p);
758 			noinfo = FALSE;
759 		}
760 	}
761 
762 	if (noinfo)
763 		message("504 HELP topic unknown");
764 	else
765 		message("214 End of HELP info");
766 	(void) fclose(hf);
767 }
768 /*
769 **  RUNINCHILD -- return twice -- once in the child, then in the parent again
770 **
771 **	Parameters:
772 **		label -- a string used in error messages
773 **
774 **	Returns:
775 **		zero in the child
776 **		one in the parent
777 **
778 **	Side Effects:
779 **		none.
780 */
781 
782 runinchild(label, e)
783 	char *label;
784 	register ENVELOPE *e;
785 {
786 	int childpid;
787 
788 	if (!OneXact)
789 	{
790 		childpid = dofork();
791 		if (childpid < 0)
792 		{
793 			syserr("%s: cannot fork", label);
794 			return (1);
795 		}
796 		if (childpid > 0)
797 		{
798 			auto int st;
799 
800 			/* parent -- wait for child to complete */
801 			st = waitfor(childpid);
802 			if (st == -1)
803 				syserr("%s: lost child", label);
804 
805 			/* if we exited on a QUIT command, complete the process */
806 			if (st == (EX_QUIT << 8))
807 				finis();
808 
809 			return (1);
810 		}
811 		else
812 		{
813 			/* child */
814 			InChild = TRUE;
815 			QuickAbort = FALSE;
816 			clearenvelope(e, FALSE);
817 		}
818 	}
819 
820 	/* open alias database */
821 	initaliases(AliasFile, FALSE, e);
822 
823 	return (0);
824 }
825 
826 # endif /* SMTP */
827