~ubuntu-branches/ubuntu/jaunty/clamav/jaunty-backports

« back to all changes in this revision

Viewing changes to clamconf/clamconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-10-02 15:36:00 UTC
  • mfrom: (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20101002153600-2tx3vki1u55cdrjy
Tags: 0.96.3+dfsg-2ubuntu0.10.04.1
Microversion update to 0.96.3 for Lucid (LP: #653738)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <unistd.h>
28
28
#endif
29
29
#include <time.h>
 
30
#ifdef HAVE_UNAME_SYSCALL
 
31
#include <sys/utsname.h>
 
32
#endif
 
33
#include <zlib.h>
 
34
#include <sys/types.h>
 
35
#include <sys/stat.h>
 
36
#include <dirent.h>
30
37
 
31
38
#include "shared/optparser.h"
32
39
#include "shared/misc.h"
34
41
#include "libclamav/str.h"
35
42
#include "libclamav/clamav.h"
36
43
#include "libclamav/others.h"
 
44
#include "libclamav/readdb.h"
37
45
#include "libclamav/bytecode.h"
 
46
#include "libclamav/bytecode_detect.h"
 
47
#include "target.h"
38
48
 
39
49
#ifndef _WIN32
40
50
extern const struct clam_option *clam_options;
52
62
    { NULL,                 0               }
53
63
};
54
64
 
55
 
static const char *dbnames[] = { "main.cvd", "main.cld", "daily.cvd",
56
 
                                 "daily.cld", "safebrowsing.cvd",
57
 
                                 "safebrowsing.cld", NULL };
58
 
 
59
65
static void printopts(struct optstruct *opts, int nondef)
60
66
{
61
67
        const struct optstruct *opt;
205
211
    return;
206
212
}
207
213
 
 
214
static void print_platform(struct cli_environment *env)
 
215
{
 
216
    printf("\nPlatform information\n--------------------\n");
 
217
    printf("uname: %s %s %s %s\n",
 
218
           env->sysname, env->release, env->version, env->machine);
 
219
 
 
220
    printf("OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE"\n");
 
221
 
 
222
#ifdef C_LINUX
 
223
    if (!access("/usr/bin/lsb_release", X_OK)) {
 
224
        fputs("Full OS version: ", stdout);
 
225
        fflush(stdout);
 
226
        if (system("/usr/bin/lsb_release -d -s") == -1) {
 
227
           perror("failed to determine");
 
228
        }
 
229
    }
 
230
#else
 
231
    /* e.g. Solaris */
 
232
    if (!access("/etc/release", R_OK)) {
 
233
        char buf[1024];
 
234
        FILE *f = fopen("/etc/release", "r");
 
235
        fgets(buf, sizeof(buf), f);
 
236
        printf("Full OS version: %s", buf);
 
237
    }
 
238
#endif
 
239
 
 
240
#ifdef ZLIB_VERNUM
 
241
    printf("zlib version: %s (%s), compile flags: %02lx\n",
 
242
           ZLIB_VERSION, zlibVersion(), zlibCompileFlags());
 
243
#else
 
244
    /* old zlib w/o zlibCompileFlags() */
 
245
    printf("zlib version: %s (%s)\n",
 
246
           ZLIB_VERSION, zlibVersion());
 
247
#endif
 
248
    if (env->triple[0])
 
249
    printf("Triple: %s\n", env->triple);
 
250
    if (env->cpu[0])
 
251
        printf("CPU: %s, %s\n", env->cpu, env->big_endian ? "Big-endian" : "Little-endian");
 
252
    printf("platform id: 0x%08x%08x%08x\n",
 
253
           env->platform_id_a,
 
254
           env->platform_id_b,
 
255
           env->platform_id_c);
 
256
}
 
257
 
 
258
static void print_build(struct cli_environment *env)
 
259
{
 
260
    const char *name;
 
261
    const char *version = NULL;
 
262
    printf("\nBuild information\n-----------------\n");
 
263
    /* Try to print information about some commonly used compilers */
 
264
#ifdef __GNUC__
 
265
        version = __VERSION__;
 
266
#endif
 
267
    switch (env->compiler) {
 
268
        case compiler_gnuc:
 
269
            name = "GNU C";
 
270
            break;
 
271
        case compiler_clang:
 
272
            name = "Clang";
 
273
            break;
 
274
        case compiler_llvm:
 
275
            name = "LLVM-GCC";
 
276
            break;
 
277
        case compiler_intel:
 
278
            name = "Intel Compiler";
 
279
            break;
 
280
        case compiler_msc:
 
281
            name = "Microsoft Visual C++";
 
282
            break;
 
283
        case compiler_sun:
 
284
            name = "Sun studio";
 
285
            break;
 
286
        default:
 
287
            name = NULL;
 
288
    }
 
289
    if (name)
 
290
        printf("%s: %s%s(%u.%u.%u)\n", name,
 
291
               version ? version : "",
 
292
               version ? " " : "",
 
293
               env->c_version >> 16,
 
294
                   (env->c_version >> 8)&0xff,
 
295
                   (env->c_version)&0xff);
 
296
    cli_printcxxver();
 
297
#if defined(BUILD_CPPFLAGS) && defined(BUILD_CFLAGS) && defined(BUILD_CXXFLAGS) && defined(BUILD_LDFLAGS) && defined(BUILD_CONFIGURE_FLAGS)
 
298
    printf("CPPFLAGS: %s\nCFLAGS: %s\nCXXFLAGS: %s\nLDFLAGS: %s\nConfigure: %s\n",
 
299
           BUILD_CPPFLAGS, BUILD_CFLAGS, BUILD_CXXFLAGS, BUILD_LDFLAGS,
 
300
           BUILD_CONFIGURE_FLAGS);
 
301
#endif
 
302
    printf("sizeof(void*) = %d\n", env->sizeof_ptr);
 
303
    printf("Engine flevel: %d, dconf: %d\n",
 
304
           env->functionality_level,
 
305
           env->dconf_level);
 
306
}
 
307
 
 
308
static void print_dbs(const char *dir)
 
309
{
 
310
        DIR *dd;
 
311
        struct dirent *dent;
 
312
        char *dbfile;
 
313
        unsigned int flevel = cl_retflevel(), cnt, sigs = 0;
 
314
        struct cl_cvd *cvd;
 
315
 
 
316
    if((dd = opendir(dir)) == NULL) {
 
317
        printf("print_dbs: Can't open directory %s\n", dir);
 
318
        return;
 
319
    }
 
320
 
 
321
    while((dent = readdir(dd))) {
 
322
        if(dent->d_ino) {
 
323
            if(CLI_DBEXT(dent->d_name)) {
 
324
                dbfile = (char *) malloc(strlen(dent->d_name) + strlen(dir) + 2);
 
325
                if(!dbfile) {
 
326
                    printf("print_dbs: Can't allocate memory for dbfile\n");
 
327
                    return;
 
328
                }
 
329
                sprintf(dbfile, "%s"PATHSEP"%s", dir, dent->d_name);
 
330
                if(cli_strbcasestr(dbfile, ".cvd") || cli_strbcasestr(dbfile, ".cld")) {
 
331
                    cvd = cl_cvdhead(dbfile);
 
332
                    if(!cvd) {
 
333
                        printf("%s: Can't get information about the database\n", dbfile);
 
334
                    } else {
 
335
                        const time_t t = cvd->stime;
 
336
                        printf("%s: version %u, sigs: %u, built on %s", dent->d_name, cvd->version, cvd->sigs, ctime(&t));
 
337
                        sigs += cvd->sigs;
 
338
                        if(cvd->fl > flevel)
 
339
                            printf("%s: WARNING: This database requires f-level %u (current f-level: %u)\n", dent->d_name, cvd->fl, flevel);
 
340
                        cl_cvdfree(cvd);
 
341
                    }
 
342
                } else if(cli_strbcasestr(dbfile, ".cbc")) {
 
343
                    printf("[3rd Party] %s: bytecode\n", dent->d_name);
 
344
                    sigs++;
 
345
                } else {
 
346
                    cnt = countlines(dbfile);
 
347
                    printf("[3rd Party] %s: %u sig%c\n", dent->d_name, cnt, cnt > 1 ? 's' : ' ');
 
348
                    sigs += cnt;
 
349
                }
 
350
                free(dbfile);
 
351
            }
 
352
        }
 
353
    }
 
354
    closedir(dd);
 
355
    printf("Total number of signatures: %u\n", sigs);
 
356
}
 
357
 
208
358
int main(int argc, char **argv)
209
359
{
210
360
        const char *dir;
211
 
        char path[512], dbdir[512], *pt;
 
361
        char path[512], dbdir[512], clamd_dbdir[512], *pt;
212
362
        struct optstruct *opts, *toolopts;
213
363
        const struct optstruct *opt;
214
364
        unsigned int i, j;
215
 
        struct cl_cvd *cvd;
216
 
        unsigned int flevel;
 
365
        struct cli_environment env;
217
366
 
218
367
 
219
368
    opts = optparse(NULL, argc, argv, 1, OPT_CLAMCONF, 0, NULL);
262
411
            opt = optget(toolopts, "DatabaseDirectory");
263
412
            strncpy(dbdir, opt->strarg, sizeof(dbdir));
264
413
            dbdir[sizeof(dbdir) - 1] = 0;
 
414
        } else if(cfgfile[i].tool == OPT_CLAMD) {
 
415
            opt = optget(toolopts, "DatabaseDirectory");
 
416
            strncpy(clamd_dbdir, opt->strarg, sizeof(clamd_dbdir));
 
417
            clamd_dbdir[sizeof(clamd_dbdir) - 1] = 0;
265
418
        }
266
419
        optfree(toolopts);
267
420
    }
310
463
        }
