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