djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
clientok.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/stat.h>
3#include "str.h"
4#include "ip.h"
5#include "byte.h"
6#include "clientok.h"
7
8static char fnaccept[3 + IPFMT];
9static char fnreject[4 + IPFMT];
10
11int clientok(char ip[16])
12{
13 struct stat st;
14 int i;
15 char sep;
16
17 fnaccept[0] = fnreject[0] = 'i';
18 fnaccept[1] = fnreject[1] = 'p';
19 fnaccept[2] = fnreject[2] = '/';
20 fnreject[3] = '#';
21
22 if (byte_equal(ip,12,V4mappedprefix)) {
23 fnaccept[3 + ip4_fmt(fnaccept + 3,ip + 12)] = 0;
24 fnreject[4 + ip4_fmt(fnreject + 4,ip + 12)] = 0;
25 sep='.';
26 } else {
27 fnaccept[3 + ip6_fmt(fnaccept + 3,ip)] = 0;
28 fnreject[4 + ip6_fmt(fnreject + 4,ip)] = 0;
29 sep=':';
30 }
31
32 /* Bad guys first */
33
34 for (;;) {
35 if (!fnreject[3]) break;
36 if (stat(fnreject,&st) == 0) return 0;
37 i = str_rchr(fnreject,sep);
38 if (i && fnreject[i] == sep)
39 fnreject[i] = 0;
40 else
41 break;
42 }
43
44 /* Good guys next */
45
46 for (;;) {
47 if (!fnaccept[3]) return 0;
48 if (stat(fnaccept,&st) == 0) return 1;
49 /* treat temporary error as rejection */
50 i = str_rchr(fnaccept,sep);
51 if (!fnaccept[i]) return 0;
52 fnaccept[i] = 0;
53 }
54}
char ip[16]
Definition: axfrdns.c:125
int clientok(char ip[16])
Definition: clientok.c:11