~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to libclamav/others.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
 
61
61
#ifdef CL_THREAD_SAFE
62
62
#  include <pthread.h>
 
63
#ifndef CLI_MEMFUNSONLY
63
64
static pthread_mutex_t cli_gentemp_mutex = PTHREAD_MUTEX_INITIALIZER;
 
65
#endif
64
66
 
65
67
# ifndef HAVE_CTIME_R
66
68
static pthread_mutex_t cli_ctime_mutex = PTHREAD_MUTEX_INITIALIZER;
77
79
#include "others.h"
78
80
#include "md5.h"
79
81
#include "cltypes.h"
 
82
#include "regex/regex.h"
80
83
 
81
84
#ifndef O_BINARY
82
85
#define O_BINARY        0
87
90
#define       P_tmpdir        "C:\\WINDOWS\\TEMP"
88
91
#endif
89
92
 
90
 
#define CL_FLEVEL 33 /* don't touch it */
 
93
#define CL_FLEVEL 35 /* don't touch it */
91
94
 
92
95
uint8_t cli_debug_flag = 0, cli_leavetemps_flag = 0;
93
96
 
 
97
#ifndef CLI_MEMFUNSONLY
94
98
static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 };
95
 
 
 
99
#endif
96
100
 
97
101
#define MSGCODE(x)                                          \
98
102
        va_list args;                                       \
133
137
    return CL_FLEVEL;
134
138
}
135
139
 
136
 
const char *cl_retver(void)
137
 
{
138
 
    return VERSION;
139
 
}
140
 
 
141
140
const char *cl_strerror(int clerror)
142
141
{
143
142
    switch(clerror) {
167
166
            return "Unable to create temporary file";
168
167
        case CL_ETMPDIR:
169
168
            return "Unable to create temporary directory";
170
 
        case CL_EFSYNC:
171
 
            return "Unable to synchronize file <-> disk";
172
169
        case CL_EMEM:
173
170
            return "Unable to allocate memory";
174
171
        case CL_EOPEN:
193
190
            return "Bad format or broken data";
194
191
        case CL_ESUPPORT:
195
192
            return "Not supported data format";
196
 
        case CL_ELOCKDB:
197
 
            return "Unable to lock database directory";
198
193
        case CL_EARJ:
199
194
            return "ARJ module failure";
200
195
        default:
562
557
}
563
558
#endif
564
559
 
 
560
/* Function: unlink
 
561
        unlink() with error checking
 
562
*/
 
563
int cli_unlink(const char *pathname)
 
564
{
 
565
        if (unlink(pathname)==-1) {
 
566
            cli_warnmsg("cli_unlink: failure - %s\n", strerror(errno));
 
567
            return 1;
 
568
        }
 
569
        return 0;
 
570
}
 
571
 
565
572
#ifdef  C_WINDOWS
566
573
/*
567
574
 * Windows doesn't allow you to delete a directory while it is still open
587
594
    }
588
595
 
589
596
    if(!S_ISDIR(statb.st_mode)) {
590
 
        if(unlink(name) < 0) {
591
 
            cli_warnmsg("cli_rmdirs: Can't remove %s: %s\n", name, strerror(errno));
592
 
            return -1;
593
 
        }
 
597
        if(cli_unlink(name)) return -1;
594
598
        return 0;
595
599
    }
596
600
 
668
672
#else
669
673
            while((dent = readdir(dd))) {
670
674
#endif
671
 
#if     (!defined(C_CYGWIN)) && (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
 
675
#if     (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
672
676
                if(dent->d_ino)
673
677
#endif
674
678
                {
698
702
                                        return -1;
699
703
                                    }
700
704
                                }
701
 
                            } else
702
 
                                if(unlink(path) < 0) {
703
 
                                    cli_warnmsg("cli_rmdirs: Couldn't remove %s: %s\n", path, strerror(errno));
 
705
                            } else {
 
706
                                if(cli_unlink(path)) {
704
707
                                    free(path);
705
708
                                    closedir(dd);
706
709
                                    return -1;
707
710
                                }
 
711
                            }
708
712
                        }
709
713
                        free(path);
710
714
                    }
799
803
        return -1;
800
804
    }
801
805
 
802
 
    if(!(buffer = cli_malloc(FILEBUFF)))
 
806
    if(!(buffer = cli_malloc(FILEBUFF))) {
 
807
        close(s);
 
808
        close(d);
803
809
        return -1;
 
810
    }
804
811
 
805
812
    while((bytes = cli_readn(s, buffer, FILEBUFF)) > 0)
806
813
        cli_writen(d, buffer, bytes);
811
818
    return close(d);
812
819
}
813
820
 
 
821
 
814
822
/* Implement a generic bitset, trog@clamav.net */
815
823
 
816
824
#define BITS_PER_CHAR (8)
947
955
        return ret;
948
956
}
949
957
 
 
958
#ifndef CLI_MEMFUNSONLY
 
959
int cli_matchregex(const char *str, const char *regex)
 
960
{
 
961
        regex_t reg;
 
962
        int match;
 
963
 
 
964
    if(cli_regcomp(&reg, regex, REG_EXTENDED | REG_NOSUB) == 0) {
 
965
        match = (cli_regexec(&reg, str, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
 
966
        cli_regfree(&reg);
 
967
        return match;
 
968
    }
 
969
 
 
970
    return 0;
 
971
}
 
972
#endif