Browse code

print version details for engine and databases

git-svn: trunk@3279

Tomasz Kojm authored on 2007/10/09 01:01:15
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Oct  8 17:02:30 CEST 2007 (tk)
2
+----------------------------------
3
+  * clamconf: print version details for engine and databases
4
+
1 5
 Mon Oct  8 15:44:59 CEST 2007 (tk)
2 6
 ----------------------------------
3 7
   * clamdscan, freshclam: fix some warnings
... ...
@@ -30,6 +30,10 @@
30 30
 #ifdef HAVE_UNISTD_H
31 31
 #include <unistd.h>
32 32
 #endif
33
+#include <time.h>
34
+
35
+#include "shared/misc.h"
36
+#include "libclamav/clamav.h"
33 37
 
34 38
 #include "cfgparser.h"
35 39
 #define _GNU_SOURCE
... ...
@@ -98,7 +102,7 @@ static void printcfg(const char *cfgfile, int nondef)
98 98
 
99 99
     if((cfgowner & OPT_CLAMD) && (cfgowner & OPT_FRESHCLAM)) { /* merged cfg */
100 100
 	printf("%s: clamd and freshclam directives\n", cfgfile);
101
-	printf("-----------------\n");
101
+	printf("------------------------------\n");
102 102
 
103 103
 	printf("\n[common]\n");
104 104
 	for(i = 0; ; i++) {
... ...
@@ -137,7 +141,7 @@ static void printcfg(const char *cfgfile, int nondef)
137 137
 
138 138
 	if(cfgowner & OPT_CLAMD) {
139 139
 	    printf("%s: clamd directives\n", cfgfile);
140
-	    printf("-----------------\n");
140
+	    printf("------------------------------\n");
141 141
 
142 142
 	    for(i = 0; ; i++) {
143 143
 		opt = &cfg_options[i];
... ...
@@ -150,7 +154,7 @@ static void printcfg(const char *cfgfile, int nondef)
150 150
 	    }
151 151
 	} else {
152 152
 	    printf("%s: freshclam directives\n", cfgfile);
153
-	    printf("-----------------\n");
153
+	    printf("------------------------------\n");
154 154
 
155 155
 	    for(i = 0; ; i++) {
156 156
 		opt = &cfg_options[i];
... ...
@@ -163,8 +167,33 @@ static void printcfg(const char *cfgfile, int nondef)
163 163
 	    }
164 164
 	}
165 165
     }
166
-
167 166
     freecfg(cfg);
167
+
168
+}
169
+
170
+static void printdb(const char *dir, const char *db)
171
+{
172
+	struct cl_cvd *cvd;
173
+	char path[256];
174
+	unsigned int inc = 0;
175
+	time_t t;
176
+
177
+
178
+    snprintf(path, sizeof(path), "%s/%s.cvd", dir, db);
179
+    if(access(path, R_OK) == -1) {
180
+	snprintf(path, sizeof(path), "%s/%s.inc/%s.info", dir, db, db);
181
+	inc = 1;
182
+	if(access(path, R_OK) == -1) {
183
+	    printf("%s db: Not found\n", db);
184
+	    return;
185
+	}
186
+    }
187
+
188
+    if((cvd = cl_cvdhead(path))) {
189
+	t = (time_t) cvd->stime;
190
+	printf("%s db: Format: %s, Version: %u, Build time: %s", db, inc ? ".inc" : ".cvd", cvd->version, ctime(&t));
191
+	cl_cvdfree(cvd);
192
+    }
168 193
 }
169 194
 
170 195
 static void help(void)
... ...
@@ -191,7 +220,7 @@ int main(int argc, char **argv)
191 191
 	    {"non-default", 0, 0, 'n'},
192 192
 	    {0, 0, 0, 0}
193 193
     	};
194
-	char *confdir = strdup(CONFDIR);
194
+	char *confdir = strdup(CONFDIR), *dbdir;
195 195
 	int found = 0;
196 196
 
197 197
 
... ...
@@ -245,7 +274,31 @@ int main(int argc, char **argv)
245 245
 	free(confdir);
246 246
 	return 1;
247 247
     }
248
-
249 248
     free(confdir);
249
+
250
+    printf("\nEngine and signature databases\n");
251
+    printf("------------------------------\n");
252
+
253
+#ifdef CL_EXPERIMENTAL
254
+    printf("Engine version: "VERSION" (with experimental code)\n");
255
+#else
256
+    printf("Engine version: "VERSION"\n");
257
+#endif
258
+
259
+    if(strcmp(VERSION, cl_retver()))
260
+	printf("WARNING: Version mismatch: clamconf: "VERSION", libclamav: %s\n", cl_retver());
261
+
262
+    printf("Database directory: ");
263
+    dbdir = freshdbdir();
264
+    if(!dbdir) {
265
+	printf("Failed to retrieve\n");
266
+	return 1;
267
+    } else printf("%s\n", dbdir);
268
+
269
+    if(dbdir) {
270
+	printdb(dbdir, "main");
271
+	printdb(dbdir, "daily");
272
+	free(dbdir);
273
+    }
250 274
     return 0;
251 275
 }