Commit Graph

483 Commits

Author SHA1 Message Date
Richard Mudgett 1a36a452bd pjproject: Add cache_pools debugging option.
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-28 11:41:30 -06:00
Jenkins2 d6147aa6a3 Merge "main/asterisk.c: Remove silly usage of RAII_VAR." 2018-02-14 12:55:18 -06:00
Corey Farrell 9e45d3f893 main/asterisk.c: Remove silly usage of RAII_VAR.
Change-Id: I7e2996397fbd3c3a6a69dd805c38448ddfc34ae9
2018-02-12 22:15:34 -06:00
Corey Farrell 9fddc8b4dc core: Remove embedded editline.
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-02-12 04:44:26 -05:00
Jenkins2 21bcd85bba Merge "core: Fix unused variable error in handle_show_sysinfo." 2018-01-29 11:45:27 -06:00
Alexander Traud d9e42f27b9 core: Fix unused variable error in handle_show_sysinfo.
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-27 16:44:21 +01:00
Corey Farrell 39fcecad59 core: Tweak startup order.
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
2018-01-25 20:23:31 -05:00
Corey Farrell c2850bfebc core: Fix unused variable error in handle_show_sysinfo.
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-20 11:13:13 -05:00
Corey Farrell d51837a1b9 CLI: Address multiple issues.
* 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-19 16:43:49 -05:00
George Joseph 08440fd1d9 Merge "CLI: Remove special handling of 'core set verbose' from rasterisk." 2017-12-18 14:42:39 -06:00
Corey Farrell 5f6a3c4399 CLI: Remove special handling of 'core set verbose' from rasterisk.
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-13 11:10:37 -06:00
Corey Farrell c01ba7437e CLI: Fix 'core show sysinfo' function ordering.
Handle CLI initialization before any processing occurs.

Change-Id: I598b911d2e409214bbdfd0ba0882be1d602d221c
2017-12-11 20:21:16 -05:00
Sean Bright 2ffe52a116 utils: Add convenience function for setting fd flags
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-08 13:28:04 -06:00
Corey Farrell ab191e9782 sounds_index: Avoid repeatedly reindexing.
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-12-06 18:47:28 -05:00
Corey Farrell d12a2ab400 CLI: Remove compatibility code.
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-27 16:23:06 -06:00
Corey Farrell b79d04f8f8 CLI: Finish conversion of completion handling to vectors.
Change-Id: Ib81318f4ee52a5e73b003316e13fe9be1dd897a1
2017-11-21 09:48:36 -05:00
Corey Farrell fbb8c0d3e4 CLI: Refactor cli_complete.
* 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-21 09:48:36 -05:00
Corey Farrell 1cd24cd726 CLI: Rewrite ast_el_strtoarr to use vector's internally.
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-21 09:48:36 -05:00
Corey Farrell 9c0a2110f0 CLI: Refactor ast_cli_display_match_list.
* 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-21 09:48:36 -05:00
Joshua Colp a6d2926e5d Merge "core: Fix configuration of remote console socket path." 2017-11-14 10:31:40 -06:00
Joshua Colp 9d7b096023 Merge "core: Use ast_alertpipe for Asterisk signal monitoring thread." 2017-11-14 07:32:24 -06:00
Corey Farrell edd1016dd8 core: Use ast_alertpipe for Asterisk signal monitoring thread.
Reduce the signal monitoring thread file descriptor use from two to one
on systems that support eventfd.

Change-Id: Id4041a237d481ff699639e153ea6982fee14a462
2017-11-13 17:41:07 -05:00
Corey Farrell cdaaa14a5f core: Fix configuration of remote console socket path.
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-13 17:20:27 -05:00
Richard Mudgett 90bb0a3e10 core: Add cache_media_frames debugging option.
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-11 14:46:15 -05:00
Corey Farrell bb77666620 core: Remove disabled code.
handle_quit has been disabled since 2003, remove it.

