xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4093)
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,
202897Seric **			which can be:
213057Seric **			- H_EOH -- this field is equivalent to a blank
223057Seric **			  line; i.e., it signifies end of header.
233057Seric **			- H_DELETE -- delete this field.
243057Seric **			There is also a field pointing to a pointer
253057Seric **			that should be set to point to this header.
26*4093Seric **
27*4093Seric **	Notes:
28*4093Seric **		I have tried to put almost all the reasonable
29*4093Seric **		configuration information into the configuration
30*4093Seric **		file read at runtime.  My intent is that anything
31*4093Seric **		here is a function of the version of UNIX you
32*4093Seric **		are running, or is really static -- for example
33*4093Seric **		the headers are a superset of widely used
34*4093Seric **		protocols.  If you find yourself playing with
35*4093Seric **		this file too much, you may be making a mistake!
36294Seric */
37294Seric 
38294Seric 
39294Seric 
40294Seric 
41*4093Seric static char SccsId[] = "@(#)conf.c	3.16	08/09/81";
42294Seric 
431388Seric 
441388Seric # include <whoami.h>		/* definitions of machine id's at berkeley */
451388Seric 
463061Seric 
472897Seric /*
482897Seric **  Header info table
493057Seric **	Final (null) entry contains the flags used for any other field.
502897Seric */
512897Seric 
522897Seric struct hdrinfo	HdrInfo[] =
532897Seric {
543384Seric 	"date",		H_CHECK,		M_NEEDDATE,
553384Seric 	"from",		H_CHECK,		M_NEEDFROM,
563388Seric 	"full-name",	H_ACHECK,		M_FULLNAME,
573057Seric 	"to",		0,			NULL,
583057Seric 	"cc",		0,			NULL,
593057Seric 	"subject",	0,			NULL,
603384Seric 	"message-id",	H_CHECK,		M_MSGID,
613057Seric 	"message",	H_EOH,			NULL,
623057Seric 	NULL,		0,			NULL,
632897Seric };
64294Seric 
65294Seric # ifdef V6
66294Seric /*
67294Seric **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
68294Seric **
69294Seric **	Returns the pathname of the user's tty.  Returns NULL if
70294Seric **	the user is not logged in or if s/he has write permission
71294Seric **	denied.
72294Seric **
73294Seric **	Parameters:
74294Seric **		none
75294Seric **
76294Seric **	Returns:
77294Seric **		pathname of the user's tty.
78294Seric **		NULL if not logged in or write permission denied.
79294Seric **
80294Seric **	Side Effects:
81294Seric **		none.
82294Seric **
83294Seric **	WARNING:
84294Seric **		Return value is in a local buffer.
85294Seric **
86294Seric **	Called By:
87294Seric **		savemail
88294Seric */
89294Seric 
90294Seric # include <sys/types.h>
91294Seric # include <sys/stat.h>
92294Seric 
93294Seric char *
94294Seric ttypath()
95294Seric {
96294Seric 	struct stat stbuf;
97294Seric 	register int i;
98294Seric 	static char pathn[] = "/dev/ttyx";
99294Seric 
100294Seric 	/* compute the pathname of the controlling tty */
101294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
102294Seric 	{
103294Seric 		errno = 0;
104294Seric 		return (NULL);
105294Seric 	}
106294Seric 	pathn[8] = i;
107294Seric 
108294Seric 	/* see if we have write permission */
1092967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
110294Seric 	{
111294Seric 		errno = 0;
112294Seric 		return (NULL);
113294Seric 	}
114294Seric 
115294Seric 	/* see if the user is logged in */
116294Seric 	if (getlogin() == NULL)
117294Seric 		return (NULL);
118294Seric 
119294Seric 	/* looks good */
120294Seric 	return (pathn);
121294Seric }
122294Seric /*
123294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
124294Seric **
125294Seric **	This is included here because it is standard in v7, but we
126294Seric **	need it in v6.
127294Seric **
128294Seric **	Algorithm:
129294Seric **		Open /dev/null to create a descriptor.
130294Seric **		Close that descriptor.
131294Seric **		Copy the existing fd into the descriptor.
132294Seric **
133294Seric **	Parameters:
134294Seric **		fd -- the open file descriptor.
135294Seric **		type -- "r", "w", or whatever.
136294Seric **
137294Seric **	Returns:
138294Seric **		The file descriptor it creates.
139294Seric **
140294Seric **	Side Effects:
141294Seric **		none
142294Seric **
143294Seric **	Called By:
144294Seric **		deliver
145294Seric **
146294Seric **	Notes:
147294Seric **		The mode of fd must match "type".
148294Seric */
149294Seric 
150294Seric FILE *
151294Seric fdopen(fd, type)
152294Seric 	int fd;
153294Seric 	char *type;
154294Seric {
155294Seric 	register FILE *f;
156294Seric 
157294Seric 	f = fopen("/dev/null", type);
1584081Seric 	(void) close(fileno(f));
159294Seric 	fileno(f) = fd;
160294Seric 	return (f);
161294Seric }
162294Seric /*
163294Seric **  INDEX -- Return pointer to character in string
164294Seric **
165294Seric **	For V7 compatibility.
166294Seric **
167294Seric **	Parameters:
168294Seric **		s -- a string to scan.
169294Seric **		c -- a character to look for.
170294Seric **
171294Seric **	Returns:
172294Seric **		If c is in s, returns the address of the first
173294Seric **			instance of c in s.
174294Seric **		NULL if c is not in s.
175294Seric **
176294Seric **	Side Effects:
177294Seric **		none.
178294Seric */
179294Seric 
180294Seric index(s, c)
181294Seric 	register char *s;
182294Seric 	register char c;
183294Seric {
184294Seric 	while (*s != '\0')
185294Seric 	{
186294Seric 		if (*s++ == c)
187294Seric 			return (--s);
188294Seric 	}
189294Seric 	return (NULL);
190294Seric }
191294Seric # endif V6
192294Seric 
193294Seric # ifndef V6
194294Seric /*
195294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
196294Seric **
197294Seric **	Returns the pathname of the user's tty.  Returns NULL if
198294Seric **	the user is not logged in or if s/he has write permission
199294Seric **	denied.
200294Seric **
201294Seric **	Parameters:
202294Seric **		none
203294Seric **
204294Seric **	Returns:
205294Seric **		pathname of the user's tty.
206294Seric **		NULL if not logged in or write permission denied.
207294Seric **
208294Seric **	Side Effects:
209294Seric **		none.
210294Seric **
211294Seric **	WARNING:
212294Seric **		Return value is in a local buffer.
213294Seric **
214294Seric **	Called By:
215294Seric **		savemail
216294Seric */
217294Seric 
218294Seric # include <sys/types.h>
219294Seric # include <sys/stat.h>
220294Seric 
221294Seric char *
222294Seric ttypath()
223294Seric {
224294Seric 	struct stat stbuf;
225294Seric 	register char *pathn;
226294Seric 	extern char *ttyname();
2274081Seric 	extern char *getlogin();
228294Seric 
229294Seric 	/* compute the pathname of the controlling tty */
230294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
231294Seric 	{
232294Seric 		errno = 0;
233294Seric 		return (NULL);
234294Seric 	}
235294Seric 
236294Seric 	/* see if we have write permission */
2372967Seric 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
238294Seric 	{
239294Seric 		errno = 0;
240294Seric 		return (NULL);
241294Seric 	}
242294Seric 
243294Seric 	/* see if the user is logged in */
244294Seric 	if (getlogin() == NULL)
245294Seric 		return (NULL);
246294Seric 
247294Seric 	/* looks good */
248294Seric 	return (pathn);
249294Seric }
250294Seric # endif V6
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