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> 10*58153Seric #include <signal.h> 1140962Sbostic #include "sendmail.h" 124535Seric 1333780Sbostic #ifndef lint 1433780Sbostic #ifdef DAEMON 15*58153Seric static char sccsid[] = "@(#)daemon.c 6.9 (Berkeley) 02/23/93 (with daemon mode)"; 1633780Sbostic #else 17*58153Seric static char sccsid[] = "@(#)daemon.c 6.9 (Berkeley) 02/23/93 (without daemon mode)"; 1833780Sbostic #endif 1933780Sbostic #endif /* not lint */ 204535Seric 2133780Sbostic #ifdef DAEMON 2233780Sbostic 2323120Seric # include <netdb.h> 2423120Seric # include <sys/wait.h> 2523120Seric # include <sys/time.h> 265978Seric 274535Seric /* 284535Seric ** DAEMON.C -- routines to use when running as a daemon. 297556Seric ** 307556Seric ** This entire file is highly dependent on the 4.2 BSD 317556Seric ** interprocess communication primitives. No attempt has 327556Seric ** been made to make this file portable to Version 7, 337556Seric ** Version 6, MPX files, etc. If you should try such a 347556Seric ** thing yourself, I recommend chucking the entire file 357556Seric ** and starting from scratch. Basic semantics are: 367556Seric ** 377556Seric ** getrequests() 387556Seric ** Opens a port and initiates a connection. 397556Seric ** Returns in a child. Must set InChannel and 407556Seric ** OutChannel appropriately. 4110206Seric ** clrdaemon() 4210206Seric ** Close any open files associated with getting 4310206Seric ** the connection; this is used when running the queue, 4410206Seric ** etc., to avoid having extra file descriptors during 4510206Seric ** the queue run and to avoid confusing the network 4610206Seric ** code (if it cares). 4752106Seric ** makeconnection(host, port, outfile, infile, usesecureport) 487556Seric ** Make a connection to the named host on the given 497556Seric ** port. Set *outfile and *infile to the files 507556Seric ** appropriate for communication. Returns zero on 517556Seric ** success, else an exit status describing the 527556Seric ** error. 5356823Seric ** maphostname(map, hbuf, hbufsiz, avp) 5456823Seric ** Convert the entry in hbuf into a canonical form. 554535Seric */ 564535Seric /* 574535Seric ** GETREQUESTS -- open mail IPC port and get requests. 584535Seric ** 594535Seric ** Parameters: 604535Seric ** none. 614535Seric ** 624535Seric ** Returns: 634535Seric ** none. 644535Seric ** 654535Seric ** Side Effects: 664535Seric ** Waits until some interesting activity occurs. When 674535Seric ** it does, a child is created to process it, and the 684535Seric ** parent waits for completion. Return from this 699886Seric ** routine is always in the child. The file pointers 709886Seric ** "InChannel" and "OutChannel" should be set to point 719886Seric ** to the communication channel. 724535Seric */ 734535Seric 7416144Seric int DaemonSocket = -1; /* fd describing socket */ 7516144Seric 764535Seric getrequests() 774535Seric { 789610Seric int t; 799610Seric register struct servent *sp; 8025027Seric int on = 1; 8153751Seric bool refusingconnections = TRUE; 8252106Seric struct sockaddr_in srvraddr; 8346928Sbostic extern void reapchild(); 847117Seric 859610Seric /* 869610Seric ** Set up the address for the mailer. 879610Seric */ 889610Seric 899610Seric sp = getservbyname("smtp", "tcp"); 909610Seric if (sp == NULL) 919610Seric { 9258151Seric syserr("554 server \"smtp\" unknown"); 9310167Seric goto severe; 949610Seric } 9552106Seric srvraddr.sin_family = AF_INET; 9652106Seric srvraddr.sin_addr.s_addr = INADDR_ANY; 9752106Seric srvraddr.sin_port = sp->s_port; 989610Seric 999610Seric /* 1009610Seric ** Try to actually open the connection. 1019610Seric */ 1029610Seric 1039610Seric if (tTd(15, 1)) 10452106Seric printf("getrequests: port 0x%x\n", srvraddr.sin_port); 1059610Seric 1069610Seric /* get a socket for the SMTP connection */ 10723120Seric DaemonSocket = socket(AF_INET, SOCK_STREAM, 0); 10810206Seric if (DaemonSocket < 0) 1099610Seric { 1109610Seric /* probably another daemon already */ 1119610Seric syserr("getrequests: can't create socket"); 1129610Seric severe: 1139610Seric # ifdef LOG 1149610Seric if (LogLevel > 0) 11557663Seric syslog(LOG_ALERT, "problem creating SMTP socket"); 11656795Seric # endif /* LOG */ 1179610Seric finis(); 1189610Seric } 11910347Seric 12010347Seric /* turn on network debugging? */ 12156328Seric if (tTd(15, 101)) 12224945Seric (void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof on); 12310347Seric 12425027Seric (void) setsockopt(DaemonSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof on); 12525027Seric (void) setsockopt(DaemonSocket, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof on); 12625027Seric 12752106Seric if (bind(DaemonSocket, (struct sockaddr *)&srvraddr, sizeof srvraddr) < 0) 1289610Seric { 1299610Seric syserr("getrequests: cannot bind"); 13010206Seric (void) close(DaemonSocket); 1319610Seric goto severe; 1329610Seric } 1339610Seric 13424955Seric (void) signal(SIGCHLD, reapchild); 13524945Seric 1369610Seric if (tTd(15, 1)) 13710206Seric printf("getrequests: %d\n", DaemonSocket); 1389610Seric 1394631Seric for (;;) 1404631Seric { 14114875Seric register int pid; 14211147Seric auto int lotherend; 14353751Seric extern bool refuseconnections(); 14411147Seric 14514875Seric /* see if we are rejecting connections */ 14653751Seric CurrentLA = getla(); 14753751Seric if (refuseconnections()) 14836584Sbostic { 14953751Seric if (!refusingconnections) 15053751Seric { 15153751Seric /* don't queue so peer will fail quickly */ 15253751Seric (void) listen(DaemonSocket, 0); 15353751Seric refusingconnections = TRUE; 15453751Seric } 15557385Seric setproctitle("rejecting connections: load average: %d", 15657385Seric CurrentLA); 15714875Seric sleep(5); 15853751Seric continue; 15936584Sbostic } 16014875Seric 16153751Seric if (refusingconnections) 16253751Seric { 16353751Seric /* start listening again */ 16453751Seric if (listen(DaemonSocket, 10) < 0) 16553751Seric { 16653751Seric syserr("getrequests: cannot listen"); 16753751Seric (void) close(DaemonSocket); 16853751Seric goto severe; 16953751Seric } 17053751Seric setproctitle("accepting connections"); 17153751Seric refusingconnections = FALSE; 17253751Seric } 17353751Seric 1749610Seric /* wait for a connection */ 1759610Seric do 1769610Seric { 1779610Seric errno = 0; 17836230Skarels lotherend = sizeof RealHostAddr; 17946928Sbostic t = accept(DaemonSocket, 18046928Sbostic (struct sockaddr *)&RealHostAddr, &lotherend); 1819610Seric } while (t < 0 && errno == EINTR); 1829610Seric if (t < 0) 1835978Seric { 1849610Seric syserr("getrequests: accept"); 1859610Seric sleep(5); 1869610Seric continue; 1875978Seric } 1884631Seric 1895978Seric /* 1905978Seric ** Create a subprocess to process the mail. 1915978Seric */ 1925978Seric 1937677Seric if (tTd(15, 2)) 1949610Seric printf("getrequests: forking (fd = %d)\n", t); 1955978Seric 1964636Seric pid = fork(); 1974636Seric if (pid < 0) 1984631Seric { 1994636Seric syserr("daemon: cannot fork"); 2004636Seric sleep(10); 2019610Seric (void) close(t); 2024636Seric continue; 2034631Seric } 2044631Seric 2054636Seric if (pid == 0) 2064631Seric { 20711147Seric extern struct hostent *gethostbyaddr(); 20811147Seric register struct hostent *hp; 20911147Seric char buf[MAXNAME]; 21057135Seric extern char *inet_ntoa(); 21111147Seric 2124636Seric /* 2134636Seric ** CHILD -- return to caller. 21411147Seric ** Collect verified idea of sending host. 2154636Seric ** Verify calling user id if possible here. 2164636Seric */ 2174631Seric 21824955Seric (void) signal(SIGCHLD, SIG_DFL); 21924950Seric 22011147Seric /* determine host name */ 22136230Skarels hp = gethostbyaddr((char *) &RealHostAddr.sin_addr, sizeof RealHostAddr.sin_addr, AF_INET); 22211147Seric if (hp != NULL) 22323104Seric (void) strcpy(buf, hp->h_name); 22411147Seric else 22516884Seric { 22616884Seric /* produce a dotted quad */ 22716884Seric (void) sprintf(buf, "[%s]", 22836230Skarels inet_ntoa(RealHostAddr.sin_addr)); 22916884Seric } 23016884Seric 23155173Seric #ifdef LOG 23257977Seric if (LogLevel > 10) 23355173Seric { 23455173Seric /* log connection information */ 23555173Seric syslog(LOG_INFO, "connect from %s (%s)", 23655173Seric buf, inet_ntoa(RealHostAddr.sin_addr)); 23755173Seric } 23855173Seric #endif 23955173Seric 24016884Seric /* should we check for illegal connection here? XXX */ 24116884Seric 24211147Seric RealHostName = newstr(buf); 24311147Seric 24410206Seric (void) close(DaemonSocket); 2459610Seric InChannel = fdopen(t, "r"); 24621062Seric OutChannel = fdopen(dup(t), "w"); 2477677Seric if (tTd(15, 2)) 2485978Seric printf("getreq: returning\n"); 2497876Seric # ifdef LOG 2507876Seric if (LogLevel > 11) 2517876Seric syslog(LOG_DEBUG, "connected, pid=%d", getpid()); 25256795Seric # endif /* LOG */ 2534636Seric return; 2544631Seric } 2554631Seric 2567117Seric /* close the port so that others will hang (for a while) */ 2579610Seric (void) close(t); 2584631Seric } 2599886Seric /*NOTREACHED*/ 2604631Seric } 2615978Seric /* 26210206Seric ** CLRDAEMON -- reset the daemon connection 26310206Seric ** 26410206Seric ** Parameters: 26510206Seric ** none. 26610206Seric ** 26710206Seric ** Returns: 26810206Seric ** none. 26910206Seric ** 27010206Seric ** Side Effects: 27110206Seric ** releases any resources used by the passive daemon. 27210206Seric */ 27310206Seric 27410206Seric clrdaemon() 27510206Seric { 27610206Seric if (DaemonSocket >= 0) 27710206Seric (void) close(DaemonSocket); 27810206Seric DaemonSocket = -1; 27910206Seric } 28010206Seric /* 2816039Seric ** MAKECONNECTION -- make a connection to an SMTP socket on another machine. 2826039Seric ** 2836039Seric ** Parameters: 2846039Seric ** host -- the name of the host. 2856633Seric ** port -- the port number to connect to. 28653739Seric ** mci -- a pointer to the mail connection information 28753739Seric ** structure to be filled in. 28852106Seric ** usesecureport -- if set, use a low numbered (reserved) 28952106Seric ** port to provide some rudimentary authentication. 2906039Seric ** 2916039Seric ** Returns: 2926039Seric ** An exit code telling whether the connection could be 2936039Seric ** made and if not why not. 2946039Seric ** 2956039Seric ** Side Effects: 2966039Seric ** none. 2976039Seric */ 2985978Seric 29954967Seric int 30053739Seric makeconnection(host, port, mci, usesecureport) 3016039Seric char *host; 3027286Seric u_short port; 30354967Seric register MCI *mci; 30452106Seric bool usesecureport; 3056039Seric { 30629430Sbloom register int i, s; 30729430Sbloom register struct hostent *hp = (struct hostent *)NULL; 30852106Seric struct sockaddr_in addr; 30952106Seric int sav_errno; 31029430Sbloom extern char *inet_ntoa(); 31135651Seric #ifdef NAMED_BIND 31235651Seric extern int h_errno; 31335651Seric #endif 3146039Seric 3156039Seric /* 3166039Seric ** Set up the address for the mailer. 3179308Seric ** Accept "[a.b.c.d]" syntax for host name. 3186039Seric */ 3196039Seric 32035651Seric #ifdef NAMED_BIND 32125475Smiriam h_errno = 0; 32235651Seric #endif 32325475Smiriam errno = 0; 32425475Smiriam 3259308Seric if (host[0] == '[') 3269308Seric { 32711147Seric long hid; 32856795Seric register char *p = strchr(host, ']'); 3299308Seric 33011147Seric if (p != NULL) 3319308Seric { 33211147Seric *p = '\0'; 33311147Seric hid = inet_addr(&host[1]); 33411147Seric *p = ']'; 3359308Seric } 33611147Seric if (p == NULL || hid == -1) 3379308Seric { 33858151Seric usrerr("553 Invalid numeric domain spec \"%s\"", host); 3399308Seric return (EX_NOHOST); 3409308Seric } 34152106Seric addr.sin_addr.s_addr = hid; 3429308Seric } 3439610Seric else 3449610Seric { 34529430Sbloom hp = gethostbyname(host); 34625475Smiriam if (hp == NULL) 34724945Seric { 34835651Seric #ifdef NAMED_BIND 34925475Smiriam if (errno == ETIMEDOUT || h_errno == TRY_AGAIN) 35025475Smiriam return (EX_TEMPFAIL); 35125657Seric 35235651Seric /* if name server is specified, assume temp fail */ 35335651Seric if (errno == ECONNREFUSED && UseNameServer) 35435651Seric return (EX_TEMPFAIL); 35535651Seric #endif 35625475Smiriam return (EX_NOHOST); 35724945Seric } 35852106Seric bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length); 35929430Sbloom i = 1; 3609610Seric } 3619610Seric 3629610Seric /* 3639610Seric ** Determine the port number. 3649610Seric */ 3659610Seric 36610011Seric if (port != 0) 36752106Seric addr.sin_port = htons(port); 36810011Seric else 3699610Seric { 3709610Seric register struct servent *sp = getservbyname("smtp", "tcp"); 3719610Seric 3729610Seric if (sp == NULL) 3739610Seric { 37458151Seric syserr("554 makeconnection: server \"smtp\" unknown"); 37557977Seric return (EX_OSERR); 3769610Seric } 37752106Seric addr.sin_port = sp->s_port; 3789610Seric } 3796039Seric 3806039Seric /* 3816039Seric ** Try to actually open the connection. 3826039Seric */ 3836039Seric 38457736Seric for (;;) 38552106Seric { 38657736Seric if (tTd(16, 1)) 38757736Seric printf("makeconnection (%s [%s])\n", host, 38857736Seric inet_ntoa(addr.sin_addr)); 38952106Seric 39057736Seric if (usesecureport) 39157736Seric { 39257736Seric int rport = IPPORT_RESERVED - 1; 3936039Seric 39457736Seric s = rresvport(&rport); 39557736Seric } 39657736Seric else 39757736Seric { 39857736Seric s = socket(AF_INET, SOCK_STREAM, 0); 39957736Seric } 40057736Seric if (s < 0) 40157736Seric { 40257736Seric sav_errno = errno; 40357736Seric syserr("makeconnection: no socket"); 40457736Seric goto failure; 40557736Seric } 40610347Seric 40757736Seric if (tTd(16, 1)) 40857736Seric printf("makeconnection: fd=%d\n", s); 40957736Seric 41057736Seric /* turn on network debugging? */ 41157736Seric if (tTd(16, 101)) 41257736Seric { 41357736Seric int on = 1; 41457736Seric (void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, 41557736Seric (char *)&on, sizeof on); 41657736Seric } 41757736Seric if (CurEnv->e_xfp != NULL) 41857736Seric (void) fflush(CurEnv->e_xfp); /* for debugging */ 41957736Seric errno = 0; /* for debugging */ 42057736Seric addr.sin_family = AF_INET; 42157736Seric if (connect(s, (struct sockaddr *) &addr, sizeof addr) >= 0) 42257736Seric break; 42357736Seric 42457736Seric /* couldn't connect.... figure out why */ 42527744Sbloom sav_errno = errno; 42627744Sbloom (void) close(s); 42729430Sbloom if (hp && hp->h_addr_list[i]) 42829430Sbloom { 42957736Seric if (tTd(16, 1)) 43057736Seric printf("Connect failed; trying new address....\n"); 43152106Seric bcopy(hp->h_addr_list[i++], (char *) &addr.sin_addr, 43252106Seric hp->h_length); 43357736Seric continue; 43429430Sbloom } 43529430Sbloom 4366039Seric /* failure, decide if temporary or not */ 4376039Seric failure: 43827744Sbloom switch (sav_errno) 4396039Seric { 4406039Seric case EISCONN: 4416039Seric case ETIMEDOUT: 4426897Seric case EINPROGRESS: 4436897Seric case EALREADY: 4446897Seric case EADDRINUSE: 44510123Seric case EHOSTDOWN: 4466897Seric case ENETDOWN: 4476897Seric case ENETRESET: 4486897Seric case ENOBUFS: 4497204Seric case ECONNREFUSED: 45011546Seric case ECONNRESET: 45110081Seric case EHOSTUNREACH: 45210098Seric case ENETUNREACH: 45351995Seric #ifdef ENOSR 45451995Seric case ENOSR: 45551995Seric #endif 4566039Seric /* there are others, I'm sure..... */ 4576039Seric return (EX_TEMPFAIL); 4586039Seric 45911147Seric case EPERM: 46011147Seric /* why is this happening? */ 46111147Seric syserr("makeconnection: funny failure, addr=%lx, port=%x", 46252106Seric addr.sin_addr.s_addr, addr.sin_port); 46314383Seric return (EX_TEMPFAIL); 46411147Seric 4656039Seric default: 46640932Srick { 46740932Srick extern char *errstring(); 46840932Srick 46958151Seric message("%s", errstring(sav_errno)); 47040932Srick return (EX_UNAVAILABLE); 47140932Srick } 4726039Seric } 4736039Seric } 4746039Seric 4756039Seric /* connection ok, put it into canonical form */ 47653739Seric mci->mci_out = fdopen(s, "w"); 47753739Seric mci->mci_in = fdopen(dup(s), "r"); 4786039Seric 47910098Seric return (EX_OK); 4806039Seric } 48110758Seric /* 48210758Seric ** MYHOSTNAME -- return the name of this host. 48310758Seric ** 48410758Seric ** Parameters: 48510758Seric ** hostbuf -- a place to return the name of this host. 48612313Seric ** size -- the size of hostbuf. 48710758Seric ** 48810758Seric ** Returns: 48910758Seric ** A list of aliases for this host. 49010758Seric ** 49110758Seric ** Side Effects: 49258110Seric ** Sets the MyIpAddrs buffer to a list of my IP addresses. 49310758Seric */ 4946039Seric 49558110Seric struct in_addr MyIpAddrs[MAXIPADDR + 1]; 49658110Seric 49710758Seric char ** 49812313Seric myhostname(hostbuf, size) 49910758Seric char hostbuf[]; 50012313Seric int size; 50110758Seric { 50258110Seric register struct hostent *hp; 50310758Seric extern struct hostent *gethostbyname(); 50410758Seric 50523120Seric if (gethostname(hostbuf, size) < 0) 50623120Seric { 50723120Seric (void) strcpy(hostbuf, "localhost"); 50823120Seric } 50911147Seric hp = gethostbyname(hostbuf); 51011147Seric if (hp != NULL) 51116877Seric { 51258110Seric (void) strncpy(hostbuf, hp->h_name, size - 1); 51358110Seric hostbuf[size - 1] = '\0'; 51458110Seric 51558110Seric if (hp->h_addrtype == AF_INET && hp->h_length == 4) 51658110Seric { 51758110Seric register int i; 51858110Seric 51958110Seric for (i = 0; i < MAXIPADDR; i++) 52058110Seric { 52158110Seric if (hp->h_addr_list[i] == NULL) 52258110Seric break; 52358110Seric MyIpAddrs[i].s_addr = *(u_long *) hp->h_addr_list[i]; 52458110Seric } 52558110Seric MyIpAddrs[i].s_addr = 0; 52658110Seric } 52758110Seric 52811147Seric return (hp->h_aliases); 52916877Seric } 53010758Seric else 53110758Seric return (NULL); 53210758Seric } 53351315Seric /* 53453751Seric ** MAPHOSTNAME -- turn a hostname into canonical form 53553751Seric ** 53653751Seric ** Parameters: 53756823Seric ** map -- a pointer to this map (unused). 53853751Seric ** hbuf -- a buffer containing a hostname. 53953751Seric ** hbsize -- the size of hbuf. 54055019Seric ** avp -- unused -- for compatibility with other mapping 54155019Seric ** functions. 54253751Seric ** 54353751Seric ** Returns: 54453751Seric ** The mapping, if found. 54553751Seric ** NULL if no mapping found. 54653751Seric ** 54753751Seric ** Side Effects: 54853751Seric ** Looks up the host specified in hbuf. If it is not 54953751Seric ** the canonical name for that host, return the canonical 55053751Seric ** name. 55153751Seric */ 55251315Seric 55353751Seric char * 55456823Seric maphostname(map, hbuf, hbsize, avp) 55556823Seric MAP *map; 55616911Seric char *hbuf; 55716911Seric int hbsize; 55853751Seric char **avp; 55916911Seric { 56016911Seric register struct hostent *hp; 56133932Sbostic u_long in_addr; 56256823Seric char *cp; 56358110Seric int i; 56433932Sbostic struct hostent *gethostbyaddr(); 56516911Seric 56656836Seric /* allow room for null */ 56756823Seric hbsize--; 56853751Seric 56925574Smiriam /* 57033932Sbostic * If first character is a bracket, then it is an address 57133932Sbostic * lookup. Address is copied into a temporary buffer to 57233932Sbostic * strip the brackets and to preserve hbuf if address is 57333932Sbostic * unknown. 57433932Sbostic */ 57553751Seric 57651315Seric if (*hbuf != '[') 57753751Seric { 57855019Seric extern bool getcanonname(); 57955019Seric 58053751Seric if (getcanonname(hbuf, hbsize)) 58153751Seric return hbuf; 58253751Seric else 58353751Seric return NULL; 58453751Seric } 58556823Seric if ((cp = strchr(hbuf, ']')) == NULL) 58653751Seric return (NULL); 58740994Sbostic *cp = '\0'; 58856823Seric in_addr = inet_addr(&hbuf[1]); 58958110Seric 59058110Seric /* check to see if this is one of our addresses */ 59158110Seric for (i = 0; MyIpAddrs[i].s_addr != 0; i++) 59258110Seric { 59358110Seric if (MyIpAddrs[i].s_addr == in_addr) 59458110Seric { 59558110Seric strncpy(hbuf, MyHostName, hbsize); 59658110Seric hbuf[hbsize] = '\0'; 59758110Seric return hbuf; 59858110Seric } 59958110Seric } 60058110Seric 60158110Seric /* nope -- ask the name server */ 60233932Sbostic hp = gethostbyaddr((char *)&in_addr, sizeof(struct in_addr), AF_INET); 60333932Sbostic if (hp == NULL) 60453751Seric return (NULL); 60553751Seric 60658110Seric /* found a match -- copy out */ 60756823Seric if (strlen(hp->h_name) > hbsize) 60856823Seric hp->h_name[hbsize] = '\0'; 60953751Seric (void) strcpy(hbuf, hp->h_name); 61053751Seric return hbuf; 61133932Sbostic } 61216911Seric 61356795Seric # else /* DAEMON */ 61416911Seric /* code for systems without sophisticated networking */ 61510758Seric 61610758Seric /* 61710758Seric ** MYHOSTNAME -- stub version for case of no daemon code. 61811297Seric ** 61911297Seric ** Can't convert to upper case here because might be a UUCP name. 62012313Seric ** 62112313Seric ** Mark, you can change this to be anything you want...... 62210758Seric */ 62310758Seric 62410758Seric char ** 62512313Seric myhostname(hostbuf, size) 62610758Seric char hostbuf[]; 62712313Seric int size; 62810758Seric { 62910758Seric register FILE *f; 63010758Seric 63110758Seric hostbuf[0] = '\0'; 63210758Seric f = fopen("/usr/include/whoami", "r"); 63310758Seric if (f != NULL) 63410758Seric { 63512313Seric (void) fgets(hostbuf, size, f); 63610758Seric fixcrlf(hostbuf, TRUE); 63710758Seric (void) fclose(f); 63810758Seric } 63910758Seric return (NULL); 64010758Seric } 64116911Seric /* 64216911Seric ** MAPHOSTNAME -- turn a hostname into canonical form 64316911Seric ** 64416911Seric ** Parameters: 64556823Seric ** map -- a pointer to the database map. 64616911Seric ** hbuf -- a buffer containing a hostname. 64753751Seric ** avp -- a pointer to a (cf file defined) argument vector. 64816911Seric ** 64916911Seric ** Returns: 65053751Seric ** mapped host name 65151315Seric ** FALSE otherwise. 65216911Seric ** 65316911Seric ** Side Effects: 65416911Seric ** Looks up the host specified in hbuf. If it is not 65516911Seric ** the canonical name for that host, replace it with 65616911Seric ** the canonical name. If the name is unknown, or it 65716911Seric ** is already the canonical name, leave it unchanged. 65816911Seric */ 65910758Seric 66016911Seric /*ARGSUSED*/ 66153751Seric char * 66256823Seric maphostname(map, hbuf, hbsize, avp) 66356823Seric MAP *map; 66416911Seric char *hbuf; 66516911Seric int hbsize; 66653751Seric char **avp; 66716911Seric { 66853751Seric return NULL; 66916911Seric } 67016911Seric 67156795Seric #endif /* DAEMON */ 672