2 * inoclam - Inotify+ClamAV virus scanner
3 * Copyright (C) 2007 Vermont Department of Taxes
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Tom Cort <tom.cort@state.vt.us>
21 * Matt Gagne <matt.gagne@state.vt.us>
26 #include <libdaemon/dlog.h>
28 #include <sys/types.h>
39 #include "inotify.hxx"
44 file_email_subject
= NULL
;
45 virus_email_subject
= NULL
;
51 void config::setDirectory(char *new_dir
) {
55 char *config::getDirectory() {
59 void config::setFileEMailSubject(char *subject
) {
60 file_email_subject
= subject
;
63 char *config::getFileEMailSubject() {
64 return file_email_subject
;
67 void config::setVirusEMailSubject(char *subject
) {
68 virus_email_subject
= subject
;
71 char *config::getVirusEMailSubject() {
72 return virus_email_subject
;
75 void config::setFileEMailEnabled(cfg_bool_t enabled
) {
76 file_email_enabled
= enabled
;
79 cfg_bool_t
config::getFileEMailEnabled() {
80 return file_email_enabled
;
83 void config::setVirusEMailEnabled(cfg_bool_t enabled
) {
84 virus_email_enabled
= enabled
;
88 cfg_bool_t
config::getVirusEMailEnabled() {
89 return virus_email_enabled
;
92 void config::setVirusRemovalEnabled(cfg_bool_t enabled
) {
93 virus_removal_enabled
= enabled
;
96 cfg_bool_t
config::getVirusRemovalEnabled() {
97 return virus_removal_enabled
;
100 char *config::getHost() {
104 void config::setHost(char *h
) {
108 int config::getPort() {
112 void config::setPort(int p
) {
116 char *config::getFrom() {
120 void config::setFrom(char *f
) {
124 std::list
<char*> *config::getTo() {
128 void config::setTo(std::list
<char*> *t
) {
134 for (std::list
<char*>::iterator itr
= to
->begin(); itr
!= to
->end(); ++itr
) {
145 if (virus_email_subject
) {
146 free(virus_email_subject
);
147 virus_email_subject
= NULL
;
150 if (file_email_subject
) {
151 free(file_email_subject
);
152 file_email_subject
= NULL
;
167 * Parses an inoclam.conf configuration file.
169 std::list
<config::config
*> *config_parse()
171 std::list
<config::config
*> *conf_list
;
172 conf_list
= new std::list
<config::config
*>;
179 cfg_opt_t file_opts
[] = {
180 CFG_BOOL("email_alert", cfg_false
, CFGF_NONE
),
181 CFG_STR("email_subject", "[inoclam] File Created/Changed", CFGF_NONE
),
185 cfg_opt_t virus_opts
[] = {
186 CFG_BOOL("auto_remove", cfg_true
, CFGF_NONE
),
187 CFG_BOOL("email_alert", cfg_true
, CFGF_NONE
),
188 CFG_STR("email_subject", "[inoclam] Virus Detected", CFGF_NONE
),
192 cfg_opt_t smtp_opts
[] = {
193 CFG_STR("host", "localhost", CFGF_NONE
),
194 CFG_INT("port", 25, CFGF_NONE
),
195 CFG_STR("from", "root@localhost", CFGF_NONE
),
196 CFG_STR_LIST("to", "{root@localhost}", CFGF_NONE
),
200 cfg_opt_t watch_opts
[] = {
201 CFG_STR("directory", "/tmp", CFGF_NONE
),
202 CFG_SEC("file", file_opts
, CFGF_NONE
),
203 CFG_SEC("virus", virus_opts
, CFGF_NONE
),
204 CFG_SEC("smtp", smtp_opts
, CFGF_NONE
),
209 CFG_SEC("watch", watch_opts
, CFGF_MULTI
),
215 cfg
= cfg_init(opts
, 0);
217 daemon_log(LOG_ERR
, "cfg_init failed!");
221 rc
= cfg_parse(cfg
, DEFAULT_CONFIGFILE
);
222 if (rc
== CFG_PARSE_ERROR
) {
223 daemon_log(LOG_ERR
, "parser error '%s'", DEFAULT_CONFIGFILE
);
226 n
= cfg_size(cfg
, "watch");
227 for(i
= 0; i
< n
; i
++) {
228 config::config
*conf
;
229 conf
= new config::config();
231 cfg_t
*smtp_cfg
= NULL
;
232 cfg_t
*file_cfg
= NULL
;
233 cfg_t
*virus_cfg
= NULL
;
234 cfg_t
*watch_cfg
= cfg_getnsec(cfg
, "watch", i
);
236 conf
->setDirectory(strdup(cfg_getstr(watch_cfg
, "directory")));
238 file_cfg
= cfg_getsec(watch_cfg
, "file");
239 conf
->setFileEMailSubject(strdup(cfg_getstr(file_cfg
, "email_subject")));
240 conf
->setFileEMailEnabled(cfg_getbool(file_cfg
, "email_alert"));
242 virus_cfg
= cfg_getsec(watch_cfg
, "virus");
243 conf
->setVirusEMailSubject(strdup(cfg_getstr(virus_cfg
, "email_subject")));
244 conf
->setVirusEMailEnabled(cfg_getbool(virus_cfg
, "email_alert"));
245 conf
->setVirusRemovalEnabled(cfg_getbool(virus_cfg
, "auto_remove"));
247 smtp_cfg
= cfg_getsec(watch_cfg
, "smtp");
248 conf
->setHost(strdup(cfg_getstr(smtp_cfg
, "host")));
249 conf
->setPort(cfg_getint(smtp_cfg
, "port"));
250 conf
->setFrom(strdup(cfg_getstr(smtp_cfg
, "from")));
253 std::list
<char*> *to
;
254 to
= new std::list
<char*>;
255 for (j
= 0; j
< cfg_size(smtp_cfg
, "to"); j
++) {
256 to
->push_front(strdup(cfg_getnstr(smtp_cfg
, "to", j
)));
260 conf_list
->push_front(conf
);