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