~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/clamdscan/clamdscan.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) 2007-2009 Sourcefire, Inc.
 
3
 *
 
4
 *  Authors: Tomasz Kojm, aCaB
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License version 2 as
 
8
 *  published by the Free Software Foundation.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
 *  MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#if HAVE_CONFIG_H
 
22
#include "clamav-config.h"
 
23
#endif
 
24
 
 
25
#include <stdio.h>
 
26
#include <string.h>
 
27
#include <stdlib.h>
 
28
#ifdef HAVE_UNISTD_H
 
29
#include <unistd.h>
 
30
#endif
 
31
#ifndef _WIN32
 
32
#include <sys/time.h>
 
33
#endif
 
34
#include <time.h>
 
35
#include <signal.h>
 
36
 
 
37
#include <openssl/ssl.h>
 
38
#include <openssl/err.h>
 
39
#include "libclamav/crypto.h"
 
40
 
 
41
#include "shared/output.h"
 
42
#include "shared/misc.h"
 
43
#include "shared/optparser.h"
 
44
#include "shared/actions.h"
 
45
 
 
46
#include "client.h"
 
47
 
 
48
void help(void);
 
49
 
 
50
extern int printinfected;
 
51
struct optstruct *clamdopts = NULL;
 
52
 
 
53
static void print_server_version(const struct optstruct *opt)
 
54
{
 
55
    if(get_clamd_version(opt)) {
 
56
        /* can't get version from server, fallback */
 
57
        printf("ClamAV %s\n", get_version());
 
58
    }
 
59
}
 
60
 
 
61
int main(int argc, char **argv)
 
62
{
 
63
        int ds, dms, ret, infected = 0, err = 0;
 
64
        struct timeval t1, t2;
 
65
        time_t starttime;
 
66
        struct optstruct *opts;
 
67
        const struct optstruct *opt;
 
68
#ifndef _WIN32
 
69
        struct sigaction sigact;
 
70
#endif
 
71
 
 
72
    cl_initialize_crypto();
 
73
 
 
74
    if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMDSCAN, OPT_CLAMSCAN, NULL)) == NULL) {
 
75
        mprintf("!Can't parse command line options\n");
 
76
        return 2;
 
77
    }
 
