xref: /csrg-svn/usr.sbin/sendmail/src/daemon.c (revision 68693)
1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #include <errno.h>
10 #include "sendmail.h"
11 
12 #ifndef lint
13 #ifdef DAEMON
14 static char sccsid[] = "@(#)daemon.c	8.76 (Berkeley) 03/31/95 (with daemon mode)";
15 #else
16 static char sccsid[] = "@(#)daemon.c	8.76 (Berkeley) 03/31/95 (without daemon mode)";
17 #endif
18 #endif /* not lint */
19 
20 #ifdef DAEMON
21 
22 # include <arpa/inet.h>
23 
24 #if NAMED_BIND
25 # include <resolv.h>
26 #endif
27 
28 /*
29 **  DAEMON.C -- routines to use when running as a daemon.
30 **
31 **	This entire file is highly dependent on the 4.2 BSD
32 **	interprocess communication primitives.  No attempt has
33 **	been made to make this file portable to Version 7,
34 **	Version 6, MPX files, etc.  If you should try such a
35 **	thing yourself, I recommend chucking the entire file
36 **	and starting from scratch.  Basic semantics are:
37 **
38 **	getrequests()
39 **		Opens a port and initiates a connection.
40 **		Returns in a child.  Must set InChannel and
41 **		OutChannel appropriately.
42 **	clrdaemon()
43 **		Close any open files associated with getting
44 **		the connection; this is used when running the queue,
45 **		etc., to avoid having extra file descriptors during
46 **		the queue run and to avoid confusing the network
47 **		code (if it cares).
48 **	makeconnection(host, port, outfile, infile, usesecureport)
49 **		Make a connection to the named host on the given
50 **		port.  Set *outfile and *infile to the files
51 **		appropriate for communication.  Returns zero on
52 **		success, else an exit status describing the
53 **		error.
54 **	host_map_lookup(map, hbuf, avp, pstat)
55 **		Convert the entry in hbuf into a canonical form.
56 */
57 /*
58 **  GETREQUESTS -- open mail IPC port and get requests.
59 **
60 **	Parameters:
61 **		none.
62 **
63 **	Returns:
64 **		none.
65 **
66 **	Side Effects:
67 **		Waits until some interesting activity occurs.  When
68 **		it does, a child is created to process it, and the
69 **		parent waits for completion.  Return from this
70 **		routine is always in the child.  The file pointers
71 **		"InChannel" and "OutChannel" should be set to point
72 **		to the communication channel.
73 */
74 
75 int		DaemonSocket	= -1;		/* fd describing socket */
76 SOCKADDR	DaemonAddr;			/* socket for incoming */
77 int		ListenQueueSize = 10;		/* size of listen queue */
78 int		TcpRcvBufferSize = 0;		/* size of TCP receive buffer */
79 int		TcpSndBufferSize = 0;		/* size of TCP send buffer */
80 
81 void
82 getrequests()
83 {
84 	int t;
85 	bool refusingconnections = TRUE;
86 	FILE *pidf;
87 	int socksize;
88 #ifdef XDEBUG
89 	bool j_has_dot;
90 #endif
91 	extern void reapchild();
92 
93 	/*
94 	**  Set up the address for the mailer.
95 	*/
96 
97 	if (DaemonAddr.sin.sin_family == 0)
98 		DaemonAddr.sin.sin_family = AF_INET;
99 	if (DaemonAddr.sin.sin_addr.s_addr == 0)
100 		DaemonAddr.sin.sin_addr.s_addr = INADDR_ANY;
101 	if (DaemonAddr.sin.sin_port == 0)
102 	{
103 		register struct servent *sp;
104 
105 		sp = getservbyname("smtp", "tcp");
106 		if (sp == NULL)
107 		{
108 			syserr("554 service \"smtp\" unknown");
109 			DaemonAddr.sin.sin_port = htons(25);
110 		}
111 		else
112 			DaemonAddr.sin.sin_port = sp->s_port;
113 	}
114 
115 	/*
116 	**  Try to actually open the connection.
117 	*/
118 
119 	if (tTd(15, 1))
120 		printf("getrequests: port 0x%x\n", DaemonAddr.sin.sin_port);
121 
122 	/* get a socket for the SMTP connection */
123 	socksize = opendaemonsocket(TRUE);
124 
125 	(void) setsignal(SIGCHLD, reapchild);
126 
127 	/* write the pid to the log file for posterity */
128 	pidf = fopen(PidFile, "w");
129 	if (pidf != NULL)
130 	{
131 		extern char *CommandLineArgs;
132 
133 		/* write the process id on line 1 */
134 		fprintf(pidf, "%d\n", getpid());
135 
136 		/* line 2 contains all command line flags */
137 		fprintf(pidf, "%s\n", CommandLineArgs);
138 
139 		/* flush and close */
140 		fclose(pidf);
141 	}
142 
143 #ifdef XDEBUG
144 	{
145 		char jbuf[MAXHOSTNAMELEN];
146 
147 		expand("\201j", jbuf, sizeof jbuf, CurEnv);
148 		j_has_dot = strchr(jbuf, '.') != NULL;
149 	}
150 #endif
151 
152 	if (tTd(15, 1))
153 		printf("getrequests: %d\n", DaemonSocket);
154 
155 	for (;;)
156 	{
157 		register int pid;
158 		auto int lotherend;
159 		extern bool refuseconnections();
160 		extern int getla();
161 
162 		/* see if we are rejecting connections */
163 		CurrentLA = getla();
164 		if (refuseconnections())
165 		{
166 			if (DaemonSocket >= 0)
167 			{
168 				/* close socket so peer will fail quickly */
169 				(void) close(DaemonSocket);
170 				DaemonSocket = -1;
171 			}
172 			refusingconnections = TRUE;
173 			setproctitle("rejecting connections: load average: %d",
174 				CurrentLA);
175 			sleep(15);
176 			continue;
177 		}
178 
179 		/* arrange to (re)open the socket if necessary */
180 		if (refusingconnections)
181 		{
182 			(void) opendaemonsocket(FALSE);
183 			setproctitle("accepting connections");
184 			refusingconnections = FALSE;
185 		}
186 
187 #ifdef XDEBUG
188 		/* check for disaster */
189 		{
190 			char jbuf[MAXHOSTNAMELEN];
191 
192 			expand("\201j", jbuf, sizeof jbuf, CurEnv);
193 			if (!wordinclass(jbuf, 'w'))
194 			{
195 				dumpstate("daemon lost $j");
196 				syslog(LOG_ALERT, "daemon process doesn't have $j in $=w; see syslog");
197 				abort();
198 			}
199 			else if (j_has_dot && strchr(jbuf, '.') == NULL)
200 			{
201 				dumpstate("daemon $j lost dot");
202 				syslog(LOG_ALERT, "daemon process $j lost dot; see syslog");
203 				abort();
204 			}
205 		}
206 #endif
207 
208 		/* wait for a connection */
209 		do
210 		{
211 			errno = 0;
212 			lotherend = socksize;
213 			t = accept(DaemonSocket,
214 			    (struct sockaddr *)&RealHostAddr, &lotherend);
215 		} while (t < 0 && errno == EINTR);
216 		if (t < 0)
217 		{
218 			syserr("getrequests: accept");
219 
220 			/* arrange to re-open the socket next time around */
221 			(void) close(DaemonSocket);
222 			DaemonSocket = -1;
223 			sleep(5);
224 			continue;
225 		}
226 
227 		/*
228 		**  Create a subprocess to process the mail.
229 		*/
230 
231 		if (tTd(15, 2))
232 			printf("getrequests: forking (fd = %d)\n", t);
233 
234 		pid = fork();
235 		if (pid < 0)
236 		{
237 			syserr("daemon: cannot fork");
238 			sleep(10);
239 			(void) close(t);
240 			continue;
241 		}
242 
243 		if (pid == 0)
244 		{
245 			char *p;
246 			extern char *hostnamebyanyaddr();
247 			extern void intsig();
248 
249 			/*
250 			**  CHILD -- return to caller.
251 			**	Collect verified idea of sending host.
252 			**	Verify calling user id if possible here.
253 			*/
254 
255 			(void) setsignal(SIGCHLD, SIG_DFL);
256 			(void) setsignal(SIGHUP, intsig);
257 			(void) close(DaemonSocket);
258 			DisConnected = FALSE;
259 
260 			setproctitle("startup with %s",
261 				anynet_ntoa(&RealHostAddr));
262 
263 			/* determine host name */
264 			p = hostnamebyanyaddr(&RealHostAddr);
265 			RealHostName = newstr(p);
266 			setproctitle("startup with %s", p);
267 
268 #ifdef LOG
269 			if (LogLevel > 11)
270 			{
271 				/* log connection information */
272 				syslog(LOG_INFO, "connect from %s (%s)",
273 					RealHostName, anynet_ntoa(&RealHostAddr));
274 			}
275 #endif
276 
277 			if ((InChannel = fdopen(t, "r")) == NULL ||
278 			    (t = dup(t)) < 0 ||
279 			    (OutChannel = fdopen(t, "w")) == NULL)
280 			{
281 				syserr("cannot open SMTP server channel, fd=%d", t);
282 				exit(0);
283 			}
284 
285 			/* should we check for illegal connection here? XXX */
286 #ifdef XLA
287 			if (!xla_host_ok(RealHostName))
288 			{
289 				message("421 Too many SMTP sessions for this host");
290 				exit(0);
291 			}
292 #endif
293 
294 			if (tTd(15, 2))
295 				printf("getreq: returning\n");
296 			return;
297 		}
298 
299 		/* close the port so that others will hang (for a while) */
300 		(void) close(t);
301 	}
302 	/*NOTREACHED*/
303 }
304 /*
305 **  OPENDAEMONSOCKET -- open the SMTP socket
306 **
307 **	Deals with setting all appropriate options.  DaemonAddr must
308 **	be set up in advance.
309 **
310 **	Parameters:
311 **		firsttime -- set if this is the initial open.
312 **
313 **	Returns:
314 **		Size in bytes of the daemon socket addr.
315 **
316 **	Side Effects:
317 **		Leaves DaemonSocket set to the open socket.
318 **		Exits if the socket cannot be created.
319 */
320 
321 #define MAXOPENTRIES	10	/* maximum number of tries to open connection */
322 
323 int
324 opendaemonsocket(firsttime)
325 	bool firsttime;
326 {
327 	int on = 1;
328 	int socksize = 0;
329 	int ntries = 0;
330 	int saveerrno;
331 
332 	if (tTd(15, 2))
333 		printf("opendaemonsocket()\n");
334 
335 	do
336 	{
337 		if (ntries > 0)
338 			sleep(5);
339 		if (firsttime || DaemonSocket < 0)
340 		{
341 			DaemonSocket = socket(DaemonAddr.sa.sa_family, SOCK_STREAM, 0);
342 			if (DaemonSocket < 0)
343 			{
344 				/* probably another daemon already */
345 				saveerrno = errno;
346 				syserr("opendaemonsocket: can't create server SMTP socket");
347 			  severe:
348 # ifdef LOG
349 				if (LogLevel > 0)
350 					syslog(LOG_ALERT, "problem creating SMTP socket");
351 # endif /* LOG */
352 				DaemonSocket = -1;
353 				continue;
354 			}
355 
356 			/* turn on network debugging? */
357 			if (tTd(15, 101))
358 				(void) setsockopt(DaemonSocket, SOL_SOCKET,
359 						  SO_DEBUG, (char *)&on,
360 						  sizeof on);
361 
362 			(void) setsockopt(DaemonSocket, SOL_SOCKET,
363 					  SO_REUSEADDR, (char *)&on, sizeof on);
364 			(void) setsockopt(DaemonSocket, SOL_SOCKET,
365 					  SO_KEEPALIVE, (char *)&on, sizeof on);
366 
367 #ifdef SO_RCVBUF
368 			if (TcpRcvBufferSize > 0)
369 			{
370 				if (setsockopt(DaemonSocket, SOL_SOCKET,
371 					       SO_RCVBUF,
372 					       (char *) &TcpRcvBufferSize,
373 					       sizeof(TcpRcvBufferSize)) < 0)
374 					syserr("getrequests: setsockopt(SO_RCVBUF)");
375 			}
376 #endif
377 
378 			switch (DaemonAddr.sa.sa_family)
379 			{
380 # ifdef NETINET
381 			  case AF_INET:
382 				socksize = sizeof DaemonAddr.sin;
383 				break;
384 # endif
385 
386 # ifdef NETISO
387 			  case AF_ISO:
388 				socksize = sizeof DaemonAddr.siso;
389 				break;
390 # endif
391 
392 			  default:
393 				socksize = sizeof DaemonAddr;
394 				break;
395 			}
396 
397 			if (bind(DaemonSocket, &DaemonAddr.sa, socksize) < 0)
398 			{
399 				saveerrno = errno;
400 				syserr("getrequests: cannot bind");
401 				(void) close(DaemonSocket);
402 				goto severe;
403 			}
404 		}
405 		if (!firsttime && listen(DaemonSocket, ListenQueueSize) < 0)
406 		{
407 			saveerrno = errno;
408 			syserr("getrequests: cannot listen");
409 			(void) close(DaemonSocket);
410 			goto severe;
411 		}
412 		return socksize;
413 	} while (ntries++ < MAXOPENTRIES && transienterror(saveerrno));
414 	syserr("!opendaemonsocket: server SMTP socket wedged: exiting");
415 	finis();
416 }
417 /*
418 **  CLRDAEMON -- reset the daemon connection
419 **
420 **	Parameters:
421 **		none.
422 **
423 **	Returns:
424 **		none.
425 **
426 **	Side Effects:
427 **		releases any resources used by the passive daemon.
428 */
429 
430 void
431 clrdaemon()
432 {
433 	if (DaemonSocket >= 0)
434 		(void) close(DaemonSocket);
435 	DaemonSocket = -1;
436 }
437 /*
438 **  SETDAEMONOPTIONS -- set options for running the daemon
439 **
440 **	Parameters:
441 **		p -- the options line.
442 **
443 **	Returns:
444 **		none.
445 */
446 
447 void
448 setdaemonoptions(p)
449 	register char *p;
450 {
451 	if (DaemonAddr.sa.sa_family == AF_UNSPEC)
452 		DaemonAddr.sa.sa_family = AF_INET;
453 
454 	while (p != NULL)
455 	{
456 		register char *f;
457 		register char *v;
458 
459 		while (isascii(*p) && isspace(*p))
460 			p++;
461 		if (*p == '\0')
462 			break;
463 		f = p;
464 		p = strchr(p, ',');
465 		if (p != NULL)
466 			*p++ = '\0';
467 		v = strchr(f, '=');
468 		if (v == NULL)
469 			continue;
470 		while (isascii(*++v) && isspace(*v))
471 			continue;
472 
473 		switch (*f)
474 		{
475 		  case 'F':		/* address family */
476 			if (isascii(*v) && isdigit(*v))
477 				DaemonAddr.sa.sa_family = atoi(v);
478 #ifdef NETINET
479 			else if (strcasecmp(v, "inet") == 0)
480 				DaemonAddr.sa.sa_family = AF_INET;
481 #endif
482 #ifdef NETISO
483 			else if (strcasecmp(v, "iso") == 0)
484 				DaemonAddr.sa.sa_family = AF_ISO;
485 #endif
486 #ifdef NETNS
487 			else if (strcasecmp(v, "ns") == 0)
488 				DaemonAddr.sa.sa_family = AF_NS;
489 #endif
490 #ifdef NETX25
491 			else if (strcasecmp(v, "x.25") == 0)
492 				DaemonAddr.sa.sa_family = AF_CCITT;
493 #endif
494 			else
495 				syserr("554 Unknown address family %s in Family=option", v);
496 			break;
497 
498 		  case 'A':		/* address */
499 			switch (DaemonAddr.sa.sa_family)
500 			{
501 #ifdef NETINET
502 			  case AF_INET:
503 				if (isascii(*v) && isdigit(*v))
504 					DaemonAddr.sin.sin_addr.s_addr = htonl(inet_network(v));
505 				else
506 				{
507 					register struct netent *np;
508 
509 					np = getnetbyname(v);
510 					if (np == NULL)
511 						syserr("554 network \"%s\" unknown", v);
512 					else
513 						DaemonAddr.sin.sin_addr.s_addr = np->n_net;
514 				}
515 				break;
516 #endif
517 
518 			  default:
519 				syserr("554 Address= option unsupported for family %d",
520 					DaemonAddr.sa.sa_family);
521 				break;
522 			}
523 			break;
524 
525 		  case 'P':		/* port */
526 			switch (DaemonAddr.sa.sa_family)
527 			{
528 				short port;
529 
530 #ifdef NETINET
531 			  case AF_INET:
532 				if (isascii(*v) && isdigit(*v))
533 					DaemonAddr.sin.sin_port = htons(atoi(v));
534 				else
535 				{
536 					register struct servent *sp;
537 
538 					sp = getservbyname(v, "tcp");
539 					if (sp == NULL)
540 						syserr("554 service \"%s\" unknown", v);
541 					else
542 						DaemonAddr.sin.sin_port = sp->s_port;
543 				}
544 				break;
545 #endif
546 
547 #ifdef NETISO
548 			  case AF_ISO:
549 				/* assume two byte transport selector */
550 				if (isascii(*v) && isdigit(*v))
551 					port = htons(atoi(v));
552 				else
553 				{
554 					register struct servent *sp;
555 
556 					sp = getservbyname(v, "tcp");
557 					if (sp == NULL)
558 						syserr("554 service \"%s\" unknown", v);
559 					else
560 						port = sp->s_port;
561 				}
562 				bcopy((char *) &port, TSEL(&DaemonAddr.siso), 2);
563 				break;
564 #endif
565 
566 			  default:
567 				syserr("554 Port= option unsupported for family %d",
568 					DaemonAddr.sa.sa_family);
569 				break;
570 			}
571 			break;
572 
573 		  case 'L':		/* listen queue size */
574 			ListenQueueSize = atoi(v);
575 			break;
576 
577 		  case 'S':		/* send buffer size */
578 			TcpSndBufferSize = atoi(v);
579 			break;
580 
581 		  case 'R':		/* receive buffer size */
582 			TcpRcvBufferSize = atoi(v);
583 			break;
584 		}
585 	}
586 }
587 /*
588 **  MAKECONNECTION -- make a connection to an SMTP socket on another machine.
589 **
590 **	Parameters:
591 **		host -- the name of the host.
592 **		port -- the port number to connect to.
593 **		mci -- a pointer to the mail connection information
594 **			structure to be filled in.
595 **		usesecureport -- if set, use a low numbered (reserved)
596 **			port to provide some rudimentary authentication.
597 **
598 **	Returns:
599 **		An exit code telling whether the connection could be
600 **			made and if not why not.
601 **
602 **	Side Effects:
603 **		none.
604 */
605 
606 SOCKADDR	CurHostAddr;		/* address of current host */
607 
608 int
609 makeconnection(host, port, mci, usesecureport)
610 	char *host;
611 	u_short port;
612 	register MCI *mci;
613 	bool usesecureport;
614 {
615 	register int i = 0;
616 	register int s;
617 	register struct hostent *hp = (struct hostent *)NULL;
618 	SOCKADDR addr;
619 	int sav_errno;
620 	int addrlen;
621 	bool firstconnect;
622 #if NAMED_BIND
623 	extern int h_errno;
624 #endif
625 
626 	/*
627 	**  Set up the address for the mailer.
628 	**	Accept "[a.b.c.d]" syntax for host name.
629 	*/
630 
631 #if NAMED_BIND
632 	h_errno = 0;
633 #endif
634 	errno = 0;
635 	bzero(&CurHostAddr, sizeof CurHostAddr);
636 	SmtpPhase = mci->mci_phase = "initial connection";
637 	CurHostName = host;
638 
639 	if (host[0] == '[')
640 	{
641 		long hid;
642 		register char *p = strchr(host, ']');
643 
644 		if (p != NULL)
645 		{
646 			*p = '\0';
647 #ifdef NETINET
648 			hid = inet_addr(&host[1]);
649 			if (hid == -1)
650 #endif
651 			{
652 				/* try it as a host name (avoid MX lookup) */
653 				hp = sm_gethostbyname(&host[1]);
654 				if (hp == NULL && p[-1] == '.')
655 				{
656 #if NAMED_BIND
657 					int oldopts = _res.options;
658 
659 					_res.options &= ~(RES_DEFNAMES|RES_DNSRCH);
660 #endif
661 					p[-1] = '\0';
662 					hp = sm_gethostbyname(&host[1]);
663 					p[-1] = '.';
664 #if NAMED_BIND
665 					_res.options = oldopts;
666 #endif
667 				}
668 				*p = ']';
669 				goto gothostent;
670 			}
671 			*p = ']';
672 		}
673 		if (p == NULL)
674 		{
675 			usrerr("553 Invalid numeric domain spec \"%s\"", host);
676 			return (EX_NOHOST);
677 		}
678 #ifdef NETINET
679 		addr.sin.sin_family = AF_INET;		/*XXX*/
680 		addr.sin.sin_addr.s_addr = hid;
681 #endif
682 	}
683 	else
684 	{
685 		register char *p = &host[strlen(host) - 1];
686 
687 		hp = sm_gethostbyname(host);
688 		if (hp == NULL && *p == '.')
689 		{
690 #if NAMED_BIND
691 			int oldopts = _res.options;
692 
693 			_res.options &= ~(RES_DEFNAMES|RES_DNSRCH);
694 #endif
695 			*p = '\0';
696 			hp = sm_gethostbyname(host);
697 			*p = '.';
698 #if NAMED_BIND
699 			_res.options = oldopts;
700 #endif
701 		}
702 gothostent:
703 		if (hp == NULL)
704 		{
705 #if NAMED_BIND
706 			/* check for name server timeouts */
707 			if (errno == ETIMEDOUT || h_errno == TRY_AGAIN ||
708 			    (errno == ECONNREFUSED && UseNameServer))
709 			{
710 				mci->mci_status = "4.4.3";
711 				return (EX_TEMPFAIL);
712 			}
713 #endif
714 			return (EX_NOHOST);
715 		}
716 		addr.sa.sa_family = hp->h_addrtype;
717 		switch (hp->h_addrtype)
718 		{
719 #ifdef NETINET
720 		  case AF_INET:
721 			bcopy(hp->h_addr,
722 				&addr.sin.sin_addr,
723 				INADDRSZ);
724 			break;
725 #endif
726 
727 		  default:
728 			bcopy(hp->h_addr,
729 				addr.sa.sa_data,
730 				hp->h_length);
731 			break;
732 		}
733 		i = 1;
734 	}
735 
736 	/*
737 	**  Determine the port number.
738 	*/
739 
740 	if (port != 0)
741 		port = htons(port);
742 	else
743 	{
744 		register struct servent *sp = getservbyname("smtp", "tcp");
745 
746 		if (sp == NULL)
747 		{
748 			syserr("554 makeconnection: service \"smtp\" unknown");
749 			port = htons(25);
750 		}
751 		else
752 			port = sp->s_port;
753 	}
754 
755 	switch (addr.sa.sa_family)
756 	{
757 #ifdef NETINET
758 	  case AF_INET:
759 		addr.sin.sin_port = port;
760 		addrlen = sizeof (struct sockaddr_in);
761 		break;
762 #endif
763 
764 #ifdef NETISO
765 	  case AF_ISO:
766 		/* assume two byte transport selector */
767 		bcopy((char *) &port, TSEL((struct sockaddr_iso *) &addr), 2);
768 		addrlen = sizeof (struct sockaddr_iso);
769 		break;
770 #endif
771 
772 	  default:
773 		syserr("Can't connect to address family %d", addr.sa.sa_family);
774 		return (EX_NOHOST);
775 	}
776 
777 	/*
778 	**  Try to actually open the connection.
779 	*/
780 
781 #ifdef XLA
782 	/* if too many connections, don't bother trying */
783 	if (!xla_noqueue_ok(host))
784 		return EX_TEMPFAIL;
785 #endif
786 
787 	firstconnect = TRUE;
788 	for (;;)
789 	{
790 		if (tTd(16, 1))
791 			printf("makeconnection (%s [%s])\n",
792 				host, anynet_ntoa(&addr));
793 
794 		/* save for logging */
795 		CurHostAddr = addr;
796 
797 		if (usesecureport)
798 		{
799 			int rport = IPPORT_RESERVED - 1;
800 
801 			s = rresvport(&rport);
802 		}
803 		else
804 		{
805 			s = socket(AF_INET, SOCK_STREAM, 0);
806 		}
807 		if (s < 0)
808 		{
809 			sav_errno = errno;
810 			syserr("makeconnection: no socket");
811 			goto failure;
812 		}
813 
814 #ifdef SO_SNDBUF
815 		if (TcpSndBufferSize > 0)
816 		{
817 			if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
818 				       (char *) &TcpSndBufferSize,
819 				       sizeof(TcpSndBufferSize)) < 0)
820 				syserr("makeconnection: setsockopt(SO_SNDBUF)");
821 		}
822 #endif
823 
824 		if (tTd(16, 1))
825 			printf("makeconnection: fd=%d\n", s);
826 
827 		/* turn on network debugging? */
828 		if (tTd(16, 101))
829 		{
830 			int on = 1;
831 			(void) setsockopt(s, SOL_SOCKET, SO_DEBUG,
832 					  (char *)&on, sizeof on);
833 		}
834 		if (CurEnv->e_xfp != NULL)
835 			(void) fflush(CurEnv->e_xfp);		/* for debugging */
836 		errno = 0;					/* for debugging */
837 		if (connect(s, (struct sockaddr *) &addr, addrlen) >= 0)
838 			break;
839 
840 		/* if running demand-dialed connection, try again */
841 		if (DialDelay > 0 && firstconnect)
842 		{
843 			if (tTd(16, 1))
844 				printf("Connect failed (%s); trying again...\n",
845 					errstring(sav_errno));
846 			firstconnect = FALSE;
847 			sleep(DialDelay);
848 			continue;
849 		}
850 
851 		/* couldn't connect.... figure out why */
852 		sav_errno = errno;
853 		(void) close(s);
854 		if (hp != NULL && hp->h_addr_list[i])
855 		{
856 			if (tTd(16, 1))
857 				printf("Connect failed (%s); trying new address....\n",
858 					errstring(sav_errno));
859 			switch (addr.sa.sa_family)
860 			{
861 #ifdef NETINET
862 			  case AF_INET:
863 				bcopy(hp->h_addr_list[i++],
864 				      &addr.sin.sin_addr,
865 				      INADDRSZ);
866 				break;
867 #endif
868 
869 			  default:
870 				bcopy(hp->h_addr_list[i++],
871 					addr.sa.sa_data,
872 					hp->h_length);
873 				break;
874 			}
875 			continue;
876 		}
877 
878 		/* failure, decide if temporary or not */
879 	failure:
880 #ifdef XLA
881 		xla_host_end(host);
882 #endif
883 		if (transienterror(sav_errno))
884 			return EX_TEMPFAIL;
885 		else
886 		{
887 			message("%s", errstring(sav_errno));
888 			return (EX_UNAVAILABLE);
889 		}
890 	}
891 
892 	/* connection ok, put it into canonical form */
893 	if ((mci->mci_out = fdopen(s, "w")) == NULL ||
894 	    (s = dup(s)) < 0 ||
895 	    (mci->mci_in = fdopen(s, "r")) == NULL)
896 	{
897 		syserr("cannot open SMTP client channel, fd=%d", s);
898 		return EX_TEMPFAIL;
899 	}
900 
901 	return (EX_OK);
902 }
903 /*
904 **  MYHOSTNAME -- return the name of this host.
905 **
906 **	Parameters:
907 **		hostbuf -- a place to return the name of this host.
908 **		size -- the size of hostbuf.
909 **
910 **	Returns:
911 **		A list of aliases for this host.
912 **
913 **	Side Effects:
914 **		Adds numeric codes to $=w.
915 */
916 
917 struct hostent *
918 myhostname(hostbuf, size)
919 	char hostbuf[];
920 	int size;
921 {
922 	register struct hostent *hp;
923 	extern bool getcanonname();
924 	extern int h_errno;
925 
926 	if (gethostname(hostbuf, size) < 0)
927 	{
928 		(void) strcpy(hostbuf, "localhost");
929 	}
930 	hp = sm_gethostbyname(hostbuf);
931 	if (hp == NULL)
932 		return NULL;
933 	if (strchr(hp->h_name, '.') != NULL || strchr(hostbuf, '.') == NULL)
934 	{
935 		(void) strncpy(hostbuf, hp->h_name, size - 1);
936 		hostbuf[size - 1] = '\0';
937 	}
938 
939 #if NAMED_BIND
940 	/*
941 	**  If still no dot, try DNS directly (i.e., avoid NIS problems).
942 	**  This ought to be driven from the configuration file, but
943 	**  we are called before the configuration is read.  We could
944 	**  check for an /etc/resolv.conf file, but that isn't required.
945 	**  All in all, a bit of a mess.
946 	*/
947 
948 	if (strchr(hostbuf, '.') == NULL &&
949 	    !getcanonname(hostbuf, size, TRUE) &&
950 	    h_errno == TRY_AGAIN)
951 	{
952 		/* try twice in case name server not yet started up */
953 		message("My unqualifed host name (%s) unknown to DNS; sleeping for retry",
954 			hostbuf);
955 		sleep(60);
956 		if (!getcanonname(hostbuf, size, TRUE))
957 			errno = h_errno + E_DNSBASE;
958 	}
959 #endif
960 	return (hp);
961 }
962 /*
963 **  GETAUTHINFO -- get the real host name asociated with a file descriptor
964 **
965 **	Uses RFC1413 protocol to try to get info from the other end.
966 **
967 **	Parameters:
968 **		fd -- the descriptor
969 **
970 **	Returns:
971 **		The user@host information associated with this descriptor.
972 */
973 
974 static jmp_buf	CtxAuthTimeout;
975 
976 static void
977 authtimeout()
978 {
979 	longjmp(CtxAuthTimeout, 1);
980 }
981 
982 char *
983 getauthinfo(fd)
984 	int fd;
985 {
986 	int falen;
987 	register char *p;
988 	SOCKADDR la;
989 	int lalen;
990 	register struct servent *sp;
991 	int s;
992 	int i;
993 	EVENT *ev;
994 	int nleft;
995 	char ibuf[MAXNAME + 1];
996 	static char hbuf[MAXNAME * 2 + 2];
997 	extern char *hostnamebyanyaddr();
998 	extern char RealUserName[];			/* main.c */
999 
1000 	falen = sizeof RealHostAddr;
1001 	if (isatty(fd) || getpeername(fd, &RealHostAddr.sa, &falen) < 0 ||
1002 	    falen <= 0 || RealHostAddr.sa.sa_family == 0)
1003 	{
1004 		(void) sprintf(hbuf, "%s@localhost", RealUserName);
1005 		if (tTd(9, 1))
1006 			printf("getauthinfo: %s\n", hbuf);
1007 		return hbuf;
1008 	}
1009 
1010 	if (RealHostName == NULL)
1011 	{
1012 		/* translate that to a host name */
1013 		RealHostName = newstr(hostnamebyanyaddr(&RealHostAddr));
1014 	}
1015 
1016 	if (TimeOuts.to_ident == 0)
1017 		goto noident;
1018 
1019 	lalen = sizeof la;
1020 	if (RealHostAddr.sa.sa_family != AF_INET ||
1021 	    getsockname(fd, &la.sa, &lalen) < 0 || lalen <= 0 ||
1022 	    la.sa.sa_family != AF_INET)
1023 	{
1024 		/* no ident info */
1025 		goto noident;
1026 	}
1027 
1028 	/* create ident query */
1029 	(void) sprintf(ibuf, "%d,%d\r\n",
1030 		ntohs(RealHostAddr.sin.sin_port), ntohs(la.sin.sin_port));
1031 
1032 	/* create local address */
1033 	la.sin.sin_port = 0;
1034 
1035 	/* create foreign address */
1036 	sp = getservbyname("auth", "tcp");
1037 	if (sp != NULL)
1038 		RealHostAddr.sin.sin_port = sp->s_port;
1039 	else
1040 		RealHostAddr.sin.sin_port = htons(113);
1041 
1042 	s = -1;
1043 	if (setjmp(CtxAuthTimeout) != 0)
1044 	{
1045 		if (s >= 0)
1046 			(void) close(s);
1047 		goto noident;
1048 	}
1049 
1050 	/* put a timeout around the whole thing */
1051 	ev = setevent(TimeOuts.to_ident, authtimeout, 0);
1052 
1053 	/* connect to foreign IDENT server using same address as SMTP socket */
1054 	s = socket(AF_INET, SOCK_STREAM, 0);
1055 	if (s < 0)
1056 	{
1057 		clrevent(ev);
1058 		goto noident;
1059 	}
1060 	if (bind(s, &la.sa, sizeof la.sin) < 0 ||
1061 	    connect(s, &RealHostAddr.sa, sizeof RealHostAddr.sin) < 0)
1062 	{
1063 		goto closeident;
1064 	}
1065 
1066 	if (tTd(9, 10))
1067 		printf("getauthinfo: sent %s", ibuf);
1068 
1069 	/* send query */
1070 	if (write(s, ibuf, strlen(ibuf)) < 0)
1071 		goto closeident;
1072 
1073 	/* get result */
1074 	p = &ibuf[0];
1075 	nleft = sizeof ibuf - 1;
1076 	while ((i = read(s, p, nleft)) > 0)
1077 	{
1078 		p += i;
1079 		nleft -= i;
1080 	}
1081 	(void) close(s);
1082 	clrevent(ev);
1083 	if (i < 0 || p == &ibuf[0])
1084 		goto noident;
1085 
1086 	if (*--p == '\n' && *--p == '\r')
1087 		p--;
1088 	*++p = '\0';
1089 
1090 	if (tTd(9, 3))
1091 		printf("getauthinfo:  got %s\n", ibuf);
1092 
1093 	/* parse result */
1094 	p = strchr(ibuf, ':');
1095 	if (p == NULL)
1096 	{
1097 		/* malformed response */
1098 		goto noident;
1099 	}
1100 	while (isascii(*++p) && isspace(*p))
1101 		continue;
1102 	if (strncasecmp(p, "userid", 6) != 0)
1103 	{
1104 		/* presumably an error string */
1105 		goto noident;
1106 	}
1107 	p += 6;
1108 	while (isascii(*p) && isspace(*p))
1109 		p++;
1110 	if (*p++ != ':')
1111 	{
1112 		/* either useridxx or malformed response */
1113 		goto noident;
1114 	}
1115 
1116 	/* p now points to the OSTYPE field */
1117 	while (isascii(*p) && isspace(*p))
1118 		p++;
1119 	if (strncasecmp(p, "other", 5) == 0 &&
1120 	    (p[5] == ':' || p[5] == ' ' || p[5] == ',' || p[5] == '\0'))
1121 	{
1122 		/* not useful information */
1123 		goto noident;
1124 	}
1125 	p = strchr(p, ':');
1126 	if (p == NULL)
1127 	{
1128 		/* malformed response */
1129 		goto noident;
1130 	}
1131 
1132 	/* 1413 says don't do this -- but it's broken otherwise */
1133 	while (isascii(*++p) && isspace(*p))
1134 		continue;
1135 
1136 	/* p now points to the authenticated name -- copy carefully */
1137 	cleanstrcpy(hbuf, p, MAXNAME);
1138 	hbuf[i++] = '@';
1139 	strcpy(&hbuf[i], RealHostName == NULL ? "localhost" : RealHostName);
1140 	goto finish;
1141 
1142 closeident:
1143 	(void) close(s);
1144 	clrevent(ev);
1145 
1146 noident:
1147 	if (RealHostName == NULL)
1148 	{
1149 		if (tTd(9, 1))
1150 			printf("getauthinfo: NULL\n");
1151 		return NULL;
1152 	}
1153 	(void) strcpy(hbuf, RealHostName);
1154 
1155 finish:
1156 	if (RealHostName != NULL && RealHostName[0] != '[')
1157 	{
1158 		p = &hbuf[strlen(hbuf)];
1159 		(void) sprintf(p, " [%s]", anynet_ntoa(&RealHostAddr));
1160 	}
1161 	if (tTd(9, 1))
1162 		printf("getauthinfo: %s\n", hbuf);
1163 	return hbuf;
1164 }
1165 /*
1166 **  HOST_MAP_LOOKUP -- turn a hostname into canonical form
1167 **
1168 **	Parameters:
1169 **		map -- a pointer to this map (unused).
1170 **		name -- the (presumably unqualified) hostname.
1171 **		av -- unused -- for compatibility with other mapping
1172 **			functions.
1173 **		statp -- an exit status (out parameter) -- set to
1174 **			EX_TEMPFAIL if the name server is unavailable.
1175 **
1176 **	Returns:
1177 **		The mapping, if found.
1178 **		NULL if no mapping found.
1179 **
1180 **	Side Effects:
1181 **		Looks up the host specified in hbuf.  If it is not
1182 **		the canonical name for that host, return the canonical
1183 **		name.
1184 */
1185 
1186 char *
1187 host_map_lookup(map, name, av, statp)
1188 	MAP *map;
1189 	char *name;
1190 	char **av;
1191 	int *statp;
1192 {
1193 	register struct hostent *hp;
1194 	struct in_addr in_addr;
1195 	char *cp;
1196 	register STAB *s;
1197 	char hbuf[MAXNAME + 1];
1198 #if NAMED_BIND
1199 	extern int h_errno;
1200 #endif
1201 
1202 	/*
1203 	**  See if we have already looked up this name.  If so, just
1204 	**  return it.
1205 	*/
1206 
1207 	s = stab(name, ST_NAMECANON, ST_ENTER);
1208 	if (bitset(NCF_VALID, s->s_namecanon.nc_flags))
1209 	{
1210 		if (tTd(9, 1))
1211 			printf("host_map_lookup(%s) => CACHE %s\n",
1212 				name, s->s_namecanon.nc_cname);
1213 		errno = s->s_namecanon.nc_errno;
1214 #if NAMED_BIND
1215 		h_errno = s->s_namecanon.nc_herrno;
1216 #endif
1217 		*statp = s->s_namecanon.nc_stat;
1218 		if (CurEnv->e_message == NULL && *statp == EX_TEMPFAIL)
1219 		{
1220 			sprintf(hbuf, "%s: Name server timeout",
1221 				shortenstring(name, 33));
1222 			CurEnv->e_message = newstr(hbuf);
1223 		}
1224 		return s->s_namecanon.nc_cname;
1225 	}
1226 
1227 	/*
1228 	**  If first character is a bracket, then it is an address
1229 	**  lookup.  Address is copied into a temporary buffer to
1230 	**  strip the brackets and to preserve name if address is
1231 	**  unknown.
1232 	*/
1233 
1234 	if (*name != '[')
1235 	{
1236 		extern bool getcanonname();
1237 
1238 		if (tTd(9, 1))
1239 			printf("host_map_lookup(%s) => ", name);
1240 		s->s_namecanon.nc_flags |= NCF_VALID;		/* will be soon */
1241 		if (strlen(name) < sizeof hbuf)
1242 			(void) strcpy(hbuf, name);
1243 		else
1244 		{
1245 			bcopy(name, hbuf, sizeof hbuf - 1);
1246 			hbuf[sizeof hbuf - 1] = '\0';
1247 		}
1248 		if (getcanonname(hbuf, sizeof hbuf - 1, TRUE))
1249 		{
1250 			if (tTd(9, 1))
1251 				printf("%s\n", hbuf);
1252 			cp = map_rewrite(map, hbuf, strlen(hbuf), av);
1253 			s->s_namecanon.nc_cname = newstr(cp);
1254 			return cp;
1255 		}
1256 		else
1257 		{
1258 			register struct hostent *hp;
1259 
1260 			s->s_namecanon.nc_errno = errno;
1261 #if NAMED_BIND
1262 			s->s_namecanon.nc_herrno = h_errno;
1263 			if (tTd(9, 1))
1264 				printf("FAIL (%d)\n", h_errno);
1265 			switch (h_errno)
1266 			{
1267 			  case TRY_AGAIN:
1268 				if (UseNameServer)
1269 				{
1270 					sprintf(hbuf, "%s: Name server timeout",
1271 						shortenstring(name, 33));
1272 					message("%s", hbuf);
1273 					if (CurEnv->e_message == NULL)
1274 						CurEnv->e_message = newstr(hbuf);
1275 				}
1276 				*statp = EX_TEMPFAIL;
1277 				break;
1278 
1279 			  case HOST_NOT_FOUND:
1280 				*statp = EX_NOHOST;
1281 				break;
1282 
1283 			  case NO_RECOVERY:
1284 				*statp = EX_SOFTWARE;
1285 				break;
1286 
1287 			  default:
1288 				*statp = EX_UNAVAILABLE;
1289 				break;
1290 			}
1291 #else
1292 			if (tTd(9, 1))
1293 				printf("FAIL\n");
1294 			*statp = EX_NOHOST;
1295 #endif
1296 			s->s_namecanon.nc_stat = *statp;
1297 			if ((*statp != EX_TEMPFAIL && *statp != EX_NOHOST) ||
1298 			    UseNameServer)
1299 				return NULL;
1300 
1301 			/*
1302 			**  Try to look it up in /etc/hosts
1303 			*/
1304 
1305 			hp = sm_gethostbyname(name);
1306 			if (hp == NULL)
1307 			{
1308 				/* no dice there either */
1309 				s->s_namecanon.nc_stat = *statp = EX_NOHOST;
1310 				return NULL;
1311 			}
1312 
1313 			s->s_namecanon.nc_stat = *statp = EX_OK;
1314 			cp = map_rewrite(map, hp->h_name, strlen(hp->h_name), av);
1315 			s->s_namecanon.nc_cname = newstr(cp);
1316 			return cp;
1317 		}
1318 	}
1319 	if ((cp = strchr(name, ']')) == NULL)
1320 		return (NULL);
1321 	*cp = '\0';
1322 	in_addr.s_addr = inet_addr(&name[1]);
1323 
1324 	/* nope -- ask the name server */
1325 	hp = sm_gethostbyaddr((char *)&in_addr, INADDRSZ, AF_INET);
1326 	s->s_namecanon.nc_errno = errno;
1327 #if NAMED_BIND
1328 	s->s_namecanon.nc_herrno = h_errno;
1329 #endif
1330 	s->s_namecanon.nc_flags |= NCF_VALID;		/* will be soon */
1331 	if (hp == NULL)
1332 	{
1333 		s->s_namecanon.nc_stat = *statp = EX_NOHOST;
1334 		return (NULL);
1335 	}
1336 
1337 	/* found a match -- copy out */
1338 	cp = map_rewrite(map, hp->h_name, strlen(hp->h_name), av);
1339 	s->s_namecanon.nc_stat = *statp = EX_OK;
1340 	s->s_namecanon.nc_cname = newstr(cp);
1341 	return cp;
1342 }
1343 /*
1344 **  ANYNET_NTOA -- convert a network address to printable form.
1345 **
1346 **	Parameters:
1347 **		sap -- a pointer to a sockaddr structure.
1348 **
1349 **	Returns:
1350 **		A printable version of that sockaddr.
1351 */
1352 
1353 char *
1354 anynet_ntoa(sap)
1355 	register SOCKADDR *sap;
1356 {
1357 	register char *bp;
1358 	register char *ap;
1359 	int l;
1360 	static char buf[100];
1361 
1362 	/* check for null/zero family */
1363 	if (sap == NULL)
1364 		return "NULLADDR";
1365 	if (sap->sa.sa_family == 0)
1366 		return "0";
1367 
1368 	switch (sap->sa.sa_family)
1369 	{
1370 #ifdef NETUNIX
1371 	  case AF_UNIX:
1372 	  	if (sap->sunix.sun_path[0] != '\0')
1373 	  		sprintf(buf, "[UNIX: %.64s]", sap->sunix.sun_path);
1374 	  	else
1375 	  		sprintf(buf, "[UNIX: localhost]");
1376 		return buf;
1377 #endif
1378 
1379 #ifdef NETINET
1380 	  case AF_INET:
1381 		return inet_ntoa(((struct sockaddr_in *) sap)->sin_addr);
1382 #endif
1383 
1384 	  default:
1385 	  	/* this case is only to ensure syntactic correctness */
1386 	  	break;
1387 	}
1388 
1389 	/* unknown family -- just dump bytes */
1390 	(void) sprintf(buf, "Family %d: ", sap->sa.sa_family);
1391 	bp = &buf[strlen(buf)];
1392 	ap = sap->sa.sa_data;
1393 	for (l = sizeof sap->sa.sa_data; --l >= 0; )
1394 	{
1395 		(void) sprintf(bp, "%02x:", *ap++ & 0377);
1396 		bp += 3;
1397 	}
1398 	*--bp = '\0';
1399 	return buf;
1400 }
1401 /*
1402 **  HOSTNAMEBYANYADDR -- return name of host based on address
1403 **
1404 **	Parameters:
1405 **		sap -- SOCKADDR pointer
1406 **
1407 **	Returns:
1408 **		text representation of host name.
1409 **
1410 **	Side Effects:
1411 **		none.
1412 */
1413 
1414 char *
1415 hostnamebyanyaddr(sap)
1416 	register SOCKADDR *sap;
1417 {
1418 	register struct hostent *hp;
1419 	int saveretry;
1420 
1421 #if NAMED_BIND
1422 	/* shorten name server timeout to avoid higher level timeouts */
1423 	saveretry = _res.retry;
1424 	_res.retry = 3;
1425 #endif /* NAMED_BIND */
1426 
1427 	switch (sap->sa.sa_family)
1428 	{
1429 #ifdef NETINET
1430 	  case AF_INET:
1431 		hp = sm_gethostbyaddr((char *) &sap->sin.sin_addr,
1432 			INADDRSZ,
1433 			AF_INET);
1434 		break;
1435 #endif
1436 
1437 #ifdef NETISO
1438 	  case AF_ISO:
1439 		hp = sm_gethostbyaddr((char *) &sap->siso.siso_addr,
1440 			sizeof sap->siso.siso_addr,
1441 			AF_ISO);
1442 		break;
1443 #endif
1444 
1445 	  case AF_UNIX:
1446 		hp = NULL;
1447 		break;
1448 
1449 	  default:
1450 		hp = sm_gethostbyaddr(sap->sa.sa_data,
1451 			   sizeof sap->sa.sa_data,
1452 			   sap->sa.sa_family);
1453 		break;
1454 	}
1455 
1456 #if NAMED_BIND
1457 	_res.retry = saveretry;
1458 #endif /* NAMED_BIND */
1459 
1460 	if (hp != NULL)
1461 		return hp->h_name;
1462 	else
1463 	{
1464 		/* produce a dotted quad */
1465 		static char buf[512];
1466 
1467 		(void) sprintf(buf, "[%s]", anynet_ntoa(sap));
1468 		return buf;
1469 	}
1470 }
1471 
1472 # else /* DAEMON */
1473 /* code for systems without sophisticated networking */
1474 
1475 /*
1476 **  MYHOSTNAME -- stub version for case of no daemon code.
1477 **
1478 **	Can't convert to upper case here because might be a UUCP name.
1479 **
1480 **	Mark, you can change this to be anything you want......
1481 */
1482 
1483 char **
1484 myhostname(hostbuf, size)
1485 	char hostbuf[];
1486 	int size;
1487 {
1488 	register FILE *f;
1489 
1490 	hostbuf[0] = '\0';
1491 	f = fopen("/usr/include/whoami", "r");
1492 	if (f != NULL)
1493 	{
1494 		(void) fgets(hostbuf, size, f);
1495 		fixcrlf(hostbuf, TRUE);
1496 		(void) fclose(f);
1497 	}
1498 	return (NULL);
1499 }
1500 /*
1501 **  GETAUTHINFO -- get the real host name asociated with a file descriptor
1502 **
1503 **	Parameters:
1504 **		fd -- the descriptor
1505 **
1506 **	Returns:
1507 **		The host name associated with this descriptor, if it can
1508 **			be determined.
1509 **		NULL otherwise.
1510 **
1511 **	Side Effects:
1512 **		none
1513 */
1514 
1515 char *
1516 getauthinfo(fd)
1517 	int fd;
1518 {
1519 	return NULL;
1520 }
1521 /*
1522 **  MAPHOSTNAME -- turn a hostname into canonical form
1523 **
1524 **	Parameters:
1525 **		map -- a pointer to the database map.
1526 **		name -- a buffer containing a hostname.
1527 **		avp -- a pointer to a (cf file defined) argument vector.
1528 **		statp -- an exit status (out parameter).
1529 **
1530 **	Returns:
1531 **		mapped host name
1532 **		FALSE otherwise.
1533 **
1534 **	Side Effects:
1535 **		Looks up the host specified in name.  If it is not
1536 **		the canonical name for that host, replace it with
1537 **		the canonical name.  If the name is unknown, or it
1538 **		is already the canonical name, leave it unchanged.
1539 */
1540 
1541 /*ARGSUSED*/
1542 char *
1543 host_map_lookup(map, name, avp, statp)
1544 	MAP *map;
1545 	char *name;
1546 	char **avp;
1547 	char *statp;
1548 {
1549 	register struct hostent *hp;
1550 
1551 	hp = sm_gethostbyname(name);
1552 	if (hp != NULL)
1553 		return hp->h_name;
1554 	*statp = EX_NOHOST;
1555 	return NULL;
1556 }
1557 
1558 #endif /* DAEMON */
1559