Browse code

respect custom dbdir settings in print_version() (bb#699)

git-svn: trunk@3521

Tomasz Kojm authored on 2008/01/22 19:42:30
Showing 7 changed files
... ...
@@ -1,3 +1,8 @@
1
+Tue Jan 22 11:20:12 CET 2008 (tk)
2
+---------------------------------
3
+  * shared/misc.c, clamd, clamscan, freshclam: respect custom dbdir settings
4
+					       in print_version() (bb#699)
5
+
1 6
 Tue Jan 22 09:16:24 CET 2008 (tk)
2 7
 ---------------------------------
3 8
   * clamd, clamdscan: drop support for direct fd passing (not maintained)
... ...
@@ -121,12 +121,6 @@ int main(int argc, char **argv)
121 121
 	return 1;
122 122
     }
123 123
 
124
-    if(opt_check(opt, "version")) {
125
-	print_version();
126
-	opt_free(opt);
127
-	return 0;
128
-    }
129
-
130 124
     if(opt_check(opt, "help")) {
131 125
     	help();
132 126
 	opt_free(opt);
... ...
@@ -156,6 +150,14 @@ int main(int argc, char **argv)
156 156
 	opt_free(opt);
157 157
 	return 1;
158 158
     }
159
+
160
+    if(opt_check(opt, "version")) {
161
+	print_version(cfgopt(copt, "DatabaseDirectory")->strarg);
162
+	opt_free(opt);
163
+	freecfg(copt);
164
+	return 0;
165
+    }
166
+
159 167
     opt_free(opt);
160 168
 
161 169
     umask(0);
... ...
@@ -104,8 +104,8 @@ int main(int argc, char **argv)
104 104
     }
105 105
 
106 106
     if(opt_check(opt, "version")) {
107
+	print_version(opt_arg(opt, "database"));
107 108
 	opt_free(opt);
108
-	print_version();
109 109
 	return 0;
110 110
     }
111 111
 
... ...
@@ -247,12 +247,6 @@ int main(int argc, char **argv)
247 247
 	return 0;
248 248
     }
249 249
 
250
-    if(opt_check(opt, "version")) {
251
-	print_version();
252
-	opt_free(opt);
253
-	return 0;
254
-    }
255
-
256 250
     /* parse the config file */
257 251
     if((cfgfile = opt_arg(opt, "config-file"))) {
258 252
 	copt = getcfg(cfgfile, 1);
... ...
@@ -268,6 +262,18 @@ int main(int argc, char **argv)
268 268
 	return 56;
269 269
     }
270 270
 
271
+    if(opt_check(opt, "datadir"))
272
+	newdir = opt_arg(opt, "datadir");
273
+    else
274
+	newdir = cfgopt(copt, "DatabaseDirectory")->strarg;
275
+
276
+    if(opt_check(opt, "version")) {
277
+	print_version(newdir);
278
+	opt_free(opt);
279
+	freecfg(copt);
280
+	return 0;
281
+    }
282
+
271 283
 #ifdef C_WINDOWS
272 284
     if(!pthread_win32_process_attach_np()) {
273 285
 	mprintf("!Can't start the win32 pthreads layer\n");
... ...
@@ -406,11 +412,6 @@ int main(int argc, char **argv)
406 406
 #endif
407 407
 
408 408
     /* change the current working directory */
409
-    if(opt_check(opt, "datadir"))
410
-	newdir = opt_arg(opt, "datadir");
411
-    else
412
-	newdir = cfgopt(copt, "DatabaseDirectory")->strarg;
413
-
414 409
     if(chdir(newdir)) {
415 410
 	logg("Can't change dir to %s\n", newdir);
416 411
 	opt_free(opt);
... ...
@@ -105,22 +105,35 @@ char *freshdbdir(void)
105 105
     return retdir;
106 106
 }
107 107
 
108
-void print_version(void)
108
+void print_version(const char *dbdir)
109 109
 {
110
-	char *dbdir, *path;
110
+	char *fdbdir, *path;
111
+	const char *pt;
111 112
 	struct cl_cvd *daily;
112 113
 
113 114
 
114
-    dbdir = freshdbdir();
115
-    if(!(path = malloc(strlen(dbdir) + 30))) {
116
-	free(dbdir);
115
+    if(dbdir)
116
+	pt = dbdir;
117
+    else
118
+	pt = fdbdir = freshdbdir();
119
+
120
+    if(!pt) {
121
+	printf("ClamAV "VERSION_EXP"\n");
122
+	return;
123
+    }
124
+
125
+    if(!(path = malloc(strlen(pt) + 11))) {
126
+	if(!dbdir)
127
+	    free(fdbdir);
117 128
 	return;
118 129
     }
119 130
 
120
-    sprintf(path, "%s/daily.cvd", dbdir);
131
+    sprintf(path, "%s/daily.cvd", pt);
121 132
     if(access(path, R_OK))
122
-	sprintf(path, "%s/daily.cld", dbdir);
123
-    free(dbdir);
133
+	sprintf(path, "%s/daily.cld", pt);
134
+
135
+    if(!dbdir)
136
+	free(fdbdir);
124 137
 
125 138
     if(!access(path, R_OK) && (daily = cl_cvdhead(path))) {
126 139
 	    time_t t = (time_t) daily->stime;
... ...
@@ -33,7 +33,7 @@
33 33
 #include "cfgparser.h"
34 34
 
35 35
 char *freshdbdir(void);
36
-void print_version(void);
36
+void print_version(const char *dbdir);
37 37
 int filecopy(const char *src, const char *dest);
38 38
 int isnumb(const char *str);
39 39
 int dircopy(const char *src, const char *dest);
... ...
@@ -1787,7 +1787,7 @@ int main(int argc, char **argv)
1787 1787
 	cl_debug();
1788 1788
 
1789 1789
     if(opt_check(opt, "version")) {
1790
-	print_version();
1790
+	print_version(NULL);
1791 1791
 	opt_free(opt);
1792 1792
 	return 0;
1793 1793
     }