~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to clamscan/manager.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:
48
48
#include <errno.h>
49
49
#include <target.h>
50
50
 
 
51
#include <openssl/ssl.h>
 
52
#include <openssl/err.h>
 
53
#include "libclamav/crypto.h"
 
54
 
51
55
#include "manager.h"
52
56
#include "global.h"
53
57
 
67
71
dev_t procdev;
68
72
#endif
69
73
 
 
74
char hostid[37];
 
75
 
 
76
char *get_hostid(void *cbdata);
 
77
 
70
78
#ifdef _WIN32
71
79
/* FIXME: If possible, handle users correctly */
72
80
static int checkaccess(const char *path, const char *username, int mode)
567
575
        return 2;
568
576
    }
569
577
 
 
578
    if (optget(opts, "disable-cache")->enabled)
 
579
        cl_engine_set_num(engine, CL_ENGINE_DISABLE_CACHE, 1);
 
580
 
 
581
    if (optget(opts, "disable-pe-stats")->enabled) {
 
582
        cl_engine_set_num(engine, CL_ENGINE_DISABLE_PE_STATS, 1);
 
583
    }
 
584
 
 
585
    if (optget(opts, "enable-stats")->enabled) {
 
586
        cl_engine_stats_enable(engine);
 
587
    }
 
588
 
 
589
    if (optget(opts, "stats-timeout")->enabled) {
 
590
        cl_engine_set_num(engine, CL_ENGINE_STATS_TIMEOUT, optget(opts, "StatsTimeout")->numarg);
 
591
    }
 
592
 
 
593
    if (optget(opts, "stats-host-id")->enabled) {
 
594
        char *p = optget(opts, "stats-host-id")->strarg;
 
595
 
 
596
        if (strcmp(p, "default")) {
 
597
            if (!strcmp(p, "none")) {
 
598
                cl_engine_set_clcb_stats_get_hostid(engine, NULL);
 
599
            } else if (!strcmp(p, "anonymous")) {
 
600
                strcpy(hostid, STATS_ANON_UUID);
 
601
            } else {
 
602
                if (strlen(p) > 36) {
 
603
                    logg("!Invalid HostID\n");
 
604
                    cl_engine_set_clcb_stats_submit(engine, NULL);
 
605
                    cl_engine_free(engine);
 
606
                    return 2;
 
607
                }
 
608
 
 
609
                strcpy(hostid, p);
 
610
            }
 
611
 
 
612
            cl_engine_set_clcb_stats_get_hostid(engine, get_hostid);
 
613
        }
 
614
    }
 
615
 
570
616
    if(optget(opts, "detect-pua")->enabled) {
571
617
        dboptions |= CL_DB_PUA;
572
618
        if((opt = optget(opts, "exclude-pua"))->enabled) {
789
835
        }
790
836
    }
791
837
 
 
838
    if((opt = optget(opts, "max-partitions"))->active) {
 
839
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_PARTITIONS, opt->numarg))) {
 
840
            logg("!cli_engine_set_num(CL_ENGINE_MAX_PARTITIONS) failed: %s\n", cl_strerror(ret));
 
841
            cl_engine_free(engine);
 
842
            return 2;
 
843
        }
 
844
    }
 
845
 
 
846
    if((opt = optget(opts, "max-iconspe"))->active) {
 
847
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_ICONSPE, opt->numarg))) {
 
848
            logg("!cli_engine_set_num(CL_ENGINE_MAX_ICONSPE) failed: %s\n", cl_strerror(ret));
 
849
            cl_engine_free(engine);
 
850
            return 2;
 
851
        }
 
852
    }
 
853
 
792
854
    /* set scan options */
793
855
    if(optget(opts, "allmatch")->enabled)
794
856
        options |= CL_SCAN_ALLMATCHES;
799
861
    if(optget(opts,"phishing-cloak")->enabled)
800
862
        options |= CL_SCAN_PHISHING_BLOCKCLOAK;
801
863
 
 
864
    if(optget(opts,"partition-intersection")->enabled)
 
865
        options |= CL_SCAN_PARTITION_INTXN;
 
866
 
802
867
    if(optget(opts,"heuristic-scan-precedence")->enabled)
803
868
        options |= CL_SCAN_HEURISTIC_PRECEDENCE;
804
869
 
965
1030
 
966
1031
    return ret;
967
1032
}
 
1033
 
 
1034
int is_valid_hostid(void)
 
1035
{
 
1036
    int count, i;
 
1037
 
 
1038
    if (strlen(hostid) != 36)
 
1039
        return 0;
 
1040
 
 
1041
    count=0;
 
1042
    for (i=0; i < 36; i++)
 
1043
        if (hostid[i] == '-')
 
1044
            count++;
 
1045
 
 
1046
    if (count != 4)
 
1047
        return 0;
 
1048
 
 
1049
    if (hostid[8] != '-' || hostid[13] != '-' || hostid[18] != '-' || hostid[23] != '-')
 
1050
        return 0;
 
1051
 
 
1052
    return 1;
 
1053
}
 
1054
 
 
1055
char *get_hostid(void *cbdata)
 
1056
{
 
1057
    if (!strcmp(hostid, "none"))
 
1058
        return NULL;
 
1059
 
 
1060
    if (!is_valid_hostid())
 
1061
        return strdup(STATS_ANON_UUID);
 
1062
 
 
1063
    logg("HostID is valid: %s\n", hostid);
 
1064
 
 
1065
    return strdup(hostid);
 
1066
}