2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2006-05-15 18:30:18 +00:00
|
|
|
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
2006-04-09 19:59:28 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
2003-07-29 15:48:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2003-09-29 11:44:52 +00:00
|
|
|
#include <zlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <locale.h>
|
2003-10-20 00:55:11 +00:00
|
|
|
#include <sys/types.h>
|
2004-09-18 19:26:08 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2003-10-20 00:55:11 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <clamav.h>
|
2003-12-02 22:48:56 +00:00
|
|
|
#include <sys/wait.h>
|
2004-01-21 08:41:44 +00:00
|
|
|
#include <dirent.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-21 19:08:07 +00:00
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
|
|
|
|
2005-01-26 17:45:25 +00:00
|
|
|
#include "vba.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
#include "shared/options.h"
|
|
|
|
#include "shared/memory.h"
|
|
|
|
#include "shared/output.h"
|
|
|
|
#include "shared/cfgparser.h"
|
|
|
|
#include "shared/misc.h"
|
2006-06-15 13:57:42 +00:00
|
|
|
#include "shared/cdiff.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
#include "libclamav/cvd.h"
|
|
|
|
#include "libclamav/others.h"
|
|
|
|
#include "libclamav/str.h"
|
|
|
|
#include "libclamav/ole2_extract.h"
|
|
|
|
#include "libclamav/htmlnorm.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int hexdump(void)
|
|
|
|
{
|
|
|
|
char buffer[FILEBUFF], *pt;
|
|
|
|
int bytes;
|
2003-10-08 10:40:53 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
while((bytes = read(0, buffer, FILEBUFF)) > 0) {
|
|
|
|
pt = cli_str2hex(buffer, bytes);
|
|
|
|
if(write(1, pt, 2 * bytes) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!hexdump: Can't write to stdout\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
free(pt);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(pt);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(bytes == -1)
|
|
|
|
return -1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int md5sig(struct optstruct *opt)
|
|
|
|
{
|
|
|
|
char *md5, *filename;
|
|
|
|
int i;
|
|
|
|
struct stat sb;
|
2004-08-18 15:22:48 +00:00
|
|
|
|
2004-08-31 11:44:51 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(opt->filename) {
|
|
|
|
for(i = 0; (filename = cli_strtok(opt->filename, i, "\t")); i++) {
|
|
|
|
if(stat(filename, &sb) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!md5sig: Can't access file %s\n", filename);
|
2006-06-15 11:59:39 +00:00
|
|
|
perror("md5sig");
|
|
|
|
free(filename);
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
if((sb.st_mode & S_IFMT) == S_IFREG) {
|
|
|
|
if((md5 = cli_md5file(filename))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("%s:%d:%s\n", md5, sb.st_size, filename);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(md5);
|
|
|
|
} else {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!md5sig: Can't generate MD5 checksum for %s\n", filename);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(filename);
|
|
|
|
return -1;
|
2004-08-31 11:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
free(filename);
|
2004-09-18 19:26:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
} else { /* stream */
|
|
|
|
md5 = cli_md5stream(stdin, NULL);
|
|
|
|
if(!md5) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!md5sig: Can't generate MD5 checksum for input stream\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-10-20 00:55:11 +00:00
|
|
|
}
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("%s\n", md5);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(md5);
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int htmlnorm(struct optstruct *opt)
|
|
|
|
{
|
|
|
|
int fd;
|
2003-10-31 02:23:54 +00:00
|
|
|
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if((fd = open(opt_arg(opt, "html-normalise"), O_RDONLY)) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!htmlnorm: Can't open file %s\n", opt_arg(opt, "html-normalise"));
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-11-01 03:16:25 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
html_normalise_fd(fd, ".", NULL);
|
|
|
|
close(fd);
|
2003-11-01 03:16:25 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static unsigned int countlines(const char *filename)
|
|
|
|
{
|
|
|
|
FILE *fd;
|
|
|
|
char buff[1024];
|
|
|
|
unsigned int lines = 0;
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if((fd = fopen(filename, "r")) == NULL)
|
|
|
|
return 0;
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
while(fgets(buff, sizeof(buff), fd)) {
|
|
|
|
if(buff[0] == '#') continue;
|
|
|
|
lines++;
|
|
|
|
}
|
2004-12-14 11:20:01 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
fclose(fd);
|
|
|
|
return lines;
|
|
|
|
}
|
2004-12-14 11:20:01 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static char *getdsig(const char *host, const char *user, const char *data)
|
|
|
|
{
|
2006-06-21 19:08:07 +00:00
|
|
|
char buff[256], cmd[128], pass[30], *pt;
|
2006-06-15 11:59:39 +00:00
|
|
|
struct sockaddr_in server;
|
|
|
|
int sockd, bread, len;
|
2006-06-21 19:08:07 +00:00
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
struct termios old, new;
|
|
|
|
#endif
|
2004-12-14 11:20:01 +00:00
|
|
|
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
#ifdef PF_INET
|
|
|
|
if((sockd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
|
|
|
#else
|
|
|
|
if((sockd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
|
|
|
#endif
|
|
|
|
perror("socket()");
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: Can't create socket\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-12-14 11:20:01 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
server.sin_family = AF_INET;
|
|
|
|
server.sin_addr.s_addr = inet_addr(host);
|
|
|
|
server.sin_port = htons(33101);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(connect(sockd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) < 0) {
|
|
|
|
close(sockd);
|
|
|
|
perror("connect()");
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: Can't connect to ClamAV Signing Service at %s\n", host);
|
2006-06-15 11:59:39 +00:00
|
|
|
return NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2006-06-21 19:08:07 +00:00
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
mprintf("Password: ");
|
|
|
|
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
if(tcgetattr(0, &old)) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: tcgetattr() failed\n", host);
|
2006-06-21 19:08:07 +00:00
|
|
|
close(sockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
new = old;
|
|
|
|
new.c_lflag &= ~ECHO;
|
|
|
|
if(tcsetattr(0, TCSAFLUSH, &new)) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: tcsetattr() failed\n", host);
|
2006-06-21 19:08:07 +00:00
|
|
|
close(sockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(fgets(pass, sizeof(pass), stdin)) {
|
|
|
|
cli_chomp(pass);
|
|
|
|
} else {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: Can't get password\n");
|
2006-06-21 19:08:07 +00:00
|
|
|
close(sockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
if(tcsetattr(0, TCSAFLUSH, &old)) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: tcsetattr() failed\n", host);
|
2006-06-21 19:08:07 +00:00
|
|
|
close(sockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mprintf("\n");
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
snprintf(cmd, sizeof(cmd) - 16, "ClamSign:%s:%s:", user, pass);
|
|
|
|
len = strlen(cmd);
|
|
|
|
pt = cmd + len;
|
|
|
|
memcpy(pt, data, 16);
|
|
|
|
len += 16;
|
2003-10-26 06:01:03 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(write(sockd, cmd, len) < 0) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: Can't write to socket\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
close(sockd);
|
|
|
|
memset(cmd, 0, len);
|
|
|
|
memset(pass, 0, strlen(pass));
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-02-27 01:31:02 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
memset(cmd, 0, len);
|
|
|
|
memset(pass, 0, strlen(pass));
|
|
|
|
memset(buff, 0, sizeof(buff));
|
2003-10-26 06:01:03 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if((bread = read(sockd, buff, sizeof(buff))) > 0) {
|
|
|
|
if(!strstr(buff, "Signature:")) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!getdsig: Error generating digital signature\n");
|
|
|
|
mprintf("!getdsig: Answer from remote server: %s\n", buff);
|
2006-06-15 11:59:39 +00:00
|
|
|
close(sockd);
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Signature received (length = %d)\n", strlen(buff) - 10);
|
2006-06-15 11:59:39 +00:00
|
|
|
}
|
2005-02-27 01:31:02 +00:00
|
|
|
}
|
2003-10-26 06:01:03 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
close(sockd);
|
|
|
|
pt = buff;
|
|
|
|
pt += 10;
|
|
|
|
return strdup(pt);
|
2003-10-26 06:01:03 +00:00
|
|
|
}
|
|
|
|
|
2006-06-22 09:16:07 +00:00
|
|
|
static int writeinfo(const char *db, unsigned int ver)
|
|
|
|
{
|
|
|
|
FILE *fh;
|
|
|
|
int i;
|
|
|
|
struct stat sb;
|
|
|
|
char file[32], *md5;
|
|
|
|
char *extlist[] = { "db", "fp", "hdb", "ndb", "rmd", "zmd", "sdb", NULL };
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(file, sizeof(file), "%s.info", db);
|
|
|
|
if(stat(file, &sb) != -1) {
|
|
|
|
if(unlink(file) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!writeinfo: Can't unlink %s\n", file);
|
2006-06-22 09:16:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(fh = fopen(file, "w"))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!writeinfo: Can't create file %s\n", file);
|
2006-06-22 09:16:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fprintf(fh, "%s:%u\n", db, ver) < 0) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!writeinfo: Can't write to info file\n");
|
2006-06-22 09:16:07 +00:00
|
|
|
fclose(fh);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; extlist[i]; i++) {
|
|
|
|
snprintf(file, sizeof(file), "%s.%s", db, extlist[i]);
|
|
|
|
if(stat(file, &sb) != -1) {
|
|
|
|
if(!(md5 = cli_md5file(file))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!writeinfo: Can't generate MD5 checksum for %s\n", file);
|
2006-06-22 09:16:07 +00:00
|
|
|
fclose(fh);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(fprintf(fh, "%s.%s:%s\n", db, extlist[i], md5) < 0) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!writeinfo: Can't write to info file\n");
|
2006-06-22 09:16:07 +00:00
|
|
|
fclose(fh);
|
|
|
|
free(md5);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(md5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int build(struct optstruct *opt)
|
2003-09-29 11:44:52 +00:00
|
|
|
{
|
2006-06-22 09:16:07 +00:00
|
|
|
int ret;
|
2006-06-15 11:59:39 +00:00
|
|
|
size_t bytes;
|
2006-06-22 09:16:07 +00:00
|
|
|
unsigned int sigs = 0, lines = 0, version;
|
2003-09-29 11:44:52 +00:00
|
|
|
struct stat foo;
|
2006-06-15 11:59:39 +00:00
|
|
|
char buffer[FILEBUFF], *tarfile, *gzfile, header[513],
|
2005-01-26 14:15:04 +00:00
|
|
|
smbuff[30], *pt, *dbdir;
|
2003-09-29 11:44:52 +00:00
|
|
|
struct cl_node *root = NULL;
|
2006-06-15 11:59:39 +00:00
|
|
|
FILE *tar, *cvd;
|
2003-09-29 11:44:52 +00:00
|
|
|
gzFile *gz;
|
|
|
|
time_t timet;
|
|
|
|
struct tm *brokent;
|
2006-06-22 09:16:07 +00:00
|
|
|
struct cl_cvd *oldcvd;
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!opt_check(opt, "server")) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: --server is required for --build\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(stat("COPYING", &foo) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: COPYING file not found in current working directory.\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(stat("main.db", &foo) == -1 && stat("daily.db", &foo) == -1 &&
|
|
|
|
stat("main.hdb", &foo) == -1 && stat("daily.hdb", &foo) == -1 &&
|
|
|
|
stat("main.ndb", &foo) == -1 && stat("daily.ndb", &foo) == -1 &&
|
2006-06-22 09:16:07 +00:00
|
|
|
stat("main.sdb", &foo) == -1 && stat("daily.sdb", &foo) == -1 &&
|
2006-06-15 11:59:39 +00:00
|
|
|
stat("main.zmd", &foo) == -1 && stat("daily.zmd", &foo) == -1 &&
|
|
|
|
stat("main.rmd", &foo) == -1 && stat("daily.rmd", &foo) == -1)
|
|
|
|
{
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: No virus database file found in current directory\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
cl_debug(); /* enable debug messages in libclamav */
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if((ret = cl_loaddbdir(".", &root, &sigs))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't load database: %s\n", cl_strerror(ret));
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
cl_free(root);
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!sigs) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: There are no signatures in database files\n");
|
2003-10-31 02:23:54 +00:00
|
|
|
} else {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Signatures: %d\n", sigs);
|
2006-06-15 11:59:39 +00:00
|
|
|
lines = countlines("main.db") + countlines("daily.db") +
|
|
|
|
countlines("main.hdb") + countlines("daily.hdb") +
|
|
|
|
countlines("main.ndb") + countlines("daily.ndb") +
|
2006-06-22 09:16:07 +00:00
|
|
|
countlines("main.sdb") + countlines("daily.sdb") +
|
2006-06-15 11:59:39 +00:00
|
|
|
countlines("main.zmd") + countlines("daily.zmd") +
|
|
|
|
countlines("main.rmd") + countlines("daily.rmd") +
|
|
|
|
countlines("main.fp") + countlines("daily.fp");
|
|
|
|
|
|
|
|
if(lines != sigs) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Signatures in database: %d, loaded by libclamav: %d\n", lines, sigs);
|
|
|
|
mprintf("!build: Please check the current directory and remove unnecessary databases\n");
|
|
|
|
mprintf("!build: or install the latest ClamAV version.\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-10-31 02:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-22 09:16:07 +00:00
|
|
|
/* try to read cvd header of current database */
|
|
|
|
dbdir = freshdbdir();
|
|
|
|
snprintf(buffer, sizeof(buffer), "%s/%s", dbdir, opt_arg(opt, "build"));
|
|
|
|
free(dbdir);
|
|
|
|
if(!(oldcvd = cl_cvdhead(buffer))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("^build: CAN'T READ CVD HEADER OF CURRENT DATABASE %s\n", buffer);
|
2006-06-22 09:16:07 +00:00
|
|
|
sleep(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(oldcvd) {
|
|
|
|
version = oldcvd->version + 1;
|
|
|
|
cl_cvdfree(oldcvd);
|
|
|
|
} else {
|
|
|
|
fflush(stdin);
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Version number: ");
|
2006-06-22 09:16:07 +00:00
|
|
|
scanf("%u", &version);
|
|
|
|
}
|
|
|
|
|
|
|
|
pt = opt_arg(opt, "build");
|
|
|
|
if(strstr(pt, "main"))
|
|
|
|
pt = "main";
|
|
|
|
else
|
|
|
|
pt = "daily";
|
|
|
|
|
|
|
|
if(writeinfo(pt, version) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't generate info file\n");
|
2006-06-22 09:16:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!(tarfile = cli_gentemp("."))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't generate temporary name for tarfile\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
switch(fork()) {
|
|
|
|
case -1:
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't fork.\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
free(tarfile);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
case 0:
|
|
|
|
{
|
2006-06-15 11:59:39 +00:00
|
|
|
char *args[] = { "tar", "-cvf", NULL, "COPYING", "main.db",
|
|
|
|
"daily.db", "main.hdb", "daily.hdb",
|
2006-06-22 09:16:07 +00:00
|
|
|
"main.ndb", "daily.ndb", "main.sdb",
|
|
|
|
"daily.sdb", "main.zmd", "daily.zmd",
|
|
|
|
"main.rmd", "daily.rmd", "main.fp",
|
|
|
|
"daily.fp", "daily.info", "main.info", NULL };
|
2004-08-18 19:06:42 +00:00
|
|
|
args[2] = tarfile;
|
2003-09-29 11:44:52 +00:00
|
|
|
execv("/bin/tar", args);
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't execute tar\n");
|
2003-09-29 11:44:52 +00:00
|
|
|
perror("tar");
|
2006-06-15 11:59:39 +00:00
|
|
|
free(tarfile);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
wait(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stat(tarfile, &foo) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Tar archive was not created\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
free(tarfile);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if((tar = fopen(tarfile, "rb")) == NULL) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't open file %s\n", tarfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(tarfile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(gzfile = cli_gentemp("."))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't generate temporary name for gzfile\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
free(tarfile);
|
|
|
|
fclose(tar);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if((gz = gzopen(gzfile, "wb")) == NULL) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't open file %s to write.\n", gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(tarfile);
|
|
|
|
fclose(tar);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
while((bytes = fread(buffer, 1, FILEBUFF, tar)) > 0) {
|
|
|
|
if(!gzwrite(gz, buffer, bytes)) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't gzwrite to %s\n", gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
fclose(tar);
|
|
|
|
gzclose(gz);
|
|
|
|
free(tarfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
fclose(tar);
|
2006-06-15 11:59:39 +00:00
|
|
|
gzclose(gz);
|
2003-09-29 11:44:52 +00:00
|
|
|
unlink(tarfile);
|
|
|
|
free(tarfile);
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
/* build header */
|
2004-04-06 22:43:44 +00:00
|
|
|
strcpy(header, "ClamAV-VDB:");
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
/* time */
|
|
|
|
time(&timet);
|
|
|
|
brokent = localtime(&timet);
|
|
|
|
setlocale(LC_TIME, "C");
|
2006-06-15 11:59:39 +00:00
|
|
|
strftime(smbuff, sizeof(smbuff), "%d %b %Y %H-%M %z", brokent);
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, smbuff);
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
/* increment version number by one */
|
2006-06-22 09:16:07 +00:00
|
|
|
sprintf(smbuff, ":%d:", version);
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, smbuff);
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
/* number of signatures */
|
2006-06-15 11:59:39 +00:00
|
|
|
sprintf(smbuff, "%d:", sigs);
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, smbuff);
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2004-04-29 20:01:32 +00:00
|
|
|
/* functionality level */
|
|
|
|
sprintf(smbuff, "%d:", cl_retflevel());
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, smbuff);
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
/* MD5 */
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!(pt = cli_md5file(gzfile))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't generate MD5 checksum for gzfile\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
unlink(gzfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, pt);
|
2003-10-20 00:55:11 +00:00
|
|
|
free(pt);
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, ":");
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2004-08-31 18:46:00 +00:00
|
|
|
/* ask for builder name */
|
2003-10-20 00:55:11 +00:00
|
|
|
fflush(stdin);
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Builder name: ");
|
2006-06-15 11:59:39 +00:00
|
|
|
if(fgets(smbuff, sizeof(smbuff), stdin)) {
|
|
|
|
cli_chomp(smbuff);
|
|
|
|
} else {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't get builder name\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
unlink(gzfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
|
|
|
}
|
2003-10-20 00:55:11 +00:00
|
|
|
|
2003-09-29 11:44:52 +00:00
|
|
|
/* digital signature */
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!(tar = fopen(gzfile, "rb"))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't open file %s for reading\n", gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
unlink(gzfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(pt = cli_md5stream(tar, (unsigned char *) buffer))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't generate MD5 checksum for %s\n", gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
unlink(gzfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-09-01 14:14:21 +00:00
|
|
|
free(pt);
|
2006-06-15 11:59:39 +00:00
|
|
|
rewind(tar);
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if(!(pt = getdsig(opt_arg(opt, "server"), smbuff, buffer))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't get digital signature from remote server\n");
|
2003-10-31 02:23:54 +00:00
|
|
|
unlink(gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(gzfile);
|
|
|
|
fclose(tar);
|
|
|
|
return -1;
|
2003-10-20 00:55:11 +00:00
|
|
|
}
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, pt);
|
2003-10-20 00:55:11 +00:00
|
|
|
free(pt);
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, ":");
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2004-08-31 18:46:00 +00:00
|
|
|
/* add builder */
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, smbuff);
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2004-08-31 18:46:00 +00:00
|
|
|
/* add current time */
|
|
|
|
sprintf(header + strlen(header), ":%d", (int) timet);
|
|
|
|
|
2003-09-29 11:44:52 +00:00
|
|
|
/* fill up with spaces */
|
2006-06-15 11:59:39 +00:00
|
|
|
while(strlen(header) < sizeof(header) - 1)
|
2004-04-06 22:43:44 +00:00
|
|
|
strcat(header, " ");
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
/* build the final database */
|
2006-05-15 18:30:18 +00:00
|
|
|
pt = opt_arg(opt, "build");
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!(cvd = fopen(pt, "wb"))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't create final database %s\n", pt);
|
2003-10-31 02:23:54 +00:00
|
|
|
unlink(gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(gzfile);
|
|
|
|
fclose(tar);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(fwrite(header, 1, 512, cvd) != 512) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't write to %s\n", pt);
|
2006-06-15 11:59:39 +00:00
|
|
|
fclose(cvd);
|
|
|
|
fclose(tar);
|
|
|
|
unlink(pt);
|
|
|
|
unlink(gzfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
while((bytes = fread(buffer, 1, FILEBUFF, tar)) > 0) {
|
|
|
|
if(fwrite(buffer, 1, bytes, cvd) != bytes) {
|
|
|
|
fclose(tar);
|
|
|
|
fclose(cvd);
|
|
|
|
unlink(pt);
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!build: Can't write to %s\n", gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
unlink(gzfile);
|
|
|
|
free(gzfile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
|
|
|
|
fclose(tar);
|
|
|
|
fclose(cvd);
|
2006-06-15 11:59:39 +00:00
|
|
|
if(unlink(gzfile) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("^build: Can't unlink %s\n", gzfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-09-29 11:44:52 +00:00
|
|
|
free(gzfile);
|
|
|
|
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Database %s created\n", pt);
|
2006-06-15 11:59:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unpack(struct optstruct *opt)
|
|
|
|
{
|
|
|
|
char *name, *dbdir;
|
|
|
|
|
|
|
|
|
|
|
|
if(opt_check(opt, "unpack-current")) {
|
|
|
|
dbdir = freshdbdir();
|
|
|
|
name = mcalloc(strlen(dbdir) + strlen(opt_arg(opt, "unpack-current")) + 2, sizeof(char));
|
|
|
|
sprintf(name, "%s/%s", dbdir, opt_arg(opt, "unpack-current"));
|
|
|
|
free(dbdir);
|
|
|
|
} else
|
|
|
|
name = strdup(opt_arg(opt, "unpack"));
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(cvd_unpack(name, ".") == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!unpack: Can't unpack CVD file %s\n", name);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(name);
|
2003-12-02 22:48:56 +00:00
|
|
|
return 0;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int cvdinfo(struct optstruct *opt)
|
2003-09-29 11:44:52 +00:00
|
|
|
{
|
|
|
|
struct cl_cvd *cvd;
|
|
|
|
char *pt;
|
2003-10-08 10:40:53 +00:00
|
|
|
int ret;
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
pt = opt_arg(opt, "info");
|
2003-10-08 10:40:53 +00:00
|
|
|
if((cvd = cl_cvdhead(pt)) == NULL) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!cvdinfo: Can't read/parse CVD header of %s\n", pt);
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
pt = strchr(cvd->time, '-');
|
|
|
|
*pt = ':';
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Build time: %s\n", cvd->time);
|
|
|
|
mprintf("Version: %d\n", cvd->version);
|
|
|
|
mprintf("Signatures: %d\n", cvd->sigs);
|
|
|
|
mprintf("Functionality level: %d\n", cvd->fl);
|
|
|
|
mprintf("Builder: %s\n", cvd->builder);
|
|
|
|
mprintf("MD5: %s\n", cvd->md5);
|
|
|
|
mprintf("Digital signature: %s\n", cvd->dsig);
|
2003-09-29 11:44:52 +00:00
|
|
|
|
2003-10-08 10:40:53 +00:00
|
|
|
#ifndef HAVE_GMP
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("^Digital signature support not compiled in.\n");
|
2003-10-08 10:40:53 +00:00
|
|
|
#endif
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
pt = opt_arg(opt, "info");
|
2003-10-08 10:40:53 +00:00
|
|
|
if((ret = cl_cvdverify(pt)))
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!cvdinfo: Verification: %s\n", cl_strerror(ret));
|
2003-10-08 10:40:53 +00:00
|
|
|
else
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("Verification OK.\n");
|
2003-10-08 10:40:53 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
cl_cvdfree(cvd);
|
|
|
|
return 0;
|
2003-09-29 11:44:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int listdb(const char *filename);
|
2003-10-20 00:55:11 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int listdir(const char *dirname)
|
|
|
|
{
|
|
|
|
DIR *dd;
|
|
|
|
struct dirent *dent;
|
|
|
|
char *dbfile;
|
2003-10-20 00:55:11 +00:00
|
|
|
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if((dd = opendir(dirname)) == NULL) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdir: Can't open directory %s\n", dirname);
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
2003-10-20 00:55:11 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
while((dent = readdir(dd))) {
|
|
|
|
#ifndef C_INTERIX
|
|
|
|
if(dent->d_ino)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") &&
|
|
|
|
(cli_strbcasestr(dent->d_name, ".db") ||
|
|
|
|
cli_strbcasestr(dent->d_name, ".hdb") ||
|
|
|
|
cli_strbcasestr(dent->d_name, ".ndb") ||
|
2006-06-22 09:16:07 +00:00
|
|
|
cli_strbcasestr(dent->d_name, ".sdb") ||
|
2006-06-15 11:59:39 +00:00
|
|
|
cli_strbcasestr(dent->d_name, ".zmd") ||
|
|
|
|
cli_strbcasestr(dent->d_name, ".rmd") ||
|
|
|
|
cli_strbcasestr(dent->d_name, ".cvd"))) {
|
2003-10-20 00:55:11 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
dbfile = (char *) mcalloc(strlen(dent->d_name) + strlen(dirname) + 2, sizeof(char));
|
2003-10-20 00:55:11 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!dbfile) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdir: Can't allocate memory for dbfile\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
closedir(dd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sprintf(dbfile, "%s/%s", dirname, dent->d_name);
|
2003-10-20 00:55:11 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(listdb(dbfile) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Error listing database %s\n", dbfile);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(dbfile);
|
|
|
|
closedir(dd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(dbfile);
|
|
|
|
}
|
2003-12-02 22:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-20 00:55:11 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
closedir(dd);
|
|
|
|
return 0;
|
2003-10-31 02:23:54 +00:00
|
|
|
}
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int listdb(const char *filename)
|
2004-01-21 08:41:44 +00:00
|
|
|
{
|
2006-06-15 11:59:39 +00:00
|
|
|
FILE *fd;
|
|
|
|
char *buffer, *pt, *start, *dir;
|
|
|
|
int line = 0;
|
2004-01-21 08:41:44 +00:00
|
|
|
const char *tmpdir;
|
|
|
|
|
|
|
|
|
|
|
|
if((fd = fopen(filename, "rb")) == NULL) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Can't open file %s\n", filename);
|
2004-01-21 08:41:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!(buffer = (char *) mcalloc(FILEBUFF, 1))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Can't allocate memory for buffer\n");
|
2004-08-31 11:44:51 +00:00
|
|
|
fclose(fd);
|
2004-01-21 08:41:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for CVD file */
|
|
|
|
fgets(buffer, 12, fd);
|
|
|
|
rewind(fd);
|
|
|
|
|
|
|
|
if(!strncmp(buffer, "ClamAV-VDB:", 11)) {
|
2006-06-15 11:59:39 +00:00
|
|
|
free(buffer);
|
|
|
|
fclose(fd);
|
2004-01-21 08:41:44 +00:00
|
|
|
|
|
|
|
tmpdir = getenv("TMPDIR");
|
|
|
|
if(tmpdir == NULL)
|
|
|
|
#ifdef P_tmpdir
|
|
|
|
tmpdir = P_tmpdir;
|
|
|
|
#else
|
|
|
|
tmpdir = "/tmp";
|
|
|
|
#endif
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(!(dir = cli_gentemp(tmpdir))) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Can't generate temporary name\n");
|
2004-01-21 08:41:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(mkdir(dir, 0700)) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Can't create temporary directory %s\n", dir);
|
2004-01-21 08:41:44 +00:00
|
|
|
free(dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(cvd_unpack(filename, dir) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Can't unpack CVD file %s\n", filename);
|
2006-06-15 11:59:39 +00:00
|
|
|
rmdirs(dir);
|
2004-01-21 08:41:44 +00:00
|
|
|
free(dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* list extracted directory */
|
2006-06-15 11:59:39 +00:00
|
|
|
if(listdir(dir) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Can't unpack CVD file %s\n", filename);
|
2006-06-15 11:59:39 +00:00
|
|
|
rmdirs(dir);
|
|
|
|
free(dir);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
rmdirs(dir);
|
2004-01-21 08:41:44 +00:00
|
|
|
free(dir);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
if(cli_strbcasestr(filename, ".db")) { /* old style database */
|
2004-08-31 18:46:00 +00:00
|
|
|
|
|
|
|
while(fgets(buffer, FILEBUFF, fd)) {
|
|
|
|
line++;
|
|
|
|
pt = strchr(buffer, '=');
|
|
|
|
if(!pt) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Malformed pattern line %d (file %s)\n", line, filename);
|
2004-08-31 18:46:00 +00:00
|
|
|
fclose(fd);
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2004-08-31 18:46:00 +00:00
|
|
|
start = buffer;
|
|
|
|
*pt = 0;
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2004-08-31 18:46:00 +00:00
|
|
|
if((pt = strstr(start, " (Clam)")))
|
|
|
|
*pt = 0;
|
|
|
|
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("%s\n", start);
|
2004-01-21 08:41:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
} else if(cli_strbcasestr(filename, ".hdb")) { /* hash database */
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2004-08-31 18:46:00 +00:00
|
|
|
while(fgets(buffer, FILEBUFF, fd)) {
|
|
|
|
line++;
|
|
|
|
cli_chomp(buffer);
|
|
|
|
start = cli_strtok(buffer, 2, ":");
|
|
|
|
|
|
|
|
if(!start) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Malformed pattern line %d (file %s)\n", line, filename);
|
2004-08-31 18:46:00 +00:00
|
|
|
fclose(fd);
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((pt = strstr(start, " (Clam)")))
|
|
|
|
*pt = 0;
|
|
|
|
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("%s\n", start);
|
2004-08-31 18:46:00 +00:00
|
|
|
free(start);
|
|
|
|
}
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-22 09:16:07 +00:00
|
|
|
} else if(cli_strbcasestr(filename, ".ndb") || cli_strbcasestr(filename, ".sdb") || cli_strbcasestr(filename, ".zmd") || cli_strbcasestr(filename, ".rmd")) {
|
2004-09-17 23:29:44 +00:00
|
|
|
|
|
|
|
while(fgets(buffer, FILEBUFF, fd)) {
|
|
|
|
line++;
|
|
|
|
cli_chomp(buffer);
|
|
|
|
start = cli_strtok(buffer, 0, ":");
|
|
|
|
|
|
|
|
if(!start) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!listdb: Malformed pattern line %d (file %s)\n", line, filename);
|
2004-09-17 23:29:44 +00:00
|
|
|
fclose(fd);
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((pt = strstr(start, " (Clam)")))
|
|
|
|
*pt = 0;
|
|
|
|
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("%s\n", start);
|
2004-09-17 23:29:44 +00:00
|
|
|
free(start);
|
|
|
|
}
|
2004-01-21 08:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
free(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
static int listsigs(struct optstruct *opt)
|
2004-01-21 08:41:44 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const char *name;
|
2005-01-26 14:15:04 +00:00
|
|
|
char *dbdir;
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
|
2004-01-21 08:41:44 +00:00
|
|
|
mprintf_stdout = 1;
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
if((name = opt_arg(opt, "list-sigs"))) {
|
2004-01-21 08:41:44 +00:00
|
|
|
ret = listdb(name);
|
2005-01-26 14:15:04 +00:00
|
|
|
} else {
|
|
|
|
dbdir = freshdbdir();
|
|
|
|
ret = listdir(dbdir);
|
|
|
|
free(dbdir);
|
|
|
|
}
|
2004-01-21 08:41:44 +00:00
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vbadump(struct optstruct *opt)
|
|
|
|
{
|
|
|
|
int fd, hex_output=0;
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
|
|
|
|
if(opt_check(opt, "vba-hex"))
|
|
|
|
hex_output = 1;
|
|
|
|
|
|
|
|
if((fd = open(opt_arg(opt, "vba"), O_RDONLY)) == -1) {
|
|
|
|
if((fd = open(opt_arg(opt, "vba-hex"), O_RDONLY)) == -1) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!vbadump: Can't open file %s\n", opt_arg(opt, "vba"));
|
2006-06-15 11:59:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generate the temporary directory */
|
|
|
|
dir = cli_gentemp(NULL);
|
|
|
|
if(mkdir(dir, 0700)) {
|
2006-06-27 14:04:07 +00:00
|
|
|
mprintf("!vbadump: Can't create temporary directory %s\n", dir);
|
2006-06-15 11:59:39 +00:00
|
|
|
free(dir);
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cli_ole2_extract(fd, dir, NULL)) {
|
|
|
|
cli_rmdirs(dir);
|
|
|
|
free(dir);
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
sigtool_vba_scandir(dir, hex_output);
|
|
|
|
rmdirs(dir);
|
|
|
|
free(dir);
|
|
|
|
return 0;
|
2004-02-01 01:18:57 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 13:57:42 +00:00
|
|
|
static int runcdiff(struct optstruct *opt)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
|
|
|
|
if((fd = open(opt_arg(opt, "run-cdiff"), O_RDONLY)) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = cdiff_apply(fd);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-06-27 22:02:59 +00:00
|
|
|
static int compare(const char *oldpath, const char *newpath, FILE *diff)
|
|
|
|
{
|
|
|
|
FILE *old, *new;
|
|
|
|
char obuff[1024], nbuff[1024], *pt, *omd5, *nmd5;
|
|
|
|
unsigned int line = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(!(new = fopen(newpath, "r"))) {
|
|
|
|
mprintf("!compare: Can't open file %s for reading\n", newpath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((omd5 = cli_md5file(oldpath))) {
|
|
|
|
if(!(nmd5 = cli_md5file(newpath))) {
|
|
|
|
mprintf("!compare: Can't get MD5 checksum of %s\n", newpath);
|
|
|
|
free(omd5);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!strcmp(omd5, nmd5)) {
|
|
|
|
free(omd5);
|
|
|
|
free(nmd5);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
free(omd5);
|
|
|
|
free(nmd5);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(diff, "OPEN %s\n", newpath);
|
|
|
|
|
|
|
|
old = fopen(oldpath, "r");
|
|
|
|
|
|
|
|
while(fgets(nbuff, sizeof(nbuff), new)) {
|
|
|
|
line++;
|
|
|
|
cli_chomp(nbuff);
|
|
|
|
|
|
|
|
if(!old) {
|
|
|
|
fprintf(diff, "ADD %s\n", nbuff);
|
|
|
|
} else {
|
|
|
|
if(fgets(obuff, sizeof(obuff), old)) {
|
|
|
|
cli_chomp(obuff);
|
|
|
|
if(!strcmp(nbuff, obuff)) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* TODO: Improve/add detection of DEL, XCHG */
|
|
|
|
if(!strncmp(nbuff, obuff, 5)) {
|
|
|
|
obuff[8] = 0;
|
|
|
|
if((pt = strchr(obuff, ' ')))
|
|
|
|
*pt = 0;
|
|
|
|
fprintf(diff, "XCHG %u %s %s\n", line, obuff, nbuff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fclose(old);
|
|
|
|
old = NULL;
|
|
|
|
fprintf(diff, "ADD %s\n", nbuff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(old)
|
|
|
|
fclose(old);
|
|
|
|
fprintf(diff, "CLOSE\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int makediff(struct optstruct *opt)
|
|
|
|
{
|
|
|
|
FILE *diff;
|
|
|
|
DIR *dd;
|
|
|
|
struct dirent *dent;
|
|
|
|
char *odir, *ndir, opath[1024], name[32];
|
|
|
|
struct cl_cvd *cvd;
|
|
|
|
unsigned int oldver, newver;
|
|
|
|
|
|
|
|
|
|
|
|
if(!opt->filename) {
|
|
|
|
mprintf("!makediff: --diff requires two arguments\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(cvd = cl_cvdhead(opt->filename))) {
|
|
|
|
mprintf("!makediff: Can't read CVD header from %s\n", opt->filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
newver = cvd->version;
|
|
|
|
free(cvd);
|
|
|
|
|
|
|
|
if(!(cvd = cl_cvdhead(opt_arg(opt, "diff")))) {
|
|
|
|
mprintf("!makediff: Can't read CVD header from %s\n", opt_arg(opt, "diff"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
oldver = cvd->version;
|
|
|
|
free(cvd);
|
|
|
|
|
|
|
|
if(oldver + 1 != newver) {
|
|
|
|
mprintf("!makediff: The old CVD must be %u\n", newver - 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
odir = cli_gentemp(NULL);
|
|
|
|
if(!odir) {
|
|
|
|
mprintf("!makediff: Can't generate temporary name for odir\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mkdir(odir, 0700) == -1) {
|
|
|
|
mprintf("!makediff: Can't create directory %s\n", odir);
|
|
|
|
free(odir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cvd_unpack(opt_arg(opt, "diff"), odir) == -1) {
|
|
|
|
mprintf("!makediff: Can't unpack CVD file %s\n", opt_arg(opt, "diff"));
|
|
|
|
rmdirs(odir);
|
|
|
|
free(odir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndir = cli_gentemp(NULL);
|
|
|
|
if(!ndir) {
|
|
|
|
mprintf("!makediff: Can't generate temporary name for ndir\n");
|
|
|
|
rmdirs(odir);
|
|
|
|
free(odir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mkdir(ndir, 0700) == -1) {
|
|
|
|
mprintf("!makediff: Can't create directory %s\n", ndir);
|
|
|
|
free(ndir);
|
|
|
|
rmdirs(odir);
|
|
|
|
free(odir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cvd_unpack(opt->filename, ndir) == -1) {
|
|
|
|
mprintf("!makediff: Can't unpack CVD file %s\n", opt->filename);
|
|
|
|
rmdirs(odir);
|
|
|
|
rmdirs(ndir);
|
|
|
|
free(odir);
|
|
|
|
free(ndir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strstr(opt->filename, "main"))
|
|
|
|
snprintf(name, sizeof(name), "main-%u.cdiff", newver);
|
|
|
|
else
|
|
|
|
snprintf(name, sizeof(name), "daily-%u.cdiff", newver);
|
|
|
|
|
|
|
|
if(!(diff = fopen(name, "w"))) {
|
|
|
|
mprintf("!makediff: Can't open %s for writing\n", name);
|
|
|
|
rmdirs(odir);
|
|
|
|
rmdirs(ndir);
|
|
|
|
free(odir);
|
|
|
|
free(ndir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(chdir(ndir) == -1) {
|
|
|
|
mprintf("!makediff: Can't chdir to %s\n", ndir);
|
|
|
|
rmdirs(odir);
|
|
|
|
rmdirs(ndir);
|
|
|
|
free(odir);
|
|
|
|
free(ndir);
|
|
|
|
fclose(diff);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((dd = opendir(ndir)) == NULL) {
|
|
|
|
mprintf("!makediff: Can't open directory %s\n", ndir);
|
|
|
|
rmdirs(odir);
|
|
|
|
rmdirs(ndir);
|
|
|
|
free(odir);
|
|
|
|
free(ndir);
|
|
|
|
fclose(diff);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((dent = readdir(dd))) {
|
|
|
|
#ifndef C_INTERIX
|
|
|
|
if(dent->d_ino)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if(!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
snprintf(opath, sizeof(opath), "%s/%s", odir, dent->d_name);
|
|
|
|
if(compare(opath, dent->d_name, diff) == -1) {
|
|
|
|
rmdirs(odir);
|
|
|
|
rmdirs(ndir);
|
|
|
|
free(odir);
|
|
|
|
free(ndir);
|
|
|
|
fclose(diff);
|
|
|
|
unlink(name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(diff);
|
|
|
|
rmdirs(odir);
|
|
|
|
rmdirs(ndir);
|
|
|
|
free(odir);
|
|
|
|
free(ndir);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-01 01:18:57 +00:00
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
mprintf("\n");
|
2005-03-18 11:57:56 +00:00
|
|
|
mprintf(" Clam AntiVirus: Signature Tool (sigtool) "VERSION"\n");
|
2006-06-15 11:59:39 +00:00
|
|
|
mprintf(" (C) 2002 - 2006 ClamAV Team - http://www.clamav.net/team.html\n\n");
|
2004-02-01 01:18:57 +00:00
|
|
|
|
|
|
|
mprintf(" --help -h show help\n");
|
|
|
|
mprintf(" --version -V print version number and exit\n");
|
|
|
|
mprintf(" --quiet be quiet, output only error messages\n");
|
|
|
|
mprintf(" --debug enable debug messages\n");
|
|
|
|
mprintf(" --stdout write to stdout instead of stderr\n");
|
|
|
|
mprintf(" --hex-dump convert data from stdin to a hex\n");
|
|
|
|
mprintf(" string and print it on stdout\n");
|
2004-08-31 11:44:51 +00:00
|
|
|
mprintf(" --md5 [FILES] generate MD5 checksum from stdin\n");
|
|
|
|
mprintf(" or MD5 sigs for FILES\n");
|
2004-09-18 19:26:08 +00:00
|
|
|
mprintf(" --html-normalise=FILE create normalised parts of HTML file\n");
|
2004-02-01 01:18:57 +00:00
|
|
|
mprintf(" --info=FILE -i FILE print database information\n");
|
|
|
|
mprintf(" --build=NAME -b NAME build a CVD file\n");
|
|
|
|
mprintf(" --server=ADDR ClamAV Signing Service address\n");
|
|
|
|
mprintf(" --unpack=FILE -u FILE Unpack a CVD file\n");
|
|
|
|
mprintf(" --unpack-current=NAME Unpack local CVD\n");
|
|
|
|
mprintf(" --list-sigs[=FILE] -l[FILE] List signature names\n");
|
2004-12-14 11:20:01 +00:00
|
|
|
mprintf(" --vba=FILE Extract VBA/Word6 macro code\n");
|
|
|
|
mprintf(" --vba-hex=FILE Extract Word6 macro code with hex values\n");
|
2006-06-15 13:57:42 +00:00
|
|
|
mprintf(" --vba-hex=FILE Extract Word6 macro code with hex values\n");
|
2006-06-27 22:02:59 +00:00
|
|
|
mprintf(" --diff=OLD NEW -d OLD NEW Create diff for OLD and NEW CVDs\n");
|
2006-06-15 13:57:42 +00:00
|
|
|
mprintf(" --run-cdiff=FILE -r FILE Execute update script FILE in cwd\n");
|
2004-02-01 01:18:57 +00:00
|
|
|
mprintf("\n");
|
|
|
|
|
2006-06-15 11:59:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret = 1;
|
|
|
|
struct optstruct *opt;
|
2006-06-27 22:02:59 +00:00
|
|
|
const char *short_options = "hvVb:i:u:l::r:d:";
|
2006-06-15 11:59:39 +00:00
|
|
|
static struct option long_options[] = {
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"quiet", 0, 0, 0},
|
|
|
|
{"debug", 0, 0, 0},
|
|
|
|
{"verbose", 0, 0, 'v'},
|
|
|
|
{"stdout", 0, 0, 0},
|
|
|
|
{"version", 0, 0, 'V'},
|
|
|
|
{"tempdir", 1, 0, 0},
|
|
|
|
{"hex-dump", 0, 0, 0},
|
|
|
|
{"md5", 0, 0, 0},
|
|
|
|
{"html-normalise", 1, 0, 0},
|
|
|
|
{"build", 1, 0, 'b'},
|
|
|
|
{"server", 1, 0, 0},
|
|
|
|
{"unpack", 1, 0, 'u'},
|
|
|
|
{"unpack-current", 1, 0, 0},
|
|
|
|
{"info", 1, 0, 'i'},
|
|
|
|
{"list-sigs", 2, 0, 'l'},
|
|
|
|
{"vba", 1, 0 ,0},
|
|
|
|
{"vba-hex", 1, 0, 0},
|
2006-06-27 22:02:59 +00:00
|
|
|
{"diff", 1, 0, 'd'},
|
2006-06-15 13:57:42 +00:00
|
|
|
{"run-cdiff", 1, 0, 'r'},
|
2006-06-15 11:59:39 +00:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
opt = opt_parse(argc, argv, short_options, long_options, NULL);
|
|
|
|
if(!opt) {
|
|
|
|
mprintf("!Can't parse the command line\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_check(opt, "quiet"))
|
|
|
|
mprintf_quiet = 1;
|
|
|
|
|
|
|
|
if(opt_check(opt, "stdout"))
|
|
|
|
mprintf_stdout = 1;
|
|
|
|
|
|
|
|
if(opt_check(opt, "debug"))
|
|
|
|
cl_debug();
|
|
|
|
|
|
|
|
if(opt_check(opt, "version")) {
|
|
|
|
print_version();
|
|
|
|
opt_free(opt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_check(opt, "help")) {
|
|
|
|
opt_free(opt);
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_check(opt, "hex-dump"))
|
|
|
|
ret = hexdump();
|
|
|
|
else if(opt_check(opt, "md5"))
|
|
|
|
ret = md5sig(opt);
|
|
|
|
else if(opt_check(opt, "html-normalise"))
|
|
|
|
ret = htmlnorm(opt);
|
|
|
|
else if(opt_check(opt, "build"))
|
|
|
|
ret = build(opt);
|
|
|
|
else if(opt_check(opt, "unpack"))
|
|
|
|
ret = unpack(opt);
|
|
|
|
else if(opt_check(opt, "unpack-current"))
|
|
|
|
ret = unpack(opt);
|
|
|
|
else if(opt_check(opt, "info"))
|
|
|
|
ret = cvdinfo(opt);
|
|
|
|
else if(opt_check(opt, "list-sigs"))
|
|
|
|
ret = listsigs(opt);
|
|
|
|
else if(opt_check(opt, "vba") || opt_check(opt, "vba-hex"))
|
|
|
|
ret = vbadump(opt);
|
2006-06-27 22:02:59 +00:00
|
|
|
else if(opt_check(opt, "diff"))
|
|
|
|
ret = makediff(opt);
|
2006-06-15 13:57:42 +00:00
|
|
|
else if(opt_check(opt, "run-cdiff"))
|
|
|
|
ret = runcdiff(opt);
|
2006-06-15 11:59:39 +00:00
|
|
|
else
|
|
|
|
help();
|
|
|
|
|
|
|
|
|
|
|
|
opt_free(opt);
|
|
|
|
return ret ? 1 : 0;
|
2004-01-21 08:41:44 +00:00
|
|
|
}
|