diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-11-24 11:23:13 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-11-24 11:23:13 +1030 |
commit | 0b4b83aea0189fe9132e4e9418b749ed7863a1d0 (patch) | |
tree | 4096eb5df5d9854627ac26534b7981e1b670e679 /ctdb/server/eventscript.c | |
parent | 534c709cba7ff6f98664d706e79f793bc940eff2 (diff) | |
download | samba-0b4b83aea0189fe9132e4e9418b749ed7863a1d0.tar.gz samba-0b4b83aea0189fe9132e4e9418b749ed7863a1d0.tar.xz samba-0b4b83aea0189fe9132e4e9418b749ed7863a1d0.zip |
eventscript: check that internal script events are being invoked correctly
This is not as good as a compile-time check, but at least we count the
number of arguments are correct.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit 83b7b233cb4707e826f6ba260bd630c8bc8f1e76)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r-- | ctdb/server/eventscript.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 6f3f7937ef..c14cb5103a 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -744,6 +744,45 @@ static int event_script_destructor(struct ctdb_event_script_state *state) return 0; } +static unsigned int count_words(const char *options) +{ + unsigned int words = 0; + + options += strspn(options, " \t"); + while (*options) { + words++; + options += strcspn(options, " \t"); + options += strspn(options, " \t"); + } + return words; +} + +static bool check_options(enum ctdb_eventscript_call call, const char *options) +{ + switch (call) { + /* These all take no arguments. */ + case CTDB_EVENT_STARTUP: + case CTDB_EVENT_START_RECOVERY: + case CTDB_EVENT_RECOVERED: + case CTDB_EVENT_STOPPED: + case CTDB_EVENT_MONITOR: + case CTDB_EVENT_STATUS: + case CTDB_EVENT_SHUTDOWN: + return count_words(options) == 0; + + case CTDB_EVENT_TAKE_IP: /* interface, IP address, netmask bits. */ + case CTDB_EVENT_RELEASE_IP: + return count_words(options) == 3; + + case CTDB_EVENT_UNKNOWN: + return true; + + default: + DEBUG(DEBUG_ERR,(__location__ "Unknown ctdb_eventscript_call %u\n", call)); + return false; + } +} + /* run the event script in the background, calling the callback when finished @@ -804,6 +843,12 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb, talloc_free(state); return -1; } + if (!check_options(state->call, state->options)) { + DEBUG(DEBUG_ERR, ("Bad eventscript options '%s' for %s\n", + call_names[state->call], state->options)); + talloc_free(state); + return -1; + } DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n", call_names[state->call], state->options)); |