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*58736Seric static char sccsid[] = "@(#)conf.c 6.39 (Berkeley) 03/19/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, 11458249Seric "restrictmailq", PRIV_RESTRMAILQ, 11558082Seric "goaway", PRIV_GOAWAY, 11658082Seric NULL, PRIV_PUBLIC, 11758082Seric }; 11858082Seric 11958082Seric 12058082Seric 12158082Seric /* 12224943Seric ** Miscellaneous stuff. 1239039Seric */ 1249039Seric 12524943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 12624943Seric /* 12724943Seric ** SETDEFAULTS -- set default values 12824943Seric ** 12924943Seric ** Because of the way freezing is done, these must be initialized 13024943Seric ** using direct code. 13124943Seric ** 13224943Seric ** Parameters: 13358734Seric ** e -- the default envelope. 13424943Seric ** 13524943Seric ** Returns: 13624943Seric ** none. 13724943Seric ** 13824943Seric ** Side Effects: 13924943Seric ** Initializes a bunch of global variables to their 14024943Seric ** default values. 14124943Seric */ 14224943Seric 14358734Seric setdefaults(e) 14458734Seric register ENVELOPE *e; 14524943Seric { 14657438Seric SpaceSub = ' '; /* option B */ 14757438Seric QueueLA = 8; /* option x */ 14857438Seric RefuseLA = 12; /* option X */ 14957438Seric WkRecipFact = 30000L; /* option y */ 15057438Seric WkClassFact = 1800L; /* option z */ 15157438Seric WkTimeFact = 90000L; /* option Z */ 15257438Seric QueueFactor = WkRecipFact * 20; /* option q */ 15357142Seric FileMode = (getuid() != geteuid()) ? 0644 : 0600; 15457438Seric /* option F */ 15557438Seric DefUid = 1; /* option u */ 15657438Seric DefGid = 1; /* option g */ 15757438Seric CheckpointInterval = 10; /* option C */ 15857438Seric MaxHopCount = 25; /* option h */ 15958734Seric e->e_sendmode = SM_FORK; /* option d */ 16058734Seric e->e_errormode = EM_PRINT; /* option e */ 16157438Seric EightBit = FALSE; /* option 8 */ 16257438Seric MaxMciCache = 1; /* option k */ 16357438Seric MciCacheTimeout = 300; /* option K */ 16457438Seric LogLevel = 9; /* option L */ 16558112Seric settimeouts(NULL); /* option r */ 16658112Seric TimeOut = 5 * 24 * 60 * 60; /* option T */ 16740973Sbostic setdefuser(); 16853654Seric setupmaps(); 16957402Seric setupmailers(); 17024943Seric } 171294Seric 17240973Sbostic 1734326Seric /* 17440973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 17540973Sbostic */ 17640973Sbostic 17740973Sbostic setdefuser() 17840973Sbostic { 17940973Sbostic struct passwd *defpwent; 18057386Seric static char defuserbuf[40]; 18140973Sbostic 18257386Seric DefUser = defuserbuf; 18340973Sbostic if ((defpwent = getpwuid(DefUid)) != NULL) 18457386Seric strcpy(defuserbuf, defpwent->pw_name); 18540973Sbostic else 18657386Seric strcpy(defuserbuf, "nobody"); 18740973Sbostic } 18853654Seric /* 18953654Seric ** SETUPMAPS -- set up map classes 19053654Seric ** 19153654Seric ** Since these are compiled in, they cannot be in the config file. 19253654Seric ** 19353654Seric */ 19440973Sbostic 19553654Seric setupmaps() 19653654Seric { 19753654Seric register STAB *s; 19856836Seric extern bool host_map_init(); 19953654Seric extern char *maphostname(); 20040973Sbostic 20153654Seric /* set up host name lookup map */ 20253654Seric s = stab("host", ST_MAPCLASS, ST_ENTER); 20356836Seric s->s_mapclass.map_init = host_map_init; 20453654Seric s->s_mapclass.map_lookup = maphostname; 20553654Seric 20653654Seric /* 20753654Seric ** Set up other map classes. 20853654Seric */ 20953654Seric 21053654Seric # ifdef DBM_MAP 21153654Seric /* dbm file access */ 21253654Seric { 21356836Seric extern bool dbm_map_init(); 21453654Seric extern char *dbm_map_lookup(); 21553654Seric 21653654Seric s = stab("dbm", ST_MAPCLASS, ST_ENTER); 21753654Seric s->s_mapclass.map_init = dbm_map_init; 21853654Seric s->s_mapclass.map_lookup = dbm_map_lookup; 21953654Seric } 22053654Seric # endif 22153654Seric 22253654Seric # ifdef BTREE_MAP 22353654Seric /* new database file access -- btree files */ 22453654Seric { 22556823Seric extern bool bt_map_init(); 22656823Seric extern char *db_map_lookup(); 22753654Seric 22853654Seric s = stab("btree", ST_MAPCLASS, ST_ENTER); 22953654Seric s->s_mapclass.map_init = bt_map_init; 23056823Seric s->s_mapclass.map_lookup = db_map_lookup; 23153654Seric } 23253654Seric # endif 23353654Seric 23453654Seric # ifdef HASH_MAP 23553654Seric /* new database file access -- hash files */ 23653654Seric { 23756823Seric extern bool hash_map_init(); 23856823Seric extern char *db_map_lookup(); 23953654Seric 24053654Seric s = stab("hash", ST_MAPCLASS, ST_ENTER); 24153654Seric s->s_mapclass.map_init = hash_map_init; 24256823Seric s->s_mapclass.map_lookup = db_map_lookup; 24353654Seric } 24453654Seric # endif 24553654Seric 24657208Seric # ifdef NIS_MAP 24757208Seric /* NIS map access */ 24857208Seric { 24957208Seric extern bool nis_map_init(); 25057208Seric extern char *nis_map_lookup(); 25157208Seric 25257208Seric s = stab("nis", ST_MAPCLASS, ST_ENTER); 25357208Seric s->s_mapclass.map_init = nis_map_init; 25457208Seric s->s_mapclass.map_lookup = nis_map_lookup; 25557208Seric } 25657208Seric # endif 25757208Seric 25853654Seric # ifdef USERDB_MAP 25953654Seric /* user database */ 26053654Seric { 26156836Seric extern bool udb_map_init(); 26253654Seric extern char *udb_map_lookup(); 26353654Seric 26453654Seric s = stab("udb", ST_MAPCLASS, ST_ENTER); 26553654Seric s->s_mapclass.map_init = udb_map_init; 26653654Seric s->s_mapclass.map_lookup = udb_map_lookup; 26753654Seric } 26853654Seric # endif 26953654Seric } 27053654Seric /* 27156836Seric ** HOST_MAP_INIT -- initialize host class structures 27256836Seric */ 27356836Seric 27456836Seric bool 27556836Seric host_map_init(map, mapname, args) 27656836Seric MAP *map; 27756836Seric char *mapname; 27856836Seric char *args; 27956836Seric { 28056836Seric register char *p = args; 28156836Seric 28256836Seric for (;;) 28356836Seric { 28458050Seric while (isascii(*p) && isspace(*p)) 28556836Seric p++; 28656836Seric if (*p != '-') 28756836Seric break; 28856836Seric switch (*++p) 28956836Seric { 29056836Seric case 'a': 29156836Seric map->map_app = ++p; 29256836Seric break; 29356836Seric } 29458050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 29556836Seric p++; 29656836Seric if (*p != '\0') 29756836Seric *p++ = '\0'; 29856836Seric } 29956836Seric if (map->map_app != NULL) 30056836Seric map->map_app = newstr(map->map_app); 30156836Seric return TRUE; 30256836Seric } 30357402Seric /* 30457402Seric ** SETUPMAILERS -- initialize default mailers 30557402Seric */ 30656836Seric 30757402Seric setupmailers() 30857402Seric { 30957402Seric char buf[100]; 31057402Seric 31157403Seric strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u"); 31257403Seric makemailer(buf); 31357403Seric 31457402Seric strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE"); 31557402Seric makemailer(buf); 31657402Seric 31757402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 31857402Seric makemailer(buf); 31957402Seric } 32056836Seric /* 3214326Seric ** GETRUID -- get real user id (V7) 3224326Seric */ 3234326Seric 3244326Seric getruid() 3254326Seric { 3269274Seric if (OpMode == MD_DAEMON) 3274536Seric return (RealUid); 3284536Seric else 3294536Seric return (getuid()); 3304326Seric } 3314326Seric 3324326Seric 3334326Seric /* 3344326Seric ** GETRGID -- get real group id (V7). 3354326Seric */ 3364326Seric 3374326Seric getrgid() 3384326Seric { 3399274Seric if (OpMode == MD_DAEMON) 3404536Seric return (RealGid); 3414536Seric else 3424536Seric return (getgid()); 3434326Seric } 34453654Seric /* 3459369Seric ** USERNAME -- return the user id of the logged in user. 3469369Seric ** 3479369Seric ** Parameters: 3489369Seric ** none. 3499369Seric ** 3509369Seric ** Returns: 3519369Seric ** The login name of the logged in user. 3529369Seric ** 3539369Seric ** Side Effects: 3549369Seric ** none. 3559369Seric ** 3569369Seric ** Notes: 3579369Seric ** The return value is statically allocated. 3589369Seric */ 3599369Seric 3609369Seric char * 3619369Seric username() 3629369Seric { 36317469Seric static char *myname = NULL; 3649369Seric extern char *getlogin(); 36519904Smiriam register struct passwd *pw; 3669369Seric 36717469Seric /* cache the result */ 36817469Seric if (myname == NULL) 36917469Seric { 37017469Seric myname = getlogin(); 37117469Seric if (myname == NULL || myname[0] == '\0') 37217469Seric { 37317469Seric pw = getpwuid(getruid()); 37417469Seric if (pw != NULL) 37540993Sbostic myname = newstr(pw->pw_name); 37617469Seric } 37719904Smiriam else 37819904Smiriam { 379*58736Seric uid_t uid = getuid(); 38019873Smiriam 38140993Sbostic myname = newstr(myname); 38240993Sbostic if ((pw = getpwnam(myname)) == NULL || 383*58736Seric (uid != 0 && uid != pw->pw_uid)) 38419904Smiriam { 385*58736Seric pw = getpwuid(uid); 38624945Seric if (pw != NULL) 38740993Sbostic myname = newstr(pw->pw_name); 38819873Smiriam } 38919873Smiriam } 39017469Seric if (myname == NULL || myname[0] == '\0') 39117469Seric { 39258151Seric syserr("554 Who are you?"); 39317469Seric myname = "postmaster"; 39417469Seric } 39517469Seric } 39617469Seric 39717469Seric return (myname); 3989369Seric } 3999369Seric /* 4004190Seric ** TTYPATH -- Get the path of the user's tty 401294Seric ** 402294Seric ** Returns the pathname of the user's tty. Returns NULL if 403294Seric ** the user is not logged in or if s/he has write permission 404294Seric ** denied. 405294Seric ** 406294Seric ** Parameters: 407294Seric ** none 408294Seric ** 409294Seric ** Returns: 410294Seric ** pathname of the user's tty. 411294Seric ** NULL if not logged in or write permission denied. 412294Seric ** 413294Seric ** Side Effects: 414294Seric ** none. 415294Seric ** 416294Seric ** WARNING: 417294Seric ** Return value is in a local buffer. 418294Seric ** 419294Seric ** Called By: 420294Seric ** savemail 421294Seric */ 422294Seric 423294Seric # include <sys/stat.h> 424294Seric 425294Seric char * 426294Seric ttypath() 427294Seric { 428294Seric struct stat stbuf; 429294Seric register char *pathn; 430294Seric extern char *ttyname(); 4314081Seric extern char *getlogin(); 432294Seric 433294Seric /* compute the pathname of the controlling tty */ 4349369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 4359369Seric (pathn = ttyname(0)) == NULL) 436294Seric { 437294Seric errno = 0; 438294Seric return (NULL); 439294Seric } 440294Seric 441294Seric /* see if we have write permission */ 4422967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 443294Seric { 444294Seric errno = 0; 445294Seric return (NULL); 446294Seric } 447294Seric 448294Seric /* see if the user is logged in */ 449294Seric if (getlogin() == NULL) 450294Seric return (NULL); 451294Seric 452294Seric /* looks good */ 453294Seric return (pathn); 454294Seric } 4552967Seric /* 4562967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4572967Seric ** 4582967Seric ** This routine can be supplied on a per-installation basis 4592967Seric ** to determine whether a person is allowed to send a message. 4602967Seric ** This allows restriction of certain types of internet 4612967Seric ** forwarding or registration of users. 4622967Seric ** 4632967Seric ** If the hosts are found to be incompatible, an error 46457454Seric ** message should be given using "usrerr" and 0 should 4652967Seric ** be returned. 4662967Seric ** 4674288Seric ** 'NoReturn' can be set to suppress the return-to-sender 4684288Seric ** function; this should be done on huge messages. 4694288Seric ** 4702967Seric ** Parameters: 4712967Seric ** to -- the person being sent to. 4722967Seric ** 4732967Seric ** Returns: 47457459Seric ** an exit status 4752967Seric ** 4762967Seric ** Side Effects: 4772967Seric ** none (unless you include the usrerr stuff) 4782967Seric */ 4792967Seric 48055012Seric checkcompat(to, e) 4812967Seric register ADDRESS *to; 48255012Seric register ENVELOPE *e; 4832967Seric { 48412133Seric # ifdef lint 48512133Seric if (to == NULL) 48612133Seric to++; 48712133Seric # endif lint 48810698Seric # ifdef EXAMPLE_CODE 48910698Seric /* this code is intended as an example only */ 4904437Seric register STAB *s; 4914437Seric 4924437Seric s = stab("arpa", ST_MAILER, ST_FIND); 49355012Seric if (s != NULL && e->e_from.q_mailer != LocalMailer && 4949369Seric to->q_mailer == s->s_mailer) 4954437Seric { 49658151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 49710698Seric /* NoReturn = TRUE; to supress return copy */ 49857459Seric return (EX_UNAVAILABLE); 4994437Seric } 50056795Seric # endif /* EXAMPLE_CODE */ 50157459Seric return (EX_OK); 5022967Seric } 5039369Seric /* 5049369Seric ** HOLDSIGS -- arrange to hold all signals 5059369Seric ** 5069369Seric ** Parameters: 5079369Seric ** none. 5089369Seric ** 5099369Seric ** Returns: 5109369Seric ** none. 5119369Seric ** 5129369Seric ** Side Effects: 5139369Seric ** Arranges that signals are held. 5149369Seric */ 5159369Seric 5169369Seric holdsigs() 5179369Seric { 5189369Seric } 5199369Seric /* 5209369Seric ** RLSESIGS -- arrange to release all signals 5219369Seric ** 5229369Seric ** This undoes the effect of holdsigs. 5239369Seric ** 5249369Seric ** Parameters: 5259369Seric ** none. 5269369Seric ** 5279369Seric ** Returns: 5289369Seric ** none. 5299369Seric ** 5309369Seric ** Side Effects: 5319369Seric ** Arranges that signals are released. 5329369Seric */ 5339369Seric 5349369Seric rlsesigs() 5359369Seric { 5369369Seric } 53714872Seric /* 53814872Seric ** GETLA -- get the current load average 53914872Seric ** 54014881Seric ** This code stolen from la.c. 54114881Seric ** 54214872Seric ** Parameters: 54314872Seric ** none. 54414872Seric ** 54514872Seric ** Returns: 54614872Seric ** The current load average as an integer. 54714872Seric ** 54814872Seric ** Side Effects: 54914872Seric ** none. 55014872Seric */ 55114872Seric 55251920Seric /* try to guess what style of load average we have */ 55351920Seric #define LA_ZERO 1 /* always return load average as zero */ 55451920Seric #define LA_INT 2 /* read kmem for avenrun; interpret as int */ 55551920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 55651920Seric #define LA_SUBR 4 /* call getloadavg */ 55714872Seric 55851920Seric #ifndef LA_TYPE 55951920Seric # if defined(sun) 56051920Seric # define LA_TYPE LA_INT 56151920Seric # endif 56257977Seric # if defined(mips) || defined(__alpha) 56357977Seric /* Ultrix or OSF/1 or RISC/os */ 56451920Seric # define LA_TYPE LA_INT 56551920Seric # define LA_AVENRUN "avenrun" 56651920Seric # endif 56751920Seric # if defined(hpux) 56851920Seric # define LA_TYPE LA_FLOAT 56951920Seric # endif 57051920Seric 57151920Seric # ifndef LA_TYPE 57257736Seric # if defined(SYSTEM5) 57357736Seric # define LA_TYPE LA_INT 57457736Seric # define LA_AVENRUN "avenrun" 57557736Seric # else 57657736Seric # if defined(BSD) 57757736Seric # define LA_TYPE LA_SUBR 57857736Seric # else 57957736Seric # define LA_TYPE LA_ZERO 58057736Seric # endif 58157736Seric # endif 58251920Seric # endif 58351920Seric #endif 58451920Seric 58551920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) 58651920Seric 58714872Seric #include <nlist.h> 58814872Seric 58951920Seric #ifndef LA_AVENRUN 59051920Seric #define LA_AVENRUN "_avenrun" 59151920Seric #endif 59251920Seric 59351920Seric /* _PATH_UNIX should be defined in <paths.h> */ 59451920Seric #ifndef _PATH_UNIX 59551920Seric # if defined(hpux) 59651920Seric # define _PATH_UNIX "/hp-ux" 59751920Seric # endif 59851920Seric # if defined(mips) && !defined(ultrix) 59951920Seric /* powerful RISC/os */ 60051920Seric # define _PATH_UNIX "/unix" 60151920Seric # endif 60257736Seric # if defined(SYSTEM5) 60357977Seric # ifndef _PATH_UNIX 60457977Seric # define _PATH_UNIX "/unix" 60557977Seric # endif 60657736Seric # endif 60751920Seric # ifndef _PATH_UNIX 60851920Seric # define _PATH_UNIX "/vmunix" 60951920Seric # endif 61051920Seric #endif 61151920Seric 61214872Seric struct nlist Nl[] = 61314872Seric { 61451920Seric { LA_AVENRUN }, 61514872Seric #define X_AVENRUN 0 61614872Seric { 0 }, 61714872Seric }; 61814872Seric 61957736Seric #if defined(unixpc) 62057736Seric # define FSHIFT 5 62157736Seric #endif 62257736Seric 62357977Seric #if defined(__alpha) 62457977Seric # define FSHIFT 10 62557977Seric #endif 62657977Seric 62751920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT) 62851920Seric # define FSHIFT 8 62957736Seric #endif 63057736Seric #if (LA_TYPE == LA_INT) && !defined(FSCALE) 63151920Seric # define FSCALE (1 << FSHIFT) 63251920Seric #endif 63340930Srick 63414872Seric getla() 63514872Seric { 63614872Seric static int kmem = -1; 63751920Seric #if LA_TYPE == LA_INT 63824943Seric long avenrun[3]; 63951920Seric #else 64051920Seric double avenrun[3]; 64151920Seric #endif 64225615Seric extern off_t lseek(); 64357736Seric extern char *errstring(); 64457736Seric extern int errno; 64514872Seric 64614872Seric if (kmem < 0) 64714872Seric { 64824945Seric kmem = open("/dev/kmem", 0, 0); 64914872Seric if (kmem < 0) 65057736Seric { 65157736Seric if (tTd(3, 1)) 65257736Seric printf("getla: open(/dev/kmem): %s\n", 65357736Seric errstring(errno)); 65414872Seric return (-1); 65557736Seric } 65651920Seric (void) fcntl(kmem, F_SETFD, 1); 65757736Seric if (nlist(_PATH_UNIX, Nl) < 0) 65857736Seric { 65957736Seric if (tTd(3, 1)) 66057736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 66157736Seric errstring(errno)); 66214872Seric return (-1); 66357736Seric } 66414872Seric } 66557736Seric if (tTd(3, 20)) 66657736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 66724945Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 || 66823118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 66919967Seric { 67019967Seric /* thank you Ian */ 67157736Seric if (tTd(3, 1)) 67257736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 67319967Seric return (-1); 67419967Seric } 67551920Seric #if LA_TYPE == LA_INT 67657736Seric if (tTd(3, 5)) 67757736Seric { 67857736Seric printf("getla: avenrun = %d", avenrun[0]); 67957736Seric if (tTd(3, 15)) 68057736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 68157736Seric printf("\n"); 68257736Seric } 68357736Seric if (tTd(3, 1)) 68457736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 68524943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 68651920Seric #else 68757736Seric if (tTd(3, 5)) 68857736Seric { 68957736Seric printf("getla: avenrun = %g", avenrun[0]); 69057736Seric if (tTd(3, 15)) 69157736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 69257736Seric printf("\n"); 69357736Seric } 69457736Seric if (tTd(3, 1)) 69557736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 69651920Seric return ((int) (avenrun[0] + 0.5)); 69751920Seric #endif 69814872Seric } 69914872Seric 70051773Seric #else 70151920Seric #if LA_TYPE == LA_SUBR 70251773Seric 70351773Seric getla() 70451773Seric { 70551920Seric double avenrun[3]; 70651920Seric 70751920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 70857736Seric { 70957736Seric if (tTd(3, 1)) 71057736Seric perror("getla: getloadavg failed:"); 71151920Seric return (-1); 71257736Seric } 71357736Seric if (tTd(3, 1)) 71457736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 71551920Seric return ((int) (avenrun[0] + 0.5)); 71651773Seric } 71751773Seric 71851773Seric #else 71951773Seric 72051773Seric getla() 72151773Seric { 72257736Seric if (tTd(3, 1)) 72357736Seric printf("getla: ZERO\n"); 72451920Seric return (0); 72551773Seric } 72651773Seric 72751773Seric #endif 72851773Seric #endif 72924943Seric /* 73024943Seric ** SHOULDQUEUE -- should this message be queued or sent? 73124943Seric ** 73224943Seric ** Compares the message cost to the load average to decide. 73324943Seric ** 73424943Seric ** Parameters: 73524943Seric ** pri -- the priority of the message in question. 73657438Seric ** ctime -- the message creation time. 73724943Seric ** 73824943Seric ** Returns: 73924943Seric ** TRUE -- if this message should be queued up for the 74024943Seric ** time being. 74124943Seric ** FALSE -- if the load is low enough to send this message. 74224943Seric ** 74324943Seric ** Side Effects: 74424943Seric ** none. 74524943Seric */ 74624943Seric 74724943Seric bool 74857438Seric shouldqueue(pri, ctime) 74924943Seric long pri; 75057438Seric time_t ctime; 75124943Seric { 75251920Seric if (CurrentLA < QueueLA) 75324943Seric return (FALSE); 75458132Seric if (CurrentLA >= RefuseLA) 75558132Seric return (TRUE); 75651920Seric return (pri > (QueueFactor / (CurrentLA - QueueLA + 1))); 75724943Seric } 75824943Seric /* 75953037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 76053037Seric ** 76153037Seric ** Parameters: 76253037Seric ** none. 76353037Seric ** 76453037Seric ** Returns: 76553037Seric ** TRUE if incoming SMTP connections should be refused 76653037Seric ** (for now). 76753037Seric ** FALSE if we should accept new work. 76853037Seric ** 76953037Seric ** Side Effects: 77053037Seric ** none. 77153037Seric */ 77253037Seric 77353037Seric bool 77453037Seric refuseconnections() 77553037Seric { 77653037Seric /* this is probably too simplistic */ 77758132Seric return (CurrentLA >= RefuseLA); 77853037Seric } 77953037Seric /* 78024943Seric ** SETPROCTITLE -- set process title for ps 78124943Seric ** 78224943Seric ** Parameters: 78358674Seric ** fmt -- a printf style format string. 78458674Seric ** a, b, c -- possible parameters to fmt. 78524943Seric ** 78624943Seric ** Returns: 78724943Seric ** none. 78824943Seric ** 78924943Seric ** Side Effects: 79024943Seric ** Clobbers argv of our main procedure so ps(1) will 79124943Seric ** display the title. 79224943Seric */ 79324943Seric 79458689Seric #ifdef SETPROCTITLE 79558689Seric # ifdef __hpux 79658689Seric # include <sys/pstat.h> 79758689Seric # endif 79858689Seric #endif 79958689Seric 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; 81258674Seric char buf[MAXLINE]; 81356852Seric VA_LOCAL_DECL 81458689Seric # ifdef __hpux 81558689Seric union pstun pst; 81658689Seric # endif 81724943Seric extern char **Argv; 81824943Seric extern char *LastArgv; 81924943Seric 82058674Seric p = buf; 82124943Seric 82258674Seric /* print sendmail: heading for grep */ 82358674Seric (void) strcpy(p, "sendmail: "); 82458674Seric p += strlen(p); 82524943Seric 82658674Seric /* print the argument string */ 82758674Seric VA_START(fmt); 82858674Seric (void) vsprintf(p, fmt, ap); 82956852Seric VA_END; 83054996Seric 83158674Seric i = strlen(buf); 83258689Seric 83358689Seric # ifdef __hpux 83458689Seric pst.pst_command = buf; 83558689Seric pstat(PSTAT_SETCMD, pst, i, 0, 0); 83658689Seric # else 83758689Seric 83854996Seric if (i > LastArgv - Argv[0] - 2) 83925049Seric { 84054996Seric i = LastArgv - Argv[0] - 2; 84158674Seric buf[i] = '\0'; 84225049Seric } 84358674Seric (void) strcpy(Argv[0], buf); 84454997Seric p = &Argv[0][i]; 84524943Seric while (p < LastArgv) 84624943Seric *p++ = ' '; 84758689Seric # endif 84856795Seric # endif /* SETPROCTITLE */ 84924943Seric } 85025698Seric /* 85125698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 85225698Seric ** 85325698Seric ** Parameters: 85425698Seric ** none. 85525698Seric ** 85625698Seric ** Returns: 85725698Seric ** none. 85825698Seric ** 85925698Seric ** Side Effects: 86025698Seric ** Picks up extant zombies. 86125698Seric */ 86225698Seric 86325698Seric # include <sys/wait.h> 86425698Seric 86546928Sbostic void 86625698Seric reapchild() 86725698Seric { 86825698Seric # ifdef WNOHANG 86925698Seric union wait status; 87025698Seric 87146928Sbostic while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0) 87225698Seric continue; 87356795Seric # else /* WNOHANG */ 87425698Seric auto int status; 87525698Seric 87646928Sbostic while (wait((int *)&status) > 0) 87725698Seric continue; 87856795Seric # endif /* WNOHANG */ 87958061Seric # ifdef SYSTEM5 88058061Seric (void) signal(SIGCHLD, reapchild); 88158061Seric # endif 88225698Seric } 88355418Seric /* 88455418Seric ** UNSETENV -- remove a variable from the environment 88555418Seric ** 88655418Seric ** Not needed on newer systems. 88755418Seric ** 88855418Seric ** Parameters: 88955418Seric ** name -- the string name of the environment variable to be 89055418Seric ** deleted from the current environment. 89155418Seric ** 89255418Seric ** Returns: 89355418Seric ** none. 89455418Seric ** 89555418Seric ** Globals: 89655418Seric ** environ -- a pointer to the current environment. 89755418Seric ** 89855418Seric ** Side Effects: 89955418Seric ** Modifies environ. 90055418Seric */ 90155418Seric 90255418Seric #ifdef UNSETENV 90355418Seric 90455418Seric void 90555418Seric unsetenv(name) 90655418Seric char *name; 90755418Seric { 90855418Seric extern char **environ; 90955418Seric register char **pp; 91055418Seric int len = strlen(name); 91155418Seric 91255418Seric for (pp = environ; *pp != NULL; pp++) 91355418Seric { 91455418Seric if (strncmp(name, *pp, len) == 0 && 91555418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 91655418Seric break; 91755418Seric } 91855418Seric 91955418Seric for (; *pp != NULL; pp++) 92055418Seric *pp = pp[1]; 92155418Seric } 92255418Seric 92355418Seric #endif /* UNSETENV */ 92456215Seric /* 92556215Seric ** GETDTABLESIZE -- return number of file descriptors 92656215Seric ** 92756215Seric ** Only on non-BSD systems 92856215Seric ** 92956215Seric ** Parameters: 93056215Seric ** none 93156215Seric ** 93256215Seric ** Returns: 93356215Seric ** size of file descriptor table 93456215Seric ** 93556215Seric ** Side Effects: 93656215Seric ** none 93756215Seric */ 93856215Seric 93956215Seric #ifdef SYSTEM5 94056215Seric 94156215Seric int 94256215Seric getdtablesize() 94356215Seric { 94458689Seric # ifdef _SC_OPEN_MAX 94558689Seric return sysconf(_SC_OPEN_MAX); 94658689Seric # else 94756215Seric return NOFILE; 94858689Seric # endif 94956215Seric } 95056215Seric 95156215Seric #endif 95257631Seric /* 95357631Seric ** UNAME -- get the UUCP name of this system. 95457631Seric */ 95557631Seric 95657943Seric #ifndef HASUNAME 95757631Seric 95857631Seric int 95957631Seric uname(name) 96057631Seric struct utsname *name; 96157631Seric { 96257631Seric FILE *file; 96357631Seric char *n; 96457631Seric 96557631Seric name->nodename[0] = '\0'; 96657631Seric 96757661Seric /* try /etc/whoami -- one line with the node name */ 96857631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 96957631Seric { 97057661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 97157631Seric (void) fclose(file); 97257661Seric n = strchr(name->nodename, '\n'); 97357631Seric if (n != NULL) 97457631Seric *n = '\0'; 97557631Seric if (name->nodename[0] != '\0') 97657631Seric return (0); 97757631Seric } 97857631Seric 97957661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 98057631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 98157631Seric { 98257631Seric char buf[MAXLINE]; 98357631Seric 98457631Seric while (fgets(buf, MAXLINE, file) != NULL) 98557631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 98657631Seric NODE_LENGTH, name->nodename) > 0) 98757631Seric break; 98857631Seric (void) fclose(file); 98957631Seric if (name->nodename[0] != '\0') 99057631Seric return (0); 99157631Seric } 99257631Seric 99357631Seric #ifdef TRUST_POPEN 99457631Seric /* 99557631Seric ** Popen is known to have security holes. 99657631Seric */ 99757631Seric 99857661Seric /* try uuname -l to return local name */ 99957631Seric if ((file = popen("uuname -l", "r")) != NULL) 100057631Seric { 100157661Seric (void) fgets(name, NODE_LENGTH + 1, file); 100257631Seric (void) pclose(file); 100357661Seric n = strchr(name, '\n'); 100457631Seric if (n != NULL) 100557631Seric *n = '\0'; 100657661Seric if (name->nodename[0] != '\0') 100757631Seric return (0); 100857631Seric } 100957631Seric #endif 101057631Seric 101157631Seric return (-1); 101257631Seric } 101357943Seric #endif /* HASUNAME */ 101458068Seric /* 101558068Seric ** INITGROUPS -- initialize groups 101658068Seric ** 101758068Seric ** Stub implementation for System V style systems 101858068Seric */ 101958068Seric 102058068Seric #ifndef HASINITGROUPS 102158068Seric # if !defined(SYSTEM5) || defined(hpux) 102258068Seric # define HASINITGROUPS 102358068Seric # endif 102458068Seric #endif 102558068Seric 102658068Seric #ifndef HASINITGROUPS 102758068Seric 102858068Seric initgroups(name, basegid) 102958068Seric char *name; 103058068Seric int basegid; 103158068Seric { 103258068Seric return 0; 103358068Seric } 103458068Seric 103558068Seric #endif 103658082Seric /* 103758082Seric ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 103858082Seric ** 103958082Seric ** Only implemented if you have statfs. 104058082Seric ** 104158082Seric ** Parameters: 104258333Seric ** msize -- the size to check against. If zero, we don't yet 104358333Seric ** know how big the message will be, so just check for 104458333Seric ** a "reasonable" amount. 104558082Seric ** 104658082Seric ** Returns: 104758082Seric ** TRUE if there is enough space. 104858082Seric ** FALSE otherwise. 104958082Seric */ 105058082Seric 105158082Seric #ifndef HASSTATFS 105258082Seric # if defined(BSD4_4) || defined(__osf__) 105358082Seric # define HASSTATFS 105458082Seric # endif 105558082Seric #endif 105658082Seric 105758082Seric #ifdef HASSTATFS 105858157Seric # undef HASUSTAT 105958157Seric #endif 106058157Seric 106158157Seric #if defined(HASUSTAT) 106258157Seric # include <sys/stat.h> 106358157Seric # include <ustat.h> 106458157Seric #endif 106558157Seric 106658157Seric #ifdef HASSTATFS 106758133Seric # if defined(sgi) || defined(apollo) 106858133Seric # include <sys/statfs.h> 106958133Seric # else 107058133Seric # if defined(sun) || defined(hpux) 107158133Seric # include <sys/vfs.h> 107258133Seric # else 107358157Seric # include <sys/mount.h> 107458133Seric # endif 107558133Seric # endif 107658082Seric #endif 107758082Seric 107858082Seric bool 107958333Seric enoughspace(msize) 108058333Seric long msize; 108158082Seric { 108258160Seric #if defined(HASSTATFS) || defined(HASUSTAT) 108358157Seric # if defined(HASUSTAT) 108458153Seric struct ustat fs; 108558153Seric struct stat statbuf; 108658366Seric # define FSBLOCKSIZE DEV_BSIZE 108758157Seric # define f_bavail f_tfree 108858157Seric # else 108958157Seric # if defined(ultrix) 109058157Seric struct fs_data fs; 109158157Seric # define f_bavail fd_bfreen 109258366Seric # define FSBLOCKSIZE fs.fd_bsize 109358153Seric # else 109458082Seric struct statfs fs; 109558366Seric # define FSBLOCKSIZE fs.f_bsize 109658153Seric # endif 109758133Seric # endif 109858333Seric long blocksneeded; 109958082Seric extern int errno; 110058082Seric extern char *errstring(); 110158082Seric 110258333Seric if (MinBlocksFree <= 0 && msize <= 0) 110358082Seric { 110458082Seric if (tTd(4, 80)) 110558133Seric printf("enoughspace: no threshold\n"); 110658133Seric return TRUE; 110758133Seric } 110858333Seric 110958157Seric # if defined(HASUSTAT) 111058157Seric if (stat(QueueDir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 111158157Seric # else 111258157Seric # if defined(sgi) || defined(apollo) 111358133Seric if (statfs(QueueDir, &fs, sizeof fs, 0) == 0) 111458157Seric # else 111558157Seric # if defined(ultrix) 111658133Seric if (statfs(QueueDir, &fs) > 0) 111758153Seric # else 111858133Seric if (statfs(QueueDir, &fs) == 0) 111958153Seric # endif 112058133Seric # endif 112158133Seric # endif 112258133Seric { 112358133Seric if (tTd(4, 80)) 112458333Seric printf("enoughspace: bavail=%ld, need=%ld\n", 112558333Seric fs.f_bavail, msize); 112658333Seric 112758333Seric /* convert msize to block count */ 112858366Seric msize = msize / FSBLOCKSIZE + 1; 112958333Seric if (MinBlocksFree >= 0) 113058333Seric msize += MinBlocksFree; 113158333Seric 113258333Seric if (fs.f_bavail < msize) 113358090Seric { 113458090Seric #ifdef LOG 113558090Seric if (LogLevel > 0) 113658090Seric syslog(LOG_ALERT, "%s: low on space (have %ld, need %ld)", 113758333Seric QueueDir, fs.f_bavail, msize); 113858090Seric #endif 113958082Seric return FALSE; 114058090Seric } 114158082Seric } 114258082Seric else if (tTd(4, 80)) 114358333Seric printf("enoughspace failure: min=%ld, need=%ld: %s\n", 114458333Seric MinBlocksFree, msize, errstring(errno)); 114558082Seric #endif 114658082Seric return TRUE; 114758082Seric } 114858542Seric /* 114958542Seric ** TRANSIENTERROR -- tell if an error code indicates a transient failure 115058542Seric ** 115158542Seric ** This looks at an errno value and tells if this is likely to 115258542Seric ** go away if retried later. 115358542Seric ** 115458542Seric ** Parameters: 115558542Seric ** err -- the errno code to classify. 115658542Seric ** 115758542Seric ** Returns: 115858542Seric ** TRUE if this is probably transient. 115958542Seric ** FALSE otherwise. 116058542Seric */ 116158542Seric 116258542Seric bool 116358542Seric transienterror(err) 116458542Seric int err; 116558542Seric { 116658542Seric switch (err) 116758542Seric { 116858542Seric case EIO: /* I/O error */ 116958542Seric case ENXIO: /* Device not configured */ 117058542Seric case EAGAIN: /* Resource temporarily unavailable */ 117158542Seric case ENOMEM: /* Cannot allocate memory */ 117258542Seric case ENODEV: /* Operation not supported by device */ 117358542Seric case ENFILE: /* Too many open files in system */ 117458542Seric case EMFILE: /* Too many open files */ 117558542Seric case ENOSPC: /* No space left on device */ 117658542Seric #ifdef ETIMEDOUT 117758542Seric case ETIMEDOUT: /* Connection timed out */ 117858542Seric #endif 117958542Seric #ifdef ESTALE 118058542Seric case ESTALE: /* Stale NFS file handle */ 118158542Seric #endif 118258542Seric #ifdef ENETDOWN 118358542Seric case ENETDOWN: /* Network is down */ 118458542Seric #endif 118558542Seric #ifdef ENETUNREACH 118658542Seric case ENETUNREACH: /* Network is unreachable */ 118758542Seric #endif 118858542Seric #ifdef ENETRESET 118958542Seric case ENETRESET: /* Network dropped connection on reset */ 119058542Seric #endif 119158542Seric #ifdef ECONNABORTED 119258542Seric case ECONNABORTED: /* Software caused connection abort */ 119358542Seric #endif 119458542Seric #ifdef ECONNRESET 119558542Seric case ECONNRESET: /* Connection reset by peer */ 119658542Seric #endif 119758542Seric #ifdef ENOBUFS 119858542Seric case ENOBUFS: /* No buffer space available */ 119958542Seric #endif 120058542Seric #ifdef ESHUTDOWN 120158542Seric case ESHUTDOWN: /* Can't send after socket shutdown */ 120258542Seric #endif 120358542Seric #ifdef ECONNREFUSED 120458542Seric case ECONNREFUSED: /* Connection refused */ 120558542Seric #endif 120658542Seric #ifdef EHOSTDOWN 120758542Seric case EHOSTDOWN: /* Host is down */ 120858542Seric #endif 120958542Seric #ifdef EHOSTUNREACH 121058542Seric case EHOSTUNREACH: /* No route to host */ 121158542Seric #endif 121258542Seric #ifdef EDQUOT 121358542Seric case EDQUOT: /* Disc quota exceeded */ 121458542Seric #endif 121558542Seric #ifdef EPROCLIM 121658542Seric case EPROCLIM: /* Too many processes */ 121758542Seric #endif 121858542Seric #ifdef EUSERS 121958542Seric case EUSERS: /* Too many users */ 122058542Seric #endif 122158542Seric #ifdef EDEADLK 122258542Seric case EDEADLK: /* Resource deadlock avoided */ 122358542Seric #endif 122458542Seric #ifdef EISCONN 122558542Seric case EISCONN: /* Socket already connected */ 122658542Seric #endif 122758542Seric #ifdef EINPROGRESS 122858542Seric case EINPROGRESS: /* Operation now in progress */ 122958542Seric #endif 123058542Seric #ifdef EALREADY 123158542Seric case EALREADY: /* Operation already in progress */ 123258542Seric #endif 123358542Seric #ifdef EADDRINUSE 123458542Seric case EADDRINUSE: /* Address already in use */ 123558542Seric #endif 123658542Seric #ifdef EADDRNOTAVAIL 123758542Seric case EADDRNOTAVAIL: /* Can't assign requested address */ 123858542Seric #endif 123958542Seric #ifdef ENOSR 124058542Seric case ENOSR: /* Out of streams resources */ 124158542Seric #endif 124258542Seric return TRUE; 124358542Seric } 124458542Seric 124558542Seric /* nope, must be permanent */ 124658542Seric return FALSE; 124758542Seric } 124858689Seric /* 124958689Seric ** LOCKFILE -- lock a file using flock or (shudder) lockf 125058689Seric ** 125158689Seric ** Parameters: 125258689Seric ** fd -- the file descriptor of the file. 125358689Seric ** filename -- the file name (for error messages). 125458689Seric ** type -- type of the lock. Bits can be: 125558689Seric ** LOCK_EX -- exclusive lock. 125658689Seric ** LOCK_NB -- non-blocking. 125758689Seric ** 125858689Seric ** Returns: 125958689Seric ** TRUE if the lock was acquired. 126058689Seric ** FALSE otherwise. 126158689Seric */ 126258689Seric 126358689Seric bool 126458689Seric lockfile(fd, filename, type) 126558689Seric int fd; 126658689Seric char *filename; 126758689Seric int type; 126858689Seric { 126958689Seric # ifdef LOCKF 127058689Seric int action; 127158689Seric struct flock lfd; 127258689Seric 127358701Seric if (bitset(LOCK_EX, type)) 127458689Seric lfd.l_type = F_WRLCK; 127558689Seric else 127658689Seric lfd.l_type = F_RDLCK; 127758689Seric 127858689Seric if (bitset(LOCK_NB, type)) 127958689Seric action = F_SETLK; 128058689Seric else 128158689Seric action = F_SETLKW; 128258689Seric 128358689Seric lfd.l_whence = lfd.l_start = lfd.l_len = 0; 128458689Seric 128558689Seric if (fcntl(fd, action, &lfd) >= 0) 128658689Seric return TRUE; 128758689Seric 128858689Seric if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 128958689Seric syserr("cannot lockf(%s)", filename); 129058689Seric # else 129158689Seric if (flock(fd, type) >= 0) 129258689Seric return TRUE; 129358689Seric 129458689Seric if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 129558689Seric syserr("cannot flock(%s)", filename); 129658689Seric # endif 129758689Seric return FALSE; 129858689Seric } 1299