xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 17469)
1294Seric # include <pwd.h>
214881Seric # include <sys/ioctl.h>
33309Seric # include "sendmail.h"
4404Seric 
5294Seric /*
63309Seric **  CONF.C -- Sendmail Configuration Tables.
7294Seric **
8294Seric **	Defines the configuration of this installation.
9294Seric **
101388Seric **	Compilation Flags:
111388Seric **		V6 -- running on a version 6 system.  This determines
121388Seric **			whether to define certain routines between
131388Seric **			the two systems.  If you are running a funny
141388Seric **			system, e.g., V6 with long tty names, this
151388Seric **			should be checked carefully.
1614872Seric **		VMUNIX -- running on a Berkeley UNIX system.
17294Seric **
181388Seric **	Configuration Variables:
192897Seric **		HdrInfo -- a table describing well-known header fields.
202897Seric **			Each entry has the field name and some flags,
214147Seric **			which are described in sendmail.h.
224093Seric **
234093Seric **	Notes:
244093Seric **		I have tried to put almost all the reasonable
254093Seric **		configuration information into the configuration
264093Seric **		file read at runtime.  My intent is that anything
274093Seric **		here is a function of the version of UNIX you
284093Seric **		are running, or is really static -- for example
294093Seric **		the headers are a superset of widely used
304093Seric **		protocols.  If you find yourself playing with
314093Seric **		this file too much, you may be making a mistake!
32294Seric */
33294Seric 
34294Seric 
35294Seric 
36294Seric 
37*17469Seric SCCSID(@(#)conf.c	4.6		12/05/84);
384437Seric 
394437Seric 
404437Seric 
414437Seric /*
422897Seric **  Header info table
433057Seric **	Final (null) entry contains the flags used for any other field.
444147Seric **
454147Seric **	Not all of these are actually handled specially by sendmail
464147Seric **	at this time.  They are included as placeholders, to let
474147Seric **	you know that "someday" I intend to have sendmail do
484147Seric **	something with them.
492897Seric */
502897Seric 
512897Seric struct hdrinfo	HdrInfo[] =
522897Seric {
538060Seric 		/* originator fields, most to least significant  */
5411417Seric 	"resent-sender",	H_FROM|H_RESENT,
5511417Seric 	"resent-from",		H_FROM|H_RESENT,
569055Seric 	"sender",		H_FROM,
579055Seric 	"from",			H_FROM,
589055Seric 	"full-name",		H_ACHECK,
599055Seric 	"return-receipt-to",	H_FROM,
609055Seric 	"errors-to",		H_FROM,
618060Seric 		/* destination fields */
629055Seric 	"to",			H_RCPT,
6311417Seric 	"resent-to",		H_RCPT|H_RESENT,
649055Seric 	"cc",			H_RCPT,
6511417Seric 	"resent-cc",		H_RCPT|H_RESENT,
669055Seric 	"bcc",			H_RCPT|H_ACHECK,
6711417Seric 	"resent-bcc",		H_RCPT|H_ACHECK|H_RESENT,
688060Seric 		/* message identification and control */
6911417Seric 	"message-id",		0,
7011417Seric 	"resent-message-id",	H_RESENT,
719055Seric 	"message",		H_EOH,
729055Seric 	"text",			H_EOH,
7311417Seric 		/* date fields */
7411417Seric 	"date",			0,
7511417Seric 	"resent-date",		H_RESENT,
768060Seric 		/* trace fields */
779055Seric 	"received",		H_TRACE|H_FORCE,
789055Seric 	"via",			H_TRACE|H_FORCE,
799055Seric 	"mail-from",		H_TRACE|H_FORCE,
808060Seric 
819055Seric 	NULL,			0,
822897Seric };
834166Seric 
844166Seric 
854166Seric /*
864166Seric **  ARPANET error message numbers.
874166Seric */
884166Seric 
897956Seric char	Arpa_Info[] =		"050";	/* arbitrary info */
907956Seric char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
917956Seric char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
927956Seric char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
934282Seric 
944282Seric 
954282Seric 
964282Seric /*
974282Seric **  Location of system files/databases/etc.
984282Seric */
994282Seric 
1004282Seric char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
1019064Seric char	*FreezeFile =	"/usr/lib/sendmail.fc";	/* frozen version of above */
1029039Seric 
1039064Seric 
1049064Seric 
1059039Seric /*
1069039Seric **  Some other configuration....
1079039Seric */
1089039Seric 
10916881Seric char	SpaceSub;		/* character to replace <lwsp> in addrs */
11016881Seric int	QueueLA;		/* load avg > QueueLA -> just queue */
11116881Seric int	RefuseLA;		/* load avg > RefuseLA -> refuse connections */
112294Seric 
113294Seric # ifdef V6
114294Seric /*
1154190Seric **  TTYNAME -- return name of terminal.
116294Seric **
117294Seric **	Parameters:
1184190Seric **		fd -- file descriptor to check.
119294Seric **
120294Seric **	Returns:
1214190Seric **		pointer to full path of tty.
1224190Seric **		NULL if no tty.
123294Seric **
124294Seric **	Side Effects:
125294Seric **		none.
126294Seric */
127294Seric 
128294Seric char *
1294190Seric ttyname(fd)
1304190Seric 	int fd;
131294Seric {
1324190Seric 	register char tn;
133294Seric 	static char pathn[] = "/dev/ttyx";
134294Seric 
135294Seric 	/* compute the pathname of the controlling tty */
1364190Seric 	if ((tn = ttyn(fd)) == NULL)
137294Seric 	{
138294Seric 		errno = 0;
139294Seric 		return (NULL);
140294Seric 	}
1414190Seric 	pathn[8] = tn;
142294Seric 	return (pathn);
143294Seric }
144294Seric /*
145294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
146294Seric **
147294Seric **	This is included here because it is standard in v7, but we
148294Seric **	need it in v6.
149294Seric **
150294Seric **	Algorithm:
151294Seric **		Open /dev/null to create a descriptor.
152294Seric **		Close that descriptor.
153294Seric **		Copy the existing fd into the descriptor.
154294Seric **
155294Seric **	Parameters:
156294Seric **		fd -- the open file descriptor.
157294Seric **		type -- "r", "w", or whatever.
158294Seric **
159294Seric **	Returns:
160294Seric **		The file descriptor it creates.
161294Seric **
162294Seric **	Side Effects:
163294Seric **		none
164294Seric **
165294Seric **	Called By:
166294Seric **		deliver
167294Seric **
168294Seric **	Notes:
169294Seric **		The mode of fd must match "type".
170294Seric */
171294Seric 
172294Seric FILE *
173294Seric fdopen(fd, type)
174294Seric 	int fd;
175294Seric 	char *type;
176294Seric {
177294Seric 	register FILE *f;
178294Seric 
179294Seric 	f = fopen("/dev/null", type);
1804081Seric 	(void) close(fileno(f));
181294Seric 	fileno(f) = fd;
182294Seric 	return (f);
183294Seric }
184294Seric /*
185294Seric **  INDEX -- Return pointer to character in string
186294Seric **
187294Seric **	For V7 compatibility.
188294Seric **
189294Seric **	Parameters:
190294Seric **		s -- a string to scan.
191294Seric **		c -- a character to look for.
192294Seric **
193294Seric **	Returns:
194294Seric **		If c is in s, returns the address of the first
195294Seric **			instance of c in s.
196294Seric **		NULL if c is not in s.
197294Seric **
198294Seric **	Side Effects:
199294Seric **		none.
200294Seric */
201294Seric 
2024437Seric char *
203294Seric index(s, c)
204294Seric 	register char *s;
205294Seric 	register char c;
206294Seric {
207294Seric 	while (*s != '\0')
208294Seric 	{
209294Seric 		if (*s++ == c)
210294Seric 			return (--s);
211294Seric 	}
212294Seric 	return (NULL);
213294Seric }
2144326Seric /*
2154326Seric **  UMASK -- fake the umask system call.
2164326Seric **
2174326Seric **	Since V6 always acts like the umask is zero, we will just
2184326Seric **	assume the same thing.
2194326Seric */
2204326Seric 
2214326Seric /*ARGSUSED*/
2224326Seric umask(nmask)
2234326Seric {
2244326Seric 	return (0);
2254326Seric }
2264326Seric 
2274326Seric 
2284326Seric /*
2294326Seric **  GETRUID -- get real user id.
2304326Seric */
2314326Seric 
2324326Seric getruid()
2334326Seric {
2344326Seric 	return (getuid() & 0377);
2354326Seric }
2364326Seric 
2374326Seric 
2384326Seric /*
2394326Seric **  GETRGID -- get real group id.
2404326Seric */
2414326Seric 
2424326Seric getrgid()
2434326Seric {
2444326Seric 	return (getgid() & 0377);
2454326Seric }
2464326Seric 
2474326Seric 
2484326Seric /*
2494326Seric **  GETEUID -- get effective user id.
2504326Seric */
2514326Seric 
2524326Seric geteuid()
2534326Seric {
2544326Seric 	return ((getuid() >> 8) & 0377);
2554326Seric }
2564326Seric 
2574326Seric 
2584326Seric /*
2594326Seric **  GETEGID -- get effective group id.
2604326Seric */
2614326Seric 
2624326Seric getegid()
2634326Seric {
2644326Seric 	return ((getgid() >> 8) & 0377);
2654326Seric }
2664326Seric 
267294Seric # endif V6
2684326Seric 
2694326Seric # ifndef V6
2704326Seric 
2714326Seric /*
2724326Seric **  GETRUID -- get real user id (V7)
2734326Seric */
2744326Seric 
2754326Seric getruid()
2764326Seric {
2779274Seric 	if (OpMode == MD_DAEMON)
2784536Seric 		return (RealUid);
2794536Seric 	else
2804536Seric 		return (getuid());
2814326Seric }
2824326Seric 
2834326Seric 
2844326Seric /*
2854326Seric **  GETRGID -- get real group id (V7).
2864326Seric */
2874326Seric 
2884326Seric getrgid()
2894326Seric {
2909274Seric 	if (OpMode == MD_DAEMON)
2914536Seric 		return (RealGid);
2924536Seric 	else
2934536Seric 		return (getgid());
2944326Seric }
2954326Seric 
2964326Seric # endif V6
2974190Seric /*
2989369Seric **  USERNAME -- return the user id of the logged in user.
2999369Seric **
3009369Seric **	Parameters:
3019369Seric **		none.
3029369Seric **
3039369Seric **	Returns:
3049369Seric **		The login name of the logged in user.
3059369Seric **
3069369Seric **	Side Effects:
3079369Seric **		none.
3089369Seric **
3099369Seric **	Notes:
3109369Seric **		The return value is statically allocated.
3119369Seric */
3129369Seric 
3139369Seric char *
3149369Seric username()
3159369Seric {
316*17469Seric 	static char *myname = NULL;
3179369Seric 	extern char *getlogin();
3189369Seric 
319*17469Seric 	/* cache the result */
320*17469Seric 	if (myname == NULL)
321*17469Seric 	{
322*17469Seric 		myname = getlogin();
323*17469Seric 		if (myname == NULL || myname[0] == '\0')
324*17469Seric 		{
325*17469Seric 			register struct passwd *pw;
326*17469Seric 			extern struct passwd *getpwuid();
327*17469Seric 
328*17469Seric 			pw = getpwuid(getruid());
329*17469Seric 			if (pw != NULL)
330*17469Seric 				myname = pw->pw_name;
331*17469Seric 		}
332*17469Seric 		if (myname == NULL || myname[0] == '\0')
333*17469Seric 		{
334*17469Seric 			syserr("Who are you?");
335*17469Seric 			myname = "postmaster";
336*17469Seric 		}
337*17469Seric 	}
338*17469Seric 
339*17469Seric 	return (myname);
3409369Seric }
3419369Seric /*
3424190Seric **  TTYPATH -- Get the path of the user's tty
343294Seric **
344294Seric **	Returns the pathname of the user's tty.  Returns NULL if
345294Seric **	the user is not logged in or if s/he has write permission
346294Seric **	denied.
347294Seric **
348294Seric **	Parameters:
349294Seric **		none
350294Seric **
351294Seric **	Returns:
352294Seric **		pathname of the user's tty.
353294Seric **		NULL if not logged in or write permission denied.
354294Seric **
355294Seric **	Side Effects:
356294Seric **		none.
357294Seric **
358294Seric **	WARNING:
359294Seric **		Return value is in a local buffer.
360294Seric **
361294Seric **	Called By:
362294Seric **		savemail
363294Seric */
364294Seric 
365294Seric # include <sys/stat.h>
366294Seric 
367294Seric char *
368294Seric ttypath()
369294Seric {
370294Seric 	struct stat stbuf;
371294Seric 	register char *pathn;
372294Seric 	extern char *ttyname();
3734081Seric 	extern char *getlogin();
374294Seric 
375294Seric 	/* compute the pathname of the controlling tty */
3769369Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
3779369Seric 	    (pathn = ttyname(0)) == NULL)
378294Seric 	{
379294Seric 		errno = 0;
380294Seric 		return (NULL);
381294Seric 	}
382294Seric 
383294Seric 	/* see if we have write permission */
3842967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
385294Seric 	{
386294Seric 		errno = 0;
387294Seric 		return (NULL);
388294Seric 	}
389294Seric 
390294Seric 	/* see if the user is logged in */
391294Seric 	if (getlogin() == NULL)
392294Seric 		return (NULL);
393294Seric 
394294Seric 	/* looks good */
395294Seric 	return (pathn);
396294Seric }
3972967Seric /*
3982967Seric **  CHECKCOMPAT -- check for From and To person compatible.
3992967Seric **
4002967Seric **	This routine can be supplied on a per-installation basis
4012967Seric **	to determine whether a person is allowed to send a message.
4022967Seric **	This allows restriction of certain types of internet
4032967Seric **	forwarding or registration of users.
4042967Seric **
4052967Seric **	If the hosts are found to be incompatible, an error
4062967Seric **	message should be given using "usrerr" and FALSE should
4072967Seric **	be returned.
4082967Seric **
4094288Seric **	'NoReturn' can be set to suppress the return-to-sender
4104288Seric **	function; this should be done on huge messages.
4114288Seric **
4122967Seric **	Parameters:
4132967Seric **		to -- the person being sent to.
4142967Seric **
4152967Seric **	Returns:
4162967Seric **		TRUE -- ok to send.
4172967Seric **		FALSE -- not ok.
4182967Seric **
4192967Seric **	Side Effects:
4202967Seric **		none (unless you include the usrerr stuff)
4212967Seric */
4222967Seric 
4232967Seric bool
4242967Seric checkcompat(to)
4252967Seric 	register ADDRESS *to;
4262967Seric {
42712133Seric # ifdef lint
42812133Seric 	if (to == NULL)
42912133Seric 		to++;
43012133Seric # endif lint
43110698Seric # ifdef EXAMPLE_CODE
43210698Seric 	/* this code is intended as an example only */
4334437Seric 	register STAB *s;
4344437Seric 
4354437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
4369369Seric 	if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer &&
4379369Seric 	    to->q_mailer == s->s_mailer)
4384437Seric 	{
4394437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
44010698Seric 		/* NoReturn = TRUE; to supress return copy */
4414437Seric 		return (FALSE);
4424437Seric 	}
44310698Seric # endif EXAMPLE_CODE
4442967Seric 	return (TRUE);
4452967Seric }
4469369Seric /*
4479369Seric **  HOLDSIGS -- arrange to hold all signals
4489369Seric **
4499369Seric **	Parameters:
4509369Seric **		none.
4519369Seric **
4529369Seric **	Returns:
4539369Seric **		none.
4549369Seric **
4559369Seric **	Side Effects:
4569369Seric **		Arranges that signals are held.
4579369Seric */
4589369Seric 
4599369Seric holdsigs()
4609369Seric {
4619369Seric }
4629369Seric /*
4639369Seric **  RLSESIGS -- arrange to release all signals
4649369Seric **
4659369Seric **	This undoes the effect of holdsigs.
4669369Seric **
4679369Seric **	Parameters:
4689369Seric **		none.
4699369Seric **
4709369Seric **	Returns:
4719369Seric **		none.
4729369Seric **
4739369Seric **	Side Effects:
4749369Seric **		Arranges that signals are released.
4759369Seric */
4769369Seric 
4779369Seric rlsesigs()
4789369Seric {
4799369Seric }
48014872Seric /*
48114872Seric **  GETLA -- get the current load average
48214872Seric **
48314881Seric **	This code stolen from la.c.
48414881Seric **
48514872Seric **	Parameters:
48614872Seric **		none.
48714872Seric **
48814872Seric **	Returns:
48914872Seric **		The current load average as an integer.
49014872Seric **
49114872Seric **	Side Effects:
49214872Seric **		none.
49314872Seric */
49414872Seric 
49514872Seric #ifdef VMUNIX
49614872Seric 
49714872Seric #include <nlist.h>
49814872Seric 
49914872Seric struct	nlist Nl[] =
50014872Seric {
50114872Seric 	{ "_avenrun" },
50214872Seric #define	X_AVENRUN	0
50314872Seric 	{ 0 },
50414872Seric };
50514872Seric 
50614872Seric getla()
50714872Seric {
50814872Seric 	static int kmem = -1;
50914872Seric 	double avenrun[3];
51014872Seric 
51114872Seric 	if (kmem < 0)
51214872Seric 	{
51314872Seric 		kmem = open("/dev/kmem", 0);
51414872Seric 		if (kmem < 0)
51514872Seric 			return (-1);
51614881Seric 		(void) ioctl(kmem, FIOCLEX, 0);
51714872Seric 		nlist("/vmunix", Nl);
51814872Seric 		if (Nl[0].n_type == 0)
51914872Seric 			return (-1);
52014872Seric 	}
52114872Seric 	(void) lseek(kmem, (long) Nl[X_AVENRUN].n_value, 0);
52214872Seric 	(void) read(kmem, avenrun, sizeof(avenrun));
52314872Seric 	return ((int) (avenrun[0] + 0.5));
52414872Seric }
52514872Seric 
52614872Seric #else VMUNIX
52714872Seric 
52814872Seric getla()
52914872Seric {
53014872Seric 	return (0);
53114872Seric }
53214872Seric 
53314872Seric #endif VMUNIX
534*17469Seric /*
535*17469Seric **  DBMCLOSE -- close the DBM file
536*17469Seric **
537*17469Seric **	This depends on the implementation of the DBM library.  It
538*17469Seric **	seems to work for all versions that I have come across.
539*17469Seric **
540*17469Seric **	Parameters:
541*17469Seric **		none.
542*17469Seric **
543*17469Seric **	Returns:
544*17469Seric **		none.
545*17469Seric **
546*17469Seric **	Side Effects:
547*17469Seric **		Closes the current DBM file; dbminit must be
548*17469Seric **		called again to continue using the DBM routines.
549*17469Seric */
550*17469Seric 
551*17469Seric dbmclose()
552*17469Seric {
553*17469Seric 	extern int pagf, dirf;	/* defined in the DBM package */
554*17469Seric 
555*17469Seric 	(void) close(pagf);
556*17469Seric 	(void) close(dirf);
557*17469Seric }
558