1 # include <stdio.h>
2 # include <pwd.h>
3 # include "dlvrmail.h"
4 
5 static char SccsId[] = "@(#)conf.c	1.4	08/02/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 **	Called By:
189 **		main
190 */
191 
192 char *
193 getname()
194 {
195 	register char *p;
196 	register struct passwd *w;
197 	extern char *getlogin();
198 	extern struct passwd *getpwuid();
199 	static char namebuf[9];
200 
201 	p = getlogin();
202 	if (p != NULL && p[0] != '\0')
203 		return (p);
204 # ifdef V6
205 	w = getpwuid(getuid() & 0377);
206 # else
207 	w = getpwuid(getuid());
208 # endif V6
209 	if (w != NULL)
210 	{
211 		strcpy(namebuf, w->pw_name);
212 		return (namebuf);
213 	}
214 	return (NULL);
215 }
216 
217 # ifdef V6
218 /*
219 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
220 **
221 **	Returns the pathname of the user's tty.  Returns NULL if
222 **	the user is not logged in or if s/he has write permission
223 **	denied.
224 **
225 **	Parameters:
226 **		none
227 **
228 **	Returns:
229 **		pathname of the user's tty.
230 **		NULL if not logged in or write permission denied.
231 **
232 **	Side Effects:
233 **		none.
234 **
235 **	WARNING:
236 **		Return value is in a local buffer.
237 **
238 **	Called By:
239 **		savemail
240 */
241 
242 # include <sys/types.h>
243 # include <sys/stat.h>
244 
245 char *
246 ttypath()
247 {
248 	struct stat stbuf;
249 	register int i;
250 	static char pathn[] = "/dev/ttyx";
251 	extern int errno;
252 
253 	/* compute the pathname of the controlling tty */
254 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
255 	{
256 		errno = 0;
257 		return (NULL);
258 	}
259 	pathn[8] = i;
260 
261 	/* see if we have write permission */
262 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
263 	{
264 		errno = 0;
265 		return (NULL);
266 	}
267 
268 	/* see if the user is logged in */
269 	if (getlogin() == NULL)
270 		return (NULL);
271 
272 	/* looks good */
273 	return (pathn);
274 }
275 /*
276 **  FDOPEN -- Open a stdio file given an open file descriptor.
277 **
278 **	This is included here because it is standard in v7, but we
279 **	need it in v6.
280 **
281 **	Algorithm:
282 **		Open /dev/null to create a descriptor.
283 **		Close that descriptor.
284 **		Copy the existing fd into the descriptor.
285 **
286 **	Parameters:
287 **		fd -- the open file descriptor.
288 **		type -- "r", "w", or whatever.
289 **
290 **	Returns:
291 **		The file descriptor it creates.
292 **
293 **	Side Effects:
294 **		none
295 **
296 **	Called By:
297 **		deliver
298 **
299 **	Notes:
300 **		The mode of fd must match "type".
301 */
302 
303 FILE *
304 fdopen(fd, type)
305 	int fd;
306 	char *type;
307 {
308 	register FILE *f;
309 
310 	f = fopen("/dev/null", type);
311 	close(fileno(f));
312 	fileno(f) = fd;
313 	return (f);
314 }
315 /*
316 **  INDEX -- Return pointer to character in string
317 **
318 **	For V7 compatibility.
319 **
320 **	Parameters:
321 **		s -- a string to scan.
322 **		c -- a character to look for.
323 **
324 **	Returns:
325 **		If c is in s, returns the address of the first
326 **			instance of c in s.
327 **		NULL if c is not in s.
328 **
329 **	Side Effects:
330 **		none.
331 */
332 
333 index(s, c)
334 	register char *s;
335 	register char c;
336 {
337 	while (*s != '\0')
338 	{
339 		if (*s++ == c)
340 			return (--s);
341 	}
342 	return (NULL);
343 }
344 # endif V6
345 
346 # ifndef V6
347 /*
348 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
349 **
350 **	Returns the pathname of the user's tty.  Returns NULL if
351 **	the user is not logged in or if s/he has write permission
352 **	denied.
353 **
354 **	Parameters:
355 **		none
356 **
357 **	Returns:
358 **		pathname of the user's tty.
359 **		NULL if not logged in or write permission denied.
360 **
361 **	Side Effects:
362 **		none.
363 **
364 **	WARNING:
365 **		Return value is in a local buffer.
366 **
367 **	Called By:
368 **		savemail
369 */
370 
371 # include <sys/types.h>
372 # include <sys/stat.h>
373 
374 char *
375 ttypath()
376 {
377 	struct stat stbuf;
378 	register char *pathn;
379 	extern int errno;
380 	extern char *ttyname();
381 
382 	/* compute the pathname of the controlling tty */
383 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
384 	{
385 		errno = 0;
386 		return (NULL);
387 	}
388 
389 	/* see if we have write permission */
390 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
391 	{
392 		errno = 0;
393 		return (NULL);
394 	}
395 
396 	/* see if the user is logged in */
397 	if (getlogin() == NULL)
398 		return (NULL);
399 
400 	/* looks good */
401 	return (pathn);
402 }
403 # endif V6
404