The error freshclam issues is:
ERROR: Verification: MD5 verification error.
Having a look at 'manager.c' we can see that the routine that checks '.cvd' file is 'cl_cvdverify':
/* temporary file is created in clamav's directory thus we don't need * to create it immediately because race condition is not possible here */ tempname = cl_gentemp(".");
if(get_database(remotename, hostfd, tempname, hostname, proxy, user, pass)) {
I think the problem is in the get_database function itself:
if((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0644)) == -1) {
For Win32, this file is created and opened in text mode. Win32 would need the O_BINARY flag, but that is not portable.
Thge fopen function cannot be used as that does not use O_EXCL when opening the file. A possible fix is to use fdopen with the mode set to "wb". See the attached patch, which I haven't tested!
--- freshclam/manager.c~ Tue Nov 11 21:26:10 2003
+++ freshclam/manager.c Fri Feb 6 19:28:02 2004
@@ -419,6 +419,7 @@
char cmd[512], buffer[FILEBUFF];
char *ch;
int bread, fd, i, rot = 0;
+ FILE *fp;
char *remotename = NULL, *authorization = NULL;
const char *rotation = "|/-\\";
@@ -443,6 +444,12 @@
perror("open");
return -1;
}
+ if((fp = fdopen(fd, "wb")) == NULL) {
+ mprintf("@Can't open new file %s to write\n", file);
+ perror("fdopen");
+ close(fd);
+ return -1;
+ }
#ifdef NO_SNPRINTF
sprintf(cmd, "GET %s/%s HTTP/1.1\r\n"
@@ -466,11 +473,13 @@
if ((bread = recv(socketfd, buffer, FILEBUFF, 0)) == -1) {
mprintf("@Error while reading database from %s\n", hostname);
+ fclose(fp);
return -1;
}
if ((strstr(buffer, "HTTP/1.1 404")) != NULL) {
mprintf("@%s not found on remote server\n", dbfile);
+ fclose(fp);
return -1;
}
@@ -486,16 +495,16 @@
i++;
}
- write(fd, ch, bread - i);
+ fwrite(ch, 1, bread - i, fp);
while((bread = read(socketfd, buffer, FILEBUFF))) {
- write(fd, buffer, bread);
+ fwrite(buffer, 1, bread, fp);
mprintf("Downloading %s [%c]\r", dbfile, rotation[rot]);
fflush(stdout);
rot = ++rot % 4;
}
mprintf("Downloading %s [*]\n", dbfile);
- close(fd);
+ fclose(fp);
return 0;
}
