xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4620)
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*4620Seric static char SccsId[] = "@(#)conf.c	3.37	10/26/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 # ifdef NEWFTP
834166Seric /* these are almost all unchecked */
844166Seric char	Arpa_Info[] =	"010";	/* arbitrary info: this is WRONG! */
854166Seric char	Arpa_Enter[] =	"354";	/* start mail input */
864166Seric char	Arpa_Mmsg[] =	"250";	/* mail successful (MAIL cmd) */
874166Seric char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
884166Seric char	Arpa_Syserr[] =	"450";	/* some (transient) system error */
894166Seric char	Arpa_Usrerr[] =	"550";	/* some (fatal) user error */
904166Seric # else NEWFTP
914166Seric char	Arpa_Info[] =	"050";	/* arbitrary info */
924166Seric char	Arpa_Enter[] =	"350";	/* start mail input */
934166Seric char	Arpa_Mmsg[] =	"256";	/* mail successful (MAIL cmd) */
944166Seric char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
954166Seric char	Arpa_Syserr[] =	"455";	/* some (transient) system error */
964166Seric char	Arpa_Usrerr[] =	"450";	/* some (fatal) user error */
974166Seric # endif NEWFTP
984282Seric 
994282Seric 
1004282Seric 
1014282Seric 
1024282Seric 
1034282Seric /*
1044282Seric **  Location of system files/databases/etc.
1054282Seric */
1064282Seric 
1074282Seric char	*AliasFile =	"/usr/lib/aliases";	/* alias file */
1084282Seric char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
1094581Seric char	*StatFile =	"/usr/lib/mailstats";	/* statistics summary */
1104581Seric char	*HelpFile =	"/usr/lib/sendmail.hf";	/* help file */
111*4620Seric char	*QueueDir =	"/usr/spool/mqueue";	/* queue of saved mail */
112*4620Seric char	*XcriptFile =	"/tmp/mailxXXXXXX";	/* template for transcript */
1134315Seric 
1144315Seric 
1154414Seric /*
1164414Seric **  Other configuration.
1174414Seric */
1184315Seric 
1194414Seric int	DefUid = 1;		/* the uid to execute mailers as */
1204414Seric int	DefGid = 1;		/* ditto for gid */
121*4620Seric time_t	TimeOut = 3*24*60*60;	/* default timeout for queue files */
1224414Seric 
1234414Seric 
1244414Seric 
1254315Seric /*
1264315Seric **  V6 system configuration.
1274315Seric */
1284315Seric 
1294315Seric # ifdef V6
1304315Seric char	*StdTimezone =	"PST";		/* std time timezone */
1314315Seric char	*DstTimezone =	"PDT";		/* daylight time timezone */
1324315Seric # endif V6
133294Seric 
134294Seric # ifdef V6
135294Seric /*
1364190Seric **  TTYNAME -- return name of terminal.
137294Seric **
138294Seric **	Parameters:
1394190Seric **		fd -- file descriptor to check.
140294Seric **
141294Seric **	Returns:
1424190Seric **		pointer to full path of tty.
1434190Seric **		NULL if no tty.
144294Seric **
145294Seric **	Side Effects:
146294Seric **		none.
147294Seric */
148294Seric 
149294Seric char *
1504190Seric ttyname(fd)
1514190Seric 	int fd;
152294Seric {
1534190Seric 	register char tn;
154294Seric 	static char pathn[] = "/dev/ttyx";
155294Seric 
156294Seric 	/* compute the pathname of the controlling tty */
1574190Seric 	if ((tn = ttyn(fd)) == NULL)
158294Seric 	{
159294Seric 		errno = 0;
160294Seric 		return (NULL);
161294Seric 	}
1624190Seric 	pathn[8] = tn;
163294Seric 	return (pathn);
164294Seric }
165294Seric /*
166294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
167294Seric **
168294Seric **	This is included here because it is standard in v7, but we
169294Seric **	need it in v6.
170294Seric **
171294Seric **	Algorithm:
172294Seric **		Open /dev/null to create a descriptor.
173294Seric **		Close that descriptor.
174294Seric **		Copy the existing fd into the descriptor.
175294Seric **
176294Seric **	Parameters:
177294Seric **		fd -- the open file descriptor.
178294Seric **		type -- "r", "w", or whatever.
179294Seric **
180294Seric **	Returns:
181294Seric **		The file descriptor it creates.
182294Seric **
183294Seric **	Side Effects:
184294Seric **		none
185294Seric **
186294Seric **	Called By:
187294Seric **		deliver
188294Seric **
189294Seric **	Notes:
190294Seric **		The mode of fd must match "type".
191294Seric */
192294Seric 
193294Seric FILE *
194294Seric fdopen(fd, type)
195294Seric 	int fd;
196294Seric 	char *type;
197294Seric {
198294Seric 	register FILE *f;
199294Seric 
200294Seric 	f = fopen("/dev/null", type);
2014081Seric 	(void) close(fileno(f));
202294Seric 	fileno(f) = fd;
203294Seric 	return (f);
204294Seric }
205294Seric /*
206294Seric **  INDEX -- Return pointer to character in string
207294Seric **
208294Seric **	For V7 compatibility.
209294Seric **
210294Seric **	Parameters:
211294Seric **		s -- a string to scan.
212294Seric **		c -- a character to look for.
213294Seric **
214294Seric **	Returns:
215294Seric **		If c is in s, returns the address of the first
216294Seric **			instance of c in s.
217294Seric **		NULL if c is not in s.
218294Seric **
219294Seric **	Side Effects:
220294Seric **		none.
221294Seric */
222294Seric 
2234437Seric char *
224294Seric index(s, c)
225294Seric 	register char *s;
226294Seric 	register char c;
227294Seric {
228294Seric 	while (*s != '\0')
229294Seric 	{
230294Seric 		if (*s++ == c)
231294Seric 			return (--s);
232294Seric 	}
233294Seric 	return (NULL);
234294Seric }
2354326Seric /*
2364326Seric **  UMASK -- fake the umask system call.
2374326Seric **
2384326Seric **	Since V6 always acts like the umask is zero, we will just
2394326Seric **	assume the same thing.
2404326Seric */
2414326Seric 
2424326Seric /*ARGSUSED*/
2434326Seric umask(nmask)
2444326Seric {
2454326Seric 	return (0);
2464326Seric }
2474326Seric 
2484326Seric 
2494326Seric /*
2504326Seric **  GETRUID -- get real user id.
2514326Seric */
2524326Seric 
2534326Seric getruid()
2544326Seric {
2554326Seric 	return (getuid() & 0377);
2564326Seric }
2574326Seric 
2584326Seric 
2594326Seric /*
2604326Seric **  GETRGID -- get real group id.
2614326Seric */
2624326Seric 
2634326Seric getrgid()
2644326Seric {
2654326Seric 	return (getgid() & 0377);
2664326Seric }
2674326Seric 
2684326Seric 
2694326Seric /*
2704326Seric **  GETEUID -- get effective user id.
2714326Seric */
2724326Seric 
2734326Seric geteuid()
2744326Seric {
2754326Seric 	return ((getuid() >> 8) & 0377);
2764326Seric }
2774326Seric 
2784326Seric 
2794326Seric /*
2804326Seric **  GETEGID -- get effective group id.
2814326Seric */
2824326Seric 
2834326Seric getegid()
2844326Seric {
2854326Seric 	return ((getgid() >> 8) & 0377);
2864326Seric }
2874326Seric 
288294Seric # endif V6
2894326Seric 
2904326Seric # ifndef V6
2914326Seric 
2924326Seric /*
2934326Seric **  GETRUID -- get real user id (V7)
2944326Seric */
2954326Seric 
2964326Seric getruid()
2974326Seric {
2984536Seric 	if (Daemon)
2994536Seric 		return (RealUid);
3004536Seric 	else
3014536Seric 		return (getuid());
3024326Seric }
3034326Seric 
3044326Seric 
3054326Seric /*
3064326Seric **  GETRGID -- get real group id (V7).
3074326Seric */
3084326Seric 
3094326Seric getrgid()
3104326Seric {
3114536Seric 	if (Daemon)
3124536Seric 		return (RealGid);
3134536Seric 	else
3144536Seric 		return (getgid());
3154326Seric }
3164326Seric 
3174326Seric # endif V6
3184190Seric /*
3194190Seric **  TTYPATH -- Get the path of the user's tty
320294Seric **
321294Seric **	Returns the pathname of the user's tty.  Returns NULL if
322294Seric **	the user is not logged in or if s/he has write permission
323294Seric **	denied.
324294Seric **
325294Seric **	Parameters:
326294Seric **		none
327294Seric **
328294Seric **	Returns:
329294Seric **		pathname of the user's tty.
330294Seric **		NULL if not logged in or write permission denied.
331294Seric **
332294Seric **	Side Effects:
333294Seric **		none.
334294Seric **
335294Seric **	WARNING:
336294Seric **		Return value is in a local buffer.
337294Seric **
338294Seric **	Called By:
339294Seric **		savemail
340294Seric */
341294Seric 
342294Seric # include <sys/stat.h>
343294Seric 
344294Seric char *
345294Seric ttypath()
346294Seric {
347294Seric 	struct stat stbuf;
348294Seric 	register char *pathn;
349294Seric 	extern char *ttyname();
3504081Seric 	extern char *getlogin();
351294Seric 
352294Seric 	/* compute the pathname of the controlling tty */
353294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
354294Seric 	{
355294Seric 		errno = 0;
356294Seric 		return (NULL);
357294Seric 	}
358294Seric 
359294Seric 	/* see if we have write permission */
3602967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
361294Seric 	{
362294Seric 		errno = 0;
363294Seric 		return (NULL);
364294Seric 	}
365294Seric 
366294Seric 	/* see if the user is logged in */
367294Seric 	if (getlogin() == NULL)
368294Seric 		return (NULL);
369294Seric 
370294Seric 	/* looks good */
371294Seric 	return (pathn);
372294Seric }
3732967Seric /*
3742967Seric **  CHECKCOMPAT -- check for From and To person compatible.
3752967Seric **
3762967Seric **	This routine can be supplied on a per-installation basis
3772967Seric **	to determine whether a person is allowed to send a message.
3782967Seric **	This allows restriction of certain types of internet
3792967Seric **	forwarding or registration of users.
3802967Seric **
3812967Seric **	If the hosts are found to be incompatible, an error
3822967Seric **	message should be given using "usrerr" and FALSE should
3832967Seric **	be returned.
3842967Seric **
3854288Seric **	'NoReturn' can be set to suppress the return-to-sender
3864288Seric **	function; this should be done on huge messages.
3874288Seric **
3882967Seric **	Parameters:
3892967Seric **		to -- the person being sent to.
3902967Seric **
3912967Seric **	Returns:
3922967Seric **		TRUE -- ok to send.
3932967Seric **		FALSE -- not ok.
3942967Seric **
3952967Seric **	Side Effects:
3962967Seric **		none (unless you include the usrerr stuff)
3972967Seric */
3982967Seric 
3992967Seric bool
4002967Seric checkcompat(to)
4012967Seric 	register ADDRESS *to;
4022967Seric {
403*4620Seric # ifdef ING70
4044437Seric 	register STAB *s;
405*4620Seric # endif ING70
4064437Seric 
4074595Seric 	if (to->q_mailer != LocalMailer && MsgSize > 100000)
4084288Seric 	{
4094288Seric 		usrerr("Message exceeds 100000 bytes");
4104288Seric 		NoReturn++;
4114288Seric 		return (FALSE);
4124288Seric 	}
4134437Seric # ifdef ING70
4144437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
4154595Seric 	if (s != NULL && From.q_mailer != LocalMailer && to->q_mailer == s->s_mailer)
4164437Seric 	{
4174437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
4184437Seric 		return (FALSE);
4194437Seric 	}
4204437Seric # endif ING70
4212967Seric 	return (TRUE);
4222967Seric }
423