xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 3046)
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.4	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 /* local mail -- must be #0 */
233 static char	*LocalArgv[] =
234 {
235 	"...local%mail",
236 	"-d",
237 	"$u",
238 	NULL
239 };
240 
241 static struct mailer	LocalMailer =
242 {
243 # ifdef NETV6MAIL
244 	"/usr/net/bin/v6mail",
245 # else
246 	"/bin/mail",
247 # endif
248 	M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT,	EX_NOUSER,	NULL,
249 	"$f",		NULL,			LocalArgv,
250 };
251 
252 /* pipes through programs -- must be #1 */
253 static char	*ProgArgv[] =
254 {
255 	"...prog%mail",
256 	"-fc",
257 	"$u",
258 	NULL
259 };
260 
261 static struct mailer	ProgMailer =
262 {
263 	"/bin/csh",
264 	M_HDR|M_FHDR|M_NOHOST,			EX_UNAVAILABLE,	NULL,
265 	"$f",		NULL,			ProgArgv,
266 };
267 
268 /* local berkeley mail */
269 static char	*BerkArgv[] =
270 {
271 	"...berk%mail",
272 	"-m",
273 	"$h",
274 	"-t",
275 	"$u",
276 	"-h",
277 	"$c",
278 	NULL
279 };
280 
281 static struct mailer	BerkMailer =
282 {
283 	"/usr/net/bin/sendberkmail",
284 	M_FOPT|M_HDR|M_STRIPQ,			EX_UNAVAILABLE,	BerkLocal,
285 	"$B:$f",	NULL,			BerkArgv,
286 };
287 
288 /* arpanet mail */
289 static char	*ArpaArgv[] =
290 {
291 	"...arpa%mail",
292 	"$f",
293 	"$h",
294 	"$u",
295 	NULL
296 };
297 
298 static struct mailer	ArpaMailer =
299 {
300 	"/usr/lib/mailers/arpa",
301 	M_STRIPQ|M_ARPAFMT,			0,		ArpaLocal,
302 	"$f@$A",	NULL,			ArpaArgv,
303 };
304 
305 /* uucp mail (cheat & use Bell's v7 mail) */
306 static char	*UucpArgv[] =
307 {
308 	"...uucp%mail",
309 # ifdef DUMBMAIL
310 	"-d",
311 # endif DUMBMAIL
312 	"$h!$u",
313 	NULL
314 };
315 
316 static struct mailer	UucpMailer =
317 {
318 	"/bin/mail",
319 	M_ROPT|M_STRIPQ,			EX_NOUSER,	UucpLocal,
320 	"$U!$f",	NULL,			UucpArgv,
321 };
322 
323 struct mailer	*Mailer[] =
324 {
325 	&LocalMailer,		/* 0 -- must be 0 */
326 	&ProgMailer,		/* 1 -- must be 1 */
327 	&BerkMailer,		/* 2 */
328 	&ArpaMailer,		/* 3 */
329 	&UucpMailer,		/* 4 */
330 };
331 
332 # define NMAILERS	(sizeof Mailer / sizeof Mailer[0])
333 
334 # define M_LOCAL	0
335 # define M_PROG		1
336 # define M_BERK		2
337 # define M_ARPA		3
338 # define M_UUCP		4
339 
340 /* list of messages for each mailer (sorted by host) */
341 ADDRESS		MailList[NMAILERS];
342 
343 
344 
345 # ifdef BERKELEY
346 struct parsetab ParseTab[] =
347 {
348 	':',	M_BERK,		P_ONE,				NULL,
349 # ifdef HASARPA
350 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
351 # else
352 	'@',	M_BERK,		P_HLAST|P_USR_UPPER|P_MOVE,	"ing70",
353 # endif HASARPA
354 	'^',	-1,		P_MAP,				"!",
355 # ifdef HASUUCP
356 	'!',	M_UUCP,		0,				NULL,
357 # else
358 	'!',	M_BERK,		P_MOVE,				"csvax",
359 # endif HASUUCP
360 	'.',	-1,		P_MAP|P_ONE,			":",
361 	'\0',	M_LOCAL,	P_MOVE,				"",
362 };
363 # else BERKELEY
364 struct parsetab ParseTab[] =
365 {
366 # ifdef HASARPA
367 	'@',	M_ARPA,		P_HLAST|P_USR_UPPER,		NULL,
368 # endif HASARPA
369 # ifdef HASUUCP
370 	'^',	-1,		P_MAP,				"!",
371 	'!',	M_UUCP,		0,				NULL,
372 # endif HASUUCP
373 	'\0',	M_LOCAL,	P_MOVE,				"",
374 };
375 # endif BERKELEY
376 
377 
378 /*
379 **  Header info table
380 */
381 
382 struct hdrinfo	HdrInfo[] =
383 {
384 	"date",		0,
385 	"from",		0,
386 	"to",		H_CONCAT,
387 	"cc",		H_CONCAT,
388 	"subject",	0,
389 	"message-id",	0,
390 	NULL,		0
391 };
392 /*
393 **  INITMACS -- initialize predefined macros.
394 **
395 **	Parameters:
396 **		none.
397 **
398 **	Returns:
399 **		none.
400 **
401 **	Side Effects:
402 **		Macros array gets initialized.
403 */
404 
405 char	*Macro[26];
406 
407 # define MACRO(x)	Macro[x - 'A']
408 
409 initmacs()
410 {
411 	MACRO('A') = ArpaHost;
412 	MACRO('B') = BerkHost;
413 	MACRO('U') = UucpHost;
414 }
415 
416 # ifdef V6
417 /*
418 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
419 **
420 **	Returns the pathname of the user's tty.  Returns NULL if
421 **	the user is not logged in or if s/he has write permission
422 **	denied.
423 **
424 **	Parameters:
425 **		none
426 **
427 **	Returns:
428 **		pathname of the user's tty.
429 **		NULL if not logged in or write permission denied.
430 **
431 **	Side Effects:
432 **		none.
433 **
434 **	WARNING:
435 **		Return value is in a local buffer.
436 **
437 **	Called By:
438 **		savemail
439 */
440 
441 # include <sys/types.h>
442 # include <sys/stat.h>
443 
444 char *
445 ttypath()
446 {
447 	struct stat stbuf;
448 	register int i;
449 	static char pathn[] = "/dev/ttyx";
450 	extern int errno;
451 
452 	/* compute the pathname of the controlling tty */
453 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
454 	{
455 		errno = 0;
456 		return (NULL);
457 	}
458 	pathn[8] = i;
459 
460 	/* see if we have write permission */
461 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
462 	{
463 		errno = 0;
464 		return (NULL);
465 	}
466 
467 	/* see if the user is logged in */
468 	if (getlogin() == NULL)
469 		return (NULL);
470 
471 	/* looks good */
472 	return (pathn);
473 }
474 /*
475 **  FDOPEN -- Open a stdio file given an open file descriptor.
476 **
477 **	This is included here because it is standard in v7, but we
478 **	need it in v6.
479 **
480 **	Algorithm:
481 **		Open /dev/null to create a descriptor.
482 **		Close that descriptor.
483 **		Copy the existing fd into the descriptor.
484 **
485 **	Parameters:
486 **		fd -- the open file descriptor.
487 **		type -- "r", "w", or whatever.
488 **
489 **	Returns:
490 **		The file descriptor it creates.
491 **
492 **	Side Effects:
493 **		none
494 **
495 **	Called By:
496 **		deliver
497 **
498 **	Notes:
499 **		The mode of fd must match "type".
500 */
501 
502 FILE *
503 fdopen(fd, type)
504 	int fd;
505 	char *type;
506 {
507 	register FILE *f;
508 
509 	f = fopen("/dev/null", type);
510 	close(fileno(f));
511 	fileno(f) = fd;
512 	return (f);
513 }
514 /*
515 **  INDEX -- Return pointer to character in string
516 **
517 **	For V7 compatibility.
518 **
519 **	Parameters:
520 **		s -- a string to scan.
521 **		c -- a character to look for.
522 **
523 **	Returns:
524 **		If c is in s, returns the address of the first
525 **			instance of c in s.
526 **		NULL if c is not in s.
527 **
528 **	Side Effects:
529 **		none.
530 */
531 
532 index(s, c)
533 	register char *s;
534 	register char c;
535 {
536 	while (*s != '\0')
537 	{
538 		if (*s++ == c)
539 			return (--s);
540 	}
541 	return (NULL);
542 }
543 # endif V6
544 
545 # ifndef V6
546 /*
547 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
548 **
549 **	Returns the pathname of the user's tty.  Returns NULL if
550 **	the user is not logged in or if s/he has write permission
551 **	denied.
552 **
553 **	Parameters:
554 **		none
555 **
556 **	Returns:
557 **		pathname of the user's tty.
558 **		NULL if not logged in or write permission denied.
559 **
560 **	Side Effects:
561 **		none.
562 **
563 **	WARNING:
564 **		Return value is in a local buffer.
565 **
566 **	Called By:
567 **		savemail
568 */
569 
570 # include <sys/types.h>
571 # include <sys/stat.h>
572 
573 char *
574 ttypath()
575 {
576 	struct stat stbuf;
577 	register char *pathn;
578 	extern int errno;
579 	extern char *ttyname();
580 
581 	/* compute the pathname of the controlling tty */
582 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
583 	{
584 		errno = 0;
585 		return (NULL);
586 	}
587 
588 	/* see if we have write permission */
589 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
590 	{
591 		errno = 0;
592 		return (NULL);
593 	}
594 
595 	/* see if the user is logged in */
596 	if (getlogin() == NULL)
597 		return (NULL);
598 
599 	/* looks good */
600 	return (pathn);
601 }
602 # endif V6
603 /*
604 **  CHECKCOMPAT -- check for From and To person compatible.
605 **
606 **	This routine can be supplied on a per-installation basis
607 **	to determine whether a person is allowed to send a message.
608 **	This allows restriction of certain types of internet
609 **	forwarding or registration of users.
610 **
611 **	If the hosts are found to be incompatible, an error
612 **	message should be given using "usrerr" and FALSE should
613 **	be returned.
614 **
615 **	Parameters:
616 **		to -- the person being sent to.
617 **
618 **	Returns:
619 **		TRUE -- ok to send.
620 **		FALSE -- not ok.
621 **
622 **	Side Effects:
623 **		none (unless you include the usrerr stuff)
624 */
625 
626 bool
627 checkcompat(to)
628 	register ADDRESS *to;
629 {
630 	return (TRUE);
631 }
632