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*69832Seric static char sccsid[] = "@(#)conf.c 8.191 (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); 73269830Seric fclose(fp); 73369830Seric return svcno; 73468508Seric } 73569830Seric 73669830Seric /* service was not found -- use compiled in default */ 73768508Seric fclose(fp); 73868508Seric } 73968508Seric #endif 74068508Seric 74168508Seric /* if the service file doesn't work, use an absolute fallback */ 74268508Seric punt: 74369401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 74469401Seric mapreturn[svcno] = 0; 74569401Seric svcno = 0; 74668508Seric if (strcmp(service, "aliases") == 0) 74768508Seric { 74868628Seric maptype[svcno++] = "files"; 74968628Seric #ifdef AUTO_NIS_ALIASES 75068628Seric # ifdef NISPLUS 75168628Seric maptype[svcno++] = "nisplus"; 75268628Seric # endif 75368628Seric # ifdef NIS 75468628Seric maptype[svcno++] = "nis"; 75568628Seric # endif 75668628Seric #endif 75768628Seric return svcno; 75868508Seric } 75968508Seric if (strcmp(service, "hosts") == 0) 76068508Seric { 76168508Seric # if NAMED_BIND 76268508Seric maptype[svcno++] = "dns"; 76368508Seric # else 76468508Seric # if defined(sun) && !defined(BSD) && !defined(SOLARIS) 76568508Seric /* SunOS */ 76668508Seric maptype[svcno++] = "nis"; 76768508Seric # endif 76868508Seric # endif 76968508Seric maptype[svcno++] = "files"; 77068508Seric return svcno; 77168508Seric } 77268508Seric return -1; 77368508Seric } 77468508Seric /* 7759369Seric ** USERNAME -- return the user id of the logged in user. 7769369Seric ** 7779369Seric ** Parameters: 7789369Seric ** none. 7799369Seric ** 7809369Seric ** Returns: 7819369Seric ** The login name of the logged in user. 7829369Seric ** 7839369Seric ** Side Effects: 7849369Seric ** none. 7859369Seric ** 7869369Seric ** Notes: 7879369Seric ** The return value is statically allocated. 7889369Seric */ 7899369Seric 7909369Seric char * 7919369Seric username() 7929369Seric { 79317469Seric static char *myname = NULL; 7949369Seric extern char *getlogin(); 79519904Smiriam register struct passwd *pw; 7969369Seric 79717469Seric /* cache the result */ 79817469Seric if (myname == NULL) 79917469Seric { 80017469Seric myname = getlogin(); 80117469Seric if (myname == NULL || myname[0] == '\0') 80217469Seric { 80368693Seric pw = sm_getpwuid(RealUid); 80417469Seric if (pw != NULL) 80540993Sbostic myname = newstr(pw->pw_name); 80617469Seric } 80719904Smiriam else 80819904Smiriam { 80963787Seric uid_t uid = RealUid; 81019873Smiriam 81140993Sbostic myname = newstr(myname); 81268693Seric if ((pw = sm_getpwnam(myname)) == NULL || 81358736Seric (uid != 0 && uid != pw->pw_uid)) 81419904Smiriam { 81568693Seric pw = sm_getpwuid(uid); 81624945Seric if (pw != NULL) 81740993Sbostic myname = newstr(pw->pw_name); 81819873Smiriam } 81919873Smiriam } 82017469Seric if (myname == NULL || myname[0] == '\0') 82117469Seric { 82258151Seric syserr("554 Who are you?"); 82317469Seric myname = "postmaster"; 82417469Seric } 82517469Seric } 82617469Seric 82717469Seric return (myname); 8289369Seric } 8299369Seric /* 8304190Seric ** TTYPATH -- Get the path of the user's tty 831294Seric ** 832294Seric ** Returns the pathname of the user's tty. Returns NULL if 833294Seric ** the user is not logged in or if s/he has write permission 834294Seric ** denied. 835294Seric ** 836294Seric ** Parameters: 837294Seric ** none 838294Seric ** 839294Seric ** Returns: 840294Seric ** pathname of the user's tty. 841294Seric ** NULL if not logged in or write permission denied. 842294Seric ** 843294Seric ** Side Effects: 844294Seric ** none. 845294Seric ** 846294Seric ** WARNING: 847294Seric ** Return value is in a local buffer. 848294Seric ** 849294Seric ** Called By: 850294Seric ** savemail 851294Seric */ 852294Seric 853294Seric char * 854294Seric ttypath() 855294Seric { 856294Seric struct stat stbuf; 857294Seric register char *pathn; 858294Seric extern char *ttyname(); 8594081Seric extern char *getlogin(); 860294Seric 861294Seric /* compute the pathname of the controlling tty */ 8629369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 8639369Seric (pathn = ttyname(0)) == NULL) 864294Seric { 865294Seric errno = 0; 866294Seric return (NULL); 867294Seric } 868294Seric 869294Seric /* see if we have write permission */ 8702967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 871294Seric { 872294Seric errno = 0; 873294Seric return (NULL); 874294Seric } 875294Seric 876294Seric /* see if the user is logged in */ 877294Seric if (getlogin() == NULL) 878294Seric return (NULL); 879294Seric 880294Seric /* looks good */ 881294Seric return (pathn); 882294Seric } 8832967Seric /* 8842967Seric ** CHECKCOMPAT -- check for From and To person compatible. 8852967Seric ** 8862967Seric ** This routine can be supplied on a per-installation basis 8872967Seric ** to determine whether a person is allowed to send a message. 8882967Seric ** This allows restriction of certain types of internet 8892967Seric ** forwarding or registration of users. 8902967Seric ** 8912967Seric ** If the hosts are found to be incompatible, an error 89268857Seric ** message should be given using "usrerr" and an EX_ code 89368857Seric ** should be returned. You can also set to->q_status to 89468857Seric ** a DSN-style status code. 8952967Seric ** 89668559Seric ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the 89768559Seric ** body during the return-to-sender function; this should be done 89868559Seric ** on huge messages. This bit may already be set by the ESMTP 89968559Seric ** protocol. 9004288Seric ** 9012967Seric ** Parameters: 9022967Seric ** to -- the person being sent to. 9032967Seric ** 9042967Seric ** Returns: 90557459Seric ** an exit status 9062967Seric ** 9072967Seric ** Side Effects: 9082967Seric ** none (unless you include the usrerr stuff) 9092967Seric */ 9102967Seric 91168508Seric int 91255012Seric checkcompat(to, e) 9132967Seric register ADDRESS *to; 91455012Seric register ENVELOPE *e; 9152967Seric { 91612133Seric # ifdef lint 91712133Seric if (to == NULL) 91812133Seric to++; 91963834Seric # endif /* lint */ 92064402Seric 92164402Seric if (tTd(49, 1)) 92264402Seric printf("checkcompat(to=%s, from=%s)\n", 92364402Seric to->q_paddr, e->e_from.q_paddr); 92464402Seric 92510698Seric # ifdef EXAMPLE_CODE 92610698Seric /* this code is intended as an example only */ 9274437Seric register STAB *s; 9284437Seric 9294437Seric s = stab("arpa", ST_MAILER, ST_FIND); 93068508Seric if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 && 9319369Seric to->q_mailer == s->s_mailer) 9324437Seric { 93358151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 93468559Seric /* e->e_flags |= EF_NO_BODY_RETN; to supress body on return */ 93568857Seric to->q_status = "5.7.1"; 93657459Seric return (EX_UNAVAILABLE); 9374437Seric } 93856795Seric # endif /* EXAMPLE_CODE */ 93957459Seric return (EX_OK); 9402967Seric } 9419369Seric /* 94264035Seric ** SETSIGNAL -- set a signal handler 94364035Seric ** 94464035Seric ** This is essentially old BSD "signal(3)". 94564035Seric */ 94664035Seric 94764561Seric sigfunc_t 94864035Seric setsignal(sig, handler) 94964035Seric int sig; 95064561Seric sigfunc_t handler; 95164035Seric { 95264380Seric #if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE) 95364035Seric return signal(sig, handler); 95464035Seric #else 95564035Seric struct sigaction n, o; 95664035Seric 95764035Seric bzero(&n, sizeof n); 95864035Seric n.sa_handler = handler; 95968508Seric # ifdef SA_RESTART 96068508Seric n.sa_flags = SA_RESTART; 96168508Seric # endif 96264035Seric if (sigaction(sig, &n, &o) < 0) 96364035Seric return SIG_ERR; 96464035Seric return o.sa_handler; 96564035Seric #endif 96664035Seric } 96764035Seric /* 9689369Seric ** HOLDSIGS -- arrange to hold all signals 9699369Seric ** 9709369Seric ** Parameters: 9719369Seric ** none. 9729369Seric ** 9739369Seric ** Returns: 9749369Seric ** none. 9759369Seric ** 9769369Seric ** Side Effects: 9779369Seric ** Arranges that signals are held. 9789369Seric */ 9799369Seric 98068508Seric void 9819369Seric holdsigs() 9829369Seric { 9839369Seric } 9849369Seric /* 9859369Seric ** RLSESIGS -- arrange to release all signals 9869369Seric ** 9879369Seric ** This undoes the effect of holdsigs. 9889369Seric ** 9899369Seric ** Parameters: 9909369Seric ** none. 9919369Seric ** 9929369Seric ** Returns: 9939369Seric ** none. 9949369Seric ** 9959369Seric ** Side Effects: 9969369Seric ** Arranges that signals are released. 9979369Seric */ 9989369Seric 99968508Seric void 10009369Seric rlsesigs() 10019369Seric { 10029369Seric } 100314872Seric /* 100464705Seric ** INIT_MD -- do machine dependent initializations 100564705Seric ** 100664705Seric ** Systems that have global modes that should be set should do 100764705Seric ** them here rather than in main. 100864705Seric */ 100964705Seric 101064705Seric #ifdef _AUX_SOURCE 101164705Seric # include <compat.h> 101264705Seric #endif 101364705Seric 101468508Seric void 101564825Seric init_md(argc, argv) 101664825Seric int argc; 101764825Seric char **argv; 101864705Seric { 101964705Seric #ifdef _AUX_SOURCE 102064705Seric setcompat(getcompat() | COMPAT_BSDPROT); 102164705Seric #endif 102268508Seric 102368508Seric #ifdef VENDOR_DEFAULT 102468508Seric VendorCode = VENDOR_DEFAULT; 102568508Seric #else 102668508Seric VendorCode = VENDOR_BERKELEY; 102768508Seric #endif 102864705Seric } 102964705Seric /* 103068508Seric ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations 103168508Seric ** 103268508Seric ** Called once, on startup. 103368508Seric ** 103468508Seric ** Parameters: 103568508Seric ** e -- the global envelope. 103668508Seric ** 103768508Seric ** Returns: 103868508Seric ** none. 103968508Seric ** 104068508Seric ** Side Effects: 104168508Seric ** vendor-dependent. 104268508Seric */ 104368508Seric 104468508Seric void 104568508Seric init_vendor_macros(e) 104668508Seric register ENVELOPE *e; 104768508Seric { 104868508Seric } 104968508Seric /* 105014872Seric ** GETLA -- get the current load average 105114872Seric ** 105214881Seric ** This code stolen from la.c. 105314881Seric ** 105414872Seric ** Parameters: 105514872Seric ** none. 105614872Seric ** 105714872Seric ** Returns: 105814872Seric ** The current load average as an integer. 105914872Seric ** 106014872Seric ** Side Effects: 106114872Seric ** none. 106214872Seric */ 106314872Seric 106451920Seric /* try to guess what style of load average we have */ 106551920Seric #define LA_ZERO 1 /* always return load average as zero */ 106664360Seric #define LA_INT 2 /* read kmem for avenrun; interpret as long */ 106751920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 106851920Seric #define LA_SUBR 4 /* call getloadavg */ 106964295Seric #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */ 107064360Seric #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */ 107166301Seric #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */ 107269462Seric #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */ 107369462Seric #define LA_DGUX 9 /* special DGUX implementation */ 107469462Seric #define LA_HPUX 10 /* special HPUX implementation */ 107514872Seric 107663962Seric /* do guesses based on general OS type */ 107751920Seric #ifndef LA_TYPE 107863962Seric # define LA_TYPE LA_ZERO 107951920Seric #endif 108051920Seric 108169462Seric #ifndef FSHIFT 108269462Seric # if defined(unixpc) 108369462Seric # define FSHIFT 5 108469462Seric # endif 108569462Seric 108669462Seric # if defined(__alpha) || defined(IRIX) 108769462Seric # define FSHIFT 10 108869462Seric # endif 108969462Seric 109069462Seric # if defined(_AIX3) 109169462Seric # define FSHIFT 16 109269462Seric # endif 109369462Seric #endif 109469462Seric 109569462Seric #ifndef FSHIFT 109669462Seric # define FSHIFT 8 109769462Seric #endif 109869462Seric 109969462Seric #ifndef FSCALE 110069462Seric # define FSCALE (1 << FSHIFT) 110169462Seric #endif 110269462Seric 110369654Seric #ifndef LA_AVENRUN 110469654Seric # ifdef SYSTEM5 110569654Seric # define LA_AVENRUN "avenrun" 110669654Seric # else 110769654Seric # define LA_AVENRUN "_avenrun" 110869654Seric # endif 110969654Seric #endif 111069654Seric 111164360Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) 111251920Seric 111314872Seric #include <nlist.h> 111414872Seric 111568508Seric #ifdef IRIX64 111668508Seric # define nlist nlist64 111768508Seric #endif 111868508Seric 111951920Seric /* _PATH_UNIX should be defined in <paths.h> */ 112051920Seric #ifndef _PATH_UNIX 112163962Seric # if defined(SYSTEM5) 112263962Seric # define _PATH_UNIX "/unix" 112363962Seric # else 112463962Seric # define _PATH_UNIX "/vmunix" 112563962Seric # endif 112651920Seric #endif 112751920Seric 112869462Seric struct nlist Nl[] = 112914872Seric { 113051920Seric { LA_AVENRUN }, 113114872Seric #define X_AVENRUN 0 113214872Seric { 0 }, 113314872Seric }; 113414872Seric 113514872Seric getla() 113614872Seric { 113714872Seric static int kmem = -1; 113851920Seric #if LA_TYPE == LA_INT 113924943Seric long avenrun[3]; 114051920Seric #else 114164360Seric # if LA_TYPE == LA_SHORT 114264360Seric short avenrun[3]; 114364360Seric # else 114451920Seric double avenrun[3]; 114564360Seric # endif 114651920Seric #endif 114769462Seric extern int errno; 114825615Seric extern off_t lseek(); 114914872Seric 115014872Seric if (kmem < 0) 115114872Seric { 115224945Seric kmem = open("/dev/kmem", 0, 0); 115314872Seric if (kmem < 0) 115457736Seric { 115557736Seric if (tTd(3, 1)) 115657736Seric printf("getla: open(/dev/kmem): %s\n", 115757736Seric errstring(errno)); 115814872Seric return (-1); 115957736Seric } 116051920Seric (void) fcntl(kmem, F_SETFD, 1); 116169462Seric 116268508Seric #ifdef _AIX3 116368508Seric if (knlist(Nl, 1, sizeof Nl[0]) < 0) 116468508Seric #else 116557736Seric if (nlist(_PATH_UNIX, Nl) < 0) 116668508Seric #endif 116757736Seric { 116857736Seric if (tTd(3, 1)) 116957736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 117057736Seric errstring(errno)); 117114872Seric return (-1); 117257736Seric } 117359253Seric if (Nl[X_AVENRUN].n_value == 0) 117459253Seric { 117559253Seric if (tTd(3, 1)) 117659253Seric printf("getla: nlist(%s, %s) ==> 0\n", 117759253Seric _PATH_UNIX, LA_AVENRUN); 117859253Seric return (-1); 117959253Seric } 118068508Seric #ifdef NAMELISTMASK 118168508Seric Nl[X_AVENRUN].n_value &= NAMELISTMASK; 118266763Seric #endif 118314872Seric } 118457736Seric if (tTd(3, 20)) 118557736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 118668508Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 || 118723118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 118819967Seric { 118919967Seric /* thank you Ian */ 119057736Seric if (tTd(3, 1)) 119157736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 119219967Seric return (-1); 119319967Seric } 119469462Seric # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) 119557736Seric if (tTd(3, 5)) 119657736Seric { 119757736Seric printf("getla: avenrun = %d", avenrun[0]); 119857736Seric if (tTd(3, 15)) 119957736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 120057736Seric printf("\n"); 120157736Seric } 120257736Seric if (tTd(3, 1)) 120357736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 120424943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 120569462Seric # else /* LA_TYPE == LA_FLOAT */ 120657736Seric if (tTd(3, 5)) 120757736Seric { 120857736Seric printf("getla: avenrun = %g", avenrun[0]); 120957736Seric if (tTd(3, 15)) 121057736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 121157736Seric printf("\n"); 121257736Seric } 121357736Seric if (tTd(3, 1)) 121457736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 121551920Seric return ((int) (avenrun[0] + 0.5)); 121669462Seric # endif 121714872Seric } 121814872Seric 121969462Seric #endif /* LA_TYPE == LA_INT or LA_SHORT or LA_FLOAT */ 122051773Seric 122169462Seric #if LA_TYPE == LA_READKSYM 122264718Seric 122369473Seric # include <sys/ksym.h> 122469473Seric 122569462Seric getla() 122669462Seric { 122769462Seric static int kmem = -1; 122869462Seric long avenrun[3]; 122969462Seric extern int errno; 123069462Seric struct mioc_rksym mirk; 123164718Seric 123269462Seric if (kmem < 0) 123369462Seric { 123469462Seric kmem = open("/dev/kmem", 0, 0); 123569462Seric if (kmem < 0) 123669462Seric { 123769462Seric if (tTd(3, 1)) 123869462Seric printf("getla: open(/dev/kmem): %s\n", 123969462Seric errstring(errno)); 124069462Seric return (-1); 124169462Seric } 124269462Seric (void) fcntl(kmem, F_SETFD, 1); 124369462Seric } 124469462Seric mirk.mirk_symname = LA_AVENRUN; 124569462Seric mirk.mirk_buf = avenrun; 124669462Seric mirk.mirk_buflen = sizeof(avenrun); 124769462Seric if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0) 124869462Seric { 124969462Seric if (tTd(3, 1)) 125069462Seric printf("getla: ioctl(MIOC_READKSYM) failed: %s\n", 125169462Seric errstring(errno)); 125269462Seric return -1; 125369462Seric } 125469462Seric if (tTd(3, 5)) 125569462Seric { 125669462Seric printf("getla: avenrun = %d", avenrun[0]); 125769462Seric if (tTd(3, 15)) 125869462Seric printf(", %d, %d", avenrun[1], avenrun[2]); 125969462Seric printf("\n"); 126069462Seric } 126169462Seric if (tTd(3, 1)) 126269462Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 126369462Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 126469462Seric } 126569462Seric 126669462Seric #endif /* LA_TYPE == LA_READKSYM */ 126769462Seric 126869462Seric #if LA_TYPE == LA_DGUX 126969462Seric 127069462Seric # include <sys/dg_sys_info.h> 127169462Seric 127268508Seric int 127368508Seric getla() 127464718Seric { 127564718Seric struct dg_sys_info_load_info load_info; 127664718Seric 127764718Seric dg_sys_info((long *)&load_info, 127864718Seric DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); 127964718Seric 128068508Seric if (tTd(3, 1)) 128168508Seric printf("getla: %d\n", (int) (load_info.one_minute + 0.5)); 128268508Seric 128364718Seric return((int) (load_info.one_minute + 0.5)); 128464718Seric } 128564718Seric 128669462Seric #endif /* LA_TYPE == LA_DGUX */ 128764718Seric 128869462Seric #if LA_TYPE == LA_HPUX 128969462Seric 129069563Seric /* forward declarations to keep gcc from complaining */ 129168869Seric struct pst_dynamic; 129269563Seric struct pst_status; 129369563Seric struct pst_static; 129469563Seric struct pst_vminfo; 129569563Seric struct pst_diskinfo; 129669563Seric struct pst_processor; 129769563Seric struct pst_lv; 129869563Seric struct pst_swapinfo; 129968869Seric 130069462Seric # include <sys/param.h> 130169462Seric # include <sys/pstat.h> 130268508Seric 130368508Seric int 130451773Seric getla() 130551773Seric { 130668508Seric struct pst_dynamic pstd; 130768508Seric 130868508Seric if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic), 130968869Seric (size_t) 1, 0) == -1) 131068508Seric return 0; 131168508Seric 131268508Seric if (tTd(3, 1)) 131368508Seric printf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5)); 131468508Seric 131568508Seric return (int) (pstd.psd_avg_1_min + 0.5); 131668508Seric } 131768508Seric 131869462Seric #endif /* LA_TYPE == LA_HPUX */ 131968508Seric 132069462Seric #if LA_TYPE == LA_SUBR 132169462Seric 132268508Seric int 132368508Seric getla() 132468508Seric { 132551920Seric double avenrun[3]; 132651920Seric 132751920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 132857736Seric { 132957736Seric if (tTd(3, 1)) 133057736Seric perror("getla: getloadavg failed:"); 133151920Seric return (-1); 133257736Seric } 133357736Seric if (tTd(3, 1)) 133457736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 133551920Seric return ((int) (avenrun[0] + 0.5)); 133651773Seric } 133751773Seric 133869462Seric #endif /* LA_TYPE == LA_SUBR */ 133969462Seric 134064295Seric #if LA_TYPE == LA_MACH 134151773Seric 134264295Seric /* 134365173Seric ** This has been tested on NEXTSTEP release 2.1/3.X. 134464295Seric */ 134564295Seric 134665173Seric #if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 134765173Seric # include <mach/mach.h> 134865173Seric #else 134965173Seric # include <mach.h> 135065173Seric #endif 135164295Seric 135251773Seric getla() 135351773Seric { 135464295Seric processor_set_t default_set; 135564295Seric kern_return_t error; 135664295Seric unsigned int info_count; 135764295Seric struct processor_set_basic_info info; 135864295Seric host_t host; 135964295Seric 136064295Seric error = processor_set_default(host_self(), &default_set); 136164295Seric if (error != KERN_SUCCESS) 136264295Seric return -1; 136364295Seric info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 136464295Seric if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, 136564295Seric &host, (processor_set_info_t)&info, 136664295Seric &info_count) != KERN_SUCCESS) 136764295Seric { 136864295Seric return -1; 136964295Seric } 137064295Seric return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE; 137164295Seric } 137264295Seric 137369462Seric #endif /* LA_TYPE == LA_MACH */ 137464295Seric 137566313Seric #if LA_TYPE == LA_PROCSTR 137664295Seric 137766301Seric /* 137866301Seric ** Read /proc/loadavg for the load average. This is assumed to be 137966301Seric ** in a format like "0.15 0.12 0.06". 138066301Seric ** 138166301Seric ** Initially intended for Linux. This has been in the kernel 138266301Seric ** since at least 0.99.15. 138366301Seric */ 138466301Seric 138566301Seric # ifndef _PATH_LOADAVG 138666301Seric # define _PATH_LOADAVG "/proc/loadavg" 138766301Seric # endif 138866301Seric 138966301Seric int 139064295Seric getla() 139164295Seric { 139266319Seric double avenrun; 139366301Seric register int result; 139466319Seric FILE *fp; 139566301Seric 139666319Seric fp = fopen(_PATH_LOADAVG, "r"); 139769472Seric if (fp == NULL) 139866301Seric { 139966319Seric if (tTd(3, 1)) 140066319Seric printf("getla: fopen(%s): %s\n", 140166319Seric _PATH_LOADAVG, errstring(errno)); 140266319Seric return -1; 140366301Seric } 140466301Seric result = fscanf(fp, "%lf", &avenrun); 140566319Seric fclose(fp); 140666301Seric if (result != 1) 140766301Seric { 140866310Seric if (tTd(3, 1)) 140966301Seric printf("getla: fscanf() = %d: %s\n", 141066301Seric result, errstring(errno)); 141166301Seric return -1; 141266301Seric } 141366301Seric 141457736Seric if (tTd(3, 1)) 141566301Seric printf("getla(): %.2f\n", avenrun); 141666301Seric 141766301Seric return ((int) (avenrun + 0.5)); 141866301Seric } 141966301Seric 142069462Seric #endif /* LA_TYPE == LA_PROCSTR */ 142166301Seric 142269462Seric #if LA_TYPE == LA_ZERO 142369462Seric 142466301Seric getla() 142566301Seric { 142666301Seric if (tTd(3, 1)) 142757736Seric printf("getla: ZERO\n"); 142851920Seric return (0); 142951773Seric } 143051773Seric 143169462Seric #endif /* LA_TYPE == LA_ZERO */ 143266045Seric 143366045Seric 143466045Seric /* 143566045Seric * Copyright 1989 Massachusetts Institute of Technology 143666045Seric * 143766045Seric * Permission to use, copy, modify, distribute, and sell this software and its 143866045Seric * documentation for any purpose is hereby granted without fee, provided that 143966045Seric * the above copyright notice appear in all copies and that both that 144066045Seric * copyright notice and this permission notice appear in supporting 144166045Seric * documentation, and that the name of M.I.T. not be used in advertising or 144266045Seric * publicity pertaining to distribution of the software without specific, 144366045Seric * written prior permission. M.I.T. makes no representations about the 144466045Seric * suitability of this software for any purpose. It is provided "as is" 144566045Seric * without express or implied warranty. 144666045Seric * 144766045Seric * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 144866045Seric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 144966045Seric * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 145066045Seric * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 145166045Seric * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 145266045Seric * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 145366045Seric * 145466045Seric * Authors: Many and varied... 145566045Seric */ 145666045Seric 145766045Seric /* Non Apollo stuff removed by Don Lewis 11/15/93 */ 145866045Seric #ifndef lint 145966045Seric static char rcsid[] = "@(#)$Id: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $"; 146066045Seric #endif /* !lint */ 146166045Seric 146266179Seric #ifdef apollo 146366045Seric # undef volatile 146466045Seric # include <apollo/base.h> 146566045Seric 146666045Seric /* ARGSUSED */ 146766045Seric int getloadavg( call_data ) 146866045Seric caddr_t call_data; /* pointer to (double) return value */ 146966045Seric { 147066045Seric double *avenrun = (double *) call_data; 147166045Seric int i; 147266045Seric status_$t st; 147366045Seric long loadav[3]; 147466045Seric proc1_$get_loadav(loadav, &st); 147566045Seric *avenrun = loadav[0] / (double) (1 << 16); 147666045Seric return(0); 147766045Seric } 147866045Seric # endif /* apollo */ 147924943Seric /* 148024943Seric ** SHOULDQUEUE -- should this message be queued or sent? 148124943Seric ** 148224943Seric ** Compares the message cost to the load average to decide. 148324943Seric ** 148424943Seric ** Parameters: 148524943Seric ** pri -- the priority of the message in question. 148657438Seric ** ctime -- the message creation time. 148724943Seric ** 148824943Seric ** Returns: 148924943Seric ** TRUE -- if this message should be queued up for the 149024943Seric ** time being. 149124943Seric ** FALSE -- if the load is low enough to send this message. 149224943Seric ** 149324943Seric ** Side Effects: 149424943Seric ** none. 149524943Seric */ 149624943Seric 149724943Seric bool 149857438Seric shouldqueue(pri, ctime) 149924943Seric long pri; 150057438Seric time_t ctime; 150124943Seric { 150268508Seric bool rval; 150368508Seric 150468508Seric if (tTd(3, 30)) 150568508Seric printf("shouldqueue: CurrentLA=%d, pri=%d: ", CurrentLA, pri); 150651920Seric if (CurrentLA < QueueLA) 150768508Seric { 150868508Seric if (tTd(3, 30)) 150968508Seric printf("FALSE (CurrentLA < QueueLA)\n"); 151024943Seric return (FALSE); 151168508Seric } 151258132Seric if (CurrentLA >= RefuseLA) 151368508Seric { 151468508Seric if (tTd(3, 30)) 151568508Seric printf("TRUE (CurrentLA >= RefuseLA)\n"); 151658132Seric return (TRUE); 151768508Seric } 151868508Seric rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1)); 151968508Seric if (tTd(3, 30)) 152068508Seric printf("%s (by calculation)\n", rval ? "TRUE" : "FALSE"); 152168508Seric return rval; 152224943Seric } 152324943Seric /* 152453037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 152553037Seric ** 152653037Seric ** Parameters: 152753037Seric ** none. 152853037Seric ** 152953037Seric ** Returns: 153053037Seric ** TRUE if incoming SMTP connections should be refused 153153037Seric ** (for now). 153253037Seric ** FALSE if we should accept new work. 153353037Seric ** 153453037Seric ** Side Effects: 1535*69832Seric ** Sets process title when it is rejecting connections. 153653037Seric */ 153753037Seric 153853037Seric bool 153953037Seric refuseconnections() 154053037Seric { 154169801Seric extern bool enoughdiskspace(); 1542*69832Seric extern void setproctitle(); 154368508Seric 154459156Seric #ifdef XLA 154559156Seric if (!xla_smtp_ok()) 154659156Seric return TRUE; 154759156Seric #endif 154859156Seric 1549*69832Seric if (CurrentLA >= RefuseLA) 1550*69832Seric { 1551*69832Seric setproctitle("rejecting connections: load average: %d", 1552*69832Seric CurrentLA); 1553*69832Seric } 1554*69832Seric else if (!enoughdiskspace(MinBlocksFree + 1)) 1555*69832Seric { 1556*69832Seric setproctitle("rejecting connections: min free: %d", 1557*69832Seric MinBlocksFree); 1558*69832Seric } 1559*69832Seric else if (MaxChildren > 0 && CurChildren >= MaxChildren) 1560*69832Seric { 1561*69832Seric setproctitle("rejecting connections: maximum children: %d", 1562*69832Seric CurChildren); 1563*69832Seric } 1564*69832Seric else 1565*69832Seric return FALSE; 1566*69832Seric return TRUE; 156753037Seric } 156853037Seric /* 156924943Seric ** SETPROCTITLE -- set process title for ps 157024943Seric ** 157124943Seric ** Parameters: 157258674Seric ** fmt -- a printf style format string. 157358674Seric ** a, b, c -- possible parameters to fmt. 157424943Seric ** 157524943Seric ** Returns: 157624943Seric ** none. 157724943Seric ** 157824943Seric ** Side Effects: 157924943Seric ** Clobbers argv of our main procedure so ps(1) will 158024943Seric ** display the title. 158124943Seric */ 158224943Seric 158368508Seric #define SPT_NONE 0 /* don't use it at all */ 158468508Seric #define SPT_REUSEARGV 1 /* cover argv with title information */ 158568508Seric #define SPT_BUILTIN 2 /* use libc builtin */ 158668508Seric #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */ 158768508Seric #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */ 158869654Seric #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */ 158968508Seric 159068508Seric #ifndef SPT_TYPE 159168508Seric # define SPT_TYPE SPT_REUSEARGV 159268508Seric #endif 159368508Seric 159468508Seric #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN 159568508Seric 159668508Seric # if SPT_TYPE == SPT_PSTAT 159758689Seric # include <sys/pstat.h> 159858689Seric # endif 159968508Seric # if SPT_TYPE == SPT_PSSTRINGS 160059732Seric # include <machine/vmparam.h> 160159732Seric # include <sys/exec.h> 160268508Seric # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */ 160368508Seric # undef SPT_TYPE 160468508Seric # define SPT_TYPE SPT_REUSEARGV 160568734Seric # else 160668734Seric # ifndef NKPDE /* FreeBSD 2.0 */ 160768734Seric # define NKPDE 63 160868734Seric typedef unsigned int *pt_entry_t; 160968734Seric # endif 161064247Seric # endif 161159732Seric # endif 161268508Seric 161368508Seric # if SPT_TYPE == SPT_PSSTRINGS 161468508Seric # define SETPROC_STATIC static 161568508Seric # else 161659732Seric # define SETPROC_STATIC 161759732Seric # endif 161867626Seric 161969654Seric # if SPT_TYPE == SPT_SYSMIPS 162069654Seric # include <sys/sysmips.h> 162169654Seric # include <sys/sysnews.h> 162269654Seric # endif 162369654Seric 162468508Seric # ifndef SPT_PADCHAR 162568508Seric # define SPT_PADCHAR ' ' 162668508Seric # endif 162758689Seric 162868508Seric #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */ 162964843Seric 163068508Seric #if SPT_TYPE != SPT_BUILTIN 163168508Seric 163224943Seric /*VARARGS1*/ 163368508Seric void 163468508Seric # ifdef __STDC__ 163557642Seric setproctitle(char *fmt, ...) 163668508Seric # else 163757642Seric setproctitle(fmt, va_alist) 163824943Seric char *fmt; 163957642Seric va_dcl 164068508Seric # endif 164124943Seric { 164268508Seric # if SPT_TYPE != SPT_NONE 164324943Seric register char *p; 164425049Seric register int i; 164559732Seric SETPROC_STATIC char buf[MAXLINE]; 164656852Seric VA_LOCAL_DECL 164768508Seric # if SPT_TYPE == SPT_PSTAT 164858689Seric union pstun pst; 164958689Seric # endif 165069748Seric # if SPT_TYPE == SPT_REUSEARGV 165124943Seric extern char **Argv; 165224943Seric extern char *LastArgv; 165369748Seric # endif 165424943Seric 165558674Seric p = buf; 165624943Seric 165758674Seric /* print sendmail: heading for grep */ 165858674Seric (void) strcpy(p, "sendmail: "); 165958674Seric p += strlen(p); 166024943Seric 166158674Seric /* print the argument string */ 166258674Seric VA_START(fmt); 166358674Seric (void) vsprintf(p, fmt, ap); 166456852Seric VA_END; 166554996Seric 166658674Seric i = strlen(buf); 166758689Seric 166868508Seric # if SPT_TYPE == SPT_PSTAT 166958689Seric pst.pst_command = buf; 167058689Seric pstat(PSTAT_SETCMD, pst, i, 0, 0); 167169654Seric # endif 167269654Seric # if SPT_TYPE == SPT_PSSTRINGS 167359732Seric PS_STRINGS->ps_nargvstr = 1; 167459732Seric PS_STRINGS->ps_argvstr = buf; 167569654Seric # endif 167669654Seric # if SPT_TYPE == SPT_SYSMIPS 167769654Seric sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf); 167869654Seric # endif 167969654Seric # if SPT_TYPE == SPT_REUSEARGV 168054996Seric if (i > LastArgv - Argv[0] - 2) 168125049Seric { 168254996Seric i = LastArgv - Argv[0] - 2; 168358674Seric buf[i] = '\0'; 168425049Seric } 168558674Seric (void) strcpy(Argv[0], buf); 168654997Seric p = &Argv[0][i]; 168724943Seric while (p < LastArgv) 168868508Seric *p++ = SPT_PADCHAR; 168968508Seric Argv[1] = NULL; 169069654Seric # endif 169168508Seric # endif /* SPT_TYPE != SPT_NONE */ 169224943Seric } 169365982Seric 169468508Seric #endif /* SPT_TYPE != SPT_BUILTIN */ 169525698Seric /* 169625698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 169725698Seric ** 169825698Seric ** Parameters: 169968508Seric ** sig -- the signal that got us here (unused). 170025698Seric ** 170125698Seric ** Returns: 170225698Seric ** none. 170325698Seric ** 170425698Seric ** Side Effects: 170525698Seric ** Picks up extant zombies. 170625698Seric */ 170725698Seric 170846928Sbostic void 170968508Seric reapchild(sig) 171068508Seric int sig; 171125698Seric { 171264738Seric int olderrno = errno; 171363966Seric # ifdef HASWAITPID 171460219Seric auto int status; 171560560Seric int count; 171660560Seric int pid; 171760219Seric 171860560Seric count = 0; 171960560Seric while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 172060560Seric { 172160560Seric if (count++ > 1000) 172260560Seric { 172366748Seric #ifdef LOG 172460560Seric syslog(LOG_ALERT, "reapchild: waitpid loop: pid=%d, status=%x", 172560560Seric pid, status); 172666748Seric #endif 172760560Seric break; 172860560Seric } 1729*69832Seric CurChildren--; 173060560Seric } 173160219Seric # else 173225698Seric # ifdef WNOHANG 173325698Seric union wait status; 173425698Seric 173563753Seric while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) 1736*69832Seric CurChildren--; 173756795Seric # else /* WNOHANG */ 173825698Seric auto int status; 173925698Seric 174060219Seric while (wait(&status) > 0) 1741*69832Seric CurChildren--; 174256795Seric # endif /* WNOHANG */ 174360219Seric # endif 174464035Seric # ifdef SYS5SIGNALS 174564035Seric (void) setsignal(SIGCHLD, reapchild); 174658061Seric # endif 174764738Seric errno = olderrno; 174825698Seric } 174955418Seric /* 175069654Seric ** PUTENV -- emulation of putenv() in terms of setenv() 175169654Seric ** 175269654Seric ** Not needed on Posix-compliant systems. 175369654Seric ** This doesn't have full Posix semantics, but it's good enough 175469654Seric ** for sendmail. 175569654Seric ** 175669654Seric ** Parameter: 175769654Seric ** env -- the environment to put. 175869654Seric ** 175969654Seric ** Returns: 176069654Seric ** none. 176169654Seric */ 176269654Seric 176369654Seric #ifdef NEEDPUTENV 176469654Seric 176569717Seric # if NEEDPUTENV == 2 /* no setenv(3) call available */ 176669717Seric 176769717Seric int 176869717Seric putenv(str) 176969717Seric char *str; 177069717Seric { 177169717Seric char **current; 177269717Seric int matchlen, envlen=0; 177369717Seric char *tmp; 177469717Seric char **newenv; 177569717Seric static int first=1; 177669717Seric extern char **environ; 177769717Seric 177869717Seric /* 177969717Seric * find out how much of str to match when searching 178069717Seric * for a string to replace. 178169717Seric */ 178269717Seric if ((tmp = index(str, '=')) == NULL || tmp == str) 178369717Seric matchlen = strlen(str); 178469717Seric else 178569717Seric matchlen = (int) (tmp - str); 178669717Seric ++matchlen; 178769717Seric 178869717Seric /* 178969717Seric * Search for an existing string in the environment and find the 179069717Seric * length of environ. If found, replace and exit. 179169717Seric */ 179269717Seric for (current=environ; *current; current++) { 179369717Seric ++envlen; 179469717Seric 179569717Seric if (strncmp(str, *current, matchlen) == 0) { 179669717Seric /* found it, now insert the new version */ 179769717Seric *current = (char *)str; 179869717Seric return(0); 179969717Seric } 180069717Seric } 180169717Seric 180269717Seric /* 180369717Seric * There wasn't already a slot so add space for a new slot. 180469717Seric * If this is our first time through, use malloc(), else realloc(). 180569717Seric */ 180669717Seric if (first) { 180769717Seric newenv = (char **) malloc(sizeof(char *) * (envlen + 2)); 180869717Seric if (newenv == NULL) 180969717Seric return(-1); 181069717Seric 181169717Seric first=0; 181269717Seric (void) memcpy(newenv, environ, sizeof(char *) * envlen); 181369717Seric } else { 181469717Seric newenv = (char **) realloc((char *)environ, sizeof(char *) * (envlen + 2)); 181569717Seric if (newenv == NULL) 181669717Seric return(-1); 181769717Seric } 181869717Seric 181969717Seric /* actually add in the new entry */ 182069717Seric environ = newenv; 182169717Seric environ[envlen] = (char *)str; 182269717Seric environ[envlen+1] = NULL; 182369717Seric 182469717Seric return(0); 182569717Seric } 182669717Seric 182769717Seric #else /* implement putenv() in terms of setenv() */ 182869717Seric 182969717Seric int 183069654Seric putenv(env) 183169654Seric char *env; 183269654Seric { 183369654Seric char *p; 183469654Seric int l; 183569654Seric char nbuf[100]; 183669654Seric 183769654Seric p = strchr(env, '='); 183869654Seric if (p == NULL) 183969717Seric return 0; 184069654Seric l = p - env; 184169654Seric if (l > sizeof nbuf - 1) 184269654Seric l = sizeof nbuf - 1; 184369654Seric bcopy(env, nbuf, l); 184469654Seric nbuf[l] = '\0'; 184569717Seric return setenv(nbuf, ++p, 1); 184669654Seric } 184769654Seric 184869717Seric # endif 184969654Seric #endif 185069654Seric /* 185155418Seric ** UNSETENV -- remove a variable from the environment 185255418Seric ** 185355418Seric ** Not needed on newer systems. 185455418Seric ** 185555418Seric ** Parameters: 185655418Seric ** name -- the string name of the environment variable to be 185755418Seric ** deleted from the current environment. 185855418Seric ** 185955418Seric ** Returns: 186055418Seric ** none. 186155418Seric ** 186255418Seric ** Globals: 186355418Seric ** environ -- a pointer to the current environment. 186455418Seric ** 186555418Seric ** Side Effects: 186655418Seric ** Modifies environ. 186755418Seric */ 186855418Seric 186963962Seric #ifndef HASUNSETENV 187055418Seric 187155418Seric void 187255418Seric unsetenv(name) 187355418Seric char *name; 187455418Seric { 187555418Seric extern char **environ; 187655418Seric register char **pp; 187755418Seric int len = strlen(name); 187855418Seric 187955418Seric for (pp = environ; *pp != NULL; pp++) 188055418Seric { 188155418Seric if (strncmp(name, *pp, len) == 0 && 188255418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 188355418Seric break; 188455418Seric } 188555418Seric 188655418Seric for (; *pp != NULL; pp++) 188755418Seric *pp = pp[1]; 188855418Seric } 188955418Seric 189063962Seric #endif 189156215Seric /* 189256215Seric ** GETDTABLESIZE -- return number of file descriptors 189356215Seric ** 189456215Seric ** Only on non-BSD systems 189556215Seric ** 189656215Seric ** Parameters: 189756215Seric ** none 189856215Seric ** 189956215Seric ** Returns: 190056215Seric ** size of file descriptor table 190156215Seric ** 190256215Seric ** Side Effects: 190356215Seric ** none 190456215Seric */ 190556215Seric 190663787Seric #ifdef SOLARIS 190763787Seric # include <sys/resource.h> 190863787Seric #endif 190956215Seric 191056215Seric int 191163787Seric getdtsize() 191256215Seric { 191363787Seric #ifdef RLIMIT_NOFILE 191463787Seric struct rlimit rl; 191563787Seric 191663787Seric if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) 191763787Seric return rl.rlim_cur; 191863787Seric #endif 191963787Seric 192064031Seric # ifdef HASGETDTABLESIZE 192164031Seric return getdtablesize(); 192264031Seric # else 192364031Seric # ifdef _SC_OPEN_MAX 192458689Seric return sysconf(_SC_OPEN_MAX); 192563787Seric # else 192656215Seric return NOFILE; 192763787Seric # endif 192858689Seric # endif 192956215Seric } 193057631Seric /* 193157631Seric ** UNAME -- get the UUCP name of this system. 193257631Seric */ 193357631Seric 193457943Seric #ifndef HASUNAME 193557631Seric 193657631Seric int 193757631Seric uname(name) 193857631Seric struct utsname *name; 193957631Seric { 194057631Seric FILE *file; 194157631Seric char *n; 194257631Seric 194357631Seric name->nodename[0] = '\0'; 194457631Seric 194557661Seric /* try /etc/whoami -- one line with the node name */ 194657631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 194757631Seric { 194857661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 194957631Seric (void) fclose(file); 195057661Seric n = strchr(name->nodename, '\n'); 195157631Seric if (n != NULL) 195257631Seric *n = '\0'; 195357631Seric if (name->nodename[0] != '\0') 195457631Seric return (0); 195557631Seric } 195657631Seric 195757661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 195857631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 195957631Seric { 196057631Seric char buf[MAXLINE]; 196157631Seric 196257631Seric while (fgets(buf, MAXLINE, file) != NULL) 196357631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 196457631Seric NODE_LENGTH, name->nodename) > 0) 196557631Seric break; 196657631Seric (void) fclose(file); 196757631Seric if (name->nodename[0] != '\0') 196857631Seric return (0); 196957631Seric } 197057631Seric 197157631Seric #ifdef TRUST_POPEN 197257631Seric /* 197357631Seric ** Popen is known to have security holes. 197457631Seric */ 197557631Seric 197657661Seric /* try uuname -l to return local name */ 197757631Seric if ((file = popen("uuname -l", "r")) != NULL) 197857631Seric { 197957661Seric (void) fgets(name, NODE_LENGTH + 1, file); 198057631Seric (void) pclose(file); 198157661Seric n = strchr(name, '\n'); 198257631Seric if (n != NULL) 198357631Seric *n = '\0'; 198457661Seric if (name->nodename[0] != '\0') 198557631Seric return (0); 198657631Seric } 198757631Seric #endif 198869472Seric 198957631Seric return (-1); 199057631Seric } 199157943Seric #endif /* HASUNAME */ 199258068Seric /* 199358068Seric ** INITGROUPS -- initialize groups 199458068Seric ** 199558068Seric ** Stub implementation for System V style systems 199658068Seric */ 199758068Seric 199858068Seric #ifndef HASINITGROUPS 199958068Seric 200058068Seric initgroups(name, basegid) 200158068Seric char *name; 200258068Seric int basegid; 200358068Seric { 200458068Seric return 0; 200558068Seric } 200658068Seric 200758068Seric #endif 200858082Seric /* 200959289Seric ** SETSID -- set session id (for non-POSIX systems) 201059289Seric */ 201159289Seric 201259289Seric #ifndef HASSETSID 201359289Seric 201463753Seric pid_t 201563753Seric setsid __P ((void)) 201659289Seric { 201764155Seric #ifdef TIOCNOTTY 201864155Seric int fd; 201964155Seric 202066743Seric fd = open("/dev/tty", O_RDWR, 0); 202164155Seric if (fd >= 0) 202264155Seric { 202364155Seric (void) ioctl(fd, (int) TIOCNOTTY, (char *) 0); 202464155Seric (void) close(fd); 202564155Seric } 202664155Seric #endif /* TIOCNOTTY */ 202764705Seric # ifdef SYS5SETPGRP 202863753Seric return setpgrp(); 202963753Seric # else 203064155Seric return setpgid(0, getpid()); 203159289Seric # endif 203259289Seric } 203359289Seric 203459289Seric #endif 203559289Seric /* 203666748Seric ** FSYNC -- dummy fsync 203766748Seric */ 203866748Seric 203966748Seric #ifdef NEEDFSYNC 204066748Seric 204166748Seric fsync(fd) 204266748Seric int fd; 204366748Seric { 204466748Seric # ifdef O_SYNC 204566748Seric return fcntl(fd, F_SETFL, O_SYNC); 204666748Seric # else 204766748Seric /* nothing we can do */ 204866748Seric return 0; 204966748Seric # endif 205066748Seric } 205166748Seric 205266748Seric #endif 205366748Seric /* 205464718Seric ** DGUX_INET_ADDR -- inet_addr for DG/UX 205564718Seric ** 205664718Seric ** Data General DG/UX version of inet_addr returns a struct in_addr 205768508Seric ** instead of a long. This patches things. Only needed on versions 205868508Seric ** prior to 5.4.3. 205964718Seric */ 206064718Seric 206168508Seric #ifdef DGUX_5_4_2 206264718Seric 206364718Seric #undef inet_addr 206464718Seric 206564718Seric long 206664718Seric dgux_inet_addr(host) 206764718Seric char *host; 206864718Seric { 206964718Seric struct in_addr haddr; 207064718Seric 207164718Seric haddr = inet_addr(host); 207264718Seric return haddr.s_addr; 207364718Seric } 207464718Seric 207564718Seric #endif 207664718Seric /* 207763969Seric ** GETOPT -- for old systems or systems with bogus implementations 207863969Seric */ 207963969Seric 208063969Seric #ifdef NEEDGETOPT 208163969Seric 208263969Seric /* 208363969Seric * Copyright (c) 1985 Regents of the University of California. 208463969Seric * All rights reserved. The Berkeley software License Agreement 208563969Seric * specifies the terms and conditions for redistribution. 208663969Seric */ 208763969Seric 208863969Seric 208963969Seric /* 209063969Seric ** this version hacked to add `atend' flag to allow state machine 209163969Seric ** to reset if invoked by the program to scan args for a 2nd time 209263969Seric */ 209363969Seric 209463969Seric #if defined(LIBC_SCCS) && !defined(lint) 209563969Seric static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; 209664072Seric #endif /* LIBC_SCCS and not lint */ 209763969Seric 209863969Seric #include <stdio.h> 209963969Seric 210063969Seric /* 210163969Seric * get option letter from argument vector 210263969Seric */ 210365352Seric #ifdef _CONVEX_SOURCE 210468508Seric extern int optind, opterr, optopt; 210568508Seric extern char *optarg; 210665352Seric #else 210765352Seric int opterr = 1; /* if error message should be printed */ 210865352Seric int optind = 1; /* index into parent argv vector */ 210968470Seric int optopt = 0; /* character checked for validity */ 211068470Seric char *optarg = NULL; /* argument associated with option */ 211168508Seric #endif 211263969Seric 211363969Seric #define BADCH (int)'?' 211463969Seric #define EMSG "" 211563969Seric #define tell(s) if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ 211663969Seric fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);} 211763969Seric 211863969Seric getopt(nargc,nargv,ostr) 211965160Seric int nargc; 212065160Seric char *const *nargv; 212165160Seric const char *ostr; 212263969Seric { 212363969Seric static char *place = EMSG; /* option letter processing */ 212463969Seric static char atend = 0; 212563969Seric register char *oli; /* option letter list index */ 212663969Seric 212763969Seric if (atend) { 212863969Seric atend = 0; 212963969Seric place = EMSG; 213063969Seric } 213163969Seric if(!*place) { /* update scanning pointer */ 213264136Seric if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) { 213363969Seric atend++; 213463969Seric return(EOF); 213563969Seric } 213663969Seric if (*place == '-') { /* found "--" */ 213763969Seric ++optind; 213863969Seric atend++; 213963969Seric return(EOF); 214063969Seric } 214163969Seric } /* option letter okay? */ 214264125Seric if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) { 214364136Seric if (!*place) ++optind; 214463969Seric tell(": illegal option -- "); 214563969Seric } 214663969Seric if (*++oli != ':') { /* don't need argument */ 214763969Seric optarg = NULL; 214863969Seric if (!*place) ++optind; 214963969Seric } 215063969Seric else { /* need an argument */ 215163969Seric if (*place) optarg = place; /* no white space */ 215263969Seric else if (nargc <= ++optind) { /* no arg */ 215363969Seric place = EMSG; 215463969Seric tell(": option requires an argument -- "); 215563969Seric } 215663969Seric else optarg = nargv[optind]; /* white space */ 215763969Seric place = EMSG; 215863969Seric ++optind; 215963969Seric } 216063969Seric return(optopt); /* dump back option letter */ 216163969Seric } 216263969Seric 216363969Seric #endif 216463969Seric /* 216563969Seric ** VFPRINTF, VSPRINTF -- for old 4.3 BSD systems missing a real version 216663969Seric */ 216763969Seric 216863969Seric #ifdef NEEDVPRINTF 216963969Seric 217063969Seric #define MAXARG 16 217163969Seric 217263969Seric vfprintf(fp, fmt, ap) 217363969Seric FILE * fp; 217463969Seric char * fmt; 217563969Seric char ** ap; 217663969Seric { 217763969Seric char * bp[MAXARG]; 217863969Seric int i = 0; 217963969Seric 218063969Seric while (*ap && i < MAXARG) 218163969Seric bp[i++] = *ap++; 218263969Seric fprintf(fp, fmt, bp[0], bp[1], bp[2], bp[3], 218363969Seric bp[4], bp[5], bp[6], bp[7], 218463969Seric bp[8], bp[9], bp[10], bp[11], 218563969Seric bp[12], bp[13], bp[14], bp[15]); 218663969Seric } 218763969Seric 218863969Seric vsprintf(s, fmt, ap) 218963969Seric char * s; 219063969Seric char * fmt; 219163969Seric char ** ap; 219263969Seric { 219363969Seric char * bp[MAXARG]; 219463969Seric int i = 0; 219563969Seric 219663969Seric while (*ap && i < MAXARG) 219763969Seric bp[i++] = *ap++; 219863969Seric sprintf(s, fmt, bp[0], bp[1], bp[2], bp[3], 219963969Seric bp[4], bp[5], bp[6], bp[7], 220063969Seric bp[8], bp[9], bp[10], bp[11], 220163969Seric bp[12], bp[13], bp[14], bp[15]); 220263969Seric } 220363969Seric 220463969Seric #endif 220563969Seric /* 220665220Seric ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use 220765208Seric ** 220865211Seric ** Parameters: 220965211Seric ** shell -- the user's shell from /etc/passwd 221065211Seric ** 221165211Seric ** Returns: 221265211Seric ** TRUE -- if it is ok to use this for unrestricted access. 221365211Seric ** FALSE -- if the shell is restricted. 221465208Seric */ 221565208Seric 221665587Seric #if !HASGETUSERSHELL 221765587Seric 221865587Seric # ifndef _PATH_SHELLS 221965587Seric # define _PATH_SHELLS "/etc/shells" 222065587Seric # endif 222165587Seric 222269762Seric # ifdef _AIX3 222369762Seric # include <userconf.h> 222469762Seric # include <usersec.h> 222569762Seric # endif 222669762Seric 222765587Seric char *DefaultUserShells[] = 222865587Seric { 222968508Seric "/bin/sh", /* standard shell */ 223065587Seric "/usr/bin/sh", 223168508Seric "/bin/csh", /* C shell */ 223265587Seric "/usr/bin/csh", 223365587Seric #ifdef __hpux 223468889Seric # ifdef V4FS 223568889Seric "/usr/bin/rsh", /* restricted Bourne shell */ 223668889Seric "/usr/bin/ksh", /* Korn shell */ 223768889Seric "/usr/bin/rksh", /* restricted Korn shell */ 223868889Seric "/usr/bin/pam", 223968889Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 224068889Seric "/usr/bin/posix/sh", 224168889Seric # else 224268508Seric "/bin/rsh", /* restricted Bourne shell */ 224368508Seric "/bin/ksh", /* Korn shell */ 224468508Seric "/bin/rksh", /* restricted Korn shell */ 224565587Seric "/bin/pam", 224668508Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 224765587Seric "/bin/posix/sh", 224868889Seric # endif 224965211Seric #endif 225068508Seric #ifdef _AIX3 225168508Seric "/bin/ksh", /* Korn shell */ 225268508Seric "/usr/bin/ksh", 225368508Seric "/bin/tsh", /* trusted shell */ 225468508Seric "/usr/bin/tsh", 225568508Seric "/bin/bsh", /* Bourne shell */ 225668508Seric "/usr/bin/bsh", 225768508Seric #endif 225865587Seric NULL 225965587Seric }; 226065587Seric 226165208Seric #endif 226265208Seric 226365747Seric #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" 226465747Seric 226565211Seric bool 226665211Seric usershellok(shell) 226765211Seric char *shell; 226865208Seric { 226965211Seric #if HASGETUSERSHELL 227065211Seric register char *p; 227165211Seric extern char *getusershell(); 227265208Seric 227369505Seric if (shell == NULL || shell[0] == '\0' || ConfigLevel <= 1) 227468457Seric return TRUE; 227568457Seric 227665211Seric setusershell(); 227765211Seric while ((p = getusershell()) != NULL) 227865747Seric if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0) 227965211Seric break; 228065211Seric endusershell(); 228165211Seric return p != NULL; 228265211Seric #else 228369769Seric # if USEGETCONFATTR 228469762Seric auto char *v; 228569762Seric # endif 228665211Seric register FILE *shellf; 228765211Seric char buf[MAXLINE]; 228865208Seric 228968457Seric if (shell == NULL || shell[0] == '\0') 229068457Seric return TRUE; 229168457Seric 229269769Seric # if USEGETCONFATTR 229369769Seric /* 229469769Seric ** Naturally IBM has a "better" idea..... 229569769Seric ** 229669769Seric ** What a crock. This interface isn't documented, it is 229769769Seric ** considered part of the security library (-ls), and it 229869769Seric ** only works if you are running as root (since the list 229969769Seric ** of valid shells is obviously a source of great concern). 230069769Seric ** I recommend that you do NOT define USEGETCONFATTR, 230169769Seric ** especially since you are going to have to set up an 230269769Seric ** /etc/shells anyhow to handle the cases where getconfattr 230369769Seric ** fails. 230469769Seric */ 230569769Seric 230669769Seric if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL) 230769762Seric { 230869769Seric while (*v != '\0') 230969762Seric { 231069762Seric if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0) 231169762Seric return TRUE; 231269762Seric v += strlen(v) + 1; 231369762Seric } 231469769Seric return FALSE; 231569762Seric } 231669762Seric # endif 231769762Seric 231865211Seric shellf = fopen(_PATH_SHELLS, "r"); 231965211Seric if (shellf == NULL) 232065211Seric { 232165211Seric /* no /etc/shells; see if it is one of the std shells */ 232265587Seric char **d; 232365587Seric 232465587Seric for (d = DefaultUserShells; *d != NULL; d++) 232565587Seric { 232665587Seric if (strcmp(shell, *d) == 0) 232765587Seric return TRUE; 232865587Seric } 232965587Seric return FALSE; 233065211Seric } 233165208Seric 233265211Seric while (fgets(buf, sizeof buf, shellf) != NULL) 233365211Seric { 233465211Seric register char *p, *q; 233565208Seric 233665211Seric p = buf; 233765211Seric while (*p != '\0' && *p != '#' && *p != '/') 233865211Seric p++; 233965211Seric if (*p == '#' || *p == '\0') 234065208Seric continue; 234165211Seric q = p; 234265211Seric while (*p != '\0' && *p != '#' && !isspace(*p)) 234365211Seric p++; 234465211Seric *p = '\0'; 234565747Seric if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0) 234665211Seric { 234765211Seric fclose(shellf); 234865211Seric return TRUE; 234965211Seric } 235065208Seric } 235165211Seric fclose(shellf); 235265211Seric return FALSE; 235365211Seric #endif 235465208Seric } 235565208Seric /* 235669801Seric ** FREEDISKSPACE -- see how much free space is on the queue filesystem 235758082Seric ** 235858082Seric ** Only implemented if you have statfs. 235958082Seric ** 236058082Seric ** Parameters: 236164311Seric ** dir -- the directory in question. 236264311Seric ** bsize -- a variable into which the filesystem 236364311Seric ** block size is stored. 236458082Seric ** 236558082Seric ** Returns: 236664311Seric ** The number of bytes free on the queue filesystem. 236764311Seric ** -1 if the statfs call fails. 236864311Seric ** 236964311Seric ** Side effects: 237064311Seric ** Puts the filesystem block size into bsize. 237158082Seric */ 237258082Seric 237365749Seric /* statfs types */ 237465749Seric #define SFS_NONE 0 /* no statfs implementation */ 237565749Seric #define SFS_USTAT 1 /* use ustat */ 237665749Seric #define SFS_4ARGS 2 /* use four-argument statfs call */ 237765749Seric #define SFS_VFS 3 /* use <sys/vfs.h> implementation */ 237865749Seric #define SFS_MOUNT 4 /* use <sys/mount.h> implementation */ 237965749Seric #define SFS_STATFS 5 /* use <sys/statfs.h> implementation */ 238066752Seric #define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */ 238165749Seric 238265749Seric #ifndef SFS_TYPE 238365749Seric # define SFS_TYPE SFS_NONE 238458157Seric #endif 238558157Seric 238665749Seric #if SFS_TYPE == SFS_USTAT 238758157Seric # include <ustat.h> 238858157Seric #endif 238965749Seric #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS 239065749Seric # include <sys/statfs.h> 239158082Seric #endif 239265749Seric #if SFS_TYPE == SFS_VFS 239365749Seric # include <sys/vfs.h> 239465749Seric #endif 239565749Seric #if SFS_TYPE == SFS_MOUNT 239665749Seric # include <sys/mount.h> 239765749Seric #endif 239866752Seric #if SFS_TYPE == SFS_STATVFS 239966752Seric # include <sys/statvfs.h> 240066752Seric #endif 240158082Seric 240264311Seric long 240369801Seric freediskspace(dir, bsize) 240464311Seric char *dir; 240564311Seric long *bsize; 240658082Seric { 240765749Seric #if SFS_TYPE != SFS_NONE 240865749Seric # if SFS_TYPE == SFS_USTAT 240958153Seric struct ustat fs; 241058153Seric struct stat statbuf; 241158366Seric # define FSBLOCKSIZE DEV_BSIZE 241268695Seric # define SFS_BAVAIL f_tfree 241358157Seric # else 241458157Seric # if defined(ultrix) 241558157Seric struct fs_data fs; 241668695Seric # define SFS_BAVAIL fd_bfreen 241768508Seric # define FSBLOCKSIZE 1024L 241858153Seric # else 241966752Seric # if SFS_TYPE == SFS_STATVFS 242066752Seric struct statvfs fs; 242168508Seric # define FSBLOCKSIZE fs.f_frsize 242266752Seric # else 242358082Seric struct statfs fs; 242466752Seric # define FSBLOCKSIZE fs.f_bsize 242563987Seric # endif 242658153Seric # endif 242758133Seric # endif 242868695Seric # ifndef SFS_BAVAIL 242968695Seric # define SFS_BAVAIL f_bavail 243068508Seric # endif 243158082Seric 243265749Seric # if SFS_TYPE == SFS_USTAT 243364311Seric if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 243458157Seric # else 243565749Seric # if SFS_TYPE == SFS_4ARGS 243664311Seric if (statfs(dir, &fs, sizeof fs, 0) == 0) 243758157Seric # else 243868508Seric # if SFS_TYPE == SFS_STATVFS 243968508Seric if (statvfs(dir, &fs) == 0) 244068508Seric # else 244168508Seric # if defined(ultrix) 244268499Seric if (statfs(dir, &fs) > 0) 244368508Seric # else 244464311Seric if (statfs(dir, &fs) == 0) 244568508Seric # endif 244658153Seric # endif 244758133Seric # endif 244858133Seric # endif 244958133Seric { 245064311Seric if (bsize != NULL) 245164311Seric *bsize = FSBLOCKSIZE; 245268695Seric return (fs.SFS_BAVAIL); 245364311Seric } 245464337Seric #endif 245564311Seric return (-1); 245664311Seric } 245764311Seric /* 245869801Seric ** ENOUGHDISKSPACE -- is there enough free space on the queue fs? 245964311Seric ** 246064311Seric ** Only implemented if you have statfs. 246164311Seric ** 246264311Seric ** Parameters: 246364311Seric ** msize -- the size to check against. If zero, we don't yet 246464311Seric ** know how big the message will be, so just check for 246564311Seric ** a "reasonable" amount. 246664311Seric ** 246764311Seric ** Returns: 246864311Seric ** TRUE if there is enough space. 246964311Seric ** FALSE otherwise. 247064311Seric */ 247164311Seric 247264311Seric bool 247369801Seric enoughdiskspace(msize) 247464311Seric long msize; 247564311Seric { 247664311Seric long bfree, bsize; 247764311Seric 247864311Seric if (MinBlocksFree <= 0 && msize <= 0) 247964311Seric { 248058133Seric if (tTd(4, 80)) 248169801Seric printf("enoughdiskspace: no threshold\n"); 248264311Seric return TRUE; 248364311Seric } 248464311Seric 248569801Seric if ((bfree = freediskspace(QueueDir, &bsize)) >= 0) 248664311Seric { 248764311Seric if (tTd(4, 80)) 248869801Seric printf("enoughdiskspace: bavail=%ld, need=%ld\n", 248964311Seric bfree, msize); 249058333Seric 249158333Seric /* convert msize to block count */ 249264311Seric msize = msize / bsize + 1; 249358333Seric if (MinBlocksFree >= 0) 249458333Seric msize += MinBlocksFree; 249558333Seric 249664311Seric if (bfree < msize) 249758090Seric { 249858090Seric #ifdef LOG 249958090Seric if (LogLevel > 0) 250064254Seric syslog(LOG_ALERT, 250164254Seric "%s: low on space (have %ld, %s needs %ld in %s)", 250268508Seric CurEnv->e_id == NULL ? "[NOQUEUE]" : CurEnv->e_id, 250368508Seric bfree, 250468508Seric CurHostName == NULL ? "SMTP-DAEMON" : CurHostName, 250568508Seric msize, QueueDir); 250658090Seric #endif 250758082Seric return FALSE; 250858090Seric } 250958082Seric } 251058082Seric else if (tTd(4, 80)) 251169801Seric printf("enoughdiskspace failure: min=%ld, need=%ld: %s\n", 251258333Seric MinBlocksFree, msize, errstring(errno)); 251358082Seric return TRUE; 251458082Seric } 251558542Seric /* 251658542Seric ** TRANSIENTERROR -- tell if an error code indicates a transient failure 251758542Seric ** 251858542Seric ** This looks at an errno value and tells if this is likely to 251958542Seric ** go away if retried later. 252058542Seric ** 252158542Seric ** Parameters: 252258542Seric ** err -- the errno code to classify. 252358542Seric ** 252458542Seric ** Returns: 252558542Seric ** TRUE if this is probably transient. 252658542Seric ** FALSE otherwise. 252758542Seric */ 252858542Seric 252958542Seric bool 253058542Seric transienterror(err) 253158542Seric int err; 253258542Seric { 253358542Seric switch (err) 253458542Seric { 253558542Seric case EIO: /* I/O error */ 253658542Seric case ENXIO: /* Device not configured */ 253758542Seric case EAGAIN: /* Resource temporarily unavailable */ 253858542Seric case ENOMEM: /* Cannot allocate memory */ 253958542Seric case ENODEV: /* Operation not supported by device */ 254058542Seric case ENFILE: /* Too many open files in system */ 254158542Seric case EMFILE: /* Too many open files */ 254258542Seric case ENOSPC: /* No space left on device */ 254358542Seric #ifdef ETIMEDOUT 254458542Seric case ETIMEDOUT: /* Connection timed out */ 254558542Seric #endif 254658542Seric #ifdef ESTALE 254758542Seric case ESTALE: /* Stale NFS file handle */ 254858542Seric #endif 254958542Seric #ifdef ENETDOWN 255058542Seric case ENETDOWN: /* Network is down */ 255158542Seric #endif 255258542Seric #ifdef ENETUNREACH 255358542Seric case ENETUNREACH: /* Network is unreachable */ 255458542Seric #endif 255558542Seric #ifdef ENETRESET 255658542Seric case ENETRESET: /* Network dropped connection on reset */ 255758542Seric #endif 255858542Seric #ifdef ECONNABORTED 255958542Seric case ECONNABORTED: /* Software caused connection abort */ 256058542Seric #endif 256158542Seric #ifdef ECONNRESET 256258542Seric case ECONNRESET: /* Connection reset by peer */ 256358542Seric #endif 256458542Seric #ifdef ENOBUFS 256558542Seric case ENOBUFS: /* No buffer space available */ 256658542Seric #endif 256758542Seric #ifdef ESHUTDOWN 256858542Seric case ESHUTDOWN: /* Can't send after socket shutdown */ 256958542Seric #endif 257058542Seric #ifdef ECONNREFUSED 257158542Seric case ECONNREFUSED: /* Connection refused */ 257258542Seric #endif 257358542Seric #ifdef EHOSTDOWN 257458542Seric case EHOSTDOWN: /* Host is down */ 257558542Seric #endif 257658542Seric #ifdef EHOSTUNREACH 257758542Seric case EHOSTUNREACH: /* No route to host */ 257858542Seric #endif 257958542Seric #ifdef EDQUOT 258058542Seric case EDQUOT: /* Disc quota exceeded */ 258158542Seric #endif 258258542Seric #ifdef EPROCLIM 258358542Seric case EPROCLIM: /* Too many processes */ 258458542Seric #endif 258558542Seric #ifdef EUSERS 258658542Seric case EUSERS: /* Too many users */ 258758542Seric #endif 258858542Seric #ifdef EDEADLK 258958542Seric case EDEADLK: /* Resource deadlock avoided */ 259058542Seric #endif 259158542Seric #ifdef EISCONN 259258542Seric case EISCONN: /* Socket already connected */ 259358542Seric #endif 259458542Seric #ifdef EINPROGRESS 259558542Seric case EINPROGRESS: /* Operation now in progress */ 259658542Seric #endif 259758542Seric #ifdef EALREADY 259858542Seric case EALREADY: /* Operation already in progress */ 259958542Seric #endif 260058542Seric #ifdef EADDRINUSE 260158542Seric case EADDRINUSE: /* Address already in use */ 260258542Seric #endif 260358542Seric #ifdef EADDRNOTAVAIL 260458542Seric case EADDRNOTAVAIL: /* Can't assign requested address */ 260558542Seric #endif 260666018Seric #ifdef ETXTBSY 260766017Seric case ETXTBSY: /* (Apollo) file locked */ 260866017Seric #endif 260963834Seric #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) 261058542Seric case ENOSR: /* Out of streams resources */ 261158542Seric #endif 261258542Seric return TRUE; 261358542Seric } 261458542Seric 261558542Seric /* nope, must be permanent */ 261658542Seric return FALSE; 261758542Seric } 261858689Seric /* 261964035Seric ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking 262058689Seric ** 262158689Seric ** Parameters: 262258689Seric ** fd -- the file descriptor of the file. 262358689Seric ** filename -- the file name (for error messages). 262464335Seric ** ext -- the filename extension. 262558689Seric ** type -- type of the lock. Bits can be: 262658689Seric ** LOCK_EX -- exclusive lock. 262758689Seric ** LOCK_NB -- non-blocking. 262858689Seric ** 262958689Seric ** Returns: 263058689Seric ** TRUE if the lock was acquired. 263158689Seric ** FALSE otherwise. 263258689Seric */ 263358689Seric 263458689Seric bool 263564335Seric lockfile(fd, filename, ext, type) 263658689Seric int fd; 263758689Seric char *filename; 263864335Seric char *ext; 263958689Seric int type; 264058689Seric { 264165830Seric # if !HASFLOCK 264258689Seric int action; 264358689Seric struct flock lfd; 264464335Seric 264564335Seric if (ext == NULL) 264664335Seric ext = ""; 264769472Seric 264863983Seric bzero(&lfd, sizeof lfd); 264959447Seric if (bitset(LOCK_UN, type)) 265059447Seric lfd.l_type = F_UNLCK; 265159447Seric else if (bitset(LOCK_EX, type)) 265258689Seric lfd.l_type = F_WRLCK; 265358689Seric else 265458689Seric lfd.l_type = F_RDLCK; 265558689Seric 265658689Seric if (bitset(LOCK_NB, type)) 265758689Seric action = F_SETLK; 265858689Seric else 265958689Seric action = F_SETLKW; 266058689Seric 266164264Seric if (tTd(55, 60)) 266264335Seric printf("lockfile(%s%s, action=%d, type=%d): ", 266364335Seric filename, ext, action, lfd.l_type); 266464264Seric 266558689Seric if (fcntl(fd, action, &lfd) >= 0) 266664264Seric { 266764264Seric if (tTd(55, 60)) 266864264Seric printf("SUCCESS\n"); 266958689Seric return TRUE; 267064264Seric } 267158689Seric 267264264Seric if (tTd(55, 60)) 267364264Seric printf("(%s) ", errstring(errno)); 267464264Seric 267564136Seric /* 267664136Seric ** On SunOS, if you are testing using -oQ/tmp/mqueue or 267764136Seric ** -oA/tmp/aliases or anything like that, and /tmp is mounted 267864136Seric ** as type "tmp" (that is, served from swap space), the 267964136Seric ** previous fcntl will fail with "Invalid argument" errors. 268064136Seric ** Since this is fairly common during testing, we will assume 268164136Seric ** that this indicates that the lock is successfully grabbed. 268264136Seric */ 268364136Seric 268464136Seric if (errno == EINVAL) 268564264Seric { 268664264Seric if (tTd(55, 60)) 268764264Seric printf("SUCCESS\n"); 268864136Seric return TRUE; 268964264Seric } 269064136Seric 269158689Seric if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 269264378Seric { 269364378Seric int omode = -1; 269464378Seric # ifdef F_GETFL 269564378Seric int oerrno = errno; 269664378Seric 269764378Seric (void) fcntl(fd, F_GETFL, &omode); 269864378Seric errno = oerrno; 269964378Seric # endif 270064378Seric syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 270164378Seric filename, ext, fd, type, omode, geteuid()); 270264378Seric } 270358689Seric # else 270464335Seric if (ext == NULL) 270564335Seric ext = ""; 270664335Seric 270764264Seric if (tTd(55, 60)) 270864335Seric printf("lockfile(%s%s, type=%o): ", filename, ext, type); 270964264Seric 271058689Seric if (flock(fd, type) >= 0) 271164264Seric { 271264264Seric if (tTd(55, 60)) 271364264Seric printf("SUCCESS\n"); 271458689Seric return TRUE; 271564264Seric } 271658689Seric 271764264Seric if (tTd(55, 60)) 271864264Seric printf("(%s) ", errstring(errno)); 271964264Seric 272058689Seric if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 272164378Seric { 272264378Seric int omode = -1; 272364378Seric # ifdef F_GETFL 272464378Seric int oerrno = errno; 272564378Seric 272664378Seric (void) fcntl(fd, F_GETFL, &omode); 272764378Seric errno = oerrno; 272864378Seric # endif 272964378Seric syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 273064378Seric filename, ext, fd, type, omode, geteuid()); 273164386Seric } 273258689Seric # endif 273364264Seric if (tTd(55, 60)) 273464264Seric printf("FAIL\n"); 273558689Seric return FALSE; 273658689Seric } 273764556Seric /* 273865948Seric ** CHOWNSAFE -- tell if chown is "safe" (executable only by root) 273965948Seric ** 274065948Seric ** Parameters: 274165948Seric ** fd -- the file descriptor to check. 274265948Seric ** 274365948Seric ** Returns: 274465948Seric ** TRUE -- if only root can chown the file to an arbitrary 274565948Seric ** user. 274665948Seric ** FALSE -- if an arbitrary user can give away a file. 274765948Seric */ 274865948Seric 274965948Seric bool 275065948Seric chownsafe(fd) 275165948Seric int fd; 275265948Seric { 275365950Seric #ifdef __hpux 275465948Seric char *s; 275565948Seric int tfd; 275665948Seric uid_t o_uid, o_euid; 275765948Seric gid_t o_gid, o_egid; 275865948Seric bool rval; 275965948Seric struct stat stbuf; 276065948Seric 276165948Seric o_uid = getuid(); 276265948Seric o_euid = geteuid(); 276365948Seric o_gid = getgid(); 276465948Seric o_egid = getegid(); 276565959Seric fstat(fd, &stbuf); 276665948Seric setresuid(stbuf.st_uid, stbuf.st_uid, -1); 276765948Seric setresgid(stbuf.st_gid, stbuf.st_gid, -1); 276865948Seric s = tmpnam(NULL); 276965948Seric tfd = open(s, O_RDONLY|O_CREAT, 0600); 277065974Seric rval = fchown(tfd, DefUid, DefGid) != 0; 277165948Seric close(tfd); 277265948Seric unlink(s); 277369638Seric setresuid(o_uid, o_euid, -1); 277465948Seric setresgid(o_gid, o_egid, -1); 277565948Seric return rval; 277665948Seric #else 277766088Seric # ifdef _POSIX_CHOWN_RESTRICTED 277866088Seric # if _POSIX_CHOWN_RESTRICTED == -1 277966088Seric return FALSE; 278066088Seric # else 278166088Seric return TRUE; 278266088Seric # endif 278366088Seric # else 278466088Seric # ifdef _PC_CHOWN_RESTRICTED 278568508Seric int rval; 278668508Seric 278768508Seric /* 278868508Seric ** Some systems (e.g., SunOS) seem to have the call and the 278968508Seric ** #define _PC_CHOWN_RESTRICTED, but don't actually implement 279068508Seric ** the call. This heuristic checks for that. 279168508Seric */ 279268508Seric 279368508Seric errno = 0; 279468508Seric rval = fpathconf(fd, _PC_CHOWN_RESTRICTED); 279568508Seric if (errno == 0) 279668508Seric return rval > 0; 279768508Seric # endif 279868508Seric # ifdef BSD 279968508Seric return TRUE; 280068499Seric # else 280165948Seric return FALSE; 280265948Seric # endif 280365948Seric # endif 280465948Seric #endif 280565948Seric } 280665948Seric /* 280768508Seric ** RESETLIMITS -- reset system controlled resource limits 280868508Seric ** 280968508Seric ** This is to avoid denial-of-service attacks 281068508Seric ** 281168508Seric ** Parameters: 281268508Seric ** none 281368508Seric ** 281468508Seric ** Returns: 281568508Seric ** none 281668508Seric */ 281768508Seric 281868508Seric #if HASSETRLIMIT 281968508Seric # include <sys/resource.h> 282068508Seric #endif 282168508Seric 282268508Seric void 282368508Seric resetlimits() 282468508Seric { 282568508Seric #if HASSETRLIMIT 282668508Seric struct rlimit lim; 282768508Seric 282868508Seric lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; 282968508Seric (void) setrlimit(RLIMIT_CPU, &lim); 283068508Seric (void) setrlimit(RLIMIT_FSIZE, &lim); 283168508Seric #else 283268508Seric # if HASULIMIT 283368508Seric (void) ulimit(2, 0x3fffff); 283468508Seric # endif 283568508Seric #endif 283668508Seric } 283768508Seric /* 283864556Seric ** GETCFNAME -- return the name of the .cf file. 283964556Seric ** 284064556Seric ** Some systems (e.g., NeXT) determine this dynamically. 284164556Seric */ 284264556Seric 284364556Seric char * 284464556Seric getcfname() 284564556Seric { 284669748Seric #ifdef TRY_VERSIONED_CF_NAME 284768842Seric int i; 284868842Seric static char cbuf[200]; 284969748Seric #endif 285068842Seric 285164556Seric if (ConfFile != NULL) 285264556Seric return ConfFile; 285365214Seric #ifdef NETINFO 285465214Seric { 285565214Seric extern char *ni_propval(); 285665214Seric char *cflocation; 285765214Seric 285868508Seric cflocation = ni_propval("/locations", NULL, "sendmail", 285968508Seric "sendmail.cf", '\0'); 286065214Seric if (cflocation != NULL) 286165214Seric return cflocation; 286265214Seric } 286365214Seric #endif 286468842Seric 286569396Seric #ifdef TRY_VERSIONED_CF_NAME 286668842Seric /* 286768842Seric ** Try sendmail.8.6.12.cf, then sendmail.8.6.cf, then 286868842Seric ** sendmail.8.cf, and finally sendmail.cf. 286968842Seric ** 287068842Seric ** I suppose it should really try a search path here -- 287168842Seric ** e.g., /etc/sendmail.cf, /etc/mail/sendmail.cf, 287268842Seric ** /usr/lib/sendmail.cf, and so forth. 287368842Seric */ 287468842Seric 287568842Seric strcpy(cbuf, _PATH_SENDMAILCF); 287668842Seric i = strlen(cbuf); 287768842Seric if (strcmp(&cbuf[i - 3], ".cf") == 0) 287868842Seric { 287968842Seric char *p; 288068842Seric extern char Version[]; 288168842Seric 288268842Seric strcpy(&cbuf[i - 2], Version); 288368842Seric p = strchr(&cbuf[i - 2], '/'); 288468842Seric if (p != NULL) 288568842Seric *p = '\0'; 288668842Seric p = &cbuf[strlen(cbuf)]; 288768842Seric do 288868842Seric { 288968842Seric int fd; 289068842Seric 289168842Seric strcpy(p, ".cf"); 289268842Seric if ((fd = open(cbuf, O_RDONLY, 0)) >= 0) 289368842Seric { 289468842Seric close(fd); 289568842Seric return cbuf; 289668842Seric } 289768842Seric *p = '\0'; 289868842Seric } while ((p = strrchr(&cbuf[i - 2], '.')) != NULL); 289968842Seric } 290069396Seric #endif 290164556Seric return _PATH_SENDMAILCF; 290264556Seric } 290364718Seric /* 290464718Seric ** SETVENDOR -- process vendor code from V configuration line 290564718Seric ** 290664718Seric ** Parameters: 290764718Seric ** vendor -- string representation of vendor. 290864718Seric ** 290964718Seric ** Returns: 291064718Seric ** TRUE -- if ok. 291164718Seric ** FALSE -- if vendor code could not be processed. 291264926Seric ** 291364926Seric ** Side Effects: 291464926Seric ** It is reasonable to set mode flags here to tweak 291564926Seric ** processing in other parts of the code if necessary. 291664926Seric ** For example, if you are a vendor that uses $%y to 291764926Seric ** indicate YP lookups, you could enable that here. 291864718Seric */ 291964718Seric 292064718Seric bool 292164718Seric setvendor(vendor) 292264718Seric char *vendor; 292364718Seric { 292464926Seric if (strcasecmp(vendor, "Berkeley") == 0) 292568508Seric { 292668508Seric VendorCode = VENDOR_BERKELEY; 292764926Seric return TRUE; 292868508Seric } 292964926Seric 293064926Seric /* add vendor extensions here */ 293164926Seric 293268508Seric #ifdef SUN_EXTENSIONS 293368508Seric if (strcasecmp(vendor, "Sun") == 0) 293468508Seric { 293568508Seric VendorCode = VENDOR_SUN; 293668508Seric return TRUE; 293768508Seric } 293868508Seric #endif 293968508Seric 294064926Seric return FALSE; 294164718Seric } 294264816Seric /* 294369510Seric ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults 294469510Seric ** 294569510Seric ** Vendor_pre_defaults is called before reading the configuration 294669510Seric ** file; vendor_post_defaults is called immediately after. 294769510Seric ** 294869510Seric ** Parameters: 294969510Seric ** e -- the global environment to initialize. 295069510Seric ** 295169510Seric ** Returns: 295269510Seric ** none. 295369510Seric */ 295469510Seric 295569510Seric void 295669510Seric vendor_pre_defaults(e) 295769510Seric ENVELOPE *e; 295869510Seric { 295969510Seric } 296069510Seric 296169510Seric 296269510Seric void 296369510Seric vendor_post_defaults(e) 296469510Seric ENVELOPE *e; 296569510Seric { 296669510Seric } 296769510Seric /* 296864816Seric ** STRTOL -- convert string to long integer 296964816Seric ** 297064816Seric ** For systems that don't have it in the C library. 297166161Seric ** 297266161Seric ** This is taken verbatim from the 4.4-Lite C library. 297364816Seric */ 297464816Seric 297564816Seric #ifdef NEEDSTRTOL 297664816Seric 297766161Seric #if defined(LIBC_SCCS) && !defined(lint) 297866161Seric static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; 297966161Seric #endif /* LIBC_SCCS and not lint */ 298066161Seric 298166161Seric #include <limits.h> 298266161Seric 298366161Seric /* 298466161Seric * Convert a string to a long integer. 298566161Seric * 298666161Seric * Ignores `locale' stuff. Assumes that the upper and lower case 298766161Seric * alphabets and digits are each contiguous. 298866161Seric */ 298966161Seric 299064816Seric long 299166161Seric strtol(nptr, endptr, base) 299266161Seric const char *nptr; 299366161Seric char **endptr; 299466161Seric register int base; 299564816Seric { 299666161Seric register const char *s = nptr; 299766161Seric register unsigned long acc; 299866161Seric register int c; 299966161Seric register unsigned long cutoff; 300066161Seric register int neg = 0, any, cutlim; 300164816Seric 300266161Seric /* 300366161Seric * Skip white space and pick up leading +/- sign if any. 300466161Seric * If base is 0, allow 0x for hex and 0 for octal, else 300566161Seric * assume decimal; if base is already 16, allow 0x. 300666161Seric */ 300766161Seric do { 300866161Seric c = *s++; 300966161Seric } while (isspace(c)); 301066161Seric if (c == '-') { 301166161Seric neg = 1; 301266161Seric c = *s++; 301366161Seric } else if (c == '+') 301466161Seric c = *s++; 301566161Seric if ((base == 0 || base == 16) && 301666161Seric c == '0' && (*s == 'x' || *s == 'X')) { 301766161Seric c = s[1]; 301866161Seric s += 2; 301966161Seric base = 16; 302066161Seric } 302166161Seric if (base == 0) 302266161Seric base = c == '0' ? 8 : 10; 302364816Seric 302466161Seric /* 302566161Seric * Compute the cutoff value between legal numbers and illegal 302666161Seric * numbers. That is the largest legal value, divided by the 302766161Seric * base. An input number that is greater than this value, if 302866161Seric * followed by a legal input character, is too big. One that 302966161Seric * is equal to this value may be valid or not; the limit 303066161Seric * between valid and invalid numbers is then based on the last 303166161Seric * digit. For instance, if the range for longs is 303266161Seric * [-2147483648..2147483647] and the input base is 10, 303366161Seric * cutoff will be set to 214748364 and cutlim to either 303466161Seric * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 303566161Seric * a value > 214748364, or equal but the next digit is > 7 (or 8), 303666161Seric * the number is too big, and we will return a range error. 303766161Seric * 303866161Seric * Set any if any `digits' consumed; make it negative to indicate 303966161Seric * overflow. 304066161Seric */ 304166161Seric cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; 304266161Seric cutlim = cutoff % (unsigned long)base; 304366161Seric cutoff /= (unsigned long)base; 304466161Seric for (acc = 0, any = 0;; c = *s++) { 304566161Seric if (isdigit(c)) 304666161Seric c -= '0'; 304766161Seric else if (isalpha(c)) 304866161Seric c -= isupper(c) ? 'A' - 10 : 'a' - 10; 304966161Seric else 305066161Seric break; 305166161Seric if (c >= base) 305266161Seric break; 305366161Seric if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) 305466161Seric any = -1; 305566161Seric else { 305666161Seric any = 1; 305766161Seric acc *= base; 305866161Seric acc += c; 305964816Seric } 306064816Seric } 306166161Seric if (any < 0) { 306266161Seric acc = neg ? LONG_MIN : LONG_MAX; 306366161Seric errno = ERANGE; 306466161Seric } else if (neg) 306566161Seric acc = -acc; 306666161Seric if (endptr != 0) 306766161Seric *endptr = (char *)(any ? s - 1 : nptr); 306866161Seric return (acc); 306964816Seric } 307064816Seric 307164816Seric #endif 307264841Seric /* 307369679Seric ** STRSTR -- find first substring in string 307469679Seric ** 307569679Seric ** Parameters: 307669679Seric ** big -- the big (full) string. 307769679Seric ** little -- the little (sub) string. 307869679Seric ** 307969679Seric ** Returns: 308069679Seric ** A pointer to the first instance of little in big. 308169679Seric ** big if little is the null string. 308269679Seric ** NULL if little is not contained in big. 308369679Seric */ 308469679Seric 308569679Seric #ifdef NEEDSTRSTR 308669679Seric 308769679Seric char * 308869679Seric strstr(big, little) 308969679Seric char *big; 309069679Seric char *little; 309169679Seric { 309269679Seric register char *p = big; 309369679Seric int l; 309469679Seric 309569679Seric if (*little == '\0') 309669679Seric return big; 309769679Seric l = strlen(little); 309869679Seric 309969679Seric while ((p = strchr(p, *little)) != NULL) 310069679Seric { 310169679Seric if (strncmp(p, little, l) == 0) 310269679Seric return p; 310369679Seric p++; 310469679Seric } 310569679Seric return NULL; 310669679Seric } 310769679Seric 310869679Seric #endif 310969679Seric /* 311068693Seric ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX 311164841Seric ** 311268693Seric ** Some operating systems have wierd problems with the gethostbyXXX 311368693Seric ** routines. For example, Solaris versions at least through 2.3 311468693Seric ** don't properly deliver a canonical h_name field. This tries to 311568693Seric ** work around these problems. 311664841Seric */ 311764841Seric 311864841Seric struct hostent * 311968693Seric sm_gethostbyname(name) 312068707Seric char *name; 312164841Seric { 312269777Seric struct hostent *h; 312369654Seric #if defined(SOLARIS) && SOLARIS < 204 || defined(sony_news) && defined(__svr4) 312468693Seric extern int h_errno; 312568693Seric 312668508Seric # if SOLARIS == 203 312764841Seric static struct hostent hp; 312864841Seric static char buf[1000]; 312964841Seric extern struct hostent *_switch_gethostbyname_r(); 313064841Seric 313169777Seric if (tTd(61, 10)) 313269777Seric printf("_switch_gethostbyname_r(%s)... ", name); 313369777Seric h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 313464841Seric # else 313565009Seric extern struct hostent *__switch_gethostbyname(); 313665009Seric 313769777Seric if (tTd(61, 10)) 313869777Seric printf("__switch_gethostbyname(%s)... ", name); 313969777Seric h = __switch_gethostbyname(name); 314064841Seric # endif 314168693Seric #else 314269777Seric # if defined(NIS) 314369687Seric int nmaps; 314469687Seric char *maptype[MAXMAPSTACK]; 314569687Seric short mapreturn[MAXMAPACTIONS]; 314669687Seric char hbuf[MAXNAME]; 314769777Seric # endif 314869687Seric 314969777Seric if (tTd(61, 10)) 315069777Seric printf("gethostbyname(%s)... ", name); 315169687Seric h = gethostbyname(name); 315269687Seric # if defined(NIS) 315369777Seric if (h == NULL) 315469687Seric { 315569777Seric if (tTd(61, 10)) 315669777Seric printf("failure\n"); 315769687Seric 315869777Seric nmaps = switch_map_find("hosts", maptype, mapreturn); 315969777Seric while (--nmaps >= 0) 316069777Seric if (strcmp(maptype[nmaps], "nis") == 0) 316169777Seric break; 316269777Seric if (nmaps >= 0) 316369777Seric { 316469777Seric /* try short name */ 316569777Seric if (strlen(name) > sizeof hbuf - 1) 316669777Seric return NULL; 316769777Seric strcpy(hbuf, name); 316869777Seric shorten_hostname(hbuf); 316969777Seric 317069777Seric /* if it hasn't been shortened, there's no point */ 317169777Seric if (strcmp(hbuf, name) != 0) 317269777Seric { 317369777Seric if (tTd(61, 10)) 317469777Seric printf("gethostbyname(%s)... ", hbuf); 317569777Seric h = gethostbyname(hbuf); 317669777Seric } 317769777Seric } 317869687Seric } 317969687Seric # endif 318069777Seric #endif 318169777Seric if (tTd(61, 10)) 318269777Seric { 318369777Seric if (h == NULL) 318469777Seric printf("failure\n"); 318569777Seric else 318669777Seric printf("%s\n", h->h_name); 318769777Seric } 318869687Seric return h; 318964841Seric } 319064841Seric 319164841Seric struct hostent * 319268693Seric sm_gethostbyaddr(addr, len, type) 319368707Seric char *addr; 319464841Seric int len; 319564841Seric int type; 319664841Seric { 319768693Seric #if defined(SOLARIS) && SOLARIS < 204 319868693Seric extern int h_errno; 319968693Seric 320068508Seric # if SOLARIS == 203 320164841Seric static struct hostent hp; 320264841Seric static char buf[1000]; 320364841Seric extern struct hostent *_switch_gethostbyaddr_r(); 320464841Seric 320564841Seric return _switch_gethostbyaddr_r(addr, len, type, &hp, buf, sizeof(buf), &h_errno); 320664841Seric # else 320765009Seric extern struct hostent *__switch_gethostbyaddr(); 320865009Seric 320964841Seric return __switch_gethostbyaddr(addr, len, type); 321064841Seric # endif 321168693Seric #else 321268693Seric return gethostbyaddr(addr, len, type); 321368693Seric #endif 321464841Seric } 321568693Seric /* 321668693Seric ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid 321768693Seric */ 321864841Seric 321968693Seric struct passwd * 322068693Seric sm_getpwnam(user) 322168704Seric char *user; 322268693Seric { 322368693Seric return getpwnam(user); 322468693Seric } 322568693Seric 322668693Seric struct passwd * 322768693Seric sm_getpwuid(uid) 322868693Seric uid_t uid; 322968693Seric { 323068693Seric return getpwuid(uid); 323168693Seric } 323265214Seric /* 323369472Seric ** LOAD_IF_NAMES -- load interface-specific names into $=w 323469472Seric ** 323569472Seric ** Parameters: 323669472Seric ** none. 323769472Seric ** 323869472Seric ** Returns: 323969472Seric ** none. 324069472Seric ** 324169472Seric ** Side Effects: 324269472Seric ** Loads $=w with the names of all the interfaces. 324369472Seric */ 324469472Seric 324569472Seric #ifdef SIOCGIFCONF 324669565Seric struct rtentry; 324769565Seric struct mbuf; 324869472Seric # include <arpa/inet.h> 324969562Seric # include <sys/time.h> 325069472Seric # include <net/if.h> 325169472Seric #endif 325269472Seric 325369472Seric void 325469472Seric load_if_names() 325569472Seric { 325669472Seric #ifdef SIOCGIFCONF 325769472Seric int s; 325869516Seric int i; 325969472Seric struct ifconf ifc; 326069472Seric char interfacebuf[1024]; 326169472Seric 326269472Seric s = socket(AF_INET, SOCK_DGRAM, 0); 326369472Seric if (s == -1) 326469472Seric return; 326569472Seric 326669472Seric /* get the list of known IP address from the kernel */ 326769472Seric ifc.ifc_buf = interfacebuf; 326869516Seric ifc.ifc_len = sizeof interfacebuf; 326969472Seric if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) 327069472Seric { 327169472Seric if (tTd(0, 4)) 327269472Seric printf("SIOGIFCONF failed: %s\n", errstring(errno)); 327369516Seric close(s); 327469472Seric return; 327569472Seric } 327669516Seric close(s); 327769472Seric 327869472Seric /* scan the list of IP address */ 327969472Seric if (tTd(0, 4)) 328069472Seric printf("scanning for interface specific names, ifc_len=%d\n", 328169472Seric ifc.ifc_len); 328269472Seric 328369516Seric for (i = 0; i < ifc.ifc_len; ) 328469516Seric { 328569516Seric struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i]; 328669516Seric struct sockaddr *sa = &ifr->ifr_addr; 328769472Seric struct in_addr ia; 328869516Seric struct hostent *hp; 328969472Seric char ip_addr[256]; 329069516Seric extern char *inet_ntoa(); 329169516Seric extern struct hostent *gethostbyaddr(); 329269472Seric 329369516Seric #ifdef BSD4_4_SOCKADDR 329469516Seric if (sa->sa_len > sizeof ifr->ifr_addr) 329569516Seric i += sizeof ifr->ifr_name + sa->sa_len; 329669516Seric else 329769516Seric #endif 329869516Seric i += sizeof *ifr; 329969516Seric 330069472Seric if (tTd(0, 20)) 330169516Seric printf("%s\n", anynet_ntoa((SOCKADDR *) sa)); 330269472Seric 330369472Seric if (ifr->ifr_addr.sa_family != AF_INET) 330469472Seric continue; 330569472Seric 330669472Seric /* extract IP address from the list*/ 330769516Seric ia = (((struct sockaddr_in *) sa)->sin_addr); 330869472Seric 330969472Seric /* save IP address in text from */ 331069472Seric (void) sprintf(ip_addr, "[%s]", 331169516Seric inet_ntoa(((struct sockaddr_in *) sa)->sin_addr)); 331269472Seric if (!wordinclass(ip_addr, 'w')) 331369472Seric { 331469472Seric setclass('w', ip_addr); 331569472Seric if (tTd(0, 4)) 331669472Seric printf("\ta.k.a.: %s\n", ip_addr); 331769472Seric } 331869472Seric 331969472Seric /* skip "loopback" interface "lo" */ 332069472Seric if (strcmp("lo0", ifr->ifr_name) == 0) 332169472Seric continue; 332269472Seric 332369472Seric /* lookup name with IP address */ 332469472Seric hp = sm_gethostbyaddr((char *) &ia, sizeof(ia), AF_INET); 332569472Seric if (hp == NULL) 332669472Seric { 332769472Seric syslog(LOG_CRIT, "gethostbyaddr() failed for %s\n", 332869472Seric inet_ntoa(ia)); 332969472Seric continue; 333069472Seric } 333169472Seric 333269472Seric /* save its cname */ 333369472Seric if (!wordinclass(hp->h_name, 'w')) 333469472Seric { 333569472Seric setclass('w', hp->h_name); 333669472Seric if (tTd(0, 4)) 333769472Seric printf("\ta.k.a.: %s\n", hp->h_name); 333869472Seric } 333969472Seric 334069472Seric /* save all it aliases name */ 334169472Seric while (*hp->h_aliases) 334269472Seric { 334369472Seric if (!wordinclass(*hp->h_aliases, 'w')) 334469472Seric { 334569472Seric setclass('w', *hp->h_aliases); 334669472Seric if (tTd(0, 4)) 334769472Seric printf("\ta.k.a.: %s\n", *hp->h_aliases); 334869472Seric } 334969472Seric hp->h_aliases++; 335069472Seric } 335169472Seric } 335269472Seric #endif 335369472Seric } 335469472Seric /* 335565214Seric ** NI_PROPVAL -- netinfo property value lookup routine 335665214Seric ** 335765214Seric ** Parameters: 335868508Seric ** keydir -- the Netinfo directory name in which to search 335968508Seric ** for the key. 336068508Seric ** keyprop -- the name of the property in which to find the 336168508Seric ** property we are interested. Defaults to "name". 336268508Seric ** keyval -- the value for which we are really searching. 336368508Seric ** valprop -- the property name for the value in which we 336468508Seric ** are interested. 336568508Seric ** sepchar -- if non-nil, this can be multiple-valued, and 336668508Seric ** we should return a string separated by this 336768508Seric ** character. 336865214Seric ** 336965214Seric ** Returns: 337065214Seric ** NULL -- if: 337165214Seric ** 1. the directory is not found 337265214Seric ** 2. the property name is not found 337365214Seric ** 3. the property contains multiple values 337465214Seric ** 4. some error occured 337565214Seric ** else -- the location of the config file. 337665214Seric ** 337768508Seric ** Example: 337868508Seric ** To search for an alias value, use: 337968508Seric ** ni_propval("/aliases", "name", aliasname, "members", ',') 338068508Seric ** 338165214Seric ** Notes: 338265214Seric ** Caller should free the return value of ni_proval 338365214Seric */ 338465214Seric 338565214Seric #ifdef NETINFO 338665214Seric 338765214Seric # include <netinfo/ni.h> 338865214Seric 338965214Seric # define LOCAL_NETINFO_DOMAIN "." 339065214Seric # define PARENT_NETINFO_DOMAIN ".." 339165214Seric # define MAX_NI_LEVELS 256 339265214Seric 339365214Seric char * 339468508Seric ni_propval(keydir, keyprop, keyval, valprop, sepchar) 339568508Seric char *keydir; 339668508Seric char *keyprop; 339768508Seric char *keyval; 339868508Seric char *valprop; 339968508Seric char sepchar; 340065214Seric { 340165820Seric char *propval = NULL; 340265214Seric int i; 340368508Seric int j, alen; 340465214Seric void *ni = NULL; 340565214Seric void *lastni = NULL; 340665214Seric ni_status nis; 340765214Seric ni_id nid; 340865214Seric ni_namelist ninl; 340968508Seric register char *p; 341068508Seric char keybuf[1024]; 341165214Seric 341265214Seric /* 341368508Seric ** Create the full key from the two parts. 341468508Seric ** 341568508Seric ** Note that directory can end with, e.g., "name=" to specify 341668508Seric ** an alternate search property. 341768508Seric */ 341868508Seric 341968508Seric i = strlen(keydir) + strlen(keyval) + 2; 342068508Seric if (keyprop != NULL) 342168508Seric i += strlen(keyprop) + 1; 342268508Seric if (i > sizeof keybuf) 342368508Seric return NULL; 342468508Seric strcpy(keybuf, keydir); 342568508Seric strcat(keybuf, "/"); 342668508Seric if (keyprop != NULL) 342768508Seric { 342868508Seric strcat(keybuf, keyprop); 342968508Seric strcat(keybuf, "="); 343068508Seric } 343168508Seric strcat(keybuf, keyval); 343268508Seric 343368508Seric /* 343465214Seric ** If the passed directory and property name are found 343565214Seric ** in one of netinfo domains we need to search (starting 343665214Seric ** from the local domain moving all the way back to the 343765214Seric ** root domain) set propval to the property's value 343865214Seric ** and return it. 343965214Seric */ 344065214Seric 344165214Seric for (i = 0; i < MAX_NI_LEVELS; ++i) 344265214Seric { 344365214Seric if (i == 0) 344465214Seric { 344565214Seric nis = ni_open(NULL, LOCAL_NETINFO_DOMAIN, &ni); 344665214Seric } 344765214Seric else 344865214Seric { 344965214Seric if (lastni != NULL) 345065214Seric ni_free(lastni); 345165214Seric lastni = ni; 345265214Seric nis = ni_open(lastni, PARENT_NETINFO_DOMAIN, &ni); 345365214Seric } 345465214Seric 345565214Seric /* 345665214Seric ** Don't bother if we didn't get a handle on a 345765214Seric ** proper domain. This is not necessarily an error. 345865214Seric ** We would get a positive ni_status if, for instance 345965214Seric ** we never found the directory or property and tried 346065214Seric ** to open the parent of the root domain! 346165214Seric */ 346265214Seric 346365214Seric if (nis != 0) 346465214Seric break; 346565214Seric 346665214Seric /* 346765214Seric ** Find the path to the server information. 346865214Seric */ 346965214Seric 347068508Seric if (ni_pathsearch(ni, &nid, keybuf) != 0) 347165214Seric continue; 347265214Seric 347365214Seric /* 347468508Seric ** Find associated value information. 347565214Seric */ 347665214Seric 347768508Seric if (ni_lookupprop(ni, &nid, valprop, &ninl) != 0) 347865214Seric continue; 347965214Seric 348065214Seric /* 348168508Seric ** See if we have an acceptable number of values. 348265214Seric */ 348365214Seric 348468508Seric if (ninl.ni_namelist_len <= 0) 348568508Seric continue; 348668508Seric 348768508Seric if (sepchar == '\0' && ninl.ni_namelist_len > 1) 348865214Seric { 348968508Seric ni_namelist_free(&ninl); 349068508Seric continue; 349165214Seric } 349268508Seric 349369472Seric /* 349468508Seric ** Calculate number of bytes needed and build result 349568508Seric */ 349668508Seric 349768508Seric alen = 1; 349868508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 349968508Seric alen += strlen(ninl.ni_namelist_val[j]) + 1; 350068508Seric propval = p = xalloc(alen); 350168508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 350268508Seric { 350368508Seric strcpy(p, ninl.ni_namelist_val[j]); 350468508Seric p += strlen(p); 350568508Seric *p++ = sepchar; 350669472Seric } 350768508Seric *--p = '\0'; 350868508Seric 350968508Seric ni_namelist_free(&ninl); 351065214Seric } 351165214Seric 351265214Seric /* 351365214Seric ** Clean up. 351465214Seric */ 351565214Seric 351665214Seric if (ni != NULL) 351765214Seric ni_free(ni); 351865214Seric if (lastni != NULL && ni != lastni) 351965214Seric ni_free(lastni); 352065214Seric 352165214Seric return propval; 352265214Seric } 352365214Seric 352465214Seric #endif /* NETINFO */ 352565504Seric /* 352665504Seric ** HARD_SYSLOG -- call syslog repeatedly until it works 352765504Seric ** 352865504Seric ** Needed on HP-UX, which apparently doesn't guarantee that 352965504Seric ** syslog succeeds during interrupt handlers. 353065504Seric */ 353165504Seric 353265504Seric #ifdef __hpux 353365504Seric 353465504Seric # define MAXSYSLOGTRIES 100 353565504Seric # undef syslog 353665504Seric 353769758Seric # ifdef __STDC__ 353869748Seric void 353965504Seric hard_syslog(int pri, char *msg, ...) 354065504Seric # else 354165504Seric hard_syslog(pri, msg, va_alist) 354265504Seric int pri; 354365504Seric char *msg; 354465504Seric va_dcl 354565504Seric # endif 354665504Seric { 354765504Seric int i; 354865504Seric char buf[SYSLOG_BUFSIZE * 2]; 354965504Seric VA_LOCAL_DECL; 355065504Seric 355165504Seric VA_START(msg); 355265504Seric vsprintf(buf, msg, ap); 355365504Seric VA_END; 355465504Seric 355565504Seric for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, "%s", buf) < 0; ) 355665504Seric continue; 355765504Seric } 355865504Seric 355965504Seric #endif 356068696Seric /* 356168696Seric ** LOCAL_HOSTNAME_LENGTH 356268696Seric ** 356368696Seric ** This is required to get sendmail to compile against BIND 4.9.x 356468696Seric ** on Ultrix. 356568696Seric */ 356668696Seric 356768696Seric #if defined(ultrix) && NAMED_BIND 356868696Seric 356968696Seric # include <resolv.h> 357068696Seric # if __RES >= 19931104 357168696Seric 357268696Seric int 357368696Seric local_hostname_length(hostname) 357468696Seric char *hostname; 357568696Seric { 357668696Seric int len_host, len_domain; 357768696Seric 357868696Seric if (!*_res.defdname) 357968696Seric res_init(); 358068696Seric len_host = strlen(hostname); 358168696Seric len_domain = strlen(_res.defdname); 358268696Seric if (len_host > len_domain && 358368696Seric (strcasecmp(hostname + len_host - len_domain,_res.defdname) == 0) && 358468696Seric hostname[len_host - len_domain - 1] == '.') 358568696Seric return len_host - len_domain - 1; 358668696Seric else 358768696Seric return 0; 358868696Seric } 358968696Seric 359068696Seric # endif 359168696Seric #endif 359268741Seric /* 359368741Seric ** Compile-Time options 359468741Seric */ 359568741Seric 359668741Seric char *CompileOptions[] = 359768741Seric { 359868741Seric #if HESIOD 359968741Seric "HESIOD", 360068741Seric #endif 360168741Seric #if LOG 360268741Seric "LOG", 360368741Seric #endif 360468741Seric #if MATCHGECOS 360568741Seric "MATCHGECOS", 360668741Seric #endif 360768741Seric #if NAMED_BIND 360868741Seric "NAMED_BIND", 360968741Seric #endif 361068741Seric #if NDBM 361168741Seric "NDBM", 361268741Seric #endif 361368741Seric #if NETINET 361468741Seric "NETINET", 361568741Seric #endif 361668741Seric #if NETINFO 361768741Seric "NETINFO", 361868741Seric #endif 361968741Seric #if NETISO 362068741Seric "NETISO", 362168741Seric #endif 362268741Seric #if NETNS 362368741Seric "NETNS", 362468741Seric #endif 362568741Seric #if NETUNIX 362668741Seric "NETUNIX", 362768741Seric #endif 362868741Seric #if NETX25 362968741Seric "NETX25", 363068741Seric #endif 363168741Seric #if NEWDB 363268741Seric "NEWDB", 363368741Seric #endif 363468741Seric #if NIS 363568741Seric "NIS", 363668741Seric #endif 363769518Seric #if NISPLUS 363869518Seric "NISPLUS", 363969518Seric #endif 364068741Seric #if SCANF 364168741Seric "SCANF", 364268741Seric #endif 364368741Seric #if SUID_ROOT_FILES_OK 364468741Seric "SUID_ROOT_FILES_OK", 364568741Seric #endif 364668741Seric #if USERDB 364768741Seric "USERDB", 364868741Seric #endif 364968741Seric #if XDEBUG 365068741Seric "XDEBUG", 365168741Seric #endif 365268741Seric #if XLA 365368741Seric "XLA", 365468741Seric #endif 365568741Seric NULL 365668741Seric }; 365769817Seric 365869817Seric 365969817Seric /* 366069817Seric ** OS compile options. 366169817Seric */ 366269817Seric 366369817Seric char *OsCompileOptions[] = 366469817Seric { 366569817Seric #if HASFLOCK 366669817Seric "HASFLOCK", 366769817Seric #endif 366869817Seric #if HASGETUSERSHELL 366969817Seric "HASGETUSERSHELL", 367069817Seric #endif 367169817Seric #if HASINITGROUPS 367269817Seric "HASINITGROUPS", 367369817Seric #endif 367469817Seric #if HASLSTAT 367569817Seric "HASLSTAT", 367669817Seric #endif 367769817Seric #if HASSETREUID 367869817Seric "HASSETREUID", 367969817Seric #endif 368069817Seric #if HASSETSID 368169817Seric "HASSETSID", 368269817Seric #endif 368369817Seric #if HASSETVBUF 368469817Seric "HASSETVBUF", 368569817Seric #endif 368669817Seric #if HASUNAME 368769817Seric "HASUNAME", 368869817Seric #endif 368969817Seric #if IDENTPROTO 369069817Seric "IDENTPROTO", 369169817Seric #endif 369269817Seric #if IP_SRCROUTE 369369817Seric "IP_SRCROUTE", 369469817Seric #endif 369569817Seric #if SYS5SETPGRP 369669817Seric "SYS5SETPGRP", 369769817Seric #endif 369869817Seric #if SYSTEM5 369969817Seric "SYSTEM5", 370069817Seric #endif 370169817Seric #if USESETEUID 370269817Seric "USESETEUID", 370369817Seric #endif 370469817Seric NULL 370569817Seric }; 3706