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_virus
= cfg_true
;
48 smtp_enabled_file
= cfg_false
;
54 smtp_subject_virus
= NULL
;
55 smtp_subject_file
= NULL
;
59 * Checks if the configuration file exists as a regular file.
60 * @return Returns 1 if the file exists and is regular, else 0.
62 int config::config_file_exists()
66 /* No config file defined - NULL Pointer Check */
67 if (!DEFAULT_CONFIGFILE
) {
72 if (stat(DEFAULT_CONFIGFILE
, &s
) < 0) {
76 /* File is a regular file? */
77 if (!S_ISREG(s
.st_mode
)) {
85 * Release any resources that hold configuration information.
86 * This function effectively resets all configurable values.
87 * It should be called at the end of the program.
89 void config::config_free()
91 if (watch_dir
!= NULL
) {
96 virus_removal_enabled
= cfg_true
;
98 smtp_enabled_virus
= cfg_true
;
100 smtp_enabled_file
= cfg_true
;
102 if (smtp_host
!= NULL
) {
109 if (smtp_to
!= NULL
) {
114 if (smtp_from
!= NULL
) {
119 if (smtp_subject_virus
!= NULL
) {
120 free(smtp_subject_virus
);
121 smtp_subject_virus
= NULL
;
124 if (smtp_subject_file
!= NULL
) {
125 free(smtp_subject_file
);
126 smtp_subject_file
= NULL
;
132 * Examines each value of the current configuration.
133 * If a value was not set, it is set to the default.
135 void config::config_with_defaults()
137 if (watch_dir
== NULL
) {
138 watch_dir
= strdup(WATCH_DIR
);
141 if (smtp_host
== NULL
) {
142 smtp_host
= strdup(SMTP_HOST
);
145 if (smtp_port
== 0) {
146 smtp_port
= SMTP_PORT
;
149 if (smtp_to
== NULL
) {
150 smtp_to
= strdup(SMTP_TO
);
153 if (smtp_from
== NULL
) {
154 smtp_from
= strdup(SMTP_FROM
);
157 if (smtp_subject_virus
== NULL
) {
158 smtp_subject_virus
= strdup(SMTP_SUBJECT_VIRUS
);
161 if (smtp_subject_file
== NULL
) {
162 smtp_subject_file
= strdup(SMTP_SUBJECT_FILE
);
168 * Parses an inoclam.conf configuration file.
178 CFG_SIMPLE_STR("watch_dir", &watch_dir
),
179 CFG_SIMPLE_BOOL("virus_removal_enabled", &virus_removal_enabled
),
180 CFG_SIMPLE_BOOL("smtp_enabled_file", &smtp_enabled_file
),
181 CFG_SIMPLE_BOOL("smtp_enabled_virus", &smtp_enabled_virus
),
182 CFG_SIMPLE_STR("smtp_host", &smtp_host
),
183 CFG_SIMPLE_INT("smtp_port", &smtp_port
),
184 CFG_SIMPLE_STR("smtp_to", &smtp_to
),
185 CFG_SIMPLE_STR("smtp_from", &smtp_from
),
186 CFG_SIMPLE_STR("smtp_subject_virus", &smtp_subject_virus
),
187 CFG_SIMPLE_STR("smtp_subject_file", &smtp_subject_file
),
193 if (!config_file_exists()) {
194 daemon_log(LOG_INFO
, "Configuration file '%s' not found.", DEFAULT_CONFIGFILE
);
195 config_with_defaults();
199 cfg
= cfg_init(opts
, 0);
201 daemon_log(LOG_ERR
, "cfg_init failed!");
202 config_with_defaults();
206 rc
= cfg_parse(cfg
, DEFAULT_CONFIGFILE
);
207 if (rc
== CFG_PARSE_ERROR
) {
208 daemon_log(LOG_ERR
, "parser error '%s'", DEFAULT_CONFIGFILE
);
216 config_with_defaults();
219 cfg_bool_t
config::isSMTPEnabledFile()
221 return smtp_enabled_file
;
224 cfg_bool_t
config::isSMTPEnabledVirus()
226 return smtp_enabled_virus
;
229 cfg_bool_t
config::getVirusRemovalEnabled()
231 return virus_removal_enabled
;
234 char *config::getHost()
239 int config::getPort()
244 char *config::getTo()
249 char *config::getFrom()
254 char *config::getVirusSubject()
256 return smtp_subject_virus
;
259 char *config::getFileSubject()
261 return smtp_subject_file
;
264 char *config::getWatchDir()