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*58112Seric static char sccsid[] = "@(#)conf.c 6.20 (Berkeley) 02/21/93"; 1133728Sbostic #endif /* not lint */ 1222698Sdist 1314881Seric # include <sys/ioctl.h> 1458082Seric # include <sys/param.h> 1536928Sbostic # include <pwd.h> 163309Seric # include "sendmail.h" 1740980Sbostic # include "pathnames.h" 18404Seric 19294Seric /* 203309Seric ** CONF.C -- Sendmail Configuration Tables. 21294Seric ** 22294Seric ** Defines the configuration of this installation. 23294Seric ** 241388Seric ** Configuration Variables: 252897Seric ** HdrInfo -- a table describing well-known header fields. 262897Seric ** Each entry has the field name and some flags, 274147Seric ** which are described in sendmail.h. 284093Seric ** 294093Seric ** Notes: 304093Seric ** I have tried to put almost all the reasonable 314093Seric ** configuration information into the configuration 324093Seric ** file read at runtime. My intent is that anything 334093Seric ** here is a function of the version of UNIX you 344093Seric ** are running, or is really static -- for example 354093Seric ** the headers are a superset of widely used 364093Seric ** protocols. If you find yourself playing with 374093Seric ** this file too much, you may be making a mistake! 38294Seric */ 39294Seric 40294Seric 41294Seric 42294Seric 434437Seric /* 442897Seric ** Header info table 453057Seric ** Final (null) entry contains the flags used for any other field. 464147Seric ** 474147Seric ** Not all of these are actually handled specially by sendmail 484147Seric ** at this time. They are included as placeholders, to let 494147Seric ** you know that "someday" I intend to have sendmail do 504147Seric ** something with them. 512897Seric */ 522897Seric 532897Seric struct hdrinfo HdrInfo[] = 542897Seric { 558060Seric /* originator fields, most to least significant */ 5611417Seric "resent-sender", H_FROM|H_RESENT, 5711417Seric "resent-from", H_FROM|H_RESENT, 5825686Seric "resent-reply-to", H_FROM|H_RESENT, 599055Seric "sender", H_FROM, 609055Seric "from", H_FROM, 6125686Seric "reply-to", H_FROM, 629055Seric "full-name", H_ACHECK, 6357359Seric "return-receipt-to", H_FROM /* |H_RECEIPTTO */, 6457359Seric "errors-to", H_FROM|H_ERRORSTO, 658060Seric /* destination fields */ 669055Seric "to", H_RCPT, 6711417Seric "resent-to", H_RCPT|H_RESENT, 689055Seric "cc", H_RCPT, 6911417Seric "resent-cc", H_RCPT|H_RESENT, 709055Seric "bcc", H_RCPT|H_ACHECK, 7111417Seric "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, 7256215Seric "apparently-to", H_RCPT, 738060Seric /* message identification and control */ 7411417Seric "message-id", 0, 7511417Seric "resent-message-id", H_RESENT, 769055Seric "message", H_EOH, 779055Seric "text", H_EOH, 7811417Seric /* date fields */ 7911417Seric "date", 0, 8011417Seric "resent-date", H_RESENT, 818060Seric /* trace fields */ 829055Seric "received", H_TRACE|H_FORCE, 839055Seric "via", H_TRACE|H_FORCE, 849055Seric "mail-from", H_TRACE|H_FORCE, 858060Seric 869055Seric NULL, 0, 872897Seric }; 884166Seric 894166Seric 904166Seric /* 914166Seric ** ARPANET error message numbers. 924166Seric */ 934166Seric 947956Seric char Arpa_Info[] = "050"; /* arbitrary info */ 957956Seric char Arpa_TSyserr[] = "451"; /* some (transient) system error */ 967956Seric char Arpa_PSyserr[] = "554"; /* some (permanent) system error */ 9757977Seric char Arpa_Usrerr[] = "501"; /* some (fatal) user error */ 984282Seric 994282Seric 1004282Seric 1014282Seric /* 1024282Seric ** Location of system files/databases/etc. 1034282Seric */ 1044282Seric 10540980Sbostic char *ConfFile = _PATH_SENDMAILCF; /* runtime configuration */ 10640980Sbostic char *FreezeFile = _PATH_SENDMAILFC; /* frozen version of above */ 10758082Seric char *PidFile = _PATH_SENDMAILPID; /* stores daemon proc id */ 1089039Seric 1099064Seric 1109064Seric 1119039Seric /* 11258082Seric ** Privacy values 11358082Seric */ 11458082Seric 11558082Seric struct prival PrivacyValues[] = 11658082Seric { 11758082Seric "public", PRIV_PUBLIC, 11858082Seric "needmailhelo", PRIV_NEEDMAILHELO, 11958082Seric "needexpnnelo", PRIV_NEEDEXPNHELO, 12058082Seric "needvrfyhelo", PRIV_NEEDVRFYHELO, 12158082Seric "noexpn", PRIV_NOEXPN, 12258082Seric "novrfy", PRIV_NOVRFY, 12358082Seric "goaway", PRIV_GOAWAY, 12458082Seric NULL, PRIV_PUBLIC, 12558082Seric }; 12658082Seric 12758082Seric 12858082Seric 12958082Seric /* 13024943Seric ** Miscellaneous stuff. 1319039Seric */ 1329039Seric 13324943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 13424943Seric /* 13524943Seric ** SETDEFAULTS -- set default values 13624943Seric ** 13724943Seric ** Because of the way freezing is done, these must be initialized 13824943Seric ** using direct code. 13924943Seric ** 14024943Seric ** Parameters: 14124943Seric ** none. 14224943Seric ** 14324943Seric ** Returns: 14424943Seric ** none. 14524943Seric ** 14624943Seric ** Side Effects: 14724943Seric ** Initializes a bunch of global variables to their 14824943Seric ** default values. 14924943Seric */ 15024943Seric 15124943Seric setdefaults() 15224943Seric { 15357438Seric SpaceSub = ' '; /* option B */ 15457438Seric QueueLA = 8; /* option x */ 15557438Seric RefuseLA = 12; /* option X */ 15657438Seric WkRecipFact = 30000L; /* option y */ 15757438Seric WkClassFact = 1800L; /* option z */ 15857438Seric WkTimeFact = 90000L; /* option Z */ 15957438Seric QueueFactor = WkRecipFact * 20; /* option q */ 16057142Seric FileMode = (getuid() != geteuid()) ? 0644 : 0600; 16157438Seric /* option F */ 16257438Seric DefUid = 1; /* option u */ 16357438Seric DefGid = 1; /* option g */ 16457438Seric CheckpointInterval = 10; /* option C */ 16557438Seric MaxHopCount = 25; /* option h */ 16657438Seric SendMode = SM_FORK; /* option d */ 16757438Seric ErrorMode = EM_PRINT; /* option e */ 16857438Seric EightBit = FALSE; /* option 8 */ 16957438Seric MaxMciCache = 1; /* option k */ 17057438Seric MciCacheTimeout = 300; /* option K */ 17157438Seric LogLevel = 9; /* option L */ 172*58112Seric settimeouts(NULL); /* option r */ 173*58112Seric TimeOut = 5 * 24 * 60 * 60; /* option T */ 17440973Sbostic setdefuser(); 17553654Seric setupmaps(); 17657402Seric setupmailers(); 17724943Seric } 178294Seric 17940973Sbostic 1804326Seric /* 18140973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 18240973Sbostic */ 18340973Sbostic 18440973Sbostic setdefuser() 18540973Sbostic { 18640973Sbostic struct passwd *defpwent; 18757386Seric static char defuserbuf[40]; 18840973Sbostic 18957386Seric DefUser = defuserbuf; 19040973Sbostic if ((defpwent = getpwuid(DefUid)) != NULL) 19157386Seric strcpy(defuserbuf, defpwent->pw_name); 19240973Sbostic else 19357386Seric strcpy(defuserbuf, "nobody"); 19440973Sbostic } 19553654Seric /* 19653654Seric ** SETUPMAPS -- set up map classes 19753654Seric ** 19853654Seric ** Since these are compiled in, they cannot be in the config file. 19953654Seric ** 20053654Seric */ 20140973Sbostic 20253654Seric setupmaps() 20353654Seric { 20453654Seric register STAB *s; 20556836Seric extern bool host_map_init(); 20653654Seric extern char *maphostname(); 20740973Sbostic 20853654Seric /* set up host name lookup map */ 20953654Seric s = stab("host", ST_MAPCLASS, ST_ENTER); 21056836Seric s->s_mapclass.map_init = host_map_init; 21153654Seric s->s_mapclass.map_lookup = maphostname; 21253654Seric 21353654Seric /* 21453654Seric ** Set up other map classes. 21553654Seric */ 21653654Seric 21753654Seric # ifdef DBM_MAP 21853654Seric /* dbm file access */ 21953654Seric { 22056836Seric extern bool dbm_map_init(); 22153654Seric extern char *dbm_map_lookup(); 22253654Seric 22353654Seric s = stab("dbm", ST_MAPCLASS, ST_ENTER); 22453654Seric s->s_mapclass.map_init = dbm_map_init; 22553654Seric s->s_mapclass.map_lookup = dbm_map_lookup; 22653654Seric } 22753654Seric # endif 22853654Seric 22953654Seric # ifdef BTREE_MAP 23053654Seric /* new database file access -- btree files */ 23153654Seric { 23256823Seric extern bool bt_map_init(); 23356823Seric extern char *db_map_lookup(); 23453654Seric 23553654Seric s = stab("btree", ST_MAPCLASS, ST_ENTER); 23653654Seric s->s_mapclass.map_init = bt_map_init; 23756823Seric s->s_mapclass.map_lookup = db_map_lookup; 23853654Seric } 23953654Seric # endif 24053654Seric 24153654Seric # ifdef HASH_MAP 24253654Seric /* new database file access -- hash files */ 24353654Seric { 24456823Seric extern bool hash_map_init(); 24556823Seric extern char *db_map_lookup(); 24653654Seric 24753654Seric s = stab("hash", ST_MAPCLASS, ST_ENTER); 24853654Seric s->s_mapclass.map_init = hash_map_init; 24956823Seric s->s_mapclass.map_lookup = db_map_lookup; 25053654Seric } 25153654Seric # endif 25253654Seric 25357208Seric # ifdef NIS_MAP 25457208Seric /* NIS map access */ 25557208Seric { 25657208Seric extern bool nis_map_init(); 25757208Seric extern char *nis_map_lookup(); 25857208Seric 25957208Seric s = stab("nis", ST_MAPCLASS, ST_ENTER); 26057208Seric s->s_mapclass.map_init = nis_map_init; 26157208Seric s->s_mapclass.map_lookup = nis_map_lookup; 26257208Seric } 26357208Seric # endif 26457208Seric 26553654Seric # ifdef USERDB_MAP 26653654Seric /* user database */ 26753654Seric { 26856836Seric extern bool udb_map_init(); 26953654Seric extern char *udb_map_lookup(); 27053654Seric 27153654Seric s = stab("udb", ST_MAPCLASS, ST_ENTER); 27253654Seric s->s_mapclass.map_init = udb_map_init; 27353654Seric s->s_mapclass.map_lookup = udb_map_lookup; 27453654Seric } 27553654Seric # endif 27653654Seric } 27753654Seric /* 27856836Seric ** HOST_MAP_INIT -- initialize host class structures 27956836Seric */ 28056836Seric 28156836Seric bool 28256836Seric host_map_init(map, mapname, args) 28356836Seric MAP *map; 28456836Seric char *mapname; 28556836Seric char *args; 28656836Seric { 28756836Seric register char *p = args; 28856836Seric 28956836Seric for (;;) 29056836Seric { 29158050Seric while (isascii(*p) && isspace(*p)) 29256836Seric p++; 29356836Seric if (*p != '-') 29456836Seric break; 29556836Seric switch (*++p) 29656836Seric { 29756836Seric case 'a': 29856836Seric map->map_app = ++p; 29956836Seric break; 30056836Seric } 30158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 30256836Seric p++; 30356836Seric if (*p != '\0') 30456836Seric *p++ = '\0'; 30556836Seric } 30656836Seric if (map->map_app != NULL) 30756836Seric map->map_app = newstr(map->map_app); 30856836Seric return TRUE; 30956836Seric } 31057402Seric /* 31157402Seric ** SETUPMAILERS -- initialize default mailers 31257402Seric */ 31356836Seric 31457402Seric setupmailers() 31557402Seric { 31657402Seric char buf[100]; 31757402Seric 31857403Seric strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u"); 31957403Seric makemailer(buf); 32057403Seric 32157402Seric strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE"); 32257402Seric makemailer(buf); 32357402Seric 32457402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 32557402Seric makemailer(buf); 32657402Seric } 32756836Seric /* 3284326Seric ** GETRUID -- get real user id (V7) 3294326Seric */ 3304326Seric 3314326Seric getruid() 3324326Seric { 3339274Seric if (OpMode == MD_DAEMON) 3344536Seric return (RealUid); 3354536Seric else 3364536Seric return (getuid()); 3374326Seric } 3384326Seric 3394326Seric 3404326Seric /* 3414326Seric ** GETRGID -- get real group id (V7). 3424326Seric */ 3434326Seric 3444326Seric getrgid() 3454326Seric { 3469274Seric if (OpMode == MD_DAEMON) 3474536Seric return (RealGid); 3484536Seric else 3494536Seric return (getgid()); 3504326Seric } 35153654Seric /* 3529369Seric ** USERNAME -- return the user id of the logged in user. 3539369Seric ** 3549369Seric ** Parameters: 3559369Seric ** none. 3569369Seric ** 3579369Seric ** Returns: 3589369Seric ** The login name of the logged in user. 3599369Seric ** 3609369Seric ** Side Effects: 3619369Seric ** none. 3629369Seric ** 3639369Seric ** Notes: 3649369Seric ** The return value is statically allocated. 3659369Seric */ 3669369Seric 3679369Seric char * 3689369Seric username() 3699369Seric { 37017469Seric static char *myname = NULL; 3719369Seric extern char *getlogin(); 37219904Smiriam register struct passwd *pw; 3739369Seric 37417469Seric /* cache the result */ 37517469Seric if (myname == NULL) 37617469Seric { 37717469Seric myname = getlogin(); 37817469Seric if (myname == NULL || myname[0] == '\0') 37917469Seric { 38017469Seric 38117469Seric pw = getpwuid(getruid()); 38217469Seric if (pw != NULL) 38340993Sbostic myname = newstr(pw->pw_name); 38417469Seric } 38519904Smiriam else 38619904Smiriam { 38719873Smiriam 38840993Sbostic myname = newstr(myname); 38940993Sbostic if ((pw = getpwnam(myname)) == NULL || 39040993Sbostic getuid() != pw->pw_uid) 39119904Smiriam { 39219873Smiriam pw = getpwuid(getuid()); 39324945Seric if (pw != NULL) 39440993Sbostic myname = newstr(pw->pw_name); 39519873Smiriam } 39619873Smiriam } 39717469Seric if (myname == NULL || myname[0] == '\0') 39817469Seric { 39917469Seric syserr("Who are you?"); 40017469Seric myname = "postmaster"; 40117469Seric } 40217469Seric } 40317469Seric 40417469Seric return (myname); 4059369Seric } 4069369Seric /* 4074190Seric ** TTYPATH -- Get the path of the user's tty 408294Seric ** 409294Seric ** Returns the pathname of the user's tty. Returns NULL if 410294Seric ** the user is not logged in or if s/he has write permission 411294Seric ** denied. 412294Seric ** 413294Seric ** Parameters: 414294Seric ** none 415294Seric ** 416294Seric ** Returns: 417294Seric ** pathname of the user's tty. 418294Seric ** NULL if not logged in or write permission denied. 419294Seric ** 420294Seric ** Side Effects: 421294Seric ** none. 422294Seric ** 423294Seric ** WARNING: 424294Seric ** Return value is in a local buffer. 425294Seric ** 426294Seric ** Called By: 427294Seric ** savemail 428294Seric */ 429294Seric 430294Seric # include <sys/stat.h> 431294Seric 432294Seric char * 433294Seric ttypath() 434294Seric { 435294Seric struct stat stbuf; 436294Seric register char *pathn; 437294Seric extern char *ttyname(); 4384081Seric extern char *getlogin(); 439294Seric 440294Seric /* compute the pathname of the controlling tty */ 4419369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 4429369Seric (pathn = ttyname(0)) == NULL) 443294Seric { 444294Seric errno = 0; 445294Seric return (NULL); 446294Seric } 447294Seric 448294Seric /* see if we have write permission */ 4492967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 450294Seric { 451294Seric errno = 0; 452294Seric return (NULL); 453294Seric } 454294Seric 455294Seric /* see if the user is logged in */ 456294Seric if (getlogin() == NULL) 457294Seric return (NULL); 458294Seric 459294Seric /* looks good */ 460294Seric return (pathn); 461294Seric } 4622967Seric /* 4632967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4642967Seric ** 4652967Seric ** This routine can be supplied on a per-installation basis 4662967Seric ** to determine whether a person is allowed to send a message. 4672967Seric ** This allows restriction of certain types of internet 4682967Seric ** forwarding or registration of users. 4692967Seric ** 4702967Seric ** If the hosts are found to be incompatible, an error 47157454Seric ** message should be given using "usrerr" and 0 should 4722967Seric ** be returned. 4732967Seric ** 4744288Seric ** 'NoReturn' can be set to suppress the return-to-sender 4754288Seric ** function; this should be done on huge messages. 4764288Seric ** 4772967Seric ** Parameters: 4782967Seric ** to -- the person being sent to. 4792967Seric ** 4802967Seric ** Returns: 48157459Seric ** an exit status 4822967Seric ** 4832967Seric ** Side Effects: 4842967Seric ** none (unless you include the usrerr stuff) 4852967Seric */ 4862967Seric 48755012Seric checkcompat(to, e) 4882967Seric register ADDRESS *to; 48955012Seric register ENVELOPE *e; 4902967Seric { 49112133Seric # ifdef lint 49212133Seric if (to == NULL) 49312133Seric to++; 49412133Seric # endif lint 49510698Seric # ifdef EXAMPLE_CODE 49610698Seric /* this code is intended as an example only */ 4974437Seric register STAB *s; 4984437Seric 4994437Seric s = stab("arpa", ST_MAILER, ST_FIND); 50055012Seric if (s != NULL && e->e_from.q_mailer != LocalMailer && 5019369Seric to->q_mailer == s->s_mailer) 5024437Seric { 5034437Seric usrerr("No ARPA mail through this machine: see your system administration"); 50410698Seric /* NoReturn = TRUE; to supress return copy */ 50557459Seric return (EX_UNAVAILABLE); 5064437Seric } 50756795Seric # endif /* EXAMPLE_CODE */ 50857459Seric return (EX_OK); 5092967Seric } 5109369Seric /* 5119369Seric ** HOLDSIGS -- arrange to hold all signals 5129369Seric ** 5139369Seric ** Parameters: 5149369Seric ** none. 5159369Seric ** 5169369Seric ** Returns: 5179369Seric ** none. 5189369Seric ** 5199369Seric ** Side Effects: 5209369Seric ** Arranges that signals are held. 5219369Seric */ 5229369Seric 5239369Seric holdsigs() 5249369Seric { 5259369Seric } 5269369Seric /* 5279369Seric ** RLSESIGS -- arrange to release all signals 5289369Seric ** 5299369Seric ** This undoes the effect of holdsigs. 5309369Seric ** 5319369Seric ** Parameters: 5329369Seric ** none. 5339369Seric ** 5349369Seric ** Returns: 5359369Seric ** none. 5369369Seric ** 5379369Seric ** Side Effects: 5389369Seric ** Arranges that signals are released. 5399369Seric */ 5409369Seric 5419369Seric rlsesigs() 5429369Seric { 5439369Seric } 54414872Seric /* 54514872Seric ** GETLA -- get the current load average 54614872Seric ** 54714881Seric ** This code stolen from la.c. 54814881Seric ** 54914872Seric ** Parameters: 55014872Seric ** none. 55114872Seric ** 55214872Seric ** Returns: 55314872Seric ** The current load average as an integer. 55414872Seric ** 55514872Seric ** Side Effects: 55614872Seric ** none. 55714872Seric */ 55814872Seric 55951920Seric /* try to guess what style of load average we have */ 56051920Seric #define LA_ZERO 1 /* always return load average as zero */ 56151920Seric #define LA_INT 2 /* read kmem for avenrun; interpret as int */ 56251920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 56351920Seric #define LA_SUBR 4 /* call getloadavg */ 56414872Seric 56551920Seric #ifndef LA_TYPE 56651920Seric # if defined(sun) 56751920Seric # define LA_TYPE LA_INT 56851920Seric # endif 56957977Seric # if defined(mips) || defined(__alpha) 57057977Seric /* Ultrix or OSF/1 or RISC/os */ 57151920Seric # define LA_TYPE LA_INT 57251920Seric # define LA_AVENRUN "avenrun" 57351920Seric # endif 57451920Seric # if defined(hpux) 57551920Seric # define LA_TYPE LA_FLOAT 57651920Seric # endif 57751920Seric 57851920Seric # ifndef LA_TYPE 57957736Seric # if defined(SYSTEM5) 58057736Seric # define LA_TYPE LA_INT 58157736Seric # define LA_AVENRUN "avenrun" 58257736Seric # else 58357736Seric # if defined(BSD) 58457736Seric # define LA_TYPE LA_SUBR 58557736Seric # else 58657736Seric # define LA_TYPE LA_ZERO 58757736Seric # endif 58857736Seric # endif 58951920Seric # endif 59051920Seric #endif 59151920Seric 59251920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) 59351920Seric 59414872Seric #include <nlist.h> 59551920Seric #include <fcntl.h> 59614872Seric 59751920Seric #ifndef LA_AVENRUN 59851920Seric #define LA_AVENRUN "_avenrun" 59951920Seric #endif 60051920Seric 60151920Seric /* _PATH_UNIX should be defined in <paths.h> */ 60251920Seric #ifndef _PATH_UNIX 60351920Seric # if defined(hpux) 60451920Seric # define _PATH_UNIX "/hp-ux" 60551920Seric # endif 60651920Seric # if defined(mips) && !defined(ultrix) 60751920Seric /* powerful RISC/os */ 60851920Seric # define _PATH_UNIX "/unix" 60951920Seric # endif 61057736Seric # if defined(SYSTEM5) 61157977Seric # ifndef _PATH_UNIX 61257977Seric # define _PATH_UNIX "/unix" 61357977Seric # endif 61457736Seric # endif 61551920Seric # ifndef _PATH_UNIX 61651920Seric # define _PATH_UNIX "/vmunix" 61751920Seric # endif 61851920Seric #endif 61951920Seric 62014872Seric struct nlist Nl[] = 62114872Seric { 62251920Seric { LA_AVENRUN }, 62314872Seric #define X_AVENRUN 0 62414872Seric { 0 }, 62514872Seric }; 62614872Seric 62757736Seric #if defined(unixpc) 62857736Seric # define FSHIFT 5 62957736Seric #endif 63057736Seric 63157977Seric #if defined(__alpha) 63257977Seric # define FSHIFT 10 63357977Seric #endif 63457977Seric 63551920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT) 63651920Seric # define FSHIFT 8 63757736Seric #endif 63857736Seric #if (LA_TYPE == LA_INT) && !defined(FSCALE) 63951920Seric # define FSCALE (1 << FSHIFT) 64051920Seric #endif 64140930Srick 64214872Seric getla() 64314872Seric { 64414872Seric static int kmem = -1; 64551920Seric #if LA_TYPE == LA_INT 64624943Seric long avenrun[3]; 64751920Seric #else 64851920Seric double avenrun[3]; 64951920Seric #endif 65025615Seric extern off_t lseek(); 65157736Seric extern char *errstring(); 65257736Seric extern int errno; 65314872Seric 65414872Seric if (kmem < 0) 65514872Seric { 65624945Seric kmem = open("/dev/kmem", 0, 0); 65714872Seric if (kmem < 0) 65857736Seric { 65957736Seric if (tTd(3, 1)) 66057736Seric printf("getla: open(/dev/kmem): %s\n", 66157736Seric errstring(errno)); 66214872Seric return (-1); 66357736Seric } 66451920Seric (void) fcntl(kmem, F_SETFD, 1); 66557736Seric if (nlist(_PATH_UNIX, Nl) < 0) 66657736Seric { 66757736Seric if (tTd(3, 1)) 66857736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 66957736Seric errstring(errno)); 67014872Seric return (-1); 67157736Seric } 67214872Seric } 67357736Seric if (tTd(3, 20)) 67457736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 67524945Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 || 67623118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 67719967Seric { 67819967Seric /* thank you Ian */ 67957736Seric if (tTd(3, 1)) 68057736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 68119967Seric return (-1); 68219967Seric } 68351920Seric #if LA_TYPE == LA_INT 68457736Seric if (tTd(3, 5)) 68557736Seric { 68657736Seric printf("getla: avenrun = %d", avenrun[0]); 68757736Seric if (tTd(3, 15)) 68857736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 68957736Seric printf("\n"); 69057736Seric } 69157736Seric if (tTd(3, 1)) 69257736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 69324943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 69451920Seric #else 69557736Seric if (tTd(3, 5)) 69657736Seric { 69757736Seric printf("getla: avenrun = %g", avenrun[0]); 69857736Seric if (tTd(3, 15)) 69957736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 70057736Seric printf("\n"); 70157736Seric } 70257736Seric if (tTd(3, 1)) 70357736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 70451920Seric return ((int) (avenrun[0] + 0.5)); 70551920Seric #endif 70614872Seric } 70714872Seric 70851773Seric #else 70951920Seric #if LA_TYPE == LA_SUBR 71051773Seric 71151773Seric getla() 71251773Seric { 71351920Seric double avenrun[3]; 71451920Seric 71551920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 71657736Seric { 71757736Seric if (tTd(3, 1)) 71857736Seric perror("getla: getloadavg failed:"); 71951920Seric return (-1); 72057736Seric } 72157736Seric if (tTd(3, 1)) 72257736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 72351920Seric return ((int) (avenrun[0] + 0.5)); 72451773Seric } 72551773Seric 72651773Seric #else 72751773Seric 72851773Seric getla() 72951773Seric { 73057736Seric if (tTd(3, 1)) 73157736Seric printf("getla: ZERO\n"); 73251920Seric return (0); 73351773Seric } 73451773Seric 73551773Seric #endif 73651773Seric #endif 73724943Seric /* 73824943Seric ** SHOULDQUEUE -- should this message be queued or sent? 73924943Seric ** 74024943Seric ** Compares the message cost to the load average to decide. 74124943Seric ** 74224943Seric ** Parameters: 74324943Seric ** pri -- the priority of the message in question. 74457438Seric ** ctime -- the message creation time. 74524943Seric ** 74624943Seric ** Returns: 74724943Seric ** TRUE -- if this message should be queued up for the 74824943Seric ** time being. 74924943Seric ** FALSE -- if the load is low enough to send this message. 75024943Seric ** 75124943Seric ** Side Effects: 75224943Seric ** none. 75324943Seric */ 75424943Seric 75524943Seric bool 75657438Seric shouldqueue(pri, ctime) 75724943Seric long pri; 75857438Seric time_t ctime; 75924943Seric { 76051920Seric if (CurrentLA < QueueLA) 76124943Seric return (FALSE); 76251920Seric return (pri > (QueueFactor / (CurrentLA - QueueLA + 1))); 76324943Seric } 76424943Seric /* 76553037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 76653037Seric ** 76753037Seric ** Parameters: 76853037Seric ** none. 76953037Seric ** 77053037Seric ** Returns: 77153037Seric ** TRUE if incoming SMTP connections should be refused 77253037Seric ** (for now). 77353037Seric ** FALSE if we should accept new work. 77453037Seric ** 77553037Seric ** Side Effects: 77653037Seric ** none. 77753037Seric */ 77853037Seric 77953037Seric bool 78053037Seric refuseconnections() 78153037Seric { 78253037Seric /* this is probably too simplistic */ 78353037Seric return (CurrentLA > RefuseLA); 78453037Seric } 78553037Seric /* 78624943Seric ** SETPROCTITLE -- set process title for ps 78724943Seric ** 78824943Seric ** Parameters: 78924943Seric ** fmt -- a printf style format string. 79024943Seric ** a, b, c -- possible parameters to fmt. 79124943Seric ** 79224943Seric ** Returns: 79324943Seric ** none. 79424943Seric ** 79524943Seric ** Side Effects: 79624943Seric ** Clobbers argv of our main procedure so ps(1) will 79724943Seric ** display the title. 79824943Seric */ 79924943Seric 80024943Seric /*VARARGS1*/ 80157642Seric #ifdef __STDC__ 80257642Seric setproctitle(char *fmt, ...) 80357642Seric #else 80457642Seric setproctitle(fmt, va_alist) 80524943Seric char *fmt; 80657642Seric va_dcl 80757642Seric #endif 80824943Seric { 80924943Seric # ifdef SETPROCTITLE 81024943Seric register char *p; 81125049Seric register int i; 81256852Seric char buf[MAXLINE]; 81356852Seric VA_LOCAL_DECL 81424943Seric extern char **Argv; 81524943Seric extern char *LastArgv; 81624943Seric 81754996Seric p = buf; 81824943Seric 81954996Seric /* print sendmail: heading for grep */ 82054996Seric (void) strcpy(p, "sendmail: "); 82154996Seric p += strlen(p); 82224943Seric 82354996Seric /* print the argument string */ 82456852Seric VA_START(fmt); 82556852Seric (void) vsprintf(p, fmt, ap); 82656852Seric VA_END; 82754996Seric 82825049Seric i = strlen(buf); 82954996Seric if (i > LastArgv - Argv[0] - 2) 83025049Seric { 83154996Seric i = LastArgv - Argv[0] - 2; 83225049Seric buf[i] = '\0'; 83325049Seric } 83454996Seric (void) strcpy(Argv[0], buf); 83554997Seric p = &Argv[0][i]; 83624943Seric while (p < LastArgv) 83724943Seric *p++ = ' '; 83856795Seric # endif /* SETPROCTITLE */ 83924943Seric } 84025698Seric /* 84125698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 84225698Seric ** 84325698Seric ** Parameters: 84425698Seric ** none. 84525698Seric ** 84625698Seric ** Returns: 84725698Seric ** none. 84825698Seric ** 84925698Seric ** Side Effects: 85025698Seric ** Picks up extant zombies. 85125698Seric */ 85225698Seric 85325698Seric # include <sys/wait.h> 85425698Seric 85546928Sbostic void 85625698Seric reapchild() 85725698Seric { 85825698Seric # ifdef WNOHANG 85925698Seric union wait status; 86025698Seric 86146928Sbostic while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0) 86225698Seric continue; 86356795Seric # else /* WNOHANG */ 86425698Seric auto int status; 86525698Seric 86646928Sbostic while (wait((int *)&status) > 0) 86725698Seric continue; 86856795Seric # endif /* WNOHANG */ 86958061Seric # ifdef SYSTEM5 87058061Seric (void) signal(SIGCHLD, reapchild); 87158061Seric # endif 87225698Seric } 87355418Seric /* 87455418Seric ** UNSETENV -- remove a variable from the environment 87555418Seric ** 87655418Seric ** Not needed on newer systems. 87755418Seric ** 87855418Seric ** Parameters: 87955418Seric ** name -- the string name of the environment variable to be 88055418Seric ** deleted from the current environment. 88155418Seric ** 88255418Seric ** Returns: 88355418Seric ** none. 88455418Seric ** 88555418Seric ** Globals: 88655418Seric ** environ -- a pointer to the current environment. 88755418Seric ** 88855418Seric ** Side Effects: 88955418Seric ** Modifies environ. 89055418Seric */ 89155418Seric 89255418Seric #ifdef UNSETENV 89355418Seric 89455418Seric void 89555418Seric unsetenv(name) 89655418Seric char *name; 89755418Seric { 89855418Seric extern char **environ; 89955418Seric register char **pp; 90055418Seric int len = strlen(name); 90155418Seric 90255418Seric for (pp = environ; *pp != NULL; pp++) 90355418Seric { 90455418Seric if (strncmp(name, *pp, len) == 0 && 90555418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 90655418Seric break; 90755418Seric } 90855418Seric 90955418Seric for (; *pp != NULL; pp++) 91055418Seric *pp = pp[1]; 91155418Seric } 91255418Seric 91355418Seric #endif /* UNSETENV */ 91456215Seric /* 91556215Seric ** GETDTABLESIZE -- return number of file descriptors 91656215Seric ** 91756215Seric ** Only on non-BSD systems 91856215Seric ** 91956215Seric ** Parameters: 92056215Seric ** none 92156215Seric ** 92256215Seric ** Returns: 92356215Seric ** size of file descriptor table 92456215Seric ** 92556215Seric ** Side Effects: 92656215Seric ** none 92756215Seric */ 92856215Seric 92956215Seric #ifdef SYSTEM5 93056215Seric 93156215Seric int 93256215Seric getdtablesize() 93356215Seric { 93456215Seric return NOFILE; 93556215Seric } 93656215Seric 93756215Seric #endif 93857631Seric /* 93957631Seric ** UNAME -- get the UUCP name of this system. 94057631Seric */ 94157631Seric 94257943Seric #ifndef HASUNAME 94357631Seric 94457631Seric int 94557631Seric uname(name) 94657631Seric struct utsname *name; 94757631Seric { 94857631Seric FILE *file; 94957631Seric char *n; 95057631Seric 95157631Seric name->nodename[0] = '\0'; 95257631Seric 95357661Seric /* try /etc/whoami -- one line with the node name */ 95457631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 95557631Seric { 95657661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 95757631Seric (void) fclose(file); 95857661Seric n = strchr(name->nodename, '\n'); 95957631Seric if (n != NULL) 96057631Seric *n = '\0'; 96157631Seric if (name->nodename[0] != '\0') 96257631Seric return (0); 96357631Seric } 96457631Seric 96557661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 96657631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 96757631Seric { 96857631Seric char buf[MAXLINE]; 96957631Seric 97057631Seric while (fgets(buf, MAXLINE, file) != NULL) 97157631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 97257631Seric NODE_LENGTH, name->nodename) > 0) 97357631Seric break; 97457631Seric (void) fclose(file); 97557631Seric if (name->nodename[0] != '\0') 97657631Seric return (0); 97757631Seric } 97857631Seric 97957631Seric #ifdef TRUST_POPEN 98057631Seric /* 98157631Seric ** Popen is known to have security holes. 98257631Seric */ 98357631Seric 98457661Seric /* try uuname -l to return local name */ 98557631Seric if ((file = popen("uuname -l", "r")) != NULL) 98657631Seric { 98757661Seric (void) fgets(name, NODE_LENGTH + 1, file); 98857631Seric (void) pclose(file); 98957661Seric n = strchr(name, '\n'); 99057631Seric if (n != NULL) 99157631Seric *n = '\0'; 99257661Seric if (name->nodename[0] != '\0') 99357631Seric return (0); 99457631Seric } 99557631Seric #endif 99657631Seric 99757631Seric return (-1); 99857631Seric } 99957943Seric #endif /* HASUNAME */ 100058068Seric /* 100158068Seric ** INITGROUPS -- initialize groups 100258068Seric ** 100358068Seric ** Stub implementation for System V style systems 100458068Seric */ 100558068Seric 100658068Seric #ifndef HASINITGROUPS 100758068Seric # if !defined(SYSTEM5) || defined(hpux) 100858068Seric # define HASINITGROUPS 100958068Seric # endif 101058068Seric #endif 101158068Seric 101258068Seric #ifndef HASINITGROUPS 101358068Seric 101458068Seric initgroups(name, basegid) 101558068Seric char *name; 101658068Seric int basegid; 101758068Seric { 101858068Seric return 0; 101958068Seric } 102058068Seric 102158068Seric #endif 102258082Seric /* 102358082Seric ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 102458082Seric ** 102558082Seric ** Only implemented if you have statfs. 102658082Seric ** 102758082Seric ** Parameters: 102858082Seric ** none. 102958082Seric ** 103058082Seric ** Returns: 103158082Seric ** TRUE if there is enough space. 103258082Seric ** FALSE otherwise. 103358082Seric */ 103458082Seric 103558082Seric #ifndef HASSTATFS 103658082Seric # if defined(BSD4_4) || defined(__osf__) 103758082Seric # define HASSTATFS 103858082Seric # endif 103958082Seric #endif 104058082Seric 104158082Seric #ifdef HASSTATFS 104258082Seric #include <sys/mount.h> 104358082Seric #endif 104458082Seric 104558082Seric bool 104658082Seric enoughspace() 104758082Seric { 104858082Seric #ifdef HASSTATFS 104958082Seric struct statfs fs; 105058082Seric extern int errno; 105158082Seric extern char *errstring(); 105258082Seric 105358082Seric if (MinBlocksFree > 0 && statfs(QueueDir, &fs) >= 0) 105458082Seric { 105558082Seric if (tTd(4, 80)) 105658082Seric printf("enoughspace: bfree=%ld, min=%ld\n", 105758082Seric fs.f_bfree, MinBlocksFree); 105858082Seric if (fs.f_bfree < MinBlocksFree) 105958090Seric { 106058090Seric #ifdef LOG 106158090Seric if (LogLevel > 0) 106258090Seric syslog(LOG_ALERT, "%s: low on space (have %ld, need %ld)", 106358090Seric QueueDir, fs.f_bfree, MinBlocksFree); 106458090Seric #endif 106558082Seric return FALSE; 106658090Seric } 106758082Seric } 106858082Seric else if (tTd(4, 80)) 106958082Seric printf("enoughspace: min=%ld: %s\n", 107058082Seric MinBlocksFree, errstring(errno)); 107158082Seric #endif 107258082Seric return TRUE; 107358082Seric } 1074