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>
37 #include "inotify.hxx"
41 * Checks if the configuration file exists as a regular file.
42 * @return Returns 1 if the file exists and is regular, else 0.
44 static int config_file_exists()
48 /* No config file defined - NULL Pointer Check */
49 if (!DEFAULT_CONFIGFILE
) {
54 if (stat(DEFAULT_CONFIGFILE
, &s
) < 0) {
58 /* File is a regular file? */
59 if (!S_ISREG(s
.st_mode
)) {
67 * Release any resources that hold configuration information.
68 * This function effectively resets all configurable values.
69 * It should be called at the end of the program.
73 if (watch_dir
!= NULL
) {
78 virus_removal_enabled
= cfg_true
;
80 smtp_enabled
= cfg_true
;
82 if (smtp_host
!= NULL
) {
89 if (smtp_to
!= NULL
) {
94 if (smtp_from
!= NULL
) {
99 if (smtp_subject
!= NULL
) {
106 * Examines each value of the current configuration.
107 * If a value was not set, it is set to the default.
109 static void config_with_defaults()
111 if (watch_dir
== NULL
) {
112 watch_dir
= strdup(WATCH_DIR
);
115 if (smtp_host
== NULL
) {
116 smtp_host
= strdup(SMTP_HOST
);
119 if (smtp_port
== 0) {
120 smtp_port
= SMTP_PORT
;
123 if (smtp_to
== NULL
) {
124 smtp_to
= strdup(SMTP_TO
);
127 if (smtp_from
== NULL
) {
128 smtp_from
= strdup(SMTP_FROM
);
131 if (smtp_subject
== NULL
) {
132 smtp_subject
= strdup(SMTP_SUBJECT
);
137 * Parses an inoclam.conf configuration file.
147 CFG_SIMPLE_STR("watch_dir", &watch_dir
),
148 CFG_SIMPLE_BOOL("virus_removal_enabled", &virus_removal_enabled
),
149 CFG_SIMPLE_BOOL("smtp_enabled", &smtp_enabled
),
150 CFG_SIMPLE_STR("smtp_host", &smtp_host
),
151 CFG_SIMPLE_INT("smtp_port", &smtp_port
),
152 CFG_SIMPLE_STR("smtp_to", &smtp_to
),
153 CFG_SIMPLE_STR("smtp_from", &smtp_from
),
154 CFG_SIMPLE_STR("smtp_subject", &smtp_subject
),
160 if (!config_file_exists()) {
161 daemon_log(LOG_INFO
, "Configuration file '%s' not found.", DEFAULT_CONFIGFILE
);
162 config_with_defaults();
166 cfg
= cfg_init(opts
, 0);
168 daemon_log(LOG_ERR
, "cfg_init failed!");
169 config_with_defaults();
173 rc
= cfg_parse(cfg
, DEFAULT_CONFIGFILE
);
174 if (rc
== CFG_PARSE_ERROR
) {
175 daemon_log(LOG_ERR
, "parser error '%s'", DEFAULT_CONFIGFILE
);
183 config_with_defaults();