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> 1058153Seric #include <signal.h> 1140962Sbostic #include "sendmail.h" 124535Seric 1333780Sbostic #ifndef lint 1433780Sbostic #ifdef DAEMON 15*58305Seric static char sccsid[] = "@(#)daemon.c 6.10 (Berkeley) 02/28/93 (with daemon mode)"; 1633780Sbostic #else 17*58305Seric static char sccsid[] = "@(#)daemon.c 6.10 (Berkeley) 02/28/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 299*58305Seric struct sockaddr_in CurHostAddr; /* address of current host */ 300*58305Seric 30154967Seric int 30253739Seric makeconnection(host, port, mci, usesecureport) 3036039Seric char *host; 3047286Seric u_short port; 30554967Seric register MCI *mci; 30652106Seric bool usesecureport; 3076039Seric { 30829430Sbloom register int i, s; 30929430Sbloom register struct hostent *hp = (struct hostent *)NULL; 31052106Seric struct sockaddr_in addr; 31152106Seric int sav_errno; 31229430Sbloom extern char *inet_ntoa(); 31335651Seric #ifdef NAMED_BIND 31435651Seric extern int h_errno; 31535651Seric #endif 3166039Seric 3176039Seric /* 3186039Seric ** Set up the address for the mailer. 3199308Seric ** Accept "[a.b.c.d]" syntax for host name. 3206039Seric */ 3216039Seric 32235651Seric #ifdef NAMED_BIND 32325475Smiriam h_errno = 0; 32435651Seric #endif 32525475Smiriam errno = 0; 32625475Smiriam 3279308Seric if (host[0] == '[') 3289308Seric { 32911147Seric long hid; 33056795Seric register char *p = strchr(host, ']'); 3319308Seric 33211147Seric if (p != NULL) 3339308Seric { 33411147Seric *p = '\0'; 33511147Seric hid = inet_addr(&host[1]); 33611147Seric *p = ']'; 3379308Seric } 33811147Seric if (p == NULL || hid == -1) 3399308Seric { 34058151Seric usrerr("553 Invalid numeric domain spec \"%s\"", host); 3419308Seric return (EX_NOHOST); 3429308Seric } 34352106Seric addr.sin_addr.s_addr = hid; 3449308Seric } 3459610Seric else 3469610Seric { 34729430Sbloom hp = gethostbyname(host); 34825475Smiriam if (hp == NULL) 34924945Seric { 35035651Seric #ifdef NAMED_BIND 35125475Smiriam if (errno == ETIMEDOUT || h_errno == TRY_AGAIN) 35225475Smiriam return (EX_TEMPFAIL); 35325657Seric 35435651Seric /* if name server is specified, assume temp fail */ 35535651Seric if (errno == ECONNREFUSED && UseNameServer) 35635651Seric return (EX_TEMPFAIL); 35735651Seric #endif 35825475Smiriam return (EX_NOHOST); 35924945Seric } 36052106Seric bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length); 36129430Sbloom i = 1; 3629610Seric } 3639610Seric 3649610Seric /* 3659610Seric ** Determine the port number. 3669610Seric */ 3679610Seric 36810011Seric if (port != 0) 36952106Seric addr.sin_port = htons(port); 37010011Seric else 3719610Seric { 3729610Seric register struct servent *sp = getservbyname("smtp", "tcp"); 3739610Seric 3749610Seric if (sp == NULL) 3759610Seric { 37658151Seric syserr("554 makeconnection: server \"smtp\" unknown"); 37757977Seric return (EX_OSERR); 3789610Seric } 37952106Seric addr.sin_port = sp->s_port; 3809610Seric } 3816039Seric 3826039Seric /* 3836039Seric ** Try to actually open the connection. 3846039Seric */ 3856039Seric 38657736Seric for (;;) 38752106Seric { 38857736Seric if (tTd(16, 1)) 38957736Seric printf("makeconnection (%s [%s])\n", host, 39057736Seric inet_ntoa(addr.sin_addr)); 39152106Seric 39257736Seric if (usesecureport) 39357736Seric { 39457736Seric int rport = IPPORT_RESERVED - 1; 3956039Seric 39657736Seric s = rresvport(&rport); 39757736Seric } 39857736Seric else 39957736Seric { 40057736Seric s = socket(AF_INET, SOCK_STREAM, 0); 40157736Seric } 40257736Seric if (s < 0) 40357736Seric { 40457736Seric sav_errno = errno; 40557736Seric syserr("makeconnection: no socket"); 40657736Seric goto failure; 40757736Seric } 40810347Seric 40957736Seric if (tTd(16, 1)) 41057736Seric printf("makeconnection: fd=%d\n", s); 41157736Seric 41257736Seric /* turn on network debugging? */ 41357736Seric if (tTd(16, 101)) 41457736Seric { 41557736Seric int on = 1; 41657736Seric (void) setsockopt(DaemonSocket, SOL_SOCKET, SO_DEBUG, 41757736Seric (char *)&on, sizeof on); 41857736Seric } 41957736Seric if (CurEnv->e_xfp != NULL) 42057736Seric (void) fflush(CurEnv->e_xfp); /* for debugging */ 42157736Seric errno = 0; /* for debugging */ 42257736Seric addr.sin_family = AF_INET; 42357736Seric if (connect(s, (struct sockaddr *) &addr, sizeof addr) >= 0) 42457736Seric break; 42557736Seric 42657736Seric /* couldn't connect.... figure out why */ 42727744Sbloom sav_errno = errno; 42827744Sbloom (void) close(s); 42929430Sbloom if (hp && hp->h_addr_list[i]) 43029430Sbloom { 43157736Seric if (tTd(16, 1)) 43257736Seric printf("Connect failed; trying new address....\n"); 43352106Seric bcopy(hp->h_addr_list[i++], (char *) &addr.sin_addr, 43452106Seric hp->h_length); 43557736Seric continue; 43629430Sbloom } 43729430Sbloom 4386039Seric /* failure, decide if temporary or not */ 4396039Seric failure: 44027744Sbloom switch (sav_errno) 4416039Seric { 4426039Seric case EISCONN: 4436039Seric case ETIMEDOUT: 4446897Seric case EINPROGRESS: 4456897Seric case EALREADY: 4466897Seric case EADDRINUSE: 44710123Seric case EHOSTDOWN: 4486897Seric case ENETDOWN: 4496897Seric case ENETRESET: 4506897Seric case ENOBUFS: 4517204Seric case ECONNREFUSED: 45211546Seric case ECONNRESET: 45310081Seric case EHOSTUNREACH: 45410098Seric case ENETUNREACH: 45551995Seric #ifdef ENOSR 45651995Seric case ENOSR: 45751995Seric #endif 4586039Seric /* there are others, I'm sure..... */ 4596039Seric return (EX_TEMPFAIL); 4606039Seric 46111147Seric case EPERM: 46211147Seric /* why is this happening? */ 46311147Seric syserr("makeconnection: funny failure, addr=%lx, port=%x", 46452106Seric addr.sin_addr.s_addr, addr.sin_port); 46514383Seric return (EX_TEMPFAIL); 46611147Seric 4676039Seric default: 46840932Srick { 46940932Srick extern char *errstring(); 47040932Srick 47158151Seric message("%s", errstring(sav_errno)); 47240932Srick return (EX_UNAVAILABLE); 47340932Srick } 4746039Seric } 4756039Seric } 4766039Seric 4776039Seric /* connection ok, put it into canonical form */ 47853739Seric mci->mci_out = fdopen(s, "w"); 47953739Seric mci->mci_in = fdopen(dup(s), "r"); 4806039Seric 481*58305Seric /* save for logging */ 482*58305Seric CurHostAddr = addr; 483*58305Seric 48410098Seric return (EX_OK); 4856039Seric } 48610758Seric /* 48710758Seric ** MYHOSTNAME -- return the name of this host. 48810758Seric ** 48910758Seric ** Parameters: 49010758Seric ** hostbuf -- a place to return the name of this host. 49112313Seric ** size -- the size of hostbuf. 49210758Seric ** 49310758Seric ** Returns: 49410758Seric ** A list of aliases for this host. 49510758Seric ** 49610758Seric ** Side Effects: 49758110Seric ** Sets the MyIpAddrs buffer to a list of my IP addresses. 49810758Seric */ 4996039Seric 50058110Seric struct in_addr MyIpAddrs[MAXIPADDR + 1]; 50158110Seric 50210758Seric char ** 50312313Seric myhostname(hostbuf, size) 50410758Seric char hostbuf[]; 50512313Seric int size; 50610758Seric { 50758110Seric register struct hostent *hp; 50810758Seric extern struct hostent *gethostbyname(); 50910758Seric 51023120Seric if (gethostname(hostbuf, size) < 0) 51123120Seric { 51223120Seric (void) strcpy(hostbuf, "localhost"); 51323120Seric } 51411147Seric hp = gethostbyname(hostbuf); 51511147Seric if (hp != NULL) 51616877Seric { 51758110Seric (void) strncpy(hostbuf, hp->h_name, size - 1); 51858110Seric hostbuf[size - 1] = '\0'; 51958110Seric 52058110Seric if (hp->h_addrtype == AF_INET && hp->h_length == 4) 52158110Seric { 52258110Seric register int i; 52358110Seric 52458110Seric for (i = 0; i < MAXIPADDR; i++) 52558110Seric { 52658110Seric if (hp->h_addr_list[i] == NULL) 52758110Seric break; 52858110Seric MyIpAddrs[i].s_addr = *(u_long *) hp->h_addr_list[i]; 52958110Seric } 53058110Seric MyIpAddrs[i].s_addr = 0; 53158110Seric } 53258110Seric 53311147Seric return (hp->h_aliases); 53416877Seric } 53510758Seric else 53610758Seric return (NULL); 53710758Seric } 53851315Seric /* 53953751Seric ** MAPHOSTNAME -- turn a hostname into canonical form 54053751Seric ** 54153751Seric ** Parameters: 54256823Seric ** map -- a pointer to this map (unused). 54353751Seric ** hbuf -- a buffer containing a hostname. 54453751Seric ** hbsize -- the size of hbuf. 54555019Seric ** avp -- unused -- for compatibility with other mapping 54655019Seric ** functions. 54753751Seric ** 54853751Seric ** Returns: 54953751Seric ** The mapping, if found. 55053751Seric ** NULL if no mapping found. 55153751Seric ** 55253751Seric ** Side Effects: 55353751Seric ** Looks up the host specified in hbuf. If it is not 55453751Seric ** the canonical name for that host, return the canonical 55553751Seric ** name. 55653751Seric */ 55751315Seric 55853751Seric char * 55956823Seric maphostname(map, hbuf, hbsize, avp) 56056823Seric MAP *map; 56116911Seric char *hbuf; 56216911Seric int hbsize; 56353751Seric char **avp; 56416911Seric { 56516911Seric register struct hostent *hp; 56633932Sbostic u_long in_addr; 56756823Seric char *cp; 56858110Seric int i; 56933932Sbostic struct hostent *gethostbyaddr(); 57016911Seric 57156836Seric /* allow room for null */ 57256823Seric hbsize--; 57353751Seric 57425574Smiriam /* 57533932Sbostic * If first character is a bracket, then it is an address 57633932Sbostic * lookup. Address is copied into a temporary buffer to 57733932Sbostic * strip the brackets and to preserve hbuf if address is 57833932Sbostic * unknown. 57933932Sbostic */ 58053751Seric 58151315Seric if (*hbuf != '[') 58253751Seric { 58355019Seric extern bool getcanonname(); 58455019Seric 58553751Seric if (getcanonname(hbuf, hbsize)) 58653751Seric return hbuf; 58753751Seric else 58853751Seric return NULL; 58953751Seric } 59056823Seric if ((cp = strchr(hbuf, ']')) == NULL) 59153751Seric return (NULL); 59240994Sbostic *cp = '\0'; 59356823Seric in_addr = inet_addr(&hbuf[1]); 59458110Seric 59558110Seric /* check to see if this is one of our addresses */ 59658110Seric for (i = 0; MyIpAddrs[i].s_addr != 0; i++) 59758110Seric { 59858110Seric if (MyIpAddrs[i].s_addr == in_addr) 59958110Seric { 60058110Seric strncpy(hbuf, MyHostName, hbsize); 60158110Seric hbuf[hbsize] = '\0'; 60258110Seric return hbuf; 60358110Seric } 60458110Seric } 60558110Seric 60658110Seric /* nope -- ask the name server */ 60733932Sbostic hp = gethostbyaddr((char *)&in_addr, sizeof(struct in_addr), AF_INET); 60833932Sbostic if (hp == NULL) 60953751Seric return (NULL); 61053751Seric 61158110Seric /* found a match -- copy out */ 61256823Seric if (strlen(hp->h_name) > hbsize) 61356823Seric hp->h_name[hbsize] = '\0'; 61453751Seric (void) strcpy(hbuf, hp->h_name); 61553751Seric return hbuf; 61633932Sbostic } 61716911Seric 61856795Seric # else /* DAEMON */ 61916911Seric /* code for systems without sophisticated networking */ 62010758Seric 62110758Seric /* 62210758Seric ** MYHOSTNAME -- stub version for case of no daemon code. 62311297Seric ** 62411297Seric ** Can't convert to upper case here because might be a UUCP name. 62512313Seric ** 62612313Seric ** Mark, you can change this to be anything you want...... 62710758Seric */ 62810758Seric 62910758Seric char ** 63012313Seric myhostname(hostbuf, size) 63110758Seric char hostbuf[]; 63212313Seric int size; 63310758Seric { 63410758Seric register FILE *f; 63510758Seric 63610758Seric hostbuf[0] = '\0'; 63710758Seric f = fopen("/usr/include/whoami", "r"); 63810758Seric if (f != NULL) 63910758Seric { 64012313Seric (void) fgets(hostbuf, size, f); 64110758Seric fixcrlf(hostbuf, TRUE); 64210758Seric (void) fclose(f); 64310758Seric } 64410758Seric return (NULL); 64510758Seric } 64616911Seric /* 64716911Seric ** MAPHOSTNAME -- turn a hostname into canonical form 64816911Seric ** 64916911Seric ** Parameters: 65056823Seric ** map -- a pointer to the database map. 65116911Seric ** hbuf -- a buffer containing a hostname. 65253751Seric ** avp -- a pointer to a (cf file defined) argument vector. 65316911Seric ** 65416911Seric ** Returns: 65553751Seric ** mapped host name 65651315Seric ** FALSE otherwise. 65716911Seric ** 65816911Seric ** Side Effects: 65916911Seric ** Looks up the host specified in hbuf. If it is not 66016911Seric ** the canonical name for that host, replace it with 66116911Seric ** the canonical name. If the name is unknown, or it 66216911Seric ** is already the canonical name, leave it unchanged. 66316911Seric */ 66410758Seric 66516911Seric /*ARGSUSED*/ 66653751Seric char * 66756823Seric maphostname(map, hbuf, hbsize, avp) 66856823Seric MAP *map; 66916911Seric char *hbuf; 67016911Seric int hbsize; 67153751Seric char **avp; 67216911Seric { 67353751Seric return NULL; 67416911Seric } 67516911Seric 67656795Seric #endif /* DAEMON */ 677