~ubuntu-branches/ubuntu/natty/clamav/natty-updates

« back to all changes in this revision

Viewing changes to win32/compat/resolv.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2011-08-25 09:02:32 UTC
  • mfrom: (105.2.2 natty-proposed) (105.1.5 oneiric)
  • Revision ID: package-import@ubuntu.com-20110825090232-84nkdn9ah8w9o83g
Tags: 0.97.2+dfsg-1ubuntu1.11.04
Microversion update from 0.97 to 0.97.2 (LP: #826828)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2009 Sourcefire, Inc.
3
 
 *
4
 
 *  Authors: aCaB <acab@clamav.net>
5
 
 *
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.
9
 
 *
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.
14
 
 *
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,
18
 
 *  MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
/* a fake libresolv-like res_query interface */
22
 
 
23
 
#include "resolv.h"
24
 
 
25
 
int res_init(void) {
26
 
    return 0;
27
 
}
28
 
 
29
 
int res_query(const char *dname, int class, int type, unsigned char *answer, int anslen) {
30
 
    DNS_RECORD *rrs, *rr;
31
 
    DNS_STATUS s;
32
 
    HEADER *h = (HEADER *)answer;
33
 
    int ret = -1;
34
 
 
35
 
    if(anslen <= sizeof(HEADER))
36
 
        return -1;
37
 
 
38
 
    s = DnsQuery(dname, (WORD)type, DNS_QUERY_BYPASS_CACHE | DNS_QUERY_NO_HOSTS_FILE | DNS_QUERY_DONT_RESET_TTL_VALUES, NULL, &rrs, NULL);
39
 
    if(s)
40
 
        return -1;
41
 
 
42
 
    /* We don't use the header data */
43
 
    h->id = 1;
44
 
    answer += sizeof(HEADER);
45
 
    anslen -= sizeof(HEADER);
46
 
 
47
 
    rr = rrs;
48
 
    do {
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;
52
 
            len++;
53
 
            if(len*2 + txtlen + 15 > anslen) break;
54
 
            memcpy(answer, dname, len);
55
 
            answer += len;
56
 
            answer[0] = type >> 8; /* type */
57
 
            answer[1] = type;
58
 
            answer[2] = class >> 8; /* class */
59
 
            answer[3] = class & 0xff;
60
 
            answer += 4;
61
 
            memcpy(answer, dname, len);
62
 
            answer += len;
63
 
            answer[0] = type >> 8; /* type */
64
 
            answer[1] = 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 */
72
 
            answer[9] = txtlen+1;
73
 
            answer[10] = txtlen;
74
 
            memcpy(&answer[11], rr->Data.TXT.pStringArray[0], txtlen);
75
 
            ret = len*2 + txtlen + 15 + sizeof(HEADER);
76
 
            break;
77
 
        }
78
 
    } while ((rr = rr->pNext));
79
 
 
80
 
    DnsRecordListFree(rrs, DnsFreeRecordList);
81
 
    return ret;
82
 
}
83
 
 
84
 
int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, char *exp_dn, int length) {
85
 
    int len, maxlen;
86
 
 
87
 
    /* names are simple C strings, not compressed not len encoded */
88
 
    if(comp_dn < msg || comp_dn >= eomorig)
89
 
        return -1;
90
 
    maxlen = eomorig - comp_dn;
91
 
    len = strnlen(comp_dn, maxlen) + 1;
92
 
    if(len > maxlen || len > length)
93
 
        return -1;
94
 
    memcpy(exp_dn, msg, len);
95
 
    return len;
96
 
}
97