|
Asterisk - The Open Source Telephony Project
18.5.0
|
Custom function management routines. More...
#include "asterisk.h"#include "asterisk/_private.h"#include "asterisk/cli.h"#include "asterisk/linkedlists.h"#include "asterisk/module.h"#include "asterisk/pbx.h"#include "asterisk/term.h"#include "asterisk/threadstorage.h"#include "asterisk/xmldoc.h"#include "pbx_private.h"
Go to the source code of this file.
Data Structures | |
| struct | acf_root |
| Registered functions container. More... | |
Functions | |
| int | __ast_custom_function_register (struct ast_custom_function *acf, struct ast_module *mod) |
| Register a custom function. More... | |
| int | __ast_custom_function_register_escalating (struct ast_custom_function *acf, enum ast_custom_function_escalation escalation, struct ast_module *mod) |
| Register a custom function which requires escalated privileges. More... | |
| static void | __init_thread_inhibit_escalations_tl (void) |
| A thread local indicating whether the current thread can run 'dangerous' dialplan functions. More... | |
| static int | acf_retrieve_docs (struct ast_custom_function *acf) |
| struct ast_custom_function * | ast_custom_function_find (const char *name) |
| static struct ast_custom_function * | ast_custom_function_find_nolock (const char *name) |
| int | ast_custom_function_unregister (struct ast_custom_function *acf) |
| Unregister a custom function. More... | |
| int | ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len) |
| executes a read operation on a function More... | |
| int | ast_func_read2 (struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen) |
| executes a read operation on a function More... | |
| int | ast_func_write (struct ast_channel *chan, const char *function, const char *value) |
| executes a write operation on a function More... | |
| int | ast_thread_inhibit_escalations (void) |
| Inhibit (in the current thread) the execution of dialplan functions which cause privilege escalations. If pbx_live_dangerously() has been called, this function has no effect. More... | |
| int | ast_thread_inhibit_escalations_swap (int inhibit) |
| Swap the current thread escalation inhibit setting. More... | |
| static char * | complete_functions (const char *word, int pos, int state) |
| static char * | func_args (char *function) |
| return a pointer to the arguments of the function, and terminates the function name with '\0' More... | |
| static char * | handle_show_function (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_show_functions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static int | is_read_allowed (struct ast_custom_function *acfptr) |
| Determines whether execution of a custom function's read function is allowed. More... | |
| static int | is_write_allowed (struct ast_custom_function *acfptr) |
| Determines whether execution of a custom function's write function is allowed. More... | |
| int | load_pbx_functions_cli (void) |
| void | pbx_live_dangerously (int new_live_dangerously) |
| Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.). More... | |
| static int | read_escalates (const struct ast_custom_function *acf) |
| Returns true if given custom function escalates privileges on read. More... | |
| static int | thread_inhibits_escalations (void) |
| Indicates whether the current thread inhibits the execution of dangerous functions. More... | |
| static void | unload_pbx_functions_cli (void) |
| static int | write_escalates (const struct ast_custom_function *acf) |
| Returns true if given custom function escalates privileges on write. More... | |
Variables | |
| static struct ast_cli_entry | acf_cli [] |
| static struct acf_root | acf_root = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
| static int | live_dangerously |
| Set to true (non-zero) to globally allow all dangerous dialplan functions to run. More... | |
| static struct ast_threadstorage | thread_inhibit_escalations_tl = { .once = PTHREAD_ONCE_INIT , .key_init = __init_thread_inhibit_escalations_tl , .custom_init = NULL , } |
Custom function management routines.
Definition in file pbx_functions.c.
| int __ast_custom_function_register | ( | struct ast_custom_function * | acf, |
| struct ast_module * | mod | ||
| ) |
Register a custom function.
Definition at line 373 of file pbx_functions.c.
References acf_retrieve_docs(), ast_custom_function_find_nolock(), ast_log, AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_verb, COLOR_BRCYAN, COLORIZE, COLORIZE_FMT, ast_custom_function::docsrc, LOG_ERROR, ast_custom_function::mod, and ast_custom_function::name.
Referenced by __ast_custom_function_register_escalating(), __init_manager(), ast_msg_init(), load_features_config(), and load_pbx().
| int __ast_custom_function_register_escalating | ( | struct ast_custom_function * | acf, |
| enum ast_custom_function_escalation | escalation, | ||
| struct ast_module * | mod | ||
| ) |
Register a custom function which requires escalated privileges.
Examples would be SHELL() (for which a read needs permission to execute arbitrary code) or FILE() (for which write needs permission to change files on the filesystem).
Definition at line 418 of file pbx_functions.c.
References __ast_custom_function_register(), AST_CFE_BOTH, AST_CFE_NONE, AST_CFE_READ, AST_CFE_WRITE, ast_custom_function::read_escalates, and ast_custom_function::write_escalates.
|
static |
A thread local indicating whether the current thread can run 'dangerous' dialplan functions.
Definition at line 46 of file pbx_functions.c.
|
static |
Definition at line 328 of file pbx_functions.c.
References ast_custom_function::arguments, ast_free, ast_module_name(), ast_string_field_init, ast_string_field_set, ast_strlen_zero, AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), desc, ast_custom_function::desc, ast_custom_function::docsrc, ast_custom_function::mod, ast_custom_function::name, ast_custom_function::seealso, synopsis, ast_custom_function::synopsis, and ast_custom_function::syntax.
Referenced by __ast_custom_function_register().
| struct ast_custom_function* ast_custom_function_find | ( | const char * | name | ) |
Definition at line 262 of file pbx_functions.c.
References ast_custom_function_find_nolock(), AST_RWLIST_RDLOCK, and AST_RWLIST_UNLOCK.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and handle_show_function().
|
static |
Definition at line 240 of file pbx_functions.c.
References AST_RWLIST_TRAVERSE, ast_custom_function::name, and NULL.
Referenced by __ast_custom_function_register(), and ast_custom_function_find().
| int ast_custom_function_unregister | ( | struct ast_custom_function * | acf | ) |
Unregister a custom function.
Definition at line 273 of file pbx_functions.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_verb, AST_XML_DOC, ast_custom_function::docsrc, and ast_custom_function::name.
Referenced by load_module(), manager_shutdown(), message_shutdown(), reload(), unload_features_config(), unload_module(), unload_parking_bridge_features(), and unload_pbx().
| int ast_func_read | ( | struct ast_channel * | chan, |
| const char * | function, | ||
| char * | workspace, | ||
| size_t | len | ||
| ) |
executes a read operation on a function
| chan | Channel to execute on |
| function | Data containing the function call string (will be modified) |
| workspace | A pointer to safe memory to use for a return value |
| len | the number of bytes in workspace |
This application executes a function in read mode on a given channel.
| 0 | success |
| non-zero | failure |
Definition at line 599 of file pbx_functions.c.
References __ast_module_user_add(), __ast_module_user_remove(), args, ast_copy_string(), ast_custom_function_find(), ast_free, ast_log, ast_str_buffer(), ast_str_create, ast_str_size(), ast_strdupa, copy(), func_args(), is_read_allowed(), LOG_ERROR, ast_custom_function::mod, NULL, ast_custom_function::read, ast_custom_function::read2, and str.
Referenced by action_getvar(), assign_uuid(), fetch_access_token(), fetch_google_access_token(), generate_status(), handle_getvariable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().
| int ast_func_read2 | ( | struct ast_channel * | chan, |
| const char * | function, | ||
| struct ast_str ** | str, | ||
| ssize_t | maxlen | ||
| ) |
executes a read operation on a function
| chan | Channel to execute on |
| function | Data containing the function call string (will be modified) |
| str | A dynamic string buffer into which to place the result. |
| maxlen | <0 if the dynamic buffer should not grow; >0 if the dynamic buffer should be limited to that number of bytes; 0 if the dynamic buffer has no upper limit |
This application executes a function in read mode on a given channel.
| 0 | success |
| non-zero | failure |
Definition at line 642 of file pbx_functions.c.
References __ast_module_user_add(), __ast_module_user_remove(), args, ast_custom_function_find(), ast_log, ast_str_buffer(), ast_str_make_space, ast_str_reset(), ast_str_size(), ast_strdupa, copy(), func_args(), is_read_allowed(), LOG_ERROR, maxsize, ast_custom_function::mod, NULL, ast_custom_function::read, ast_custom_function::read2, ast_custom_function::read_max, and VAR_BUF_SIZE.
Referenced by ast_ari_channels_get_channel_var(), ast_str_substitute_variables_full(), AST_TEST_DEFINE(), and channel_get_external_vars().
| int ast_func_write | ( | struct ast_channel * | chan, |
| const char * | function, | ||
| const char * | value | ||
| ) |
executes a write operation on a function
| chan | Channel to execute on |
| function | Data containing the function call string (will be modified) |
| value | A value parameter to pass for writing |
This application executes a function in write mode on a given channel.
| 0 | success |
| non-zero | failure |
Definition at line 692 of file pbx_functions.c.
References __ast_module_user_add(), __ast_module_user_remove(), args, ast_custom_function_find(), ast_log, ast_strdupa, copy(), func_args(), is_write_allowed(), LOG_ERROR, ast_custom_function::mod, NULL, and ast_custom_function::write.
Referenced by ast_channel_hangupcause_hash_set(), AST_TEST_DEFINE(), chanavail_exec(), conf_run(), confbridge_exec(), fetch_google_access_token(), pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), setup_profile_bridge(), setup_profile_caller(), and setup_profile_paged().
| int ast_thread_inhibit_escalations | ( | void | ) |
Inhibit (in the current thread) the execution of dialplan functions which cause privilege escalations. If pbx_live_dangerously() has been called, this function has no effect.
Definition at line 479 of file pbx_functions.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_inhibit_escalations_tl.
Referenced by ast_add_extension2_lockopt(), and handle_tcptls_connection().
| int ast_thread_inhibit_escalations_swap | ( | int | inhibit | ) |
Swap the current thread escalation inhibit setting.
| inhibit | New setting. Non-zero to inhibit. |
| 1 | if dangerous function execution was inhibited. |
| 0 | if dangerous function execution was allowed. |
| -1 | on error. |
Definition at line 494 of file pbx_functions.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_inhibit_escalations_tl.
Referenced by ast_add_extension2_lockopt().
|
static |
Definition at line 105 of file pbx_functions.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_custom_function::name, and NULL.
Referenced by handle_show_function().
|
static |
return a pointer to the arguments of the function, and terminates the function name with '\0'
Definition at line 448 of file pbx_functions.c.
References args, ast_log, and LOG_WARNING.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and read_pjsip().
|
static |
Definition at line 143 of file pbx_functions.c.
References ast_cli_args::argc, ast_custom_function::arguments, ast_cli_args::argv, ast_cli(), ast_custom_function_find(), ast_free, ast_malloc, AST_MAX_APP, AST_TERM_MAX_ESCAPE_CHARS, AST_XML_DOC, ast_xmldoc_printable(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_CYAN, COLOR_MAGENTA, ast_cli_entry::command, complete_functions(), ast_custom_function::desc, ast_custom_function::docsrc, ast_cli_args::fd, sip_to_pjsip::info(), ast_cli_args::n, ast_custom_function::name, NULL, ast_cli_args::pos, S_OR, ast_custom_function::seealso, synopsis, ast_custom_function::synopsis, ast_custom_function::syntax, term_color(), ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 61 of file pbx_functions.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_custom_function::name, NULL, S_OR, ast_custom_function::synopsis, ast_custom_function::syntax, and ast_cli_entry::usage.
|
static |
Determines whether execution of a custom function's read function is allowed.
| acfptr | Custom function to check |
Definition at line 541 of file pbx_functions.c.
References ast_debug, live_dangerously, ast_custom_function::name, read_escalates(), and thread_inhibits_escalations().
Referenced by ast_func_read(), and ast_func_read2().
|
static |
Determines whether execution of a custom function's write function is allowed.
| acfptr | Custom function to check |
Definition at line 574 of file pbx_functions.c.
References ast_debug, live_dangerously, ast_custom_function::name, thread_inhibits_escalations(), and write_escalates().
Referenced by ast_func_write().
| int load_pbx_functions_cli | ( | void | ) |
Provided by pbx_functions.c
Definition at line 732 of file pbx_functions.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), and unload_pbx_functions_cli().
Referenced by asterisk_daemon().
| void pbx_live_dangerously | ( | int | new_live_dangerously | ) |
Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.).
These dialplan functions (such as SHELL) provide an opportunity for privilege escalation. They are okay to invoke from the dialplan, but external protocols with permission controls should not normally invoke them.
This function can globally enable/disable the execution of dangerous functions from external protocols.
| new_live_dangerously | If true, enable the execution of escalating functions from external protocols. |
Definition at line 466 of file pbx_functions.c.
References ast_log, live_dangerously, LOG_NOTICE, and LOG_WARNING.
Referenced by load_asterisk_conf().
|
static |
Returns true if given custom function escalates privileges on read.
| acf | Custom function to query. |
Definition at line 303 of file pbx_functions.c.
References ast_custom_function::read_escalates.
Referenced by is_read_allowed().
|
static |
Indicates whether the current thread inhibits the execution of dangerous functions.
Definition at line 518 of file pbx_functions.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_inhibit_escalations_tl.
Referenced by is_read_allowed(), and is_write_allowed().
|
static |
Definition at line 727 of file pbx_functions.c.
References ARRAY_LEN, and ast_cli_unregister_multiple().
Referenced by load_pbx_functions_cli().
|
static |
Returns true if given custom function escalates privileges on write.
| acf | Custom function to query. |
Definition at line 315 of file pbx_functions.c.
References ast_custom_function::write_escalates.
Referenced by is_write_allowed().
|
static |
Definition at line 722 of file pbx_functions.c.
|
static |
|
static |
Set to true (non-zero) to globally allow all dangerous dialplan functions to run.
Definition at line 46 of file pbx_functions.c.
Referenced by is_read_allowed(), is_write_allowed(), load_asterisk_conf(), and pbx_live_dangerously().
|
static |
Definition at line 46 of file pbx_functions.c.
Referenced by ast_thread_inhibit_escalations(), ast_thread_inhibit_escalations_swap(), and thread_inhibits_escalations().
1.8.13