diff --git a/clamdscan/clamdscan.c b/clamdscan/clamdscan.c index a855c749ea..a741d82c2f 100644 --- a/clamdscan/clamdscan.c +++ b/clamdscan/clamdscan.c @@ -59,6 +59,7 @@ int main(int argc, char **argv) int ds, dms, ret, infected = 0, err = 0; struct timeval t1, t2; time_t starttime; + char *config_file; struct optstruct *opts; const struct optstruct *opt; #ifndef _WIN32 @@ -70,8 +71,30 @@ int main(int argc, char **argv) return 2; } - if((clamdopts = optparse(optget(opts, "config-file")->strarg, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) { - logg("!Can't parse clamd configuration file %s\n", optget(opts, "config-file")->strarg); + /* XXX: if the user-specified config file does not exist, + * try the clamd.conf file. */ + config_file = optget(opts, "config-file")->strarg; + /* XXX: assert: config_file contains either + * /etc/clamdscan.conf or user-provided string */ + if ( access(config_file,R_OK) ) { + /* XXX: file not found or readable: abort if the user provided the filename + * (one bug here: user specifies CONFDIR_CLAMDSCAN which is not found + * and then we read CONFDIR_CLAMD ) */ + if (strcmp(config_file,CONFDIR_CLAMDSCAN)) { + logg("!Can't find or read requested clamd configuration file %s\n", config_file); + return 2; + } + else { + config_file = CONFDIR_CLAMD; + if ( access(config_file,R_OK) ) { + logg("!Can't find any readable clamd configuration file"); + return 2; + } + } + } + + if((clamdopts = optparse(config_file, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) { + logg("!Can't parse clamd configuration file %s\n", config_file); return 2; } diff --git a/docs/man/clamdscan.1.in b/docs/man/clamdscan.1.in index 8dc6804c0c..d709f111fb 100644 --- a/docs/man/clamdscan.1.in +++ b/docs/man/clamdscan.1.in @@ -28,7 +28,11 @@ Be quiet \- only output error messages. Write all messages (except for libclamav output) to the standard output (stdout). .TP \fB\-\-config\-file=FILE\fR -Read clamd settings from FILE. +Read clamd settings from FILE. If this option is not specified, the program +tries @CFGDIR@/clamdscan.conf, and if that is not found, it tries +@CFGDIR@/clamd.conf. The program recognizes a small subset of clamd.conf's +configuration directives, and ignores all others. See the provided configuration +sample. .TP \fB\-l FILE, \-\-log=FILE\fR Save the scan report to FILE. diff --git a/etc/Makefile.am b/etc/Makefile.am index 69a6e31548..fa9d355a55 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -16,10 +16,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. -EXTRA_DIST = clamd.conf.sample freshclam.conf.sample clamav-milter.conf.sample +EXTRA_DIST = clamd.conf.sample freshclam.conf.sample clamav-milter.conf.sample clamdscan.conf.sample CFGINST = @CFGDIR@ -sysconf_DATA = clamd.conf.sample freshclam.conf.sample +sysconf_DATA = clamd.conf.sample freshclam.conf.sample clamdscan.conf.sample if BUILD_CLAMD if HAVE_MILTER diff --git a/etc/Makefile.in b/etc/Makefile.in index 1a10989407..4220368951 100644 --- a/etc/Makefile.in +++ b/etc/Makefile.in @@ -301,9 +301,9 @@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -EXTRA_DIST = clamd.conf.sample freshclam.conf.sample clamav-milter.conf.sample +EXTRA_DIST = clamd.conf.sample freshclam.conf.sample clamav-milter.conf.sample clamdscan.conf.sample CFGINST = @CFGDIR@ -sysconf_DATA = clamd.conf.sample freshclam.conf.sample $(am__append_1) +sysconf_DATA = clamd.conf.sample freshclam.conf.sample clamdscan.conf.sample $(am__append_1) all: all-am .SUFFIXES: diff --git a/etc/clamdscan.conf.sample b/etc/clamdscan.conf.sample new file mode 100644 index 0000000000..a63259dea0 --- /dev/null +++ b/etc/clamdscan.conf.sample @@ -0,0 +1,40 @@ +## +## Sample clamdscan.conf file for a clamdscan program to +## work with a remote clamd scanner. +## +## Please read the clamd.conf(5) manual before editing this file. +## The options in this sample file are all those that the clamdscan +## program recognizes +## + +## Connection information for daemon +# Use local socket (unix only) +# Default: yes +LocalSocket yes + +## Or use TCP sockets +# TCPSocket 3310 +# TCPAddr 127.0.0.1 + +# Close the connection when the data size limit is exceeded. +# The value should match your MTA's limit for a maximum attachment size. +# +# Default: 25M +StreamMaxLength 200M + +# Maximum depth directories are scanned at. +# Default: 15 +MaxDirectoryRecursion 250 + +# This directive can be used multiple times +# Default: scan all +#ExcludePath ^/proc/ +#ExcludePath ^/sys/ + +# Follow directory symlinks. +# Default: no +#FollowDirectorySymlinks yes + +# Follow regular file symlinks. +# Default: no +#FollowFileSymlinks yes diff --git a/platform.h.in b/platform.h.in index bddbf1b38f..6ff6b85410 100644 --- a/platform.h.in +++ b/platform.h.in @@ -35,6 +35,7 @@ typedef unsigned int in_addr_t; #endif #define CONFDIR_CLAMD CONFDIR PATHSEP "clamd.conf" +#define CONFDIR_CLAMDSCAN CONFDIR PATHSEP "clamdscan.conf" #define CONFDIR_FRESHCLAM CONFDIR PATHSEP "freshclam.conf" #define CONFDIR_MILTER CONFDIR PATHSEP "clamav-milter.conf" diff --git a/shared/optparser.c b/shared/optparser.c index b99a3ff800..9371d32d9c 100644 --- a/shared/optparser.c +++ b/shared/optparser.c @@ -63,7 +63,8 @@ const struct clam_option __clam_options[] = { /* cmdline only */ { NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP | OPT_CLAMBC, "", "" }, - { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_CLAMD, FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" }, + { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_CLAMD, FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDTOP, "", "" }, + { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_CLAMDSCAN, FLAG_REQUIRED, OPT_CLAMDSCAN, "", "" }, { NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR_FRESHCLAM, FLAG_REQUIRED, OPT_FRESHCLAM, "", "" }, { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_MILTER, FLAG_REQUIRED, OPT_MILTER, "", "" }, { NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP | OPT_CLAMBC, "", "" },