aboutsummaryrefslogtreecommitdiffstats
path: root/extcap.c
AgeCommit message (Collapse)AuthorFilesLines
2024-02-23extcap: Use extcap.cfg as extcap config file nameJohn Thacker1-1/+1
"extcap" by itself can be the name of a directory that stores extcap programs, especially if the default profile is being used. Add an extension to the default file name so it doesn't clash. Follow up to 4fb2ef8af871682905b29cc1f3dbbfaba41c9e38
2024-02-18extcap: Really don't load extcap interfaces if disabledJohn Thacker1-3/+17
If the capture.no_extcap preference is set, really don't load the extcap interfaces. Previously, the extcap interfaces were loaded before the preference was read, because otherwise the extcap preferences wouldn't be registered and properly read out of the configuration file. Wait until after that preference is read to register the extcap preferences and then re-read just the extcap module preferences from the configuration files. Make sure to check other times when the preference may be changed, such as switching profiles. Write extcap prefs to a separate file so that they don't get lost if the extcap interfaces aren't loaded and the prefs are then written out. Continue writing them to the main file for backwards compability. Related to #15295. Cuts ~100 ms off the loading time of Wireshark in a normal situation if the capture.no_extcap preference is set, more if an extcap has some kind of issue that makes it take a long time to load.
2024-02-15extcap: Update comments about callbackJohn Thacker1-3/+5
extcap_foreach no longer exists. The extcap_cb_t is used with extcap_run_one, and when operations are needed on multiple extcaps they are run in parallel in multiple threads, since each operations requires spawning a process. Update the comments to note this, and that the return value is no longer used.
2024-02-15extcap: Don't add args to a list just to destroy itJohn Thacker1-5/+6
Allow cb_preference to take a NULL for the pointer to a list of arguments. If the pointer is NULL, then free the argument list. This keeps extcap_load_interface_list from creating a list that is immediately freed.
2023-12-16extcap: Fix Coverity 1559270John Thacker1-2/+15
Check to see if the return pointer is non NULL
2023-12-15capture: Add return messages to the if_capabilities_t structJohn Thacker1-4/+4
Add the return messages to the if_capabilities_t struct. We are already serializing them in the JSON. This is necessary if we want to query the capabilities of multiple interfaces at once and determine which interfaces had failures and what each reason was. Keep the behavior of capture_get_if_capabilities, which retrieves a single interface, the same; it still returns NULL on failure and the messages separately. Related to #15082
2023-10-25plugins: Allow multiple types in descriptionJoão Valverde1-1/+1
Allow plugins to declare their type, for the purpose of inserting a description in the UI. The type consist of one or more bit ORed flags. This fixes the 'stats_tree' plugin description in the UI. The plugin is not a dissector type plugin, as was being displayed before. Now it correctly shows "tap listener" plugin.
2023-09-26Fix misppellings in root and ui directoriesMoshe Kaplan1-1/+1
Fix misppellings in root and ui directories. Most of these are comments, but some are in error messages.
2023-08-26Don't pretend to return an error string from append_extcap_interface_list().Guy Harris1-1/+1
append_extcap_interface_list() does not return an error string; remove the error string argument from it.
2023-08-12Get rid of a no-longer-needed header.Guy Harris1-3/+0
The include of <sys/wait.h> was added to get WIFEXITED defined; we no longer use WIFEXITED or any other such macros, and we don't call any of the wait() routines, so we shouldn't need <sys/wait.h>.
2023-02-07Move ui/version_info.[ch] to wsutilJoão Valverde1-2/+1
2023-02-06extcap: Fix of handling default valuesj.novak@netsystem.cz1-9/+16
2023-01-21Actually load user extcaps from the new pathJoão Valverde1-4/+1
Don't just say it, do it too. Follow-up to 39124f2f8f3419b624a9e3bab9fac4c2cfe23e18.
2023-01-13MinGW: Fix -WformatJoão Valverde1-6/+6
2022-12-12Extcap: Clean up our fifo in non-blocking mode.Gerald Combs1-1/+1
Use O_NONBLOCK when opening our fifo for cleanup. Ping #18715
2022-12-12Extcap: Create our fifo in a temporary directory.Gerald Combs1-16/+12
Instead of creating a temp file, unlinking it, and creating a fifo with the same name, add create_tempdir() so that we can create a temporary directory and create a fifo inside that. This should avoid a race condition in Carbon Black Cloud antivirus, which if the timing is right, will stat the initial temporary *file*, miss the fact that it's been replaced with a *fifo*, and open and steal data^W^W read from it, leaving dumpcap to contend with the truncated remains. Adding the unexpected magic number to cap_pipe_open_live()'s error message helped to debug this. Leave it in since it's handy to have in that case. Ping #15587
2022-12-12extcap: Do not hang if extcap doesn't open fifoTomasz Moń1-0/+9
Simply open and close the fifo as part of cleanup. Doing so lets dumpcap know that the capture has finished if extcap did not open the pipe. This is only needed on *NIX systems, because there was no hang on Windows. Fixes #18715
2022-08-16win32-utils: Explicitly list inherited handlesTomasz Moń1-1/+1
Windows processes inherit all inheritable handles when a new process is created using CreateProcess() with bInheritHandles set to TRUE. This can lead to undesired object lifetime extension. That is, the child process will keep ineritable handles alive even if it does not use them. Up to Windows Vista it was not possible explicitly list handles that should be inherited. Wireshark no longer works on Windows releases earlier than Vista, so use the new API without checking Windows version. Require all callers to win32_create_process() to pass in the list of handles to inherit. Set the listed handles as inheritable shortly before calling CreateProcess() and set them as not inheritable shortly after the process is created. This minimizes possibility for other callers (especially in 3rd party libraries) to inherit handles by accident. Do not terminate mmdbresolve process on exit. Instead rely on process exit when EOF is received on standard input. Previously the EOF was never received because mmdbresolve inherited both ends of standard input pipe, i.e. the fact that Wireshark closed the write end was not observed by mmdbresolve because mmdbresolve kept write handle the standard input pipe open.
2022-08-13capture: Stop extcaps before dumpcapTomasz Moń1-62/+79
Send SIGTERM on UNIX systems to all extcap processes when user requests capture stop. Wait up to 30 seconds for extcaps to finish. If extcaps do not finish in time, send SIGKILL to remaining extcaps. Do not call TerminateProcess() on Windows in the same place where UNIX SIGTERM is sent. Instead schedule extcap termination timeout to happen as soon as control returns back to the event loop. There is no universally agreed replacement for SIGTERM on Windows, so just keep things simple (forcefully terminate like always) until we have agreed on something.
2022-08-12extcap: Do not drain stderr on process exitTomasz Moń1-61/+139
Extcap child watch callback assumed that the stderr pipe is broken. However the stdout and stderr pipes are not necessarily broken if the child process spawned new processes that inherited standard handles. Do not drain stderr in busy loop to prevent UI freeze. Stop capture session only when all extcap watches are removed. Remove stdout and stderr watches on capture stop timer (30 seconds) expiration, even if the pipes are not broken. Do not rely only on 0 bytes read to cease reading stdout and stderr. Stop reading if the status is anything else than G_IO_STATUS_NORMAL (especially it can be G_IO_STATUS_EOF).
2022-08-10extcap: Read stdout and stderr during captureTomasz Moń1-10/+72
Read extcap stdout/stderr data when available to prevent extcap hang on stdout/stderr write. Discard stdout data as it was not used earlier. Store up to 1024 bytes of stderr and display it to user after capture stops. Fixes #17827
2022-08-10wsutil: Use GIOChannel for standard pipesTomasz Moń1-8/+6
Remove ws_read_string_from_pipe() as this function encourages bad design and is no longer necessary. Extcap stderr is read only after the child process has finished and thus the read will never block. Close process information thread handle right away as we don't use it. Remove unused ws_pipe_t member variables.
2022-08-10extcap: Close capture session after extcap finishesTomasz Moń1-121/+84
Wait up to 30 seconds for extcap process to finish after closing pipes. The wait is achieved in non-blocking fashion, i.e. the UI is completely responsive during the wait. Only actions related to capture process like capture control, file open, save, export are inactive during the wait. On Windows extcap child watch callback gets called immediately as the process is forcefully terminated. Prior to this change the extcap was forcefully terminated on Windows anyway. The wait is possible on UNIX systems if extcap does handle SIGPIPE and SIGTERM signals. The defaults handlers for SIGPIPE and SIGTERM simply terminate the process so for large number of extcaps there is no change. If extcap does not finish within 30 seconds, it is forcefully terminated using SIGKILL signal.
2022-02-09Specify directory for temporary capturesDavid Perry1-2/+8
2021-12-30Prefs/Extcap: Added support for password which is never stored on the diskj.novak@netsystem.cz1-1/+7
2021-12-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde1-3/+3
Use macros from inttypes.h.
2021-12-19Replace g_snprintf() with snprintf()João Valverde1-1/+1
Use macros from inttypes.h with format strings.
2021-12-05Define more log domains for extcapsJoão Valverde1-1/+1
2021-07-04Move version_info.[ch] to ui/João Valverde1-1/+1
Version info is an aspect of UI implementation so move it to a more appropriate place, such as ui/. This also helps declutter the top-level. A static library is appropriate to encapsulate the dependencies as private and it is better supported by CMake than object libraries. Also version_info.h should not be installed as a public header.
2021-06-19Replace g_assert() with ws_assert()João Valverde1-1/+2
2021-06-11Refactor our logging and extend the wslog APIJoão Valverde1-34/+24
Experience has shown that: 1. The current logging methods are not very reliable or practical. A logging bitmask makes little sense as the user-facing interface (who would want debug but not crtical messages for example?); it's computer-friendly and user-unfriendly. More importantly the console log level preference is initialized too late in the startup process to be used for the logging subsystem and that fact raises a number of annoying and hard-to-fix usability issues. 2. Coding around G_MESSAGES_DEBUG to comply with our log level mask and not clobber the user's settings or not create unexpected log misses is unworkable and generally follows the principle of most surprise. The fact that G_MESSAGES_DEBUG="all" can leak to other programs using GLib is also annoying. 3. The non-structured GLib logging API is very opinionated and lacks configurability beyond replacing the log handler. 4. Windows GUI has some special code to attach to a console, but it would be nice to abstract away the rest under a single interface. 5. Using this logger seems to be noticeably faster. Deprecate the console log level preference and extend our API to implement a log handler in wsutil/wslog.h to provide easy-to-use, flexible and dependable logging during all execution phases. Log levels have a hierarchy, from most verbose to least verbose (debug to error). When a given level is set everything above that is also enabled. The log level can be set with an environment variable or a command line option (parsed as soon as possible but still later than the environment). The default log level is "message". Dissector logging is not included because it is not clear what log domain they should use. An explosion to thousands of domains is not desirable and putting everything in a single domain is probably too coarse and noisy. For now I think it makes sense to let them do their own thing using g_log_default_handler() and continue using the G_MESSAGES_DEBUG mechanism with specific domains for each individual dissector. In the future a mechanism may be added to selectively enable these domains at runtime while trying to avoid the problems introduced by G_MESSAGES_DEBUG.
2021-05-24Add ws_debug() and use itJoão Valverde1-2/+1
Replace most instances of ws_debug_printf() except in epan/dissectors and dissector plugins. Some replacements use printf(), some use ws_debug(), and some were removed because they were dead or judged to be temporary.
2021-02-11extcap: Fix Dead Store found by Clang AnalyzerAlexis La Goutte1-3/+1
extcap.c:876:26: warning: Although the value stored to 'pref' is used in the enclosing expression, the value is never actually read from 'pref'
2020-11-25GLib: Bump requirement 2.32 -> 2.36John Thacker1-6/+0
2020-07-07extcap: Lazily load our interface list.Gerald Combs1-21/+42
Add extcap_ensure_all_interfaces_loaded, which calls extcap_load_interface_list if our interface list is empty. Call it in each of our public functions that require a valid interface list. Clean up the extcap API documentation and note which routines initialize the interface list. In tshark, don't unconditionally call extcap_register_preferences and instead rely on lazy loading. Change-Id: I8493ae5f4d703b0fd767246557d17723bcf207c6 Ping-Bug: 15295 Reviewed-on: https://code.wireshark.org/review/37750 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-02-01extcap: Check for valid PID before killing child processMikael Kanstrup1-1/+4
If an extcap tool fails to start or the tool exits unexpectedly Wireshark will try to kill PID -1. This has very unexpected results on Linux, like bringing down the whole window manager. Make sure it's a valid PID before killing the extcap child process. Bug: 16362 Change-Id: I58c0cb409fec3f35d3c76d841e2430a2f8742301 Fixes: v3.3.0rc0-461-g8efde39805 ("extcap: terminate the child process using kill.") Reviewed-on: https://code.wireshark.org/review/35998 Reviewed-by: Pascal Quantin <pascal@wireshark.org> Petri-Dish: Pascal Quantin <pascal@wireshark.org> Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <lomato@gmail.com> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2020-01-29extcap: terminate the child process using kill.Anders Esbensen1-0/+4
On linux and osx extcap would potentially leave the external dumper process running after stopping the capture. With this change the child process will receive a TERM signal when the capture stops. Change-Id: I2681a26509c90696c98c7615fbab172604ce6e31 Reviewed-on: https://code.wireshark.org/review/35959 Reviewed-by: Dario Lombardo <lomato@gmail.com> Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-12-20Use g_file_open_tmp within create_tempfileMichael Mann1-3/+6
Much better to use a known library than create it ourselves. Also remove get_tempfile_path as it's not used. Bug: 15992 Change-Id: I17b9bd879e8bdb540f79db83c6c138f8ee724764 Reviewed-on: https://code.wireshark.org/review/34420 Reviewed-by: Tomasz Moń <desowin@gmail.com> Petri-Dish: Tomasz Moń <desowin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
2019-12-19extcap: fix use-after-free bug.Dario Lombardo1-2/+1
Regression introduced in g1cd1e36. Change-Id: I85775ef86d9325d4f5bf811a5f52925a2cf0d387 Reviewed-on: https://code.wireshark.org/review/35503 Petri-Dish: Tomasz Moń <desowin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Tomasz Moń <desowin@gmail.com>
2019-12-15extcap: remove potential leak.Dario Lombardo1-3/+11
Found by clang. Change-Id: I84359a2f7985bca8b0089200b3c37d04e06effe2 Reviewed-on: https://code.wireshark.org/review/35354 Petri-Dish: Tomasz Moń <desowin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Tomasz Moń <desowin@gmail.com>
2019-12-10Revert "extcap: Pass --extcap-version if extcap supports it"Gerald Combs1-60/+15
This reverts commit 9910d8c913d2a1874c7f98ef3bf3ad2921dd67e4. Reasons for revert: - We need to improve the reliability of extcap-version=x.y detection. - WSDG_chapter_capture.adoc needs to be more clear about extcap-version=x.y support. - Our extcap utilities need to be updated. Change-Id: Ic8dd2018489f5ec03c35b18e6b09faf69defd59b Reviewed-on: https://code.wireshark.org/review/35393 Reviewed-by: Rafał Kuźnia <rafal.kuznia@protonmail.com> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2019-12-10extcap: Pass --extcap-version if extcap supports itRafał Kuźnia1-15/+60
This change makes the --extcap-version argument to be passed to the extcap script, if it is supported. If the extcap fails with --extcap-version argument, it is treated as legacy and will not receive the additional argument in all subsequent runs. Change-Id: I279aa38d9f39ed85ccb84ba2c09dd93a0492ca51 Reviewed-on: https://code.wireshark.org/review/34914 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-11-06extcap: Fix memory leak in extcap_get_extcap_pathsVasil Velichkov1-1/+4
The path returned by get_persconffile_path needs to be freed. Direct leak of 64 byte(s) in 1 object(s) allocated from: #0 0x5653e6c98e06 in realloc (/home/vasko/sources/wireshark/build_clang/run/wireshark+0x2486e06) #1 0x7f5b697f2e7d in g_realloc gmem.c:164:16 #2 0x7f5b69810016 in g_string_maybe_expand gstring.c:102:21 #3 0x7f5b69810369 gstring.c:476:7 #4 0x7f5b69810369 in g_string_insert_len gstring.c:424:1 #5 0x7f5b697d808d in g_build_path_va gfileutils.c:1766:7 #6 0x7f5b697d9518 in g_build_filename_va gfileutils.c:1987:9 #7 0x7f5b697d9518 in g_build_filename gfileutils.c:2069:9 #8 0x7f5b69bd0c28 in get_persconffile_path /home/vasko/sources/wireshark/wsutil/filesystem.c:1856:12 #9 0x5653e8825f82 in extcap_get_extcap_paths /home/vasko/sources/wireshark/extcap.c:258:53 #10 0x5653e8825f82 in extcap_run_all /home/vasko/sources/wireshark/extcap.c:449 #11 0x5653e8825f82 in extcap_load_interface_list /home/vasko/sources/wireshark/extcap.c:2024 #12 0x5653e7775356 in main /home/vasko/sources/wireshark/ui/qt/main.cpp:726:5 Change-Id: I275d0ad6f06fbf3222c2d4ebef7f3079073404a0 Reviewed-on: https://code.wireshark.org/review/34994 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
2019-11-05extcap: Allow loading of extcap files from personal directoryRoland Knall1-10/+25
Allow the storage of extcap plugins in the personal directory and enable loading from there. It will also take precedence of any system-wide extcaps with an identical name Change-Id: Ib88e09a26c4f99cf5e793327f2808c7445c6b1b5 Reviewed-on: https://code.wireshark.org/review/34988 Reviewed-by: Roland Knall <rknall@gmail.com>
2019-10-27extcap: Do not append disabled boolflagsTomasz Moń1-1/+1
If boolean flag is active by default, then when launching extcap without opening configuration dialog it would be added to extcap call regardless of user configuration. Modify the logic so default value is used only if there is no stored user configuration available. Change-Id: I1855a058a99e2395da5593486411e160d48fca4b Reviewed-on: https://code.wireshark.org/review/34865 Petri-Dish: Tomasz Moń <desowin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
2019-09-23extcap: Multiple extcap instance support on WindowsTomasz Moń1-1/+1
Wireshark does create named pipes and waits for the child process to connect. The named pipe server handle is inheritable and thus available in child dumpcap process. Pass the handle identifier instead of named pipe name so dumpcap can use it. Bug: 13653 Change-Id: Id2c019f67a63f1ea3d98b9da2153d6de5078cd01 Reviewed-on: https://code.wireshark.org/review/34503 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-09-21Qt, docs, ieee1905: fix some spelling errorsPeter Wu1-1/+1
The spelling error for "Desription" in the context menu was very obvious. The others were found by scanning the output of: grep -Po '<source>\K.*(?=</source>)' wireshark_en.ts Change-Id: I4b95236c82f76828a115d59d7c8e0b853eae1d26 Reviewed-on: https://code.wireshark.org/review/34582 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-07-26HTTPS (almost) everywhere.Guy Harris1-1/+1
Change all wireshark.org URLs to use https. Fix some broken links while we're at it. Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c Reviewed-on: https://code.wireshark.org/review/34089 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-06-10extcap: Do not use global pipe handle on WindowsTomasz Moń1-90/+87
Make extcap_create_pipe() static. Change-Id: I06a0af2dcf9fb4a51b4f7ba6ee7c57e7a52c5e97 Reviewed-on: https://code.wireshark.org/review/33250 Petri-Dish: Pascal Quantin <pascal@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Pascal Quantin <pascal@wireshark.org>
2019-05-21extcap: Fix memory leak in extcap_load_interface_list()Tomasz Moń1-0/+1
The content of the list returned by g_hash_table_get_values() is owned by GHashTable and should not be modified or freed. However, the list itself should be freed using g_list_free(). Change-Id: Ie4a1da290f25dbd6dc2f3a01f051bfca13bb01d3 Reviewed-on: https://code.wireshark.org/review/33281 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>