Avoid exposing HAVE_PLUGINS in the public API

Instead *_register_plugin() is turned into a noop (with a warning).

The test suit is failing with ENABLE_PLUGINS=Off (it was already failing
before and this patch didn't affect that).

Closes #17202.
This commit is contained in:
João Valverde 2021-02-06 16:35:51 +00:00 committed by Wireshark GitLab Utility
parent 91064e337c
commit 89fee9321e
17 changed files with 103 additions and 75 deletions

View File

@ -567,6 +567,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
epan_load_settings@Base 2.3.0
epan_memmem@Base 1.9.1
epan_new@Base 1.12.0~rc1
epan_plugins_supported@Base 3.5.0
epan_register_plugin@Base 2.5.0
epan_strcasestr@Base 1.9.1
escape_string@Base 1.9.1

View File

@ -128,6 +128,7 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_opttypes_initialize@Base 2.1.2
wtap_opttypes_cleanup@Base 2.3.0
wtap_pcap_encap_to_wtap_encap@Base 1.9.1
wtap_plugins_supported@Base 3.5.0
wtap_read@Base 1.9.1
wtap_read_bytes@Base 1.99.1
wtap_read_bytes_or_eof@Base 1.99.1

View File

@ -15,7 +15,7 @@ project(Hello VERSION 0.0.1 DESCRIPTION "Wireshark Hello Plugin" LANGUAGES C)
find_package(Wireshark CONFIG REQUIRED)
if(NOT Wireshark_PLUGINS_ENABLED)
message(FATAL_ERROR "Wireshark was compiled without support for plugins")
message(WARNING "Wireshark was compiled without support for plugins")
endif()
set(CMAKE_C_VISIBILITY_PRESET hidden)

View File

@ -320,10 +320,6 @@ add_library(epan
${CMAKE_BINARY_DIR}/image/libwireshark.rc
)
if(ENABLE_PLUGINS)
target_compile_definitions(epan PUBLIC HAVE_PLUGINS)
endif()
set_target_properties(epan PROPERTIES
COMPILE_DEFINITIONS "WS_BUILD_DLL"
LINK_FLAGS "${WS_LINK_FLAGS}"

View File

@ -103,10 +103,13 @@ gboolean wireshark_abort_on_dissector_bug = FALSE;
gboolean wireshark_abort_on_too_many_items = FALSE;
#ifdef HAVE_PLUGINS
plugins_t *libwireshark_plugins = NULL;
static GSList *epan_plugins = NULL;
/* Used for bookkeeping, includes all libwireshark plugin types (dissector, tap, epan). */
static plugins_t *libwireshark_plugins = NULL;
#endif
/* "epan_plugins" are a specific type of libwireshark plugin (the name isn't the best for clarity). */
static GSList *epan_plugins = NULL;
const gchar*
epan_get_version(void) {
return VERSION;
@ -149,7 +152,6 @@ quiet_gcrypt_logger (void *dummy _U_, int level, const char *format, va_list arg
}
#endif // _WIN32
#ifdef HAVE_PLUGINS
static void
epan_plugin_init(gpointer data, gpointer user_data _U_)
{
@ -174,6 +176,7 @@ epan_plugin_cleanup(gpointer data, gpointer user_data _U_)
((epan_plugin *)data)->cleanup();
}
#ifdef HAVE_PLUGINS
void epan_register_plugin(const epan_plugin *plug)
{
epan_plugins = g_slist_prepend(epan_plugins, (epan_plugin *)plug);
@ -182,14 +185,28 @@ void epan_register_plugin(const epan_plugin *plug)
if (plug->register_all_handoffs)
epan_plugin_register_all_handoffs = g_slist_prepend(epan_plugin_register_all_handoffs, plug->register_all_handoffs);
}
#else /* HAVE_PLUGINS */
void epan_register_plugin(const epan_plugin *plug _U_)
{
g_warning("epan_register_plugin: built without support for binary plugins");
}
#endif /* HAVE_PLUGINS */
void epan_plugin_register_all_tap_listeners(gpointer data, gpointer user_data _U_)
int epan_plugins_supported(void)
{
#ifdef HAVE_PLUGINS
return g_module_supported() ? 0 : 1;
#else
return -1;
#endif
}
static void epan_plugin_register_all_tap_listeners(gpointer data, gpointer user_data _U_)
{
epan_plugin *plug = (epan_plugin *)data;
if (plug->register_all_tap_listeners)
plug->register_all_tap_listeners();
}
#endif
gboolean
epan_init(register_cb cb, gpointer client_data, gboolean load_plugins)
@ -265,13 +282,9 @@ epan_init(register_cb cb, gpointer client_data, gboolean load_plugins)
conversation_init();
capture_dissector_init();
reassembly_tables_init();
#ifdef HAVE_PLUGINS
g_slist_foreach(epan_plugins, epan_plugin_init, NULL);
#endif
proto_init(epan_plugin_register_all_procotols, epan_plugin_register_all_handoffs, cb, client_data);
#ifdef HAVE_PLUGINS
g_slist_foreach(epan_plugins, epan_plugin_register_all_tap_listeners, NULL);
#endif
packet_cache_proto_handles();
dfilter_init();
final_registration_all_protocols();
@ -329,11 +342,9 @@ epan_load_settings(void)
void
epan_cleanup(void)
{
#ifdef HAVE_PLUGINS
g_slist_foreach(epan_plugins, epan_plugin_cleanup, NULL);
g_slist_free(epan_plugins);
epan_plugins = NULL;
#endif
g_slist_free(epan_plugin_register_all_procotols);
epan_plugin_register_all_procotols = NULL;
g_slist_free(epan_plugin_register_all_handoffs);
@ -520,9 +531,7 @@ epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_pr
edt->tvb = NULL;
#ifdef HAVE_PLUGINS
g_slist_foreach(epan_plugins, epan_plugin_dissect_init, edt);
#endif
}
void
@ -634,9 +643,7 @@ epan_dissect_cleanup(epan_dissect_t* edt)
{
g_assert(edt);
#ifdef HAVE_PLUGINS
g_slist_foreach(epan_plugins, epan_plugin_dissect_cleanup, edt);
#endif
g_slist_free(edt->pi.proto_data);
g_slist_free(edt->pi.dependent_frames);

View File

@ -52,10 +52,6 @@ struct packet_provider_funcs {
const char *(*get_user_comment)(struct packet_provider_data *prov, const frame_data *fd);
};
#ifdef HAVE_PLUGINS
extern plugins_t *libwireshark_plugins;
#endif
/**
@section Epan The Enhanced Packet ANalyzer
@ -118,7 +114,6 @@ e_prefs *epan_load_settings(void);
WS_DLL_PUBLIC
void epan_cleanup(void);
#ifdef HAVE_PLUGINS
typedef struct {
void (*init)(void);
void (*dissect_init)(epan_dissect_t *);
@ -130,7 +125,14 @@ typedef struct {
} epan_plugin;
WS_DLL_PUBLIC void epan_register_plugin(const epan_plugin *plugin);
#endif
/** Returns_
* 0 if plugins can be loaded for all of libwireshark (tap, dissector, epan).
* 1 if plugins are not supported by the platform.
* -1 if plugins were disabled in the build configuration.
*/
WS_DLL_PUBLIC int epan_plugins_supported(void);
/**
* Initialize the table of conversations. Conversations are identified by
* their endpoints; they are used for protocols such as IP, TCP, and UDP,

View File

@ -444,18 +444,21 @@ proto_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
return g_ascii_strcasecmp(p1->short_name, p2->short_name);
}
#ifdef HAVE_PLUGINS
static GSList *dissector_plugins = NULL;
#ifdef HAVE_PLUGINS
void
proto_register_plugin(const proto_plugin *plug)
{
if (!plug) {
/* XXX print useful warning */
return;
}
dissector_plugins = g_slist_prepend(dissector_plugins, (proto_plugin *)plug);
}
#else /* HAVE_PLUGINS */
void
proto_register_plugin(const proto_plugin *plug _U_)
{
g_warning("proto_register_plugin: built without support for binary plugins");
}
#endif /* HAVE_PLUGINS */
static void
call_plugin_register_protoinfo(gpointer data, gpointer user_data _U_)
@ -476,7 +479,6 @@ call_plugin_register_handoff(gpointer data, gpointer user_data _U_)
plug->register_handoff();
}
}
#endif /* HAVE_PLUGINS */
/* initialize data structures and register protocols and fields */
void
@ -527,12 +529,10 @@ proto_init(GSList *register_all_plugin_protocols_list,
((void (*)(register_cb, gpointer))l->data)(cb, client_data);
}
#ifdef HAVE_PLUGINS
/* Now call the registration routines for all dissector plugins. */
if (cb)
(*cb)(RA_PLUGIN_REGISTER, NULL, client_data);
g_slist_foreach(dissector_plugins, call_plugin_register_protoinfo, NULL);
#endif
/* Now call the "handoff registration" routines of all built-in
dissectors; those routines register the dissector in other
@ -545,12 +545,10 @@ proto_init(GSList *register_all_plugin_protocols_list,
((void (*)(register_cb, gpointer))l->data)(cb, client_data);
}
#ifdef HAVE_PLUGINS
/* Now do the same with dissector plugins. */
if (cb)
(*cb)(RA_PLUGIN_HANDOFF, NULL, client_data);
g_slist_foreach(dissector_plugins, call_plugin_register_handoff, NULL);
#endif
/* sort the protocols by protocol name */
protocols = g_list_sort(protocols, proto_compare_name);
@ -643,10 +641,8 @@ proto_cleanup(void)
proto_free_deregistered_fields();
proto_cleanup_base();
#ifdef HAVE_PLUGINS
g_slist_free(dissector_plugins);
dissector_plugins = NULL;
#endif
}
static gboolean

