xref: /illumos-gate/usr/src/cmd/sendmail/src/conf.c (revision bbf21555)
17c478bd9Sstevel@tonic-gate /*
2e9af4bc0SJohn Beck  * Copyright (c) 1998-2009 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *	All rights reserved.
47c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
67c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
97c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
107c478bd9Sstevel@tonic-gate  * the sendmail distribution.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate /*
15d25d47eeSjbeck  * Copyright 1999-2006 Sun Microsystems, Inc.  All rights reserved.
167c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
1748bbca81SDaniel Hoffman  * Copyright (c) 2016 by Delphix. All rights reserved.
187c478bd9Sstevel@tonic-gate  */
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include <sendmail.h>
217c478bd9Sstevel@tonic-gate 
22e9af4bc0SJohn Beck SM_RCSID("@(#)$Id: conf.c,v 8.1153 2009/12/18 17:25:12 ca Exp $")
237c478bd9Sstevel@tonic-gate 
24058561cbSjbeck #include <sm/sendmail.h>
257c478bd9Sstevel@tonic-gate #include <sendmail/pathnames.h>
267c478bd9Sstevel@tonic-gate #if NEWDB
277c478bd9Sstevel@tonic-gate # include "sm/bdb.h"
287c478bd9Sstevel@tonic-gate #endif /* NEWDB */
297c478bd9Sstevel@tonic-gate 
30058561cbSjbeck #include <daemon.h>
31058561cbSjbeck #include "map.h"
32058561cbSjbeck 
3349218d4fSjbeck #ifdef DEC
3449218d4fSjbeck # if NETINET6
3549218d4fSjbeck /* for the IPv6 device lookup */
3649218d4fSjbeck #  define _SOCKADDR_LEN
3749218d4fSjbeck #  include <macros.h>
3849218d4fSjbeck # endif /* NETINET6 */
3949218d4fSjbeck #endif /* DEC */
4049218d4fSjbeck 
417c478bd9Sstevel@tonic-gate # include <sys/ioctl.h>
427c478bd9Sstevel@tonic-gate # include <sys/param.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <limits.h>
457c478bd9Sstevel@tonic-gate #if NETINET || NETINET6
467c478bd9Sstevel@tonic-gate # include <arpa/inet.h>
477c478bd9Sstevel@tonic-gate #endif /* NETINET || NETINET6 */
487c478bd9Sstevel@tonic-gate #if HASULIMIT && defined(HPUX11)
497c478bd9Sstevel@tonic-gate # include <ulimit.h>
507c478bd9Sstevel@tonic-gate #endif /* HASULIMIT && defined(HPUX11) */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static void	setupmaps __P((void));
537c478bd9Sstevel@tonic-gate static void	setupmailers __P((void));
547c478bd9Sstevel@tonic-gate static void	setupqueues __P((void));
557c478bd9Sstevel@tonic-gate static int	get_num_procs_online __P((void));
567c478bd9Sstevel@tonic-gate static int	add_hostnames __P((SOCKADDR *));
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #if NETINET6 && NEEDSGETIPNODE
597c478bd9Sstevel@tonic-gate static struct hostent *getipnodebyname __P((char *, int, int, int *));
607c478bd9Sstevel@tonic-gate static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
617c478bd9Sstevel@tonic-gate #endif /* NETINET6 && NEEDSGETIPNODE */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate **  CONF.C -- Sendmail Configuration Tables.
667c478bd9Sstevel@tonic-gate **
677c478bd9Sstevel@tonic-gate **	Defines the configuration of this installation.
687c478bd9Sstevel@tonic-gate **
697c478bd9Sstevel@tonic-gate **	Configuration Variables:
707c478bd9Sstevel@tonic-gate **		HdrInfo -- a table describing well-known header fields.
717c478bd9Sstevel@tonic-gate **			Each entry has the field name and some flags,
727c478bd9Sstevel@tonic-gate **			which are described in sendmail.h.
737c478bd9Sstevel@tonic-gate **
747c478bd9Sstevel@tonic-gate **	Notes:
757c478bd9Sstevel@tonic-gate **		I have tried to put almost all the reasonable
767c478bd9Sstevel@tonic-gate **		configuration information into the configuration
777c478bd9Sstevel@tonic-gate **		file read at runtime.  My intent is that anything
787c478bd9Sstevel@tonic-gate **		here is a function of the version of UNIX you
797c478bd9Sstevel@tonic-gate **		are running, or is really static -- for example
807c478bd9Sstevel@tonic-gate **		the headers are a superset of widely used
817c478bd9Sstevel@tonic-gate **		protocols.  If you find yourself playing with
827c478bd9Sstevel@tonic-gate **		this file too much, you may be making a mistake!
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate **  Header info table
887c478bd9Sstevel@tonic-gate **	Final (null) entry contains the flags used for any other field.
897c478bd9Sstevel@tonic-gate **
907c478bd9Sstevel@tonic-gate **	Not all of these are actually handled specially by sendmail
917c478bd9Sstevel@tonic-gate **	at this time.  They are included as placeholders, to let
927c478bd9Sstevel@tonic-gate **	you know that "someday" I intend to have sendmail do
937c478bd9Sstevel@tonic-gate **	something with them.
947c478bd9Sstevel@tonic-gate */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate struct hdrinfo	HdrInfo[] =
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate 		/* originator fields, most to least significant */
997c478bd9Sstevel@tonic-gate 	{ "resent-sender",		H_FROM|H_RESENT,	NULL	},
1007c478bd9Sstevel@tonic-gate 	{ "resent-from",		H_FROM|H_RESENT,	NULL	},
1017c478bd9Sstevel@tonic-gate 	{ "resent-reply-to",		H_FROM|H_RESENT,	NULL	},
1027c478bd9Sstevel@tonic-gate 	{ "sender",			H_FROM,			NULL	},
1037c478bd9Sstevel@tonic-gate 	{ "from",			H_FROM,			NULL	},
1047c478bd9Sstevel@tonic-gate 	{ "reply-to",			H_FROM,			NULL	},
1057c478bd9Sstevel@tonic-gate 	{ "errors-to",			H_FROM|H_ERRORSTO,	NULL	},
1067c478bd9Sstevel@tonic-gate 	{ "full-name",			H_ACHECK,		NULL	},
1077c478bd9Sstevel@tonic-gate 	{ "return-receipt-to",		H_RECEIPTTO,		NULL	},
1087c478bd9Sstevel@tonic-gate 	{ "delivery-receipt-to",	H_RECEIPTTO,		NULL	},
1097c478bd9Sstevel@tonic-gate 	{ "disposition-notification-to",	H_FROM,		NULL	},
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 		/* destination fields */
1127c478bd9Sstevel@tonic-gate 	{ "to",				H_RCPT,			NULL	},
1137c478bd9Sstevel@tonic-gate 	{ "resent-to",			H_RCPT|H_RESENT,	NULL	},
1147c478bd9Sstevel@tonic-gate 	{ "cc",				H_RCPT,			NULL	},
1157c478bd9Sstevel@tonic-gate 	{ "resent-cc",			H_RCPT|H_RESENT,	NULL	},
1167c478bd9Sstevel@tonic-gate 	{ "bcc",			H_RCPT|H_BCC,		NULL	},
1177c478bd9Sstevel@tonic-gate 	{ "resent-bcc",			H_RCPT|H_BCC|H_RESENT,	NULL	},
1187c478bd9Sstevel@tonic-gate 	{ "apparently-to",		H_RCPT,			NULL	},
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 		/* message identification and control */
1217c478bd9Sstevel@tonic-gate 	{ "message-id",			0,			NULL	},
1227c478bd9Sstevel@tonic-gate 	{ "resent-message-id",		H_RESENT,		NULL	},
1237c478bd9Sstevel@tonic-gate 	{ "message",			H_EOH,			NULL	},
1247c478bd9Sstevel@tonic-gate 	{ "text",			H_EOH,			NULL	},
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 		/* date fields */
1277c478bd9Sstevel@tonic-gate 	{ "date",			0,			NULL	},
1287c478bd9Sstevel@tonic-gate 	{ "resent-date",		H_RESENT,		NULL	},
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 		/* trace fields */
1317c478bd9Sstevel@tonic-gate 	{ "received",			H_TRACE|H_FORCE,	NULL	},
1327c478bd9Sstevel@tonic-gate 	{ "x400-received",		H_TRACE|H_FORCE,	NULL	},
1337c478bd9Sstevel@tonic-gate 	{ "via",			H_TRACE|H_FORCE,	NULL	},
1347c478bd9Sstevel@tonic-gate 	{ "mail-from",			H_TRACE|H_FORCE,	NULL	},
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 		/* miscellaneous fields */
1377c478bd9Sstevel@tonic-gate 	{ "comments",			H_FORCE|H_ENCODABLE,	NULL	},
1387c478bd9Sstevel@tonic-gate 	{ "return-path",		H_FORCE|H_ACHECK|H_BINDLATE,	NULL	},
1397c478bd9Sstevel@tonic-gate 	{ "content-transfer-encoding",	H_CTE,			NULL	},
1407c478bd9Sstevel@tonic-gate 	{ "content-type",		H_CTYPE,		NULL	},
1417c478bd9Sstevel@tonic-gate 	{ "content-length",		H_ACHECK,		NULL	},
1427c478bd9Sstevel@tonic-gate 	{ "subject",			H_ENCODABLE,		NULL	},
1437c478bd9Sstevel@tonic-gate 	{ "x-authentication-warning",	H_FORCE,		NULL	},
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	{ NULL,				0,			NULL	}
1467c478bd9Sstevel@tonic-gate };
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate **  Privacy values
1527c478bd9Sstevel@tonic-gate */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate struct prival PrivacyValues[] =
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate 	{ "public",		PRIV_PUBLIC		},
1577c478bd9Sstevel@tonic-gate 	{ "needmailhelo",	PRIV_NEEDMAILHELO	},
1587c478bd9Sstevel@tonic-gate 	{ "needexpnhelo",	PRIV_NEEDEXPNHELO	},
1597c478bd9Sstevel@tonic-gate 	{ "needvrfyhelo",	PRIV_NEEDVRFYHELO	},
1607c478bd9Sstevel@tonic-gate 	{ "noexpn",		PRIV_NOEXPN		},
1617c478bd9Sstevel@tonic-gate 	{ "novrfy",		PRIV_NOVRFY		},
1627c478bd9Sstevel@tonic-gate 	{ "restrictexpand",	PRIV_RESTRICTEXPAND	},
1637c478bd9Sstevel@tonic-gate 	{ "restrictmailq",	PRIV_RESTRICTMAILQ	},
1647c478bd9Sstevel@tonic-gate 	{ "restrictqrun",	PRIV_RESTRICTQRUN	},
1657c478bd9Sstevel@tonic-gate 	{ "noetrn",		PRIV_NOETRN		},
1667c478bd9Sstevel@tonic-gate 	{ "noverb",		PRIV_NOVERB		},
1677c478bd9Sstevel@tonic-gate 	{ "authwarnings",	PRIV_AUTHWARNINGS	},
1687c478bd9Sstevel@tonic-gate 	{ "noreceipts",		PRIV_NORECEIPTS		},
1697c478bd9Sstevel@tonic-gate 	{ "nobodyreturn",	PRIV_NOBODYRETN		},
1707c478bd9Sstevel@tonic-gate 	{ "goaway",		PRIV_GOAWAY		},
1717c478bd9Sstevel@tonic-gate 	{ "noactualrecipient",	PRIV_NOACTUALRECIPIENT	},
1727c478bd9Sstevel@tonic-gate 	{ NULL,			0			}
1737c478bd9Sstevel@tonic-gate };
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate **  DontBlameSendmail values
1777c478bd9Sstevel@tonic-gate */
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate struct dbsval DontBlameSendmailValues[] =
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate 	{ "safe",			DBS_SAFE			},
1827c478bd9Sstevel@tonic-gate 	{ "assumesafechown",		DBS_ASSUMESAFECHOWN		},
1837c478bd9Sstevel@tonic-gate 	{ "groupwritabledirpathsafe",	DBS_GROUPWRITABLEDIRPATHSAFE	},
1847c478bd9Sstevel@tonic-gate 	{ "groupwritableforwardfilesafe",
1857c478bd9Sstevel@tonic-gate 					DBS_GROUPWRITABLEFORWARDFILESAFE },
1867c478bd9Sstevel@tonic-gate 	{ "groupwritableincludefilesafe",
1877c478bd9Sstevel@tonic-gate 					DBS_GROUPWRITABLEINCLUDEFILESAFE },
1887c478bd9Sstevel@tonic-gate 	{ "groupwritablealiasfile",	DBS_GROUPWRITABLEALIASFILE	},
1897c478bd9Sstevel@tonic-gate 	{ "worldwritablealiasfile",	DBS_WORLDWRITABLEALIASFILE	},
1907c478bd9Sstevel@tonic-gate 	{ "forwardfileinunsafedirpath",	DBS_FORWARDFILEINUNSAFEDIRPATH	},
1917c478bd9Sstevel@tonic-gate 	{ "includefileinunsafedirpath",	DBS_INCLUDEFILEINUNSAFEDIRPATH	},
1927c478bd9Sstevel@tonic-gate 	{ "mapinunsafedirpath",		DBS_MAPINUNSAFEDIRPATH	},
1937c478bd9Sstevel@tonic-gate 	{ "linkedaliasfileinwritabledir",
1947c478bd9Sstevel@tonic-gate 					DBS_LINKEDALIASFILEINWRITABLEDIR },
1957c478bd9Sstevel@tonic-gate 	{ "linkedclassfileinwritabledir",
1967c478bd9Sstevel@tonic-gate 					DBS_LINKEDCLASSFILEINWRITABLEDIR },
1977c478bd9Sstevel@tonic-gate 	{ "linkedforwardfileinwritabledir",
1987c478bd9Sstevel@tonic-gate 					DBS_LINKEDFORWARDFILEINWRITABLEDIR },
1997c478bd9Sstevel@tonic-gate 	{ "linkedincludefileinwritabledir",
2007c478bd9Sstevel@tonic-gate 					DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
2017c478bd9Sstevel@tonic-gate 	{ "linkedmapinwritabledir",	DBS_LINKEDMAPINWRITABLEDIR	},
2027c478bd9Sstevel@tonic-gate 	{ "linkedserviceswitchfileinwritabledir",
2037c478bd9Sstevel@tonic-gate 					DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
2047c478bd9Sstevel@tonic-gate 	{ "filedeliverytohardlink",	DBS_FILEDELIVERYTOHARDLINK	},
2057c478bd9Sstevel@tonic-gate 	{ "filedeliverytosymlink",	DBS_FILEDELIVERYTOSYMLINK	},
2067c478bd9Sstevel@tonic-gate 	{ "writemaptohardlink",		DBS_WRITEMAPTOHARDLINK		},
2077c478bd9Sstevel@tonic-gate 	{ "writemaptosymlink",		DBS_WRITEMAPTOSYMLINK		},
2087c478bd9Sstevel@tonic-gate 	{ "writestatstohardlink",	DBS_WRITESTATSTOHARDLINK	},
2097c478bd9Sstevel@tonic-gate 	{ "writestatstosymlink",	DBS_WRITESTATSTOSYMLINK		},
2107c478bd9Sstevel@tonic-gate 	{ "forwardfileingroupwritabledirpath",
2117c478bd9Sstevel@tonic-gate 					DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
2127c478bd9Sstevel@tonic-gate 	{ "includefileingroupwritabledirpath",
2137c478bd9Sstevel@tonic-gate 					DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
2147c478bd9Sstevel@tonic-gate 	{ "classfileinunsafedirpath",	DBS_CLASSFILEINUNSAFEDIRPATH	},
2157c478bd9Sstevel@tonic-gate 	{ "errorheaderinunsafedirpath",	DBS_ERRORHEADERINUNSAFEDIRPATH	},
2167c478bd9Sstevel@tonic-gate 	{ "helpfileinunsafedirpath",	DBS_HELPFILEINUNSAFEDIRPATH	},
2177c478bd9Sstevel@tonic-gate 	{ "forwardfileinunsafedirpathsafe",
2187c478bd9Sstevel@tonic-gate 					DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
2197c478bd9Sstevel@tonic-gate 	{ "includefileinunsafedirpathsafe",
2207c478bd9Sstevel@tonic-gate 					DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
2217c478bd9Sstevel@tonic-gate 	{ "runprograminunsafedirpath",	DBS_RUNPROGRAMINUNSAFEDIRPATH	},
2227c478bd9Sstevel@tonic-gate 	{ "runwritableprogram",		DBS_RUNWRITABLEPROGRAM		},
2237c478bd9Sstevel@tonic-gate 	{ "nonrootsafeaddr",		DBS_NONROOTSAFEADDR		},
2247c478bd9Sstevel@tonic-gate 	{ "truststickybit",		DBS_TRUSTSTICKYBIT		},
2257c478bd9Sstevel@tonic-gate 	{ "dontwarnforwardfileinunsafedirpath",
2267c478bd9Sstevel@tonic-gate 					DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
2277c478bd9Sstevel@tonic-gate 	{ "insufficiententropy",	DBS_INSUFFICIENTENTROPY },
2287c478bd9Sstevel@tonic-gate 	{ "groupreadablesasldbfile",	DBS_GROUPREADABLESASLDBFILE	},
2297c478bd9Sstevel@tonic-gate 	{ "groupwritablesasldbfile",	DBS_GROUPWRITABLESASLDBFILE	},
2307c478bd9Sstevel@tonic-gate 	{ "groupwritableforwardfile",	DBS_GROUPWRITABLEFORWARDFILE	},
2317c478bd9Sstevel@tonic-gate 	{ "groupwritableincludefile",	DBS_GROUPWRITABLEINCLUDEFILE	},
2327c478bd9Sstevel@tonic-gate 	{ "worldwritableforwardfile",	DBS_WORLDWRITABLEFORWARDFILE	},
2337c478bd9Sstevel@tonic-gate 	{ "worldwritableincludefile",	DBS_WORLDWRITABLEINCLUDEFILE	},
2347c478bd9Sstevel@tonic-gate 	{ "groupreadablekeyfile",	DBS_GROUPREADABLEKEYFILE	},
2357c478bd9Sstevel@tonic-gate #if _FFR_GROUPREADABLEAUTHINFOFILE
2367c478bd9Sstevel@tonic-gate 	{ "groupreadableadefaultauthinfofile",
2377c478bd9Sstevel@tonic-gate 					DBS_GROUPREADABLEAUTHINFOFILE	},
2387c478bd9Sstevel@tonic-gate #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
2397c478bd9Sstevel@tonic-gate 	{ NULL,				0				}
2407c478bd9Sstevel@tonic-gate };
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate **  Miscellaneous stuff.
2447c478bd9Sstevel@tonic-gate */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate int	DtableSize =	50;		/* max open files; reset in 4.2bsd */
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate **  SETDEFAULTS -- set default values
2497c478bd9Sstevel@tonic-gate **
2507c478bd9Sstevel@tonic-gate **	Some of these must be initialized using direct code since they
2517c478bd9Sstevel@tonic-gate **	depend on run-time values. So let's do all of them this way.
2527c478bd9Sstevel@tonic-gate **
2537c478bd9Sstevel@tonic-gate **	Parameters:
2547c478bd9Sstevel@tonic-gate **		e -- the default envelope.
2557c478bd9Sstevel@tonic-gate **
2567c478bd9Sstevel@tonic-gate **	Returns:
2577c478bd9Sstevel@tonic-gate **		none.
2587c478bd9Sstevel@tonic-gate **
2597c478bd9Sstevel@tonic-gate **	Side Effects:
2607c478bd9Sstevel@tonic-gate **		Initializes a bunch of global variables to their
2617c478bd9Sstevel@tonic-gate **		default values.
2627c478bd9Sstevel@tonic-gate */
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate #define MINUTES		* 60
2657c478bd9Sstevel@tonic-gate #define HOURS		* 60 MINUTES
2667c478bd9Sstevel@tonic-gate #define DAYS		* 24 HOURS
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate #ifndef MAXRULERECURSION
2697c478bd9Sstevel@tonic-gate # define MAXRULERECURSION	50	/* max ruleset recursion depth */
2707c478bd9Sstevel@tonic-gate #endif /* ! MAXRULERECURSION */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate void
setdefaults(e)2737c478bd9Sstevel@tonic-gate setdefaults(e)
2747c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
2757c478bd9Sstevel@tonic-gate {
2767c478bd9Sstevel@tonic-gate 	int i;
2777c478bd9Sstevel@tonic-gate 	int numprocs;
2787c478bd9Sstevel@tonic-gate 	struct passwd *pw;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	numprocs = get_num_procs_online();
2817c478bd9Sstevel@tonic-gate 	SpaceSub = ' ';				/* option B */
2827c478bd9Sstevel@tonic-gate 	QueueLA = 8 * numprocs;			/* option x */
2837c478bd9Sstevel@tonic-gate 	RefuseLA = 12 * numprocs;		/* option X */
2847c478bd9Sstevel@tonic-gate 	WkRecipFact = 30000L;			/* option y */
2857c478bd9Sstevel@tonic-gate 	WkClassFact = 1800L;			/* option z */
2867c478bd9Sstevel@tonic-gate 	WkTimeFact = 90000L;			/* option Z */
2877c478bd9Sstevel@tonic-gate 	QueueFactor = WkRecipFact * 20;		/* option q */
2887c478bd9Sstevel@tonic-gate 	QueueMode = QM_NORMAL;		/* what queue items to act upon */
2897c478bd9Sstevel@tonic-gate 	FileMode = (RealUid != geteuid()) ? 0644 : 0600;
2907c478bd9Sstevel@tonic-gate 						/* option F */
2917c478bd9Sstevel@tonic-gate 	QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
2927c478bd9Sstevel@tonic-gate 						/* option QueueFileMode */
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
2957c478bd9Sstevel@tonic-gate 	    ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
2967c478bd9Sstevel@tonic-gate 	    ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
2977c478bd9Sstevel@tonic-gate 	{
2987c478bd9Sstevel@tonic-gate 		DefUid = pw->pw_uid;		/* option u */
2997c478bd9Sstevel@tonic-gate 		DefGid = pw->pw_gid;		/* option g */
3007c478bd9Sstevel@tonic-gate 		DefUser = newstr(pw->pw_name);
3017c478bd9Sstevel@tonic-gate 	}
3027c478bd9Sstevel@tonic-gate 	else
3037c478bd9Sstevel@tonic-gate 	{
3047c478bd9Sstevel@tonic-gate 		DefUid = 1;			/* option u */
3057c478bd9Sstevel@tonic-gate 		DefGid = 1;			/* option g */
3067c478bd9Sstevel@tonic-gate 		setdefuser();
3077c478bd9Sstevel@tonic-gate 	}
3087c478bd9Sstevel@tonic-gate 	TrustedUid = 0;
3097c478bd9Sstevel@tonic-gate 	if (tTd(37, 4))
3107c478bd9Sstevel@tonic-gate 		sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
3117c478bd9Sstevel@tonic-gate 			DefUser != NULL ? DefUser : "<1:1>",
3127c478bd9Sstevel@tonic-gate 			(int) DefUid, (int) DefGid);
3137c478bd9Sstevel@tonic-gate 	CheckpointInterval = 10;		/* option C */
3147c478bd9Sstevel@tonic-gate 	MaxHopCount = 25;			/* option h */
3157c478bd9Sstevel@tonic-gate 	set_delivery_mode(SM_FORK, e);		/* option d */
3167c478bd9Sstevel@tonic-gate 	e->e_errormode = EM_PRINT;		/* option e */
3177c478bd9Sstevel@tonic-gate 	e->e_qgrp = NOQGRP;
3187c478bd9Sstevel@tonic-gate 	e->e_qdir = NOQDIR;
3197c478bd9Sstevel@tonic-gate 	e->e_xfqgrp = NOQGRP;
3207c478bd9Sstevel@tonic-gate 	e->e_xfqdir = NOQDIR;
3217c478bd9Sstevel@tonic-gate 	e->e_ctime = curtime();
3227c478bd9Sstevel@tonic-gate 	SevenBitInput = false;			/* option 7 */
3237c478bd9Sstevel@tonic-gate 	MaxMciCache = 1;			/* option k */
3247c478bd9Sstevel@tonic-gate 	MciCacheTimeout = 5 MINUTES;		/* option K */
3257c478bd9Sstevel@tonic-gate 	LogLevel = 9;				/* option L */
3267c478bd9Sstevel@tonic-gate #if MILTER
3277c478bd9Sstevel@tonic-gate 	MilterLogLevel = -1;
3287c478bd9Sstevel@tonic-gate #endif /* MILTER */
3297c478bd9Sstevel@tonic-gate 	inittimeouts(NULL, false);		/* option r */
3307c478bd9Sstevel@tonic-gate 	PrivacyFlags = PRIV_PUBLIC;		/* option p */
3317c478bd9Sstevel@tonic-gate 	MeToo = true;				/* option m */
3327c478bd9Sstevel@tonic-gate 	SendMIMEErrors = true;			/* option f */
3337c478bd9Sstevel@tonic-gate 	SuperSafe = SAFE_REALLY;		/* option s */
3347c478bd9Sstevel@tonic-gate 	clrbitmap(DontBlameSendmail);		/* DontBlameSendmail option */
3357c478bd9Sstevel@tonic-gate #if MIME8TO7
3367c478bd9Sstevel@tonic-gate 	MimeMode = MM_CVTMIME|MM_PASS8BIT;	/* option 8 */
3377c478bd9Sstevel@tonic-gate #else /* MIME8TO7 */
3387c478bd9Sstevel@tonic-gate 	MimeMode = MM_PASS8BIT;
3397c478bd9Sstevel@tonic-gate #endif /* MIME8TO7 */
3407c478bd9Sstevel@tonic-gate 	for (i = 0; i < MAXTOCLASS; i++)
3417c478bd9Sstevel@tonic-gate 	{
3427c478bd9Sstevel@tonic-gate 		TimeOuts.to_q_return[i] = 5 DAYS;	/* option T */
3437c478bd9Sstevel@tonic-gate 		TimeOuts.to_q_warning[i] = 0;		/* option T */
3447c478bd9Sstevel@tonic-gate 	}
3457c478bd9Sstevel@tonic-gate 	ServiceSwitchFile = "/etc/mail/service.switch";
3467c478bd9Sstevel@tonic-gate 	ServiceCacheMaxAge = (time_t) 10;
3477c478bd9Sstevel@tonic-gate 	HostsFile = _PATH_HOSTS;
3487c478bd9Sstevel@tonic-gate 	PidFile = newstr(_PATH_SENDMAILPID);
3497c478bd9Sstevel@tonic-gate 	MustQuoteChars = "@,;:\\()[].'";
3507c478bd9Sstevel@tonic-gate 	MciInfoTimeout = 30 MINUTES;
3517c478bd9Sstevel@tonic-gate 	MaxRuleRecursion = MAXRULERECURSION;
3527c478bd9Sstevel@tonic-gate 	MaxAliasRecursion = 10;
3537c478bd9Sstevel@tonic-gate 	MaxMacroRecursion = 10;
3547c478bd9Sstevel@tonic-gate 	ColonOkInAddr = true;
3557c478bd9Sstevel@tonic-gate 	DontLockReadFiles = true;
3567c478bd9Sstevel@tonic-gate 	DontProbeInterfaces = DPI_PROBEALL;
3577c478bd9Sstevel@tonic-gate 	DoubleBounceAddr = "postmaster";
3587c478bd9Sstevel@tonic-gate 	MaxHeadersLength = MAXHDRSLEN;
3597c478bd9Sstevel@tonic-gate 	MaxMimeHeaderLength = MAXLINE;
3607c478bd9Sstevel@tonic-gate 	MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3617c478bd9Sstevel@tonic-gate 	MaxForwardEntries = 0;
3627c478bd9Sstevel@tonic-gate 	FastSplit = 1;
363445f2479Sjbeck 	MaxNOOPCommands = MAXNOOPCOMMANDS;
3647c478bd9Sstevel@tonic-gate #if SASL
3657c478bd9Sstevel@tonic-gate 	AuthMechanisms = newstr(AUTH_MECHANISMS);
3667c478bd9Sstevel@tonic-gate 	AuthRealm = NULL;
3677c478bd9Sstevel@tonic-gate 	MaxSLBits = INT_MAX;
3687c478bd9Sstevel@tonic-gate #endif /* SASL */
3697c478bd9Sstevel@tonic-gate #if STARTTLS
3707c478bd9Sstevel@tonic-gate 	TLS_Srv_Opts = TLS_I_SRV;
3717c478bd9Sstevel@tonic-gate #endif /* STARTTLS */
3727c478bd9Sstevel@tonic-gate #ifdef HESIOD_INIT
3737c478bd9Sstevel@tonic-gate 	HesiodContext = NULL;
3747c478bd9Sstevel@tonic-gate #endif /* HESIOD_INIT */
3757c478bd9Sstevel@tonic-gate #if NETINET6
3767c478bd9Sstevel@tonic-gate 	/* Detect if IPv6 is available at run time */
3777c478bd9Sstevel@tonic-gate 	i = socket(AF_INET6, SOCK_STREAM, 0);
3787c478bd9Sstevel@tonic-gate 	if (i >= 0)
3797c478bd9Sstevel@tonic-gate 	{
3807c478bd9Sstevel@tonic-gate 		InetMode = AF_INET6;
3817c478bd9Sstevel@tonic-gate 		(void) close(i);
3827c478bd9Sstevel@tonic-gate 	}
3837c478bd9Sstevel@tonic-gate 	else
3847c478bd9Sstevel@tonic-gate 		InetMode = AF_INET;
3857c478bd9Sstevel@tonic-gate #else /* NETINET6 */
3867c478bd9Sstevel@tonic-gate 	InetMode = AF_INET;
3877c478bd9Sstevel@tonic-gate #endif /* NETINET6 */
3887c478bd9Sstevel@tonic-gate 	ControlSocketName = NULL;
389058561cbSjbeck 	memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo));
3907c478bd9Sstevel@tonic-gate 	DataFileBufferSize = 4096;
3917c478bd9Sstevel@tonic-gate 	XscriptFileBufferSize = 4096;
3927c478bd9Sstevel@tonic-gate 	for (i = 0; i < MAXRWSETS; i++)
3937c478bd9Sstevel@tonic-gate 		RuleSetNames[i] = NULL;
3947c478bd9Sstevel@tonic-gate #if MILTER
3957c478bd9Sstevel@tonic-gate 	InputFilters[0] = NULL;
3967c478bd9Sstevel@tonic-gate #endif /* MILTER */
3977c478bd9Sstevel@tonic-gate 	RejectLogInterval = 3 HOURS;
3987c478bd9Sstevel@tonic-gate #if REQUIRES_DIR_FSYNC
3997c478bd9Sstevel@tonic-gate 	RequiresDirfsync = true;
4007c478bd9Sstevel@tonic-gate #endif /* REQUIRES_DIR_FSYNC */
401e9af4bc0SJohn Beck #if _FFR_RCPTTHROTDELAY
402e9af4bc0SJohn Beck 	BadRcptThrottleDelay = 1;
403e9af4bc0SJohn Beck #endif /* _FFR_RCPTTHROTDELAY */
4047c478bd9Sstevel@tonic-gate 	ConnectionRateWindowSize = 60;
4057c478bd9Sstevel@tonic-gate 	setupmaps();
4067c478bd9Sstevel@tonic-gate 	setupqueues();
4077c478bd9Sstevel@tonic-gate 	setupmailers();
4087c478bd9Sstevel@tonic-gate 	setupheaders();
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate /*
4137c478bd9Sstevel@tonic-gate **  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
4147c478bd9Sstevel@tonic-gate */
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate void
setdefuser()4177c478bd9Sstevel@tonic-gate setdefuser()
4187c478bd9Sstevel@tonic-gate {
4197c478bd9Sstevel@tonic-gate 	struct passwd *defpwent;
4207c478bd9Sstevel@tonic-gate 	static char defuserbuf[40];
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	DefUser = defuserbuf;
4237c478bd9Sstevel@tonic-gate 	defpwent = sm_getpwuid(DefUid);
4247c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(defuserbuf,
4257c478bd9Sstevel@tonic-gate 			  (defpwent == NULL || defpwent->pw_name == NULL)
4267c478bd9Sstevel@tonic-gate 			   ? "nobody" : defpwent->pw_name,
427058561cbSjbeck 			  sizeof(defuserbuf));
4287c478bd9Sstevel@tonic-gate 	if (tTd(37, 4))
4297c478bd9Sstevel@tonic-gate 		sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
4307c478bd9Sstevel@tonic-gate 			   (int) DefUid, DefUser);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate **  SETUPQUEUES -- initialize default queues
4347c478bd9Sstevel@tonic-gate **
4357c478bd9Sstevel@tonic-gate **	The mqueue QUEUE structure gets filled in after readcf() but
4367c478bd9Sstevel@tonic-gate **	we need something to point to now for the mailer setup,
4377c478bd9Sstevel@tonic-gate **	which use "mqueue" as default queue.
4387c478bd9Sstevel@tonic-gate */
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate static void
setupqueues()4417c478bd9Sstevel@tonic-gate setupqueues()
4427c478bd9Sstevel@tonic-gate {
4437c478bd9Sstevel@tonic-gate 	char buf[100];
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	MaxRunnersPerQueue = 1;
446058561cbSjbeck 	(void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf));
4477c478bd9Sstevel@tonic-gate 	makequeue(buf, false);
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate **  SETUPMAILERS -- initialize default mailers
4517c478bd9Sstevel@tonic-gate */
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate static void
setupmailers()4547c478bd9Sstevel@tonic-gate setupmailers()
4557c478bd9Sstevel@tonic-gate {
4567c478bd9Sstevel@tonic-gate 	char buf[100];
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
459058561cbSjbeck 			sizeof(buf));
4607c478bd9Sstevel@tonic-gate 	makemailer(buf);
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
463058561cbSjbeck 			sizeof(buf));
4647c478bd9Sstevel@tonic-gate 	makemailer(buf);
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
467058561cbSjbeck 			sizeof(buf));
4687c478bd9Sstevel@tonic-gate 	makemailer(buf);
4697c478bd9Sstevel@tonic-gate 	initerrmailers();
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate /*
4727c478bd9Sstevel@tonic-gate **  SETUPMAPS -- set up map classes
4737c478bd9Sstevel@tonic-gate */
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
4767c478bd9Sstevel@tonic-gate 	{ \
4777c478bd9Sstevel@tonic-gate 		extern bool parse __P((MAP *, char *)); \
4787c478bd9Sstevel@tonic-gate 		extern bool open __P((MAP *, int)); \
4797c478bd9Sstevel@tonic-gate 		extern void close __P((MAP *)); \
4807c478bd9Sstevel@tonic-gate 		extern char *lookup __P((MAP *, char *, char **, int *)); \
4817c478bd9Sstevel@tonic-gate 		extern void store __P((MAP *, char *, char *)); \
4827c478bd9Sstevel@tonic-gate 		s = stab(name, ST_MAPCLASS, ST_ENTER); \
4837c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_cname = name; \
4847c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_ext = ext; \
4857c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_cflags = flags; \
4867c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_parse = parse; \
4877c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_open = open; \
4887c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_close = close; \
4897c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_lookup = lookup; \
4907c478bd9Sstevel@tonic-gate 		s->s_mapclass.map_store = store; \
4917c478bd9Sstevel@tonic-gate 	}
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate static void
setupmaps()4947c478bd9Sstevel@tonic-gate setupmaps()
4957c478bd9Sstevel@tonic-gate {
4967c478bd9Sstevel@tonic-gate 	register STAB *s;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate #if NEWDB
4997c478bd9Sstevel@tonic-gate # if DB_VERSION_MAJOR > 1
5007c478bd9Sstevel@tonic-gate 	int major_v, minor_v, patch_v;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	(void) db_version(&major_v, &minor_v, &patch_v);
5037c478bd9Sstevel@tonic-gate 	if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
5047c478bd9Sstevel@tonic-gate 	{
5057c478bd9Sstevel@tonic-gate 		errno = 0;
5067c478bd9Sstevel@tonic-gate 		syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
5077c478bd9Sstevel@tonic-gate 		  DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
5087c478bd9Sstevel@tonic-gate 		  major_v, minor_v, patch_v);
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate # endif /* DB_VERSION_MAJOR > 1 */
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
5137c478bd9Sstevel@tonic-gate 		map_parseargs, hash_map_open, db_map_close,
5147c478bd9Sstevel@tonic-gate 		db_map_lookup, db_map_store);
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
5177c478bd9Sstevel@tonic-gate 		map_parseargs, bt_map_open, db_map_close,
5187c478bd9Sstevel@tonic-gate 		db_map_lookup, db_map_store);
5197c478bd9Sstevel@tonic-gate #endif /* NEWDB */
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate #if NDBM
5227c478bd9Sstevel@tonic-gate 	MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
5237c478bd9Sstevel@tonic-gate 		map_parseargs, ndbm_map_open, ndbm_map_close,
5247c478bd9Sstevel@tonic-gate 		ndbm_map_lookup, ndbm_map_store);
5257c478bd9Sstevel@tonic-gate #endif /* NDBM */
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate #if NIS
5287c478bd9Sstevel@tonic-gate 	MAPDEF("nis", NULL, MCF_ALIASOK,
5297c478bd9Sstevel@tonic-gate 		map_parseargs, nis_map_open, null_map_close,
5307c478bd9Sstevel@tonic-gate 		nis_map_lookup, null_map_store);
5317c478bd9Sstevel@tonic-gate #endif /* NIS */
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate #if NISPLUS
5347c478bd9Sstevel@tonic-gate 	MAPDEF("nisplus", NULL, MCF_ALIASOK,
5357c478bd9Sstevel@tonic-gate 		map_parseargs, nisplus_map_open, null_map_close,
5367c478bd9Sstevel@tonic-gate 		nisplus_map_lookup, null_map_store);
5377c478bd9Sstevel@tonic-gate #endif /* NISPLUS */
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate #if LDAPMAP
5407c478bd9Sstevel@tonic-gate 	MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
5417c478bd9Sstevel@tonic-gate 		ldapmap_parseargs, ldapmap_open, ldapmap_close,
5427c478bd9Sstevel@tonic-gate 		ldapmap_lookup, null_map_store);
5437c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate #if PH_MAP
5467c478bd9Sstevel@tonic-gate 	MAPDEF("ph", NULL, MCF_NOTPERSIST,
5477c478bd9Sstevel@tonic-gate 		ph_map_parseargs, ph_map_open, ph_map_close,
5487c478bd9Sstevel@tonic-gate 		ph_map_lookup, null_map_store);
5497c478bd9Sstevel@tonic-gate #endif /* PH_MAP */
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate #if MAP_NSD
5527c478bd9Sstevel@tonic-gate 	/* IRIX 6.5 nsd support */
5537c478bd9Sstevel@tonic-gate 	MAPDEF("nsd", NULL, MCF_ALIASOK,
5547c478bd9Sstevel@tonic-gate 	       map_parseargs, null_map_open, null_map_close,
5557c478bd9Sstevel@tonic-gate 	       nsd_map_lookup, null_map_store);
5567c478bd9Sstevel@tonic-gate #endif /* MAP_NSD */
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate #if HESIOD
5597c478bd9Sstevel@tonic-gate 	MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
5607c478bd9Sstevel@tonic-gate 		map_parseargs, hes_map_open, hes_map_close,
5617c478bd9Sstevel@tonic-gate 		hes_map_lookup, null_map_store);
5627c478bd9Sstevel@tonic-gate #endif /* HESIOD */
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate #if NETINFO
5657c478bd9Sstevel@tonic-gate 	MAPDEF("netinfo", NULL, MCF_ALIASOK,
5667c478bd9Sstevel@tonic-gate 		map_parseargs, ni_map_open, null_map_close,
5677c478bd9Sstevel@tonic-gate 		ni_map_lookup, null_map_store);
5687c478bd9Sstevel@tonic-gate #endif /* NETINFO */
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate #if 0
5717c478bd9Sstevel@tonic-gate 	MAPDEF("dns", NULL, 0,
5727c478bd9Sstevel@tonic-gate 		dns_map_init, null_map_open, null_map_close,
5737c478bd9Sstevel@tonic-gate 		dns_map_lookup, null_map_store);
5747c478bd9Sstevel@tonic-gate #endif /* 0 */
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate #if NAMED_BIND
5777c478bd9Sstevel@tonic-gate # if DNSMAP
5787c478bd9Sstevel@tonic-gate #  if _FFR_DNSMAP_ALIASABLE
5797c478bd9Sstevel@tonic-gate 	MAPDEF("dns", NULL, MCF_ALIASOK,
5807c478bd9Sstevel@tonic-gate 	       dns_map_parseargs, dns_map_open, null_map_close,
5817c478bd9Sstevel@tonic-gate 	       dns_map_lookup, null_map_store);
5827c478bd9Sstevel@tonic-gate #  else /* _FFR_DNSMAP_ALIASABLE */
5837c478bd9Sstevel@tonic-gate 	MAPDEF("dns", NULL, 0,
5847c478bd9Sstevel@tonic-gate 	       dns_map_parseargs, dns_map_open, null_map_close,
5857c478bd9Sstevel@tonic-gate 	       dns_map_lookup, null_map_store);
5867c478bd9Sstevel@tonic-gate #  endif /* _FFR_DNSMAP_ALIASABLE */
5877c478bd9Sstevel@tonic-gate # endif /* DNSMAP */
5887c478bd9Sstevel@tonic-gate #endif /* NAMED_BIND */
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate #if NAMED_BIND
5917c478bd9Sstevel@tonic-gate 	/* best MX DNS lookup */
5927c478bd9Sstevel@tonic-gate 	MAPDEF("bestmx", NULL, MCF_OPTFILE,
5937c478bd9Sstevel@tonic-gate 		map_parseargs, null_map_open, null_map_close,
5947c478bd9Sstevel@tonic-gate 		bestmx_map_lookup, null_map_store);
5957c478bd9Sstevel@tonic-gate #endif /* NAMED_BIND */
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 	MAPDEF("host", NULL, 0,
5987c478bd9Sstevel@tonic-gate 		host_map_init, null_map_open, null_map_close,
5997c478bd9Sstevel@tonic-gate 		host_map_lookup, null_map_store);
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 	MAPDEF("text", NULL, MCF_ALIASOK,
6027c478bd9Sstevel@tonic-gate 		map_parseargs, text_map_open, null_map_close,
6037c478bd9Sstevel@tonic-gate 		text_map_lookup, null_map_store);
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 	MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
6067c478bd9Sstevel@tonic-gate 		map_parseargs, stab_map_open, null_map_close,
6077c478bd9Sstevel@tonic-gate 		stab_map_lookup, stab_map_store);
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
6107c478bd9Sstevel@tonic-gate 		map_parseargs, impl_map_open, impl_map_close,
6117c478bd9Sstevel@tonic-gate 		impl_map_lookup, impl_map_store);
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 	/* access to system passwd file */
6147c478bd9Sstevel@tonic-gate 	MAPDEF("user", NULL, MCF_OPTFILE,
6157c478bd9Sstevel@tonic-gate 		map_parseargs, user_map_open, null_map_close,
6167c478bd9Sstevel@tonic-gate 		user_map_lookup, null_map_store);
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	/* dequote map */
6197c478bd9Sstevel@tonic-gate 	MAPDEF("dequote", NULL, 0,
6207c478bd9Sstevel@tonic-gate 		dequote_init, null_map_open, null_map_close,
6217c478bd9Sstevel@tonic-gate 		dequote_map, null_map_store);
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate #if MAP_REGEX
6247c478bd9Sstevel@tonic-gate 	MAPDEF("regex", NULL, 0,
6257c478bd9Sstevel@tonic-gate 		regex_map_init, null_map_open, null_map_close,
6267c478bd9Sstevel@tonic-gate 		regex_map_lookup, null_map_store);
6277c478bd9Sstevel@tonic-gate #endif /* MAP_REGEX */
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate #if USERDB
6307c478bd9Sstevel@tonic-gate 	/* user database */
6317c478bd9Sstevel@tonic-gate 	MAPDEF("userdb", ".db", 0,
6327c478bd9Sstevel@tonic-gate 		map_parseargs, null_map_open, null_map_close,
6337c478bd9Sstevel@tonic-gate 		udb_map_lookup, null_map_store);
6347c478bd9Sstevel@tonic-gate #endif /* USERDB */
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 	/* arbitrary programs */
6377c478bd9Sstevel@tonic-gate 	MAPDEF("program", NULL, MCF_ALIASOK,
6387c478bd9Sstevel@tonic-gate 		map_parseargs, null_map_open, null_map_close,
6397c478bd9Sstevel@tonic-gate 		prog_map_lookup, null_map_store);
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	/* sequenced maps */
6427c478bd9Sstevel@tonic-gate 	MAPDEF("sequence", NULL, MCF_ALIASOK,
6437c478bd9Sstevel@tonic-gate 		seq_map_parse, null_map_open, null_map_close,
6447c478bd9Sstevel@tonic-gate 		seq_map_lookup, seq_map_store);
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	/* switched interface to sequenced maps */
6477c478bd9Sstevel@tonic-gate 	MAPDEF("switch", NULL, MCF_ALIASOK,
6487c478bd9Sstevel@tonic-gate 		map_parseargs, switch_map_open, null_map_close,
6497c478bd9Sstevel@tonic-gate 		seq_map_lookup, seq_map_store);
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	/* null map lookup -- really for internal use only */
6527c478bd9Sstevel@tonic-gate 	MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
6537c478bd9Sstevel@tonic-gate 		map_parseargs, null_map_open, null_map_close,
6547c478bd9Sstevel@tonic-gate 		null_map_lookup, null_map_store);
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 	/* syslog map -- logs information to syslog */
6577c478bd9Sstevel@tonic-gate 	MAPDEF("syslog", NULL, 0,
6587c478bd9Sstevel@tonic-gate 		syslog_map_parseargs, null_map_open, null_map_close,
6597c478bd9Sstevel@tonic-gate 		syslog_map_lookup, null_map_store);
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	/* macro storage map -- rulesets can set macros */
6627c478bd9Sstevel@tonic-gate 	MAPDEF("macro", NULL, 0,
6637c478bd9Sstevel@tonic-gate 		dequote_init, null_map_open, null_map_close,
6647c478bd9Sstevel@tonic-gate 		macro_map_lookup, null_map_store);
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 	/* arithmetic map -- add/subtract/compare */
6677c478bd9Sstevel@tonic-gate 	MAPDEF("arith", NULL, 0,
6687c478bd9Sstevel@tonic-gate 		dequote_init, null_map_open, null_map_close,
6697c478bd9Sstevel@tonic-gate 		arith_map_lookup, null_map_store);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate #if SOCKETMAP
6727c478bd9Sstevel@tonic-gate 	/* arbitrary daemons */
6737c478bd9Sstevel@tonic-gate 	MAPDEF("socket", NULL, MCF_ALIASOK,
6747c478bd9Sstevel@tonic-gate 		map_parseargs, socket_map_open, socket_map_close,
6757c478bd9Sstevel@tonic-gate 		socket_map_lookup, null_map_store);
6767c478bd9Sstevel@tonic-gate #endif /* SOCKETMAP */
6777c478bd9Sstevel@tonic-gate 
678058561cbSjbeck #if _FFR_DPRINTF_MAP
679058561cbSjbeck 	/* dprintf map -- logs information to syslog */
680058561cbSjbeck 	MAPDEF("dprintf", NULL, 0,
681058561cbSjbeck 		dprintf_map_parseargs, null_map_open, null_map_close,
682058561cbSjbeck 		dprintf_map_lookup, null_map_store);
683058561cbSjbeck #endif /* _FFR_DPRINTF_MAP */
684058561cbSjbeck 
6857c478bd9Sstevel@tonic-gate 	if (tTd(38, 2))
6867c478bd9Sstevel@tonic-gate 	{
6877c478bd9Sstevel@tonic-gate 		/* bogus map -- always return tempfail */
6887c478bd9Sstevel@tonic-gate 		MAPDEF("bogus",	NULL, MCF_ALIASOK|MCF_OPTFILE,
6897c478bd9Sstevel@tonic-gate 		       map_parseargs, null_map_open, null_map_close,
6907c478bd9Sstevel@tonic-gate 		       bogus_map_lookup, null_map_store);
6917c478bd9Sstevel@tonic-gate 	}
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate #undef MAPDEF
6957c478bd9Sstevel@tonic-gate /*
6967c478bd9Sstevel@tonic-gate **  INITHOSTMAPS -- initial host-dependent maps
6977c478bd9Sstevel@tonic-gate **
6987c478bd9Sstevel@tonic-gate **	This should act as an interface to any local service switch
6997c478bd9Sstevel@tonic-gate **	provided by the host operating system.
7007c478bd9Sstevel@tonic-gate **
7017c478bd9Sstevel@tonic-gate **	Parameters:
7027c478bd9Sstevel@tonic-gate **		none
7037c478bd9Sstevel@tonic-gate **
7047c478bd9Sstevel@tonic-gate **	Returns:
7057c478bd9Sstevel@tonic-gate **		none
7067c478bd9Sstevel@tonic-gate **
7077c478bd9Sstevel@tonic-gate **	Side Effects:
7087c478bd9Sstevel@tonic-gate **		Should define maps "host" and "users" as necessary
7097c478bd9Sstevel@tonic-gate **		for this OS.  If they are not defined, they will get
7107c478bd9Sstevel@tonic-gate **		a default value later.  It should check to make sure
7117c478bd9Sstevel@tonic-gate **		they are not defined first, since it's possible that
7127c478bd9Sstevel@tonic-gate **		the config file has provided an override.
7137c478bd9Sstevel@tonic-gate */
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate void
inithostmaps()7167c478bd9Sstevel@tonic-gate inithostmaps()
7177c478bd9Sstevel@tonic-gate {
7187c478bd9Sstevel@tonic-gate 	register int i;
7197c478bd9Sstevel@tonic-gate 	int nmaps;
7207c478bd9Sstevel@tonic-gate 	char *maptype[MAXMAPSTACK];
7217c478bd9Sstevel@tonic-gate 	short mapreturn[MAXMAPACTIONS];
7227c478bd9Sstevel@tonic-gate 	char buf[MAXLINE];
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 	/*
7257c478bd9Sstevel@tonic-gate 	**  Make sure we have a host map.
7267c478bd9Sstevel@tonic-gate 	*/
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 	if (stab("host", ST_MAP, ST_FIND) == NULL)
7297c478bd9Sstevel@tonic-gate 	{
7307c478bd9Sstevel@tonic-gate 		/* user didn't initialize: set up host map */
731058561cbSjbeck 		(void) sm_strlcpy(buf, "host host", sizeof(buf));
7327c478bd9Sstevel@tonic-gate #if NAMED_BIND
7337c478bd9Sstevel@tonic-gate 		if (ConfigLevel >= 2)
734058561cbSjbeck 			(void) sm_strlcat(buf, " -a. -D", sizeof(buf));
7357c478bd9Sstevel@tonic-gate #endif /* NAMED_BIND */
7367c478bd9Sstevel@tonic-gate 		(void) makemapentry(buf);
7377c478bd9Sstevel@tonic-gate 	}
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate 	/*
7407c478bd9Sstevel@tonic-gate 	**  Set up default aliases maps
7417c478bd9Sstevel@tonic-gate 	*/
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 	nmaps = switch_map_find("aliases", maptype, mapreturn);
7447c478bd9Sstevel@tonic-gate 	for (i = 0; i < nmaps; i++)
7457c478bd9Sstevel@tonic-gate 	{
7467c478bd9Sstevel@tonic-gate 		if (strcmp(maptype[i], "files") == 0 &&
7477c478bd9Sstevel@tonic-gate 		    stab("aliases.files", ST_MAP, ST_FIND) == NULL)
7487c478bd9Sstevel@tonic-gate 		{
7497c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(buf, "aliases.files null",
750058561cbSjbeck 					  sizeof(buf));
7517c478bd9Sstevel@tonic-gate 			(void) makemapentry(buf);
7527c478bd9Sstevel@tonic-gate 		}
7537c478bd9Sstevel@tonic-gate #if NISPLUS
7547c478bd9Sstevel@tonic-gate 		else if (strcmp(maptype[i], "nisplus") == 0 &&
7557c478bd9Sstevel@tonic-gate 			 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
7567c478bd9Sstevel@tonic-gate 		{
7577c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
758058561cbSjbeck 				sizeof(buf));
7597c478bd9Sstevel@tonic-gate 			(void) makemapentry(buf);
7607c478bd9Sstevel@tonic-gate 		}
7617c478bd9Sstevel@tonic-gate #endif /* NISPLUS */
7627c478bd9Sstevel@tonic-gate #if NIS
7637c478bd9Sstevel@tonic-gate 		else if (strcmp(maptype[i], "nis") == 0 &&
7647c478bd9Sstevel@tonic-gate 			 stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
7657c478bd9Sstevel@tonic-gate 		{
7667c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
767058561cbSjbeck 				sizeof(buf));
7687c478bd9Sstevel@tonic-gate 			(void) makemapentry(buf);
7697c478bd9Sstevel@tonic-gate 		}
7707c478bd9Sstevel@tonic-gate #endif /* NIS */
7717c478bd9Sstevel@tonic-gate #if NETINFO
7727c478bd9Sstevel@tonic-gate 		else if (strcmp(maptype[i], "netinfo") == 0 &&
7737c478bd9Sstevel@tonic-gate 			 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
7747c478bd9Sstevel@tonic-gate 		{
7757c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
776058561cbSjbeck 				sizeof(buf));
7777c478bd9Sstevel@tonic-gate 			(void) makemapentry(buf);
7787c478bd9Sstevel@tonic-gate 		}
7797c478bd9Sstevel@tonic-gate #endif /* NETINFO */
7807c478bd9Sstevel@tonic-gate #if HESIOD
7817c478bd9Sstevel@tonic-gate 		else if (strcmp(maptype[i], "hesiod") == 0 &&
7827c478bd9Sstevel@tonic-gate 			 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
7837c478bd9Sstevel@tonic-gate 		{
7847c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
785058561cbSjbeck 				sizeof(buf));
7867c478bd9Sstevel@tonic-gate 			(void) makemapentry(buf);
7877c478bd9Sstevel@tonic-gate 		}
7887c478bd9Sstevel@tonic-gate #endif /* HESIOD */
789d25d47eeSjbeck #if LDAPMAP && defined(SUN_EXTENSIONS) && \
790d25d47eeSjbeck     defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
7917c478bd9Sstevel@tonic-gate 		else if (strcmp(maptype[i], "ldap") == 0 &&
7927c478bd9Sstevel@tonic-gate 		    stab("aliases.ldap", ST_MAP, ST_FIND) == NULL)
7937c478bd9Sstevel@tonic-gate 		{
794e9af4bc0SJohn Beck 			(void) sm_strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
7957c478bd9Sstevel@tonic-gate 				sizeof buf);
7967c478bd9Sstevel@tonic-gate 			(void) makemapentry(buf);
7977c478bd9Sstevel@tonic-gate 		}
798d25d47eeSjbeck #endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */
7997c478bd9Sstevel@tonic-gate 	}
8007c478bd9Sstevel@tonic-gate 	if (stab("aliases", ST_MAP, ST_FIND) == NULL)
8017c478bd9Sstevel@tonic-gate 	{
802058561cbSjbeck 		(void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf));
8037c478bd9Sstevel@tonic-gate 		(void) makemapentry(buf);
8047c478bd9Sstevel@tonic-gate 	}
8057c478bd9Sstevel@tonic-gate }
806058561cbSjbeck 
8077c478bd9Sstevel@tonic-gate /*
8087c478bd9Sstevel@tonic-gate **  SWITCH_MAP_FIND -- find the list of types associated with a map
8097c478bd9Sstevel@tonic-gate **
8107c478bd9Sstevel@tonic-gate **	This is the system-dependent interface to the service switch.
8117c478bd9Sstevel@tonic-gate **
8127c478bd9Sstevel@tonic-gate **	Parameters:
8137c478bd9Sstevel@tonic-gate **		service -- the name of the service of interest.
8147c478bd9Sstevel@tonic-gate **		maptype -- an out-array of strings containing the types
8157c478bd9Sstevel@tonic-gate **			of access to use for this service.  There can
8167c478bd9Sstevel@tonic-gate **			be at most MAXMAPSTACK types for a single service.
8177c478bd9Sstevel@tonic-gate **		mapreturn -- an out-array of return information bitmaps
8187c478bd9Sstevel@tonic-gate **			for the map.
8197c478bd9Sstevel@tonic-gate **
8207c478bd9Sstevel@tonic-gate **	Returns:
8217c478bd9Sstevel@tonic-gate **		The number of map types filled in, or -1 for failure.
8227c478bd9Sstevel@tonic-gate **
8237c478bd9Sstevel@tonic-gate **	Side effects:
8247c478bd9Sstevel@tonic-gate **		Preserves errno so nothing in the routine clobbers it.
8257c478bd9Sstevel@tonic-gate */
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
8287c478bd9Sstevel@tonic-gate # define _USE_SUN_NSSWITCH_
8297c478bd9Sstevel@tonic-gate #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate #if _FFR_HPUX_NSSWITCH
8327c478bd9Sstevel@tonic-gate # ifdef __hpux
8337c478bd9Sstevel@tonic-gate #  define _USE_SUN_NSSWITCH_
8347c478bd9Sstevel@tonic-gate # endif /* __hpux */
8357c478bd9Sstevel@tonic-gate #endif /* _FFR_HPUX_NSSWITCH */
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate #ifdef _USE_SUN_NSSWITCH_
8387c478bd9Sstevel@tonic-gate # include <nsswitch.h>
8397c478bd9Sstevel@tonic-gate #endif /* _USE_SUN_NSSWITCH_ */
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate #if defined(ultrix) || (defined(__osf__) && defined(__alpha))
8427c478bd9Sstevel@tonic-gate # define _USE_DEC_SVC_CONF_
8437c478bd9Sstevel@tonic-gate #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate #ifdef _USE_DEC_SVC_CONF_
8467c478bd9Sstevel@tonic-gate # include <sys/svcinfo.h>
8477c478bd9Sstevel@tonic-gate #endif /* _USE_DEC_SVC_CONF_ */
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate int
switch_map_find(service,maptype,mapreturn)8507c478bd9Sstevel@tonic-gate switch_map_find(service, maptype, mapreturn)
8517c478bd9Sstevel@tonic-gate 	char *service;
8527c478bd9Sstevel@tonic-gate 	char *maptype[MAXMAPSTACK];
8537c478bd9Sstevel@tonic-gate 	short mapreturn[MAXMAPACTIONS];
8547c478bd9Sstevel@tonic-gate {
8557c478bd9Sstevel@tonic-gate 	int svcno = 0;
8567c478bd9Sstevel@tonic-gate 	int save_errno = errno;
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate #ifdef _USE_SUN_NSSWITCH_
8597c478bd9Sstevel@tonic-gate 	struct __nsw_switchconfig *nsw_conf;
8607c478bd9Sstevel@tonic-gate 	enum __nsw_parse_err pserr;
8617c478bd9Sstevel@tonic-gate 	struct __nsw_lookup *lk;
8627c478bd9Sstevel@tonic-gate 	static struct __nsw_lookup lkp0 =
8637c478bd9Sstevel@tonic-gate 		{ "files", {1, 0, 0, 0}, NULL, NULL };
8647c478bd9Sstevel@tonic-gate 	static struct __nsw_switchconfig lkp_default =
8657c478bd9Sstevel@tonic-gate 		{ 0, "sendmail", 3, &lkp0 };
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 	for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
8687c478bd9Sstevel@tonic-gate 		mapreturn[svcno] = 0;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
8717c478bd9Sstevel@tonic-gate 		lk = lkp_default.lookups;
8727c478bd9Sstevel@tonic-gate 	else
8737c478bd9Sstevel@tonic-gate 		lk = nsw_conf->lookups;
8747c478bd9Sstevel@tonic-gate 	svcno = 0;
8757c478bd9Sstevel@tonic-gate 	while (lk != NULL && svcno < MAXMAPSTACK)
8767c478bd9Sstevel@tonic-gate 	{
8777c478bd9Sstevel@tonic-gate 		maptype[svcno] = lk->service_name;
8787c478bd9Sstevel@tonic-gate 		if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
8797c478bd9Sstevel@tonic-gate 			mapreturn[MA_NOTFOUND] |= 1 << svcno;
8807c478bd9Sstevel@tonic-gate 		if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
8817c478bd9Sstevel@tonic-gate 			mapreturn[MA_TRYAGAIN] |= 1 << svcno;
8827c478bd9Sstevel@tonic-gate 		if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
8837c478bd9Sstevel@tonic-gate 			mapreturn[MA_TRYAGAIN] |= 1 << svcno;
8847c478bd9Sstevel@tonic-gate 		svcno++;
8857c478bd9Sstevel@tonic-gate 		lk = lk->next;
8867c478bd9Sstevel@tonic-gate 	}
8877c478bd9Sstevel@tonic-gate 	errno = save_errno;
8887c478bd9Sstevel@tonic-gate 	return svcno;
8897c478bd9Sstevel@tonic-gate #endif /* _USE_SUN_NSSWITCH_ */
8907c478bd9Sstevel@tonic-gate 
8917c478bd9Sstevel@tonic-gate #ifdef _USE_DEC_SVC_CONF_
8927c478bd9Sstevel@tonic-gate 	struct svcinfo *svcinfo;
8937c478bd9Sstevel@tonic-gate 	int svc;
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
8967c478bd9Sstevel@tonic-gate 		mapreturn[svcno] = 0;
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate 	svcinfo = getsvc();
8997c478bd9Sstevel@tonic-gate 	if (svcinfo == NULL)
9007c478bd9Sstevel@tonic-gate 		goto punt;
9017c478bd9Sstevel@tonic-gate 	if (strcmp(service, "hosts") == 0)
9027c478bd9Sstevel@tonic-gate 		svc = SVC_HOSTS;
9037c478bd9Sstevel@tonic-gate 	else if (strcmp(service, "aliases") == 0)
9047c478bd9Sstevel@tonic-gate 		svc = SVC_ALIASES;
9057c478bd9Sstevel@tonic-gate 	else if (strcmp(service, "passwd") == 0)
9067c478bd9Sstevel@tonic-gate 		svc = SVC_PASSWD;
9077c478bd9Sstevel@tonic-gate 	else
9087c478bd9Sstevel@tonic-gate 	{
9097c478bd9Sstevel@tonic-gate 		errno = save_errno;
9107c478bd9Sstevel@tonic-gate 		return -1;
9117c478bd9Sstevel@tonic-gate 	}
9127c478bd9Sstevel@tonic-gate 	for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
9137c478bd9Sstevel@tonic-gate 	{
9147c478bd9Sstevel@tonic-gate 		switch (svcinfo->svcpath[svc][svcno])
9157c478bd9Sstevel@tonic-gate 		{
9167c478bd9Sstevel@tonic-gate 		  case SVC_LOCAL:
9177c478bd9Sstevel@tonic-gate 			maptype[svcno] = "files";
9187c478bd9Sstevel@tonic-gate 			break;
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate 		  case SVC_YP:
9217c478bd9Sstevel@tonic-gate 			maptype[svcno] = "nis";
9227c478bd9Sstevel@tonic-gate 			break;
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 		  case SVC_BIND:
9257c478bd9Sstevel@tonic-gate 			maptype[svcno] = "dns";
9267c478bd9Sstevel@tonic-gate 			break;
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate # ifdef SVC_HESIOD
9297c478bd9Sstevel@tonic-gate 		  case SVC_HESIOD:
9307c478bd9Sstevel@tonic-gate 			maptype[svcno] = "hesiod";
9317c478bd9Sstevel@tonic-gate 			break;
9327c478bd9Sstevel@tonic-gate # endif /* SVC_HESIOD */
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate 		  case SVC_LAST:
9357c478bd9Sstevel@tonic-gate 			errno = save_errno;
9367c478bd9Sstevel@tonic-gate 			return svcno;
9377c478bd9Sstevel@tonic-gate 		}
9387c478bd9Sstevel@tonic-gate 	}
9397c478bd9Sstevel@tonic-gate 	errno = save_errno;
9407c478bd9Sstevel@tonic-gate 	return svcno;
9417c478bd9Sstevel@tonic-gate #endif /* _USE_DEC_SVC_CONF_ */
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
9447c478bd9Sstevel@tonic-gate 	/*
9457c478bd9Sstevel@tonic-gate 	**  Fall-back mechanism.
9467c478bd9Sstevel@tonic-gate 	*/
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate 	STAB *st;
9497c478bd9Sstevel@tonic-gate 	static time_t servicecachetime;	/* time service switch was cached */
9507c478bd9Sstevel@tonic-gate 	time_t now = curtime();
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate 	for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
9537c478bd9Sstevel@tonic-gate 		mapreturn[svcno] = 0;
9547c478bd9Sstevel@tonic-gate 
9557c478bd9Sstevel@tonic-gate 	if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
9567c478bd9Sstevel@tonic-gate 	{
9577c478bd9Sstevel@tonic-gate 		/* (re)read service switch */
9587c478bd9Sstevel@tonic-gate 		register SM_FILE_T *fp;
9597c478bd9Sstevel@tonic-gate 		long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate 		if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
9627c478bd9Sstevel@tonic-gate 			    DontBlameSendmail))
9637c478bd9Sstevel@tonic-gate 			sff |= SFF_NOWLINK;
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 		if (ConfigFileRead)
9667c478bd9Sstevel@tonic-gate 			servicecachetime = now;
9677c478bd9Sstevel@tonic-gate 		fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
9687c478bd9Sstevel@tonic-gate 		if (fp != NULL)
9697c478bd9Sstevel@tonic-gate 		{
9707c478bd9Sstevel@tonic-gate 			char buf[MAXLINE];
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 			while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
973058561cbSjbeck 					   sizeof(buf)) != NULL)
9747c478bd9Sstevel@tonic-gate 			{
9757c478bd9Sstevel@tonic-gate 				register char *p;
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 				p = strpbrk(buf, "#\n");
9787c478bd9Sstevel@tonic-gate 				if (p != NULL)
9797c478bd9Sstevel@tonic-gate 					*p = '\0';
980e9af4bc0SJohn Beck #ifndef SM_NSSWITCH_DELIMS
981e9af4bc0SJohn Beck # define SM_NSSWITCH_DELIMS	" \t"
982e9af4bc0SJohn Beck #endif /* SM_NSSWITCH_DELIMS */
983e9af4bc0SJohn Beck 				p = strpbrk(buf, SM_NSSWITCH_DELIMS);
9847c478bd9Sstevel@tonic-gate 				if (p != NULL)
9857c478bd9Sstevel@tonic-gate 					*p++ = '\0';
9867c478bd9Sstevel@tonic-gate 				if (buf[0] == '\0')
9877c478bd9Sstevel@tonic-gate 					continue;
9887c478bd9Sstevel@tonic-gate 				if (p == NULL)
9897c478bd9Sstevel@tonic-gate 				{
9907c478bd9Sstevel@tonic-gate 					sm_syslog(LOG_ERR, NOQID,
9917c478bd9Sstevel@tonic-gate 						  "Bad line on %.100s: %.100s",
9927c478bd9Sstevel@tonic-gate 						  ServiceSwitchFile,
9937c478bd9Sstevel@tonic-gate 						  buf);
9947c478bd9Sstevel@tonic-gate 					continue;
9957c478bd9Sstevel@tonic-gate 				}
996e9af4bc0SJohn Beck 				while (isascii(*p) && isspace(*p))
9977c478bd9Sstevel@tonic-gate 					p++;
9987c478bd9Sstevel@tonic-gate 				if (*p == '\0')
9997c478bd9Sstevel@tonic-gate 					continue;
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate 				/*
10027c478bd9Sstevel@tonic-gate 				**  Find/allocate space for this service entry.
10037c478bd9Sstevel@tonic-gate 				**	Space for all of the service strings
10047c478bd9Sstevel@tonic-gate 				**	are allocated at once.  This means
10057c478bd9Sstevel@tonic-gate 				**	that we only have to free the first
10067c478bd9Sstevel@tonic-gate 				**	one to free all of them.
10077c478bd9Sstevel@tonic-gate 				*/
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 				st = stab(buf, ST_SERVICE, ST_ENTER);
10107c478bd9Sstevel@tonic-gate 				if (st->s_service[0] != NULL)
10117c478bd9Sstevel@tonic-gate 					sm_free((void *) st->s_service[0]); /* XXX */
10127c478bd9Sstevel@tonic-gate 				p = newstr(p);
10137c478bd9Sstevel@tonic-gate 				for (svcno = 0; svcno < MAXMAPSTACK; )
10147c478bd9Sstevel@tonic-gate 				{
10157c478bd9Sstevel@tonic-gate 					if (*p == '\0')
10167c478bd9Sstevel@tonic-gate 						break;
10177c478bd9Sstevel@tonic-gate 					st->s_service[svcno++] = p;
10187c478bd9Sstevel@tonic-gate 					p = strpbrk(p, " \t");
10197c478bd9Sstevel@tonic-gate 					if (p == NULL)
10207c478bd9Sstevel@tonic-gate 						break;
10217c478bd9Sstevel@tonic-gate 					*p++ = '\0';
1022e9af4bc0SJohn Beck 					while (isascii(*p) && isspace(*p))
10237c478bd9Sstevel@tonic-gate 						p++;
10247c478bd9Sstevel@tonic-gate 				}
10257c478bd9Sstevel@tonic-gate 				if (svcno < MAXMAPSTACK)
10267c478bd9Sstevel@tonic-gate 					st->s_service[svcno] = NULL;
10277c478bd9Sstevel@tonic-gate 			}
10287c478bd9Sstevel@tonic-gate 			(void) sm_io_close(fp, SM_TIME_DEFAULT);
10297c478bd9Sstevel@tonic-gate 		}
10307c478bd9Sstevel@tonic-gate 	}
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate 	/* look up entry in cache */
10337c478bd9Sstevel@tonic-gate 	st = stab(service, ST_SERVICE, ST_FIND);
10347c478bd9Sstevel@tonic-gate 	if (st != NULL && st->s_service[0] != NULL)
10357c478bd9Sstevel@tonic-gate 	{
10367c478bd9Sstevel@tonic-gate 		/* extract data */
10377c478bd9Sstevel@tonic-gate 		svcno = 0;
10387c478bd9Sstevel@tonic-gate 		while (svcno < MAXMAPSTACK)
10397c478bd9Sstevel@tonic-gate 		{
10407c478bd9Sstevel@tonic-gate 			maptype[svcno] = st->s_service[svcno];
10417c478bd9Sstevel@tonic-gate 			if (maptype[svcno++] == NULL)
10427c478bd9Sstevel@tonic-gate 				break;
10437c478bd9Sstevel@tonic-gate 		}
10447c478bd9Sstevel@tonic-gate 		errno = save_errno;
10457c478bd9Sstevel@tonic-gate 		return --svcno;
10467c478bd9Sstevel@tonic-gate 	}
10477c478bd9Sstevel@tonic-gate #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate #if !defined(_USE_SUN_NSSWITCH_)
10507c478bd9Sstevel@tonic-gate 	/* if the service file doesn't work, use an absolute fallback */
10517c478bd9Sstevel@tonic-gate # ifdef _USE_DEC_SVC_CONF_
10527c478bd9Sstevel@tonic-gate   punt:
10537c478bd9Sstevel@tonic-gate # endif /* _USE_DEC_SVC_CONF_ */
10547c478bd9Sstevel@tonic-gate 	for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
10557c478bd9Sstevel@tonic-gate 		mapreturn[svcno] = 0;
10567c478bd9Sstevel@tonic-gate 	svcno = 0;
10577c478bd9Sstevel@tonic-gate 	if (strcmp(service, "aliases") == 0)
10587c478bd9Sstevel@tonic-gate 	{
10597c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "files";
10607c478bd9Sstevel@tonic-gate # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
10617c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "netinfo";
10627c478bd9Sstevel@tonic-gate # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
10637c478bd9Sstevel@tonic-gate # ifdef AUTO_NIS_ALIASES
10647c478bd9Sstevel@tonic-gate #  if NISPLUS
10657c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "nisplus";
10667c478bd9Sstevel@tonic-gate #  endif /* NISPLUS */
10677c478bd9Sstevel@tonic-gate #  if NIS
10687c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "nis";
10697c478bd9Sstevel@tonic-gate #  endif /* NIS */
10707c478bd9Sstevel@tonic-gate # endif /* AUTO_NIS_ALIASES */
10717c478bd9Sstevel@tonic-gate 		errno = save_errno;
10727c478bd9Sstevel@tonic-gate 		return svcno;
10737c478bd9Sstevel@tonic-gate 	}
10747c478bd9Sstevel@tonic-gate 	if (strcmp(service, "hosts") == 0)
10757c478bd9Sstevel@tonic-gate 	{
10767c478bd9Sstevel@tonic-gate # if NAMED_BIND
10777c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "dns";
10787c478bd9Sstevel@tonic-gate # else /* NAMED_BIND */
10797c478bd9Sstevel@tonic-gate #  if defined(sun) && !defined(BSD)
10807c478bd9Sstevel@tonic-gate 		/* SunOS */
10817c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "nis";
10827c478bd9Sstevel@tonic-gate #  endif /* defined(sun) && !defined(BSD) */
10837c478bd9Sstevel@tonic-gate # endif /* NAMED_BIND */
10847c478bd9Sstevel@tonic-gate # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
10857c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "netinfo";
10867c478bd9Sstevel@tonic-gate # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
10877c478bd9Sstevel@tonic-gate 		maptype[svcno++] = "files";
10887c478bd9Sstevel@tonic-gate 		errno = save_errno;
10897c478bd9Sstevel@tonic-gate 		return svcno;
10907c478bd9Sstevel@tonic-gate 	}
10917c478bd9Sstevel@tonic-gate 	errno = save_errno;
10927c478bd9Sstevel@tonic-gate 	return -1;
10937c478bd9Sstevel@tonic-gate #endif /* !defined(_USE_SUN_NSSWITCH_) */
10947c478bd9Sstevel@tonic-gate }
10957c478bd9Sstevel@tonic-gate /*
10967c478bd9Sstevel@tonic-gate **  USERNAME -- return the user id of the logged in user.
10977c478bd9Sstevel@tonic-gate **
10987c478bd9Sstevel@tonic-gate **	Parameters:
10997c478bd9Sstevel@tonic-gate **		none.
11007c478bd9Sstevel@tonic-gate **
11017c478bd9Sstevel@tonic-gate **	Returns:
11027c478bd9Sstevel@tonic-gate **		The login name of the logged in user.
11037c478bd9Sstevel@tonic-gate **
11047c478bd9Sstevel@tonic-gate **	Side Effects:
11057c478bd9Sstevel@tonic-gate **		none.
11067c478bd9Sstevel@tonic-gate **
11077c478bd9Sstevel@tonic-gate **	Notes:
11087c478bd9Sstevel@tonic-gate **		The return value is statically allocated.
11097c478bd9Sstevel@tonic-gate */
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate char *
username()11127c478bd9Sstevel@tonic-gate username()
11137c478bd9Sstevel@tonic-gate {
11147c478bd9Sstevel@tonic-gate 	static char *myname = NULL;
11157c478bd9Sstevel@tonic-gate 	extern char *getlogin();
11167c478bd9Sstevel@tonic-gate 	register struct passwd *pw;
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 	/* cache the result */
11197c478bd9Sstevel@tonic-gate 	if (myname == NULL)
11207c478bd9Sstevel@tonic-gate 	{
11217c478bd9Sstevel@tonic-gate 		myname = getlogin();
11227c478bd9Sstevel@tonic-gate 		if (myname == NULL || myname[0] == '\0')
11237c478bd9Sstevel@tonic-gate 		{
11247c478bd9Sstevel@tonic-gate 			pw = sm_getpwuid(RealUid);
11257c478bd9Sstevel@tonic-gate 			if (pw != NULL)
11267c478bd9Sstevel@tonic-gate 				myname = pw->pw_name;
11277c478bd9Sstevel@tonic-gate 		}
11287c478bd9Sstevel@tonic-gate 		else
11297c478bd9Sstevel@tonic-gate 		{
11307c478bd9Sstevel@tonic-gate 			uid_t uid = RealUid;
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 			if ((pw = sm_getpwnam(myname)) == NULL ||
11337c478bd9Sstevel@tonic-gate 			      (uid != 0 && uid != pw->pw_uid))
11347c478bd9Sstevel@tonic-gate 			{
11357c478bd9Sstevel@tonic-gate 				pw = sm_getpwuid(uid);
11367c478bd9Sstevel@tonic-gate 				if (pw != NULL)
11377c478bd9Sstevel@tonic-gate 					myname = pw->pw_name;
11387c478bd9Sstevel@tonic-gate 			}
11397c478bd9Sstevel@tonic-gate 		}
11407c478bd9Sstevel@tonic-gate 		if (myname == NULL || myname[0] == '\0')
11417c478bd9Sstevel@tonic-gate 		{
11427c478bd9Sstevel@tonic-gate 			syserr("554 5.3.0 Who are you?");
11437c478bd9Sstevel@tonic-gate 			myname = "postmaster";
11447c478bd9Sstevel@tonic-gate 		}
11457c478bd9Sstevel@tonic-gate 		else if (strpbrk(myname, ",;:/|\"\\") != NULL)
11467c478bd9Sstevel@tonic-gate 			myname = addquotes(myname, NULL);
11477c478bd9Sstevel@tonic-gate 		else
11487c478bd9Sstevel@tonic-gate 			myname = sm_pstrdup_x(myname);
11497c478bd9Sstevel@tonic-gate 	}
11507c478bd9Sstevel@tonic-gate 	return myname;
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate /*
11537c478bd9Sstevel@tonic-gate **  TTYPATH -- Get the path of the user's tty
11547c478bd9Sstevel@tonic-gate **
11557c478bd9Sstevel@tonic-gate **	Returns the pathname of the user's tty.  Returns NULL if
115648bbca81SDaniel Hoffman **	the user is not logged in or if they have write permission
11577c478bd9Sstevel@tonic-gate **	denied.
11587c478bd9Sstevel@tonic-gate **
11597c478bd9Sstevel@tonic-gate **	Parameters:
11607c478bd9Sstevel@tonic-gate **		none
11617c478bd9Sstevel@tonic-gate **
11627c478bd9Sstevel@tonic-gate **	Returns:
11637c478bd9Sstevel@tonic-gate **		pathname of the user's tty.
11647c478bd9Sstevel@tonic-gate **		NULL if not logged in or write permission denied.
11657c478bd9Sstevel@tonic-gate **
11667c478bd9Sstevel@tonic-gate **	Side Effects:
11677c478bd9Sstevel@tonic-gate **		none.
11687c478bd9Sstevel@tonic-gate **
11697c478bd9Sstevel@tonic-gate **	WARNING:
11707c478bd9Sstevel@tonic-gate **		Return value is in a local buffer.
11717c478bd9Sstevel@tonic-gate **
11727c478bd9Sstevel@tonic-gate **	Called By:
11737c478bd9Sstevel@tonic-gate **		savemail
11747c478bd9Sstevel@tonic-gate */
11757c478bd9Sstevel@tonic-gate 
11767c478bd9Sstevel@tonic-gate char *
ttypath()11777c478bd9Sstevel@tonic-gate ttypath()
11787c478bd9Sstevel@tonic-gate {
11797c478bd9Sstevel@tonic-gate 	struct stat stbuf;
11807c478bd9Sstevel@tonic-gate 	register char *pathn;
11817c478bd9Sstevel@tonic-gate 	extern char *ttyname();
11827c478bd9Sstevel@tonic-gate 	extern char *getlogin();
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate 	/* compute the pathname of the controlling tty */
11857c478bd9Sstevel@tonic-gate 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
11867c478bd9Sstevel@tonic-gate 	    (pathn = ttyname(0)) == NULL)
11877c478bd9Sstevel@tonic-gate 	{
11887c478bd9Sstevel@tonic-gate 		errno = 0;
11897c478bd9Sstevel@tonic-gate 		return NULL;
11907c478bd9Sstevel@tonic-gate 	}
11917c478bd9Sstevel@tonic-gate 
11927c478bd9Sstevel@tonic-gate 	/* see if we have write permission */
11937c478bd9Sstevel@tonic-gate 	if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
11947c478bd9Sstevel@tonic-gate