libclamav/others.c: move cli_gentemp*() to others_common.c

clamav-milter: don't link to libclamav (bb#1463)


git-svn: trunk@4938
0.95
Tomasz Kojm 16 years ago
parent 2f4e80d8b1
commit 20473dece8
  1. 5
      ChangeLog
  2. 3
      clamav-milter/Makefile.am
  3. 4
      clamav-milter/Makefile.in
  4. 4
      libclamav/Makefile.am
  5. 32
      libclamav/Makefile.in
  6. 123
      libclamav/others.c
  7. 117
      libclamav/others_common.c

@ -1,3 +1,8 @@
Fri Mar 13 11:58:38 CET 2009 (tk)
---------------------------------
* libclamav/others.c: move cli_gentemp*() to others_common.c
* clamav-milter: don't link to libclamav (bb#1463)
Thu Mar 12 18:00:35 EET 2009 (edwin)
------------------------------------
* libclamav/others_common.c: add missing ifdefs

@ -44,7 +44,8 @@ man_MANS = $(top_builddir)/docs/man/clamav-milter.8
endif
endif
DEFS = @DEFS@ -DCL_NOLIBCLAMAV
CFLAGS=`echo "@CFLAGS@" | sed -e 's/-Wwrite-strings//' -e 's/-Werror /-Werror -Wno-error=format-nonliteral /'`
LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@
LIBS = $(top_builddir)/libclamav/libclamav_internal_utils.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@
AM_CPPFLAGS = -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav -I$(top_srcdir)/shared -I$(top_srcdir)
CLEANFILES=*.gcda *.gcno

@ -135,7 +135,7 @@ CURSES_CPPFLAGS = @CURSES_CPPFLAGS@
CURSES_LIBS = @CURSES_LIBS@
CYGPATH_W = @CYGPATH_W@
DBDIR = @DBDIR@
DEFS = @DEFS@
DEFS = @DEFS@ -DCL_NOLIBCLAMAV
DEPDIR = @DEPDIR@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
@ -170,7 +170,7 @@ LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
LIBLTDL = @LIBLTDL@
LIBOBJS = @LIBOBJS@
LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@
LIBS = $(top_builddir)/libclamav/libclamav_internal_utils.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@

@ -76,6 +76,8 @@ endif
libclamav_internal_utils_la_SOURCES=str.c \
str.h \
md5.c \
md5.h \
others_common.c \
others.h \
regex/strlcpy.c \
@ -116,8 +118,6 @@ libclamav_la_SOURCES = \
matcher-bm.h \
matcher.c \
matcher.h \
md5.c \
md5.h \
others.c \
others.h \
readdb.c \

