minor code cleanup

git-svn: trunk@2656
remotes/push_mirror/metadata
Tomasz Kojm 19 years ago
parent 7a2997f190
commit a57e3d41e1
  1. 4
      clamav-devel/ChangeLog
  2. 10
      clamav-devel/clamd/clamd.c
  3. 2
      clamav-devel/clamd/clamuko.c
  4. 2
      clamav-devel/clamd/localserver.c
  5. 20
      clamav-devel/clamd/scanner.c
  6. 8
      clamav-devel/clamd/scanner.h
  7. 50
      clamav-devel/clamd/server-th.c
  8. 8
      clamav-devel/clamd/server.h
  9. 28
      clamav-devel/clamd/session.c
  10. 2
      clamav-devel/clamd/session.h

@ -1,3 +1,7 @@
Tue Jan 30 22:25:36 CET 2007 (tk)
---------------------------------
* clamd: minor code cleanup
Tue Jan 30 22:08:22 CET 2007 (tk)
---------------------------------
* clamscan: code cleanup

@ -88,7 +88,7 @@ int main(int argc, char **argv)
struct cfgstruct *copt, *cpt;
struct passwd *user;
time_t currtime;
struct cl_node *root = NULL;
struct cl_engine *engine = NULL;
const char *dbdir, *cfgfile;
int ret, tcpsock = 0, localsock = 0;
unsigned int sigs = 0;
@ -329,14 +329,14 @@ int main(int argc, char **argv)
#endif
}
if((ret = cl_load(dbdir, &root, &sigs, dboptions))) {
if((ret = cl_load(dbdir, &engine, &sigs, dboptions))) {
logg("!%s\n", cl_strerror(ret));
logg_close();
freecfg(copt);
return 1;
}
if(!root) {
if(!engine) {
logg("!Database initialization error.\n");
logg_close();
freecfg(copt);
@ -344,7 +344,7 @@ int main(int argc, char **argv)
}
logg("#Loaded %d signatures.\n", sigs);
if((ret = cl_build(root)) != 0) {
if((ret = cl_build(engine)) != 0) {
logg("!Database initialization error: %s\n", cl_strerror(ret));;
logg_close();
freecfg(copt);
@ -383,7 +383,7 @@ int main(int argc, char **argv)
nlsockets++;
}
ret = acceptloop_th(lsockets, nlsockets, root, dboptions, copt);
ret = acceptloop_th(lsockets, nlsockets, engine, dboptions, copt);
#ifdef C_WINDOWS
if(tcpsock)

@ -169,7 +169,7 @@ void *clamukoth(void *arg)
}
}
if(scan && cl_scanfile(acc->filename, &virname, NULL, tharg->root, tharg->limits, tharg->options) == CL_VIRUS) {
if(scan && cl_scanfile(acc->filename, &virname, NULL, tharg->engine, tharg->limits, tharg->options) == CL_VIRUS) {
logg("Clamuko: %s: %s FOUND\n", acc->filename, virname);
virusaction(acc->filename, virname, tharg->copt);
acc->deny = 1;

@ -42,7 +42,7 @@
#include "output.h"
#ifdef C_WINDOWS
int localserver(const struct cfgstruct *copt, struct cl_node *root)
int localserver(const struct cfgstruct *copt)
{
logg("!Localserver is not supported on this platform");
return -1;

@ -89,7 +89,7 @@ int checksymlink(const char *path)
}
/* :set nowrap, if you don't like this style ;)) */
int dirscan(const char *dirname, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, short contscan)
int dirscan(const char *dirname, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, short contscan)
{
DIR *dd;
struct dirent *dent;
@ -139,7 +139,7 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
/* stat the file */
if(lstat(fname, &statbuf) != -1) {
if((S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) || (S_ISLNK(statbuf.st_mode) && (checksymlink(fname) == 1) && cfgopt(copt, "FollowDirectorySymlinks")->enabled)) {
if(dirscan(fname, virname, scanned, root, limits, options, copt, odesc, reclev, contscan) == 1) {
if(dirscan(fname, virname, scanned, engine, limits, options, copt, odesc, reclev, contscan) == 1) {
free(fname);
closedir(dd);
return 1;
@ -152,7 +152,7 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
scanret = CL_CLEAN;
else
#endif
scanret = cl_scanfile(fname, virname, scanned, root, limits, options);
scanret = cl_scanfile(fname, virname, scanned, engine, limits, options);
if(scanret == CL_VIRUS) {
@ -196,7 +196,7 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
}
int scan(const char *filename, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, short contscan)
int scan(const char *filename, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc, short contscan)
{
struct stat sb;
int ret = 0;
@ -233,7 +233,7 @@ int scan(const char *filename, unsigned long int *scanned, const struct cl_node
ret = CL_CLEAN;
else
#endif
ret = cl_scanfile(filename, &virname, scanned, root, limits, options);
ret = cl_scanfile(filename, &virname, scanned, engine, limits, options);
if(ret == CL_VIRUS) {
mdprintf(odesc, "%s: %s FOUND\n", filename, virname);
@ -249,7 +249,7 @@ int scan(const char *filename, unsigned long int *scanned, const struct cl_node
}
break;
case S_IFDIR:
ret = dirscan(filename, &virname, scanned, root, limits, options, copt, odesc, &reclev, contscan);
ret = dirscan(filename, &virname, scanned, engine, limits, options, copt, odesc, &reclev, contscan);
break;
default:
mdprintf(odesc, "%s: Not supported file type. ERROR\n", filename);
@ -263,7 +263,7 @@ int scan(const char *filename, unsigned long int *scanned, const struct cl_node
return ret;
}
int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc)
int scanfd(const int fd, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc)
{
int ret;
const char *virname;
@ -279,7 +279,7 @@ int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root,
snprintf(fdstr, sizeof(fdstr), "fd[%d]", fd);
ret = cl_scandesc(fd, &virname, scanned, root, limits, options);
ret = cl_scandesc(fd, &virname, scanned, engine, limits, options);
if(ret == CL_VIRUS) {
mdprintf(odesc, "%s: %s FOUND\n", fdstr, virname);
@ -297,7 +297,7 @@ int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root,
return ret;
}
int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt)
int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt)
{
int ret, portscan = 1000, sockfd, port = 0, acceptd;
int tmpd, bread, retval, timeout, btread, min_port, max_port;
@ -451,7 +451,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
if(retval == 1) {
lseek(tmpd, 0, SEEK_SET);
ret = cl_scandesc(tmpd, &virname, scanned, root, limits, options);
ret = cl_scandesc(tmpd, &virname, scanned, engine, limits, options);
} else {
ret = -1;
}

@ -23,13 +23,13 @@
#include "libclamav/clamav.h"
#include "shared/cfgparser.h"
int dirscan(const char *dirname, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, short contscan);
int dirscan(const char *dirname, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, short contscan);
int scan(const char *filename, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, short contscan);
int scan(const char *filename, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc, short contscan);
int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc);
int scanfd(const int fd, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc);
int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt);
int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt);
int checksymlink(const char *path);

@ -74,10 +74,10 @@ static struct cl_stat *dbstat = NULL;
typedef struct client_conn_tag {
int sd;
int options;
unsigned int options;
const struct cfgstruct *copt;
struct cl_node *root;
time_t root_timestamp;
struct cl_engine *engine;
time_t engine_timestamp;
const struct cl_limits *limits;
int *socketds;
int nsockets;
@ -103,7 +103,7 @@ void scanner_thread(void *arg)
timeout = -1;
do {
ret = command(conn->sd, conn->root, conn->limits, conn->options, conn->copt, timeout);
ret = command(conn->sd, conn->engine, conn->limits, conn->options, conn->copt, timeout);
if (ret < 0) {
break;
}
@ -140,7 +140,7 @@ void scanner_thread(void *arg)
}
pthread_mutex_unlock(&exit_mutex);
pthread_mutex_lock(&reload_mutex);
if (conn->root_timestamp != reloaded_time) {
if (conn->engine_timestamp != reloaded_time) {
session = FALSE;
}
pthread_mutex_unlock(&reload_mutex);
@ -148,7 +148,7 @@ void scanner_thread(void *arg)
} while (session);
closesocket(conn->sd);
cl_free(conn->root);
cl_free(conn->engine);
free(conn);
return;
}
@ -178,7 +178,7 @@ void sighandler_th(int sig)
}
}
static struct cl_node *reload_db(struct cl_node *root, unsigned int dboptions, const struct cfgstruct *copt, int do_check, int *ret)
static struct cl_engine *reload_db(struct cl_engine *engine, unsigned int dboptions, const struct cfgstruct *copt, int do_check, int *ret)
{
const char *dbdir;
int retval;
@ -188,12 +188,12 @@ static struct cl_node *reload_db(struct cl_node *root, unsigned int dboptions, c
if(do_check) {
if(dbstat == NULL) {
logg("No stats for Database check - forcing reload\n");
return root;
return engine;
}
if(cl_statchkdir(dbstat) == 1) {
logg("SelfCheck: Database modification detected. Forcing reload.\n");
return root;
return engine;
} else {
logg("SelfCheck: Database status OK.\n");
return NULL;
@ -201,9 +201,9 @@ static struct cl_node *reload_db(struct cl_node *root, unsigned int dboptions, c
}
/* release old structure */
if(root) {
cl_free(root);
root = NULL;
if(engine) {
cl_free(engine);
engine = NULL;
}
dbdir = cfgopt(copt, "DatabaseDirectory")->strarg;
@ -223,29 +223,29 @@ static struct cl_node *reload_db(struct cl_node *root, unsigned int dboptions, c
memset(dbstat, 0, sizeof(struct cl_stat));
cl_statinidir(dbdir, dbstat);
if((retval = cl_load(dbdir, &root, &sigs, dboptions))) {
if((retval = cl_load(dbdir, &engine, &sigs, dboptions))) {
logg("!reload db failed: %s\n", cl_strerror(retval));
*ret = 1;
return NULL;
}
if(!root) {
if(!engine) {
logg("!reload db failed: %s\n", cl_strerror(retval));
*ret = 1;
return NULL;
}
if((retval = cl_build(root)) != 0) {
if((retval = cl_build(engine)) != 0) {
logg("!Database initialization error: can't build engine: %s\n", cl_strerror(retval));
*ret = 1;
return NULL;
}
logg("Database correctly reloaded (%d signatures)\n", sigs);
return root;
return engine;
}
int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned int dboptions, const struct cfgstruct *copt)
int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigned int dboptions, const struct cfgstruct *copt)
{
int new_sd, max_threads, i, ret = 0;
unsigned int options = 0;
@ -459,7 +459,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned in
tharg = (struct thrarg *) mmalloc(sizeof(struct thrarg));
tharg->copt = copt;
tharg->root = root;
tharg->engine = engine;
tharg->limits = &limits;
tharg->options = options;
@ -560,8 +560,8 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned in
client_conn->sd = new_sd;
client_conn->options = options;
client_conn->copt = copt;
client_conn->root = cl_dup(root);
client_conn->root_timestamp = reloaded_time;
client_conn->engine = cl_dup(engine);
client_conn->engine_timestamp = reloaded_time;
client_conn->limits = &limits;
client_conn->socketds = socketds;
client_conn->nsockets = nsockets;
@ -585,7 +585,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned in
if(selfchk) {
time(&current_time);
if((current_time - start_time) > (time_t)selfchk) {
if(reload_db(root, dboptions, copt, TRUE, &ret)) {
if(reload_db(engine, dboptions, copt, TRUE, &ret)) {
pthread_mutex_lock(&reload_mutex);
reload = 1;
pthread_mutex_unlock(&reload_mutex);
@ -597,7 +597,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned in
pthread_mutex_lock(&reload_mutex);
if(reload) {
pthread_mutex_unlock(&reload_mutex);
root = reload_db(root, dboptions, copt, FALSE, &ret);
engine = reload_db(engine, dboptions, copt, FALSE, &ret);
if(ret) {
logg("Terminating because of a fatal error.");
if(new_sd >= 0)
@ -613,7 +613,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned in
logg("Stopping and restarting Clamuko.\n");
pthread_kill(clamuko_pid, SIGUSR1);
pthread_join(clamuko_pid, NULL);
tharg->root = root;
tharg->engine = engine;
pthread_create(&clamuko_pid, &clamuko_attr, clamukoth, tharg);
}
#endif
@ -633,8 +633,8 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned in
pthread_join(clamuko_pid, NULL);
}
#endif
if(root)
cl_free(root);
if(engine)
cl_free(engine);
if(dbstat)
cl_statfree(dbstat);

@ -30,7 +30,7 @@ struct thrarg {
int sid;
int options;
const struct cfgstruct *copt;
const struct cl_node *root;
const struct cl_engine *engine;
const struct cl_limits *limits;
};
@ -45,13 +45,13 @@ struct thrsession {
/* thread watcher arguments */
struct thrwarg {
int socketd;
struct cl_node **root;
struct cl_engine **engine;
const struct cfgstruct *copt;
const struct cl_limits *limits;
int options;
unsigned int options;
};
int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, unsigned int dboptions, const struct cfgstruct *copt);
int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigned int dboptions, const struct cfgstruct *copt);
void sighandler(int sig);
void sighandler_th(int sig);
void daemonize(void);

@ -64,10 +64,10 @@ extern int progexit;
struct multi_tag {
int sd;
int options;
unsigned int options;
const struct cfgstruct *copt;
char *fname;
const struct cl_node *root;
const struct cl_engine *engine;
const struct cl_limits *limits;
};
@ -87,7 +87,7 @@ void multiscanfile(void *arg)
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
#endif
ret = cl_scanfile(tag->fname, &virname, NULL, tag->root, tag->limits, tag->options);
ret = cl_scanfile(tag->fname, &virname, NULL, tag->engine, tag->limits, tag->options);
if(ret == CL_VIRUS) {
mdprintf(tag->sd, "%s: %s FOUND\n", tag->fname, virname);
@ -105,7 +105,7 @@ void multiscanfile(void *arg)
return;
}
static int multiscan(const char *dirname, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, threadpool_t *multi_pool)
static int multiscan(const char *dirname, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, threadpool_t *multi_pool)
{
DIR *dd;
struct dirent *dent;
@ -167,7 +167,7 @@ static int multiscan(const char *dirname, const struct cl_node *root, const stru
/* stat the file */
if(lstat(fname, &statbuf) != -1) {
if((S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) || (S_ISLNK(statbuf.st_mode) && (checksymlink(fname) == 1) && cfgopt(copt, "FollowDirectorySymlinks")->enabled)) {
if(multiscan(fname, root, limits, options, copt, odesc, reclev, multi_pool) == -1) {
if(multiscan(fname, engine, limits, options, copt, odesc, reclev, multi_pool) == -1) {
free(fname);
closedir(dd);
return -1;
@ -193,7 +193,7 @@ static int multiscan(const char *dirname, const struct cl_node *root, const stru
scandata->options = options;
scandata->copt = copt;
scandata->fname = fname;
scandata->root = root;
scandata->engine = engine;
scandata->limits = limits;
if(!thrmgr_dispatch(multi_pool, scandata)) {
logg("!multiscan: thread dispatch failed for multi_pool (file %s)\n", fname);
@ -228,7 +228,7 @@ static int multiscan(const char *dirname, const struct cl_node *root, const stru
return 0;
}
int command(int desc, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int timeout)
int command(int desc, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int timeout)
{
char buff[1025];
int bread, opt;
@ -249,13 +249,13 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits
cli_chomp(buff);
if(!strncmp(buff, CMD1, strlen(CMD1))) { /* SCAN */
if(scan(buff + strlen(CMD1) + 1, NULL, root, limits, options, copt, desc, 0) == -2)
if(scan(buff + strlen(CMD1) + 1, NULL, engine, limits, options, copt, desc, 0) == -2)
if(cfgopt(copt, "ExitOnOOM")->enabled)
return COMMAND_SHUTDOWN;
} else if(!strncmp(buff, CMD2, strlen(CMD2))) { /* RAWSCAN */
opt = options & ~CL_SCAN_ARCHIVE;
if(scan(buff + strlen(CMD2) + 1, NULL, root, NULL, opt, copt, desc, 0) == -2)
if(scan(buff + strlen(CMD2) + 1, NULL, engine, NULL, opt, copt, desc, 0) == -2)
if(cfgopt(copt, "ExitOnOOM")->enabled)
return COMMAND_SHUTDOWN;
@ -270,7 +270,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits
mdprintf(desc, "PONG\n");
} else if(!strncmp(buff, CMD6, strlen(CMD6))) { /* CONTSCAN */
if(scan(buff + strlen(CMD6) + 1, NULL, root, limits, options, copt, desc, 1) == -2)
if(scan(buff + strlen(CMD6) + 1, NULL, engine, limits, options, copt, desc, 1) == -2)
if(cfgopt(copt, "ExitOnOOM")->enabled)
return COMMAND_SHUTDOWN;
@ -304,7 +304,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits
free(path);
} else if(!strncmp(buff, CMD8, strlen(CMD8))) { /* STREAM */
if(scanstream(desc, NULL, root, limits, options, copt) == CL_EMEM)
if(scanstream(desc, NULL, engine, limits, options, copt) == CL_EMEM)
if(cfgopt(copt, "ExitOnOOM")->enabled)
return COMMAND_SHUTDOWN;
@ -320,7 +320,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits
} else if(!strncmp(buff, CMD12, strlen(CMD12))) { /* FD */
int fd = atoi(buff + strlen(CMD12) + 1);
scanfd(fd, NULL, root, limits, options, copt, desc);
scanfd(fd, NULL, engine, limits, options, copt, desc);
close(fd); /* FIXME: should we close it here? */
} else if(!strncmp(buff, CMD13, strlen(CMD13))) { /* MULTISCAN */
@ -345,14 +345,14 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits
return -1;
}
ret = multiscan(path, root, limits, options, copt, desc, &reclev, multi_pool);
ret = multiscan(path, engine, limits, options, copt, desc, &reclev, multi_pool);
thrmgr_destroy(multi_pool);
if(ret < 0)
return -1;
} else {
ret = cl_scanfile(path, &virname, NULL, root, limits, options);
ret = cl_scanfile(path, &virname, NULL, engine, limits, options);
if(ret == CL_VIRUS) {
mdprintf(desc, "%s: %s FOUND\n", path, virname);

@ -42,6 +42,6 @@
#include "libclamav/clamav.h"
#include "shared/cfgparser.h"
int command(int desc, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int timeout);
int command(int desc, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int timeout);
#endif

Loading…
Cancel
Save