xref: /original-bsd/usr.sbin/sendmail/src/daemon.c (revision 3c154354)
1939f5b94Sdist /*
2939f5b94Sdist **  Sendmail
3939f5b94Sdist **  Copyright (c) 1983  Eric P. Allman
4939f5b94Sdist **  Berkeley, California
5939f5b94Sdist **
6939f5b94Sdist **  Copyright (c) 1983 Regents of the University of California.
7939f5b94Sdist **  All rights reserved.  The Berkeley software License Agreement
8939f5b94Sdist **  specifies the terms and conditions for redistribution.
9939f5b94Sdist */
10939f5b94Sdist 
11939f5b94Sdist 
127aa493c5Seric # include <errno.h>
137fa39d90Seric # include "sendmail.h"
147fa39d90Seric 
15d0a9e852Seric # ifndef DAEMON
16af5e902cSeric # ifndef lint
17*3c154354Seric static char	SccsId[] = "@(#)daemon.c	5.4.1.1 (Berkeley) 09/19/85	(w/o daemon mode)";
18af5e902cSeric # endif not lint
19d0a9e852Seric # else
20d0a9e852Seric 
211c71e510Seric # include <netdb.h>
221e1663f7Swnj # include <sys/wait.h>
23af5e902cSeric # include <sys/time.h>
24af5e902cSeric # include <sys/resource.h>
25d0a9e852Seric 
26af5e902cSeric # ifndef lint
27*3c154354Seric static char	SccsId[] = "@(#)daemon.c	5.4.1.1 (Berkeley) 09/19/85 (with daemon mode)";
28af5e902cSeric # endif not lint
297fa39d90Seric 
307fa39d90Seric /*
317fa39d90Seric **  DAEMON.C -- routines to use when running as a daemon.
3247b12ae1Seric **
3347b12ae1Seric **	This entire file is highly dependent on the 4.2 BSD
3447b12ae1Seric **	interprocess communication primitives.  No attempt has
3547b12ae1Seric **	been made to make this file portable to Version 7,
3647b12ae1Seric **	Version 6, MPX files, etc.  If you should try such a
3747b12ae1Seric **	thing yourself, I recommend chucking the entire file
3847b12ae1Seric **	and starting from scratch.  Basic semantics are:
3947b12ae1Seric **
4047b12ae1Seric **	getrequests()
4147b12ae1Seric **		Opens a port and initiates a connection.
4247b12ae1Seric **		Returns in a child.  Must set InChannel and
4347b12ae1Seric **		OutChannel appropriately.
44b7d7afcbSeric **	clrdaemon()
45b7d7afcbSeric **		Close any open files associated with getting
46b7d7afcbSeric **		the connection; this is used when running the queue,
47b7d7afcbSeric **		etc., to avoid having extra file descriptors during
48b7d7afcbSeric **		the queue run and to avoid confusing the network
49b7d7afcbSeric **		code (if it cares).
5047b12ae1Seric **	makeconnection(host, port, outfile, infile)
5147b12ae1Seric **		Make a connection to the named host on the given
5247b12ae1Seric **		port.  Set *outfile and *infile to the files
5347b12ae1Seric **		appropriate for communication.  Returns zero on
5447b12ae1Seric **		success, else an exit status describing the
5547b12ae1Seric **		error.
5647b12ae1Seric **
5747b12ae1Seric **	The semantics of both of these should be clean.
587fa39d90Seric */
597fa39d90Seric /*
607fa39d90Seric **  GETREQUESTS -- open mail IPC port and get requests.
617fa39d90Seric **
627fa39d90Seric **	Parameters:
637fa39d90Seric **		none.
647fa39d90Seric **
657fa39d90Seric **	Returns:
667fa39d90Seric **		none.
677fa39d90Seric **
687fa39d90Seric **	Side Effects:
697fa39d90Seric **		Waits until some interesting activity occurs.  When
707fa39d90Seric **		it does, a child is created to process it, and the
717fa39d90Seric **		parent waits for completion.  Return from this
72147303b1Seric **		routine is always in the child.  The file pointers
73147303b1Seric **		"InChannel" and "OutChannel" should be set to point
74147303b1Seric **		to the communication channel.
757fa39d90Seric */
767fa39d90Seric 
77b7d7afcbSeric struct sockaddr_in	SendmailAddress;/* internet address of sendmail */
789478786eSeric 
79b7d7afcbSeric int	DaemonSocket	= -1;		/* fd describing socket */
80be388505Seric char	*NetName;			/* name of home (local?) network */
811c71e510Seric 
827fa39d90Seric getrequests()
837fa39d90Seric {
841c71e510Seric 	int t;
85*3c154354Seric 	union wait status;
861c71e510Seric 	register struct servent *sp;
87eb889047Seric 
88a8268164Seric 	/*
891c71e510Seric 	**  Set up the address for the mailer.
90eb889047Seric 	*/
91eb889047Seric 
921c71e510Seric 	sp = getservbyname("smtp", "tcp");
931c71e510Seric 	if (sp == NULL)
94d0a9e852Seric 	{
951c71e510Seric 		syserr("server \"smtp\" unknown");
96a1961f2aSeric 		goto severe;
971c71e510Seric 	}
981c71e510Seric 	SendmailAddress.sin_family = AF_INET;
991c71e510Seric 	SendmailAddress.sin_addr.s_addr = INADDR_ANY;
100f43fa3c2Ssam 	SendmailAddress.sin_port = sp->s_port;
1011c71e510Seric 
1021c71e510Seric 	/*
1031c71e510Seric 	**  Try to actually open the connection.
1041c71e510Seric 	*/
1051c71e510Seric 
1061c71e510Seric # ifdef DEBUG
1071c71e510Seric 	if (tTd(15, 1))
1081c71e510Seric 		printf("getrequests: port 0x%x\n", SendmailAddress.sin_port);
1091c71e510Seric # endif DEBUG
1101c71e510Seric 
1111c71e510Seric 	/* get a socket for the SMTP connection */
112af5e902cSeric 	DaemonSocket = socket(AF_INET, SOCK_STREAM, 0);
113b7d7afcbSeric 	if (DaemonSocket < 0)
1141c71e510Seric 	{
1151c71e510Seric 		/* probably another daemon already */
1161c71e510Seric 		syserr("getrequests: can't create socket");
1171c71e510Seric 	  severe:
118b0ba8827Seric # ifdef LOG
119b0ba8827Seric 		if (LogLevel > 0)
120d2aa4720Seric 			syslog(LOG_ALERT, "cannot get connection");
121b0ba8827Seric # endif LOG
12247b12ae1Seric 		finis();
123d0a9e852Seric 	}
1241b6e4a15Seric 
1251b6e4a15Seric #ifdef DEBUG
1261b6e4a15Seric 	/* turn on network debugging? */
1271b6e4a15Seric 	if (tTd(15, 15))
128*3c154354Seric 		(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, 0, 0);
1291b6e4a15Seric #endif DEBUG
1301b6e4a15Seric 
131af5e902cSeric 	if (bind(DaemonSocket, &SendmailAddress, sizeof SendmailAddress) < 0)
1321c71e510Seric 	{
1331c71e510Seric 		syserr("getrequests: cannot bind");
134b7d7afcbSeric 		(void) close(DaemonSocket);
1351c71e510Seric 		goto severe;
1361c71e510Seric 	}
137af5e902cSeric 	if (listen(DaemonSocket, 10) < 0)
138af5e902cSeric 	{
139af5e902cSeric 		syserr("getrequests: cannot listen");
140af5e902cSeric 		(void) close(DaemonSocket);
141af5e902cSeric 		goto severe;
142af5e902cSeric 	}
1431c71e510Seric 
1441c71e510Seric # ifdef DEBUG
1451c71e510Seric 	if (tTd(15, 1))
146b7d7afcbSeric 		printf("getrequests: %d\n", DaemonSocket);
1471c71e510Seric # endif DEBUG
1481c71e510Seric 
1491c71e510Seric 	for (;;)
1501c71e510Seric 	{
1513a099713Seric 		register int pid;
152a44d5a5eSeric 		auto int lotherend;
153a44d5a5eSeric 		struct sockaddr_in otherend;
1543a099713Seric 		extern int RefuseLA;
1553a099713Seric 
1563a099713Seric 		/* see if we are rejecting connections */
1573a099713Seric 		while (getla() > RefuseLA)
1583a099713Seric 			sleep(5);
159a44d5a5eSeric 
1601c71e510Seric 		/* wait for a connection */
1611c71e510Seric 		do
1621c71e510Seric 		{
1631c71e510Seric 			errno = 0;
1641c71e510Seric 			lotherend = sizeof otherend;
165af5e902cSeric 			t = accept(DaemonSocket, &otherend, &lotherend);
1661c71e510Seric 		} while (t < 0 && errno == EINTR);
1671c71e510Seric 		if (t < 0)
1681c71e510Seric 		{
1691c71e510Seric 			syserr("getrequests: accept");
1701c71e510Seric 			sleep(5);
1711c71e510Seric 			continue;
1721c71e510Seric 		}
173d0a9e852Seric 
174d0a9e852Seric 		/*
175d0a9e852Seric 		**  Create a subprocess to process the mail.
176d0a9e852Seric 		*/
177d0a9e852Seric 
178d0a9e852Seric # ifdef DEBUG
17961e4310fSeric 		if (tTd(15, 2))
1801c71e510Seric 			printf("getrequests: forking (fd = %d)\n", t);
181d0a9e852Seric # endif DEBUG
182eb889047Seric 
183a8268164Seric 		pid = fork();
184a8268164Seric 		if (pid < 0)
185a8268164Seric 		{
186a8268164Seric 			syserr("daemon: cannot fork");
187a8268164Seric 			sleep(10);
1881c71e510Seric 			(void) close(t);
189a8268164Seric 			continue;
190a8268164Seric 		}
191a8268164Seric 
192a8268164Seric 		if (pid == 0)
193a8268164Seric 		{
194a44d5a5eSeric 			extern struct hostent *gethostbyaddr();
195a44d5a5eSeric 			register struct hostent *hp;
196a44d5a5eSeric 			char buf[MAXNAME];
197a44d5a5eSeric 
198a8268164Seric 			/*
199a8268164Seric 			**  CHILD -- return to caller.
200a44d5a5eSeric 			**	Collect verified idea of sending host.
201a8268164Seric 			**	Verify calling user id if possible here.
202a8268164Seric 			*/
203a8268164Seric 
204a44d5a5eSeric 			/* determine host name */
205a44d5a5eSeric 			hp = gethostbyaddr(&otherend.sin_addr, sizeof otherend.sin_addr, AF_INET);
206a44d5a5eSeric 			if (hp != NULL)
207be388505Seric 			{
208fefbbe29Seric 				(void) strcpy(buf, hp->h_name);
209be388505Seric 				if (NetName != NULL && NetName[0] != '\0' &&
2107dcf5c8cSeric 				    index(hp->h_name, '.') == NULL)
211be388505Seric 				{
212fefbbe29Seric 					(void) strcat(buf, ".");
213fefbbe29Seric 					(void) strcat(buf, NetName);
214be388505Seric 				}
215be388505Seric 			}
216a44d5a5eSeric 			else
21729dcf4baSeric 			{
21829dcf4baSeric 				extern char *inet_ntoa();
21929dcf4baSeric 
22029dcf4baSeric 				/* produce a dotted quad */
22129dcf4baSeric 				(void) sprintf(buf, "[%s]",
22229dcf4baSeric 					inet_ntoa(otherend.sin_addr));
22329dcf4baSeric 			}
22429dcf4baSeric 
22529dcf4baSeric 			/* should we check for illegal connection here? XXX */
22629dcf4baSeric 
227a44d5a5eSeric 			RealHostName = newstr(buf);
228a44d5a5eSeric 
229b7d7afcbSeric 			(void) close(DaemonSocket);
2301c71e510Seric 			InChannel = fdopen(t, "r");
2311d5bd586Seric 			OutChannel = fdopen(dup(t), "w");
232d0a9e852Seric # ifdef DEBUG
23361e4310fSeric 			if (tTd(15, 2))
234d0a9e852Seric 				printf("getreq: returning\n");
235d0a9e852Seric # endif DEBUG
236252c8a22Seric # ifdef LOG
237252c8a22Seric 			if (LogLevel > 11)
238252c8a22Seric 				syslog(LOG_DEBUG, "connected, pid=%d", getpid());
239252c8a22Seric # endif LOG
240a8268164Seric 			return;
241a8268164Seric 		}
242a8268164Seric 
243*3c154354Seric 		/*
244*3c154354Seric 		**  PARENT -- wait for child to terminate.
245*3c154354Seric 		**	Perhaps we should allow concurrent processing?
2468e3e4b17Seric 		*/
2478e3e4b17Seric 
248*3c154354Seric # ifdef DEBUG
249*3c154354Seric 		if (tTd(15, 2))
2508e3e4b17Seric 		{
251*3c154354Seric 			sleep(2);
252*3c154354Seric 			printf("getreq: parent waiting\n");
253*3c154354Seric 		}
254*3c154354Seric # endif DEBUG
2558e3e4b17Seric 
256*3c154354Seric 		/* close the port so that others will hang (for a while) */
257*3c154354Seric 		(void) close(t);
258*3c154354Seric 
259*3c154354Seric 		/* pick up old zombies */
260*3c154354Seric 		while (wait3(&status, WNOHANG, (struct rusage *) 0) > 0)
2618e3e4b17Seric 			continue;
2628e3e4b17Seric 	}
263*3c154354Seric 	/*NOTREACHED*/
264*3c154354Seric }
2658e3e4b17Seric /*
266b7d7afcbSeric **  CLRDAEMON -- reset the daemon connection
267b7d7afcbSeric **
268b7d7afcbSeric **	Parameters:
269b7d7afcbSeric **		none.
270b7d7afcbSeric **
271b7d7afcbSeric **	Returns:
272b7d7afcbSeric **		none.
273b7d7afcbSeric **
274b7d7afcbSeric **	Side Effects:
275b7d7afcbSeric **		releases any resources used by the passive daemon.
276b7d7afcbSeric */
277b7d7afcbSeric 
278b7d7afcbSeric clrdaemon()
279b7d7afcbSeric {
280b7d7afcbSeric 	if (DaemonSocket >= 0)
281b7d7afcbSeric 		(void) close(DaemonSocket);
282b7d7afcbSeric 	DaemonSocket = -1;
283b7d7afcbSeric }
284b7d7afcbSeric /*
2857aa493c5Seric **  MAKECONNECTION -- make a connection to an SMTP socket on another machine.
2867aa493c5Seric **
2877aa493c5Seric **	Parameters:
2887aa493c5Seric **		host -- the name of the host.
28948ff0a9dSeric **		port -- the port number to connect to.
2907aa493c5Seric **		outfile -- a pointer to a place to put the outfile
2917aa493c5Seric **			descriptor.
2927aa493c5Seric **		infile -- ditto for infile.
2937aa493c5Seric **
2947aa493c5Seric **	Returns:
2957aa493c5Seric **		An exit code telling whether the connection could be
2967aa493c5Seric **			made and if not why not.
2977aa493c5Seric **
2987aa493c5Seric **	Side Effects:
2997aa493c5Seric **		none.
3007aa493c5Seric */
3017aa493c5Seric 
30248ff0a9dSeric makeconnection(host, port, outfile, infile)
3037aa493c5Seric 	char *host;
304210215eaSeric 	u_short port;
3057aa493c5Seric 	FILE **outfile;
3067aa493c5Seric 	FILE **infile;
3077aa493c5Seric {
3087aa493c5Seric 	register int s;
3097aa493c5Seric 
3107aa493c5Seric 	/*
3117aa493c5Seric 	**  Set up the address for the mailer.
31271096d12Seric 	**	Accept "[a.b.c.d]" syntax for host name.
3137aa493c5Seric 	*/
3147aa493c5Seric 
31571096d12Seric 	if (host[0] == '[')
31671096d12Seric 	{
317a44d5a5eSeric 		long hid;
318a44d5a5eSeric 		register char *p = index(host, ']');
31971096d12Seric 
320a44d5a5eSeric 		if (p != NULL)
32171096d12Seric 		{
322a44d5a5eSeric 			*p = '\0';
323a44d5a5eSeric 			hid = inet_addr(&host[1]);
324a44d5a5eSeric 			*p = ']';
32571096d12Seric 		}
326a44d5a5eSeric 		if (p == NULL || hid == -1)
32771096d12Seric 		{
32871096d12Seric 			usrerr("Invalid numeric domain spec \"%s\"", host);
32971096d12Seric 			return (EX_NOHOST);
33071096d12Seric 		}
33171096d12Seric 		SendmailAddress.sin_addr.s_addr = hid;
33271096d12Seric 	}
3331c71e510Seric 	else
3341c71e510Seric 	{
3351c71e510Seric 		register struct hostent *hp = gethostbyname(host);
3361c71e510Seric 
337a44d5a5eSeric 		if (hp == NULL)
3387aa493c5Seric 			return (EX_NOHOST);
33929dcf4baSeric 		bcopy(hp->h_addr, (char *) &SendmailAddress.sin_addr, hp->h_length);
3401c71e510Seric 	}
3411c71e510Seric 
3421c71e510Seric 	/*
3431c71e510Seric 	**  Determine the port number.
3441c71e510Seric 	*/
3451c71e510Seric 
346fd7c0790Seric 	if (port != 0)
347fd7c0790Seric 		SendmailAddress.sin_port = htons(port);
348fd7c0790Seric 	else
3491c71e510Seric 	{
3501c71e510Seric 		register struct servent *sp = getservbyname("smtp", "tcp");
3511c71e510Seric 
3521c71e510Seric 		if (sp == NULL)
3531c71e510Seric 		{
3541c71e510Seric 			syserr("makeconnection: server \"smtp\" unknown");
3551c71e510Seric 			return (EX_OSFILE);
3561c71e510Seric 		}
357fd7c0790Seric 		SendmailAddress.sin_port = sp->s_port;
3581c71e510Seric 	}
3597aa493c5Seric 
3607aa493c5Seric 	/*
3617aa493c5Seric 	**  Try to actually open the connection.
3627aa493c5Seric 	*/
3637aa493c5Seric 
3647aa493c5Seric # ifdef DEBUG
36561e4310fSeric 	if (tTd(16, 1))
3667aa493c5Seric 		printf("makeconnection (%s)\n", host);
3677aa493c5Seric # endif DEBUG
3687aa493c5Seric 
369af5e902cSeric 	s = socket(AF_INET, SOCK_STREAM, 0);
3707aa493c5Seric 	if (s < 0)
3717aa493c5Seric 	{
3727aa493c5Seric 		syserr("makeconnection: no socket");
3737aa493c5Seric 		goto failure;
3747aa493c5Seric 	}
3757aa493c5Seric 
3767aa493c5Seric # ifdef DEBUG
37761e4310fSeric 	if (tTd(16, 1))
3787aa493c5Seric 		printf("makeconnection: %d\n", s);
3791b6e4a15Seric 
3801b6e4a15Seric 	/* turn on network debugging? */
3811b6e4a15Seric 	if (tTd(16, 14))
382*3c154354Seric 		(void) setsockopt(s, SOL_SOCKET, SO_DEBUG, 0, 0);
3837aa493c5Seric # endif DEBUG
384877a6142Seric 	(void) fflush(CurEnv->e_xfp);			/* for debugging */
3854bd6a662Seric 	errno = 0;					/* for debugging */
3861c71e510Seric 	SendmailAddress.sin_family = AF_INET;
387af5e902cSeric 	if (connect(s, &SendmailAddress, sizeof SendmailAddress) < 0)
3887aa493c5Seric 	{
3897aa493c5Seric 		/* failure, decide if temporary or not */
3907aa493c5Seric 	failure:
3917aa493c5Seric 		switch (errno)
3927aa493c5Seric 		{
3937aa493c5Seric 		  case EISCONN:
3947aa493c5Seric 		  case ETIMEDOUT:
395292668b9Seric 		  case EINPROGRESS:
396292668b9Seric 		  case EALREADY:
397292668b9Seric 		  case EADDRINUSE:
39836bd23a8Seric 		  case EHOSTDOWN:
399292668b9Seric 		  case ENETDOWN:
400292668b9Seric 		  case ENETRESET:
401292668b9Seric 		  case ENOBUFS:
402a1645df8Seric 		  case ECONNREFUSED:
403efe49624Seric 		  case ECONNRESET:
404cae8261aSeric 		  case EHOSTUNREACH:
405dca8e1f7Seric 		  case ENETUNREACH:
4067aa493c5Seric 			/* there are others, I'm sure..... */
40729dcf4baSeric 			CurEnv->e_flags &= ~EF_FATALERRS;
4087aa493c5Seric 			return (EX_TEMPFAIL);
4097aa493c5Seric 
410a44d5a5eSeric 		  case EPERM:
411a44d5a5eSeric 			/* why is this happening? */
412a44d5a5eSeric 			syserr("makeconnection: funny failure, addr=%lx, port=%x",
413a44d5a5eSeric 				SendmailAddress.sin_addr.s_addr, SendmailAddress.sin_port);
4144bd6a662Seric 			return (EX_TEMPFAIL);
415a44d5a5eSeric 
4167aa493c5Seric 		  default:
4177aa493c5Seric 			return (EX_UNAVAILABLE);
4187aa493c5Seric 		}
4197aa493c5Seric 	}
4207aa493c5Seric 
4217aa493c5Seric 	/* connection ok, put it into canonical form */
4227aa493c5Seric 	*outfile = fdopen(s, "w");
4237aa493c5Seric 	*infile = fdopen(s, "r");
4247aa493c5Seric 
425dca8e1f7Seric 	return (EX_OK);
4267aa493c5Seric }
427444eaf03Seric /*
428444eaf03Seric **  MYHOSTNAME -- return the name of this host.
429444eaf03Seric **
430444eaf03Seric **	Parameters:
431444eaf03Seric **		hostbuf -- a place to return the name of this host.
432897f1869Seric **		size -- the size of hostbuf.
433444eaf03Seric **
434444eaf03Seric **	Returns:
435444eaf03Seric **		A list of aliases for this host.
436444eaf03Seric **
437444eaf03Seric **	Side Effects:
438444eaf03Seric **		none.
439444eaf03Seric */
440444eaf03Seric 
441444eaf03Seric char **
442897f1869Seric myhostname(hostbuf, size)
443444eaf03Seric 	char hostbuf[];
444897f1869Seric 	int size;
445444eaf03Seric {
446444eaf03Seric 	extern struct hostent *gethostbyname();
447a44d5a5eSeric 	struct hostent *hp;
448444eaf03Seric 
449af5e902cSeric 	if (gethostname(hostbuf, size) < 0)
450af5e902cSeric 	{
451af5e902cSeric 		(void) strcpy(hostbuf, "localhost");
452af5e902cSeric 	}
453a44d5a5eSeric 	hp = gethostbyname(hostbuf);
454a44d5a5eSeric 	if (hp != NULL)
4557364df9fSeric 	{
456fefbbe29Seric 		(void) strcpy(hostbuf, hp->h_name);
457a44d5a5eSeric 		return (hp->h_aliases);
4587364df9fSeric 	}
459444eaf03Seric 	else
460444eaf03Seric 		return (NULL);
461444eaf03Seric }
46299f7cf32Seric /*
46399f7cf32Seric **  MAPHOSTNAME -- turn a hostname into canonical form
46499f7cf32Seric **
46599f7cf32Seric **	Parameters:
46699f7cf32Seric **		hbuf -- a buffer containing a hostname.
46799f7cf32Seric **		hbsize -- the size of hbuf.
46899f7cf32Seric **
46999f7cf32Seric **	Returns:
47099f7cf32Seric **		none.
47199f7cf32Seric **
47299f7cf32Seric **	Side Effects:
47399f7cf32Seric **		Looks up the host specified in hbuf.  If it is not
47499f7cf32Seric **		the canonical name for that host, replace it with
47599f7cf32Seric **		the canonical name.  If the name is unknown, or it
47699f7cf32Seric **		is already the canonical name, leave it unchanged.
47799f7cf32Seric */
478444eaf03Seric 
47999f7cf32Seric maphostname(hbuf, hbsize)
48099f7cf32Seric 	char *hbuf;
48199f7cf32Seric 	int hbsize;
48299f7cf32Seric {
48399f7cf32Seric 	register struct hostent *hp;
48499f7cf32Seric 	extern struct hostent *gethostbyname();
48599f7cf32Seric 
48699f7cf32Seric 	makelower(hbuf);
48799f7cf32Seric 	hp = gethostbyname(hbuf);
48899f7cf32Seric 	if (hp != NULL)
48999f7cf32Seric 	{
49099f7cf32Seric 		int i = strlen(hp->h_name);
49199f7cf32Seric 
49299f7cf32Seric 		if (i >= hbsize)
49399f7cf32Seric 			hp->h_name[--i] = '\0';
494fefbbe29Seric 		(void) strcpy(hbuf, hp->h_name);
49599f7cf32Seric 	}
49699f7cf32Seric }
49799f7cf32Seric 
498444eaf03Seric # else DAEMON
49999f7cf32Seric /* code for systems without sophisticated networking */
500444eaf03Seric 
501444eaf03Seric /*
502444eaf03Seric **  MYHOSTNAME -- stub version for case of no daemon code.
50321e9914dSeric **
50421e9914dSeric **	Can't convert to upper case here because might be a UUCP name.
505897f1869Seric **
506897f1869Seric **	Mark, you can change this to be anything you want......
507444eaf03Seric */
508444eaf03Seric 
509444eaf03Seric char **
510897f1869Seric myhostname(hostbuf, size)
511444eaf03Seric 	char hostbuf[];
512897f1869Seric 	int size;
513444eaf03Seric {
514444eaf03Seric 	register FILE *f;
515444eaf03Seric 
516444eaf03Seric 	hostbuf[0] = '\0';
517444eaf03Seric 	f = fopen("/usr/include/whoami", "r");
518444eaf03Seric 	if (f != NULL)
519444eaf03Seric 	{
520897f1869Seric 		(void) fgets(hostbuf, size, f);
521444eaf03Seric 		fixcrlf(hostbuf, TRUE);
522444eaf03Seric 		(void) fclose(f);
523444eaf03Seric 	}
524444eaf03Seric 	return (NULL);
525444eaf03Seric }
52699f7cf32Seric /*
52799f7cf32Seric **  MAPHOSTNAME -- turn a hostname into canonical form
52899f7cf32Seric **
52999f7cf32Seric **	Parameters:
53099f7cf32Seric **		hbuf -- a buffer containing a hostname.
53199f7cf32Seric **		hbsize -- the size of hbuf.
53299f7cf32Seric **
53399f7cf32Seric **	Returns:
53499f7cf32Seric **		none.
53599f7cf32Seric **
53699f7cf32Seric **	Side Effects:
53799f7cf32Seric **		Looks up the host specified in hbuf.  If it is not
53899f7cf32Seric **		the canonical name for that host, replace it with
53999f7cf32Seric **		the canonical name.  If the name is unknown, or it
54099f7cf32Seric **		is already the canonical name, leave it unchanged.
54199f7cf32Seric */
54299f7cf32Seric 
54399f7cf32Seric /*ARGSUSED*/
54499f7cf32Seric maphostname(hbuf, hbsize)
54599f7cf32Seric 	char *hbuf;
54699f7cf32Seric 	int hbsize;
54799f7cf32Seric {
54899f7cf32Seric 	return;
54999f7cf32Seric }
55099f7cf32Seric 
551d0a9e852Seric 
552d0a9e852Seric #endif DAEMON
553