xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4180)
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 static char SccsId[] = "@(#)conf.c	3.19	08/20/81";
36 
37 
38 # include <whoami.h>		/* definitions of machine id's at berkeley */
39 
40 
41 /*
42 **  Header info table
43 **	Final (null) entry contains the flags used for any other field.
44 **
45 **	Not all of these are actually handled specially by sendmail
46 **	at this time.  They are included as placeholders, to let
47 **	you know that "someday" I intend to have sendmail do
48 **	something with them.
49 */
50 
51 struct hdrinfo	HdrInfo[] =
52 {
53 	"date",			H_CHECK,		M_NEEDDATE,
54 	"from",			H_CHECK,		M_NEEDFROM,
55 	"sender",		0,			0,
56 	"full-name",		H_ACHECK,		M_FULLNAME,
57 	"to",			0,			0,
58 	"cc",			0,			0,
59 	"bcc",			0,			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_FINAL,
66 	"received-from",	H_CHECK,		M_FINAL,
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 # ifdef V6
95 /*
96 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
97 **
98 **	Returns the pathname of the user's tty.  Returns NULL if
99 **	the user is not logged in or if s/he has write permission
100 **	denied.
101 **
102 **	Parameters:
103 **		none
104 **
105 **	Returns:
106 **		pathname of the user's tty.
107 **		NULL if not logged in or write permission denied.
108 **
109 **	Side Effects:
110 **		none.
111 **
112 **	WARNING:
113 **		Return value is in a local buffer.
114 **
115 **	Called By:
116 **		savemail
117 */
118 
119 # include <sys/stat.h>
120 
121 char *
122 ttypath()
123 {
124 	struct stat stbuf;
125 	register int i;
126 	static char pathn[] = "/dev/ttyx";
127 
128 	/* compute the pathname of the controlling tty */
129 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
130 	{
131 		errno = 0;
132 		return (NULL);
133 	}
134 	pathn[8] = i;
135 
136 	/* see if we have write permission */
137 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
138 	{
139 		errno = 0;
140 		return (NULL);
141 	}
142 
143 	/* see if the user is logged in */
144 	if (getlogin() == NULL)
145 		return (NULL);
146 
147 	/* looks good */
148 	return (pathn);
149 }
150 /*
151 **  FDOPEN -- Open a stdio file given an open file descriptor.
152 **
153 **	This is included here because it is standard in v7, but we
154 **	need it in v6.
155 **
156 **	Algorithm:
157 **		Open /dev/null to create a descriptor.
158 **		Close that descriptor.
159 **		Copy the existing fd into the descriptor.
160 **
161 **	Parameters:
162 **		fd -- the open file descriptor.
163 **		type -- "r", "w", or whatever.
164 **
165 **	Returns:
166 **		The file descriptor it creates.
167 **
168 **	Side Effects:
169 **		none
170 **
171 **	Called By:
172 **		deliver
173 **
174 **	Notes:
175 **		The mode of fd must match "type".
176 */
177 
178 FILE *
179 fdopen(fd, type)
180 	int fd;
181 	char *type;
182 {
183 	register FILE *f;
184 
185 	f = fopen("/dev/null", type);
186 	(void) close(fileno(f));
187 	fileno(f) = fd;
188 	return (f);
189 }
190 /*
191 **  INDEX -- Return pointer to character in string
192 **
193 **	For V7 compatibility.
194 **
195 **	Parameters:
196 **		s -- a string to scan.
197 **		c -- a character to look for.
198 **
199 **	Returns:
200 **		If c is in s, returns the address of the first
201 **			instance of c in s.
202 **		NULL if c is not in s.
203 **
204 **	Side Effects:
205 **		none.
206 */
207 
208 index(s, c)
209 	register char *s;
210 	register char c;
211 {
212 	while (*s != '\0')
213 	{
214 		if (*s++ == c)
215 			return (--s);
216 	}
217 	return (NULL);
218 }
219 # endif V6
220 
221 # ifndef V6
222 /*
223 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
224 **
225 **	Returns the pathname of the user's tty.  Returns NULL if
226 **	the user is not logged in or if s/he has write permission
227 **	denied.
228 **
229 **	Parameters:
230 **		none
231 **
232 **	Returns:
233 **		pathname of the user's tty.
234 **		NULL if not logged in or write permission denied.
235 **
236 **	Side Effects:
237 **		none.
238 **
239 **	WARNING:
240 **		Return value is in a local buffer.
241 **
242 **	Called By:
243 **		savemail
244 */
245 
246 # include <sys/stat.h>
247 
248 char *
249 ttypath()
250 {
251 	struct stat stbuf;
252 	register char *pathn;
253 	extern char *ttyname();
254 	extern char *getlogin();
255 
256 	/* compute the pathname of the controlling tty */
257 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
258 	{
259 		errno = 0;
260 		return (NULL);
261 	}
262 
263 	/* see if we have write permission */
264 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
265 	{
266 		errno = 0;
267 		return (NULL);
268 	}
269 
270 	/* see if the user is logged in */
271 	if (getlogin() == NULL)
272 		return (NULL);
273 
274 	/* looks good */
275 	return (pathn);
276 }
277 # endif V6
278 /*
279 **  CHECKCOMPAT -- check for From and To person compatible.
280 **
281 **	This routine can be supplied on a per-installation basis
282 **	to determine whether a person is allowed to send a message.
283 **	This allows restriction of certain types of internet
284 **	forwarding or registration of users.
285 **
286 **	If the hosts are found to be incompatible, an error
287 **	message should be given using "usrerr" and FALSE should
288 **	be returned.
289 **
290 **	Parameters:
291 **		to -- the person being sent to.
292 **
293 **	Returns:
294 **		TRUE -- ok to send.
295 **		FALSE -- not ok.
296 **
297 **	Side Effects:
298 **		none (unless you include the usrerr stuff)
299 */
300 
301 bool
302 checkcompat(to)
303 	register ADDRESS *to;
304 {
305 # ifdef lint
306 	ADDRESS *x = to;
307 
308 	to = x;
309 # endif lint
310 
311 	return (TRUE);
312 }
313