xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 8247)
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 **
16 **	Configuration Variables:
17 **		HdrInfo -- a table describing well-known header fields.
18 **			Each entry has the field name and some flags,
19 **			which are described in sendmail.h.
20 **		StdTimezone -- name of local timezone in standard time
21 **			(V6 only).
22 **		DstTimezone -- name of local timezone in daylight savings
23 **			time (V6 only).
24 **
25 **	Notes:
26 **		I have tried to put almost all the reasonable
27 **		configuration information into the configuration
28 **		file read at runtime.  My intent is that anything
29 **		here is a function of the version of UNIX you
30 **		are running, or is really static -- for example
31 **		the headers are a superset of widely used
32 **		protocols.  If you find yourself playing with
33 **		this file too much, you may be making a mistake!
34 */
35 
36 
37 
38 
39 SCCSID(@(#)conf.c	3.57		09/24/82);
40 
41 
42 
43 /*
44 **  Header info table
45 **	Final (null) entry contains the flags used for any other field.
46 **
47 **	Not all of these are actually handled specially by sendmail
48 **	at this time.  They are included as placeholders, to let
49 **	you know that "someday" I intend to have sendmail do
50 **	something with them.
51 */
52 
53 struct hdrinfo	HdrInfo[] =
54 {
55 		/* date information */
56 	"posted-date",		0,			0,
57 	"date",			H_CHECK,		M_NEEDDATE,
58 	"resent-date",		0,			0,
59 	"received-date",	H_CHECK,		M_LOCAL,
60 		/* originator fields, most to least significant  */
61 	"resent-sender",	H_FROM,			0,
62 	"resent-from",		H_FROM,			0,
63 	"sender",		H_FROM,			0,
64 	"from",			H_FROM|H_CHECK,		M_NEEDFROM,
65 	"full-name",		H_ACHECK,		M_FULLNAME,
66 	"received-from",	H_CHECK,		M_LOCAL,
67 	"return-receipt-to",	H_FROM,			0,
68 	"errors-to",		H_FROM,			0,
69 		/* destination fields */
70 	"to",			H_RCPT,			0,
71 	"resent-to",		H_RCPT,			0,
72 	"cc",			H_RCPT,			0,
73 	"resent-cc",		H_RCPT,			0,
74 	"bcc",			H_RCPT,			0,
75 	"resent-bcc",		H_RCPT,			0,
76 		/* message identification and control */
77 	"message-id",		0,			0,
78 	"resent-message-id",	0,			0,
79 	"precedence",		0,			0,
80 	"message",		H_EOH,			0,
81 	"text",			H_EOH,			0,
82 		/* trace fields */
83 	"received",		H_TRACE|H_FORCE,	0,
84 	"via",			H_TRACE|H_FORCE,	0,
85 	"mail-from",		H_TRACE|H_FORCE,	0,
86 
87 	NULL,			0,			0,
88 };
89 
90 
91 /*
92 **  ARPANET error message numbers.
93 */
94 
95 char	Arpa_Info[] =		"050";	/* arbitrary info */
96 char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
97 char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
98 char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
99 
100 
101 
102 
103 
104 /*
105 **  Location of system files/databases/etc.
106 */
107 
108 char	*AliasFile =	"/usr/lib/aliases";	/* alias file */
109 char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
110 char	*StatFile =	"/usr/lib/sendmail.st";	/* statistics summary */
111 char	*HelpFile =	"/usr/lib/sendmail.hf";	/* help file */
112 # ifdef QUEUE
113 char	*QueueDir =	"/usr/spool/mqueue";	/* queue of saved mail */
114 # else QUEUE
115 char	*QueueDir =	"/tmp";			/* location of temp files */
116 # endif QUEUE
117 char	*XcriptFile =	"/tmp/mailxXXXXXX";	/* template for transcript */
118 
119 
120 /*
121 **  Other configuration.
122 */
123 
124 int	DefUid =	1;		/* the uid to execute mailers as */
125 int	DefGid =	1;		/* ditto for gid */
126 time_t	TimeOut =	3*24*60*60L;	/* default timeout for queue files */
127 int	ReadTimeout =	10*60;		/* timeout on external reads */
128 int	LogLevel =	9;		/* default logging level */
129 
130 
131 
132 /*
133 **  V6 system configuration.
134 */
135 
136 # ifdef V6
137 char	*StdTimezone =	"PST";		/* std time timezone */
138 char	*DstTimezone =	"PDT";		/* daylight time timezone */
139 # endif V6
140 
141 # ifdef V6
142 /*
143 **  TTYNAME -- return name of terminal.
144 **
145 **	Parameters:
146 **		fd -- file descriptor to check.
147 **
148 **	Returns:
149 **		pointer to full path of tty.
150 **		NULL if no tty.
151 **
152 **	Side Effects:
153 **		none.
154 */
155 
156 char *
157 ttyname(fd)
158 	int fd;
159 {
160 	register char tn;
161 	static char pathn[] = "/dev/ttyx";
162 
163 	/* compute the pathname of the controlling tty */
164 	if ((tn = ttyn(fd)) == NULL)
165 	{
166 		errno = 0;
167 		return (NULL);
168 	}
169 	pathn[8] = tn;
170 	return (pathn);
171 }
172 /*
173 **  FDOPEN -- Open a stdio file given an open file descriptor.
174 **
175 **	This is included here because it is standard in v7, but we
176 **	need it in v6.
177 **
178 **	Algorithm:
179 **		Open /dev/null to create a descriptor.
180 **		Close that descriptor.
181 **		Copy the existing fd into the descriptor.
182 **
183 **	Parameters:
184 **		fd -- the open file descriptor.
185 **		type -- "r", "w", or whatever.
186 **
187 **	Returns:
188 **		The file descriptor it creates.
189 **
190 **	Side Effects:
191 **		none
192 **
193 **	Called By:
194 **		deliver
195 **
196 **	Notes:
197 **		The mode of fd must match "type".
198 */
199 
200 FILE *
201 fdopen(fd, type)
202 	int fd;
203 	char *type;
204 {
205 	register FILE *f;
206 
207 	f = fopen("/dev/null", type);
208 	(void) close(fileno(f));
209 	fileno(f) = fd;
210 	return (f);
211 }
212 /*
213 **  INDEX -- Return pointer to character in string
214 **
215 **	For V7 compatibility.
216 **
217 **	Parameters:
218 **		s -- a string to scan.
219 **		c -- a character to look for.
220 **
221 **	Returns:
222 **		If c is in s, returns the address of the first
223 **			instance of c in s.
224 **		NULL if c is not in s.
225 **
226 **	Side Effects:
227 **		none.
228 */
229 
230 char *
231 index(s, c)
232 	register char *s;
233 	register char c;
234 {
235 	while (*s != '\0')
236 	{
237 		if (*s++ == c)
238 			return (--s);
239 	}
240 	return (NULL);
241 }
242 /*
243 **  UMASK -- fake the umask system call.
244 **
245 **	Since V6 always acts like the umask is zero, we will just
246 **	assume the same thing.
247 */
248 
249 /*ARGSUSED*/
250 umask(nmask)
251 {
252 	return (0);
253 }
254 
255 
256 /*
257 **  GETRUID -- get real user id.
258 */
259 
260 getruid()
261 {
262 	return (getuid() & 0377);
263 }
264 
265 
266 /*
267 **  GETRGID -- get real group id.
268 */
269 
270 getrgid()
271 {
272 	return (getgid() & 0377);
273 }
274 
275 
276 /*
277 **  GETEUID -- get effective user id.
278 */
279 
280 geteuid()
281 {
282 	return ((getuid() >> 8) & 0377);
283 }
284 
285 
286 /*
287 **  GETEGID -- get effective group id.
288 */
289 
290 getegid()
291 {
292 	return ((getgid() >> 8) & 0377);
293 }
294 
295 # endif V6
296 
297 # ifndef V6
298 
299 /*
300 **  GETRUID -- get real user id (V7)
301 */
302 
303 getruid()
304 {
305 	if (Mode == MD_DAEMON)
306 		return (RealUid);
307 	else
308 		return (getuid());
309 }
310 
311 
312 /*
313 **  GETRGID -- get real group id (V7).
314 */
315 
316 getrgid()
317 {
318 	if (Mode == MD_DAEMON)
319 		return (RealGid);
320 	else
321 		return (getgid());
322 }
323 
324 # endif V6
325 /*
326 **  TTYPATH -- Get the path of the user's tty
327 **
328 **	Returns the pathname of the user's tty.  Returns NULL if
329 **	the user is not logged in or if s/he has write permission
330 **	denied.
331 **
332 **	Parameters:
333 **		none
334 **
335 **	Returns:
336 **		pathname of the user's tty.
337 **		NULL if not logged in or write permission denied.
338 **
339 **	Side Effects:
340 **		none.
341 **
342 **	WARNING:
343 **		Return value is in a local buffer.
344 **
345 **	Called By:
346 **		savemail
347 */
348 
349 # include <sys/stat.h>
350 
351 char *
352 ttypath()
353 {
354 	struct stat stbuf;
355 	register char *pathn;
356 	extern char *ttyname();
357 	extern char *getlogin();
358 
359 	/* compute the pathname of the controlling tty */
360 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
361 	{
362 		errno = 0;
363 		return (NULL);
364 	}
365 
366 	/* see if we have write permission */
367 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
368 	{
369 		errno = 0;
370 		return (NULL);
371 	}
372 
373 	/* see if the user is logged in */
374 	if (getlogin() == NULL)
375 		return (NULL);
376 
377 	/* looks good */
378 	return (pathn);
379 }
380 /*
381 **  CHECKCOMPAT -- check for From and To person compatible.
382 **
383 **	This routine can be supplied on a per-installation basis
384 **	to determine whether a person is allowed to send a message.
385 **	This allows restriction of certain types of internet
386 **	forwarding or registration of users.
387 **
388 **	If the hosts are found to be incompatible, an error
389 **	message should be given using "usrerr" and FALSE should
390 **	be returned.
391 **
392 **	'NoReturn' can be set to suppress the return-to-sender
393 **	function; this should be done on huge messages.
394 **
395 **	Parameters:
396 **		to -- the person being sent to.
397 **
398 **	Returns:
399 **		TRUE -- ok to send.
400 **		FALSE -- not ok.
401 **
402 **	Side Effects:
403 **		none (unless you include the usrerr stuff)
404 */
405 
406 bool
407 checkcompat(to)
408 	register ADDRESS *to;
409 {
410 # ifdef ING70
411 	register STAB *s;
412 # endif ING70
413 
414 	if (to->q_mailer != LocalMailer && CurEnv->e_msgsize > 100000)
415 	{
416 		usrerr("Message exceeds 100000 bytes");
417 		NoReturn++;
418 		return (FALSE);
419 	}
420 # ifdef ING70
421 	s = stab("arpa", ST_MAILER, ST_FIND);
422 	if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && to->q_mailer == s->s_mailer)
423 	{
424 		usrerr("No ARPA mail through this machine: see your system administration");
425 		return (FALSE);
426 	}
427 # endif ING70
428 	return (TRUE);
429 }
430