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>
25 #include <libdaemon/dlog.h>
27 #include <sys/types.h>
38 #include "inotify.hxx"
46 virus_removal_enabled
= cfg_false
;
47 smtp_enabled
= cfg_true
;
53 smtp_subject_virus
= NULL
;
54 smtp_subject_file
= NULL
;
58 * Checks if the configuration file exists as a regular file.
59 * @return Returns 1 if the file exists and is regular, else 0.
61 int config::config_file_exists()
65 /* No config file defined - NULL Pointer Check */
66 if (!DEFAULT_CONFIGFILE
) {
71 if (stat(DEFAULT_CONFIGFILE
, &s
) < 0) {
75 /* File is a regular file? */
76 if (!S_ISREG(s
.st_mode
)) {
84 * Release any resources that hold configuration information.
85 * This function effectively resets all configurable values.
86 * It should be called at the end of the program.
88 void config::config_free()
90 if (watch_dir
!= NULL
) {
95 virus_removal_enabled
= cfg_true
;
97 smtp_enabled
= cfg_true
;
99 if (smtp_host
!= NULL
) {
106 if (smtp_to
!= NULL
) {
111 if (smtp_from
!= NULL
) {
116 if (smtp_subject_virus
!= NULL
) {
117 free(smtp_subject_virus
);
118 smtp_subject_virus
= NULL
;
121 if (smtp_subject_file
!= NULL
) {
122 free(smtp_subject_file
);
123 smtp_subject_file
= NULL
;
129 * Examines each value of the current configuration.
130 * If a value was not set, it is set to the default.
132 void config::config_with_defaults()
134 if (watch_dir
== NULL
) {
135 watch_dir
= strdup(WATCH_DIR
);
138 if (smtp_host
== NULL
) {
139 smtp_host
= strdup(SMTP_HOST
);
142 if (smtp_port
== 0) {
143 smtp_port
= SMTP_PORT
;
146 if (smtp_to
== NULL
) {
147 smtp_to
= strdup(SMTP_TO
);
150 if (smtp_from
== NULL
) {
151 smtp_from
= strdup(SMTP_FROM
);
154 if (smtp_subject_virus
== NULL
) {
155 smtp_subject_virus
= strdup(SMTP_SUBJECT_VIRUS
);
158 if (smtp_subject_file
== NULL
) {
159 smtp_subject_file
= strdup(SMTP_SUBJECT_FILE
);
165 * Parses an inoclam.conf configuration file.
175 CFG_SIMPLE_STR("watch_dir", &watch_dir
),
176 CFG_SIMPLE_BOOL("virus_removal_enabled", &virus_removal_enabled
),
177 CFG_SIMPLE_BOOL("smtp_enabled", &smtp_enabled
),
178 CFG_SIMPLE_STR("smtp_host", &smtp_host
),
179 CFG_SIMPLE_INT("smtp_port", &smtp_port
),
180 CFG_SIMPLE_STR("smtp_to", &smtp_to
),
181 CFG_SIMPLE_STR("smtp_from", &smtp_from
),
182 CFG_SIMPLE_STR("smtp_subject_virus", &smtp_subject_virus
),
183 CFG_SIMPLE_STR("smtp_subject_file", &smtp_subject_file
),
189 if (!config_file_exists()) {
190 daemon_log(LOG_INFO
, "Configuration file '%s' not found.", DEFAULT_CONFIGFILE
);
191 config_with_defaults();
195 cfg
= cfg_init(opts
, 0);
197 daemon_log(LOG_ERR
, "cfg_init failed!");
198 config_with_defaults();
202 rc
= cfg_parse(cfg
, DEFAULT_CONFIGFILE
);
203 if (rc
== CFG_PARSE_ERROR
) {
204 daemon_log(LOG_ERR
, "parser error '%s'", DEFAULT_CONFIGFILE
);
212 config_with_defaults();
215 cfg_bool_t
config::getSMTPEnabled()
220 cfg_bool_t
config::getVirusRemovalEnabled()
222 return virus_removal_enabled
;
225 char *config::getHost()
230 int config::getPort()
235 char *config::getTo()
240 char *config::getFrom()
245 char *config::getVirusSubject()
247 return smtp_subject_virus
;
250 char *config::getFileSubject()
252 return smtp_subject_file
;
255 char *config::getWatchDir()