xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4263)
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*4263Seric static char SccsId[] = "@(#)conf.c	3.25	08/29/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,
58*4263Seric 	"to",			H_ADDR,			0,
59*4263Seric 	"cc",			H_ADDR,			0,
60*4263Seric 	"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
94294Seric 
95294Seric # ifdef V6
96294Seric /*
974190Seric **  TTYNAME -- return name of terminal.
98294Seric **
99294Seric **	Parameters:
1004190Seric **		fd -- file descriptor to check.
101294Seric **
102294Seric **	Returns:
1034190Seric **		pointer to full path of tty.
1044190Seric **		NULL if no tty.
105294Seric **
106294Seric **	Side Effects:
107294Seric **		none.
108294Seric */
109294Seric 
110294Seric char *
1114190Seric ttyname(fd)
1124190Seric 	int fd;
113294Seric {
1144190Seric 	register char tn;
115294Seric 	static char pathn[] = "/dev/ttyx";
116294Seric 
117294Seric 	/* compute the pathname of the controlling tty */
1184190Seric 	if ((tn = ttyn(fd)) == NULL)
119294Seric 	{
120294Seric 		errno = 0;
121294Seric 		return (NULL);
122294Seric 	}
1234190Seric 	pathn[8] = tn;
124294Seric 	return (pathn);
125294Seric }
126294Seric /*
127294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
128294Seric **
129294Seric **	This is included here because it is standard in v7, but we
130294Seric **	need it in v6.
131294Seric **
132294Seric **	Algorithm:
133294Seric **		Open /dev/null to create a descriptor.
134294Seric **		Close that descriptor.
135294Seric **		Copy the existing fd into the descriptor.
136294Seric **
137294Seric **	Parameters:
138294Seric **		fd -- the open file descriptor.
139294Seric **		type -- "r", "w", or whatever.
140294Seric **
141294Seric **	Returns:
142294Seric **		The file descriptor it creates.
143294Seric **
144294Seric **	Side Effects:
145294Seric **		none
146294Seric **
147294Seric **	Called By:
148294Seric **		deliver
149294Seric **
150294Seric **	Notes:
151294Seric **		The mode of fd must match "type".
152294Seric */
153294Seric 
154294Seric FILE *
155294Seric fdopen(fd, type)
156294Seric 	int fd;
157294Seric 	char *type;
158294Seric {
159294Seric 	register FILE *f;
160294Seric 
161294Seric 	f = fopen("/dev/null", type);
1624081Seric 	(void) close(fileno(f));
163294Seric 	fileno(f) = fd;
164294Seric 	return (f);
165294Seric }
166294Seric /*
167294Seric **  INDEX -- Return pointer to character in string
168294Seric **
169294Seric **	For V7 compatibility.
170294Seric **
171294Seric **	Parameters:
172294Seric **		s -- a string to scan.
173294Seric **		c -- a character to look for.
174294Seric **
175294Seric **	Returns:
176294Seric **		If c is in s, returns the address of the first
177294Seric **			instance of c in s.
178294Seric **		NULL if c is not in s.
179294Seric **
180294Seric **	Side Effects:
181294Seric **		none.
182294Seric */
183294Seric 
184294Seric index(s, c)
185294Seric 	register char *s;
186294Seric 	register char c;
187294Seric {
188294Seric 	while (*s != '\0')
189294Seric 	{
190294Seric 		if (*s++ == c)
191294Seric 			return (--s);
192294Seric 	}
193294Seric 	return (NULL);
194294Seric }
195294Seric # endif V6
1964190Seric /*
1974190Seric **  TTYPATH -- Get the path of the user's tty
198294Seric **
199294Seric **	Returns the pathname of the user's tty.  Returns NULL if
200294Seric **	the user is not logged in or if s/he has write permission
201294Seric **	denied.
202294Seric **
203294Seric **	Parameters:
204294Seric **		none
205294Seric **
206294Seric **	Returns:
207294Seric **		pathname of the user's tty.
208294Seric **		NULL if not logged in or write permission denied.
209294Seric **
210294Seric **	Side Effects:
211294Seric **		none.
212294Seric **
213294Seric **	WARNING:
214294Seric **		Return value is in a local buffer.
215294Seric **
216294Seric **	Called By:
217294Seric **		savemail
218294Seric */
219294Seric 
220294Seric # include <sys/stat.h>
221294Seric 
222294Seric char *
223294Seric ttypath()
224294Seric {
225294Seric 	struct stat stbuf;
226294Seric 	register char *pathn;
227294Seric 	extern char *ttyname();
2284081Seric 	extern char *getlogin();
229294Seric 
230294Seric 	/* compute the pathname of the controlling tty */
231294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
232294Seric 	{
233294Seric 		errno = 0;
234294Seric 		return (NULL);
235294Seric 	}
236294Seric 
237294Seric 	/* see if we have write permission */
2382967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
239294Seric 	{
240294Seric 		errno = 0;
241294Seric 		return (NULL);
242294Seric 	}
243294Seric 
244294Seric 	/* see if the user is logged in */
245294Seric 	if (getlogin() == NULL)
246294Seric 		return (NULL);
247294Seric 
248294Seric 	/* looks good */
249294Seric 	return (pathn);
250294Seric }
2512967Seric /*
2522967Seric **  CHECKCOMPAT -- check for From and To person compatible.
2532967Seric **
2542967Seric **	This routine can be supplied on a per-installation basis
2552967Seric **	to determine whether a person is allowed to send a message.
2562967Seric **	This allows restriction of certain types of internet
2572967Seric **	forwarding or registration of users.
2582967Seric **
2592967Seric **	If the hosts are found to be incompatible, an error
2602967Seric **	message should be given using "usrerr" and FALSE should
2612967Seric **	be returned.
2622967Seric **
2632967Seric **	Parameters:
2642967Seric **		to -- the person being sent to.
2652967Seric **
2662967Seric **	Returns:
2672967Seric **		TRUE -- ok to send.
2682967Seric **		FALSE -- not ok.
2692967Seric **
2702967Seric **	Side Effects:
2712967Seric **		none (unless you include the usrerr stuff)
2722967Seric */
2732967Seric 
2742967Seric bool
2752967Seric checkcompat(to)
2762967Seric 	register ADDRESS *to;
2772967Seric {
2784081Seric # ifdef lint
2794081Seric 	ADDRESS *x = to;
2804081Seric 
2814081Seric 	to = x;
2824081Seric # endif lint
2834081Seric 
2842967Seric 	return (TRUE);
2852967Seric }
286