xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4778)
1294Seric # include <pwd.h>
23309Seric # include "sendmail.h"
3404Seric 
4294Seric /*
53309Seric **  CONF.C -- Sendmail Configuration Tables.
6294Seric **
7294Seric **	Defines the configuration of this installation.
8294Seric **
91388Seric **	Compilation Flags:
101388Seric **		V6 -- running on a version 6 system.  This determines
111388Seric **			whether to define certain routines between
121388Seric **			the two systems.  If you are running a funny
131388Seric **			system, e.g., V6 with long tty names, this
141388Seric **			should be checked carefully.
15294Seric **
161388Seric **	Configuration Variables:
172897Seric **		HdrInfo -- a table describing well-known header fields.
182897Seric **			Each entry has the field name and some flags,
194147Seric **			which are described in sendmail.h.
204315Seric **		StdTimezone -- name of local timezone in standard time
214315Seric **			(V6 only).
224315Seric **		DstTimezone -- name of local timezone in daylight savings
234315Seric **			time (V6 only).
244093Seric **
254093Seric **	Notes:
264093Seric **		I have tried to put almost all the reasonable
274093Seric **		configuration information into the configuration
284093Seric **		file read at runtime.  My intent is that anything
294093Seric **		here is a function of the version of UNIX you
304093Seric **		are running, or is really static -- for example
314093Seric **		the headers are a superset of widely used
324093Seric **		protocols.  If you find yourself playing with
334093Seric **		this file too much, you may be making a mistake!
34294Seric */
35294Seric 
36294Seric 
37294Seric 
38294Seric 
39*4778Seric static char SccsId[] = "@(#)conf.c	3.39	11/07/81";
404437Seric 
414437Seric 
424437Seric # include <whoami.h>		/* definitions of machine id's at berkeley */
434437Seric 
444437Seric 
454437Seric /*
462897Seric **  Header info table
473057Seric **	Final (null) entry contains the flags used for any other field.
484147Seric **
494147Seric **	Not all of these are actually handled specially by sendmail
504147Seric **	at this time.  They are included as placeholders, to let
514147Seric **	you know that "someday" I intend to have sendmail do
524147Seric **	something with them.
532897Seric */
542897Seric 
552897Seric struct hdrinfo	HdrInfo[] =
562897Seric {
574147Seric 	"date",			H_CHECK,		M_NEEDDATE,
584147Seric 	"from",			H_CHECK,		M_NEEDFROM,
594369Seric 	"original-from",	0,			0,
604147Seric 	"sender",		0,			0,
614147Seric 	"full-name",		H_ACHECK,		M_FULLNAME,
624263Seric 	"to",			H_ADDR,			0,
634263Seric 	"cc",			H_ADDR,			0,
644263Seric 	"bcc",			H_ADDR|H_ACHECK,	0,
654147Seric 	"message-id",		H_CHECK,		M_MSGID,
664147Seric 	"message",		H_EOH,			0,
674147Seric 	"text",			H_EOH,			0,
684147Seric 	"posted-date",		0,			0,
694147Seric 	"return-receipt-to",	0,			0,
704193Seric 	"received-date",	H_CHECK,		M_LOCAL,
714193Seric 	"received-from",	H_CHECK,		M_LOCAL,
724147Seric 	"precedence",		0,			0,
734147Seric 	"via",			H_FORCE,		0,
744147Seric 	NULL,			0,			0,
752897Seric };
764166Seric 
774166Seric 
784166Seric /*
794166Seric **  ARPANET error message numbers.
804166Seric */
814166Seric 
824166Seric char	Arpa_Info[] =	"050";	/* arbitrary info */
834708Seric char	Arpa_Syserr[] =	"451";	/* some (transient) system error */
844708Seric char	Arpa_Usrerr[] =	"554";	/* some (fatal) user error */
854282Seric 
864282Seric 
874282Seric 
884282Seric 
894282Seric 
904282Seric /*
914282Seric **  Location of system files/databases/etc.
924282Seric */
934282Seric 
944282Seric char	*AliasFile =	"/usr/lib/aliases";	/* alias file */
954282Seric char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
96*4778Seric char	*StatFile =	"/usr/lib/sendmail.st";	/* statistics summary */
974581Seric char	*HelpFile =	"/usr/lib/sendmail.hf";	/* help file */
984620Seric char	*QueueDir =	"/usr/spool/mqueue";	/* queue of saved mail */
994620Seric char	*XcriptFile =	"/tmp/mailxXXXXXX";	/* template for transcript */
1004315Seric 
1014315Seric 
1024414Seric /*
1034414Seric **  Other configuration.
1044414Seric */
1054315Seric 
1064414Seric int	DefUid = 1;		/* the uid to execute mailers as */
1074414Seric int	DefGid = 1;		/* ditto for gid */
1084620Seric time_t	TimeOut = 3*24*60*60;	/* default timeout for queue files */
1094414Seric 
1104414Seric 
1114414Seric 
1124315Seric /*
1134315Seric **  V6 system configuration.
1144315Seric */
1154315Seric 
1164315Seric # ifdef V6
1174315Seric char	*StdTimezone =	"PST";		/* std time timezone */
1184315Seric char	*DstTimezone =	"PDT";		/* daylight time timezone */
1194315Seric # endif V6
120294Seric 
121294Seric # ifdef V6
122294Seric /*
1234190Seric **  TTYNAME -- return name of terminal.
124294Seric **
125294Seric **	Parameters:
1264190Seric **		fd -- file descriptor to check.
127294Seric **
128294Seric **	Returns:
1294190Seric **		pointer to full path of tty.
1304190Seric **		NULL if no tty.
131294Seric **
132294Seric **	Side Effects:
133294Seric **		none.
134294Seric */
135294Seric 
136294Seric char *
1374190Seric ttyname(fd)
1384190Seric 	int fd;
139294Seric {
1404190Seric 	register char tn;
141294Seric 	static char pathn[] = "/dev/ttyx";
142294Seric 
143294Seric 	/* compute the pathname of the controlling tty */
1444190Seric 	if ((tn = ttyn(fd)) == NULL)
145294Seric 	{
146294Seric 		errno = 0;
147294Seric 		return (NULL);
148294Seric 	}
1494190Seric 	pathn[8] = tn;
150294Seric 	return (pathn);
151294Seric }
152294Seric /*
153294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
154294Seric **
155294Seric **	This is included here because it is standard in v7, but we
156294Seric **	need it in v6.
157294Seric **
158294Seric **	Algorithm:
159294Seric **		Open /dev/null to create a descriptor.
160294Seric **		Close that descriptor.
161294Seric **		Copy the existing fd into the descriptor.
162294Seric **
163294Seric **	Parameters:
164294Seric **		fd -- the open file descriptor.
165294Seric **		type -- "r", "w", or whatever.
166294Seric **
167294Seric **	Returns:
168294Seric **		The file descriptor it creates.
169294Seric **
170294Seric **	Side Effects:
171294Seric **		none
172294Seric **
173294Seric **	Called By:
174294Seric **		deliver
175294Seric **
176294Seric **	Notes:
177294Seric **		The mode of fd must match "type".
178294Seric */
179294Seric 
180294Seric FILE *
181294Seric fdopen(fd, type)
182294Seric 	int fd;
183294Seric 	char *type;
184294Seric {
185294Seric 	register FILE *f;
186294Seric 
187294Seric 	f = fopen("/dev/null", type);
1884081Seric 	(void) close(fileno(f));
189294Seric 	fileno(f) = fd;
190294Seric 	return (f);
191294Seric }
192294Seric /*
193294Seric **  INDEX -- Return pointer to character in string
194294Seric **
195294Seric **	For V7 compatibility.
196294Seric **
197294Seric **	Parameters:
198294Seric **		s -- a string to scan.
199294Seric **		c -- a character to look for.
200294Seric **
201294Seric **	Returns:
202294Seric **		If c is in s, returns the address of the first
203294Seric **			instance of c in s.
204294Seric **		NULL if c is not in s.
205294Seric **
206294Seric **	Side Effects:
207294Seric **		none.
208294Seric */
209294Seric 
2104437Seric char *
211294Seric index(s, c)
212294Seric 	register char *s;
213294Seric 	register char c;
214294Seric {
215294Seric 	while (*s != '\0')
216294Seric 	{
217294Seric 		if (*s++ == c)
218294Seric 			return (--s);
219294Seric 	}
220294Seric 	return (NULL);
221294Seric }
2224326Seric /*
2234326Seric **  UMASK -- fake the umask system call.
2244326Seric **
2254326Seric **	Since V6 always acts like the umask is zero, we will just
2264326Seric **	assume the same thing.
2274326Seric */
2284326Seric 
2294326Seric /*ARGSUSED*/
2304326Seric umask(nmask)
2314326Seric {
2324326Seric 	return (0);
2334326Seric }
2344326Seric 
2354326Seric 
2364326Seric /*
2374326Seric **  GETRUID -- get real user id.
2384326Seric */
2394326Seric 
2404326Seric getruid()
2414326Seric {
2424326Seric 	return (getuid() & 0377);
2434326Seric }
2444326Seric 
2454326Seric 
2464326Seric /*
2474326Seric **  GETRGID -- get real group id.
2484326Seric */
2494326Seric 
2504326Seric getrgid()
2514326Seric {
2524326Seric 	return (getgid() & 0377);
2534326Seric }
2544326Seric 
2554326Seric 
2564326Seric /*
2574326Seric **  GETEUID -- get effective user id.
2584326Seric */
2594326Seric 
2604326Seric geteuid()
2614326Seric {
2624326Seric 	return ((getuid() >> 8) & 0377);
2634326Seric }
2644326Seric 
2654326Seric 
2664326Seric /*
2674326Seric **  GETEGID -- get effective group id.
2684326Seric */
2694326Seric 
2704326Seric getegid()
2714326Seric {
2724326Seric 	return ((getgid() >> 8) & 0377);
2734326Seric }
2744326Seric 
275294Seric # endif V6
2764326Seric 
2774326Seric # ifndef V6
2784326Seric 
2794326Seric /*
2804326Seric **  GETRUID -- get real user id (V7)
2814326Seric */
2824326Seric 
2834326Seric getruid()
2844326Seric {
2854536Seric 	if (Daemon)
2864536Seric 		return (RealUid);
2874536Seric 	else
2884536Seric 		return (getuid());
2894326Seric }
2904326Seric 
2914326Seric 
2924326Seric /*
2934326Seric **  GETRGID -- get real group id (V7).
2944326Seric */
2954326Seric 
2964326Seric getrgid()
2974326Seric {
2984536Seric 	if (Daemon)
2994536Seric 		return (RealGid);
3004536Seric 	else
3014536Seric 		return (getgid());
3024326Seric }
3034326Seric 
3044326Seric # endif V6
3054190Seric /*
3064190Seric **  TTYPATH -- Get the path of the user's tty
307294Seric **
308294Seric **	Returns the pathname of the user's tty.  Returns NULL if
309294Seric **	the user is not logged in or if s/he has write permission
310294Seric **	denied.
311294Seric **
312294Seric **	Parameters:
313294Seric **		none
314294Seric **
315294Seric **	Returns:
316294Seric **		pathname of the user's tty.
317294Seric **		NULL if not logged in or write permission denied.
318294Seric **
319294Seric **	Side Effects:
320294Seric **		none.
321294Seric **
322294Seric **	WARNING:
323294Seric **		Return value is in a local buffer.
324294Seric **
325294Seric **	Called By:
326294Seric **		savemail
327294Seric */
328294Seric 
329294Seric # include <sys/stat.h>
330294Seric 
331294Seric char *
332294Seric ttypath()
333294Seric {
334294Seric 	struct stat stbuf;
335294Seric 	register char *pathn;
336294Seric 	extern char *ttyname();
3374081Seric 	extern char *getlogin();
338294Seric 
339294Seric 	/* compute the pathname of the controlling tty */
340294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
341294Seric 	{
342294Seric 		errno = 0;
343294Seric 		return (NULL);
344294Seric 	}
345294Seric 
346294Seric 	/* see if we have write permission */
3472967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
348294Seric 	{
349294Seric 		errno = 0;
350294Seric 		return (NULL);
351294Seric 	}
352294Seric 
353294Seric 	/* see if the user is logged in */
354294Seric 	if (getlogin() == NULL)
355294Seric 		return (NULL);
356294Seric 
357294Seric 	/* looks good */
358294Seric 	return (pathn);
359294Seric }
3602967Seric /*
3612967Seric **  CHECKCOMPAT -- check for From and To person compatible.
3622967Seric **
3632967Seric **	This routine can be supplied on a per-installation basis
3642967Seric **	to determine whether a person is allowed to send a message.
3652967Seric **	This allows restriction of certain types of internet
3662967Seric **	forwarding or registration of users.
3672967Seric **
3682967Seric **	If the hosts are found to be incompatible, an error
3692967Seric **	message should be given using "usrerr" and FALSE should
3702967Seric **	be returned.
3712967Seric **
3724288Seric **	'NoReturn' can be set to suppress the return-to-sender
3734288Seric **	function; this should be done on huge messages.
3744288Seric **
3752967Seric **	Parameters:
3762967Seric **		to -- the person being sent to.
3772967Seric **
3782967Seric **	Returns:
3792967Seric **		TRUE -- ok to send.
3802967Seric **		FALSE -- not ok.
3812967Seric **
3822967Seric **	Side Effects:
3832967Seric **		none (unless you include the usrerr stuff)
3842967Seric */
3852967Seric 
3862967Seric bool
3872967Seric checkcompat(to)
3882967Seric 	register ADDRESS *to;
3892967Seric {
3904620Seric # ifdef ING70
3914437Seric 	register STAB *s;
3924620Seric # endif ING70
3934437Seric 
3944595Seric 	if (to->q_mailer != LocalMailer && MsgSize > 100000)
3954288Seric 	{
3964288Seric 		usrerr("Message exceeds 100000 bytes");
3974288Seric 		NoReturn++;
3984288Seric 		return (FALSE);
3994288Seric 	}
4004437Seric # ifdef ING70
4014437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
4024595Seric 	if (s != NULL && From.q_mailer != LocalMailer && to->q_mailer == s->s_mailer)
4034437Seric 	{
4044437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
4054437Seric 		return (FALSE);
4064437Seric 	}
4074437Seric # endif ING70
4082967Seric 	return (TRUE);
4092967Seric }
410