xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4282)
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.26	08/31/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 	"original-from",	H_ACHECK,		0,		/* internal */
56 	"sender",		0,			0,
57 	"full-name",		H_ACHECK,		M_FULLNAME,
58 	"to",			H_ADDR,			0,
59 	"cc",			H_ADDR,			0,
60 	"bcc",			H_ADDR|H_ACHECK,	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_LOCAL,
67 	"received-from",	H_CHECK,		M_LOCAL,
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 
96 
97 
98 
99 /*
100 **  Location of system files/databases/etc.
101 */
102 
103 char	*AliasFile =	"/usr/lib/aliases";	/* alias file */
104 char	*ConfFile =	"/usr/lib/sendmail.cf";	/* runtime configuration */
105 char	*StatFile =	"/usr/eric/mailstats";	/* statistics summary */
106 
107 # ifdef V6
108 /*
109 **  TTYNAME -- return name of terminal.
110 **
111 **	Parameters:
112 **		fd -- file descriptor to check.
113 **
114 **	Returns:
115 **		pointer to full path of tty.
116 **		NULL if no tty.
117 **
118 **	Side Effects:
119 **		none.
120 */
121 
122 char *
123 ttyname(fd)
124 	int fd;
125 {
126 	register char tn;
127 	static char pathn[] = "/dev/ttyx";
128 
129 	/* compute the pathname of the controlling tty */
130 	if ((tn = ttyn(fd)) == NULL)
131 	{
132 		errno = 0;
133 		return (NULL);
134 	}
135 	pathn[8] = tn;
136 	return (pathn);
137 }
138 /*
139 **  FDOPEN -- Open a stdio file given an open file descriptor.
140 **
141 **	This is included here because it is standard in v7, but we
142 **	need it in v6.
143 **
144 **	Algorithm:
145 **		Open /dev/null to create a descriptor.
146 **		Close that descriptor.
147 **		Copy the existing fd into the descriptor.
148 **
149 **	Parameters:
150 **		fd -- the open file descriptor.
151 **		type -- "r", "w", or whatever.
152 **
153 **	Returns:
154 **		The file descriptor it creates.
155 **
156 **	Side Effects:
157 **		none
158 **
159 **	Called By:
160 **		deliver
161 **
162 **	Notes:
163 **		The mode of fd must match "type".
164 */
165 
166 FILE *
167 fdopen(fd, type)
168 	int fd;
169 	char *type;
170 {
171 	register FILE *f;
172 
173 	f = fopen("/dev/null", type);
174 	(void) close(fileno(f));
175 	fileno(f) = fd;
176 	return (f);
177 }
178 /*
179 **  INDEX -- Return pointer to character in string
180 **
181 **	For V7 compatibility.
182 **
183 **	Parameters:
184 **		s -- a string to scan.
185 **		c -- a character to look for.
186 **
187 **	Returns:
188 **		If c is in s, returns the address of the first
189 **			instance of c in s.
190 **		NULL if c is not in s.
191 **
192 **	Side Effects:
193 **		none.
194 */
195 
196 index(s, c)
197 	register char *s;
198 	register char c;
199 {
200 	while (*s != '\0')
201 	{
202 		if (*s++ == c)
203 			return (--s);
204 	}
205 	return (NULL);
206 }
207 # endif V6
208 /*
209 **  TTYPATH -- Get the path of the user's tty
210 **
211 **	Returns the pathname of the user's tty.  Returns NULL if
212 **	the user is not logged in or if s/he has write permission
213 **	denied.
214 **
215 **	Parameters:
216 **		none
217 **
218 **	Returns:
219 **		pathname of the user's tty.
220 **		NULL if not logged in or write permission denied.
221 **
222 **	Side Effects:
223 **		none.
224 **
225 **	WARNING:
226 **		Return value is in a local buffer.
227 **
228 **	Called By:
229 **		savemail
230 */
231 
232 # include <sys/stat.h>
233 
234 char *
235 ttypath()
236 {
237 	struct stat stbuf;
238 	register char *pathn;
239 	extern char *ttyname();
240 	extern char *getlogin();
241 
242 	/* compute the pathname of the controlling tty */
243 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
244 	{
245 		errno = 0;
246 		return (NULL);
247 	}
248 
249 	/* see if we have write permission */
250 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
251 	{
252 		errno = 0;
253 		return (NULL);
254 	}
255 
256 	/* see if the user is logged in */
257 	if (getlogin() == NULL)
258 		return (NULL);
259 
260 	/* looks good */
261 	return (pathn);
262 }
263 /*
264 **  CHECKCOMPAT -- check for From and To person compatible.
265 **
266 **	This routine can be supplied on a per-installation basis
267 **	to determine whether a person is allowed to send a message.
268 **	This allows restriction of certain types of internet
269 **	forwarding or registration of users.
270 **
271 **	If the hosts are found to be incompatible, an error
272 **	message should be given using "usrerr" and FALSE should
273 **	be returned.
274 **
275 **	Parameters:
276 **		to -- the person being sent to.
277 **
278 **	Returns:
279 **		TRUE -- ok to send.
280 **		FALSE -- not ok.
281 **
282 **	Side Effects:
283 **		none (unless you include the usrerr stuff)
284 */
285 
286 bool
287 checkcompat(to)
288 	register ADDRESS *to;
289 {
290 # ifdef lint
291 	ADDRESS *x = to;
292 
293 	to = x;
294 # endif lint
295 
296 	return (TRUE);
297 }
298