2 * Copyright (c) 1998-2005 Sendmail, 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.1061 2005/03/07 17:18:44 ca Exp $")
18 #include <sendmail/pathnames.h>
23 # include <sys/ioctl.h>
24 # include <sys/param.h>
27 #if NETINET || NETINET6
28 # include <arpa/inet.h>
29 #endif /* NETINET || NETINET6 */
30 #if HASULIMIT && defined(HPUX11)
32 #endif /* HASULIMIT && defined(HPUX11) */
34 static void setupmaps __P((void));
35 static void setupmailers __P((void));
36 static void setupqueues __P((void));
37 static int get_num_procs_online __P((void));
38 static int add_hostnames __P((SOCKADDR *));
40 #if NETINET6 && NEEDSGETIPNODE
41 static struct hostent *getipnodebyname __P((char *, int, int, int *));
42 static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
43 #endif /* NETINET6 && NEEDSGETIPNODE */
47 ** CONF.C -- Sendmail Configuration Tables.
49 ** Defines the configuration of this installation.
51 ** Configuration Variables:
52 ** HdrInfo -- a table describing well-known header fields.
53 ** Each entry has the field name and some flags,
54 ** which are described in sendmail.h.
57 ** I have tried to put almost all the reasonable
58 ** configuration information into the configuration
59 ** file read at runtime. My intent is that anything
60 ** here is a function of the version of UNIX you
61 ** are running, or is really static -- for example
62 ** the headers are a superset of widely used
63 ** protocols. If you find yourself playing with
64 ** this file too much, you may be making a mistake!
70 ** Final (null) entry contains the flags used for any other field.
72 ** Not all of these are actually handled specially by sendmail
73 ** at this time. They are included as placeholders, to let
74 ** you know that "someday" I intend to have sendmail do
75 ** something with them.
78 struct hdrinfo HdrInfo[] =
80 /* originator fields, most to least significant */
81 { "resent-sender", H_FROM|H_RESENT, NULL },
82 { "resent-from", H_FROM|H_RESENT, NULL },
83 { "resent-reply-to", H_FROM|H_RESENT, NULL },
84 { "sender", H_FROM, NULL },
85 { "from", H_FROM, NULL },
86 { "reply-to", H_FROM, NULL },
87 { "errors-to", H_FROM|H_ERRORSTO, NULL },
88 { "full-name", H_ACHECK, NULL },
89 { "return-receipt-to", H_RECEIPTTO, NULL },
90 { "delivery-receipt-to", H_RECEIPTTO, NULL },
91 { "disposition-notification-to", H_FROM, NULL },
93 /* destination fields */
94 { "to", H_RCPT, NULL },
95 { "resent-to", H_RCPT|H_RESENT, NULL },
96 { "cc", H_RCPT, NULL },
97 { "resent-cc", H_RCPT|H_RESENT, NULL },
98 { "bcc", H_RCPT|H_BCC, NULL },
99 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
100 { "apparently-to", H_RCPT, NULL },
102 /* message identification and control */
103 { "message-id", 0, NULL },
104 { "resent-message-id", H_RESENT, NULL },
105 { "message", H_EOH, NULL },
106 { "text", H_EOH, NULL },
110 { "resent-date", H_RESENT, NULL },
113 { "received", H_TRACE|H_FORCE, NULL },
114 { "x400-received", H_TRACE|H_FORCE, NULL },
115 { "via", H_TRACE|H_FORCE, NULL },
116 { "mail-from", H_TRACE|H_FORCE, NULL },
118 /* miscellaneous fields */
119 { "comments", H_FORCE|H_ENCODABLE, NULL },
120 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
121 { "content-transfer-encoding", H_CTE, NULL },
122 { "content-type", H_CTYPE, NULL },
123 { "content-length", H_ACHECK, NULL },
124 { "subject", H_ENCODABLE, NULL },
125 { "x-authentication-warning", H_FORCE, NULL },
136 struct prival PrivacyValues[] =
138 { "public", PRIV_PUBLIC },
139 { "needmailhelo", PRIV_NEEDMAILHELO },
140 { "needexpnhelo", PRIV_NEEDEXPNHELO },
141 { "needvrfyhelo", PRIV_NEEDVRFYHELO },
142 { "noexpn", PRIV_NOEXPN },
143 { "novrfy", PRIV_NOVRFY },
144 { "restrictexpand", PRIV_RESTRICTEXPAND },
145 { "restrictmailq", PRIV_RESTRICTMAILQ },
146 { "restrictqrun", PRIV_RESTRICTQRUN },
147 { "noetrn", PRIV_NOETRN },
148 { "noverb", PRIV_NOVERB },
149 { "authwarnings", PRIV_AUTHWARNINGS },
150 { "noreceipts", PRIV_NORECEIPTS },
151 { "nobodyreturn", PRIV_NOBODYRETN },
152 { "goaway", PRIV_GOAWAY },
153 #if _FFR_PRIV_NOACTUALRECIPIENT
154 { "noactualrecipient", PRIV_NOACTUALRECIPIENT },
155 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
160 ** DontBlameSendmail values
163 struct dbsval DontBlameSendmailValues[] =
165 { "safe", DBS_SAFE },
166 { "assumesafechown", DBS_ASSUMESAFECHOWN },
167 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
168 { "groupwritableforwardfilesafe",
169 DBS_GROUPWRITABLEFORWARDFILESAFE },
170 { "groupwritableincludefilesafe",
171 DBS_GROUPWRITABLEINCLUDEFILESAFE },
172 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
173 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
174 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
175 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
176 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
177 { "linkedaliasfileinwritabledir",
178 DBS_LINKEDALIASFILEINWRITABLEDIR },
179 { "linkedclassfileinwritabledir",
180 DBS_LINKEDCLASSFILEINWRITABLEDIR },
181 { "linkedforwardfileinwritabledir",
182 DBS_LINKEDFORWARDFILEINWRITABLEDIR },
183 { "linkedincludefileinwritabledir",
184 DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
185 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
186 { "linkedserviceswitchfileinwritabledir",
187 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
188 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
189 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
190 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
191 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
192 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
193 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
194 { "forwardfileingroupwritabledirpath",
195 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
196 { "includefileingroupwritabledirpath",
197 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
198 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
199 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
200 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
201 { "forwardfileinunsafedirpathsafe",
202 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
203 { "includefileinunsafedirpathsafe",
204 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
205 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
206 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
207 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
208 { "truststickybit", DBS_TRUSTSTICKYBIT },
209 { "dontwarnforwardfileinunsafedirpath",
210 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
211 { "insufficiententropy", DBS_INSUFFICIENTENTROPY },
212 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
213 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
214 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
215 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
216 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
217 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
218 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
219 #if _FFR_GROUPREADABLEAUTHINFOFILE
220 { "groupreadableadefaultauthinfofile",
221 DBS_GROUPREADABLEAUTHINFOFILE },
222 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
227 ** Miscellaneous stuff.
230 int DtableSize = 50; /* max open files; reset in 4.2bsd */
232 ** SETDEFAULTS -- set default values
234 ** Some of these must be initialized using direct code since they
235 ** depend on run-time values. So let's do all of them this way.
238 ** e -- the default envelope.
244 ** Initializes a bunch of global variables to their
249 #define HOURS * 60 MINUTES
250 #define DAYS * 24 HOURS
252 #ifndef MAXRULERECURSION
253 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
254 #endif /* ! MAXRULERECURSION */
258 register ENVELOPE *e;
264 numprocs = get_num_procs_online();
265 SpaceSub = ' '; /* option B */
266 QueueLA = 8 * numprocs; /* option x */
267 RefuseLA = 12 * numprocs; /* option X */
268 WkRecipFact = 30000L; /* option y */
269 WkClassFact = 1800L; /* option z */
270 WkTimeFact = 90000L; /* option Z */
271 QueueFactor = WkRecipFact * 20; /* option q */
272 QueueMode = QM_NORMAL; /* what queue items to act upon */
273 FileMode = (RealUid != geteuid()) ? 0644 : 0600;
275 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
276 /* option QueueFileMode */
278 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
279 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
280 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
282 DefUid = pw->pw_uid; /* option u */
283 DefGid = pw->pw_gid; /* option g */
284 DefUser = newstr(pw->pw_name);
288 DefUid = 1; /* option u */
289 DefGid = 1; /* option g */
294 sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
295 DefUser != NULL ? DefUser : "<1:1>",
296 (int) DefUid, (int) DefGid);
297 CheckpointInterval = 10; /* option C */
298 MaxHopCount = 25; /* option h */
299 set_delivery_mode(SM_FORK, e); /* option d */
300 e->e_errormode = EM_PRINT; /* option e */
303 e->e_xfqgrp = NOQGRP;
304 e->e_xfqdir = NOQDIR;
305 e->e_ctime = curtime();
306 SevenBitInput = false; /* option 7 */
307 MaxMciCache = 1; /* option k */
308 MciCacheTimeout = 5 MINUTES; /* option K */
309 LogLevel = 9; /* option L */
313 inittimeouts(NULL, false); /* option r */
314 PrivacyFlags = PRIV_PUBLIC; /* option p */
315 MeToo = true; /* option m */
316 SendMIMEErrors = true; /* option f */
317 SuperSafe = SAFE_REALLY; /* option s */
318 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
320 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
322 MimeMode = MM_PASS8BIT;
323 #endif /* MIME8TO7 */
324 for (i = 0; i < MAXTOCLASS; i++)
326 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
327 TimeOuts.to_q_warning[i] = 0; /* option T */
329 ServiceSwitchFile = "/etc/mail/service.switch";
330 ServiceCacheMaxAge = (time_t) 10;
331 HostsFile = _PATH_HOSTS;
332 PidFile = newstr(_PATH_SENDMAILPID);
333 MustQuoteChars = "@,;:\\()[].'";
334 MciInfoTimeout = 30 MINUTES;
335 MaxRuleRecursion = MAXRULERECURSION;
336 MaxAliasRecursion = 10;
337 MaxMacroRecursion = 10;
338 ColonOkInAddr = true;
339 DontLockReadFiles = true;
340 DontProbeInterfaces = DPI_PROBEALL;
341 DoubleBounceAddr = "postmaster";
342 MaxHeadersLength = MAXHDRSLEN;
343 MaxMimeHeaderLength = MAXLINE;
344 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
345 MaxForwardEntries = 0;
348 AuthMechanisms = newstr(AUTH_MECHANISMS);
353 TLS_Srv_Opts = TLS_I_SRV;
354 #endif /* STARTTLS */
356 HesiodContext = NULL;
357 #endif /* HESIOD_INIT */
359 /* Detect if IPv6 is available at run time */
360 i = socket(AF_INET6, SOCK_STREAM, 0);
370 #endif /* NETINET6 */
371 ControlSocketName = NULL;
372 memset(&ConnectOnlyTo, '\0', sizeof ConnectOnlyTo);
373 DataFileBufferSize = 4096;
374 XscriptFileBufferSize = 4096;
375 for (i = 0; i < MAXRWSETS; i++)
376 RuleSetNames[i] = NULL;
378 InputFilters[0] = NULL;
380 RejectLogInterval = 3 HOURS;
381 #if REQUIRES_DIR_FSYNC
382 RequiresDirfsync = true;
383 #endif /* REQUIRES_DIR_FSYNC */
384 ConnectionRateWindowSize = 60;
393 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
399 struct passwd *defpwent;
400 static char defuserbuf[40];
402 DefUser = defuserbuf;
403 defpwent = sm_getpwuid(DefUid);
404 (void) sm_strlcpy(defuserbuf,
405 (defpwent == NULL || defpwent->pw_name == NULL)
406 ? "nobody" : defpwent->pw_name,
409 sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
410 (int) DefUid, DefUser);
413 ** SETUPQUEUES -- initialize default queues
415 ** The mqueue QUEUE structure gets filled in after readcf() but
416 ** we need something to point to now for the mailer setup,
417 ** which use "mqueue" as default queue.
425 MaxRunnersPerQueue = 1;
426 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof buf);
427 makequeue(buf, false);
430 ** SETUPMAILERS -- initialize default mailers
438 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
442 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
446 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
452 ** SETUPMAPS -- set up map classes
455 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
457 extern bool parse __P((MAP *, char *)); \
458 extern bool open __P((MAP *, int)); \
459 extern void close __P((MAP *)); \
460 extern char *lookup __P((MAP *, char *, char **, int *)); \
461 extern void store __P((MAP *, char *, char *)); \
462 s = stab(name, ST_MAPCLASS, ST_ENTER); \
463 s->s_mapclass.map_cname = name; \
464 s->s_mapclass.map_ext = ext; \
465 s->s_mapclass.map_cflags = flags; \
466 s->s_mapclass.map_parse = parse; \
467 s->s_mapclass.map_open = open; \
468 s->s_mapclass.map_close = close; \
469 s->s_mapclass.map_lookup = lookup; \
470 s->s_mapclass.map_store = store; \
479 # if DB_VERSION_MAJOR > 1
480 int major_v, minor_v, patch_v;
482 (void) db_version(&major_v, &minor_v, &patch_v);
483 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
486 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
487 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
488 major_v, minor_v, patch_v);
490 # endif /* DB_VERSION_MAJOR > 1 */
492 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
493 map_parseargs, hash_map_open, db_map_close,
494 db_map_lookup, db_map_store);
496 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
497 map_parseargs, bt_map_open, db_map_close,
498 db_map_lookup, db_map_store);
502 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
503 map_parseargs, ndbm_map_open, ndbm_map_close,
504 ndbm_map_lookup, ndbm_map_store);
508 MAPDEF("nis", NULL, MCF_ALIASOK,
509 map_parseargs, nis_map_open, null_map_close,
510 nis_map_lookup, null_map_store);
514 MAPDEF("nisplus", NULL, MCF_ALIASOK,
515 map_parseargs, nisplus_map_open, null_map_close,
516 nisplus_map_lookup, null_map_store);
520 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
521 ldapmap_parseargs, ldapmap_open, ldapmap_close,
522 ldapmap_lookup, null_map_store);
526 MAPDEF("ph", NULL, MCF_NOTPERSIST,
527 ph_map_parseargs, ph_map_open, ph_map_close,
528 ph_map_lookup, null_map_store);
532 /* IRIX 6.5 nsd support */
533 MAPDEF("nsd", NULL, MCF_ALIASOK,
534 map_parseargs, null_map_open, null_map_close,
535 nsd_map_lookup, null_map_store);
539 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
540 map_parseargs, hes_map_open, hes_map_close,
541 hes_map_lookup, null_map_store);
545 MAPDEF("netinfo", NULL, MCF_ALIASOK,
546 map_parseargs, ni_map_open, null_map_close,
547 ni_map_lookup, null_map_store);
551 MAPDEF("dns", NULL, 0,
552 dns_map_init, null_map_open, null_map_close,
553 dns_map_lookup, null_map_store);
558 # if _FFR_DNSMAP_ALIASABLE
559 MAPDEF("dns", NULL, MCF_ALIASOK,
560 dns_map_parseargs, dns_map_open, null_map_close,
561 dns_map_lookup, null_map_store);
562 # else /* _FFR_DNSMAP_ALIASABLE */
563 MAPDEF("dns", NULL, 0,
564 dns_map_parseargs, dns_map_open, null_map_close,
565 dns_map_lookup, null_map_store);
566 # endif /* _FFR_DNSMAP_ALIASABLE */
568 #endif /* NAMED_BIND */
571 /* best MX DNS lookup */
572 MAPDEF("bestmx", NULL, MCF_OPTFILE,
573 map_parseargs, null_map_open, null_map_close,
574 bestmx_map_lookup, null_map_store);
575 #endif /* NAMED_BIND */
577 MAPDEF("host", NULL, 0,
578 host_map_init, null_map_open, null_map_close,
579 host_map_lookup, null_map_store);
581 MAPDEF("text", NULL, MCF_ALIASOK,
582 map_parseargs, text_map_open, null_map_close,
583 text_map_lookup, null_map_store);
585 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
586 map_parseargs, stab_map_open, null_map_close,
587 stab_map_lookup, stab_map_store);
589 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
590 map_parseargs, impl_map_open, impl_map_close,
591 impl_map_lookup, impl_map_store);
593 /* access to system passwd file */
594 MAPDEF("user", NULL, MCF_OPTFILE,
595 map_parseargs, user_map_open, null_map_close,
596 user_map_lookup, null_map_store);
599 MAPDEF("dequote", NULL, 0,
600 dequote_init, null_map_open, null_map_close,
601 dequote_map, null_map_store);
604 MAPDEF("regex", NULL, 0,
605 regex_map_init, null_map_open, null_map_close,
606 regex_map_lookup, null_map_store);
607 #endif /* MAP_REGEX */
611 MAPDEF("userdb", ".db", 0,
612 map_parseargs, null_map_open, null_map_close,
613 udb_map_lookup, null_map_store);
616 /* arbitrary programs */
617 MAPDEF("program", NULL, MCF_ALIASOK,
618 map_parseargs, null_map_open, null_map_close,
619 prog_map_lookup, null_map_store);
622 MAPDEF("sequence", NULL, MCF_ALIASOK,
623 seq_map_parse, null_map_open, null_map_close,
624 seq_map_lookup, seq_map_store);
626 /* switched interface to sequenced maps */
627 MAPDEF("switch", NULL, MCF_ALIASOK,
628 map_parseargs, switch_map_open, null_map_close,
629 seq_map_lookup, seq_map_store);
631 /* null map lookup -- really for internal use only */
632 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
633 map_parseargs, null_map_open, null_map_close,
634 null_map_lookup, null_map_store);
636 /* syslog map -- logs information to syslog */
637 MAPDEF("syslog", NULL, 0,
638 syslog_map_parseargs, null_map_open, null_map_close,
639 syslog_map_lookup, null_map_store);
641 /* macro storage map -- rulesets can set macros */
642 MAPDEF("macro", NULL, 0,
643 dequote_init, null_map_open, null_map_close,
644 macro_map_lookup, null_map_store);
646 /* arithmetic map -- add/subtract/compare */
647 MAPDEF("arith", NULL, 0,
648 dequote_init, null_map_open, null_map_close,
649 arith_map_lookup, null_map_store);
652 /* arbitrary daemons */
653 MAPDEF("socket", NULL, MCF_ALIASOK,
654 map_parseargs, socket_map_open, socket_map_close,
655 socket_map_lookup, null_map_store);
656 #endif /* SOCKETMAP */
660 /* bogus map -- always return tempfail */
661 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
662 map_parseargs, null_map_open, null_map_close,
663 bogus_map_lookup, null_map_store);
669 ** INITHOSTMAPS -- initial host-dependent maps
671 ** This should act as an interface to any local service switch
672 ** provided by the host operating system.
681 ** Should define maps "host" and "users" as necessary
682 ** for this OS. If they are not defined, they will get
683 ** a default value later. It should check to make sure
684 ** they are not defined first, since it's possible that
685 ** the config file has provided an override.
693 char *maptype[MAXMAPSTACK];
694 short mapreturn[MAXMAPACTIONS];
698 ** Set up default hosts maps.
702 nmaps = switch_map_find("hosts", maptype, mapreturn);
703 for (i = 0; i < nmaps; i++)
705 if (strcmp(maptype[i], "files") == 0 &&
706 stab("hosts.files", ST_MAP, ST_FIND) == NULL)
708 (void) sm_strlcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts",
710 (void) makemapentry(buf);
713 else if (strcmp(maptype[i], "dns") == 0 &&
714 stab("hosts.dns", ST_MAP, ST_FIND) == NULL)
716 (void) sm_strlcpy(buf, "hosts.dns dns A", sizeof buf);
717 (void) makemapentry(buf);
719 # endif /* NAMED_BIND */
721 else if (strcmp(maptype[i], "nisplus") == 0 &&
722 stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL)
724 (void) sm_strlcpy(buf, "hosts.nisplus nisplus -k name -v address hosts.org_dir",
726 (void) makemapentry(buf);
728 # endif /* NISPLUS */
730 else if (strcmp(maptype[i], "nis") == 0 &&
731 stab("hosts.nis", ST_MAP, ST_FIND) == NULL)
733 (void) sm_strlcpy(buf, "hosts.nis nis -k 0 -v 1 hosts.byname",
735 (void) makemapentry(buf);
739 else if (strcmp(maptype[i], "netinfo") == 0 &&
740 stab("hosts.netinfo", ST_MAP, ST_FIND) == NULL)
742 (void) sm_strlcpy(buf, "hosts.netinfo netinfo -v name /machines",
744 (void) makemapentry(buf);
746 # endif /* NETINFO */
751 ** Make sure we have a host map.
754 if (stab("host", ST_MAP, ST_FIND) == NULL)
756 /* user didn't initialize: set up host map */
757 (void) sm_strlcpy(buf, "host host", sizeof buf);
759 if (ConfigLevel >= 2)
760 (void) sm_strlcat(buf, " -a. -D", sizeof buf);
761 #endif /* NAMED_BIND */
762 (void) makemapentry(buf);
766 ** Set up default aliases maps
769 nmaps = switch_map_find("aliases", maptype, mapreturn);
770 for (i = 0; i < nmaps; i++)
772 if (strcmp(maptype[i], "files") == 0 &&
773 stab("aliases.files", ST_MAP, ST_FIND) == NULL)
775 (void) sm_strlcpy(buf, "aliases.files null",
777 (void) makemapentry(buf);
780 else if (strcmp(maptype[i], "nisplus") == 0 &&
781 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
783 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
785 (void) makemapentry(buf);
789 else if (strcmp(maptype[i], "nis") == 0 &&
790 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
792 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
794 (void) makemapentry(buf);
798 else if (strcmp(maptype[i], "netinfo") == 0 &&
799 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
801 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
803 (void) makemapentry(buf);
807 else if (strcmp(maptype[i], "hesiod") == 0 &&
808 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
810 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
812 (void) makemapentry(buf);
816 if (stab("aliases", ST_MAP, ST_FIND) == NULL)
818 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof buf);
819 (void) makemapentry(buf);
822 #if 0 /* "user" map class is a better choice */
824 ** Set up default users maps.
827 nmaps = switch_map_find("passwd", maptype, mapreturn);
828 for (i = 0; i < nmaps; i++)
830 if (strcmp(maptype[i], "files") == 0 &&
831 stab("users.files", ST_MAP, ST_FIND) == NULL)
833 (void) sm_strlcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd",
835 (void) makemapentry(buf);
838 else if (strcmp(maptype[i], "nisplus") == 0 &&
839 stab("users.nisplus", ST_MAP, ST_FIND) == NULL)
841 (void) sm_strlcpy(buf, "users.nisplus nisplus -m -kname -vhome passwd.org_dir",
843 (void) makemapentry(buf);
845 # endif /* NISPLUS */
847 else if (strcmp(maptype[i], "nis") == 0 &&
848 stab("users.nis", ST_MAP, ST_FIND) == NULL)
850 (void) sm_strlcpy(buf, "users.nis nis -m passwd.byname",
852 (void) makemapentry(buf);
856 else if (strcmp(maptype[i], "hesiod") == 0 &&
857 stab("users.hesiod", ST_MAP, ST_FIND) == NULL)
859 (void) sm_strlcpy(buf, "users.hesiod hesiod", sizeof buf);
860 (void) makemapentry(buf);
864 if (stab("users", ST_MAP, ST_FIND) == NULL)
866 (void) sm_strlcpy(buf, "users switch -m passwd", sizeof buf);
867 (void) makemapentry(buf);
872 ** SWITCH_MAP_FIND -- find the list of types associated with a map
874 ** This is the system-dependent interface to the service switch.
877 ** service -- the name of the service of interest.
878 ** maptype -- an out-array of strings containing the types
879 ** of access to use for this service. There can
880 ** be at most MAXMAPSTACK types for a single service.
881 ** mapreturn -- an out-array of return information bitmaps
885 ** The number of map types filled in, or -1 for failure.
888 ** Preserves errno so nothing in the routine clobbers it.
891 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
892 # define _USE_SUN_NSSWITCH_
893 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
895 #if _FFR_HPUX_NSSWITCH
897 # define _USE_SUN_NSSWITCH_
899 #endif /* _FFR_HPUX_NSSWITCH */
901 #ifdef _USE_SUN_NSSWITCH_
902 # include <nsswitch.h>
903 #endif /* _USE_SUN_NSSWITCH_ */
905 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
906 # define _USE_DEC_SVC_CONF_
907 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
909 #ifdef _USE_DEC_SVC_CONF_
910 # include <sys/svcinfo.h>
911 #endif /* _USE_DEC_SVC_CONF_ */
914 switch_map_find(service, maptype, mapreturn)
916 char *maptype[MAXMAPSTACK];
917 short mapreturn[MAXMAPACTIONS];
920 int save_errno = errno;
922 #ifdef _USE_SUN_NSSWITCH_
923 struct __nsw_switchconfig *nsw_conf;
924 enum __nsw_parse_err pserr;
925 struct __nsw_lookup *lk;
926 static struct __nsw_lookup lkp0 =
927 { "files", {1, 0, 0, 0}, NULL, NULL };
928 static struct __nsw_switchconfig lkp_default =
929 { 0, "sendmail", 3, &lkp0 };
931 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
932 mapreturn[svcno] = 0;
934 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
935 lk = lkp_default.lookups;
937 lk = nsw_conf->lookups;
939 while (lk != NULL && svcno < MAXMAPSTACK)
941 maptype[svcno] = lk->service_name;
942 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
943 mapreturn[MA_NOTFOUND] |= 1 << svcno;
944 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
945 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
946 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
947 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
953 #endif /* _USE_SUN_NSSWITCH_ */
955 #ifdef _USE_DEC_SVC_CONF_
956 struct svcinfo *svcinfo;
959 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
960 mapreturn[svcno] = 0;
965 if (strcmp(service, "hosts") == 0)
967 else if (strcmp(service, "aliases") == 0)
969 else if (strcmp(service, "passwd") == 0)
976 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
978 switch (svcinfo->svcpath[svc][svcno])
981 maptype[svcno] = "files";
985 maptype[svcno] = "nis";
989 maptype[svcno] = "dns";
994 maptype[svcno] = "hesiod";
996 # endif /* SVC_HESIOD */
1005 #endif /* _USE_DEC_SVC_CONF_ */
1007 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
1009 ** Fall-back mechanism.
1013 static time_t servicecachetime; /* time service switch was cached */
1014 time_t now = curtime();
1016 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1017 mapreturn[svcno] = 0;
1019 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
1021 /* (re)read service switch */
1022 register SM_FILE_T *fp;
1023 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
1025 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
1030 servicecachetime = now;
1031 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
1036 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
1037 sizeof buf) != NULL)
1041 p = strpbrk(buf, "#\n");
1044 p = strpbrk(buf, " \t");
1051 sm_syslog(LOG_ERR, NOQID,
1052 "Bad line on %.100s: %.100s",
1063 ** Find/allocate space for this service entry.
1064 ** Space for all of the service strings
1065 ** are allocated at once. This means
1066 ** that we only have to free the first
1067 ** one to free all of them.
1070 st = stab(buf, ST_SERVICE, ST_ENTER);
1071 if (st->s_service[0] != NULL)
1072 sm_free((void *) st->s_service[0]); /* XXX */
1074 for (svcno = 0; svcno < MAXMAPSTACK; )
1078 st->s_service[svcno++] = p;
1079 p = strpbrk(p, " \t");
1086 if (svcno < MAXMAPSTACK)
1087 st->s_service[svcno] = NULL;
1089 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1093 /* look up entry in cache */
1094 st = stab(service, ST_SERVICE, ST_FIND);
1095 if (st != NULL && st->s_service[0] != NULL)
1099 while (svcno < MAXMAPSTACK)
1101 maptype[svcno] = st->s_service[svcno];
1102 if (maptype[svcno++] == NULL)
1108 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1110 #if !defined(_USE_SUN_NSSWITCH_)
1111 /* if the service file doesn't work, use an absolute fallback */
1112 # ifdef _USE_DEC_SVC_CONF_
1114 # endif /* _USE_DEC_SVC_CONF_ */
1115 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1116 mapreturn[svcno] = 0;
1118 if (strcmp(service, "aliases") == 0)
1120 maptype[svcno++] = "files";
1121 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1122 maptype[svcno++] = "netinfo";
1123 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
1124 # ifdef AUTO_NIS_ALIASES
1126 maptype[svcno++] = "nisplus";
1127 # endif /* NISPLUS */
1129 maptype[svcno++] = "nis";
1131 # endif /* AUTO_NIS_ALIASES */
1135 if (strcmp(service, "hosts") == 0)
1138 maptype[svcno++] = "dns";
1139 # else /* NAMED_BIND */
1140 # if defined(sun) && !defined(BSD)
1142 maptype[svcno++] = "nis";
1143 # endif /* defined(sun) && !defined(BSD) */
1144 # endif /* NAMED_BIND */
1145 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1146 maptype[svcno++] = "netinfo";
1147 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
1148 maptype[svcno++] = "files";
1154 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1157 ** USERNAME -- return the user id of the logged in user.
1163 ** The login name of the logged in user.
1169 ** The return value is statically allocated.
1175 static char *myname = NULL;
1176 extern char *getlogin();
1177 register struct passwd *pw;
1179 /* cache the result */
1182 myname = getlogin();
1183 if (myname == NULL || myname[0] == '\0')
1185 pw = sm_getpwuid(RealUid);
1187 myname = pw->pw_name;
1191 uid_t uid = RealUid;
1193 if ((pw = sm_getpwnam(myname)) == NULL ||
1194 (uid != 0 && uid != pw->pw_uid))
1196 pw = sm_getpwuid(uid);
1198 myname = pw->pw_name;
1201 if (myname == NULL || myname[0] == '\0')
1203 syserr("554 5.3.0 Who are you?");
1204 myname = "postmaster";
1206 else if (strpbrk(myname, ",;:/|\"\\") != NULL)
1207 myname = addquotes(myname, NULL);
1209 myname = sm_pstrdup_x(myname);
1214 ** TTYPATH -- Get the path of the user's tty
1216 ** Returns the pathname of the user's tty. Returns NULL if
1217 ** the user is not logged in or if s/he has write permission
1224 ** pathname of the user's tty.
1225 ** NULL if not logged in or write permission denied.
1231 ** Return value is in a local buffer.
1241 register char *pathn;
1242 extern char *ttyname();
1243 extern char *getlogin();
1245 /* compute the pathname of the controlling tty */
1246 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
1247 (pathn = ttyname(0)) == NULL)
1253 /* see if we have write permission */
1254 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
1260 /* see if the user is logged in */
1261 if (getlogin() == NULL)
1268 ** CHECKCOMPAT -- check for From and To person compatible.
1270 ** This routine can be supplied on a per-installation basis
1271 ** to determine whether a person is allowed to send a message.
1272 ** This allows restriction of certain types of internet
1273 ** forwarding or registration of users.
1275 ** If the hosts are found to be incompatible, an error
1276 ** message should be given using "usrerr" and an EX_ code
1277 ** should be returned. You can also set to->q_status to
1278 ** a DSN-style status code.
1280 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1281 ** body during the return-to-sender function; this should be done
1282 ** on huge messages. This bit may already be set by the ESMTP
1286 ** to -- the person being sent to.
1292 ** none (unless you include the usrerr stuff)
1297 register ADDRESS *to;
1298 register ENVELOPE *e;
1301 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1302 to->q_paddr, e->e_from.q_paddr);
1305 /* this code is intended as an example only */
1308 s = stab("arpa", ST_MAILER, ST_FIND);
1309 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
1310 to->q_mailer == s->s_mailer)
1312 usrerr("553 No ARPA mail through this machine: see your system administration");
1313 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1314 to->q_status = "5.7.1";
1315 return EX_UNAVAILABLE;
1317 #endif /* EXAMPLE_CODE */
1321 ** INIT_MD -- do machine dependent initializations
1323 ** Systems that have global modes that should be set should do
1324 ** them here rather than in main.
1328 # include <compat.h>
1329 #endif /* _AUX_SOURCE */
1332 # include <shares.h>
1333 #endif /* SHARE_V1 */
1341 setcompat(getcompat() | COMPAT_BSDPROT);
1342 #endif /* _AUX_SOURCE */
1344 #ifdef SUN_EXTENSIONS
1346 #endif /* SUN_EXTENSIONS */
1349 /* keep gethostby*() from stripping the local domain name */
1350 set_domain_trim_off();
1351 #endif /* _CONVEX_SOURCE */
1354 ** Due to QNX's network distributed nature, you can target a tcpip
1355 ** stack on a different node in the qnx network; this patch lets
1356 ** this feature work. The __sock_locate() must be done before the
1357 ** environment is clear.
1360 #endif /* __QNX__ */
1361 #if SECUREWARE || defined(_SCO_unix_)
1362 set_auth_parameters(argc, argv);
1366 ** This is required for highest security levels (the kernel
1367 ** won't let it call set*uid() or run setuid binaries without
1368 ** it). It may be necessary on other SECUREWARE systems.
1371 if (getluid() == -1)
1373 # endif /* _SCO_unix_ */
1374 #endif /* SECUREWARE || defined(_SCO_unix_) */
1377 #ifdef VENDOR_DEFAULT
1378 VendorCode = VENDOR_DEFAULT;
1379 #else /* VENDOR_DEFAULT */
1380 VendorCode = VENDOR_BERKELEY;
1381 #endif /* VENDOR_DEFAULT */
1384 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1386 ** Called once, on startup.
1389 ** e -- the global envelope.
1395 ** vendor-dependent.
1399 init_vendor_macros(e)
1400 register ENVELOPE *e;
1404 ** GETLA -- get the current load average
1406 ** This code stolen from la.c.
1412 ** The current load average as an integer.
1418 /* try to guess what style of load average we have */
1419 #define LA_ZERO 1 /* always return load average as zero */
1420 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1421 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1422 #define LA_SUBR 4 /* call getloadavg */
1423 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1424 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1425 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1426 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1427 #define LA_DGUX 9 /* special DGUX implementation */
1428 #define LA_HPUX 10 /* special HPUX implementation */
1429 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1430 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1431 #define LA_DEVSHORT 13 /* read short from a device */
1432 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1433 #define LA_PSET 15 /* Solaris per-processor-set load average */
1434 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1436 /* do guesses based on general OS type */
1438 # define LA_TYPE LA_ZERO
1439 #endif /* ! LA_TYPE */
1442 # if defined(unixpc)
1444 # endif /* defined(unixpc) */
1446 # if defined(__alpha) || defined(IRIX)
1448 # endif /* defined(__alpha) || defined(IRIX) */
1450 #endif /* ! FSHIFT */
1454 #endif /* ! FSHIFT */
1457 # define FSCALE (1 << FSHIFT)
1458 #endif /* ! FSCALE */
1462 # define LA_AVENRUN "avenrun"
1463 # else /* SYSTEM5 */
1464 # define LA_AVENRUN "_avenrun"
1465 # endif /* SYSTEM5 */
1466 #endif /* ! LA_AVENRUN */
1468 /* _PATH_KMEM should be defined in <paths.h> */
1470 # define _PATH_KMEM "/dev/kmem"
1471 #endif /* ! _PATH_KMEM */
1473 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1477 /* _PATH_UNIX should be defined in <paths.h> */
1479 # if defined(SYSTEM5)
1480 # define _PATH_UNIX "/unix"
1481 # else /* defined(SYSTEM5) */
1482 # define _PATH_UNIX "/vmunix"
1483 # endif /* defined(SYSTEM5) */
1484 # endif /* ! _PATH_UNIX */
1488 # else /* _AUX_SOURCE */
1494 # endif /* _AUX_SOURCE */
1495 # define X_AVENRUN 0
1501 static int kmem = -1;
1502 # if LA_TYPE == LA_INT
1504 # else /* LA_TYPE == LA_INT */
1505 # if LA_TYPE == LA_SHORT
1508 # if LA_TYPE == LA_LONGLONG
1509 long long avenrun[3];
1510 # else /* LA_TYPE == LA_LONGLONG */
1512 # endif /* LA_TYPE == LA_LONGLONG */
1513 # endif /* LA_TYPE == LA_SHORT */
1514 # endif /* LA_TYPE == LA_INT */
1515 extern off_t lseek();
1520 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
1521 sizeof Nl[X_AVENRUN].n_name);
1522 Nl[1].n_name[0] = '\0';
1523 # endif /* _AUX_SOURCE */
1525 # if defined(_AIX3) || defined(_AIX4)
1526 if (knlist(Nl, 1, sizeof Nl[0]) < 0)
1527 # else /* defined(_AIX3) || defined(_AIX4) */
1528 if (nlist(_PATH_UNIX, Nl) < 0)
1529 # endif /* defined(_AIX3) || defined(_AIX4) */
1532 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
1533 sm_errstring(errno));
1536 if (Nl[X_AVENRUN].n_value == 0)
1539 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1540 _PATH_UNIX, LA_AVENRUN);
1543 # ifdef NAMELISTMASK
1544 Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1545 # endif /* NAMELISTMASK */
1547 kmem = open(_PATH_KMEM, 0, 0);
1551 sm_dprintf("getla: open(/dev/kmem): %s\n",
1552 sm_errstring(errno));
1555 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1556 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1559 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1560 sm_errstring(errno));
1567 sm_dprintf("getla: symbol address = %#lx\n",
1568 (unsigned long) Nl[X_AVENRUN].n_value);
1569 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1570 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1574 sm_dprintf("getla: lseek or read: %s\n",
1575 sm_errstring(errno));
1578 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1581 # if LA_TYPE == LA_SHORT
1582 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1584 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1585 # else /* LA_TYPE == LA_SHORT */
1586 # if LA_TYPE == LA_LONGLONG
1587 sm_dprintf("getla: avenrun = %lld", avenrun[0]);
1589 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
1590 # else /* LA_TYPE == LA_LONGLONG */
1591 sm_dprintf("getla: avenrun = %ld", avenrun[0]);
1593 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
1594 # endif /* LA_TYPE == LA_LONGLONG */
1595 # endif /* LA_TYPE == LA_SHORT */
1599 sm_dprintf("getla: %d\n",
1600 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1601 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1602 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1605 sm_dprintf("getla: avenrun = %g", avenrun[0]);
1607 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
1611 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1612 return ((int) (avenrun[0] + 0.5));
1613 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1616 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1618 #if LA_TYPE == LA_READKSYM
1620 # include <sys/ksym.h>
1626 static int kmem = -1;
1628 struct mioc_rksym mirk;
1632 kmem = open("/dev/kmem", 0, 0);
1636 sm_dprintf("getla: open(/dev/kmem): %s\n",
1637 sm_errstring(errno));
1640 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1641 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1644 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1645 sm_errstring(errno));
1651 mirk.mirk_symname = LA_AVENRUN;
1652 mirk.mirk_buf = avenrun;
1653 mirk.mirk_buflen = sizeof(avenrun);
1654 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
1657 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1658 sm_errstring(errno));
1663 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1665 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1669 sm_dprintf("getla: %d\n",
1670 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1671 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1674 #endif /* LA_TYPE == LA_READKSYM */
1676 #if LA_TYPE == LA_DGUX
1678 # include <sys/dg_sys_info.h>
1683 struct dg_sys_info_load_info load_info;
1685 dg_sys_info((long *)&load_info,
1686 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1689 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1691 return ((int) (load_info.one_minute + 0.5));
1694 #endif /* LA_TYPE == LA_DGUX */
1696 #if LA_TYPE == LA_HPUX
1698 /* forward declarations to keep gcc from complaining */
1703 struct pst_diskinfo;
1704 struct pst_processor;
1706 struct pst_swapinfo;
1708 # include <sys/param.h>
1709 # include <sys/pstat.h>
1714 struct pst_dynamic pstd;
1716 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1717 (size_t) 1, 0) == -1)
1721 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1723 return (int) (pstd.psd_avg_1_min + 0.5);
1726 #endif /* LA_TYPE == LA_HPUX */
1728 #if LA_TYPE == LA_SUBR
1735 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1738 sm_dprintf("getla: getloadavg failed: %s",
1739 sm_errstring(errno));
1743 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1744 return ((int) (avenrun[0] + 0.5));
1747 #endif /* LA_TYPE == LA_SUBR */
1749 #if LA_TYPE == LA_MACH
1752 ** This has been tested on NEXTSTEP release 2.1/3.X.
1755 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1756 # include <mach/mach.h>
1757 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1759 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1764 processor_set_t default_set;
1765 kern_return_t error;
1766 unsigned int info_count;
1767 struct processor_set_basic_info info;
1770 error = processor_set_default(host_self(), &default_set);
1771 if (error != KERN_SUCCESS)
1774 sm_dprintf("getla: processor_set_default failed: %s",
1775 sm_errstring(errno));
1778 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1779 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1780 &host, (processor_set_info_t)&info,
1781 &info_count) != KERN_SUCCESS)
1784 sm_dprintf("getla: processor_set_info failed: %s",
1785 sm_errstring(errno));
1789 sm_dprintf("getla: %d\n",
1790 (int) ((info.load_average + (LOAD_SCALE / 2)) /
1792 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1795 #endif /* LA_TYPE == LA_MACH */
1797 #if LA_TYPE == LA_PROCSTR
1798 # if SM_CONF_BROKEN_STRTOD
1799 ERROR: This OS has most likely a broken strtod() implemenentation.
1800 ERROR: The function is required for getla().
1801 ERROR: Check the compilation options _LA_PROCSTR and
1802 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
1803 # endif /* SM_CONF_BROKEN_STRTOD */
1806 ** Read /proc/loadavg for the load average. This is assumed to be
1807 ** in a format like "0.15 0.12 0.06".
1809 ** Initially intended for Linux. This has been in the kernel
1810 ** since at least 0.99.15.
1813 # ifndef _PATH_LOADAVG
1814 # define _PATH_LOADAVG "/proc/loadavg"
1815 # endif /* ! _PATH_LOADAVG */
1821 register int result;
1824 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
1829 sm_dprintf("getla: sm_io_open(%s): %s\n",
1830 _PATH_LOADAVG, sm_errstring(errno));
1833 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
1834 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1838 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1839 result, sm_errstring(errno));
1844 sm_dprintf("getla(): %.2f\n", avenrun);
1846 return ((int) (avenrun + 0.5));
1849 #endif /* LA_TYPE == LA_PROCSTR */
1851 #if LA_TYPE == LA_IRIX6
1853 # include <sys/sysmp.h>
1856 # define CAST_SYSMP(x) (x)
1857 # else /* _UNICOSMP */
1858 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1859 # endif /* _UNICOSMP */
1865 static int kmem = -1;
1870 kmem = open(_PATH_KMEM, 0, 0);
1874 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
1875 sm_errstring(errno));
1878 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1879 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1882 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1883 sm_errstring(errno));
1890 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
1892 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1895 sm_dprintf("getla: lseek or read: %s\n",
1896 sm_errstring(errno));
1901 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
1903 sm_dprintf(", %ld, %ld",
1904 (long int) avenrun[1], (long int) avenrun[2]);
1909 sm_dprintf("getla: %d\n",
1910 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1911 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1914 #endif /* LA_TYPE == LA_IRIX6 */
1916 #if LA_TYPE == LA_KSTAT
1923 static kstat_ctl_t *kc = NULL;
1924 static kstat_t *ksp = NULL;
1928 if (kc == NULL) /* if not initialized before */
1933 sm_dprintf("getla: kstat_open(): %s\n",
1934 sm_errstring(errno));
1938 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
1942 sm_dprintf("getla: kstat_lookup(): %s\n",
1943 sm_errstring(errno));
1946 if (kstat_read(kc, ksp, NULL) < 0)
1949 sm_dprintf("getla: kstat_read(): %s\n",
1950 sm_errstring(errno));
1953 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
1954 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
1955 /* kstat_close(kc); /o do not close for fast access */
1959 #endif /* LA_TYPE == LA_KSTAT */
1961 #if LA_TYPE == LA_DEVSHORT
1964 ** Read /dev/table/avenrun for the load average. This should contain
1965 ** three shorts for the 1, 5, and 15 minute loads. We only read the
1966 ** first, since that's all we care about.
1968 ** Intended for SCO OpenServer 5.
1971 # ifndef _PATH_AVENRUN
1972 # define _PATH_AVENRUN "/dev/table/avenrun"
1973 # endif /* ! _PATH_AVENRUN */
1978 static int afd = -1;
1985 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
1989 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
1992 sm_syslog(LOG_ERR, NOQID,
1993 "can't open %s: %s",
1994 _PATH_AVENRUN, sm_errstring(errno));
1999 r = read(afd, &avenrun, sizeof avenrun);
2002 sm_dprintf("getla: avenrun = %d\n", avenrun);
2003 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
2005 sm_dprintf("getla: %d\n", loadav);
2009 #endif /* LA_TYPE == LA_DEVSHORT */
2011 #if LA_TYPE == LA_ALPHAOSF
2014 # include <sys/table.h>
2020 struct tbl_loadavg tab;
2022 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
2025 sm_dprintf("getla: table %s\n", sm_errstring(errno));
2030 sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
2033 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
2036 ave = (int) (tab.tl_avenrun.d[2] + 0.5);
2039 sm_dprintf("getla: %d\n", ave);
2044 #endif /* LA_TYPE == LA_ALPHAOSF */
2046 #if LA_TYPE == LA_PSET
2053 if (pset_getloadavg(PS_MYID, avenrun,
2054 sizeof(avenrun) / sizeof(avenrun[0])) < 0)
2057 sm_dprintf("getla: pset_getloadavg failed: %s",
2058 sm_errstring(errno));
2062 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
2063 return ((int) (avenrun[0] + 0.5));
2066 #endif /* LA_TYPE == LA_PSET */
2068 #if LA_TYPE == LA_ZERO
2074 sm_dprintf("getla: ZERO\n");
2078 #endif /* LA_TYPE == LA_ZERO */
2081 * Copyright 1989 Massachusetts Institute of Technology
2083 * Permission to use, copy, modify, distribute, and sell this software and its
2084 * documentation for any purpose is hereby granted without fee, provided that
2085 * the above copyright notice appear in all copies and that both that
2086 * copyright notice and this permission notice appear in supporting
2087 * documentation, and that the name of M.I.T. not be used in advertising or
2088 * publicity pertaining to distribution of the software without specific,
2089 * written prior permission. M.I.T. makes no representations about the
2090 * suitability of this software for any purpose. It is provided "as is"
2091 * without express or implied warranty.
2093 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2094 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2095 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2096 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2097 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2098 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2100 * Authors: Many and varied...
2103 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2105 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2110 # include <apollo/base.h>
2113 int getloadavg( call_data )
2114 caddr_t call_data; /* pointer to (double) return value */
2116 double *avenrun = (double *) call_data;
2121 proc1_$get_loadav(loadav, &st);
2122 *avenrun = loadav[0] / (double) (1 << 16);
2127 ** SM_GETLA -- get the current load average
2136 ** Set CurrentLA to the current load average.
2137 ** Set {load_avg} in GlobalMacros to the current load average.
2145 CurrentLA = getla();
2146 (void) sm_snprintf(labuf, sizeof labuf, "%d", CurrentLA);
2147 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
2150 ** SHOULDQUEUE -- should this message be queued or sent?
2152 ** Compares the message cost to the load average to decide.
2154 ** Note: Do NOT change this API! It is documented in op.me
2155 ** and theoretically the user can change this function...
2158 ** pri -- the priority of the message in question.
2159 ** ct -- the message creation time (unused, but see above).
2162 ** true -- if this message should be queued up for the
2164 ** false -- if the load is low enough to send this message.
2172 shouldqueue(pri, ct)
2179 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2181 if (CurrentLA < QueueLA)
2184 sm_dprintf("false (CurrentLA < QueueLA)\n");
2187 # if 0 /* this code is reported to cause oscillation around RefuseLA */
2188 if (CurrentLA >= RefuseLA && QueueLA < RefuseLA)
2191 sm_dprintf("TRUE (CurrentLA >= RefuseLA)\n");
2195 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
2197 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
2201 ** REFUSECONNECTIONS -- decide if connections should be refused
2204 ** name -- daemon name (for error messages only)
2205 ** e -- the current envelope.
2206 ** d -- number of daemon
2207 ** active -- was this daemon actually active?
2210 ** true if incoming SMTP connections should be refused
2212 ** false if we should accept new work.
2215 ** Sets process title when it is rejecting connections.
2219 refuseconnections(name, e, d, active)
2225 static time_t lastconn[MAXDAEMONS];
2226 static int conncnt[MAXDAEMONS];
2227 static time_t firstrejtime[MAXDAEMONS];
2228 static time_t nextlogtime[MAXDAEMONS];
2236 SM_ASSERT(d < MAXDAEMONS);
2237 if (ConnRateThrottle > 0)
2244 if (now != lastconn[d])
2249 else if (conncnt[d]++ > ConnRateThrottle)
2251 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2252 /* sleep to flatten out connection load */
2253 sm_setproctitle(true, e, D_MSG_CRT,
2254 name, ConnRateThrottle);
2256 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
2257 name, ConnRateThrottle);
2261 else if (now != lastconn[d])
2266 if (RefuseLA > 0 && CurrentLA >= RefuseLA)
2270 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2271 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2272 sm_setproctitle(true, e, R_MSG_LA, name, CurrentLA);
2274 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA, name, CurrentLA);
2276 if (firstrejtime[d] == 0)
2278 firstrejtime[d] = now;
2279 nextlogtime[d] = now + RejectLogInterval;
2281 else if (nextlogtime[d] < now)
2283 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, name,
2284 pintvl(now - firstrejtime[d], true));
2285 nextlogtime[d] = now + RejectLogInterval;
2290 firstrejtime[d] = 0;
2292 if (DelayLA > 0 && CurrentLA >= DelayLA)
2295 static time_t log_delay = (time_t) 0;
2297 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2298 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2299 /* sleep to flatten out connection load */
2300 sm_setproctitle(true, e, D_MSG_LA, name, DelayLA);
2301 if (LogLevel > 8 && (now = curtime()) > log_delay)
2303 sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
2304 name, CurrentLA, DelayLA);
2305 log_delay = now + MIN_DELAY_LOG;
2310 if (MaxChildren > 0 && CurChildren >= MaxChildren)
2313 if (CurChildren >= MaxChildren)
2315 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2316 sm_setproctitle(true, e, R_MSG_CHILD,
2317 name, CurChildren, MaxChildren);
2319 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
2320 name, CurChildren, MaxChildren);
2327 ** SETPROCTITLE -- set process title for ps
2330 ** fmt -- a printf style format string.
2331 ** a, b, c -- possible parameters to fmt.
2337 ** Clobbers argv of our main procedure so ps(1) will
2338 ** display the title.
2341 #define SPT_NONE 0 /* don't use it at all */
2342 #define SPT_REUSEARGV 1 /* cover argv with title information */
2343 #define SPT_BUILTIN 2 /* use libc builtin */
2344 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2345 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2346 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2347 #define SPT_SCO 6 /* write kernel u. area */
2348 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2351 # define SPT_TYPE SPT_REUSEARGV
2352 #endif /* ! SPT_TYPE */
2355 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2357 # if SPT_TYPE == SPT_PSTAT
2358 # include <sys/pstat.h>
2359 # endif /* SPT_TYPE == SPT_PSTAT */
2360 # if SPT_TYPE == SPT_PSSTRINGS
2361 # include <machine/vmparam.h>
2362 # include <sys/exec.h>
2363 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2365 # define SPT_TYPE SPT_REUSEARGV
2366 # else /* ! PS_STRINGS */
2367 # ifndef NKPDE /* FreeBSD 2.0 */
2369 typedef unsigned int *pt_entry_t;
2370 # endif /* ! NKPDE */
2371 # endif /* ! PS_STRINGS */
2372 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2374 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2375 # define SETPROC_STATIC static
2376 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2377 # define SETPROC_STATIC
2378 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2380 # if SPT_TYPE == SPT_SYSMIPS
2381 # include <sys/sysmips.h>
2382 # include <sys/sysnews.h>
2383 # endif /* SPT_TYPE == SPT_SYSMIPS */
2385 # if SPT_TYPE == SPT_SCO
2386 # include <sys/immu.h>
2387 # include <sys/dir.h>
2388 # include <sys/user.h>
2389 # include <sys/fs/s5param.h>
2390 # if PSARGSZ > MAXLINE
2391 # define SPT_BUFSIZE PSARGSZ
2392 # endif /* PSARGSZ > MAXLINE */
2393 # endif /* SPT_TYPE == SPT_SCO */
2395 # ifndef SPT_PADCHAR
2396 # define SPT_PADCHAR ' '
2397 # endif /* ! SPT_PADCHAR */
2399 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2402 # define SPT_BUFSIZE MAXLINE
2403 #endif /* ! SPT_BUFSIZE */
2408 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2409 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2410 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2411 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2412 ** you use this FFR.
2415 # ifdef SPT_ALIGN_SIZE
2416 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2417 # else /* SPT_ALIGN_SIZE */
2418 # define SPT_ALIGN(x, align) (x)
2419 # endif /* SPT_ALIGN_SIZE */
2420 #else /* _FFR_SPT_ALIGN */
2421 # define SPT_ALIGN(x, align) (x)
2422 #endif /* _FFR_SPT_ALIGN */
2425 ** Pointers for setproctitle.
2426 ** This allows "ps" listings to give more useful information.
2429 static char **Argv = NULL; /* pointer to argument vector */
2430 static char *LastArgv = NULL; /* end of argv */
2431 #if SPT_TYPE != SPT_BUILTIN
2432 static void setproctitle __P((const char *, ...));
2433 #endif /* SPT_TYPE != SPT_BUILTIN */
2436 initsetproctitle(argc, argv, envp)
2443 extern char **environ;
2446 ** Move the environment so setproctitle can use the space at
2447 ** the top of memory.
2452 for (i = 0; envp[i] != NULL; i++)
2454 environ = (char **) xalloc(sizeof (char *) * (i + 1));
2455 for (i = 0; envp[i] != NULL; i++)
2456 environ[i] = newstr(envp[i]);
2461 ** Save start and extent of argv for setproctitle.
2467 ** Determine how much space we can use for setproctitle.
2468 ** Use all contiguous argv and envp pointers starting at argv[0]
2473 # ifdef SPT_ALIGN_SIZE
2474 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
2476 # endif /* SPT_ALIGN_SIZE */
2477 # endif /* _FFR_SPT_ALIGN */
2479 for (i = 0; i < argc; i++)
2481 if (i == 0 || LastArgv + 1 == argv[i])
2482 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
2484 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
2486 if (LastArgv + 1 == envp[i])
2487 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
2491 #if SPT_TYPE != SPT_BUILTIN
2496 setproctitle(const char *fmt, ...)
2497 # else /* __STDC__ */
2498 setproctitle(fmt, va_alist)
2501 # endif /* __STDC__ */
2503 # if SPT_TYPE != SPT_NONE
2506 SETPROC_STATIC char buf[SPT_BUFSIZE];
2508 # if SPT_TYPE == SPT_PSTAT
2510 # endif /* SPT_TYPE == SPT_PSTAT */
2511 # if SPT_TYPE == SPT_SCO
2514 static int kmem = -1;
2515 static pid_t kmempid = -1;
2517 # endif /* SPT_TYPE == SPT_SCO */
2521 /* print sendmail: heading for grep */
2522 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
2525 /* print the argument string */
2526 SM_VA_START(ap, fmt);
2527 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
2530 i = (int) strlen(buf);
2534 # if SPT_TYPE == SPT_PSTAT
2535 pst.pst_command = buf;
2536 pstat(PSTAT_SETCMD, pst, i, 0, 0);
2537 # endif /* SPT_TYPE == SPT_PSTAT */
2538 # if SPT_TYPE == SPT_PSSTRINGS
2539 PS_STRINGS->ps_nargvstr = 1;
2540 PS_STRINGS->ps_argvstr = buf;
2541 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2542 # if SPT_TYPE == SPT_SYSMIPS
2543 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
2544 # endif /* SPT_TYPE == SPT_SYSMIPS */
2545 # if SPT_TYPE == SPT_SCO
2546 if (kmem < 0 || kmempid != CurrentPid)
2550 kmem = open(_PATH_KMEM, O_RDWR, 0);
2553 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
2554 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
2560 kmempid = CurrentPid;
2562 buf[PSARGSZ - 1] = '\0';
2563 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
2564 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
2565 (void) write(kmem, buf, PSARGSZ);
2566 # endif /* SPT_TYPE == SPT_SCO */
2567 # if SPT_TYPE == SPT_REUSEARGV
2568 if (LastArgv == NULL)
2571 if (i > LastArgv - Argv[0] - 2)
2573 i = LastArgv - Argv[0] - 2;
2576 (void) sm_strlcpy(Argv[0], buf, i + 1);
2578 while (p < LastArgv)
2581 # endif /* SPT_TYPE == SPT_REUSEARGV */
2582 # if SPT_TYPE == SPT_CHANGEARGV
2585 # endif /* SPT_TYPE == SPT_CHANGEARGV */
2586 # endif /* SPT_TYPE != SPT_NONE */
2589 #endif /* SPT_TYPE != SPT_BUILTIN */
2591 ** SM_SETPROCTITLE -- set process task and set process title for ps
2593 ** Possibly set process status and call setproctitle() to
2594 ** change the ps display.
2597 ** status -- whether or not to store as process status
2598 ** e -- the current envelope.
2599 ** fmt -- a printf style format string.
2600 ** a, b, c -- possible parameters to fmt.
2609 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
2610 #else /* __STDC__ */
2611 sm_setproctitle(status, e, fmt, va_alist)
2616 #endif /* __STDC__ */
2618 char buf[SPT_BUFSIZE];
2621 /* print the argument string */
2622 SM_VA_START(ap, fmt);
2623 (void) sm_vsnprintf(buf, sizeof buf, fmt, ap);
2627 proc_list_set(CurrentPid, buf);
2629 if (ProcTitlePrefix != NULL)
2631 char prefix[SPT_BUFSIZE];
2633 expand(ProcTitlePrefix, prefix, sizeof prefix, e);
2634 setproctitle("%s: %s", prefix, buf);
2637 setproctitle("%s", buf);
2640 ** WAITFOR -- wait for a particular process id.
2643 ** pid -- process id to wait for.
2647 ** -1 if pid never shows up.
2665 proc_list_drop(i, st, NULL);
2666 } while ((i >= 0 || errno == EINTR) && i != pid);
2675 ** status -- pointer to status (return value)
2687 # else /* WAITUNION */
2689 # endif /* WAITUNION */
2691 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2693 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2695 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2696 savesig = sm_releasesignal(SIGCHLD);
2697 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2699 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2701 sm_blocksignal(SIGCHLD);
2702 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2704 *status = st.w_status;
2705 # else /* WAITUNION */
2707 # endif /* WAITUNION */
2711 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2714 ** sig -- the signal that got us here (unused).
2720 ** Picks up extant zombies.
2721 ** Control socket exits may restart/shutdown daemon.
2723 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2724 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2733 int save_errno = errno;
2741 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
2746 # else /* HASWAITPID */
2750 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
2752 st = status.w_status;
2753 # else /* WNOHANG */
2757 ** Catch one zombie -- we will be re-invoked (we hope) if there
2758 ** are more. Unreliable signals probably break this, but this
2759 ** is the "old system" situation -- waitpid or wait3 are to be
2760 ** strongly preferred.
2763 if ((pid = wait(&status)) > 0)
2766 # endif /* WNOHANG */
2767 # endif /* HASWAITPID */
2768 /* Drop PID and check if it was a control socket child */
2769 proc_list_drop(pid, st, NULL);
2771 FIX_SYSV_SIGNAL(sig, reapchild);
2773 return SIGFUNC_RETURN;
2776 ** GETDTABLESIZE -- return number of file descriptors
2778 ** Only on non-BSD systems
2784 ** size of file descriptor table
2791 # include <sys/resource.h>
2792 #endif /* SOLARIS */
2797 # ifdef RLIMIT_NOFILE
2800 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
2802 # endif /* RLIMIT_NOFILE */
2804 # if HASGETDTABLESIZE
2805 return getdtablesize();
2806 # else /* HASGETDTABLESIZE */
2807 # ifdef _SC_OPEN_MAX
2808 return sysconf(_SC_OPEN_MAX);
2809 # else /* _SC_OPEN_MAX */
2811 # endif /* _SC_OPEN_MAX */
2812 # endif /* HASGETDTABLESIZE */
2815 ** UNAME -- get the UUCP name of this system.
2822 struct utsname *name;
2827 name->nodename[0] = '\0';
2829 /* try /etc/whoami -- one line with the node name */
2830 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
2831 SM_IO_RDONLY, NULL)) != NULL)
2833 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
2835 (void) sm_io_close(file, SM_TIME_DEFAULT);
2836 n = strchr(name->nodename, '\n');
2839 if (name->nodename[0] != '\0')
2843 /* try /usr/include/whoami.h -- has a #define somewhere */
2844 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
2845 "/usr/include/whoami.h", SM_IO_RDONLY, NULL))
2850 while (sm_io_fgets(file, SM_TIME_DEFAULT,
2851 buf, sizeof buf) != NULL)
2853 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
2854 NODE_LENGTH, name->nodename) > 0)
2857 (void) sm_io_close(file, SM_TIME_DEFAULT);
2858 if (name->nodename[0] != '\0')
2864 #endif /* !HASUNAME */
2866 ** INITGROUPS -- initialize groups
2868 ** Stub implementation for System V style systems
2873 initgroups(name, basegid)
2880 #endif /* !HASINITGROUPS */
2882 ** SETGROUPS -- set group list
2884 ** Stub implementation for systems that don't have group lists
2890 setgroups(ngroups, grouplist)
2892 GIDSET_T grouplist[];
2897 #endif /* ! NGROUPS_MAX */
2899 ** SETSID -- set session id (for non-POSIX systems)
2910 fd = open("/dev/tty", O_RDWR, 0);
2913 (void) ioctl(fd, TIOCNOTTY, (char *) 0);
2916 # endif /* TIOCNOTTY */
2919 # else /* SYS5SETPGRP */
2920 return setpgid(0, CurrentPid);
2921 # endif /* SYS5SETPGRP */
2924 #endif /* !HASSETSID */
2926 ** FSYNC -- dummy fsync
2935 return fcntl(fd, F_SETFL, O_SYNC);
2937 /* nothing we can do */
2939 # endif /* O_SYNC */
2942 #endif /* NEEDFSYNC */
2944 ** DGUX_INET_ADDR -- inet_addr for DG/UX
2946 ** Data General DG/UX version of inet_addr returns a struct in_addr
2947 ** instead of a long. This patches things. Only needed on versions
2956 dgux_inet_addr(host)
2959 struct in_addr haddr;
2961 haddr = inet_addr(host);
2962 return haddr.s_addr;
2965 #endif /* DGUX_5_4_2 */
2967 ** GETOPT -- for old systems or systems with bogus implementations
2973 * Copyright (c) 1985 Regents of the University of California.
2974 * All rights reserved. The Berkeley software License Agreement
2975 * specifies the terms and conditions for redistribution.
2980 ** this version hacked to add `atend' flag to allow state machine
2981 ** to reset if invoked by the program to scan args for a 2nd time
2984 # if defined(LIBC_SCCS) && !defined(lint)
2985 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
2986 # endif /* defined(LIBC_SCCS) && !defined(lint) */
2989 ** get option letter from argument vector
2991 # ifdef _CONVEX_SOURCE
2992 extern int optind, opterr, optopt;
2993 extern char *optarg;
2994 # else /* _CONVEX_SOURCE */
2995 int opterr = 1; /* if error message should be printed */
2996 int optind = 1; /* index into parent argv vector */
2997 int optopt = 0; /* character checked for validity */
2998 char *optarg = NULL; /* argument associated with option */
2999 # endif /* _CONVEX_SOURCE */
3001 # define BADCH (int)'?'
3003 # define tell(s) if (opterr) \
3004 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
3005 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
3006 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
3007 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
3011 getopt(nargc,nargv,ostr)
3016 static char *place = EMSG; /* option letter processing */
3017 static char atend = 0;
3018 register char *oli = NULL; /* option letter list index */
3024 if(!*place) { /* update scanning pointer */
3025 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
3029 if (*place == '-') { /* found "--" */
3034 } /* option letter okay? */
3035 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
3036 if (!*place) ++optind;
3037 tell(": illegal option -- ");
3039 if (oli && *++oli != ':') { /* don't need argument */
3041 if (!*place) ++optind;
3043 else { /* need an argument */
3044 if (*place) optarg = place; /* no white space */
3045 else if (nargc <= ++optind) { /* no arg */
3047 tell(": option requires an argument -- ");
3049 else optarg = nargv[optind]; /* white space */
3053 return optopt; /* dump back option letter */
3056 #endif /* !SM_CONF_GETOPT */
3058 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3061 ** user -- the name of the user we are checking.
3062 ** shell -- the user's shell from /etc/passwd
3065 ** true -- if it is ok to use this for unrestricted access.
3066 ** false -- if the shell is restricted.
3069 #if !HASGETUSERSHELL
3071 # ifndef _PATH_SHELLS
3072 # define _PATH_SHELLS "/etc/shells"
3073 # endif /* ! _PATH_SHELLS */
3075 # if defined(_AIX3) || defined(_AIX4)
3076 # include <userconf.h>
3078 # include <userpw.h>
3079 # endif /* _AIX4 >= 40200 */
3080 # include <usersec.h>
3081 # endif /* defined(_AIX3) || defined(_AIX4) */
3083 static char *DefaultUserShells[] =
3085 "/bin/sh", /* standard shell */
3090 "/bin/csh", /* C shell */
3095 "/usr/bin/rsh", /* restricted Bourne shell */
3096 "/usr/bin/ksh", /* Korn shell */
3097 "/usr/bin/rksh", /* restricted Korn shell */
3099 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3100 "/usr/bin/posix/sh",
3102 "/bin/rsh", /* restricted Bourne shell */
3103 "/bin/ksh", /* Korn shell */
3104 "/bin/rksh", /* restricted Korn shell */
3106 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3110 # endif /* __hpux */
3111 # if defined(_AIX3) || defined(_AIX4)
3112 "/bin/ksh", /* Korn shell */
3114 "/bin/tsh", /* trusted shell */
3116 "/bin/bsh", /* Bourne shell */
3118 # endif /* defined(_AIX3) || defined(_AIX4) */
3119 # if defined(__svr4__) || defined(__svr5__)
3120 "/bin/ksh", /* Korn shell */
3122 # endif /* defined(__svr4__) || defined(__svr5__) */
3124 "/sbin/sh", /* SGI's shells really live in /sbin */
3126 "/sbin/bsh", /* classic Bourne shell */
3129 "/sbin/csh", /* standard csh */
3132 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3135 "/bin/ksh", /* Korn shell */
3138 "/sbin/tcsh", /* Extended csh */
3145 #endif /* !HASGETUSERSHELL */
3147 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3150 usershellok(user, shell)
3154 # if HASGETUSERSHELL
3156 extern char *getusershell();
3158 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3163 while ((p = getusershell()) != NULL)
3164 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
3168 # else /* HASGETUSERSHELL */
3171 # endif /* USEGETCONFATTR */
3172 register SM_FILE_T *shellf;
3175 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3181 ** Naturally IBM has a "better" idea.....
3183 ** What a crock. This interface isn't documented, it is
3184 ** considered part of the security library (-ls), and it
3185 ** only works if you are running as root (since the list
3186 ** of valid shells is obviously a source of great concern).
3187 ** I recommend that you do NOT define USEGETCONFATTR,
3188 ** especially since you are going to have to set up an
3189 ** /etc/shells anyhow to handle the cases where getconfattr
3193 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
3197 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
3203 # endif /* USEGETCONFATTR */
3205 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
3206 SM_IO_RDONLY, NULL);
3209 /* no /etc/shells; see if it is one of the std shells */
3212 if (errno != ENOENT && LogLevel > 3)
3213 sm_syslog(LOG_ERR, NOQID,
3214 "usershellok: cannot open %s: %s",
3215 _PATH_SHELLS, sm_errstring(errno));
3217 for (d = DefaultUserShells; *d != NULL; d++)
3219 if (strcmp(shell, *d) == 0)
3225 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof buf) != NULL)
3227 register char *p, *q;
3230 while (*p != '\0' && *p != '#' && *p != '/')
3232 if (*p == '#' || *p == '\0')
3235 while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
3238 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
3240 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3244 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3246 # endif /* HASGETUSERSHELL */
3249 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3251 ** Only implemented if you have statfs.
3254 ** dir -- the directory in question.
3255 ** bsize -- a variable into which the filesystem
3256 ** block size is stored.
3259 ** The number of blocks free on the queue filesystem.
3260 ** -1 if the statfs call fails.
3263 ** Puts the filesystem block size into bsize.
3267 # define SFS_NONE 0 /* no statfs implementation */
3268 # define SFS_USTAT 1 /* use ustat */
3269 # define SFS_4ARGS 2 /* use four-argument statfs call */
3270 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3271 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3272 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3273 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3276 # define SFS_TYPE SFS_NONE
3277 # endif /* ! SFS_TYPE */
3279 # if SFS_TYPE == SFS_USTAT
3281 # endif /* SFS_TYPE == SFS_USTAT */
3282 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3283 # include <sys/statfs.h>
3284 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
3285 # if SFS_TYPE == SFS_VFS
3286 # include <sys/vfs.h>
3287 # endif /* SFS_TYPE == SFS_VFS */
3288 # if SFS_TYPE == SFS_MOUNT
3289 # include <sys/mount.h>
3290 # endif /* SFS_TYPE == SFS_MOUNT */
3291 # if SFS_TYPE == SFS_STATVFS
3292 # include <sys/statvfs.h>
3293 # endif /* SFS_TYPE == SFS_STATVFS */
3296 freediskspace(dir, bsize)
3300 # if SFS_TYPE == SFS_NONE
3304 /* assume free space is plentiful */
3305 return (long) LONG_MAX;
3306 # else /* SFS_TYPE == SFS_NONE */
3307 # if SFS_TYPE == SFS_USTAT
3309 struct stat statbuf;
3310 # define FSBLOCKSIZE DEV_BSIZE
3311 # define SFS_BAVAIL f_tfree
3312 # else /* SFS_TYPE == SFS_USTAT */
3313 # if defined(ultrix)
3315 # define SFS_BAVAIL fd_bfreen
3316 # define FSBLOCKSIZE 1024L
3317 # else /* defined(ultrix) */
3318 # if SFS_TYPE == SFS_STATVFS
3320 # define FSBLOCKSIZE fs.f_frsize
3321 # else /* SFS_TYPE == SFS_STATVFS */
3323 # define FSBLOCKSIZE fs.f_bsize
3324 # endif /* SFS_TYPE == SFS_STATVFS */
3325 # endif /* defined(ultrix) */
3326 # endif /* SFS_TYPE == SFS_USTAT */
3328 # define SFS_BAVAIL f_bavail
3329 # endif /* ! SFS_BAVAIL */
3331 # if SFS_TYPE == SFS_USTAT
3332 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
3333 # else /* SFS_TYPE == SFS_USTAT */
3334 # if SFS_TYPE == SFS_4ARGS
3335 if (statfs(dir, &fs, sizeof fs, 0) == 0)
3336 # else /* SFS_TYPE == SFS_4ARGS */
3337 # if SFS_TYPE == SFS_STATVFS
3338 if (statvfs(dir, &fs) == 0)
3339 # else /* SFS_TYPE == SFS_STATVFS */
3340 # if defined(ultrix)
3341 if (statfs(dir, &fs) > 0)
3342 # else /* defined(ultrix) */
3343 if (statfs(dir, &fs) == 0)
3344 # endif /* defined(ultrix) */
3345 # endif /* SFS_TYPE == SFS_STATVFS */
3346 # endif /* SFS_TYPE == SFS_4ARGS */
3347 # endif /* SFS_TYPE == SFS_USTAT */
3350 *bsize = FSBLOCKSIZE;
3351 if (fs.SFS_BAVAIL <= 0)
3353 else if (fs.SFS_BAVAIL > LONG_MAX)
3354 return (long) LONG_MAX;
3356 return (long) fs.SFS_BAVAIL;
3359 # endif /* SFS_TYPE == SFS_NONE */
3362 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3365 ** msize -- the size to check against. If zero, we don't yet
3366 ** know how big the message will be, so just check for
3367 ** a "reasonable" amount.
3368 ** e -- envelope, or NULL -- controls logging
3371 ** true if in every queue group there is at least one
3372 ** queue directory whose file system contains enough free space.
3376 ** If there is not enough disk space and e != NULL
3377 ** then sm_syslog is called.
3381 enoughdiskspace(msize, e)
3387 if (MinBlocksFree <= 0 && msize <= 0)
3390 sm_dprintf("enoughdiskspace: no threshold\n");
3395 for (i = 0; i < NumQueue; ++i)
3397 if (pickqdir(Queue[i], msize, e) < 0)
3403 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3405 ** This looks at an errno value and tells if this is likely to
3406 ** go away if retried later.
3409 ** err -- the errno code to classify.
3412 ** true if this is probably transient.
3422 case EIO: /* I/O error */
3423 case ENXIO: /* Device not configured */
3424 case EAGAIN: /* Resource temporarily unavailable */
3425 case ENOMEM: /* Cannot allocate memory */
3426 case ENODEV: /* Operation not supported by device */
3427 case ENFILE: /* Too many open files in system */
3428 case EMFILE: /* Too many open files */
3429 case ENOSPC: /* No space left on device */
3430 case ETIMEDOUT: /* Connection timed out */
3432 case ESTALE: /* Stale NFS file handle */
3435 case ENETDOWN: /* Network is down */
3436 #endif /* ENETDOWN */
3438 case ENETUNREACH: /* Network is unreachable */
3439 #endif /* ENETUNREACH */
3441 case ENETRESET: /* Network dropped connection on reset */
3442 #endif /* ENETRESET */
3444 case ECONNABORTED: /* Software caused connection abort */
3445 #endif /* ECONNABORTED */
3447 case ECONNRESET: /* Connection reset by peer */
3448 #endif /* ECONNRESET */
3450 case ENOBUFS: /* No buffer space available */
3451 #endif /* ENOBUFS */
3453 case ESHUTDOWN: /* Can't send after socket shutdown */
3454 #endif /* ESHUTDOWN */
3456 case ECONNREFUSED: /* Connection refused */
3457 #endif /* ECONNREFUSED */
3459 case EHOSTDOWN: /* Host is down */
3460 #endif /* EHOSTDOWN */
3462 case EHOSTUNREACH: /* No route to host */
3463 #endif /* EHOSTUNREACH */
3465 case EDQUOT: /* Disc quota exceeded */
3468 case EPROCLIM: /* Too many processes */
3469 #endif /* EPROCLIM */
3471 case EUSERS: /* Too many users */
3474 case EDEADLK: /* Resource deadlock avoided */
3475 #endif /* EDEADLK */
3477 case EISCONN: /* Socket already connected */
3478 #endif /* EISCONN */
3480 case EINPROGRESS: /* Operation now in progress */
3481 #endif /* EINPROGRESS */
3483 case EALREADY: /* Operation already in progress */
3484 #endif /* EALREADY */
3486 case EADDRINUSE: /* Address already in use */
3487 #endif /* EADDRINUSE */
3488 #ifdef EADDRNOTAVAIL
3489 case EADDRNOTAVAIL: /* Can't assign requested address */
3490 #endif /* EADDRNOTAVAIL */
3492 case ETXTBSY: /* (Apollo) file locked */
3493 #endif /* ETXTBSY */
3494 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3495 case ENOSR: /* Out of streams resources */
3496 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
3498 case ENOLCK: /* No locks available */
3500 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
3504 /* nope, must be permanent */
3508 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3511 ** fd -- the file descriptor of the file.
3512 ** filename -- the file name (for error messages).
3513 ** ext -- the filename extension.
3514 ** type -- type of the lock. Bits can be:
3515 ** LOCK_EX -- exclusive lock.
3516 ** LOCK_NB -- non-blocking.
3517 ** LOCK_UN -- unlock.
3520 ** true if the lock was acquired.
3525 lockfile(fd, filename, ext, type)
3540 memset(&lfd, '\0', sizeof lfd);
3541 if (bitset(LOCK_UN, type))
3542 lfd.l_type = F_UNLCK;
3543 else if (bitset(LOCK_EX, type))
3544 lfd.l_type = F_WRLCK;
3546 lfd.l_type = F_RDLCK;
3548 if (bitset(LOCK_NB, type))
3554 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
3555 filename, ext, action, lfd.l_type);
3557 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
3562 sm_dprintf("SUCCESS\n");
3568 sm_dprintf("(%s) ", sm_errstring(save_errno));
3571 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3572 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3573 ** as type "tmp" (that is, served from swap space), the
3574 ** previous fcntl will fail with "Invalid argument" errors.
3575 ** Since this is fairly common during testing, we will assume
3576 ** that this indicates that the lock is successfully grabbed.
3579 if (save_errno == EINVAL)
3582 sm_dprintf("SUCCESS\n");
3586 if (!bitset(LOCK_NB, type) ||
3587 (save_errno != EACCES && save_errno != EAGAIN))
3589 int omode = fcntl(fd, F_GETFL, 0);
3590 uid_t euid = geteuid();
3593 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3594 filename, ext, fd, type, omode, euid);
3595 dumpfd(fd, true, true);
3597 # else /* !HASFLOCK */
3602 sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
3604 while ((i = flock(fd, type)) < 0 && errno == EINTR)
3609 sm_dprintf("SUCCESS\n");
3615 sm_dprintf("(%s) ", sm_errstring(save_errno));
3617 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
3619 int omode = fcntl(fd, F_GETFL, 0);
3620 uid_t euid = geteuid();
3623 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3624 filename, ext, fd, type, omode, euid);
3625 dumpfd(fd, true, true);
3627 # endif /* !HASFLOCK */
3629 sm_dprintf("FAIL\n");
3634 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3636 ** Unfortunately, given that we can't predict other systems on which
3637 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3638 ** almost always that this is unsafe.
3640 ** Note also that many operating systems have non-compliant
3641 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3642 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3643 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3644 ** no non-root process can give away the file. However, vendors
3645 ** don't take NFS into account, so a comfortable value of
3646 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3648 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3649 ** even on files where chown is not restricted. Many systems get
3650 ** this wrong on NFS-based filesystems (that is, they say that chown
3651 ** is restricted [safe] on NFS filesystems where it may not be, since
3652 ** other systems can access the same filesystem and do file giveaway;
3653 ** only the NFS server knows for sure!) Hence, it is important to
3654 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3655 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3656 ** NFS-based filesystem to ensure that you can get meaningful results.
3657 ** If in doubt, assume unsafe!
3659 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3660 ** condition indicating whether the return from pathconf indicates
3661 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3662 ** even any agreement about whether a zero return means that a file
3663 ** is or is not safe). It defaults to "> 0".
3665 ** If the parent directory is safe (writable only by owner back
3666 ** to the root) then we can relax slightly and trust fpathconf
3667 ** in more circumstances. This is really a crock -- if this is an
3668 ** NFS mounted filesystem then we really know nothing about the
3669 ** underlying implementation. However, most systems pessimize and
3670 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3671 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3672 ** us into a possible problem only on systems that have a broken
3673 ** pathconf implementation and which are also poorly configured
3674 ** (have :include: files in group- or world-writable directories).
3677 ** fd -- the file descriptor to check.
3678 ** safedir -- set if the parent directory is safe.
3681 ** true -- if the chown(2) operation is "safe" -- that is,
3682 ** only root can chown the file to an arbitrary user.
3683 ** false -- if an arbitrary user can give away a file.
3686 #ifndef IS_SAFE_CHOWN
3687 # define IS_SAFE_CHOWN > 0
3688 #endif /* ! IS_SAFE_CHOWN */
3691 chownsafe(fd, safedir)
3695 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3696 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3699 /* give the system administrator a chance to override */
3700 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
3704 ** Some systems (e.g., SunOS) seem to have the call and the
3705 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3706 ** the call. This heuristic checks for that.
3710 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
3711 # if SAFENFSPATHCONF
3712 return errno == 0 && rval IS_SAFE_CHOWN;
3713 # else /* SAFENFSPATHCONF */
3714 return safedir && errno == 0 && rval IS_SAFE_CHOWN;
3715 # endif /* SAFENFSPATHCONF */
3716 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3717 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
3718 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3721 ** RESETLIMITS -- reset system controlled resource limits
3723 ** This is to avoid denial-of-service attacks
3733 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3734 # include <sys/time.h>
3735 # endif /* RLIMIT_NEEDS_SYS_TIME_H */
3736 # include <sys/resource.h>
3737 #endif /* HASSETRLIMIT */
3745 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
3746 (void) setrlimit(RLIMIT_CPU, &lim);
3747 (void) setrlimit(RLIMIT_FSIZE, &lim);
3748 # ifdef RLIMIT_NOFILE
3749 lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
3750 (void) setrlimit(RLIMIT_NOFILE, &lim);
3751 # endif /* RLIMIT_NOFILE */
3752 #else /* HASSETRLIMIT */
3754 (void) ulimit(2, 0x3fffff);
3755 (void) ulimit(4, FD_SETSIZE);
3756 # endif /* HASULIMIT */
3757 #endif /* HASSETRLIMIT */
3761 ** SETVENDOR -- process vendor code from V configuration line
3764 ** vendor -- string representation of vendor.
3768 ** false -- if vendor code could not be processed.
3771 ** It is reasonable to set mode flags here to tweak
3772 ** processing in other parts of the code if necessary.
3773 ** For example, if you are a vendor that uses $%y to
3774 ** indicate YP lookups, you could enable that here.
3781 if (sm_strcasecmp(vendor, "Berkeley") == 0)
3783 VendorCode = VENDOR_BERKELEY;
3787 /* add vendor extensions here */
3789 #ifdef SUN_EXTENSIONS
3790 if (sm_strcasecmp(vendor, "Sun") == 0)
3792 VendorCode = VENDOR_SUN;
3795 #endif /* SUN_EXTENSIONS */
3797 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3798 if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
3800 VendorCode = VENDOR_CODE;
3803 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3808 ** GETVENDOR -- return vendor name based on vendor code
3811 ** vendorcode -- numeric representation of vendor.
3814 ** string containing vendor name.
3818 getvendor(vendorcode)
3821 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3823 ** Can't have the same switch case twice so need to
3824 ** handle VENDOR_CODE outside of switch. It might
3825 ** match one of the existing VENDOR_* codes.
3828 if (vendorcode == VENDOR_CODE)
3830 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3834 case VENDOR_BERKELEY:
3846 case VENDOR_SENDMAIL:
3854 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3856 ** Vendor_pre_defaults is called before reading the configuration
3857 ** file; vendor_post_defaults is called immediately after.
3860 ** e -- the global environment to initialize.
3867 int DefShareUid; /* default share uid to run as -- unused??? */
3868 #endif /* SHARE_V1 */
3871 vendor_pre_defaults(e)
3875 /* OTHERUID is defined in shares.h, do not be alarmed */
3876 DefShareUid = OTHERUID;
3877 #endif /* SHARE_V1 */
3878 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3879 sun_pre_defaults(e);
3880 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3883 ** stupid domain/os can't even open
3884 ** /etc/mail/sendmail.cf without this
3887 setuserenv("ISP", NULL);
3888 setuserenv("SYSTYPE", NULL);
3894 vendor_post_defaults(e)
3900 /* Makes sure the SOCK environment variable remains */
3901 if (p = getextenv("SOCK"))
3902 setuserenv("SOCK", p);
3903 #endif /* __QNX__ */
3904 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3905 sun_post_defaults(e);
3906 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3909 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
3913 vendor_daemon_setup(e)
3917 (void) setlogin(RunAsUserName);
3918 #endif /* HASSETLOGIN */
3920 if (getluid() != -1)
3922 usrerr("Daemon cannot have LUID");
3923 finis(false, true, EX_USAGE);
3925 #endif /* SECUREWARE */
3928 ** VENDOR_SET_UID -- do setup for setting a user id
3930 ** This is called when we are still root.
3933 ** uid -- the uid we are about to become.
3944 ** We need to setup the share groups (lnodes)
3945 ** and add auditing information (luid's)
3946 ** before we loose our ``root''ness.
3949 if (setupshares(uid, syserr) != 0)
3950 syserr("Unable to set up shares");
3951 #endif /* SHARE_V1 */
3953 (void) setup_secure(uid);
3954 #endif /* SECUREWARE */
3957 ** VALIDATE_CONNECTION -- check connection for rationality
3959 ** If the connection is rejected, this routine should log an
3960 ** appropriate message -- but should never issue any SMTP protocol.
3963 ** sap -- a pointer to a SOCKADDR naming the peer.
3964 ** hostname -- the name corresponding to sap.
3965 ** e -- the current envelope.
3968 ** error message from rejection.
3969 ** NULL if not rejected.
3975 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
3976 int allow_severity = LOG_INFO;
3977 int deny_severity = LOG_NOTICE;
3978 #endif /* TCPWRAPPERS */
3981 validate_connection(sap, hostname, e)
3989 extern int hosts_ctl();
3990 #endif /* TCPWRAPPERS */
3993 sm_dprintf("validate_connection(%s, %s)\n",
3994 hostname, anynet_ntoa(sap));
3996 connection_rate_check(sap, e);
3997 if (rscheck("check_relay", hostname, anynet_ntoa(sap),
3998 e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID) != EX_OK)
4000 static char reject[BUFSIZ*2];
4001 extern char MsgBuf[];
4004 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
4006 if (strlen(MsgBuf) >= 3)
4007 (void) sm_strlcpy(reject, MsgBuf, sizeof reject);
4009 (void) sm_strlcpy(reject, "Access denied", sizeof reject);
4015 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
4019 addr = anynet_ntoa(sap);
4022 /* TCP/Wrappers don't want the IPv6: protocol label */
4023 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
4025 # endif /* NETINET6 */
4027 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
4030 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4032 sm_syslog(LOG_NOTICE, e->e_id,
4033 "tcpwrappers (%s, %s) rejection",
4035 return "Access denied";
4037 #endif /* TCPWRAPPERS */
4039 sm_dprintf(" ... validate_connection: OK\n");
4044 ** STRTOL -- convert string to long integer
4046 ** For systems that don't have it in the C library.
4048 ** This is taken verbatim from the 4.4-Lite C library.
4053 # if defined(LIBC_SCCS) && !defined(lint)
4054 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4055 # endif /* defined(LIBC_SCCS) && !defined(lint) */
4058 ** Convert a string to a long integer.
4060 ** Ignores `locale' stuff. Assumes that the upper and lower case
4061 ** alphabets and digits are each contiguous.
4065 strtol(nptr, endptr, base)
4070 register const char *s = nptr;
4071 register unsigned long acc;
4073 register unsigned long cutoff;
4074 register int neg = 0, any, cutlim;
4077 ** Skip white space and pick up leading +/- sign if any.
4078 ** If base is 0, allow 0x for hex and 0 for octal, else
4079 ** assume decimal; if base is already 16, allow 0x.
4083 } while (isspace(c));
4087 } else if (c == '+')
4089 if ((base == 0 || base == 16) &&
4090 c == '0' && (*s == 'x' || *s == 'X')) {
4096 base = c == '0' ? 8 : 10;
4099 ** Compute the cutoff value between legal numbers and illegal
4100 ** numbers. That is the largest legal value, divided by the
4101 ** base. An input number that is greater than this value, if
4102 ** followed by a legal input character, is too big. One that
4103 ** is equal to this value may be valid or not; the limit
4104 ** between valid and invalid numbers is then based on the last
4105 ** digit. For instance, if the range for longs is
4106 ** [-2147483648..2147483647] and the input base is 10,
4107 ** cutoff will be set to 214748364 and cutlim to either
4108 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4109 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4110 ** the number is too big, and we will return a range error.
4112 ** Set any if any `digits' consumed; make it negative to indicate
4115 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
4116 cutlim = cutoff % (unsigned long) base;
4117 cutoff /= (unsigned long) base;
4118 for (acc = 0, any = 0;; c = *s++) {
4121 else if (isalpha(c))
4122 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
4127 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
4136 acc = neg ? LONG_MIN : LONG_MAX;
4141 *endptr = (char *)(any ? s - 1 : nptr);
4145 #endif /* NEEDSTRTOL */
4147 ** STRSTR -- find first substring in string
4150 ** big -- the big (full) string.
4151 ** little -- the little (sub) string.
4154 ** A pointer to the first instance of little in big.
4155 ** big if little is the null string.
4156 ** NULL if little is not contained in big.
4166 register char *p = big;
4169 if (*little == '\0')
4173 while ((p = strchr(p, *little)) != NULL)
4175 if (strncmp(p, little, l) == 0)
4182 #endif /* NEEDSTRSTR */
4184 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4186 ** Some operating systems have wierd problems with the gethostbyXXX
4187 ** routines. For example, Solaris versions at least through 2.3
4188 ** don't properly deliver a canonical h_name field. This tries to
4189 ** work around these problems.
4191 ** Support IPv6 as well as IPv4.
4194 #if NETINET6 && NEEDSGETIPNODE
4197 # define AI_DEFAULT 0 /* dummy */
4198 # endif /* ! AI_DEFAULT */
4199 # ifndef AI_ADDRCONFIG
4200 # define AI_ADDRCONFIG 0 /* dummy */
4201 # endif /* ! AI_ADDRCONFIG */
4202 # ifndef AI_V4MAPPED
4203 # define AI_V4MAPPED 0 /* dummy */
4204 # endif /* ! AI_V4MAPPED */
4206 # define AI_ALL 0 /* dummy */
4207 # endif /* ! AI_ALL */
4209 static struct hostent *
4210 getipnodebyname(name, family, flags, err)
4219 if (family == AF_INET6)
4221 /* From RFC2133, section 6.1 */
4222 resv6 = bitset(RES_USE_INET6, _res.options);
4223 _res.options |= RES_USE_INET6;
4226 h = gethostbyname(name);
4228 _res.options &= ~RES_USE_INET6;
4233 static struct hostent *
4234 getipnodebyaddr(addr, len, family, err)
4243 h = gethostbyaddr(addr, len, family);
4253 ** Stub routine -- if they don't have getipnodeby*(),
4254 ** they probably don't have the free routine either.
4259 #endif /* NETINET6 && NEEDSGETIPNODE */
4262 sm_gethostbyname(name, family)
4267 struct hostent *h = NULL;
4268 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4269 # if SOLARIS == 20300 || SOLARIS == 203
4270 static struct hostent hp;
4271 static char buf[1000];
4272 extern struct hostent *_switch_gethostbyname_r();
4275 sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
4276 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
4278 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4279 extern struct hostent *__switch_gethostbyname();
4282 sm_dprintf("__switch_gethostbyname(%s)... ", name);
4283 h = __switch_gethostbyname(name);
4285 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4286 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4289 int flags = AI_DEFAULT|AI_ALL;
4291 # endif /* NETINET6 */
4292 char *maptype[MAXMAPSTACK];
4293 short mapreturn[MAXMAPACTIONS];
4297 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
4300 # if ADDRCONFIG_IS_BROKEN
4301 flags &= ~AI_ADDRCONFIG;
4302 # endif /* ADDRCONFIG_IS_BROKEN */
4303 h = getipnodebyname(name, family, flags, &err);
4304 SM_SET_H_ERRNO(err);
4305 # else /* NETINET6 */
4306 h = gethostbyname(name);
4307 # endif /* NETINET6 */
4313 sm_dprintf("failure\n");
4315 nmaps = switch_map_find("hosts", maptype, mapreturn);
4316 while (--nmaps >= 0)
4318 if (strcmp(maptype[nmaps], "nis") == 0 ||
4319 strcmp(maptype[nmaps], "files") == 0)
4325 /* try short name */
4326 if (strlen(name) > sizeof hbuf - 1)
4331 (void) sm_strlcpy(hbuf, name, sizeof hbuf);
4332 (void) shorten_hostname(hbuf);
4334 /* if it hasn't been shortened, there's no point */
4335 if (strcmp(hbuf, name) != 0)
4338 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4342 h = getipnodebyname(hbuf, family, flags, &err);
4343 SM_SET_H_ERRNO(err);
4345 # else /* NETINET6 */
4346 h = gethostbyname(hbuf);
4348 # endif /* NETINET6 */
4352 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4356 sm_dprintf("failure\n");
4359 sm_dprintf("%s\n", h->h_name);
4363 struct in6_addr ia6;
4364 char buf6[INET6_ADDRSTRLEN];
4365 #else /* NETINET6 */
4367 #endif /* NETINET6 */
4370 if (h->h_aliases != NULL)
4371 for (i = 0; h->h_aliases[i] != NULL;
4373 sm_dprintf("\talias: %s\n",
4375 for (i = 0; h->h_addr_list[i] != NULL; i++)
4380 memmove(&ia6, h->h_addr_list[i],
4382 addr = anynet_ntop(&ia6,
4384 #else /* NETINET6 */
4385 memmove(&ia, h->h_addr_list[i],
4387 addr = (char *) inet_ntoa(ia);
4388 #endif /* NETINET6 */
4390 sm_dprintf("\taddr: %s\n", addr);
4400 sm_gethostbyaddr(addr, len, type)
4408 if (type == AF_INET6 &&
4409 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
4411 /* Avoid reverse lookup for IPv6 unspecified address */
4412 SM_SET_H_ERRNO(HOST_NOT_FOUND);
4415 #endif /* NETINET6 */
4417 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4418 # if SOLARIS == 20300 || SOLARIS == 203
4420 static struct hostent he;
4421 static char buf[1000];
4422 extern struct hostent *_switch_gethostbyaddr_r();
4424 hp = _switch_gethostbyaddr_r(addr, len, type, &he,
4425 buf, sizeof(buf), &h_errno);
4427 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4429 extern struct hostent *__switch_gethostbyaddr();
4431 hp = __switch_gethostbyaddr(addr, len, type);
4433 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4434 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4439 hp = getipnodebyaddr(addr, len, type, &err);
4440 SM_SET_H_ERRNO(err);
4442 # else /* NETINET6 */
4443 hp = gethostbyaddr(addr, len, type);
4444 # endif /* NETINET6 */
4445 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4449 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4457 extern struct passwd *_getpwnam_shadow(const char *, const int);
4459 return _getpwnam_shadow(user, 0);
4461 return getpwnam(user);
4469 #if defined(_AIX4) && 0
4470 extern struct passwd *_getpwuid_shadow(const int, const int);
4472 return _getpwuid_shadow(uid,0);
4473 #else /* defined(_AIX4) && 0 */
4474 return getpwuid(uid);
4475 #endif /* defined(_AIX4) && 0 */
4478 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4480 ** Set up the trusted computing environment for C2 level security
4481 ** under SecureWare.
4484 ** uid -- uid of the user to initialize in the TCB
4490 ** Initialized the user in the trusted computing base
4495 # include <sys/security.h>
4499 secureware_setup_secure(uid)
4504 if (getluid() != -1)
4507 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
4511 case SSI_NO_PRPW_ENTRY:
4512 syserr("No protected passwd entry, uid = %d",
4517 syserr("Account has been disabled, uid = %d",
4522 syserr("Account has been retired, uid = %d",
4526 case SSI_BAD_SET_LUID:
4527 syserr("Could not set LUID, uid = %d", (int) uid);
4530 case SSI_BAD_SET_PRIVS:
4531 syserr("Could not set kernel privs, uid = %d",
4535 syserr("Unknown return code (%d) from set_secure_info(%d)",
4539 finis(false, true, EX_NOPERM);
4542 #endif /* SECUREWARE */
4544 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4546 ** Add hostnames to class 'w' based on the IP address read from
4547 ** the network interface.
4550 ** sa -- a pointer to a SOCKADDR containing the address
4553 ** 0 if successful, -1 if host lookup fails.
4562 char hnb[MAXHOSTNAMELEN];
4564 /* lookup name with IP address */
4565 switch (sa->sa.sa_family)
4569 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
4570 sizeof(sa->sin.sin_addr),
4573 #endif /* NETINET */
4577 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
4578 sizeof(sa->sin6.sin6_addr),
4581 #endif /* NETINET6 */
4584 /* Give warning about unsupported family */
4586 sm_syslog(LOG_WARNING, NOQID,
4587 "Unsupported address family %d: %.100s",
4588 sa->sa.sa_family, anynet_ntoa(sa));
4594 int save_errno = errno;
4598 !(sa->sa.sa_family == AF_INET6 &&
4599 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
4600 #endif /* NETINET6 */
4602 sm_syslog(LOG_WARNING, NOQID,
4603 "gethostbyaddr(%.100s) failed: %d",
4607 #else /* NAMED_BIND */
4609 #endif /* NAMED_BIND */
4615 /* save its cname */
4616 if (!wordinclass((char *) hp->h_name, 'w'))
4618 setclass('w', (char *) hp->h_name);
4620 sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
4622 if (sm_snprintf(hnb, sizeof hnb, "[%s]", hp->h_name) < sizeof hnb
4623 && !wordinclass((char *) hnb, 'w'))
4629 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
4632 /* save all it aliases name */
4633 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
4635 if (!wordinclass(*ha, 'w'))
4639 sm_dprintf("\ta.k.a.: %s\n", *ha);
4640 if (sm_snprintf(hnb, sizeof hnb,
4641 "[%s]", *ha) < sizeof hnb &&
4642 !wordinclass((char *) hnb, 'w'))
4648 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4654 #endif /* NETINET6 */
4658 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4667 ** Loads $=w with the names of all the interfaces.
4671 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4672 #endif /* !NETINET */
4674 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4678 # include <sys/time.h>
4679 # endif /* ! SUNOS403 */
4680 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4682 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
4683 # include <net/if.h>
4684 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4689 # if NETINET6 && defined(SIOCGLIFCONF)
4693 ** Unfortunately, HP has changed all of the structures,
4694 ** making life difficult for implementors.
4697 # define lifconf if_laddrconf
4698 # define lifc_len iflc_len
4699 # define lifc_buf iflc_buf
4700 # define lifreq if_laddrreq
4701 # define lifr_addr iflr_addr
4702 # define lifr_name iflr_name
4703 # define lifr_flags iflr_flags
4704 # define ss_family sa_family
4706 # endif /* __hpux */
4713 struct lifconf lifc;
4716 # endif /* SIOCGLIFNUM */
4718 s = socket(InetMode, SOCK_DGRAM, 0);
4722 /* get the list of known IP address from the kernel */
4724 i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
4725 # endif /* __hpux */
4727 lifn.lifn_family = AF_UNSPEC;
4728 lifn.lifn_flags = 0;
4729 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
4730 numifs = lifn.lifn_count;
4731 # endif /* SIOCGLIFNUM */
4733 # if defined(__hpux) || defined(SIOCGLIFNUM)
4736 /* can't get number of interfaces -- fall back */
4738 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4739 sm_errstring(errno));
4742 else if (tTd(0, 42))
4743 sm_dprintf("system has %d interfaces\n", numifs);
4745 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4746 numifs = MAXINTERFACES;
4754 len = lifc.lifc_len = numifs * sizeof (struct lifreq);
4755 buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
4757 lifc.lifc_family = AF_UNSPEC;
4758 lifc.lifc_flags = 0;
4759 # endif /* ! __hpux */
4760 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
4763 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4764 sm_errstring(errno));
4770 /* scan the list of IP address */
4772 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4775 for (i = 0; i < len && i >= 0; )
4778 struct lifreq *ifr = (struct lifreq *)&buf[i];
4779 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
4780 int af = ifr->lifr_addr.ss_family;
4783 struct in6_addr ia6;
4785 # ifdef SIOCGLIFFLAGS
4787 # endif /* SIOCGLIFFLAGS */
4789 char buf6[INET6_ADDRSTRLEN];
4792 ** We must close and recreate the socket each time
4793 ** since we don't know what type of socket it is now
4794 ** (each status function may change it).
4799 s = socket(af, SOCK_DGRAM, 0);
4802 sm_free(buf); /* XXX */
4807 ** If we don't have a complete ifr structure,
4808 ** don't try to use it.
4811 if ((len - i) < sizeof *ifr)
4814 # ifdef BSD4_4_SOCKADDR
4815 if (sa->sa.sa_len > sizeof ifr->lifr_addr)
4816 i += sizeof ifr->lifr_name + sa->sa.sa_len;
4818 # endif /* BSD4_4_SOCKADDR */
4822 sm_dprintf("%s\n", anynet_ntoa(sa));
4824 if (af != AF_INET && af != AF_INET6)
4827 # ifdef SIOCGLIFFLAGS
4828 memset(&ifrf, '\0', sizeof(struct lifreq));
4829 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
4830 sizeof(ifrf.lifr_name));
4831 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
4834 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4835 sm_errstring(errno));
4839 name = ifr->lifr_name;
4840 flags = ifrf.lifr_flags;
4843 sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
4845 if (!bitset(IFF_UP, flags))
4847 # endif /* SIOCGLIFFLAGS */
4851 /* extract IP address from the list*/
4856 /* convert into proper scoped address */
4857 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
4858 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
4859 sa->sin6.sin6_scope_id == 0)
4861 struct in6_addr *ia6p;
4863 ia6p = &sa->sin6.sin6_addr;
4864 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
4865 ((unsigned int)ia6p->s6_addr[2] << 8));
4866 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
4868 # endif /* __KAME__ */
4869 ia6 = sa->sin6.sin6_addr;
4870 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
4872 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
4873 message("WARNING: interface %s is UP with %s address",
4874 name, addr == NULL ? "(NULL)" : addr);
4878 /* save IP address in text from */
4879 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
4881 (void) sm_snprintf(ip_addr, sizeof ip_addr,
4883 (int) sizeof ip_addr - 3,
4888 ia = sa->sin.sin_addr;
4889 if (ia.s_addr == INADDR_ANY ||
4890 ia.s_addr == INADDR_NONE)
4892 message("WARNING: interface %s is UP with %s address",
4893 name, inet_ntoa(ia));
4897 /* save IP address in text from */
4898 (void) sm_snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
4899 (int) sizeof ip_addr - 3, inet_ntoa(ia));
4903 if (*ip_addr == '\0')
4906 if (!wordinclass(ip_addr, 'w'))
4908 setclass('w', ip_addr);
4910 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
4913 # ifdef SIOCGLIFFLAGS
4914 /* skip "loopback" interface "lo" */
4915 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
4916 bitset(IFF_LOOPBACK, flags))
4918 # endif /* SIOCGLIFFLAGS */
4919 (void) add_hostnames(sa);
4921 sm_free(buf); /* XXX */
4923 # else /* NETINET6 && defined(SIOCGLIFCONF) */
4924 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4930 s = socket(AF_INET, SOCK_DGRAM, 0);
4934 /* get the list of known IP address from the kernel */
4935 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
4936 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
4938 /* can't get number of interfaces -- fall back */
4940 sm_dprintf("SIOCGIFNUM failed: %s\n",
4941 sm_errstring(errno));
4944 else if (tTd(0, 42))
4945 sm_dprintf("system has %d interfaces\n", numifs);
4947 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
4948 numifs = MAXINTERFACES;
4955 ifc.ifc_len = numifs * sizeof (struct ifreq);
4956 ifc.ifc_buf = xalloc(ifc.ifc_len);
4957 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
4960 sm_dprintf("SIOCGIFCONF failed: %s\n",
4961 sm_errstring(errno));
4966 /* scan the list of IP address */
4968 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
4971 for (i = 0; i < ifc.ifc_len && i >= 0; )
4974 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
4975 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
4978 struct in6_addr ia6;
4979 # endif /* NETINET6 */
4981 # ifdef SIOCGIFFLAGS
4983 # endif /* SIOCGIFFLAGS */
4986 char buf6[INET6_ADDRSTRLEN];
4987 # endif /* NETINET6 */
4990 ** If we don't have a complete ifr structure,
4991 ** don't try to use it.
4994 if ((ifc.ifc_len - i) < sizeof *ifr)
4997 # ifdef BSD4_4_SOCKADDR
4998 if (sa->sa.sa_len > sizeof ifr->ifr_addr)
4999 i += sizeof ifr->ifr_name + sa->sa.sa_len;
5001 # endif /* BSD4_4_SOCKADDR */
5005 sm_dprintf("%s\n", anynet_ntoa(sa));
5007 af = ifr->ifr_addr.sa_family;
5011 # endif /* NETINET6 */
5015 # ifdef SIOCGIFFLAGS
5016 memset(&ifrf, '\0', sizeof(struct ifreq));
5017 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
5018 sizeof(ifrf.ifr_name));
5019 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
5021 sm_dprintf("\tflags: %lx\n",
5022 (unsigned long) ifrf.ifr_flags);
5023 # define IFRFREF ifrf
5024 # else /* SIOCGIFFLAGS */
5025 # define IFRFREF (*ifr)
5026 # endif /* SIOCGIFFLAGS */
5028 if (!bitset(IFF_UP, IFRFREF.ifr_flags))
5033 /* extract IP address from the list*/
5037 ia = sa->sin.sin_addr;
5038 if (ia.s_addr == INADDR_ANY ||
5039 ia.s_addr == INADDR_NONE)
5041 message("WARNING: interface %s is UP with %s address",
5042 ifr->ifr_name, inet_ntoa(ia));
5046 /* save IP address in text from */
5047 (void) sm_snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
5048 (int) sizeof ip_addr - 3,
5055 /* convert into proper scoped address */
5056 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5057 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5058 sa->sin6.sin6_scope_id == 0)
5060 struct in6_addr *ia6p;
5062 ia6p = &sa->sin6.sin6_addr;
5063 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5064 ((unsigned int)ia6p->s6_addr[2] << 8));
5065 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5067 # endif /* __KAME__ */
5068 ia6 = sa->sin6.sin6_addr;
5069 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5071 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
5072 message("WARNING: interface %s is UP with %s address",
5074 addr == NULL ? "(NULL)" : addr);
5078 /* save IP address in text from */
5079 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
5081 (void) sm_snprintf(ip_addr, sizeof ip_addr,
5083 (int) sizeof ip_addr - 3,
5087 # endif /* NETINET6 */
5090 if (ip_addr[0] == '\0')
5093 if (!wordinclass(ip_addr, 'w'))
5095 setclass('w', ip_addr);
5097 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5100 /* skip "loopback" interface "lo" */
5101 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5102 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
5105 (void) add_hostnames(sa);
5107 sm_free(ifc.ifc_buf); /* XXX */
5110 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5111 # endif /* NETINET6 && defined(SIOCGLIFCONF) */
5114 ** ISLOOPBACK -- is socket address in the loopback net?
5117 ** sa -- socket address.
5120 ** true -- is socket address in the loopback net?
5121 ** false -- otherwise
5130 if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
5132 #else /* NETINET6 */
5133 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5134 if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
5135 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
5137 #endif /* NETINET6 */
5141 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5147 ** The number of processors online.
5151 get_num_procs_online()
5156 # if defined(CTL_HW) && defined(HW_NCPU)
5162 sz = (size_t) sizeof nproc;
5163 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
5164 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5165 #else /* USESYSCTL */
5166 # ifdef _SC_NPROCESSORS_ONLN
5167 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
5168 # else /* _SC_NPROCESSORS_ONLN */
5170 # include <sys/pstat.h>
5171 struct pst_dynamic psd;
5173 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
5174 nproc = psd.psd_proc_cnt;
5175 # endif /* __hpux */
5176 # endif /* _SC_NPROCESSORS_ONLN */
5177 #endif /* USESYSCTL */
5184 ** SM_CLOSEFROM -- close file descriptors
5187 ** lowest -- first fd to close
5188 ** highest -- last fd + 1 to close
5195 sm_closefrom(lowest, highest)
5196 int lowest, highest;
5200 #else /* HASCLOSEFROM */
5203 for (i = lowest; i < highest; i++)
5205 #endif /* HASCLOSEFROM */
5209 ** CLOSEFD_WALK -- walk fd's arranging to close them
5210 ** Callback for fdwalk()
5213 ** lowest -- first fd to arrange to be closed
5214 ** fd -- fd to arrange to be closed
5221 closefd_walk(lowest, fd)
5225 if (fd >= *(int *)lowest)
5226 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
5229 #endif /* HASFDWALK */
5231 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5234 ** lowest -- first fd to arrange to be closed
5235 ** highest -- last fd + 1 to arrange to be closed
5242 sm_close_on_exec(highest, lowest)
5243 int highest, lowest;
5246 (void) fdwalk(closefd_walk, &lowest);
5247 #else /* HASFDWALK */
5250 for (i = lowest; i < highest; i++)
5252 if ((j = fcntl(i, F_GETFD, 0)) != -1)
5253 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
5255 #endif /* HASFDWALK */
5258 ** SEED_RANDOM -- seed the random number generator
5272 #else /* HASSRANDOMDEV */
5276 seed = (long) CurrentPid;
5277 if (gettimeofday(&t, NULL) >= 0)
5278 seed += t.tv_sec + t.tv_usec;
5281 (void) srandom(seed);
5282 # else /* HASRANDOM */
5283 (void) srand((unsigned int) seed);
5284 # endif /* HASRANDOM */
5285 #endif /* HASSRANDOMDEV */
5288 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5291 ** level -- syslog level
5292 ** id -- envelope ID or NULL (NOQUEUE)
5293 ** fmt -- format string
5294 ** arg... -- arguments as implied by fmt.
5303 sm_syslog(int level, const char *id, const char *fmt, ...)
5304 #else /* __STDC__ */
5305 sm_syslog(level, id, fmt, va_alist)
5310 #endif /* __STDC__ */
5312 static char *buf = NULL;
5313 static size_t bufsize;
5320 extern int SyslogPrefixLen;
5327 idlen = strlen(id) + SyslogPrefixLen;
5329 else if (strcmp(id, NOQID) == 0)
5332 idlen = SyslogPrefixLen;
5335 idlen = strlen(id) + SyslogPrefixLen;
5340 bufsize = sizeof buf0;
5347 /* print log message into buf */
5348 SM_VA_START(ap, fmt);
5349 n = sm_vsnprintf(buf, bufsize, fmt, ap);
5355 /* String too small, redo with correct size */
5362 buf = sm_malloc_x(bufsize);
5365 /* clean up buf after it has been expanded with args */
5366 newstring = str2prt(buf);
5367 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
5371 syslog(level, "%s", newstring);
5373 syslog(level, "%s: %s", id, newstring);
5375 /*XXX should do something more sensible */
5377 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
5380 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5381 "%s: %s\n", id, newstring);
5390 ** additional length for splitting: " ..." + 3, where 3 is magic to
5391 ** have some data for the next entry.
5397 idlen += 5; /* strlen("[999]"), see below */
5398 while (*begin != '\0' &&
5399 (strlen(begin) + idlen) > SYSLOG_BUFSIZE)
5405 /* Too many messages */
5408 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5411 /* Break on comma or space */
5412 if (*end == ',' || *end == ' ')
5414 end++; /* Include separator */
5419 /* No separator, break midstring... */
5421 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5425 syslog(level, "%s[%d]: %s ...", id, seq++, begin);
5427 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5428 "%s[%d]: %s ...\n", id, seq++, begin);
5435 syslog(level, "%s[%d]: log terminated, too many parts",
5438 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5439 "%s[%d]: log terminated, too many parts\n", id, seq);
5441 else if (*begin != '\0')
5443 syslog(level, "%s[%d]: %s", id, seq, begin);
5445 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5446 "%s[%d]: %s\n", id, seq, begin);
5453 ** HARD_SYSLOG -- call syslog repeatedly until it works
5455 ** Needed on HP-UX, which apparently doesn't guarantee that
5456 ** syslog succeeds during interrupt handlers.
5459 #if defined(__hpux) && !defined(HPUX11)
5461 # define MAXSYSLOGTRIES 100
5464 # define XCNST const
5465 # define CAST (const char *)
5473 hard_syslog(int pri, XCNST char *msg, ...)
5474 # else /* __STDC__ */
5475 hard_syslog(pri, msg, va_alist)
5479 # endif /* __STDC__ */
5482 char buf[SYSLOG_BUFSIZE];
5485 SM_VA_START(ap, msg);
5486 (void) sm_vsnprintf(buf, sizeof buf, msg, ap);
5489 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
5494 #endif /* defined(__hpux) && !defined(HPUX11) */
5495 #if NEEDLOCAL_HOSTNAME_LENGTH
5497 ** LOCAL_HOSTNAME_LENGTH
5499 ** This is required to get sendmail to compile against BIND 4.9.x
5502 ** Unfortunately, a Compaq Y2K patch kit provides it without
5503 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5504 ** figure out whether it is needed.
5508 local_hostname_length(hostname)
5511 size_t len_host, len_domain;
5513 if (!*_res.defdname)
5515 len_host = strlen(hostname);
5516 len_domain = strlen(_res.defdname);
5517 if (len_host > len_domain &&
5518 (sm_strcasecmp(hostname + len_host - len_domain,
5519 _res.defdname) == 0) &&
5520 hostname[len_host - len_domain - 1] == '.')
5521 return len_host - len_domain - 1;
5525 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5529 ** LINK -- clone a file
5531 ** Some OS's lacks link() and hard links. Since sendmail is using
5532 ** link() as an efficient way to clone files, this implementation
5533 ** will simply do a file copy.
5535 ** NOTE: This link() replacement is not a generic replacement as it
5536 ** does not handle all of the semantics of the real link(2).
5539 ** source -- pathname of existing file.
5540 ** target -- pathname of link (clone) to be created.
5544 ** -1 -- failure, see errno for details.
5548 link(source, target)
5554 int src = -1, dst = -1;
5560 sff = SFF_REGONLY|SFF_OPENASROOT;
5561 if (DontLockReadFiles)
5564 /* Open the original file */
5565 src = safeopen((char *)source, O_RDONLY, 0, sff);
5569 /* Obtain the size and the mode */
5570 if (fstat(src, &st) < 0)
5573 /* Create the duplicate copy */
5576 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
5581 /* Copy all of the bytes one buffer at a time */
5582 while ((readlen = read(src, &buf, sizeof(buf))) > 0)
5584 ssize_t left = readlen;
5588 (writelen = write(dst, p, (size_t) left)) >= 0)
5597 /* Any trouble reading? */
5598 if (readlen < 0 || writelen < 0)
5601 /* Close the input file */
5609 /* Close the output file */
5612 /* don't set dst = -1 here so we unlink the file */
5625 (void) unlink(target);
5631 #endif /* NEEDLINK */
5634 ** Compile-Time options
5637 char *CompileOptions[] =
5641 #endif /* ALLOW_255 */
5645 # endif /* DNSMAP */
5646 #endif /* NAMED_BIND */
5655 #endif /* HES_GETMAILHOST */
5658 #endif /* LDAPMAP */
5664 #endif /* MAP_NSD */
5667 #endif /* MAP_REGEX */
5670 #endif /* MATCHGECOS */
5676 #endif /* MIME7TO8 */
5679 #endif /* MIME7TO8_OLD */
5682 #endif /* MIME8TO7 */
5685 #endif /* NAMED_BIND */
5691 #endif /* NETINET */
5694 #endif /* NETINET6 */
5697 #endif /* NETINFO */
5706 #endif /* NETUNIX */
5718 #endif /* NISPLUS */
5725 #ifdef PICKY_HELO_CHECK
5727 #endif /* PICKY_HELO_CHECK */
5730 #endif /* PIPELINING */
5734 # else /* SASL >= 20000 */
5736 # endif /* SASL >= 20000 */
5743 #endif /* SMTPDEBUG */
5746 #endif /* SOCKETMAP */
5749 #endif /* STARTTLS */
5750 #if SUID_ROOT_FILES_OK
5751 "SUID_ROOT_FILES_OK",
5752 #endif /* SUID_ROOT_FILES_OK */
5755 #endif /* TCPWRAPPERS */
5758 #endif /* TLS_NO_RSA */
5759 #if TLS_VRFY_PER_CTX
5761 #endif /* TLS_VRFY_PER_CTX */
5767 #endif /* USE_LDAP_INIT */
5770 #endif /* USE_TTYPATH */
5782 ** OS compile options.
5785 char *OsCompileOptions[] =
5787 #if ADDRCONFIG_IS_BROKEN
5788 "ADDRCONFIG_IS_BROKEN",
5789 #endif /* ADDRCONFIG_IS_BROKEN */
5790 #ifdef AUTO_NETINFO_HOSTS
5791 "AUTO_NETINFO_HOSTS",
5792 #endif /* AUTO_NETINFO_HOSTS */
5793 #ifdef AUTO_NIS_ALIASES
5795 #endif /* AUTO_NIS_ALIASES */
5796 #if BROKEN_RES_SEARCH
5797 "BROKEN_RES_SEARCH",
5798 #endif /* BROKEN_RES_SEARCH */
5799 #ifdef BSD4_4_SOCKADDR
5801 #endif /* BSD4_4_SOCKADDR */
5804 #endif /* BOGUS_O_EXCL */
5805 #if DEC_OSF_BROKEN_GETPWENT
5806 "DEC_OSF_BROKEN_GETPWENT",
5807 #endif /* DEC_OSF_BROKEN_GETPWENT */
5808 #if FAST_PID_RECYCLE
5810 #endif /* FAST_PID_RECYCLE */
5813 #endif /* HASCLOSEFROM */
5816 #endif /* HASFCHOWN */
5819 #endif /* HASFCHMOD */
5822 #endif /* HASFDWALK */
5825 #endif /* HASFLOCK */
5826 #if HASGETDTABLESIZE
5828 #endif /* HASGETDTABLESIZE */
5831 #endif /* HASGETUSERSHELL */
5834 #endif /* HASINITGROUPS */
5837 #endif /* HASLSTAT */
5840 #endif /* HASNICE */
5843 #endif /* HASRANDOM */
5846 #endif /* HASRRESVPORT */
5849 #endif /* HASSETEGID */
5852 #endif /* HASSETLOGIN */
5855 #endif /* HASSETREGID */
5858 #endif /* HASSETRESGID */
5861 #endif /* HASSETREUID */
5864 #endif /* HASSETRLIMIT */
5867 #endif /* HASSETSID */
5868 #if HASSETUSERCONTEXT
5869 "HASSETUSERCONTEXT",
5870 #endif /* HASSETUSERCONTEXT */
5873 #endif /* HASSETVBUF */
5876 #endif /* HAS_ST_GEN */
5879 #endif /* HASSRANDOMDEV */
5882 #endif /* HASURANDOMDEV */
5885 #endif /* HASSTRERROR */
5888 #endif /* HASULIMIT */
5891 #endif /* HASUNAME */
5894 #endif /* HASUNSETENV */
5897 #endif /* HASWAITPID */
5900 #endif /* IDENTPROTO */
5903 #endif /* IP_SRCROUTE */
5904 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
5906 #endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */
5909 #endif /* NEEDFSYNC */
5912 #endif /* NEEDLINK */
5913 #if NEEDLOCAL_HOSTNAME_LENGTH
5914 "NEEDLOCAL_HOSTNAME_LENGTH",
5915 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5918 #endif /* NEEDSGETIPNODE */
5921 #endif /* NEEDSTRSTR */
5924 #endif /* NEEDSTRTOL */
5925 #ifdef NO_GETSERVBYNAME
5927 #endif /* NO_GETSERVBYNAME */
5930 #endif /* NOFTRUNCATE */
5931 #if REQUIRES_DIR_FSYNC
5932 "REQUIRES_DIR_FSYNC",
5933 #endif /* REQUIRES_DIR_FSYNC */
5934 #if RLIMIT_NEEDS_SYS_TIME_H
5935 "RLIMIT_NEEDS_SYS_TIME_H",
5936 #endif /* RLIMIT_NEEDS_SYS_TIME_H */
5939 #endif /* SAFENFSPATHCONF */
5942 #endif /* SECUREWARE */
5945 #endif /* SHARE_V1 */
5946 #if SIOCGIFCONF_IS_BROKEN
5947 "SIOCGIFCONF_IS_BROKEN",
5948 #endif /* SIOCGIFCONF_IS_BROKEN */
5949 #if SIOCGIFNUM_IS_BROKEN
5950 "SIOCGIFNUM_IS_BROKEN",
5951 #endif /* SIOCGIFNUM_IS_BROKEN */
5952 #if SNPRINTF_IS_BROKEN
5953 "SNPRINTF_IS_BROKEN",
5954 #endif /* SNPRINTF_IS_BROKEN */
5955 #if SO_REUSEADDR_IS_BROKEN
5956 "SO_REUSEADDR_IS_BROKEN",
5957 #endif /* SO_REUSEADDR_IS_BROKEN */
5960 #endif /* SYS5SETPGRP */
5963 #endif /* SYSTEM5 */
5966 #endif /* USE_DOUBLE_FORK */
5969 #endif /* USE_ENVIRON */
5970 #if USE_SA_SIGACTION
5972 #endif /* USE_SA_SIGACTION */
5975 #endif /* USE_SIGLONGJMP */
5978 #endif /* USEGETCONFATTR */
5981 #endif /* USESETEUID */
5984 #endif /* USESYSCTL */
5985 #if USING_NETSCAPE_LDAP
5986 "USING_NETSCAPE_LDAP",
5987 #endif /* USING_NETSCAPE_LDAP */
5990 #endif /* WAITUNION */
5995 ** FFR compile options.
5998 char *FFRCompileOptions[] =
6000 #if _FFR_ALLOW_SASLINFO
6001 /* DefaultAuthInfo can be specified by user. */
6002 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */
6003 "_FFR_ALLOW_SASLINFO",
6004 #endif /* _FFR_ALLOW_SASLINFO */
6005 #if _FFR_BESTMX_BETTER_TRUNCATION
6006 /* Better truncation of list of MX records for dns map. */
6007 "_FFR_BESTMX_BETTER_TRUNCATION",
6008 #endif /* _FFR_BESTMX_BETTER_TRUNCATION */
6009 #if _FFR_BLOCK_PROXIES
6011 ** Try to deal with open HTTP proxies that are used to send spam
6012 ** by recognizing some commands from them.
6015 "_FFR_BLOCK_PROXIES",
6016 #endif /* _FFR_BLOCK_PROXIES */
6017 #if _FFR_CATCH_BROKEN_MTAS
6018 /* Deal with MTAs that send a reply during the DATA phase. */
6019 "_FFR_CATCH_BROKEN_MTAS",
6020 #endif /* _FFR_CATCH_BROKEN_MTAS */
6022 /* Enable check_eom ruleset */
6024 #endif /* _FFR_CHECK_EOM */
6026 /* Stricter checks about queue directory permissions. */
6028 #endif /* _FFR_CHK_QUEUE */
6029 #if _FFR_CLIENT_SIZE
6030 /* Don't try to send mail if its size exceeds SIZE= of server. */
6032 #endif /* _FFR_CLIENT_SIZE */
6033 #if _FFR_CONTROL_MSTAT
6034 /* Extended daemon status. */
6035 "_FFR_CONTROL_MSTAT",
6036 #endif /* _FFR_CONTROL_MSTAT */
6038 /* CRLPath; needs documentation; Al Smith */
6040 #endif /* _FFR_CRLPATH */
6041 #if _FFR_DAEMON_NETUNIX
6042 /* Allow local (not just TCP) socket connection to server. */
6043 "_FFR_DAEMON_NETUNIX",
6044 #endif /* _FFR_DAEMON_NETUNIX */
6045 #if _FFR_DEPRECATE_MAILER_FLAG_I
6046 /* What it says :-) */
6047 "_FFR_DEPRECATE_MAILER_FLAG_I",
6048 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
6049 #if _FFR_DIGUNIX_SAFECHOWN
6050 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6051 /* Problem noted by Anne Bennett of Concordia University */
6052 "_FFR_DIGUNIX_SAFECHOWN",
6053 #endif /* _FFR_DIGUNIX_SAFECHOWN */
6054 #if _FFR_DM_PER_DAEMON
6055 /* DeliveryMode per DaemonPortOptions: 'D' */
6056 "_FFR_DM_PER_DAEMON",
6057 #endif /* _FFR_DM_PER_DAEMON */
6058 #if _FFR_DNSMAP_ALIASABLE
6059 /* Allow dns map type to be used for aliases. */
6060 /* Don Lewis of TDK */
6061 "_FFR_DNSMAP_ALIASABLE",
6062 #endif /* _FFR_DNSMAP_ALIASABLE */
6063 #if _FFR_DNSMAP_BASE
6064 /* Specify a "base" domain for DNS lookups. */
6066 #endif /* _FFR_DNSMAP_BASE */
6067 #if _FFR_DNSMAP_MULTI
6068 /* Allow multiple return values for DNS map. */
6069 "_FFR_DNSMAP_MULTI",
6070 # if _FFR_DNSMAP_MULTILIMIT
6071 /* Limit number of return values for DNS map. */
6072 "_FFR_DNSMAP_MULTILIMIT",
6073 # endif /* _FFR_DNSMAP_MULTILIMIT */
6074 #endif /* _FFR_DNSMAP_MULTI */
6075 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6076 /* Enable DontLockFilesForRead option. */
6077 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6078 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
6079 #if _FFR_DOTTED_USERNAMES
6080 /* Allow usernames with '.' */
6081 "_FFR_DOTTED_USERNAMES",
6082 #endif /* _FFR_DOTTED_USERNAMES */
6083 #if _FFR_DROP_TRUSTUSER_WARNING
6085 ** Don't issue this warning:
6086 ** "readcf: option TrustedUser may cause problems on systems
6087 ** which do not support fchown() if UseMSP is not set.
6090 "_FFR_DROP_TRUSTUSER_WARNING",
6091 #endif /* _FFR_DROP_TRUSTUSER_WARNING */
6092 #if _FFR_EXTRA_MAP_CHECK
6093 /* perform extra checks on $( $) in R lines */
6094 "_FFR_EXTRA_MAP_CHECK",
6095 #endif /* _FFR_EXTRA_MAP_CHECK */
6098 ** If using -t, force not sending to argv recipients, even
6099 ** if they are mentioned in the headers.
6103 #endif /* _FFR_FIX_DASHT */
6104 #if _FFR_FORWARD_SYSERR
6105 /* Cause a "syserr" if forward file isn't "safe". */
6106 "_FFR_FORWARD_SYSERR",
6107 #endif /* _FFR_FORWARD_SYSERR */
6109 /* Generate a ORCPT DSN arg if not already provided */
6111 #endif /* _FFR_GEN_ORCPT */
6112 #if _FFR_GROUPREADABLEAUTHINFOFILE
6113 /* Allow group readable DefaultAuthInfo file. */
6114 "_FFR_GROUPREADABLEAUTHINFOFILE",
6115 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
6116 #if _FFR_HANDLE_ISO8859_GECOS
6118 ** Allow ISO 8859 characters in GECOS field: replace them
6119 ** ith ASCII "equivalent".
6122 /* Peter Eriksson of Linkopings universitet */
6123 "_FFR_HANDLE_ISO8859_GECOS",
6124 #endif /* _FFR_HANDLE_ISO8859_GECOS */
6126 /* Set 'h' in {addr_type} for headers. */
6128 #endif /* _FFR_HDR_TYPE */
6130 /* option to set heloname; Nik Clayton of FreeBSD */
6132 #endif /* _FFR_HELONAME */
6133 #if _FFR_HPUX_NSSWITCH
6134 /* Use nsswitch on HP-UX */
6135 "_FFR_HPUX_NSSWITCH",
6136 #endif /* _FFR_HPUX_NSSWITCH */
6137 #if _FFR_IGNORE_BOGUS_ADDR
6138 /* Ignore addresses for which prescan() failed */
6139 "_FFR_IGNORE_BOGUS_ADDR",
6140 #endif /* _FFR_IGNORE_BOGUS_ADDR */
6141 #if _FFR_IGNORE_EXT_ON_HELO
6142 /* Ignore extensions offered in response to HELO */
6143 "_FFR_IGNORE_EXT_ON_HELO",
6144 #endif /* _FFR_IGNORE_EXT_ON_HELO */
6145 #if _FFR_MAXDATASIZE
6147 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6148 ** hence this shouldn't be used as limit for milter communication.
6149 ** see also libmilter/comm.c
6150 ** Gurusamy Sarathy of ActiveState
6154 #endif /* _FFR_MAXDATASIZE */
6155 #if _FFR_MAX_FORWARD_ENTRIES
6156 /* Try to limit number of .forward entries */
6157 /* (doesn't work) */
6158 /* Randall S. Winchester of the University of Maryland */
6159 "_FFR_MAX_FORWARD_ENTRIES",
6160 #endif /* _FFR_MAX_FORWARD_ENTRIES */
6161 #if _FFR_MAX_SLEEP_TIME
6162 /* Limit sleep(2) time in libsm/clock.c */
6163 "_FFR_MAX_SLEEP_TIME",
6164 #endif /* _FFR_MAX_SLEEP_TIME */
6165 #if _FFR_MILTER_NAGLE
6166 /* milter: turn off Nagle ("cork" on Linux) */
6167 /* John Gardiner Myers of Proofpoint */
6168 "_FFR_MILTER_NAGLE ",
6169 #endif /* _FFR_MILTER_NAGLE */
6170 #if _FFR_MILTER_NOHDR_RESP
6171 /* milter: no response expected when sending headers */
6172 /* John Gardiner Myers of Proofpoint */
6173 "_FFR_MILTER_NOHDR_RESP",
6174 #endif /* _FFR_MILTER_NOHDR_RESP */
6175 #if _FFR_MIME7TO8_OLD
6176 /* Old mime7to8 code, the new is broken for at least one example. */
6177 "_FFR_MIME7TO8_OLD",
6178 #endif /* _FFR_MAX_SLEEP_TIME */
6179 #if _FFR_NODELAYDSN_ON_HOLD
6180 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6182 "_FFR_NODELAYDSN_ON_HOLD",
6183 #endif /* _FFR_NODELAYDSN_ON_HOLD */
6185 /* Disable PIPELINING, delay client if used. */
6187 #endif /* _FFR_NO_PIPE */
6189 /* log ntries=, from Nik Clayton of FreeBSD */
6191 #endif /* _FFR_LOG_NTRIES */
6192 #if _FFR_PRIV_NOACTUALRECIPIENT
6194 ** PrivacyOptions=noactualrecipient stops sendmail from putting
6195 ** X-Actual-Recipient lines in DSNs revealing the actual
6196 ** account that addresses map to. Patch from Dan Harkless.
6199 "_FFR_PRIV_NOACTUALRECIPIENT",
6200 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
6202 /* Exponential queue delay; disabled in 8.13 since it isn't used. */
6204 #endif /* _FFR_QUEUEDELAY */
6205 #if _FFR_QUEUE_GROUP_SORTORDER
6206 /* Allow QueueSortOrder per queue group. */
6207 /* XXX: Still need to actually use qgrp->qg_sortorder */
6208 "_FFR_QUEUE_GROUP_SORTORDER",
6209 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
6210 #if _FFR_QUEUE_MACRO
6211 /* Define {queue} macro. */
6213 #endif /* _FFR_QUEUE_MACRO */
6214 #if _FFR_QUEUE_RUN_PARANOIA
6215 /* Additional checks when doing queue runs. */
6216 "_FFR_QUEUE_RUN_PARANOIA",
6217 #endif /* _FFR_QUEUE_RUN_PARANOIA */
6218 #if _FFR_QUEUE_SCHED_DBG
6219 /* Debug output for the queue scheduler. */
6220 "_FFR_QUEUE_SCHED_DBG",
6221 #endif /* _FFR_QUEUE_SCHED_DBG */
6222 #if _FFR_REDIRECTEMPTY
6224 ** envelope <> can't be sent to mailing lists, only owner-
6225 ** send spam of this type to owner- of the list
6226 ** ---- to stop spam from going to mailing lists.
6229 "_FFR_REDIRECTEMPTY",
6230 #endif /* _FFR_REDIRECTEMPTY */
6231 #if _FFR_RESET_MACRO_GLOBALS
6232 /* Allow macro 'j' to be set dynamically via rulesets. */
6233 "_FFR_RESET_MACRO_GLOBALS",
6234 #endif /* _FFR_RESET_MACRO_GLOBALS */
6236 /* Random shuffle for queue sorting. */
6238 #endif /* _FFR_RHS */
6240 /* Auto-select of shared memory key */
6242 #endif /* _FFR_SELECT_SHM */
6244 /* Donated code (unused). */
6246 #endif /* _FFR_SHM_STATUS */
6247 #if _FFR_SKIP_DOMAINS
6248 /* process every N'th domain instead of every N'th message */
6249 "_FFR_SKIP_DOMAINS",
6250 #endif /* _FFR_SKIP_DOMAINS */
6251 #if _FFR_SLEEP_USE_SELECT
6252 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6253 "_FFR_SLEEP_USE_SELECT ",
6254 #endif /* _FFR_SLEEP_USE_SELECT */
6255 #if _FFR_SOFT_BOUNCE
6256 /* Turn all errors into temporary errors. */
6258 #endif /* _FFR_SOFT_BOUNCE */
6261 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6262 ** bit alignment, so unless each piece of argv and envp is a multiple
6263 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6264 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6265 ** if you use this FFR.
6268 /* Chris Adams of HiWAAY Informations Services */
6270 #endif /* _FFR_SPT_ALIGN */
6271 #if _FFR_SS_PER_DAEMON
6272 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6273 "_FFR_SS_PER_DAEMON",
6274 #endif /* _FFR_SS_PER_DAEMON */
6276 /* Donated code (unused). */
6278 #endif /* _FFR_TIMERS */
6280 /* More STARTTLS options, e.g., secondary certs. */
6282 #endif /* _FFR_TLS_1 */
6285 ** If we don't own the file mark it as unsafe.
6286 ** However, allow TrustedUser to own it as well
6287 ** in case TrustedUser manipulates the queue.
6291 #endif /* _FFR_TRUSTED_QF */
6292 #if _FFR_USE_SEM_LOCKING
6293 "_FFR_USE_SEM_LOCKING",
6294 #endif /* _FFR_USE_SEM_LOCKING */
6295 #if _FFR_USE_SETLOGIN
6296 /* Use setlogin() */
6298 "_FFR_USE_SETLOGIN",
6299 #endif /* _FFR_USE_SETLOGIN */