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.
17 SM_RCSID("@(#)$Id: conf.c,v 8.1061 2005/03/07 17:18:44 ca Exp $")
19 #include <sendmail/pathnames.h>
24 # include <sys/ioctl.h>
25 # include <sys/param.h>
28 #if NETINET || NETINET6
29 # include <arpa/inet.h>
30 #endif /* NETINET || NETINET6 */
31 #if HASULIMIT && defined(HPUX11)
33 #endif /* HASULIMIT && defined(HPUX11) */
35 static void setupmaps __P((void));
36 static void setupmailers __P((void));
37 static void setupqueues __P((void));
38 static int get_num_procs_online __P((void));
39 static int add_hostnames __P((SOCKADDR *));
41 #if NETINET6 && NEEDSGETIPNODE
42 static struct hostent *getipnodebyname __P((char *, int, int, int *));
43 static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
44 #endif /* NETINET6 && NEEDSGETIPNODE */
48 ** CONF.C -- Sendmail Configuration Tables.
50 ** Defines the configuration of this installation.
52 ** Configuration Variables:
53 ** HdrInfo -- a table describing well-known header fields.
54 ** Each entry has the field name and some flags,
55 ** which are described in sendmail.h.
58 ** I have tried to put almost all the reasonable
59 ** configuration information into the configuration
60 ** file read at runtime. My intent is that anything
61 ** here is a function of the version of UNIX you
62 ** are running, or is really static -- for example
63 ** the headers are a superset of widely used
64 ** protocols. If you find yourself playing with
65 ** this file too much, you may be making a mistake!
71 ** Final (null) entry contains the flags used for any other field.
73 ** Not all of these are actually handled specially by sendmail
74 ** at this time. They are included as placeholders, to let
75 ** you know that "someday" I intend to have sendmail do
76 ** something with them.
79 struct hdrinfo HdrInfo[] =
81 /* originator fields, most to least significant */
82 { "resent-sender", H_FROM|H_RESENT, NULL },
83 { "resent-from", H_FROM|H_RESENT, NULL },
84 { "resent-reply-to", H_FROM|H_RESENT, NULL },
85 { "sender", H_FROM, NULL },
86 { "from", H_FROM, NULL },
87 { "reply-to", H_FROM, NULL },
88 { "errors-to", H_FROM|H_ERRORSTO, NULL },
89 { "full-name", H_ACHECK, NULL },
90 { "return-receipt-to", H_RECEIPTTO, NULL },
91 { "delivery-receipt-to", H_RECEIPTTO, NULL },
92 { "disposition-notification-to", H_FROM, NULL },
94 /* destination fields */
95 { "to", H_RCPT, NULL },
96 { "resent-to", H_RCPT|H_RESENT, NULL },
97 { "cc", H_RCPT, NULL },
98 { "resent-cc", H_RCPT|H_RESENT, NULL },
99 { "bcc", H_RCPT|H_BCC, NULL },
100 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
101 { "apparently-to", H_RCPT, NULL },
103 /* message identification and control */
104 { "message-id", 0, NULL },
105 { "resent-message-id", H_RESENT, NULL },
106 { "message", H_EOH, NULL },
107 { "text", H_EOH, NULL },
111 { "resent-date", H_RESENT, NULL },
114 { "received", H_TRACE|H_FORCE, NULL },
115 { "x400-received", H_TRACE|H_FORCE, NULL },
116 { "via", H_TRACE|H_FORCE, NULL },
117 { "mail-from", H_TRACE|H_FORCE, NULL },
119 /* miscellaneous fields */
120 { "comments", H_FORCE|H_ENCODABLE, NULL },
121 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
122 { "content-transfer-encoding", H_CTE, NULL },
123 { "content-type", H_CTYPE, NULL },
124 { "content-length", H_ACHECK, NULL },
125 { "subject", H_ENCODABLE, NULL },
126 { "x-authentication-warning", H_FORCE, NULL },
137 struct prival PrivacyValues[] =
139 { "public", PRIV_PUBLIC },
140 { "needmailhelo", PRIV_NEEDMAILHELO },
141 { "needexpnhelo", PRIV_NEEDEXPNHELO },
142 { "needvrfyhelo", PRIV_NEEDVRFYHELO },
143 { "noexpn", PRIV_NOEXPN },
144 { "novrfy", PRIV_NOVRFY },
145 { "restrictexpand", PRIV_RESTRICTEXPAND },
146 { "restrictmailq", PRIV_RESTRICTMAILQ },
147 { "restrictqrun", PRIV_RESTRICTQRUN },
148 { "noetrn", PRIV_NOETRN },
149 { "noverb", PRIV_NOVERB },
150 { "authwarnings", PRIV_AUTHWARNINGS },
151 { "noreceipts", PRIV_NORECEIPTS },
152 { "nobodyreturn", PRIV_NOBODYRETN },
153 { "goaway", PRIV_GOAWAY },
154 #if _FFR_PRIV_NOACTUALRECIPIENT
155 { "noactualrecipient", PRIV_NOACTUALRECIPIENT },
156 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
161 ** DontBlameSendmail values
164 struct dbsval DontBlameSendmailValues[] =
166 { "safe", DBS_SAFE },
167 { "assumesafechown", DBS_ASSUMESAFECHOWN },
168 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
169 { "groupwritableforwardfilesafe",
170 DBS_GROUPWRITABLEFORWARDFILESAFE },
171 { "groupwritableincludefilesafe",
172 DBS_GROUPWRITABLEINCLUDEFILESAFE },
173 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
174 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
175 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
176 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
177 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
178 { "linkedaliasfileinwritabledir",
179 DBS_LINKEDALIASFILEINWRITABLEDIR },
180 { "linkedclassfileinwritabledir",
181 DBS_LINKEDCLASSFILEINWRITABLEDIR },
182 { "linkedforwardfileinwritabledir",
183 DBS_LINKEDFORWARDFILEINWRITABLEDIR },
184 { "linkedincludefileinwritabledir",
185 DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
186 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
187 { "linkedserviceswitchfileinwritabledir",
188 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
189 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
190 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
191 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
192 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
193 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
194 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
195 { "forwardfileingroupwritabledirpath",
196 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
197 { "includefileingroupwritabledirpath",
198 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
199 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
200 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
201 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
202 { "forwardfileinunsafedirpathsafe",
203 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
204 { "includefileinunsafedirpathsafe",
205 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
206 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
207 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
208 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
209 { "truststickybit", DBS_TRUSTSTICKYBIT },
210 { "dontwarnforwardfileinunsafedirpath",
211 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
212 { "insufficiententropy", DBS_INSUFFICIENTENTROPY },
213 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
214 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
215 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
216 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
217 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
218 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
219 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
220 #if _FFR_GROUPREADABLEAUTHINFOFILE
221 { "groupreadableadefaultauthinfofile",
222 DBS_GROUPREADABLEAUTHINFOFILE },
223 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
228 ** Miscellaneous stuff.
231 int DtableSize = 50; /* max open files; reset in 4.2bsd */
233 ** SETDEFAULTS -- set default values
235 ** Some of these must be initialized using direct code since they
236 ** depend on run-time values. So let's do all of them this way.
239 ** e -- the default envelope.
245 ** Initializes a bunch of global variables to their
250 #define HOURS * 60 MINUTES
251 #define DAYS * 24 HOURS
253 #ifndef MAXRULERECURSION
254 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
255 #endif /* ! MAXRULERECURSION */
259 register ENVELOPE *e;
265 numprocs = get_num_procs_online();
266 SpaceSub = ' '; /* option B */
267 QueueLA = 8 * numprocs; /* option x */
268 RefuseLA = 12 * numprocs; /* option X */
269 WkRecipFact = 30000L; /* option y */
270 WkClassFact = 1800L; /* option z */
271 WkTimeFact = 90000L; /* option Z */
272 QueueFactor = WkRecipFact * 20; /* option q */
273 QueueMode = QM_NORMAL; /* what queue items to act upon */
274 FileMode = (RealUid != geteuid()) ? 0644 : 0600;
276 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
277 /* option QueueFileMode */
279 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
280 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
281 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
283 DefUid = pw->pw_uid; /* option u */
284 DefGid = pw->pw_gid; /* option g */
285 DefUser = newstr(pw->pw_name);
289 DefUid = 1; /* option u */
290 DefGid = 1; /* option g */
295 sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
296 DefUser != NULL ? DefUser : "<1:1>",
297 (int) DefUid, (int) DefGid);
298 CheckpointInterval = 10; /* option C */
299 MaxHopCount = 25; /* option h */
300 set_delivery_mode(SM_FORK, e); /* option d */
301 e->e_errormode = EM_PRINT; /* option e */
304 e->e_xfqgrp = NOQGRP;
305 e->e_xfqdir = NOQDIR;
306 e->e_ctime = curtime();
307 SevenBitInput = false; /* option 7 */
308 MaxMciCache = 1; /* option k */
309 MciCacheTimeout = 5 MINUTES; /* option K */
310 LogLevel = 9; /* option L */
314 inittimeouts(NULL, false); /* option r */
315 PrivacyFlags = PRIV_PUBLIC; /* option p */
316 MeToo = true; /* option m */
317 SendMIMEErrors = true; /* option f */
318 SuperSafe = SAFE_REALLY; /* option s */
319 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
321 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
323 MimeMode = MM_PASS8BIT;
324 #endif /* MIME8TO7 */
325 for (i = 0; i < MAXTOCLASS; i++)
327 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
328 TimeOuts.to_q_warning[i] = 0; /* option T */
330 ServiceSwitchFile = "/etc/mail/service.switch";
331 ServiceCacheMaxAge = (time_t) 10;
332 HostsFile = _PATH_HOSTS;
333 PidFile = newstr(_PATH_SENDMAILPID);
334 MustQuoteChars = "@,;:\\()[].'";
335 MciInfoTimeout = 30 MINUTES;
336 MaxRuleRecursion = MAXRULERECURSION;
337 MaxAliasRecursion = 10;
338 MaxMacroRecursion = 10;
339 ColonOkInAddr = true;
340 DontLockReadFiles = true;
341 DontProbeInterfaces = DPI_PROBEALL;
342 DoubleBounceAddr = "postmaster";
343 MaxHeadersLength = MAXHDRSLEN;
344 MaxMimeHeaderLength = MAXLINE;
345 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
346 MaxForwardEntries = 0;
349 AuthMechanisms = newstr(AUTH_MECHANISMS);
354 TLS_Srv_Opts = TLS_I_SRV;
355 #endif /* STARTTLS */
357 HesiodContext = NULL;
358 #endif /* HESIOD_INIT */
360 /* Detect if IPv6 is available at run time */
361 i = socket(AF_INET6, SOCK_STREAM, 0);
371 #endif /* NETINET6 */
372 ControlSocketName = NULL;
373 memset(&ConnectOnlyTo, '\0', sizeof ConnectOnlyTo);
374 DataFileBufferSize = 4096;
375 XscriptFileBufferSize = 4096;
376 for (i = 0; i < MAXRWSETS; i++)
377 RuleSetNames[i] = NULL;
379 InputFilters[0] = NULL;
381 RejectLogInterval = 3 HOURS;
382 #if REQUIRES_DIR_FSYNC
383 RequiresDirfsync = true;
384 #endif /* REQUIRES_DIR_FSYNC */
385 ConnectionRateWindowSize = 60;
394 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
400 struct passwd *defpwent;
401 static char defuserbuf[40];
403 DefUser = defuserbuf;
404 defpwent = sm_getpwuid(DefUid);
405 (void) sm_strlcpy(defuserbuf,
406 (defpwent == NULL || defpwent->pw_name == NULL)
407 ? "nobody" : defpwent->pw_name,
410 sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
411 (int) DefUid, DefUser);
414 ** SETUPQUEUES -- initialize default queues
416 ** The mqueue QUEUE structure gets filled in after readcf() but
417 ** we need something to point to now for the mailer setup,
418 ** which use "mqueue" as default queue.
426 MaxRunnersPerQueue = 1;
427 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof buf);
428 makequeue(buf, false);
431 ** SETUPMAILERS -- initialize default mailers
439 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
443 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
447 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
453 ** SETUPMAPS -- set up map classes
456 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
458 extern bool parse __P((MAP *, char *)); \
459 extern bool open __P((MAP *, int)); \
460 extern void close __P((MAP *)); \
461 extern char *lookup __P((MAP *, char *, char **, int *)); \
462 extern void store __P((MAP *, char *, char *)); \
463 s = stab(name, ST_MAPCLASS, ST_ENTER); \
464 s->s_mapclass.map_cname = name; \
465 s->s_mapclass.map_ext = ext; \
466 s->s_mapclass.map_cflags = flags; \
467 s->s_mapclass.map_parse = parse; \
468 s->s_mapclass.map_open = open; \
469 s->s_mapclass.map_close = close; \
470 s->s_mapclass.map_lookup = lookup; \
471 s->s_mapclass.map_store = store; \
480 # if DB_VERSION_MAJOR > 1
481 int major_v, minor_v, patch_v;
483 (void) db_version(&major_v, &minor_v, &patch_v);
484 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
487 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
488 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
489 major_v, minor_v, patch_v);
491 # endif /* DB_VERSION_MAJOR > 1 */
493 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
494 map_parseargs, hash_map_open, db_map_close,
495 db_map_lookup, db_map_store);
497 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
498 map_parseargs, bt_map_open, db_map_close,
499 db_map_lookup, db_map_store);
503 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
504 map_parseargs, ndbm_map_open, ndbm_map_close,
505 ndbm_map_lookup, ndbm_map_store);
509 MAPDEF("nis", NULL, MCF_ALIASOK,
510 map_parseargs, nis_map_open, null_map_close,
511 nis_map_lookup, null_map_store);
515 MAPDEF("nisplus", NULL, MCF_ALIASOK,
516 map_parseargs, nisplus_map_open, null_map_close,
517 nisplus_map_lookup, null_map_store);
521 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
522 ldapmap_parseargs, ldapmap_open, ldapmap_close,
523 ldapmap_lookup, null_map_store);
527 MAPDEF("ph", NULL, MCF_NOTPERSIST,
528 ph_map_parseargs, ph_map_open, ph_map_close,
529 ph_map_lookup, null_map_store);
533 /* IRIX 6.5 nsd support */
534 MAPDEF("nsd", NULL, MCF_ALIASOK,
535 map_parseargs, null_map_open, null_map_close,
536 nsd_map_lookup, null_map_store);
540 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
541 map_parseargs, hes_map_open, hes_map_close,
542 hes_map_lookup, null_map_store);
546 MAPDEF("netinfo", NULL, MCF_ALIASOK,
547 map_parseargs, ni_map_open, null_map_close,
548 ni_map_lookup, null_map_store);
552 MAPDEF("dns", NULL, 0,
553 dns_map_init, null_map_open, null_map_close,
554 dns_map_lookup, null_map_store);
559 # if _FFR_DNSMAP_ALIASABLE
560 MAPDEF("dns", NULL, MCF_ALIASOK,
561 dns_map_parseargs, dns_map_open, null_map_close,
562 dns_map_lookup, null_map_store);
563 # else /* _FFR_DNSMAP_ALIASABLE */
564 MAPDEF("dns", NULL, 0,
565 dns_map_parseargs, dns_map_open, null_map_close,
566 dns_map_lookup, null_map_store);
567 # endif /* _FFR_DNSMAP_ALIASABLE */
569 #endif /* NAMED_BIND */
572 /* best MX DNS lookup */
573 MAPDEF("bestmx", NULL, MCF_OPTFILE,
574 map_parseargs, null_map_open, null_map_close,
575 bestmx_map_lookup, null_map_store);
576 #endif /* NAMED_BIND */
578 MAPDEF("host", NULL, 0,
579 host_map_init, null_map_open, null_map_close,
580 host_map_lookup, null_map_store);
582 MAPDEF("text", NULL, MCF_ALIASOK,
583 map_parseargs, text_map_open, null_map_close,
584 text_map_lookup, null_map_store);
586 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
587 map_parseargs, stab_map_open, null_map_close,
588 stab_map_lookup, stab_map_store);
590 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
591 map_parseargs, impl_map_open, impl_map_close,
592 impl_map_lookup, impl_map_store);
594 /* access to system passwd file */
595 MAPDEF("user", NULL, MCF_OPTFILE,
596 map_parseargs, user_map_open, null_map_close,
597 user_map_lookup, null_map_store);
600 MAPDEF("dequote", NULL, 0,
601 dequote_init, null_map_open, null_map_close,
602 dequote_map, null_map_store);
605 MAPDEF("regex", NULL, 0,
606 regex_map_init, null_map_open, null_map_close,
607 regex_map_lookup, null_map_store);
608 #endif /* MAP_REGEX */
612 MAPDEF("userdb", ".db", 0,
613 map_parseargs, null_map_open, null_map_close,
614 udb_map_lookup, null_map_store);
617 /* arbitrary programs */
618 MAPDEF("program", NULL, MCF_ALIASOK,
619 map_parseargs, null_map_open, null_map_close,
620 prog_map_lookup, null_map_store);
623 MAPDEF("sequence", NULL, MCF_ALIASOK,
624 seq_map_parse, null_map_open, null_map_close,
625 seq_map_lookup, seq_map_store);
627 /* switched interface to sequenced maps */
628 MAPDEF("switch", NULL, MCF_ALIASOK,
629 map_parseargs, switch_map_open, null_map_close,
630 seq_map_lookup, seq_map_store);
632 /* null map lookup -- really for internal use only */
633 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
634 map_parseargs, null_map_open, null_map_close,
635 null_map_lookup, null_map_store);
637 /* syslog map -- logs information to syslog */
638 MAPDEF("syslog", NULL, 0,
639 syslog_map_parseargs, null_map_open, null_map_close,
640 syslog_map_lookup, null_map_store);
642 /* macro storage map -- rulesets can set macros */
643 MAPDEF("macro", NULL, 0,
644 dequote_init, null_map_open, null_map_close,
645 macro_map_lookup, null_map_store);
647 /* arithmetic map -- add/subtract/compare */
648 MAPDEF("arith", NULL, 0,
649 dequote_init, null_map_open, null_map_close,
650 arith_map_lookup, null_map_store);
653 /* arbitrary daemons */
654 MAPDEF("socket", NULL, MCF_ALIASOK,
655 map_parseargs, socket_map_open, socket_map_close,
656 socket_map_lookup, null_map_store);
657 #endif /* SOCKETMAP */
661 /* bogus map -- always return tempfail */
662 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
663 map_parseargs, null_map_open, null_map_close,
664 bogus_map_lookup, null_map_store);
670 ** INITHOSTMAPS -- initial host-dependent maps
672 ** This should act as an interface to any local service switch
673 ** provided by the host operating system.
682 ** Should define maps "host" and "users" as necessary
683 ** for this OS. If they are not defined, they will get
684 ** a default value later. It should check to make sure
685 ** they are not defined first, since it's possible that
686 ** the config file has provided an override.
694 char *maptype[MAXMAPSTACK];
695 short mapreturn[MAXMAPACTIONS];
699 ** Set up default hosts maps.
703 nmaps = switch_map_find("hosts", maptype, mapreturn);
704 for (i = 0; i < nmaps; i++)
706 if (strcmp(maptype[i], "files") == 0 &&
707 stab("hosts.files", ST_MAP, ST_FIND) == NULL)
709 (void) sm_strlcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts",
711 (void) makemapentry(buf);
714 else if (strcmp(maptype[i], "dns") == 0 &&
715 stab("hosts.dns", ST_MAP, ST_FIND) == NULL)
717 (void) sm_strlcpy(buf, "hosts.dns dns A", sizeof buf);
718 (void) makemapentry(buf);
720 # endif /* NAMED_BIND */
722 else if (strcmp(maptype[i], "nisplus") == 0 &&
723 stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL)
725 (void) sm_strlcpy(buf, "hosts.nisplus nisplus -k name -v address hosts.org_dir",
727 (void) makemapentry(buf);
729 # endif /* NISPLUS */
731 else if (strcmp(maptype[i], "nis") == 0 &&
732 stab("hosts.nis", ST_MAP, ST_FIND) == NULL)
734 (void) sm_strlcpy(buf, "hosts.nis nis -k 0 -v 1 hosts.byname",
736 (void) makemapentry(buf);
740 else if (strcmp(maptype[i], "netinfo") == 0 &&
741 stab("hosts.netinfo", ST_MAP, ST_FIND) == NULL)
743 (void) sm_strlcpy(buf, "hosts.netinfo netinfo -v name /machines",
745 (void) makemapentry(buf);
747 # endif /* NETINFO */
752 ** Make sure we have a host map.
755 if (stab("host", ST_MAP, ST_FIND) == NULL)
757 /* user didn't initialize: set up host map */
758 (void) sm_strlcpy(buf, "host host", sizeof buf);
760 if (ConfigLevel >= 2)
761 (void) sm_strlcat(buf, " -a. -D", sizeof buf);
762 #endif /* NAMED_BIND */
763 (void) makemapentry(buf);
767 ** Set up default aliases maps
770 nmaps = switch_map_find("aliases", maptype, mapreturn);
771 for (i = 0; i < nmaps; i++)
773 if (strcmp(maptype[i], "files") == 0 &&
774 stab("aliases.files", ST_MAP, ST_FIND) == NULL)
776 (void) sm_strlcpy(buf, "aliases.files null",
778 (void) makemapentry(buf);
781 else if (strcmp(maptype[i], "nisplus") == 0 &&
782 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
784 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
786 (void) makemapentry(buf);
790 else if (strcmp(maptype[i], "nis") == 0 &&
791 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
793 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
795 (void) makemapentry(buf);
799 else if (strcmp(maptype[i], "netinfo") == 0 &&
800 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
802 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
804 (void) makemapentry(buf);
808 else if (strcmp(maptype[i], "hesiod") == 0 &&
809 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
811 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
813 (void) makemapentry(buf);
817 if (stab("aliases", ST_MAP, ST_FIND) == NULL)
819 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof buf);
820 (void) makemapentry(buf);
823 #if 0 /* "user" map class is a better choice */
825 ** Set up default users maps.
828 nmaps = switch_map_find("passwd", maptype, mapreturn);
829 for (i = 0; i < nmaps; i++)
831 if (strcmp(maptype[i], "files") == 0 &&
832 stab("users.files", ST_MAP, ST_FIND) == NULL)
834 (void) sm_strlcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd",
836 (void) makemapentry(buf);
839 else if (strcmp(maptype[i], "nisplus") == 0 &&
840 stab("users.nisplus", ST_MAP, ST_FIND) == NULL)
842 (void) sm_strlcpy(buf, "users.nisplus nisplus -m -kname -vhome passwd.org_dir",
844 (void) makemapentry(buf);
846 # endif /* NISPLUS */
848 else if (strcmp(maptype[i], "nis") == 0 &&
849 stab("users.nis", ST_MAP, ST_FIND) == NULL)
851 (void) sm_strlcpy(buf, "users.nis nis -m passwd.byname",
853 (void) makemapentry(buf);
857 else if (strcmp(maptype[i], "hesiod") == 0 &&
858 stab("users.hesiod", ST_MAP, ST_FIND) == NULL)
860 (void) sm_strlcpy(buf, "users.hesiod hesiod", sizeof buf);
861 (void) makemapentry(buf);
865 if (stab("users", ST_MAP, ST_FIND) == NULL)
867 (void) sm_strlcpy(buf, "users switch -m passwd", sizeof buf);
868 (void) makemapentry(buf);
873 ** SWITCH_MAP_FIND -- find the list of types associated with a map
875 ** This is the system-dependent interface to the service switch.
878 ** service -- the name of the service of interest.
879 ** maptype -- an out-array of strings containing the types
880 ** of access to use for this service. There can
881 ** be at most MAXMAPSTACK types for a single service.
882 ** mapreturn -- an out-array of return information bitmaps
886 ** The number of map types filled in, or -1 for failure.
889 ** Preserves errno so nothing in the routine clobbers it.
892 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
893 # define _USE_SUN_NSSWITCH_
894 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
896 #if _FFR_HPUX_NSSWITCH
898 # define _USE_SUN_NSSWITCH_
900 #endif /* _FFR_HPUX_NSSWITCH */
902 #ifdef _USE_SUN_NSSWITCH_
903 # include <nsswitch.h>
904 #endif /* _USE_SUN_NSSWITCH_ */
906 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
907 # define _USE_DEC_SVC_CONF_
908 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
910 #ifdef _USE_DEC_SVC_CONF_
911 # include <sys/svcinfo.h>
912 #endif /* _USE_DEC_SVC_CONF_ */
915 switch_map_find(service, maptype, mapreturn)
917 char *maptype[MAXMAPSTACK];
918 short mapreturn[MAXMAPACTIONS];
921 int save_errno = errno;
923 #ifdef _USE_SUN_NSSWITCH_
924 struct __nsw_switchconfig *nsw_conf;
925 enum __nsw_parse_err pserr;
926 struct __nsw_lookup *lk;
927 static struct __nsw_lookup lkp0 =
928 { "files", {1, 0, 0, 0}, NULL, NULL };
929 static struct __nsw_switchconfig lkp_default =
930 { 0, "sendmail", 3, &lkp0 };
932 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
933 mapreturn[svcno] = 0;
935 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
936 lk = lkp_default.lookups;
938 lk = nsw_conf->lookups;
940 while (lk != NULL && svcno < MAXMAPSTACK)
942 maptype[svcno] = lk->service_name;
943 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
944 mapreturn[MA_NOTFOUND] |= 1 << svcno;
945 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
946 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
947 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
948 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
954 #endif /* _USE_SUN_NSSWITCH_ */
956 #ifdef _USE_DEC_SVC_CONF_
957 struct svcinfo *svcinfo;
960 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
961 mapreturn[svcno] = 0;
966 if (strcmp(service, "hosts") == 0)
968 else if (strcmp(service, "aliases") == 0)
970 else if (strcmp(service, "passwd") == 0)
977 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
979 switch (svcinfo->svcpath[svc][svcno])
982 maptype[svcno] = "files";
986 maptype[svcno] = "nis";
990 maptype[svcno] = "dns";
995 maptype[svcno] = "hesiod";
997 # endif /* SVC_HESIOD */
1006 #endif /* _USE_DEC_SVC_CONF_ */
1008 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
1010 ** Fall-back mechanism.
1014 static time_t servicecachetime; /* time service switch was cached */
1015 time_t now = curtime();
1017 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1018 mapreturn[svcno] = 0;
1020 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
1022 /* (re)read service switch */
1023 register SM_FILE_T *fp;
1024 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
1026 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
1031 servicecachetime = now;
1032 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
1037 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
1038 sizeof buf) != NULL)
1042 p = strpbrk(buf, "#\n");
1045 p = strpbrk(buf, " \t");
1052 sm_syslog(LOG_ERR, NOQID,
1053 "Bad line on %.100s: %.100s",
1064 ** Find/allocate space for this service entry.
1065 ** Space for all of the service strings
1066 ** are allocated at once. This means
1067 ** that we only have to free the first
1068 ** one to free all of them.
1071 st = stab(buf, ST_SERVICE, ST_ENTER);
1072 if (st->s_service[0] != NULL)
1073 sm_free((void *) st->s_service[0]); /* XXX */
1075 for (svcno = 0; svcno < MAXMAPSTACK; )
1079 st->s_service[svcno++] = p;
1080 p = strpbrk(p, " \t");
1087 if (svcno < MAXMAPSTACK)
1088 st->s_service[svcno] = NULL;
1090 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1094 /* look up entry in cache */
1095 st = stab(service, ST_SERVICE, ST_FIND);
1096 if (st != NULL && st->s_service[0] != NULL)
1100 while (svcno < MAXMAPSTACK)
1102 maptype[svcno] = st->s_service[svcno];
1103 if (maptype[svcno++] == NULL)
1109 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1111 #if !defined(_USE_SUN_NSSWITCH_)
1112 /* if the service file doesn't work, use an absolute fallback */
1113 # ifdef _USE_DEC_SVC_CONF_
1115 # endif /* _USE_DEC_SVC_CONF_ */
1116 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1117 mapreturn[svcno] = 0;
1119 if (strcmp(service, "aliases") == 0)
1121 maptype[svcno++] = "files";
1122 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1123 maptype[svcno++] = "netinfo";
1124 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
1125 # ifdef AUTO_NIS_ALIASES
1127 maptype[svcno++] = "nisplus";
1128 # endif /* NISPLUS */
1130 maptype[svcno++] = "nis";
1132 # endif /* AUTO_NIS_ALIASES */
1136 if (strcmp(service, "hosts") == 0)
1139 maptype[svcno++] = "dns";
1140 # else /* NAMED_BIND */
1141 # if defined(sun) && !defined(BSD)
1143 maptype[svcno++] = "nis";
1144 # endif /* defined(sun) && !defined(BSD) */
1145 # endif /* NAMED_BIND */
1146 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1147 maptype[svcno++] = "netinfo";
1148 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
1149 maptype[svcno++] = "files";
1155 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1158 ** USERNAME -- return the user id of the logged in user.
1164 ** The login name of the logged in user.
1170 ** The return value is statically allocated.
1176 static char *myname = NULL;
1177 extern char *getlogin();
1178 register struct passwd *pw;
1180 /* cache the result */
1183 myname = getlogin();
1184 if (myname == NULL || myname[0] == '\0')
1186 pw = sm_getpwuid(RealUid);
1188 myname = pw->pw_name;
1192 uid_t uid = RealUid;
1194 if ((pw = sm_getpwnam(myname)) == NULL ||
1195 (uid != 0 && uid != pw->pw_uid))
1197 pw = sm_getpwuid(uid);
1199 myname = pw->pw_name;
1202 if (myname == NULL || myname[0] == '\0')
1204 syserr("554 5.3.0 Who are you?");
1205 myname = "postmaster";
1207 else if (strpbrk(myname, ",;:/|\"\\") != NULL)
1208 myname = addquotes(myname, NULL);
1210 myname = sm_pstrdup_x(myname);
1215 ** TTYPATH -- Get the path of the user's tty
1217 ** Returns the pathname of the user's tty. Returns NULL if
1218 ** the user is not logged in or if s/he has write permission
1225 ** pathname of the user's tty.
1226 ** NULL if not logged in or write permission denied.
1232 ** Return value is in a local buffer.
1242 register char *pathn;
1243 extern char *ttyname();
1244 extern char *getlogin();
1246 /* compute the pathname of the controlling tty */
1247 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
1248 (pathn = ttyname(0)) == NULL)
1254 /* see if we have write permission */
1255 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
1261 /* see if the user is logged in */
1262 if (getlogin() == NULL)
1269 ** CHECKCOMPAT -- check for From and To person compatible.
1271 ** This routine can be supplied on a per-installation basis
1272 ** to determine whether a person is allowed to send a message.
1273 ** This allows restriction of certain types of internet
1274 ** forwarding or registration of users.
1276 ** If the hosts are found to be incompatible, an error
1277 ** message should be given using "usrerr" and an EX_ code
1278 ** should be returned. You can also set to->q_status to
1279 ** a DSN-style status code.
1281 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1282 ** body during the return-to-sender function; this should be done
1283 ** on huge messages. This bit may already be set by the ESMTP
1287 ** to -- the person being sent to.
1293 ** none (unless you include the usrerr stuff)
1298 register ADDRESS *to;
1299 register ENVELOPE *e;
1302 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1303 to->q_paddr, e->e_from.q_paddr);
1306 /* this code is intended as an example only */
1309 s = stab("arpa", ST_MAILER, ST_FIND);
1310 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
1311 to->q_mailer == s->s_mailer)
1313 usrerr("553 No ARPA mail through this machine: see your system administration");
1314 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1315 to->q_status = "5.7.1";
1316 return EX_UNAVAILABLE;
1318 #endif /* EXAMPLE_CODE */
1322 ** INIT_MD -- do machine dependent initializations
1324 ** Systems that have global modes that should be set should do
1325 ** them here rather than in main.
1329 # include <compat.h>
1330 #endif /* _AUX_SOURCE */
1333 # include <shares.h>
1334 #endif /* SHARE_V1 */
1342 setcompat(getcompat() | COMPAT_BSDPROT);
1343 #endif /* _AUX_SOURCE */
1345 #ifdef SUN_EXTENSIONS
1347 #endif /* SUN_EXTENSIONS */
1350 /* keep gethostby*() from stripping the local domain name */
1351 set_domain_trim_off();
1352 #endif /* _CONVEX_SOURCE */
1355 ** Due to QNX's network distributed nature, you can target a tcpip
1356 ** stack on a different node in the qnx network; this patch lets
1357 ** this feature work. The __sock_locate() must be done before the
1358 ** environment is clear.
1361 #endif /* __QNX__ */
1362 #if SECUREWARE || defined(_SCO_unix_)
1363 set_auth_parameters(argc, argv);
1367 ** This is required for highest security levels (the kernel
1368 ** won't let it call set*uid() or run setuid binaries without
1369 ** it). It may be necessary on other SECUREWARE systems.
1372 if (getluid() == -1)
1374 # endif /* _SCO_unix_ */
1375 #endif /* SECUREWARE || defined(_SCO_unix_) */
1378 #ifdef VENDOR_DEFAULT
1379 VendorCode = VENDOR_DEFAULT;
1380 #else /* VENDOR_DEFAULT */
1381 VendorCode = VENDOR_BERKELEY;
1382 #endif /* VENDOR_DEFAULT */
1385 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1387 ** Called once, on startup.
1390 ** e -- the global envelope.
1396 ** vendor-dependent.
1400 init_vendor_macros(e)
1401 register ENVELOPE *e;
1405 ** GETLA -- get the current load average
1407 ** This code stolen from la.c.
1413 ** The current load average as an integer.
1419 /* try to guess what style of load average we have */
1420 #define LA_ZERO 1 /* always return load average as zero */
1421 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1422 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1423 #define LA_SUBR 4 /* call getloadavg */
1424 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1425 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1426 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1427 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1428 #define LA_DGUX 9 /* special DGUX implementation */
1429 #define LA_HPUX 10 /* special HPUX implementation */
1430 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1431 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1432 #define LA_DEVSHORT 13 /* read short from a device */
1433 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1434 #define LA_PSET 15 /* Solaris per-processor-set load average */
1435 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1437 /* do guesses based on general OS type */
1439 # define LA_TYPE LA_ZERO
1440 #endif /* ! LA_TYPE */
1443 # if defined(unixpc)
1445 # endif /* defined(unixpc) */
1447 # if defined(__alpha) || defined(IRIX)
1449 # endif /* defined(__alpha) || defined(IRIX) */
1451 #endif /* ! FSHIFT */
1455 #endif /* ! FSHIFT */
1458 # define FSCALE (1 << FSHIFT)
1459 #endif /* ! FSCALE */
1463 # define LA_AVENRUN "avenrun"
1464 # else /* SYSTEM5 */
1465 # define LA_AVENRUN "_avenrun"
1466 # endif /* SYSTEM5 */
1467 #endif /* ! LA_AVENRUN */
1469 /* _PATH_KMEM should be defined in <paths.h> */
1471 # define _PATH_KMEM "/dev/kmem"
1472 #endif /* ! _PATH_KMEM */
1474 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1478 /* _PATH_UNIX should be defined in <paths.h> */
1480 # if defined(SYSTEM5)
1481 # define _PATH_UNIX "/unix"
1482 # else /* defined(SYSTEM5) */
1483 # define _PATH_UNIX "/vmunix"
1484 # endif /* defined(SYSTEM5) */
1485 # endif /* ! _PATH_UNIX */
1489 # else /* _AUX_SOURCE */
1495 # endif /* _AUX_SOURCE */
1496 # define X_AVENRUN 0
1502 static int kmem = -1;
1503 # if LA_TYPE == LA_INT
1505 # else /* LA_TYPE == LA_INT */
1506 # if LA_TYPE == LA_SHORT
1509 # if LA_TYPE == LA_LONGLONG
1510 long long avenrun[3];
1511 # else /* LA_TYPE == LA_LONGLONG */
1513 # endif /* LA_TYPE == LA_LONGLONG */
1514 # endif /* LA_TYPE == LA_SHORT */
1515 # endif /* LA_TYPE == LA_INT */
1516 extern off_t lseek();
1521 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
1522 sizeof Nl[X_AVENRUN].n_name);
1523 Nl[1].n_name[0] = '\0';
1524 # endif /* _AUX_SOURCE */
1526 # if defined(_AIX3) || defined(_AIX4)
1527 if (knlist(Nl, 1, sizeof Nl[0]) < 0)
1528 # else /* defined(_AIX3) || defined(_AIX4) */
1529 if (nlist(_PATH_UNIX, Nl) < 0)
1530 # endif /* defined(_AIX3) || defined(_AIX4) */
1533 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
1534 sm_errstring(errno));
1537 if (Nl[X_AVENRUN].n_value == 0)
1540 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1541 _PATH_UNIX, LA_AVENRUN);
1544 # ifdef NAMELISTMASK
1545 Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1546 # endif /* NAMELISTMASK */
1548 kmem = open(_PATH_KMEM, 0, 0);
1552 sm_dprintf("getla: open(/dev/kmem): %s\n",
1553 sm_errstring(errno));
1556 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1557 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1560 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1561 sm_errstring(errno));
1568 sm_dprintf("getla: symbol address = %#lx\n",
1569 (unsigned long) Nl[X_AVENRUN].n_value);
1570 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1571 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1575 sm_dprintf("getla: lseek or read: %s\n",
1576 sm_errstring(errno));
1579 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1582 # if LA_TYPE == LA_SHORT
1583 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1585 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1586 # else /* LA_TYPE == LA_SHORT */
1587 # if LA_TYPE == LA_LONGLONG
1588 sm_dprintf("getla: avenrun = %lld", avenrun[0]);
1590 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
1591 # else /* LA_TYPE == LA_LONGLONG */
1592 sm_dprintf("getla: avenrun = %ld", avenrun[0]);
1594 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
1595 # endif /* LA_TYPE == LA_LONGLONG */
1596 # endif /* LA_TYPE == LA_SHORT */
1600 sm_dprintf("getla: %d\n",
1601 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1602 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1603 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1606 sm_dprintf("getla: avenrun = %g", avenrun[0]);
1608 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
1612 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1613 return ((int) (avenrun[0] + 0.5));
1614 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1617 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1619 #if LA_TYPE == LA_READKSYM
1621 # include <sys/ksym.h>
1627 static int kmem = -1;
1629 struct mioc_rksym mirk;
1633 kmem = open("/dev/kmem", 0, 0);
1637 sm_dprintf("getla: open(/dev/kmem): %s\n",
1638 sm_errstring(errno));
1641 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1642 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1645 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1646 sm_errstring(errno));
1652 mirk.mirk_symname = LA_AVENRUN;
1653 mirk.mirk_buf = avenrun;
1654 mirk.mirk_buflen = sizeof(avenrun);
1655 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
1658 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1659 sm_errstring(errno));
1664 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1666 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1670 sm_dprintf("getla: %d\n",
1671 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1672 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1675 #endif /* LA_TYPE == LA_READKSYM */
1677 #if LA_TYPE == LA_DGUX
1679 # include <sys/dg_sys_info.h>
1684 struct dg_sys_info_load_info load_info;
1686 dg_sys_info((long *)&load_info,
1687 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1690 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1692 return ((int) (load_info.one_minute + 0.5));
1695 #endif /* LA_TYPE == LA_DGUX */
1697 #if LA_TYPE == LA_HPUX
1699 /* forward declarations to keep gcc from complaining */
1704 struct pst_diskinfo;
1705 struct pst_processor;
1707 struct pst_swapinfo;
1709 # include <sys/param.h>
1710 # include <sys/pstat.h>
1715 struct pst_dynamic pstd;
1717 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1718 (size_t) 1, 0) == -1)
1722 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1724 return (int) (pstd.psd_avg_1_min + 0.5);
1727 #endif /* LA_TYPE == LA_HPUX */
1729 #if LA_TYPE == LA_SUBR
1736 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1739 sm_dprintf("getla: getloadavg failed: %s",
1740 sm_errstring(errno));
1744 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1745 return ((int) (avenrun[0] + 0.5));
1748 #endif /* LA_TYPE == LA_SUBR */
1750 #if LA_TYPE == LA_MACH
1753 ** This has been tested on NEXTSTEP release 2.1/3.X.
1756 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1757 # include <mach/mach.h>
1758 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1760 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1765 processor_set_t default_set;
1766 kern_return_t error;
1767 unsigned int info_count;
1768 struct processor_set_basic_info info;
1771 error = processor_set_default(host_self(), &default_set);
1772 if (error != KERN_SUCCESS)
1775 sm_dprintf("getla: processor_set_default failed: %s",
1776 sm_errstring(errno));
1779 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1780 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1781 &host, (processor_set_info_t)&info,
1782 &info_count) != KERN_SUCCESS)
1785 sm_dprintf("getla: processor_set_info failed: %s",
1786 sm_errstring(errno));
1790 sm_dprintf("getla: %d\n",
1791 (int) ((info.load_average + (LOAD_SCALE / 2)) /
1793 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1796 #endif /* LA_TYPE == LA_MACH */
1798 #if LA_TYPE == LA_PROCSTR
1799 # if SM_CONF_BROKEN_STRTOD
1800 ERROR: This OS has most likely a broken strtod() implemenentation.
1801 ERROR: The function is required for getla().
1802 ERROR: Check the compilation options _LA_PROCSTR and
1803 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
1804 # endif /* SM_CONF_BROKEN_STRTOD */
1807 ** Read /proc/loadavg for the load average. This is assumed to be
1808 ** in a format like "0.15 0.12 0.06".
1810 ** Initially intended for Linux. This has been in the kernel
1811 ** since at least 0.99.15.
1814 # ifndef _PATH_LOADAVG
1815 # define _PATH_LOADAVG "/proc/loadavg"
1816 # endif /* ! _PATH_LOADAVG */
1822 register int result;
1825 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
1830 sm_dprintf("getla: sm_io_open(%s): %s\n",
1831 _PATH_LOADAVG, sm_errstring(errno));
1834 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
1835 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1839 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1840 result, sm_errstring(errno));
1845 sm_dprintf("getla(): %.2f\n", avenrun);
1847 return ((int) (avenrun + 0.5));
1850 #endif /* LA_TYPE == LA_PROCSTR */
1852 #if LA_TYPE == LA_IRIX6
1854 # include <sys/sysmp.h>
1857 # define CAST_SYSMP(x) (x)
1858 # else /* _UNICOSMP */
1859 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1860 # endif /* _UNICOSMP */
1866 static int kmem = -1;
1871 kmem = open(_PATH_KMEM, 0, 0);
1875 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
1876 sm_errstring(errno));
1879 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1880 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1883 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1884 sm_errstring(errno));
1891 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
1893 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1896 sm_dprintf("getla: lseek or read: %s\n",
1897 sm_errstring(errno));
1902 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
1904 sm_dprintf(", %ld, %ld",
1905 (long int) avenrun[1], (long int) avenrun[2]);
1910 sm_dprintf("getla: %d\n",
1911 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1912 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1915 #endif /* LA_TYPE == LA_IRIX6 */
1917 #if LA_TYPE == LA_KSTAT
1924 static kstat_ctl_t *kc = NULL;
1925 static kstat_t *ksp = NULL;
1929 if (kc == NULL) /* if not initialized before */
1934 sm_dprintf("getla: kstat_open(): %s\n",
1935 sm_errstring(errno));
1939 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
1943 sm_dprintf("getla: kstat_lookup(): %s\n",
1944 sm_errstring(errno));
1947 if (kstat_read(kc, ksp, NULL) < 0)
1950 sm_dprintf("getla: kstat_read(): %s\n",
1951 sm_errstring(errno));
1954 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
1955 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
1956 /* kstat_close(kc); /o do not close for fast access */
1960 #endif /* LA_TYPE == LA_KSTAT */
1962 #if LA_TYPE == LA_DEVSHORT
1965 ** Read /dev/table/avenrun for the load average. This should contain
1966 ** three shorts for the 1, 5, and 15 minute loads. We only read the
1967 ** first, since that's all we care about.
1969 ** Intended for SCO OpenServer 5.
1972 # ifndef _PATH_AVENRUN
1973 # define _PATH_AVENRUN "/dev/table/avenrun"
1974 # endif /* ! _PATH_AVENRUN */
1979 static int afd = -1;
1986 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
1990 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
1993 sm_syslog(LOG_ERR, NOQID,
1994 "can't open %s: %s",
1995 _PATH_AVENRUN, sm_errstring(errno));
2000 r = read(afd, &avenrun, sizeof avenrun);
2003 sm_dprintf("getla: avenrun = %d\n", avenrun);
2004 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
2006 sm_dprintf("getla: %d\n", loadav);
2010 #endif /* LA_TYPE == LA_DEVSHORT */
2012 #if LA_TYPE == LA_ALPHAOSF
2015 # include <sys/table.h>
2021 struct tbl_loadavg tab;
2023 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
2026 sm_dprintf("getla: table %s\n", sm_errstring(errno));
2031 sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
2034 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
2037 ave = (int) (tab.tl_avenrun.d[2] + 0.5);
2040 sm_dprintf("getla: %d\n", ave);
2045 #endif /* LA_TYPE == LA_ALPHAOSF */
2047 #if LA_TYPE == LA_PSET
2054 if (pset_getloadavg(PS_MYID, avenrun,
2055 sizeof(avenrun) / sizeof(avenrun[0])) < 0)
2058 sm_dprintf("getla: pset_getloadavg failed: %s",
2059 sm_errstring(errno));
2063 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
2064 return ((int) (avenrun[0] + 0.5));
2067 #endif /* LA_TYPE == LA_PSET */
2069 #if LA_TYPE == LA_ZERO
2075 sm_dprintf("getla: ZERO\n");
2079 #endif /* LA_TYPE == LA_ZERO */
2082 * Copyright 1989 Massachusetts Institute of Technology
2084 * Permission to use, copy, modify, distribute, and sell this software and its
2085 * documentation for any purpose is hereby granted without fee, provided that
2086 * the above copyright notice appear in all copies and that both that
2087 * copyright notice and this permission notice appear in supporting
2088 * documentation, and that the name of M.I.T. not be used in advertising or
2089 * publicity pertaining to distribution of the software without specific,
2090 * written prior permission. M.I.T. makes no representations about the
2091 * suitability of this software for any purpose. It is provided "as is"
2092 * without express or implied warranty.
2094 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2095 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2096 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2097 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2098 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2099 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2101 * Authors: Many and varied...
2104 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2106 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2111 # include <apollo/base.h>
2114 int getloadavg( call_data )
2115 caddr_t call_data; /* pointer to (double) return value */
2117 double *avenrun = (double *) call_data;
2122 proc1_$get_loadav(loadav, &st);
2123 *avenrun = loadav[0] / (double) (1 << 16);
2128 ** SM_GETLA -- get the current load average
2137 ** Set CurrentLA to the current load average.
2138 ** Set {load_avg} in GlobalMacros to the current load average.
2146 CurrentLA = getla();
2147 (void) sm_snprintf(labuf, sizeof labuf, "%d", CurrentLA);
2148 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
2151 ** SHOULDQUEUE -- should this message be queued or sent?
2153 ** Compares the message cost to the load average to decide.
2155 ** Note: Do NOT change this API! It is documented in op.me
2156 ** and theoretically the user can change this function...
2159 ** pri -- the priority of the message in question.
2160 ** ct -- the message creation time (unused, but see above).
2163 ** true -- if this message should be queued up for the
2165 ** false -- if the load is low enough to send this message.
2173 shouldqueue(pri, ct)
2180 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2182 if (CurrentLA < QueueLA)
2185 sm_dprintf("false (CurrentLA < QueueLA)\n");
2188 # if 0 /* this code is reported to cause oscillation around RefuseLA */
2189 if (CurrentLA >= RefuseLA && QueueLA < RefuseLA)
2192 sm_dprintf("TRUE (CurrentLA >= RefuseLA)\n");
2196 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
2198 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
2202 ** REFUSECONNECTIONS -- decide if connections should be refused
2205 ** name -- daemon name (for error messages only)
2206 ** e -- the current envelope.
2207 ** d -- number of daemon
2208 ** active -- was this daemon actually active?
2211 ** true if incoming SMTP connections should be refused
2213 ** false if we should accept new work.
2216 ** Sets process title when it is rejecting connections.
2220 refuseconnections(name, e, d, active)
2226 static time_t lastconn[MAXDAEMONS];
2227 static int conncnt[MAXDAEMONS];
2228 static time_t firstrejtime[MAXDAEMONS];
2229 static time_t nextlogtime[MAXDAEMONS];
2237 SM_ASSERT(d < MAXDAEMONS);
2238 if (ConnRateThrottle > 0)
2245 if (now != lastconn[d])
2250 else if (conncnt[d]++ > ConnRateThrottle)
2252 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2253 /* sleep to flatten out connection load */
2254 sm_setproctitle(true, e, D_MSG_CRT,
2255 name, ConnRateThrottle);
2257 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
2258 name, ConnRateThrottle);
2262 else if (now != lastconn[d])
2267 if (RefuseLA > 0 && CurrentLA >= RefuseLA)
2271 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2272 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2273 sm_setproctitle(true, e, R_MSG_LA, name, CurrentLA);
2275 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA, name, CurrentLA);
2277 if (firstrejtime[d] == 0)
2279 firstrejtime[d] = now;
2280 nextlogtime[d] = now + RejectLogInterval;
2282 else if (nextlogtime[d] < now)
2284 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, name,
2285 pintvl(now - firstrejtime[d], true));
2286 nextlogtime[d] = now + RejectLogInterval;
2291 firstrejtime[d] = 0;
2293 if (DelayLA > 0 && CurrentLA >= DelayLA)
2296 static time_t log_delay = (time_t) 0;
2298 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2299 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2300 /* sleep to flatten out connection load */
2301 sm_setproctitle(true, e, D_MSG_LA, name, DelayLA);
2302 if (LogLevel > 8 && (now = curtime()) > log_delay)
2304 sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
2305 name, CurrentLA, DelayLA);
2306 log_delay = now + MIN_DELAY_LOG;
2311 if (MaxChildren > 0 && CurChildren >= MaxChildren)
2314 if (CurChildren >= MaxChildren)
2316 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2317 sm_setproctitle(true, e, R_MSG_CHILD,
2318 name, CurChildren, MaxChildren);
2320 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
2321 name, CurChildren, MaxChildren);
2328 ** SETPROCTITLE -- set process title for ps
2331 ** fmt -- a printf style format string.
2332 ** a, b, c -- possible parameters to fmt.
2338 ** Clobbers argv of our main procedure so ps(1) will
2339 ** display the title.
2342 #define SPT_NONE 0 /* don't use it at all */
2343 #define SPT_REUSEARGV 1 /* cover argv with title information */
2344 #define SPT_BUILTIN 2 /* use libc builtin */
2345 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2346 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2347 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2348 #define SPT_SCO 6 /* write kernel u. area */
2349 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2352 # define SPT_TYPE SPT_REUSEARGV
2353 #endif /* ! SPT_TYPE */
2356 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2358 # if SPT_TYPE == SPT_PSTAT
2359 # include <sys/pstat.h>
2360 # endif /* SPT_TYPE == SPT_PSTAT */
2361 # if SPT_TYPE == SPT_PSSTRINGS
2362 # include <machine/vmparam.h>
2363 # include <sys/exec.h>
2364 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2366 # define SPT_TYPE SPT_REUSEARGV
2367 # else /* ! PS_STRINGS */
2368 # ifndef NKPDE /* FreeBSD 2.0 */
2370 typedef unsigned int *pt_entry_t;
2371 # endif /* ! NKPDE */
2372 # endif /* ! PS_STRINGS */
2373 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2375 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2376 # define SETPROC_STATIC static
2377 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2378 # define SETPROC_STATIC
2379 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2381 # if SPT_TYPE == SPT_SYSMIPS
2382 # include <sys/sysmips.h>
2383 # include <sys/sysnews.h>
2384 # endif /* SPT_TYPE == SPT_SYSMIPS */
2386 # if SPT_TYPE == SPT_SCO
2387 # include <sys/immu.h>
2388 # include <sys/dir.h>
2389 # include <sys/user.h>
2390 # include <sys/fs/s5param.h>
2391 # if PSARGSZ > MAXLINE
2392 # define SPT_BUFSIZE PSARGSZ
2393 # endif /* PSARGSZ > MAXLINE */
2394 # endif /* SPT_TYPE == SPT_SCO */
2396 # ifndef SPT_PADCHAR
2397 # define SPT_PADCHAR ' '
2398 # endif /* ! SPT_PADCHAR */
2400 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2403 # define SPT_BUFSIZE MAXLINE
2404 #endif /* ! SPT_BUFSIZE */
2409 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2410 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2411 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2412 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2413 ** you use this FFR.
2416 # ifdef SPT_ALIGN_SIZE
2417 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2418 # else /* SPT_ALIGN_SIZE */
2419 # define SPT_ALIGN(x, align) (x)
2420 # endif /* SPT_ALIGN_SIZE */
2421 #else /* _FFR_SPT_ALIGN */
2422 # define SPT_ALIGN(x, align) (x)
2423 #endif /* _FFR_SPT_ALIGN */
2426 ** Pointers for setproctitle.
2427 ** This allows "ps" listings to give more useful information.
2430 static char **Argv = NULL; /* pointer to argument vector */
2431 static char *LastArgv = NULL; /* end of argv */
2432 #if SPT_TYPE != SPT_BUILTIN
2433 static void setproctitle __P((const char *, ...));
2434 #endif /* SPT_TYPE != SPT_BUILTIN */
2437 initsetproctitle(argc, argv, envp)
2444 extern char **environ;
2447 ** Move the environment so setproctitle can use the space at
2448 ** the top of memory.
2453 for (i = 0; envp[i] != NULL; i++)
2455 environ = (char **) xalloc(sizeof (char *) * (i + 1));
2456 for (i = 0; envp[i] != NULL; i++)
2457 environ[i] = newstr(envp[i]);
2462 ** Save start and extent of argv for setproctitle.
2468 ** Determine how much space we can use for setproctitle.
2469 ** Use all contiguous argv and envp pointers starting at argv[0]
2474 # ifdef SPT_ALIGN_SIZE
2475 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
2477 # endif /* SPT_ALIGN_SIZE */
2478 # endif /* _FFR_SPT_ALIGN */
2480 for (i = 0; i < argc; i++)
2482 if (i == 0 || LastArgv + 1 == argv[i])
2483 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
2485 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
2487 if (LastArgv + 1 == envp[i])
2488 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
2492 #if SPT_TYPE != SPT_BUILTIN
2497 setproctitle(const char *fmt, ...)
2498 # else /* __STDC__ */
2499 setproctitle(fmt, va_alist)
2502 # endif /* __STDC__ */
2504 # if SPT_TYPE != SPT_NONE
2507 SETPROC_STATIC char buf[SPT_BUFSIZE];
2509 # if SPT_TYPE == SPT_PSTAT
2511 # endif /* SPT_TYPE == SPT_PSTAT */
2512 # if SPT_TYPE == SPT_SCO
2515 static int kmem = -1;
2516 static pid_t kmempid = -1;
2518 # endif /* SPT_TYPE == SPT_SCO */
2522 /* print sendmail: heading for grep */
2523 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
2526 /* print the argument string */
2527 SM_VA_START(ap, fmt);
2528 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
2531 i = (int) strlen(buf);
2535 # if SPT_TYPE == SPT_PSTAT
2536 pst.pst_command = buf;
2537 pstat(PSTAT_SETCMD, pst, i, 0, 0);
2538 # endif /* SPT_TYPE == SPT_PSTAT */
2539 # if SPT_TYPE == SPT_PSSTRINGS
2540 PS_STRINGS->ps_nargvstr = 1;
2541 PS_STRINGS->ps_argvstr = buf;
2542 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2543 # if SPT_TYPE == SPT_SYSMIPS
2544 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
2545 # endif /* SPT_TYPE == SPT_SYSMIPS */
2546 # if SPT_TYPE == SPT_SCO
2547 if (kmem < 0 || kmempid != CurrentPid)
2551 kmem = open(_PATH_KMEM, O_RDWR, 0);
2554 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
2555 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
2561 kmempid = CurrentPid;
2563 buf[PSARGSZ - 1] = '\0';
2564 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
2565 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
2566 (void) write(kmem, buf, PSARGSZ);
2567 # endif /* SPT_TYPE == SPT_SCO */
2568 # if SPT_TYPE == SPT_REUSEARGV
2569 if (LastArgv == NULL)
2572 if (i > LastArgv - Argv[0] - 2)
2574 i = LastArgv - Argv[0] - 2;
2577 (void) sm_strlcpy(Argv[0], buf, i + 1);
2579 while (p < LastArgv)
2582 # endif /* SPT_TYPE == SPT_REUSEARGV */
2583 # if SPT_TYPE == SPT_CHANGEARGV
2586 # endif /* SPT_TYPE == SPT_CHANGEARGV */
2587 # endif /* SPT_TYPE != SPT_NONE */
2590 #endif /* SPT_TYPE != SPT_BUILTIN */
2592 ** SM_SETPROCTITLE -- set process task and set process title for ps
2594 ** Possibly set process status and call setproctitle() to
2595 ** change the ps display.
2598 ** status -- whether or not to store as process status
2599 ** e -- the current envelope.
2600 ** fmt -- a printf style format string.
2601 ** a, b, c -- possible parameters to fmt.
2610 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
2611 #else /* __STDC__ */
2612 sm_setproctitle(status, e, fmt, va_alist)
2617 #endif /* __STDC__ */
2619 char buf[SPT_BUFSIZE];
2622 /* print the argument string */
2623 SM_VA_START(ap, fmt);
2624 (void) sm_vsnprintf(buf, sizeof buf, fmt, ap);
2628 proc_list_set(CurrentPid, buf);
2630 if (ProcTitlePrefix != NULL)
2632 char prefix[SPT_BUFSIZE];
2634 expand(ProcTitlePrefix, prefix, sizeof prefix, e);
2635 setproctitle("%s: %s", prefix, buf);
2638 setproctitle("%s", buf);
2641 ** WAITFOR -- wait for a particular process id.
2644 ** pid -- process id to wait for.
2648 ** -1 if pid never shows up.
2666 proc_list_drop(i, st, NULL);
2667 } while ((i >= 0 || errno == EINTR) && i != pid);
2676 ** status -- pointer to status (return value)
2688 # else /* WAITUNION */
2690 # endif /* WAITUNION */
2692 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2694 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2696 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2697 savesig = sm_releasesignal(SIGCHLD);
2698 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2700 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2702 sm_blocksignal(SIGCHLD);
2703 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2705 *status = st.w_status;
2706 # else /* WAITUNION */
2708 # endif /* WAITUNION */
2712 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2715 ** sig -- the signal that got us here (unused).
2721 ** Picks up extant zombies.
2722 ** Control socket exits may restart/shutdown daemon.
2724 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2725 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2734 int save_errno = errno;
2742 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
2747 # else /* HASWAITPID */
2751 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
2753 st = status.w_status;
2754 # else /* WNOHANG */
2758 ** Catch one zombie -- we will be re-invoked (we hope) if there
2759 ** are more. Unreliable signals probably break this, but this
2760 ** is the "old system" situation -- waitpid or wait3 are to be
2761 ** strongly preferred.
2764 if ((pid = wait(&status)) > 0)
2767 # endif /* WNOHANG */
2768 # endif /* HASWAITPID */
2769 /* Drop PID and check if it was a control socket child */
2770 proc_list_drop(pid, st, NULL);
2772 FIX_SYSV_SIGNAL(sig, reapchild);
2774 return SIGFUNC_RETURN;
2777 ** GETDTABLESIZE -- return number of file descriptors
2779 ** Only on non-BSD systems
2785 ** size of file descriptor table
2792 # include <sys/resource.h>
2793 #endif /* SOLARIS */
2798 # ifdef RLIMIT_NOFILE
2801 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
2803 # endif /* RLIMIT_NOFILE */
2805 # if HASGETDTABLESIZE
2806 return getdtablesize();
2807 # else /* HASGETDTABLESIZE */
2808 # ifdef _SC_OPEN_MAX
2809 return sysconf(_SC_OPEN_MAX);
2810 # else /* _SC_OPEN_MAX */
2812 # endif /* _SC_OPEN_MAX */
2813 # endif /* HASGETDTABLESIZE */
2816 ** UNAME -- get the UUCP name of this system.
2823 struct utsname *name;
2828 name->nodename[0] = '\0';
2830 /* try /etc/whoami -- one line with the node name */
2831 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
2832 SM_IO_RDONLY, NULL)) != NULL)
2834 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
2836 (void) sm_io_close(file, SM_TIME_DEFAULT);
2837 n = strchr(name->nodename, '\n');
2840 if (name->nodename[0] != '\0')
2844 /* try /usr/include/whoami.h -- has a #define somewhere */
2845 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
2846 "/usr/include/whoami.h", SM_IO_RDONLY, NULL))
2851 while (sm_io_fgets(file, SM_TIME_DEFAULT,
2852 buf, sizeof buf) != NULL)
2854 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
2855 NODE_LENGTH, name->nodename) > 0)
2858 (void) sm_io_close(file, SM_TIME_DEFAULT);
2859 if (name->nodename[0] != '\0')
2865 #endif /* !HASUNAME */
2867 ** INITGROUPS -- initialize groups
2869 ** Stub implementation for System V style systems
2874 initgroups(name, basegid)
2881 #endif /* !HASINITGROUPS */
2883 ** SETGROUPS -- set group list
2885 ** Stub implementation for systems that don't have group lists
2891 setgroups(ngroups, grouplist)
2893 GIDSET_T grouplist[];
2898 #endif /* ! NGROUPS_MAX */
2900 ** SETSID -- set session id (for non-POSIX systems)
2911 fd = open("/dev/tty", O_RDWR, 0);
2914 (void) ioctl(fd, TIOCNOTTY, (char *) 0);
2917 # endif /* TIOCNOTTY */
2920 # else /* SYS5SETPGRP */
2921 return setpgid(0, CurrentPid);
2922 # endif /* SYS5SETPGRP */
2925 #endif /* !HASSETSID */
2927 ** FSYNC -- dummy fsync
2936 return fcntl(fd, F_SETFL, O_SYNC);
2938 /* nothing we can do */
2940 # endif /* O_SYNC */
2943 #endif /* NEEDFSYNC */
2945 ** DGUX_INET_ADDR -- inet_addr for DG/UX
2947 ** Data General DG/UX version of inet_addr returns a struct in_addr
2948 ** instead of a long. This patches things. Only needed on versions
2957 dgux_inet_addr(host)
2960 struct in_addr haddr;
2962 haddr = inet_addr(host);
2963 return haddr.s_addr;
2966 #endif /* DGUX_5_4_2 */
2968 ** GETOPT -- for old systems or systems with bogus implementations
2974 * Copyright (c) 1985 Regents of the University of California.
2975 * All rights reserved. The Berkeley software License Agreement
2976 * specifies the terms and conditions for redistribution.
2981 ** this version hacked to add `atend' flag to allow state machine
2982 ** to reset if invoked by the program to scan args for a 2nd time
2985 # if defined(LIBC_SCCS) && !defined(lint)
2986 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
2987 # endif /* defined(LIBC_SCCS) && !defined(lint) */
2990 ** get option letter from argument vector
2992 # ifdef _CONVEX_SOURCE
2993 extern int optind, opterr, optopt;
2994 extern char *optarg;
2995 # else /* _CONVEX_SOURCE */
2996 int opterr = 1; /* if error message should be printed */
2997 int optind = 1; /* index into parent argv vector */
2998 int optopt = 0; /* character checked for validity */
2999 char *optarg = NULL; /* argument associated with option */
3000 # endif /* _CONVEX_SOURCE */
3002 # define BADCH (int)'?'
3004 # define tell(s) if (opterr) \
3005 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
3006 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
3007 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
3008 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
3012 getopt(nargc,nargv,ostr)
3017 static char *place = EMSG; /* option letter processing */
3018 static char atend = 0;
3019 register char *oli = NULL; /* option letter list index */
3025 if(!*place) { /* update scanning pointer */
3026 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
3030 if (*place == '-') { /* found "--" */
3035 } /* option letter okay? */
3036 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
3037 if (!*place) ++optind;
3038 tell(": illegal option -- ");
3040 if (oli && *++oli != ':') { /* don't need argument */
3042 if (!*place) ++optind;
3044 else { /* need an argument */
3045 if (*place) optarg = place; /* no white space */
3046 else if (nargc <= ++optind) { /* no arg */
3048 tell(": option requires an argument -- ");
3050 else optarg = nargv[optind]; /* white space */
3054 return optopt; /* dump back option letter */
3057 #endif /* !SM_CONF_GETOPT */
3059 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3062 ** user -- the name of the user we are checking.
3063 ** shell -- the user's shell from /etc/passwd
3066 ** true -- if it is ok to use this for unrestricted access.
3067 ** false -- if the shell is restricted.
3070 #if !HASGETUSERSHELL
3072 # ifndef _PATH_SHELLS
3073 # define _PATH_SHELLS "/etc/shells"
3074 # endif /* ! _PATH_SHELLS */
3076 # if defined(_AIX3) || defined(_AIX4)
3077 # include <userconf.h>
3079 # include <userpw.h>
3080 # endif /* _AIX4 >= 40200 */
3081 # include <usersec.h>
3082 # endif /* defined(_AIX3) || defined(_AIX4) */
3084 static char *DefaultUserShells[] =
3086 "/bin/sh", /* standard shell */
3091 "/bin/csh", /* C shell */
3096 "/usr/bin/rsh", /* restricted Bourne shell */
3097 "/usr/bin/ksh", /* Korn shell */
3098 "/usr/bin/rksh", /* restricted Korn shell */
3100 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3101 "/usr/bin/posix/sh",
3103 "/bin/rsh", /* restricted Bourne shell */
3104 "/bin/ksh", /* Korn shell */
3105 "/bin/rksh", /* restricted Korn shell */
3107 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3111 # endif /* __hpux */
3112 # if defined(_AIX3) || defined(_AIX4)
3113 "/bin/ksh", /* Korn shell */
3115 "/bin/tsh", /* trusted shell */
3117 "/bin/bsh", /* Bourne shell */
3119 # endif /* defined(_AIX3) || defined(_AIX4) */
3120 # if defined(__svr4__) || defined(__svr5__)
3121 "/bin/ksh", /* Korn shell */
3123 # endif /* defined(__svr4__) || defined(__svr5__) */
3125 "/sbin/sh", /* SGI's shells really live in /sbin */
3127 "/sbin/bsh", /* classic Bourne shell */
3130 "/sbin/csh", /* standard csh */
3133 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3136 "/bin/ksh", /* Korn shell */
3139 "/sbin/tcsh", /* Extended csh */
3146 #endif /* !HASGETUSERSHELL */
3148 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3151 usershellok(user, shell)
3155 # if HASGETUSERSHELL
3157 extern char *getusershell();
3159 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3164 while ((p = getusershell()) != NULL)
3165 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
3169 # else /* HASGETUSERSHELL */
3172 # endif /* USEGETCONFATTR */
3173 register SM_FILE_T *shellf;
3176 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3182 ** Naturally IBM has a "better" idea.....
3184 ** What a crock. This interface isn't documented, it is
3185 ** considered part of the security library (-ls), and it
3186 ** only works if you are running as root (since the list
3187 ** of valid shells is obviously a source of great concern).
3188 ** I recommend that you do NOT define USEGETCONFATTR,
3189 ** especially since you are going to have to set up an
3190 ** /etc/shells anyhow to handle the cases where getconfattr
3194 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
3198 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
3204 # endif /* USEGETCONFATTR */
3206 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
3207 SM_IO_RDONLY, NULL);
3210 /* no /etc/shells; see if it is one of the std shells */
3213 if (errno != ENOENT && LogLevel > 3)
3214 sm_syslog(LOG_ERR, NOQID,
3215 "usershellok: cannot open %s: %s",
3216 _PATH_SHELLS, sm_errstring(errno));
3218 for (d = DefaultUserShells; *d != NULL; d++)
3220 if (strcmp(shell, *d) == 0)
3226 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof buf) != NULL)
3228 register char *p, *q;
3231 while (*p != '\0' && *p != '#' && *p != '/')
3233 if (*p == '#' || *p == '\0')
3236 while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
3239 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
3241 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3245 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3247 # endif /* HASGETUSERSHELL */
3250 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3252 ** Only implemented if you have statfs.
3255 ** dir -- the directory in question.
3256 ** bsize -- a variable into which the filesystem
3257 ** block size is stored.
3260 ** The number of blocks free on the queue filesystem.
3261 ** -1 if the statfs call fails.
3264 ** Puts the filesystem block size into bsize.
3268 # define SFS_NONE 0 /* no statfs implementation */
3269 # define SFS_USTAT 1 /* use ustat */
3270 # define SFS_4ARGS 2 /* use four-argument statfs call */
3271 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3272 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3273 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3274 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3277 # define SFS_TYPE SFS_NONE
3278 # endif /* ! SFS_TYPE */
3280 # if SFS_TYPE == SFS_USTAT
3282 # endif /* SFS_TYPE == SFS_USTAT */
3283 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3284 # include <sys/statfs.h>
3285 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
3286 # if SFS_TYPE == SFS_VFS
3287 # include <sys/vfs.h>
3288 # endif /* SFS_TYPE == SFS_VFS */
3289 # if SFS_TYPE == SFS_MOUNT
3290 # include <sys/mount.h>
3291 # endif /* SFS_TYPE == SFS_MOUNT */
3292 # if SFS_TYPE == SFS_STATVFS
3293 # include <sys/statvfs.h>
3294 # endif /* SFS_TYPE == SFS_STATVFS */
3297 freediskspace(dir, bsize)
3301 # if SFS_TYPE == SFS_NONE
3305 /* assume free space is plentiful */
3306 return (long) LONG_MAX;
3307 # else /* SFS_TYPE == SFS_NONE */
3308 # if SFS_TYPE == SFS_USTAT
3310 struct stat statbuf;
3311 # define FSBLOCKSIZE DEV_BSIZE
3312 # define SFS_BAVAIL f_tfree
3313 # else /* SFS_TYPE == SFS_USTAT */
3314 # if defined(ultrix)
3316 # define SFS_BAVAIL fd_bfreen
3317 # define FSBLOCKSIZE 1024L
3318 # else /* defined(ultrix) */
3319 # if SFS_TYPE == SFS_STATVFS
3321 # define FSBLOCKSIZE fs.f_frsize
3322 # else /* SFS_TYPE == SFS_STATVFS */
3324 # define FSBLOCKSIZE fs.f_bsize
3325 # endif /* SFS_TYPE == SFS_STATVFS */
3326 # endif /* defined(ultrix) */
3327 # endif /* SFS_TYPE == SFS_USTAT */
3329 # define SFS_BAVAIL f_bavail
3330 # endif /* ! SFS_BAVAIL */
3332 # if SFS_TYPE == SFS_USTAT
3333 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
3334 # else /* SFS_TYPE == SFS_USTAT */
3335 # if SFS_TYPE == SFS_4ARGS
3336 if (statfs(dir, &fs, sizeof fs, 0) == 0)
3337 # else /* SFS_TYPE == SFS_4ARGS */
3338 # if SFS_TYPE == SFS_STATVFS
3339 if (statvfs(dir, &fs) == 0)
3340 # else /* SFS_TYPE == SFS_STATVFS */
3341 # if defined(ultrix)
3342 if (statfs(dir, &fs) > 0)
3343 # else /* defined(ultrix) */
3344 if (statfs(dir, &fs) == 0)
3345 # endif /* defined(ultrix) */
3346 # endif /* SFS_TYPE == SFS_STATVFS */
3347 # endif /* SFS_TYPE == SFS_4ARGS */
3348 # endif /* SFS_TYPE == SFS_USTAT */
3351 *bsize = FSBLOCKSIZE;
3352 if (fs.SFS_BAVAIL <= 0)
3354 else if (fs.SFS_BAVAIL > LONG_MAX)
3355 return (long) LONG_MAX;
3357 return (long) fs.SFS_BAVAIL;
3360 # endif /* SFS_TYPE == SFS_NONE */
3363 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3366 ** msize -- the size to check against. If zero, we don't yet
3367 ** know how big the message will be, so just check for
3368 ** a "reasonable" amount.
3369 ** e -- envelope, or NULL -- controls logging
3372 ** true if in every queue group there is at least one
3373 ** queue directory whose file system contains enough free space.
3377 ** If there is not enough disk space and e != NULL
3378 ** then sm_syslog is called.
3382 enoughdiskspace(msize, e)
3388 if (MinBlocksFree <= 0 && msize <= 0)
3391 sm_dprintf("enoughdiskspace: no threshold\n");
3396 for (i = 0; i < NumQueue; ++i)
3398 if (pickqdir(Queue[i], msize, e) < 0)
3404 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3406 ** This looks at an errno value and tells if this is likely to
3407 ** go away if retried later.
3410 ** err -- the errno code to classify.
3413 ** true if this is probably transient.
3423 case EIO: /* I/O error */
3424 case ENXIO: /* Device not configured */
3425 case EAGAIN: /* Resource temporarily unavailable */
3426 case ENOMEM: /* Cannot allocate memory */
3427 case ENODEV: /* Operation not supported by device */
3428 case ENFILE: /* Too many open files in system */
3429 case EMFILE: /* Too many open files */
3430 case ENOSPC: /* No space left on device */
3431 case ETIMEDOUT: /* Connection timed out */
3433 case ESTALE: /* Stale NFS file handle */
3436 case ENETDOWN: /* Network is down */
3437 #endif /* ENETDOWN */
3439 case ENETUNREACH: /* Network is unreachable */
3440 #endif /* ENETUNREACH */
3442 case ENETRESET: /* Network dropped connection on reset */
3443 #endif /* ENETRESET */
3445 case ECONNABORTED: /* Software caused connection abort */
3446 #endif /* ECONNABORTED */
3448 case ECONNRESET: /* Connection reset by peer */
3449 #endif /* ECONNRESET */
3451 case ENOBUFS: /* No buffer space available */
3452 #endif /* ENOBUFS */
3454 case ESHUTDOWN: /* Can't send after socket shutdown */
3455 #endif /* ESHUTDOWN */
3457 case ECONNREFUSED: /* Connection refused */
3458 #endif /* ECONNREFUSED */
3460 case EHOSTDOWN: /* Host is down */
3461 #endif /* EHOSTDOWN */
3463 case EHOSTUNREACH: /* No route to host */
3464 #endif /* EHOSTUNREACH */
3466 case EDQUOT: /* Disc quota exceeded */
3469 case EPROCLIM: /* Too many processes */
3470 #endif /* EPROCLIM */
3472 case EUSERS: /* Too many users */
3475 case EDEADLK: /* Resource deadlock avoided */
3476 #endif /* EDEADLK */
3478 case EISCONN: /* Socket already connected */
3479 #endif /* EISCONN */
3481 case EINPROGRESS: /* Operation now in progress */
3482 #endif /* EINPROGRESS */
3484 case EALREADY: /* Operation already in progress */
3485 #endif /* EALREADY */
3487 case EADDRINUSE: /* Address already in use */
3488 #endif /* EADDRINUSE */
3489 #ifdef EADDRNOTAVAIL
3490 case EADDRNOTAVAIL: /* Can't assign requested address */
3491 #endif /* EADDRNOTAVAIL */
3493 case ETXTBSY: /* (Apollo) file locked */
3494 #endif /* ETXTBSY */
3495 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3496 case ENOSR: /* Out of streams resources */
3497 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
3499 case ENOLCK: /* No locks available */
3501 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
3505 /* nope, must be permanent */
3509 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3512 ** fd -- the file descriptor of the file.
3513 ** filename -- the file name (for error messages).
3514 ** ext -- the filename extension.
3515 ** type -- type of the lock. Bits can be:
3516 ** LOCK_EX -- exclusive lock.
3517 ** LOCK_NB -- non-blocking.
3518 ** LOCK_UN -- unlock.
3521 ** true if the lock was acquired.
3526 lockfile(fd, filename, ext, type)
3541 memset(&lfd, '\0', sizeof lfd);
3542 if (bitset(LOCK_UN, type))
3543 lfd.l_type = F_UNLCK;
3544 else if (bitset(LOCK_EX, type))
3545 lfd.l_type = F_WRLCK;
3547 lfd.l_type = F_RDLCK;
3549 if (bitset(LOCK_NB, type))
3555 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
3556 filename, ext, action, lfd.l_type);
3558 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
3563 sm_dprintf("SUCCESS\n");
3569 sm_dprintf("(%s) ", sm_errstring(save_errno));
3572 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3573 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3574 ** as type "tmp" (that is, served from swap space), the
3575 ** previous fcntl will fail with "Invalid argument" errors.
3576 ** Since this is fairly common during testing, we will assume
3577 ** that this indicates that the lock is successfully grabbed.
3580 if (save_errno == EINVAL)
3583 sm_dprintf("SUCCESS\n");
3587 if (!bitset(LOCK_NB, type) ||
3588 (save_errno != EACCES && save_errno != EAGAIN))
3590 int omode = fcntl(fd, F_GETFL, 0);
3591 uid_t euid = geteuid();
3594 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3595 filename, ext, fd, type, omode, euid);
3596 dumpfd(fd, true, true);
3598 # else /* !HASFLOCK */
3603 sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
3605 while ((i = flock(fd, type)) < 0 && errno == EINTR)
3610 sm_dprintf("SUCCESS\n");
3616 sm_dprintf("(%s) ", sm_errstring(save_errno));
3618 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
3620 int omode = fcntl(fd, F_GETFL, 0);
3621 uid_t euid = geteuid();
3624 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3625 filename, ext, fd, type, omode, euid);
3626 dumpfd(fd, true, true);
3628 # endif /* !HASFLOCK */
3630 sm_dprintf("FAIL\n");
3635 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3637 ** Unfortunately, given that we can't predict other systems on which
3638 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3639 ** almost always that this is unsafe.
3641 ** Note also that many operating systems have non-compliant
3642 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3643 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3644 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3645 ** no non-root process can give away the file. However, vendors
3646 ** don't take NFS into account, so a comfortable value of
3647 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3649 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3650 ** even on files where chown is not restricted. Many systems get
3651 ** this wrong on NFS-based filesystems (that is, they say that chown
3652 ** is restricted [safe] on NFS filesystems where it may not be, since
3653 ** other systems can access the same filesystem and do file giveaway;
3654 ** only the NFS server knows for sure!) Hence, it is important to
3655 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3656 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3657 ** NFS-based filesystem to ensure that you can get meaningful results.
3658 ** If in doubt, assume unsafe!
3660 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3661 ** condition indicating whether the return from pathconf indicates
3662 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3663 ** even any agreement about whether a zero return means that a file
3664 ** is or is not safe). It defaults to "> 0".
3666 ** If the parent directory is safe (writable only by owner back
3667 ** to the root) then we can relax slightly and trust fpathconf
3668 ** in more circumstances. This is really a crock -- if this is an
3669 ** NFS mounted filesystem then we really know nothing about the
3670 ** underlying implementation. However, most systems pessimize and
3671 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3672 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3673 ** us into a possible problem only on systems that have a broken
3674 ** pathconf implementation and which are also poorly configured
3675 ** (have :include: files in group- or world-writable directories).
3678 ** fd -- the file descriptor to check.
3679 ** safedir -- set if the parent directory is safe.
3682 ** true -- if the chown(2) operation is "safe" -- that is,
3683 ** only root can chown the file to an arbitrary user.
3684 ** false -- if an arbitrary user can give away a file.
3687 #ifndef IS_SAFE_CHOWN
3688 # define IS_SAFE_CHOWN > 0
3689 #endif /* ! IS_SAFE_CHOWN */
3692 chownsafe(fd, safedir)
3696 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3697 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3700 /* give the system administrator a chance to override */
3701 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
3705 ** Some systems (e.g., SunOS) seem to have the call and the
3706 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3707 ** the call. This heuristic checks for that.
3711 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
3712 # if SAFENFSPATHCONF
3713 return errno == 0 && rval IS_SAFE_CHOWN;
3714 # else /* SAFENFSPATHCONF */
3715 return safedir && errno == 0 && rval IS_SAFE_CHOWN;
3716 # endif /* SAFENFSPATHCONF */
3717 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3718 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
3719 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3722 ** RESETLIMITS -- reset system controlled resource limits
3724 ** This is to avoid denial-of-service attacks
3734 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3735 # include <sys/time.h>
3736 # endif /* RLIMIT_NEEDS_SYS_TIME_H */
3737 # include <sys/resource.h>
3738 #endif /* HASSETRLIMIT */
3746 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
3747 (void) setrlimit(RLIMIT_CPU, &lim);
3748 (void) setrlimit(RLIMIT_FSIZE, &lim);
3749 # ifdef RLIMIT_NOFILE
3750 lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
3751 (void) setrlimit(RLIMIT_NOFILE, &lim);
3752 # endif /* RLIMIT_NOFILE */
3753 #else /* HASSETRLIMIT */
3755 (void) ulimit(2, 0x3fffff);
3756 (void) ulimit(4, FD_SETSIZE);
3757 # endif /* HASULIMIT */
3758 #endif /* HASSETRLIMIT */
3762 ** SETVENDOR -- process vendor code from V configuration line
3765 ** vendor -- string representation of vendor.
3769 ** false -- if vendor code could not be processed.
3772 ** It is reasonable to set mode flags here to tweak
3773 ** processing in other parts of the code if necessary.
3774 ** For example, if you are a vendor that uses $%y to
3775 ** indicate YP lookups, you could enable that here.
3782 if (sm_strcasecmp(vendor, "Berkeley") == 0)
3784 VendorCode = VENDOR_BERKELEY;
3788 /* add vendor extensions here */
3790 #ifdef SUN_EXTENSIONS
3791 if (sm_strcasecmp(vendor, "Sun") == 0)
3793 VendorCode = VENDOR_SUN;
3796 #endif /* SUN_EXTENSIONS */
3798 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3799 if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
3801 VendorCode = VENDOR_CODE;
3804 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3809 ** GETVENDOR -- return vendor name based on vendor code
3812 ** vendorcode -- numeric representation of vendor.
3815 ** string containing vendor name.
3819 getvendor(vendorcode)
3822 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3824 ** Can't have the same switch case twice so need to
3825 ** handle VENDOR_CODE outside of switch. It might
3826 ** match one of the existing VENDOR_* codes.
3829 if (vendorcode == VENDOR_CODE)
3831 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3835 case VENDOR_BERKELEY:
3847 case VENDOR_SENDMAIL:
3855 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3857 ** Vendor_pre_defaults is called before reading the configuration
3858 ** file; vendor_post_defaults is called immediately after.
3861 ** e -- the global environment to initialize.
3868 int DefShareUid; /* default share uid to run as -- unused??? */
3869 #endif /* SHARE_V1 */
3872 vendor_pre_defaults(e)
3876 /* OTHERUID is defined in shares.h, do not be alarmed */
3877 DefShareUid = OTHERUID;
3878 #endif /* SHARE_V1 */
3879 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3880 sun_pre_defaults(e);
3881 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3884 ** stupid domain/os can't even open
3885 ** /etc/mail/sendmail.cf without this
3888 setuserenv("ISP", NULL);
3889 setuserenv("SYSTYPE", NULL);
3895 vendor_post_defaults(e)
3901 /* Makes sure the SOCK environment variable remains */
3902 if (p = getextenv("SOCK"))
3903 setuserenv("SOCK", p);
3904 #endif /* __QNX__ */
3905 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3906 sun_post_defaults(e);
3907 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3910 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
3914 vendor_daemon_setup(e)
3918 (void) setlogin(RunAsUserName);
3919 #endif /* HASSETLOGIN */
3921 if (getluid() != -1)
3923 usrerr("Daemon cannot have LUID");
3924 finis(false, true, EX_USAGE);
3926 #endif /* SECUREWARE */
3929 ** VENDOR_SET_UID -- do setup for setting a user id
3931 ** This is called when we are still root.
3934 ** uid -- the uid we are about to become.
3945 ** We need to setup the share groups (lnodes)
3946 ** and add auditing information (luid's)
3947 ** before we loose our ``root''ness.
3950 if (setupshares(uid, syserr) != 0)
3951 syserr("Unable to set up shares");
3952 #endif /* SHARE_V1 */
3954 (void) setup_secure(uid);
3955 #endif /* SECUREWARE */
3958 ** VALIDATE_CONNECTION -- check connection for rationality
3960 ** If the connection is rejected, this routine should log an
3961 ** appropriate message -- but should never issue any SMTP protocol.
3964 ** sap -- a pointer to a SOCKADDR naming the peer.
3965 ** hostname -- the name corresponding to sap.
3966 ** e -- the current envelope.
3969 ** error message from rejection.
3970 ** NULL if not rejected.
3976 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
3977 int allow_severity = LOG_INFO;
3978 int deny_severity = LOG_NOTICE;
3979 #endif /* TCPWRAPPERS */
3982 validate_connection(sap, hostname, e)
3990 extern int hosts_ctl();
3991 #endif /* TCPWRAPPERS */
3994 sm_dprintf("validate_connection(%s, %s)\n",
3995 hostname, anynet_ntoa(sap));
3997 connection_rate_check(sap, e);
3998 if (rscheck("check_relay", hostname, anynet_ntoa(sap),
3999 e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID) != EX_OK)
4001 static char reject[BUFSIZ*2];
4002 extern char MsgBuf[];
4005 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
4007 if (strlen(MsgBuf) >= 3)
4008 (void) sm_strlcpy(reject, MsgBuf, sizeof reject);
4010 (void) sm_strlcpy(reject, "Access denied", sizeof reject);
4016 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
4020 addr = anynet_ntoa(sap);
4023 /* TCP/Wrappers don't want the IPv6: protocol label */
4024 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
4026 # endif /* NETINET6 */
4028 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
4031 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4033 sm_syslog(LOG_NOTICE, e->e_id,
4034 "tcpwrappers (%s, %s) rejection",
4036 return "Access denied";
4038 #endif /* TCPWRAPPERS */
4040 sm_dprintf(" ... validate_connection: OK\n");
4045 ** STRTOL -- convert string to long integer
4047 ** For systems that don't have it in the C library.
4049 ** This is taken verbatim from the 4.4-Lite C library.
4054 # if defined(LIBC_SCCS) && !defined(lint)
4055 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4056 # endif /* defined(LIBC_SCCS) && !defined(lint) */
4059 ** Convert a string to a long integer.
4061 ** Ignores `locale' stuff. Assumes that the upper and lower case
4062 ** alphabets and digits are each contiguous.
4066 strtol(nptr, endptr, base)
4071 register const char *s = nptr;
4072 register unsigned long acc;
4074 register unsigned long cutoff;
4075 register int neg = 0, any, cutlim;
4078 ** Skip white space and pick up leading +/- sign if any.
4079 ** If base is 0, allow 0x for hex and 0 for octal, else
4080 ** assume decimal; if base is already 16, allow 0x.
4084 } while (isspace(c));
4088 } else if (c == '+')
4090 if ((base == 0 || base == 16) &&
4091 c == '0' && (*s == 'x' || *s == 'X')) {
4097 base = c == '0' ? 8 : 10;
4100 ** Compute the cutoff value between legal numbers and illegal
4101 ** numbers. That is the largest legal value, divided by the
4102 ** base. An input number that is greater than this value, if
4103 ** followed by a legal input character, is too big. One that
4104 ** is equal to this value may be valid or not; the limit
4105 ** between valid and invalid numbers is then based on the last
4106 ** digit. For instance, if the range for longs is
4107 ** [-2147483648..2147483647] and the input base is 10,
4108 ** cutoff will be set to 214748364 and cutlim to either
4109 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4110 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4111 ** the number is too big, and we will return a range error.
4113 ** Set any if any `digits' consumed; make it negative to indicate
4116 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
4117 cutlim = cutoff % (unsigned long) base;
4118 cutoff /= (unsigned long) base;
4119 for (acc = 0, any = 0;; c = *s++) {
4122 else if (isalpha(c))
4123 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
4128 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
4137 acc = neg ? LONG_MIN : LONG_MAX;
4142 *endptr = (char *)(any ? s - 1 : nptr);
4146 #endif /* NEEDSTRTOL */
4148 ** STRSTR -- find first substring in string
4151 ** big -- the big (full) string.
4152 ** little -- the little (sub) string.
4155 ** A pointer to the first instance of little in big.
4156 ** big if little is the null string.
4157 ** NULL if little is not contained in big.
4167 register char *p = big;
4170 if (*little == '\0')
4174 while ((p = strchr(p, *little)) != NULL)
4176 if (strncmp(p, little, l) == 0)
4183 #endif /* NEEDSTRSTR */
4185 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4187 ** Some operating systems have wierd problems with the gethostbyXXX
4188 ** routines. For example, Solaris versions at least through 2.3
4189 ** don't properly deliver a canonical h_name field. This tries to
4190 ** work around these problems.
4192 ** Support IPv6 as well as IPv4.
4195 #if NETINET6 && NEEDSGETIPNODE
4198 # define AI_DEFAULT 0 /* dummy */
4199 # endif /* ! AI_DEFAULT */
4200 # ifndef AI_ADDRCONFIG
4201 # define AI_ADDRCONFIG 0 /* dummy */
4202 # endif /* ! AI_ADDRCONFIG */
4203 # ifndef AI_V4MAPPED
4204 # define AI_V4MAPPED 0 /* dummy */
4205 # endif /* ! AI_V4MAPPED */
4207 # define AI_ALL 0 /* dummy */
4208 # endif /* ! AI_ALL */
4210 static struct hostent *
4211 getipnodebyname(name, family, flags, err)
4220 if (family == AF_INET6)
4222 /* From RFC2133, section 6.1 */
4223 resv6 = bitset(RES_USE_INET6, _res.options);
4224 _res.options |= RES_USE_INET6;
4227 h = gethostbyname(name);
4229 _res.options &= ~RES_USE_INET6;
4234 static struct hostent *
4235 getipnodebyaddr(addr, len, family, err)
4244 h = gethostbyaddr(addr, len, family);
4254 ** Stub routine -- if they don't have getipnodeby*(),
4255 ** they probably don't have the free routine either.
4260 #endif /* NETINET6 && NEEDSGETIPNODE */
4263 sm_gethostbyname(name, family)
4268 struct hostent *h = NULL;
4269 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4270 # if SOLARIS == 20300 || SOLARIS == 203
4271 static struct hostent hp;
4272 static char buf[1000];
4273 extern struct hostent *_switch_gethostbyname_r();
4276 sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
4277 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
4279 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4280 extern struct hostent *__switch_gethostbyname();
4283 sm_dprintf("__switch_gethostbyname(%s)... ", name);
4284 h = __switch_gethostbyname(name);
4286 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4287 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4290 int flags = AI_DEFAULT|AI_ALL;
4292 # endif /* NETINET6 */
4293 char *maptype[MAXMAPSTACK];
4294 short mapreturn[MAXMAPACTIONS];
4298 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
4301 # if ADDRCONFIG_IS_BROKEN
4302 flags &= ~AI_ADDRCONFIG;
4303 # endif /* ADDRCONFIG_IS_BROKEN */
4304 h = getipnodebyname(name, family, flags, &err);
4305 SM_SET_H_ERRNO(err);
4306 # else /* NETINET6 */
4307 h = gethostbyname(name);
4308 # endif /* NETINET6 */
4314 sm_dprintf("failure\n");
4316 nmaps = switch_map_find("hosts", maptype, mapreturn);
4317 while (--nmaps >= 0)
4319 if (strcmp(maptype[nmaps], "nis") == 0 ||
4320 strcmp(maptype[nmaps], "files") == 0)
4326 /* try short name */
4327 if (strlen(name) > sizeof hbuf - 1)
4332 (void) sm_strlcpy(hbuf, name, sizeof hbuf);
4333 (void) shorten_hostname(hbuf);
4335 /* if it hasn't been shortened, there's no point */
4336 if (strcmp(hbuf, name) != 0)
4339 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4343 h = getipnodebyname(hbuf, family, flags, &err);
4344 SM_SET_H_ERRNO(err);
4346 # else /* NETINET6 */
4347 h = gethostbyname(hbuf);
4349 # endif /* NETINET6 */
4353 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4357 sm_dprintf("failure\n");
4360 sm_dprintf("%s\n", h->h_name);
4364 struct in6_addr ia6;
4365 char buf6[INET6_ADDRSTRLEN];
4366 #else /* NETINET6 */
4368 #endif /* NETINET6 */
4371 if (h->h_aliases != NULL)
4372 for (i = 0; h->h_aliases[i] != NULL;
4374 sm_dprintf("\talias: %s\n",
4376 for (i = 0; h->h_addr_list[i] != NULL; i++)
4381 memmove(&ia6, h->h_addr_list[i],
4383 addr = anynet_ntop(&ia6,
4385 #else /* NETINET6 */
4386 memmove(&ia, h->h_addr_list[i],
4388 addr = (char *) inet_ntoa(ia);
4389 #endif /* NETINET6 */
4391 sm_dprintf("\taddr: %s\n", addr);
4401 sm_gethostbyaddr(addr, len, type)
4409 if (type == AF_INET6 &&
4410 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
4412 /* Avoid reverse lookup for IPv6 unspecified address */
4413 SM_SET_H_ERRNO(HOST_NOT_FOUND);
4416 #endif /* NETINET6 */
4418 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4419 # if SOLARIS == 20300 || SOLARIS == 203
4421 static struct hostent he;
4422 static char buf[1000];
4423 extern struct hostent *_switch_gethostbyaddr_r();
4425 hp = _switch_gethostbyaddr_r(addr, len, type, &he,
4426 buf, sizeof(buf), &h_errno);
4428 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4430 extern struct hostent *__switch_gethostbyaddr();
4432 hp = __switch_gethostbyaddr(addr, len, type);
4434 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4435 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4440 hp = getipnodebyaddr(addr, len, type, &err);
4441 SM_SET_H_ERRNO(err);
4443 # else /* NETINET6 */
4444 hp = gethostbyaddr(addr, len, type);
4445 # endif /* NETINET6 */
4446 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4450 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4458 extern struct passwd *_getpwnam_shadow(const char *, const int);
4460 return _getpwnam_shadow(user, 0);
4462 return getpwnam(user);
4470 #if defined(_AIX4) && 0
4471 extern struct passwd *_getpwuid_shadow(const int, const int);
4473 return _getpwuid_shadow(uid,0);
4474 #else /* defined(_AIX4) && 0 */
4475 return getpwuid(uid);
4476 #endif /* defined(_AIX4) && 0 */
4479 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4481 ** Set up the trusted computing environment for C2 level security
4482 ** under SecureWare.
4485 ** uid -- uid of the user to initialize in the TCB
4491 ** Initialized the user in the trusted computing base
4496 # include <sys/security.h>
4500 secureware_setup_secure(uid)
4505 if (getluid() != -1)
4508 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
4512 case SSI_NO_PRPW_ENTRY:
4513 syserr("No protected passwd entry, uid = %d",
4518 syserr("Account has been disabled, uid = %d",
4523 syserr("Account has been retired, uid = %d",
4527 case SSI_BAD_SET_LUID:
4528 syserr("Could not set LUID, uid = %d", (int) uid);
4531 case SSI_BAD_SET_PRIVS:
4532 syserr("Could not set kernel privs, uid = %d",
4536 syserr("Unknown return code (%d) from set_secure_info(%d)",
4540 finis(false, true, EX_NOPERM);
4543 #endif /* SECUREWARE */
4545 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4547 ** Add hostnames to class 'w' based on the IP address read from
4548 ** the network interface.
4551 ** sa -- a pointer to a SOCKADDR containing the address
4554 ** 0 if successful, -1 if host lookup fails.
4563 char hnb[MAXHOSTNAMELEN];
4565 /* lookup name with IP address */
4566 switch (sa->sa.sa_family)
4570 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
4571 sizeof(sa->sin.sin_addr),
4574 #endif /* NETINET */
4578 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
4579 sizeof(sa->sin6.sin6_addr),
4582 #endif /* NETINET6 */
4585 /* Give warning about unsupported family */
4587 sm_syslog(LOG_WARNING, NOQID,
4588 "Unsupported address family %d: %.100s",
4589 sa->sa.sa_family, anynet_ntoa(sa));
4595 int save_errno = errno;
4599 !(sa->sa.sa_family == AF_INET6 &&
4600 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
4601 #endif /* NETINET6 */
4603 sm_syslog(LOG_WARNING, NOQID,
4604 "gethostbyaddr(%.100s) failed: %d",
4608 #else /* NAMED_BIND */
4610 #endif /* NAMED_BIND */
4616 /* save its cname */
4617 if (!wordinclass((char *) hp->h_name, 'w'))
4619 setclass('w', (char *) hp->h_name);
4621 sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
4623 if (sm_snprintf(hnb, sizeof hnb, "[%s]", hp->h_name) < sizeof hnb
4624 && !wordinclass((char *) hnb, 'w'))
4630 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
4633 /* save all it aliases name */
4634 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
4636 if (!wordinclass(*ha, 'w'))
4640 sm_dprintf("\ta.k.a.: %s\n", *ha);
4641 if (sm_snprintf(hnb, sizeof hnb,
4642 "[%s]", *ha) < sizeof hnb &&
4643 !wordinclass((char *) hnb, 'w'))
4649 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4655 #endif /* NETINET6 */
4659 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4668 ** Loads $=w with the names of all the interfaces.
4672 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4673 #endif /* !NETINET */
4675 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4679 # include <sys/time.h>
4680 # endif /* ! SUNOS403 */
4681 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4683 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
4684 # include <net/if.h>
4685 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4690 # if NETINET6 && defined(SIOCGLIFCONF)
4694 ** Unfortunately, HP has changed all of the structures,
4695 ** making life difficult for implementors.
4698 # define lifconf if_laddrconf
4699 # define lifc_len iflc_len
4700 # define lifc_buf iflc_buf
4701 # define lifreq if_laddrreq
4702 # define lifr_addr iflr_addr
4703 # define lifr_name iflr_name
4704 # define lifr_flags iflr_flags
4705 # define ss_family sa_family
4707 # endif /* __hpux */
4714 struct lifconf lifc;
4717 # endif /* SIOCGLIFNUM */
4719 s = socket(InetMode, SOCK_DGRAM, 0);
4723 /* get the list of known IP address from the kernel */
4725 i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
4726 # endif /* __hpux */
4728 lifn.lifn_family = AF_UNSPEC;
4729 lifn.lifn_flags = 0;
4730 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
4731 numifs = lifn.lifn_count;
4732 # endif /* SIOCGLIFNUM */
4734 # if defined(__hpux) || defined(SIOCGLIFNUM)
4737 /* can't get number of interfaces -- fall back */
4739 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4740 sm_errstring(errno));
4743 else if (tTd(0, 42))
4744 sm_dprintf("system has %d interfaces\n", numifs);
4746 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4747 numifs = MAXINTERFACES;
4755 len = lifc.lifc_len = numifs * sizeof (struct lifreq);
4756 buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
4758 lifc.lifc_family = AF_UNSPEC;
4759 lifc.lifc_flags = 0;
4760 # endif /* ! __hpux */
4761 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
4764 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4765 sm_errstring(errno));
4771 /* scan the list of IP address */
4773 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4776 for (i = 0; i < len && i >= 0; )
4779 struct lifreq *ifr = (struct lifreq *)&buf[i];
4780 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
4781 int af = ifr->lifr_addr.ss_family;
4784 struct in6_addr ia6;
4786 # ifdef SIOCGLIFFLAGS
4788 # endif /* SIOCGLIFFLAGS */
4790 char buf6[INET6_ADDRSTRLEN];
4793 ** We must close and recreate the socket each time
4794 ** since we don't know what type of socket it is now
4795 ** (each status function may change it).
4800 s = socket(af, SOCK_DGRAM, 0);
4803 sm_free(buf); /* XXX */
4808 ** If we don't have a complete ifr structure,
4809 ** don't try to use it.
4812 if ((len - i) < sizeof *ifr)
4815 # ifdef BSD4_4_SOCKADDR
4816 if (sa->sa.sa_len > sizeof ifr->lifr_addr)
4817 i += sizeof ifr->lifr_name + sa->sa.sa_len;
4819 # endif /* BSD4_4_SOCKADDR */
4823 sm_dprintf("%s\n", anynet_ntoa(sa));
4825 if (af != AF_INET && af != AF_INET6)
4828 # ifdef SIOCGLIFFLAGS
4829 memset(&ifrf, '\0', sizeof(struct lifreq));
4830 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
4831 sizeof(ifrf.lifr_name));
4832 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
4835 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4836 sm_errstring(errno));
4840 name = ifr->lifr_name;
4841 flags = ifrf.lifr_flags;
4844 sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
4846 if (!bitset(IFF_UP, flags))
4848 # endif /* SIOCGLIFFLAGS */
4852 /* extract IP address from the list*/
4857 /* convert into proper scoped address */
4858 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
4859 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
4860 sa->sin6.sin6_scope_id == 0)
4862 struct in6_addr *ia6p;
4864 ia6p = &sa->sin6.sin6_addr;
4865 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
4866 ((unsigned int)ia6p->s6_addr[2] << 8));
4867 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
4869 # endif /* __KAME__ */
4870 ia6 = sa->sin6.sin6_addr;
4871 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
4873 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
4874 message("WARNING: interface %s is UP with %s address",
4875 name, addr == NULL ? "(NULL)" : addr);
4879 /* save IP address in text from */
4880 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
4882 (void) sm_snprintf(ip_addr, sizeof ip_addr,
4884 (int) sizeof ip_addr - 3,
4889 ia = sa->sin.sin_addr;
4890 if (ia.s_addr == INADDR_ANY ||
4891 ia.s_addr == INADDR_NONE)
4893 message("WARNING: interface %s is UP with %s address",
4894 name, inet_ntoa(ia));
4898 /* save IP address in text from */
4899 (void) sm_snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
4900 (int) sizeof ip_addr - 3, inet_ntoa(ia));
4904 if (*ip_addr == '\0')
4907 if (!wordinclass(ip_addr, 'w'))
4909 setclass('w', ip_addr);
4911 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
4914 # ifdef SIOCGLIFFLAGS
4915 /* skip "loopback" interface "lo" */
4916 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
4917 bitset(IFF_LOOPBACK, flags))
4919 # endif /* SIOCGLIFFLAGS */
4920 (void) add_hostnames(sa);
4922 sm_free(buf); /* XXX */
4924 # else /* NETINET6 && defined(SIOCGLIFCONF) */
4925 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4931 s = socket(AF_INET, SOCK_DGRAM, 0);
4935 /* get the list of known IP address from the kernel */
4936 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
4937 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
4939 /* can't get number of interfaces -- fall back */
4941 sm_dprintf("SIOCGIFNUM failed: %s\n",
4942 sm_errstring(errno));
4945 else if (tTd(0, 42))
4946 sm_dprintf("system has %d interfaces\n", numifs);
4948 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
4949 numifs = MAXINTERFACES;
4956 ifc.ifc_len = numifs * sizeof (struct ifreq);
4957 ifc.ifc_buf = xalloc(ifc.ifc_len);
4958 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
4961 sm_dprintf("SIOCGIFCONF failed: %s\n",
4962 sm_errstring(errno));
4967 /* scan the list of IP address */
4969 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
4972 for (i = 0; i < ifc.ifc_len && i >= 0; )
4975 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
4976 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
4979 struct in6_addr ia6;
4980 # endif /* NETINET6 */
4982 # ifdef SIOCGIFFLAGS
4984 # endif /* SIOCGIFFLAGS */
4987 char buf6[INET6_ADDRSTRLEN];
4988 # endif /* NETINET6 */
4991 ** If we don't have a complete ifr structure,
4992 ** don't try to use it.
4995 if ((ifc.ifc_len - i) < sizeof *ifr)
4998 # ifdef BSD4_4_SOCKADDR
4999 if (sa->sa.sa_len > sizeof ifr->ifr_addr)
5000 i += sizeof ifr->ifr_name + sa->sa.sa_len;
5002 # endif /* BSD4_4_SOCKADDR */
5006 sm_dprintf("%s\n", anynet_ntoa(sa));
5008 af = ifr->ifr_addr.sa_family;
5012 # endif /* NETINET6 */
5016 # ifdef SIOCGIFFLAGS
5017 memset(&ifrf, '\0', sizeof(struct ifreq));
5018 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
5019 sizeof(ifrf.ifr_name));
5020 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
5022 sm_dprintf("\tflags: %lx\n",
5023 (unsigned long) ifrf.ifr_flags);
5024 # define IFRFREF ifrf
5025 # else /* SIOCGIFFLAGS */
5026 # define IFRFREF (*ifr)
5027 # endif /* SIOCGIFFLAGS */
5029 if (!bitset(IFF_UP, IFRFREF.ifr_flags))
5034 /* extract IP address from the list*/
5038 ia = sa->sin.sin_addr;
5039 if (ia.s_addr == INADDR_ANY ||
5040 ia.s_addr == INADDR_NONE)
5042 message("WARNING: interface %s is UP with %s address",
5043 ifr->ifr_name, inet_ntoa(ia));
5047 /* save IP address in text from */
5048 (void) sm_snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
5049 (int) sizeof ip_addr - 3,
5056 /* convert into proper scoped address */
5057 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5058 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5059 sa->sin6.sin6_scope_id == 0)
5061 struct in6_addr *ia6p;
5063 ia6p = &sa->sin6.sin6_addr;
5064 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5065 ((unsigned int)ia6p->s6_addr[2] << 8));
5066 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5068 # endif /* __KAME__ */
5069 ia6 = sa->sin6.sin6_addr;
5070 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5072 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
5073 message("WARNING: interface %s is UP with %s address",
5075 addr == NULL ? "(NULL)" : addr);
5079 /* save IP address in text from */
5080 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
5082 (void) sm_snprintf(ip_addr, sizeof ip_addr,
5084 (int) sizeof ip_addr - 3,
5088 # endif /* NETINET6 */
5091 if (ip_addr[0] == '\0')
5094 if (!wordinclass(ip_addr, 'w'))
5096 setclass('w', ip_addr);
5098 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5101 /* skip "loopback" interface "lo" */
5102 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5103 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
5106 (void) add_hostnames(sa);
5108 sm_free(ifc.ifc_buf); /* XXX */
5111 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5112 # endif /* NETINET6 && defined(SIOCGLIFCONF) */
5115 ** ISLOOPBACK -- is socket address in the loopback net?
5118 ** sa -- socket address.
5121 ** true -- is socket address in the loopback net?
5122 ** false -- otherwise
5131 if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
5133 #else /* NETINET6 */
5134 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5135 if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
5136 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
5138 #endif /* NETINET6 */
5142 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5148 ** The number of processors online.
5152 get_num_procs_online()
5157 # if defined(CTL_HW) && defined(HW_NCPU)
5163 sz = (size_t) sizeof nproc;
5164 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
5165 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5166 #else /* USESYSCTL */
5167 # ifdef _SC_NPROCESSORS_ONLN
5168 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
5169 # else /* _SC_NPROCESSORS_ONLN */
5171 # include <sys/pstat.h>
5172 struct pst_dynamic psd;
5174 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
5175 nproc = psd.psd_proc_cnt;
5176 # endif /* __hpux */
5177 # endif /* _SC_NPROCESSORS_ONLN */
5178 #endif /* USESYSCTL */
5185 ** SM_CLOSEFROM -- close file descriptors
5188 ** lowest -- first fd to close
5189 ** highest -- last fd + 1 to close
5196 sm_closefrom(lowest, highest)
5197 int lowest, highest;
5201 #else /* HASCLOSEFROM */
5204 for (i = lowest; i < highest; i++)
5206 #endif /* HASCLOSEFROM */
5210 ** CLOSEFD_WALK -- walk fd's arranging to close them
5211 ** Callback for fdwalk()
5214 ** lowest -- first fd to arrange to be closed
5215 ** fd -- fd to arrange to be closed
5222 closefd_walk(lowest, fd)
5226 if (fd >= *(int *)lowest)
5227 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
5230 #endif /* HASFDWALK */
5232 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5235 ** lowest -- first fd to arrange to be closed
5236 ** highest -- last fd + 1 to arrange to be closed
5243 sm_close_on_exec(highest, lowest)
5244 int highest, lowest;
5247 (void) fdwalk(closefd_walk, &lowest);
5248 #else /* HASFDWALK */
5251 for (i = lowest; i < highest; i++)
5253 if ((j = fcntl(i, F_GETFD, 0)) != -1)
5254 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
5256 #endif /* HASFDWALK */
5259 ** SEED_RANDOM -- seed the random number generator
5273 #else /* HASSRANDOMDEV */
5277 seed = (long) CurrentPid;
5278 if (gettimeofday(&t, NULL) >= 0)
5279 seed += t.tv_sec + t.tv_usec;
5282 (void) srandom(seed);
5283 # else /* HASRANDOM */
5284 (void) srand((unsigned int) seed);
5285 # endif /* HASRANDOM */
5286 #endif /* HASSRANDOMDEV */
5289 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5292 ** level -- syslog level
5293 ** id -- envelope ID or NULL (NOQUEUE)
5294 ** fmt -- format string
5295 ** arg... -- arguments as implied by fmt.
5304 sm_syslog(int level, const char *id, const char *fmt, ...)
5305 #else /* __STDC__ */
5306 sm_syslog(level, id, fmt, va_alist)
5311 #endif /* __STDC__ */
5313 static char *buf = NULL;
5314 static size_t bufsize;
5321 extern int SyslogPrefixLen;
5328 idlen = strlen(id) + SyslogPrefixLen;
5330 else if (strcmp(id, NOQID) == 0)
5333 idlen = SyslogPrefixLen;
5336 idlen = strlen(id) + SyslogPrefixLen;
5341 bufsize = sizeof buf0;
5348 /* print log message into buf */
5349 SM_VA_START(ap, fmt);
5350 n = sm_vsnprintf(buf, bufsize, fmt, ap);
5356 /* String too small, redo with correct size */
5363 buf = sm_malloc_x(bufsize);
5366 /* clean up buf after it has been expanded with args */
5367 newstring = str2prt(buf);
5368 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
5372 syslog(level, "%s", newstring);
5374 syslog(level, "%s: %s", id, newstring);
5376 /*XXX should do something more sensible */
5378 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
5381 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5382 "%s: %s\n", id, newstring);
5391 ** additional length for splitting: " ..." + 3, where 3 is magic to
5392 ** have some data for the next entry.
5398 idlen += 5; /* strlen("[999]"), see below */
5399 while (*begin != '\0' &&
5400 (strlen(begin) + idlen) > SYSLOG_BUFSIZE)
5406 /* Too many messages */
5409 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5412 /* Break on comma or space */
5413 if (*end == ',' || *end == ' ')
5415 end++; /* Include separator */
5420 /* No separator, break midstring... */
5422 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5426 syslog(level, "%s[%d]: %s ...", id, seq++, begin);
5428 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5429 "%s[%d]: %s ...\n", id, seq++, begin);
5436 syslog(level, "%s[%d]: log terminated, too many parts",
5439 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5440 "%s[%d]: log terminated, too many parts\n", id, seq);
5442 else if (*begin != '\0')
5444 syslog(level, "%s[%d]: %s", id, seq, begin);
5446 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5447 "%s[%d]: %s\n", id, seq, begin);
5454 ** HARD_SYSLOG -- call syslog repeatedly until it works
5456 ** Needed on HP-UX, which apparently doesn't guarantee that
5457 ** syslog succeeds during interrupt handlers.
5460 #if defined(__hpux) && !defined(HPUX11)
5462 # define MAXSYSLOGTRIES 100
5465 # define XCNST const
5466 # define CAST (const char *)
5474 hard_syslog(int pri, XCNST char *msg, ...)
5475 # else /* __STDC__ */
5476 hard_syslog(pri, msg, va_alist)
5480 # endif /* __STDC__ */
5483 char buf[SYSLOG_BUFSIZE];
5486 SM_VA_START(ap, msg);
5487 (void) sm_vsnprintf(buf, sizeof buf, msg, ap);
5490 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
5495 #endif /* defined(__hpux) && !defined(HPUX11) */
5496 #if NEEDLOCAL_HOSTNAME_LENGTH
5498 ** LOCAL_HOSTNAME_LENGTH
5500 ** This is required to get sendmail to compile against BIND 4.9.x
5503 ** Unfortunately, a Compaq Y2K patch kit provides it without
5504 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5505 ** figure out whether it is needed.
5509 local_hostname_length(hostname)
5512 size_t len_host, len_domain;
5514 if (!*_res.defdname)
5516 len_host = strlen(hostname);
5517 len_domain = strlen(_res.defdname);
5518 if (len_host > len_domain &&
5519 (sm_strcasecmp(hostname + len_host - len_domain,
5520 _res.defdname) == 0) &&
5521 hostname[len_host - len_domain - 1] == '.')
5522 return len_host - len_domain - 1;
5526 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5530 ** LINK -- clone a file
5532 ** Some OS's lacks link() and hard links. Since sendmail is using
5533 ** link() as an efficient way to clone files, this implementation
5534 ** will simply do a file copy.
5536 ** NOTE: This link() replacement is not a generic replacement as it
5537 ** does not handle all of the semantics of the real link(2).
5540 ** source -- pathname of existing file.
5541 ** target -- pathname of link (clone) to be created.
5545 ** -1 -- failure, see errno for details.
5549 link(source, target)
5555 int src = -1, dst = -1;
5561 sff = SFF_REGONLY|SFF_OPENASROOT;
5562 if (DontLockReadFiles)
5565 /* Open the original file */
5566 src = safeopen((char *)source, O_RDONLY, 0, sff);
5570 /* Obtain the size and the mode */
5571 if (fstat(src, &st) < 0)
5574 /* Create the duplicate copy */
5577 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
5582 /* Copy all of the bytes one buffer at a time */
5583 while ((readlen = read(src, &buf, sizeof(buf))) > 0)
5585 ssize_t left = readlen;
5589 (writelen = write(dst, p, (size_t) left)) >= 0)
5598 /* Any trouble reading? */
5599 if (readlen < 0 || writelen < 0)
5602 /* Close the input file */
5610 /* Close the output file */
5613 /* don't set dst = -1 here so we unlink the file */
5626 (void) unlink(target);
5632 #endif /* NEEDLINK */
5635 ** Compile-Time options
5638 char *CompileOptions[] =
5642 #endif /* ALLOW_255 */
5646 # endif /* DNSMAP */
5647 #endif /* NAMED_BIND */
5656 #endif /* HES_GETMAILHOST */
5659 #endif /* LDAPMAP */
5665 #endif /* MAP_NSD */
5668 #endif /* MAP_REGEX */
5671 #endif /* MATCHGECOS */
5677 #endif /* MIME7TO8 */
5680 #endif /* MIME7TO8_OLD */
5683 #endif /* MIME8TO7 */
5686 #endif /* NAMED_BIND */
5692 #endif /* NETINET */
5695 #endif /* NETINET6 */
5698 #endif /* NETINFO */
5707 #endif /* NETUNIX */
5719 #endif /* NISPLUS */
5726 #ifdef PICKY_HELO_CHECK
5728 #endif /* PICKY_HELO_CHECK */
5731 #endif /* PIPELINING */
5735 # else /* SASL >= 20000 */
5737 # endif /* SASL >= 20000 */
5744 #endif /* SMTPDEBUG */
5747 #endif /* SOCKETMAP */
5750 #endif /* STARTTLS */
5751 #if SUID_ROOT_FILES_OK
5752 "SUID_ROOT_FILES_OK",
5753 #endif /* SUID_ROOT_FILES_OK */
5756 #endif /* TCPWRAPPERS */
5759 #endif /* TLS_NO_RSA */
5760 #if TLS_VRFY_PER_CTX
5762 #endif /* TLS_VRFY_PER_CTX */
5768 #endif /* USE_LDAP_INIT */
5771 #endif /* USE_TTYPATH */
5783 ** OS compile options.
5786 char *OsCompileOptions[] =
5788 #if ADDRCONFIG_IS_BROKEN
5789 "ADDRCONFIG_IS_BROKEN",
5790 #endif /* ADDRCONFIG_IS_BROKEN */
5791 #ifdef AUTO_NETINFO_HOSTS
5792 "AUTO_NETINFO_HOSTS",
5793 #endif /* AUTO_NETINFO_HOSTS */
5794 #ifdef AUTO_NIS_ALIASES
5796 #endif /* AUTO_NIS_ALIASES */
5797 #if BROKEN_RES_SEARCH
5798 "BROKEN_RES_SEARCH",
5799 #endif /* BROKEN_RES_SEARCH */
5800 #ifdef BSD4_4_SOCKADDR
5802 #endif /* BSD4_4_SOCKADDR */
5805 #endif /* BOGUS_O_EXCL */
5806 #if DEC_OSF_BROKEN_GETPWENT
5807 "DEC_OSF_BROKEN_GETPWENT",
5808 #endif /* DEC_OSF_BROKEN_GETPWENT */
5809 #if FAST_PID_RECYCLE
5811 #endif /* FAST_PID_RECYCLE */
5814 #endif /* HASCLOSEFROM */
5817 #endif /* HASFCHOWN */
5820 #endif /* HASFCHMOD */
5823 #endif /* HASFDWALK */
5826 #endif /* HASFLOCK */
5827 #if HASGETDTABLESIZE
5829 #endif /* HASGETDTABLESIZE */
5832 #endif /* HASGETUSERSHELL */
5835 #endif /* HASINITGROUPS */
5838 #endif /* HASLSTAT */
5841 #endif /* HASNICE */
5844 #endif /* HASRANDOM */
5847 #endif /* HASRRESVPORT */
5850 #endif /* HASSETEGID */
5853 #endif /* HASSETLOGIN */
5856 #endif /* HASSETREGID */
5859 #endif /* HASSETRESGID */
5862 #endif /* HASSETREUID */
5865 #endif /* HASSETRLIMIT */
5868 #endif /* HASSETSID */
5869 #if HASSETUSERCONTEXT
5870 "HASSETUSERCONTEXT",
5871 #endif /* HASSETUSERCONTEXT */
5874 #endif /* HASSETVBUF */
5877 #endif /* HAS_ST_GEN */
5880 #endif /* HASSRANDOMDEV */
5883 #endif /* HASURANDOMDEV */
5886 #endif /* HASSTRERROR */
5889 #endif /* HASULIMIT */
5892 #endif /* HASUNAME */
5895 #endif /* HASUNSETENV */
5898 #endif /* HASWAITPID */
5901 #endif /* IDENTPROTO */
5904 #endif /* IP_SRCROUTE */
5905 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
5907 #endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */
5910 #endif /* NEEDFSYNC */
5913 #endif /* NEEDLINK */
5914 #if NEEDLOCAL_HOSTNAME_LENGTH
5915 "NEEDLOCAL_HOSTNAME_LENGTH",
5916 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5919 #endif /* NEEDSGETIPNODE */
5922 #endif /* NEEDSTRSTR */
5925 #endif /* NEEDSTRTOL */
5926 #ifdef NO_GETSERVBYNAME
5928 #endif /* NO_GETSERVBYNAME */
5931 #endif /* NOFTRUNCATE */
5932 #if REQUIRES_DIR_FSYNC
5933 "REQUIRES_DIR_FSYNC",
5934 #endif /* REQUIRES_DIR_FSYNC */
5935 #if RLIMIT_NEEDS_SYS_TIME_H
5936 "RLIMIT_NEEDS_SYS_TIME_H",
5937 #endif /* RLIMIT_NEEDS_SYS_TIME_H */
5940 #endif /* SAFENFSPATHCONF */
5943 #endif /* SECUREWARE */
5946 #endif /* SHARE_V1 */
5947 #if SIOCGIFCONF_IS_BROKEN
5948 "SIOCGIFCONF_IS_BROKEN",
5949 #endif /* SIOCGIFCONF_IS_BROKEN */
5950 #if SIOCGIFNUM_IS_BROKEN
5951 "SIOCGIFNUM_IS_BROKEN",
5952 #endif /* SIOCGIFNUM_IS_BROKEN */
5953 #if SNPRINTF_IS_BROKEN
5954 "SNPRINTF_IS_BROKEN",
5955 #endif /* SNPRINTF_IS_BROKEN */
5956 #if SO_REUSEADDR_IS_BROKEN
5957 "SO_REUSEADDR_IS_BROKEN",
5958 #endif /* SO_REUSEADDR_IS_BROKEN */
5961 #endif /* SYS5SETPGRP */
5964 #endif /* SYSTEM5 */
5967 #endif /* USE_DOUBLE_FORK */
5970 #endif /* USE_ENVIRON */
5971 #if USE_SA_SIGACTION
5973 #endif /* USE_SA_SIGACTION */
5976 #endif /* USE_SIGLONGJMP */
5979 #endif /* USEGETCONFATTR */
5982 #endif /* USESETEUID */
5985 #endif /* USESYSCTL */
5986 #if USING_NETSCAPE_LDAP
5987 "USING_NETSCAPE_LDAP",
5988 #endif /* USING_NETSCAPE_LDAP */
5991 #endif /* WAITUNION */
5996 ** FFR compile options.
5999 char *FFRCompileOptions[] =
6001 #if _FFR_ALLOW_SASLINFO
6002 /* DefaultAuthInfo can be specified by user. */
6003 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */
6004 "_FFR_ALLOW_SASLINFO",
6005 #endif /* _FFR_ALLOW_SASLINFO */
6006 #if _FFR_BESTMX_BETTER_TRUNCATION
6007 /* Better truncation of list of MX records for dns map. */
6008 "_FFR_BESTMX_BETTER_TRUNCATION",
6009 #endif /* _FFR_BESTMX_BETTER_TRUNCATION */
6010 #if _FFR_BLOCK_PROXIES
6012 ** Try to deal with open HTTP proxies that are used to send spam
6013 ** by recognizing some commands from them.
6016 "_FFR_BLOCK_PROXIES",
6017 #endif /* _FFR_BLOCK_PROXIES */
6018 #if _FFR_CATCH_BROKEN_MTAS
6019 /* Deal with MTAs that send a reply during the DATA phase. */
6020 "_FFR_CATCH_BROKEN_MTAS",
6021 #endif /* _FFR_CATCH_BROKEN_MTAS */
6023 /* Enable check_eom ruleset */
6025 #endif /* _FFR_CHECK_EOM */
6027 /* Stricter checks about queue directory permissions. */
6029 #endif /* _FFR_CHK_QUEUE */
6030 #if _FFR_CLIENT_SIZE
6031 /* Don't try to send mail if its size exceeds SIZE= of server. */
6033 #endif /* _FFR_CLIENT_SIZE */
6034 #if _FFR_CONTROL_MSTAT
6035 /* Extended daemon status. */
6036 "_FFR_CONTROL_MSTAT",
6037 #endif /* _FFR_CONTROL_MSTAT */
6039 /* CRLPath; needs documentation; Al Smith */
6041 #endif /* _FFR_CRLPATH */
6042 #if _FFR_DAEMON_NETUNIX
6043 /* Allow local (not just TCP) socket connection to server. */
6044 "_FFR_DAEMON_NETUNIX",
6045 #endif /* _FFR_DAEMON_NETUNIX */
6046 #if _FFR_DEPRECATE_MAILER_FLAG_I
6047 /* What it says :-) */
6048 "_FFR_DEPRECATE_MAILER_FLAG_I",
6049 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
6050 #if _FFR_DIGUNIX_SAFECHOWN
6051 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6052 /* Problem noted by Anne Bennett of Concordia University */
6053 "_FFR_DIGUNIX_SAFECHOWN",
6054 #endif /* _FFR_DIGUNIX_SAFECHOWN */
6055 #if _FFR_DM_PER_DAEMON
6056 /* DeliveryMode per DaemonPortOptions: 'D' */
6057 "_FFR_DM_PER_DAEMON",
6058 #endif /* _FFR_DM_PER_DAEMON */
6059 #if _FFR_DNSMAP_ALIASABLE
6060 /* Allow dns map type to be used for aliases. */
6061 /* Don Lewis of TDK */
6062 "_FFR_DNSMAP_ALIASABLE",
6063 #endif /* _FFR_DNSMAP_ALIASABLE */
6064 #if _FFR_DNSMAP_BASE
6065 /* Specify a "base" domain for DNS lookups. */
6067 #endif /* _FFR_DNSMAP_BASE */
6068 #if _FFR_DNSMAP_MULTI
6069 /* Allow multiple return values for DNS map. */
6070 "_FFR_DNSMAP_MULTI",
6071 # if _FFR_DNSMAP_MULTILIMIT
6072 /* Limit number of return values for DNS map. */
6073 "_FFR_DNSMAP_MULTILIMIT",
6074 # endif /* _FFR_DNSMAP_MULTILIMIT */
6075 #endif /* _FFR_DNSMAP_MULTI */
6076 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6077 /* Enable DontLockFilesForRead option. */
6078 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6079 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
6080 #if _FFR_DOTTED_USERNAMES
6081 /* Allow usernames with '.' */
6082 "_FFR_DOTTED_USERNAMES",
6083 #endif /* _FFR_DOTTED_USERNAMES */
6084 #if _FFR_DROP_TRUSTUSER_WARNING
6086 ** Don't issue this warning:
6087 ** "readcf: option TrustedUser may cause problems on systems
6088 ** which do not support fchown() if UseMSP is not set.
6091 "_FFR_DROP_TRUSTUSER_WARNING",
6092 #endif /* _FFR_DROP_TRUSTUSER_WARNING */
6093 #if _FFR_EXTRA_MAP_CHECK
6094 /* perform extra checks on $( $) in R lines */
6095 "_FFR_EXTRA_MAP_CHECK",
6096 #endif /* _FFR_EXTRA_MAP_CHECK */
6099 ** If using -t, force not sending to argv recipients, even
6100 ** if they are mentioned in the headers.
6104 #endif /* _FFR_FIX_DASHT */
6105 #if _FFR_FORWARD_SYSERR
6106 /* Cause a "syserr" if forward file isn't "safe". */
6107 "_FFR_FORWARD_SYSERR",
6108 #endif /* _FFR_FORWARD_SYSERR */
6110 /* Generate a ORCPT DSN arg if not already provided */
6112 #endif /* _FFR_GEN_ORCPT */
6113 #if _FFR_GROUPREADABLEAUTHINFOFILE
6114 /* Allow group readable DefaultAuthInfo file. */
6115 "_FFR_GROUPREADABLEAUTHINFOFILE",
6116 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
6117 #if _FFR_HANDLE_ISO8859_GECOS
6119 ** Allow ISO 8859 characters in GECOS field: replace them
6120 ** ith ASCII "equivalent".
6123 /* Peter Eriksson of Linkopings universitet */
6124 "_FFR_HANDLE_ISO8859_GECOS",
6125 #endif /* _FFR_HANDLE_ISO8859_GECOS */
6127 /* Set 'h' in {addr_type} for headers. */
6129 #endif /* _FFR_HDR_TYPE */
6131 /* option to set heloname; Nik Clayton of FreeBSD */
6133 #endif /* _FFR_HELONAME */
6134 #if _FFR_HPUX_NSSWITCH
6135 /* Use nsswitch on HP-UX */
6136 "_FFR_HPUX_NSSWITCH",
6137 #endif /* _FFR_HPUX_NSSWITCH */
6138 #if _FFR_IGNORE_BOGUS_ADDR
6139 /* Ignore addresses for which prescan() failed */
6140 "_FFR_IGNORE_BOGUS_ADDR",
6141 #endif /* _FFR_IGNORE_BOGUS_ADDR */
6142 #if _FFR_IGNORE_EXT_ON_HELO
6143 /* Ignore extensions offered in response to HELO */
6144 "_FFR_IGNORE_EXT_ON_HELO",
6145 #endif /* _FFR_IGNORE_EXT_ON_HELO */
6146 #if _FFR_MAXDATASIZE
6148 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6149 ** hence this shouldn't be used as limit for milter communication.
6150 ** see also libmilter/comm.c
6151 ** Gurusamy Sarathy of ActiveState
6155 #endif /* _FFR_MAXDATASIZE */
6156 #if _FFR_MAX_FORWARD_ENTRIES
6157 /* Try to limit number of .forward entries */
6158 /* (doesn't work) */
6159 /* Randall S. Winchester of the University of Maryland */
6160 "_FFR_MAX_FORWARD_ENTRIES",
6161 #endif /* _FFR_MAX_FORWARD_ENTRIES */
6162 #if _FFR_MAX_SLEEP_TIME
6163 /* Limit sleep(2) time in libsm/clock.c */
6164 "_FFR_MAX_SLEEP_TIME",
6165 #endif /* _FFR_MAX_SLEEP_TIME */
6166 #if _FFR_MILTER_NAGLE
6167 /* milter: turn off Nagle ("cork" on Linux) */
6168 /* John Gardiner Myers of Proofpoint */
6169 "_FFR_MILTER_NAGLE ",
6170 #endif /* _FFR_MILTER_NAGLE */
6171 #if _FFR_MILTER_NOHDR_RESP
6172 /* milter: no response expected when sending headers */
6173 /* John Gardiner Myers of Proofpoint */
6174 "_FFR_MILTER_NOHDR_RESP",
6175 #endif /* _FFR_MILTER_NOHDR_RESP */
6176 #if _FFR_MIME7TO8_OLD
6177 /* Old mime7to8 code, the new is broken for at least one example. */
6178 "_FFR_MIME7TO8_OLD",
6179 #endif /* _FFR_MAX_SLEEP_TIME */
6180 #if _FFR_NODELAYDSN_ON_HOLD
6181 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6183 "_FFR_NODELAYDSN_ON_HOLD",
6184 #endif /* _FFR_NODELAYDSN_ON_HOLD */
6186 /* Disable PIPELINING, delay client if used. */
6188 #endif /* _FFR_NO_PIPE */
6190 /* log ntries=, from Nik Clayton of FreeBSD */
6192 #endif /* _FFR_LOG_NTRIES */
6193 #if _FFR_PRIV_NOACTUALRECIPIENT
6195 ** PrivacyOptions=noactualrecipient stops sendmail from putting
6196 ** X-Actual-Recipient lines in DSNs revealing the actual
6197 ** account that addresses map to. Patch from Dan Harkless.
6200 "_FFR_PRIV_NOACTUALRECIPIENT",
6201 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
6203 /* Exponential queue delay; disabled in 8.13 since it isn't used. */
6205 #endif /* _FFR_QUEUEDELAY */
6206 #if _FFR_QUEUE_GROUP_SORTORDER
6207 /* Allow QueueSortOrder per queue group. */
6208 /* XXX: Still need to actually use qgrp->qg_sortorder */
6209 "_FFR_QUEUE_GROUP_SORTORDER",
6210 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
6211 #if _FFR_QUEUE_MACRO
6212 /* Define {queue} macro. */
6214 #endif /* _FFR_QUEUE_MACRO */
6215 #if _FFR_QUEUE_RUN_PARANOIA
6216 /* Additional checks when doing queue runs. */
6217 "_FFR_QUEUE_RUN_PARANOIA",
6218 #endif /* _FFR_QUEUE_RUN_PARANOIA */
6219 #if _FFR_QUEUE_SCHED_DBG
6220 /* Debug output for the queue scheduler. */
6221 "_FFR_QUEUE_SCHED_DBG",
6222 #endif /* _FFR_QUEUE_SCHED_DBG */
6223 #if _FFR_REDIRECTEMPTY
6225 ** envelope <> can't be sent to mailing lists, only owner-
6226 ** send spam of this type to owner- of the list
6227 ** ---- to stop spam from going to mailing lists.
6230 "_FFR_REDIRECTEMPTY",
6231 #endif /* _FFR_REDIRECTEMPTY */
6232 #if _FFR_RESET_MACRO_GLOBALS
6233 /* Allow macro 'j' to be set dynamically via rulesets. */
6234 "_FFR_RESET_MACRO_GLOBALS",
6235 #endif /* _FFR_RESET_MACRO_GLOBALS */
6237 /* Random shuffle for queue sorting. */
6239 #endif /* _FFR_RHS */
6241 /* Auto-select of shared memory key */
6243 #endif /* _FFR_SELECT_SHM */
6245 /* Donated code (unused). */
6247 #endif /* _FFR_SHM_STATUS */
6248 #if _FFR_SKIP_DOMAINS
6249 /* process every N'th domain instead of every N'th message */
6250 "_FFR_SKIP_DOMAINS",
6251 #endif /* _FFR_SKIP_DOMAINS */
6252 #if _FFR_SLEEP_USE_SELECT
6253 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6254 "_FFR_SLEEP_USE_SELECT ",
6255 #endif /* _FFR_SLEEP_USE_SELECT */
6256 #if _FFR_SOFT_BOUNCE
6257 /* Turn all errors into temporary errors. */
6259 #endif /* _FFR_SOFT_BOUNCE */
6262 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6263 ** bit alignment, so unless each piece of argv and envp is a multiple
6264 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6265 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6266 ** if you use this FFR.
6269 /* Chris Adams of HiWAAY Informations Services */
6271 #endif /* _FFR_SPT_ALIGN */
6272 #if _FFR_SS_PER_DAEMON
6273 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6274 "_FFR_SS_PER_DAEMON",
6275 #endif /* _FFR_SS_PER_DAEMON */
6277 /* Donated code (unused). */
6279 #endif /* _FFR_TIMERS */
6281 /* More STARTTLS options, e.g., secondary certs. */
6283 #endif /* _FFR_TLS_1 */
6286 ** If we don't own the file mark it as unsafe.
6287 ** However, allow TrustedUser to own it as well
6288 ** in case TrustedUser manipulates the queue.
6292 #endif /* _FFR_TRUSTED_QF */
6293 #if _FFR_USE_SEM_LOCKING
6294 "_FFR_USE_SEM_LOCKING",
6295 #endif /* _FFR_USE_SEM_LOCKING */
6296 #if _FFR_USE_SETLOGIN
6297 /* Use setlogin() */
6299 "_FFR_USE_SETLOGIN",
6300 #endif /* _FFR_USE_SETLOGIN */