View File

@ -40,9 +40,6 @@
#include "register.h"
#include "ws_symbol_export.h"
#include "ws_attributes.h"
#ifdef HAVE_PLUGINS
#include "wsutil/plugins.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -1038,7 +1035,6 @@ extern gboolean proto_tree_traverse_post_order(proto_tree *tree,
WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
proto_tree_foreach_func func, gpointer data);
#ifdef HAVE_PLUGINS
typedef struct {
void (*register_protoinfo)(void); /* routine to call to register protocol information */
void (*register_handoff)(void); /* routine to call to register dissector handoff */
@ -1046,7 +1042,6 @@ typedef struct {
/** Register dissector plugin with the plugin system. */
WS_DLL_PUBLIC void proto_register_plugin(const proto_plugin *plugin);
#endif
/** Sets up memory used by proto routines. Called at program startup */
void proto_init(GSList *register_all_plugin_protocols_list,

View File

@ -93,14 +93,21 @@ typedef struct _tap_listener_t {
static tap_listener_t *tap_listener_queue=NULL;
#ifdef HAVE_PLUGINS
static GSList *tap_plugins = NULL;
#ifdef HAVE_PLUGINS
void
tap_register_plugin(const tap_plugin *plug)
{
tap_plugins = g_slist_prepend(tap_plugins, (tap_plugin *)plug);
}
#else /* HAVE_PLUGINS */
void
tap_register_plugin(const tap_plugin *plug _U_)
{
g_warning("tap_register_plugin: built without support for binary plugins");
}
#endif /* HAVE_PLUGINS */
static void
call_plugin_register_tap_listener(gpointer data, gpointer user_data _U_)
@ -111,7 +118,6 @@ call_plugin_register_tap_listener(gpointer data, gpointer user_data _U_)
plug->register_tap_listener();
}
}
#endif /* HAVE_PLUGINS */
/*
* For all taps, call their register routines.
@ -122,12 +128,10 @@ call_plugin_register_tap_listener(gpointer data, gpointer user_data _U_)
void
register_all_tap_listeners(tap_reg_t *tap_reg_listeners)
{
#ifdef HAVE_PLUGINS
/* we register the plugin taps before the other taps because
* stats_tree taps plugins will be registered as tap listeners
* by stats_tree_stat.c and need to registered before that */
g_slist_foreach(tap_plugins, call_plugin_register_tap_listener, NULL);
#endif
/* Register all builtin listeners. */
for (tap_reg_t *t = &tap_reg_listeners[0]; t->cb_func != NULL; t++) {
@ -770,10 +774,8 @@ void tap_cleanup(void)
g_free((gpointer)elem_dl);
}
#ifdef HAVE_PLUGINS
g_slist_free(tap_plugins);
tap_plugins = NULL;
#endif /* HAVE_PLUGINS */
}
/*

View File

@ -14,9 +14,6 @@
#include <epan/epan.h>
#include <epan/packet_info.h>
#include "ws_symbol_export.h"
#ifdef HAVE_PLUGINS
#include "wsutil/plugins.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -47,14 +44,12 @@ typedef void (*tap_finish_cb)(void *tapdata);
#define TL_IS_DISSECTOR_HELPER 0x00000008 /**< tap helps a dissector do work
** but does not, itself, require dissection */
#ifdef HAVE_PLUGINS
typedef struct {
void (*register_tap_listener)(void); /* routine to call to register tap listener */
} tap_plugin;
/** Register tap plugin with the plugin system. */
WS_DLL_PUBLIC void tap_register_plugin(const tap_plugin *plug);
#endif
/*
* Entry in the table of built-in taps to register.

View File

@ -450,8 +450,10 @@ get_runtime_version_info(void (*additional_info)(GString *))
g_string_append_printf(str, ", binary plugins supported (%d loaded)", plugins_get_count());
}
else {
g_string_append(str, ", binary plugins not supported");
g_string_append(str, ", binary plugins not supported by the platform");
}
#else
g_string_append(str, ", built without support for binary plugins");
#endif
g_string_append(str, ".");

View File

@ -21,6 +21,8 @@
#include "wtap.h"
#include "wtap_opttypes.h"
#define wtap_warn(...) g_warning(__VA_ARGS__)
WS_DLL_PUBLIC
int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err);

View File

@ -20,18 +20,39 @@
#include "file_wrappers.h"
#include <wsutil/file_util.h>
#include <wsutil/buffer.h>
#ifdef HAVE_PLUGINS
#include <wsutil/plugins.h>
#endif
#ifdef HAVE_PLUGINS
static plugins_t *libwiretap_plugins = NULL;
#endif
static GSList *wtap_plugins = NULL;
#ifdef HAVE_PLUGINS
void
wtap_register_plugin(const wtap_plugin *plug)
{
wtap_plugins = g_slist_prepend(wtap_plugins, (wtap_plugin *)plug);
}
#else /* HAVE_PLUGINS */
void
wtap_register_plugin(const wtap_plugin *plug _U_)
{
wtap_warn("wtap_register_plugin: built without support for binary plugins");
}
#endif /* HAVE_PLUGINS */
int
wtap_plugins_supported(void)
{
#ifdef HAVE_PLUGINS
return g_module_supported() ? 0 : 1;
#else
return -1;
#endif
}
static void
call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_)
@ -42,7 +63,6 @@ call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_)
plug->register_wtap_module();
}
}
#endif /* HAVE_PLUGINS */
/*
* Return the size of the file, as reported by the OS.
@ -1789,8 +1809,8 @@ wtap_init(gboolean load_wiretap_plugins)
if (load_wiretap_plugins) {
#ifdef HAVE_PLUGINS
libwiretap_plugins = plugins_init(WS_PLUGIN_WIRETAP);
g_slist_foreach(wtap_plugins, call_plugin_register_wtap_module, NULL);
#endif
g_slist_foreach(wtap_plugins, call_plugin_register_wtap_module, NULL);
}
}
@ -1804,9 +1824,9 @@ wtap_cleanup(void)
wtap_opttypes_cleanup();
ws_buffer_cleanup();
cleanup_open_routines();
#ifdef HAVE_PLUGINS
g_slist_free(wtap_plugins);
wtap_plugins = NULL;
#ifdef HAVE_PLUGINS
plugins_cleanup(libwiretap_plugins);
libwiretap_plugins = NULL;
#endif

View File

@ -17,9 +17,6 @@
#include "wtap_opttypes.h"
#include "ws_symbol_export.h"
#include "ws_attributes.h"
#ifdef HAVE_PLUGINS
#include "wsutil/plugins.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -2323,14 +2320,20 @@ GSList *wtap_get_file_extension_type_extensions(guint extension_type);
WS_DLL_PUBLIC
void wtap_register_file_type_extension(const struct file_extension_info *ei);
#ifdef HAVE_PLUGINS
typedef struct {
void (*register_wtap_module)(void); /* routine to call to register a wiretap module */
} wtap_plugin;
WS_DLL_PUBLIC
void wtap_register_plugin(const wtap_plugin *plug);
#endif
/** Returns_
* 0 if plugins can be loaded for libwiretap (file type).
* 1 if plugins are not supported by the platform.
* -1 if plugins were disabled in the build configuration.
*/
WS_DLL_PUBLIC
int wtap_plugins_supported(void);
WS_DLL_PUBLIC
void wtap_register_open_info(struct open_info *oi, const gboolean first_routine);

