output "stream" instead of "fd[]" for INSTREAM.

Add INSTREAM command test.

git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4753 77e5149b-7576-45b1-b177-96237e5ba77b
0.95
Török Edvin 17 years ago
parent d66eff0ace
commit 004f8386ce
  1. 5
      ChangeLog
  2. 1
      clamd/others.c
  3. 1
      clamd/others.h
  4. 5
      clamd/scanner.c
  5. 2
      clamd/scanner.h
  6. 2
      clamd/server-th.c
  7. 4
      clamd/session.c
  8. 2
      unit_tests/Makefile.am
  9. 2
      unit_tests/Makefile.in
  10. 63
      unit_tests/check_clamd.c
  11. 12
      unit_tests/check_clamd.sh

@ -1,3 +1,8 @@
Thu Feb 12 18:19:28 EET 2009 (edwin)
------------------------------------
* clamd/, unit_tests/: output stream instead of fd[] for INSTREAM.
Add INSTREAM command test.
Thu Feb 12 17:11:16 EET 2009 (edwin)
------------------------------------
* Makefile.in, unit_tests/Makefile.am, unit_tests/Makefile.in,

@ -317,6 +317,7 @@ static int buf_init(struct fd_buf *buf, int listen_only)
buf->quota = 0;
buf->dumpname = NULL;
buf->group = NULL;
buf->term = '\0';
if (!listen_only) {
if (!buf->buffer) {
buf->bufsize = PATH_MAX+8;

@ -40,6 +40,7 @@ struct fd_buf {
size_t bufsize;
size_t off;
int fd;
char term;
int got_newdata; /* 0: no, 1: yes, -1: error */
int recvfd;
/* TODO: these fields don't belong here, there are identical fields in conn

@ -234,13 +234,16 @@ int scan_callback(struct stat *sb, char *filename, const char *msg, enum cli_ftw
int scanfd(const int fd, const client_conn_t *conn, unsigned long int *scanned,
const struct cl_engine *engine,
unsigned int options, const struct optstruct *opts, int odesc)
unsigned int options, const struct optstruct *opts, int odesc, int stream)
{
int ret;
const char *virname;
struct stat statbuf;
char fdstr[32];
if (stream)
strncpy(fdstr, "stream", sizeof(fdstr));
else
snprintf(fdstr, sizeof(fdstr), "fd[%d]", fd);
if(fstat(fd, &statbuf) == -1 || !S_ISREG(statbuf.st_mode)) {
conn_reply(conn, fdstr, "Not a regular file", "ERROR");

@ -46,7 +46,7 @@ struct scan_cb_data {
jobgroup_t *group;
};
int scanfd(const int fd, const client_conn_t *conn, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options, const struct optstruct *opts, int odesc);
int scanfd(const int fd, const client_conn_t *conn, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options, const struct optstruct *opts, int odesc, int stream);
int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *engine, unsigned int options, const struct optstruct *opts, char term);
int scan_callback(struct stat *sb, char *filename, const char *msg, enum cli_ftw_reason reason, struct cli_ftw_cbdata *data);

@ -853,6 +853,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
}
conn.term = term;
buf->term = term;
if ((rc = execute_or_dispatch_command(&conn, cmdtype, argument)) < 0) {
logg("!Command dispatch failed\n");
@ -951,6 +952,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
if (!buf->chunksize) {
/* chunksize 0 marks end of stream */
conn.scanfd = buf->dumpfd;
conn.term = buf->term;
buf->dumpfd = -1;
buf->mode = buf->group ? MODE_COMMAND : MODE_WAITREPLY;
logg("*RECVTH: chunks complete\n");

@ -236,7 +236,7 @@ int command(client_conn_t *conn, int *virus)
if (conn->scanfd == -1)
conn_reply_error(conn, "FILDES: didn't receive file descriptor.");
else {
ret = scanfd(conn->scanfd, conn, NULL, engine, options, opts, desc);
ret = scanfd(conn->scanfd, conn, NULL, engine, options, opts, desc, 0);
if (ret == CL_VIRUS)
*virus = 1;
if (ret == CL_EMEM) {
@ -268,7 +268,7 @@ int command(client_conn_t *conn, int *virus)
}
return 0;
case COMMAND_INSTREAMSCAN:
ret = scanfd(conn->scanfd, conn, NULL, engine, options, opts, desc);
ret = scanfd(conn->scanfd, conn, NULL, engine, options, opts, desc, 1);
if (ret == CL_VIRUS)
*virus = 1;
if (ret == CL_EMEM) {

@ -26,7 +26,7 @@ check_clamav_SOURCES = check_clamav.c checks.h checks_common.h $(top_builddir)/l
check_clamav_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\"
check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CHECK_LIBS@
check_clamd_SOURCES = check_clamd.c checks_common.h
check_clamd_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\"
check_clamd_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\" -DBUILDDIR=\"$(abs_builddir)\"
check_clamd_LDADD = @CHECK_LIBS@ @CLAMD_LIBS@
else
check_clamd_SOURCES = check_clamav_skip.c

@ -271,7 +271,7 @@ check_SCRIPTS = $(scripts)
@HAVE_LIBCHECK_TRUE@check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CHECK_LIBS@
@HAVE_LIBCHECK_FALSE@check_clamd_SOURCES = check_clamav_skip.c
@HAVE_LIBCHECK_TRUE@check_clamd_SOURCES = check_clamd.c checks_common.h
@HAVE_LIBCHECK_TRUE@check_clamd_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\"
@HAVE_LIBCHECK_TRUE@check_clamd_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\" -DBUILDDIR=\"$(abs_builddir)\"
@HAVE_LIBCHECK_TRUE@check_clamd_LDADD = @CHECK_LIBS@ @CLAMD_LIBS@
CLEANFILES = lcov.out *.gcno *.gcda *.log $(FILES) test-stderr.log clamscan.log valgrind-*.log duma.log duma2.log clamscan2.log
EXTRA_DIST = .split $(srcdir)/*.ref input test-clamd.conf test-freshclam.conf valgrind.supp virusaction-test.sh $(scripts) preload_run.sh

@ -2,6 +2,7 @@
#include "clamav-config.h"
#endif
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -11,10 +12,14 @@
#include <sys/types.h>
#endif
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <unistd.h>
#include <check.h>
#include "checks_common.h"
#include "libclamav/version.h"
#include "libclamav/cltypes.h"
#ifdef CHECK_HAVE_LOOPS
@ -46,13 +51,20 @@ static void conn_teardown(void)
#ifndef REPO_VERSION
#define REPO_VERSION VERSION
#endif
#define SCANFILE BUILDDIR"/../test/clam.exe"
#define FOUNDREPLY SCANFILE": ClamAV-Test-File.UNOFFICIAL FOUND"
static struct basic_test {
const char *command;
const char *reply;
} basic_tests[] = {
{"PING", "PONG"},
{"RELOAD","RELOADING"},
{"VERSION", "ClamAV "REPO_VERSION""VERSION_SUFFIX}
{"VERSION", "ClamAV "REPO_VERSION""VERSION_SUFFIX},
{"SCAN "SCANFILE, FOUNDREPLY},
{"CONTSCAN "SCANFILE, FOUNDREPLY},
{"MULTISCAN "SCANFILE, FOUNDREPLY},
};
static void *recvfull(int sd, size_t *len)
@ -83,7 +95,7 @@ static void test_command(const char *cmd, size_t len, const char *expect, size_t
void *recvdata;
int rc;
rc = send(sockd, cmd, len, 0);
fail_unless_fmt(rc != -1, "Unable to send(): %s\n", strerror(errno));
fail_unless_fmt(rc == len, "Unable to send(): %s\n", strerror(errno));
recvdata = recvfull(sockd, &len);
@ -121,12 +133,59 @@ START_TEST (test_basic_commands)
}
END_TEST
#define EXPECT_INSTREAM "stream: ClamAV-Test-File.UNOFFICIAL FOUND\n"
START_TEST (tc_instream)
{
int fd, nread, rc;
struct stat stbuf;
uint32_t chunk;
void *recvdata;
size_t len, expect_len;
char buf[4096] = "nINSTREAM\n";
size_t off = strlen(buf);
fail_unless_fmt(stat(SCANFILE, &stbuf) != -1, "stat failed for %s: %s", SCANFILE, strerror(errno));
fd = open(SCANFILE, O_RDONLY);
fail_unless_fmt(fd != -1, "open failed: %s\n", strerror(errno));
chunk = htonl(stbuf.st_size);
memcpy(&buf[off], &chunk, sizeof(chunk));
off += 4;
nread = read(fd, &buf[off], sizeof(buf)-off-4);
fail_unless_fmt(nread == stbuf.st_size, "read failed: %s\n", strerror(errno));
off += nread;
buf[off++]=0;
buf[off++]=0;
buf[off++]=0;
buf[off++]=0;
close(fd);
conn_setup();
fail_unless(send(sockd, buf, off, 0) == off, "send() failed: %s\n", strerror(errno));
recvdata = recvfull(sockd, &len);
expect_len = strlen(EXPECT_INSTREAM);
fail_unless_fmt(len == expect_len, "Reply has wrong size: %lu, expected %lu, reply: %s\n",
len, expect_len, recvdata);
rc = memcmp(recvdata, EXPECT_INSTREAM, expect_len);
fail_unless_fmt(!rc, "Wrong reply for command INSTREAM: |%s|, expected: |%s|\n", recvdata, EXPECT_INSTREAM);
free(recvdata);
conn_teardown();
}
END_TEST
static Suite *test_clamd_suite(void)
{
Suite *s = suite_create("clamd");
TCase *tc_commands = tcase_create("clamd commands");
suite_add_tcase(s, tc_commands);
tcase_add_loop_test(tc_commands, test_basic_commands, 0, sizeof(basic_tests)/sizeof(basic_tests[0]));
tcase_add_test(tc_commands, tc_instream);
return s;
}

@ -89,12 +89,6 @@ run_clamdscan() {
cat clamdscan-multiscan.log
die 1
fi
$TOP/unit_tests/check_clamd
ecode=$?
if test $ecode -ne 77 && test $ecode -ne 0; then
error "Failed clamd protocol test!"
die 1
fi
}
run_reload_test()
@ -202,6 +196,12 @@ if test "$NFILES" -ne "0$NINFECTED_MULTI_FDPASS"; then
scan_failed clamdscan-multiscan.log "clamd did not detect all testfiles correctly in fdpass+multiscan mode!"
fi
$TOP/unit_tests/check_clamd
ecode=$?
if test $ecode -ne 77 && test $ecode -ne 0; then
error "Failed clamd protocol test!"
die 1
fi
# Test HeuristicScanPrecedence off feature
run_clamdscan ../clam-phish-exe
grep "ClamAV-Test-File" clamdscan.log >/dev/null 2>/dev/null;

Loading…
Cancel
Save