~ubuntu-branches/ubuntu/oneiric/clamav/oneiric-updates

« back to all changes in this revision

Viewing changes to clamd/clamuko.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-06-18 09:37:17 UTC
  • mfrom: (110.1.6 quantal)
  • Revision ID: package-import@ubuntu.com-20120618093717-n4dfr1v3ndxhhzf8
Tags: 0.97.5+dfsg-1ubuntu0.11.10.1
* SECURITY UPDATE: Updated to 0.97.5 to fix multiple security issues with
  malformed files.
  - CVE-2012-1457
  - CVE-2012-1458
  - CVE-2012-1459

Show diffs side-by-side

added added

removed removed

Lines of Context:
231
231
    return clamukofsth(arg);
232
232
}
233
233
 
 
234
#elif defined(CLAMAUTH)
 
235
 
 
236
#include <stdio.h>
 
237
#include <unistd.h>
 
238
#include <sys/types.h>
 
239
#include <sys/stat.h>
 
240
#include <sys/uio.h>
 
241
#include <fcntl.h>
 
242
#include <signal.h>
 
243
#include <pthread.h>
 
244
#include <string.h>
 
245
#include <errno.h>
 
246
 
 
247
#include "libclamav/clamav.h"
 
248
#include "libclamav/scanners.h"
 
249
 
 
250
#include "shared/optparser.h"
 
251
#include "shared/output.h"
 
252
 
 
253
#include "server.h"
 
254
#include "others.h"
 
255
#include "scanner.h"
 
256
 
 
257
#define SUPPORTED_PROTOCOL  2
 
258
 
 
259
static int cauth_fd = -1;
 
260
 
 
261
struct ClamAuthEvent {
 
262
    unsigned int action;
 
263
    char path[1024];
 
264
    unsigned int pid;
 
265
};
 
266
 
 
267
static void cauth_exit(int sig)
 
268
{
 
269
    logg("*ClamAuth: cauth_exit(), signal %d\n", sig);
 
270
    if(cauth_fd > 0)
 
271
        close(cauth_fd);
 
272
    pthread_exit(NULL);
 
273
    logg("ClamAuth: stopped\n");
 
274
}
 
275
 
 
276
static int cauth_scanfile(const char *fname, int extinfo, struct thrarg *tharg)
 
277
{
 
278
        struct cb_context context;
 
279
        const char *virname;
 
280
        int ret = 0, fd;
 
281
 
 
282
    context.filename = fname;
 
283
    context.virsize = 0;
 
284
 
 
285
    fd = open(fname, O_RDONLY);
 
286
    if(fd == -1)
 
287
        return -1;
 
288
 
 
289
    if(cl_scandesc_callback(fd, &virname, NULL, tharg->engine, tharg->options, &context) == CL_VIRUS) {
 
290
        if(context.virsize)
 
291
            detstats_add(virname, fname, context.virsize, context.virhash);
 
292
        if(extinfo && context.virsize)
 
293
            logg("ClamAuth: %s: %s(%s:%llu) FOUND\n", fname, virname, context.virhash, context.virsize);
 
294
        else
 
295
            logg("ClamAuth: %s: %s FOUND\n", fname, virname);
 
296
        virusaction(fname, virname, tharg->opts);
 
297
    }
 
298
    close(fd);
 
299
    return ret;
 
300
}
 
301
 
 
302
void *clamukoth(void *arg)
 
303
{
 
304
        struct thrarg *tharg = (struct thrarg *) arg;
 
305
        sigset_t sigset;
 
306
        struct sigaction act;
 
307
        int eventcnt = 1, extinfo;
 
308
        char err[128];
 
309
        struct ClamAuthEvent event;
 
310
 
 
311
    /* ignore all signals except SIGUSR1 */
 
312
    sigfillset(&sigset);
 
313
    sigdelset(&sigset, SIGUSR1);
 
314
    /* The behavior of a process is undefined after it ignores a 
 
315
     * SIGFPE, SIGILL, SIGSEGV, or SIGBUS signal */
 
316
    sigdelset(&sigset, SIGFPE);
 
317
    sigdelset(&sigset, SIGILL);
 
318
    sigdelset(&sigset, SIGSEGV);
 
319
#ifdef SIGBUS    
 
320
    sigdelset(&sigset, SIGBUS);
 
321
#endif
 
322
    pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 
323
    memset(&act, 0, sizeof(struct sigaction));
 
324
    act.sa_handler = cauth_exit;
 
325
    sigfillset(&(act.sa_mask));
 
326
    sigaction(SIGUSR1, &act, NULL);
 
327
    sigaction(SIGSEGV, &act, NULL);
 
328
 
 
329
    extinfo = optget(tharg->opts, "ExtendedDetectionInfo")->enabled;
 
330
 
 
331
    cauth_fd = open("/dev/clamauth", O_RDONLY);
 
332
    if(cauth_fd == -1) {
 
333
        logg("!ClamAuth: Can't open /dev/clamauth\n");
 
334
        if(errno == ENOENT)
 
335
            logg("!ClamAuth: Please make sure ClamAuth.kext is loaded\n");
 
336
        else if(errno == EACCES)
 
337
            logg("!ClamAuth: This application requires root privileges\n");
 
338
        else
 
339
            logg("!ClamAuth: /dev/clamauth: %s\n", cli_strerror(errno, err, sizeof(err)));
 
340
 
 
341
        return NULL;
 
342
    }
 
343
 
 
344
    while(1) {
 
345
        if(read(cauth_fd, &event, sizeof(event)) > 0) {
 
346
            if(eventcnt == 1) {
 
347
                if(event.action != SUPPORTED_PROTOCOL) {
 
348
                    logg("!ClamAuth: Protocol version mismatch (tool: %d, driver: %d)\n", SUPPORTED_PROTOCOL, event.action);
 
349
                    close(cauth_fd);
 
350
                    return NULL;
 
351
                }
 
352
                if(strncmp(event.path, "ClamAuth", 8)) {
 
353
                    logg("!ClamAuth: Invalid version event\n");
 
354
                    close(cauth_fd);
 
355
                    return NULL;
 
356
                }
 
357
                logg("ClamAuth: Driver version: %s, protocol version: %d\n", &event.path[9], event.action);
 
358
            } else {
 
359
                cauth_scanfile(event.path, extinfo, tharg);
 
360
            }
 
361
            eventcnt++;
 
362
        } else {
 
363
            if(errno == ENODEV) {
 
364
                printf("^ClamAuth: ClamAuth module deactivated, terminating\n");
 
365
                close(cauth_fd);
 
366
                return NULL;
 
367
            }
 
368
        }
 
369
        usleep(200);
 
370
    }
 
371
}
234
372
#endif