1 # include <stdio.h>
2 # include <pwd.h>
3 # include "dlvrmail.h"
4 
5 static char SccsId[] = "@(#)conf.c	1.3	07/25/80";
6 # include <whoami.h>
7 
8 /*
9 **  CONF.C -- Delivermail Configuration Tables.
10 **
11 **	Defines the configuration of this installation.
12 **
13 **	The first table describes available mailers.  This is
14 **	just a list of argument vectors, with the following
15 **	codes embedded:
16 **		$u -- insert the user name.
17 **		$h -- insert the host name.
18 **		$f -- insert the from person name.
19 **		$c -- insert the hop count.
20 **	This stuff is interpreted in buildmail.  There are two
21 **	important conventions here: entry zero must be the
22 **	local mailer & entry one must be the shell.
23 **
24 **	The second table gives a list of special characters.  This
25 **	table is scanned linearly by parse() until an entry is
26 **	found using one of the magic characters.  Other fields
27 **	give more information on how to handle it.
28 **
29 **	Defined Constants:
30 **		M_* -- indices into Mailer, used only in this module.
31 **
32 **	Defines:
33 **		Mailer -- the mailer descriptor table.
34 **		ParseTab -- the parse table.
35 **
36 **	Notes:
37 **		Ingres 11/70 version.
38 **
39 **	History:
40 **		3/5/80 -- Generalized to use <whoami.h>.
41 **		12/26/79 -- written for Ingres 11/70.
42 */
43 
44 
45 
46 
47 
48 # ifdef ING70
49 static char	*BerkLocal[] = { "i", "ingres", "ing70", NULL };
50 char		*MyLocNam = "Ing70";
51 # define HASARPA
52 # define V6
53 # endif ING70
54 
55 # ifdef INGVAX
56 /* untested */
57 static char	*BerkLocal[] = { "j", "ingvax", NULL };
58 char		*MyLocNam = "IngVax";
59 # endif INGVAX
60 
61 # ifdef CSVAX
62 /* untested */
63 static char	*BerkLocal[] = { "v", "csvax", "vax", NULL };
64 char		*MyLocNam = "CSVax";
65 # define HASUUCP
66 # define NETV6MAIL
67 # endif CSVAX
68 
69 # ifdef CORY
70 /* untested */
71 static char	*BerkLocal[] = { "y", "cory", NULL };
72 char		*MyLocNam = "Cory";
73 # endif CORY
74 
75 # ifdef IMAGE
76 /* untested */
77 static char	*BerkLocal[] = { "m", "image", NULL };
78 char		*MyLocNam = "Image";
79 # define V6
80 # endif IMAGE
81 
82 # ifdef ESVAX
83 /* untested */
84 static char	*BerkLocal[] = { "o", "esvax", NULL };
85 char		*MyLocNam = "ESVax";
86 # endif ESVAX
87 
88 # ifdef EECS40
89 /* untested */
90 static char	*BerkLocal[] = { "z", "eecs40", NULL };
91 char		*MyLocNam = "EECS40";
92 # define V6
93 # endif EECS40
94 
95 struct mailer Mailer[] =
96 {
97 	/* local mail -- must be #0 */
98 	{
99 # ifdef NETV6MAIL
100 		"/usr/net/bin/v6mail",
101 # else
102 		"/bin/mail",
103 # endif
104 		M_ROPT|M_NOHOST|M_STRIPQ,	EX_NOUSER,	NULL,
105 		{ "...local%mail", "-d", "$u", NULL }
106 	},
107 	/* pipes through programs -- must be #1 */
108 	{
109 		"/bin/csh",
110 		M_HDR|M_NOHOST,			EX_UNAVAIL,	NULL,
111 		{ "...prog%mail", "-fc", "$u", NULL }
112 	},
113 	/* local berkeley mail */
114 	{
115 		"/usr/net/bin/sendberkmail",
116 		M_FOPT|M_HDR|M_STRIPQ,		EX_UNAVAIL,	BerkLocal,
117 		{ "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL }
118 	},
119 	/* arpanet mail */
120 	{
121 		"/usr/lib/mailers/arpa",
122 		M_STRIPQ,			0,		NULL,
123 		{ "...arpa%mail", "$f", "$h", "$u", NULL }
124 	},
125 	/* uucp mail (cheat & use Bell's v7 mail) */
126 	{
127 # ifdef UCKMAIL
128 		"/bin/badmail",
129 # else
130 		"/bin/mail",
131 # endif
132 		M_ROPT|M_NOHOST|M_STRIPQ,	EX_NOUSER,	NULL,
133 # ifdef DUMBMAIL
134 		{ "...uucp%mail", "$h!$u", NULL }
135 # else
136 		{ "...uucp%mail", "-d", "$h!$u", NULL }
137 # endif DUMBMAIL
138 	},
139 };
140 
141 # define M_LOCAL	0
142 # define M_BERK		2
143 # define M_ARPA		3
144 # define M_UUCP		4
145 
146 
147 
148 struct parsetab ParseTab[] =
149 {
150 	':',	M_BERK,		P_ONE,				NULL,
151 # ifdef HASARPA
152 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
153 # else
154 	'@',	M_BERK,		P_HLAST|P_USR_UPPER|P_MOVE,	"ing70",
155 # endif HASARPA
156 	'^',	-1,		P_MAP,				"!",
157 # ifdef HASUUCP
158 	'!',	M_UUCP,		0,				NULL,
159 # else
160 	'!',	M_BERK,		P_MOVE,				"csvax",
161 # endif HASUUCP
162 	'.',	-1,		P_MAP|P_ONE,			":",
163 	'\0',	M_LOCAL,	P_MOVE,				"",
164 };
165 /*
166 **  GETNAME -- Get the current users login name.
167 **
168 **	This is in config.c because it is somewhat machine dependent.
169 **	Examine it carefully for your installation.
170 **
171 **	Algorithm:
172 **		See if the person is logged in.  If so, return
173 **			the name s/he is logged in as.
174 **		Look up the user id in /etc/passwd.  If found,
175 **			return that name.
176 **		Return NULL.
177 **
178 **	Parameters:
179 **		none
180 **
181 **	Returns:
182 **		The login name of this user.
183 **		NULL if this person is noone.
184 **
185 **	Side Effects:
186 **		none
187 **
188 **	Requires:
189 **		getlogin (sys)
190 **		getpwuid (sys)
191 **		getuid (sys)
192 **
193 **	Called By:
194 **		main
195 **
196 **	History:
197 **		12/26/79 -- written.
198 */
199 
200 char *
201 getname()
202 {
203 	register char *p;
204 	register struct passwd *w;
205 	extern char *getlogin();
206 	extern struct passwd *getpwuid();
207 	static char namebuf[9];
208 
209 	p = getlogin();
210 	if (p != NULL && p[0] != '\0')
211 		return (p);
212 # ifdef V6
213 	w = getpwuid(getuid() & 0377);
214 # else
215 	w = getpwuid(getuid());
216 # endif V6
217 	if (w != NULL)
218 	{
219 		strcpy(namebuf, w->pw_name);
220 		return (namebuf);
221 	}
222 	return (NULL);
223 }
224 
225 # ifdef V6
226 /*
227 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
228 **
229 **	Returns the pathname of the user's tty.  Returns NULL if
230 **	the user is not logged in or if s/he has write permission
231 **	denied.
232 **
233 **	Parameters:
234 **		none
235 **
236 **	Returns:
237 **		pathname of the user's tty.
238 **		NULL if not logged in or write permission denied.
239 **
240 **	Side Effects:
241 **		none.
242 **
243 **	WARNING:
244 **		Return value is in a local buffer.
245 **
246 **	Requires:
247 **		stat (sys)
248 **		ttyn (sys)
249 **		open (sys)
250 **		read (sys)
251 **		close (sys)
252 **		seek (sys)
253 **
254 **	Called By:
255 **		savemail
256 **
257 **	History:
258 **		1/12/80 -- written.
259 */
260 
261 # include <sys/types.h>
262 # include <sys/stat.h>
263 
264 char *
265 ttypath()
266 {
267 	struct stat stbuf;
268 	register int i;
269 	static char pathn[] = "/dev/ttyx";
270 	extern int errno;
271 
272 	/* compute the pathname of the controlling tty */
273 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
274 	{
275 		errno = 0;
276 		return (NULL);
277 	}
278 	pathn[8] = i;
279 
280 	/* see if we have write permission */
281 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
282 	{
283 		errno = 0;
284 		return (NULL);
285 	}
286 
287 	/* see if the user is logged in */
288 	if (getlogin() == NULL)
289 		return (NULL);
290 
291 	/* looks good */
292 	return (pathn);
293 }
294 /*
295 **  FDOPEN -- Open a stdio file given an open file descriptor.
296 **
297 **	This is included here because it is standard in v7, but we
298 **	need it in v6.
299 **
300 **	Algorithm:
301 **		Open /dev/null to create a descriptor.
302 **		Close that descriptor.
303 **		Copy the existing fd into the descriptor.
304 **
305 **	Parameters:
306 **		fd -- the open file descriptor.
307 **		type -- "r", "w", or whatever.
308 **
309 **	Returns:
310 **		The file descriptor it creates.
311 **
312 **	Side Effects:
313 **		none
314 **
315 **	Requires:
316 **		fopen (sys)
317 **
318 **	Called By:
319 **		deliver
320 **
321 **	Notes:
322 **		The mode of fd must match "type".
323 */
324 
325 FILE *
326 fdopen(fd, type)
327 	int fd;
328 	char *type;
329 {
330 	register FILE *f;
331 
332 	f = fopen("/dev/null", type);
333 	close(fileno(f));
334 	fileno(f) = fd;
335 	return (f);
336 }
337 /*
338 **  INDEX -- Return pointer to character in string
339 **
340 **	For V7 compatibility.
341 **
342 **	Parameters:
343 **		s -- a string to scan.
344 **		c -- a character to look for.
345 **
346 **	Returns:
347 **		If c is in s, returns the address of the first
348 **			instance of c in s.
349 **		NULL if c is not in s.
350 **
351 **	Side Effects:
352 **		none.
353 **
354 **	Requires:
355 **		none.
356 **
357 **	History:
358 **		3/14/80 -- written.  Why isn't this in -lS?
359 */
360 
361 index(s, c)
362 	register char *s;
363 	register char c;
364 {
365 	while (*s != '\0')
366 	{
367 		if (*s++ == c)
368 			return (--s);
369 	}
370 	return (NULL);
371 }
372 # endif V6
373 
374 # ifndef V6
375 /*
376 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
377 **
378 **	Returns the pathname of the user's tty.  Returns NULL if
379 **	the user is not logged in or if s/he has write permission
380 **	denied.
381 **
382 **	Parameters:
383 **		none
384 **
385 **	Returns:
386 **		pathname of the user's tty.
387 **		NULL if not logged in or write permission denied.
388 **
389 **	Side Effects:
390 **		none.
391 **
392 **	WARNING:
393 **		Return value is in a local buffer.
394 **
395 **	Requires:
396 **		stat (sys)
397 **		ttyn (sys)
398 **		open (sys)
399 **		read (sys)
400 **		close (sys)
401 **		seek (sys)
402 **
403 **	Called By:
404 **		savemail
405 **
406 **	History:
407 **		1/12/80 -- written.
408 */
409 
410 # include <sys/types.h>
411 # include <sys/stat.h>
412 
413 char *
414 ttypath()
415 {
416 	struct stat stbuf;
417 	register char *pathn;
418 	extern int errno;
419 	extern char *ttyname();
420 
421 	/* compute the pathname of the controlling tty */
422 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
423 	{
424 		errno = 0;
425 		return (NULL);
426 	}
427 
428 	/* see if we have write permission */
429 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
430 	{
431 		errno = 0;
432 		return (NULL);
433 	}
434 
435 	/* see if the user is logged in */
436 	if (getlogin() == NULL)
437 		return (NULL);
438 
439 	/* looks good */
440 	return (pathn);
441 }
442 # endif V6
443