xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 3144)
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 **		Mailer -- a table of mailers known to the system.
31 **			The fields are:
32 **			- the pathname of the mailer.
33 **			- a list of flags describing the properties
34 **			  of this mailer:
35 **			   M_FOPT -- if set, the mailer has a picky "-f"
36 **				option.  In this mode, the mailer will
37 **				only accept the "-f" option if the
38 **				sender is actually "root", "network",
39 **				and possibly (but not necessarily) if
40 **				the -f argument matches the real sender.
41 **				The effect is that if the "-f" option
42 **				is given to postbox then it will be
43 **				passed through (as arguments 1 & 2) to
44 **				the mailer.
45 **			   M_ROPT -- identical to M_FOPT, except uses
46 **				-r instead.
47 **			   M_QUIET -- if set, don't print a message if
48 **				the mailer returns bad status.
49 **			   M_RESTR -- if set, this mailer is restricted
50 **				to use by "daemon"; otherwise, we do a
51 **				setuid(getuid()) before calling the
52 **				mailer.
53 **			   M_HDR -- if set, the mailer wants us to
54 **				insert a UNIX "From" line before
55 **				outputing.
56 **			   M_FHDR -- if set, the header that we
57 **				generate will be used literally, so
58 **				we must force it to be correct.  The
59 **				effect is that we generate a header
60 **				even if one exists.
61 **			   M_NOHOST -- if set, this mailer doesn't care
62 **				about the host part (e.g., the local
63 **				mailer).
64 **			   M_STRIPQ -- if set, strip quote (`"')
65 **				characters out of parameters as you
66 **				transliterate them into the argument
67 **				vector.  For example, the local mailer
68 **				is called directly, so these should be
69 **				stripped, but the program-mailer (i.e.,
70 **				csh) should leave them in.
71 **			   M_NEEDDATE -- this mailer requires a Date:
72 **				field in the message.
73 **			   M_NEEDFROM -- this mailer requires a From:
74 **				field in the message.
75 **			   M_MSGID -- this mailer requires a Message-Id
76 **				field in the message.
77 **			   M_COMMAS -- this mailer wants comma-
78 **				seperated To: and Cc: fields.
79 **			   M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID|
80 **				M_COMMAS.
81 **			- an exit status to use as the code for the
82 **			  error message print if the mailer returns
83 **			  something we don't understand.
84 **			- A list of names that are to be considered
85 **			  "local" (and hence are stripped off) for
86 **			  this mailer.
87 **			- An argument vector to be passed to the
88 **			  mailer with the following substitutions:
89 **			   $f - the from person name.
90 **			   $u - the target user name.
91 **			   $h - the target user host.
92 **			   $c - the hop count.
93 **			>>>>>>>>>> Entry zero must be for the local
94 **			>> NOTE >> mailer and entry one must be for
95 **			>>>>>>>>>> the shell.
96 **		HdrInfo -- a table describing well-known header fields.
97 **			Each entry has the field name and some flags,
98 **			which can be:
99 **			- H_EOH -- this field is equivalent to a blank
100 **			  line; i.e., it signifies end of header.
101 **			- H_DELETE -- delete this field.
102 **			There is also a field pointing to a pointer
103 **			that should be set to point to this header.
104 */
105 
106 
107 
108 
109 static char SccsId[] = "@(#)conf.c	3.7	03/09/81";
110 
111 
112 # include <whoami.h>		/* definitions of machine id's at berkeley */
113 
114 # ifdef BERKELEY
115 
116 # define NETV6MAIL		/* use /usr/net/bin/v6mail for local delivery */
117 
118 /* Specific Configurations for Berkeley Machines */
119 
120 /* Berkeley people: mail changes to ingvax:eric or they will be lost! */
121 
122 # ifdef ING70
123 # include "c.ing70.h"
124 # endif ING70
125 
126 # ifdef INGVAX
127 # include "c.ingvax.h"
128 # endif INGVAX
129 
130 # ifdef CSVAX
131 # include "c.csvax.h"
132 # endif CSVAX
133 
134 # ifdef ARPAVAX
135 # include "c.arpavax.h"
136 # endif ARPAVAX
137 
138 # ifdef CORY
139 # include "c.cory.h"
140 # endif CORY
141 
142 # ifdef ONYX
143 # include "c.onyx.h"
144 # endif ONYX
145 
146 # ifdef IMAGE
147 # include "c.image.h"
148 # endif IMAGE
149 
150 # ifdef ESVAX
151 # include "c.esvax.h"
152 # endif ESVAX
153 
154 # ifdef EECS40
155 # include "c.eecs40.h"
156 # endif EECS40
157 
158 # else BERKELEY
159 
160 # define HASUUCP		/* default to having UUCP net */
161 
162 # endif BERKELEY
163 
164 
165 
166 /* local mail -- must be #0 */
167 static char	*LocalArgv[] =
168 {
169 	"...local%mail",
170 	"-d",
171 	"$u",
172 	NULL
173 };
174 
175 static struct mailer	LocalMailer =
176 {
177 # ifdef NETV6MAIL
178 	"/usr/net/bin/v6mail",
179 # else
180 	"/bin/mail",
181 # endif
182 	"local",	M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT,	EX_NOUSER,
183 	"$f",		LocalArgv,
184 };
185 
186 /* pipes through programs -- must be #1 */
187 static char	*ProgArgv[] =
188 {
189 	"...prog%mail",
190 	"-fc",
191 	"$u",
192 	NULL
193 };
194 
195 static struct mailer	ProgMailer =
196 {
197 	"/bin/csh",
198 	"prog",		M_HDR|M_FHDR|M_NOHOST,			EX_UNAVAILABLE,
199 	"$f",		ProgArgv,
200 };
201 
202 /* local berkeley mail */
203 static char	*BerkArgv[] =
204 {
205 	"...berk%mail",
206 	"-m",
207 	"$h",
208 	"-t",
209 	"$u",
210 	"-h",
211 	"$c",
212 	NULL
213 };
214 
215 static struct mailer	BerkMailer =
216 {
217 	"/usr/net/bin/sendberkmail",
218 	"berk",		M_FOPT|M_HDR|M_STRIPQ,			EX_UNAVAILABLE,
219 	"$B:$f",	BerkArgv,
220 };
221 
222 /* arpanet mail */
223 static char	*ArpaArgv[] =
224 {
225 	"...arpa%mail",
226 	"$f",
227 	"$h",
228 	"$u",
229 	NULL
230 };
231 
232 static struct mailer	ArpaMailer =
233 {
234 	"/usr/lib/mailers/arpa",
235 	"arpa",		M_STRIPQ|M_ARPAFMT,			0,
236 	"$f@$A",	ArpaArgv,
237 };
238 
239 /* uucp mail (cheat & use Bell's v7 mail) */
240 static char	*UucpArgv[] =
241 {
242 	"...uucp%mail",
243 # ifdef DUMBMAIL
244 	"-d",
245 # endif DUMBMAIL
246 	"$h!$u",
247 	NULL
248 };
249 
250 static struct mailer	UucpMailer =
251 {
252 	"/bin/mail",
253 	"uucp",		M_ROPT|M_STRIPQ,			EX_NOUSER,
254 	"$U!$f",	UucpArgv,
255 };
256 
257 struct mailer	*Mailer[] =
258 {
259 	&LocalMailer,		/* 0 -- must be 0 */
260 	&ProgMailer,		/* 1 -- must be 1 */
261 	&BerkMailer,		/* 2 */
262 	&ArpaMailer,		/* 3 */
263 	&UucpMailer,		/* 4 */
264 	NULL
265 };
266 
267 # define NMAILERS	((sizeof Mailer / sizeof Mailer[0]) - 1)
268 
269 # define M_LOCAL	0
270 # define M_PROG		1
271 # define M_BERK		2
272 # define M_ARPA		3
273 # define M_UUCP		4
274 
275 /* list of messages for each mailer (sorted by host) */
276 ADDRESS		MailList[NMAILERS];
277 
278 
279 
280 
281 
282 /*
283 **  Header info table
284 **	Final (null) entry contains the flags used for any other field.
285 */
286 
287 struct hdrinfo	HdrInfo[] =
288 {
289 	"date",		0,			NULL,
290 	"from",		0,			NULL,
291 	"to",		0,			NULL,
292 	"cc",		0,			NULL,
293 	"subject",	0,			NULL,
294 	"message-id",	0,			&MsgId,
295 	"message",	H_EOH,			NULL,
296 	NULL,		0,			NULL,
297 };
298 
299 # ifdef V6
300 /*
301 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
302 **
303 **	Returns the pathname of the user's tty.  Returns NULL if
304 **	the user is not logged in or if s/he has write permission
305 **	denied.
306 **
307 **	Parameters:
308 **		none
309 **
310 **	Returns:
311 **		pathname of the user's tty.
312 **		NULL if not logged in or write permission denied.
313 **
314 **	Side Effects:
315 **		none.
316 **
317 **	WARNING:
318 **		Return value is in a local buffer.
319 **
320 **	Called By:
321 **		savemail
322 */
323 
324 # include <sys/types.h>
325 # include <sys/stat.h>
326 
327 char *
328 ttypath()
329 {
330 	struct stat stbuf;
331 	register int i;
332 	static char pathn[] = "/dev/ttyx";
333 	extern int errno;
334 
335 	/* compute the pathname of the controlling tty */
336 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
337 	{
338 		errno = 0;
339 		return (NULL);
340 	}
341 	pathn[8] = i;
342 
343 	/* see if we have write permission */
344 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
345 	{
346 		errno = 0;
347 		return (NULL);
348 	}
349 
350 	/* see if the user is logged in */
351 	if (getlogin() == NULL)
352 		return (NULL);
353 
354 	/* looks good */
355 	return (pathn);
356 }
357 /*
358 **  FDOPEN -- Open a stdio file given an open file descriptor.
359 **
360 **	This is included here because it is standard in v7, but we
361 **	need it in v6.
362 **
363 **	Algorithm:
364 **		Open /dev/null to create a descriptor.
365 **		Close that descriptor.
366 **		Copy the existing fd into the descriptor.
367 **
368 **	Parameters:
369 **		fd -- the open file descriptor.
370 **		type -- "r", "w", or whatever.
371 **
372 **	Returns:
373 **		The file descriptor it creates.
374 **
375 **	Side Effects:
376 **		none
377 **
378 **	Called By:
379 **		deliver
380 **
381 **	Notes:
382 **		The mode of fd must match "type".
383 */
384 
385 FILE *
386 fdopen(fd, type)
387 	int fd;
388 	char *type;
389 {
390 	register FILE *f;
391 
392 	f = fopen("/dev/null", type);
393 	close(fileno(f));
394 	fileno(f) = fd;
395 	return (f);
396 }
397 /*
398 **  INDEX -- Return pointer to character in string
399 **
400 **	For V7 compatibility.
401 **
402 **	Parameters:
403 **		s -- a string to scan.
404 **		c -- a character to look for.
405 **
406 **	Returns:
407 **		If c is in s, returns the address of the first
408 **			instance of c in s.
409 **		NULL if c is not in s.
410 **
411 **	Side Effects:
412 **		none.
413 */
414 
415 index(s, c)
416 	register char *s;
417 	register char c;
418 {
419 	while (*s != '\0')
420 	{
421 		if (*s++ == c)
422 			return (--s);
423 	}
424 	return (NULL);
425 }
426 # endif V6
427 
428 # ifndef V6
429 /*
430 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
431 **
432 **	Returns the pathname of the user's tty.  Returns NULL if
433 **	the user is not logged in or if s/he has write permission
434 **	denied.
435 **
436 **	Parameters:
437 **		none
438 **
439 **	Returns:
440 **		pathname of the user's tty.
441 **		NULL if not logged in or write permission denied.
442 **
443 **	Side Effects:
444 **		none.
445 **
446 **	WARNING:
447 **		Return value is in a local buffer.
448 **
449 **	Called By:
450 **		savemail
451 */
452 
453 # include <sys/types.h>
454 # include <sys/stat.h>
455 
456 char *
457 ttypath()
458 {
459 	struct stat stbuf;
460 	register char *pathn;
461 	extern int errno;
462 	extern char *ttyname();
463 
464 	/* compute the pathname of the controlling tty */
465 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
466 	{
467 		errno = 0;
468 		return (NULL);
469 	}
470 
471 	/* see if we have write permission */
472 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
473 	{
474 		errno = 0;
475 		return (NULL);
476 	}
477 
478 	/* see if the user is logged in */
479 	if (getlogin() == NULL)
480 		return (NULL);
481 
482 	/* looks good */
483 	return (pathn);
484 }
485 # endif V6
486 /*
487 **  CHECKCOMPAT -- check for From and To person compatible.
488 **
489 **	This routine can be supplied on a per-installation basis
490 **	to determine whether a person is allowed to send a message.
491 **	This allows restriction of certain types of internet
492 **	forwarding or registration of users.
493 **
494 **	If the hosts are found to be incompatible, an error
495 **	message should be given using "usrerr" and FALSE should
496 **	be returned.
497 **
498 **	Parameters:
499 **		to -- the person being sent to.
500 **
501 **	Returns:
502 **		TRUE -- ok to send.
503 **		FALSE -- not ok.
504 **
505 **	Side Effects:
506 **		none (unless you include the usrerr stuff)
507 */
508 
509 bool
510 checkcompat(to)
511 	register ADDRESS *to;
512 {
513 	return (TRUE);
514 }
515