View File

@ -50,7 +50,6 @@ set(WSUTIL_PUBLIC_HEADERS
os_version_info.h
pint.h
please_report_bug.h
plugins.h
pow2.h
privileges.h
processes.h

View File

@ -14,15 +14,28 @@
#include "codecs.h"
#ifdef HAVE_PLUGINS
#include <wsutil/plugins.h>
#endif
#ifdef HAVE_PLUGINS
static plugins_t *libwscodecs_plugins = NULL;
#endif
static plugins_t *libwscodecs_plugins;
static GSList *codecs_plugins = NULL;
#ifdef HAVE_PLUGINS
void
codecs_register_plugin(const codecs_plugin *plug)
{
codecs_plugins = g_slist_prepend(codecs_plugins, (codecs_plugin *)plug);
}
#else /* HAVE_PLUGINS */
void
codecs_register_plugin(const codecs_plugin *plug _U_)
{
g_warning("codecs_register_plugin: built without support for binary plugins");
}
#endif /* HAVE_PLUGINS */
static void
call_plugin_register_codec_module(gpointer data, gpointer user_data _U_)
@ -33,7 +46,6 @@ call_plugin_register_codec_module(gpointer data, gpointer user_data _U_)
plug->register_codec_module();
}
}
#endif /* HAVE_PLUGINS */
/*
@ -44,16 +56,16 @@ codecs_init(void)
{
#ifdef HAVE_PLUGINS
libwscodecs_plugins = plugins_init(WS_PLUGIN_CODEC);
#endif
g_slist_foreach(codecs_plugins, call_plugin_register_codec_module, NULL);
#endif /* HAVE_PLUGINS */
}
void
codecs_cleanup(void)
{
#ifdef HAVE_PLUGINS
g_slist_free(codecs_plugins);
codecs_plugins = NULL;
#ifdef HAVE_PLUGINS
plugins_cleanup(libwscodecs_plugins);
libwscodecs_plugins = NULL;
#endif

View File

@ -14,21 +14,16 @@
#include <epan/epan.h>
#include "ws_symbol_export.h"
#include "ws_attributes.h"
#ifdef HAVE_PLUGINS
#include "wsutil/plugins.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef HAVE_PLUGINS
typedef struct {
void (*register_codec_module)(void); /* routine to call to register a codec */
} codecs_plugin;
WS_DLL_PUBLIC void codecs_register_plugin(const codecs_plugin *plug);
#endif
/**
* For all built-in codecs and codec plugins, call their register routines.