~ubuntu-branches/ubuntu/jaunty/clamav/jaunty-backports

« back to all changes in this revision

Viewing changes to clambc/bcrun.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-20 22:09:21 UTC
  • mfrom: (1.44.1 upstream) (10.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20100520220921-flsp1pbntitvwc59
Tags: 0.96.1+dfsg-0ubuntu1
* New upstream release
  - Remove non-free libclamunrar directory and repack +dfsg tarball
  - Remove win32/ for size reasons since the tarball is repacked already and
    adjust Makefile.in/am
  - Add support for new TestDatabases option in debian/clamav-
    freshclam.postinst.in (match upstream default of yes)
  - Add VirusAction option to debian/clamav-milter.postinst.in
  - Drop powerpc clamd fix, incorporated upstream
  - Drop diff in docs/man/clamd.conf.5.in, incorporated upstream
  - Drop addition of COPYING.llvm, incorporated upstream
* Remaining differences from Debian:
  - Drop initial signature definitions from clamav-base
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Detect incorrect value for clamav-freshclam/NotifyClamd and set it to true

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "shared/optparser.h"
34
34
#include "shared/misc.h"
35
35
#include "libclamav/dconf.h"
 
36
#include "libclamav/others.h"
36
37
 
37
38
#include <fcntl.h>
38
39
#include <stdlib.h>
123
124
    fprintf(stderr, "[trace] %p\n", ptr);
124
125
}
125
126
 
126
 
static uint8_t cli_debug_flag=0;
 
127
static uint8_t debug_flag = 0;
127
128
static void print_src(const char *file)
128
129
{
129
130
  char buf[4096];
143
144
      }
144
145
    }
145
146
  } while (!found && (nread == sizeof(buf)));
146
 
  if (cli_debug_flag)
 
147
  if (debug_flag)
147
148
      printf("[clambc] Source code:");
148
149
  do {
149
150
    for (;i+1<nread;i++) {
237
238
    const struct optstruct *opt;
238
239
    unsigned funcid=0, i;
239
240
    struct cli_all_bc bcs;
240
 
    unsigned int fd = -1;
 
241
    int fd = -1;
241
242
    unsigned tracelevel;
242
243
 
 
244
    if(check_flevel())
 
245
        exit(1);
 
246
 
243
247
    opts = optparse(NULL, argc, argv, 1, OPT_CLAMBC, 0, NULL);
244
248
    if (!opts) {
245
249
        fprintf(stderr, "ERROR: Can't parse command line options\n");
273
277
 
274
278
    if (optget(opts,"debug")->enabled) {
275
279
        cl_debug();
276
 
        cli_debug_flag=1;
 
280
        debug_flag=1;
277
281
    }
278
282
    rc = cl_init(CL_INIT_DEFAULT);
279
283
    if (rc != CL_SUCCESS) {
309
313
        exit(4);
310
314
    }
311
315
    fclose(f);
312
 
    if (cli_debug_flag)
313
 
    printf("[clambc] Bytecode loaded\n");
 
316
    if (bc->state == bc_skip) {
 
317
        fprintf(stderr,"bytecode load skipped\n");
 
318
        exit(0);
 
319
    }
 
320
    if (debug_flag)
 
321
        printf("[clambc] Bytecode loaded\n");
314
322
    if (optget(opts, "info")->enabled) {
315
323
        cli_bytecode_describe(bc);
316
324
    } else if (optget(opts, "printsrc")->enabled) {
317
325
        print_src(opts->filename[0]);
318
326
    } else {
 
327
        cli_ctx cctx;
 
328
        struct cl_engine *engine = cl_engine_new();
319
329
        fmap_t *map = NULL;
 
330
        memset(&cctx, 0, sizeof(cctx));
 
331
        if (!engine) {
 
332
            fprintf(stderr,"Unable to create engine\n");
 
333
            optfree(opts);
 
334
            exit(3);
 
335
        }
 
336
        rc = cl_engine_compile(engine);
 
337
        if (rc) {
 
338
            fprintf(stderr,"Unable to compile engine: %s\n", cl_strerror(rc));
 
339
            optfree(opts);
 
340
            exit(4);
 
341
        }
320
342
        rc = cli_bytecode_prepare(&bcs, BYTECODE_ENGINE_MASK);
321
343
        if (rc != CL_SUCCESS) {
322
344
            fprintf(stderr,"Unable to prepare bytecode: %s\n", cl_strerror(rc));
323
345
            optfree(opts);
324
346
            exit(4);
325
347
        }
326
 
        if (cli_debug_flag)
 
348
        if (debug_flag)
327
349
            printf("[clambc] Bytecode prepared\n");
328
350
 
329
351
        ctx = cli_bytecode_context_alloc();
331
353
            fprintf(stderr,"Out of memory\n");
332
354
            exit(3);
333
355
        }
 
356
        ctx->ctx = &cctx;
 
357
        cctx.engine = engine;
 
358
        cctx.fmap = cli_calloc(sizeof(fmap_t*), engine->maxreclevel+2);
 
359
        if (!cctx.fmap) {
 
360
            fprintf(stderr,"Out of memory\n");
 
361
            exit(3);
 
362
        }
334
363
        memset(&dbg_state, 0, sizeof(dbg_state));
335
364
        dbg_state.file = "<libclamav>";
336
365
        dbg_state.line = 0;
347
376
            funcid = atoi(opts->filename[1]);
348
377
        }
349
378
        cli_bytecode_context_setfuncid(ctx, bc, funcid);
350
 
        if (cli_debug_flag)
 
379
        if (debug_flag)
351
380
            printf("[clambc] Running bytecode function :%u\n", funcid);
352
381
 
353
382
        if (opts->filename[1]) {
371
400
            map = fmap(fd, 0, 0);
372
401
            if (!map) {
373
402
                fprintf(stderr, "Unable to map input file %s\n", opt->strarg);
 
403
                exit(5);
374
404
            }
375
405
            rc = cli_bytecode_context_setfile(ctx, map);
376
406
            if (rc != CL_SUCCESS) {
381
411
        }
382
412
        /* for testing */
383
413
        ctx->hooks.match_counts = deadbeefcounts;
 
414
        ctx->hooks.match_offsets = deadbeefcounts;
384
415
        rc = cli_bytecode_run(&bcs, bc, ctx);
385
416
        if (rc != CL_SUCCESS) {
386
417
            fprintf(stderr,"Unable to run bytecode: %s\n", cl_strerror(rc));
387
418
        } else {
388
419
            uint64_t v;
389
 
            if (cli_debug_flag)
 
420
            if (debug_flag)
390
421
                printf("[clambc] Bytecode run finished\n");
391
422
            v = cli_bytecode_context_getresult_int(ctx);
392
 
            if (cli_debug_flag)
 
423
            if (debug_flag)
393
424
                printf("[clambc] Bytecode returned: 0x%llx\n", (long long)v);
394
425
        }
395
426
        cli_bytecode_context_destroy(ctx);
396
427
        if (map)
397
428
            funmap(map);
 
429
        cl_engine_free(engine);
 
430
        free(cctx.fmap);
398
431
    }
399
432
    cli_bytecode_destroy(bc);
400
433
    cli_bytecode_done(&bcs);
402
435
    optfree(opts);
403
436
    if (fd != -1)
404
437
        close(fd);
405
 
    if (cli_debug_flag)
 
438
    if (debug_flag)
406
439
        printf("[clambc] Exiting\n");
407
440
    return 0;
408
441
}