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*68880Seric static char sccsid[] = "@(#)conf.c 8.156 (Berkeley) 04/25/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"; 19440973Sbostic setdefuser(); 19553654Seric setupmaps(); 19657402Seric setupmailers(); 19724943Seric } 198294Seric 19940973Sbostic 2004326Seric /* 20140973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 20240973Sbostic */ 20340973Sbostic 20468508Seric void 20540973Sbostic setdefuser() 20640973Sbostic { 20740973Sbostic struct passwd *defpwent; 20857386Seric static char defuserbuf[40]; 20940973Sbostic 21057386Seric DefUser = defuserbuf; 21168693Seric if ((defpwent = sm_getpwuid(DefUid)) != NULL) 21257386Seric strcpy(defuserbuf, defpwent->pw_name); 21340973Sbostic else 21457386Seric strcpy(defuserbuf, "nobody"); 21540973Sbostic } 21653654Seric /* 21756836Seric ** HOST_MAP_INIT -- initialize host class structures 21856836Seric */ 21956836Seric 22068508Seric bool host_map_init __P((MAP *map, char *args)); 22168508Seric 22256836Seric bool 22360219Seric host_map_init(map, args) 22456836Seric MAP *map; 22556836Seric char *args; 22656836Seric { 22756836Seric register char *p = args; 22856836Seric 22956836Seric for (;;) 23056836Seric { 23158050Seric while (isascii(*p) && isspace(*p)) 23256836Seric p++; 23356836Seric if (*p != '-') 23456836Seric break; 23556836Seric switch (*++p) 23656836Seric { 23756836Seric case 'a': 23856836Seric map->map_app = ++p; 23956836Seric break; 24056836Seric } 24158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 24256836Seric p++; 24356836Seric if (*p != '\0') 24456836Seric *p++ = '\0'; 24556836Seric } 24656836Seric if (map->map_app != NULL) 24756836Seric map->map_app = newstr(map->map_app); 24856836Seric return TRUE; 24956836Seric } 25057402Seric /* 25157402Seric ** SETUPMAILERS -- initialize default mailers 25257402Seric */ 25356836Seric 25468508Seric void 25557402Seric setupmailers() 25657402Seric { 25757402Seric char buf[100]; 25868508Seric extern void makemailer(); 25957402Seric 26068868Seric strcpy(buf, "prog, P=/bin/sh, F=lsoD, T=X-Unix, A=sh -c $u"); 26157403Seric makemailer(buf); 26257403Seric 263*68880Seric strcpy(buf, "*file*, P=[FILE], F=lsDFMPEou, T=X-Unix, A=FILE"); 26457402Seric makemailer(buf); 26557402Seric 26657402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 26757402Seric makemailer(buf); 26857402Seric } 26956836Seric /* 27060207Seric ** SETUPMAPS -- set up map classes 27160207Seric */ 27260207Seric 27360207Seric #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \ 27460207Seric { \ 27560207Seric extern bool parse __P((MAP *, char *)); \ 27660207Seric extern bool open __P((MAP *, int)); \ 27760207Seric extern void close __P((MAP *)); \ 27860207Seric extern char *lookup __P((MAP *, char *, char **, int *)); \ 27960207Seric extern void store __P((MAP *, char *, char *)); \ 28060207Seric s = stab(name, ST_MAPCLASS, ST_ENTER); \ 28160207Seric s->s_mapclass.map_cname = name; \ 28260207Seric s->s_mapclass.map_ext = ext; \ 28360207Seric s->s_mapclass.map_cflags = flags; \ 28460207Seric s->s_mapclass.map_parse = parse; \ 28560207Seric s->s_mapclass.map_open = open; \ 28660207Seric s->s_mapclass.map_close = close; \ 28760207Seric s->s_mapclass.map_lookup = lookup; \ 28860207Seric s->s_mapclass.map_store = store; \ 28960207Seric } 29060207Seric 29168508Seric void 29260207Seric setupmaps() 29360207Seric { 29460207Seric register STAB *s; 29560207Seric 29660207Seric #ifdef NEWDB 29760207Seric MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 29860207Seric map_parseargs, hash_map_open, db_map_close, 29960207Seric db_map_lookup, db_map_store); 30068508Seric 30160207Seric MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 30260207Seric map_parseargs, bt_map_open, db_map_close, 30360207Seric db_map_lookup, db_map_store); 30460207Seric #endif 30560207Seric 30660207Seric #ifdef NDBM 30760207Seric MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE, 30860207Seric map_parseargs, ndbm_map_open, ndbm_map_close, 30960207Seric ndbm_map_lookup, ndbm_map_store); 31060207Seric #endif 31160207Seric 31260207Seric #ifdef NIS 31360207Seric MAPDEF("nis", NULL, MCF_ALIASOK, 31468508Seric map_parseargs, nis_map_open, null_map_close, 31568508Seric nis_map_lookup, null_map_store); 31660207Seric #endif 31760207Seric 31868508Seric #ifdef NISPLUS 31968508Seric MAPDEF("nisplus", NULL, MCF_ALIASOK, 32068508Seric map_parseargs, nisplus_map_open, null_map_close, 32168508Seric nisplus_map_lookup, null_map_store); 32268508Seric #endif 32368508Seric 32468508Seric #ifdef HESIOD 32568508Seric MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY, 32668508Seric map_parseargs, null_map_open, null_map_close, 32768508Seric hes_map_lookup, null_map_store); 32868508Seric #endif 32968508Seric 33068508Seric #ifdef NETINFO 33168508Seric MAPDEF("netinfo", NULL, MCF_ALIASOK, 33268508Seric map_parseargs, ni_map_open, null_map_close, 33368508Seric ni_map_lookup, null_map_store); 33468508Seric #endif 33568508Seric 33668508Seric #if 0 33768508Seric MAPDEF("dns", NULL, 0, 33868508Seric dns_map_init, null_map_open, null_map_close, 33968508Seric dns_map_lookup, null_map_store); 34068508Seric #endif 34168508Seric 34268508Seric #if NAMED_BIND 34368508Seric /* best MX DNS lookup */ 34468508Seric MAPDEF("bestmx", NULL, MCF_OPTFILE, 34568508Seric map_parseargs, null_map_open, null_map_close, 34668508Seric bestmx_map_lookup, null_map_store); 34768508Seric #endif 34868508Seric 34968508Seric MAPDEF("host", NULL, 0, 35068508Seric host_map_init, null_map_open, null_map_close, 35168508Seric host_map_lookup, null_map_store); 35268508Seric 35368508Seric MAPDEF("text", NULL, MCF_ALIASOK, 35468508Seric map_parseargs, text_map_open, null_map_close, 35568508Seric text_map_lookup, null_map_store); 35668508Seric 35760207Seric MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY, 35868508Seric map_parseargs, stab_map_open, null_map_close, 35960207Seric stab_map_lookup, stab_map_store); 36060207Seric 36160207Seric MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE, 36260207Seric map_parseargs, impl_map_open, impl_map_close, 36360207Seric impl_map_lookup, impl_map_store); 36460207Seric 36568508Seric /* access to system passwd file */ 36668508Seric MAPDEF("user", NULL, MCF_OPTFILE, 36768508Seric map_parseargs, user_map_open, null_map_close, 36868508Seric user_map_lookup, null_map_store); 36960207Seric 37060207Seric /* dequote map */ 37160207Seric MAPDEF("dequote", NULL, 0, 37260207Seric dequote_init, null_map_open, null_map_close, 37360207Seric dequote_map, null_map_store); 37460207Seric 37568521Seric #ifdef USERDB 37660207Seric /* user database */ 37768521Seric MAPDEF("userdb", ".db", 0, 37868521Seric map_parseargs, null_map_open, null_map_close, 37960207Seric udb_map_lookup, null_map_store); 38060207Seric #endif 38168508Seric 38268508Seric /* sequenced maps */ 38368508Seric MAPDEF("sequence", NULL, MCF_ALIASOK, 38468508Seric seq_map_parse, null_map_open, null_map_close, 38568508Seric seq_map_lookup, seq_map_store); 38668508Seric 38768508Seric /* switched interface to sequenced maps */ 38868508Seric MAPDEF("switch", NULL, MCF_ALIASOK, 38968508Seric map_parseargs, switch_map_open, null_map_close, 39068508Seric seq_map_lookup, seq_map_store); 39160207Seric } 39260207Seric 39360207Seric #undef MAPDEF 39460207Seric /* 39568508Seric ** INITHOSTMAPS -- initial host-dependent maps 39668508Seric ** 39768508Seric ** This should act as an interface to any local service switch 39868508Seric ** provided by the host operating system. 39968508Seric ** 40068508Seric ** Parameters: 40168508Seric ** none 40268508Seric ** 40368508Seric ** Returns: 40468508Seric ** none 40568508Seric ** 40668508Seric ** Side Effects: 40768508Seric ** Should define maps "host" and "users" as necessary 40868508Seric ** for this OS. If they are not defined, they will get 40968508Seric ** a default value later. It should check to make sure 41068508Seric ** they are not defined first, since it's possible that 41168508Seric ** the config file has provided an override. 41268508Seric */ 41368508Seric 41468508Seric void 41568508Seric inithostmaps() 41668508Seric { 41768508Seric register int i; 41868508Seric int nmaps; 41968508Seric char *maptype[MAXMAPSTACK]; 42068508Seric short mapreturn[MAXMAPACTIONS]; 42168508Seric char buf[MAXLINE]; 42268508Seric 42368508Seric /* 42468508Seric ** Set up default hosts maps. 42568508Seric */ 42668508Seric 42768508Seric #if 0 42868508Seric nmaps = switch_map_find("hosts", maptype, mapreturn); 42968508Seric for (i = 0; i < nmaps; i++) 43068508Seric { 43168508Seric if (strcmp(maptype[i], "files") == 0 && 43268508Seric stab("hosts.files", ST_MAP, ST_FIND) == NULL) 43368508Seric { 43468508Seric strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts"); 43568508Seric makemapentry(buf); 43668508Seric } 43768508Seric #if NAMED_BIND 43868508Seric else if (strcmp(maptype[i], "dns") == 0 && 43968508Seric stab("hosts.dns", ST_MAP, ST_FIND) == NULL) 44068508Seric { 44168508Seric strcpy(buf, "hosts.dns dns A"); 44268508Seric makemapentry(buf); 44368508Seric } 44468508Seric #endif 44568508Seric #ifdef NISPLUS 44668508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 44768508Seric stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL) 44868508Seric { 44968508Seric strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir"); 45068508Seric makemapentry(buf); 45168508Seric } 45268508Seric #endif 45368508Seric #ifdef NIS 45468508Seric else if (strcmp(maptype[i], "nis") == 0 && 45568508Seric stab("hosts.nis", ST_MAP, ST_FIND) == NULL) 45668508Seric { 45768508Seric strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname"); 45868508Seric makemapentry(buf); 45968508Seric } 46068508Seric #endif 46168508Seric } 46268508Seric #endif 46368508Seric 46468508Seric /* 46568508Seric ** Make sure we have a host map. 46668508Seric */ 46768508Seric 46868508Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 46968508Seric { 47068508Seric /* user didn't initialize: set up host map */ 47168508Seric strcpy(buf, "host host"); 47268508Seric #if NAMED_BIND 47368508Seric if (ConfigLevel >= 2) 47468508Seric strcat(buf, " -a."); 47568508Seric #endif 47668508Seric makemapentry(buf); 47768508Seric } 47868508Seric 47968508Seric /* 48068508Seric ** Set up default aliases maps 48168508Seric */ 48268508Seric 48368508Seric nmaps = switch_map_find("aliases", maptype, mapreturn); 48468508Seric for (i = 0; i < nmaps; i++) 48568508Seric { 48668508Seric if (strcmp(maptype[i], "files") == 0 && 48768508Seric stab("aliases.files", ST_MAP, ST_FIND) == NULL) 48868508Seric { 48968508Seric strcpy(buf, "aliases.files implicit /etc/aliases"); 49068508Seric makemapentry(buf); 49168508Seric } 49268508Seric #ifdef NISPLUS 49368508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 49468508Seric stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL) 49568508Seric { 49668508Seric strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir"); 49768508Seric makemapentry(buf); 49868508Seric } 49968508Seric #endif 50068508Seric #ifdef NIS 50168508Seric else if (strcmp(maptype[i], "nis") == 0 && 50268508Seric stab("aliases.nis", ST_MAP, ST_FIND) == NULL) 50368508Seric { 50468508Seric strcpy(buf, "aliases.nis nis -d mail.aliases"); 50568508Seric makemapentry(buf); 50668508Seric } 50768508Seric #endif 50868508Seric } 50968508Seric if (stab("aliases", ST_MAP, ST_FIND) == NULL) 51068508Seric { 51168508Seric strcpy(buf, "aliases switch aliases"); 51268508Seric makemapentry(buf); 51368508Seric } 51468508Seric strcpy(buf, "switch:aliases"); 51568508Seric setalias(buf); 51668508Seric 51768508Seric #if 0 /* "user" map class is a better choice */ 51868508Seric /* 51968508Seric ** Set up default users maps. 52068508Seric */ 52168508Seric 52268508Seric nmaps = switch_map_find("passwd", maptype, mapreturn); 52368508Seric for (i = 0; i < nmaps; i++) 52468508Seric { 52568508Seric if (strcmp(maptype[i], "files") == 0 && 52668508Seric stab("users.files", ST_MAP, ST_FIND) == NULL) 52768508Seric { 52868508Seric strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd"); 52968508Seric makemapentry(buf); 53068508Seric } 53168508Seric #ifdef NISPLUS 53268508Seric else if (strcmp(maptype[i], "nisplus") == 0 && 53368508Seric stab("users.nisplus", ST_MAP, ST_FIND) == NULL) 53468508Seric { 53568508Seric strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir"); 53668508Seric makemapentry(buf); 53768508Seric } 53868508Seric #endif 53968508Seric #ifdef NIS 54068508Seric else if (strcmp(maptype[i], "nis") == 0 && 54168508Seric stab("users.nis", ST_MAP, ST_FIND) == NULL) 54268508Seric { 54368508Seric strcpy(buf, "users.nis nis -m -d passwd.byname"); 54468508Seric makemapentry(buf); 54568508Seric } 54668508Seric #endif 54768508Seric #ifdef HESIOD 54868508Seric else if (strcmp(maptype[i], "hesiod") == 0) && 54968508Seric stab("users.hesiod", ST_MAP, ST_FIND) == NULL) 55068508Seric { 55168508Seric strcpy(buf, "users.hesiod hesiod"); 55268508Seric makemapentry(buf); 55368508Seric } 55468508Seric #endif 55568508Seric } 55668508Seric if (stab("users", ST_MAP, ST_FIND) == NULL) 55768508Seric { 55868508Seric strcpy(buf, "users switch -m passwd"); 55968508Seric makemapentry(buf); 56068508Seric } 56168508Seric #endif 56268508Seric } 56368508Seric /* 56468508Seric ** SWITCH_MAP_FIND -- find the list of types associated with a map 56568508Seric ** 56668508Seric ** This is the system-dependent interface to the service switch. 56768508Seric ** 56868508Seric ** Parameters: 56968508Seric ** service -- the name of the service of interest. 57068508Seric ** maptype -- an out-array of strings containing the types 57168508Seric ** of access to use for this service. There can 57268508Seric ** be at most MAXMAPSTACK types for a single service. 57368508Seric ** mapreturn -- an out-array of return information bitmaps 57468508Seric ** for the map. 57568508Seric ** 57668508Seric ** Returns: 57768508Seric ** The number of map types filled in, or -1 for failure. 57868508Seric */ 57968508Seric 58068508Seric #ifdef SOLARIS 58168508Seric # include <nsswitch.h> 58268508Seric #endif 58368508Seric 58468508Seric #if defined(ultrix) || defined(__osf__) 58568508Seric # include <sys/svcinfo.h> 58668508Seric #endif 58768508Seric 58868508Seric int 58968508Seric switch_map_find(service, maptype, mapreturn) 59068508Seric char *service; 59168508Seric char *maptype[MAXMAPSTACK]; 59268508Seric short mapreturn[MAXMAPACTIONS]; 59368508Seric { 59468508Seric register FILE *fp; 59568508Seric int svcno; 59668508Seric static char buf[MAXLINE]; 59768508Seric 59868508Seric #ifdef SOLARIS 59968508Seric struct __nsw_switchconfig *nsw_conf; 60068508Seric enum __nsw_parse_err pserr; 60168508Seric struct __nsw_lookup *lk; 60268508Seric int nsw_rc; 60368508Seric static struct __nsw_lookup lkp0 = 60468508Seric { "files", {1, 0, 0, 0}, NULL, NULL }; 60568508Seric static struct __nsw_switchconfig lkp_default = 60668508Seric { 0, "sendmail", 3, &lkp0 }; 60768508Seric 60868508Seric if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL) 60968508Seric lk = lkp_default.lookups; 61068508Seric else 61168508Seric lk = nsw_conf->lookups; 61268508Seric svcno = 0; 61368508Seric while (lk != NULL) 61468508Seric { 61568508Seric maptype[svcno] = lk->service_name; 61668508Seric if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN) 61768508Seric mapreturn[MA_NOTFOUND] |= 1 << svcno; 61868508Seric if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN) 61968508Seric mapreturn[MA_TRYAGAIN] |= 1 << svcno; 62068508Seric if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN) 62168508Seric mapreturn[MA_TRYAGAIN] |= 1 << svcno; 62268508Seric svcno++; 62368508Seric lk = lk->next; 62468508Seric } 62568508Seric return svcno; 62668508Seric #endif 62768508Seric 62868508Seric #if defined(ultrix) || defined(__osf__) 62968508Seric struct svcinfo *svcinfo; 63068508Seric int svc; 63168508Seric 63268508Seric svcinfo = getsvc(); 63368508Seric if (svcinfo == NULL) 63468508Seric goto punt; 63568508Seric if (strcmp(service, "hosts") == 0) 63668508Seric svc = SVC_HOSTS; 63768508Seric else if (strcmp(service, "aliases") == 0) 63868508Seric svc = SVC_ALIASES; 63968508Seric else if (strcmp(service, "passwd") == 0) 64068508Seric svc = SVC_PASSWD; 64168508Seric else 64268508Seric return -1; 64368508Seric for (svcno = 0; svcno < SVC_PATHSIZE; svcno++) 64468508Seric { 64568508Seric switch (svcinfo->svcpath[svc][svcno]) 64668508Seric { 64768508Seric case SVC_LOCAL: 64868508Seric maptype[svcno] = "files"; 64968508Seric break; 65068508Seric 65168508Seric case SVC_YP: 65268508Seric maptype[svcno] = "nis"; 65368508Seric break; 65468508Seric 65568508Seric case SVC_BIND: 65668508Seric maptype[svcno] = "dns"; 65768508Seric break; 65868508Seric 65968508Seric #ifdef SVC_HESIOD 66068508Seric case SVC_HESIOD: 66168508Seric maptype[svcno] = "hesiod"; 66268508Seric break; 66368508Seric #endif 66468508Seric 66568508Seric case SVC_LAST: 66668508Seric return svcno; 66768508Seric } 66868508Seric } 66968508Seric return svcno; 67068508Seric #endif 67168508Seric 67268508Seric #if !defined(SOLARIS) && !defined(ultrix) && !defined(__osf__) 67368508Seric /* 67468508Seric ** Fall-back mechanism. 67568508Seric */ 67668508Seric 67768508Seric svcno = 0; 67868508Seric fp = fopen(ServiceSwitchFile, "r"); 67968508Seric if (fp != NULL) 68068508Seric { 68168508Seric while (fgets(buf, sizeof buf, fp) != NULL) 68268508Seric { 68368508Seric register char *p; 68468508Seric 68568508Seric p = strpbrk(buf, "#\n"); 68668508Seric if (p != NULL) 68768508Seric *p = '\0'; 68868508Seric p = strpbrk(buf, " \t"); 68968508Seric if (p != NULL) 69068508Seric *p++ = '\0'; 69168508Seric if (strcmp(buf, service) != 0) 69268508Seric continue; 69368508Seric 69468508Seric /* got the right service -- extract data */ 69568508Seric do 69668508Seric { 69768508Seric while (isspace(*p)) 69868508Seric p++; 69968508Seric if (*p == '\0') 70068508Seric break; 70168508Seric maptype[svcno++] = p; 70268508Seric p = strpbrk(p, " \t"); 70368508Seric if (p != NULL) 70468508Seric *p++ = '\0'; 70568508Seric } while (p != NULL); 70668508Seric break; 70768508Seric } 70868508Seric fclose(fp); 70968508Seric return svcno; 71068508Seric } 71168508Seric #endif 71268508Seric 71368508Seric /* if the service file doesn't work, use an absolute fallback */ 71468508Seric punt: 71568508Seric if (strcmp(service, "aliases") == 0) 71668508Seric { 71768628Seric maptype[svcno++] = "files"; 71868628Seric #ifdef AUTO_NIS_ALIASES 71968628Seric # ifdef NISPLUS 72068628Seric maptype[svcno++] = "nisplus"; 72168628Seric # endif 72268628Seric # ifdef NIS 72368628Seric maptype[svcno++] = "nis"; 72468628Seric # endif 72568628Seric #endif 72668628Seric return svcno; 72768508Seric } 72868508Seric if (strcmp(service, "hosts") == 0) 72968508Seric { 73068508Seric # if NAMED_BIND 73168508Seric maptype[svcno++] = "dns"; 73268508Seric # else 73368508Seric # if defined(sun) && !defined(BSD) && !defined(SOLARIS) 73468508Seric /* SunOS */ 73568508Seric maptype[svcno++] = "nis"; 73668508Seric # endif 73768508Seric # endif 73868508Seric maptype[svcno++] = "files"; 73968508Seric return svcno; 74068508Seric } 74168508Seric return -1; 74268508Seric } 74368508Seric /* 7449369Seric ** USERNAME -- return the user id of the logged in user. 7459369Seric ** 7469369Seric ** Parameters: 7479369Seric ** none. 7489369Seric ** 7499369Seric ** Returns: 7509369Seric ** The login name of the logged in user. 7519369Seric ** 7529369Seric ** Side Effects: 7539369Seric ** none. 7549369Seric ** 7559369Seric ** Notes: 7569369Seric ** The return value is statically allocated. 7579369Seric */ 7589369Seric 7599369Seric char * 7609369Seric username() 7619369Seric { 76217469Seric static char *myname = NULL; 7639369Seric extern char *getlogin(); 76419904Smiriam register struct passwd *pw; 7659369Seric 76617469Seric /* cache the result */ 76717469Seric if (myname == NULL) 76817469Seric { 76917469Seric myname = getlogin(); 77017469Seric if (myname == NULL || myname[0] == '\0') 77117469Seric { 77268693Seric pw = sm_getpwuid(RealUid); 77317469Seric if (pw != NULL) 77440993Sbostic myname = newstr(pw->pw_name); 77517469Seric } 77619904Smiriam else 77719904Smiriam { 77863787Seric uid_t uid = RealUid; 77919873Smiriam 78040993Sbostic myname = newstr(myname); 78168693Seric if ((pw = sm_getpwnam(myname)) == NULL || 78258736Seric (uid != 0 && uid != pw->pw_uid)) 78319904Smiriam { 78468693Seric pw = sm_getpwuid(uid); 78524945Seric if (pw != NULL) 78640993Sbostic myname = newstr(pw->pw_name); 78719873Smiriam } 78819873Smiriam } 78917469Seric if (myname == NULL || myname[0] == '\0') 79017469Seric { 79158151Seric syserr("554 Who are you?"); 79217469Seric myname = "postmaster"; 79317469Seric } 79417469Seric } 79517469Seric 79617469Seric return (myname); 7979369Seric } 7989369Seric /* 7994190Seric ** TTYPATH -- Get the path of the user's tty 800294Seric ** 801294Seric ** Returns the pathname of the user's tty. Returns NULL if 802294Seric ** the user is not logged in or if s/he has write permission 803294Seric ** denied. 804294Seric ** 805294Seric ** Parameters: 806294Seric ** none 807294Seric ** 808294Seric ** Returns: 809294Seric ** pathname of the user's tty. 810294Seric ** NULL if not logged in or write permission denied. 811294Seric ** 812294Seric ** Side Effects: 813294Seric ** none. 814294Seric ** 815294Seric ** WARNING: 816294Seric ** Return value is in a local buffer. 817294Seric ** 818294Seric ** Called By: 819294Seric ** savemail 820294Seric */ 821294Seric 822294Seric char * 823294Seric ttypath() 824294Seric { 825294Seric struct stat stbuf; 826294Seric register char *pathn; 827294Seric extern char *ttyname(); 8284081Seric extern char *getlogin(); 829294Seric 830294Seric /* compute the pathname of the controlling tty */ 8319369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 8329369Seric (pathn = ttyname(0)) == NULL) 833294Seric { 834294Seric errno = 0; 835294Seric return (NULL); 836294Seric } 837294Seric 838294Seric /* see if we have write permission */ 8392967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 840294Seric { 841294Seric errno = 0; 842294Seric return (NULL); 843294Seric } 844294Seric 845294Seric /* see if the user is logged in */ 846294Seric if (getlogin() == NULL) 847294Seric return (NULL); 848294Seric 849294Seric /* looks good */ 850294Seric return (pathn); 851294Seric } 8522967Seric /* 8532967Seric ** CHECKCOMPAT -- check for From and To person compatible. 8542967Seric ** 8552967Seric ** This routine can be supplied on a per-installation basis 8562967Seric ** to determine whether a person is allowed to send a message. 8572967Seric ** This allows restriction of certain types of internet 8582967Seric ** forwarding or registration of users. 8592967Seric ** 8602967Seric ** If the hosts are found to be incompatible, an error 86168857Seric ** message should be given using "usrerr" and an EX_ code 86268857Seric ** should be returned. You can also set to->q_status to 86368857Seric ** a DSN-style status code. 8642967Seric ** 86568559Seric ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the 86668559Seric ** body during the return-to-sender function; this should be done 86768559Seric ** on huge messages. This bit may already be set by the ESMTP 86868559Seric ** protocol. 8694288Seric ** 8702967Seric ** Parameters: 8712967Seric ** to -- the person being sent to. 8722967Seric ** 8732967Seric ** Returns: 87457459Seric ** an exit status 8752967Seric ** 8762967Seric ** Side Effects: 8772967Seric ** none (unless you include the usrerr stuff) 8782967Seric */ 8792967Seric 88068508Seric int 88155012Seric checkcompat(to, e) 8822967Seric register ADDRESS *to; 88355012Seric register ENVELOPE *e; 8842967Seric { 88512133Seric # ifdef lint 88612133Seric if (to == NULL) 88712133Seric to++; 88863834Seric # endif /* lint */ 88964402Seric 89064402Seric if (tTd(49, 1)) 89164402Seric printf("checkcompat(to=%s, from=%s)\n", 89264402Seric to->q_paddr, e->e_from.q_paddr); 89364402Seric 89410698Seric # ifdef EXAMPLE_CODE 89510698Seric /* this code is intended as an example only */ 8964437Seric register STAB *s; 8974437Seric 8984437Seric s = stab("arpa", ST_MAILER, ST_FIND); 89968508Seric if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 && 9009369Seric to->q_mailer == s->s_mailer) 9014437Seric { 90258151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 90368559Seric /* e->e_flags |= EF_NO_BODY_RETN; to supress body on return */ 90468857Seric to->q_status = "5.7.1"; 90557459Seric return (EX_UNAVAILABLE); 9064437Seric } 90756795Seric # endif /* EXAMPLE_CODE */ 90857459Seric return (EX_OK); 9092967Seric } 9109369Seric /* 91164035Seric ** SETSIGNAL -- set a signal handler 91264035Seric ** 91364035Seric ** This is essentially old BSD "signal(3)". 91464035Seric */ 91564035Seric 91664561Seric sigfunc_t 91764035Seric setsignal(sig, handler) 91864035Seric int sig; 91964561Seric sigfunc_t handler; 92064035Seric { 92164380Seric #if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE) 92264035Seric return signal(sig, handler); 92364035Seric #else 92464035Seric struct sigaction n, o; 92564035Seric 92664035Seric bzero(&n, sizeof n); 92764035Seric n.sa_handler = handler; 92868508Seric # ifdef SA_RESTART 92968508Seric n.sa_flags = SA_RESTART; 93068508Seric # endif 93164035Seric if (sigaction(sig, &n, &o) < 0) 93264035Seric return SIG_ERR; 93364035Seric return o.sa_handler; 93464035Seric #endif 93564035Seric } 93664035Seric /* 9379369Seric ** HOLDSIGS -- arrange to hold all signals 9389369Seric ** 9399369Seric ** Parameters: 9409369Seric ** none. 9419369Seric ** 9429369Seric ** Returns: 9439369Seric ** none. 9449369Seric ** 9459369Seric ** Side Effects: 9469369Seric ** Arranges that signals are held. 9479369Seric */ 9489369Seric 94968508Seric void 9509369Seric holdsigs() 9519369Seric { 9529369Seric } 9539369Seric /* 9549369Seric ** RLSESIGS -- arrange to release all signals 9559369Seric ** 9569369Seric ** This undoes the effect of holdsigs. 9579369Seric ** 9589369Seric ** Parameters: 9599369Seric ** none. 9609369Seric ** 9619369Seric ** Returns: 9629369Seric ** none. 9639369Seric ** 9649369Seric ** Side Effects: 9659369Seric ** Arranges that signals are released. 9669369Seric */ 9679369Seric 96868508Seric void 9699369Seric rlsesigs() 9709369Seric { 9719369Seric } 97214872Seric /* 97364705Seric ** INIT_MD -- do machine dependent initializations 97464705Seric ** 97564705Seric ** Systems that have global modes that should be set should do 97664705Seric ** them here rather than in main. 97764705Seric */ 97864705Seric 97964705Seric #ifdef _AUX_SOURCE 98064705Seric # include <compat.h> 98164705Seric #endif 98264705Seric 98368508Seric void 98464825Seric init_md(argc, argv) 98564825Seric int argc; 98664825Seric char **argv; 98764705Seric { 98864705Seric #ifdef _AUX_SOURCE 98964705Seric setcompat(getcompat() | COMPAT_BSDPROT); 99064705Seric #endif 99168508Seric 99268508Seric #ifdef VENDOR_DEFAULT 99368508Seric VendorCode = VENDOR_DEFAULT; 99468508Seric #else 99568508Seric VendorCode = VENDOR_BERKELEY; 99668508Seric #endif 99764705Seric } 99864705Seric /* 99968508Seric ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations 100068508Seric ** 100168508Seric ** Called once, on startup. 100268508Seric ** 100368508Seric ** Parameters: 100468508Seric ** e -- the global envelope. 100568508Seric ** 100668508Seric ** Returns: 100768508Seric ** none. 100868508Seric ** 100968508Seric ** Side Effects: 101068508Seric ** vendor-dependent. 101168508Seric */ 101268508Seric 101368508Seric void 101468508Seric init_vendor_macros(e) 101568508Seric register ENVELOPE *e; 101668508Seric { 101768508Seric } 101868508Seric /* 101914872Seric ** GETLA -- get the current load average 102014872Seric ** 102114881Seric ** This code stolen from la.c. 102214881Seric ** 102314872Seric ** Parameters: 102414872Seric ** none. 102514872Seric ** 102614872Seric ** Returns: 102714872Seric ** The current load average as an integer. 102814872Seric ** 102914872Seric ** Side Effects: 103014872Seric ** none. 103114872Seric */ 103214872Seric 103351920Seric /* try to guess what style of load average we have */ 103451920Seric #define LA_ZERO 1 /* always return load average as zero */ 103564360Seric #define LA_INT 2 /* read kmem for avenrun; interpret as long */ 103651920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 103751920Seric #define LA_SUBR 4 /* call getloadavg */ 103864295Seric #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */ 103964360Seric #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */ 104066301Seric #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */ 104114872Seric 104263962Seric /* do guesses based on general OS type */ 104351920Seric #ifndef LA_TYPE 104463962Seric # define LA_TYPE LA_ZERO 104551920Seric #endif 104651920Seric 104764360Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) 104851920Seric 104914872Seric #include <nlist.h> 105014872Seric 105168508Seric #ifdef IRIX64 105268508Seric # define nlist nlist64 105368508Seric #endif 105468508Seric 105551920Seric #ifndef LA_AVENRUN 105663962Seric # ifdef SYSTEM5 105763962Seric # define LA_AVENRUN "avenrun" 105863962Seric # else 105963962Seric # define LA_AVENRUN "_avenrun" 106063962Seric # endif 106151920Seric #endif 106251920Seric 106351920Seric /* _PATH_UNIX should be defined in <paths.h> */ 106451920Seric #ifndef _PATH_UNIX 106563962Seric # if defined(SYSTEM5) 106663962Seric # define _PATH_UNIX "/unix" 106763962Seric # else 106863962Seric # define _PATH_UNIX "/vmunix" 106963962Seric # endif 107051920Seric #endif 107151920Seric 107214872Seric struct nlist Nl[] = 107314872Seric { 107451920Seric { LA_AVENRUN }, 107514872Seric #define X_AVENRUN 0 107614872Seric { 0 }, 107714872Seric }; 107814872Seric 107960583Seric #ifndef FSHIFT 108060583Seric # if defined(unixpc) 108160583Seric # define FSHIFT 5 108260583Seric # endif 108357736Seric 108466763Seric # if defined(__alpha) || defined(IRIX) 108560583Seric # define FSHIFT 10 108660583Seric # endif 108768508Seric 108868508Seric # if defined(_AIX3) 108968508Seric # define FSHIFT 16 109068508Seric # endif 109166788Seric #endif 109257977Seric 109366788Seric #ifndef FSHIFT 109466788Seric # define FSHIFT 8 109557736Seric #endif 109660583Seric 109766788Seric #ifndef FSCALE 109866788Seric # define FSCALE (1 << FSHIFT) 109951920Seric #endif 110040930Srick 110114872Seric getla() 110214872Seric { 110314872Seric static int kmem = -1; 110451920Seric #if LA_TYPE == LA_INT 110524943Seric long avenrun[3]; 110651920Seric #else 110764360Seric # if LA_TYPE == LA_SHORT 110864360Seric short avenrun[3]; 110964360Seric # else 111051920Seric double avenrun[3]; 111164360Seric # endif 111251920Seric #endif 111325615Seric extern off_t lseek(); 111457736Seric extern int errno; 111514872Seric 111614872Seric if (kmem < 0) 111714872Seric { 111824945Seric kmem = open("/dev/kmem", 0, 0); 111914872Seric if (kmem < 0) 112057736Seric { 112157736Seric if (tTd(3, 1)) 112257736Seric printf("getla: open(/dev/kmem): %s\n", 112357736Seric errstring(errno)); 112414872Seric return (-1); 112557736Seric } 112651920Seric (void) fcntl(kmem, F_SETFD, 1); 112768508Seric #ifdef _AIX3 112868508Seric if (knlist(Nl, 1, sizeof Nl[0]) < 0) 112968508Seric #else 113057736Seric if (nlist(_PATH_UNIX, Nl) < 0) 113168508Seric #endif 113257736Seric { 113357736Seric if (tTd(3, 1)) 113457736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 113557736Seric errstring(errno)); 113614872Seric return (-1); 113757736Seric } 113859253Seric if (Nl[X_AVENRUN].n_value == 0) 113959253Seric { 114059253Seric if (tTd(3, 1)) 114159253Seric printf("getla: nlist(%s, %s) ==> 0\n", 114259253Seric _PATH_UNIX, LA_AVENRUN); 114359253Seric return (-1); 114459253Seric } 114568508Seric #ifdef NAMELISTMASK 114668508Seric Nl[X_AVENRUN].n_value &= NAMELISTMASK; 114766763Seric #endif 114814872Seric } 114957736Seric if (tTd(3, 20)) 115057736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 115168508Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 || 115223118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 115319967Seric { 115419967Seric /* thank you Ian */ 115557736Seric if (tTd(3, 1)) 115657736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 115719967Seric return (-1); 115819967Seric } 115964360Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) 116057736Seric if (tTd(3, 5)) 116157736Seric { 116257736Seric printf("getla: avenrun = %d", avenrun[0]); 116357736Seric if (tTd(3, 15)) 116457736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 116557736Seric printf("\n"); 116657736Seric } 116757736Seric if (tTd(3, 1)) 116857736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 116924943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 117051920Seric #else 117157736Seric if (tTd(3, 5)) 117257736Seric { 117357736Seric printf("getla: avenrun = %g", avenrun[0]); 117457736Seric if (tTd(3, 15)) 117557736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 117657736Seric printf("\n"); 117757736Seric } 117857736Seric if (tTd(3, 1)) 117957736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 118051920Seric return ((int) (avenrun[0] + 0.5)); 118151920Seric #endif 118214872Seric } 118314872Seric 118451773Seric #else 118551920Seric #if LA_TYPE == LA_SUBR 118651773Seric 118764718Seric #ifdef DGUX 118864718Seric 118964718Seric #include <sys/dg_sys_info.h> 119064718Seric 119168508Seric int 119268508Seric getla() 119364718Seric { 119464718Seric struct dg_sys_info_load_info load_info; 119564718Seric 119664718Seric dg_sys_info((long *)&load_info, 119764718Seric DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); 119864718Seric 119968508Seric if (tTd(3, 1)) 120068508Seric printf("getla: %d\n", (int) (load_info.one_minute + 0.5)); 120168508Seric 120264718Seric return((int) (load_info.one_minute + 0.5)); 120364718Seric } 120464718Seric 120564718Seric #else 120668508Seric # ifdef __hpux 120764718Seric 120868869Seric struct pst_dynamic; 120968869Seric 121068508Seric # include <sys/param.h> 121168508Seric # include <sys/pstat.h> 121268508Seric 121368508Seric int 121451773Seric getla() 121551773Seric { 121668508Seric struct pst_dynamic pstd; 121768508Seric 121868508Seric if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic), 121968869Seric (size_t) 1, 0) == -1) 122068508Seric return 0; 122168508Seric 122268508Seric if (tTd(3, 1)) 122368508Seric printf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5)); 122468508Seric 122568508Seric return (int) (pstd.psd_avg_1_min + 0.5); 122668508Seric } 122768508Seric 122868508Seric # else 122968508Seric 123068508Seric int 123168508Seric getla() 123268508Seric { 123351920Seric double avenrun[3]; 123451920Seric 123551920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 123657736Seric { 123757736Seric if (tTd(3, 1)) 123857736Seric perror("getla: getloadavg failed:"); 123951920Seric return (-1); 124057736Seric } 124157736Seric if (tTd(3, 1)) 124257736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 124351920Seric return ((int) (avenrun[0] + 0.5)); 124451773Seric } 124551773Seric 124668508Seric # endif /* __hpux */ 124764718Seric #endif /* DGUX */ 124851773Seric #else 124964295Seric #if LA_TYPE == LA_MACH 125051773Seric 125164295Seric /* 125265173Seric ** This has been tested on NEXTSTEP release 2.1/3.X. 125364295Seric */ 125464295Seric 125565173Seric #if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 125665173Seric # include <mach/mach.h> 125765173Seric #else 125865173Seric # include <mach.h> 125965173Seric #endif 126064295Seric 126151773Seric getla() 126251773Seric { 126364295Seric processor_set_t default_set; 126464295Seric kern_return_t error; 126564295Seric unsigned int info_count; 126664295Seric struct processor_set_basic_info info; 126764295Seric host_t host; 126864295Seric 126964295Seric error = processor_set_default(host_self(), &default_set); 127064295Seric if (error != KERN_SUCCESS) 127164295Seric return -1; 127264295Seric info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 127364295Seric if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, 127464295Seric &host, (processor_set_info_t)&info, 127564295Seric &info_count) != KERN_SUCCESS) 127664295Seric { 127764295Seric return -1; 127864295Seric } 127964295Seric return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE; 128064295Seric } 128164295Seric 128264295Seric 128364295Seric #else 128466313Seric #if LA_TYPE == LA_PROCSTR 128564295Seric 128666301Seric /* 128766301Seric ** Read /proc/loadavg for the load average. This is assumed to be 128866301Seric ** in a format like "0.15 0.12 0.06". 128966301Seric ** 129066301Seric ** Initially intended for Linux. This has been in the kernel 129166301Seric ** since at least 0.99.15. 129266301Seric */ 129366301Seric 129466301Seric # ifndef _PATH_LOADAVG 129566301Seric # define _PATH_LOADAVG "/proc/loadavg" 129666301Seric # endif 129766301Seric 129866301Seric int 129964295Seric getla() 130064295Seric { 130166319Seric double avenrun; 130266301Seric register int result; 130366319Seric FILE *fp; 130466301Seric 130566319Seric fp = fopen(_PATH_LOADAVG, "r"); 130666319Seric if (fp == NULL) 130766301Seric { 130866319Seric if (tTd(3, 1)) 130966319Seric printf("getla: fopen(%s): %s\n", 131066319Seric _PATH_LOADAVG, errstring(errno)); 131166319Seric return -1; 131266301Seric } 131366301Seric result = fscanf(fp, "%lf", &avenrun); 131466319Seric fclose(fp); 131566301Seric if (result != 1) 131666301Seric { 131766310Seric if (tTd(3, 1)) 131866301Seric printf("getla: fscanf() = %d: %s\n", 131966301Seric result, errstring(errno)); 132066301Seric return -1; 132166301Seric } 132266301Seric 132357736Seric if (tTd(3, 1)) 132466301Seric printf("getla(): %.2f\n", avenrun); 132566301Seric 132666301Seric return ((int) (avenrun + 0.5)); 132766301Seric } 132866301Seric 132966301Seric #else 133066301Seric 133166301Seric getla() 133266301Seric { 133366301Seric if (tTd(3, 1)) 133457736Seric printf("getla: ZERO\n"); 133551920Seric return (0); 133651773Seric } 133751773Seric 133851773Seric #endif 133951773Seric #endif 134064295Seric #endif 134166301Seric #endif 134266045Seric 134366045Seric 134466045Seric /* 134566045Seric * Copyright 1989 Massachusetts Institute of Technology 134666045Seric * 134766045Seric * Permission to use, copy, modify, distribute, and sell this software and its 134866045Seric * documentation for any purpose is hereby granted without fee, provided that 134966045Seric * the above copyright notice appear in all copies and that both that 135066045Seric * copyright notice and this permission notice appear in supporting 135166045Seric * documentation, and that the name of M.I.T. not be used in advertising or 135266045Seric * publicity pertaining to distribution of the software without specific, 135366045Seric * written prior permission. M.I.T. makes no representations about the 135466045Seric * suitability of this software for any purpose. It is provided "as is" 135566045Seric * without express or implied warranty. 135666045Seric * 135766045Seric * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 135866045Seric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 135966045Seric * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 136066045Seric * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 136166045Seric * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 136266045Seric * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 136366045Seric * 136466045Seric * Authors: Many and varied... 136566045Seric */ 136666045Seric 136766045Seric /* Non Apollo stuff removed by Don Lewis 11/15/93 */ 136866045Seric #ifndef lint 136966045Seric static char rcsid[] = "@(#)$Id: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $"; 137066045Seric #endif /* !lint */ 137166045Seric 137266179Seric #ifdef apollo 137366045Seric # undef volatile 137466045Seric # include <apollo/base.h> 137566045Seric 137666045Seric /* ARGSUSED */ 137766045Seric int getloadavg( call_data ) 137866045Seric caddr_t call_data; /* pointer to (double) return value */ 137966045Seric { 138066045Seric double *avenrun = (double *) call_data; 138166045Seric int i; 138266045Seric status_$t st; 138366045Seric long loadav[3]; 138466045Seric proc1_$get_loadav(loadav, &st); 138566045Seric *avenrun = loadav[0] / (double) (1 << 16); 138666045Seric return(0); 138766045Seric } 138866045Seric # endif /* apollo */ 138924943Seric /* 139024943Seric ** SHOULDQUEUE -- should this message be queued or sent? 139124943Seric ** 139224943Seric ** Compares the message cost to the load average to decide. 139324943Seric ** 139424943Seric ** Parameters: 139524943Seric ** pri -- the priority of the message in question. 139657438Seric ** ctime -- the message creation time. 139724943Seric ** 139824943Seric ** Returns: 139924943Seric ** TRUE -- if this message should be queued up for the 140024943Seric ** time being. 140124943Seric ** FALSE -- if the load is low enough to send this message. 140224943Seric ** 140324943Seric ** Side Effects: 140424943Seric ** none. 140524943Seric */ 140624943Seric 140724943Seric bool 140857438Seric shouldqueue(pri, ctime) 140924943Seric long pri; 141057438Seric time_t ctime; 141124943Seric { 141268508Seric bool rval; 141368508Seric 141468508Seric if (tTd(3, 30)) 141568508Seric printf("shouldqueue: CurrentLA=%d, pri=%d: ", CurrentLA, pri); 141651920Seric if (CurrentLA < QueueLA) 141768508Seric { 141868508Seric if (tTd(3, 30)) 141968508Seric printf("FALSE (CurrentLA < QueueLA)\n"); 142024943Seric return (FALSE); 142168508Seric } 142258132Seric if (CurrentLA >= RefuseLA) 142368508Seric { 142468508Seric if (tTd(3, 30)) 142568508Seric printf("TRUE (CurrentLA >= RefuseLA)\n"); 142658132Seric return (TRUE); 142768508Seric } 142868508Seric rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1)); 142968508Seric if (tTd(3, 30)) 143068508Seric printf("%s (by calculation)\n", rval ? "TRUE" : "FALSE"); 143168508Seric return rval; 143224943Seric } 143324943Seric /* 143453037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 143553037Seric ** 143653037Seric ** Parameters: 143753037Seric ** none. 143853037Seric ** 143953037Seric ** Returns: 144053037Seric ** TRUE if incoming SMTP connections should be refused 144153037Seric ** (for now). 144253037Seric ** FALSE if we should accept new work. 144353037Seric ** 144453037Seric ** Side Effects: 144553037Seric ** none. 144653037Seric */ 144753037Seric 144853037Seric bool 144953037Seric refuseconnections() 145053037Seric { 145168508Seric extern bool enoughspace(); 145268508Seric 145359156Seric #ifdef XLA 145459156Seric if (!xla_smtp_ok()) 145559156Seric return TRUE; 145659156Seric #endif 145759156Seric 145853037Seric /* this is probably too simplistic */ 145968508Seric return CurrentLA >= RefuseLA || !enoughspace(MinBlocksFree + 1); 146053037Seric } 146153037Seric /* 146224943Seric ** SETPROCTITLE -- set process title for ps 146324943Seric ** 146424943Seric ** Parameters: 146558674Seric ** fmt -- a printf style format string. 146658674Seric ** a, b, c -- possible parameters to fmt. 146724943Seric ** 146824943Seric ** Returns: 146924943Seric ** none. 147024943Seric ** 147124943Seric ** Side Effects: 147224943Seric ** Clobbers argv of our main procedure so ps(1) will 147324943Seric ** display the title. 147424943Seric */ 147524943Seric 147668508Seric #define SPT_NONE 0 /* don't use it at all */ 147768508Seric #define SPT_REUSEARGV 1 /* cover argv with title information */ 147868508Seric #define SPT_BUILTIN 2 /* use libc builtin */ 147968508Seric #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */ 148068508Seric #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */ 148168508Seric #define SPT_WRITEUDOT 5 /* write u. area in kmem */ 148268508Seric 148368508Seric #ifndef SPT_TYPE 148468508Seric # define SPT_TYPE SPT_REUSEARGV 148568508Seric #endif 148668508Seric 148768508Seric #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN 148868508Seric 148968508Seric # if SPT_TYPE == SPT_PSTAT 149058689Seric # include <sys/pstat.h> 149158689Seric # endif 149268508Seric # if SPT_TYPE == SPT_PSSTRINGS 149359732Seric # include <machine/vmparam.h> 149459732Seric # include <sys/exec.h> 149568508Seric # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */ 149668508Seric # undef SPT_TYPE 149768508Seric # define SPT_TYPE SPT_REUSEARGV 149868734Seric # else 149968734Seric # ifndef NKPDE /* FreeBSD 2.0 */ 150068734Seric # define NKPDE 63 150168734Seric typedef unsigned int *pt_entry_t; 150268734Seric # endif 150364247Seric # endif 150459732Seric # endif 150568508Seric 150668508Seric # if SPT_TYPE == SPT_PSSTRINGS 150768508Seric # define SETPROC_STATIC static 150868508Seric # else 150959732Seric # define SETPROC_STATIC 151059732Seric # endif 151167626Seric 151268508Seric # ifndef SPT_PADCHAR 151368508Seric # define SPT_PADCHAR ' ' 151468508Seric # endif 151558689Seric 151668508Seric #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */ 151764843Seric 151868508Seric #if SPT_TYPE != SPT_BUILTIN 151968508Seric 152024943Seric /*VARARGS1*/ 152168508Seric void 152268508Seric # ifdef __STDC__ 152357642Seric setproctitle(char *fmt, ...) 152468508Seric # else 152557642Seric setproctitle(fmt, va_alist) 152624943Seric char *fmt; 152757642Seric va_dcl 152868508Seric # endif 152924943Seric { 153068508Seric # if SPT_TYPE != SPT_NONE 153124943Seric register char *p; 153225049Seric register int i; 153359732Seric SETPROC_STATIC char buf[MAXLINE]; 153456852Seric VA_LOCAL_DECL 153568508Seric # if SPT_TYPE == SPT_PSTAT 153658689Seric union pstun pst; 153758689Seric # endif 153824943Seric extern char **Argv; 153924943Seric extern char *LastArgv; 154024943Seric 154158674Seric p = buf; 154224943Seric 154358674Seric /* print sendmail: heading for grep */ 154458674Seric (void) strcpy(p, "sendmail: "); 154558674Seric p += strlen(p); 154624943Seric 154758674Seric /* print the argument string */ 154858674Seric VA_START(fmt); 154958674Seric (void) vsprintf(p, fmt, ap); 155056852Seric VA_END; 155154996Seric 155258674Seric i = strlen(buf); 155358689Seric 155468508Seric # if SPT_TYPE == SPT_PSTAT 155558689Seric pst.pst_command = buf; 155658689Seric pstat(PSTAT_SETCMD, pst, i, 0, 0); 155758689Seric # else 155868508Seric # if SPT_TYPE == SPT_PSSTRINGS 155959732Seric PS_STRINGS->ps_nargvstr = 1; 156059732Seric PS_STRINGS->ps_argvstr = buf; 156159732Seric # else 156254996Seric if (i > LastArgv - Argv[0] - 2) 156325049Seric { 156454996Seric i = LastArgv - Argv[0] - 2; 156558674Seric buf[i] = '\0'; 156625049Seric } 156758674Seric (void) strcpy(Argv[0], buf); 156854997Seric p = &Argv[0][i]; 156924943Seric while (p < LastArgv) 157068508Seric *p++ = SPT_PADCHAR; 157168508Seric Argv[1] = NULL; 157268508Seric # endif /* SPT_TYPE == SPT_PSSTRINGS */ 157368508Seric # endif /* SPT_TYPE == SPT_PSTAT */ 157468508Seric # endif /* SPT_TYPE != SPT_NONE */ 157524943Seric } 157665982Seric 157768508Seric #endif /* SPT_TYPE != SPT_BUILTIN */ 157825698Seric /* 157925698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 158025698Seric ** 158125698Seric ** Parameters: 158268508Seric ** sig -- the signal that got us here (unused). 158325698Seric ** 158425698Seric ** Returns: 158525698Seric ** none. 158625698Seric ** 158725698Seric ** Side Effects: 158825698Seric ** Picks up extant zombies. 158925698Seric */ 159025698Seric 159146928Sbostic void 159268508Seric reapchild(sig) 159368508Seric int sig; 159425698Seric { 159564738Seric int olderrno = errno; 159663966Seric # ifdef HASWAITPID 159760219Seric auto int status; 159860560Seric int count; 159960560Seric int pid; 160060219Seric 160160560Seric count = 0; 160260560Seric while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 160360560Seric { 160460560Seric if (count++ > 1000) 160560560Seric { 160666748Seric #ifdef LOG 160760560Seric syslog(LOG_ALERT, "reapchild: waitpid loop: pid=%d, status=%x", 160860560Seric pid, status); 160966748Seric #endif 161060560Seric break; 161160560Seric } 161260560Seric } 161360219Seric # else 161425698Seric # ifdef WNOHANG 161525698Seric union wait status; 161625698Seric 161763753Seric while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) 161825698Seric continue; 161956795Seric # else /* WNOHANG */ 162025698Seric auto int status; 162125698Seric 162260219Seric while (wait(&status) > 0) 162325698Seric continue; 162456795Seric # endif /* WNOHANG */ 162560219Seric # endif 162664035Seric # ifdef SYS5SIGNALS 162764035Seric (void) setsignal(SIGCHLD, reapchild); 162858061Seric # endif 162964738Seric errno = olderrno; 163025698Seric } 163155418Seric /* 163255418Seric ** UNSETENV -- remove a variable from the environment 163355418Seric ** 163455418Seric ** Not needed on newer systems. 163555418Seric ** 163655418Seric ** Parameters: 163755418Seric ** name -- the string name of the environment variable to be 163855418Seric ** deleted from the current environment. 163955418Seric ** 164055418Seric ** Returns: 164155418Seric ** none. 164255418Seric ** 164355418Seric ** Globals: 164455418Seric ** environ -- a pointer to the current environment. 164555418Seric ** 164655418Seric ** Side Effects: 164755418Seric ** Modifies environ. 164855418Seric */ 164955418Seric 165063962Seric #ifndef HASUNSETENV 165155418Seric 165255418Seric void 165355418Seric unsetenv(name) 165455418Seric char *name; 165555418Seric { 165655418Seric extern char **environ; 165755418Seric register char **pp; 165855418Seric int len = strlen(name); 165955418Seric 166055418Seric for (pp = environ; *pp != NULL; pp++) 166155418Seric { 166255418Seric if (strncmp(name, *pp, len) == 0 && 166355418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 166455418Seric break; 166555418Seric } 166655418Seric 166755418Seric for (; *pp != NULL; pp++) 166855418Seric *pp = pp[1]; 166955418Seric } 167055418Seric 167163962Seric #endif 167256215Seric /* 167356215Seric ** GETDTABLESIZE -- return number of file descriptors 167456215Seric ** 167556215Seric ** Only on non-BSD systems 167656215Seric ** 167756215Seric ** Parameters: 167856215Seric ** none 167956215Seric ** 168056215Seric ** Returns: 168156215Seric ** size of file descriptor table 168256215Seric ** 168356215Seric ** Side Effects: 168456215Seric ** none 168556215Seric */ 168656215Seric 168763787Seric #ifdef SOLARIS 168863787Seric # include <sys/resource.h> 168963787Seric #endif 169056215Seric 169156215Seric int 169263787Seric getdtsize() 169356215Seric { 169463787Seric #ifdef RLIMIT_NOFILE 169563787Seric struct rlimit rl; 169663787Seric 169763787Seric if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) 169863787Seric return rl.rlim_cur; 169963787Seric #endif 170063787Seric 170164031Seric # ifdef HASGETDTABLESIZE 170264031Seric return getdtablesize(); 170364031Seric # else 170464031Seric # ifdef _SC_OPEN_MAX 170558689Seric return sysconf(_SC_OPEN_MAX); 170663787Seric # else 170756215Seric return NOFILE; 170863787Seric # endif 170958689Seric # endif 171056215Seric } 171157631Seric /* 171257631Seric ** UNAME -- get the UUCP name of this system. 171357631Seric */ 171457631Seric 171557943Seric #ifndef HASUNAME 171657631Seric 171757631Seric int 171857631Seric uname(name) 171957631Seric struct utsname *name; 172057631Seric { 172157631Seric FILE *file; 172257631Seric char *n; 172357631Seric 172457631Seric name->nodename[0] = '\0'; 172557631Seric 172657661Seric /* try /etc/whoami -- one line with the node name */ 172757631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 172857631Seric { 172957661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 173057631Seric (void) fclose(file); 173157661Seric n = strchr(name->nodename, '\n'); 173257631Seric if (n != NULL) 173357631Seric *n = '\0'; 173457631Seric if (name->nodename[0] != '\0') 173557631Seric return (0); 173657631Seric } 173757631Seric 173857661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 173957631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 174057631Seric { 174157631Seric char buf[MAXLINE]; 174257631Seric 174357631Seric while (fgets(buf, MAXLINE, file) != NULL) 174457631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 174557631Seric NODE_LENGTH, name->nodename) > 0) 174657631Seric break; 174757631Seric (void) fclose(file); 174857631Seric if (name->nodename[0] != '\0') 174957631Seric return (0); 175057631Seric } 175157631Seric 175257631Seric #ifdef TRUST_POPEN 175357631Seric /* 175457631Seric ** Popen is known to have security holes. 175557631Seric */ 175657631Seric 175757661Seric /* try uuname -l to return local name */ 175857631Seric if ((file = popen("uuname -l", "r")) != NULL) 175957631Seric { 176057661Seric (void) fgets(name, NODE_LENGTH + 1, file); 176157631Seric (void) pclose(file); 176257661Seric n = strchr(name, '\n'); 176357631Seric if (n != NULL) 176457631Seric *n = '\0'; 176557661Seric if (name->nodename[0] != '\0') 176657631Seric return (0); 176757631Seric } 176857631Seric #endif 176957631Seric 177057631Seric return (-1); 177157631Seric } 177257943Seric #endif /* HASUNAME */ 177358068Seric /* 177458068Seric ** INITGROUPS -- initialize groups 177558068Seric ** 177658068Seric ** Stub implementation for System V style systems 177758068Seric */ 177858068Seric 177958068Seric #ifndef HASINITGROUPS 178058068Seric 178158068Seric initgroups(name, basegid) 178258068Seric char *name; 178358068Seric int basegid; 178458068Seric { 178558068Seric return 0; 178658068Seric } 178758068Seric 178858068Seric #endif 178958082Seric /* 179059289Seric ** SETSID -- set session id (for non-POSIX systems) 179159289Seric */ 179259289Seric 179359289Seric #ifndef HASSETSID 179459289Seric 179563753Seric pid_t 179663753Seric setsid __P ((void)) 179759289Seric { 179864155Seric #ifdef TIOCNOTTY 179964155Seric int fd; 180064155Seric 180166743Seric fd = open("/dev/tty", O_RDWR, 0); 180264155Seric if (fd >= 0) 180364155Seric { 180464155Seric (void) ioctl(fd, (int) TIOCNOTTY, (char *) 0); 180564155Seric (void) close(fd); 180664155Seric } 180764155Seric #endif /* TIOCNOTTY */ 180864705Seric # ifdef SYS5SETPGRP 180963753Seric return setpgrp(); 181063753Seric # else 181164155Seric return setpgid(0, getpid()); 181259289Seric # endif 181359289Seric } 181459289Seric 181559289Seric #endif 181659289Seric /* 181766748Seric ** FSYNC -- dummy fsync 181866748Seric */ 181966748Seric 182066748Seric #ifdef NEEDFSYNC 182166748Seric 182266748Seric fsync(fd) 182366748Seric int fd; 182466748Seric { 182566748Seric # ifdef O_SYNC 182666748Seric return fcntl(fd, F_SETFL, O_SYNC); 182766748Seric # else 182866748Seric /* nothing we can do */ 182966748Seric return 0; 183066748Seric # endif 183166748Seric } 183266748Seric 183366748Seric #endif 183466748Seric /* 183564718Seric ** DGUX_INET_ADDR -- inet_addr for DG/UX 183664718Seric ** 183764718Seric ** Data General DG/UX version of inet_addr returns a struct in_addr 183868508Seric ** instead of a long. This patches things. Only needed on versions 183968508Seric ** prior to 5.4.3. 184064718Seric */ 184164718Seric 184268508Seric #ifdef DGUX_5_4_2 184364718Seric 184464718Seric #undef inet_addr 184564718Seric 184664718Seric long 184764718Seric dgux_inet_addr(host) 184864718Seric char *host; 184964718Seric { 185064718Seric struct in_addr haddr; 185164718Seric 185264718Seric haddr = inet_addr(host); 185364718Seric return haddr.s_addr; 185464718Seric } 185564718Seric 185664718Seric #endif 185764718Seric /* 185863969Seric ** GETOPT -- for old systems or systems with bogus implementations 185963969Seric */ 186063969Seric 186163969Seric #ifdef NEEDGETOPT 186263969Seric 186363969Seric /* 186463969Seric * Copyright (c) 1985 Regents of the University of California. 186563969Seric * All rights reserved. The Berkeley software License Agreement 186663969Seric * specifies the terms and conditions for redistribution. 186763969Seric */ 186863969Seric 186963969Seric 187063969Seric /* 187163969Seric ** this version hacked to add `atend' flag to allow state machine 187263969Seric ** to reset if invoked by the program to scan args for a 2nd time 187363969Seric */ 187463969Seric 187563969Seric #if defined(LIBC_SCCS) && !defined(lint) 187663969Seric static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; 187764072Seric #endif /* LIBC_SCCS and not lint */ 187863969Seric 187963969Seric #include <stdio.h> 188063969Seric 188163969Seric /* 188263969Seric * get option letter from argument vector 188363969Seric */ 188465352Seric #ifdef _CONVEX_SOURCE 188568508Seric extern int optind, opterr, optopt; 188668508Seric extern char *optarg; 188765352Seric #else 188865352Seric int opterr = 1; /* if error message should be printed */ 188965352Seric int optind = 1; /* index into parent argv vector */ 189068470Seric int optopt = 0; /* character checked for validity */ 189168470Seric char *optarg = NULL; /* argument associated with option */ 189268508Seric #endif 189363969Seric 189463969Seric #define BADCH (int)'?' 189563969Seric #define EMSG "" 189663969Seric #define tell(s) if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ 189763969Seric fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);} 189863969Seric 189963969Seric getopt(nargc,nargv,ostr) 190065160Seric int nargc; 190165160Seric char *const *nargv; 190265160Seric const char *ostr; 190363969Seric { 190463969Seric static char *place = EMSG; /* option letter processing */ 190563969Seric static char atend = 0; 190663969Seric register char *oli; /* option letter list index */ 190763969Seric 190863969Seric if (atend) { 190963969Seric atend = 0; 191063969Seric place = EMSG; 191163969Seric } 191263969Seric if(!*place) { /* update scanning pointer */ 191364136Seric if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) { 191463969Seric atend++; 191563969Seric return(EOF); 191663969Seric } 191763969Seric if (*place == '-') { /* found "--" */ 191863969Seric ++optind; 191963969Seric atend++; 192063969Seric return(EOF); 192163969Seric } 192263969Seric } /* option letter okay? */ 192364125Seric if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) { 192464136Seric if (!*place) ++optind; 192563969Seric tell(": illegal option -- "); 192663969Seric } 192763969Seric if (*++oli != ':') { /* don't need argument */ 192863969Seric optarg = NULL; 192963969Seric if (!*place) ++optind; 193063969Seric } 193163969Seric else { /* need an argument */ 193263969Seric if (*place) optarg = place; /* no white space */ 193363969Seric else if (nargc <= ++optind) { /* no arg */ 193463969Seric place = EMSG; 193563969Seric tell(": option requires an argument -- "); 193663969Seric } 193763969Seric else optarg = nargv[optind]; /* white space */ 193863969Seric place = EMSG; 193963969Seric ++optind; 194063969Seric } 194163969Seric return(optopt); /* dump back option letter */ 194263969Seric } 194363969Seric 194463969Seric #endif 194563969Seric /* 194663969Seric ** VFPRINTF, VSPRINTF -- for old 4.3 BSD systems missing a real version 194763969Seric */ 194863969Seric 194963969Seric #ifdef NEEDVPRINTF 195063969Seric 195163969Seric #define MAXARG 16 195263969Seric 195363969Seric vfprintf(fp, fmt, ap) 195463969Seric FILE * fp; 195563969Seric char * fmt; 195663969Seric char ** ap; 195763969Seric { 195863969Seric char * bp[MAXARG]; 195963969Seric int i = 0; 196063969Seric 196163969Seric while (*ap && i < MAXARG) 196263969Seric bp[i++] = *ap++; 196363969Seric fprintf(fp, fmt, bp[0], bp[1], bp[2], bp[3], 196463969Seric bp[4], bp[5], bp[6], bp[7], 196563969Seric bp[8], bp[9], bp[10], bp[11], 196663969Seric bp[12], bp[13], bp[14], bp[15]); 196763969Seric } 196863969Seric 196963969Seric vsprintf(s, fmt, ap) 197063969Seric char * s; 197163969Seric char * fmt; 197263969Seric char ** ap; 197363969Seric { 197463969Seric char * bp[MAXARG]; 197563969Seric int i = 0; 197663969Seric 197763969Seric while (*ap && i < MAXARG) 197863969Seric bp[i++] = *ap++; 197963969Seric sprintf(s, fmt, bp[0], bp[1], bp[2], bp[3], 198063969Seric bp[4], bp[5], bp[6], bp[7], 198163969Seric bp[8], bp[9], bp[10], bp[11], 198263969Seric bp[12], bp[13], bp[14], bp[15]); 198363969Seric } 198463969Seric 198563969Seric #endif 198663969Seric /* 198765220Seric ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use 198865208Seric ** 198965211Seric ** Parameters: 199065211Seric ** shell -- the user's shell from /etc/passwd 199165211Seric ** 199265211Seric ** Returns: 199365211Seric ** TRUE -- if it is ok to use this for unrestricted access. 199465211Seric ** FALSE -- if the shell is restricted. 199565208Seric */ 199665208Seric 199765587Seric #if !HASGETUSERSHELL 199865587Seric 199965587Seric # ifndef _PATH_SHELLS 200065587Seric # define _PATH_SHELLS "/etc/shells" 200165587Seric # endif 200265587Seric 200365587Seric char *DefaultUserShells[] = 200465587Seric { 200568508Seric "/bin/sh", /* standard shell */ 200665587Seric "/usr/bin/sh", 200768508Seric "/bin/csh", /* C shell */ 200865587Seric "/usr/bin/csh", 200965587Seric #ifdef __hpux 201068508Seric "/bin/rsh", /* restricted Bourne shell */ 201168508Seric "/bin/ksh", /* Korn shell */ 201268508Seric "/bin/rksh", /* restricted Korn shell */ 201365587Seric "/bin/pam", 201468508Seric "/usr/bin/keysh", /* key shell (extended Korn shell) */ 201565587Seric "/bin/posix/sh", 201665211Seric #endif 201768508Seric #ifdef _AIX3 201868508Seric "/bin/ksh", /* Korn shell */ 201968508Seric "/usr/bin/ksh", 202068508Seric "/bin/tsh", /* trusted shell */ 202168508Seric "/usr/bin/tsh", 202268508Seric "/bin/bsh", /* Bourne shell */ 202368508Seric "/usr/bin/bsh", 202468508Seric #endif 202565587Seric NULL 202665587Seric }; 202765587Seric 202865208Seric #endif 202965208Seric 203065747Seric #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" 203165747Seric 203265211Seric bool 203365211Seric usershellok(shell) 203465211Seric char *shell; 203565208Seric { 203665211Seric #if HASGETUSERSHELL 203765211Seric register char *p; 203865211Seric extern char *getusershell(); 203965208Seric 204068457Seric if (shell == NULL || shell[0] == '\0') 204168457Seric return TRUE; 204268457Seric 204365211Seric setusershell(); 204465211Seric while ((p = getusershell()) != NULL) 204565747Seric if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0) 204665211Seric break; 204765211Seric endusershell(); 204865211Seric return p != NULL; 204965211Seric #else 205065211Seric register FILE *shellf; 205165211Seric char buf[MAXLINE]; 205265208Seric 205368457Seric if (shell == NULL || shell[0] == '\0') 205468457Seric return TRUE; 205568457Seric 205665211Seric shellf = fopen(_PATH_SHELLS, "r"); 205765211Seric if (shellf == NULL) 205865211Seric { 205965211Seric /* no /etc/shells; see if it is one of the std shells */ 206065587Seric char **d; 206165587Seric 206265587Seric for (d = DefaultUserShells; *d != NULL; d++) 206365587Seric { 206465587Seric if (strcmp(shell, *d) == 0) 206565587Seric return TRUE; 206665587Seric } 206765587Seric return FALSE; 206865211Seric } 206965208Seric 207065211Seric while (fgets(buf, sizeof buf, shellf) != NULL) 207165211Seric { 207265211Seric register char *p, *q; 207365208Seric 207465211Seric p = buf; 207565211Seric while (*p != '\0' && *p != '#' && *p != '/') 207665211Seric p++; 207765211Seric if (*p == '#' || *p == '\0') 207865208Seric continue; 207965211Seric q = p; 208065211Seric while (*p != '\0' && *p != '#' && !isspace(*p)) 208165211Seric p++; 208265211Seric *p = '\0'; 208365747Seric if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0) 208465211Seric { 208565211Seric fclose(shellf); 208665211Seric return TRUE; 208765211Seric } 208865208Seric } 208965211Seric fclose(shellf); 209065211Seric return FALSE; 209165211Seric #endif 209265208Seric } 209365208Seric /* 209464311Seric ** FREESPACE -- see how much free space is on the queue filesystem 209558082Seric ** 209658082Seric ** Only implemented if you have statfs. 209758082Seric ** 209858082Seric ** Parameters: 209964311Seric ** dir -- the directory in question. 210064311Seric ** bsize -- a variable into which the filesystem 210164311Seric ** block size is stored. 210258082Seric ** 210358082Seric ** Returns: 210464311Seric ** The number of bytes free on the queue filesystem. 210564311Seric ** -1 if the statfs call fails. 210664311Seric ** 210764311Seric ** Side effects: 210864311Seric ** Puts the filesystem block size into bsize. 210958082Seric */ 211058082Seric 211165749Seric /* statfs types */ 211265749Seric #define SFS_NONE 0 /* no statfs implementation */ 211365749Seric #define SFS_USTAT 1 /* use ustat */ 211465749Seric #define SFS_4ARGS 2 /* use four-argument statfs call */ 211565749Seric #define SFS_VFS 3 /* use <sys/vfs.h> implementation */ 211665749Seric #define SFS_MOUNT 4 /* use <sys/mount.h> implementation */ 211765749Seric #define SFS_STATFS 5 /* use <sys/statfs.h> implementation */ 211866752Seric #define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */ 211965749Seric 212065749Seric #ifndef SFS_TYPE 212165749Seric # define SFS_TYPE SFS_NONE 212258157Seric #endif 212358157Seric 212465749Seric #if SFS_TYPE == SFS_USTAT 212558157Seric # include <ustat.h> 212658157Seric #endif 212765749Seric #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS 212865749Seric # include <sys/statfs.h> 212958082Seric #endif 213065749Seric #if SFS_TYPE == SFS_VFS 213165749Seric # include <sys/vfs.h> 213265749Seric #endif 213365749Seric #if SFS_TYPE == SFS_MOUNT 213465749Seric # include <sys/mount.h> 213565749Seric #endif 213666752Seric #if SFS_TYPE == SFS_STATVFS 213766752Seric # include <sys/statvfs.h> 213866752Seric #endif 213958082Seric 214064311Seric long 214164311Seric freespace(dir, bsize) 214264311Seric char *dir; 214364311Seric long *bsize; 214458082Seric { 214565749Seric #if SFS_TYPE != SFS_NONE 214665749Seric # if SFS_TYPE == SFS_USTAT 214758153Seric struct ustat fs; 214858153Seric struct stat statbuf; 214958366Seric # define FSBLOCKSIZE DEV_BSIZE 215068695Seric # define SFS_BAVAIL f_tfree 215158157Seric # else 215258157Seric # if defined(ultrix) 215358157Seric struct fs_data fs; 215468695Seric # define SFS_BAVAIL fd_bfreen 215568508Seric # define FSBLOCKSIZE 1024L 215658153Seric # else 215766752Seric # if SFS_TYPE == SFS_STATVFS 215866752Seric struct statvfs fs; 215968508Seric # define FSBLOCKSIZE fs.f_frsize 216066752Seric # else 216158082Seric struct statfs fs; 216266752Seric # define FSBLOCKSIZE fs.f_bsize 216363987Seric # endif 216458153Seric # endif 216558133Seric # endif 216668695Seric # ifndef SFS_BAVAIL 216768695Seric # define SFS_BAVAIL f_bavail 216868508Seric # endif 216958082Seric 217065749Seric # if SFS_TYPE == SFS_USTAT 217164311Seric if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 217258157Seric # else 217365749Seric # if SFS_TYPE == SFS_4ARGS 217464311Seric if (statfs(dir, &fs, sizeof fs, 0) == 0) 217558157Seric # else 217668508Seric # if SFS_TYPE == SFS_STATVFS 217768508Seric if (statvfs(dir, &fs) == 0) 217868508Seric # else 217968508Seric # if defined(ultrix) 218068499Seric if (statfs(dir, &fs) > 0) 218168508Seric # else 218264311Seric if (statfs(dir, &fs) == 0) 218368508Seric # endif 218458153Seric # endif 218558133Seric # endif 218658133Seric # endif 218758133Seric { 218864311Seric if (bsize != NULL) 218964311Seric *bsize = FSBLOCKSIZE; 219068695Seric return (fs.SFS_BAVAIL); 219164311Seric } 219264337Seric #endif 219364311Seric return (-1); 219464311Seric } 219564311Seric /* 219664311Seric ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 219764311Seric ** 219864311Seric ** Only implemented if you have statfs. 219964311Seric ** 220064311Seric ** Parameters: 220164311Seric ** msize -- the size to check against. If zero, we don't yet 220264311Seric ** know how big the message will be, so just check for 220364311Seric ** a "reasonable" amount. 220464311Seric ** 220564311Seric ** Returns: 220664311Seric ** TRUE if there is enough space. 220764311Seric ** FALSE otherwise. 220864311Seric */ 220964311Seric 221064311Seric bool 221164311Seric enoughspace(msize) 221264311Seric long msize; 221364311Seric { 221464311Seric long bfree, bsize; 221564311Seric 221664311Seric if (MinBlocksFree <= 0 && msize <= 0) 221764311Seric { 221858133Seric if (tTd(4, 80)) 221964311Seric printf("enoughspace: no threshold\n"); 222064311Seric return TRUE; 222164311Seric } 222264311Seric 222364311Seric if ((bfree = freespace(QueueDir, &bsize)) >= 0) 222464311Seric { 222564311Seric if (tTd(4, 80)) 222658333Seric printf("enoughspace: bavail=%ld, need=%ld\n", 222764311Seric bfree, msize); 222858333Seric 222958333Seric /* convert msize to block count */ 223064311Seric msize = msize / bsize + 1; 223158333Seric if (MinBlocksFree >= 0) 223258333Seric msize += MinBlocksFree; 223358333Seric 223464311Seric if (bfree < msize) 223558090Seric { 223658090Seric #ifdef LOG 223758090Seric if (LogLevel > 0) 223864254Seric syslog(LOG_ALERT, 223964254Seric "%s: low on space (have %ld, %s needs %ld in %s)", 224068508Seric CurEnv->e_id == NULL ? "[NOQUEUE]" : CurEnv->e_id, 224168508Seric bfree, 224268508Seric CurHostName == NULL ? "SMTP-DAEMON" : CurHostName, 224368508Seric msize, QueueDir); 224458090Seric #endif 224558082Seric return FALSE; 224658090Seric } 224758082Seric } 224858082Seric else if (tTd(4, 80)) 224958333Seric printf("enoughspace failure: min=%ld, need=%ld: %s\n", 225058333Seric MinBlocksFree, msize, errstring(errno)); 225158082Seric return TRUE; 225258082Seric } 225358542Seric /* 225458542Seric ** TRANSIENTERROR -- tell if an error code indicates a transient failure 225558542Seric ** 225658542Seric ** This looks at an errno value and tells if this is likely to 225758542Seric ** go away if retried later. 225858542Seric ** 225958542Seric ** Parameters: 226058542Seric ** err -- the errno code to classify. 226158542Seric ** 226258542Seric ** Returns: 226358542Seric ** TRUE if this is probably transient. 226458542Seric ** FALSE otherwise. 226558542Seric */ 226658542Seric 226758542Seric bool 226858542Seric transienterror(err) 226958542Seric int err; 227058542Seric { 227158542Seric switch (err) 227258542Seric { 227358542Seric case EIO: /* I/O error */ 227458542Seric case ENXIO: /* Device not configured */ 227558542Seric case EAGAIN: /* Resource temporarily unavailable */ 227658542Seric case ENOMEM: /* Cannot allocate memory */ 227758542Seric case ENODEV: /* Operation not supported by device */ 227858542Seric case ENFILE: /* Too many open files in system */ 227958542Seric case EMFILE: /* Too many open files */ 228058542Seric case ENOSPC: /* No space left on device */ 228158542Seric #ifdef ETIMEDOUT 228258542Seric case ETIMEDOUT: /* Connection timed out */ 228358542Seric #endif 228458542Seric #ifdef ESTALE 228558542Seric case ESTALE: /* Stale NFS file handle */ 228658542Seric #endif 228758542Seric #ifdef ENETDOWN 228858542Seric case ENETDOWN: /* Network is down */ 228958542Seric #endif 229058542Seric #ifdef ENETUNREACH 229158542Seric case ENETUNREACH: /* Network is unreachable */ 229258542Seric #endif 229358542Seric #ifdef ENETRESET 229458542Seric case ENETRESET: /* Network dropped connection on reset */ 229558542Seric #endif 229658542Seric #ifdef ECONNABORTED 229758542Seric case ECONNABORTED: /* Software caused connection abort */ 229858542Seric #endif 229958542Seric #ifdef ECONNRESET 230058542Seric case ECONNRESET: /* Connection reset by peer */ 230158542Seric #endif 230258542Seric #ifdef ENOBUFS 230358542Seric case ENOBUFS: /* No buffer space available */ 230458542Seric #endif 230558542Seric #ifdef ESHUTDOWN 230658542Seric case ESHUTDOWN: /* Can't send after socket shutdown */ 230758542Seric #endif 230858542Seric #ifdef ECONNREFUSED 230958542Seric case ECONNREFUSED: /* Connection refused */ 231058542Seric #endif 231158542Seric #ifdef EHOSTDOWN 231258542Seric case EHOSTDOWN: /* Host is down */ 231358542Seric #endif 231458542Seric #ifdef EHOSTUNREACH 231558542Seric case EHOSTUNREACH: /* No route to host */ 231658542Seric #endif 231758542Seric #ifdef EDQUOT 231858542Seric case EDQUOT: /* Disc quota exceeded */ 231958542Seric #endif 232058542Seric #ifdef EPROCLIM 232158542Seric case EPROCLIM: /* Too many processes */ 232258542Seric #endif 232358542Seric #ifdef EUSERS 232458542Seric case EUSERS: /* Too many users */ 232558542Seric #endif 232658542Seric #ifdef EDEADLK 232758542Seric case EDEADLK: /* Resource deadlock avoided */ 232858542Seric #endif 232958542Seric #ifdef EISCONN 233058542Seric case EISCONN: /* Socket already connected */ 233158542Seric #endif 233258542Seric #ifdef EINPROGRESS 233358542Seric case EINPROGRESS: /* Operation now in progress */ 233458542Seric #endif 233558542Seric #ifdef EALREADY 233658542Seric case EALREADY: /* Operation already in progress */ 233758542Seric #endif 233858542Seric #ifdef EADDRINUSE 233958542Seric case EADDRINUSE: /* Address already in use */ 234058542Seric #endif 234158542Seric #ifdef EADDRNOTAVAIL 234258542Seric case EADDRNOTAVAIL: /* Can't assign requested address */ 234358542Seric #endif 234466018Seric #ifdef ETXTBSY 234566017Seric case ETXTBSY: /* (Apollo) file locked */ 234666017Seric #endif 234763834Seric #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) 234858542Seric case ENOSR: /* Out of streams resources */ 234958542Seric #endif 235058542Seric return TRUE; 235158542Seric } 235258542Seric 235358542Seric /* nope, must be permanent */ 235458542Seric return FALSE; 235558542Seric } 235658689Seric /* 235764035Seric ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking 235858689Seric ** 235958689Seric ** Parameters: 236058689Seric ** fd -- the file descriptor of the file. 236158689Seric ** filename -- the file name (for error messages). 236264335Seric ** ext -- the filename extension. 236358689Seric ** type -- type of the lock. Bits can be: 236458689Seric ** LOCK_EX -- exclusive lock. 236558689Seric ** LOCK_NB -- non-blocking. 236658689Seric ** 236758689Seric ** Returns: 236858689Seric ** TRUE if the lock was acquired. 236958689Seric ** FALSE otherwise. 237058689Seric */ 237158689Seric 237258689Seric bool 237364335Seric lockfile(fd, filename, ext, type) 237458689Seric int fd; 237558689Seric char *filename; 237664335Seric char *ext; 237758689Seric int type; 237858689Seric { 237965830Seric # if !HASFLOCK 238058689Seric int action; 238158689Seric struct flock lfd; 238264335Seric 238364335Seric if (ext == NULL) 238464335Seric ext = ""; 238564035Seric 238663983Seric bzero(&lfd, sizeof lfd); 238759447Seric if (bitset(LOCK_UN, type)) 238859447Seric lfd.l_type = F_UNLCK; 238959447Seric else if (bitset(LOCK_EX, type)) 239058689Seric lfd.l_type = F_WRLCK; 239158689Seric else 239258689Seric lfd.l_type = F_RDLCK; 239358689Seric 239458689Seric if (bitset(LOCK_NB, type)) 239558689Seric action = F_SETLK; 239658689Seric else 239758689Seric action = F_SETLKW; 239858689Seric 239964264Seric if (tTd(55, 60)) 240064335Seric printf("lockfile(%s%s, action=%d, type=%d): ", 240164335Seric filename, ext, action, lfd.l_type); 240264264Seric 240358689Seric if (fcntl(fd, action, &lfd) >= 0) 240464264Seric { 240564264Seric if (tTd(55, 60)) 240664264Seric printf("SUCCESS\n"); 240758689Seric return TRUE; 240864264Seric } 240958689Seric 241064264Seric if (tTd(55, 60)) 241164264Seric printf("(%s) ", errstring(errno)); 241264264Seric 241364136Seric /* 241464136Seric ** On SunOS, if you are testing using -oQ/tmp/mqueue or 241564136Seric ** -oA/tmp/aliases or anything like that, and /tmp is mounted 241664136Seric ** as type "tmp" (that is, served from swap space), the 241764136Seric ** previous fcntl will fail with "Invalid argument" errors. 241864136Seric ** Since this is fairly common during testing, we will assume 241964136Seric ** that this indicates that the lock is successfully grabbed. 242064136Seric */ 242164136Seric 242264136Seric if (errno == EINVAL) 242364264Seric { 242464264Seric if (tTd(55, 60)) 242564264Seric printf("SUCCESS\n"); 242664136Seric return TRUE; 242764264Seric } 242864136Seric 242958689Seric if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 243064378Seric { 243164378Seric int omode = -1; 243264378Seric # ifdef F_GETFL 243364378Seric int oerrno = errno; 243464378Seric 243564378Seric (void) fcntl(fd, F_GETFL, &omode); 243664378Seric errno = oerrno; 243764378Seric # endif 243864378Seric syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 243964378Seric filename, ext, fd, type, omode, geteuid()); 244064378Seric } 244158689Seric # else 244264335Seric if (ext == NULL) 244364335Seric ext = ""; 244464335Seric 244564264Seric if (tTd(55, 60)) 244664335Seric printf("lockfile(%s%s, type=%o): ", filename, ext, type); 244764264Seric 244858689Seric if (flock(fd, type) >= 0) 244964264Seric { 245064264Seric if (tTd(55, 60)) 245164264Seric printf("SUCCESS\n"); 245258689Seric return TRUE; 245364264Seric } 245458689Seric 245564264Seric if (tTd(55, 60)) 245664264Seric printf("(%s) ", errstring(errno)); 245764264Seric 245858689Seric if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 245964378Seric { 246064378Seric int omode = -1; 246164378Seric # ifdef F_GETFL 246264378Seric int oerrno = errno; 246364378Seric 246464378Seric (void) fcntl(fd, F_GETFL, &omode); 246564378Seric errno = oerrno; 246664378Seric # endif 246764378Seric syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 246864378Seric filename, ext, fd, type, omode, geteuid()); 246964386Seric } 247058689Seric # endif 247164264Seric if (tTd(55, 60)) 247264264Seric printf("FAIL\n"); 247358689Seric return FALSE; 247458689Seric } 247564556Seric /* 247665948Seric ** CHOWNSAFE -- tell if chown is "safe" (executable only by root) 247765948Seric ** 247865948Seric ** Parameters: 247965948Seric ** fd -- the file descriptor to check. 248065948Seric ** 248165948Seric ** Returns: 248265948Seric ** TRUE -- if only root can chown the file to an arbitrary 248365948Seric ** user. 248465948Seric ** FALSE -- if an arbitrary user can give away a file. 248565948Seric */ 248665948Seric 248765948Seric bool 248865948Seric chownsafe(fd) 248965948Seric int fd; 249065948Seric { 249165950Seric #ifdef __hpux 249265948Seric char *s; 249365948Seric int tfd; 249465948Seric uid_t o_uid, o_euid; 249565948Seric gid_t o_gid, o_egid; 249665948Seric bool rval; 249765948Seric struct stat stbuf; 249865948Seric 249965948Seric o_uid = getuid(); 250065948Seric o_euid = geteuid(); 250165948Seric o_gid = getgid(); 250265948Seric o_egid = getegid(); 250365959Seric fstat(fd, &stbuf); 250465948Seric setresuid(stbuf.st_uid, stbuf.st_uid, -1); 250565948Seric setresgid(stbuf.st_gid, stbuf.st_gid, -1); 250665948Seric s = tmpnam(NULL); 250765948Seric tfd = open(s, O_RDONLY|O_CREAT, 0600); 250865974Seric rval = fchown(tfd, DefUid, DefGid) != 0; 250965948Seric close(tfd); 251065948Seric unlink(s); 251165948Seric setreuid(o_uid, o_euid); 251265948Seric setresgid(o_gid, o_egid, -1); 251365948Seric return rval; 251465948Seric #else 251566088Seric # ifdef _POSIX_CHOWN_RESTRICTED 251666088Seric # if _POSIX_CHOWN_RESTRICTED == -1 251766088Seric return FALSE; 251866088Seric # else 251966088Seric return TRUE; 252066088Seric # endif 252166088Seric # else 252266088Seric # ifdef _PC_CHOWN_RESTRICTED 252368508Seric int rval; 252468508Seric 252568508Seric /* 252668508Seric ** Some systems (e.g., SunOS) seem to have the call and the 252768508Seric ** #define _PC_CHOWN_RESTRICTED, but don't actually implement 252868508Seric ** the call. This heuristic checks for that. 252968508Seric */ 253068508Seric 253168508Seric errno = 0; 253268508Seric rval = fpathconf(fd, _PC_CHOWN_RESTRICTED); 253368508Seric if (errno == 0) 253468508Seric return rval > 0; 253568508Seric # endif 253668508Seric # ifdef BSD 253768508Seric return TRUE; 253868499Seric # else 253965948Seric return FALSE; 254065948Seric # endif 254165948Seric # endif 254265948Seric #endif 254365948Seric } 254465948Seric /* 254568508Seric ** RESETLIMITS -- reset system controlled resource limits 254668508Seric ** 254768508Seric ** This is to avoid denial-of-service attacks 254868508Seric ** 254968508Seric ** Parameters: 255068508Seric ** none 255168508Seric ** 255268508Seric ** Returns: 255368508Seric ** none 255468508Seric */ 255568508Seric 255668508Seric #if HASSETRLIMIT 255768508Seric # include <sys/resource.h> 255868508Seric #endif 255968508Seric 256068508Seric void 256168508Seric resetlimits() 256268508Seric { 256368508Seric #if HASSETRLIMIT 256468508Seric struct rlimit lim; 256568508Seric 256668508Seric lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; 256768508Seric (void) setrlimit(RLIMIT_CPU, &lim); 256868508Seric (void) setrlimit(RLIMIT_FSIZE, &lim); 256968508Seric #else 257068508Seric # if HASULIMIT 257168508Seric (void) ulimit(2, 0x3fffff); 257268508Seric # endif 257368508Seric #endif 257468508Seric } 257568508Seric /* 257664556Seric ** GETCFNAME -- return the name of the .cf file. 257764556Seric ** 257864556Seric ** Some systems (e.g., NeXT) determine this dynamically. 257964556Seric */ 258064556Seric 258164556Seric char * 258264556Seric getcfname() 258364556Seric { 258468842Seric int i; 258568842Seric static char cbuf[200]; 258668842Seric 258764556Seric if (ConfFile != NULL) 258864556Seric return ConfFile; 258965214Seric #ifdef NETINFO 259065214Seric { 259165214Seric extern char *ni_propval(); 259265214Seric char *cflocation; 259365214Seric 259468508Seric cflocation = ni_propval("/locations", NULL, "sendmail", 259568508Seric "sendmail.cf", '\0'); 259665214Seric if (cflocation != NULL) 259765214Seric return cflocation; 259865214Seric } 259965214Seric #endif 260068842Seric 260168842Seric /* 260268842Seric ** Try sendmail.8.6.12.cf, then sendmail.8.6.cf, then 260368842Seric ** sendmail.8.cf, and finally sendmail.cf. 260468842Seric ** 260568842Seric ** I suppose it should really try a search path here -- 260668842Seric ** e.g., /etc/sendmail.cf, /etc/mail/sendmail.cf, 260768842Seric ** /usr/lib/sendmail.cf, and so forth. 260868842Seric */ 260968842Seric 261068842Seric strcpy(cbuf, _PATH_SENDMAILCF); 261168842Seric i = strlen(cbuf); 261268842Seric if (strcmp(&cbuf[i - 3], ".cf") == 0) 261368842Seric { 261468842Seric char *p; 261568842Seric extern char Version[]; 261668842Seric 261768842Seric strcpy(&cbuf[i - 2], Version); 261868842Seric p = strchr(&cbuf[i - 2], '/'); 261968842Seric if (p != NULL) 262068842Seric *p = '\0'; 262168842Seric p = &cbuf[strlen(cbuf)]; 262268842Seric do 262368842Seric { 262468842Seric int fd; 262568842Seric 262668842Seric strcpy(p, ".cf"); 262768842Seric if ((fd = open(cbuf, O_RDONLY, 0)) >= 0) 262868842Seric { 262968842Seric close(fd); 263068842Seric return cbuf; 263168842Seric } 263268842Seric *p = '\0'; 263368842Seric } while ((p = strrchr(&cbuf[i - 2], '.')) != NULL); 263468842Seric } 263564556Seric return _PATH_SENDMAILCF; 263664556Seric } 263764718Seric /* 263864718Seric ** SETVENDOR -- process vendor code from V configuration line 263964718Seric ** 264064718Seric ** Parameters: 264164718Seric ** vendor -- string representation of vendor. 264264718Seric ** 264364718Seric ** Returns: 264464718Seric ** TRUE -- if ok. 264564718Seric ** FALSE -- if vendor code could not be processed. 264664926Seric ** 264764926Seric ** Side Effects: 264864926Seric ** It is reasonable to set mode flags here to tweak 264964926Seric ** processing in other parts of the code if necessary. 265064926Seric ** For example, if you are a vendor that uses $%y to 265164926Seric ** indicate YP lookups, you could enable that here. 265264718Seric */ 265364718Seric 265464718Seric bool 265564718Seric setvendor(vendor) 265664718Seric char *vendor; 265764718Seric { 265864926Seric if (strcasecmp(vendor, "Berkeley") == 0) 265968508Seric { 266068508Seric VendorCode = VENDOR_BERKELEY; 266164926Seric return TRUE; 266268508Seric } 266364926Seric 266464926Seric /* add vendor extensions here */ 266564926Seric 266668508Seric #ifdef SUN_EXTENSIONS 266768508Seric if (strcasecmp(vendor, "Sun") == 0) 266868508Seric { 266968508Seric VendorCode = VENDOR_SUN; 267068508Seric return TRUE; 267168508Seric } 267268508Seric #endif 267368508Seric 267464926Seric return FALSE; 267564718Seric } 267664816Seric /* 267764816Seric ** STRTOL -- convert string to long integer 267864816Seric ** 267964816Seric ** For systems that don't have it in the C library. 268066161Seric ** 268166161Seric ** This is taken verbatim from the 4.4-Lite C library. 268264816Seric */ 268364816Seric 268464816Seric #ifdef NEEDSTRTOL 268564816Seric 268666161Seric #if defined(LIBC_SCCS) && !defined(lint) 268766161Seric static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; 268866161Seric #endif /* LIBC_SCCS and not lint */ 268966161Seric 269066161Seric #include <limits.h> 269166161Seric 269266161Seric /* 269366161Seric * Convert a string to a long integer. 269466161Seric * 269566161Seric * Ignores `locale' stuff. Assumes that the upper and lower case 269666161Seric * alphabets and digits are each contiguous. 269766161Seric */ 269866161Seric 269964816Seric long 270066161Seric strtol(nptr, endptr, base) 270166161Seric const char *nptr; 270266161Seric char **endptr; 270366161Seric register int base; 270464816Seric { 270566161Seric register const char *s = nptr; 270666161Seric register unsigned long acc; 270766161Seric register int c; 270866161Seric register unsigned long cutoff; 270966161Seric register int neg = 0, any, cutlim; 271064816Seric 271166161Seric /* 271266161Seric * Skip white space and pick up leading +/- sign if any. 271366161Seric * If base is 0, allow 0x for hex and 0 for octal, else 271466161Seric * assume decimal; if base is already 16, allow 0x. 271566161Seric */ 271666161Seric do { 271766161Seric c = *s++; 271866161Seric } while (isspace(c)); 271966161Seric if (c == '-') { 272066161Seric neg = 1; 272166161Seric c = *s++; 272266161Seric } else if (c == '+') 272366161Seric c = *s++; 272466161Seric if ((base == 0 || base == 16) && 272566161Seric c == '0' && (*s == 'x' || *s == 'X')) { 272666161Seric c = s[1]; 272766161Seric s += 2; 272866161Seric base = 16; 272966161Seric } 273066161Seric if (base == 0) 273166161Seric base = c == '0' ? 8 : 10; 273264816Seric 273366161Seric /* 273466161Seric * Compute the cutoff value between legal numbers and illegal 273566161Seric * numbers. That is the largest legal value, divided by the 273666161Seric * base. An input number that is greater than this value, if 273766161Seric * followed by a legal input character, is too big. One that 273866161Seric * is equal to this value may be valid or not; the limit 273966161Seric * between valid and invalid numbers is then based on the last 274066161Seric * digit. For instance, if the range for longs is 274166161Seric * [-2147483648..2147483647] and the input base is 10, 274266161Seric * cutoff will be set to 214748364 and cutlim to either 274366161Seric * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 274466161Seric * a value > 214748364, or equal but the next digit is > 7 (or 8), 274566161Seric * the number is too big, and we will return a range error. 274666161Seric * 274766161Seric * Set any if any `digits' consumed; make it negative to indicate 274866161Seric * overflow. 274966161Seric */ 275066161Seric cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; 275166161Seric cutlim = cutoff % (unsigned long)base; 275266161Seric cutoff /= (unsigned long)base; 275366161Seric for (acc = 0, any = 0;; c = *s++) { 275466161Seric if (isdigit(c)) 275566161Seric c -= '0'; 275666161Seric else if (isalpha(c)) 275766161Seric c -= isupper(c) ? 'A' - 10 : 'a' - 10; 275866161Seric else 275966161Seric break; 276066161Seric if (c >= base) 276166161Seric break; 276266161Seric if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) 276366161Seric any = -1; 276466161Seric else { 276566161Seric any = 1; 276666161Seric acc *= base; 276766161Seric acc += c; 276864816Seric } 276964816Seric } 277066161Seric if (any < 0) { 277166161Seric acc = neg ? LONG_MIN : LONG_MAX; 277266161Seric errno = ERANGE; 277366161Seric } else if (neg) 277466161Seric acc = -acc; 277566161Seric if (endptr != 0) 277666161Seric *endptr = (char *)(any ? s - 1 : nptr); 277766161Seric return (acc); 277864816Seric } 277964816Seric 278064816Seric #endif 278164841Seric /* 278268693Seric ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX 278364841Seric ** 278468693Seric ** Some operating systems have wierd problems with the gethostbyXXX 278568693Seric ** routines. For example, Solaris versions at least through 2.3 278668693Seric ** don't properly deliver a canonical h_name field. This tries to 278768693Seric ** work around these problems. 278864841Seric */ 278964841Seric 279064841Seric struct hostent * 279168693Seric sm_gethostbyname(name) 279268707Seric char *name; 279364841Seric { 279468693Seric #if defined(SOLARIS) && SOLARIS < 204 279568693Seric extern int h_errno; 279668693Seric 279768508Seric # if SOLARIS == 203 279864841Seric static struct hostent hp; 279964841Seric static char buf[1000]; 280064841Seric extern struct hostent *_switch_gethostbyname_r(); 280164841Seric 280264841Seric return _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 280364841Seric # else 280465009Seric extern struct hostent *__switch_gethostbyname(); 280565009Seric 280664841Seric return __switch_gethostbyname(name); 280764841Seric # endif 280868693Seric #else 280968693Seric return gethostbyname(name); 281068693Seric #endif 281164841Seric } 281264841Seric 281364841Seric struct hostent * 281468693Seric sm_gethostbyaddr(addr, len, type) 281568707Seric char *addr; 281664841Seric int len; 281764841Seric int type; 281864841Seric { 281968693Seric #if defined(SOLARIS) && SOLARIS < 204 282068693Seric extern int h_errno; 282168693Seric 282268508Seric # if SOLARIS == 203 282364841Seric static struct hostent hp; 282464841Seric static char buf[1000]; 282564841Seric extern struct hostent *_switch_gethostbyaddr_r(); 282664841Seric 282764841Seric return _switch_gethostbyaddr_r(addr, len, type, &hp, buf, sizeof(buf), &h_errno); 282864841Seric # else 282965009Seric extern struct hostent *__switch_gethostbyaddr(); 283065009Seric 283164841Seric return __switch_gethostbyaddr(addr, len, type); 283264841Seric # endif 283368693Seric #else 283468693Seric return gethostbyaddr(addr, len, type); 283568693Seric #endif 283664841Seric } 283768693Seric /* 283868693Seric ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid 283968693Seric */ 284064841Seric 284168693Seric struct passwd * 284268693Seric sm_getpwnam(user) 284368704Seric char *user; 284468693Seric { 284568693Seric return getpwnam(user); 284668693Seric } 284768693Seric 284868693Seric struct passwd * 284968693Seric sm_getpwuid(uid) 285068693Seric uid_t uid; 285168693Seric { 285268693Seric return getpwuid(uid); 285368693Seric } 285465214Seric /* 285565214Seric ** NI_PROPVAL -- netinfo property value lookup routine 285665214Seric ** 285765214Seric ** Parameters: 285868508Seric ** keydir -- the Netinfo directory name in which to search 285968508Seric ** for the key. 286068508Seric ** keyprop -- the name of the property in which to find the 286168508Seric ** property we are interested. Defaults to "name". 286268508Seric ** keyval -- the value for which we are really searching. 286368508Seric ** valprop -- the property name for the value in which we 286468508Seric ** are interested. 286568508Seric ** sepchar -- if non-nil, this can be multiple-valued, and 286668508Seric ** we should return a string separated by this 286768508Seric ** character. 286865214Seric ** 286965214Seric ** Returns: 287065214Seric ** NULL -- if: 287165214Seric ** 1. the directory is not found 287265214Seric ** 2. the property name is not found 287365214Seric ** 3. the property contains multiple values 287465214Seric ** 4. some error occured 287565214Seric ** else -- the location of the config file. 287665214Seric ** 287768508Seric ** Example: 287868508Seric ** To search for an alias value, use: 287968508Seric ** ni_propval("/aliases", "name", aliasname, "members", ',') 288068508Seric ** 288165214Seric ** Notes: 288265214Seric ** Caller should free the return value of ni_proval 288365214Seric */ 288465214Seric 288565214Seric #ifdef NETINFO 288665214Seric 288765214Seric # include <netinfo/ni.h> 288865214Seric 288965214Seric # define LOCAL_NETINFO_DOMAIN "." 289065214Seric # define PARENT_NETINFO_DOMAIN ".." 289165214Seric # define MAX_NI_LEVELS 256 289265214Seric 289365214Seric char * 289468508Seric ni_propval(keydir, keyprop, keyval, valprop, sepchar) 289568508Seric char *keydir; 289668508Seric char *keyprop; 289768508Seric char *keyval; 289868508Seric char *valprop; 289968508Seric char sepchar; 290065214Seric { 290165820Seric char *propval = NULL; 290265214Seric int i; 290368508Seric int j, alen; 290465214Seric void *ni = NULL; 290565214Seric void *lastni = NULL; 290665214Seric ni_status nis; 290765214Seric ni_id nid; 290865214Seric ni_namelist ninl; 290968508Seric register char *p; 291068508Seric char keybuf[1024]; 291165214Seric 291265214Seric /* 291368508Seric ** Create the full key from the two parts. 291468508Seric ** 291568508Seric ** Note that directory can end with, e.g., "name=" to specify 291668508Seric ** an alternate search property. 291768508Seric */ 291868508Seric 291968508Seric i = strlen(keydir) + strlen(keyval) + 2; 292068508Seric if (keyprop != NULL) 292168508Seric i += strlen(keyprop) + 1; 292268508Seric if (i > sizeof keybuf) 292368508Seric return NULL; 292468508Seric strcpy(keybuf, keydir); 292568508Seric strcat(keybuf, "/"); 292668508Seric if (keyprop != NULL) 292768508Seric { 292868508Seric strcat(keybuf, keyprop); 292968508Seric strcat(keybuf, "="); 293068508Seric } 293168508Seric strcat(keybuf, keyval); 293268508Seric 293368508Seric /* 293465214Seric ** If the passed directory and property name are found 293565214Seric ** in one of netinfo domains we need to search (starting 293665214Seric ** from the local domain moving all the way back to the 293765214Seric ** root domain) set propval to the property's value 293865214Seric ** and return it. 293965214Seric */ 294065214Seric 294165214Seric for (i = 0; i < MAX_NI_LEVELS; ++i) 294265214Seric { 294365214Seric if (i == 0) 294465214Seric { 294565214Seric nis = ni_open(NULL, LOCAL_NETINFO_DOMAIN, &ni); 294665214Seric } 294765214Seric else 294865214Seric { 294965214Seric if (lastni != NULL) 295065214Seric ni_free(lastni); 295165214Seric lastni = ni; 295265214Seric nis = ni_open(lastni, PARENT_NETINFO_DOMAIN, &ni); 295365214Seric } 295465214Seric 295565214Seric /* 295665214Seric ** Don't bother if we didn't get a handle on a 295765214Seric ** proper domain. This is not necessarily an error. 295865214Seric ** We would get a positive ni_status if, for instance 295965214Seric ** we never found the directory or property and tried 296065214Seric ** to open the parent of the root domain! 296165214Seric */ 296265214Seric 296365214Seric if (nis != 0) 296465214Seric break; 296565214Seric 296665214Seric /* 296765214Seric ** Find the path to the server information. 296865214Seric */ 296965214Seric 297068508Seric if (ni_pathsearch(ni, &nid, keybuf) != 0) 297165214Seric continue; 297265214Seric 297365214Seric /* 297468508Seric ** Find associated value information. 297565214Seric */ 297665214Seric 297768508Seric if (ni_lookupprop(ni, &nid, valprop, &ninl) != 0) 297865214Seric continue; 297965214Seric 298065214Seric /* 298168508Seric ** See if we have an acceptable number of values. 298265214Seric */ 298365214Seric 298468508Seric if (ninl.ni_namelist_len <= 0) 298568508Seric continue; 298668508Seric 298768508Seric if (sepchar == '\0' && ninl.ni_namelist_len > 1) 298865214Seric { 298968508Seric ni_namelist_free(&ninl); 299068508Seric continue; 299165214Seric } 299268508Seric 299368508Seric /* 299468508Seric ** Calculate number of bytes needed and build result 299568508Seric */ 299668508Seric 299768508Seric alen = 1; 299868508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 299968508Seric alen += strlen(ninl.ni_namelist_val[j]) + 1; 300068508Seric propval = p = xalloc(alen); 300168508Seric for (j = 0; j < ninl.ni_namelist_len; j++) 300268508Seric { 300368508Seric strcpy(p, ninl.ni_namelist_val[j]); 300468508Seric p += strlen(p); 300568508Seric *p++ = sepchar; 300668508Seric } 300768508Seric *--p = '\0'; 300868508Seric 300968508Seric ni_namelist_free(&ninl); 301065214Seric } 301165214Seric 301265214Seric /* 301365214Seric ** Clean up. 301465214Seric */ 301565214Seric 301665214Seric if (ni != NULL) 301765214Seric ni_free(ni); 301865214Seric if (lastni != NULL && ni != lastni) 301965214Seric ni_free(lastni); 302065214Seric 302165214Seric return propval; 302265214Seric } 302365214Seric 302465214Seric #endif /* NETINFO */ 302565504Seric /* 302665504Seric ** HARD_SYSLOG -- call syslog repeatedly until it works 302765504Seric ** 302865504Seric ** Needed on HP-UX, which apparently doesn't guarantee that 302965504Seric ** syslog succeeds during interrupt handlers. 303065504Seric */ 303165504Seric 303265504Seric #ifdef __hpux 303365504Seric 303465504Seric # define MAXSYSLOGTRIES 100 303565504Seric # undef syslog 303665504Seric 303765504Seric # ifdef __STDC__ 303865504Seric hard_syslog(int pri, char *msg, ...) 303965504Seric # else 304065504Seric hard_syslog(pri, msg, va_alist) 304165504Seric int pri; 304265504Seric char *msg; 304365504Seric va_dcl 304465504Seric # endif 304565504Seric { 304665504Seric int i; 304765504Seric char buf[SYSLOG_BUFSIZE * 2]; 304865504Seric VA_LOCAL_DECL; 304965504Seric 305065504Seric VA_START(msg); 305165504Seric vsprintf(buf, msg, ap); 305265504Seric VA_END; 305365504Seric 305465504Seric for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, "%s", buf) < 0; ) 305565504Seric continue; 305665504Seric } 305765504Seric 305865504Seric #endif 305968696Seric /* 306068696Seric ** LOCAL_HOSTNAME_LENGTH 306168696Seric ** 306268696Seric ** This is required to get sendmail to compile against BIND 4.9.x 306368696Seric ** on Ultrix. 306468696Seric */ 306568696Seric 306668696Seric #if defined(ultrix) && NAMED_BIND 306768696Seric 306868696Seric # include <resolv.h> 306968696Seric # if __RES >= 19931104 307068696Seric 307168696Seric int 307268696Seric local_hostname_length(hostname) 307368696Seric char *hostname; 307468696Seric { 307568696Seric int len_host, len_domain; 307668696Seric 307768696Seric if (!*_res.defdname) 307868696Seric res_init(); 307968696Seric len_host = strlen(hostname); 308068696Seric len_domain = strlen(_res.defdname); 308168696Seric if (len_host > len_domain && 308268696Seric (strcasecmp(hostname + len_host - len_domain,_res.defdname) == 0) && 308368696Seric hostname[len_host - len_domain - 1] == '.') 308468696Seric return len_host - len_domain - 1; 308568696Seric else 308668696Seric return 0; 308768696Seric } 308868696Seric 308968696Seric # endif 309068696Seric #endif 309168741Seric /* 309268741Seric ** Compile-Time options 309368741Seric */ 309468741Seric 309568741Seric char *CompileOptions[] = 309668741Seric { 309768741Seric #if HESIOD 309868741Seric "HESIOD", 309968741Seric #endif 310068741Seric #if LOG 310168741Seric "LOG", 310268741Seric #endif 310368741Seric #if MATCHGECOS 310468741Seric "MATCHGECOS", 310568741Seric #endif 310668741Seric #if NAMED_BIND 310768741Seric "NAMED_BIND", 310868741Seric #endif 310968741Seric #if NDBM 311068741Seric "NDBM", 311168741Seric #endif 311268741Seric #if NETINET 311368741Seric "NETINET", 311468741Seric #endif 311568741Seric #if NETINFO 311668741Seric "NETINFO", 311768741Seric #endif 311868741Seric #if NETISO 311968741Seric "NETISO", 312068741Seric #endif 312168741Seric #if NETNS 312268741Seric "NETNS", 312368741Seric #endif 312468741Seric #if NETUNIX 312568741Seric "NETUNIX", 312668741Seric #endif 312768741Seric #if NETX25 312868741Seric "NETX25", 312968741Seric #endif 313068741Seric #if NEWDB 313168741Seric "NEWDB", 313268741Seric #endif 313368741Seric #if NIS 313468741Seric "NIS", 313568741Seric #endif 313668741Seric #if SCANF 313768741Seric "SCANF", 313868741Seric #endif 313968741Seric #if SUID_ROOT_FILES_OK 314068741Seric "SUID_ROOT_FILES_OK", 314168741Seric #endif 314268741Seric #if USERDB 314368741Seric "USERDB", 314468741Seric #endif 314568741Seric #if XDEBUG 314668741Seric "XDEBUG", 314768741Seric #endif 314868741Seric #if XLA 314968741Seric "XLA", 315068741Seric #endif 315168741Seric NULL 315268741Seric }; 3153