xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 3309)
1294Seric # include <stdio.h>
2294Seric # include <pwd.h>
3*3309Seric # include "sendmail.h"
4404Seric 
5294Seric /*
6*3309Seric **  CONF.C -- Sendmail 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
42*3309Seric **				is given to sendmail 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.
533185Seric **			   M_NHDR -- if set, the mailer doesn't want us
543185Seric **				to insert a UNIX "From" line before
551388Seric **				outputing.
561388Seric **			   M_NOHOST -- if set, this mailer doesn't care
571388Seric **				about the host part (e.g., the local
581388Seric **				mailer).
591388Seric **			   M_STRIPQ -- if set, strip quote (`"')
601388Seric **				characters out of parameters as you
611388Seric **				transliterate them into the argument
621388Seric **				vector.  For example, the local mailer
631388Seric **				is called directly, so these should be
641388Seric **				stripped, but the program-mailer (i.e.,
651388Seric **				csh) should leave them in.
662897Seric **			   M_NEEDDATE -- this mailer requires a Date:
672897Seric **				field in the message.
682897Seric **			   M_NEEDFROM -- this mailer requires a From:
692897Seric **				field in the message.
702897Seric **			   M_MSGID -- this mailer requires a Message-Id
712897Seric **				field in the message.
723185Seric **			   M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID.
731388Seric **			- an exit status to use as the code for the
741388Seric **			  error message print if the mailer returns
751388Seric **			  something we don't understand.
761388Seric **			- A list of names that are to be considered
771388Seric **			  "local" (and hence are stripped off) for
781388Seric **			  this mailer.
791388Seric **			- An argument vector to be passed to the
801388Seric **			  mailer with the following substitutions:
811388Seric **			   $f - the from person name.
821388Seric **			   $u - the target user name.
831388Seric **			   $h - the target user host.
841388Seric **			   $c - the hop count.
851388Seric **			>>>>>>>>>> Entry zero must be for the local
861388Seric **			>> NOTE >> mailer and entry one must be for
871388Seric **			>>>>>>>>>> the shell.
882897Seric **		HdrInfo -- a table describing well-known header fields.
892897Seric **			Each entry has the field name and some flags,
902897Seric **			which can be:
913057Seric **			- H_EOH -- this field is equivalent to a blank
923057Seric **			  line; i.e., it signifies end of header.
933057Seric **			- H_DELETE -- delete this field.
943057Seric **			There is also a field pointing to a pointer
953057Seric **			that should be set to point to this header.
96294Seric */
97294Seric 
98294Seric 
99294Seric 
100294Seric 
101*3309Seric static char SccsId[] = "@(#)conf.c	3.10	03/20/81";
102294Seric 
1031388Seric 
1041388Seric # include <whoami.h>		/* definitions of machine id's at berkeley */
1051388Seric 
1061573Seric # ifdef BERKELEY
1072099Seric 
1082355Seric # define NETV6MAIL		/* use /usr/net/bin/v6mail for local delivery */
1092099Seric 
1102099Seric /* Specific Configurations for Berkeley Machines */
1112099Seric 
1123061Seric /* Berkeley people: mail changes to ingvax:eric or they will be lost! */
1132099Seric 
114294Seric # ifdef ING70
1153061Seric # include "c.ing70.h"
116294Seric # endif ING70
117294Seric 
118294Seric # ifdef INGVAX
1193061Seric # include "c.ingvax.h"
120294Seric # endif INGVAX
121294Seric 
122294Seric # ifdef CSVAX
1233061Seric # include "c.csvax.h"
124294Seric # endif CSVAX
125294Seric 
1262355Seric # ifdef ARPAVAX
1273061Seric # include "c.arpavax.h"
1282355Seric # endif ARPAVAX
1292355Seric 
130294Seric # ifdef CORY
1313061Seric # include "c.cory.h"
132294Seric # endif CORY
133294Seric 
1342420Seric # ifdef ONYX
1353061Seric # include "c.onyx.h"
1362420Seric # endif ONYX
1372420Seric 
138294Seric # ifdef IMAGE
1393061Seric # include "c.image.h"
140294Seric # endif IMAGE
141294Seric 
142294Seric # ifdef ESVAX
1433061Seric # include "c.esvax.h"
144294Seric # endif ESVAX
145294Seric 
146294Seric # ifdef EECS40
1473061Seric # include "c.eecs40.h"
148294Seric # endif EECS40
149294Seric 
1503061Seric # else BERKELEY
151590Seric 
1523061Seric # define HASUUCP		/* default to having UUCP net */
1533061Seric 
1543061Seric # endif BERKELEY
1553061Seric 
1563061Seric 
1573061Seric 
1583046Seric /* local mail -- must be #0 */
1593046Seric static char	*LocalArgv[] =
160294Seric {
1613046Seric 	"...local%mail",
1623046Seric 	"-d",
1633046Seric 	"$u",
1643046Seric 	NULL
1653046Seric };
1663046Seric 
1673046Seric static struct mailer	LocalMailer =
1683046Seric {
169294Seric # ifdef NETV6MAIL
1703185Seric 	"local",	"/usr/net/bin/v6mail",
171294Seric # else
1723185Seric 	"local",	"/bin/mail",
173294Seric # endif
1743185Seric 	M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT|M_MUSER|M_NHDR,
1753185Seric 	EX_NOUSER,	"$f",		LocalArgv,	NULL,
1763046Seric };
1773046Seric 
1783185Seric /* pipes through programs -- must be #1 -- also used for files */
1793046Seric static char	*ProgArgv[] =
1803046Seric {
1813046Seric 	"...prog%mail",
1823046Seric 	"-fc",
1833046Seric 	"$u",
1843046Seric 	NULL
1853046Seric };
1863046Seric 
1873046Seric static struct mailer	ProgMailer =
1883046Seric {
1893185Seric 	"prog",		"/bin/csh",
1903185Seric 	M_NOHOST|M_ARPAFMT,
1913185Seric 	EX_UNAVAILABLE, "$f",		ProgArgv,	NULL,
1923046Seric };
1933046Seric 
1943046Seric /* local berkeley mail */
1953046Seric static char	*BerkArgv[] =
1963046Seric {
1973046Seric 	"...berk%mail",
1983046Seric 	"-m",
1993046Seric 	"$h",
2003232Seric 	"-h",
2013232Seric 	"$c",
2023046Seric 	"-t",
2033046Seric 	"$u",
2043046Seric 	NULL
2053046Seric };
2063046Seric 
2073046Seric static struct mailer	BerkMailer =
2083046Seric {
2093185Seric 	"berk",		"/usr/net/bin/sendberkmail",
2103232Seric 	M_FOPT|M_ARPAFMT|M_STRIPQ,
2113185Seric 	EX_UNAVAILABLE,	"$B:$f",	BerkArgv,	NULL,
2123046Seric };
2133046Seric 
2143046Seric /* arpanet mail */
2153046Seric static char	*ArpaArgv[] =
2163046Seric {
2173046Seric 	"...arpa%mail",
2183046Seric 	"$f",
2193046Seric 	"$h",
2203046Seric 	"$u",
2213046Seric 	NULL
2223046Seric };
2233046Seric 
2243046Seric static struct mailer	ArpaMailer =
2253046Seric {
2263185Seric 	"arpa",		"/usr/lib/mailers/arpa",
2273185Seric 	M_STRIPQ|M_ARPAFMT|M_USR_UPPER,
2283185Seric 	0,		"$f@$A",	ArpaArgv,	NULL,
2293046Seric };
2303046Seric 
2313046Seric /* uucp mail (cheat & use Bell's v7 mail) */
2323046Seric static char	*UucpArgv[] =
2333046Seric {
2343046Seric 	"...uucp%mail",
2353232Seric 	"-",
2363232Seric 	"$h!rmail",
2373232Seric 	"($u)",
2383046Seric 	NULL
239294Seric };
240294Seric 
2413046Seric static struct mailer	UucpMailer =
2423046Seric {
2433232Seric 	"uucp",		"/usr/bin/uux",
2443185Seric 	M_ROPT|M_STRIPQ|M_ARPAFMT|M_MUSER,
2453185Seric 	EX_NOUSER,	"$U!$f",	UucpArgv,	NULL,
2463046Seric };
2473046Seric 
2483046Seric struct mailer	*Mailer[] =
2493046Seric {
2503046Seric 	&LocalMailer,		/* 0 -- must be 0 */
2513046Seric 	&ProgMailer,		/* 1 -- must be 1 */
2523046Seric 	&BerkMailer,		/* 2 */
2533046Seric 	&ArpaMailer,		/* 3 */
2543046Seric 	&UucpMailer,		/* 4 */
2553144Seric 	NULL
2563046Seric };
2573046Seric 
258294Seric # define M_LOCAL	0
2593046Seric # define M_PROG		1
260294Seric # define M_BERK		2
261294Seric # define M_ARPA		3
262294Seric # define M_UUCP		4
263294Seric 
264294Seric 
265294Seric 
2663046Seric 
2672897Seric 
2682897Seric /*
2692897Seric **  Header info table
2703057Seric **	Final (null) entry contains the flags used for any other field.
2712897Seric */
2722897Seric 
2732897Seric struct hdrinfo	HdrInfo[] =
2742897Seric {
2753057Seric 	"date",		0,			NULL,
2763057Seric 	"from",		0,			NULL,
2773057Seric 	"to",		0,			NULL,
2783057Seric 	"cc",		0,			NULL,
2793057Seric 	"subject",	0,			NULL,
2803057Seric 	"message-id",	0,			&MsgId,
2813057Seric 	"message",	H_EOH,			NULL,
2823057Seric 	NULL,		0,			NULL,
2832897Seric };
284294Seric 
285294Seric # ifdef V6
286294Seric /*
287294Seric **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
288294Seric **
289294Seric **	Returns the pathname of the user's tty.  Returns NULL if
290294Seric **	the user is not logged in or if s/he has write permission
291294Seric **	denied.
292294Seric **
293294Seric **	Parameters:
294294Seric **		none
295294Seric **
296294Seric **	Returns:
297294Seric **		pathname of the user's tty.
298294Seric **		NULL if not logged in or write permission denied.
299294Seric **
300294Seric **	Side Effects:
301294Seric **		none.
302294Seric **
303294Seric **	WARNING:
304294Seric **		Return value is in a local buffer.
305294Seric **
306294Seric **	Called By:
307294Seric **		savemail
308294Seric */
309294Seric 
310294Seric # include <sys/types.h>
311294Seric # include <sys/stat.h>
312294Seric 
313294Seric char *
314294Seric ttypath()
315294Seric {
316294Seric 	struct stat stbuf;
317294Seric 	register int i;
318294Seric 	static char pathn[] = "/dev/ttyx";
319294Seric 	extern int errno;
320294Seric 
321294Seric 	/* compute the pathname of the controlling tty */
322294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
323294Seric 	{
324294Seric 		errno = 0;
325294Seric 		return (NULL);
326294Seric 	}
327294Seric 	pathn[8] = i;
328294Seric 
329294Seric 	/* see if we have write permission */
3302967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
331294Seric 	{
332294Seric 		errno = 0;
333294Seric 		return (NULL);
334294Seric 	}
335294Seric 
336294Seric 	/* see if the user is logged in */
337294Seric 	if (getlogin() == NULL)
338294Seric 		return (NULL);
339294Seric 
340294Seric 	/* looks good */
341294Seric 	return (pathn);
342294Seric }
343294Seric /*
344294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
345294Seric **
346294Seric **	This is included here because it is standard in v7, but we
347294Seric **	need it in v6.
348294Seric **
349294Seric **	Algorithm:
350294Seric **		Open /dev/null to create a descriptor.
351294Seric **		Close that descriptor.
352294Seric **		Copy the existing fd into the descriptor.
353294Seric **
354294Seric **	Parameters:
355294Seric **		fd -- the open file descriptor.
356294Seric **		type -- "r", "w", or whatever.
357294Seric **
358294Seric **	Returns:
359294Seric **		The file descriptor it creates.
360294Seric **
361294Seric **	Side Effects:
362294Seric **		none
363294Seric **
364294Seric **	Called By:
365294Seric **		deliver
366294Seric **
367294Seric **	Notes:
368294Seric **		The mode of fd must match "type".
369294Seric */
370294Seric 
371294Seric FILE *
372294Seric fdopen(fd, type)
373294Seric 	int fd;
374294Seric 	char *type;
375294Seric {
376294Seric 	register FILE *f;
377294Seric 
378294Seric 	f = fopen("/dev/null", type);
379294Seric 	close(fileno(f));
380294Seric 	fileno(f) = fd;
381294Seric 	return (f);
382294Seric }
383294Seric /*
384294Seric **  INDEX -- Return pointer to character in string
385294Seric **
386294Seric **	For V7 compatibility.
387294Seric **
388294Seric **	Parameters:
389294Seric **		s -- a string to scan.
390294Seric **		c -- a character to look for.
391294Seric **
392294Seric **	Returns:
393294Seric **		If c is in s, returns the address of the first
394294Seric **			instance of c in s.
395294Seric **		NULL if c is not in s.
396294Seric **
397294Seric **	Side Effects:
398294Seric **		none.
399294Seric */
400294Seric 
401294Seric index(s, c)
402294Seric 	register char *s;
403294Seric 	register char c;
404294Seric {
405294Seric 	while (*s != '\0')
406294Seric 	{
407294Seric 		if (*s++ == c)
408294Seric 			return (--s);
409294Seric 	}
410294Seric 	return (NULL);
411294Seric }
412294Seric # endif V6
413294Seric 
414294Seric # ifndef V6
415294Seric /*
416294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
417294Seric **
418294Seric **	Returns the pathname of the user's tty.  Returns NULL if
419294Seric **	the user is not logged in or if s/he has write permission
420294Seric **	denied.
421294Seric **
422294Seric **	Parameters:
423294Seric **		none
424294Seric **
425294Seric **	Returns:
426294Seric **		pathname of the user's tty.
427294Seric **		NULL if not logged in or write permission denied.
428294Seric **
429294Seric **	Side Effects:
430294Seric **		none.
431294Seric **
432294Seric **	WARNING:
433294Seric **		Return value is in a local buffer.
434294Seric **
435294Seric **	Called By:
436294Seric **		savemail
437294Seric */
438294Seric 
439294Seric # include <sys/types.h>
440294Seric # include <sys/stat.h>
441294Seric 
442294Seric char *
443294Seric ttypath()
444294Seric {
445294Seric 	struct stat stbuf;
446294Seric 	register char *pathn;
447294Seric 	extern int errno;
448294Seric 	extern char *ttyname();
449294Seric 
450294Seric 	/* compute the pathname of the controlling tty */
451294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
452294Seric 	{
453294Seric 		errno = 0;
454294Seric 		return (NULL);
455294Seric 	}
456294Seric 
457294Seric 	/* see if we have write permission */
4582967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
459294Seric 	{
460294Seric 		errno = 0;
461294Seric 		return (NULL);
462294Seric 	}
463294Seric 
464294Seric 	/* see if the user is logged in */
465294Seric 	if (getlogin() == NULL)
466294Seric 		return (NULL);
467294Seric 
468294Seric 	/* looks good */
469294Seric 	return (pathn);
470294Seric }
471294Seric # endif V6
4722967Seric /*
4732967Seric **  CHECKCOMPAT -- check for From and To person compatible.
4742967Seric **
4752967Seric **	This routine can be supplied on a per-installation basis
4762967Seric **	to determine whether a person is allowed to send a message.
4772967Seric **	This allows restriction of certain types of internet
4782967Seric **	forwarding or registration of users.
4792967Seric **
4802967Seric **	If the hosts are found to be incompatible, an error
4812967Seric **	message should be given using "usrerr" and FALSE should
4822967Seric **	be returned.
4832967Seric **
4842967Seric **	Parameters:
4852967Seric **		to -- the person being sent to.
4862967Seric **
4872967Seric **	Returns:
4882967Seric **		TRUE -- ok to send.
4892967Seric **		FALSE -- not ok.
4902967Seric **
4912967Seric **	Side Effects:
4922967Seric **		none (unless you include the usrerr stuff)
4932967Seric */
4942967Seric 
4952967Seric bool
4962967Seric checkcompat(to)
4972967Seric 	register ADDRESS *to;
4982967Seric {
4992967Seric 	return (TRUE);
5002967Seric }
501