69 e->
command =
"core show functions [like]";
71 "Usage: core show functions [like <text>]\n"
72 " List builtin functions, optionally only those matching a given string\n";
78 if (
a->argc == 5 && (!strcmp(
a->argv[3],
"like")) ) {
80 }
else if (
a->argc != 3) {
84 ast_cli(
a->fd,
"%s Custom Functions:\n"
85 "--------------------------------------------------------------------------------\n",
86 like ?
"Matching" :
"Installed");
90 if (!like || strstr(acf->
name,
a->argv[4])) {
92 ast_cli(
a->fd,
"%-20.20s %-35.35s %s\n",
100 ast_cli(
a->fd,
"%d %scustom functions installed.\n", count_acf, like ?
"matching " :
"");
117 wordlen = strlen(
word);
127 cmp = strncasecmp(
word, cur->
name, wordlen);
130 if (++which <=
state) {
147 char infotitle[64 +
AST_MAX_APP + 22], syntitle[40], desctitle[40], argtitle[40], seealsotitle[40];
150 int syntax_size, description_size, synopsis_size, arguments_size, seealso_size;
154 e->
command =
"core show function";
156 "Usage: core show function <function>\n"
157 " Describe a particular dialplan function.\n";
168 ast_cli(
a->fd,
"No function by that name registered.\n");
176 ast_cli(
a->fd,
"Memory allocation failure!\n");
181 snprintf(
info,
sizeof(
info),
"\n -= Info about function '%s' =- \n\n", acf->
name);
227 ast_cli(
a->fd,
"%s%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n",
228 infotitle, syntitle,
synopsis, desctitle, description,
289 ast_verb(5,
"Unregistered custom function %s\n", cur->
name);
401 if (strcmp(acf->
name, cur->
name) < 0) {
427 switch (escalation) {
450 char *
args = strchr(function,
'(');
453 ast_log(
LOG_WARNING,
"Function '%s' doesn't contain parentheses. Assuming null argument.\n", function);
457 if ((p = strrchr(
args,
')'))) {
470 "See https://docs.asterisk.org/Configuration/Dialplan/Privilege-Escalations-with-Dialplan-Functions/ for more details.\n");
481 int *thread_inhibit_escalations;
485 if (thread_inhibit_escalations ==
NULL) {
486 ast_log(
LOG_ERROR,
"Error inhibiting privilege escalations for current thread\n");
490 *thread_inhibit_escalations = 1;
496 int *thread_inhibit_escalations;
501 if (thread_inhibit_escalations ==
NULL) {
502 ast_log(
LOG_ERROR,
"Error swapping privilege escalations inhibit for current thread\n");
506 orig = *thread_inhibit_escalations;
507 *thread_inhibit_escalations = !!inhibit;
520 int *thread_inhibit_escalations;
524 if (thread_inhibit_escalations ==
NULL) {
525 ast_log(
LOG_ERROR,
"Error checking thread's ability to run dangerous functions\n");
530 return *thread_inhibit_escalations;
557 ast_debug(2,
"Reading %s from a dangerous context\n",
590 ast_debug(2,
"Writing %s from a dangerous context\n",
607 if (acfptr ==
NULL) {
609 }
else if (!acfptr->
read && !acfptr->
read2) {
613 }
else if (acfptr->
read) {
618 if (acfptr->
mod && u) {
630 if (acfptr->
mod && u) {
650 if (acfptr ==
NULL) {
652 }
else if (!acfptr->
read && !acfptr->
read2) {
683 if (acfptr->
mod && u) {
699 if (acfptr ==
NULL) {
701 }
else if (!acfptr->
write) {
713 if (acfptr->
mod && u) {
Prototypes for public functions only of internal interest,.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_malloc(len)
A wrapper for malloc()
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
A set of macros to manage forward-linked lists.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
#define AST_RWLIST_REMOVE
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_TRAVERSE
#define AST_RWLIST_INSERT_TAIL
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Asterisk module definitions.
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Core PBX routines and definitions.
ast_custom_function_escalation
Description of the ways in which a function may escalate privileges.
static int thread_inhibits_escalations(void)
Indicates whether the current thread inhibits the execution of dangerous functions.
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's read function is allowed.
static int read_escalates(const struct ast_custom_function *acf)
Returns true if given custom function escalates privileges on read.
void pbx_live_dangerously(int new_live_dangerously)
Enable/disable the execution of 'dangerous' functions from external protocols (AMI,...
int ast_thread_inhibit_escalations_swap(int inhibit)
Swap the current thread escalation inhibit setting.
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 struct ast_custom_function * ast_custom_function_find_nolock(const char *name)
static int write_escalates(const struct ast_custom_function *acf)
Returns true if given custom function escalates privileges on write.
static struct ast_threadstorage thread_inhibit_escalations_tl
struct ast_custom_function * ast_custom_function_find(const char *name)
int load_pbx_functions_cli(void)
static int acf_retrieve_docs(struct ast_custom_function *acf)
static void unload_pbx_functions_cli(void)
static int live_dangerously
Set to true (non-zero) to globally allow all dangerous dialplan functions to run.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static char * complete_functions(const char *word, int pos, int state)
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
static char * handle_show_functions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
static char * handle_show_function(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
static int is_write_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's write function is allowed.
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with '\0'
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...
static struct ast_cli_entry acf_cli[]
Private include file for pbx.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define ast_str_make_space(buf, new_len)
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Registered functions container.
Main Channel structure associated with a channel.
descriptor for a cli entry.
Data structure associated with a custom dialplan function.
const ast_string_field desc
const ast_string_field synopsis
const ast_string_field seealso
const ast_string_field syntax
const ast_string_field arguments
unsigned int read_escalates
unsigned int write_escalates
struct ast_channel * chan
Support for dynamic strings.
Handy terminal functions for vt* terms.
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
#define AST_TERM_MAX_ESCAPE_CHARS
Maximum number of characters needed for a color escape sequence, and another one for a trailing reset...
#define COLORIZE(fg, bg, str)
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definitions to aid in the use of thread local storage.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
Asterisk XML Documentation API.
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
char * ast_xmldoc_build_syntax(const char *type, const char *name, const char *module)
Get the syntax for a specified application or function.
char * ast_xmldoc_build_arguments(const char *type, const char *name, const char *module)
Generate the [arguments] tag based on type of node ('application', 'function' or 'agi') and name.
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.