ldb: Release ldb 2.2.1
[Samba.git] / ctdb / event / event_conf.c
blob61ecf8e33eb6f73b9c14c0f6410261ef82b49302
1 /*
2 CTDB event daemon
4 Copyright (C) Amitay Isaacs 2018
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.
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.
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/>.
20 #include "replace.h"
21 #include "system/filesys.h"
22 #include "system/dir.h"
24 #include "lib/util/debug.h"
26 #include "common/conf.h"
27 #include "common/path.h"
29 #include "event/event_conf.h"
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)
36 char script[PATH_MAX];
37 char script_path[PATH_MAX];
38 struct stat st;
39 size_t len;
40 int ret;
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;
48 ret = snprintf(script_path,
49 sizeof(script_path),
50 "%s/%s",
51 path_etcdir(),
52 basename(script));
53 if (ret < 0 || (size_t)ret >= sizeof(script_path)) {
54 D_ERR("debug script path too long\n");
55 return false;
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;
64 if (! S_ISREG(st.st_mode)) {
65 D_ERR("debug script %s is not a file\n", script_path);
66 return false;
68 if (! (st.st_mode & S_IXUSR)) {
69 D_ERR("debug script %s is not executable\n", script_path);
70 return false;
73 return true;
76 void event_conf_init(struct conf_context *conf)
78 conf_define_section(conf, EVENT_CONF_SECTION, NULL);
80 conf_define_string(conf,
81 EVENT_CONF_SECTION,
82 EVENT_CONF_DEBUG_SCRIPT,
83 NULL,
84 event_conf_validate_debug_script);