Change-Id: Idc3aaa6c81676160547078f9b71e8aa43de2db18
2017-11-09 21:34:32 -05:00
Corey Farrell 1bf3dfffd7 AST-2017-006: Fix app_minivm application MinivmNotify command injection
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-30 18:43:38 +00:00
Corey Farrell 58d032112b Fix compiler warnings on Fedora 26 / GCC 7.
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-08-01 15:42:38 -06:00
Jenkins2 1bec535df2 Merge "Core: Add support for systemd socket activation." 2017-07-26 09:17:40 -05:00
Joshua Colp 95b35cb1cb Merge "Avoid setting maxfiles for a remote asterisk" 2017-07-12 04:24:43 -05:00
Tzafrir Cohen d58ef31acd Avoid setting maxfiles for a remote asterisk
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-11 20:46:42 +03:00
Sean Bright 325eeced6a core: Remove 'Data Retrieval API'
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-07-05 11:25:58 -05:00
Corey Farrell 70d2ccb9da Core: Add support for systemd socket activation.
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-06-19 13:33:48 -04:00
George Joseph 747beb1ed1 modules: change module LOAD_FAILUREs to LOAD_DECLINES
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-04-12 15:57:21 -06:00
Kevin Harwell 9b103e7bea rtp_engine: allocate RTP dynamic payloads per session
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-03-22 15:43:33 -05:00
Richard Mudgett 6f3e8c8e01 PJPROJECT logging: Fix detection of max supported log level.
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
2017-01-24 11:25:19 -06:00
Richard Mudgett 1dfa11b65c PJPROJECT logging: Made easier to get available logging levels.
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-30 13:11:48 -06:00
Michael Kuron 0b588778c0 chan_sip: Fix segfault during module unload
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 776a14386a.

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 5d313f51b9.

ASTERISK-26586 #close

Change-Id: I76fd9d47d56e4264e2629bce8ec15fecba673e7b
2016-11-26 18:20:06 +01:00
George Joseph 72da2ef9ff cli: Fix ast_el_read_char to work with libedit >= 3.1
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-14 13:20:38 -05:00
Alexander Traud 9ac53877f6 rtp_engine: Allow more than 32 dynamic payload types.
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-11-02 08:44:26 -05:00
Corey Farrell d6ad867897 Fix shutdown crash caused by modules being left open.
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-28 10:24:26 -05:00
Corey Farrell a6e5bae3ef Remove ASTERISK_REGISTER_FILE.
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-10-27 09:53:55 -04:00
Corey Farrell 8c5c95ad89 core: Remove ABI effects of LOW_MEMORY.
This allows asterisk to compiled with LOW_MEMORY to load modules built
without LOW_MEMORY.

ASTERISK-26398 #close

Change-Id: I24b78ac9493ab933b11087a8b6794f3c96d4872d
2016-09-29 03:22:28 -04:00
Joshua Colp 57b29f3b69 Merge "logger: Always enable verbose for console channel." 2016-09-21 14:35:27 -05:00
zuul 4caee4a11b Merge "core: Fix LOW_MEMORY missing symbol ast_pbx_uuid_get." 2016-09-21 11:31:54 -05:00
zuul f84652bd81 Merge "asterisk.c: Non-root users also get the astcanary after core restart." 2016-09-21 07:10:09 -05:00
Corey Farrell 5cb905a227 core: Fix LOW_MEMORY missing symbol ast_pbx_uuid_get.
Move the function outside the conditional block that excludes
LOW_MEMORY.

ASTERISK-26273 #close

Change-Id: Ic290fa128222c410c3531107e30efacabc8493b4
2016-09-20 15:23:25 -05:00
Corey Farrell 00f1d05d34 logger: Always enable verbose for console channel.
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-20 13:03:40 -04:00
zuul ea8105cf5e Merge "sd_notify (systemd status notifications) support" 2016-09-20 11:19:02 -05:00
zuul d36da3a26b Merge "Fix showing of swap details when sysinfo() is available" 2016-09-19 16:05:02 -05:00
Walter Doekes 0bc9912739 asterisk.c: Non-root users also get the astcanary after core restart.
Without this change, a 'core restart' would kill the astcanary forever
if you're not running as root. Both with and without this patch, the
scheduling priority was still SCHED_RR after restart.

Additionally, the astcanary is now spawned if you start with high
priority and Asterisk doesn't get a chance to lower it. For example
through: `chrt -r 10 sudo -u asterisk asterisk -c`

Also reap killed astcanary processes on core restart.

ASTERISK-26352 #close

Change-Id: Iacb49f26491a0717084ad46ed96b0bea5f627a55
2016-09-19 22:33:42 +02:00