#include <sendmail.h>
SM_RCSID("@(#)$Id: conf.c,v 8.1153 2009/12/18 17:25:12 ca Exp $")
#include <sm/sendmail.h>
#include <sendmail/pathnames.h>
#if NEWDB
# include "sm/bdb.h"
#endif
#include <daemon.h>
#include "map.h"
#ifdef DEC
# if NETINET6
# define _SOCKADDR_LEN
# include <macros.h>
# endif
#endif
# include <sys/ioctl.h>
# include <sys/param.h>
#include <limits.h>
#if NETINET || NETINET6
# include <arpa/inet.h>
#endif
#if HASULIMIT && defined(HPUX11)
# include <ulimit.h>
#endif
static void setupmaps __P((void));
static void setupmailers __P((void));
static void setupqueues __P((void));
static int get_num_procs_online __P((void));
static int add_hostnames __P((SOCKADDR *));
#if NETINET6 && NEEDSGETIPNODE
static struct hostent *getipnodebyname __P((char *, int, int, int *));
static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
#endif
struct hdrinfo HdrInfo[] =
{
{ "resent-sender", H_FROM|H_RESENT, NULL },
{ "resent-from", H_FROM|H_RESENT, NULL },
{ "resent-reply-to", H_FROM|H_RESENT, NULL },
{ "sender", H_FROM, NULL },
{ "from", H_FROM, NULL },
{ "reply-to", H_FROM, NULL },
{ "errors-to", H_FROM|H_ERRORSTO, NULL },
{ "full-name", H_ACHECK, NULL },
{ "return-receipt-to", H_RECEIPTTO, NULL },
{ "delivery-receipt-to", H_RECEIPTTO, NULL },
{ "disposition-notification-to", H_FROM, NULL },
{ "to", H_RCPT, NULL },
{ "resent-to", H_RCPT|H_RESENT, NULL },
{ "cc", H_RCPT, NULL },
{ "resent-cc", H_RCPT|H_RESENT, NULL },
{ "bcc", H_RCPT|H_BCC, NULL },
{ "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
{ "apparently-to", H_RCPT, NULL },
{ "message-id", 0, NULL },
{ "resent-message-id", H_RESENT, NULL },
{ "message", H_EOH, NULL },
{ "text", H_EOH, NULL },
{ "date", 0, NULL },
{ "resent-date", H_RESENT, NULL },
{ "received", H_TRACE|H_FORCE, NULL },
{ "x400-received", H_TRACE|H_FORCE, NULL },
{ "via", H_TRACE|H_FORCE, NULL },
{ "mail-from", H_TRACE|H_FORCE, NULL },
{ "comments", H_FORCE|H_ENCODABLE, NULL },
{ "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
{ "content-transfer-encoding", H_CTE, NULL },
{ "content-type", H_CTYPE, NULL },
{ "content-length", H_ACHECK, NULL },
{ "subject", H_ENCODABLE, NULL },
{ "x-authentication-warning", H_FORCE, NULL },
{ NULL, 0, NULL }
};
struct prival PrivacyValues[] =
{
{ "public", PRIV_PUBLIC },
{ "needmailhelo", PRIV_NEEDMAILHELO },
{ "needexpnhelo", PRIV_NEEDEXPNHELO },
{ "needvrfyhelo", PRIV_NEEDVRFYHELO },
{ "noexpn", PRIV_NOEXPN },
{ "novrfy", PRIV_NOVRFY },
{ "restrictexpand", PRIV_RESTRICTEXPAND },
{ "restrictmailq", PRIV_RESTRICTMAILQ },
{ "restrictqrun", PRIV_RESTRICTQRUN },
{ "noetrn", PRIV_NOETRN },
{ "noverb", PRIV_NOVERB },
{ "authwarnings", PRIV_AUTHWARNINGS },
{ "noreceipts", PRIV_NORECEIPTS },
{ "nobodyreturn", PRIV_NOBODYRETN },
{ "goaway", PRIV_GOAWAY },
{ "noactualrecipient", PRIV_NOACTUALRECIPIENT },
{ NULL, 0 }
};
struct dbsval DontBlameSendmailValues[] =
{
{ "safe", DBS_SAFE },
{ "assumesafechown", DBS_ASSUMESAFECHOWN },
{ "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
{ "groupwritableforwardfilesafe",
DBS_GROUPWRITABLEFORWARDFILESAFE },
{ "groupwritableincludefilesafe",
DBS_GROUPWRITABLEINCLUDEFILESAFE },
{ "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
{ "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
{ "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
{ "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
{ "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
{ "linkedaliasfileinwritabledir",
DBS_LINKEDALIASFILEINWRITABLEDIR },
{ "linkedclassfileinwritabledir",
DBS_LINKEDCLASSFILEINWRITABLEDIR },
{ "linkedforwardfileinwritabledir",
DBS_LINKEDFORWARDFILEINWRITABLEDIR },
{ "linkedincludefileinwritabledir",
DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
{ "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
{ "linkedserviceswitchfileinwritabledir",
DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
{ "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
{ "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
{ "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
{ "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
{ "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
{ "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
{ "forwardfileingroupwritabledirpath",
DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
{ "includefileingroupwritabledirpath",
DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
{ "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
{ "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
{ "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
{ "forwardfileinunsafedirpathsafe",
DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
{ "includefileinunsafedirpathsafe",
DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
{ "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
{ "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
{ "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
{ "truststickybit", DBS_TRUSTSTICKYBIT },
{ "dontwarnforwardfileinunsafedirpath",
DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
{ "insufficiententropy", DBS_INSUFFICIENTENTROPY },
{ "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
{ "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
{ "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
{ "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
{ "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
{ "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
{ "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
#if _FFR_GROUPREADABLEAUTHINFOFILE
{ "groupreadableadefaultauthinfofile",
DBS_GROUPREADABLEAUTHINFOFILE },
#endif
{ NULL, 0 }
};
int DtableSize = 50;
#define MINUTES * 60
#define HOURS * 60 MINUTES
#define DAYS * 24 HOURS
#ifndef MAXRULERECURSION
# define MAXRULERECURSION 50
#endif
void
setdefaults(e)
register ENVELOPE *e;
{
int i;
int numprocs;
struct passwd *pw;
numprocs = get_num_procs_online();
SpaceSub = ' ';
QueueLA = 8 * numprocs;
RefuseLA = 12 * numprocs;
WkRecipFact = 30000L;
WkClassFact = 1800L;
WkTimeFact = 90000L;
QueueFactor = WkRecipFact * 20;
QueueMode = QM_NORMAL;
FileMode = (RealUid != geteuid()) ? 0644 : 0600;
QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
{
DefUid = pw->pw_uid;
DefGid = pw->pw_gid;
DefUser = newstr(pw->pw_name);
}
else
{
DefUid = 1;
DefGid = 1;
setdefuser();
}
TrustedUid = 0;
if (tTd(37, 4))
sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
DefUser != NULL ? DefUser : "<1:1>",
(int) DefUid, (int) DefGid);
CheckpointInterval = 10;
MaxHopCount = 25;
set_delivery_mode(SM_FORK, e);
e->e_errormode = EM_PRINT;
e->e_qgrp = NOQGRP;
e->e_qdir = NOQDIR;
e->e_xfqgrp = NOQGRP;
e->e_xfqdir = NOQDIR;
e->e_ctime = curtime();
SevenBitInput = false;
MaxMciCache = 1;
MciCacheTimeout = 5 MINUTES;
LogLevel = 9;
#if MILTER
MilterLogLevel = -1;
#endif
inittimeouts(NULL, false);
PrivacyFlags = PRIV_PUBLIC;
MeToo = true;
SendMIMEErrors = true;
SuperSafe = SAFE_REALLY;
clrbitmap(DontBlameSendmail);
#if MIME8TO7
MimeMode = MM_CVTMIME|MM_PASS8BIT;
#else
MimeMode = MM_PASS8BIT;
#endif
for (i = 0; i < MAXTOCLASS; i++)
{
TimeOuts.to_q_return[i] = 5 DAYS;
TimeOuts.to_q_warning[i] = 0;
}
ServiceSwitchFile = "/etc/mail/service.switch";
ServiceCacheMaxAge = (time_t) 10;
HostsFile = _PATH_HOSTS;
PidFile = newstr(_PATH_SENDMAILPID);
MustQuoteChars = "@,;:\\()[].'";
MciInfoTimeout = 30 MINUTES;
MaxRuleRecursion = MAXRULERECURSION;
MaxAliasRecursion = 10;
MaxMacroRecursion = 10;
ColonOkInAddr = true;
DontLockReadFiles = true;
DontProbeInterfaces = DPI_PROBEALL;
DoubleBounceAddr = "postmaster";
MaxHeadersLength = MAXHDRSLEN;
MaxMimeHeaderLength = MAXLINE;
MaxMimeFieldLength = MaxMimeHeaderLength / 2;
MaxForwardEntries = 0;
FastSplit = 1;
MaxNOOPCommands = MAXNOOPCOMMANDS;
#if SASL
AuthMechanisms = newstr(AUTH_MECHANISMS);
AuthRealm = NULL;
MaxSLBits = INT_MAX;
#endif
#if STARTTLS
TLS_Srv_Opts = TLS_I_SRV;
#endif
#ifdef HESIOD_INIT
HesiodContext = NULL;
#endif
#if NETINET6
i = socket(AF_INET6, SOCK_STREAM, 0);
if (i >= 0)
{
InetMode = AF_INET6;
(void) close(i);
}
else
InetMode = AF_INET;
#else
InetMode = AF_INET;
#endif
ControlSocketName = NULL;
memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo));
DataFileBufferSize = 4096;
XscriptFileBufferSize = 4096;
for (i = 0; i < MAXRWSETS; i++)
RuleSetNames[i] = NULL;
#if MILTER
InputFilters[0] = NULL;
#endif
RejectLogInterval = 3 HOURS;
#if REQUIRES_DIR_FSYNC
RequiresDirfsync = true;
#endif
#if _FFR_RCPTTHROTDELAY
BadRcptThrottleDelay = 1;
#endif
ConnectionRateWindowSize = 60;
setupmaps();
setupqueues();
setupmailers();
setupheaders();
}
void
setdefuser()
{
struct passwd *defpwent;
static char defuserbuf[40];
DefUser = defuserbuf;
defpwent = sm_getpwuid(DefUid);
(void) sm_strlcpy(defuserbuf,
(defpwent == NULL || defpwent->pw_name == NULL)
? "nobody" : defpwent->pw_name,
sizeof(defuserbuf));
if (tTd(37, 4))
sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
(int) DefUid, DefUser);
}
static void
setupqueues()
{
char buf[100];
MaxRunnersPerQueue = 1;
(void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf));
makequeue(buf, false);
}
static void
setupmailers()
{
char buf[100];
(void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
sizeof(buf));
makemailer(buf);
(void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
sizeof(buf));
makemailer(buf);
(void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
sizeof(buf));
makemailer(buf);
initerrmailers();
}
#define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
{ \
extern bool parse __P((MAP *, char *)); \
extern bool open __P((MAP *, int)); \
extern void close __P((MAP *)); \
extern char *lookup __P((MAP *, char *, char **, int *)); \
extern void store __P((MAP *, char *, char *)); \
s = stab(name, ST_MAPCLASS, ST_ENTER); \
s->s_mapclass.map_cname = name; \
s->s_mapclass.map_ext = ext; \
s->s_mapclass.map_cflags = flags; \
s->s_mapclass.map_parse = parse; \
s->s_mapclass.map_open = open; \
s->s_mapclass.map_close = close; \
s->s_mapclass.map_lookup = lookup; \
s->s_mapclass.map_store = store; \
}
static void
setupmaps()
{
register STAB *s;
#if NEWDB
# if DB_VERSION_MAJOR > 1
int major_v, minor_v, patch_v;
(void) db_version(&major_v, &minor_v, &patch_v);
if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
{
errno = 0;
syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
major_v, minor_v, patch_v);
}
# endif
MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
map_parseargs, hash_map_open, db_map_close,
db_map_lookup, db_map_store);
MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
map_parseargs, bt_map_open, db_map_close,
db_map_lookup, db_map_store);
#endif
#if NDBM
MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
map_parseargs, ndbm_map_open, ndbm_map_close,
ndbm_map_lookup, ndbm_map_store);
#endif
#if NIS
MAPDEF("nis", NULL, MCF_ALIASOK,
map_parseargs, nis_map_open, null_map_close,
nis_map_lookup, null_map_store);
#endif
#if NISPLUS
MAPDEF("nisplus", NULL, MCF_ALIASOK,
map_parseargs, nisplus_map_open, null_map_close,
nisplus_map_lookup, null_map_store);
#endif
#if LDAPMAP
MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
ldapmap_parseargs, ldapmap_open, ldapmap_close,
ldapmap_lookup, null_map_store);
#endif
#if PH_MAP
MAPDEF("ph", NULL, MCF_NOTPERSIST,
ph_map_parseargs, ph_map_open, ph_map_close,
ph_map_lookup, null_map_store);
#endif
#if MAP_NSD
MAPDEF("nsd", NULL, MCF_ALIASOK,
map_parseargs, null_map_open, null_map_close,
nsd_map_lookup, null_map_store);
#endif
#if HESIOD
MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
map_parseargs, hes_map_open, hes_map_close,
hes_map_lookup, null_map_store);
#endif
#if NETINFO
MAPDEF("netinfo", NULL, MCF_ALIASOK,
map_parseargs, ni_map_open, null_map_close,
ni_map_lookup, null_map_store);
#endif
#if 0
MAPDEF("dns", NULL, 0,
dns_map_init, null_map_open, null_map_close,
dns_map_lookup, null_map_store);
#endif
#if NAMED_BIND
# if DNSMAP
# if _FFR_DNSMAP_ALIASABLE
MAPDEF("dns", NULL, MCF_ALIASOK,
dns_map_parseargs, dns_map_open, null_map_close,
dns_map_lookup, null_map_store);
# else
MAPDEF("dns", NULL, 0,
dns_map_parseargs, dns_map_open, null_map_close,
dns_map_lookup, null_map_store);
# endif
# endif
#endif
#if NAMED_BIND
MAPDEF("bestmx", NULL, MCF_OPTFILE,
map_parseargs, null_map_open, null_map_close,
bestmx_map_lookup, null_map_store);
#endif
MAPDEF("host", NULL, 0,
host_map_init, null_map_open, null_map_close,
host_map_lookup, null_map_store);
MAPDEF("text", NULL, MCF_ALIASOK,
map_parseargs, text_map_open, null_map_close,
text_map_lookup, null_map_store);
MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
map_parseargs, stab_map_open, null_map_close,
stab_map_lookup, stab_map_store);
MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
map_parseargs, impl_map_open, impl_map_close,
impl_map_lookup, impl_map_store);
MAPDEF("user", NULL, MCF_OPTFILE,
map_parseargs, user_map_open, null_map_close,
user_map_lookup, null_map_store);
MAPDEF("dequote", NULL, 0,
dequote_init, null_map_open, null_map_close,
dequote_map, null_map_store);
#if MAP_REGEX
MAPDEF("regex", NULL, 0,
regex_map_init, null_map_open, null_map_close,
regex_map_lookup, null_map_store);
#endif
#if USERDB
MAPDEF("userdb", ".db", 0,
map_parseargs, null_map_open, null_map_close,
udb_map_lookup, null_map_store);
#endif
MAPDEF("program", NULL, MCF_ALIASOK,
map_parseargs, null_map_open, null_map_close,
prog_map_lookup, null_map_store);
MAPDEF("sequence", NULL, MCF_ALIASOK,
seq_map_parse, null_map_open, null_map_close,
seq_map_lookup, seq_map_store);
MAPDEF("switch", NULL, MCF_ALIASOK,
map_parseargs, switch_map_open, null_map_close,
seq_map_lookup, seq_map_store);
MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
map_parseargs, null_map_open, null_map_close,
null_map_lookup, null_map_store);
MAPDEF("syslog", NULL, 0,
syslog_map_parseargs, null_map_open, null_map_close,
syslog_map_lookup, null_map_store);
MAPDEF("macro", NULL, 0,
dequote_init, null_map_open, null_map_close,
macro_map_lookup, null_map_store);
MAPDEF("arith", NULL, 0,
dequote_init, null_map_open, null_map_close,
arith_map_lookup, null_map_store);
#if SOCKETMAP
MAPDEF("socket", NULL, MCF_ALIASOK,
map_parseargs, socket_map_open, socket_map_close,
socket_map_lookup, null_map_store);
#endif
#if _FFR_DPRINTF_MAP
MAPDEF("dprintf", NULL, 0,
dprintf_map_parseargs, null_map_open, null_map_close,
dprintf_map_lookup, null_map_store);
#endif
if (tTd(38, 2))
{
MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
map_parseargs, null_map_open, null_map_close,
bogus_map_lookup, null_map_store);
}
}
#undef MAPDEF
void
inithostmaps()
{
register int i;
int nmaps;
char *maptype[MAXMAPSTACK];
short mapreturn[MAXMAPACTIONS];
char buf[MAXLINE];
if (stab("host", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "host host", sizeof(buf));
#if NAMED_BIND
if (ConfigLevel >= 2)
(void) sm_strlcat(buf, " -a. -D", sizeof(buf));
#endif
(void) makemapentry(buf);
}
nmaps = switch_map_find("aliases", maptype, mapreturn);
for (i = 0; i < nmaps; i++)
{
if (strcmp(maptype[i], "files") == 0 &&
stab("aliases.files", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.files null",
sizeof(buf));
(void) makemapentry(buf);
}
#if NISPLUS
else if (strcmp(maptype[i], "nisplus") == 0 &&
stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
sizeof(buf));
(void) makemapentry(buf);
}
#endif
#if NIS
else if (strcmp(maptype[i], "nis") == 0 &&
stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
sizeof(buf));
(void) makemapentry(buf);
}
#endif
#if NETINFO
else if (strcmp(maptype[i], "netinfo") == 0 &&
stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
sizeof(buf));
(void) makemapentry(buf);
}
#endif
#if HESIOD
else if (strcmp(maptype[i], "hesiod") == 0 &&
stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
sizeof(buf));
(void) makemapentry(buf);
}
#endif
#if LDAPMAP && defined(SUN_EXTENSIONS) && \
defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
else if (strcmp(maptype[i], "ldap") == 0 &&
stab("aliases.ldap", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
sizeof buf);
(void) makemapentry(buf);
}
#endif
}
if (stab("aliases", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf));
(void) makemapentry(buf);
}
}
#if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
# define _USE_SUN_NSSWITCH_
#endif
#if _FFR_HPUX_NSSWITCH
# ifdef __hpux
# define _USE_SUN_NSSWITCH_
# endif
#endif
#ifdef _USE_SUN_NSSWITCH_
# include <nsswitch.h>
#endif
#if defined(ultrix) || (defined(__osf__) && defined(__alpha))
# define _USE_DEC_SVC_CONF_
#endif
#ifdef _USE_DEC_SVC_CONF_
# include <sys/svcinfo.h>
#endif
int
switch_map_find(service, maptype, mapreturn)
char *service;
char *maptype[MAXMAPSTACK];
short mapreturn[MAXMAPACTIONS];
{
int svcno = 0;
int save_errno = errno;
#ifdef _USE_SUN_NSSWITCH_
struct __nsw_switchconfig *nsw_conf;
enum __nsw_parse_err pserr;
struct __nsw_lookup *lk;
static struct __nsw_lookup lkp0 =
{ "files", {1, 0, 0, 0}, NULL, NULL };
static struct __nsw_switchconfig lkp_default =
{ 0, "sendmail", 3, &lkp0 };
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
lk = lkp_default.lookups;
else
lk = nsw_conf->lookups;
svcno = 0;
while (lk != NULL && svcno < MAXMAPSTACK)
{
maptype[svcno] = lk->service_name;
if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
mapreturn[MA_NOTFOUND] |= 1 << svcno;
if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
mapreturn[MA_TRYAGAIN] |= 1 << svcno;
if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
mapreturn[MA_TRYAGAIN] |= 1 << svcno;
svcno++;
lk = lk->next;
}
errno = save_errno;
return svcno;
#endif
#ifdef _USE_DEC_SVC_CONF_
struct svcinfo *svcinfo;
int svc;
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
svcinfo = getsvc();
if (svcinfo == NULL)
goto punt;
if (strcmp(service, "hosts") == 0)
svc = SVC_HOSTS;
else if (strcmp(service, "aliases") == 0)
svc = SVC_ALIASES;
else if (strcmp(service, "passwd") == 0)
svc = SVC_PASSWD;
else
{
errno = save_errno;
return -1;
}
for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
{
switch (svcinfo->svcpath[svc][svcno])
{
case SVC_LOCAL:
maptype[svcno] = "files";
break;
case SVC_YP:
maptype[svcno] = "nis";
break;
case SVC_BIND:
maptype[svcno] = "dns";
break;
# ifdef SVC_HESIOD
case SVC_HESIOD:
maptype[svcno] = "hesiod";
break;
# endif
case SVC_LAST:
errno = save_errno;
return svcno;
}
}
errno = save_errno;
return svcno;
#endif
#if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
STAB *st;
static time_t servicecachetime;
time_t now = curtime();
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
{
register SM_FILE_T *fp;
long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
DontBlameSendmail))
sff |= SFF_NOWLINK;
if (ConfigFileRead)
servicecachetime = now;
fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
if (fp != NULL)
{
char buf[MAXLINE];
while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
sizeof(buf)) != NULL)
{
register char *p;
p = strpbrk(buf, "#\n");
if (p != NULL)
*p = '\0';
#ifndef SM_NSSWITCH_DELIMS
# define SM_NSSWITCH_DELIMS " \t"
#endif
p = strpbrk(buf, SM_NSSWITCH_DELIMS);
if (p != NULL)
*p++ = '\0';
if (buf[0] == '\0')
continue;
if (p == NULL)
{
sm_syslog(LOG_ERR, NOQID,
"Bad line on %.100s: %.100s",
ServiceSwitchFile,
buf);
continue;
}
while (isascii(*p) && isspace(*p))
p++;
if (*p == '\0')
continue;
st = stab(buf, ST_SERVICE, ST_ENTER);
if (st->s_service[0] != NULL)
sm_free((void *) st->s_service[0]);
p = newstr(p);
for (svcno = 0; svcno < MAXMAPSTACK; )
{
if (*p == '\0')
break;
st->s_service[svcno++] = p;
p = strpbrk(p, " \t");
if (p == NULL)
break;
*p++ = '\0';
while (isascii(*p) && isspace(*p))
p++;
}
if (svcno < MAXMAPSTACK)
st->s_service[svcno] = NULL;
}
(void) sm_io_close(fp, SM_TIME_DEFAULT);
}
}
st = stab(service, ST_SERVICE, ST_FIND);
if (st != NULL && st->s_service[0] != NULL)
{
svcno = 0;
while (svcno < MAXMAPSTACK)
{
maptype[svcno] = st->s_service[svcno];
if (maptype[svcno++] == NULL)
break;
}
errno = save_errno;
return --svcno;
}
#endif
#if !defined(_USE_SUN_NSSWITCH_)
# ifdef _USE_DEC_SVC_CONF_
punt:
# endif
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
svcno = 0;
if (strcmp(service, "aliases") == 0)
{
maptype[svcno++] = "files";
# if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
maptype[svcno++] = "netinfo";
# endif
# ifdef AUTO_NIS_ALIASES
# if NISPLUS
maptype[svcno++] = "nisplus";
# endif
# if NIS
maptype[svcno++] = "nis";
# endif
# endif
errno = save_errno;
return svcno;
}
if (strcmp(service, "hosts") == 0)
{
# if NAMED_BIND
maptype[svcno++] = "dns";
# else
# if defined(sun) && !defined(BSD)
maptype[svcno++] = "nis";
# endif
# endif
# if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
maptype[svcno++] = "netinfo";
# endif
maptype[svcno++] = "files";
errno = save_errno;
return svcno;
}
errno = save_errno;
return -1;
#endif
}
char *
username()
{
static char *myname = NULL;
extern char *getlogin();
register struct passwd *pw;
if (myname == NULL)
{
myname = getlogin();
if (myname == NULL || myname[0] == '\0')
{
pw = sm_getpwuid(RealUid);
if (pw != NULL)
myname = pw->pw_name;
}
else
{
uid_t uid = RealUid;
if ((pw = sm_getpwnam(myname)) == NULL ||
(uid != 0 && uid != pw->pw_uid))
{
pw = sm_getpwuid(uid);
if (pw != NULL)
myname = pw->pw_name;
}
}
if (myname == NULL || myname[0] == '\0')
{
syserr("554 5.3.0 Who are you?");
myname = "postmaster";
}
else if (strpbrk(myname, ",;:/|\"\\") != NULL)
myname = addquotes(myname, NULL);
else
myname = sm_pstrdup_x(myname);
}
return myname;
}
char *
ttypath()
{
struct stat stbuf;
register char *pathn;
extern char *ttyname();
extern char *getlogin();
if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
(pathn = ttyname(0)) == NULL)
{
errno = 0;
return NULL;
}
if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
{
errno = 0;
return NULL;
}
if (getlogin() == NULL)
return NULL;
return pathn;
}
int
checkcompat(to, e)
register ADDRESS *to;
register ENVELOPE *e;
{
if (tTd(49, 1))
sm_dprintf("checkcompat(to=%s, from=%s)\n",
to->q_paddr, e->e_from.q_paddr);
#ifdef EXAMPLE_CODE
register STAB *s;
s = stab("arpa", ST_MAILER, ST_FIND);
if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
to->q_mailer == s->s_mailer)
{
usrerr("553 No ARPA mail through this machine: see your system administration");
to->q_status = "5.7.1";
return EX_UNAVAILABLE;
}
#endif
return EX_OK;
}
#ifdef SUN_EXTENSIONS
static void
init_md_sun()
{
struct stat sbuf;
if (fstat(fileno(stdin), &sbuf) < 0)
{
if (errno == EOVERFLOW)
{
perror("stdin");
exit(EX_NOINPUT);
}
}
}
#endif
#ifdef _AUX_SOURCE
# include <compat.h>
#endif
#if SHARE_V1
# include <shares.h>
#endif
void
init_md(argc, argv)
int argc;
char **argv;
{
#ifdef _AUX_SOURCE
setcompat(getcompat() | COMPAT_BSDPROT);
#endif
#ifdef SUN_EXTENSIONS
init_md_sun();
#endif
#if _CONVEX_SOURCE
set_domain_trim_off();
#endif
#if defined(__QNX__) && !defined(__QNXNTO__)
__sock_locate();
#endif
#if SECUREWARE || defined(_SCO_unix_)
set_auth_parameters(argc, argv);
# ifdef _SCO_unix_
if (getluid() == -1)
setluid(0);
# endif
#endif
#ifdef VENDOR_DEFAULT
VendorCode = VENDOR_DEFAULT;
#else
VendorCode = VENDOR_BERKELEY;
#endif
}
void
init_vendor_macros(e)
register ENVELOPE *e;
{
}
#define LA_ZERO 1
#define LA_INT 2
#define LA_FLOAT 3
#define LA_SUBR 4
#define LA_MACH 5
#define LA_SHORT 6
#define LA_PROCSTR 7
#define LA_READKSYM 8
#define LA_DGUX 9
#define LA_HPUX 10
#define LA_IRIX6 11
#define LA_KSTAT 12
#define LA_DEVSHORT 13
#define LA_ALPHAOSF 14
#define LA_PSET 15
#define LA_LONGLONG 17
#ifndef LA_TYPE
# define LA_TYPE LA_ZERO
#endif
#ifndef FSHIFT
# if defined(unixpc)
# define FSHIFT 5
# endif
# if defined(__alpha) || defined(IRIX)
# define FSHIFT 10
# endif
#endif
#ifndef FSHIFT
# define FSHIFT 8
#endif
#ifndef FSCALE
# define FSCALE (1 << FSHIFT)
#endif
#ifndef LA_AVENRUN
# ifdef SYSTEM5
# define LA_AVENRUN "avenrun"
# else
# define LA_AVENRUN "_avenrun"
# endif
#endif
#ifndef _PATH_KMEM
# define _PATH_KMEM "/dev/kmem"
#endif
#if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
# include <nlist.h>
# ifndef _PATH_UNIX
# if defined(SYSTEM5)
# define _PATH_UNIX "/unix"
# else
# define _PATH_UNIX "/vmunix"
# endif
# endif
# ifdef _AUX_SOURCE
struct nlist Nl[2];
# else
struct nlist Nl[] =
{
{ LA_AVENRUN },
{ 0 },
};
# endif
# define X_AVENRUN 0
int
getla()
{
int j;
static int kmem = -1;
# if LA_TYPE == LA_INT
long avenrun[3];
# else
# if LA_TYPE == LA_SHORT
short avenrun[3];
# else
# if LA_TYPE == LA_LONGLONG
long long avenrun[3];
# else
double avenrun[3];
# endif
# endif
# endif
extern off_t lseek();
if (kmem < 0)
{
# ifdef _AUX_SOURCE
(void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
sizeof(Nl[X_AVENRUN].n_name));
Nl[1].n_name[0] = '\0';
# endif
# if defined(_AIX3) || defined(_AIX4)
if (knlist(Nl, 1, sizeof(Nl[0])) < 0)
# else
if (nlist(_PATH_UNIX, Nl) < 0)
# endif
{
if (tTd(3, 1))
sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
sm_errstring(errno));
return -1;
}
if (Nl[X_AVENRUN].n_value == 0)
{
if (tTd(3, 1))
sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
_PATH_UNIX, LA_AVENRUN);
return -1;
}
# ifdef NAMELISTMASK
Nl[X_AVENRUN].n_value &= NAMELISTMASK;
# endif
kmem = open(_PATH_KMEM, 0, 0);
if (kmem < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: open(/dev/kmem): %s\n",
sm_errstring(errno));
return -1;
}
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
sm_errstring(errno));
(void) close(kmem);
kmem = -1;
return -1;
}
}
if (tTd(3, 20))
sm_dprintf("getla: symbol address = %#lx\n",
(unsigned long) Nl[X_AVENRUN].n_value);
if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
{
if (tTd(3, 1))
sm_dprintf("getla: lseek or read: %s\n",
sm_errstring(errno));
return -1;
}
# if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
if (tTd(3, 5))
{
# if LA_TYPE == LA_SHORT
sm_dprintf("getla: avenrun = %d", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
# else
# if LA_TYPE == LA_LONGLONG
sm_dprintf("getla: avenrun = %lld", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
# else
sm_dprintf("getla: avenrun = %ld", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
# endif
# endif
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) (avenrun[0] + FSCALE/2) >> FSHIFT);
return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
# else
if (tTd(3, 5))
{
sm_dprintf("getla: avenrun = %g", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
return ((int) (avenrun[0] + 0.5));
# endif
}
#endif
#if LA_TYPE == LA_READKSYM
# include <sys/ksym.h>
int
getla()
{
int j;
static int kmem = -1;
long avenrun[3];
struct mioc_rksym mirk;
if (kmem < 0)
{
kmem = open("/dev/kmem", 0, 0);
if (kmem < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: open(/dev/kmem): %s\n",
sm_errstring(errno));
return -1;
}
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
sm_errstring(errno));
(void) close(kmem);
kmem = -1;
return -1;
}
}
mirk.mirk_symname = LA_AVENRUN;
mirk.mirk_buf = avenrun;
mirk.mirk_buflen = sizeof(avenrun);
if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
sm_errstring(errno));
return -1;
}
if (tTd(3, 5))
{
sm_dprintf("getla: avenrun = %d", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) (avenrun[0] + FSCALE/2) >> FSHIFT);
return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
}
#endif
#if LA_TYPE == LA_DGUX
# include <sys/dg_sys_info.h>
int
getla()
{
struct dg_sys_info_load_info load_info;
dg_sys_info((long *)&load_info,
DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
return ((int) (load_info.one_minute + 0.5));
}
#endif
#if LA_TYPE == LA_HPUX
struct pst_dynamic;
struct pst_status;
struct pst_static;
struct pst_vminfo;
struct pst_diskinfo;
struct pst_processor;
struct pst_lv;
struct pst_swapinfo;
# include <sys/param.h>
# include <sys/pstat.h>
int
getla()
{
struct pst_dynamic pstd;
if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
(size_t) 1, 0) == -1)
return 0;
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
return (int) (pstd.psd_avg_1_min + 0.5);
}
#endif
#if LA_TYPE == LA_SUBR
int
getla()
{
double avenrun[3];
if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: getloadavg failed: %s",
sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
return ((int) (avenrun[0] + 0.5));
}
#endif
#if LA_TYPE == LA_MACH
# if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
# include <mach/mach.h>
# else
# include <mach.h>
# endif
int
getla()
{
processor_set_t default_set;
kern_return_t error;
unsigned int info_count;
struct processor_set_basic_info info;
host_t host;
error = processor_set_default(host_self(), &default_set);
if (error != KERN_SUCCESS)
{
if (tTd(3, 1))
sm_dprintf("getla: processor_set_default failed: %s",
sm_errstring(errno));
return -1;
}
info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
&host, (processor_set_info_t)&info,
&info_count) != KERN_SUCCESS)
{
if (tTd(3, 1))
sm_dprintf("getla: processor_set_info failed: %s",
sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) ((info.load_average + (LOAD_SCALE / 2)) /
LOAD_SCALE));
return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
}
#endif
#if LA_TYPE == LA_PROCSTR
# if SM_CONF_BROKEN_STRTOD
ERROR: This OS has most likely a broken strtod() implemenentation.
ERROR: The function is required for getla().
ERROR: Check the compilation options _LA_PROCSTR and
ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
# endif
# ifndef _PATH_LOADAVG
# define _PATH_LOADAVG "/proc/loadavg"
# endif
int
getla()
{
double avenrun;
register int result;
SM_FILE_T *fp;
fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
NULL);
if (fp == NULL)
{
if (tTd(3, 1))
sm_dprintf("getla: sm_io_open(%s): %s\n",
_PATH_LOADAVG, sm_errstring(errno));
return -1;
}
result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
(void) sm_io_close(fp, SM_TIME_DEFAULT);
if (result != 1)
{
if (tTd(3, 1))
sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
result, sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla(): %.2f\n", avenrun);
return ((int) (avenrun + 0.5));
}
#endif
#if LA_TYPE == LA_IRIX6
# include <sys/sysmp.h>
# ifdef _UNICOSMP
# define CAST_SYSMP(x) (x)
# else
# define CAST_SYSMP(x) ((x) & 0x7fffffff)
# endif
int
getla(void)
{
int j;
static int kmem = -1;
int avenrun[3];
if (kmem < 0)
{
kmem = open(_PATH_KMEM, 0, 0);
if (kmem < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
sm_errstring(errno));
return -1;
}
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
sm_errstring(errno));
(void) close(kmem);
kmem = -1;
return -1;
}
}
if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
== -1 ||
read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
{
if (tTd(3, 1))
sm_dprintf("getla: lseek or read: %s\n",
sm_errstring(errno));
return -1;
}
if (tTd(3, 5))
{
sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %ld, %ld",
(long int) avenrun[1], (long int) avenrun[2]);
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) (avenrun[0] + FSCALE/2) >> FSHIFT);
return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
}
#endif
#if LA_TYPE == LA_KSTAT
# include <kstat.h>
int
getla()
{
static kstat_ctl_t *kc = NULL;
static kstat_t *ksp = NULL;
kstat_named_t *ksn;
int la;
if (kc == NULL)
kc = kstat_open();
if (kc == NULL)
{
if (tTd(3, 1))
sm_dprintf("getla: kstat_open(): %s\n",
sm_errstring(errno));
return -1;
}
if (ksp == NULL)
ksp = kstat_lookup(kc, "unix", 0, "system_misc");
if (ksp == NULL)
{
if (tTd(3, 1))
sm_dprintf("getla: kstat_lookup(): %s\n",
sm_errstring(errno));
return -1;
}
if (kstat_read(kc, ksp, NULL) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: kstat_read(): %s\n",
sm_errstring(errno));
return -1;
}
ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
return la;
}
#endif
#if LA_TYPE == LA_DEVSHORT
# ifndef _PATH_AVENRUN
# define _PATH_AVENRUN "/dev/table/avenrun"
# endif
int
getla()
{
static int afd = -1;
short avenrun;
int loadav;
int r;
errno = EBADF;
if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
{
if (errno != EBADF)
return -1;
afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
if (afd < 0)
{
sm_syslog(LOG_ERR, NOQID,
"can't open %s: %s",
_PATH_AVENRUN, sm_errstring(errno));
return -1;
}
}
r = read(afd, &avenrun, sizeof(avenrun));
if (r != sizeof(avenrun))
{
sm_syslog(LOG_ERR, NOQID,
"can't read %s: %s", _PATH_AVENRUN,
r == -1 ? sm_errstring(errno) : "short read");
return -1;
}
if (tTd(3, 5))
sm_dprintf("getla: avenrun = %d\n", avenrun);
loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
if (tTd(3, 1))
sm_dprintf("getla: %d\n", loadav);
return loadav;
}
#endif
#if LA_TYPE == LA_ALPHAOSF
struct rtentry;
struct mbuf;
# include <sys/table.h>
int
getla()
{
int ave = 0;
struct tbl_loadavg tab;
if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
{
if (tTd(3, 1))
sm_dprintf("getla: table %s\n", sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
if (tab.tl_lscale)
ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
tab.tl_lscale);
else
ave = (int) (tab.tl_avenrun.d[2] + 0.5);
if (tTd(3, 1))
sm_dprintf("getla: %d\n", ave);
return ave;
}
#endif
#if LA_TYPE == LA_PSET
int
getla()
{
double avenrun[3];
if (pset_getloadavg(PS_MYID, avenrun,
sizeof(avenrun) / sizeof(avenrun[0])) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: pset_getloadavg failed: %s",
sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
return ((int) (avenrun[0] + 0.5));
}
#endif
#if LA_TYPE == LA_ZERO
int
getla()
{
if (tTd(3, 1))
sm_dprintf("getla: ZERO\n");
return 0;
}
#endif
#ifndef lint
SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
#endif
#ifdef apollo
# undef volatile
# include <apollo/base.h>
int getloadavg( call_data )
caddr_t call_data;
{
double *avenrun = (double *) call_data;
int i;
status_$t st;
long loadav[3];
proc1_$get_loadav(loadav, &st);
*avenrun = loadav[0] / (double) (1 << 16);
return 0;
}
#endif
void
sm_getla()
{
char labuf[8];
CurrentLA = getla();
(void) sm_snprintf(labuf, sizeof(labuf), "%d", CurrentLA);
macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
}
bool
shouldqueue(pri, ct)
long pri;
time_t ct;
{
bool rval;
#if _FFR_MEMSTAT
long memfree;
#endif
if (tTd(3, 30))
sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
CurrentLA, pri);
#if _FFR_MEMSTAT
if (QueueLowMem > 0 &&
sm_memstat_get(MemoryResource, &memfree) >= 0 &&
memfree < QueueLowMem)
{
if (tTd(3, 30))
sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n",
memfree, QueueLowMem);
return true;
}
#endif
if (CurrentLA < QueueLA)
{
if (tTd(3, 30))
sm_dprintf("false (CurrentLA < QueueLA)\n");
return false;
}
rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
if (tTd(3, 30))
sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
return rval;
}
bool
refuseconnections(e, dn, active)
ENVELOPE *e;
int dn;
bool active;
{
static time_t lastconn[MAXDAEMONS];
static int conncnt[MAXDAEMONS];
static time_t firstrejtime[MAXDAEMONS];
static time_t nextlogtime[MAXDAEMONS];
int limit;
#if _FFR_MEMSTAT
long memfree;
#endif
#if XLA
if (!xla_smtp_ok())
return true;
#endif
SM_ASSERT(dn >= 0);
SM_ASSERT(dn < MAXDAEMONS);
if (ConnRateThrottle > 0)
{
time_t now;
now = curtime();
if (active)
{
if (now != lastconn[dn])
{
lastconn[dn] = now;
conncnt[dn] = 1;
}
else if (conncnt[dn]++ > ConnRateThrottle)
{
#define D_MSG_CRT "deferring connections on daemon %s: %d per second"
sm_setproctitle(true, e, D_MSG_CRT,
Daemons[dn].d_name,
ConnRateThrottle);
if (LogLevel > 8)
sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
Daemons[dn].d_name,
ConnRateThrottle);
(void) sleep(1);
}
}
else if (now != lastconn[dn])
conncnt[dn] = 0;
}
#if _FFR_MEMSTAT
if (RefuseLowMem > 0 &&
sm_memstat_get(MemoryResource, &memfree) >= 0 &&
memfree < RefuseLowMem)
{
# define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
sm_setproctitle(true, e, R_MSG_LM, Daemons[dn].d_name, memfree);
if (LogLevel > 8)
sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM,
Daemons[dn].d_name, memfree);
return true;
}
#endif
sm_getla();
limit = (Daemons[dn].d_refuseLA != DPO_NOTSET) ?
Daemons[dn].d_refuseLA : RefuseLA;
if (limit > 0 && CurrentLA >= limit)
{
time_t now;
# define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
# define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
sm_setproctitle(true, e, R_MSG_LA, Daemons[dn].d_name,
CurrentLA);
if (LogLevel > 8)
sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA,
Daemons[dn].d_name, CurrentLA);
now = curtime();
if (firstrejtime[dn] == 0)
{
firstrejtime[dn] = now;
nextlogtime[dn] = now + RejectLogInterval;
}
else if (nextlogtime[dn] < now)
{
sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, Daemons[dn].d_name,
pintvl(now - firstrejtime[dn], true));
nextlogtime[dn] = now + RejectLogInterval;
}
return true;
}
else
firstrejtime[dn] = 0;
limit = (Daemons[dn].d_delayLA != DPO_NOTSET) ?
Daemons[dn].d_delayLA : DelayLA;
if (limit > 0 && CurrentLA >= limit)
{
time_t now;
static time_t log_delay = (time_t) 0;
# define MIN_DELAY_LOG 90
# define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
sm_setproctitle(true, e, D_MSG_LA, Daemons[dn].d_name,
CurrentLA, limit);
if (LogLevel > 8 && (now = curtime()) > log_delay)
{
sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
Daemons[dn].d_name, CurrentLA, limit);
log_delay = now + MIN_DELAY_LOG;
}
(void) sleep(1);
}
limit = (Daemons[dn].d_maxchildren != DPO_NOTSET) ?
Daemons[dn].d_maxchildren : MaxChildren;
if (limit > 0 && CurChildren >= limit)
{
proc_list_probe();
if (CurChildren >= limit)
{
#define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
sm_setproctitle(true, e, R_MSG_CHILD,
Daemons[dn].d_name, CurChildren,
limit);
if (LogLevel > 8)
sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
Daemons[dn].d_name, CurChildren,
limit);
return true;
}
}
return false;
}
#define SPT_NONE 0
#define SPT_REUSEARGV 1
#define SPT_BUILTIN 2
#define SPT_PSTAT 3
#define SPT_PSSTRINGS 4
#define SPT_SYSMIPS 5
#define SPT_SCO 6
#define SPT_CHANGEARGV 7
#ifndef SPT_TYPE
# define SPT_TYPE SPT_REUSEARGV
#endif
#if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
# if SPT_TYPE == SPT_PSTAT
# include <sys/pstat.h>
# endif
# if SPT_TYPE == SPT_PSSTRINGS
# include <machine/vmparam.h>
# include <sys/exec.h>
# ifndef PS_STRINGS
# undef SPT_TYPE
# define SPT_TYPE SPT_REUSEARGV
# else
# ifndef NKPDE
# define NKPDE 63
typedef unsigned int *pt_entry_t;
# endif
# endif
# endif
# if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
# define SETPROC_STATIC static
# else
# define SETPROC_STATIC
# endif
# if SPT_TYPE == SPT_SYSMIPS
# include <sys/sysmips.h>
# include <sys/sysnews.h>
# endif
# if SPT_TYPE == SPT_SCO
# include <sys/immu.h>
# include <sys/dir.h>
# include <sys/user.h>
# include <sys/fs/s5param.h>
# if PSARGSZ > MAXLINE
# define SPT_BUFSIZE PSARGSZ
# endif
# endif
# ifndef SPT_PADCHAR
# define SPT_PADCHAR ' '
# endif
#endif
#ifndef SPT_BUFSIZE
# define SPT_BUFSIZE MAXLINE
#endif
#if _FFR_SPT_ALIGN
# ifdef SPT_ALIGN_SIZE
# define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
# else
# define SPT_ALIGN(x, align) (x)
# endif
#else
# define SPT_ALIGN(x, align) (x)
#endif
static char **Argv = NULL;
static char *LastArgv = NULL;
#if SPT_TYPE != SPT_BUILTIN
static void setproctitle __P((const char *, ...));
#endif
void
initsetproctitle(argc, argv, envp)
int argc;
char **argv;
char **envp;
{
register int i;
int align;
extern char **environ;
if (envp != NULL)
{
for (i = 0; envp[i] != NULL; i++)
continue;
environ = (char **) xalloc(sizeof(char *) * (i + 1));
for (i = 0; envp[i] != NULL; i++)
environ[i] = newstr(envp[i]);
environ[i] = NULL;
}
Argv = argv;
align = -1;
# if _FFR_SPT_ALIGN
# ifdef SPT_ALIGN_SIZE
for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
align++;
# endif
# endif
for (i = 0; i < argc; i++)
{
if (i == 0 || LastArgv + 1 == argv[i])
LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
}
for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
{
if (LastArgv + 1 == envp[i])
LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
}
}
#if SPT_TYPE != SPT_BUILTIN
static void
# ifdef __STDC__
setproctitle(const char *fmt, ...)
# else
setproctitle(fmt, va_alist)
const char *fmt;
va_dcl
# endif
{
# if SPT_TYPE != SPT_NONE
register int i;
register char *p;
SETPROC_STATIC char buf[SPT_BUFSIZE];
SM_VA_LOCAL_DECL
# if SPT_TYPE == SPT_PSTAT
union pstun pst;
# endif
# if SPT_TYPE == SPT_SCO
int j;
off_t seek_off;
static int kmem = -1;
static pid_t kmempid = -1;
struct user u;
# endif
p = buf;
(void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
p += strlen(p);
SM_VA_START(ap, fmt);
(void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
SM_VA_END(ap);
i = (int) strlen(buf);
if (i < 0)
return;
# if SPT_TYPE == SPT_PSTAT
pst.pst_command = buf;
pstat(PSTAT_SETCMD, pst, i, 0, 0);
# endif
# if SPT_TYPE == SPT_PSSTRINGS
PS_STRINGS->ps_nargvstr = 1;
PS_STRINGS->ps_argvstr = buf;
# endif
# if SPT_TYPE == SPT_SYSMIPS
sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
# endif
# if SPT_TYPE == SPT_SCO
if (kmem < 0 || kmempid != CurrentPid)
{
if (kmem >= 0)
(void) close(kmem);
kmem = open(_PATH_KMEM, O_RDWR, 0);
if (kmem < 0)
return;
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
(void) close(kmem);
kmem = -1;
return;
}
kmempid = CurrentPid;
}
buf[PSARGSZ - 1] = '\0';
seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
(void) write(kmem, buf, PSARGSZ);
# endif
# if SPT_TYPE == SPT_REUSEARGV
if (LastArgv == NULL)
return;
if (i > LastArgv - Argv[0] - 2)
{
i = LastArgv - Argv[0] - 2;
buf[i] = '\0';
}
(void) sm_strlcpy(Argv[0], buf, i + 1);
p = &Argv[0][i];
while (p < LastArgv)
*p++ = SPT_PADCHAR;
Argv[1] = NULL;
# endif
# if SPT_TYPE == SPT_CHANGEARGV
Argv[0] = buf;
Argv[1] = 0;
# endif
# endif
}
#endif
void
#ifdef __STDC__
sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
#else
sm_setproctitle(status, e, fmt, va_alist)
bool status;
ENVELOPE *e;
const char *fmt;
va_dcl
#endif
{
char buf[SPT_BUFSIZE];
SM_VA_LOCAL_DECL
SM_VA_START(ap, fmt);
(void) sm_vsnprintf(buf, sizeof(buf), fmt, ap);
SM_VA_END(ap);
if (status)
proc_list_set(CurrentPid, buf);
if (ProcTitlePrefix != NULL)
{
char prefix[SPT_BUFSIZE];
expand(ProcTitlePrefix, prefix, sizeof(prefix), e);
setproctitle("%s: %s", prefix, buf);
}
else
setproctitle("%s", buf);
}
int
waitfor(pid)
pid_t pid;
{
int st;
pid_t i;
do
{
errno = 0;
i = sm_wait(&st);
if (i > 0)
proc_list_drop(i, st, NULL);
} while ((i >= 0 || errno == EINTR) && i != pid);
if (i < 0)
return -1;
return st;
}
pid_t
sm_wait(status)
int *status;
{
# ifdef WAITUNION
union wait st;
# else
auto int st;
# endif
pid_t i;
# if defined(ISC_UNIX) || defined(_SCO_unix_)
int savesig;
# endif
# if defined(ISC_UNIX) || defined(_SCO_unix_)
savesig = sm_releasesignal(SIGCHLD);
# endif
i = wait(&st);
# if defined(ISC_UNIX) || defined(_SCO_unix_)
if (savesig > 0)
sm_blocksignal(SIGCHLD);
# endif
# ifdef WAITUNION
*status = st.w_status;
# else
*status = st;
# endif
return i;
}
SIGFUNC_DECL
reapchild(sig)
int sig;
{
int save_errno = errno;
int st;
pid_t pid;
# if HASWAITPID
auto int status;
int count;
count = 0;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
{
st = status;
if (count++ > 1000)
break;
# else
# ifdef WNOHANG
union wait status;
while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
{
st = status.w_status;
# else
auto int status;
if ((pid = wait(&status)) > 0)
{
st = status;
# endif
# endif
proc_list_drop(pid, st, NULL);
}
FIX_SYSV_SIGNAL(sig, reapchild);
errno = save_errno;
return SIGFUNC_RETURN;
}
#ifdef SOLARIS
# include <sys/resource.h>
#endif
int
getdtsize()
{
# ifdef RLIMIT_NOFILE
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
return rl.rlim_cur;
# endif
# if HASGETDTABLESIZE
return getdtablesize();
# else
# ifdef _SC_OPEN_MAX
return sysconf(_SC_OPEN_MAX);
# else
return NOFILE;
# endif
# endif
}
#if !HASUNAME
int
uname(name)
struct utsname *name;
{
SM_FILE_T *file;
char *n;
name->nodename[0] = '\0';
if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
SM_IO_RDONLY, NULL)) != NULL)
{
(void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
NODE_LENGTH + 1);
(void) sm_io_close(file, SM_TIME_DEFAULT);
n = strchr(name->nodename, '\n');
if (n != NULL)
*n = '\0';
if (name->nodename[0] != '\0')
return 0;
}
if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
"/usr/include/whoami.h", SM_IO_RDONLY, NULL))
!= NULL)
{
char buf[MAXLINE];
while (sm_io_fgets(file, SM_TIME_DEFAULT,
buf, sizeof(buf)) != NULL)
{
if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
NODE_LENGTH, name->nodename) > 0)
break;
}
(void) sm_io_close(file, SM_TIME_DEFAULT);
if (name->nodename[0] != '\0')
return 0;
}
return -1;
}
#endif
#if !HASINITGROUPS
initgroups(name, basegid)
char *name;
int basegid;
{
return 0;
}
#endif
#ifndef NGROUPS_MAX
int
setgroups(ngroups, grouplist)
int ngroups;
GIDSET_T grouplist[];
{
return 0;
}
#endif
#if !HASSETSID
pid_t
setsid __P ((void))
{
# ifdef TIOCNOTTY
int fd;
fd = open("/dev/tty", O_RDWR, 0);
if (fd >= 0)
{
(void) ioctl(fd, TIOCNOTTY, (char *) 0);
(void) close(fd);
}
# endif
# ifdef SYS5SETPGRP
return setpgrp();
# else
return setpgid(0, CurrentPid);
# endif
}
#endif
#if NEEDFSYNC
fsync(fd)
int fd;
{
# ifdef O_SYNC
return fcntl(fd, F_SETFL, O_SYNC);
# else
return 0;
# endif
}
#endif
#ifdef DGUX_5_4_2
# undef inet_addr
long
dgux_inet_addr(host)
char *host;
{
struct in_addr haddr;
haddr = inet_addr(host);
return haddr.s_addr;
}
#endif
#if !SM_CONF_GETOPT
# if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
# endif
# ifdef _CONVEX_SOURCE
extern int optind, opterr, optopt;
extern char *optarg;
# else
int opterr = 1;
int optind = 1;
int optopt = 0;
char *optarg = NULL;
# endif
# define BADCH (int)'?'
# define EMSG ""
# define tell(s) if (opterr) \
{sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
(void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
(void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
(void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
return BADCH;}
int
getopt(nargc,nargv,ostr)
int nargc;
char *const *nargv;
const char *ostr;
{
static char *place = EMSG;
static char atend = 0;
register char *oli = NULL;
if (atend) {
atend = 0;
place = EMSG;
}
if(!*place) {
if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
atend++;
return -1;
}
if (*place == '-') {
++optind;
atend++;
return -1;
}
}
if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
if (!*place) ++optind;
tell(": illegal option -- ");
}
if (oli && *++oli != ':') {
optarg = NULL;
if (!*place) ++optind;
}
else {
if (*place) optarg = place;
else if (nargc <= ++optind) {
place = EMSG;
tell(": option requires an argument -- ");
}
else optarg = nargv[optind];
place = EMSG;
++optind;
}
return optopt;
}
#endif
#if !HASGETUSERSHELL
# ifndef _PATH_SHELLS
# define _PATH_SHELLS "/etc/shells"
# endif
# if defined(_AIX3) || defined(_AIX4)
# include <userconf.h>
# if _AIX4 >= 40200
# include <userpw.h>
# endif
# include <usersec.h>
# endif
static char *DefaultUserShells[] =
{
"/bin/sh",
# ifdef MPE
"/SYS/PUB/CI",
# else
"/usr/bin/sh",
"/bin/csh",
"/usr/bin/csh",
# endif
# ifdef __hpux
# ifdef V4FS
"/usr/bin/rsh",
"/usr/bin/ksh",
"/usr/bin/rksh",
"/usr/bin/pam",
"/usr/bin/keysh",
"/usr/bin/posix/sh",
# else
"/bin/rsh",
"/bin/ksh",
"/bin/rksh",
"/bin/pam",
"/usr/bin/keysh",
"/bin/posix/sh",
"/sbin/sh",
# endif
# endif
# if defined(_AIX3) || defined(_AIX4)
"/bin/ksh",
"/usr/bin/ksh",
"/bin/tsh",
"/usr/bin/tsh",
"/bin/bsh",
"/usr/bin/bsh",
# endif
# if defined(__svr4__) || defined(__svr5__)
"/bin/ksh",
"/usr/bin/ksh",
# endif
# ifdef sgi
"/sbin/sh",
"/usr/bin/sh",
"/sbin/bsh",
"/bin/bsh",
"/usr/bin/bsh",
"/sbin/csh",
"/bin/csh",
"/usr/bin/csh",
"/sbin/jsh",
"/bin/jsh",
"/usr/bin/jsh",
"/bin/ksh",
"/sbin/ksh",
"/usr/bin/ksh",
"/sbin/tcsh",
"/bin/tcsh",
"/usr/bin/tcsh",
# endif
NULL
};
#endif
#define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
bool
usershellok(user, shell)
char *user;
char *shell;
{
# if HASGETUSERSHELL
register char *p;
extern char *getusershell();
if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
ConfigLevel <= 1)
return true;
setusershell();
while ((p = getusershell()) != NULL)
if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
break;
endusershell();
return p != NULL;
# else
# if USEGETCONFATTR
auto char *v;
# endif
register SM_FILE_T *shellf;
char buf[MAXLINE];
if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
ConfigLevel <= 1)
return true;
# if USEGETCONFATTR
if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
{
while (*v != '\0')
{
if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
return true;
v += strlen(v) + 1;
}
return false;
}
# endif
shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
SM_IO_RDONLY, NULL);
if (shellf == NULL)
{
char **d;
if (errno != ENOENT && LogLevel > 3)
sm_syslog(LOG_ERR, NOQID,
"usershellok: cannot open %s: %s",
_PATH_SHELLS, sm_errstring(errno));
for (d = DefaultUserShells; *d != NULL; d++)
{
if (strcmp(shell, *d) == 0)
return true;
}
return false;
}
while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
{
register char *p, *q;
p = buf;
while (*p != '\0' && *p != '#' && *p != '/')
p++;
if (*p == '#' || *p == '\0')
continue;
q = p;
while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
p++;
*p = '\0';
if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
{
(void) sm_io_close(shellf, SM_TIME_DEFAULT);
return true;
}
}
(void) sm_io_close(shellf, SM_TIME_DEFAULT);
return false;
# endif
}
# define SFS_NONE 0
# define SFS_USTAT 1
# define SFS_4ARGS 2
# define SFS_VFS 3
# define SFS_MOUNT 4
# define SFS_STATFS 5
# define SFS_STATVFS 6
# ifndef SFS_TYPE
# define SFS_TYPE SFS_NONE
# endif
# if SFS_TYPE == SFS_USTAT
# include <ustat.h>
# endif
# if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
# include <sys/statfs.h>
# endif
# if SFS_TYPE == SFS_VFS
# include <sys/vfs.h>
# endif
# if SFS_TYPE == SFS_MOUNT
# include <sys/mount.h>
# endif
# if SFS_TYPE == SFS_STATVFS
# include <sys/statvfs.h>
# endif
long
freediskspace(dir, bsize)
const char *dir;
long *bsize;
{
# if SFS_TYPE == SFS_NONE
if (bsize != NULL)
*bsize = 4096L;
return (long) LONG_MAX;
# else
# if SFS_TYPE == SFS_USTAT
struct ustat fs;
struct stat statbuf;
# define FSBLOCKSIZE DEV_BSIZE
# define SFS_BAVAIL f_tfree
# else
# if defined(ultrix)
struct fs_data fs;
# define SFS_BAVAIL fd_bfreen
# define FSBLOCKSIZE 1024L
# else
# if SFS_TYPE == SFS_STATVFS
struct statvfs fs;
# define FSBLOCKSIZE fs.f_frsize
# else
struct statfs fs;
# define FSBLOCKSIZE fs.f_bsize
# endif
# endif
# endif
# ifndef SFS_BAVAIL
# define SFS_BAVAIL f_bavail
# endif
# if SFS_TYPE == SFS_USTAT
if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
# else
# if SFS_TYPE == SFS_4ARGS
if (statfs(dir, &fs, sizeof(fs), 0) == 0)
# else
# if SFS_TYPE == SFS_STATVFS
if (statvfs(dir, &fs) == 0)
# else
# if defined(ultrix)
if (statfs(dir, &fs) > 0)
# else
if (statfs(dir, &fs) == 0)
# endif
# endif
# endif
# endif
{
if (bsize != NULL)
*bsize = FSBLOCKSIZE;
if (fs.SFS_BAVAIL <= 0)
return 0;
else if (fs.SFS_BAVAIL > LONG_MAX)
return (long) LONG_MAX;
else
return (long) fs.SFS_BAVAIL;
}
return -1;
# endif
}
bool
enoughdiskspace(msize, e)
long msize;
ENVELOPE *e;
{
int i;
#if _FFR_TESTS
if (tTd(4, 101))
return false;
#endif
if (MinBlocksFree <= 0 && msize <= 0)
{
if (tTd(4, 80))
sm_dprintf("enoughdiskspace: no threshold\n");
return true;
}
filesys_update();
for (i = 0; i < NumQueue; ++i)
{
if (pickqdir(Queue[i], msize, e) < 0)
return false;
}
return true;
}
bool
transienterror(err)
int err;
{
switch (err)
{
case EIO:
case ENXIO:
case EAGAIN:
case ENOMEM:
case ENODEV:
case ENFILE:
case EMFILE:
case ENOSPC:
case ETIMEDOUT:
#ifdef ESTALE
case ESTALE:
#endif
#ifdef ENETDOWN
case ENETDOWN:
#endif
#ifdef ENETUNREACH
case ENETUNREACH:
#endif
#ifdef ENETRESET
case ENETRESET:
#endif
#ifdef ECONNABORTED
case ECONNABORTED:
#endif
#ifdef ECONNRESET
case ECONNRESET:
#endif
#ifdef ENOBUFS
case ENOBUFS:
#endif
#ifdef ESHUTDOWN
case ESHUTDOWN:
#endif
#ifdef ECONNREFUSED
case ECONNREFUSED:
#endif
#ifdef EHOSTDOWN
case EHOSTDOWN:
#endif
#ifdef EHOSTUNREACH
case EHOSTUNREACH:
#endif
#ifdef EDQUOT
case EDQUOT:
#endif
#ifdef EPROCLIM
case EPROCLIM:
#endif
#ifdef EUSERS
case EUSERS:
#endif
#ifdef EDEADLK
case EDEADLK:
#endif
#ifdef EISCONN
case EISCONN:
#endif
#ifdef EINPROGRESS
case EINPROGRESS:
#endif
#ifdef EALREADY
case EALREADY:
#endif
#ifdef EADDRINUSE
case EADDRINUSE:
#endif
#ifdef EADDRNOTAVAIL
case EADDRNOTAVAIL:
#endif
#ifdef ETXTBSY
case ETXTBSY:
#endif
#if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
case ENOSR:
#endif
#ifdef ENOLCK
case ENOLCK:
#endif
case E_SM_OPENTIMEOUT:
return true;
}
return false;
}
bool
lockfile(fd, filename, ext, type)
int fd;
char *filename;
char *ext;
int type;
{
int i;
int save_errno;
# if !HASFLOCK
int action;
struct flock lfd;
if (ext == NULL)
ext = "";
memset(&lfd, '\0', sizeof(lfd));
if (bitset(LOCK_UN, type))
lfd.l_type = F_UNLCK;
else if (bitset(LOCK_EX, type))
lfd.l_type = F_WRLCK;
else
lfd.l_type = F_RDLCK;
if (bitset(LOCK_NB, type))
action = F_SETLK;
else
action = F_SETLKW;
if (tTd(55, 60))
sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
filename, ext, action, lfd.l_type);
while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
continue;
if (i >= 0)
{
if (tTd(55, 60))
sm_dprintf("SUCCESS\n");
return true;
}
save_errno = errno;
if (tTd(55, 60))
sm_dprintf("(%s) ", sm_errstring(save_errno));
if (save_errno == EINVAL)
{
if (tTd(55, 60))
sm_dprintf("SUCCESS\n");
return true;
}
if (!bitset(LOCK_NB, type) ||
(save_errno != EACCES && save_errno != EAGAIN))
{
int omode = fcntl(fd, F_GETFL, 0);
uid_t euid = geteuid();
errno = save_errno;
syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
filename, ext, fd, type, omode, euid);
dumpfd(fd, true, true);
}
# else
if (ext == NULL)
ext = "";
if (tTd(55, 60))
sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
while ((i = flock(fd, type)) < 0 && errno == EINTR)
continue;
if (i >= 0)
{
if (tTd(55, 60))
sm_dprintf("SUCCESS\n");
return true;
}
save_errno = errno;
if (tTd(55, 60))
sm_dprintf("(%s) ", sm_errstring(save_errno));
if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
{
int omode = fcntl(fd, F_GETFL, 0);
uid_t euid = geteuid();
errno = save_errno;
syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
filename, ext, fd, type, omode, euid);
dumpfd(fd, true, true);
}
# endif
if (tTd(55, 60))
sm_dprintf("FAIL\n");
errno = save_errno;
return false;
}
#ifndef IS_SAFE_CHOWN
# define IS_SAFE_CHOWN > 0
#endif
bool
chownsafe(fd, safedir)
int fd;
bool safedir;
{
# if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
(defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
int rval;
if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
return true;
errno = 0;
rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
# if SAFENFSPATHCONF
return errno == 0 && rval IS_SAFE_CHOWN;
# else
return safedir && errno == 0 && rval IS_SAFE_CHOWN;
# endif
# else
return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
# endif
}
#if HASSETRLIMIT
# ifdef RLIMIT_NEEDS_SYS_TIME_H
# include <sm/time.h>
# endif
# include <sys/resource.h>
#endif
void
resetlimits()
{
#if HASSETRLIMIT
struct rlimit lim;
lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
(void) setrlimit(RLIMIT_CPU, &lim);
(void) setrlimit(RLIMIT_FSIZE, &lim);
# ifdef RLIMIT_NOFILE
lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
(void) setrlimit(RLIMIT_NOFILE, &lim);
# endif
#else
# if HASULIMIT
(void) ulimit(2, 0x3fffff);
(void) ulimit(4, FD_SETSIZE);
# endif
#endif
errno = 0;
}
bool
setvendor(vendor)
char *vendor;
{
if (sm_strcasecmp(vendor, "Berkeley") == 0)
{
VendorCode = VENDOR_BERKELEY;
return true;
}
#ifdef SUN_EXTENSIONS
if (sm_strcasecmp(vendor, "Sun") == 0)
{
VendorCode = VENDOR_SUN;
return true;
}
#endif
#ifdef DEC
if (sm_strcasecmp(vendor, "Digital") == 0)
{
VendorCode = VENDOR_DEC;
return true;
}
#endif
#if defined(VENDOR_NAME) && defined(VENDOR_CODE)
if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
{
VendorCode = VENDOR_CODE;
return true;
}
#endif
return false;
}
char *
getvendor(vendorcode)
int vendorcode;
{
#if defined(VENDOR_NAME) && defined(VENDOR_CODE)
if (vendorcode == VENDOR_CODE)
return VENDOR_NAME;
#endif
switch (vendorcode)
{
case VENDOR_BERKELEY:
return "Berkeley";
case VENDOR_SUN:
return "Sun";
case VENDOR_HP:
return "HP";
case VENDOR_IBM:
return "IBM";
case VENDOR_SENDMAIL:
return "Sendmail";
default:
return "Unknown";
}
}
#if SHARE_V1
int DefShareUid;
#endif
void
vendor_pre_defaults(e)
ENVELOPE *e;
{
#if SHARE_V1
DefShareUid = OTHERUID;
#endif
#if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
sun_pre_defaults(e);
#endif
#ifdef apollo
sm_setuserenv("ISP", NULL);
sm_setuserenv("SYSTYPE", NULL);
#endif
}
void
vendor_post_defaults(e)
ENVELOPE *e;
{
#ifdef __QNX__
sm_setuserenv("SOCK", NULL);
#endif
#if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
sun_post_defaults(e);
#endif
}
void
vendor_daemon_setup(e)
ENVELOPE *e;
{
#if HASSETLOGIN
(void) setlogin(RunAsUserName);
#endif
#if SECUREWARE
if (getluid() != -1)
{
usrerr("Daemon cannot have LUID");
finis(false, true, EX_USAGE);
}
#endif
}
void
vendor_set_uid(uid)
UID_T uid;
{
#if SHARE_V1
if (setupshares(uid, syserr) != 0)
syserr("Unable to set up shares");
#endif
#if SECUREWARE
(void) setup_secure(uid);
#endif
}
#if TCPWRAPPERS
# include <tcpd.h>
int allow_severity = LOG_INFO;
int deny_severity = LOG_NOTICE;
#endif
char *
validate_connection(sap, hostname, e)
SOCKADDR *sap;
char *hostname;
ENVELOPE *e;
{
#if TCPWRAPPERS
char *host;
char *addr;
extern int hosts_ctl();
#endif
if (tTd(48, 3))
sm_dprintf("validate_connection(%s, %s)\n",
hostname, anynet_ntoa(sap));
connection_rate_check(sap, e);
if (rscheck("check_relay", hostname, anynet_ntoa(sap),
e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID, NULL) != EX_OK)
{
static char reject[BUFSIZ*2];
extern char MsgBuf[];
if (tTd(48, 4))
sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
if (strlen(MsgBuf) >= 3)
(void) sm_strlcpy(reject, MsgBuf, sizeof(reject));
else
(void) sm_strlcpy(reject, "Access denied", sizeof(reject));
return reject;
}
#if TCPWRAPPERS
if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
host = "unknown";
else
host = hostname;
addr = anynet_ntoa(sap);
# if NETINET6
if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
addr += 5;
# endif
if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
{
if (tTd(48, 4))
sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
if (LogLevel > 3)
sm_syslog(LOG_NOTICE, e->e_id,
"tcpwrappers (%s, %s) rejection",
host, addr);
return "Access denied";
}
#endif
if (tTd(48, 4))
sm_dprintf(" ... validate_connection: OK\n");
return NULL;
}
#if NEEDSTRTOL
# if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
# endif
long
strtol(nptr, endptr, base)
const char *nptr;
char **endptr;
register int base;
{
register const char *s = nptr;
register unsigned long acc;
register int c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
do {
c = *s++;
} while (isascii(c) && isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long) base;
cutoff /= (unsigned long) base;
for (acc = 0, any = 0;; c = *s++) {
if (isascii(c) && isdigit(c))
c -= '0';
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (char *)(any ? s - 1 : nptr);
return acc;
}
#endif
#if NEEDSTRSTR
char *
strstr(big, little)
char *big;
char *little;
{
register char *p = big;
int l;
if (*little == '\0')
return big;
l = strlen(little);
while ((p = strchr(p, *little)) != NULL)
{
if (strncmp(p, little, l) == 0)
return p;
p++;
}
return NULL;
}
#endif
#if NETINET6 && NEEDSGETIPNODE
# ifndef AI_DEFAULT
# define AI_DEFAULT 0
# endif
# ifndef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0
# endif
# ifndef AI_V4MAPPED
# define AI_V4MAPPED 0
# endif
# ifndef AI_ALL
# define AI_ALL 0
# endif
static struct hostent *
getipnodebyname(name, family, flags, err)
char *name;
int family;
int flags;
int *err;
{
bool resv6 = true;
struct hostent *h;
if (family == AF_INET6)
{
resv6 = bitset(RES_USE_INET6, _res.options);
_res.options |= RES_USE_INET6;
}
SM_SET_H_ERRNO(0);
h = gethostbyname(name);
if (!resv6)
_res.options &= ~RES_USE_INET6;
*err = h_errno;
return h;
}
static struct hostent *
getipnodebyaddr(addr, len, family, err)
char *addr;
int len;
int family;
int *err;
{
struct hostent *h;
SM_SET_H_ERRNO(0);
h = gethostbyaddr(addr, len, family);
*err = h_errno;
return h;
}
void
freehostent(h)
struct hostent *h;
{
return;
}
#endif
struct hostent *
sm_gethostbyname(name, family)
char *name;
int family;
{
int save_errno;
struct hostent *h = NULL;
#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
# if SOLARIS == 20300 || SOLARIS == 203
static struct hostent hp;
static char buf[1000];
extern struct hostent *_switch_gethostbyname_r();
if (tTd(61, 10))
sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
save_errno = errno;
# else
extern struct hostent *__switch_gethostbyname();
if (tTd(61, 10))
sm_dprintf("__switch_gethostbyname(%s)... ", name);
h = __switch_gethostbyname(name);
save_errno = errno;
# endif
#else
int nmaps;
# if NETINET6
int flags = AI_DEFAULT|AI_ALL;
int err;
# endif
char *maptype[MAXMAPSTACK];
short mapreturn[MAXMAPACTIONS];
char hbuf[MAXNAME];
if (tTd(61, 10))
sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
# if NETINET6
# if ADDRCONFIG_IS_BROKEN
flags &= ~AI_ADDRCONFIG;
# endif
h = getipnodebyname(name, family, flags, &err);
SM_SET_H_ERRNO(err);
# else
h = gethostbyname(name);
# endif
save_errno = errno;
if (h == NULL)
{
if (tTd(61, 10))
sm_dprintf("failure\n");
nmaps = switch_map_find("hosts", maptype, mapreturn);
while (--nmaps >= 0)
{
if (strcmp(maptype[nmaps], "nis") == 0 ||
strcmp(maptype[nmaps], "files") == 0)
break;
}
if (nmaps >= 0)
{
if (strlen(name) > sizeof(hbuf) - 1)
{
errno = save_errno;
return NULL;
}
(void) sm_strlcpy(hbuf, name, sizeof(hbuf));
(void) shorten_hostname(hbuf);
if (strcmp(hbuf, name) != 0)
{
if (tTd(61, 10))
sm_dprintf("sm_gethostbyname(%s, %d)... ",
hbuf, family);
# if NETINET6
h = getipnodebyname(hbuf, family, flags, &err);
SM_SET_H_ERRNO(err);
save_errno = errno;
# else
h = gethostbyname(hbuf);
save_errno = errno;
# endif
}
}
}
#endif
if (tTd(61, 10))
{
if (h == NULL)
sm_dprintf("failure\n");
else
{
sm_dprintf("%s\n", h->h_name);
if (tTd(61, 11))
{
#if NETINET6
struct in6_addr ia6;
char buf6[INET6_ADDRSTRLEN];
#else
struct in_addr ia;
#endif
size_t i;
if (h->h_aliases != NULL)
for (i = 0; h->h_aliases[i] != NULL;
i++)
sm_dprintf("\talias: %s\n",
h->h_aliases[i]);
for (i = 0; h->h_addr_list[i] != NULL; i++)
{
char *addr;
#if NETINET6
memmove(&ia6, h->h_addr_list[i],
IN6ADDRSZ);
addr = anynet_ntop(&ia6,
buf6, sizeof(buf6));
#else
memmove(&ia, h->h_addr_list[i],
INADDRSZ);
addr = (char *) inet_ntoa(ia);
#endif
if (addr != NULL)
sm_dprintf("\taddr: %s\n", addr);
}
}
}
}
errno = save_errno;
return h;
}
struct hostent *
sm_gethostbyaddr(addr, len, type)
char *addr;
int len;
int type;
{
struct hostent *hp;
#if NETINET6
if (type == AF_INET6 &&
IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
{
SM_SET_H_ERRNO(HOST_NOT_FOUND);
return NULL;
}
#endif
#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
# if SOLARIS == 20300 || SOLARIS == 203
{
static struct hostent he;
static char buf[1000];
extern struct hostent *_switch_gethostbyaddr_r();
hp = _switch_gethostbyaddr_r(addr, len, type, &he,
buf, sizeof(buf), &h_errno);
}
# else
{
extern struct hostent *__switch_gethostbyaddr();
hp = __switch_gethostbyaddr(addr, len, type);
}
# endif
#else
# if NETINET6
{
int err;
hp = getipnodebyaddr(addr, len, type, &err);
SM_SET_H_ERRNO(err);
}
# else
hp = gethostbyaddr(addr, len, type);
# endif
#endif
return hp;
}
struct passwd *
sm_getpwnam(user)
char *user;
{
#ifdef _AIX4
extern struct passwd *_getpwnam_shadow(const char *, const int);
return _getpwnam_shadow(user, 0);
#else
return getpwnam(user);
#endif
}
struct passwd *
sm_getpwuid(uid)
UID_T uid;
{
#if defined(_AIX4) && 0
extern struct passwd *_getpwuid_shadow(const int, const int);
return _getpwuid_shadow(uid,0);
#else
return getpwuid(uid);
#endif
}
#if SECUREWARE
# include <sys/security.h>
# include <prot.h>
void
secureware_setup_secure(uid)
UID_T uid;
{
int rc;
if (getluid() != -1)
return;
if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
{
switch (rc)
{
case SSI_NO_PRPW_ENTRY:
syserr("No protected passwd entry, uid = %d",
(int) uid);
break;
case SSI_LOCKED:
syserr("Account has been disabled, uid = %d",
(int) uid);
break;
case SSI_RETIRED:
syserr("Account has been retired, uid = %d",
(int) uid);
break;
case SSI_BAD_SET_LUID:
syserr("Could not set LUID, uid = %d", (int) uid);
break;
case SSI_BAD_SET_PRIVS:
syserr("Could not set kernel privs, uid = %d",
(int) uid);
default:
syserr("Unknown return code (%d) from set_secure_info(%d)",
rc, (int) uid);
break;
}
finis(false, true, EX_NOPERM);
}
}
#endif
static int
add_hostnames(sa)
SOCKADDR *sa;
{
struct hostent *hp;
char **ha;
char hnb[MAXHOSTNAMELEN];
switch (sa->sa.sa_family)
{
#if NETINET
case AF_INET:
hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
sizeof(sa->sin.sin_addr),
sa->sa.sa_family);
break;
#endif
#if NETINET6
case AF_INET6:
hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
sizeof(sa->sin6.sin6_addr),
sa->sa.sa_family);
break;
#endif
default:
if (LogLevel > 3)
sm_syslog(LOG_WARNING, NOQID,
"Unsupported address family %d: %.100s",
sa->sa.sa_family, anynet_ntoa(sa));
return -1;
}
if (hp == NULL)
{
int save_errno = errno;
if (LogLevel > 3 &&
#if NETINET6
!(sa->sa.sa_family == AF_INET6 &&
IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
#endif
true)
sm_syslog(LOG_WARNING, NOQID,
"gethostbyaddr(%.100s) failed: %d",
anynet_ntoa(sa),
#if NAMED_BIND
h_errno
#else
-1
#endif
);
errno = save_errno;
return -1;
}
if (!wordinclass((char *) hp->h_name, 'w'))
{
setclass('w', (char *) hp->h_name);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
if (sm_snprintf(hnb, sizeof(hnb), "[%s]", hp->h_name) <
sizeof(hnb)
&& !wordinclass((char *) hnb, 'w'))
setclass('w', hnb);
}
else
{
if (tTd(0, 43))
sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
}
for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
{
if (!wordinclass(*ha, 'w'))
{
setclass('w', *ha);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", *ha);
if (sm_snprintf(hnb, sizeof(hnb),
"[%s]", *ha) < sizeof(hnb) &&
!wordinclass((char *) hnb, 'w'))
setclass('w', hnb);
}
else
{
if (tTd(0, 43))
sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
*ha);
}
}
#if NETINET6
freehostent(hp);
#endif
return 0;
}
#if !NETINET
# define SIOCGIFCONF_IS_BROKEN 1
#endif
#if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
struct rtentry;
struct mbuf;
# ifndef SUNOS403
# include <sm/time.h>
# endif
# if (_AIX4 >= 40300) && !defined(_NET_IF_H)
# undef __P
# endif
# include <net/if.h>
#endif
void
load_if_names()
{
# if NETINET6 && defined(SIOCGLIFCONF)
# ifdef __hpux
# define lifconf if_laddrconf
# define lifc_len iflc_len
# define lifc_buf iflc_buf
# define lifreq if_laddrreq
# define lifr_addr iflr_addr
# define lifr_name iflr_name
# define lifr_flags iflr_flags
# define ss_family sa_family
# undef SIOCGLIFNUM
# endif
int s;
int i;
size_t len;
int numifs;
char *buf;
struct lifconf lifc;
# ifdef SIOCGLIFNUM
struct lifnum lifn;
# endif
s = socket(InetMode, SOCK_DGRAM, 0);
if (s == -1)
return;
# ifdef __hpux
i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
# endif
# ifdef SIOCGLIFNUM
lifn.lifn_family = AF_UNSPEC;
lifn.lifn_flags = 0;
i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
numifs = lifn.lifn_count;
# endif
# if defined(__hpux) || defined(SIOCGLIFNUM)
if (i < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGLIFNUM failed: %s\n",
sm_errstring(errno));
numifs = -1;
}
else if (tTd(0, 42))
sm_dprintf("system has %d interfaces\n", numifs);
if (numifs < 0)
# endif
numifs = MAXINTERFACES;
if (numifs <= 0)
{
(void) close(s);
return;
}
len = lifc.lifc_len = numifs * sizeof(struct lifreq);
buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
# ifndef __hpux
lifc.lifc_family = AF_UNSPEC;
lifc.lifc_flags = 0;
# endif
if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGLIFCONF failed: %s\n",
sm_errstring(errno));
(void) close(s);
sm_free(buf);
return;
}
if (tTd(0, 40))
sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
(long) len);
for (i = 0; i < len && i >= 0; )
{
int flags;
struct lifreq *ifr = (struct lifreq *)&buf[i];
SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
int af = ifr->lifr_addr.ss_family;
char *addr;
char *name;
struct in6_addr ia6;
struct in_addr ia;
# ifdef SIOCGLIFFLAGS
struct lifreq ifrf;
# endif
char ip_addr[256];
char buf6[INET6_ADDRSTRLEN];
(void) close(s);
s = socket(af, SOCK_DGRAM, 0);
if (s == -1)
{
sm_free(buf);
return;
}
if ((len - i) < sizeof(*ifr))
break;
# ifdef BSD4_4_SOCKADDR
if (sa->sa.sa_len > sizeof(ifr->lifr_addr))
i += sizeof(ifr->lifr_name) + sa->sa.sa_len;
else
# endif
# ifdef DEC
i += sizeof(ifr->ifr_name) +
max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
# else
i += sizeof(*ifr);
# endif
if (tTd(0, 20))
sm_dprintf("%s\n", anynet_ntoa(sa));
if (af != AF_INET && af != AF_INET6)
continue;
# ifdef SIOCGLIFFLAGS
memset(&ifrf, '\0', sizeof(struct lifreq));
(void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
sizeof(ifrf.lifr_name));
if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
sm_errstring(errno));
continue;
}
name = ifr->lifr_name;
flags = ifrf.lifr_flags;
if (tTd(0, 41))
sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
if (!bitset(IFF_UP, flags))
continue;
# endif
ip_addr[0] = '\0';
switch (af)
{
case AF_INET6:
# ifdef __KAME__
if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
sa->sin6.sin6_scope_id == 0)
{
struct in6_addr *ia6p;
ia6p = &sa->sin6.sin6_addr;
sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
((unsigned int)ia6p->s6_addr[2] << 8));
ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
}
# endif
ia6 = sa->sin6.sin6_addr;
if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
{
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
message("WARNING: interface %s is UP with %s address",
name, addr == NULL ? "(NULL)" : addr);
continue;
}
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
if (addr != NULL)
(void) sm_snprintf(ip_addr, sizeof(ip_addr),
"[%.*s]",
(int) sizeof(ip_addr) - 3,
addr);
break;
case AF_INET:
ia = sa->sin.sin_addr;
if (ia.s_addr == INADDR_ANY ||
ia.s_addr == INADDR_NONE)
{
message("WARNING: interface %s is UP with %s address",
name, inet_ntoa(ia));
continue;
}
(void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
(int) sizeof(ip_addr) - 3, inet_ntoa(ia));
break;
}
if (*ip_addr == '\0')
continue;
if (!wordinclass(ip_addr, 'w'))
{
setclass('w', ip_addr);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", ip_addr);
}
# ifdef SIOCGLIFFLAGS
if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
bitset(IFF_LOOPBACK, flags))
continue;
# endif
(void) add_hostnames(sa);
}
sm_free(buf);
(void) close(s);
# else
# if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
int s;
int i;
struct ifconf ifc;
int numifs;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1)
return;
# if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGIFNUM failed: %s\n",
sm_errstring(errno));
numifs = -1;
}
else if (tTd(0, 42))
sm_dprintf("system has %d interfaces\n", numifs);
if (numifs < 0)
# endif
numifs = MAXINTERFACES;
if (numifs <= 0)
{
(void) close(s);
return;
}
ifc.ifc_len = numifs * sizeof(struct ifreq);
ifc.ifc_buf = xalloc(ifc.ifc_len);
if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGIFCONF failed: %s\n",
sm_errstring(errno));
(void) close(s);
return;
}
if (tTd(0, 40))
sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
ifc.ifc_len);
for (i = 0; i < ifc.ifc_len && i >= 0; )
{
int af;
struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
# if NETINET6
char *addr;
struct in6_addr ia6;
# endif
struct in_addr ia;
# ifdef SIOCGIFFLAGS
struct ifreq ifrf;
# endif
char ip_addr[256];
# if NETINET6
char buf6[INET6_ADDRSTRLEN];
# endif
if ((ifc.ifc_len - i) < sizeof(*ifr))
break;
# ifdef BSD4_4_SOCKADDR
if (sa->sa.sa_len > sizeof(ifr->ifr_addr))
i += sizeof(ifr->ifr_name) + sa->sa.sa_len;
else
# endif
i += sizeof(*ifr);
if (tTd(0, 20))
sm_dprintf("%s\n", anynet_ntoa(sa));
af = ifr->ifr_addr.sa_family;
if (af != AF_INET
# if NETINET6
&& af != AF_INET6
# endif
)
continue;
# ifdef SIOCGIFFLAGS
memset(&ifrf, '\0', sizeof(struct ifreq));
(void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
sizeof(ifrf.ifr_name));
(void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
if (tTd(0, 41))
sm_dprintf("\tflags: %lx\n",
(unsigned long) ifrf.ifr_flags);
# define IFRFREF ifrf
# else
# define IFRFREF (*ifr)
# endif
if (!bitset(IFF_UP, IFRFREF.ifr_flags))
continue;
ip_addr[0] = '\0';
switch (af)
{
case AF_INET:
ia = sa->sin.sin_addr;
if (ia.s_addr == INADDR_ANY ||
ia.s_addr == INADDR_NONE)
{
message("WARNING: interface %s is UP with %s address",
ifr->ifr_name, inet_ntoa(ia));
continue;
}
(void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
(int) sizeof(ip_addr) - 3,
inet_ntoa(ia));
break;
# if NETINET6
case AF_INET6:
# ifdef __KAME__
if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
sa->sin6.sin6_scope_id == 0)
{
struct in6_addr *ia6p;
ia6p = &sa->sin6.sin6_addr;
sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
((unsigned int)ia6p->s6_addr[2] << 8));
ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
}
# endif
ia6 = sa->sin6.sin6_addr;
if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
{
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
message("WARNING: interface %s is UP with %s address",
ifr->ifr_name,
addr == NULL ? "(NULL)" : addr);
continue;
}
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
if (addr != NULL)
(void) sm_snprintf(ip_addr, sizeof(ip_addr),
"[%.*s]",
(int) sizeof(ip_addr) - 3,
addr);
break;
# endif
}
if (ip_addr[0] == '\0')
continue;
if (!wordinclass(ip_addr, 'w'))
{
setclass('w', ip_addr);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", ip_addr);
}
if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
continue;
(void) add_hostnames(sa);
}
sm_free(ifc.ifc_buf);
(void) close(s);
# undef IFRFREF
# endif
# endif
}
bool
isloopback(sa)
SOCKADDR sa;
{
#if NETINET6
if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
return true;
#else
if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
>> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
return true;
#endif
return false;
}
static int
get_num_procs_online()
{
int nproc = 0;
#ifdef USESYSCTL
# if defined(CTL_HW) && defined(HW_NCPU)
size_t sz;
int mib[2];
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
sz = (size_t) sizeof(nproc);
(void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
# endif
#else
# ifdef _SC_NPROCESSORS_ONLN
nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
# else
# ifdef __hpux
# include <sys/pstat.h>
struct pst_dynamic psd;
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
nproc = psd.psd_proc_cnt;
# endif
# endif
#endif
if (nproc <= 0)
nproc = 1;
return nproc;
}
void
sm_closefrom(lowest, highest)
int lowest, highest;
{
#if HASCLOSEFROM
closefrom(lowest);
#else
int i;
for (i = lowest; i < highest; i++)
(void) close(i);
#endif
}
#if HASFDWALK
static int
closefd_walk(lowest, fd)
void *lowest;
int fd;
{
if (fd >= *(int *)lowest)
(void) fcntl(fd, F_SETFD, FD_CLOEXEC);
return 0;
}
#endif
void
sm_close_on_exec(highest, lowest)
int highest, lowest;
{
#if HASFDWALK
(void) fdwalk(closefd_walk, &lowest);
#else
int i, j;
for (i = lowest; i < highest; i++)
{
if ((j = fcntl(i, F_GETFD, 0)) != -1)
(void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
}
#endif
}
void
seed_random()
{
#if HASSRANDOMDEV
srandomdev();
#else
long seed;
struct timeval t;
seed = (long) CurrentPid;
if (gettimeofday(&t, NULL) >= 0)
seed += t.tv_sec + t.tv_usec;
# if HASRANDOM
(void) srandom(seed);
# else
(void) srand((unsigned int) seed);
# endif
#endif
}
void
#ifdef __STDC__
sm_syslog(int level, const char *id, const char *fmt, ...)
#else
sm_syslog(level, id, fmt, va_alist)
int level;
const char *id;
const char *fmt;
va_dcl
#endif
{
char *buf;
size_t bufsize;
char *begin, *end;
int save_errno;
int seq = 1;
int idlen;
char buf0[MAXLINE];
char *newstring;
extern int SyslogPrefixLen;
SM_VA_LOCAL_DECL
save_errno = errno;
if (id == NULL)
id = "NOQUEUE";
idlen = strlen(id) + SyslogPrefixLen;
buf = buf0;
bufsize = sizeof(buf0);
for (;;)
{
int n;
SM_VA_START(ap, fmt);
n = sm_vsnprintf(buf, bufsize, fmt, ap);
SM_VA_END(ap);
SM_ASSERT(n > 0);
if (n < bufsize)
break;
bufsize = n + 1;
if (buf != buf0)
{
sm_free(buf);
buf = NULL;
}
buf = sm_malloc_x(bufsize);
}
newstring = str2prt(buf);
if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
{
#if LOG
if (*id == '\0')
{
if (tTd(89, 8))
sm_dprintf("%s\n", newstring);
else
syslog(level, "%s", newstring);
}
else
{
if (tTd(89, 8))
sm_dprintf("%s: %s\n", id, newstring);
else
syslog(level, "%s: %s", id, newstring);
}
#else
if (*id == '\0')
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
newstring);
else
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s: %s\n", id, newstring);
#endif
if (buf != buf0)
sm_free(buf);
errno = save_errno;
return;
}
#define SL_SPLIT 7
begin = newstring;
idlen += 5;
while (*begin != '\0' &&
(strlen(begin) + idlen) > SYSLOG_BUFSIZE)
{
char save;
if (seq >= 999)
{
break;
}
end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
while (end > begin)
{
if (*end == ',' || *end == ' ')
{
end++;
break;
}
end--;
}
if (end == begin)
end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
save = *end;
*end = 0;
#if LOG
if (tTd(89, 8))
sm_dprintf("%s[%d]: %s ...\n", id, seq++, begin);
else
syslog(level, "%s[%d]: %s ...", id, seq++, begin);
#else
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s[%d]: %s ...\n", id, seq++, begin);
#endif
*end = save;
begin = end;
}
if (seq >= 999)
{
#if LOG
if (tTd(89, 8))
sm_dprintf("%s[%d]: log terminated, too many parts\n",
id, seq);
else
syslog(level, "%s[%d]: log terminated, too many parts",
id, seq);
#else
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s[%d]: log terminated, too many parts\n", id, seq);
#endif
}
else if (*begin != '\0')
{
#if LOG
if (tTd(89, 8))
sm_dprintf("%s[%d]: %s\n", id, seq, begin);
else
syslog(level, "%s[%d]: %s", id, seq, begin);
#else
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s[%d]: %s\n", id, seq, begin);
#endif
}
if (buf != buf0)
sm_free(buf);
errno = save_errno;
}
#if defined(__hpux) && !defined(HPUX11)
# define MAXSYSLOGTRIES 100
# undef syslog
# ifdef V4FS
# define XCNST const
# define CAST (const char *)
# else
# define XCNST
# define CAST
# endif
void
# ifdef __STDC__
hard_syslog(int pri, XCNST char *msg, ...)
# else
hard_syslog(pri, msg, va_alist)
int pri;
XCNST char *msg;
va_dcl
# endif
{
int i;
char buf[SYSLOG_BUFSIZE];
SM_VA_LOCAL_DECL
SM_VA_START(ap, msg);
(void) sm_vsnprintf(buf, sizeof(buf), msg, ap);
SM_VA_END(ap);
for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
continue;
}
# undef CAST
#endif
#if NEEDLOCAL_HOSTNAME_LENGTH
int
local_hostname_length(hostname)
char *hostname;
{
size_t len_host, len_domain;
if (!*_res.defdname)
res_init();
len_host = strlen(hostname);
len_domain = strlen(_res.defdname);
if (len_host > len_domain &&
(sm_strcasecmp(hostname + len_host - len_domain,
_res.defdname) == 0) &&
hostname[len_host - len_domain - 1] == '.')
return len_host - len_domain - 1;
else
return 0;
}
#endif
#if NEEDLINK
int
link(source, target)
const char *source;
const char *target;
{
int save_errno;
int sff;
int src = -1, dst = -1;
ssize_t readlen;
ssize_t writelen;
char buf[BUFSIZ];
struct stat st;
sff = SFF_REGONLY|SFF_OPENASROOT;
if (DontLockReadFiles)
sff |= SFF_NOLOCK;
src = safeopen((char *)source, O_RDONLY, 0, sff);
if (src < 0)
goto fail;
if (fstat(src, &st) < 0)
goto fail;
sff &= ~SFF_NOLOCK;
sff |= SFF_CREAT;
dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
st.st_mode, sff);
if (dst < 0)
goto fail;
while ((readlen = read(src, &buf, sizeof(buf))) > 0)
{
ssize_t left = readlen;
char *p = buf;
while (left > 0 &&
(writelen = write(dst, p, (size_t) left)) >= 0)
{
left -= writelen;
p += writelen;
}
if (writelen < 0)
break;
}
if (readlen < 0 || writelen < 0)
goto fail;
if (close(src) < 0)
{
src = -1;
goto fail;
}
src = -1;
if (close(dst) < 0)
{
goto fail;
}
return 0;
fail:
save_errno = errno;
if (src >= 0)
(void) close(src);
if (dst >= 0)
{
(void) unlink(target);
(void) close(dst);
}
errno = save_errno;
return -1;
}
#endif
char *CompileOptions[] =
{
#if ALLOW_255
"ALLOW_255",
#endif
#if NAMED_BIND
# if DNSMAP
"DNSMAP",
# endif
#endif
#if EGD
"EGD",
#endif
#if HESIOD
"HESIOD",
#endif
#if HES_GETMAILHOST
"HES_GETMAILHOST",
#endif
#if LDAPMAP
"LDAPMAP",
#endif
#if LDAP_REFERRALS
"LDAP_REFERRALS",
#endif
#if LOG
"LOG",
#endif
#if MAP_NSD
"MAP_NSD",
#endif
#if MAP_REGEX
"MAP_REGEX",
#endif
#if MATCHGECOS
"MATCHGECOS",
#endif
#if MILTER
"MILTER",
#endif
#if MIME7TO8
"MIME7TO8",
#endif
#if MIME7TO8_OLD
"MIME7TO8_OLD",
#endif
#if MIME8TO7
"MIME8TO7",
#endif
#if NAMED_BIND
"NAMED_BIND",
#endif
#if NDBM
"NDBM",
#endif
#if NETINET
"NETINET",
#endif
#if NETINET6
"NETINET6",
#endif
#if NETINFO
"NETINFO",
#endif
#if NETISO
"NETISO",
#endif
#if NETNS
"NETNS",
#endif
#if NETUNIX
"NETUNIX",
#endif
#if NETX25
"NETX25",
#endif
#if NEWDB
"NEWDB",
#endif
#if NIS
"NIS",
#endif
#if NISPLUS
"NISPLUS",
#endif
#if NO_DH
"NO_DH",
#endif
#if PH_MAP
"PH_MAP",
#endif
#ifdef PICKY_HELO_CHECK
"PICKY_HELO_CHECK",
#endif
#if PIPELINING
"PIPELINING",
#endif
#if SASL
# if SASL >= 20000
"SASLv2",
# else
"SASL",
# endif
#endif
#if SCANF
"SCANF",
#endif
#if SM_LDAP_ERROR_ON_MISSING_ARGS
"SM_LDAP_ERROR_ON_MISSING_ARGS",
#endif
#if SMTPDEBUG
"SMTPDEBUG",
#endif
#if SOCKETMAP
"SOCKETMAP",
#endif
#if STARTTLS
"STARTTLS",
#endif
#if SUID_ROOT_FILES_OK
"SUID_ROOT_FILES_OK",
#endif
#if TCPWRAPPERS
"TCPWRAPPERS",
#endif
#if TLS_NO_RSA
"TLS_NO_RSA",
#endif
#if TLS_VRFY_PER_CTX
"TLS_VRFY_PER_CTX",
#endif
#if USERDB
"USERDB",
#endif
#if USE_LDAP_INIT
"USE_LDAP_INIT",
#endif
#if USE_TTYPATH
"USE_TTYPATH",
#endif
#if XDEBUG
"XDEBUG",
#endif
#if XLA
"XLA",
#endif
NULL
};
char *OsCompileOptions[] =
{
#if ADDRCONFIG_IS_BROKEN
"ADDRCONFIG_IS_BROKEN",
#endif
#ifdef AUTO_NETINFO_HOSTS
"AUTO_NETINFO_HOSTS",
#endif
#ifdef AUTO_NIS_ALIASES
"AUTO_NIS_ALIASES",
#endif
#if BROKEN_RES_SEARCH
"BROKEN_RES_SEARCH",
#endif
#ifdef BSD4_4_SOCKADDR
"BSD4_4_SOCKADDR",
#endif
#if BOGUS_O_EXCL
"BOGUS_O_EXCL",
#endif
#if DEC_OSF_BROKEN_GETPWENT
"DEC_OSF_BROKEN_GETPWENT",
#endif
#if FAST_PID_RECYCLE
"FAST_PID_RECYCLE",
#endif
#if HASCLOSEFROM
"HASCLOSEFROM",
#endif
#if HASFCHOWN
"HASFCHOWN",
#endif
#if HASFCHMOD
"HASFCHMOD",
#endif
#if HASFDWALK
"HASFDWALK",
#endif
#if HASFLOCK
"HASFLOCK",
#endif
#if HASGETDTABLESIZE
"HASGETDTABLESIZE",
#endif
#if HASGETUSERSHELL
"HASGETUSERSHELL",
#endif
#if HASINITGROUPS
"HASINITGROUPS",
#endif
#if HASLDAPGETALIASBYNAME
"HASLDAPGETALIASBYNAME",
#endif
#if HASLSTAT
"HASLSTAT",
#endif
#if HASNICE
"HASNICE",
#endif
#if HASRANDOM
"HASRANDOM",
#endif
#if HASRRESVPORT
"HASRRESVPORT",
#endif
#if HASSETEGID
"HASSETEGID",
#endif
#if HASSETLOGIN
"HASSETLOGIN",
#endif
#if HASSETREGID
"HASSETREGID",
#endif
#if HASSETRESGID
"HASSETRESGID",
#endif
#if HASSETREUID
"HASSETREUID",
#endif
#if HASSETRLIMIT
"HASSETRLIMIT",
#endif
#if HASSETSID
"HASSETSID",
#endif
#if HASSETUSERCONTEXT
"HASSETUSERCONTEXT",
#endif
#if HASSETVBUF
"HASSETVBUF",
#endif
#if HAS_ST_GEN
"HAS_ST_GEN",
#endif
#if HASSRANDOMDEV
"HASSRANDOMDEV",
#endif
#if HASURANDOMDEV
"HASURANDOMDEV",
#endif
#if HASSTRERROR
"HASSTRERROR",
#endif
#if HASULIMIT
"HASULIMIT",
#endif
#if HASUNAME
"HASUNAME",
#endif
#if HASUNSETENV
"HASUNSETENV",
#endif
#if HASWAITPID
"HASWAITPID",
#endif
#if IDENTPROTO
"IDENTPROTO",
#endif
#if IP_SRCROUTE
"IP_SRCROUTE",
#endif
#if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
"LOCK_ON_OPEN",
#endif
#if MILTER_NO_NAGLE
"MILTER_NO_NAGLE ",
#endif
#if NEEDFSYNC
"NEEDFSYNC",
#endif
#if NEEDLINK
"NEEDLINK",
#endif
#if NEEDLOCAL_HOSTNAME_LENGTH
"NEEDLOCAL_HOSTNAME_LENGTH",
#endif
#if NEEDSGETIPNODE
"NEEDSGETIPNODE",
#endif
#if NEEDSTRSTR
"NEEDSTRSTR",
#endif
#if NEEDSTRTOL
"NEEDSTRTOL",
#endif
#ifdef NO_GETSERVBYNAME
"NO_GETSERVBYNAME",
#endif
#if NOFTRUNCATE
"NOFTRUNCATE",
#endif
#if REQUIRES_DIR_FSYNC
"REQUIRES_DIR_FSYNC",
#endif
#if RLIMIT_NEEDS_SYS_TIME_H
"RLIMIT_NEEDS_SYS_TIME_H",
#endif
#if SAFENFSPATHCONF
"SAFENFSPATHCONF",
#endif
#if SECUREWARE
"SECUREWARE",
#endif
#if SHARE_V1
"SHARE_V1",
#endif
#if SIOCGIFCONF_IS_BROKEN
"SIOCGIFCONF_IS_BROKEN",
#endif
#if SIOCGIFNUM_IS_BROKEN
"SIOCGIFNUM_IS_BROKEN",
#endif
#if SNPRINTF_IS_BROKEN
"SNPRINTF_IS_BROKEN",
#endif
#if SO_REUSEADDR_IS_BROKEN
"SO_REUSEADDR_IS_BROKEN",
#endif
#if SYS5SETPGRP
"SYS5SETPGRP",
#endif
#if SYSTEM5
"SYSTEM5",
#endif
#if USE_DOUBLE_FORK
"USE_DOUBLE_FORK",
#endif
#if USE_ENVIRON
"USE_ENVIRON",
#endif
#if USE_SA_SIGACTION
"USE_SA_SIGACTION",
#endif
#if USE_SIGLONGJMP
"USE_SIGLONGJMP",
#endif
#if USEGETCONFATTR
"USEGETCONFATTR",
#endif
#if USESETEUID
"USESETEUID",
#endif
#ifdef USESYSCTL
"USESYSCTL",
#endif
#if USING_NETSCAPE_LDAP
"USING_NETSCAPE_LDAP",
#endif
#ifdef WAITUNION
"WAITUNION",
#endif
NULL
};
char *FFRCompileOptions[] =
{
#if _FFR_ADDR_TYPE_MODES
"_FFR_ADDR_TYPE_MODES",
#endif
#if _FFR_ALLOW_SASLINFO
"_FFR_ALLOW_SASLINFO",
#endif
#if _FFR_BADRCPT_SHUTDOWN
"_FFR_BADRCPT_SHUTDOWN",
#endif
#if _FFR_BESTMX_BETTER_TRUNCATION
"_FFR_BESTMX_BETTER_TRUNCATION",
#endif
#if _FFR_CATCH_BROKEN_MTAS
"_FFR_CATCH_BROKEN_MTAS",
#endif
#if _FFR_CHECKCONFIG
"_FFR_CHECKCONFIG",
#endif
#if _FFR_CHK_QUEUE
"_FFR_CHK_QUEUE",
#endif
#if _FFR_CLIENT_SIZE
"_FFR_CLIENT_SIZE",
#endif
#if _FFR_CRLPATH
"_FFR_CRLPATH",
#endif
#if _FFR_DAEMON_NETUNIX
"_FFR_DAEMON_NETUNIX",
#endif
#if _FFR_DEPRECATE_MAILER_FLAG_I
"_FFR_DEPRECATE_MAILER_FLAG_I",
#endif
#if _FFR_DM_ONE
"_FFR_DM_ONE",
#endif
#if _FFR_DIGUNIX_SAFECHOWN
"_FFR_DIGUNIX_SAFECHOWN",
#endif
#if _FFR_DNSMAP_ALIASABLE
"_FFR_DNSMAP_ALIASABLE",
#endif
#if _FFR_DONTLOCKFILESFORREAD_OPTION
"_FFR_DONTLOCKFILESFORREAD_OPTION",
#endif
#if _FFR_DOTTED_USERNAMES
"_FFR_DOTTED_USERNAMES",
#endif
#if _FFR_DPO_CS
"_FFR_DPO_CS",
#endif
#if _FFR_DPRINTF_MAP
"_FFR_DPRINTF_MAP",
#endif
#if _FFR_DROP_TRUSTUSER_WARNING
"_FFR_DROP_TRUSTUSER_WARNING",
#endif
#if _FFR_EIGHT_BIT_ADDR_OK
"_FFR_EIGHT_BIT_ADDR_OK",
#endif
#if _FFR_EXPDELAY
"_FFR_EXPDELAY",
#endif
#if _FFR_EXTRA_MAP_CHECK
"_FFR_EXTRA_MAP_CHECK",
#endif
#if _FFR_GETHBN_ExFILE
"_FFR_GETHBN_ExFILE",
#endif
#if _FFR_FIX_DASHT
"_FFR_FIX_DASHT",
#endif
#if _FFR_FORWARD_SYSERR
"_FFR_FORWARD_SYSERR",
#endif
#if _FFR_GEN_ORCPT
"_FFR_GEN_ORCPT",
#endif
#if _FFR_GROUPREADABLEAUTHINFOFILE
"_FFR_GROUPREADABLEAUTHINFOFILE",
#endif
#if _FFR_HANDLE_ISO8859_GECOS
"_FFR_HANDLE_ISO8859_GECOS",
#endif
#if _FFR_HPUX_NSSWITCH
"_FFR_HPUX_NSSWITCH",
#endif
#if _FFR_IGNORE_BOGUS_ADDR
"_FFR_IGNORE_BOGUS_ADDR",
#endif
#if _FFR_IGNORE_EXT_ON_HELO
"_FFR_IGNORE_EXT_ON_HELO",
#endif
#if _FFR_LINUX_MHNL
"_FFR_LINUX_MHNL",
#endif
#if _FFR_LOCAL_DAEMON
"_FFR_LOCAL_DAEMON",
#endif
#if _FFR_MAIL_MACRO
"_FFR_MAIL_MACRO",
#endif
#if _FFR_MAXDATASIZE
"_FFR_MAXDATASIZE",
#endif
#if _FFR_MAX_FORWARD_ENTRIES
"_FFR_MAX_FORWARD_ENTRIES",
#endif
#if _FFR_MAX_SLEEP_TIME
"_FFR_MAX_SLEEP_TIME",
#endif
#if _FFR_MDS_NEGOTIATE
"_FFR_MDS_NEGOTIATE",
#endif
#if _FFR_MEMSTAT
"_FFR_MEMSTAT",
#endif
#if _FFR_MILTER_CHECK
"_FFR_MILTER_CHECK",
#endif
#if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF
"_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF",
#endif
#if _FFR_MILTER_CHECK_REJECTIONS_TOO
"_FFR_MILTER_CHECK_REJECTIONS_TOO",
#endif
#if _FFR_MILTER_ENHSC
"_FFR_MILTER_ENHSC",
#endif
#if _FFR_MIME7TO8_OLD
"_FFR_MIME7TO8_OLD",
#endif
#if _FFR_MORE_MACROS
"_FFR_MORE_MACROS",
#endif
#if _FFR_MSG_ACCEPT
"_FFR_MSG_ACCEPT",
#endif
#if _FFR_NODELAYDSN_ON_HOLD
"_FFR_NODELAYDSN_ON_HOLD",
#endif
#if _FFR_NO_PIPE
"_FFR_NO_PIPE",
#endif
#if _FFR_LDAP_NETWORK_TIMEOUT
"_FFR_LDAP_NETWORK_TIMEOUT",
#endif
#if _FFR_LOG_NTRIES
"_FFR_LOG_NTRIES",
#endif
#if _FFR_QF_PARANOIA
"_FFR_QF_PARANOIA",
#endif
#if _FFR_QUEUEDELAY
"_FFR_QUEUEDELAY",
#endif
#if _FFR_QUEUE_GROUP_SORTORDER
"_FFR_QUEUE_GROUP_SORTORDER",
#endif
#if _FFR_QUEUE_MACRO
"_FFR_QUEUE_MACRO",
#endif
#if _FFR_QUEUE_RUN_PARANOIA
"_FFR_QUEUE_RUN_PARANOIA",
#endif
#if _FFR_QUEUE_SCHED_DBG
"_FFR_QUEUE_SCHED_DBG",
#endif
#if _FFR_RCPTTHROTDELAY
"_FFR_RCPTTHROTDELAY"
#endif
#if _FFR_REDIRECTEMPTY
"_FFR_REDIRECTEMPTY",
#endif
#if _FFR_RESET_MACRO_GLOBALS
"_FFR_RESET_MACRO_GLOBALS",
#endif
#if _FFR_RHS
"_FFR_RHS",
#endif
#if _FFR_RUNPQG
"_FFR_RUNPQG",
#endif
#if _FFR_SESSID
"_FFR_SESSID",
#endif
#if _FFR_SHM_STATUS
"_FFR_SHM_STATUS",
#endif
#if _FFR_LDAP_SINGLEDN
"_FFR_LDAP_SINGLEDN",
#endif
#if _FFR_SKIP_DOMAINS
"_FFR_SKIP_DOMAINS",
#endif
#if _FFR_SLEEP_USE_SELECT
"_FFR_SLEEP_USE_SELECT ",
#endif
#if _FFR_SPT_ALIGN
"_FFR_SPT_ALIGN",
#endif
#if _FFR_SS_PER_DAEMON
"_FFR_SS_PER_DAEMON",
#endif
#if _FFR_TESTS
"_FFR_TESTS",
#endif
#if _FFR_TIMERS
"_FFR_TIMERS",
#endif
#if _FFR_TLS_1
"_FFR_TLS_1",
#endif
#if _FFR_TRUSTED_QF
"_FFR_TRUSTED_QF",
#endif
#if _FFR_USE_SEM_LOCKING
"_FFR_USE_SEM_LOCKING",
#endif
#if _FFR_USE_SETLOGIN
"_FFR_USE_SETLOGIN",
#endif
NULL
};