|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|