2
* Copyright (C) 2009 Sourcefire, Inc.
4
* Authors: aCaB <acab@clamav.net>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
/* a fake libresolv-like res_query interface */
29
int res_query(const char *dname, int class, int type, unsigned char *answer, int anslen) {
32
HEADER *h = (HEADER *)answer;
35
if(anslen <= sizeof(HEADER))
38
s = DnsQuery(dname, (WORD)type, DNS_QUERY_BYPASS_CACHE | DNS_QUERY_NO_HOSTS_FILE | DNS_QUERY_DONT_RESET_TTL_VALUES, NULL, &rrs, NULL);
42
/* We don't use the header data */
44
answer += sizeof(HEADER);
45
anslen -= sizeof(HEADER);
49
if(rr->wType == (WORD)type && rr->Data.TXT.dwStringCount && rr->Data.TXT.pStringArray[0]) {
50
unsigned int len = strlen(dname), txtlen = strlen(rr->Data.TXT.pStringArray[0]);
51
if(txtlen > 255) continue;
53
if(len*2 + txtlen + 15 > anslen) break;
54
memcpy(answer, dname, len);
56
answer[0] = type >> 8; /* type */
58
answer[2] = class >> 8; /* class */
59
answer[3] = class & 0xff;
61
memcpy(answer, dname, len);
63
answer[0] = type >> 8; /* type */
65
answer[2] = class >> 8; /* class */
66
answer[3] = class & 0xff;
67
answer[4] = rr->dwTtl >> 24;
68
answer[5] = rr->dwTtl >> 16;
69
answer[6] = rr->dwTtl >> 8;
70
answer[7] = rr->dwTtl;
71
answer[8] = (txtlen+1) >> 8; /* rdata len */
74
memcpy(&answer[11], rr->Data.TXT.pStringArray[0], txtlen);
75
ret = len*2 + txtlen + 15 + sizeof(HEADER);
78
} while ((rr = rr->pNext));
80
DnsRecordListFree(rrs, DnsFreeRecordList);
84
int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, char *exp_dn, int length) {
87
/* names are simple C strings, not compressed not len encoded */
88
if(comp_dn < msg || comp_dn >= eomorig)
90
maxlen = eomorig - comp_dn;
91
len = strnlen(comp_dn, maxlen) + 1;
92
if(len > maxlen || len > length)
94
memcpy(exp_dn, msg, len);