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>
24 #include <libdaemon/dlog.h>
26 #include <sys/types.h>
36 #include "inotify.hxx"
40 * Checks if the configuration file exists as a regular file.
41 * @return Returns 1 if the file exists and is regular, else 0.
43 static int config_file_exists()
47 /* No config file defined - NULL Pointer Check */
48 if (!DEFAULT_CONFIGFILE
) {
53 if (stat(DEFAULT_CONFIGFILE
, &s
) < 0) {
57 /* File is a regular file? */
58 if (!S_ISREG(s
.st_mode
)) {
66 * Release any resources that hold configuration information.
67 * This function effectively resets all configurable values.
68 * It should be called at the end of the program.
72 if (watch_dir
!= NULL
) {
77 virus_removal_enabled
= cfg_true
;
79 smtp_enabled
= cfg_true
;
81 if (smtp_host
!= NULL
) {
88 if (smtp_to
!= NULL
) {
93 if (smtp_from
!= NULL
) {
98 if (smtp_subject
!= NULL
) {
105 * Examines each value of the current configuration.
106 * If a value was not set, it is set to the default.
108 static void config_with_defaults()
110 if (watch_dir
== NULL
) {
111 watch_dir
= strdup(WATCH_DIR
);
114 if (smtp_host
== NULL
) {
115 smtp_host
= strdup(SMTP_HOST
);
118 if (smtp_port
== 0) {
119 smtp_port
= SMTP_PORT
;
122 if (smtp_to
== NULL
) {
123 smtp_to
= strdup(SMTP_TO
);
126 if (smtp_from
== NULL
) {
127 smtp_from
= strdup(SMTP_FROM
);
130 if (smtp_subject
== NULL
) {
131 smtp_subject
= strdup(SMTP_SUBJECT
);
136 * Parses an inoclam.conf configuration file.
146 CFG_SIMPLE_STR("watch_dir", &watch_dir
),
147 CFG_SIMPLE_BOOL("virus_removal_enabled", &virus_removal_enabled
),
148 CFG_SIMPLE_BOOL("smtp_enabled", &smtp_enabled
),
149 CFG_SIMPLE_STR("smtp_host", &smtp_host
),
150 CFG_SIMPLE_INT("smtp_port", &smtp_port
),
151 CFG_SIMPLE_STR("smtp_to", &smtp_to
),
152 CFG_SIMPLE_STR("smtp_from", &smtp_from
),
153 CFG_SIMPLE_STR("smtp_subject", &smtp_subject
),
159 if (!config_file_exists()) {
160 daemon_log(LOG_INFO
, "(%s:%u) config file '%s' does not exist", __FILE__
, __LINE__
, DEFAULT_CONFIGFILE
);
161 config_with_defaults();
165 cfg
= cfg_init(opts
, 0);
167 daemon_log(LOG_ERR
, "(%s:%u) cfg_init failed!", __FILE__
, __LINE__
);
168 config_with_defaults();
172 rc
= cfg_parse(cfg
, DEFAULT_CONFIGFILE
);
173 if (rc
== CFG_PARSE_ERROR
) {
174 daemon_log(LOG_ERR
, "(%s:%u) parser error '%s'", __FILE__
, __LINE__
, DEFAULT_CONFIGFILE
);
182 config_with_defaults();