By default, freshclam uses a User-Agent header of PACKAGE/VERSION
(e.g. clamav/0.87.1) when downloading virus updates over HTTP. This makes
it a little awkward if your servers are behind a firewall/proxy which
applies User-Agent filtering.
The attached patch adds a new freshclam option (HTTPUserAgent) which
allows forcing the use of a different User-Agent header, please can you
consider including this (or something like it!) in CVS ?
Thanks,
Andy
diff -ur clamav-devel/freshclam/manager.c
clamav-devel-patched/freshclam/manager.c
--- clamav-devel/freshclam/manager.c 2005-12-10 18:50:26.000000000 +0000
+++ clamav-devel-patched/freshclam/manager.c 2006-01-04 23:09:30.150139000
+0000
@@ -245,7 +245,7 @@
struct cfgstruct *cpt;
int hostfd, nodb = 0, dbver = -1, ret, port = 0, ims = -1;
char *tempname, ipaddr[16], *pt;
- const char *proxy = NULL, *user = NULL, *pass = NULL;
+ const char *proxy = NULL, *user = NULL, *pass = NULL, *uas = NULL;
int flevel = cl_retflevel();
@@ -301,6 +301,12 @@
logg("Connecting via %s\n", proxy);
}
+ if((cpt = cfgopt(copt, "HTTPUserAgent"))->enabled) {
+ uas = cpt->strarg;
+ if ((pt = strpbrk(uas, "\n\r")))
+ *pt = '\0';
+ }
+
memset(ipaddr, 0, sizeof(ipaddr));
if(!nodb && dbver == -1) {
@@ -321,7 +327,7 @@
if(!ip[0])
strcpy(ip, ipaddr);
- remote = remote_cvdhead(remotename, hostfd, hostname, proxy, user,
pass, &ims);
+ remote = remote_cvdhead(remotename, hostfd, hostname, proxy, user,
pass, (char *)uas, &ims);
if(!nodb && !ims) {
logg("%s is up to date (version: %d, sigs: %d, f-level: %d,
builder: %s)\n", localname, current->version, current->sigs, current->fl,
current->builder);
@@ -596,7 +602,7 @@
return strftime(buf, 36, "%a, %d %b %Y %X GMT", time);
}
-struct cl_cvd *remote_cvdhead(const char *file, int socketfd, const char
*hostname, const char *proxy, const char *user, const char *pass, int *ims)
+struct cl_cvd *remote_cvdhead(const char *file, int socketfd, const char
*hostname, const char *proxy, const char *user, const char *pass, char *uas,
int *ims)
{
char cmd[512], head[513], buffer[FILEBUFF], *ch, *tmp;
int i, j, bread, cnt;
@@ -635,22 +641,24 @@
logg("*If-Modified-Since: %s\n", last_modified);
logg("Reading CVD header (%s): ", file);
+ if(!uas)
+ uas = PACKAGE"/"VERSION;
#ifdef NO_SNPRINTF
sprintf(cmd, "GET %s/%s HTTP/1.1\r\n"
"Host: %s\r\n%s"
- "User-Agent: "PACKAGE"/"VERSION"\r\n"
+ "User-Agent: %s\r\n"
"Connection: close\r\n"
"Range: bytes=0-511\r\n"
"If-Modified-Since: %s\r\n"
- "\r\n", (remotename != NULL)?remotename:"", file, hostname,
(authorization != NULL)?authorization:"", last_modified);
+ "\r\n", (remotename != NULL)?remotename:"", file, hostname,
(authorization != NULL)?authorization:"", uas, last_modified);
#else
snprintf(cmd, sizeof(cmd), "GET %s/%s HTTP/1.1\r\n"
"Host: %s\r\n%s"
- "User-Agent: "PACKAGE"/"VERSION"\r\n"
+ "User-Agent: %s\r\n"
"Connection: close\r\n"
"Range: bytes=0-511\r\n"
"If-Modified-Since: %s\r\n"
- "\r\n", (remotename != NULL)?remotename:"", file, hostname,
(authorization != NULL)?authorization:"", last_modified);
+ "\r\n", (remotename != NULL)?remotename:"", file, hostname,
(authorization != NULL)?authorization:"", uas, last_modified);
#endif
write(socketfd, cmd, strlen(cmd));
diff -ur clamav-devel/freshclam/manager.h
clamav-devel-patched/freshclam/manager.h
--- clamav-devel/freshclam/manager.h 2005-08-03 14:21:55.000000000 +0000
+++ clamav-devel-patched/freshclam/manager.h 2006-01-04 22:46:35.750195000
+0000
@@ -28,7 +28,7 @@
int wwwconnect(const char *server, const char *proxy, int pport, char
*remoteip, char *localip);
-struct cl_cvd *remote_cvdhead(const char *file, int socketfd, const char
*hostname, const char *proxy, const char *user, const char *pass, int *ims);
+struct cl_cvd *remote_cvdhead(const char *file, int socketfd, const char
*hostname, const char *proxy, const char *user, const char *pass, char *uas,
int *ims);
int get_database(const char *dbfile, int socketfd, const char *file, const
char *hostname, const char *proxy, const char *user, const char *pass);
diff -ur clamav-devel/shared/cfgparser.c clamav-devel-patched/shared/cfgparser.c
--- clamav-devel/shared/cfgparser.c 2005-12-12 18:44:37.000000000 +0000
+++ clamav-devel-patched/shared/cfgparser.c 2006-01-04 23:01:31.867949000
+0000
@@ -110,6 +110,7 @@
{"HTTPProxyPort", OPT_NUM, -1, NULL, 0}, /* freshclam */
{"HTTPProxyUsername", OPT_STR, -1, NULL, 0}, /* freshclam */
{"HTTPProxyPassword", OPT_STR, -1, NULL, 0}, /* freshclam */
+ {"HTTPUserAgent", OPT_FULLSTR, -1, NULL, 0}, /* freshclam */
{"NotifyClamd", OPT_STR, -1, NULL, 0}, /* freshclam */
{"OnUpdateExecute", OPT_FULLSTR, -1, NULL, 0}, /* freshclam */
{"OnErrorExecute", OPT_FULLSTR, -1, NULL, 0}, /* freshclam */
_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html