[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

aCaB acab at clamav.net
Sun Apr 4 01:08:01 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 46bd63825030cd499bf5022af26d98adf3f6835a
Author: aCaB <acab at clamav.net>
Date:   Fri Oct 16 01:47:42 2009 +0200

    win32: resolv.[ch]

diff --git a/ChangeLog b/ChangeLog
index 297d1b4..4e629a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Oct 16 01:46:28 CEST 2009 (acab)
+------------------------------------
+ * win32: res_query compatible interface
+
 Thu Oct 15 13:06:33 CEST 2009 (acab)
 ------------------------------------
  * win32: add freshclam
diff --git a/freshclam/dns.c b/freshclam/dns.c
index 8cdbc2c..94d1a69 100644
--- a/freshclam/dns.c
+++ b/freshclam/dns.c
@@ -28,10 +28,11 @@
 
 #include <string.h>
 #include <sys/types.h>
+#ifndef _WIN32
 #include <netinet/in.h>
 #include <arpa/nameser.h>
+#endif
 #include <resolv.h>
-#include <sys/types.h>
 
 #include "shared/output.h"
 
@@ -140,41 +141,6 @@ char *txtquery(const char *domain, unsigned int *ttl)
     return txt;
 }
 
-#elif defined(C_WINDOWS)
-
-/*
- * Note: Needs to link with dnsapi.lib.  
- * The dll behind this library is available from Windows 2000 onward.
- * Written by Mark Pizzolato
- */
-#include <winsock.h>
-#include <string.h>
-#include <windows.h>
-#include <windns.h>
-#include "shared/output.h"
-
-char *txtquery(const char *domain, unsigned int *ttl)
-{
-	PDNS_RECORD pDnsRecord;
-	char *txt = NULL;
-
-    *ttl = 0;
-    mprintf("*Querying %s\n", domain);
-
-   if(DnsQuery_UTF8(domain, DNS_TYPE_TEXT, DNS_QUERY_TREAT_AS_FQDN, NULL, &pDnsRecord, NULL) != 0)
-	return NULL;
-
-    if((pDnsRecord->Data.TXT.dwStringCount > 0) && pDnsRecord->Data.TXT.pStringArray[0]) {
-	txt = malloc(strlen(pDnsRecord->Data.TXT.pStringArray[0]) + 1);
-	if(txt)
-	    strcpy(txt, pDnsRecord->Data.TXT.pStringArray[0]);
-	*ttl = pDnsRecord->dwTtl;
-    }
-    DnsRecordListFree(pDnsRecord, DnsFreeRecordList);
-
-    return txt;
-}
-
 #else
 
 char *txtquery(const char *domain, unsigned int *ttl)
diff --git a/freshclam/manager.c b/freshclam/manager.c
index 6518e60..97b0a85 100644
--- a/freshclam/manager.c
+++ b/freshclam/manager.c
@@ -211,9 +211,7 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip
 		else
 			port = 8080;
 
-#ifndef	_WIN32
 		endservent();
