2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2020-01-03 15:44:07 -05:00
|
|
|
* Copyright (C) 2013-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
2019-01-25 10:15:50 -05:00
|
|
|
* Copyright (C) 2009-2013 Sourcefire, Inc.
|
2009-02-07 00:59:58 +00:00
|
|
|
*
|
|
|
|
* Authors: Tomasz Kojm, aCaB
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-03-31 20:31:04 +00:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-04-09 19:59:28 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
2003-07-29 15:48:06 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
2009-01-20 17:46:47 +00:00
|
|
|
#include <stdlib.h>
|
2018-12-03 12:40:13 -05:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-11-28 23:26:29 +00:00
|
|
|
#include <unistd.h>
|
2009-02-12 17:31:09 +00:00
|
|
|
#endif
|
2004-11-28 23:26:29 +00:00
|
|
|
#include <string.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <sys/types.h>
|
2004-03-29 00:00:58 +00:00
|
|
|
#include <sys/stat.h>
|
2008-08-01 14:50:33 +00:00
|
|
|
#ifdef HAVE_SYS_LIMITS_H
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#endif
|
2009-09-24 16:08:52 +02:00
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
2009-02-04 17:18:58 +00:00
|
|
|
#include <sys/select.h>
|
2009-09-24 16:08:52 +02:00
|
|
|
#endif
|
2009-09-24 19:23:21 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/socket.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <sys/un.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2003-12-05 23:45:11 +00:00
|
|
|
#include <netdb.h>
|
2004-11-28 23:26:29 +00:00
|
|
|
#include <utime.h>
|
2009-09-24 19:23:21 +02:00
|
|
|
#endif
|
2004-11-28 23:26:29 +00:00
|
|
|
#include <errno.h>
|
2009-01-20 17:46:47 +00:00
|
|
|
#include <dirent.h>
|
2009-01-22 17:29:40 +00:00
|
|
|
#include <fcntl.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-12-07 01:53:16 +00:00
|
|
|
#ifdef HAVE_SYS_UIO_H
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
2014-07-01 19:38:01 -04:00
|
|
|
#include "libclamav/clamav.h"
|
2008-12-30 21:16:02 +00:00
|
|
|
#include "shared/optparser.h"
|
|
|
|
#include "shared/output.h"
|
|
|
|
#include "shared/misc.h"
|
2009-02-12 15:14:12 +00:00
|
|
|
#include "shared/actions.h"
|
2010-11-05 15:32:51 +01:00
|
|
|
#include "shared/clamdcom.h"
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
#include "libclamav/str.h"
|
2009-01-29 17:31:37 +00:00
|
|
|
#include "libclamav/others.h"
|
2008-12-30 21:16:02 +00:00
|
|
|
|
2007-02-11 00:41:13 +00:00
|
|
|
#include "client.h"
|
2009-02-07 00:59:58 +00:00
|
|
|
#include "proto.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2009-02-08 15:06:10 +00:00
|
|
|
unsigned long int maxstream;
|
2009-09-24 19:23:21 +02:00
|
|
|
#ifndef _WIN32
|
2014-01-27 14:34:02 -05:00
|
|
|
struct sockaddr_un nixsock;
|
2009-09-24 19:23:21 +02:00
|
|
|
#endif
|
2010-05-07 21:14:34 +02:00
|
|
|
extern struct optstruct *clamdopts;
|
2004-12-07 01:53:16 +00:00
|
|
|
|
2009-02-08 14:43:17 +00:00
|
|
|
/* Inits the communication layer
|
|
|
|
* Returns 0 if clamd is local, non zero if clamd is remote */
|
2018-12-03 12:40:13 -05:00
|
|
|
static int isremote(const struct optstruct *opts)
|
|
|
|
{
|
2009-01-23 09:59:40 +00:00
|
|
|
int s, ret;
|
|
|
|
const struct optstruct *opt;
|
2014-01-26 14:58:21 -05:00
|
|
|
char *ipaddr, port[10];
|
|
|
|
struct addrinfo hints, *info, *p;
|
|
|
|
int res;
|
2004-06-22 16:50:58 +00:00
|
|
|
|
2014-07-11 09:30:58 -04:00
|
|
|
UNUSEDPARAM(opts);
|
|
|
|
|
2009-09-24 16:08:52 +02:00
|
|
|
#ifndef _WIN32
|
2018-12-03 12:40:13 -05:00
|
|
|
if ((opt = optget(clamdopts, "LocalSocket"))->enabled) {
|
2014-01-25 21:50:33 -05:00
|
|
|
memset((void *)&nixsock, 0, sizeof(nixsock));
|
|
|
|
nixsock.sun_family = AF_UNIX;
|
|
|
|
strncpy(nixsock.sun_path, opt->strarg, sizeof(nixsock.sun_path));
|
2018-12-03 12:40:13 -05:00
|
|
|
nixsock.sun_path[sizeof(nixsock.sun_path) - 1] = '\0';
|
2014-01-25 21:50:33 -05:00
|
|
|
return 0;
|
2004-07-28 20:28:26 +00:00
|
|
|
}
|
2009-09-24 16:08:52 +02:00
|
|
|
#endif
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!(opt = optget(clamdopts, "TCPSocket"))->enabled)
|
2014-01-25 21:50:33 -05:00
|
|
|
return 0;
|
2010-05-07 21:14:34 +02:00
|
|
|
|
2014-01-26 14:58:21 -05:00
|
|
|
snprintf(port, sizeof(port), "%lld", optget(clamdopts, "TCPSocket")->numarg);
|
2009-02-12 21:14:51 +00:00
|
|
|
|
2014-01-25 21:50:33 -05:00
|
|
|
opt = optget(clamdopts, "TCPAddr");
|
|
|
|
while (opt) {
|
2014-05-13 11:10:18 -04:00
|
|
|
ipaddr = NULL;
|
|
|
|
if (opt->strarg)
|
2014-01-26 14:58:21 -05:00
|
|
|
ipaddr = (!strcmp(opt->strarg, "any") ? NULL : opt->strarg);
|
|
|
|
|
|
|
|
memset(&hints, 0x00, sizeof(struct addrinfo));
|
2018-12-03 12:40:13 -05:00
|
|
|
hints.ai_family = AF_UNSPEC;
|
2014-01-26 14:58:21 -05:00
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
2018-12-03 12:40:13 -05:00
|
|
|
hints.ai_flags = AI_PASSIVE;
|
2014-01-26 14:58:21 -05:00
|
|
|
|
|
|
|
if ((res = getaddrinfo(ipaddr, port, &hints, &info))) {
|
|
|
|
logg("!Can't lookup clamd hostname: %s\n", gai_strerror(res));
|
2014-05-13 11:10:18 -04:00
|
|
|
opt = opt->nextarg;
|
2014-01-26 14:58:21 -05:00
|
|
|
continue;
|
2014-01-25 21:50:33 -05:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:58:21 -05:00
|
|
|
for (p = info; p != NULL; p = p->ai_next) {
|
2018-12-03 12:40:13 -05:00
|
|
|
if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
|
2014-01-26 14:58:21 -05:00
|
|
|
logg("isremote: socket() returning: %s.\n", strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-27 14:34:02 -05:00
|
|
|
switch (p->ai_family) {
|
2018-12-03 12:40:13 -05:00
|
|
|
case AF_INET:
|
|
|
|
((struct sockaddr_in *)(p->ai_addr))->sin_port = htons(INADDR_ANY);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
((struct sockaddr_in6 *)(p->ai_addr))->sin6_port = htons(INADDR_ANY);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-01-27 14:34:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = bind(s, p->ai_addr, p->ai_addrlen);
|
2014-01-26 14:58:21 -05:00
|
|
|
if (ret) {
|
2014-01-27 14:34:02 -05:00
|
|
|
if (errno == EADDRINUSE) {
|
2020-01-03 15:44:07 -05:00
|
|
|
/*
|
2014-01-27 14:34:02 -05:00
|
|
|
* If we can't bind, then either we're attempting to listen on an IP that isn't
|
|
|
|
* ours or that clamd is already listening on.
|
|
|
|
*/
|
|
|
|
closesocket(s);
|
|
|
|
freeaddrinfo(info);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
closesocket(s);
|
2014-01-26 14:58:21 -05:00
|
|
|
freeaddrinfo(info);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-01-27 14:34:02 -05:00
|
|
|
|
|
|
|
closesocket(s);
|
2014-01-25 21:50:33 -05:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:58:21 -05:00
|
|
|
freeaddrinfo(info);
|
2014-01-25 21:50:33 -05:00
|
|
|
|
2014-05-13 11:10:18 -04:00
|
|
|
opt = opt->nextarg;
|
2012-09-14 08:00:47 -07:00
|
|
|
}
|
2014-01-26 14:58:21 -05:00
|
|
|
|
2014-01-27 14:34:02 -05:00
|
|
|
return 0;
|
2004-06-22 16:50:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 13:20:12 -05:00
|
|
|
/* pings clamd at the specified interval the number of time specified
|
|
|
|
* return 0 on a succesful connection, 1 upon timeout, -1 on error */
|
|
|
|
int16_t ping_clamd(const struct optstruct *opts)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint64_t attempts = 0;
|
|
|
|
uint64_t interval = 0;
|
|
|
|
char *attempt_str = NULL;
|
|
|
|
char *interval_str = NULL;
|
|
|
|
char *errchk = NULL;
|
|
|
|
uint64_t i = 0;
|
|
|
|
const struct optstruct *opt = NULL;
|
|
|
|
int64_t sockd;
|
|
|
|
struct RCVLN rcv;
|
|
|
|
uint16_t ret = 0;
|
|
|
|
|
|
|
|
if (opts == NULL) {
|
|
|
|
logg("!null parameter was passed\n");
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ping command takes the form --ping [attempts[:interval]] */
|
|
|
|
if (opt = optget(opts, "ping")) {
|
|
|
|
if (attempt_str = cli_strdup(opt->strarg)) {
|
|
|
|
if (NULL == attempt_str) {
|
|
|
|
logg("!could not allocate memory for string\n");
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
interval_str = strchr(attempt_str, ':');
|
|
|
|
if (interval_str[0] != '\0') {
|
|
|
|
interval_str[0] = '\0';
|
|
|
|
interval_str++;
|
|
|
|
interval = cli_strntoul(interval_str, strlen(interval_str), &errchk, 10);
|
|
|
|
if (interval_str + strlen(interval_str) > errchk) {
|
|
|
|
logg("^interval_str would go past end of buffer\n");
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
interval = CLAMDSCAN_DEFAULT_PING_INTERVAL;
|
|
|
|
}
|
|
|
|
attempts = cli_strntoul(attempt_str, strlen(attempt_str), &errchk, 10);
|
|
|
|
if (attempt_str + strlen(attempt_str) > errchk) {
|
|
|
|
logg("^attmept_str would go past end of buffer\n");
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
attempts = CLAMDSCAN_DEFAULT_PING_ATTEMPTS;
|
|
|
|
interval = CLAMDSCAN_DEFAULT_PING_INTERVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isremote(opts);
|
|
|
|
do {
|
|
|
|
if ((sockd = dconnect()) >= 0) {
|
|
|
|
recvlninit(&rcv, sockd);
|
|
|
|
|
|
|
|
if (sendln(sockd, "zPING", 5)) {
|
|
|
|
logg("*PING failed...\n");
|
|
|
|
closesocket(sockd);
|
|
|
|
} else {
|
|
|
|
if (!optget(opts, "wait")->enabled) {
|
|
|
|
logg("PONG\n");
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i + 1 < attempts) {
|
|
|
|
logg("*PINGing again in %lu seconds\n", interval);
|
|
|
|
sleep(interval);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
} while (i < attempts);
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (attempt_str) {
|
|
|
|
free(attempt_str);
|
|
|
|
}
|
|
|
|
attempt_str = NULL;
|
|
|
|
interval_str = NULL;
|
|
|
|
errchk = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-02-08 14:43:17 +00:00
|
|
|
/* Turns a relative path into an absolute one
|
2020-01-03 15:44:07 -05:00
|
|
|
* Returns a pointer to the path (which must be
|
2009-02-08 14:43:17 +00:00
|
|
|
* freed by the caller) or NULL on error */
|
2018-12-03 12:40:13 -05:00
|
|
|
static char *makeabs(const char *basepath)
|
|
|
|
{
|
2009-01-30 11:30:54 +00:00
|
|
|
int namelen;
|
2009-02-04 17:18:58 +00:00
|
|
|
char *ret;
|
2004-06-22 16:50:58 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!(ret = malloc(PATH_MAX + 1))) {
|
|
|
|
logg("^Can't make room for fullpath.\n");
|
|
|
|
return NULL;
|
2009-02-04 17:18:58 +00:00
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!cli_is_abspath(basepath)) {
|
|
|
|
if (!getcwd(ret, PATH_MAX)) {
|
|
|
|
logg("^Can't get absolute pathname of current working directory.\n");
|
|
|
|
free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-19 02:48:12 +01:00
|
|
|
#ifdef _WIN32
|
2018-12-03 12:40:13 -05:00
|
|
|
if (*basepath == '\\') {
|
|
|
|
namelen = 2;
|
|
|
|
basepath++;
|
|
|
|
} else
|
2010-03-19 02:48:12 +01:00
|
|
|
#endif
|
2018-12-03 12:40:13 -05:00
|
|
|
namelen = strlen(ret);
|
|
|
|
snprintf(&ret[namelen], PATH_MAX - namelen, PATHSEP "%s", basepath);
|
2003-07-29 15:48:06 +00:00
|
|
|
} else {
|
2018-12-03 12:40:13 -05:00
|
|
|
strncpy(ret, basepath, PATH_MAX);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2009-02-04 17:18:58 +00:00
|
|
|
ret[PATH_MAX] = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2009-02-08 14:43:17 +00:00
|
|
|
/* Recursively scans a path with the given scantype
|
|
|
|
* Returns non zero for serious errors, zero otherwise */
|
2018-12-03 12:40:13 -05:00
|
|
|
static int client_scan(const char *file, int scantype, int *infected, int *err, int maxlevel, int session, int flags)
|
|
|
|
{
|
2009-02-04 17:18:58 +00:00
|
|
|
int ret;
|
|
|
|
char *fullpath = makeabs(file);
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!fullpath)
|
|
|
|
return 0;
|
2009-02-04 17:18:58 +00:00
|
|
|
if (!session)
|
2018-12-03 12:40:13 -05:00
|
|
|
ret = serial_client_scan(fullpath, scantype, infected, err, maxlevel, flags);
|
2009-02-04 17:18:58 +00:00
|
|
|
else
|
2018-12-03 12:40:13 -05:00
|
|
|
ret = parallel_client_scan(fullpath, scantype, infected, err, maxlevel, flags);
|
2009-02-04 17:18:58 +00:00
|
|
|
free(fullpath);
|
2009-02-08 14:43:17 +00:00
|
|
|
return ret;
|
2004-06-22 16:50:58 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
int get_clamd_version(const struct optstruct *opts)
|
2008-01-10 13:57:05 +00:00
|
|
|
{
|
2018-12-03 12:40:13 -05:00
|
|
|
char *buff;
|
|
|
|
int len, sockd;
|
|
|
|
struct RCVLN rcv;
|
2008-01-10 13:57:05 +00:00
|
|
|
|
2009-01-23 09:59:40 +00:00
|
|
|
isremote(opts);
|
2018-12-03 12:40:13 -05:00
|
|
|
if ((sockd = dconnect()) < 0) return 2;
|
2009-01-23 11:59:11 +00:00
|
|
|
recvlninit(&rcv, sockd);
|
2008-01-10 13:57:05 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (sendln(sockd, "zVERSION", 9)) {
|
|
|
|
closesocket(sockd);
|
|
|
|
return 2;
|
2008-01-10 13:57:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
while ((len = recvln(&rcv, &buff, NULL))) {
|
|
|
|
if (len == -1) {
|
|
|
|
logg("!Error occurred while receiving version information.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("%s\n", buff);
|
2008-01-10 13:57:05 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 16:21:51 +02:00
|
|
|
closesocket(sockd);
|
2008-01-10 13:57:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
int reload_clamd_database(const struct optstruct *opts)
|
2008-09-18 08:17:47 +00:00
|
|
|
{
|
2018-12-03 12:40:13 -05:00
|
|
|
char *buff;
|
|
|
|
int len, sockd;
|
|
|
|
struct RCVLN rcv;
|
2008-09-18 08:17:47 +00:00
|
|
|
|
2009-01-23 09:59:40 +00:00
|
|
|
isremote(opts);
|
2018-12-03 12:40:13 -05:00
|
|
|
if ((sockd = dconnect()) < 0) return 2;
|
2009-01-23 11:59:11 +00:00
|
|
|
recvlninit(&rcv, sockd);
|
2008-09-18 08:17:47 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (sendln(sockd, "zRELOAD", 8)) {
|
|
|
|
closesocket(sockd);
|
|
|
|
return 2;
|
2008-09-18 08:17:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!(len = recvln(&rcv, &buff, NULL)) || len < 10 || memcmp(buff, "RELOADING", 9)) {
|
|
|
|
logg("!Clamd did not reload the database\n");
|
|
|
|
closesocket(sockd);
|
|
|
|
return 2;
|
2008-09-18 08:17:47 +00:00
|
|
|
}
|
2009-09-24 16:21:51 +02:00
|
|
|
closesocket(sockd);
|
2008-09-18 08:17:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-03 18:23:30 +01:00
|
|
|
int client(const struct optstruct *opts, int *infected, int *err)
|
2004-06-22 16:50:58 +00:00
|
|
|
{
|
2018-12-03 12:40:13 -05:00
|
|
|
int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec, flags = 0;
|
|
|
|
const char *fname;
|
2007-01-13 00:02:54 +00:00
|
|
|
|
2019-12-18 13:20:12 -05:00
|
|
|
if (optget(opts, "wait")->enabled) {
|
|
|
|
if (ping_clamd(opts) != 0) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-21 13:43:05 +00:00
|
|
|
scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !optget(opts, "file-list")->enabled && !opts->filename[1]);
|
2018-12-03 12:40:13 -05:00
|
|
|
remote = isremote(opts) | optget(opts, "stream")->enabled;
|
2009-01-22 17:29:40 +00:00
|
|
|
#ifdef HAVE_FD_PASSING
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!remote && optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) {
|
|
|
|
scantype = FILDES;
|
|
|
|
session = optget(opts, "multiscan")->enabled;
|
|
|
|
} else
|
2009-01-22 17:29:40 +00:00
|
|
|
#endif
|
2018-12-03 12:40:13 -05:00
|
|
|
if (remote || scandash) {
|
|
|
|
scantype = STREAM;
|
|
|
|
session = optget(opts, "multiscan")->enabled;
|
|
|
|
} else if (optget(opts, "multiscan")->enabled)
|
|
|
|
scantype = MULTI;
|
|
|
|
else if (optget(opts, "allmatch")->enabled)
|
|
|
|
scantype = ALLMATCH;
|
|
|
|
else
|
|
|
|
scantype = CONT;
|
|
|
|
|
|
|
|
maxrec = optget(clamdopts, "MaxDirectoryRecursion")->numarg;
|
2009-02-09 16:23:38 +00:00
|
|
|
maxstream = optget(clamdopts, "StreamMaxLength")->numarg;
|
2009-02-12 15:14:12 +00:00
|
|
|
if (optget(clamdopts, "FollowDirectorySymlinks")->enabled)
|
2018-12-03 12:40:13 -05:00
|
|
|
flags |= CLI_FTW_FOLLOW_DIR_SYMLINK;
|
2009-02-12 15:14:12 +00:00
|
|
|
if (optget(clamdopts, "FollowFileSymlinks")->enabled)
|
2018-12-03 12:40:13 -05:00
|
|
|
flags |= CLI_FTW_FOLLOW_FILE_SYMLINK;
|
2009-02-24 13:21:27 +00:00
|
|
|
flags |= CLI_FTW_TRIM_SLASHES;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2009-01-22 17:29:40 +00:00
|
|
|
*infected = 0;
|
2004-03-29 00:00:58 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (scandash) {
|
|
|
|
int sockd, ret;
|
|
|
|
STATBUF sb;
|
|
|
|
if (FSTAT(0, &sb) < 0) {
|
|
|
|
logg("client.c: fstat failed for file name \"%s\", with %s\n.",
|
|
|
|
opts->filename[0], strerror(errno));
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if ((sb.st_mode & S_IFMT) != S_IFREG) scantype = STREAM;
|
|
|
|
if ((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret, NULL)) >= 0)
|
|
|
|
*infected = ret;
|
|
|
|
else
|
|
|
|
errors = 1;
|
|
|
|
if (sockd >= 0) closesocket(sockd);
|
|
|
|
} else if (opts->filename || optget(opts, "file-list")->enabled) {
|
|
|
|
if (opts->filename && optget(opts, "file-list")->enabled)
|
|
|
|
logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");
|
|
|
|
|
|
|
|
while ((fname = filelist(opts, NULL))) {
|
|
|
|
if (!strcmp(fname, "-")) {
|
|
|
|
logg("!Scanning from standard input requires \"-\" to be the only file argument\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
errors += client_scan(fname, scantype, infected, err, maxrec, session, flags);
|
|
|
|
/* this may be too strict
|
2010-02-03 18:23:30 +01:00
|
|
|
if(errors >= 10) {
|
|
|
|
logg("!Too many errors\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
2018-12-03 12:40:13 -05:00
|
|
|
}
|
2009-01-22 17:29:40 +00:00
|
|
|
} else {
|
2018-12-03 12:40:13 -05:00
|
|
|
errors = client_scan("", scantype, infected, err, maxrec, session, flags);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2004-06-22 16:50:58 +00:00
|
|
|
return *infected ? 1 : (errors ? 2 : 0);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|