122698Sdist /* 234920Sbostic * Copyright (c) 1983 Eric P. Allman 333728Sbostic * Copyright (c) 1988 Regents of the University of California. 433728Sbostic * All rights reserved. 533728Sbostic * 642825Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822698Sdist 922698Sdist #ifndef lint 10*57661Seric static char sccsid[] = "@(#)conf.c 6.11 (Berkeley) 01/22/93"; 1133728Sbostic #endif /* not lint */ 1222698Sdist 1314881Seric # include <sys/ioctl.h> 1436928Sbostic # include <pwd.h> 153309Seric # include "sendmail.h" 1640980Sbostic # include "pathnames.h" 17404Seric 18294Seric /* 193309Seric ** CONF.C -- Sendmail Configuration Tables. 20294Seric ** 21294Seric ** Defines the configuration of this installation. 22294Seric ** 231388Seric ** Configuration Variables: 242897Seric ** HdrInfo -- a table describing well-known header fields. 252897Seric ** Each entry has the field name and some flags, 264147Seric ** which are described in sendmail.h. 274093Seric ** 284093Seric ** Notes: 294093Seric ** I have tried to put almost all the reasonable 304093Seric ** configuration information into the configuration 314093Seric ** file read at runtime. My intent is that anything 324093Seric ** here is a function of the version of UNIX you 334093Seric ** are running, or is really static -- for example 344093Seric ** the headers are a superset of widely used 354093Seric ** protocols. If you find yourself playing with 364093Seric ** this file too much, you may be making a mistake! 37294Seric */ 38294Seric 39294Seric 40294Seric 41294Seric 424437Seric /* 432897Seric ** Header info table 443057Seric ** Final (null) entry contains the flags used for any other field. 454147Seric ** 464147Seric ** Not all of these are actually handled specially by sendmail 474147Seric ** at this time. They are included as placeholders, to let 484147Seric ** you know that "someday" I intend to have sendmail do 494147Seric ** something with them. 502897Seric */ 512897Seric 522897Seric struct hdrinfo HdrInfo[] = 532897Seric { 548060Seric /* originator fields, most to least significant */ 5511417Seric "resent-sender", H_FROM|H_RESENT, 5611417Seric "resent-from", H_FROM|H_RESENT, 5725686Seric "resent-reply-to", H_FROM|H_RESENT, 589055Seric "sender", H_FROM, 599055Seric "from", H_FROM, 6025686Seric "reply-to", H_FROM, 619055Seric "full-name", H_ACHECK, 6257359Seric "return-receipt-to", H_FROM /* |H_RECEIPTTO */, 6357359Seric "errors-to", H_FROM|H_ERRORSTO, 648060Seric /* destination fields */ 659055Seric "to", H_RCPT, 6611417Seric "resent-to", H_RCPT|H_RESENT, 679055Seric "cc", H_RCPT, 6811417Seric "resent-cc", H_RCPT|H_RESENT, 699055Seric "bcc", H_RCPT|H_ACHECK, 7011417Seric "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, 7156215Seric "apparently-to", H_RCPT, 728060Seric /* message identification and control */ 7311417Seric "message-id", 0, 7411417Seric "resent-message-id", H_RESENT, 759055Seric "message", H_EOH, 769055Seric "text", H_EOH, 7711417Seric /* date fields */ 7811417Seric "date", 0, 7911417Seric "resent-date", H_RESENT, 808060Seric /* trace fields */ 819055Seric "received", H_TRACE|H_FORCE, 829055Seric "via", H_TRACE|H_FORCE, 839055Seric "mail-from", H_TRACE|H_FORCE, 848060Seric 859055Seric NULL, 0, 862897Seric }; 874166Seric 884166Seric 894166Seric /* 904166Seric ** ARPANET error message numbers. 914166Seric */ 924166Seric 937956Seric char Arpa_Info[] = "050"; /* arbitrary info */ 947956Seric char Arpa_TSyserr[] = "451"; /* some (transient) system error */ 957956Seric char Arpa_PSyserr[] = "554"; /* some (permanent) system error */ 967956Seric char Arpa_Usrerr[] = "554"; /* some (fatal) user error */ 974282Seric 984282Seric 994282Seric 1004282Seric /* 1014282Seric ** Location of system files/databases/etc. 1024282Seric */ 1034282Seric 10440980Sbostic char *ConfFile = _PATH_SENDMAILCF; /* runtime configuration */ 10540980Sbostic char *FreezeFile = _PATH_SENDMAILFC; /* frozen version of above */ 1069039Seric 1079064Seric 1089064Seric 1099039Seric /* 11024943Seric ** Miscellaneous stuff. 1119039Seric */ 1129039Seric 11324943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 11424943Seric /* 11524943Seric ** SETDEFAULTS -- set default values 11624943Seric ** 11724943Seric ** Because of the way freezing is done, these must be initialized 11824943Seric ** using direct code. 11924943Seric ** 12024943Seric ** Parameters: 12124943Seric ** none. 12224943Seric ** 12324943Seric ** Returns: 12424943Seric ** none. 12524943Seric ** 12624943Seric ** Side Effects: 12724943Seric ** Initializes a bunch of global variables to their 12824943Seric ** default values. 12924943Seric */ 13024943Seric 13124943Seric setdefaults() 13224943Seric { 13357438Seric SpaceSub = ' '; /* option B */ 13457438Seric QueueLA = 8; /* option x */ 13557438Seric RefuseLA = 12; /* option X */ 13657438Seric WkRecipFact = 30000L; /* option y */ 13757438Seric WkClassFact = 1800L; /* option z */ 13857438Seric WkTimeFact = 90000L; /* option Z */ 13957438Seric QueueFactor = WkRecipFact * 20; /* option q */ 14057142Seric FileMode = (getuid() != geteuid()) ? 0644 : 0600; 14157438Seric /* option F */ 14257438Seric DefUid = 1; /* option u */ 14357438Seric DefGid = 1; /* option g */ 14457438Seric CheckpointInterval = 10; /* option C */ 14557438Seric MaxHopCount = 25; /* option h */ 14657438Seric SendMode = SM_FORK; /* option d */ 14757438Seric ErrorMode = EM_PRINT; /* option e */ 14857438Seric EightBit = FALSE; /* option 8 */ 14957438Seric MaxMciCache = 1; /* option k */ 15057438Seric MciCacheTimeout = 300; /* option K */ 15157438Seric LogLevel = 9; /* option L */ 15257438Seric ReadTimeout = 2 * 60 * 60; /* option r */ 15357438Seric TimeOut = 3 * 24 * 60 * 60; /* option T */ 15440973Sbostic setdefuser(); 15553654Seric setupmaps(); 15657402Seric setupmailers(); 15724943Seric } 158294Seric 15940973Sbostic 1604326Seric /* 16140973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 16240973Sbostic */ 16340973Sbostic 16440973Sbostic setdefuser() 16540973Sbostic { 16640973Sbostic struct passwd *defpwent; 16757386Seric static char defuserbuf[40]; 16840973Sbostic 16957386Seric DefUser = defuserbuf; 17040973Sbostic if ((defpwent = getpwuid(DefUid)) != NULL) 17157386Seric strcpy(defuserbuf, defpwent->pw_name); 17240973Sbostic else 17357386Seric strcpy(defuserbuf, "nobody"); 17440973Sbostic } 17553654Seric /* 17653654Seric ** SETUPMAPS -- set up map classes 17753654Seric ** 17853654Seric ** Since these are compiled in, they cannot be in the config file. 17953654Seric ** 18053654Seric */ 18140973Sbostic 18253654Seric setupmaps() 18353654Seric { 18453654Seric register STAB *s; 18556836Seric extern bool host_map_init(); 18653654Seric extern char *maphostname(); 18740973Sbostic 18853654Seric /* set up host name lookup map */ 18953654Seric s = stab("host", ST_MAPCLASS, ST_ENTER); 19056836Seric s->s_mapclass.map_init = host_map_init; 19153654Seric s->s_mapclass.map_lookup = maphostname; 19253654Seric 19353654Seric /* 19453654Seric ** Set up other map classes. 19553654Seric */ 19653654Seric 19753654Seric # ifdef DBM_MAP 19853654Seric /* dbm file access */ 19953654Seric { 20056836Seric extern bool dbm_map_init(); 20153654Seric extern char *dbm_map_lookup(); 20253654Seric 20353654Seric s = stab("dbm", ST_MAPCLASS, ST_ENTER); 20453654Seric s->s_mapclass.map_init = dbm_map_init; 20553654Seric s->s_mapclass.map_lookup = dbm_map_lookup; 20653654Seric } 20753654Seric # endif 20853654Seric 20953654Seric # ifdef BTREE_MAP 21053654Seric /* new database file access -- btree files */ 21153654Seric { 21256823Seric extern bool bt_map_init(); 21356823Seric extern char *db_map_lookup(); 21453654Seric 21553654Seric s = stab("btree", ST_MAPCLASS, ST_ENTER); 21653654Seric s->s_mapclass.map_init = bt_map_init; 21756823Seric s->s_mapclass.map_lookup = db_map_lookup; 21853654Seric } 21953654Seric # endif 22053654Seric 22153654Seric # ifdef HASH_MAP 22253654Seric /* new database file access -- hash files */ 22353654Seric { 22456823Seric extern bool hash_map_init(); 22556823Seric extern char *db_map_lookup(); 22653654Seric 22753654Seric s = stab("hash", ST_MAPCLASS, ST_ENTER); 22853654Seric s->s_mapclass.map_init = hash_map_init; 22956823Seric s->s_mapclass.map_lookup = db_map_lookup; 23053654Seric } 23153654Seric # endif 23253654Seric 23357208Seric # ifdef NIS_MAP 23457208Seric /* NIS map access */ 23557208Seric { 23657208Seric extern bool nis_map_init(); 23757208Seric extern char *nis_map_lookup(); 23857208Seric 23957208Seric s = stab("nis", ST_MAPCLASS, ST_ENTER); 24057208Seric s->s_mapclass.map_init = nis_map_init; 24157208Seric s->s_mapclass.map_lookup = nis_map_lookup; 24257208Seric } 24357208Seric # endif 24457208Seric 24553654Seric # ifdef USERDB_MAP 24653654Seric /* user database */ 24753654Seric { 24856836Seric extern bool udb_map_init(); 24953654Seric extern char *udb_map_lookup(); 25053654Seric 25153654Seric s = stab("udb", ST_MAPCLASS, ST_ENTER); 25253654Seric s->s_mapclass.map_init = udb_map_init; 25353654Seric s->s_mapclass.map_lookup = udb_map_lookup; 25453654Seric } 25553654Seric # endif 25653654Seric } 25753654Seric /* 25856836Seric ** HOST_MAP_INIT -- initialize host class structures 25956836Seric */ 26056836Seric 26156836Seric bool 26256836Seric host_map_init(map, mapname, args) 26356836Seric MAP *map; 26456836Seric char *mapname; 26556836Seric char *args; 26656836Seric { 26756836Seric register char *p = args; 26856836Seric 26956836Seric for (;;) 27056836Seric { 27156836Seric while (isspace(*p)) 27256836Seric p++; 27356836Seric if (*p != '-') 27456836Seric break; 27556836Seric switch (*++p) 27656836Seric { 27756836Seric case 'a': 27856836Seric map->map_app = ++p; 27956836Seric break; 28056836Seric } 28156836Seric while (*p != '\0' && !isspace(*p)) 28256836Seric p++; 28356836Seric if (*p != '\0') 28456836Seric *p++ = '\0'; 28556836Seric } 28656836Seric if (map->map_app != NULL) 28756836Seric map->map_app = newstr(map->map_app); 28856836Seric return TRUE; 28956836Seric } 29057402Seric /* 29157402Seric ** SETUPMAILERS -- initialize default mailers 29257402Seric */ 29356836Seric 29457402Seric setupmailers() 29557402Seric { 29657402Seric char buf[100]; 29757402Seric 29857403Seric strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u"); 29957403Seric makemailer(buf); 30057403Seric 30157402Seric strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE"); 30257402Seric makemailer(buf); 30357402Seric 30457402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 30557402Seric makemailer(buf); 30657402Seric } 30756836Seric /* 3084326Seric ** GETRUID -- get real user id (V7) 3094326Seric */ 3104326Seric 3114326Seric getruid() 3124326Seric { 3139274Seric if (OpMode == MD_DAEMON) 3144536Seric return (RealUid); 3154536Seric else 3164536Seric return (getuid()); 3174326Seric } 3184326Seric 3194326Seric 3204326Seric /* 3214326Seric ** GETRGID -- get real group id (V7). 3224326Seric */ 3234326Seric 3244326Seric getrgid() 3254326Seric { 3269274Seric if (OpMode == MD_DAEMON) 3274536Seric return (RealGid); 3284536Seric else 3294536Seric return (getgid()); 3304326Seric } 33153654Seric /* 3329369Seric ** USERNAME -- return the user id of the logged in user. 3339369Seric ** 3349369Seric ** Parameters: 3359369Seric ** none. 3369369Seric ** 3379369Seric ** Returns: 3389369Seric ** The login name of the logged in user. 3399369Seric ** 3409369Seric ** Side Effects: 3419369Seric ** none. 3429369Seric ** 3439369Seric ** Notes: 3449369Seric ** The return value is statically allocated. 3459369Seric */ 3469369Seric 3479369Seric char * 3489369Seric username() 3499369Seric { 35017469Seric static char *myname = NULL; 3519369Seric extern char *getlogin(); 35219904Smiriam register struct passwd *pw; 3539369Seric 35417469Seric /* cache the result */ 35517469Seric if (myname == NULL) 35617469Seric { 35717469Seric myname = getlogin(); 35817469Seric if (myname == NULL || myname[0] == '\0') 35917469Seric { 36017469Seric 36117469Seric pw = getpwuid(getruid()); 36217469Seric if (pw != NULL) 36340993Sbostic myname = newstr(pw->pw_name); 36417469Seric } 36519904Smiriam else 36619904Smiriam { 36719873Smiriam 36840993Sbostic myname = newstr(myname); 36940993Sbostic if ((pw = getpwnam(myname)) == NULL || 37040993Sbostic getuid() != pw->pw_uid) 37119904Smiriam { 37219873Smiriam pw = getpwuid(getuid()); 37324945Seric if (pw != NULL) 37440993Sbostic myname = newstr(pw->pw_name); 37519873Smiriam } 37619873Smiriam } 37717469Seric if (myname == NULL || myname[0] == '\0') 37817469Seric { 37917469Seric syserr("Who are you?"); 38017469Seric myname = "postmaster"; 38117469Seric } 38217469Seric } 38317469Seric 38417469Seric return (myname); 3859369Seric } 3869369Seric /* 3874190Seric ** TTYPATH -- Get the path of the user's tty 388294Seric ** 389294Seric ** Returns the pathname of the user's tty. Returns NULL if 390294Seric ** the user is not logged in or if s/he has write permission 391294Seric ** denied. 392294Seric ** 393294Seric ** Parameters: 394294Seric ** none 395294Seric ** 396294Seric ** Returns: 397294Seric ** pathname of the user's tty. 398294Seric ** NULL if not logged in or write permission denied. 399294Seric ** 400294Seric ** Side Effects: 401294Seric ** none. 402294Seric ** 403294Seric ** WARNING: 404294Seric ** Return value is in a local buffer. 405294Seric ** 406294Seric ** Called By: 407294Seric ** savemail 408294Seric */ 409294Seric 410294Seric # include <sys/stat.h> 411294Seric 412294Seric char * 413294Seric ttypath() 414294Seric { 415294Seric struct stat stbuf; 416294Seric register char *pathn; 417294Seric extern char *ttyname(); 4184081Seric extern char *getlogin(); 419294Seric 420294Seric /* compute the pathname of the controlling tty */ 4219369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 4229369Seric (pathn = ttyname(0)) == NULL) 423294Seric { 424294Seric errno = 0; 425294Seric return (NULL); 426294Seric } 427294Seric 428294Seric /* see if we have write permission */ 4292967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 430294Seric { 431294Seric errno = 0; 432294Seric return (NULL); 433294Seric } 434294Seric 435294Seric /* see if the user is logged in */ 436294Seric if (getlogin() == NULL) 437294Seric return (NULL); 438294Seric 439294Seric /* looks good */ 440294Seric return (pathn); 441294Seric } 4422967Seric /* 4432967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4442967Seric ** 4452967Seric ** This routine can be supplied on a per-installation basis 4462967Seric ** to determine whether a person is allowed to send a message. 4472967Seric ** This allows restriction of certain types of internet 4482967Seric ** forwarding or registration of users. 4492967Seric ** 4502967Seric ** If the hosts are found to be incompatible, an error 45157454Seric ** message should be given using "usrerr" and 0 should 4522967Seric ** be returned. 4532967Seric ** 4544288Seric ** 'NoReturn' can be set to suppress the return-to-sender 4554288Seric ** function; this should be done on huge messages. 4564288Seric ** 4572967Seric ** Parameters: 4582967Seric ** to -- the person being sent to. 4592967Seric ** 4602967Seric ** Returns: 46157459Seric ** an exit status 4622967Seric ** 4632967Seric ** Side Effects: 4642967Seric ** none (unless you include the usrerr stuff) 4652967Seric */ 4662967Seric 46755012Seric checkcompat(to, e) 4682967Seric register ADDRESS *to; 46955012Seric register ENVELOPE *e; 4702967Seric { 47112133Seric # ifdef lint 47212133Seric if (to == NULL) 47312133Seric to++; 47412133Seric # endif lint 47510698Seric # ifdef EXAMPLE_CODE 47610698Seric /* this code is intended as an example only */ 4774437Seric register STAB *s; 4784437Seric 4794437Seric s = stab("arpa", ST_MAILER, ST_FIND); 48055012Seric if (s != NULL && e->e_from.q_mailer != LocalMailer && 4819369Seric to->q_mailer == s->s_mailer) 4824437Seric { 4834437Seric usrerr("No ARPA mail through this machine: see your system administration"); 48410698Seric /* NoReturn = TRUE; to supress return copy */ 48557459Seric return (EX_UNAVAILABLE); 4864437Seric } 48756795Seric # endif /* EXAMPLE_CODE */ 48857459Seric return (EX_OK); 4892967Seric } 4909369Seric /* 4919369Seric ** HOLDSIGS -- arrange to hold all signals 4929369Seric ** 4939369Seric ** Parameters: 4949369Seric ** none. 4959369Seric ** 4969369Seric ** Returns: 4979369Seric ** none. 4989369Seric ** 4999369Seric ** Side Effects: 5009369Seric ** Arranges that signals are held. 5019369Seric */ 5029369Seric 5039369Seric holdsigs() 5049369Seric { 5059369Seric } 5069369Seric /* 5079369Seric ** RLSESIGS -- arrange to release all signals 5089369Seric ** 5099369Seric ** This undoes the effect of holdsigs. 5109369Seric ** 5119369Seric ** Parameters: 5129369Seric ** none. 5139369Seric ** 5149369Seric ** Returns: 5159369Seric ** none. 5169369Seric ** 5179369Seric ** Side Effects: 5189369Seric ** Arranges that signals are released. 5199369Seric */ 5209369Seric 5219369Seric rlsesigs() 5229369Seric { 5239369Seric } 52414872Seric /* 52514872Seric ** GETLA -- get the current load average 52614872Seric ** 52714881Seric ** This code stolen from la.c. 52814881Seric ** 52914872Seric ** Parameters: 53014872Seric ** none. 53114872Seric ** 53214872Seric ** Returns: 53314872Seric ** The current load average as an integer. 53414872Seric ** 53514872Seric ** Side Effects: 53614872Seric ** none. 53714872Seric */ 53814872Seric 53951920Seric /* try to guess what style of load average we have */ 54051920Seric #define LA_ZERO 1 /* always return load average as zero */ 54151920Seric #define LA_INT 2 /* read kmem for avenrun; interpret as int */ 54251920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 54351920Seric #define LA_SUBR 4 /* call getloadavg */ 54414872Seric 54551920Seric #ifndef LA_TYPE 54651920Seric # if defined(sun) 54751920Seric # define LA_TYPE LA_INT 54851920Seric # endif 54951920Seric # if defined(mips) 55051920Seric /* Ultrix or RISC/os */ 55151920Seric # define LA_TYPE LA_INT 55251920Seric # define LA_AVENRUN "avenrun" 55351920Seric # endif 55451920Seric # if defined(hpux) 55551920Seric # define LA_TYPE LA_FLOAT 55651920Seric # endif 55751920Seric # if defined(BSD) 55851920Seric # define LA_TYPE LA_SUBR 55951920Seric # endif 56051920Seric 56151920Seric # ifndef LA_TYPE 56251920Seric # define LA_TYPE LA_ZERO 56351920Seric # endif 56451920Seric #endif 56551920Seric 56651920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) 56751920Seric 56814872Seric #include <nlist.h> 56951920Seric #include <fcntl.h> 57014872Seric 57151920Seric #ifndef LA_AVENRUN 57251920Seric #define LA_AVENRUN "_avenrun" 57351920Seric #endif 57451920Seric 57551920Seric /* _PATH_UNIX should be defined in <paths.h> */ 57651920Seric #ifndef _PATH_UNIX 57751920Seric # if defined(hpux) 57851920Seric # define _PATH_UNIX "/hp-ux" 57951920Seric # endif 58051920Seric # if defined(mips) && !defined(ultrix) 58151920Seric /* powerful RISC/os */ 58251920Seric # define _PATH_UNIX "/unix" 58351920Seric # endif 58451920Seric # ifndef _PATH_UNIX 58551920Seric # define _PATH_UNIX "/vmunix" 58651920Seric # endif 58751920Seric #endif 58851920Seric 58914872Seric struct nlist Nl[] = 59014872Seric { 59151920Seric { LA_AVENRUN }, 59214872Seric #define X_AVENRUN 0 59314872Seric { 0 }, 59414872Seric }; 59514872Seric 59651920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT) 59751920Seric # define FSHIFT 8 59851920Seric # define FSCALE (1 << FSHIFT) 59951920Seric #endif 60040930Srick 60114872Seric getla() 60214872Seric { 60314872Seric static int kmem = -1; 60451920Seric #if LA_TYPE == LA_INT 60524943Seric long avenrun[3]; 60651920Seric #else 60751920Seric double avenrun[3]; 60851920Seric #endif 60925615Seric extern off_t lseek(); 61014872Seric 61114872Seric if (kmem < 0) 61214872Seric { 61324945Seric kmem = open("/dev/kmem", 0, 0); 61414872Seric if (kmem < 0) 61514872Seric return (-1); 61651920Seric (void) fcntl(kmem, F_SETFD, 1); 61751920Seric nlist(_PATH_UNIX, Nl); 61814872Seric if (Nl[0].n_type == 0) 61914872Seric return (-1); 62014872Seric } 62124945Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 || 62223118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 62319967Seric { 62419967Seric /* thank you Ian */ 62519967Seric return (-1); 62619967Seric } 62751920Seric #if LA_TYPE == LA_INT 62824943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 62951920Seric #else 63051920Seric return ((int) (avenrun[0] + 0.5)); 63151920Seric #endif 63214872Seric } 63314872Seric 63451773Seric #else 63551920Seric #if LA_TYPE == LA_SUBR 63651773Seric 63751773Seric getla() 63851773Seric { 63951920Seric double avenrun[3]; 64051920Seric 64151920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 64251920Seric return (-1); 64351920Seric return ((int) (avenrun[0] + 0.5)); 64451773Seric } 64551773Seric 64651773Seric #else 64751773Seric 64851773Seric getla() 64951773Seric { 65051920Seric return (0); 65151773Seric } 65251773Seric 65351773Seric #endif 65451773Seric #endif 65524943Seric /* 65624943Seric ** SHOULDQUEUE -- should this message be queued or sent? 65724943Seric ** 65824943Seric ** Compares the message cost to the load average to decide. 65924943Seric ** 66024943Seric ** Parameters: 66124943Seric ** pri -- the priority of the message in question. 66257438Seric ** ctime -- the message creation time. 66324943Seric ** 66424943Seric ** Returns: 66524943Seric ** TRUE -- if this message should be queued up for the 66624943Seric ** time being. 66724943Seric ** FALSE -- if the load is low enough to send this message. 66824943Seric ** 66924943Seric ** Side Effects: 67024943Seric ** none. 67124943Seric */ 67224943Seric 67324943Seric bool 67457438Seric shouldqueue(pri, ctime) 67524943Seric long pri; 67657438Seric time_t ctime; 67724943Seric { 67851920Seric if (CurrentLA < QueueLA) 67924943Seric return (FALSE); 68051920Seric return (pri > (QueueFactor / (CurrentLA - QueueLA + 1))); 68124943Seric } 68224943Seric /* 68353037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 68453037Seric ** 68553037Seric ** Parameters: 68653037Seric ** none. 68753037Seric ** 68853037Seric ** Returns: 68953037Seric ** TRUE if incoming SMTP connections should be refused 69053037Seric ** (for now). 69153037Seric ** FALSE if we should accept new work. 69253037Seric ** 69353037Seric ** Side Effects: 69453037Seric ** none. 69553037Seric */ 69653037Seric 69753037Seric bool 69853037Seric refuseconnections() 69953037Seric { 70053037Seric /* this is probably too simplistic */ 70153037Seric return (CurrentLA > RefuseLA); 70253037Seric } 70353037Seric /* 70424943Seric ** SETPROCTITLE -- set process title for ps 70524943Seric ** 70624943Seric ** Parameters: 70724943Seric ** fmt -- a printf style format string. 70824943Seric ** a, b, c -- possible parameters to fmt. 70924943Seric ** 71024943Seric ** Returns: 71124943Seric ** none. 71224943Seric ** 71324943Seric ** Side Effects: 71424943Seric ** Clobbers argv of our main procedure so ps(1) will 71524943Seric ** display the title. 71624943Seric */ 71724943Seric 71824943Seric /*VARARGS1*/ 71957642Seric #ifdef __STDC__ 72057642Seric setproctitle(char *fmt, ...) 72157642Seric #else 72257642Seric setproctitle(fmt, va_alist) 72324943Seric char *fmt; 72457642Seric va_dcl 72557642Seric #endif 72624943Seric { 72724943Seric # ifdef SETPROCTITLE 72824943Seric register char *p; 72925049Seric register int i; 73056852Seric char buf[MAXLINE]; 73156852Seric VA_LOCAL_DECL 73224943Seric extern char **Argv; 73324943Seric extern char *LastArgv; 73424943Seric 73554996Seric p = buf; 73624943Seric 73754996Seric /* print sendmail: heading for grep */ 73854996Seric (void) strcpy(p, "sendmail: "); 73954996Seric p += strlen(p); 74024943Seric 74154996Seric /* print the argument string */ 74256852Seric VA_START(fmt); 74356852Seric (void) vsprintf(p, fmt, ap); 74456852Seric VA_END; 74554996Seric 74625049Seric i = strlen(buf); 74754996Seric if (i > LastArgv - Argv[0] - 2) 74825049Seric { 74954996Seric i = LastArgv - Argv[0] - 2; 75025049Seric buf[i] = '\0'; 75125049Seric } 75254996Seric (void) strcpy(Argv[0], buf); 75354997Seric p = &Argv[0][i]; 75424943Seric while (p < LastArgv) 75524943Seric *p++ = ' '; 75656795Seric # endif /* SETPROCTITLE */ 75724943Seric } 75825698Seric /* 75925698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 76025698Seric ** 76125698Seric ** Parameters: 76225698Seric ** none. 76325698Seric ** 76425698Seric ** Returns: 76525698Seric ** none. 76625698Seric ** 76725698Seric ** Side Effects: 76825698Seric ** Picks up extant zombies. 76925698Seric */ 77025698Seric 77125698Seric # include <sys/wait.h> 77225698Seric 77346928Sbostic void 77425698Seric reapchild() 77525698Seric { 77625698Seric # ifdef WNOHANG 77725698Seric union wait status; 77825698Seric 77946928Sbostic while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0) 78025698Seric continue; 78156795Seric # else /* WNOHANG */ 78225698Seric auto int status; 78325698Seric 78446928Sbostic while (wait((int *)&status) > 0) 78525698Seric continue; 78656795Seric # endif /* WNOHANG */ 78725698Seric } 78855418Seric /* 78955418Seric ** UNSETENV -- remove a variable from the environment 79055418Seric ** 79155418Seric ** Not needed on newer systems. 79255418Seric ** 79355418Seric ** Parameters: 79455418Seric ** name -- the string name of the environment variable to be 79555418Seric ** deleted from the current environment. 79655418Seric ** 79755418Seric ** Returns: 79855418Seric ** none. 79955418Seric ** 80055418Seric ** Globals: 80155418Seric ** environ -- a pointer to the current environment. 80255418Seric ** 80355418Seric ** Side Effects: 80455418Seric ** Modifies environ. 80555418Seric */ 80655418Seric 80755418Seric #ifdef UNSETENV 80855418Seric 80955418Seric void 81055418Seric unsetenv(name) 81155418Seric char *name; 81255418Seric { 81355418Seric extern char **environ; 81455418Seric register char **pp; 81555418Seric int len = strlen(name); 81655418Seric 81755418Seric for (pp = environ; *pp != NULL; pp++) 81855418Seric { 81955418Seric if (strncmp(name, *pp, len) == 0 && 82055418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 82155418Seric break; 82255418Seric } 82355418Seric 82455418Seric for (; *pp != NULL; pp++) 82555418Seric *pp = pp[1]; 82655418Seric } 82755418Seric 82855418Seric #endif /* UNSETENV */ 82956215Seric /* 83056215Seric ** GETDTABLESIZE -- return number of file descriptors 83156215Seric ** 83256215Seric ** Only on non-BSD systems 83356215Seric ** 83456215Seric ** Parameters: 83556215Seric ** none 83656215Seric ** 83756215Seric ** Returns: 83856215Seric ** size of file descriptor table 83956215Seric ** 84056215Seric ** Side Effects: 84156215Seric ** none 84256215Seric */ 84356215Seric 84456215Seric #ifdef SYSTEM5 84556215Seric 84656215Seric int 84756215Seric getdtablesize() 84856215Seric { 84956215Seric return NOFILE; 85056215Seric } 85156215Seric 85256215Seric #endif 85357631Seric /* 85457631Seric ** UNAME -- get the UUCP name of this system. 85557631Seric */ 85657631Seric 85757631Seric #ifndef UNAME 85857631Seric 85957631Seric int 86057631Seric uname(name) 86157631Seric struct utsname *name; 86257631Seric { 86357631Seric FILE *file; 86457631Seric char *n; 86557631Seric 86657631Seric name->nodename[0] = '\0'; 86757631Seric 868*57661Seric /* try /etc/whoami -- one line with the node name */ 86957631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 87057631Seric { 871*57661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 87257631Seric (void) fclose(file); 873*57661Seric n = strchr(name->nodename, '\n'); 87457631Seric if (n != NULL) 87557631Seric *n = '\0'; 87657631Seric if (name->nodename[0] != '\0') 87757631Seric return (0); 87857631Seric } 87957631Seric 880*57661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 88157631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 88257631Seric { 88357631Seric char buf[MAXLINE]; 88457631Seric 88557631Seric while (fgets(buf, MAXLINE, file) != NULL) 88657631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 88757631Seric NODE_LENGTH, name->nodename) > 0) 88857631Seric break; 88957631Seric (void) fclose(file); 89057631Seric if (name->nodename[0] != '\0') 89157631Seric return (0); 89257631Seric } 89357631Seric 89457631Seric #ifdef TRUST_POPEN 89557631Seric /* 89657631Seric ** Popen is known to have security holes. 89757631Seric */ 89857631Seric 899*57661Seric /* try uuname -l to return local name */ 90057631Seric if ((file = popen("uuname -l", "r")) != NULL) 90157631Seric { 902*57661Seric (void) fgets(name, NODE_LENGTH + 1, file); 90357631Seric (void) pclose(file); 904*57661Seric n = strchr(name, '\n'); 90557631Seric if (n != NULL) 90657631Seric *n = '\0'; 907*57661Seric if (name->nodename[0] != '\0') 90857631Seric return (0); 90957631Seric } 91057631Seric #endif 91157631Seric 91257631Seric return (-1); 91357631Seric } 91457631Seric #endif /* UNAME */ 915