xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4288)
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*4288Seric static char SccsId[] = "@(#)conf.c	3.27	09/01/81";
36294Seric 
371388Seric 
381388Seric # include <whoami.h>		/* definitions of machine id's at berkeley */
391388Seric 
403061Seric 
412897Seric /*
422897Seric **  Header info table
433057Seric **	Final (null) entry contains the flags used for any other field.
444147Seric **
454147Seric **	Not all of these are actually handled specially by sendmail
464147Seric **	at this time.  They are included as placeholders, to let
474147Seric **	you know that "someday" I intend to have sendmail do
484147Seric **	something with them.
492897Seric */
502897Seric 
512897Seric struct hdrinfo	HdrInfo[] =
522897Seric {
534147Seric 	"date",			H_CHECK,		M_NEEDDATE,
544147Seric 	"from",			H_CHECK,		M_NEEDFROM,
554262Seric 	"original-from",	H_ACHECK,		0,		/* internal */
564147Seric 	"sender",		0,			0,
574147Seric 	"full-name",		H_ACHECK,		M_FULLNAME,
584263Seric 	"to",			H_ADDR,			0,
594263Seric 	"cc",			H_ADDR,			0,
604263Seric 	"bcc",			H_ADDR|H_ACHECK,	0,
614147Seric 	"message-id",		H_CHECK,		M_MSGID,
624147Seric 	"message",		H_EOH,			0,
634147Seric 	"text",			H_EOH,			0,
644147Seric 	"posted-date",		0,			0,
654147Seric 	"return-receipt-to",	0,			0,
664193Seric 	"received-date",	H_CHECK,		M_LOCAL,
674193Seric 	"received-from",	H_CHECK,		M_LOCAL,
684147Seric 	"precedence",		0,			0,
694147Seric 	"via",			H_FORCE,		0,
704147Seric 	NULL,			0,			0,
712897Seric };
724166Seric 
734166Seric 
744166Seric /*
754166Seric **  ARPANET error message numbers.
764166Seric */
774166Seric 
784166Seric # ifdef NEWFTP
794166Seric /* these are almost all unchecked */
804166Seric char	Arpa_Info[] =	"010";	/* arbitrary info: this is WRONG! */
814166Seric char	Arpa_Enter[] =	"354";	/* start mail input */
824166Seric char	Arpa_Mmsg[] =	"250";	/* mail successful (MAIL cmd) */
834166Seric char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
844166Seric char	Arpa_Syserr[] =	"450";	/* some (transient) system error */
854166Seric char	Arpa_Usrerr[] =	"550";	/* some (fatal) user error */
864166Seric # else NEWFTP
874166Seric char	Arpa_Info[] =	"050";	/* arbitrary info */
884166Seric char	Arpa_Enter[] =	"350";	/* start mail input */
894166Seric char	Arpa_Mmsg[] =	"256";	/* mail successful (MAIL cmd) */
904166Seric char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
914166Seric char	Arpa_Syserr[] =	"455";	/* some (transient) system error */
924166Seric char	Arpa_Usrerr[] =	"450";	/* some (fatal) user error */
934166Seric # endif NEWFTP
944282Seric 
954282Seric 
964282Seric 
974282Seric 
984282Seric 
994282Seric /*
1004282Seric **  Location of system files/databases/etc.
1014282Seric */
1024282Seric 
1034282Seric char	*AliasFile =	"/usr/lib/aliases";	/* alias file */
1044282Seric char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
1054282Seric char	*StatFile =	"/usr/eric/mailstats";	/* statistics summary */
106294Seric 
107294Seric # ifdef V6
108294Seric /*
1094190Seric **  TTYNAME -- return name of terminal.
110294Seric **
111294Seric **	Parameters:
1124190Seric **		fd -- file descriptor to check.
113294Seric **
114294Seric **	Returns:
1154190Seric **		pointer to full path of tty.
1164190Seric **		NULL if no tty.
117294Seric **
118294Seric **	Side Effects:
119294Seric **		none.
120294Seric */
121294Seric 
122294Seric char *
1234190Seric ttyname(fd)
1244190Seric 	int fd;
125294Seric {
1264190Seric 	register char tn;
127294Seric 	static char pathn[] = "/dev/ttyx";
128294Seric 
129294Seric 	/* compute the pathname of the controlling tty */
1304190Seric 	if ((tn = ttyn(fd)) == NULL)
131294Seric 	{
132294Seric 		errno = 0;
133294Seric 		return (NULL);
134294Seric 	}
1354190Seric 	pathn[8] = tn;
136294Seric 	return (pathn);
137294Seric }
138294Seric /*
139294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
140294Seric **
141294Seric **	This is included here because it is standard in v7, but we
142294Seric **	need it in v6.
143294Seric **
144294Seric **	Algorithm:
145294Seric **		Open /dev/null to create a descriptor.
146294Seric **		Close that descriptor.
147294Seric **		Copy the existing fd into the descriptor.
148294Seric **
149294Seric **	Parameters:
150294Seric **		fd -- the open file descriptor.
151294Seric **		type -- "r", "w", or whatever.
152294Seric **
153294Seric **	Returns:
154294Seric **		The file descriptor it creates.
155294Seric **
156294Seric **	Side Effects:
157294Seric **		none
158294Seric **
159294Seric **	Called By:
160294Seric **		deliver
161294Seric **
162294Seric **	Notes:
163294Seric **		The mode of fd must match "type".
164294Seric */
165294Seric 
166294Seric FILE *
167294Seric fdopen(fd, type)
168294Seric 	int fd;
169294Seric 	char *type;
170294Seric {
171294Seric 	register FILE *f;
172294Seric 
173294Seric 	f = fopen("/dev/null", type);
1744081Seric 	(void) close(fileno(f));
175294Seric 	fileno(f) = fd;
176294Seric 	return (f);
177294Seric }
178294Seric /*
179294Seric **  INDEX -- Return pointer to character in string
180294Seric **
181294Seric **	For V7 compatibility.
182294Seric **
183294Seric **	Parameters:
184294Seric **		s -- a string to scan.
185294Seric **		c -- a character to look for.
186294Seric **
187294Seric **	Returns:
188294Seric **		If c is in s, returns the address of the first
189294Seric **			instance of c in s.
190294Seric **		NULL if c is not in s.
191294Seric **
192294Seric **	Side Effects:
193294Seric **		none.
194294Seric */
195294Seric 
196294Seric index(s, c)
197294Seric 	register char *s;
198294Seric 	register char c;
199294Seric {
200294Seric 	while (*s != '\0')
201294Seric 	{
202294Seric 		if (*s++ == c)
203294Seric 			return (--s);
204294Seric 	}
205294Seric 	return (NULL);
206294Seric }
207294Seric # endif V6
2084190Seric /*
2094190Seric **  TTYPATH -- Get the path of the user's tty
210294Seric **
211294Seric **	Returns the pathname of the user's tty.  Returns NULL if
212294Seric **	the user is not logged in or if s/he has write permission
213294Seric **	denied.
214294Seric **
215294Seric **	Parameters:
216294Seric **		none
217294Seric **
218294Seric **	Returns:
219294Seric **		pathname of the user's tty.
220294Seric **		NULL if not logged in or write permission denied.
221294Seric **
222294Seric **	Side Effects:
223294Seric **		none.
224294Seric **
225294Seric **	WARNING:
226294Seric **		Return value is in a local buffer.
227294Seric **
228294Seric **	Called By:
229294Seric **		savemail
230294Seric */
231294Seric 
232294Seric # include <sys/stat.h>
233294Seric 
234294Seric char *
235294Seric ttypath()
236294Seric {
237294Seric 	struct stat stbuf;
238294Seric 	register char *pathn;
239294Seric 	extern char *ttyname();
2404081Seric 	extern char *getlogin();
241294Seric 
242294Seric 	/* compute the pathname of the controlling tty */
243294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
244294Seric 	{
245294Seric 		errno = 0;
246294Seric 		return (NULL);
247294Seric 	}
248294Seric 
249294Seric 	/* see if we have write permission */
2502967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
251294Seric 	{
252294Seric 		errno = 0;
253294Seric 		return (NULL);
254294Seric 	}
255294Seric 
256294Seric 	/* see if the user is logged in */
257294Seric 	if (getlogin() == NULL)
258294Seric 		return (NULL);
259294Seric 
260294Seric 	/* looks good */
261294Seric 	return (pathn);
262294Seric }
2632967Seric /*
2642967Seric **  CHECKCOMPAT -- check for From and To person compatible.
2652967Seric **
2662967Seric **	This routine can be supplied on a per-installation basis
2672967Seric **	to determine whether a person is allowed to send a message.
2682967Seric **	This allows restriction of certain types of internet
2692967Seric **	forwarding or registration of users.
2702967Seric **
2712967Seric **	If the hosts are found to be incompatible, an error
2722967Seric **	message should be given using "usrerr" and FALSE should
2732967Seric **	be returned.
2742967Seric **
275*4288Seric **	'NoReturn' can be set to suppress the return-to-sender
276*4288Seric **	function; this should be done on huge messages.
277*4288Seric **
2782967Seric **	Parameters:
2792967Seric **		to -- the person being sent to.
2802967Seric **
2812967Seric **	Returns:
2822967Seric **		TRUE -- ok to send.
2832967Seric **		FALSE -- not ok.
2842967Seric **
2852967Seric **	Side Effects:
2862967Seric **		none (unless you include the usrerr stuff)
2872967Seric */
2882967Seric 
2892967Seric bool
2902967Seric checkcompat(to)
2912967Seric 	register ADDRESS *to;
2922967Seric {
293*4288Seric 	if (to->q_mailer != MN_LOCAL && MsgSize > 100000)
294*4288Seric 	{
295*4288Seric 		usrerr("Message exceeds 100000 bytes");
296*4288Seric 		NoReturn++;
297*4288Seric 		return (FALSE);
298*4288Seric 	}
2992967Seric 	return (TRUE);
3002967Seric }
301