aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt22
-rw-r--r--docbook/release-notes.adoc5
-rw-r--r--docbook/wsdg_src/wsdg_lua_support.adoc34
-rw-r--r--epan/wslua/CMakeLists.txt7
-rw-r--r--epan/wslua/init.lua26
-rw-r--r--epan/wslua/init_wslua.c53
-rw-r--r--packaging/nsis/CMakeLists.txt8
-rw-r--r--packaging/wix/CMakeLists.txt10
-rw-r--r--test/lua/globals_2.2.txt2
9 files changed, 61 insertions, 106 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0f91ca10b4..888921ecf0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2385,28 +2385,6 @@ if (BUILD_logray AND ENABLE_APPLICATION_BUNDLE)
endforeach()
endif()
-# Install Lua files in staging directory such that Lua can used when Wireshark
-# is ran from the build directory. For install targets, see
-# epan/wslua/CMakeLists.txt
-if(LUA_FOUND AND ENABLE_LUA)
- set(_lua_files
- "${CMAKE_SOURCE_DIR}/epan/wslua/init.lua"
- )
- foreach(_lua_file ${_lua_files})
- get_filename_component(_lua_filename "${_lua_file}" NAME)
- list(APPEND copy_data_files_depends
- "${DATAFILE_DIR}/${_lua_filename}")
- add_custom_command(OUTPUT "${DATAFILE_DIR}/${_lua_filename}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "${_lua_file}"
- "${DATAFILE_DIR}/${_lua_filename}"
- DEPENDS
- "${_lua_file}"
- )
- endforeach()
-endif(LUA_FOUND AND ENABLE_LUA)
-# doc/*.html handled elsewhere.
-
set(_protocol_data_dir ${CMAKE_SOURCE_DIR}/resources/protocols)
# Glob patterns relative to the source directory that should be copied to
# ${DATAFILE_DIR} (including directory prefixes)
diff --git a/docbook/release-notes.adoc b/docbook/release-notes.adoc
index 5b76da8fb5..8d7807e26f 100644
--- a/docbook/release-notes.adoc
+++ b/docbook/release-notes.adoc
@@ -195,6 +195,11 @@ The following features are new (or have been significantly updated) since versio
* Installation of development header must be done explicitly using the CMake
command ``cmake --install <builddir> --component Development``.
+* The "init.lua" file is now loaded from any of the Lua plugins directory.
+ Previously it was loaded from the personal configuration directory. (For
+ backward-compatibility this is still allowed; note that deprecated features
+ may be removed in a future release).
+
=== Removed Features and Support
* With the addition of the universal and consistent filtering support for
diff --git a/docbook/wsdg_src/wsdg_lua_support.adoc b/docbook/wsdg_src/wsdg_lua_support.adoc
index fd6db05135..40f6ac53c8 100644
--- a/docbook/wsdg_src/wsdg_lua_support.adoc
+++ b/docbook/wsdg_src/wsdg_lua_support.adoc
@@ -14,21 +14,37 @@ applications. Wireshark contains an embedded Lua 5.2 interpreter which
can be used to write dissectors, taps, and capture file readers
and writers.
-Wireshark’s Lua interpreter starts by loading a file named `init.lua` from
-Wireshark's link:{wireshark-users-guide-url}ChAppFilesConfigurationSection.html[_global configuration directory_].
-The _global configuration directory_'s `init.lua` controls whether or not Lua
-scripts are enabled via the
+If Lua is enabled, Wireshark will first try to load a file named `init.lua`
+from the global link:{wireshark-users-guide-url}ChPluginFolders.html[_plugins directory_].
+and then from the user’s
+link:{wireshark-users-guide-url}ChAppFilesConfigurationSection.html[_personal plugins directory_]. Then all files ending with _.lua_ are loaded from the global plugins
+directory. Then Then all files ending with _.lua_ in the personal Lua plugin's
+directory.
+
+Whether or not Lua scripts are enabled can be controlled via the
_$$enable_lua$$_ variable. Lua scripts are enabled by
default. To disable Lua scripts, set the _$$enable_lua$$_ variable to _false_.
Wireshark 2.6 and earlier enabled or disabled Lua scripts using
the variable _$$disable_lua$$_ (deprecated). If both _$$enable_lua$$_ and
_$$disable_lua$$_ are present, _$$disable_lua$$_ is ignored.
-If Lua is enabled, Wireshark will try to load a file named `init.lua`
-from the user’s
-link:{wireshark-users-guide-url}ChAppFilesConfigurationSection.html[_personal configuration directory_]
-and all files ending with _.lua_ in the global and the personal
-link:{wireshark-users-guide-url}ChPluginFolders.html[_plugins directory_].
+.Example for init.lua
+[source,lua]
+----
+-- Set enable_lua to false to disable Lua support.
+enable_lua = true
+
+if not enable_lua then
+ return
+end
+
+-- If false and Wireshark was started as (setuid) root, then the user
+-- will not be able to execute custom Lua scripts from the personal
+-- configuration directory, the -Xlua_script command line option or
+-- the Lua Evaluate menu option in the GUI.
+-- Note: Not checked on Windows. running_superuser is always false.
+run_user_scripts_when_superuser = true
+----
The command line option _$$-X lua_script:$$++file.lua++_ can also be used to load
specific Lua scripts.
diff --git a/epan/wslua/CMakeLists.txt b/epan/wslua/CMakeLists.txt
index b708769f99..c7d16e1cdc 100644
--- a/epan/wslua/CMakeLists.txt
+++ b/epan/wslua/CMakeLists.txt
@@ -109,13 +109,6 @@ add_custom_target(
set_target_properties(register_wslua PROPERTIES FOLDER "Libs/epan/wslua")
-install(
- FILES
- init.lua
- DESTINATION
- ${CMAKE_INSTALL_DATADIR}
-)
-
add_library(wslua OBJECT
${WSLUA_FILES}
)
diff --git a/epan/wslua/init.lua b/epan/wslua/init.lua
deleted file mode 100644
index b83302ec7a..0000000000
--- a/epan/wslua/init.lua
+++ /dev/null
@@ -1,26 +0,0 @@
--- init.lua
---
--- initialize wireshark's lua
---
--- This file is going to be executed before any other lua script.
--- It can be used to load libraries, disable functions and more.
---
--- Wireshark - Network traffic analyzer
--- By Gerald Combs <gerald@wireshark.org>
--- Copyright 1998 Gerald Combs
---
--- SPDX-License-Identifier: GPL-2.0-or-later
-
--- Set enable_lua to false to disable Lua support.
-enable_lua = true
-
-if not enable_lua then
- return
-end
-
--- If false and Wireshark was started as (setuid) root, then the user
--- will not be able to execute custom Lua scripts from the personal
--- configuration directory, the -Xlua_script command line option or
--- the Lua Evaluate menu option in the GUI.
--- Note: Not checked on Windows. running_superuser is always false.
-run_user_scripts_when_superuser = true
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c
index 1b13be3fcb..c0f7e08276 100644
--- a/epan/wslua/init_wslua.c
+++ b/epan/wslua/init_wslua.c
@@ -733,6 +733,7 @@ static gboolean lua_load_plugin_script(const gchar* name,
const gchar* dirname,
const int file_count)
{
+ ws_debug("Loading lua script: %s", filename);
if (lua_load_script(filename, dirname, file_count)) {
wslua_add_plugin(name, get_current_plugin_version(), filename);
clear_current_plugin_version();
@@ -767,8 +768,12 @@ static int lua_load_plugins(const char *dirname, register_cb cb, gpointer client
while ((file = ws_dir_read_name(dir)) != NULL) {
name = ws_dir_get_name(file);
- if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
- continue; /* skip "." and ".." */
+ if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0 ||
+ strcmp(name, "init.lua") == 0) {
+ /* skip "." and ".." */
+ /* init.lua was already loaded if it exists, skip */
+ continue;
+ }
filename = ws_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", dirname, name);
if (test_for_directory(filename) == EISDIR) {
@@ -867,19 +872,11 @@ static int lua_load_pers_plugins(register_cb cb, gpointer client_data,
}
int wslua_count_plugins(void) {
- gchar* filename;
int plugins_counter;
/* count global scripts */
plugins_counter = lua_load_global_plugins(NULL, NULL, TRUE);
- /* count users init.lua */
- filename = get_persconffile_path("init.lua", FALSE);
- if ((file_exists(filename))) {
- plugins_counter++;
- }
- g_free(filename);
-
/* count user scripts */
plugins_counter += lua_load_pers_plugins(NULL, NULL, TRUE);
@@ -1595,12 +1592,32 @@ void wslua_init(register_cb cb, gpointer client_data) {
}
/* load system's init.lua */
- filename = get_datafile_path("init.lua");
- if (( file_exists(filename))) {
+ filename = g_build_filename(get_plugins_dir(), "init.lua", (char *)NULL);
+ if (file_exists(filename)) {
+ ws_debug("Loading init.lua file: %s", filename);
lua_load_internal_script(filename);
}
-
g_free(filename);
+
+ /* load user's init.lua */
+ /* if we are indeed superuser run user scripts only if told to do so */
+ if (!started_with_special_privs() || run_anyway) {
+ filename = g_build_filename(get_plugins_pers_dir(), "init.lua", (char *)NULL);
+ if (file_exists(filename)) {
+ ws_debug("Loading init.lua file: %s", filename);
+ lua_load_internal_script(filename);
+ }
+ g_free(filename);
+
+ /* For backward compatibility also load it from the configuration directory. */
+ filename = get_persconffile_path("init.lua", FALSE);
+ if (file_exists(filename)) {
+ ws_message("Loading init.lua file from deprecated path: %s", filename);
+ lua_load_internal_script(filename);
+ }
+ g_free(filename);
+ }
+
filename = NULL;
/* check if lua is to be disabled */
@@ -1636,15 +1653,7 @@ void wslua_init(register_cb cb, gpointer client_data) {
lua_pop(L,1); /* pop the getglobal result */
/* if we are indeed superuser run user scripts only if told to do so */
- if ( (!started_with_special_privs()) || run_anyway ) {
- /* load users init.lua */
- filename = get_persconffile_path("init.lua", FALSE);
- if ((file_exists(filename))) {
- if (cb)
- (*cb)(RA_LUA_PLUGINS, get_basename(filename), client_data);
- lua_load_internal_script(filename);
- }
- g_free(filename);
+ if (!started_with_special_privs() || run_anyway) {
/* load user scripts */
lua_load_pers_plugins(cb, client_data, FALSE);
diff --git a/packaging/nsis/CMakeLists.txt b/packaging/nsis/CMakeLists.txt
index 6a40e465f2..4dea03cae9 100644
--- a/packaging/nsis/CMakeLists.txt
+++ b/packaging/nsis/CMakeLists.txt
@@ -179,11 +179,6 @@ if (BUILD_wireshark)
set(_all_manifest_contents "${_all_manifest_contents}File \"${_path}\"\n")
endforeach()
endif()
- if(LUA_FOUND)
- foreach(_script "init.lua")
- set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_script}\"\n")
- endforeach()
- endif()
file(WRITE "${_all_manifest}" "${_all_manifest_contents}")
endif()
@@ -220,9 +215,6 @@ if (BUILD_logray)
)
set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_dll}\"\n")
endforeach()
- foreach(_script "init.lua")
- set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_script}\"\n")
- endforeach()
file(WRITE "${_all_manifest}" "${_all_manifest_contents}")
endif()
diff --git a/packaging/wix/CMakeLists.txt b/packaging/wix/CMakeLists.txt
index f995c80e95..937ab71b43 100644
--- a/packaging/wix/CMakeLists.txt
+++ b/packaging/wix/CMakeLists.txt
@@ -144,12 +144,6 @@ foreach(_dll ${CARES_DLL} ${PCRE2_DLL} ${GCRYPT_DLLS}
SET(unique_component ${unique_component} ${_dll})
ENDIF(NOT "${unique_component}" MATCHES "(^|;)${_dll}(;|$)")
endforeach()
-foreach(_script "init.lua")
- STRING(REGEX REPLACE "[-|\\.]" "_" _wix_name ${_script})
- file(APPEND "${_all_manifest_wix}" " <Component Id=\"cmp${_wix_name}\" Guid=\"*\">\n")
- file(APPEND "${_all_manifest_wix}" " <File Id=\"fil${_wix_name}\" KeyPath=\"yes\" Source=\"$(var.Staging.Dir)\\${_script}\"/>\n")
- file(APPEND "${_all_manifest_wix}" " </Component>\n")
-endforeach()
file(APPEND "${_all_manifest_wix}" " </DirectoryRef>\n")
file(APPEND "${_all_manifest_wix}" " </Fragment>\n")
file(APPEND "${_all_manifest_wix}" " <Fragment>\n")
@@ -182,10 +176,6 @@ foreach(_dll ${CARES_DLL} ${PCRE2_DLL} ${GCRYPT_DLLS}
SET(unique_file ${unique_file} ${_dll})
ENDIF(NOT "${unique_file}" MATCHES "(^|;)${_dll}(;|$)")
endforeach()
-foreach(_script "init.lua")
- STRING(REGEX REPLACE "[-|\\.]" "_" _wix_name ${_script})
- file(APPEND "${_all_manifest_wix}" " <ComponentRef Id=\"cmp${_wix_name}\" />\n")
-endforeach()
file(APPEND "${_all_manifest_wix}" " </ComponentGroup>\n")
file(APPEND "${_all_manifest_wix}" " </Fragment>\n")
file(APPEND "${_all_manifest_wix}" "\n</Wix>\n")
diff --git a/test/lua/globals_2.2.txt b/test/lua/globals_2.2.txt
index 51d22eefbf..4e3245727d 100644
--- a/test/lua/globals_2.2.txt
+++ b/test/lua/globals_2.2.txt
@@ -714,7 +714,6 @@
["datafile_path"] = '<function 33>',
["deregister_filehandler"] = '<function 382>',
["dofile"] = '<function 383>',
- ["enable_lua"] = true,
["error"] = '<function 384>',
["expert"] = {
["group"] = {
@@ -909,7 +908,6 @@
["rex_pcre2"] = {
["_VERSION"] = "Lrexlib 2.9.1 (for PCRE2)"
},
- ["run_user_scripts_when_superuser"] = '<filtered>',
["running_superuser"] = '<filtered>',
["select"] = '<function 474>',
["set_color_filter_slot"] = '<function 475>',