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