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