78
 
 
79
    if((clamdopts = optparse(optget(opts, "config-file")->strarg, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
 
80
        logg("!Can't parse clamd configuration file %s\n", optget(opts, "config-file")->strarg);
 
81
        return 2;
 
82
    }
 
83
 
 
84
    if(optget(opts, "verbose")->enabled) {
 
85
        mprintf_verbose = 1;
 
86
        logg_verbose = 1;
 
87
    }
 
88
 
 
89
    if(optget(opts, "quiet")->enabled)
 
90
        mprintf_quiet = 1;
 
91
 
 
92
    if(optget(opts, "stdout")->enabled)
 
93
        mprintf_stdout = 1;
 
94
 
 
95
    if(optget(opts, "version")->enabled) {
 
96
        print_server_version(opts);
 
97
        optfree(opts);
 
98
        optfree(clamdopts);
 
99
        exit(0);
 
100
    }
 
101
 
 
102
    if(optget(opts, "help")->enabled) {
 
103
        optfree(opts);
 
104
        optfree(clamdopts);
 
105
        help();
 
106
    }
 
107
 
 
108
    if(optget(opts, "infected")->enabled)
 
109
        printinfected = 1;
 
110
 
 
111
    /* initialize logger */
 
112
 
 
113
    if((opt = optget(opts, "log"))->enabled) {
 
114
        logg_file = opt->strarg;
 
115
        if(logg("--------------------------------------\n")) {
 
116
            mprintf("!Problem with internal logger.\n");
 
117
            optfree(opts);
 
118
            optfree(clamdopts);
 
119
            exit(2);
 
120
        }
 
121
    } else 
 
122
        logg_file = NULL;
 
123
 
 
124
 
 
125
    if(optget(opts, "reload")->enabled) {
 
126
        ret = reload_clamd_database(opts);
 
127
        optfree(opts);
 
128
        optfree(clamdopts);
 
129
        logg_close();
 
130
        exit(ret);
 
131
    }
 
132
 
 
133
    if(actsetup(opts)) {
 
134
        optfree(opts);
 
135
        optfree(clamdopts);
 
136
        logg_close();
 
137
        exit(2);
 
138
    }
 
139
 
 
140
#ifndef _WIN32
 
141
    memset(&sigact, 0, sizeof(struct sigaction));
 
142
    sigact.sa_handler = SIG_IGN;
 
143
    sigemptyset(&sigact.sa_mask);
 
144
    sigaddset(&sigact.sa_mask, SIGPIPE);
 
145
    sigaction(SIGPIPE, &sigact, NULL);
 
146
#endif
 
147
 
 
148
    time(&starttime);
 
149
    /* ctime() does \n, but I need it once more */
 
150
 
 
151
    gettimeofday(&t1, NULL);
 
152
 
 
153
    ret = client(opts, &infected, &err);
 
154
    optfree(clamdopts);
 
155
 
 
156
    /* TODO: Implement STATUS in clamd */
 
157
    if(!optget(opts, "no-summary")->enabled) {
 
158
        gettimeofday(&t2, NULL);
 
159
        ds = t2.tv_sec - t1.tv_sec;
 
160
        dms = t2.tv_usec - t1.tv_usec;
 
161
        ds -= (dms < 0) ? (1):(0);
 
162
        dms += (dms < 0) ? (1000000):(0);
 
163
        logg("\n----------- SCAN SUMMARY -----------\n");
 
164
        logg("Infected files: %d\n", infected);
 
165
        if(err)
 
166
            logg("Total errors: %d\n", err);
 
167
        if(notremoved) {
 
168
            logg("Not removed: %d\n", notremoved);
 
169
        }
 
170
        if(notmoved) {
 
171
            logg("Not moved: %d\n", notmoved);
 
172
        }
 
173
        logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
 
174
    }
 
175
 
 
176
    logg_close();
 
177
    optfree(opts);
 
178
    cl_cleanup_crypto();
 
179
    exit(ret);
 
180
}
 
181
 
 
182
void help(void)
 
183
{
 
184
 
 
185
    mprintf_stdout = 1;
 
186
 
 
187
    mprintf("\n");
 
188
    mprintf("                       ClamAV Daemon Client %s\n", get_version());
 
189
    printf("           By The ClamAV Team: http://www.clamav.net/team\n");
 
190
    printf("           (C) 2007-2009 Sourcefire, Inc.\n\n");
 
191
 
 
192
    mprintf("    --help              -h             Show help\n");
 
193
    mprintf("    --version           -V             Print version number and exit\n");
 
194
    mprintf("    --verbose           -v             Be verbose\n");
 
195
    mprintf("    --quiet                            Be quiet, only output error messages\n");
 
196
    mprintf("    --stdout                           Write to stdout instead of stderr\n");
 
197
    mprintf("                                       (this help is always written to stdout)\n");
 
198
    mprintf("    --log=FILE          -l FILE        Save scan report in FILE\n");
 
199
    mprintf("    --file-list=FILE    -f FILE        Scan files from FILE\n");
 
200
    mprintf("    --remove                           Remove infected files. Be careful!\n");
 
201
    mprintf("    --move=DIRECTORY                   Move infected files into DIRECTORY\n");
 
202
    mprintf("    --copy=DIRECTORY                   Copy infected files into DIRECTORY\n");
 
203
    mprintf("    --config-file=FILE                 Read configuration from FILE.\n");
 
204
    mprintf("    --allmatch            -z           Continue scanning within file after finding a match.\n");
 
205
    mprintf("    --multiscan           -m           Force MULTISCAN mode\n");
 
206
    mprintf("    --infected            -i           Only print infected files\n");
 
207
    mprintf("    --no-summary                       Disable summary at end of scanning\n");
 
208
    mprintf("    --reload                           Request clamd to reload virus database\n");
 
209
    mprintf("    --fdpass                           Pass filedescriptor to clamd (useful if clamd is running as a different user)\n");
 
210
    mprintf("    --stream                           Force streaming files to clamd (for debugging and unit testing)\n");
 
211
    mprintf("\n");
 
212
 
 
213
    exit(0);
 
214
}