2008-12-17 21:42:54 +00:00
/*
* Copyright ( C ) 2008 Sourcefire , Inc .
*
* Author : Tomasz Kojm < tkojm @ clamav . net >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
*
* 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
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
*/
/*
* TODO :
2008-12-30 21:16:02 +00:00
* - clamconf , milter
2008-12-17 21:42:54 +00:00
* - clamconf : generation / verification / updating of config files and man page entries
* - automatically generate - - help pages ( use the first line from the description )
*/
# if HAVE_CONFIG_H
# include "clamav-config.h"
# endif
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# ifdef HAVE_STRINGS_H
# include <strings.h>
# endif
# include <ctype.h>
# include "shared/optparser.h"
# include "shared/misc.h"
# include "libclamav/regex/regex.h"
2009-01-22 14:19:47 +00:00
# include "libclamav/default.h"
2008-12-17 21:42:54 +00:00
# include "getopt.h"
2008-12-30 21:16:02 +00:00
# define MAXCMDOPTS 100
2008-12-17 21:42:54 +00:00
# define MAX(a,b) (a > b ? a : b)
# define MATCH_NUMBER "^[0-9]+$"
# define MATCH_SIZE "^[0-9]+[kKmM]?$"
2008-12-22 21:22:17 +00:00
# define MATCH_BOOL "^([yY]es|[tT]rue|1|[nN]o|[fF]alse|0)$"
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
# define FLAG_MULTIPLE 1 /* option can be used multiple times */
# define FLAG_REQUIRED 2 /* arg is required, even if there's a default value */
2009-01-22 14:19:47 +00:00
const struct clam_option clam_options [ ] = {
2008-12-17 21:42:54 +00:00
/* name, longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
2008-12-18 19:42:53 +00:00
/* cmdline only */
2009-01-22 14:19:47 +00:00
{ NULL , " help " , ' h ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF , " " , " " } ,
2008-12-31 12:26:30 +00:00
{ NULL , " config-file " , ' c ' , TYPE_STRING , NULL , 0 , CONFDIR " /clamd.conf " , FLAG_REQUIRED , OPT_CLAMD | OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " config-file " , 0 , TYPE_STRING , NULL , 0 , CONFDIR " /freshclam.conf " , FLAG_REQUIRED , OPT_FRESHCLAM , " " , " " } ,
2009-01-02 15:30:17 +00:00
{ NULL , " config-file " , ' c ' , TYPE_STRING , NULL , 0 , CONFDIR " /clamav-milter.conf " , FLAG_REQUIRED , OPT_MILTER , " " , " " } ,
2009-01-22 14:38:16 +00:00
{ NULL , " version " , ' V ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF , " " , " " } ,
2009-01-02 11:54:08 +00:00
{ NULL , " debug " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL , " " , " " } ,
{ NULL , " verbose " , ' v ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL , " " , " " } ,
{ NULL , " quiet " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL , " " , " " } ,
2008-12-31 12:26:30 +00:00
{ NULL , " leave-temps " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " no-warnings " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM , " " , " " } ,
2009-01-02 11:54:08 +00:00
{ NULL , " stdout " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL , " " , " " } ,
2008-12-31 12:26:30 +00:00
{ NULL , " daemon " , ' d ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM , " " , " " } ,
{ NULL , " no-dns " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM , " " , " " } ,
{ NULL , " list-mirrors " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM , " " , " " } ,
{ NULL , " submit-stats " , 0 , TYPE_STRING , NULL , 0 , CONFDIR " /clamd.conf " , 0 , OPT_FRESHCLAM , " " , " " } , /* Don't merge this one with SubmitDetectionStats */
{ NULL , " reload " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " multiscan " , ' m ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " fdpass " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " database " , ' d ' , TYPE_STRING , NULL , - 1 , DATADIR , FLAG_REQUIRED , OPT_CLAMSCAN , " " , " " } , /* merge it with DatabaseDirectory (and fix conflict with --datadir */
{ NULL , " recursive " , ' r ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " bell " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " no-summary " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " infected " , ' i ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " move " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMSCAN | OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " copy " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMSCAN | OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " remove " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_CLAMDSCAN , " " , " " } ,
{ NULL , " exclude " , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " exclude-dir " , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " include " , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " include-dir " , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMSCAN , " " , " " } ,
{ NULL , " structured-ssn-format " , 0 , TYPE_NUMBER , MATCH_NUMBER , 0 , NULL , 0 , OPT_CLAMSCAN , " " , " " } ,
2009-01-02 11:54:08 +00:00
{ NULL , " hex-dump " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " md5 " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " mdb " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " html-normalise " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " utf16-decode " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " build " , ' b ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " server " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " unpack " , ' u ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " unpack-current " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " info " , ' i ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " list-sigs " , ' l ' , TYPE_STRING , NULL , - 1 , DATADIR , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " vba " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " vba-hex " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " diff " , ' d ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " run-cdiff " , ' r ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
{ NULL , " verify-cdiff " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_SIGTOOL , " " , " " } ,
2008-12-30 10:33:43 +00:00
2009-01-22 14:19:47 +00:00
{ NULL , " config-dir " , ' c ' , TYPE_STRING , NULL , 0 , CONFDIR , FLAG_REQUIRED , OPT_CLAMCONF , " " , " " } ,
{ NULL , " non-default " , ' n ' , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMCONF , " " , " " } ,
2008-12-30 10:33:43 +00:00
/* cmdline only - deprecated */
2008-12-31 12:26:30 +00:00
{ NULL , " http-proxy " , 0 , TYPE_STRING , NULL , 0 , NULL , 0 , OPT_FRESHCLAM | OPT_DEPRECATED , " " , " " } ,
{ NULL , " proxy-user " , 0 , TYPE_STRING , NULL , 0 , NULL , 0 , OPT_FRESHCLAM | OPT_DEPRECATED , " " , " " } ,
{ NULL , " force " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " disable-summary " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " disable-archive " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-archive " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-pe " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-elf " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-ole2 " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-pdf " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-html " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-mail " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-phishing-sigs " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-phishing-scan-urls " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-algorithmic " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " no-phishing-restrictedscan " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " max-ratio " , 0 , TYPE_NUMBER , MATCH_NUMBER , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " max-space " , 0 , TYPE_SIZE , MATCH_SIZE , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " block-max " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " unzip " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " unrar " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " arj " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " unzoo " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " lha " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " jar " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " tar " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " tgz " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
{ NULL , " deb " , 0 , TYPE_STRING , NULL , - 1 , " foo " , 0 , OPT_CLAMSCAN | OPT_DEPRECATED , " " , " " } ,
2008-12-18 19:42:53 +00:00
/* config file/cmdline options */
2008-12-31 12:26:30 +00:00
{ " LogFile " , " log " , ' l ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN | OPT_CLAMDSCAN , " Save all reports to a log file. " , " /tmp/clamav.log " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogFileUnlock " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_MILTER , " By default the log file is locked for writing and only a single \n daemon process can write to it. This option disables the lock. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogFileMaxSize " , NULL , 0 , TYPE_SIZE , MATCH_SIZE , 1048576 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Maximum size of the log file. \n Value of 0 disables the limit. " , " 5M " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogTime " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Log time with each message. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogClean " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " Log all clean files. \n Useful in debugging but drastically increases the log size. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogVerbose " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Enable verbose logging. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogSyslog " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Use the system logger (can work together with LogFile). " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LogFacility " , NULL , 0 , TYPE_STRING , NULL , - 1 , " LOG_LOCAL6 " , FLAG_REQUIRED , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Type of syslog messages. \n Please refer to 'man syslog' for the facility names. " , " LOG_MAIL " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " PidFile " , " pid " , ' p ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Save the process ID to a file. " , " /var/run/clamd.pid " } ,
2008-12-17 21:42:54 +00:00
2009-01-02 11:54:08 +00:00
{ " TemporaryDirectory " , " tempdir " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN | OPT_SIGTOOL , " This option allows you to change the default temporary directory. " , " /tmp " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " DatabaseDirectory " , " datadir " , 0 , TYPE_STRING , NULL , - 1 , DATADIR , 0 , OPT_CLAMD | OPT_FRESHCLAM , " This option allows you to change the default database directory. \n If you enable it, please make sure it points to the same directory in \n both clamd and freshclam. " , " /var/lib/clamav " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LocalSocket " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD , " Path to a local socket file the daemon will listen on. " , " /tmp/clamd.socket " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " FixStaleSocket " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_MILTER , " Remove a stale socket after unclean shutdown " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " TCPSocket " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , - 1 , NULL , 0 , OPT_CLAMD , " A TCP port number the daemon will listen on. " , " 3310 " } ,
2008-12-17 21:42:54 +00:00
/* FIXME: add a regex for IP addr */
2008-12-31 12:26:30 +00:00
{ " TCPAddr " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD , " By default clamd binds to INADDR_ANY. \n This option allows you to restrict the TCP address and provide \n some degree of protection from the outside world. " , " 3310 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " MaxConnectionQueueLength " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 15 , NULL , 0 , OPT_CLAMD , " Maximum length the queue of pending connections may grow to. " , " 30 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " StreamMaxLength " , NULL , 0 , TYPE_SIZE , MATCH_SIZE , 10485760 , NULL , 0 , OPT_CLAMD , " Close the STREAM session when the data size limit is exceeded. \n The value should match your MTA's limit for the maximum attachment size. " , " 25M " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " StreamMinPort " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 1024 , NULL , 0 , OPT_CLAMD , " The STREAM command uses an FTP-like protocol. \n This option sets the lower boundary for the port range. " , " 1024 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " StreamMaxPort " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 2048 , NULL , 0 , OPT_CLAMD , " This option sets the upper boundary for the port range. " , " 2048 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " MaxThreads " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 10 , NULL , 0 , OPT_CLAMD | OPT_MILTER , " Maximum number of threads running at the same time. " , " 20 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ReadTimeout " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 120 , NULL , 0 , OPT_CLAMD | OPT_MILTER , " This option specifies the time (in seconds) after which clamd should \n timeout if a client doesn't provide any data. " , " 120 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " IdleTimeout " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 30 , NULL , 0 , OPT_CLAMD , " This option specifies how long (in seconds) the process should wait for a new job. " , " 60 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ExcludePath " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMD , " Don't scan files/directories whose names match the provided \n regular expression. This option can be specified multiple times. " , " ^/proc/ " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " MaxDirectoryRecursion " , " max-dir-recursion " , 0 , TYPE_NUMBER , MATCH_NUMBER , 15 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Maximum depth the directories are scanned at. " , " 15 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " FollowDirectorySymlinks " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " Follow directory symlinks. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " FollowFileSymlinks " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " Follow symlinks to regular files. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " SelfCheck " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 600 , NULL , 0 , OPT_CLAMD , " This option specifies the time intervals (in seconds) in which clamd \n should perform a database check. " , " 600 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " VirusEvent " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD , " Execute a command when a virus is found. In the command string %v will be \n replaced with the virus name. Additionally, two environment variables will \n be defined: $CLAM_VIRUSEVENT_FILENAME and $CLAM_VIRUSEVENT_VIRUSNAME. " , " /usr/bin/mailx -s \" ClamAV VIRUS ALERT: %v \" alert < /dev/null " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ExitOnOOM " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " Stop the daemon when libclamav reports an out of memory condition. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " Foreground " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Don't fork into background. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " Debug " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM , " Enable debug messages in libclamav. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " LeaveTemporaryFiles " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " Don't remove temporary files (for debugging purposes). " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " User " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_MILTER , " Run the daemon as a specified user (the process must be started by root). " , " clamav " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " AllowSupplementaryGroups " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER , " Initialize a supplementary group access (the process must be started by root). " , " no " } ,
2008-12-17 21:42:54 +00:00
/* Scan options */
2008-12-31 12:26:30 +00:00
{ " DetectPUA " , " detect-pua " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Detect Potentially Unwanted Applications. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ExcludePUA " , " exclude-pua " , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMD | OPT_CLAMSCAN , " Exclude a specific PUA category. This directive can be used multiple times. \n See http://www.clamav.net/support/pua for the complete list of PUA \n categories. " , " NetTool " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " IncludePUA " , " include-pua " , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMD | OPT_CLAMSCAN , " Only include a specific PUA category. This directive can be used multiple \n times. " , " Spy " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " AlgorithmicDetection " , " algorithmic-detection " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " In some cases (eg. complex malware, exploits in graphic files, and others), \n ClamAV uses special algorithms to provide accurate detection. This option \n controls the algorithmic detection. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanPE " , " scan-pe " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " PE stands for Portable Executable - it's an executable file format used \n in all 32- and 64-bit versions of Windows operating systems. This option \n allows ClamAV to perform a deeper analysis of executable files and it's also \n required for decompression of popular executable packers such as UPX or FSG. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanELF " , " scan-elf " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Executable and Linking Format is a standard format for UN*X executables. \n This option allows you to control the scanning of ELF files. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " DetectBrokenExecutables " , " detect-broken " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " With this option enabled clamav will try to detect broken executables \n (both PE and ELF) and mark them as Broken.Executable. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanMail " , " scan-mail " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Enable the built in email scanner. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " MailFollowURLs " , " mail-follow-urls " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " If an email contains URLs ClamAV can download and scan them. \n WARNING: This option may open your system to a DoS attack. Please don't use \n this feature on highly loaded servers. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanPartialMessages " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " Scan RFC1341 messages split over many emails. You will need to \n periodically clean up $TemporaryDirectory/clamav-partial directory. \n WARNING: This option may open your system to a DoS attack. Please don't use \n this feature on highly loaded servers. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " PhishingSignatures " , " phishing-sigs " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " With this option enabled ClamAV will try to detect phishing attempts by using \n signatures. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " PhishingScanURLs " , " phishing-scan-urls " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Scan URLs found in mails for phishing attempts using heuristics. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " PhishingAlwaysBlockCloak " , " phishing-cloak " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Always block cloaked URLs, even if they're not in the database. \n This feature can lead to false positives. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " PhishingAlwaysBlockSSLMismatch " , " phishing-ssl " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Always block SSL mismatches in URLs, even if they're not in the database. \n This feature can lead to false positives. " , " " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " HeuristicScanPrecedence " , " heuristic-scan-precedence " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Allow heuristic match to take precedence. \n When enabled, if a heuristic scan (such as phishingScan) detects \n a possible virus/phish it will stop scan immediately. Recommended, saves CPU \n scan-time. \n When disabled, virus/phish detected by heuristic scans will be reported only \n at the end of a scan. If an archive contains both a heuristically detected \n virus/phish, and a real malware, the real malware will be reported. \n Keep this disabled if you intend to handle \" *.Heuristics.* \" viruses \n differently from \" real \" malware. \n If a non-heuristically-detected virus (signature-based) is found first, \n the scan is interrupted immediately, regardless of this config option. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " StructuredDataDetection " , " detect-structured " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Enable the Data Loss Prevention module. " , " no " } ,
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
{ " StructuredMinCreditCardCount " , " structured-cc-count " , 0 , TYPE_NUMBER , MATCH_NUMBER , CLI_DEFAULT_MIN_CC_COUNT , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " This option sets the lowest number of Credit Card numbers found in a file \n to generate a detect. " , " 5 " } ,
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
{ " StructuredMinSSNCount " , " structured-ssn-count " , 0 , TYPE_NUMBER , MATCH_NUMBER , CLI_DEFAULT_MIN_SSN_COUNT , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " This option sets the lowest number of Social Security Numbers found \n in a file to generate a detect. " , " 5 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " StructuredSSNFormatNormal " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD , " With this option enabled the DLP module will search for valid \n SSNs formatted as xxx-yy-zzzz. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " StructuredSSNFormatStripped " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD , " With this option enabled the DLP module will search for valid \n SSNs formatted as xxxyyzzzz " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanHTML " , " scan-html " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Perform HTML/JavaScript/ScriptEncoder normalisation and decryption. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanOLE2 " , " scan-ole2 " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " This option enables scanning of OLE2 files, such as Microsoft Office \n documents and .msi files. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanPDF " , " scan-pdf " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " This option enables scanning within PDF files. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScanArchive " , " scan-archive " , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Scan within archives and compressed files. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ArchiveBlockEncrypted " , " block-encrypted " , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Mark encrypted archives as viruses (Encrypted.Zip, Encrypted.RAR). " , " no " } ,
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
{ " MaxScanSize " , " max-scansize " , 0 , TYPE_SIZE , MATCH_SIZE , CLI_DEFAULT_MAXSCANSIZE , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " This option sets the maximum amount of data to be scanned for each input file. \n Archives and other containers are recursively extracted and scanned up to this \n value. \n The value of 0 disables the limit. \n WARNING: disabling this limit or setting it too high may result in severe damage. " , " 100M " } ,
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
{ " MaxFileSize " , " max-filesize " , 0 , TYPE_SIZE , MATCH_SIZE , CLI_DEFAULT_MAXFILESIZE , NULL , 0 , OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN , " Files larger than this limit won't be scanned. Affects the input file itself \n as well as files contained inside it (when the input file is an archive, a \n document or some other kind of container). \n The value of 0 disables the limit. \n WARNING: disabling this limit or setting it too high may result in severe damage to the system. " , " 25M " } ,
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
{ " MaxRecursion " , " max-recursion " , 0 , TYPE_NUMBER , MATCH_NUMBER , CLI_DEFAULT_MAXRECLEVEL , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Nested archives are scanned recursively, e.g. if a Zip archive contains a RAR \n file, all files within it will also be scanned. This option specifies how \n deeply the process should be continued. \n The value of 0 disables the limit. \n WARNING: disabling this limit or setting it too high may result in severe damage to the system. " , " 16 " } ,
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
{ " MaxFiles " , " max-files " , 0 , TYPE_NUMBER , MATCH_NUMBER , CLI_DEFAULT_MAXFILES , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " Number of files to be scanned within an archive, a document, or any other \n container file. \n The value of 0 disables the limit. \n WARNING: disabling this limit or setting it too high may result in severe damage to the system. " , " 10000 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoScanOnAccess " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD , " This option enables Clamuko. Dazuko needs to be already configured and \n running. " , " no " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoScanOnOpen " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD , " Scan files when they get opened by the system. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoScanOnClose " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD , " Scan files when they get closed by the system. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoScanOnExec " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD , " Scan files when they get executed by the system. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoIncludePath " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMD , " This option specifies a directory (together will all files and directories \n inside this directory) which should be scanned on-access. This option can \n be used multiple times. " , " /home " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoExcludePath " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_CLAMD , " This option allows excluding directories from on-access scanning. It can be used multiple times. " , " /home/bofh " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ClamukoMaxFileSize " , NULL , 0 , TYPE_SIZE , MATCH_SIZE , 5242880 , NULL , 0 , OPT_CLAMD , " Files larger than this value will not be scanned. " , " 5M " } ,
2008-12-17 21:42:54 +00:00
/* FIXME: mark these as private and don't output into clamd.conf/man */
2008-12-31 12:26:30 +00:00
{ " DevACOnly " , " dev-ac-only " , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " " , " " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " DevACDepth " , " dev-ac-depth " , 0 , TYPE_NUMBER , MATCH_NUMBER , - 1 , NULL , 0 , OPT_CLAMD | OPT_CLAMSCAN , " " , " " } ,
2008-12-17 21:42:54 +00:00
/* Freshclam-only entries */
/* FIXME: drop this entry and use LogFile */
2008-12-31 12:26:30 +00:00
{ " UpdateLogFile " , " log " , ' l ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " Save all reports to a log file. " , " /var/log/freshclam.log " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " DatabaseOwner " , " user " , ' u ' , TYPE_STRING , NULL , - 1 , CLAMAVUSER , FLAG_REQUIRED , OPT_FRESHCLAM , " When started by root freshclam will drop privileges and switch to the user \n defined in this option. " , CLAMAVUSER } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " Checks " , " checks " , ' c ' , TYPE_NUMBER , MATCH_NUMBER , 12 , NULL , 0 , OPT_FRESHCLAM , " This option defined how many times daily freshclam should check for \n a database update. " , " 24 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " DNSDatabaseInfo " , NULL , 0 , TYPE_STRING , NULL , - 1 , " current.cvd.clamav.net " , FLAG_REQUIRED , OPT_FRESHCLAM , " Use DNS to verify the virus database version. Freshclam uses DNS TXT records \n to verify the versions of the database and software itself. With this \n directive you can change the database verification domain. \n WARNING: Please don't change it unless you're configuring freshclam to use \n your own database verification domain. " , " current.cvd.clamav.net " } ,
2008-12-17 21:42:54 +00:00
/* FIXME: - add an inactive entry for db.XY.clamav.net for freshclam.conf
* purposes
* -
*/
2008-12-31 12:26:30 +00:00
{ " DatabaseMirror " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_FRESHCLAM , " FIXME " , " " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " MaxAttempts " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 3 , NULL , 0 , OPT_FRESHCLAM , " This option defines how many attempts freshclam should make before giving up. " , " 5 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ScriptedUpdates " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 1 , NULL , 0 , OPT_FRESHCLAM , " With this option you can control scripted updates. It's highly recommended to keep them enabled. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " CompressLocalDatabase " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_FRESHCLAM , " By default freshclam will keep the local databases (.cld) uncompressed to \n make their handling faster. With this option you can enable the compression. \n The change will take effect with the next database update. " , " " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " HTTPProxyServer " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " If you're behind a proxy, please enter its address here. " , " your-proxy " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " HTTPProxyPort " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , - 1 , NULL , 0 , OPT_FRESHCLAM , " HTTP proxy's port " , " 8080 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " HTTPProxyUsername " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " A user name for the HTTP proxy authentication. " , " username " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " HTTPProxyPassword " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " A password for the HTTP proxy authentication. " , " pass " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " HTTPUserAgent " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " If your servers are behind a firewall/proxy which does a User-Agent \n filtering you can use this option to force the use of a different \n User-Agent header. " , " default " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " NotifyClamd " , " daemon-notify " , 0 , TYPE_STRING , NULL , - 1 , CONFDIR " /clamd.conf " , 0 , OPT_FRESHCLAM , " Send the RELOAD command to clamd after a successful update. " , " yes " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " OnUpdateExecute " , " on-update-execute " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " Run a command after a successful database update. " , " command " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " OnErrorExecute " , " on-error-execute " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " Run a command when a database update error occurs. " , " command " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " OnOutdatedExecute " , " on-outdated-execute " , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " Run a command when freshclam reports an outdated version. \n In the command string %v will be replaced with the new version number. " , " command " } ,
2008-12-17 21:42:54 +00:00
/* FIXME: MATCH_IPADDR */
2008-12-31 12:26:30 +00:00
{ " LocalIPAddress " , " local-address " , ' a ' , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " With this option you can provide a client address for the database downlading. \n Useful for multi-homed systems. " , " aaa.bbb.ccc.ddd " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ConnectTimeout " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 30 , NULL , 0 , OPT_FRESHCLAM , " Timeout in seconds when connecting to database server. " , " 30 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " ReceiveTimeout " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , 30 , NULL , 0 , OPT_FRESHCLAM , " Timeout in seconds when reading from database server. " , " 30 " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " SubmitDetectionStats " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " " , " " } ,
2008-12-17 21:42:54 +00:00
2008-12-31 12:26:30 +00:00
{ " DetectionStatsCountry " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_FRESHCLAM , " When enabled freshclam will submit statistics to the ClamAV Project about \n the latest virus detections in your environment. The ClamAV maintainers \n will then use this data to determine what types of malware are the most \n detected in the field and in what geographic area they are. \n This feature requires LogTime and LogFile to be enabled in clamd.conf. " , " /path/to/clamd.conf " } ,
2008-12-17 21:42:54 +00:00
/* Deprecated options */
2008-12-31 12:26:30 +00:00
{ " MailMaxRecursion " , NULL , 0 , TYPE_NUMBER , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
{ " ArchiveMaxScanSize " , NULL , 0 , TYPE_SIZE , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
{ " ArchiveMaxRecursion " , NULL , 0 , TYPE_NUMBER , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
{ " ArchiveMaxFiles " , NULL , 0 , TYPE_NUMBER , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
{ " ArchiveMaxCompressionRatio " , NULL , 0 , TYPE_NUMBER , NULL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
{ " ArchiveBlockMax " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
{ " ArchiveLimitMemoryUsage " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_CLAMD | OPT_DEPRECATED , " " , " " } ,
2008-12-17 21:42:54 +00:00
/* Milter specific options */
2009-01-02 15:30:17 +00:00
{ " ClamdSocket " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_MILTER , " " , " " } ,
{ " MilterSocket " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER , " " , " " } ,
{ " LocalNet " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , FLAG_MULTIPLE , OPT_MILTER , " " , " " } ,
{ " OnClean " , NULL , 0 , TYPE_STRING , NULL , - 1 , " Accept " , 0 , OPT_MILTER , " " , " " } ,
{ " OnInfected " , NULL , 0 , TYPE_STRING , NULL , - 1 , " Quarantine " , 0 , OPT_MILTER , " " , " " } ,
{ " OnFail " , NULL , 0 , TYPE_STRING , NULL , - 1 , " Defer " , 0 , OPT_MILTER , " " , " " } ,
{ " AddHeader " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , 0 , NULL , 0 , OPT_MILTER , " " , " " } ,
{ " Chroot " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER , " " , " " } ,
{ " Whitelist " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER , " " , " " } ,
2008-12-17 21:42:54 +00:00
/* Deprecated milter options */
2009-01-02 15:30:17 +00:00
{ " ArchiveBlockEncrypted " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " DatabaseDirectory " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " Debug " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " DetectBrokenExecutables " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " LeaveTemporaryFiles " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " LocalSocket " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " MailFollowURLs " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " MaxScanSize " , NULL , 0 , TYPE_SIZE , MATCH_SIZE , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " MaxFiles " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " MaxRecursion " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " PhishingSignatures " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " ScanArchive " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " ScanHTML " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " ScanMail " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " ScanOLE2 " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " ScanPE " , NULL , 0 , TYPE_BOOL , MATCH_BOOL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " StreamMaxLength " , NULL , 0 , TYPE_SIZE , MATCH_SIZE , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " TCPAddr " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " TCPSocket " , NULL , 0 , TYPE_NUMBER , MATCH_NUMBER , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
{ " TemporaryDirectory " , NULL , 0 , TYPE_STRING , NULL , - 1 , NULL , 0 , OPT_MILTER | OPT_DEPRECATED , " " , " " } ,
2008-12-17 21:42:54 +00:00
{ NULL , NULL , 0 , 0 , NULL , 0 , NULL , 0 , 0 , NULL , NULL }
} ;
const struct optstruct * optget ( const struct optstruct * opts , const char * name )
{
while ( opts ) {
2008-12-18 14:24:43 +00:00
if ( ( opts - > name & & ! strcmp ( opts - > name , name ) ) | | ( opts - > cmd & & ! strcmp ( opts - > cmd , name ) ) )
2008-12-17 21:42:54 +00:00
return opts ;
opts = opts - > next ;
}
return NULL ;
}
static struct optstruct * optget_i ( struct optstruct * opts , const char * name )
{
while ( opts ) {
2008-12-18 14:24:43 +00:00
if ( ( opts - > name & & ! strcmp ( opts - > name , name ) ) | | ( opts - > cmd & & ! strcmp ( opts - > cmd , name ) ) )
2008-12-17 21:42:54 +00:00
return opts ;
opts = opts - > next ;
}
return NULL ;
}
/*
static void optprint ( const struct optstruct * opts )
{
const struct optstruct * h ;
printf ( " \n OPTIONS: \n \n " ) ;
while ( opts ) {
printf ( " OPT_NAME: %s \n " , opts - > name ) ;
printf ( " OPT_CMD: %s \n " , opts - > cmd ) ;
printf ( " OPT_STRARG: %s \n " , opts - > strarg ? opts - > strarg : " NONE " ) ;
printf ( " OPT_NUMARG: %d \n " , opts - > numarg ) ;
h = opts ;
while ( ( h = h - > nextarg ) ) {
printf ( " SUBARG_OPT_STRARG: %s \n " , h - > strarg ? h - > strarg : " NONE " ) ;
printf ( " SUBARG_OPT_NUMARG: %d \n " , h - > numarg ) ;
}
printf ( " ---------------- \n " ) ;
opts = opts - > next ;
}
}
*/
2009-01-22 14:19:47 +00:00
static int optadd ( struct optstruct * * opts , struct optstruct * * opts_last , const char * name , const char * cmd , const char * strarg , int numarg , int flags , int idx )
2008-12-17 21:42:54 +00:00
{
struct optstruct * newnode ;
newnode = ( struct optstruct * ) malloc ( sizeof ( struct optstruct ) ) ;
if ( ! newnode )
return - 1 ;
if ( name ) {
newnode - > name = strdup ( name ) ;
if ( ! newnode - > name ) {
free ( newnode ) ;
return - 1 ;
}
} else {
newnode - > name = NULL ;
}
if ( cmd ) {
newnode - > cmd = strdup ( cmd ) ;
if ( ! newnode - > cmd ) {
free ( newnode - > name ) ;
free ( newnode ) ;
return - 1 ;
}
} else {
newnode - > cmd = NULL ;
}
if ( strarg ) {
newnode - > strarg = strdup ( strarg ) ;
if ( ! newnode - > strarg ) {
free ( newnode - > cmd ) ;
free ( newnode - > name ) ;
free ( newnode ) ;
return - 1 ;
}
newnode - > enabled = 1 ;
} else {
newnode - > strarg = NULL ;
newnode - > enabled = 0 ;
}
newnode - > numarg = numarg ;
if ( numarg & & numarg ! = - 1 )
newnode - > enabled = 1 ;
newnode - > nextarg = NULL ;
newnode - > next = NULL ;
newnode - > active = 0 ;
2008-12-31 12:26:30 +00:00
newnode - > flags = flags ;
2008-12-17 21:42:54 +00:00
newnode - > idx = idx ;
2008-12-30 10:33:43 +00:00
newnode - > filename = NULL ;
2008-12-17 21:42:54 +00:00
2009-01-22 14:19:47 +00:00
if ( ! * opts_last ) {
newnode - > next = * opts ;
* opts = newnode ;
* opts_last = * opts ;
} else {
( * opts_last ) - > next = newnode ;
* opts_last = newnode ;
}
2008-12-17 21:42:54 +00:00
return 0 ;
}
static int optaddarg ( struct optstruct * opts , const char * name , const char * strarg , int numarg )
{
struct optstruct * pt , * h , * new ;
if ( ! ( pt = optget_i ( opts , name ) ) ) {
fprintf ( stderr , " ERROR: optaddarg: Unregistered option %s \n " , name ) ;
return - 1 ;
}
2008-12-31 12:26:30 +00:00
if ( pt - > flags & FLAG_MULTIPLE ) {
2008-12-17 21:42:54 +00:00
if ( ! pt - > active ) {
if ( strarg ) {
2008-12-22 15:01:59 +00:00
free ( pt - > strarg ) ;
2008-12-17 21:42:54 +00:00
pt - > strarg = strdup ( strarg ) ;
if ( ! pt - > strarg ) {
fprintf ( stderr , " ERROR: optaddarg: strdup() failed \n " ) ;
return - 1 ;
}
}
pt - > numarg = numarg ;
} else {
new = ( struct optstruct * ) calloc ( 1 , sizeof ( struct optstruct ) ) ;
if ( ! new ) {
fprintf ( stderr , " ERROR: optaddarg: malloc() failed \n " ) ;
return - 1 ;
}
if ( strarg ) {
new - > strarg = strdup ( strarg ) ;
if ( ! new - > strarg ) {
fprintf ( stderr , " ERROR: optaddarg: strdup() failed \n " ) ;
free ( new ) ;
return - 1 ;
}
}
new - > numarg = numarg ;
h = pt ;
while ( h - > nextarg )
h = h - > nextarg ;
h - > nextarg = new ;
}
} else {
2008-12-18 19:42:53 +00:00
if ( pt - > active )
return 0 ;
2008-12-17 21:42:54 +00:00
if ( strarg ) {
2008-12-22 15:01:59 +00:00
free ( pt - > strarg ) ;
2008-12-17 21:42:54 +00:00
pt - > strarg = strdup ( strarg ) ;
if ( ! pt - > strarg ) {
fprintf ( stderr , " ERROR: optaddarg: strdup() failed \n " ) ;
return - 1 ;
}
}
pt - > numarg = numarg ;
}
pt - > active = 1 ;
if ( pt - > strarg | | ( pt - > numarg & & pt - > numarg ! = - 1 ) )
pt - > enabled = 1 ;
return 0 ;
}
void optfree ( struct optstruct * opts )
{
struct optstruct * h , * a ;
2009-01-19 19:41:27 +00:00
int i ;
2008-12-17 21:42:54 +00:00
2009-01-19 19:41:27 +00:00
if ( opts & & opts - > filename ) {
for ( i = 0 ; opts - > filename [ i ] ; i + + )
free ( opts - > filename [ i ] ) ;
2008-12-30 10:33:43 +00:00
free ( opts - > filename ) ;
2009-01-19 19:41:27 +00:00
}
2008-12-30 10:33:43 +00:00
2008-12-17 21:42:54 +00:00
while ( opts ) {
a = opts - > nextarg ;
while ( a ) {
if ( a - > strarg ) {
free ( a - > name ) ;
free ( a - > cmd ) ;
free ( a - > strarg ) ;
h = a ;
a = a - > nextarg ;
free ( h ) ;
} else {
a = a - > nextarg ;
}
}
free ( opts - > name ) ;
free ( opts - > cmd ) ;
free ( opts - > strarg ) ;
h = opts ;
opts = opts - > next ;
free ( h ) ;
}
return ;
}
2009-01-02 17:04:11 +00:00
struct optstruct * optparse ( const char * cfgfile , int argc , char * * argv , int verbose , int toolmask , int ignore , struct optstruct * oldopts )
2008-12-17 21:42:54 +00:00
{
FILE * fs = NULL ;
const struct clam_option * optentry ;
char * pt ;
const char * name = NULL , * arg ;
int i , err = 0 , lc = 0 , sc = 0 , opt_index , line = 0 , ret , numarg ;
2009-01-22 14:19:47 +00:00
struct optstruct * opts = NULL , * opts_last = NULL , * opt ;
2008-12-17 21:42:54 +00:00
char buff [ 512 ] ;
struct option longopts [ MAXCMDOPTS ] ;
char shortopts [ MAXCMDOPTS ] ;
regex_t regex ;
if ( oldopts )
opts = oldopts ;
shortopts [ sc + + ] = ' : ' ;
for ( i = 0 ; ; i + + ) {
optentry = & clam_options [ i ] ;
if ( ! optentry - > name & & ! optentry - > longopt )
break ;
2009-01-22 14:19:47 +00:00
if ( ( ( optentry - > owner & toolmask ) & & ( ( optentry - > owner & toolmask ) ! = OPT_DEPRECATED ) ) | | ( ignore & & ( optentry - > owner & ignore ) ) ) {
if ( ! oldopts & & optadd ( & opts , & opts_last , optentry - > name , optentry - > longopt , optentry - > strarg , optentry - > numarg , optentry - > flags , i ) < 0 ) {
2008-12-17 21:42:54 +00:00
fprintf ( stderr , " ERROR: optparse: Can't register new option (not enough memory) \n " ) ;
optfree ( opts ) ;
return NULL ;
}
if ( ! cfgfile ) {
if ( optentry - > longopt ) {
if ( lc > = MAXCMDOPTS ) {
fprintf ( stderr , " ERROR: optparse: longopts[] is too small \n " ) ;
optfree ( opts ) ;
return NULL ;
}
longopts [ lc ] . name = optentry - > longopt ;
2008-12-31 12:26:30 +00:00
if ( ! ( optentry - > flags & FLAG_REQUIRED ) & & ( optentry - > argtype = = TYPE_BOOL | | optentry - > strarg ) )
2008-12-17 21:42:54 +00:00
longopts [ lc ] . has_arg = 2 ;
else
longopts [ lc ] . has_arg = 1 ;
longopts [ lc ] . flag = NULL ;
longopts [ lc + + ] . val = optentry - > shortopt ;
}
if ( optentry - > shortopt ) {
2009-01-02 11:54:08 +00:00
if ( sc + 2 > = MAXCMDOPTS ) {
2008-12-17 21:42:54 +00:00
fprintf ( stderr , " ERROR: optparse: shortopts[] is too small \n " ) ;
optfree ( opts ) ;
return NULL ;
}
shortopts [ sc + + ] = optentry - > shortopt ;
2009-01-02 11:54:08 +00:00
shortopts [ sc + + ] = ' : ' ;
if ( ! ( optentry - > flags & FLAG_REQUIRED ) & & ( optentry - > argtype = = TYPE_BOOL | | optentry - > strarg ) )
2008-12-17 21:42:54 +00:00
shortopts [ sc + + ] = ' : ' ;
}
}
}
}
if ( cfgfile ) {
if ( ( fs = fopen ( cfgfile , " rb " ) ) = = NULL ) {
/* don't print error messages here! */
optfree ( opts ) ;
return NULL ;
}
} else {
if ( MAX ( sc , lc ) > MAXCMDOPTS ) {
fprintf ( stderr , " ERROR: optparse: (short|long)opts[] is too small \n " ) ;
optfree ( opts ) ;
return NULL ;
}
shortopts [ sc ] = 0 ;
longopts [ lc ] . name = NULL ;
longopts [ lc ] . flag = NULL ;
longopts [ lc ] . has_arg = longopts [ lc ] . val = 0 ;
}
while ( 1 ) {
if ( cfgfile ) {
if ( ! fgets ( buff , sizeof ( buff ) , fs ) )
break ;
line + + ;
if ( strlen ( buff ) < = 2 | | buff [ 0 ] = = ' # ' )
continue ;
if ( ! strncmp ( " Example " , buff , 7 ) ) {
if ( verbose )
fprintf ( stderr , " ERROR: Please edit the example config file %s \n " , cfgfile ) ;
err = 1 ;
break ;
}
if ( ! ( pt = strchr ( buff , ' ' ) ) ) {
if ( verbose )
fprintf ( stderr , " ERROR: Missing argument for option at line %d \n " , line ) ;
err = 1 ;
break ;
}
name = buff ;
* pt + + = 0 ;
for ( i = 0 ; i < ( int ) strlen ( pt ) - 1 & & pt [ i ] = = ' ' ; i + + ) ;
pt + = i ;
if ( ( i = strlen ( pt ) ) & & pt [ i - 1 ] = = ' \n ' )
pt [ i - - - 1 ] = 0 ;
if ( ! i ) {
if ( verbose )
fprintf ( stderr , " ERROR: Missing argument for option at line %d \n " , line ) ;
err = 1 ;
break ;
}
arg = pt ;
if ( * arg = = ' " ' ) {
arg + + ; pt + + ;
pt = strrchr ( pt , ' " ' ) ;
if ( ! pt ) {
if ( verbose )
fprintf ( stderr , " ERROR: Missing closing parenthesis in option %s at line %d \n " , name , line ) ;
err = 1 ;
break ;
}
* pt = 0 ;
if ( ! strlen ( arg ) ) {
if ( verbose )
fprintf ( stderr , " ERROR: Empty argument for option %s at line %d \n " , name , line ) ;
err = 1 ;
break ;
}
}
} else {
opt_index = 0 ;
ret = getopt_long ( argc , argv , shortopts , longopts , & opt_index ) ;
if ( ret = = - 1 )
break ;
if ( ret = = ' : ' ) {
fprintf ( stderr , " ERROR: Incomplete option passed (missing argument) \n " ) ;
err = 1 ;
break ;
} else if ( ! ret | | strchr ( shortopts , ret ) ) {
name = NULL ;
if ( ret ) {
for ( i = 0 ; i < lc ; i + + ) {
if ( ret = = longopts [ i ] . val ) {
name = longopts [ i ] . name ;
break ;
}
}
} else {
name = longopts [ opt_index ] . name ;
}
if ( ! name ) {
fprintf ( stderr , " ERROR: optparse: No corresponding long name for option '-%c' \n " , ( char ) ret ) ;
err = 1 ;
break ;
}
optarg ? ( arg = optarg ) : ( arg = NULL ) ;
} else {
fprintf ( stderr , " ERROR: Unknown option passed \n " ) ;
err = 1 ;
break ;
}
}
if ( ! name ) {
fprintf ( stderr , " ERROR: Problem parsing options (name == NULL) \n " ) ;
err = 1 ;
break ;
}
opt = optget_i ( opts , name ) ;
if ( ! opt ) {
if ( cfgfile ) {
if ( verbose )
fprintf ( stderr , " ERROR: Parse error at line %d: Unknown option %s \n " , line , name ) ;
}
err = 1 ;
break ;
}
optentry = & clam_options [ opt - > idx ] ;
2008-12-30 21:16:02 +00:00
if ( ignore & & ( optentry - > owner & ignore ) & & ! ( optentry - > owner & toolmask ) ) {
if ( cfgfile ) {
if ( verbose )
fprintf ( stderr , " WARNING: Ignoring unsupported option %s at line %u \n " , opt - > name , line ) ;
} else {
if ( verbose ) {
if ( optentry - > shortopt )
fprintf ( stderr , " WARNING: Ignoring unsupported option --%s (-%c) \n " , optentry - > longopt , optentry - > shortopt ) ;
else
fprintf ( stderr , " WARNING: Ignoring unsupported option --%s \n " , optentry - > longopt ) ;
}
}
continue ;
}
2008-12-17 21:42:54 +00:00
if ( optentry - > owner & OPT_DEPRECATED ) {
if ( toolmask & OPT_DEPRECATED ) {
2009-01-22 14:19:47 +00:00
if ( optaddarg ( opts , name , " foo " , 1 ) < 0 ) {
if ( cfgfile )
fprintf ( stderr , " ERROR: Can't register argument for option %s \n " , name ) ;
else
fprintf ( stderr , " ERROR: Can't register argument for option --%s \n " , optentry - > longopt ) ;
err = 1 ;
break ;
}
2008-12-17 21:42:54 +00:00
} else {
if ( cfgfile ) {
if ( verbose )
fprintf ( stderr , " WARNING: Ignoring deprecated option %s at line %u \n " , opt - > name , line ) ;
} else {
if ( verbose ) {
if ( optentry - > shortopt )
fprintf ( stderr , " WARNING: Ignoring deprecated option --%s (-%c) \n " , optentry - > longopt , optentry - > shortopt ) ;
else
fprintf ( stderr , " WARNING: Ignoring deprecated option --%s \n " , optentry - > longopt ) ;
}
}
}
2009-01-22 14:19:47 +00:00
continue ;
2008-12-17 21:42:54 +00:00
}
2008-12-31 12:26:30 +00:00
if ( ! cfgfile & & ! arg & & optentry - > argtype = = TYPE_BOOL ) {
2008-12-17 21:42:54 +00:00
arg = " yes " ; /* default to yes */
} else if ( optentry - > regex ) {
if ( cli_regcomp ( & regex , optentry - > regex , REG_EXTENDED | REG_NOSUB ) ) {
fprintf ( stderr , " ERROR: optparse: Can't compile regular expression %s for option %s \n " , optentry - > regex , name ) ;
err = 1 ;
break ;
}
ret = cli_regexec ( & regex , arg , 0 , NULL , 0 ) ;
cli_regfree ( & regex ) ;
if ( ret = = REG_NOMATCH ) {
if ( cfgfile ) {
fprintf ( stderr , " ERROR: Incorrect argument format for option %s \n " , name ) ;
} else {
if ( optentry - > shortopt )
fprintf ( stderr , " ERROR: Incorrect argument format for option --%s (-%c) \n " , optentry - > longopt , optentry - > shortopt ) ;
else
fprintf ( stderr , " ERROR: Incorrect argument format for option --%s \n " , optentry - > longopt ) ;
}
err = 1 ;
break ;
}
}
numarg = - 1 ;
switch ( optentry - > argtype ) {
2008-12-31 12:26:30 +00:00
case TYPE_STRING :
2008-12-18 19:42:53 +00:00
if ( ! arg )
arg = optentry - > strarg ;
2008-12-17 21:42:54 +00:00
if ( ! cfgfile & & ! strlen ( arg ) ) {
if ( optentry - > shortopt )
fprintf ( stderr , " ERROR: Option --%s (-%c) requires a non-empty string argument \n " , optentry - > longopt , optentry - > shortopt ) ;
else
fprintf ( stderr , " ERROR: Option --%s requires a non-empty string argument \n " , optentry - > longopt ) ;
err = 1 ;
break ;
}
break ;
2008-12-31 12:26:30 +00:00
case TYPE_NUMBER :
2008-12-17 21:42:54 +00:00
numarg = atoi ( arg ) ;
arg = NULL ;
break ;
2008-12-31 12:26:30 +00:00
case TYPE_SIZE :
2008-12-17 21:42:54 +00:00
if ( sscanf ( arg , " %d " , & numarg ) ! = 1 ) {
if ( cfgfile ) {
fprintf ( stderr , " ERROR: Can't parse numerical argument for option %s \n " , name ) ;
} else {
if ( optentry - > shortopt )
fprintf ( stderr , " ERROR: Can't parse numerical argument for option --%s (-%c) \n " , optentry - > longopt , optentry - > shortopt ) ;
else
fprintf ( stderr , " ERROR: Can't parse numerical argument for option --%s \n " , optentry - > longopt ) ;
}
err = 1 ;
break ;
}
i = strlen ( arg ) - 1 ;
if ( arg [ i ] = = ' M ' | | arg [ i ] = = ' m ' )
numarg * = 1048576 ;
else if ( arg [ i ] = = ' K ' | | arg [ i ] = = ' k ' )
numarg * = 1024 ;
else
numarg = atoi ( arg ) ;
arg = NULL ;
break ;
2008-12-31 12:26:30 +00:00
case TYPE_BOOL :
2008-12-17 21:42:54 +00:00
if ( ! strcasecmp ( arg , " yes " ) | | ! strcmp ( arg , " 1 " ) | | ! strcasecmp ( arg , " true " ) )
numarg = 1 ;
else
numarg = 0 ;
arg = NULL ;
break ;
}
if ( err )
break ;
if ( optaddarg ( opts , name , arg , numarg ) < 0 ) {
if ( cfgfile )
fprintf ( stderr , " ERROR: Can't register argument for option %s \n " , name ) ;
else
fprintf ( stderr , " ERROR: Can't register argument for option --%s \n " , optentry - > longopt ) ;
err = 1 ;
break ;
}
}
if ( fs )
fclose ( fs ) ;
if ( err ) {
optfree ( opts ) ;
return NULL ;
}
2008-12-30 10:33:43 +00:00
if ( ! cfgfile & & ( optind < argc ) ) {
2009-01-19 19:41:27 +00:00
opts - > filename = ( char * * ) calloc ( argc - optind + 1 , sizeof ( char * ) ) ;
2008-12-30 10:33:43 +00:00
if ( ! opts - > filename ) {
fprintf ( stderr , " ERROR: optparse: calloc failed \n " ) ;
2008-12-31 14:28:02 +00:00
optfree ( opts ) ;
2008-12-30 10:33:43 +00:00
return NULL ;
}
for ( i = optind ; i < argc ; i + + ) {
2009-01-19 19:41:27 +00:00
opts - > filename [ i - optind ] = strdup ( argv [ i ] ) ;
if ( ! opts - > filename [ i - optind ] ) {
fprintf ( stderr , " ERROR: optparse: strdup failed \n " ) ;
optfree ( opts ) ;
return NULL ;
}
2008-12-30 10:33:43 +00:00
}
}
2008-12-17 21:42:54 +00:00
/* optprint(opts); */
return opts ;
}