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