xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 14880)
1 # include <pwd.h>
2 # include "sendmail.h"
3 
4 /*
5 **  CONF.C -- Sendmail Configuration Tables.
6 **
7 **	Defines the configuration of this installation.
8 **
9 **	Compilation Flags:
10 **		V6 -- running on a version 6 system.  This determines
11 **			whether to define certain routines between
12 **			the two systems.  If you are running a funny
13 **			system, e.g., V6 with long tty names, this
14 **			should be checked carefully.
15 **		VMUNIX -- running on a Berkeley UNIX system.
16 **
17 **	Configuration Variables:
18 **		HdrInfo -- a table describing well-known header fields.
19 **			Each entry has the field name and some flags,
20 **			which are described in sendmail.h.
21 **
22 **	Notes:
23 **		I have tried to put almost all the reasonable
24 **		configuration information into the configuration
25 **		file read at runtime.  My intent is that anything
26 **		here is a function of the version of UNIX you
27 **		are running, or is really static -- for example
28 **		the headers are a superset of widely used
29 **		protocols.  If you find yourself playing with
30 **		this file too much, you may be making a mistake!
31 */
32 
33 
34 
35 
36 SCCSID(@(#)conf.c	4.3		08/28/83);
37 
38 
39 
40 /*
41 **  Header info table
42 **	Final (null) entry contains the flags used for any other field.
43 **
44 **	Not all of these are actually handled specially by sendmail
45 **	at this time.  They are included as placeholders, to let
46 **	you know that "someday" I intend to have sendmail do
47 **	something with them.
48 */
49 
50 struct hdrinfo	HdrInfo[] =
51 {
52 		/* originator fields, most to least significant  */
53 	"resent-sender",	H_FROM|H_RESENT,
54 	"resent-from",		H_FROM|H_RESENT,
55 	"sender",		H_FROM,
56 	"from",			H_FROM,
57 	"full-name",		H_ACHECK,
58 	"return-receipt-to",	H_FROM,
59 	"errors-to",		H_FROM,
60 		/* destination fields */
61 	"to",			H_RCPT,
62 	"resent-to",		H_RCPT|H_RESENT,
63 	"cc",			H_RCPT,
64 	"resent-cc",		H_RCPT|H_RESENT,
65 	"bcc",			H_RCPT|H_ACHECK,
66 	"resent-bcc",		H_RCPT|H_ACHECK|H_RESENT,
67 		/* message identification and control */
68 	"message-id",		0,
69 	"resent-message-id",	H_RESENT,
70 	"message",		H_EOH,
71 	"text",			H_EOH,
72 		/* date fields */
73 	"date",			0,
74 	"resent-date",		H_RESENT,
75 		/* trace fields */
76 	"received",		H_TRACE|H_FORCE,
77 	"via",			H_TRACE|H_FORCE,
78 	"mail-from",		H_TRACE|H_FORCE,
79 
80 	NULL,			0,
81 };
82 
83 
84 /*
85 **  ARPANET error message numbers.
86 */
87 
88 char	Arpa_Info[] =		"050";	/* arbitrary info */
89 char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
90 char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
91 char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
92 
93 
94 
95 /*
96 **  Location of system files/databases/etc.
97 */
98 
99 char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
100 char	*FreezeFile =	"/usr/lib/sendmail.fc";	/* frozen version of above */
101 
102 
103 
104 /*
105 **  Some other configuration....
106 */
107 
108 char	SpaceSub =	'.';	/* character to replace <lwsp> in addrs */
109 int	QueueLA =	8;	/* load avg > QueueLA -> just queue */
110 int	RefuseLA =	12;	/* load avg > RefuseLA -> refuse connections */
111 
112 # ifdef V6
113 /*
114 **  TTYNAME -- return name of terminal.
115 **
116 **	Parameters:
117 **		fd -- file descriptor to check.
118 **
119 **	Returns:
120 **		pointer to full path of tty.
121 **		NULL if no tty.
122 **
123 **	Side Effects:
124 **		none.
125 */
126 
127 char *
128 ttyname(fd)
129 	int fd;
130 {
131 	register char tn;
132 	static char pathn[] = "/dev/ttyx";
133 
134 	/* compute the pathname of the controlling tty */
135 	if ((tn = ttyn(fd)) == NULL)
136 	{
137 		errno = 0;
138 		return (NULL);
139 	}
140 	pathn[8] = tn;
141 	return (pathn);
142 }
143 /*
144 **  FDOPEN -- Open a stdio file given an open file descriptor.
145 **
146 **	This is included here because it is standard in v7, but we
147 **	need it in v6.
148 **
149 **	Algorithm:
150 **		Open /dev/null to create a descriptor.
151 **		Close that descriptor.
152 **		Copy the existing fd into the descriptor.
153 **
154 **	Parameters:
155 **		fd -- the open file descriptor.
156 **		type -- "r", "w", or whatever.
157 **
158 **	Returns:
159 **		The file descriptor it creates.
160 **
161 **	Side Effects:
162 **		none
163 **
164 **	Called By:
165 **		deliver
166 **
167 **	Notes:
168 **		The mode of fd must match "type".
169 */
170 
171 FILE *
172 fdopen(fd, type)
173 	int fd;
174 	char *type;
175 {
176 	register FILE *f;
177 
178 	f = fopen("/dev/null", type);
179 	(void) close(fileno(f));
180 	fileno(f) = fd;
181 	return (f);
182 }
183 /*
184 **  INDEX -- Return pointer to character in string
185 **
186 **	For V7 compatibility.
187 **
188 **	Parameters:
189 **		s -- a string to scan.
190 **		c -- a character to look for.
191 **
192 **	Returns:
193 **		If c is in s, returns the address of the first
194 **			instance of c in s.
195 **		NULL if c is not in s.
196 **
197 **	Side Effects:
198 **		none.
199 */
200 
201 char *
202 index(s, c)
203 	register char *s;
204 	register char c;
205 {
206 	while (*s != '\0')
207 	{
208 		if (*s++ == c)
209 			return (--s);
210 	}
211 	return (NULL);
212 }
213 /*
214 **  UMASK -- fake the umask system call.
215 **
216 **	Since V6 always acts like the umask is zero, we will just
217 **	assume the same thing.
218 */
219 
220 /*ARGSUSED*/
221 umask(nmask)
222 {
223 	return (0);
224 }
225 
226 
227 /*
228 **  GETRUID -- get real user id.
229 */
230 
231 getruid()
232 {
233 	return (getuid() & 0377);
234 }
235 
236 
237 /*
238 **  GETRGID -- get real group id.
239 */
240 
241 getrgid()
242 {
243 	return (getgid() & 0377);
244 }
245 
246 
247 /*
248 **  GETEUID -- get effective user id.
249 */
250 
251 geteuid()
252 {
253 	return ((getuid() >> 8) & 0377);
254 }
255 
256 
257 /*
258 **  GETEGID -- get effective group id.
259 */
260 
261 getegid()
262 {
263 	return ((getgid() >> 8) & 0377);
264 }
265 
266 # endif V6
267 
268 # ifndef V6
269 
270 /*
271 **  GETRUID -- get real user id (V7)
272 */
273 
274 getruid()
275 {
276 	if (OpMode == MD_DAEMON)
277 		return (RealUid);
278 	else
279 		return (getuid());
280 }
281 
282 
283 /*
284 **  GETRGID -- get real group id (V7).
285 */
286 
287 getrgid()
288 {
289 	if (OpMode == MD_DAEMON)
290 		return (RealGid);
291 	else
292 		return (getgid());
293 }
294 
295 # endif V6
296 /*
297 **  USERNAME -- return the user id of the logged in user.
298 **
299 **	Parameters:
300 **		none.
301 **
302 **	Returns:
303 **		The login name of the logged in user.
304 **
305 **	Side Effects:
306 **		none.
307 **
308 **	Notes:
309 **		The return value is statically allocated.
310 */
311 
312 char *
313 username()
314 {
315 	extern char *getlogin();
316 
317 	return (getlogin());
318 }
319 /*
320 **  TTYPATH -- Get the path of the user's tty
321 **
322 **	Returns the pathname of the user's tty.  Returns NULL if
323 **	the user is not logged in or if s/he has write permission
324 **	denied.
325 **
326 **	Parameters:
327 **		none
328 **
329 **	Returns:
330 **		pathname of the user's tty.
331 **		NULL if not logged in or write permission denied.
332 **
333 **	Side Effects:
334 **		none.
335 **
336 **	WARNING:
337 **		Return value is in a local buffer.
338 **
339 **	Called By:
340 **		savemail
341 */
342 
343 # include <sys/stat.h>
344 
345 char *
346 ttypath()
347 {
348 	struct stat stbuf;
349 	register char *pathn;
350 	extern char *ttyname();
351 	extern char *getlogin();
352 
353 	/* compute the pathname of the controlling tty */
354 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
355 	    (pathn = ttyname(0)) == NULL)
356 	{
357 		errno = 0;
358 		return (NULL);
359 	}
360 
361 	/* see if we have write permission */
362 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
363 	{
364 		errno = 0;
365 		return (NULL);
366 	}
367 
368 	/* see if the user is logged in */
369 	if (getlogin() == NULL)
370 		return (NULL);
371 
372 	/* looks good */
373 	return (pathn);
374 }
375 /*
376 **  CHECKCOMPAT -- check for From and To person compatible.
377 **
378 **	This routine can be supplied on a per-installation basis
379 **	to determine whether a person is allowed to send a message.
380 **	This allows restriction of certain types of internet
381 **	forwarding or registration of users.
382 **
383 **	If the hosts are found to be incompatible, an error
384 **	message should be given using "usrerr" and FALSE should
385 **	be returned.
386 **
387 **	'NoReturn' can be set to suppress the return-to-sender
388 **	function; this should be done on huge messages.
389 **
390 **	Parameters:
391 **		to -- the person being sent to.
392 **
393 **	Returns:
394 **		TRUE -- ok to send.
395 **		FALSE -- not ok.
396 **
397 **	Side Effects:
398 **		none (unless you include the usrerr stuff)
399 */
400 
401 bool
402 checkcompat(to)
403 	register ADDRESS *to;
404 {
405 # ifdef lint
406 	if (to == NULL)
407 		to++;
408 # endif lint
409 # ifdef EXAMPLE_CODE
410 	/* this code is intended as an example only */
411 	register STAB *s;
412 
413 	s = stab("arpa", ST_MAILER, ST_FIND);
414 	if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer &&
415 	    to->q_mailer == s->s_mailer)
416 	{
417 		usrerr("No ARPA mail through this machine: see your system administration");
418 		/* NoReturn = TRUE; to supress return copy */
419 		return (FALSE);
420 	}
421 # endif EXAMPLE_CODE
422 	return (TRUE);
423 }
424 /*
425 **  HOLDSIGS -- arrange to hold all signals
426 **
427 **	Parameters:
428 **		none.
429 **
430 **	Returns:
431 **		none.
432 **
433 **	Side Effects:
434 **		Arranges that signals are held.
435 */
436 
437 holdsigs()
438 {
439 }
440 /*
441 **  RLSESIGS -- arrange to release all signals
442 **
443 **	This undoes the effect of holdsigs.
444 **
445 **	Parameters:
446 **		none.
447 **
448 **	Returns:
449 **		none.
450 **
451 **	Side Effects:
452 **		Arranges that signals are released.
453 */
454 
455 rlsesigs()
456 {
457 }
458 /*
459 **  GETLA -- get the current load average
460 **
461 **	Parameters:
462 **		none.
463 **
464 **	Returns:
465 **		The current load average as an integer.
466 **
467 **	Side Effects:
468 **		none.
469 */
470 
471 #ifdef VMUNIX
472 
473 #include <nlist.h>
474 
475 struct	nlist Nl[] =
476 {
477 	{ "_avenrun" },
478 #define	X_AVENRUN	0
479 	{ 0 },
480 };
481 
482 getla()
483 {
484 	static int kmem = -1;
485 	double avenrun[3];
486 
487 	if (kmem < 0)
488 	{
489 		kmem = open("/dev/kmem", 0);
490 		if (kmem < 0)
491 			return (-1);
492 		nlist("/vmunix", Nl);
493 		if (Nl[0].n_type == 0)
494 			return (-1);
495 	}
496 	(void) lseek(kmem, (long) Nl[X_AVENRUN].n_value, 0);
497 	(void) read(kmem, avenrun, sizeof(avenrun));
498 	return ((int) (avenrun[0] + 0.5));
499 }
500 
501 #else VMUNIX
502 
503 getla()
504 {
505 	return (0);
506 }
507 
508 #endif VMUNIX
509