Ignore:
Timestamp:
Apr 19, 2011, 11:12:07 PM (14 years ago)
Author:
Yuri Dario
Message:

clamav: update trunk to 0.97.

Location:
clamav/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • clamav/trunk

  • TabularUnified clamav/trunk/libclamav/others.c

    r191 r319  
    6161#include "others.h"
    6262#include "md5.h"
     63#include "sha1.h"
     64#include "sha256.h"
    6365#include "cltypes.h"
    6466#include "regex/regex.h"
     
    255257            return "CL_EFORMAT: Bad format or broken data";
    256258        case CL_EBYTECODE:
    257             return "CL_EBYTECODE: error during bytecode execution";
     259            return "Error during bytecode execution";
    258260        case CL_EBYTECODE_TESTFAIL:
    259             return "CL_EBYTECODE_TESTFAIL: failure in bytecode testmode";
     261            return "Failure in bytecode testmode";
     262        case CL_ELOCK:
     263            return "Mutex lock failed";
     264        case CL_EBUSY:
     265            return "Scanner still active";
     266        case CL_ESTATE:
     267            return "Bad state (engine not initialized, or already initialized)";
    260268        default:
    261269            return "Unknown error code";
     
    434442            if (num == CL_BYTECODE_MODE_OFF) {
    435443                cli_errmsg("cl_engine_set_num: CL_BYTECODE_MODE_OFF is not settable, use dboptions to turn off!\n");
     444                return CL_EARG;
    436445            }
    437446            engine->bytecode_mode = num;
     447            if (num == CL_BYTECODE_MODE_TEST)
     448                cli_infomsg(NULL, "bytecode engine in test mode\n");
    438449            break;
    439450        default:
     
    566577    settings->min_cc_count = engine->min_cc_count;
    567578    settings->min_ssn_count = engine->min_ssn_count;
     579    settings->bytecode_security = engine->bytecode_security;
     580    settings->bytecode_timeout = engine->bytecode_timeout;
     581    settings->bytecode_mode = engine->bytecode_mode;
    568582    settings->pua_cats = engine->pua_cats ? strdup(engine->pua_cats) : NULL;
     583
     584    settings->cb_pre_scan = engine->cb_pre_scan;
     585    settings->cb_post_scan = engine->cb_post_scan;
     586    settings->cb_sigload = engine->cb_sigload;
     587    settings->cb_sigload_ctx = engine->cb_sigload_ctx;
     588    settings->cb_hash = engine->cb_hash;
    569589
    570590    return settings;
     
    583603    engine->min_cc_count = settings->min_cc_count;
    584604    engine->min_ssn_count = settings->min_ssn_count;
     605    engine->bytecode_security = settings->bytecode_security;
     606    engine->bytecode_timeout = settings->bytecode_timeout;
     607    engine->bytecode_mode = settings->bytecode_mode;
    585608
    586609    if(engine->tmpdir)
     
    604627    }
    605628
     629    engine->cb_pre_scan = settings->cb_pre_scan;
     630    engine->cb_post_scan = settings->cb_post_scan;
     631    engine->cb_sigload = settings->cb_sigload;
     632    engine->cb_sigload_ctx = settings->cb_sigload_ctx;
     633    engine->cb_hash = settings->cb_hash;
     634
    606635    return CL_SUCCESS;
    607636}
     
    663692}
    664693
    665 unsigned char *cli_md5digest(int desc)
    666 {
    667         unsigned char *digest;
     694/*
     695 * Type: 1 = MD5, 2 = SHA1, 3 = SHA256
     696 */
     697char *cli_hashstream(FILE *fs, unsigned char *digcpy, int type)
     698{
     699        unsigned char digest[32];
    668700        char buff[FILEBUFF];
    669         cli_md5_ctx ctx;
    670         int bytes;
    671 
    672 
    673     if(!(digest = cli_malloc(16)))
     701        cli_md5_ctx md5;
     702        SHA1Context sha1;
     703        SHA256_CTX sha256;
     704        char *hashstr, *pt;
     705        int i, bytes, size;
     706
     707
     708    if(type == 1)
     709        cli_md5_init(&md5);
     710    else if(type == 2)
     711        SHA1Init(&sha1);
     712    else
     713        sha256_init(&sha256);
     714
     715    while((bytes = fread(buff, 1, FILEBUFF, fs))) {
     716        if(type == 1)
     717            cli_md5_update(&md5, buff, bytes);
     718        else if(type == 2)
     719            SHA1Update(&sha1, buff, bytes);
     720        else
     721            sha256_update(&sha256, buff, bytes);
     722    }
     723
     724    if(type == 1) {
     725        cli_md5_final(digest, &md5);
     726        size = 16;
     727    } else if(type == 2) {
     728        SHA1Final(&sha1, digest);
     729        size = 20;
     730    } else {
     731        sha256_final(&sha256, digest);
     732        size = 32;
     733    }
     734
     735    if(!(hashstr = (char *) cli_calloc(size*2 + 1, sizeof(char))))
    674736        return NULL;
    675737
    676     cli_md5_init(&ctx);
    677 
    678     while((bytes = cli_readn(desc, buff, FILEBUFF)))
    679         cli_md5_update(&ctx, buff, bytes);
    680 
    681     cli_md5_final(digest, &ctx);
    682 
    683     return digest;
    684 }
    685 
    686 char *cli_md5stream(FILE *fs, unsigned char *digcpy)
    687 {
    688         unsigned char digest[16];
    689         char buff[FILEBUFF];
    690         cli_md5_ctx ctx;
    691         char *md5str, *pt;
    692         int i, bytes;
    693 
    694 
    695     cli_md5_init(&ctx);
    696 
    697     while((bytes = fread(buff, 1, FILEBUFF, fs)))
    698         cli_md5_update(&ctx, buff, bytes);
    699 
    700     cli_md5_final(digest, &ctx);
    701 
    702     if(!(md5str = (char *) cli_calloc(32 + 1, sizeof(char))))
    703         return NULL;
    704 
    705     pt = md5str;
    706     for(i = 0; i < 16; i++) {
     738    pt = hashstr;
     739    for(i = 0; i < size; i++) {
    707740        sprintf(pt, "%02x", digest[i]);
    708741        pt += 2;
     
    710743
    711744    if(digcpy)
    712         memcpy(digcpy, digest, 16);
    713 
    714     return md5str;
    715 }
    716 
    717 char *cli_md5file(const char *filename)
     745        memcpy(digcpy, digest, size);
     746
     747    return hashstr;
     748}
     749
     750char *cli_hashfile(const char *filename, int type)
    718751{
    719752        FILE *fs;
    720         char *md5str;
     753        char *hashstr;
    721754
    722755
    723756    if((fs = fopen(filename, "rb")) == NULL) {
    724         cli_errmsg("cli_md5file(): Can't read file %s\n", filename);
     757        cli_errmsg("cli_hashfile(): Can't open file %s\n", filename);
    725758        return NULL;
    726759    }
    727760
    728     md5str = cli_md5stream(fs, NULL);
     761    hashstr = cli_hashstream(fs, NULL, type);
     762
    729763    fclose(fs);
    730 
    731     return md5str;
     764    return hashstr;
    732765}
    733766
     
    10651098    engine->cb_sigload_ctx = callback ? context : NULL;
    10661099}
     1100
     1101void cl_engine_set_clcb_hash(struct cl_engine *engine, clcb_hash callback)
     1102{
     1103    engine->cb_hash = callback;
     1104}
Note: See TracChangeset for help on using the changeset viewer.