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

« back to all changes in this revision

Viewing changes to clamd/others.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:
65
65
#endif /* HAVE_POLL_H */
66
66
#endif /* HAVE_POLL */
67
67
 
 
68
#include <openssl/ssl.h>
 
69
#include <openssl/err.h>
 
70
#include "libclamav/crypto.h"
 
71
 
68
72
#include <limits.h>
69
73
#include "shared/optparser.h"
70
74
#include "shared/output.h"
75
79
#include "others.h"
76
80
 
77
81
static pthread_mutex_t virusaction_lock = PTHREAD_MUTEX_INITIALIZER;
78
 
static pthread_mutex_t detstats_lock = PTHREAD_MUTEX_INITIALIZER;
79
82
 
80
83
static void xfree(void *p)
81
84
{
798
801
    fds_unlock (data);
799
802
}
800
803
 
801
 
struct detstats_s
802
 
{
803
 
    char virname[128];
804
 
    char fname[128];
805
 
    char md5[33];
806
 
    unsigned int fsize;
807
 
    unsigned int time;
808
 
};
809
 
#define DETSTATS_MAX 50
810
 
static struct detstats_s detstats_data[DETSTATS_MAX];
811
 
static unsigned int detstats_idx = 0, detstats_total = 0;
812
 
 
813
 
void
814
 
detstats_clear (void)
815
 
{
816
 
    pthread_mutex_lock (&detstats_lock);
817
 
    detstats_idx = detstats_total = 0;
818
 
    pthread_mutex_unlock (&detstats_lock);
819
 
}
820
 
 
821
 
void
822
 
detstats_add (const char *virname, const char *fname, unsigned int fsize,
823
 
              const char *md5)
824
 
{
825
 
    pthread_mutex_lock (&detstats_lock);
826
 
 
827
 
    strncpy (detstats_data[detstats_idx].virname, virname,
828
 
             sizeof (detstats_data[detstats_idx].virname));
829
 
    detstats_data[detstats_idx].
830
 
        virname[sizeof (detstats_data[detstats_idx].virname) - 1] = 0;
831
 
 
832
 
    if ((fname = strrchr (fname, *PATHSEP)))
833
 
        fname++;
834
 
    strncpy (detstats_data[detstats_idx].fname,
835
 
             (!fname
836
 
              || !strlen (fname)) ? "NOFNAME" : fname,
837
 
             sizeof (detstats_data[detstats_idx].fname));
838
 
    detstats_data[detstats_idx].
839
 
        fname[sizeof (detstats_data[detstats_idx].fname) - 1] = 0;
840
 
 
841
 
    strncpy (detstats_data[detstats_idx].md5, md5,
842
 
             sizeof (detstats_data[detstats_idx].md5));
843
 
    detstats_data[detstats_idx].md5[sizeof (detstats_data[detstats_idx].md5) -
844
 
                                    1] = 0;
845
 
 
846
 
    detstats_data[detstats_idx].fsize = fsize;
847
 
    detstats_data[detstats_idx++].time = time (NULL);
848
 
    if (detstats_idx == DETSTATS_MAX)
849
 
        detstats_idx = 0;
850
 
    detstats_total++;
851
 
    pthread_mutex_unlock (&detstats_lock);
852
 
}
853
 
 
854
 
void
855
 
detstats_print (int desc, char term)
856
 
{
857
 
    unsigned int i;
858
 
 
859
 
    pthread_mutex_lock (&detstats_lock);
860
 
    for (i = 0; i < DETSTATS_MAX && i < detstats_total; i++)
861
 
        mdprintf (desc, "%u:%s:%u:%s:%s%c", detstats_data[i].time,
862
 
                  detstats_data[i].md5, detstats_data[i].fsize,
863
 
                  detstats_data[i].virname, detstats_data[i].fname, term);
864
 
    pthread_mutex_unlock (&detstats_lock);
865
 
}
866
 
 
867
804
#ifdef FANOTIFY
868
805
int
869
806
fan_checkowner (int pid, const struct optstruct *opts)