|
Asterisk - The Open Source Telephony Project GIT-master-27fb039
|
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. | |
| 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. | |
| 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. | |
| int | ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len) |
| executes a read operation on a function | |
| 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 | |
| int | ast_func_write (struct ast_channel *chan, const char *function, const char *value) |
| executes a write operation on a function | |
| 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. | |
| int | ast_thread_inhibit_escalations_swap (int inhibit) |
| Swap the current thread escalation inhibit setting. | |
| AST_THREADSTORAGE_CUSTOM_SCOPE (thread_inhibit_escalations_tl, NULL, ast_free_ptr, static) | |
| A thread local indicating whether the current thread can run 'dangerous' dialplan functions. | |
| 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' | |
| 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. | |
| static int | is_write_allowed (struct ast_custom_function *acfptr) |
| Determines whether execution of a custom function's write function is allowed. | |
| 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.). | |
| static int | read_escalates (const struct ast_custom_function *acf) |
| Returns true if given custom function escalates privileges on read. | |
| static int | thread_inhibits_escalations (void) |
| Indicates whether the current thread inhibits the execution of dangerous functions. | |
| 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. | |
Variables | |
| static struct ast_cli_entry | acf_cli [] |
| static struct acf_root | acf_root = AST_RWLIST_HEAD_INIT_VALUE |
| static int | live_dangerously |
| Set to true (non-zero) to globally allow all dangerous dialplan functions to run. | |
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 372 of file pbx_functions.c.
References acf_retrieve_docs(), ast_custom_function::acflist, 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 417 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::mod, ast_custom_function::read_escalates, and ast_custom_function::write_escalates.
|
static |
Definition at line 317 of file pbx_functions.c.
References ast_custom_function::arguments, ast_free, ast_module_name(), ast_string_field_free_memory, ast_string_field_init, ast_string_field_init_extended, 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_since(), 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 251 of file pbx_functions.c.
References ast_custom_function_find_nolock(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and name.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and handle_show_function().
|
static |
Definition at line 229 of file pbx_functions.c.
References ast_custom_function::acflist, AST_RWLIST_TRAVERSE, name, 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 262 of file pbx_functions.c.
References ast_custom_function::acflist, 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 __unload_module(), close_logger(), geoloc_dialplan_unload(), load_module(), load_module(), manager_shutdown(), message_shutdown(), reload(), unload_features_config(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), 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 598 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, ast_module_user::chan, copy(), func_args(), is_read_allowed(), len(), 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_eval_function(), handle_getvariable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full_location().
| 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 641 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_str_update(), ast_strdupa, ast_module_user::chan, 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, str, and VAR_BUF_SIZE.
Referenced by ast_ari_channels_get_channel_var(), ast_str_substitute_variables_full2(), AST_TEST_DEFINE(), 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, ast_module_user::chan, copy(), func_args(), is_write_allowed(), LOG_ERROR, ast_custom_function::mod, NULL, value, and ast_custom_function::write.
Referenced by ast_channel_hangupcause_hash_set(), AST_TEST_DEFINE(), chanavail_exec(), conf_run(), 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 478 of file pbx_functions.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, and NULL.
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 493 of file pbx_functions.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, and NULL.
Referenced by ast_add_extension2_lockopt().
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | thread_inhibit_escalations_tl | , |
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) |
A thread local indicating whether the current thread can run 'dangerous' dialplan functions.
|
static |
Definition at line 105 of file pbx_functions.c.
References ast_custom_function::acflist, 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 447 of file pbx_functions.c.
References args, ast_log, and LOG_WARNING.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), pjsip_acf_channel_read(), pjsip_acf_parse_uri_read(), and read_pjsip().
|
static |
Definition at line 143 of file pbx_functions.c.
References a, ast_custom_function::arguments, ast_cli(), ast_custom_function_find(), ast_free, ast_strdup, ast_term_color(), ast_term_reset(), AST_XML_DOC, ast_xmldoc_printable(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_MAGENTA, COLORIZE, COLORIZE_FMT, ast_cli_entry::command, complete_functions(), ast_custom_function::desc, ast_custom_function::docsrc, ast_custom_function::name, NULL, S_OR, ast_custom_function::seealso, synopsis, ast_custom_function::synopsis, ast_custom_function::syntax, and ast_cli_entry::usage.
|
static |
Definition at line 61 of file pbx_functions.c.
References a, ast_custom_function::acflist, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, 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 540 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 573 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 acf_cli, 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 465 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 292 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 517 of file pbx_functions.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, and NULL.
Referenced by is_read_allowed(), and is_write_allowed().
|
static |
Definition at line 727 of file pbx_functions.c.
References acf_cli, 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 304 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.
Referenced by load_pbx_functions_cli(), and unload_pbx_functions_cli().
|
static |
|
static |
Set to true (non-zero) to globally allow all dangerous dialplan functions to run.
Definition at line 52 of file pbx_functions.c.
Referenced by is_read_allowed(), is_write_allowed(), and pbx_live_dangerously().