xref: /original-bsd/usr.sbin/sendmail/src/conf.c (revision 552e81d8)
1 # include <stdio.h>
2 # include <pwd.h>
3 # include "dlvrmail.h"
4 
5 static char SccsId[] = "@(#)conf.c	1.7	10/03/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 # define ArpaLocal	NULL
51 char		*MyLocName = "Ing70";
52 # define HASARPA
53 # define V6
54 # endif ING70
55 
56 # ifdef INGVAX
57 /* untested */
58 static char	*BerkLocal[] = { "j", "ingvax", NULL };
59 char		*MyLocName = "IngVax";
60 # endif INGVAX
61 
62 # ifdef CSVAX
63 /* untested */
64 static char	*BerkLocal[] = { "v", "csvax", "vax", NULL };
65 static char	*UucpLocal[] = { "ucbvax", "ernie", NULL };
66 char		*MyLocName = "CSVAX";
67 # define HASUUCP
68 # define NETV6MAIL
69 # endif CSVAX
70 
71 # ifdef CORY
72 /* untested */
73 static char	*BerkLocal[] = { "y", "cory", NULL };
74 char		*MyLocName = "Cory";
75 # endif CORY
76 
77 # ifdef IMAGE
78 /* untested */
79 static char	*BerkLocal[] = { "m", "image", NULL };
80 char		*MyLocName = "Image";
81 # define V6
82 # endif IMAGE
83 
84 # ifdef ESVAX
85 /* untested */
86 static char	*BerkLocal[] = { "o", "esvax", NULL };
87 char		*MyLocName = "ESVAX";
88 # endif ESVAX
89 
90 # ifdef EECS40
91 /* untested */
92 static char	*BerkLocal[] = { "z", "eecs40", NULL };
93 char		*MyLocName = "EECS40";
94 # define V6
95 # endif EECS40
96 
97 
98 # ifndef HASARPA
99 # define ArpaLocal	NULL
100 # endif HASARPA
101 
102 # ifndef HASUUCP
103 # define UucpLocal	NULL
104 # endif HASUUCP
105 
106 
107 struct mailer Mailer[] =
108 {
109 	/* local mail -- must be #0 */
110 	{
111 # ifdef NETV6MAIL
112 		"/usr/net/bin/v6mail",
113 # else
114 		"/bin/mail",
115 # endif
116 		M_ROPT|M_NOHOST|M_STRIPQ,	EX_NOUSER,	NULL,
117 		{ "...local%mail", "-d", "$u", NULL }
118 	},
119 	/* pipes through programs -- must be #1 */
120 	{
121 		"/bin/csh",
122 		M_HDR|M_NOHOST,			EX_UNAVAIL,	NULL,
123 		{ "...prog%mail", "-fc", "$u", NULL }
124 	},
125 	/* local berkeley mail */
126 	{
127 		"/usr/net/bin/sendberkmail",
128 		M_FOPT|M_HDR|M_STRIPQ,		EX_UNAVAIL,	BerkLocal,
129 		{ "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL }
130 	},
131 	/* arpanet mail */
132 	{
133 		"/usr/lib/mailers/arpa",
134 		M_STRIPQ,			0,		ArpaLocal,
135 		{ "...arpa%mail", "$f", "$h", "$u", NULL }
136 	},
137 	/* uucp mail (cheat & use Bell's v7 mail) */
138 	{
139 		"/bin/mail",
140 		M_ROPT|M_STRIPQ,		EX_NOUSER,	UucpLocal,
141 # ifdef DUMBMAIL
142 		{ "...uucp%mail", "$h!$u", NULL }
143 # else
144 		{ "...uucp%mail", "-d", "$h!$u", NULL }
145 # endif DUMBMAIL
146 	},
147 };
148 
149 # define M_LOCAL	0
150 # define M_BERK		2
151 # define M_ARPA		3
152 # define M_UUCP		4
153 
154 
155 
156 struct parsetab ParseTab[] =
157 {
158 	':',	M_BERK,		P_ONE,				NULL,
159 # ifdef HASARPA
160 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
161 # else
162 	'@',	M_BERK,		P_HLAST|P_USR_UPPER|P_MOVE,	"ing70",
163 # endif HASARPA
164 	'^',	-1,		P_MAP,				"!",
165 # ifdef HASUUCP
166 	'!',	M_UUCP,		0,				NULL,
167 # else
168 	'!',	M_BERK,		P_MOVE,				"csvax",
169 # endif HASUUCP
170 	'.',	-1,		P_MAP|P_ONE,			":",
171 	'\0',	M_LOCAL,	P_MOVE,				"",
172 };
173 /*
174 **  GETNAME -- Get the current users login name.
175 **
176 **	This is in config.c because it is somewhat machine dependent.
177 **	Examine it carefully for your installation.
178 **
179 **	Algorithm:
180 **		See if the person is logged in.  If so, return
181 **			the name s/he is logged in as.
182 **		Look up the user id in /etc/passwd.  If found,
183 **			return that name.
184 **		Return NULL.
185 **
186 **	Parameters:
187 **		none
188 **
189 **	Returns:
190 **		The login name of this user.
191 **		NULL if this person is noone.
192 **
193 **	Side Effects:
194 **		none
195 **
196 **	Called By:
197 **		main
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 **	Called By:
247 **		savemail
248 */
249 
250 # include <sys/types.h>
251 # include <sys/stat.h>
252 
253 char *
254 ttypath()
255 {
256 	struct stat stbuf;
257 	register int i;
258 	static char pathn[] = "/dev/ttyx";
259 	extern int errno;
260 
261 	/* compute the pathname of the controlling tty */
262 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
263 	{
264 		errno = 0;
265 		return (NULL);
266 	}
267 	pathn[8] = i;
268 
269 	/* see if we have write permission */
270 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
271 	{
272 		errno = 0;
273 		return (NULL);
274 	}
275 
276 	/* see if the user is logged in */
277 	if (getlogin() == NULL)
278 		return (NULL);
279 
280 	/* looks good */
281 	return (pathn);
282 }
283 /*
284 **  FDOPEN -- Open a stdio file given an open file descriptor.
285 **
286 **	This is included here because it is standard in v7, but we
287 **	need it in v6.
288 **
289 **	Algorithm:
290 **		Open /dev/null to create a descriptor.
291 **		Close that descriptor.
292 **		Copy the existing fd into the descriptor.
293 **
294 **	Parameters:
295 **		fd -- the open file descriptor.
296 **		type -- "r", "w", or whatever.
297 **
298 **	Returns:
299 **		The file descriptor it creates.
300 **
301 **	Side Effects:
302 **		none
303 **
304 **	Called By:
305 **		deliver
306 **
307 **	Notes:
308 **		The mode of fd must match "type".
309 */
310 
311 FILE *
312 fdopen(fd, type)
313 	int fd;
314 	char *type;
315 {
316 	register FILE *f;
317 
318 	f = fopen("/dev/null", type);
319 	close(fileno(f));
320 	fileno(f) = fd;
321 	return (f);
322 }
323 /*
324 **  INDEX -- Return pointer to character in string
325 **
326 **	For V7 compatibility.
327 **
328 **	Parameters:
329 **		s -- a string to scan.
330 **		c -- a character to look for.
331 **
332 **	Returns:
333 **		If c is in s, returns the address of the first
334 **			instance of c in s.
335 **		NULL if c is not in s.
336 **
337 **	Side Effects:
338 **		none.
339 */
340 
341 index(s, c)
342 	register char *s;
343 	register char c;
344 {
345 	while (*s != '\0')
346 	{
347 		if (*s++ == c)
348 			return (--s);
349 	}
350 	return (NULL);
351 }
352 # endif V6
353 
354 # ifndef V6
355 /*
356 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
357 **
358 **	Returns the pathname of the user's tty.  Returns NULL if
359 **	the user is not logged in or if s/he has write permission
360 **	denied.
361 **
362 **	Parameters:
363 **		none
364 **
365 **	Returns:
366 **		pathname of the user's tty.
367 **		NULL if not logged in or write permission denied.
368 **
369 **	Side Effects:
370 **		none.
371 **
372 **	WARNING:
373 **		Return value is in a local buffer.
374 **
375 **	Called By:
376 **		savemail
377 */
378 
379 # include <sys/types.h>
380 # include <sys/stat.h>
381 
382 char *
383 ttypath()
384 {
385 	struct stat stbuf;
386 	register char *pathn;
387 	extern int errno;
388 	extern char *ttyname();
389 
390 	/* compute the pathname of the controlling tty */
391 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
392 	{
393 		errno = 0;
394 		return (NULL);
395 	}
396 
397 	/* see if we have write permission */
398 	if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
399 	{
400 		errno = 0;
401 		return (NULL);
402 	}
403 
404 	/* see if the user is logged in */
405 	if (getlogin() == NULL)
406 		return (NULL);
407 
408 	/* looks good */
409 	return (pathn);
410 }
411 # endif V6
412