~ubuntu-branches/ubuntu/trusty/clamav/trusty-proposed

« back to all changes in this revision

Viewing changes to freshclam/dns.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2005-09-19 09:05:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050919090559-hikpqduq8yx5qxo2
Tags: 0.87-1
* New upstream version
  - Fixes CAN-2005-2920 and CAN-2005-2919 (closes: #328660)
* New logcheck line for clamav-daemon (closes: #323132)
* relibtoolize and apply kfreebsd patch (closes: #327707)
* Make sure init.d script starts freshclam up again after upgrade when run
  from if-up.d (closes: #328912)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004 Tomasz Kojm <tkojm@clamav.net>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 */
 
18
 
 
19
#if HAVE_CONFIG_H
 
20
#include "clamav-config.h"
 
21
#endif
 
22
 
 
23
#include <stdio.h>
 
24
 
 
25
#ifdef HAVE_RESOLV_H
 
26
 
 
27
#include <string.h>
 
28
#include <sys/types.h>
 
29
#include <netinet/in.h>
 
30
#include <arpa/nameser.h>
 
31
#include <resolv.h>
 
32
#include <sys/types.h>
 
33
 
 
34
#include "memory.h"
 
35
#include "output.h"
 
36
 
 
37
#ifndef PACKETSZ
 
38
#define PACKETSZ 512
 
39
#endif
 
40
 
 
41
char *txtquery(const char *domain, unsigned int *ttl)
 
42
{
 
43
        unsigned char answer[PACKETSZ], host[128], *pt, *txt;
 
44
        int len, exp, cttl, size, txtlen, type;
 
45
 
 
46
 
 
47
    if(res_init() < 0) {
 
48
        mprintf("@res_init failed\n");
 
49
        return NULL;
 
50
    }
 
51
 
 
52
    mprintf("*Querying %s\n", domain);
 
53
 
 
54
    memset(answer, 0, PACKETSZ);
 
55
    if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
 
56
        mprintf("@Can't query %s\n", domain);
 
57
        return NULL;
 
58
    }
 
59
 
 
60
    pt = answer + sizeof(HEADER);
 
61
 
 
62
    if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
 
63
        mprintf("@dn_expand failed\n");
 
64
        return NULL;
 
65
    }
 
66
 
 
67
    pt += exp;
 
68
 
 
69
    GETSHORT(type, pt);
 
70
    if(type != T_TXT) {
 
71
        mprintf("@Broken DNS reply.\n");
 
72
        return NULL;
 
73
    }
 
74
 
 
75
    pt += INT16SZ; /* class */
 
76
 
 
77
    if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
 
78
        mprintf("@second dn_expand failed\n");
 
79
        return NULL;
 
80
    }
 
81
 
 
82
    pt += exp;
 
83
    GETSHORT(type, pt);
 
84
    if(type != T_TXT) {
 
85
        mprintf("@Not a TXT record\n");
 
86
        return NULL;
 
87
    }
 
88
 
 
89
    pt += INT16SZ; /* class */
 
90
    GETLONG(cttl, pt);
 
91
    *ttl = cttl;
 
92
    GETSHORT(size, pt);
 
93
    txtlen = *pt;
 
94
 
 
95
    if(txtlen >= size || !txtlen) {
 
96
        mprintf("@Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size);
 
97
        return NULL;
 
98
    }
 
99
 
 
100
    if(!(txt = mmalloc(txtlen + 1)))
 
101
        return NULL;
 
102
 
 
103
    pt++;
 
104
    strncpy(txt, pt, txtlen);
 
105
    txt[txtlen] = 0;
 
106
 
 
107
    return txt;
 
108
}
 
109
 
 
110
#else
 
111
 
 
112
char *txtquery(const char *domain, unsigned int *ttl)
 
113
{
 
114
    return NULL;
 
115
}
 
116
 
 
117
#endif