xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 57403)
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*57403Seric static char sccsid[] = "@(#)conf.c	6.5 (Berkeley) 01/02/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 {
13324943Seric 	QueueLA = 8;
13424943Seric 	QueueFactor = 10000;
13524943Seric 	RefuseLA = 12;
13624943Seric 	SpaceSub = ' ';
13724981Seric 	WkRecipFact = 1000;
13824981Seric 	WkClassFact = 1800;
13925812Seric 	WkTimeFact = 9000;
14057142Seric 	FileMode = (getuid() != geteuid()) ? 0644 : 0600;
14124981Seric 	DefUid = 1;
14224981Seric 	DefGid = 1;
14347284Seric 	CheckpointInterval = 10;
14457142Seric 	MaxHopCount = 17;
14552105Seric 	SendMode = SM_FORK;
14652105Seric 	ErrorMode = EM_PRINT;
14752106Seric 	EightBit = FALSE;
14854967Seric 	MaxMciCache = 1;
14954967Seric 	MciCacheTimeout = 300;
15040973Sbostic 	setdefuser();
15153654Seric 	setupmaps();
15257402Seric 	setupmailers();
15324943Seric }
154294Seric 
15540973Sbostic 
1564326Seric /*
15740973Sbostic **  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
15840973Sbostic */
15940973Sbostic 
16040973Sbostic setdefuser()
16140973Sbostic {
16240973Sbostic 	struct passwd *defpwent;
16357386Seric 	static char defuserbuf[40];
16440973Sbostic 
16557386Seric 	DefUser = defuserbuf;
16640973Sbostic 	if ((defpwent = getpwuid(DefUid)) != NULL)
16757386Seric 		strcpy(defuserbuf, defpwent->pw_name);
16840973Sbostic 	else
16957386Seric 		strcpy(defuserbuf, "nobody");
17040973Sbostic }
17153654Seric /*
17253654Seric **  SETUPMAPS -- set up map classes
17353654Seric **
17453654Seric **	Since these are compiled in, they cannot be in the config file.
17553654Seric **
17653654Seric */
17740973Sbostic 
17853654Seric setupmaps()
17953654Seric {
18053654Seric 	register STAB *s;
18156836Seric 	extern bool host_map_init();
18253654Seric 	extern char *maphostname();
18340973Sbostic 
18453654Seric 	/* set up host name lookup map */
18553654Seric 	s = stab("host", ST_MAPCLASS, ST_ENTER);
18656836Seric 	s->s_mapclass.map_init = host_map_init;
18753654Seric 	s->s_mapclass.map_lookup = maphostname;
18853654Seric 
18953654Seric 	/*
19053654Seric 	**  Set up other map classes.
19153654Seric 	*/
19253654Seric 
19353654Seric # ifdef DBM_MAP
19453654Seric 	/* dbm file access */
19553654Seric 	{
19656836Seric 		extern bool dbm_map_init();
19753654Seric 		extern char *dbm_map_lookup();
19853654Seric 
19953654Seric 		s = stab("dbm", ST_MAPCLASS, ST_ENTER);
20053654Seric 		s->s_mapclass.map_init = dbm_map_init;
20153654Seric 		s->s_mapclass.map_lookup = dbm_map_lookup;
20253654Seric 	}
20353654Seric # endif
20453654Seric 
20553654Seric # ifdef BTREE_MAP
20653654Seric 	/* new database file access -- btree files */
20753654Seric 	{
20856823Seric 		extern bool bt_map_init();
20956823Seric 		extern char *db_map_lookup();
21053654Seric 
21153654Seric 		s = stab("btree", ST_MAPCLASS, ST_ENTER);
21253654Seric 		s->s_mapclass.map_init = bt_map_init;
21356823Seric 		s->s_mapclass.map_lookup = db_map_lookup;
21453654Seric 	}
21553654Seric # endif
21653654Seric 
21753654Seric # ifdef HASH_MAP
21853654Seric 	/* new database file access -- hash files */
21953654Seric 	{
22056823Seric 		extern bool hash_map_init();
22156823Seric 		extern char *db_map_lookup();
22253654Seric 
22353654Seric 		s = stab("hash", ST_MAPCLASS, ST_ENTER);
22453654Seric 		s->s_mapclass.map_init = hash_map_init;
22556823Seric 		s->s_mapclass.map_lookup = db_map_lookup;
22653654Seric 	}
22753654Seric # endif
22853654Seric 
22957208Seric # ifdef NIS_MAP
23057208Seric 	/* NIS map access */
23157208Seric 	{
23257208Seric 		extern bool nis_map_init();
23357208Seric 		extern char *nis_map_lookup();
23457208Seric 
23557208Seric 		s = stab("nis", ST_MAPCLASS, ST_ENTER);
23657208Seric 		s->s_mapclass.map_init = nis_map_init;
23757208Seric 		s->s_mapclass.map_lookup = nis_map_lookup;
23857208Seric 	}
23957208Seric # endif
24057208Seric 
24153654Seric # ifdef USERDB_MAP
24253654Seric 	/* user database */
24353654Seric 	{
24456836Seric 		extern bool udb_map_init();
24553654Seric 		extern char *udb_map_lookup();
24653654Seric 
24753654Seric 		s = stab("udb", ST_MAPCLASS, ST_ENTER);
24853654Seric 		s->s_mapclass.map_init = udb_map_init;
24953654Seric 		s->s_mapclass.map_lookup = udb_map_lookup;
25053654Seric 	}
25153654Seric # endif
25253654Seric }
25353654Seric /*
25456836Seric **  HOST_MAP_INIT -- initialize host class structures
25556836Seric */
25656836Seric 
25756836Seric bool
25856836Seric host_map_init(map, mapname, args)
25956836Seric 	MAP *map;
26056836Seric 	char *mapname;
26156836Seric 	char *args;
26256836Seric {
26356836Seric 	register char *p = args;
26456836Seric 
26556836Seric 	for (;;)
26656836Seric 	{
26756836Seric 		while (isspace(*p))
26856836Seric 			p++;
26956836Seric 		if (*p != '-')
27056836Seric 			break;
27156836Seric 		switch (*++p)
27256836Seric 		{
27356836Seric 		  case 'a':
27456836Seric 			map->map_app = ++p;
27556836Seric 			break;
27656836Seric 		}
27756836Seric 		while (*p != '\0' && !isspace(*p))
27856836Seric 			p++;
27956836Seric 		if (*p != '\0')
28056836Seric 			*p++ = '\0';
28156836Seric 	}
28256836Seric 	if (map->map_app != NULL)
28356836Seric 		map->map_app = newstr(map->map_app);
28456836Seric 	return TRUE;
28556836Seric }
28657402Seric /*
28757402Seric **  SETUPMAILERS -- initialize default mailers
28857402Seric */
28956836Seric 
29057402Seric setupmailers()
29157402Seric {
29257402Seric 	char buf[100];
29357402Seric 
294*57403Seric 	strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u");
295*57403Seric 	makemailer(buf);
296*57403Seric 
29757402Seric 	strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE");
29857402Seric 	makemailer(buf);
29957402Seric 
30057402Seric 	strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE");
30157402Seric 	makemailer(buf);
30257402Seric }
30356836Seric /*
3044326Seric **  GETRUID -- get real user id (V7)
3054326Seric */
3064326Seric 
3074326Seric getruid()
3084326Seric {
3099274Seric 	if (OpMode == MD_DAEMON)
3104536Seric 		return (RealUid);
3114536Seric 	else
3124536Seric 		return (getuid());
3134326Seric }
3144326Seric 
3154326Seric 
3164326Seric /*
3174326Seric **  GETRGID -- get real group id (V7).
3184326Seric */
3194326Seric 
3204326Seric getrgid()
3214326Seric {
3229274Seric 	if (OpMode == MD_DAEMON)
3234536Seric 		return (RealGid);
3244536Seric 	else
3254536Seric 		return (getgid());
3264326Seric }
32753654Seric /*
3289369Seric **  USERNAME -- return the user id of the logged in user.
3299369Seric **
3309369Seric **	Parameters:
3319369Seric **		none.
3329369Seric **
3339369Seric **	Returns:
3349369Seric **		The login name of the logged in user.
3359369Seric **
3369369Seric **	Side Effects:
3379369Seric **		none.
3389369Seric **
3399369Seric **	Notes:
3409369Seric **		The return value is statically allocated.
3419369Seric */
3429369Seric 
3439369Seric char *
3449369Seric username()
3459369Seric {
34617469Seric 	static char *myname = NULL;
3479369Seric 	extern char *getlogin();
34819904Smiriam 	register struct passwd *pw;
3499369Seric 
35017469Seric 	/* cache the result */
35117469Seric 	if (myname == NULL)
35217469Seric 	{
35317469Seric 		myname = getlogin();
35417469Seric 		if (myname == NULL || myname[0] == '\0')
35517469Seric 		{
35617469Seric 
35717469Seric 			pw = getpwuid(getruid());
35817469Seric 			if (pw != NULL)
35940993Sbostic 				myname = newstr(pw->pw_name);
36017469Seric 		}
36119904Smiriam 		else
36219904Smiriam 		{
36319873Smiriam 
36440993Sbostic 			myname = newstr(myname);
36540993Sbostic 			if ((pw = getpwnam(myname)) == NULL ||
36640993Sbostic 			      getuid() != pw->pw_uid)
36719904Smiriam 			{
36819873Smiriam 				pw = getpwuid(getuid());
36924945Seric 				if (pw != NULL)
37040993Sbostic 					myname = newstr(pw->pw_name);
37119873Smiriam 			}
37219873Smiriam 		}
37317469Seric 		if (myname == NULL || myname[0] == '\0')
37417469Seric 		{
37517469Seric 			syserr("Who are you?");
37617469Seric 			myname = "postmaster";
37717469Seric 		}
37817469Seric 	}
37917469Seric 
38017469Seric 	return (myname);
3819369Seric }
3829369Seric /*
3834190Seric **  TTYPATH -- Get the path of the user's tty
384294Seric **
385294Seric **	Returns the pathname of the user's tty.  Returns NULL if
386294Seric **	the user is not logged in or if s/he has write permission
387294Seric **	denied.
388294Seric **
389294Seric **	Parameters:
390294Seric **		none
391294Seric **
392294Seric **	Returns:
393294Seric **		pathname of the user's tty.
394294Seric **		NULL if not logged in or write permission denied.
395294Seric **
396294Seric **	Side Effects:
397294Seric **		none.
398294Seric **
399294Seric **	WARNING:
400294Seric **		Return value is in a local buffer.
401294Seric **
402294Seric **	Called By:
403294Seric **		savemail
404294Seric */
405294Seric 
406294Seric # include <sys/stat.h>
407294Seric 
408294Seric char *
409294Seric ttypath()
410294Seric {
411294Seric 	struct stat stbuf;
412294Seric 	register char *pathn;
413294Seric 	extern char *ttyname();
4144081Seric 	extern char *getlogin();
415294Seric 
416294Seric 	/* compute the pathname of the controlling tty */
4179369Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
4189369Seric 	    (pathn = ttyname(0)) == NULL)
419294Seric 	{
420294Seric 		errno = 0;
421294Seric 		return (NULL);
422294Seric 	}
423294Seric 
424294Seric 	/* see if we have write permission */
4252967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
426294Seric 	{
427294Seric 		errno = 0;
428294Seric 		return (NULL);
429294Seric 	}
430294Seric 
431294Seric 	/* see if the user is logged in */
432294Seric 	if (getlogin() == NULL)
433294Seric 		return (NULL);
434294Seric 
435294Seric 	/* looks good */
436294Seric 	return (pathn);
437294Seric }
4382967Seric /*
4392967Seric **  CHECKCOMPAT -- check for From and To person compatible.
4402967Seric **
4412967Seric **	This routine can be supplied on a per-installation basis
4422967Seric **	to determine whether a person is allowed to send a message.
4432967Seric **	This allows restriction of certain types of internet
4442967Seric **	forwarding or registration of users.
4452967Seric **
4462967Seric **	If the hosts are found to be incompatible, an error
4472967Seric **	message should be given using "usrerr" and FALSE should
4482967Seric **	be returned.
4492967Seric **
4504288Seric **	'NoReturn' can be set to suppress the return-to-sender
4514288Seric **	function; this should be done on huge messages.
4524288Seric **
4532967Seric **	Parameters:
4542967Seric **		to -- the person being sent to.
4552967Seric **
4562967Seric **	Returns:
4572967Seric **		TRUE -- ok to send.
4582967Seric **		FALSE -- not ok.
4592967Seric **
4602967Seric **	Side Effects:
4612967Seric **		none (unless you include the usrerr stuff)
4622967Seric */
4632967Seric 
4642967Seric bool
46555012Seric checkcompat(to, e)
4662967Seric 	register ADDRESS *to;
46755012Seric 	register ENVELOPE *e;
4682967Seric {
46912133Seric # ifdef lint
47012133Seric 	if (to == NULL)
47112133Seric 		to++;
47212133Seric # endif lint
47310698Seric # ifdef EXAMPLE_CODE
47410698Seric 	/* this code is intended as an example only */
4754437Seric 	register STAB *s;
4764437Seric 
4774437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
47855012Seric 	if (s != NULL && e->e_from.q_mailer != LocalMailer &&
4799369Seric 	    to->q_mailer == s->s_mailer)
4804437Seric 	{
4814437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
48210698Seric 		/* NoReturn = TRUE; to supress return copy */
4834437Seric 		return (FALSE);
4844437Seric 	}
48556795Seric # endif /* EXAMPLE_CODE */
4862967Seric 	return (TRUE);
4872967Seric }
4889369Seric /*
4899369Seric **  HOLDSIGS -- arrange to hold all signals
4909369Seric **
4919369Seric **	Parameters:
4929369Seric **		none.
4939369Seric **
4949369Seric **	Returns:
4959369Seric **		none.
4969369Seric **
4979369Seric **	Side Effects:
4989369Seric **		Arranges that signals are held.
4999369Seric */
5009369Seric 
5019369Seric holdsigs()
5029369Seric {
5039369Seric }
5049369Seric /*
5059369Seric **  RLSESIGS -- arrange to release all signals
5069369Seric **
5079369Seric **	This undoes the effect of holdsigs.
5089369Seric **
5099369Seric **	Parameters:
5109369Seric **		none.
5119369Seric **
5129369Seric **	Returns:
5139369Seric **		none.
5149369Seric **
5159369Seric **	Side Effects:
5169369Seric **		Arranges that signals are released.
5179369Seric */
5189369Seric 
5199369Seric rlsesigs()
5209369Seric {
5219369Seric }
52214872Seric /*
52314872Seric **  GETLA -- get the current load average
52414872Seric **
52514881Seric **	This code stolen from la.c.
52614881Seric **
52714872Seric **	Parameters:
52814872Seric **		none.
52914872Seric **
53014872Seric **	Returns:
53114872Seric **		The current load average as an integer.
53214872Seric **
53314872Seric **	Side Effects:
53414872Seric **		none.
53514872Seric */
53614872Seric 
53751920Seric /* try to guess what style of load average we have */
53851920Seric #define LA_ZERO		1	/* always return load average as zero */
53951920Seric #define LA_INT		2	/* read kmem for avenrun; interpret as int */
54051920Seric #define LA_FLOAT	3	/* read kmem for avenrun; interpret as float */
54151920Seric #define LA_SUBR		4	/* call getloadavg */
54214872Seric 
54351920Seric #ifndef LA_TYPE
54451920Seric #  if defined(sun)
54551920Seric #    define LA_TYPE		LA_INT
54651920Seric #  endif
54751920Seric #  if defined(mips)
54851920Seric      /* Ultrix or RISC/os */
54951920Seric #    define LA_TYPE		LA_INT
55051920Seric #    define LA_AVENRUN		"avenrun"
55151920Seric #  endif
55251920Seric #  if defined(hpux)
55351920Seric #    define LA_TYPE		LA_FLOAT
55451920Seric #  endif
55551920Seric #  if defined(BSD)
55651920Seric #    define LA_TYPE		LA_SUBR
55751920Seric #  endif
55851920Seric 
55951920Seric #  ifndef LA_TYPE
56051920Seric #    define LA_TYPE		LA_ZERO
56151920Seric #  endif
56251920Seric #endif
56351920Seric 
56451920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT)
56551920Seric 
56614872Seric #include <nlist.h>
56751920Seric #include <fcntl.h>
56814872Seric 
56951920Seric #ifndef LA_AVENRUN
57051920Seric #define LA_AVENRUN	"_avenrun"
57151920Seric #endif
57251920Seric 
57351920Seric /* _PATH_UNIX should be defined in <paths.h> */
57451920Seric #ifndef _PATH_UNIX
57551920Seric #  if defined(hpux)
57651920Seric #    define _PATH_UNIX		"/hp-ux"
57751920Seric #  endif
57851920Seric #  if defined(mips) && !defined(ultrix)
57951920Seric      /* powerful RISC/os */
58051920Seric #    define _PATH_UNIX		"/unix"
58151920Seric #  endif
58251920Seric #  ifndef _PATH_UNIX
58351920Seric #    define _PATH_UNIX		"/vmunix"
58451920Seric #  endif
58551920Seric #endif
58651920Seric 
58714872Seric struct	nlist Nl[] =
58814872Seric {
58951920Seric 	{ LA_AVENRUN },
59014872Seric #define	X_AVENRUN	0
59114872Seric 	{ 0 },
59214872Seric };
59314872Seric 
59451920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT)
59551920Seric #  define FSHIFT	8
59651920Seric #  define FSCALE	(1 << FSHIFT)
59751920Seric #endif
59840930Srick 
59914872Seric getla()
60014872Seric {
60114872Seric 	static int kmem = -1;
60251920Seric #if LA_TYPE == LA_INT
60324943Seric 	long avenrun[3];
60451920Seric #else
60551920Seric 	double avenrun[3];
60651920Seric #endif
60725615Seric 	extern off_t lseek();
60814872Seric 
60914872Seric 	if (kmem < 0)
61014872Seric 	{
61124945Seric 		kmem = open("/dev/kmem", 0, 0);
61214872Seric 		if (kmem < 0)
61314872Seric 			return (-1);
61451920Seric 		(void) fcntl(kmem, F_SETFD, 1);
61551920Seric 		nlist(_PATH_UNIX, Nl);
61614872Seric 		if (Nl[0].n_type == 0)
61714872Seric 			return (-1);
61814872Seric 	}
61924945Seric 	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
62023118Seric 	    read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
62119967Seric 	{
62219967Seric 		/* thank you Ian */
62319967Seric 		return (-1);
62419967Seric 	}
62551920Seric #if LA_TYPE == LA_INT
62624943Seric 	return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
62751920Seric #else
62851920Seric 	return ((int) (avenrun[0] + 0.5));
62951920Seric #endif
63014872Seric }
63114872Seric 
63251773Seric #else
63351920Seric #if LA_TYPE == LA_SUBR
63451773Seric 
63551773Seric getla()
63651773Seric {
63751920Seric 	double avenrun[3];
63851920Seric 
63951920Seric 	if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
64051920Seric 		return (-1);
64151920Seric 	return ((int) (avenrun[0] + 0.5));
64251773Seric }
64351773Seric 
64451773Seric #else
64551773Seric 
64651773Seric getla()
64751773Seric {
64851920Seric 	return (0);
64951773Seric }
65051773Seric 
65151773Seric #endif
65251773Seric #endif
65324943Seric /*
65424943Seric **  SHOULDQUEUE -- should this message be queued or sent?
65524943Seric **
65624943Seric **	Compares the message cost to the load average to decide.
65724943Seric **
65824943Seric **	Parameters:
65924943Seric **		pri -- the priority of the message in question.
66024943Seric **
66124943Seric **	Returns:
66224943Seric **		TRUE -- if this message should be queued up for the
66324943Seric **			time being.
66424943Seric **		FALSE -- if the load is low enough to send this message.
66524943Seric **
66624943Seric **	Side Effects:
66724943Seric **		none.
66824943Seric */
66924943Seric 
67024943Seric bool
67124943Seric shouldqueue(pri)
67224943Seric 	long pri;
67324943Seric {
67451920Seric 	if (CurrentLA < QueueLA)
67524943Seric 		return (FALSE);
67651920Seric 	return (pri > (QueueFactor / (CurrentLA - QueueLA + 1)));
67724943Seric }
67824943Seric /*
67953037Seric **  REFUSECONNECTIONS -- decide if connections should be refused
68053037Seric **
68153037Seric **	Parameters:
68253037Seric **		none.
68353037Seric **
68453037Seric **	Returns:
68553037Seric **		TRUE if incoming SMTP connections should be refused
68653037Seric **			(for now).
68753037Seric **		FALSE if we should accept new work.
68853037Seric **
68953037Seric **	Side Effects:
69053037Seric **		none.
69153037Seric */
69253037Seric 
69353037Seric bool
69453037Seric refuseconnections()
69553037Seric {
69653037Seric 	/* this is probably too simplistic */
69753037Seric 	return (CurrentLA > RefuseLA);
69853037Seric }
69953037Seric /*
70024943Seric **  SETPROCTITLE -- set process title for ps
70124943Seric **
70224943Seric **	Parameters:
70324943Seric **		fmt -- a printf style format string.
70424943Seric **		a, b, c -- possible parameters to fmt.
70524943Seric **
70624943Seric **	Returns:
70724943Seric **		none.
70824943Seric **
70924943Seric **	Side Effects:
71024943Seric **		Clobbers argv of our main procedure so ps(1) will
71124943Seric **		display the title.
71224943Seric */
71324943Seric 
71424943Seric /*VARARGS1*/
71556852Seric setproctitle(fmt VA_ARG_FORMAL)
71624943Seric 	char *fmt;
71756852Seric 	VA_ARG_DECL
71824943Seric {
71924943Seric # ifdef SETPROCTITLE
72024943Seric 	register char *p;
72125049Seric 	register int i;
72256852Seric 	char buf[MAXLINE];
72356852Seric 	VA_LOCAL_DECL
72424943Seric 	extern char **Argv;
72524943Seric 	extern char *LastArgv;
72624943Seric 
72754996Seric 	p = buf;
72824943Seric 
72954996Seric 	/* print sendmail: heading for grep */
73054996Seric 	(void) strcpy(p, "sendmail: ");
73154996Seric 	p += strlen(p);
73224943Seric 
73354996Seric 	/* print the argument string */
73456852Seric 	VA_START(fmt);
73556852Seric 	(void) vsprintf(p, fmt, ap);
73656852Seric 	VA_END;
73754996Seric 
73825049Seric 	i = strlen(buf);
73954996Seric 	if (i > LastArgv - Argv[0] - 2)
74025049Seric 	{
74154996Seric 		i = LastArgv - Argv[0] - 2;
74225049Seric 		buf[i] = '\0';
74325049Seric 	}
74454996Seric 	(void) strcpy(Argv[0], buf);
74554997Seric 	p = &Argv[0][i];
74624943Seric 	while (p < LastArgv)
74724943Seric 		*p++ = ' ';
74856795Seric # endif /* SETPROCTITLE */
74924943Seric }
75025698Seric /*
75125698Seric **  REAPCHILD -- pick up the body of my child, lest it become a zombie
75225698Seric **
75325698Seric **	Parameters:
75425698Seric **		none.
75525698Seric **
75625698Seric **	Returns:
75725698Seric **		none.
75825698Seric **
75925698Seric **	Side Effects:
76025698Seric **		Picks up extant zombies.
76125698Seric */
76225698Seric 
76325698Seric # include <sys/wait.h>
76425698Seric 
76546928Sbostic void
76625698Seric reapchild()
76725698Seric {
76825698Seric # ifdef WNOHANG
76925698Seric 	union wait status;
77025698Seric 
77146928Sbostic 	while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0)
77225698Seric 		continue;
77356795Seric # else /* WNOHANG */
77425698Seric 	auto int status;
77525698Seric 
77646928Sbostic 	while (wait((int *)&status) > 0)
77725698Seric 		continue;
77856795Seric # endif /* WNOHANG */
77925698Seric }
78055418Seric /*
78155418Seric **  UNSETENV -- remove a variable from the environment
78255418Seric **
78355418Seric **	Not needed on newer systems.
78455418Seric **
78555418Seric **	Parameters:
78655418Seric **		name -- the string name of the environment variable to be
78755418Seric **			deleted from the current environment.
78855418Seric **
78955418Seric **	Returns:
79055418Seric **		none.
79155418Seric **
79255418Seric **	Globals:
79355418Seric **		environ -- a pointer to the current environment.
79455418Seric **
79555418Seric **	Side Effects:
79655418Seric **		Modifies environ.
79755418Seric */
79855418Seric 
79955418Seric #ifdef UNSETENV
80055418Seric 
80155418Seric void
80255418Seric unsetenv(name)
80355418Seric 	char *name;
80455418Seric {
80555418Seric 	extern char **environ;
80655418Seric 	register char **pp;
80755418Seric 	int len = strlen(name);
80855418Seric 
80955418Seric 	for (pp = environ; *pp != NULL; pp++)
81055418Seric 	{
81155418Seric 		if (strncmp(name, *pp, len) == 0 &&
81255418Seric 		    ((*pp)[len] == '=' || (*pp)[len] == '\0'))
81355418Seric 			break;
81455418Seric 	}
81555418Seric 
81655418Seric 	for (; *pp != NULL; pp++)
81755418Seric 		*pp = pp[1];
81855418Seric }
81955418Seric 
82055418Seric #endif /* UNSETENV */
82156215Seric /*
82256215Seric **  GETDTABLESIZE -- return number of file descriptors
82356215Seric **
82456215Seric **	Only on non-BSD systems
82556215Seric **
82656215Seric **	Parameters:
82756215Seric **		none
82856215Seric **
82956215Seric **	Returns:
83056215Seric **		size of file descriptor table
83156215Seric **
83256215Seric **	Side Effects:
83356215Seric **		none
83456215Seric */
83556215Seric 
83656215Seric #ifdef SYSTEM5
83756215Seric 
83856215Seric int
83956215Seric getdtablesize()
84056215Seric {
84156215Seric 	return NOFILE;
84256215Seric }
84356215Seric 
84456215Seric #endif
845