summaryrefslogtreecommitdiff
path: root/ctdb/event/event_conf.c
blob: 33bfc7c533599bacd35b4d4d5e82234728a74124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
   CTDB event daemon

   Copyright (C) Amitay Isaacs  2018

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include "replace.h"
#include "system/filesys.h"
#include "system/dir.h"

#include "lib/util/debug.h"

#include "common/conf.h"
#include "common/path.h"

#include "event/event_conf.h"

static bool event_conf_validate_debug_script(const char *key,
					     const char *old_script,
					     const char *new_script,
					     enum conf_update_mode mode)
{
	char script[PATH_MAX];
	char script_path[PATH_MAX];
	struct stat st;
	size_t len;
	int ret;

	len = strlcpy(script, new_script, sizeof(script));
	if (len >= sizeof(script)) {
		D_ERR("debug script name too long\n");
		return false;
	}

	ret = snprintf(script_path,
		       sizeof(script_path),
		       "%s/%s",
		       path_etcdir(),
		       basename(script));
	if (ret >= sizeof(script_path)) {
		D_ERR("debug script path too long\n");
		return false;
	}

	ret = stat(script_path, &st);
	if (ret == -1) {
		D_ERR("debug script %s does not exist\n", script_path);
		return false;
	}

	if (! S_ISREG(st.st_mode)) {
		D_ERR("debug script %s is not a file\n", script_path);
		return false;
	}
	if (! (st.st_mode & S_IXUSR)) {
		D_ERR("debug script %s is not executable\n", script_path);
		return false;
	}

	return true;
}

void event_conf_init(struct conf_context *conf)
{
	conf_define_section(conf, EVENT_CONF_SECTION, NULL);

	conf_define_string(conf,
			   EVENT_CONF_SECTION,
			   EVENT_CONF_DEBUG_SCRIPT,
			   NULL,
			   event_conf_validate_debug_script);
}