xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 2987)
1 # include <stdio.h>
2 # include <pwd.h>
3 # include "postbox.h"
4 
5 /*
6 **  CONF.C -- Postbox Configuration Tables.
7 **
8 **	Defines the configuration of this installation.
9 **
10 **	Compilation Flags:
11 **		HASARPA -- set if this machine has a connection to
12 **			the Arpanet.
13 **		HASUUCP -- set if this machine has a connection to
14 **			the UUCP network.
15 **		NETV6MAIL -- set if you want to use "v6mail" that
16 **			comes with the Berkeley network.  Normally
17 **			/bin/mail will work fine, but around Berkeley
18 **			we use v6mail because it is a "fixed target".
19 **			Also, only v6mail has the "/dev/mail" stuff
20 **			in it (for biff(1)).
21 **		V6 -- running on a version 6 system.  This determines
22 **			whether to define certain routines between
23 **			the two systems.  If you are running a funny
24 **			system, e.g., V6 with long tty names, this
25 **			should be checked carefully.
26 **		DUMBMAIL -- set if your /bin/mail doesn't have the
27 **			-d flag.
28 **
29 **	Configuration Variables:
30 **		ArpaHost -- the arpanet name of the host through
31 **			which arpanet mail will be sent.
32 **		MyLocName -- the name of the host on a local network.
33 **			This is used to disambiguate the contents of
34 **			ArpaHost among many hosts who may be sharing
35 **			a gateway.
36 **		DaemonName -- the name of this agent for use in
37 **			error messages, typically "~MAILER~DAEMON~"
38 **			at this host on the local net.
39 **		ArpaLocal -- a list of local names for this host on
40 **			the arpanet.  Only functional if HASARPA set.
41 **		UucpLocal -- ditto for the Arpanet.
42 **		BerkLocal -- ditto for the Berknet.
43 **		Mailer -- a table of mailers known to the system.
44 **			The fields are:
45 **			- the pathname of the mailer.
46 **			- a list of flags describing the properties
47 **			  of this mailer:
48 **			   M_FOPT -- if set, the mailer has a picky "-f"
49 **				option.  In this mode, the mailer will
50 **				only accept the "-f" option if the
51 **				sender is actually "root", "network",
52 **				and possibly (but not necessarily) if
53 **				the -f argument matches the real sender.
54 **				The effect is that if the "-f" option
55 **				is given to postbox then it will be
56 **				passed through (as arguments 1 & 2) to
57 **				the mailer.
58 **			   M_ROPT -- identical to M_FOPT, except uses
59 **				-r instead.
60 **			   M_QUIET -- if set, don't print a message if
61 **				the mailer returns bad status.
62 **			   M_RESTR -- if set, this mailer is restricted
63 **				to use by "daemon"; otherwise, we do a
64 **				setuid(getuid()) before calling the
65 **				mailer.
66 **			   M_HDR -- if set, the mailer wants us to
67 **				insert a UNIX "From" line before
68 **				outputing.
69 **			   M_FHDR -- if set, the header that we
70 **				generate will be used literally, so
71 **				we must force it to be correct.  The
72 **				effect is that we generate a header
73 **				even if one exists.
74 **			   M_NOHOST -- if set, this mailer doesn't care
75 **				about the host part (e.g., the local
76 **				mailer).
77 **			   M_STRIPQ -- if set, strip quote (`"')
78 **				characters out of parameters as you
79 **				transliterate them into the argument
80 **				vector.  For example, the local mailer
81 **				is called directly, so these should be
82 **				stripped, but the program-mailer (i.e.,
83 **				csh) should leave them in.
84 **			   M_NEEDDATE -- this mailer requires a Date:
85 **				field in the message.
86 **			   M_NEEDFROM -- this mailer requires a From:
87 **				field in the message.
88 **			   M_MSGID -- this mailer requires a Message-Id
89 **				field in the message.
90 **			   M_COMMAS -- this mailer wants comma-
91 **				seperated To: and Cc: fields.
92 **			   M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID|
93 **				M_COMMAS.
94 **			- an exit status to use as the code for the
95 **			  error message print if the mailer returns
96 **			  something we don't understand.
97 **			- A list of names that are to be considered
98 **			  "local" (and hence are stripped off) for
99 **			  this mailer.
100 **			- An argument vector to be passed to the
101 **			  mailer with the following substitutions:
102 **			   $f - the from person name.
103 **			   $u - the target user name.
104 **			   $h - the target user host.
105 **			   $c - the hop count.
106 **			>>>>>>>>>> Entry zero must be for the local
107 **			>> NOTE >> mailer and entry one must be for
108 **			>>>>>>>>>> the shell.
109 **		ParseTab -- a table driving the parsing process.  Each
110 **			entry contains:
111 **			- a character that will trigger this entry.
112 **			- an index into the Mailer table.
113 **			- a word of flags, described in postbox.h.
114 **			- an argument.  If we have P_MAP, it is the
115 **			  character to turn the trigger character into.
116 **			  If we have P_MOVE, it is the site to send it
117 **			  to, using the mailer specified above.
118 **			This table will almost certainly have to be
119 **			changed on your site if you have anything more
120 **			than the UUCP net.
121 **		HdrInfo -- a table describing well-known header fields.
122 **			Each entry has the field name and some flags,
123 **			which can be:
124 **			H_CONCAT -- if there is more than one field
125 **				of this name, turn it into a comma-
126 **				seperated list.
127 **			H_DELETE -- delete this field.
128 */
129 
130 
131 
132 
133 static char SccsId[] = "@(#)conf.c	3.3	03/07/81";
134 
135 
136 # include <whoami.h>		/* definitions of machine id's at berkeley */
137 
138 # ifdef BERKELEY
139 
140 char	*ArpaHost = "Berkeley";	/* host name of gateway on Arpanet */
141 char	*UucpHost = "ucbvax";	/* host name of gateway on UUCP net */
142 # define BerkHost   MyLocName	/* host name of gateway on Berk net */
143 # define NETV6MAIL		/* use /usr/net/bin/v6mail for local delivery */
144 
145 # else BERKELEY
146 
147 char	*ArpaHost = "[unknown]";
148 char	*MyLocName = sysname;
149 # define HASUUCP		/* default to having UUCP net */
150 char	*UucpLocal[] = { sysname, NULL };
151 
152 # endif BERKELEY
153 
154 
155 /* Specific Configurations for Berkeley Machines */
156 
157 /* Berkeley people: mail changes to csvax:eric or they will be lost! */
158 
159 # ifdef ING70
160 static char	*BerkLocal[] = { "i", "ingres", "ing70", NULL };
161 char		*ArpaLocal = { "berkeley", "ucb", NULL };
162 char		*MyLocName = "Ing70";
163 char		*DaemonName = "Ing70:~MAILER~DAEMON~";
164 # define HASARPA
165 # define V6
166 # endif ING70
167 
168 # ifdef INGVAX
169 static char	*BerkLocal[] = { "j", "ingvax", NULL };
170 char		*MyLocName = "IngVax";
171 char		*DaemonName = "IngVax:~MAILER~DAEMON~";
172 # endif INGVAX
173 
174 # ifdef CSVAX
175 static char	*BerkLocal[] = { "v", "csvax", "vax", NULL };
176 static char	*UucpLocal[] = { "ucbvax", "ernie", NULL };
177 char		*MyLocName = "CSVAX";
178 char		*DaemonName = "CSVAX:~MAILER~DAEMON~";
179 # define HASUUCP
180 # endif CSVAX
181 
182 # ifdef ARPAVAX
183 static char	*BerkLocal[] = { "r", "arpavax", NULL };
184 char		*MyLocName = "ARPAVAX";
185 char		*DaemonName = "ARPAVAX:~MAILER~DAEMON~";
186 # endif ARPAVAX
187 
188 # ifdef CORY
189 static char	*BerkLocal[] = { "y", "cory", NULL };
190 char		*MyLocName = "Cory";
191 char		*DaemonName = "Cory:~MAILER~DAEMON~";
192 # endif CORY
193 
194 # ifdef ONYX
195 static char	*BerkLocal[[] = { "x", "onyx", NULL };
196 char		*MyLocName = "Onyx";
197 char		*DaemonName = "Onyx:~MAILER~DAEMON~";
198 # endif ONYX
199 
200 # ifdef IMAGE
201 /* untested */
202 static char	*BerkLocal[] = { "m", "image", NULL };
203 char		*MyLocName = "Image";
204 char		*DaemonName = "Image:~MAILER~DAEMON~";
205 # define V6
206 # endif IMAGE
207 
208 # ifdef ESVAX
209 static char	*BerkLocal[] = { "o", "esvax", NULL };
210 char		*MyLocName = "ESVAX";
211 char		*DaemonName = "ESVAX:~MAILER~DAEMON~";
212 # endif ESVAX
213 
214 # ifdef EECS40
215 /* untested */
216 static char	*BerkLocal[] = { "z", "eecs40", NULL };
217 char		*MyLocName = "EECS40";
218 char		*DaemonName = "EECS40:~MAILER~DAEMON~";
219 # define V6
220 # endif EECS40
221 
222 
223 # ifndef HASARPA
224 # define ArpaLocal	NULL
225 # endif HASARPA
226 
227 # ifndef HASUUCP
228 # define UucpLocal	NULL
229 # endif HASUUCP
230 
231 
232 struct mailer Mailer[] =
233 {
234 	/* local mail -- must be #0 */
235 	{
236 # ifdef NETV6MAIL
237 		"/usr/net/bin/v6mail",
238 # else
239 		"/bin/mail",
240 # endif
241 		M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT,	EX_NOUSER,	NULL,
242 		"$f",		NULL,
243 		{ "...local%mail", "-d", "$u", NULL }
244 	},
245 	/* pipes through programs -- must be #1 */
246 	{
247 		"/bin/csh",
248 		M_HDR|M_FHDR|M_NOHOST,		EX_UNAVAILABLE,	NULL,
249 		"$f",		NULL,
250 		{ "...prog%mail", "-fc", "$u", NULL }
251 	},
252 	/* local berkeley mail */
253 	{
254 		"/usr/net/bin/sendberkmail",
255 		M_FOPT|M_HDR|M_STRIPQ,		EX_UNAVAILABLE,	BerkLocal,
256 		"$B:$f",	NULL,
257 		{ "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL }
258 	},
259 	/* arpanet mail */
260 	{
261 		"/usr/lib/mailers/arpa",
262 		M_STRIPQ|M_ARPAFMT,		0,		ArpaLocal,
263 		"$f@$A",	NULL,
264 		{ "...arpa%mail", "$f", "$h", "$u", NULL }
265 	},
266 	/* uucp mail (cheat & use Bell's v7 mail) */
267 	{
268 		"/bin/mail",
269 		M_ROPT|M_STRIPQ,		EX_NOUSER,	UucpLocal,
270 		"$U!$f",	NULL,
271 # ifdef DUMBMAIL
272 		{ "...uucp%mail", "$h!$u", NULL }
273 # else
274 		{ "...uucp%mail", "-d", "$h!$u", NULL }
275 # endif DUMBMAIL
276 	},
277 };
278 
279 # define M_LOCAL	0
280 # define M_BERK		2
281 # define M_ARPA		3
282 # define M_UUCP		4
283 
284 
285 
286 # ifdef BERKELEY
287 struct parsetab ParseTab[] =
288 {
289 	':',	M_BERK,		P_ONE,				NULL,
290 # ifdef HASARPA
291 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
292 # else
293 	'@',	M_BERK,		P_HLAST|P_USR_UPPER|P_MOVE,	"ing70",
294 # endif HASARPA
295 	'^',	-1,		P_MAP,				"!",
296 # ifdef HASUUCP
297 	'!',	M_UUCP,		0,				NULL,
298 # else
299 	'!',	M_BERK,		P_MOVE,				"csvax",
300 # endif HASUUCP
301 	'.',	-1,		P_MAP|P_ONE,			":",
302 	'\0',	M_LOCAL,	P_MOVE,				"",
303 };
304 # else BERKELEY
305 struct parsetab ParseTab[] =
306 {
307 # ifdef HASARPA
308 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
309 # endif HASARPA
310 # ifdef HASUUCP
311 	'^',	-1,		P_MAP,				"!",
312 	'!',	M_UUCP,		0,				NULL,
313 # endif HASUUCP
314 	'\0',	M_LOCAL,	P_MOVE,				"",
315 };
316 # endif BERKELEY
317 
318 
319 /*
320 **  Header info table
321 */
322 
323 struct hdrinfo	HdrInfo[] =
324 {
325 	"date",		0,
326 	"from",		0,
327 	"to",		H_CONCAT,
328 	"cc",		H_CONCAT,
329 	"subject",	0,
330 	"message-id",	0,
331 	NULL,		0
332 };
333 /*
334 **  INITMACS -- initialize predefined macros.
335 **
336 **	Parameters:
337 **		none.
338 **
339 **	Returns:
340 **		none.
341 **
342 **	Side Effects:
343 **		Macros array gets initialized.
344 */
345 
346 char	*Macro[26];
347 
348 # define MACRO(x)	Macro[x - 'A']
349 
350 initmacs()
351 {
352 	MACRO('A') = ArpaHost;
353 	MACRO('B') = BerkHost;
354 	MACRO('U') = UucpHost;
355 }
356 
357 # ifdef V6
358 /*
359 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
360 **
361 **	Returns the pathname of the user's tty.  Returns NULL if
362 **	the user is not logged in or if s/he has write permission
363 **	denied.
364 **
365 **	Parameters:
366 **		none
367 **
368 **	Returns:
369 **		pathname of the user's tty.
370 **		NULL if not logged in or write permission denied.
371 **
372 **	Side Effects:
373 **		none.
374 **
375 **	WARNING:
376 **		Return value is in a local buffer.
377 **
378 **	Called By:
379 **		savemail
380 */
381 
382 # include <sys/types.h>
383 # include <sys/stat.h>
384 
385 char *
386 ttypath()
387 {
388 	struct stat stbuf;
389 	register int i;
390 	static char pathn[] = "/dev/ttyx";
391 	extern int errno;
392 
393 	/* compute the pathname of the controlling tty */
394 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
395 	{
396 		errno = 0;
397 		return (NULL);
398 	}
399 	pathn[8] = i;
400 
401 	/* see if we have write permission */
402 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
403 	{
404 		errno = 0;
405 		return (NULL);
406 	}
407 
408 	/* see if the user is logged in */
409 	if (getlogin() == NULL)
410 		return (NULL);
411 
412 	/* looks good */
413 	return (pathn);
414 }
415 /*
416 **  FDOPEN -- Open a stdio file given an open file descriptor.
417 **
418 **	This is included here because it is standard in v7, but we
419 **	need it in v6.
420 **
421 **	Algorithm:
422 **		Open /dev/null to create a descriptor.
423 **		Close that descriptor.
424 **		Copy the existing fd into the descriptor.
425 **
426 **	Parameters:
427 **		fd -- the open file descriptor.
428 **		type -- "r", "w", or whatever.
429 **
430 **	Returns:
431 **		The file descriptor it creates.
432 **
433 **	Side Effects:
434 **		none
435 **
436 **	Called By:
437 **		deliver
438 **
439 **	Notes:
440 **		The mode of fd must match "type".
441 */
442 
443 FILE *
444 fdopen(fd, type)
445 	int fd;
446 	char *type;
447 {
448 	register FILE *f;
449 
450 	f = fopen("/dev/null", type);
451 	close(fileno(f));
452 	fileno(f) = fd;
453 	return (f);
454 }
455 /*
456 **  INDEX -- Return pointer to character in string
457 **
458 **	For V7 compatibility.
459 **
460 **	Parameters:
461 **		s -- a string to scan.
462 **		c -- a character to look for.
463 **
464 **	Returns:
465 **		If c is in s, returns the address of the first
466 **			instance of c in s.
467 **		NULL if c is not in s.
468 **
469 **	Side Effects:
470 **		none.
471 */
472 
473 index(s, c)
474 	register char *s;
475 	register char c;
476 {
477 	while (*s != '\0')
478 	{
479 		if (*s++ == c)
480 			return (--s);
481 	}
482 	return (NULL);
483 }
484 # endif V6
485 
486 # ifndef V6
487 /*
488 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
489 **
490 **	Returns the pathname of the user's tty.  Returns NULL if
491 **	the user is not logged in or if s/he has write permission
492 **	denied.
493 **
494 **	Parameters:
495 **		none
496 **
497 **	Returns:
498 **		pathname of the user's tty.
499 **		NULL if not logged in or write permission denied.
500 **
501 **	Side Effects:
502 **		none.
503 **
504 **	WARNING:
505 **		Return value is in a local buffer.
506 **
507 **	Called By:
508 **		savemail
509 */
510 
511 # include <sys/types.h>
512 # include <sys/stat.h>
513 
514 char *
515 ttypath()
516 {
517 	struct stat stbuf;
518 	register char *pathn;
519 	extern int errno;
520 	extern char *ttyname();
521 
522 	/* compute the pathname of the controlling tty */
523 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
524 	{
525 		errno = 0;
526 		return (NULL);
527 	}
528 
529 	/* see if we have write permission */
530 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
531 	{
532 		errno = 0;
533 		return (NULL);
534 	}
535 
536 	/* see if the user is logged in */
537 	if (getlogin() == NULL)
538 		return (NULL);
539 
540 	/* looks good */
541 	return (pathn);
542 }
543 # endif V6
544 /*
545 **  CHECKCOMPAT -- check for From and To person compatible.
546 **
547 **	This routine can be supplied on a per-installation basis
548 **	to determine whether a person is allowed to send a message.
549 **	This allows restriction of certain types of internet
550 **	forwarding or registration of users.
551 **
552 **	If the hosts are found to be incompatible, an error
553 **	message should be given using "usrerr" and FALSE should
554 **	be returned.
555 **
556 **	Parameters:
557 **		to -- the person being sent to.
558 **
559 **	Returns:
560 **		TRUE -- ok to send.
561 **		FALSE -- not ok.
562 **
563 **	Side Effects:
564 **		none (unless you include the usrerr stuff)
565 */
566 
567 bool
568 checkcompat(to)
569 	register ADDRESS *to;
570 {
571 	return (TRUE);
572 }
573