-
Notifications
You must be signed in to change notification settings - Fork 1
/
vcheck.c
160 lines (138 loc) · 3.2 KB
/
vcheck.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
149
150
151
152
153
154
155
156
157
158
159
160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<netinet/in.h>
#include<arpa/nameser.h>
#include<resolv.h>
#include<errno.h>
#include<signal.h>
#include<netdb.h>
#include<unistd.h>
#include<ctype.h>
#include<pthread.h>
#include"dnsqry.h"
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void *
vcheck(void *ptr)
{
struct funcargs *da=(struct funcargs*)ptr;
register char *p;
char *op;
struct servers *llp=da->reserved;
struct hostent *host;
int count , sendlen;
union {
HEADER hdr;
unsigned char buf[PACKETSZ];
} response;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/*
* Exclude gethostbyname() calls from each other since the function
* is is not reetrant.
*/
#ifdef DEBUG
tdpf("pthread_mutex_lock(&mutex)");
#endif
pthread_mutex_lock(&mutex);
#ifdef DEBUG
tdpf("gethostbyname");
#endif
if (!(host = gethostbyname(llp->ns))) {
#ifdef DEBUG
tdpf("pthread_mutex_unlock(&mutex)");
#endif
pthread_mutex_unlock(&mutex);
printf("Unable to resolve: %s\n", llp->ns);
puts("Possible erreneous NS record.");
#ifdef DEBUG
tdpf("pthread_exit");
#endif
pthread_exit((void *)-1);
}
memcpy((void *)&_res.nsaddr_list[0].sin_addr,
(void *)host->h_addr_list[0], (size_t)host->h_length);
spin();
#ifdef DEBUG
tdpf("res_query");
#endif
if (
(sendlen =
res_query(NS_VERSION_STRING, C_CHAOS, T_TXT,
(unsigned char *)&response, sizeof(response))) < 0) {
#ifdef DEBUG
tdpf("pthread_exit");
#endif
pthread_exit((void *)-1);
}
#ifdef DEBUG
tdpf("pthread_mutex_unlock(&mutex)");
#endif
pthread_mutex_unlock(&mutex);
#ifdef DEBUG
tdpf("recurtest");
#endif
if (!recurtest(host, RECURSIVE_QUERY_TEST_DOMAIN))
printf("%s seems to have recursive queries enabled\n",llp->ns);
spin();
#ifdef DEBUG
tdpf("axfrtest");
#endif
if (!axfrtest(host, da->dom))
printf("%s appears willing to zone transfer %s\n",
llp->ns, da->dom);
da->eom = response.buf + sendlen;
da->cp = response.buf + sizeof(HEADER);
da->cp += skipname(response.buf, da->cp, da->eom) + QFIXEDSZ;
da->bufp = (char*)response.buf;
da->cp += skiptodata(da);
if (da->cp < da->eom) {
if (da->type == T_TXT) {
int flag=0;
op = p = (char*)da->cp + 1;
#ifdef DEBUG
tdpf("calloc");
#endif
if (!(llp->ver = (char *)calloc(MAXDNAME + 1, sizeof(char))))
vexit("calloc");
count = da->eom - da->cp + 1;
/* Paranoid strncpy(). */
strncpy(llp->ver, op, count);
for (p = llp->ver; *p; p++) {
if (!isprint(*p)) {
*p = 0;
break;
}
}
printf("%s is %s", llp->ns, llp->ver);
if(!strchr(llp->ver,'.'))
llp->ver=(char*)-1;
else
{
for (p = llp->ver; *p; p++) {
if (isspace(*p)) {
llp->ver = (char*)-1;
break;
}
if(isdigit(*p))
flag=1;
}
}
if(!flag)
llp->ver = (char*)-1;
if (p == llp->ver)
llp->ver = (char*)-1;
if (llp->ver==(char*)-1)
printf(" (Cannot parse returned version string)");
putchar('\n');
}
else
{
puts("Possible Malformed DNS response");
}
}
spin();
#ifdef DEBUG
tdpf("pthread_exit");
#endif
pthread_exit((void *)0);
}