@ -92,10 +92,10 @@ libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
@ENABLE_UNRAR_TRUE@am__DEPENDENCIES_1 = libclamunrar_iface.la
am_libclamav_la_OBJECTS = matcher-ac.lo matcher-bm.lo matcher.lo \
md5.lo others.lo readdb.lo cvd.lo dsig.lo scanners.lo \
textdet.lo filetypes.lo rtf.lo blob.lo mbox.lo message.lo \
table.lo text.lo ole2_extract.lo vba_extract.lo msexpand.lo \
pe.lo disasm.lo upx.lo htmlnorm.lo chmunpack.lo rebuildpe.lo \
others.lo readdb.lo cvd.lo dsig.lo scanners.lo textdet.lo \
filetypes.lo rtf.lo blob.lo mbox.lo message.lo table.lo \
text.lo ole2_extract.lo vba_extract.lo msexpand.lo pe.lo \
disasm.lo upx.lo htmlnorm.lo chmunpack.lo rebuildpe.lo \
petite.lo wwunpack.lo unsp.lo aspack.lo packlibs.lo fsg.lo \
mew.lo upack.lo line.lo untar.lo unzip.lo inflate64.lo \
special.lo binhex.lo is_tar.lo tnef.lo autoit.lo unarj.lo \
@ -110,7 +110,7 @@ libclamav_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libclamav_la_LDFLAGS) $(LDFLAGS) -o $@
libclamav_internal_utils_la_LIBADD =
am__libclamav_internal_utils_la_SOURCES_DIST = str.c str.h \
am__libclamav_internal_utils_la_SOURCES_DIST = str.c str.h md5.c md5.h \
others_common.c others.h regex/strlcpy.c regex/regcomp.c \
regex/regerror.c regex/regexec.c regex/regfree.c \
regex/cclass.h regex/cname.h regex/regex.h regex/regex2.h \
@ -119,6 +119,7 @@ am__libclamav_internal_utils_la_SOURCES_DIST = str.c str.h \
@LINK_TOMMATH_FALSE@ libclamav_internal_utils_la-bignum.lo
am_libclamav_internal_utils_la_OBJECTS = \
libclamav_internal_utils_la-str.lo \
libclamav_internal_utils_la-md5.lo \
libclamav_internal_utils_la-others_common.lo \
libclamav_internal_utils_la-strlcpy.lo \
libclamav_internal_utils_la-regcomp.lo \
@ -389,11 +390,11 @@ EXTRA_DIST = $(am__append_4) regex/engine.c libclamav.map \
@ENABLE_UNRAR_TRUE@IFACELIBADD = -dlopen libclamunrar_iface.la
@ENABLE_UNRAR_TRUE@IFACEDEP = libclamunrar_iface.la
libclamav_internal_utils_la_SOURCES = str.c str.h others_common.c \
others.h regex/strlcpy.c regex/regcomp.c regex/regerror.c \
regex/regexec.c regex/regfree.c regex/cclass.h regex/cname.h \
regex/regex.h regex/regex2.h regex/utils.h bignum.h \
$(am__append_6)
libclamav_internal_utils_la_SOURCES = str.c str.h md5.c md5.h \
others_common.c others.h regex/strlcpy.c regex/regcomp.c \
regex/regerror.c regex/regexec.c regex/regfree.c \
regex/cclass.h regex/cname.h regex/regex.h regex/regex2.h \
regex/utils.h bignum.h $(am__append_6)
libclamav_internal_utils_la_LDFLAGS = -static
libclamav_internal_utils_la_CFLAGS = -fPIC -DPIC
libclamav_la_LIBADD = @LIBLTDL@ $(IFACELIBADD) lzma/liblzma.la libclamav_internal_utils.la @LIBCLAMAV_LIBS@ @THREAD_LIBS@
@ -409,8 +410,6 @@ libclamav_la_SOURCES = \
matcher-bm.h \
matcher.c \
matcher.h \
md5.c \
md5.h \
others.c \
others.h \
readdb.c \
@ -679,6 +678,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_tar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/js-norm.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-bignum.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-md5.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-others_common.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-regcomp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-regerror.Plo@am__quote@
@ -692,7 +692,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/matcher-bm.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/matcher.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbox.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/message.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mew.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpool.Plo@am__quote@
@ -801,6 +800,13 @@ libclamav_internal_utils_la-str.lo: str.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_la-str.lo `test -f 'str.c' || echo '$(srcdir)/'`str.c
libclamav_internal_utils_la-md5.lo: md5.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_la-md5.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_la-md5.Tpo -c -o libclamav_internal_utils_la-md5.lo `test -f 'md5.c' || echo '$(srcdir)/'`md5.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libclamav_internal_utils_la-md5.Tpo $(DEPDIR)/libclamav_internal_utils_la-md5.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='md5.c' object='libclamav_internal_utils_la-md5.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_la-md5.lo `test -f 'md5.c' || echo '$(srcdir)/'`md5.c
libclamav_internal_utils_la-others_common.lo: others_common.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_la-others_common.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_la-others_common.Tpo -c -o libclamav_internal_utils_la-others_common.lo `test -f 'others_common.c' || echo '$(srcdir)/'`others_common.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libclamav_internal_utils_la-others_common.Tpo $(DEPDIR)/libclamav_internal_utils_la-others_common.Plo

