xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 3144)
1294Seric # include <stdio.h>
2294Seric # include <pwd.h>
32967Seric # include "postbox.h"
4404Seric 
5294Seric /*
62967Seric **  CONF.C -- Postbox Configuration Tables.
7294Seric **
8294Seric **	Defines the configuration of this installation.
9294Seric **
101388Seric **	Compilation Flags:
111388Seric **		HASARPA -- set if this machine has a connection to
121388Seric **			the Arpanet.
131388Seric **		HASUUCP -- set if this machine has a connection to
141388Seric **			the UUCP network.
151388Seric **		NETV6MAIL -- set if you want to use "v6mail" that
161388Seric **			comes with the Berkeley network.  Normally
171388Seric **			/bin/mail will work fine, but around Berkeley
181388Seric **			we use v6mail because it is a "fixed target".
192355Seric **			Also, only v6mail has the "/dev/mail" stuff
202355Seric **			in it (for biff(1)).
211388Seric **		V6 -- running on a version 6 system.  This determines
221388Seric **			whether to define certain routines between
231388Seric **			the two systems.  If you are running a funny
241388Seric **			system, e.g., V6 with long tty names, this
251388Seric **			should be checked carefully.
261573Seric **		DUMBMAIL -- set if your /bin/mail doesn't have the
271573Seric **			-d flag.
28294Seric **
291388Seric **	Configuration Variables:
301388Seric **		Mailer -- a table of mailers known to the system.
311388Seric **			The fields are:
321388Seric **			- the pathname of the mailer.
331388Seric **			- a list of flags describing the properties
341388Seric **			  of this mailer:
351388Seric **			   M_FOPT -- if set, the mailer has a picky "-f"
361388Seric **				option.  In this mode, the mailer will
371388Seric **				only accept the "-f" option if the
381388Seric **				sender is actually "root", "network",
391388Seric **				and possibly (but not necessarily) if
401388Seric **				the -f argument matches the real sender.
411388Seric **				The effect is that if the "-f" option
422967Seric **				is given to postbox then it will be
431388Seric **				passed through (as arguments 1 & 2) to
441388Seric **				the mailer.
451388Seric **			   M_ROPT -- identical to M_FOPT, except uses
461388Seric **				-r instead.
471388Seric **			   M_QUIET -- if set, don't print a message if
481388Seric **				the mailer returns bad status.
491388Seric **			   M_RESTR -- if set, this mailer is restricted
501388Seric **				to use by "daemon"; otherwise, we do a
511388Seric **				setuid(getuid()) before calling the
521388Seric **				mailer.
531388Seric **			   M_HDR -- if set, the mailer wants us to
541388Seric **				insert a UNIX "From" line before
551388Seric **				outputing.
561827Seric **			   M_FHDR -- if set, the header that we
571827Seric **				generate will be used literally, so
581827Seric **				we must force it to be correct.  The
591827Seric **				effect is that we generate a header
601827Seric **				even if one exists.
611388Seric **			   M_NOHOST -- if set, this mailer doesn't care
621388Seric **				about the host part (e.g., the local
631388Seric **				mailer).
641388Seric **			   M_STRIPQ -- if set, strip quote (`"')
651388Seric **				characters out of parameters as you
661388Seric **				transliterate them into the argument
671388Seric **				vector.  For example, the local mailer
681388Seric **				is called directly, so these should be
691388Seric **				stripped, but the program-mailer (i.e.,
701388Seric **				csh) should leave them in.
712897Seric **			   M_NEEDDATE -- this mailer requires a Date:
722897Seric **				field in the message.
732897Seric **			   M_NEEDFROM -- this mailer requires a From:
742897Seric **				field in the message.
752897Seric **			   M_MSGID -- this mailer requires a Message-Id
762897Seric **				field in the message.
772897Seric **			   M_COMMAS -- this mailer wants comma-
782897Seric **				seperated To: and Cc: fields.
792897Seric **			   M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID|
802897Seric **				M_COMMAS.
811388Seric **			- an exit status to use as the code for the
821388Seric **			  error message print if the mailer returns
831388Seric **			  something we don't understand.
841388Seric **			- A list of names that are to be considered
851388Seric **			  "local" (and hence are stripped off) for
861388Seric **			  this mailer.
871388Seric **			- An argument vector to be passed to the
881388Seric **			  mailer with the following substitutions:
891388Seric **			   $f - the from person name.
901388Seric **			   $u - the target user name.
911388Seric **			   $h - the target user host.
921388Seric **			   $c - the hop count.
931388Seric **			>>>>>>>>>> Entry zero must be for the local
941388Seric **			>> NOTE >> mailer and entry one must be for
951388Seric **			>>>>>>>>>> the shell.
962897Seric **		HdrInfo -- a table describing well-known header fields.
972897Seric **			Each entry has the field name and some flags,
982897Seric **			which can be:
993057Seric **			- H_EOH -- this field is equivalent to a blank
1003057Seric **			  line; i.e., it signifies end of header.
1013057Seric **			- H_DELETE -- delete this field.
1023057Seric **			There is also a field pointing to a pointer
1033057Seric **			that should be set to point to this header.
104294Seric */
105294Seric 
106294Seric 
107294Seric 
108294Seric 
109*3144Seric static char SccsId[] = "@(#)conf.c	3.7	03/09/81";
110294Seric 
1111388Seric 
1121388Seric # include <whoami.h>		/* definitions of machine id's at berkeley */
1131388Seric 
1141573Seric # ifdef BERKELEY
1152099Seric 
1162355Seric # define NETV6MAIL		/* use /usr/net/bin/v6mail for local delivery */
1172099Seric 
1182099Seric /* Specific Configurations for Berkeley Machines */
1192099Seric 
1203061Seric /* Berkeley people: mail changes to ingvax:eric or they will be lost! */
1212099Seric 
122294Seric # ifdef ING70
1233061Seric # include "c.ing70.h"
124294Seric # endif ING70
125294Seric 
126294Seric # ifdef INGVAX
1273061Seric # include "c.ingvax.h"
128294Seric # endif INGVAX
129294Seric 
130294Seric # ifdef CSVAX
1313061Seric # include "c.csvax.h"
132294Seric # endif CSVAX
133294Seric 
1342355Seric # ifdef ARPAVAX
1353061Seric # include "c.arpavax.h"
1362355Seric # endif ARPAVAX
1372355Seric 
138294Seric # ifdef CORY
1393061Seric # include "c.cory.h"
140294Seric # endif CORY
141294Seric 
1422420Seric # ifdef ONYX
1433061Seric # include "c.onyx.h"
1442420Seric # endif ONYX
1452420Seric 
146294Seric # ifdef IMAGE
1473061Seric # include "c.image.h"
148294Seric # endif IMAGE
149294Seric 
150294Seric # ifdef ESVAX
1513061Seric # include "c.esvax.h"
152294Seric # endif ESVAX
153294Seric 
154294Seric # ifdef EECS40
1553061Seric # include "c.eecs40.h"
156294Seric # endif EECS40
157294Seric 
1583061Seric # else BERKELEY
159590Seric 
1603061Seric # define HASUUCP		/* default to having UUCP net */
1613061Seric 
1623061Seric # endif BERKELEY
1633061Seric 
1643061Seric 
1653061Seric 
1663046Seric /* local mail -- must be #0 */
1673046Seric static char	*LocalArgv[] =
168294Seric {
1693046Seric 	"...local%mail",
1703046Seric 	"-d",
1713046Seric 	"$u",
1723046Seric 	NULL
1733046Seric };
1743046Seric 
1753046Seric static struct mailer	LocalMailer =
1763046Seric {
177294Seric # ifdef NETV6MAIL
1783046Seric 	"/usr/net/bin/v6mail",
179294Seric # else
1803046Seric 	"/bin/mail",
181294Seric # endif
182*3144Seric 	"local",	M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT,	EX_NOUSER,
183*3144Seric 	"$f",		LocalArgv,
1843046Seric };
1853046Seric 
1863046Seric /* pipes through programs -- must be #1 */
1873046Seric static char	*ProgArgv[] =
1883046Seric {
1893046Seric 	"...prog%mail",
1903046Seric 	"-fc",
1913046Seric 	"$u",
1923046Seric 	NULL
1933046Seric };
1943046Seric 
1953046Seric static struct mailer	ProgMailer =
1963046Seric {
1973046Seric 	"/bin/csh",
198*3144Seric 	"prog",		M_HDR|M_FHDR|M_NOHOST,			EX_UNAVAILABLE,
199*3144Seric 	"$f",		ProgArgv,
2003046Seric };
2013046Seric 
2023046Seric /* local berkeley mail */
2033046Seric static char	*BerkArgv[] =
2043046Seric {
2053046Seric 	"...berk%mail",
2063046Seric 	"-m",
2073046Seric 	"$h",
2083046Seric 	"-t",
2093046Seric 	"$u",
2103046Seric 	"-h",
2113046Seric 	"$c",
2123046Seric 	NULL
2133046Seric };
2143046Seric 
2153046Seric static struct mailer	BerkMailer =
2163046Seric {
2173046Seric 	"/usr/net/bin/sendberkmail",
218*3144Seric 	"berk",		M_FOPT|M_HDR|M_STRIPQ,			EX_UNAVAILABLE,
219*3144Seric 	"$B:$f",	BerkArgv,
2203046Seric };
2213046Seric 
2223046Seric /* arpanet mail */
2233046Seric static char	*ArpaArgv[] =
2243046Seric {
2253046Seric 	"...arpa%mail",
2263046Seric 	"$f",
2273046Seric 	"$h",
2283046Seric 	"$u",
2293046Seric 	NULL
2303046Seric };
2313046Seric 
2323046Seric static struct mailer	ArpaMailer =
2333046Seric {
2343046Seric 	"/usr/lib/mailers/arpa",
235*3144Seric 	"arpa",		M_STRIPQ|M_ARPAFMT,			0,
236*3144Seric 	"$f@$A",	ArpaArgv,
2373046Seric };
2383046Seric 
2393046Seric /* uucp mail (cheat & use Bell's v7 mail) */
2403046Seric static char	*UucpArgv[] =
2413046Seric {
2423046Seric 	"...uucp%mail",
243294Seric # ifdef DUMBMAIL
2443046Seric 	"-d",
245294Seric # endif DUMBMAIL
2463046Seric 	"$h!$u",
2473046Seric 	NULL
248294Seric };
249294Seric 
2503046Seric static struct mailer	UucpMailer =
2513046Seric {
2523046Seric 	"/bin/mail",
253*3144Seric 	"uucp",		M_ROPT|M_STRIPQ,			EX_NOUSER,
254*3144Seric 	"$U!$f",	UucpArgv,
2553046Seric };
2563046Seric 
2573046Seric struct mailer	*Mailer[] =
2583046Seric {
2593046Seric 	&LocalMailer,		/* 0 -- must be 0 */
2603046Seric 	&ProgMailer,		/* 1 -- must be 1 */
2613046Seric 	&BerkMailer,		/* 2 */
2623046Seric 	&ArpaMailer,		/* 3 */
2633046Seric 	&UucpMailer,		/* 4 */
264*3144Seric 	NULL
2653046Seric };
2663046Seric 
267*3144Seric # define NMAILERS	((sizeof Mailer / sizeof Mailer[0]) - 1)
2683046Seric 
269294Seric # define M_LOCAL	0
2703046Seric # define M_PROG		1
271294Seric # define M_BERK		2
272294Seric # define M_ARPA		3
273294Seric # define M_UUCP		4
274294Seric 
2753046Seric /* list of messages for each mailer (sorted by host) */
2763046Seric ADDRESS		MailList[NMAILERS];
277294Seric 
278294Seric 
2793046Seric 
2802897Seric 
2812897Seric 
2822897Seric /*
2832897Seric **  Header info table
2843057Seric **	Final (null) entry contains the flags used for any other field.
2852897Seric */
2862897Seric 
2872897Seric struct hdrinfo	HdrInfo[] =
2882897Seric {
2893057Seric 	"date",		0,			NULL,
2903057Seric 	"from",		0,			NULL,
2913057Seric 	"to",		0,			NULL,
2923057Seric 	"cc",		0,			NULL,
2933057Seric 	"subject",	0,			NULL,
2943057Seric 	"message-id",	0,			&MsgId,
2953057Seric 	"message",	H_EOH,			NULL,
2963057Seric 	NULL,		0,			NULL,
2972897Seric };
298294Seric 
299294Seric # ifdef V6
300294Seric /*
301294Seric **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
302294Seric **
303294Seric **	Returns the pathname of the user's tty.  Returns NULL if
304294Seric **	the user is not logged in or if s/he has write permission
305294Seric **	denied.
306294Seric **
307294Seric **	Parameters:
308294Seric **		none
309294Seric **
310294Seric **	Returns:
311294Seric **		pathname of the user's tty.
312294Seric **		NULL if not logged in or write permission denied.
313294Seric **
314294Seric **	Side Effects:
315294Seric **		none.
316294Seric **
317294Seric **	WARNING:
318294Seric **		Return value is in a local buffer.
319294Seric **
320294Seric **	Called By:
321294Seric **		savemail
322294Seric */
323294Seric 
324294Seric # include <sys/types.h>
325294Seric # include <sys/stat.h>
326294Seric 
327294Seric char *
328294Seric ttypath()
329294Seric {
330294Seric 	struct stat stbuf;
331294Seric 	register int i;
332294Seric 	static char pathn[] = "/dev/ttyx";
333294Seric 	extern int errno;
334294Seric 
335294Seric 	/* compute the pathname of the controlling tty */
336294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
337294Seric 	{
338294Seric 		errno = 0;
339294Seric 		return (NULL);
340294Seric 	}
341294Seric 	pathn[8] = i;
342294Seric 
343294Seric 	/* see if we have write permission */
3442967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
345294Seric 	{
346294Seric 		errno = 0;
347294Seric 		return (NULL);
348294Seric 	}
349294Seric 
350294Seric 	/* see if the user is logged in */
351294Seric 	if (getlogin() == NULL)
352294Seric 		return (NULL);
353294Seric 
354294Seric 	/* looks good */
355294Seric 	return (pathn);
356294Seric }
357294Seric /*
358294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
359294Seric **
360294Seric **	This is included here because it is standard in v7, but we
361294Seric **	need it in v6.
362294Seric **
363294Seric **	Algorithm:
364294Seric **		Open /dev/null to create a descriptor.
365294Seric **		Close that descriptor.
366294Seric **		Copy the existing fd into the descriptor.
367294Seric **
368294Seric **	Parameters:
369294Seric **		fd -- the open file descriptor.
370294Seric **		type -- "r", "w", or whatever.
371294Seric **
372294Seric **	Returns:
373294Seric **		The file descriptor it creates.
374294Seric **
375294Seric **	Side Effects:
376294Seric **		none
377294Seric **
378294Seric **	Called By:
379294Seric **		deliver
380294Seric **
381294Seric **	Notes:
382294Seric **		The mode of fd must match "type".
383294Seric */
384294Seric 
385294Seric FILE *
386294Seric fdopen(fd, type)
387294Seric 	int fd;
388294Seric 	char *type;
389294Seric {
390294Seric 	register FILE *f;
391294Seric 
392294Seric 	f = fopen("/dev/null", type);
393294Seric 	close(fileno(f));
394294Seric 	fileno(f) = fd;
395294Seric 	return (f);
396294Seric }
397294Seric /*
398294Seric **  INDEX -- Return pointer to character in string
399294Seric **
400294Seric **	For V7 compatibility.
401294Seric **
402294Seric **	Parameters:
403294Seric **		s -- a string to scan.
404294Seric **		c -- a character to look for.
405294Seric **
406294Seric **	Returns:
407294Seric **		If c is in s, returns the address of the first
408294Seric **			instance of c in s.
409294Seric **		NULL if c is not in s.
410294Seric **
411294Seric **	Side Effects:
412294Seric **		none.
413294Seric */
414294Seric 
415294Seric index(s, c)
416294Seric 	register char *s;
417294Seric 	register char c;
418294Seric {
419294Seric 	while (*s != '\0')
420294Seric 	{
421294Seric 		if (*s++ == c)
422294Seric 			return (--s);
423294Seric 	}
424294Seric 	return (NULL);
425294Seric }
426294Seric # endif V6
427294Seric 
428294Seric # ifndef V6
429294Seric /*
430294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
431294Seric **
432294Seric **	Returns the pathname of the user's tty.  Returns NULL if
433294Seric **	the user is not logged in or if s/he has write permission
434294Seric **	denied.
435294Seric **
436294Seric **	Parameters:
437294Seric **		none
438294Seric **
439294Seric **	Returns:
440294Seric **		pathname of the user's tty.
441294Seric **		NULL if not logged in or write permission denied.
442294Seric **
443294Seric **	Side Effects:
444294Seric **		none.
445294Seric **
446294Seric **	WARNING:
447294Seric **		Return value is in a local buffer.
448294Seric **
449294Seric **	Called By:
450294Seric **		savemail
451294Seric */
452294Seric 
453294Seric # include <sys/types.h>
454294Seric # include <sys/stat.h>
455294Seric 
456294Seric char *
457294Seric ttypath()
458294Seric {
459294Seric 	struct stat stbuf;
460294Seric 	register char *pathn;
461294Seric 	extern int errno;
462294Seric 	extern char *ttyname();
463294Seric 
464294Seric 	/* compute the pathname of the controlling tty */
465294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
466294Seric 	{
467294Seric 		errno = 0;
468294Seric 		return (NULL);
469294Seric 	}
470294Seric 
471294Seric 	/* see if we have write permission */
4722967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
473294Seric 	{
474294Seric 		errno = 0;
475294Seric 		return (NULL);
476294Seric 	}
477294Seric 
478294Seric 	/* see if the user is logged in */
479294Seric 	if (getlogin() == NULL)
480294Seric 		return (NULL);
481294Seric 
482294Seric 	/* looks good */
483294Seric 	return (pathn);
484294Seric }
485294Seric # endif V6
4862967Seric /*
4872967Seric **  CHECKCOMPAT -- check for From and To person compatible.
4882967Seric **
4892967Seric **	This routine can be supplied on a per-installation basis
4902967Seric **	to determine whether a person is allowed to send a message.
4912967Seric **	This allows restriction of certain types of internet
4922967Seric **	forwarding or registration of users.
4932967Seric **
4942967Seric **	If the hosts are found to be incompatible, an error
4952967Seric **	message should be given using "usrerr" and FALSE should
4962967Seric **	be returned.
4972967Seric **
4982967Seric **	Parameters:
4992967Seric **		to -- the person being sent to.
5002967Seric **
5012967Seric **	Returns:
5022967Seric **		TRUE -- ok to send.
5032967Seric **		FALSE -- not ok.
5042967Seric **
5052967Seric **	Side Effects:
5062967Seric **		none (unless you include the usrerr stuff)
5072967Seric */
5082967Seric 
5092967Seric bool
5102967Seric checkcompat(to)
5112967Seric 	register ADDRESS *to;
5122967Seric {
5132967Seric 	return (TRUE);
5142967Seric }
515