2 * Copyright (c) 1998-2008 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.1141 2008/04/14 02:09:35 ca Exp $")
18 #include <sm/sendmail.h>
19 #include <sendmail/pathnames.h>
29 /* for the IPv6 device lookup */
30 # define _SOCKADDR_LEN
32 # endif /* NETINET6 */
35 # include <sys/ioctl.h>
36 # include <sys/param.h>
39 #if NETINET || NETINET6
40 # include <arpa/inet.h>
41 #endif /* NETINET || NETINET6 */
42 #if HASULIMIT && defined(HPUX11)
44 #endif /* HASULIMIT && defined(HPUX11) */
46 static void setupmaps __P((void));
47 static void setupmailers __P((void));
48 static void setupqueues __P((void));
49 static int get_num_procs_online __P((void));
50 static int add_hostnames __P((SOCKADDR *));
52 #if NETINET6 && NEEDSGETIPNODE
53 static struct hostent *getipnodebyname __P((char *, int, int, int *));
54 static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
55 #endif /* NETINET6 && NEEDSGETIPNODE */
59 ** CONF.C -- Sendmail Configuration Tables.
61 ** Defines the configuration of this installation.
63 ** Configuration Variables:
64 ** HdrInfo -- a table describing well-known header fields.
65 ** Each entry has the field name and some flags,
66 ** which are described in sendmail.h.
69 ** I have tried to put almost all the reasonable
70 ** configuration information into the configuration
71 ** file read at runtime. My intent is that anything
72 ** here is a function of the version of UNIX you
73 ** are running, or is really static -- for example
74 ** the headers are a superset of widely used
75 ** protocols. If you find yourself playing with
76 ** this file too much, you may be making a mistake!
82 ** Final (null) entry contains the flags used for any other field.
84 ** Not all of these are actually handled specially by sendmail
85 ** at this time. They are included as placeholders, to let
86 ** you know that "someday" I intend to have sendmail do
87 ** something with them.
90 struct hdrinfo HdrInfo[] =
92 /* originator fields, most to least significant */
93 { "resent-sender", H_FROM|H_RESENT, NULL },
94 { "resent-from", H_FROM|H_RESENT, NULL },
95 { "resent-reply-to", H_FROM|H_RESENT, NULL },
96 { "sender", H_FROM, NULL },
97 { "from", H_FROM, NULL },
98 { "reply-to", H_FROM, NULL },
99 { "errors-to", H_FROM|H_ERRORSTO, NULL },
100 { "full-name", H_ACHECK, NULL },
101 { "return-receipt-to", H_RECEIPTTO, NULL },
102 { "delivery-receipt-to", H_RECEIPTTO, NULL },
103 { "disposition-notification-to", H_FROM, NULL },
105 /* destination fields */
106 { "to", H_RCPT, NULL },
107 { "resent-to", H_RCPT|H_RESENT, NULL },
108 { "cc", H_RCPT, NULL },
109 { "resent-cc", H_RCPT|H_RESENT, NULL },
110 { "bcc", H_RCPT|H_BCC, NULL },
111 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
112 { "apparently-to", H_RCPT, NULL },
114 /* message identification and control */
115 { "message-id", 0, NULL },
116 { "resent-message-id", H_RESENT, NULL },
117 { "message", H_EOH, NULL },
118 { "text", H_EOH, NULL },
122 { "resent-date", H_RESENT, NULL },
125 { "received", H_TRACE|H_FORCE, NULL },
126 { "x400-received", H_TRACE|H_FORCE, NULL },
127 { "via", H_TRACE|H_FORCE, NULL },
128 { "mail-from", H_TRACE|H_FORCE, NULL },
130 /* miscellaneous fields */
131 { "comments", H_FORCE|H_ENCODABLE, NULL },
132 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
133 { "content-transfer-encoding", H_CTE, NULL },
134 { "content-type", H_CTYPE, NULL },
135 { "content-length", H_ACHECK, NULL },
136 { "subject", H_ENCODABLE, NULL },
137 { "x-authentication-warning", H_FORCE, NULL },
148 struct prival PrivacyValues[] =
150 { "public", PRIV_PUBLIC },
151 { "needmailhelo", PRIV_NEEDMAILHELO },
152 { "needexpnhelo", PRIV_NEEDEXPNHELO },
153 { "needvrfyhelo", PRIV_NEEDVRFYHELO },
154 { "noexpn", PRIV_NOEXPN },
155 { "novrfy", PRIV_NOVRFY },
156 { "restrictexpand", PRIV_RESTRICTEXPAND },
157 { "restrictmailq", PRIV_RESTRICTMAILQ },
158 { "restrictqrun", PRIV_RESTRICTQRUN },
159 { "noetrn", PRIV_NOETRN },
160 { "noverb", PRIV_NOVERB },
161 { "authwarnings", PRIV_AUTHWARNINGS },
162 { "noreceipts", PRIV_NORECEIPTS },
163 { "nobodyreturn", PRIV_NOBODYRETN },
164 { "goaway", PRIV_GOAWAY },
165 { "noactualrecipient", PRIV_NOACTUALRECIPIENT },
170 ** DontBlameSendmail values
173 struct dbsval DontBlameSendmailValues[] =
175 { "safe", DBS_SAFE },
176 { "assumesafechown", DBS_ASSUMESAFECHOWN },
177 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
178 { "groupwritableforwardfilesafe",
179 DBS_GROUPWRITABLEFORWARDFILESAFE },
180 { "groupwritableincludefilesafe",
181 DBS_GROUPWRITABLEINCLUDEFILESAFE },
182 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
183 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
184 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
185 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
186 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
187 { "linkedaliasfileinwritabledir",
188 DBS_LINKEDALIASFILEINWRITABLEDIR },
189 { "linkedclassfileinwritabledir",
190 DBS_LINKEDCLASSFILEINWRITABLEDIR },
191 { "linkedforwardfileinwritabledir",
192 DBS_LINKEDFORWARDFILEINWRITABLEDIR },
193 { "linkedincludefileinwritabledir",
194 DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
195 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
196 { "linkedserviceswitchfileinwritabledir",
197 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
198 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
199 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
200 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
201 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
202 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
203 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
204 { "forwardfileingroupwritabledirpath",
205 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
206 { "includefileingroupwritabledirpath",
207 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
208 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
209 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
210 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
211 { "forwardfileinunsafedirpathsafe",
212 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
213 { "includefileinunsafedirpathsafe",
214 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
215 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
216 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
217 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
218 { "truststickybit", DBS_TRUSTSTICKYBIT },
219 { "dontwarnforwardfileinunsafedirpath",
220 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
221 { "insufficiententropy", DBS_INSUFFICIENTENTROPY },
222 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
223 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
224 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
225 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
226 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
227 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
228 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
229 #if _FFR_GROUPREADABLEAUTHINFOFILE
230 { "groupreadableadefaultauthinfofile",
231 DBS_GROUPREADABLEAUTHINFOFILE },
232 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
237 ** Miscellaneous stuff.
240 int DtableSize = 50; /* max open files; reset in 4.2bsd */
242 ** SETDEFAULTS -- set default values
244 ** Some of these must be initialized using direct code since they
245 ** depend on run-time values. So let's do all of them this way.
248 ** e -- the default envelope.
254 ** Initializes a bunch of global variables to their
259 #define HOURS * 60 MINUTES
260 #define DAYS * 24 HOURS
262 #ifndef MAXRULERECURSION
263 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
264 #endif /* ! MAXRULERECURSION */
268 register ENVELOPE *e;
274 numprocs = get_num_procs_online();
275 SpaceSub = ' '; /* option B */
276 QueueLA = 8 * numprocs; /* option x */
277 RefuseLA = 12 * numprocs; /* option X */
278 WkRecipFact = 30000L; /* option y */
279 WkClassFact = 1800L; /* option z */
280 WkTimeFact = 90000L; /* option Z */
281 QueueFactor = WkRecipFact * 20; /* option q */
282 QueueMode = QM_NORMAL; /* what queue items to act upon */
283 FileMode = (RealUid != geteuid()) ? 0644 : 0600;
285 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
286 /* option QueueFileMode */
288 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
289 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
290 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
292 DefUid = pw->pw_uid; /* option u */
293 DefGid = pw->pw_gid; /* option g */
294 DefUser = newstr(pw->pw_name);
298 DefUid = 1; /* option u */
299 DefGid = 1; /* option g */
304 sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
305 DefUser != NULL ? DefUser : "<1:1>",
306 (int) DefUid, (int) DefGid);
307 CheckpointInterval = 10; /* option C */
308 MaxHopCount = 25; /* option h */
309 set_delivery_mode(SM_FORK, e); /* option d */
310 e->e_errormode = EM_PRINT; /* option e */
313 e->e_xfqgrp = NOQGRP;
314 e->e_xfqdir = NOQDIR;
315 e->e_ctime = curtime();
316 SevenBitInput = false; /* option 7 */
317 MaxMciCache = 1; /* option k */
318 MciCacheTimeout = 5 MINUTES; /* option K */
319 LogLevel = 9; /* option L */
323 inittimeouts(NULL, false); /* option r */
324 PrivacyFlags = PRIV_PUBLIC; /* option p */
325 MeToo = true; /* option m */
326 SendMIMEErrors = true; /* option f */
327 SuperSafe = SAFE_REALLY; /* option s */
328 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
330 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
332 MimeMode = MM_PASS8BIT;
333 #endif /* MIME8TO7 */
334 for (i = 0; i < MAXTOCLASS; i++)
336 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
337 TimeOuts.to_q_warning[i] = 0; /* option T */
339 ServiceSwitchFile = "/etc/mail/service.switch";
340 ServiceCacheMaxAge = (time_t) 10;
341 HostsFile = _PATH_HOSTS;
342 PidFile = newstr(_PATH_SENDMAILPID);
343 MustQuoteChars = "@,;:\\()[].'";
344 MciInfoTimeout = 30 MINUTES;
345 MaxRuleRecursion = MAXRULERECURSION;
346 MaxAliasRecursion = 10;
347 MaxMacroRecursion = 10;
348 ColonOkInAddr = true;
349 DontLockReadFiles = true;
350 DontProbeInterfaces = DPI_PROBEALL;
351 DoubleBounceAddr = "postmaster";
352 MaxHeadersLength = MAXHDRSLEN;
353 MaxMimeHeaderLength = MAXLINE;
354 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
355 MaxForwardEntries = 0;
357 MaxNOOPCommands = MAXNOOPCOMMANDS;
359 AuthMechanisms = newstr(AUTH_MECHANISMS);
364 TLS_Srv_Opts = TLS_I_SRV;
365 #endif /* STARTTLS */
367 HesiodContext = NULL;
368 #endif /* HESIOD_INIT */
370 /* Detect if IPv6 is available at run time */
371 i = socket(AF_INET6, SOCK_STREAM, 0);
381 #endif /* NETINET6 */
382 ControlSocketName = NULL;
383 memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo));
384 DataFileBufferSize = 4096;
385 XscriptFileBufferSize = 4096;
386 for (i = 0; i < MAXRWSETS; i++)
387 RuleSetNames[i] = NULL;
389 InputFilters[0] = NULL;
391 RejectLogInterval = 3 HOURS;
392 #if REQUIRES_DIR_FSYNC
393 RequiresDirfsync = true;
394 #endif /* REQUIRES_DIR_FSYNC */
395 ConnectionRateWindowSize = 60;
404 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
410 struct passwd *defpwent;
411 static char defuserbuf[40];
413 DefUser = defuserbuf;
414 defpwent = sm_getpwuid(DefUid);
415 (void) sm_strlcpy(defuserbuf,
416 (defpwent == NULL || defpwent->pw_name == NULL)
417 ? "nobody" : defpwent->pw_name,
420 sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
421 (int) DefUid, DefUser);
424 ** SETUPQUEUES -- initialize default queues
426 ** The mqueue QUEUE structure gets filled in after readcf() but
427 ** we need something to point to now for the mailer setup,
428 ** which use "mqueue" as default queue.
436 MaxRunnersPerQueue = 1;
437 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf));
438 makequeue(buf, false);
441 ** SETUPMAILERS -- initialize default mailers
449 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
453 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
457 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
463 ** SETUPMAPS -- set up map classes
466 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
468 extern bool parse __P((MAP *, char *)); \
469 extern bool open __P((MAP *, int)); \
470 extern void close __P((MAP *)); \
471 extern char *lookup __P((MAP *, char *, char **, int *)); \
472 extern void store __P((MAP *, char *, char *)); \
473 s = stab(name, ST_MAPCLASS, ST_ENTER); \
474 s->s_mapclass.map_cname = name; \
475 s->s_mapclass.map_ext = ext; \
476 s->s_mapclass.map_cflags = flags; \
477 s->s_mapclass.map_parse = parse; \
478 s->s_mapclass.map_open = open; \
479 s->s_mapclass.map_close = close; \
480 s->s_mapclass.map_lookup = lookup; \
481 s->s_mapclass.map_store = store; \
490 # if DB_VERSION_MAJOR > 1
491 int major_v, minor_v, patch_v;
493 (void) db_version(&major_v, &minor_v, &patch_v);
494 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
497 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
498 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
499 major_v, minor_v, patch_v);
501 # endif /* DB_VERSION_MAJOR > 1 */
503 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
504 map_parseargs, hash_map_open, db_map_close,
505 db_map_lookup, db_map_store);
507 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
508 map_parseargs, bt_map_open, db_map_close,
509 db_map_lookup, db_map_store);
513 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
514 map_parseargs, ndbm_map_open, ndbm_map_close,
515 ndbm_map_lookup, ndbm_map_store);
519 MAPDEF("nis", NULL, MCF_ALIASOK,
520 map_parseargs, nis_map_open, null_map_close,
521 nis_map_lookup, null_map_store);
525 MAPDEF("nisplus", NULL, MCF_ALIASOK,
526 map_parseargs, nisplus_map_open, null_map_close,
527 nisplus_map_lookup, null_map_store);
531 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
532 ldapmap_parseargs, ldapmap_open, ldapmap_close,
533 ldapmap_lookup, null_map_store);
537 MAPDEF("ph", NULL, MCF_NOTPERSIST,
538 ph_map_parseargs, ph_map_open, ph_map_close,
539 ph_map_lookup, null_map_store);
543 /* IRIX 6.5 nsd support */
544 MAPDEF("nsd", NULL, MCF_ALIASOK,
545 map_parseargs, null_map_open, null_map_close,
546 nsd_map_lookup, null_map_store);
550 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
551 map_parseargs, hes_map_open, hes_map_close,
552 hes_map_lookup, null_map_store);
556 MAPDEF("netinfo", NULL, MCF_ALIASOK,
557 map_parseargs, ni_map_open, null_map_close,
558 ni_map_lookup, null_map_store);
562 MAPDEF("dns", NULL, 0,
563 dns_map_init, null_map_open, null_map_close,
564 dns_map_lookup, null_map_store);
569 # if _FFR_DNSMAP_ALIASABLE
570 MAPDEF("dns", NULL, MCF_ALIASOK,
571 dns_map_parseargs, dns_map_open, null_map_close,
572 dns_map_lookup, null_map_store);
573 # else /* _FFR_DNSMAP_ALIASABLE */
574 MAPDEF("dns", NULL, 0,
575 dns_map_parseargs, dns_map_open, null_map_close,
576 dns_map_lookup, null_map_store);
577 # endif /* _FFR_DNSMAP_ALIASABLE */
579 #endif /* NAMED_BIND */
582 /* best MX DNS lookup */
583 MAPDEF("bestmx", NULL, MCF_OPTFILE,
584 map_parseargs, null_map_open, null_map_close,
585 bestmx_map_lookup, null_map_store);
586 #endif /* NAMED_BIND */
588 MAPDEF("host", NULL, 0,
589 host_map_init, null_map_open, null_map_close,
590 host_map_lookup, null_map_store);
592 MAPDEF("text", NULL, MCF_ALIASOK,
593 map_parseargs, text_map_open, null_map_close,
594 text_map_lookup, null_map_store);
596 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
597 map_parseargs, stab_map_open, null_map_close,
598 stab_map_lookup, stab_map_store);
600 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
601 map_parseargs, impl_map_open, impl_map_close,
602 impl_map_lookup, impl_map_store);
604 /* access to system passwd file */
605 MAPDEF("user", NULL, MCF_OPTFILE,
606 map_parseargs, user_map_open, null_map_close,
607 user_map_lookup, null_map_store);
610 MAPDEF("dequote", NULL, 0,
611 dequote_init, null_map_open, null_map_close,
612 dequote_map, null_map_store);
615 MAPDEF("regex", NULL, 0,
616 regex_map_init, null_map_open, null_map_close,
617 regex_map_lookup, null_map_store);
618 #endif /* MAP_REGEX */
622 MAPDEF("userdb", ".db", 0,
623 map_parseargs, null_map_open, null_map_close,
624 udb_map_lookup, null_map_store);
627 /* arbitrary programs */
628 MAPDEF("program", NULL, MCF_ALIASOK,
629 map_parseargs, null_map_open, null_map_close,
630 prog_map_lookup, null_map_store);
633 MAPDEF("sequence", NULL, MCF_ALIASOK,
634 seq_map_parse, null_map_open, null_map_close,
635 seq_map_lookup, seq_map_store);
637 /* switched interface to sequenced maps */
638 MAPDEF("switch", NULL, MCF_ALIASOK,
639 map_parseargs, switch_map_open, null_map_close,
640 seq_map_lookup, seq_map_store);
642 /* null map lookup -- really for internal use only */
643 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
644 map_parseargs, null_map_open, null_map_close,
645 null_map_lookup, null_map_store);
647 /* syslog map -- logs information to syslog */
648 MAPDEF("syslog", NULL, 0,
649 syslog_map_parseargs, null_map_open, null_map_close,
650 syslog_map_lookup, null_map_store);
652 /* macro storage map -- rulesets can set macros */
653 MAPDEF("macro", NULL, 0,
654 dequote_init, null_map_open, null_map_close,
655 macro_map_lookup, null_map_store);
657 /* arithmetic map -- add/subtract/compare */
658 MAPDEF("arith", NULL, 0,
659 dequote_init, null_map_open, null_map_close,
660 arith_map_lookup, null_map_store);
663 /* arbitrary daemons */
664 MAPDEF("socket", NULL, MCF_ALIASOK,
665 map_parseargs, socket_map_open, socket_map_close,
666 socket_map_lookup, null_map_store);
667 #endif /* SOCKETMAP */
670 /* dprintf map -- logs information to syslog */
671 MAPDEF("dprintf", NULL, 0,
672 dprintf_map_parseargs, null_map_open, null_map_close,
673 dprintf_map_lookup, null_map_store);
674 #endif /* _FFR_DPRINTF_MAP */
678 /* bogus map -- always return tempfail */
679 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
680 map_parseargs, null_map_open, null_map_close,
681 bogus_map_lookup, null_map_store);
687 ** INITHOSTMAPS -- initial host-dependent maps
689 ** This should act as an interface to any local service switch
690 ** provided by the host operating system.
699 ** Should define maps "host" and "users" as necessary
700 ** for this OS. If they are not defined, they will get
701 ** a default value later. It should check to make sure
702 ** they are not defined first, since it's possible that
703 ** the config file has provided an override.
711 char *maptype[MAXMAPSTACK];
712 short mapreturn[MAXMAPACTIONS];
716 ** Make sure we have a host map.
719 if (stab("host", ST_MAP, ST_FIND) == NULL)
721 /* user didn't initialize: set up host map */
722 (void) sm_strlcpy(buf, "host host", sizeof(buf));
724 if (ConfigLevel >= 2)
725 (void) sm_strlcat(buf, " -a. -D", sizeof(buf));
726 #endif /* NAMED_BIND */
727 (void) makemapentry(buf);
731 ** Set up default aliases maps
734 nmaps = switch_map_find("aliases", maptype, mapreturn);
735 for (i = 0; i < nmaps; i++)
737 if (strcmp(maptype[i], "files") == 0 &&
738 stab("aliases.files", ST_MAP, ST_FIND) == NULL)
740 (void) sm_strlcpy(buf, "aliases.files null",
742 (void) makemapentry(buf);
745 else if (strcmp(maptype[i], "nisplus") == 0 &&
746 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
748 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
750 (void) makemapentry(buf);
754 else if (strcmp(maptype[i], "nis") == 0 &&
755 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
757 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
759 (void) makemapentry(buf);
763 else if (strcmp(maptype[i], "netinfo") == 0 &&
764 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
766 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
768 (void) makemapentry(buf);
772 else if (strcmp(maptype[i], "hesiod") == 0 &&
773 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
775 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
777 (void) makemapentry(buf);
780 #if LDAPMAP && defined(SUN_EXTENSIONS) && \
781 defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
782 else if (strcmp(maptype[i], "ldap") == 0 &&
783 stab("aliases.ldap", ST_MAP, ST_FIND) == NULL)
785 (void) strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
787 (void) makemapentry(buf);
789 #endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */
791 if (stab("aliases", ST_MAP, ST_FIND) == NULL)
793 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf));
794 (void) makemapentry(buf);
799 ** SWITCH_MAP_FIND -- find the list of types associated with a map
801 ** This is the system-dependent interface to the service switch.
804 ** service -- the name of the service of interest.
805 ** maptype -- an out-array of strings containing the types
806 ** of access to use for this service. There can
807 ** be at most MAXMAPSTACK types for a single service.
808 ** mapreturn -- an out-array of return information bitmaps
812 ** The number of map types filled in, or -1 for failure.
815 ** Preserves errno so nothing in the routine clobbers it.
818 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
819 # define _USE_SUN_NSSWITCH_
820 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
822 #if _FFR_HPUX_NSSWITCH
824 # define _USE_SUN_NSSWITCH_
826 #endif /* _FFR_HPUX_NSSWITCH */
828 #ifdef _USE_SUN_NSSWITCH_
829 # include <nsswitch.h>
830 #endif /* _USE_SUN_NSSWITCH_ */
832 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
833 # define _USE_DEC_SVC_CONF_
834 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
836 #ifdef _USE_DEC_SVC_CONF_
837 # include <sys/svcinfo.h>
838 #endif /* _USE_DEC_SVC_CONF_ */
841 switch_map_find(service, maptype, mapreturn)
843 char *maptype[MAXMAPSTACK];
844 short mapreturn[MAXMAPACTIONS];
847 int save_errno = errno;
849 #ifdef _USE_SUN_NSSWITCH_
850 struct __nsw_switchconfig *nsw_conf;
851 enum __nsw_parse_err pserr;
852 struct __nsw_lookup *lk;
853 static struct __nsw_lookup lkp0 =
854 { "files", {1, 0, 0, 0}, NULL, NULL };
855 static struct __nsw_switchconfig lkp_default =
856 { 0, "sendmail", 3, &lkp0 };
858 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
859 mapreturn[svcno] = 0;
861 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
862 lk = lkp_default.lookups;
864 lk = nsw_conf->lookups;
866 while (lk != NULL && svcno < MAXMAPSTACK)
868 maptype[svcno] = lk->service_name;
869 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
870 mapreturn[MA_NOTFOUND] |= 1 << svcno;
871 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
872 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
873 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
874 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
880 #endif /* _USE_SUN_NSSWITCH_ */
882 #ifdef _USE_DEC_SVC_CONF_
883 struct svcinfo *svcinfo;
886 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
887 mapreturn[svcno] = 0;
892 if (strcmp(service, "hosts") == 0)
894 else if (strcmp(service, "aliases") == 0)
896 else if (strcmp(service, "passwd") == 0)
903 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
905 switch (svcinfo->svcpath[svc][svcno])
908 maptype[svcno] = "files";
912 maptype[svcno] = "nis";
916 maptype[svcno] = "dns";
921 maptype[svcno] = "hesiod";
923 # endif /* SVC_HESIOD */
932 #endif /* _USE_DEC_SVC_CONF_ */
934 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
936 ** Fall-back mechanism.
940 static time_t servicecachetime; /* time service switch was cached */
941 time_t now = curtime();
943 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
944 mapreturn[svcno] = 0;
946 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
948 /* (re)read service switch */
949 register SM_FILE_T *fp;
950 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
952 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
957 servicecachetime = now;
958 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
963 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
964 sizeof(buf)) != NULL)
968 p = strpbrk(buf, "#\n");
971 p = strpbrk(buf, " \t");
978 sm_syslog(LOG_ERR, NOQID,
979 "Bad line on %.100s: %.100s",
990 ** Find/allocate space for this service entry.
991 ** Space for all of the service strings
992 ** are allocated at once. This means
993 ** that we only have to free the first
994 ** one to free all of them.
997 st = stab(buf, ST_SERVICE, ST_ENTER);
998 if (st->s_service[0] != NULL)
999 sm_free((void *) st->s_service[0]); /* XXX */
1001 for (svcno = 0; svcno < MAXMAPSTACK; )
1005 st->s_service[svcno++] = p;
1006 p = strpbrk(p, " \t");
1013 if (svcno < MAXMAPSTACK)
1014 st->s_service[svcno] = NULL;
1016 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1020 /* look up entry in cache */
1021 st = stab(service, ST_SERVICE, ST_FIND);
1022 if (st != NULL && st->s_service[0] != NULL)
1026 while (svcno < MAXMAPSTACK)
1028 maptype[svcno] = st->s_service[svcno];
1029 if (maptype[svcno++] == NULL)
1035 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1037 #if !defined(_USE_SUN_NSSWITCH_)
1038 /* if the service file doesn't work, use an absolute fallback */
1039 # ifdef _USE_DEC_SVC_CONF_
1041 # endif /* _USE_DEC_SVC_CONF_ */
1042 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1043 mapreturn[svcno] = 0;
1045 if (strcmp(service, "aliases") == 0)
1047 maptype[svcno++] = "files";
1048 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1049 maptype[svcno++] = "netinfo";
1050 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
1051 # ifdef AUTO_NIS_ALIASES
1053 maptype[svcno++] = "nisplus";
1054 # endif /* NISPLUS */
1056 maptype[svcno++] = "nis";
1058 # endif /* AUTO_NIS_ALIASES */
1062 if (strcmp(service, "hosts") == 0)
1065 maptype[svcno++] = "dns";
1066 # else /* NAMED_BIND */
1067 # if defined(sun) && !defined(BSD)
1069 maptype[svcno++] = "nis";
1070 # endif /* defined(sun) && !defined(BSD) */
1071 # endif /* NAMED_BIND */
1072 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1073 maptype[svcno++] = "netinfo";
1074 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
1075 maptype[svcno++] = "files";
1081 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1084 ** USERNAME -- return the user id of the logged in user.
1090 ** The login name of the logged in user.
1096 ** The return value is statically allocated.
1102 static char *myname = NULL;
1103 extern char *getlogin();
1104 register struct passwd *pw;
1106 /* cache the result */
1109 myname = getlogin();
1110 if (myname == NULL || myname[0] == '\0')
1112 pw = sm_getpwuid(RealUid);
1114 myname = pw->pw_name;
1118 uid_t uid = RealUid;
1120 if ((pw = sm_getpwnam(myname)) == NULL ||
1121 (uid != 0 && uid != pw->pw_uid))
1123 pw = sm_getpwuid(uid);
1125 myname = pw->pw_name;
1128 if (myname == NULL || myname[0] == '\0')
1130 syserr("554 5.3.0 Who are you?");
1131 myname = "postmaster";
1133 else if (strpbrk(myname, ",;:/|\"\\") != NULL)
1134 myname = addquotes(myname, NULL);
1136 myname = sm_pstrdup_x(myname);
1141 ** TTYPATH -- Get the path of the user's tty
1143 ** Returns the pathname of the user's tty. Returns NULL if
1144 ** the user is not logged in or if s/he has write permission
1151 ** pathname of the user's tty.
1152 ** NULL if not logged in or write permission denied.
1158 ** Return value is in a local buffer.
1168 register char *pathn;
1169 extern char *ttyname();
1170 extern char *getlogin();
1172 /* compute the pathname of the controlling tty */
1173 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
1174 (pathn = ttyname(0)) == NULL)
1180 /* see if we have write permission */
1181 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
1187 /* see if the user is logged in */
1188 if (getlogin() == NULL)
1195 ** CHECKCOMPAT -- check for From and To person compatible.
1197 ** This routine can be supplied on a per-installation basis
1198 ** to determine whether a person is allowed to send a message.
1199 ** This allows restriction of certain types of internet
1200 ** forwarding or registration of users.
1202 ** If the hosts are found to be incompatible, an error
1203 ** message should be given using "usrerr" and an EX_ code
1204 ** should be returned. You can also set to->q_status to
1205 ** a DSN-style status code.
1207 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1208 ** body during the return-to-sender function; this should be done
1209 ** on huge messages. This bit may already be set by the ESMTP
1213 ** to -- the person being sent to.
1219 ** none (unless you include the usrerr stuff)
1224 register ADDRESS *to;
1225 register ENVELOPE *e;
1228 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1229 to->q_paddr, e->e_from.q_paddr);
1232 /* this code is intended as an example only */
1235 s = stab("arpa", ST_MAILER, ST_FIND);
1236 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
1237 to->q_mailer == s->s_mailer)
1239 usrerr("553 No ARPA mail through this machine: see your system administration");
1240 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1241 to->q_status = "5.7.1";
1242 return EX_UNAVAILABLE;
1244 #endif /* EXAMPLE_CODE */
1248 #ifdef SUN_EXTENSIONS
1254 /* Check for large file descriptor */
1255 if (fstat(fileno(stdin), &sbuf) < 0)
1257 if (errno == EOVERFLOW)
1264 #endif /* SUN_EXTENSIONS */
1267 ** INIT_MD -- do machine dependent initializations
1269 ** Systems that have global modes that should be set should do
1270 ** them here rather than in main.
1274 # include <compat.h>
1275 #endif /* _AUX_SOURCE */
1278 # include <shares.h>
1279 #endif /* SHARE_V1 */
1287 setcompat(getcompat() | COMPAT_BSDPROT);
1288 #endif /* _AUX_SOURCE */
1290 #ifdef SUN_EXTENSIONS
1292 #endif /* SUN_EXTENSIONS */
1295 /* keep gethostby*() from stripping the local domain name */
1296 set_domain_trim_off();
1297 #endif /* _CONVEX_SOURCE */
1298 #if defined(__QNX__) && !defined(__QNXNTO__)
1300 ** Due to QNX's network distributed nature, you can target a tcpip
1301 ** stack on a different node in the qnx network; this patch lets
1302 ** this feature work. The __sock_locate() must be done before the
1303 ** environment is clear.
1306 #endif /* __QNX__ */
1307 #if SECUREWARE || defined(_SCO_unix_)
1308 set_auth_parameters(argc, argv);
1312 ** This is required for highest security levels (the kernel
1313 ** won't let it call set*uid() or run setuid binaries without
1314 ** it). It may be necessary on other SECUREWARE systems.
1317 if (getluid() == -1)
1319 # endif /* _SCO_unix_ */
1320 #endif /* SECUREWARE || defined(_SCO_unix_) */
1323 #ifdef VENDOR_DEFAULT
1324 VendorCode = VENDOR_DEFAULT;
1325 #else /* VENDOR_DEFAULT */
1326 VendorCode = VENDOR_BERKELEY;
1327 #endif /* VENDOR_DEFAULT */
1330 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1332 ** Called once, on startup.
1335 ** e -- the global envelope.
1341 ** vendor-dependent.
1345 init_vendor_macros(e)
1346 register ENVELOPE *e;
1350 ** GETLA -- get the current load average
1352 ** This code stolen from la.c.
1358 ** The current load average as an integer.
1364 /* try to guess what style of load average we have */
1365 #define LA_ZERO 1 /* always return load average as zero */
1366 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1367 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1368 #define LA_SUBR 4 /* call getloadavg */
1369 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1370 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1371 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1372 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1373 #define LA_DGUX 9 /* special DGUX implementation */
1374 #define LA_HPUX 10 /* special HPUX implementation */
1375 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1376 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1377 #define LA_DEVSHORT 13 /* read short from a device */
1378 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1379 #define LA_PSET 15 /* Solaris per-processor-set load average */
1380 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1382 /* do guesses based on general OS type */
1384 # define LA_TYPE LA_ZERO
1385 #endif /* ! LA_TYPE */
1388 # if defined(unixpc)
1390 # endif /* defined(unixpc) */
1392 # if defined(__alpha) || defined(IRIX)
1394 # endif /* defined(__alpha) || defined(IRIX) */
1396 #endif /* ! FSHIFT */
1400 #endif /* ! FSHIFT */
1403 # define FSCALE (1 << FSHIFT)
1404 #endif /* ! FSCALE */
1408 # define LA_AVENRUN "avenrun"
1409 # else /* SYSTEM5 */
1410 # define LA_AVENRUN "_avenrun"
1411 # endif /* SYSTEM5 */
1412 #endif /* ! LA_AVENRUN */
1414 /* _PATH_KMEM should be defined in <paths.h> */
1416 # define _PATH_KMEM "/dev/kmem"
1417 #endif /* ! _PATH_KMEM */
1419 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1423 /* _PATH_UNIX should be defined in <paths.h> */
1425 # if defined(SYSTEM5)
1426 # define _PATH_UNIX "/unix"
1427 # else /* defined(SYSTEM5) */
1428 # define _PATH_UNIX "/vmunix"
1429 # endif /* defined(SYSTEM5) */
1430 # endif /* ! _PATH_UNIX */
1434 # else /* _AUX_SOURCE */
1440 # endif /* _AUX_SOURCE */
1441 # define X_AVENRUN 0
1447 static int kmem = -1;
1448 # if LA_TYPE == LA_INT
1450 # else /* LA_TYPE == LA_INT */
1451 # if LA_TYPE == LA_SHORT
1454 # if LA_TYPE == LA_LONGLONG
1455 long long avenrun[3];
1456 # else /* LA_TYPE == LA_LONGLONG */
1458 # endif /* LA_TYPE == LA_LONGLONG */
1459 # endif /* LA_TYPE == LA_SHORT */
1460 # endif /* LA_TYPE == LA_INT */
1461 extern off_t lseek();
1466 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
1467 sizeof(Nl[X_AVENRUN].n_name));
1468 Nl[1].n_name[0] = '\0';
1469 # endif /* _AUX_SOURCE */
1471 # if defined(_AIX3) || defined(_AIX4)
1472 if (knlist(Nl, 1, sizeof(Nl[0])) < 0)
1473 # else /* defined(_AIX3) || defined(_AIX4) */
1474 if (nlist(_PATH_UNIX, Nl) < 0)
1475 # endif /* defined(_AIX3) || defined(_AIX4) */
1478 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
1479 sm_errstring(errno));
1482 if (Nl[X_AVENRUN].n_value == 0)
1485 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1486 _PATH_UNIX, LA_AVENRUN);
1489 # ifdef NAMELISTMASK
1490 Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1491 # endif /* NAMELISTMASK */
1493 kmem = open(_PATH_KMEM, 0, 0);
1497 sm_dprintf("getla: open(/dev/kmem): %s\n",
1498 sm_errstring(errno));
1501 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1502 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1505 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1506 sm_errstring(errno));
1513 sm_dprintf("getla: symbol address = %#lx\n",
1514 (unsigned long) Nl[X_AVENRUN].n_value);
1515 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1516 read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
1520 sm_dprintf("getla: lseek or read: %s\n",
1521 sm_errstring(errno));
1524 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1527 # if LA_TYPE == LA_SHORT
1528 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1530 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1531 # else /* LA_TYPE == LA_SHORT */
1532 # if LA_TYPE == LA_LONGLONG
1533 sm_dprintf("getla: avenrun = %lld", avenrun[0]);
1535 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
1536 # else /* LA_TYPE == LA_LONGLONG */
1537 sm_dprintf("getla: avenrun = %ld", avenrun[0]);
1539 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
1540 # endif /* LA_TYPE == LA_LONGLONG */
1541 # endif /* LA_TYPE == LA_SHORT */
1545 sm_dprintf("getla: %d\n",
1546 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1547 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1548 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1551 sm_dprintf("getla: avenrun = %g", avenrun[0]);
1553 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
1557 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1558 return ((int) (avenrun[0] + 0.5));
1559 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1562 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1564 #if LA_TYPE == LA_READKSYM
1566 # include <sys/ksym.h>
1572 static int kmem = -1;
1574 struct mioc_rksym mirk;
1578 kmem = open("/dev/kmem", 0, 0);
1582 sm_dprintf("getla: open(/dev/kmem): %s\n",
1583 sm_errstring(errno));
1586 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1587 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1590 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1591 sm_errstring(errno));
1597 mirk.mirk_symname = LA_AVENRUN;
1598 mirk.mirk_buf = avenrun;
1599 mirk.mirk_buflen = sizeof(avenrun);
1600 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
1603 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1604 sm_errstring(errno));
1609 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1611 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1615 sm_dprintf("getla: %d\n",
1616 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1617 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1620 #endif /* LA_TYPE == LA_READKSYM */
1622 #if LA_TYPE == LA_DGUX
1624 # include <sys/dg_sys_info.h>
1629 struct dg_sys_info_load_info load_info;
1631 dg_sys_info((long *)&load_info,
1632 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1635 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1637 return ((int) (load_info.one_minute + 0.5));
1640 #endif /* LA_TYPE == LA_DGUX */
1642 #if LA_TYPE == LA_HPUX
1644 /* forward declarations to keep gcc from complaining */
1649 struct pst_diskinfo;
1650 struct pst_processor;
1652 struct pst_swapinfo;
1654 # include <sys/param.h>
1655 # include <sys/pstat.h>
1660 struct pst_dynamic pstd;
1662 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1663 (size_t) 1, 0) == -1)
1667 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1669 return (int) (pstd.psd_avg_1_min + 0.5);
1672 #endif /* LA_TYPE == LA_HPUX */
1674 #if LA_TYPE == LA_SUBR
1681 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1684 sm_dprintf("getla: getloadavg failed: %s",
1685 sm_errstring(errno));
1689 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1690 return ((int) (avenrun[0] + 0.5));
1693 #endif /* LA_TYPE == LA_SUBR */
1695 #if LA_TYPE == LA_MACH
1698 ** This has been tested on NEXTSTEP release 2.1/3.X.
1701 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1702 # include <mach/mach.h>
1703 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1705 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1710 processor_set_t default_set;
1711 kern_return_t error;
1712 unsigned int info_count;
1713 struct processor_set_basic_info info;
1716 error = processor_set_default(host_self(), &default_set);
1717 if (error != KERN_SUCCESS)
1720 sm_dprintf("getla: processor_set_default failed: %s",
1721 sm_errstring(errno));
1724 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1725 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1726 &host, (processor_set_info_t)&info,
1727 &info_count) != KERN_SUCCESS)
1730 sm_dprintf("getla: processor_set_info failed: %s",
1731 sm_errstring(errno));
1735 sm_dprintf("getla: %d\n",
1736 (int) ((info.load_average + (LOAD_SCALE / 2)) /
1738 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1741 #endif /* LA_TYPE == LA_MACH */
1743 #if LA_TYPE == LA_PROCSTR
1744 # if SM_CONF_BROKEN_STRTOD
1745 ERROR: This OS has most likely a broken strtod() implemenentation.
1746 ERROR: The function is required for getla().
1747 ERROR: Check the compilation options _LA_PROCSTR and
1748 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
1749 # endif /* SM_CONF_BROKEN_STRTOD */
1752 ** Read /proc/loadavg for the load average. This is assumed to be
1753 ** in a format like "0.15 0.12 0.06".
1755 ** Initially intended for Linux. This has been in the kernel
1756 ** since at least 0.99.15.
1759 # ifndef _PATH_LOADAVG
1760 # define _PATH_LOADAVG "/proc/loadavg"
1761 # endif /* ! _PATH_LOADAVG */
1767 register int result;
1770 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
1775 sm_dprintf("getla: sm_io_open(%s): %s\n",
1776 _PATH_LOADAVG, sm_errstring(errno));
1779 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
1780 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1784 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1785 result, sm_errstring(errno));
1790 sm_dprintf("getla(): %.2f\n", avenrun);
1792 return ((int) (avenrun + 0.5));
1795 #endif /* LA_TYPE == LA_PROCSTR */
1797 #if LA_TYPE == LA_IRIX6
1799 # include <sys/sysmp.h>
1802 # define CAST_SYSMP(x) (x)
1803 # else /* _UNICOSMP */
1804 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1805 # endif /* _UNICOSMP */
1811 static int kmem = -1;
1816 kmem = open(_PATH_KMEM, 0, 0);
1820 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
1821 sm_errstring(errno));
1824 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1825 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1828 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1829 sm_errstring(errno));
1836 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
1838 read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
1841 sm_dprintf("getla: lseek or read: %s\n",
1842 sm_errstring(errno));
1847 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
1849 sm_dprintf(", %ld, %ld",
1850 (long int) avenrun[1], (long int) avenrun[2]);
1855 sm_dprintf("getla: %d\n",
1856 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1857 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1860 #endif /* LA_TYPE == LA_IRIX6 */
1862 #if LA_TYPE == LA_KSTAT
1869 static kstat_ctl_t *kc = NULL;
1870 static kstat_t *ksp = NULL;
1874 if (kc == NULL) /* if not initialized before */
1879 sm_dprintf("getla: kstat_open(): %s\n",
1880 sm_errstring(errno));
1884 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
1888 sm_dprintf("getla: kstat_lookup(): %s\n",
1889 sm_errstring(errno));
1892 if (kstat_read(kc, ksp, NULL) < 0)
1895 sm_dprintf("getla: kstat_read(): %s\n",
1896 sm_errstring(errno));
1899 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
1900 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
1901 /* kstat_close(kc); /o do not close for fast access */
1905 #endif /* LA_TYPE == LA_KSTAT */
1907 #if LA_TYPE == LA_DEVSHORT
1910 ** Read /dev/table/avenrun for the load average. This should contain
1911 ** three shorts for the 1, 5, and 15 minute loads. We only read the
1912 ** first, since that's all we care about.
1914 ** Intended for SCO OpenServer 5.
1917 # ifndef _PATH_AVENRUN
1918 # define _PATH_AVENRUN "/dev/table/avenrun"
1919 # endif /* ! _PATH_AVENRUN */
1924 static int afd = -1;
1931 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
1935 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
1938 sm_syslog(LOG_ERR, NOQID,
1939 "can't open %s: %s",
1940 _PATH_AVENRUN, sm_errstring(errno));
1945 r = read(afd, &avenrun, sizeof(avenrun));
1946 if (r != sizeof(avenrun))
1948 sm_syslog(LOG_ERR, NOQID,
1949 "can't read %s: %s", _PATH_AVENRUN,
1950 r == -1 ? sm_errstring(errno) : "short read");
1955 sm_dprintf("getla: avenrun = %d\n", avenrun);
1956 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
1958 sm_dprintf("getla: %d\n", loadav);
1962 #endif /* LA_TYPE == LA_DEVSHORT */
1964 #if LA_TYPE == LA_ALPHAOSF
1967 # include <sys/table.h>
1973 struct tbl_loadavg tab;
1975 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
1978 sm_dprintf("getla: table %s\n", sm_errstring(errno));
1983 sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
1986 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
1989 ave = (int) (tab.tl_avenrun.d[2] + 0.5);
1992 sm_dprintf("getla: %d\n", ave);
1997 #endif /* LA_TYPE == LA_ALPHAOSF */
1999 #if LA_TYPE == LA_PSET
2006 if (pset_getloadavg(PS_MYID, avenrun,
2007 sizeof(avenrun) / sizeof(avenrun[0])) < 0)
2010 sm_dprintf("getla: pset_getloadavg failed: %s",
2011 sm_errstring(errno));
2015 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
2016 return ((int) (avenrun[0] + 0.5));
2019 #endif /* LA_TYPE == LA_PSET */
2021 #if LA_TYPE == LA_ZERO
2027 sm_dprintf("getla: ZERO\n");
2031 #endif /* LA_TYPE == LA_ZERO */
2034 * Copyright 1989 Massachusetts Institute of Technology
2036 * Permission to use, copy, modify, distribute, and sell this software and its
2037 * documentation for any purpose is hereby granted without fee, provided that
2038 * the above copyright notice appear in all copies and that both that
2039 * copyright notice and this permission notice appear in supporting
2040 * documentation, and that the name of M.I.T. not be used in advertising or
2041 * publicity pertaining to distribution of the software without specific,
2042 * written prior permission. M.I.T. makes no representations about the
2043 * suitability of this software for any purpose. It is provided "as is"
2044 * without express or implied warranty.
2046 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2047 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2048 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2049 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2050 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2051 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2053 * Authors: Many and varied...
2056 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2058 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2063 # include <apollo/base.h>
2066 int getloadavg( call_data )
2067 caddr_t call_data; /* pointer to (double) return value */
2069 double *avenrun = (double *) call_data;
2074 proc1_$get_loadav(loadav, &st);
2075 *avenrun = loadav[0] / (double) (1 << 16);
2080 ** SM_GETLA -- get the current load average
2089 ** Set CurrentLA to the current load average.
2090 ** Set {load_avg} in GlobalMacros to the current load average.
2098 CurrentLA = getla();
2099 (void) sm_snprintf(labuf, sizeof(labuf), "%d", CurrentLA);
2100 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
2103 ** SHOULDQUEUE -- should this message be queued or sent?
2105 ** Compares the message cost to the load average to decide.
2107 ** Note: Do NOT change this API! It is documented in op.me
2108 ** and theoretically the user can change this function...
2111 ** pri -- the priority of the message in question.
2112 ** ct -- the message creation time (unused, but see above).
2115 ** true -- if this message should be queued up for the
2117 ** false -- if the load is low enough to send this message.
2125 shouldqueue(pri, ct)
2132 #endif /* _FFR_MEMSTAT */
2135 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2139 if (QueueLowMem > 0 &&
2140 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2141 memfree < QueueLowMem)
2144 sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n",
2145 memfree, QueueLowMem);
2148 #endif /* _FFR_MEMSTAT */
2149 if (CurrentLA < QueueLA)
2152 sm_dprintf("false (CurrentLA < QueueLA)\n");
2155 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
2157 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
2162 ** REFUSECONNECTIONS -- decide if connections should be refused
2165 ** e -- the current envelope.
2166 ** dn -- number of daemon.
2167 ** active -- was this daemon actually active?
2170 ** true if incoming SMTP connections should be refused
2172 ** false if we should accept new work.
2175 ** Sets process title when it is rejecting connections.
2179 refuseconnections(e, dn, active)
2184 static time_t lastconn[MAXDAEMONS];
2185 static int conncnt[MAXDAEMONS];
2186 static time_t firstrejtime[MAXDAEMONS];
2187 static time_t nextlogtime[MAXDAEMONS];
2191 #endif /* _FFR_MEMSTAT */
2199 SM_ASSERT(dn < MAXDAEMONS);
2200 if (ConnRateThrottle > 0)
2207 if (now != lastconn[dn])
2212 else if (conncnt[dn]++ > ConnRateThrottle)
2214 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2215 /* sleep to flatten out connection load */
2216 sm_setproctitle(true, e, D_MSG_CRT,
2220 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
2226 else if (now != lastconn[dn])
2232 if (RefuseLowMem > 0 &&
2233 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2234 memfree < RefuseLowMem)
2236 # define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
2237 sm_setproctitle(true, e, R_MSG_LM, Daemons[dn].d_name, memfree);
2239 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM,
2240 Daemons[dn].d_name, memfree);
2243 #endif /* _FFR_MEMSTAT */
2245 limit = (Daemons[dn].d_refuseLA != DPO_NOTSET) ?
2246 Daemons[dn].d_refuseLA : RefuseLA;
2247 if (limit > 0 && CurrentLA >= limit)
2251 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2252 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2253 sm_setproctitle(true, e, R_MSG_LA, Daemons[dn].d_name,
2256 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA,
2257 Daemons[dn].d_name, CurrentLA);
2259 if (firstrejtime[dn] == 0)
2261 firstrejtime[dn] = now;
2262 nextlogtime[dn] = now + RejectLogInterval;
2264 else if (nextlogtime[dn] < now)
2266 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, Daemons[dn].d_name,
2267 pintvl(now - firstrejtime[dn], true));
2268 nextlogtime[dn] = now + RejectLogInterval;
2273 firstrejtime[dn] = 0;
2275 limit = (Daemons[dn].d_delayLA != DPO_NOTSET) ?
2276 Daemons[dn].d_delayLA : DelayLA;
2277 if (limit > 0 && CurrentLA >= limit)
2280 static time_t log_delay = (time_t) 0;
2282 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2283 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2284 /* sleep to flatten out connection load */
2285 sm_setproctitle(true, e, D_MSG_LA, Daemons[dn].d_name, limit);
2286 if (LogLevel > 8 && (now = curtime()) > log_delay)
2288 sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
2289 Daemons[dn].d_name, CurrentLA, limit);
2290 log_delay = now + MIN_DELAY_LOG;
2295 limit = (Daemons[dn].d_maxchildren != DPO_NOTSET) ?
2296 Daemons[dn].d_maxchildren : MaxChildren;
2297 if (limit > 0 && CurChildren >= limit)
2300 if (CurChildren >= limit)
2302 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2303 sm_setproctitle(true, e, R_MSG_CHILD,
2304 Daemons[dn].d_name, CurChildren,
2307 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
2308 Daemons[dn].d_name, CurChildren,
2317 ** SETPROCTITLE -- set process title for ps
2320 ** fmt -- a printf style format string.
2321 ** a, b, c -- possible parameters to fmt.
2327 ** Clobbers argv of our main procedure so ps(1) will
2328 ** display the title.
2331 #define SPT_NONE 0 /* don't use it at all */
2332 #define SPT_REUSEARGV 1 /* cover argv with title information */
2333 #define SPT_BUILTIN 2 /* use libc builtin */
2334 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2335 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2336 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2337 #define SPT_SCO 6 /* write kernel u. area */
2338 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2341 # define SPT_TYPE SPT_REUSEARGV
2342 #endif /* ! SPT_TYPE */
2345 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2347 # if SPT_TYPE == SPT_PSTAT
2348 # include <sys/pstat.h>
2349 # endif /* SPT_TYPE == SPT_PSTAT */
2350 # if SPT_TYPE == SPT_PSSTRINGS
2351 # include <machine/vmparam.h>
2352 # include <sys/exec.h>
2353 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2355 # define SPT_TYPE SPT_REUSEARGV
2356 # else /* ! PS_STRINGS */
2357 # ifndef NKPDE /* FreeBSD 2.0 */
2359 typedef unsigned int *pt_entry_t;
2360 # endif /* ! NKPDE */
2361 # endif /* ! PS_STRINGS */
2362 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2364 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2365 # define SETPROC_STATIC static
2366 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2367 # define SETPROC_STATIC
2368 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2370 # if SPT_TYPE == SPT_SYSMIPS
2371 # include <sys/sysmips.h>
2372 # include <sys/sysnews.h>
2373 # endif /* SPT_TYPE == SPT_SYSMIPS */
2375 # if SPT_TYPE == SPT_SCO
2376 # include <sys/immu.h>
2377 # include <sys/dir.h>
2378 # include <sys/user.h>
2379 # include <sys/fs/s5param.h>
2380 # if PSARGSZ > MAXLINE
2381 # define SPT_BUFSIZE PSARGSZ
2382 # endif /* PSARGSZ > MAXLINE */
2383 # endif /* SPT_TYPE == SPT_SCO */
2385 # ifndef SPT_PADCHAR
2386 # define SPT_PADCHAR ' '
2387 # endif /* ! SPT_PADCHAR */
2389 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2392 # define SPT_BUFSIZE MAXLINE
2393 #endif /* ! SPT_BUFSIZE */
2398 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2399 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2400 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2401 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2402 ** you use this FFR.
2405 # ifdef SPT_ALIGN_SIZE
2406 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2407 # else /* SPT_ALIGN_SIZE */
2408 # define SPT_ALIGN(x, align) (x)
2409 # endif /* SPT_ALIGN_SIZE */
2410 #else /* _FFR_SPT_ALIGN */
2411 # define SPT_ALIGN(x, align) (x)
2412 #endif /* _FFR_SPT_ALIGN */
2415 ** Pointers for setproctitle.
2416 ** This allows "ps" listings to give more useful information.
2419 static char **Argv = NULL; /* pointer to argument vector */
2420 static char *LastArgv = NULL; /* end of argv */
2421 #if SPT_TYPE != SPT_BUILTIN
2422 static void setproctitle __P((const char *, ...));
2423 #endif /* SPT_TYPE != SPT_BUILTIN */
2426 initsetproctitle(argc, argv, envp)
2433 extern char **environ;
2436 ** Move the environment so setproctitle can use the space at
2437 ** the top of memory.
2442 for (i = 0; envp[i] != NULL; i++)
2444 environ = (char **) xalloc(sizeof(char *) * (i + 1));
2445 for (i = 0; envp[i] != NULL; i++)
2446 environ[i] = newstr(envp[i]);
2451 ** Save start and extent of argv for setproctitle.
2457 ** Determine how much space we can use for setproctitle.
2458 ** Use all contiguous argv and envp pointers starting at argv[0]
2463 # ifdef SPT_ALIGN_SIZE
2464 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
2466 # endif /* SPT_ALIGN_SIZE */
2467 # endif /* _FFR_SPT_ALIGN */
2469 for (i = 0; i < argc; i++)
2471 if (i == 0 || LastArgv + 1 == argv[i])
2472 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
2474 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
2476 if (LastArgv + 1 == envp[i])
2477 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
2481 #if SPT_TYPE != SPT_BUILTIN
2486 setproctitle(const char *fmt, ...)
2487 # else /* __STDC__ */
2488 setproctitle(fmt, va_alist)
2491 # endif /* __STDC__ */
2493 # if SPT_TYPE != SPT_NONE
2496 SETPROC_STATIC char buf[SPT_BUFSIZE];
2498 # if SPT_TYPE == SPT_PSTAT
2500 # endif /* SPT_TYPE == SPT_PSTAT */
2501 # if SPT_TYPE == SPT_SCO
2504 static int kmem = -1;
2505 static pid_t kmempid = -1;
2507 # endif /* SPT_TYPE == SPT_SCO */
2511 /* print sendmail: heading for grep */
2512 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
2515 /* print the argument string */
2516 SM_VA_START(ap, fmt);
2517 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
2520 i = (int) strlen(buf);
2524 # if SPT_TYPE == SPT_PSTAT
2525 pst.pst_command = buf;
2526 pstat(PSTAT_SETCMD, pst, i, 0, 0);
2527 # endif /* SPT_TYPE == SPT_PSTAT */
2528 # if SPT_TYPE == SPT_PSSTRINGS
2529 PS_STRINGS->ps_nargvstr = 1;
2530 PS_STRINGS->ps_argvstr = buf;
2531 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2532 # if SPT_TYPE == SPT_SYSMIPS
2533 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
2534 # endif /* SPT_TYPE == SPT_SYSMIPS */
2535 # if SPT_TYPE == SPT_SCO
2536 if (kmem < 0 || kmempid != CurrentPid)
2540 kmem = open(_PATH_KMEM, O_RDWR, 0);
2543 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
2544 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
2550 kmempid = CurrentPid;
2552 buf[PSARGSZ - 1] = '\0';
2553 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
2554 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
2555 (void) write(kmem, buf, PSARGSZ);
2556 # endif /* SPT_TYPE == SPT_SCO */
2557 # if SPT_TYPE == SPT_REUSEARGV
2558 if (LastArgv == NULL)
2561 if (i > LastArgv - Argv[0] - 2)
2563 i = LastArgv - Argv[0] - 2;
2566 (void) sm_strlcpy(Argv[0], buf, i + 1);
2568 while (p < LastArgv)
2571 # endif /* SPT_TYPE == SPT_REUSEARGV */
2572 # if SPT_TYPE == SPT_CHANGEARGV
2575 # endif /* SPT_TYPE == SPT_CHANGEARGV */
2576 # endif /* SPT_TYPE != SPT_NONE */
2579 #endif /* SPT_TYPE != SPT_BUILTIN */
2581 ** SM_SETPROCTITLE -- set process task and set process title for ps
2583 ** Possibly set process status and call setproctitle() to
2584 ** change the ps display.
2587 ** status -- whether or not to store as process status
2588 ** e -- the current envelope.
2589 ** fmt -- a printf style format string.
2590 ** a, b, c -- possible parameters to fmt.
2599 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
2600 #else /* __STDC__ */
2601 sm_setproctitle(status, e, fmt, va_alist)
2606 #endif /* __STDC__ */
2608 char buf[SPT_BUFSIZE];
2611 /* print the argument string */
2612 SM_VA_START(ap, fmt);
2613 (void) sm_vsnprintf(buf, sizeof(buf), fmt, ap);
2617 proc_list_set(CurrentPid, buf);
2619 if (ProcTitlePrefix != NULL)
2621 char prefix[SPT_BUFSIZE];
2623 expand(ProcTitlePrefix, prefix, sizeof(prefix), e);
2624 setproctitle("%s: %s", prefix, buf);
2627 setproctitle("%s", buf);
2630 ** WAITFOR -- wait for a particular process id.
2633 ** pid -- process id to wait for.
2637 ** -1 if pid never shows up.
2655 proc_list_drop(i, st, NULL);
2656 } while ((i >= 0 || errno == EINTR) && i != pid);
2665 ** status -- pointer to status (return value)
2677 # else /* WAITUNION */
2679 # endif /* WAITUNION */
2681 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2683 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2685 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2686 savesig = sm_releasesignal(SIGCHLD);
2687 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2689 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2691 sm_blocksignal(SIGCHLD);
2692 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2694 *status = st.w_status;
2695 # else /* WAITUNION */
2697 # endif /* WAITUNION */
2701 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2704 ** sig -- the signal that got us here (unused).
2710 ** Picks up extant zombies.
2711 ** Control socket exits may restart/shutdown daemon.
2713 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2714 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2723 int save_errno = errno;
2731 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
2736 # else /* HASWAITPID */
2740 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
2742 st = status.w_status;
2743 # else /* WNOHANG */
2747 ** Catch one zombie -- we will be re-invoked (we hope) if there
2748 ** are more. Unreliable signals probably break this, but this
2749 ** is the "old system" situation -- waitpid or wait3 are to be
2750 ** strongly preferred.
2753 if ((pid = wait(&status)) > 0)
2756 # endif /* WNOHANG */
2757 # endif /* HASWAITPID */
2758 /* Drop PID and check if it was a control socket child */
2759 proc_list_drop(pid, st, NULL);
2761 FIX_SYSV_SIGNAL(sig, reapchild);
2763 return SIGFUNC_RETURN;
2766 ** GETDTABLESIZE -- return number of file descriptors
2768 ** Only on non-BSD systems
2774 ** size of file descriptor table
2781 # include <sys/resource.h>
2782 #endif /* SOLARIS */
2787 # ifdef RLIMIT_NOFILE
2790 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
2792 # endif /* RLIMIT_NOFILE */
2794 # if HASGETDTABLESIZE
2795 return getdtablesize();
2796 # else /* HASGETDTABLESIZE */
2797 # ifdef _SC_OPEN_MAX
2798 return sysconf(_SC_OPEN_MAX);
2799 # else /* _SC_OPEN_MAX */
2801 # endif /* _SC_OPEN_MAX */
2802 # endif /* HASGETDTABLESIZE */
2805 ** UNAME -- get the UUCP name of this system.
2812 struct utsname *name;
2817 name->nodename[0] = '\0';
2819 /* try /etc/whoami -- one line with the node name */
2820 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
2821 SM_IO_RDONLY, NULL)) != NULL)
2823 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
2825 (void) sm_io_close(file, SM_TIME_DEFAULT);
2826 n = strchr(name->nodename, '\n');
2829 if (name->nodename[0] != '\0')
2833 /* try /usr/include/whoami.h -- has a #define somewhere */
2834 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
2835 "/usr/include/whoami.h", SM_IO_RDONLY, NULL))
2840 while (sm_io_fgets(file, SM_TIME_DEFAULT,
2841 buf, sizeof(buf)) != NULL)
2843 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
2844 NODE_LENGTH, name->nodename) > 0)
2847 (void) sm_io_close(file, SM_TIME_DEFAULT);
2848 if (name->nodename[0] != '\0')
2854 #endif /* !HASUNAME */
2856 ** INITGROUPS -- initialize groups
2858 ** Stub implementation for System V style systems
2863 initgroups(name, basegid)
2870 #endif /* !HASINITGROUPS */
2872 ** SETGROUPS -- set group list
2874 ** Stub implementation for systems that don't have group lists
2880 setgroups(ngroups, grouplist)
2882 GIDSET_T grouplist[];
2887 #endif /* ! NGROUPS_MAX */
2889 ** SETSID -- set session id (for non-POSIX systems)
2900 fd = open("/dev/tty", O_RDWR, 0);
2903 (void) ioctl(fd, TIOCNOTTY, (char *) 0);
2906 # endif /* TIOCNOTTY */
2909 # else /* SYS5SETPGRP */
2910 return setpgid(0, CurrentPid);
2911 # endif /* SYS5SETPGRP */
2914 #endif /* !HASSETSID */
2916 ** FSYNC -- dummy fsync
2925 return fcntl(fd, F_SETFL, O_SYNC);
2927 /* nothing we can do */
2929 # endif /* O_SYNC */
2932 #endif /* NEEDFSYNC */
2934 ** DGUX_INET_ADDR -- inet_addr for DG/UX
2936 ** Data General DG/UX version of inet_addr returns a struct in_addr
2937 ** instead of a long. This patches things. Only needed on versions
2946 dgux_inet_addr(host)
2949 struct in_addr haddr;
2951 haddr = inet_addr(host);
2952 return haddr.s_addr;
2955 #endif /* DGUX_5_4_2 */
2957 ** GETOPT -- for old systems or systems with bogus implementations
2963 * Copyright (c) 1985 Regents of the University of California.
2964 * All rights reserved. The Berkeley software License Agreement
2965 * specifies the terms and conditions for redistribution.
2970 ** this version hacked to add `atend' flag to allow state machine
2971 ** to reset if invoked by the program to scan args for a 2nd time
2974 # if defined(LIBC_SCCS) && !defined(lint)
2975 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
2976 # endif /* defined(LIBC_SCCS) && !defined(lint) */
2979 ** get option letter from argument vector
2981 # ifdef _CONVEX_SOURCE
2982 extern int optind, opterr, optopt;
2983 extern char *optarg;
2984 # else /* _CONVEX_SOURCE */
2985 int opterr = 1; /* if error message should be printed */
2986 int optind = 1; /* index into parent argv vector */
2987 int optopt = 0; /* character checked for validity */
2988 char *optarg = NULL; /* argument associated with option */
2989 # endif /* _CONVEX_SOURCE */
2991 # define BADCH (int)'?'
2993 # define tell(s) if (opterr) \
2994 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
2995 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
2996 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
2997 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
3001 getopt(nargc,nargv,ostr)
3006 static char *place = EMSG; /* option letter processing */
3007 static char atend = 0;
3008 register char *oli = NULL; /* option letter list index */
3014 if(!*place) { /* update scanning pointer */
3015 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
3019 if (*place == '-') { /* found "--" */
3024 } /* option letter okay? */
3025 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
3026 if (!*place) ++optind;
3027 tell(": illegal option -- ");
3029 if (oli && *++oli != ':') { /* don't need argument */
3031 if (!*place) ++optind;
3033 else { /* need an argument */
3034 if (*place) optarg = place; /* no white space */
3035 else if (nargc <= ++optind) { /* no arg */
3037 tell(": option requires an argument -- ");
3039 else optarg = nargv[optind]; /* white space */
3043 return optopt; /* dump back option letter */
3046 #endif /* !SM_CONF_GETOPT */
3048 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3051 ** user -- the name of the user we are checking.
3052 ** shell -- the user's shell from /etc/passwd
3055 ** true -- if it is ok to use this for unrestricted access.
3056 ** false -- if the shell is restricted.
3059 #if !HASGETUSERSHELL
3061 # ifndef _PATH_SHELLS
3062 # define _PATH_SHELLS "/etc/shells"
3063 # endif /* ! _PATH_SHELLS */
3065 # if defined(_AIX3) || defined(_AIX4)
3066 # include <userconf.h>
3068 # include <userpw.h>
3069 # endif /* _AIX4 >= 40200 */
3070 # include <usersec.h>
3071 # endif /* defined(_AIX3) || defined(_AIX4) */
3073 static char *DefaultUserShells[] =
3075 "/bin/sh", /* standard shell */
3080 "/bin/csh", /* C shell */
3085 "/usr/bin/rsh", /* restricted Bourne shell */
3086 "/usr/bin/ksh", /* Korn shell */
3087 "/usr/bin/rksh", /* restricted Korn shell */
3089 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3090 "/usr/bin/posix/sh",
3092 "/bin/rsh", /* restricted Bourne shell */
3093 "/bin/ksh", /* Korn shell */
3094 "/bin/rksh", /* restricted Korn shell */
3096 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3100 # endif /* __hpux */
3101 # if defined(_AIX3) || defined(_AIX4)
3102 "/bin/ksh", /* Korn shell */
3104 "/bin/tsh", /* trusted shell */
3106 "/bin/bsh", /* Bourne shell */
3108 # endif /* defined(_AIX3) || defined(_AIX4) */
3109 # if defined(__svr4__) || defined(__svr5__)
3110 "/bin/ksh", /* Korn shell */
3112 # endif /* defined(__svr4__) || defined(__svr5__) */
3114 "/sbin/sh", /* SGI's shells really live in /sbin */
3116 "/sbin/bsh", /* classic Bourne shell */
3119 "/sbin/csh", /* standard csh */
3122 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3125 "/bin/ksh", /* Korn shell */
3128 "/sbin/tcsh", /* Extended csh */
3135 #endif /* !HASGETUSERSHELL */
3137 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3140 usershellok(user, shell)
3144 # if HASGETUSERSHELL
3146 extern char *getusershell();
3148 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3153 while ((p = getusershell()) != NULL)
3154 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
3158 # else /* HASGETUSERSHELL */
3161 # endif /* USEGETCONFATTR */
3162 register SM_FILE_T *shellf;
3165 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3171 ** Naturally IBM has a "better" idea.....
3173 ** What a crock. This interface isn't documented, it is
3174 ** considered part of the security library (-ls), and it
3175 ** only works if you are running as root (since the list
3176 ** of valid shells is obviously a source of great concern).
3177 ** I recommend that you do NOT define USEGETCONFATTR,
3178 ** especially since you are going to have to set up an
3179 ** /etc/shells anyhow to handle the cases where getconfattr
3183 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
3187 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
3193 # endif /* USEGETCONFATTR */
3195 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
3196 SM_IO_RDONLY, NULL);
3199 /* no /etc/shells; see if it is one of the std shells */
3202 if (errno != ENOENT && LogLevel > 3)
3203 sm_syslog(LOG_ERR, NOQID,
3204 "usershellok: cannot open %s: %s",
3205 _PATH_SHELLS, sm_errstring(errno));
3207 for (d = DefaultUserShells; *d != NULL; d++)
3209 if (strcmp(shell, *d) == 0)
3215 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
3217 register char *p, *q;
3220 while (*p != '\0' && *p != '#' && *p != '/')
3222 if (*p == '#' || *p == '\0')
3225 while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
3228 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
3230 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3234 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3236 # endif /* HASGETUSERSHELL */
3239 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3241 ** Only implemented if you have statfs.
3244 ** dir -- the directory in question.
3245 ** bsize -- a variable into which the filesystem
3246 ** block size is stored.
3249 ** The number of blocks free on the queue filesystem.
3250 ** -1 if the statfs call fails.
3253 ** Puts the filesystem block size into bsize.
3257 # define SFS_NONE 0 /* no statfs implementation */
3258 # define SFS_USTAT 1 /* use ustat */
3259 # define SFS_4ARGS 2 /* use four-argument statfs call */
3260 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3261 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3262 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3263 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3266 # define SFS_TYPE SFS_NONE
3267 # endif /* ! SFS_TYPE */
3269 # if SFS_TYPE == SFS_USTAT
3271 # endif /* SFS_TYPE == SFS_USTAT */
3272 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3273 # include <sys/statfs.h>
3274 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
3275 # if SFS_TYPE == SFS_VFS
3276 # include <sys/vfs.h>
3277 # endif /* SFS_TYPE == SFS_VFS */
3278 # if SFS_TYPE == SFS_MOUNT
3279 # include <sys/mount.h>
3280 # endif /* SFS_TYPE == SFS_MOUNT */
3281 # if SFS_TYPE == SFS_STATVFS
3282 # include <sys/statvfs.h>
3283 # endif /* SFS_TYPE == SFS_STATVFS */
3286 freediskspace(dir, bsize)
3290 # if SFS_TYPE == SFS_NONE
3294 /* assume free space is plentiful */
3295 return (long) LONG_MAX;
3296 # else /* SFS_TYPE == SFS_NONE */
3297 # if SFS_TYPE == SFS_USTAT
3299 struct stat statbuf;
3300 # define FSBLOCKSIZE DEV_BSIZE
3301 # define SFS_BAVAIL f_tfree
3302 # else /* SFS_TYPE == SFS_USTAT */
3303 # if defined(ultrix)
3305 # define SFS_BAVAIL fd_bfreen
3306 # define FSBLOCKSIZE 1024L
3307 # else /* defined(ultrix) */
3308 # if SFS_TYPE == SFS_STATVFS
3310 # define FSBLOCKSIZE fs.f_frsize
3311 # else /* SFS_TYPE == SFS_STATVFS */
3313 # define FSBLOCKSIZE fs.f_bsize
3314 # endif /* SFS_TYPE == SFS_STATVFS */
3315 # endif /* defined(ultrix) */
3316 # endif /* SFS_TYPE == SFS_USTAT */
3318 # define SFS_BAVAIL f_bavail
3319 # endif /* ! SFS_BAVAIL */
3321 # if SFS_TYPE == SFS_USTAT
3322 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
3323 # else /* SFS_TYPE == SFS_USTAT */
3324 # if SFS_TYPE == SFS_4ARGS
3325 if (statfs(dir, &fs, sizeof(fs), 0) == 0)
3326 # else /* SFS_TYPE == SFS_4ARGS */
3327 # if SFS_TYPE == SFS_STATVFS
3328 if (statvfs(dir, &fs) == 0)
3329 # else /* SFS_TYPE == SFS_STATVFS */
3330 # if defined(ultrix)
3331 if (statfs(dir, &fs) > 0)
3332 # else /* defined(ultrix) */
3333 if (statfs(dir, &fs) == 0)
3334 # endif /* defined(ultrix) */
3335 # endif /* SFS_TYPE == SFS_STATVFS */
3336 # endif /* SFS_TYPE == SFS_4ARGS */
3337 # endif /* SFS_TYPE == SFS_USTAT */
3340 *bsize = FSBLOCKSIZE;
3341 if (fs.SFS_BAVAIL <= 0)
3343 else if (fs.SFS_BAVAIL > LONG_MAX)
3344 return (long) LONG_MAX;
3346 return (long) fs.SFS_BAVAIL;
3349 # endif /* SFS_TYPE == SFS_NONE */
3352 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3355 ** msize -- the size to check against. If zero, we don't yet
3356 ** know how big the message will be, so just check for
3357 ** a "reasonable" amount.
3358 ** e -- envelope, or NULL -- controls logging
3361 ** true if in every queue group there is at least one
3362 ** queue directory whose file system contains enough free space.
3366 ** If there is not enough disk space and e != NULL
3367 ** then sm_syslog is called.
3371 enoughdiskspace(msize, e)
3377 if (MinBlocksFree <= 0 && msize <= 0)
3380 sm_dprintf("enoughdiskspace: no threshold\n");
3385 for (i = 0; i < NumQueue; ++i)
3387 if (pickqdir(Queue[i], msize, e) < 0)
3393 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3395 ** This looks at an errno value and tells if this is likely to
3396 ** go away if retried later.
3399 ** err -- the errno code to classify.
3402 ** true if this is probably transient.
3412 case EIO: /* I/O error */
3413 case ENXIO: /* Device not configured */
3414 case EAGAIN: /* Resource temporarily unavailable */
3415 case ENOMEM: /* Cannot allocate memory */
3416 case ENODEV: /* Operation not supported by device */
3417 case ENFILE: /* Too many open files in system */
3418 case EMFILE: /* Too many open files */
3419 case ENOSPC: /* No space left on device */
3420 case ETIMEDOUT: /* Connection timed out */
3422 case ESTALE: /* Stale NFS file handle */
3425 case ENETDOWN: /* Network is down */
3426 #endif /* ENETDOWN */
3428 case ENETUNREACH: /* Network is unreachable */
3429 #endif /* ENETUNREACH */
3431 case ENETRESET: /* Network dropped connection on reset */
3432 #endif /* ENETRESET */
3434 case ECONNABORTED: /* Software caused connection abort */
3435 #endif /* ECONNABORTED */
3437 case ECONNRESET: /* Connection reset by peer */
3438 #endif /* ECONNRESET */
3440 case ENOBUFS: /* No buffer space available */
3441 #endif /* ENOBUFS */
3443 case ESHUTDOWN: /* Can't send after socket shutdown */
3444 #endif /* ESHUTDOWN */
3446 case ECONNREFUSED: /* Connection refused */
3447 #endif /* ECONNREFUSED */
3449 case EHOSTDOWN: /* Host is down */
3450 #endif /* EHOSTDOWN */
3452 case EHOSTUNREACH: /* No route to host */
3453 #endif /* EHOSTUNREACH */
3455 case EDQUOT: /* Disc quota exceeded */
3458 case EPROCLIM: /* Too many processes */
3459 #endif /* EPROCLIM */
3461 case EUSERS: /* Too many users */
3464 case EDEADLK: /* Resource deadlock avoided */
3465 #endif /* EDEADLK */
3467 case EISCONN: /* Socket already connected */
3468 #endif /* EISCONN */
3470 case EINPROGRESS: /* Operation now in progress */
3471 #endif /* EINPROGRESS */
3473 case EALREADY: /* Operation already in progress */
3474 #endif /* EALREADY */
3476 case EADDRINUSE: /* Address already in use */
3477 #endif /* EADDRINUSE */
3478 #ifdef EADDRNOTAVAIL
3479 case EADDRNOTAVAIL: /* Can't assign requested address */
3480 #endif /* EADDRNOTAVAIL */
3482 case ETXTBSY: /* (Apollo) file locked */
3483 #endif /* ETXTBSY */
3484 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3485 case ENOSR: /* Out of streams resources */
3486 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
3488 case ENOLCK: /* No locks available */
3490 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
3494 /* nope, must be permanent */
3498 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3501 ** fd -- the file descriptor of the file.
3502 ** filename -- the file name (for error messages).
3503 ** ext -- the filename extension.
3504 ** type -- type of the lock. Bits can be:
3505 ** LOCK_EX -- exclusive lock.
3506 ** LOCK_NB -- non-blocking.
3507 ** LOCK_UN -- unlock.
3510 ** true if the lock was acquired.
3515 lockfile(fd, filename, ext, type)
3530 memset(&lfd, '\0', sizeof(lfd));
3531 if (bitset(LOCK_UN, type))
3532 lfd.l_type = F_UNLCK;
3533 else if (bitset(LOCK_EX, type))
3534 lfd.l_type = F_WRLCK;
3536 lfd.l_type = F_RDLCK;
3538 if (bitset(LOCK_NB, type))
3544 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
3545 filename, ext, action, lfd.l_type);
3547 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
3552 sm_dprintf("SUCCESS\n");
3558 sm_dprintf("(%s) ", sm_errstring(save_errno));
3561 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3562 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3563 ** as type "tmp" (that is, served from swap space), the
3564 ** previous fcntl will fail with "Invalid argument" errors.
3565 ** Since this is fairly common during testing, we will assume
3566 ** that this indicates that the lock is successfully grabbed.
3569 if (save_errno == EINVAL)
3572 sm_dprintf("SUCCESS\n");
3576 if (!bitset(LOCK_NB, type) ||
3577 (save_errno != EACCES && save_errno != EAGAIN))
3579 int omode = fcntl(fd, F_GETFL, 0);
3580 uid_t euid = geteuid();
3583 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3584 filename, ext, fd, type, omode, euid);
3585 dumpfd(fd, true, true);
3587 # else /* !HASFLOCK */
3592 sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
3594 while ((i = flock(fd, type)) < 0 && errno == EINTR)
3599 sm_dprintf("SUCCESS\n");
3605 sm_dprintf("(%s) ", sm_errstring(save_errno));
3607 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
3609 int omode = fcntl(fd, F_GETFL, 0);
3610 uid_t euid = geteuid();
3613 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3614 filename, ext, fd, type, omode, euid);
3615 dumpfd(fd, true, true);
3617 # endif /* !HASFLOCK */
3619 sm_dprintf("FAIL\n");
3624 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3626 ** Unfortunately, given that we can't predict other systems on which
3627 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3628 ** almost always that this is unsafe.
3630 ** Note also that many operating systems have non-compliant
3631 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3632 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3633 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3634 ** no non-root process can give away the file. However, vendors
3635 ** don't take NFS into account, so a comfortable value of
3636 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3638 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3639 ** even on files where chown is not restricted. Many systems get
3640 ** this wrong on NFS-based filesystems (that is, they say that chown
3641 ** is restricted [safe] on NFS filesystems where it may not be, since
3642 ** other systems can access the same filesystem and do file giveaway;
3643 ** only the NFS server knows for sure!) Hence, it is important to
3644 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3645 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3646 ** NFS-based filesystem to ensure that you can get meaningful results.
3647 ** If in doubt, assume unsafe!
3649 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3650 ** condition indicating whether the return from pathconf indicates
3651 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3652 ** even any agreement about whether a zero return means that a file
3653 ** is or is not safe). It defaults to "> 0".
3655 ** If the parent directory is safe (writable only by owner back
3656 ** to the root) then we can relax slightly and trust fpathconf
3657 ** in more circumstances. This is really a crock -- if this is an
3658 ** NFS mounted filesystem then we really know nothing about the
3659 ** underlying implementation. However, most systems pessimize and
3660 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3661 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3662 ** us into a possible problem only on systems that have a broken
3663 ** pathconf implementation and which are also poorly configured
3664 ** (have :include: files in group- or world-writable directories).
3667 ** fd -- the file descriptor to check.
3668 ** safedir -- set if the parent directory is safe.
3671 ** true -- if the chown(2) operation is "safe" -- that is,
3672 ** only root can chown the file to an arbitrary user.
3673 ** false -- if an arbitrary user can give away a file.
3676 #ifndef IS_SAFE_CHOWN
3677 # define IS_SAFE_CHOWN > 0
3678 #endif /* ! IS_SAFE_CHOWN */
3681 chownsafe(fd, safedir)
3685 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3686 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3689 /* give the system administrator a chance to override */
3690 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
3694 ** Some systems (e.g., SunOS) seem to have the call and the
3695 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3696 ** the call. This heuristic checks for that.
3700 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
3701 # if SAFENFSPATHCONF
3702 return errno == 0 && rval IS_SAFE_CHOWN;
3703 # else /* SAFENFSPATHCONF */
3704 return safedir && errno == 0 && rval IS_SAFE_CHOWN;
3705 # endif /* SAFENFSPATHCONF */
3706 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3707 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
3708 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3711 ** RESETLIMITS -- reset system controlled resource limits
3713 ** This is to avoid denial-of-service attacks
3723 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3724 # include <sm/time.h>
3725 # endif /* RLIMIT_NEEDS_SYS_TIME_H */
3726 # include <sys/resource.h>
3727 #endif /* HASSETRLIMIT */
3735 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
3736 (void) setrlimit(RLIMIT_CPU, &lim);
3737 (void) setrlimit(RLIMIT_FSIZE, &lim);
3738 # ifdef RLIMIT_NOFILE
3739 lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
3740 (void) setrlimit(RLIMIT_NOFILE, &lim);
3741 # endif /* RLIMIT_NOFILE */
3742 #else /* HASSETRLIMIT */
3744 (void) ulimit(2, 0x3fffff);
3745 (void) ulimit(4, FD_SETSIZE);
3746 # endif /* HASULIMIT */
3747 #endif /* HASSETRLIMIT */
3751 ** SETVENDOR -- process vendor code from V configuration line
3754 ** vendor -- string representation of vendor.
3758 ** false -- if vendor code could not be processed.
3761 ** It is reasonable to set mode flags here to tweak
3762 ** processing in other parts of the code if necessary.
3763 ** For example, if you are a vendor that uses $%y to
3764 ** indicate YP lookups, you could enable that here.
3771 if (sm_strcasecmp(vendor, "Berkeley") == 0)
3773 VendorCode = VENDOR_BERKELEY;
3777 /* add vendor extensions here */
3779 #ifdef SUN_EXTENSIONS
3780 if (sm_strcasecmp(vendor, "Sun") == 0)
3782 VendorCode = VENDOR_SUN;
3785 #endif /* SUN_EXTENSIONS */
3787 if (sm_strcasecmp(vendor, "Digital") == 0)
3789 VendorCode = VENDOR_DEC;
3794 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3795 if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
3797 VendorCode = VENDOR_CODE;
3800 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3805 ** GETVENDOR -- return vendor name based on vendor code
3808 ** vendorcode -- numeric representation of vendor.
3811 ** string containing vendor name.
3815 getvendor(vendorcode)
3818 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3820 ** Can't have the same switch case twice so need to
3821 ** handle VENDOR_CODE outside of switch. It might
3822 ** match one of the existing VENDOR_* codes.
3825 if (vendorcode == VENDOR_CODE)
3827 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3831 case VENDOR_BERKELEY:
3843 case VENDOR_SENDMAIL:
3851 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3853 ** Vendor_pre_defaults is called before reading the configuration
3854 ** file; vendor_post_defaults is called immediately after.
3857 ** e -- the global environment to initialize.
3864 int DefShareUid; /* default share uid to run as -- unused??? */
3865 #endif /* SHARE_V1 */
3868 vendor_pre_defaults(e)
3872 /* OTHERUID is defined in shares.h, do not be alarmed */
3873 DefShareUid = OTHERUID;
3874 #endif /* SHARE_V1 */
3875 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3876 sun_pre_defaults(e);
3877 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3880 ** stupid domain/os can't even open
3881 ** /etc/mail/sendmail.cf without this
3884 sm_setuserenv("ISP", NULL);
3885 sm_setuserenv("SYSTYPE", NULL);
3891 vendor_post_defaults(e)
3895 /* Makes sure the SOCK environment variable remains */
3896 sm_setuserenv("SOCK", NULL);
3897 #endif /* __QNX__ */
3898 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3899 sun_post_defaults(e);
3900 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3903 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
3907 vendor_daemon_setup(e)
3911 (void) setlogin(RunAsUserName);
3912 #endif /* HASSETLOGIN */
3914 if (getluid() != -1)
3916 usrerr("Daemon cannot have LUID");
3917 finis(false, true, EX_USAGE);
3919 #endif /* SECUREWARE */
3922 ** VENDOR_SET_UID -- do setup for setting a user id
3924 ** This is called when we are still root.
3927 ** uid -- the uid we are about to become.
3938 ** We need to setup the share groups (lnodes)
3939 ** and add auditing information (luid's)
3940 ** before we loose our ``root''ness.
3943 if (setupshares(uid, syserr) != 0)
3944 syserr("Unable to set up shares");
3945 #endif /* SHARE_V1 */
3947 (void) setup_secure(uid);
3948 #endif /* SECUREWARE */
3951 ** VALIDATE_CONNECTION -- check connection for rationality
3953 ** If the connection is rejected, this routine should log an
3954 ** appropriate message -- but should never issue any SMTP protocol.
3957 ** sap -- a pointer to a SOCKADDR naming the peer.
3958 ** hostname -- the name corresponding to sap.
3959 ** e -- the current envelope.
3962 ** error message from rejection.
3963 ** NULL if not rejected.
3969 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
3970 int allow_severity = LOG_INFO;
3971 int deny_severity = LOG_NOTICE;
3972 #endif /* TCPWRAPPERS */
3975 validate_connection(sap, hostname, e)
3983 extern int hosts_ctl();
3984 #endif /* TCPWRAPPERS */
3987 sm_dprintf("validate_connection(%s, %s)\n",
3988 hostname, anynet_ntoa(sap));
3990 connection_rate_check(sap, e);
3991 if (rscheck("check_relay", hostname, anynet_ntoa(sap),
3992 e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID, NULL) != EX_OK)
3994 static char reject[BUFSIZ*2];
3995 extern char MsgBuf[];
3998 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
4000 if (strlen(MsgBuf) >= 3)
4001 (void) sm_strlcpy(reject, MsgBuf, sizeof(reject));
4003 (void) sm_strlcpy(reject, "Access denied", sizeof(reject));
4009 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
4013 addr = anynet_ntoa(sap);
4016 /* TCP/Wrappers don't want the IPv6: protocol label */
4017 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
4019 # endif /* NETINET6 */
4021 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
4024 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4026 sm_syslog(LOG_NOTICE, e->e_id,
4027 "tcpwrappers (%s, %s) rejection",
4029 return "Access denied";
4031 #endif /* TCPWRAPPERS */
4033 sm_dprintf(" ... validate_connection: OK\n");
4038 ** STRTOL -- convert string to long integer
4040 ** For systems that don't have it in the C library.
4042 ** This is taken verbatim from the 4.4-Lite C library.
4047 # if defined(LIBC_SCCS) && !defined(lint)
4048 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4049 # endif /* defined(LIBC_SCCS) && !defined(lint) */
4052 ** Convert a string to a long integer.
4054 ** Ignores `locale' stuff. Assumes that the upper and lower case
4055 ** alphabets and digits are each contiguous.
4059 strtol(nptr, endptr, base)
4064 register const char *s = nptr;
4065 register unsigned long acc;
4067 register unsigned long cutoff;
4068 register int neg = 0, any, cutlim;
4071 ** Skip white space and pick up leading +/- sign if any.
4072 ** If base is 0, allow 0x for hex and 0 for octal, else
4073 ** assume decimal; if base is already 16, allow 0x.
4077 } while (isspace(c));
4081 } else if (c == '+')
4083 if ((base == 0 || base == 16) &&
4084 c == '0' && (*s == 'x' || *s == 'X')) {
4090 base = c == '0' ? 8 : 10;
4093 ** Compute the cutoff value between legal numbers and illegal
4094 ** numbers. That is the largest legal value, divided by the
4095 ** base. An input number that is greater than this value, if
4096 ** followed by a legal input character, is too big. One that
4097 ** is equal to this value may be valid or not; the limit
4098 ** between valid and invalid numbers is then based on the last
4099 ** digit. For instance, if the range for longs is
4100 ** [-2147483648..2147483647] and the input base is 10,
4101 ** cutoff will be set to 214748364 and cutlim to either
4102 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4103 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4104 ** the number is too big, and we will return a range error.
4106 ** Set any if any `digits' consumed; make it negative to indicate
4109 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
4110 cutlim = cutoff % (unsigned long) base;
4111 cutoff /= (unsigned long) base;
4112 for (acc = 0, any = 0;; c = *s++) {
4115 else if (isalpha(c))
4116 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
4121 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
4130 acc = neg ? LONG_MIN : LONG_MAX;
4135 *endptr = (char *)(any ? s - 1 : nptr);
4139 #endif /* NEEDSTRTOL */
4141 ** STRSTR -- find first substring in string
4144 ** big -- the big (full) string.
4145 ** little -- the little (sub) string.
4148 ** A pointer to the first instance of little in big.
4149 ** big if little is the null string.
4150 ** NULL if little is not contained in big.
4160 register char *p = big;
4163 if (*little == '\0')
4167 while ((p = strchr(p, *little)) != NULL)
4169 if (strncmp(p, little, l) == 0)
4176 #endif /* NEEDSTRSTR */
4178 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4180 ** Some operating systems have wierd problems with the gethostbyXXX
4181 ** routines. For example, Solaris versions at least through 2.3
4182 ** don't properly deliver a canonical h_name field. This tries to
4183 ** work around these problems.
4185 ** Support IPv6 as well as IPv4.
4188 #if NETINET6 && NEEDSGETIPNODE
4191 # define AI_DEFAULT 0 /* dummy */
4192 # endif /* ! AI_DEFAULT */
4193 # ifndef AI_ADDRCONFIG
4194 # define AI_ADDRCONFIG 0 /* dummy */
4195 # endif /* ! AI_ADDRCONFIG */
4196 # ifndef AI_V4MAPPED
4197 # define AI_V4MAPPED 0 /* dummy */
4198 # endif /* ! AI_V4MAPPED */
4200 # define AI_ALL 0 /* dummy */
4201 # endif /* ! AI_ALL */
4203 static struct hostent *
4204 getipnodebyname(name, family, flags, err)
4213 if (family == AF_INET6)
4215 /* From RFC2133, section 6.1 */
4216 resv6 = bitset(RES_USE_INET6, _res.options);
4217 _res.options |= RES_USE_INET6;
4220 h = gethostbyname(name);
4222 _res.options &= ~RES_USE_INET6;
4227 static struct hostent *
4228 getipnodebyaddr(addr, len, family, err)
4237 h = gethostbyaddr(addr, len, family);
4247 ** Stub routine -- if they don't have getipnodeby*(),
4248 ** they probably don't have the free routine either.
4253 #endif /* NETINET6 && NEEDSGETIPNODE */
4256 sm_gethostbyname(name, family)
4261 struct hostent *h = NULL;
4262 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4263 # if SOLARIS == 20300 || SOLARIS == 203
4264 static struct hostent hp;
4265 static char buf[1000];
4266 extern struct hostent *_switch_gethostbyname_r();
4269 sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
4270 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
4272 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4273 extern struct hostent *__switch_gethostbyname();
4276 sm_dprintf("__switch_gethostbyname(%s)... ", name);
4277 h = __switch_gethostbyname(name);
4279 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4280 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4283 int flags = AI_DEFAULT|AI_ALL;
4285 # endif /* NETINET6 */
4286 char *maptype[MAXMAPSTACK];
4287 short mapreturn[MAXMAPACTIONS];
4291 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
4294 # if ADDRCONFIG_IS_BROKEN
4295 flags &= ~AI_ADDRCONFIG;
4296 # endif /* ADDRCONFIG_IS_BROKEN */
4297 h = getipnodebyname(name, family, flags, &err);
4298 SM_SET_H_ERRNO(err);
4299 # else /* NETINET6 */
4300 h = gethostbyname(name);
4301 # endif /* NETINET6 */
4307 sm_dprintf("failure\n");
4309 nmaps = switch_map_find("hosts", maptype, mapreturn);
4310 while (--nmaps >= 0)
4312 if (strcmp(maptype[nmaps], "nis") == 0 ||
4313 strcmp(maptype[nmaps], "files") == 0)
4319 /* try short name */
4320 if (strlen(name) > sizeof(hbuf) - 1)
4325 (void) sm_strlcpy(hbuf, name, sizeof(hbuf));
4326 (void) shorten_hostname(hbuf);
4328 /* if it hasn't been shortened, there's no point */
4329 if (strcmp(hbuf, name) != 0)
4332 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4336 h = getipnodebyname(hbuf, family, flags, &err);
4337 SM_SET_H_ERRNO(err);
4339 # else /* NETINET6 */
4340 h = gethostbyname(hbuf);
4342 # endif /* NETINET6 */
4346 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4350 sm_dprintf("failure\n");
4353 sm_dprintf("%s\n", h->h_name);
4357 struct in6_addr ia6;
4358 char buf6[INET6_ADDRSTRLEN];
4359 #else /* NETINET6 */
4361 #endif /* NETINET6 */
4364 if (h->h_aliases != NULL)
4365 for (i = 0; h->h_aliases[i] != NULL;
4367 sm_dprintf("\talias: %s\n",
4369 for (i = 0; h->h_addr_list[i] != NULL; i++)
4374 memmove(&ia6, h->h_addr_list[i],
4376 addr = anynet_ntop(&ia6,
4377 buf6, sizeof(buf6));
4378 #else /* NETINET6 */
4379 memmove(&ia, h->h_addr_list[i],
4381 addr = (char *) inet_ntoa(ia);
4382 #endif /* NETINET6 */
4384 sm_dprintf("\taddr: %s\n", addr);
4394 sm_gethostbyaddr(addr, len, type)
4402 if (type == AF_INET6 &&
4403 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
4405 /* Avoid reverse lookup for IPv6 unspecified address */
4406 SM_SET_H_ERRNO(HOST_NOT_FOUND);
4409 #endif /* NETINET6 */
4411 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4412 # if SOLARIS == 20300 || SOLARIS == 203
4414 static struct hostent he;
4415 static char buf[1000];
4416 extern struct hostent *_switch_gethostbyaddr_r();
4418 hp = _switch_gethostbyaddr_r(addr, len, type, &he,
4419 buf, sizeof(buf), &h_errno);
4421 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4423 extern struct hostent *__switch_gethostbyaddr();
4425 hp = __switch_gethostbyaddr(addr, len, type);
4427 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4428 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4433 hp = getipnodebyaddr(addr, len, type, &err);
4434 SM_SET_H_ERRNO(err);
4436 # else /* NETINET6 */
4437 hp = gethostbyaddr(addr, len, type);
4438 # endif /* NETINET6 */
4439 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4443 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4451 extern struct passwd *_getpwnam_shadow(const char *, const int);
4453 return _getpwnam_shadow(user, 0);
4455 return getpwnam(user);
4463 #if defined(_AIX4) && 0
4464 extern struct passwd *_getpwuid_shadow(const int, const int);
4466 return _getpwuid_shadow(uid,0);
4467 #else /* defined(_AIX4) && 0 */
4468 return getpwuid(uid);
4469 #endif /* defined(_AIX4) && 0 */
4472 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4474 ** Set up the trusted computing environment for C2 level security
4475 ** under SecureWare.
4478 ** uid -- uid of the user to initialize in the TCB
4484 ** Initialized the user in the trusted computing base
4489 # include <sys/security.h>
4493 secureware_setup_secure(uid)
4498 if (getluid() != -1)
4501 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
4505 case SSI_NO_PRPW_ENTRY:
4506 syserr("No protected passwd entry, uid = %d",
4511 syserr("Account has been disabled, uid = %d",
4516 syserr("Account has been retired, uid = %d",
4520 case SSI_BAD_SET_LUID:
4521 syserr("Could not set LUID, uid = %d", (int) uid);
4524 case SSI_BAD_SET_PRIVS:
4525 syserr("Could not set kernel privs, uid = %d",
4529 syserr("Unknown return code (%d) from set_secure_info(%d)",
4533 finis(false, true, EX_NOPERM);
4536 #endif /* SECUREWARE */
4538 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4540 ** Add hostnames to class 'w' based on the IP address read from
4541 ** the network interface.
4544 ** sa -- a pointer to a SOCKADDR containing the address
4547 ** 0 if successful, -1 if host lookup fails.
4556 char hnb[MAXHOSTNAMELEN];
4558 /* lookup name with IP address */
4559 switch (sa->sa.sa_family)
4563 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
4564 sizeof(sa->sin.sin_addr),
4567 #endif /* NETINET */
4571 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
4572 sizeof(sa->sin6.sin6_addr),
4575 #endif /* NETINET6 */
4578 /* Give warning about unsupported family */
4580 sm_syslog(LOG_WARNING, NOQID,
4581 "Unsupported address family %d: %.100s",
4582 sa->sa.sa_family, anynet_ntoa(sa));
4588 int save_errno = errno;
4592 !(sa->sa.sa_family == AF_INET6 &&
4593 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
4594 #endif /* NETINET6 */
4596 sm_syslog(LOG_WARNING, NOQID,
4597 "gethostbyaddr(%.100s) failed: %d",
4601 #else /* NAMED_BIND */
4603 #endif /* NAMED_BIND */
4609 /* save its cname */
4610 if (!wordinclass((char *) hp->h_name, 'w'))
4612 setclass('w', (char *) hp->h_name);
4614 sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
4616 if (sm_snprintf(hnb, sizeof(hnb), "[%s]", hp->h_name) <
4618 && !wordinclass((char *) hnb, 'w'))
4624 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
4627 /* save all it aliases name */
4628 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
4630 if (!wordinclass(*ha, 'w'))
4634 sm_dprintf("\ta.k.a.: %s\n", *ha);
4635 if (sm_snprintf(hnb, sizeof(hnb),
4636 "[%s]", *ha) < sizeof(hnb) &&
4637 !wordinclass((char *) hnb, 'w'))
4643 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4649 #endif /* NETINET6 */
4653 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4662 ** Loads $=w with the names of all the interfaces.
4666 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4667 #endif /* !NETINET */
4669 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4673 # include <sm/time.h>
4674 # endif /* ! SUNOS403 */
4675 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4677 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
4678 # include <net/if.h>
4679 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4684 # if NETINET6 && defined(SIOCGLIFCONF)
4688 ** Unfortunately, HP has changed all of the structures,
4689 ** making life difficult for implementors.
4692 # define lifconf if_laddrconf
4693 # define lifc_len iflc_len
4694 # define lifc_buf iflc_buf
4695 # define lifreq if_laddrreq
4696 # define lifr_addr iflr_addr
4697 # define lifr_name iflr_name
4698 # define lifr_flags iflr_flags
4699 # define ss_family sa_family
4701 # endif /* __hpux */
4708 struct lifconf lifc;
4711 # endif /* SIOCGLIFNUM */
4713 s = socket(InetMode, SOCK_DGRAM, 0);
4717 /* get the list of known IP address from the kernel */
4719 i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
4720 # endif /* __hpux */
4722 lifn.lifn_family = AF_UNSPEC;
4723 lifn.lifn_flags = 0;
4724 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
4725 numifs = lifn.lifn_count;
4726 # endif /* SIOCGLIFNUM */
4728 # if defined(__hpux) || defined(SIOCGLIFNUM)
4731 /* can't get number of interfaces -- fall back */
4733 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4734 sm_errstring(errno));
4737 else if (tTd(0, 42))
4738 sm_dprintf("system has %d interfaces\n", numifs);
4740 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4741 numifs = MAXINTERFACES;
4749 len = lifc.lifc_len = numifs * sizeof(struct lifreq);
4750 buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
4752 lifc.lifc_family = AF_UNSPEC;
4753 lifc.lifc_flags = 0;
4754 # endif /* ! __hpux */
4755 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
4758 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4759 sm_errstring(errno));
4765 /* scan the list of IP address */
4767 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4770 for (i = 0; i < len && i >= 0; )
4773 struct lifreq *ifr = (struct lifreq *)&buf[i];
4774 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
4775 int af = ifr->lifr_addr.ss_family;
4778 struct in6_addr ia6;
4780 # ifdef SIOCGLIFFLAGS
4782 # endif /* SIOCGLIFFLAGS */
4784 char buf6[INET6_ADDRSTRLEN];
4787 ** We must close and recreate the socket each time
4788 ** since we don't know what type of socket it is now
4789 ** (each status function may change it).
4794 s = socket(af, SOCK_DGRAM, 0);
4797 sm_free(buf); /* XXX */
4802 ** If we don't have a complete ifr structure,
4803 ** don't try to use it.
4806 if ((len - i) < sizeof(*ifr))
4809 # ifdef BSD4_4_SOCKADDR
4810 if (sa->sa.sa_len > sizeof(ifr->lifr_addr))
4811 i += sizeof(ifr->lifr_name) + sa->sa.sa_len;
4813 # endif /* BSD4_4_SOCKADDR */
4815 /* fix for IPv6 size differences */
4816 i += sizeof(ifr->ifr_name) +
4817 max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
4823 sm_dprintf("%s\n", anynet_ntoa(sa));
4825 if (af != AF_INET && af != AF_INET6)
4828 # ifdef SIOCGLIFFLAGS
4829 memset(&ifrf, '\0', sizeof(struct lifreq));
4830 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
4831 sizeof(ifrf.lifr_name));
4832 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
4835 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4836 sm_errstring(errno));
4840 name = ifr->lifr_name;
4841 flags = ifrf.lifr_flags;
4844 sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
4846 if (!bitset(IFF_UP, flags))
4848 # endif /* SIOCGLIFFLAGS */
4852 /* extract IP address from the list*/
4857 /* convert into proper scoped address */
4858 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
4859 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
4860 sa->sin6.sin6_scope_id == 0)
4862 struct in6_addr *ia6p;
4864 ia6p = &sa->sin6.sin6_addr;
4865 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
4866 ((unsigned int)ia6p->s6_addr[2] << 8));
4867 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
4869 # endif /* __KAME__ */
4870 ia6 = sa->sin6.sin6_addr;
4871 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
4873 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
4874 message("WARNING: interface %s is UP with %s address",
4875 name, addr == NULL ? "(NULL)" : addr);
4879 /* save IP address in text from */
4880 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
4882 (void) sm_snprintf(ip_addr, sizeof(ip_addr),
4884 (int) sizeof(ip_addr) - 3,
4889 ia = sa->sin.sin_addr;
4890 if (ia.s_addr == INADDR_ANY ||
4891 ia.s_addr == INADDR_NONE)
4893 message("WARNING: interface %s is UP with %s address",
4894 name, inet_ntoa(ia));
4898 /* save IP address in text from */
4899 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
4900 (int) sizeof(ip_addr) - 3, inet_ntoa(ia));
4904 if (*ip_addr == '\0')
4907 if (!wordinclass(ip_addr, 'w'))
4909 setclass('w', ip_addr);
4911 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
4914 # ifdef SIOCGLIFFLAGS
4915 /* skip "loopback" interface "lo" */
4916 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
4917 bitset(IFF_LOOPBACK, flags))
4919 # endif /* SIOCGLIFFLAGS */
4920 (void) add_hostnames(sa);
4922 sm_free(buf); /* XXX */
4924 # else /* NETINET6 && defined(SIOCGLIFCONF) */
4925 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4931 s = socket(AF_INET, SOCK_DGRAM, 0);
4935 /* get the list of known IP address from the kernel */
4936 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
4937 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
4939 /* can't get number of interfaces -- fall back */
4941 sm_dprintf("SIOCGIFNUM failed: %s\n",
4942 sm_errstring(errno));
4945 else if (tTd(0, 42))
4946 sm_dprintf("system has %d interfaces\n", numifs);
4948 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
4949 numifs = MAXINTERFACES;
4956 ifc.ifc_len = numifs * sizeof(struct ifreq);
4957 ifc.ifc_buf = xalloc(ifc.ifc_len);
4958 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
4961 sm_dprintf("SIOCGIFCONF failed: %s\n",
4962 sm_errstring(errno));
4967 /* scan the list of IP address */
4969 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
4972 for (i = 0; i < ifc.ifc_len && i >= 0; )
4975 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
4976 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
4979 struct in6_addr ia6;
4980 # endif /* NETINET6 */
4982 # ifdef SIOCGIFFLAGS
4984 # endif /* SIOCGIFFLAGS */
4987 char buf6[INET6_ADDRSTRLEN];
4988 # endif /* NETINET6 */
4991 ** If we don't have a complete ifr structure,
4992 ** don't try to use it.
4995 if ((ifc.ifc_len - i) < sizeof(*ifr))
4998 # ifdef BSD4_4_SOCKADDR
4999 if (sa->sa.sa_len > sizeof(ifr->ifr_addr))
5000 i += sizeof(ifr->ifr_name) + sa->sa.sa_len;
5002 # endif /* BSD4_4_SOCKADDR */
5006 sm_dprintf("%s\n", anynet_ntoa(sa));
5008 af = ifr->ifr_addr.sa_family;
5012 # endif /* NETINET6 */
5016 # ifdef SIOCGIFFLAGS
5017 memset(&ifrf, '\0', sizeof(struct ifreq));
5018 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
5019 sizeof(ifrf.ifr_name));
5020 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
5022 sm_dprintf("\tflags: %lx\n",
5023 (unsigned long) ifrf.ifr_flags);
5024 # define IFRFREF ifrf
5025 # else /* SIOCGIFFLAGS */
5026 # define IFRFREF (*ifr)
5027 # endif /* SIOCGIFFLAGS */
5029 if (!bitset(IFF_UP, IFRFREF.ifr_flags))
5034 /* extract IP address from the list*/
5038 ia = sa->sin.sin_addr;
5039 if (ia.s_addr == INADDR_ANY ||
5040 ia.s_addr == INADDR_NONE)
5042 message("WARNING: interface %s is UP with %s address",
5043 ifr->ifr_name, inet_ntoa(ia));
5047 /* save IP address in text from */
5048 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
5049 (int) sizeof(ip_addr) - 3,
5056 /* convert into proper scoped address */
5057 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5058 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5059 sa->sin6.sin6_scope_id == 0)
5061 struct in6_addr *ia6p;
5063 ia6p = &sa->sin6.sin6_addr;
5064 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5065 ((unsigned int)ia6p->s6_addr[2] << 8));
5066 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5068 # endif /* __KAME__ */
5069 ia6 = sa->sin6.sin6_addr;
5070 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5072 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5073 message("WARNING: interface %s is UP with %s address",
5075 addr == NULL ? "(NULL)" : addr);
5079 /* save IP address in text from */
5080 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5082 (void) sm_snprintf(ip_addr, sizeof(ip_addr),
5084 (int) sizeof(ip_addr) - 3,
5088 # endif /* NETINET6 */
5091 if (ip_addr[0] == '\0')
5094 if (!wordinclass(ip_addr, 'w'))
5096 setclass('w', ip_addr);
5098 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5101 /* skip "loopback" interface "lo" */
5102 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5103 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
5106 (void) add_hostnames(sa);
5108 sm_free(ifc.ifc_buf); /* XXX */
5111 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5112 # endif /* NETINET6 && defined(SIOCGLIFCONF) */
5115 ** ISLOOPBACK -- is socket address in the loopback net?
5118 ** sa -- socket address.
5121 ** true -- is socket address in the loopback net?
5122 ** false -- otherwise
5131 if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
5133 #else /* NETINET6 */
5134 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5135 if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
5136 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
5138 #endif /* NETINET6 */
5142 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5148 ** The number of processors online.
5152 get_num_procs_online()
5157 # if defined(CTL_HW) && defined(HW_NCPU)
5163 sz = (size_t) sizeof(nproc);
5164 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
5165 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5166 #else /* USESYSCTL */
5167 # ifdef _SC_NPROCESSORS_ONLN
5168 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
5169 # else /* _SC_NPROCESSORS_ONLN */
5171 # include <sys/pstat.h>
5172 struct pst_dynamic psd;
5174 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
5175 nproc = psd.psd_proc_cnt;
5176 # endif /* __hpux */
5177 # endif /* _SC_NPROCESSORS_ONLN */
5178 #endif /* USESYSCTL */
5185 ** SM_CLOSEFROM -- close file descriptors
5188 ** lowest -- first fd to close
5189 ** highest -- last fd + 1 to close
5196 sm_closefrom(lowest, highest)
5197 int lowest, highest;
5201 #else /* HASCLOSEFROM */
5204 for (i = lowest; i < highest; i++)
5206 #endif /* HASCLOSEFROM */
5210 ** CLOSEFD_WALK -- walk fd's arranging to close them
5211 ** Callback for fdwalk()
5214 ** lowest -- first fd to arrange to be closed
5215 ** fd -- fd to arrange to be closed
5222 closefd_walk(lowest, fd)
5226 if (fd >= *(int *)lowest)
5227 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
5230 #endif /* HASFDWALK */
5232 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5235 ** lowest -- first fd to arrange to be closed
5236 ** highest -- last fd + 1 to arrange to be closed
5243 sm_close_on_exec(highest, lowest)
5244 int highest, lowest;
5247 (void) fdwalk(closefd_walk, &lowest);
5248 #else /* HASFDWALK */
5251 for (i = lowest; i < highest; i++)
5253 if ((j = fcntl(i, F_GETFD, 0)) != -1)
5254 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
5256 #endif /* HASFDWALK */
5259 ** SEED_RANDOM -- seed the random number generator
5273 #else /* HASSRANDOMDEV */
5277 seed = (long) CurrentPid;
5278 if (gettimeofday(&t, NULL) >= 0)
5279 seed += t.tv_sec + t.tv_usec;
5282 (void) srandom(seed);
5283 # else /* HASRANDOM */
5284 (void) srand((unsigned int) seed);
5285 # endif /* HASRANDOM */
5286 #endif /* HASSRANDOMDEV */
5289 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5292 ** level -- syslog level
5293 ** id -- envelope ID or NULL (NOQUEUE)
5294 ** fmt -- format string
5295 ** arg... -- arguments as implied by fmt.
5304 sm_syslog(int level, const char *id, const char *fmt, ...)
5305 #else /* __STDC__ */
5306 sm_syslog(level, id, fmt, va_alist)
5311 #endif /* __STDC__ */
5321 extern int SyslogPrefixLen;
5327 idlen = strlen(id) + SyslogPrefixLen;
5330 bufsize = sizeof(buf0);
5336 /* print log message into buf */
5337 SM_VA_START(ap, fmt);
5338 n = sm_vsnprintf(buf, bufsize, fmt, ap);
5344 /* String too small, redo with correct size */
5351 buf = sm_malloc_x(bufsize);
5354 /* clean up buf after it has been expanded with args */
5355 newstring = str2prt(buf);
5356 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
5362 sm_dprintf("%s\n", newstring);
5364 syslog(level, "%s", newstring);
5369 sm_dprintf("%s: %s\n", id, newstring);
5371 syslog(level, "%s: %s", id, newstring);
5374 /*XXX should do something more sensible */
5376 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
5379 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5380 "%s: %s\n", id, newstring);
5389 ** additional length for splitting: " ..." + 3, where 3 is magic to
5390 ** have some data for the next entry.
5396 idlen += 5; /* strlen("[999]"), see below */
5397 while (*begin != '\0' &&
5398 (strlen(begin) + idlen) > SYSLOG_BUFSIZE)
5404 /* Too many messages */
5407 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5410 /* Break on comma or space */
5411 if (*end == ',' || *end == ' ')
5413 end++; /* Include separator */
5418 /* No separator, break midstring... */
5420 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5425 sm_dprintf("%s[%d]: %s ...\n", id, seq++, begin);
5427 syslog(level, "%s[%d]: %s ...", id, seq++, begin);
5429 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5430 "%s[%d]: %s ...\n", id, seq++, begin);
5439 sm_dprintf("%s[%d]: log terminated, too many parts\n",
5442 syslog(level, "%s[%d]: log terminated, too many parts",
5445 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5446 "%s[%d]: log terminated, too many parts\n", id, seq);
5449 else if (*begin != '\0')
5453 sm_dprintf("%s[%d]: %s\n", id, seq, begin);
5455 syslog(level, "%s[%d]: %s", id, seq, begin);
5457 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5458 "%s[%d]: %s\n", id, seq, begin);
5466 ** HARD_SYSLOG -- call syslog repeatedly until it works
5468 ** Needed on HP-UX, which apparently doesn't guarantee that
5469 ** syslog succeeds during interrupt handlers.
5472 #if defined(__hpux) && !defined(HPUX11)
5474 # define MAXSYSLOGTRIES 100
5477 # define XCNST const
5478 # define CAST (const char *)
5486 hard_syslog(int pri, XCNST char *msg, ...)
5487 # else /* __STDC__ */
5488 hard_syslog(pri, msg, va_alist)
5492 # endif /* __STDC__ */
5495 char buf[SYSLOG_BUFSIZE];
5498 SM_VA_START(ap, msg);
5499 (void) sm_vsnprintf(buf, sizeof(buf), msg, ap);
5502 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
5507 #endif /* defined(__hpux) && !defined(HPUX11) */
5508 #if NEEDLOCAL_HOSTNAME_LENGTH
5510 ** LOCAL_HOSTNAME_LENGTH
5512 ** This is required to get sendmail to compile against BIND 4.9.x
5515 ** Unfortunately, a Compaq Y2K patch kit provides it without
5516 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5517 ** figure out whether it is needed.
5521 local_hostname_length(hostname)
5524 size_t len_host, len_domain;
5526 if (!*_res.defdname)
5528 len_host = strlen(hostname);
5529 len_domain = strlen(_res.defdname);
5530 if (len_host > len_domain &&
5531 (sm_strcasecmp(hostname + len_host - len_domain,
5532 _res.defdname) == 0) &&
5533 hostname[len_host - len_domain - 1] == '.')
5534 return len_host - len_domain - 1;
5538 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5542 ** LINK -- clone a file
5544 ** Some OS's lacks link() and hard links. Since sendmail is using
5545 ** link() as an efficient way to clone files, this implementation
5546 ** will simply do a file copy.
5548 ** NOTE: This link() replacement is not a generic replacement as it
5549 ** does not handle all of the semantics of the real link(2).
5552 ** source -- pathname of existing file.
5553 ** target -- pathname of link (clone) to be created.
5557 ** -1 -- failure, see errno for details.
5561 link(source, target)
5567 int src = -1, dst = -1;
5573 sff = SFF_REGONLY|SFF_OPENASROOT;
5574 if (DontLockReadFiles)
5577 /* Open the original file */
5578 src = safeopen((char *)source, O_RDONLY, 0, sff);
5582 /* Obtain the size and the mode */
5583 if (fstat(src, &st) < 0)
5586 /* Create the duplicate copy */
5589 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
5594 /* Copy all of the bytes one buffer at a time */
5595 while ((readlen = read(src, &buf, sizeof(buf))) > 0)
5597 ssize_t left = readlen;
5601 (writelen = write(dst, p, (size_t) left)) >= 0)
5610 /* Any trouble reading? */
5611 if (readlen < 0 || writelen < 0)
5614 /* Close the input file */
5622 /* Close the output file */
5625 /* don't set dst = -1 here so we unlink the file */
5638 (void) unlink(target);
5644 #endif /* NEEDLINK */
5647 ** Compile-Time options
5650 char *CompileOptions[] =
5654 #endif /* ALLOW_255 */
5658 # endif /* DNSMAP */
5659 #endif /* NAMED_BIND */
5668 #endif /* HES_GETMAILHOST */
5671 #endif /* LDAPMAP */
5674 #endif /* LDAP_REFERRALS */
5680 #endif /* MAP_NSD */
5683 #endif /* MAP_REGEX */
5686 #endif /* MATCHGECOS */
5692 #endif /* MIME7TO8 */
5695 #endif /* MIME7TO8_OLD */
5698 #endif /* MIME8TO7 */
5701 #endif /* NAMED_BIND */
5707 #endif /* NETINET */
5710 #endif /* NETINET6 */
5713 #endif /* NETINFO */
5722 #endif /* NETUNIX */
5734 #endif /* NISPLUS */
5741 #ifdef PICKY_HELO_CHECK
5743 #endif /* PICKY_HELO_CHECK */
5746 #endif /* PIPELINING */
5750 # else /* SASL >= 20000 */
5752 # endif /* SASL >= 20000 */
5757 #if SM_LDAP_ERROR_ON_MISSING_ARGS
5758 "SM_LDAP_ERROR_ON_MISSING_ARGS",
5759 #endif /* SM_LDAP_ERROR_ON_MISSING_ARGS */
5762 #endif /* SMTPDEBUG */
5765 #endif /* SOCKETMAP */
5768 #endif /* STARTTLS */
5769 #if SUID_ROOT_FILES_OK
5770 "SUID_ROOT_FILES_OK",
5771 #endif /* SUID_ROOT_FILES_OK */
5774 #endif /* TCPWRAPPERS */
5777 #endif /* TLS_NO_RSA */
5778 #if TLS_VRFY_PER_CTX
5780 #endif /* TLS_VRFY_PER_CTX */
5786 #endif /* USE_LDAP_INIT */
5789 #endif /* USE_TTYPATH */
5801 ** OS compile options.
5804 char *OsCompileOptions[] =
5806 #if ADDRCONFIG_IS_BROKEN
5807 "ADDRCONFIG_IS_BROKEN",
5808 #endif /* ADDRCONFIG_IS_BROKEN */
5809 #ifdef AUTO_NETINFO_HOSTS
5810 "AUTO_NETINFO_HOSTS",
5811 #endif /* AUTO_NETINFO_HOSTS */
5812 #ifdef AUTO_NIS_ALIASES
5814 #endif /* AUTO_NIS_ALIASES */
5815 #if BROKEN_RES_SEARCH
5816 "BROKEN_RES_SEARCH",
5817 #endif /* BROKEN_RES_SEARCH */
5818 #ifdef BSD4_4_SOCKADDR
5820 #endif /* BSD4_4_SOCKADDR */
5823 #endif /* BOGUS_O_EXCL */
5824 #if DEC_OSF_BROKEN_GETPWENT
5825 "DEC_OSF_BROKEN_GETPWENT",
5826 #endif /* DEC_OSF_BROKEN_GETPWENT */
5827 #if FAST_PID_RECYCLE
5829 #endif /* FAST_PID_RECYCLE */
5832 #endif /* HASCLOSEFROM */
5835 #endif /* HASFCHOWN */
5838 #endif /* HASFCHMOD */
5841 #endif /* HASFDWALK */
5844 #endif /* HASFLOCK */
5845 #if HASGETDTABLESIZE
5847 #endif /* HASGETDTABLESIZE */
5850 #endif /* HASGETUSERSHELL */
5853 #endif /* HASINITGROUPS */
5854 #if HASLDAPGETALIASBYNAME
5855 "HASLDAPGETALIASBYNAME",
5856 #endif /* HASLDAPGETALIASBYNAME */
5859 #endif /* HASLSTAT */
5862 #endif /* HASNICE */
5865 #endif /* HASRANDOM */
5868 #endif /* HASRRESVPORT */
5871 #endif /* HASSETEGID */
5874 #endif /* HASSETLOGIN */
5877 #endif /* HASSETREGID */
5880 #endif /* HASSETRESGID */
5883 #endif /* HASSETREUID */
5886 #endif /* HASSETRLIMIT */
5889 #endif /* HASSETSID */
5890 #if HASSETUSERCONTEXT
5891 "HASSETUSERCONTEXT",
5892 #endif /* HASSETUSERCONTEXT */
5895 #endif /* HASSETVBUF */
5898 #endif /* HAS_ST_GEN */
5901 #endif /* HASSRANDOMDEV */
5904 #endif /* HASURANDOMDEV */
5907 #endif /* HASSTRERROR */
5910 #endif /* HASULIMIT */
5913 #endif /* HASUNAME */
5916 #endif /* HASUNSETENV */
5919 #endif /* HASWAITPID */
5922 #endif /* IDENTPROTO */
5925 #endif /* IP_SRCROUTE */
5926 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
5928 #endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */
5931 #endif /* MILTER_NO_NAGLE */
5934 #endif /* NEEDFSYNC */
5937 #endif /* NEEDLINK */
5938 #if NEEDLOCAL_HOSTNAME_LENGTH
5939 "NEEDLOCAL_HOSTNAME_LENGTH",
5940 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5943 #endif /* NEEDSGETIPNODE */
5946 #endif /* NEEDSTRSTR */
5949 #endif /* NEEDSTRTOL */
5950 #ifdef NO_GETSERVBYNAME
5952 #endif /* NO_GETSERVBYNAME */
5955 #endif /* NOFTRUNCATE */
5956 #if REQUIRES_DIR_FSYNC
5957 "REQUIRES_DIR_FSYNC",
5958 #endif /* REQUIRES_DIR_FSYNC */
5959 #if RLIMIT_NEEDS_SYS_TIME_H
5960 "RLIMIT_NEEDS_SYS_TIME_H",
5961 #endif /* RLIMIT_NEEDS_SYS_TIME_H */
5964 #endif /* SAFENFSPATHCONF */
5967 #endif /* SECUREWARE */
5970 #endif /* SHARE_V1 */
5971 #if SIOCGIFCONF_IS_BROKEN
5972 "SIOCGIFCONF_IS_BROKEN",
5973 #endif /* SIOCGIFCONF_IS_BROKEN */
5974 #if SIOCGIFNUM_IS_BROKEN
5975 "SIOCGIFNUM_IS_BROKEN",
5976 #endif /* SIOCGIFNUM_IS_BROKEN */
5977 #if SNPRINTF_IS_BROKEN
5978 "SNPRINTF_IS_BROKEN",
5979 #endif /* SNPRINTF_IS_BROKEN */
5980 #if SO_REUSEADDR_IS_BROKEN
5981 "SO_REUSEADDR_IS_BROKEN",
5982 #endif /* SO_REUSEADDR_IS_BROKEN */
5985 #endif /* SYS5SETPGRP */
5988 #endif /* SYSTEM5 */
5991 #endif /* USE_DOUBLE_FORK */
5994 #endif /* USE_ENVIRON */
5995 #if USE_SA_SIGACTION
5997 #endif /* USE_SA_SIGACTION */
6000 #endif /* USE_SIGLONGJMP */
6003 #endif /* USEGETCONFATTR */
6006 #endif /* USESETEUID */
6009 #endif /* USESYSCTL */
6010 #if USING_NETSCAPE_LDAP
6011 "USING_NETSCAPE_LDAP",
6012 #endif /* USING_NETSCAPE_LDAP */
6015 #endif /* WAITUNION */
6020 ** FFR compile options.
6023 char *FFRCompileOptions[] =
6025 #if _FFR_ADDR_TYPE_MODES
6026 /* more info in {addr_type}, requires m4 changes! */
6027 "_FFR_ADDR_TYPE_MODES",
6028 #endif /* _FFR_ADDR_TYPE_MODES */
6029 #if _FFR_ALLOW_SASLINFO
6030 /* DefaultAuthInfo can be specified by user. */
6031 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */
6032 "_FFR_ALLOW_SASLINFO",
6033 #endif /* _FFR_ALLOW_SASLINFO */
6034 #if _FFR_BADRCPT_SHUTDOWN
6035 /* shut down connection (421) if there are too many bad RCPTs */
6036 "_FFR_BADRCPT_SHUTDOWN",
6037 #endif /* _FFR_BADRCPT_SHUTDOWN */
6038 #if _FFR_BESTMX_BETTER_TRUNCATION
6039 /* Better truncation of list of MX records for dns map. */
6040 "_FFR_BESTMX_BETTER_TRUNCATION",
6041 #endif /* _FFR_BESTMX_BETTER_TRUNCATION */
6042 #if _FFR_CATCH_BROKEN_MTAS
6043 /* Deal with MTAs that send a reply during the DATA phase. */
6044 "_FFR_CATCH_BROKEN_MTAS",
6045 #endif /* _FFR_CATCH_BROKEN_MTAS */
6047 /* Stricter checks about queue directory permissions. */
6049 #endif /* _FFR_CHK_QUEUE */
6050 #if _FFR_CLIENT_SIZE
6051 /* Don't try to send mail if its size exceeds SIZE= of server. */
6053 #endif /* _FFR_CLIENT_SIZE */
6055 /* CRLPath; needs documentation; Al Smith */
6057 #endif /* _FFR_CRLPATH */
6058 #if _FFR_DAEMON_NETUNIX
6059 /* Allow local (not just TCP) socket connection to server. */
6060 "_FFR_DAEMON_NETUNIX",
6061 #endif /* _FFR_DAEMON_NETUNIX */
6062 #if _FFR_DEPRECATE_MAILER_FLAG_I
6063 /* What it says :-) */
6064 "_FFR_DEPRECATE_MAILER_FLAG_I",
6065 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
6067 /* deliver first TA in background, then queue */
6069 #endif /* _FFR_DM_ONE */
6070 #if _FFR_DIGUNIX_SAFECHOWN
6071 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6072 /* Problem noted by Anne Bennett of Concordia University */
6073 "_FFR_DIGUNIX_SAFECHOWN",
6074 #endif /* _FFR_DIGUNIX_SAFECHOWN */
6075 #if _FFR_DNSMAP_ALIASABLE
6076 /* Allow dns map type to be used for aliases. */
6077 /* Don Lewis of TDK */
6078 "_FFR_DNSMAP_ALIASABLE",
6079 #endif /* _FFR_DNSMAP_ALIASABLE */
6080 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6081 /* Enable DontLockFilesForRead option. */
6082 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6083 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
6084 #if _FFR_DOTTED_USERNAMES
6085 /* Allow usernames with '.' */
6086 "_FFR_DOTTED_USERNAMES",
6087 #endif /* _FFR_DOTTED_USERNAMES */
6090 ** Make DaemonPortOptions case sensitive.
6091 ** For some unknown reasons the code converted every option
6092 ** to uppercase (first letter only, as that's the only one that
6093 ** is actually checked). This prevented all new lower case options
6095 ** The documentation doesn't say anything about case (in)sensitivity,
6096 ** which means it should be case sensitive by default,
6097 ** but it's not a good idea to change this within a patch release,
6098 ** so let's delay this to 8.15.
6102 #endif /* _FFR_DPO_CS */
6103 #if _FFR_DPRINTF_MAP
6104 /* dprintf map for logging */
6106 #endif /* _FFR_DPRINTF_MAP */
6107 #if _FFR_DROP_TRUSTUSER_WARNING
6109 ** Don't issue this warning:
6110 ** "readcf: option TrustedUser may cause problems on systems
6111 ** which do not support fchown() if UseMSP is not set.
6114 "_FFR_DROP_TRUSTUSER_WARNING",
6115 #endif /* _FFR_DROP_TRUSTUSER_WARNING */
6116 #if _FFR_EIGHT_BIT_ADDR_OK
6117 /* EightBitAddrOK: allow 8-bit e-mail addresses */
6118 "_FFR_EIGHT_BIT_ADDR_OK",
6119 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
6120 #if _FFR_EXTRA_MAP_CHECK
6121 /* perform extra checks on $( $) in R lines */
6122 "_FFR_EXTRA_MAP_CHECK",
6123 #endif /* _FFR_EXTRA_MAP_CHECK */
6124 #if _FFR_GETHBN_ExFILE
6126 ** According to Motonori Nakamura some gethostbyname()
6127 ** implementations (TurboLinux?) may (temporarily) fail
6128 ** due to a lack of file discriptors. Enabling this FFR
6129 ** will check errno for EMFILE and ENFILE and in case of a match
6130 ** cause a temporary error instead of a permanent error.
6131 ** The right solution is of course to file a bug against those
6132 ** systems such that they actually set h_errno = TRY_AGAIN.
6135 "_FFR_GETHBN_ExFILE",
6136 #endif /* _FFR_GETHBN_ExFILE */
6139 ** If using -t, force not sending to argv recipients, even
6140 ** if they are mentioned in the headers.
6144 #endif /* _FFR_FIX_DASHT */
6145 #if _FFR_FORWARD_SYSERR
6146 /* Cause a "syserr" if forward file isn't "safe". */
6147 "_FFR_FORWARD_SYSERR",
6148 #endif /* _FFR_FORWARD_SYSERR */
6150 /* Generate a ORCPT DSN arg if not already provided */
6152 #endif /* _FFR_GEN_ORCPT */
6153 #if _FFR_GROUPREADABLEAUTHINFOFILE
6154 /* Allow group readable DefaultAuthInfo file. */
6155 "_FFR_GROUPREADABLEAUTHINFOFILE",
6156 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
6157 #if _FFR_HANDLE_ISO8859_GECOS
6159 ** Allow ISO 8859 characters in GECOS field: replace them
6160 ** ith ASCII "equivalent".
6163 /* Peter Eriksson of Linkopings universitet */
6164 "_FFR_HANDLE_ISO8859_GECOS",
6165 #endif /* _FFR_HANDLE_ISO8859_GECOS */
6166 #if _FFR_HPUX_NSSWITCH
6167 /* Use nsswitch on HP-UX */
6168 "_FFR_HPUX_NSSWITCH",
6169 #endif /* _FFR_HPUX_NSSWITCH */
6170 #if _FFR_IGNORE_BOGUS_ADDR
6171 /* Ignore addresses for which prescan() failed */
6172 "_FFR_IGNORE_BOGUS_ADDR",
6173 #endif /* _FFR_IGNORE_BOGUS_ADDR */
6174 #if _FFR_IGNORE_EXT_ON_HELO
6175 /* Ignore extensions offered in response to HELO */
6176 "_FFR_IGNORE_EXT_ON_HELO",
6177 #endif /* _FFR_IGNORE_EXT_ON_HELO */
6178 #if _FFR_LOCAL_DAEMON
6179 /* Local daemon mode (-bl) which only accepts loopback connections */
6180 "_FFR_LOCAL_DAEMON",
6181 #endif /* _FFR_LOCAL_DAEMON */
6182 #if _FFR_MAXDATASIZE
6184 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6185 ** hence this shouldn't be used as limit for milter communication.
6186 ** see also libmilter/comm.c
6187 ** Gurusamy Sarathy of ActiveState
6191 #endif /* _FFR_MAXDATASIZE */
6192 #if _FFR_MAX_FORWARD_ENTRIES
6193 /* Try to limit number of .forward entries */
6194 /* (doesn't work) */
6195 /* Randall S. Winchester of the University of Maryland */
6196 "_FFR_MAX_FORWARD_ENTRIES",
6197 #endif /* _FFR_MAX_FORWARD_ENTRIES */
6198 #if _FFR_MAX_SLEEP_TIME
6199 /* Limit sleep(2) time in libsm/clock.c */
6200 "_FFR_MAX_SLEEP_TIME",
6201 #endif /* _FFR_MAX_SLEEP_TIME */
6203 /* Check free memory */
6205 #endif /* _FFR_MEMSTAT */
6206 #if _FFR_MILTER_CHECK
6207 "_FFR_MILTER_CHECK",
6208 #endif /* _FFR_MILTER_CHECK */
6209 #if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF
6211 ** milter_body() uses the same conversion algorithm as putbody()
6212 ** to translate the "local" df format (\n) to SMTP format (\r\n).
6213 ** However, putbody() and mime8to7() use different conversion
6215 ** If the input date does not follow the SMTP standard
6216 ** (e.g., if it has "naked \r"s), then the output from putbody()
6217 ** and mime8to7() will most likely be different.
6218 ** By turning on this FFR milter_body() will try to "imitate"
6220 ** Note: there is no (simple) way to deal with both conversions
6221 ** in a consistent manner. Moreover, as the "GiGo" principle applies,
6222 ** it's not really worth to fix it.
6225 "_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF",
6226 #endif /* _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF */
6227 #if _FFR_MILTER_CHECK_REJECTIONS_TOO
6229 ** Also send RCPTs that are rejected by check_rcpt to a milter
6230 ** (if requested during option negotiation).
6233 "_FFR_MILTER_CHECK_REJECTIONS_TOO",
6234 #endif /* _FFR_MILTER_CHECK_REJECTIONS_TOO */
6235 #if _FFR_MIME7TO8_OLD
6236 /* Old mime7to8 code, the new is broken for at least one example. */
6237 "_FFR_MIME7TO8_OLD",
6238 #endif /* _FFR_MAX_SLEEP_TIME */
6239 #if _FFR_MORE_MACROS
6240 /* allow more long macro names ("unprintable" characters). */
6242 #endif /* _FFR_MORE_MACROS */
6244 /* allow to override "Message accepted for delivery" */
6246 #endif /* _FFR_MSG_ACCEPT */
6247 #if _FFR_NODELAYDSN_ON_HOLD
6248 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6250 "_FFR_NODELAYDSN_ON_HOLD",
6251 #endif /* _FFR_NODELAYDSN_ON_HOLD */
6253 /* Disable PIPELINING, delay client if used. */
6255 #endif /* _FFR_NO_PIPE */
6256 #if _FFR_LDAP_NETWORK_TIMEOUT
6257 /* set LDAP_OPT_NETWORK_TIMEOUT if available (-c) */
6258 "_FFR_LDAP_NETWORK_TIMEOUT",
6259 #endif /* _FFR_LDAP_NETWORK_TIMEOUT */
6261 /* log ntries=, from Nik Clayton of FreeBSD */
6263 #endif /* _FFR_LOG_NTRIES */
6264 #if _FFR_QF_PARANOIA
6266 #endif /* _FFR_QF_PARANOIA */
6268 /* Exponential queue delay; disabled in 8.13 since it isn't used. */
6270 #endif /* _FFR_QUEUEDELAY */
6271 #if _FFR_QUEUE_GROUP_SORTORDER
6272 /* Allow QueueSortOrder per queue group. */
6273 /* XXX: Still need to actually use qgrp->qg_sortorder */
6274 "_FFR_QUEUE_GROUP_SORTORDER",
6275 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
6276 #if _FFR_QUEUE_MACRO
6277 /* Define {queue} macro. */
6279 #endif /* _FFR_QUEUE_MACRO */
6280 #if _FFR_QUEUE_RUN_PARANOIA
6281 /* Additional checks when doing queue runs; interval of checks */
6282 "_FFR_QUEUE_RUN_PARANOIA",
6283 #endif /* _FFR_QUEUE_RUN_PARANOIA */
6284 #if _FFR_QUEUE_SCHED_DBG
6285 /* Debug output for the queue scheduler. */
6286 "_FFR_QUEUE_SCHED_DBG",
6287 #endif /* _FFR_QUEUE_SCHED_DBG */
6288 #if _FFR_REDIRECTEMPTY
6290 ** envelope <> can't be sent to mailing lists, only owner-
6291 ** send spam of this type to owner- of the list
6292 ** ---- to stop spam from going to mailing lists.
6295 "_FFR_REDIRECTEMPTY",
6296 #endif /* _FFR_REDIRECTEMPTY */
6297 #if _FFR_RESET_MACRO_GLOBALS
6298 /* Allow macro 'j' to be set dynamically via rulesets. */
6299 "_FFR_RESET_MACRO_GLOBALS",
6300 #endif /* _FFR_RESET_MACRO_GLOBALS */
6302 /* Random shuffle for queue sorting. */
6304 #endif /* _FFR_RHS */
6307 ** allow -qGqueue_group -qp to work, i.e.,
6308 ** restrict a persistent queue runner to a queue group.
6312 #endif /* _FFR_RUNPQG */
6314 /* session id (for logging) */
6316 #endif /* _FFR_SESSID */
6318 /* Donated code (unused). */
6320 #endif /* _FFR_SHM_STATUS */
6321 #if _FFR_LDAP_SINGLEDN
6323 ** The LDAP database map code in Sendmail 8.12.10, when
6324 ** given the -1 switch, would match only a single DN,
6325 ** but was able to return multiple attributes for that
6326 ** DN. In Sendmail 8.13 this "bug" was corrected to
6327 ** only return if exactly one attribute matched.
6329 ** Unfortunately, our configuration uses the former
6330 ** behaviour. Attached is a relatively simple patch
6331 ** to 8.13.4 which adds a -2 switch (for lack of a
6332 ** better option) which returns the single dn/multiple
6335 ** Jeffrey T. Eaton, Carnegie-Mellon University
6338 "_FFR_LDAP_SINGLEDN",
6339 #endif /* _FFR_LDAP_SINGLEDN */
6340 #if _FFR_SKIP_DOMAINS
6341 /* process every N'th domain instead of every N'th message */
6342 "_FFR_SKIP_DOMAINS",
6343 #endif /* _FFR_SKIP_DOMAINS */
6344 #if _FFR_SLEEP_USE_SELECT
6345 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6346 "_FFR_SLEEP_USE_SELECT ",
6347 #endif /* _FFR_SLEEP_USE_SELECT */
6350 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6351 ** bit alignment, so unless each piece of argv and envp is a multiple
6352 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6353 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6354 ** if you use this FFR.
6357 /* Chris Adams of HiWAAY Informations Services */
6359 #endif /* _FFR_SPT_ALIGN */
6360 #if _FFR_SS_PER_DAEMON
6361 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6362 "_FFR_SS_PER_DAEMON",
6363 #endif /* _FFR_SS_PER_DAEMON */
6365 /* Donated code (unused). */
6367 #endif /* _FFR_TIMERS */
6369 /* More STARTTLS options, e.g., secondary certs. */
6371 #endif /* _FFR_TLS_1 */
6374 ** If we don't own the file mark it as unsafe.
6375 ** However, allow TrustedUser to own it as well
6376 ** in case TrustedUser manipulates the queue.
6380 #endif /* _FFR_TRUSTED_QF */
6381 #if _FFR_USE_SEM_LOCKING
6382 "_FFR_USE_SEM_LOCKING",
6383 #endif /* _FFR_USE_SEM_LOCKING */
6384 #if _FFR_USE_SETLOGIN
6385 /* Use setlogin() */
6387 "_FFR_USE_SETLOGIN",
6388 #endif /* _FFR_USE_SETLOGIN */