122698Sdist /* 268839Seric * Copyright (c) 1983, 1995 Eric P. Allman 362522Sbostic * Copyright (c) 1988, 1993 462522Sbostic * The Regents of the University of California. All rights reserved. 533728Sbostic * 642825Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822698Sdist 922698Sdist #ifndef lint 10*69817Seric static char sccsid[] = "@(#)conf.c 8.189 (Berkeley) 06/10/95"; 1133728Sbostic #endif /* not lint */ 1222698Sdist 1363937Seric # include "sendmail.h" 1463937Seric # include "pathnames.h" 1514881Seric # include <sys/ioctl.h> 1658082Seric # include <sys/param.h> 17404Seric 18294Seric /* 193309Seric ** CONF.C -- Sendmail Configuration Tables. 20294Seric ** 21294Seric ** Defines the configuration of this installation. 22294Seric ** 231388Seric ** Configuration Variables: 242897Seric ** HdrInfo -- a table describing well-known header fields. 252897Seric ** Each entry has the field name and some flags, 264147Seric ** which are described in sendmail.h. 274093Seric ** 284093Seric ** Notes: 294093Seric ** I have tried to put almost all the reasonable 304093Seric ** configuration information into the configuration 314093Seric ** file read at runtime. My intent is that anything 324093Seric ** here is a function of the version of UNIX you 334093Seric ** are running, or is really static -- for example 344093Seric ** the headers are a superset of widely used 354093Seric ** protocols. If you find yourself playing with 364093Seric ** this file too much, you may be making a mistake! 37294Seric */ 38294Seric 39294Seric 40294Seric 41294Seric 424437Seric /* 432897Seric ** Header info table 443057Seric ** Final (null) entry contains the flags used for any other field. 454147Seric ** 464147Seric ** Not all of these are actually handled specially by sendmail 474147Seric ** at this time. They are included as placeholders, to let 484147Seric ** you know that "someday" I intend to have sendmail do 494147Seric ** something with them. 502897Seric */ 512897Seric 522897Seric struct hdrinfo HdrInfo[] = 532897Seric { 548060Seric /* originator fields, most to least significant */ 5568508Seric "resent-sender", H_FROM|H_RESENT, 5668508Seric "resent-from", H_FROM|H_RESENT, 5768508Seric "resent-reply-to", H_FROM|H_RESENT, 5868508Seric "sender", H_FROM, 5968508Seric "from", H_FROM, 6068508Seric "reply-to", H_FROM, 6168508Seric "full-name", H_ACHECK, 6268508Seric "return-receipt-to", H_FROM|H_RECEIPTTO, 6368508Seric "errors-to", H_FROM|H_ERRORSTO, 6458796Seric 658060Seric /* destination fields */ 6668508Seric "to", H_RCPT, 6768508Seric "resent-to", H_RCPT|H_RESENT, 6868508Seric "cc", H_RCPT, 6968508Seric "resent-cc", H_RCPT|H_RESENT, 7068508Seric "bcc", H_RCPT|H_STRIPVAL, 7168508Seric "resent-bcc", H_RCPT|H_STRIPVAL|H_RESENT, 7268508Seric "apparently-to", H_RCPT, 7358796Seric 748060Seric /* message identification and control */ 7568508Seric "message-id", 0, 7668508Seric "resent-message-id", H_RESENT, 7768508Seric "message", H_EOH, 7868508Seric "text", H_EOH, 7958796Seric 8011417Seric /* date fields */ 8168508Seric "date", 0, 8268508Seric "resent-date", H_RESENT, 8358796Seric 848060Seric /* trace fields */ 8568508Seric "received", H_TRACE|H_FORCE, 8668508Seric "x400-received", H_TRACE|H_FORCE, 8768508Seric "via", H_TRACE|H_FORCE, 8868508Seric "mail-from", H_TRACE|H_FORCE, 898060Seric 9058796Seric /* miscellaneous fields */ 9168508Seric "comments", H_FORCE, 9268508Seric "return-path", H_FORCE|H_ACHECK, 9368508Seric "content-transfer-encoding", H_CTE, 9468508Seric "content-type", H_CTYPE, 9568706Seric "content-length", H_ACHECK, 9658796Seric 979055Seric NULL, 0, 982897Seric }; 994166Seric 1004166Seric 1014166Seric 1024282Seric /* 1034282Seric ** Location of system files/databases/etc. 1044282Seric */ 1054282Seric 10658082Seric char *PidFile = _PATH_SENDMAILPID; /* stores daemon proc id */ 1079039Seric 1089064Seric 1099064Seric 1109039Seric /* 11158082Seric ** Privacy values 11258082Seric */ 11358082Seric 11458082Seric struct prival PrivacyValues[] = 11558082Seric { 11658082Seric "public", PRIV_PUBLIC, 11758082Seric "needmailhelo", PRIV_NEEDMAILHELO, 11858114Seric "needexpnhelo", PRIV_NEEDEXPNHELO, 11958082Seric "needvrfyhelo", PRIV_NEEDVRFYHELO, 12058082Seric "noexpn", PRIV_NOEXPN, 12158082Seric "novrfy", PRIV_NOVRFY, 12264333Seric "restrictmailq", PRIV_RESTRICTMAILQ, 12364333Seric "restrictqrun", PRIV_RESTRICTQRUN, 12458789Seric "authwarnings", PRIV_AUTHWARNINGS, 12566783Seric "noreceipts", PRIV_NORECEIPTS, 12658082Seric "goaway", PRIV_GOAWAY, 12758789Seric NULL, 0, 12858082Seric }; 12958082Seric 13058082Seric 13158082Seric 13258082Seric /* 13324943Seric ** Miscellaneous stuff. 1349039Seric */ 1359039Seric 13624943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 13724943Seric /* 13824943Seric ** SETDEFAULTS -- set default values 13924943Seric ** 14024943Seric ** Because of the way freezing is done, these must be initialized 14124943Seric ** using direct code. 14224943Seric ** 14324943Seric ** Parameters: 14458734Seric ** e -- the default envelope. 14524943Seric ** 14624943Seric ** Returns: 14724943Seric ** none. 14824943Seric ** 14924943Seric ** Side Effects: 15024943Seric ** Initializes a bunch of global variables to their 15124943Seric ** default values. 15224943Seric */ 15324943Seric 15458737Seric #define DAYS * 24 * 60 * 60 15558737Seric 15668508Seric void 15758734Seric setdefaults(e) 15858734Seric register ENVELOPE *e; 15924943Seric { 16068508Seric int i; 16168508Seric extern void inittimeouts(); 16268508Seric extern void setdefuser(); 16368508Seric extern void setupmaps(); 16468508Seric extern void setupmailers(); 16568508Seric 16657438Seric SpaceSub = ' '; /* option B */ 16757438Seric QueueLA = 8; /* option x */ 16857438Seric RefuseLA = 12; /* option X */ 16957438Seric WkRecipFact = 30000L; /* option y */ 17057438Seric WkClassFact = 1800L; /* option z */ 17157438Seric WkTimeFact = 90000L; /* option Z */ 17257438Seric QueueFactor = WkRecipFact * 20; /* option q */ 17363787Seric FileMode = (RealUid != geteuid()) ? 0644 : 0600; 17457438Seric /* option F */ 17557438Seric DefUid = 1; /* option u */ 17657438Seric DefGid = 1; /* option g */ 17757438Seric CheckpointInterval = 10; /* option C */ 17857438Seric MaxHopCount = 25; /* option h */ 17958734Seric e->e_sendmode = SM_FORK; /* option d */ 18058734Seric e->e_errormode = EM_PRINT; /* option e */ 18168508Seric SevenBitInput = FALSE; /* option 7 */ 18257438Seric MaxMciCache = 1; /* option k */ 18357438Seric MciCacheTimeout = 300; /* option K */ 18457438Seric LogLevel = 9; /* option L */ 18568508Seric inittimeouts(NULL); /* option r */ 18658853Seric PrivacyFlags = 0; /* option p */ 18769480Seric #if MIME8TO7 18868508Seric MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */ 18969480Seric #else 19069480Seric MimeMode = MM_PASS8BIT; 19169480Seric #endif 19268508Seric for (i = 0; i < MAXTOCLASS; i++) 19368508Seric { 19468508Seric TimeOuts.to_q_return[i] = 5 DAYS; /* option T */ 19568508Seric TimeOuts.to_q_warning[i] = 0; /* option T */ 19668508Seric } 19768508Seric ServiceSwitchFile = "/etc/service.switch"; 19869401Seric HostsFile = _PATH_HOSTS; 19940973Sbostic setdefuser(); 20053654Seric setupmaps(); 20157402Seric setupmailers(); 20224943Seric } 203294Seric 20440973Sbostic 2054326Seric /* 20640973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 20740973Sbostic */ 20840973Sbostic 20968508Seric void 21040973Sbostic setdefuser() 21140973Sbostic { 21240973Sbostic struct passwd *defpwent; 21357386Seric static char defuserbuf[40]; 21440973Sbostic 21557386Seric DefUser = defuserbuf; 21668693Seric if ((defpwent = sm_getpwuid(DefUid)) != NULL) 21757386Seric strcpy(defuserbuf, defpwent->pw_name); 21840973Sbostic else 21957386Seric strcpy(defuserbuf, "nobody"); 22040973Sbostic } 22153654Seric /* 22256836Seric ** HOST_MAP_INIT -- initialize host class structures 22356836Seric */ 22456836Seric 22568508Seric bool host_map_init __P((MAP *map, char *args)); 22668508Seric 22756836Seric bool 22860219Seric host_map_init(map, args) 22956836Seric MAP *map; 23056836Seric char *args; 23156836Seric { 23256836Seric register char *p = args; 23356836Seric 23456836Seric for (;;) 23556836Seric { 23658050Seric while (isascii(*p) && isspace(*p)) 23756836Seric p++; 23856836Seric if (*p != '-') 23956836Seric break; 24056836Seric switch (*++p) 24156836Seric { 24256836Seric case 'a': 24356836Seric map->map_app = ++p; 24456836Seric break; 24556836Seric } 24658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 24756836Seric p++; 24856836Seric if (*p != '\0') 24956836Seric *p++ = '\0'; 25056836Seric } 25156836Seric if (map->map_app != NULL) 25256836Seric map->map_app = newstr(map->map_app); 25356836Seric return TRUE; 25456836Seric } 25557402Seric /* 25657402Seric ** SETUPMAILERS -- initialize default mailers 25757402Seric */ 25856836Seric 25968508Seric void 26057402Seric setupmailers() 26157402Seric { 26257402Seric char buf[100]; 26368508Seric extern void makemailer(); 26457402Seric 26569793Seric strcpy(buf, "prog, P=/bin/sh, F=lsoD, T=DNS/RFC822/X-Unix, A=sh -c \201u"); 26657403Seric makemailer(buf); 26757403Seric 26869721Seric strcpy(buf, "*file*, P=[FILE], F=lsDFMPEou, T=DNS/RFC822/X-Unix, A=FILE"); 26957402Seric makemailer(buf); 27057402Seric 27157402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 27257402Seric makemailer(buf); 27357402Seric } 27456836Seric /* 27560207Seric ** SETUPMAPS -- set up map classes 27660207Seric */ 27760207Seric 27860207Seric #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \ 27960207Seric { \ 28060207Seric extern bool parse __P((MAP *, char *)); \ 28160207Seric extern bool open __P((MAP *, int)); \ 28260207Seric extern void close __P((MAP *)); \ 28360207Seric extern char *lookup __P((MAP *, char *, char **, int *)); \ 28460207Seric extern void store __P((MAP *, char *, char *)); \ 28560207Seric s = stab(name, ST_MAPCLASS, ST_ENTER); \ 28660207Seric s->s_mapclass.map_cname = name; \ 28760207Seric s->s_mapclass.map_ext = ext; \ 28860207Seric s->s_mapclass.map_cflags = flags; \ 28960207Seric s->s_mapclass.map_parse = parse; \ 29060207Seric s->s_mapclass.map_open = open; \ 29160207Seric s->s_mapclass.map_close = close; \ 29260207Seric s->s_mapclass.map_lookup = lookup; \ 29360207Seric s->s_mapclass.map_store = store; \ 29460207Seric } 29560207Seric 29668508Seric void 29760207Seric setupmaps() 29860207Seric { 29960207Seric register STAB *s; 30060207Seric 30160207Seric #ifdef NEWDB 30260207Seric MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 30360207Seric map_parseargs, hash_map_open, db_map_close, 30460207Seric db_map_lookup, db_map_store); 30568508Seric 30660207Seric MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 30760207Seric map_parseargs, bt_map_open, db_map_close, 30860207Seric db_map_lookup, db_map_store); 30960207Seric #endif 31060207Seric 31160207Seric #ifdef NDBM 31260207Seric MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE, 31360207Seric map_parseargs, ndbm_map_open, ndbm_map_close, 31460207Seric ndbm_map_lookup, ndbm_map_store); 31560207Seric #endif 31660207Seric 31760207Seric #ifdef NIS 31860207Seric MAPDEF("nis", NULL, MCF_ALIASOK, 31968508Seric map_parseargs, nis_map_open, null_map_close, 32068508Seric nis_map_lookup, null_map_store); 32160207Seric #endif 32260207Seric 32368508Seric #ifdef NISPLUS 32468508Seric MAPDEF("nisplus", NULL, MCF_ALIASOK, 32568508Seric map_parseargs, nisplus_map_open, null_map_close, 32668508Seric nisplus_map_lookup, null_map_store); 32768508Seric #endif 32868508Seric 32968508Seric #ifdef HESIOD 33068508Seric MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY, 33168508Seric map_parseargs, null_map_open, null_map_close, 33268508Seric hes_map_lookup, null_map_store); 33368508Seric #endif 33468508Seric 33568508Seric #ifdef NETINFO 33668508Seric MAPDEF("netinfo", NULL, MCF_ALIASOK, 33768508Seric map_parseargs, ni_map_open, null_map_close, 33868508Seric ni_map_lookup, null_map_store); 33968508Seric #endif 34068508Seric 34168508Seric #if 0 34268508Seric MAPDEF("dns", NULL, 0, 34368508Seric dns_map_init, null_map_open, null_map_close, 34468508Seric dns_map_lookup, null_map_store); 34568508Seric #endif 34668508Seric 34768508Seric #if NAMED_BIND 34868508Seric /* best MX DNS lookup */ 34968508Seric MAPDEF("bestmx", NULL, MCF_OPTFILE, 35068508Seric map_parseargs, null_map_open, null_map_close, 35168508Seric bestmx_map_lookup, null_map_store); 35268508Seric #endif 35368508Seric 35468508Seric MAPDEF("host", NULL, 0, 35568508Seric host_map_init, null_map_open, null_map_close, 35668508Seric host_map_lookup, null_map_store); 35768508Seric 35868508Seric MAPDEF("text", NULL, MCF_ALIASOK, 35968508Seric map_parseargs, text_map_open, null_map_close, 36068508Seric text_map_lookup, null_map_store); 36168508Seric 36260207Seric MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY, 36368508Seric map_parseargs, stab_map_open, null_map_close, 36460207Seric stab_map_lookup, stab_map_store); 36560207Seric 36660207Seric MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE, 36760207Seric map_parseargs, impl_map_open, impl_map_close, 36860207Seric impl_map_lookup, impl_map_store); 36960207Seric 37068508Seric /* access to system passwd file */ 37168508Seric MAPDEF("user", NULL, MCF_OPTFILE, 37268508Seric map_parseargs, user_map_open, null_map_close, 37368508Seric user_map_lookup, null_map_store); 37460207Seric 37560207Seric /* dequote map */ 37660207Seric MAPDEF("dequote", NULL, 0, 37760207Seric dequote_init, null_map_open, null_map_close, 37860207Seric dequote_map, null_map_store); 37960207Seric 38069717Seric #if USERDB 38160207Seric /* user database */ 38268521Seric MAPDEF("userdb", ".db", 0, 38368521Seric map_parseargs, null_map_open, null_map_close, 38460207Seric udb_map_lookup, null_map_store); 38560207Seric #endif 38668508Seric 38769453Seric /* arbitrary programs */ 38869499Seric MAPDEF("program", NULL, MCF_ALIASOK, 38969453Seric map_parseargs, null_map_open, null_map_close, 39069453Seric prog_map_lookup, null_map_store); 39169453Seric 39268508Seric /* sequenced maps */ 39368508Seric MAPDEF("sequence", NULL, MCF_ALIASOK, 39468508Seric seq_map_parse, null_map_open, null_map_close, 39568508Seric seq_map_lookup, seq_map_store); 39668508Seric 39768508Seric /* switched interface to sequenced maps */ 39868508Seric MAPDEF("switch", NULL, MCF_ALIASOK, 39968508Seric map_parseargs, switch_map_open, null_map_close, 40068508Seric seq_map_lookup, seq_map_store); 40160207Seric } 40260207Seric 40360207Seric #undef MAPDEF 40460207Seric /* 40568508Seric ** INITHOSTMAPS -- initial host-dependent maps 40668508Seric ** 40768508Seric ** This should act as an interface to any local service switch 40868508Seric ** provided by the host operating system. 40968508Seric ** 41068508Seric ** Parameters: 41168508Seric ** none 41268508Seric ** 41368508Seric ** Returns: 41468508Seric ** none 41568508Seric ** 41668508Seric ** Side Effects: 41768508Seric ** Should define maps "host" and "users" as necessary 41868508Seric ** for this OS. If they are not defined, they will get 41968508Seric ** a default value later. It should check to make sure 42068508Seric ** they are not defined first, since it's possible that 42168508Seric ** the config file has provided an override. 42268508Seric */ 42368508Seric 42468508Seric void 42568508Seric inithostmaps() 42668508Seric { 42768508Seric register int i; 42868508Seric int nmaps; 42968508Seric char *maptype[MAXMAPSTACK]; 43068508Seric short mapreturn[MAXMAPACTIONS]; 43168508Seric char buf[MAXLINE]; 43268508Seric 43368508Seric /* 43468508Seric ** Set up default hosts maps. 43568508Seric */ 43668508Seric 43768508Seric #if 0 43868508Seric nmaps = switch_map_find("hosts", maptype, mapreturn); 43968508Seric for (i = 0; i < nmaps; i++) 44068508Seric { 44168508Seric if (strcmp(maptype[i], "files") == 0 && 44268508Seric stab("hosts.files", ST_MAP, ST_FIND) == NULL) 44368508Seric { 44468508Seric strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts"); 44569774Seric (void) makemapentry(buf); 44668508Seric } 44768508Seric #if NAMED_BIND 44868508Seric else if (strcmp(maptype[i], "dns") == 0 && 44968508Seric stab("hosts.dns", ST_MAP, ST_FIND) == NULL) 45068508Seric { 45168508Seric strcpy(buf, "hosts.dns dns A"); 45269774Seric (void) makemapentry(buf); 45368508Seric } 45468508Seric #endif 45568508Seric #ifdef NISPLUS 45668508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 45768508Seric stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL) 45868508Seric { 45968508Seric strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir"); 46069774Seric (void) makemapentry(buf); 46168508Seric } 46268508Seric #endif 46368508Seric #ifdef NIS 46468508Seric else if (strcmp(maptype[i], "nis") == 0 && 46568508Seric stab("hosts.nis", ST_MAP, ST_FIND) == NULL) 46668508Seric { 46768508Seric strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname"); 46869774Seric (void) makemapentry(buf); 46968508Seric } 47068508Seric #endif 47168508Seric } 47268508Seric #endif 47368508Seric 47468508Seric /* 47568508Seric ** Make sure we have a host map. 47668508Seric */ 47768508Seric 47868508Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 47968508Seric { 48068508Seric /* user didn't initialize: set up host map */ 48168508Seric strcpy(buf, "host host"); 48268508Seric #if NAMED_BIND 48368508Seric if (ConfigLevel >= 2) 48468508Seric strcat(buf, " -a."); 48568508Seric #endif 48669774Seric (void) makemapentry(buf); 48768508Seric } 48868508Seric 48968508Seric /* 49068508Seric ** Set up default aliases maps 49168508Seric */ 49268508Seric 49368508Seric nmaps = switch_map_find("aliases", maptype, mapreturn); 49468508Seric for (i = 0; i < nmaps; i++) 49568508Seric { 49668508Seric if (strcmp(maptype[i], "files") == 0 && 49768508Seric stab("aliases.files", ST_MAP, ST_FIND) == NULL) 49868508Seric { 49968508Seric strcpy(buf, "aliases.files implicit /etc/aliases"); 50069774Seric (void) makemapentry(buf); 50168508Seric } 50268508Seric #ifdef NISPLUS 50368508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 50468508Seric stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL) 50568508Seric { 50668508Seric strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir"); 50769774Seric (void) makemapentry(buf); 50868508Seric } 50968508Seric #endif 51068508Seric #ifdef NIS 51168508Seric else if (strcmp(maptype[i], "nis") == 0 && 51268508Seric stab("aliases.nis", ST_MAP, ST_FIND) == NULL) 51368508Seric { 51468508Seric strcpy(buf, "aliases.nis nis -d mail.aliases"); 51569774Seric (void) makemapentry(buf); 51668508Seric } 51768508Seric #endif 51869774Seric #ifdef HESIOD 51969774Seric else if (strcmp(maptype[i], "hesiod") == 0 && 52069774Seric stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL) 52169774Seric { 52269774Seric strcpy(buf, "aliases.hesiod hesiod aliases"); 52369774Seric (void) makemapentry(buf); 52469774Seric } 52569774Seric #endif 52668508Seric } 52769774Seric if (stab("aliases", ST_MAP, ST_FIND) == NULL) 52868508Seric { 52968508Seric strcpy(buf, "aliases switch aliases"); 53069774Seric (void) makemapentry(buf); 53168508Seric } 53268508Seric 53368508Seric #if 0 /* "user" map class is a better choice */ 53468508Seric /* 53568508Seric ** Set up default users maps. 53668508Seric */ 53768508Seric 53868508Seric nmaps = switch_map_find("passwd", maptype, mapreturn); 53968508Seric for (i = 0; i < nmaps; i++) 54068508Seric { 54168508Seric if (strcmp(maptype[i], "files") == 0 && 54268508Seric stab("users.files", ST_MAP, ST_FIND) == NULL) 54368508Seric { 54468508Seric strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd"); 54569774Seric (void) makemapentry(buf); 54668508Seric } 54768508Seric #ifdef NISPLUS 54868508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 54968508Seric stab("users.nisplus", ST_MAP, ST_FIND) == NULL) 55068508Seric { 55168508Seric strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir"); 55269774Seric (void) makemapentry(buf); 55368508Seric } 55468508Seric #endif 55568508Seric #ifdef NIS 55668508Seric else if (strcmp(maptype[i], "nis") == 0 && 55768508Seric stab("users.nis", ST_MAP, ST_FIND) == NULL) 55868508Seric { 55968508Seric strcpy(buf, "users.nis nis -m -d passwd.byname"); 56069774Seric (void) makemapentry(buf); 56168508Seric } 56268508Seric #endif 56368508Seric #ifdef HESIOD 56468508Seric else if (strcmp(maptype[i], "hesiod") == 0) && 56568508Seric stab("users.hesiod", ST_MAP, ST_FIND) == NULL) 56668508Seric { 56768508Seric strcpy(buf, "users.hesiod hesiod"); 56869774Seric (void) makemapentry(buf); 56968508Seric } 57068508Seric #endif 57168508Seric } 57268508Seric if (stab("users", ST_MAP, ST_FIND) == NULL) 57368508Seric { 57468508Seric strcpy(buf, "users switch -m passwd"); 57569774Seric (void) makemapentry(buf); 57668508Seric } 57768508Seric #endif 57868508Seric } 57968508Seric /* 58068508Seric ** SWITCH_MAP_FIND -- find the list of types associated with a map 58168508Seric ** 58268508Seric ** This is the system-dependent interface to the service switch. 58368508Seric ** 58468508Seric ** Parameters: 58568508Seric ** service -- the name of the service of interest. 58668508Seric ** maptype -- an out-array of strings containing the types 58768508Seric ** of access to use for this service. There can 58868508Seric ** be at most MAXMAPSTACK types for a single service. 58968508Seric ** mapreturn -- an out-array of return information bitmaps 59068508Seric ** for the map. 59168508Seric ** 59268508Seric ** Returns: 59368508Seric ** The number of map types filled in, or -1 for failure. 59468508Seric */ 59568508Seric 59668508Seric #ifdef SOLARIS 59768508Seric # include <nsswitch.h> 59868508Seric #endif 59968508Seric 60069815Seric #if defined(ultrix) || (defined(__osf__) && defined(__alpha)) 60169815Seric # define _USE_DEC_SVC_CONF_ 60269815Seric #endif 60369815Seric 60469815Seric #ifdef _USE_DEC_SVC_CONF_ 60568508Seric # include <sys/svcinfo.h> 60668508Seric #endif 60768508Seric 60868508Seric int 60968508Seric switch_map_find(service, maptype, mapreturn) 61068508Seric char *service; 61168508Seric char *maptype[MAXMAPSTACK]; 61268508Seric short mapreturn[MAXMAPACTIONS]; 61368508Seric { 61468508Seric register FILE *fp; 61568508Seric int svcno; 61668508Seric static char buf[MAXLINE]; 61768508Seric 61868508Seric #ifdef SOLARIS 61968508Seric struct __nsw_switchconfig *nsw_conf; 62068508Seric enum __nsw_parse_err pserr; 62168508Seric struct __nsw_lookup *lk; 62268508Seric int nsw_rc; 62368508Seric static struct __nsw_lookup lkp0 = 62468508Seric { "files", {1, 0, 0, 0}, NULL, NULL }; 62568508Seric static struct __nsw_switchconfig lkp_default = 62668508Seric { 0, "sendmail", 3, &lkp0 }; 62768508Seric 62868508Seric if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL) 62968508Seric lk = lkp_default.lookups; 63068508Seric else 63168508Seric lk = nsw_conf->lookups; 63268508Seric svcno = 0; 63368508Seric while (lk != NULL) 63468508Seric { 63568508Seric maptype[svcno] = lk->service_name; 63668508Seric if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN) 63768508Seric mapreturn[MA_NOTFOUND] |= 1 << svcno; 63868508Seric if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN) 63968508Seric mapreturn[MA_TRYAGAIN] |= 1 << svcno; 64068508Seric if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN) 64168508Seric mapreturn[MA_TRYAGAIN] |= 1 << svcno; 64268508Seric svcno++; 64368508Seric lk = lk->next; 64468508Seric } 64568508Seric return svcno; 64668508Seric #endif 64768508Seric 64869815Seric #ifdef _USE_DEC_SVC_CONF_ 64968508Seric struct svcinfo *svcinfo; 65068508Seric int svc; 65168508Seric 65269401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 65369401Seric mapreturn[svcno] = 0; 65469401Seric 65568508Seric svcinfo = getsvc(); 65668508Seric if (svcinfo == NULL) 65768508Seric goto punt; 65868508Seric if (strcmp(service, "hosts") == 0) 65968508Seric svc = SVC_HOSTS; 66068508Seric else if (strcmp(service, "aliases") == 0) 66168508Seric svc = SVC_ALIASES; 66268508Seric else if (strcmp(service, "passwd") == 0) 66368508Seric svc = SVC_PASSWD; 66468508Seric else 66568508Seric return -1; 66668508Seric for (svcno = 0; svcno < SVC_PATHSIZE; svcno++) 66768508Seric { 66868508Seric switch (svcinfo->svcpath[svc][svcno]) 66968508Seric { 67068508Seric case SVC_LOCAL: 67168508Seric maptype[svcno] = "files"; 67268508Seric break; 67368508Seric 67468508Seric case SVC_YP: 67568508Seric maptype[svcno] = "nis"; 67668508Seric break; 67768508Seric 67868508Seric case SVC_BIND: 67968508Seric maptype[svcno] = "dns"; 68068508Seric break; 68168508Seric 68268508Seric #ifdef SVC_HESIOD 68368508Seric case SVC_HESIOD: 68468508Seric maptype[svcno] = "hesiod"; 68568508Seric break; 68668508Seric #endif 68768508Seric 68868508Seric case SVC_LAST: 68968508Seric return svcno; 69068508Seric } 69168508Seric } 69268508Seric return svcno; 69368508Seric #endif 69468508Seric 69569815Seric #if !defined(SOLARIS) && !defined(_USE_DEC_SVC_CONF_) 69668508Seric /* 69768508Seric ** Fall-back mechanism. 69868508Seric */ 69968508Seric 70069401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 70169401Seric mapreturn[svcno] = 0; 70269401Seric 70368508Seric svcno = 0; 70468508Seric fp = fopen(ServiceSwitchFile, "r"); 70568508Seric if (fp != NULL) 70668508Seric { 70768508Seric while (fgets(buf, sizeof buf, fp) != NULL) 70868508Seric { 70968508Seric register char *p; 71068508Seric 71168508Seric p = strpbrk(buf, "#\n"); 71268508Seric if (p != NULL) 71368508Seric *p = '\0'; 71468508Seric p = strpbrk(buf, " \t"); 71568508Seric if (p != NULL) 71668508Seric *p++ = '\0'; 71768508Seric if (strcmp(buf, service) != 0) 71868508Seric continue; 71968508Seric 72068508Seric /* got the right service -- extract data */ 72168508Seric do 72268508Seric { 72368508Seric while (isspace(*p)) 72468508Seric p++; 72568508Seric if (*p == '\0') 72668508Seric break; 72768508Seric maptype[svcno++] = p; 72868508Seric p = strpbrk(p, " \t"); 72968508Seric if (p != NULL) 73068508Seric *p++ = '\0'; 73168508Seric } while (p != NULL); 73268508Seric break; 73368508Seric } 73468508Seric fclose(fp); 73568508Seric return svcno; 73668508Seric } 73768508Seric #endif 73868508Seric 73968508Seric /* if the service file doesn't work, use an absolute fallback */ 74068508Seric punt: 74169401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 74269401Seric mapreturn[svcno] = 0; 74369401Seric svcno = 0; 74468508Seric if (strcmp(service, "aliases") == 0) 74568508Seric { 74668628Seric maptype[svcno++] = "files"; 74768628Seric #ifdef AUTO_NIS_ALIASES 74868628Seric # ifdef NISPLUS 74968628Seric maptype[svcno++] = "nisplus"; 75068628Seric # endif 75168628Seric # ifdef NIS 75268628Seric maptype[svcno++] = "nis"; 75368628Seric # endif 75468628Seric #endif 75568628Seric return svcno; 75668508Seric } 75768508Seric if (strcmp(service, "hosts") == 0) 75868508Seric { 75968508Seric # if NAMED_BIND 76068508Seric maptype[svcno++] = "dns"; 76168508Seric # else 76268508Seric # if defined(sun) && !defined(BSD) && !defined(SOLARIS) 76368508Seric /* SunOS */ 76468508Seric maptype[svcno++] = "nis"; 76568508Seric # endif 76668508Seric # endif 76768508Seric maptype[svcno++] = "files"; 76868508Seric return svcno; 76968508Seric } 77068508Seric return -1; 77168508Seric } 77268508Seric /* 7739369Seric ** USERNAME -- return the user id of the logged in user. 7749369Seric ** 7759369Seric ** Parameters: 7769369Seric ** none. 7779369Seric ** 7789369Seric ** Returns: 7799369Seric ** The login name of the logged in user. 7809369Seric ** 7819369Seric ** Side Effects: 7829369Seric ** none. 7839369Seric ** 7849369Seric ** Notes: 7859369Seric ** The return value is statically allocated. 7869369Seric */ 7879369Seric 7889369Seric char * 7899369Seric username() 7909369Seric { 79117469Seric static char *myname = NULL; 7929369Seric extern char *getlogin(); 79319904Smiriam register struct passwd *pw; 7949369Seric 79517469Seric /* cache the result */ 79617469Seric if (myname == NULL) 79717469Seric { 79817469Seric myname = getlogin(); 79917469Seric if (myname == NULL || myname[0] == '\0') 80017469Seric { 80168693Seric pw = sm_getpwuid(RealUid); 80217469Seric if (pw != NULL) 80340993Sbostic myname = newstr(pw->pw_name); 80417469Seric } 80519904Smiriam else 80619904Smiriam { 80763787Seric uid_t uid = RealUid; 80819873Smiriam 80940993Sbostic myname = newstr(myname); 81068693Seric if ((pw = sm_getpwnam(myname)) == NULL || 81158736Seric (uid != 0 && uid != pw->pw_uid)) 81219904Smiriam { 81368693Seric pw = sm_getpwuid(uid); 81424945Seric if (pw != NULL) 81540993Sbostic myname = newstr(pw->pw_name); 81619873Smiriam } 81719873Smiriam } 81817469Seric if (myname == NULL || myname[0] == '\0') 81917469Seric { 82058151Seric syserr("554 Who are you?"); 82117469Seric myname = "postmaster"; 82217469Seric } 82317469Seric } 82417469Seric 82517469Seric return (myname); 8269369Seric } 8279369Seric /* 8284190Seric ** TTYPATH -- Get the path of the user's tty 829294Seric ** 830294Seric ** Returns the pathname of the user's tty. Returns NULL if 831294Seric ** the user is not logged in or if s/he has write permission 832294Seric ** denied. 833294Seric ** 834294Seric ** Parameters: 835294Seric ** none 836294Seric ** 837294Seric ** Returns: 838294Seric ** pathname of the user's tty. 839294Seric ** NULL if not logged in or write permission denied. 840294Seric ** 841294Seric ** Side Effects: 842294Seric ** none. 843294Seric ** 844294Seric ** WARNING: 845294Seric ** Return value is in a local buffer. 846294Seric ** 847294Seric ** Called By: 848294Seric ** savemail 849294Seric */ 850294Seric 851294Seric char * 852294Seric ttypath() 853294Seric { 854294Seric struct stat stbuf; 855294Seric register char *pathn; 856294Seric extern char *ttyname(); 8574081Seric extern char *getlogin(); 858294Seric 859294Seric /* compute the pathname of the controlling tty */ 8609369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 8619369Seric (pathn = ttyname(0)) == NULL) 862294Seric { 863294Seric errno = 0; 864294Seric return (NULL); 865294Seric } 866294Seric 867294Seric /* see if we have write permission */ 8682967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 869294Seric { 870294Seric errno = 0; 871294Seric return (NULL); 872294Seric } 873294Seric 874294Seric /* see if the user is logged in */ 875294Seric if (getlogin() == NULL) 876294Seric return (NULL); 877294Seric 878294Seric /* looks good */ 879294Seric return (pathn); 880294Seric } 8812967Seric /* 8822967Seric ** CHECKCOMPAT -- check for From and To person compatible. 8832967Seric ** 8842967Seric ** This routine can be supplied on a per-installation basis 8852967Seric ** to determine whether a person is allowed to send a message. 8862967Seric ** This allows restriction of certain types of internet 8872967Seric ** forwarding or registration of users. 8882967Seric ** 8892967Seric ** If the hosts are found to be incompatible, an error 89068857Seric ** message should be given using "usrerr" and an EX_ code 89168857Seric ** should be returned. You can also set to->q_status to 89268857Seric ** a DSN-style status code. 8932967Seric ** 89468559Seric ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the 89568559Seric ** body during the return-to-sender function; this should be done 89668559Seric ** on huge messages. This bit may already be set by the ESMTP 89768559Seric ** protocol. 8984288Seric ** 8992967Seric ** Parameters: 9002967Seric ** to -- the person being sent to. 9012967Seric ** 9022967Seric ** Returns: 90357459Seric ** an exit status 9042967Seric ** 9052967Seric ** Side Effects: 9062967Seric ** none (unless you include the usrerr stuff) 9072967Seric */ 9082967Seric 90968508Seric int 91055012Seric checkcompat(to, e) 9112967Seric register ADDRESS *to; 91255012Seric register ENVELOPE *e; 9132967Seric { 91412133Seric # ifdef lint 91512133Seric if (to == NULL) 91612133Seric to++; 91763834Seric # endif /* lint */ 91864402Seric 91964402Seric if (tTd(49, 1)) 92064402Seric printf("checkcompat(to=%s, from=%s)\n", 92164402Seric to->q_paddr, e->e_from.q_paddr); 92264402Seric 92310698Seric # ifdef EXAMPLE_CODE 92410698Seric /* this code is intended as an example only */ 9254437Seric register STAB *s; 9264437Seric 9274437Seric s = stab("arpa", ST_MAILER, ST_FIND); 92868508Seric if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 && 9299369Seric to->q_mailer == s->s_mailer) 9304437Seric { 93158151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 93268559Seric /* e->e_flags |= EF_NO_BODY_RETN; to supress body on return */ 93368857Seric to->q_status = "5.7.1"; 93457459Seric return (EX_UNAVAILABLE); 9354437Seric } 93656795Seric # endif /* EXAMPLE_CODE */ 93757459Seric return (EX_OK); 9382967Seric } 9399369Seric /* 94064035Seric ** SETSIGNAL -- set a signal handler 94164035Seric ** 94264035Seric ** This is essentially old BSD "signal(3)". 94364035Seric */ 94464035Seric 94564561Seric sigfunc_t 94664035Seric setsignal(sig, handler) 94764035Seric int sig; 94864561Seric sigfunc_t handler; 94964035Seric { 95064380Seric #if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE) 95164035Seric return signal(sig, handler); 95264035Seric #else 95364035Seric struct sigaction n, o; 95464035Seric 95564035Seric bzero(&n, sizeof n); 95664035Seric n.sa_handler = handler; 95768508Seric # ifdef SA_RESTART 95868508Seric n.sa_flags = SA_RESTART; 95968508Seric # endif 96064035Seric if (sigaction(sig, &n, &o) < 0) 96164035Seric return SIG_ERR; 96264035Seric return o.sa_handler; 96364035Seric #endif 96464035Seric } 96564035Seric /* 9669369Seric ** HOLDSIGS -- arrange to hold all signals 9679369Seric ** 9689369Seric ** Parameters: 9699369Seric ** none. 9709369Seric ** 9719369Seric ** Returns: 9729369Seric ** none. 9739369Seric ** 9749369Seric ** Side Effects: 9759369Seric ** Arranges that signals are held. 9769369Seric */ 9779369Seric 97868508Seric void 9799369Seric holdsigs() 9809369Seric { 9819369Seric } 9829369Seric /* 9839369Seric ** RLSESIGS -- arrange to release all signals 9849369Seric ** 9859369Seric ** This undoes the effect of holdsigs. 9869369Seric ** 9879369Seric ** Parameters: 9889369Seric ** none. 9899369Seric ** 9909369Seric ** Returns: 9919369Seric ** none. 9929369Seric ** 9939369Seric ** Side Effects: 9949369Seric ** Arranges that signals are released. 9959369Seric */ 9969369Seric 99768508Seric void 9989369Seric rlsesigs() 9999369Seric { 10009369Seric } 100114872Seric /* 100264705Seric ** INIT_MD -- do machine dependent initializations 100364705Seric ** 100464705Seric ** Systems that have global modes that should be set should do 100564705Seric ** them here rather than in main. 100664705Seric */ 100764705Seric 100864705Seric #ifdef _AUX_SOURCE 100964705Seric # include <compat.h> 101064705Seric #endif 101164705Seric 101268508Seric void 101364825Seric init_md(argc, argv) 101464825Seric int argc; 101564825Seric char **argv; 101664705Seric { 101764705Seric #ifdef _AUX_SOURCE 101864705Seric setcompat(getcompat() | COMPAT_BSDPROT); 101964705Seric #endif 102068508Seric 102168508Seric #ifdef VENDOR_DEFAULT 102268508Seric VendorCode = VENDOR_DEFAULT; 102368508Seric #else 102468508Seric VendorCode = VENDOR_BERKELEY; 102568508Seric #endif 102664705Seric } 102764705Seric /* 102868508Seric ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations 102968508Seric ** 103068508Seric ** Called once, on startup. 103168508Seric ** 103268508Seric ** Parameters: 103368508Seric ** e -- the global envelope. 103468508Seric ** 103568508Seric ** Returns: 103668508Seric ** none. 103768508Seric ** 103868508Seric ** Side Effects: 103968508Seric ** vendor-dependent. 104068508Seric */ 104168508Seric 104268508Seric void 104368508Seric init_vendor_macros(e) 104468508Seric register ENVELOPE *e; 104568508Seric { 104668508Seric } 104768508Seric /* 104814872Seric ** GETLA -- get the current load average 104914872Seric ** 105014881Seric ** This code stolen from la.c. 105114881Seric ** 105214872Seric ** Parameters: 105314872Seric ** none. 105414872Seric ** 105514872Seric ** Returns: 105614872Seric ** The current load average as an integer. 105714872Seric ** 105814872Seric ** Side Effects: 105914872Seric ** none. 106014872Seric */ 106114872Seric 106251920Seric /* try to guess what style of load average we have */ 106351920Seric #define LA_ZERO 1 /* always return load average as zero */ 106464360Seric #define LA_INT 2 /* read kmem for avenrun; interpret as long */ 106551920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 106651920Seric #define LA_SUBR 4 /* call getloadavg */ 106764295Seric #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */ 106864360Seric #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */ 106966301Seric #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */ 107069462Seric #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */ 107169462Seric #define LA_DGUX 9 /* special DGUX implementation */ 107269462Seric #define LA_HPUX 10 /* special HPUX implementation */ 107314872Seric 107463962Seric /* do guesses based on general OS type */ 107551920Seric #ifndef LA_TYPE 107663962Seric # define LA_TYPE LA_ZERO 107751920Seric #endif 107851920Seric 107969462Seric #ifndef FSHIFT 108069462Seric # if defined(unixpc) 108169462Seric # define FSHIFT 5 108269462Seric # endif 108369462Seric 108469462Seric # if defined(__alpha) || defined(IRIX) 108569462Seric # define FSHIFT 10 108669462Seric # endif 108769462Seric 108869462Seric # if defined(_AIX3) 108969462Seric # define FSHIFT 16 109069462Seric # endif 109169462Seric #endif 109269462Seric 109369462Seric #ifndef FSHIFT 109469462Seric # define FSHIFT 8 109569462Seric #endif 109669462Seric 109769462Seric #ifndef FSCALE 109869462Seric # define FSCALE (1 << FSHIFT) 109969462Seric #endif 110069462Seric 110169654Seric #ifndef LA_AVENRUN 110269654Seric # ifdef SYSTEM5 110369654Seric # define LA_AVENRUN "avenrun" 110469654Seric # else 110569654Seric # define LA_AVENRUN "_avenrun" 110669654Seric # endif 110769654Seric #endif 110869654Seric 110964360Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) 111051920Seric 111114872Seric #include <nlist.h> 111214872Seric 111368508Seric #ifdef IRIX64 111468508Seric # define nlist nlist64 111568508Seric #endif 111668508Seric 111751920Seric /* _PATH_UNIX should be defined in <paths.h> */ 111851920Seric #ifndef _PATH_UNIX 111963962Seric # if defined(SYSTEM5) 112063962Seric # define _PATH_UNIX "/unix" 112163962Seric # else 112263962Seric # define _PATH_UNIX "/vmunix" 112363962Seric # endif 112451920Seric #endif 112551920Seric 112669462Seric struct nlist Nl[] = 112714872Seric { 112851920Seric { LA_AVENRUN }, 112914872Seric #define X_AVENRUN 0 113014872Seric { 0 }, 113114872Seric }; 113214872Seric 113314872Seric getla() 113414872Seric { 113514872Seric static int kmem = -1; 113651920Seric #if LA_TYPE == LA_INT 113724943Seric long avenrun[3]; 113851920Seric #else 113964360Seric # if LA_TYPE == LA_SHORT 114064360Seric short avenrun[3]; 114164360Seric # else 114251920Seric double avenrun[3]; 114364360Seric # endif 114451920Seric #endif 114569462Seric extern int errno; 114625615Seric extern off_t lseek(); 114714872Seric 114814872Seric if (kmem < 0) 114914872Seric { 115024945Seric kmem = open("/dev/kmem", 0, 0); 115114872Seric if (kmem < 0) 115257736Seric { 115357736Seric if (tTd(3, 1)) 115457736Seric printf("getla: open(/dev/kmem): %s\n", 115557736Seric errstring(errno)); 115614872Seric return (-1); 115757736Seric } 115851920Seric (void) fcntl(kmem, F_SETFD, 1); 115969462Seric 116068508Seric #ifdef _AIX3 116168508Seric if (knlist(Nl, 1, sizeof Nl[0]) < 0) 116268508Seric #else 116357736Seric if (nlist(_PATH_UNIX, Nl) < 0) 116468508Seric #endif 116557736Seric { 116657736Seric if (tTd(3, 1)) 116757736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 116857736Seric errstring(errno)); 116914872Seric return (-1); 117057736Seric } 117159253Seric if (Nl[X_AVENRUN].n_value == 0) 117259253Seric { 117359253Seric if (tTd(3, 1)) 117459253Seric printf("getla: nlist(%s, %s) ==> 0\n", 117559253Seric _PATH_UNIX, LA_AVENRUN); 117659253Seric return (-1); 117759253Seric } 117868508Seric #ifdef NAMELISTMASK 117968508Seric Nl[X_AVENRUN].n_value &= NAMELISTMASK; 118066763Seric #endif 118114872Seric } 118257736Seric if (tTd(3, 20)) 118357736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 118468508Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 || 118523118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 118619967Seric { 118719967Seric /* thank you Ian */ 118857736Seric if (tTd(3, 1)) 118957736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 119019967Seric return (-1); 119119967Seric } 119269462Seric # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) 119357736Seric if (tTd(3, 5)) 119457736Seric { 119557736Seric printf("getla: avenrun = %d", avenrun[0]); 119657736Seric if (tTd(3, 15)) 119757736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 119857736Seric printf("\n"); 119957736Seric } 120057736Seric if (tTd(3, 1)) 120157736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 120224943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 120369462Seric # else /* LA_TYPE == LA_FLOAT */ 120457736Seric if (tTd(3, 5)) 120557736Seric { 120657736Seric printf("getla: avenrun = %g", avenrun[0]); 120757736Seric if (tTd(3, 15)) 120857736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 120957736Seric printf("\n"); 121057736Seric } 121157736Seric if (tTd(3, 1)) 121257736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 121351920Seric return ((int) (avenrun[0] + 0.5)); 121469462Seric # endif 121514872Seric } 121614872Seric 121769462Seric #endif /* LA_TYPE == LA_INT or LA_SHORT or LA_FLOAT */ 121851773Seric 121969462Seric #if LA_TYPE == LA_READKSYM 122064718Seric 122169473Seric # include <sys/ksym.h> 122269473Seric 122369462Seric getla() 122469462Seric { 122569462Seric static int kmem = -1; 122669462Seric long avenrun[3]; 122769462Seric extern int errno; 122869462Seric struct mioc_rksym mirk; 122964718Seric 123069462Seric if (kmem < 0) 123169462Seric { 123269462Seric kmem = open("/dev/kmem", 0, 0); 123369462Seric if (kmem < 0) 123469462Seric { 123569462Seric if (tTd(3, 1)) 123669462Seric printf("getla: open(/dev/kmem): %s\n", 123769462Seric errstring(errno)); 123869462Seric return (-1); 123969462Seric } 124069462Seric (void) fcntl(kmem, F_SETFD, 1); 124169462Seric } 124269462Seric mirk.mirk_symname = LA_AVENRUN; 124369462Seric mirk.mirk_buf = avenrun; 124469462Seric mirk.mirk_buflen = sizeof(avenrun); 124569462Seric if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0) 124669462Seric { 124769462Seric if (tTd(3, 1)) 124869462Seric printf("getla: ioctl(MIOC_READKSYM) failed: %s\n", 124969462Seric errstring(errno)); 125069462Seric return -1; 125169462Seric } 125269462Seric if (tTd(3, 5)) 125369462Seric { 125469462Seric printf("getla: avenrun = %d", avenrun[0]); 125569462Seric if (tTd(3, 15)) 125669462Seric printf(", %d, %d", avenrun[1], avenrun[2]); 125769462Seric printf("\n"); 125869462Seric } 125969462Seric if (tTd(3, 1)) 126069462Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 126169462Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 126269462Seric } 126369462Seric 126469462Seric #endif /* LA_TYPE == LA_READKSYM */ 126569462Seric 126669462Seric #if LA_TYPE == LA_DGUX 126769462Seric 126869462Seric # include <sys/dg_sys_info.h> 126969462Seric 127068508Seric int 127168508Seric getla() 127264718Seric { 127364718Seric struct dg_sys_info_load_info load_info; 127464718Seric 127564718Seric dg_sys_info((long *)&load_info, 127664718Seric DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); 127764718Seric 127868508Seric if (tTd(3, 1)) 127968508Seric printf("getla: %d\n", (int) (load_info.one_minute + 0.5)); 128068508Seric 128164718Seric return((int) (load_info.one_minute + 0.5)); 128264718Seric } 128364718Seric 128469462Seric #endif /* LA_TYPE == LA_DGUX */ 128564718Seric 128669462Seric #if LA_TYPE == LA_HPUX 128769462Seric 128869563Seric /* forward declarations to keep gcc from complaining */ 128968869Seric struct pst_dynamic; 129069563Seric struct pst_status; 129169563Seric struct pst_static; 129269563Seric struct pst_vminfo; 129369563Seric struct pst_diskinfo; 129469563Seric struct pst_processor; 129569563Seric struct pst_lv; 129669563Seric struct pst_swapinfo; 129768869Seric 129869462Seric # include <sys/param.h> 129969462Seric # include <sys/pstat.h> 130068508Seric 130168508Seric int 130251773Seric getla() 130351773Seric { 130468508Seric struct pst_dynamic pstd; 130568508Seric 130668508Seric if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic), 130768869Seric (size_t) 1, 0) == -1) 130868508Seric return 0; 130968508Seric 131068508Seric if (tTd(3, 1)) 131168508Seric printf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5)); 131268508Seric 131368508Seric return (int) (pstd.psd_avg_1_min + 0.5); 131468508Seric } 131568508Seric 131669462Seric #endif /* LA_TYPE == LA_HPUX */ 131768508Seric 131869462Seric #if LA_TYPE == LA_SUBR 131969462Seric 132068508Seric int 132168508Seric getla() 132268508Seric { 132351920Seric double avenrun[3]; 132451920Seric 132551920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 132657736Seric { 132757736Seric if (tTd(3, 1)) 132857736Seric perror("getla: getloadavg failed:"); 132951920Seric return (-1); 133057736Seric } 133157736Seric if (tTd(3, 1)) 133257736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 133351920Seric return ((int) (avenrun[0] + 0.5)); 133451773Seric } 133551773Seric 133669462Seric #endif /* LA_TYPE == LA_SUBR */ 133769462Seric 133864295Seric #if LA_TYPE == LA_MACH 133951773Seric 134064295Seric /* 134165173Seric ** This has been tested on NEXTSTEP release 2.1/3.X. 134264295Seric */ 134364295Seric 134465173Seric #if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 134565173Seric # include <mach/mach.h> 134665173Seric #else 134765173Seric # include <mach.h> 134865173Seric #endif 134964295Seric 135051773Seric getla() 135151773Seric { 135264295Seric processor_set_t default_set; 135364295Seric kern_return_t error; 135464295Seric unsigned int info_count; 135564295Seric struct processor_set_basic_info info; 135664295Seric host_t host; 135764295Seric 135864295Seric error = processor_set_default(host_self(), &default_set); 135964295Seric if (error != KERN_SUCCESS) 136064295Seric return -1; 136164295Seric info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 136264295Seric if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, 136364295Seric &host, (processor_set_info_t)&info, 136464295Seric &info_count) != KERN_SUCCESS) 136564295Seric { 136664295Seric return -1; 136764295Seric } 136864295Seric return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE; 136964295Seric } 137064295Seric 137169462Seric #endif /* LA_TYPE == LA_MACH */ 137264295Seric 137366313Seric #if LA_TYPE == LA_PROCSTR 137464295Seric 137566301Seric /* 137666301Seric ** Read /proc/loadavg for the load average. This is assumed to be 137766301Seric ** in a format like "0.15 0.12 0.06". 137866301Seric ** 137966301Seric ** Initially intended for Linux. This has been in the kernel 138066301Seric ** since at least 0.99.15. 138166301Seric */ 138266301Seric 138366301Seric # ifndef _PATH_LOADAVG 138466301Seric # define _PATH_LOADAVG "/proc/loadavg" 138566301Seric # endif 138666301Seric 138766301Seric int 138864295Seric getla() 138964295Seric { 139066319Seric double avenrun; 139166301Seric register int result; 139266319Seric FILE *fp; 139366301Seric 139466319Seric fp = fopen(_PATH_LOADAVG, "r"); 139569472Seric if (fp == NULL) 139666301Seric { 139766319Seric if (tTd(3, 1)) 139866319Seric printf("getla: fopen(%s): %s\n", 139966319Seric _PATH_LOADAVG, errstring(errno)); 140066319Seric return -1; 140166301Seric } 140266301Seric result = fscanf(fp, "%lf", &avenrun); 140366319Seric fclose(fp); 140466301Seric if (result != 1) 140566301Seric { 140666310Seric if (tTd(3, 1)) 140766301Seric printf("getla: fscanf() = %d: %s\n", 140866301Seric result, errstring(errno)); 140966301Seric return -1; 141066301Seric } 141166301Seric 141257736Seric if (tTd(3, 1)) 141366301Seric printf("getla(): %.2f\n", avenrun); 141466301Seric 141566301Seric return ((int) (avenrun + 0.5)); 141666301Seric } 141766301Seric 141869462Seric #endif /* LA_TYPE == LA_PROCSTR */ 141966301Seric 142069462Seric #if LA_TYPE == LA_ZERO 142169462Seric 142266301Seric getla() 142366301Seric { 142466301Seric if (tTd(3, 1)) 142557736Seric printf("getla: ZERO\n"); 142651920Seric return (0); 142751773Seric } 142851773Seric 142969462Seric #endif /* LA_TYPE == LA_ZERO */ 143066045Seric 143166045Seric 143266045Seric /* 143366045Seric * Copyright 1989 Massachusetts Institute of Technology 143466045Seric * 143566045Seric * Permission to use, copy, modify, distribute, and sell this software and its 143666045Seric * documentation for any purpose is hereby granted without fee, provided that 143766045Seric * the above copyright notice appear in all copies and that both that 143866045Seric * copyright notice and this permission notice appear in supporting 143966045Seric * documentation, and that the name of M.I.T. not be used in advertising or 144066045Seric * publicity pertaining to distribution of the software without specific, 144166045Seric * written prior permission. M.I.T. makes no representations about the 144266045Seric * suitability of this software for any purpose. It is provided "as is" 144366045Seric * without express or implied warranty. 144466045Seric * 144566045Seric * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 144666045Seric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 144766045Seric * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 144866045Seric * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 144966045Seric * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 145066045Seric * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 145166045Seric * 145266045Seric * Authors: Many and varied... 145366045Seric */ 145466045Seric 145566045Seric /* Non Apollo stuff removed by Don Lewis 11/15/93 */ 145666045Seric #ifndef lint 145766045Seric static char rcsid[] = "@(#)$Id: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $"; 145866045Seric #endif /* !lint */ 145966045Seric 146066179Seric #ifdef apollo 146166045Seric # undef volatile 146266045Seric # include <apollo/base.h> 146366045Seric 146466045Seric /* ARGSUSED */ 146566045Seric int getloadavg( call_data ) 146666045Seric caddr_t call_data; /* pointer to (double) return value */ 146766045Seric { 146866045Seric double *avenrun = (double *) call_data; 146966045Seric int i; 147066045Seric status_$t st; 147166045Seric long loadav[3]; 147266045Seric proc1_$get_loadav(loadav, &st); 147366045Seric *avenrun = loadav[0] / (double) (1 << 16); 147466045Seric return(0); 147566045Seric } 147666045Seric # endif /* apollo */ 147724943Seric /* 147824943Seric ** SHOULDQUEUE -- should this message be queued or sent? 147924943Seric ** 148024943Seric ** Compares the message cost to the load average to decide. 148124943Seric ** 148224943Seric ** Parameters: 148324943Seric ** pri -- the priority of the message in question. 148457438Seric ** ctime -- the message creation time. 148524943Seric ** 148624943Seric ** Returns: 148724943Seric ** TRUE -- if this message should be queued up for the 148824943Seric ** time being. 148924943Seric ** FALSE -- if the load is low enough to send this message. 149024943Seric ** 149124943Seric ** Side Effects: 149224943Seric ** none. 149324943Seric */ 149424943Seric 149524943Seric bool 149657438Seric shouldqueue(pri, ctime) 149724943Seric long pri; 149857438Seric time_t ctime; 149924943Seric { 150068508Seric bool rval; 150168508Seric 150268508Seric if (tTd(3, 30)) 150368508Seric printf("shouldqueue: CurrentLA=%d, pri=%d: ", CurrentLA, pri); 150451920Seric if (CurrentLA < QueueLA) 150568508Seric { 150668508Seric if (tTd(3, 30)) 150768508Seric printf("FALSE (CurrentLA < QueueLA)\n"); 150824943Seric return (FALSE); 150968508Seric } 151058132Seric if (CurrentLA >= RefuseLA) 151168508Seric { 151268508Seric if (tTd(3, 30)) 151368508Seric printf("TRUE (CurrentLA >= RefuseLA)\n"); 151458132Seric return (TRUE); 151568508Seric } 151668508Seric rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1)); 151768508Seric if (tTd(3, 30)) 151868508Seric printf("%s (by calculation)\n", rval ? "TRUE" : "FALSE"); 151968508Seric return rval; 152024943Seric } 152124943Seric /* 152253037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 152353037Seric ** 152453037Seric ** Parameters: 152553037Seric ** none. 152653037Seric ** 152753037Seric ** Returns: 152853037Seric ** TRUE if incoming SMTP connections should be refused 152953037Seric ** (for now). 153053037Seric ** FALSE if we should accept new work. 153153037Seric ** 153253037Seric ** Side Effects: 153353037Seric ** none. 153453037Seric */ 153553037Seric 153653037Seric bool 153753037Seric refuseconnections() 153853037Seric { 153969801Seric extern bool enoughdiskspace(); 154068508Seric 154159156Seric #ifdef XLA 154259156Seric if (!xla_smtp_ok()) 154359156Seric return TRUE; 154459156Seric #endif 154559156Seric 154653037Seric /* this is probably too simplistic */ 154769801Seric return CurrentLA >= RefuseLA || !enoughdiskspace(MinBlocksFree + 1); 154853037Seric } 154953037Seric /* 155024943Seric ** SETPROCTITLE -- set process title for ps 155124943Seric ** 155224943Seric ** Parameters: 155358674Seric ** fmt -- a printf style format string. 155458674Seric ** a, b, c -- possible parameters to fmt. 155524943Seric ** 155624943Seric ** Returns: 155724943Seric ** none. 155824943Seric ** 155924943Seric ** Side Effects: 156024943Seric ** Clobbers argv of our main procedure so ps(1) will 156124943Seric ** display the title. 156224943Seric */ 156324943Seric 156468508Seric #define SPT_NONE 0 /* don't use it at all */ 156568508Seric #define SPT_REUSEARGV 1 /* cover argv with title information */ 156668508Seric #define SPT_BUILTIN 2 /* use libc builtin */ 156768508Seric #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */ 156868508Seric #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */ 156969654Seric #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */ 157068508Seric 157168508Seric #ifndef SPT_TYPE 157268508Seric # define SPT_TYPE SPT_REUSEARGV 157368508Seric #endif 157468508Seric 157568508Seric #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN 157668508Seric 157768508Seric # if SPT_TYPE == SPT_PSTAT 157858689Seric # include <sys/pstat.h> 157958689Seric # endif 158068508Seric # if SPT_TYPE == SPT_PSSTRINGS 158159732Seric # include <machine/vmparam.h> 158259732Seric # include <sys/exec.h> 158368508Seric # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */ 158468508Seric # undef SPT_TYPE 158568508Seric # define SPT_TYPE SPT_REUSEARGV 158668734Seric # else 158768734Seric # ifndef NKPDE /* FreeBSD 2.0 */ 158868734Seric # define NKPDE 63 158968734Seric typedef unsigned int *pt_entry_t; 159068734Seric # endif 159164247Seric # endif 159259732Seric # endif 159368508Seric 159468508Seric # if SPT_TYPE == SPT_PSSTRINGS 159568508Seric # define SETPROC_STATIC static 159668508Seric # else 159759732Seric # define SETPROC_STATIC 159859732Seric # endif 159967626Seric 160069654Seric # if SPT_TYPE == SPT_SYSMIPS 160169654Seric # include <sys/sysmips.h> 160269654Seric # include <sys/sysnews.h> 160369654Seric # endif 160469654Seric 160568508Seric # ifndef SPT_PADCHAR 160668508Seric # define SPT_PADCHAR ' ' 160768508Seric # endif 160858689Seric 160968508Seric #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */ 161064843Seric 161168508Seric #if SPT_TYPE != SPT_BUILTIN 161268508Seric 161324943Seric /*VARARGS1*/ 161468508Seric void 161568508Seric # ifdef __STDC__ 161657642Seric setproctitle(char *fmt, ...) 161768508Seric # else 161857642Seric setproctitle(fmt, va_alist) 161924943Seric char *fmt; 162057642Seric va_dcl 162168508Seric # endif 162224943Seric { 162368508Seric # if SPT_TYPE != SPT_NONE 162424943Seric register char *p; 162525049Seric register int i; 162659732Seric SETPROC_STATIC char buf[MAXLINE]; 162756852Seric VA_LOCAL_DECL 162868508Seric # if SPT_TYPE == SPT_PSTAT 162958689Seric union pstun pst; 163058689Seric # endif 163169748Seric # if SPT_TYPE == SPT_REUSEARGV 163224943Seric extern char **Argv; 163324943Seric extern char *LastArgv; 163469748Seric # endif 163524943Seric 163658674Seric p = buf; 163724943Seric 163858674Seric /* print sendmail: heading for grep */ 163958674Seric (void) strcpy(p, "sendmail: "); 164058674Seric p += strlen(p); 164124943Seric 164258674Seric /* print the argument string */ 164358674Seric VA_START(fmt); 164458674Seric (void) vsprintf(p, fmt, ap); 164556852Seric VA_END; 164654996Seric 164758674Seric i = strlen(buf); 164858689Seric 164968508Seric # if SPT_TYPE == SPT_PSTAT 165058689Seric pst.pst_command = buf; 165158689Seric pstat(PSTAT_SETCMD, pst, i, 0, 0); 165269654Seric # endif 165369654Seric # if SPT_TYPE == SPT_PSSTRINGS 165459732Seric PS_STRINGS->ps_nargvstr = 1; 165559732Seric PS_STRINGS->ps_argvstr = buf; 165669654Seric # endif 165769654Seric # if SPT_TYPE == SPT_SYSMIPS 165869654Seric sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf); 165969654Seric # endif 166069654Seric # if SPT_TYPE == SPT_REUSEARGV 166154996Seric if (i > LastArgv - Argv[0] - 2) 166225049Seric { 166354996Seric i = LastArgv - Argv[0] - 2; 166458674Seric buf[i] = '\0'; 166525049Seric } 166658674Seric (void) strcpy(Argv[0], buf); 166754997Seric p = &Argv[0][i]; 166824943Seric while (p < LastArgv) 166968508Seric *p++ = SPT_PADCHAR; 167068508Seric Argv[1] = NULL; 167169654Seric # endif 167268508Seric # endif /* SPT_TYPE != SPT_NONE */ 167324943Seric } 167465982Seric 167568508Seric #endif /* SPT_TYPE != SPT_BUILTIN */ 167625698Seric /* 167725698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 167825698Seric ** 167925698Seric ** Parameters: 168068508Seric ** sig -- the signal that got us here (unused). 168125698Seric ** 168225698Seric ** Returns: 168325698Seric ** none. 168425698Seric ** 168525698Seric ** Side Effects: 168625698Seric ** Picks up extant zombies. 168725698Seric */ 168825698Seric 168946928Sbostic void 169068508Seric reapchild(sig) 169168508Seric int sig; 169225698Seric { 169364738Seric int olderrno = errno; 169463966Seric # ifdef HASWAITPID 169560219Seric auto int status; 169660560Seric int count; 169760560Seric int pid; 169860219Seric 169960560Seric count = 0; 170060560Seric while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 170160560Seric { 170260560Seric if (count++ > 1000) 170360560Seric { 170466748Seric #ifdef LOG 170560560Seric syslog(LOG_ALERT, "reapchild: waitpid loop: pid=%d, status=%x", 170660560Seric pid, status); 170766748Seric #endif 170860560Seric break; 170960560Seric } 171060560Seric } 171160219Seric # else 171225698Seric # ifdef WNOHANG 171325698Seric union wait status; 171425698Seric 171563753Seric while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) 171625698Seric continue; 171756795Seric # else /* WNOHANG */ 171825698Seric auto int status; 171925698Seric 172060219Seric while (wait(&status) > 0) 172125698Seric continue; 172256795Seric # endif /* WNOHANG */ 172360219Seric # endif 172464035Seric # ifdef SYS5SIGNALS 172564035Seric (void) setsignal(SIGCHLD, reapchild); 172658061Seric # endif 172764738Seric errno = olderrno; 172825698Seric } 172955418Seric /* 173069654Seric ** PUTENV -- emulation of putenv() in terms of setenv() 173169654Seric ** 173269654Seric ** Not needed on Posix-compliant systems. 173369654Seric ** This doesn't have full Posix semantics, but it's good enough 173469654Seric ** for sendmail. 173569654Seric ** 173669654Seric ** Parameter: 173769654Seric ** env -- the environment to put. 173869654Seric ** 173969654Seric ** Returns: 174069654Seric ** none. 174169654Seric */ 174269654Seric 174369654Seric #ifdef NEEDPUTENV 174469654Seric 174569717Seric # if NEEDPUTENV == 2 /* no setenv(3) call available */ 174669717Seric 174769717Seric int 174869717Seric putenv(str) 174969717Seric char *str; 175069717Seric { 175169717Seric char **current; 175269717Seric int matchlen, envlen=0; 175369717Seric char *tmp; 175469717Seric char **newenv; 175569717Seric static int first=1; 175669717Seric extern char **environ; 175769717Seric 175869717Seric /* 175969717Seric * find out how much of str to match when searching 176069717Seric * for a string to replace. 176169717Seric */ 176269717Seric if ((tmp = index(str, '=')) == NULL || tmp == str) 176369717Seric matchlen = strlen(str); 176469717Seric else 176569717Seric matchlen = (int) (tmp - str); 176669717Seric ++matchlen; 176769717Seric 176869717Seric /* 176969717Seric * Search for an existing string in the environment and find the 177069717Seric * length of environ. If found, replace and exit. 177169717Seric */ 177269717Seric for (current=environ; *current; current++) { 177369717Seric ++envlen; 177469717Seric 177569717Seric if (strncmp(str, *current, matchlen) == 0) { 177669717Seric /* found it, now insert the new version */ 177769717Seric *current = (char *)str; 177869717Seric return(0); 177969717Seric } 178069717Seric } 178169717Seric 178269717Seric /* 178369717Seric * There wasn't already a slot so add space for a new slot. 178469717Seric * If this is our first time through, use malloc(), else realloc(). 178569717Seric */ 178669717Seric if (first) { 178769717Seric newenv = (char **) malloc(sizeof(char *) * (envlen + 2)); 178869717Seric if (newenv == NULL) 178969717Seric return(-1); 179069717Seric 179169717Seric first=0; 179269717Seric (void) memcpy(newenv, environ, sizeof(char *) * envlen); 179369717Seric } else { 179469717Seric newenv = (char **) realloc((char *)environ, sizeof(char *) * (envlen + 2)); 179569717Seric if (newenv == NULL) 179669717Seric return(-1); 179769717Seric } 179869717Seric 179969717Seric /* actually add in the new entry */ 180069717Seric environ = newenv; 180169717Seric environ[envlen] = (char *)str; 180269717Seric environ[envlen+1] = NULL; 180369717Seric 180469717Seric return(0); 180569717Seric } 180669717Seric 180769717Seric #else /* implement putenv() in terms of setenv() */ 180869717Seric 180969717Seric int 181069654Seric putenv(env) 181169654Seric char *env; 181269654Seric { 181369654Seric char *p; 181469654Seric int l; 181569654Seric char nbuf[100]; 181669654Seric 181769654Seric p = strchr(env, '='); 181869654Seric if (p == NULL) 181969717Seric return 0; 182069654Seric l = p - env; 182169654Seric if (l > sizeof nbuf - 1) 182269654Seric l = sizeof nbuf - 1; 182369654Seric bcopy(env, nbuf, l); 182469654Seric nbuf[l] = '\0'; 182569717Seric return setenv(nbuf, ++p, 1); 182669654Seric } 182769654Seric 182869717Seric # endif 182969654Seric #endif 183069654Seric /* 183155418Seric ** UNSETENV -- remove a variable from the environment 183255418Seric ** 183355418Seric ** Not needed on newer systems. 183455418Seric ** 183555418Seric ** Parameters: 183655418Seric ** name -- the string name of the environment variable to be 183755418Seric ** deleted from the current environment. 183855418Seric ** 183955418Seric ** Returns: 184055418Seric ** none. 184155418Seric ** 184255418Seric ** Globals: 184355418Seric ** environ -- a pointer to the current environment. 184455418Seric ** 184555418Seric ** Side Effects: 184655418Seric ** Modifies environ. 184755418Seric */ 184855418Seric 184963962Seric #ifndef HASUNSETENV 185055418Seric 185155418Seric void 185255418Seric unsetenv(name) 185355418Seric char *name; 185455418Seric { 185555418Seric extern char **environ; 185655418Seric register char **pp; 185755418Seric int len = strlen(name); 185855418Seric 185955418Seric for (pp = environ; *pp != NULL; pp++) 186055418Seric { 186155418Seric if (strncmp(name, *pp, len) == 0 && 186255418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 186355418Seric break; 186455418Seric } 186555418Seric 186655418Seric for (; *pp != NULL; pp++) 186755418Seric *pp = pp[1]; 186855418Seric } 186955418Seric 187063962Seric #endif 187156215Seric /* 187256215Seric ** GETDTABLESIZE -- return number of file descriptors 187356215Seric ** 187456215Seric ** Only on non-BSD systems 187556215Seric ** 187656215Seric ** Parameters: 187756215Seric ** none 187856215Seric ** 187956215Seric ** Returns: 188056215Seric ** size of file descriptor table 188156215Seric ** 188256215Seric ** Side Effects: 188356215Seric ** none 188456215Seric */ 188556215Seric 188663787Seric #ifdef SOLARIS 188763787Seric # include <sys/resource.h> 188863787Seric #endif 188956215Seric 189056215Seric int 189163787Seric getdtsize() 189256215Seric { 189363787Seric #ifdef RLIMIT_NOFILE 189463787Seric struct rlimit rl; 189563787Seric 189663787Seric if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) 189763787Seric return rl.rlim_cur; 189863787Seric #endif 189963787Seric 190064031Seric # ifdef HASGETDTABLESIZE 190164031Seric return getdtablesize(); 190264031Seric # else 190364031Seric # ifdef _SC_OPEN_MAX 190458689Seric return sysconf(_SC_OPEN_MAX); 190563787Seric # else 190656215Seric return NOFILE; 190763787Seric # endif 190858689Seric # endif 190956215Seric } 191057631Seric /* 191157631Seric ** UNAME -- get the UUCP name of this system. 191257631Seric */ 191357631Seric 191457943Seric #ifndef HASUNAME 191557631Seric 191657631Seric int 191757631Seric uname(name) 191857631Seric struct utsname *name; 191957631Seric { 192057631Seric FILE *file; 192157631Seric char *n; 192257631Seric 192357631Seric name->nodename[0] = '\0'; 192457631Seric 192557661Seric /* try /etc/whoami -- one line with the node name */ 192657631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 192757631Seric { 192857661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 192957631Seric (void) fclose(file); 193057661Seric n = strchr(name->nodename, '\n'); 193157631Seric if (n != NULL) 193257631Seric *n = '\0'; 193357631Seric if (name->nodename[0] != '\0') 193457631Seric return (0); 193557631Seric } 193657631Seric 193757661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 193857631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 193957631Seric { 194057631Seric char buf[MAXLINE]; 194157631Seric 194257631Seric while (fgets(buf, MAXLINE, file) != NULL) 194357631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 194457631Seric NODE_LENGTH, name->nodename) > 0) 194557631Seric break; 194657631Seric (void) fclose(file); 194757631Seric if (name->nodename[0] != '\0') 194857631Seric return (0); 194957631Seric } 195057631Seric 195157631Seric #ifdef TRUST_POPEN 195257631Seric /* 195357631Seric ** Popen is known to have security holes. 195457631Seric */ 195557631Seric 195657661Seric /* try uuname -l to return local name */ 195757631Seric if ((file = popen("uuname -l", "r")) != NULL) 195857631Seric { 195957661Seric (void) fgets(name, NODE_LENGTH + 1, file); 196057631Seric (void) pclose(file); 196157661Seric n = strchr(name, '\n'); 196257631Seric if (n != NULL) 196357631Seric *n = '\0'; 196457661Seric if (name->nodename[0] != '\0') 196557631Seric return (0); 196657631Seric } 196757631Seric #endif 196869472Seric 196957631Seric return (-1); 197057631Seric } 197157943Seric #endif /* HASUNAME */ 197258068Seric /* 197358068Seric ** INITGROUPS -- initialize groups 197458068Seric ** 197558068Seric ** Stub implementation for System V style systems 197658068Seric */ 197758068Seric 197858068Seric #ifndef HASINITGROUPS 197958068Seric 198058068Seric initgroups(name, basegid) 198158068Seric char *name; 198258068Seric int basegid; 198358068Seric { 198458068Seric return 0; 198558068Seric } 198658068Seric 198758068Seric #endif 198858082Seric /* 198959289Seric ** SETSID -- set session id (for non-POSIX systems) 199059289Seric */ 199159289Seric 199259289Seric #ifndef HASSETSID 199359289Seric 199463753Seric pid_t 199563753Seric setsid __P ((void)) 199659289Seric { 199764155Seric #ifdef TIOCNOTTY 199864155Seric int fd; 199964155Seric 200066743Seric fd = open("/dev/tty", O_RDWR, 0); 200164155Seric if (fd >= 0) 200264155Seric { 200364155Seric (void) ioctl(fd, (int) TIOCNOTTY, (char *) 0); 200464155Seric (void) close(fd); 200564155Seric } 200664155Seric #endif /* TIOCNOTTY */ 200764705Seric # ifdef SYS5SETPGRP 200863753Seric return setpgrp(); 200963753Seric # else 201064155Seric return setpgid(0, getpid()); 201159289Seric # endif 201259289Seric } 201359289Seric 201459289Seric #endif 201559289Seric /* 201666748Seric ** FSYNC -- dummy fsync 201766748Seric */ 201866748Seric 201966748Seric #ifdef NEEDFSYNC 202066748Seric 202166748Seric fsync(fd) 202266748Seric int fd; 202366748Seric { 202466748Seric # ifdef O_SYNC 202566748Seric return fcntl(fd, F_SETFL, O_SYNC); 202666748Seric # else 202766748Seric /* nothing we can do */ 202866748Seric return 0; 202966748Seric # endif 203066748Seric } 203166748Seric 203266748Seric #endif 203366748Seric /* 203464718Seric ** DGUX_INET_ADDR -- inet_addr for DG/UX 203564718Seric ** 203664718Seric ** Data General DG/UX version of inet_addr returns a struct in_addr 203768508Seric ** instead of a long. This patches things. Only needed on versions 203868508Seric ** prior to 5.4.3. 203964718Seric */ 204064718Seric 204168508Seric #ifdef DGUX_5_4_2 204264718Seric 204364718Seric #undef inet_addr 204464718Seric 204564718Seric long 204664718Seric dgux_inet_addr(host) 204764718Seric char *host; 204864718Seric { 204964718Seric struct in_addr haddr; 205064718Seric 205164718Seric haddr = inet_addr(host); 205264718Seric return haddr.s_addr; 205364718Seric } 205464718Seric 205564718Seric #endif 205664718Seric /* 205763969Seric ** GETOPT -- for old systems or systems with bogus implementations 205863969Seric */ 205963969Seric 206063969Seric #ifdef NEEDGETOPT 206163969Seric 206263969Seric /* 206363969Seric * Copyright (c) 1985 Regents of the University of California. 206463969Seric * All rights reserved. The Berkeley software License Agreement 206563969Seric * specifies the terms and conditions for redistribution. 206663969Seric */ 206763969Seric 206863969Seric 206963969Seric /* 207063969Seric ** this version hacked to add `atend' flag to allow state machine 207163969Seric ** to reset if invoked by the program to scan args for a 2nd time 207263969Seric */ 207363969Seric 207463969Seric #if defined(LIBC_SCCS) && !defined(lint) 207563969Seric static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; 207664072Seric #endif /* LIBC_SCCS and not lint */ 207763969Seric 207863969Seric #include <stdio.h> 207963969Seric 208063969Seric /* 208163969Seric * get option letter from argument vector 208263969Seric */ 208365352Seric #ifdef _CONVEX_SOURCE 208468508Seric extern int optind, opterr, optopt; 208568508Seric extern char *optarg; 208665352Seric #else 208765352Seric int opterr = 1; /* if error message should be printed */ 208865352Seric int optind = 1; /* index into parent argv vector */ 208968470Seric int optopt = 0; /* character checked for validity */ 209068470Seric char *optarg = NULL; /* argument associated with option */ 209168508Seric #endif 209263969Seric 209363969Seric #define BADCH (int)'?' 209463969Seric #define EMSG "" 209563969Seric #define tell(s) if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ 209663969Seric fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);} 209763969Seric 209863969Seric getopt(nargc,nargv,ostr) 209965160Seric int nargc; 210065160Seric char *const *nargv; 210165160Seric const char *ostr; 210263969Seric { 210363969Seric static char *place = EMSG; /* option letter processing */ 210463969Seric static char atend = 0; 210563969Seric register char *oli; /* option letter list index */ 210663969Seric 210763969Seric if (atend) { 210863969Seric atend = 0; 210963969Seric place = EMSG; 211063969Seric } 211163969Seric if(!*place) { /* update scanning pointer */ 211264136Seric if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) { 211363969Seric atend++; 211463969Seric return(EOF); 211563969Seric } 211663969Seric if (*place == '-') { /* found "--" */ 211763969Seric ++optind; 211863969Seric atend++; 211963969Seric return(EOF); 212063969Seric } 212163969Seric } /* option letter okay? */ 212264125Seric if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) { 212364136Seric if (!*place) ++optind; 212463969Seric tell(": illegal option -- "); 212563969Seric } 212663969Seric if (*++oli != ':') { /* don't need argument */ 212763969Seric optarg = NULL; 212863969Seric if (!*place) ++optind; 212963969Seric } 213063969Seric else { /* need an argument */ 213163969Seric if (*place) optarg = place; /* no white space */ 213263969Seric else if (nargc <= ++optind) { /* no arg */ 213363969Seric place = EMSG; 213463969Seric tell(": option requires an argument -- "); 213563969Seric } 213663969Seric else optarg = nargv[optind]; /* white space */ 213763969Seric place = EMSG; 213863969Seric ++optind; 213963969Seric } 214063969Seric return(optopt); /* dump back option letter */ 214163969Seric } 214263969Seric 214363969Seric #endif 214463969Seric /* 214563969Seric ** VFPRINTF, VSPRINTF -- for old 4.3 BSD systems missing a real version 214663969Seric */ 214763969Seric 214863969Seric #ifdef NEEDVPRINTF 214963969Seric 215063969Seric #define MAXARG 16 215163969Seric 215263969Seric vfprintf(fp, fmt, ap) 215363969Seric FILE * fp; 215463969Seric char * fmt; 215563969Seric char ** ap; 215663969Seric { 215763969Seric char * bp[MAXARG]; 215863969Seric int i = 0; 215963969Seric 216063969Seric while (*ap && i < MAXARG) 216163969Seric bp[i++] = *ap++; 216263969Seric fprintf(fp, fmt, bp[0], bp[1], bp[2], bp[3], 216363969Seric bp[4], bp[5], bp[6], bp[7], 216463969Seric bp[8], bp[9], bp[10], bp[11], 216563969Seric bp[12], bp[13], bp[14], bp[15]); 216663969Seric } 216763969Seric 216863969Seric vsprintf(s, fmt, ap) 216963969Seric char * s; 217063969Seric char * fmt; 217163969Seric char ** ap; 217263969Seric { 217363969Seric char * bp[MAXARG]; 217463969Seric int i = 0; 217563969Seric 217663969Seric while (*ap && i < MAXARG) 217763969Seric bp[i++] = *ap++; 217863969Seric sprintf(s, fmt, bp[0], bp[1], bp[2], bp[3], 217963969Seric bp[4], bp[5], bp[6], bp[7], 218063969Seric bp[8], bp[9], bp[10], bp[11], 218163969Seric bp[12], bp[13], bp[14], bp[15]); 218263969Seric } 218363969Seric 218463969Seric #endif 218563969Seric /* 218665220Seric ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use 218765208Seric ** 218865211Seric ** Parameters: 218965211Seric ** shell -- the user's shell from /etc/passwd 219065211Seric ** 219165211Seric ** Returns: 219265211Seric ** TRUE -- if it is ok to use this for unrestricted access. 219365211Seric ** FALSE -- if the shell is restricted. 219465208Seric */ 219565208Seric 219665587Seric #if !HASGETUSERSHELL 219765587Seric 219865587Seric # ifndef _PATH_SHELLS 219965587Seric # define _PATH_SHELLS "/etc/shells" 220065587Seric # endif 220165587Seric 220269762Seric # ifdef _AIX3 220369762Seric # include <userconf.h> 220469762Seric # include <usersec.h> 220569762Seric # endif 220669762Seric 220765587Seric char *DefaultUserShells[] = 220865587Seric { 220968508Seric "/bin/sh", /* standard shell */ 221065587Seric "/usr/bin/sh", 221168508Seric "/bin/csh", /* C shell */ 221265587Seric "/usr/bin/csh", 221365587Seric #ifdef __hpux 221468889Seric # ifdef V4FS 221568889Seric "/usr/bin/rsh", /* restricted Bourne shell */ 221668889Seric "/usr/bin/ksh", /* Korn shell */ 221768889Seric "/usr/bin/rksh", /* restricted Korn shell */ 221868889Seric "/usr/bin/pam", 221968889Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 222068889Seric "/usr/bin/posix/sh", 222168889Seric # else 222268508Seric "/bin/rsh", /* restricted Bourne shell */ 222368508Seric "/bin/ksh", /* Korn shell */ 222468508Seric "/bin/rksh", /* restricted Korn shell */ 222565587Seric "/bin/pam", 222668508Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 222765587Seric "/bin/posix/sh", 222868889Seric # endif 222965211Seric #endif 223068508Seric #ifdef _AIX3 223168508Seric "/bin/ksh", /* Korn shell */ 223268508Seric "/usr/bin/ksh", 223368508Seric "/bin/tsh", /* trusted shell */ 223468508Seric "/usr/bin/tsh", 223568508Seric "/bin/bsh", /* Bourne shell */ 223668508Seric "/usr/bin/bsh", 223768508Seric #endif 223865587Seric NULL 223965587Seric }; 224065587Seric 224165208Seric #endif 224265208Seric 224365747Seric #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" 224465747Seric 224565211Seric bool 224665211Seric usershellok(shell) 224765211Seric char *shell; 224865208Seric { 224965211Seric #if HASGETUSERSHELL 225065211Seric register char *p; 225165211Seric extern char *getusershell(); 225265208Seric 225369505Seric if (shell == NULL || shell[0] == '\0' || ConfigLevel <= 1) 225468457Seric return TRUE; 225568457Seric 225665211Seric setusershell(); 225765211Seric while ((p = getusershell()) != NULL) 225865747Seric if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0) 225965211Seric break; 226065211Seric endusershell(); 226165211Seric return p != NULL; 226265211Seric #else 226369769Seric # if USEGETCONFATTR 226469762Seric auto char *v; 226569762Seric # endif 226665211Seric register FILE *shellf; 226765211Seric char buf[MAXLINE]; 226865208Seric 226968457Seric if (shell == NULL || shell[0] == '\0') 227068457Seric return TRUE; 227168457Seric 227269769Seric # if USEGETCONFATTR 227369769Seric /* 227469769Seric ** Naturally IBM has a "better" idea..... 227569769Seric ** 227669769Seric ** What a crock. This interface isn't documented, it is 227769769Seric ** considered part of the security library (-ls), and it 227869769Seric ** only works if you are running as root (since the list 227969769Seric ** of valid shells is obviously a source of great concern). 228069769Seric ** I recommend that you do NOT define USEGETCONFATTR, 228169769Seric ** especially since you are going to have to set up an 228269769Seric ** /etc/shells anyhow to handle the cases where getconfattr 228369769Seric ** fails. 228469769Seric */ 228569769Seric 228669769Seric if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL) 228769762Seric { 228869769Seric while (*v != '\0') 228969762Seric { 229069762Seric if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0) 229169762Seric return TRUE; 229269762Seric v += strlen(v) + 1; 229369762Seric } 229469769Seric return FALSE; 229569762Seric } 229669762Seric # endif 229769762Seric 229865211Seric shellf = fopen(_PATH_SHELLS, "r"); 229965211Seric if (shellf == NULL) 230065211Seric { 230165211Seric /* no /etc/shells; see if it is one of the std shells */ 230265587Seric char **d; 230365587Seric 230465587Seric for (d = DefaultUserShells; *d != NULL; d++) 230565587Seric { 230665587Seric if (strcmp(shell, *d) == 0) 230765587Seric return TRUE; 230865587Seric } 230965587Seric return FALSE; 231065211Seric } 231165208Seric 231265211Seric while (fgets(buf, sizeof buf, shellf) != NULL) 231365211Seric { 231465211Seric register char *p, *q; 231565208Seric 231665211Seric p = buf; 231765211Seric while (*p != '\0' && *p != '#' && *p != '/') 231865211Seric p++; 231965211Seric if (*p == '#' || *p == '\0') 232065208Seric continue; 232165211Seric q = p; 232265211Seric while (*p != '\0' && *p != '#' && !isspace(*p)) 232365211Seric p++; 232465211Seric *p = '\0'; 232565747Seric if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0) 232665211Seric { 232765211Seric fclose(shellf); 232865211Seric return TRUE; 232965211Seric } 233065208Seric } 233165211Seric fclose(shellf); 233265211Seric return FALSE; 233365211Seric #endif 233465208Seric } 233565208Seric /* 233669801Seric ** FREEDISKSPACE -- see how much free space is on the queue filesystem 233758082Seric ** 233858082Seric ** Only implemented if you have statfs. 233958082Seric ** 234058082Seric ** Parameters: 234164311Seric ** dir -- the directory in question. 234264311Seric ** bsize -- a variable into which the filesystem 234364311Seric ** block size is stored. 234458082Seric ** 234558082Seric ** Returns: 234664311Seric ** The number of bytes free on the queue filesystem. 234764311Seric ** -1 if the statfs call fails. 234864311Seric ** 234964311Seric ** Side effects: 235064311Seric ** Puts the filesystem block size into bsize. 235158082Seric */ 235258082Seric 235365749Seric /* statfs types */ 235465749Seric #define SFS_NONE 0 /* no statfs implementation */ 235565749Seric #define SFS_USTAT 1 /* use ustat */ 235665749Seric #define SFS_4ARGS 2 /* use four-argument statfs call */ 235765749Seric #define SFS_VFS 3 /* use <sys/vfs.h> implementation */ 235865749Seric #define SFS_MOUNT 4 /* use <sys/mount.h> implementation */ 235965749Seric #define SFS_STATFS 5 /* use <sys/statfs.h> implementation */ 236066752Seric #define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */ 236165749Seric 236265749Seric #ifndef SFS_TYPE 236365749Seric # define SFS_TYPE SFS_NONE 236458157Seric #endif 236558157Seric 236665749Seric #if SFS_TYPE == SFS_USTAT 236758157Seric # include <ustat.h> 236858157Seric #endif 236965749Seric #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS 237065749Seric # include <sys/statfs.h> 237158082Seric #endif 237265749Seric #if SFS_TYPE == SFS_VFS 237365749Seric # include <sys/vfs.h> 237465749Seric #endif 237565749Seric #if SFS_TYPE == SFS_MOUNT 237665749Seric # include <sys/mount.h> 237765749Seric #endif 237866752Seric #if SFS_TYPE == SFS_STATVFS 237966752Seric # include <sys/statvfs.h> 238066752Seric #endif 238158082Seric 238264311Seric long 238369801Seric freediskspace(dir, bsize) 238464311Seric char *dir; 238564311Seric long *bsize; 238658082Seric { 238765749Seric #if SFS_TYPE != SFS_NONE 238865749Seric # if SFS_TYPE == SFS_USTAT 238958153Seric struct ustat fs; 239058153Seric struct stat statbuf; 239158366Seric # define FSBLOCKSIZE DEV_BSIZE 239268695Seric # define SFS_BAVAIL f_tfree 239358157Seric # else 239458157Seric # if defined(ultrix) 239558157Seric struct fs_data fs; 239668695Seric # define SFS_BAVAIL fd_bfreen 239768508Seric # define FSBLOCKSIZE 1024L 239858153Seric # else 239966752Seric # if SFS_TYPE == SFS_STATVFS 240066752Seric struct statvfs fs; 240168508Seric # define FSBLOCKSIZE fs.f_frsize 240266752Seric # else 240358082Seric struct statfs fs; 240466752Seric # define FSBLOCKSIZE fs.f_bsize 240563987Seric # endif 240658153Seric # endif 240758133Seric # endif 240868695Seric # ifndef SFS_BAVAIL 240968695Seric # define SFS_BAVAIL f_bavail 241068508Seric # endif 241158082Seric 241265749Seric # if SFS_TYPE == SFS_USTAT 241364311Seric if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 241458157Seric # else 241565749Seric # if SFS_TYPE == SFS_4ARGS 241664311Seric if (statfs(dir, &fs, sizeof fs, 0) == 0) 241758157Seric # else 241868508Seric # if SFS_TYPE == SFS_STATVFS 241968508Seric if (statvfs(dir, &fs) == 0) 242068508Seric # else 242168508Seric # if defined(ultrix) 242268499Seric if (statfs(dir, &fs) > 0) 242368508Seric # else 242464311Seric if (statfs(dir, &fs) == 0) 242568508Seric # endif 242658153Seric # endif 242758133Seric # endif 242858133Seric # endif 242958133Seric { 243064311Seric if (bsize != NULL) 243164311Seric *bsize = FSBLOCKSIZE; 243268695Seric return (fs.SFS_BAVAIL); 243364311Seric } 243464337Seric #endif 243564311Seric return (-1); 243664311Seric } 243764311Seric /* 243869801Seric ** ENOUGHDISKSPACE -- is there enough free space on the queue fs? 243964311Seric ** 244064311Seric ** Only implemented if you have statfs. 244164311Seric ** 244264311Seric ** Parameters: 244364311Seric ** msize -- the size to check against. If zero, we don't yet 244464311Seric ** know how big the message will be, so just check for 244564311Seric ** a "reasonable" amount. 244664311Seric ** 244764311Seric ** Returns: 244864311Seric ** TRUE if there is enough space. 244964311Seric ** FALSE otherwise. 245064311Seric */ 245164311Seric 245264311Seric bool 245369801Seric enoughdiskspace(msize) 245464311Seric long msize; 245564311Seric { 245664311Seric long bfree, bsize; 245764311Seric 245864311Seric if (MinBlocksFree <= 0 && msize <= 0) 245964311Seric { 246058133Seric if (tTd(4, 80)) 246169801Seric printf("enoughdiskspace: no threshold\n"); 246264311Seric return TRUE; 246364311Seric } 246464311Seric 246569801Seric if ((bfree = freediskspace(QueueDir, &bsize)) >= 0) 246664311Seric { 246764311Seric if (tTd(4, 80)) 246869801Seric printf("enoughdiskspace: bavail=%ld, need=%ld\n", 246964311Seric bfree, msize); 247058333Seric 247158333Seric /* convert msize to block count */ 247264311Seric msize = msize / bsize + 1; 247358333Seric if (MinBlocksFree >= 0) 247458333Seric msize += MinBlocksFree; 247558333Seric 247664311Seric if (bfree < msize) 247758090Seric { 247858090Seric #ifdef LOG 247958090Seric if (LogLevel > 0) 248064254Seric syslog(LOG_ALERT, 248164254Seric "%s: low on space (have %ld, %s needs %ld in %s)", 248268508Seric CurEnv->e_id == NULL ? "[NOQUEUE]" : CurEnv->e_id, 248368508Seric bfree, 248468508Seric CurHostName == NULL ? "SMTP-DAEMON" : CurHostName, 248568508Seric msize, QueueDir); 248658090Seric #endif 248758082Seric return FALSE; 248858090Seric } 248958082Seric } 249058082Seric else if (tTd(4, 80)) 249169801Seric printf("enoughdiskspace failure: min=%ld, need=%ld: %s\n", 249258333Seric MinBlocksFree, msize, errstring(errno)); 249358082Seric return TRUE; 249458082Seric } 249558542Seric /* 249658542Seric ** TRANSIENTERROR -- tell if an error code indicates a transient failure 249758542Seric ** 249858542Seric ** This looks at an errno value and tells if this is likely to 249958542Seric ** go away if retried later. 250058542Seric ** 250158542Seric ** Parameters: 250258542Seric ** err -- the errno code to classify. 250358542Seric ** 250458542Seric ** Returns: 250558542Seric ** TRUE if this is probably transient. 250658542Seric ** FALSE otherwise. 250758542Seric */ 250858542Seric 250958542Seric bool 251058542Seric transienterror(err) 251158542Seric int err; 251258542Seric { 251358542Seric switch (err) 251458542Seric { 251558542Seric case EIO: /* I/O error */ 251658542Seric case ENXIO: /* Device not configured */ 251758542Seric case EAGAIN: /* Resource temporarily unavailable */ 251858542Seric case ENOMEM: /* Cannot allocate memory */ 251958542Seric case ENODEV: /* Operation not supported by device */ 252058542Seric case ENFILE: /* Too many open files in system */ 252158542Seric case EMFILE: /* Too many open files */ 252258542Seric case ENOSPC: /* No space left on device */ 252358542Seric #ifdef ETIMEDOUT 252458542Seric case ETIMEDOUT: /* Connection timed out */ 252558542Seric #endif 252658542Seric #ifdef ESTALE 252758542Seric case ESTALE: /* Stale NFS file handle */ 252858542Seric #endif 252958542Seric #ifdef ENETDOWN 253058542Seric case ENETDOWN: /* Network is down */ 253158542Seric #endif 253258542Seric #ifdef ENETUNREACH 253358542Seric case ENETUNREACH: /* Network is unreachable */ 253458542Seric #endif 253558542Seric #ifdef ENETRESET 253658542Seric case ENETRESET: /* Network dropped connection on reset */ 253758542Seric #endif 253858542Seric #ifdef ECONNABORTED 253958542Seric case ECONNABORTED: /* Software caused connection abort */ 254058542Seric #endif 254158542Seric #ifdef ECONNRESET 254258542Seric case ECONNRESET: /* Connection reset by peer */ 254358542Seric #endif 254458542Seric #ifdef ENOBUFS 254558542Seric case ENOBUFS: /* No buffer space available */ 254658542Seric #endif 254758542Seric #ifdef ESHUTDOWN 254858542Seric case ESHUTDOWN: /* Can't send after socket shutdown */ 254958542Seric #endif 255058542Seric #ifdef ECONNREFUSED 255158542Seric case ECONNREFUSED: /* Connection refused */ 255258542Seric #endif 255358542Seric #ifdef EHOSTDOWN 255458542Seric case EHOSTDOWN: /* Host is down */ 255558542Seric #endif 255658542Seric #ifdef EHOSTUNREACH 255758542Seric case EHOSTUNREACH: /* No route to host */ 255858542Seric #endif 255958542Seric #ifdef EDQUOT 256058542Seric case EDQUOT: /* Disc quota exceeded */ 256158542Seric #endif 256258542Seric #ifdef EPROCLIM 256358542Seric case EPROCLIM: /* Too many processes */ 256458542Seric #endif 256558542Seric #ifdef EUSERS 256658542Seric case EUSERS: /* Too many users */ 256758542Seric #endif 256858542Seric #ifdef EDEADLK 256958542Seric case EDEADLK: /* Resource deadlock avoided */ 257058542Seric #endif 257158542Seric #ifdef EISCONN 257258542Seric case EISCONN: /* Socket already connected */ 257358542Seric #endif 257458542Seric #ifdef EINPROGRESS 257558542Seric case EINPROGRESS: /* Operation now in progress */ 257658542Seric #endif 257758542Seric #ifdef EALREADY 257858542Seric case EALREADY: /* Operation already in progress */ 257958542Seric #endif 258058542Seric #ifdef EADDRINUSE 258158542Seric case EADDRINUSE: /* Address already in use */ 258258542Seric #endif 258358542Seric #ifdef EADDRNOTAVAIL 258458542Seric case EADDRNOTAVAIL: /* Can't assign requested address */ 258558542Seric #endif 258666018Seric #ifdef ETXTBSY 258766017Seric case ETXTBSY: /* (Apollo) file locked */ 258866017Seric #endif 258963834Seric #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) 259058542Seric case ENOSR: /* Out of streams resources */ 259158542Seric #endif 259258542Seric return TRUE; 259358542Seric } 259458542Seric 259558542Seric /* nope, must be permanent */ 259658542Seric return FALSE; 259758542Seric } 259858689Seric /* 259964035Seric ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking 260058689Seric ** 260158689Seric ** Parameters: 260258689Seric ** fd -- the file descriptor of the file. 260358689Seric ** filename -- the file name (for error messages). 260464335Seric ** ext -- the filename extension. 260558689Seric ** type -- type of the lock. Bits can be: 260658689Seric ** LOCK_EX -- exclusive lock. 260758689Seric ** LOCK_NB -- non-blocking. 260858689Seric ** 260958689Seric ** Returns: 261058689Seric ** TRUE if the lock was acquired. 261158689Seric ** FALSE otherwise. 261258689Seric */ 261358689Seric 261458689Seric bool 261564335Seric lockfile(fd, filename, ext, type) 261658689Seric int fd; 261758689Seric char *filename; 261864335Seric char *ext; 261958689Seric int type; 262058689Seric { 262165830Seric # if !HASFLOCK 262258689Seric int action; 262358689Seric struct flock lfd; 262464335Seric 262564335Seric if (ext == NULL) 262664335Seric ext = ""; 262769472Seric 262863983Seric bzero(&lfd, sizeof lfd); 262959447Seric if (bitset(LOCK_UN, type)) 263059447Seric lfd.l_type = F_UNLCK; 263159447Seric else if (bitset(LOCK_EX, type)) 263258689Seric lfd.l_type = F_WRLCK; 263358689Seric else 263458689Seric lfd.l_type = F_RDLCK; 263558689Seric 263658689Seric if (bitset(LOCK_NB, type)) 263758689Seric action = F_SETLK; 263858689Seric else 263958689Seric action = F_SETLKW; 264058689Seric 264164264Seric if (tTd(55, 60)) 264264335Seric printf("lockfile(%s%s, action=%d, type=%d): ", 264364335Seric filename, ext, action, lfd.l_type); 264464264Seric 264558689Seric if (fcntl(fd, action, &lfd) >= 0) 264664264Seric { 264764264Seric if (tTd(55, 60)) 264864264Seric printf("SUCCESS\n"); 264958689Seric return TRUE; 265064264Seric } 265158689Seric 265264264Seric if (tTd(55, 60)) 265364264Seric printf("(%s) ", errstring(errno)); 265464264Seric 265564136Seric /* 265664136Seric ** On SunOS, if you are testing using -oQ/tmp/mqueue or 265764136Seric ** -oA/tmp/aliases or anything like that, and /tmp is mounted 265864136Seric ** as type "tmp" (that is, served from swap space), the 265964136Seric ** previous fcntl will fail with "Invalid argument" errors. 266064136Seric ** Since this is fairly common during testing, we will assume 266164136Seric ** that this indicates that the lock is successfully grabbed. 266264136Seric */ 266364136Seric 266464136Seric if (errno == EINVAL) 266564264Seric { 266664264Seric if (tTd(55, 60)) 266764264Seric printf("SUCCESS\n"); 266864136Seric return TRUE; 266964264Seric } 267064136Seric 267158689Seric if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 267264378Seric { 267364378Seric int omode = -1; 267464378Seric # ifdef F_GETFL 267564378Seric int oerrno = errno; 267664378Seric 267764378Seric (void) fcntl(fd, F_GETFL, &omode); 267864378Seric errno = oerrno; 267964378Seric # endif 268064378Seric syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 268164378Seric filename, ext, fd, type, omode, geteuid()); 268264378Seric } 268358689Seric # else 268464335Seric if (ext == NULL) 268564335Seric ext = ""; 268664335Seric 268764264Seric if (tTd(55, 60)) 268864335Seric printf("lockfile(%s%s, type=%o): ", filename, ext, type); 268964264Seric 269058689Seric if (flock(fd, type) >= 0) 269164264Seric { 269264264Seric if (tTd(55, 60)) 269364264Seric printf("SUCCESS\n"); 269458689Seric return TRUE; 269564264Seric } 269658689Seric 269764264Seric if (tTd(55, 60)) 269864264Seric printf("(%s) ", errstring(errno)); 269964264Seric 270058689Seric if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 270164378Seric { 270264378Seric int omode = -1; 270364378Seric # ifdef F_GETFL 270464378Seric int oerrno = errno; 270564378Seric 270664378Seric (void) fcntl(fd, F_GETFL, &omode); 270764378Seric errno = oerrno; 270864378Seric # endif 270964378Seric syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 271064378Seric filename, ext, fd, type, omode, geteuid()); 271164386Seric } 271258689Seric # endif 271364264Seric if (tTd(55, 60)) 271464264Seric printf("FAIL\n"); 271558689Seric return FALSE; 271658689Seric } 271764556Seric /* 271865948Seric ** CHOWNSAFE -- tell if chown is "safe" (executable only by root) 271965948Seric ** 272065948Seric ** Parameters: 272165948Seric ** fd -- the file descriptor to check. 272265948Seric ** 272365948Seric ** Returns: 272465948Seric ** TRUE -- if only root can chown the file to an arbitrary 272565948Seric ** user. 272665948Seric ** FALSE -- if an arbitrary user can give away a file. 272765948Seric */ 272865948Seric 272965948Seric bool 273065948Seric chownsafe(fd) 273165948Seric int fd; 273265948Seric { 273365950Seric #ifdef __hpux 273465948Seric char *s; 273565948Seric int tfd; 273665948Seric uid_t o_uid, o_euid; 273765948Seric gid_t o_gid, o_egid; 273865948Seric bool rval; 273965948Seric struct stat stbuf; 274065948Seric 274165948Seric o_uid = getuid(); 274265948Seric o_euid = geteuid(); 274365948Seric o_gid = getgid(); 274465948Seric o_egid = getegid(); 274565959Seric fstat(fd, &stbuf); 274665948Seric setresuid(stbuf.st_uid, stbuf.st_uid, -1); 274765948Seric setresgid(stbuf.st_gid, stbuf.st_gid, -1); 274865948Seric s = tmpnam(NULL); 274965948Seric tfd = open(s, O_RDONLY|O_CREAT, 0600); 275065974Seric rval = fchown(tfd, DefUid, DefGid) != 0; 275165948Seric close(tfd); 275265948Seric unlink(s); 275369638Seric setresuid(o_uid, o_euid, -1); 275465948Seric setresgid(o_gid, o_egid, -1); 275565948Seric return rval; 275665948Seric #else 275766088Seric # ifdef _POSIX_CHOWN_RESTRICTED 275866088Seric # if _POSIX_CHOWN_RESTRICTED == -1 275966088Seric return FALSE; 276066088Seric # else 276166088Seric return TRUE; 276266088Seric # endif 276366088Seric # else 276466088Seric # ifdef _PC_CHOWN_RESTRICTED 276568508Seric int rval; 276668508Seric 276768508Seric /* 276868508Seric ** Some systems (e.g., SunOS) seem to have the call and the 276968508Seric ** #define _PC_CHOWN_RESTRICTED, but don't actually implement 277068508Seric ** the call. This heuristic checks for that. 277168508Seric */ 277268508Seric 277368508Seric errno = 0; 277468508Seric rval = fpathconf(fd, _PC_CHOWN_RESTRICTED); 277568508Seric if (errno == 0) 277668508Seric return rval > 0; 277768508Seric # endif 277868508Seric # ifdef BSD 277968508Seric return TRUE; 278068499Seric # else 278165948Seric return FALSE; 278265948Seric # endif 278365948Seric # endif 278465948Seric #endif 278565948Seric } 278665948Seric /* 278768508Seric ** RESETLIMITS -- reset system controlled resource limits 278868508Seric ** 278968508Seric ** This is to avoid denial-of-service attacks 279068508Seric ** 279168508Seric ** Parameters: 279268508Seric ** none 279368508Seric ** 279468508Seric ** Returns: 279568508Seric ** none 279668508Seric */ 279768508Seric 279868508Seric #if HASSETRLIMIT 279968508Seric # include <sys/resource.h> 280068508Seric #endif 280168508Seric 280268508Seric void 280368508Seric resetlimits() 280468508Seric { 280568508Seric #if HASSETRLIMIT 280668508Seric struct rlimit lim; 280768508Seric 280868508Seric lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; 280968508Seric (void) setrlimit(RLIMIT_CPU, &lim); 281068508Seric (void) setrlimit(RLIMIT_FSIZE, &lim); 281168508Seric #else 281268508Seric # if HASULIMIT 281368508Seric (void) ulimit(2, 0x3fffff); 281468508Seric # endif 281568508Seric #endif 281668508Seric } 281768508Seric /* 281864556Seric ** GETCFNAME -- return the name of the .cf file. 281964556Seric ** 282064556Seric ** Some systems (e.g., NeXT) determine this dynamically. 282164556Seric */ 282264556Seric 282364556Seric char * 282464556Seric getcfname() 282564556Seric { 282669748Seric #ifdef TRY_VERSIONED_CF_NAME 282768842Seric int i; 282868842Seric static char cbuf[200]; 282969748Seric #endif 283068842Seric 283164556Seric if (ConfFile != NULL) 283264556Seric return ConfFile; 283365214Seric #ifdef NETINFO 283465214Seric { 283565214Seric extern char *ni_propval(); 283665214Seric char *cflocation; 283765214Seric 283868508Seric cflocation = ni_propval("/locations", NULL, "sendmail", 283968508Seric "sendmail.cf", '\0'); 284065214Seric if (cflocation != NULL) 284165214Seric return cflocation; 284265214Seric } 284365214Seric #endif 284468842Seric 284569396Seric #ifdef TRY_VERSIONED_CF_NAME 284668842Seric /* 284768842Seric ** Try sendmail.8.6.12.cf, then sendmail.8.6.cf, then 284868842Seric ** sendmail.8.cf, and finally sendmail.cf. 284968842Seric ** 285068842Seric ** I suppose it should really try a search path here -- 285168842Seric ** e.g., /etc/sendmail.cf, /etc/mail/sendmail.cf, 285268842Seric ** /usr/lib/sendmail.cf, and so forth. 285368842Seric */ 285468842Seric 285568842Seric strcpy(cbuf, _PATH_SENDMAILCF); 285668842Seric i = strlen(cbuf); 285768842Seric if (strcmp(&cbuf[i - 3], ".cf") == 0) 285868842Seric { 285968842Seric char *p; 286068842Seric extern char Version[]; 286168842Seric 286268842Seric strcpy(&cbuf[i - 2], Version); 286368842Seric p = strchr(&cbuf[i - 2], '/'); 286468842Seric if (p != NULL) 286568842Seric *p = '\0'; 286668842Seric p = &cbuf[strlen(cbuf)]; 286768842Seric do 286868842Seric { 286968842Seric int fd; 287068842Seric 287168842Seric strcpy(p, ".cf"); 287268842Seric if ((fd = open(cbuf, O_RDONLY, 0)) >= 0) 287368842Seric { 287468842Seric close(fd); 287568842Seric return cbuf; 287668842Seric } 287768842Seric *p = '\0'; 287868842Seric } while ((p = strrchr(&cbuf[i - 2], '.')) != NULL); 287968842Seric } 288069396Seric #endif 288164556Seric return _PATH_SENDMAILCF; 288264556Seric } 288364718Seric /* 288464718Seric ** SETVENDOR -- process vendor code from V configuration line 288564718Seric ** 288664718Seric ** Parameters: 288764718Seric ** vendor -- string representation of vendor. 288864718Seric ** 288964718Seric ** Returns: 289064718Seric ** TRUE -- if ok. 289164718Seric ** FALSE -- if vendor code could not be processed. 289264926Seric ** 289364926Seric ** Side Effects: 289464926Seric ** It is reasonable to set mode flags here to tweak 289564926Seric ** processing in other parts of the code if necessary. 289664926Seric ** For example, if you are a vendor that uses $%y to 289764926Seric ** indicate YP lookups, you could enable that here. 289864718Seric */ 289964718Seric 290064718Seric bool 290164718Seric setvendor(vendor) 290264718Seric char *vendor; 290364718Seric { 290464926Seric if (strcasecmp(vendor, "Berkeley") == 0) 290568508Seric { 290668508Seric VendorCode = VENDOR_BERKELEY; 290764926Seric return TRUE; 290868508Seric } 290964926Seric 291064926Seric /* add vendor extensions here */ 291164926Seric 291268508Seric #ifdef SUN_EXTENSIONS 291368508Seric if (strcasecmp(vendor, "Sun") == 0) 291468508Seric { 291568508Seric VendorCode = VENDOR_SUN; 291668508Seric return TRUE; 291768508Seric } 291868508Seric #endif 291968508Seric 292064926Seric return FALSE; 292164718Seric } 292264816Seric /* 292369510Seric ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults 292469510Seric ** 292569510Seric ** Vendor_pre_defaults is called before reading the configuration 292669510Seric ** file; vendor_post_defaults is called immediately after. 292769510Seric ** 292869510Seric ** Parameters: 292969510Seric ** e -- the global environment to initialize. 293069510Seric ** 293169510Seric ** Returns: 293269510Seric ** none. 293369510Seric */ 293469510Seric 293569510Seric void 293669510Seric vendor_pre_defaults(e) 293769510Seric ENVELOPE *e; 293869510Seric { 293969510Seric } 294069510Seric 294169510Seric 294269510Seric void 294369510Seric vendor_post_defaults(e) 294469510Seric ENVELOPE *e; 294569510Seric { 294669510Seric } 294769510Seric /* 294864816Seric ** STRTOL -- convert string to long integer 294964816Seric ** 295064816Seric ** For systems that don't have it in the C library. 295166161Seric ** 295266161Seric ** This is taken verbatim from the 4.4-Lite C library. 295364816Seric */ 295464816Seric 295564816Seric #ifdef NEEDSTRTOL 295664816Seric 295766161Seric #if defined(LIBC_SCCS) && !defined(lint) 295866161Seric static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; 295966161Seric #endif /* LIBC_SCCS and not lint */ 296066161Seric 296166161Seric #include <limits.h> 296266161Seric 296366161Seric /* 296466161Seric * Convert a string to a long integer. 296566161Seric * 296666161Seric * Ignores `locale' stuff. Assumes that the upper and lower case 296766161Seric * alphabets and digits are each contiguous. 296866161Seric */ 296966161Seric 297064816Seric long 297166161Seric strtol(nptr, endptr, base) 297266161Seric const char *nptr; 297366161Seric char **endptr; 297466161Seric register int base; 297564816Seric { 297666161Seric register const char *s = nptr; 297766161Seric register unsigned long acc; 297866161Seric register int c; 297966161Seric register unsigned long cutoff; 298066161Seric register int neg = 0, any, cutlim; 298164816Seric 298266161Seric /* 298366161Seric * Skip white space and pick up leading +/- sign if any. 298466161Seric * If base is 0, allow 0x for hex and 0 for octal, else 298566161Seric * assume decimal; if base is already 16, allow 0x. 298666161Seric */ 298766161Seric do { 298866161Seric c = *s++; 298966161Seric } while (isspace(c)); 299066161Seric if (c == '-') { 299166161Seric neg = 1; 299266161Seric c = *s++; 299366161Seric } else if (c == '+') 299466161Seric c = *s++; 299566161Seric if ((base == 0 || base == 16) && 299666161Seric c == '0' && (*s == 'x' || *s == 'X')) { 299766161Seric c = s[1]; 299866161Seric s += 2; 299966161Seric base = 16; 300066161Seric } 300166161Seric if (base == 0) 300266161Seric base = c == '0' ? 8 : 10; 300364816Seric 300466161Seric /* 300566161Seric * Compute the cutoff value between legal numbers and illegal 300666161Seric * numbers. That is the largest legal value, divided by the 300766161Seric * base. An input number that is greater than this value, if 300866161Seric * followed by a legal input character, is too big. One that 300966161Seric * is equal to this value may be valid or not; the limit 301066161Seric * between valid and invalid numbers is then based on the last 301166161Seric * digit. For instance, if the range for longs is 301266161Seric * [-2147483648..2147483647] and the input base is 10, 301366161Seric * cutoff will be set to 214748364 and cutlim to either 301466161Seric * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 301566161Seric * a value > 214748364, or equal but the next digit is > 7 (or 8), 301666161Seric * the number is too big, and we will return a range error. 301766161Seric * 301866161Seric * Set any if any `digits' consumed; make it negative to indicate 301966161Seric * overflow. 302066161Seric */ 302166161Seric cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; 302266161Seric cutlim = cutoff % (unsigned long)base; 302366161Seric cutoff /= (unsigned long)base; 302466161Seric for (acc = 0, any = 0;; c = *s++) { 302566161Seric if (isdigit(c)) 302666161Seric c -= '0'; 302766161Seric else if (isalpha(c)) 302866161Seric c -= isupper(c) ? 'A' - 10 : 'a' - 10; 302966161Seric else 303066161Seric break; 303166161Seric if (c >= base) 303266161Seric break; 303366161Seric if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) 303466161Seric any = -1; 303566161Seric else { 303666161Seric any = 1; 303766161Seric acc *= base; 303866161Seric acc += c; 303964816Seric } 304064816Seric } 304166161Seric if (any < 0) { 304266161Seric acc = neg ? LONG_MIN : LONG_MAX; 304366161Seric errno = ERANGE; 304466161Seric } else if (neg) 304566161Seric acc = -acc; 304666161Seric if (endptr != 0) 304766161Seric *endptr = (char *)(any ? s - 1 : nptr); 304866161Seric return (acc); 304964816Seric } 305064816Seric 305164816Seric #endif 305264841Seric /* 305369679Seric ** STRSTR -- find first substring in string 305469679Seric ** 305569679Seric ** Parameters: 305669679Seric ** big -- the big (full) string. 305769679Seric ** little -- the little (sub) string. 305869679Seric ** 305969679Seric ** Returns: 306069679Seric ** A pointer to the first instance of little in big. 306169679Seric ** big if little is the null string. 306269679Seric ** NULL if little is not contained in big. 306369679Seric */ 306469679Seric 306569679Seric #ifdef NEEDSTRSTR 306669679Seric 306769679Seric char * 306869679Seric strstr(big, little) 306969679Seric char *big; 307069679Seric char *little; 307169679Seric { 307269679Seric register char *p = big; 307369679Seric int l; 307469679Seric 307569679Seric if (*little == '\0') 307669679Seric return big; 307769679Seric l = strlen(little); 307869679Seric 307969679Seric while ((p = strchr(p, *little)) != NULL) 308069679Seric { 308169679Seric if (strncmp(p, little, l) == 0) 308269679Seric return p; 308369679Seric p++; 308469679Seric } 308569679Seric return NULL; 308669679Seric } 308769679Seric 308869679Seric #endif 308969679Seric /* 309068693Seric ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX 309164841Seric ** 309268693Seric ** Some operating systems have wierd problems with the gethostbyXXX 309368693Seric ** routines. For example, Solaris versions at least through 2.3 309468693Seric ** don't properly deliver a canonical h_name field. This tries to 309568693Seric ** work around these problems. 309664841Seric */ 309764841Seric 309864841Seric struct hostent * 309968693Seric sm_gethostbyname(name) 310068707Seric char *name; 310164841Seric { 310269777Seric struct hostent *h; 310369654Seric #if defined(SOLARIS) && SOLARIS < 204 || defined(sony_news) && defined(__svr4) 310468693Seric extern int h_errno; 310568693Seric 310668508Seric # if SOLARIS == 203 310764841Seric static struct hostent hp; 310864841Seric static char buf[1000]; 310964841Seric extern struct hostent *_switch_gethostbyname_r(); 311064841Seric 311169777Seric if (tTd(61, 10)) 311269777Seric printf("_switch_gethostbyname_r(%s)... ", name); 311369777Seric h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 311464841Seric # else 311565009Seric extern struct hostent *__switch_gethostbyname(); 311665009Seric 311769777Seric if (tTd(61, 10)) 311869777Seric printf("__switch_gethostbyname(%s)... ", name); 311969777Seric h = __switch_gethostbyname(name); 312064841Seric # endif 312168693Seric #else 312269777Seric # if defined(NIS) 312369687Seric int nmaps; 312469687Seric char *maptype[MAXMAPSTACK]; 312569687Seric short mapreturn[MAXMAPACTIONS]; 312669687Seric char hbuf[MAXNAME]; 312769777Seric # endif 312869687Seric 312969777Seric if (tTd(61, 10)) 313069777Seric printf("gethostbyname(%s)... ", name); 313169687Seric h = gethostbyname(name); 313269687Seric # if defined(NIS) 313369777Seric if (h == NULL) 313469687Seric { 313569777Seric if (tTd(61, 10)) 313669777Seric printf("failure\n"); 313769687Seric 313869777Seric nmaps = switch_map_find("hosts", maptype, mapreturn); 313969777Seric while (--nmaps >= 0) 314069777Seric if (strcmp(maptype[nmaps], "nis") == 0) 314169777Seric break; 314269777Seric if (nmaps >= 0) 314369777Seric { 314469777Seric /* try short name */ 314569777Seric if (strlen(name) > sizeof hbuf - 1) 314669777Seric return NULL; 314769777Seric strcpy(hbuf, name); 314869777Seric shorten_hostname(hbuf); 314969777Seric 315069777Seric /* if it hasn't been shortened, there's no point */ 315169777Seric if (strcmp(hbuf, name) != 0) 315269777Seric { 315369777Seric if (tTd(61, 10)) 315469777Seric printf("gethostbyname(%s)... ", hbuf); 315569777Seric h = gethostbyname(hbuf); 315669777Seric } 315769777Seric } 315869687Seric } 315969687Seric # endif 316069777Seric #endif 316169777Seric if (tTd(61, 10)) 316269777Seric { 316369777Seric if (h == NULL) 316469777Seric printf("failure\n"); 316569777Seric else 316669777Seric printf("%s\n", h->h_name); 316769777Seric } 316869687Seric return h; 316964841Seric } 317064841Seric 317164841Seric struct hostent * 317268693Seric sm_gethostbyaddr(addr, len, type) 317368707Seric char *addr; 317464841Seric int len; 317564841Seric int type; 317664841Seric { 317768693Seric #if defined(SOLARIS) && SOLARIS < 204 317868693Seric extern int h_errno; 317968693Seric 318068508Seric # if SOLARIS == 203 318164841Seric static struct hostent hp; 318264841Seric static char buf[1000]; 318364841Seric extern struct hostent *_switch_gethostbyaddr_r(); 318464841Seric 318564841Seric return _switch_gethostbyaddr_r(addr, len, type, &hp, buf, sizeof(buf), &h_errno); 318664841Seric # else 318765009Seric extern struct hostent *__switch_gethostbyaddr(); 318865009Seric 318964841Seric return __switch_gethostbyaddr(addr, len, type); 319064841Seric # endif 319168693Seric #else 319268693Seric return gethostbyaddr(addr, len, type); 319368693Seric #endif 319464841Seric } 319568693Seric /* 319668693Seric ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid 319768693Seric */ 319864841Seric 319968693Seric struct passwd * 320068693Seric sm_getpwnam(user) 320168704Seric char *user; 320268693Seric { 320368693Seric return getpwnam(user); 320468693Seric } 320568693Seric 320668693Seric struct passwd * 320768693Seric sm_getpwuid(uid) 320868693Seric uid_t uid; 320968693Seric { 321068693Seric return getpwuid(uid); 321168693Seric } 321265214Seric /* 321369472Seric ** LOAD_IF_NAMES -- load interface-specific names into $=w 321469472Seric ** 321569472Seric ** Parameters: 321669472Seric ** none. 321769472Seric ** 321869472Seric ** Returns: 321969472Seric ** none. 322069472Seric ** 322169472Seric ** Side Effects: 322269472Seric ** Loads $=w with the names of all the interfaces. 322369472Seric */ 322469472Seric 322569472Seric #ifdef SIOCGIFCONF 322669565Seric struct rtentry; 322769565Seric struct mbuf; 322869472Seric # include <arpa/inet.h> 322969562Seric # include <sys/time.h> 323069472Seric # include <net/if.h> 323169472Seric #endif 323269472Seric 323369472Seric void 323469472Seric load_if_names() 323569472Seric { 323669472Seric #ifdef SIOCGIFCONF 323769472Seric int s; 323869516Seric int i; 323969472Seric struct ifconf ifc; 324069472Seric char interfacebuf[1024]; 324169472Seric 324269472Seric s = socket(AF_INET, SOCK_DGRAM, 0); 324369472Seric if (s == -1) 324469472Seric return; 324569472Seric 324669472Seric /* get the list of known IP address from the kernel */ 324769472Seric ifc.ifc_buf = interfacebuf; 324869516Seric ifc.ifc_len = sizeof interfacebuf; 324969472Seric if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) 325069472Seric { 325169472Seric if (tTd(0, 4)) 325269472Seric printf("SIOGIFCONF failed: %s\n", errstring(errno)); 325369516Seric close(s); 325469472Seric return; 325569472Seric } 325669516Seric close(s); 325769472Seric 325869472Seric /* scan the list of IP address */ 325969472Seric if (tTd(0, 4)) 326069472Seric printf("scanning for interface specific names, ifc_len=%d\n", 326169472Seric ifc.ifc_len); 326269472Seric 326369516Seric for (i = 0; i < ifc.ifc_len; ) 326469516Seric { 326569516Seric struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i]; 326669516Seric struct sockaddr *sa = &ifr->ifr_addr; 326769472Seric struct in_addr ia; 326869516Seric struct hostent *hp; 326969472Seric char ip_addr[256]; 327069516Seric extern char *inet_ntoa(); 327169516Seric extern struct hostent *gethostbyaddr(); 327269472Seric 327369516Seric #ifdef BSD4_4_SOCKADDR 327469516Seric if (sa->sa_len > sizeof ifr->ifr_addr) 327569516Seric i += sizeof ifr->ifr_name + sa->sa_len; 327669516Seric else 327769516Seric #endif 327869516Seric i += sizeof *ifr; 327969516Seric 328069472Seric if (tTd(0, 20)) 328169516Seric printf("%s\n", anynet_ntoa((SOCKADDR *) sa)); 328269472Seric 328369472Seric if (ifr->ifr_addr.sa_family != AF_INET) 328469472Seric continue; 328569472Seric 328669472Seric /* extract IP address from the list*/ 328769516Seric ia = (((struct sockaddr_in *) sa)->sin_addr); 328869472Seric 328969472Seric /* save IP address in text from */ 329069472Seric (void) sprintf(ip_addr, "[%s]", 329169516Seric inet_ntoa(((struct sockaddr_in *) sa)->sin_addr)); 329269472Seric if (!wordinclass(ip_addr, 'w')) 329369472Seric { 329469472Seric setclass('w', ip_addr); 329569472Seric if (tTd(0, 4)) 329669472Seric printf("\ta.k.a.: %s\n", ip_addr); 329769472Seric } 329869472Seric 329969472Seric /* skip "loopback" interface "lo" */ 330069472Seric if (strcmp("lo0", ifr->ifr_name) == 0) 330169472Seric continue; 330269472Seric 330369472Seric /* lookup name with IP address */ 330469472Seric hp = sm_gethostbyaddr((char *) &ia, sizeof(ia), AF_INET); 330569472Seric if (hp == NULL) 330669472Seric { 330769472Seric syslog(LOG_CRIT, "gethostbyaddr() failed for %s\n", 330869472Seric inet_ntoa(ia)); 330969472Seric continue; 331069472Seric } 331169472Seric 331269472Seric /* save its cname */ 331369472Seric if (!wordinclass(hp->h_name, 'w')) 331469472Seric { 331569472Seric setclass('w', hp->h_name); 331669472Seric if (tTd(0, 4)) 331769472Seric printf("\ta.k.a.: %s\n", hp->h_name); 331869472Seric } 331969472Seric 332069472Seric /* save all it aliases name */ 332169472Seric while (*hp->h_aliases) 332269472Seric { 332369472Seric if (!wordinclass(*hp->h_aliases, 'w')) 332469472Seric { 332569472Seric setclass('w', *hp->h_aliases); 332669472Seric if (tTd(0, 4)) 332769472Seric printf("\ta.k.a.: %s\n", *hp->h_aliases); 332869472Seric } 332969472Seric hp->h_aliases++; 333069472Seric } 333169472Seric } 333269472Seric #endif 333369472Seric } 333469472Seric /* 333565214Seric ** NI_PROPVAL -- netinfo property value lookup routine 333665214Seric ** 333765214Seric ** Parameters: 333868508Seric ** keydir -- the Netinfo directory name in which to search 333968508Seric ** for the key. 334068508Seric ** keyprop -- the name of the property in which to find the 334168508Seric ** property we are interested. Defaults to "name". 334268508Seric ** keyval -- the value for which we are really searching. 334368508Seric ** valprop -- the property name for the value in which we 334468508Seric ** are interested. 334568508Seric ** sepchar -- if non-nil, this can be multiple-valued, and 334668508Seric ** we should return a string separated by this 334768508Seric ** character. 334865214Seric ** 334965214Seric ** Returns: 335065214Seric ** NULL -- if: 335165214Seric ** 1. the directory is not found 335265214Seric ** 2. the property name is not found 335365214Seric ** 3. the property contains multiple values 335465214Seric ** 4. some error occured 335565214Seric ** else -- the location of the config file. 335665214Seric ** 335768508Seric ** Example: 335868508Seric ** To search for an alias value, use: 335968508Seric ** ni_propval("/aliases", "name", aliasname, "members", ',') 336068508Seric ** 336165214Seric ** Notes: 336265214Seric ** Caller should free the return value of ni_proval 336365214Seric */ 336465214Seric 336565214Seric #ifdef NETINFO 336665214Seric 336765214Seric # include <netinfo/ni.h> 336865214Seric 336965214Seric # define LOCAL_NETINFO_DOMAIN "." 337065214Seric # define PARENT_NETINFO_DOMAIN ".." 337165214Seric # define MAX_NI_LEVELS 256 337265214Seric 337365214Seric char * 337468508Seric ni_propval(keydir, keyprop, keyval, valprop, sepchar) 337568508Seric char *keydir; 337668508Seric char *keyprop; 337768508Seric char *keyval; 337868508Seric char *valprop; 337968508Seric char sepchar; 338065214Seric { 338165820Seric char *propval = NULL; 338265214Seric int i; 338368508Seric int j, alen; 338465214Seric void *ni = NULL; 338565214Seric void *lastni = NULL; 338665214Seric ni_status nis; 338765214Seric ni_id nid; 338865214Seric ni_namelist ninl; 338968508Seric register char *p; 339068508Seric char keybuf[1024]; 339165214Seric 339265214Seric /* 339368508Seric ** Create the full key from the two parts. 339468508Seric ** 339568508Seric ** Note that directory can end with, e.g., "name=" to specify 339668508Seric ** an alternate search property. 339768508Seric */ 339868508Seric 339968508Seric i = strlen(keydir) + strlen(keyval) + 2; 340068508Seric if (keyprop != NULL) 340168508Seric i += strlen(keyprop) + 1; 340268508Seric if (i > sizeof keybuf) 340368508Seric return NULL; 340468508Seric strcpy(keybuf, keydir); 340568508Seric strcat(keybuf, "/"); 340668508Seric if (keyprop != NULL) 340768508Seric { 340868508Seric strcat(keybuf, keyprop); 340968508Seric strcat(keybuf, "="); 341068508Seric } 341168508Seric strcat(keybuf, keyval); 341268508Seric 341368508Seric /* 341465214Seric ** If the passed directory and property name are found 341565214Seric ** in one of netinfo domains we need to search (starting 341665214Seric ** from the local domain moving all the way back to the 341765214Seric ** root domain) set propval to the property's value 341865214Seric ** and return it. 341965214Seric */ 342065214Seric 342165214Seric for (i = 0; i < MAX_NI_LEVELS; ++i) 342265214Seric { 342365214Seric if (i == 0) 342465214Seric { 342565214Seric nis = ni_open(NULL, LOCAL_NETINFO_DOMAIN, &ni); 342665214Seric } 342765214Seric else 342865214Seric { 342965214Seric if (lastni != NULL) 343065214Seric ni_free(lastni); 343165214Seric lastni = ni; 343265214Seric nis = ni_open(lastni, PARENT_NETINFO_DOMAIN, &ni); 343365214Seric } 343465214Seric 343565214Seric /* 343665214Seric ** Don't bother if we didn't get a handle on a 343765214Seric ** proper domain. This is not necessarily an error. 343865214Seric ** We would get a positive ni_status if, for instance 343965214Seric ** we never found the directory or property and tried 344065214Seric ** to open the parent of the root domain! 344165214Seric */ 344265214Seric 344365214Seric if (nis != 0) 344465214Seric break; 344565214Seric 344665214Seric /* 344765214Seric ** Find the path to the server information. 344865214Seric */ 344965214Seric 345068508Seric if (ni_pathsearch(ni, &nid, keybuf) != 0) 345165214Seric continue; 345265214Seric 345365214Seric /* 345468508Seric ** Find associated value information. 345565214Seric */ 345665214Seric 345768508Seric if (ni_lookupprop(ni, &nid, valprop, &ninl) != 0) 345865214Seric continue; 345965214Seric 346065214Seric /* 346168508Seric ** See if we have an acceptable number of values. 346265214Seric */ 346365214Seric 346468508Seric if (ninl.ni_namelist_len <= 0) 346568508Seric continue; 346668508Seric 346768508Seric if (sepchar == '\0' && ninl.ni_namelist_len > 1) 346865214Seric { 346968508Seric ni_namelist_free(&ninl); 347068508Seric continue; 347165214Seric } 347268508Seric 347369472Seric /* 347468508Seric ** Calculate number of bytes needed and build result 347568508Seric */ 347668508Seric 347768508Seric alen = 1; 347868508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 347968508Seric alen += strlen(ninl.ni_namelist_val[j]) + 1; 348068508Seric propval = p = xalloc(alen); 348168508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 348268508Seric { 348368508Seric strcpy(p, ninl.ni_namelist_val[j]); 348468508Seric p += strlen(p); 348568508Seric *p++ = sepchar; 348669472Seric } 348768508Seric *--p = '\0'; 348868508Seric 348968508Seric ni_namelist_free(&ninl); 349065214Seric } 349165214Seric 349265214Seric /* 349365214Seric ** Clean up. 349465214Seric */ 349565214Seric 349665214Seric if (ni != NULL) 349765214Seric ni_free(ni); 349865214Seric if (lastni != NULL && ni != lastni) 349965214Seric ni_free(lastni); 350065214Seric 350165214Seric return propval; 350265214Seric } 350365214Seric 350465214Seric #endif /* NETINFO */ 350565504Seric /* 350665504Seric ** HARD_SYSLOG -- call syslog repeatedly until it works 350765504Seric ** 350865504Seric ** Needed on HP-UX, which apparently doesn't guarantee that 350965504Seric ** syslog succeeds during interrupt handlers. 351065504Seric */ 351165504Seric 351265504Seric #ifdef __hpux 351365504Seric 351465504Seric # define MAXSYSLOGTRIES 100 351565504Seric # undef syslog 351665504Seric 351769758Seric # ifdef __STDC__ 351869748Seric void 351965504Seric hard_syslog(int pri, char *msg, ...) 352065504Seric # else 352165504Seric hard_syslog(pri, msg, va_alist) 352265504Seric int pri; 352365504Seric char *msg; 352465504Seric va_dcl 352565504Seric # endif 352665504Seric { 352765504Seric int i; 352865504Seric char buf[SYSLOG_BUFSIZE * 2]; 352965504Seric VA_LOCAL_DECL; 353065504Seric 353165504Seric VA_START(msg); 353265504Seric vsprintf(buf, msg, ap); 353365504Seric VA_END; 353465504Seric 353565504Seric for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, "%s", buf) < 0; ) 353665504Seric continue; 353765504Seric } 353865504Seric 353965504Seric #endif 354068696Seric /* 354168696Seric ** LOCAL_HOSTNAME_LENGTH 354268696Seric ** 354368696Seric ** This is required to get sendmail to compile against BIND 4.9.x 354468696Seric ** on Ultrix. 354568696Seric */ 354668696Seric 354768696Seric #if defined(ultrix) && NAMED_BIND 354868696Seric 354968696Seric # include <resolv.h> 355068696Seric # if __RES >= 19931104 355168696Seric 355268696Seric int 355368696Seric local_hostname_length(hostname) 355468696Seric char *hostname; 355568696Seric { 355668696Seric int len_host, len_domain; 355768696Seric 355868696Seric if (!*_res.defdname) 355968696Seric res_init(); 356068696Seric len_host = strlen(hostname); 356168696Seric len_domain = strlen(_res.defdname); 356268696Seric if (len_host > len_domain && 356368696Seric (strcasecmp(hostname + len_host - len_domain,_res.defdname) == 0) && 356468696Seric hostname[len_host - len_domain - 1] == '.') 356568696Seric return len_host - len_domain - 1; 356668696Seric else 356768696Seric return 0; 356868696Seric } 356968696Seric 357068696Seric # endif 357168696Seric #endif 357268741Seric /* 357368741Seric ** Compile-Time options 357468741Seric */ 357568741Seric 357668741Seric char *CompileOptions[] = 357768741Seric { 357868741Seric #if HESIOD 357968741Seric "HESIOD", 358068741Seric #endif 358168741Seric #if LOG 358268741Seric "LOG", 358368741Seric #endif 358468741Seric #if MATCHGECOS 358568741Seric "MATCHGECOS", 358668741Seric #endif 358768741Seric #if NAMED_BIND 358868741Seric "NAMED_BIND", 358968741Seric #endif 359068741Seric #if NDBM 359168741Seric "NDBM", 359268741Seric #endif 359368741Seric #if NETINET 359468741Seric "NETINET", 359568741Seric #endif 359668741Seric #if NETINFO 359768741Seric "NETINFO", 359868741Seric #endif 359968741Seric #if NETISO 360068741Seric "NETISO", 360168741Seric #endif 360268741Seric #if NETNS 360368741Seric "NETNS", 360468741Seric #endif 360568741Seric #if NETUNIX 360668741Seric "NETUNIX", 360768741Seric #endif 360868741Seric #if NETX25 360968741Seric "NETX25", 361068741Seric #endif 361168741Seric #if NEWDB 361268741Seric "NEWDB", 361368741Seric #endif 361468741Seric #if NIS 361568741Seric "NIS", 361668741Seric #endif 361769518Seric #if NISPLUS 361869518Seric "NISPLUS", 361969518Seric #endif 362068741Seric #if SCANF 362168741Seric "SCANF", 362268741Seric #endif 362368741Seric #if SUID_ROOT_FILES_OK 362468741Seric "SUID_ROOT_FILES_OK", 362568741Seric #endif 362668741Seric #if USERDB 362768741Seric "USERDB", 362868741Seric #endif 362968741Seric #if XDEBUG 363068741Seric "XDEBUG", 363168741Seric #endif 363268741Seric #if XLA 363368741Seric "XLA", 363468741Seric #endif 363568741Seric NULL 363668741Seric }; 3637*69817Seric 3638*69817Seric 3639*69817Seric /* 3640*69817Seric ** OS compile options. 3641*69817Seric */ 3642*69817Seric 3643*69817Seric char *OsCompileOptions[] = 3644*69817Seric { 3645*69817Seric #if HASFLOCK 3646*69817Seric "HASFLOCK", 3647*69817Seric #endif 3648*69817Seric #if HASGETUSERSHELL 3649*69817Seric "HASGETUSERSHELL", 3650*69817Seric #endif 3651*69817Seric #if HASINITGROUPS 3652*69817Seric "HASINITGROUPS", 3653*69817Seric #endif 3654*69817Seric #if HASLSTAT 3655*69817Seric "HASLSTAT", 3656*69817Seric #endif 3657*69817Seric #if HASSETREUID 3658*69817Seric "HASSETREUID", 3659*69817Seric #endif 3660*69817Seric #if HASSETSID 3661*69817Seric "HASSETSID", 3662*69817Seric #endif 3663*69817Seric #if HASSETVBUF 3664*69817Seric "HASSETVBUF", 3665*69817Seric #endif 3666*69817Seric #if HASUNAME 3667*69817Seric "HASUNAME", 3668*69817Seric #endif 3669*69817Seric #if IDENTPROTO 3670*69817Seric "IDENTPROTO", 3671*69817Seric #endif 3672*69817Seric #if IP_SRCROUTE 3673*69817Seric "IP_SRCROUTE", 3674*69817Seric #endif 3675*69817Seric #if SYS5SETPGRP 3676*69817Seric "SYS5SETPGRP", 3677*69817Seric #endif 3678*69817Seric #if SYSTEM5 3679*69817Seric "SYSTEM5", 3680*69817Seric #endif 3681*69817Seric #if USESETEUID 3682*69817Seric "USESETEUID", 3683*69817Seric #endif 3684*69817Seric NULL 3685*69817Seric }; 3686