summaryrefslogtreecommitdiff
path: root/main/asterisk.c
AgeCommit message (Collapse)Author
2018-03-14loader: Convert reload_classes to built-in modules.Corey Farrell
* acl (named_acl.c) * cdr * cel * ccss * dnsmgr * dsp * enum * extconfig (config.c) * features * http * indications * logger * manager * plc * sounds * udptl These modules are now loaded at appropriate time by the module loader. Unlike loadable modules these use AST_MODULE_LOAD_FAILURE on error so the module loader will abort startup on failure of these modules. Some of these modules are still initialized or shutdown from outside the module loader. logger.c is initialized very early and shutdown very late, manager.c is initialized by the module loader but is shutdown by the Asterisk core (too much uses it without holding references). Change-Id: I371a9a45064f20026c492623ea8062d02a1ab97f
2018-03-13core: Remove non-critical cleanup from startup aborts.Corey Farrell
When built-in components of Asterisk fail to start they cause the Asterisk startup to abort. In these cases only the most critical cleanup should be performed - closing databases and terminating proceses. These cleanups are registered using ast_register_atexit, all other cleanups should not be run during startup abort. The main reason for this change is that these cleanup procedures are untestable from the partially initialized states, if they fail it could prevent us from ever running the critical cleanup with ast_run_atexits. Create separate initialization for dns_core.c to be run unconditionally during startup instead of being initialized by the first dns resolver to be registered. This ensures that 'sched' is initialized before it can be potentially used. Replace ast_register_atexit with ast_register_cleanup in media_cache.c. There is no reason for this cleanup to happen unconditionally. Change-Id: Iecc2df98008b21509925ff16740bd5fa29527db3
2018-02-28pjproject: Add cache_pools debugging option.Richard Mudgett
The pool cache gets in the way of finding use after free errors of memory pool contents. Tools like valgrind and MALLOC_DEBUG don't know when a pool is released because it gets put into the cache instead of being freed. * Added the "cache_pools" option to pjproject.conf. Disabling the option helps track down pool content mismanagement when using valgrind or MALLOC_DEBUG. The cache gets in the way of determining if the pool contents are used after free and who freed it. To disable the pool caching simply disable the cache_pools option in pjproject.conf and restart Asterisk. Sample pjproject.conf setting: [startup] cache_pools=no * Made current users of the caching pool factory initialization and destruction calls call common routines to create and destroy cached pools. ASTERISK-27704 Change-Id: I64d5befbaeed2532f93aa027a51eb52347d2b828
2018-02-14Merge "main/asterisk.c: Remove silly usage of RAII_VAR."Jenkins2
2018-02-12main/asterisk.c: Remove silly usage of RAII_VAR.Corey Farrell
Change-Id: I7e2996397fbd3c3a6a69dd805c38448ddfc34ae9
2018-02-12core: Remove embedded editline.Corey Farrell
This removes the embedded copy of editline from the Asterisk source tree, making a system copy of libedit mandatory in Asterisk 16+. ASTERISK-27634 #close Change-Id: Iedb64ad92acb78419f3caefedaa2bb7cd2a1a33f
2018-01-29Merge "core: Fix unused variable error in handle_show_sysinfo."Jenkins2
2018-01-27core: Fix unused variable error in handle_show_sysinfo.Alexander Traud
The previous fix broke the case HAVE_SYSINFO = no HAVE_SYSCTL = yes HAVE_SWAPCTL = no which occurs on FreeBSD 11.1 for example. ASTERISK-26563 Change-Id: If77c39bc75f0b83a6c8a24ecb2fa69be8846160a
2018-01-25core: Tweak startup order.Corey Farrell
Move initialization of units which do not require configuration to occur before preload modules. This leaves only units which load config between module preload and regular load stages. Change-Id: I1d15384acad16a22c3498124421af474fa517478
2017-12-20core: Fix unused variable error in handle_show_sysinfo.Corey Farrell
Apparently in OSX it's possible for OSX to HAVE_SYSCTL but not HAVE_SYSINFO or HAVE_SWAPCTL. In this case freeswap caused an unused variable error. ASTERISK-26563 #close Change-Id: I8ec5b1897b786cc1abaf62264aa75039eea05510
2017-12-19CLI: Address multiple issues.Corey Farrell
* listen uses the variable `s` for the result from ast_poll() then overwrites it with the result of accept(). Create a separate variable poll_result to avoid confusion since ast_poll does not return a file descriptor. * Resolve fd leak that would occur if setsockopt failed in listen. * Reserve an extra byte while processing completion results from remote daemon. This fixes a bug where completion processing used strstr() on a string that was not '\0' terminated. This was no risk to the Asterisk daemon, the bug was only reachable the remote console process. * Resolve leak in handle_showchan when the channel is not found. * Multiple leaks and a deadlock in pbx_config CLI completion. * Fix leaks in "manager show command". Change-Id: I8f633ceb1714867ae30ef4e421858f77c14485a9
2017-12-18Merge "CLI: Remove special handling of 'core set verbose' from rasterisk."George Joseph
2017-12-13CLI: Remove special handling of 'core set verbose' from rasterisk.Corey Farrell
rasterisk does not need to handle setting verbose levels locally, it should just tell the daemon what it wants and print what it is given. Just max out the verbose level on the local client so all filtering happens on the daemon. ASTERISK-20281 #close Change-Id: Ia305f75f1fc424a9169bfa30ef70d626ace2c8a8
2017-12-11CLI: Fix 'core show sysinfo' function ordering.Corey Farrell
Handle CLI initialization before any processing occurs. Change-Id: I598b911d2e409214bbdfd0ba0882be1d602d221c
2017-12-08utils: Add convenience function for setting fd flagsSean Bright
There are many places in the code base where we ignore the return value of fcntl() when getting/setting file descriptior flags. This patch introduces a convenience function that allows setting or clearing file descriptor flags and will also log an error on failure for later analysis. Change-Id: I8b81901e1b1bd537ca632567cdb408931c6eded7
2017-12-06sounds_index: Avoid repeatedly reindexing.Corey Farrell
The sounds index is rebuilt each time a format is registered or unregistered. This causes the index to be repeatedly rebuilt during startup and shutdown. This patch significantly reduces the work done by delaying sound index initialization until after modules are loaded. This way a reindex only occurs if a format module is loaded after startup. We also skip reindexing when format modules are unloaded during shutdown. Change-Id: I585fd6ee04200612ab1490dc804f76805f89cf0a
2017-11-27CLI: Remove compatibility code.Corey Farrell
Previous commits maintained compatibility with older remote console clients as well as maintaining all API's. Remove the following compatibility code: * ast_cli_generatornummatches. * Remote command "_command nummatches". * Sorting / duplicate removal by remote console. Change-Id: I59e6ce94fa57ae564888442049695f7e46746437
2017-11-21CLI: Finish conversion of completion handling to vectors.Corey Farrell
Change-Id: Ib81318f4ee52a5e73b003316e13fe9be1dd897a1
2017-11-21CLI: Refactor cli_complete.Corey Farrell
* Stop using "_COMMAND NUMMATCHES" on remote consoles. Using this command had doubled the amount of work needed from the Asterisk daemon for each completion request. * Fix code formatting. * Remove static buffer used to send the command, use the same buffer that will receive the results. * Move sort from ast_cli_display_match_list. Change-Id: Ie2211b519a3d4bec45bf46e0095bdd01d384cb69
2017-11-21CLI: Rewrite ast_el_strtoarr to use vector's internally.Corey Farrell
This rewrites ast_el_strtoarr to use vector's internally, but still return the original NULL terminated array of strings. Change-Id: Ibfe776cbe14f750effa9ca360930acaccc02e957
2017-11-21CLI: Refactor ast_cli_display_match_list.Corey Farrell
* Stop estimating line count, just print until we run out of matches. * Stop freeing entries, the caller does that anyways. * Stop calculating / returning numoutput, it was ignored. Change-Id: I7f92afa8bea92241a95227587367424c8c32a5cb
2017-11-14Merge "core: Fix configuration of remote console socket path."Joshua Colp
2017-11-14Merge "core: Use ast_alertpipe for Asterisk signal monitoring thread."Joshua Colp
2017-11-13core: Use ast_alertpipe for Asterisk signal monitoring thread.Corey Farrell
Reduce the signal monitoring thread file descriptor use from two to one on systems that support eventfd. Change-Id: Id4041a237d481ff699639e153ea6982fee14a462
2017-11-13core: Fix configuration of remote console socket path.Corey Farrell
The remote console socket path is the combination of asterisk.conf settings astrundir from [directories] and astctl from [files]. Unconditionally combine the two strings after processing all values to ensure we end up with the correct socket path. ASTERISK-27415 Change-Id: Ib1e2805d55d6b0955c6430a1a2a93acbf9b091e8
2017-11-11core: Add cache_media_frames debugging option.Richard Mudgett
The media frame cache gets in the way of finding use after free errors of media frames. Tools like valgrind and MALLOC_DEBUG don't know when a frame is released because it gets put into the cache instead of being freed. * Added the "cache_media_frames" option to asterisk.conf. Disabling the option helps track down media frame mismanagement when using valgrind or MALLOC_DEBUG. The cache gets in the way of determining if the frame is used after free and who freed it. NOTE: This option has no effect when Asterisk is compiled with the LOW_MEMORY compile time option enabled because the cache code does not exist. To disable the media frame cache simply disable the cache_media_frames option in asterisk.conf and restart Asterisk. Sample asterisk.conf setting: [options] cache_media_frames=no ASTERISK-27413 Change-Id: I0ab2ce0f4547cccf2eb214901835c2d951b78c00
2017-11-09core: Remove disabled code.Corey Farrell
handle_quit has been disabled since 2003, remove it. Change-Id: Idc3aaa6c81676160547078f9b71e8aa43de2db18
2017-08-30AST-2017-006: Fix app_minivm application MinivmNotify command injectionCorey Farrell
An admin can configure app_minivm with an externnotify program to be run when a voicemail is received. The app_minivm application MinivmNotify uses ast_safe_system() for this purpose which is vulnerable to command injection since the Caller-ID name and number values given to externnotify can come from an external untrusted source. * Add ast_safe_execvp() function. This gives modules the ability to run external commands with greater safety compared to ast_safe_system(). Specifically when some parameters are filled by untrusted sources the new function does not allow malicious input to break argument encoding. This may be of particular concern where CALLERID(name) or CALLERID(num) may be used as a parameter to a script run by ast_safe_system() which could potentially allow arbitrary command execution. * Changed app_minivm.c:run_externnotify() to use the new ast_safe_execvp() instead of ast_safe_system() to avoid command injection. * Document code injection potential from untrusted data sources for other shell commands that are under user control. ASTERISK-27103 Change-Id: I7552472247a84cde24e1358aaf64af160107aef1
2017-08-01Fix compiler warnings on Fedora 26 / GCC 7.Corey Farrell
GCC 7 has added capability to produce warnings, this fixes most of those warnings. The specific warnings are disabled in a few places: * app_voicemail.c: truncation of paths more than 4096 chars in many places. * chan_mgcp.c: callid truncated to 80 chars. * cdr.c: two userfields are combined to cdr copy, fix would break ABI. * tcptls.c: ignore use of deprecated method SSLv3_client_method(). ASTERISK-27156 #close Change-Id: I65f280e7d3cfad279d16f41823a4d6fddcbc4c88
2017-07-26Merge "Core: Add support for systemd socket activation."Jenkins2
2017-07-12Merge "Avoid setting maxfiles for a remote asterisk"Joshua Colp
2017-07-11Avoid setting maxfiles for a remote asteriskTzafrir Cohen
Setting maxfiles (maximum number of open files) has no practical effect on a remote asterisk (rasterisk, rasterisk -x). It has an ill effect of printing an extra message, which may be annoying in case of -x. ASTERISK-27105 #close Change-Id: Iaf9eb344e4b4b517df91b736b27ec55f6a6921a2
2017-07-05core: Remove 'Data Retrieval API'Sean Bright
This API was not actively maintained, was not added to new modules (such as res_pjsip), and there exist better alternatives to acquire the same information, such as the ARI. Change-Id: I4b2185a83aeb74798b4ad43ff8f89f971096aa83
2017-06-19Core: Add support for systemd socket activation.Corey Farrell
This change adds support for socket activation of certain SOCK_STREAM listeners in Asterisk: * AMI / AMI over TLS * CLI * HTTP / HTTPS Example systemd units are provided. This support extends to any socket which is initialized using ast_tcptls_server_start, so any unknown modules using this function will support socket activation. Asterisk continues to function as normal if socket activation is not enabled or if systemd development headers are not available during build. ASTERISK-27063 #close Change-Id: Id814ee6a892f4b80d018365c8ad8d89063474f4d
2017-04-12modules: change module LOAD_FAILUREs to LOAD_DECLINESGeorge Joseph
In all non-pbx modules, AST_MODULE_LOAD_FAILURE has been changed to AST_MODULE_LOAD_DECLINE. This prevents asterisk from exiting if a module can't be loaded. If the user wishes to retain the FAILURE behavior for a specific module, they can use the "require" or "preload-require" keyword in modules.conf. A new API was added to logger: ast_is_logger_initialized(). This allows asterisk.c/check_init() to print to the error log once the logger subsystem is ready instead of just to stdout. If something does fail before the logger is initialized, we now print to stderr instead of stdout. Change-Id: I5f4b50623d9b5a6cb7c5624a8c5c1274c13b2b25
2017-03-22rtp_engine: allocate RTP dynamic payloads per sessionKevin Harwell
Dynamic payload types were statically defined in Asterisk. This unfortunately limited the number of dynamic payloads that could be registered. With this patch dynamic payload type numbers are now assigned dynamically and per RTP instance. However, in order to limit any issues where some clients expect the old statically defined value this patch makes it so the value Asterisk used to pre- designate is used for the dynamic assignment if available. An option, "rtp_use_dynamic", has also been added (can be set in asterisk.conf) that turns the new dynamic behavior on or off. When off it reverts back to using statically defined payload values. This option defaults to "yes" in Asterisk 15. ASTERISK-26515 #close patches: ASTERISK-26515.diff submitted by jcolp (license 5000 Change-Id: I7653465c5ebeaf968f1a1cc8f3f4f5c4321da7fc
2017-01-24PJPROJECT logging: Fix detection of max supported log level.Richard Mudgett
The mechanism used for detecting the maximum log level compiled into the linked pjproject did not work. The API call simply stores the requested level into an integer and does no range checking. Asterisk was assuming that there was range checking and limited the new value to the allowable range. To get the actual maximum log level compiled into the linked pjproject we need to get and save off the initial set log level from pjproject. This is the maximum log level supported. * Get and save off the initial log level setting before altering it to the desired level on startup. This has to be done by a macro rather than calling a core function to avoid incorrectly linking pjproject. * Split the initial log level warning messages to warn if the linked pjproject cannot support the requested startup level and if it is too low to get the pjproject buildopts for "pjproject show buildopts". * Adjust the CLI "pjproject set log level" to check the saved max log level and to generate normal output messages instead of a warning message. ASTERISK-26743 #close Change-Id: I40aa76653e2a1dece66c3f8734594b4f0471cfb4
2016-11-30PJPROJECT logging: Made easier to get available logging levels.Richard Mudgett
Use of the new logging is as simple as issuing the new CLI command or setting the new pjproject.conf option. Other options that can affect the logging are how you have the pjproject log levels mapped to Asterisk log types in pjproject.conf and if you have configured Asterisk to log the DEBUG type messages. Altering the pjproject.conf level mapping shouldn't be necessary for most installations as the default mapping is sensible. Configuring Asterisk to log the DEBUG message type is standard practice for collecting debug information. * Added CLI "pjproject set log level" command to dynamically adjust the maximum pjproject log message level. * Added CLI "pjproject show log level" command to see the currently set maximum pjproject log message level. * Added pjproject.conf startup section "log_level" option to set the initial maximum pjproject log message level so all messages could be captured from initialization. * Set PJ_LOG_MAX_LEVEL to 6 to compile in all defined logging levels into bundled pjproject. Pjproject will use the currently set run time log level to determine if a log message is generated just like Asterisk verbose and debug logging levels. * In log_forwarder(), made always log enabled and mapped pjproject log messages. DEBUG mapped log messages are no longer gated by the current Asterisk debug logging level. * Removed RAII_VAR() from res_pjproject.c:get_log_level(). ASTERISK-26630 #close Change-Id: I6dca12979f482ffb0450aaf58db0fe0f6d2e5389
2016-11-26chan_sip: Fix segfault during module unloadMichael Kuron
If a TCP/TLS connection was pending (not accepted and not timed out) during unload of chan_sip, Asterisk would segfault when trying to send a signal to a thread whose thread ID hadn't been recorded yet. This commit fixes that by recording the thread ID before calling the blocking connect() syscall. This was a regression introduced by 776a14386a55b5425c7e9617eff8af8b45427144. The above wasn't enough to fix the segfault, which was now delayed to the point where connect() timed out. Therefore, it was necessary to also remove the SA_RESTART flag from the SIGURG sigaction so that pthread_kill() could be used to interruput the connect() syscall. This was a regression introduced by 5d313f51b982a18f7321adcf7c7a4e822d8b2714. ASTERISK-26586 #close Change-Id: I76fd9d47d56e4264e2629bce8ec15fecba673e7b
2016-11-14cli: Fix ast_el_read_char to work with libedit >= 3.1George Joseph
Libedit 3.1 is not build with unicode on as a default and so the prototype for the el_gets callback changed from expecting a char buffer to accepting a wchar buffer. If ast_el_read_char isn't changed, the cli reads garbage from teh terminal. Added a configure test for (*el_rfunc_t)(EditLine *, wchar_t *) and updated ast_el_read_char to use the HAVE_ define to detemrine whether to use char or wchar. ASTERISK-26592 #close Change-Id: I9099b46f68e06d0202ff80e53022a2b68b08871a
2016-11-02rtp_engine: Allow more than 32 dynamic payload types.Alexander Traud
Since adding all remaining rates of Signed Linear (ASTERISK-24274), SILK (Gerrit 3136) and Codec 2 (ASTERISK-26217), no RTP Payload Type is left in the dynamic range (96-127). RFC 3551 section 3 allows to reassign other ranges. Consequently, when the dynamic range is exhausted, this change utilizes payload types in the range between 35 and 63 giving room for another 29 payload types. ASTERISK-26311 #close Change-Id: I7bc96ab764bc30098a178b841cbf7146f9d64964
2016-10-28Fix shutdown crash caused by modules being left open.Corey Farrell
It is only safe to run ast_register_cleanup callbacks when all modules have been unloaded. Previously these callbacks were run during graceful shutdown, making it possible to crash during shutdown. ASTERISK-26513 #close Change-Id: Ibfa635bb688d1227ec54aa211d90d6bd45052e21
2016-10-27Remove ASTERISK_REGISTER_FILE.Corey Farrell
ASTERISK_REGISTER_FILE no longer has any purpose so this commit removes all traces of it. Previously exported symbols removed: * __ast_register_file * __ast_unregister_file * ast_complete_source_filename This also removes the mtx_prof static variable that was declared when MTX_PROFILE was enabled. This variable was only used in lock.c so it is now initialized in that file only. ASTERISK-26480 #close Change-Id: I1074af07d71f9e159c48ef36631aa432c86f9966
2016-09-29core: Remove ABI effects of LOW_MEMORY.Corey Farrell
This allows asterisk to compiled with LOW_MEMORY to load modules built without LOW_MEMORY. ASTERISK-26398 #close Change-Id: I24b78ac9493ab933b11087a8b6794f3c96d4872d
2016-09-21Merge "logger: Always enable verbose for console channel."Joshua Colp
2016-09-21Merge "core: Fix LOW_MEMORY missing symbol ast_pbx_uuid_get."zuul
2016-09-21Merge "asterisk.c: Non-root users also get the astcanary after core restart."zuul
2016-09-20core: Fix LOW_MEMORY missing symbol ast_pbx_uuid_get.Corey Farrell
Move the function outside the conditional block that excludes LOW_MEMORY. ASTERISK-26273 #close Change-Id: Ic290fa128222c410c3531107e30efacabc8493b4
2016-09-20logger: Always enable verbose for console channel.Corey Farrell
Previous versions of Asterisk did not require verbose to be specified in logger.conf for the console channel, if it was requested by command line or asterisk.conf it just worked. This change causes Asterisk to always enable verbose in the console channel level mask. Verbose is displayed on consoles if requested by command line, option_verbose or 'core set verbose'. This also delays initialization of the logger until after threadstorage is initialized. Initializing too early can cause messages to be printed multiple times to the console (stdout). ASTERISK-26391 #close Change-Id: I52187d67c2fcb3efd5561bf04b3e5e23e5ee8a04
2016-09-20Merge "sd_notify (systemd status notifications) support"zuul