xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4166)
1 # include <stdio.h>
2 # include <pwd.h>
3 # include "sendmail.h"
4 
5 /*
6 **  CONF.C -- Sendmail Configuration Tables.
7 **
8 **	Defines the configuration of this installation.
9 **
10 **	Compilation Flags:
11 **		V6 -- running on a version 6 system.  This determines
12 **			whether to define certain routines between
13 **			the two systems.  If you are running a funny
14 **			system, e.g., V6 with long tty names, this
15 **			should be checked carefully.
16 **
17 **	Configuration Variables:
18 **		HdrInfo -- a table describing well-known header fields.
19 **			Each entry has the field name and some flags,
20 **			which are described in sendmail.h.
21 **
22 **	Notes:
23 **		I have tried to put almost all the reasonable
24 **		configuration information into the configuration
25 **		file read at runtime.  My intent is that anything
26 **		here is a function of the version of UNIX you
27 **		are running, or is really static -- for example
28 **		the headers are a superset of widely used
29 **		protocols.  If you find yourself playing with
30 **		this file too much, you may be making a mistake!
31 */
32 
33 
34 
35 
36 static char SccsId[] = "@(#)conf.c	3.18	08/18/81";
37 
38 
39 # include <whoami.h>		/* definitions of machine id's at berkeley */
40 
41 
42 /*
43 **  Header info table
44 **	Final (null) entry contains the flags used for any other field.
45 **
46 **	Not all of these are actually handled specially by sendmail
47 **	at this time.  They are included as placeholders, to let
48 **	you know that "someday" I intend to have sendmail do
49 **	something with them.
50 */
51 
52 struct hdrinfo	HdrInfo[] =
53 {
54 	"date",			H_CHECK,		M_NEEDDATE,
55 	"from",			H_CHECK,		M_NEEDFROM,
56 	"sender",		0,			0,
57 	"full-name",		H_ACHECK,		M_FULLNAME,
58 	"to",			0,			0,
59 	"cc",			0,			0,
60 	"bcc",			0,			0,
61 	"message-id",		H_CHECK,		M_MSGID,
62 	"message",		H_EOH,			0,
63 	"text",			H_EOH,			0,
64 	"posted-date",		0,			0,
65 	"return-receipt-to",	0,			0,
66 	"received-date",	H_CHECK,		M_FINAL,
67 	"received-from",	H_CHECK,		M_FINAL,
68 	"precedence",		0,			0,
69 	"via",			H_FORCE,		0,
70 	NULL,			0,			0,
71 };
72 
73 
74 /*
75 **  ARPANET error message numbers.
76 */
77 
78 # ifdef NEWFTP
79 /* these are almost all unchecked */
80 char	Arpa_Info[] =	"010";	/* arbitrary info: this is WRONG! */
81 char	Arpa_Enter[] =	"354";	/* start mail input */
82 char	Arpa_Mmsg[] =	"250";	/* mail successful (MAIL cmd) */
83 char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
84 char	Arpa_Syserr[] =	"450";	/* some (transient) system error */
85 char	Arpa_Usrerr[] =	"550";	/* some (fatal) user error */
86 # else NEWFTP
87 char	Arpa_Info[] =	"050";	/* arbitrary info */
88 char	Arpa_Enter[] =	"350";	/* start mail input */
89 char	Arpa_Mmsg[] =	"256";	/* mail successful (MAIL cmd) */
90 char	Arpa_Fmsg[] =	"250";	/* mail successful (MLFL cmd) */
91 char	Arpa_Syserr[] =	"455";	/* some (transient) system error */
92 char	Arpa_Usrerr[] =	"450";	/* some (fatal) user error */
93 # endif NEWFTP
94 
95 # ifdef V6
96 /*
97 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
98 **
99 **	Returns the pathname of the user's tty.  Returns NULL if
100 **	the user is not logged in or if s/he has write permission
101 **	denied.
102 **
103 **	Parameters:
104 **		none
105 **
106 **	Returns:
107 **		pathname of the user's tty.
108 **		NULL if not logged in or write permission denied.
109 **
110 **	Side Effects:
111 **		none.
112 **
113 **	WARNING:
114 **		Return value is in a local buffer.
115 **
116 **	Called By:
117 **		savemail
118 */
119 
120 # include <sys/stat.h>
121 
122 char *
123 ttypath()
124 {
125 	struct stat stbuf;
126 	register int i;
127 	static char pathn[] = "/dev/ttyx";
128 
129 	/* compute the pathname of the controlling tty */
130 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
131 	{
132 		errno = 0;
133 		return (NULL);
134 	}
135 	pathn[8] = i;
136 
137 	/* see if we have write permission */
138 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
139 	{
140 		errno = 0;
141 		return (NULL);
142 	}
143 
144 	/* see if the user is logged in */
145 	if (getlogin() == NULL)
146 		return (NULL);
147 
148 	/* looks good */
149 	return (pathn);
150 }
151 /*
152 **  FDOPEN -- Open a stdio file given an open file descriptor.
153 **
154 **	This is included here because it is standard in v7, but we
155 **	need it in v6.
156 **
157 **	Algorithm:
158 **		Open /dev/null to create a descriptor.
159 **		Close that descriptor.
160 **		Copy the existing fd into the descriptor.
161 **
162 **	Parameters:
163 **		fd -- the open file descriptor.
164 **		type -- "r", "w", or whatever.
165 **
166 **	Returns:
167 **		The file descriptor it creates.
168 **
169 **	Side Effects:
170 **		none
171 **
172 **	Called By:
173 **		deliver
174 **
175 **	Notes:
176 **		The mode of fd must match "type".
177 */
178 
179 FILE *
180 fdopen(fd, type)
181 	int fd;
182 	char *type;
183 {
184 	register FILE *f;
185 
186 	f = fopen("/dev/null", type);
187 	(void) close(fileno(f));
188 	fileno(f) = fd;
189 	return (f);
190 }
191 /*
192 **  INDEX -- Return pointer to character in string
193 **
194 **	For V7 compatibility.
195 **
196 **	Parameters:
197 **		s -- a string to scan.
198 **		c -- a character to look for.
199 **
200 **	Returns:
201 **		If c is in s, returns the address of the first
202 **			instance of c in s.
203 **		NULL if c is not in s.
204 **
205 **	Side Effects:
206 **		none.
207 */
208 
209 index(s, c)
210 	register char *s;
211 	register char c;
212 {
213 	while (*s != '\0')
214 	{
215 		if (*s++ == c)
216 			return (--s);
217 	}
218 	return (NULL);
219 }
220 # endif V6
221 
222 # ifndef V6
223 /*
224 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
225 **
226 **	Returns the pathname of the user's tty.  Returns NULL if
227 **	the user is not logged in or if s/he has write permission
228 **	denied.
229 **
230 **	Parameters:
231 **		none
232 **
233 **	Returns:
234 **		pathname of the user's tty.
235 **		NULL if not logged in or write permission denied.
236 **
237 **	Side Effects:
238 **		none.
239 **
240 **	WARNING:
241 **		Return value is in a local buffer.
242 **
243 **	Called By:
244 **		savemail
245 */
246 
247 # include <sys/stat.h>
248 
249 char *
250 ttypath()
251 {
252 	struct stat stbuf;
253 	register char *pathn;
254 	extern char *ttyname();
255 	extern char *getlogin();
256 
257 	/* compute the pathname of the controlling tty */
258 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
259 	{
260 		errno = 0;
261 		return (NULL);
262 	}
263 
264 	/* see if we have write permission */
265 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
266 	{
267 		errno = 0;
268 		return (NULL);
269 	}
270 
271 	/* see if the user is logged in */
272 	if (getlogin() == NULL)
273 		return (NULL);
274 
275 	/* looks good */
276 	return (pathn);
277 }
278 # endif V6
279 /*
280 **  CHECKCOMPAT -- check for From and To person compatible.
281 **
282 **	This routine can be supplied on a per-installation basis
283 **	to determine whether a person is allowed to send a message.
284 **	This allows restriction of certain types of internet
285 **	forwarding or registration of users.
286 **
287 **	If the hosts are found to be incompatible, an error
288 **	message should be given using "usrerr" and FALSE should
289 **	be returned.
290 **
291 **	Parameters:
292 **		to -- the person being sent to.
293 **
294 **	Returns:
295 **		TRUE -- ok to send.
296 **		FALSE -- not ok.
297 **
298 **	Side Effects:
299 **		none (unless you include the usrerr stuff)
300 */
301 
302 bool
303 checkcompat(to)
304 	register ADDRESS *to;
305 {
306 # ifdef lint
307 	ADDRESS *x = to;
308 
309 	to = x;
310 # endif lint
311 
312 	return (TRUE);
313 }
314