~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to .pc/0010-Call-cl_initialize_crypto-in-cl_init.patch/clamconf/clamconf.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2009-2013 Sourcefire, Inc.
 
3
 *  Author: Tomasz Kojm <tkojm@clamav.net>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License version 2 as
 
7
 *  published by the Free Software Foundation.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
17
 *  MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#if HAVE_CONFIG_H
 
21
#include "clamav-config.h"
 
22
#endif
 
23
 
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#ifdef HAVE_UNISTD_H
 
27
#include <unistd.h>
 
28
#endif
 
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>
 
37
 
 
38
#include <openssl/ssl.h>
 
39
#include <openssl/err.h>
 
40
#include "libclamav/crypto.h"
 
41
 
 
42
#include "shared/optparser.h"
 
43
#include "shared/misc.h"
 
44
 
 
45
#include "libclamav/str.h"
 
46
#include "libclamav/clamav.h"
 
47
#include "libclamav/others.h"
 
48
#include "libclamav/readdb.h"
 
49
#include "libclamav/bytecode.h"
 
50
#include "libclamav/bytecode_detect.h"
 
51
#include "target.h"
 
52
#include "fpu.h"
 
53
 
 
54
#ifndef _WIN32
 
55
extern const struct clam_option *clam_options;
 
56
#else
 
57
__declspec(dllimport) extern const struct clam_option *clam_options;
 
58
#endif
 
59
 
 
60
static struct _cfgfile {
 
61
    const char *name;
 
62
    int tool;
 
63
} cfgfile[] = {
 
64
    { "clamd.conf",         OPT_CLAMD       },
 
65
    { "freshclam.conf",     OPT_FRESHCLAM   },
 
66
    { "clamav-milter.conf", OPT_MILTER      },
 
67
    { NULL,                 0               }
 
68
};
 
69
 
 
70
static void printopts(struct optstruct *opts, int nondef)
 
71
{
 
72
        const struct optstruct *opt;
 
73
 
 
74
    while(opts) {
 
75
        if(!opts->name) {
 
76
            opts = opts->next;
 
77
            continue;
 
78
        }
 
79
        if(clam_options[opts->idx].owner & OPT_DEPRECATED) {
 
80
            if(opts->active)
 
81
                printf("*** %s is DEPRECATED ***\n", opts->name);
 
82
            opts = opts->next;
 
83
            continue;
 
84
        }
 
85
        if(nondef && (opts->numarg == clam_options[opts->idx].numarg) && ((opts->strarg == clam_options[opts->idx].strarg) || (opts->strarg && clam_options[opts->idx].strarg && !strcmp(opts->strarg, clam_options[opts->idx].strarg)))) {
 
86
            opts = opts->next;
 
87
            continue;
 
88
        }
 
89
        if(!opts->enabled) 
 
90
            printf("%s disabled\n", opts->name);
 
91
        else switch(clam_options[opts->idx].argtype) {
 
92
            case TYPE_STRING:
 
93
                printf("%s = \"%s\"", opts->name, opts->strarg);
 
94
                opt = opts;
 
95
                while((opt = opt->nextarg))
 
96
                    printf(", \"%s\"", opt->strarg);
 
97
                printf("\n");
 
98
                break;
 
99
 
 
100
            case TYPE_NUMBER:
 
101
            case TYPE_SIZE:
 
102
                printf("%s = \"%lld\"", opts->name, opts->numarg);
 
103
                opt = opts;
 
104
                while((opt = opt->nextarg))
 
105
                    printf(", \"%lld\"", opt->numarg);
 
106
                printf("\n");
 
107
                break;
 
108
 
 
109
            case TYPE_BOOL:
 
110
                printf("%s = \"yes\"\n", opts->name);
 
111
                break;
 
112
 
 
113
            default:
 
114
                printf("!!! %s: UNKNOWN INTERNAL TYPE !!!\n", opts->name);
 
115
        }
 
116
        opts = opts->next;
 
117
    }
 
118
}
 
119
 
 
120
static int printconf(const char *name)
 
