xref: /csrg-svn/usr.sbin/sendmail/src/daemon.c (revision 53751)
122700Sdist /*
234920Sbostic  * Copyright (c) 1983 Eric P. Allman
333780Sbostic  * Copyright (c) 1988 Regents of the University of California.
433780Sbostic  * All rights reserved.
533780Sbostic  *
642825Sbostic  * %sccs.include.redist.c%
733780Sbostic  */
822700Sdist 
933932Sbostic #include <errno.h>
1040962Sbostic #include "sendmail.h"
114535Seric 
1233780Sbostic #ifndef lint
1333780Sbostic #ifdef DAEMON
14*53751Seric static char sccsid[] = "@(#)daemon.c	5.45 (Berkeley) 05/31/92 (with daemon mode)";
1533780Sbostic #else
16*53751Seric static char sccsid[] = "@(#)daemon.c	5.45 (Berkeley) 05/31/92 (without daemon mode)";
1733780Sbostic #endif
1833780Sbostic #endif /* not lint */
194535Seric 
2033780Sbostic #ifdef DAEMON
2133780Sbostic 
2223120Seric # include <netdb.h>
2324945Seric # include <sys/signal.h>
2423120Seric # include <sys/wait.h>
2523120Seric # include <sys/time.h>
2623120Seric # include <sys/resource.h>
275978Seric 
284535Seric /*
294535Seric **  DAEMON.C -- routines to use when running as a daemon.
307556Seric **
317556Seric **	This entire file is highly dependent on the 4.2 BSD
327556Seric **	interprocess communication primitives.  No attempt has
337556Seric **	been made to make this file portable to Version 7,
347556Seric **	Version 6, MPX files, etc.  If you should try such a
357556Seric **	thing yourself, I recommend chucking the entire file
367556Seric **	and starting from scratch.  Basic semantics are:
377556Seric **
387556Seric **	getrequests()
397556Seric **		Opens a port and initiates a connection.
407556Seric **		Returns in a child.  Must set InChannel and
417556Seric **		OutChannel appropriately.
4210206Seric **	clrdaemon()
4310206Seric **		Close any open files associated with getting
4410206Seric **		the connection; this is used when running the queue,
4510206Seric **		etc., to avoid having extra file descriptors during
4610206Seric **		the queue run and to avoid confusing the network
4710206Seric **		code (if it cares).
4852106Seric **	makeconnection(host, port, outfile, infile, usesecureport)
497556Seric **		Make a connection to the named host on the given
507556Seric **		port.  Set *outfile and *infile to the files
517556Seric **		appropriate for communication.  Returns zero on
527556Seric **		success, else an exit status describing the
537556Seric **		error.
5425699Seric **	maphostname(hbuf, hbufsize)
5525699Seric **		Convert the entry in hbuf into a canonical form.  It
5625699Seric **		may not be larger than hbufsize.
574535Seric */
584535Seric /*
594535Seric **  GETREQUESTS -- open mail IPC port and get requests.
604535Seric **
614535Seric **	Parameters:
624535Seric **		none.
634535Seric **
644535Seric **	Returns:
654535Seric **		none.
664535Seric **
674535Seric **	Side Effects:
684535Seric **		Waits until some interesting activity occurs.  When
694535Seric **		it does, a child is created to process it, and the
704535Seric **		parent waits for completion.  Return from this
719886Seric **		routine is always in the child.  The file pointers
729886Seric **		"InChannel" and "OutChannel" should be set to point
739886Seric **		to the communication channel.
744535Seric */
754535Seric 
7616144Seric int	DaemonSocket	= -1;		/* fd describing socket */
7716144Seric 
784535Seric getrequests()
794535Seric {
809610Seric 	int t;
819610Seric 	register struct servent *sp;
8225027Seric 	int on = 1;
83*53751Seric 	bool refusingconnections = TRUE;
8452106Seric 	struct sockaddr_in srvraddr;
8546928Sbostic 	extern void reapchild();
867117Seric 
879610Seric 	/*
889610Seric 	**  Set up the address for the mailer.
899610Seric 	*/
909610Seric 
919610Seric 	sp = getservbyname("smtp", "tcp");
929610Seric 	if (sp == NULL)
939610Seric 	{
949610Seric 		syserr("server \"smtp\" unknown");
9510167Seric 		goto severe;
969610Seric 	}
9752106Seric 	srvraddr.sin_family = AF_INET;
9852106Seric 	srvraddr.sin_addr.s_addr = INADDR_ANY;
9952106Seric 	srvraddr.sin_port = sp->s_port;
1009610Seric 
1019610Seric 	/*
1029610Seric 	**  Try to actually open the connection.
1039610Seric 	*/
1049610Seric 
1059610Seric 	if (tTd(15, 1))
10652106Seric 		printf("getrequests: port 0x%x\n", srvraddr.sin_port);
1079610Seric 
1089610Seric 	/* get a socket for the SMTP connection */
10923120Seric 	DaemonSocket = socket(AF_INET, SOCK_STREAM, 0);
11010206Seric 	if (DaemonSocket < 0)
1119610Seric 	{
1129610Seric 		/* probably another daemon already */
1139610Seric 		syserr("getrequests: can't create socket");
1149610Seric 	  severe:
1159610Seric # ifdef LOG
1169610Seric 		if (LogLevel > 0)
11724858Seric 			syslog(LOG_ALERT, "cannot get connection");
1189610Seric # endif LOG
1199610Seric 		finis();
1209610Seric 	}
12110347Seric 
12210347Seric 	/* turn on network debugging? */
12310347Seric 	if (tTd(15, 15))
12424945Seric 		(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof on);
12510347Seric 
12625027Seric 	(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof on);
12725027Seric 	(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof on);
12825027Seric 
12952106Seric 	if (bind(DaemonSocket, (struct sockaddr *)&srvraddr, sizeof srvraddr) < 0)
1309610Seric 	{
1319610Seric 		syserr("getrequests: cannot bind");
13210206Seric 		(void) close(DaemonSocket);
1339610Seric 		goto severe;
1349610Seric 	}
1359610Seric 
13624955Seric 	(void) signal(SIGCHLD, reapchild);
13724945Seric 
1389610Seric 	if (tTd(15, 1))
13910206Seric 		printf("getrequests: %d\n", DaemonSocket);
1409610Seric 
1414631Seric 	for (;;)
1424631Seric 	{
14314875Seric 		register int pid;
14411147Seric 		auto int lotherend;
145*53751Seric 		extern bool refuseconnections();
14611147Seric 
14714875Seric 		/* see if we are rejecting connections */
148*53751Seric 		CurrentLA = getla();
149*53751Seric 		if (refuseconnections())
15036584Sbostic 		{
151*53751Seric 			if (!refusingconnections)
152*53751Seric 			{
153*53751Seric 				/* don't queue so peer will fail quickly */
154*53751Seric 				(void) listen(DaemonSocket, 0);
155*53751Seric 				refusingconnections = TRUE;
156*53751Seric 			}
157*53751Seric 			setproctitle("rejecting connections: load average: %.2f",
158*53751Seric 				(double)CurrentLA);
15914875Seric 			sleep(5);
160*53751Seric 			continue;
16136584Sbostic 		}
16214875Seric 
163*53751Seric 		if (refusingconnections)
164*53751Seric 		{
165*53751Seric 			/* start listening again */
166*53751Seric 			if (listen(DaemonSocket, 10) < 0)
167*53751Seric 			{
168*53751Seric 				syserr("getrequests: cannot listen");
169*53751Seric 				(void) close(DaemonSocket);
170*53751Seric 				goto severe;
171*53751Seric 			}
172*53751Seric 			setproctitle("accepting connections");
173*53751Seric 			refusingconnections = FALSE;
174*53751Seric 		}
175*53751Seric 
1769610Seric 		/* wait for a connection */
1779610Seric 		do
1789610Seric 		{
1799610Seric 			errno = 0;
18036230Skarels 			lotherend = sizeof RealHostAddr;
18146928Sbostic 			t = accept(DaemonSocket,
18246928Sbostic 			    (struct sockaddr *)&RealHostAddr, &lotherend);
1839610Seric 		} while (t < 0 && errno == EINTR);
1849610Seric 		if (t < 0)
1855978Seric 		{
1869610Seric 			syserr("getrequests: accept");
1879610Seric 			sleep(5);
1889610Seric 			continue;
1895978Seric 		}
1904631Seric 
1915978Seric 		/*
1925978Seric 		**  Create a subprocess to process the mail.
1935978Seric 		*/
1945978Seric 
1957677Seric 		if (tTd(15, 2))
1969610Seric 			printf("getrequests: forking (fd = %d)\n", t);
1975978Seric 
1984636Seric 		pid = fork();
1994636Seric 		if (pid < 0)
2004631Seric 		{
2014636Seric 			syserr("daemon: cannot fork");
2024636Seric 			sleep(10);
2039610Seric 			(void) close(t);
2044636Seric 			continue;
2054631Seric 		}
2064631Seric 
2074636Seric 		if (pid == 0)
2084631Seric 		{
20911147Seric 			extern struct hostent *gethostbyaddr();
21011147Seric 			register struct hostent *hp;
21111147Seric 			char buf[MAXNAME];
21211147Seric 
2134636Seric 			/*
2144636Seric 			**  CHILD -- return to caller.
21511147Seric 			**	Collect verified idea of sending host.
2164636Seric 			**	Verify calling user id if possible here.
2174636Seric 			*/
2184631Seric 
21924955Seric 			(void) signal(SIGCHLD, SIG_DFL);
22024950Seric 
22111147Seric 			/* determine host name */
22236230Skarels 			hp = gethostbyaddr((char *) &RealHostAddr.sin_addr, sizeof RealHostAddr.sin_addr, AF_INET);
22311147Seric 			if (hp != NULL)
22423104Seric 				(void) strcpy(buf, hp->h_name);
22511147Seric 			else
22616884Seric 			{
22716884Seric 				extern char *inet_ntoa();
22816884Seric 
22916884Seric 				/* produce a dotted quad */
23016884Seric 				(void) sprintf(buf, "[%s]",
23136230Skarels 					inet_ntoa(RealHostAddr.sin_addr));
23216884Seric 			}
23316884Seric 
23416884Seric 			/* should we check for illegal connection here? XXX */
23516884Seric 
23611147Seric 			RealHostName = newstr(buf);
23711147Seric 
23810206Seric 			(void) close(DaemonSocket);
2399610Seric 			InChannel = fdopen(t, "r");
24021062Seric 			OutChannel = fdopen(dup(t), "w");
2417677Seric 			if (tTd(15, 2))
2425978Seric 				printf("getreq: returning\n");
2437876Seric # ifdef LOG
2447876Seric 			if (LogLevel > 11)
2457876Seric 				syslog(LOG_DEBUG, "connected, pid=%d", getpid());
2467876Seric # endif LOG
2474636Seric 			return;
2484631Seric 		}
2494631Seric 
2507117Seric 		/* close the port so that others will hang (for a while) */
2519610Seric 		(void) close(t);
2524631Seric 	}
2539886Seric 	/*NOTREACHED*/
2544631Seric }
2555978Seric /*
25610206Seric **  CLRDAEMON -- reset the daemon connection
25710206Seric **
25810206Seric **	Parameters:
25910206Seric **		none.
26010206Seric **
26110206Seric **	Returns:
26210206Seric **		none.
26310206Seric **
26410206Seric **	Side Effects:
26510206Seric **		releases any resources used by the passive daemon.
26610206Seric */
26710206Seric 
26810206Seric clrdaemon()
26910206Seric {
27010206Seric 	if (DaemonSocket >= 0)
27110206Seric 		(void) close(DaemonSocket);
27210206Seric 	DaemonSocket = -1;
27310206Seric }
27410206Seric /*
2756039Seric **  MAKECONNECTION -- make a connection to an SMTP socket on another machine.
2766039Seric **
2776039Seric **	Parameters:
2786039Seric **		host -- the name of the host.
2796633Seric **		port -- the port number to connect to.
28053739Seric **		mci -- a pointer to the mail connection information
28153739Seric **			structure to be filled in.
28252106Seric **		usesecureport -- if set, use a low numbered (reserved)
28352106Seric **			port to provide some rudimentary authentication.
2846039Seric **
2856039Seric **	Returns:
2866039Seric **		An exit code telling whether the connection could be
2876039Seric **			made and if not why not.
2886039Seric **
2896039Seric **	Side Effects:
2906039Seric **		none.
2916039Seric */
2925978Seric 
29353739Seric makeconnection(host, port, mci, usesecureport)
2946039Seric 	char *host;
2957286Seric 	u_short port;
29653739Seric 	register MCONINFO *mci;
29752106Seric 	bool usesecureport;
2986039Seric {
29929430Sbloom 	register int i, s;
30029430Sbloom 	register struct hostent *hp = (struct hostent *)NULL;
30152106Seric 	struct sockaddr_in addr;
30252106Seric 	int sav_errno;
30329430Sbloom 	extern char *inet_ntoa();
30435651Seric #ifdef NAMED_BIND
30535651Seric 	extern int h_errno;
30635651Seric #endif
3076039Seric 
3086039Seric 	/*
3096039Seric 	**  Set up the address for the mailer.
3109308Seric 	**	Accept "[a.b.c.d]" syntax for host name.
3116039Seric 	*/
3126039Seric 
31335651Seric #ifdef NAMED_BIND
31425475Smiriam 	h_errno = 0;
31535651Seric #endif
31625475Smiriam 	errno = 0;
31725475Smiriam 
3189308Seric 	if (host[0] == '[')
3199308Seric 	{
32011147Seric 		long hid;
32111147Seric 		register char *p = index(host, ']');
3229308Seric 
32311147Seric 		if (p != NULL)
3249308Seric 		{
32511147Seric 			*p = '\0';
32611147Seric 			hid = inet_addr(&host[1]);
32711147Seric 			*p = ']';
3289308Seric 		}
32911147Seric 		if (p == NULL || hid == -1)
3309308Seric 		{
3319308Seric 			usrerr("Invalid numeric domain spec \"%s\"", host);
3329308Seric 			return (EX_NOHOST);
3339308Seric 		}
33452106Seric 		addr.sin_addr.s_addr = hid;
3359308Seric 	}
3369610Seric 	else
3379610Seric 	{
33829430Sbloom 		hp = gethostbyname(host);
33925475Smiriam 		if (hp == NULL)
34024945Seric 		{
34135651Seric #ifdef NAMED_BIND
34225475Smiriam 			if (errno == ETIMEDOUT || h_errno == TRY_AGAIN)
34325475Smiriam 				return (EX_TEMPFAIL);
34425657Seric 
34535651Seric 			/* if name server is specified, assume temp fail */
34635651Seric 			if (errno == ECONNREFUSED && UseNameServer)
34735651Seric 				return (EX_TEMPFAIL);
34835651Seric #endif
34935651Seric 
35025657Seric 			/*
35125657Seric 			**  XXX Should look for mail forwarder record here
35225657Seric 			**  XXX if (h_errno == NO_ADDRESS).
35325657Seric 			*/
35425657Seric 
35525475Smiriam 			return (EX_NOHOST);
35624945Seric 		}
35752106Seric 		bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length);
35829430Sbloom 		i = 1;
3599610Seric 	}
3609610Seric 
3619610Seric 	/*
3629610Seric 	**  Determine the port number.
3639610Seric 	*/
3649610Seric 
36510011Seric 	if (port != 0)
36652106Seric 		addr.sin_port = htons(port);
36710011Seric 	else
3689610Seric 	{
3699610Seric 		register struct servent *sp = getservbyname("smtp", "tcp");
3709610Seric 
3719610Seric 		if (sp == NULL)
3729610Seric 		{
3739610Seric 			syserr("makeconnection: server \"smtp\" unknown");
3749610Seric 			return (EX_OSFILE);
3759610Seric 		}
37652106Seric 		addr.sin_port = sp->s_port;
3779610Seric 	}
3786039Seric 
3796039Seric 	/*
3806039Seric 	**  Try to actually open the connection.
3816039Seric 	*/
3826039Seric 
38329430Sbloom again:
3847677Seric 	if (tTd(16, 1))
38529430Sbloom 		printf("makeconnection (%s [%s])\n", host,
38652106Seric 		    inet_ntoa(addr.sin_addr));
3876039Seric 
38852106Seric 	if (usesecureport)
38952106Seric 	{
39052106Seric 		int rport = IPPORT_RESERVED - 1;
39152106Seric 
39252106Seric 		s = rresvport(&rport);
39352106Seric 	}
39452106Seric 	else
39552106Seric 	{
39652106Seric 		s = socket(AF_INET, SOCK_STREAM, 0);
39752106Seric 	}
3986039Seric 	if (s < 0)
3996039Seric 	{
40052106Seric 		sav_errno = errno;
4016039Seric 		syserr("makeconnection: no socket");
4026039Seric 		goto failure;
4036039Seric 	}
4046039Seric 
4057677Seric 	if (tTd(16, 1))
4066039Seric 		printf("makeconnection: %d\n", s);
40710347Seric 
40810347Seric 	/* turn on network debugging? */
40910347Seric 	if (tTd(16, 14))
41024945Seric 	{
41124945Seric 		int on = 1;
41224945Seric 		(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof on);
41324945Seric 	}
41440932Srick 	if (CurEnv->e_xfp != NULL)
41540932Srick 		(void) fflush(CurEnv->e_xfp);		/* for debugging */
41614383Seric 	errno = 0;					/* for debugging */
41752106Seric 	addr.sin_family = AF_INET;
41852106Seric 	if (connect(s, (struct sockaddr *) &addr, sizeof addr) < 0)
4196039Seric 	{
42027744Sbloom 		sav_errno = errno;
42127744Sbloom 		(void) close(s);
42229430Sbloom 		if (hp && hp->h_addr_list[i])
42329430Sbloom 		{
42452106Seric 			bcopy(hp->h_addr_list[i++], (char *) &addr.sin_addr,
42552106Seric 					hp->h_length);
42629430Sbloom 			goto again;
42729430Sbloom 		}
42829430Sbloom 
4296039Seric 		/* failure, decide if temporary or not */
4306039Seric 	failure:
43127744Sbloom 		switch (sav_errno)
4326039Seric 		{
4336039Seric 		  case EISCONN:
4346039Seric 		  case ETIMEDOUT:
4356897Seric 		  case EINPROGRESS:
4366897Seric 		  case EALREADY:
4376897Seric 		  case EADDRINUSE:
43810123Seric 		  case EHOSTDOWN:
4396897Seric 		  case ENETDOWN:
4406897Seric 		  case ENETRESET:
4416897Seric 		  case ENOBUFS:
4427204Seric 		  case ECONNREFUSED:
44311546Seric 		  case ECONNRESET:
44410081Seric 		  case EHOSTUNREACH:
44510098Seric 		  case ENETUNREACH:
44651995Seric #ifdef ENOSR
44751995Seric 		  case ENOSR:
44851995Seric #endif
4496039Seric 			/* there are others, I'm sure..... */
4506039Seric 			return (EX_TEMPFAIL);
4516039Seric 
45211147Seric 		  case EPERM:
45311147Seric 			/* why is this happening? */
45411147Seric 			syserr("makeconnection: funny failure, addr=%lx, port=%x",
45552106Seric 				addr.sin_addr.s_addr, addr.sin_port);
45614383Seric 			return (EX_TEMPFAIL);
45711147Seric 
4586039Seric 		  default:
45940932Srick 			{
46040932Srick 				extern char *errstring();
46140932Srick 
46240932Srick 				message(Arpa_Info, "%s", errstring(sav_errno));
46340932Srick 				return (EX_UNAVAILABLE);
46440932Srick 			}
4656039Seric 		}
4666039Seric 	}
4676039Seric 
4686039Seric 	/* connection ok, put it into canonical form */
46953739Seric 	mci->mci_out = fdopen(s, "w");
47053739Seric 	mci->mci_in = fdopen(dup(s), "r");
4716039Seric 
47210098Seric 	return (EX_OK);
4736039Seric }
47410758Seric /*
47510758Seric **  MYHOSTNAME -- return the name of this host.
47610758Seric **
47710758Seric **	Parameters:
47810758Seric **		hostbuf -- a place to return the name of this host.
47912313Seric **		size -- the size of hostbuf.
48010758Seric **
48110758Seric **	Returns:
48210758Seric **		A list of aliases for this host.
48310758Seric **
48410758Seric **	Side Effects:
48510758Seric **		none.
48610758Seric */
4876039Seric 
48810758Seric char **
48912313Seric myhostname(hostbuf, size)
49010758Seric 	char hostbuf[];
49112313Seric 	int size;
49210758Seric {
49310758Seric 	extern struct hostent *gethostbyname();
49411147Seric 	struct hostent *hp;
49510758Seric 
49623120Seric 	if (gethostname(hostbuf, size) < 0)
49723120Seric 	{
49823120Seric 		(void) strcpy(hostbuf, "localhost");
49923120Seric 	}
50011147Seric 	hp = gethostbyname(hostbuf);
50111147Seric 	if (hp != NULL)
50216877Seric 	{
50323104Seric 		(void) strcpy(hostbuf, hp->h_name);
50411147Seric 		return (hp->h_aliases);
50516877Seric 	}
50610758Seric 	else
50710758Seric 		return (NULL);
50810758Seric }
50951315Seric /*
510*53751Seric **  MAPHOSTNAME -- turn a hostname into canonical form
511*53751Seric **
512*53751Seric **	Parameters:
513*53751Seric **		hbuf -- a buffer containing a hostname.
514*53751Seric **		hbsize -- the size of hbuf.
515*53751Seric **
516*53751Seric **	Returns:
517*53751Seric **		The mapping, if found.
518*53751Seric **		NULL if no mapping found.
519*53751Seric **
520*53751Seric **	Side Effects:
521*53751Seric **		Looks up the host specified in hbuf.  If it is not
522*53751Seric **		the canonical name for that host, return the canonical
523*53751Seric **		name.
524*53751Seric */
52551315Seric 
526*53751Seric char *
527*53751Seric maphostname(hbuf, hbsize, avp)
52816911Seric 	char *hbuf;
52916911Seric 	int hbsize;
530*53751Seric 	char **avp;
53116911Seric {
53216911Seric 	register struct hostent *hp;
53333932Sbostic 	u_long in_addr;
53440994Sbostic 	char ptr[256], *cp;
53533932Sbostic 	struct hostent *gethostbyaddr();
53616911Seric 
537*53751Seric 	/* allow room for trailing dot on correct match */
538*53751Seric 	if (ConfigLevel >= 2)
539*53751Seric 		hbsize--;
540*53751Seric 
54125574Smiriam 	/*
54233932Sbostic 	 * If first character is a bracket, then it is an address
54333932Sbostic 	 * lookup.  Address is copied into a temporary buffer to
54433932Sbostic 	 * strip the brackets and to preserve hbuf if address is
54533932Sbostic 	 * unknown.
54633932Sbostic 	 */
547*53751Seric 
54851315Seric 	if (*hbuf != '[')
549*53751Seric 	{
550*53751Seric 		if (getcanonname(hbuf, hbsize))
551*53751Seric 		{
552*53751Seric 			/* found a match -- add the trailing dot */
553*53751Seric 			if (ConfigLevel >= 2)
554*53751Seric 				(void) strcat(hbuf, ".");
555*53751Seric 			return hbuf;
556*53751Seric 		}
557*53751Seric 		else
558*53751Seric 			return NULL;
559*53751Seric 	}
56040994Sbostic 	if ((cp = index(strcpy(ptr, hbuf), ']')) == NULL)
561*53751Seric 		return (NULL);
56240994Sbostic 	*cp = '\0';
56333932Sbostic 	in_addr = inet_addr(&ptr[1]);
56433932Sbostic 	hp = gethostbyaddr((char *)&in_addr, sizeof(struct in_addr), AF_INET);
56533932Sbostic 	if (hp == NULL)
566*53751Seric 		return (NULL);
567*53751Seric 
568*53751Seric 	/* found a match -- copy and dot terminate */
56933932Sbostic 	if (strlen(hp->h_name) >= hbsize)
57033932Sbostic 		hp->h_name[hbsize - 1] = '\0';
571*53751Seric 	(void) strcpy(hbuf, hp->h_name);
572*53751Seric 	if (ConfigLevel >= 2)
573*53751Seric 		(void) strcat(hbuf, ".");
574*53751Seric 	return hbuf;
57533932Sbostic }
57616911Seric 
57710758Seric # else DAEMON
57816911Seric /* code for systems without sophisticated networking */
57910758Seric 
58010758Seric /*
58110758Seric **  MYHOSTNAME -- stub version for case of no daemon code.
58211297Seric **
58311297Seric **	Can't convert to upper case here because might be a UUCP name.
58412313Seric **
58512313Seric **	Mark, you can change this to be anything you want......
58610758Seric */
58710758Seric 
58810758Seric char **
58912313Seric myhostname(hostbuf, size)
59010758Seric 	char hostbuf[];
59112313Seric 	int size;
59210758Seric {
59310758Seric 	register FILE *f;
59410758Seric 
59510758Seric 	hostbuf[0] = '\0';
59610758Seric 	f = fopen("/usr/include/whoami", "r");
59710758Seric 	if (f != NULL)
59810758Seric 	{
59912313Seric 		(void) fgets(hostbuf, size, f);
60010758Seric 		fixcrlf(hostbuf, TRUE);
60110758Seric 		(void) fclose(f);
60210758Seric 	}
60310758Seric 	return (NULL);
60410758Seric }
60516911Seric /*
60616911Seric **  MAPHOSTNAME -- turn a hostname into canonical form
60716911Seric **
60816911Seric **	Parameters:
60916911Seric **		hbuf -- a buffer containing a hostname.
61016911Seric **		hbsize -- the size of hbuf.
611*53751Seric **		avp -- a pointer to a (cf file defined) argument vector.
61216911Seric **
61316911Seric **	Returns:
614*53751Seric **		mapped host name
61551315Seric **		FALSE otherwise.
61616911Seric **
61716911Seric **	Side Effects:
61816911Seric **		Looks up the host specified in hbuf.  If it is not
61916911Seric **		the canonical name for that host, replace it with
62016911Seric **		the canonical name.  If the name is unknown, or it
62116911Seric **		is already the canonical name, leave it unchanged.
62216911Seric */
62310758Seric 
62416911Seric /*ARGSUSED*/
625*53751Seric char *
626*53751Seric maphostname(hbuf, hbsize, avp)
62716911Seric 	char *hbuf;
62816911Seric 	int hbsize;
629*53751Seric 	char **avp;
63016911Seric {
631*53751Seric 	return NULL;
63216911Seric }
63316911Seric 
6345978Seric #endif DAEMON
635