2 * Copyright (c) 1998-2006 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: conf.c,v 8.1081 2006/02/24 02:21:53 ca Exp $")
18 #include <sendmail/pathnames.h>
25 /* for the IPv6 device lookup */
26 # define _SOCKADDR_LEN
28 # endif /* NETINET6 */
31 # include <sys/ioctl.h>
32 # include <sys/param.h>
35 #if NETINET || NETINET6
36 # include <arpa/inet.h>
37 #endif /* NETINET || NETINET6 */
38 #if HASULIMIT && defined(HPUX11)
40 #endif /* HASULIMIT && defined(HPUX11) */
42 static void setupmaps __P((void));
43 static void setupmailers __P((void));
44 static void setupqueues __P((void));
45 static int get_num_procs_online __P((void));
46 static int add_hostnames __P((SOCKADDR *));
48 #if NETINET6 && NEEDSGETIPNODE
49 static struct hostent *getipnodebyname __P((char *, int, int, int *));
50 static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
51 #endif /* NETINET6 && NEEDSGETIPNODE */
55 ** CONF.C -- Sendmail Configuration Tables.
57 ** Defines the configuration of this installation.
59 ** Configuration Variables:
60 ** HdrInfo -- a table describing well-known header fields.
61 ** Each entry has the field name and some flags,
62 ** which are described in sendmail.h.
65 ** I have tried to put almost all the reasonable
66 ** configuration information into the configuration
67 ** file read at runtime. My intent is that anything
68 ** here is a function of the version of UNIX you
69 ** are running, or is really static -- for example
70 ** the headers are a superset of widely used
71 ** protocols. If you find yourself playing with
72 ** this file too much, you may be making a mistake!
78 ** Final (null) entry contains the flags used for any other field.
80 ** Not all of these are actually handled specially by sendmail
81 ** at this time. They are included as placeholders, to let
82 ** you know that "someday" I intend to have sendmail do
83 ** something with them.
86 struct hdrinfo HdrInfo[] =
88 /* originator fields, most to least significant */
89 { "resent-sender", H_FROM|H_RESENT, NULL },
90 { "resent-from", H_FROM|H_RESENT, NULL },
91 { "resent-reply-to", H_FROM|H_RESENT, NULL },
92 { "sender", H_FROM, NULL },
93 { "from", H_FROM, NULL },
94 { "reply-to", H_FROM, NULL },
95 { "errors-to", H_FROM|H_ERRORSTO, NULL },
96 { "full-name", H_ACHECK, NULL },
97 { "return-receipt-to", H_RECEIPTTO, NULL },
98 { "delivery-receipt-to", H_RECEIPTTO, NULL },
99 { "disposition-notification-to", H_FROM, NULL },
101 /* destination fields */
102 { "to", H_RCPT, NULL },
103 { "resent-to", H_RCPT|H_RESENT, NULL },
104 { "cc", H_RCPT, NULL },
105 { "resent-cc", H_RCPT|H_RESENT, NULL },
106 { "bcc", H_RCPT|H_BCC, NULL },
107 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
108 { "apparently-to", H_RCPT, NULL },
110 /* message identification and control */
111 { "message-id", 0, NULL },
112 { "resent-message-id", H_RESENT, NULL },
113 { "message", H_EOH, NULL },
114 { "text", H_EOH, NULL },
118 { "resent-date", H_RESENT, NULL },
121 { "received", H_TRACE|H_FORCE, NULL },
122 { "x400-received", H_TRACE|H_FORCE, NULL },
123 { "via", H_TRACE|H_FORCE, NULL },
124 { "mail-from", H_TRACE|H_FORCE, NULL },
126 /* miscellaneous fields */
127 { "comments", H_FORCE|H_ENCODABLE, NULL },
128 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
129 { "content-transfer-encoding", H_CTE, NULL },
130 { "content-type", H_CTYPE, NULL },
131 { "content-length", H_ACHECK, NULL },
132 { "subject", H_ENCODABLE, NULL },
133 { "x-authentication-warning", H_FORCE, NULL },
144 struct prival PrivacyValues[] =
146 { "public", PRIV_PUBLIC },
147 { "needmailhelo", PRIV_NEEDMAILHELO },
148 { "needexpnhelo", PRIV_NEEDEXPNHELO },
149 { "needvrfyhelo", PRIV_NEEDVRFYHELO },
150 { "noexpn", PRIV_NOEXPN },
151 { "novrfy", PRIV_NOVRFY },
152 { "restrictexpand", PRIV_RESTRICTEXPAND },
153 { "restrictmailq", PRIV_RESTRICTMAILQ },
154 { "restrictqrun", PRIV_RESTRICTQRUN },
155 { "noetrn", PRIV_NOETRN },
156 { "noverb", PRIV_NOVERB },
157 { "authwarnings", PRIV_AUTHWARNINGS },
158 { "noreceipts", PRIV_NORECEIPTS },
159 { "nobodyreturn", PRIV_NOBODYRETN },
160 { "goaway", PRIV_GOAWAY },
161 #if _FFR_PRIV_NOACTUALRECIPIENT
162 { "noactualrecipient", PRIV_NOACTUALRECIPIENT },
163 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
168 ** DontBlameSendmail values
171 struct dbsval DontBlameSendmailValues[] =
173 { "safe", DBS_SAFE },
174 { "assumesafechown", DBS_ASSUMESAFECHOWN },
175 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
176 { "groupwritableforwardfilesafe",
177 DBS_GROUPWRITABLEFORWARDFILESAFE },
178 { "groupwritableincludefilesafe",
179 DBS_GROUPWRITABLEINCLUDEFILESAFE },
180 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
181 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
182 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
183 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
184 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
185 { "linkedaliasfileinwritabledir",
186 DBS_LINKEDALIASFILEINWRITABLEDIR },
187 { "linkedclassfileinwritabledir",
188 DBS_LINKEDCLASSFILEINWRITABLEDIR },
189 { "linkedforwardfileinwritabledir",
190 DBS_LINKEDFORWARDFILEINWRITABLEDIR },
191 { "linkedincludefileinwritabledir",
192 DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
193 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
194 { "linkedserviceswitchfileinwritabledir",
195 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
196 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
197 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
198 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
199 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
200 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
201 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
202 { "forwardfileingroupwritabledirpath",
203 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
204 { "includefileingroupwritabledirpath",
205 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
206 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
207 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
208 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
209 { "forwardfileinunsafedirpathsafe",
210 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
211 { "includefileinunsafedirpathsafe",
212 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
213 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
214 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
215 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
216 { "truststickybit", DBS_TRUSTSTICKYBIT },
217 { "dontwarnforwardfileinunsafedirpath",
218 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
219 { "insufficiententropy", DBS_INSUFFICIENTENTROPY },
220 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
221 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
222 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
223 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
224 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
225 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
226 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
227 #if _FFR_GROUPREADABLEAUTHINFOFILE
228 { "groupreadableadefaultauthinfofile",
229 DBS_GROUPREADABLEAUTHINFOFILE },
230 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
235 ** Miscellaneous stuff.
238 int DtableSize = 50; /* max open files; reset in 4.2bsd */
240 ** SETDEFAULTS -- set default values
242 ** Some of these must be initialized using direct code since they
243 ** depend on run-time values. So let's do all of them this way.
246 ** e -- the default envelope.
252 ** Initializes a bunch of global variables to their
257 #define HOURS * 60 MINUTES
258 #define DAYS * 24 HOURS
260 #ifndef MAXRULERECURSION
261 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
262 #endif /* ! MAXRULERECURSION */
266 register ENVELOPE *e;
272 numprocs = get_num_procs_online();
273 SpaceSub = ' '; /* option B */
274 QueueLA = 8 * numprocs; /* option x */
275 RefuseLA = 12 * numprocs; /* option X */
276 WkRecipFact = 30000L; /* option y */
277 WkClassFact = 1800L; /* option z */
278 WkTimeFact = 90000L; /* option Z */
279 QueueFactor = WkRecipFact * 20; /* option q */
280 QueueMode = QM_NORMAL; /* what queue items to act upon */
281 FileMode = (RealUid != geteuid()) ? 0644 : 0600;
283 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
284 /* option QueueFileMode */
286 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
287 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
288 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
290 DefUid = pw->pw_uid; /* option u */
291 DefGid = pw->pw_gid; /* option g */
292 DefUser = newstr(pw->pw_name);
296 DefUid = 1; /* option u */
297 DefGid = 1; /* option g */
302 sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
303 DefUser != NULL ? DefUser : "<1:1>",
304 (int) DefUid, (int) DefGid);
305 CheckpointInterval = 10; /* option C */
306 MaxHopCount = 25; /* option h */
307 set_delivery_mode(SM_FORK, e); /* option d */
308 e->e_errormode = EM_PRINT; /* option e */
311 e->e_xfqgrp = NOQGRP;
312 e->e_xfqdir = NOQDIR;
313 e->e_ctime = curtime();
314 SevenBitInput = false; /* option 7 */
315 MaxMciCache = 1; /* option k */
316 MciCacheTimeout = 5 MINUTES; /* option K */
317 LogLevel = 9; /* option L */
321 inittimeouts(NULL, false); /* option r */
322 PrivacyFlags = PRIV_PUBLIC; /* option p */
323 MeToo = true; /* option m */
324 SendMIMEErrors = true; /* option f */
325 SuperSafe = SAFE_REALLY; /* option s */
326 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
328 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
330 MimeMode = MM_PASS8BIT;
331 #endif /* MIME8TO7 */
332 for (i = 0; i < MAXTOCLASS; i++)
334 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
335 TimeOuts.to_q_warning[i] = 0; /* option T */
337 ServiceSwitchFile = "/etc/mail/service.switch";
338 ServiceCacheMaxAge = (time_t) 10;
339 HostsFile = _PATH_HOSTS;
340 PidFile = newstr(_PATH_SENDMAILPID);
341 MustQuoteChars = "@,;:\\()[].'";
342 MciInfoTimeout = 30 MINUTES;
343 MaxRuleRecursion = MAXRULERECURSION;
344 MaxAliasRecursion = 10;
345 MaxMacroRecursion = 10;
346 ColonOkInAddr = true;
347 DontLockReadFiles = true;
348 DontProbeInterfaces = DPI_PROBEALL;
349 DoubleBounceAddr = "postmaster";
350 MaxHeadersLength = MAXHDRSLEN;
351 MaxMimeHeaderLength = MAXLINE;
352 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
353 MaxForwardEntries = 0;
355 MaxNOOPCommands = MAXNOOPCOMMANDS;
357 AuthMechanisms = newstr(AUTH_MECHANISMS);
362 TLS_Srv_Opts = TLS_I_SRV;
363 #endif /* STARTTLS */
365 HesiodContext = NULL;
366 #endif /* HESIOD_INIT */
368 /* Detect if IPv6 is available at run time */
369 i = socket(AF_INET6, SOCK_STREAM, 0);
379 #endif /* NETINET6 */
380 ControlSocketName = NULL;
381 memset(&ConnectOnlyTo, '\0', sizeof ConnectOnlyTo);
382 DataFileBufferSize = 4096;
383 XscriptFileBufferSize = 4096;
384 for (i = 0; i < MAXRWSETS; i++)
385 RuleSetNames[i] = NULL;
387 InputFilters[0] = NULL;
389 RejectLogInterval = 3 HOURS;
390 #if REQUIRES_DIR_FSYNC
391 RequiresDirfsync = true;
392 #endif /* REQUIRES_DIR_FSYNC */
393 ConnectionRateWindowSize = 60;
402 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
408 struct passwd *defpwent;
409 static char defuserbuf[40];
411 DefUser = defuserbuf;
412 defpwent = sm_getpwuid(DefUid);
413 (void) sm_strlcpy(defuserbuf,
414 (defpwent == NULL || defpwent->pw_name == NULL)
415 ? "nobody" : defpwent->pw_name,
418 sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
419 (int) DefUid, DefUser);
422 ** SETUPQUEUES -- initialize default queues
424 ** The mqueue QUEUE structure gets filled in after readcf() but
425 ** we need something to point to now for the mailer setup,
426 ** which use "mqueue" as default queue.
434 MaxRunnersPerQueue = 1;
435 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof buf);
436 makequeue(buf, false);
439 ** SETUPMAILERS -- initialize default mailers
447 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
451 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
455 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
461 ** SETUPMAPS -- set up map classes
464 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
466 extern bool parse __P((MAP *, char *)); \
467 extern bool open __P((MAP *, int)); \
468 extern void close __P((MAP *)); \
469 extern char *lookup __P((MAP *, char *, char **, int *)); \
470 extern void store __P((MAP *, char *, char *)); \
471 s = stab(name, ST_MAPCLASS, ST_ENTER); \
472 s->s_mapclass.map_cname = name; \
473 s->s_mapclass.map_ext = ext; \
474 s->s_mapclass.map_cflags = flags; \
475 s->s_mapclass.map_parse = parse; \
476 s->s_mapclass.map_open = open; \
477 s->s_mapclass.map_close = close; \
478 s->s_mapclass.map_lookup = lookup; \
479 s->s_mapclass.map_store = store; \
488 # if DB_VERSION_MAJOR > 1
489 int major_v, minor_v, patch_v;
491 (void) db_version(&major_v, &minor_v, &patch_v);
492 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
495 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
496 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
497 major_v, minor_v, patch_v);
499 # endif /* DB_VERSION_MAJOR > 1 */
501 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
502 map_parseargs, hash_map_open, db_map_close,
503 db_map_lookup, db_map_store);
505 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
506 map_parseargs, bt_map_open, db_map_close,
507 db_map_lookup, db_map_store);
511 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
512 map_parseargs, ndbm_map_open, ndbm_map_close,
513 ndbm_map_lookup, ndbm_map_store);
517 MAPDEF("nis", NULL, MCF_ALIASOK,
518 map_parseargs, nis_map_open, null_map_close,
519 nis_map_lookup, null_map_store);
523 MAPDEF("nisplus", NULL, MCF_ALIASOK,
524 map_parseargs, nisplus_map_open, null_map_close,
525 nisplus_map_lookup, null_map_store);
529 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
530 ldapmap_parseargs, ldapmap_open, ldapmap_close,
531 ldapmap_lookup, null_map_store);
535 MAPDEF("ph", NULL, MCF_NOTPERSIST,
536 ph_map_parseargs, ph_map_open, ph_map_close,
537 ph_map_lookup, null_map_store);
541 /* IRIX 6.5 nsd support */
542 MAPDEF("nsd", NULL, MCF_ALIASOK,
543 map_parseargs, null_map_open, null_map_close,
544 nsd_map_lookup, null_map_store);
548 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
549 map_parseargs, hes_map_open, hes_map_close,
550 hes_map_lookup, null_map_store);
554 MAPDEF("netinfo", NULL, MCF_ALIASOK,
555 map_parseargs, ni_map_open, null_map_close,
556 ni_map_lookup, null_map_store);
560 MAPDEF("dns", NULL, 0,
561 dns_map_init, null_map_open, null_map_close,
562 dns_map_lookup, null_map_store);
567 # if _FFR_DNSMAP_ALIASABLE
568 MAPDEF("dns", NULL, MCF_ALIASOK,
569 dns_map_parseargs, dns_map_open, null_map_close,
570 dns_map_lookup, null_map_store);
571 # else /* _FFR_DNSMAP_ALIASABLE */
572 MAPDEF("dns", NULL, 0,
573 dns_map_parseargs, dns_map_open, null_map_close,
574 dns_map_lookup, null_map_store);
575 # endif /* _FFR_DNSMAP_ALIASABLE */
577 #endif /* NAMED_BIND */
580 /* best MX DNS lookup */
581 MAPDEF("bestmx", NULL, MCF_OPTFILE,
582 map_parseargs, null_map_open, null_map_close,
583 bestmx_map_lookup, null_map_store);
584 #endif /* NAMED_BIND */
586 MAPDEF("host", NULL, 0,
587 host_map_init, null_map_open, null_map_close,
588 host_map_lookup, null_map_store);
590 MAPDEF("text", NULL, MCF_ALIASOK,
591 map_parseargs, text_map_open, null_map_close,
592 text_map_lookup, null_map_store);
594 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
595 map_parseargs, stab_map_open, null_map_close,
596 stab_map_lookup, stab_map_store);
598 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
599 map_parseargs, impl_map_open, impl_map_close,
600 impl_map_lookup, impl_map_store);
602 /* access to system passwd file */
603 MAPDEF("user", NULL, MCF_OPTFILE,
604 map_parseargs, user_map_open, null_map_close,
605 user_map_lookup, null_map_store);
608 MAPDEF("dequote", NULL, 0,
609 dequote_init, null_map_open, null_map_close,
610 dequote_map, null_map_store);
613 MAPDEF("regex", NULL, 0,
614 regex_map_init, null_map_open, null_map_close,
615 regex_map_lookup, null_map_store);
616 #endif /* MAP_REGEX */
620 MAPDEF("userdb", ".db", 0,
621 map_parseargs, null_map_open, null_map_close,
622 udb_map_lookup, null_map_store);
625 /* arbitrary programs */
626 MAPDEF("program", NULL, MCF_ALIASOK,
627 map_parseargs, null_map_open, null_map_close,
628 prog_map_lookup, null_map_store);
631 MAPDEF("sequence", NULL, MCF_ALIASOK,
632 seq_map_parse, null_map_open, null_map_close,
633 seq_map_lookup, seq_map_store);
635 /* switched interface to sequenced maps */
636 MAPDEF("switch", NULL, MCF_ALIASOK,
637 map_parseargs, switch_map_open, null_map_close,
638 seq_map_lookup, seq_map_store);
640 /* null map lookup -- really for internal use only */
641 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
642 map_parseargs, null_map_open, null_map_close,
643 null_map_lookup, null_map_store);
645 /* syslog map -- logs information to syslog */
646 MAPDEF("syslog", NULL, 0,
647 syslog_map_parseargs, null_map_open, null_map_close,
648 syslog_map_lookup, null_map_store);
650 /* macro storage map -- rulesets can set macros */
651 MAPDEF("macro", NULL, 0,
652 dequote_init, null_map_open, null_map_close,
653 macro_map_lookup, null_map_store);
655 /* arithmetic map -- add/subtract/compare */
656 MAPDEF("arith", NULL, 0,
657 dequote_init, null_map_open, null_map_close,
658 arith_map_lookup, null_map_store);
661 /* arbitrary daemons */
662 MAPDEF("socket", NULL, MCF_ALIASOK,
663 map_parseargs, socket_map_open, socket_map_close,
664 socket_map_lookup, null_map_store);
665 #endif /* SOCKETMAP */
669 /* bogus map -- always return tempfail */
670 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
671 map_parseargs, null_map_open, null_map_close,
672 bogus_map_lookup, null_map_store);
678 ** INITHOSTMAPS -- initial host-dependent maps
680 ** This should act as an interface to any local service switch
681 ** provided by the host operating system.
690 ** Should define maps "host" and "users" as necessary
691 ** for this OS. If they are not defined, they will get
692 ** a default value later. It should check to make sure
693 ** they are not defined first, since it's possible that
694 ** the config file has provided an override.
702 char *maptype[MAXMAPSTACK];
703 short mapreturn[MAXMAPACTIONS];
707 ** Set up default hosts maps.
711 nmaps = switch_map_find("hosts", maptype, mapreturn);
712 for (i = 0; i < nmaps; i++)
714 if (strcmp(maptype[i], "files") == 0 &&
715 stab("hosts.files", ST_MAP, ST_FIND) == NULL)
717 (void) sm_strlcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts",
719 (void) makemapentry(buf);
722 else if (strcmp(maptype[i], "dns") == 0 &&
723 stab("hosts.dns", ST_MAP, ST_FIND) == NULL)
725 (void) sm_strlcpy(buf, "hosts.dns dns A", sizeof buf);
726 (void) makemapentry(buf);
728 # endif /* NAMED_BIND */
730 else if (strcmp(maptype[i], "nisplus") == 0 &&
731 stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL)
733 (void) sm_strlcpy(buf, "hosts.nisplus nisplus -k name -v address hosts.org_dir",
735 (void) makemapentry(buf);
737 # endif /* NISPLUS */
739 else if (strcmp(maptype[i], "nis") == 0 &&
740 stab("hosts.nis", ST_MAP, ST_FIND) == NULL)
742 (void) sm_strlcpy(buf, "hosts.nis nis -k 0 -v 1 hosts.byname",
744 (void) makemapentry(buf);
748 else if (strcmp(maptype[i], "netinfo") == 0 &&
749 stab("hosts.netinfo", ST_MAP, ST_FIND) == NULL)
751 (void) sm_strlcpy(buf, "hosts.netinfo netinfo -v name /machines",
753 (void) makemapentry(buf);
755 # endif /* NETINFO */
760 ** Make sure we have a host map.
763 if (stab("host", ST_MAP, ST_FIND) == NULL)
765 /* user didn't initialize: set up host map */
766 (void) sm_strlcpy(buf, "host host", sizeof buf);
768 if (ConfigLevel >= 2)
769 (void) sm_strlcat(buf, " -a. -D", sizeof buf);
770 #endif /* NAMED_BIND */
771 (void) makemapentry(buf);
775 ** Set up default aliases maps
778 nmaps = switch_map_find("aliases", maptype, mapreturn);
779 for (i = 0; i < nmaps; i++)
781 if (strcmp(maptype[i], "files") == 0 &&
782 stab("aliases.files", ST_MAP, ST_FIND) == NULL)
784 (void) sm_strlcpy(buf, "aliases.files null",
786 (void) makemapentry(buf);
789 else if (strcmp(maptype[i], "nisplus") == 0 &&
790 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
792 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
794 (void) makemapentry(buf);
798 else if (strcmp(maptype[i], "nis") == 0 &&
799 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
801 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
803 (void) makemapentry(buf);
807 else if (strcmp(maptype[i], "netinfo") == 0 &&
808 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
810 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
812 (void) makemapentry(buf);
816 else if (strcmp(maptype[i], "hesiod") == 0 &&
817 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
819 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
821 (void) makemapentry(buf);
825 if (stab("aliases", ST_MAP, ST_FIND) == NULL)
827 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof buf);
828 (void) makemapentry(buf);
831 #if 0 /* "user" map class is a better choice */
833 ** Set up default users maps.
836 nmaps = switch_map_find("passwd", maptype, mapreturn);
837 for (i = 0; i < nmaps; i++)
839 if (strcmp(maptype[i], "files") == 0 &&
840 stab("users.files", ST_MAP, ST_FIND) == NULL)
842 (void) sm_strlcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd",
844 (void) makemapentry(buf);
847 else if (strcmp(maptype[i], "nisplus") == 0 &&
848 stab("users.nisplus", ST_MAP, ST_FIND) == NULL)
850 (void) sm_strlcpy(buf, "users.nisplus nisplus -m -kname -vhome passwd.org_dir",
852 (void) makemapentry(buf);
854 # endif /* NISPLUS */
856 else if (strcmp(maptype[i], "nis") == 0 &&
857 stab("users.nis", ST_MAP, ST_FIND) == NULL)
859 (void) sm_strlcpy(buf, "users.nis nis -m passwd.byname",
861 (void) makemapentry(buf);
865 else if (strcmp(maptype[i], "hesiod") == 0 &&
866 stab("users.hesiod", ST_MAP, ST_FIND) == NULL)
868 (void) sm_strlcpy(buf, "users.hesiod hesiod", sizeof buf);
869 (void) makemapentry(buf);
873 if (stab("users", ST_MAP, ST_FIND) == NULL)
875 (void) sm_strlcpy(buf, "users switch -m passwd", sizeof buf);
876 (void) makemapentry(buf);
881 ** SWITCH_MAP_FIND -- find the list of types associated with a map
883 ** This is the system-dependent interface to the service switch.
886 ** service -- the name of the service of interest.
887 ** maptype -- an out-array of strings containing the types
888 ** of access to use for this service. There can
889 ** be at most MAXMAPSTACK types for a single service.
890 ** mapreturn -- an out-array of return information bitmaps
894 ** The number of map types filled in, or -1 for failure.
897 ** Preserves errno so nothing in the routine clobbers it.
900 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
901 # define _USE_SUN_NSSWITCH_
902 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
904 #if _FFR_HPUX_NSSWITCH
906 # define _USE_SUN_NSSWITCH_
908 #endif /* _FFR_HPUX_NSSWITCH */
910 #ifdef _USE_SUN_NSSWITCH_
911 # include <nsswitch.h>
912 #endif /* _USE_SUN_NSSWITCH_ */
914 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
915 # define _USE_DEC_SVC_CONF_
916 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
918 #ifdef _USE_DEC_SVC_CONF_
919 # include <sys/svcinfo.h>
920 #endif /* _USE_DEC_SVC_CONF_ */
923 switch_map_find(service, maptype, mapreturn)
925 char *maptype[MAXMAPSTACK];
926 short mapreturn[MAXMAPACTIONS];
929 int save_errno = errno;
931 #ifdef _USE_SUN_NSSWITCH_
932 struct __nsw_switchconfig *nsw_conf;
933 enum __nsw_parse_err pserr;
934 struct __nsw_lookup *lk;
935 static struct __nsw_lookup lkp0 =
936 { "files", {1, 0, 0, 0}, NULL, NULL };
937 static struct __nsw_switchconfig lkp_default =
938 { 0, "sendmail", 3, &lkp0 };
940 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
941 mapreturn[svcno] = 0;
943 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
944 lk = lkp_default.lookups;
946 lk = nsw_conf->lookups;
948 while (lk != NULL && svcno < MAXMAPSTACK)
950 maptype[svcno] = lk->service_name;
951 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
952 mapreturn[MA_NOTFOUND] |= 1 << svcno;
953 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
954 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
955 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
956 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
962 #endif /* _USE_SUN_NSSWITCH_ */
964 #ifdef _USE_DEC_SVC_CONF_
965 struct svcinfo *svcinfo;
968 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
969 mapreturn[svcno] = 0;
974 if (strcmp(service, "hosts") == 0)
976 else if (strcmp(service, "aliases") == 0)
978 else if (strcmp(service, "passwd") == 0)
985 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
987 switch (svcinfo->svcpath[svc][svcno])
990 maptype[svcno] = "files";
994 maptype[svcno] = "nis";
998 maptype[svcno] = "dns";
1003 maptype[svcno] = "hesiod";
1005 # endif /* SVC_HESIOD */
1014 #endif /* _USE_DEC_SVC_CONF_ */
1016 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
1018 ** Fall-back mechanism.
1022 static time_t servicecachetime; /* time service switch was cached */
1023 time_t now = curtime();
1025 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1026 mapreturn[svcno] = 0;
1028 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
1030 /* (re)read service switch */
1031 register SM_FILE_T *fp;
1032 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
1034 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
1039 servicecachetime = now;
1040 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
1045 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
1046 sizeof buf) != NULL)
1050 p = strpbrk(buf, "#\n");
1053 p = strpbrk(buf, " \t");
1060 sm_syslog(LOG_ERR, NOQID,
1061 "Bad line on %.100s: %.100s",
1072 ** Find/allocate space for this service entry.
1073 ** Space for all of the service strings
1074 ** are allocated at once. This means
1075 ** that we only have to free the first
1076 ** one to free all of them.
1079 st = stab(buf, ST_SERVICE, ST_ENTER);
1080 if (st->s_service[0] != NULL)
1081 sm_free((void *) st->s_service[0]); /* XXX */
1083 for (svcno = 0; svcno < MAXMAPSTACK; )
1087 st->s_service[svcno++] = p;
1088 p = strpbrk(p, " \t");
1095 if (svcno < MAXMAPSTACK)
1096 st->s_service[svcno] = NULL;
1098 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1102 /* look up entry in cache */
1103 st = stab(service, ST_SERVICE, ST_FIND);
1104 if (st != NULL && st->s_service[0] != NULL)
1108 while (svcno < MAXMAPSTACK)
1110 maptype[svcno] = st->s_service[svcno];
1111 if (maptype[svcno++] == NULL)
1117 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1119 #if !defined(_USE_SUN_NSSWITCH_)
1120 /* if the service file doesn't work, use an absolute fallback */
1121 # ifdef _USE_DEC_SVC_CONF_
1123 # endif /* _USE_DEC_SVC_CONF_ */
1124 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1125 mapreturn[svcno] = 0;
1127 if (strcmp(service, "aliases") == 0)
1129 maptype[svcno++] = "files";
1130 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1131 maptype[svcno++] = "netinfo";
1132 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
1133 # ifdef AUTO_NIS_ALIASES
1135 maptype[svcno++] = "nisplus";
1136 # endif /* NISPLUS */
1138 maptype[svcno++] = "nis";
1140 # endif /* AUTO_NIS_ALIASES */
1144 if (strcmp(service, "hosts") == 0)
1147 maptype[svcno++] = "dns";
1148 # else /* NAMED_BIND */
1149 # if defined(sun) && !defined(BSD)
1151 maptype[svcno++] = "nis";
1152 # endif /* defined(sun) && !defined(BSD) */
1153 # endif /* NAMED_BIND */
1154 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1155 maptype[svcno++] = "netinfo";
1156 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
1157 maptype[svcno++] = "files";
1163 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1166 ** USERNAME -- return the user id of the logged in user.
1172 ** The login name of the logged in user.
1178 ** The return value is statically allocated.
1184 static char *myname = NULL;
1185 extern char *getlogin();
1186 register struct passwd *pw;
1188 /* cache the result */
1191 myname = getlogin();
1192 if (myname == NULL || myname[0] == '\0')
1194 pw = sm_getpwuid(RealUid);
1196 myname = pw->pw_name;
1200 uid_t uid = RealUid;
1202 if ((pw = sm_getpwnam(myname)) == NULL ||
1203 (uid != 0 && uid != pw->pw_uid))
1205 pw = sm_getpwuid(uid);
1207 myname = pw->pw_name;
1210 if (myname == NULL || myname[0] == '\0')
1212 syserr("554 5.3.0 Who are you?");
1213 myname = "postmaster";
1215 else if (strpbrk(myname, ",;:/|\"\\") != NULL)
1216 myname = addquotes(myname, NULL);
1218 myname = sm_pstrdup_x(myname);
1223 ** TTYPATH -- Get the path of the user's tty
1225 ** Returns the pathname of the user's tty. Returns NULL if
1226 ** the user is not logged in or if s/he has write permission
1233 ** pathname of the user's tty.
1234 ** NULL if not logged in or write permission denied.
1240 ** Return value is in a local buffer.
1250 register char *pathn;
1251 extern char *ttyname();
1252 extern char *getlogin();
1254 /* compute the pathname of the controlling tty */
1255 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
1256 (pathn = ttyname(0)) == NULL)
1262 /* see if we have write permission */
1263 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
1269 /* see if the user is logged in */
1270 if (getlogin() == NULL)
1277 ** CHECKCOMPAT -- check for From and To person compatible.
1279 ** This routine can be supplied on a per-installation basis
1280 ** to determine whether a person is allowed to send a message.
1281 ** This allows restriction of certain types of internet
1282 ** forwarding or registration of users.
1284 ** If the hosts are found to be incompatible, an error
1285 ** message should be given using "usrerr" and an EX_ code
1286 ** should be returned. You can also set to->q_status to
1287 ** a DSN-style status code.
1289 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1290 ** body during the return-to-sender function; this should be done
1291 ** on huge messages. This bit may already be set by the ESMTP
1295 ** to -- the person being sent to.
1301 ** none (unless you include the usrerr stuff)
1306 register ADDRESS *to;
1307 register ENVELOPE *e;
1310 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1311 to->q_paddr, e->e_from.q_paddr);
1314 /* this code is intended as an example only */
1317 s = stab("arpa", ST_MAILER, ST_FIND);
1318 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
1319 to->q_mailer == s->s_mailer)
1321 usrerr("553 No ARPA mail through this machine: see your system administration");
1322 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1323 to->q_status = "5.7.1";
1324 return EX_UNAVAILABLE;
1326 #endif /* EXAMPLE_CODE */
1330 ** INIT_MD -- do machine dependent initializations
1332 ** Systems that have global modes that should be set should do
1333 ** them here rather than in main.
1337 # include <compat.h>
1338 #endif /* _AUX_SOURCE */
1341 # include <shares.h>
1342 #endif /* SHARE_V1 */
1350 setcompat(getcompat() | COMPAT_BSDPROT);
1351 #endif /* _AUX_SOURCE */
1353 #ifdef SUN_EXTENSIONS
1355 #endif /* SUN_EXTENSIONS */
1358 /* keep gethostby*() from stripping the local domain name */
1359 set_domain_trim_off();
1360 #endif /* _CONVEX_SOURCE */
1363 ** Due to QNX's network distributed nature, you can target a tcpip
1364 ** stack on a different node in the qnx network; this patch lets
1365 ** this feature work. The __sock_locate() must be done before the
1366 ** environment is clear.
1369 #endif /* __QNX__ */
1370 #if SECUREWARE || defined(_SCO_unix_)
1371 set_auth_parameters(argc, argv);
1375 ** This is required for highest security levels (the kernel
1376 ** won't let it call set*uid() or run setuid binaries without
1377 ** it). It may be necessary on other SECUREWARE systems.
1380 if (getluid() == -1)
1382 # endif /* _SCO_unix_ */
1383 #endif /* SECUREWARE || defined(_SCO_unix_) */
1386 #ifdef VENDOR_DEFAULT
1387 VendorCode = VENDOR_DEFAULT;
1388 #else /* VENDOR_DEFAULT */
1389 VendorCode = VENDOR_BERKELEY;
1390 #endif /* VENDOR_DEFAULT */
1393 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1395 ** Called once, on startup.
1398 ** e -- the global envelope.
1404 ** vendor-dependent.
1408 init_vendor_macros(e)
1409 register ENVELOPE *e;
1413 ** GETLA -- get the current load average
1415 ** This code stolen from la.c.
1421 ** The current load average as an integer.
1427 /* try to guess what style of load average we have */
1428 #define LA_ZERO 1 /* always return load average as zero */
1429 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1430 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1431 #define LA_SUBR 4 /* call getloadavg */
1432 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1433 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1434 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1435 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1436 #define LA_DGUX 9 /* special DGUX implementation */
1437 #define LA_HPUX 10 /* special HPUX implementation */
1438 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1439 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1440 #define LA_DEVSHORT 13 /* read short from a device */
1441 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1442 #define LA_PSET 15 /* Solaris per-processor-set load average */
1443 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1445 /* do guesses based on general OS type */
1447 # define LA_TYPE LA_ZERO
1448 #endif /* ! LA_TYPE */
1451 # if defined(unixpc)
1453 # endif /* defined(unixpc) */
1455 # if defined(__alpha) || defined(IRIX)
1457 # endif /* defined(__alpha) || defined(IRIX) */
1459 #endif /* ! FSHIFT */
1463 #endif /* ! FSHIFT */
1466 # define FSCALE (1 << FSHIFT)
1467 #endif /* ! FSCALE */
1471 # define LA_AVENRUN "avenrun"
1472 # else /* SYSTEM5 */
1473 # define LA_AVENRUN "_avenrun"
1474 # endif /* SYSTEM5 */
1475 #endif /* ! LA_AVENRUN */
1477 /* _PATH_KMEM should be defined in <paths.h> */
1479 # define _PATH_KMEM "/dev/kmem"
1480 #endif /* ! _PATH_KMEM */
1482 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1486 /* _PATH_UNIX should be defined in <paths.h> */
1488 # if defined(SYSTEM5)
1489 # define _PATH_UNIX "/unix"
1490 # else /* defined(SYSTEM5) */
1491 # define _PATH_UNIX "/vmunix"
1492 # endif /* defined(SYSTEM5) */
1493 # endif /* ! _PATH_UNIX */
1497 # else /* _AUX_SOURCE */
1503 # endif /* _AUX_SOURCE */
1504 # define X_AVENRUN 0
1510 static int kmem = -1;
1511 # if LA_TYPE == LA_INT
1513 # else /* LA_TYPE == LA_INT */
1514 # if LA_TYPE == LA_SHORT
1517 # if LA_TYPE == LA_LONGLONG
1518 long long avenrun[3];
1519 # else /* LA_TYPE == LA_LONGLONG */
1521 # endif /* LA_TYPE == LA_LONGLONG */
1522 # endif /* LA_TYPE == LA_SHORT */
1523 # endif /* LA_TYPE == LA_INT */
1524 extern off_t lseek();
1529 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
1530 sizeof Nl[X_AVENRUN].n_name);
1531 Nl[1].n_name[0] = '\0';
1532 # endif /* _AUX_SOURCE */
1534 # if defined(_AIX3) || defined(_AIX4)
1535 if (knlist(Nl, 1, sizeof Nl[0]) < 0)
1536 # else /* defined(_AIX3) || defined(_AIX4) */
1537 if (nlist(_PATH_UNIX, Nl) < 0)
1538 # endif /* defined(_AIX3) || defined(_AIX4) */
1541 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
1542 sm_errstring(errno));
1545 if (Nl[X_AVENRUN].n_value == 0)
1548 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1549 _PATH_UNIX, LA_AVENRUN);
1552 # ifdef NAMELISTMASK
1553 Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1554 # endif /* NAMELISTMASK */
1556 kmem = open(_PATH_KMEM, 0, 0);
1560 sm_dprintf("getla: open(/dev/kmem): %s\n",
1561 sm_errstring(errno));
1564 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1565 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1568 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1569 sm_errstring(errno));
1576 sm_dprintf("getla: symbol address = %#lx\n",
1577 (unsigned long) Nl[X_AVENRUN].n_value);
1578 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1579 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1583 sm_dprintf("getla: lseek or read: %s\n",
1584 sm_errstring(errno));
1587 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1590 # if LA_TYPE == LA_SHORT
1591 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1593 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1594 # else /* LA_TYPE == LA_SHORT */
1595 # if LA_TYPE == LA_LONGLONG
1596 sm_dprintf("getla: avenrun = %lld", avenrun[0]);
1598 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
1599 # else /* LA_TYPE == LA_LONGLONG */
1600 sm_dprintf("getla: avenrun = %ld", avenrun[0]);
1602 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
1603 # endif /* LA_TYPE == LA_LONGLONG */
1604 # endif /* LA_TYPE == LA_SHORT */
1608 sm_dprintf("getla: %d\n",
1609 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1610 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1611 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1614 sm_dprintf("getla: avenrun = %g", avenrun[0]);
1616 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
1620 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1621 return ((int) (avenrun[0] + 0.5));
1622 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1625 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1627 #if LA_TYPE == LA_READKSYM
1629 # include <sys/ksym.h>
1635 static int kmem = -1;
1637 struct mioc_rksym mirk;
1641 kmem = open("/dev/kmem", 0, 0);
1645 sm_dprintf("getla: open(/dev/kmem): %s\n",
1646 sm_errstring(errno));
1649 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1650 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1653 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1654 sm_errstring(errno));
1660 mirk.mirk_symname = LA_AVENRUN;
1661 mirk.mirk_buf = avenrun;
1662 mirk.mirk_buflen = sizeof(avenrun);
1663 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
1666 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1667 sm_errstring(errno));
1672 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1674 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1678 sm_dprintf("getla: %d\n",
1679 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1680 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1683 #endif /* LA_TYPE == LA_READKSYM */
1685 #if LA_TYPE == LA_DGUX
1687 # include <sys/dg_sys_info.h>
1692 struct dg_sys_info_load_info load_info;
1694 dg_sys_info((long *)&load_info,
1695 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1698 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1700 return ((int) (load_info.one_minute + 0.5));
1703 #endif /* LA_TYPE == LA_DGUX */
1705 #if LA_TYPE == LA_HPUX
1707 /* forward declarations to keep gcc from complaining */
1712 struct pst_diskinfo;
1713 struct pst_processor;
1715 struct pst_swapinfo;
1717 # include <sys/param.h>
1718 # include <sys/pstat.h>
1723 struct pst_dynamic pstd;
1725 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1726 (size_t) 1, 0) == -1)
1730 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1732 return (int) (pstd.psd_avg_1_min + 0.5);
1735 #endif /* LA_TYPE == LA_HPUX */
1737 #if LA_TYPE == LA_SUBR
1744 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1747 sm_dprintf("getla: getloadavg failed: %s",
1748 sm_errstring(errno));
1752 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1753 return ((int) (avenrun[0] + 0.5));
1756 #endif /* LA_TYPE == LA_SUBR */
1758 #if LA_TYPE == LA_MACH
1761 ** This has been tested on NEXTSTEP release 2.1/3.X.
1764 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1765 # include <mach/mach.h>
1766 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1768 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1773 processor_set_t default_set;
1774 kern_return_t error;
1775 unsigned int info_count;
1776 struct processor_set_basic_info info;
1779 error = processor_set_default(host_self(), &default_set);
1780 if (error != KERN_SUCCESS)
1783 sm_dprintf("getla: processor_set_default failed: %s",
1784 sm_errstring(errno));
1787 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1788 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1789 &host, (processor_set_info_t)&info,
1790 &info_count) != KERN_SUCCESS)
1793 sm_dprintf("getla: processor_set_info failed: %s",
1794 sm_errstring(errno));
1798 sm_dprintf("getla: %d\n",
1799 (int) ((info.load_average + (LOAD_SCALE / 2)) /
1801 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1804 #endif /* LA_TYPE == LA_MACH */
1806 #if LA_TYPE == LA_PROCSTR
1807 # if SM_CONF_BROKEN_STRTOD
1808 ERROR: This OS has most likely a broken strtod() implemenentation.
1809 ERROR: The function is required for getla().
1810 ERROR: Check the compilation options _LA_PROCSTR and
1811 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
1812 # endif /* SM_CONF_BROKEN_STRTOD */
1815 ** Read /proc/loadavg for the load average. This is assumed to be
1816 ** in a format like "0.15 0.12 0.06".
1818 ** Initially intended for Linux. This has been in the kernel
1819 ** since at least 0.99.15.
1822 # ifndef _PATH_LOADAVG
1823 # define _PATH_LOADAVG "/proc/loadavg"
1824 # endif /* ! _PATH_LOADAVG */
1830 register int result;
1833 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
1838 sm_dprintf("getla: sm_io_open(%s): %s\n",
1839 _PATH_LOADAVG, sm_errstring(errno));
1842 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
1843 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1847 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1848 result, sm_errstring(errno));
1853 sm_dprintf("getla(): %.2f\n", avenrun);
1855 return ((int) (avenrun + 0.5));
1858 #endif /* LA_TYPE == LA_PROCSTR */
1860 #if LA_TYPE == LA_IRIX6
1862 # include <sys/sysmp.h>
1865 # define CAST_SYSMP(x) (x)
1866 # else /* _UNICOSMP */
1867 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1868 # endif /* _UNICOSMP */
1874 static int kmem = -1;
1879 kmem = open(_PATH_KMEM, 0, 0);
1883 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
1884 sm_errstring(errno));
1887 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1888 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1891 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1892 sm_errstring(errno));
1899 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
1901 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1904 sm_dprintf("getla: lseek or read: %s\n",
1905 sm_errstring(errno));
1910 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
1912 sm_dprintf(", %ld, %ld",
1913 (long int) avenrun[1], (long int) avenrun[2]);
1918 sm_dprintf("getla: %d\n",
1919 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1920 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1923 #endif /* LA_TYPE == LA_IRIX6 */
1925 #if LA_TYPE == LA_KSTAT
1932 static kstat_ctl_t *kc = NULL;
1933 static kstat_t *ksp = NULL;
1937 if (kc == NULL) /* if not initialized before */
1942 sm_dprintf("getla: kstat_open(): %s\n",
1943 sm_errstring(errno));
1947 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
1951 sm_dprintf("getla: kstat_lookup(): %s\n",
1952 sm_errstring(errno));
1955 if (kstat_read(kc, ksp, NULL) < 0)
1958 sm_dprintf("getla: kstat_read(): %s\n",
1959 sm_errstring(errno));
1962 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
1963 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
1964 /* kstat_close(kc); /o do not close for fast access */
1968 #endif /* LA_TYPE == LA_KSTAT */
1970 #if LA_TYPE == LA_DEVSHORT
1973 ** Read /dev/table/avenrun for the load average. This should contain
1974 ** three shorts for the 1, 5, and 15 minute loads. We only read the
1975 ** first, since that's all we care about.
1977 ** Intended for SCO OpenServer 5.
1980 # ifndef _PATH_AVENRUN
1981 # define _PATH_AVENRUN "/dev/table/avenrun"
1982 # endif /* ! _PATH_AVENRUN */
1987 static int afd = -1;
1994 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
1998 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
2001 sm_syslog(LOG_ERR, NOQID,
2002 "can't open %s: %s",
2003 _PATH_AVENRUN, sm_errstring(errno));
2008 r = read(afd, &avenrun, sizeof avenrun);
2011 sm_dprintf("getla: avenrun = %d\n", avenrun);
2012 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
2014 sm_dprintf("getla: %d\n", loadav);
2018 #endif /* LA_TYPE == LA_DEVSHORT */
2020 #if LA_TYPE == LA_ALPHAOSF
2023 # include <sys/table.h>
2029 struct tbl_loadavg tab;
2031 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
2034 sm_dprintf("getla: table %s\n", sm_errstring(errno));
2039 sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
2042 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
2045 ave = (int) (tab.tl_avenrun.d[2] + 0.5);
2048 sm_dprintf("getla: %d\n", ave);
2053 #endif /* LA_TYPE == LA_ALPHAOSF */
2055 #if LA_TYPE == LA_PSET
2062 if (pset_getloadavg(PS_MYID, avenrun,
2063 sizeof(avenrun) / sizeof(avenrun[0])) < 0)
2066 sm_dprintf("getla: pset_getloadavg failed: %s",
2067 sm_errstring(errno));
2071 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
2072 return ((int) (avenrun[0] + 0.5));
2075 #endif /* LA_TYPE == LA_PSET */
2077 #if LA_TYPE == LA_ZERO
2083 sm_dprintf("getla: ZERO\n");
2087 #endif /* LA_TYPE == LA_ZERO */
2090 * Copyright 1989 Massachusetts Institute of Technology
2092 * Permission to use, copy, modify, distribute, and sell this software and its
2093 * documentation for any purpose is hereby granted without fee, provided that
2094 * the above copyright notice appear in all copies and that both that
2095 * copyright notice and this permission notice appear in supporting
2096 * documentation, and that the name of M.I.T. not be used in advertising or
2097 * publicity pertaining to distribution of the software without specific,
2098 * written prior permission. M.I.T. makes no representations about the
2099 * suitability of this software for any purpose. It is provided "as is"
2100 * without express or implied warranty.
2102 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2103 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2104 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2105 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2106 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2107 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2109 * Authors: Many and varied...
2112 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2114 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2119 # include <apollo/base.h>
2122 int getloadavg( call_data )
2123 caddr_t call_data; /* pointer to (double) return value */
2125 double *avenrun = (double *) call_data;
2130 proc1_$get_loadav(loadav, &st);
2131 *avenrun = loadav[0] / (double) (1 << 16);
2136 ** SM_GETLA -- get the current load average
2145 ** Set CurrentLA to the current load average.
2146 ** Set {load_avg} in GlobalMacros to the current load average.
2154 CurrentLA = getla();
2155 (void) sm_snprintf(labuf, sizeof labuf, "%d", CurrentLA);
2156 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
2159 ** SHOULDQUEUE -- should this message be queued or sent?
2161 ** Compares the message cost to the load average to decide.
2163 ** Note: Do NOT change this API! It is documented in op.me
2164 ** and theoretically the user can change this function...
2167 ** pri -- the priority of the message in question.
2168 ** ct -- the message creation time (unused, but see above).
2171 ** true -- if this message should be queued up for the
2173 ** false -- if the load is low enough to send this message.
2181 shouldqueue(pri, ct)
2188 #endif /* _FFR_MEMSTAT */
2191 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2195 if (QueueLowMem > 0 &&
2196 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2197 memfree < QueueLowMem)
2200 sm_dprintf("true (memfree=%ld < QueueLowMem)\n",
2201 memfree, QueueLowMem);
2204 #endif /* _FFR_MEMSTAT */
2205 if (CurrentLA < QueueLA)
2208 sm_dprintf("false (CurrentLA < QueueLA)\n");
2211 # if 0 /* this code is reported to cause oscillation around RefuseLA */
2212 if (CurrentLA >= RefuseLA && QueueLA < RefuseLA)
2215 sm_dprintf("TRUE (CurrentLA >= RefuseLA)\n");
2219 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
2221 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
2225 ** REFUSECONNECTIONS -- decide if connections should be refused
2228 ** name -- daemon name (for error messages only)
2229 ** e -- the current envelope.
2230 ** d -- number of daemon
2231 ** active -- was this daemon actually active?
2234 ** true if incoming SMTP connections should be refused
2236 ** false if we should accept new work.
2239 ** Sets process title when it is rejecting connections.
2243 refuseconnections(name, e, d, active)
2249 static time_t lastconn[MAXDAEMONS];
2250 static int conncnt[MAXDAEMONS];
2251 static time_t firstrejtime[MAXDAEMONS];
2252 static time_t nextlogtime[MAXDAEMONS];
2255 #endif /* _FFR_MEMSTAT */
2263 SM_ASSERT(d < MAXDAEMONS);
2264 if (ConnRateThrottle > 0)
2271 if (now != lastconn[d])
2276 else if (conncnt[d]++ > ConnRateThrottle)
2278 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2279 /* sleep to flatten out connection load */
2280 sm_setproctitle(true, e, D_MSG_CRT,
2281 name, ConnRateThrottle);
2283 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
2284 name, ConnRateThrottle);
2288 else if (now != lastconn[d])
2294 if (RefuseLowMem > 0 &&
2295 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2296 memfree < RefuseLowMem)
2298 # define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
2299 sm_setproctitle(true, e, R_MSG_LM, name, memfree);
2301 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM, name, memfree);
2304 #endif /* _FFR_MEMSTAT */
2306 if (RefuseLA > 0 && CurrentLA >= RefuseLA)
2310 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2311 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2312 sm_setproctitle(true, e, R_MSG_LA, name, CurrentLA);
2314 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA, name, CurrentLA);
2316 if (firstrejtime[d] == 0)
2318 firstrejtime[d] = now;
2319 nextlogtime[d] = now + RejectLogInterval;
2321 else if (nextlogtime[d] < now)
2323 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, name,
2324 pintvl(now - firstrejtime[d], true));
2325 nextlogtime[d] = now + RejectLogInterval;
2330 firstrejtime[d] = 0;
2332 if (DelayLA > 0 && CurrentLA >= DelayLA)
2335 static time_t log_delay = (time_t) 0;
2337 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2338 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2339 /* sleep to flatten out connection load */
2340 sm_setproctitle(true, e, D_MSG_LA, name, DelayLA);
2341 if (LogLevel > 8 && (now = curtime()) > log_delay)
2343 sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
2344 name, CurrentLA, DelayLA);
2345 log_delay = now + MIN_DELAY_LOG;
2350 if (MaxChildren > 0 && CurChildren >= MaxChildren)
2353 if (CurChildren >= MaxChildren)
2355 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2356 sm_setproctitle(true, e, R_MSG_CHILD,
2357 name, CurChildren, MaxChildren);
2359 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
2360 name, CurChildren, MaxChildren);
2367 ** SETPROCTITLE -- set process title for ps
2370 ** fmt -- a printf style format string.
2371 ** a, b, c -- possible parameters to fmt.
2377 ** Clobbers argv of our main procedure so ps(1) will
2378 ** display the title.
2381 #define SPT_NONE 0 /* don't use it at all */
2382 #define SPT_REUSEARGV 1 /* cover argv with title information */
2383 #define SPT_BUILTIN 2 /* use libc builtin */
2384 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2385 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2386 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2387 #define SPT_SCO 6 /* write kernel u. area */
2388 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2391 # define SPT_TYPE SPT_REUSEARGV
2392 #endif /* ! SPT_TYPE */
2395 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2397 # if SPT_TYPE == SPT_PSTAT
2398 # include <sys/pstat.h>
2399 # endif /* SPT_TYPE == SPT_PSTAT */
2400 # if SPT_TYPE == SPT_PSSTRINGS
2401 # include <machine/vmparam.h>
2402 # include <sys/exec.h>
2403 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2405 # define SPT_TYPE SPT_REUSEARGV
2406 # else /* ! PS_STRINGS */
2407 # ifndef NKPDE /* FreeBSD 2.0 */
2409 typedef unsigned int *pt_entry_t;
2410 # endif /* ! NKPDE */
2411 # endif /* ! PS_STRINGS */
2412 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2414 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2415 # define SETPROC_STATIC static
2416 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2417 # define SETPROC_STATIC
2418 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2420 # if SPT_TYPE == SPT_SYSMIPS
2421 # include <sys/sysmips.h>
2422 # include <sys/sysnews.h>
2423 # endif /* SPT_TYPE == SPT_SYSMIPS */
2425 # if SPT_TYPE == SPT_SCO
2426 # include <sys/immu.h>
2427 # include <sys/dir.h>
2428 # include <sys/user.h>
2429 # include <sys/fs/s5param.h>
2430 # if PSARGSZ > MAXLINE
2431 # define SPT_BUFSIZE PSARGSZ
2432 # endif /* PSARGSZ > MAXLINE */
2433 # endif /* SPT_TYPE == SPT_SCO */
2435 # ifndef SPT_PADCHAR
2436 # define SPT_PADCHAR ' '
2437 # endif /* ! SPT_PADCHAR */
2439 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2442 # define SPT_BUFSIZE MAXLINE
2443 #endif /* ! SPT_BUFSIZE */
2448 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2449 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2450 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2451 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2452 ** you use this FFR.
2455 # ifdef SPT_ALIGN_SIZE
2456 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2457 # else /* SPT_ALIGN_SIZE */
2458 # define SPT_ALIGN(x, align) (x)
2459 # endif /* SPT_ALIGN_SIZE */
2460 #else /* _FFR_SPT_ALIGN */
2461 # define SPT_ALIGN(x, align) (x)
2462 #endif /* _FFR_SPT_ALIGN */
2465 ** Pointers for setproctitle.
2466 ** This allows "ps" listings to give more useful information.
2469 static char **Argv = NULL; /* pointer to argument vector */
2470 static char *LastArgv = NULL; /* end of argv */
2471 #if SPT_TYPE != SPT_BUILTIN
2472 static void setproctitle __P((const char *, ...));
2473 #endif /* SPT_TYPE != SPT_BUILTIN */
2476 initsetproctitle(argc, argv, envp)
2483 extern char **environ;
2486 ** Move the environment so setproctitle can use the space at
2487 ** the top of memory.
2492 for (i = 0; envp[i] != NULL; i++)
2494 environ = (char **) xalloc(sizeof (char *) * (i + 1));
2495 for (i = 0; envp[i] != NULL; i++)
2496 environ[i] = newstr(envp[i]);
2501 ** Save start and extent of argv for setproctitle.
2507 ** Determine how much space we can use for setproctitle.
2508 ** Use all contiguous argv and envp pointers starting at argv[0]
2513 # ifdef SPT_ALIGN_SIZE
2514 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
2516 # endif /* SPT_ALIGN_SIZE */
2517 # endif /* _FFR_SPT_ALIGN */
2519 for (i = 0; i < argc; i++)
2521 if (i == 0 || LastArgv + 1 == argv[i])
2522 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
2524 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
2526 if (LastArgv + 1 == envp[i])
2527 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
2531 #if SPT_TYPE != SPT_BUILTIN
2536 setproctitle(const char *fmt, ...)
2537 # else /* __STDC__ */
2538 setproctitle(fmt, va_alist)
2541 # endif /* __STDC__ */
2543 # if SPT_TYPE != SPT_NONE
2546 SETPROC_STATIC char buf[SPT_BUFSIZE];
2548 # if SPT_TYPE == SPT_PSTAT
2550 # endif /* SPT_TYPE == SPT_PSTAT */
2551 # if SPT_TYPE == SPT_SCO
2554 static int kmem = -1;
2555 static pid_t kmempid = -1;
2557 # endif /* SPT_TYPE == SPT_SCO */
2561 /* print sendmail: heading for grep */
2562 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
2565 /* print the argument string */
2566 SM_VA_START(ap, fmt);
2567 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
2570 i = (int) strlen(buf);
2574 # if SPT_TYPE == SPT_PSTAT
2575 pst.pst_command = buf;
2576 pstat(PSTAT_SETCMD, pst, i, 0, 0);
2577 # endif /* SPT_TYPE == SPT_PSTAT */
2578 # if SPT_TYPE == SPT_PSSTRINGS
2579 PS_STRINGS->ps_nargvstr = 1;
2580 PS_STRINGS->ps_argvstr = buf;
2581 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2582 # if SPT_TYPE == SPT_SYSMIPS
2583 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
2584 # endif /* SPT_TYPE == SPT_SYSMIPS */
2585 # if SPT_TYPE == SPT_SCO
2586 if (kmem < 0 || kmempid != CurrentPid)
2590 kmem = open(_PATH_KMEM, O_RDWR, 0);
2593 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
2594 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
2600 kmempid = CurrentPid;
2602 buf[PSARGSZ - 1] = '\0';
2603 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
2604 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
2605 (void) write(kmem, buf, PSARGSZ);
2606 # endif /* SPT_TYPE == SPT_SCO */
2607 # if SPT_TYPE == SPT_REUSEARGV
2608 if (LastArgv == NULL)
2611 if (i > LastArgv - Argv[0] - 2)
2613 i = LastArgv - Argv[0] - 2;
2616 (void) sm_strlcpy(Argv[0], buf, i + 1);
2618 while (p < LastArgv)
2621 # endif /* SPT_TYPE == SPT_REUSEARGV */
2622 # if SPT_TYPE == SPT_CHANGEARGV
2625 # endif /* SPT_TYPE == SPT_CHANGEARGV */
2626 # endif /* SPT_TYPE != SPT_NONE */
2629 #endif /* SPT_TYPE != SPT_BUILTIN */
2631 ** SM_SETPROCTITLE -- set process task and set process title for ps
2633 ** Possibly set process status and call setproctitle() to
2634 ** change the ps display.
2637 ** status -- whether or not to store as process status
2638 ** e -- the current envelope.
2639 ** fmt -- a printf style format string.
2640 ** a, b, c -- possible parameters to fmt.
2649 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
2650 #else /* __STDC__ */
2651 sm_setproctitle(status, e, fmt, va_alist)
2656 #endif /* __STDC__ */
2658 char buf[SPT_BUFSIZE];
2661 /* print the argument string */
2662 SM_VA_START(ap, fmt);
2663 (void) sm_vsnprintf(buf, sizeof buf, fmt, ap);
2667 proc_list_set(CurrentPid, buf);
2669 if (ProcTitlePrefix != NULL)
2671 char prefix[SPT_BUFSIZE];
2673 expand(ProcTitlePrefix, prefix, sizeof prefix, e);
2674 setproctitle("%s: %s", prefix, buf);
2677 setproctitle("%s", buf);
2680 ** WAITFOR -- wait for a particular process id.
2683 ** pid -- process id to wait for.
2687 ** -1 if pid never shows up.
2705 proc_list_drop(i, st, NULL);
2706 } while ((i >= 0 || errno == EINTR) && i != pid);
2715 ** status -- pointer to status (return value)
2727 # else /* WAITUNION */
2729 # endif /* WAITUNION */
2731 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2733 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2735 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2736 savesig = sm_releasesignal(SIGCHLD);
2737 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2739 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2741 sm_blocksignal(SIGCHLD);
2742 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2744 *status = st.w_status;
2745 # else /* WAITUNION */
2747 # endif /* WAITUNION */
2751 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2754 ** sig -- the signal that got us here (unused).
2760 ** Picks up extant zombies.
2761 ** Control socket exits may restart/shutdown daemon.
2763 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2764 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2773 int save_errno = errno;
2781 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
2786 # else /* HASWAITPID */
2790 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
2792 st = status.w_status;
2793 # else /* WNOHANG */
2797 ** Catch one zombie -- we will be re-invoked (we hope) if there
2798 ** are more. Unreliable signals probably break this, but this
2799 ** is the "old system" situation -- waitpid or wait3 are to be
2800 ** strongly preferred.
2803 if ((pid = wait(&status)) > 0)
2806 # endif /* WNOHANG */
2807 # endif /* HASWAITPID */
2808 /* Drop PID and check if it was a control socket child */
2809 proc_list_drop(pid, st, NULL);
2811 FIX_SYSV_SIGNAL(sig, reapchild);
2813 return SIGFUNC_RETURN;
2816 ** GETDTABLESIZE -- return number of file descriptors
2818 ** Only on non-BSD systems
2824 ** size of file descriptor table
2831 # include <sys/resource.h>
2832 #endif /* SOLARIS */
2837 # ifdef RLIMIT_NOFILE
2840 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
2842 # endif /* RLIMIT_NOFILE */
2844 # if HASGETDTABLESIZE
2845 return getdtablesize();
2846 # else /* HASGETDTABLESIZE */
2847 # ifdef _SC_OPEN_MAX
2848 return sysconf(_SC_OPEN_MAX);
2849 # else /* _SC_OPEN_MAX */
2851 # endif /* _SC_OPEN_MAX */
2852 # endif /* HASGETDTABLESIZE */
2855 ** UNAME -- get the UUCP name of this system.
2862 struct utsname *name;
2867 name->nodename[0] = '\0';
2869 /* try /etc/whoami -- one line with the node name */
2870 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
2871 SM_IO_RDONLY, NULL)) != NULL)
2873 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
2875 (void) sm_io_close(file, SM_TIME_DEFAULT);
2876 n = strchr(name->nodename, '\n');
2879 if (name->nodename[0] != '\0')
2883 /* try /usr/include/whoami.h -- has a #define somewhere */
2884 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
2885 "/usr/include/whoami.h", SM_IO_RDONLY, NULL))
2890 while (sm_io_fgets(file, SM_TIME_DEFAULT,
2891 buf, sizeof buf) != NULL)
2893 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
2894 NODE_LENGTH, name->nodename) > 0)
2897 (void) sm_io_close(file, SM_TIME_DEFAULT);
2898 if (name->nodename[0] != '\0')
2904 #endif /* !HASUNAME */
2906 ** INITGROUPS -- initialize groups
2908 ** Stub implementation for System V style systems
2913 initgroups(name, basegid)
2920 #endif /* !HASINITGROUPS */
2922 ** SETGROUPS -- set group list
2924 ** Stub implementation for systems that don't have group lists
2930 setgroups(ngroups, grouplist)
2932 GIDSET_T grouplist[];
2937 #endif /* ! NGROUPS_MAX */
2939 ** SETSID -- set session id (for non-POSIX systems)
2950 fd = open("/dev/tty", O_RDWR, 0);
2953 (void) ioctl(fd, TIOCNOTTY, (char *) 0);
2956 # endif /* TIOCNOTTY */
2959 # else /* SYS5SETPGRP */
2960 return setpgid(0, CurrentPid);
2961 # endif /* SYS5SETPGRP */
2964 #endif /* !HASSETSID */
2966 ** FSYNC -- dummy fsync
2975 return fcntl(fd, F_SETFL, O_SYNC);
2977 /* nothing we can do */
2979 # endif /* O_SYNC */
2982 #endif /* NEEDFSYNC */
2984 ** DGUX_INET_ADDR -- inet_addr for DG/UX
2986 ** Data General DG/UX version of inet_addr returns a struct in_addr
2987 ** instead of a long. This patches things. Only needed on versions
2996 dgux_inet_addr(host)
2999 struct in_addr haddr;
3001 haddr = inet_addr(host);
3002 return haddr.s_addr;
3005 #endif /* DGUX_5_4_2 */
3007 ** GETOPT -- for old systems or systems with bogus implementations
3013 * Copyright (c) 1985 Regents of the University of California.
3014 * All rights reserved. The Berkeley software License Agreement
3015 * specifies the terms and conditions for redistribution.
3020 ** this version hacked to add `atend' flag to allow state machine
3021 ** to reset if invoked by the program to scan args for a 2nd time
3024 # if defined(LIBC_SCCS) && !defined(lint)
3025 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
3026 # endif /* defined(LIBC_SCCS) && !defined(lint) */
3029 ** get option letter from argument vector
3031 # ifdef _CONVEX_SOURCE
3032 extern int optind, opterr, optopt;
3033 extern char *optarg;
3034 # else /* _CONVEX_SOURCE */
3035 int opterr = 1; /* if error message should be printed */
3036 int optind = 1; /* index into parent argv vector */
3037 int optopt = 0; /* character checked for validity */
3038 char *optarg = NULL; /* argument associated with option */
3039 # endif /* _CONVEX_SOURCE */
3041 # define BADCH (int)'?'
3043 # define tell(s) if (opterr) \
3044 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
3045 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
3046 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
3047 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
3051 getopt(nargc,nargv,ostr)
3056 static char *place = EMSG; /* option letter processing */
3057 static char atend = 0;
3058 register char *oli = NULL; /* option letter list index */
3064 if(!*place) { /* update scanning pointer */
3065 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
3069 if (*place == '-') { /* found "--" */
3074 } /* option letter okay? */
3075 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
3076 if (!*place) ++optind;
3077 tell(": illegal option -- ");
3079 if (oli && *++oli != ':') { /* don't need argument */
3081 if (!*place) ++optind;
3083 else { /* need an argument */
3084 if (*place) optarg = place; /* no white space */
3085 else if (nargc <= ++optind) { /* no arg */
3087 tell(": option requires an argument -- ");
3089 else optarg = nargv[optind]; /* white space */
3093 return optopt; /* dump back option letter */
3096 #endif /* !SM_CONF_GETOPT */
3098 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3101 ** user -- the name of the user we are checking.
3102 ** shell -- the user's shell from /etc/passwd
3105 ** true -- if it is ok to use this for unrestricted access.
3106 ** false -- if the shell is restricted.
3109 #if !HASGETUSERSHELL
3111 # ifndef _PATH_SHELLS
3112 # define _PATH_SHELLS "/etc/shells"
3113 # endif /* ! _PATH_SHELLS */
3115 # if defined(_AIX3) || defined(_AIX4)
3116 # include <userconf.h>
3118 # include <userpw.h>
3119 # endif /* _AIX4 >= 40200 */
3120 # include <usersec.h>
3121 # endif /* defined(_AIX3) || defined(_AIX4) */
3123 static char *DefaultUserShells[] =
3125 "/bin/sh", /* standard shell */
3130 "/bin/csh", /* C shell */
3135 "/usr/bin/rsh", /* restricted Bourne shell */
3136 "/usr/bin/ksh", /* Korn shell */
3137 "/usr/bin/rksh", /* restricted Korn shell */
3139 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3140 "/usr/bin/posix/sh",
3142 "/bin/rsh", /* restricted Bourne shell */
3143 "/bin/ksh", /* Korn shell */
3144 "/bin/rksh", /* restricted Korn shell */
3146 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3150 # endif /* __hpux */
3151 # if defined(_AIX3) || defined(_AIX4)
3152 "/bin/ksh", /* Korn shell */
3154 "/bin/tsh", /* trusted shell */
3156 "/bin/bsh", /* Bourne shell */
3158 # endif /* defined(_AIX3) || defined(_AIX4) */
3159 # if defined(__svr4__) || defined(__svr5__)
3160 "/bin/ksh", /* Korn shell */
3162 # endif /* defined(__svr4__) || defined(__svr5__) */
3164 "/sbin/sh", /* SGI's shells really live in /sbin */
3166 "/sbin/bsh", /* classic Bourne shell */
3169 "/sbin/csh", /* standard csh */
3172 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3175 "/bin/ksh", /* Korn shell */
3178 "/sbin/tcsh", /* Extended csh */
3185 #endif /* !HASGETUSERSHELL */
3187 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3190 usershellok(user, shell)
3194 # if HASGETUSERSHELL
3196 extern char *getusershell();
3198 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3203 while ((p = getusershell()) != NULL)
3204 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
3208 # else /* HASGETUSERSHELL */
3211 # endif /* USEGETCONFATTR */
3212 register SM_FILE_T *shellf;
3215 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3221 ** Naturally IBM has a "better" idea.....
3223 ** What a crock. This interface isn't documented, it is
3224 ** considered part of the security library (-ls), and it
3225 ** only works if you are running as root (since the list
3226 ** of valid shells is obviously a source of great concern).
3227 ** I recommend that you do NOT define USEGETCONFATTR,
3228 ** especially since you are going to have to set up an
3229 ** /etc/shells anyhow to handle the cases where getconfattr
3233 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
3237 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
3243 # endif /* USEGETCONFATTR */
3245 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
3246 SM_IO_RDONLY, NULL);
3249 /* no /etc/shells; see if it is one of the std shells */
3252 if (errno != ENOENT && LogLevel > 3)
3253 sm_syslog(LOG_ERR, NOQID,
3254 "usershellok: cannot open %s: %s",
3255 _PATH_SHELLS, sm_errstring(errno));
3257 for (d = DefaultUserShells; *d != NULL; d++)
3259 if (strcmp(shell, *d) == 0)
3265 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof buf) != NULL)
3267 register char *p, *q;
3270 while (*p != '\0' && *p != '#' && *p != '/')
3272 if (*p == '#' || *p == '\0')
3275 while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
3278 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
3280 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3284 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3286 # endif /* HASGETUSERSHELL */
3289 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3291 ** Only implemented if you have statfs.
3294 ** dir -- the directory in question.
3295 ** bsize -- a variable into which the filesystem
3296 ** block size is stored.
3299 ** The number of blocks free on the queue filesystem.
3300 ** -1 if the statfs call fails.
3303 ** Puts the filesystem block size into bsize.
3307 # define SFS_NONE 0 /* no statfs implementation */
3308 # define SFS_USTAT 1 /* use ustat */
3309 # define SFS_4ARGS 2 /* use four-argument statfs call */
3310 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3311 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3312 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3313 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3316 # define SFS_TYPE SFS_NONE
3317 # endif /* ! SFS_TYPE */
3319 # if SFS_TYPE == SFS_USTAT
3321 # endif /* SFS_TYPE == SFS_USTAT */
3322 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3323 # include <sys/statfs.h>
3324 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
3325 # if SFS_TYPE == SFS_VFS
3326 # include <sys/vfs.h>
3327 # endif /* SFS_TYPE == SFS_VFS */
3328 # if SFS_TYPE == SFS_MOUNT
3329 # include <sys/mount.h>
3330 # endif /* SFS_TYPE == SFS_MOUNT */
3331 # if SFS_TYPE == SFS_STATVFS
3332 # include <sys/statvfs.h>
3333 # endif /* SFS_TYPE == SFS_STATVFS */
3336 freediskspace(dir, bsize)
3340 # if SFS_TYPE == SFS_NONE
3344 /* assume free space is plentiful */
3345 return (long) LONG_MAX;
3346 # else /* SFS_TYPE == SFS_NONE */
3347 # if SFS_TYPE == SFS_USTAT
3349 struct stat statbuf;
3350 # define FSBLOCKSIZE DEV_BSIZE
3351 # define SFS_BAVAIL f_tfree
3352 # else /* SFS_TYPE == SFS_USTAT */
3353 # if defined(ultrix)
3355 # define SFS_BAVAIL fd_bfreen
3356 # define FSBLOCKSIZE 1024L
3357 # else /* defined(ultrix) */
3358 # if SFS_TYPE == SFS_STATVFS
3360 # define FSBLOCKSIZE fs.f_frsize
3361 # else /* SFS_TYPE == SFS_STATVFS */
3363 # define FSBLOCKSIZE fs.f_bsize
3364 # endif /* SFS_TYPE == SFS_STATVFS */
3365 # endif /* defined(ultrix) */
3366 # endif /* SFS_TYPE == SFS_USTAT */
3368 # define SFS_BAVAIL f_bavail
3369 # endif /* ! SFS_BAVAIL */
3371 # if SFS_TYPE == SFS_USTAT
3372 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
3373 # else /* SFS_TYPE == SFS_USTAT */
3374 # if SFS_TYPE == SFS_4ARGS
3375 if (statfs(dir, &fs, sizeof fs, 0) == 0)
3376 # else /* SFS_TYPE == SFS_4ARGS */
3377 # if SFS_TYPE == SFS_STATVFS
3378 if (statvfs(dir, &fs) == 0)
3379 # else /* SFS_TYPE == SFS_STATVFS */
3380 # if defined(ultrix)
3381 if (statfs(dir, &fs) > 0)
3382 # else /* defined(ultrix) */
3383 if (statfs(dir, &fs) == 0)
3384 # endif /* defined(ultrix) */
3385 # endif /* SFS_TYPE == SFS_STATVFS */
3386 # endif /* SFS_TYPE == SFS_4ARGS */
3387 # endif /* SFS_TYPE == SFS_USTAT */
3390 *bsize = FSBLOCKSIZE;
3391 if (fs.SFS_BAVAIL <= 0)
3393 else if (fs.SFS_BAVAIL > LONG_MAX)
3394 return (long) LONG_MAX;
3396 return (long) fs.SFS_BAVAIL;
3399 # endif /* SFS_TYPE == SFS_NONE */
3402 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3405 ** msize -- the size to check against. If zero, we don't yet
3406 ** know how big the message will be, so just check for
3407 ** a "reasonable" amount.
3408 ** e -- envelope, or NULL -- controls logging
3411 ** true if in every queue group there is at least one
3412 ** queue directory whose file system contains enough free space.
3416 ** If there is not enough disk space and e != NULL
3417 ** then sm_syslog is called.
3421 enoughdiskspace(msize, e)
3427 if (MinBlocksFree <= 0 && msize <= 0)
3430 sm_dprintf("enoughdiskspace: no threshold\n");
3435 for (i = 0; i < NumQueue; ++i)
3437 if (pickqdir(Queue[i], msize, e) < 0)
3443 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3445 ** This looks at an errno value and tells if this is likely to
3446 ** go away if retried later.
3449 ** err -- the errno code to classify.
3452 ** true if this is probably transient.
3462 case EIO: /* I/O error */
3463 case ENXIO: /* Device not configured */
3464 case EAGAIN: /* Resource temporarily unavailable */
3465 case ENOMEM: /* Cannot allocate memory */
3466 case ENODEV: /* Operation not supported by device */
3467 case ENFILE: /* Too many open files in system */
3468 case EMFILE: /* Too many open files */
3469 case ENOSPC: /* No space left on device */
3470 case ETIMEDOUT: /* Connection timed out */
3472 case ESTALE: /* Stale NFS file handle */
3475 case ENETDOWN: /* Network is down */
3476 #endif /* ENETDOWN */
3478 case ENETUNREACH: /* Network is unreachable */
3479 #endif /* ENETUNREACH */
3481 case ENETRESET: /* Network dropped connection on reset */
3482 #endif /* ENETRESET */
3484 case ECONNABORTED: /* Software caused connection abort */
3485 #endif /* ECONNABORTED */
3487 case ECONNRESET: /* Connection reset by peer */
3488 #endif /* ECONNRESET */
3490 case ENOBUFS: /* No buffer space available */
3491 #endif /* ENOBUFS */
3493 case ESHUTDOWN: /* Can't send after socket shutdown */
3494 #endif /* ESHUTDOWN */
3496 case ECONNREFUSED: /* Connection refused */
3497 #endif /* ECONNREFUSED */
3499 case EHOSTDOWN: /* Host is down */
3500 #endif /* EHOSTDOWN */
3502 case EHOSTUNREACH: /* No route to host */
3503 #endif /* EHOSTUNREACH */
3505 case EDQUOT: /* Disc quota exceeded */
3508 case EPROCLIM: /* Too many processes */
3509 #endif /* EPROCLIM */
3511 case EUSERS: /* Too many users */
3514 case EDEADLK: /* Resource deadlock avoided */
3515 #endif /* EDEADLK */
3517 case EISCONN: /* Socket already connected */
3518 #endif /* EISCONN */
3520 case EINPROGRESS: /* Operation now in progress */
3521 #endif /* EINPROGRESS */
3523 case EALREADY: /* Operation already in progress */
3524 #endif /* EALREADY */
3526 case EADDRINUSE: /* Address already in use */
3527 #endif /* EADDRINUSE */
3528 #ifdef EADDRNOTAVAIL
3529 case EADDRNOTAVAIL: /* Can't assign requested address */
3530 #endif /* EADDRNOTAVAIL */
3532 case ETXTBSY: /* (Apollo) file locked */
3533 #endif /* ETXTBSY */
3534 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3535 case ENOSR: /* Out of streams resources */
3536 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
3538 case ENOLCK: /* No locks available */
3540 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
3544 /* nope, must be permanent */
3548 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3551 ** fd -- the file descriptor of the file.
3552 ** filename -- the file name (for error messages).
3553 ** ext -- the filename extension.
3554 ** type -- type of the lock. Bits can be:
3555 ** LOCK_EX -- exclusive lock.
3556 ** LOCK_NB -- non-blocking.
3557 ** LOCK_UN -- unlock.
3560 ** true if the lock was acquired.
3565 lockfile(fd, filename, ext, type)
3580 memset(&lfd, '\0', sizeof lfd);
3581 if (bitset(LOCK_UN, type))
3582 lfd.l_type = F_UNLCK;
3583 else if (bitset(LOCK_EX, type))
3584 lfd.l_type = F_WRLCK;
3586 lfd.l_type = F_RDLCK;
3588 if (bitset(LOCK_NB, type))
3594 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
3595 filename, ext, action, lfd.l_type);
3597 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
3602 sm_dprintf("SUCCESS\n");
3608 sm_dprintf("(%s) ", sm_errstring(save_errno));
3611 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3612 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3613 ** as type "tmp" (that is, served from swap space), the
3614 ** previous fcntl will fail with "Invalid argument" errors.
3615 ** Since this is fairly common during testing, we will assume
3616 ** that this indicates that the lock is successfully grabbed.
3619 if (save_errno == EINVAL)
3622 sm_dprintf("SUCCESS\n");
3626 if (!bitset(LOCK_NB, type) ||
3627 (save_errno != EACCES && save_errno != EAGAIN))
3629 int omode = fcntl(fd, F_GETFL, 0);
3630 uid_t euid = geteuid();
3633 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3634 filename, ext, fd, type, omode, euid);
3635 dumpfd(fd, true, true);
3637 # else /* !HASFLOCK */
3642 sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
3644 while ((i = flock(fd, type)) < 0 && errno == EINTR)
3649 sm_dprintf("SUCCESS\n");
3655 sm_dprintf("(%s) ", sm_errstring(save_errno));
3657 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
3659 int omode = fcntl(fd, F_GETFL, 0);
3660 uid_t euid = geteuid();
3663 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3664 filename, ext, fd, type, omode, euid);
3665 dumpfd(fd, true, true);
3667 # endif /* !HASFLOCK */
3669 sm_dprintf("FAIL\n");
3674 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3676 ** Unfortunately, given that we can't predict other systems on which
3677 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3678 ** almost always that this is unsafe.
3680 ** Note also that many operating systems have non-compliant
3681 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3682 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3683 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3684 ** no non-root process can give away the file. However, vendors
3685 ** don't take NFS into account, so a comfortable value of
3686 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3688 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3689 ** even on files where chown is not restricted. Many systems get
3690 ** this wrong on NFS-based filesystems (that is, they say that chown
3691 ** is restricted [safe] on NFS filesystems where it may not be, since
3692 ** other systems can access the same filesystem and do file giveaway;
3693 ** only the NFS server knows for sure!) Hence, it is important to
3694 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3695 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3696 ** NFS-based filesystem to ensure that you can get meaningful results.
3697 ** If in doubt, assume unsafe!
3699 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3700 ** condition indicating whether the return from pathconf indicates
3701 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3702 ** even any agreement about whether a zero return means that a file
3703 ** is or is not safe). It defaults to "> 0".
3705 ** If the parent directory is safe (writable only by owner back
3706 ** to the root) then we can relax slightly and trust fpathconf
3707 ** in more circumstances. This is really a crock -- if this is an
3708 ** NFS mounted filesystem then we really know nothing about the
3709 ** underlying implementation. However, most systems pessimize and
3710 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3711 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3712 ** us into a possible problem only on systems that have a broken
3713 ** pathconf implementation and which are also poorly configured
3714 ** (have :include: files in group- or world-writable directories).
3717 ** fd -- the file descriptor to check.
3718 ** safedir -- set if the parent directory is safe.
3721 ** true -- if the chown(2) operation is "safe" -- that is,
3722 ** only root can chown the file to an arbitrary user.
3723 ** false -- if an arbitrary user can give away a file.
3726 #ifndef IS_SAFE_CHOWN
3727 # define IS_SAFE_CHOWN > 0
3728 #endif /* ! IS_SAFE_CHOWN */
3731 chownsafe(fd, safedir)
3735 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3736 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3739 /* give the system administrator a chance to override */
3740 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
3744 ** Some systems (e.g., SunOS) seem to have the call and the
3745 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3746 ** the call. This heuristic checks for that.
3750 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
3751 # if SAFENFSPATHCONF
3752 return errno == 0 && rval IS_SAFE_CHOWN;
3753 # else /* SAFENFSPATHCONF */
3754 return safedir && errno == 0 && rval IS_SAFE_CHOWN;
3755 # endif /* SAFENFSPATHCONF */
3756 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3757 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
3758 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3761 ** RESETLIMITS -- reset system controlled resource limits
3763 ** This is to avoid denial-of-service attacks
3773 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3774 # include <sm/time.h>
3775 # endif /* RLIMIT_NEEDS_SYS_TIME_H */
3776 # include <sys/resource.h>
3777 #endif /* HASSETRLIMIT */
3785 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
3786 (void) setrlimit(RLIMIT_CPU, &lim);
3787 (void) setrlimit(RLIMIT_FSIZE, &lim);
3788 # ifdef RLIMIT_NOFILE
3789 lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
3790 (void) setrlimit(RLIMIT_NOFILE, &lim);
3791 # endif /* RLIMIT_NOFILE */
3792 #else /* HASSETRLIMIT */
3794 (void) ulimit(2, 0x3fffff);
3795 (void) ulimit(4, FD_SETSIZE);
3796 # endif /* HASULIMIT */
3797 #endif /* HASSETRLIMIT */
3801 ** SETVENDOR -- process vendor code from V configuration line
3804 ** vendor -- string representation of vendor.
3808 ** false -- if vendor code could not be processed.
3811 ** It is reasonable to set mode flags here to tweak
3812 ** processing in other parts of the code if necessary.
3813 ** For example, if you are a vendor that uses $%y to
3814 ** indicate YP lookups, you could enable that here.
3821 if (sm_strcasecmp(vendor, "Berkeley") == 0)
3823 VendorCode = VENDOR_BERKELEY;
3827 /* add vendor extensions here */
3829 #ifdef SUN_EXTENSIONS
3830 if (sm_strcasecmp(vendor, "Sun") == 0)
3832 VendorCode = VENDOR_SUN;
3835 #endif /* SUN_EXTENSIONS */
3837 if (sm_strcasecmp(vendor, "Digital") == 0)
3839 VendorCode = VENDOR_DEC;
3844 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3845 if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
3847 VendorCode = VENDOR_CODE;
3850 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3855 ** GETVENDOR -- return vendor name based on vendor code
3858 ** vendorcode -- numeric representation of vendor.
3861 ** string containing vendor name.
3865 getvendor(vendorcode)
3868 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3870 ** Can't have the same switch case twice so need to
3871 ** handle VENDOR_CODE outside of switch. It might
3872 ** match one of the existing VENDOR_* codes.
3875 if (vendorcode == VENDOR_CODE)
3877 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3881 case VENDOR_BERKELEY:
3893 case VENDOR_SENDMAIL:
3901 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3903 ** Vendor_pre_defaults is called before reading the configuration
3904 ** file; vendor_post_defaults is called immediately after.
3907 ** e -- the global environment to initialize.
3914 int DefShareUid; /* default share uid to run as -- unused??? */
3915 #endif /* SHARE_V1 */
3918 vendor_pre_defaults(e)
3922 /* OTHERUID is defined in shares.h, do not be alarmed */
3923 DefShareUid = OTHERUID;
3924 #endif /* SHARE_V1 */
3925 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3926 sun_pre_defaults(e);
3927 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3930 ** stupid domain/os can't even open
3931 ** /etc/mail/sendmail.cf without this
3934 sm_setuserenv("ISP", NULL);
3935 sm_setuserenv("SYSTYPE", NULL);
3941 vendor_post_defaults(e)
3947 /* Makes sure the SOCK environment variable remains */
3948 if (p = getextenv("SOCK"))
3949 sm_setuserenv("SOCK", p);
3950 #endif /* __QNX__ */
3951 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3952 sun_post_defaults(e);
3953 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3956 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
3960 vendor_daemon_setup(e)
3964 (void) setlogin(RunAsUserName);
3965 #endif /* HASSETLOGIN */
3967 if (getluid() != -1)
3969 usrerr("Daemon cannot have LUID");
3970 finis(false, true, EX_USAGE);
3972 #endif /* SECUREWARE */
3975 ** VENDOR_SET_UID -- do setup for setting a user id
3977 ** This is called when we are still root.
3980 ** uid -- the uid we are about to become.
3991 ** We need to setup the share groups (lnodes)
3992 ** and add auditing information (luid's)
3993 ** before we loose our ``root''ness.
3996 if (setupshares(uid, syserr) != 0)
3997 syserr("Unable to set up shares");
3998 #endif /* SHARE_V1 */
4000 (void) setup_secure(uid);
4001 #endif /* SECUREWARE */
4004 ** VALIDATE_CONNECTION -- check connection for rationality
4006 ** If the connection is rejected, this routine should log an
4007 ** appropriate message -- but should never issue any SMTP protocol.
4010 ** sap -- a pointer to a SOCKADDR naming the peer.
4011 ** hostname -- the name corresponding to sap.
4012 ** e -- the current envelope.
4015 ** error message from rejection.
4016 ** NULL if not rejected.
4022 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
4023 int allow_severity = LOG_INFO;
4024 int deny_severity = LOG_NOTICE;
4025 #endif /* TCPWRAPPERS */
4028 validate_connection(sap, hostname, e)
4036 extern int hosts_ctl();
4037 #endif /* TCPWRAPPERS */
4040 sm_dprintf("validate_connection(%s, %s)\n",
4041 hostname, anynet_ntoa(sap));
4043 connection_rate_check(sap, e);
4044 if (rscheck("check_relay", hostname, anynet_ntoa(sap),
4045 e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID) != EX_OK)
4047 static char reject[BUFSIZ*2];
4048 extern char MsgBuf[];
4051 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
4053 if (strlen(MsgBuf) >= 3)
4054 (void) sm_strlcpy(reject, MsgBuf, sizeof reject);
4056 (void) sm_strlcpy(reject, "Access denied", sizeof reject);
4062 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
4066 addr = anynet_ntoa(sap);
4069 /* TCP/Wrappers don't want the IPv6: protocol label */
4070 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
4072 # endif /* NETINET6 */
4074 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
4077 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4079 sm_syslog(LOG_NOTICE, e->e_id,
4080 "tcpwrappers (%s, %s) rejection",
4082 return "Access denied";
4084 #endif /* TCPWRAPPERS */
4086 sm_dprintf(" ... validate_connection: OK\n");
4091 ** STRTOL -- convert string to long integer
4093 ** For systems that don't have it in the C library.
4095 ** This is taken verbatim from the 4.4-Lite C library.
4100 # if defined(LIBC_SCCS) && !defined(lint)
4101 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4102 # endif /* defined(LIBC_SCCS) && !defined(lint) */
4105 ** Convert a string to a long integer.
4107 ** Ignores `locale' stuff. Assumes that the upper and lower case
4108 ** alphabets and digits are each contiguous.
4112 strtol(nptr, endptr, base)
4117 register const char *s = nptr;
4118 register unsigned long acc;
4120 register unsigned long cutoff;
4121 register int neg = 0, any, cutlim;
4124 ** Skip white space and pick up leading +/- sign if any.
4125 ** If base is 0, allow 0x for hex and 0 for octal, else
4126 ** assume decimal; if base is already 16, allow 0x.
4130 } while (isspace(c));
4134 } else if (c == '+')
4136 if ((base == 0 || base == 16) &&
4137 c == '0' && (*s == 'x' || *s == 'X')) {
4143 base = c == '0' ? 8 : 10;
4146 ** Compute the cutoff value between legal numbers and illegal
4147 ** numbers. That is the largest legal value, divided by the
4148 ** base. An input number that is greater than this value, if
4149 ** followed by a legal input character, is too big. One that
4150 ** is equal to this value may be valid or not; the limit
4151 ** between valid and invalid numbers is then based on the last
4152 ** digit. For instance, if the range for longs is
4153 ** [-2147483648..2147483647] and the input base is 10,
4154 ** cutoff will be set to 214748364 and cutlim to either
4155 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4156 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4157 ** the number is too big, and we will return a range error.
4159 ** Set any if any `digits' consumed; make it negative to indicate
4162 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
4163 cutlim = cutoff % (unsigned long) base;
4164 cutoff /= (unsigned long) base;
4165 for (acc = 0, any = 0;; c = *s++) {
4168 else if (isalpha(c))
4169 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
4174 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
4183 acc = neg ? LONG_MIN : LONG_MAX;
4188 *endptr = (char *)(any ? s - 1 : nptr);
4192 #endif /* NEEDSTRTOL */
4194 ** STRSTR -- find first substring in string
4197 ** big -- the big (full) string.
4198 ** little -- the little (sub) string.
4201 ** A pointer to the first instance of little in big.
4202 ** big if little is the null string.
4203 ** NULL if little is not contained in big.
4213 register char *p = big;
4216 if (*little == '\0')
4220 while ((p = strchr(p, *little)) != NULL)
4222 if (strncmp(p, little, l) == 0)
4229 #endif /* NEEDSTRSTR */
4231 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4233 ** Some operating systems have wierd problems with the gethostbyXXX
4234 ** routines. For example, Solaris versions at least through 2.3
4235 ** don't properly deliver a canonical h_name field. This tries to
4236 ** work around these problems.
4238 ** Support IPv6 as well as IPv4.
4241 #if NETINET6 && NEEDSGETIPNODE
4244 # define AI_DEFAULT 0 /* dummy */
4245 # endif /* ! AI_DEFAULT */
4246 # ifndef AI_ADDRCONFIG
4247 # define AI_ADDRCONFIG 0 /* dummy */
4248 # endif /* ! AI_ADDRCONFIG */
4249 # ifndef AI_V4MAPPED
4250 # define AI_V4MAPPED 0 /* dummy */
4251 # endif /* ! AI_V4MAPPED */
4253 # define AI_ALL 0 /* dummy */
4254 # endif /* ! AI_ALL */
4256 static struct hostent *
4257 getipnodebyname(name, family, flags, err)
4266 if (family == AF_INET6)
4268 /* From RFC2133, section 6.1 */
4269 resv6 = bitset(RES_USE_INET6, _res.options);
4270 _res.options |= RES_USE_INET6;
4273 h = gethostbyname(name);
4275 _res.options &= ~RES_USE_INET6;
4280 static struct hostent *
4281 getipnodebyaddr(addr, len, family, err)
4290 h = gethostbyaddr(addr, len, family);
4300 ** Stub routine -- if they don't have getipnodeby*(),
4301 ** they probably don't have the free routine either.
4306 #endif /* NETINET6 && NEEDSGETIPNODE */
4309 sm_gethostbyname(name, family)
4314 struct hostent *h = NULL;
4315 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4316 # if SOLARIS == 20300 || SOLARIS == 203
4317 static struct hostent hp;
4318 static char buf[1000];
4319 extern struct hostent *_switch_gethostbyname_r();
4322 sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
4323 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
4325 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4326 extern struct hostent *__switch_gethostbyname();
4329 sm_dprintf("__switch_gethostbyname(%s)... ", name);
4330 h = __switch_gethostbyname(name);
4332 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4333 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4336 int flags = AI_DEFAULT|AI_ALL;
4338 # endif /* NETINET6 */
4339 char *maptype[MAXMAPSTACK];
4340 short mapreturn[MAXMAPACTIONS];
4344 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
4347 # if ADDRCONFIG_IS_BROKEN
4348 flags &= ~AI_ADDRCONFIG;
4349 # endif /* ADDRCONFIG_IS_BROKEN */
4350 h = getipnodebyname(name, family, flags, &err);
4351 SM_SET_H_ERRNO(err);
4352 # else /* NETINET6 */
4353 h = gethostbyname(name);
4354 # endif /* NETINET6 */
4360 sm_dprintf("failure\n");
4362 nmaps = switch_map_find("hosts", maptype, mapreturn);
4363 while (--nmaps >= 0)
4365 if (strcmp(maptype[nmaps], "nis") == 0 ||
4366 strcmp(maptype[nmaps], "files") == 0)
4372 /* try short name */
4373 if (strlen(name) > sizeof hbuf - 1)
4378 (void) sm_strlcpy(hbuf, name, sizeof hbuf);
4379 (void) shorten_hostname(hbuf);
4381 /* if it hasn't been shortened, there's no point */
4382 if (strcmp(hbuf, name) != 0)
4385 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4389 h = getipnodebyname(hbuf, family, flags, &err);
4390 SM_SET_H_ERRNO(err);
4392 # else /* NETINET6 */
4393 h = gethostbyname(hbuf);
4395 # endif /* NETINET6 */
4399 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4403 sm_dprintf("failure\n");
4406 sm_dprintf("%s\n", h->h_name);
4410 struct in6_addr ia6;
4411 char buf6[INET6_ADDRSTRLEN];
4412 #else /* NETINET6 */
4414 #endif /* NETINET6 */
4417 if (h->h_aliases != NULL)
4418 for (i = 0; h->h_aliases[i] != NULL;
4420 sm_dprintf("\talias: %s\n",
4422 for (i = 0; h->h_addr_list[i] != NULL; i++)
4427 memmove(&ia6, h->h_addr_list[i],
4429 addr = anynet_ntop(&ia6,
4431 #else /* NETINET6 */
4432 memmove(&ia, h->h_addr_list[i],
4434 addr = (char *) inet_ntoa(ia);
4435 #endif /* NETINET6 */
4437 sm_dprintf("\taddr: %s\n", addr);
4447 sm_gethostbyaddr(addr, len, type)
4455 if (type == AF_INET6 &&
4456 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
4458 /* Avoid reverse lookup for IPv6 unspecified address */
4459 SM_SET_H_ERRNO(HOST_NOT_FOUND);
4462 #endif /* NETINET6 */
4464 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4465 # if SOLARIS == 20300 || SOLARIS == 203
4467 static struct hostent he;
4468 static char buf[1000];
4469 extern struct hostent *_switch_gethostbyaddr_r();
4471 hp = _switch_gethostbyaddr_r(addr, len, type, &he,
4472 buf, sizeof(buf), &h_errno);
4474 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4476 extern struct hostent *__switch_gethostbyaddr();
4478 hp = __switch_gethostbyaddr(addr, len, type);
4480 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4481 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4486 hp = getipnodebyaddr(addr, len, type, &err);
4487 SM_SET_H_ERRNO(err);
4489 # else /* NETINET6 */
4490 hp = gethostbyaddr(addr, len, type);
4491 # endif /* NETINET6 */
4492 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4496 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4504 extern struct passwd *_getpwnam_shadow(const char *, const int);
4506 return _getpwnam_shadow(user, 0);
4508 return getpwnam(user);
4516 #if defined(_AIX4) && 0
4517 extern struct passwd *_getpwuid_shadow(const int, const int);
4519 return _getpwuid_shadow(uid,0);
4520 #else /* defined(_AIX4) && 0 */
4521 return getpwuid(uid);
4522 #endif /* defined(_AIX4) && 0 */
4525 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4527 ** Set up the trusted computing environment for C2 level security
4528 ** under SecureWare.
4531 ** uid -- uid of the user to initialize in the TCB
4537 ** Initialized the user in the trusted computing base
4542 # include <sys/security.h>
4546 secureware_setup_secure(uid)
4551 if (getluid() != -1)
4554 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
4558 case SSI_NO_PRPW_ENTRY:
4559 syserr("No protected passwd entry, uid = %d",
4564 syserr("Account has been disabled, uid = %d",
4569 syserr("Account has been retired, uid = %d",
4573 case SSI_BAD_SET_LUID:
4574 syserr("Could not set LUID, uid = %d", (int) uid);
4577 case SSI_BAD_SET_PRIVS:
4578 syserr("Could not set kernel privs, uid = %d",
4582 syserr("Unknown return code (%d) from set_secure_info(%d)",
4586 finis(false, true, EX_NOPERM);
4589 #endif /* SECUREWARE */
4591 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4593 ** Add hostnames to class 'w' based on the IP address read from
4594 ** the network interface.
4597 ** sa -- a pointer to a SOCKADDR containing the address
4600 ** 0 if successful, -1 if host lookup fails.
4609 char hnb[MAXHOSTNAMELEN];
4611 /* lookup name with IP address */
4612 switch (sa->sa.sa_family)
4616 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
4617 sizeof(sa->sin.sin_addr),
4620 #endif /* NETINET */
4624 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
4625 sizeof(sa->sin6.sin6_addr),
4628 #endif /* NETINET6 */
4631 /* Give warning about unsupported family */
4633 sm_syslog(LOG_WARNING, NOQID,
4634 "Unsupported address family %d: %.100s",
4635 sa->sa.sa_family, anynet_ntoa(sa));
4641 int save_errno = errno;
4645 !(sa->sa.sa_family == AF_INET6 &&
4646 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
4647 #endif /* NETINET6 */
4649 sm_syslog(LOG_WARNING, NOQID,
4650 "gethostbyaddr(%.100s) failed: %d",
4654 #else /* NAMED_BIND */
4656 #endif /* NAMED_BIND */
4662 /* save its cname */
4663 if (!wordinclass((char *) hp->h_name, 'w'))
4665 setclass('w', (char *) hp->h_name);
4667 sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
4669 if (sm_snprintf(hnb, sizeof hnb, "[%s]", hp->h_name) < sizeof hnb
4670 && !wordinclass((char *) hnb, 'w'))
4676 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
4679 /* save all it aliases name */
4680 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
4682 if (!wordinclass(*ha, 'w'))
4686 sm_dprintf("\ta.k.a.: %s\n", *ha);
4687 if (sm_snprintf(hnb, sizeof hnb,
4688 "[%s]", *ha) < sizeof hnb &&
4689 !wordinclass((char *) hnb, 'w'))
4695 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4701 #endif /* NETINET6 */
4705 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4714 ** Loads $=w with the names of all the interfaces.
4718 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4719 #endif /* !NETINET */
4721 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4725 # include <sm/time.h>
4726 # endif /* ! SUNOS403 */
4727 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4729 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
4730 # include <net/if.h>
4731 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4736 # if NETINET6 && defined(SIOCGLIFCONF)
4740 ** Unfortunately, HP has changed all of the structures,
4741 ** making life difficult for implementors.
4744 # define lifconf if_laddrconf
4745 # define lifc_len iflc_len
4746 # define lifc_buf iflc_buf
4747 # define lifreq if_laddrreq
4748 # define lifr_addr iflr_addr
4749 # define lifr_name iflr_name
4750 # define lifr_flags iflr_flags
4751 # define ss_family sa_family
4753 # endif /* __hpux */
4760 struct lifconf lifc;
4763 # endif /* SIOCGLIFNUM */
4765 s = socket(InetMode, SOCK_DGRAM, 0);
4769 /* get the list of known IP address from the kernel */
4771 i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
4772 # endif /* __hpux */
4774 lifn.lifn_family = AF_UNSPEC;
4775 lifn.lifn_flags = 0;
4776 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
4777 numifs = lifn.lifn_count;
4778 # endif /* SIOCGLIFNUM */
4780 # if defined(__hpux) || defined(SIOCGLIFNUM)
4783 /* can't get number of interfaces -- fall back */
4785 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4786 sm_errstring(errno));
4789 else if (tTd(0, 42))
4790 sm_dprintf("system has %d interfaces\n", numifs);
4792 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4793 numifs = MAXINTERFACES;
4801 len = lifc.lifc_len = numifs * sizeof (struct lifreq);
4802 buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
4804 lifc.lifc_family = AF_UNSPEC;
4805 lifc.lifc_flags = 0;
4806 # endif /* ! __hpux */
4807 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
4810 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4811 sm_errstring(errno));
4817 /* scan the list of IP address */
4819 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4822 for (i = 0; i < len && i >= 0; )
4825 struct lifreq *ifr = (struct lifreq *)&buf[i];
4826 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
4827 int af = ifr->lifr_addr.ss_family;
4830 struct in6_addr ia6;
4832 # ifdef SIOCGLIFFLAGS
4834 # endif /* SIOCGLIFFLAGS */
4836 char buf6[INET6_ADDRSTRLEN];
4839 ** We must close and recreate the socket each time
4840 ** since we don't know what type of socket it is now
4841 ** (each status function may change it).
4846 s = socket(af, SOCK_DGRAM, 0);
4849 sm_free(buf); /* XXX */
4854 ** If we don't have a complete ifr structure,
4855 ** don't try to use it.
4858 if ((len - i) < sizeof *ifr)
4861 # ifdef BSD4_4_SOCKADDR
4862 if (sa->sa.sa_len > sizeof ifr->lifr_addr)
4863 i += sizeof ifr->lifr_name + sa->sa.sa_len;
4865 # endif /* BSD4_4_SOCKADDR */
4867 /* fix for IPv6 size differences */
4868 i += sizeof ifr->ifr_name +
4869 max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
4875 sm_dprintf("%s\n", anynet_ntoa(sa));
4877 if (af != AF_INET && af != AF_INET6)
4880 # ifdef SIOCGLIFFLAGS
4881 memset(&ifrf, '\0', sizeof(struct lifreq));
4882 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
4883 sizeof(ifrf.lifr_name));
4884 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
4887 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4888 sm_errstring(errno));
4892 name = ifr->lifr_name;
4893 flags = ifrf.lifr_flags;
4896 sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
4898 if (!bitset(IFF_UP, flags))
4900 # endif /* SIOCGLIFFLAGS */
4904 /* extract IP address from the list*/
4909 /* convert into proper scoped address */
4910 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
4911 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
4912 sa->sin6.sin6_scope_id == 0)
4914 struct in6_addr *ia6p;
4916 ia6p = &sa->sin6.sin6_addr;
4917 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
4918 ((unsigned int)ia6p->s6_addr[2] << 8));
4919 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
4921 # endif /* __KAME__ */
4922 ia6 = sa->sin6.sin6_addr;
4923 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
4925 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
4926 message("WARNING: interface %s is UP with %s address",
4927 name, addr == NULL ? "(NULL)" : addr);
4931 /* save IP address in text from */
4932 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
4934 (void) sm_snprintf(ip_addr, sizeof ip_addr,
4936 (int) sizeof ip_addr - 3,
4941 ia = sa->sin.sin_addr;
4942 if (ia.s_addr == INADDR_ANY ||
4943 ia.s_addr == INADDR_NONE)
4945 message("WARNING: interface %s is UP with %s address",
4946 name, inet_ntoa(ia));
4950 /* save IP address in text from */
4951 (void) sm_snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
4952 (int) sizeof ip_addr - 3, inet_ntoa(ia));
4956 if (*ip_addr == '\0')
4959 if (!wordinclass(ip_addr, 'w'))
4961 setclass('w', ip_addr);
4963 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
4966 # ifdef SIOCGLIFFLAGS
4967 /* skip "loopback" interface "lo" */
4968 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
4969 bitset(IFF_LOOPBACK, flags))
4971 # endif /* SIOCGLIFFLAGS */
4972 (void) add_hostnames(sa);
4974 sm_free(buf); /* XXX */
4976 # else /* NETINET6 && defined(SIOCGLIFCONF) */
4977 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4983 s = socket(AF_INET, SOCK_DGRAM, 0);
4987 /* get the list of known IP address from the kernel */
4988 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
4989 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
4991 /* can't get number of interfaces -- fall back */
4993 sm_dprintf("SIOCGIFNUM failed: %s\n",
4994 sm_errstring(errno));
4997 else if (tTd(0, 42))
4998 sm_dprintf("system has %d interfaces\n", numifs);
5000 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
5001 numifs = MAXINTERFACES;
5008 ifc.ifc_len = numifs * sizeof (struct ifreq);
5009 ifc.ifc_buf = xalloc(ifc.ifc_len);
5010 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
5013 sm_dprintf("SIOCGIFCONF failed: %s\n",
5014 sm_errstring(errno));
5019 /* scan the list of IP address */
5021 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
5024 for (i = 0; i < ifc.ifc_len && i >= 0; )
5027 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
5028 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
5031 struct in6_addr ia6;
5032 # endif /* NETINET6 */
5034 # ifdef SIOCGIFFLAGS
5036 # endif /* SIOCGIFFLAGS */
5039 char buf6[INET6_ADDRSTRLEN];
5040 # endif /* NETINET6 */
5043 ** If we don't have a complete ifr structure,
5044 ** don't try to use it.
5047 if ((ifc.ifc_len - i) < sizeof *ifr)
5050 # ifdef BSD4_4_SOCKADDR
5051 if (sa->sa.sa_len > sizeof ifr->ifr_addr)
5052 i += sizeof ifr->ifr_name + sa->sa.sa_len;
5054 # endif /* BSD4_4_SOCKADDR */
5058 sm_dprintf("%s\n", anynet_ntoa(sa));
5060 af = ifr->ifr_addr.sa_family;
5064 # endif /* NETINET6 */
5068 # ifdef SIOCGIFFLAGS
5069 memset(&ifrf, '\0', sizeof(struct ifreq));
5070 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
5071 sizeof(ifrf.ifr_name));
5072 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
5074 sm_dprintf("\tflags: %lx\n",
5075 (unsigned long) ifrf.ifr_flags);
5076 # define IFRFREF ifrf
5077 # else /* SIOCGIFFLAGS */
5078 # define IFRFREF (*ifr)
5079 # endif /* SIOCGIFFLAGS */
5081 if (!bitset(IFF_UP, IFRFREF.ifr_flags))
5086 /* extract IP address from the list*/
5090 ia = sa->sin.sin_addr;
5091 if (ia.s_addr == INADDR_ANY ||
5092 ia.s_addr == INADDR_NONE)
5094 message("WARNING: interface %s is UP with %s address",
5095 ifr->ifr_name, inet_ntoa(ia));
5099 /* save IP address in text from */
5100 (void) sm_snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
5101 (int) sizeof ip_addr - 3,
5108 /* convert into proper scoped address */
5109 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5110 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5111 sa->sin6.sin6_scope_id == 0)
5113 struct in6_addr *ia6p;
5115 ia6p = &sa->sin6.sin6_addr;
5116 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5117 ((unsigned int)ia6p->s6_addr[2] << 8));
5118 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5120 # endif /* __KAME__ */
5121 ia6 = sa->sin6.sin6_addr;
5122 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5124 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
5125 message("WARNING: interface %s is UP with %s address",
5127 addr == NULL ? "(NULL)" : addr);
5131 /* save IP address in text from */
5132 addr = anynet_ntop(&ia6, buf6, sizeof buf6);
5134 (void) sm_snprintf(ip_addr, sizeof ip_addr,
5136 (int) sizeof ip_addr - 3,
5140 # endif /* NETINET6 */
5143 if (ip_addr[0] == '\0')
5146 if (!wordinclass(ip_addr, 'w'))
5148 setclass('w', ip_addr);
5150 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5153 /* skip "loopback" interface "lo" */
5154 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5155 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
5158 (void) add_hostnames(sa);
5160 sm_free(ifc.ifc_buf); /* XXX */
5163 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5164 # endif /* NETINET6 && defined(SIOCGLIFCONF) */
5167 ** ISLOOPBACK -- is socket address in the loopback net?
5170 ** sa -- socket address.
5173 ** true -- is socket address in the loopback net?
5174 ** false -- otherwise
5183 if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
5185 #else /* NETINET6 */
5186 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5187 if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
5188 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
5190 #endif /* NETINET6 */
5194 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5200 ** The number of processors online.
5204 get_num_procs_online()
5209 # if defined(CTL_HW) && defined(HW_NCPU)
5215 sz = (size_t) sizeof nproc;
5216 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
5217 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5218 #else /* USESYSCTL */
5219 # ifdef _SC_NPROCESSORS_ONLN
5220 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
5221 # else /* _SC_NPROCESSORS_ONLN */
5223 # include <sys/pstat.h>
5224 struct pst_dynamic psd;
5226 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
5227 nproc = psd.psd_proc_cnt;
5228 # endif /* __hpux */
5229 # endif /* _SC_NPROCESSORS_ONLN */
5230 #endif /* USESYSCTL */
5237 ** SM_CLOSEFROM -- close file descriptors
5240 ** lowest -- first fd to close
5241 ** highest -- last fd + 1 to close
5248 sm_closefrom(lowest, highest)
5249 int lowest, highest;
5253 #else /* HASCLOSEFROM */
5256 for (i = lowest; i < highest; i++)
5258 #endif /* HASCLOSEFROM */
5262 ** CLOSEFD_WALK -- walk fd's arranging to close them
5263 ** Callback for fdwalk()
5266 ** lowest -- first fd to arrange to be closed
5267 ** fd -- fd to arrange to be closed
5274 closefd_walk(lowest, fd)
5278 if (fd >= *(int *)lowest)
5279 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
5282 #endif /* HASFDWALK */
5284 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5287 ** lowest -- first fd to arrange to be closed
5288 ** highest -- last fd + 1 to arrange to be closed
5295 sm_close_on_exec(highest, lowest)
5296 int highest, lowest;
5299 (void) fdwalk(closefd_walk, &lowest);
5300 #else /* HASFDWALK */
5303 for (i = lowest; i < highest; i++)
5305 if ((j = fcntl(i, F_GETFD, 0)) != -1)
5306 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
5308 #endif /* HASFDWALK */
5311 ** SEED_RANDOM -- seed the random number generator
5325 #else /* HASSRANDOMDEV */
5329 seed = (long) CurrentPid;
5330 if (gettimeofday(&t, NULL) >= 0)
5331 seed += t.tv_sec + t.tv_usec;
5334 (void) srandom(seed);
5335 # else /* HASRANDOM */
5336 (void) srand((unsigned int) seed);
5337 # endif /* HASRANDOM */
5338 #endif /* HASSRANDOMDEV */
5341 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5344 ** level -- syslog level
5345 ** id -- envelope ID or NULL (NOQUEUE)
5346 ** fmt -- format string
5347 ** arg... -- arguments as implied by fmt.
5356 sm_syslog(int level, const char *id, const char *fmt, ...)
5357 #else /* __STDC__ */
5358 sm_syslog(level, id, fmt, va_alist)
5363 #endif /* __STDC__ */
5373 extern int SyslogPrefixLen;
5380 idlen = strlen(id) + SyslogPrefixLen;
5382 else if (strcmp(id, NOQID) == 0)
5385 idlen = SyslogPrefixLen;
5388 idlen = strlen(id) + SyslogPrefixLen;
5391 bufsize = sizeof buf0;
5397 /* print log message into buf */
5398 SM_VA_START(ap, fmt);
5399 n = sm_vsnprintf(buf, bufsize, fmt, ap);
5405 /* String too small, redo with correct size */
5412 buf = sm_malloc_x(bufsize);
5415 /* clean up buf after it has been expanded with args */
5416 newstring = str2prt(buf);
5417 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
5421 syslog(level, "%s", newstring);
5423 syslog(level, "%s: %s", id, newstring);
5425 /*XXX should do something more sensible */
5427 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
5430 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5431 "%s: %s\n", id, newstring);
5440 ** additional length for splitting: " ..." + 3, where 3 is magic to
5441 ** have some data for the next entry.
5447 idlen += 5; /* strlen("[999]"), see below */
5448 while (*begin != '\0' &&
5449 (strlen(begin) + idlen) > SYSLOG_BUFSIZE)
5455 /* Too many messages */
5458 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5461 /* Break on comma or space */
5462 if (*end == ',' || *end == ' ')
5464 end++; /* Include separator */
5469 /* No separator, break midstring... */
5471 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5475 syslog(level, "%s[%d]: %s ...", id, seq++, begin);
5477 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5478 "%s[%d]: %s ...\n", id, seq++, begin);
5485 syslog(level, "%s[%d]: log terminated, too many parts",
5488 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5489 "%s[%d]: log terminated, too many parts\n", id, seq);
5491 else if (*begin != '\0')
5493 syslog(level, "%s[%d]: %s", id, seq, begin);
5495 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5496 "%s[%d]: %s\n", id, seq, begin);
5503 ** HARD_SYSLOG -- call syslog repeatedly until it works
5505 ** Needed on HP-UX, which apparently doesn't guarantee that
5506 ** syslog succeeds during interrupt handlers.
5509 #if defined(__hpux) && !defined(HPUX11)
5511 # define MAXSYSLOGTRIES 100
5514 # define XCNST const
5515 # define CAST (const char *)
5523 hard_syslog(int pri, XCNST char *msg, ...)
5524 # else /* __STDC__ */
5525 hard_syslog(pri, msg, va_alist)
5529 # endif /* __STDC__ */
5532 char buf[SYSLOG_BUFSIZE];
5535 SM_VA_START(ap, msg);
5536 (void) sm_vsnprintf(buf, sizeof buf, msg, ap);
5539 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
5544 #endif /* defined(__hpux) && !defined(HPUX11) */
5545 #if NEEDLOCAL_HOSTNAME_LENGTH
5547 ** LOCAL_HOSTNAME_LENGTH
5549 ** This is required to get sendmail to compile against BIND 4.9.x
5552 ** Unfortunately, a Compaq Y2K patch kit provides it without
5553 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5554 ** figure out whether it is needed.
5558 local_hostname_length(hostname)
5561 size_t len_host, len_domain;
5563 if (!*_res.defdname)
5565 len_host = strlen(hostname);
5566 len_domain = strlen(_res.defdname);
5567 if (len_host > len_domain &&
5568 (sm_strcasecmp(hostname + len_host - len_domain,
5569 _res.defdname) == 0) &&
5570 hostname[len_host - len_domain - 1] == '.')
5571 return len_host - len_domain - 1;
5575 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5579 ** LINK -- clone a file
5581 ** Some OS's lacks link() and hard links. Since sendmail is using
5582 ** link() as an efficient way to clone files, this implementation
5583 ** will simply do a file copy.
5585 ** NOTE: This link() replacement is not a generic replacement as it
5586 ** does not handle all of the semantics of the real link(2).
5589 ** source -- pathname of existing file.
5590 ** target -- pathname of link (clone) to be created.
5594 ** -1 -- failure, see errno for details.
5598 link(source, target)
5604 int src = -1, dst = -1;
5610 sff = SFF_REGONLY|SFF_OPENASROOT;
5611 if (DontLockReadFiles)
5614 /* Open the original file */
5615 src = safeopen((char *)source, O_RDONLY, 0, sff);
5619 /* Obtain the size and the mode */
5620 if (fstat(src, &st) < 0)
5623 /* Create the duplicate copy */
5626 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
5631 /* Copy all of the bytes one buffer at a time */
5632 while ((readlen = read(src, &buf, sizeof(buf))) > 0)
5634 ssize_t left = readlen;
5638 (writelen = write(dst, p, (size_t) left)) >= 0)
5647 /* Any trouble reading? */
5648 if (readlen < 0 || writelen < 0)
5651 /* Close the input file */
5659 /* Close the output file */
5662 /* don't set dst = -1 here so we unlink the file */
5675 (void) unlink(target);
5681 #endif /* NEEDLINK */
5684 ** Compile-Time options
5687 char *CompileOptions[] =
5691 #endif /* ALLOW_255 */
5695 # endif /* DNSMAP */
5696 #endif /* NAMED_BIND */
5705 #endif /* HES_GETMAILHOST */
5708 #endif /* LDAPMAP */
5711 #endif /* LDAP_REFERRALS */
5717 #endif /* MAP_NSD */
5720 #endif /* MAP_REGEX */
5723 #endif /* MATCHGECOS */
5729 #endif /* MIME7TO8 */
5732 #endif /* MIME7TO8_OLD */
5735 #endif /* MIME8TO7 */
5738 #endif /* NAMED_BIND */
5744 #endif /* NETINET */
5747 #endif /* NETINET6 */
5750 #endif /* NETINFO */
5759 #endif /* NETUNIX */
5771 #endif /* NISPLUS */
5778 #ifdef PICKY_HELO_CHECK
5780 #endif /* PICKY_HELO_CHECK */
5783 #endif /* PIPELINING */
5787 # else /* SASL >= 20000 */
5789 # endif /* SASL >= 20000 */
5796 #endif /* SMTPDEBUG */
5799 #endif /* SOCKETMAP */
5802 #endif /* STARTTLS */
5803 #if SUID_ROOT_FILES_OK
5804 "SUID_ROOT_FILES_OK",
5805 #endif /* SUID_ROOT_FILES_OK */
5808 #endif /* TCPWRAPPERS */
5811 #endif /* TLS_NO_RSA */
5812 #if TLS_VRFY_PER_CTX
5814 #endif /* TLS_VRFY_PER_CTX */
5820 #endif /* USE_LDAP_INIT */
5823 #endif /* USE_TTYPATH */
5835 ** OS compile options.
5838 char *OsCompileOptions[] =
5840 #if ADDRCONFIG_IS_BROKEN
5841 "ADDRCONFIG_IS_BROKEN",
5842 #endif /* ADDRCONFIG_IS_BROKEN */
5843 #ifdef AUTO_NETINFO_HOSTS
5844 "AUTO_NETINFO_HOSTS",
5845 #endif /* AUTO_NETINFO_HOSTS */
5846 #ifdef AUTO_NIS_ALIASES
5848 #endif /* AUTO_NIS_ALIASES */
5849 #if BROKEN_RES_SEARCH
5850 "BROKEN_RES_SEARCH",
5851 #endif /* BROKEN_RES_SEARCH */
5852 #ifdef BSD4_4_SOCKADDR
5854 #endif /* BSD4_4_SOCKADDR */
5857 #endif /* BOGUS_O_EXCL */
5858 #if DEC_OSF_BROKEN_GETPWENT
5859 "DEC_OSF_BROKEN_GETPWENT",
5860 #endif /* DEC_OSF_BROKEN_GETPWENT */
5861 #if FAST_PID_RECYCLE
5863 #endif /* FAST_PID_RECYCLE */
5866 #endif /* HASCLOSEFROM */
5869 #endif /* HASFCHOWN */
5872 #endif /* HASFCHMOD */
5875 #endif /* HASFDWALK */
5878 #endif /* HASFLOCK */
5879 #if HASGETDTABLESIZE
5881 #endif /* HASGETDTABLESIZE */
5884 #endif /* HASGETUSERSHELL */
5887 #endif /* HASINITGROUPS */
5890 #endif /* HASLSTAT */
5893 #endif /* HASNICE */
5896 #endif /* HASRANDOM */
5899 #endif /* HASRRESVPORT */
5902 #endif /* HASSETEGID */
5905 #endif /* HASSETLOGIN */
5908 #endif /* HASSETREGID */
5911 #endif /* HASSETRESGID */
5914 #endif /* HASSETREUID */
5917 #endif /* HASSETRLIMIT */
5920 #endif /* HASSETSID */
5921 #if HASSETUSERCONTEXT
5922 "HASSETUSERCONTEXT",
5923 #endif /* HASSETUSERCONTEXT */
5926 #endif /* HASSETVBUF */
5929 #endif /* HAS_ST_GEN */
5932 #endif /* HASSRANDOMDEV */
5935 #endif /* HASURANDOMDEV */
5938 #endif /* HASSTRERROR */
5941 #endif /* HASULIMIT */
5944 #endif /* HASUNAME */
5947 #endif /* HASUNSETENV */
5950 #endif /* HASWAITPID */
5953 #endif /* IDENTPROTO */
5956 #endif /* IP_SRCROUTE */
5957 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
5959 #endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */
5962 #endif /* NEEDFSYNC */
5965 #endif /* NEEDLINK */
5966 #if NEEDLOCAL_HOSTNAME_LENGTH
5967 "NEEDLOCAL_HOSTNAME_LENGTH",
5968 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5971 #endif /* NEEDSGETIPNODE */
5974 #endif /* NEEDSTRSTR */
5977 #endif /* NEEDSTRTOL */
5978 #ifdef NO_GETSERVBYNAME
5980 #endif /* NO_GETSERVBYNAME */
5983 #endif /* NOFTRUNCATE */
5984 #if REQUIRES_DIR_FSYNC
5985 "REQUIRES_DIR_FSYNC",
5986 #endif /* REQUIRES_DIR_FSYNC */
5987 #if RLIMIT_NEEDS_SYS_TIME_H
5988 "RLIMIT_NEEDS_SYS_TIME_H",
5989 #endif /* RLIMIT_NEEDS_SYS_TIME_H */
5992 #endif /* SAFENFSPATHCONF */
5995 #endif /* SECUREWARE */
5998 #endif /* SHARE_V1 */
5999 #if SIOCGIFCONF_IS_BROKEN
6000 "SIOCGIFCONF_IS_BROKEN",
6001 #endif /* SIOCGIFCONF_IS_BROKEN */
6002 #if SIOCGIFNUM_IS_BROKEN
6003 "SIOCGIFNUM_IS_BROKEN",
6004 #endif /* SIOCGIFNUM_IS_BROKEN */
6005 #if SNPRINTF_IS_BROKEN
6006 "SNPRINTF_IS_BROKEN",
6007 #endif /* SNPRINTF_IS_BROKEN */
6008 #if SO_REUSEADDR_IS_BROKEN
6009 "SO_REUSEADDR_IS_BROKEN",
6010 #endif /* SO_REUSEADDR_IS_BROKEN */
6013 #endif /* SYS5SETPGRP */
6016 #endif /* SYSTEM5 */
6019 #endif /* USE_DOUBLE_FORK */
6022 #endif /* USE_ENVIRON */
6023 #if USE_SA_SIGACTION
6025 #endif /* USE_SA_SIGACTION */
6028 #endif /* USE_SIGLONGJMP */
6031 #endif /* USEGETCONFATTR */
6034 #endif /* USESETEUID */
6037 #endif /* USESYSCTL */
6038 #if USING_NETSCAPE_LDAP
6039 "USING_NETSCAPE_LDAP",
6040 #endif /* USING_NETSCAPE_LDAP */
6043 #endif /* WAITUNION */
6048 ** FFR compile options.
6051 char *FFRCompileOptions[] =
6053 #if _FFR_ALLOW_SASLINFO
6054 /* DefaultAuthInfo can be specified by user. */
6055 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */
6056 "_FFR_ALLOW_SASLINFO",
6057 #endif /* _FFR_ALLOW_SASLINFO */
6058 #if _FFR_BESTMX_BETTER_TRUNCATION
6059 /* Better truncation of list of MX records for dns map. */
6060 "_FFR_BESTMX_BETTER_TRUNCATION",
6061 #endif /* _FFR_BESTMX_BETTER_TRUNCATION */
6062 #if _FFR_BLOCK_PROXIES
6064 ** Try to deal with open HTTP proxies that are used to send spam
6065 ** by recognizing some commands from them.
6068 "_FFR_BLOCK_PROXIES",
6069 #endif /* _FFR_BLOCK_PROXIES */
6070 #if _FFR_CATCH_BROKEN_MTAS
6071 /* Deal with MTAs that send a reply during the DATA phase. */
6072 "_FFR_CATCH_BROKEN_MTAS",
6073 #endif /* _FFR_CATCH_BROKEN_MTAS */
6075 /* Enable check_eom ruleset */
6077 #endif /* _FFR_CHECK_EOM */
6079 /* Stricter checks about queue directory permissions. */
6081 #endif /* _FFR_CHK_QUEUE */
6082 #if _FFR_CLIENT_SIZE
6083 /* Don't try to send mail if its size exceeds SIZE= of server. */
6085 #endif /* _FFR_CLIENT_SIZE */
6086 #if _FFR_CONTROL_MSTAT
6087 /* Extended daemon status. */
6088 "_FFR_CONTROL_MSTAT",
6089 #endif /* _FFR_CONTROL_MSTAT */
6091 /* CRLPath; needs documentation; Al Smith */
6093 #endif /* _FFR_CRLPATH */
6094 #if _FFR_DAEMON_NETUNIX
6095 /* Allow local (not just TCP) socket connection to server. */
6096 "_FFR_DAEMON_NETUNIX",
6097 #endif /* _FFR_DAEMON_NETUNIX */
6098 #if _FFR_DEPRECATE_MAILER_FLAG_I
6099 /* What it says :-) */
6100 "_FFR_DEPRECATE_MAILER_FLAG_I",
6101 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
6103 /* deliver first TA in background, then queue */
6105 #endif /* _FFR_DM_ONE */
6106 #if _FFR_DIGUNIX_SAFECHOWN
6107 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6108 /* Problem noted by Anne Bennett of Concordia University */
6109 "_FFR_DIGUNIX_SAFECHOWN",
6110 #endif /* _FFR_DIGUNIX_SAFECHOWN */
6111 #if _FFR_DM_PER_DAEMON
6112 /* DeliveryMode per DaemonPortOptions: 'D' */
6113 "_FFR_DM_PER_DAEMON",
6114 #endif /* _FFR_DM_PER_DAEMON */
6115 #if _FFR_DNSMAP_ALIASABLE
6116 /* Allow dns map type to be used for aliases. */
6117 /* Don Lewis of TDK */
6118 "_FFR_DNSMAP_ALIASABLE",
6119 #endif /* _FFR_DNSMAP_ALIASABLE */
6120 #if _FFR_DNSMAP_BASE
6121 /* Specify a "base" domain for DNS lookups. */
6123 #endif /* _FFR_DNSMAP_BASE */
6124 #if _FFR_DNSMAP_MULTI
6125 /* Allow multiple return values for DNS map. */
6126 "_FFR_DNSMAP_MULTI",
6127 # if _FFR_DNSMAP_MULTILIMIT
6128 /* Limit number of return values for DNS map. */
6129 "_FFR_DNSMAP_MULTILIMIT",
6130 # endif /* _FFR_DNSMAP_MULTILIMIT */
6131 #endif /* _FFR_DNSMAP_MULTI */
6132 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6133 /* Enable DontLockFilesForRead option. */
6134 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6135 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
6136 #if _FFR_DOTTED_USERNAMES
6137 /* Allow usernames with '.' */
6138 "_FFR_DOTTED_USERNAMES",
6139 #endif /* _FFR_DOTTED_USERNAMES */
6140 #if _FFR_DROP_TRUSTUSER_WARNING
6142 ** Don't issue this warning:
6143 ** "readcf: option TrustedUser may cause problems on systems
6144 ** which do not support fchown() if UseMSP is not set.
6147 "_FFR_DROP_TRUSTUSER_WARNING",
6148 #endif /* _FFR_DROP_TRUSTUSER_WARNING */
6149 #if _FFR_EXTRA_MAP_CHECK
6150 /* perform extra checks on $( $) in R lines */
6151 "_FFR_EXTRA_MAP_CHECK",
6152 #endif /* _FFR_EXTRA_MAP_CHECK */
6155 ** If using -t, force not sending to argv recipients, even
6156 ** if they are mentioned in the headers.
6160 #endif /* _FFR_FIX_DASHT */
6161 #if _FFR_FORWARD_SYSERR
6162 /* Cause a "syserr" if forward file isn't "safe". */
6163 "_FFR_FORWARD_SYSERR",
6164 #endif /* _FFR_FORWARD_SYSERR */
6166 /* Generate a ORCPT DSN arg if not already provided */
6168 #endif /* _FFR_GEN_ORCPT */
6169 #if _FFR_LOG_GREET_PAUSE
6170 /* log time for greet_pause delay; from Nik Clayton */
6171 "_FFR_LOG_GREET_PAUSE",
6172 #endif /* _FFR_LOG_GREET_PAUSE */
6173 #if _FFR_GROUPREADABLEAUTHINFOFILE
6174 /* Allow group readable DefaultAuthInfo file. */
6175 "_FFR_GROUPREADABLEAUTHINFOFILE",
6176 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
6177 #if _FFR_HANDLE_ISO8859_GECOS
6179 ** Allow ISO 8859 characters in GECOS field: replace them
6180 ** ith ASCII "equivalent".
6183 /* Peter Eriksson of Linkopings universitet */
6184 "_FFR_HANDLE_ISO8859_GECOS",
6185 #endif /* _FFR_HANDLE_ISO8859_GECOS */
6187 /* Set 'h' in {addr_type} for headers. */
6189 #endif /* _FFR_HDR_TYPE */
6191 /* option to set heloname; Nik Clayton of FreeBSD */
6193 #endif /* _FFR_HELONAME */
6194 #if _FFR_HPUX_NSSWITCH
6195 /* Use nsswitch on HP-UX */
6196 "_FFR_HPUX_NSSWITCH",
6197 #endif /* _FFR_HPUX_NSSWITCH */
6198 #if _FFR_IGNORE_BOGUS_ADDR
6199 /* Ignore addresses for which prescan() failed */
6200 "_FFR_IGNORE_BOGUS_ADDR",
6201 #endif /* _FFR_IGNORE_BOGUS_ADDR */
6202 #if _FFR_IGNORE_EXT_ON_HELO
6203 /* Ignore extensions offered in response to HELO */
6204 "_FFR_IGNORE_EXT_ON_HELO",
6205 #endif /* _FFR_IGNORE_EXT_ON_HELO */
6206 #if _FFR_MAXDATASIZE
6208 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6209 ** hence this shouldn't be used as limit for milter communication.
6210 ** see also libmilter/comm.c
6211 ** Gurusamy Sarathy of ActiveState
6215 #endif /* _FFR_MAXDATASIZE */
6216 #if _FFR_MAX_FORWARD_ENTRIES
6217 /* Try to limit number of .forward entries */
6218 /* (doesn't work) */
6219 /* Randall S. Winchester of the University of Maryland */
6220 "_FFR_MAX_FORWARD_ENTRIES",
6221 #endif /* _FFR_MAX_FORWARD_ENTRIES */
6223 /* increase key size for LDAP lookups, see conf.h */
6225 #endif /* _FFR_MAXKEY */
6226 #if _FFR_MAXNOOPCOMMANDS
6227 /* runtime option for "MaxNOOPCommands" */
6228 "_FFR_MAXNOOPCOMMANDS",
6229 #endif /* _FFR_MAXNOOPCOMMANDS */
6230 #if _FFR_MAX_SLEEP_TIME
6231 /* Limit sleep(2) time in libsm/clock.c */
6232 "_FFR_MAX_SLEEP_TIME",
6233 #endif /* _FFR_MAX_SLEEP_TIME */
6235 /* Check free memory */
6237 #endif /* _FFR_MEMSTAT */
6238 #if _FFR_MILTER_NAGLE
6239 /* milter: turn off Nagle ("cork" on Linux) */
6240 /* John Gardiner Myers of Proofpoint */
6241 "_FFR_MILTER_NAGLE ",
6242 #endif /* _FFR_MILTER_NAGLE */
6243 #if _FFR_MILTER_NOHDR_RESP
6244 /* milter: no response expected when sending headers */
6245 /* John Gardiner Myers of Proofpoint */
6246 "_FFR_MILTER_NOHDR_RESP",
6247 #endif /* _FFR_MILTER_NOHDR_RESP */
6248 #if _FFR_MIME7TO8_OLD
6249 /* Old mime7to8 code, the new is broken for at least one example. */
6250 "_FFR_MIME7TO8_OLD",
6251 #endif /* _FFR_MAX_SLEEP_TIME */
6253 /* allow to override "Message accepted for delivery" */
6255 #endif /* _FFR_MSG_ACCEPT */
6256 #if _FFR_NODELAYDSN_ON_HOLD
6257 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6259 "_FFR_NODELAYDSN_ON_HOLD",
6260 #endif /* _FFR_NODELAYDSN_ON_HOLD */
6262 /* Disable PIPELINING, delay client if used. */
6264 #endif /* _FFR_NO_PIPE */
6266 /* log ntries=, from Nik Clayton of FreeBSD */
6268 #endif /* _FFR_LOG_NTRIES */
6269 #if _FFR_PRIV_NOACTUALRECIPIENT
6271 ** PrivacyOptions=noactualrecipient stops sendmail from putting
6272 ** X-Actual-Recipient lines in DSNs revealing the actual
6273 ** account that addresses map to. Patch from Dan Harkless.
6276 "_FFR_PRIV_NOACTUALRECIPIENT",
6277 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
6279 /* Exponential queue delay; disabled in 8.13 since it isn't used. */
6281 #endif /* _FFR_QUEUEDELAY */
6282 #if _FFR_QUEUE_GROUP_SORTORDER
6283 /* Allow QueueSortOrder per queue group. */
6284 /* XXX: Still need to actually use qgrp->qg_sortorder */
6285 "_FFR_QUEUE_GROUP_SORTORDER",
6286 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
6287 #if _FFR_QUEUE_MACRO
6288 /* Define {queue} macro. */
6290 #endif /* _FFR_QUEUE_MACRO */
6291 #if _FFR_QUEUE_RUN_PARANOIA
6292 /* Additional checks when doing queue runs; interval of checks */
6293 "_FFR_QUEUE_RUN_PARANOIA",
6294 #endif /* _FFR_QUEUE_RUN_PARANOIA */
6295 #if _FFR_QUEUE_SCHED_DBG
6296 /* Debug output for the queue scheduler. */
6297 "_FFR_QUEUE_SCHED_DBG",
6298 #endif /* _FFR_QUEUE_SCHED_DBG */
6299 #if _FFR_REDIRECTEMPTY
6301 ** envelope <> can't be sent to mailing lists, only owner-
6302 ** send spam of this type to owner- of the list
6303 ** ---- to stop spam from going to mailing lists.
6306 "_FFR_REDIRECTEMPTY",
6307 #endif /* _FFR_REDIRECTEMPTY */
6308 #if _FFR_RESET_MACRO_GLOBALS
6309 /* Allow macro 'j' to be set dynamically via rulesets. */
6310 "_FFR_RESET_MACRO_GLOBALS",
6311 #endif /* _FFR_RESET_MACRO_GLOBALS */
6313 /* Random shuffle for queue sorting. */
6315 #endif /* _FFR_RHS */
6317 /* Auto-select of shared memory key */
6319 #endif /* _FFR_SELECT_SHM */
6321 /* Donated code (unused). */
6323 #endif /* _FFR_SHM_STATUS */
6324 #if _FFR_LDAP_SINGLEDN
6326 ** The LDAP database map code in Sendmail 8.12.10, when
6327 ** given the -1 switch, would match only a single DN,
6328 ** but was able to return multiple attributes for that
6329 ** DN. In Sendmail 8.13 this "bug" was corrected to
6330 ** only return if exactly one attribute matched.
6332 ** Unfortunately, our configuration uses the former
6333 ** behaviour. Attached is a relatively simple patch
6334 ** to 8.13.4 which adds a -2 switch (for lack of a
6335 ** better option) which returns the single dn/multiple
6338 ** Jeffrey T. Eaton, Carnegie-Mellon University
6341 "_FFR_LDAP_SINGLEDN",
6342 #endif /* _FFR_LDAP_SINGLEDN */
6343 #if _FFR_SKIP_DOMAINS
6344 /* process every N'th domain instead of every N'th message */
6345 "_FFR_SKIP_DOMAINS",
6346 #endif /* _FFR_SKIP_DOMAINS */
6347 #if _FFR_SLEEP_USE_SELECT
6348 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6349 "_FFR_SLEEP_USE_SELECT ",
6350 #endif /* _FFR_SLEEP_USE_SELECT */
6351 #if _FFR_SOFT_BOUNCE
6352 /* Turn all errors into temporary errors. */
6354 #endif /* _FFR_SOFT_BOUNCE */
6357 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6358 ** bit alignment, so unless each piece of argv and envp is a multiple
6359 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6360 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6361 ** if you use this FFR.
6364 /* Chris Adams of HiWAAY Informations Services */
6366 #endif /* _FFR_SPT_ALIGN */
6367 #if _FFR_SS_PER_DAEMON
6368 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6369 "_FFR_SS_PER_DAEMON",
6370 #endif /* _FFR_SS_PER_DAEMON */
6372 /* Donated code (unused). */
6374 #endif /* _FFR_TIMERS */
6376 /* More STARTTLS options, e.g., secondary certs. */
6378 #endif /* _FFR_TLS_1 */
6381 ** If we don't own the file mark it as unsafe.
6382 ** However, allow TrustedUser to own it as well
6383 ** in case TrustedUser manipulates the queue.
6387 #endif /* _FFR_TRUSTED_QF */
6388 #if _FFR_USE_SEM_LOCKING
6389 "_FFR_USE_SEM_LOCKING",
6390 #endif /* _FFR_USE_SEM_LOCKING */
6391 #if _FFR_USE_SETLOGIN
6392 /* Use setlogin() */
6394 "_FFR_USE_SETLOGIN",
6395 #endif /* _FFR_USE_SETLOGIN */