2 * Copyright (c) 1998-2013 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: conf.c,v 8.1192 2014-01-27 18:23:21 ca Exp $")
18 #include <sm/sendmail.h>
19 #include <sendmail/pathnames.h>
28 #if defined(DEC) && NETINET6
29 /* for the IPv6 device lookup */
30 # define _SOCKADDR_LEN
34 #include <sys/ioctl.h>
35 #include <sys/param.h>
38 #if NETINET || NETINET6
39 # include <arpa/inet.h>
41 #if HASULIMIT && defined(HPUX11)
48 static void setupmaps __P((void));
49 static void setupmailers __P((void));
50 static void setupqueues __P((void));
51 static int get_num_procs_online __P((void));
52 static int add_hostnames __P((SOCKADDR *));
54 #if NETINET6 && NEEDSGETIPNODE
55 static struct hostent *sm_getipnodebyname __P((const char *, int, int, int *));
56 static struct hostent *sm_getipnodebyaddr __P((const void *, size_t, int, int *));
57 #else /* NETINET6 && NEEDSGETIPNODE */
58 #define sm_getipnodebyname getipnodebyname
59 #define sm_getipnodebyaddr getipnodebyaddr
60 #endif /* NETINET6 && NEEDSGETIPNODE */
64 ** CONF.C -- Sendmail Configuration Tables.
66 ** Defines the configuration of this installation.
68 ** Configuration Variables:
69 ** HdrInfo -- a table describing well-known header fields.
70 ** Each entry has the field name and some flags,
71 ** which are described in sendmail.h.
74 ** I have tried to put almost all the reasonable
75 ** configuration information into the configuration
76 ** file read at runtime. My intent is that anything
77 ** here is a function of the version of UNIX you
78 ** are running, or is really static -- for example
79 ** the headers are a superset of widely used
80 ** protocols. If you find yourself playing with
81 ** this file too much, you may be making a mistake!
86 ** Final (null) entry contains the flags used for any other field.
88 ** Not all of these are actually handled specially by sendmail
89 ** at this time. They are included as placeholders, to let
90 ** you know that "someday" I intend to have sendmail do
91 ** something with them.
95 # define Xflags H_ASIS
100 struct hdrinfo HdrInfo[] =
102 /* originator fields, most to least significant */
103 { "resent-sender", H_FROM|H_RESENT, NULL },
104 { "resent-from", H_FROM|H_RESENT, NULL },
105 { "resent-reply-to", H_FROM|H_RESENT, NULL },
106 { "sender", H_FROM, NULL },
107 { "from", H_FROM | Xflags, NULL },
108 { "reply-to", H_FROM | Xflags, NULL },
109 { "errors-to", H_FROM|H_ERRORSTO, NULL },
110 { "full-name", H_ACHECK, NULL },
111 { "return-receipt-to", H_RECEIPTTO, NULL },
112 { "delivery-receipt-to", H_RECEIPTTO, NULL },
113 { "disposition-notification-to", H_FROM, NULL },
115 /* destination fields */
116 { "to", H_RCPT | Xflags, NULL },
117 { "resent-to", H_RCPT|H_RESENT, NULL },
118 { "cc", H_RCPT, NULL },
119 { "resent-cc", H_RCPT|H_RESENT, NULL },
120 { "bcc", H_RCPT|H_BCC, NULL },
121 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
122 { "apparently-to", H_RCPT, NULL },
124 /* message identification and control */
125 { "message-id", 0, NULL },
126 { "resent-message-id", H_RESENT, NULL },
128 { "message", H_EOH, NULL },
129 { "text", H_EOH, NULL },
134 { "resent-date", H_RESENT, NULL },
137 { "received", H_TRACE|H_FORCE, NULL },
138 { "x400-received", H_TRACE|H_FORCE, NULL },
139 { "via", H_TRACE|H_FORCE, NULL },
140 { "mail-from", H_TRACE|H_FORCE, NULL },
142 /* miscellaneous fields */
143 { "comments", H_FORCE|H_ENCODABLE, NULL },
144 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
145 { "content-transfer-encoding", H_CTE, NULL },
146 { "content-type", H_CTYPE, NULL },
147 { "content-length", H_ACHECK, NULL },
148 { "subject", H_ENCODABLE, NULL },
149 { "x-authentication-warning", H_FORCE, NULL },
158 struct prival PrivacyValues[] =
160 { "public", PRIV_PUBLIC },
161 { "needmailhelo", PRIV_NEEDMAILHELO },
162 { "needexpnhelo", PRIV_NEEDEXPNHELO },
163 { "needvrfyhelo", PRIV_NEEDVRFYHELO },
164 { "noexpn", PRIV_NOEXPN },
165 { "novrfy", PRIV_NOVRFY },
166 { "authwarnings", PRIV_AUTHWARNINGS },
167 { "noverb", PRIV_NOVERB },
168 { "restrictmailq", PRIV_RESTRICTMAILQ },
169 { "restrictqrun", PRIV_RESTRICTQRUN },
170 { "restrictexpand", PRIV_RESTRICTEXPAND },
171 { "noetrn", PRIV_NOETRN },
172 { "nobodyreturn", PRIV_NOBODYRETN },
173 { "noreceipts", PRIV_NORECEIPTS },
174 { "goaway", PRIV_GOAWAY },
175 { "noactualrecipient", PRIV_NOACTUALRECIPIENT },
177 { "noreflection", PRIV_NOREFLECTION },
183 ** DontBlameSendmail values
186 struct dbsval DontBlameSendmailValues[] =
188 { "safe", DBS_SAFE },
189 { "assumesafechown", DBS_ASSUMESAFECHOWN },
190 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
191 { "groupwritableforwardfilesafe",
192 DBS_GROUPWRITABLEFORWARDFILESAFE },
193 { "groupwritableincludefilesafe",
194 DBS_GROUPWRITABLEINCLUDEFILESAFE },
195 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
196 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
197 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
198 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
199 { "linkedaliasfileinwritabledir",
200 DBS_LINKEDALIASFILEINWRITABLEDIR },
201 { "linkedclassfileinwritabledir",
202 DBS_LINKEDCLASSFILEINWRITABLEDIR },
203 { "linkedforwardfileinwritabledir",
204 DBS_LINKEDFORWARDFILEINWRITABLEDIR },
205 { "linkedincludefileinwritabledir",
206 DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
207 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
208 { "linkedserviceswitchfileinwritabledir",
209 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
210 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
211 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
212 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
213 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
214 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
215 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
216 { "forwardfileingroupwritabledirpath",
217 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
218 { "includefileingroupwritabledirpath",
219 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
220 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
221 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
222 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
223 { "forwardfileinunsafedirpathsafe",
224 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
225 { "includefileinunsafedirpathsafe",
226 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
227 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
228 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
229 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
230 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
231 { "truststickybit", DBS_TRUSTSTICKYBIT },
232 { "dontwarnforwardfileinunsafedirpath",
233 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
234 { "insufficiententropy", DBS_INSUFFICIENTENTROPY },
235 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
236 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
237 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
238 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
239 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
240 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
241 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
242 { "groupreadabledefaultauthinfofile",
243 DBS_GROUPREADABLEAUTHINFOFILE },
244 { "certowner", DBS_CERTOWNER },
249 ** Miscellaneous stuff.
252 int DtableSize = 50; /* max open files; reset in 4.2bsd */
254 ** SETDEFAULTS -- set default values
256 ** Some of these must be initialized using direct code since they
257 ** depend on run-time values. So let's do all of them this way.
260 ** e -- the default envelope.
266 ** Initializes a bunch of global variables to their
271 #define HOURS * 60 MINUTES
272 #define DAYS * 24 HOURS
274 #ifndef MAXRULERECURSION
275 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
280 register ENVELOPE *e;
286 numprocs = get_num_procs_online();
287 SpaceSub = ' '; /* option B */
288 QueueLA = 8 * numprocs; /* option x */
289 RefuseLA = 12 * numprocs; /* option X */
290 WkRecipFact = 30000L; /* option y */
291 WkClassFact = 1800L; /* option z */
292 WkTimeFact = 90000L; /* option Z */
293 QueueFactor = WkRecipFact * 20; /* option q */
294 QueueMode = QM_NORMAL; /* what queue items to act upon */
295 FileMode = (RealUid != geteuid()) ? 0644 : 0600;
297 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
298 /* option QueueFileMode */
300 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
301 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
302 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
304 DefUid = pw->pw_uid; /* option u */
305 DefGid = pw->pw_gid; /* option g */
306 DefUser = newstr(pw->pw_name);
310 DefUid = 1; /* option u */
311 DefGid = 1; /* option g */
316 sm_dprintf("setdefaults: DefUser=%s, DefUid=%ld, DefGid=%ld\n",
317 DefUser != NULL ? DefUser : "<1:1>",
318 (long) DefUid, (long) DefGid);
319 CheckpointInterval = 10; /* option C */
320 MaxHopCount = 25; /* option h */
321 set_delivery_mode(SM_FORK, e); /* option d */
322 e->e_errormode = EM_PRINT; /* option e */
325 e->e_xfqgrp = NOQGRP;
326 e->e_xfqdir = NOQDIR;
327 e->e_ctime = curtime();
329 e->e_smtputf8 = false;
331 SevenBitInput = false; /* option 7 */
332 MaxMciCache = 1; /* option k */
333 MciCacheTimeout = 5 MINUTES; /* option K */
334 LogLevel = 9; /* option L */
338 inittimeouts(NULL, false); /* option r */
339 PrivacyFlags = PRIV_PUBLIC; /* option p */
340 MeToo = true; /* option m */
341 SendMIMEErrors = true; /* option f */
342 SuperSafe = SAFE_REALLY; /* option s */
343 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
345 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
347 MimeMode = MM_PASS8BIT;
349 for (i = 0; i < MAXTOCLASS; i++)
351 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
352 TimeOuts.to_q_warning[i] = 0; /* option T */
354 ServiceSwitchFile = "/etc/mail/service.switch";
355 ServiceCacheMaxAge = (time_t) 10;
356 HostsFile = _PATH_HOSTS;
357 PidFile = newstr(_PATH_SENDMAILPID);
358 MustQuoteChars = "@,;:\\()[].'";
359 MciInfoTimeout = 30 MINUTES;
360 MaxRuleRecursion = MAXRULERECURSION;
361 MaxAliasRecursion = 10;
362 MaxMacroRecursion = 10;
363 ColonOkInAddr = true;
364 DontLockReadFiles = true;
365 DontProbeInterfaces = DPI_PROBEALL;
366 DoubleBounceAddr = "postmaster";
367 MaxHeadersLength = MAXHDRSLEN;
368 MaxMimeHeaderLength = MAXLINE;
369 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
370 MaxForwardEntries = 0;
372 MaxNOOPCommands = MAXNOOPCOMMANDS;
374 AuthMechanisms = newstr(AUTH_MECHANISMS);
379 TLS_Srv_Opts = TLS_I_SRV;
380 if (NULL == EVP_digest)
381 EVP_digest = EVP_md5();
382 # if _FFR_TLSFB2CLEAR
383 TLSFallbacktoClear = true;
385 Srv_SSL_Options = SSL_OP_ALL;
386 Clt_SSL_Options = SSL_OP_ALL
387 # ifdef SSL_OP_NO_SSLv2
390 # ifdef SSL_OP_NO_TICKET
394 # ifdef SSL_OP_TLSEXT_PADDING
395 /* SSL_OP_TLSEXT_PADDING breaks compatibility with some sites */
396 Srv_SSL_Options &= ~SSL_OP_TLSEXT_PADDING;
397 Clt_SSL_Options &= ~SSL_OP_TLSEXT_PADDING;
398 # endif /* SSL_OP_TLSEXT_PADDING */
399 #endif /* STARTTLS */
401 HesiodContext = NULL;
404 /* Detect if IPv6 is available at run time */
405 i = socket(AF_INET6, SOCK_STREAM, 0);
414 UseCompressedIPv6Addresses = true;
418 #endif /* NETINET6 */
419 ControlSocketName = NULL;
420 memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo));
421 DataFileBufferSize = 4096;
422 XscriptFileBufferSize = 4096;
423 for (i = 0; i < MAXRWSETS; i++)
424 RuleSetNames[i] = NULL;
426 InputFilters[0] = NULL;
428 RejectLogInterval = 3 HOURS;
429 #if REQUIRES_DIR_FSYNC
430 RequiresDirfsync = true;
432 #if _FFR_RCPTTHROTDELAY
433 BadRcptThrottleDelay = 1;
435 ConnectionRateWindowSize = 60;
436 #if _FFR_BOUNCE_QUEUE
437 BounceQueue = NOQGRP;
446 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
452 struct passwd *defpwent;
453 static char defuserbuf[40];
455 DefUser = defuserbuf;
456 defpwent = sm_getpwuid(DefUid);
457 (void) sm_strlcpy(defuserbuf,
458 (defpwent == NULL || defpwent->pw_name == NULL)
459 ? "nobody" : defpwent->pw_name,
462 sm_dprintf("setdefuser: DefUid=%ld, DefUser=%s\n",
463 (long) DefUid, DefUser);
466 ** SETUPQUEUES -- initialize default queues
468 ** The mqueue QUEUE structure gets filled in after readcf() but
469 ** we need something to point to now for the mailer setup,
470 ** which use "mqueue" as default queue.
478 MaxRunnersPerQueue = 1;
479 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf));
480 makequeue(buf, false);
483 ** SETUPMAILERS -- initialize default mailers
491 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
495 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
499 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
505 ** SETUPMAPS -- set up map classes
508 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
510 extern bool parse __P((MAP *, char *)); \
511 extern bool open __P((MAP *, int)); \
512 extern void close __P((MAP *)); \
513 extern char *lookup __P((MAP *, char *, char **, int *)); \
514 extern void store __P((MAP *, char *, char *)); \
515 s = stab(name, ST_MAPCLASS, ST_ENTER); \
516 s->s_mapclass.map_cname = name; \
517 s->s_mapclass.map_ext = ext; \
518 s->s_mapclass.map_cflags = flags; \
519 s->s_mapclass.map_parse = parse; \
520 s->s_mapclass.map_open = open; \
521 s->s_mapclass.map_close = close; \
522 s->s_mapclass.map_lookup = lookup; \
523 s->s_mapclass.map_store = store; \
532 # if DB_VERSION_MAJOR > 1
533 int major_v, minor_v, patch_v;
535 (void) db_version(&major_v, &minor_v, &patch_v);
536 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
539 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
540 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
541 major_v, minor_v, patch_v);
543 # endif /* DB_VERSION_MAJOR > 1 */
545 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
546 map_parseargs, hash_map_open, db_map_close,
547 db_map_lookup, db_map_store);
549 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
550 map_parseargs, bt_map_open, db_map_close,
551 db_map_lookup, db_map_store);
555 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
556 map_parseargs, ndbm_map_open, ndbm_map_close,
557 ndbm_map_lookup, ndbm_map_store);
561 MAPDEF("cdb", CDBEXT, MCF_ALIASOK|MCF_REBUILDABLE,
562 map_parseargs, cdb_map_open, cdb_map_close,
563 cdb_map_lookup, cdb_map_store);
567 MAPDEF("nis", NULL, MCF_ALIASOK,
568 map_parseargs, nis_map_open, null_map_close,
569 nis_map_lookup, null_map_store);
573 MAPDEF("nisplus", NULL, MCF_ALIASOK,
574 map_parseargs, nisplus_map_open, null_map_close,
575 nisplus_map_lookup, null_map_store);
579 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
580 ldapmap_parseargs, ldapmap_open, ldapmap_close,
581 ldapmap_lookup, null_map_store);
585 MAPDEF("ph", NULL, MCF_NOTPERSIST,
586 ph_map_parseargs, ph_map_open, ph_map_close,
587 ph_map_lookup, null_map_store);
591 /* IRIX 6.5 nsd support */
592 MAPDEF("nsd", NULL, MCF_ALIASOK,
593 map_parseargs, null_map_open, null_map_close,
594 nsd_map_lookup, null_map_store);
598 MAPDEF("hesiod", NULL, MCF_ALIASOK,
599 map_parseargs, hes_map_open, hes_map_close,
600 hes_map_lookup, null_map_store);
604 MAPDEF("netinfo", NULL, MCF_ALIASOK,
605 map_parseargs, ni_map_open, null_map_close,
606 ni_map_lookup, null_map_store);
610 MAPDEF("dns", NULL, 0,
611 dns_map_init, null_map_open, null_map_close,
612 dns_map_lookup, null_map_store);
617 # if _FFR_DNSMAP_ALIASABLE
618 MAPDEF("dns", NULL, MCF_ALIASOK,
619 dns_map_parseargs, dns_map_open, null_map_close,
620 dns_map_lookup, null_map_store);
621 # else /* _FFR_DNSMAP_ALIASABLE */
622 MAPDEF("dns", NULL, 0,
623 dns_map_parseargs, dns_map_open, null_map_close,
624 dns_map_lookup, null_map_store);
625 # endif /* _FFR_DNSMAP_ALIASABLE */
627 #endif /* NAMED_BIND */
630 /* best MX DNS lookup */
631 MAPDEF("bestmx", NULL, MCF_OPTFILE,
632 map_parseargs, null_map_open, null_map_close,
633 bestmx_map_lookup, null_map_store);
636 MAPDEF("host", NULL, 0,
637 host_map_init, null_map_open, null_map_close,
638 host_map_lookup, null_map_store);
640 MAPDEF("text", NULL, MCF_ALIASOK,
641 map_parseargs, text_map_open, null_map_close,
642 text_map_lookup, null_map_store);
644 MAPDEF("stab", NULL, MCF_ALIASOK,
645 map_parseargs, stab_map_open, null_map_close,
646 stab_map_lookup, stab_map_store);
648 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_REBUILDABLE,
649 map_parseargs, impl_map_open, impl_map_close,
650 impl_map_lookup, impl_map_store);
652 /* access to system passwd file */
653 MAPDEF("user", NULL, MCF_OPTFILE,
654 map_parseargs, user_map_open, null_map_close,
655 user_map_lookup, null_map_store);
658 MAPDEF("dequote", NULL, 0,
659 dequote_init, null_map_open, null_map_close,
660 dequote_map, null_map_store);
663 MAPDEF("regex", NULL, 0,
664 regex_map_init, null_map_open, null_map_close,
665 regex_map_lookup, null_map_store);
670 MAPDEF("userdb", ".db", 0,
671 map_parseargs, null_map_open, null_map_close,
672 udb_map_lookup, null_map_store);
675 /* arbitrary programs */
676 MAPDEF("program", NULL, MCF_ALIASOK,
677 map_parseargs, null_map_open, null_map_close,
678 prog_map_lookup, null_map_store);
681 MAPDEF("sequence", NULL, MCF_ALIASOK,
682 seq_map_parse, null_map_open, null_map_close,
683 seq_map_lookup, seq_map_store);
685 /* switched interface to sequenced maps */
686 MAPDEF("switch", NULL, MCF_ALIASOK,
687 map_parseargs, switch_map_open, null_map_close,
688 seq_map_lookup, seq_map_store);
690 /* null map lookup -- really for internal use only */
691 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
692 map_parseargs, null_map_open, null_map_close,
693 null_map_lookup, null_map_store);
695 /* syslog map -- logs information to syslog */
696 MAPDEF("syslog", NULL, 0,
697 syslog_map_parseargs, null_map_open, null_map_close,
698 syslog_map_lookup, null_map_store);
700 /* macro storage map -- rulesets can set macros */
701 MAPDEF("macro", NULL, 0,
702 dequote_init, null_map_open, null_map_close,
703 macro_map_lookup, null_map_store);
705 /* arithmetic map -- add/subtract/compare */
706 MAPDEF("arith", NULL, 0,
707 dequote_init, null_map_open, null_map_close,
708 arith_map_lookup, null_map_store);
710 /* "arpa" map -- IP -> arpa */
711 MAPDEF("arpa", NULL, 0,
712 dequote_init, null_map_open, null_map_close,
713 arpa_map_lookup, null_map_store);
716 /* arbitrary daemons */
717 MAPDEF("socket", NULL, MCF_ALIASOK,
718 map_parseargs, socket_map_open, socket_map_close,
719 socket_map_lookup, null_map_store);
723 /* dprintf map -- logs information to syslog */
724 MAPDEF("dprintf", NULL, 0,
725 dprintf_map_parseargs, null_map_open, null_map_close,
726 dprintf_map_lookup, null_map_store);
729 #if _FFR_SETDEBUG_MAP
730 /* setdebug map -- set debug levels */
731 MAPDEF("setdebug", NULL, 0,
732 dequote_init, null_map_open, null_map_close,
733 setdebug_map_lookup, null_map_store);
737 /* setopt map -- set option */
738 MAPDEF("setopt", NULL, 0,
739 dequote_init, null_map_open, null_map_close,
740 setopt_map_lookup, null_map_store);
745 /* bogus map -- always return tempfail */
746 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
747 map_parseargs, null_map_open, null_map_close,
748 bogus_map_lookup, null_map_store);
754 ** INITHOSTMAPS -- initial host-dependent maps
756 ** This should act as an interface to any local service switch
757 ** provided by the host operating system.
766 ** Should define maps "host" and "users" as necessary
767 ** for this OS. If they are not defined, they will get
768 ** a default value later. It should check to make sure
769 ** they are not defined first, since it's possible that
770 ** the config file has provided an override.
778 char *maptype[MAXMAPSTACK];
779 short mapreturn[MAXMAPACTIONS];
783 ** Make sure we have a host map.
786 if (stab("host", ST_MAP, ST_FIND) == NULL)
788 /* user didn't initialize: set up host map */
789 (void) sm_strlcpy(buf, "host host", sizeof(buf));
791 if (ConfigLevel >= 2)
792 (void) sm_strlcat(buf, " -a. -D", sizeof(buf));
794 (void) makemapentry(buf);
798 ** Set up default aliases maps
801 nmaps = switch_map_find("aliases", maptype, mapreturn);
802 for (i = 0; i < nmaps; i++)
804 if (strcmp(maptype[i], "files") == 0 &&
805 stab("aliases.files", ST_MAP, ST_FIND) == NULL)
807 (void) sm_strlcpy(buf, "aliases.files null",
809 (void) makemapentry(buf);
812 else if (strcmp(maptype[i], "cdb") == 0 &&
813 stab("aliases.cdb", ST_MAP, ST_FIND) == NULL)
815 (void) sm_strlcpy(buf, "aliases.cdb null", sizeof(buf));
816 (void) makemapentry(buf);
820 else if (strcmp(maptype[i], "nisplus") == 0 &&
821 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
823 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
825 (void) makemapentry(buf);
829 else if (strcmp(maptype[i], "nis") == 0 &&
830 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
832 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
834 (void) makemapentry(buf);
838 else if (strcmp(maptype[i], "netinfo") == 0 &&
839 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
841 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
843 (void) makemapentry(buf);
847 else if (strcmp(maptype[i], "hesiod") == 0 &&
848 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
850 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
852 (void) makemapentry(buf);
855 #if LDAPMAP && defined(SUN_EXTENSIONS) && \
856 defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
857 else if (strcmp(maptype[i], "ldap") == 0 &&
858 stab("aliases.ldap", ST_MAP, ST_FIND) == NULL)
860 (void) sm_strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
862 (void) makemapentry(buf);
864 #endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */
866 if (stab("aliases", ST_MAP, ST_FIND) == NULL)
868 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf));
869 (void) makemapentry(buf);
874 ** SWITCH_MAP_FIND -- find the list of types associated with a map
876 ** This is the system-dependent interface to the service switch.
879 ** service -- the name of the service of interest.
880 ** maptype -- an out-array of strings containing the types
881 ** of access to use for this service. There can
882 ** be at most MAXMAPSTACK types for a single service.
883 ** mapreturn -- an out-array of return information bitmaps
887 ** The number of map types filled in, or -1 for failure.
890 ** Preserves errno so nothing in the routine clobbers it.
893 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
894 # define _USE_SUN_NSSWITCH_
897 #if _FFR_HPUX_NSSWITCH
899 # define _USE_SUN_NSSWITCH_
901 #endif /* _FFR_HPUX_NSSWITCH */
903 #ifdef _USE_SUN_NSSWITCH_
904 # include <nsswitch.h>
907 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
908 # define _USE_DEC_SVC_CONF_
911 #ifdef _USE_DEC_SVC_CONF_
912 # include <sys/svcinfo.h>
916 switch_map_find(service, maptype, mapreturn)
918 char *maptype[MAXMAPSTACK];
919 short mapreturn[MAXMAPACTIONS];
922 int save_errno = errno;
924 #ifdef _USE_SUN_NSSWITCH_
925 struct __nsw_switchconfig *nsw_conf;
926 enum __nsw_parse_err pserr;
927 struct __nsw_lookup *lk;
928 static struct __nsw_lookup lkp0 =
929 { "files", {1, 0, 0, 0}, NULL, NULL };
930 static struct __nsw_switchconfig lkp_default =
931 { 0, "sendmail", 3, &lkp0 };
933 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
934 mapreturn[svcno] = 0;
936 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
937 lk = lkp_default.lookups;
939 lk = nsw_conf->lookups;
941 while (lk != NULL && svcno < MAXMAPSTACK)
943 maptype[svcno] = lk->service_name;
944 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
945 mapreturn[MA_NOTFOUND] |= 1 << svcno;
946 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
947 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
948 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
949 mapreturn[MA_TRYAGAIN] |= 1 << svcno;
955 #endif /* _USE_SUN_NSSWITCH_ */
957 #ifdef _USE_DEC_SVC_CONF_
958 struct svcinfo *svcinfo;
961 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
962 mapreturn[svcno] = 0;
967 if (strcmp(service, "hosts") == 0)
969 else if (strcmp(service, "aliases") == 0)
971 else if (strcmp(service, "passwd") == 0)
978 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
980 switch (svcinfo->svcpath[svc][svcno])
983 maptype[svcno] = "files";
987 maptype[svcno] = "nis";
991 maptype[svcno] = "dns";
996 maptype[svcno] = "hesiod";
1007 #endif /* _USE_DEC_SVC_CONF_ */
1009 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
1011 ** Fall-back mechanism.
1015 static time_t servicecachetime; /* time service switch was cached */
1016 time_t now = curtime();
1018 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1019 mapreturn[svcno] = 0;
1021 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
1023 /* (re)read service switch */
1024 register SM_FILE_T *fp;
1025 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
1027 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
1032 servicecachetime = now;
1033 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
1038 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
1043 p = strpbrk(buf, "#\n");
1046 # ifndef SM_NSSWITCH_DELIMS
1047 # define SM_NSSWITCH_DELIMS " \t"
1049 p = strpbrk(buf, SM_NSSWITCH_DELIMS);
1056 sm_syslog(LOG_ERR, NOQID,
1057 "Bad line on %.100s: %.100s",
1062 while (SM_ISSPACE(*p))
1068 ** Find/allocate space for this service entry.
1069 ** Space for all of the service strings
1070 ** are allocated at once. This means
1071 ** that we only have to free the first
1072 ** one to free all of them.
1075 st = stab(buf, ST_SERVICE, ST_ENTER);
1076 if (st->s_service[0] != NULL)
1077 sm_free((void *) st->s_service[0]); /* XXX */
1079 for (svcno = 0; svcno < MAXMAPSTACK; )
1083 st->s_service[svcno++] = p;
1084 p = strpbrk(p, " \t");
1088 while (SM_ISSPACE(*p))
1091 if (svcno < MAXMAPSTACK)
1092 st->s_service[svcno] = NULL;
1094 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1098 /* look up entry in cache */
1099 st = stab(service, ST_SERVICE, ST_FIND);
1100 if (st != NULL && st->s_service[0] != NULL)
1104 while (svcno < MAXMAPSTACK)
1106 maptype[svcno] = st->s_service[svcno];
1107 if (maptype[svcno++] == NULL)
1113 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1115 #if !defined(_USE_SUN_NSSWITCH_)
1116 /* if the service file doesn't work, use an absolute fallback */
1117 # ifdef _USE_DEC_SVC_CONF_
1120 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
1121 mapreturn[svcno] = 0;
1123 if (strcmp(service, "aliases") == 0)
1125 SM_ASSERT(svcno < MAXMAPSTACK);
1126 maptype[svcno++] = "files";
1128 SM_ASSERT(svcno < MAXMAPSTACK);
1129 maptype[svcno++] = "cdb";
1131 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1132 SM_ASSERT(svcno < MAXMAPSTACK);
1133 maptype[svcno++] = "netinfo";
1135 # ifdef AUTO_NIS_ALIASES
1137 SM_ASSERT(svcno < MAXMAPSTACK);
1138 maptype[svcno++] = "nisplus";
1141 SM_ASSERT(svcno < MAXMAPSTACK);
1142 maptype[svcno++] = "nis";
1144 # endif /* AUTO_NIS_ALIASES */
1148 if (strcmp(service, "hosts") == 0)
1151 SM_ASSERT(svcno < MAXMAPSTACK);
1152 maptype[svcno++] = "dns";
1153 # else /* NAMED_BIND */
1154 # if defined(sun) && !defined(BSD)
1156 SM_ASSERT(svcno < MAXMAPSTACK);
1157 maptype[svcno++] = "nis";
1158 # endif /* defined(sun) && !defined(BSD) */
1159 # endif /* NAMED_BIND */
1160 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1161 SM_ASSERT(svcno < MAXMAPSTACK);
1162 maptype[svcno++] = "netinfo";
1164 SM_ASSERT(svcno < MAXMAPSTACK);
1165 maptype[svcno++] = "files";
1171 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1174 ** USERNAME -- return the user id of the logged in user.
1180 ** The login name of the logged in user.
1186 ** The return value is statically allocated.
1192 static char *myname = NULL;
1193 extern char *getlogin __P((void));
1194 register struct passwd *pw;
1196 /* cache the result */
1199 myname = getlogin();
1200 if (SM_IS_EMPTY(myname))
1202 pw = sm_getpwuid(RealUid);
1204 myname = pw->pw_name;
1208 uid_t uid = RealUid;
1210 if ((pw = sm_getpwnam(myname)) == NULL ||
1211 (uid != 0 && uid != pw->pw_uid))
1213 pw = sm_getpwuid(uid);
1215 myname = pw->pw_name;
1218 if (SM_IS_EMPTY(myname))
1220 syserr("554 5.3.0 Who are you?");
1221 myname = "postmaster";
1223 else if (strpbrk(myname, ",;:/|\"\\") != NULL)
1224 myname = addquotes(myname, NULL);
1226 myname = sm_pstrdup_x(myname);
1231 ** TTYPATH -- Get the path of the user's tty
1233 ** Returns the pathname of the user's tty. Returns NULL if
1234 ** the user is not logged in or if s/he has write permission
1241 ** pathname of the user's tty.
1242 ** NULL if not logged in or write permission denied.
1248 ** Return value is in a local buffer.
1258 register char *pathn;
1259 extern char *ttyname __P((int));
1260 extern char *getlogin __P((void));
1262 /* compute the pathname of the controlling tty */
1263 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
1264 (pathn = ttyname(0)) == NULL)
1270 /* see if we have write permission */
1271 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
1277 /* see if the user is logged in */
1278 if (getlogin() == NULL)
1285 ** CHECKCOMPAT -- check for From and To person compatible.
1287 ** This routine can be supplied on a per-installation basis
1288 ** to determine whether a person is allowed to send a message.
1289 ** This allows restriction of certain types of internet
1290 ** forwarding or registration of users.
1292 ** If the hosts are found to be incompatible, an error
1293 ** message should be given using "usrerr" and an EX_ code
1294 ** should be returned. You can also set to->q_status to
1295 ** a DSN-style status code.
1297 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1298 ** body during the return-to-sender function; this should be done
1299 ** on huge messages. This bit may already be set by the ESMTP
1303 ** to -- the person being sent to.
1309 ** none (unless you include the usrerr stuff)
1314 register ADDRESS *to;
1315 register ENVELOPE *e;
1318 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1319 to->q_paddr, e->e_from.q_paddr);
1322 /* this code is intended as an example only */
1325 s = stab("arpa", ST_MAILER, ST_FIND);
1326 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
1327 to->q_mailer == s->s_mailer)
1329 usrerr("553 No ARPA mail through this machine: see your system administration");
1330 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1331 to->q_status = "5.7.1";
1332 return EX_UNAVAILABLE;
1334 #endif /* EXAMPLE_CODE */
1338 #ifdef SUN_EXTENSIONS
1344 /* Check for large file descriptor */
1345 if (fstat(fileno(stdin), &sbuf) < 0)
1347 if (errno == EOVERFLOW)
1354 #endif /* SUN_EXTENSIONS */
1357 ** INIT_MD -- do machine dependent initializations
1359 ** Systems that have global modes that should be set should do
1360 ** them here rather than in main.
1364 # include <compat.h>
1368 # include <shares.h>
1377 setcompat(getcompat() | COMPAT_BSDPROT);
1380 #ifdef SUN_EXTENSIONS
1385 /* keep gethostby*() from stripping the local domain name */
1386 set_domain_trim_off();
1388 #if defined(__QNX__) && !defined(__QNXNTO__)
1390 ** Due to QNX's network distributed nature, you can target a tcpip
1391 ** stack on a different node in the qnx network; this patch lets
1392 ** this feature work. The __sock_locate() must be done before the
1393 ** environment is clear.
1396 #endif /* __QNX__ */
1397 #if SECUREWARE || defined(_SCO_unix_)
1398 set_auth_parameters(argc, argv);
1402 ** This is required for highest security levels (the kernel
1403 ** won't let it call set*uid() or run setuid binaries without
1404 ** it). It may be necessary on other SECUREWARE systems.
1407 if (getluid() == -1)
1409 # endif /* _SCO_unix_ */
1410 #endif /* SECUREWARE || defined(_SCO_unix_) */
1412 #ifdef VENDOR_DEFAULT
1413 VendorCode = VENDOR_DEFAULT;
1415 VendorCode = VENDOR_BERKELEY;
1419 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1421 ** Called once, on startup.
1424 ** e -- the global envelope.
1430 ** vendor-dependent.
1434 init_vendor_macros(e)
1435 register ENVELOPE *e;
1439 ** GETLA -- get the current load average
1441 ** This code stolen from la.c.
1447 ** The current load average as an integer.
1453 /* try to guess what style of load average we have */
1454 #define LA_ZERO 1 /* always return load average as zero */
1455 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1456 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1457 #define LA_SUBR 4 /* call getloadavg */
1458 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1459 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1460 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1461 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1462 #define LA_DGUX 9 /* special DGUX implementation */
1463 #define LA_HPUX 10 /* special HPUX implementation */
1464 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1465 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1466 #define LA_DEVSHORT 13 /* read short from a device */
1467 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1468 #define LA_PSET 15 /* Solaris per-processor-set load average */
1469 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1471 /* do guesses based on general OS type */
1473 # define LA_TYPE LA_ZERO
1477 # if defined(unixpc)
1481 # if defined(__alpha) || defined(IRIX)
1485 #endif /* ! FSHIFT */
1492 # define FSCALE (1 << FSHIFT)
1497 # define LA_AVENRUN "avenrun"
1499 # define LA_AVENRUN "_avenrun"
1501 #endif /* ! LA_AVENRUN */
1503 /* _PATH_KMEM should be defined in <paths.h> */
1505 # define _PATH_KMEM "/dev/kmem"
1508 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1512 /* _PATH_UNIX should be defined in <paths.h> */
1514 # if defined(SYSTEM5)
1515 # define _PATH_UNIX "/unix"
1517 # define _PATH_UNIX "/vmunix"
1519 # endif /* ! _PATH_UNIX */
1523 # else /* _AUX_SOURCE */
1529 # endif /* _AUX_SOURCE */
1530 # define X_AVENRUN 0
1536 static int kmem = -1;
1537 # if LA_TYPE == LA_INT
1539 # else /* LA_TYPE == LA_INT */
1540 # if LA_TYPE == LA_SHORT
1543 # if LA_TYPE == LA_LONGLONG
1544 long long avenrun[3];
1548 # endif /* LA_TYPE == LA_SHORT */
1549 # endif /* LA_TYPE == LA_INT */
1550 extern off_t lseek __P((int, off_t, int));
1555 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
1556 sizeof(Nl[X_AVENRUN].n_name));
1557 Nl[1].n_name[0] = '\0';
1558 # endif /* _AUX_SOURCE */
1560 # if defined(_AIX3) || defined(_AIX4)
1561 if (knlist(Nl, 1, sizeof(Nl[0])) < 0)
1563 if (nlist(_PATH_UNIX, Nl) < 0)
1567 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
1568 sm_errstring(errno));
1571 if (Nl[X_AVENRUN].n_value == 0)
1574 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1575 _PATH_UNIX, LA_AVENRUN);
1578 # ifdef NAMELISTMASK
1579 Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1582 kmem = open(_PATH_KMEM, 0, 0);
1586 sm_dprintf("getla: open(/dev/kmem): %s\n",
1587 sm_errstring(errno));
1590 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1591 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1594 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1595 sm_errstring(errno));
1602 sm_dprintf("getla: symbol address = %#lx\n",
1603 (unsigned long) Nl[X_AVENRUN].n_value);
1604 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1605 read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
1609 sm_dprintf("getla: lseek or read: %s\n",
1610 sm_errstring(errno));
1613 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1616 # if LA_TYPE == LA_SHORT
1617 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1619 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1620 # else /* LA_TYPE == LA_SHORT */
1621 # if LA_TYPE == LA_LONGLONG
1622 sm_dprintf("getla: avenrun = %lld", avenrun[0]);
1624 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
1625 # else /* LA_TYPE == LA_LONGLONG */
1626 sm_dprintf("getla: avenrun = %ld", avenrun[0]);
1628 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
1629 # endif /* LA_TYPE == LA_LONGLONG */
1630 # endif /* LA_TYPE == LA_SHORT */
1634 sm_dprintf("getla: %d\n",
1635 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1636 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1637 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1640 sm_dprintf("getla: avenrun = %g", avenrun[0]);
1642 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
1646 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1647 return ((int) (avenrun[0] + 0.5));
1648 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1651 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1653 #if LA_TYPE == LA_READKSYM
1655 # include <sys/ksym.h>
1661 static int kmem = -1;
1663 struct mioc_rksym mirk;
1667 kmem = open("/dev/kmem", 0, 0);
1671 sm_dprintf("getla: open(/dev/kmem): %s\n",
1672 sm_errstring(errno));
1675 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1676 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1679 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1680 sm_errstring(errno));
1686 mirk.mirk_symname = LA_AVENRUN;
1687 mirk.mirk_buf = avenrun;
1688 mirk.mirk_buflen = sizeof(avenrun);
1689 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
1692 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1693 sm_errstring(errno));
1698 sm_dprintf("getla: avenrun = %d", avenrun[0]);
1700 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
1704 sm_dprintf("getla: %d\n",
1705 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1706 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1709 #endif /* LA_TYPE == LA_READKSYM */
1711 #if LA_TYPE == LA_DGUX
1713 # include <sys/dg_sys_info.h>
1718 struct dg_sys_info_load_info load_info;
1720 dg_sys_info((long *)&load_info,
1721 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1724 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1726 return ((int) (load_info.one_minute + 0.5));
1729 #endif /* LA_TYPE == LA_DGUX */
1731 #if LA_TYPE == LA_HPUX
1733 /* forward declarations to keep gcc from complaining */
1738 struct pst_diskinfo;
1739 struct pst_processor;
1741 struct pst_swapinfo;
1743 # include <sys/param.h>
1744 # include <sys/pstat.h>
1749 struct pst_dynamic pstd;
1751 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1752 (size_t) 1, 0) == -1)
1756 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1758 return (int) (pstd.psd_avg_1_min + 0.5);
1761 #endif /* LA_TYPE == LA_HPUX */
1763 #if LA_TYPE == LA_SUBR
1770 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1773 sm_dprintf("getla: getloadavg failed: %s",
1774 sm_errstring(errno));
1778 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
1779 return ((int) (avenrun[0] + 0.5));
1782 #endif /* LA_TYPE == LA_SUBR */
1784 #if LA_TYPE == LA_MACH
1787 ** This has been tested on NEXTSTEP release 2.1/3.X.
1790 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1791 # include <mach/mach.h>
1799 processor_set_t default_set;
1800 kern_return_t error;
1801 unsigned int info_count;
1802 struct processor_set_basic_info info;
1805 error = processor_set_default(host_self(), &default_set);
1806 if (error != KERN_SUCCESS)
1809 sm_dprintf("getla: processor_set_default failed: %s",
1810 sm_errstring(errno));
1813 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1814 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1815 &host, (processor_set_info_t)&info,
1816 &info_count) != KERN_SUCCESS)
1819 sm_dprintf("getla: processor_set_info failed: %s",
1820 sm_errstring(errno));
1824 sm_dprintf("getla: %d\n",
1825 (int) ((info.load_average + (LOAD_SCALE / 2)) /
1827 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1830 #endif /* LA_TYPE == LA_MACH */
1832 #if LA_TYPE == LA_PROCSTR
1833 # if SM_CONF_BROKEN_STRTOD
1834 ERROR: This OS has most likely a broken strtod() implemenentation.
1835 ERROR: The function is required for getla().
1836 ERROR: Check the compilation options _LA_PROCSTR and
1837 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
1838 # endif /* SM_CONF_BROKEN_STRTOD */
1841 ** Read /proc/loadavg for the load average. This is assumed to be
1842 ** in a format like "0.15 0.12 0.06".
1844 ** Initially intended for Linux. This has been in the kernel
1845 ** since at least 0.99.15.
1848 # ifndef _PATH_LOADAVG
1849 # define _PATH_LOADAVG "/proc/loadavg"
1856 register int result;
1859 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
1864 sm_dprintf("getla: sm_io_open(%s): %s\n",
1865 _PATH_LOADAVG, sm_errstring(errno));
1868 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
1869 (void) sm_io_close(fp, SM_TIME_DEFAULT);
1873 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1874 result, sm_errstring(errno));
1879 sm_dprintf("getla(): %.2f\n", avenrun);
1881 return ((int) (avenrun + 0.5));
1884 #endif /* LA_TYPE == LA_PROCSTR */
1886 #if LA_TYPE == LA_IRIX6
1888 # include <sys/sysmp.h>
1891 # define CAST_SYSMP(x) (x)
1893 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1900 static int kmem = -1;
1905 kmem = open(_PATH_KMEM, 0, 0);
1909 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
1910 sm_errstring(errno));
1913 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
1914 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
1917 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1918 sm_errstring(errno));
1925 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
1927 read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
1930 sm_dprintf("getla: lseek or read: %s\n",
1931 sm_errstring(errno));
1936 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
1938 sm_dprintf(", %ld, %ld",
1939 (long int) avenrun[1], (long int) avenrun[2]);
1944 sm_dprintf("getla: %d\n",
1945 (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1946 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1949 #endif /* LA_TYPE == LA_IRIX6 */
1951 #if LA_TYPE == LA_KSTAT
1958 static kstat_ctl_t *kc = NULL;
1959 static kstat_t *ksp = NULL;
1963 if (kc == NULL) /* if not initialized before */
1968 sm_dprintf("getla: kstat_open(): %s\n",
1969 sm_errstring(errno));
1973 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
1977 sm_dprintf("getla: kstat_lookup(): %s\n",
1978 sm_errstring(errno));
1981 if (kstat_read(kc, ksp, NULL) < 0)
1984 sm_dprintf("getla: kstat_read(): %s\n",
1985 sm_errstring(errno));
1988 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
1989 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
1990 /* kstat_close(kc); /o do not close for fast access */
1994 #endif /* LA_TYPE == LA_KSTAT */
1996 #if LA_TYPE == LA_DEVSHORT
1999 ** Read /dev/table/avenrun for the load average. This should contain
2000 ** three shorts for the 1, 5, and 15 minute loads. We only read the
2001 ** first, since that's all we care about.
2003 ** Intended for SCO OpenServer 5.
2006 # ifndef _PATH_AVENRUN
2007 # define _PATH_AVENRUN "/dev/table/avenrun"
2013 static int afd = -1;
2020 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
2024 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
2027 sm_syslog(LOG_ERR, NOQID,
2028 "can't open %s: %s",
2029 _PATH_AVENRUN, sm_errstring(errno));
2034 r = read(afd, &avenrun, sizeof(avenrun));
2035 if (r != sizeof(avenrun))
2037 sm_syslog(LOG_ERR, NOQID,
2038 "can't read %s: %s", _PATH_AVENRUN,
2039 r == -1 ? sm_errstring(errno) : "short read");
2044 sm_dprintf("getla: avenrun = %d\n", avenrun);
2045 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
2047 sm_dprintf("getla: %d\n", loadav);
2051 #endif /* LA_TYPE == LA_DEVSHORT */
2053 #if LA_TYPE == LA_ALPHAOSF
2056 # include <sys/table.h>
2062 struct tbl_loadavg tab;
2064 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
2067 sm_dprintf("getla: table %s\n", sm_errstring(errno));
2072 sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
2075 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
2078 ave = (int) (tab.tl_avenrun.d[2] + 0.5);
2081 sm_dprintf("getla: %d\n", ave);
2086 #endif /* LA_TYPE == LA_ALPHAOSF */
2088 #if LA_TYPE == LA_PSET
2095 if (pset_getloadavg(PS_MYID, avenrun,
2096 sizeof(avenrun) / sizeof(avenrun[0])) < 0)
2099 sm_dprintf("getla: pset_getloadavg failed: %s",
2100 sm_errstring(errno));
2104 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
2105 return ((int) (avenrun[0] + 0.5));
2108 #endif /* LA_TYPE == LA_PSET */
2110 #if LA_TYPE == LA_ZERO
2116 sm_dprintf("getla: ZERO\n");
2120 #endif /* LA_TYPE == LA_ZERO */
2123 * Copyright 1989 Massachusetts Institute of Technology
2125 * Permission to use, copy, modify, distribute, and sell this software and its
2126 * documentation for any purpose is hereby granted without fee, provided that
2127 * the above copyright notice appear in all copies and that both that
2128 * copyright notice and this permission notice appear in supporting
2129 * documentation, and that the name of M.I.T. not be used in advertising or
2130 * publicity pertaining to distribution of the software without specific,
2131 * written prior permission. M.I.T. makes no representations about the
2132 * suitability of this software for any purpose. It is provided "as is"
2133 * without express or implied warranty.
2135 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2136 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2137 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2138 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2139 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2140 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2142 * Authors: Many and varied...
2145 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2147 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2152 # include <apollo/base.h>
2155 int getloadavg( call_data )
2156 caddr_t call_data; /* pointer to (double) return value */
2158 double *avenrun = (double *) call_data;
2163 proc1_$get_loadav(loadav, &st);
2164 *avenrun = loadav[0] / (double) (1 << 16);
2169 ** SM_GETLA -- get the current load average
2178 ** Set CurrentLA to the current load average.
2179 ** Set {load_avg} in GlobalMacros to the current load average.
2187 CurrentLA = getla();
2188 (void) sm_snprintf(labuf, sizeof(labuf), "%d", CurrentLA);
2189 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
2192 ** SHOULDQUEUE -- should this message be queued or sent?
2194 ** Compares the message cost to the load average to decide.
2196 ** Note: Do NOT change this API! It is documented in op.me
2197 ** and theoretically the user can change this function...
2200 ** pri -- the priority of the message in question.
2201 ** ct -- the message creation time (unused, but see above).
2204 ** true -- if this message should be queued up for the
2206 ** false -- if the load is low enough to send this message.
2214 shouldqueue(pri, ct)
2224 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2228 if (QueueLowMem > 0 &&
2229 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2230 memfree < QueueLowMem)
2233 sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n",
2234 memfree, QueueLowMem);
2237 #endif /* _FFR_MEMSTAT */
2238 if (CurrentLA < QueueLA)
2241 sm_dprintf("false (CurrentLA < QueueLA)\n");
2244 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
2246 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
2251 ** REFUSECONNECTIONS -- decide if connections should be refused
2254 ** e -- the current envelope.
2255 ** dn -- number of daemon.
2256 ** active -- was this daemon actually active?
2259 ** true if incoming SMTP connections should be refused
2261 ** false if we should accept new work.
2264 ** Sets process title when it is rejecting connections.
2268 refuseconnections(e, dn, active)
2273 static time_t lastconn[MAXDAEMONS];
2274 static int conncnt[MAXDAEMONS];
2275 static time_t firstrejtime[MAXDAEMONS];
2276 static time_t nextlogtime[MAXDAEMONS];
2288 SM_ASSERT(dn < MAXDAEMONS);
2289 if (ConnRateThrottle > 0)
2296 if (now != lastconn[dn])
2301 else if (conncnt[dn]++ > ConnRateThrottle)
2303 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2304 /* sleep to flatten out connection load */
2305 sm_setproctitle(true, e, D_MSG_CRT,
2309 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
2315 else if (now != lastconn[dn])
2320 if (RefuseLowMem > 0 &&
2321 sm_memstat_get(MemoryResource, &memfree) >= 0 &&
2322 memfree < RefuseLowMem)
2324 # define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
2325 sm_setproctitle(true, e, R_MSG_LM, Daemons[dn].d_name, memfree);
2327 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM,
2328 Daemons[dn].d_name, memfree);
2331 #endif /* _FFR_MEMSTAT */
2333 limit = (Daemons[dn].d_refuseLA != DPO_NOTSET) ?
2334 Daemons[dn].d_refuseLA : RefuseLA;
2335 if (limit > 0 && CurrentLA >= limit)
2339 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2340 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2341 sm_setproctitle(true, e, R_MSG_LA, Daemons[dn].d_name,
2344 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA,
2345 Daemons[dn].d_name, CurrentLA);
2347 if (firstrejtime[dn] == 0)
2349 firstrejtime[dn] = now;
2350 nextlogtime[dn] = now + RejectLogInterval;
2352 else if (nextlogtime[dn] < now)
2354 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, Daemons[dn].d_name,
2355 pintvl(now - firstrejtime[dn], true));
2356 nextlogtime[dn] = now + RejectLogInterval;
2361 firstrejtime[dn] = 0;
2363 limit = (Daemons[dn].d_delayLA != DPO_NOTSET) ?
2364 Daemons[dn].d_delayLA : DelayLA;
2365 if (limit > 0 && CurrentLA >= limit)
2368 static time_t log_delay = (time_t) 0;
2370 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2371 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2372 /* sleep to flatten out connection load */
2373 sm_setproctitle(true, e, D_MSG_LA, Daemons[dn].d_name,
2375 if (LogLevel > 8 && (now = curtime()) > log_delay)
2377 sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
2378 Daemons[dn].d_name, CurrentLA, limit);
2379 log_delay = now + MIN_DELAY_LOG;
2384 limit = (Daemons[dn].d_maxchildren != DPO_NOTSET) ?
2385 Daemons[dn].d_maxchildren : MaxChildren;
2386 if (limit > 0 && CurChildren >= limit)
2389 if (CurChildren >= limit)
2391 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2392 sm_setproctitle(true, e, R_MSG_CHILD,
2393 Daemons[dn].d_name, CurChildren,
2396 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
2397 Daemons[dn].d_name, CurChildren,
2406 ** SETPROCTITLE -- set process title for ps
2409 ** fmt -- a printf style format string.
2410 ** a, b, c -- possible parameters to fmt.
2416 ** Clobbers argv of our main procedure so ps(1) will
2417 ** display the title.
2420 #define SPT_NONE 0 /* don't use it at all */
2421 #define SPT_REUSEARGV 1 /* cover argv with title information */
2422 #define SPT_BUILTIN 2 /* use libc builtin */
2423 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2424 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2425 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2426 #define SPT_SCO 6 /* write kernel u. area */
2427 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2430 # define SPT_TYPE SPT_REUSEARGV
2433 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2435 # if SPT_TYPE == SPT_PSTAT
2436 # include <sys/pstat.h>
2438 # if SPT_TYPE == SPT_PSSTRINGS
2439 # include <machine/vmparam.h>
2440 # include <sys/exec.h>
2441 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2443 # define SPT_TYPE SPT_REUSEARGV
2444 # else /* ! PS_STRINGS */
2445 # ifndef NKPDE /* FreeBSD 2.0 */
2447 typedef unsigned int *pt_entry_t;
2448 # endif /* ! NKPDE */
2449 # endif /* ! PS_STRINGS */
2450 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2452 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2453 # define SETPROC_STATIC static
2455 # define SETPROC_STATIC
2458 # if SPT_TYPE == SPT_SYSMIPS
2459 # include <sys/sysmips.h>
2460 # include <sys/sysnews.h>
2463 # if SPT_TYPE == SPT_SCO
2464 # include <sys/immu.h>
2465 # include <sys/dir.h>
2466 # include <sys/user.h>
2467 # include <sys/fs/s5param.h>
2468 # if PSARGSZ > MAXLINE
2469 # define SPT_BUFSIZE PSARGSZ
2471 # endif /* SPT_TYPE == SPT_SCO */
2473 # ifndef SPT_PADCHAR
2474 # define SPT_PADCHAR ' '
2477 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2480 # define SPT_BUFSIZE MAXLINE
2486 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2487 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2488 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2489 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2490 ** you use this FFR.
2493 # ifdef SPT_ALIGN_SIZE
2494 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2496 # define SPT_ALIGN(x, align) (x)
2498 #else /* _FFR_SPT_ALIGN */
2499 # define SPT_ALIGN(x, align) (x)
2500 #endif /* _FFR_SPT_ALIGN */
2503 ** Pointers for setproctitle.
2504 ** This allows "ps" listings to give more useful information.
2507 static char **Argv = NULL; /* pointer to argument vector */
2508 static char *LastArgv = NULL; /* end of argv */
2509 #if SPT_TYPE != SPT_BUILTIN
2510 static void setproctitle __P((const char *, ...));
2514 initsetproctitle(argc, argv, envp)
2523 extern char **environ;
2526 ** Move the environment so setproctitle can use the space at
2527 ** the top of memory.
2532 for (i = 0; envp[i] != NULL; i++)
2534 environ = (char **) xalloc(sizeof(char *) * (i + 1));
2535 for (i = 0; envp[i] != NULL; i++)
2536 environ[i] = newstr(envp[i]);
2541 ** Save start and extent of argv for setproctitle.
2547 ** Determine how much space we can use for setproctitle.
2548 ** Use all contiguous argv and envp pointers starting at argv[0]
2553 # ifdef SPT_ALIGN_SIZE
2554 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
2557 #endif /* _FFR_SPT_ALIGN */
2559 for (i = 0; i < argc; i++)
2561 if (i == 0 || LastArgv + 1 == argv[i])
2562 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
2564 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
2566 if (LastArgv + 1 == envp[i])
2567 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
2571 #if SPT_TYPE != SPT_BUILTIN
2576 setproctitle(const char *fmt, ...)
2577 # else /* __STDC__ */
2578 setproctitle(fmt, va_alist)
2581 # endif /* __STDC__ */
2583 # if SPT_TYPE != SPT_NONE
2586 SETPROC_STATIC char buf[SPT_BUFSIZE];
2588 # if SPT_TYPE == SPT_PSTAT
2591 # if SPT_TYPE == SPT_SCO
2594 static int kmem = -1;
2595 static pid_t kmempid = -1;
2597 # endif /* SPT_TYPE == SPT_SCO */
2601 /* print sendmail: heading for grep */
2602 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
2605 /* print the argument string */
2606 SM_VA_START(ap, fmt);
2607 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
2610 i = (int) strlen(buf);
2614 # if SPT_TYPE == SPT_PSTAT
2615 pst.pst_command = buf;
2616 pstat(PSTAT_SETCMD, pst, i, 0, 0);
2618 # if SPT_TYPE == SPT_PSSTRINGS
2619 PS_STRINGS->ps_nargvstr = 1;
2620 PS_STRINGS->ps_argvstr = buf;
2622 # if SPT_TYPE == SPT_SYSMIPS
2623 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
2625 # if SPT_TYPE == SPT_SCO
2626 if (kmem < 0 || kmempid != CurrentPid)
2630 kmem = open(_PATH_KMEM, O_RDWR, 0);
2633 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
2634 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
2640 kmempid = CurrentPid;
2642 buf[PSARGSZ - 1] = '\0';
2643 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
2644 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
2645 (void) write(kmem, buf, PSARGSZ);
2646 # endif /* SPT_TYPE == SPT_SCO */
2647 # if SPT_TYPE == SPT_REUSEARGV
2648 if (LastArgv == NULL)
2651 if (i > LastArgv - Argv[0] - 2)
2653 i = LastArgv - Argv[0] - 2;
2656 (void) sm_strlcpy(Argv[0], buf, i + 1);
2658 while (p < LastArgv)
2661 # endif /* SPT_TYPE == SPT_REUSEARGV */
2662 # if SPT_TYPE == SPT_CHANGEARGV
2666 # endif /* SPT_TYPE != SPT_NONE */
2668 #endif /* SPT_TYPE != SPT_BUILTIN */
2671 ** SM_SETPROCTITLE -- set process task and set process title for ps
2673 ** Possibly set process status and call setproctitle() to
2674 ** change the ps display.
2677 ** status -- whether or not to store as process status
2678 ** e -- the current envelope.
2679 ** fmt -- a printf style format string.
2680 ** a, b, c -- possible parameters to fmt.
2689 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
2690 #else /* __STDC__ */
2691 sm_setproctitle(status, e, fmt, va_alist)
2696 #endif /* __STDC__ */
2698 char buf[SPT_BUFSIZE];
2701 /* print the argument string */
2702 SM_VA_START(ap, fmt);
2703 (void) sm_vsnprintf(buf, sizeof(buf), fmt, ap);
2707 proc_list_set(CurrentPid, buf);
2709 if (ProcTitlePrefix != NULL)
2711 char prefix[SPT_BUFSIZE];
2713 expand(ProcTitlePrefix, prefix, sizeof(prefix), e);
2714 setproctitle("%s: %s", prefix, buf);
2717 setproctitle("%s", buf);
2720 ** WAITFOR -- wait for a particular process id.
2723 ** pid -- process id to wait for.
2727 ** -1 if pid never shows up.
2745 proc_list_drop(i, st, NULL);
2746 } while ((i >= 0 || errno == EINTR) && i != pid);
2755 ** status -- pointer to status (return value)
2771 #if defined(ISC_UNIX) || defined(_SCO_unix_)
2775 #if defined(ISC_UNIX) || defined(_SCO_unix_)
2776 savesig = sm_releasesignal(SIGCHLD);
2779 #if defined(ISC_UNIX) || defined(_SCO_unix_)
2781 sm_blocksignal(SIGCHLD);
2784 *status = st.w_status;
2791 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2794 ** sig -- the signal that got us here (unused).
2800 ** Picks up extant zombies.
2801 ** Control socket exits may restart/shutdown daemon.
2803 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2804 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2813 int save_errno = errno;
2821 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
2826 #else /* HASWAITPID */
2830 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
2832 st = status.w_status;
2833 # else /* WNOHANG */
2837 ** Catch one zombie -- we will be re-invoked (we hope) if there
2838 ** are more. Unreliable signals probably break this, but this
2839 ** is the "old system" situation -- waitpid or wait3 are to be
2840 ** strongly preferred.
2843 if ((pid = wait(&status)) > 0)
2846 # endif /* WNOHANG */
2847 #endif /* HASWAITPID */
2848 /* Drop PID and check if it was a control socket child */
2849 proc_list_drop(pid, st, NULL);
2851 FIX_SYSV_SIGNAL(sig, reapchild);
2853 return SIGFUNC_RETURN;
2856 ** GETDTSIZE -- return number of file descriptors
2858 ** Only on non-BSD systems
2864 ** size of file descriptor table
2871 # include <sys/resource.h>
2877 #ifdef RLIMIT_NOFILE
2880 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
2882 #endif /* RLIMIT_NOFILE */
2884 #if HASGETDTABLESIZE
2885 return getdtablesize();
2886 #else /* HASGETDTABLESIZE */
2887 # ifdef _SC_OPEN_MAX
2888 return sysconf(_SC_OPEN_MAX);
2892 #endif /* HASGETDTABLESIZE */
2895 ** UNAME -- get the UUCP name of this system.
2902 struct utsname *name;
2907 name->nodename[0] = '\0';
2909 /* try /etc/whoami -- one line with the node name */
2910 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
2911 SM_IO_RDONLY, NULL)) != NULL)
2913 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
2915 (void) sm_io_close(file, SM_TIME_DEFAULT);
2916 n = strchr(name->nodename, '\n');
2919 if (name->nodename[0] != '\0')
2923 /* try /usr/include/whoami.h -- has a #define somewhere */
2924 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
2925 "/usr/include/whoami.h", SM_IO_RDONLY, NULL))
2930 while (sm_io_fgets(file, SM_TIME_DEFAULT,
2931 buf, sizeof(buf)) >= 0)
2933 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
2934 NODE_LENGTH, name->nodename) > 0)
2937 (void) sm_io_close(file, SM_TIME_DEFAULT);
2938 if (name->nodename[0] != '\0')
2944 #endif /* !HASUNAME */
2946 ** INITGROUPS -- initialize groups
2948 ** Stub implementation for System V style systems
2953 initgroups(name, basegid)
2959 #endif /* !HASINITGROUPS */
2962 ** SETGROUPS -- set group list
2964 ** Stub implementation for systems that don't have group lists
2969 setgroups(ngroups, grouplist)
2971 GIDSET_T grouplist[];
2975 #endif /* ! NGROUPS_MAX */
2978 ** SETSID -- set session id (for non-POSIX systems)
2989 fd = open("/dev/tty", O_RDWR, 0);
2992 (void) ioctl(fd, TIOCNOTTY, (char *) 0);
2995 # endif /* TIOCNOTTY */
2999 return setpgid(0, CurrentPid);
3003 #endif /* !HASSETSID */
3005 ** FSYNC -- dummy fsync
3014 return fcntl(fd, F_SETFL, O_SYNC);
3016 /* nothing we can do */
3020 #endif /* NEEDFSYNC */
3023 ** DGUX_INET_ADDR -- inet_addr for DG/UX
3025 ** Data General DG/UX version of inet_addr returns a struct in_addr
3026 ** instead of a long. This patches things. Only needed on versions
3035 dgux_inet_addr(host)
3038 struct in_addr haddr;
3040 haddr = inet_addr(host);
3041 return haddr.s_addr;
3044 #endif /* DGUX_5_4_2 */
3046 ** GETOPT -- for old systems or systems with bogus implementations
3052 * Copyright (c) 1985 Regents of the University of California.
3053 * All rights reserved. The Berkeley software License Agreement
3054 * specifies the terms and conditions for redistribution.
3058 ** this version hacked to add `atend' flag to allow state machine
3059 ** to reset if invoked by the program to scan args for a 2nd time
3062 # if defined(LIBC_SCCS) && !defined(lint)
3063 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
3067 ** get option letter from argument vector
3069 # ifdef _CONVEX_SOURCE
3070 extern int optind, opterr, optopt;
3071 extern char *optarg;
3072 # else /* _CONVEX_SOURCE */
3073 int opterr = 1; /* if error message should be printed */
3074 int optind = 1; /* index into parent argv vector */
3075 int optopt = 0; /* character checked for validity */
3076 char *optarg = NULL; /* argument associated with option */
3077 # endif /* _CONVEX_SOURCE */
3079 # define BADCH (int)'?'
3081 # define tell(s) if (opterr) \
3082 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
3083 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
3084 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
3085 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
3089 getopt(nargc,nargv,ostr)
3094 static char *place = EMSG; /* option letter processing */
3095 static char atend = 0;
3096 register char *oli = NULL; /* option letter list index */
3102 if(!*place) { /* update scanning pointer */
3103 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
3107 if (*place == '-') { /* found "--" */
3112 } /* option letter okay? */
3113 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
3114 if (!*place) ++optind;
3115 tell(": illegal option -- ");
3117 if (oli && *++oli != ':') { /* don't need argument */
3119 if (!*place) ++optind;
3121 else { /* need an argument */
3122 if (*place) optarg = place; /* no white space */
3123 else if (nargc <= ++optind) { /* no arg */
3125 tell(": option requires an argument -- ");
3127 else optarg = nargv[optind]; /* white space */
3131 return optopt; /* dump back option letter */
3134 #endif /* !SM_CONF_GETOPT */
3136 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3139 ** user -- the name of the user we are checking.
3140 ** shell -- the user's shell from /etc/passwd
3143 ** true -- if it is ok to use this for unrestricted access.
3144 ** false -- if the shell is restricted.
3147 #if !HASGETUSERSHELL
3149 # ifndef _PATH_SHELLS
3150 # define _PATH_SHELLS "/etc/shells"
3153 # if defined(_AIX3) || defined(_AIX4)
3154 # include <userconf.h>
3156 # include <userpw.h>
3158 # include <usersec.h>
3159 # endif /* defined(_AIX3) || defined(_AIX4) */
3161 static char *DefaultUserShells[] =
3163 "/bin/sh", /* standard shell */
3168 "/bin/csh", /* C shell */
3173 "/usr/bin/rsh", /* restricted Bourne shell */
3174 "/usr/bin/ksh", /* Korn shell */
3175 "/usr/bin/rksh", /* restricted Korn shell */
3177 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3178 "/usr/bin/posix/sh",
3180 "/bin/rsh", /* restricted Bourne shell */
3181 "/bin/ksh", /* Korn shell */
3182 "/bin/rksh", /* restricted Korn shell */
3184 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3188 # endif /* __hpux */
3189 # if defined(_AIX3) || defined(_AIX4)
3190 "/bin/ksh", /* Korn shell */
3192 "/bin/tsh", /* trusted shell */
3194 "/bin/bsh", /* Bourne shell */
3196 # endif /* defined(_AIX3) || defined(_AIX4) */
3197 # if defined(__svr4__) || defined(__svr5__)
3198 "/bin/ksh", /* Korn shell */
3200 # endif /* defined(__svr4__) || defined(__svr5__) */
3202 "/sbin/sh", /* SGI's shells really live in /sbin */
3204 "/sbin/bsh", /* classic Bourne shell */
3207 "/sbin/csh", /* standard csh */
3210 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3213 "/bin/ksh", /* Korn shell */
3216 "/sbin/tcsh", /* Extended csh */
3223 #endif /* !HASGETUSERSHELL */
3225 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3228 usershellok(user, shell)
3234 extern char *getusershell __P((void));
3236 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3241 while ((p = getusershell()) != NULL)
3242 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
3246 #else /* HASGETUSERSHELL */
3250 register SM_FILE_T *shellf;
3253 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
3259 ** Naturally IBM has a "better" idea.....
3261 ** What a crock. This interface isn't documented, it is
3262 ** considered part of the security library (-ls), and it
3263 ** only works if you are running as root (since the list
3264 ** of valid shells is obviously a source of great concern).
3265 ** I recommend that you do NOT define USEGETCONFATTR,
3266 ** especially since you are going to have to set up an
3267 ** /etc/shells anyhow to handle the cases where getconfattr
3271 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
3275 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
3281 # endif /* USEGETCONFATTR */
3283 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
3284 SM_IO_RDONLY, NULL);
3287 /* no /etc/shells; see if it is one of the std shells */
3290 if (errno != ENOENT && LogLevel > 3)
3291 sm_syslog(LOG_ERR, NOQID,
3292 "usershellok: cannot open %s: %s",
3293 _PATH_SHELLS, sm_errstring(errno));
3295 for (d = DefaultUserShells; *d != NULL; d++)
3297 if (strcmp(shell, *d) == 0)
3303 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof(buf)) >= 0)
3305 register char *p, *q;
3308 while (*p != '\0' && *p != '#' && *p != '/')
3310 if (*p == '#' || *p == '\0')
3313 while (*p != '\0' && *p != '#' && !(SM_ISSPACE(*p)))
3316 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
3318 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3322 (void) sm_io_close(shellf, SM_TIME_DEFAULT);
3324 #endif /* HASGETUSERSHELL */
3327 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3329 ** Only implemented if you have statfs.
3332 ** dir -- the directory in question.
3333 ** bsize -- a variable into which the filesystem
3334 ** block size is stored.
3337 ** The number of blocks free on the queue filesystem.
3338 ** -1 if the statfs call fails.
3341 ** Puts the filesystem block size into bsize.
3345 #define SFS_NONE 0 /* no statfs implementation */
3346 #define SFS_USTAT 1 /* use ustat */
3347 #define SFS_4ARGS 2 /* use four-argument statfs call */
3348 #define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3349 #define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3350 #define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3351 #define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3354 # define SFS_TYPE SFS_NONE
3357 #if SFS_TYPE == SFS_USTAT
3360 #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3361 # include <sys/statfs.h>
3363 #if SFS_TYPE == SFS_VFS
3364 # include <sys/vfs.h>
3366 #if SFS_TYPE == SFS_MOUNT
3367 # include <sys/mount.h>
3369 #if SFS_TYPE == SFS_STATVFS
3370 # include <sys/statvfs.h>
3374 freediskspace(dir, bsize)
3378 #if SFS_TYPE == SFS_NONE
3382 /* assume free space is plentiful */
3383 return (long) LONG_MAX;
3384 #else /* SFS_TYPE == SFS_NONE */
3385 # if SFS_TYPE == SFS_USTAT
3387 struct stat statbuf;
3388 # define FSBLOCKSIZE DEV_BSIZE
3389 # define SFS_BAVAIL f_tfree
3390 # else /* SFS_TYPE == SFS_USTAT */
3391 # if defined(ultrix)
3393 # define SFS_BAVAIL fd_bfreen
3394 # define FSBLOCKSIZE 1024L
3395 # else /* defined(ultrix) */
3396 # if SFS_TYPE == SFS_STATVFS
3398 # define FSBLOCKSIZE fs.f_frsize
3399 # else /* SFS_TYPE == SFS_STATVFS */
3401 # define FSBLOCKSIZE fs.f_bsize
3402 # endif /* SFS_TYPE == SFS_STATVFS */
3403 # endif /* defined(ultrix) */
3404 # endif /* SFS_TYPE == SFS_USTAT */
3406 # define SFS_BAVAIL f_bavail
3409 # if SFS_TYPE == SFS_USTAT
3410 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
3411 # else /* SFS_TYPE == SFS_USTAT */
3412 # if SFS_TYPE == SFS_4ARGS
3413 if (statfs(dir, &fs, sizeof(fs), 0) == 0)
3414 # else /* SFS_TYPE == SFS_4ARGS */
3415 # if SFS_TYPE == SFS_STATVFS
3416 if (statvfs(dir, &fs) == 0)
3417 # else /* SFS_TYPE == SFS_STATVFS */
3418 # if defined(ultrix)
3419 if (statfs(dir, &fs) > 0)
3420 # else /* defined(ultrix) */
3421 if (statfs(dir, &fs) == 0)
3422 # endif /* defined(ultrix) */
3423 # endif /* SFS_TYPE == SFS_STATVFS */
3424 # endif /* SFS_TYPE == SFS_4ARGS */
3425 # endif /* SFS_TYPE == SFS_USTAT */
3428 *bsize = FSBLOCKSIZE;
3429 if (fs.SFS_BAVAIL <= 0)
3431 else if (fs.SFS_BAVAIL > LONG_MAX)
3432 return (long) LONG_MAX;
3434 return (long) fs.SFS_BAVAIL;
3437 #endif /* SFS_TYPE == SFS_NONE */
3440 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3443 ** msize -- the size to check against. If zero, we don't yet
3444 ** know how big the message will be, so just check for
3445 ** a "reasonable" amount.
3446 ** e -- envelope, or NULL -- controls logging
3449 ** true if in every queue group there is at least one
3450 ** queue directory whose file system contains enough free space.
3454 ** If there is not enough disk space and e != NULL
3455 ** then sm_syslog is called.
3459 enoughdiskspace(msize, e)
3469 if (MinBlocksFree <= 0 && msize <= 0)
3472 sm_dprintf("enoughdiskspace: no threshold\n");
3477 for (i = 0; i < NumQueue; ++i)
3479 if (pickqdir(Queue[i], msize, e) < 0)
3485 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3487 ** This looks at an errno value and tells if this is likely to
3488 ** go away if retried later.
3491 ** err -- the errno code to classify.
3494 ** true if this is probably transient.
3504 case EIO: /* I/O error */
3505 case ENXIO: /* Device not configured */
3506 case EAGAIN: /* Resource temporarily unavailable */
3507 case ENOMEM: /* Cannot allocate memory */
3508 case ENODEV: /* Operation not supported by device */
3509 case ENFILE: /* Too many open files in system */
3510 case EMFILE: /* Too many open files */
3511 case ENOSPC: /* No space left on device */
3512 case ETIMEDOUT: /* Connection timed out */
3514 case ESTALE: /* Stale NFS file handle */
3517 case ENETDOWN: /* Network is down */
3520 case ENETUNREACH: /* Network is unreachable */
3523 case ENETRESET: /* Network dropped connection on reset */
3526 case ECONNABORTED: /* Software caused connection abort */
3529 case ECONNRESET: /* Connection reset by peer */
3532 case ENOBUFS: /* No buffer space available */
3535 case ESHUTDOWN: /* Can't send after socket shutdown */
3538 case ECONNREFUSED: /* Connection refused */
3541 case EHOSTDOWN: /* Host is down */
3544 case EHOSTUNREACH: /* No route to host */
3547 case EDQUOT: /* Disc quota exceeded */
3550 case EPROCLIM: /* Too many processes */
3553 case EUSERS: /* Too many users */
3556 case EDEADLK: /* Resource deadlock avoided */
3559 case EISCONN: /* Socket already connected */
3562 case EINPROGRESS: /* Operation now in progress */
3565 case EALREADY: /* Operation already in progress */
3568 case EADDRINUSE: /* Address already in use */
3570 #ifdef EADDRNOTAVAIL
3571 case EADDRNOTAVAIL: /* Can't assign requested address */
3574 case ETXTBSY: /* (Apollo) file locked */
3576 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3577 case ENOSR: /* Out of streams resources */
3580 case ENOLCK: /* No locks available */
3582 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
3586 /* nope, must be permanent */
3590 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3593 ** fd -- the file descriptor of the file.
3594 ** filename -- the file name (for error messages).
3595 ** ext -- the filename extension.
3596 ** type -- type of the lock. Bits can be:
3597 ** LOCK_EX -- exclusive lock.
3598 ** LOCK_NB -- non-blocking.
3599 ** LOCK_UN -- unlock.
3602 ** true if the lock was acquired.
3607 lockfile(fd, filename, ext, type)
3622 (void) memset(&lfd, '\0', sizeof(lfd));
3623 if (bitset(LOCK_UN, type))
3624 lfd.l_type = F_UNLCK;
3625 else if (bitset(LOCK_EX, type))
3626 lfd.l_type = F_WRLCK;
3628 lfd.l_type = F_RDLCK;
3630 if (bitset(LOCK_NB, type))
3636 sm_dprintf("lockfile(%s%s, fd=%d, action=%s, type=%s): ",
3638 bitset(LOCK_NB, type) ? "nb" : "block",
3639 bitset(LOCK_UN, type) ? "unlock" :
3640 (bitset(LOCK_EX, type) ? "wr" : "rd"));
3641 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
3646 sm_dprintf("SUCCESS\n");
3652 sm_dprintf("(%s) ", sm_errstring(save_errno));
3655 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3656 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3657 ** as type "tmp" (that is, served from swap space), the
3658 ** previous fcntl will fail with "Invalid argument" errors.
3659 ** Since this is fairly common during testing, we will assume
3660 ** that this indicates that the lock is successfully grabbed.
3663 if (save_errno == EINVAL)
3666 sm_dprintf("SUCCESS\n");
3670 if (!bitset(LOCK_NB, type) ||
3671 (save_errno != EACCES && save_errno != EAGAIN))
3673 int omode = fcntl(fd, F_GETFL, 0);
3674 uid_t euid = geteuid();
3677 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%ld)",
3678 filename, ext, fd, type, omode, (long) euid);
3679 dumpfd(fd, true, true);
3681 #else /* !HASFLOCK */
3686 sm_dprintf("lockfile(%s%s, fd=%d, type=%s): ", filename, ext,
3687 fd, bitset(LOCK_UN, type) ? "unlock" :
3688 (bitset(LOCK_EX, type) ? "wr" : "rd"));
3690 while ((i = flock(fd, type)) < 0 && errno == EINTR)
3695 sm_dprintf("SUCCESS\n");
3701 sm_dprintf("(%s) ", sm_errstring(save_errno));
3703 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
3705 int omode = fcntl(fd, F_GETFL, 0);
3706 uid_t euid = geteuid();
3709 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%ld)",
3710 filename, ext, fd, type, omode, (long) euid);
3711 dumpfd(fd, true, true);
3713 #endif /* !HASFLOCK */
3715 sm_dprintf("FAIL\n");
3720 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3722 ** Unfortunately, given that we can't predict other systems on which
3723 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3724 ** almost always that this is unsafe.
3726 ** Note also that many operating systems have non-compliant
3727 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3728 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3729 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3730 ** no non-root process can give away the file. However, vendors
3731 ** don't take NFS into account, so a comfortable value of
3732 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3734 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3735 ** even on files where chown is not restricted. Many systems get
3736 ** this wrong on NFS-based filesystems (that is, they say that chown
3737 ** is restricted [safe] on NFS filesystems where it may not be, since
3738 ** other systems can access the same filesystem and do file giveaway;
3739 ** only the NFS server knows for sure!) Hence, it is important to
3740 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3741 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3742 ** NFS-based filesystem to ensure that you can get meaningful results.
3743 ** If in doubt, assume unsafe!
3745 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3746 ** condition indicating whether the return from pathconf indicates
3747 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3748 ** even any agreement about whether a zero return means that a file
3749 ** is or is not safe). It defaults to "> 0".
3751 ** If the parent directory is safe (writable only by owner back
3752 ** to the root) then we can relax slightly and trust fpathconf
3753 ** in more circumstances. This is really a crock -- if this is an
3754 ** NFS mounted filesystem then we really know nothing about the
3755 ** underlying implementation. However, most systems pessimize and
3756 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3757 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3758 ** us into a possible problem only on systems that have a broken
3759 ** pathconf implementation and which are also poorly configured
3760 ** (have :include: files in group- or world-writable directories).
3763 ** fd -- the file descriptor to check.
3764 ** safedir -- set if the parent directory is safe.
3767 ** true -- if the chown(2) operation is "safe" -- that is,
3768 ** only root can chown the file to an arbitrary user.
3769 ** false -- if an arbitrary user can give away a file.
3772 #ifndef IS_SAFE_CHOWN
3773 # define IS_SAFE_CHOWN > 0
3777 chownsafe(fd, safedir)
3781 #if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3782 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3785 /* give the system administrator a chance to override */
3786 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
3790 ** Some systems (e.g., SunOS) seem to have the call and the
3791 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3792 ** the call. This heuristic checks for that.
3796 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
3797 # if SAFENFSPATHCONF
3798 return errno == 0 && rval IS_SAFE_CHOWN;
3800 return safedir && errno == 0 && rval IS_SAFE_CHOWN;
3802 #else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3803 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
3804 #endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3807 ** RESETLIMITS -- reset system controlled resource limits
3809 ** This is to avoid denial-of-service attacks
3819 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3820 # include <sm/time.h>
3822 # include <sys/resource.h>
3823 #endif /* HASSETRLIMIT */
3831 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
3832 (void) setrlimit(RLIMIT_CPU, &lim);
3833 (void) setrlimit(RLIMIT_FSIZE, &lim);
3834 # ifdef RLIMIT_NOFILE
3835 lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
3836 (void) setrlimit(RLIMIT_NOFILE, &lim);
3838 #else /* HASSETRLIMIT */
3840 (void) ulimit(2, 0x3fffff);
3841 (void) ulimit(4, FD_SETSIZE);
3843 #endif /* HASSETRLIMIT */
3847 ** SETVENDOR -- process vendor code from V configuration line
3850 ** vendor -- string representation of vendor.
3854 ** false -- if vendor code could not be processed.
3857 ** It is reasonable to set mode flags here to tweak
3858 ** processing in other parts of the code if necessary.
3859 ** For example, if you are a vendor that uses $%y to
3860 ** indicate YP lookups, you could enable that here.
3867 if (SM_STRCASEEQ(vendor, "Berkeley"))
3869 VendorCode = VENDOR_BERKELEY;
3873 /* add vendor extensions here */
3875 #ifdef SUN_EXTENSIONS
3876 if (SM_STRCASEEQ(vendor, "Sun"))
3878 VendorCode = VENDOR_SUN;
3881 #endif /* SUN_EXTENSIONS */
3883 if (SM_STRCASEEQ(vendor, "Digital"))
3885 VendorCode = VENDOR_DEC;
3890 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3891 if (SM_STRCASEEQ(vendor, VENDOR_NAME))
3893 VendorCode = VENDOR_CODE;
3896 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3901 ** GETVENDOR -- return vendor name based on vendor code
3904 ** vendorcode -- numeric representation of vendor.
3907 ** string containing vendor name.
3911 getvendor(vendorcode)
3914 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3916 ** Can't have the same switch case twice so need to
3917 ** handle VENDOR_CODE outside of switch. It might
3918 ** match one of the existing VENDOR_* codes.
3921 if (vendorcode == VENDOR_CODE)
3923 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3927 case VENDOR_BERKELEY:
3939 case VENDOR_SENDMAIL:
3947 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3949 ** Vendor_pre_defaults is called before reading the configuration
3950 ** file; vendor_post_defaults is called immediately after.
3953 ** e -- the global environment to initialize.
3960 int DefShareUid; /* default share uid to run as -- unused??? */
3964 vendor_pre_defaults(e)
3968 /* OTHERUID is defined in shares.h, do not be alarmed */
3969 DefShareUid = OTHERUID;
3971 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3972 sun_pre_defaults(e);
3976 ** stupid domain/os can't even open
3977 ** /etc/mail/sendmail.cf without this
3980 sm_setuserenv("ISP", NULL);
3981 sm_setuserenv("SYSTYPE", NULL);
3986 vendor_post_defaults(e)
3990 /* Makes sure the SOCK environment variable remains */
3991 sm_setuserenv("SOCK", NULL);
3993 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3994 sun_post_defaults(e);
3998 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
4002 vendor_daemon_setup(e)
4006 (void) setlogin(RunAsUserName);
4009 if (getluid() != -1)
4011 usrerr("Daemon cannot have LUID");
4012 finis(false, true, EX_USAGE);
4014 #endif /* SECUREWARE */
4017 ** VENDOR_SET_UID -- do setup for setting a user id
4019 ** This is called when we are still root.
4022 ** uid -- the uid we are about to become.
4033 ** We need to setup the share groups (lnodes)
4034 ** and add auditing information (luid's)
4035 ** before we loose our ``root''ness.
4038 if (setupshares(uid, syserr) != 0)
4039 syserr("Unable to set up shares");
4042 (void) setup_secure(uid);
4046 ** VALIDATE_CONNECTION -- check connection for rationality
4048 ** If the connection is rejected, this routine should log an
4049 ** appropriate message -- but should never issue any SMTP protocol.
4052 ** sap -- a pointer to a SOCKADDR naming the peer.
4053 ** hostname -- the name corresponding to sap.
4054 ** e -- the current envelope.
4057 ** error message from rejection.
4058 ** NULL if not rejected.
4064 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
4065 int allow_severity = LOG_INFO;
4066 int deny_severity = LOG_NOTICE;
4067 #endif /* TCPWRAPPERS */
4070 validate_connection(sap, hostname, e)
4078 extern int hosts_ctl();
4079 #endif /* TCPWRAPPERS */
4082 sm_dprintf("validate_connection(%s, %s)\n",
4083 hostname, anynet_ntoa(sap));
4085 connection_rate_check(sap, e);
4086 if (rscheck("check_relay", hostname, anynet_ntoa(sap), e,
4087 RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID, NULL, NULL) != EX_OK)
4089 static char reject[BUFSIZ*2];
4090 extern char MsgBuf[];
4093 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
4095 if (strlen(MsgBuf) >= 3)
4096 (void) sm_strlcpy(reject, MsgBuf, sizeof(reject));
4098 (void) sm_strlcpy(reject, "Access denied", sizeof(reject));
4104 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
4108 addr = anynet_ntoa(sap);
4111 /* TCP/Wrappers don't want the IPv6: protocol label */
4112 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
4114 # endif /* NETINET6 */
4116 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
4119 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4121 sm_syslog(LOG_NOTICE, e->e_id,
4122 "tcpwrappers (%s, %s) rejection",
4124 return "Access denied";
4126 #endif /* TCPWRAPPERS */
4128 sm_dprintf(" ... validate_connection: OK\n");
4133 ** STRTOL -- convert string to long integer
4135 ** For systems that don't have it in the C library.
4137 ** This is taken verbatim from the 4.4-Lite C library.
4142 # if defined(LIBC_SCCS) && !defined(lint)
4143 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4147 ** Convert a string to a long integer.
4149 ** Ignores `locale' stuff. Assumes that the upper and lower case
4150 ** alphabets and digits are each contiguous.
4154 strtol(nptr, endptr, base)
4159 register const char *s = nptr;
4160 register unsigned long acc;
4162 register unsigned long cutoff;
4163 register int neg = 0, any, cutlim;
4166 ** Skip white space and pick up leading +/- sign if any.
4167 ** If base is 0, allow 0x for hex and 0 for octal, else
4168 ** assume decimal; if base is already 16, allow 0x.
4172 } while (SM_ISSPACE(c));
4176 } else if (c == '+')
4178 if ((base == 0 || base == 16) &&
4179 c == '0' && (*s == 'x' || *s == 'X')) {
4185 base = c == '0' ? 8 : 10;
4188 ** Compute the cutoff value between legal numbers and illegal
4189 ** numbers. That is the largest legal value, divided by the
4190 ** base. An input number that is greater than this value, if
4191 ** followed by a legal input character, is too big. One that
4192 ** is equal to this value may be valid or not; the limit
4193 ** between valid and invalid numbers is then based on the last
4194 ** digit. For instance, if the range for longs is
4195 ** [-2147483648..2147483647] and the input base is 10,
4196 ** cutoff will be set to 214748364 and cutlim to either
4197 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4198 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4199 ** the number is too big, and we will return a range error.
4201 ** Set any if any `digits' consumed; make it negative to indicate
4204 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
4205 cutlim = cutoff % (unsigned long) base;
4206 cutoff /= (unsigned long) base;
4207 for (acc = 0, any = 0;; c = *s++) {
4208 if (isascii(c) && isdigit(c))
4210 else if (isascii(c) && isalpha(c))
4211 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
4216 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
4225 acc = neg ? LONG_MIN : LONG_MAX;
4230 *endptr = (char *)(any ? s - 1 : nptr);
4234 #endif /* NEEDSTRTOL */
4236 ** STRSTR -- find first substring in string
4239 ** big -- the big (full) string.
4240 ** little -- the little (sub) string.
4243 ** A pointer to the first instance of little in big.
4244 ** big if little is the null string.
4245 ** NULL if little is not contained in big.
4255 register char *p = big;
4258 if (*little == '\0')
4262 while ((p = strchr(p, *little)) != NULL)
4264 if (strncmp(p, little, l) == 0)
4271 #endif /* NEEDSTRSTR */
4273 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4275 ** Some operating systems have weird problems with the gethostbyXXX
4276 ** routines. For example, Solaris versions at least through 2.3
4277 ** don't properly deliver a canonical h_name field. This tries to
4278 ** work around these problems.
4280 ** Support IPv6 as well as IPv4.
4283 #if NETINET6 && NEEDSGETIPNODE
4286 # define AI_DEFAULT 0 /* dummy */
4288 # ifndef AI_ADDRCONFIG
4289 # define AI_ADDRCONFIG 0 /* dummy */
4291 # ifndef AI_V4MAPPED
4292 # define AI_V4MAPPED 0 /* dummy */
4295 # define AI_ALL 0 /* dummy */
4298 static struct hostent *
4299 sm_getipnodebyname(name, family, flags, err)
4306 # if HAS_GETHOSTBYNAME2
4308 h = gethostbyname2(name, family);
4313 # else /* HAS_GETHOSTBYNAME2 */
4314 # ifdef RES_USE_INET6
4317 if (family == AF_INET6)
4319 /* From RFC2133, section 6.1 */
4320 resv6 = bitset(RES_USE_INET6, _res.options);
4321 _res.options |= RES_USE_INET6;
4323 # endif /* RES_USE_INET6 */
4325 h = gethostbyname(name);
4326 # ifdef RES_USE_INET6
4328 _res.options &= ~RES_USE_INET6;
4331 /* the function is supposed to return only the requested family */
4332 if (h != NULL && h->h_addrtype != family)
4343 # endif /* HAS_GETHOSTBYNAME2 */
4346 static struct hostent *
4347 sm_getipnodebyaddr(addr, len, family, err)
4356 h = gethostbyaddr(addr, len, family);
4366 ** Stub routine -- if they don't have getipnodeby*(),
4367 ** they probably don't have the free routine either.
4372 #endif /* NETINET6 && NEEDSGETIPNODE */
4375 sm_gethostbyname(name, family)
4380 struct hostent *h = NULL;
4381 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4382 # if SOLARIS == 20300 || SOLARIS == 203
4383 static struct hostent hp;
4384 static char buf[1000];
4385 extern struct hostent *_switch_gethostbyname_r();
4388 sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
4389 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
4391 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4392 extern struct hostent *__switch_gethostbyname();
4395 sm_dprintf("__switch_gethostbyname(%s)... ", name);
4396 h = __switch_gethostbyname(name);
4398 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4399 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4402 # ifndef SM_IPNODEBYNAME_FLAGS
4403 /* For IPv4-mapped addresses, use: AI_DEFAULT|AI_ALL */
4404 # define SM_IPNODEBYNAME_FLAGS AI_ADDRCONFIG
4407 int flags = SM_IPNODEBYNAME_FLAGS;
4409 # endif /* NETINET6 */
4410 char *maptype[MAXMAPSTACK];
4411 short mapreturn[MAXMAPACTIONS];
4412 char hbuf[MAXNAME_I];
4413 # if _FFR_8BITENVADDR
4414 (void) dequote_internal_chars(name, hbuf, sizeof(hbuf));
4418 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
4421 # if ADDRCONFIG_IS_BROKEN
4422 flags &= ~AI_ADDRCONFIG;
4424 h = sm_getipnodebyname(name, family, flags, &err);
4425 SM_SET_H_ERRNO(err);
4426 # else /* NETINET6 */
4427 h = gethostbyname(name);
4428 # endif /* NETINET6 */
4434 sm_dprintf("failure: errno=%d, h_errno=%d\n",
4437 nmaps = switch_map_find("hosts", maptype, mapreturn);
4438 while (--nmaps >= 0)
4440 if (strcmp(maptype[nmaps], "nis") == 0 ||
4441 strcmp(maptype[nmaps], "files") == 0)
4447 /* try short name */
4448 if (strlen(name) > sizeof(hbuf) - 1)
4453 (void) sm_strlcpy(hbuf, name, sizeof(hbuf));
4454 (void) shorten_hostname(hbuf);
4456 /* if it hasn't been shortened, there's no point */
4457 if (strcmp(hbuf, name) != 0)
4460 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4464 h = sm_getipnodebyname(hbuf, family, flags, &err);
4465 SM_SET_H_ERRNO(err);
4467 # else /* NETINET6 */
4468 h = gethostbyname(hbuf);
4470 # endif /* NETINET6 */
4474 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4476 /* the function is supposed to return only the requested family */
4477 if (h != NULL && h->h_addrtype != family)
4483 SM_SET_H_ERRNO(NO_DATA);
4489 sm_dprintf("failure: errno=%d, h_errno=%d\n",
4493 sm_dprintf("%s\n", h->h_name);
4499 struct in6_addr ia6;
4500 char buf6[INET6_ADDRSTRLEN];
4503 if (h->h_aliases != NULL)
4504 for (i = 0; h->h_aliases[i] != NULL;
4506 sm_dprintf("\talias: %s\n",
4508 for (i = 0; h->h_addr_list[i] != NULL; i++)
4514 if (h->h_addrtype == AF_INET6)
4516 memmove(&ia6, h->h_addr_list[i],
4518 addr = anynet_ntop(&ia6,
4519 buf6, sizeof(buf6));
4522 #endif /* NETINET6 */
4523 /* "else" in #if code above */
4525 memmove(&ia, h->h_addr_list[i],
4527 addr = (char *) inet_ntoa(ia);
4530 sm_dprintf("\taddr: %s\n", addr);
4540 sm_gethostbyaddr(addr, len, type)
4548 if (type == AF_INET6 &&
4549 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
4551 /* Avoid reverse lookup for IPv6 unspecified address */
4552 SM_SET_H_ERRNO(HOST_NOT_FOUND);
4555 #endif /* NETINET6 */
4557 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4558 # if SOLARIS == 20300 || SOLARIS == 203
4560 static struct hostent he;
4561 static char buf[1000];
4562 extern struct hostent *_switch_gethostbyaddr_r();
4564 hp = _switch_gethostbyaddr_r(addr, len, type, &he,
4565 buf, sizeof(buf), &h_errno);
4567 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4569 extern struct hostent *__switch_gethostbyaddr();
4571 hp = __switch_gethostbyaddr(addr, len, type);
4573 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4574 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4579 hp = sm_getipnodebyaddr(addr, len, type, &err);
4580 SM_SET_H_ERRNO(err);
4582 # else /* NETINET6 */
4583 hp = gethostbyaddr(addr, len, type);
4584 # endif /* NETINET6 */
4585 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4589 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4597 extern struct passwd *_getpwnam_shadow(const char *, const int);
4599 return _getpwnam_shadow(user, 0);
4601 return getpwnam(user);
4609 #if defined(_AIX4) && 0
4610 extern struct passwd *_getpwuid_shadow(const int, const int);
4612 return _getpwuid_shadow(uid,0);
4613 #else /* defined(_AIX4) && 0 */
4614 return getpwuid(uid);
4615 #endif /* defined(_AIX4) && 0 */
4618 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4620 ** Set up the trusted computing environment for C2 level security
4621 ** under SecureWare.
4624 ** uid -- uid of the user to initialize in the TCB
4630 ** Initialized the user in the trusted computing base
4635 # include <sys/security.h>
4639 secureware_setup_secure(uid)
4644 if (getluid() != -1)
4647 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
4651 case SSI_NO_PRPW_ENTRY:
4652 syserr("No protected passwd entry, uid = %d",
4657 syserr("Account has been disabled, uid = %d",
4662 syserr("Account has been retired, uid = %d",
4666 case SSI_BAD_SET_LUID:
4667 syserr("Could not set LUID, uid = %d", (int) uid);
4670 case SSI_BAD_SET_PRIVS:
4671 syserr("Could not set kernel privs, uid = %d",
4675 syserr("Unknown return code (%d) from set_secure_info(%d)",
4679 finis(false, true, EX_NOPERM);
4682 #endif /* SECUREWARE */
4684 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4686 ** Add hostnames to class 'w' based on the IP address read from
4687 ** the network interface.
4690 ** sa -- a pointer to a SOCKADDR containing the address
4693 ** 0 if successful, -1 if host lookup fails.
4702 char hnb[MAXHOSTNAMELEN];
4704 /* look up name with IP address */
4705 switch (sa->sa.sa_family)
4709 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
4710 sizeof(sa->sin.sin_addr),
4713 #endif /* NETINET */
4717 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
4718 sizeof(sa->sin6.sin6_addr),
4721 #endif /* NETINET6 */
4724 /* Give warning about unsupported family */
4726 sm_syslog(LOG_WARNING, NOQID,
4727 "Unsupported address family %d: %.100s",
4728 sa->sa.sa_family, anynet_ntoa(sa));
4734 int save_errno = errno;
4737 #if NETINET && defined(IN_LINKLOCAL)
4738 !(sa->sa.sa_family == AF_INET &&
4739 IN_LINKLOCAL(ntohl(sa->sin.sin_addr.s_addr))) &&
4742 !(sa->sa.sa_family == AF_INET6 &&
4743 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
4746 sm_syslog(LOG_WARNING, NOQID,
4747 "gethostbyaddr(%.100s) failed: %d",
4759 /* save its cname */
4760 if (!wordinclass((char *) hp->h_name, 'w'))
4762 setclass('w', (char *) hp->h_name);
4764 sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
4766 if (sm_snprintf(hnb, sizeof(hnb), "[%s]", hp->h_name) <
4768 && !wordinclass((char *) hnb, 'w'))
4774 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
4777 /* save all it aliases name */
4778 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
4780 if (!wordinclass(*ha, 'w'))
4784 sm_dprintf("\ta.k.a.: %s\n", *ha);
4785 if (sm_snprintf(hnb, sizeof(hnb),
4786 "[%s]", *ha) < sizeof(hnb) &&
4787 !wordinclass((char *) hnb, 'w'))
4793 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4803 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4812 ** Loads $=w with the names of all the interfaces.
4816 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4819 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4823 # include <sm/time.h>
4825 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4828 # include <net/if.h>
4829 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4834 #if NETINET6 && defined(SIOCGLIFCONF)
4838 ** Unfortunately, HP has changed all of the structures,
4839 ** making life difficult for implementors.
4842 # define lifconf if_laddrconf
4843 # define lifc_len iflc_len
4844 # define lifc_buf iflc_buf
4845 # define lifreq if_laddrreq
4846 # define lifr_addr iflr_addr
4847 # define lifr_name iflr_name
4848 # define lifr_flags iflr_flags
4849 # define ss_family sa_family
4851 # endif /* __hpux */
4858 struct lifconf lifc;
4863 s = socket(InetMode, SOCK_DGRAM, 0);
4867 /* get the list of known IP address from the kernel */
4869 i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
4872 lifn.lifn_family = AF_UNSPEC;
4873 lifn.lifn_flags = 0;
4874 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
4875 numifs = lifn.lifn_count;
4876 # endif /* SIOCGLIFNUM */
4878 # if defined(__hpux) || defined(SIOCGLIFNUM)
4881 /* can't get number of interfaces -- fall back */
4883 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4884 sm_errstring(errno));
4887 else if (tTd(0, 42))
4888 sm_dprintf("system has %d interfaces\n", numifs);
4890 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4891 numifs = MAXINTERFACES;
4899 len = lifc.lifc_len = numifs * sizeof(struct lifreq);
4900 buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
4902 lifc.lifc_family = AF_UNSPEC;
4903 lifc.lifc_flags = 0;
4905 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
4908 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4909 sm_errstring(errno));
4915 /* scan the list of IP address */
4917 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4920 for (i = 0; i < len && i >= 0; )
4923 struct lifreq *ifr = (struct lifreq *)&buf[i];
4924 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
4925 int af = ifr->lifr_addr.ss_family;
4928 struct in6_addr ia6;
4930 # ifdef SIOCGLIFFLAGS
4934 char buf6[INET6_ADDRSTRLEN];
4937 ** We must close and recreate the socket each time
4938 ** since we don't know what type of socket it is now
4939 ** (each status function may change it).
4944 s = socket(af, SOCK_DGRAM, 0);
4947 sm_free(buf); /* XXX */
4952 ** If we don't have a complete ifr structure,
4953 ** don't try to use it.
4956 if ((len - i) < sizeof(*ifr))
4959 # ifdef BSD4_4_SOCKADDR
4960 if (sa->sa.sa_len > sizeof(ifr->lifr_addr))
4961 i += sizeof(ifr->lifr_name) + sa->sa.sa_len;
4963 # endif /* BSD4_4_SOCKADDR */
4964 /* "else" in #if code above */
4967 /* fix for IPv6 size differences */
4968 i += sizeof(ifr->ifr_name) +
4969 max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
4976 sm_dprintf("%s\n", anynet_ntoa(sa));
4978 if (af != AF_INET && af != AF_INET6)
4981 # ifdef SIOCGLIFFLAGS
4982 memset(&ifrf, '\0', sizeof(struct lifreq));
4983 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
4984 sizeof(ifrf.lifr_name));
4985 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
4988 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4989 sm_errstring(errno));
4993 name = ifr->lifr_name;
4994 flags = ifrf.lifr_flags;
4997 sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
4999 if (!bitset(IFF_UP, flags))
5001 # endif /* SIOCGLIFFLAGS */
5005 /* extract IP address from the list*/
5009 SETV6LOOPBACKADDRFOUND(*sa);
5011 /* convert into proper scoped address */
5012 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5013 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5014 sa->sin6.sin6_scope_id == 0)
5016 struct in6_addr *ia6p;
5018 ia6p = &sa->sin6.sin6_addr;
5019 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5020 ((unsigned int)ia6p->s6_addr[2] << 8));
5021 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5023 # endif /* __KAME__ */
5024 ia6 = sa->sin6.sin6_addr;
5025 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5027 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5028 message("WARNING: interface %s is UP with %s address",
5029 name, addr == NULL ? "(NULL)" : addr);
5033 /* save IP address in text from */
5034 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5036 (void) sm_snprintf(ip_addr, sizeof(ip_addr),
5038 (int) sizeof(ip_addr) - 3,
5043 ia = sa->sin.sin_addr;
5044 if (ia.s_addr == INADDR_ANY ||
5045 ia.s_addr == INADDR_NONE)
5047 message("WARNING: interface %s is UP with %s address",
5048 name, inet_ntoa(ia));
5052 /* save IP address in text from */
5053 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
5054 (int) sizeof(ip_addr) - 3, inet_ntoa(ia));
5058 if (*ip_addr == '\0')
5061 if (!wordinclass(ip_addr, 'w'))
5063 setclass('w', ip_addr);
5065 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5068 # ifdef SIOCGLIFFLAGS
5069 /* skip "loopback" interface "lo" */
5070 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5071 bitset(IFF_LOOPBACK, flags))
5073 # endif /* SIOCGLIFFLAGS */
5074 (void) add_hostnames(sa);
5076 sm_free(buf); /* XXX */
5078 #else /* NETINET6 && defined(SIOCGLIFCONF) */
5079 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
5085 s = socket(AF_INET, SOCK_DGRAM, 0);
5089 /* get the list of known IP address from the kernel */
5090 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
5091 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
5093 /* can't get number of interfaces -- fall back */
5095 sm_dprintf("SIOCGIFNUM failed: %s\n",
5096 sm_errstring(errno));
5099 else if (tTd(0, 42))
5100 sm_dprintf("system has %d interfaces\n", numifs);
5102 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
5103 numifs = MAXINTERFACES;
5110 ifc.ifc_len = numifs * sizeof(struct ifreq);
5111 ifc.ifc_buf = xalloc(ifc.ifc_len);
5112 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
5115 sm_dprintf("SIOCGIFCONF failed: %s\n",
5116 sm_errstring(errno));
5121 /* scan the list of IP address */
5123 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
5126 for (i = 0; i < ifc.ifc_len && i >= 0; )
5129 # if HAVE_IFC_BUF_VOID
5130 struct ifreq *ifr = (struct ifreq *) &((char *)ifc.ifc_buf)[i];
5132 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
5134 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
5137 struct in6_addr ia6;
5140 # ifdef SIOCGIFFLAGS
5145 char buf6[INET6_ADDRSTRLEN];
5149 ** If we don't have a complete ifr structure,
5150 ** don't try to use it.
5153 if ((ifc.ifc_len - i) < sizeof(*ifr))
5156 # ifdef BSD4_4_SOCKADDR
5157 if (sa->sa.sa_len > sizeof(ifr->ifr_addr))
5158 i += sizeof(ifr->ifr_name) + sa->sa.sa_len;
5160 # endif /* BSD4_4_SOCKADDR */
5161 /* "else" in #if code above */
5167 sm_dprintf("%s\n", anynet_ntoa(sa));
5169 af = ifr->ifr_addr.sa_family;
5177 # ifdef SIOCGIFFLAGS
5178 memset(&ifrf, '\0', sizeof(struct ifreq));
5179 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
5180 sizeof(ifrf.ifr_name));
5181 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
5183 sm_dprintf("\tflags: %lx\n",
5184 (unsigned long) ifrf.ifr_flags);
5185 # define IFRFREF ifrf
5186 # else /* SIOCGIFFLAGS */
5187 # define IFRFREF (*ifr)
5188 # endif /* SIOCGIFFLAGS */
5190 if (!bitset(IFF_UP, IFRFREF.ifr_flags))
5195 /* extract IP address from the list*/
5199 ia = sa->sin.sin_addr;
5200 if (ia.s_addr == INADDR_ANY ||
5201 ia.s_addr == INADDR_NONE)
5203 message("WARNING: interface %s is UP with %s address",
5204 ifr->ifr_name, inet_ntoa(ia));
5208 /* save IP address in text from */
5209 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
5210 (int) sizeof(ip_addr) - 3,
5216 SETV6LOOPBACKADDRFOUND(*sa);
5218 /* convert into proper scoped address */
5219 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
5220 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
5221 sa->sin6.sin6_scope_id == 0)
5223 struct in6_addr *ia6p;
5225 ia6p = &sa->sin6.sin6_addr;
5226 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
5227 ((unsigned int)ia6p->s6_addr[2] << 8));
5228 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
5230 # endif /* __KAME__ */
5231 ia6 = sa->sin6.sin6_addr;
5232 if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
5234 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5235 message("WARNING: interface %s is UP with %s address",
5237 addr == NULL ? "(NULL)" : addr);
5241 /* save IP address in text from */
5242 addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
5244 (void) sm_snprintf(ip_addr, sizeof(ip_addr),
5246 (int) sizeof(ip_addr) - 3,
5250 # endif /* NETINET6 */
5253 if (ip_addr[0] == '\0')
5256 if (!wordinclass(ip_addr, 'w'))
5258 setclass('w', ip_addr);
5260 sm_dprintf("\ta.k.a.: %s\n", ip_addr);
5263 /* skip "loopback" interface "lo" */
5264 if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
5265 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
5268 (void) add_hostnames(sa);
5270 sm_free(ifc.ifc_buf); /* XXX */
5273 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5274 #endif /* NETINET6 && defined(SIOCGLIFCONF) */
5277 ** ISLOOPBACK -- is socket address in the loopback net?
5280 ** sa -- socket address.
5283 ** true -- is socket address in the loopback net?
5284 ** false -- otherwise
5292 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5294 # define SM_IS_IPV4_LOOP(a) IN_LOOPBACK(ntohl(a))
5295 #else /* IN_LOOPBACK */
5296 # define SM_IS_IPV4_LOOP(a) (((ntohl(a) & IN_CLASSA_NET) \
5297 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
5298 # endif /* IN_LOOPBACK */
5300 if (sa.sa.sa_family == AF_INET6 &&
5301 IN6_IS_ADDR_V4MAPPED(&sa.sin6.sin6_addr) &&
5302 SM_IS_IPV4_LOOP(((uint32_t *) (&sa.sin6.sin6_addr))[3]))
5304 if (sa.sa.sa_family == AF_INET6 &&
5305 IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
5309 if (sa.sa.sa_family == AF_INET &&
5310 SM_IS_IPV4_LOOP(sa.sin.sin_addr.s_addr))
5317 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5323 ** The number of processors online.
5327 get_num_procs_online()
5332 # if defined(CTL_HW) && defined(HW_NCPU)
5338 sz = (size_t) sizeof(nproc);
5339 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
5340 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5341 #else /* USESYSCTL */
5342 # ifdef _SC_NPROCESSORS_ONLN
5343 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
5344 # else /* _SC_NPROCESSORS_ONLN */
5346 # include <sys/pstat.h>
5347 struct pst_dynamic psd;
5349 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
5350 nproc = psd.psd_proc_cnt;
5351 # endif /* __hpux */
5352 # endif /* _SC_NPROCESSORS_ONLN */
5353 #endif /* USESYSCTL */
5360 ** SM_CLOSEFROM -- close file descriptors
5363 ** lowest -- first fd to close
5364 ** highest -- last fd + 1 to close
5371 sm_closefrom(lowest, highest)
5372 int lowest, highest;
5376 #else /* HASCLOSEFROM */
5379 for (i = lowest; i < highest; i++)
5381 #endif /* HASCLOSEFROM */
5385 ** CLOSEFD_WALK -- walk fd's arranging to close them
5386 ** Callback for fdwalk()
5389 ** lowest -- first fd to arrange to be closed
5390 ** fd -- fd to arrange to be closed
5397 closefd_walk(lowest, fd)
5401 if (fd >= *(int *)lowest)
5402 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
5405 #endif /* HASFDWALK */
5407 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5410 ** lowest -- first fd to arrange to be closed
5411 ** highest -- last fd + 1 to arrange to be closed
5418 sm_close_on_exec(lowest, highest)
5419 int lowest, highest;
5422 (void) fdwalk(closefd_walk, &lowest);
5423 #else /* HASFDWALK */
5426 for (i = lowest; i < highest; i++)
5428 if ((j = fcntl(i, F_GETFD, 0)) != -1)
5429 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
5431 #endif /* HASFDWALK */
5434 ** SEED_RANDOM -- seed the random number generator
5448 #else /* HASSRANDOMDEV */
5452 seed = (long) CurrentPid;
5453 if (gettimeofday(&t, NULL) >= 0)
5454 seed += t.tv_sec + t.tv_usec;
5457 (void) srandom(seed);
5459 (void) srand((unsigned int) seed);
5461 #endif /* HASSRANDOMDEV */
5464 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5467 ** level -- syslog level
5468 ** id -- envelope ID or NULL (NOQUEUE)
5469 ** fmt -- format string
5470 ** arg... -- arguments as implied by fmt.
5479 sm_syslog(int level, const char *id, const char *fmt, ...)
5480 #else /* __STDC__ */
5481 sm_syslog(level, id, fmt, va_alist)
5486 #endif /* __STDC__ */
5496 extern int SyslogPrefixLen;
5502 idlen = strlen(id) + SyslogPrefixLen;
5505 bufsize = sizeof(buf0);
5511 /* print log message into buf */
5512 SM_VA_START(ap, fmt);
5513 n = sm_vsnprintf(buf, bufsize, fmt, ap);
5519 /* String too small, redo with correct size */
5526 buf = sm_malloc_x(bufsize);
5529 /* clean up buf after it has been expanded with args */
5530 #if _FFR_LOGASIS >= 5
5531 /* for testing! maybe make it an -d option (hence runtime)? */
5534 newstring = str2prt(buf);
5536 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
5545 gettimeofday(&tv, NULL);
5546 sm_dprintf("%ld.%06ld %s\n", (long) tv.tv_sec,
5547 (long) tv.tv_usec, newstring);
5549 else if (tTd(89, 8))
5550 sm_dprintf("%s\n", newstring);
5552 syslog(level, "%s", newstring);
5560 gettimeofday(&tv, NULL);
5561 sm_dprintf("%ld.%06ld %s: %s\n", (long) tv.tv_sec,
5562 (long) tv.tv_usec, id, newstring);
5564 else if (tTd(89, 8))
5565 sm_dprintf("%s: %s\n", id, newstring);
5567 syslog(level, "%s: %s", id, newstring);
5570 /*XXX should do something more sensible */
5572 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
5575 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5576 "%s: %s\n", id, newstring);
5585 ** additional length for splitting: " ..." + 3, where 3 is magic to
5586 ** have some data for the next entry.
5592 idlen += 5; /* strlen("[999]"), see below */
5593 while (*begin != '\0' &&
5594 (strlen(begin) + idlen) > SYSLOG_BUFSIZE)
5600 /* Too many messages */
5603 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5606 /* Break on comma or space */
5607 if (*end == ',' || *end == ' ')
5609 end++; /* Include separator */
5614 /* No separator, break midstring... */
5616 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
5621 sm_dprintf("%s[%d]: %s ...\n", id, seq++, begin);
5623 syslog(level, "%s[%d]: %s ...", id, seq++, begin);
5625 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5626 "%s[%d]: %s ...\n", id, seq++, begin);
5635 sm_dprintf("%s[%d]: log terminated, too many parts\n",
5638 syslog(level, "%s[%d]: log terminated, too many parts",
5641 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5642 "%s[%d]: log terminated, too many parts\n", id, seq);
5645 else if (*begin != '\0')
5649 sm_dprintf("%s[%d]: %s\n", id, seq, begin);
5651 syslog(level, "%s[%d]: %s", id, seq, begin);
5653 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
5654 "%s[%d]: %s\n", id, seq, begin);
5662 ** HARD_SYSLOG -- call syslog repeatedly until it works
5664 ** Needed on HP-UX, which apparently doesn't guarantee that
5665 ** syslog succeeds during interrupt handlers.
5668 #if defined(__hpux) && !defined(HPUX11)
5670 # define MAXSYSLOGTRIES 100
5673 # define XCNST const
5674 # define CAST (const char *)
5682 hard_syslog(int pri, XCNST char *msg, ...)
5683 # else /* __STDC__ */
5684 hard_syslog(pri, msg, va_alist)
5688 # endif /* __STDC__ */
5691 char buf[SYSLOG_BUFSIZE];
5694 SM_VA_START(ap, msg);
5695 (void) sm_vsnprintf(buf, sizeof(buf), msg, ap);
5698 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
5703 #endif /* defined(__hpux) && !defined(HPUX11) */
5704 #if NEEDLOCAL_HOSTNAME_LENGTH
5706 ** LOCAL_HOSTNAME_LENGTH
5708 ** This is required to get sendmail to compile against BIND 4.9.x
5711 ** Unfortunately, a Compaq Y2K patch kit provides it without
5712 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5713 ** figure out whether it is needed.
5717 local_hostname_length(hostname)
5720 size_t len_host, len_domain;
5722 if (!*_res.defdname)
5724 len_host = strlen(hostname);
5725 len_domain = strlen(_res.defdname);
5726 if (len_host > len_domain &&
5727 (SM_STRCASEEQ(hostname + len_host - len_domain, _res.defdname)) &&
5728 hostname[len_host - len_domain - 1] == '.')
5729 return len_host - len_domain - 1;
5733 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5737 ** LINK -- clone a file
5739 ** Some OS's lacks link() and hard links. Since sendmail is using
5740 ** link() as an efficient way to clone files, this implementation
5741 ** will simply do a file copy.
5743 ** NOTE: This link() replacement is not a generic replacement as it
5744 ** does not handle all of the semantics of the real link(2).
5747 ** source -- pathname of existing file.
5748 ** target -- pathname of link (clone) to be created.
5752 ** -1 -- failure, see errno for details.
5756 link(source, target)
5762 int src = -1, dst = -1;
5768 sff = SFF_REGONLY|SFF_OPENASROOT;
5769 if (DontLockReadFiles)
5772 /* Open the original file */
5773 src = safeopen((char *)source, O_RDONLY, 0, sff);
5777 /* Obtain the size and the mode */
5778 if (fstat(src, &st) < 0)
5781 /* Create the duplicate copy */
5784 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
5789 /* Copy all of the bytes one buffer at a time */
5790 while ((readlen = read(src, &buf, sizeof(buf))) > 0)
5792 ssize_t left = readlen;
5796 (writelen = write(dst, p, (size_t) left)) >= 0)
5805 /* Any trouble reading? */
5806 if (readlen < 0 || writelen < 0)
5809 /* Close the input file */
5817 /* Close the output file */
5820 /* don't set dst = -1 here so we unlink the file */
5833 (void) unlink(target);
5839 #endif /* NEEDLINK */
5842 ** Compile-Time options
5845 #define SM_STR(x) #x
5846 #define SM_XSTR(x) SM_STR(x)
5848 char *CompileOptions[] =
5851 /* if not enabled (and EightBitAddrOK not set): convert 0xff to 0x7f */
5857 #if HAVE_SSL_CTX_dane_enable
5858 "HAVE_SSL_CTX_dane_enable",
5861 "MAX_TLSA_RR=" SM_XSTR(MAX_TLSA_RR),
5874 #if HESIOD_ALLOW_NUMERIC_LOGIN
5875 "HESIOD_ALLOW_NUMERIC_LOGIN",
5881 /* Use uncompressed IPv6 address format (no "::") by default */
5887 #if LDAP_NETWORK_TIMEOUT
5888 /* set LDAP_OPT_NETWORK_TIMEOUT if available (-c) */
5889 "LDAP_NETWORK_TIMEOUT",
5906 #if MAXDAEMONS != 10
5907 "MAXDAEMONS=" SM_XSTR(MAXDAEMONS),
5909 #if defined(MSGIDLOGLEN)
5910 "MSGIDLOGLEN=" SM_XSTR(MSGIDLOGLEN),
5928 # error "DANE requires NAMED_BIND"
5959 # if defined(DB_VERSION_MAJOR) && defined(DB_VERSION_MINOR)
5960 # if DB_VERSION_MAJOR >= 5 && !defined(SOLARIS) && !HASFLOCK && !ACCEPT_BROKEN_BDB_LOCKING
5963 ** NOTE: disabling this check by setting ACCEPT_BROKEN_BDB_LOCKING
5964 ** means you are taking full responsibility for any problems
5967 ** Map locking will not work, and making a change to a map
5968 ** while sendmail is using it can break mail handling.
5969 ** At least you must stop all sendmail processes when using
5970 ** makemap or newaliases - but there might be other things
5971 ** which could break.
5973 ** You have been warned - use at your own risk!
5976 # error "Berkeley DB file locking needs flock() for version 5.x (and greater?)"
5978 "NEWDB=" SM_XSTR(DB_VERSION_MAJOR) "." SM_XSTR(DB_VERSION_MINOR),
5984 "CDB=" SM_XSTR(CDB),
5998 #ifdef PICKY_HELO_CHECK
6014 #if SM_LDAP_ERROR_ON_MISSING_ARGS
6015 "SM_LDAP_ERROR_ON_MISSING_ARGS",
6026 #if SUID_ROOT_FILES_OK
6027 "SUID_ROOT_FILES_OK",
6029 #if SYSLOG_BUFSIZE > 1024
6030 "SYSLOG_BUFSIZE=" SM_XSTR(SYSLOG_BUFSIZE),
6040 # error "NO_DH disables TLS_EC"
6042 /* elliptic curves */
6046 #if TLS_VRFY_PER_CTX
6055 ** Initial/Partial/Experimental EAI (SMTPUTF8) support.
6056 ** Requires ICU include files and library depending on the OS.
6057 ** Initial patch from Arnt Gulbrandsen.
6061 # error "USE_EAI requires ALLOW_255"
6063 # if _FFR_EIGHT_BIT_ADDR_OK
6064 # error "Cannot enable both USE_EAI and _FFR_EIGHT_BIT_ADDR_OK"
6084 ** OS compile options.
6087 char *OsCompileOptions[] =
6089 #if ADDRCONFIG_IS_BROKEN
6090 "ADDRCONFIG_IS_BROKEN",
6092 #ifdef AUTO_NETINFO_HOSTS
6093 "AUTO_NETINFO_HOSTS",
6095 #ifdef AUTO_NIS_ALIASES
6098 #if BROKEN_RES_SEARCH
6099 "BROKEN_RES_SEARCH",
6101 #ifdef BSD4_4_SOCKADDR
6107 #if DEC_OSF_BROKEN_GETPWENT
6108 "DEC_OSF_BROKEN_GETPWENT",
6113 #if FAST_PID_RECYCLE
6131 #if HASGETDTABLESIZE
6134 #if HAS_GETHOSTBYNAME2
6135 "HAS_GETHOSTBYNAME2",
6143 #if HASLDAPGETALIASBYNAME
6144 "HASLDAPGETALIASBYNAME",
6179 #if HASSETUSERCONTEXT
6180 "HASSETUSERCONTEXT",
6218 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
6230 #if NEEDLOCAL_HOSTNAME_LENGTH
6231 "NEEDLOCAL_HOSTNAME_LENGTH",
6242 #ifdef NO_GETSERVBYNAME
6248 #if REQUIRES_DIR_FSYNC
6249 "REQUIRES_DIR_FSYNC",
6251 #if RLIMIT_NEEDS_SYS_TIME_H
6252 "RLIMIT_NEEDS_SYS_TIME_H",
6260 #if SFS_TYPE == SFS_4ARGS
6262 #elif SFS_TYPE == SFS_MOUNT
6264 #elif SFS_TYPE == SFS_NONE
6266 #elif SFS_TYPE == SFS_NT
6268 #elif SFS_TYPE == SFS_STATFS
6270 #elif SFS_TYPE == SFS_STATVFS
6272 #elif SFS_TYPE == SFS_USTAT
6274 #elif SFS_TYPE == SFS_VFS
6280 #if SIOCGIFCONF_IS_BROKEN
6281 "SIOCGIFCONF_IS_BROKEN",
6283 #if SIOCGIFNUM_IS_BROKEN
6284 "SIOCGIFNUM_IS_BROKEN",
6286 #if SNPRINTF_IS_BROKEN
6287 "SNPRINTF_IS_BROKEN",
6289 #if SO_REUSEADDR_IS_BROKEN
6290 "SO_REUSEADDR_IS_BROKEN",
6304 #if USE_SA_SIGACTION
6319 #if USE_OPENSSL_ENGINE
6321 ** 0: OpenSSL ENGINE?
6322 ** 1: Support Sun OpenSSL patch for SPARC T4 pkcs11
6325 # if USE_OPENSSL_ENGINE != 1
6326 "USE_OPENSSL_ENGINE=" SM_XSTR(USE_OPENSSL_ENGINE),
6328 "USE_OPENSSL_ENGINE",
6331 #if USING_NETSCAPE_LDAP
6332 "USING_NETSCAPE_LDAP",
6341 ** FFR compile options.
6344 char *FFRCompileOptions[] =
6347 /* see cf/feature/bcc.m4 */
6350 #if _FFR_ADDR_TYPE_MODES
6351 /* more info in {addr_type}, requires m4 changes! */
6352 "_FFR_ADDR_TYPE_MODES",
6354 #if _FFR_ALIAS_DETAIL
6355 /* try to handle +detail for aliases */
6356 "_FFR_ALIAS_DETAIL",
6358 #if _FFR_ALLOW_SASLINFO
6359 /* DefaultAuthInfo can be specified by user. */
6360 /* DefaultAuthInfo doesn't really work in 8.13ff anymore. */
6361 "_FFR_ALLOW_SASLINFO",
6363 #if _FFR_BADRCPT_SHUTDOWN
6364 /* shut down connection (421) if there are too many bad RCPTs */
6365 "_FFR_BADRCPT_SHUTDOWN",
6367 #if _FFR_BESTMX_BETTER_TRUNCATION
6368 /* Better truncation of list of MX records for dns map. */
6369 "_FFR_BESTMX_BETTER_TRUNCATION",
6371 #if _FFR_BLANKENV_MACV
6372 /* also look up macros in BlankEnvelope */
6373 "_FFR_BLANKENV_MACV",
6375 #if _FFR_BOUNCE_QUEUE
6376 /* Separate, unprocessed queue for DSNs */
6377 /* John Gardiner Myers of Proofpoint */
6378 "_FFR_BOUNCE_QUEUE",
6380 #if _FFR_CATCH_BROKEN_MTAS
6381 /* Deal with MTAs that send a reply during the DATA phase. */
6382 "_FFR_CATCH_BROKEN_MTAS",
6385 /* Stricter checks about queue directory permissions. */
6388 #if _FFR_CLASS_RM_ENTRY
6389 /* WIP: remove entries from a class: C-{name}entry */
6390 "_FFR_CLASS_RM_ENTRY",
6394 ** Allow to set client specific CA values.
6395 ** CACertFile: see doc/op.*:
6396 ** "The DNs of these certificates are sent to the client
6397 ** during the TLS handshake (as part of the CertificateRequest)
6398 ** as the list of acceptable CAs.
6399 ** However, do not list too many root CAs in that file,
6400 ** otherwise the TLS handshake may fail;"
6401 ** In TLSv1.3 the certs in CACertFile are also sent by
6402 ** the client to the server and there is seemingly a
6403 ** 16KB limit (just in OpenSSL?).
6404 ** Having a separate CACertFile for the client
6405 ** helps to avoid this problem.
6410 #if _FFR_CLIENT_SIZE
6411 /* Don't try to send mail if its size exceeds SIZE= of server. */
6414 #if _FFR_DIGUNIX_SAFECHOWN
6415 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6416 /* Problem noted by Anne Bennett of Concordia University */
6417 "_FFR_DIGUNIX_SAFECHOWN",
6420 /* deliver first TA in background, then queue */
6425 ** WIP: DeliveryMode=Trigger: queue message and notify
6426 ** some kind of queue manager about it.
6431 #if _FFR_DNSMAP_ALIASABLE
6432 /* Allow dns map type to be used for aliases. */
6433 /* Don Lewis of TDK */
6434 "_FFR_DNSMAP_ALIASABLE",
6436 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6437 /* Enable DontLockFilesForRead option. */
6438 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6440 #if _FFR_DOTTED_USERNAMES
6441 /* Allow usernames with '.' */
6442 "_FFR_DOTTED_USERNAMES",
6446 ** Make DaemonPortOptions case sensitive.
6447 ** For some unknown reasons the code converted every option
6448 ** to uppercase (first letter only, as that's the only one that
6449 ** is actually checked). This prevented all new lower case options
6451 ** The documentation doesn't say anything about case (in)sensitivity,
6452 ** which means it should be case sensitive by default,
6453 ** but it's not a good idea to change this within a patch release,
6454 ** so let's delay this to 8.15.
6459 #if _FFR_DPRINTF_MAP
6460 /* dprintf map for logging */
6463 #if _FFR_DROP_TRUSTUSER_WARNING
6465 ** Don't issue this warning:
6466 ** "readcf: option TrustedUser may cause problems on systems
6467 ** which do not support fchown() if UseMSP is not set.
6470 "_FFR_DROP_TRUSTUSER_WARNING",
6473 /* dynamic classes based on maps */
6476 #if _FFR_EIGHT_BIT_ADDR_OK
6478 ** EightBitAddrOK: allow all 8-bit e-mail addresses.
6479 ** By default only ((ch & 0340) == 0200) is blocked
6480 ** because that range is used for "META" chars.
6483 "_FFR_EIGHT_BIT_ADDR_OK",
6485 #if _FFR_EXPAND_HELONAME
6486 /* perform macro expansion for heloname */
6487 "_FFR_EXPAND_HELONAME",
6489 #if _FFR_EXTRA_MAP_CHECK
6490 /* perform extra checks on $( $) in R lines */
6491 "_FFR_EXTRA_MAP_CHECK",
6493 #if _FFR_GETHBN_ExFILE
6495 ** According to Motonori Nakamura some gethostbyname()
6496 ** implementations (TurboLinux?) may (temporarily) fail
6497 ** due to a lack of file descriptors. Enabling this FFR
6498 ** will check errno for EMFILE and ENFILE and in case of a match
6499 ** cause a temporary error instead of a permanent error.
6500 ** The right solution is of course to file a bug against those
6501 ** systems such that they actually set h_errno = TRY_AGAIN.
6504 "_FFR_GETHBN_ExFILE",
6507 /* FIPSMode (if supported by OpenSSL library) */
6512 ** If using -t, force not sending to argv recipients, even
6513 ** if they are mentioned in the headers.
6518 #if _FFR_FORWARD_SYSERR
6519 /* Cause a "syserr" if forward file isn't "safe". */
6520 "_FFR_FORWARD_SYSERR",
6523 /* Generate a ORCPT DSN arg if not already provided */
6526 #if _FFR_HANDLE_ISO8859_GECOS
6528 ** Allow ISO 8859 characters in GECOS field: replace them
6529 ** with ASCII "equivalent".
6532 /* Peter Eriksson of Linkopings universitet */
6533 "_FFR_HANDLE_ISO8859_GECOS",
6535 #if _FFR_HANDLE_HDR_RW_TEMPFAIL
6537 ** Temporary header rewriting problems from remotename() etc
6538 ** are not "sticky" for mci (e.g., during queue runs).
6541 "_FFR_HANDLE_HDR_RW_TEMPFAIL",
6543 #if _FFR_HPUX_NSSWITCH
6544 /* Use nsswitch on HP-UX */
6545 "_FFR_HPUX_NSSWITCH",
6547 #if _FFR_IGNORE_BOGUS_ADDR
6548 /* Ignore addresses for which prescan() failed */
6549 "_FFR_IGNORE_BOGUS_ADDR",
6551 #if _FFR_IGNORE_EXT_ON_HELO
6552 /* Ignore extensions offered in response to HELO */
6553 "_FFR_IGNORE_EXT_ON_HELO",
6556 /* Keep Bcc header */
6559 #if _FFR_LOCAL_DAEMON
6560 /* Local daemon mode (-bl) which only accepts loopback connections */
6561 "_FFR_LOCAL_DAEMON",
6563 #if _FFR_LOG_FAILOVER
6564 /* WIP: log reason why trying another host */
6565 "_FFR_LOG_FAILOVER",
6568 /* log some TLS/AUTH info in from= too */
6569 "_FFR_LOG_MORE1=" SM_XSTR(_FFR_LOG_MORE1),
6572 /* log some TLS info in to= too */
6573 "_FFR_LOG_MORE2=" SM_XSTR(_FFR_LOG_MORE2),
6576 /* log protocol stage for delivery problems */
6580 /* make the "real" sender address available in {mail_from} */
6583 #if _FFR_MAP_CHK_FILE
6584 /* check whether the underlying map file was changed */
6585 "_FFR_MAP_CHK_FILE=" SM_XSTR(_FFR_MAP_CHK_FILE),
6587 #if _FFR_MAXDATASIZE
6589 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6590 ** hence this shouldn't be used as limit for milter communication.
6591 ** see also libmilter/comm.c
6592 ** Gurusamy Sarathy of ActiveState
6597 #if _FFR_MAX_FORWARD_ENTRIES
6598 /* Try to limit number of .forward entries */
6599 /* (doesn't work) */
6600 /* Randall S. Winchester of the University of Maryland */
6601 "_FFR_MAX_FORWARD_ENTRIES",
6603 #if _FFR_MAX_SLEEP_TIME
6604 /* Limit sleep(2) time in libsm/clock.c */
6605 "_FFR_MAX_SLEEP_TIME",
6607 #if _FFR_MDS_NEGOTIATE
6608 /* MaxDataSize negotiation with libmilter */
6609 "_FFR_MDS_NEGOTIATE",
6612 /* Check free memory */
6615 #if _FFR_MILTER_CHECK
6616 /* for (lib)milter testing */
6617 "_FFR_MILTER_CHECK",
6619 #if _FFR_MILTER_CONNECT_REPLYCODE
6620 /* milter: propagate replycode returned by connect commands */
6621 /* John Gardiner Myers of Proofpoint */
6622 "_FFR_MILTER_CONNECT_REPLYCODE",
6624 #if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF
6626 ** milter_body() uses the same conversion algorithm as putbody()
6627 ** to translate the "local" df format (\n) to SMTP format (\r\n).
6628 ** However, putbody() and mime8to7() use different conversion
6630 ** If the input date does not follow the SMTP standard
6631 ** (e.g., if it has "naked \r"s), then the output from putbody()
6632 ** and mime8to7() will most likely be different.
6633 ** By turning on this FFR milter_body() will try to "imitate"
6635 ** Note: there is no (simple) way to deal with both conversions
6636 ** in a consistent manner. Moreover, as the "GiGo" principle applies,
6637 ** it's not really worth to fix it.
6640 "_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF",
6642 #if _FFR_MILTER_CHECK_REJECTIONS_TOO
6644 ** Also send RCPTs that are rejected by check_rcpt to a milter
6645 ** (if requested during option negotiation).
6648 "_FFR_MILTER_CHECK_REJECTIONS_TOO",
6650 #if _FFR_MILTER_ENHSC
6651 /* extract enhanced status code from milter replies for dsn= logging */
6652 "_FFR_MILTER_ENHSC",
6654 #if _FFR_MIME7TO8_OLD
6655 /* Old mime7to8 code, the new is broken for at least one example. */
6656 "_FFR_MIME7TO8_OLD",
6658 #if _FFR_MORE_MACROS
6659 /* allow more long macro names ("unprintable" characters). */
6663 /* allow to override "Message accepted for delivery" */
6667 /* do not modify headers -- does NOT (yet) work */
6672 # error "_FFR_MTA_STS requires MAP_REGEX"
6675 # error "_FFR_MTA_STS requires STARTTLS"
6677 # if !_FFR_TLS_ALTNAMES
6678 # error "_FFR_MTA_STS requires _FFR_TLS_ALTNAMES"
6680 /* MTA STS support */
6682 #endif /* _FFR_MTA_STS */
6683 #if _FFR_NODELAYDSN_ON_HOLD
6684 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6686 "_FFR_NODELAYDSN_ON_HOLD",
6689 /* Disable PIPELINING, delay client if used. */
6692 #if _FFR_LDAP_SINGLEDN
6694 ** The LDAP database map code in Sendmail 8.12.10, when
6695 ** given the -1 switch, would match only a single DN,
6696 ** but was able to return multiple attributes for that
6697 ** DN. In Sendmail 8.13 this "bug" was corrected to
6698 ** only return if exactly one attribute matched.
6700 ** Unfortunately, our configuration uses the former
6701 ** behaviour. Attached is a relatively simple patch
6702 ** to 8.13.4 which adds a -2 switch (for lack of a
6703 ** better option) which returns the single dn/multiple
6706 ** Jeffrey T. Eaton, Carnegie-Mellon University
6709 "_FFR_LDAP_SINGLEDN",
6712 /* log ntries=, from Nik Clayton of FreeBSD */
6717 /* outgoing connection control (not yet working) */
6720 # error "_FFR_OCC requires SM_CONF_SHM"
6724 /* "proxy" (synchronous) delivery mode */
6727 #if _FFR_QF_PARANOIA
6728 /* Check to make sure key fields were read from qf */
6731 #if _FFR_QUEUE_GROUP_SORTORDER
6732 /* Allow QueueSortOrder per queue group. */
6733 /* XXX: Still need to actually use qgrp->qg_sortorder */
6734 "_FFR_QUEUE_GROUP_SORTORDER",
6736 #if _FFR_QUEUE_MACRO
6737 /* Define {queue} macro. */
6740 #if _FFR_QUEUE_RUN_PARANOIA
6741 /* Additional checks when doing queue runs; interval of checks */
6742 "_FFR_QUEUE_RUN_PARANOIA",
6744 #if _FFR_QUEUE_SCHED_DBG
6745 /* Debug output for the queue scheduler. */
6746 "_FFR_QUEUE_SCHED_DBG",
6749 /* dynamic mailer modifications via {rcpt_flags}*/
6752 #if _FFR_RCPTTHROTDELAY
6753 /* configurable delay for BadRcptThrottle */
6754 "_FFR_RCPTTHROTDELAY",
6756 #if _FFR_REDIRECTEMPTY
6758 ** envelope <> can't be sent to mailing lists, only owner-
6759 ** send spam of this type to owner- of the list
6760 ** ---- to stop spam from going to mailing lists.
6763 "_FFR_REDIRECTEMPTY",
6765 #if _FFR_REJECT_NUL_BYTE
6766 /* reject NUL bytes in body */
6767 "_FFR_REJECT_NUL_BYTE",
6769 #if _FFR_REPLY_MULTILINE
6770 /* try to gather multi-line replies for reply= logging */
6771 "_FFR_REPLY_MULTILINE=" SM_XSTR(_FFR_REPLY_MULTILINE),
6773 #if _FFR_RESET_MACRO_GLOBALS
6774 /* Allow macro 'j' to be set dynamically via rulesets. */
6775 "_FFR_RESET_MACRO_GLOBALS",
6778 /* Random shuffle for queue sorting. */
6783 ** allow -qGqueue_group -qp to work, i.e.,
6784 ** restrict a persistent queue runner to a queue group.
6790 /* session id (for logging): WIP, no logging yet! */
6795 ** if _FFR_SETOPT_MAP is used: allow to set any option
6796 ** (which probably does not work as expected for many options).
6801 #if _FFR_SETDEBUG_MAP
6802 /* enable setdebug map to set debug levels from rules */
6803 "_FFR_SETDEBUG_MAP",
6806 /* enable setopt map to set options from rules */
6810 /* Donated code (unused). */
6813 #if _FFR_SKIP_DOMAINS
6814 /* process every N'th domain instead of every N'th message */
6815 "_FFR_SKIP_DOMAINS",
6817 #if _FFR_SLEEP_USE_SELECT
6818 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6819 "_FFR_SLEEP_USE_SELECT",
6821 #if _FFR_SM_LDAP_DBG
6822 # if defined(LBER_OPT_LOG_PRINT_FN)
6823 /* LDAP debugging */
6826 # error "_FFR_SM_LDAP_DBG requires LBER_OPT_LOG_PRINT_FN"
6831 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6832 ** bit alignment, so unless each piece of argv and envp is a multiple
6833 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6834 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6835 ** if you use this FFR.
6838 /* Chris Adams of HiWAAY Informations Services */
6841 #if _FFR_SS_PER_DAEMON
6842 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6843 "_FFR_SS_PER_DAEMON",
6846 /* enable some test code */
6850 /* Donated code (unused). */
6853 #if _FFR_TLS_ALTNAMES
6854 /* store subjectAltNames in class {cert_altnames} */
6855 "_FFR_TLS_ALTNAMES",
6857 #if _FFR_TLSFB2CLEAR
6858 /* set default for TLSFallbacktoClear to true */
6861 #if _FFR_TLS_USE_CERTIFICATE_CHAIN_FILE
6863 ** Use SSL_CTX_use_certificate_chain_file()
6864 ** instead of SSL_CTX_use_certificate_file()
6867 "_FFR_TLS_USE_CERTIFICATE_CHAIN_FILE",
6871 ** If we don't own the file mark it as unsafe.
6872 ** However, allow TrustedUser to own it as well
6873 ** in case TrustedUser manipulates the queue.
6878 #if _FFR_USE_GETPWNAM_ERRNO
6880 ** See libsm/mbdb.c: only enable this on OSs
6881 ** that implement the correct (POSIX) semantics.
6882 ** This will need to become an OS-specific #if enabled
6883 ** in one of the headers files under include/sm/os/ .
6886 "_FFR_USE_GETPWNAM_ERRNO",
6888 #if _FFR_VRFY_TRUSTED_FIRST
6890 ** Sets X509_V_FLAG_TRUSTED_FIRST if -d88;.101 is used.
6891 ** X509_VERIFY_PARAM_set_flags(3)
6892 ** When X509_V_FLAG_TRUSTED_FIRST is set, construction of the
6893 ** certificate chain in X509_verify_cert(3) will search the trust
6894 ** store for issuer certificates before searching the provided
6895 ** untrusted certificates. Local issuer certificates are often more
6896 ** likely to satisfy local security requirements and lead to a locally
6897 ** trusted root. This is especially important when some certificates
6898 ** in the trust store have explicit trust settings (see "TRUST
6899 ** SETTINGS" in x509(1)).
6900 ** As of OpenSSL 1.1.0 this option is on by default.
6903 # if defined(X509_V_FLAG_TRUSTED_FIRST)
6904 "_FFR_VRFY_TRUSTED_FIRST",
6906 # error "_FFR_VRFY_TRUSTED_FIRST set but X509_V_FLAG_TRUSTED_FIRST not defined"
6910 #if _FFR_USE_SEM_LOCKING
6911 /* Use semaphore locking */
6912 "_FFR_USE_SEM_LOCKING",
6914 #if _FFR_USE_SETLOGIN
6915 /* Use setlogin() */
6917 "_FFR_USE_SETLOGIN",
6920 /* X-Connect support */
6924 /* HAproxy support */
6928 /* only convert char <= 31 to something printable for logging etc */
6929 "_FFR_LOGASIS=" SM_XSTR(_FFR_LOGASIS),
6932 /* Allow to override nameserver set by OS */
6936 /* Do not include input from a client in a reply of the server */
6939 #if _FFR_AUTH_PASSING
6940 /* Set the default AUTH= if the sender didn't */
6941 "_FFR_AUTH_PASSING",
6943 #if _FFR_HOST_SORT_REVERSE
6944 /* Reverse sort for host for recipient sorting pre-envelope-split */
6945 "_FFR_HOST_SORT_REVERSE",
6947 #if _FFR_MSP_PARANOIA
6949 ** Forbid queue groups, multiple queues, and
6950 ** dangerous queue permissions when operating as an MSP
6953 "_FFR_MSP_PARANOIA",
6955 #if _FFR_ANY_FREE_FS
6957 ** Check whether there is at least one fs with enough space
6958 ** (may not work, needs review)
6965 ** Strip trailing CR in MIME boundaries
6966 ** (may not work, needs review)
6971 #if _FFR_M_ONLY_IPV4
6972 /* mailer flag 4: use only IPv4 for delivery attempts */
6975 #if _FFR_SMTPS_CLIENT
6976 /* SMTP over TLS client (defaults to port 465/tcp outbound) */
6977 "_FFR_SMTPS_CLIENT",