-#endif
 	}
 
     } else {
diff --git a/win32/clamav-config.h b/win32/clamav-config.h
index d7d29ac..4b7f6a9 100644
--- a/win32/clamav-config.h
+++ b/win32/clamav-config.h
@@ -32,7 +32,7 @@
 #define CL_THREAD_SAFE 1
 
 /* where to look for the config file */
-#define CONFDIR "/usr/local/etc"
+#define CONFDIR "C:\\ClamAV"
 
 /* curses header location */
 /* #define CURSES_INCLUDE <ncurses.h>
@@ -83,7 +83,7 @@
 /* #undef C_SOLARIS */
 
 /* Path to virus database directory. */
-#define DATADIR "c:\\db"
+#define DATADIR "c:\\ClamAV\\db"
 
 /* "default FD_SETSIZE value" */
 #define DEFAULT_FD_SETSIZE 1024
@@ -304,7 +304,7 @@
 #define HAVE_RECVMSG 1
 
 /* have resolv.h */
-/* #undef HAVE_RESOLV_H */
+#define HAVE_RESOLV_H 1
 
 /* Define signed right shift implementation */
 #define HAVE_SAR 1
diff --git a/win32/compat/net.c b/win32/compat/net.c
index 152756a..5acd5d7 100644
--- a/win32/compat/net.c
+++ b/win32/compat/net.c
@@ -1,3 +1,23 @@
+/*
+ *  Copyright (C) 2009 Sourcefire, Inc.
+ *
+ *  Authors: aCaB <acab at clamav.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+
 #include <winsock2.h>
 #include <Ws2tcpip.h>
 #include "net.h"
diff --git a/win32/compat/net.h b/win32/compat/net.h
index d086918..98e59f6 100644
--- a/win32/compat/net.h
+++ b/win32/compat/net.h
@@ -33,6 +33,7 @@ ssize_t w32_send(int sockfd, const void *buf, size_t len, int flags);
 ssize_t w32_recv(int sockfd, void *buf, size_t len, int flags);
 int w32_closesocket(int sockfd);
 struct servent *w32_getservbyname(const char *name, const char *proto);
+#define endservent()
 int w32_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
 void w32_freeaddrinfo(struct addrinfo *res);
 const char *w32_inet_ntop(int af, const void *src, char *dst, socklen_t size);
diff --git a/win32/compat/resolv.c b/win32/compat/resolv.c
new file mode 100644
index 0000000..0f47ca1
--- /dev/null
+++ b/win32/compat/resolv.c
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (C) 2009 Sourcefire, Inc.
+ *
+ *  Authors: aCaB <acab at clamav.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+
+/* a fake libresolv-like res_query interface */
+
+#include "resolv.h"
+
+int res_init(void) {
+    return 0;
+}
+
+int res_query(const char *dname, int class, int type, unsigned char *answer, int anslen) {
+    DNS_RECORD *rrs, *rr;
+    DNS_STATUS s;
+    HEADER *h = (HEADER *)answer;
+    int ret = -1;
+
+    if(anslen <= sizeof(HEADER))
+	return -1;
+
+    s = DnsQuery(dname, (WORD)type, DNS_QUERY_BYPASS_CACHE | DNS_QUERY_NO_HOSTS_FILE | DNS_QUERY_DONT_RESET_TTL_VALUES, NULL, &rrs, NULL);
+    if(s)
+	return -1;
+
+    /* We don't use the header data */
+    h->id = 1;
+    answer += sizeof(HEADER);
+    anslen -= sizeof(HEADER);
+
+    rr = rrs;
+    do {
+	if(rr->wType == (WORD)type || rr->Data.TXT.dwStringCount || rr->Data.TXT.pStringArray[0]) {
+	    unsigned int len = strlen(dname), txtlen = strlen(rr->Data.TXT.pStringArray[0]);
+	    if(txtlen > 255) continue;
+	    len++;
+	    if(len*2 + txtlen + 15 > anslen) break;
+	    memcpy(answer, dname, len);
+	    answer += len;
+	    answer[0] = type >> 8; /* type */
+	    answer[1] = type;
+	    answer[2] = class >> 8; /* class */
+	    answer[3] = class & 0xff;
+	    answer += 4;
+	    memcpy(answer, dname, len);
+	    answer += len;
+	    answer[0] = type >> 8; /* type */
+	    answer[1] = type;
+	    answer[2] = class >> 8; /* class */
+	    answer[3] = class & 0xff;
+	    answer[4] = rr->dwTtl >> 24;
+	    answer[5] = rr->dwTtl >> 16;
+	    answer[6] = rr->dwTtl >> 8;
+	    answer[7] = rr->dwTtl;
+	    answer[8] = (txtlen+1) >> 8; /* rdata len */
+	    answer[9] = txtlen+1;
+	    answer[10] = txtlen;
+	    memcpy(&answer[11], rr->Data.TXT.pStringArray[0], txtlen);
+	    ret = len*2 + txtlen + 15 + sizeof(HEADER);
+	    break;
+	}
+    } while ((rr = rr->pNext));
+
+    DnsRecordListFree(rrs, DnsFreeRecordList);
+    return ret;
+}
+
+int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, char *exp_dn, int length) {
+    int len, maxlen;
+
+    /* names are simple C strings, not compressed not len encoded */
+    if(comp_dn < msg || comp_dn >= eomorig)
+	return -1;
+    maxlen = eomorig - comp_dn;
+    len = strnlen(comp_dn, maxlen) + 1;
+    if(len > maxlen || len > length)
+	return -1;
+    memcpy(exp_dn, msg, len);
+    return len;
+}
+
diff --git a/win32/compat/resolv.h b/win32/compat/resolv.h
new file mode 100644
index 0000000..3929e1f
--- /dev/null
+++ b/win32/compat/resolv.h
@@ -0,0 +1,122 @@
+/*
+ *  Copyright (C) 2009 Sourcefire, Inc.
+ *
+ *  Authors: aCaB <acab at clamav.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+
+#ifndef __RESOLV_H
+#define __RESOLV_H
+
+#if HAVE_CONFIG_H
+#include "clamav-config.h"
+#endif
+
+#include <Windns.h>
+#include "cltypes.h"
+
+#define C_IN 1
+
+#define T_A DNS_TYPE_A
+#define T_NS DNS_TYPE_NS
+#define T_MD DNS_TYPE_MD
+#define T_MF DNS_TYPE_MF
+#define T_CNAME DNS_TYPE_CNAME
+#define T_SOA DNS_TYPE_SOA 0
+#define T_MB DNS_TYPE_MB
+#define T_MG DNS_TYPE_MG
+#define T_MR DNS_TYPE_MR
+#define T_NULL DNS_TYPE_NULL
+#define T_WKS DNS_TYPE_WKS
+#define T_PTR DNS_TYPE_PTR
+#define T_HINFO DNS_TYPE_HINFO
+#define T_MINFO DNS_TYPE_MINFO
+#define T_MX DNS_TYPE_MX
+#define T_TXT DNS_TYPE_TEXT
+#define T_RP DNS_TYPE_RP
+#define T_AFSDB DNS_TYPE_AFSDB
+#define T_X25 DNS_TYPE_X25
+#define T_ISDN DNS_TYPE_ISDN
+#define T_RT DNS_TYPE_RT
+#define T_NSAP DNS_TYPE_NSAP
+#define T_NSAP_PTR DNS_TYPE_NSAPPTR
+#define T_SIG DNS_TYPE_SIG
+#define T_KEY DNS_TYPE_KEY
+#define T_PX DNS_TYPE_PX
+#define T_GPOS DNS_TYPE_GPOS
+#define T_AAAA DNS_TYPE_AAAA
+#define T_LOC DNS_TYPE_LOC
+#define T_NXT DNS_TYPE_NXT
+#define T_EID DNS_TYPE_EID
+#define T_NIMLOC DNS_TYPE_NIMLOC
+#define T_SRV DNS_TYPE_SRV
+#define T_ATMA DNS_TYPE_ATMA
+#define T_NAPTR DNS_TYPE_NAPTR
+#define T_KX DNS_TYPE_KX
+#define T_CERT DNS_TYPE_CERT
+#define T_A6 DNS_TYPE_A6
+#define T_DNAME DNS_TYPE_DNAME
+#define T_SINK DNS_TYPE_SINK
+#define T_OPT DNS_TYPE_OPT
+#define T_DS DNS_TYPE_DS
+#define T_RRSIG DNS_TYPE_RRSIG
+#define T_NSEC DNS_TYPE_NSEC
+#define T_DNSKEY DNS_TYPE_DNSKEY
+#define T_DHCID DNS_TYPE_DHCID
+#define T_UINFO DNS_TYPE_UINFO
+#define T_UID DNS_TYPE_UID
+#define T_GID DNS_TYPE_GID
+#define T_UNSPEC DNS_TYPE_UNSPEC
+#define T_ADDRS DNS_TYPE_ADDRS
+#define T_TKEY DNS_TYPE_TKEY
+#define T_TSIG DNS_TYPE_TSIG
+#define T_IXFR DNS_TYPE_IXFR
+#define T_AXFR DNS_TYPE_AXFR
+#define T_MAILB DNS_TYPE_MAILB
+#define T_MAILA DNS_TYPE_MAILA
+#define T_ALL DNS_TYPE_ALL
+#define T_ANY DNS_TYPE_ANY
+#define T_WINS DNS_TYPE_WINS
+#define T_WINSR DNS_TYPE_WINSR
+#define T_NBSTAT DNS_TYPE_NBSTAT
+
+#ifndef DNS_QUERY_NO_HOSTS_FILE
+#define DNS_QUERY_NO_HOSTS_FILE 0
+#endif
+
+typedef struct {
+	unsigned short	id; /* fake stuff */
+} HEADER;
+
+#define INT16SZ 2
+
+#define GETSHORT(var, ptr) do { \
+    var = ((uint16_t)(*(uint8_t *)ptr++)) << 8; \
+    var |= *(uint8_t *)ptr++; \
+    } while (0)
+
+#define GETLONG(var, ptr) do { \
+    var = ((uint32_t)(*(uint8_t *)ptr++)) << 24; \
+    var = ((uint32_t)(*(uint8_t *)ptr++)) << 16; \
+    var = ((uint32_t)(*(uint8_t *)ptr++)) << 8; \
+    var |= *(uint8_t *)ptr++; \
+    } while (0)
+
+int res_init(void);
+int res_query(const char *dname, int class, int type, unsigned char *answer, int anslen);
+int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, char *exp_dn, int length);
+
+#endif
diff --git a/win32/freshclam.vcproj b/win32/freshclam.vcproj
index 0c5aa9d..564a769 100644
--- a/win32/freshclam.vcproj
+++ b/win32/freshclam.vcproj
@@ -63,6 +63,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="dnsapi.lib"
 				LinkIncremental="1"
 				GenerateDebugInformation="true"
 				SubSystem="1"
@@ -139,6 +140,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="dnsapi.lib"
 				LinkIncremental="1"
 				GenerateDebugInformation="true"
 				SubSystem="1"
@@ -237,6 +239,14 @@
 				Name="compat"
 				>
 				<File
+					RelativePath=".\compat\resolv.c"
+					>
+				</File>
+				<File
+					RelativePath=".\compat\resolv.h"
+					>
+				</File>
+				<File
 					RelativePath=".\compat\strptime.c"
 					>
 				</File>
diff --git a/win32/libclamav.vcproj b/win32/libclamav.vcproj
index e676564..179c0c6 100644
--- a/win32/libclamav.vcproj
+++ b/win32/libclamav.vcproj
@@ -788,10 +788,6 @@
 					>
 				</File>
 				<File
-					RelativePath=".\compat\net.h"
-					>
-				</File>
-				<File
 					RelativePath=".\compat\snprintf.c"
 					>
 				</File>

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list