xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 1206)
1294Seric # include <stdio.h>
2294Seric # include <pwd.h>
3294Seric # include "dlvrmail.h"
4404Seric 
5*1206Seric static char SccsId[] = "@(#)conf.c	1.7	10/03/80";
6294Seric # include <whoami.h>
7294Seric 
8294Seric /*
9294Seric **  CONF.C -- Delivermail Configuration Tables.
10294Seric **
11294Seric **	Defines the configuration of this installation.
12294Seric **
13294Seric **	The first table describes available mailers.  This is
14294Seric **	just a list of argument vectors, with the following
15294Seric **	codes embedded:
16294Seric **		$u -- insert the user name.
17294Seric **		$h -- insert the host name.
18294Seric **		$f -- insert the from person name.
19294Seric **		$c -- insert the hop count.
20294Seric **	This stuff is interpreted in buildmail.  There are two
21294Seric **	important conventions here: entry zero must be the
22294Seric **	local mailer & entry one must be the shell.
23294Seric **
24294Seric **	The second table gives a list of special characters.  This
25294Seric **	table is scanned linearly by parse() until an entry is
26294Seric **	found using one of the magic characters.  Other fields
27294Seric **	give more information on how to handle it.
28294Seric **
29294Seric **	Defined Constants:
30294Seric **		M_* -- indices into Mailer, used only in this module.
31294Seric **
32294Seric **	Defines:
33294Seric **		Mailer -- the mailer descriptor table.
34294Seric **		ParseTab -- the parse table.
35294Seric **
36294Seric **	Notes:
37294Seric **		Ingres 11/70 version.
38294Seric **
39294Seric **	History:
40294Seric **		3/5/80 -- Generalized to use <whoami.h>.
41294Seric **		12/26/79 -- written for Ingres 11/70.
42294Seric */
43294Seric 
44294Seric 
45294Seric 
46294Seric 
47294Seric 
48294Seric # ifdef ING70
49294Seric static char	*BerkLocal[] = { "i", "ingres", "ing70", NULL };
50590Seric # define ArpaLocal	NULL
51*1206Seric char		*MyLocName = "Ing70";
52294Seric # define HASARPA
53294Seric # define V6
54294Seric # endif ING70
55294Seric 
56294Seric # ifdef INGVAX
57294Seric /* untested */
58294Seric static char	*BerkLocal[] = { "j", "ingvax", NULL };
59*1206Seric char		*MyLocName = "IngVax";
60294Seric # endif INGVAX
61294Seric 
62294Seric # ifdef CSVAX
63294Seric /* untested */
64294Seric static char	*BerkLocal[] = { "v", "csvax", "vax", NULL };
65590Seric static char	*UucpLocal[] = { "ucbvax", "ernie", NULL };
66*1206Seric char		*MyLocName = "CSVAX";
67294Seric # define HASUUCP
68294Seric # define NETV6MAIL
69294Seric # endif CSVAX
70294Seric 
71294Seric # ifdef CORY
72294Seric /* untested */
73294Seric static char	*BerkLocal[] = { "y", "cory", NULL };
74*1206Seric char		*MyLocName = "Cory";
75294Seric # endif CORY
76294Seric 
77294Seric # ifdef IMAGE
78294Seric /* untested */
79294Seric static char	*BerkLocal[] = { "m", "image", NULL };
80*1206Seric char		*MyLocName = "Image";
81294Seric # define V6
82294Seric # endif IMAGE
83294Seric 
84294Seric # ifdef ESVAX
85294Seric /* untested */
86294Seric static char	*BerkLocal[] = { "o", "esvax", NULL };
87*1206Seric char		*MyLocName = "ESVAX";
88294Seric # endif ESVAX
89294Seric 
90294Seric # ifdef EECS40
91294Seric /* untested */
92294Seric static char	*BerkLocal[] = { "z", "eecs40", NULL };
93*1206Seric char		*MyLocName = "EECS40";
94294Seric # define V6
95294Seric # endif EECS40
96294Seric 
97590Seric 
98590Seric # ifndef HASARPA
99590Seric # define ArpaLocal	NULL
100590Seric # endif HASARPA
101590Seric 
102590Seric # ifndef HASUUCP
103590Seric # define UucpLocal	NULL
104590Seric # endif HASUUCP
105590Seric 
106590Seric 
107294Seric struct mailer Mailer[] =
108294Seric {
109294Seric 	/* local mail -- must be #0 */
110294Seric 	{
111294Seric # ifdef NETV6MAIL
112294Seric 		"/usr/net/bin/v6mail",
113294Seric # else
114294Seric 		"/bin/mail",
115294Seric # endif
116294Seric 		M_ROPT|M_NOHOST|M_STRIPQ,	EX_NOUSER,	NULL,
117294Seric 		{ "...local%mail", "-d", "$u", NULL }
118294Seric 	},
119294Seric 	/* pipes through programs -- must be #1 */
120294Seric 	{
121294Seric 		"/bin/csh",
122294Seric 		M_HDR|M_NOHOST,			EX_UNAVAIL,	NULL,
123294Seric 		{ "...prog%mail", "-fc", "$u", NULL }
124294Seric 	},
125294Seric 	/* local berkeley mail */
126294Seric 	{
127294Seric 		"/usr/net/bin/sendberkmail",
128310Seric 		M_FOPT|M_HDR|M_STRIPQ,		EX_UNAVAIL,	BerkLocal,
129294Seric 		{ "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL }
130294Seric 	},
131294Seric 	/* arpanet mail */
132294Seric 	{
133294Seric 		"/usr/lib/mailers/arpa",
134590Seric 		M_STRIPQ,			0,		ArpaLocal,
135294Seric 		{ "...arpa%mail", "$f", "$h", "$u", NULL }
136294Seric 	},
137294Seric 	/* uucp mail (cheat & use Bell's v7 mail) */
138294Seric 	{
139294Seric 		"/bin/mail",
140917Seric 		M_ROPT|M_STRIPQ,		EX_NOUSER,	UucpLocal,
141294Seric # ifdef DUMBMAIL
142294Seric 		{ "...uucp%mail", "$h!$u", NULL }
143294Seric # else
144294Seric 		{ "...uucp%mail", "-d", "$h!$u", NULL }
145294Seric # endif DUMBMAIL
146294Seric 	},
147294Seric };
148294Seric 
149294Seric # define M_LOCAL	0
150294Seric # define M_BERK		2
151294Seric # define M_ARPA		3
152294Seric # define M_UUCP		4
153294Seric 
154294Seric 
155294Seric 
156294Seric struct parsetab ParseTab[] =
157294Seric {
158294Seric 	':',	M_BERK,		P_ONE,				NULL,
159294Seric # ifdef HASARPA
160294Seric 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
161294Seric # else
162294Seric 	'@',	M_BERK,		P_HLAST|P_USR_UPPER|P_MOVE,	"ing70",
163294Seric # endif HASARPA
164294Seric 	'^',	-1,		P_MAP,				"!",
165294Seric # ifdef HASUUCP
166294Seric 	'!',	M_UUCP,		0,				NULL,
167294Seric # else
168294Seric 	'!',	M_BERK,		P_MOVE,				"csvax",
169294Seric # endif HASUUCP
170294Seric 	'.',	-1,		P_MAP|P_ONE,			":",
171294Seric 	'\0',	M_LOCAL,	P_MOVE,				"",
172294Seric };
173294Seric /*
174294Seric **  GETNAME -- Get the current users login name.
175294Seric **
176294Seric **	This is in config.c because it is somewhat machine dependent.
177294Seric **	Examine it carefully for your installation.
178294Seric **
179294Seric **	Algorithm:
180294Seric **		See if the person is logged in.  If so, return
181294Seric **			the name s/he is logged in as.
182294Seric **		Look up the user id in /etc/passwd.  If found,
183294Seric **			return that name.
184294Seric **		Return NULL.
185294Seric **
186294Seric **	Parameters:
187294Seric **		none
188294Seric **
189294Seric **	Returns:
190294Seric **		The login name of this user.
191294Seric **		NULL if this person is noone.
192294Seric **
193294Seric **	Side Effects:
194294Seric **		none
195294Seric **
196294Seric **	Called By:
197294Seric **		main
198294Seric */
199294Seric 
200294Seric char *
201294Seric getname()
202294Seric {
203294Seric 	register char *p;
204294Seric 	register struct passwd *w;
205294Seric 	extern char *getlogin();
206294Seric 	extern struct passwd *getpwuid();
207294Seric 	static char namebuf[9];
208294Seric 
209294Seric 	p = getlogin();
210294Seric 	if (p != NULL && p[0] != '\0')
211294Seric 		return (p);
212294Seric # ifdef V6
213294Seric 	w = getpwuid(getuid() & 0377);
214294Seric # else
215294Seric 	w = getpwuid(getuid());
216294Seric # endif V6
217294Seric 	if (w != NULL)
218294Seric 	{
219294Seric 		strcpy(namebuf, w->pw_name);
220294Seric 		return (namebuf);
221294Seric 	}
222294Seric 	return (NULL);
223294Seric }
224294Seric 
225294Seric # ifdef V6
226294Seric /*
227294Seric **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
228294Seric **
229294Seric **	Returns the pathname of the user's tty.  Returns NULL if
230294Seric **	the user is not logged in or if s/he has write permission
231294Seric **	denied.
232294Seric **
233294Seric **	Parameters:
234294Seric **		none
235294Seric **
236294Seric **	Returns:
237294Seric **		pathname of the user's tty.
238294Seric **		NULL if not logged in or write permission denied.
239294Seric **
240294Seric **	Side Effects:
241294Seric **		none.
242294Seric **
243294Seric **	WARNING:
244294Seric **		Return value is in a local buffer.
245294Seric **
246294Seric **	Called By:
247294Seric **		savemail
248294Seric */
249294Seric 
250294Seric # include <sys/types.h>
251294Seric # include <sys/stat.h>
252294Seric 
253294Seric char *
254294Seric ttypath()
255294Seric {
256294Seric 	struct stat stbuf;
257294Seric 	register int i;
258294Seric 	static char pathn[] = "/dev/ttyx";
259294Seric 	extern int errno;
260294Seric 
261294Seric 	/* compute the pathname of the controlling tty */
262294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
263294Seric 	{
264294Seric 		errno = 0;
265294Seric 		return (NULL);
266294Seric 	}
267294Seric 	pathn[8] = i;
268294Seric 
269294Seric 	/* see if we have write permission */
270294Seric 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
271294Seric 	{
272294Seric 		errno = 0;
273294Seric 		return (NULL);
274294Seric 	}
275294Seric 
276294Seric 	/* see if the user is logged in */
277294Seric 	if (getlogin() == NULL)
278294Seric 		return (NULL);
279294Seric 
280294Seric 	/* looks good */
281294Seric 	return (pathn);
282294Seric }
283294Seric /*
284294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
285294Seric **
286294Seric **	This is included here because it is standard in v7, but we
287294Seric **	need it in v6.
288294Seric **
289294Seric **	Algorithm:
290294Seric **		Open /dev/null to create a descriptor.
291294Seric **		Close that descriptor.
292294Seric **		Copy the existing fd into the descriptor.
293294Seric **
294294Seric **	Parameters:
295294Seric **		fd -- the open file descriptor.
296294Seric **		type -- "r", "w", or whatever.
297294Seric **
298294Seric **	Returns:
299294Seric **		The file descriptor it creates.
300294Seric **
301294Seric **	Side Effects:
302294Seric **		none
303294Seric **
304294Seric **	Called By:
305294Seric **		deliver
306294Seric **
307294Seric **	Notes:
308294Seric **		The mode of fd must match "type".
309294Seric */
310294Seric 
311294Seric FILE *
312294Seric fdopen(fd, type)
313294Seric 	int fd;
314294Seric 	char *type;
315294Seric {
316294Seric 	register FILE *f;
317294Seric 
318294Seric 	f = fopen("/dev/null", type);
319294Seric 	close(fileno(f));
320294Seric 	fileno(f) = fd;
321294Seric 	return (f);
322294Seric }
323294Seric /*
324294Seric **  INDEX -- Return pointer to character in string
325294Seric **
326294Seric **	For V7 compatibility.
327294Seric **
328294Seric **	Parameters:
329294Seric **		s -- a string to scan.
330294Seric **		c -- a character to look for.
331294Seric **
332294Seric **	Returns:
333294Seric **		If c is in s, returns the address of the first
334294Seric **			instance of c in s.
335294Seric **		NULL if c is not in s.
336294Seric **
337294Seric **	Side Effects:
338294Seric **		none.
339294Seric */
340294Seric 
341294Seric index(s, c)
342294Seric 	register char *s;
343294Seric 	register char c;
344294Seric {
345294Seric 	while (*s != '\0')
346294Seric 	{
347294Seric 		if (*s++ == c)
348294Seric 			return (--s);
349294Seric 	}
350294Seric 	return (NULL);
351294Seric }
352294Seric # endif V6
353294Seric 
354294Seric # ifndef V6
355294Seric /*
356294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
357294Seric **
358294Seric **	Returns the pathname of the user's tty.  Returns NULL if
359294Seric **	the user is not logged in or if s/he has write permission
360294Seric **	denied.
361294Seric **
362294Seric **	Parameters:
363294Seric **		none
364294Seric **
365294Seric **	Returns:
366294Seric **		pathname of the user's tty.
367294Seric **		NULL if not logged in or write permission denied.
368294Seric **
369294Seric **	Side Effects:
370294Seric **		none.
371294Seric **
372294Seric **	WARNING:
373294Seric **		Return value is in a local buffer.
374294Seric **
375294Seric **	Called By:
376294Seric **		savemail
377294Seric */
378294Seric 
379294Seric # include <sys/types.h>
380294Seric # include <sys/stat.h>
381294Seric 
382294Seric char *
383294Seric ttypath()
384294Seric {
385294Seric 	struct stat stbuf;
386294Seric 	register char *pathn;
387294Seric 	extern int errno;
388294Seric 	extern char *ttyname();
389294Seric 
390294Seric 	/* compute the pathname of the controlling tty */
391294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
392294Seric 	{
393294Seric 		errno = 0;
394294Seric 		return (NULL);
395294Seric 	}
396294Seric 
397294Seric 	/* see if we have write permission */
398294Seric 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
399294Seric 	{
400294Seric 		errno = 0;
401294Seric 		return (NULL);
402294Seric 	}
403294Seric 
404294Seric 	/* see if the user is logged in */
405294Seric 	if (getlogin() == NULL)
406294Seric 		return (NULL);
407294Seric 
408294Seric 	/* looks good */
409294Seric 	return (pathn);
410294Seric }
411294Seric # endif V6
412