2 * Copyright (c) 1998-2007 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: conf.c,v 8.1136 2007/10/10 00:06:45 ca Exp $")
18 #include <sm/sendmail.h>
19 #include <sendmail/pathnames.h>
29 /* for the IPv6 device lookup */
30 # define _SOCKADDR_LEN
32 # endif /* NETINET6 */
35 # include <sys/ioctl.h>
36 # include <sys/param.h>
39 #if NETINET || NETINET6
40 # include <arpa/inet.h>
41 #endif /* NETINET || NETINET6 */
42 #if HASULIMIT && defined(HPUX11)
44 #endif /* HASULIMIT && defined(HPUX11) */
46 static void setupmaps
__P((void));
47 static void setupmailers
__P((void));
48 static void setupqueues
__P((void));
49 static int get_num_procs_online
__P((void));
50 static int add_hostnames
__P((SOCKADDR
*));
52 #if NETINET6 && NEEDSGETIPNODE
53 static struct hostent
*getipnodebyname
__P((char *, int, int, int *));
54 static struct hostent
*getipnodebyaddr
__P((char *, int, int, int *));
55 #endif /* NETINET6 && NEEDSGETIPNODE */
59 ** CONF.C -- Sendmail Configuration Tables.
61 ** Defines the configuration of this installation.
63 ** Configuration Variables:
64 ** HdrInfo -- a table describing well-known header fields.
65 ** Each entry has the field name and some flags,
66 ** which are described in sendmail.h.
69 ** I have tried to put almost all the reasonable
70 ** configuration information into the configuration
71 ** file read at runtime. My intent is that anything
72 ** here is a function of the version of UNIX you
73 ** are running, or is really static -- for example
74 ** the headers are a superset of widely used
75 ** protocols. If you find yourself playing with
76 ** this file too much, you may be making a mistake!
82 ** Final (null) entry contains the flags used for any other field.
84 ** Not all of these are actually handled specially by sendmail
85 ** at this time. They are included as placeholders, to let
86 ** you know that "someday" I intend to have sendmail do
87 ** something with them.
90 struct hdrinfo HdrInfo
[] =
92 /* originator fields, most to least significant */
93 { "resent-sender", H_FROM
|H_RESENT
, NULL
},
94 { "resent-from", H_FROM
|H_RESENT
, NULL
},
95 { "resent-reply-to", H_FROM
|H_RESENT
, NULL
},
96 { "sender", H_FROM
, NULL
},
97 { "from", H_FROM
, NULL
},
98 { "reply-to", H_FROM
, NULL
},
99 { "errors-to", H_FROM
|H_ERRORSTO
, NULL
},
100 { "full-name", H_ACHECK
, NULL
},
101 { "return-receipt-to", H_RECEIPTTO
, NULL
},
102 { "delivery-receipt-to", H_RECEIPTTO
, NULL
},
103 { "disposition-notification-to", H_FROM
, NULL
},
105 /* destination fields */
106 { "to", H_RCPT
, NULL
},
107 { "resent-to", H_RCPT
|H_RESENT
, NULL
},
108 { "cc", H_RCPT
, NULL
},
109 { "resent-cc", H_RCPT
|H_RESENT
, NULL
},
110 { "bcc", H_RCPT
|H_BCC
, NULL
},
111 { "resent-bcc", H_RCPT
|H_BCC
|H_RESENT
, NULL
},
112 { "apparently-to", H_RCPT
, NULL
},
114 /* message identification and control */
115 { "message-id", 0, NULL
},
116 { "resent-message-id", H_RESENT
, NULL
},
117 { "message", H_EOH
, NULL
},
118 { "text", H_EOH
, NULL
},
122 { "resent-date", H_RESENT
, NULL
},
125 { "received", H_TRACE
|H_FORCE
, NULL
},
126 { "x400-received", H_TRACE
|H_FORCE
, NULL
},
127 { "via", H_TRACE
|H_FORCE
, NULL
},
128 { "mail-from", H_TRACE
|H_FORCE
, NULL
},
130 /* miscellaneous fields */
131 { "comments", H_FORCE
|H_ENCODABLE
, NULL
},
132 { "return-path", H_FORCE
|H_ACHECK
|H_BINDLATE
, NULL
},
133 { "content-transfer-encoding", H_CTE
, NULL
},
134 { "content-type", H_CTYPE
, NULL
},
135 { "content-length", H_ACHECK
, NULL
},
136 { "subject", H_ENCODABLE
, NULL
},
137 { "x-authentication-warning", H_FORCE
, NULL
},
148 struct prival PrivacyValues
[] =
150 { "public", PRIV_PUBLIC
},
151 { "needmailhelo", PRIV_NEEDMAILHELO
},
152 { "needexpnhelo", PRIV_NEEDEXPNHELO
},
153 { "needvrfyhelo", PRIV_NEEDVRFYHELO
},
154 { "noexpn", PRIV_NOEXPN
},
155 { "novrfy", PRIV_NOVRFY
},
156 { "restrictexpand", PRIV_RESTRICTEXPAND
},
157 { "restrictmailq", PRIV_RESTRICTMAILQ
},
158 { "restrictqrun", PRIV_RESTRICTQRUN
},
159 { "noetrn", PRIV_NOETRN
},
160 { "noverb", PRIV_NOVERB
},
161 { "authwarnings", PRIV_AUTHWARNINGS
},
162 { "noreceipts", PRIV_NORECEIPTS
},
163 { "nobodyreturn", PRIV_NOBODYRETN
},
164 { "goaway", PRIV_GOAWAY
},
165 { "noactualrecipient", PRIV_NOACTUALRECIPIENT
},
170 ** DontBlameSendmail values
173 struct dbsval DontBlameSendmailValues
[] =
175 { "safe", DBS_SAFE
},
176 { "assumesafechown", DBS_ASSUMESAFECHOWN
},
177 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE
},
178 { "groupwritableforwardfilesafe",
179 DBS_GROUPWRITABLEFORWARDFILESAFE
},
180 { "groupwritableincludefilesafe",
181 DBS_GROUPWRITABLEINCLUDEFILESAFE
},
182 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE
},
183 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE
},
184 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH
},
185 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH
},
186 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH
},
187 { "linkedaliasfileinwritabledir",
188 DBS_LINKEDALIASFILEINWRITABLEDIR
},
189 { "linkedclassfileinwritabledir",
190 DBS_LINKEDCLASSFILEINWRITABLEDIR
},
191 { "linkedforwardfileinwritabledir",
192 DBS_LINKEDFORWARDFILEINWRITABLEDIR
},
193 { "linkedincludefileinwritabledir",
194 DBS_LINKEDINCLUDEFILEINWRITABLEDIR
},
195 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR
},
196 { "linkedserviceswitchfileinwritabledir",
197 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR
},
198 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK
},
199 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK
},
200 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK
},
201 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK
},
202 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK
},
203 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK
},
204 { "forwardfileingroupwritabledirpath",
205 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH
},
206 { "includefileingroupwritabledirpath",
207 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH
},
208 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH
},
209 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH
},
210 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH
},
211 { "forwardfileinunsafedirpathsafe",
212 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE
},
213 { "includefileinunsafedirpathsafe",
214 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE
},
215 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH
},
216 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM
},
217 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR
},
218 { "truststickybit", DBS_TRUSTSTICKYBIT
},
219 { "dontwarnforwardfileinunsafedirpath",
220 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH
},
221 { "insufficiententropy", DBS_INSUFFICIENTENTROPY
},
222 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE
},
223 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE
},
224 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE
},
225 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE
},
226 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE
},
227 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE
},
228 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE
},
229 #if _FFR_GROUPREADABLEAUTHINFOFILE
230 { "groupreadableadefaultauthinfofile",
231 DBS_GROUPREADABLEAUTHINFOFILE
},
232 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
237 ** Miscellaneous stuff.
240 int DtableSize
= 50; /* max open files; reset in 4.2bsd */
242 ** SETDEFAULTS -- set default values
244 ** Some of these must be initialized using direct code since they
245 ** depend on run-time values. So let's do all of them this way.
248 ** e -- the default envelope.
254 ** Initializes a bunch of global variables to their
259 #define HOURS * 60 MINUTES
260 #define DAYS * 24 HOURS
262 #ifndef MAXRULERECURSION
263 # define MAXRULERECURSION 50 /* max ruleset recursion depth */
264 #endif /* ! MAXRULERECURSION */
268 register ENVELOPE
*e
;
274 numprocs
= get_num_procs_online();
275 SpaceSub
= ' '; /* option B */
276 QueueLA
= 8 * numprocs
; /* option x */
277 RefuseLA
= 12 * numprocs
; /* option X */
278 WkRecipFact
= 30000L; /* option y */
279 WkClassFact
= 1800L; /* option z */
280 WkTimeFact
= 90000L; /* option Z */
281 QueueFactor
= WkRecipFact
* 20; /* option q */
282 QueueMode
= QM_NORMAL
; /* what queue items to act upon */
283 FileMode
= (RealUid
!= geteuid()) ? 0644 : 0600;
285 QueueFileMode
= (RealUid
!= geteuid()) ? 0644 : 0600;
286 /* option QueueFileMode */
288 if (((pw
= sm_getpwnam("mailnull")) != NULL
&& pw
->pw_uid
!= 0) ||
289 ((pw
= sm_getpwnam("sendmail")) != NULL
&& pw
->pw_uid
!= 0) ||
290 ((pw
= sm_getpwnam("daemon")) != NULL
&& pw
->pw_uid
!= 0))
292 DefUid
= pw
->pw_uid
; /* option u */
293 DefGid
= pw
->pw_gid
; /* option g */
294 DefUser
= newstr(pw
->pw_name
);
298 DefUid
= 1; /* option u */
299 DefGid
= 1; /* option g */
304 sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
305 DefUser
!= NULL
? DefUser
: "<1:1>",
306 (int) DefUid
, (int) DefGid
);
307 CheckpointInterval
= 10; /* option C */
308 MaxHopCount
= 25; /* option h */
309 set_delivery_mode(SM_FORK
, e
); /* option d */
310 e
->e_errormode
= EM_PRINT
; /* option e */
313 e
->e_xfqgrp
= NOQGRP
;
314 e
->e_xfqdir
= NOQDIR
;
315 e
->e_ctime
= curtime();
316 SevenBitInput
= false; /* option 7 */
317 MaxMciCache
= 1; /* option k */
318 MciCacheTimeout
= 5 MINUTES
; /* option K */
319 LogLevel
= 9; /* option L */
323 inittimeouts(NULL
, false); /* option r */
324 PrivacyFlags
= PRIV_PUBLIC
; /* option p */
325 MeToo
= true; /* option m */
326 SendMIMEErrors
= true; /* option f */
327 SuperSafe
= SAFE_REALLY
; /* option s */
328 clrbitmap(DontBlameSendmail
); /* DontBlameSendmail option */
330 MimeMode
= MM_CVTMIME
|MM_PASS8BIT
; /* option 8 */
332 MimeMode
= MM_PASS8BIT
;
333 #endif /* MIME8TO7 */
334 for (i
= 0; i
< MAXTOCLASS
; i
++)
336 TimeOuts
.to_q_return
[i
] = 5 DAYS
; /* option T */
337 TimeOuts
.to_q_warning
[i
] = 0; /* option T */
339 ServiceSwitchFile
= "/etc/mail/service.switch";
340 ServiceCacheMaxAge
= (time_t) 10;
341 HostsFile
= _PATH_HOSTS
;
342 PidFile
= newstr(_PATH_SENDMAILPID
);
343 MustQuoteChars
= "@,;:\\()[].'";
344 MciInfoTimeout
= 30 MINUTES
;
345 MaxRuleRecursion
= MAXRULERECURSION
;
346 MaxAliasRecursion
= 10;
347 MaxMacroRecursion
= 10;
348 ColonOkInAddr
= true;
349 DontLockReadFiles
= true;
350 DontProbeInterfaces
= DPI_PROBEALL
;
351 DoubleBounceAddr
= "postmaster";
352 MaxHeadersLength
= MAXHDRSLEN
;
353 MaxMimeHeaderLength
= MAXLINE
;
354 MaxMimeFieldLength
= MaxMimeHeaderLength
/ 2;
355 MaxForwardEntries
= 0;
357 MaxNOOPCommands
= MAXNOOPCOMMANDS
;
359 AuthMechanisms
= newstr(AUTH_MECHANISMS
);
364 TLS_Srv_Opts
= TLS_I_SRV
;
365 #endif /* STARTTLS */
367 HesiodContext
= NULL
;
368 #endif /* HESIOD_INIT */
370 /* Detect if IPv6 is available at run time */
371 i
= socket(AF_INET6
, SOCK_STREAM
, 0);
381 #endif /* NETINET6 */
382 ControlSocketName
= NULL
;
383 memset(&ConnectOnlyTo
, '\0', sizeof(ConnectOnlyTo
));
384 DataFileBufferSize
= 4096;
385 XscriptFileBufferSize
= 4096;
386 for (i
= 0; i
< MAXRWSETS
; i
++)
387 RuleSetNames
[i
] = NULL
;
389 InputFilters
[0] = NULL
;
391 RejectLogInterval
= 3 HOURS
;
392 #if REQUIRES_DIR_FSYNC
393 RequiresDirfsync
= true;
394 #endif /* REQUIRES_DIR_FSYNC */
395 ConnectionRateWindowSize
= 60;
404 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
410 struct passwd
*defpwent
;
411 static char defuserbuf
[40];
413 DefUser
= defuserbuf
;
414 defpwent
= sm_getpwuid(DefUid
);
415 (void) sm_strlcpy(defuserbuf
,
416 (defpwent
== NULL
|| defpwent
->pw_name
== NULL
)
417 ? "nobody" : defpwent
->pw_name
,
420 sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
421 (int) DefUid
, DefUser
);
424 ** SETUPQUEUES -- initialize default queues
426 ** The mqueue QUEUE structure gets filled in after readcf() but
427 ** we need something to point to now for the mailer setup,
428 ** which use "mqueue" as default queue.
436 MaxRunnersPerQueue
= 1;
437 (void) sm_strlcpy(buf
, "mqueue, P=/var/spool/mqueue", sizeof(buf
));
438 makequeue(buf
, false);
441 ** SETUPMAILERS -- initialize default mailers
449 (void) sm_strlcpy(buf
, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
453 (void) sm_strlcpy(buf
, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
457 (void) sm_strlcpy(buf
, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
463 ** SETUPMAPS -- set up map classes
466 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
468 extern bool parse __P((MAP *, char *)); \
469 extern bool open __P((MAP *, int)); \
470 extern void close __P((MAP *)); \
471 extern char *lookup __P((MAP *, char *, char **, int *)); \
472 extern void store __P((MAP *, char *, char *)); \
473 s = stab(name, ST_MAPCLASS, ST_ENTER); \
474 s->s_mapclass.map_cname = name; \
475 s->s_mapclass.map_ext = ext; \
476 s->s_mapclass.map_cflags = flags; \
477 s->s_mapclass.map_parse = parse; \
478 s->s_mapclass.map_open = open; \
479 s->s_mapclass.map_close = close; \
480 s->s_mapclass.map_lookup = lookup; \
481 s->s_mapclass.map_store = store; \
490 # if DB_VERSION_MAJOR > 1
491 int major_v
, minor_v
, patch_v
;
493 (void) db_version(&major_v
, &minor_v
, &patch_v
);
494 if (major_v
!= DB_VERSION_MAJOR
|| minor_v
!= DB_VERSION_MINOR
)
497 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
498 DB_VERSION_MAJOR
, DB_VERSION_MINOR
, DB_VERSION_PATCH
,
499 major_v
, minor_v
, patch_v
);
501 # endif /* DB_VERSION_MAJOR > 1 */
503 MAPDEF("hash", ".db", MCF_ALIASOK
|MCF_REBUILDABLE
,
504 map_parseargs
, hash_map_open
, db_map_close
,
505 db_map_lookup
, db_map_store
);
507 MAPDEF("btree", ".db", MCF_ALIASOK
|MCF_REBUILDABLE
,
508 map_parseargs
, bt_map_open
, db_map_close
,
509 db_map_lookup
, db_map_store
);
513 MAPDEF("dbm", ".dir", MCF_ALIASOK
|MCF_REBUILDABLE
,
514 map_parseargs
, ndbm_map_open
, ndbm_map_close
,
515 ndbm_map_lookup
, ndbm_map_store
);
519 MAPDEF("nis", NULL
, MCF_ALIASOK
,
520 map_parseargs
, nis_map_open
, null_map_close
,
521 nis_map_lookup
, null_map_store
);
525 MAPDEF("nisplus", NULL
, MCF_ALIASOK
,
526 map_parseargs
, nisplus_map_open
, null_map_close
,
527 nisplus_map_lookup
, null_map_store
);
531 MAPDEF("ldap", NULL
, MCF_ALIASOK
|MCF_NOTPERSIST
,
532 ldapmap_parseargs
, ldapmap_open
, ldapmap_close
,
533 ldapmap_lookup
, null_map_store
);
537 MAPDEF("ph", NULL
, MCF_NOTPERSIST
,
538 ph_map_parseargs
, ph_map_open
, ph_map_close
,
539 ph_map_lookup
, null_map_store
);
543 /* IRIX 6.5 nsd support */
544 MAPDEF("nsd", NULL
, MCF_ALIASOK
,
545 map_parseargs
, null_map_open
, null_map_close
,
546 nsd_map_lookup
, null_map_store
);
550 MAPDEF("hesiod", NULL
, MCF_ALIASOK
|MCF_ALIASONLY
,
551 map_parseargs
, hes_map_open
, hes_map_close
,
552 hes_map_lookup
, null_map_store
);
556 MAPDEF("netinfo", NULL
, MCF_ALIASOK
,
557 map_parseargs
, ni_map_open
, null_map_close
,
558 ni_map_lookup
, null_map_store
);
562 MAPDEF("dns", NULL
, 0,
563 dns_map_init
, null_map_open
, null_map_close
,
564 dns_map_lookup
, null_map_store
);
569 # if _FFR_DNSMAP_ALIASABLE
570 MAPDEF("dns", NULL
, MCF_ALIASOK
,
571 dns_map_parseargs
, dns_map_open
, null_map_close
,
572 dns_map_lookup
, null_map_store
);
573 # else /* _FFR_DNSMAP_ALIASABLE */
574 MAPDEF("dns", NULL
, 0,
575 dns_map_parseargs
, dns_map_open
, null_map_close
,
576 dns_map_lookup
, null_map_store
);
577 # endif /* _FFR_DNSMAP_ALIASABLE */
579 #endif /* NAMED_BIND */
582 /* best MX DNS lookup */
583 MAPDEF("bestmx", NULL
, MCF_OPTFILE
,
584 map_parseargs
, null_map_open
, null_map_close
,
585 bestmx_map_lookup
, null_map_store
);
586 #endif /* NAMED_BIND */
588 MAPDEF("host", NULL
, 0,
589 host_map_init
, null_map_open
, null_map_close
,
590 host_map_lookup
, null_map_store
);
592 MAPDEF("text", NULL
, MCF_ALIASOK
,
593 map_parseargs
, text_map_open
, null_map_close
,
594 text_map_lookup
, null_map_store
);
596 MAPDEF("stab", NULL
, MCF_ALIASOK
|MCF_ALIASONLY
,
597 map_parseargs
, stab_map_open
, null_map_close
,
598 stab_map_lookup
, stab_map_store
);
600 MAPDEF("implicit", NULL
, MCF_ALIASOK
|MCF_ALIASONLY
|MCF_REBUILDABLE
,
601 map_parseargs
, impl_map_open
, impl_map_close
,
602 impl_map_lookup
, impl_map_store
);
604 /* access to system passwd file */
605 MAPDEF("user", NULL
, MCF_OPTFILE
,
606 map_parseargs
, user_map_open
, null_map_close
,
607 user_map_lookup
, null_map_store
);
610 MAPDEF("dequote", NULL
, 0,
611 dequote_init
, null_map_open
, null_map_close
,
612 dequote_map
, null_map_store
);
615 MAPDEF("regex", NULL
, 0,
616 regex_map_init
, null_map_open
, null_map_close
,
617 regex_map_lookup
, null_map_store
);
618 #endif /* MAP_REGEX */
622 MAPDEF("userdb", ".db", 0,
623 map_parseargs
, null_map_open
, null_map_close
,
624 udb_map_lookup
, null_map_store
);
627 /* arbitrary programs */
628 MAPDEF("program", NULL
, MCF_ALIASOK
,
629 map_parseargs
, null_map_open
, null_map_close
,
630 prog_map_lookup
, null_map_store
);
633 MAPDEF("sequence", NULL
, MCF_ALIASOK
,
634 seq_map_parse
, null_map_open
, null_map_close
,
635 seq_map_lookup
, seq_map_store
);
637 /* switched interface to sequenced maps */
638 MAPDEF("switch", NULL
, MCF_ALIASOK
,
639 map_parseargs
, switch_map_open
, null_map_close
,
640 seq_map_lookup
, seq_map_store
);
642 /* null map lookup -- really for internal use only */
643 MAPDEF("null", NULL
, MCF_ALIASOK
|MCF_OPTFILE
,
644 map_parseargs
, null_map_open
, null_map_close
,
645 null_map_lookup
, null_map_store
);
647 /* syslog map -- logs information to syslog */
648 MAPDEF("syslog", NULL
, 0,
649 syslog_map_parseargs
, null_map_open
, null_map_close
,
650 syslog_map_lookup
, null_map_store
);
652 /* macro storage map -- rulesets can set macros */
653 MAPDEF("macro", NULL
, 0,
654 dequote_init
, null_map_open
, null_map_close
,
655 macro_map_lookup
, null_map_store
);
657 /* arithmetic map -- add/subtract/compare */
658 MAPDEF("arith", NULL
, 0,
659 dequote_init
, null_map_open
, null_map_close
,
660 arith_map_lookup
, null_map_store
);
663 /* arbitrary daemons */
664 MAPDEF("socket", NULL
, MCF_ALIASOK
,
665 map_parseargs
, socket_map_open
, socket_map_close
,
666 socket_map_lookup
, null_map_store
);
667 #endif /* SOCKETMAP */
670 /* dprintf map -- logs information to syslog */
671 MAPDEF("dprintf", NULL
, 0,
672 dprintf_map_parseargs
, null_map_open
, null_map_close
,
673 dprintf_map_lookup
, null_map_store
);
674 #endif /* _FFR_DPRINTF_MAP */
678 /* bogus map -- always return tempfail */
679 MAPDEF("bogus", NULL
, MCF_ALIASOK
|MCF_OPTFILE
,
680 map_parseargs
, null_map_open
, null_map_close
,
681 bogus_map_lookup
, null_map_store
);
687 ** INITHOSTMAPS -- initial host-dependent maps
689 ** This should act as an interface to any local service switch
690 ** provided by the host operating system.
699 ** Should define maps "host" and "users" as necessary
700 ** for this OS. If they are not defined, they will get
701 ** a default value later. It should check to make sure
702 ** they are not defined first, since it's possible that
703 ** the config file has provided an override.
711 char *maptype
[MAXMAPSTACK
];
712 short mapreturn
[MAXMAPACTIONS
];
716 ** Make sure we have a host map.
719 if (stab("host", ST_MAP
, ST_FIND
) == NULL
)
721 /* user didn't initialize: set up host map */
722 (void) sm_strlcpy(buf
, "host host", sizeof(buf
));
724 if (ConfigLevel
>= 2)
725 (void) sm_strlcat(buf
, " -a. -D", sizeof(buf
));
726 #endif /* NAMED_BIND */
727 (void) makemapentry(buf
);
731 ** Set up default aliases maps
734 nmaps
= switch_map_find("aliases", maptype
, mapreturn
);
735 for (i
= 0; i
< nmaps
; i
++)
737 if (strcmp(maptype
[i
], "files") == 0 &&
738 stab("aliases.files", ST_MAP
, ST_FIND
) == NULL
)
740 (void) sm_strlcpy(buf
, "aliases.files null",
742 (void) makemapentry(buf
);
745 else if (strcmp(maptype
[i
], "nisplus") == 0 &&
746 stab("aliases.nisplus", ST_MAP
, ST_FIND
) == NULL
)
748 (void) sm_strlcpy(buf
, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
750 (void) makemapentry(buf
);
754 else if (strcmp(maptype
[i
], "nis") == 0 &&
755 stab("aliases.nis", ST_MAP
, ST_FIND
) == NULL
)
757 (void) sm_strlcpy(buf
, "aliases.nis nis mail.aliases",
759 (void) makemapentry(buf
);
763 else if (strcmp(maptype
[i
], "netinfo") == 0 &&
764 stab("aliases.netinfo", ST_MAP
, ST_FIND
) == NULL
)
766 (void) sm_strlcpy(buf
, "aliases.netinfo netinfo -z, /aliases",
768 (void) makemapentry(buf
);
772 else if (strcmp(maptype
[i
], "hesiod") == 0 &&
773 stab("aliases.hesiod", ST_MAP
, ST_FIND
) == NULL
)
775 (void) sm_strlcpy(buf
, "aliases.hesiod hesiod aliases",
777 (void) makemapentry(buf
);
780 #if LDAPMAP && defined(SUN_EXTENSIONS) && \
781 defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
782 else if (strcmp(maptype
[i
], "ldap") == 0 &&
783 stab("aliases.ldap", ST_MAP
, ST_FIND
) == NULL
)
785 (void) strlcpy(buf
, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
787 (void) makemapentry(buf
);
789 #endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */
791 if (stab("aliases", ST_MAP
, ST_FIND
) == NULL
)
793 (void) sm_strlcpy(buf
, "aliases switch aliases", sizeof(buf
));
794 (void) makemapentry(buf
);
799 ** SWITCH_MAP_FIND -- find the list of types associated with a map
801 ** This is the system-dependent interface to the service switch.
804 ** service -- the name of the service of interest.
805 ** maptype -- an out-array of strings containing the types
806 ** of access to use for this service. There can
807 ** be at most MAXMAPSTACK types for a single service.
808 ** mapreturn -- an out-array of return information bitmaps
812 ** The number of map types filled in, or -1 for failure.
815 ** Preserves errno so nothing in the routine clobbers it.
818 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
819 # define _USE_SUN_NSSWITCH_
820 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
822 #if _FFR_HPUX_NSSWITCH
824 # define _USE_SUN_NSSWITCH_
826 #endif /* _FFR_HPUX_NSSWITCH */
828 #ifdef _USE_SUN_NSSWITCH_
829 # include <nsswitch.h>
830 #endif /* _USE_SUN_NSSWITCH_ */
832 #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
833 # define _USE_DEC_SVC_CONF_
834 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
836 #ifdef _USE_DEC_SVC_CONF_
837 # include <sys/svcinfo.h>
838 #endif /* _USE_DEC_SVC_CONF_ */
841 switch_map_find(service
, maptype
, mapreturn
)
843 char *maptype
[MAXMAPSTACK
];
844 short mapreturn
[MAXMAPACTIONS
];
847 int save_errno
= errno
;
849 #ifdef _USE_SUN_NSSWITCH_
850 struct __nsw_switchconfig
*nsw_conf
;
851 enum __nsw_parse_err pserr
;
852 struct __nsw_lookup
*lk
;
853 static struct __nsw_lookup lkp0
=
854 { "files", {1, 0, 0, 0}, NULL
, NULL
};
855 static struct __nsw_switchconfig lkp_default
=
856 { 0, "sendmail", 3, &lkp0
};
858 for (svcno
= 0; svcno
< MAXMAPACTIONS
; svcno
++)
859 mapreturn
[svcno
] = 0;
861 if ((nsw_conf
= __nsw_getconfig(service
, &pserr
)) == NULL
)
862 lk
= lkp_default
.lookups
;
864 lk
= nsw_conf
->lookups
;
866 while (lk
!= NULL
&& svcno
< MAXMAPSTACK
)
868 maptype
[svcno
] = lk
->service_name
;
869 if (lk
->actions
[__NSW_NOTFOUND
] == __NSW_RETURN
)
870 mapreturn
[MA_NOTFOUND
] |= 1 << svcno
;
871 if (lk
->actions
[__NSW_TRYAGAIN
] == __NSW_RETURN
)
872 mapreturn
[MA_TRYAGAIN
] |= 1 << svcno
;
873 if (lk
->actions
[__NSW_UNAVAIL
] == __NSW_RETURN
)
874 mapreturn
[MA_TRYAGAIN
] |= 1 << svcno
;
880 #endif /* _USE_SUN_NSSWITCH_ */
882 #ifdef _USE_DEC_SVC_CONF_
883 struct svcinfo
*svcinfo
;
886 for (svcno
= 0; svcno
< MAXMAPACTIONS
; svcno
++)
887 mapreturn
[svcno
] = 0;
892 if (strcmp(service
, "hosts") == 0)
894 else if (strcmp(service
, "aliases") == 0)
896 else if (strcmp(service
, "passwd") == 0)
903 for (svcno
= 0; svcno
< SVC_PATHSIZE
&& svcno
< MAXMAPSTACK
; svcno
++)
905 switch (svcinfo
->svcpath
[svc
][svcno
])
908 maptype
[svcno
] = "files";
912 maptype
[svcno
] = "nis";
916 maptype
[svcno
] = "dns";
921 maptype
[svcno
] = "hesiod";
923 # endif /* SVC_HESIOD */
932 #endif /* _USE_DEC_SVC_CONF_ */
934 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
936 ** Fall-back mechanism.
940 static time_t servicecachetime
; /* time service switch was cached */
941 time_t now
= curtime();
943 for (svcno
= 0; svcno
< MAXMAPACTIONS
; svcno
++)
944 mapreturn
[svcno
] = 0;
946 if ((now
- servicecachetime
) > (time_t) ServiceCacheMaxAge
)
948 /* (re)read service switch */
949 register SM_FILE_T
*fp
;
950 long sff
= SFF_REGONLY
|SFF_OPENASROOT
|SFF_NOLOCK
;
952 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR
,
957 servicecachetime
= now
;
958 fp
= safefopen(ServiceSwitchFile
, O_RDONLY
, 0, sff
);
963 while (sm_io_fgets(fp
, SM_TIME_DEFAULT
, buf
,
964 sizeof(buf
)) != NULL
)
968 p
= strpbrk(buf
, "#\n");
971 p
= strpbrk(buf
, " \t");
978 sm_syslog(LOG_ERR
, NOQID
,
979 "Bad line on %.100s: %.100s",
990 ** Find/allocate space for this service entry.
991 ** Space for all of the service strings
992 ** are allocated at once. This means
993 ** that we only have to free the first
994 ** one to free all of them.
997 st
= stab(buf
, ST_SERVICE
, ST_ENTER
);
998 if (st
->s_service
[0] != NULL
)
999 sm_free((void *) st
->s_service
[0]); /* XXX */
1001 for (svcno
= 0; svcno
< MAXMAPSTACK
; )
1005 st
->s_service
[svcno
++] = p
;
1006 p
= strpbrk(p
, " \t");
1013 if (svcno
< MAXMAPSTACK
)
1014 st
->s_service
[svcno
] = NULL
;
1016 (void) sm_io_close(fp
, SM_TIME_DEFAULT
);
1020 /* look up entry in cache */
1021 st
= stab(service
, ST_SERVICE
, ST_FIND
);
1022 if (st
!= NULL
&& st
->s_service
[0] != NULL
)
1026 while (svcno
< MAXMAPSTACK
)
1028 maptype
[svcno
] = st
->s_service
[svcno
];
1029 if (maptype
[svcno
++] == NULL
)
1035 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1037 #if !defined(_USE_SUN_NSSWITCH_)
1038 /* if the service file doesn't work, use an absolute fallback */
1039 # ifdef _USE_DEC_SVC_CONF_
1041 # endif /* _USE_DEC_SVC_CONF_ */
1042 for (svcno
= 0; svcno
< MAXMAPACTIONS
; svcno
++)
1043 mapreturn
[svcno
] = 0;
1045 if (strcmp(service
, "aliases") == 0)
1047 maptype
[svcno
++] = "files";
1048 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
1049 maptype
[svcno
++] = "netinfo";
1050 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
1051 # ifdef AUTO_NIS_ALIASES
1053 maptype
[svcno
++] = "nisplus";
1054 # endif /* NISPLUS */
1056 maptype
[svcno
++] = "nis";
1058 # endif /* AUTO_NIS_ALIASES */
1062 if (strcmp(service
, "hosts") == 0)
1065 maptype
[svcno
++] = "dns";
1066 # else /* NAMED_BIND */
1067 # if defined(sun) && !defined(BSD)
1069 maptype
[svcno
++] = "nis";
1070 # endif /* defined(sun) && !defined(BSD) */
1071 # endif /* NAMED_BIND */
1072 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
1073 maptype
[svcno
++] = "netinfo";
1074 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
1075 maptype
[svcno
++] = "files";
1081 #endif /* !defined(_USE_SUN_NSSWITCH_) */
1084 ** USERNAME -- return the user id of the logged in user.
1090 ** The login name of the logged in user.
1096 ** The return value is statically allocated.
1102 static char *myname
= NULL
;
1103 extern char *getlogin();
1104 register struct passwd
*pw
;
1106 /* cache the result */
1109 myname
= getlogin();
1110 if (myname
== NULL
|| myname
[0] == '\0')
1112 pw
= sm_getpwuid(RealUid
);
1114 myname
= pw
->pw_name
;
1118 uid_t uid
= RealUid
;
1120 if ((pw
= sm_getpwnam(myname
)) == NULL
||
1121 (uid
!= 0 && uid
!= pw
->pw_uid
))
1123 pw
= sm_getpwuid(uid
);
1125 myname
= pw
->pw_name
;
1128 if (myname
== NULL
|| myname
[0] == '\0')
1130 syserr("554 5.3.0 Who are you?");
1131 myname
= "postmaster";
1133 else if (strpbrk(myname
, ",;:/|\"\\") != NULL
)
1134 myname
= addquotes(myname
, NULL
);
1136 myname
= sm_pstrdup_x(myname
);
1141 ** TTYPATH -- Get the path of the user's tty
1143 ** Returns the pathname of the user's tty. Returns NULL if
1144 ** the user is not logged in or if s/he has write permission
1151 ** pathname of the user's tty.
1152 ** NULL if not logged in or write permission denied.
1158 ** Return value is in a local buffer.
1168 register char *pathn
;
1169 extern char *ttyname();
1170 extern char *getlogin();
1172 /* compute the pathname of the controlling tty */
1173 if ((pathn
= ttyname(2)) == NULL
&& (pathn
= ttyname(1)) == NULL
&&
1174 (pathn
= ttyname(0)) == NULL
)
1180 /* see if we have write permission */
1181 if (stat(pathn
, &stbuf
) < 0 || !bitset(S_IWOTH
, stbuf
.st_mode
))
1187 /* see if the user is logged in */
1188 if (getlogin() == NULL
)
1195 ** CHECKCOMPAT -- check for From and To person compatible.
1197 ** This routine can be supplied on a per-installation basis
1198 ** to determine whether a person is allowed to send a message.
1199 ** This allows restriction of certain types of internet
1200 ** forwarding or registration of users.
1202 ** If the hosts are found to be incompatible, an error
1203 ** message should be given using "usrerr" and an EX_ code
1204 ** should be returned. You can also set to->q_status to
1205 ** a DSN-style status code.
1207 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
1208 ** body during the return-to-sender function; this should be done
1209 ** on huge messages. This bit may already be set by the ESMTP
1213 ** to -- the person being sent to.
1219 ** none (unless you include the usrerr stuff)
1224 register ADDRESS
*to
;
1225 register ENVELOPE
*e
;
1228 sm_dprintf("checkcompat(to=%s, from=%s)\n",
1229 to
->q_paddr
, e
->e_from
.q_paddr
);
1232 /* this code is intended as an example only */
1235 s
= stab("arpa", ST_MAILER
, ST_FIND
);
1236 if (s
!= NULL
&& strcmp(e
->e_from
.q_mailer
->m_name
, "local") != 0 &&
1237 to
->q_mailer
== s
->s_mailer
)
1239 usrerr("553 No ARPA mail through this machine: see your system administration");
1240 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
1241 to
->q_status
= "5.7.1";
1242 return EX_UNAVAILABLE
;
1244 #endif /* EXAMPLE_CODE */
1248 #ifdef SUN_EXTENSIONS
1254 /* Check for large file descriptor */
1255 if (fstat(fileno(stdin
), &sbuf
) < 0)
1257 if (errno
== EOVERFLOW
)
1264 #endif /* SUN_EXTENSIONS */
1267 ** INIT_MD -- do machine dependent initializations
1269 ** Systems that have global modes that should be set should do
1270 ** them here rather than in main.
1274 # include <compat.h>
1275 #endif /* _AUX_SOURCE */
1278 # include <shares.h>
1279 #endif /* SHARE_V1 */
1287 setcompat(getcompat() | COMPAT_BSDPROT
);
1288 #endif /* _AUX_SOURCE */
1290 #ifdef SUN_EXTENSIONS
1292 #endif /* SUN_EXTENSIONS */
1295 /* keep gethostby*() from stripping the local domain name */
1296 set_domain_trim_off();
1297 #endif /* _CONVEX_SOURCE */
1298 #if defined(__QNX__) && !defined(__QNXNTO__)
1300 ** Due to QNX's network distributed nature, you can target a tcpip
1301 ** stack on a different node in the qnx network; this patch lets
1302 ** this feature work. The __sock_locate() must be done before the
1303 ** environment is clear.
1306 #endif /* __QNX__ */
1307 #if SECUREWARE || defined(_SCO_unix_)
1308 set_auth_parameters(argc
, argv
);
1312 ** This is required for highest security levels (the kernel
1313 ** won't let it call set*uid() or run setuid binaries without
1314 ** it). It may be necessary on other SECUREWARE systems.
1317 if (getluid() == -1)
1319 # endif /* _SCO_unix_ */
1320 #endif /* SECUREWARE || defined(_SCO_unix_) */
1323 #ifdef VENDOR_DEFAULT
1324 VendorCode
= VENDOR_DEFAULT
;
1325 #else /* VENDOR_DEFAULT */
1326 VendorCode
= VENDOR_BERKELEY
;
1327 #endif /* VENDOR_DEFAULT */
1330 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
1332 ** Called once, on startup.
1335 ** e -- the global envelope.
1341 ** vendor-dependent.
1345 init_vendor_macros(e
)
1346 register ENVELOPE
*e
;
1350 ** GETLA -- get the current load average
1352 ** This code stolen from la.c.
1358 ** The current load average as an integer.
1364 /* try to guess what style of load average we have */
1365 #define LA_ZERO 1 /* always return load average as zero */
1366 #define LA_INT 2 /* read kmem for avenrun; interpret as long */
1367 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
1368 #define LA_SUBR 4 /* call getloadavg */
1369 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
1370 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
1371 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
1372 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
1373 #define LA_DGUX 9 /* special DGUX implementation */
1374 #define LA_HPUX 10 /* special HPUX implementation */
1375 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */
1376 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
1377 #define LA_DEVSHORT 13 /* read short from a device */
1378 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
1379 #define LA_PSET 15 /* Solaris per-processor-set load average */
1380 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
1382 /* do guesses based on general OS type */
1384 # define LA_TYPE LA_ZERO
1385 #endif /* ! LA_TYPE */
1388 # if defined(unixpc)
1390 # endif /* defined(unixpc) */
1392 # if defined(__alpha) || defined(IRIX)
1394 # endif /* defined(__alpha) || defined(IRIX) */
1396 #endif /* ! FSHIFT */
1400 #endif /* ! FSHIFT */
1403 # define FSCALE (1 << FSHIFT)
1404 #endif /* ! FSCALE */
1408 # define LA_AVENRUN "avenrun"
1409 # else /* SYSTEM5 */
1410 # define LA_AVENRUN "_avenrun"
1411 # endif /* SYSTEM5 */
1412 #endif /* ! LA_AVENRUN */
1414 /* _PATH_KMEM should be defined in <paths.h> */
1416 # define _PATH_KMEM "/dev/kmem"
1417 #endif /* ! _PATH_KMEM */
1419 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1423 /* _PATH_UNIX should be defined in <paths.h> */
1425 # if defined(SYSTEM5)
1426 # define _PATH_UNIX "/unix"
1427 # else /* defined(SYSTEM5) */
1428 # define _PATH_UNIX "/vmunix"
1429 # endif /* defined(SYSTEM5) */
1430 # endif /* ! _PATH_UNIX */
1434 # else /* _AUX_SOURCE */
1440 # endif /* _AUX_SOURCE */
1441 # define X_AVENRUN 0
1447 static int kmem
= -1;
1448 # if LA_TYPE == LA_INT
1450 # else /* LA_TYPE == LA_INT */
1451 # if LA_TYPE == LA_SHORT
1454 # if LA_TYPE == LA_LONGLONG
1455 long long avenrun
[3];
1456 # else /* LA_TYPE == LA_LONGLONG */
1458 # endif /* LA_TYPE == LA_LONGLONG */
1459 # endif /* LA_TYPE == LA_SHORT */
1460 # endif /* LA_TYPE == LA_INT */
1461 extern off_t
lseek();
1466 (void) sm_strlcpy(Nl
[X_AVENRUN
].n_name
, LA_AVENRUN
,
1467 sizeof(Nl
[X_AVENRUN
].n_name
));
1468 Nl
[1].n_name
[0] = '\0';
1469 # endif /* _AUX_SOURCE */
1471 # if defined(_AIX3) || defined(_AIX4)
1472 if (knlist(Nl
, 1, sizeof(Nl
[0])) < 0)
1473 # else /* defined(_AIX3) || defined(_AIX4) */
1474 if (nlist(_PATH_UNIX
, Nl
) < 0)
1475 # endif /* defined(_AIX3) || defined(_AIX4) */
1478 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX
,
1479 sm_errstring(errno
));
1482 if (Nl
[X_AVENRUN
].n_value
== 0)
1485 sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
1486 _PATH_UNIX
, LA_AVENRUN
);
1489 # ifdef NAMELISTMASK
1490 Nl
[X_AVENRUN
].n_value
&= NAMELISTMASK
;
1491 # endif /* NAMELISTMASK */
1493 kmem
= open(_PATH_KMEM
, 0, 0);
1497 sm_dprintf("getla: open(/dev/kmem): %s\n",
1498 sm_errstring(errno
));
1501 if ((j
= fcntl(kmem
, F_GETFD
, 0)) < 0 ||
1502 fcntl(kmem
, F_SETFD
, j
| FD_CLOEXEC
) < 0)
1505 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1506 sm_errstring(errno
));
1513 sm_dprintf("getla: symbol address = %#lx\n",
1514 (unsigned long) Nl
[X_AVENRUN
].n_value
);
1515 if (lseek(kmem
, (off_t
) Nl
[X_AVENRUN
].n_value
, SEEK_SET
) == -1 ||
1516 read(kmem
, (char *) avenrun
, sizeof(avenrun
)) < sizeof(avenrun
))
1520 sm_dprintf("getla: lseek or read: %s\n",
1521 sm_errstring(errno
));
1524 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
1527 # if LA_TYPE == LA_SHORT
1528 sm_dprintf("getla: avenrun = %d", avenrun
[0]);
1530 sm_dprintf(", %d, %d", avenrun
[1], avenrun
[2]);
1531 # else /* LA_TYPE == LA_SHORT */
1532 # if LA_TYPE == LA_LONGLONG
1533 sm_dprintf("getla: avenrun = %lld", avenrun
[0]);
1535 sm_dprintf(", %lld, %lld", avenrun
[1], avenrun
[2]);
1536 # else /* LA_TYPE == LA_LONGLONG */
1537 sm_dprintf("getla: avenrun = %ld", avenrun
[0]);
1539 sm_dprintf(", %ld, %ld", avenrun
[1], avenrun
[2]);
1540 # endif /* LA_TYPE == LA_LONGLONG */
1541 # endif /* LA_TYPE == LA_SHORT */
1545 sm_dprintf("getla: %d\n",
1546 (int) (avenrun
[0] + FSCALE
/2) >> FSHIFT
);
1547 return ((int) (avenrun
[0] + FSCALE
/2) >> FSHIFT
);
1548 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1551 sm_dprintf("getla: avenrun = %g", avenrun
[0]);
1553 sm_dprintf(", %g, %g", avenrun
[1], avenrun
[2]);
1557 sm_dprintf("getla: %d\n", (int) (avenrun
[0] +0.5));
1558 return ((int) (avenrun
[0] + 0.5));
1559 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1562 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
1564 #if LA_TYPE == LA_READKSYM
1566 # include <sys/ksym.h>
1572 static int kmem
= -1;
1574 struct mioc_rksym mirk
;
1578 kmem
= open("/dev/kmem", 0, 0);
1582 sm_dprintf("getla: open(/dev/kmem): %s\n",
1583 sm_errstring(errno
));
1586 if ((j
= fcntl(kmem
, F_GETFD
, 0)) < 0 ||
1587 fcntl(kmem
, F_SETFD
, j
| FD_CLOEXEC
) < 0)
1590 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1591 sm_errstring(errno
));
1597 mirk
.mirk_symname
= LA_AVENRUN
;
1598 mirk
.mirk_buf
= avenrun
;
1599 mirk
.mirk_buflen
= sizeof(avenrun
);
1600 if (ioctl(kmem
, MIOC_READKSYM
, &mirk
) < 0)
1603 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
1604 sm_errstring(errno
));
1609 sm_dprintf("getla: avenrun = %d", avenrun
[0]);
1611 sm_dprintf(", %d, %d", avenrun
[1], avenrun
[2]);
1615 sm_dprintf("getla: %d\n",
1616 (int) (avenrun
[0] + FSCALE
/2) >> FSHIFT
);
1617 return ((int) (avenrun
[0] + FSCALE
/2) >> FSHIFT
);
1620 #endif /* LA_TYPE == LA_READKSYM */
1622 #if LA_TYPE == LA_DGUX
1624 # include <sys/dg_sys_info.h>
1629 struct dg_sys_info_load_info load_info
;
1631 dg_sys_info((long *)&load_info
,
1632 DG_SYS_INFO_LOAD_INFO_TYPE
, DG_SYS_INFO_LOAD_VERSION_0
);
1635 sm_dprintf("getla: %d\n", (int) (load_info
.one_minute
+ 0.5));
1637 return ((int) (load_info
.one_minute
+ 0.5));
1640 #endif /* LA_TYPE == LA_DGUX */
1642 #if LA_TYPE == LA_HPUX
1644 /* forward declarations to keep gcc from complaining */
1649 struct pst_diskinfo
;
1650 struct pst_processor
;
1652 struct pst_swapinfo
;
1654 # include <sys/param.h>
1655 # include <sys/pstat.h>
1660 struct pst_dynamic pstd
;
1662 if (pstat_getdynamic(&pstd
, sizeof(struct pst_dynamic
),
1663 (size_t) 1, 0) == -1)
1667 sm_dprintf("getla: %d\n", (int) (pstd
.psd_avg_1_min
+ 0.5));
1669 return (int) (pstd
.psd_avg_1_min
+ 0.5);
1672 #endif /* LA_TYPE == LA_HPUX */
1674 #if LA_TYPE == LA_SUBR
1681 if (getloadavg(avenrun
, sizeof(avenrun
) / sizeof(avenrun
[0])) < 0)
1684 sm_dprintf("getla: getloadavg failed: %s",
1685 sm_errstring(errno
));
1689 sm_dprintf("getla: %d\n", (int) (avenrun
[0] +0.5));
1690 return ((int) (avenrun
[0] + 0.5));
1693 #endif /* LA_TYPE == LA_SUBR */
1695 #if LA_TYPE == LA_MACH
1698 ** This has been tested on NEXTSTEP release 2.1/3.X.
1701 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1702 # include <mach/mach.h>
1703 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1705 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
1710 processor_set_t default_set
;
1711 kern_return_t error
;
1712 unsigned int info_count
;
1713 struct processor_set_basic_info info
;
1716 error
= processor_set_default(host_self(), &default_set
);
1717 if (error
!= KERN_SUCCESS
)
1720 sm_dprintf("getla: processor_set_default failed: %s",
1721 sm_errstring(errno
));
1724 info_count
= PROCESSOR_SET_BASIC_INFO_COUNT
;
1725 if (processor_set_info(default_set
, PROCESSOR_SET_BASIC_INFO
,
1726 &host
, (processor_set_info_t
)&info
,
1727 &info_count
) != KERN_SUCCESS
)
1730 sm_dprintf("getla: processor_set_info failed: %s",
1731 sm_errstring(errno
));
1735 sm_dprintf("getla: %d\n",
1736 (int) ((info
.load_average
+ (LOAD_SCALE
/ 2)) /
1738 return (int) (info
.load_average
+ (LOAD_SCALE
/ 2)) / LOAD_SCALE
;
1741 #endif /* LA_TYPE == LA_MACH */
1743 #if LA_TYPE == LA_PROCSTR
1744 # if SM_CONF_BROKEN_STRTOD
1745 ERROR
: This OS has most likely a broken
strtod() implemenentation
.
1746 ERROR
: The function is required
for getla().
1747 ERROR
: Check the compilation options _LA_PROCSTR
and
1748 ERROR
: _SM_CONF_BROKEN_STRTOD (without the leading _
).
1749 # endif /* SM_CONF_BROKEN_STRTOD */
1752 ** Read /proc/loadavg for the load average. This is assumed to be
1753 ** in a format like "0.15 0.12 0.06".
1755 ** Initially intended for Linux. This has been in the kernel
1756 ** since at least 0.99.15.
1759 # ifndef _PATH_LOADAVG
1760 # define _PATH_LOADAVG "/proc/loadavg"
1761 # endif /* ! _PATH_LOADAVG */
1767 register int result
;
1770 fp
= sm_io_open(SmFtStdio
, SM_TIME_DEFAULT
, _PATH_LOADAVG
, SM_IO_RDONLY
,
1775 sm_dprintf("getla: sm_io_open(%s): %s\n",
1776 _PATH_LOADAVG
, sm_errstring(errno
));
1779 result
= sm_io_fscanf(fp
, SM_TIME_DEFAULT
, "%lf", &avenrun
);
1780 (void) sm_io_close(fp
, SM_TIME_DEFAULT
);
1784 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
1785 result
, sm_errstring(errno
));
1790 sm_dprintf("getla(): %.2f\n", avenrun
);
1792 return ((int) (avenrun
+ 0.5));
1795 #endif /* LA_TYPE == LA_PROCSTR */
1797 #if LA_TYPE == LA_IRIX6
1799 # include <sys/sysmp.h>
1802 # define CAST_SYSMP(x) (x)
1803 # else /* _UNICOSMP */
1804 # define CAST_SYSMP(x) ((x) & 0x7fffffff)
1805 # endif /* _UNICOSMP */
1811 static int kmem
= -1;
1816 kmem
= open(_PATH_KMEM
, 0, 0);
1820 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM
,
1821 sm_errstring(errno
));
1824 if ((j
= fcntl(kmem
, F_GETFD
, 0)) < 0 ||
1825 fcntl(kmem
, F_SETFD
, j
| FD_CLOEXEC
) < 0)
1828 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
1829 sm_errstring(errno
));
1836 if (lseek(kmem
, CAST_SYSMP(sysmp(MP_KERNADDR
, MPKA_AVENRUN
)), SEEK_SET
)
1838 read(kmem
, (char *) avenrun
, sizeof(avenrun
)) < sizeof(avenrun
))
1841 sm_dprintf("getla: lseek or read: %s\n",
1842 sm_errstring(errno
));
1847 sm_dprintf("getla: avenrun = %ld", (long int) avenrun
[0]);
1849 sm_dprintf(", %ld, %ld",
1850 (long int) avenrun
[1], (long int) avenrun
[2]);
1855 sm_dprintf("getla: %d\n",
1856 (int) (avenrun
[0] + FSCALE
/2) >> FSHIFT
);
1857 return ((int) (avenrun
[0] + FSCALE
/2) >> FSHIFT
);
1860 #endif /* LA_TYPE == LA_IRIX6 */
1862 #if LA_TYPE == LA_KSTAT
1869 static kstat_ctl_t
*kc
= NULL
;
1870 static kstat_t
*ksp
= NULL
;
1874 if (kc
== NULL
) /* if not initialized before */
1879 sm_dprintf("getla: kstat_open(): %s\n",
1880 sm_errstring(errno
));
1884 ksp
= kstat_lookup(kc
, "unix", 0, "system_misc");
1888 sm_dprintf("getla: kstat_lookup(): %s\n",
1889 sm_errstring(errno
));
1892 if (kstat_read(kc
, ksp
, NULL
) < 0)
1895 sm_dprintf("getla: kstat_read(): %s\n",
1896 sm_errstring(errno
));
1899 ksn
= (kstat_named_t
*) kstat_data_lookup(ksp
, "avenrun_1min");
1900 la
= ((double) ksn
->value
.ul
+ FSCALE
/2) / FSCALE
;
1901 /* kstat_close(kc); /o do not close for fast access */
1905 #endif /* LA_TYPE == LA_KSTAT */
1907 #if LA_TYPE == LA_DEVSHORT
1910 ** Read /dev/table/avenrun for the load average. This should contain
1911 ** three shorts for the 1, 5, and 15 minute loads. We only read the
1912 ** first, since that's all we care about.
1914 ** Intended for SCO OpenServer 5.
1917 # ifndef _PATH_AVENRUN
1918 # define _PATH_AVENRUN "/dev/table/avenrun"
1919 # endif /* ! _PATH_AVENRUN */
1924 static int afd
= -1;
1931 if (afd
== -1 || lseek(afd
, 0L, SEEK_SET
) == -1)
1935 afd
= open(_PATH_AVENRUN
, O_RDONLY
|O_SYNC
);
1938 sm_syslog(LOG_ERR
, NOQID
,
1939 "can't open %s: %s",
1940 _PATH_AVENRUN
, sm_errstring(errno
));
1945 r
= read(afd
, &avenrun
, sizeof(avenrun
));
1948 sm_dprintf("getla: avenrun = %d\n", avenrun
);
1949 loadav
= (int) (avenrun
+ FSCALE
/2) >> FSHIFT
;
1951 sm_dprintf("getla: %d\n", loadav
);
1955 #endif /* LA_TYPE == LA_DEVSHORT */
1957 #if LA_TYPE == LA_ALPHAOSF
1960 # include <sys/table.h>
1966 struct tbl_loadavg tab
;
1968 if (table(TBL_LOADAVG
, 0, &tab
, 1, sizeof(tab
)) == -1)
1971 sm_dprintf("getla: table %s\n", sm_errstring(errno
));
1976 sm_dprintf("getla: scale = %d\n", tab
.tl_lscale
);
1979 ave
= ((tab
.tl_avenrun
.l
[2] + (tab
.tl_lscale
/2)) /
1982 ave
= (int) (tab
.tl_avenrun
.d
[2] + 0.5);
1985 sm_dprintf("getla: %d\n", ave
);
1990 #endif /* LA_TYPE == LA_ALPHAOSF */
1992 #if LA_TYPE == LA_PSET
1999 if (pset_getloadavg(PS_MYID
, avenrun
,
2000 sizeof(avenrun
) / sizeof(avenrun
[0])) < 0)
2003 sm_dprintf("getla: pset_getloadavg failed: %s",
2004 sm_errstring(errno
));
2008 sm_dprintf("getla: %d\n", (int) (avenrun
[0] +0.5));
2009 return ((int) (avenrun
[0] + 0.5));
2012 #endif /* LA_TYPE == LA_PSET */
2014 #if LA_TYPE == LA_ZERO
2020 sm_dprintf("getla: ZERO\n");
2024 #endif /* LA_TYPE == LA_ZERO */
2027 * Copyright 1989 Massachusetts Institute of Technology
2029 * Permission to use, copy, modify, distribute, and sell this software and its
2030 * documentation for any purpose is hereby granted without fee, provided that
2031 * the above copyright notice appear in all copies and that both that
2032 * copyright notice and this permission notice appear in supporting
2033 * documentation, and that the name of M.I.T. not be used in advertising or
2034 * publicity pertaining to distribution of the software without specific,
2035 * written prior permission. M.I.T. makes no representations about the
2036 * suitability of this software for any purpose. It is provided "as is"
2037 * without express or implied warranty.
2039 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
2040 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
2041 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2042 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
2043 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2044 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2046 * Authors: Many and varied...
2049 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
2051 SM_UNUSED(static char rcsid
[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
2056 # include <apollo/base.h>
2059 int getloadavg( call_data
)
2060 caddr_t call_data
; /* pointer to (double) return value */
2062 double *avenrun
= (double *) call_data
;
2067 proc1_$
get_loadav(loadav
, &st
);
2068 *avenrun
= loadav
[0] / (double) (1 << 16);
2073 ** SM_GETLA -- get the current load average
2082 ** Set CurrentLA to the current load average.
2083 ** Set {load_avg} in GlobalMacros to the current load average.
2091 CurrentLA
= getla();
2092 (void) sm_snprintf(labuf
, sizeof(labuf
), "%d", CurrentLA
);
2093 macdefine(&GlobalMacros
, A_TEMP
, macid("{load_avg}"), labuf
);
2096 ** SHOULDQUEUE -- should this message be queued or sent?
2098 ** Compares the message cost to the load average to decide.
2100 ** Note: Do NOT change this API! It is documented in op.me
2101 ** and theoretically the user can change this function...
2104 ** pri -- the priority of the message in question.
2105 ** ct -- the message creation time (unused, but see above).
2108 ** true -- if this message should be queued up for the
2110 ** false -- if the load is low enough to send this message.
2118 shouldqueue(pri
, ct
)
2125 #endif /* _FFR_MEMSTAT */
2128 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
2132 if (QueueLowMem
> 0 &&
2133 sm_memstat_get(MemoryResource
, &memfree
) >= 0 &&
2134 memfree
< QueueLowMem
)
2137 sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n",
2138 memfree
, QueueLowMem
);
2141 #endif /* _FFR_MEMSTAT */
2142 if (CurrentLA
< QueueLA
)
2145 sm_dprintf("false (CurrentLA < QueueLA)\n");
2148 rval
= pri
> (QueueFactor
/ (CurrentLA
- QueueLA
+ 1));
2150 sm_dprintf("%s (by calculation)\n", rval
? "true" : "false");
2155 ** REFUSECONNECTIONS -- decide if connections should be refused
2158 ** e -- the current envelope.
2159 ** dn -- number of daemon.
2160 ** active -- was this daemon actually active?
2163 ** true if incoming SMTP connections should be refused
2165 ** false if we should accept new work.
2168 ** Sets process title when it is rejecting connections.
2172 refuseconnections(e
, dn
, active
)
2177 static time_t lastconn
[MAXDAEMONS
];
2178 static int conncnt
[MAXDAEMONS
];
2179 static time_t firstrejtime
[MAXDAEMONS
];
2180 static time_t nextlogtime
[MAXDAEMONS
];
2184 #endif /* _FFR_MEMSTAT */
2192 SM_ASSERT(dn
< MAXDAEMONS
);
2193 if (ConnRateThrottle
> 0)
2200 if (now
!= lastconn
[dn
])
2205 else if (conncnt
[dn
]++ > ConnRateThrottle
)
2207 #define D_MSG_CRT "deferring connections on daemon %s: %d per second"
2208 /* sleep to flatten out connection load */
2209 sm_setproctitle(true, e
, D_MSG_CRT
,
2213 sm_syslog(LOG_INFO
, NOQID
, D_MSG_CRT
,
2219 else if (now
!= lastconn
[dn
])
2225 if (RefuseLowMem
> 0 &&
2226 sm_memstat_get(MemoryResource
, &memfree
) >= 0 &&
2227 memfree
< RefuseLowMem
)
2229 # define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
2230 sm_setproctitle(true, e
, R_MSG_LM
, Daemons
[dn
].d_name
, memfree
);
2232 sm_syslog(LOG_NOTICE
, NOQID
, R_MSG_LM
,
2233 Daemons
[dn
].d_name
, memfree
);
2236 #endif /* _FFR_MEMSTAT */
2238 limit
= (Daemons
[dn
].d_refuseLA
!= DPO_NOTSET
) ?
2239 Daemons
[dn
].d_refuseLA
: RefuseLA
;
2240 if (limit
> 0 && CurrentLA
>= limit
)
2244 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
2245 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
2246 sm_setproctitle(true, e
, R_MSG_LA
, Daemons
[dn
].d_name
,
2249 sm_syslog(LOG_NOTICE
, NOQID
, R_MSG_LA
,
2250 Daemons
[dn
].d_name
, CurrentLA
);
2252 if (firstrejtime
[dn
] == 0)
2254 firstrejtime
[dn
] = now
;
2255 nextlogtime
[dn
] = now
+ RejectLogInterval
;
2257 else if (nextlogtime
[dn
] < now
)
2259 sm_syslog(LOG_ERR
, NOQID
, R2_MSG_LA
, Daemons
[dn
].d_name
,
2260 pintvl(now
- firstrejtime
[dn
], true));
2261 nextlogtime
[dn
] = now
+ RejectLogInterval
;
2266 firstrejtime
[dn
] = 0;
2268 limit
= (Daemons
[dn
].d_delayLA
!= DPO_NOTSET
) ?
2269 Daemons
[dn
].d_delayLA
: DelayLA
;
2270 if (limit
> 0 && CurrentLA
>= limit
)
2273 static time_t log_delay
= (time_t) 0;
2275 # define MIN_DELAY_LOG 90 /* wait before logging this again */
2276 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
2277 /* sleep to flatten out connection load */
2278 sm_setproctitle(true, e
, D_MSG_LA
, Daemons
[dn
].d_name
, limit
);
2279 if (LogLevel
> 8 && (now
= curtime()) > log_delay
)
2281 sm_syslog(LOG_INFO
, NOQID
, D_MSG_LA
,
2282 Daemons
[dn
].d_name
, CurrentLA
, limit
);
2283 log_delay
= now
+ MIN_DELAY_LOG
;
2288 limit
= (Daemons
[dn
].d_maxchildren
!= DPO_NOTSET
) ?
2289 Daemons
[dn
].d_maxchildren
: MaxChildren
;
2290 if (limit
> 0 && CurChildren
>= limit
)
2293 if (CurChildren
>= limit
)
2295 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
2296 sm_setproctitle(true, e
, R_MSG_CHILD
,
2297 Daemons
[dn
].d_name
, CurChildren
,
2300 sm_syslog(LOG_INFO
, NOQID
, R_MSG_CHILD
,
2301 Daemons
[dn
].d_name
, CurChildren
,
2310 ** SETPROCTITLE -- set process title for ps
2313 ** fmt -- a printf style format string.
2314 ** a, b, c -- possible parameters to fmt.
2320 ** Clobbers argv of our main procedure so ps(1) will
2321 ** display the title.
2324 #define SPT_NONE 0 /* don't use it at all */
2325 #define SPT_REUSEARGV 1 /* cover argv with title information */
2326 #define SPT_BUILTIN 2 /* use libc builtin */
2327 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
2328 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
2329 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
2330 #define SPT_SCO 6 /* write kernel u. area */
2331 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
2334 # define SPT_TYPE SPT_REUSEARGV
2335 #endif /* ! SPT_TYPE */
2338 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
2340 # if SPT_TYPE == SPT_PSTAT
2341 # include <sys/pstat.h>
2342 # endif /* SPT_TYPE == SPT_PSTAT */
2343 # if SPT_TYPE == SPT_PSSTRINGS
2344 # include <machine/vmparam.h>
2345 # include <sys/exec.h>
2346 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
2348 # define SPT_TYPE SPT_REUSEARGV
2349 # else /* ! PS_STRINGS */
2350 # ifndef NKPDE /* FreeBSD 2.0 */
2352 typedef unsigned int *pt_entry_t
;
2353 # endif /* ! NKPDE */
2354 # endif /* ! PS_STRINGS */
2355 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2357 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
2358 # define SETPROC_STATIC static
2359 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2360 # define SETPROC_STATIC
2361 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
2363 # if SPT_TYPE == SPT_SYSMIPS
2364 # include <sys/sysmips.h>
2365 # include <sys/sysnews.h>
2366 # endif /* SPT_TYPE == SPT_SYSMIPS */
2368 # if SPT_TYPE == SPT_SCO
2369 # include <sys/immu.h>
2370 # include <sys/dir.h>
2371 # include <sys/user.h>
2372 # include <sys/fs/s5param.h>
2373 # if PSARGSZ > MAXLINE
2374 # define SPT_BUFSIZE PSARGSZ
2375 # endif /* PSARGSZ > MAXLINE */
2376 # endif /* SPT_TYPE == SPT_SCO */
2378 # ifndef SPT_PADCHAR
2379 # define SPT_PADCHAR ' '
2380 # endif /* ! SPT_PADCHAR */
2382 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
2385 # define SPT_BUFSIZE MAXLINE
2386 #endif /* ! SPT_BUFSIZE */
2391 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
2392 ** 64 bit alignment, so unless each piece of argv and envp is a multiple
2393 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use
2394 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
2395 ** you use this FFR.
2398 # ifdef SPT_ALIGN_SIZE
2399 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
2400 # else /* SPT_ALIGN_SIZE */
2401 # define SPT_ALIGN(x, align) (x)
2402 # endif /* SPT_ALIGN_SIZE */
2403 #else /* _FFR_SPT_ALIGN */
2404 # define SPT_ALIGN(x, align) (x)
2405 #endif /* _FFR_SPT_ALIGN */
2408 ** Pointers for setproctitle.
2409 ** This allows "ps" listings to give more useful information.
2412 static char **Argv
= NULL
; /* pointer to argument vector */
2413 static char *LastArgv
= NULL
; /* end of argv */
2414 #if SPT_TYPE != SPT_BUILTIN
2415 static void setproctitle
__P((const char *, ...));
2416 #endif /* SPT_TYPE != SPT_BUILTIN */
2419 initsetproctitle(argc
, argv
, envp
)
2426 extern char **environ
;
2429 ** Move the environment so setproctitle can use the space at
2430 ** the top of memory.
2435 for (i
= 0; envp
[i
] != NULL
; i
++)
2437 environ
= (char **) xalloc(sizeof(char *) * (i
+ 1));
2438 for (i
= 0; envp
[i
] != NULL
; i
++)
2439 environ
[i
] = newstr(envp
[i
]);
2444 ** Save start and extent of argv for setproctitle.
2450 ** Determine how much space we can use for setproctitle.
2451 ** Use all contiguous argv and envp pointers starting at argv[0]
2456 # ifdef SPT_ALIGN_SIZE
2457 for (i
= SPT_ALIGN_SIZE
; i
> 0; i
>>= 1)
2459 # endif /* SPT_ALIGN_SIZE */
2460 # endif /* _FFR_SPT_ALIGN */
2462 for (i
= 0; i
< argc
; i
++)
2464 if (i
== 0 || LastArgv
+ 1 == argv
[i
])
2465 LastArgv
= argv
[i
] + SPT_ALIGN(strlen(argv
[i
]), align
);
2467 for (i
= 0; LastArgv
!= NULL
&& envp
!= NULL
&& envp
[i
] != NULL
; i
++)
2469 if (LastArgv
+ 1 == envp
[i
])
2470 LastArgv
= envp
[i
] + SPT_ALIGN(strlen(envp
[i
]), align
);
2474 #if SPT_TYPE != SPT_BUILTIN
2479 setproctitle(const char *fmt
, ...)
2480 # else /* __STDC__ */
2481 setproctitle(fmt
, va_alist
)
2484 # endif /* __STDC__ */
2486 # if SPT_TYPE != SPT_NONE
2489 SETPROC_STATIC
char buf
[SPT_BUFSIZE
];
2491 # if SPT_TYPE == SPT_PSTAT
2493 # endif /* SPT_TYPE == SPT_PSTAT */
2494 # if SPT_TYPE == SPT_SCO
2497 static int kmem
= -1;
2498 static pid_t kmempid
= -1;
2500 # endif /* SPT_TYPE == SPT_SCO */
2504 /* print sendmail: heading for grep */
2505 (void) sm_strlcpy(p
, "sendmail: ", SPACELEFT(buf
, p
));
2508 /* print the argument string */
2509 SM_VA_START(ap
, fmt
);
2510 (void) sm_vsnprintf(p
, SPACELEFT(buf
, p
), fmt
, ap
);
2513 i
= (int) strlen(buf
);
2517 # if SPT_TYPE == SPT_PSTAT
2518 pst
.pst_command
= buf
;
2519 pstat(PSTAT_SETCMD
, pst
, i
, 0, 0);
2520 # endif /* SPT_TYPE == SPT_PSTAT */
2521 # if SPT_TYPE == SPT_PSSTRINGS
2522 PS_STRINGS
->ps_nargvstr
= 1;
2523 PS_STRINGS
->ps_argvstr
= buf
;
2524 # endif /* SPT_TYPE == SPT_PSSTRINGS */
2525 # if SPT_TYPE == SPT_SYSMIPS
2526 sysmips(SONY_SYSNEWS
, NEWS_SETPSARGS
, buf
);
2527 # endif /* SPT_TYPE == SPT_SYSMIPS */
2528 # if SPT_TYPE == SPT_SCO
2529 if (kmem
< 0 || kmempid
!= CurrentPid
)
2533 kmem
= open(_PATH_KMEM
, O_RDWR
, 0);
2536 if ((j
= fcntl(kmem
, F_GETFD
, 0)) < 0 ||
2537 fcntl(kmem
, F_SETFD
, j
| FD_CLOEXEC
) < 0)
2543 kmempid
= CurrentPid
;
2545 buf
[PSARGSZ
- 1] = '\0';
2546 seek_off
= UVUBLK
+ (off_t
) u
.u_psargs
- (off_t
) &u
;
2547 if (lseek(kmem
, (off_t
) seek_off
, SEEK_SET
) == seek_off
)
2548 (void) write(kmem
, buf
, PSARGSZ
);
2549 # endif /* SPT_TYPE == SPT_SCO */
2550 # if SPT_TYPE == SPT_REUSEARGV
2551 if (LastArgv
== NULL
)
2554 if (i
> LastArgv
- Argv
[0] - 2)
2556 i
= LastArgv
- Argv
[0] - 2;
2559 (void) sm_strlcpy(Argv
[0], buf
, i
+ 1);
2561 while (p
< LastArgv
)
2564 # endif /* SPT_TYPE == SPT_REUSEARGV */
2565 # if SPT_TYPE == SPT_CHANGEARGV
2568 # endif /* SPT_TYPE == SPT_CHANGEARGV */
2569 # endif /* SPT_TYPE != SPT_NONE */
2572 #endif /* SPT_TYPE != SPT_BUILTIN */
2574 ** SM_SETPROCTITLE -- set process task and set process title for ps
2576 ** Possibly set process status and call setproctitle() to
2577 ** change the ps display.
2580 ** status -- whether or not to store as process status
2581 ** e -- the current envelope.
2582 ** fmt -- a printf style format string.
2583 ** a, b, c -- possible parameters to fmt.
2592 sm_setproctitle(bool status
, ENVELOPE
*e
, const char *fmt
, ...)
2593 #else /* __STDC__ */
2594 sm_setproctitle(status
, e
, fmt
, va_alist
)
2599 #endif /* __STDC__ */
2601 char buf
[SPT_BUFSIZE
];
2604 /* print the argument string */
2605 SM_VA_START(ap
, fmt
);
2606 (void) sm_vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
2610 proc_list_set(CurrentPid
, buf
);
2612 if (ProcTitlePrefix
!= NULL
)
2614 char prefix
[SPT_BUFSIZE
];
2616 expand(ProcTitlePrefix
, prefix
, sizeof(prefix
), e
);
2617 setproctitle("%s: %s", prefix
, buf
);
2620 setproctitle("%s", buf
);
2623 ** WAITFOR -- wait for a particular process id.
2626 ** pid -- process id to wait for.
2630 ** -1 if pid never shows up.
2648 proc_list_drop(i
, st
, NULL
);
2649 } while ((i
>= 0 || errno
== EINTR
) && i
!= pid
);
2658 ** status -- pointer to status (return value)
2670 # else /* WAITUNION */
2672 # endif /* WAITUNION */
2674 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2676 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2678 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2679 savesig
= sm_releasesignal(SIGCHLD
);
2680 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2682 # if defined(ISC_UNIX) || defined(_SCO_unix_)
2684 sm_blocksignal(SIGCHLD
);
2685 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
2687 *status
= st
.w_status
;
2688 # else /* WAITUNION */
2690 # endif /* WAITUNION */
2694 ** REAPCHILD -- pick up the body of my child, lest it become a zombie
2697 ** sig -- the signal that got us here (unused).
2703 ** Picks up extant zombies.
2704 ** Control socket exits may restart/shutdown daemon.
2706 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2707 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2716 int save_errno
= errno
;
2724 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0)
2729 # else /* HASWAITPID */
2733 while ((pid
= wait3(&status
, WNOHANG
, (struct rusage
*) NULL
)) > 0)
2735 st
= status
.w_status
;
2736 # else /* WNOHANG */
2740 ** Catch one zombie -- we will be re-invoked (we hope) if there
2741 ** are more. Unreliable signals probably break this, but this
2742 ** is the "old system" situation -- waitpid or wait3 are to be
2743 ** strongly preferred.
2746 if ((pid
= wait(&status
)) > 0)
2749 # endif /* WNOHANG */
2750 # endif /* HASWAITPID */
2751 /* Drop PID and check if it was a control socket child */
2752 proc_list_drop(pid
, st
, NULL
);
2754 FIX_SYSV_SIGNAL(sig
, reapchild
);
2756 return SIGFUNC_RETURN
;
2759 ** GETDTABLESIZE -- return number of file descriptors
2761 ** Only on non-BSD systems
2767 ** size of file descriptor table
2774 # include <sys/resource.h>
2775 #endif /* SOLARIS */
2780 # ifdef RLIMIT_NOFILE
2783 if (getrlimit(RLIMIT_NOFILE
, &rl
) >= 0)
2785 # endif /* RLIMIT_NOFILE */
2787 # if HASGETDTABLESIZE
2788 return getdtablesize();
2789 # else /* HASGETDTABLESIZE */
2790 # ifdef _SC_OPEN_MAX
2791 return sysconf(_SC_OPEN_MAX
);
2792 # else /* _SC_OPEN_MAX */
2794 # endif /* _SC_OPEN_MAX */
2795 # endif /* HASGETDTABLESIZE */
2798 ** UNAME -- get the UUCP name of this system.
2805 struct utsname
*name
;
2810 name
->nodename
[0] = '\0';
2812 /* try /etc/whoami -- one line with the node name */
2813 if ((file
= sm_io_open(SmFtStdio
, SM_TIME_DEFAULT
, "/etc/whoami",
2814 SM_IO_RDONLY
, NULL
)) != NULL
)
2816 (void) sm_io_fgets(file
, SM_TIME_DEFAULT
, name
->nodename
,
2818 (void) sm_io_close(file
, SM_TIME_DEFAULT
);
2819 n
= strchr(name
->nodename
, '\n');
2822 if (name
->nodename
[0] != '\0')
2826 /* try /usr/include/whoami.h -- has a #define somewhere */
2827 if ((file
= sm_io_open(SmFtStdio
, SM_TIME_DEFAULT
,
2828 "/usr/include/whoami.h", SM_IO_RDONLY
, NULL
))
2833 while (sm_io_fgets(file
, SM_TIME_DEFAULT
,
2834 buf
, sizeof(buf
)) != NULL
)
2836 if (sm_io_sscanf(buf
, "#define sysname \"%*[^\"]\"",
2837 NODE_LENGTH
, name
->nodename
) > 0)
2840 (void) sm_io_close(file
, SM_TIME_DEFAULT
);
2841 if (name
->nodename
[0] != '\0')
2847 #endif /* !HASUNAME */
2849 ** INITGROUPS -- initialize groups
2851 ** Stub implementation for System V style systems
2856 initgroups(name
, basegid
)
2863 #endif /* !HASINITGROUPS */
2865 ** SETGROUPS -- set group list
2867 ** Stub implementation for systems that don't have group lists
2873 setgroups(ngroups
, grouplist
)
2875 GIDSET_T grouplist
[];
2880 #endif /* ! NGROUPS_MAX */
2882 ** SETSID -- set session id (for non-POSIX systems)
2893 fd
= open("/dev/tty", O_RDWR
, 0);
2896 (void) ioctl(fd
, TIOCNOTTY
, (char *) 0);
2899 # endif /* TIOCNOTTY */
2902 # else /* SYS5SETPGRP */
2903 return setpgid(0, CurrentPid
);
2904 # endif /* SYS5SETPGRP */
2907 #endif /* !HASSETSID */
2909 ** FSYNC -- dummy fsync
2918 return fcntl(fd
, F_SETFL
, O_SYNC
);
2920 /* nothing we can do */
2922 # endif /* O_SYNC */
2925 #endif /* NEEDFSYNC */
2927 ** DGUX_INET_ADDR -- inet_addr for DG/UX
2929 ** Data General DG/UX version of inet_addr returns a struct in_addr
2930 ** instead of a long. This patches things. Only needed on versions
2939 dgux_inet_addr(host
)
2942 struct in_addr haddr
;
2944 haddr
= inet_addr(host
);
2945 return haddr
.s_addr
;
2948 #endif /* DGUX_5_4_2 */
2950 ** GETOPT -- for old systems or systems with bogus implementations
2956 * Copyright (c) 1985 Regents of the University of California.
2957 * All rights reserved. The Berkeley software License Agreement
2958 * specifies the terms and conditions for redistribution.
2963 ** this version hacked to add `atend' flag to allow state machine
2964 ** to reset if invoked by the program to scan args for a 2nd time
2967 # if defined(LIBC_SCCS) && !defined(lint)
2968 static char sccsid
[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
2969 # endif /* defined(LIBC_SCCS) && !defined(lint) */
2972 ** get option letter from argument vector
2974 # ifdef _CONVEX_SOURCE
2975 extern int optind
, opterr
, optopt
;
2976 extern char *optarg
;
2977 # else /* _CONVEX_SOURCE */
2978 int opterr
= 1; /* if error message should be printed */
2979 int optind
= 1; /* index into parent argv vector */
2980 int optopt
= 0; /* character checked for validity */
2981 char *optarg
= NULL
; /* argument associated with option */
2982 # endif /* _CONVEX_SOURCE */
2984 # define BADCH (int)'?'
2986 # define tell(s) if (opterr) \
2987 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
2988 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
2989 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
2990 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
2994 getopt(nargc
,nargv
,ostr
)
2999 static char *place
= EMSG
; /* option letter processing */
3000 static char atend
= 0;
3001 register char *oli
= NULL
; /* option letter list index */
3007 if(!*place
) { /* update scanning pointer */
3008 if (optind
>= nargc
|| *(place
= nargv
[optind
]) != '-' || !*++place
) {
3012 if (*place
== '-') { /* found "--" */
3017 } /* option letter okay? */
3018 if ((optopt
= (int)*place
++) == (int)':' || !(oli
= strchr(ostr
,optopt
))) {
3019 if (!*place
) ++optind
;
3020 tell(": illegal option -- ");
3022 if (oli
&& *++oli
!= ':') { /* don't need argument */
3024 if (!*place
) ++optind
;
3026 else { /* need an argument */
3027 if (*place
) optarg
= place
; /* no white space */
3028 else if (nargc
<= ++optind
) { /* no arg */
3030 tell(": option requires an argument -- ");
3032 else optarg
= nargv
[optind
]; /* white space */
3036 return optopt
; /* dump back option letter */
3039 #endif /* !SM_CONF_GETOPT */
3041 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
3044 ** user -- the name of the user we are checking.
3045 ** shell -- the user's shell from /etc/passwd
3048 ** true -- if it is ok to use this for unrestricted access.
3049 ** false -- if the shell is restricted.
3052 #if !HASGETUSERSHELL
3054 # ifndef _PATH_SHELLS
3055 # define _PATH_SHELLS "/etc/shells"
3056 # endif /* ! _PATH_SHELLS */
3058 # if defined(_AIX3) || defined(_AIX4)
3059 # include <userconf.h>
3061 # include <userpw.h>
3062 # endif /* _AIX4 >= 40200 */
3063 # include <usersec.h>
3064 # endif /* defined(_AIX3) || defined(_AIX4) */
3066 static char *DefaultUserShells
[] =
3068 "/bin/sh", /* standard shell */
3073 "/bin/csh", /* C shell */
3078 "/usr/bin/rsh", /* restricted Bourne shell */
3079 "/usr/bin/ksh", /* Korn shell */
3080 "/usr/bin/rksh", /* restricted Korn shell */
3082 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3083 "/usr/bin/posix/sh",
3085 "/bin/rsh", /* restricted Bourne shell */
3086 "/bin/ksh", /* Korn shell */
3087 "/bin/rksh", /* restricted Korn shell */
3089 "/usr/bin/keysh", /* key shell (extended Korn shell) */
3093 # endif /* __hpux */
3094 # if defined(_AIX3) || defined(_AIX4)
3095 "/bin/ksh", /* Korn shell */
3097 "/bin/tsh", /* trusted shell */
3099 "/bin/bsh", /* Bourne shell */
3101 # endif /* defined(_AIX3) || defined(_AIX4) */
3102 # if defined(__svr4__) || defined(__svr5__)
3103 "/bin/ksh", /* Korn shell */
3105 # endif /* defined(__svr4__) || defined(__svr5__) */
3107 "/sbin/sh", /* SGI's shells really live in /sbin */
3109 "/sbin/bsh", /* classic Bourne shell */
3112 "/sbin/csh", /* standard csh */
3115 "/sbin/jsh", /* classic Bourne shell w/ job control*/
3118 "/bin/ksh", /* Korn shell */
3121 "/sbin/tcsh", /* Extended csh */
3128 #endif /* !HASGETUSERSHELL */
3130 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
3133 usershellok(user
, shell
)
3137 # if HASGETUSERSHELL
3139 extern char *getusershell();
3141 if (shell
== NULL
|| shell
[0] == '\0' || wordinclass(user
, 't') ||
3146 while ((p
= getusershell()) != NULL
)
3147 if (strcmp(p
, shell
) == 0 || strcmp(p
, WILDCARD_SHELL
) == 0)
3151 # else /* HASGETUSERSHELL */
3154 # endif /* USEGETCONFATTR */
3155 register SM_FILE_T
*shellf
;
3158 if (shell
== NULL
|| shell
[0] == '\0' || wordinclass(user
, 't') ||
3164 ** Naturally IBM has a "better" idea.....
3166 ** What a crock. This interface isn't documented, it is
3167 ** considered part of the security library (-ls), and it
3168 ** only works if you are running as root (since the list
3169 ** of valid shells is obviously a source of great concern).
3170 ** I recommend that you do NOT define USEGETCONFATTR,
3171 ** especially since you are going to have to set up an
3172 ** /etc/shells anyhow to handle the cases where getconfattr
3176 if (getconfattr(SC_SYS_LOGIN
, SC_SHELLS
, &v
, SEC_LIST
) == 0 && v
!= NULL
)
3180 if (strcmp(v
, shell
) == 0 || strcmp(v
, WILDCARD_SHELL
) == 0)
3186 # endif /* USEGETCONFATTR */
3188 shellf
= sm_io_open(SmFtStdio
, SM_TIME_DEFAULT
, _PATH_SHELLS
,
3189 SM_IO_RDONLY
, NULL
);
3192 /* no /etc/shells; see if it is one of the std shells */
3195 if (errno
!= ENOENT
&& LogLevel
> 3)
3196 sm_syslog(LOG_ERR
, NOQID
,
3197 "usershellok: cannot open %s: %s",
3198 _PATH_SHELLS
, sm_errstring(errno
));
3200 for (d
= DefaultUserShells
; *d
!= NULL
; d
++)
3202 if (strcmp(shell
, *d
) == 0)
3208 while (sm_io_fgets(shellf
, SM_TIME_DEFAULT
, buf
, sizeof(buf
)) != NULL
)
3210 register char *p
, *q
;
3213 while (*p
!= '\0' && *p
!= '#' && *p
!= '/')
3215 if (*p
== '#' || *p
== '\0')
3218 while (*p
!= '\0' && *p
!= '#' && !(isascii(*p
) && isspace(*p
)))
3221 if (strcmp(shell
, q
) == 0 || strcmp(WILDCARD_SHELL
, q
) == 0)
3223 (void) sm_io_close(shellf
, SM_TIME_DEFAULT
);
3227 (void) sm_io_close(shellf
, SM_TIME_DEFAULT
);
3229 # endif /* HASGETUSERSHELL */
3232 ** FREEDISKSPACE -- see how much free space is on the queue filesystem
3234 ** Only implemented if you have statfs.
3237 ** dir -- the directory in question.
3238 ** bsize -- a variable into which the filesystem
3239 ** block size is stored.
3242 ** The number of blocks free on the queue filesystem.
3243 ** -1 if the statfs call fails.
3246 ** Puts the filesystem block size into bsize.
3250 # define SFS_NONE 0 /* no statfs implementation */
3251 # define SFS_USTAT 1 /* use ustat */
3252 # define SFS_4ARGS 2 /* use four-argument statfs call */
3253 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */
3254 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
3255 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
3256 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
3259 # define SFS_TYPE SFS_NONE
3260 # endif /* ! SFS_TYPE */
3262 # if SFS_TYPE == SFS_USTAT
3264 # endif /* SFS_TYPE == SFS_USTAT */
3265 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
3266 # include <sys/statfs.h>
3267 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
3268 # if SFS_TYPE == SFS_VFS
3269 # include <sys/vfs.h>
3270 # endif /* SFS_TYPE == SFS_VFS */
3271 # if SFS_TYPE == SFS_MOUNT
3272 # include <sys/mount.h>
3273 # endif /* SFS_TYPE == SFS_MOUNT */
3274 # if SFS_TYPE == SFS_STATVFS
3275 # include <sys/statvfs.h>
3276 # endif /* SFS_TYPE == SFS_STATVFS */
3279 freediskspace(dir
, bsize
)
3283 # if SFS_TYPE == SFS_NONE
3287 /* assume free space is plentiful */
3288 return (long) LONG_MAX
;
3289 # else /* SFS_TYPE == SFS_NONE */
3290 # if SFS_TYPE == SFS_USTAT
3292 struct stat statbuf
;
3293 # define FSBLOCKSIZE DEV_BSIZE
3294 # define SFS_BAVAIL f_tfree
3295 # else /* SFS_TYPE == SFS_USTAT */
3296 # if defined(ultrix)
3298 # define SFS_BAVAIL fd_bfreen
3299 # define FSBLOCKSIZE 1024L
3300 # else /* defined(ultrix) */
3301 # if SFS_TYPE == SFS_STATVFS
3303 # define FSBLOCKSIZE fs.f_frsize
3304 # else /* SFS_TYPE == SFS_STATVFS */
3306 # define FSBLOCKSIZE fs.f_bsize
3307 # endif /* SFS_TYPE == SFS_STATVFS */
3308 # endif /* defined(ultrix) */
3309 # endif /* SFS_TYPE == SFS_USTAT */
3311 # define SFS_BAVAIL f_bavail
3312 # endif /* ! SFS_BAVAIL */
3314 # if SFS_TYPE == SFS_USTAT
3315 if (stat(dir
, &statbuf
) == 0 && ustat(statbuf
.st_dev
, &fs
) == 0)
3316 # else /* SFS_TYPE == SFS_USTAT */
3317 # if SFS_TYPE == SFS_4ARGS
3318 if (statfs(dir
, &fs
, sizeof(fs
), 0) == 0)
3319 # else /* SFS_TYPE == SFS_4ARGS */
3320 # if SFS_TYPE == SFS_STATVFS
3321 if (statvfs(dir
, &fs
) == 0)
3322 # else /* SFS_TYPE == SFS_STATVFS */
3323 # if defined(ultrix)
3324 if (statfs(dir
, &fs
) > 0)
3325 # else /* defined(ultrix) */
3326 if (statfs(dir
, &fs
) == 0)
3327 # endif /* defined(ultrix) */
3328 # endif /* SFS_TYPE == SFS_STATVFS */
3329 # endif /* SFS_TYPE == SFS_4ARGS */
3330 # endif /* SFS_TYPE == SFS_USTAT */
3333 *bsize
= FSBLOCKSIZE
;
3334 if (fs
.SFS_BAVAIL
<= 0)
3336 else if (fs
.SFS_BAVAIL
> LONG_MAX
)
3337 return (long) LONG_MAX
;
3339 return (long) fs
.SFS_BAVAIL
;
3342 # endif /* SFS_TYPE == SFS_NONE */
3345 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
3348 ** msize -- the size to check against. If zero, we don't yet
3349 ** know how big the message will be, so just check for
3350 ** a "reasonable" amount.
3351 ** e -- envelope, or NULL -- controls logging
3354 ** true if in every queue group there is at least one
3355 ** queue directory whose file system contains enough free space.
3359 ** If there is not enough disk space and e != NULL
3360 ** then sm_syslog is called.
3364 enoughdiskspace(msize
, e
)
3370 if (MinBlocksFree
<= 0 && msize
<= 0)
3373 sm_dprintf("enoughdiskspace: no threshold\n");
3378 for (i
= 0; i
< NumQueue
; ++i
)
3380 if (pickqdir(Queue
[i
], msize
, e
) < 0)
3386 ** TRANSIENTERROR -- tell if an error code indicates a transient failure
3388 ** This looks at an errno value and tells if this is likely to
3389 ** go away if retried later.
3392 ** err -- the errno code to classify.
3395 ** true if this is probably transient.
3405 case EIO
: /* I/O error */
3406 case ENXIO
: /* Device not configured */
3407 case EAGAIN
: /* Resource temporarily unavailable */
3408 case ENOMEM
: /* Cannot allocate memory */
3409 case ENODEV
: /* Operation not supported by device */
3410 case ENFILE
: /* Too many open files in system */
3411 case EMFILE
: /* Too many open files */
3412 case ENOSPC
: /* No space left on device */
3413 case ETIMEDOUT
: /* Connection timed out */
3415 case ESTALE
: /* Stale NFS file handle */
3418 case ENETDOWN
: /* Network is down */
3419 #endif /* ENETDOWN */
3421 case ENETUNREACH
: /* Network is unreachable */
3422 #endif /* ENETUNREACH */
3424 case ENETRESET
: /* Network dropped connection on reset */
3425 #endif /* ENETRESET */
3427 case ECONNABORTED
: /* Software caused connection abort */
3428 #endif /* ECONNABORTED */
3430 case ECONNRESET
: /* Connection reset by peer */
3431 #endif /* ECONNRESET */
3433 case ENOBUFS
: /* No buffer space available */
3434 #endif /* ENOBUFS */
3436 case ESHUTDOWN
: /* Can't send after socket shutdown */
3437 #endif /* ESHUTDOWN */
3439 case ECONNREFUSED
: /* Connection refused */
3440 #endif /* ECONNREFUSED */
3442 case EHOSTDOWN
: /* Host is down */
3443 #endif /* EHOSTDOWN */
3445 case EHOSTUNREACH
: /* No route to host */
3446 #endif /* EHOSTUNREACH */
3448 case EDQUOT
: /* Disc quota exceeded */
3451 case EPROCLIM
: /* Too many processes */
3452 #endif /* EPROCLIM */
3454 case EUSERS
: /* Too many users */
3457 case EDEADLK
: /* Resource deadlock avoided */
3458 #endif /* EDEADLK */
3460 case EISCONN
: /* Socket already connected */
3461 #endif /* EISCONN */
3463 case EINPROGRESS
: /* Operation now in progress */
3464 #endif /* EINPROGRESS */
3466 case EALREADY
: /* Operation already in progress */
3467 #endif /* EALREADY */
3469 case EADDRINUSE
: /* Address already in use */
3470 #endif /* EADDRINUSE */
3471 #ifdef EADDRNOTAVAIL
3472 case EADDRNOTAVAIL
: /* Can't assign requested address */
3473 #endif /* EADDRNOTAVAIL */
3475 case ETXTBSY
: /* (Apollo) file locked */
3476 #endif /* ETXTBSY */
3477 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
3478 case ENOSR
: /* Out of streams resources */
3479 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
3481 case ENOLCK
: /* No locks available */
3483 case E_SM_OPENTIMEOUT
: /* PSEUDO: open timed out */
3487 /* nope, must be permanent */
3491 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
3494 ** fd -- the file descriptor of the file.
3495 ** filename -- the file name (for error messages).
3496 ** ext -- the filename extension.
3497 ** type -- type of the lock. Bits can be:
3498 ** LOCK_EX -- exclusive lock.
3499 ** LOCK_NB -- non-blocking.
3500 ** LOCK_UN -- unlock.
3503 ** true if the lock was acquired.
3508 lockfile(fd
, filename
, ext
, type
)
3523 memset(&lfd
, '\0', sizeof(lfd
));
3524 if (bitset(LOCK_UN
, type
))
3525 lfd
.l_type
= F_UNLCK
;
3526 else if (bitset(LOCK_EX
, type
))
3527 lfd
.l_type
= F_WRLCK
;
3529 lfd
.l_type
= F_RDLCK
;
3531 if (bitset(LOCK_NB
, type
))
3537 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
3538 filename
, ext
, action
, lfd
.l_type
);
3540 while ((i
= fcntl(fd
, action
, &lfd
)) < 0 && errno
== EINTR
)
3545 sm_dprintf("SUCCESS\n");
3551 sm_dprintf("(%s) ", sm_errstring(save_errno
));
3554 ** On SunOS, if you are testing using -oQ/tmp/mqueue or
3555 ** -oA/tmp/aliases or anything like that, and /tmp is mounted
3556 ** as type "tmp" (that is, served from swap space), the
3557 ** previous fcntl will fail with "Invalid argument" errors.
3558 ** Since this is fairly common during testing, we will assume
3559 ** that this indicates that the lock is successfully grabbed.
3562 if (save_errno
== EINVAL
)
3565 sm_dprintf("SUCCESS\n");
3569 if (!bitset(LOCK_NB
, type
) ||
3570 (save_errno
!= EACCES
&& save_errno
!= EAGAIN
))
3572 int omode
= fcntl(fd
, F_GETFL
, 0);
3573 uid_t euid
= geteuid();
3576 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3577 filename
, ext
, fd
, type
, omode
, euid
);
3578 dumpfd(fd
, true, true);
3580 # else /* !HASFLOCK */
3585 sm_dprintf("lockfile(%s%s, type=%o): ", filename
, ext
, type
);
3587 while ((i
= flock(fd
, type
)) < 0 && errno
== EINTR
)
3592 sm_dprintf("SUCCESS\n");
3598 sm_dprintf("(%s) ", sm_errstring(save_errno
));
3600 if (!bitset(LOCK_NB
, type
) || save_errno
!= EWOULDBLOCK
)
3602 int omode
= fcntl(fd
, F_GETFL
, 0);
3603 uid_t euid
= geteuid();
3606 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
3607 filename
, ext
, fd
, type
, omode
, euid
);
3608 dumpfd(fd
, true, true);
3610 # endif /* !HASFLOCK */
3612 sm_dprintf("FAIL\n");
3617 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
3619 ** Unfortunately, given that we can't predict other systems on which
3620 ** a remote mounted (NFS) filesystem will be mounted, the answer is
3621 ** almost always that this is unsafe.
3623 ** Note also that many operating systems have non-compliant
3624 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
3625 ** fpathconf() routine. According to IEEE 1003.1-1990, if
3626 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
3627 ** no non-root process can give away the file. However, vendors
3628 ** don't take NFS into account, so a comfortable value of
3629 ** _POSIX_CHOWN_RESTRICTED tells us nothing.
3631 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
3632 ** even on files where chown is not restricted. Many systems get
3633 ** this wrong on NFS-based filesystems (that is, they say that chown
3634 ** is restricted [safe] on NFS filesystems where it may not be, since
3635 ** other systems can access the same filesystem and do file giveaway;
3636 ** only the NFS server knows for sure!) Hence, it is important to
3637 ** get the value of SAFENFSPATHCONF correct -- it should be defined
3638 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
3639 ** NFS-based filesystem to ensure that you can get meaningful results.
3640 ** If in doubt, assume unsafe!
3642 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a
3643 ** condition indicating whether the return from pathconf indicates
3644 ** that chown is safe (typically either > 0 or >= 0 -- there isn't
3645 ** even any agreement about whether a zero return means that a file
3646 ** is or is not safe). It defaults to "> 0".
3648 ** If the parent directory is safe (writable only by owner back
3649 ** to the root) then we can relax slightly and trust fpathconf
3650 ** in more circumstances. This is really a crock -- if this is an
3651 ** NFS mounted filesystem then we really know nothing about the
3652 ** underlying implementation. However, most systems pessimize and
3653 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
3654 ** we interpret as unsafe, as we should. Thus, this heuristic gets
3655 ** us into a possible problem only on systems that have a broken
3656 ** pathconf implementation and which are also poorly configured
3657 ** (have :include: files in group- or world-writable directories).
3660 ** fd -- the file descriptor to check.
3661 ** safedir -- set if the parent directory is safe.
3664 ** true -- if the chown(2) operation is "safe" -- that is,
3665 ** only root can chown the file to an arbitrary user.
3666 ** false -- if an arbitrary user can give away a file.
3669 #ifndef IS_SAFE_CHOWN
3670 # define IS_SAFE_CHOWN > 0
3671 #endif /* ! IS_SAFE_CHOWN */
3674 chownsafe(fd
, safedir
)
3678 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
3679 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
3682 /* give the system administrator a chance to override */
3683 if (bitnset(DBS_ASSUMESAFECHOWN
, DontBlameSendmail
))
3687 ** Some systems (e.g., SunOS) seem to have the call and the
3688 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement
3689 ** the call. This heuristic checks for that.
3693 rval
= fpathconf(fd
, _PC_CHOWN_RESTRICTED
);
3694 # if SAFENFSPATHCONF
3695 return errno
== 0 && rval IS_SAFE_CHOWN
;
3696 # else /* SAFENFSPATHCONF */
3697 return safedir
&& errno
== 0 && rval IS_SAFE_CHOWN
;
3698 # endif /* SAFENFSPATHCONF */
3699 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3700 return bitnset(DBS_ASSUMESAFECHOWN
, DontBlameSendmail
);
3701 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
3704 ** RESETLIMITS -- reset system controlled resource limits
3706 ** This is to avoid denial-of-service attacks
3716 # ifdef RLIMIT_NEEDS_SYS_TIME_H
3717 # include <sm/time.h>
3718 # endif /* RLIMIT_NEEDS_SYS_TIME_H */
3719 # include <sys/resource.h>
3720 #endif /* HASSETRLIMIT */
3728 lim
.rlim_cur
= lim
.rlim_max
= RLIM_INFINITY
;
3729 (void) setrlimit(RLIMIT_CPU
, &lim
);
3730 (void) setrlimit(RLIMIT_FSIZE
, &lim
);
3731 # ifdef RLIMIT_NOFILE
3732 lim
.rlim_cur
= lim
.rlim_max
= FD_SETSIZE
;
3733 (void) setrlimit(RLIMIT_NOFILE
, &lim
);
3734 # endif /* RLIMIT_NOFILE */
3735 #else /* HASSETRLIMIT */
3737 (void) ulimit(2, 0x3fffff);
3738 (void) ulimit(4, FD_SETSIZE
);
3739 # endif /* HASULIMIT */
3740 #endif /* HASSETRLIMIT */
3744 ** SETVENDOR -- process vendor code from V configuration line
3747 ** vendor -- string representation of vendor.
3751 ** false -- if vendor code could not be processed.
3754 ** It is reasonable to set mode flags here to tweak
3755 ** processing in other parts of the code if necessary.
3756 ** For example, if you are a vendor that uses $%y to
3757 ** indicate YP lookups, you could enable that here.
3764 if (sm_strcasecmp(vendor
, "Berkeley") == 0)
3766 VendorCode
= VENDOR_BERKELEY
;
3770 /* add vendor extensions here */
3772 #ifdef SUN_EXTENSIONS
3773 if (sm_strcasecmp(vendor
, "Sun") == 0)
3775 VendorCode
= VENDOR_SUN
;
3778 #endif /* SUN_EXTENSIONS */
3780 if (sm_strcasecmp(vendor
, "Digital") == 0)
3782 VendorCode
= VENDOR_DEC
;
3787 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3788 if (sm_strcasecmp(vendor
, VENDOR_NAME
) == 0)
3790 VendorCode
= VENDOR_CODE
;
3793 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3798 ** GETVENDOR -- return vendor name based on vendor code
3801 ** vendorcode -- numeric representation of vendor.
3804 ** string containing vendor name.
3808 getvendor(vendorcode
)
3811 #if defined(VENDOR_NAME) && defined(VENDOR_CODE)
3813 ** Can't have the same switch case twice so need to
3814 ** handle VENDOR_CODE outside of switch. It might
3815 ** match one of the existing VENDOR_* codes.
3818 if (vendorcode
== VENDOR_CODE
)
3820 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
3824 case VENDOR_BERKELEY
:
3836 case VENDOR_SENDMAIL
:
3844 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
3846 ** Vendor_pre_defaults is called before reading the configuration
3847 ** file; vendor_post_defaults is called immediately after.
3850 ** e -- the global environment to initialize.
3857 int DefShareUid
; /* default share uid to run as -- unused??? */
3858 #endif /* SHARE_V1 */
3861 vendor_pre_defaults(e
)
3865 /* OTHERUID is defined in shares.h, do not be alarmed */
3866 DefShareUid
= OTHERUID
;
3867 #endif /* SHARE_V1 */
3868 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3869 sun_pre_defaults(e
);
3870 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3873 ** stupid domain/os can't even open
3874 ** /etc/mail/sendmail.cf without this
3877 sm_setuserenv("ISP", NULL
);
3878 sm_setuserenv("SYSTYPE", NULL
);
3884 vendor_post_defaults(e
)
3888 /* Makes sure the SOCK environment variable remains */
3889 sm_setuserenv("SOCK", NULL
);
3890 #endif /* __QNX__ */
3891 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
3892 sun_post_defaults(e
);
3893 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
3896 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
3900 vendor_daemon_setup(e
)
3904 (void) setlogin(RunAsUserName
);
3905 #endif /* HASSETLOGIN */
3907 if (getluid() != -1)
3909 usrerr("Daemon cannot have LUID");
3910 finis(false, true, EX_USAGE
);
3912 #endif /* SECUREWARE */
3915 ** VENDOR_SET_UID -- do setup for setting a user id
3917 ** This is called when we are still root.
3920 ** uid -- the uid we are about to become.
3931 ** We need to setup the share groups (lnodes)
3932 ** and add auditing information (luid's)
3933 ** before we loose our ``root''ness.
3936 if (setupshares(uid
, syserr
) != 0)
3937 syserr("Unable to set up shares");
3938 #endif /* SHARE_V1 */
3940 (void) setup_secure(uid
);
3941 #endif /* SECUREWARE */
3944 ** VALIDATE_CONNECTION -- check connection for rationality
3946 ** If the connection is rejected, this routine should log an
3947 ** appropriate message -- but should never issue any SMTP protocol.
3950 ** sap -- a pointer to a SOCKADDR naming the peer.
3951 ** hostname -- the name corresponding to sap.
3952 ** e -- the current envelope.
3955 ** error message from rejection.
3956 ** NULL if not rejected.
3962 /* tcpwrappers does no logging, but you still have to declare these -- ugh */
3963 int allow_severity
= LOG_INFO
;
3964 int deny_severity
= LOG_NOTICE
;
3965 #endif /* TCPWRAPPERS */
3968 validate_connection(sap
, hostname
, e
)
3976 extern int hosts_ctl();
3977 #endif /* TCPWRAPPERS */
3980 sm_dprintf("validate_connection(%s, %s)\n",
3981 hostname
, anynet_ntoa(sap
));
3983 connection_rate_check(sap
, e
);
3984 if (rscheck("check_relay", hostname
, anynet_ntoa(sap
),
3985 e
, RSF_RMCOMM
|RSF_COUNT
, 3, NULL
, NOQID
, NULL
) != EX_OK
)
3987 static char reject
[BUFSIZ
*2];
3988 extern char MsgBuf
[];
3991 sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
3993 if (strlen(MsgBuf
) >= 3)
3994 (void) sm_strlcpy(reject
, MsgBuf
, sizeof(reject
));
3996 (void) sm_strlcpy(reject
, "Access denied", sizeof(reject
));
4002 if (hostname
[0] == '[' && hostname
[strlen(hostname
) - 1] == ']')
4006 addr
= anynet_ntoa(sap
);
4009 /* TCP/Wrappers don't want the IPv6: protocol label */
4010 if (addr
!= NULL
&& sm_strncasecmp(addr
, "IPv6:", 5) == 0)
4012 # endif /* NETINET6 */
4014 if (!hosts_ctl("sendmail", host
, addr
, STRING_UNKNOWN
))
4017 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
4019 sm_syslog(LOG_NOTICE
, e
->e_id
,
4020 "tcpwrappers (%s, %s) rejection",
4022 return "Access denied";
4024 #endif /* TCPWRAPPERS */
4026 sm_dprintf(" ... validate_connection: OK\n");
4031 ** STRTOL -- convert string to long integer
4033 ** For systems that don't have it in the C library.
4035 ** This is taken verbatim from the 4.4-Lite C library.
4040 # if defined(LIBC_SCCS) && !defined(lint)
4041 static char sccsid
[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
4042 # endif /* defined(LIBC_SCCS) && !defined(lint) */
4045 ** Convert a string to a long integer.
4047 ** Ignores `locale' stuff. Assumes that the upper and lower case
4048 ** alphabets and digits are each contiguous.
4052 strtol(nptr
, endptr
, base
)
4057 register const char *s
= nptr
;
4058 register unsigned long acc
;
4060 register unsigned long cutoff
;
4061 register int neg
= 0, any
, cutlim
;
4064 ** Skip white space and pick up leading +/- sign if any.
4065 ** If base is 0, allow 0x for hex and 0 for octal, else
4066 ** assume decimal; if base is already 16, allow 0x.
4070 } while (isspace(c
));
4074 } else if (c
== '+')
4076 if ((base
== 0 || base
== 16) &&
4077 c
== '0' && (*s
== 'x' || *s
== 'X')) {
4083 base
= c
== '0' ? 8 : 10;
4086 ** Compute the cutoff value between legal numbers and illegal
4087 ** numbers. That is the largest legal value, divided by the
4088 ** base. An input number that is greater than this value, if
4089 ** followed by a legal input character, is too big. One that
4090 ** is equal to this value may be valid or not; the limit
4091 ** between valid and invalid numbers is then based on the last
4092 ** digit. For instance, if the range for longs is
4093 ** [-2147483648..2147483647] and the input base is 10,
4094 ** cutoff will be set to 214748364 and cutlim to either
4095 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
4096 ** a value > 214748364, or equal but the next digit is > 7 (or 8),
4097 ** the number is too big, and we will return a range error.
4099 ** Set any if any `digits' consumed; make it negative to indicate
4102 cutoff
= neg
? -(unsigned long) LONG_MIN
: LONG_MAX
;
4103 cutlim
= cutoff
% (unsigned long) base
;
4104 cutoff
/= (unsigned long) base
;
4105 for (acc
= 0, any
= 0;; c
= *s
++) {
4108 else if (isalpha(c
))
4109 c
-= isupper(c
) ? 'A' - 10 : 'a' - 10;
4114 if (any
< 0 || acc
> cutoff
|| acc
== cutoff
&& c
> cutlim
)
4123 acc
= neg
? LONG_MIN
: LONG_MAX
;
4128 *endptr
= (char *)(any
? s
- 1 : nptr
);
4132 #endif /* NEEDSTRTOL */
4134 ** STRSTR -- find first substring in string
4137 ** big -- the big (full) string.
4138 ** little -- the little (sub) string.
4141 ** A pointer to the first instance of little in big.
4142 ** big if little is the null string.
4143 ** NULL if little is not contained in big.
4153 register char *p
= big
;
4156 if (*little
== '\0')
4160 while ((p
= strchr(p
, *little
)) != NULL
)
4162 if (strncmp(p
, little
, l
) == 0)
4169 #endif /* NEEDSTRSTR */
4171 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
4173 ** Some operating systems have wierd problems with the gethostbyXXX
4174 ** routines. For example, Solaris versions at least through 2.3
4175 ** don't properly deliver a canonical h_name field. This tries to
4176 ** work around these problems.
4178 ** Support IPv6 as well as IPv4.
4181 #if NETINET6 && NEEDSGETIPNODE
4184 # define AI_DEFAULT 0 /* dummy */
4185 # endif /* ! AI_DEFAULT */
4186 # ifndef AI_ADDRCONFIG
4187 # define AI_ADDRCONFIG 0 /* dummy */
4188 # endif /* ! AI_ADDRCONFIG */
4189 # ifndef AI_V4MAPPED
4190 # define AI_V4MAPPED 0 /* dummy */
4191 # endif /* ! AI_V4MAPPED */
4193 # define AI_ALL 0 /* dummy */
4194 # endif /* ! AI_ALL */
4196 static struct hostent
*
4197 getipnodebyname(name
, family
, flags
, err
)
4206 if (family
== AF_INET6
)
4208 /* From RFC2133, section 6.1 */
4209 resv6
= bitset(RES_USE_INET6
, _res
.options
);
4210 _res
.options
|= RES_USE_INET6
;
4213 h
= gethostbyname(name
);
4215 _res
.options
&= ~RES_USE_INET6
;
4220 static struct hostent
*
4221 getipnodebyaddr(addr
, len
, family
, err
)
4230 h
= gethostbyaddr(addr
, len
, family
);
4240 ** Stub routine -- if they don't have getipnodeby*(),
4241 ** they probably don't have the free routine either.
4246 #endif /* NETINET6 && NEEDSGETIPNODE */
4249 sm_gethostbyname(name
, family
)
4254 struct hostent
*h
= NULL
;
4255 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
4256 # if SOLARIS == 20300 || SOLARIS == 203
4257 static struct hostent hp
;
4258 static char buf
[1000];
4259 extern struct hostent
*_switch_gethostbyname_r();
4262 sm_dprintf("_switch_gethostbyname_r(%s)... ", name
);
4263 h
= _switch_gethostbyname_r(name
, &hp
, buf
, sizeof(buf
), &h_errno
);
4265 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4266 extern struct hostent
*__switch_gethostbyname();
4269 sm_dprintf("__switch_gethostbyname(%s)... ", name
);
4270 h
= __switch_gethostbyname(name
);
4272 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4273 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4276 int flags
= AI_DEFAULT
|AI_ALL
;
4278 # endif /* NETINET6 */
4279 char *maptype
[MAXMAPSTACK
];
4280 short mapreturn
[MAXMAPACTIONS
];
4284 sm_dprintf("sm_gethostbyname(%s, %d)... ", name
, family
);
4287 # if ADDRCONFIG_IS_BROKEN
4288 flags
&= ~AI_ADDRCONFIG
;
4289 # endif /* ADDRCONFIG_IS_BROKEN */
4290 h
= getipnodebyname(name
, family
, flags
, &err
);
4291 SM_SET_H_ERRNO(err
);
4292 # else /* NETINET6 */
4293 h
= gethostbyname(name
);
4294 # endif /* NETINET6 */
4300 sm_dprintf("failure\n");
4302 nmaps
= switch_map_find("hosts", maptype
, mapreturn
);
4303 while (--nmaps
>= 0)
4305 if (strcmp(maptype
[nmaps
], "nis") == 0 ||
4306 strcmp(maptype
[nmaps
], "files") == 0)
4312 /* try short name */
4313 if (strlen(name
) > sizeof(hbuf
) - 1)
4318 (void) sm_strlcpy(hbuf
, name
, sizeof(hbuf
));
4319 (void) shorten_hostname(hbuf
);
4321 /* if it hasn't been shortened, there's no point */
4322 if (strcmp(hbuf
, name
) != 0)
4325 sm_dprintf("sm_gethostbyname(%s, %d)... ",
4329 h
= getipnodebyname(hbuf
, family
, flags
, &err
);
4330 SM_SET_H_ERRNO(err
);
4332 # else /* NETINET6 */
4333 h
= gethostbyname(hbuf
);
4335 # endif /* NETINET6 */
4339 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
4343 sm_dprintf("failure\n");
4346 sm_dprintf("%s\n", h
->h_name
);
4350 struct in6_addr ia6
;
4351 char buf6
[INET6_ADDRSTRLEN
];
4352 #else /* NETINET6 */
4354 #endif /* NETINET6 */
4357 if (h
->h_aliases
!= NULL
)
4358 for (i
= 0; h
->h_aliases
[i
] != NULL
;
4360 sm_dprintf("\talias: %s\n",
4362 for (i
= 0; h
->h_addr_list
[i
] != NULL
; i
++)
4367 memmove(&ia6
, h
->h_addr_list
[i
],
4369 addr
= anynet_ntop(&ia6
,
4370 buf6
, sizeof(buf6
));
4371 #else /* NETINET6 */
4372 memmove(&ia
, h
->h_addr_list
[i
],
4374 addr
= (char *) inet_ntoa(ia
);
4375 #endif /* NETINET6 */
4377 sm_dprintf("\taddr: %s\n", addr
);
4387 sm_gethostbyaddr(addr
, len
, type
)
4395 if (type
== AF_INET6
&&
4396 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr
*) addr
))
4398 /* Avoid reverse lookup for IPv6 unspecified address */
4399 SM_SET_H_ERRNO(HOST_NOT_FOUND
);
4402 #endif /* NETINET6 */
4404 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
4405 # if SOLARIS == 20300 || SOLARIS == 203
4407 static struct hostent he
;
4408 static char buf
[1000];
4409 extern struct hostent
*_switch_gethostbyaddr_r();
4411 hp
= _switch_gethostbyaddr_r(addr
, len
, type
, &he
,
4412 buf
, sizeof(buf
), &h_errno
);
4414 # else /* SOLARIS == 20300 || SOLARIS == 203 */
4416 extern struct hostent
*__switch_gethostbyaddr();
4418 hp
= __switch_gethostbyaddr(addr
, len
, type
);
4420 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
4421 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4426 hp
= getipnodebyaddr(addr
, len
, type
, &err
);
4427 SM_SET_H_ERRNO(err
);
4429 # else /* NETINET6 */
4430 hp
= gethostbyaddr(addr
, len
, type
);
4431 # endif /* NETINET6 */
4432 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
4436 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
4444 extern struct passwd
*_getpwnam_shadow(const char *, const int);
4446 return _getpwnam_shadow(user
, 0);
4448 return getpwnam(user
);
4456 #if defined(_AIX4) && 0
4457 extern struct passwd
*_getpwuid_shadow(const int, const int);
4459 return _getpwuid_shadow(uid
,0);
4460 #else /* defined(_AIX4) && 0 */
4461 return getpwuid(uid
);
4462 #endif /* defined(_AIX4) && 0 */
4465 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
4467 ** Set up the trusted computing environment for C2 level security
4468 ** under SecureWare.
4471 ** uid -- uid of the user to initialize in the TCB
4477 ** Initialized the user in the trusted computing base
4482 # include <sys/security.h>
4486 secureware_setup_secure(uid
)
4491 if (getluid() != -1)
4494 if ((rc
= set_secure_info(uid
)) != SSI_GOOD_RETURN
)
4498 case SSI_NO_PRPW_ENTRY
:
4499 syserr("No protected passwd entry, uid = %d",
4504 syserr("Account has been disabled, uid = %d",
4509 syserr("Account has been retired, uid = %d",
4513 case SSI_BAD_SET_LUID
:
4514 syserr("Could not set LUID, uid = %d", (int) uid
);
4517 case SSI_BAD_SET_PRIVS
:
4518 syserr("Could not set kernel privs, uid = %d",
4522 syserr("Unknown return code (%d) from set_secure_info(%d)",
4526 finis(false, true, EX_NOPERM
);
4529 #endif /* SECUREWARE */
4531 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
4533 ** Add hostnames to class 'w' based on the IP address read from
4534 ** the network interface.
4537 ** sa -- a pointer to a SOCKADDR containing the address
4540 ** 0 if successful, -1 if host lookup fails.
4549 char hnb
[MAXHOSTNAMELEN
];
4551 /* lookup name with IP address */
4552 switch (sa
->sa
.sa_family
)
4556 hp
= sm_gethostbyaddr((char *) &sa
->sin
.sin_addr
,
4557 sizeof(sa
->sin
.sin_addr
),
4560 #endif /* NETINET */
4564 hp
= sm_gethostbyaddr((char *) &sa
->sin6
.sin6_addr
,
4565 sizeof(sa
->sin6
.sin6_addr
),
4568 #endif /* NETINET6 */
4571 /* Give warning about unsupported family */
4573 sm_syslog(LOG_WARNING
, NOQID
,
4574 "Unsupported address family %d: %.100s",
4575 sa
->sa
.sa_family
, anynet_ntoa(sa
));
4581 int save_errno
= errno
;
4585 !(sa
->sa
.sa_family
== AF_INET6
&&
4586 IN6_IS_ADDR_LINKLOCAL(&sa
->sin6
.sin6_addr
)) &&
4587 #endif /* NETINET6 */
4589 sm_syslog(LOG_WARNING
, NOQID
,
4590 "gethostbyaddr(%.100s) failed: %d",
4594 #else /* NAMED_BIND */
4596 #endif /* NAMED_BIND */
4602 /* save its cname */
4603 if (!wordinclass((char *) hp
->h_name
, 'w'))
4605 setclass('w', (char *) hp
->h_name
);
4607 sm_dprintf("\ta.k.a.: %s\n", hp
->h_name
);
4609 if (sm_snprintf(hnb
, sizeof(hnb
), "[%s]", hp
->h_name
) <
4611 && !wordinclass((char *) hnb
, 'w'))
4617 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp
->h_name
);
4620 /* save all it aliases name */
4621 for (ha
= hp
->h_aliases
; ha
!= NULL
&& *ha
!= NULL
; ha
++)
4623 if (!wordinclass(*ha
, 'w'))
4627 sm_dprintf("\ta.k.a.: %s\n", *ha
);
4628 if (sm_snprintf(hnb
, sizeof(hnb
),
4629 "[%s]", *ha
) < sizeof(hnb
) &&
4630 !wordinclass((char *) hnb
, 'w'))
4636 sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
4642 #endif /* NETINET6 */
4646 ** LOAD_IF_NAMES -- load interface-specific names into $=w
4655 ** Loads $=w with the names of all the interfaces.
4659 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
4660 #endif /* !NETINET */
4662 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4666 # include <sm/time.h>
4667 # endif /* ! SUNOS403 */
4668 # if (_AIX4 >= 40300) && !defined(_NET_IF_H)
4670 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
4671 # include <net/if.h>
4672 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
4677 # if NETINET6 && defined(SIOCGLIFCONF)
4681 ** Unfortunately, HP has changed all of the structures,
4682 ** making life difficult for implementors.
4685 # define lifconf if_laddrconf
4686 # define lifc_len iflc_len
4687 # define lifc_buf iflc_buf
4688 # define lifreq if_laddrreq
4689 # define lifr_addr iflr_addr
4690 # define lifr_name iflr_name
4691 # define lifr_flags iflr_flags
4692 # define ss_family sa_family
4694 # endif /* __hpux */
4701 struct lifconf lifc
;
4704 # endif /* SIOCGLIFNUM */
4706 s
= socket(InetMode
, SOCK_DGRAM
, 0);
4710 /* get the list of known IP address from the kernel */
4712 i
= ioctl(s
, SIOCGIFNUM
, (char *) &numifs
);
4713 # endif /* __hpux */
4715 lifn
.lifn_family
= AF_UNSPEC
;
4716 lifn
.lifn_flags
= 0;
4717 i
= ioctl(s
, SIOCGLIFNUM
, (char *)&lifn
);
4718 numifs
= lifn
.lifn_count
;
4719 # endif /* SIOCGLIFNUM */
4721 # if defined(__hpux) || defined(SIOCGLIFNUM)
4724 /* can't get number of interfaces -- fall back */
4726 sm_dprintf("SIOCGLIFNUM failed: %s\n",
4727 sm_errstring(errno
));
4730 else if (tTd(0, 42))
4731 sm_dprintf("system has %d interfaces\n", numifs
);
4733 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
4734 numifs
= MAXINTERFACES
;
4742 len
= lifc
.lifc_len
= numifs
* sizeof(struct lifreq
);
4743 buf
= lifc
.lifc_buf
= xalloc(lifc
.lifc_len
);
4745 lifc
.lifc_family
= AF_UNSPEC
;
4746 lifc
.lifc_flags
= 0;
4747 # endif /* ! __hpux */
4748 if (ioctl(s
, SIOCGLIFCONF
, (char *)&lifc
) < 0)
4751 sm_dprintf("SIOCGLIFCONF failed: %s\n",
4752 sm_errstring(errno
));
4758 /* scan the list of IP address */
4760 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
4763 for (i
= 0; i
< len
&& i
>= 0; )
4766 struct lifreq
*ifr
= (struct lifreq
*)&buf
[i
];
4767 SOCKADDR
*sa
= (SOCKADDR
*) &ifr
->lifr_addr
;
4768 int af
= ifr
->lifr_addr
.ss_family
;
4771 struct in6_addr ia6
;
4773 # ifdef SIOCGLIFFLAGS
4775 # endif /* SIOCGLIFFLAGS */
4777 char buf6
[INET6_ADDRSTRLEN
];
4780 ** We must close and recreate the socket each time
4781 ** since we don't know what type of socket it is now
4782 ** (each status function may change it).
4787 s
= socket(af
, SOCK_DGRAM
, 0);
4790 sm_free(buf
); /* XXX */
4795 ** If we don't have a complete ifr structure,
4796 ** don't try to use it.
4799 if ((len
- i
) < sizeof(*ifr
))
4802 # ifdef BSD4_4_SOCKADDR
4803 if (sa
->sa
.sa_len
> sizeof(ifr
->lifr_addr
))
4804 i
+= sizeof(ifr
->lifr_name
) + sa
->sa
.sa_len
;
4806 # endif /* BSD4_4_SOCKADDR */
4808 /* fix for IPv6 size differences */
4809 i
+= sizeof(ifr
->ifr_name
) +
4810 max(sizeof(ifr
->ifr_addr
), ifr
->ifr_addr
.sa_len
);
4816 sm_dprintf("%s\n", anynet_ntoa(sa
));
4818 if (af
!= AF_INET
&& af
!= AF_INET6
)
4821 # ifdef SIOCGLIFFLAGS
4822 memset(&ifrf
, '\0', sizeof(struct lifreq
));
4823 (void) sm_strlcpy(ifrf
.lifr_name
, ifr
->lifr_name
,
4824 sizeof(ifrf
.lifr_name
));
4825 if (ioctl(s
, SIOCGLIFFLAGS
, (char *) &ifrf
) < 0)
4828 sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
4829 sm_errstring(errno
));
4833 name
= ifr
->lifr_name
;
4834 flags
= ifrf
.lifr_flags
;
4837 sm_dprintf("\tflags: %lx\n", (unsigned long) flags
);
4839 if (!bitset(IFF_UP
, flags
))
4841 # endif /* SIOCGLIFFLAGS */
4845 /* extract IP address from the list*/
4850 /* convert into proper scoped address */
4851 if ((IN6_IS_ADDR_LINKLOCAL(&sa
->sin6
.sin6_addr
) ||
4852 IN6_IS_ADDR_SITELOCAL(&sa
->sin6
.sin6_addr
)) &&
4853 sa
->sin6
.sin6_scope_id
== 0)
4855 struct in6_addr
*ia6p
;
4857 ia6p
= &sa
->sin6
.sin6_addr
;
4858 sa
->sin6
.sin6_scope_id
= ntohs(ia6p
->s6_addr
[3] |
4859 ((unsigned int)ia6p
->s6_addr
[2] << 8));
4860 ia6p
->s6_addr
[2] = ia6p
->s6_addr
[3] = 0;
4862 # endif /* __KAME__ */
4863 ia6
= sa
->sin6
.sin6_addr
;
4864 if (IN6_IS_ADDR_UNSPECIFIED(&ia6
))
4866 addr
= anynet_ntop(&ia6
, buf6
, sizeof(buf6
));
4867 message("WARNING: interface %s is UP with %s address",
4868 name
, addr
== NULL
? "(NULL)" : addr
);
4872 /* save IP address in text from */
4873 addr
= anynet_ntop(&ia6
, buf6
, sizeof(buf6
));
4875 (void) sm_snprintf(ip_addr
, sizeof(ip_addr
),
4877 (int) sizeof(ip_addr
) - 3,
4882 ia
= sa
->sin
.sin_addr
;
4883 if (ia
.s_addr
== INADDR_ANY
||
4884 ia
.s_addr
== INADDR_NONE
)
4886 message("WARNING: interface %s is UP with %s address",
4887 name
, inet_ntoa(ia
));
4891 /* save IP address in text from */
4892 (void) sm_snprintf(ip_addr
, sizeof(ip_addr
), "[%.*s]",
4893 (int) sizeof(ip_addr
) - 3, inet_ntoa(ia
));
4897 if (*ip_addr
== '\0')
4900 if (!wordinclass(ip_addr
, 'w'))
4902 setclass('w', ip_addr
);
4904 sm_dprintf("\ta.k.a.: %s\n", ip_addr
);
4907 # ifdef SIOCGLIFFLAGS
4908 /* skip "loopback" interface "lo" */
4909 if (DontProbeInterfaces
== DPI_SKIPLOOPBACK
&&
4910 bitset(IFF_LOOPBACK
, flags
))
4912 # endif /* SIOCGLIFFLAGS */
4913 (void) add_hostnames(sa
);
4915 sm_free(buf
); /* XXX */
4917 # else /* NETINET6 && defined(SIOCGLIFCONF) */
4918 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
4924 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
4928 /* get the list of known IP address from the kernel */
4929 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
4930 if (ioctl(s
, SIOCGIFNUM
, (char *) &numifs
) < 0)
4932 /* can't get number of interfaces -- fall back */
4934 sm_dprintf("SIOCGIFNUM failed: %s\n",
4935 sm_errstring(errno
));
4938 else if (tTd(0, 42))
4939 sm_dprintf("system has %d interfaces\n", numifs
);
4941 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
4942 numifs
= MAXINTERFACES
;
4949 ifc
.ifc_len
= numifs
* sizeof(struct ifreq
);
4950 ifc
.ifc_buf
= xalloc(ifc
.ifc_len
);
4951 if (ioctl(s
, SIOCGIFCONF
, (char *)&ifc
) < 0)
4954 sm_dprintf("SIOCGIFCONF failed: %s\n",
4955 sm_errstring(errno
));
4960 /* scan the list of IP address */
4962 sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
4965 for (i
= 0; i
< ifc
.ifc_len
&& i
>= 0; )
4968 struct ifreq
*ifr
= (struct ifreq
*) &ifc
.ifc_buf
[i
];
4969 SOCKADDR
*sa
= (SOCKADDR
*) &ifr
->ifr_addr
;
4972 struct in6_addr ia6
;
4973 # endif /* NETINET6 */
4975 # ifdef SIOCGIFFLAGS
4977 # endif /* SIOCGIFFLAGS */
4980 char buf6
[INET6_ADDRSTRLEN
];
4981 # endif /* NETINET6 */
4984 ** If we don't have a complete ifr structure,
4985 ** don't try to use it.
4988 if ((ifc
.ifc_len
- i
) < sizeof(*ifr
))
4991 # ifdef BSD4_4_SOCKADDR
4992 if (sa
->sa
.sa_len
> sizeof(ifr
->ifr_addr
))
4993 i
+= sizeof(ifr
->ifr_name
) + sa
->sa
.sa_len
;
4995 # endif /* BSD4_4_SOCKADDR */
4999 sm_dprintf("%s\n", anynet_ntoa(sa
));
5001 af
= ifr
->ifr_addr
.sa_family
;
5005 # endif /* NETINET6 */
5009 # ifdef SIOCGIFFLAGS
5010 memset(&ifrf
, '\0', sizeof(struct ifreq
));
5011 (void) sm_strlcpy(ifrf
.ifr_name
, ifr
->ifr_name
,
5012 sizeof(ifrf
.ifr_name
));
5013 (void) ioctl(s
, SIOCGIFFLAGS
, (char *) &ifrf
);
5015 sm_dprintf("\tflags: %lx\n",
5016 (unsigned long) ifrf
.ifr_flags
);
5017 # define IFRFREF ifrf
5018 # else /* SIOCGIFFLAGS */
5019 # define IFRFREF (*ifr)
5020 # endif /* SIOCGIFFLAGS */
5022 if (!bitset(IFF_UP
, IFRFREF
.ifr_flags
))
5027 /* extract IP address from the list*/
5031 ia
= sa
->sin
.sin_addr
;
5032 if (ia
.s_addr
== INADDR_ANY
||
5033 ia
.s_addr
== INADDR_NONE
)
5035 message("WARNING: interface %s is UP with %s address",
5036 ifr
->ifr_name
, inet_ntoa(ia
));
5040 /* save IP address in text from */
5041 (void) sm_snprintf(ip_addr
, sizeof(ip_addr
), "[%.*s]",
5042 (int) sizeof(ip_addr
) - 3,
5049 /* convert into proper scoped address */
5050 if ((IN6_IS_ADDR_LINKLOCAL(&sa
->sin6
.sin6_addr
) ||
5051 IN6_IS_ADDR_SITELOCAL(&sa
->sin6
.sin6_addr
)) &&
5052 sa
->sin6
.sin6_scope_id
== 0)
5054 struct in6_addr
*ia6p
;
5056 ia6p
= &sa
->sin6
.sin6_addr
;
5057 sa
->sin6
.sin6_scope_id
= ntohs(ia6p
->s6_addr
[3] |
5058 ((unsigned int)ia6p
->s6_addr
[2] << 8));
5059 ia6p
->s6_addr
[2] = ia6p
->s6_addr
[3] = 0;
5061 # endif /* __KAME__ */
5062 ia6
= sa
->sin6
.sin6_addr
;
5063 if (IN6_IS_ADDR_UNSPECIFIED(&ia6
))
5065 addr
= anynet_ntop(&ia6
, buf6
, sizeof(buf6
));
5066 message("WARNING: interface %s is UP with %s address",
5068 addr
== NULL
? "(NULL)" : addr
);
5072 /* save IP address in text from */
5073 addr
= anynet_ntop(&ia6
, buf6
, sizeof(buf6
));
5075 (void) sm_snprintf(ip_addr
, sizeof(ip_addr
),
5077 (int) sizeof(ip_addr
) - 3,
5081 # endif /* NETINET6 */
5084 if (ip_addr
[0] == '\0')
5087 if (!wordinclass(ip_addr
, 'w'))
5089 setclass('w', ip_addr
);
5091 sm_dprintf("\ta.k.a.: %s\n", ip_addr
);
5094 /* skip "loopback" interface "lo" */
5095 if (DontProbeInterfaces
== DPI_SKIPLOOPBACK
&&
5096 bitset(IFF_LOOPBACK
, IFRFREF
.ifr_flags
))
5099 (void) add_hostnames(sa
);
5101 sm_free(ifc
.ifc_buf
); /* XXX */
5104 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
5105 # endif /* NETINET6 && defined(SIOCGLIFCONF) */
5108 ** ISLOOPBACK -- is socket address in the loopback net?
5111 ** sa -- socket address.
5114 ** true -- is socket address in the loopback net?
5115 ** false -- otherwise
5124 if (IN6_IS_ADDR_LOOPBACK(&sa
.sin6
.sin6_addr
))
5126 #else /* NETINET6 */
5127 /* XXX how to correctly extract IN_LOOPBACKNET part? */
5128 if (((ntohl(sa
.sin
.sin_addr
.s_addr
) & IN_CLASSA_NET
)
5129 >> IN_CLASSA_NSHIFT
) == IN_LOOPBACKNET
)
5131 #endif /* NETINET6 */
5135 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
5141 ** The number of processors online.
5145 get_num_procs_online()
5150 # if defined(CTL_HW) && defined(HW_NCPU)
5156 sz
= (size_t) sizeof(nproc
);
5157 (void) sysctl(mib
, 2, &nproc
, &sz
, NULL
, 0);
5158 # endif /* defined(CTL_HW) && defined(HW_NCPU) */
5159 #else /* USESYSCTL */
5160 # ifdef _SC_NPROCESSORS_ONLN
5161 nproc
= (int) sysconf(_SC_NPROCESSORS_ONLN
);
5162 # else /* _SC_NPROCESSORS_ONLN */
5164 # include <sys/pstat.h>
5165 struct pst_dynamic psd
;
5167 if (pstat_getdynamic(&psd
, sizeof(psd
), (size_t)1, 0) != -1)
5168 nproc
= psd
.psd_proc_cnt
;
5169 # endif /* __hpux */
5170 # endif /* _SC_NPROCESSORS_ONLN */
5171 #endif /* USESYSCTL */
5178 ** SM_CLOSEFROM -- close file descriptors
5181 ** lowest -- first fd to close
5182 ** highest -- last fd + 1 to close
5189 sm_closefrom(lowest
, highest
)
5190 int lowest
, highest
;
5194 #else /* HASCLOSEFROM */
5197 for (i
= lowest
; i
< highest
; i
++)
5199 #endif /* HASCLOSEFROM */
5203 ** CLOSEFD_WALK -- walk fd's arranging to close them
5204 ** Callback for fdwalk()
5207 ** lowest -- first fd to arrange to be closed
5208 ** fd -- fd to arrange to be closed
5215 closefd_walk(lowest
, fd
)
5219 if (fd
>= *(int *)lowest
)
5220 (void) fcntl(fd
, F_SETFD
, FD_CLOEXEC
);
5223 #endif /* HASFDWALK */
5225 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
5228 ** lowest -- first fd to arrange to be closed
5229 ** highest -- last fd + 1 to arrange to be closed
5236 sm_close_on_exec(highest
, lowest
)
5237 int highest
, lowest
;
5240 (void) fdwalk(closefd_walk
, &lowest
);
5241 #else /* HASFDWALK */
5244 for (i
= lowest
; i
< highest
; i
++)
5246 if ((j
= fcntl(i
, F_GETFD
, 0)) != -1)
5247 (void) fcntl(i
, F_SETFD
, j
| FD_CLOEXEC
);
5249 #endif /* HASFDWALK */
5252 ** SEED_RANDOM -- seed the random number generator
5266 #else /* HASSRANDOMDEV */
5270 seed
= (long) CurrentPid
;
5271 if (gettimeofday(&t
, NULL
) >= 0)
5272 seed
+= t
.tv_sec
+ t
.tv_usec
;
5275 (void) srandom(seed
);
5276 # else /* HASRANDOM */
5277 (void) srand((unsigned int) seed
);
5278 # endif /* HASRANDOM */
5279 #endif /* HASSRANDOMDEV */
5282 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
5285 ** level -- syslog level
5286 ** id -- envelope ID or NULL (NOQUEUE)
5287 ** fmt -- format string
5288 ** arg... -- arguments as implied by fmt.
5297 sm_syslog(int level
, const char *id
, const char *fmt
, ...)
5298 #else /* __STDC__ */
5299 sm_syslog(level
, id
, fmt
, va_alist
)
5304 #endif /* __STDC__ */
5314 extern int SyslogPrefixLen
;
5320 idlen
= strlen(id
) + SyslogPrefixLen
;
5323 bufsize
= sizeof(buf0
);
5329 /* print log message into buf */
5330 SM_VA_START(ap
, fmt
);
5331 n
= sm_vsnprintf(buf
, bufsize
, fmt
, ap
);
5337 /* String too small, redo with correct size */
5344 buf
= sm_malloc_x(bufsize
);
5347 /* clean up buf after it has been expanded with args */
5348 newstring
= str2prt(buf
);
5349 if ((strlen(newstring
) + idlen
+ 1) < SYSLOG_BUFSIZE
)
5355 sm_dprintf("%s\n", newstring
);
5357 syslog(level
, "%s", newstring
);
5362 sm_dprintf("%s: %s\n", id
, newstring
);
5364 syslog(level
, "%s: %s", id
, newstring
);
5367 /*XXX should do something more sensible */
5369 (void) sm_io_fprintf(smioerr
, SM_TIME_DEFAULT
, "%s\n",
5372 (void) sm_io_fprintf(smioerr
, SM_TIME_DEFAULT
,
5373 "%s: %s\n", id
, newstring
);
5382 ** additional length for splitting: " ..." + 3, where 3 is magic to
5383 ** have some data for the next entry.
5389 idlen
+= 5; /* strlen("[999]"), see below */
5390 while (*begin
!= '\0' &&
5391 (strlen(begin
) + idlen
) > SYSLOG_BUFSIZE
)
5397 /* Too many messages */
5400 end
= begin
+ SYSLOG_BUFSIZE
- idlen
- SL_SPLIT
;
5403 /* Break on comma or space */
5404 if (*end
== ',' || *end
== ' ')
5406 end
++; /* Include separator */
5411 /* No separator, break midstring... */
5413 end
= begin
+ SYSLOG_BUFSIZE
- idlen
- SL_SPLIT
;
5418 sm_dprintf("%s[%d]: %s ...\n", id
, seq
++, begin
);
5420 syslog(level
, "%s[%d]: %s ...", id
, seq
++, begin
);
5422 (void) sm_io_fprintf(smioerr
, SM_TIME_DEFAULT
,
5423 "%s[%d]: %s ...\n", id
, seq
++, begin
);
5432 sm_dprintf("%s[%d]: log terminated, too many parts\n",
5435 syslog(level
, "%s[%d]: log terminated, too many parts",
5438 (void) sm_io_fprintf(smioerr
, SM_TIME_DEFAULT
,
5439 "%s[%d]: log terminated, too many parts\n", id
, seq
);
5442 else if (*begin
!= '\0')
5446 sm_dprintf("%s[%d]: %s\n", id
, seq
, begin
);
5448 syslog(level
, "%s[%d]: %s", id
, seq
, begin
);
5450 (void) sm_io_fprintf(smioerr
, SM_TIME_DEFAULT
,
5451 "%s[%d]: %s\n", id
, seq
, begin
);
5459 ** HARD_SYSLOG -- call syslog repeatedly until it works
5461 ** Needed on HP-UX, which apparently doesn't guarantee that
5462 ** syslog succeeds during interrupt handlers.
5465 #if defined(__hpux) && !defined(HPUX11)
5467 # define MAXSYSLOGTRIES 100
5470 # define XCNST const
5471 # define CAST (const char *)
5479 hard_syslog(int pri
, XCNST
char *msg
, ...)
5480 # else /* __STDC__ */
5481 hard_syslog(pri
, msg
, va_alist
)
5485 # endif /* __STDC__ */
5488 char buf
[SYSLOG_BUFSIZE
];
5491 SM_VA_START(ap
, msg
);
5492 (void) sm_vsnprintf(buf
, sizeof(buf
), msg
, ap
);
5495 for (i
= MAXSYSLOGTRIES
; --i
>= 0 && syslog(pri
, CAST
"%s", buf
) < 0; )
5500 #endif /* defined(__hpux) && !defined(HPUX11) */
5501 #if NEEDLOCAL_HOSTNAME_LENGTH
5503 ** LOCAL_HOSTNAME_LENGTH
5505 ** This is required to get sendmail to compile against BIND 4.9.x
5508 ** Unfortunately, a Compaq Y2K patch kit provides it without
5509 ** bumping __RES in /usr/include/resolv.h so we can't automatically
5510 ** figure out whether it is needed.
5514 local_hostname_length(hostname
)
5517 size_t len_host
, len_domain
;
5519 if (!*_res
.defdname
)
5521 len_host
= strlen(hostname
);
5522 len_domain
= strlen(_res
.defdname
);
5523 if (len_host
> len_domain
&&
5524 (sm_strcasecmp(hostname
+ len_host
- len_domain
,
5525 _res
.defdname
) == 0) &&
5526 hostname
[len_host
- len_domain
- 1] == '.')
5527 return len_host
- len_domain
- 1;
5531 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5535 ** LINK -- clone a file
5537 ** Some OS's lacks link() and hard links. Since sendmail is using
5538 ** link() as an efficient way to clone files, this implementation
5539 ** will simply do a file copy.
5541 ** NOTE: This link() replacement is not a generic replacement as it
5542 ** does not handle all of the semantics of the real link(2).
5545 ** source -- pathname of existing file.
5546 ** target -- pathname of link (clone) to be created.
5550 ** -1 -- failure, see errno for details.
5554 link(source
, target
)
5560 int src
= -1, dst
= -1;
5566 sff
= SFF_REGONLY
|SFF_OPENASROOT
;
5567 if (DontLockReadFiles
)
5570 /* Open the original file */
5571 src
= safeopen((char *)source
, O_RDONLY
, 0, sff
);
5575 /* Obtain the size and the mode */
5576 if (fstat(src
, &st
) < 0)
5579 /* Create the duplicate copy */
5582 dst
= safeopen((char *)target
, O_CREAT
|O_EXCL
|O_WRONLY
,
5587 /* Copy all of the bytes one buffer at a time */
5588 while ((readlen
= read(src
, &buf
, sizeof(buf
))) > 0)
5590 ssize_t left
= readlen
;
5594 (writelen
= write(dst
, p
, (size_t) left
)) >= 0)
5603 /* Any trouble reading? */
5604 if (readlen
< 0 || writelen
< 0)
5607 /* Close the input file */
5615 /* Close the output file */
5618 /* don't set dst = -1 here so we unlink the file */
5631 (void) unlink(target
);
5637 #endif /* NEEDLINK */
5640 ** Compile-Time options
5643 char *CompileOptions
[] =
5647 #endif /* ALLOW_255 */
5651 # endif /* DNSMAP */
5652 #endif /* NAMED_BIND */
5661 #endif /* HES_GETMAILHOST */
5664 #endif /* LDAPMAP */
5667 #endif /* LDAP_REFERRALS */
5673 #endif /* MAP_NSD */
5676 #endif /* MAP_REGEX */
5679 #endif /* MATCHGECOS */
5685 #endif /* MIME7TO8 */
5688 #endif /* MIME7TO8_OLD */
5691 #endif /* MIME8TO7 */
5694 #endif /* NAMED_BIND */
5700 #endif /* NETINET */
5703 #endif /* NETINET6 */
5706 #endif /* NETINFO */
5715 #endif /* NETUNIX */
5727 #endif /* NISPLUS */
5734 #ifdef PICKY_HELO_CHECK
5736 #endif /* PICKY_HELO_CHECK */
5739 #endif /* PIPELINING */
5743 # else /* SASL >= 20000 */
5745 # endif /* SASL >= 20000 */
5750 #if SM_LDAP_ERROR_ON_MISSING_ARGS
5751 "SM_LDAP_ERROR_ON_MISSING_ARGS",
5752 #endif /* SM_LDAP_ERROR_ON_MISSING_ARGS */
5755 #endif /* SMTPDEBUG */
5758 #endif /* SOCKETMAP */
5761 #endif /* STARTTLS */
5762 #if SUID_ROOT_FILES_OK
5763 "SUID_ROOT_FILES_OK",
5764 #endif /* SUID_ROOT_FILES_OK */
5767 #endif /* TCPWRAPPERS */
5770 #endif /* TLS_NO_RSA */
5771 #if TLS_VRFY_PER_CTX
5773 #endif /* TLS_VRFY_PER_CTX */
5779 #endif /* USE_LDAP_INIT */
5782 #endif /* USE_TTYPATH */
5794 ** OS compile options.
5797 char *OsCompileOptions
[] =
5799 #if ADDRCONFIG_IS_BROKEN
5800 "ADDRCONFIG_IS_BROKEN",
5801 #endif /* ADDRCONFIG_IS_BROKEN */
5802 #ifdef AUTO_NETINFO_HOSTS
5803 "AUTO_NETINFO_HOSTS",
5804 #endif /* AUTO_NETINFO_HOSTS */
5805 #ifdef AUTO_NIS_ALIASES
5807 #endif /* AUTO_NIS_ALIASES */
5808 #if BROKEN_RES_SEARCH
5809 "BROKEN_RES_SEARCH",
5810 #endif /* BROKEN_RES_SEARCH */
5811 #ifdef BSD4_4_SOCKADDR
5813 #endif /* BSD4_4_SOCKADDR */
5816 #endif /* BOGUS_O_EXCL */
5817 #if DEC_OSF_BROKEN_GETPWENT
5818 "DEC_OSF_BROKEN_GETPWENT",
5819 #endif /* DEC_OSF_BROKEN_GETPWENT */
5820 #if FAST_PID_RECYCLE
5822 #endif /* FAST_PID_RECYCLE */
5825 #endif /* HASCLOSEFROM */
5828 #endif /* HASFCHOWN */
5831 #endif /* HASFCHMOD */
5834 #endif /* HASFDWALK */
5837 #endif /* HASFLOCK */
5838 #if HASGETDTABLESIZE
5840 #endif /* HASGETDTABLESIZE */
5843 #endif /* HASGETUSERSHELL */
5846 #endif /* HASINITGROUPS */
5847 #if HASLDAPGETALIASBYNAME
5848 "HASLDAPGETALIASBYNAME",
5849 #endif /* HASLDAPGETALIASBYNAME */
5852 #endif /* HASLSTAT */
5855 #endif /* HASNICE */
5858 #endif /* HASRANDOM */
5861 #endif /* HASRRESVPORT */
5864 #endif /* HASSETEGID */
5867 #endif /* HASSETLOGIN */
5870 #endif /* HASSETREGID */
5873 #endif /* HASSETRESGID */
5876 #endif /* HASSETREUID */
5879 #endif /* HASSETRLIMIT */
5882 #endif /* HASSETSID */
5883 #if HASSETUSERCONTEXT
5884 "HASSETUSERCONTEXT",
5885 #endif /* HASSETUSERCONTEXT */
5888 #endif /* HASSETVBUF */
5891 #endif /* HAS_ST_GEN */
5894 #endif /* HASSRANDOMDEV */
5897 #endif /* HASURANDOMDEV */
5900 #endif /* HASSTRERROR */
5903 #endif /* HASULIMIT */
5906 #endif /* HASUNAME */
5909 #endif /* HASUNSETENV */
5912 #endif /* HASWAITPID */
5915 #endif /* IDENTPROTO */
5918 #endif /* IP_SRCROUTE */
5919 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
5921 #endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */
5924 #endif /* MILTER_NO_NAGLE */
5927 #endif /* NEEDFSYNC */
5930 #endif /* NEEDLINK */
5931 #if NEEDLOCAL_HOSTNAME_LENGTH
5932 "NEEDLOCAL_HOSTNAME_LENGTH",
5933 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */
5936 #endif /* NEEDSGETIPNODE */
5939 #endif /* NEEDSTRSTR */
5942 #endif /* NEEDSTRTOL */
5943 #ifdef NO_GETSERVBYNAME
5945 #endif /* NO_GETSERVBYNAME */
5948 #endif /* NOFTRUNCATE */
5949 #if REQUIRES_DIR_FSYNC
5950 "REQUIRES_DIR_FSYNC",
5951 #endif /* REQUIRES_DIR_FSYNC */
5952 #if RLIMIT_NEEDS_SYS_TIME_H
5953 "RLIMIT_NEEDS_SYS_TIME_H",
5954 #endif /* RLIMIT_NEEDS_SYS_TIME_H */
5957 #endif /* SAFENFSPATHCONF */
5960 #endif /* SECUREWARE */
5963 #endif /* SHARE_V1 */
5964 #if SIOCGIFCONF_IS_BROKEN
5965 "SIOCGIFCONF_IS_BROKEN",
5966 #endif /* SIOCGIFCONF_IS_BROKEN */
5967 #if SIOCGIFNUM_IS_BROKEN
5968 "SIOCGIFNUM_IS_BROKEN",
5969 #endif /* SIOCGIFNUM_IS_BROKEN */
5970 #if SNPRINTF_IS_BROKEN
5971 "SNPRINTF_IS_BROKEN",
5972 #endif /* SNPRINTF_IS_BROKEN */
5973 #if SO_REUSEADDR_IS_BROKEN
5974 "SO_REUSEADDR_IS_BROKEN",
5975 #endif /* SO_REUSEADDR_IS_BROKEN */
5978 #endif /* SYS5SETPGRP */
5981 #endif /* SYSTEM5 */
5984 #endif /* USE_DOUBLE_FORK */
5987 #endif /* USE_ENVIRON */
5988 #if USE_SA_SIGACTION
5990 #endif /* USE_SA_SIGACTION */
5993 #endif /* USE_SIGLONGJMP */
5996 #endif /* USEGETCONFATTR */
5999 #endif /* USESETEUID */
6002 #endif /* USESYSCTL */
6003 #if USING_NETSCAPE_LDAP
6004 "USING_NETSCAPE_LDAP",
6005 #endif /* USING_NETSCAPE_LDAP */
6008 #endif /* WAITUNION */
6013 ** FFR compile options.
6016 char *FFRCompileOptions
[] =
6018 #if _FFR_ADDR_TYPE_MODES
6019 /* more info in {addr_type}, requires m4 changes! */
6020 "_FFR_ADDR_TYPE_MODES",
6021 #endif /* _FFR_ADDR_TYPE_MODES */
6022 #if _FFR_ALLOW_SASLINFO
6023 /* DefaultAuthInfo can be specified by user. */
6024 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */
6025 "_FFR_ALLOW_SASLINFO",
6026 #endif /* _FFR_ALLOW_SASLINFO */
6027 #if _FFR_BESTMX_BETTER_TRUNCATION
6028 /* Better truncation of list of MX records for dns map. */
6029 "_FFR_BESTMX_BETTER_TRUNCATION",
6030 #endif /* _FFR_BESTMX_BETTER_TRUNCATION */
6031 #if _FFR_CATCH_BROKEN_MTAS
6032 /* Deal with MTAs that send a reply during the DATA phase. */
6033 "_FFR_CATCH_BROKEN_MTAS",
6034 #endif /* _FFR_CATCH_BROKEN_MTAS */
6036 /* Stricter checks about queue directory permissions. */
6038 #endif /* _FFR_CHK_QUEUE */
6039 #if _FFR_CLIENT_SIZE
6040 /* Don't try to send mail if its size exceeds SIZE= of server. */
6042 #endif /* _FFR_CLIENT_SIZE */
6044 /* CRLPath; needs documentation; Al Smith */
6046 #endif /* _FFR_CRLPATH */
6047 #if _FFR_DAEMON_NETUNIX
6048 /* Allow local (not just TCP) socket connection to server. */
6049 "_FFR_DAEMON_NETUNIX",
6050 #endif /* _FFR_DAEMON_NETUNIX */
6051 #if _FFR_DEPRECATE_MAILER_FLAG_I
6052 /* What it says :-) */
6053 "_FFR_DEPRECATE_MAILER_FLAG_I",
6054 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
6056 /* deliver first TA in background, then queue */
6058 #endif /* _FFR_DM_ONE */
6059 #if _FFR_DIGUNIX_SAFECHOWN
6060 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
6061 /* Problem noted by Anne Bennett of Concordia University */
6062 "_FFR_DIGUNIX_SAFECHOWN",
6063 #endif /* _FFR_DIGUNIX_SAFECHOWN */
6064 #if _FFR_DNSMAP_ALIASABLE
6065 /* Allow dns map type to be used for aliases. */
6066 /* Don Lewis of TDK */
6067 "_FFR_DNSMAP_ALIASABLE",
6068 #endif /* _FFR_DNSMAP_ALIASABLE */
6069 #if _FFR_DONTLOCKFILESFORREAD_OPTION
6070 /* Enable DontLockFilesForRead option. */
6071 "_FFR_DONTLOCKFILESFORREAD_OPTION",
6072 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
6073 #if _FFR_DOTTED_USERNAMES
6074 /* Allow usernames with '.' */
6075 "_FFR_DOTTED_USERNAMES",
6076 #endif /* _FFR_DOTTED_USERNAMES */
6079 ** Make DaemonPortOptions case sensitive.
6080 ** For some unknown reasons the code converted every option
6081 ** to uppercase (first letter only, as that's the only one that
6082 ** is actually checked). This prevented all new lower case options
6084 ** The documentation doesn't say anything about case (in)sensitivity,
6085 ** which means it should be case sensitive by default,
6086 ** but it's not a good idea to change this within a patch release,
6087 ** so let's delay this to 8.15.
6091 #endif /* _FFR_DPO_CS */
6092 #if _FFR_DPRINTF_MAP
6093 /* dprintf map for logging */
6095 #endif /* _FFR_DPRINTF_MAP */
6096 #if _FFR_DROP_TRUSTUSER_WARNING
6098 ** Don't issue this warning:
6099 ** "readcf: option TrustedUser may cause problems on systems
6100 ** which do not support fchown() if UseMSP is not set.
6103 "_FFR_DROP_TRUSTUSER_WARNING",
6104 #endif /* _FFR_DROP_TRUSTUSER_WARNING */
6105 #if _FFR_EIGHT_BIT_ADDR_OK
6106 /* EightBitAddrOK: allow 8-bit e-mail addresses */
6107 "_FFR_EIGHT_BIT_ADDR_OK",
6108 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
6109 #if _FFR_EXTRA_MAP_CHECK
6110 /* perform extra checks on $( $) in R lines */
6111 "_FFR_EXTRA_MAP_CHECK",
6112 #endif /* _FFR_EXTRA_MAP_CHECK */
6113 #if _FFR_GETHBN_ExFILE
6115 ** According to Motonori Nakamura some gethostbyname()
6116 ** implementations (TurboLinux?) may (temporarily) fail
6117 ** due to a lack of file discriptors. Enabling this FFR
6118 ** will check errno for EMFILE and ENFILE and in case of a match
6119 ** cause a temporary error instead of a permanent error.
6120 ** The right solution is of course to file a bug against those
6121 ** systems such that they actually set h_errno = TRY_AGAIN.
6124 "_FFR_GETHBN_ExFILE",
6125 #endif /* _FFR_GETHBN_ExFILE */
6128 ** If using -t, force not sending to argv recipients, even
6129 ** if they are mentioned in the headers.
6133 #endif /* _FFR_FIX_DASHT */
6134 #if _FFR_FORWARD_SYSERR
6135 /* Cause a "syserr" if forward file isn't "safe". */
6136 "_FFR_FORWARD_SYSERR",
6137 #endif /* _FFR_FORWARD_SYSERR */
6139 /* Generate a ORCPT DSN arg if not already provided */
6141 #endif /* _FFR_GEN_ORCPT */
6142 #if _FFR_GROUPREADABLEAUTHINFOFILE
6143 /* Allow group readable DefaultAuthInfo file. */
6144 "_FFR_GROUPREADABLEAUTHINFOFILE",
6145 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
6146 #if _FFR_HANDLE_ISO8859_GECOS
6148 ** Allow ISO 8859 characters in GECOS field: replace them
6149 ** ith ASCII "equivalent".
6152 /* Peter Eriksson of Linkopings universitet */
6153 "_FFR_HANDLE_ISO8859_GECOS",
6154 #endif /* _FFR_HANDLE_ISO8859_GECOS */
6155 #if _FFR_HPUX_NSSWITCH
6156 /* Use nsswitch on HP-UX */
6157 "_FFR_HPUX_NSSWITCH",
6158 #endif /* _FFR_HPUX_NSSWITCH */
6159 #if _FFR_IGNORE_BOGUS_ADDR
6160 /* Ignore addresses for which prescan() failed */
6161 "_FFR_IGNORE_BOGUS_ADDR",
6162 #endif /* _FFR_IGNORE_BOGUS_ADDR */
6163 #if _FFR_IGNORE_EXT_ON_HELO
6164 /* Ignore extensions offered in response to HELO */
6165 "_FFR_IGNORE_EXT_ON_HELO",
6166 #endif /* _FFR_IGNORE_EXT_ON_HELO */
6167 #if _FFR_MAXDATASIZE
6169 ** It is possible that a header is larger than MILTER_CHUNK_SIZE,
6170 ** hence this shouldn't be used as limit for milter communication.
6171 ** see also libmilter/comm.c
6172 ** Gurusamy Sarathy of ActiveState
6176 #endif /* _FFR_MAXDATASIZE */
6177 #if _FFR_MAX_FORWARD_ENTRIES
6178 /* Try to limit number of .forward entries */
6179 /* (doesn't work) */
6180 /* Randall S. Winchester of the University of Maryland */
6181 "_FFR_MAX_FORWARD_ENTRIES",
6182 #endif /* _FFR_MAX_FORWARD_ENTRIES */
6183 #if _FFR_MAX_SLEEP_TIME
6184 /* Limit sleep(2) time in libsm/clock.c */
6185 "_FFR_MAX_SLEEP_TIME",
6186 #endif /* _FFR_MAX_SLEEP_TIME */
6188 /* Check free memory */
6190 #endif /* _FFR_MEMSTAT */
6191 #if _FFR_MILTER_CHECK
6192 "_FFR_MILTER_CHECK",
6193 #endif /* _FFR_MILTER_CHECK */
6194 #if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF
6196 ** milter_body() uses the same conversion algorithm as putbody()
6197 ** to translate the "local" df format (\n) to SMTP format (\r\n).
6198 ** However, putbody() and mime8to7() use different conversion
6200 ** If the input date does not follow the SMTP standard
6201 ** (e.g., if it has "naked \r"s), then the output from putbody()
6202 ** and mime8to7() will most likely be different.
6203 ** By turning on this FFR milter_body() will try to "imitate"
6205 ** Note: there is no (simple) way to deal with both conversions
6206 ** in a consistent manner. Moreover, as the "GiGo" principle applies,
6207 ** it's not really worth to fix it.
6210 "_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF",
6211 #endif /* _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF */
6212 #if _FFR_MILTER_CHECK_REJECTIONS_TOO
6214 ** Also send RCPTs that are rejected by check_rcpt to a milter
6215 ** (if requested during option negotiation).
6218 "_FFR_MILTER_CHECK_REJECTIONS_TOO",
6219 #endif /* _FFR_MILTER_CHECK_REJECTIONS_TOO */
6220 #if _FFR_MIME7TO8_OLD
6221 /* Old mime7to8 code, the new is broken for at least one example. */
6222 "_FFR_MIME7TO8_OLD",
6223 #endif /* _FFR_MAX_SLEEP_TIME */
6224 #if _FFR_MORE_MACROS
6225 /* allow more long macro names ("unprintable" characters). */
6227 #endif /* _FFR_MORE_MACROS */
6229 /* allow to override "Message accepted for delivery" */
6231 #endif /* _FFR_MSG_ACCEPT */
6232 #if _FFR_NODELAYDSN_ON_HOLD
6233 /* Do not issue a DELAY DSN for mailers that use the hold flag. */
6235 "_FFR_NODELAYDSN_ON_HOLD",
6236 #endif /* _FFR_NODELAYDSN_ON_HOLD */
6238 /* Disable PIPELINING, delay client if used. */
6240 #endif /* _FFR_NO_PIPE */
6241 #if _FFR_LDAP_NETWORK_TIMEOUT
6242 /* set LDAP_OPT_NETWORK_TIMEOUT if available (-c) */
6243 "_FFR_LDAP_NETWORK_TIMEOUT",
6244 #endif /* _FFR_LDAP_NETWORK_TIMEOUT */
6246 /* log ntries=, from Nik Clayton of FreeBSD */
6248 #endif /* _FFR_LOG_NTRIES */
6249 #if _FFR_QF_PARANOIA
6251 #endif /* _FFR_QF_PARANOIA */
6253 /* Exponential queue delay; disabled in 8.13 since it isn't used. */
6255 #endif /* _FFR_QUEUEDELAY */
6256 #if _FFR_QUEUE_GROUP_SORTORDER
6257 /* Allow QueueSortOrder per queue group. */
6258 /* XXX: Still need to actually use qgrp->qg_sortorder */
6259 "_FFR_QUEUE_GROUP_SORTORDER",
6260 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
6261 #if _FFR_QUEUE_MACRO
6262 /* Define {queue} macro. */
6264 #endif /* _FFR_QUEUE_MACRO */
6265 #if _FFR_QUEUE_RUN_PARANOIA
6266 /* Additional checks when doing queue runs; interval of checks */
6267 "_FFR_QUEUE_RUN_PARANOIA",
6268 #endif /* _FFR_QUEUE_RUN_PARANOIA */
6269 #if _FFR_QUEUE_SCHED_DBG
6270 /* Debug output for the queue scheduler. */
6271 "_FFR_QUEUE_SCHED_DBG",
6272 #endif /* _FFR_QUEUE_SCHED_DBG */
6273 #if _FFR_REDIRECTEMPTY
6275 ** envelope <> can't be sent to mailing lists, only owner-
6276 ** send spam of this type to owner- of the list
6277 ** ---- to stop spam from going to mailing lists.
6280 "_FFR_REDIRECTEMPTY",
6281 #endif /* _FFR_REDIRECTEMPTY */
6282 #if _FFR_RESET_MACRO_GLOBALS
6283 /* Allow macro 'j' to be set dynamically via rulesets. */
6284 "_FFR_RESET_MACRO_GLOBALS",
6285 #endif /* _FFR_RESET_MACRO_GLOBALS */
6287 /* Random shuffle for queue sorting. */
6289 #endif /* _FFR_RHS */
6292 ** allow -qGqueue_group -qp to work, i.e.,
6293 ** restrict a persistent queue runner to a queue group.
6297 #endif /* _FFR_RUNPQG */
6299 /* session id (for logging) */
6301 #endif /* _FFR_SESSID */
6303 /* Donated code (unused). */
6305 #endif /* _FFR_SHM_STATUS */
6306 #if _FFR_LDAP_SINGLEDN
6308 ** The LDAP database map code in Sendmail 8.12.10, when
6309 ** given the -1 switch, would match only a single DN,
6310 ** but was able to return multiple attributes for that
6311 ** DN. In Sendmail 8.13 this "bug" was corrected to
6312 ** only return if exactly one attribute matched.
6314 ** Unfortunately, our configuration uses the former
6315 ** behaviour. Attached is a relatively simple patch
6316 ** to 8.13.4 which adds a -2 switch (for lack of a
6317 ** better option) which returns the single dn/multiple
6320 ** Jeffrey T. Eaton, Carnegie-Mellon University
6323 "_FFR_LDAP_SINGLEDN",
6324 #endif /* _FFR_LDAP_SINGLEDN */
6325 #if _FFR_SKIP_DOMAINS
6326 /* process every N'th domain instead of every N'th message */
6327 "_FFR_SKIP_DOMAINS",
6328 #endif /* _FFR_SKIP_DOMAINS */
6329 #if _FFR_SLEEP_USE_SELECT
6330 /* Use select(2) in libsm/clock.c to emulate sleep(2) */
6331 "_FFR_SLEEP_USE_SELECT ",
6332 #endif /* _FFR_SLEEP_USE_SELECT */
6335 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
6336 ** bit alignment, so unless each piece of argv and envp is a multiple
6337 ** of 8 bytes (including terminating NULL), initsetproctitle() won't
6338 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
6339 ** if you use this FFR.
6342 /* Chris Adams of HiWAAY Informations Services */
6344 #endif /* _FFR_SPT_ALIGN */
6345 #if _FFR_SS_PER_DAEMON
6346 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
6347 "_FFR_SS_PER_DAEMON",
6348 #endif /* _FFR_SS_PER_DAEMON */
6350 /* Donated code (unused). */
6352 #endif /* _FFR_TIMERS */
6354 /* More STARTTLS options, e.g., secondary certs. */
6356 #endif /* _FFR_TLS_1 */
6359 ** If we don't own the file mark it as unsafe.
6360 ** However, allow TrustedUser to own it as well
6361 ** in case TrustedUser manipulates the queue.
6365 #endif /* _FFR_TRUSTED_QF */
6366 #if _FFR_USE_SEM_LOCKING
6367 "_FFR_USE_SEM_LOCKING",
6368 #endif /* _FFR_USE_SEM_LOCKING */
6369 #if _FFR_USE_SETLOGIN
6370 /* Use setlogin() */
6372 "_FFR_USE_SETLOGIN",
6373 #endif /* _FFR_USE_SETLOGIN */