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*58160Seric static char sccsid[] = "@(#)conf.c 6.28 (Berkeley) 02/23/93"; 1133728Sbostic #endif /* not lint */ 1222698Sdist 1314881Seric # include <sys/ioctl.h> 1458082Seric # include <sys/param.h> 1558153Seric # include <signal.h> 1636928Sbostic # include <pwd.h> 173309Seric # include "sendmail.h" 1840980Sbostic # include "pathnames.h" 19404Seric 20294Seric /* 213309Seric ** CONF.C -- Sendmail Configuration Tables. 22294Seric ** 23294Seric ** Defines the configuration of this installation. 24294Seric ** 251388Seric ** Configuration Variables: 262897Seric ** HdrInfo -- a table describing well-known header fields. 272897Seric ** Each entry has the field name and some flags, 284147Seric ** which are described in sendmail.h. 294093Seric ** 304093Seric ** Notes: 314093Seric ** I have tried to put almost all the reasonable 324093Seric ** configuration information into the configuration 334093Seric ** file read at runtime. My intent is that anything 344093Seric ** here is a function of the version of UNIX you 354093Seric ** are running, or is really static -- for example 364093Seric ** the headers are a superset of widely used 374093Seric ** protocols. If you find yourself playing with 384093Seric ** this file too much, you may be making a mistake! 39294Seric */ 40294Seric 41294Seric 42294Seric 43294Seric 444437Seric /* 452897Seric ** Header info table 463057Seric ** Final (null) entry contains the flags used for any other field. 474147Seric ** 484147Seric ** Not all of these are actually handled specially by sendmail 494147Seric ** at this time. They are included as placeholders, to let 504147Seric ** you know that "someday" I intend to have sendmail do 514147Seric ** something with them. 522897Seric */ 532897Seric 542897Seric struct hdrinfo HdrInfo[] = 552897Seric { 568060Seric /* originator fields, most to least significant */ 5711417Seric "resent-sender", H_FROM|H_RESENT, 5811417Seric "resent-from", H_FROM|H_RESENT, 5925686Seric "resent-reply-to", H_FROM|H_RESENT, 609055Seric "sender", H_FROM, 619055Seric "from", H_FROM, 6225686Seric "reply-to", H_FROM, 639055Seric "full-name", H_ACHECK, 6457359Seric "return-receipt-to", H_FROM /* |H_RECEIPTTO */, 6557359Seric "errors-to", H_FROM|H_ERRORSTO, 668060Seric /* destination fields */ 679055Seric "to", H_RCPT, 6811417Seric "resent-to", H_RCPT|H_RESENT, 699055Seric "cc", H_RCPT, 7011417Seric "resent-cc", H_RCPT|H_RESENT, 719055Seric "bcc", H_RCPT|H_ACHECK, 7211417Seric "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, 7356215Seric "apparently-to", H_RCPT, 748060Seric /* message identification and control */ 7511417Seric "message-id", 0, 7611417Seric "resent-message-id", H_RESENT, 779055Seric "message", H_EOH, 789055Seric "text", H_EOH, 7911417Seric /* date fields */ 8011417Seric "date", 0, 8111417Seric "resent-date", H_RESENT, 828060Seric /* trace fields */ 839055Seric "received", H_TRACE|H_FORCE, 849055Seric "via", H_TRACE|H_FORCE, 859055Seric "mail-from", H_TRACE|H_FORCE, 868060Seric 879055Seric NULL, 0, 882897Seric }; 894166Seric 904166Seric 914166Seric 924282Seric /* 934282Seric ** Location of system files/databases/etc. 944282Seric */ 954282Seric 9640980Sbostic char *ConfFile = _PATH_SENDMAILCF; /* runtime configuration */ 9740980Sbostic char *FreezeFile = _PATH_SENDMAILFC; /* frozen version of above */ 9858082Seric char *PidFile = _PATH_SENDMAILPID; /* stores daemon proc id */ 999039Seric 1009064Seric 1019064Seric 1029039Seric /* 10358082Seric ** Privacy values 10458082Seric */ 10558082Seric 10658082Seric struct prival PrivacyValues[] = 10758082Seric { 10858082Seric "public", PRIV_PUBLIC, 10958082Seric "needmailhelo", PRIV_NEEDMAILHELO, 11058114Seric "needexpnhelo", PRIV_NEEDEXPNHELO, 11158082Seric "needvrfyhelo", PRIV_NEEDVRFYHELO, 11258082Seric "noexpn", PRIV_NOEXPN, 11358082Seric "novrfy", PRIV_NOVRFY, 11458082Seric "goaway", PRIV_GOAWAY, 11558082Seric NULL, PRIV_PUBLIC, 11658082Seric }; 11758082Seric 11858082Seric 11958082Seric 12058082Seric /* 12124943Seric ** Miscellaneous stuff. 1229039Seric */ 1239039Seric 12424943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 12524943Seric /* 12624943Seric ** SETDEFAULTS -- set default values 12724943Seric ** 12824943Seric ** Because of the way freezing is done, these must be initialized 12924943Seric ** using direct code. 13024943Seric ** 13124943Seric ** Parameters: 13224943Seric ** none. 13324943Seric ** 13424943Seric ** Returns: 13524943Seric ** none. 13624943Seric ** 13724943Seric ** Side Effects: 13824943Seric ** Initializes a bunch of global variables to their 13924943Seric ** default values. 14024943Seric */ 14124943Seric 14224943Seric setdefaults() 14324943Seric { 14457438Seric SpaceSub = ' '; /* option B */ 14557438Seric QueueLA = 8; /* option x */ 14657438Seric RefuseLA = 12; /* option X */ 14757438Seric WkRecipFact = 30000L; /* option y */ 14857438Seric WkClassFact = 1800L; /* option z */ 14957438Seric WkTimeFact = 90000L; /* option Z */ 15057438Seric QueueFactor = WkRecipFact * 20; /* option q */ 15157142Seric FileMode = (getuid() != geteuid()) ? 0644 : 0600; 15257438Seric /* option F */ 15357438Seric DefUid = 1; /* option u */ 15457438Seric DefGid = 1; /* option g */ 15557438Seric CheckpointInterval = 10; /* option C */ 15657438Seric MaxHopCount = 25; /* option h */ 15757438Seric SendMode = SM_FORK; /* option d */ 15857438Seric ErrorMode = EM_PRINT; /* option e */ 15957438Seric EightBit = FALSE; /* option 8 */ 16057438Seric MaxMciCache = 1; /* option k */ 16157438Seric MciCacheTimeout = 300; /* option K */ 16257438Seric LogLevel = 9; /* option L */ 16358112Seric settimeouts(NULL); /* option r */ 16458112Seric TimeOut = 5 * 24 * 60 * 60; /* option T */ 16540973Sbostic setdefuser(); 16653654Seric setupmaps(); 16757402Seric setupmailers(); 16824943Seric } 169294Seric 17040973Sbostic 1714326Seric /* 17240973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 17340973Sbostic */ 17440973Sbostic 17540973Sbostic setdefuser() 17640973Sbostic { 17740973Sbostic struct passwd *defpwent; 17857386Seric static char defuserbuf[40]; 17940973Sbostic 18057386Seric DefUser = defuserbuf; 18140973Sbostic if ((defpwent = getpwuid(DefUid)) != NULL) 18257386Seric strcpy(defuserbuf, defpwent->pw_name); 18340973Sbostic else 18457386Seric strcpy(defuserbuf, "nobody"); 18540973Sbostic } 18653654Seric /* 18753654Seric ** SETUPMAPS -- set up map classes 18853654Seric ** 18953654Seric ** Since these are compiled in, they cannot be in the config file. 19053654Seric ** 19153654Seric */ 19240973Sbostic 19353654Seric setupmaps() 19453654Seric { 19553654Seric register STAB *s; 19656836Seric extern bool host_map_init(); 19753654Seric extern char *maphostname(); 19840973Sbostic 19953654Seric /* set up host name lookup map */ 20053654Seric s = stab("host", ST_MAPCLASS, ST_ENTER); 20156836Seric s->s_mapclass.map_init = host_map_init; 20253654Seric s->s_mapclass.map_lookup = maphostname; 20353654Seric 20453654Seric /* 20553654Seric ** Set up other map classes. 20653654Seric */ 20753654Seric 20853654Seric # ifdef DBM_MAP 20953654Seric /* dbm file access */ 21053654Seric { 21156836Seric extern bool dbm_map_init(); 21253654Seric extern char *dbm_map_lookup(); 21353654Seric 21453654Seric s = stab("dbm", ST_MAPCLASS, ST_ENTER); 21553654Seric s->s_mapclass.map_init = dbm_map_init; 21653654Seric s->s_mapclass.map_lookup = dbm_map_lookup; 21753654Seric } 21853654Seric # endif 21953654Seric 22053654Seric # ifdef BTREE_MAP 22153654Seric /* new database file access -- btree files */ 22253654Seric { 22356823Seric extern bool bt_map_init(); 22456823Seric extern char *db_map_lookup(); 22553654Seric 22653654Seric s = stab("btree", ST_MAPCLASS, ST_ENTER); 22753654Seric s->s_mapclass.map_init = bt_map_init; 22856823Seric s->s_mapclass.map_lookup = db_map_lookup; 22953654Seric } 23053654Seric # endif 23153654Seric 23253654Seric # ifdef HASH_MAP 23353654Seric /* new database file access -- hash files */ 23453654Seric { 23556823Seric extern bool hash_map_init(); 23656823Seric extern char *db_map_lookup(); 23753654Seric 23853654Seric s = stab("hash", ST_MAPCLASS, ST_ENTER); 23953654Seric s->s_mapclass.map_init = hash_map_init; 24056823Seric s->s_mapclass.map_lookup = db_map_lookup; 24153654Seric } 24253654Seric # endif 24353654Seric 24457208Seric # ifdef NIS_MAP 24557208Seric /* NIS map access */ 24657208Seric { 24757208Seric extern bool nis_map_init(); 24857208Seric extern char *nis_map_lookup(); 24957208Seric 25057208Seric s = stab("nis", ST_MAPCLASS, ST_ENTER); 25157208Seric s->s_mapclass.map_init = nis_map_init; 25257208Seric s->s_mapclass.map_lookup = nis_map_lookup; 25357208Seric } 25457208Seric # endif 25557208Seric 25653654Seric # ifdef USERDB_MAP 25753654Seric /* user database */ 25853654Seric { 25956836Seric extern bool udb_map_init(); 26053654Seric extern char *udb_map_lookup(); 26153654Seric 26253654Seric s = stab("udb", ST_MAPCLASS, ST_ENTER); 26353654Seric s->s_mapclass.map_init = udb_map_init; 26453654Seric s->s_mapclass.map_lookup = udb_map_lookup; 26553654Seric } 26653654Seric # endif 26753654Seric } 26853654Seric /* 26956836Seric ** HOST_MAP_INIT -- initialize host class structures 27056836Seric */ 27156836Seric 27256836Seric bool 27356836Seric host_map_init(map, mapname, args) 27456836Seric MAP *map; 27556836Seric char *mapname; 27656836Seric char *args; 27756836Seric { 27856836Seric register char *p = args; 27956836Seric 28056836Seric for (;;) 28156836Seric { 28258050Seric while (isascii(*p) && isspace(*p)) 28356836Seric p++; 28456836Seric if (*p != '-') 28556836Seric break; 28656836Seric switch (*++p) 28756836Seric { 28856836Seric case 'a': 28956836Seric map->map_app = ++p; 29056836Seric break; 29156836Seric } 29258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 29356836Seric p++; 29456836Seric if (*p != '\0') 29556836Seric *p++ = '\0'; 29656836Seric } 29756836Seric if (map->map_app != NULL) 29856836Seric map->map_app = newstr(map->map_app); 29956836Seric return TRUE; 30056836Seric } 30157402Seric /* 30257402Seric ** SETUPMAILERS -- initialize default mailers 30357402Seric */ 30456836Seric 30557402Seric setupmailers() 30657402Seric { 30757402Seric char buf[100]; 30857402Seric 30957403Seric strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u"); 31057403Seric makemailer(buf); 31157403Seric 31257402Seric strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE"); 31357402Seric makemailer(buf); 31457402Seric 31557402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 31657402Seric makemailer(buf); 31757402Seric } 31856836Seric /* 3194326Seric ** GETRUID -- get real user id (V7) 3204326Seric */ 3214326Seric 3224326Seric getruid() 3234326Seric { 3249274Seric if (OpMode == MD_DAEMON) 3254536Seric return (RealUid); 3264536Seric else 3274536Seric return (getuid()); 3284326Seric } 3294326Seric 3304326Seric 3314326Seric /* 3324326Seric ** GETRGID -- get real group id (V7). 3334326Seric */ 3344326Seric 3354326Seric getrgid() 3364326Seric { 3379274Seric if (OpMode == MD_DAEMON) 3384536Seric return (RealGid); 3394536Seric else 3404536Seric return (getgid()); 3414326Seric } 34253654Seric /* 3439369Seric ** USERNAME -- return the user id of the logged in user. 3449369Seric ** 3459369Seric ** Parameters: 3469369Seric ** none. 3479369Seric ** 3489369Seric ** Returns: 3499369Seric ** The login name of the logged in user. 3509369Seric ** 3519369Seric ** Side Effects: 3529369Seric ** none. 3539369Seric ** 3549369Seric ** Notes: 3559369Seric ** The return value is statically allocated. 3569369Seric */ 3579369Seric 3589369Seric char * 3599369Seric username() 3609369Seric { 36117469Seric static char *myname = NULL; 3629369Seric extern char *getlogin(); 36319904Smiriam register struct passwd *pw; 3649369Seric 36517469Seric /* cache the result */ 36617469Seric if (myname == NULL) 36717469Seric { 36817469Seric myname = getlogin(); 36917469Seric if (myname == NULL || myname[0] == '\0') 37017469Seric { 37117469Seric 37217469Seric pw = getpwuid(getruid()); 37317469Seric if (pw != NULL) 37440993Sbostic myname = newstr(pw->pw_name); 37517469Seric } 37619904Smiriam else 37719904Smiriam { 37819873Smiriam 37940993Sbostic myname = newstr(myname); 38040993Sbostic if ((pw = getpwnam(myname)) == NULL || 38140993Sbostic getuid() != pw->pw_uid) 38219904Smiriam { 38319873Smiriam pw = getpwuid(getuid()); 38424945Seric if (pw != NULL) 38540993Sbostic myname = newstr(pw->pw_name); 38619873Smiriam } 38719873Smiriam } 38817469Seric if (myname == NULL || myname[0] == '\0') 38917469Seric { 39058151Seric syserr("554 Who are you?"); 39117469Seric myname = "postmaster"; 39217469Seric } 39317469Seric } 39417469Seric 39517469Seric return (myname); 3969369Seric } 3979369Seric /* 3984190Seric ** TTYPATH -- Get the path of the user's tty 399294Seric ** 400294Seric ** Returns the pathname of the user's tty. Returns NULL if 401294Seric ** the user is not logged in or if s/he has write permission 402294Seric ** denied. 403294Seric ** 404294Seric ** Parameters: 405294Seric ** none 406294Seric ** 407294Seric ** Returns: 408294Seric ** pathname of the user's tty. 409294Seric ** NULL if not logged in or write permission denied. 410294Seric ** 411294Seric ** Side Effects: 412294Seric ** none. 413294Seric ** 414294Seric ** WARNING: 415294Seric ** Return value is in a local buffer. 416294Seric ** 417294Seric ** Called By: 418294Seric ** savemail 419294Seric */ 420294Seric 421294Seric # include <sys/stat.h> 422294Seric 423294Seric char * 424294Seric ttypath() 425294Seric { 426294Seric struct stat stbuf; 427294Seric register char *pathn; 428294Seric extern char *ttyname(); 4294081Seric extern char *getlogin(); 430294Seric 431294Seric /* compute the pathname of the controlling tty */ 4329369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 4339369Seric (pathn = ttyname(0)) == NULL) 434294Seric { 435294Seric errno = 0; 436294Seric return (NULL); 437294Seric } 438294Seric 439294Seric /* see if we have write permission */ 4402967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 441294Seric { 442294Seric errno = 0; 443294Seric return (NULL); 444294Seric } 445294Seric 446294Seric /* see if the user is logged in */ 447294Seric if (getlogin() == NULL) 448294Seric return (NULL); 449294Seric 450294Seric /* looks good */ 451294Seric return (pathn); 452294Seric } 4532967Seric /* 4542967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4552967Seric ** 4562967Seric ** This routine can be supplied on a per-installation basis 4572967Seric ** to determine whether a person is allowed to send a message. 4582967Seric ** This allows restriction of certain types of internet 4592967Seric ** forwarding or registration of users. 4602967Seric ** 4612967Seric ** If the hosts are found to be incompatible, an error 46257454Seric ** message should be given using "usrerr" and 0 should 4632967Seric ** be returned. 4642967Seric ** 4654288Seric ** 'NoReturn' can be set to suppress the return-to-sender 4664288Seric ** function; this should be done on huge messages. 4674288Seric ** 4682967Seric ** Parameters: 4692967Seric ** to -- the person being sent to. 4702967Seric ** 4712967Seric ** Returns: 47257459Seric ** an exit status 4732967Seric ** 4742967Seric ** Side Effects: 4752967Seric ** none (unless you include the usrerr stuff) 4762967Seric */ 4772967Seric 47855012Seric checkcompat(to, e) 4792967Seric register ADDRESS *to; 48055012Seric register ENVELOPE *e; 4812967Seric { 48212133Seric # ifdef lint 48312133Seric if (to == NULL) 48412133Seric to++; 48512133Seric # endif lint 48610698Seric # ifdef EXAMPLE_CODE 48710698Seric /* this code is intended as an example only */ 4884437Seric register STAB *s; 4894437Seric 4904437Seric s = stab("arpa", ST_MAILER, ST_FIND); 49155012Seric if (s != NULL && e->e_from.q_mailer != LocalMailer && 4929369Seric to->q_mailer == s->s_mailer) 4934437Seric { 49458151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 49510698Seric /* NoReturn = TRUE; to supress return copy */ 49657459Seric return (EX_UNAVAILABLE); 4974437Seric } 49856795Seric # endif /* EXAMPLE_CODE */ 49957459Seric return (EX_OK); 5002967Seric } 5019369Seric /* 5029369Seric ** HOLDSIGS -- arrange to hold all signals 5039369Seric ** 5049369Seric ** Parameters: 5059369Seric ** none. 5069369Seric ** 5079369Seric ** Returns: 5089369Seric ** none. 5099369Seric ** 5109369Seric ** Side Effects: 5119369Seric ** Arranges that signals are held. 5129369Seric */ 5139369Seric 5149369Seric holdsigs() 5159369Seric { 5169369Seric } 5179369Seric /* 5189369Seric ** RLSESIGS -- arrange to release all signals 5199369Seric ** 5209369Seric ** This undoes the effect of holdsigs. 5219369Seric ** 5229369Seric ** Parameters: 5239369Seric ** none. 5249369Seric ** 5259369Seric ** Returns: 5269369Seric ** none. 5279369Seric ** 5289369Seric ** Side Effects: 5299369Seric ** Arranges that signals are released. 5309369Seric */ 5319369Seric 5329369Seric rlsesigs() 5339369Seric { 5349369Seric } 53514872Seric /* 53614872Seric ** GETLA -- get the current load average 53714872Seric ** 53814881Seric ** This code stolen from la.c. 53914881Seric ** 54014872Seric ** Parameters: 54114872Seric ** none. 54214872Seric ** 54314872Seric ** Returns: 54414872Seric ** The current load average as an integer. 54514872Seric ** 54614872Seric ** Side Effects: 54714872Seric ** none. 54814872Seric */ 54914872Seric 55051920Seric /* try to guess what style of load average we have */ 55151920Seric #define LA_ZERO 1 /* always return load average as zero */ 55251920Seric #define LA_INT 2 /* read kmem for avenrun; interpret as int */ 55351920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 55451920Seric #define LA_SUBR 4 /* call getloadavg */ 55514872Seric 55651920Seric #ifndef LA_TYPE 55751920Seric # if defined(sun) 55851920Seric # define LA_TYPE LA_INT 55951920Seric # endif 56057977Seric # if defined(mips) || defined(__alpha) 56157977Seric /* Ultrix or OSF/1 or RISC/os */ 56251920Seric # define LA_TYPE LA_INT 56351920Seric # define LA_AVENRUN "avenrun" 56451920Seric # endif 56551920Seric # if defined(hpux) 56651920Seric # define LA_TYPE LA_FLOAT 56751920Seric # endif 56851920Seric 56951920Seric # ifndef LA_TYPE 57057736Seric # if defined(SYSTEM5) 57157736Seric # define LA_TYPE LA_INT 57257736Seric # define LA_AVENRUN "avenrun" 57357736Seric # else 57457736Seric # if defined(BSD) 57557736Seric # define LA_TYPE LA_SUBR 57657736Seric # else 57757736Seric # define LA_TYPE LA_ZERO 57857736Seric # endif 57957736Seric # endif 58051920Seric # endif 58151920Seric #endif 58251920Seric 58351920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) 58451920Seric 58514872Seric #include <nlist.h> 58651920Seric #include <fcntl.h> 58714872Seric 58851920Seric #ifndef LA_AVENRUN 58951920Seric #define LA_AVENRUN "_avenrun" 59051920Seric #endif 59151920Seric 59251920Seric /* _PATH_UNIX should be defined in <paths.h> */ 59351920Seric #ifndef _PATH_UNIX 59451920Seric # if defined(hpux) 59551920Seric # define _PATH_UNIX "/hp-ux" 59651920Seric # endif 59751920Seric # if defined(mips) && !defined(ultrix) 59851920Seric /* powerful RISC/os */ 59951920Seric # define _PATH_UNIX "/unix" 60051920Seric # endif 60157736Seric # if defined(SYSTEM5) 60257977Seric # ifndef _PATH_UNIX 60357977Seric # define _PATH_UNIX "/unix" 60457977Seric # endif 60557736Seric # endif 60651920Seric # ifndef _PATH_UNIX 60751920Seric # define _PATH_UNIX "/vmunix" 60851920Seric # endif 60951920Seric #endif 61051920Seric 61114872Seric struct nlist Nl[] = 61214872Seric { 61351920Seric { LA_AVENRUN }, 61414872Seric #define X_AVENRUN 0 61514872Seric { 0 }, 61614872Seric }; 61714872Seric 61857736Seric #if defined(unixpc) 61957736Seric # define FSHIFT 5 62057736Seric #endif 62157736Seric 62257977Seric #if defined(__alpha) 62357977Seric # define FSHIFT 10 62457977Seric #endif 62557977Seric 62651920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT) 62751920Seric # define FSHIFT 8 62857736Seric #endif 62957736Seric #if (LA_TYPE == LA_INT) && !defined(FSCALE) 63051920Seric # define FSCALE (1 << FSHIFT) 63151920Seric #endif 63240930Srick 63314872Seric getla() 63414872Seric { 63514872Seric static int kmem = -1; 63651920Seric #if LA_TYPE == LA_INT 63724943Seric long avenrun[3]; 63851920Seric #else 63951920Seric double avenrun[3]; 64051920Seric #endif 64125615Seric extern off_t lseek(); 64257736Seric extern char *errstring(); 64357736Seric extern int errno; 64414872Seric 64514872Seric if (kmem < 0) 64614872Seric { 64724945Seric kmem = open("/dev/kmem", 0, 0); 64814872Seric if (kmem < 0) 64957736Seric { 65057736Seric if (tTd(3, 1)) 65157736Seric printf("getla: open(/dev/kmem): %s\n", 65257736Seric errstring(errno)); 65314872Seric return (-1); 65457736Seric } 65551920Seric (void) fcntl(kmem, F_SETFD, 1); 65657736Seric if (nlist(_PATH_UNIX, Nl) < 0) 65757736Seric { 65857736Seric if (tTd(3, 1)) 65957736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 66057736Seric errstring(errno)); 66114872Seric return (-1); 66257736Seric } 66314872Seric } 66457736Seric if (tTd(3, 20)) 66557736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 66624945Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 || 66723118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 66819967Seric { 66919967Seric /* thank you Ian */ 67057736Seric if (tTd(3, 1)) 67157736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 67219967Seric return (-1); 67319967Seric } 67451920Seric #if LA_TYPE == LA_INT 67557736Seric if (tTd(3, 5)) 67657736Seric { 67757736Seric printf("getla: avenrun = %d", avenrun[0]); 67857736Seric if (tTd(3, 15)) 67957736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 68057736Seric printf("\n"); 68157736Seric } 68257736Seric if (tTd(3, 1)) 68357736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 68424943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 68551920Seric #else 68657736Seric if (tTd(3, 5)) 68757736Seric { 68857736Seric printf("getla: avenrun = %g", avenrun[0]); 68957736Seric if (tTd(3, 15)) 69057736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 69157736Seric printf("\n"); 69257736Seric } 69357736Seric if (tTd(3, 1)) 69457736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 69551920Seric return ((int) (avenrun[0] + 0.5)); 69651920Seric #endif 69714872Seric } 69814872Seric 69951773Seric #else 70051920Seric #if LA_TYPE == LA_SUBR 70151773Seric 70251773Seric getla() 70351773Seric { 70451920Seric double avenrun[3]; 70551920Seric 70651920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 70757736Seric { 70857736Seric if (tTd(3, 1)) 70957736Seric perror("getla: getloadavg failed:"); 71051920Seric return (-1); 71157736Seric } 71257736Seric if (tTd(3, 1)) 71357736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 71451920Seric return ((int) (avenrun[0] + 0.5)); 71551773Seric } 71651773Seric 71751773Seric #else 71851773Seric 71951773Seric getla() 72051773Seric { 72157736Seric if (tTd(3, 1)) 72257736Seric printf("getla: ZERO\n"); 72351920Seric return (0); 72451773Seric } 72551773Seric 72651773Seric #endif 72751773Seric #endif 72824943Seric /* 72924943Seric ** SHOULDQUEUE -- should this message be queued or sent? 73024943Seric ** 73124943Seric ** Compares the message cost to the load average to decide. 73224943Seric ** 73324943Seric ** Parameters: 73424943Seric ** pri -- the priority of the message in question. 73557438Seric ** ctime -- the message creation time. 73624943Seric ** 73724943Seric ** Returns: 73824943Seric ** TRUE -- if this message should be queued up for the 73924943Seric ** time being. 74024943Seric ** FALSE -- if the load is low enough to send this message. 74124943Seric ** 74224943Seric ** Side Effects: 74324943Seric ** none. 74424943Seric */ 74524943Seric 74624943Seric bool 74757438Seric shouldqueue(pri, ctime) 74824943Seric long pri; 74957438Seric time_t ctime; 75024943Seric { 75151920Seric if (CurrentLA < QueueLA) 75224943Seric return (FALSE); 75358132Seric if (CurrentLA >= RefuseLA) 75458132Seric return (TRUE); 75551920Seric return (pri > (QueueFactor / (CurrentLA - QueueLA + 1))); 75624943Seric } 75724943Seric /* 75853037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 75953037Seric ** 76053037Seric ** Parameters: 76153037Seric ** none. 76253037Seric ** 76353037Seric ** Returns: 76453037Seric ** TRUE if incoming SMTP connections should be refused 76553037Seric ** (for now). 76653037Seric ** FALSE if we should accept new work. 76753037Seric ** 76853037Seric ** Side Effects: 76953037Seric ** none. 77053037Seric */ 77153037Seric 77253037Seric bool 77353037Seric refuseconnections() 77453037Seric { 77553037Seric /* this is probably too simplistic */ 77658132Seric return (CurrentLA >= RefuseLA); 77753037Seric } 77853037Seric /* 77924943Seric ** SETPROCTITLE -- set process title for ps 78024943Seric ** 78124943Seric ** Parameters: 78224943Seric ** fmt -- a printf style format string. 78324943Seric ** a, b, c -- possible parameters to fmt. 78424943Seric ** 78524943Seric ** Returns: 78624943Seric ** none. 78724943Seric ** 78824943Seric ** Side Effects: 78924943Seric ** Clobbers argv of our main procedure so ps(1) will 79024943Seric ** display the title. 79124943Seric */ 79224943Seric 79324943Seric /*VARARGS1*/ 79457642Seric #ifdef __STDC__ 79557642Seric setproctitle(char *fmt, ...) 79657642Seric #else 79757642Seric setproctitle(fmt, va_alist) 79824943Seric char *fmt; 79957642Seric va_dcl 80057642Seric #endif 80124943Seric { 80224943Seric # ifdef SETPROCTITLE 80324943Seric register char *p; 80425049Seric register int i; 80556852Seric char buf[MAXLINE]; 80656852Seric VA_LOCAL_DECL 80724943Seric extern char **Argv; 80824943Seric extern char *LastArgv; 80924943Seric 81054996Seric p = buf; 81124943Seric 81254996Seric /* print sendmail: heading for grep */ 81354996Seric (void) strcpy(p, "sendmail: "); 81454996Seric p += strlen(p); 81524943Seric 81654996Seric /* print the argument string */ 81756852Seric VA_START(fmt); 81856852Seric (void) vsprintf(p, fmt, ap); 81956852Seric VA_END; 82054996Seric 82125049Seric i = strlen(buf); 82254996Seric if (i > LastArgv - Argv[0] - 2) 82325049Seric { 82454996Seric i = LastArgv - Argv[0] - 2; 82525049Seric buf[i] = '\0'; 82625049Seric } 82754996Seric (void) strcpy(Argv[0], buf); 82854997Seric p = &Argv[0][i]; 82924943Seric while (p < LastArgv) 83024943Seric *p++ = ' '; 83156795Seric # endif /* SETPROCTITLE */ 83224943Seric } 83325698Seric /* 83425698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 83525698Seric ** 83625698Seric ** Parameters: 83725698Seric ** none. 83825698Seric ** 83925698Seric ** Returns: 84025698Seric ** none. 84125698Seric ** 84225698Seric ** Side Effects: 84325698Seric ** Picks up extant zombies. 84425698Seric */ 84525698Seric 84625698Seric # include <sys/wait.h> 84725698Seric 84846928Sbostic void 84925698Seric reapchild() 85025698Seric { 85125698Seric # ifdef WNOHANG 85225698Seric union wait status; 85325698Seric 85446928Sbostic while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0) 85525698Seric continue; 85656795Seric # else /* WNOHANG */ 85725698Seric auto int status; 85825698Seric 85946928Sbostic while (wait((int *)&status) > 0) 86025698Seric continue; 86156795Seric # endif /* WNOHANG */ 86258061Seric # ifdef SYSTEM5 86358061Seric (void) signal(SIGCHLD, reapchild); 86458061Seric # endif 86525698Seric } 86655418Seric /* 86755418Seric ** UNSETENV -- remove a variable from the environment 86855418Seric ** 86955418Seric ** Not needed on newer systems. 87055418Seric ** 87155418Seric ** Parameters: 87255418Seric ** name -- the string name of the environment variable to be 87355418Seric ** deleted from the current environment. 87455418Seric ** 87555418Seric ** Returns: 87655418Seric ** none. 87755418Seric ** 87855418Seric ** Globals: 87955418Seric ** environ -- a pointer to the current environment. 88055418Seric ** 88155418Seric ** Side Effects: 88255418Seric ** Modifies environ. 88355418Seric */ 88455418Seric 88555418Seric #ifdef UNSETENV 88655418Seric 88755418Seric void 88855418Seric unsetenv(name) 88955418Seric char *name; 89055418Seric { 89155418Seric extern char **environ; 89255418Seric register char **pp; 89355418Seric int len = strlen(name); 89455418Seric 89555418Seric for (pp = environ; *pp != NULL; pp++) 89655418Seric { 89755418Seric if (strncmp(name, *pp, len) == 0 && 89855418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 89955418Seric break; 90055418Seric } 90155418Seric 90255418Seric for (; *pp != NULL; pp++) 90355418Seric *pp = pp[1]; 90455418Seric } 90555418Seric 90655418Seric #endif /* UNSETENV */ 90756215Seric /* 90856215Seric ** GETDTABLESIZE -- return number of file descriptors 90956215Seric ** 91056215Seric ** Only on non-BSD systems 91156215Seric ** 91256215Seric ** Parameters: 91356215Seric ** none 91456215Seric ** 91556215Seric ** Returns: 91656215Seric ** size of file descriptor table 91756215Seric ** 91856215Seric ** Side Effects: 91956215Seric ** none 92056215Seric */ 92156215Seric 92256215Seric #ifdef SYSTEM5 92356215Seric 92456215Seric int 92556215Seric getdtablesize() 92656215Seric { 92756215Seric return NOFILE; 92856215Seric } 92956215Seric 93056215Seric #endif 93157631Seric /* 93257631Seric ** UNAME -- get the UUCP name of this system. 93357631Seric */ 93457631Seric 93557943Seric #ifndef HASUNAME 93657631Seric 93757631Seric int 93857631Seric uname(name) 93957631Seric struct utsname *name; 94057631Seric { 94157631Seric FILE *file; 94257631Seric char *n; 94357631Seric 94457631Seric name->nodename[0] = '\0'; 94557631Seric 94657661Seric /* try /etc/whoami -- one line with the node name */ 94757631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 94857631Seric { 94957661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 95057631Seric (void) fclose(file); 95157661Seric n = strchr(name->nodename, '\n'); 95257631Seric if (n != NULL) 95357631Seric *n = '\0'; 95457631Seric if (name->nodename[0] != '\0') 95557631Seric return (0); 95657631Seric } 95757631Seric 95857661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 95957631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 96057631Seric { 96157631Seric char buf[MAXLINE]; 96257631Seric 96357631Seric while (fgets(buf, MAXLINE, file) != NULL) 96457631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 96557631Seric NODE_LENGTH, name->nodename) > 0) 96657631Seric break; 96757631Seric (void) fclose(file); 96857631Seric if (name->nodename[0] != '\0') 96957631Seric return (0); 97057631Seric } 97157631Seric 97257631Seric #ifdef TRUST_POPEN 97357631Seric /* 97457631Seric ** Popen is known to have security holes. 97557631Seric */ 97657631Seric 97757661Seric /* try uuname -l to return local name */ 97857631Seric if ((file = popen("uuname -l", "r")) != NULL) 97957631Seric { 98057661Seric (void) fgets(name, NODE_LENGTH + 1, file); 98157631Seric (void) pclose(file); 98257661Seric n = strchr(name, '\n'); 98357631Seric if (n != NULL) 98457631Seric *n = '\0'; 98557661Seric if (name->nodename[0] != '\0') 98657631Seric return (0); 98757631Seric } 98857631Seric #endif 98957631Seric 99057631Seric return (-1); 99157631Seric } 99257943Seric #endif /* HASUNAME */ 99358068Seric /* 99458068Seric ** INITGROUPS -- initialize groups 99558068Seric ** 99658068Seric ** Stub implementation for System V style systems 99758068Seric */ 99858068Seric 99958068Seric #ifndef HASINITGROUPS 100058068Seric # if !defined(SYSTEM5) || defined(hpux) 100158068Seric # define HASINITGROUPS 100258068Seric # endif 100358068Seric #endif 100458068Seric 100558068Seric #ifndef HASINITGROUPS 100658068Seric 100758068Seric initgroups(name, basegid) 100858068Seric char *name; 100958068Seric int basegid; 101058068Seric { 101158068Seric return 0; 101258068Seric } 101358068Seric 101458068Seric #endif 101558082Seric /* 101658082Seric ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 101758082Seric ** 101858082Seric ** Only implemented if you have statfs. 101958082Seric ** 102058082Seric ** Parameters: 102158082Seric ** none. 102258082Seric ** 102358082Seric ** Returns: 102458082Seric ** TRUE if there is enough space. 102558082Seric ** FALSE otherwise. 102658082Seric */ 102758082Seric 102858082Seric #ifndef HASSTATFS 102958082Seric # if defined(BSD4_4) || defined(__osf__) 103058082Seric # define HASSTATFS 103158082Seric # endif 103258082Seric #endif 103358082Seric 103458082Seric #ifdef HASSTATFS 103558157Seric # undef HASUSTAT 103658157Seric #endif 103758157Seric 103858157Seric #if defined(HASUSTAT) 103958157Seric # include <sys/types.h> 104058157Seric # include <sys/stat.h> 104158157Seric # include <ustat.h> 104258157Seric #endif 104358157Seric 104458157Seric #ifdef HASSTATFS 104558133Seric # if defined(sgi) || defined(apollo) 104658133Seric # include <sys/statfs.h> 104758133Seric # else 104858133Seric # if defined(sun) || defined(hpux) 104958133Seric # include <sys/vfs.h> 105058133Seric # else 105158157Seric # include <sys/mount.h> 105258133Seric # endif 105358133Seric # endif 105458082Seric #endif 105558082Seric 105658082Seric bool 105758082Seric enoughspace() 105858082Seric { 1059*58160Seric #if defined(HASSTATFS) || defined(HASUSTAT) 106058157Seric # if defined(HASUSTAT) 106158153Seric struct ustat fs; 106258153Seric struct stat statbuf; 106358157Seric # define f_bavail f_tfree 106458157Seric # else 106558157Seric # if defined(ultrix) 106658157Seric struct fs_data fs; 106758157Seric # define f_bavail fd_bfreen 106858153Seric # else 106958082Seric struct statfs fs; 107058153Seric # endif 107158133Seric # endif 107258082Seric extern int errno; 107358082Seric extern char *errstring(); 107458082Seric 107558133Seric if (MinBlocksFree <= 0) 107658082Seric { 107758082Seric if (tTd(4, 80)) 107858133Seric printf("enoughspace: no threshold\n"); 107958133Seric return TRUE; 108058133Seric } 108158157Seric # if defined(HASUSTAT) 108258157Seric if (stat(QueueDir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 108358157Seric # else 108458157Seric # if defined(sgi) || defined(apollo) 108558133Seric if (statfs(QueueDir, &fs, sizeof fs, 0) == 0) 108658157Seric # else 108758157Seric # if defined(ultrix) 108858133Seric if (statfs(QueueDir, &fs) > 0) 108958153Seric # else 109058133Seric if (statfs(QueueDir, &fs) == 0) 109158153Seric # endif 109258133Seric # endif 109358133Seric # endif 109458133Seric { 109558133Seric if (tTd(4, 80)) 109658115Seric printf("enoughspace: bavail=%ld, min=%ld\n", 109758115Seric fs.f_bavail, MinBlocksFree); 109858115Seric if (fs.f_bavail < MinBlocksFree) 109958090Seric { 110058090Seric #ifdef LOG 110158090Seric if (LogLevel > 0) 110258090Seric syslog(LOG_ALERT, "%s: low on space (have %ld, need %ld)", 110358115Seric QueueDir, fs.f_bavail, MinBlocksFree); 110458090Seric #endif 110558082Seric return FALSE; 110658090Seric } 110758082Seric } 110858082Seric else if (tTd(4, 80)) 110958082Seric printf("enoughspace: min=%ld: %s\n", 111058082Seric MinBlocksFree, errstring(errno)); 111158082Seric #endif 111258082Seric return TRUE; 111358082Seric } 1114