1294Seric # include <stdio.h>
2294Seric # include <pwd.h>
3294Seric # include "dlvrmail.h"
4*404Seric 
5*404Seric static char SccsId[] = "@(#)conf.c	1.3	07/25/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 };
50294Seric char		*MyLocNam = "Ing70";
51294Seric # define HASARPA
52294Seric # define V6
53294Seric # endif ING70
54294Seric 
55294Seric # ifdef INGVAX
56294Seric /* untested */
57294Seric static char	*BerkLocal[] = { "j", "ingvax", NULL };
58294Seric char		*MyLocNam = "IngVax";
59294Seric # endif INGVAX
60294Seric 
61294Seric # ifdef CSVAX
62294Seric /* untested */
63294Seric static char	*BerkLocal[] = { "v", "csvax", "vax", NULL };
64294Seric char		*MyLocNam = "CSVax";
65294Seric # define HASUUCP
66294Seric # define NETV6MAIL
67294Seric # endif CSVAX
68294Seric 
69294Seric # ifdef CORY
70294Seric /* untested */
71294Seric static char	*BerkLocal[] = { "y", "cory", NULL };
72294Seric char		*MyLocNam = "Cory";
73294Seric # endif CORY
74294Seric 
75294Seric # ifdef IMAGE
76294Seric /* untested */
77294Seric static char	*BerkLocal[] = { "m", "image", NULL };
78294Seric char		*MyLocNam = "Image";
79294Seric # define V6
80294Seric # endif IMAGE
81294Seric 
82294Seric # ifdef ESVAX
83294Seric /* untested */
84294Seric static char	*BerkLocal[] = { "o", "esvax", NULL };
85294Seric char		*MyLocNam = "ESVax";
86294Seric # endif ESVAX
87294Seric 
88294Seric # ifdef EECS40
89294Seric /* untested */
90294Seric static char	*BerkLocal[] = { "z", "eecs40", NULL };
91294Seric char		*MyLocNam = "EECS40";
92294Seric # define V6
93294Seric # endif EECS40
94294Seric 
95294Seric struct mailer Mailer[] =
96294Seric {
97294Seric 	/* local mail -- must be #0 */
98294Seric 	{
99294Seric # ifdef NETV6MAIL
100294Seric 		"/usr/net/bin/v6mail",
101294Seric # else
102294Seric 		"/bin/mail",
103294Seric # endif
104294Seric 		M_ROPT|M_NOHOST|M_STRIPQ,	EX_NOUSER,	NULL,
105294Seric 		{ "...local%mail", "-d", "$u", NULL }
106294Seric 	},
107294Seric 	/* pipes through programs -- must be #1 */
108294Seric 	{
109294Seric 		"/bin/csh",
110294Seric 		M_HDR|M_NOHOST,			EX_UNAVAIL,	NULL,
111294Seric 		{ "...prog%mail", "-fc", "$u", NULL }
112294Seric 	},
113294Seric 	/* local berkeley mail */
114294Seric 	{
115294Seric 		"/usr/net/bin/sendberkmail",
116310Seric 		M_FOPT|M_HDR|M_STRIPQ,		EX_UNAVAIL,	BerkLocal,
117294Seric 		{ "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL }
118294Seric 	},
119294Seric 	/* arpanet mail */
120294Seric 	{
121294Seric 		"/usr/lib/mailers/arpa",
122310Seric 		M_STRIPQ,			0,		NULL,
123294Seric 		{ "...arpa%mail", "$f", "$h", "$u", NULL }
124294Seric 	},
125294Seric 	/* uucp mail (cheat & use Bell's v7 mail) */
126294Seric 	{
127294Seric # ifdef UCKMAIL
128294Seric 		"/bin/badmail",
129294Seric # else
130294Seric 		"/bin/mail",
131294Seric # endif
132294Seric 		M_ROPT|M_NOHOST|M_STRIPQ,	EX_NOUSER,	NULL,
133294Seric # ifdef DUMBMAIL
134294Seric 		{ "...uucp%mail", "$h!$u", NULL }
135294Seric # else
136294Seric 		{ "...uucp%mail", "-d", "$h!$u", NULL }
137294Seric # endif DUMBMAIL
138294Seric 	},
139294Seric };
140294Seric 
141294Seric # define M_LOCAL	0
142294Seric # define M_BERK		2
143294Seric # define M_ARPA		3
144294Seric # define M_UUCP		4
145294Seric 
146294Seric 
147294Seric 
148294Seric struct parsetab ParseTab[] =
149294Seric {
150294Seric 	':',	M_BERK,		P_ONE,				NULL,
151294Seric # ifdef HASARPA
152294Seric 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
153294Seric # else
154294Seric 	'@',	M_BERK,		P_HLAST|P_USR_UPPER|P_MOVE,	"ing70",
155294Seric # endif HASARPA
156294Seric 	'^',	-1,		P_MAP,				"!",
157294Seric # ifdef HASUUCP
158294Seric 	'!',	M_UUCP,		0,				NULL,
159294Seric # else
160294Seric 	'!',	M_BERK,		P_MOVE,				"csvax",
161294Seric # endif HASUUCP
162294Seric 	'.',	-1,		P_MAP|P_ONE,			":",
163294Seric 	'\0',	M_LOCAL,	P_MOVE,				"",
164294Seric };
165294Seric /*
166294Seric **  GETNAME -- Get the current users login name.
167294Seric **
168294Seric **	This is in config.c because it is somewhat machine dependent.
169294Seric **	Examine it carefully for your installation.
170294Seric **
171294Seric **	Algorithm:
172294Seric **		See if the person is logged in.  If so, return
173294Seric **			the name s/he is logged in as.
174294Seric **		Look up the user id in /etc/passwd.  If found,
175294Seric **			return that name.
176294Seric **		Return NULL.
177294Seric **
178294Seric **	Parameters:
179294Seric **		none
180294Seric **
181294Seric **	Returns:
182294Seric **		The login name of this user.
183294Seric **		NULL if this person is noone.
184294Seric **
185294Seric **	Side Effects:
186294Seric **		none
187294Seric **
188294Seric **	Requires:
189294Seric **		getlogin (sys)
190294Seric **		getpwuid (sys)
191294Seric **		getuid (sys)
192294Seric **
193294Seric **	Called By:
194294Seric **		main
195294Seric **
196294Seric **	History:
197294Seric **		12/26/79 -- written.
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 **	Requires:
247294Seric **		stat (sys)
248294Seric **		ttyn (sys)
249294Seric **		open (sys)
250294Seric **		read (sys)
251294Seric **		close (sys)
252294Seric **		seek (sys)
253294Seric **
254294Seric **	Called By:
255294Seric **		savemail
256294Seric **
257294Seric **	History:
258294Seric **		1/12/80 -- written.
259294Seric */
260294Seric 
261294Seric # include <sys/types.h>
262294Seric # include <sys/stat.h>
263294Seric 
264294Seric char *
265294Seric ttypath()
266294Seric {
267294Seric 	struct stat stbuf;
268294Seric 	register int i;
269294Seric 	static char pathn[] = "/dev/ttyx";
270294Seric 	extern int errno;
271294Seric 
272294Seric 	/* compute the pathname of the controlling tty */
273294Seric 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
274294Seric 	{
275294Seric 		errno = 0;
276294Seric 		return (NULL);
277294Seric 	}
278294Seric 	pathn[8] = i;
279294Seric 
280294Seric 	/* see if we have write permission */
281294Seric 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
282294Seric 	{
283294Seric 		errno = 0;
284294Seric 		return (NULL);
285294Seric 	}
286294Seric 
287294Seric 	/* see if the user is logged in */
288294Seric 	if (getlogin() == NULL)
289294Seric 		return (NULL);
290294Seric 
291294Seric 	/* looks good */
292294Seric 	return (pathn);
293294Seric }
294294Seric /*
295294Seric **  FDOPEN -- Open a stdio file given an open file descriptor.
296294Seric **
297294Seric **	This is included here because it is standard in v7, but we
298294Seric **	need it in v6.
299294Seric **
300294Seric **	Algorithm:
301294Seric **		Open /dev/null to create a descriptor.
302294Seric **		Close that descriptor.
303294Seric **		Copy the existing fd into the descriptor.
304294Seric **
305294Seric **	Parameters:
306294Seric **		fd -- the open file descriptor.
307294Seric **		type -- "r", "w", or whatever.
308294Seric **
309294Seric **	Returns:
310294Seric **		The file descriptor it creates.
311294Seric **
312294Seric **	Side Effects:
313294Seric **		none
314294Seric **
315294Seric **	Requires:
316294Seric **		fopen (sys)
317294Seric **
318294Seric **	Called By:
319294Seric **		deliver
320294Seric **
321294Seric **	Notes:
322294Seric **		The mode of fd must match "type".
323294Seric */
324294Seric 
325294Seric FILE *
326294Seric fdopen(fd, type)
327294Seric 	int fd;
328294Seric 	char *type;
329294Seric {
330294Seric 	register FILE *f;
331294Seric 
332294Seric 	f = fopen("/dev/null", type);
333294Seric 	close(fileno(f));
334294Seric 	fileno(f) = fd;
335294Seric 	return (f);
336294Seric }
337294Seric /*
338294Seric **  INDEX -- Return pointer to character in string
339294Seric **
340294Seric **	For V7 compatibility.
341294Seric **
342294Seric **	Parameters:
343294Seric **		s -- a string to scan.
344294Seric **		c -- a character to look for.
345294Seric **
346294Seric **	Returns:
347294Seric **		If c is in s, returns the address of the first
348294Seric **			instance of c in s.
349294Seric **		NULL if c is not in s.
350294Seric **
351294Seric **	Side Effects:
352294Seric **		none.
353294Seric **
354294Seric **	Requires:
355294Seric **		none.
356294Seric **
357294Seric **	History:
358294Seric **		3/14/80 -- written.  Why isn't this in -lS?
359294Seric */
360294Seric 
361294Seric index(s, c)
362294Seric 	register char *s;
363294Seric 	register char c;
364294Seric {
365294Seric 	while (*s != '\0')
366294Seric 	{
367294Seric 		if (*s++ == c)
368294Seric 			return (--s);
369294Seric 	}
370294Seric 	return (NULL);
371294Seric }
372294Seric # endif V6
373294Seric 
374294Seric # ifndef V6
375294Seric /*
376294Seric **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
377294Seric **
378294Seric **	Returns the pathname of the user's tty.  Returns NULL if
379294Seric **	the user is not logged in or if s/he has write permission
380294Seric **	denied.
381294Seric **
382294Seric **	Parameters:
383294Seric **		none
384294Seric **
385294Seric **	Returns:
386294Seric **		pathname of the user's tty.
387294Seric **		NULL if not logged in or write permission denied.
388294Seric **
389294Seric **	Side Effects:
390294Seric **		none.
391294Seric **
392294Seric **	WARNING:
393294Seric **		Return value is in a local buffer.
394294Seric **
395294Seric **	Requires:
396294Seric **		stat (sys)
397294Seric **		ttyn (sys)
398294Seric **		open (sys)
399294Seric **		read (sys)
400294Seric **		close (sys)
401294Seric **		seek (sys)
402294Seric **
403294Seric **	Called By:
404294Seric **		savemail
405294Seric **
406294Seric **	History:
407294Seric **		1/12/80 -- written.
408294Seric */
409294Seric 
410294Seric # include <sys/types.h>
411294Seric # include <sys/stat.h>
412294Seric 
413294Seric char *
414294Seric ttypath()
415294Seric {
416294Seric 	struct stat stbuf;
417294Seric 	register char *pathn;
418294Seric 	extern int errno;
419294Seric 	extern char *ttyname();
420294Seric 
421294Seric 	/* compute the pathname of the controlling tty */
422294Seric 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
423294Seric 	{
424294Seric 		errno = 0;
425294Seric 		return (NULL);
426294Seric 	}
427294Seric 
428294Seric 	/* see if we have write permission */
429294Seric 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
430294Seric 	{
431294Seric 		errno = 0;
432294Seric 		return (NULL);
433294Seric 	}
434294Seric 
435294Seric 	/* see if the user is logged in */
436294Seric 	if (getlogin() == NULL)
437294Seric 		return (NULL);
438294Seric 
439294Seric 	/* looks good */
440294Seric 	return (pathn);
441294Seric }
442294Seric # endif V6
443