]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/mts/sendmail/RCS/hosts.c,v
Simplify folder_exists() to just testing stat(2)'s return value.
[nmh] / docs / historical / mh-6.8.5 / mts / sendmail / RCS / hosts.c,v
1 head 1.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.7
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.6;
12
13 1.6
14 date 92.01.31.21.37.07; author jromine; state Exp;
15 branches;
16 next 1.5;
17
18 1.5
19 date 90.04.05.15.30.14; author sources; state Exp;
20 branches;
21 next 1.4;
22
23 1.4
24 date 90.04.05.14.43.37; author sources; state Exp;
25 branches;
26 next 1.3;
27
28 1.3
29 date 90.02.06.12.57.57; author sources; state Exp;
30 branches;
31 next 1.2;
32
33 1.2
34 date 90.02.05.14.52.35; author sources; state Exp;
35 branches;
36 next 1.1;
37
38 1.1
39 date 90.02.05.14.52.05; author sources; state Exp;
40 branches;
41 next ;
42
43
44 desc
45 @@
46
47
48 1.7
49 log
50 @endif sugar
51 @
52 text
53 @/* hosts.c - find out the official name of a host */
54 #ifndef lint
55 static char ident[] = "@@(#)$Id: hosts.c,v 1.6 1992/01/31 21:37:07 jromine Exp jromine $";
56 #endif /* lint */
57
58 /* LINTLIBRARY */
59
60 /* In the SendMail world, we really don't know what the valid hosts are.
61 We could poke around in the sendmail.cf file, but that still isn't a
62 guarantee. As a result, we'll say that everything is a valid host, and
63 let SendMail worry about it. */
64
65
66 #include "../h/strings.h"
67 #include <stdio.h>
68 #include "../zotnet/mts.h"
69 #include <ctype.h>
70 #if defined(BSD42) || defined(SOCKETS)
71 #include <netdb.h>
72 #endif /* BSD42 or SOCKETS */
73
74
75 #define NOTOK (-1)
76
77
78 static struct host {
79 char *h_name;
80 char **h_aliases;
81 struct host *h_next;
82 } hosts;
83
84 char *getcpy ();
85
86 static int init_hs();
87
88 /* \f */
89
90 char *OfficialName (name)
91 register char *name;
92 {
93 register char *p;
94 char *q,
95 site[BUFSIZ];
96 #if defined(BSD42) || defined(SOCKETS)
97 register struct hostent *hp;
98 #endif /* BSD42 or SOCKETS */
99 static char buffer[BUFSIZ];
100 register char **r;
101 register struct host *h;
102
103 for (p = name, q = site; *p; p++, q++)
104 *q = isupper (*p) ? tolower (*p) : *p;
105 *q = 0;
106 q = site;
107
108 if (uleq (LocalName (), site))
109 return LocalName ();
110
111 #ifdef BSD41A
112 if (rhost (&q) != NOTOK) {
113 (void) strcpy (buffer, q);
114 free (q);
115 return buffer;
116 }
117 #endif /* BSD41A */
118 #if defined(BSD42) || defined(SOCKETS)
119 #ifndef BIND
120 sethostent (1);
121 #endif
122 if (hp = gethostbyname (q)) {
123 (void) strcpy (buffer, hp -> h_name);
124 return buffer;
125 }
126 #endif /* BSD42 or SOCKETS */
127
128 if (hosts.h_name || init_hs ())
129 for (h = hosts.h_next; h; h = h -> h_next)
130 if (uleq (h -> h_name, q))
131 return h -> h_name;
132 else
133 for (r = h -> h_aliases; *r; r++)
134 if (uleq (*r, q))
135 return h -> h_name;
136
137 (void) strcpy (buffer, site);
138 return buffer;
139 }
140
141 /* \f */
142
143 /* Use hostable as an exception file for those hosts that aren't on the
144 Internet (listed in /etc/hosts). These are usually PhoneNet and UUCP
145 sites. */
146
147
148 #define NALIASES 50
149
150 static int init_hs () {
151 register char *cp,
152 *dp,
153 **q,
154 **r;
155 char buffer[BUFSIZ],
156 *aliases[NALIASES];
157 register struct host *h;
158 register FILE *fp;
159
160 if ((fp = fopen (hostable, "r")) == NULL)
161 return 0;
162
163 h = &hosts;
164 while (fgets (buffer, sizeof buffer, fp) != NULL) {
165 if (cp = index (buffer, '#'))
166 *cp = 0;
167 if (cp = index (buffer, '\n'))
168 *cp = 0;
169 for (cp = buffer; *cp; cp++)
170 if (isspace (*cp))
171 *cp = ' ';
172 for (cp = buffer; isspace (*cp); cp++)
173 continue;
174 if (*cp == 0)
175 continue;
176
177 q = aliases;
178 if (cp = index (dp = cp, ' ')) {
179 *cp = 0;
180 for (cp++; *cp; cp++) {
181 while (isspace (*cp))
182 cp++;
183 if (*cp == 0)
184 break;
185 if (cp = index (*q++ = cp, ' '))
186 *cp = 0;
187 else
188 break;
189 if (q >= aliases + NALIASES)
190 break;
191 }
192 }
193
194 *q = 0;
195
196 h -> h_next = (struct host *) calloc (1, sizeof *h);
197 h = h -> h_next;
198 h -> h_name = getcpy (dp);
199 r = h -> h_aliases =
200 (char **) calloc ((unsigned) (q - aliases + 1), sizeof *q);
201 for (q = aliases; *q; q++)
202 *r++ = getcpy (*q);
203 *r = 0;
204 }
205
206 (void) fclose (fp);
207 return 1;
208 }
209 @
210
211
212 1.6
213 log
214 @kerberos
215 @
216 text
217 @d3 2
218 a4 2
219 static char ident[] = "@@(#)$Id: hosts.c,v 1.5 1990/04/05 15:30:14 sources Exp jromine $";
220 #endif lint
221 d20 1
222 a20 1
223 #endif BSD42 or SOCKETS
224 d46 1
225 a46 1
226 #endif BSD42 or SOCKETS
227 d65 1
228 a65 1
229 #endif BSD41A
230 d74 1
231 a74 1
232 #endif BSD42 or SOCKETS
233 @
234
235
236 1.5
237 log
238 @add ID
239 @
240 text
241 @d3 1
242 a3 1
243 static char ident[] = "@@(#)$Id:$";
244 d53 1
245 a53 1
246 *q = NULL;
247 d114 1
248 a114 1
249 *cp = NULL;
250 d116 1
251 a116 1
252 *cp = NULL;
253 d122 1
254 a122 1
255 if (*cp == NULL)
256 d127 1
257 a127 1
258 *cp = NULL;
259 d131 1
260 a131 1
261 if (*cp == NULL)
262 d134 1
263 a134 1
264 *cp = NULL;
265 d142 1
266 a142 1
267 *q = NULL;
268 d151 1
269 a151 1
270 *r = NULL;
271 @
272
273
274 1.4
275 log
276 @add ID
277 @
278 text
279 @d3 1
280 a3 1
281 static char ident[] = "$Id:";
282 @
283
284
285 1.3
286 log
287 @ANSI Compilance
288 @
289 text
290 @d2 3
291 @
292
293
294 1.2
295 log
296 @SOCKETS
297 @
298 text
299 @d31 2
300 @
301
302
303 1.1
304 log
305 @Initial revision
306 @
307 text
308 @d15 1
309 a15 1
310 #ifdef BSD42
311 d17 1
312 a17 1
313 #endif BSD42
314 d39 1
315 a39 1
316 #ifdef BSD42
317 d41 1
318 a41 1
319 #endif BSD42
320 d61 1
321 a61 1
322 #ifdef BSD42
323 d69 1
324 a69 1
325 #endif BSD42
326 @