@ -58,12 +58,6 @@
#include <crtdbg.h>
#endif
#ifdef CL_THREAD_SAFE
# include <pthread.h>
static pthread_mutex_t cli_gentemp_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
#include <limits.h>
#include <stddef.h>
@ -87,8 +81,6 @@ static pthread_mutex_t cli_gentemp_mutex = PTHREAD_MUTEX_INITIALIZER;
#define P_tmpdir "C:\\WINDOWS\\TEMP"
#endif
static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 };
int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname);
int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname);
@ -592,121 +584,6 @@ char *cli_md5file(const char *filename)
return md5str;
}
static char *cli_md5buff(const unsigned char *buffer, unsigned int len, unsigned char *dig)
{
unsigned char digest[16];
char *md5str, *pt;
cli_md5_ctx ctx;
int i;
cli_md5_init(&ctx);
cli_md5_update(&ctx, buffer, len);
cli_md5_final(digest, &ctx);
if(dig)
memcpy(dig, digest, 16);
if(!(md5str = (char *) cli_calloc(32 + 1, sizeof(char))))
return NULL;
pt = md5str;
for(i = 0; i < 16; i++) {
sprintf(pt, "%02x", digest[i]);
pt += 2;
}
return md5str;
}
unsigned int cli_rndnum(unsigned int max)
{
if(name_salt[0] == 16) { /* minimizes re-seeding after the first call to cli_gentemp() */
struct timeval tv;
gettimeofday(&tv, (struct timezone *) 0);
srand(tv.tv_usec+clock());
}
return 1 + (unsigned int) (max * (rand() / (1.0 + RAND_MAX)));
}
char *cli_gentemp(const char *dir)
{
char *name, *tmp;
const char *mdir;
unsigned char salt[16 + 32];
int i;
if(!dir) {
if((mdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
mdir = P_tmpdir;
#else
mdir = "/tmp";
#endif
} else
mdir = dir;
name = (char *) cli_calloc(strlen(mdir) + 1 + 32 + 1 + 7, sizeof(char));
if(!name) {
cli_dbgmsg("cli_gentemp('%s'): out of memory\n", mdir);
return NULL;
}
#ifdef CL_THREAD_SAFE
pthread_mutex_lock(&cli_gentemp_mutex);
#endif
memcpy(salt, name_salt, 16);
for(i = 16; i < 48; i++)
salt[i] = cli_rndnum(255);
tmp = cli_md5buff(salt, 48, name_salt);
#ifdef CL_THREAD_SAFE
pthread_mutex_unlock(&cli_gentemp_mutex);
#endif
if(!tmp) {
free(name);
cli_dbgmsg("cli_gentemp('%s'): out of memory\n", mdir);
return NULL;
}
#ifdef C_WINDOWS
sprintf(name, "%s\\clamav-", mdir);
#else
sprintf(name, "%s/clamav-", mdir);
#endif
strncat(name, tmp, 32);
free(tmp);
return(name);
}
int cli_gentempfd(const char *dir, char **name, int *fd)
{
*name = cli_gentemp(dir);
if(!*name)
return CL_EMEM;
*fd = open(*name, O_RDWR|O_CREAT|O_TRUNC|O_BINARY|O_EXCL, S_IRWXU);
/*
* EEXIST is almost impossible to occur, so we just treat it as other
* errors
*/
if(*fd == -1) {
char err[128];
cli_errmsg("cli_gentempfd: Can't create temporary file %s: %s\n", *name, cli_strerror(errno, err, sizeof(err)));
free(*name);
return CL_ECREAT;
}
return CL_SUCCESS;
}
/* Function: unlink
unlink() with error checking
*/

@ -65,14 +65,18 @@
#include "regex/regex.h"
#include "ltdl.h"
#include "matcher-ac.h"
#include "md5.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 };
#ifdef CL_THREAD_SAFE
# include <pthread.h>
static pthread_mutex_t cli_gentemp_mutex = PTHREAD_MUTEX_INITIALIZER;
# ifndef HAVE_CTIME_R
static pthread_mutex_t cli_ctime_mutex = PTHREAD_MUTEX_INITIALIZER;
# endif
@ -699,3 +703,116 @@ const char* cli_strerror(int errnum, char *buf, size_t len)
return buf;
}
static char *cli_md5buff(const unsigned char *buffer, unsigned int len, unsigned char *dig)
{
unsigned char digest[16];
char *md5str, *pt;
cli_md5_ctx ctx;
int i;
cli_md5_init(&ctx);
cli_md5_update(&ctx, buffer, len);
cli_md5_final(digest, &ctx);
if(dig)
memcpy(dig, digest, 16);
if(!(md5str = (char *) cli_calloc(32 + 1, sizeof(char))))
return NULL;
pt = md5str;
for(i = 0; i < 16; i++) {
sprintf(pt, "%02x", digest[i]);
pt += 2;
}
return md5str;
}
unsigned int cli_rndnum(unsigned int max)
{
if(name_salt[0] == 16) { /* minimizes re-seeding after the first call to cli_gentemp() */
struct timeval tv;
gettimeofday(&tv, (struct timezone *) 0);
srand(tv.tv_usec+clock());
}
return 1 + (unsigned int) (max * (rand() / (1.0 + RAND_MAX)));
}
char *cli_gentemp(const char *dir)
{
char *name, *tmp;
const char *mdir;
unsigned char salt[16 + 32];
int i;
if(!dir) {
if((mdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
mdir = P_tmpdir;
#else
mdir = "/tmp";
#endif
} else
mdir = dir;
name = (char *) cli_calloc(strlen(mdir) + 1 + 32 + 1 + 7, sizeof(char));
if(!name) {
cli_dbgmsg("cli_gentemp('%s'): out of memory\n", mdir);
return NULL;
}
#ifdef CL_THREAD_SAFE
pthread_mutex_lock(&cli_gentemp_mutex);
#endif
memcpy(salt, name_salt, 16);
for(i = 16; i < 48; i++)
salt[i] = cli_rndnum(255);
tmp = cli_md5buff(salt, 48, name_salt);
#ifdef CL_THREAD_SAFE
pthread_mutex_unlock(&cli_gentemp_mutex);
#endif
if(!tmp) {
free(name);
cli_dbgmsg("cli_gentemp('%s'): out of memory\n", mdir);
return NULL;
}
#ifdef C_WINDOWS
sprintf(name, "%s\\clamav-", mdir);
#else
sprintf(name, "%s/clamav-", mdir);
#endif
strncat(name, tmp, 32);
free(tmp);
return(name);
}
int cli_gentempfd(const char *dir, char **name, int *fd)
{
*name = cli_gentemp(dir);
if(!*name)
return CL_EMEM;
*fd = open(*name, O_RDWR|O_CREAT|O_TRUNC|O_BINARY|O_EXCL, S_IRWXU);
/*
* EEXIST is almost impossible to occur, so we just treat it as other
* errors
*/
if(*fd == -1) {
cli_errmsg("cli_gentempfd: Can't create temporary file %s: %s\n", *name, strerror(errno));
free(*name);
return CL_ECREAT;
}
return CL_SUCCESS;
}

Loading…
Cancel
Save