121
{
 
122
        int i, j, tool = 0, tokens_count;
 
123
        char buffer[1025];
 
124
        const char *tokens[128];
 
125
        const struct clam_option *cpt;
 
126
 
 
127
    for(i = 0; cfgfile[i].name; i++) {
 
128
        if(!strcmp(name, cfgfile[i].name)) {
 
129
            tool = cfgfile[i].tool;
 
130
            break;
 
131
        }
 
132
    }
 
133
    if(!tool) {
 
134
        printf("ERROR: Unknown config file\nAvailable options:");
 
135
        for(i = 0; cfgfile[i].name; i++)
 
136
            printf(" %s", cfgfile[i].name);
 
137
        printf("\n");
 
138
        return 1;
 
139
    }
 
140
 
 
141
    printf("##\n## %s - automatically generated by clamconf "VERSION"\n##\n", name);
 
142
    printf("\n# Comment out or remove the line below.\nExample\n");
 
143
 
 
144
    for(i = 0; clam_options[i].owner; i++) {
 
145
        cpt = &clam_options[i];
 
146
        if(cpt->name && (cpt->owner & tool) && !(cpt->owner & OPT_DEPRECATED) && !(cpt->flags & 4)) {
 
147
            strncpy(buffer, cpt->description, sizeof(buffer)-1);
 
148
            buffer[sizeof(buffer)-1] = 0;
 
149
            tokens_count = cli_strtokenize(buffer, '\n', 128, tokens);
 
150
            printf("\n");
 
151
            for(j = 0; j < tokens_count; j++)
 
152
                printf("# %s\n", tokens[j]);
 
153
 
 
154
            switch(cpt->argtype) {
 
155
                case TYPE_STRING:
 
156
                    if(cpt->strarg)
 
157
                        printf("# Default: %s\n", cpt->strarg);
 
158
                    else
 
159
                        printf("# Default: disabled\n");
 
160
                    break;
 
161
 
 
162
                case TYPE_NUMBER:
 
163
                    if(cpt->numarg != -1)
 
164
                        printf("# Default: %lld\n", cpt->numarg);
 
165
                    else
 
166
                        printf("# Default: disabled\n");
 
167
                    break;
 
168
 
 
169
                case TYPE_SIZE:
 
170
                    printf("# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)\n# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes). To specify the size\n# in bytes just don't use modifiers.\n");
 
171
                    if(cpt->numarg != -1)
 
172
                        printf("# Default: %lld\n", cpt->numarg);
 
173
                    else
 
174
                        printf("# Default: disabled\n");
 
175
                    break;
 
176
 
 
177
                case TYPE_BOOL:
 
178
                    if(cpt->numarg != -1)
 
179
                        printf("# Default: %s\n", cpt->numarg ? "yes" : "no");
 
180
                    else
 
181
                        printf("# Default: disabled\n");
 
182
                    break;
 
183
 
 
184
                default:
 
185
                    printf("!!! %s: UNKNOWN INTERNAL TYPE !!!\n", cpt->name);
 
186
            }
 
187
 
 
188
            if(cpt->suggested && strchr(cpt->suggested, '\n')) {
 
189
                strncpy(buffer, cpt->suggested, sizeof(buffer)-1);
 
190
                buffer[sizeof(buffer)-1] = 0;
 
191
                tokens_count = cli_strtokenize(buffer, '\n', 128, tokens);
 
192
                for(j = 0; j < tokens_count; j++)
 
193
                    printf("#%s %s\n", cpt->name, tokens[j]);
 
194
            } else {
 
195
                printf("#%s %s\n", cpt->name, cpt->suggested ? cpt->suggested : "ARG");
 
196
            }
 
197
        }
 
198
    }
 
199
 
 
200
    return 0;
 
201
}
 
202
 
 
203
static void help(void)
 
204
{
 
205
    printf("\n");
 
206
    printf("           Clam AntiVirus: Configuration Tool %s\n", get_version());
 
207
    printf("           By The ClamAV Team: http://www.clamav.net/team\n");
 
208
    printf("           (C) 2009 Sourcefire, Inc.\n\n");
 
209
 
 
210
    printf("    --help                 -h         Show help\n");
 
211
    printf("    --version              -V         Show version\n");
 
212
    printf("    --config-dir=DIR       -c DIR     Read configuration files from DIR\n");
 
213
    printf("    --non-default          -n         Only display non-default settings\n");
 
214
    printf("    --generate-config=NAME -g NAME    Generate example config file\n");
 
215
    printf("\n");
 
216
    return;
 
217
}
 
