~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to clamd/clamuko.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2007-2009 Sourcefire, Inc.
3
 
 *
4
 
 *  Authors: Tomasz Kojm
 
2
 *  Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
5
3
 *
6
4
 *  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.
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
9
8
 *
10
9
 *  This program is distributed in the hope that it will be useful,
11
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
30
29
#include <sys/stat.h>
31
30
#include <signal.h>
32
31
#include <pthread.h>
33
 
#include <string.h>
34
32
 
35
33
#include "libclamav/clamav.h"
36
 
#include "libclamav/scanners.h"
37
34
 
38
 
#include "shared/optparser.h"
 
35
#include "shared/cfgparser.h"
39
36
#include "shared/output.h"
40
37
 
41
38
#include "server.h"
42
39
#include "others.h"
43
40
#include "dazukoio.h"
44
 
#include "clamukofs.h"
45
41
#include "clamuko.h"
46
 
#include "scanner.h"
47
42
 
48
43
struct dazuko_access *acc;
49
 
short int clamuko_scanning;
 
44
 
50
45
static void clamuko_exit(int sig)
51
46
{
52
47
 
66
61
    pthread_exit(NULL);
67
62
}
68
63
 
69
 
static void *clamukolegacyth(void *arg)
 
64
void *clamukoth(void *arg)
70
65
{
71
66
        struct thrarg *tharg = (struct thrarg *) arg;
72
67
        sigset_t sigset;
73
68
        const char *virname;
74
69
        struct sigaction act;
75
70
        unsigned long mask = 0;
76
 
        const struct optstruct *pt;
 
71
        const struct cfgstruct *pt;
77
72
        short int scan;
78
 
        int sizelimit = 0, extinfo;
 
73
        int sizelimit = 0;
79
74
        struct stat sb;
80
 
        struct cb_context context;
81
75
 
82
76
 
83
77
    clamuko_scanning = 0;
85
79
    /* ignore all signals except SIGUSR1 */
86
80
    sigfillset(&sigset);
87
81
    sigdelset(&sigset, SIGUSR1);
88
 
    /* The behavior of a process is undefined after it ignores a 
89
 
     * SIGFPE, SIGILL, SIGSEGV, or SIGBUS signal */
90
 
    sigdelset(&sigset, SIGFPE);
91
 
    sigdelset(&sigset, SIGILL);
92
82
    sigdelset(&sigset, SIGSEGV);
93
 
#ifdef SIGBUS    
94
 
    sigdelset(&sigset, SIGBUS);
95
 
#endif
96
83
    pthread_sigmask(SIG_SETMASK, &sigset, NULL);
97
 
    memset(&act, 0, sizeof(struct sigaction));
98
84
    act.sa_handler = clamuko_exit;
99
85
    sigfillset(&(act.sa_mask));
100
86
    sigaction(SIGUSR1, &act, NULL);
108
94
        logg("Clamuko: Correctly registered with Dazuko.\n");
109
95
 
110
96
    /* access mask */
111
 
    if(optget(tharg->opts, "ClamukoScanOnOpen")->enabled) {
 
97
    if(cfgopt(tharg->copt, "ClamukoScanOnOpen")->enabled) {
112
98
        logg("Clamuko: Scan-on-open mode activated.\n");
113
99
        mask |= DAZUKO_ON_OPEN;
114
100
    }
115
 
    if(optget(tharg->opts, "ClamukoScanOnClose")->enabled) {
 
101
    if(cfgopt(tharg->copt, "ClamukoScanOnClose")->enabled) {
116
102
        logg("Clamuko: Scan-on-close mode activated.\n");
117
103
        mask |= DAZUKO_ON_CLOSE;
118
104
    }
119
 
    if(optget(tharg->opts, "ClamukoScanOnExec")->enabled) {
 
105
    if(cfgopt(tharg->copt, "ClamukoScanOnExec")->enabled) {
120
106
        logg("Clamuko: Scan-on-exec mode activated.\n");
121
107
        mask |= DAZUKO_ON_EXEC;
122
108
    }
133
119
        return NULL;
134
120
    }
135
121
 
136
 
    if((pt = optget(tharg->opts, "ClamukoIncludePath"))->enabled) {
 
122
    if((pt = cfgopt(tharg->copt, "ClamukoIncludePath"))->enabled) {
137
123
        while(pt) {
138
124
            if((dazukoAddIncludePath(pt->strarg))) {
139
125
                logg("!Clamuko: Dazuko -> Can't include path %s\n", pt->strarg);
142
128
            } else
143
129
                logg("Clamuko: Included path %s\n", pt->strarg);
144
130
 
145
 
            pt = (struct optstruct *) pt->nextarg;
 
131
            pt = (struct cfgstruct *) pt->nextarg;
146
132
        }
147
133
    } else {
148
134
        logg("!Clamuko: please include at least one path.\n");
150
136
        return NULL;
151
137
    }
152
138
 
153
 
    if((pt = optget(tharg->opts, "ClamukoExcludePath"))->enabled) {
 
139
    if((pt = cfgopt(tharg->copt, "ClamukoExcludePath"))->enabled) {
154
140
        while(pt) {
155
141
            if((dazukoAddExcludePath(pt->strarg))) {
156
142
                logg("!Clamuko: Dazuko -> Can't exclude path %s\n", pt->strarg);
159
145
            } else
160
146
                logg("Clamuko: Excluded path %s\n", pt->strarg);
161
147
 
162
 
            pt = (struct optstruct *) pt->nextarg;
 
148
            pt = (struct cfgstruct *) pt->nextarg;
163
149
        }
164
150
    }
165
151
 
166
 
    sizelimit = optget(tharg->opts, "ClamukoMaxFileSize")->numarg;
 
152
    sizelimit = cfgopt(tharg->copt, "ClamukoMaxFileSize")->numarg;
167
153
    if(sizelimit)
168
154
        logg("Clamuko: Max file size limited to %d bytes.\n", sizelimit);
169
155
    else
170
156
        logg("Clamuko: File size limit disabled.\n");
171
157
 
172
 
    extinfo = optget(tharg->opts, "ExtendedDetectionInfo")->enabled;
173
 
 
174
158
    while(1) {
175
159
 
176
160
        if(dazukoGetAccess(&acc) == 0) {
185
169
                }
186
170
            }
187
171
 
188
 
            context.filename = acc->filename;
189
 
            context.virsize = 0;
190
 
            if(scan && cl_scanfile_callback(acc->filename, &virname, NULL, tharg->engine, tharg->options, &context) == CL_VIRUS) {
191
 
                if(context.virsize)
192
 
                    detstats_add(virname, acc->filename, context.virsize, context.virhash);
193
 
                if(extinfo && context.virsize)
194
 
                    logg("Clamuko: %s: %s(%s:%llu) FOUND\n", acc->filename, virname, context.virhash, context.virsize);
195
 
                else
196
 
                    logg("Clamuko: %s: %s FOUND\n", acc->filename, virname);
197
 
                virusaction(acc->filename, virname, tharg->opts);
 
172
            if(scan && cl_scanfile(acc->filename, &virname, NULL, tharg->engine, tharg->limits, tharg->options) == CL_VIRUS) {
 
173
                logg("Clamuko: %s: %s FOUND\n", acc->filename, virname);
 
174
                virusaction(acc->filename, virname, tharg->copt);
198
175
                acc->deny = 1;
199
176
            } else
200
177
                acc->deny = 0;
215
192
    return NULL;
216
193
}
217
194
 
218
 
void *clamukoth(void *arg)
219
 
{
220
 
        struct stat s;
221
 
 
222
 
    /* we use DazukoFS if /dev/dazukofs.ctrl exists and it is a
223
 
     * character device, otherwise we use Dazuko */
224
 
    if(stat("/dev/dazukofs.ctrl", &s) != 0) return clamukolegacyth(arg);
225
 
    if(!S_ISCHR(s.st_mode)) return clamukolegacyth(arg);
226
 
    return clamukofsth(arg);
227
 
}
228
 
 
229
195
#endif