311
464
        dbdir[sizeof(dbdir) - 1] = 0;
312
465
    }
 
466
 
 
467
    printf("\nDatabase information\n--------------------\n");
313
468
    printf("Database directory: %s\n", dbdir);
314
 
    flevel = cl_retflevel();
315
 
    for(i = 0; dbnames[i]; i++) {
316
 
        snprintf(path, sizeof(path), "%s"PATHSEP"%s", dbdir, dbnames[i]);
317
 
        path[511] = 0;
318
 
        if(!access(path, R_OK)) {
319
 
            cvd = cl_cvdhead(path);
320
 
            if(!cvd) {
321
 
                printf("%s: Can't get information about the database\n", dbnames[i]);
322
 
            } else {
323
 
                const time_t t = cvd->stime;
324
 
                printf("%s: version %u, sigs: %u, built on %s", dbnames[i], cvd->version, cvd->sigs, ctime(&t));
325
 
                if(cvd->fl > flevel)
326
 
                    printf("%s: WARNING: This database requires f-level %u (current f-level: %u)\n", dbnames[i], cvd->fl, flevel);
327
 
                cl_cvdfree(cvd);
328
 
            }
329
 
        }
330
 
    }
 
469
    if(strcmp(dbdir, clamd_dbdir))
 
470
        printf("WARNING: freshclam.conf and clamd.conf point to different database directories\n");
 
471
    print_dbs(dbdir);
 
472
 
 
473
    cli_detect_environment(&env);
 
474
    print_platform(&env);
 
475
    print_build(&env);
331
476
    return 0;
332
477
}