218
 
 
219
static void print_platform(struct cli_environment *env)
 
220
{
 
221
    printf("\nPlatform information\n--------------------\n");
 
222
    printf("uname: %s %s %s %s\n",
 
223
           env->sysname, env->release, env->version, env->machine);
 
224
 
 
225
    printf("OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE"\n");
 
226
 
 
227
#ifdef C_LINUX
 
228
    if (!access("/usr/bin/lsb_release", X_OK)) {
 
229
        fputs("Full OS version: ", stdout);
 
230
        fflush(stdout);
 
231
        if (system("/usr/bin/lsb_release -d -s") == -1) {
 
232
           perror("failed to determine");
 
233
        }
 
234
    }
 
235
#else
 
236
    /* e.g. Solaris */
 
237
    if (!access("/etc/release", R_OK)) {
 
238
        char buf[1024];
 
239
        FILE *f = fopen("/etc/release", "r");
 
240
 
 
241
        if (f) {
 
242
            fgets(buf, sizeof(buf), f);
 
243
            printf("Full OS version: %s", buf);
 
244
            fclose(f);
 
245
        }
 
246
    }
 
247
#endif
 
248
 
 
249
    if (strcmp(ZLIB_VERSION, zlibVersion()))
 
250
        printf("WARNING: zlib version mismatch: %s (%s)\n", ZLIB_VERSION, zlibVersion());
 
251
#ifdef ZLIB_VERNUM
 
252
    printf("zlib version: %s (%s), compile flags: %02lx\n",
 
253
           ZLIB_VERSION, zlibVersion(), zlibCompileFlags());
 
254
#else
 
255
    /* old zlib w/o zlibCompileFlags() */
 
256
    printf("zlib version: %s (%s)\n",
 
257
           ZLIB_VERSION, zlibVersion());
 
258
#endif
 
259
    if (env->triple[0])
 
260
    printf("Triple: %s\n", env->triple);
 
261
    if (env->cpu[0])
 
262
        printf("CPU: %s, %s\n", env->cpu, env->big_endian ? "Big-endian" : "Little-endian");
 
263
    printf("platform id: 0x%08x%08x%08x\n",
 
264
           env->platform_id_a,
 
265
           env->platform_id_b,
 
266
           env->platform_id_c);
 
267
}
 
268
 
 
269
static void print_build(struct cli_environment *env)
 
270
{
 
271
    const char *name;
 
272
    const char *version = NULL;
 
273
    printf("\nBuild information\n-----------------\n");
 
274
    /* Try to print information about some commonly used compilers */
 
275
#ifdef __GNUC__
 
276
        version = __VERSION__;
 
277
#endif
 
278
    switch (env->compiler) {
 
279
        case compiler_gnuc:
 
280
            name = "GNU C";
 
281
            break;
 
282
        case compiler_clang:
 
283
            name = "Clang";
 
284
            break;
 
285
        case compiler_llvm:
 
286
            name = "LLVM-GCC";
 
287
            break;
 
288
        case compiler_intel:
 
289
            name = "Intel Compiler";
 
290
            break;
 
291
        case compiler_msc:
 
292
            name = "Microsoft Visual C++";
 
293
            break;
 
294
        case compiler_sun:
 
295
            name = "Sun studio";
 
296
            break;
 
297
        default:
 
298
            name = NULL;
 
299
    }
 
300
    if (name)
 
301
        printf("%s: %s%s(%u.%u.%u)\n", name,
 
302
               version ? version : "",
 
303
               version ? " " : "",
 
304
               env->c_version >> 16,
 
305
                   (env->c_version >> 8)&0xff,
 
306
                   (env->c_version)&0xff);
 
307
    cli_printcxxver();
 
308
#if defined(BUILD_CPPFLAGS) && defined(BUILD_CFLAGS) && defined(BUILD_CXXFLAGS) && defined(BUILD_LDFLAGS) && defined(BUILD_CONFIGURE_FLAGS)
 
309
    printf("CPPFLAGS: %s\nCFLAGS: %s\nCXXFLAGS: %s\nLDFLAGS: %s\nConfigure: %s\n",
 
310
           BUILD_CPPFLAGS, BUILD_CFLAGS, BUILD_CXXFLAGS, BUILD_LDFLAGS,
 
311
           BUILD_CONFIGURE_FLAGS);
 
312
#endif
 
313
    printf("sizeof(void*) = %d\n", env->sizeof_ptr);
 
314
    printf("Engine flevel: %d, dconf: %d\n",
 
315
           env->functionality_level,
 
316
           env->dconf_level);
 
317
}
 
318
 
 
319
static void print_dbs(const char *dir)
 
320
{
 
321
        DIR *dd;
 
322
        struct dirent *dent;
 
323
        char *dbfile;
 
324
        unsigned int flevel = cl_retflevel(), cnt, sigs = 0;
 
325
        struct cl_cvd *cvd;
 
326
 
 
327
    if((dd = opendir(dir)) == NULL) {
 
328
        printf("print_dbs: Can't open directory %s\n", dir);
 
329
        return;
 
330
    }
 
331
 
 
332
    while((dent = readdir(dd))) {
 
333
        if(dent->d_ino) {
 
334
            if(CLI_DBEXT(dent->d_name)) {
 
335
                dbfile = (char *) malloc(strlen(dent->d_name) + strlen(dir) + 2);
 
336
                if(!dbfile) {
 
337
                    printf("print_dbs: Can't allocate memory for dbfile\n");
 
338
                    closedir(dd);
 
339
                    return;
 
340
                }
 
341
                sprintf(dbfile, "%s"PATHSEP"%s", dir, dent->d_name);
 
342
                if(cli_strbcasestr(dbfile, ".cvd") || cli_strbcasestr(dbfile, ".cld")) {
 
343
                    cvd = cl_cvdhead(dbfile);
 
344
                    if(!cvd) {
 
345
                        printf("%s: Can't get information about the database\n", dbfile);
 
346
                    } else {
 
347
                        const time_t t = cvd->stime;
 
348
                        printf("%s: version %u, sigs: %u, built on %s", dent->d_name, cvd->version, cvd->sigs, ctime(&t));
 
349
                        sigs += cvd->sigs;
 
350
                        if(cvd->fl > flevel)
 
351
                            printf("%s: WARNING: This database requires f-level %u (current f-level: %u)\n", dent->d_name, cvd->fl, flevel);
 
352
                        cl_cvdfree(cvd);
 
353
                    }
 
354
                } else if(cli_strbcasestr(dbfile, ".cbc")) {
 
355
                    printf("[3rd Party] %s: bytecode\n", dent->d_name);
 
356
                    sigs++;
 
357
                } else {
 
358
                    cnt = countlines(dbfile);
 
359
                    printf("[3rd Party] %s: %u sig%c\n", dent->d_name, cnt, cnt > 1 ? 's' : ' ');
 
360
                    sigs += cnt;
 
361
                }
 
362
                free(dbfile);
 
363
            }
 
364
        }
 
365
    }
 
366
    closedir(dd);
 
367
    printf("Total number of signatures: %u\n", sigs);
 
368
}
 
369
 
 
370
int main(int argc, char **argv)
 
371
{
 
372
        const char *dir;
 
373
        char path[512], dbdir[512], clamd_dbdir[512], *pt;
 
374
        struct optstruct *opts, *toolopts;
 
375
        const struct optstruct *opt;
 
376
        unsigned int i, j;
 
377
        struct cli_environment env;
 
378
 
 
379
    cl_initialize_crypto();
 
380
 
 
381
    opts = optparse(NULL, argc, argv, 1, OPT_CLAMCONF, 0, NULL);
 
382
    if(!opts) {
 
383
        printf("ERROR: Can't parse command line options\n");
 
384
        return 1;
 
385
    }
 
386
 
 
387
    if(optget(opts, "help")->enabled) {
 
388
        help();
 
389
        optfree(opts);
 
390
        return 0;
 
391
    }
 
392
 
 
393
    if(optget(opts, "version")->enabled) {
 
394
        printf("Clam AntiVirus Configuration Tool %s\n", get_version());
 
395
        optfree(opts);
 
396
        return 0;
 
397
    }
 
398
 
 
399
    if((opt = optget(opts, "generate-config"))->enabled) {
 
400
        printconf(opt->strarg);
 
401
        optfree(opts);
 
402
        return 0;
 
403
    }
 
404
 
 
405
    dbdir[0] = 0;
 
406
    clamd_dbdir[0] = 0;
 
407
    dir = optget(opts, "config-dir")->strarg;
 
408
    printf("Checking configuration files in %s\n", dir);
 
409
    for(i = 0; cfgfile[i].name; i++) {
 
410
        snprintf(path, sizeof(path), "%s"PATHSEP"%s", dir, cfgfile[i].name);
 
411
        path[511] = 0;
 
412
        if(access(path, R_OK)) {
 
413
            printf("\n%s not found\n", cfgfile[i].name);
 
414
            continue;
 
415
        }
 
416
        printf("\nConfig file: %s\n", cfgfile[i].name);
 
417
        for(j = 0; j < strlen(cfgfile[i].name) + 13; j++)
 
418
            printf("-");
 
419
        printf("\n");
 
420
        toolopts = optparse(path, 0, NULL, 1, cfgfile[i].tool | OPT_DEPRECATED, 0, NULL);
 
421
        if(!toolopts)
 
422
            continue;
 
423
        printopts(toolopts, optget(opts, "non-default")->enabled);
 
424
        if(cfgfile[i].tool == OPT_FRESHCLAM) {
 
425
            opt = optget(toolopts, "DatabaseDirectory");
 
426
            strncpy(dbdir, opt->strarg, sizeof(dbdir));
 
427
            dbdir[sizeof(dbdir) - 1] = 0;
 
428
        } else if(cfgfile[i].tool == OPT_CLAMD) {
 
429
            opt = optget(toolopts, "DatabaseDirectory");
 
430
            strncpy(clamd_dbdir, opt->strarg, sizeof(clamd_dbdir));
 
431
            clamd_dbdir[sizeof(clamd_dbdir) - 1] = 0;
 
432
        }
 
433
        optfree(toolopts);
 
434
    }
 
435
    optfree(opts);
 
436
 
 
437
    printf("\nSoftware settings\n-----------------\n");
 
438
    printf("Version: %s\n", cl_retver());
 
439
    if(strcmp(cl_retver(), get_version()))
 
440
        printf("WARNING: Version mismatch: libclamav=%s, clamconf=%s\n", cl_retver(), get_version());
 
441
    cl_init(CL_INIT_DEFAULT);
 
442
    printf("Optional features supported: ");
 
443
#ifdef USE_MPOOL
 
444
        printf("MEMPOOL ");
 
445
#endif
 
446
#ifdef SUPPORT_IPv6
 
447
        printf("IPv6 ");
 
448
#endif
 
449
#ifdef CLAMUKO
 
450
        printf("CLAMUKO ");
 
451
#endif
 
452
#ifdef C_BIGSTACK
 
453
        printf("BIGSTACK ");
 
454
#endif
 
455
#ifdef FRESHCLAM_DNS_FIX
 
456
        printf("FRESHCLAM_DNS_FIX ");
 
457
#endif
 
458
#ifndef _WIN32
 
459
        if (get_fpu_endian() != FPU_ENDIAN_UNKNOWN)
 
460
#endif
 
461
                        printf("AUTOIT_EA06 ");
 
462
#ifdef HAVE_BZLIB_H
 
463
        printf("BZIP2 ");
 
464
#endif
 
465
    if(have_rar)
 
466
        printf("RAR ");
 
467
    if (have_clamjit)
 
468
        printf("JIT");
 
469
    printf("\n");
 
470
 
 
471
    if(!strlen(dbdir)) {
 
472
        pt = freshdbdir();
 
473
        if(pt) {
 
474
            strncpy(dbdir, pt, sizeof(dbdir));
 
475
            free(pt);
 
476
        } else {
 
477
            strncpy(dbdir, DATADIR, sizeof(dbdir));
 
478
        }
 
479
        dbdir[sizeof(dbdir) - 1] = 0;
 
480
    }
 
481
 
 
482
    printf("\nDatabase information\n--------------------\n");
 
483
    printf("Database directory: %s\n", dbdir);
 
484
    if(strcmp(dbdir, clamd_dbdir))
 
485
        printf("WARNING: freshclam.conf and clamd.conf point to different database directories\n");
 
486
    print_dbs(dbdir);
 
487
 
 
488
    cli_detect_environment(&env);
 
489
    print_platform(&env);
 
490
    print_build(&env);
 
491
    cl_cleanup_crypto();
 
492
    return 0;
 
493
}