git-svn: trunk@550
Tomasz Kojm authored on 2004/05/10 09:48:15... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Mon May 10 02:43:32 CEST 2004 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamscan, sigtool: compare clamav.conf's DatabaseDirectory against the |
|
4 |
+ hardcoded directory and select more fresh one (by |
|
5 |
+ checking version numbers of daily.cvd) |
|
6 |
+ |
|
1 | 7 |
Mon May 10 00:05:23 CEST 2004 (tk) |
2 | 8 |
---------------------------------- |
3 | 9 |
* clamscan: + allow regular expressions in --[in|ex]clude (patch by |
... | ... |
@@ -127,6 +127,8 @@ clamscan_SOURCES = \ |
127 | 127 |
$(top_srcdir)/shared/getopt.h \ |
128 | 128 |
$(top_srcdir)/shared/memory.c \ |
129 | 129 |
$(top_srcdir)/shared/memory.h \ |
130 |
+ $(top_srcdir)/shared/cfgparser.c \ |
|
131 |
+ $(top_srcdir)/shared/cfgparser.h \ |
|
130 | 132 |
clamscan.c \ |
131 | 133 |
options.c \ |
132 | 134 |
options.h \ |
... | ... |
@@ -151,8 +153,8 @@ bin_PROGRAMS = clamscan$(EXEEXT) |
151 | 151 |
PROGRAMS = $(bin_PROGRAMS) |
152 | 152 |
|
153 | 153 |
am_clamscan_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) memory.$(OBJEXT) \ |
154 |
- clamscan.$(OBJEXT) options.$(OBJEXT) others.$(OBJEXT) \ |
|
155 |
- manager.$(OBJEXT) treewalk.$(OBJEXT) |
|
154 |
+ cfgparser.$(OBJEXT) clamscan.$(OBJEXT) options.$(OBJEXT) \ |
|
155 |
+ others.$(OBJEXT) manager.$(OBJEXT) treewalk.$(OBJEXT) |
|
156 | 156 |
clamscan_OBJECTS = $(am_clamscan_OBJECTS) |
157 | 157 |
clamscan_LDADD = $(LDADD) |
158 | 158 |
clamscan_DEPENDENCIES = |
... | ... |
@@ -162,10 +164,11 @@ CPPFLAGS = @CPPFLAGS@ |
162 | 162 |
LDFLAGS = @LDFLAGS@ |
163 | 163 |
depcomp = $(SHELL) $(top_srcdir)/depcomp |
164 | 164 |
am__depfiles_maybe = depfiles |
165 |
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/clamscan.Po ./$(DEPDIR)/getopt.Po \ |
|
166 |
-@AMDEP_TRUE@ ./$(DEPDIR)/manager.Po ./$(DEPDIR)/memory.Po \ |
|
167 |
-@AMDEP_TRUE@ ./$(DEPDIR)/options.Po ./$(DEPDIR)/others.Po \ |
|
168 |
-@AMDEP_TRUE@ ./$(DEPDIR)/output.Po ./$(DEPDIR)/treewalk.Po |
|
165 |
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cfgparser.Po ./$(DEPDIR)/clamscan.Po \ |
|
166 |
+@AMDEP_TRUE@ ./$(DEPDIR)/getopt.Po ./$(DEPDIR)/manager.Po \ |
|
167 |
+@AMDEP_TRUE@ ./$(DEPDIR)/memory.Po ./$(DEPDIR)/options.Po \ |
|
168 |
+@AMDEP_TRUE@ ./$(DEPDIR)/others.Po ./$(DEPDIR)/output.Po \ |
|
169 |
+@AMDEP_TRUE@ ./$(DEPDIR)/treewalk.Po |
|
169 | 170 |
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ |
170 | 171 |
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) |
171 | 172 |
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ |
... | ... |
@@ -217,6 +220,7 @@ clean-binPROGRAMS: |
217 | 217 |
output.$(OBJEXT): $(top_srcdir)/shared/output.c |
218 | 218 |
getopt.$(OBJEXT): $(top_srcdir)/shared/getopt.c |
219 | 219 |
memory.$(OBJEXT): $(top_srcdir)/shared/memory.c |
220 |
+cfgparser.$(OBJEXT): $(top_srcdir)/shared/cfgparser.c |
|
220 | 221 |
clamscan$(EXEEXT): $(clamscan_OBJECTS) $(clamscan_DEPENDENCIES) |
221 | 222 |
@rm -f clamscan$(EXEEXT) |
222 | 223 |
$(LINK) $(clamscan_LDFLAGS) $(clamscan_OBJECTS) $(clamscan_LDADD) $(LIBS) |
... | ... |
@@ -227,6 +231,7 @@ mostlyclean-compile: |
227 | 227 |
distclean-compile: |
228 | 228 |
-rm -f *.tab.c |
229 | 229 |
|
230 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@ |
|
230 | 231 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamscan.Po@am__quote@ |
231 | 232 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ |
232 | 233 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/manager.Po@am__quote@ |
... | ... |
@@ -310,6 +315,24 @@ memory.lo: $(top_srcdir)/shared/memory.c |
310 | 310 |
@AMDEP_TRUE@ depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@ |
311 | 311 |
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
312 | 312 |
$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c |
313 |
+ |
|
314 |
+cfgparser.o: $(top_srcdir)/shared/cfgparser.c |
|
315 |
+@AMDEP_TRUE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@ |
|
316 |
+@AMDEP_TRUE@ depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@ |
|
317 |
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
318 |
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c |
|
319 |
+ |
|
320 |
+cfgparser.obj: $(top_srcdir)/shared/cfgparser.c |
|
321 |
+@AMDEP_TRUE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@ |
|
322 |
+@AMDEP_TRUE@ depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@ |
|
323 |
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
324 |
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `cygpath -w $(top_srcdir)/shared/cfgparser.c` |
|
325 |
+ |
|
326 |
+cfgparser.lo: $(top_srcdir)/shared/cfgparser.c |
|
327 |
+@AMDEP_TRUE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.lo' libtool=yes @AMDEPBACKSLASH@ |
|
328 |
+@AMDEP_TRUE@ depfile='$(DEPDIR)/cfgparser.Plo' tmpdepfile='$(DEPDIR)/cfgparser.TPlo' @AMDEPBACKSLASH@ |
|
329 |
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
330 |
+ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.lo `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c |
|
313 | 331 |
CCDEPMODE = @CCDEPMODE@ |
314 | 332 |
|
315 | 333 |
mostlyclean-libtool: |
... | ... |
@@ -53,7 +53,6 @@ int clamscan(struct optstruct *opt) |
53 | 53 |
struct timezone tz; |
54 | 54 |
time_t starttime; |
55 | 55 |
|
56 |
- |
|
57 | 56 |
/* initialize some important variables */ |
58 | 57 |
|
59 | 58 |
if(optc(opt, 'v')) { |
... | ... |
@@ -197,7 +196,7 @@ void help(void) |
197 | 197 |
mprintf("\n"); |
198 | 198 |
mprintf(" --tempdir=DIRECTORY create temporary files in DIRECTORY\n"); |
199 | 199 |
mprintf(" --database=FILE/DIR -d FILE/DIR Load virus database from FILE or load\n"); |
200 |
- mprintf(" all .db and .db2 files from DIR\n"); |
|
200 |
+ mprintf(" all .cvd and .db[2] files from DIR\n"); |
|
201 | 201 |
mprintf(" --log=FILE -l FILE Save scan report to FILE\n"); |
202 | 202 |
mprintf(" --recursive -r Scan directories recursively\n"); |
203 | 203 |
mprintf(" --infected -i Print infected files only\n"); |
... | ... |
@@ -53,6 +53,7 @@ |
53 | 53 |
#include "strrcpy.h" |
54 | 54 |
#include "memory.h" |
55 | 55 |
#include "output.h" |
56 |
+#include "cfgparser.h" |
|
56 | 57 |
|
57 | 58 |
#ifdef C_LINUX |
58 | 59 |
dev_t procdev; |
... | ... |
@@ -67,7 +68,9 @@ int scanmanager(const struct optstruct *opt) |
67 | 67 |
struct passwd *user = NULL; |
68 | 68 |
struct stat sb; |
69 | 69 |
char *fullpath = NULL, cwd[200]; |
70 |
- |
|
70 |
+ struct cfgstruct *copt, *cpt; |
|
71 |
+ struct cl_cvd *d1, *d2; |
|
72 |
+ const char *dbdir; |
|
71 | 73 |
|
72 | 74 |
/* njh@bandsman.co.uk: BeOS */ |
73 | 75 |
#if !defined(C_CYGWIN) && !defined(C_BEOS) |
... | ... |
@@ -79,14 +82,12 @@ int scanmanager(const struct optstruct *opt) |
79 | 79 |
} |
80 | 80 |
#endif |
81 | 81 |
|
82 |
- |
|
83 | 82 |
if(optl(opt, "unzip") || optl(opt, "unrar") || optl(opt, "unace") || |
84 | 83 |
optl(opt, "arj") || optl(opt, "unzoo") || optl(opt, "jar") || |
85 | 84 |
optl(opt, "lha") || optl(opt, "tar") || optl(opt, "tgz") || |
86 | 85 |
optl(opt, "deb")) |
87 | 86 |
compression = 1; |
88 | 87 |
|
89 |
- |
|
90 | 88 |
/* now initialize the database */ |
91 | 89 |
|
92 | 90 |
if(optc(opt, 'd')) { |
... | ... |
@@ -110,10 +111,42 @@ int scanmanager(const struct optstruct *opt) |
110 | 110 |
} |
111 | 111 |
|
112 | 112 |
} else { |
113 |
- if((ret = cl_loaddbdir(cl_retdbdir(), &trie, &claminfo.signs))) { |
|
113 |
+ /* try to find fresh directory */ |
|
114 |
+ dbdir = cl_retdbdir(); |
|
115 |
+ if((copt = parsecfg(CONFDIR"/clamav.conf"))) { |
|
116 |
+ if((cpt = cfgopt(copt, "DatabaseDirectory")) || (cpt = cfgopt(copt, "DataDirectory"))) { |
|
117 |
+ if(strcmp(cl_retdbdir(), cpt->strarg)) { |
|
118 |
+ char *daily = (char *) mmalloc(strlen(cpt->strarg) + strlen(cl_retdbdir()) + 15); |
|
119 |
+ sprintf(daily, "%s/daily.cvd", cpt->strarg); |
|
120 |
+ if((d1 = cl_cvdhead(daily))) { |
|
121 |
+ sprintf(daily, "%s/daily.cvd", cl_retdbdir()); |
|
122 |
+ if((d2 = cl_cvdhead(daily))) { |
|
123 |
+ free(daily); |
|
124 |
+ if(d1->version > d2->version) |
|
125 |
+ dbdir = cpt->strarg; |
|
126 |
+ else |
|
127 |
+ dbdir = cl_retdbdir(); |
|
128 |
+ cl_cvdfree(d2); |
|
129 |
+ } else { |
|
130 |
+ free(daily); |
|
131 |
+ dbdir = cpt->strarg; |
|
132 |
+ } |
|
133 |
+ cl_cvdfree(d1); |
|
134 |
+ } else { |
|
135 |
+ free(daily); |
|
136 |
+ dbdir = cl_retdbdir(); |
|
137 |
+ } |
|
138 |
+ } |
|
139 |
+ } |
|
140 |
+ } |
|
141 |
+ |
|
142 |
+ if((ret = cl_loaddbdir(dbdir, &trie, &claminfo.signs))) { |
|
114 | 143 |
mprintf("@%s\n", cl_strerror(ret)); |
115 | 144 |
return 50; |
116 | 145 |
} |
146 |
+ |
|
147 |
+ if(copt) |
|
148 |
+ freecfg(copt); |
|
117 | 149 |
} |
118 | 150 |
|
119 | 151 |
|
... | ... |
@@ -4,8 +4,8 @@ |
4 | 4 |
## This file may be optionally merged with clamav.conf. |
5 | 5 |
## |
6 | 6 |
|
7 |
- |
|
8 |
-# You can change the default database directory here. |
|
7 |
+# It should match clamav.conf's directive ! (in most cases you shouldn't |
|
8 |
+# change it) |
|
9 | 9 |
#DatabaseDirectory /var/lib/clamav |
10 | 10 |
|
11 | 11 |
# Path to the log file (make sure it has proper permissions) |
... | ... |
@@ -126,6 +126,8 @@ sigtool_SOURCES = \ |
126 | 126 |
$(top_srcdir)/shared/getopt.h \ |
127 | 127 |
$(top_srcdir)/shared/memory.c \ |
128 | 128 |
$(top_srcdir)/shared/memory.h \ |
129 |
+ $(top_srcdir)/shared/cfgparser.c \ |
|
130 |
+ $(top_srcdir)/shared/cfgparser.h \ |
|
129 | 131 |
options.c \ |
130 | 132 |
options.h \ |
131 | 133 |
sigtool.c |
... | ... |
@@ -144,7 +146,7 @@ bin_PROGRAMS = sigtool$(EXEEXT) |
144 | 144 |
PROGRAMS = $(bin_PROGRAMS) |
145 | 145 |
|
146 | 146 |
am_sigtool_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) memory.$(OBJEXT) \ |
147 |
- options.$(OBJEXT) sigtool.$(OBJEXT) |
|
147 |
+ cfgparser.$(OBJEXT) options.$(OBJEXT) sigtool.$(OBJEXT) |
|
148 | 148 |
sigtool_OBJECTS = $(am_sigtool_OBJECTS) |
149 | 149 |
sigtool_DEPENDENCIES = $(top_builddir)/clamscan/others.o |
150 | 150 |
sigtool_LDFLAGS = |
... | ... |
@@ -153,9 +155,9 @@ CPPFLAGS = @CPPFLAGS@ |
153 | 153 |
LDFLAGS = @LDFLAGS@ |
154 | 154 |
depcomp = $(SHELL) $(top_srcdir)/depcomp |
155 | 155 |
am__depfiles_maybe = depfiles |
156 |
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/getopt.Po ./$(DEPDIR)/memory.Po \ |
|
157 |
-@AMDEP_TRUE@ ./$(DEPDIR)/options.Po ./$(DEPDIR)/output.Po \ |
|
158 |
-@AMDEP_TRUE@ ./$(DEPDIR)/sigtool.Po |
|
156 |
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cfgparser.Po ./$(DEPDIR)/getopt.Po \ |
|
157 |
+@AMDEP_TRUE@ ./$(DEPDIR)/memory.Po ./$(DEPDIR)/options.Po \ |
|
158 |
+@AMDEP_TRUE@ ./$(DEPDIR)/output.Po ./$(DEPDIR)/sigtool.Po |
|
159 | 159 |
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ |
160 | 160 |
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) |
161 | 161 |
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ |
... | ... |
@@ -207,6 +209,7 @@ clean-binPROGRAMS: |
207 | 207 |
output.$(OBJEXT): $(top_srcdir)/shared/output.c |
208 | 208 |
getopt.$(OBJEXT): $(top_srcdir)/shared/getopt.c |
209 | 209 |
memory.$(OBJEXT): $(top_srcdir)/shared/memory.c |
210 |
+cfgparser.$(OBJEXT): $(top_srcdir)/shared/cfgparser.c |
|
210 | 211 |
sigtool$(EXEEXT): $(sigtool_OBJECTS) $(sigtool_DEPENDENCIES) |
211 | 212 |
@rm -f sigtool$(EXEEXT) |
212 | 213 |
$(LINK) $(sigtool_LDFLAGS) $(sigtool_OBJECTS) $(sigtool_LDADD) $(LIBS) |
... | ... |
@@ -217,6 +220,7 @@ mostlyclean-compile: |
217 | 217 |
distclean-compile: |
218 | 218 |
-rm -f *.tab.c |
219 | 219 |
|
220 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@ |
|
220 | 221 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ |
221 | 222 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@ |
222 | 223 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@ |
... | ... |
@@ -297,6 +301,24 @@ memory.lo: $(top_srcdir)/shared/memory.c |
297 | 297 |
@AMDEP_TRUE@ depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@ |
298 | 298 |
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
299 | 299 |
$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c |
300 |
+ |
|
301 |
+cfgparser.o: $(top_srcdir)/shared/cfgparser.c |
|
302 |
+@AMDEP_TRUE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@ |
|
303 |
+@AMDEP_TRUE@ depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@ |
|
304 |
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
305 |
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c |
|
306 |
+ |
|
307 |
+cfgparser.obj: $(top_srcdir)/shared/cfgparser.c |
|
308 |
+@AMDEP_TRUE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@ |
|
309 |
+@AMDEP_TRUE@ depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@ |
|
310 |
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
311 |
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `cygpath -w $(top_srcdir)/shared/cfgparser.c` |
|
312 |
+ |
|
313 |
+cfgparser.lo: $(top_srcdir)/shared/cfgparser.c |
|
314 |
+@AMDEP_TRUE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.lo' libtool=yes @AMDEPBACKSLASH@ |
|
315 |
+@AMDEP_TRUE@ depfile='$(DEPDIR)/cfgparser.Plo' tmpdepfile='$(DEPDIR)/cfgparser.TPlo' @AMDEPBACKSLASH@ |
|
316 |
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
317 |
+ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.lo `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c |
|
300 | 318 |
CCDEPMODE = @CCDEPMODE@ |
301 | 319 |
|
302 | 320 |
mostlyclean-libtool: |
... | ... |
@@ -47,6 +47,7 @@ |
47 | 47 |
#include "str.h" |
48 | 48 |
#include "memory.h" |
49 | 49 |
#include "output.h" |
50 |
+#include "cfgparser.h" |
|
50 | 51 |
|
51 | 52 |
#define LINE 1024 |
52 | 53 |
|
... | ... |
@@ -477,6 +478,44 @@ int countlines(const char *filename) |
477 | 477 |
return lines; |
478 | 478 |
} |
479 | 479 |
|
480 |
+const char *getdbdir(void) |
|
481 |
+{ |
|
482 |
+ struct cfgstruct *copt, *cpt; |
|
483 |
+ struct cl_cvd *d1, *d2; |
|
484 |
+ const char *dbdir; |
|
485 |
+ |
|
486 |
+ |
|
487 |
+ dbdir = cl_retdbdir(); |
|
488 |
+ if((copt = parsecfg(CONFDIR"/clamav.conf"))) { |
|
489 |
+ if((cpt = cfgopt(copt, "DatabaseDirectory")) || (cpt = cfgopt(copt, "DataDirectory"))) { |
|
490 |
+ if(strcmp(cl_retdbdir(), cpt->strarg)) { |
|
491 |
+ char *daily = (char *) mmalloc(strlen(cpt->strarg) + strlen(cl_retdbdir()) + 15); |
|
492 |
+ sprintf(daily, "%s/daily.cvd", cpt->strarg); |
|
493 |
+ if((d1 = cl_cvdhead(daily))) { |
|
494 |
+ sprintf(daily, "%s/daily.cvd", cl_retdbdir()); |
|
495 |
+ if((d2 = cl_cvdhead(daily))) { |
|
496 |
+ free(daily); |
|
497 |
+ if(d1->version > d2->version) |
|
498 |
+ dbdir = cpt->strarg; |
|
499 |
+ else |
|
500 |
+ dbdir = cl_retdbdir(); |
|
501 |
+ cl_cvdfree(d2); |
|
502 |
+ } else { |
|
503 |
+ free(daily); |
|
504 |
+ dbdir = cpt->strarg; |
|
505 |
+ } |
|
506 |
+ cl_cvdfree(d1); |
|
507 |
+ } else { |
|
508 |
+ free(daily); |
|
509 |
+ dbdir = cl_retdbdir(); |
|
510 |
+ } |
|
511 |
+ } |
|
512 |
+ } |
|
513 |
+ } |
|
514 |
+ |
|
515 |
+ return dbdir; |
|
516 |
+} |
|
517 |
+ |
|
480 | 518 |
int build(struct optstruct *opt) |
481 | 519 |
{ |
482 | 520 |
int ret, no = 0, realno = 0, bytes, itmp; |
... | ... |
@@ -575,7 +614,7 @@ int build(struct optstruct *opt) |
575 | 575 |
|
576 | 576 |
|
577 | 577 |
/* try to read cvd header of old database */ |
578 |
- sprintf(buffer, "%s/%s", cl_retdbdir(), getargc(opt, 'b')); |
|
578 |
+ sprintf(buffer, "%s/%s", getdbdir(), getargc(opt, 'b')); |
|
579 | 579 |
if((oldcvd = cl_cvdhead(buffer)) == NULL) |
580 | 580 |
mprintf("WARNING: CAN'T READ CVD HEADER OF CURRENT DATABASE %s\n", buffer); |
581 | 581 |
|
... | ... |
@@ -785,7 +824,7 @@ int unpack(struct optstruct *opt) |
785 | 785 |
|
786 | 786 |
if(optl(opt, "unpack-current")) { |
787 | 787 |
name = mcalloc(300, sizeof(char)); /* FIXME */ |
788 |
- sprintf(name, "%s/%s", cl_retdbdir(), getargl(opt, "unpack-current")); |
|
788 |
+ sprintf(name, "%s/%s", getdbdir(), getargl(opt, "unpack-current")); |
|
789 | 789 |
} else |
790 | 790 |
name = getargc(opt, 'u'); |
791 | 791 |
|
... | ... |
@@ -979,7 +1018,7 @@ void listsigs(struct optstruct *opt) |
979 | 979 |
if((name = getargc(opt, 'l'))) |
980 | 980 |
ret = listdb(name); |
981 | 981 |
else |
982 |
- ret = listdir(cl_retdbdir()); |
|
982 |
+ ret = listdir(getdbdir()); |
|
983 | 983 |
|
984 | 984 |
ret ? exit(1) : exit(0); |
985 | 985 |
} |