xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 7956)
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*7956Seric SCCSID(@(#)conf.c	3.55		08/29/82);
404437Seric 
414437Seric 
424437Seric 
434437Seric /*
442897Seric **  Header info table
453057Seric **	Final (null) entry contains the flags used for any other field.
464147Seric **
474147Seric **	Not all of these are actually handled specially by sendmail
484147Seric **	at this time.  They are included as placeholders, to let
494147Seric **	you know that "someday" I intend to have sendmail do
504147Seric **	something with them.
512897Seric */
522897Seric 
532897Seric struct hdrinfo	HdrInfo[] =
542897Seric {
554147Seric 	"date",			H_CHECK,		M_NEEDDATE,
567760Seric 	"from",			H_ADDR|H_FROM|H_CHECK,	M_NEEDFROM,
574369Seric 	"original-from",	0,			0,
585915Seric 	"sender",		H_ADDR,			0,
594147Seric 	"full-name",		H_ACHECK,		M_FULLNAME,
605915Seric 	"to",			H_ADDR|H_RCPT,		0,
615915Seric 	"cc",			H_ADDR|H_RCPT,		0,
627669Seric 	"bcc",			H_ADDR|H_RCPT,		0,
637669Seric 	"message-id",		0,			0,
644147Seric 	"message",		H_EOH,			0,
654147Seric 	"text",			H_EOH,			0,
664147Seric 	"posted-date",		0,			0,
674147Seric 	"return-receipt-to",	0,			0,
684193Seric 	"received-date",	H_CHECK,		M_LOCAL,
694193Seric 	"received-from",	H_CHECK,		M_LOCAL,
704147Seric 	"precedence",		0,			0,
717787Seric 	"received",		H_FORCE,		0,
724147Seric 	"via",			H_FORCE,		0,
734147Seric 	NULL,			0,			0,
742897Seric };
754166Seric 
764166Seric 
774166Seric /*
784166Seric **  ARPANET error message numbers.
794166Seric */
804166Seric 
81*7956Seric char	Arpa_Info[] =		"050";	/* arbitrary info */
82*7956Seric char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
83*7956Seric char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
84*7956Seric 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 */
964778Seric char	*StatFile =	"/usr/lib/sendmail.st";	/* statistics summary */
974581Seric char	*HelpFile =	"/usr/lib/sendmail.hf";	/* help file */
985178Seric # ifdef QUEUE
994620Seric char	*QueueDir =	"/usr/spool/mqueue";	/* queue of saved mail */
1005178Seric # else QUEUE
1015178Seric char	*QueueDir =	"/tmp";			/* location of temp files */
1025178Seric # endif QUEUE
1034620Seric char	*XcriptFile =	"/tmp/mailxXXXXXX";	/* template for transcript */
1044315Seric 
1054315Seric 
1064414Seric /*
1074414Seric **  Other configuration.
1084414Seric */
1094315Seric 
1107354Seric int	DefUid =	1;		/* the uid to execute mailers as */
1117354Seric int	DefGid =	1;		/* ditto for gid */
1127354Seric time_t	TimeOut =	3*24*60*60L;	/* default timeout for queue files */
1137354Seric int	ReadTimeout =	10*60;		/* timeout on external reads */
1147679Seric int	LogLevel =	9;		/* default logging level */
1154414Seric 
1164414Seric 
1174414Seric 
1184315Seric /*
1194315Seric **  V6 system configuration.
1204315Seric */
1214315Seric 
1224315Seric # ifdef V6
1234315Seric char	*StdTimezone =	"PST";		/* std time timezone */
1244315Seric char	*DstTimezone =	"PDT";		/* daylight time timezone */
1254315Seric # endif V6
126294Seric 
127294Seric # ifdef V6
128294Seric /*
1294190Seric **  TTYNAME -- return name of terminal.
130294Seric **
131294Seric **	Parameters:
1324190Seric **		fd -- file descriptor to check.
133294Seric **
134294Seric **	Returns:
1354190Seric **		pointer to full path of tty.
1364190Seric **		NULL if no tty.
137294Seric **
138294Seric **	Side Effects:
139294Seric **		none.
140294Seric */
141294Seric 
142294Seric char *
1434190Seric ttyname(fd)
1444190Seric 	int fd;
145294Seric {
1464190Seric 	register char tn;
147294Seric 	static char pathn[] = "/dev/ttyx";
148294Seric 
149294Seric 	/* compute the pathname of the controlling tty */
1504190Seric 	if ((tn = ttyn(fd)) == NULL)
151294Seric 	{
152294Seric 		errno = 0;
153294Seric 		return (NULL);
154294Seric 	}
1554190Seric 	pathn[8] = tn;
156294Seric 	return (pathn);
157294Seric }
158294Seric /*
159294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
160294Seric **
161294Seric **	This is included here because it is standard in v7, but we
162294Seric **	need it in v6.
163294Seric **
164294Seric **	Algorithm:
165294Seric **		Open /dev/null to create a descriptor.
166294Seric **		Close that descriptor.
167294Seric **		Copy the existing fd into the descriptor.
168294Seric **
169294Seric **	Parameters:
170294Seric **		fd -- the open file descriptor.
171294Seric **		type -- "r", "w", or whatever.
172294Seric **
173294Seric **	Returns:
174294Seric **		The file descriptor it creates.
175294Seric **
176294Seric **	Side Effects:
177294Seric **		none
178294Seric **
179294Seric **	Called By:
180294Seric **		deliver
181294Seric **
182294Seric **	Notes:
183294Seric **		The mode of fd must match "type".
184294Seric */
185294Seric 
186294Seric FILE *
187294Seric fdopen(fd, type)
188294Seric 	int fd;
189294Seric 	char *type;
190294Seric {
191294Seric 	register FILE *f;
192294Seric 
193294Seric 	f = fopen("/dev/null", type);
1944081Seric 	(void) close(fileno(f));
195294Seric 	fileno(f) = fd;
196294Seric 	return (f);
197294Seric }
198294Seric /*
199294Seric **  INDEX -- Return pointer to character in string
200294Seric **
201294Seric **	For V7 compatibility.
202294Seric **
203294Seric **	Parameters:
204294Seric **		s -- a string to scan.
205294Seric **		c -- a character to look for.
206294Seric **
207294Seric **	Returns:
208294Seric **		If c is in s, returns the address of the first
209294Seric **			instance of c in s.
210294Seric **		NULL if c is not in s.
211294Seric **
212294Seric **	Side Effects:
213294Seric **		none.
214294Seric */
215294Seric 
2164437Seric char *
217294Seric index(s, c)
218294Seric 	register char *s;
219294Seric 	register char c;
220294Seric {
221294Seric 	while (*s != '\0')
222294Seric 	{
223294Seric 		if (*s++ == c)
224294Seric 			return (--s);
225294Seric 	}
226294Seric 	return (NULL);
227294Seric }
2284326Seric /*
2294326Seric **  UMASK -- fake the umask system call.
2304326Seric **
2314326Seric **	Since V6 always acts like the umask is zero, we will just
2324326Seric **	assume the same thing.
2334326Seric */
2344326Seric 
2354326Seric /*ARGSUSED*/
2364326Seric umask(nmask)
2374326Seric {
2384326Seric 	return (0);
2394326Seric }
2404326Seric 
2414326Seric 
2424326Seric /*
2434326Seric **  GETRUID -- get real user id.
2444326Seric */
2454326Seric 
2464326Seric getruid()
2474326Seric {
2484326Seric 	return (getuid() & 0377);
2494326Seric }
2504326Seric 
2514326Seric 
2524326Seric /*
2534326Seric **  GETRGID -- get real group id.
2544326Seric */
2554326Seric 
2564326Seric getrgid()
2574326Seric {
2584326Seric 	return (getgid() & 0377);
2594326Seric }
2604326Seric 
2614326Seric 
2624326Seric /*
2634326Seric **  GETEUID -- get effective user id.
2644326Seric */
2654326Seric 
2664326Seric geteuid()
2674326Seric {
2684326Seric 	return ((getuid() >> 8) & 0377);
2694326Seric }
2704326Seric 
2714326Seric 
2724326Seric /*
2734326Seric **  GETEGID -- get effective group id.
2744326Seric */
2754326Seric 
2764326Seric getegid()
2774326Seric {
2784326Seric 	return ((getgid() >> 8) & 0377);
2794326Seric }
2804326Seric 
281294Seric # endif V6
2824326Seric 
2834326Seric # ifndef V6
2844326Seric 
2854326Seric /*
2864326Seric **  GETRUID -- get real user id (V7)
2874326Seric */
2884326Seric 
2894326Seric getruid()
2904326Seric {
2916996Seric 	if (Mode == MD_DAEMON)
2924536Seric 		return (RealUid);
2934536Seric 	else
2944536Seric 		return (getuid());
2954326Seric }
2964326Seric 
2974326Seric 
2984326Seric /*
2994326Seric **  GETRGID -- get real group id (V7).
3004326Seric */
3014326Seric 
3024326Seric getrgid()
3034326Seric {
3046996Seric 	if (Mode == MD_DAEMON)
3054536Seric 		return (RealGid);
3064536Seric 	else
3074536Seric 		return (getgid());
3084326Seric }
3094326Seric 
3104326Seric # endif V6
3114190Seric /*
3124190Seric **  TTYPATH -- Get the path of the user's tty
313294Seric **
314294Seric **	Returns the pathname of the user's tty.  Returns NULL if
315294Seric **	the user is not logged in or if s/he has write permission
316294Seric **	denied.
317294Seric **
318294Seric **	Parameters:
319294Seric **		none
320294Seric **
321294Seric **	Returns:
322294Seric **		pathname of the user's tty.
323294Seric **		NULL if not logged in or write permission denied.
324294Seric **
325294Seric **	Side Effects:
326294Seric **		none.
327294Seric **
328294Seric **	WARNING:
329294Seric **		Return value is in a local buffer.
330294Seric **
331294Seric **	Called By:
332294Seric **		savemail
333294Seric */
334294Seric 
335294Seric # include <sys/stat.h>
336294Seric 
337294Seric char *
338294Seric ttypath()
339294Seric {
340294Seric 	struct stat stbuf;
341294Seric 	register char *pathn;
342294Seric 	extern char *ttyname();
3434081Seric 	extern char *getlogin();
344294Seric 
345294Seric 	/* compute the pathname of the controlling tty */
346294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
347294Seric 	{
348294Seric 		errno = 0;
349294Seric 		return (NULL);
350294Seric 	}
351294Seric 
352294Seric 	/* see if we have write permission */
3532967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
354294Seric 	{
355294Seric 		errno = 0;
356294Seric 		return (NULL);
357294Seric 	}
358294Seric 
359294Seric 	/* see if the user is logged in */
360294Seric 	if (getlogin() == NULL)
361294Seric 		return (NULL);
362294Seric 
363294Seric 	/* looks good */
364294Seric 	return (pathn);
365294Seric }
3662967Seric /*
3672967Seric **  CHECKCOMPAT -- check for From and To person compatible.
3682967Seric **
3692967Seric **	This routine can be supplied on a per-installation basis
3702967Seric **	to determine whether a person is allowed to send a message.
3712967Seric **	This allows restriction of certain types of internet
3722967Seric **	forwarding or registration of users.
3732967Seric **
3742967Seric **	If the hosts are found to be incompatible, an error
3752967Seric **	message should be given using "usrerr" and FALSE should
3762967Seric **	be returned.
3772967Seric **
3784288Seric **	'NoReturn' can be set to suppress the return-to-sender
3794288Seric **	function; this should be done on huge messages.
3804288Seric **
3812967Seric **	Parameters:
3822967Seric **		to -- the person being sent to.
3832967Seric **
3842967Seric **	Returns:
3852967Seric **		TRUE -- ok to send.
3862967Seric **		FALSE -- not ok.
3872967Seric **
3882967Seric **	Side Effects:
3892967Seric **		none (unless you include the usrerr stuff)
3902967Seric */
3912967Seric 
3922967Seric bool
3932967Seric checkcompat(to)
3942967Seric 	register ADDRESS *to;
3952967Seric {
3964620Seric # ifdef ING70
3974437Seric 	register STAB *s;
3984620Seric # endif ING70
3994437Seric 
4006899Seric 	if (to->q_mailer != LocalMailer && CurEnv->e_msgsize > 100000)
4014288Seric 	{
4024288Seric 		usrerr("Message exceeds 100000 bytes");
4034288Seric 		NoReturn++;
4044288Seric 		return (FALSE);
4054288Seric 	}
4064437Seric # ifdef ING70
4074437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
4086899Seric 	if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && to->q_mailer == s->s_mailer)
4094437Seric 	{
4104437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
4114437Seric 		return (FALSE);
4124437Seric 	}
4134437Seric # endif ING70
4142967Seric 	return (TRUE);
4152967Seric }
416