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) {
85 "--------------------------------------------------------------------------------\n",
86 like ?
"Matching" :
"Installed");
90 if (!like || strstr(acf->
name, a->
argv[4])) {
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], destitle[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);
211 if (!synopsis || !description || !arguments || !seealso) {
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, destitle, description,
229 stxtitle, syntax, argtitle, arguments, seealsotitle, seealso);
246 cmp = strcmp(name, cur->
name);
289 ast_verb(2,
"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,
')'))) {
460 ast_log(
LOG_WARNING,
"Can't find trailing parenthesis for function '%s(%s'?\n",
function, args);
470 "See https://wiki.asterisk.org/wiki/x/1gKfAQ 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) {
617 res = acfptr->
read(chan, copy, args, workspace, len);
618 if (acfptr->
mod && u) {
629 res = acfptr->
read2(chan, copy, args, &str, 0);
630 if (acfptr->
mod && u) {
650 if (acfptr ==
NULL) {
652 }
else if (!acfptr->
read && !acfptr->
read2) {
663 res = acfptr->
read2(chan, copy, args, str, maxlen);
682 if (acfptr->
mod && u) {
698 if (acfptr ==
NULL) {
700 }
else if (!acfptr->
write) {
711 res = acfptr->
write(chan, copy, args, value);
712 if (acfptr->
mod && u) {
static const char synopsis[]
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
Main Channel structure associated with a channel.
int ast_thread_inhibit_escalations(void)
Inhibit (in the current thread) the execution of dialplan functions which cause privilege escalations...
#define AST_CLI_DEFINE(fn, txt,...)
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
Asterisk main include file. File version handling, generic pbx functions.
int ast_thread_inhibit_escalations_swap(int inhibit)
Swap the current thread escalation inhibit setting.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
static char * handle_show_function(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Private include file for pbx.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
static int live_dangerously
Set to true (non-zero) to globally allow all dangerous dialplan functions to run. ...
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
const ast_string_field syntax
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's read function is allowed.
descriptor for a cli entry.
#define ast_str_make_space(buf, new_len)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
ast_custom_function_escalation
Description of the ways in which a function may escalate privileges.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
const ast_string_field desc
static char * handle_show_functions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
const ast_string_field arguments
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
static struct ast_custom_function * ast_custom_function_find_nolock(const char *name)
static int is_write_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's write function is allowed.
#define ast_strdup(str)
A wrapper for strdup()
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.
Definitions to aid in the use of thread local storage.
unsigned int write_escalates
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
void ast_cli(int fd, const char *fmt,...)
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...
#define ast_verb(level,...)
#define COLORIZE(fg, bg, str)
#define ast_strlen_zero(foo)
#define AST_TERM_MAX_ESCAPE_CHARS
Maximum number of characters needed for a color escape sequence, and another one for a trailing reset...
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define ast_debug(level,...)
Log a DEBUG message.
static int thread_inhibits_escalations(void)
Indicates whether the current thread inhibits the execution of dangerous functions.
static void unload_pbx_functions_cli(void)
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with '\0' ...
Data structure associated with a custom dialplan function.
#define AST_RWLIST_TRAVERSE
unsigned int read_escalates
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Registered functions container.
A set of macros to manage forward-linked lists.
#define ast_malloc(len)
A wrapper for malloc()
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Core PBX routines and definitions.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
static char * complete_functions(const char *word, int pos, int state)
static int acf_retrieve_docs(struct ast_custom_function *acf)
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
struct ast_channel * chan
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
void pbx_live_dangerously(int new_live_dangerously)
Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.).
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 int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct ast_cli_entry acf_cli[]
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int load_pbx_functions_cli(void)
static int write_escalates(const struct ast_custom_function *acf)
Returns true if given custom function escalates privileges on write.
static int read_escalates(const struct ast_custom_function *acf)
Returns true if given custom function escalates privileges on read.
struct ast_custom_function * ast_custom_function_find(const char *name)
Asterisk XML Documentation API.
Prototypes for public functions only of internal interest,.
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
const ast_string_field synopsis
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_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
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_RWLIST_INSERT_TAIL
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
#define AST_RWLIST_REMOVE
Handy terminal functions for vt* terms.
static struct ast_threadstorage thread_inhibit_escalations_tl
const ast_string_field seealso
Asterisk module definitions.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
#define AST_RWLIST_TRAVERSE_SAFE_END
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.