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

« back to all changes in this revision

Viewing changes to freshclam/freshclam.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:
46
46
#include <syslog.h>
47
47
#endif
48
48
 
 
49
#include <openssl/ssl.h>
 
50
#include <openssl/err.h>
 
51
#include "libclamav/crypto.h"
 
52
 
49
53
#include "target.h"
50
54
#include "clamav.h"
51
55
#include "freshclamcodes.h"
68
72
char updtmpdir[512], dbdir[512];
69
73
int sigchld_wait = 1;
70
74
const char *pidfile = NULL;
 
75
char hostid[37];
 
76
 
 
77
void submit_host_info(struct optstruct *opts);
 
78
char *get_hostid(void *cbdata);
71
79
 
72
80
static void
73
81
sighandler (int sig)
130
138
    }
131
139
    else
132
140
    {
133
 
        fprintf (fd, "%d", (int) getpid ());
 
141
        fprintf (fd, "%d\n", (int) getpid ());
134
142
        fclose (fd);
135
143
    }
136
144
    umask (old_umask);
190
198
    mprintf
191
199
        ("    --list-mirrors                       print mirrors from mirrors.dat\n");
192
200
    mprintf
193
 
        ("    --submit-stats[=/path/clamd.conf]    only submit detection statistics\n");
 
201
        ("    --enable-stats                       enable statistical information reporting\n");
 
202
    mprintf
 
203
        ("    --stats-host-id=UUID                 HostID in the form of an UUID to use when submitting statistical information\n");
194
204
    mprintf
195
205
        ("    --update-db=DBNAME                   only update database DBNAME\n");
196
206
 
331
341
        return 0;
332
342
    }
333
343
 
 
344
    /* Stats/intelligence gathering  */
 
345
    if (optget(opts, "stats-host-id")->enabled) {
 
346
        char *p = optget(opts, "stats-host-id")->strarg;
 
347
 
 
348
        if (strcmp(p, "default")) {
 
349
            if (!strcmp(p, "anonymous")) {
 
350
                strcpy(hostid, STATS_ANON_UUID);
 
351
            } else {
 
352
                if (strlen(p) > 36) {
 
353
                    logg("!Invalid HostID\n");
 
354
                    optfree(opts);
 
355
                    return FCE_INIT;
 
356
                }
 
357
 
 
358
                strcpy(hostid, p);
 
359
            }
 
360
        } else {
 
361
            strcpy(hostid, "default");
 
362
        }
 
363
    }
 
364
    submit_host_info(opts);
 
365
 
334
366
    if (optget (opts, "HTTPProxyPassword")->enabled)
335
367
    {
336
368
        if (CLAMSTAT (cfgfile, &statbuf) == -1)
635
667
        {
636
668
            ret = download (opts, cfgfile);
637
669
 
638
 
            if (ret <= 1)
639
 
            {
640
 
                if ((opt = optget (opts, "SubmitDetectionStats"))->enabled)
641
 
                    submitstats (opt->strarg, opts);
642
 
            }
643
 
            else
 
670
            if (ret > 1)
644
671
            {
645
672
                if ((opt = optget (opts, "OnErrorExecute"))->enabled)
646
673
                    arg = opt->strarg;
696
723
    }
697
724
    else
698
725
    {
699
 
        if ((opt = optget (opts, "submit-stats"))->active)
700
 
        {
701
 
            if (!optget (opts, "no-warnings")->enabled)
702
 
                logg (" *** Virus databases are not updated in this mode ***\n");
703
 
            ret = submitstats (opt->strarg, opts);
704
 
        }
705
 
        else
706
 
        {
707
 
            ret = download (opts, cfgfile);
708
 
 
709
 
            if ((opt = optget (opts, "SubmitDetectionStats"))->enabled)
710
 
                submitstats (opt->strarg, opts);
711
 
        }
 
726
        ret = download (opts, cfgfile);
712
727
    }
713
728
 
714
729
    if (ret > 1)
724
739
 
725
740
    optfree (opts);
726
741
 
 
742
    cl_cleanup_crypto();
 
743
 
727
744
    return (ret);
728
745
}
 
746
 
 
747
void submit_host_info(struct optstruct *opts)
 
748
{
 
749
    struct optstruct *opt;
 
750
    struct cl_engine *engine;
 
751
    cli_intel_t *intel;
 
752
 
 
753
    if (!optget(opts, "enable-stats")->enabled)
 
754
        return;
 
755
 
 
756
    engine = cl_engine_new();
 
757
    if (!(engine))
 
758
        return;
 
759
 
 
760
    if (optget (opts, "Debug")->enabled || optget (opts, "debug")->enabled)
 
761
        cl_debug ();
 
762
 
 
763
    if (optget (opts, "verbose")->enabled)
 
764
        mprintf_verbose = 1;
 
765
 
 
766
    cl_engine_stats_enable(engine);
 
767
 
 
768
    intel = engine->stats_data;
 
769
    if (!(intel)) {
 
770
        engine->cb_stats_submit = NULL;
 
771
        cl_engine_free(engine);
 
772
        return;
 
773
    }
 
774
 
 
775
    intel->host_info = calloc(1, strlen(TARGET_OS_TYPE) + strlen(TARGET_ARCH_TYPE) + 2);
 
776
    if (!(intel->host_info)) {
 
777
        engine->cb_stats_submit = NULL;
 
778
        cl_engine_free(engine);
 
779
        return;
 
780
    }
 
781
 
 
782
    sprintf(intel->host_info, "%s %s", TARGET_OS_TYPE, TARGET_ARCH_TYPE);
 
783
 
 
784
    if (!strcmp(hostid, "none"))
 
785
        cl_engine_set_clcb_stats_get_hostid(engine, NULL);
 
786
    else if (strcmp(hostid, "default"))
 
787
        cl_engine_set_clcb_stats_get_hostid(engine, get_hostid);
 
788
 
 
789
    if (optget(opts, "stats-timeout")->enabled) {
 
790
        cl_engine_set_num(engine, CL_ENGINE_STATS_TIMEOUT, optget(opts, "StatsTimeout")->numarg);
 
791
    }
 
792
 
 
793
    cl_engine_free(engine);
 
794
}
 
795
 
 
796
int is_valid_hostid(void)
 
797
{
 
798
    int count, i;
 
799
 
 
800
    if (strlen(hostid) != 36)
 
801
        return 0;
 
802
 
 
803
    count=0;
 
804
    for (i=0; i < 36; i++)
 
805
        if (hostid[i] == '-')
 
806
            count++;
 
807
 
 
808
    if (count != 4)
 
809
        return 0;
 
810
 
 
811
    if (hostid[8] != '-' || hostid[13] != '-' || hostid[18] != '-' || hostid[23] != '-')
 
812
        return 0;
 
813
 
 
814
    return 1;
 
815
}
 
816
 
 
817
char *get_hostid(void *cbdata)
 
818
{
 
819
    if (!strcmp(hostid, "none"))
 
820
        return NULL;
 
821
 
 
822
    if (!is_valid_hostid())
 
823
        return strdup(STATS_ANON_UUID);
 
824
 
 
825
    logg("HostID is valid: %s\n", hostid);
 
826
 
 
827
    return strdup(hostid);
 
828
}