~ubuntu-branches/ubuntu/dapper/clamav/dapper-updates

« back to all changes in this revision

Viewing changes to clamdscan/clamdscan.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Tautschnig, Michael Tautschnig
  • Date: 2009-03-25 16:02:18 UTC
  • mfrom: (0.12.1 upstream)
  • mto: (12.1.9 dapper-security)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090325160218-forpco6d0ghp48br
Tags: 0.95+dfsg-1
[ Michael Tautschnig ]
* New upstream version, fixes:
  - License incompatibility with libgmp (closes: #512776)
  - wrong claim about all interception message methods (closes: #438455)
  - clamdscan fails to connect to clamd (closes: #515798)
  - clamav-milter dies after email scanning (sparc64) (closes: #339590)
  - VERSION reports wrong database version (closes: #323803)
  - memory footprint skyrockets (closes: #420391)
  - Virus not detected in RAR-archive inside email (closes: #484642)
  - clamav-milter ignores whitelist file (closes: #520353)
  - clamav-milter won't start when both local and tcp socket are in use 
    (closes: #505852)
  - ERROR: Can't find any clamd server (closes: #435007)
  - clamd: random SIGABRT (closes: #512720)
* Removed configure options that aren't supported anymore (--with-sendmail,
  --with-tcpwrappers, --with-dns)
* Bumped Standards-Version to 3.8.1 (added mkdir calls to ensure
  /var/run/clamav exists)
* Configure with --with-system-tommath to use Debian's libtommath-dev
  instead of the bundled one.
* Updated *Depends (dropped essential packages and removed versions where
  etch already satisfies the dependencies).
* SONAME bump: libclamav5 -> libclamav6
* Build-Depend on libltdl3-dev to avoid using the bundled libltdl, but still
  get support for runtime loading (nonfree) unrar code if the user so
  decides.
* Fixed watch file to deal with new versioning schema (+dfsg).
* Run make check unless nocheck is in DEB_BUILD_OPTIONS
* Changed Section of clamav-dbg to debug.
* Override lintian error stating that libclamav6 statically links to zlib
  (lintian is right, libclamav6 does indeed duplicate parts of the zlib
  code, but there is not way around that).
* Handle new option SafeBrowsing in freshclam.conf.
* Create symlinks to AUTHORS, not AUTHORS.gz (closes: #520172).
* clamav-milter got its own config file and logging options, handled via
  debconf, added logrotation (closes: #518628)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
 
2
 *  Copyright (C) 2007-2009 Sourcefire, Inc.
 
3
 *
 
4
 *  Authors: Tomasz Kojm, aCaB
3
5
 *
4
6
 *  This program is free software; you can redistribute it and/or modify
5
7
 *  it under the terms of the GNU General Public License version 2 as
28
30
#include <time.h>
29
31
#include <signal.h>
30
32
 
31
 
#include "options.h"
32
 
#include "others.h"
33
 
#include "defaults.h"
 
33
#include "shared/output.h"
 
34
#include "shared/misc.h"
 
35
#include "shared/optparser.h"
 
36
#include "shared/actions.h"
 
37
 
34
38
#include "client.h"
35
 
#include "output.h"
36
 
#include "misc.h"
37
 
 
38
 
#include "clamscan/clamscan_opt.h"
39
39
 
40
40
void help(void);
41
41
 
42
42
extern int printinfected;
43
 
extern int notremoved, notmoved;
44
43
 
45
44
static void print_server_version(const struct optstruct *opt)
46
45
{
50
49
    }
51
50
}
52
51
 
53
 
static int reload_server_database(const struct optstruct *opt)
54
 
{
55
 
    if(reload_clamd_database(opt)) {
56
 
        logg("!Clamd did not reload the database\n");
57
 
        return 2;
58
 
    }
59
 
    return 0;
60
 
}
61
 
 
62
52
int main(int argc, char **argv)
63
53
{
64
54
        int ds, dms, ret, infected;
65
55
        struct timeval t1, t2;
66
56
        struct timezone tz;
67
57
        time_t starttime;
68
 
        struct optstruct *opt;
69
 
        const char *clamdscan_accepted[] = { "help", "version", "verbose", "quiet",
70
 
                                  "stdout", "log", "move", "copy", "remove",
71
 
                                  "config-file", "no-summary",  "fdpass",
72
 
                                  "disable-summary", "multiscan", "reload",
73
 
                                  "infected",
74
 
                                  NULL };
75
 
 
76
 
 
77
 
    opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, clamdscan_accepted, NULL);
78
 
    if(!opt) {
79
 
        mprintf("!Can't parse the command line\n");
 
58
        struct optstruct *opts;
 
59
        const struct optstruct *opt;
 
60
        struct sigaction sigact;
 
61
 
 
62
 
 
63
    if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMDSCAN, OPT_CLAMSCAN, NULL)) == NULL) {
 
64
        mprintf("!Can't parse command line options\n");
80
65
        return 2;
81
66
    }
82
67
 
83
 
    if(opt_check(opt, "verbose")) {
 
68
    if(optget(opts, "verbose")->enabled) {
84
69
        mprintf_verbose = 1;
85
70
        logg_verbose = 1;
86
71
    }
87
72
 
88
 
    if(opt_check(opt, "quiet"))
 
73
    if(optget(opts, "quiet")->enabled)
89
74
        mprintf_quiet = 1;
90
75
 
91
 
    if(opt_check(opt, "stdout"))
 
76
    if(optget(opts, "stdout")->enabled)
92
77
        mprintf_stdout = 1;
93
78
 
94
 
    if(opt_check(opt, "version")) {
95
 
        print_server_version(opt);
96
 
        opt_free(opt);
 
79
    if(optget(opts, "version")->enabled) {
 
80
        print_server_version(opts);
 
81
        optfree(opts);
97
82
        exit(0);
98
83
    }
99
84
 
100
 
    if(opt_check(opt, "help")) {
101
 
        opt_free(opt);
 
85
    if(optget(opts, "help")->enabled) {
 
86
        optfree(opts);
102
87
        help();
103
88
    }
104
89
 
105
 
    if(opt_check(opt, "infected"))
 
90
    if(optget(opts, "infected")->enabled)
106
91
        printinfected = 1;
107
92
 
108
93
    /* initialize logger */
109
94
 
110
 
    if(opt_check(opt, "log")) {
111
 
        logg_file = opt_arg(opt, "log");
 
95
    if((opt = optget(opts, "log"))->enabled) {
 
96
        logg_file = opt->strarg;
112
97
        if(logg("--------------------------------------\n")) {
113
98
            mprintf("!Problem with internal logger.\n");
114
 
            opt_free(opt);
 
99
            optfree(opts);
115
100
            exit(2);
116
101
        }
117
102
    } else 
118
103
        logg_file = NULL;
119
104
 
120
105
 
121
 
    if(opt_check(opt, "reload")) {
122
 
        ret = reload_server_database(opt);
123
 
        opt_free(opt);
 
106
    if(optget(opts, "reload")->enabled) {
 
107
        ret = reload_clamd_database(opts);
 
108
        optfree(opts);
124
109
        logg_close();
125
110
        exit(ret);
126
111
    }
127
112
 
 
113
    if(actsetup(opts)) {
 
114
        optfree(opts);
 
115
        logg_close();
 
116
        exit(2);
 
117
    }
 
118
 
 
119
    memset(&sigact, 0, sizeof(struct sigaction));
 
120
    sigact.sa_handler = SIG_IGN;
 
121
    sigemptyset(&sigact.sa_mask);
 
122
    sigaddset(&sigact.sa_mask, SIGPIPE);
 
123
    sigaction(SIGPIPE, &sigact, NULL);
 
124
 
128
125
    time(&starttime);
129
126
    /* ctime() does \n, but I need it once more */
130
127
 
131
128
    gettimeofday(&t1, &tz);
132
129
 
133
 
    ret = client(opt, &infected);
 
130
    ret = client(opts, &infected);
134
131
 
135
132
    /* TODO: Implement STATUS in clamd */
136
 
    if((infected || ret != 2) && !opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) {
 
133
    if((infected || ret != 2) && !optget(opts, "no-summary")->enabled) {
137
134
        gettimeofday(&t2, &tz);
138
135
        ds = t2.tv_sec - t1.tv_sec;
139
136
        dms = t2.tv_usec - t1.tv_usec;
151
148
    }
152
149
 
153
150
    logg_close();
154
 
    opt_free(opt);
 
151
    optfree(opts);
155
152
    exit(ret);
156
153
}
157
154
 
162
159
 
163
160
    mprintf("\n");
164
161
    mprintf("                       ClamAV Daemon Client %s\n", get_version());
165
 
    mprintf("     (C) 2002 - 2007 ClamAV Team - http://www.clamav.net/team\n\n");
 
162
    printf("           By The ClamAV Team: http://www.clamav.net/team\n");
 
163
    printf("           (C) 2007-2009 Sourcefire, Inc.\n\n");
166
164
 
167
165
    mprintf("    --help              -h             Show help\n");
168
166
    mprintf("    --version           -V             Print version number and exit\n");
179
177
    mprintf("    --infected            -i           Only print infected files\n");
180
178
    mprintf("    --no-summary                       Disable summary at end of scanning\n");
181
179
    mprintf("    --reload                           Request clamd to reload virus database\n");
182
 
    mprintf("    --fdpass                           pass filedescriptor to clamd (useful if clamd is running as a different user)\n");
 
180
    mprintf("    --fdpass                           Pass filedescriptor to clamd (useful if clamd is running as a different user)\n");
 
181
    mprintf("    --stream                           Force streaming files to clamd (for debugging and unit testing)\n");
183
182
    mprintf("\n");
184
183
 
185
184
    exit(0);