2 * inoclam - Inotify+ClamAV virus scanner
3 * Copyright (C) 2007, 2008, 2009 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 version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <libdaemon/dlog.h>
23 #include <sys/types.h>
34 #include "inotify.hxx"
40 file_email_subject
= NULL
;
41 virus_email_subject
= NULL
;
47 void config::setDirectory(char *new_dir
)
52 char *config::getDirectory()
57 void config::setFileEMailSubject(char *subject
)
59 file_email_subject
= subject
;
62 char *config::getFileEMailSubject()
64 return file_email_subject
;
67 void config::setVirusEMailSubject(char *subject
)
69 virus_email_subject
= subject
;
72 char *config::getVirusEMailSubject()
74 return virus_email_subject
;
77 void config::setFileEMailEnabled(cfg_bool_t enabled
)
79 file_email_enabled
= enabled
;
82 cfg_bool_t
config::getFileEMailEnabled()
84 return file_email_enabled
;
87 void config::setVirusEMailEnabled(cfg_bool_t enabled
)
89 virus_email_enabled
= enabled
;
93 cfg_bool_t
config::getVirusEMailEnabled()
95 return virus_email_enabled
;
98 void config::setVirusRemovalEnabled(cfg_bool_t enabled
)
100 virus_removal_enabled
= enabled
;
103 cfg_bool_t
config::getVirusRemovalEnabled()
105 return virus_removal_enabled
;
108 char *config::getHost()
113 void config::setHost(char *h
)
118 int config::getPort()
123 void config::setPort(int p
)
128 char *config::getFrom()
133 void config::setFrom(char *f
)
138 std::list
< char *>*config::getTo()
143 void config::setTo(std::list
< char *>*t
)
151 for (std::list
< char *>::iterator itr
= to
->begin(); itr
!= to
->end(); ++itr
) {
162 if (virus_email_subject
) {
163 free(virus_email_subject
);
164 virus_email_subject
= NULL
;
167 if (file_email_subject
) {
168 free(file_email_subject
);
169 file_email_subject
= NULL
;
184 * The configuration file path.
189 * Parses an inoclam.conf configuration file.
191 std::list
< config::config
* >*config_parse()
193 std::list
< config::config
* >*conf_list
;
194 conf_list
= new std::list
< config::config
* >;
201 cfg_opt_t file_opts
[] = {
202 CFG_BOOL((char*)"email_alert", cfg_false
, CFGF_NONE
),
203 CFG_STR((char*)"email_subject", (char*)"[inoclam] File Created/Changed", CFGF_NONE
),
207 cfg_opt_t virus_opts
[] = {
208 CFG_BOOL((char*)"auto_remove", cfg_true
, CFGF_NONE
),
209 CFG_BOOL((char*)"email_alert", cfg_true
, CFGF_NONE
),
210 CFG_STR((char*)"email_subject", (char*)"[inoclam] Virus Detected", CFGF_NONE
),
214 cfg_opt_t smtp_opts
[] = {
215 CFG_STR((char*)"host", (char*)"localhost", CFGF_NONE
),
216 CFG_INT((char*)"port", 25, CFGF_NONE
),
217 CFG_STR((char*)"from", (char*)"root@localhost", CFGF_NONE
),
218 CFG_STR_LIST((char*)"to", (char*)"{root@localhost}", CFGF_NONE
),
222 cfg_opt_t watch_opts
[] = {
223 CFG_STR((char*)"directory", (char*)"/tmp", CFGF_NONE
),
224 CFG_SEC((char*)"file", file_opts
, CFGF_NONE
),
225 CFG_SEC((char*)"virus", virus_opts
, CFGF_NONE
),
226 CFG_SEC((char*)"smtp", smtp_opts
, CFGF_NONE
),
231 CFG_SEC((char*)"watch", watch_opts
, CFGF_MULTI
),
237 cfg
= cfg_init(opts
, 0);
239 daemon_log(LOG_ERR
, "cfg_init failed!");
243 rc
= cfg_parse(cfg
, configfile
);
244 if (rc
== CFG_PARSE_ERROR
) {
245 daemon_log(LOG_ERR
, "parser error '%s'", configfile
);
248 n
= cfg_size(cfg
, "watch");
249 for (i
= 0; i
< n
; i
++) {
250 config::config
* conf
;
251 conf
= new config::config();
253 cfg_t
*smtp_cfg
= NULL
;
254 cfg_t
*file_cfg
= NULL
;
255 cfg_t
*virus_cfg
= NULL
;
256 cfg_t
*watch_cfg
= cfg_getnsec(cfg
, "watch", i
);
258 conf
->setDirectory(strdup(cfg_getstr(watch_cfg
, "directory")));
260 file_cfg
= cfg_getsec(watch_cfg
, "file");
261 conf
->setFileEMailSubject(strdup(cfg_getstr(file_cfg
, "email_subject")));
262 conf
->setFileEMailEnabled(cfg_getbool(file_cfg
, "email_alert"));
264 virus_cfg
= cfg_getsec(watch_cfg
, "virus");
265 conf
->setVirusEMailSubject(strdup(cfg_getstr(virus_cfg
, "email_subject")));
266 conf
->setVirusEMailEnabled(cfg_getbool(virus_cfg
, "email_alert"));
267 conf
->setVirusRemovalEnabled(cfg_getbool(virus_cfg
, "auto_remove"));
269 smtp_cfg
= cfg_getsec(watch_cfg
, "smtp");
270 conf
->setHost(strdup(cfg_getstr(smtp_cfg
, "host")));
271 conf
->setPort(cfg_getint(smtp_cfg
, "port"));
272 conf
->setFrom(strdup(cfg_getstr(smtp_cfg
, "from")));
275 std::list
< char *>*to
;
276 to
= new std::list
< char *>;
277 for (j
= 0; j
< cfg_size(smtp_cfg
, "to"); j
++) {
278 to
->push_front(strdup(cfg_getnstr(smtp_cfg
, "to", j
)));
282 conf_list
->push_front(conf
);