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*69453Seric static char sccsid[] = "@(#)conf.c 8.160 (Berkeley) 05/14/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 */ 18768508Seric MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */ 18868508Seric for (i = 0; i < MAXTOCLASS; i++) 18968508Seric { 19068508Seric TimeOuts.to_q_return[i] = 5 DAYS; /* option T */ 19168508Seric TimeOuts.to_q_warning[i] = 0; /* option T */ 19268508Seric } 19368508Seric ServiceSwitchFile = "/etc/service.switch"; 19469401Seric HostsFile = _PATH_HOSTS; 19540973Sbostic setdefuser(); 19653654Seric setupmaps(); 19757402Seric setupmailers(); 19824943Seric } 199294Seric 20040973Sbostic 2014326Seric /* 20240973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 20340973Sbostic */ 20440973Sbostic 20568508Seric void 20640973Sbostic setdefuser() 20740973Sbostic { 20840973Sbostic struct passwd *defpwent; 20957386Seric static char defuserbuf[40]; 21040973Sbostic 21157386Seric DefUser = defuserbuf; 21268693Seric if ((defpwent = sm_getpwuid(DefUid)) != NULL) 21357386Seric strcpy(defuserbuf, defpwent->pw_name); 21440973Sbostic else 21557386Seric strcpy(defuserbuf, "nobody"); 21640973Sbostic } 21753654Seric /* 21856836Seric ** HOST_MAP_INIT -- initialize host class structures 21956836Seric */ 22056836Seric 22168508Seric bool host_map_init __P((MAP *map, char *args)); 22268508Seric 22356836Seric bool 22460219Seric host_map_init(map, args) 22556836Seric MAP *map; 22656836Seric char *args; 22756836Seric { 22856836Seric register char *p = args; 22956836Seric 23056836Seric for (;;) 23156836Seric { 23258050Seric while (isascii(*p) && isspace(*p)) 23356836Seric p++; 23456836Seric if (*p != '-') 23556836Seric break; 23656836Seric switch (*++p) 23756836Seric { 23856836Seric case 'a': 23956836Seric map->map_app = ++p; 24056836Seric break; 24156836Seric } 24258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 24356836Seric p++; 24456836Seric if (*p != '\0') 24556836Seric *p++ = '\0'; 24656836Seric } 24756836Seric if (map->map_app != NULL) 24856836Seric map->map_app = newstr(map->map_app); 24956836Seric return TRUE; 25056836Seric } 25157402Seric /* 25257402Seric ** SETUPMAILERS -- initialize default mailers 25357402Seric */ 25456836Seric 25568508Seric void 25657402Seric setupmailers() 25757402Seric { 25857402Seric char buf[100]; 25968508Seric extern void makemailer(); 26057402Seric 26168868Seric strcpy(buf, "prog, P=/bin/sh, F=lsoD, T=X-Unix, A=sh -c $u"); 26257403Seric makemailer(buf); 26357403Seric 26468880Seric strcpy(buf, "*file*, P=[FILE], F=lsDFMPEou, T=X-Unix, A=FILE"); 26557402Seric makemailer(buf); 26657402Seric 26757402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 26857402Seric makemailer(buf); 26957402Seric } 27056836Seric /* 27160207Seric ** SETUPMAPS -- set up map classes 27260207Seric */ 27360207Seric 27460207Seric #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \ 27560207Seric { \ 27660207Seric extern bool parse __P((MAP *, char *)); \ 27760207Seric extern bool open __P((MAP *, int)); \ 27860207Seric extern void close __P((MAP *)); \ 27960207Seric extern char *lookup __P((MAP *, char *, char **, int *)); \ 28060207Seric extern void store __P((MAP *, char *, char *)); \ 28160207Seric s = stab(name, ST_MAPCLASS, ST_ENTER); \ 28260207Seric s->s_mapclass.map_cname = name; \ 28360207Seric s->s_mapclass.map_ext = ext; \ 28460207Seric s->s_mapclass.map_cflags = flags; \ 28560207Seric s->s_mapclass.map_parse = parse; \ 28660207Seric s->s_mapclass.map_open = open; \ 28760207Seric s->s_mapclass.map_close = close; \ 28860207Seric s->s_mapclass.map_lookup = lookup; \ 28960207Seric s->s_mapclass.map_store = store; \ 29060207Seric } 29160207Seric 29268508Seric void 29360207Seric setupmaps() 29460207Seric { 29560207Seric register STAB *s; 29660207Seric 29760207Seric #ifdef NEWDB 29860207Seric MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 29960207Seric map_parseargs, hash_map_open, db_map_close, 30060207Seric db_map_lookup, db_map_store); 30168508Seric 30260207Seric MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 30360207Seric map_parseargs, bt_map_open, db_map_close, 30460207Seric db_map_lookup, db_map_store); 30560207Seric #endif 30660207Seric 30760207Seric #ifdef NDBM 30860207Seric MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE, 30960207Seric map_parseargs, ndbm_map_open, ndbm_map_close, 31060207Seric ndbm_map_lookup, ndbm_map_store); 31160207Seric #endif 31260207Seric 31360207Seric #ifdef NIS 31460207Seric MAPDEF("nis", NULL, MCF_ALIASOK, 31568508Seric map_parseargs, nis_map_open, null_map_close, 31668508Seric nis_map_lookup, null_map_store); 31760207Seric #endif 31860207Seric 31968508Seric #ifdef NISPLUS 32068508Seric MAPDEF("nisplus", NULL, MCF_ALIASOK, 32168508Seric map_parseargs, nisplus_map_open, null_map_close, 32268508Seric nisplus_map_lookup, null_map_store); 32368508Seric #endif 32468508Seric 32568508Seric #ifdef HESIOD 32668508Seric MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY, 32768508Seric map_parseargs, null_map_open, null_map_close, 32868508Seric hes_map_lookup, null_map_store); 32968508Seric #endif 33068508Seric 33168508Seric #ifdef NETINFO 33268508Seric MAPDEF("netinfo", NULL, MCF_ALIASOK, 33368508Seric map_parseargs, ni_map_open, null_map_close, 33468508Seric ni_map_lookup, null_map_store); 33568508Seric #endif 33668508Seric 33768508Seric #if 0 33868508Seric MAPDEF("dns", NULL, 0, 33968508Seric dns_map_init, null_map_open, null_map_close, 34068508Seric dns_map_lookup, null_map_store); 34168508Seric #endif 34268508Seric 34368508Seric #if NAMED_BIND 34468508Seric /* best MX DNS lookup */ 34568508Seric MAPDEF("bestmx", NULL, MCF_OPTFILE, 34668508Seric map_parseargs, null_map_open, null_map_close, 34768508Seric bestmx_map_lookup, null_map_store); 34868508Seric #endif 34968508Seric 35068508Seric MAPDEF("host", NULL, 0, 35168508Seric host_map_init, null_map_open, null_map_close, 35268508Seric host_map_lookup, null_map_store); 35368508Seric 35468508Seric MAPDEF("text", NULL, MCF_ALIASOK, 35568508Seric map_parseargs, text_map_open, null_map_close, 35668508Seric text_map_lookup, null_map_store); 35768508Seric 35860207Seric MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY, 35968508Seric map_parseargs, stab_map_open, null_map_close, 36060207Seric stab_map_lookup, stab_map_store); 36160207Seric 36260207Seric MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE, 36360207Seric map_parseargs, impl_map_open, impl_map_close, 36460207Seric impl_map_lookup, impl_map_store); 36560207Seric 36668508Seric /* access to system passwd file */ 36768508Seric MAPDEF("user", NULL, MCF_OPTFILE, 36868508Seric map_parseargs, user_map_open, null_map_close, 36968508Seric user_map_lookup, null_map_store); 37060207Seric 37160207Seric /* dequote map */ 37260207Seric MAPDEF("dequote", NULL, 0, 37360207Seric dequote_init, null_map_open, null_map_close, 37460207Seric dequote_map, null_map_store); 37560207Seric 37668521Seric #ifdef USERDB 37760207Seric /* user database */ 37868521Seric MAPDEF("userdb", ".db", 0, 37968521Seric map_parseargs, null_map_open, null_map_close, 38060207Seric udb_map_lookup, null_map_store); 38160207Seric #endif 38268508Seric 383*69453Seric /* arbitrary programs */ 384*69453Seric MAPDEF("program", NULL, 0, 385*69453Seric map_parseargs, null_map_open, null_map_close, 386*69453Seric prog_map_lookup, null_map_store); 387*69453Seric 38868508Seric /* sequenced maps */ 38968508Seric MAPDEF("sequence", NULL, MCF_ALIASOK, 39068508Seric seq_map_parse, null_map_open, null_map_close, 39168508Seric seq_map_lookup, seq_map_store); 39268508Seric 39368508Seric /* switched interface to sequenced maps */ 39468508Seric MAPDEF("switch", NULL, MCF_ALIASOK, 39568508Seric map_parseargs, switch_map_open, null_map_close, 39668508Seric seq_map_lookup, seq_map_store); 39760207Seric } 39860207Seric 39960207Seric #undef MAPDEF 40060207Seric /* 40168508Seric ** INITHOSTMAPS -- initial host-dependent maps 40268508Seric ** 40368508Seric ** This should act as an interface to any local service switch 40468508Seric ** provided by the host operating system. 40568508Seric ** 40668508Seric ** Parameters: 40768508Seric ** none 40868508Seric ** 40968508Seric ** Returns: 41068508Seric ** none 41168508Seric ** 41268508Seric ** Side Effects: 41368508Seric ** Should define maps "host" and "users" as necessary 41468508Seric ** for this OS. If they are not defined, they will get 41568508Seric ** a default value later. It should check to make sure 41668508Seric ** they are not defined first, since it's possible that 41768508Seric ** the config file has provided an override. 41868508Seric */ 41968508Seric 42068508Seric void 42168508Seric inithostmaps() 42268508Seric { 42368508Seric register int i; 42468508Seric int nmaps; 42568508Seric char *maptype[MAXMAPSTACK]; 42668508Seric short mapreturn[MAXMAPACTIONS]; 42768508Seric char buf[MAXLINE]; 42868508Seric 42968508Seric /* 43068508Seric ** Set up default hosts maps. 43168508Seric */ 43268508Seric 43368508Seric #if 0 43468508Seric nmaps = switch_map_find("hosts", maptype, mapreturn); 43568508Seric for (i = 0; i < nmaps; i++) 43668508Seric { 43768508Seric if (strcmp(maptype[i], "files") == 0 && 43868508Seric stab("hosts.files", ST_MAP, ST_FIND) == NULL) 43968508Seric { 44068508Seric strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts"); 44168508Seric makemapentry(buf); 44268508Seric } 44368508Seric #if NAMED_BIND 44468508Seric else if (strcmp(maptype[i], "dns") == 0 && 44568508Seric stab("hosts.dns", ST_MAP, ST_FIND) == NULL) 44668508Seric { 44768508Seric strcpy(buf, "hosts.dns dns A"); 44868508Seric makemapentry(buf); 44968508Seric } 45068508Seric #endif 45168508Seric #ifdef NISPLUS 45268508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 45368508Seric stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL) 45468508Seric { 45568508Seric strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir"); 45668508Seric makemapentry(buf); 45768508Seric } 45868508Seric #endif 45968508Seric #ifdef NIS 46068508Seric else if (strcmp(maptype[i], "nis") == 0 && 46168508Seric stab("hosts.nis", ST_MAP, ST_FIND) == NULL) 46268508Seric { 46368508Seric strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname"); 46468508Seric makemapentry(buf); 46568508Seric } 46668508Seric #endif 46768508Seric } 46868508Seric #endif 46968508Seric 47068508Seric /* 47168508Seric ** Make sure we have a host map. 47268508Seric */ 47368508Seric 47468508Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 47568508Seric { 47668508Seric /* user didn't initialize: set up host map */ 47768508Seric strcpy(buf, "host host"); 47868508Seric #if NAMED_BIND 47968508Seric if (ConfigLevel >= 2) 48068508Seric strcat(buf, " -a."); 48168508Seric #endif 48268508Seric makemapentry(buf); 48368508Seric } 48468508Seric 48568508Seric /* 48668508Seric ** Set up default aliases maps 48768508Seric */ 48868508Seric 48968508Seric nmaps = switch_map_find("aliases", maptype, mapreturn); 49068508Seric for (i = 0; i < nmaps; i++) 49168508Seric { 49268508Seric if (strcmp(maptype[i], "files") == 0 && 49368508Seric stab("aliases.files", ST_MAP, ST_FIND) == NULL) 49468508Seric { 49568508Seric strcpy(buf, "aliases.files implicit /etc/aliases"); 49668508Seric makemapentry(buf); 49768508Seric } 49868508Seric #ifdef NISPLUS 49968508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 50068508Seric stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL) 50168508Seric { 50268508Seric strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir"); 50368508Seric makemapentry(buf); 50468508Seric } 50568508Seric #endif 50668508Seric #ifdef NIS 50768508Seric else if (strcmp(maptype[i], "nis") == 0 && 50868508Seric stab("aliases.nis", ST_MAP, ST_FIND) == NULL) 50968508Seric { 51068508Seric strcpy(buf, "aliases.nis nis -d mail.aliases"); 51168508Seric makemapentry(buf); 51268508Seric } 51368508Seric #endif 51468508Seric } 51568508Seric if (stab("aliases", ST_MAP, ST_FIND) == NULL) 51668508Seric { 51768508Seric strcpy(buf, "aliases switch aliases"); 51868508Seric makemapentry(buf); 51968508Seric } 52068508Seric strcpy(buf, "switch:aliases"); 52168508Seric setalias(buf); 52268508Seric 52368508Seric #if 0 /* "user" map class is a better choice */ 52468508Seric /* 52568508Seric ** Set up default users maps. 52668508Seric */ 52768508Seric 52868508Seric nmaps = switch_map_find("passwd", maptype, mapreturn); 52968508Seric for (i = 0; i < nmaps; i++) 53068508Seric { 53168508Seric if (strcmp(maptype[i], "files") == 0 && 53268508Seric stab("users.files", ST_MAP, ST_FIND) == NULL) 53368508Seric { 53468508Seric strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd"); 53568508Seric makemapentry(buf); 53668508Seric } 53768508Seric #ifdef NISPLUS 53868508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 53968508Seric stab("users.nisplus", ST_MAP, ST_FIND) == NULL) 54068508Seric { 54168508Seric strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir"); 54268508Seric makemapentry(buf); 54368508Seric } 54468508Seric #endif 54568508Seric #ifdef NIS 54668508Seric else if (strcmp(maptype[i], "nis") == 0 && 54768508Seric stab("users.nis", ST_MAP, ST_FIND) == NULL) 54868508Seric { 54968508Seric strcpy(buf, "users.nis nis -m -d passwd.byname"); 55068508Seric makemapentry(buf); 55168508Seric } 55268508Seric #endif 55368508Seric #ifdef HESIOD 55468508Seric else if (strcmp(maptype[i], "hesiod") == 0) && 55568508Seric stab("users.hesiod", ST_MAP, ST_FIND) == NULL) 55668508Seric { 55768508Seric strcpy(buf, "users.hesiod hesiod"); 55868508Seric makemapentry(buf); 55968508Seric } 56068508Seric #endif 56168508Seric } 56268508Seric if (stab("users", ST_MAP, ST_FIND) == NULL) 56368508Seric { 56468508Seric strcpy(buf, "users switch -m passwd"); 56568508Seric makemapentry(buf); 56668508Seric } 56768508Seric #endif 56868508Seric } 56968508Seric /* 57068508Seric ** SWITCH_MAP_FIND -- find the list of types associated with a map 57168508Seric ** 57268508Seric ** This is the system-dependent interface to the service switch. 57368508Seric ** 57468508Seric ** Parameters: 57568508Seric ** service -- the name of the service of interest. 57668508Seric ** maptype -- an out-array of strings containing the types 57768508Seric ** of access to use for this service. There can 57868508Seric ** be at most MAXMAPSTACK types for a single service. 57968508Seric ** mapreturn -- an out-array of return information bitmaps 58068508Seric ** for the map. 58168508Seric ** 58268508Seric ** Returns: 58368508Seric ** The number of map types filled in, or -1 for failure. 58468508Seric */ 58568508Seric 58668508Seric #ifdef SOLARIS 58768508Seric # include <nsswitch.h> 58868508Seric #endif 58968508Seric 59068508Seric #if defined(ultrix) || defined(__osf__) 59168508Seric # include <sys/svcinfo.h> 59268508Seric #endif 59368508Seric 59468508Seric int 59568508Seric switch_map_find(service, maptype, mapreturn) 59668508Seric char *service; 59768508Seric char *maptype[MAXMAPSTACK]; 59868508Seric short mapreturn[MAXMAPACTIONS]; 59968508Seric { 60068508Seric register FILE *fp; 60168508Seric int svcno; 60268508Seric static char buf[MAXLINE]; 60368508Seric 60468508Seric #ifdef SOLARIS 60568508Seric struct __nsw_switchconfig *nsw_conf; 60668508Seric enum __nsw_parse_err pserr; 60768508Seric struct __nsw_lookup *lk; 60868508Seric int nsw_rc; 60968508Seric static struct __nsw_lookup lkp0 = 61068508Seric { "files", {1, 0, 0, 0}, NULL, NULL }; 61168508Seric static struct __nsw_switchconfig lkp_default = 61268508Seric { 0, "sendmail", 3, &lkp0 }; 61368508Seric 61468508Seric if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL) 61568508Seric lk = lkp_default.lookups; 61668508Seric else 61768508Seric lk = nsw_conf->lookups; 61868508Seric svcno = 0; 61968508Seric while (lk != NULL) 62068508Seric { 62168508Seric maptype[svcno] = lk->service_name; 62268508Seric if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN) 62368508Seric mapreturn[MA_NOTFOUND] |= 1 << svcno; 62468508Seric if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN) 62568508Seric mapreturn[MA_TRYAGAIN] |= 1 << svcno; 62668508Seric if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN) 62768508Seric mapreturn[MA_TRYAGAIN] |= 1 << svcno; 62868508Seric svcno++; 62968508Seric lk = lk->next; 63068508Seric } 63168508Seric return svcno; 63268508Seric #endif 63368508Seric 63468508Seric #if defined(ultrix) || defined(__osf__) 63568508Seric struct svcinfo *svcinfo; 63668508Seric int svc; 63768508Seric 63869401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 63969401Seric mapreturn[svcno] = 0; 64069401Seric 64168508Seric svcinfo = getsvc(); 64268508Seric if (svcinfo == NULL) 64368508Seric goto punt; 64468508Seric if (strcmp(service, "hosts") == 0) 64568508Seric svc = SVC_HOSTS; 64668508Seric else if (strcmp(service, "aliases") == 0) 64768508Seric svc = SVC_ALIASES; 64868508Seric else if (strcmp(service, "passwd") == 0) 64968508Seric svc = SVC_PASSWD; 65068508Seric else 65168508Seric return -1; 65268508Seric for (svcno = 0; svcno < SVC_PATHSIZE; svcno++) 65368508Seric { 65468508Seric switch (svcinfo->svcpath[svc][svcno]) 65568508Seric { 65668508Seric case SVC_LOCAL: 65768508Seric maptype[svcno] = "files"; 65868508Seric break; 65968508Seric 66068508Seric case SVC_YP: 66168508Seric maptype[svcno] = "nis"; 66268508Seric break; 66368508Seric 66468508Seric case SVC_BIND: 66568508Seric maptype[svcno] = "dns"; 66668508Seric break; 66768508Seric 66868508Seric #ifdef SVC_HESIOD 66968508Seric case SVC_HESIOD: 67068508Seric maptype[svcno] = "hesiod"; 67168508Seric break; 67268508Seric #endif 67368508Seric 67468508Seric case SVC_LAST: 67568508Seric return svcno; 67668508Seric } 67768508Seric } 67868508Seric return svcno; 67968508Seric #endif 68068508Seric 68168508Seric #if !defined(SOLARIS) && !defined(ultrix) && !defined(__osf__) 68268508Seric /* 68368508Seric ** Fall-back mechanism. 68468508Seric */ 68568508Seric 68669401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 68769401Seric mapreturn[svcno] = 0; 68869401Seric 68968508Seric svcno = 0; 69068508Seric fp = fopen(ServiceSwitchFile, "r"); 69168508Seric if (fp != NULL) 69268508Seric { 69368508Seric while (fgets(buf, sizeof buf, fp) != NULL) 69468508Seric { 69568508Seric register char *p; 69668508Seric 69768508Seric p = strpbrk(buf, "#\n"); 69868508Seric if (p != NULL) 69968508Seric *p = '\0'; 70068508Seric p = strpbrk(buf, " \t"); 70168508Seric if (p != NULL) 70268508Seric *p++ = '\0'; 70368508Seric if (strcmp(buf, service) != 0) 70468508Seric continue; 70568508Seric 70668508Seric /* got the right service -- extract data */ 70768508Seric do 70868508Seric { 70968508Seric while (isspace(*p)) 71068508Seric p++; 71168508Seric if (*p == '\0') 71268508Seric break; 71368508Seric maptype[svcno++] = p; 71468508Seric p = strpbrk(p, " \t"); 71568508Seric if (p != NULL) 71668508Seric *p++ = '\0'; 71768508Seric } while (p != NULL); 71868508Seric break; 71968508Seric } 72068508Seric fclose(fp); 72168508Seric return svcno; 72268508Seric } 72368508Seric #endif 72468508Seric 72568508Seric /* if the service file doesn't work, use an absolute fallback */ 72668508Seric punt: 72769401Seric for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 72869401Seric mapreturn[svcno] = 0; 72969401Seric svcno = 0; 73068508Seric if (strcmp(service, "aliases") == 0) 73168508Seric { 73268628Seric maptype[svcno++] = "files"; 73368628Seric #ifdef AUTO_NIS_ALIASES 73468628Seric # ifdef NISPLUS 73568628Seric maptype[svcno++] = "nisplus"; 73668628Seric # endif 73768628Seric # ifdef NIS 73868628Seric maptype[svcno++] = "nis"; 73968628Seric # endif 74068628Seric #endif 74168628Seric return svcno; 74268508Seric } 74368508Seric if (strcmp(service, "hosts") == 0) 74468508Seric { 74568508Seric # if NAMED_BIND 74668508Seric maptype[svcno++] = "dns"; 74768508Seric # else 74868508Seric # if defined(sun) && !defined(BSD) && !defined(SOLARIS) 74968508Seric /* SunOS */ 75068508Seric maptype[svcno++] = "nis"; 75168508Seric # endif 75268508Seric # endif 75368508Seric maptype[svcno++] = "files"; 75468508Seric return svcno; 75568508Seric } 75668508Seric return -1; 75768508Seric } 75868508Seric /* 7599369Seric ** USERNAME -- return the user id of the logged in user. 7609369Seric ** 7619369Seric ** Parameters: 7629369Seric ** none. 7639369Seric ** 7649369Seric ** Returns: 7659369Seric ** The login name of the logged in user. 7669369Seric ** 7679369Seric ** Side Effects: 7689369Seric ** none. 7699369Seric ** 7709369Seric ** Notes: 7719369Seric ** The return value is statically allocated. 7729369Seric */ 7739369Seric 7749369Seric char * 7759369Seric username() 7769369Seric { 77717469Seric static char *myname = NULL; 7789369Seric extern char *getlogin(); 77919904Smiriam register struct passwd *pw; 7809369Seric 78117469Seric /* cache the result */ 78217469Seric if (myname == NULL) 78317469Seric { 78417469Seric myname = getlogin(); 78517469Seric if (myname == NULL || myname[0] == '\0') 78617469Seric { 78768693Seric pw = sm_getpwuid(RealUid); 78817469Seric if (pw != NULL) 78940993Sbostic myname = newstr(pw->pw_name); 79017469Seric } 79119904Smiriam else 79219904Smiriam { 79363787Seric uid_t uid = RealUid; 79419873Smiriam 79540993Sbostic myname = newstr(myname); 79668693Seric if ((pw = sm_getpwnam(myname)) == NULL || 79758736Seric (uid != 0 && uid != pw->pw_uid)) 79819904Smiriam { 79968693Seric pw = sm_getpwuid(uid); 80024945Seric if (pw != NULL) 80140993Sbostic myname = newstr(pw->pw_name); 80219873Smiriam } 80319873Smiriam } 80417469Seric if (myname == NULL || myname[0] == '\0') 80517469Seric { 80658151Seric syserr("554 Who are you?"); 80717469Seric myname = "postmaster"; 80817469Seric } 80917469Seric } 81017469Seric 81117469Seric return (myname); 8129369Seric } 8139369Seric /* 8144190Seric ** TTYPATH -- Get the path of the user's tty 815294Seric ** 816294Seric ** Returns the pathname of the user's tty. Returns NULL if 817294Seric ** the user is not logged in or if s/he has write permission 818294Seric ** denied. 819294Seric ** 820294Seric ** Parameters: 821294Seric ** none 822294Seric ** 823294Seric ** Returns: 824294Seric ** pathname of the user's tty. 825294Seric ** NULL if not logged in or write permission denied. 826294Seric ** 827294Seric ** Side Effects: 828294Seric ** none. 829294Seric ** 830294Seric ** WARNING: 831294Seric ** Return value is in a local buffer. 832294Seric ** 833294Seric ** Called By: 834294Seric ** savemail 835294Seric */ 836294Seric 837294Seric char * 838294Seric ttypath() 839294Seric { 840294Seric struct stat stbuf; 841294Seric register char *pathn; 842294Seric extern char *ttyname(); 8434081Seric extern char *getlogin(); 844294Seric 845294Seric /* compute the pathname of the controlling tty */ 8469369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 8479369Seric (pathn = ttyname(0)) == NULL) 848294Seric { 849294Seric errno = 0; 850294Seric return (NULL); 851294Seric } 852294Seric 853294Seric /* see if we have write permission */ 8542967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 855294Seric { 856294Seric errno = 0; 857294Seric return (NULL); 858294Seric } 859294Seric 860294Seric /* see if the user is logged in */ 861294Seric if (getlogin() == NULL) 862294Seric return (NULL); 863294Seric 864294Seric /* looks good */ 865294Seric return (pathn); 866294Seric } 8672967Seric /* 8682967Seric ** CHECKCOMPAT -- check for From and To person compatible. 8692967Seric ** 8702967Seric ** This routine can be supplied on a per-installation basis 8712967Seric ** to determine whether a person is allowed to send a message. 8722967Seric ** This allows restriction of certain types of internet 8732967Seric ** forwarding or registration of users. 8742967Seric ** 8752967Seric ** If the hosts are found to be incompatible, an error 87668857Seric ** message should be given using "usrerr" and an EX_ code 87768857Seric ** should be returned. You can also set to->q_status to 87868857Seric ** a DSN-style status code. 8792967Seric ** 88068559Seric ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the 88168559Seric ** body during the return-to-sender function; this should be done 88268559Seric ** on huge messages. This bit may already be set by the ESMTP 88368559Seric ** protocol. 8844288Seric ** 8852967Seric ** Parameters: 8862967Seric ** to -- the person being sent to. 8872967Seric ** 8882967Seric ** Returns: 88957459Seric ** an exit status 8902967Seric ** 8912967Seric ** Side Effects: 8922967Seric ** none (unless you include the usrerr stuff) 8932967Seric */ 8942967Seric 89568508Seric int 89655012Seric checkcompat(to, e) 8972967Seric register ADDRESS *to; 89855012Seric register ENVELOPE *e; 8992967Seric { 90012133Seric # ifdef lint 90112133Seric if (to == NULL) 90212133Seric to++; 90363834Seric # endif /* lint */ 90464402Seric 90564402Seric if (tTd(49, 1)) 90664402Seric printf("checkcompat(to=%s, from=%s)\n", 90764402Seric to->q_paddr, e->e_from.q_paddr); 90864402Seric 90910698Seric # ifdef EXAMPLE_CODE 91010698Seric /* this code is intended as an example only */ 9114437Seric register STAB *s; 9124437Seric 9134437Seric s = stab("arpa", ST_MAILER, ST_FIND); 91468508Seric if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 && 9159369Seric to->q_mailer == s->s_mailer) 9164437Seric { 91758151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 91868559Seric /* e->e_flags |= EF_NO_BODY_RETN; to supress body on return */ 91968857Seric to->q_status = "5.7.1"; 92057459Seric return (EX_UNAVAILABLE); 9214437Seric } 92256795Seric # endif /* EXAMPLE_CODE */ 92357459Seric return (EX_OK); 9242967Seric } 9259369Seric /* 92664035Seric ** SETSIGNAL -- set a signal handler 92764035Seric ** 92864035Seric ** This is essentially old BSD "signal(3)". 92964035Seric */ 93064035Seric 93164561Seric sigfunc_t 93264035Seric setsignal(sig, handler) 93364035Seric int sig; 93464561Seric sigfunc_t handler; 93564035Seric { 93664380Seric #if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE) 93764035Seric return signal(sig, handler); 93864035Seric #else 93964035Seric struct sigaction n, o; 94064035Seric 94164035Seric bzero(&n, sizeof n); 94264035Seric n.sa_handler = handler; 94368508Seric # ifdef SA_RESTART 94468508Seric n.sa_flags = SA_RESTART; 94568508Seric # endif 94664035Seric if (sigaction(sig, &n, &o) < 0) 94764035Seric return SIG_ERR; 94864035Seric return o.sa_handler; 94964035Seric #endif 95064035Seric } 95164035Seric /* 9529369Seric ** HOLDSIGS -- arrange to hold all signals 9539369Seric ** 9549369Seric ** Parameters: 9559369Seric ** none. 9569369Seric ** 9579369Seric ** Returns: 9589369Seric ** none. 9599369Seric ** 9609369Seric ** Side Effects: 9619369Seric ** Arranges that signals are held. 9629369Seric */ 9639369Seric 96468508Seric void 9659369Seric holdsigs() 9669369Seric { 9679369Seric } 9689369Seric /* 9699369Seric ** RLSESIGS -- arrange to release all signals 9709369Seric ** 9719369Seric ** This undoes the effect of holdsigs. 9729369Seric ** 9739369Seric ** Parameters: 9749369Seric ** none. 9759369Seric ** 9769369Seric ** Returns: 9779369Seric ** none. 9789369Seric ** 9799369Seric ** Side Effects: 9809369Seric ** Arranges that signals are released. 9819369Seric */ 9829369Seric 98368508Seric void 9849369Seric rlsesigs() 9859369Seric { 9869369Seric } 98714872Seric /* 98864705Seric ** INIT_MD -- do machine dependent initializations 98964705Seric ** 99064705Seric ** Systems that have global modes that should be set should do 99164705Seric ** them here rather than in main. 99264705Seric */ 99364705Seric 99464705Seric #ifdef _AUX_SOURCE 99564705Seric # include <compat.h> 99664705Seric #endif 99764705Seric 99868508Seric void 99964825Seric init_md(argc, argv) 100064825Seric int argc; 100164825Seric char **argv; 100264705Seric { 100364705Seric #ifdef _AUX_SOURCE 100464705Seric setcompat(getcompat() | COMPAT_BSDPROT); 100564705Seric #endif 100668508Seric 100768508Seric #ifdef VENDOR_DEFAULT 100868508Seric VendorCode = VENDOR_DEFAULT; 100968508Seric #else 101068508Seric VendorCode = VENDOR_BERKELEY; 101168508Seric #endif 101264705Seric } 101364705Seric /* 101468508Seric ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations 101568508Seric ** 101668508Seric ** Called once, on startup. 101768508Seric ** 101868508Seric ** Parameters: 101968508Seric ** e -- the global envelope. 102068508Seric ** 102168508Seric ** Returns: 102268508Seric ** none. 102368508Seric ** 102468508Seric ** Side Effects: 102568508Seric ** vendor-dependent. 102668508Seric */ 102768508Seric 102868508Seric void 102968508Seric init_vendor_macros(e) 103068508Seric register ENVELOPE *e; 103168508Seric { 103268508Seric } 103368508Seric /* 103414872Seric ** GETLA -- get the current load average 103514872Seric ** 103614881Seric ** This code stolen from la.c. 103714881Seric ** 103814872Seric ** Parameters: 103914872Seric ** none. 104014872Seric ** 104114872Seric ** Returns: 104214872Seric ** The current load average as an integer. 104314872Seric ** 104414872Seric ** Side Effects: 104514872Seric ** none. 104614872Seric */ 104714872Seric 104851920Seric /* try to guess what style of load average we have */ 104951920Seric #define LA_ZERO 1 /* always return load average as zero */ 105064360Seric #define LA_INT 2 /* read kmem for avenrun; interpret as long */ 105151920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 105251920Seric #define LA_SUBR 4 /* call getloadavg */ 105364295Seric #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */ 105464360Seric #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */ 105566301Seric #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */ 105614872Seric 105763962Seric /* do guesses based on general OS type */ 105851920Seric #ifndef LA_TYPE 105963962Seric # define LA_TYPE LA_ZERO 106051920Seric #endif 106151920Seric 106264360Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) 106351920Seric 106414872Seric #include <nlist.h> 106514872Seric 106668508Seric #ifdef IRIX64 106768508Seric # define nlist nlist64 106868508Seric #endif 106968508Seric 107051920Seric #ifndef LA_AVENRUN 107163962Seric # ifdef SYSTEM5 107263962Seric # define LA_AVENRUN "avenrun" 107363962Seric # else 107463962Seric # define LA_AVENRUN "_avenrun" 107563962Seric # endif 107651920Seric #endif 107751920Seric 107851920Seric /* _PATH_UNIX should be defined in <paths.h> */ 107951920Seric #ifndef _PATH_UNIX 108063962Seric # if defined(SYSTEM5) 108163962Seric # define _PATH_UNIX "/unix" 108263962Seric # else 108363962Seric # define _PATH_UNIX "/vmunix" 108463962Seric # endif 108551920Seric #endif 108651920Seric 108714872Seric struct nlist Nl[] = 108814872Seric { 108951920Seric { LA_AVENRUN }, 109014872Seric #define X_AVENRUN 0 109114872Seric { 0 }, 109214872Seric }; 109314872Seric 109460583Seric #ifndef FSHIFT 109560583Seric # if defined(unixpc) 109660583Seric # define FSHIFT 5 109760583Seric # endif 109857736Seric 109966763Seric # if defined(__alpha) || defined(IRIX) 110060583Seric # define FSHIFT 10 110160583Seric # endif 110268508Seric 110368508Seric # if defined(_AIX3) 110468508Seric # define FSHIFT 16 110568508Seric # endif 110666788Seric #endif 110757977Seric 110866788Seric #ifndef FSHIFT 110966788Seric # define FSHIFT 8 111057736Seric #endif 111160583Seric 111266788Seric #ifndef FSCALE 111366788Seric # define FSCALE (1 << FSHIFT) 111451920Seric #endif 111540930Srick 111614872Seric getla() 111714872Seric { 111814872Seric static int kmem = -1; 111951920Seric #if LA_TYPE == LA_INT 112024943Seric long avenrun[3]; 112151920Seric #else 112264360Seric # if LA_TYPE == LA_SHORT 112364360Seric short avenrun[3]; 112464360Seric # else 112551920Seric double avenrun[3]; 112664360Seric # endif 112751920Seric #endif 112825615Seric extern off_t lseek(); 112957736Seric extern int errno; 113014872Seric 113114872Seric if (kmem < 0) 113214872Seric { 113324945Seric kmem = open("/dev/kmem", 0, 0); 113414872Seric if (kmem < 0) 113557736Seric { 113657736Seric if (tTd(3, 1)) 113757736Seric printf("getla: open(/dev/kmem): %s\n", 113857736Seric errstring(errno)); 113914872Seric return (-1); 114057736Seric } 114151920Seric (void) fcntl(kmem, F_SETFD, 1); 114268508Seric #ifdef _AIX3 114368508Seric if (knlist(Nl, 1, sizeof Nl[0]) < 0) 114468508Seric #else 114557736Seric if (nlist(_PATH_UNIX, Nl) < 0) 114668508Seric #endif 114757736Seric { 114857736Seric if (tTd(3, 1)) 114957736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 115057736Seric errstring(errno)); 115114872Seric return (-1); 115257736Seric } 115359253Seric if (Nl[X_AVENRUN].n_value == 0) 115459253Seric { 115559253Seric if (tTd(3, 1)) 115659253Seric printf("getla: nlist(%s, %s) ==> 0\n", 115759253Seric _PATH_UNIX, LA_AVENRUN); 115859253Seric return (-1); 115959253Seric } 116068508Seric #ifdef NAMELISTMASK 116168508Seric Nl[X_AVENRUN].n_value &= NAMELISTMASK; 116266763Seric #endif 116314872Seric } 116457736Seric if (tTd(3, 20)) 116557736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 116668508Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 || 116723118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 116819967Seric { 116919967Seric /* thank you Ian */ 117057736Seric if (tTd(3, 1)) 117157736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 117219967Seric return (-1); 117319967Seric } 117464360Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) 117557736Seric if (tTd(3, 5)) 117657736Seric { 117757736Seric printf("getla: avenrun = %d", avenrun[0]); 117857736Seric if (tTd(3, 15)) 117957736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 118057736Seric printf("\n"); 118157736Seric } 118257736Seric if (tTd(3, 1)) 118357736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 118424943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 118551920Seric #else 118657736Seric if (tTd(3, 5)) 118757736Seric { 118857736Seric printf("getla: avenrun = %g", avenrun[0]); 118957736Seric if (tTd(3, 15)) 119057736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 119157736Seric printf("\n"); 119257736Seric } 119357736Seric if (tTd(3, 1)) 119457736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 119551920Seric return ((int) (avenrun[0] + 0.5)); 119651920Seric #endif 119714872Seric } 119814872Seric 119951773Seric #else 120051920Seric #if LA_TYPE == LA_SUBR 120151773Seric 120264718Seric #ifdef DGUX 120364718Seric 120464718Seric #include <sys/dg_sys_info.h> 120564718Seric 120668508Seric int 120768508Seric getla() 120864718Seric { 120964718Seric struct dg_sys_info_load_info load_info; 121064718Seric 121164718Seric dg_sys_info((long *)&load_info, 121264718Seric DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); 121364718Seric 121468508Seric if (tTd(3, 1)) 121568508Seric printf("getla: %d\n", (int) (load_info.one_minute + 0.5)); 121668508Seric 121764718Seric return((int) (load_info.one_minute + 0.5)); 121864718Seric } 121964718Seric 122064718Seric #else 122168508Seric # ifdef __hpux 122264718Seric 122368869Seric struct pst_dynamic; 122468869Seric 122568508Seric # include <sys/param.h> 122668508Seric # include <sys/pstat.h> 122768508Seric 122868508Seric int 122951773Seric getla() 123051773Seric { 123168508Seric struct pst_dynamic pstd; 123268508Seric 123368508Seric if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic), 123468869Seric (size_t) 1, 0) == -1) 123568508Seric return 0; 123668508Seric 123768508Seric if (tTd(3, 1)) 123868508Seric printf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5)); 123968508Seric 124068508Seric return (int) (pstd.psd_avg_1_min + 0.5); 124168508Seric } 124268508Seric 124368508Seric # else 124468508Seric 124568508Seric int 124668508Seric getla() 124768508Seric { 124851920Seric double avenrun[3]; 124951920Seric 125051920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 125157736Seric { 125257736Seric if (tTd(3, 1)) 125357736Seric perror("getla: getloadavg failed:"); 125451920Seric return (-1); 125557736Seric } 125657736Seric if (tTd(3, 1)) 125757736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 125851920Seric return ((int) (avenrun[0] + 0.5)); 125951773Seric } 126051773Seric 126168508Seric # endif /* __hpux */ 126264718Seric #endif /* DGUX */ 126351773Seric #else 126464295Seric #if LA_TYPE == LA_MACH 126551773Seric 126664295Seric /* 126765173Seric ** This has been tested on NEXTSTEP release 2.1/3.X. 126864295Seric */ 126964295Seric 127065173Seric #if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 127165173Seric # include <mach/mach.h> 127265173Seric #else 127365173Seric # include <mach.h> 127465173Seric #endif 127564295Seric 127651773Seric getla() 127751773Seric { 127864295Seric processor_set_t default_set; 127964295Seric kern_return_t error; 128064295Seric unsigned int info_count; 128164295Seric struct processor_set_basic_info info; 128264295Seric host_t host; 128364295Seric 128464295Seric error = processor_set_default(host_self(), &default_set); 128564295Seric if (error != KERN_SUCCESS) 128664295Seric return -1; 128764295Seric info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 128864295Seric if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, 128964295Seric &host, (processor_set_info_t)&info, 129064295Seric &info_count) != KERN_SUCCESS) 129164295Seric { 129264295Seric return -1; 129364295Seric } 129464295Seric return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE; 129564295Seric } 129664295Seric 129764295Seric 129864295Seric #else 129966313Seric #if LA_TYPE == LA_PROCSTR 130064295Seric 130166301Seric /* 130266301Seric ** Read /proc/loadavg for the load average. This is assumed to be 130366301Seric ** in a format like "0.15 0.12 0.06". 130466301Seric ** 130566301Seric ** Initially intended for Linux. This has been in the kernel 130666301Seric ** since at least 0.99.15. 130766301Seric */ 130866301Seric 130966301Seric # ifndef _PATH_LOADAVG 131066301Seric # define _PATH_LOADAVG "/proc/loadavg" 131166301Seric # endif 131266301Seric 131366301Seric int 131464295Seric getla() 131564295Seric { 131666319Seric double avenrun; 131766301Seric register int result; 131866319Seric FILE *fp; 131966301Seric 132066319Seric fp = fopen(_PATH_LOADAVG, "r"); 132166319Seric if (fp == NULL) 132266301Seric { 132366319Seric if (tTd(3, 1)) 132466319Seric printf("getla: fopen(%s): %s\n", 132566319Seric _PATH_LOADAVG, errstring(errno)); 132666319Seric return -1; 132766301Seric } 132866301Seric result = fscanf(fp, "%lf", &avenrun); 132966319Seric fclose(fp); 133066301Seric if (result != 1) 133166301Seric { 133266310Seric if (tTd(3, 1)) 133366301Seric printf("getla: fscanf() = %d: %s\n", 133466301Seric result, errstring(errno)); 133566301Seric return -1; 133666301Seric } 133766301Seric 133857736Seric if (tTd(3, 1)) 133966301Seric printf("getla(): %.2f\n", avenrun); 134066301Seric 134166301Seric return ((int) (avenrun + 0.5)); 134266301Seric } 134366301Seric 134466301Seric #else 134566301Seric 134666301Seric getla() 134766301Seric { 134866301Seric if (tTd(3, 1)) 134957736Seric printf("getla: ZERO\n"); 135051920Seric return (0); 135151773Seric } 135251773Seric 135351773Seric #endif 135451773Seric #endif 135564295Seric #endif 135666301Seric #endif 135766045Seric 135866045Seric 135966045Seric /* 136066045Seric * Copyright 1989 Massachusetts Institute of Technology 136166045Seric * 136266045Seric * Permission to use, copy, modify, distribute, and sell this software and its 136366045Seric * documentation for any purpose is hereby granted without fee, provided that 136466045Seric * the above copyright notice appear in all copies and that both that 136566045Seric * copyright notice and this permission notice appear in supporting 136666045Seric * documentation, and that the name of M.I.T. not be used in advertising or 136766045Seric * publicity pertaining to distribution of the software without specific, 136866045Seric * written prior permission. M.I.T. makes no representations about the 136966045Seric * suitability of this software for any purpose. It is provided "as is" 137066045Seric * without express or implied warranty. 137166045Seric * 137266045Seric * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 137366045Seric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 137466045Seric * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 137566045Seric * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 137666045Seric * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 137766045Seric * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 137866045Seric * 137966045Seric * Authors: Many and varied... 138066045Seric */ 138166045Seric 138266045Seric /* Non Apollo stuff removed by Don Lewis 11/15/93 */ 138366045Seric #ifndef lint 138466045Seric static char rcsid[] = "@(#)$Id: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $"; 138566045Seric #endif /* !lint */ 138666045Seric 138766179Seric #ifdef apollo 138866045Seric # undef volatile 138966045Seric # include <apollo/base.h> 139066045Seric 139166045Seric /* ARGSUSED */ 139266045Seric int getloadavg( call_data ) 139366045Seric caddr_t call_data; /* pointer to (double) return value */ 139466045Seric { 139566045Seric double *avenrun = (double *) call_data; 139666045Seric int i; 139766045Seric status_$t st; 139866045Seric long loadav[3]; 139966045Seric proc1_$get_loadav(loadav, &st); 140066045Seric *avenrun = loadav[0] / (double) (1 << 16); 140166045Seric return(0); 140266045Seric } 140366045Seric # endif /* apollo */ 140424943Seric /* 140524943Seric ** SHOULDQUEUE -- should this message be queued or sent? 140624943Seric ** 140724943Seric ** Compares the message cost to the load average to decide. 140824943Seric ** 140924943Seric ** Parameters: 141024943Seric ** pri -- the priority of the message in question. 141157438Seric ** ctime -- the message creation time. 141224943Seric ** 141324943Seric ** Returns: 141424943Seric ** TRUE -- if this message should be queued up for the 141524943Seric ** time being. 141624943Seric ** FALSE -- if the load is low enough to send this message. 141724943Seric ** 141824943Seric ** Side Effects: 141924943Seric ** none. 142024943Seric */ 142124943Seric 142224943Seric bool 142357438Seric shouldqueue(pri, ctime) 142424943Seric long pri; 142557438Seric time_t ctime; 142624943Seric { 142768508Seric bool rval; 142868508Seric 142968508Seric if (tTd(3, 30)) 143068508Seric printf("shouldqueue: CurrentLA=%d, pri=%d: ", CurrentLA, pri); 143151920Seric if (CurrentLA < QueueLA) 143268508Seric { 143368508Seric if (tTd(3, 30)) 143468508Seric printf("FALSE (CurrentLA < QueueLA)\n"); 143524943Seric return (FALSE); 143668508Seric } 143758132Seric if (CurrentLA >= RefuseLA) 143868508Seric { 143968508Seric if (tTd(3, 30)) 144068508Seric printf("TRUE (CurrentLA >= RefuseLA)\n"); 144158132Seric return (TRUE); 144268508Seric } 144368508Seric rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1)); 144468508Seric if (tTd(3, 30)) 144568508Seric printf("%s (by calculation)\n", rval ? "TRUE" : "FALSE"); 144668508Seric return rval; 144724943Seric } 144824943Seric /* 144953037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 145053037Seric ** 145153037Seric ** Parameters: 145253037Seric ** none. 145353037Seric ** 145453037Seric ** Returns: 145553037Seric ** TRUE if incoming SMTP connections should be refused 145653037Seric ** (for now). 145753037Seric ** FALSE if we should accept new work. 145853037Seric ** 145953037Seric ** Side Effects: 146053037Seric ** none. 146153037Seric */ 146253037Seric 146353037Seric bool 146453037Seric refuseconnections() 146553037Seric { 146668508Seric extern bool enoughspace(); 146768508Seric 146859156Seric #ifdef XLA 146959156Seric if (!xla_smtp_ok()) 147059156Seric return TRUE; 147159156Seric #endif 147259156Seric 147353037Seric /* this is probably too simplistic */ 147468508Seric return CurrentLA >= RefuseLA || !enoughspace(MinBlocksFree + 1); 147553037Seric } 147653037Seric /* 147724943Seric ** SETPROCTITLE -- set process title for ps 147824943Seric ** 147924943Seric ** Parameters: 148058674Seric ** fmt -- a printf style format string. 148158674Seric ** a, b, c -- possible parameters to fmt. 148224943Seric ** 148324943Seric ** Returns: 148424943Seric ** none. 148524943Seric ** 148624943Seric ** Side Effects: 148724943Seric ** Clobbers argv of our main procedure so ps(1) will 148824943Seric ** display the title. 148924943Seric */ 149024943Seric 149168508Seric #define SPT_NONE 0 /* don't use it at all */ 149268508Seric #define SPT_REUSEARGV 1 /* cover argv with title information */ 149368508Seric #define SPT_BUILTIN 2 /* use libc builtin */ 149468508Seric #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */ 149568508Seric #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */ 149668508Seric #define SPT_WRITEUDOT 5 /* write u. area in kmem */ 149768508Seric 149868508Seric #ifndef SPT_TYPE 149968508Seric # define SPT_TYPE SPT_REUSEARGV 150068508Seric #endif 150168508Seric 150268508Seric #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN 150368508Seric 150468508Seric # if SPT_TYPE == SPT_PSTAT 150558689Seric # include <sys/pstat.h> 150658689Seric # endif 150768508Seric # if SPT_TYPE == SPT_PSSTRINGS 150859732Seric # include <machine/vmparam.h> 150959732Seric # include <sys/exec.h> 151068508Seric # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */ 151168508Seric # undef SPT_TYPE 151268508Seric # define SPT_TYPE SPT_REUSEARGV 151368734Seric # else 151468734Seric # ifndef NKPDE /* FreeBSD 2.0 */ 151568734Seric # define NKPDE 63 151668734Seric typedef unsigned int *pt_entry_t; 151768734Seric # endif 151864247Seric # endif 151959732Seric # endif 152068508Seric 152168508Seric # if SPT_TYPE == SPT_PSSTRINGS 152268508Seric # define SETPROC_STATIC static 152368508Seric # else 152459732Seric # define SETPROC_STATIC 152559732Seric # endif 152667626Seric 152768508Seric # ifndef SPT_PADCHAR 152868508Seric # define SPT_PADCHAR ' ' 152968508Seric # endif 153058689Seric 153168508Seric #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */ 153264843Seric 153368508Seric #if SPT_TYPE != SPT_BUILTIN 153468508Seric 153524943Seric /*VARARGS1*/ 153668508Seric void 153768508Seric # ifdef __STDC__ 153857642Seric setproctitle(char *fmt, ...) 153968508Seric # else 154057642Seric setproctitle(fmt, va_alist) 154124943Seric char *fmt; 154257642Seric va_dcl 154368508Seric # endif 154424943Seric { 154568508Seric # if SPT_TYPE != SPT_NONE 154624943Seric register char *p; 154725049Seric register int i; 154859732Seric SETPROC_STATIC char buf[MAXLINE]; 154956852Seric VA_LOCAL_DECL 155068508Seric # if SPT_TYPE == SPT_PSTAT 155158689Seric union pstun pst; 155258689Seric # endif 155324943Seric extern char **Argv; 155424943Seric extern char *LastArgv; 155524943Seric 155658674Seric p = buf; 155724943Seric 155858674Seric /* print sendmail: heading for grep */ 155958674Seric (void) strcpy(p, "sendmail: "); 156058674Seric p += strlen(p); 156124943Seric 156258674Seric /* print the argument string */ 156358674Seric VA_START(fmt); 156458674Seric (void) vsprintf(p, fmt, ap); 156556852Seric VA_END; 156654996Seric 156758674Seric i = strlen(buf); 156858689Seric 156968508Seric # if SPT_TYPE == SPT_PSTAT 157058689Seric pst.pst_command = buf; 157158689Seric pstat(PSTAT_SETCMD, pst, i, 0, 0); 157258689Seric # else 157368508Seric # if SPT_TYPE == SPT_PSSTRINGS 157459732Seric PS_STRINGS->ps_nargvstr = 1; 157559732Seric PS_STRINGS->ps_argvstr = buf; 157659732Seric # else 157754996Seric if (i > LastArgv - Argv[0] - 2) 157825049Seric { 157954996Seric i = LastArgv - Argv[0] - 2; 158058674Seric buf[i] = '\0'; 158125049Seric } 158258674Seric (void) strcpy(Argv[0], buf); 158354997Seric p = &Argv[0][i]; 158424943Seric while (p < LastArgv) 158568508Seric *p++ = SPT_PADCHAR; 158668508Seric Argv[1] = NULL; 158768508Seric # endif /* SPT_TYPE == SPT_PSSTRINGS */ 158868508Seric # endif /* SPT_TYPE == SPT_PSTAT */ 158968508Seric # endif /* SPT_TYPE != SPT_NONE */ 159024943Seric } 159165982Seric 159268508Seric #endif /* SPT_TYPE != SPT_BUILTIN */ 159325698Seric /* 159425698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 159525698Seric ** 159625698Seric ** Parameters: 159768508Seric ** sig -- the signal that got us here (unused). 159825698Seric ** 159925698Seric ** Returns: 160025698Seric ** none. 160125698Seric ** 160225698Seric ** Side Effects: 160325698Seric ** Picks up extant zombies. 160425698Seric */ 160525698Seric 160646928Sbostic void 160768508Seric reapchild(sig) 160868508Seric int sig; 160925698Seric { 161064738Seric int olderrno = errno; 161163966Seric # ifdef HASWAITPID 161260219Seric auto int status; 161360560Seric int count; 161460560Seric int pid; 161560219Seric 161660560Seric count = 0; 161760560Seric while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 161860560Seric { 161960560Seric if (count++ > 1000) 162060560Seric { 162166748Seric #ifdef LOG 162260560Seric syslog(LOG_ALERT, "reapchild: waitpid loop: pid=%d, status=%x", 162360560Seric pid, status); 162466748Seric #endif 162560560Seric break; 162660560Seric } 162760560Seric } 162860219Seric # else 162925698Seric # ifdef WNOHANG 163025698Seric union wait status; 163125698Seric 163263753Seric while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) 163325698Seric continue; 163456795Seric # else /* WNOHANG */ 163525698Seric auto int status; 163625698Seric 163760219Seric while (wait(&status) > 0) 163825698Seric continue; 163956795Seric # endif /* WNOHANG */ 164060219Seric # endif 164164035Seric # ifdef SYS5SIGNALS 164264035Seric (void) setsignal(SIGCHLD, reapchild); 164358061Seric # endif 164464738Seric errno = olderrno; 164525698Seric } 164655418Seric /* 164755418Seric ** UNSETENV -- remove a variable from the environment 164855418Seric ** 164955418Seric ** Not needed on newer systems. 165055418Seric ** 165155418Seric ** Parameters: 165255418Seric ** name -- the string name of the environment variable to be 165355418Seric ** deleted from the current environment. 165455418Seric ** 165555418Seric ** Returns: 165655418Seric ** none. 165755418Seric ** 165855418Seric ** Globals: 165955418Seric ** environ -- a pointer to the current environment. 166055418Seric ** 166155418Seric ** Side Effects: 166255418Seric ** Modifies environ. 166355418Seric */ 166455418Seric 166563962Seric #ifndef HASUNSETENV 166655418Seric 166755418Seric void 166855418Seric unsetenv(name) 166955418Seric char *name; 167055418Seric { 167155418Seric extern char **environ; 167255418Seric register char **pp; 167355418Seric int len = strlen(name); 167455418Seric 167555418Seric for (pp = environ; *pp != NULL; pp++) 167655418Seric { 167755418Seric if (strncmp(name, *pp, len) == 0 && 167855418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 167955418Seric break; 168055418Seric } 168155418Seric 168255418Seric for (; *pp != NULL; pp++) 168355418Seric *pp = pp[1]; 168455418Seric } 168555418Seric 168663962Seric #endif 168756215Seric /* 168856215Seric ** GETDTABLESIZE -- return number of file descriptors 168956215Seric ** 169056215Seric ** Only on non-BSD systems 169156215Seric ** 169256215Seric ** Parameters: 169356215Seric ** none 169456215Seric ** 169556215Seric ** Returns: 169656215Seric ** size of file descriptor table 169756215Seric ** 169856215Seric ** Side Effects: 169956215Seric ** none 170056215Seric */ 170156215Seric 170263787Seric #ifdef SOLARIS 170363787Seric # include <sys/resource.h> 170463787Seric #endif 170556215Seric 170656215Seric int 170763787Seric getdtsize() 170856215Seric { 170963787Seric #ifdef RLIMIT_NOFILE 171063787Seric struct rlimit rl; 171163787Seric 171263787Seric if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) 171363787Seric return rl.rlim_cur; 171463787Seric #endif 171563787Seric 171664031Seric # ifdef HASGETDTABLESIZE 171764031Seric return getdtablesize(); 171864031Seric # else 171964031Seric # ifdef _SC_OPEN_MAX 172058689Seric return sysconf(_SC_OPEN_MAX); 172163787Seric # else 172256215Seric return NOFILE; 172363787Seric # endif 172458689Seric # endif 172556215Seric } 172657631Seric /* 172757631Seric ** UNAME -- get the UUCP name of this system. 172857631Seric */ 172957631Seric 173057943Seric #ifndef HASUNAME 173157631Seric 173257631Seric int 173357631Seric uname(name) 173457631Seric struct utsname *name; 173557631Seric { 173657631Seric FILE *file; 173757631Seric char *n; 173857631Seric 173957631Seric name->nodename[0] = '\0'; 174057631Seric 174157661Seric /* try /etc/whoami -- one line with the node name */ 174257631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 174357631Seric { 174457661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 174557631Seric (void) fclose(file); 174657661Seric n = strchr(name->nodename, '\n'); 174757631Seric if (n != NULL) 174857631Seric *n = '\0'; 174957631Seric if (name->nodename[0] != '\0') 175057631Seric return (0); 175157631Seric } 175257631Seric 175357661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 175457631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 175557631Seric { 175657631Seric char buf[MAXLINE]; 175757631Seric 175857631Seric while (fgets(buf, MAXLINE, file) != NULL) 175957631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 176057631Seric NODE_LENGTH, name->nodename) > 0) 176157631Seric break; 176257631Seric (void) fclose(file); 176357631Seric if (name->nodename[0] != '\0') 176457631Seric return (0); 176557631Seric } 176657631Seric 176757631Seric #ifdef TRUST_POPEN 176857631Seric /* 176957631Seric ** Popen is known to have security holes. 177057631Seric */ 177157631Seric 177257661Seric /* try uuname -l to return local name */ 177357631Seric if ((file = popen("uuname -l", "r")) != NULL) 177457631Seric { 177557661Seric (void) fgets(name, NODE_LENGTH + 1, file); 177657631Seric (void) pclose(file); 177757661Seric n = strchr(name, '\n'); 177857631Seric if (n != NULL) 177957631Seric *n = '\0'; 178057661Seric if (name->nodename[0] != '\0') 178157631Seric return (0); 178257631Seric } 178357631Seric #endif 178457631Seric 178557631Seric return (-1); 178657631Seric } 178757943Seric #endif /* HASUNAME */ 178858068Seric /* 178958068Seric ** INITGROUPS -- initialize groups 179058068Seric ** 179158068Seric ** Stub implementation for System V style systems 179258068Seric */ 179358068Seric 179458068Seric #ifndef HASINITGROUPS 179558068Seric 179658068Seric initgroups(name, basegid) 179758068Seric char *name; 179858068Seric int basegid; 179958068Seric { 180058068Seric return 0; 180158068Seric } 180258068Seric 180358068Seric #endif 180458082Seric /* 180559289Seric ** SETSID -- set session id (for non-POSIX systems) 180659289Seric */ 180759289Seric 180859289Seric #ifndef HASSETSID 180959289Seric 181063753Seric pid_t 181163753Seric setsid __P ((void)) 181259289Seric { 181364155Seric #ifdef TIOCNOTTY 181464155Seric int fd; 181564155Seric 181666743Seric fd = open("/dev/tty", O_RDWR, 0); 181764155Seric if (fd >= 0) 181864155Seric { 181964155Seric (void) ioctl(fd, (int) TIOCNOTTY, (char *) 0); 182064155Seric (void) close(fd); 182164155Seric } 182264155Seric #endif /* TIOCNOTTY */ 182364705Seric # ifdef SYS5SETPGRP 182463753Seric return setpgrp(); 182563753Seric # else 182664155Seric return setpgid(0, getpid()); 182759289Seric # endif 182859289Seric } 182959289Seric 183059289Seric #endif 183159289Seric /* 183266748Seric ** FSYNC -- dummy fsync 183366748Seric */ 183466748Seric 183566748Seric #ifdef NEEDFSYNC 183666748Seric 183766748Seric fsync(fd) 183866748Seric int fd; 183966748Seric { 184066748Seric # ifdef O_SYNC 184166748Seric return fcntl(fd, F_SETFL, O_SYNC); 184266748Seric # else 184366748Seric /* nothing we can do */ 184466748Seric return 0; 184566748Seric # endif 184666748Seric } 184766748Seric 184866748Seric #endif 184966748Seric /* 185064718Seric ** DGUX_INET_ADDR -- inet_addr for DG/UX 185164718Seric ** 185264718Seric ** Data General DG/UX version of inet_addr returns a struct in_addr 185368508Seric ** instead of a long. This patches things. Only needed on versions 185468508Seric ** prior to 5.4.3. 185564718Seric */ 185664718Seric 185768508Seric #ifdef DGUX_5_4_2 185864718Seric 185964718Seric #undef inet_addr 186064718Seric 186164718Seric long 186264718Seric dgux_inet_addr(host) 186364718Seric char *host; 186464718Seric { 186564718Seric struct in_addr haddr; 186664718Seric 186764718Seric haddr = inet_addr(host); 186864718Seric return haddr.s_addr; 186964718Seric } 187064718Seric 187164718Seric #endif 187264718Seric /* 187363969Seric ** GETOPT -- for old systems or systems with bogus implementations 187463969Seric */ 187563969Seric 187663969Seric #ifdef NEEDGETOPT 187763969Seric 187863969Seric /* 187963969Seric * Copyright (c) 1985 Regents of the University of California. 188063969Seric * All rights reserved. The Berkeley software License Agreement 188163969Seric * specifies the terms and conditions for redistribution. 188263969Seric */ 188363969Seric 188463969Seric 188563969Seric /* 188663969Seric ** this version hacked to add `atend' flag to allow state machine 188763969Seric ** to reset if invoked by the program to scan args for a 2nd time 188863969Seric */ 188963969Seric 189063969Seric #if defined(LIBC_SCCS) && !defined(lint) 189163969Seric static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; 189264072Seric #endif /* LIBC_SCCS and not lint */ 189363969Seric 189463969Seric #include <stdio.h> 189563969Seric 189663969Seric /* 189763969Seric * get option letter from argument vector 189863969Seric */ 189965352Seric #ifdef _CONVEX_SOURCE 190068508Seric extern int optind, opterr, optopt; 190168508Seric extern char *optarg; 190265352Seric #else 190365352Seric int opterr = 1; /* if error message should be printed */ 190465352Seric int optind = 1; /* index into parent argv vector */ 190568470Seric int optopt = 0; /* character checked for validity */ 190668470Seric char *optarg = NULL; /* argument associated with option */ 190768508Seric #endif 190863969Seric 190963969Seric #define BADCH (int)'?' 191063969Seric #define EMSG "" 191163969Seric #define tell(s) if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ 191263969Seric fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);} 191363969Seric 191463969Seric getopt(nargc,nargv,ostr) 191565160Seric int nargc; 191665160Seric char *const *nargv; 191765160Seric const char *ostr; 191863969Seric { 191963969Seric static char *place = EMSG; /* option letter processing */ 192063969Seric static char atend = 0; 192163969Seric register char *oli; /* option letter list index */ 192263969Seric 192363969Seric if (atend) { 192463969Seric atend = 0; 192563969Seric place = EMSG; 192663969Seric } 192763969Seric if(!*place) { /* update scanning pointer */ 192864136Seric if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) { 192963969Seric atend++; 193063969Seric return(EOF); 193163969Seric } 193263969Seric if (*place == '-') { /* found "--" */ 193363969Seric ++optind; 193463969Seric atend++; 193563969Seric return(EOF); 193663969Seric } 193763969Seric } /* option letter okay? */ 193864125Seric if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) { 193964136Seric if (!*place) ++optind; 194063969Seric tell(": illegal option -- "); 194163969Seric } 194263969Seric if (*++oli != ':') { /* don't need argument */ 194363969Seric optarg = NULL; 194463969Seric if (!*place) ++optind; 194563969Seric } 194663969Seric else { /* need an argument */ 194763969Seric if (*place) optarg = place; /* no white space */ 194863969Seric else if (nargc <= ++optind) { /* no arg */ 194963969Seric place = EMSG; 195063969Seric tell(": option requires an argument -- "); 195163969Seric } 195263969Seric else optarg = nargv[optind]; /* white space */ 195363969Seric place = EMSG; 195463969Seric ++optind; 195563969Seric } 195663969Seric return(optopt); /* dump back option letter */ 195763969Seric } 195863969Seric 195963969Seric #endif 196063969Seric /* 196163969Seric ** VFPRINTF, VSPRINTF -- for old 4.3 BSD systems missing a real version 196263969Seric */ 196363969Seric 196463969Seric #ifdef NEEDVPRINTF 196563969Seric 196663969Seric #define MAXARG 16 196763969Seric 196863969Seric vfprintf(fp, fmt, ap) 196963969Seric FILE * fp; 197063969Seric char * fmt; 197163969Seric char ** ap; 197263969Seric { 197363969Seric char * bp[MAXARG]; 197463969Seric int i = 0; 197563969Seric 197663969Seric while (*ap && i < MAXARG) 197763969Seric bp[i++] = *ap++; 197863969Seric fprintf(fp, fmt, bp[0], bp[1], bp[2], bp[3], 197963969Seric bp[4], bp[5], bp[6], bp[7], 198063969Seric bp[8], bp[9], bp[10], bp[11], 198163969Seric bp[12], bp[13], bp[14], bp[15]); 198263969Seric } 198363969Seric 198463969Seric vsprintf(s, fmt, ap) 198563969Seric char * s; 198663969Seric char * fmt; 198763969Seric char ** ap; 198863969Seric { 198963969Seric char * bp[MAXARG]; 199063969Seric int i = 0; 199163969Seric 199263969Seric while (*ap && i < MAXARG) 199363969Seric bp[i++] = *ap++; 199463969Seric sprintf(s, fmt, bp[0], bp[1], bp[2], bp[3], 199563969Seric bp[4], bp[5], bp[6], bp[7], 199663969Seric bp[8], bp[9], bp[10], bp[11], 199763969Seric bp[12], bp[13], bp[14], bp[15]); 199863969Seric } 199963969Seric 200063969Seric #endif 200163969Seric /* 200265220Seric ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use 200365208Seric ** 200465211Seric ** Parameters: 200565211Seric ** shell -- the user's shell from /etc/passwd 200665211Seric ** 200765211Seric ** Returns: 200865211Seric ** TRUE -- if it is ok to use this for unrestricted access. 200965211Seric ** FALSE -- if the shell is restricted. 201065208Seric */ 201165208Seric 201265587Seric #if !HASGETUSERSHELL 201365587Seric 201465587Seric # ifndef _PATH_SHELLS 201565587Seric # define _PATH_SHELLS "/etc/shells" 201665587Seric # endif 201765587Seric 201865587Seric char *DefaultUserShells[] = 201965587Seric { 202068508Seric "/bin/sh", /* standard shell */ 202165587Seric "/usr/bin/sh", 202268508Seric "/bin/csh", /* C shell */ 202365587Seric "/usr/bin/csh", 202465587Seric #ifdef __hpux 202568889Seric # ifdef V4FS 202668889Seric "/usr/bin/rsh", /* restricted Bourne shell */ 202768889Seric "/usr/bin/ksh", /* Korn shell */ 202868889Seric "/usr/bin/rksh", /* restricted Korn shell */ 202968889Seric "/usr/bin/pam", 203068889Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 203168889Seric "/usr/bin/posix/sh", 203268889Seric # else 203368508Seric "/bin/rsh", /* restricted Bourne shell */ 203468508Seric "/bin/ksh", /* Korn shell */ 203568508Seric "/bin/rksh", /* restricted Korn shell */ 203665587Seric "/bin/pam", 203768508Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 203865587Seric "/bin/posix/sh", 203968889Seric # endif 204065211Seric #endif 204168508Seric #ifdef _AIX3 204268508Seric "/bin/ksh", /* Korn shell */ 204368508Seric "/usr/bin/ksh", 204468508Seric "/bin/tsh", /* trusted shell */ 204568508Seric "/usr/bin/tsh", 204668508Seric "/bin/bsh", /* Bourne shell */ 204768508Seric "/usr/bin/bsh", 204868508Seric #endif 204965587Seric NULL 205065587Seric }; 205165587Seric 205265208Seric #endif 205365208Seric 205465747Seric #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" 205565747Seric 205665211Seric bool 205765211Seric usershellok(shell) 205865211Seric char *shell; 205965208Seric { 206065211Seric #if HASGETUSERSHELL 206165211Seric register char *p; 206265211Seric extern char *getusershell(); 206365208Seric 206468457Seric if (shell == NULL || shell[0] == '\0') 206568457Seric return TRUE; 206668457Seric 206765211Seric setusershell(); 206865211Seric while ((p = getusershell()) != NULL) 206965747Seric if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0) 207065211Seric break; 207165211Seric endusershell(); 207265211Seric return p != NULL; 207365211Seric #else 207465211Seric register FILE *shellf; 207565211Seric char buf[MAXLINE]; 207665208Seric 207768457Seric if (shell == NULL || shell[0] == '\0') 207868457Seric return TRUE; 207968457Seric 208065211Seric shellf = fopen(_PATH_SHELLS, "r"); 208165211Seric if (shellf == NULL) 208265211Seric { 208365211Seric /* no /etc/shells; see if it is one of the std shells */ 208465587Seric char **d; 208565587Seric 208665587Seric for (d = DefaultUserShells; *d != NULL; d++) 208765587Seric { 208865587Seric if (strcmp(shell, *d) == 0) 208965587Seric return TRUE; 209065587Seric } 209165587Seric return FALSE; 209265211Seric } 209365208Seric 209465211Seric while (fgets(buf, sizeof buf, shellf) != NULL) 209565211Seric { 209665211Seric register char *p, *q; 209765208Seric 209865211Seric p = buf; 209965211Seric while (*p != '\0' && *p != '#' && *p != '/') 210065211Seric p++; 210165211Seric if (*p == '#' || *p == '\0') 210265208Seric continue; 210365211Seric q = p; 210465211Seric while (*p != '\0' && *p != '#' && !isspace(*p)) 210565211Seric p++; 210665211Seric *p = '\0'; 210765747Seric if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0) 210865211Seric { 210965211Seric fclose(shellf); 211065211Seric return TRUE; 211165211Seric } 211265208Seric } 211365211Seric fclose(shellf); 211465211Seric return FALSE; 211565211Seric #endif 211665208Seric } 211765208Seric /* 211864311Seric ** FREESPACE -- see how much free space is on the queue filesystem 211958082Seric ** 212058082Seric ** Only implemented if you have statfs. 212158082Seric ** 212258082Seric ** Parameters: 212364311Seric ** dir -- the directory in question. 212464311Seric ** bsize -- a variable into which the filesystem 212564311Seric ** block size is stored. 212658082Seric ** 212758082Seric ** Returns: 212864311Seric ** The number of bytes free on the queue filesystem. 212964311Seric ** -1 if the statfs call fails. 213064311Seric ** 213164311Seric ** Side effects: 213264311Seric ** Puts the filesystem block size into bsize. 213358082Seric */ 213458082Seric 213565749Seric /* statfs types */ 213665749Seric #define SFS_NONE 0 /* no statfs implementation */ 213765749Seric #define SFS_USTAT 1 /* use ustat */ 213865749Seric #define SFS_4ARGS 2 /* use four-argument statfs call */ 213965749Seric #define SFS_VFS 3 /* use <sys/vfs.h> implementation */ 214065749Seric #define SFS_MOUNT 4 /* use <sys/mount.h> implementation */ 214165749Seric #define SFS_STATFS 5 /* use <sys/statfs.h> implementation */ 214266752Seric #define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */ 214365749Seric 214465749Seric #ifndef SFS_TYPE 214565749Seric # define SFS_TYPE SFS_NONE 214658157Seric #endif 214758157Seric 214865749Seric #if SFS_TYPE == SFS_USTAT 214958157Seric # include <ustat.h> 215058157Seric #endif 215165749Seric #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS 215265749Seric # include <sys/statfs.h> 215358082Seric #endif 215465749Seric #if SFS_TYPE == SFS_VFS 215565749Seric # include <sys/vfs.h> 215665749Seric #endif 215765749Seric #if SFS_TYPE == SFS_MOUNT 215865749Seric # include <sys/mount.h> 215965749Seric #endif 216066752Seric #if SFS_TYPE == SFS_STATVFS 216166752Seric # include <sys/statvfs.h> 216266752Seric #endif 216358082Seric 216464311Seric long 216564311Seric freespace(dir, bsize) 216664311Seric char *dir; 216764311Seric long *bsize; 216858082Seric { 216965749Seric #if SFS_TYPE != SFS_NONE 217065749Seric # if SFS_TYPE == SFS_USTAT 217158153Seric struct ustat fs; 217258153Seric struct stat statbuf; 217358366Seric # define FSBLOCKSIZE DEV_BSIZE 217468695Seric # define SFS_BAVAIL f_tfree 217558157Seric # else 217658157Seric # if defined(ultrix) 217758157Seric struct fs_data fs; 217868695Seric # define SFS_BAVAIL fd_bfreen 217968508Seric # define FSBLOCKSIZE 1024L 218058153Seric # else 218166752Seric # if SFS_TYPE == SFS_STATVFS 218266752Seric struct statvfs fs; 218368508Seric # define FSBLOCKSIZE fs.f_frsize 218466752Seric # else 218558082Seric struct statfs fs; 218666752Seric # define FSBLOCKSIZE fs.f_bsize 218763987Seric # endif 218858153Seric # endif 218958133Seric # endif 219068695Seric # ifndef SFS_BAVAIL 219168695Seric # define SFS_BAVAIL f_bavail 219268508Seric # endif 219358082Seric 219465749Seric # if SFS_TYPE == SFS_USTAT 219564311Seric if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 219658157Seric # else 219765749Seric # if SFS_TYPE == SFS_4ARGS 219864311Seric if (statfs(dir, &fs, sizeof fs, 0) == 0) 219958157Seric # else 220068508Seric # if SFS_TYPE == SFS_STATVFS 220168508Seric if (statvfs(dir, &fs) == 0) 220268508Seric # else 220368508Seric # if defined(ultrix) 220468499Seric if (statfs(dir, &fs) > 0) 220568508Seric # else 220664311Seric if (statfs(dir, &fs) == 0) 220768508Seric # endif 220858153Seric # endif 220958133Seric # endif 221058133Seric # endif 221158133Seric { 221264311Seric if (bsize != NULL) 221364311Seric *bsize = FSBLOCKSIZE; 221468695Seric return (fs.SFS_BAVAIL); 221564311Seric } 221664337Seric #endif 221764311Seric return (-1); 221864311Seric } 221964311Seric /* 222064311Seric ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 222164311Seric ** 222264311Seric ** Only implemented if you have statfs. 222364311Seric ** 222464311Seric ** Parameters: 222564311Seric ** msize -- the size to check against. If zero, we don't yet 222664311Seric ** know how big the message will be, so just check for 222764311Seric ** a "reasonable" amount. 222864311Seric ** 222964311Seric ** Returns: 223064311Seric ** TRUE if there is enough space. 223164311Seric ** FALSE otherwise. 223264311Seric */ 223364311Seric 223464311Seric bool 223564311Seric enoughspace(msize) 223664311Seric long msize; 223764311Seric { 223864311Seric long bfree, bsize; 223964311Seric 224064311Seric if (MinBlocksFree <= 0 && msize <= 0) 224164311Seric { 224258133Seric if (tTd(4, 80)) 224364311Seric printf("enoughspace: no threshold\n"); 224464311Seric return TRUE; 224564311Seric } 224664311Seric 224764311Seric if ((bfree = freespace(QueueDir, &bsize)) >= 0) 224864311Seric { 224964311Seric if (tTd(4, 80)) 225058333Seric printf("enoughspace: bavail=%ld, need=%ld\n", 225164311Seric bfree, msize); 225258333Seric 225358333Seric /* convert msize to block count */ 225464311Seric msize = msize / bsize + 1; 225558333Seric if (MinBlocksFree >= 0) 225658333Seric msize += MinBlocksFree; 225758333Seric 225864311Seric if (bfree < msize) 225958090Seric { 226058090Seric #ifdef LOG 226158090Seric if (LogLevel > 0) 226264254Seric syslog(LOG_ALERT, 226364254Seric "%s: low on space (have %ld, %s needs %ld in %s)", 226468508Seric CurEnv->e_id == NULL ? "[NOQUEUE]" : CurEnv->e_id, 226568508Seric bfree, 226668508Seric CurHostName == NULL ? "SMTP-DAEMON" : CurHostName, 226768508Seric msize, QueueDir); 226858090Seric #endif 226958082Seric return FALSE; 227058090Seric } 227158082Seric } 227258082Seric else if (tTd(4, 80)) 227358333Seric printf("enoughspace failure: min=%ld, need=%ld: %s\n", 227458333Seric MinBlocksFree, msize, errstring(errno)); 227558082Seric return TRUE; 227658082Seric } 227758542Seric /* 227858542Seric ** TRANSIENTERROR -- tell if an error code indicates a transient failure 227958542Seric ** 228058542Seric ** This looks at an errno value and tells if this is likely to 228158542Seric ** go away if retried later. 228258542Seric ** 228358542Seric ** Parameters: 228458542Seric ** err -- the errno code to classify. 228558542Seric ** 228658542Seric ** Returns: 228758542Seric ** TRUE if this is probably transient. 228858542Seric ** FALSE otherwise. 228958542Seric */ 229058542Seric 229158542Seric bool 229258542Seric transienterror(err) 229358542Seric int err; 229458542Seric { 229558542Seric switch (err) 229658542Seric { 229758542Seric case EIO: /* I/O error */ 229858542Seric case ENXIO: /* Device not configured */ 229958542Seric case EAGAIN: /* Resource temporarily unavailable */ 230058542Seric case ENOMEM: /* Cannot allocate memory */ 230158542Seric case ENODEV: /* Operation not supported by device */ 230258542Seric case ENFILE: /* Too many open files in system */ 230358542Seric case EMFILE: /* Too many open files */ 230458542Seric case ENOSPC: /* No space left on device */ 230558542Seric #ifdef ETIMEDOUT 230658542Seric case ETIMEDOUT: /* Connection timed out */ 230758542Seric #endif 230858542Seric #ifdef ESTALE 230958542Seric case ESTALE: /* Stale NFS file handle */ 231058542Seric #endif 231158542Seric #ifdef ENETDOWN 231258542Seric case ENETDOWN: /* Network is down */ 231358542Seric #endif 231458542Seric #ifdef ENETUNREACH 231558542Seric case ENETUNREACH: /* Network is unreachable */ 231658542Seric #endif 231758542Seric #ifdef ENETRESET 231858542Seric case ENETRESET: /* Network dropped connection on reset */ 231958542Seric #endif 232058542Seric #ifdef ECONNABORTED 232158542Seric case ECONNABORTED: /* Software caused connection abort */ 232258542Seric #endif 232358542Seric #ifdef ECONNRESET 232458542Seric case ECONNRESET: /* Connection reset by peer */ 232558542Seric #endif 232658542Seric #ifdef ENOBUFS 232758542Seric case ENOBUFS: /* No buffer space available */ 232858542Seric #endif 232958542Seric #ifdef ESHUTDOWN 233058542Seric case ESHUTDOWN: /* Can't send after socket shutdown */ 233158542Seric #endif 233258542Seric #ifdef ECONNREFUSED 233358542Seric case ECONNREFUSED: /* Connection refused */ 233458542Seric #endif 233558542Seric #ifdef EHOSTDOWN 233658542Seric case EHOSTDOWN: /* Host is down */ 233758542Seric #endif 233858542Seric #ifdef EHOSTUNREACH 233958542Seric case EHOSTUNREACH: /* No route to host */ 234058542Seric #endif 234158542Seric #ifdef EDQUOT 234258542Seric case EDQUOT: /* Disc quota exceeded */ 234358542Seric #endif 234458542Seric #ifdef EPROCLIM 234558542Seric case EPROCLIM: /* Too many processes */ 234658542Seric #endif 234758542Seric #ifdef EUSERS 234858542Seric case EUSERS: /* Too many users */ 234958542Seric #endif 235058542Seric #ifdef EDEADLK 235158542Seric case EDEADLK: /* Resource deadlock avoided */ 235258542Seric #endif 235358542Seric #ifdef EISCONN 235458542Seric case EISCONN: /* Socket already connected */ 235558542Seric #endif 235658542Seric #ifdef EINPROGRESS 235758542Seric case EINPROGRESS: /* Operation now in progress */ 235858542Seric #endif 235958542Seric #ifdef EALREADY 236058542Seric case EALREADY: /* Operation already in progress */ 236158542Seric #endif 236258542Seric #ifdef EADDRINUSE 236358542Seric case EADDRINUSE: /* Address already in use */ 236458542Seric #endif 236558542Seric #ifdef EADDRNOTAVAIL 236658542Seric case EADDRNOTAVAIL: /* Can't assign requested address */ 236758542Seric #endif 236866018Seric #ifdef ETXTBSY 236966017Seric case ETXTBSY: /* (Apollo) file locked */ 237066017Seric #endif 237163834Seric #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) 237258542Seric case ENOSR: /* Out of streams resources */ 237358542Seric #endif 237458542Seric return TRUE; 237558542Seric } 237658542Seric 237758542Seric /* nope, must be permanent */ 237858542Seric return FALSE; 237958542Seric } 238058689Seric /* 238164035Seric ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking 238258689Seric ** 238358689Seric ** Parameters: 238458689Seric ** fd -- the file descriptor of the file. 238558689Seric ** filename -- the file name (for error messages). 238664335Seric ** ext -- the filename extension. 238758689Seric ** type -- type of the lock. Bits can be: 238858689Seric ** LOCK_EX -- exclusive lock. 238958689Seric ** LOCK_NB -- non-blocking. 239058689Seric ** 239158689Seric ** Returns: 239258689Seric ** TRUE if the lock was acquired. 239358689Seric ** FALSE otherwise. 239458689Seric */ 239558689Seric 239658689Seric bool 239764335Seric lockfile(fd, filename, ext, type) 239858689Seric int fd; 239958689Seric char *filename; 240064335Seric char *ext; 240158689Seric int type; 240258689Seric { 240365830Seric # if !HASFLOCK 240458689Seric int action; 240558689Seric struct flock lfd; 240664335Seric 240764335Seric if (ext == NULL) 240864335Seric ext = ""; 240964035Seric 241063983Seric bzero(&lfd, sizeof lfd); 241159447Seric if (bitset(LOCK_UN, type)) 241259447Seric lfd.l_type = F_UNLCK; 241359447Seric else if (bitset(LOCK_EX, type)) 241458689Seric lfd.l_type = F_WRLCK; 241558689Seric else 241658689Seric lfd.l_type = F_RDLCK; 241758689Seric 241858689Seric if (bitset(LOCK_NB, type)) 241958689Seric action = F_SETLK; 242058689Seric else 242158689Seric action = F_SETLKW; 242258689Seric 242364264Seric if (tTd(55, 60)) 242464335Seric printf("lockfile(%s%s, action=%d, type=%d): ", 242564335Seric filename, ext, action, lfd.l_type); 242664264Seric 242758689Seric if (fcntl(fd, action, &lfd) >= 0) 242864264Seric { 242964264Seric if (tTd(55, 60)) 243064264Seric printf("SUCCESS\n"); 243158689Seric return TRUE; 243264264Seric } 243358689Seric 243464264Seric if (tTd(55, 60)) 243564264Seric printf("(%s) ", errstring(errno)); 243664264Seric 243764136Seric /* 243864136Seric ** On SunOS, if you are testing using -oQ/tmp/mqueue or 243964136Seric ** -oA/tmp/aliases or anything like that, and /tmp is mounted 244064136Seric ** as type "tmp" (that is, served from swap space), the 244164136Seric ** previous fcntl will fail with "Invalid argument" errors. 244264136Seric ** Since this is fairly common during testing, we will assume 244364136Seric ** that this indicates that the lock is successfully grabbed. 244464136Seric */ 244564136Seric 244664136Seric if (errno == EINVAL) 244764264Seric { 244864264Seric if (tTd(55, 60)) 244964264Seric printf("SUCCESS\n"); 245064136Seric return TRUE; 245164264Seric } 245264136Seric 245358689Seric if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 245464378Seric { 245564378Seric int omode = -1; 245664378Seric # ifdef F_GETFL 245764378Seric int oerrno = errno; 245864378Seric 245964378Seric (void) fcntl(fd, F_GETFL, &omode); 246064378Seric errno = oerrno; 246164378Seric # endif 246264378Seric syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 246364378Seric filename, ext, fd, type, omode, geteuid()); 246464378Seric } 246558689Seric # else 246664335Seric if (ext == NULL) 246764335Seric ext = ""; 246864335Seric 246964264Seric if (tTd(55, 60)) 247064335Seric printf("lockfile(%s%s, type=%o): ", filename, ext, type); 247164264Seric 247258689Seric if (flock(fd, type) >= 0) 247364264Seric { 247464264Seric if (tTd(55, 60)) 247564264Seric printf("SUCCESS\n"); 247658689Seric return TRUE; 247764264Seric } 247858689Seric 247964264Seric if (tTd(55, 60)) 248064264Seric printf("(%s) ", errstring(errno)); 248164264Seric 248258689Seric if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 248364378Seric { 248464378Seric int omode = -1; 248564378Seric # ifdef F_GETFL 248664378Seric int oerrno = errno; 248764378Seric 248864378Seric (void) fcntl(fd, F_GETFL, &omode); 248964378Seric errno = oerrno; 249064378Seric # endif 249164378Seric syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 249264378Seric filename, ext, fd, type, omode, geteuid()); 249364386Seric } 249458689Seric # endif 249564264Seric if (tTd(55, 60)) 249664264Seric printf("FAIL\n"); 249758689Seric return FALSE; 249858689Seric } 249964556Seric /* 250065948Seric ** CHOWNSAFE -- tell if chown is "safe" (executable only by root) 250165948Seric ** 250265948Seric ** Parameters: 250365948Seric ** fd -- the file descriptor to check. 250465948Seric ** 250565948Seric ** Returns: 250665948Seric ** TRUE -- if only root can chown the file to an arbitrary 250765948Seric ** user. 250865948Seric ** FALSE -- if an arbitrary user can give away a file. 250965948Seric */ 251065948Seric 251165948Seric bool 251265948Seric chownsafe(fd) 251365948Seric int fd; 251465948Seric { 251565950Seric #ifdef __hpux 251665948Seric char *s; 251765948Seric int tfd; 251865948Seric uid_t o_uid, o_euid; 251965948Seric gid_t o_gid, o_egid; 252065948Seric bool rval; 252165948Seric struct stat stbuf; 252265948Seric 252365948Seric o_uid = getuid(); 252465948Seric o_euid = geteuid(); 252565948Seric o_gid = getgid(); 252665948Seric o_egid = getegid(); 252765959Seric fstat(fd, &stbuf); 252865948Seric setresuid(stbuf.st_uid, stbuf.st_uid, -1); 252965948Seric setresgid(stbuf.st_gid, stbuf.st_gid, -1); 253065948Seric s = tmpnam(NULL); 253165948Seric tfd = open(s, O_RDONLY|O_CREAT, 0600); 253265974Seric rval = fchown(tfd, DefUid, DefGid) != 0; 253365948Seric close(tfd); 253465948Seric unlink(s); 253565948Seric setreuid(o_uid, o_euid); 253665948Seric setresgid(o_gid, o_egid, -1); 253765948Seric return rval; 253865948Seric #else 253966088Seric # ifdef _POSIX_CHOWN_RESTRICTED 254066088Seric # if _POSIX_CHOWN_RESTRICTED == -1 254166088Seric return FALSE; 254266088Seric # else 254366088Seric return TRUE; 254466088Seric # endif 254566088Seric # else 254666088Seric # ifdef _PC_CHOWN_RESTRICTED 254768508Seric int rval; 254868508Seric 254968508Seric /* 255068508Seric ** Some systems (e.g., SunOS) seem to have the call and the 255168508Seric ** #define _PC_CHOWN_RESTRICTED, but don't actually implement 255268508Seric ** the call. This heuristic checks for that. 255368508Seric */ 255468508Seric 255568508Seric errno = 0; 255668508Seric rval = fpathconf(fd, _PC_CHOWN_RESTRICTED); 255768508Seric if (errno == 0) 255868508Seric return rval > 0; 255968508Seric # endif 256068508Seric # ifdef BSD 256168508Seric return TRUE; 256268499Seric # else 256365948Seric return FALSE; 256465948Seric # endif 256565948Seric # endif 256665948Seric #endif 256765948Seric } 256865948Seric /* 256968508Seric ** RESETLIMITS -- reset system controlled resource limits 257068508Seric ** 257168508Seric ** This is to avoid denial-of-service attacks 257268508Seric ** 257368508Seric ** Parameters: 257468508Seric ** none 257568508Seric ** 257668508Seric ** Returns: 257768508Seric ** none 257868508Seric */ 257968508Seric 258068508Seric #if HASSETRLIMIT 258168508Seric # include <sys/resource.h> 258268508Seric #endif 258368508Seric 258468508Seric void 258568508Seric resetlimits() 258668508Seric { 258768508Seric #if HASSETRLIMIT 258868508Seric struct rlimit lim; 258968508Seric 259068508Seric lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; 259168508Seric (void) setrlimit(RLIMIT_CPU, &lim); 259268508Seric (void) setrlimit(RLIMIT_FSIZE, &lim); 259368508Seric #else 259468508Seric # if HASULIMIT 259568508Seric (void) ulimit(2, 0x3fffff); 259668508Seric # endif 259768508Seric #endif 259868508Seric } 259968508Seric /* 260064556Seric ** GETCFNAME -- return the name of the .cf file. 260164556Seric ** 260264556Seric ** Some systems (e.g., NeXT) determine this dynamically. 260364556Seric */ 260464556Seric 260564556Seric char * 260664556Seric getcfname() 260764556Seric { 260868842Seric int i; 260968842Seric static char cbuf[200]; 261068842Seric 261164556Seric if (ConfFile != NULL) 261264556Seric return ConfFile; 261365214Seric #ifdef NETINFO 261465214Seric { 261565214Seric extern char *ni_propval(); 261665214Seric char *cflocation; 261765214Seric 261868508Seric cflocation = ni_propval("/locations", NULL, "sendmail", 261968508Seric "sendmail.cf", '\0'); 262065214Seric if (cflocation != NULL) 262165214Seric return cflocation; 262265214Seric } 262365214Seric #endif 262468842Seric 262569396Seric #ifdef TRY_VERSIONED_CF_NAME 262668842Seric /* 262768842Seric ** Try sendmail.8.6.12.cf, then sendmail.8.6.cf, then 262868842Seric ** sendmail.8.cf, and finally sendmail.cf. 262968842Seric ** 263068842Seric ** I suppose it should really try a search path here -- 263168842Seric ** e.g., /etc/sendmail.cf, /etc/mail/sendmail.cf, 263268842Seric ** /usr/lib/sendmail.cf, and so forth. 263368842Seric */ 263468842Seric 263568842Seric strcpy(cbuf, _PATH_SENDMAILCF); 263668842Seric i = strlen(cbuf); 263768842Seric if (strcmp(&cbuf[i - 3], ".cf") == 0) 263868842Seric { 263968842Seric char *p; 264068842Seric extern char Version[]; 264168842Seric 264268842Seric strcpy(&cbuf[i - 2], Version); 264368842Seric p = strchr(&cbuf[i - 2], '/'); 264468842Seric if (p != NULL) 264568842Seric *p = '\0'; 264668842Seric p = &cbuf[strlen(cbuf)]; 264768842Seric do 264868842Seric { 264968842Seric int fd; 265068842Seric 265168842Seric strcpy(p, ".cf"); 265268842Seric if ((fd = open(cbuf, O_RDONLY, 0)) >= 0) 265368842Seric { 265468842Seric close(fd); 265568842Seric return cbuf; 265668842Seric } 265768842Seric *p = '\0'; 265868842Seric } while ((p = strrchr(&cbuf[i - 2], '.')) != NULL); 265968842Seric } 266069396Seric #endif 266164556Seric return _PATH_SENDMAILCF; 266264556Seric } 266364718Seric /* 266464718Seric ** SETVENDOR -- process vendor code from V configuration line 266564718Seric ** 266664718Seric ** Parameters: 266764718Seric ** vendor -- string representation of vendor. 266864718Seric ** 266964718Seric ** Returns: 267064718Seric ** TRUE -- if ok. 267164718Seric ** FALSE -- if vendor code could not be processed. 267264926Seric ** 267364926Seric ** Side Effects: 267464926Seric ** It is reasonable to set mode flags here to tweak 267564926Seric ** processing in other parts of the code if necessary. 267664926Seric ** For example, if you are a vendor that uses $%y to 267764926Seric ** indicate YP lookups, you could enable that here. 267864718Seric */ 267964718Seric 268064718Seric bool 268164718Seric setvendor(vendor) 268264718Seric char *vendor; 268364718Seric { 268464926Seric if (strcasecmp(vendor, "Berkeley") == 0) 268568508Seric { 268668508Seric VendorCode = VENDOR_BERKELEY; 268764926Seric return TRUE; 268868508Seric } 268964926Seric 269064926Seric /* add vendor extensions here */ 269164926Seric 269268508Seric #ifdef SUN_EXTENSIONS 269368508Seric if (strcasecmp(vendor, "Sun") == 0) 269468508Seric { 269568508Seric VendorCode = VENDOR_SUN; 269668508Seric return TRUE; 269768508Seric } 269868508Seric #endif 269968508Seric 270064926Seric return FALSE; 270164718Seric } 270264816Seric /* 270364816Seric ** STRTOL -- convert string to long integer 270464816Seric ** 270564816Seric ** For systems that don't have it in the C library. 270666161Seric ** 270766161Seric ** This is taken verbatim from the 4.4-Lite C library. 270864816Seric */ 270964816Seric 271064816Seric #ifdef NEEDSTRTOL 271164816Seric 271266161Seric #if defined(LIBC_SCCS) && !defined(lint) 271366161Seric static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; 271466161Seric #endif /* LIBC_SCCS and not lint */ 271566161Seric 271666161Seric #include <limits.h> 271766161Seric 271866161Seric /* 271966161Seric * Convert a string to a long integer. 272066161Seric * 272166161Seric * Ignores `locale' stuff. Assumes that the upper and lower case 272266161Seric * alphabets and digits are each contiguous. 272366161Seric */ 272466161Seric 272564816Seric long 272666161Seric strtol(nptr, endptr, base) 272766161Seric const char *nptr; 272866161Seric char **endptr; 272966161Seric register int base; 273064816Seric { 273166161Seric register const char *s = nptr; 273266161Seric register unsigned long acc; 273366161Seric register int c; 273466161Seric register unsigned long cutoff; 273566161Seric register int neg = 0, any, cutlim; 273664816Seric 273766161Seric /* 273866161Seric * Skip white space and pick up leading +/- sign if any. 273966161Seric * If base is 0, allow 0x for hex and 0 for octal, else 274066161Seric * assume decimal; if base is already 16, allow 0x. 274166161Seric */ 274266161Seric do { 274366161Seric c = *s++; 274466161Seric } while (isspace(c)); 274566161Seric if (c == '-') { 274666161Seric neg = 1; 274766161Seric c = *s++; 274866161Seric } else if (c == '+') 274966161Seric c = *s++; 275066161Seric if ((base == 0 || base == 16) && 275166161Seric c == '0' && (*s == 'x' || *s == 'X')) { 275266161Seric c = s[1]; 275366161Seric s += 2; 275466161Seric base = 16; 275566161Seric } 275666161Seric if (base == 0) 275766161Seric base = c == '0' ? 8 : 10; 275864816Seric 275966161Seric /* 276066161Seric * Compute the cutoff value between legal numbers and illegal 276166161Seric * numbers. That is the largest legal value, divided by the 276266161Seric * base. An input number that is greater than this value, if 276366161Seric * followed by a legal input character, is too big. One that 276466161Seric * is equal to this value may be valid or not; the limit 276566161Seric * between valid and invalid numbers is then based on the last 276666161Seric * digit. For instance, if the range for longs is 276766161Seric * [-2147483648..2147483647] and the input base is 10, 276866161Seric * cutoff will be set to 214748364 and cutlim to either 276966161Seric * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 277066161Seric * a value > 214748364, or equal but the next digit is > 7 (or 8), 277166161Seric * the number is too big, and we will return a range error. 277266161Seric * 277366161Seric * Set any if any `digits' consumed; make it negative to indicate 277466161Seric * overflow. 277566161Seric */ 277666161Seric cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; 277766161Seric cutlim = cutoff % (unsigned long)base; 277866161Seric cutoff /= (unsigned long)base; 277966161Seric for (acc = 0, any = 0;; c = *s++) { 278066161Seric if (isdigit(c)) 278166161Seric c -= '0'; 278266161Seric else if (isalpha(c)) 278366161Seric c -= isupper(c) ? 'A' - 10 : 'a' - 10; 278466161Seric else 278566161Seric break; 278666161Seric if (c >= base) 278766161Seric break; 278866161Seric if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) 278966161Seric any = -1; 279066161Seric else { 279166161Seric any = 1; 279266161Seric acc *= base; 279366161Seric acc += c; 279464816Seric } 279564816Seric } 279666161Seric if (any < 0) { 279766161Seric acc = neg ? LONG_MIN : LONG_MAX; 279866161Seric errno = ERANGE; 279966161Seric } else if (neg) 280066161Seric acc = -acc; 280166161Seric if (endptr != 0) 280266161Seric *endptr = (char *)(any ? s - 1 : nptr); 280366161Seric return (acc); 280464816Seric } 280564816Seric 280664816Seric #endif 280764841Seric /* 280868693Seric ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX 280964841Seric ** 281068693Seric ** Some operating systems have wierd problems with the gethostbyXXX 281168693Seric ** routines. For example, Solaris versions at least through 2.3 281268693Seric ** don't properly deliver a canonical h_name field. This tries to 281368693Seric ** work around these problems. 281464841Seric */ 281564841Seric 281664841Seric struct hostent * 281768693Seric sm_gethostbyname(name) 281868707Seric char *name; 281964841Seric { 282068693Seric #if defined(SOLARIS) && SOLARIS < 204 282168693Seric extern int h_errno; 282268693Seric 282368508Seric # if SOLARIS == 203 282464841Seric static struct hostent hp; 282564841Seric static char buf[1000]; 282664841Seric extern struct hostent *_switch_gethostbyname_r(); 282764841Seric 282864841Seric return _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 282964841Seric # else 283065009Seric extern struct hostent *__switch_gethostbyname(); 283165009Seric 283264841Seric return __switch_gethostbyname(name); 283364841Seric # endif 283468693Seric #else 283568693Seric return gethostbyname(name); 283668693Seric #endif 283764841Seric } 283864841Seric 283964841Seric struct hostent * 284068693Seric sm_gethostbyaddr(addr, len, type) 284168707Seric char *addr; 284264841Seric int len; 284364841Seric int type; 284464841Seric { 284568693Seric #if defined(SOLARIS) && SOLARIS < 204 284668693Seric extern int h_errno; 284768693Seric 284868508Seric # if SOLARIS == 203 284964841Seric static struct hostent hp; 285064841Seric static char buf[1000]; 285164841Seric extern struct hostent *_switch_gethostbyaddr_r(); 285264841Seric 285364841Seric return _switch_gethostbyaddr_r(addr, len, type, &hp, buf, sizeof(buf), &h_errno); 285464841Seric # else 285565009Seric extern struct hostent *__switch_gethostbyaddr(); 285665009Seric 285764841Seric return __switch_gethostbyaddr(addr, len, type); 285864841Seric # endif 285968693Seric #else 286068693Seric return gethostbyaddr(addr, len, type); 286168693Seric #endif 286264841Seric } 286368693Seric /* 286468693Seric ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid 286568693Seric */ 286664841Seric 286768693Seric struct passwd * 286868693Seric sm_getpwnam(user) 286968704Seric char *user; 287068693Seric { 287168693Seric return getpwnam(user); 287268693Seric } 287368693Seric 287468693Seric struct passwd * 287568693Seric sm_getpwuid(uid) 287668693Seric uid_t uid; 287768693Seric { 287868693Seric return getpwuid(uid); 287968693Seric } 288065214Seric /* 288165214Seric ** NI_PROPVAL -- netinfo property value lookup routine 288265214Seric ** 288365214Seric ** Parameters: 288468508Seric ** keydir -- the Netinfo directory name in which to search 288568508Seric ** for the key. 288668508Seric ** keyprop -- the name of the property in which to find the 288768508Seric ** property we are interested. Defaults to "name". 288868508Seric ** keyval -- the value for which we are really searching. 288968508Seric ** valprop -- the property name for the value in which we 289068508Seric ** are interested. 289168508Seric ** sepchar -- if non-nil, this can be multiple-valued, and 289268508Seric ** we should return a string separated by this 289368508Seric ** character. 289465214Seric ** 289565214Seric ** Returns: 289665214Seric ** NULL -- if: 289765214Seric ** 1. the directory is not found 289865214Seric ** 2. the property name is not found 289965214Seric ** 3. the property contains multiple values 290065214Seric ** 4. some error occured 290165214Seric ** else -- the location of the config file. 290265214Seric ** 290368508Seric ** Example: 290468508Seric ** To search for an alias value, use: 290568508Seric ** ni_propval("/aliases", "name", aliasname, "members", ',') 290668508Seric ** 290765214Seric ** Notes: 290865214Seric ** Caller should free the return value of ni_proval 290965214Seric */ 291065214Seric 291165214Seric #ifdef NETINFO 291265214Seric 291365214Seric # include <netinfo/ni.h> 291465214Seric 291565214Seric # define LOCAL_NETINFO_DOMAIN "." 291665214Seric # define PARENT_NETINFO_DOMAIN ".." 291765214Seric # define MAX_NI_LEVELS 256 291865214Seric 291965214Seric char * 292068508Seric ni_propval(keydir, keyprop, keyval, valprop, sepchar) 292168508Seric char *keydir; 292268508Seric char *keyprop; 292368508Seric char *keyval; 292468508Seric char *valprop; 292568508Seric char sepchar; 292665214Seric { 292765820Seric char *propval = NULL; 292865214Seric int i; 292968508Seric int j, alen; 293065214Seric void *ni = NULL; 293165214Seric void *lastni = NULL; 293265214Seric ni_status nis; 293365214Seric ni_id nid; 293465214Seric ni_namelist ninl; 293568508Seric register char *p; 293668508Seric char keybuf[1024]; 293765214Seric 293865214Seric /* 293968508Seric ** Create the full key from the two parts. 294068508Seric ** 294168508Seric ** Note that directory can end with, e.g., "name=" to specify 294268508Seric ** an alternate search property. 294368508Seric */ 294468508Seric 294568508Seric i = strlen(keydir) + strlen(keyval) + 2; 294668508Seric if (keyprop != NULL) 294768508Seric i += strlen(keyprop) + 1; 294868508Seric if (i > sizeof keybuf) 294968508Seric return NULL; 295068508Seric strcpy(keybuf, keydir); 295168508Seric strcat(keybuf, "/"); 295268508Seric if (keyprop != NULL) 295368508Seric { 295468508Seric strcat(keybuf, keyprop); 295568508Seric strcat(keybuf, "="); 295668508Seric } 295768508Seric strcat(keybuf, keyval); 295868508Seric 295968508Seric /* 296065214Seric ** If the passed directory and property name are found 296165214Seric ** in one of netinfo domains we need to search (starting 296265214Seric ** from the local domain moving all the way back to the 296365214Seric ** root domain) set propval to the property's value 296465214Seric ** and return it. 296565214Seric */ 296665214Seric 296765214Seric for (i = 0; i < MAX_NI_LEVELS; ++i) 296865214Seric { 296965214Seric if (i == 0) 297065214Seric { 297165214Seric nis = ni_open(NULL, LOCAL_NETINFO_DOMAIN, &ni); 297265214Seric } 297365214Seric else 297465214Seric { 297565214Seric if (lastni != NULL) 297665214Seric ni_free(lastni); 297765214Seric lastni = ni; 297865214Seric nis = ni_open(lastni, PARENT_NETINFO_DOMAIN, &ni); 297965214Seric } 298065214Seric 298165214Seric /* 298265214Seric ** Don't bother if we didn't get a handle on a 298365214Seric ** proper domain. This is not necessarily an error. 298465214Seric ** We would get a positive ni_status if, for instance 298565214Seric ** we never found the directory or property and tried 298665214Seric ** to open the parent of the root domain! 298765214Seric */ 298865214Seric 298965214Seric if (nis != 0) 299065214Seric break; 299165214Seric 299265214Seric /* 299365214Seric ** Find the path to the server information. 299465214Seric */ 299565214Seric 299668508Seric if (ni_pathsearch(ni, &nid, keybuf) != 0) 299765214Seric continue; 299865214Seric 299965214Seric /* 300068508Seric ** Find associated value information. 300165214Seric */ 300265214Seric 300368508Seric if (ni_lookupprop(ni, &nid, valprop, &ninl) != 0) 300465214Seric continue; 300565214Seric 300665214Seric /* 300768508Seric ** See if we have an acceptable number of values. 300865214Seric */ 300965214Seric 301068508Seric if (ninl.ni_namelist_len <= 0) 301168508Seric continue; 301268508Seric 301368508Seric if (sepchar == '\0' && ninl.ni_namelist_len > 1) 301465214Seric { 301568508Seric ni_namelist_free(&ninl); 301668508Seric continue; 301765214Seric } 301868508Seric 301968508Seric /* 302068508Seric ** Calculate number of bytes needed and build result 302168508Seric */ 302268508Seric 302368508Seric alen = 1; 302468508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 302568508Seric alen += strlen(ninl.ni_namelist_val[j]) + 1; 302668508Seric propval = p = xalloc(alen); 302768508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 302868508Seric { 302968508Seric strcpy(p, ninl.ni_namelist_val[j]); 303068508Seric p += strlen(p); 303168508Seric *p++ = sepchar; 303268508Seric } 303368508Seric *--p = '\0'; 303468508Seric 303568508Seric ni_namelist_free(&ninl); 303665214Seric } 303765214Seric 303865214Seric /* 303965214Seric ** Clean up. 304065214Seric */ 304165214Seric 304265214Seric if (ni != NULL) 304365214Seric ni_free(ni); 304465214Seric if (lastni != NULL && ni != lastni) 304565214Seric ni_free(lastni); 304665214Seric 304765214Seric return propval; 304865214Seric } 304965214Seric 305065214Seric #endif /* NETINFO */ 305165504Seric /* 305265504Seric ** HARD_SYSLOG -- call syslog repeatedly until it works 305365504Seric ** 305465504Seric ** Needed on HP-UX, which apparently doesn't guarantee that 305565504Seric ** syslog succeeds during interrupt handlers. 305665504Seric */ 305765504Seric 305865504Seric #ifdef __hpux 305965504Seric 306065504Seric # define MAXSYSLOGTRIES 100 306165504Seric # undef syslog 306265504Seric 306365504Seric # ifdef __STDC__ 306465504Seric hard_syslog(int pri, char *msg, ...) 306565504Seric # else 306665504Seric hard_syslog(pri, msg, va_alist) 306765504Seric int pri; 306865504Seric char *msg; 306965504Seric va_dcl 307065504Seric # endif 307165504Seric { 307265504Seric int i; 307365504Seric char buf[SYSLOG_BUFSIZE * 2]; 307465504Seric VA_LOCAL_DECL; 307565504Seric 307665504Seric VA_START(msg); 307765504Seric vsprintf(buf, msg, ap); 307865504Seric VA_END; 307965504Seric 308065504Seric for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, "%s", buf) < 0; ) 308165504Seric continue; 308265504Seric } 308365504Seric 308465504Seric #endif 308568696Seric /* 308668696Seric ** LOCAL_HOSTNAME_LENGTH 308768696Seric ** 308868696Seric ** This is required to get sendmail to compile against BIND 4.9.x 308968696Seric ** on Ultrix. 309068696Seric */ 309168696Seric 309268696Seric #if defined(ultrix) && NAMED_BIND 309368696Seric 309468696Seric # include <resolv.h> 309568696Seric # if __RES >= 19931104 309668696Seric 309768696Seric int 309868696Seric local_hostname_length(hostname) 309968696Seric char *hostname; 310068696Seric { 310168696Seric int len_host, len_domain; 310268696Seric 310368696Seric if (!*_res.defdname) 310468696Seric res_init(); 310568696Seric len_host = strlen(hostname); 310668696Seric len_domain = strlen(_res.defdname); 310768696Seric if (len_host > len_domain && 310868696Seric (strcasecmp(hostname + len_host - len_domain,_res.defdname) == 0) && 310968696Seric hostname[len_host - len_domain - 1] == '.') 311068696Seric return len_host - len_domain - 1; 311168696Seric else 311268696Seric return 0; 311368696Seric } 311468696Seric 311568696Seric # endif 311668696Seric #endif 311768741Seric /* 311868741Seric ** Compile-Time options 311968741Seric */ 312068741Seric 312168741Seric char *CompileOptions[] = 312268741Seric { 312368741Seric #if HESIOD 312468741Seric "HESIOD", 312568741Seric #endif 312668741Seric #if LOG 312768741Seric "LOG", 312868741Seric #endif 312968741Seric #if MATCHGECOS 313068741Seric "MATCHGECOS", 313168741Seric #endif 313268741Seric #if NAMED_BIND 313368741Seric "NAMED_BIND", 313468741Seric #endif 313568741Seric #if NDBM 313668741Seric "NDBM", 313768741Seric #endif 313868741Seric #if NETINET 313968741Seric "NETINET", 314068741Seric #endif 314168741Seric #if NETINFO 314268741Seric "NETINFO", 314368741Seric #endif 314468741Seric #if NETISO 314568741Seric "NETISO", 314668741Seric #endif 314768741Seric #if NETNS 314868741Seric "NETNS", 314968741Seric #endif 315068741Seric #if NETUNIX 315168741Seric "NETUNIX", 315268741Seric #endif 315368741Seric #if NETX25 315468741Seric "NETX25", 315568741Seric #endif 315668741Seric #if NEWDB 315768741Seric "NEWDB", 315868741Seric #endif 315968741Seric #if NIS 316068741Seric "NIS", 316168741Seric #endif 316268741Seric #if SCANF 316368741Seric "SCANF", 316468741Seric #endif 316568741Seric #if SUID_ROOT_FILES_OK 316668741Seric "SUID_ROOT_FILES_OK", 316768741Seric #endif 316868741Seric #if USERDB 316968741Seric "USERDB", 317068741Seric #endif 317168741Seric #if XDEBUG 317268741Seric "XDEBUG", 317368741Seric #endif 317468741Seric #if XLA 317568741Seric "XLA", 317668741Seric #endif 317768741Seric NULL 317868741Seric }; 3179