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 | 187efa08aba97a3cc3d203f25f5a117ac55717ec (patch) | |
tree | 51ea8609531902e9ec4e679449e4ffbf0dec6ec7 /ctdb/server/eventscript.c | |
parent | 0ef91a4e1f8e417945723c8beb67772425054baa (diff) | |
download | samba-187efa08aba97a3cc3d203f25f5a117ac55717ec.tar.gz samba-187efa08aba97a3cc3d203f25f5a117ac55717ec.tar.xz samba-187efa08aba97a3cc3d203f25f5a117ac55717ec.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 a6d353519932eee48f9241ad8887b692882906c9)
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 8ca3be1b76..8814858f26 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 @@ -805,6 +844,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)); |