|
1 #include "cdb.h" |
|
2 #include "byte.h" |
|
3 #include "open.h" |
|
4 #include "error.h" |
|
5 #include "control.h" |
|
6 #include "constmap.h" |
|
7 #include "stralloc.h" |
|
8 #include "rcpthosts.h" |
|
9 |
|
10 static int flagrh = 0; |
|
11 static stralloc rh = {0}; |
|
12 static struct constmap maprh; |
|
13 static int fdmrh; |
|
14 |
|
15 int rcpthosts_init() |
|
16 { |
|
17 flagrh = control_readfile(&rh,"control/rcpthosts",0); |
|
18 if (flagrh != 1) return flagrh; |
|
19 if (!constmap_init(&maprh,rh.s,rh.len,0)) return flagrh = -1; |
|
20 fdmrh = open_read("control/morercpthosts.cdb"); |
|
21 if (fdmrh == -1) if (errno != error_noent) return flagrh = -1; |
|
22 return 0; |
|
23 } |
|
24 |
|
25 static stralloc host = {0}; |
|
26 |
|
27 int rcpthosts(buf,len) |
|
28 char *buf; |
|
29 int len; |
|
30 { |
|
31 int j; |
|
32 |
|
33 if (flagrh != 1) return 1; |
|
34 |
|
35 j = byte_rchr(buf,len,'@'); |
|
36 if (j >= len) return 1; /* presumably envnoathost is acceptable */ |
|
37 |
|
38 ++j; buf += j; len -= j; |
|
39 |
|
40 if (!stralloc_copyb(&host,buf,len)) return -1; |
|
41 buf = host.s; |
|
42 case_lowerb(buf,len); |
|
43 |
|
44 for (j = 0;j < len;++j) |
|
45 if (!j || (buf[j] == '.')) |
|
46 if (constmap(&maprh,buf + j,len - j)) return 1; |
|
47 |
|
48 if (fdmrh != -1) { |
|
49 uint32 dlen; |
|
50 int r; |
|
51 |
|
52 for (j = 0;j < len;++j) |
|
53 if (!j || (buf[j] == '.')) { |
|
54 r = cdb_seek(fdmrh,buf + j,len - j,&dlen); |
|
55 if (r) return r; |
|
56 } |
|
57 } |
|
58 |
|
59 return 0; |
|
60 } |