xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4166)
1294Seric # include <stdio.h>
2294Seric # include <pwd.h>
33309Seric # include "sendmail.h"
4404Seric 
5294Seric /*
63309Seric **  CONF.C -- Sendmail Configuration Tables.
7294Seric **
8294Seric **	Defines the configuration of this installation.
9294Seric **
101388Seric **	Compilation Flags:
111388Seric **		V6 -- running on a version 6 system.  This determines
121388Seric **			whether to define certain routines between
131388Seric **			the two systems.  If you are running a funny
141388Seric **			system, e.g., V6 with long tty names, this
151388Seric **			should be checked carefully.
16294Seric **
171388Seric **	Configuration Variables:
182897Seric **		HdrInfo -- a table describing well-known header fields.
192897Seric **			Each entry has the field name and some flags,
204147Seric **			which are described in sendmail.h.
214093Seric **
224093Seric **	Notes:
234093Seric **		I have tried to put almost all the reasonable
244093Seric **		configuration information into the configuration
254093Seric **		file read at runtime.  My intent is that anything
264093Seric **		here is a function of the version of UNIX you
274093Seric **		are running, or is really static -- for example
284093Seric **		the headers are a superset of widely used
294093Seric **		protocols.  If you find yourself playing with
304093Seric **		this file too much, you may be making a mistake!
31294Seric */
32294Seric 
33294Seric 
34294Seric 
35294Seric 
36*4166Seric static char SccsId[] = "@(#)conf.c	3.18	08/18/81";
37294Seric 
381388Seric 
391388Seric # include <whoami.h>		/* definitions of machine id's at berkeley */
401388Seric 
413061Seric 
422897Seric /*
432897Seric **  Header info table
443057Seric **	Final (null) entry contains the flags used for any other field.
454147Seric **
464147Seric **	Not all of these are actually handled specially by sendmail
474147Seric **	at this time.  They are included as placeholders, to let
484147Seric **	you know that "someday" I intend to have sendmail do
494147Seric **	something with them.
502897Seric */
512897Seric 
522897Seric struct hdrinfo	HdrInfo[] =
532897Seric {
544147Seric 	"date",			H_CHECK,		M_NEEDDATE,
554147Seric 	"from",			H_CHECK,		M_NEEDFROM,
564147Seric 	"sender",		0,			0,
574147Seric 	"full-name",		H_ACHECK,		M_FULLNAME,
584147Seric 	"to",			0,			0,
594147Seric 	"cc",			0,			0,
604147Seric 	"bcc",			0,			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,
664147Seric 	"received-date",	H_CHECK,		M_FINAL,
674147Seric 	"received-from",	H_CHECK,		M_FINAL,
684147Seric 	"precedence",		0,			0,
694147Seric 	"via",			H_FORCE,		0,
704147Seric 	NULL,			0,			0,
712897Seric };
72*4166Seric 
73*4166Seric 
74*4166Seric /*
75*4166Seric **  ARPANET error message numbers.
76*4166Seric */
77*4166Seric 
78*4166Seric # ifdef NEWFTP
79*4166Seric /* these are almost all unchecked */
80*4166Seric char	Arpa_Info[] =	"010";	/* arbitrary info: this is WRONG! */
81*4166Seric char	Arpa_Enter[] =	"354";	/* start mail input */
82*4166Seric char	Arpa_Mmsg[] =	"250";	/* mail successful (MAIL cmd) */
83*4166Seric char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
84*4166Seric char	Arpa_Syserr[] =	"450";	/* some (transient) system error */
85*4166Seric char	Arpa_Usrerr[] =	"550";	/* some (fatal) user error */
86*4166Seric # else NEWFTP
87*4166Seric char	Arpa_Info[] =	"050";	/* arbitrary info */
88*4166Seric char	Arpa_Enter[] =	"350";	/* start mail input */
89*4166Seric char	Arpa_Mmsg[] =	"256";	/* mail successful (MAIL cmd) */
90*4166Seric char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
91*4166Seric char	Arpa_Syserr[] =	"455";	/* some (transient) system error */
92*4166Seric char	Arpa_Usrerr[] =	"450";	/* some (fatal) user error */
93*4166Seric # endif NEWFTP
94294Seric 
95294Seric # ifdef V6
96294Seric /*
97294Seric **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
98294Seric **
99294Seric **	Returns the pathname of the user's tty.  Returns NULL if
100294Seric **	the user is not logged in or if s/he has write permission
101294Seric **	denied.
102294Seric **
103294Seric **	Parameters:
104294Seric **		none
105294Seric **
106294Seric **	Returns:
107294Seric **		pathname of the user's tty.
108294Seric **		NULL if not logged in or write permission denied.
109294Seric **
110294Seric **	Side Effects:
111294Seric **		none.
112294Seric **
113294Seric **	WARNING:
114294Seric **		Return value is in a local buffer.
115294Seric **
116294Seric **	Called By:
117294Seric **		savemail
118294Seric */
119294Seric 
120294Seric # include <sys/stat.h>
121294Seric 
122294Seric char *
123294Seric ttypath()
124294Seric {
125294Seric 	struct stat stbuf;
126294Seric 	register int i;
127294Seric 	static char pathn[] = "/dev/ttyx";
128294Seric 
129294Seric 	/* compute the pathname of the controlling tty */
130294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
131294Seric 	{
132294Seric 		errno = 0;
133294Seric 		return (NULL);
134294Seric 	}
135294Seric 	pathn[8] = i;
136294Seric 
137294Seric 	/* see if we have write permission */
1382967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
139294Seric 	{
140294Seric 		errno = 0;
141294Seric 		return (NULL);
142294Seric 	}
143294Seric 
144294Seric 	/* see if the user is logged in */
145294Seric 	if (getlogin() == NULL)
146294Seric 		return (NULL);
147294Seric 
148294Seric 	/* looks good */
149294Seric 	return (pathn);
150294Seric }
151294Seric /*
152294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
153294Seric **
154294Seric **	This is included here because it is standard in v7, but we
155294Seric **	need it in v6.
156294Seric **
157294Seric **	Algorithm:
158294Seric **		Open /dev/null to create a descriptor.
159294Seric **		Close that descriptor.
160294Seric **		Copy the existing fd into the descriptor.
161294Seric **
162294Seric **	Parameters:
163294Seric **		fd -- the open file descriptor.
164294Seric **		type -- "r", "w", or whatever.
165294Seric **
166294Seric **	Returns:
167294Seric **		The file descriptor it creates.
168294Seric **
169294Seric **	Side Effects:
170294Seric **		none
171294Seric **
172294Seric **	Called By:
173294Seric **		deliver
174294Seric **
175294Seric **	Notes:
176294Seric **		The mode of fd must match "type".
177294Seric */
178294Seric 
179294Seric FILE *
180294Seric fdopen(fd, type)
181294Seric 	int fd;
182294Seric 	char *type;
183294Seric {
184294Seric 	register FILE *f;
185294Seric 
186294Seric 	f = fopen("/dev/null", type);
1874081Seric 	(void) close(fileno(f));
188294Seric 	fileno(f) = fd;
189294Seric 	return (f);
190294Seric }
191294Seric /*
192294Seric **  INDEX -- Return pointer to character in string
193294Seric **
194294Seric **	For V7 compatibility.
195294Seric **
196294Seric **	Parameters:
197294Seric **		s -- a string to scan.
198294Seric **		c -- a character to look for.
199294Seric **
200294Seric **	Returns:
201294Seric **		If c is in s, returns the address of the first
202294Seric **			instance of c in s.
203294Seric **		NULL if c is not in s.
204294Seric **
205294Seric **	Side Effects:
206294Seric **		none.
207294Seric */
208294Seric 
209294Seric index(s, c)
210294Seric 	register char *s;
211294Seric 	register char c;
212294Seric {
213294Seric 	while (*s != '\0')
214294Seric 	{
215294Seric 		if (*s++ == c)
216294Seric 			return (--s);
217294Seric 	}
218294Seric 	return (NULL);
219294Seric }
220294Seric # endif V6
221294Seric 
222294Seric # ifndef V6
223294Seric /*
224294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
225294Seric **
226294Seric **	Returns the pathname of the user's tty.  Returns NULL if
227294Seric **	the user is not logged in or if s/he has write permission
228294Seric **	denied.
229294Seric **
230294Seric **	Parameters:
231294Seric **		none
232294Seric **
233294Seric **	Returns:
234294Seric **		pathname of the user's tty.
235294Seric **		NULL if not logged in or write permission denied.
236294Seric **
237294Seric **	Side Effects:
238294Seric **		none.
239294Seric **
240294Seric **	WARNING:
241294Seric **		Return value is in a local buffer.
242294Seric **
243294Seric **	Called By:
244294Seric **		savemail
245294Seric */
246294Seric 
247294Seric # include <sys/stat.h>
248294Seric 
249294Seric char *
250294Seric ttypath()
251294Seric {
252294Seric 	struct stat stbuf;
253294Seric 	register char *pathn;
254294Seric 	extern char *ttyname();
2554081Seric 	extern char *getlogin();
256294Seric 
257294Seric 	/* compute the pathname of the controlling tty */
258294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
259294Seric 	{
260294Seric 		errno = 0;
261294Seric 		return (NULL);
262294Seric 	}
263294Seric 
264294Seric 	/* see if we have write permission */
2652967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
266294Seric 	{
267294Seric 		errno = 0;
268294Seric 		return (NULL);
269294Seric 	}
270294Seric 
271294Seric 	/* see if the user is logged in */
272294Seric 	if (getlogin() == NULL)
273294Seric 		return (NULL);
274294Seric 
275294Seric 	/* looks good */
276294Seric 	return (pathn);
277294Seric }
278294Seric # endif V6
2792967Seric /*
2802967Seric **  CHECKCOMPAT -- check for From and To person compatible.
2812967Seric **
2822967Seric **	This routine can be supplied on a per-installation basis
2832967Seric **	to determine whether a person is allowed to send a message.
2842967Seric **	This allows restriction of certain types of internet
2852967Seric **	forwarding or registration of users.
2862967Seric **
2872967Seric **	If the hosts are found to be incompatible, an error
2882967Seric **	message should be given using "usrerr" and FALSE should
2892967Seric **	be returned.
2902967Seric **
2912967Seric **	Parameters:
2922967Seric **		to -- the person being sent to.
2932967Seric **
2942967Seric **	Returns:
2952967Seric **		TRUE -- ok to send.
2962967Seric **		FALSE -- not ok.
2972967Seric **
2982967Seric **	Side Effects:
2992967Seric **		none (unless you include the usrerr stuff)
3002967Seric */
3012967Seric 
3022967Seric bool
3032967Seric checkcompat(to)
3042967Seric 	register ADDRESS *to;
3052967Seric {
3064081Seric # ifdef lint
3074081Seric 	ADDRESS *x = to;
3084081Seric 
3094081Seric 	to = x;
3104081Seric # endif lint
3114081Seric 
3122967Seric 	return (TRUE);
3132967Seric }
314