ctdb-scripts: Update statd-callout to try several configuration files
[vlendec/samba-autobuild/.git] / ctdb / event / event_conf.c
1 /*
2    CTDB event daemon
3
4    Copyright (C) Amitay Isaacs  2018
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "replace.h"
21 #include "system/filesys.h"
22 #include "system/dir.h"
23
24 #include "lib/util/debug.h"
25
26 #include "common/conf.h"
27 #include "common/path.h"
28
29 #include "event/event_conf.h"
30
31 static bool event_conf_validate_debug_script(const char *key,
32                                              const char *old_script,
33                                              const char *new_script,
34                                              enum conf_update_mode mode)
35 {
36         char script[PATH_MAX];
37         char script_path[PATH_MAX];
38         struct stat st;
39         size_t len;
40         int ret;
41
42         len = strlcpy(script, new_script, sizeof(script));
43         if (len >= sizeof(script)) {
44                 D_ERR("debug script name too long\n");
45                 return false;
46         }
47
48         ret = snprintf(script_path,
49                        sizeof(script_path),
50                        "%s/%s",
51                        path_etcdir(),
52                        basename(script));
53         if (ret >= sizeof(script_path)) {
54                 D_ERR("debug script path too long\n");
55                 return false;
56         }
57
58         ret = stat(script_path, &st);
59         if (ret == -1) {
60                 D_ERR("debug script %s does not exist\n", script_path);
61                 return false;
62         }
63
64         if (! S_ISREG(st.st_mode)) {
65                 D_ERR("debug script %s is not a file\n", script_path);
66                 return false;
67         }
68         if (! (st.st_mode & S_IXUSR)) {
69                 D_ERR("debug script %s is not executable\n", script_path);
70                 return false;
71         }
72
73         return true;
74 }
75
76 void event_conf_init(struct conf_context *conf)
77 {
78         conf_define_section(conf, EVENT_CONF_SECTION, NULL);
79
80         conf_define_string(conf,
81                            EVENT_CONF_SECTION,
82                            EVENT_CONF_DEBUG_SCRIPT,
83                            NULL,
84                            event_conf_validate_debug_script);
85 }