xref: /csrg-svn/usr.sbin/sendmail/src/conf.c (revision 4262)
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.24	08/29/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|H_FORCE,		0,
59 	"cc",			H_ADDR|H_FORCE,		0,
60 	"bcc",			H_ADDR|H_ACHECK|H_FORCE,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 # ifdef V6
96 /*
97 **  TTYNAME -- return name of terminal.
98 **
99 **	Parameters:
100 **		fd -- file descriptor to check.
101 **
102 **	Returns:
103 **		pointer to full path of tty.
104 **		NULL if no tty.
105 **
106 **	Side Effects:
107 **		none.
108 */
109 
110 char *
111 ttyname(fd)
112 	int fd;
113 {
114 	register char tn;
115 	static char pathn[] = "/dev/ttyx";
116 
117 	/* compute the pathname of the controlling tty */
118 	if ((tn = ttyn(fd)) == NULL)
119 	{
120 		errno = 0;
121 		return (NULL);
122 	}
123 	pathn[8] = tn;
124 	return (pathn);
125 }
126 /*
127 **  FDOPEN -- Open a stdio file given an open file descriptor.
128 **
129 **	This is included here because it is standard in v7, but we
130 **	need it in v6.
131 **
132 **	Algorithm:
133 **		Open /dev/null to create a descriptor.
134 **		Close that descriptor.
135 **		Copy the existing fd into the descriptor.
136 **
137 **	Parameters:
138 **		fd -- the open file descriptor.
139 **		type -- "r", "w", or whatever.
140 **
141 **	Returns:
142 **		The file descriptor it creates.
143 **
144 **	Side Effects:
145 **		none
146 **
147 **	Called By:
148 **		deliver
149 **
150 **	Notes:
151 **		The mode of fd must match "type".
152 */
153 
154 FILE *
155 fdopen(fd, type)
156 	int fd;
157 	char *type;
158 {
159 	register FILE *f;
160 
161 	f = fopen("/dev/null", type);
162 	(void) close(fileno(f));
163 	fileno(f) = fd;
164 	return (f);
165 }
166 /*
167 **  INDEX -- Return pointer to character in string
168 **
169 **	For V7 compatibility.
170 **
171 **	Parameters:
172 **		s -- a string to scan.
173 **		c -- a character to look for.
174 **
175 **	Returns:
176 **		If c is in s, returns the address of the first
177 **			instance of c in s.
178 **		NULL if c is not in s.
179 **
180 **	Side Effects:
181 **		none.
182 */
183 
184 index(s, c)
185 	register char *s;
186 	register char c;
187 {
188 	while (*s != '\0')
189 	{
190 		if (*s++ == c)
191 			return (--s);
192 	}
193 	return (NULL);
194 }
195 # endif V6
196 /*
197 **  TTYPATH -- Get the path of the user's tty
198 **
199 **	Returns the pathname of the user's tty.  Returns NULL if
200 **	the user is not logged in or if s/he has write permission
201 **	denied.
202 **
203 **	Parameters:
204 **		none
205 **
206 **	Returns:
207 **		pathname of the user's tty.
208 **		NULL if not logged in or write permission denied.
209 **
210 **	Side Effects:
211 **		none.
212 **
213 **	WARNING:
214 **		Return value is in a local buffer.
215 **
216 **	Called By:
217 **		savemail
218 */
219 
220 # include <sys/stat.h>
221 
222 char *
223 ttypath()
224 {
225 	struct stat stbuf;
226 	register char *pathn;
227 	extern char *ttyname();
228 	extern char *getlogin();
229 
230 	/* compute the pathname of the controlling tty */
231 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
232 	{
233 		errno = 0;
234 		return (NULL);
235 	}
236 
237 	/* see if we have write permission */
238 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
239 	{
240 		errno = 0;
241 		return (NULL);
242 	}
243 
244 	/* see if the user is logged in */
245 	if (getlogin() == NULL)
246 		return (NULL);
247 
248 	/* looks good */
249 	return (pathn);
250 }
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