xref: /original-bsd/usr.sbin/sendmail/src/conf.c (revision f0fd5f8a)
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 **
21 **	Notes:
22 **		I have tried to put almost all the reasonable
23 **		configuration information into the configuration
24 **		file read at runtime.  My intent is that anything
25 **		here is a function of the version of UNIX you
26 **		are running, or is really static -- for example
27 **		the headers are a superset of widely used
28 **		protocols.  If you find yourself playing with
29 **		this file too much, you may be making a mistake!
30 */
31 
32 
33 
34 
35 SCCSID(@(#)conf.c	3.65		11/28/82);
36 
37 
38 
39 /*
40 **  Header info table
41 **	Final (null) entry contains the flags used for any other field.
42 **
43 **	Not all of these are actually handled specially by sendmail
44 **	at this time.  They are included as placeholders, to let
45 **	you know that "someday" I intend to have sendmail do
46 **	something with them.
47 */
48 
49 struct hdrinfo	HdrInfo[] =
50 {
51 		/* originator fields, most to least significant  */
52 	"resent-sender",	H_FROM,
53 	"resent-from",		H_FROM,
54 	"sender",		H_FROM,
55 	"from",			H_FROM,
56 	"full-name",		H_ACHECK,
57 	"return-receipt-to",	H_FROM,
58 	"errors-to",		H_FROM,
59 		/* destination fields */
60 	"to",			H_RCPT,
61 	"resent-to",		H_RCPT,
62 	"cc",			H_RCPT,
63 	"resent-cc",		H_RCPT,
64 	"bcc",			H_RCPT|H_ACHECK,
65 	"resent-bcc",		H_RCPT|H_ACHECK,
66 		/* message identification and control */
67 	"message",		H_EOH,
68 	"text",			H_EOH,
69 		/* trace fields */
70 	"received",		H_TRACE|H_FORCE,
71 	"via",			H_TRACE|H_FORCE,
72 	"mail-from",		H_TRACE|H_FORCE,
73 
74 	NULL,			0,
75 };
76 
77 
78 /*
79 **  ARPANET error message numbers.
80 */
81 
82 char	Arpa_Info[] =		"050";	/* arbitrary info */
83 char	Arpa_TSyserr[] =	"451";	/* some (transient) system error */
84 char	Arpa_PSyserr[] =	"554";	/* some (permanent) system error */
85 char	Arpa_Usrerr[] =		"554";	/* some (fatal) user error */
86 
87 
88 
89 /*
90 **  Location of system files/databases/etc.
91 */
92 
93 char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
94 char	*FreezeFile =	"/usr/lib/sendmail.fc";	/* frozen version of above */
95 
96 
97 
98 /*
99 **  Some other configuration....
100 */
101 
102 char	SpaceSub =	'.';
103 
104 # ifdef V6
105 /*
106 **  TTYNAME -- return name of terminal.
107 **
108 **	Parameters:
109 **		fd -- file descriptor to check.
110 **
111 **	Returns:
112 **		pointer to full path of tty.
113 **		NULL if no tty.
114 **
115 **	Side Effects:
116 **		none.
117 */
118 
119 char *
120 ttyname(fd)
121 	int fd;
122 {
123 	register char tn;
124 	static char pathn[] = "/dev/ttyx";
125 
126 	/* compute the pathname of the controlling tty */
127 	if ((tn = ttyn(fd)) == NULL)
128 	{
129 		errno = 0;
130 		return (NULL);
131 	}
132 	pathn[8] = tn;
133 	return (pathn);
134 }
135 /*
136 **  FDOPEN -- Open a stdio file given an open file descriptor.
137 **
138 **	This is included here because it is standard in v7, but we
139 **	need it in v6.
140 **
141 **	Algorithm:
142 **		Open /dev/null to create a descriptor.
143 **		Close that descriptor.
144 **		Copy the existing fd into the descriptor.
145 **
146 **	Parameters:
147 **		fd -- the open file descriptor.
148 **		type -- "r", "w", or whatever.
149 **
150 **	Returns:
151 **		The file descriptor it creates.
152 **
153 **	Side Effects:
154 **		none
155 **
156 **	Called By:
157 **		deliver
158 **
159 **	Notes:
160 **		The mode of fd must match "type".
161 */
162 
163 FILE *
164 fdopen(fd, type)
165 	int fd;
166 	char *type;
167 {
168 	register FILE *f;
169 
170 	f = fopen("/dev/null", type);
171 	(void) close(fileno(f));
172 	fileno(f) = fd;
173 	return (f);
174 }
175 /*
176 **  INDEX -- Return pointer to character in string
177 **
178 **	For V7 compatibility.
179 **
180 **	Parameters:
181 **		s -- a string to scan.
182 **		c -- a character to look for.
183 **
184 **	Returns:
185 **		If c is in s, returns the address of the first
186 **			instance of c in s.
187 **		NULL if c is not in s.
188 **
189 **	Side Effects:
190 **		none.
191 */
192 
193 char *
194 index(s, c)
195 	register char *s;
196 	register char c;
197 {
198 	while (*s != '\0')
199 	{
200 		if (*s++ == c)
201 			return (--s);
202 	}
203 	return (NULL);
204 }
205 /*
206 **  UMASK -- fake the umask system call.
207 **
208 **	Since V6 always acts like the umask is zero, we will just
209 **	assume the same thing.
210 */
211 
212 /*ARGSUSED*/
213 umask(nmask)
214 {
215 	return (0);
216 }
217 
218 
219 /*
220 **  GETRUID -- get real user id.
221 */
222 
223 getruid()
224 {
225 	return (getuid() & 0377);
226 }
227 
228 
229 /*
230 **  GETRGID -- get real group id.
231 */
232 
233 getrgid()
234 {
235 	return (getgid() & 0377);
236 }
237 
238 
239 /*
240 **  GETEUID -- get effective user id.
241 */
242 
243 geteuid()
244 {
245 	return ((getuid() >> 8) & 0377);
246 }
247 
248 
249 /*
250 **  GETEGID -- get effective group id.
251 */
252 
253 getegid()
254 {
255 	return ((getgid() >> 8) & 0377);
256 }
257 
258 # endif V6
259 
260 # ifndef V6
261 
262 /*
263 **  GETRUID -- get real user id (V7)
264 */
265 
266 getruid()
267 {
268 	if (OpMode == MD_DAEMON)
269 		return (RealUid);
270 	else
271 		return (getuid());
272 }
273 
274 
275 /*
276 **  GETRGID -- get real group id (V7).
277 */
278 
279 getrgid()
280 {
281 	if (OpMode == MD_DAEMON)
282 		return (RealGid);
283 	else
284 		return (getgid());
285 }
286 
287 # endif V6
288 /*
289 **  USERNAME -- return the user id of the logged in user.
290 **
291 **	Parameters:
292 **		none.
293 **
294 **	Returns:
295 **		The login name of the logged in user.
296 **
297 **	Side Effects:
298 **		none.
299 **
300 **	Notes:
301 **		The return value is statically allocated.
302 */
303 
304 char *
305 username()
306 {
307 	extern char *getlogin();
308 
309 	return (getlogin());
310 }
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 &&
347 	    (pathn = ttyname(0)) == NULL)
348 	{
349 		errno = 0;
350 		return (NULL);
351 	}
352 
353 	/* see if we have write permission */
354 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
355 	{
356 		errno = 0;
357 		return (NULL);
358 	}
359 
360 	/* see if the user is logged in */
361 	if (getlogin() == NULL)
362 		return (NULL);
363 
364 	/* looks good */
365 	return (pathn);
366 }
367 /*
368 **  CHECKCOMPAT -- check for From and To person compatible.
369 **
370 **	This routine can be supplied on a per-installation basis
371 **	to determine whether a person is allowed to send a message.
372 **	This allows restriction of certain types of internet
373 **	forwarding or registration of users.
374 **
375 **	If the hosts are found to be incompatible, an error
376 **	message should be given using "usrerr" and FALSE should
377 **	be returned.
378 **
379 **	'NoReturn' can be set to suppress the return-to-sender
380 **	function; this should be done on huge messages.
381 **
382 **	Parameters:
383 **		to -- the person being sent to.
384 **
385 **	Returns:
386 **		TRUE -- ok to send.
387 **		FALSE -- not ok.
388 **
389 **	Side Effects:
390 **		none (unless you include the usrerr stuff)
391 */
392 
393 bool
394 checkcompat(to)
395 	register ADDRESS *to;
396 {
397 # ifdef ING70
398 	register STAB *s;
399 # endif ING70
400 
401 	if (to->q_mailer != LocalMailer && CurEnv->e_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 && CurEnv->e_from.q_mailer != LocalMailer &&
410 	    to->q_mailer == s->s_mailer)
411 	{
412 		usrerr("No ARPA mail through this machine: see your system administration");
413 		return (FALSE);
414 	}
415 # endif ING70
416 	return (TRUE);
417 }
418 /*
419 **  HOLDSIGS -- arrange to hold all signals
420 **
421 **	Parameters:
422 **		none.
423 **
424 **	Returns:
425 **		none.
426 **
427 **	Side Effects:
428 **		Arranges that signals are held.
429 */
430 
431 holdsigs()
432 {
433 }
434 /*
435 **  RLSESIGS -- arrange to release all signals
436 **
437 **	This undoes the effect of holdsigs.
438 **
439 **	Parameters:
440 **		none.
441 **
442 **	Returns:
443 **		none.
444 **
445 **	Side Effects:
446 **		Arranges that signals are released.
447 */
448 
449 rlsesigs()
450 {
451 }
452