2 * Copyright (c) 1998-2013 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: conf.c,v 8.1192 2014-01-27 18:23:21 ca Exp $")
18 #include <sm/sendmail.h>
19 #include <sendmail/pathnames.h>
29 /* for the IPv6 device lookup */
30 # define _SOCKADDR_LEN
32 # endif /* NETINET6 */
35 # include <sys/ioctl.h>
36 # include <sys/param.h>
39 #if NETINET || NETINET6
40 # include <arpa/inet.h>
41 #endif /* NETINET || NETINET6 */
42 #if HASULIMIT && defined(HPUX11)
44 #endif /* HASULIMIT && defined(HPUX11) */
46 static void setupmaps __P((void));
47 static void setupmailers __P((void));
48 static void setupqueues __P((void));
49 static int get_num_procs_online __P((void));
50 static int add_hostnames __P((SOCKADDR *));
52 #if NETINET6 && NEEDSGETIPNODE
53 static struct hostent *sm_getipnodebyname __P((const char *, int, int, int *));
54 static struct hostent *sm_getipnodebyaddr __P((const void *, size_t, int, int *));
55 #else /* NETINET6 && NEEDSGETIPNODE */
56 #define sm_getipnodebyname getipnodebyname
57 #define sm_getipnodebyaddr getipnodebyaddr
58 #endif /* NETINET6 && NEEDSGETIPNODE */
62 ** CONF.C -- Sendmail Configuration Tables.
64 ** Defines the configuration of this installation.
66 ** Configuration Variables:
67 ** HdrInfo -- a table describing well-known header fields.
68 ** Each entry has the field name and some flags,
69 ** which are described in sendmail.h.
72 ** I have tried to put almost all the reasonable
73 ** configuration information into the configuration
74 ** file read at runtime. My intent is that anything
75 ** here is a function of the version of UNIX you
76 ** are running, or is really static -- for example
77 ** the headers are a superset of widely used
78 ** protocols. If you find yourself playing with
79 ** this file too much, you may be making a mistake!
85 ** Final (null) entry contains the flags used for any other field.
87 ** Not all of these are actually handled specially by sendmail
88 ** at this time. They are included as placeholders, to let
89 ** you know that "someday" I intend to have sendmail do
90 ** something with them.
93 struct hdrinfo HdrInfo[] =
95 /* originator fields, most to least significant */
96 { "resent-sender", H_FROM|H_RESENT, NULL },
97 { "resent-from", H_FROM|H_RESENT, NULL },
98 { "resent-reply-to", H_FROM|H_RESENT, NULL },
99 { "sender", H_FROM, NULL },
100 { "from", H_FROM, NULL },
101 { "reply-to", H_FROM, NULL },
102 { "errors-to", H_FROM|H_ERRORSTO, NULL },
103 { "full-name", H_ACHECK, NULL },
104 { "return-receipt-to", H_RECEIPTTO, NULL },
105 { "delivery-receipt-to", H_RECEIPTTO, NULL },
106 { "disposition-notification-to", H_FROM, NULL },
108 /* destination fields */
109 { "to", H_RCPT, NULL },
110 { "resent-to", H_RCPT|H_RESENT, NULL },
111 { "cc", H_RCPT, NULL },
112 { "resent-cc", H_RCPT|H_RESENT, NULL },
113 { "bcc", H_RCPT|H_BCC, NULL },
114 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
115 { "apparently-to", H_RCPT, NULL },
117 /* message identification and control */
118 { "message-id", 0, NULL },
119 { "resent-message-id", H_RESENT, NULL },
120 { "message", H_EOH, NULL },
121 { "text", H_EOH, NULL },
125 { "resent-date", H_RESENT, NULL },
128 { "received", H_TRACE|H_FORCE, NULL },
129 { "x400-received", H_TRACE|H_FORCE, NULL },
130 { "via", H_TRACE|H_FORCE, NULL },
131 { "mail-from", H_TRACE|H_FORCE, NULL },
133 /* miscellaneous fields */
134 { "comments", H_FORCE|H_ENCODABLE, NULL },
135 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
136 { "content-transfer-encoding", H_CTE, NULL },
137 { "content-type", H_CTYPE, NULL },
138 { "content-length", H_ACHECK, NULL },
139 { "subject", H_ENCODABLE, NULL },
140 { "x-authentication-warning", H_FORCE, NULL },
151 struct prival PrivacyValues[] =
153 { "public", PRIV_PUBLIC },
154 { "needmailhelo", PRIV_NEEDMAILHELO },
155 { "needexpnhelo", PRIV_NEEDEXPNHELO },
156 { "needvrfyhelo", PRIV_NEEDVRFYHELO },
157 { "noexpn", PRIV_NOEXPN },
158 { "novrfy", PRIV_NOVRFY },
159 { "restrictexpand", PRIV_RESTRICTEXPAND },
160 { "restrictmailq", PRIV_RESTRICTMAILQ },
161 { "restrictqrun", PRIV_RESTRICTQRUN },
162 { "noetrn", PRIV_NOETRN },
163 { "noverb", PRIV_NOVERB },
164 { "authwarnings", PRIV_AUTHWARNINGS },
165 { "noreceipts", PRIV_NORECEIPTS },
166 { "nobodyreturn", PRIV_NOBODYRETN },
167 { "goaway", PRIV_GOAWAY },
168 { "noactualrecipient", PRIV_NOACTUALRECIPIENT },
173 ** DontBlameSendmail values
176 struct dbsval DontBlameSendmailValues[] =
178 { "safe", DBS_SAFE },
179 { "assumesafechown", DBS_ASSUMESAFECHOWN },
180 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
181 { "groupwritableforwardfilesafe",
182 DBS_GROUPWRITABLEFORWARDFILESAFE },
183 { "groupwritableincludefilesafe",
184 DBS_GROUPWRITABLEINCLUDEFILESAFE },
185 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
186 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
187 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
188 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
189 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
190 { "linkedaliasfileinwritabledir",
191 DBS_LINKEDALIASFILEINWRITABLEDIR },
192 { "linkedclassfileinwritabledir",
193 DBS_LINKEDCLASSFILEINWRITABLEDIR },
194 { "linkedforwardfileinwritabledir",
195 DBS_LINKEDFORWARDFILEINWRITABLEDIR },
196 { "linkedincludefileinwritabledir",
197 DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
198 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
199 { "linkedserviceswitchfileinwritabledir",
200 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
201 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
202 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
203 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
204 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
205 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
206 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
207 { "forwardfileingroupwritabledirpath",
208 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
209 { "includefileingroupwritabledirpath",
210 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
211 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
212 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
213 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
214 { "forwardfileinunsafedirpathsafe",
215 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
216 { "includefileinunsafedirpathsafe",
217 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
218 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
219 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
220 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
221 { "truststickybit", DBS_TRUSTSTICKYBIT },
222 { "dontwarnforwardfileinunsafedirpath",
223 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
224 { "insufficiententropy", DBS_INSUFFICIENTENTROPY },
225 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
226 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
227 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
228 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
229 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
230 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
231 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
232 { "groupreadabledefaultauthinfofile",
233 DBS_GROUPREADABLEAUTHINFOFILE },
238 ** Miscellaneous stuff.
241 int DtableSize = 50; /* max open files; reset in 4.2bsd */
243 ** SETDEFAULTS -- set default values
245 ** Some of these must be initialized using direct code since they
246 ** depend on run-time values. So let's do all of them this way.
249 ** e -- the default envelope.
255 ** Initializes a bunch of global variables to their
260 #define HOURS * 60 MINUTES
261 #define DAYS * 24 HOURS
263 #ifndef MAXRULERECURSION
264 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
265 #endif /* ! MAXRULERECURSION */
269 register ENVELOPE *e;
275 numprocs = get_num_procs_online();
276 SpaceSub = ' '; /* option B */
277 QueueLA = 8 * numprocs; /* option x */
278 RefuseLA = 12 * numprocs; /* option X */
279 WkRecipFact = 30000L; /* option y */
280 WkClassFact = 1800L; /* option z */
281 WkTimeFact = 90000L; /* option Z */
282 QueueFactor = WkRecipFact * 20; /* option q */
283 QueueMode = QM_NORMAL; /* what queue items to act upon */
284 FileMode = (RealUid != geteuid()) ? 0644 : 0600;
286 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
287 /* option QueueFileMode */
289 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
290 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
291 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
293 DefUid = pw->pw_uid; /* option u */
294 DefGid = pw->pw_gid; /* option g */
295 DefUser = newstr(pw->pw_name);
299 DefUid = 1; /* option u */
300 DefGid = 1; /* option g */
305 sm_dprintf("setdefaults: DefUser=%s, DefUid=%ld, DefGid=%ld\n",
306 DefUser != NULL ? DefUser : "<1:1>",
307 (long) DefUid, (long) DefGid);
308 CheckpointInterval = 10; /* option C */
309 MaxHopCount = 25; /* option h */
310 set_delivery_mode(SM_FORK, e); /* option d */
311 e->e_errormode = EM_PRINT; /* option e */
314 e->e_xfqgrp = NOQGRP;
315 e->e_xfqdir = NOQDIR;
316 e->e_ctime = curtime();
317 SevenBitInput = false; /* option 7 */
318 MaxMciCache = 1; /* option k */
319 MciCacheTimeout = 5 MINUTES; /* option K */
320 LogLevel = 9; /* option L */
324 inittimeouts(NULL, false); /* option r */
325 PrivacyFlags = PRIV_PUBLIC; /* option p */
326 MeToo = true; /* option m */
327 SendMIMEErrors = true; /* option f */
328 SuperSafe = SAFE_REALLY; /* option s */
329 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
331 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
333 MimeMode = MM_PASS8BIT;
334 #endif /* MIME8TO7 */
335 for (i = 0; i < MAXTOCLASS; i++)
337 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
338 TimeOuts.to_q_warning[i] = 0; /* option T */
340 ServiceSwitchFile = "/etc/mail/service.switch";
341 ServiceCacheMaxAge = (time_t) 10;
342 HostsFile = _PATH_HOSTS;
343 PidFile = newstr(_PATH_SENDMAILPID);
344 MustQuoteChars = "@,;:\\()[].'";
345 MciInfoTimeout = 30 MINUTES;
346 MaxRuleRecursion = MAXRULERECURSION;
347 MaxAliasRecursion = 10;
348 MaxMacroRecursion = 10;
349 ColonOkInAddr = true;
350 DontLockReadFiles = true;
351 DontProbeInterfaces = DPI_PROBEALL;
352 DoubleBounceAddr = "postmaster";
353 MaxHeadersLength = MAXHDRSLEN;
354 MaxMimeHeaderLength = MAXLINE;
355 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
356 MaxForwardEntries = 0;
358 MaxNOOPCommands = MAXNOOPCOMMANDS;
360 AuthMechanisms = newstr(AUTH_MECHANISMS);
365 TLS_Srv_Opts = TLS_I_SRV;
366 if (NULL == EVP_digest)
367 EVP_digest = EVP_md5();
368 Srv_SSL_Options = SSL_OP_ALL;
369 Clt_SSL_Options = SSL_OP_ALL
370 # ifdef SSL_OP_NO_SSLv2
373 # ifdef SSL_OP_NO_TICKET
377 # ifdef SSL_OP_TLSEXT_PADDING
378 /* SSL_OP_TLSEXT_PADDING breaks compatibility with some sites */
379 Srv_SSL_Options &= ~SSL_OP_TLSEXT_PADDING;
380 Clt_SSL_Options &= ~SSL_OP_TLSEXT_PADDING;
381 # endif /* SSL_OP_TLSEXT_PADDING */
382 #endif /* STARTTLS */
384 HesiodContext = NULL;
385 #endif /* HESIOD_INIT */
387 /* Detect if IPv6 is available at run time */
388 i = socket(AF_INET6, SOCK_STREAM, 0);
397 UseCompressedIPv6Addresses = true;
401 #endif /* NETINET6 */
402 ControlSocketName = NULL;
403 memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo));
404 DataFileBufferSize = 4096;
405 XscriptFileBufferSize = 4096;
406 for (i = 0; i < MAXRWSETS; i++)
407 RuleSetNames[i] = NULL;
409 InputFilters[0] = NULL;
411 RejectLogInterval = 3 HOURS;
412 #if REQUIRES_DIR_FSYNC
413 RequiresDirfsync = true;
414 #endif /* REQUIRES_DIR_FSYNC */
415 #if _FFR_RCPTTHROTDELAY
416 BadRcptThrottleDelay = 1;
417 #endif /* _FFR_RCPTTHROTDELAY */
418 ConnectionRateWindowSize = 60;
419 #if _FFR_BOUNCE_QUEUE
420 BounceQueue = NOQGRP;
421 #endif /* _FFR_BOUNCE_QUEUE */
430 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
436 struct passwd *defpwent;
437 static char defuserbuf[40];
439 DefUser = defuserbuf;
440 defpwent = sm_getpwuid(DefUid);
441 (void) sm_strlcpy(defuserbuf,
442 (defpwent == NULL || defpwent->pw_name == NULL)
443 ? "nobody" : defpwent->pw_name,
446 sm_dprintf("setdefuser: DefUid=%ld, DefUser=%s\n",
447 (long) DefUid, DefUser);
450 ** SETUPQUEUES -- initialize default queues
452 ** The mqueue QUEUE structure gets filled in after readcf() but
453 ** we need something to point to now for the mailer setup,
454 ** which use "mqueue" as default queue.
462 MaxRunnersPerQueue = 1;
463 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf));
464 makequeue(buf, false);
467 ** SETUPMAILERS -- initialize default mailers
475 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
479 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
483 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
489 ** SETUPMAPS -- set up map classes
492 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
494 extern bool parse __P((MAP *, char *)); \
495 extern bool open __P((MAP *, int)); \
496 extern void close __P((MAP *)); \
497 extern char *lookup __P((MAP *, char *, char **, int *)); \
498 extern void store __P((MAP *, char *, char *)); \
499 s = stab(name, ST_MAPCLASS, ST_ENTER); \
500 s->s_mapclass.map_cname = name; \
501 s->s_mapclass.map_ext = ext; \
502 s->s_mapclass.map_cflags = flags; \
503 s->s_mapclass.map_parse = parse; \
504 s->s_mapclass.map_open = open; \
505 s->s_mapclass.map_close = close; \
506 s->s_mapclass.map_lookup = lookup; \
507 s->s_mapclass.map_store = store; \
516 # if DB_VERSION_MAJOR > 1
517 int major_v, minor_v, patch_v;
519 (void) db_version(&major_v, &minor_v, &patch_v);
520 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
523 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
524 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
525 major_v, minor_v, patch_v);
527 # endif /* DB_VERSION_MAJOR > 1 */
529 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
530 map_parseargs, hash_map_open, db_map_close,
531 db_map_lookup, db_map_store);
533 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
534 map_parseargs, bt_map_open, db_map_close,
535 db_map_lookup, db_map_store);
539 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
540 map_parseargs, ndbm_map_open, ndbm_map_close,
541 ndbm_map_lookup, ndbm_map_store);
545 MAPDEF("nis", NULL, MCF_ALIASOK,
546 map_parseargs, nis_map_open, null_map_close,
547 nis_map_lookup, null_map_store);
551 MAPDEF("nisplus", NULL, MCF_ALIASOK,
552 map_parseargs, nisplus_map_open, null_map_close,
553 nisplus_map_lookup, null_map_store);
557 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
558 ldapmap_parseargs, ldapmap_open, ldapmap_close,
559 ldapmap_lookup, null_map_store);
563 MAPDEF("ph", NULL, MCF_NOTPERSIST,
564 ph_map_parseargs, ph_map_open, ph_map_close,
565 ph_map_lookup, null_map_store);
569 /* IRIX 6.5 nsd support */
570 MAPDEF("nsd", NULL, MCF_ALIASOK,
571 map_parseargs, null_map_open, null_map_close,
572 nsd_map_lookup, null_map_store);
576 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
577 map_parseargs, hes_map_open, hes_map_close,
578 hes_map_lookup, null_map_store);
582 MAPDEF("netinfo", NULL, MCF_ALIASOK,
583 map_parseargs, ni_map_open, null_map_close,
584 ni_map_lookup, null_map_store);
588 MAPDEF("dns", NULL, 0,
589 dns_map_init, null_map_open, null_map_close,
590 dns_map_lookup, null_map_store);
595 # if _FFR_DNSMAP_ALIASABLE
596 MAPDEF("dns", NULL, MCF_ALIASOK,
597 dns_map_parseargs, dns_map_open, null_map_close,
598 dns_map_lookup, null_map_store);
599 # else /* _FFR_DNSMAP_ALIASABLE */
600 MAPDEF("dns", NULL, 0,
601 dns_map_parseargs, dns_map_open, null_map_close,
602 dns_map_lookup, null_map_store);
603 # endif /* _FFR_DNSMAP_ALIASABLE */
605 #endif /* NAMED_BIND */
608 /* best MX DNS lookup */
609 MAPDEF("bestmx", NULL, MCF_OPTFILE,
610 map_parseargs, null_map_open, null_map_close,
611 bestmx_map_lookup, null_map_store);
612 #endif /* NAMED_BIND */
614 MAPDEF("host", NULL, 0,
615 host_map_init, null_map_open, null_map_close,
616 host_map_lookup, null_map_store);
618 MAPDEF("text", NULL, MCF_ALIASOK,
619 map_parseargs, text_map_open, null_map_close,
620 text_map_lookup, null_map_store);
622 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
623 map_parseargs, stab_map_open, null_map_close,
624 stab_map_lookup, stab_map_store);
626 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
627 map_parseargs, impl_map_open, impl_map_close,
628 impl_map_lookup, impl_map_store);
630 /* access to system passwd file */
631 MAPDEF("user", NULL, MCF_OPTFILE,
632 map_parseargs, user_map_open, null_map_close,
633 user_map_lookup, null_map_store);
636 MAPDEF("dequote", NULL, 0,
637 dequote_init, null_map_open, null_map_close,
638 dequote_map, null_map_store);
641 MAPDEF("regex", NULL, 0,
642 regex_map_init, null_map_open, null_map_close,
643 regex_map_lookup, null_map_store);
644 #endif /* MAP_REGEX */
648 MAPDEF("userdb", ".db", 0,
649 map_parseargs, null_map_open, null_map_close,
650 udb_map_lookup, null_map_store);
653 /* arbitrary programs */
654 MAPDEF("program", NULL, MCF_ALIASOK,
655 map_parseargs, null_map_open, null_map_close,
656 prog_map_lookup, null_map_store);
659 MAPDEF("sequence", NULL, MCF_ALIASOK,
660 seq_map_parse, null_map_open, null_map_close,
661 seq_map_lookup, seq_map_store);
663 /* switched interface to sequenced maps */
664 MAPDEF("switch", NULL, MCF_ALIASOK,
665 map_parseargs, switch_map_open, null_map_close,
666 seq_map_lookup, seq_map_store);
668 /* null map lookup -- really for internal use only */
669 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
670 map_parseargs, null_map_open, null_map_close,
671 null_map_lookup, null_map_store);
673 /* syslog map -- logs information to syslog */
674 MAPDEF("syslog", NULL, 0,
675 syslog_map_parseargs, null_map_open, null_map_close,
676 syslog_map_lookup, null_map_store);
678 /* macro storage map -- rulesets can set macros */
679 MAPDEF("macro", NULL, 0,
680 dequote_init, null_map_open, null_map_close,
681 macro_map_lookup, null_map_store);
683 /* arithmetic map -- add/subtract/compare */
684 MAPDEF("arith", NULL, 0,
685 dequote_init, null_map_open, null_map_close,
686 arith_map_lookup, null_map_store);
688 /* "arpa" map -- IP -> arpa */
689 MAPDEF("arpa", NULL, 0,
690 dequote_init, null_map_open, null_map_close,
691 arpa_map_lookup, null_map_store);
694 /* arbitrary daemons */
695 MAPDEF("socket", NULL, MCF_ALIASOK,
696 map_parseargs, socket_map_open, socket_map_close,
697 socket_map_lookup, null_map_store);
698 #endif /* SOCKETMAP */
701 /* dprintf map -- logs information to syslog */
702 MAPDEF("dprintf", NULL, 0,
703 dprintf_map_parseargs, null_map_open, null_map_close,
704 dprintf_map_lookup, null_map_store);
705 #endif /* _FFR_DPRINTF_MAP */
709 /* bogus map -- always return tempfail */
710 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
711 map_parseargs, null_map_open, null_map_close,
712 bogus_map_lookup, null_map_store);
718 ** INITHOSTMAPS -- initial host-dependent maps
720 ** This should act as an interface to any local service switch
721 ** provided by the host operating system.
730 ** Should define maps "host" and "users" as necessary
731 ** for this OS. If they are not defined, they will get
732 ** a default value later. It should check to make sure
733 ** they are not defined first, since it's possible that
734 ** the config file has provided an override.
742 char *maptype[MAXMAPSTACK];
743 short mapreturn[MAXMAPACTIONS];
747 ** Make sure we have a host map.
750 if (stab("host", ST_MAP, ST_FIND) == NULL)
752 /* user didn't initialize: set up host map */
753 (void) sm_strlcpy(buf, "host host", sizeof(buf));
755 if (ConfigLevel >= 2)
756 (void) sm_strlcat(buf, " -a. -D", sizeof(buf));
757 #endif /* NAMED_BIND */
758 (void) makemapentry(buf);
762 ** Set up default aliases maps
765 nmaps = switch_map_find("aliases", maptype, mapreturn);
766 for (i = 0; i < nmaps; i++)
768 if (strcmp(maptype[i], "files") == 0 &&
769 stab("aliases.files", ST_MAP, ST_FIND) == NULL)
771 (void) sm_strlcpy(buf, "aliases.files null",
773 (void) makemapentry(buf);
776 else if (strcmp(maptype[i], "nisplus") == 0 &&
777 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
779 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
781 (void) makemapentry(buf);
785 else if (strcmp(maptype[i], "nis") == 0 &&
786 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
788 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
790 (void) makemapentry(buf);
794 else if (strcmp(maptype[i], "netinfo") == 0 &&
795 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
797 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
799 (void) makemapentry(buf);
803 else if (strcmp(maptype[i], "hesiod") == 0 &&
804 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
806 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
808 (void) makemapentry(buf);
811 #if LDAPMAP && defined(SUN_EXTENSIONS) && \
812 defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
813 else if (strcmp(maptype[i], "ldap") == 0 &&
814 stab("aliases.ldap", ST_MAP, ST_FIND) == NULL)
816 (void) sm_strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
818 (void) makemapentry(buf);
820 #endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */
822 if (stab("aliases", ST_MAP, ST_FIND) == NULL)
824 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf));
825 (void) makemapentry(buf);
830 ** SWITCH_MAP_FIND -- find the list of types associated with a map
832 ** This is the system-dependent interface to the service switch.
835 ** service -- the name of the service of interest.
836 ** maptype -- an out-array of strings containing the types
837 ** of access to use for this service. There can
838 ** be at most MAXMAPSTACK types for a single service.
839 ** mapreturn -- an out-array of return information bitmaps
843 ** The number of map types filled in, or -1 for failure.
846 ** Preserves errno so nothing in the routine clobbers it.
849 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
850 # define _USE_SUN_NSSWITCH_
851 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
853 #if _FFR_HPUX_NSSWITCH
855 # define _USE_SUN_NSSWITCH_
857 #endif /* _FFR_HPUX_NSSWITCH */
859 #ifdef _USE_SUN_NSSWITCH_
860 # include <nsswitch.h>
861 #endif /* _USE_SUN_NSSWITCH_ */
863 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
864 # define _USE_DEC_SVC_CONF_
865 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
867 #ifdef _USE_DEC_SVC_CONF_
868 # include <sys/svcinfo.h>
869 #endif /* _USE_DEC_SVC_CONF_ */
872 switch_map_find(service, maptype, mapreturn)
874 char *maptype[MAXMAPSTACK];
875 short mapreturn[MAXMAPACTIONS];
878 int save_errno = errno;
880 #ifdef _USE_SUN_NSSWITCH_
881 struct __nsw_switchconfig *nsw_conf;
882 enum __nsw_parse_err pserr;
883 struct __nsw_lookup *lk;
884 static struct __nsw_lookup lkp0 =
885 { "files", {1, 0, 0, 0}, NULL, NULL };
886 static struct __nsw_switchconfig lkp_default =
887 { 0, "sendmail", 3, &lkp0 };
889 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
890 mapreturn[svcno] = 0;
892 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
893 lk = lkp_default.lookups;
895 lk = nsw_conf->lookups;
897 while (lk != NULL && svcno < MAXMAPSTACK)
899 maptype[svcno] = lk->service_name;
900 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
901 mapreturn[MA_NOTFOUND] |= 1 << svcno;
902 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
903 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
904 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
905 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
911 #endif /* _USE_SUN_NSSWITCH_ */
913 #ifdef _USE_DEC_SVC_CONF_
914 struct svcinfo *svcinfo;
917 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
918 mapreturn[svcno] = 0;
923 if (strcmp(service, "hosts") == 0)
925 else if (strcmp(service, "aliases") == 0)
927 else if (strcmp(service, "passwd") == 0)
934 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
936 switch (svcinfo->svcpath[svc][svcno])
939 maptype[svcno] = "files";
943 maptype[svcno] = "nis";
947 maptype[svcno] = "dns";
952 maptype[svcno] = "hesiod";
954 # endif /* SVC_HESIOD */
963 #endif /* _USE_DEC_SVC_CONF_ */
965 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
967 ** Fall-back mechanism.
971 static time_t servicecachetime; /* time service switch was cached */
972 time_t now = curtime();
974 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
975 mapreturn[svcno] = 0;
977 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
979 /* (re)read service switch */
980 register SM_FILE_T *fp;
981 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
983 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
988 servicecachetime = now;
989 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
994 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
999 p = strpbrk(buf, "#\n");
1002 #ifndef SM_NSSWITCH_DELIMS
1003 # define SM_NSSWITCH_DELIMS " \t"
1004 #endif /* SM_NSSWITCH_DELIMS */
1005 p = strpbrk(buf, SM_NSSWITCH_DELIMS);
1012 sm_syslog(LOG_ERR, NOQID,
1013 "Bad line on %.100s: %.100s",
1018 while (isascii(*p) && isspace(*p))
1024 ** Find/allocate space for this service entry.
1025 ** Space for all of the service strings
1026 ** are allocated at once. This means
1027 ** that we only have to free the first
1028 ** one to free all of them.
1031 st = stab(buf, ST_SERVICE, ST_ENTER);
1032 if (st->s_service[0] != NULL)
1033 sm_free((void *) st->s_service[0]); /* XXX */
1035 for (svcno = 0; svcno < MAXMAPSTACK; )
1039 st->s_service[svcno++] = p;
1040 p = strpbrk(p, " \t");
1044 while (isascii(*p) && isspace(*p))
1047 if (svcno < MAXMAPSTACK)
1048 st->s_service[svcno] = NULL;
1050 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1054 /* look up entry in cache */
1055 st = stab(service, ST_SERVICE, ST_FIND);
1056 if (st != NULL && st->s_service[0] != NULL)
1060 while (svcno < MAXMAPSTACK)
1062 maptype[svcno] = st->s_service[svcno];
1063 if (maptype[svcno++] == NULL)
1069 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1071 #if !defined(_USE_SUN_NSSWITCH_)
1072 /* if the service file doesn't work, use an absolute fallback */
1073 # ifdef _USE_DEC_SVC_CONF_
1075 # endif /* _USE_DEC_SVC_CONF_ */
1076 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1077 mapreturn[svcno] = 0;
1079 if (strcmp(service, "aliases") == 0)
1081 maptype[svcno++] = "files";
1082 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1083 maptype[svcno++] = "netinfo";
1084 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
1085 # ifdef AUTO_NIS_ALIASES
1087 maptype[svcno++] = "nisplus";
1088 # endif /* NISPLUS */
1090 maptype[svcno++] = "nis";
1092 # endif /* AUTO_NIS_ALIASES */
1096 if (strcmp(service, "hosts") == 0)
1099 maptype[svcno++] = "dns";
1100 # else /* NAMED_BIND */
1101 # if defined(sun) && !defined(BSD)
1103 maptype[svcno++] = "nis";
1104 # endif /* defined(sun) && !defined(BSD) */
1105 # endif /* NAMED_BIND */
1106 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1107 maptype[svcno++] = "netinfo";
1108 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
1109 maptype[svcno++] = "files";
1115 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1118 ** USERNAME -- return the user id of the logged in user.
1124 ** The login name of the logged in user.
1130 ** The return value is statically allocated.
1136 static char *myname = NULL;
1137 extern char *getlogin();
1138 register struct passwd *pw;
1140 /* cache the result */
1143 myname = getlogin();
1144 if (myname == NULL || myname[0] == '\0')
1146 pw = sm_getpwuid(RealUid);
1148 myname = pw->pw_name;
1152 uid_t uid = RealUid;
1154 if ((pw = sm_getpwnam(myname)) == NULL ||
1155 (uid != 0 && uid != pw->pw_uid))
1157 pw = sm_getpwuid(uid);
1159 myname = pw->pw_name;
1162 if (myname == NULL || myname[0] == '\0')
1164 syserr("554 5.3.0 Who are you?");
1165 myname = "postmaster";
1167 else if (strpbrk(myname, ",;:/|\"\\") != NULL)
1168 myname = addquotes(myname, NULL);
1170 myname = sm_pstrdup_x(myname);
1175 ** TTYPATH -- Get the path of the user's tty
1177 ** Returns the pathname of the user's tty. Returns NULL if
1178 ** the user is not logged in or if s/he has write permission
1185 ** pathname of the user's tty.
1186 ** NULL if not logged in or write permission denied.
1192 ** Return value is in a local buffer.
1202 register char *pathn;
1203 extern char *ttyname();
1204 extern char *getlogin();
1206 /* compute the pathname of the controlling tty */
1207 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
1208 (pathn = ttyname(0)) == NULL)
1214 /* see if we have write permission */
1215 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
1221 /* see if the user is logged in */
1222 if (getlogin() == NULL)
1229 ** CHECKCOMPAT -- check for From and To person compatible.
1231 ** This routine can be supplied on a per-installation basis
1232 ** to determine whether a person is allowed to send a message.
1233 ** This allows restriction of certain types of internet
1234 ** forwarding or registration of users.
1236 ** If the hosts are found to be incompatible, an error
1237 ** message should be given using "usrerr" and an EX_ code
1238 ** should be returned. You can also set to->q_status to
1239 ** a DSN-style status code.
1241 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1242 ** body during the return-to-sender function; this should be done
1243 ** on huge messages. This bit may already be set by the ESMTP
1247 ** to -- the person being sent to.
1253 ** none (unless you include the usrerr stuff)
1258 register ADDRESS *to;
1259 register ENVELOPE *e;
1262 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1263 to->q_paddr, e->e_from.q_paddr);
1266 /* this code is intended as an example only */
1269 s = stab("arpa", ST_MAILER, ST_FIND);
1270 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
1271 to->q_mailer == s->s_mailer)
1273 usrerr("553 No ARPA mail through this machine: see your system administration");
1274 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1275 to->q_status = "5.7.1";
1276 return EX_UNAVAILABLE;
1278 #endif /* EXAMPLE_CODE */
1282 #ifdef SUN_EXTENSIONS
1288 /* Check for large file descriptor */
1289 if (fstat(fileno(stdin), &sbuf) < 0)
1291 if (errno == EOVERFLOW)
1298 #endif /* SUN_EXTENSIONS */
1301 ** INIT_MD -- do machine dependent initializations
1303 ** Systems that have global modes that should be set should do
1304 ** them here rather than in main.
1308 # include <compat.h>
1309 #endif /* _AUX_SOURCE */
1312 # include <shares.h>
1313 #endif /* SHARE_V1 */
1321 setcompat(getcompat() | COMPAT_BSDPROT);
1322 #endif /* _AUX_SOURCE */
1324 #ifdef SUN_EXTENSIONS
1326 #endif /* SUN_EXTENSIONS */
1329 /* keep gethostby*() from stripping the local domain name */
1330 set_domain_trim_off();
1331 #endif /* _CONVEX_SOURCE */
1332 #if defined(__QNX__) && !defined(__QNXNTO__)
1334 ** Due to QNX's network distributed nature, you can target a tcpip
1335 ** stack on a different node in the qnx network; this patch lets
1336 ** this feature work. The __sock_locate() must be done before the
1337 ** environment is clear.
1340 #endif /* __QNX__ */
1341 #if SECUREWARE || defined(_SCO_unix_)
1342 set_auth_parameters(argc, argv);
1346 ** This is required for highest security levels (the kernel
1347 ** won't let it call set*uid() or run setuid binaries without
1348 ** it). It may be necessary on other SECUREWARE systems.
1351 if (getluid() == -1)
1353 # endif /* _SCO_unix_ */
1354 #endif /* SECUREWARE || defined(_SCO_unix_) */
1357 #ifdef VENDOR_DEFAULT
1358 VendorCode = VENDOR_DEFAULT;
1359 #else /* VENDOR_DEFAULT */
1360 VendorCode = VENDOR_BERKELEY;
1361 #endif /* VENDOR_DEFAULT */
1364 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1366 ** Called once, on startup.
1369 ** e -- the global envelope.
1375 ** vendor-dependent.
1379 init_vendor_macros(e)
1380 register ENVELOPE *e;
1384 ** GETLA -- get the current load average
1386 ** This code stolen from la.c.
1392 ** The current load average as an integer.
1398 /* try to guess what style of load average we have */
1399 #define LA_ZERO 1 /* always return load average as zero */
1400 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1401 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1402 #define LA_SUBR 4 /* call getloadavg */
1403 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1404 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1405 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1406 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1407 #define LA_DGUX 9 /* special DGUX implementation */
1408 #define LA_HPUX 10 /* special HPUX implementation */
1409 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1410 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1411 #define LA_DEVSHORT 13 /* read short from a device */
1412 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1413 #define LA_PSET 15 /* Solaris per-processor-set load average */
1414 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1416 /* do guesses based on general OS type */
1418 # define LA_TYPE LA_ZERO
1419 #endif /* ! LA_TYPE */
1422 # if defined(unixpc)
1424 # endif /* defined(unixpc) */
1426 # if defined(__alpha) || defined(IRIX)
1428 # endif /* defined(__alpha) || defined(IRIX) */
1430 #endif /* ! FSHIFT */
1434 #endif /* ! FSHIFT */
1437 # define FSCALE (1 << FSHIFT)
1438 #endif /* ! FSCALE */
1442 # define LA_AVENRUN "avenrun"
1443 # else /* SYSTEM5 */
1444 # define LA_AVENRUN "_avenrun"
1445 # endif /* SYSTEM5 */
1446 #endif /* ! LA_AVENRUN */
1448 /* _PATH_KMEM should be defined in <paths.h> */
1450 # define _PATH_KMEM "/dev/kmem"
1451 #endif /* ! _PATH_KMEM */
1453 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1457 /* _PATH_UNIX should be defined in <paths.h> */
1459 # if defined(SYSTEM5)
1460 # define _PATH_UNIX "/unix"
1461 # else /* defined(SYSTEM5) */
1462 # define _PATH_UNIX "/vmunix"
1463 # endif /* defined(SYSTEM5) */
1464 # endif /* ! _PATH_UNIX */
1468 # else /* _AUX_SOURCE */
1474 # endif /* _AUX_SOURCE */
1475 # define X_AVENRUN 0
1481 static int kmem = -1;
1482 # if LA_TYPE == LA_INT
1484 # else /* LA_TYPE == LA_INT */
1485 # if LA_TYPE == LA_SHORT
1488 # if LA_TYPE == LA_LONGLONG
1489 long long avenrun[3];
1490 # else /* LA_TYPE == LA_LONGLONG */
1492 # endif /* LA_TYPE == LA_LONGLONG */
1493 # endif /* LA_TYPE == LA_SHORT */
1494 # endif /* LA_TYPE == LA_INT */
1495 extern off_t lseek();
1500 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
1501 sizeof(Nl[X_AVENRUN].n_name));
1502 Nl[1].n_name[0] = '\0';
1503 # endif /* _AUX_SOURCE */
1505 # if defined(_AIX3) || defined(_AIX4)
1506 if (knlist(Nl, 1, sizeof(Nl[0])) < 0)
1507 # else /* defined(_AIX3) || defined(_AIX4) */
1508 if (nlist(_PATH_UNIX, Nl) < 0)
1509 # endif /* defined(_AIX3) || defined(_AIX4) */
1512 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
1513 sm_errstring(errno));
1516 if (Nl[X_AVENRUN].n_value == 0)
1519 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1520 _PATH_UNIX, LA_AVENRUN);
1523 # ifdef NAMELISTMASK
1524 Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1525 # endif /* NAMELISTMASK */
1527 kmem = open(_PATH_KMEM, 0, 0);
1531 sm_dprintf("getla: open(/dev/kmem): %s\n",
1532 sm_errstring(errno));
1535 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1536 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1539 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1540 sm_errstring(errno));
1547 sm_dprintf("getla: symbol address = %#lx\n",
1548 (unsigned long) Nl[X_AVENRUN].n_value);
1549 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1550 read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
1554 sm_dprintf("getla: lseek or read: %s\n",
1555 sm_errstring(errno));
1558 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1561 # if LA_TYPE == LA_SHORT
1562 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1564 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1565 # else /* LA_TYPE == LA_SHORT */
1566 # if LA_TYPE == LA_LONGLONG
1567 sm_dprintf("getla: avenrun = %lld", avenrun[0]);
1569 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
1570 # else /* LA_TYPE == LA_LONGLONG */
1571 sm_dprintf("getla: avenrun = %ld", avenrun[0]);
1573 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
1574 # endif /* LA_TYPE == LA_LONGLONG */
1575 # endif /* LA_TYPE == LA_SHORT */
1579 sm_dprintf("getla: %d\n",
1580 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1581 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1582 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1585 sm_dprintf("getla: avenrun = %g", avenrun[0]);
1587 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
1591 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1592 return ((int) (avenrun[0] + 0.5));
1593 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1596 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1598 #if LA_TYPE == LA_READKSYM
1600 # include <sys/ksym.h>
1606 static int kmem = -1;
1608 struct mioc_rksym mirk;
1612 kmem = open("/dev/kmem", 0, 0);
1616 sm_dprintf("getla: open(/dev/kmem): %s\n",
1617 sm_errstring(errno));
1620 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1621 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1624 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1625 sm_errstring(errno));
1631 mirk.mirk_symname = LA_AVENRUN;
1632 mirk.mirk_buf = avenrun;
1633 mirk.mirk_buflen = sizeof(avenrun);
1634 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
1637 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1638 sm_errstring(errno));
1643 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1645 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1649 sm_dprintf("getla: %d\n",
1650 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1651 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1654 #endif /* LA_TYPE == LA_READKSYM */
1656 #if LA_TYPE == LA_DGUX
1658 # include <sys/dg_sys_info.h>
1663 struct dg_sys_info_load_info load_info;
1665 dg_sys_info((long *)&load_info,
1666 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1669 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1671 return ((int) (load_info.one_minute + 0.5));
1674 #endif /* LA_TYPE == LA_DGUX */
1676 #if LA_TYPE == LA_HPUX
1678 /* forward declarations to keep gcc from complaining */
1683 struct pst_diskinfo;
1684 struct pst_processor;
1686 struct pst_swapinfo;
1688 # include <sys/param.h>
1689 # include <sys/pstat.h>
1694 struct pst_dynamic pstd;
1696 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1697 (size_t) 1, 0) == -1)
1701 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1703 return (int) (pstd.psd_avg_1_min + 0.5);
1706 #endif /* LA_TYPE == LA_HPUX */
1708 #if LA_TYPE == LA_SUBR
1715 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1718 sm_dprintf("getla: getloadavg failed: %s",
1719 sm_errstring(errno));
1723 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1724 return ((int) (avenrun[0] + 0.5));
1727 #endif /* LA_TYPE == LA_SUBR */
1729 #if LA_TYPE == LA_MACH
1732 ** This has been tested on NEXTSTEP release 2.1/3.X.
1735 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1736 # include <mach/mach.h>
1737 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1739 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1744 processor_set_t default_set;
1745 kern_return_t error;
1746 unsigned int info_count;
1747 struct processor_set_basic_info info;
1750 error = processor_set_default(host_self(), &default_set);
1751 if (error != KERN_SUCCESS)
1754 sm_dprintf("getla: processor_set_default failed: %s",
1755 sm_errstring(errno));
1758 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1759 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1760 &host, (processor_set_info_t)&info,
1761 &info_count) != KERN_SUCCESS)
1764 sm_dprintf("getla: processor_set_info failed: %s",
1765 sm_errstring(errno));
1769 sm_dprintf("getla: %d\n",
1770 (int) ((info.load_average + (LOAD_SCALE / 2)) /
1772 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1775 #endif /* LA_TYPE == LA_MACH */
1777 #if LA_TYPE == LA_PROCSTR
1778 # if SM_CONF_BROKEN_STRTOD
1779 ERROR: This OS has most likely a broken strtod() implemenentation.
1780 ERROR: The function is required for getla().
1781 ERROR: Check the compilation options _LA_PROCSTR and
1782 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
1783 # endif /* SM_CONF_BROKEN_STRTOD */
1786 ** Read /proc/loadavg for the load average. This is assumed to be
1787 ** in a format like "0.15 0.12 0.06".
1789 ** Initially intended for Linux. This has been in the kernel
1790 ** since at least 0.99.15.
1793 # ifndef _PATH_LOADAVG
1794 # define _PATH_LOADAVG "/proc/loadavg"
1795 # endif /* ! _PATH_LOADAVG */
1801 register int result;
1804 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
1809 sm_dprintf("getla: sm_io_open(%s): %s\n",
1810 _PATH_LOADAVG, sm_errstring(errno));
1813 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
1814 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1818 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1819 result, sm_errstring(errno));
1824 sm_dprintf("getla(): %.2f\n", avenrun);
1826 return ((int) (avenrun + 0.5));
1829 #endif /* LA_TYPE == LA_PROCSTR */
1831 #if LA_TYPE == LA_IRIX6
1833 # include <sys/sysmp.h>
1836 # define CAST_SYSMP(x) (x)
1837 # else /* _UNICOSMP */
1838 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1839 # endif /* _UNICOSMP */
1845 static int kmem = -1;
1850 kmem = open(_PATH_KMEM, 0, 0);
1854 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
1855 sm_errstring(errno));
1858 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1859 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1862 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1863 sm_errstring(errno));
1870 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
1872 read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
1875 sm_dprintf("getla: lseek or read: %s\n",
1876 sm_errstring(errno));
1881 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
1883 sm_dprintf(", %ld, %ld",
1884 (long int) avenrun[1], (long int) avenrun[2]);
1889 sm_dprintf("getla: %d\n",
1890 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1891 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1894 #endif /* LA_TYPE == LA_IRIX6 */
1896 #if LA_TYPE == LA_KSTAT
1903 static kstat_ctl_t *kc = NULL;
1904 static kstat_t *ksp = NULL;
1908 if (kc == NULL) /* if not initialized before */
1913 sm_dprintf("getla: kstat_open(): %s\n",
1914 sm_errstring(errno));
1918 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
1922 sm_dprintf("getla: kstat_lookup(): %s\n",
1923 sm_errstring(errno));
1926 if (kstat_read(kc, ksp, NULL) < 0)
1929 sm_dprintf("getla: kstat_read(): %s\n",
1930 sm_errstring(errno));
1933 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
1934 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
1935 /* kstat_close(kc); /o do not close for fast access */
1939 #endif /* LA_TYPE == LA_KSTAT */
1941 #if LA_TYPE == LA_DEVSHORT
1944 ** Read /dev/table/avenrun for the load average. This should contain
1945 ** three shorts for the 1, 5, and 15 minute loads. We only read the
1946 ** first, since that's all we care about.
1948 ** Intended for SCO OpenServer 5.
1951 # ifndef _PATH_AVENRUN
1952 # define _PATH_AVENRUN "/dev/table/avenrun"
1953 # endif /* ! _PATH_AVENRUN */
1958 static int afd = -1;
1965 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
1969 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
1972 sm_syslog(LOG_ERR, NOQID,
1973 "can't open %s: %s",
1974 _PATH_AVENRUN, sm_errstring(errno));
1979 r = read(afd, &avenrun, sizeof(avenrun));
1980 if (r != sizeof(avenrun))
1982 sm_syslog(LOG_ERR, NOQID,
1983 "can't read %s: %s", _PATH_AVENRUN,
1984 r == -1 ? sm_errstring(errno) : "short read");
1989 sm_dprintf("getla: avenrun = %d\n", avenrun);
1990 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
1992 sm_dprintf("getla: %d\n", loadav);
1996 #endif /* LA_TYPE == LA_DEVSHORT */
1998 #if LA_TYPE == LA_ALPHAOSF
2001 # include <sys/table.h>
2007 struct tbl_loadavg tab;
2009 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
2012 sm_dprintf("getla: table %s\n", sm_errstring(errno));
2017 sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
2020 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
2023 ave = (int) (tab.tl_avenrun.d[2] + 0.5);
2026 sm_dprintf("getla: %d\n", ave);
2031 #endif /* LA_TYPE == LA_ALPHAOSF */
2033 #if LA_TYPE == LA_PSET
2040 if (pset_getloadavg(PS_MYID, avenrun,
2041 sizeof(avenrun) / sizeof(avenrun[0])) < 0)
2044 sm_dprintf("getla: pset_getloadavg failed: %s",
2045 sm_errstring(errno));
2049 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
2050 return ((int) (avenrun[0] + 0.5));
2053 #endif /* LA_TYPE == LA_PSET */
2055 #if LA_TYPE == LA_ZERO
2061 sm_dprintf("getla: ZERO\n");
2065 #endif /* LA_TYPE == LA_ZERO */
2068 * Copyright 1989 Massachusetts Institute of Technology
2070 * Permission to use, copy, modify, distribute, and sell this software and its
2071 * documentation for any purpose is hereby granted without fee, provided that
2072 * the above copyright notice appear in all copies and that both that
2073 * copyright notice and this permission notice appear in supporting
2074 * documentation, and that the name of M.I.T. not be used in advertising or
2075 * publicity pertaining to distribution of the software without specific,
2076 * written prior permission. M.I.T. makes no representations about the
2077 * suitability of this software for any purpose. It is provided "as is"
2078 * without express or implied warranty.
2080 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2081 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2082 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2083 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2084 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2085 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2087 * Authors: Many and varied...
2090 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2092 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2097 # include <apollo/base.h>
2100 int getloadavg( call_data )
2101 caddr_t call_data; /* pointer to (double) return value */
2103 double *avenrun = (double *) call_data;
2108 proc1_$get_loadav(loadav, &st);
2109 *avenrun = loadav[0] / (double) (1 << 16);
2114 ** SM_GETLA -- get the current load average
2123 ** Set CurrentLA to the current load average.
2124 ** Set {load_avg} in GlobalMacros to the current load average.
2132 CurrentLA = getla();
2133 (void) sm_snprintf(labuf, sizeof(labuf), "%d", CurrentLA);
2134 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
2137 ** SHOULDQUEUE -- should this message be queued or sent?
2139 ** Compares the message cost to the load average to decide.
2141 ** Note: Do NOT change this API! It is documented in op.me
2142 ** and theoretically the user can change this function...
2145 ** pri -- the priority of the message in question.
2146 ** ct -- the message creation time (unused, but see above).
2149 ** true -- if this message should be queued up for the
2151 ** false -- if the load is low enough to send this message.
2159 shouldqueue(pri, ct)
2166 #endif /* _FFR_MEMSTAT */
2169 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2173 if (QueueLowMem > 0 &&
2174 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2175 memfree < QueueLowMem)
2178 sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n",
2179 memfree, QueueLowMem);
2182 #endif /* _FFR_MEMSTAT */
2183 if (CurrentLA < QueueLA)
2186 sm_dprintf("false (CurrentLA < QueueLA)\n");
2189 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
2191 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
2196 ** REFUSECONNECTIONS -- decide if connections should be refused
2199 ** e -- the current envelope.
2200 ** dn -- number of daemon.
2201 ** active -- was this daemon actually active?
2204 ** true if incoming SMTP connections should be refused
2206 ** false if we should accept new work.
2209 ** Sets process title when it is rejecting connections.
2213 refuseconnections(e, dn, active)
2218 static time_t lastconn[MAXDAEMONS];
2219 static int conncnt[MAXDAEMONS];
2220 static time_t firstrejtime[MAXDAEMONS];
2221 static time_t nextlogtime[MAXDAEMONS];
2225 #endif /* _FFR_MEMSTAT */
2233 SM_ASSERT(dn < MAXDAEMONS);
2234 if (ConnRateThrottle > 0)
2241 if (now != lastconn[dn])
2246 else if (conncnt[dn]++ > ConnRateThrottle)
2248 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2249 /* sleep to flatten out connection load */
2250 sm_setproctitle(true, e, D_MSG_CRT,
2254 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
2260 else if (now != lastconn[dn])
2266 if (RefuseLowMem > 0 &&
2267 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2268 memfree < RefuseLowMem)
2270 # define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
2271 sm_setproctitle(true, e, R_MSG_LM, Daemons[dn].d_name, memfree);
2273 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM,
2274 Daemons[dn].d_name, memfree);
2277 #endif /* _FFR_MEMSTAT */
2279 limit = (Daemons[dn].d_refuseLA != DPO_NOTSET) ?
2280 Daemons[dn].d_refuseLA : RefuseLA;
2281 if (limit > 0 && CurrentLA >= limit)
2285 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2286 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2287 sm_setproctitle(true, e, R_MSG_LA, Daemons[dn].d_name,
2290 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA,
2291 Daemons[dn].d_name, CurrentLA);
2293 if (firstrejtime[dn] == 0)
2295 firstrejtime[dn] = now;
2296 nextlogtime[dn] = now + RejectLogInterval;
2298 else if (nextlogtime[dn] < now)
2300 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, Daemons[dn].d_name,
2301 pintvl(now - firstrejtime[dn], true));
2302 nextlogtime[dn] = now + RejectLogInterval;
2307 firstrejtime[dn] = 0;
2309 limit = (Daemons[dn].d_delayLA != DPO_NOTSET) ?
2310 Daemons[dn].d_delayLA : DelayLA;
2311 if (limit > 0 && CurrentLA >= limit)
2314 static time_t log_delay = (time_t) 0;
2316 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2317 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2318 /* sleep to flatten out connection load */
2319 sm_setproctitle(true, e, D_MSG_LA, Daemons[dn].d_name,
2321 if (LogLevel > 8 && (now = curtime()) > log_delay)
2323 sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
2324 Daemons[dn].d_name, CurrentLA, limit);
2325 log_delay = now + MIN_DELAY_LOG;
2330 limit = (Daemons[dn].d_maxchildren != DPO_NOTSET) ?
2331 Daemons[dn].d_maxchildren : MaxChildren;
2332 if (limit > 0 && CurChildren >= limit)
2335 if (CurChildren >= limit)
2337 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2338 sm_setproctitle(true, e, R_MSG_CHILD,
2339 Daemons[dn].d_name, CurChildren,
2342 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
2343 Daemons[dn].d_name, CurChildren,
2352 ** SETPROCTITLE -- set process title for ps
2355 ** fmt -- a printf style format string.
2356 ** a, b, c -- possible parameters to fmt.
2362 ** Clobbers argv of our main procedure so ps(1) will
2363 ** display the title.
2366 #define SPT_NONE 0 /* don't use it at all */
2367 #define SPT_REUSEARGV 1 /* cover argv with title information */
2368 #define SPT_BUILTIN 2 /* use libc builtin */
2369 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2370 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2371 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2372 #define SPT_SCO 6 /* write kernel u. area */
2373 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2376 # define SPT_TYPE SPT_REUSEARGV
2377 #endif /* ! SPT_TYPE */
2380 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2382 # if SPT_TYPE == SPT_PSTAT
2383 # include <sys/pstat.h>
2384 # endif /* SPT_TYPE == SPT_PSTAT */
2385 # if SPT_TYPE == SPT_PSSTRINGS
2386 # include <machine/vmparam.h>
2387 # include <sys/exec.h>
2388 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2390 # define SPT_TYPE SPT_REUSEARGV
2391 # else /* ! PS_STRINGS */
2392 # ifndef NKPDE /* FreeBSD 2.0 */
2394 typedef unsigned int *pt_entry_t;
2395 # endif /* ! NKPDE */
2396 # endif /* ! PS_STRINGS */
2397 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2399 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2400 # define SETPROC_STATIC static
2401 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2402 # define SETPROC_STATIC
2403 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2405 # if SPT_TYPE == SPT_SYSMIPS
2406 # include <sys/sysmips.h>
2407 # include <sys/sysnews.h>
2408 # endif /* SPT_TYPE == SPT_SYSMIPS */
2410 # if SPT_TYPE == SPT_SCO
2411 # include <sys/immu.h>
2412 # include <sys/dir.h>
2413 # include <sys/user.h>
2414 # include <sys/fs/s5param.h>
2415 # if PSARGSZ > MAXLINE
2416 # define SPT_BUFSIZE PSARGSZ
2417 # endif /* PSARGSZ > MAXLINE */
2418 # endif /* SPT_TYPE == SPT_SCO */
2420 # ifndef SPT_PADCHAR
2421 # define SPT_PADCHAR ' '
2422 # endif /* ! SPT_PADCHAR */
2424 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2427 # define SPT_BUFSIZE MAXLINE
2428 #endif /* ! SPT_BUFSIZE */
2433 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2434 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2435 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2436 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2437 ** you use this FFR.
2440 # ifdef SPT_ALIGN_SIZE
2441 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2442 # else /* SPT_ALIGN_SIZE */
2443 # define SPT_ALIGN(x, align) (x)
2444 # endif /* SPT_ALIGN_SIZE */
2445 #else /* _FFR_SPT_ALIGN */
2446 # define SPT_ALIGN(x, align) (x)
2447 #endif /* _FFR_SPT_ALIGN */
2450 ** Pointers for setproctitle.
2451 ** This allows "ps" listings to give more useful information.
2454 static char **Argv = NULL; /* pointer to argument vector */
2455 static char *LastArgv = NULL; /* end of argv */
2456 #if SPT_TYPE != SPT_BUILTIN
2457 static void setproctitle __P((const char *, ...));
2458 #endif /* SPT_TYPE != SPT_BUILTIN */
2461 initsetproctitle(argc, argv, envp)
2468 extern char **environ;
2471 ** Move the environment so setproctitle can use the space at
2472 ** the top of memory.
2477 for (i = 0; envp[i] != NULL; i++)
2479 environ = (char **) xalloc(sizeof(char *) * (i + 1));
2480 for (i = 0; envp[i] != NULL; i++)
2481 environ[i] = newstr(envp[i]);
2486 ** Save start and extent of argv for setproctitle.
2492 ** Determine how much space we can use for setproctitle.
2493 ** Use all contiguous argv and envp pointers starting at argv[0]
2498 # ifdef SPT_ALIGN_SIZE
2499 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
2501 # endif /* SPT_ALIGN_SIZE */
2502 # endif /* _FFR_SPT_ALIGN */
2504 for (i = 0; i < argc; i++)
2506 if (i == 0 || LastArgv + 1 == argv[i])
2507 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
2509 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
2511 if (LastArgv + 1 == envp[i])
2512 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
2516 #if SPT_TYPE != SPT_BUILTIN
2521 setproctitle(const char *fmt, ...)
2522 # else /* __STDC__ */
2523 setproctitle(fmt, va_alist)
2526 # endif /* __STDC__ */
2528 # if SPT_TYPE != SPT_NONE
2531 SETPROC_STATIC char buf[SPT_BUFSIZE];
2533 # if SPT_TYPE == SPT_PSTAT
2535 # endif /* SPT_TYPE == SPT_PSTAT */
2536 # if SPT_TYPE == SPT_SCO
2539 static int kmem = -1;
2540 static pid_t kmempid = -1;
2542 # endif /* SPT_TYPE == SPT_SCO */
2546 /* print sendmail: heading for grep */
2547 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
2550 /* print the argument string */
2551 SM_VA_START(ap, fmt);
2552 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
2555 i = (int) strlen(buf);
2559 # if SPT_TYPE == SPT_PSTAT
2560 pst.pst_command = buf;
2561 pstat(PSTAT_SETCMD, pst, i, 0, 0);
2562 # endif /* SPT_TYPE == SPT_PSTAT */
2563 # if SPT_TYPE == SPT_PSSTRINGS
2564 PS_STRINGS->ps_nargvstr = 1;
2565 PS_STRINGS->ps_argvstr = buf;
2566 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2567 # if SPT_TYPE == SPT_SYSMIPS
2568 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
2569 # endif /* SPT_TYPE == SPT_SYSMIPS */
2570 # if SPT_TYPE == SPT_SCO
2571 if (kmem < 0 || kmempid != CurrentPid)
2575 kmem = open(_PATH_KMEM, O_RDWR, 0);
2578 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
2579 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
2585 kmempid = CurrentPid;
2587 buf[PSARGSZ - 1] = '\0';
2588 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
2589 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
2590 (void) write(kmem, buf, PSARGSZ);
2591 # endif /* SPT_TYPE == SPT_SCO */
2592 # if SPT_TYPE == SPT_REUSEARGV
2593 if (LastArgv == NULL)
2596 if (i > LastArgv - Argv[0] - 2)
2598 i = LastArgv - Argv[0] - 2;
2601 (void) sm_strlcpy(Argv[0], buf, i + 1);
2603 while (p < LastArgv)
2606 # endif /* SPT_TYPE == SPT_REUSEARGV */
2607 # if SPT_TYPE == SPT_CHANGEARGV
2610 # endif /* SPT_TYPE == SPT_CHANGEARGV */
2611 # endif /* SPT_TYPE != SPT_NONE */
2614 #endif /* SPT_TYPE != SPT_BUILTIN */
2616 ** SM_SETPROCTITLE -- set process task and set process title for ps
2618 ** Possibly set process status and call setproctitle() to
2619 ** change the ps display.
2622 ** status -- whether or not to store as process status
2623 ** e -- the current envelope.
2624 ** fmt -- a printf style format string.
2625 ** a, b, c -- possible parameters to fmt.
2634 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
2635 #else /* __STDC__ */
2636 sm_setproctitle(status, e, fmt, va_alist)
2641 #endif /* __STDC__ */
2643 char buf[SPT_BUFSIZE];
2646 /* print the argument string */
2647 SM_VA_START(ap, fmt);
2648 (void) sm_vsnprintf(buf, sizeof(buf), fmt, ap);
2652 proc_list_set(CurrentPid, buf);
2654 if (ProcTitlePrefix != NULL)
2656 char prefix[SPT_BUFSIZE];
2658 expand(ProcTitlePrefix, prefix, sizeof(prefix), e);
2659 setproctitle("%s: %s", prefix, buf);
2662 setproctitle("%s", buf);
2665 ** WAITFOR -- wait for a particular process id.
2668 ** pid -- process id to wait for.
2672 ** -1 if pid never shows up.
2690 proc_list_drop(i, st, NULL);
2691 } while ((i >= 0 || errno == EINTR) && i != pid);
2700 ** status -- pointer to status (return value)
2712 # else /* WAITUNION */
2714 # endif /* WAITUNION */
2716 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2718 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2720 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2721 savesig = sm_releasesignal(SIGCHLD);
2722 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2724 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2726 sm_blocksignal(SIGCHLD);
2727 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2729 *status = st.w_status;
2730 # else /* WAITUNION */
2732 # endif /* WAITUNION */
2736 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2739 ** sig -- the signal that got us here (unused).
2745 ** Picks up extant zombies.
2746 ** Control socket exits may restart/shutdown daemon.
2748 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2749 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2758 int save_errno = errno;
2766 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
2771 # else /* HASWAITPID */
2775 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
2777 st = status.w_status;
2778 # else /* WNOHANG */
2782 ** Catch one zombie -- we will be re-invoked (we hope) if there
2783 ** are more. Unreliable signals probably break this, but this
2784 ** is the "old system" situation -- waitpid or wait3 are to be
2785 ** strongly preferred.
2788 if ((pid = wait(&status)) > 0)
2791 # endif /* WNOHANG */
2792 # endif /* HASWAITPID */
2793 /* Drop PID and check if it was a control socket child */
2794 proc_list_drop(pid, st, NULL);
2796 FIX_SYSV_SIGNAL(sig, reapchild);
2798 return SIGFUNC_RETURN;
2801 ** GETDTSIZE -- return number of file descriptors
2803 ** Only on non-BSD systems
2809 ** size of file descriptor table
2816 # include <sys/resource.h>
2817 #endif /* SOLARIS */
2822 # ifdef RLIMIT_NOFILE
2825 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
2827 # endif /* RLIMIT_NOFILE */
2829 # if HASGETDTABLESIZE
2830 return getdtablesize();
2831 # else /* HASGETDTABLESIZE */
2832 # ifdef _SC_OPEN_MAX
2833 return sysconf(_SC_OPEN_MAX);
2834 # else /* _SC_OPEN_MAX */
2836 # endif /* _SC_OPEN_MAX */
2837 # endif /* HASGETDTABLESIZE */
2840 ** UNAME -- get the UUCP name of this system.
2847 struct utsname *name;
2852 name->nodename[0] = '\0';
2854 /* try /etc/whoami -- one line with the node name */
2855 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
2856 SM_IO_RDONLY, NULL)) != NULL)
2858 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
2860 (void) sm_io_close(file, SM_TIME_DEFAULT);
2861 n = strchr(name->nodename, '\n');
2864 if (name->nodename[0] != '\0')
2868 /* try /usr/include/whoami.h -- has a #define somewhere */
2869 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
2870 "/usr/include/whoami.h", SM_IO_RDONLY, NULL))
2875 while (sm_io_fgets(file, SM_TIME_DEFAULT,
2876 buf, sizeof(buf)) >= 0)
2878 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
2879 NODE_LENGTH, name->nodename) > 0)
2882 (void) sm_io_close(file, SM_TIME_DEFAULT);
2883 if (name->nodename[0] != '\0')
2889 #endif /* !HASUNAME */
2891 ** INITGROUPS -- initialize groups
2893 ** Stub implementation for System V style systems
2898 initgroups(name, basegid)
2905 #endif /* !HASINITGROUPS */
2907 ** SETGROUPS -- set group list
2909 ** Stub implementation for systems that don't have group lists
2915 setgroups(ngroups, grouplist)
2917 GIDSET_T grouplist[];
2922 #endif /* ! NGROUPS_MAX */
2924 ** SETSID -- set session id (for non-POSIX systems)
2935 fd = open("/dev/tty", O_RDWR, 0);
2938 (void) ioctl(fd, TIOCNOTTY, (char *) 0);
2941 # endif /* TIOCNOTTY */
2944 # else /* SYS5SETPGRP */
2945 return setpgid(0, CurrentPid);
2946 # endif /* SYS5SETPGRP */
2949 #endif /* !HASSETSID */
2951 ** FSYNC -- dummy fsync
2960 return fcntl(fd, F_SETFL, O_SYNC);
2962 /* nothing we can do */
2964 # endif /* O_SYNC */
2967 #endif /* NEEDFSYNC */
2969 ** DGUX_INET_ADDR -- inet_addr for DG/UX
2971 ** Data General DG/UX version of inet_addr returns a struct in_addr
2972 ** instead of a long. This patches things. Only needed on versions
2981 dgux_inet_addr(host)
2984 struct in_addr haddr;
2986 haddr = inet_addr(host);
2987 return haddr.s_addr;
2990 #endif /* DGUX_5_4_2 */
2992 ** GETOPT -- for old systems or systems with bogus implementations
2998 * Copyright (c) 1985 Regents of the University of California.
2999 * All rights reserved. The Berkeley software License Agreement
3000 * specifies the terms and conditions for redistribution.
3005 ** this version hacked to add `atend' flag to allow state machine
3006 ** to reset if invoked by the program to scan args for a 2nd time
3009 # if defined(LIBC_SCCS) && !defined(lint)
3010 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
3011 # endif /* defined(LIBC_SCCS) && !defined(lint) */
3014 ** get option letter from argument vector
3016 # ifdef _CONVEX_SOURCE
3017 extern int optind, opterr, optopt;
3018 extern char *optarg;
3019 # else /* _CONVEX_SOURCE */
3020 int opterr = 1; /* if error message should be printed */
3021 int optind = 1; /* index into parent argv vector */
3022 int optopt = 0; /* character checked for validity */
3023 char *optarg = NULL; /* argument associated with option */
3024 # endif /* _CONVEX_SOURCE */
3026 # define BADCH (int)'?'
3028 # define tell(s) if (opterr) \
3029 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
3030 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
3031 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
3032 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
3036 getopt(nargc,nargv,ostr)
3041 static char *place = EMSG; /* option letter processing */
3042 static char atend = 0;
3043 register char *oli = NULL; /* option letter list index */
3049 if(!*place) { /* update scanning pointer */
3050 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
3054 if (*place == '-') { /* found "--" */
3059 } /* option letter okay? */
3060 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
3061 if (!*place) ++optind;
3062 tell(": illegal option -- ");
3064 if (oli && *++oli != ':') { /* don't need argument */
3066 if (!*place) ++optind;
3068 else { /* need an argument */
3069 if (*place) optarg = place; /* no white space */
3070 else if (nargc <= ++optind) { /* no arg */
3072 tell(": option requires an argument -- ");
3074 else optarg = nargv[optind]; /* white space */
3078 return optopt; /* dump back option letter */
3081 #endif /* !SM_CONF_GETOPT */
3083 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3086 ** user -- the name of the user we are checking.
3087 ** shell -- the user's shell from /etc/passwd
3090 ** true -- if it is ok to use this for unrestricted access.
3091 ** false -- if the shell is restricted.
3094 #if !HASGETUSERSHELL
3096 # ifndef _PATH_SHELLS
3097 # define _PATH_SHELLS "/etc/shells"
3098 # endif /* ! _PATH_SHELLS */
3100 # if defined(_AIX3) || defined(_AIX4)
3101 # include <userconf.h>
3103 # include <userpw.h>
3104 # endif /* _AIX4 >= 40200 */
3105 # include <usersec.h>
3106 # endif /* defined(_AIX3) || defined(_AIX4) */
3108 static char *DefaultUserShells[] =
3110 "/bin/sh", /* standard shell */
3115 "/bin/csh", /* C shell */
3120 "/usr/bin/rsh", /* restricted Bourne shell */
3121 "/usr/bin/ksh", /* Korn shell */
3122 "/usr/bin/rksh", /* restricted Korn shell */
3124 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3125 "/usr/bin/posix/sh",
3127 "/bin/rsh", /* restricted Bourne shell */
3128 "/bin/ksh", /* Korn shell */
3129 "/bin/rksh", /* restricted Korn shell */
3131 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3135 # endif /* __hpux */
3136 # if defined(_AIX3) || defined(_AIX4)
3137 "/bin/ksh", /* Korn shell */
3139 "/bin/tsh", /* trusted shell */
3141 "/bin/bsh", /* Bourne shell */
3143 # endif /* defined(_AIX3) || defined(_AIX4) */
3144 # if defined(__svr4__) || defined(__svr5__)
3145 "/bin/ksh", /* Korn shell */
3147 # endif /* defined(__svr4__) || defined(__svr5__) */
3149 "/sbin/sh", /* SGI's shells really live in /sbin */
3151 "/sbin/bsh", /* classic Bourne shell */
3154 "/sbin/csh", /* standard csh */
3157 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3160 "/bin/ksh", /* Korn shell */
3163 "/sbin/tcsh", /* Extended csh */
3170 #endif /* !HASGETUSERSHELL */
3172 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3175 usershellok(user, shell)
3179 # if HASGETUSERSHELL
3181 extern char *getusershell();
3183 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3188 while ((p = getusershell()) != NULL)
3189 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
3193 # else /* HASGETUSERSHELL */
3196 # endif /* USEGETCONFATTR */
3197 register SM_FILE_T *shellf;
3200 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3206 ** Naturally IBM has a "better" idea.....
3208 ** What a crock. This interface isn't documented, it is
3209 ** considered part of the security library (-ls), and it
3210 ** only works if you are running as root (since the list
3211 ** of valid shells is obviously a source of great concern).
3212 ** I recommend that you do NOT define USEGETCONFATTR,
3213 ** especially since you are going to have to set up an
3214 ** /etc/shells anyhow to handle the cases where getconfattr
3218 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
3222 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
3228 # endif /* USEGETCONFATTR */
3230 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
3231 SM_IO_RDONLY, NULL);
3234 /* no /etc/shells; see if it is one of the std shells */
3237 if (errno != ENOENT && LogLevel > 3)
3238 sm_syslog(LOG_ERR, NOQID,
3239 "usershellok: cannot open %s: %s",
3240 _PATH_SHELLS, sm_errstring(errno));
3242 for (d = DefaultUserShells; *d != NULL; d++)
3244 if (strcmp(shell, *d) == 0)
3250 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof(buf)) >= 0)
3252 register char *p, *q;
3255 while (*p != '\0' && *p != '#' && *p != '/')
3257 if (*p == '#' || *p == '\0')
3260 while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
3263 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
3265 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3269 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3271 # endif /* HASGETUSERSHELL */
3274 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3276 ** Only implemented if you have statfs.
3279 ** dir -- the directory in question.
3280 ** bsize -- a variable into which the filesystem
3281 ** block size is stored.
3284 ** The number of blocks free on the queue filesystem.
3285 ** -1 if the statfs call fails.
3288 ** Puts the filesystem block size into bsize.
3292 # define SFS_NONE 0 /* no statfs implementation */
3293 # define SFS_USTAT 1 /* use ustat */
3294 # define SFS_4ARGS 2 /* use four-argument statfs call */
3295 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3296 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3297 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3298 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3301 # define SFS_TYPE SFS_NONE
3302 # endif /* ! SFS_TYPE */
3304 # if SFS_TYPE == SFS_USTAT
3306 # endif /* SFS_TYPE == SFS_USTAT */
3307 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3308 # include <sys/statfs.h>
3309 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
3310 # if SFS_TYPE == SFS_VFS
3311 # include <sys/vfs.h>
3312 # endif /* SFS_TYPE == SFS_VFS */
3313 # if SFS_TYPE == SFS_MOUNT
3314 # include <sys/mount.h>
3315 # endif /* SFS_TYPE == SFS_MOUNT */
3316 # if SFS_TYPE == SFS_STATVFS
3317 # include <sys/statvfs.h>
3318 # endif /* SFS_TYPE == SFS_STATVFS */
3321 freediskspace(dir, bsize)
3325 # if SFS_TYPE == SFS_NONE
3329 /* assume free space is plentiful */
3330 return (long) LONG_MAX;
3331 # else /* SFS_TYPE == SFS_NONE */
3332 # if SFS_TYPE == SFS_USTAT
3334 struct stat statbuf;
3335 # define FSBLOCKSIZE DEV_BSIZE
3336 # define SFS_BAVAIL f_tfree
3337 # else /* SFS_TYPE == SFS_USTAT */
3338 # if defined(ultrix)
3340 # define SFS_BAVAIL fd_bfreen
3341 # define FSBLOCKSIZE 1024L
3342 # else /* defined(ultrix) */
3343 # if SFS_TYPE == SFS_STATVFS
3345 # define FSBLOCKSIZE fs.f_frsize
3346 # else /* SFS_TYPE == SFS_STATVFS */
3348 # define FSBLOCKSIZE fs.f_bsize
3349 # endif /* SFS_TYPE == SFS_STATVFS */
3350 # endif /* defined(ultrix) */
3351 # endif /* SFS_TYPE == SFS_USTAT */
3353 # define SFS_BAVAIL f_bavail
3354 # endif /* ! SFS_BAVAIL */
3356 # if SFS_TYPE == SFS_USTAT
3357 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
3358 # else /* SFS_TYPE == SFS_USTAT */
3359 # if SFS_TYPE == SFS_4ARGS
3360 if (statfs(dir, &fs, sizeof(fs), 0) == 0)
3361 # else /* SFS_TYPE == SFS_4ARGS */
3362 # if SFS_TYPE == SFS_STATVFS
3363 if (statvfs(dir, &fs) == 0)
3364 # else /* SFS_TYPE == SFS_STATVFS */
3365 # if defined(ultrix)
3366 if (statfs(dir, &fs) > 0)
3367 # else /* defined(ultrix) */
3368 if (statfs(dir, &fs) == 0)
3369 # endif /* defined(ultrix) */
3370 # endif /* SFS_TYPE == SFS_STATVFS */
3371 # endif /* SFS_TYPE == SFS_4ARGS */
3372 # endif /* SFS_TYPE == SFS_USTAT */
3375 *bsize = FSBLOCKSIZE;
3376 if (fs.SFS_BAVAIL <= 0)
3378 else if (fs.SFS_BAVAIL > LONG_MAX)
3379 return (long) LONG_MAX;
3381 return (long) fs.SFS_BAVAIL;
3384 # endif /* SFS_TYPE == SFS_NONE */
3387 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3390 ** msize -- the size to check against. If zero, we don't yet
3391 ** know how big the message will be, so just check for
3392 ** a "reasonable" amount.
3393 ** e -- envelope, or NULL -- controls logging
3396 ** true if in every queue group there is at least one
3397 ** queue directory whose file system contains enough free space.
3401 ** If there is not enough disk space and e != NULL
3402 ** then sm_syslog is called.
3406 enoughdiskspace(msize, e)
3415 #endif /* _FFR_TESTS */
3416 if (MinBlocksFree <= 0 && msize <= 0)
3419 sm_dprintf("enoughdiskspace: no threshold\n");
3424 for (i = 0; i < NumQueue; ++i)
3426 if (pickqdir(Queue[i], msize, e) < 0)
3432 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3434 ** This looks at an errno value and tells if this is likely to
3435 ** go away if retried later.
3438 ** err -- the errno code to classify.
3441 ** true if this is probably transient.
3451 case EIO: /* I/O error */
3452 case ENXIO: /* Device not configured */
3453 case EAGAIN: /* Resource temporarily unavailable */
3454 case ENOMEM: /* Cannot allocate memory */
3455 case ENODEV: /* Operation not supported by device */
3456 case ENFILE: /* Too many open files in system */
3457 case EMFILE: /* Too many open files */
3458 case ENOSPC: /* No space left on device */
3459 case ETIMEDOUT: /* Connection timed out */
3461 case ESTALE: /* Stale NFS file handle */
3464 case ENETDOWN: /* Network is down */
3465 #endif /* ENETDOWN */
3467 case ENETUNREACH: /* Network is unreachable */
3468 #endif /* ENETUNREACH */
3470 case ENETRESET: /* Network dropped connection on reset */
3471 #endif /* ENETRESET */
3473 case ECONNABORTED: /* Software caused connection abort */
3474 #endif /* ECONNABORTED */
3476 case ECONNRESET: /* Connection reset by peer */
3477 #endif /* ECONNRESET */
3479 case ENOBUFS: /* No buffer space available */
3480 #endif /* ENOBUFS */
3482 case ESHUTDOWN: /* Can't send after socket shutdown */
3483 #endif /* ESHUTDOWN */
3485 case ECONNREFUSED: /* Connection refused */
3486 #endif /* ECONNREFUSED */
3488 case EHOSTDOWN: /* Host is down */
3489 #endif /* EHOSTDOWN */
3491 case EHOSTUNREACH: /* No route to host */
3492 #endif /* EHOSTUNREACH */
3494 case EDQUOT: /* Disc quota exceeded */
3497 case EPROCLIM: /* Too many processes */
3498 #endif /* EPROCLIM */
3500 case EUSERS: /* Too many users */
3503 case EDEADLK: /* Resource deadlock avoided */
3504 #endif /* EDEADLK */
3506 case EISCONN: /* Socket already connected */
3507 #endif /* EISCONN */
3509 case EINPROGRESS: /* Operation now in progress */
3510 #endif /* EINPROGRESS */
3512 case EALREADY: /* Operation already in progress */
3513 #endif /* EALREADY */
3515 case EADDRINUSE: /* Address already in use */
3516 #endif /* EADDRINUSE */
3517 #ifdef EADDRNOTAVAIL
3518 case EADDRNOTAVAIL: /* Can't assign requested address */
3519 #endif /* EADDRNOTAVAIL */
3521 case ETXTBSY: /* (Apollo) file locked */
3522 #endif /* ETXTBSY */
3523 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3524 case ENOSR: /* Out of streams resources */
3525 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
3527 case ENOLCK: /* No locks available */
3529 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
3533 /* nope, must be permanent */
3537 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3540 ** fd -- the file descriptor of the file.
3541 ** filename -- the file name (for error messages).
3542 ** ext -- the filename extension.
3543 ** type -- type of the lock. Bits can be:
3544 ** LOCK_EX -- exclusive lock.
3545 ** LOCK_NB -- non-blocking.
3546 ** LOCK_UN -- unlock.
3549 ** true if the lock was acquired.
3554 lockfile(fd, filename, ext, type)
3569 memset(&lfd, '\0', sizeof(lfd));
3570 if (bitset(LOCK_UN, type))
3571 lfd.l_type = F_UNLCK;
3572 else if (bitset(LOCK_EX, type))
3573 lfd.l_type = F_WRLCK;
3575 lfd.l_type = F_RDLCK;
3577 if (bitset(LOCK_NB, type))
3583 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
3584 filename, ext, action, lfd.l_type);
3586 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
3591 sm_dprintf("SUCCESS\n");
3597 sm_dprintf("(%s) ", sm_errstring(save_errno));
3600 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3601 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3602 ** as type "tmp" (that is, served from swap space), the
3603 ** previous fcntl will fail with "Invalid argument" errors.
3604 ** Since this is fairly common during testing, we will assume
3605 ** that this indicates that the lock is successfully grabbed.
3608 if (save_errno == EINVAL)
3611 sm_dprintf("SUCCESS\n");
3615 if (!bitset(LOCK_NB, type) ||
3616 (save_errno != EACCES && save_errno != EAGAIN))
3618 int omode = fcntl(fd, F_GETFL, 0);
3619 uid_t euid = geteuid();
3622 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%ld)",
3623 filename, ext, fd, type, omode, (long) euid);
3624 dumpfd(fd, true, true);
3626 # else /* !HASFLOCK */
3631 sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
3633 while ((i = flock(fd, type)) < 0 && errno == EINTR)
3638 sm_dprintf("SUCCESS\n");
3644 sm_dprintf("(%s) ", sm_errstring(save_errno));
3646 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
3648 int omode = fcntl(fd, F_GETFL, 0);
3649 uid_t euid = geteuid();
3652 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%ld)",
3653 filename, ext, fd, type, omode, (long) euid);
3654 dumpfd(fd, true, true);
3656 # endif /* !HASFLOCK */
3658 sm_dprintf("FAIL\n");
3663 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3665 ** Unfortunately, given that we can't predict other systems on which
3666 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3667 ** almost always that this is unsafe.
3669 ** Note also that many operating systems have non-compliant
3670 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3671 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3672 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3673 ** no non-root process can give away the file. However, vendors
3674 ** don't take NFS into account, so a comfortable value of
3675 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3677 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3678 ** even on files where chown is not restricted. Many systems get
3679 ** this wrong on NFS-based filesystems (that is, they say that chown
3680 ** is restricted [safe] on NFS filesystems where it may not be, since
3681 ** other systems can access the same filesystem and do file giveaway;
3682 ** only the NFS server knows for sure!) Hence, it is important to
3683 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3684 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3685 ** NFS-based filesystem to ensure that you can get meaningful results.
3686 ** If in doubt, assume unsafe!
3688 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3689 ** condition indicating whether the return from pathconf indicates
3690 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3691 ** even any agreement about whether a zero return means that a file
3692 ** is or is not safe). It defaults to "> 0".
3694 ** If the parent directory is safe (writable only by owner back
3695 ** to the root) then we can relax slightly and trust fpathconf
3696 ** in more circumstances. This is really a crock -- if this is an
3697 ** NFS mounted filesystem then we really know nothing about the
3698 ** underlying implementation. However, most systems pessimize and
3699 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3700 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3701 ** us into a possible problem only on systems that have a broken
3702 ** pathconf implementation and which are also poorly configured
3703 ** (have :include: files in group- or world-writable directories).
3706 ** fd -- the file descriptor to check.
3707 ** safedir -- set if the parent directory is safe.
3710 ** true -- if the chown(2) operation is "safe" -- that is,
3711 ** only root can chown the file to an arbitrary user.
3712 ** false -- if an arbitrary user can give away a file.
3715 #ifndef IS_SAFE_CHOWN
3716 # define IS_SAFE_CHOWN > 0
3717 #endif /* ! IS_SAFE_CHOWN */
3720 chownsafe(fd, safedir)
3724 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3725 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3728 /* give the system administrator a chance to override */
3729 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
3733 ** Some systems (e.g., SunOS) seem to have the call and the
3734 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3735 ** the call. This heuristic checks for that.
3739 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
3740 # if SAFENFSPATHCONF
3741 return errno == 0 && rval IS_SAFE_CHOWN;
3742 # else /* SAFENFSPATHCONF */
3743 return safedir && errno == 0 && rval IS_SAFE_CHOWN;
3744 # endif /* SAFENFSPATHCONF */
3745 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3746 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
3747 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3750 ** RESETLIMITS -- reset system controlled resource limits
3752 ** This is to avoid denial-of-service attacks
3762 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3763 # include <sm/time.h>
3764 # endif /* RLIMIT_NEEDS_SYS_TIME_H */
3765 # include <sys/resource.h>
3766 #endif /* HASSETRLIMIT */
3774 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
3775 (void) setrlimit(RLIMIT_CPU, &lim);
3776 (void) setrlimit(RLIMIT_FSIZE, &lim);
3777 # ifdef RLIMIT_NOFILE
3778 lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
3779 (void) setrlimit(RLIMIT_NOFILE, &lim);
3780 # endif /* RLIMIT_NOFILE */
3781 #else /* HASSETRLIMIT */
3783 (void) ulimit(2, 0x3fffff);
3784 (void) ulimit(4, FD_SETSIZE);
3785 # endif /* HASULIMIT */
3786 #endif /* HASSETRLIMIT */
3790 ** SETVENDOR -- process vendor code from V configuration line
3793 ** vendor -- string representation of vendor.
3797 ** false -- if vendor code could not be processed.
3800 ** It is reasonable to set mode flags here to tweak
3801 ** processing in other parts of the code if necessary.
3802 ** For example, if you are a vendor that uses $%y to
3803 ** indicate YP lookups, you could enable that here.
3810 if (sm_strcasecmp(vendor, "Berkeley") == 0)
3812 VendorCode = VENDOR_BERKELEY;
3816 /* add vendor extensions here */
3818 #ifdef SUN_EXTENSIONS
3819 if (sm_strcasecmp(vendor, "Sun") == 0)
3821 VendorCode = VENDOR_SUN;
3824 #endif /* SUN_EXTENSIONS */
3826 if (sm_strcasecmp(vendor, "Digital") == 0)
3828 VendorCode = VENDOR_DEC;
3833 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3834 if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
3836 VendorCode = VENDOR_CODE;
3839 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3844 ** GETVENDOR -- return vendor name based on vendor code
3847 ** vendorcode -- numeric representation of vendor.
3850 ** string containing vendor name.
3854 getvendor(vendorcode)
3857 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3859 ** Can't have the same switch case twice so need to
3860 ** handle VENDOR_CODE outside of switch. It might
3861 ** match one of the existing VENDOR_* codes.
3864 if (vendorcode == VENDOR_CODE)
3866 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3870 case VENDOR_BERKELEY:
3882 case VENDOR_SENDMAIL:
3890 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3892 ** Vendor_pre_defaults is called before reading the configuration
3893 ** file; vendor_post_defaults is called immediately after.
3896 ** e -- the global environment to initialize.
3903 int DefShareUid; /* default share uid to run as -- unused??? */
3904 #endif /* SHARE_V1 */
3907 vendor_pre_defaults(e)
3911 /* OTHERUID is defined in shares.h, do not be alarmed */
3912 DefShareUid = OTHERUID;
3913 #endif /* SHARE_V1 */
3914 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3915 sun_pre_defaults(e);
3916 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3919 ** stupid domain/os can't even open
3920 ** /etc/mail/sendmail.cf without this
3923 sm_setuserenv("ISP", NULL);
3924 sm_setuserenv("SYSTYPE", NULL);
3930 vendor_post_defaults(e)
3934 /* Makes sure the SOCK environment variable remains */
3935 sm_setuserenv("SOCK", NULL);
3936 #endif /* __QNX__ */
3937 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3938 sun_post_defaults(e);
3939 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3942 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
3946 vendor_daemon_setup(e)
3950 (void) setlogin(RunAsUserName);
3951 #endif /* HASSETLOGIN */
3953 if (getluid() != -1)
3955 usrerr("Daemon cannot have LUID");
3956 finis(false, true, EX_USAGE);
3958 #endif /* SECUREWARE */
3961 ** VENDOR_SET_UID -- do setup for setting a user id
3963 ** This is called when we are still root.
3966 ** uid -- the uid we are about to become.
3977 ** We need to setup the share groups (lnodes)
3978 ** and add auditing information (luid's)
3979 ** before we loose our ``root''ness.
3982 if (setupshares(uid, syserr) != 0)
3983 syserr("Unable to set up shares");
3984 #endif /* SHARE_V1 */
3986 (void) setup_secure(uid);
3987 #endif /* SECUREWARE */
3990 ** VALIDATE_CONNECTION -- check connection for rationality
3992 ** If the connection is rejected, this routine should log an
3993 ** appropriate message -- but should never issue any SMTP protocol.
3996 ** sap -- a pointer to a SOCKADDR naming the peer.
3997 ** hostname -- the name corresponding to sap.
3998 ** e -- the current envelope.
4001 ** error message from rejection.
4002 ** NULL if not rejected.
4008 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
4009 int allow_severity = LOG_INFO;
4010 int deny_severity = LOG_NOTICE;
4011 #endif /* TCPWRAPPERS */
4014 validate_connection(sap, hostname, e)
4022 extern int hosts_ctl();
4023 #endif /* TCPWRAPPERS */
4026 sm_dprintf("validate_connection(%s, %s)\n",
4027 hostname, anynet_ntoa(sap));
4029 connection_rate_check(sap, e);
4030 if (rscheck("check_relay", hostname, anynet_ntoa(sap), e,
4031 RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID, NULL, NULL) != EX_OK)
4033 static char reject[BUFSIZ*2];
4034 extern char MsgBuf[];
4037 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
4039 if (strlen(MsgBuf) >= 3)
4040 (void) sm_strlcpy(reject, MsgBuf, sizeof(reject));
4042 (void) sm_strlcpy(reject, "Access denied", sizeof(reject));
4048 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
4052 addr = anynet_ntoa(sap);
4055 /* TCP/Wrappers don't want the IPv6: protocol label */
4056 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
4058 # endif /* NETINET6 */
4060 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
4063 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4065 sm_syslog(LOG_NOTICE, e->e_id,
4066 "tcpwrappers (%s, %s) rejection",
4068 return "Access denied";
4070 #endif /* TCPWRAPPERS */
4072 sm_dprintf(" ... validate_connection: OK\n");
4077 ** STRTOL -- convert string to long integer
4079 ** For systems that don't have it in the C library.
4081 ** This is taken verbatim from the 4.4-Lite C library.
4086 # if defined(LIBC_SCCS) && !defined(lint)
4087 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4088 # endif /* defined(LIBC_SCCS) && !defined(lint) */
4091 ** Convert a string to a long integer.
4093 ** Ignores `locale' stuff. Assumes that the upper and lower case
4094 ** alphabets and digits are each contiguous.
4098 strtol(nptr, endptr, base)
4103 register const char *s = nptr;
4104 register unsigned long acc;
4106 register unsigned long cutoff;
4107 register int neg = 0, any, cutlim;
4110 ** Skip white space and pick up leading +/- sign if any.
4111 ** If base is 0, allow 0x for hex and 0 for octal, else
4112 ** assume decimal; if base is already 16, allow 0x.
4116 } while (isascii(c) && isspace(c));
4120 } else if (c == '+')
4122 if ((base == 0 || base == 16) &&
4123 c == '0' && (*s == 'x' || *s == 'X')) {
4129 base = c == '0' ? 8 : 10;
4132 ** Compute the cutoff value between legal numbers and illegal
4133 ** numbers. That is the largest legal value, divided by the
4134 ** base. An input number that is greater than this value, if
4135 ** followed by a legal input character, is too big. One that
4136 ** is equal to this value may be valid or not; the limit
4137 ** between valid and invalid numbers is then based on the last
4138 ** digit. For instance, if the range for longs is
4139 ** [-2147483648..2147483647] and the input base is 10,
4140 ** cutoff will be set to 214748364 and cutlim to either
4141 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4142 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4143 ** the number is too big, and we will return a range error.
4145 ** Set any if any `digits' consumed; make it negative to indicate
4148 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
4149 cutlim = cutoff % (unsigned long) base;
4150 cutoff /= (unsigned long) base;
4151 for (acc = 0, any = 0;; c = *s++) {
4152 if (isascii(c) && isdigit(c))
4154 else if (isascii(c) && isalpha(c))
4155 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
4160 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
4169 acc = neg ? LONG_MIN : LONG_MAX;
4174 *endptr = (char *)(any ? s - 1 : nptr);
4178 #endif /* NEEDSTRTOL */
4180 ** STRSTR -- find first substring in string
4183 ** big -- the big (full) string.
4184 ** little -- the little (sub) string.
4187 ** A pointer to the first instance of little in big.
4188 ** big if little is the null string.
4189 ** NULL if little is not contained in big.
4199 register char *p = big;
4202 if (*little == '\0')
4206 while ((p = strchr(p, *little)) != NULL)
4208 if (strncmp(p, little, l) == 0)
4215 #endif /* NEEDSTRSTR */
4217 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4219 ** Some operating systems have weird problems with the gethostbyXXX
4220 ** routines. For example, Solaris versions at least through 2.3
4221 ** don't properly deliver a canonical h_name field. This tries to
4222 ** work around these problems.
4224 ** Support IPv6 as well as IPv4.
4227 #if NETINET6 && NEEDSGETIPNODE
4230 # define AI_DEFAULT 0 /* dummy */
4231 # endif /* ! AI_DEFAULT */
4232 # ifndef AI_ADDRCONFIG
4233 # define AI_ADDRCONFIG 0 /* dummy */
4234 # endif /* ! AI_ADDRCONFIG */
4235 # ifndef AI_V4MAPPED
4236 # define AI_V4MAPPED 0 /* dummy */
4237 # endif /* ! AI_V4MAPPED */
4239 # define AI_ALL 0 /* dummy */
4240 # endif /* ! AI_ALL */
4242 static struct hostent *
4243 sm_getipnodebyname(name, family, flags, err)
4250 # if HAS_GETHOSTBYNAME2
4252 h = gethostbyname2(name, family);
4257 # else /* HAS_GETHOSTBYNAME2 */
4260 if (family == AF_INET6)
4262 /* From RFC2133, section 6.1 */
4263 resv6 = bitset(RES_USE_INET6, _res.options);
4264 _res.options |= RES_USE_INET6;
4267 h = gethostbyname(name);
4269 _res.options &= ~RES_USE_INET6;
4271 /* the function is supposed to return only the requested family */
4272 if (h != NULL && h->h_addrtype != family)
4276 # endif /* NETINET6 */
4283 # endif /* HAS_GETHOSTBYNAME2 */
4286 static struct hostent *
4287 sm_getipnodebyaddr(addr, len, family, err)
4296 h = gethostbyaddr(addr, len, family);
4306 ** Stub routine -- if they don't have getipnodeby*(),
4307 ** they probably don't have the free routine either.
4312 #endif /* NETINET6 && NEEDSGETIPNODE */
4315 sm_gethostbyname(name, family)
4320 struct hostent *h = NULL;
4321 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4322 # if SOLARIS == 20300 || SOLARIS == 203
4323 static struct hostent hp;
4324 static char buf[1000];
4325 extern struct hostent *_switch_gethostbyname_r();
4328 sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
4329 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
4331 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4332 extern struct hostent *__switch_gethostbyname();
4335 sm_dprintf("__switch_gethostbyname(%s)... ", name);
4336 h = __switch_gethostbyname(name);
4338 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4339 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4342 # ifndef SM_IPNODEBYNAME_FLAGS
4343 /* For IPv4-mapped addresses, use: AI_DEFAULT|AI_ALL */
4344 # define SM_IPNODEBYNAME_FLAGS AI_ADDRCONFIG
4345 # endif /* SM_IPNODEBYNAME_FLAGS */
4347 int flags = SM_IPNODEBYNAME_FLAGS;
4349 # endif /* NETINET6 */
4350 char *maptype[MAXMAPSTACK];
4351 short mapreturn[MAXMAPACTIONS];
4355 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
4358 # if ADDRCONFIG_IS_BROKEN
4359 flags &= ~AI_ADDRCONFIG;
4360 # endif /* ADDRCONFIG_IS_BROKEN */
4361 h = sm_getipnodebyname(name, family, flags, &err);
4362 SM_SET_H_ERRNO(err);
4363 # else /* NETINET6 */
4364 h = gethostbyname(name);
4365 # endif /* NETINET6 */
4371 sm_dprintf("failure\n");
4373 nmaps = switch_map_find("hosts", maptype, mapreturn);
4374 while (--nmaps >= 0)
4376 if (strcmp(maptype[nmaps], "nis") == 0 ||
4377 strcmp(maptype[nmaps], "files") == 0)
4383 /* try short name */
4384 if (strlen(name) > sizeof(hbuf) - 1)
4389 (void) sm_strlcpy(hbuf, name, sizeof(hbuf));
4390 (void) shorten_hostname(hbuf);
4392 /* if it hasn't been shortened, there's no point */
4393 if (strcmp(hbuf, name) != 0)
4396 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4400 h = sm_getipnodebyname(hbuf, family, flags, &err);
4401 SM_SET_H_ERRNO(err);
4403 # else /* NETINET6 */
4404 h = gethostbyname(hbuf);
4406 # endif /* NETINET6 */
4410 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4412 /* the function is supposed to return only the requested family */
4413 if (h != NULL && h->h_addrtype != family)
4417 # endif /* NETINET6 */
4419 SM_SET_H_ERRNO(NO_DATA);
4425 sm_dprintf("failure\n");
4428 sm_dprintf("%s\n", h->h_name);
4434 struct in6_addr ia6;
4435 char buf6[INET6_ADDRSTRLEN];
4436 #endif /* NETINET6 */
4438 if (h->h_aliases != NULL)
4439 for (i = 0; h->h_aliases[i] != NULL;
4441 sm_dprintf("\talias: %s\n",
4443 for (i = 0; h->h_addr_list[i] != NULL; i++)
4449 if (h->h_addrtype == AF_INET6)
4451 memmove(&ia6, h->h_addr_list[i],
4453 addr = anynet_ntop(&ia6,
4454 buf6, sizeof(buf6));
4457 #endif /* NETINET6 */
4458 /* "else" in #if code above */
4460 memmove(&ia, h->h_addr_list[i],
4462 addr = (char *) inet_ntoa(ia);
4465 sm_dprintf("\taddr: %s\n", addr);
4475 sm_gethostbyaddr(addr, len, type)
4483 if (type == AF_INET6 &&
4484 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
4486 /* Avoid reverse lookup for IPv6 unspecified address */
4487 SM_SET_H_ERRNO(HOST_NOT_FOUND);
4490 #endif /* NETINET6 */
4492 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4493 # if SOLARIS == 20300 || SOLARIS == 203
4495 static struct hostent he;
4496 static char buf[1000];
4497 extern struct hostent *_switch_gethostbyaddr_r();
4499 hp = _switch_gethostbyaddr_r(addr, len, type, &he,
4500 buf, sizeof(buf), &h_errno);
4502 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4504 extern struct hostent *__switch_gethostbyaddr();
4506 hp = __switch_gethostbyaddr(addr, len, type);
4508 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4509 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4514 hp = sm_getipnodebyaddr(addr, len, type, &err);
4515 SM_SET_H_ERRNO(err);
4517 # else /* NETINET6 */
4518 hp = gethostbyaddr(addr, len, type);
4519 # endif /* NETINET6 */
4520 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4524 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4532 extern struct passwd *_getpwnam_shadow(const char *, const int);
4534 return _getpwnam_shadow(user, 0);
4536 return getpwnam(user);
4544 #if defined(_AIX4) && 0
4545 extern struct passwd *_getpwuid_shadow(const int, const int);
4547 return _getpwuid_shadow(uid,0);
4548 #else /* defined(_AIX4) && 0 */
4549 return getpwuid(uid);
4550 #endif /* defined(_AIX4) && 0 */
4553 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4555 ** Set up the trusted computing environment for C2 level security
4556 ** under SecureWare.
4559 ** uid -- uid of the user to initialize in the TCB
4565 ** Initialized the user in the trusted computing base
4570 # include <sys/security.h>
4574 secureware_setup_secure(uid)
4579 if (getluid() != -1)
4582 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
4586 case SSI_NO_PRPW_ENTRY:
4587 syserr("No protected passwd entry, uid = %d",
4592 syserr("Account has been disabled, uid = %d",
4597 syserr("Account has been retired, uid = %d",
4601 case SSI_BAD_SET_LUID:
4602 syserr("Could not set LUID, uid = %d", (int) uid);
4605 case SSI_BAD_SET_PRIVS:
4606 syserr("Could not set kernel privs, uid = %d",
4610 syserr("Unknown return code (%d) from set_secure_info(%d)",
4614 finis(false, true, EX_NOPERM);
4617 #endif /* SECUREWARE */
4619 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4621 ** Add hostnames to class 'w' based on the IP address read from
4622 ** the network interface.
4625 ** sa -- a pointer to a SOCKADDR containing the address
4628 ** 0 if successful, -1 if host lookup fails.
4637 char hnb[MAXHOSTNAMELEN];
4639 /* lookup name with IP address */
4640 switch (sa->sa.sa_family)
4644 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
4645 sizeof(sa->sin.sin_addr),
4648 #endif /* NETINET */
4652 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
4653 sizeof(sa->sin6.sin6_addr),
4656 #endif /* NETINET6 */
4659 /* Give warning about unsupported family */
4661 sm_syslog(LOG_WARNING, NOQID,
4662 "Unsupported address family %d: %.100s",
4663 sa->sa.sa_family, anynet_ntoa(sa));
4669 int save_errno = errno;
4672 #if NETINET && defined(IN_LINKLOCAL)
4673 !(sa->sa.sa_family == AF_INET &&
4674 IN_LINKLOCAL(ntohl(sa->sin.sin_addr.s_addr))) &&
4675 #endif /* NETINET && defined(IN_LINKLOCAL) */
4677 !(sa->sa.sa_family == AF_INET6 &&
4678 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
4679 #endif /* NETINET6 */
4681 sm_syslog(LOG_WARNING, NOQID,
4682 "gethostbyaddr(%.100s) failed: %d",
4686 #else /* NAMED_BIND */
4688 #endif /* NAMED_BIND */
4694 /* save its cname */
4695 if (!wordinclass((char *) hp->h_name, 'w'))
4697 setclass('w', (char *) hp->h_name);
4699 sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
4701 if (sm_snprintf(hnb, sizeof(hnb), "[%s]", hp->h_name) <
4703 && !wordinclass((char *) hnb, 'w'))
4709 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
4712 /* save all it aliases name */
4713 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
4715 if (!wordinclass(*ha, 'w'))
4719 sm_dprintf("\ta.k.a.: %s\n", *ha);
4720 if (sm_snprintf(hnb, sizeof(hnb),
4721 "[%s]", *ha) < sizeof(hnb) &&
4722 !wordinclass((char *) hnb, 'w'))
4728 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4734 #endif /* NETINET6 */
4738 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4747 ** Loads $=w with the names of all the interfaces.
4751 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4752 #endif /* !NETINET */
4754 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4758 # include <sm/time.h>
4759 # endif /* ! SUNOS403 */
4760 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4762 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
4763 # include <net/if.h>
4764 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4769 # if NETINET6 && defined(SIOCGLIFCONF)
4773 ** Unfortunately, HP has changed all of the structures,
4774 ** making life difficult for implementors.
4777 # define lifconf if_laddrconf
4778 # define lifc_len iflc_len
4779 # define lifc_buf iflc_buf
4780 # define lifreq if_laddrreq
4781 # define lifr_addr iflr_addr
4782 # define lifr_name iflr_name
4783 # define lifr_flags iflr_flags
4784 # define ss_family sa_family
4786 # endif /* __hpux */
4793 struct lifconf lifc;
4796 # endif /* SIOCGLIFNUM */
4798 s = socket(InetMode, SOCK_DGRAM, 0);
4802 /* get the list of known IP address from the kernel */
4804 i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
4805 # endif /* __hpux */
4807 lifn.lifn_family = AF_UNSPEC;
4808 lifn.lifn_flags = 0;
4809 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
4810 numifs = lifn.lifn_count;
4811 # endif /* SIOCGLIFNUM */
4813 # if defined(__hpux) || defined(SIOCGLIFNUM)
4816 /* can't get number of interfaces -- fall back */
4818 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4819 sm_errstring(errno));
4822 else if (tTd(0, 42))
4823 sm_dprintf("system has %d interfaces\n", numifs);
4825 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4826 numifs = MAXINTERFACES;
4834 len = lifc.lifc_len = numifs * sizeof(struct lifreq);
4835 buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
4837 lifc.lifc_family = AF_UNSPEC;
4838 lifc.lifc_flags = 0;
4839 # endif /* ! __hpux */
4840 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
4843 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4844 sm_errstring(errno));
4850 /* scan the list of IP address */
4852 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4855 for (i = 0; i < len && i >= 0; )
4858 struct lifreq *ifr = (struct lifreq *)&buf[i];
4859 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
4860 int af = ifr->lifr_addr.ss_family;
4863 struct in6_addr ia6;
4865 # ifdef SIOCGLIFFLAGS
4867 # endif /* SIOCGLIFFLAGS */
4869 char buf6[INET6_ADDRSTRLEN];
4872 ** We must close and recreate the socket each time
4873 ** since we don't know what type of socket it is now
4874 ** (each status function may change it).
4879 s = socket(af, SOCK_DGRAM, 0);
4882 sm_free(buf); /* XXX */
4887 ** If we don't have a complete ifr structure,
4888 ** don't try to use it.
4891 if ((len - i) < sizeof(*ifr))
4894 # ifdef BSD4_4_SOCKADDR
4895 if (sa->sa.sa_len > sizeof(ifr->lifr_addr))
4896 i += sizeof(ifr->lifr_name) + sa->sa.sa_len;
4898 # endif /* BSD4_4_SOCKADDR */
4900 /* fix for IPv6 size differences */
4901 i += sizeof(ifr->ifr_name) +
4902 max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
4908 sm_dprintf("%s\n", anynet_ntoa(sa));
4910 if (af != AF_INET && af != AF_INET6)
4913 # ifdef SIOCGLIFFLAGS
4914 memset(&ifrf, '\0', sizeof(struct lifreq));
4915 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
4916 sizeof(ifrf.lifr_name));
4917 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
4920 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4921 sm_errstring(errno));
4925 name = ifr->lifr_name;
4926 flags = ifrf.lifr_flags;
4929 sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
4931 if (!bitset(IFF_UP, flags))
4933 # endif /* SIOCGLIFFLAGS */
4937 /* extract IP address from the list*/
4941 SETV6LOOPBACKADDRFOUND(*sa);
4943 /* convert into proper scoped address */
4944 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
4945 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
4946 sa->sin6.sin6_scope_id == 0)
4948 struct in6_addr *ia6p;
4950 ia6p = &sa->sin6.sin6_addr;
4951 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
4952 ((unsigned int)ia6p->s6_addr[2] << 8));
4953 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
4955 # endif /* __KAME__ */
4956 ia6 = sa->sin6.sin6_addr;
4957 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
4959 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
4960 message("WARNING: interface %s is UP with %s address",
4961 name, addr == NULL ? "(NULL)" : addr);
4965 /* save IP address in text from */
4966 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
4968 (void) sm_snprintf(ip_addr, sizeof(ip_addr),
4970 (int) sizeof(ip_addr) - 3,
4975 ia = sa->sin.sin_addr;
4976 if (ia.s_addr == INADDR_ANY ||
4977 ia.s_addr == INADDR_NONE)
4979 message("WARNING: interface %s is UP with %s address",
4980 name, inet_ntoa(ia));
4984 /* save IP address in text from */
4985 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
4986 (int) sizeof(ip_addr) - 3, inet_ntoa(ia));
4990 if (*ip_addr == '\0')
4993 if (!wordinclass(ip_addr, 'w'))
4995 setclass('w', ip_addr);
4997 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5000 # ifdef SIOCGLIFFLAGS
5001 /* skip "loopback" interface "lo" */
5002 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5003 bitset(IFF_LOOPBACK, flags))
5005 # endif /* SIOCGLIFFLAGS */
5006 (void) add_hostnames(sa);
5008 sm_free(buf); /* XXX */
5010 # else /* NETINET6 && defined(SIOCGLIFCONF) */
5011 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
5017 s = socket(AF_INET, SOCK_DGRAM, 0);
5021 /* get the list of known IP address from the kernel */
5022 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
5023 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
5025 /* can't get number of interfaces -- fall back */
5027 sm_dprintf("SIOCGIFNUM failed: %s\n",
5028 sm_errstring(errno));
5031 else if (tTd(0, 42))
5032 sm_dprintf("system has %d interfaces\n", numifs);
5034 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
5035 numifs = MAXINTERFACES;
5042 ifc.ifc_len = numifs * sizeof(struct ifreq);
5043 ifc.ifc_buf = xalloc(ifc.ifc_len);
5044 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
5047 sm_dprintf("SIOCGIFCONF failed: %s\n",
5048 sm_errstring(errno));
5053 /* scan the list of IP address */
5055 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
5058 for (i = 0; i < ifc.ifc_len && i >= 0; )
5061 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
5062 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
5065 struct in6_addr ia6;
5066 # endif /* NETINET6 */
5068 # ifdef SIOCGIFFLAGS
5070 # endif /* SIOCGIFFLAGS */
5073 char buf6[INET6_ADDRSTRLEN];
5074 # endif /* NETINET6 */
5077 ** If we don't have a complete ifr structure,
5078 ** don't try to use it.
5081 if ((ifc.ifc_len - i) < sizeof(*ifr))
5084 # ifdef BSD4_4_SOCKADDR
5085 if (sa->sa.sa_len > sizeof(ifr->ifr_addr))
5086 i += sizeof(ifr->ifr_name) + sa->sa.sa_len;
5088 # endif /* BSD4_4_SOCKADDR */
5092 sm_dprintf("%s\n", anynet_ntoa(sa));
5094 af = ifr->ifr_addr.sa_family;
5098 # endif /* NETINET6 */
5102 # ifdef SIOCGIFFLAGS
5103 memset(&ifrf, '\0', sizeof(struct ifreq));
5104 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
5105 sizeof(ifrf.ifr_name));
5106 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
5108 sm_dprintf("\tflags: %lx\n",
5109 (unsigned long) ifrf.ifr_flags);
5110 # define IFRFREF ifrf
5111 # else /* SIOCGIFFLAGS */
5112 # define IFRFREF (*ifr)
5113 # endif /* SIOCGIFFLAGS */
5115 if (!bitset(IFF_UP, IFRFREF.ifr_flags))
5120 /* extract IP address from the list*/
5124 ia = sa->sin.sin_addr;
5125 if (ia.s_addr == INADDR_ANY ||
5126 ia.s_addr == INADDR_NONE)
5128 message("WARNING: interface %s is UP with %s address",
5129 ifr->ifr_name, inet_ntoa(ia));
5133 /* save IP address in text from */
5134 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
5135 (int) sizeof(ip_addr) - 3,
5141 SETV6LOOPBACKADDRFOUND(*sa);
5143 /* convert into proper scoped address */
5144 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5145 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5146 sa->sin6.sin6_scope_id == 0)
5148 struct in6_addr *ia6p;
5150 ia6p = &sa->sin6.sin6_addr;
5151 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5152 ((unsigned int)ia6p->s6_addr[2] << 8));
5153 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5155 # endif /* __KAME__ */
5156 ia6 = sa->sin6.sin6_addr;
5157 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5159 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5160 message("WARNING: interface %s is UP with %s address",
5162 addr == NULL ? "(NULL)" : addr);
5166 /* save IP address in text from */
5167 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5169 (void) sm_snprintf(ip_addr, sizeof(ip_addr),
5171 (int) sizeof(ip_addr) - 3,
5175 # endif /* NETINET6 */
5178 if (ip_addr[0] == '\0')
5181 if (!wordinclass(ip_addr, 'w'))
5183 setclass('w', ip_addr);
5185 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5188 /* skip "loopback" interface "lo" */
5189 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5190 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
5193 (void) add_hostnames(sa);
5195 sm_free(ifc.ifc_buf); /* XXX */
5198 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5199 # endif /* NETINET6 && defined(SIOCGLIFCONF) */
5202 ** ISLOOPBACK -- is socket address in the loopback net?
5205 ** sa -- socket address.
5208 ** true -- is socket address in the loopback net?
5209 ** false -- otherwise
5218 if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
5220 #else /* NETINET6 */
5221 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5222 if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
5223 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
5225 #endif /* NETINET6 */
5229 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5235 ** The number of processors online.
5239 get_num_procs_online()
5244 # if defined(CTL_HW) && defined(HW_NCPU)
5250 sz = (size_t) sizeof(nproc);
5251 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
5252 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5253 #else /* USESYSCTL */
5254 # ifdef _SC_NPROCESSORS_ONLN
5255 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
5256 # else /* _SC_NPROCESSORS_ONLN */
5258 # include <sys/pstat.h>
5259 struct pst_dynamic psd;
5261 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
5262 nproc = psd.psd_proc_cnt;
5263 # endif /* __hpux */
5264 # endif /* _SC_NPROCESSORS_ONLN */
5265 #endif /* USESYSCTL */
5272 ** SM_CLOSEFROM -- close file descriptors
5275 ** lowest -- first fd to close
5276 ** highest -- last fd + 1 to close
5283 sm_closefrom(lowest, highest)
5284 int lowest, highest;
5288 #else /* HASCLOSEFROM */
5291 for (i = lowest; i < highest; i++)
5293 #endif /* HASCLOSEFROM */
5297 ** CLOSEFD_WALK -- walk fd's arranging to close them
5298 ** Callback for fdwalk()
5301 ** lowest -- first fd to arrange to be closed
5302 ** fd -- fd to arrange to be closed
5309 closefd_walk(lowest, fd)
5313 if (fd >= *(int *)lowest)
5314 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
5317 #endif /* HASFDWALK */
5319 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5322 ** lowest -- first fd to arrange to be closed
5323 ** highest -- last fd + 1 to arrange to be closed
5330 sm_close_on_exec(lowest, highest)
5331 int lowest, highest;
5334 (void) fdwalk(closefd_walk, &lowest);
5335 #else /* HASFDWALK */
5338 for (i = lowest; i < highest; i++)
5340 if ((j = fcntl(i, F_GETFD, 0)) != -1)
5341 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
5343 #endif /* HASFDWALK */
5346 ** SEED_RANDOM -- seed the random number generator
5360 #else /* HASSRANDOMDEV */
5364 seed = (long) CurrentPid;
5365 if (gettimeofday(&t, NULL) >= 0)
5366 seed += t.tv_sec + t.tv_usec;
5369 (void) srandom(seed);
5370 # else /* HASRANDOM */
5371 (void) srand((unsigned int) seed);
5372 # endif /* HASRANDOM */
5373 #endif /* HASSRANDOMDEV */
5376 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5379 ** level -- syslog level
5380 ** id -- envelope ID or NULL (NOQUEUE)
5381 ** fmt -- format string
5382 ** arg... -- arguments as implied by fmt.
5391 sm_syslog(int level, const char *id, const char *fmt, ...)
5392 #else /* __STDC__ */
5393 sm_syslog(level, id, fmt, va_alist)
5398 #endif /* __STDC__ */
5408 extern int SyslogPrefixLen;
5414 idlen = strlen(id) + SyslogPrefixLen;
5417 bufsize = sizeof(buf0);
5423 /* print log message into buf */
5424 SM_VA_START(ap, fmt);
5425 n = sm_vsnprintf(buf, bufsize, fmt, ap);
5431 /* String too small, redo with correct size */
5438 buf = sm_malloc_x(bufsize);
5441 /* clean up buf after it has been expanded with args */
5442 newstring = str2prt(buf);
5443 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
5452 gettimeofday(&tv, NULL);
5453 sm_dprintf("%ld.%06ld %s\n", (long) tv.tv_sec,
5454 (long) tv.tv_usec, newstring);
5456 else if (tTd(89, 8))
5457 sm_dprintf("%s\n", newstring);
5459 syslog(level, "%s", newstring);
5467 gettimeofday(&tv, NULL);
5468 sm_dprintf("%ld.%06ld %s: %s\n", (long) tv.tv_sec,
5469 (long) tv.tv_usec, id, newstring);
5471 else if (tTd(89, 8))
5472 sm_dprintf("%s: %s\n", id, newstring);
5474 syslog(level, "%s: %s", id, newstring);
5477 /*XXX should do something more sensible */
5479 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
5482 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5483 "%s: %s\n", id, newstring);
5492 ** additional length for splitting: " ..." + 3, where 3 is magic to
5493 ** have some data for the next entry.
5499 idlen += 5; /* strlen("[999]"), see below */
5500 while (*begin != '\0' &&
5501 (strlen(begin) + idlen) > SYSLOG_BUFSIZE)
5507 /* Too many messages */
5510 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5513 /* Break on comma or space */
5514 if (*end == ',' || *end == ' ')
5516 end++; /* Include separator */
5521 /* No separator, break midstring... */
5523 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5528 sm_dprintf("%s[%d]: %s ...\n", id, seq++, begin);
5530 syslog(level, "%s[%d]: %s ...", id, seq++, begin);
5532 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5533 "%s[%d]: %s ...\n", id, seq++, begin);
5542 sm_dprintf("%s[%d]: log terminated, too many parts\n",
5545 syslog(level, "%s[%d]: log terminated, too many parts",
5548 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5549 "%s[%d]: log terminated, too many parts\n", id, seq);
5552 else if (*begin != '\0')
5556 sm_dprintf("%s[%d]: %s\n", id, seq, begin);
5558 syslog(level, "%s[%d]: %s", id, seq, begin);
5560 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5561 "%s[%d]: %s\n", id, seq, begin);
5569 ** HARD_SYSLOG -- call syslog repeatedly until it works
5571 ** Needed on HP-UX, which apparently doesn't guarantee that
5572 ** syslog succeeds during interrupt handlers.
5575 #if defined(__hpux) && !defined(HPUX11)
5577 # define MAXSYSLOGTRIES 100
5580 # define XCNST const
5581 # define CAST (const char *)
5589 hard_syslog(int pri, XCNST char *msg, ...)
5590 # else /* __STDC__ */
5591 hard_syslog(pri, msg, va_alist)
5595 # endif /* __STDC__ */
5598 char buf[SYSLOG_BUFSIZE];
5601 SM_VA_START(ap, msg);
5602 (void) sm_vsnprintf(buf, sizeof(buf), msg, ap);
5605 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
5610 #endif /* defined(__hpux) && !defined(HPUX11) */
5611 #if NEEDLOCAL_HOSTNAME_LENGTH
5613 ** LOCAL_HOSTNAME_LENGTH
5615 ** This is required to get sendmail to compile against BIND 4.9.x
5618 ** Unfortunately, a Compaq Y2K patch kit provides it without
5619 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5620 ** figure out whether it is needed.
5624 local_hostname_length(hostname)
5627 size_t len_host, len_domain;
5629 if (!*_res.defdname)
5631 len_host = strlen(hostname);
5632 len_domain = strlen(_res.defdname);
5633 if (len_host > len_domain &&
5634 (sm_strcasecmp(hostname + len_host - len_domain,
5635 _res.defdname) == 0) &&
5636 hostname[len_host - len_domain - 1] == '.')
5637 return len_host - len_domain - 1;
5641 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5645 ** LINK -- clone a file
5647 ** Some OS's lacks link() and hard links. Since sendmail is using
5648 ** link() as an efficient way to clone files, this implementation
5649 ** will simply do a file copy.
5651 ** NOTE: This link() replacement is not a generic replacement as it
5652 ** does not handle all of the semantics of the real link(2).
5655 ** source -- pathname of existing file.
5656 ** target -- pathname of link (clone) to be created.
5660 ** -1 -- failure, see errno for details.
5664 link(source, target)
5670 int src = -1, dst = -1;
5676 sff = SFF_REGONLY|SFF_OPENASROOT;
5677 if (DontLockReadFiles)
5680 /* Open the original file */
5681 src = safeopen((char *)source, O_RDONLY, 0, sff);
5685 /* Obtain the size and the mode */
5686 if (fstat(src, &st) < 0)
5689 /* Create the duplicate copy */
5692 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
5697 /* Copy all of the bytes one buffer at a time */
5698 while ((readlen = read(src, &buf, sizeof(buf))) > 0)
5700 ssize_t left = readlen;
5704 (writelen = write(dst, p, (size_t) left)) >= 0)
5713 /* Any trouble reading? */
5714 if (readlen < 0 || writelen < 0)
5717 /* Close the input file */
5725 /* Close the output file */
5728 /* don't set dst = -1 here so we unlink the file */
5741 (void) unlink(target);
5747 #endif /* NEEDLINK */
5750 ** Compile-Time options
5753 char *CompileOptions[] =
5769 #if HESIOD_ALLOW_NUMERIC_LOGIN
5770 "HESIOD_ALLOW_NUMERIC_LOGIN",
5776 /* Use uncompressed IPv6 address format (no "::") by default */
5851 #ifdef PICKY_HELO_CHECK
5860 # else /* SASL >= 20000 */
5867 #if SM_LDAP_ERROR_ON_MISSING_ARGS
5868 "SM_LDAP_ERROR_ON_MISSING_ARGS",
5879 #if SUID_ROOT_FILES_OK
5880 "SUID_ROOT_FILES_OK",
5888 #if TLS_VRFY_PER_CTX
5911 ** OS compile options.
5914 char *OsCompileOptions[] =
5916 #if ADDRCONFIG_IS_BROKEN
5917 "ADDRCONFIG_IS_BROKEN",
5919 #ifdef AUTO_NETINFO_HOSTS
5920 "AUTO_NETINFO_HOSTS",
5922 #ifdef AUTO_NIS_ALIASES
5925 #if BROKEN_RES_SEARCH
5926 "BROKEN_RES_SEARCH",
5928 #ifdef BSD4_4_SOCKADDR
5934 #if DEC_OSF_BROKEN_GETPWENT
5935 "DEC_OSF_BROKEN_GETPWENT",
5937 #if FAST_PID_RECYCLE
5955 #if HASGETDTABLESIZE
5964 #if HASLDAPGETALIASBYNAME
5965 "HASLDAPGETALIASBYNAME",
6000 #if HASSETUSERCONTEXT
6001 "HASSETUSERCONTEXT",
6039 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
6051 #if NEEDLOCAL_HOSTNAME_LENGTH
6052 "NEEDLOCAL_HOSTNAME_LENGTH",
6063 #ifdef NO_GETSERVBYNAME
6069 #if REQUIRES_DIR_FSYNC
6070 "REQUIRES_DIR_FSYNC",
6072 #if RLIMIT_NEEDS_SYS_TIME_H
6073 "RLIMIT_NEEDS_SYS_TIME_H",
6081 #if SFS_TYPE == SFS_4ARGS
6083 #elif SFS_TYPE == SFS_MOUNT
6085 #elif SFS_TYPE == SFS_NONE
6087 #elif SFS_TYPE == SFS_NT
6089 #elif SFS_TYPE == SFS_STATFS
6091 #elif SFS_TYPE == SFS_STATVFS
6093 #elif SFS_TYPE == SFS_USTAT
6095 #elif SFS_TYPE == SFS_VFS
6101 #if SIOCGIFCONF_IS_BROKEN
6102 "SIOCGIFCONF_IS_BROKEN",
6104 #if SIOCGIFNUM_IS_BROKEN
6105 "SIOCGIFNUM_IS_BROKEN",
6107 #if SNPRINTF_IS_BROKEN
6108 "SNPRINTF_IS_BROKEN",
6110 #if SO_REUSEADDR_IS_BROKEN
6111 "SO_REUSEADDR_IS_BROKEN",
6125 #if USE_SA_SIGACTION
6140 #if USE_OPENSSL_ENGINE
6141 "USE_OPENSSL_ENGINE",
6143 #if USING_NETSCAPE_LDAP
6144 "USING_NETSCAPE_LDAP",
6153 ** FFR compile options.
6156 char *FFRCompileOptions[] =
6161 #if _FFR_ADDR_TYPE_MODES
6162 /* more info in {addr_type}, requires m4 changes! */
6163 "_FFR_ADDR_TYPE_MODES",
6165 #if _FFR_ALIAS_DETAIL
6166 /* try to handle +detail for aliases */
6167 "_FFR_ALIAS_DETAIL",
6169 #if _FFR_ALLOW_SASLINFO
6170 /* DefaultAuthInfo can be specified by user. */
6171 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */
6172 "_FFR_ALLOW_SASLINFO",
6174 #if _FFR_BADRCPT_SHUTDOWN
6175 /* shut down connection (421) if there are too many bad RCPTs */
6176 "_FFR_BADRCPT_SHUTDOWN",
6178 #if _FFR_BESTMX_BETTER_TRUNCATION
6179 /* Better truncation of list of MX records for dns map. */
6180 "_FFR_BESTMX_BETTER_TRUNCATION",
6182 #if _FFR_BOUNCE_QUEUE
6183 /* Separate, unprocessed queue for DSNs */
6184 /* John Gardiner Myers of Proofpoint */
6185 "_FFR_BOUNCE_QUEUE",
6187 #if _FFR_CATCH_BROKEN_MTAS
6188 /* Deal with MTAs that send a reply during the DATA phase. */
6189 "_FFR_CATCH_BROKEN_MTAS",
6192 /* Stricter checks about queue directory permissions. */
6195 #if _FFR_CLIENT_SIZE
6196 /* Don't try to send mail if its size exceeds SIZE= of server. */
6200 /* CRLPath; needs documentation; Al Smith */
6204 /* deliver first TA in background, then queue */
6207 #if _FFR_DIGUNIX_SAFECHOWN
6208 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6209 /* Problem noted by Anne Bennett of Concordia University */
6210 "_FFR_DIGUNIX_SAFECHOWN",
6212 #if _FFR_DNSMAP_ALIASABLE
6213 /* Allow dns map type to be used for aliases. */
6214 /* Don Lewis of TDK */
6215 "_FFR_DNSMAP_ALIASABLE",
6217 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6218 /* Enable DontLockFilesForRead option. */
6219 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6221 #if _FFR_DOTTED_USERNAMES
6222 /* Allow usernames with '.' */
6223 "_FFR_DOTTED_USERNAMES",
6227 ** Make DaemonPortOptions case sensitive.
6228 ** For some unknown reasons the code converted every option
6229 ** to uppercase (first letter only, as that's the only one that
6230 ** is actually checked). This prevented all new lower case options
6232 ** The documentation doesn't say anything about case (in)sensitivity,
6233 ** which means it should be case sensitive by default,
6234 ** but it's not a good idea to change this within a patch release,
6235 ** so let's delay this to 8.15.
6240 #if _FFR_DPRINTF_MAP
6241 /* dprintf map for logging */
6244 #if _FFR_DROP_TRUSTUSER_WARNING
6246 ** Don't issue this warning:
6247 ** "readcf: option TrustedUser may cause problems on systems
6248 ** which do not support fchown() if UseMSP is not set.
6251 "_FFR_DROP_TRUSTUSER_WARNING",
6253 #if _FFR_EIGHT_BIT_ADDR_OK
6254 /* EightBitAddrOK: allow 8-bit e-mail addresses */
6255 "_FFR_EIGHT_BIT_ADDR_OK",
6257 #if _FFR_EXTRA_MAP_CHECK
6258 /* perform extra checks on $( $) in R lines */
6259 "_FFR_EXTRA_MAP_CHECK",
6261 #if _FFR_GETHBN_ExFILE
6263 ** According to Motonori Nakamura some gethostbyname()
6264 ** implementations (TurboLinux?) may (temporarily) fail
6265 ** due to a lack of file descriptors. Enabling this FFR
6266 ** will check errno for EMFILE and ENFILE and in case of a match
6267 ** cause a temporary error instead of a permanent error.
6268 ** The right solution is of course to file a bug against those
6269 ** systems such that they actually set h_errno = TRY_AGAIN.
6272 "_FFR_GETHBN_ExFILE",
6275 /* FIPSMode (if supported by OpenSSL library) */
6280 ** If using -t, force not sending to argv recipients, even
6281 ** if they are mentioned in the headers.
6286 #if _FFR_FORWARD_SYSERR
6287 /* Cause a "syserr" if forward file isn't "safe". */
6288 "_FFR_FORWARD_SYSERR",
6291 /* Generate a ORCPT DSN arg if not already provided */
6294 #if _FFR_HANDLE_ISO8859_GECOS
6296 ** Allow ISO 8859 characters in GECOS field: replace them
6297 ** with ASCII "equivalent".
6300 /* Peter Eriksson of Linkopings universitet */
6301 "_FFR_HANDLE_ISO8859_GECOS",
6303 #if _FFR_HANDLE_HDR_RW_TEMPFAIL
6305 ** Temporary header rewriting problems from remotename() etc
6306 ** are not "sticky" for mci (e.g., during queue runs).
6309 "_FFR_HANDLE_HDR_RW_TEMPFAIL",
6311 #if _FFR_HPUX_NSSWITCH
6312 /* Use nsswitch on HP-UX */
6313 "_FFR_HPUX_NSSWITCH",
6315 #if _FFR_IGNORE_BOGUS_ADDR
6316 /* Ignore addresses for which prescan() failed */
6317 "_FFR_IGNORE_BOGUS_ADDR",
6319 #if _FFR_IGNORE_EXT_ON_HELO
6320 /* Ignore extensions offered in response to HELO */
6321 "_FFR_IGNORE_EXT_ON_HELO",
6324 /* Set MAXHOSTNAMELEN to 256 (Linux) */
6327 #if _FFR_LOCAL_DAEMON
6328 /* Local daemon mode (-bl) which only accepts loopback connections */
6329 "_FFR_LOCAL_DAEMON",
6332 /* log some TLS/AUTH info in from= too */
6336 /* log some TLS info in to= too */
6345 #if _FFR_MAXDATASIZE
6347 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6348 ** hence this shouldn't be used as limit for milter communication.
6349 ** see also libmilter/comm.c
6350 ** Gurusamy Sarathy of ActiveState
6355 #if _FFR_MAX_FORWARD_ENTRIES
6356 /* Try to limit number of .forward entries */
6357 /* (doesn't work) */
6358 /* Randall S. Winchester of the University of Maryland */
6359 "_FFR_MAX_FORWARD_ENTRIES",
6361 #if _FFR_MAX_SLEEP_TIME
6362 /* Limit sleep(2) time in libsm/clock.c */
6363 "_FFR_MAX_SLEEP_TIME",
6365 #if _FFR_MDS_NEGOTIATE
6366 /* MaxDataSize negotation with libmilter */
6367 "_FFR_MDS_NEGOTIATE",
6370 /* Check free memory */
6373 #if _FFR_MILTER_CHECK
6374 "_FFR_MILTER_CHECK",
6376 #if _FFR_MILTER_CONNECT_REPLYCODE
6377 /* milter: propagate replycode returned by connect commands */
6378 /* John Gardiner Myers of Proofpoint */
6379 "_FFR_MILTER_CONNECT_REPLYCODE ",
6381 #if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF
6383 ** milter_body() uses the same conversion algorithm as putbody()
6384 ** to translate the "local" df format (\n) to SMTP format (\r\n).
6385 ** However, putbody() and mime8to7() use different conversion
6387 ** If the input date does not follow the SMTP standard
6388 ** (e.g., if it has "naked \r"s), then the output from putbody()
6389 ** and mime8to7() will most likely be different.
6390 ** By turning on this FFR milter_body() will try to "imitate"
6392 ** Note: there is no (simple) way to deal with both conversions
6393 ** in a consistent manner. Moreover, as the "GiGo" principle applies,
6394 ** it's not really worth to fix it.
6397 "_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF",
6399 #if _FFR_MILTER_CHECK_REJECTIONS_TOO
6401 ** Also send RCPTs that are rejected by check_rcpt to a milter
6402 ** (if requested during option negotiation).
6405 "_FFR_MILTER_CHECK_REJECTIONS_TOO",
6407 #if _FFR_MILTER_ENHSC
6408 /* extract enhanced status code from milter replies for dsn= logging */
6409 "_FFR_MILTER_ENHSC",
6411 #if _FFR_MIME7TO8_OLD
6412 /* Old mime7to8 code, the new is broken for at least one example. */
6413 "_FFR_MIME7TO8_OLD",
6415 #if _FFR_MORE_MACROS
6416 /* allow more long macro names ("unprintable" characters). */
6420 /* allow to override "Message accepted for delivery" */
6423 #if _FFR_NODELAYDSN_ON_HOLD
6424 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6426 "_FFR_NODELAYDSN_ON_HOLD",
6429 /* Disable PIPELINING, delay client if used. */
6432 #if _FFR_LDAP_NETWORK_TIMEOUT
6433 /* set LDAP_OPT_NETWORK_TIMEOUT if available (-c) */
6434 "_FFR_LDAP_NETWORK_TIMEOUT",
6437 /* log ntries=, from Nik Clayton of FreeBSD */
6441 /* "proxy" (synchronous) delivery mode */
6444 #if _FFR_QF_PARANOIA
6447 #if _FFR_QUEUE_GROUP_SORTORDER
6448 /* Allow QueueSortOrder per queue group. */
6449 /* XXX: Still need to actually use qgrp->qg_sortorder */
6450 "_FFR_QUEUE_GROUP_SORTORDER",
6452 #if _FFR_QUEUE_MACRO
6453 /* Define {queue} macro. */
6456 #if _FFR_QUEUE_RUN_PARANOIA
6457 /* Additional checks when doing queue runs; interval of checks */
6458 "_FFR_QUEUE_RUN_PARANOIA",
6460 #if _FFR_QUEUE_SCHED_DBG
6461 /* Debug output for the queue scheduler. */
6462 "_FFR_QUEUE_SCHED_DBG",
6467 #if _FFR_RCPTTHROTDELAY
6468 /* configurable delay for BadRcptThrottle */
6469 "_FFR_RCPTTHROTDELAY",
6471 #if _FFR_REDIRECTEMPTY
6473 ** envelope <> can't be sent to mailing lists, only owner-
6474 ** send spam of this type to owner- of the list
6475 ** ---- to stop spam from going to mailing lists.
6478 "_FFR_REDIRECTEMPTY",
6480 #if _FFR_REJECT_NUL_BYTE
6481 /* reject NUL bytes in body */
6482 "_FFR_REJECT_NUL_BYTE",
6484 #if _FFR_RESET_MACRO_GLOBALS
6485 /* Allow macro 'j' to be set dynamically via rulesets. */
6486 "_FFR_RESET_MACRO_GLOBALS",
6489 /* Random shuffle for queue sorting. */
6494 ** allow -qGqueue_group -qp to work, i.e.,
6495 ** restrict a persistent queue runner to a queue group.
6501 /* session id (for logging) */
6505 /* Donated code (unused). */
6508 #if _FFR_LDAP_SINGLEDN
6510 ** The LDAP database map code in Sendmail 8.12.10, when
6511 ** given the -1 switch, would match only a single DN,
6512 ** but was able to return multiple attributes for that
6513 ** DN. In Sendmail 8.13 this "bug" was corrected to
6514 ** only return if exactly one attribute matched.
6516 ** Unfortunately, our configuration uses the former
6517 ** behaviour. Attached is a relatively simple patch
6518 ** to 8.13.4 which adds a -2 switch (for lack of a
6519 ** better option) which returns the single dn/multiple
6522 ** Jeffrey T. Eaton, Carnegie-Mellon University
6525 "_FFR_LDAP_SINGLEDN",
6527 #if _FFR_SKIP_DOMAINS
6528 /* process every N'th domain instead of every N'th message */
6529 "_FFR_SKIP_DOMAINS",
6531 #if _FFR_SLEEP_USE_SELECT
6532 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6533 "_FFR_SLEEP_USE_SELECT ",
6537 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6538 ** bit alignment, so unless each piece of argv and envp is a multiple
6539 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6540 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6541 ** if you use this FFR.
6544 /* Chris Adams of HiWAAY Informations Services */
6547 #if _FFR_SS_PER_DAEMON
6548 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6549 "_FFR_SS_PER_DAEMON",
6552 /* enable some test code */
6556 /* Donated code (unused). */
6562 #if _FFR_TLS_USE_CERTIFICATE_CHAIN_FILE
6564 ** Use SSL_CTX_use_certificate_chain_file()
6565 ** instead of SSL_CTX_use_certificate_file()
6568 "_FFR_TLS_USE_CERTIFICATE_CHAIN_FILE",
6570 #if _FFR_TLS_SE_OPTS
6571 /* TLS session options */
6576 ** If we don't own the file mark it as unsafe.
6577 ** However, allow TrustedUser to own it as well
6578 ** in case TrustedUser manipulates the queue.
6583 #if _FFR_USE_GETPWNAM_ERRNO
6585 ** See libsm/mbdb.c: only enable this on OSs
6586 ** that implement the correct (POSIX) semantics.
6587 ** This will need to become an OS-specific #if enabled
6588 ** in one of the headers files under include/sm/os/ .
6591 "_FFR_USE_GETPWNAM_ERRNO",
6593 #if _FFR_USE_SEM_LOCKING
6594 "_FFR_USE_SEM_LOCKING",
6596 #if _FFR_USE_SETLOGIN
6597 /* Use setlogin() */
6599 "_FFR_USE_SETLOGIN",