diff options
Diffstat (limited to 'main/named_acl.c')
-rw-r--r-- | main/named_acl.c | 109 |
1 files changed, 60 insertions, 49 deletions
diff --git a/main/named_acl.c b/main/named_acl.c index 3a4c45401..c4628216f 100644 --- a/main/named_acl.c +++ b/main/named_acl.c @@ -27,6 +27,11 @@ * Olle E. Johansson <oej@edvina.net> */ +/* This maintains the original "module reload acl" CLI command instead + * of replacing it with "module reload named_acl". */ +#undef AST_MODULE +#define AST_MODULE "acl" + #include "asterisk.h" #include "asterisk/config.h" @@ -397,36 +402,6 @@ publish_failure: /*! * \internal - * \brief reload configuration for named ACLs - * - * \param fd file descriptor for CLI client - */ -int ast_named_acl_reload(void) -{ - enum aco_process_status status; - - status = aco_process_config(&cfg_info, 1); - - if (status == ACO_PROCESS_ERROR) { - ast_log(LOG_WARNING, "Could not reload ACL config\n"); - return 0; - } - - if (status == ACO_PROCESS_UNCHANGED) { - /* We don't actually log anything if the config was unchanged, - * but we don't need to send a config change event either. - */ - return 0; - } - - /* We need to push an ACL change event with no ACL name so that all subscribers update with all ACLs */ - publish_acl_change(""); - - return 0; -} - -/*! - * \internal * \brief secondary handler for the 'acl show <name>' command (with arg) * * \param fd file descriptor of the cli @@ -500,12 +475,10 @@ static void cli_display_named_acl_list(int fd) /* \brief ACL command show <name> */ static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - RAII_VAR(struct named_acl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); + struct named_acl_config *cfg; int length; - int which; struct ao2_iterator i; struct named_acl *named_acl; - char *match = NULL; switch (cmd) { case CLI_INIT: @@ -515,23 +488,29 @@ static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct " Shows a list of named ACLs or lists all entries in a given named ACL.\n"; return NULL; case CLI_GENERATE: + if (a->pos != 2) { + return NULL; + } + + cfg = ao2_global_obj_ref(globals); if (!cfg) { return NULL; } length = strlen(a->word); - which = 0; i = ao2_iterator_init(cfg->named_acl_list, 0); while ((named_acl = ao2_iterator_next(&i))) { - if (!strncasecmp(a->word, named_acl->name, length) && ++which > a->n) { - match = ast_strdup(named_acl->name); - ao2_ref(named_acl, -1); - break; + if (!strncasecmp(a->word, named_acl->name, length)) { + if (ast_cli_completion_add(ast_strdup(named_acl->name))) { + ao2_ref(named_acl, -1); + break; + } } ao2_ref(named_acl, -1); } ao2_iterator_destroy(&i); - return match; + ao2_ref(cfg, -1); + return NULL; } if (a->argc == 2) { @@ -552,32 +531,64 @@ static struct ast_cli_entry cli_named_acl[] = { AST_CLI_DEFINE(handle_show_named_acl_cmd, "Show a named ACL or list all named ACLs"), }; -static void named_acl_cleanup(void) +static int reload_module(void) +{ + enum aco_process_status status; + + status = aco_process_config(&cfg_info, 1); + + if (status == ACO_PROCESS_ERROR) { + ast_log(LOG_WARNING, "Could not reload ACL config\n"); + return 0; + } + + if (status == ACO_PROCESS_UNCHANGED) { + /* We don't actually log anything if the config was unchanged, + * but we don't need to send a config change event either. + */ + return 0; + } + + /* We need to push an ACL change event with no ACL name so that all subscribers update with all ACLs */ + publish_acl_change(""); + + return 0; +} + +static int unload_module(void) { ast_cli_unregister_multiple(cli_named_acl, ARRAY_LEN(cli_named_acl)); STASIS_MESSAGE_TYPE_CLEANUP(ast_named_acl_change_type); aco_info_destroy(&cfg_info); ao2_global_obj_release(globals); + + return 0; } -int ast_named_acl_init() +static int load_module(void) { - ast_cli_register_multiple(cli_named_acl, ARRAY_LEN(cli_named_acl)); - - STASIS_MESSAGE_TYPE_INIT(ast_named_acl_change_type); - - ast_register_cleanup(named_acl_cleanup); - if (aco_info_init(&cfg_info)) { - return 0; + return AST_MODULE_LOAD_FAILURE; } + STASIS_MESSAGE_TYPE_INIT(ast_named_acl_change_type); + /* Register the per level options. */ aco_option_register(&cfg_info, "permit", ACO_EXACT, named_acl_types, NULL, OPT_ACL_T, 1, FLDSET(struct named_acl, ha)); aco_option_register(&cfg_info, "deny", ACO_EXACT, named_acl_types, NULL, OPT_ACL_T, 0, FLDSET(struct named_acl, ha)); aco_process_config(&cfg_info, 0); - return 0; + ast_cli_register_multiple(cli_named_acl, ARRAY_LEN(cli_named_acl)); + + return AST_MODULE_LOAD_SUCCESS; } + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Named ACL system", + .support_level = AST_MODULE_SUPPORT_CORE, + .load = load_module, + .unload = unload_module, + .reload = reload_module, + .load_pri = AST_MODPRI_CORE, +); |