git-svn: trunk@194
Tomasz Kojm authored on 2004/01/21 17:41:44... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Wed Jan 21 09:38:01 CET 2004 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * sigtool: --list-sigs: list virus signature names from all databases. |
|
4 |
+ Optionally it can list signatures from selected database |
|
5 |
+ (--list-sigs=/path/to/database) |
|
6 |
+ |
|
1 | 7 |
Tue Jan 20 11:34:38 CET 2004 (tk) |
2 | 8 |
--------------------------------- |
3 | 9 |
* clamd: new commands: SESSION, END: SESSION starts a clamd session and |
... | ... |
@@ -61,7 +61,7 @@ struct cfgstruct *parsecfg(const char *cfgfile) |
61 | 61 |
{"MaxConnectionQueueLength", OPT_NUM}, |
62 | 62 |
{"StreamSaveToDisk", OPT_NOARG}, |
63 | 63 |
{"StreamMaxLength", OPT_COMPSIZE}, |
64 |
- {"UseProcessess", OPT_NOARG}, |
|
64 |
+ {"UseProcesses", OPT_NOARG}, |
|
65 | 65 |
{"MaxThreads", OPT_NUM}, |
66 | 66 |
{"ThreadTimeout", OPT_NUM}, |
67 | 67 |
{"MaxDirectoryRecursion", OPT_NUM}, |
... | ... |
@@ -96,7 +96,7 @@ int localserver(const struct optstruct *opt, const struct cfgstruct *copt, struc |
96 | 96 |
exit(1); |
97 | 97 |
} |
98 | 98 |
|
99 |
- if(cfgopt(copt, "UseProcessess")) |
|
99 |
+ if(cfgopt(copt, "UseProcesses")) |
|
100 | 100 |
acceptloop_proc(sockfd, root, copt); |
101 | 101 |
else |
102 | 102 |
acceptloop_th(sockfd, root, copt); |
... | ... |
@@ -75,16 +75,19 @@ void *threadscanner(void *arg) |
75 | 75 |
void *threadwatcher(void *arg) |
76 | 76 |
{ |
77 | 77 |
struct thrwarg *thwarg = (struct thrwarg *) arg; |
78 |
- struct thrarg *tharg; |
|
79 |
- pthread_attr_t thattr; |
|
80 | 78 |
struct cfgstruct *cpt; |
81 | 79 |
sigset_t sigset; |
82 |
- int i, j, ret, maxwait, virnum; |
|
80 |
+ int i, j, ret, virnum; |
|
83 | 81 |
unsigned long int timer = 0; |
84 | 82 |
unsigned int timeout, threads, selfchk; |
85 | 83 |
short int need_wait = 0, do_loop = 0, db_problem = 0; |
86 | 84 |
const char *dbdir; |
87 | 85 |
struct cl_stat dbstat; |
86 |
+#ifdef CLAMUKO |
|
87 |
+ struct thrarg *tharg; |
|
88 |
+ pthread_attr_t thattr; |
|
89 |
+ int maxwait; |
|
90 |
+#endif |
|
88 | 91 |
|
89 | 92 |
|
90 | 93 |
/* ignore all signals (except for SIGSEGV) */ |
... | ... |
@@ -95,7 +95,7 @@ int tcpserver(const struct optstruct *opt, const struct cfgstruct *copt, struct |
95 | 95 |
exit(1); |
96 | 96 |
} |
97 | 97 |
|
98 |
- if(cfgopt(copt, "UseProcessess")) |
|
98 |
+ if(cfgopt(copt, "UseProcesses")) |
|
99 | 99 |
acceptloop_proc(sockfd, root, copt); |
100 | 100 |
else |
101 | 101 |
acceptloop_th(sockfd, root, copt); |
... | ... |
@@ -76,7 +76,7 @@ LocalSocket /tmp/clamd |
76 | 76 |
#StreamMaxLength 10M |
77 | 77 |
|
78 | 78 |
# Use processes instead of threads (thread directives apply to processes too) |
79 |
-#UseProcessess |
|
79 |
+#UseProcesses |
|
80 | 80 |
|
81 | 81 |
# Maximal number of a threads running at the same time. |
82 | 82 |
# Default is 5, and it should be sufficient for a typical workstation. |
... | ... |
@@ -38,7 +38,7 @@ int main(int argc, char **argv) |
38 | 38 |
int ret, opt_index, i, len; |
39 | 39 |
struct optstruct *opt; |
40 | 40 |
|
41 |
- const char *getopt_parameters = "hvVc:s:f:b:i:u:"; |
|
41 |
+ const char *getopt_parameters = "hvVc:s:f:b:i:u:l"; |
|
42 | 42 |
|
43 | 43 |
static struct option long_options[] = { |
44 | 44 |
{"help", 0, 0, 'h'}, |
... | ... |
@@ -57,6 +57,7 @@ int main(int argc, char **argv) |
57 | 57 |
{"unpack", 1, 0, 'u'}, |
58 | 58 |
{"unpack-current", 1, 0, 0}, |
59 | 59 |
{"info", 1, 0, 'i'}, |
60 |
+ {"list-sigs", 2, 0, 0}, |
|
60 | 61 |
{0, 0, 0, 0} |
61 | 62 |
}; |
62 | 63 |
|
... | ... |
@@ -32,6 +32,7 @@ |
32 | 32 |
#include <arpa/inet.h> |
33 | 33 |
#include <clamav.h> |
34 | 34 |
#include <sys/wait.h> |
35 |
+#include <dirent.h> |
|
35 | 36 |
|
36 | 37 |
#include "options.h" |
37 | 38 |
#include "others.h" |
... | ... |
@@ -51,6 +52,10 @@ char *getdsig(const char *host, const char *user, const char *data); |
51 | 51 |
void cvdinfo(struct optstruct *opt); |
52 | 52 |
int build(struct optstruct *opt); |
53 | 53 |
int unpack(struct optstruct *opt); |
54 |
+int listdb(const char *filename); |
|
55 |
+int listdir(const char *dirname); |
|
56 |
+void listsigs(struct optstruct *opt); |
|
57 |
+int cli_rmdirs(const char *dirname); /* libclamav's internal */ |
|
54 | 58 |
|
55 | 59 |
int scanfile(const char *cmd, const char *str, const char *file) |
56 | 60 |
{ |
... | ... |
@@ -215,10 +220,14 @@ void sigtool(struct optstruct *opt) |
215 | 215 |
|
216 | 216 |
cvdinfo(opt); |
217 | 217 |
|
218 |
+ } else if(optl(opt, "list-sigs")) { |
|
219 |
+ |
|
220 |
+ listsigs(opt); |
|
221 |
+ |
|
218 | 222 |
} else { |
219 |
- int jmp, lastjmp, end, found = 0, exec = 0, pos, filesize, |
|
223 |
+ int jmp, lastjmp = 0, end, found = 0, exec = 0, pos, filesize, |
|
220 | 224 |
maxsize = 0, ret; |
221 |
- char *c, *s, *f, *tmp, *signame, *bsigname, *f2; |
|
225 |
+ char *c, *s, *f, *tmp, *signame, *bsigname, *f2 = NULL; |
|
222 | 226 |
FILE *fd, *wd; |
223 | 227 |
|
224 | 228 |
if(!optc(opt, 'c')) { |
... | ... |
@@ -608,7 +617,7 @@ int build(struct optstruct *opt) |
608 | 608 |
/* builder - question */ |
609 | 609 |
fflush(stdin); |
610 | 610 |
mprintf("Builder id: "); |
611 |
- fscanf(stdin, "%s", &smbuff); |
|
611 |
+ fscanf(stdin, "%s", smbuff); |
|
612 | 612 |
|
613 | 613 |
/* digital signature */ |
614 | 614 |
fd = fopen(gzfile, "rb"); |
... | ... |
@@ -705,7 +714,7 @@ void help(void) |
705 | 705 |
{ |
706 | 706 |
mprintf("\n"); |
707 | 707 |
mprintf(" Clam AntiVirus: Signature Tool (sigtool) "VERSION"\n"); |
708 |
- mprintf(" (c) 2002, 2003 Tomasz Kojm <tkojm@clamav.net>\n\n"); |
|
708 |
+ mprintf(" (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>\n\n"); |
|
709 | 709 |
|
710 | 710 |
mprintf(" --help -h show help\n"); |
711 | 711 |
mprintf(" --version -V print version number and exit\n"); |
... | ... |
@@ -723,6 +732,7 @@ void help(void) |
723 | 723 |
mprintf(" --server=ADDR ClamAV Signing Service address\n"); |
724 | 724 |
mprintf(" --unpack=FILE -u FILE Unpack a CVD file\n"); |
725 | 725 |
mprintf(" --unpack-current=NAME Unpack local CVD\n"); |
726 |
+ mprintf(" --list-sigs[=FILE] List virus signatures\n"); |
|
726 | 727 |
mprintf("\n"); |
727 | 728 |
|
728 | 729 |
exit(0); |
... | ... |
@@ -821,3 +831,181 @@ int unpack(struct optstruct *opt) |
821 | 821 |
fclose(fd); |
822 | 822 |
exit(0); |
823 | 823 |
} |
824 |
+ |
|
825 |
+int listdb(const char *filename) |
|
826 |
+{ |
|
827 |
+ FILE *fd, *tmpd; |
|
828 |
+ char *buffer, *pt, *start, *dir, *tmp; |
|
829 |
+ int line = 0, bytes; |
|
830 |
+ const char *tmpdir; |
|
831 |
+ |
|
832 |
+ |
|
833 |
+ if((fd = fopen(filename, "rb")) == NULL) { |
|
834 |
+ mprintf("!listdb(): Can't open file %s\n", filename); |
|
835 |
+ return -1; |
|
836 |
+ } |
|
837 |
+ |
|
838 |
+ if(!(buffer = (char *) mmalloc(FILEBUFF))) { |
|
839 |
+ mprintf("!listdb(): Can't allocate memory.\n"); |
|
840 |
+ return -1; |
|
841 |
+ } |
|
842 |
+ |
|
843 |
+ memset(buffer, 0, FILEBUFF); |
|
844 |
+ /* check for CVD file */ |
|
845 |
+ fgets(buffer, 12, fd); |
|
846 |
+ rewind(fd); |
|
847 |
+ |
|
848 |
+ if(!strncmp(buffer, "ClamAV-VDB:", 11)) { |
|
849 |
+ |
|
850 |
+ fseek(fd, 512, SEEK_SET); |
|
851 |
+ |
|
852 |
+ tmpdir = getenv("TMPDIR"); |
|
853 |
+ if(tmpdir == NULL) |
|
854 |
+#ifdef P_tmpdir |
|
855 |
+ tmpdir = P_tmpdir; |
|
856 |
+#else |
|
857 |
+ tmpdir = "/tmp"; |
|
858 |
+#endif |
|
859 |
+ |
|
860 |
+ dir = cl_gentemp(tmpdir); |
|
861 |
+ if(mkdir(dir, 0700)) { |
|
862 |
+ mprintf("!listdb(): Can't create temporary directory %s\n", dir); |
|
863 |
+ free(buffer); |
|
864 |
+ fclose(fd); |
|
865 |
+ return -1; |
|
866 |
+ } |
|
867 |
+ |
|
868 |
+ /* FIXME: it seems there is some problem with current position indicator |
|
869 |
+ * after gzdopen() call in cli_untgz(). Temporarily we need this wrapper: |
|
870 |
+ */ |
|
871 |
+ |
|
872 |
+ /* start */ |
|
873 |
+ |
|
874 |
+ tmp = cl_gentemp(tmpdir); |
|
875 |
+ if((tmpd = fopen(tmp, "wb+")) == NULL) { |
|
876 |
+ mprintf("!listdb(): Can't create temporary file %s\n", tmp); |
|
877 |
+ free(dir); |
|
878 |
+ free(tmp); |
|
879 |
+ free(buffer); |
|
880 |
+ fclose(fd); |
|
881 |
+ return -1; |
|
882 |
+ } |
|
883 |
+ |
|
884 |
+ while((bytes = fread(buffer, 1, FILEBUFF, fd)) > 0) |
|
885 |
+ fwrite(buffer, 1, bytes, tmpd); |
|
886 |
+ |
|
887 |
+ free(buffer); |
|
888 |
+ fclose(fd); |
|
889 |
+ |
|
890 |
+ fflush(tmpd); |
|
891 |
+ fseek(tmpd, 0L, SEEK_SET); |
|
892 |
+ |
|
893 |
+ if(cli_untgz(fileno(tmpd), dir)) { |
|
894 |
+ mprintf("!listdb(): Can't unpack CVD file.\n"); |
|
895 |
+ cli_rmdirs(dir); |
|
896 |
+ free(dir); |
|
897 |
+ unlink(tmp); |
|
898 |
+ free(tmp); |
|
899 |
+ free(buffer); |
|
900 |
+ return -1; |
|
901 |
+ } |
|
902 |
+ |
|
903 |
+ fclose(tmpd); |
|
904 |
+ unlink(tmp); |
|
905 |
+ free(tmp); |
|
906 |
+ |
|
907 |
+ /* wrapper end */ |
|
908 |
+ |
|
909 |
+ /* list extracted directory */ |
|
910 |
+ listdir(dir); |
|
911 |
+ |
|
912 |
+ cli_rmdirs(dir); |
|
913 |
+ free(dir); |
|
914 |
+ |
|
915 |
+ return 0; |
|
916 |
+ } |
|
917 |
+ |
|
918 |
+ |
|
919 |
+ /* old style database */ |
|
920 |
+ |
|
921 |
+ while(fgets(buffer, FILEBUFF, fd)) { |
|
922 |
+ line++; |
|
923 |
+ pt = strchr(buffer, '='); |
|
924 |
+ if(!pt) { |
|
925 |
+ mprintf("!listdb(): Malformed pattern line %d (file %s).\n", line, filename); |
|
926 |
+ fclose(fd); |
|
927 |
+ free(buffer); |
|
928 |
+ return -1; |
|
929 |
+ } |
|
930 |
+ |
|
931 |
+ start = buffer; |
|
932 |
+ *pt = 0; |
|
933 |
+ |
|
934 |
+ if((pt = strstr(start, " (Clam)"))) |
|
935 |
+ *pt = 0; |
|
936 |
+ |
|
937 |
+ mprintf("%s\n", start); |
|
938 |
+ } |
|
939 |
+ |
|
940 |
+ fclose(fd); |
|
941 |
+ free(buffer); |
|
942 |
+ return 0; |
|
943 |
+} |
|
944 |
+ |
|
945 |
+int listdir(const char *dirname) |
|
946 |
+{ |
|
947 |
+ DIR *dd; |
|
948 |
+ struct dirent *dent; |
|
949 |
+ char *dbfile; |
|
950 |
+ |
|
951 |
+ |
|
952 |
+ if((dd = opendir(dirname)) == NULL) { |
|
953 |
+ mprintf("!Can't open directory %s\n", dirname); |
|
954 |
+ return -1; |
|
955 |
+ } |
|
956 |
+ |
|
957 |
+ while((dent = readdir(dd))) { |
|
958 |
+ if(dent->d_ino) { |
|
959 |
+ if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && |
|
960 |
+ (cli_strbcasestr(dent->d_name, ".db") || |
|
961 |
+ cli_strbcasestr(dent->d_name, ".db2") || |
|
962 |
+ cli_strbcasestr(dent->d_name, ".cvd"))) { |
|
963 |
+ |
|
964 |
+ dbfile = (char *) mcalloc(strlen(dent->d_name) + strlen(dirname) + 2, sizeof(char)); |
|
965 |
+ |
|
966 |
+ if(!dbfile) { |
|
967 |
+ mprintf("!listdir(): Can't allocate memory.\n"); |
|
968 |
+ closedir(dd); |
|
969 |
+ return -1; |
|
970 |
+ } |
|
971 |
+ sprintf(dbfile, "%s/%s", dirname, dent->d_name); |
|
972 |
+ |
|
973 |
+ if(listdb(dbfile)) { |
|
974 |
+ mprintf("!listdb(): error listing database %s\n", dbfile); |
|
975 |
+ free(dbfile); |
|
976 |
+ closedir(dd); |
|
977 |
+ return -1; |
|
978 |
+ } |
|
979 |
+ free(dbfile); |
|
980 |
+ } |
|
981 |
+ } |
|
982 |
+ } |
|
983 |
+ |
|
984 |
+ closedir(dd); |
|
985 |
+ return 0; |
|
986 |
+} |
|
987 |
+ |
|
988 |
+void listsigs(struct optstruct *opt) |
|
989 |
+{ |
|
990 |
+ int ret; |
|
991 |
+ const char *name; |
|
992 |
+ |
|
993 |
+ mprintf_stdout = 1; |
|
994 |
+ |
|
995 |
+ if((name = getargl(opt, "list-sigs"))) |
|
996 |
+ ret = listdb(name); |
|
997 |
+ else |
|
998 |
+ ret = listdir(cl_retdbdir()); |
|
999 |
+ |
|
1000 |
+ return ret ? exit(1) : exit(0); |
|
1001 |
+} |