forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
excludedlist.c
148 lines (115 loc) · 2.78 KB
/
excludedlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <string.h>
#include <time.h>
#include "excludedlist.h"
#include "querydnsbase.h"
#include "utils.h"
#include "stringchunk.h"
#include "stringlist.h"
#include "bst.h"
#include "common.h"
static Bst DisabledTypes;
static StringChunk DisabledDomains;
static StringChunk ExcludedDomains;
BOOL IsDisabledType(int Type)
{
if( Bst_Search(&DisabledTypes, &Type, NULL) != NULL )
{
return TRUE;
} else {
return FALSE;
}
}
BOOL MatchDomain(StringChunk *List, const char *Domain, int *HashValue)
{
if( List == NULL )
{
return FALSE;
}
if( StringChunk_Match(List, Domain, HashValue, NULL) == TRUE )
{
return TRUE;
}
Domain = strchr(Domain + 1, '.');
while( Domain != NULL )
{
if( StringChunk_Match_NoWildCard(List, Domain, NULL, NULL) == TRUE ||
StringChunk_Match_NoWildCard(List, Domain + 1, NULL, NULL) == TRUE
)
{
return TRUE;
}
Domain = strchr(Domain + 1, '.');
}
return FALSE;
}
BOOL IsDisabledDomain(const char *Domain, int *HashValue){
return MatchDomain(&DisabledDomains, Domain, HashValue);
}
BOOL IsExcludedDomain(const char *Domain, int *HashValue)
{
return MatchDomain(&ExcludedDomains, Domain, HashValue);
}
static int TypeCompare(int *_1, int *_2)
{
return *_1 - *_2;
}
static int LoadDisableType(void)
{
const StringList *DisableType_Str = ConfigGetStringList(&ConfigInfo, "DisabledType");
const char *OneTypePendingToAdd_Str;
int OneTypePendingToAdd;
if( Bst_Init(&DisabledTypes, NULL, sizeof(int), TypeCompare) != 0 )
{
return -1;
}
if( DisableType_Str == NULL )
{
return 0;
}
OneTypePendingToAdd_Str = StringList_GetNext(DisableType_Str, NULL);
while( OneTypePendingToAdd_Str != NULL )
{
sscanf(OneTypePendingToAdd_Str, "%d", &OneTypePendingToAdd);
Bst_Add(&DisabledTypes, &OneTypePendingToAdd);
OneTypePendingToAdd_Str = StringList_GetNext(DisableType_Str, OneTypePendingToAdd_Str);
}
return 0;
}
static int LoadDomains(StringChunk *List, const StringList *Domains)
{
const char *Str;
if( StringChunk_Init(List, NULL) < 0 )
{
return -1;
}
if( Domains == NULL )
{
return 0;
}
Str = StringList_GetNext(Domains, NULL);
while( Str != NULL )
{
if( *Str == '.' )
{
Str++;
}
if( StringChunk_Add(List, Str, NULL, 0) != 0 )
{
return -2;
}
Str = StringList_GetNext(Domains, Str);
}
return 0;
}
int ExcludedList_Init(void)
{
StringList *DisabledDomain = ConfigGetStringList(&ConfigInfo, "DisabledDomain");
StringList *ExcludedDomain = ConfigGetStringList(&ConfigInfo, "ExcludedDomain");
LoadDomains(&DisabledDomains, ConfigGetStringList(&ConfigInfo, "DisabledDomain"));
StringList_Free(DisabledDomain);
LoadDomains(&ExcludedDomains, ConfigGetStringList(&ConfigInfo, "ExcludedDomain"));
StringList_Free(ExcludedDomain);
LoadDisableType();
INFO("Excluded & Disabled list initialized.\n");
return 0;
}