xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 12133)
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*12133Seric SCCSID(@(#)conf.c	3.71		04/30/83);
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  */
5211417Seric 	"resent-sender",	H_FROM|H_RESENT,
5311417Seric 	"resent-from",		H_FROM|H_RESENT,
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,
6111417Seric 	"resent-to",		H_RCPT|H_RESENT,
629055Seric 	"cc",			H_RCPT,
6311417Seric 	"resent-cc",		H_RCPT|H_RESENT,
649055Seric 	"bcc",			H_RCPT|H_ACHECK,
6511417Seric 	"resent-bcc",		H_RCPT|H_ACHECK|H_RESENT,
668060Seric 		/* message identification and control */
6711417Seric 	"message-id",		0,
6811417Seric 	"resent-message-id",	H_RESENT,
699055Seric 	"message",		H_EOH,
709055Seric 	"text",			H_EOH,
7111417Seric 		/* date fields */
7211417Seric 	"date",			0,
7311417Seric 	"resent-date",		H_RESENT,
748060Seric 		/* trace fields */
759055Seric 	"received",		H_TRACE|H_FORCE,
769055Seric 	"via",			H_TRACE|H_FORCE,
779055Seric 	"mail-from",		H_TRACE|H_FORCE,
788060Seric 
799055Seric 	NULL,			0,
802897Seric };
814166Seric 
824166Seric 
834166Seric /*
844166Seric **  ARPANET error message numbers.
854166Seric */
864166Seric 
877956Seric char	Arpa_Info[] =		"050";	/* arbitrary info */
887956Seric char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
897956Seric char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
907956Seric char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
914282Seric 
924282Seric 
934282Seric 
944282Seric /*
954282Seric **  Location of system files/databases/etc.
964282Seric */
974282Seric 
984282Seric char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
999064Seric char	*FreezeFile =	"/usr/lib/sendmail.fc";	/* frozen version of above */
1009039Seric 
1019064Seric 
1029064Seric 
1039039Seric /*
1049039Seric **  Some other configuration....
1059039Seric */
1069039Seric 
1079039Seric char	SpaceSub =	'.';
108294Seric 
109294Seric # ifdef V6
110294Seric /*
1114190Seric **  TTYNAME -- return name of terminal.
112294Seric **
113294Seric **	Parameters:
1144190Seric **		fd -- file descriptor to check.
115294Seric **
116294Seric **	Returns:
1174190Seric **		pointer to full path of tty.
1184190Seric **		NULL if no tty.
119294Seric **
120294Seric **	Side Effects:
121294Seric **		none.
122294Seric */
123294Seric 
124294Seric char *
1254190Seric ttyname(fd)
1264190Seric 	int fd;
127294Seric {
1284190Seric 	register char tn;
129294Seric 	static char pathn[] = "/dev/ttyx";
130294Seric 
131294Seric 	/* compute the pathname of the controlling tty */
1324190Seric 	if ((tn = ttyn(fd)) == NULL)
133294Seric 	{
134294Seric 		errno = 0;
135294Seric 		return (NULL);
136294Seric 	}
1374190Seric 	pathn[8] = tn;
138294Seric 	return (pathn);
139294Seric }
140294Seric /*
141294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
142294Seric **
143294Seric **	This is included here because it is standard in v7, but we
144294Seric **	need it in v6.
145294Seric **
146294Seric **	Algorithm:
147294Seric **		Open /dev/null to create a descriptor.
148294Seric **		Close that descriptor.
149294Seric **		Copy the existing fd into the descriptor.
150294Seric **
151294Seric **	Parameters:
152294Seric **		fd -- the open file descriptor.
153294Seric **		type -- "r", "w", or whatever.
154294Seric **
155294Seric **	Returns:
156294Seric **		The file descriptor it creates.
157294Seric **
158294Seric **	Side Effects:
159294Seric **		none
160294Seric **
161294Seric **	Called By:
162294Seric **		deliver
163294Seric **
164294Seric **	Notes:
165294Seric **		The mode of fd must match "type".
166294Seric */
167294Seric 
168294Seric FILE *
169294Seric fdopen(fd, type)
170294Seric 	int fd;
171294Seric 	char *type;
172294Seric {
173294Seric 	register FILE *f;
174294Seric 
175294Seric 	f = fopen("/dev/null", type);
1764081Seric 	(void) close(fileno(f));
177294Seric 	fileno(f) = fd;
178294Seric 	return (f);
179294Seric }
180294Seric /*
181294Seric **  INDEX -- Return pointer to character in string
182294Seric **
183294Seric **	For V7 compatibility.
184294Seric **
185294Seric **	Parameters:
186294Seric **		s -- a string to scan.
187294Seric **		c -- a character to look for.
188294Seric **
189294Seric **	Returns:
190294Seric **		If c is in s, returns the address of the first
191294Seric **			instance of c in s.
192294Seric **		NULL if c is not in s.
193294Seric **
194294Seric **	Side Effects:
195294Seric **		none.
196294Seric */
197294Seric 
1984437Seric char *
199294Seric index(s, c)
200294Seric 	register char *s;
201294Seric 	register char c;
202294Seric {
203294Seric 	while (*s != '\0')
204294Seric 	{
205294Seric 		if (*s++ == c)
206294Seric 			return (--s);
207294Seric 	}
208294Seric 	return (NULL);
209294Seric }
2104326Seric /*
2114326Seric **  UMASK -- fake the umask system call.
2124326Seric **
2134326Seric **	Since V6 always acts like the umask is zero, we will just
2144326Seric **	assume the same thing.
2154326Seric */
2164326Seric 
2174326Seric /*ARGSUSED*/
2184326Seric umask(nmask)
2194326Seric {
2204326Seric 	return (0);
2214326Seric }
2224326Seric 
2234326Seric 
2244326Seric /*
2254326Seric **  GETRUID -- get real user id.
2264326Seric */
2274326Seric 
2284326Seric getruid()
2294326Seric {
2304326Seric 	return (getuid() & 0377);
2314326Seric }
2324326Seric 
2334326Seric 
2344326Seric /*
2354326Seric **  GETRGID -- get real group id.
2364326Seric */
2374326Seric 
2384326Seric getrgid()
2394326Seric {
2404326Seric 	return (getgid() & 0377);
2414326Seric }
2424326Seric 
2434326Seric 
2444326Seric /*
2454326Seric **  GETEUID -- get effective user id.
2464326Seric */
2474326Seric 
2484326Seric geteuid()
2494326Seric {
2504326Seric 	return ((getuid() >> 8) & 0377);
2514326Seric }
2524326Seric 
2534326Seric 
2544326Seric /*
2554326Seric **  GETEGID -- get effective group id.
2564326Seric */
2574326Seric 
2584326Seric getegid()
2594326Seric {
2604326Seric 	return ((getgid() >> 8) & 0377);
2614326Seric }
2624326Seric 
263294Seric # endif V6
2644326Seric 
2654326Seric # ifndef V6
2664326Seric 
2674326Seric /*
2684326Seric **  GETRUID -- get real user id (V7)
2694326Seric */
2704326Seric 
2714326Seric getruid()
2724326Seric {
2739274Seric 	if (OpMode == MD_DAEMON)
2744536Seric 		return (RealUid);
2754536Seric 	else
2764536Seric 		return (getuid());
2774326Seric }
2784326Seric 
2794326Seric 
2804326Seric /*
2814326Seric **  GETRGID -- get real group id (V7).
2824326Seric */
2834326Seric 
2844326Seric getrgid()
2854326Seric {
2869274Seric 	if (OpMode == MD_DAEMON)
2874536Seric 		return (RealGid);
2884536Seric 	else
2894536Seric 		return (getgid());
2904326Seric }
2914326Seric 
2924326Seric # endif V6
2934190Seric /*
2949369Seric **  USERNAME -- return the user id of the logged in user.
2959369Seric **
2969369Seric **	Parameters:
2979369Seric **		none.
2989369Seric **
2999369Seric **	Returns:
3009369Seric **		The login name of the logged in user.
3019369Seric **
3029369Seric **	Side Effects:
3039369Seric **		none.
3049369Seric **
3059369Seric **	Notes:
3069369Seric **		The return value is statically allocated.
3079369Seric */
3089369Seric 
3099369Seric char *
3109369Seric username()
3119369Seric {
3129369Seric 	extern char *getlogin();
3139369Seric 
3149369Seric 	return (getlogin());
3159369Seric }
3169369Seric /*
3174190Seric **  TTYPATH -- Get the path of the user's tty
318294Seric **
319294Seric **	Returns the pathname of the user's tty.  Returns NULL if
320294Seric **	the user is not logged in or if s/he has write permission
321294Seric **	denied.
322294Seric **
323294Seric **	Parameters:
324294Seric **		none
325294Seric **
326294Seric **	Returns:
327294Seric **		pathname of the user's tty.
328294Seric **		NULL if not logged in or write permission denied.
329294Seric **
330294Seric **	Side Effects:
331294Seric **		none.
332294Seric **
333294Seric **	WARNING:
334294Seric **		Return value is in a local buffer.
335294Seric **
336294Seric **	Called By:
337294Seric **		savemail
338294Seric */
339294Seric 
340294Seric # include <sys/stat.h>
341294Seric 
342294Seric char *
343294Seric ttypath()
344294Seric {
345294Seric 	struct stat stbuf;
346294Seric 	register char *pathn;
347294Seric 	extern char *ttyname();
3484081Seric 	extern char *getlogin();
349294Seric 
350294Seric 	/* compute the pathname of the controlling tty */
3519369Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
3529369Seric 	    (pathn = ttyname(0)) == NULL)
353294Seric 	{
354294Seric 		errno = 0;
355294Seric 		return (NULL);
356294Seric 	}
357294Seric 
358294Seric 	/* see if we have write permission */
3592967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
360294Seric 	{
361294Seric 		errno = 0;
362294Seric 		return (NULL);
363294Seric 	}
364294Seric 
365294Seric 	/* see if the user is logged in */
366294Seric 	if (getlogin() == NULL)
367294Seric 		return (NULL);
368294Seric 
369294Seric 	/* looks good */
370294Seric 	return (pathn);
371294Seric }
3722967Seric /*
3732967Seric **  CHECKCOMPAT -- check for From and To person compatible.
3742967Seric **
3752967Seric **	This routine can be supplied on a per-installation basis
3762967Seric **	to determine whether a person is allowed to send a message.
3772967Seric **	This allows restriction of certain types of internet
3782967Seric **	forwarding or registration of users.
3792967Seric **
3802967Seric **	If the hosts are found to be incompatible, an error
3812967Seric **	message should be given using "usrerr" and FALSE should
3822967Seric **	be returned.
3832967Seric **
3844288Seric **	'NoReturn' can be set to suppress the return-to-sender
3854288Seric **	function; this should be done on huge messages.
3864288Seric **
3872967Seric **	Parameters:
3882967Seric **		to -- the person being sent to.
3892967Seric **
3902967Seric **	Returns:
3912967Seric **		TRUE -- ok to send.
3922967Seric **		FALSE -- not ok.
3932967Seric **
3942967Seric **	Side Effects:
3952967Seric **		none (unless you include the usrerr stuff)
3962967Seric */
3972967Seric 
3982967Seric bool
3992967Seric checkcompat(to)
4002967Seric 	register ADDRESS *to;
4012967Seric {
402*12133Seric # ifdef lint
403*12133Seric 	if (to == NULL)
404*12133Seric 		to++;
405*12133Seric # endif lint
40610698Seric # ifdef EXAMPLE_CODE
40710698Seric 	/* this code is intended as an example only */
4084437Seric 	register STAB *s;
4094437Seric 
4104437Seric 	s = stab("arpa", ST_MAILER, ST_FIND);
4119369Seric 	if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer &&
4129369Seric 	    to->q_mailer == s->s_mailer)
4134437Seric 	{
4144437Seric 		usrerr("No ARPA mail through this machine: see your system administration");
41510698Seric 		/* NoReturn = TRUE; to supress return copy */
4164437Seric 		return (FALSE);
4174437Seric 	}
41810698Seric # endif EXAMPLE_CODE
4192967Seric 	return (TRUE);
4202967Seric }
4219369Seric /*
4229369Seric **  HOLDSIGS -- arrange to hold all signals
4239369Seric **
4249369Seric **	Parameters:
4259369Seric **		none.
4269369Seric **
4279369Seric **	Returns:
4289369Seric **		none.
4299369Seric **
4309369Seric **	Side Effects:
4319369Seric **		Arranges that signals are held.
4329369Seric */
4339369Seric 
4349369Seric holdsigs()
4359369Seric {
4369369Seric }
4379369Seric /*
4389369Seric **  RLSESIGS -- arrange to release all signals
4399369Seric **
4409369Seric **	This undoes the effect of holdsigs.
4419369Seric **
4429369Seric **	Parameters:
4439369Seric **		none.
4449369Seric **
4459369Seric **	Returns:
4469369Seric **		none.
4479369Seric **
4489369Seric **	Side Effects:
4499369Seric **		Arranges that signals are released.
4509369Seric */
4519369Seric 
4529369Seric rlsesigs()
4539369Seric {
4549369Seric }
455