xref: /csrg-svn/usr.sbin/sendmail/src/daemon.c (revision 57663)
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*57663Seric static char sccsid[] = "@(#)daemon.c	6.3 (Berkeley) 01/22/93 (with daemon mode)";
1533780Sbostic #else
16*57663Seric static char sccsid[] = "@(#)daemon.c	6.3 (Berkeley) 01/22/93 (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.
5456823Seric **	maphostname(map, hbuf, hbufsiz, avp)
5556823Seric **		Convert the entry in hbuf into a canonical form.
564535Seric */
574535Seric /*
584535Seric **  GETREQUESTS -- open mail IPC port and get requests.
594535Seric **
604535Seric **	Parameters:
614535Seric **		none.
624535Seric **
634535Seric **	Returns:
644535Seric **		none.
654535Seric **
664535Seric **	Side Effects:
674535Seric **		Waits until some interesting activity occurs.  When
684535Seric **		it does, a child is created to process it, and the
694535Seric **		parent waits for completion.  Return from this
709886Seric **		routine is always in the child.  The file pointers
719886Seric **		"InChannel" and "OutChannel" should be set to point
729886Seric **		to the communication channel.
734535Seric */
744535Seric 
7516144Seric int	DaemonSocket	= -1;		/* fd describing socket */
7616144Seric 
774535Seric getrequests()
784535Seric {
799610Seric 	int t;
809610Seric 	register struct servent *sp;
8125027Seric 	int on = 1;
8253751Seric 	bool refusingconnections = TRUE;
8352106Seric 	struct sockaddr_in srvraddr;
8446928Sbostic 	extern void reapchild();
857117Seric 
869610Seric 	/*
879610Seric 	**  Set up the address for the mailer.
889610Seric 	*/
899610Seric 
909610Seric 	sp = getservbyname("smtp", "tcp");
919610Seric 	if (sp == NULL)
929610Seric 	{
939610Seric 		syserr("server \"smtp\" unknown");
9410167Seric 		goto severe;
959610Seric 	}
9652106Seric 	srvraddr.sin_family = AF_INET;
9752106Seric 	srvraddr.sin_addr.s_addr = INADDR_ANY;
9852106Seric 	srvraddr.sin_port = sp->s_port;
999610Seric 
1009610Seric 	/*
1019610Seric 	**  Try to actually open the connection.
1029610Seric 	*/
1039610Seric 
1049610Seric 	if (tTd(15, 1))
10552106Seric 		printf("getrequests: port 0x%x\n", srvraddr.sin_port);
1069610Seric 
1079610Seric 	/* get a socket for the SMTP connection */
10823120Seric 	DaemonSocket = socket(AF_INET, SOCK_STREAM, 0);
10910206Seric 	if (DaemonSocket < 0)
1109610Seric 	{
1119610Seric 		/* probably another daemon already */
1129610Seric 		syserr("getrequests: can't create socket");
1139610Seric 	  severe:
1149610Seric # ifdef LOG
1159610Seric 		if (LogLevel > 0)
116*57663Seric 			syslog(LOG_ALERT, "problem creating SMTP socket");
11756795Seric # endif /* LOG */
1189610Seric 		finis();
1199610Seric 	}
12010347Seric 
12110347Seric 	/* turn on network debugging? */
12256328Seric 	if (tTd(15, 101))
12324945Seric 		(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof on);
12410347Seric 
12525027Seric 	(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof on);
12625027Seric 	(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof on);
12725027Seric 
12852106Seric 	if (bind(DaemonSocket, (struct sockaddr *)&srvraddr, sizeof srvraddr) < 0)
1299610Seric 	{
1309610Seric 		syserr("getrequests: cannot bind");
13110206Seric 		(void) close(DaemonSocket);
1329610Seric 		goto severe;
1339610Seric 	}
1349610Seric 
13524955Seric 	(void) signal(SIGCHLD, reapchild);
13624945Seric 
1379610Seric 	if (tTd(15, 1))
13810206Seric 		printf("getrequests: %d\n", DaemonSocket);
1399610Seric 
1404631Seric 	for (;;)
1414631Seric 	{
14214875Seric 		register int pid;
14311147Seric 		auto int lotherend;
14453751Seric 		extern bool refuseconnections();
14511147Seric 
14614875Seric 		/* see if we are rejecting connections */
14753751Seric 		CurrentLA = getla();
14853751Seric 		if (refuseconnections())
14936584Sbostic 		{
15053751Seric 			if (!refusingconnections)
15153751Seric 			{
15253751Seric 				/* don't queue so peer will fail quickly */
15353751Seric 				(void) listen(DaemonSocket, 0);
15453751Seric 				refusingconnections = TRUE;
15553751Seric 			}
15657385Seric 			setproctitle("rejecting connections: load average: %d",
15757385Seric 				CurrentLA);
15814875Seric 			sleep(5);
15953751Seric 			continue;
16036584Sbostic 		}
16114875Seric 
16253751Seric 		if (refusingconnections)
16353751Seric 		{
16453751Seric 			/* start listening again */
16553751Seric 			if (listen(DaemonSocket, 10) < 0)
16653751Seric 			{
16753751Seric 				syserr("getrequests: cannot listen");
16853751Seric 				(void) close(DaemonSocket);
16953751Seric 				goto severe;
17053751Seric 			}
17153751Seric 			setproctitle("accepting connections");
17253751Seric 			refusingconnections = FALSE;
17353751Seric 		}
17453751Seric 
1759610Seric 		/* wait for a connection */
1769610Seric 		do
1779610Seric 		{
1789610Seric 			errno = 0;
17936230Skarels 			lotherend = sizeof RealHostAddr;
18046928Sbostic 			t = accept(DaemonSocket,
18146928Sbostic 			    (struct sockaddr *)&RealHostAddr, &lotherend);
1829610Seric 		} while (t < 0 && errno == EINTR);
1839610Seric 		if (t < 0)
1845978Seric 		{
1859610Seric 			syserr("getrequests: accept");
1869610Seric 			sleep(5);
1879610Seric 			continue;
1885978Seric 		}
1894631Seric 
1905978Seric 		/*
1915978Seric 		**  Create a subprocess to process the mail.
1925978Seric 		*/
1935978Seric 
1947677Seric 		if (tTd(15, 2))
1959610Seric 			printf("getrequests: forking (fd = %d)\n", t);
1965978Seric 
1974636Seric 		pid = fork();
1984636Seric 		if (pid < 0)
1994631Seric 		{
2004636Seric 			syserr("daemon: cannot fork");
2014636Seric 			sleep(10);
2029610Seric 			(void) close(t);
2034636Seric 			continue;
2044631Seric 		}
2054631Seric 
2064636Seric 		if (pid == 0)
2074631Seric 		{
20811147Seric 			extern struct hostent *gethostbyaddr();
20911147Seric 			register struct hostent *hp;
21011147Seric 			char buf[MAXNAME];
21157135Seric 			extern char *inet_ntoa();
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 				/* produce a dotted quad */
22816884Seric 				(void) sprintf(buf, "[%s]",
22936230Skarels 					inet_ntoa(RealHostAddr.sin_addr));
23016884Seric 			}
23116884Seric 
23255173Seric #ifdef LOG
23355173Seric 			if (LogLevel > 9)
23455173Seric 			{
23555173Seric 				/* log connection information */
23655173Seric 				syslog(LOG_INFO, "connect from %s (%s)",
23755173Seric 					buf, inet_ntoa(RealHostAddr.sin_addr));
23855173Seric 			}
23955173Seric #endif
24055173Seric 
24116884Seric 			/* should we check for illegal connection here? XXX */
24216884Seric 
24311147Seric 			RealHostName = newstr(buf);
24411147Seric 
24510206Seric 			(void) close(DaemonSocket);
2469610Seric 			InChannel = fdopen(t, "r");
24721062Seric 			OutChannel = fdopen(dup(t), "w");
2487677Seric 			if (tTd(15, 2))
2495978Seric 				printf("getreq: returning\n");
2507876Seric # ifdef LOG
2517876Seric 			if (LogLevel > 11)
2527876Seric 				syslog(LOG_DEBUG, "connected, pid=%d", getpid());
25356795Seric # endif /* LOG */
2544636Seric 			return;
2554631Seric 		}
2564631Seric 
2577117Seric 		/* close the port so that others will hang (for a while) */
2589610Seric 		(void) close(t);
2594631Seric 	}
2609886Seric 	/*NOTREACHED*/
2614631Seric }
2625978Seric /*
26310206Seric **  CLRDAEMON -- reset the daemon connection
26410206Seric **
26510206Seric **	Parameters:
26610206Seric **		none.
26710206Seric **
26810206Seric **	Returns:
26910206Seric **		none.
27010206Seric **
27110206Seric **	Side Effects:
27210206Seric **		releases any resources used by the passive daemon.
27310206Seric */
27410206Seric 
27510206Seric clrdaemon()
27610206Seric {
27710206Seric 	if (DaemonSocket >= 0)
27810206Seric 		(void) close(DaemonSocket);
27910206Seric 	DaemonSocket = -1;
28010206Seric }
28110206Seric /*
2826039Seric **  MAKECONNECTION -- make a connection to an SMTP socket on another machine.
2836039Seric **
2846039Seric **	Parameters:
2856039Seric **		host -- the name of the host.
2866633Seric **		port -- the port number to connect to.
28753739Seric **		mci -- a pointer to the mail connection information
28853739Seric **			structure to be filled in.
28952106Seric **		usesecureport -- if set, use a low numbered (reserved)
29052106Seric **			port to provide some rudimentary authentication.
2916039Seric **
2926039Seric **	Returns:
2936039Seric **		An exit code telling whether the connection could be
2946039Seric **			made and if not why not.
2956039Seric **
2966039Seric **	Side Effects:
2976039Seric **		none.
2986039Seric */
2995978Seric 
30054967Seric int
30153739Seric makeconnection(host, port, mci, usesecureport)
3026039Seric 	char *host;
3037286Seric 	u_short port;
30454967Seric 	register MCI *mci;
30552106Seric 	bool usesecureport;
3066039Seric {
30729430Sbloom 	register int i, s;
30829430Sbloom 	register struct hostent *hp = (struct hostent *)NULL;
30952106Seric 	struct sockaddr_in addr;
31052106Seric 	int sav_errno;
31129430Sbloom 	extern char *inet_ntoa();
31235651Seric #ifdef NAMED_BIND
31335651Seric 	extern int h_errno;
31435651Seric #endif
3156039Seric 
3166039Seric 	/*
3176039Seric 	**  Set up the address for the mailer.
3189308Seric 	**	Accept "[a.b.c.d]" syntax for host name.
3196039Seric 	*/
3206039Seric 
32135651Seric #ifdef NAMED_BIND
32225475Smiriam 	h_errno = 0;
32335651Seric #endif
32425475Smiriam 	errno = 0;
32525475Smiriam 
3269308Seric 	if (host[0] == '[')
3279308Seric 	{
32811147Seric 		long hid;
32956795Seric 		register char *p = strchr(host, ']');
3309308Seric 
33111147Seric 		if (p != NULL)
3329308Seric 		{
33311147Seric 			*p = '\0';
33411147Seric 			hid = inet_addr(&host[1]);
33511147Seric 			*p = ']';
3369308Seric 		}
33711147Seric 		if (p == NULL || hid == -1)
3389308Seric 		{
3399308Seric 			usrerr("Invalid numeric domain spec \"%s\"", host);
3409308Seric 			return (EX_NOHOST);
3419308Seric 		}
34252106Seric 		addr.sin_addr.s_addr = hid;
3439308Seric 	}
3449610Seric 	else
3459610Seric 	{
34629430Sbloom 		hp = gethostbyname(host);
34725475Smiriam 		if (hp == NULL)
34824945Seric 		{
34935651Seric #ifdef NAMED_BIND
35025475Smiriam 			if (errno == ETIMEDOUT || h_errno == TRY_AGAIN)
35125475Smiriam 				return (EX_TEMPFAIL);
35225657Seric 
35335651Seric 			/* if name server is specified, assume temp fail */
35435651Seric 			if (errno == ECONNREFUSED && UseNameServer)
35535651Seric 				return (EX_TEMPFAIL);
35635651Seric #endif
35735651Seric 
35825657Seric 			/*
35925657Seric 			**  XXX Should look for mail forwarder record here
36025657Seric 			**  XXX if (h_errno == NO_ADDRESS).
36125657Seric 			*/
36225657Seric 
36325475Smiriam 			return (EX_NOHOST);
36424945Seric 		}
36552106Seric 		bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length);
36629430Sbloom 		i = 1;
3679610Seric 	}
3689610Seric 
3699610Seric 	/*
3709610Seric 	**  Determine the port number.
3719610Seric 	*/
3729610Seric 
37310011Seric 	if (port != 0)
37452106Seric 		addr.sin_port = htons(port);
37510011Seric 	else
3769610Seric 	{
3779610Seric 		register struct servent *sp = getservbyname("smtp", "tcp");
3789610Seric 
3799610Seric 		if (sp == NULL)
3809610Seric 		{
3819610Seric 			syserr("makeconnection: server \"smtp\" unknown");
3829610Seric 			return (EX_OSFILE);
3839610Seric 		}
38452106Seric 		addr.sin_port = sp->s_port;
3859610Seric 	}
3866039Seric 
3876039Seric 	/*
3886039Seric 	**  Try to actually open the connection.
3896039Seric 	*/
3906039Seric 
39129430Sbloom again:
3927677Seric 	if (tTd(16, 1))
39329430Sbloom 		printf("makeconnection (%s [%s])\n", host,
39452106Seric 		    inet_ntoa(addr.sin_addr));
3956039Seric 
39652106Seric 	if (usesecureport)
39752106Seric 	{
39852106Seric 		int rport = IPPORT_RESERVED - 1;
39952106Seric 
40052106Seric 		s = rresvport(&rport);
40152106Seric 	}
40252106Seric 	else
40352106Seric 	{
40452106Seric 		s = socket(AF_INET, SOCK_STREAM, 0);
40552106Seric 	}
4066039Seric 	if (s < 0)
4076039Seric 	{
40852106Seric 		sav_errno = errno;
4096039Seric 		syserr("makeconnection: no socket");
4106039Seric 		goto failure;
4116039Seric 	}
4126039Seric 
4137677Seric 	if (tTd(16, 1))
41454967Seric 		printf("makeconnection: fd=%d\n", s);
41510347Seric 
41610347Seric 	/* turn on network debugging? */
41756328Seric 	if (tTd(16, 101))
41824945Seric 	{
41924945Seric 		int on = 1;
42024945Seric 		(void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof on);
42124945Seric 	}
42240932Srick 	if (CurEnv->e_xfp != NULL)
42340932Srick 		(void) fflush(CurEnv->e_xfp);		/* for debugging */
42414383Seric 	errno = 0;					/* for debugging */
42552106Seric 	addr.sin_family = AF_INET;
42652106Seric 	if (connect(s, (struct sockaddr *) &addr, sizeof addr) < 0)
4276039Seric 	{
42827744Sbloom 		sav_errno = errno;
42927744Sbloom 		(void) close(s);
43029430Sbloom 		if (hp && hp->h_addr_list[i])
43129430Sbloom 		{
43252106Seric 			bcopy(hp->h_addr_list[i++], (char *) &addr.sin_addr,
43352106Seric 					hp->h_length);
43429430Sbloom 			goto again;
43529430Sbloom 		}
43629430Sbloom 
4376039Seric 		/* failure, decide if temporary or not */
4386039Seric 	failure:
43927744Sbloom 		switch (sav_errno)
4406039Seric 		{
4416039Seric 		  case EISCONN:
4426039Seric 		  case ETIMEDOUT:
4436897Seric 		  case EINPROGRESS:
4446897Seric 		  case EALREADY:
4456897Seric 		  case EADDRINUSE:
44610123Seric 		  case EHOSTDOWN:
4476897Seric 		  case ENETDOWN:
4486897Seric 		  case ENETRESET:
4496897Seric 		  case ENOBUFS:
4507204Seric 		  case ECONNREFUSED:
45111546Seric 		  case ECONNRESET:
45210081Seric 		  case EHOSTUNREACH:
45310098Seric 		  case ENETUNREACH:
45451995Seric #ifdef ENOSR
45551995Seric 		  case ENOSR:
45651995Seric #endif
4576039Seric 			/* there are others, I'm sure..... */
4586039Seric 			return (EX_TEMPFAIL);
4596039Seric 
46011147Seric 		  case EPERM:
46111147Seric 			/* why is this happening? */
46211147Seric 			syserr("makeconnection: funny failure, addr=%lx, port=%x",
46352106Seric 				addr.sin_addr.s_addr, addr.sin_port);
46414383Seric 			return (EX_TEMPFAIL);
46511147Seric 
4666039Seric 		  default:
46740932Srick 			{
46840932Srick 				extern char *errstring();
46940932Srick 
47040932Srick 				message(Arpa_Info, "%s", errstring(sav_errno));
47140932Srick 				return (EX_UNAVAILABLE);
47240932Srick 			}
4736039Seric 		}
4746039Seric 	}
4756039Seric 
4766039Seric 	/* connection ok, put it into canonical form */
47753739Seric 	mci->mci_out = fdopen(s, "w");
47853739Seric 	mci->mci_in = fdopen(dup(s), "r");
4796039Seric 
48010098Seric 	return (EX_OK);
4816039Seric }
48210758Seric /*
48310758Seric **  MYHOSTNAME -- return the name of this host.
48410758Seric **
48510758Seric **	Parameters:
48610758Seric **		hostbuf -- a place to return the name of this host.
48712313Seric **		size -- the size of hostbuf.
48810758Seric **
48910758Seric **	Returns:
49010758Seric **		A list of aliases for this host.
49110758Seric **
49210758Seric **	Side Effects:
49310758Seric **		none.
49410758Seric */
4956039Seric 
49610758Seric char **
49712313Seric myhostname(hostbuf, size)
49810758Seric 	char hostbuf[];
49912313Seric 	int size;
50010758Seric {
50110758Seric 	extern struct hostent *gethostbyname();
50211147Seric 	struct hostent *hp;
50310758Seric 
50423120Seric 	if (gethostname(hostbuf, size) < 0)
50523120Seric 	{
50623120Seric 		(void) strcpy(hostbuf, "localhost");
50723120Seric 	}
50811147Seric 	hp = gethostbyname(hostbuf);
50911147Seric 	if (hp != NULL)
51016877Seric 	{
51123104Seric 		(void) strcpy(hostbuf, hp->h_name);
51211147Seric 		return (hp->h_aliases);
51316877Seric 	}
51410758Seric 	else
51510758Seric 		return (NULL);
51610758Seric }
51751315Seric /*
51853751Seric **  MAPHOSTNAME -- turn a hostname into canonical form
51953751Seric **
52053751Seric **	Parameters:
52156823Seric **		map -- a pointer to this map (unused).
52253751Seric **		hbuf -- a buffer containing a hostname.
52353751Seric **		hbsize -- the size of hbuf.
52455019Seric **		avp -- unused -- for compatibility with other mapping
52555019Seric **			functions.
52653751Seric **
52753751Seric **	Returns:
52853751Seric **		The mapping, if found.
52953751Seric **		NULL if no mapping found.
53053751Seric **
53153751Seric **	Side Effects:
53253751Seric **		Looks up the host specified in hbuf.  If it is not
53353751Seric **		the canonical name for that host, return the canonical
53453751Seric **		name.
53553751Seric */
53651315Seric 
53753751Seric char *
53856823Seric maphostname(map, hbuf, hbsize, avp)
53956823Seric 	MAP *map;
54016911Seric 	char *hbuf;
54116911Seric 	int hbsize;
54253751Seric 	char **avp;
54316911Seric {
54416911Seric 	register struct hostent *hp;
54533932Sbostic 	u_long in_addr;
54656823Seric 	char *cp;
54733932Sbostic 	struct hostent *gethostbyaddr();
54816911Seric 
54956836Seric 	/* allow room for null */
55056823Seric 	hbsize--;
55153751Seric 
55225574Smiriam 	/*
55333932Sbostic 	 * If first character is a bracket, then it is an address
55433932Sbostic 	 * lookup.  Address is copied into a temporary buffer to
55533932Sbostic 	 * strip the brackets and to preserve hbuf if address is
55633932Sbostic 	 * unknown.
55733932Sbostic 	 */
55853751Seric 
55951315Seric 	if (*hbuf != '[')
56053751Seric 	{
56155019Seric 		extern bool getcanonname();
56255019Seric 
56353751Seric 		if (getcanonname(hbuf, hbsize))
56453751Seric 			return hbuf;
56553751Seric 		else
56653751Seric 			return NULL;
56753751Seric 	}
56856823Seric 	if ((cp = strchr(hbuf, ']')) == NULL)
56953751Seric 		return (NULL);
57040994Sbostic 	*cp = '\0';
57156823Seric 	in_addr = inet_addr(&hbuf[1]);
57233932Sbostic 	hp = gethostbyaddr((char *)&in_addr, sizeof(struct in_addr), AF_INET);
57333932Sbostic 	if (hp == NULL)
57453751Seric 		return (NULL);
57553751Seric 
57653751Seric 	/* found a match -- copy and dot terminate */
57756823Seric 	if (strlen(hp->h_name) > hbsize)
57856823Seric 		hp->h_name[hbsize] = '\0';
57953751Seric 	(void) strcpy(hbuf, hp->h_name);
58053751Seric 	return hbuf;
58133932Sbostic }
58216911Seric 
58356795Seric # else /* DAEMON */
58416911Seric /* code for systems without sophisticated networking */
58510758Seric 
58610758Seric /*
58710758Seric **  MYHOSTNAME -- stub version for case of no daemon code.
58811297Seric **
58911297Seric **	Can't convert to upper case here because might be a UUCP name.
59012313Seric **
59112313Seric **	Mark, you can change this to be anything you want......
59210758Seric */
59310758Seric 
59410758Seric char **
59512313Seric myhostname(hostbuf, size)
59610758Seric 	char hostbuf[];
59712313Seric 	int size;
59810758Seric {
59910758Seric 	register FILE *f;
60010758Seric 
60110758Seric 	hostbuf[0] = '\0';
60210758Seric 	f = fopen("/usr/include/whoami", "r");
60310758Seric 	if (f != NULL)
60410758Seric 	{
60512313Seric 		(void) fgets(hostbuf, size, f);
60610758Seric 		fixcrlf(hostbuf, TRUE);
60710758Seric 		(void) fclose(f);
60810758Seric 	}
60910758Seric 	return (NULL);
61010758Seric }
61116911Seric /*
61216911Seric **  MAPHOSTNAME -- turn a hostname into canonical form
61316911Seric **
61416911Seric **	Parameters:
61556823Seric **		map -- a pointer to the database map.
61616911Seric **		hbuf -- a buffer containing a hostname.
61753751Seric **		avp -- a pointer to a (cf file defined) argument vector.
61816911Seric **
61916911Seric **	Returns:
62053751Seric **		mapped host name
62151315Seric **		FALSE otherwise.
62216911Seric **
62316911Seric **	Side Effects:
62416911Seric **		Looks up the host specified in hbuf.  If it is not
62516911Seric **		the canonical name for that host, replace it with
62616911Seric **		the canonical name.  If the name is unknown, or it
62716911Seric **		is already the canonical name, leave it unchanged.
62816911Seric */
62910758Seric 
63016911Seric /*ARGSUSED*/
63153751Seric char *
63256823Seric maphostname(map, hbuf, hbsize, avp)
63356823Seric 	MAP *map;
63416911Seric 	char *hbuf;
63516911Seric 	int hbsize;
63653751Seric 	char **avp;
63716911Seric {
63853751Seric 	return NULL;
63916911Seric }
64016911Seric 
64156795Seric #endif /* DAEMON */
642