xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4093)
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 can be:
21 **			- H_EOH -- this field is equivalent to a blank
22 **			  line; i.e., it signifies end of header.
23 **			- H_DELETE -- delete this field.
24 **			There is also a field pointing to a pointer
25 **			that should be set to point to this header.
26 **
27 **	Notes:
28 **		I have tried to put almost all the reasonable
29 **		configuration information into the configuration
30 **		file read at runtime.  My intent is that anything
31 **		here is a function of the version of UNIX you
32 **		are running, or is really static -- for example
33 **		the headers are a superset of widely used
34 **		protocols.  If you find yourself playing with
35 **		this file too much, you may be making a mistake!
36 */
37 
38 
39 
40 
41 static char SccsId[] = "@(#)conf.c	3.16	08/09/81";
42 
43 
44 # include <whoami.h>		/* definitions of machine id's at berkeley */
45 
46 
47 /*
48 **  Header info table
49 **	Final (null) entry contains the flags used for any other field.
50 */
51 
52 struct hdrinfo	HdrInfo[] =
53 {
54 	"date",		H_CHECK,		M_NEEDDATE,
55 	"from",		H_CHECK,		M_NEEDFROM,
56 	"full-name",	H_ACHECK,		M_FULLNAME,
57 	"to",		0,			NULL,
58 	"cc",		0,			NULL,
59 	"subject",	0,			NULL,
60 	"message-id",	H_CHECK,		M_MSGID,
61 	"message",	H_EOH,			NULL,
62 	NULL,		0,			NULL,
63 };
64 
65 # ifdef V6
66 /*
67 **  TTYPATH -- Get the path of the user's tty -- Version 6 version.
68 **
69 **	Returns the pathname of the user's tty.  Returns NULL if
70 **	the user is not logged in or if s/he has write permission
71 **	denied.
72 **
73 **	Parameters:
74 **		none
75 **
76 **	Returns:
77 **		pathname of the user's tty.
78 **		NULL if not logged in or write permission denied.
79 **
80 **	Side Effects:
81 **		none.
82 **
83 **	WARNING:
84 **		Return value is in a local buffer.
85 **
86 **	Called By:
87 **		savemail
88 */
89 
90 # include <sys/types.h>
91 # include <sys/stat.h>
92 
93 char *
94 ttypath()
95 {
96 	struct stat stbuf;
97 	register int i;
98 	static char pathn[] = "/dev/ttyx";
99 
100 	/* compute the pathname of the controlling tty */
101 	if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
102 	{
103 		errno = 0;
104 		return (NULL);
105 	}
106 	pathn[8] = i;
107 
108 	/* see if we have write permission */
109 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
110 	{
111 		errno = 0;
112 		return (NULL);
113 	}
114 
115 	/* see if the user is logged in */
116 	if (getlogin() == NULL)
117 		return (NULL);
118 
119 	/* looks good */
120 	return (pathn);
121 }
122 /*
123 **  FDOPEN -- Open a stdio file given an open file descriptor.
124 **
125 **	This is included here because it is standard in v7, but we
126 **	need it in v6.
127 **
128 **	Algorithm:
129 **		Open /dev/null to create a descriptor.
130 **		Close that descriptor.
131 **		Copy the existing fd into the descriptor.
132 **
133 **	Parameters:
134 **		fd -- the open file descriptor.
135 **		type -- "r", "w", or whatever.
136 **
137 **	Returns:
138 **		The file descriptor it creates.
139 **
140 **	Side Effects:
141 **		none
142 **
143 **	Called By:
144 **		deliver
145 **
146 **	Notes:
147 **		The mode of fd must match "type".
148 */
149 
150 FILE *
151 fdopen(fd, type)
152 	int fd;
153 	char *type;
154 {
155 	register FILE *f;
156 
157 	f = fopen("/dev/null", type);
158 	(void) close(fileno(f));
159 	fileno(f) = fd;
160 	return (f);
161 }
162 /*
163 **  INDEX -- Return pointer to character in string
164 **
165 **	For V7 compatibility.
166 **
167 **	Parameters:
168 **		s -- a string to scan.
169 **		c -- a character to look for.
170 **
171 **	Returns:
172 **		If c is in s, returns the address of the first
173 **			instance of c in s.
174 **		NULL if c is not in s.
175 **
176 **	Side Effects:
177 **		none.
178 */
179 
180 index(s, c)
181 	register char *s;
182 	register char c;
183 {
184 	while (*s != '\0')
185 	{
186 		if (*s++ == c)
187 			return (--s);
188 	}
189 	return (NULL);
190 }
191 # endif V6
192 
193 # ifndef V6
194 /*
195 **  TTYPATH -- Get the path of the user's tty -- Version 7 version.
196 **
197 **	Returns the pathname of the user's tty.  Returns NULL if
198 **	the user is not logged in or if s/he has write permission
199 **	denied.
200 **
201 **	Parameters:
202 **		none
203 **
204 **	Returns:
205 **		pathname of the user's tty.
206 **		NULL if not logged in or write permission denied.
207 **
208 **	Side Effects:
209 **		none.
210 **
211 **	WARNING:
212 **		Return value is in a local buffer.
213 **
214 **	Called By:
215 **		savemail
216 */
217 
218 # include <sys/types.h>
219 # include <sys/stat.h>
220 
221 char *
222 ttypath()
223 {
224 	struct stat stbuf;
225 	register char *pathn;
226 	extern char *ttyname();
227 	extern char *getlogin();
228 
229 	/* compute the pathname of the controlling tty */
230 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
231 	{
232 		errno = 0;
233 		return (NULL);
234 	}
235 
236 	/* see if we have write permission */
237 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
238 	{
239 		errno = 0;
240 		return (NULL);
241 	}
242 
243 	/* see if the user is logged in */
244 	if (getlogin() == NULL)
245 		return (NULL);
246 
247 	/* looks good */
248 	return (pathn);
249 }
250 # endif V6
251 /*
252 **  CHECKCOMPAT -- check for From and To person compatible.
253 **
254 **	This routine can be supplied on a per-installation basis
255 **	to determine whether a person is allowed to send a message.
256 **	This allows restriction of certain types of internet
257 **	forwarding or registration of users.
258 **
259 **	If the hosts are found to be incompatible, an error
260 **	message should be given using "usrerr" and FALSE should
261 **	be returned.
262 **
263 **	Parameters:
264 **		to -- the person being sent to.
265 **
266 **	Returns:
267 **		TRUE -- ok to send.
268 **		FALSE -- not ok.
269 **
270 **	Side Effects:
271 **		none (unless you include the usrerr stuff)
272 */
273 
274 bool
275 checkcompat(to)
276 	register ADDRESS *to;
277 {
278 # ifdef lint
279 	ADDRESS *x = to;
280 
281 	to = x;
282 # endif lint
283 
284 	return (TRUE);
285 }
286