xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 57454)
122698Sdist /*
234920Sbostic  * Copyright (c) 1983 Eric P. Allman
333728Sbostic  * Copyright (c) 1988 Regents of the University of California.
433728Sbostic  * All rights reserved.
533728Sbostic  *
642825Sbostic  * %sccs.include.redist.c%
733728Sbostic  */
822698Sdist 
922698Sdist #ifndef lint
10*57454Seric static char sccsid[] = "@(#)conf.c	6.7 (Berkeley) 01/10/93";
1133728Sbostic #endif /* not lint */
1222698Sdist 
1314881Seric # include <sys/ioctl.h>
1436928Sbostic # include <pwd.h>
153309Seric # include "sendmail.h"
1640980Sbostic # include "pathnames.h"
17404Seric 
18294Seric /*
193309Seric **  CONF.C -- Sendmail Configuration Tables.
20294Seric **
21294Seric **	Defines the configuration of this installation.
22294Seric **
231388Seric **	Configuration Variables:
242897Seric **		HdrInfo -- a table describing well-known header fields.
252897Seric **			Each entry has the field name and some flags,
264147Seric **			which are described in sendmail.h.
274093Seric **
284093Seric **	Notes:
294093Seric **		I have tried to put almost all the reasonable
304093Seric **		configuration information into the configuration
314093Seric **		file read at runtime.  My intent is that anything
324093Seric **		here is a function of the version of UNIX you
334093Seric **		are running, or is really static -- for example
344093Seric **		the headers are a superset of widely used
354093Seric **		protocols.  If you find yourself playing with
364093Seric **		this file too much, you may be making a mistake!
37294Seric */
38294Seric 
39294Seric 
40294Seric 
41294Seric 
424437Seric /*
432897Seric **  Header info table
443057Seric **	Final (null) entry contains the flags used for any other field.
454147Seric **
464147Seric **	Not all of these are actually handled specially by sendmail
474147Seric **	at this time.  They are included as placeholders, to let
484147Seric **	you know that "someday" I intend to have sendmail do
494147Seric **	something with them.
502897Seric */
512897Seric 
522897Seric struct hdrinfo	HdrInfo[] =
532897Seric {
548060Seric 		/* originator fields, most to least significant  */
5511417Seric 	"resent-sender",	H_FROM|H_RESENT,
5611417Seric 	"resent-from",		H_FROM|H_RESENT,
5725686Seric 	"resent-reply-to",	H_FROM|H_RESENT,
589055Seric 	"sender",		H_FROM,
599055Seric 	"from",			H_FROM,
6025686Seric 	"reply-to",		H_FROM,
619055Seric 	"full-name",		H_ACHECK,
6257359Seric 	"return-receipt-to",	H_FROM /* |H_RECEIPTTO */,
6357359Seric 	"errors-to",		H_FROM|H_ERRORSTO,
648060Seric 		/* destination fields */
659055Seric 	"to",			H_RCPT,
6611417Seric 	"resent-to",		H_RCPT|H_RESENT,
679055Seric 	"cc",			H_RCPT,
6811417Seric 	"resent-cc",		H_RCPT|H_RESENT,
699055Seric 	"bcc",			H_RCPT|H_ACHECK,
7011417Seric 	"resent-bcc",		H_RCPT|H_ACHECK|H_RESENT,
7156215Seric 	"apparently-to",	H_RCPT,
728060Seric 		/* message identification and control */
7311417Seric 	"message-id",		0,
7411417Seric 	"resent-message-id",	H_RESENT,
759055Seric 	"message",		H_EOH,
769055Seric 	"text",			H_EOH,
7711417Seric 		/* date fields */
7811417Seric 	"date",			0,
7911417Seric 	"resent-date",		H_RESENT,
808060Seric 		/* trace fields */
819055Seric 	"received",		H_TRACE|H_FORCE,
829055Seric 	"via",			H_TRACE|H_FORCE,
839055Seric 	"mail-from",		H_TRACE|H_FORCE,
848060Seric 
859055Seric 	NULL,			0,
862897Seric };
874166Seric 
884166Seric 
894166Seric /*
904166Seric **  ARPANET error message numbers.
914166Seric */
924166Seric 
937956Seric char	Arpa_Info[] =		"050";	/* arbitrary info */
947956Seric char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
957956Seric char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
967956Seric char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
974282Seric 
984282Seric 
994282Seric 
1004282Seric /*
1014282Seric **  Location of system files/databases/etc.
1024282Seric */
1034282Seric 
10440980Sbostic char	*ConfFile =	_PATH_SENDMAILCF;	/* runtime configuration */
10540980Sbostic char	*FreezeFile =	_PATH_SENDMAILFC;	/* frozen version of above */
1069039Seric 
1079064Seric 
1089064Seric 
1099039Seric /*
11024943Seric **  Miscellaneous stuff.
1119039Seric */
1129039Seric 
11324943Seric int	DtableSize =	50;		/* max open files; reset in 4.2bsd */
11424943Seric /*
11524943Seric **  SETDEFAULTS -- set default values
11624943Seric **
11724943Seric **	Because of the way freezing is done, these must be initialized
11824943Seric **	using direct code.
11924943Seric **
12024943Seric **	Parameters:
12124943Seric **		none.
12224943Seric **
12324943Seric **	Returns:
12424943Seric **		none.
12524943Seric **
12624943Seric **	Side Effects:
12724943Seric **		Initializes a bunch of global variables to their
12824943Seric **		default values.
12924943Seric */
13024943Seric 
13124943Seric setdefaults()
13224943Seric {
13357438Seric 	SpaceSub = ' ';				/* option B */
13457438Seric 	QueueLA = 8;				/* option x */
13557438Seric 	RefuseLA = 12;				/* option X */
13657438Seric 	WkRecipFact = 30000L;			/* option y */
13757438Seric 	WkClassFact = 1800L;			/* option z */
13857438Seric 	WkTimeFact = 90000L;			/* option Z */
13957438Seric 	QueueFactor = WkRecipFact * 20;		/* option q */
14057142Seric 	FileMode = (getuid() != geteuid()) ? 0644 : 0600;
14157438Seric 						/* option F */
14257438Seric 	DefUid = 1;				/* option u */
14357438Seric 	DefGid = 1;				/* option g */
14457438Seric 	CheckpointInterval = 10;		/* option C */
14557438Seric 	MaxHopCount = 25;			/* option h */
14657438Seric 	SendMode = SM_FORK;			/* option d */
14757438Seric 	ErrorMode = EM_PRINT;			/* option e */
14857438Seric 	EightBit = FALSE;			/* option 8 */
14957438Seric 	MaxMciCache = 1;			/* option k */
15057438Seric 	MciCacheTimeout = 300;			/* option K */
15157438Seric 	LogLevel = 9;				/* option L */
15257438Seric 	ReadTimeout = 2 * 60 * 60;		/* option r */
15357438Seric 	TimeOut = 3 * 24 * 60 * 60;		/* option T */
15440973Sbostic 	setdefuser();
15553654Seric 	setupmaps();
15657402Seric 	setupmailers();
15724943Seric }
158294Seric 
15940973Sbostic 
1604326Seric /*
16140973Sbostic **  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
16240973Sbostic */
16340973Sbostic 
16440973Sbostic setdefuser()
16540973Sbostic {
16640973Sbostic 	struct passwd *defpwent;
16757386Seric 	static char defuserbuf[40];
16840973Sbostic 
16957386Seric 	DefUser = defuserbuf;
17040973Sbostic 	if ((defpwent = getpwuid(DefUid)) != NULL)
17157386Seric 		strcpy(defuserbuf, defpwent->pw_name);
17240973Sbostic 	else
17357386Seric 		strcpy(defuserbuf, "nobody");
17440973Sbostic }
17553654Seric /*
17653654Seric **  SETUPMAPS -- set up map classes
17753654Seric **
17853654Seric **	Since these are compiled in, they cannot be in the config file.
17953654Seric **
18053654Seric */
18140973Sbostic 
18253654Seric setupmaps()
18353654Seric {
18453654Seric 	register STAB *s;
18556836Seric 	extern bool host_map_init();
18653654Seric 	extern char *maphostname();
18740973Sbostic 
18853654Seric 	/* set up host name lookup map */
18953654Seric 	s = stab("host", ST_MAPCLASS, ST_ENTER);
19056836Seric 	s->s_mapclass.map_init = host_map_init;
19153654Seric 	s->s_mapclass.map_lookup = maphostname;
19253654Seric 
19353654Seric 	/*
19453654Seric 	**  Set up other map classes.
19553654Seric 	*/
19653654Seric 
19753654Seric # ifdef DBM_MAP
19853654Seric 	/* dbm file access */
19953654Seric 	{
20056836Seric 		extern bool dbm_map_init();
20153654Seric 		extern char *dbm_map_lookup();
20253654Seric 
20353654Seric 		s = stab("dbm", ST_MAPCLASS, ST_ENTER);
20453654Seric 		s->s_mapclass.map_init = dbm_map_init;
20553654Seric 		s->s_mapclass.map_lookup = dbm_map_lookup;
20653654Seric 	}
20753654Seric # endif
20853654Seric 
20953654Seric # ifdef BTREE_MAP
21053654Seric 	/* new database file access -- btree files */
21153654Seric 	{
21256823Seric 		extern bool bt_map_init();
21356823Seric 		extern char *db_map_lookup();
21453654Seric 
21553654Seric 		s = stab("btree", ST_MAPCLASS, ST_ENTER);
21653654Seric 		s->s_mapclass.map_init = bt_map_init;
21756823Seric 		s->s_mapclass.map_lookup = db_map_lookup;
21853654Seric 	}
21953654Seric # endif
22053654Seric 
22153654Seric # ifdef HASH_MAP
22253654Seric 	/* new database file access -- hash files */
22353654Seric 	{
22456823Seric 		extern bool hash_map_init();
22556823Seric 		extern char *db_map_lookup();
22653654Seric 
22753654Seric 		s = stab("hash", ST_MAPCLASS, ST_ENTER);
22853654Seric 		s->s_mapclass.map_init = hash_map_init;
22956823Seric 		s->s_mapclass.map_lookup = db_map_lookup;
23053654Seric 	}
23153654Seric # endif
23253654Seric 
23357208Seric # ifdef NIS_MAP
23457208Seric 	/* NIS map access */
23557208Seric 	{
23657208Seric 		extern bool nis_map_init();
23757208Seric 		extern char *nis_map_lookup();
23857208Seric 
23957208Seric 		s = stab("nis", ST_MAPCLASS, ST_ENTER);
24057208Seric 		s->s_mapclass.map_init = nis_map_init;
24157208Seric 		s->s_mapclass.map_lookup = nis_map_lookup;
24257208Seric 	}
24357208Seric # endif
24457208Seric 
24553654Seric # ifdef USERDB_MAP
24653654Seric 	/* user database */
24753654Seric 	{
24856836Seric 		extern bool udb_map_init();
24953654Seric 		extern char *udb_map_lookup();
25053654Seric 
25153654Seric 		s = stab("udb", ST_MAPCLASS, ST_ENTER);
25253654Seric 		s->s_mapclass.map_init = udb_map_init;
25353654Seric 		s->s_mapclass.map_lookup = udb_map_lookup;
25453654Seric 	}
25553654Seric # endif
25653654Seric }
25753654Seric /*
25856836Seric **  HOST_MAP_INIT -- initialize host class structures
25956836Seric */
26056836Seric 
26156836Seric bool
26256836Seric host_map_init(map, mapname, args)
26356836Seric 	MAP *map;
26456836Seric 	char *mapname;
26556836Seric 	char *args;
26656836Seric {
26756836Seric 	register char *p = args;
26856836Seric 
26956836Seric 	for (;;)
27056836Seric 	{
27156836Seric 		while (isspace(*p))
27256836Seric 			p++;
27356836Seric 		if (*p != '-')
27456836Seric 			break;
27556836Seric 		switch (*++p)
27656836Seric 		{
27756836Seric 		  case 'a':
27856836Seric 			map->map_app = ++p;
27956836Seric 			break;
28056836Seric 		}
28156836Seric 		while (*p != '\0' && !isspace(*p))
28256836Seric 			p++;
28356836Seric 		if (*p != '\0')
28456836Seric 			*p++ = '\0';
28556836Seric 	}
28656836Seric 	if (map->map_app != NULL)
28756836Seric 		map->map_app = newstr(map->map_app);
28856836Seric 	return TRUE;
28956836Seric }
29057402Seric /*
29157402Seric **  SETUPMAILERS -- initialize default mailers
29257402Seric */
29356836Seric 
29457402Seric setupmailers()
29557402Seric {
29657402Seric 	char buf[100];
29757402Seric 
29857403Seric 	strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u");
29957403Seric 	makemailer(buf);
30057403Seric 
30157402Seric 	strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE");
30257402Seric 	makemailer(buf);
30357402Seric 
30457402Seric 	strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE");
30557402Seric 	makemailer(buf);
30657402Seric }
30756836Seric /*
3084326Seric **  GETRUID -- get real user id (V7)
3094326Seric */
3104326Seric 
3114326Seric getruid()
3124326Seric {
3139274Seric 	if (OpMode == MD_DAEMON)
3144536Seric 		return (RealUid);
3154536Seric 	else
3164536Seric 		return (getuid());
3174326Seric }
3184326Seric 
3194326Seric 
3204326Seric /*
3214326Seric **  GETRGID -- get real group id (V7).
3224326Seric */
3234326Seric 
3244326Seric getrgid()
3254326Seric {
3269274Seric 	if (OpMode == MD_DAEMON)
3274536Seric 		return (RealGid);
3284536Seric 	else
3294536Seric 		return (getgid());
3304326Seric }
33153654Seric /*
3329369Seric **  USERNAME -- return the user id of the logged in user.
3339369Seric **
3349369Seric **	Parameters:
3359369Seric **		none.
3369369Seric **
3379369Seric **	Returns:
3389369Seric **		The login name of the logged in user.
3399369Seric **
3409369Seric **	Side Effects:
3419369Seric **		none.
3429369Seric **
3439369Seric **	Notes:
3449369Seric **		The return value is statically allocated.
3459369Seric */
3469369Seric 
3479369Seric char *
3489369Seric username()
3499369Seric {
35017469Seric 	static char *myname = NULL;
3519369Seric 	extern char *getlogin();
35219904Smiriam 	register struct passwd *pw;
3539369Seric 
35417469Seric 	/* cache the result */
35517469Seric 	if (myname == NULL)
35617469Seric 	{
35717469Seric 		myname = getlogin();
35817469Seric 		if (myname == NULL || myname[0] == '\0')
35917469Seric 		{
36017469Seric 
36117469Seric 			pw = getpwuid(getruid());
36217469Seric 			if (pw != NULL)
36340993Sbostic 				myname = newstr(pw->pw_name);
36417469Seric 		}
36519904Smiriam 		else
36619904Smiriam 		{
36719873Smiriam 
36840993Sbostic 			myname = newstr(myname);
36940993Sbostic 			if ((pw = getpwnam(myname)) == NULL ||
37040993Sbostic 			      getuid() != pw->pw_uid)
37119904Smiriam 			{
37219873Smiriam 				pw = getpwuid(getuid());
37324945Seric 				if (pw != NULL)
37440993Sbostic 					myname = newstr(pw->pw_name);
37519873Smiriam 			}
37619873Smiriam 		}
37717469Seric 		if (myname == NULL || myname[0] == '\0')
37817469Seric 		{
37917469Seric 			syserr("Who are you?");
38017469Seric 			myname = "postmaster";
38117469Seric 		}
38217469Seric 	}
38317469Seric 
38417469Seric 	return (myname);
3859369Seric }
3869369Seric /*
3874190Seric **  TTYPATH -- Get the path of the user's tty
388294Seric **
389294Seric **	Returns the pathname of the user's tty.  Returns NULL if
390294Seric **	the user is not logged in or if s/he has write permission
391294Seric **	denied.
392294Seric **
393294Seric **	Parameters:
394294Seric **		none
395294Seric **
396294Seric **	Returns:
397294Seric **		pathname of the user's tty.
398294Seric **		NULL if not logged in or write permission denied.
399294Seric **
400294Seric **	Side Effects:
401294Seric **		none.
402294Seric **
403294Seric **	WARNING:
404294Seric **		Return value is in a local buffer.
405294Seric **
406294Seric **	Called By:
407294Seric **		savemail
408294Seric */
409294Seric 
410294Seric # include <sys/stat.h>
411294Seric 
412294Seric char *
413294Seric ttypath()
414294Seric {
415294Seric 	struct stat stbuf;
416294Seric 	register char *pathn;
417294Seric 	extern char *ttyname();
4184081Seric 	extern char *getlogin();
419294Seric 
420294Seric 	/* compute the pathname of the controlling tty */
4219369Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
4229369Seric 	    (pathn = ttyname(0)) == NULL)
423294Seric 	{
424294Seric 		errno = 0;
425294Seric 		return (NULL);
426294Seric 	}
427294Seric 
428294Seric 	/* see if we have write permission */
4292967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
430294Seric 	{
431294Seric 		errno = 0;
432294Seric 		return (NULL);
433294Seric 	}
434294Seric 
435294Seric 	/* see if the user is logged in */
436294Seric 	if (getlogin() == NULL)
437294Seric 		return (NULL);
438294Seric 
439294Seric 	/* looks good */
440294Seric 	return (pathn);
441294Seric }
4422967Seric /*
4432967Seric **  CHECKCOMPAT -- check for From and To person compatible.
4442967Seric **
4452967Seric **	This routine can be supplied on a per-installation basis
4462967Seric **	to determine whether a person is allowed to send a message.
4472967Seric **	This allows restriction of certain types of internet
4482967Seric **	forwarding or registration of users.
4492967Seric **
4502967Seric **	If the hosts are found to be incompatible, an error
451*57454Seric **	message should be given using "usrerr" and 0 should
4522967Seric **	be returned.
4532967Seric **
4544288Seric **	'NoReturn' can be set to suppress the return-to-sender
4554288Seric **	function; this should be done on huge messages.
4564288Seric **
4572967Seric **	Parameters:
4582967Seric **		to -- the person being sent to.
4592967Seric **
4602967Seric **	Returns:
461*57454Seric **		+1 -- ok to send.
462*57454Seric **		0 -- not ok.
463*57454Seric **		-1 -- return TEMPFAIL.
4642967Seric **
4652967Seric **	Side Effects:
4662967Seric **		none (unless you include the usrerr stuff)
4672967Seric */
4682967Seric 
46955012Seric checkcompat(to, e)
4702967Seric 	register ADDRESS *to;
47155012Seric 	register ENVELOPE *e;
4722967Seric {
47312133Seric # ifdef lint
47412133Seric 	if (to == NULL)
47512133Seric 		to++;
47612133Seric # endif lint
47710698Seric # ifdef EXAMPLE_CODE
47810698Seric 	/* this code is intended as an example only */
4794437Seric 	register STAB *s;
4804437Seric 
4814437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
48255012Seric 	if (s != NULL && e->e_from.q_mailer != LocalMailer &&
4839369Seric 	    to->q_mailer == s->s_mailer)
4844437Seric 	{
4854437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
48610698Seric 		/* NoReturn = TRUE; to supress return copy */
4874437Seric 		return (FALSE);
4884437Seric 	}
48956795Seric # endif /* EXAMPLE_CODE */
4902967Seric 	return (TRUE);
4912967Seric }
4929369Seric /*
4939369Seric **  HOLDSIGS -- arrange to hold all signals
4949369Seric **
4959369Seric **	Parameters:
4969369Seric **		none.
4979369Seric **
4989369Seric **	Returns:
4999369Seric **		none.
5009369Seric **
5019369Seric **	Side Effects:
5029369Seric **		Arranges that signals are held.
5039369Seric */
5049369Seric 
5059369Seric holdsigs()
5069369Seric {
5079369Seric }
5089369Seric /*
5099369Seric **  RLSESIGS -- arrange to release all signals
5109369Seric **
5119369Seric **	This undoes the effect of holdsigs.
5129369Seric **
5139369Seric **	Parameters:
5149369Seric **		none.
5159369Seric **
5169369Seric **	Returns:
5179369Seric **		none.
5189369Seric **
5199369Seric **	Side Effects:
5209369Seric **		Arranges that signals are released.
5219369Seric */
5229369Seric 
5239369Seric rlsesigs()
5249369Seric {
5259369Seric }
52614872Seric /*
52714872Seric **  GETLA -- get the current load average
52814872Seric **
52914881Seric **	This code stolen from la.c.
53014881Seric **
53114872Seric **	Parameters:
53214872Seric **		none.
53314872Seric **
53414872Seric **	Returns:
53514872Seric **		The current load average as an integer.
53614872Seric **
53714872Seric **	Side Effects:
53814872Seric **		none.
53914872Seric */
54014872Seric 
54151920Seric /* try to guess what style of load average we have */
54251920Seric #define LA_ZERO		1	/* always return load average as zero */
54351920Seric #define LA_INT		2	/* read kmem for avenrun; interpret as int */
54451920Seric #define LA_FLOAT	3	/* read kmem for avenrun; interpret as float */
54551920Seric #define LA_SUBR		4	/* call getloadavg */
54614872Seric 
54751920Seric #ifndef LA_TYPE
54851920Seric #  if defined(sun)
54951920Seric #    define LA_TYPE		LA_INT
55051920Seric #  endif
55151920Seric #  if defined(mips)
55251920Seric      /* Ultrix or RISC/os */
55351920Seric #    define LA_TYPE		LA_INT
55451920Seric #    define LA_AVENRUN		"avenrun"
55551920Seric #  endif
55651920Seric #  if defined(hpux)
55751920Seric #    define LA_TYPE		LA_FLOAT
55851920Seric #  endif
55951920Seric #  if defined(BSD)
56051920Seric #    define LA_TYPE		LA_SUBR
56151920Seric #  endif
56251920Seric 
56351920Seric #  ifndef LA_TYPE
56451920Seric #    define LA_TYPE		LA_ZERO
56551920Seric #  endif
56651920Seric #endif
56751920Seric 
56851920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT)
56951920Seric 
57014872Seric #include <nlist.h>
57151920Seric #include <fcntl.h>
57214872Seric 
57351920Seric #ifndef LA_AVENRUN
57451920Seric #define LA_AVENRUN	"_avenrun"
57551920Seric #endif
57651920Seric 
57751920Seric /* _PATH_UNIX should be defined in <paths.h> */
57851920Seric #ifndef _PATH_UNIX
57951920Seric #  if defined(hpux)
58051920Seric #    define _PATH_UNIX		"/hp-ux"
58151920Seric #  endif
58251920Seric #  if defined(mips) && !defined(ultrix)
58351920Seric      /* powerful RISC/os */
58451920Seric #    define _PATH_UNIX		"/unix"
58551920Seric #  endif
58651920Seric #  ifndef _PATH_UNIX
58751920Seric #    define _PATH_UNIX		"/vmunix"
58851920Seric #  endif
58951920Seric #endif
59051920Seric 
59114872Seric struct	nlist Nl[] =
59214872Seric {
59351920Seric 	{ LA_AVENRUN },
59414872Seric #define	X_AVENRUN	0
59514872Seric 	{ 0 },
59614872Seric };
59714872Seric 
59851920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT)
59951920Seric #  define FSHIFT	8
60051920Seric #  define FSCALE	(1 << FSHIFT)
60151920Seric #endif
60240930Srick 
60314872Seric getla()
60414872Seric {
60514872Seric 	static int kmem = -1;
60651920Seric #if LA_TYPE == LA_INT
60724943Seric 	long avenrun[3];
60851920Seric #else
60951920Seric 	double avenrun[3];
61051920Seric #endif
61125615Seric 	extern off_t lseek();
61214872Seric 
61314872Seric 	if (kmem < 0)
61414872Seric 	{
61524945Seric 		kmem = open("/dev/kmem", 0, 0);
61614872Seric 		if (kmem < 0)
61714872Seric 			return (-1);
61851920Seric 		(void) fcntl(kmem, F_SETFD, 1);
61951920Seric 		nlist(_PATH_UNIX, Nl);
62014872Seric 		if (Nl[0].n_type == 0)
62114872Seric 			return (-1);
62214872Seric 	}
62324945Seric 	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
62423118Seric 	    read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
62519967Seric 	{
62619967Seric 		/* thank you Ian */
62719967Seric 		return (-1);
62819967Seric 	}
62951920Seric #if LA_TYPE == LA_INT
63024943Seric 	return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
63151920Seric #else
63251920Seric 	return ((int) (avenrun[0] + 0.5));
63351920Seric #endif
63414872Seric }
63514872Seric 
63651773Seric #else
63751920Seric #if LA_TYPE == LA_SUBR
63851773Seric 
63951773Seric getla()
64051773Seric {
64151920Seric 	double avenrun[3];
64251920Seric 
64351920Seric 	if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
64451920Seric 		return (-1);
64551920Seric 	return ((int) (avenrun[0] + 0.5));
64651773Seric }
64751773Seric 
64851773Seric #else
64951773Seric 
65051773Seric getla()
65151773Seric {
65251920Seric 	return (0);
65351773Seric }
65451773Seric 
65551773Seric #endif
65651773Seric #endif
65724943Seric /*
65824943Seric **  SHOULDQUEUE -- should this message be queued or sent?
65924943Seric **
66024943Seric **	Compares the message cost to the load average to decide.
66124943Seric **
66224943Seric **	Parameters:
66324943Seric **		pri -- the priority of the message in question.
66457438Seric **		ctime -- the message creation time.
66524943Seric **
66624943Seric **	Returns:
66724943Seric **		TRUE -- if this message should be queued up for the
66824943Seric **			time being.
66924943Seric **		FALSE -- if the load is low enough to send this message.
67024943Seric **
67124943Seric **	Side Effects:
67224943Seric **		none.
67324943Seric */
67424943Seric 
67524943Seric bool
67657438Seric shouldqueue(pri, ctime)
67724943Seric 	long pri;
67857438Seric 	time_t ctime;
67924943Seric {
68051920Seric 	if (CurrentLA < QueueLA)
68124943Seric 		return (FALSE);
68251920Seric 	return (pri > (QueueFactor / (CurrentLA - QueueLA + 1)));
68324943Seric }
68424943Seric /*
68553037Seric **  REFUSECONNECTIONS -- decide if connections should be refused
68653037Seric **
68753037Seric **	Parameters:
68853037Seric **		none.
68953037Seric **
69053037Seric **	Returns:
69153037Seric **		TRUE if incoming SMTP connections should be refused
69253037Seric **			(for now).
69353037Seric **		FALSE if we should accept new work.
69453037Seric **
69553037Seric **	Side Effects:
69653037Seric **		none.
69753037Seric */
69853037Seric 
69953037Seric bool
70053037Seric refuseconnections()
70153037Seric {
70253037Seric 	/* this is probably too simplistic */
70353037Seric 	return (CurrentLA > RefuseLA);
70453037Seric }
70553037Seric /*
70624943Seric **  SETPROCTITLE -- set process title for ps
70724943Seric **
70824943Seric **	Parameters:
70924943Seric **		fmt -- a printf style format string.
71024943Seric **		a, b, c -- possible parameters to fmt.
71124943Seric **
71224943Seric **	Returns:
71324943Seric **		none.
71424943Seric **
71524943Seric **	Side Effects:
71624943Seric **		Clobbers argv of our main procedure so ps(1) will
71724943Seric **		display the title.
71824943Seric */
71924943Seric 
72024943Seric /*VARARGS1*/
72156852Seric setproctitle(fmt VA_ARG_FORMAL)
72224943Seric 	char *fmt;
72356852Seric 	VA_ARG_DECL
72424943Seric {
72524943Seric # ifdef SETPROCTITLE
72624943Seric 	register char *p;
72725049Seric 	register int i;
72856852Seric 	char buf[MAXLINE];
72956852Seric 	VA_LOCAL_DECL
73024943Seric 	extern char **Argv;
73124943Seric 	extern char *LastArgv;
73224943Seric 
73354996Seric 	p = buf;
73424943Seric 
73554996Seric 	/* print sendmail: heading for grep */
73654996Seric 	(void) strcpy(p, "sendmail: ");
73754996Seric 	p += strlen(p);
73824943Seric 
73954996Seric 	/* print the argument string */
74056852Seric 	VA_START(fmt);
74156852Seric 	(void) vsprintf(p, fmt, ap);
74256852Seric 	VA_END;
74354996Seric 
74425049Seric 	i = strlen(buf);
74554996Seric 	if (i > LastArgv - Argv[0] - 2)
74625049Seric 	{
74754996Seric 		i = LastArgv - Argv[0] - 2;
74825049Seric 		buf[i] = '\0';
74925049Seric 	}
75054996Seric 	(void) strcpy(Argv[0], buf);
75154997Seric 	p = &Argv[0][i];
75224943Seric 	while (p < LastArgv)
75324943Seric 		*p++ = ' ';
75456795Seric # endif /* SETPROCTITLE */
75524943Seric }
75625698Seric /*
75725698Seric **  REAPCHILD -- pick up the body of my child, lest it become a zombie
75825698Seric **
75925698Seric **	Parameters:
76025698Seric **		none.
76125698Seric **
76225698Seric **	Returns:
76325698Seric **		none.
76425698Seric **
76525698Seric **	Side Effects:
76625698Seric **		Picks up extant zombies.
76725698Seric */
76825698Seric 
76925698Seric # include <sys/wait.h>
77025698Seric 
77146928Sbostic void
77225698Seric reapchild()
77325698Seric {
77425698Seric # ifdef WNOHANG
77525698Seric 	union wait status;
77625698Seric 
77746928Sbostic 	while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0)
77825698Seric 		continue;
77956795Seric # else /* WNOHANG */
78025698Seric 	auto int status;
78125698Seric 
78246928Sbostic 	while (wait((int *)&status) > 0)
78325698Seric 		continue;
78456795Seric # endif /* WNOHANG */
78525698Seric }
78655418Seric /*
78755418Seric **  UNSETENV -- remove a variable from the environment
78855418Seric **
78955418Seric **	Not needed on newer systems.
79055418Seric **
79155418Seric **	Parameters:
79255418Seric **		name -- the string name of the environment variable to be
79355418Seric **			deleted from the current environment.
79455418Seric **
79555418Seric **	Returns:
79655418Seric **		none.
79755418Seric **
79855418Seric **	Globals:
79955418Seric **		environ -- a pointer to the current environment.
80055418Seric **
80155418Seric **	Side Effects:
80255418Seric **		Modifies environ.
80355418Seric */
80455418Seric 
80555418Seric #ifdef UNSETENV
80655418Seric 
80755418Seric void
80855418Seric unsetenv(name)
80955418Seric 	char *name;
81055418Seric {
81155418Seric 	extern char **environ;
81255418Seric 	register char **pp;
81355418Seric 	int len = strlen(name);
81455418Seric 
81555418Seric 	for (pp = environ; *pp != NULL; pp++)
81655418Seric 	{
81755418Seric 		if (strncmp(name, *pp, len) == 0 &&
81855418Seric 		    ((*pp)[len] == '=' || (*pp)[len] == '\0'))
81955418Seric 			break;
82055418Seric 	}
82155418Seric 
82255418Seric 	for (; *pp != NULL; pp++)
82355418Seric 		*pp = pp[1];
82455418Seric }
82555418Seric 
82655418Seric #endif /* UNSETENV */
82756215Seric /*
82856215Seric **  GETDTABLESIZE -- return number of file descriptors
82956215Seric **
83056215Seric **	Only on non-BSD systems
83156215Seric **
83256215Seric **	Parameters:
83356215Seric **		none
83456215Seric **
83556215Seric **	Returns:
83656215Seric **		size of file descriptor table
83756215Seric **
83856215Seric **	Side Effects:
83956215Seric **		none
84056215Seric */
84156215Seric 
84256215Seric #ifdef SYSTEM5
84356215Seric 
84456215Seric int
84556215Seric getdtablesize()
84656215Seric {
84756215Seric 	return NOFILE;
84856215Seric }
84956215Seric 
85056215Seric #endif
851