xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 9064)
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.
204093Seric **
214093Seric **	Notes:
224093Seric **		I have tried to put almost all the reasonable
234093Seric **		configuration information into the configuration
244093Seric **		file read at runtime.  My intent is that anything
254093Seric **		here is a function of the version of UNIX you
264093Seric **		are running, or is really static -- for example
274093Seric **		the headers are a superset of widely used
284093Seric **		protocols.  If you find yourself playing with
294093Seric **		this file too much, you may be making a mistake!
30294Seric */
31294Seric 
32294Seric 
33294Seric 
34294Seric 
35*9064Seric SCCSID(@(#)conf.c	3.63		11/05/82);
364437Seric 
374437Seric 
384437Seric 
394437Seric /*
402897Seric **  Header info table
413057Seric **	Final (null) entry contains the flags used for any other field.
424147Seric **
434147Seric **	Not all of these are actually handled specially by sendmail
444147Seric **	at this time.  They are included as placeholders, to let
454147Seric **	you know that "someday" I intend to have sendmail do
464147Seric **	something with them.
472897Seric */
482897Seric 
492897Seric struct hdrinfo	HdrInfo[] =
502897Seric {
518060Seric 		/* originator fields, most to least significant  */
529055Seric 	"resent-sender",	H_FROM,
539055Seric 	"resent-from",		H_FROM,
549055Seric 	"sender",		H_FROM,
559055Seric 	"from",			H_FROM,
569055Seric 	"full-name",		H_ACHECK,
579055Seric 	"return-receipt-to",	H_FROM,
589055Seric 	"errors-to",		H_FROM,
598060Seric 		/* destination fields */
609055Seric 	"to",			H_RCPT,
619055Seric 	"resent-to",		H_RCPT,
629055Seric 	"cc",			H_RCPT,
639055Seric 	"resent-cc",		H_RCPT,
649055Seric 	"bcc",			H_RCPT|H_ACHECK,
659055Seric 	"resent-bcc",		H_RCPT|H_ACHECK,
668060Seric 		/* message identification and control */
679055Seric 	"message",		H_EOH,
689055Seric 	"text",			H_EOH,
698060Seric 		/* trace fields */
709055Seric 	"received",		H_TRACE|H_FORCE,
719055Seric 	"via",			H_TRACE|H_FORCE,
729055Seric 	"mail-from",		H_TRACE|H_FORCE,
738060Seric 
749055Seric 	NULL,			0,
752897Seric };
764166Seric 
774166Seric 
784166Seric /*
794166Seric **  ARPANET error message numbers.
804166Seric */
814166Seric 
827956Seric char	Arpa_Info[] =		"050";	/* arbitrary info */
837956Seric char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
847956Seric char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
857956Seric char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
864282Seric 
874282Seric 
884282Seric 
894282Seric /*
904282Seric **  Location of system files/databases/etc.
914282Seric */
924282Seric 
934282Seric char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
94*9064Seric char	*FreezeFile =	"/usr/lib/sendmail.fc";	/* frozen version of above */
959039Seric 
96*9064Seric 
97*9064Seric 
989039Seric /*
999039Seric **  Some other configuration....
1009039Seric */
1019039Seric 
1029039Seric char	SpaceSub =	'.';
103294Seric 
104294Seric # ifdef V6
105294Seric /*
1064190Seric **  TTYNAME -- return name of terminal.
107294Seric **
108294Seric **	Parameters:
1094190Seric **		fd -- file descriptor to check.
110294Seric **
111294Seric **	Returns:
1124190Seric **		pointer to full path of tty.
1134190Seric **		NULL if no tty.
114294Seric **
115294Seric **	Side Effects:
116294Seric **		none.
117294Seric */
118294Seric 
119294Seric char *
1204190Seric ttyname(fd)
1214190Seric 	int fd;
122294Seric {
1234190Seric 	register char tn;
124294Seric 	static char pathn[] = "/dev/ttyx";
125294Seric 
126294Seric 	/* compute the pathname of the controlling tty */
1274190Seric 	if ((tn = ttyn(fd)) == NULL)
128294Seric 	{
129294Seric 		errno = 0;
130294Seric 		return (NULL);
131294Seric 	}
1324190Seric 	pathn[8] = tn;
133294Seric 	return (pathn);
134294Seric }
135294Seric /*
136294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
137294Seric **
138294Seric **	This is included here because it is standard in v7, but we
139294Seric **	need it in v6.
140294Seric **
141294Seric **	Algorithm:
142294Seric **		Open /dev/null to create a descriptor.
143294Seric **		Close that descriptor.
144294Seric **		Copy the existing fd into the descriptor.
145294Seric **
146294Seric **	Parameters:
147294Seric **		fd -- the open file descriptor.
148294Seric **		type -- "r", "w", or whatever.
149294Seric **
150294Seric **	Returns:
151294Seric **		The file descriptor it creates.
152294Seric **
153294Seric **	Side Effects:
154294Seric **		none
155294Seric **
156294Seric **	Called By:
157294Seric **		deliver
158294Seric **
159294Seric **	Notes:
160294Seric **		The mode of fd must match "type".
161294Seric */
162294Seric 
163294Seric FILE *
164294Seric fdopen(fd, type)
165294Seric 	int fd;
166294Seric 	char *type;
167294Seric {
168294Seric 	register FILE *f;
169294Seric 
170294Seric 	f = fopen("/dev/null", type);
1714081Seric 	(void) close(fileno(f));
172294Seric 	fileno(f) = fd;
173294Seric 	return (f);
174294Seric }
175294Seric /*
176294Seric **  INDEX -- Return pointer to character in string
177294Seric **
178294Seric **	For V7 compatibility.
179294Seric **
180294Seric **	Parameters:
181294Seric **		s -- a string to scan.
182294Seric **		c -- a character to look for.
183294Seric **
184294Seric **	Returns:
185294Seric **		If c is in s, returns the address of the first
186294Seric **			instance of c in s.
187294Seric **		NULL if c is not in s.
188294Seric **
189294Seric **	Side Effects:
190294Seric **		none.
191294Seric */
192294Seric 
1934437Seric char *
194294Seric index(s, c)
195294Seric 	register char *s;
196294Seric 	register char c;
197294Seric {
198294Seric 	while (*s != '\0')
199294Seric 	{
200294Seric 		if (*s++ == c)
201294Seric 			return (--s);
202294Seric 	}
203294Seric 	return (NULL);
204294Seric }
2054326Seric /*
2064326Seric **  UMASK -- fake the umask system call.
2074326Seric **
2084326Seric **	Since V6 always acts like the umask is zero, we will just
2094326Seric **	assume the same thing.
2104326Seric */
2114326Seric 
2124326Seric /*ARGSUSED*/
2134326Seric umask(nmask)
2144326Seric {
2154326Seric 	return (0);
2164326Seric }
2174326Seric 
2184326Seric 
2194326Seric /*
2204326Seric **  GETRUID -- get real user id.
2214326Seric */
2224326Seric 
2234326Seric getruid()
2244326Seric {
2254326Seric 	return (getuid() & 0377);
2264326Seric }
2274326Seric 
2284326Seric 
2294326Seric /*
2304326Seric **  GETRGID -- get real group id.
2314326Seric */
2324326Seric 
2334326Seric getrgid()
2344326Seric {
2354326Seric 	return (getgid() & 0377);
2364326Seric }
2374326Seric 
2384326Seric 
2394326Seric /*
2404326Seric **  GETEUID -- get effective user id.
2414326Seric */
2424326Seric 
2434326Seric geteuid()
2444326Seric {
2454326Seric 	return ((getuid() >> 8) & 0377);
2464326Seric }
2474326Seric 
2484326Seric 
2494326Seric /*
2504326Seric **  GETEGID -- get effective group id.
2514326Seric */
2524326Seric 
2534326Seric getegid()
2544326Seric {
2554326Seric 	return ((getgid() >> 8) & 0377);
2564326Seric }
2574326Seric 
258294Seric # endif V6
2594326Seric 
2604326Seric # ifndef V6
2614326Seric 
2624326Seric /*
2634326Seric **  GETRUID -- get real user id (V7)
2644326Seric */
2654326Seric 
2664326Seric getruid()
2674326Seric {
2686996Seric 	if (Mode == MD_DAEMON)
2694536Seric 		return (RealUid);
2704536Seric 	else
2714536Seric 		return (getuid());
2724326Seric }
2734326Seric 
2744326Seric 
2754326Seric /*
2764326Seric **  GETRGID -- get real group id (V7).
2774326Seric */
2784326Seric 
2794326Seric getrgid()
2804326Seric {
2816996Seric 	if (Mode == MD_DAEMON)
2824536Seric 		return (RealGid);
2834536Seric 	else
2844536Seric 		return (getgid());
2854326Seric }
2864326Seric 
2874326Seric # endif V6
2884190Seric /*
2894190Seric **  TTYPATH -- Get the path of the user's tty
290294Seric **
291294Seric **	Returns the pathname of the user's tty.  Returns NULL if
292294Seric **	the user is not logged in or if s/he has write permission
293294Seric **	denied.
294294Seric **
295294Seric **	Parameters:
296294Seric **		none
297294Seric **
298294Seric **	Returns:
299294Seric **		pathname of the user's tty.
300294Seric **		NULL if not logged in or write permission denied.
301294Seric **
302294Seric **	Side Effects:
303294Seric **		none.
304294Seric **
305294Seric **	WARNING:
306294Seric **		Return value is in a local buffer.
307294Seric **
308294Seric **	Called By:
309294Seric **		savemail
310294Seric */
311294Seric 
312294Seric # include <sys/stat.h>
313294Seric 
314294Seric char *
315294Seric ttypath()
316294Seric {
317294Seric 	struct stat stbuf;
318294Seric 	register char *pathn;
319294Seric 	extern char *ttyname();
3204081Seric 	extern char *getlogin();
321294Seric 
322294Seric 	/* compute the pathname of the controlling tty */
323294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
324294Seric 	{
325294Seric 		errno = 0;
326294Seric 		return (NULL);
327294Seric 	}
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 }
3432967Seric /*
3442967Seric **  CHECKCOMPAT -- check for From and To person compatible.
3452967Seric **
3462967Seric **	This routine can be supplied on a per-installation basis
3472967Seric **	to determine whether a person is allowed to send a message.
3482967Seric **	This allows restriction of certain types of internet
3492967Seric **	forwarding or registration of users.
3502967Seric **
3512967Seric **	If the hosts are found to be incompatible, an error
3522967Seric **	message should be given using "usrerr" and FALSE should
3532967Seric **	be returned.
3542967Seric **
3554288Seric **	'NoReturn' can be set to suppress the return-to-sender
3564288Seric **	function; this should be done on huge messages.
3574288Seric **
3582967Seric **	Parameters:
3592967Seric **		to -- the person being sent to.
3602967Seric **
3612967Seric **	Returns:
3622967Seric **		TRUE -- ok to send.
3632967Seric **		FALSE -- not ok.
3642967Seric **
3652967Seric **	Side Effects:
3662967Seric **		none (unless you include the usrerr stuff)
3672967Seric */
3682967Seric 
3692967Seric bool
3702967Seric checkcompat(to)
3712967Seric 	register ADDRESS *to;
3722967Seric {
3734620Seric # ifdef ING70
3744437Seric 	register STAB *s;
3754620Seric # endif ING70
3764437Seric 
3776899Seric 	if (to->q_mailer != LocalMailer && CurEnv->e_msgsize > 100000)
3784288Seric 	{
3794288Seric 		usrerr("Message exceeds 100000 bytes");
3804288Seric 		NoReturn++;
3814288Seric 		return (FALSE);
3824288Seric 	}
3834437Seric # ifdef ING70
3844437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
3856899Seric 	if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && to->q_mailer == s->s_mailer)
3864437Seric 	{
3874437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
3884437Seric 		return (FALSE);
3894437Seric 	}
3904437Seric # endif ING70
3912967Seric 	return (TRUE);
3922967Seric }
393