xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4147)
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,
20*4147Seric **			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*4147Seric static char SccsId[] = "@(#)conf.c	3.17	08/17/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.
45*4147Seric **
46*4147Seric **	Not all of these are actually handled specially by sendmail
47*4147Seric **	at this time.  They are included as placeholders, to let
48*4147Seric **	you know that "someday" I intend to have sendmail do
49*4147Seric **	something with them.
502897Seric */
512897Seric 
522897Seric struct hdrinfo	HdrInfo[] =
532897Seric {
54*4147Seric 	"date",			H_CHECK,		M_NEEDDATE,
55*4147Seric 	"from",			H_CHECK,		M_NEEDFROM,
56*4147Seric 	"sender",		0,			0,
57*4147Seric 	"full-name",		H_ACHECK,		M_FULLNAME,
58*4147Seric 	"to",			0,			0,
59*4147Seric 	"cc",			0,			0,
60*4147Seric 	"bcc",			0,			0,
61*4147Seric 	"message-id",		H_CHECK,		M_MSGID,
62*4147Seric 	"message",		H_EOH,			0,
63*4147Seric 	"text",			H_EOH,			0,
64*4147Seric 	"posted-date",		0,			0,
65*4147Seric 	"return-receipt-to",	0,			0,
66*4147Seric 	"received-date",	H_CHECK,		M_FINAL,
67*4147Seric 	"received-from",	H_CHECK,		M_FINAL,
68*4147Seric 	"precedence",		0,			0,
69*4147Seric 	"via",			H_FORCE,		0,
70*4147Seric 	NULL,			0,			0,
712897Seric };
72294Seric 
73294Seric # ifdef V6
74294Seric /*
75294Seric **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
76294Seric **
77294Seric **	Returns the pathname of the user's tty.  Returns NULL if
78294Seric **	the user is not logged in or if s/he has write permission
79294Seric **	denied.
80294Seric **
81294Seric **	Parameters:
82294Seric **		none
83294Seric **
84294Seric **	Returns:
85294Seric **		pathname of the user's tty.
86294Seric **		NULL if not logged in or write permission denied.
87294Seric **
88294Seric **	Side Effects:
89294Seric **		none.
90294Seric **
91294Seric **	WARNING:
92294Seric **		Return value is in a local buffer.
93294Seric **
94294Seric **	Called By:
95294Seric **		savemail
96294Seric */
97294Seric 
98294Seric # include <sys/stat.h>
99294Seric 
100294Seric char *
101294Seric ttypath()
102294Seric {
103294Seric 	struct stat stbuf;
104294Seric 	register int i;
105294Seric 	static char pathn[] = "/dev/ttyx";
106294Seric 
107294Seric 	/* compute the pathname of the controlling tty */
108294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
109294Seric 	{
110294Seric 		errno = 0;
111294Seric 		return (NULL);
112294Seric 	}
113294Seric 	pathn[8] = i;
114294Seric 
115294Seric 	/* see if we have write permission */
1162967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
117294Seric 	{
118294Seric 		errno = 0;
119294Seric 		return (NULL);
120294Seric 	}
121294Seric 
122294Seric 	/* see if the user is logged in */
123294Seric 	if (getlogin() == NULL)
124294Seric 		return (NULL);
125294Seric 
126294Seric 	/* looks good */
127294Seric 	return (pathn);
128294Seric }
129294Seric /*
130294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
131294Seric **
132294Seric **	This is included here because it is standard in v7, but we
133294Seric **	need it in v6.
134294Seric **
135294Seric **	Algorithm:
136294Seric **		Open /dev/null to create a descriptor.
137294Seric **		Close that descriptor.
138294Seric **		Copy the existing fd into the descriptor.
139294Seric **
140294Seric **	Parameters:
141294Seric **		fd -- the open file descriptor.
142294Seric **		type -- "r", "w", or whatever.
143294Seric **
144294Seric **	Returns:
145294Seric **		The file descriptor it creates.
146294Seric **
147294Seric **	Side Effects:
148294Seric **		none
149294Seric **
150294Seric **	Called By:
151294Seric **		deliver
152294Seric **
153294Seric **	Notes:
154294Seric **		The mode of fd must match "type".
155294Seric */
156294Seric 
157294Seric FILE *
158294Seric fdopen(fd, type)
159294Seric 	int fd;
160294Seric 	char *type;
161294Seric {
162294Seric 	register FILE *f;
163294Seric 
164294Seric 	f = fopen("/dev/null", type);
1654081Seric 	(void) close(fileno(f));
166294Seric 	fileno(f) = fd;
167294Seric 	return (f);
168294Seric }
169294Seric /*
170294Seric **  INDEX -- Return pointer to character in string
171294Seric **
172294Seric **	For V7 compatibility.
173294Seric **
174294Seric **	Parameters:
175294Seric **		s -- a string to scan.
176294Seric **		c -- a character to look for.
177294Seric **
178294Seric **	Returns:
179294Seric **		If c is in s, returns the address of the first
180294Seric **			instance of c in s.
181294Seric **		NULL if c is not in s.
182294Seric **
183294Seric **	Side Effects:
184294Seric **		none.
185294Seric */
186294Seric 
187294Seric index(s, c)
188294Seric 	register char *s;
189294Seric 	register char c;
190294Seric {
191294Seric 	while (*s != '\0')
192294Seric 	{
193294Seric 		if (*s++ == c)
194294Seric 			return (--s);
195294Seric 	}
196294Seric 	return (NULL);
197294Seric }
198294Seric # endif V6
199294Seric 
200294Seric # ifndef V6
201294Seric /*
202294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
203294Seric **
204294Seric **	Returns the pathname of the user's tty.  Returns NULL if
205294Seric **	the user is not logged in or if s/he has write permission
206294Seric **	denied.
207294Seric **
208294Seric **	Parameters:
209294Seric **		none
210294Seric **
211294Seric **	Returns:
212294Seric **		pathname of the user's tty.
213294Seric **		NULL if not logged in or write permission denied.
214294Seric **
215294Seric **	Side Effects:
216294Seric **		none.
217294Seric **
218294Seric **	WARNING:
219294Seric **		Return value is in a local buffer.
220294Seric **
221294Seric **	Called By:
222294Seric **		savemail
223294Seric */
224294Seric 
225294Seric # include <sys/stat.h>
226294Seric 
227294Seric char *
228294Seric ttypath()
229294Seric {
230294Seric 	struct stat stbuf;
231294Seric 	register char *pathn;
232294Seric 	extern char *ttyname();
2334081Seric 	extern char *getlogin();
234294Seric 
235294Seric 	/* compute the pathname of the controlling tty */
236294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
237294Seric 	{
238294Seric 		errno = 0;
239294Seric 		return (NULL);
240294Seric 	}
241294Seric 
242294Seric 	/* see if we have write permission */
2432967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
244294Seric 	{
245294Seric 		errno = 0;
246294Seric 		return (NULL);
247294Seric 	}
248294Seric 
249294Seric 	/* see if the user is logged in */
250294Seric 	if (getlogin() == NULL)
251294Seric 		return (NULL);
252294Seric 
253294Seric 	/* looks good */
254294Seric 	return (pathn);
255294Seric }
256294Seric # endif V6
2572967Seric /*
2582967Seric **  CHECKCOMPAT -- check for From and To person compatible.
2592967Seric **
2602967Seric **	This routine can be supplied on a per-installation basis
2612967Seric **	to determine whether a person is allowed to send a message.
2622967Seric **	This allows restriction of certain types of internet
2632967Seric **	forwarding or registration of users.
2642967Seric **
2652967Seric **	If the hosts are found to be incompatible, an error
2662967Seric **	message should be given using "usrerr" and FALSE should
2672967Seric **	be returned.
2682967Seric **
2692967Seric **	Parameters:
2702967Seric **		to -- the person being sent to.
2712967Seric **
2722967Seric **	Returns:
2732967Seric **		TRUE -- ok to send.
2742967Seric **		FALSE -- not ok.
2752967Seric **
2762967Seric **	Side Effects:
2772967Seric **		none (unless you include the usrerr stuff)
2782967Seric */
2792967Seric 
2802967Seric bool
2812967Seric checkcompat(to)
2822967Seric 	register ADDRESS *to;
2832967Seric {
2844081Seric # ifdef lint
2854081Seric 	ADDRESS *x = to;
2864081Seric 
2874081Seric 	to = x;
2884081Seric # endif lint
2894081Seric 
2902967Seric 	return (TRUE);
2912967Seric }
292