From 3086774fa69b1732ccc737951e87d68c81fef108 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 20 Feb 2022 12:09:34 -0800 Subject: [PATCH] wsutil: Add configuration namespaces. Rename init_progfile_dir to configuration_init. Add an argument which specifies our configuration namespace, which can be "Wireshark" (default) or "Logwolf". --- CMakeLists.txt | 6 ++ capinfos.c | 10 +-- captype.c | 10 +-- dftest.c | 10 +-- editcap.c | 10 +-- extcap/androiddump.c | 2 +- extcap/ciscodump.c | 2 +- extcap/dpauxmon.c | 10 +-- extcap/etwdump.c | 2 +- extcap/randpktdump.c | 2 +- extcap/sdjournal.c | 10 +-- extcap/sshdump.c | 2 +- extcap/udpdump.c | 2 +- extcap/wifidump.c | 2 +- fuzz/fuzzshark.c | 10 +-- mergecap.c | 10 +-- packaging/debian/libwsutil0.symbols | 2 +- randpkt.c | 12 ++-- rawshark.c | 2 +- reordercap.c | 10 +-- sharkd.c | 8 +-- tfshark.c | 10 +-- tshark.c | 2 +- ui/qt/main.cpp | 2 +- ui/qt_logshark/ls_main.cpp | 4 +- wsutil/file_util.c | 2 +- wsutil/filesystem.c | 107 +++++++++++++++++++++------- wsutil/filesystem.h | 23 ++++-- 28 files changed, 178 insertions(+), 106 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dbebba250..fb03e49b4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1667,6 +1667,12 @@ if(ENABLE_APPLICATION_BUNDLE) # Xcode set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$/Wireshark.app/Contents/PlugIns/wireshark/${PLUGIN_PATH_ID}") endif() + if(CMAKE_CFG_INTDIR STREQUAL ".") + set(_logshark_plugin_dir "${CMAKE_BINARY_DIR}/run/Logshark.app/Contents/PlugIns/logwolf/${PLUGIN_PATH_ID}") + else() + # Xcode + set(_logshark_plugin_dir "${CMAKE_BINARY_DIR}/run/$/Logshark.app/Contents/PlugIns/logwolf/${PLUGIN_PATH_ID}") + endif() elseif(WIN32 AND NOT CMAKE_CFG_INTDIR STREQUAL ".") set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$/${PLUGIN_VERSION_DIR}") else() diff --git a/capinfos.c b/capinfos.c index 8a0a9ad166..0f21f369e4 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1569,7 +1569,7 @@ capinfos_cmdarg_err_cont(const char *msg_format, va_list ap) int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines capinfos_report_routines = { failure_message, failure_message, @@ -1630,12 +1630,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "capinfos: Can't get pathname of directory containing the capinfos program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } init_report_message("capinfos", &capinfos_report_routines); diff --git a/captype.c b/captype.c index 189c52801f..b04326bd43 100644 --- a/captype.c +++ b/captype.c @@ -78,7 +78,7 @@ captype_cmdarg_err_cont(const char *msg_format, va_list ap) int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines captype_report_routines = { failure_message, failure_message, @@ -137,12 +137,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "captype: Can't get pathname of directory containing the captype program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } init_report_message("captype", &captype_report_routines); diff --git a/dftest.c b/dftest.c index 5995bbffeb..8ab3113c6b 100644 --- a/dftest.c +++ b/dftest.c @@ -43,7 +43,7 @@ static void dftest_cmdarg_err_cont(const char *fmt, va_list ap); int main(int argc, char **argv) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines dftest_report_routines = { failure_message, failure_message, @@ -77,11 +77,11 @@ main(int argc, char **argv) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "dftest: Can't get pathname of directory containing the dftest program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } init_report_message("dftest", &dftest_report_routines); diff --git a/editcap.c b/editcap.c index 9dfa26d8c7..56f8acf061 100644 --- a/editcap.c +++ b/editcap.c @@ -1102,7 +1102,7 @@ process_new_idbs(wtap *wth, wtap_dumper *pdh, GArray *idbs_seen, int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines editcap_report_routines = { failure_message, failure_message, @@ -1203,12 +1203,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "editcap: Can't get pathname of directory containing the editcap program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } init_report_message("editcap", &editcap_report_routines); diff --git a/extcap/androiddump.c b/extcap/androiddump.c index 2c72fdae54..78e0f62fbb 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -2539,7 +2539,7 @@ int main(int argc, char *argv[]) { * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/extcap/ciscodump.c b/extcap/ciscodump.c index ccb250b764..1adf45a8b1 100644 --- a/extcap/ciscodump.c +++ b/extcap/ciscodump.c @@ -546,7 +546,7 @@ int main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/extcap/dpauxmon.c b/extcap/dpauxmon.c index 9696b33771..b443103cd6 100644 --- a/extcap/dpauxmon.c +++ b/extcap/dpauxmon.c @@ -486,7 +486,7 @@ close_out: int main(int argc, char *argv[]) { - char* init_progfile_dir_error; + char* configuration_init_error; int option_idx = 0; int result; unsigned int interface_id = 0; @@ -506,11 +506,11 @@ int main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } extcap_base_set_util_info(extcap_conf, argv[0], DPAUXMON_VERSION_MAJOR, DPAUXMON_VERSION_MINOR, DPAUXMON_VERSION_RELEASE, diff --git a/extcap/etwdump.c b/extcap/etwdump.c index 3054a93d58..69b43d487f 100644 --- a/extcap/etwdump.c +++ b/extcap/etwdump.c @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c index 4350eae22f..55aace8f11 100644 --- a/extcap/randpktdump.c +++ b/extcap/randpktdump.c @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/extcap/sdjournal.c b/extcap/sdjournal.c index c1c937c705..5f72b70adb 100644 --- a/extcap/sdjournal.c +++ b/extcap/sdjournal.c @@ -331,7 +331,7 @@ static int list_config(char *interface) int main(int argc, char **argv) { - char* init_progfile_dir_error; + char* configuration_init_error; int result; int option_idx = 0; int start_from_entries = 10; @@ -353,11 +353,11 @@ int main(int argc, char **argv) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } help_url = data_file_url("sdjournal.html"); diff --git a/extcap/sshdump.c b/extcap/sshdump.c index 13cc1f69a2..5e384303cf 100644 --- a/extcap/sshdump.c +++ b/extcap/sshdump.c @@ -376,7 +376,7 @@ int main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/extcap/udpdump.c b/extcap/udpdump.c index 0113c73156..39eb737beb 100644 --- a/extcap/udpdump.c +++ b/extcap/udpdump.c @@ -369,7 +369,7 @@ int main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/extcap/wifidump.c b/extcap/wifidump.c index 1f4fd341a4..212f4d0205 100644 --- a/extcap/wifidump.c +++ b/extcap/wifidump.c @@ -539,7 +539,7 @@ int main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { ws_warning("Can't get pathname of directory containing the extcap program: %s.", err_msg); diff --git a/fuzz/fuzzshark.c b/fuzz/fuzzshark.c index 145bec0874..e6ee5720b8 100644 --- a/fuzz/fuzzshark.c +++ b/fuzz/fuzzshark.c @@ -151,7 +151,7 @@ fuzz_prefs_apply(void) static int fuzz_init(int argc _U_, char **argv) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines fuzzshark_report_routines = { failure_message, @@ -256,10 +256,10 @@ fuzz_init(int argc _U_, char **argv) /* * Attempt to get the pathname of the executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { - fprintf(stderr, "fuzzshark: Can't get pathname of oss-fuzzshark program: %s.\n", init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { + fprintf(stderr, "fuzzshark: Can't get pathname of oss-fuzzshark program: %s.\n", configuration_init_error); + g_free(configuration_init_error); } /* Initialize the version information. */ diff --git a/mergecap.c b/mergecap.c index 58e6de23c7..8bc5be0466 100644 --- a/mergecap.c +++ b/mergecap.c @@ -184,7 +184,7 @@ merge_callback(merge_event event, int num, int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines mergecap_report_routines = { failure_message, failure_message, @@ -241,12 +241,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "mergecap: Can't get pathname of directory containing the mergecap program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } init_report_message("mergecap", &mergecap_report_routines); diff --git a/packaging/debian/libwsutil0.symbols b/packaging/debian/libwsutil0.symbols index 8140620737..788d1f0f06 100644 --- a/packaging/debian/libwsutil0.symbols +++ b/packaging/debian/libwsutil0.symbols @@ -21,6 +21,7 @@ libwsutil.so.0 libwsutil0 #MINVER# codecs_init@Base 3.1.0 codecs_register_plugin@Base 3.1.0 config_file_exists_with_entries@Base 2.9.0 + configuration_init@Base 3.7.0 copy_file_binary_mode@Base 1.12.0~rc1 copy_persconffile_profile@Base 1.12.0~rc1 crc11_307_noreflect_noxor@Base 1.10.0 @@ -115,7 +116,6 @@ libwsutil.so.0 libwsutil0 #MINVER# ieee80211_mhz_to_chan@Base 1.99.7 ieee80211_mhz_to_str@Base 1.99.7 init_process_policies@Base 1.10.0 - init_progfile_dir@Base 1.12.0~rc1 init_report_message@Base 2.3.0 int64_to_str_back@Base 3.5.1 int_to_str_back@Base 3.5.1 diff --git a/randpkt.c b/randpkt.c index 6ca5e10316..e255e13c17 100644 --- a/randpkt.c +++ b/randpkt.c @@ -99,7 +99,7 @@ usage(gboolean is_error) int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines randpkt_report_routines = { failure_message, failure_message, @@ -144,12 +144,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, - "capinfos: Can't get pathname of directory containing the capinfos program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + "capinfos: Can't get pathname of directory containing the capinfos program: %s.\n", + configuration_init_error); + g_free(configuration_init_error); } init_report_message("randpkt", &randpkt_report_routines); diff --git a/rawshark.c b/rawshark.c index cf6ea51efc..d70ea50d86 100644 --- a/rawshark.c +++ b/rawshark.c @@ -479,7 +479,7 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { fprintf(stderr, "rawshark: Can't get pathname of rawshark program: %s.\n", err_msg); diff --git a/reordercap.c b/reordercap.c index b219751795..92c641e738 100644 --- a/reordercap.c +++ b/reordercap.c @@ -159,7 +159,7 @@ reordercap_cmdarg_err_cont(const char *msg_format, va_list ap) int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; static const struct report_message_routines reordercap_message_routines = { failure_message, failure_message, @@ -218,12 +218,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "reordercap: Can't get pathname of directory containing the reordercap program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } init_report_message("reordercap", &reordercap_message_routines); diff --git a/sharkd.c b/sharkd.c index 371933f466..f354e973a3 100644 --- a/sharkd.c +++ b/sharkd.c @@ -98,7 +98,7 @@ print_current_user(void) int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; char *err_msg = NULL; e_prefs *prefs_p; @@ -136,10 +136,10 @@ main(int argc, char *argv[]) /* * Attempt to get the pathname of the executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "sharkd: Can't get pathname of sharkd program: %s.\n", - init_progfile_dir_error); + configuration_init_error); } /* Initialize the version information. */ diff --git a/tfshark.c b/tfshark.c index 245c5ea8cc..aac058e6ad 100644 --- a/tfshark.c +++ b/tfshark.c @@ -267,7 +267,7 @@ print_current_user(void) int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *configuration_init_error; int opt; static const struct ws_option long_options[] = { {"help", ws_no_argument, NULL, 'h'}, @@ -359,12 +359,12 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + configuration_init_error = configuration_init(argv[0], NULL); + if (configuration_init_error != NULL) { fprintf(stderr, "tfshark: Can't get pathname of directory containing the tfshark program: %s.\n", - init_progfile_dir_error); - g_free(init_progfile_dir_error); + configuration_init_error); + g_free(configuration_init_error); } initialize_funnel_ops(); diff --git a/tshark.c b/tshark.c index b3ff9ff9cd..d39ffcd33f 100644 --- a/tshark.c +++ b/tshark.c @@ -845,7 +845,7 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - err_msg = init_progfile_dir(argv[0]); + err_msg = configuration_init(argv[0], NULL); if (err_msg != NULL) { fprintf(stderr, "tshark: Can't get pathname of directory containing the tshark program: %s.\n" diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index cdbc1451a4..c4f6b13865 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -560,7 +560,7 @@ int main(int argc, char *qt_argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - /* init_progfile_dir_error = */ init_progfile_dir(argv[0]); + /* configuration_init_error = */ configuration_init(argv[0], NULL); /* ws_log(NULL, LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir()); */ #ifdef _WIN32 diff --git a/ui/qt_logshark/ls_main.cpp b/ui/qt_logshark/ls_main.cpp index abc141ed87..3350e07863 100644 --- a/ui/qt_logshark/ls_main.cpp +++ b/ui/qt_logshark/ls_main.cpp @@ -560,7 +560,7 @@ int main(int argc, char *qt_argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - /* init_progfile_dir_error = */ init_progfile_dir(argv[0]); + /* configuration_init_error = */ configuration_init(argv[0], "Logwolf"); /* ws_log(NULL, LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir()); */ #ifdef _WIN32 @@ -613,7 +613,7 @@ int main(int argc, char *qt_argv[]) #endif /* _WIN32 */ /* Get the compile-time version information string */ - ws_init_version_info("Logshark", gather_wireshark_qt_compiled_info, + ws_init_version_info("Logwolf", gather_wireshark_qt_compiled_info, gather_wireshark_runtime_info); /* Create the user profiles directory */ diff --git a/wsutil/file_util.c b/wsutil/file_util.c index a8a2a6bd2a..a7bbaa081e 100644 --- a/wsutil/file_util.c +++ b/wsutil/file_util.c @@ -456,7 +456,7 @@ init_dll_load_paths() if (program_path && system_path && npcap_path) return TRUE; - /* XXX - Duplicate code in filesystem.c:init_progfile_dir */ + /* XXX - Duplicate code in filesystem.c:configuration_init */ if (GetModuleFileName(NULL, path_w, MAX_PATH) == 0 || GetLastError() == ERROR_INSUFFICIENT_BUFFER) { return FALSE; } diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index eb384a8594..25d6f1e499 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -11,6 +11,8 @@ #include "config.h" #include "filesystem.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSUTIL + #include #include #include @@ -49,7 +51,19 @@ #define PLUGINS_DIR_NAME "plugins" #define PROFILES_INFO_NAME "profile_files.txt" -#define ENV_CONFIG_PATH_VAR "WIRESHARK_CONFIG_DIR" +/* + * Application configuration namespace. Used to construct configuration + * paths and environment variables. + */ +enum configuration_namespace_e { + CONFIGURATION_NAMESPACE_UNINITIALIZED, + CONFIGURATION_NAMESPACE_WIRESHARK, + CONFIGURATION_NAMESPACE_LOGWOLF +}; +enum configuration_namespace_e configuration_namespace = CONFIGURATION_NAMESPACE_UNINITIALIZED; + +#define CONFIGURATION_NAMESPACE_LOWER (configuration_namespace == CONFIGURATION_NAMESPACE_WIRESHARK ? "wireshark" : "logwolf") +#define CONFIGURATION_ENVIRONMENT_VARIABLE(suffix) (configuration_namespace == CONFIGURATION_NAMESPACE_WIRESHARK ? "WIRESHARK_" suffix : "LOGWOLF_" suffix) char *persconffile_dir = NULL; char *datafile_dir = NULL; @@ -258,6 +272,35 @@ static char *appbundle_dir; */ static gboolean running_in_build_directory_flag = FALSE; +/* + * Set our configuration namespace. This will be used for top-level + * configuration directory names and environment variable prefixes. + */ +static void +set_configuration_namespace(const char *namespace_name) +{ + + if (namespace_name != CONFIGURATION_NAMESPACE_UNINITIALIZED) { + return; + } + + if (!namespace_name || g_ascii_strcasecmp(namespace_name, "wireshark") == 0) + { + configuration_namespace = CONFIGURATION_NAMESPACE_WIRESHARK; + } + else if (namespace_name && g_ascii_strcasecmp(namespace_name, "logwolf") == 0) + { + configuration_namespace = CONFIGURATION_NAMESPACE_LOGWOLF; + } + else + { + ws_error("Unknown configuration namespace %s", namespace_name); + } + + ws_debug("Using configuration namespace %s.", + configuration_namespace == CONFIGURATION_NAMESPACE_WIRESHARK ? "Wireshark" : "Logwolf"); +} + #ifndef _WIN32 /* * Get the pathname of the executable using various platform- @@ -467,14 +510,17 @@ get_executable_path(void) * g_mallocated string containing an error on failure. */ char * -init_progfile_dir( +configuration_init( #ifdef _WIN32 - const char* arg0 _U_ + const char* arg0 _U_, #else - const char* arg0 + const char* arg0, #endif + const char *namespace_name ) { + set_configuration_namespace(namespace_name); + #ifdef _WIN32 TCHAR prog_pathname_w[_MAX_PATH+2]; char *prog_pathname; @@ -547,7 +593,7 @@ init_progfile_dir( char *dir_end; /* - * Check whether WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set in the + * Check whether XXX_RUN_FROM_BUILD_DIRECTORY is set in the * environment; if so, set running_in_build_directory_flag if we * weren't started with special privileges. (If we were started * with special privileges, it's not safe to allow the user to point @@ -555,9 +601,11 @@ init_progfile_dir( * set, causes us to look for plugins and the like in the build * directory.) */ - if (g_getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL - && !started_with_special_privs()) + const char *run_from_envar = CONFIGURATION_ENVIRONMENT_VARIABLE("RUN_FROM_BUILD_DIRECTORY"); + if (g_getenv(run_from_envar) != NULL + && !started_with_special_privs()) { running_in_build_directory_flag = TRUE; + } execname = get_executable_path(); if (execname == NULL) { @@ -841,13 +889,14 @@ get_datafile_dir(void) } #else - if (g_getenv("WIRESHARK_DATA_DIR") && !started_with_special_privs()) { + const char *data_dir_envar = CONFIGURATION_ENVIRONMENT_VARIABLE("DATA_DIR"); + if (g_getenv(data_dir_envar) && !started_with_special_privs()) { /* * The user specified a different directory for data files * and we aren't running with special privileges. * XXX - We might be able to dispense with the priv check */ - datafile_dir = g_strdup(g_getenv("WIRESHARK_DATA_DIR")); + datafile_dir = g_strdup(g_getenv(data_dir_envar)); } #ifdef __APPLE__ /* @@ -860,8 +909,8 @@ get_datafile_dir(void) * it; we don't need to call started_with_special_privs().) */ else if (appbundle_dir != NULL) { - datafile_dir = ws_strdup_printf("%s/Contents/Resources/share/wireshark", - appbundle_dir); + datafile_dir = ws_strdup_printf("%s/Contents/Resources/share/%s", + appbundle_dir, CONFIGURATION_NAMESPACE_LOWER); } #endif else if (running_in_build_directory_flag && progfile_dir != NULL) { @@ -881,7 +930,6 @@ get_datafile_dir(void) } else { datafile_dir = g_strdup(DATA_DIR); } - #endif return datafile_dir; } @@ -959,12 +1007,13 @@ init_plugin_dir(void) */ plugin_dir = g_build_filename(get_progfile_dir(), "plugins", (gchar *)NULL); } else { - if (g_getenv("WIRESHARK_PLUGIN_DIR") && !started_with_special_privs()) { + const char *plugin_dir_envar = CONFIGURATION_ENVIRONMENT_VARIABLE("PLUGIN_DIR"); + if (g_getenv(plugin_dir_envar) && !started_with_special_privs()) { /* * The user specified a different directory for plugins * and we aren't running with special privileges. */ - plugin_dir = g_strdup(g_getenv("WIRESHARK_PLUGIN_DIR")); + plugin_dir = g_strdup(g_getenv(plugin_dir_envar)); } #ifdef __APPLE__ /* @@ -977,7 +1026,8 @@ init_plugin_dir(void) * it; we don't need to call started_with_special_privs().) */ else if (appbundle_dir != NULL) { - plugin_dir = g_build_filename(appbundle_dir, "Contents/PlugIns/wireshark", (gchar *)NULL); + plugin_dir = g_build_filename(appbundle_dir, "Contents/PlugIns", + CONFIGURATION_NAMESPACE_LOWER, (gchar *)NULL); } #endif else { @@ -995,7 +1045,8 @@ init_plugin_pers_dir(void) #ifdef _WIN32 plugin_pers_dir = get_persconffile_path(PLUGINS_DIR_NAME, FALSE); #else - plugin_pers_dir = g_build_filename(g_get_home_dir(), ".local/lib/wireshark/" PLUGINS_DIR_NAME, (gchar *)NULL); + plugin_pers_dir = g_build_filename(g_get_home_dir(), ".local/lib", + CONFIGURATION_NAMESPACE_LOWER, PLUGINS_DIR_NAME, (gchar *)NULL); #endif #endif /* defined(HAVE_PLUGINS) || defined(HAVE_LUA) */ } @@ -1061,12 +1112,13 @@ get_plugins_pers_dir_with_version(void) static char *extcap_dir = NULL; static void init_extcap_dir(void) { - if (g_getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) { + const char *extcap_dir_envar = CONFIGURATION_ENVIRONMENT_VARIABLE("EXTCAP_DIR"); + if (g_getenv(extcap_dir_envar) && !started_with_special_privs()) { /* * The user specified a different directory for extcap hooks * and we aren't running with special privileges. */ - extcap_dir = g_strdup(g_getenv("WIRESHARK_EXTCAP_DIR")); + extcap_dir = g_strdup(g_getenv(extcap_dir_envar)); } #ifdef _WIN32 else { @@ -1255,7 +1307,8 @@ get_persconffile_dir_no_profile(void) /* * See if the user has selected an alternate environment. */ - env = g_getenv(ENV_CONFIG_PATH_VAR); + const char *config_dir_envar = CONFIGURATION_ENVIRONMENT_VARIABLE("CONFIG_DIR"); + env = g_getenv(config_dir_envar); #ifdef _WIN32 if (env == NULL) { /* for backward compatibility */ @@ -1277,11 +1330,12 @@ get_persconffile_dir_no_profile(void) * is an inaccessible network drive. */ env = g_getenv("APPDATA"); + const char *persconf_namespace = configuration_namespace == CONFIGURATION_NAMESPACE_WIRESHARK ? "Wireshark" : "Logwolf"; if (env != NULL) { /* - * Concatenate %APPDATA% with "\Wireshark". + * Concatenate %APPDATA% with "\Wireshark" or "\Logwolf". */ - persconffile_dir = g_build_filename(env, "Wireshark", NULL); + persconffile_dir = g_build_filename(env, persconf_namespace, NULL); return persconffile_dir; } @@ -1290,14 +1344,14 @@ get_persconffile_dir_no_profile(void) */ env = g_getenv("USERPROFILE"); if (env != NULL) { - persconffile_dir = g_build_filename(env, "Application Data", "Wireshark", NULL); + persconffile_dir = g_build_filename(env, "Application Data", persconf_namespace, NULL); return persconffile_dir; } /* * Give up and use "C:". */ - persconffile_dir = g_build_filename("C:", "Wireshark", NULL); + persconffile_dir = g_build_filename("C:", persconf_namespace, NULL); return persconffile_dir; #else char *xdg_path, *path; @@ -1307,7 +1361,8 @@ get_persconffile_dir_no_profile(void) /* * Check if XDG_CONFIG_HOME/wireshark exists and is a directory. */ - xdg_path = g_build_filename(g_get_user_config_dir(), "wireshark", NULL); + xdg_path = g_build_filename(g_get_user_config_dir(), + CONFIGURATION_NAMESPACE_LOWER, NULL); if (g_file_test(xdg_path, G_FILE_TEST_IS_DIR)) { persconffile_dir = xdg_path; return persconffile_dir; @@ -1338,7 +1393,9 @@ get_persconffile_dir_no_profile(void) homedir = "/tmp"; } } - path = g_build_filename(homedir, ".wireshark", NULL); + path = g_build_filename(homedir, + configuration_namespace == CONFIGURATION_NAMESPACE_WIRESHARK ? ".wireshark" : ".logwolf", + NULL); if (g_file_test(path, G_FILE_TEST_IS_DIR)) { g_free(xdg_path); persconffile_dir = path; diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h index b3acd76807..8d276f3d99 100644 --- a/wsutil/filesystem.h +++ b/wsutil/filesystem.h @@ -22,13 +22,22 @@ extern "C" { */ #define DEFAULT_PROFILE "Default" - -/* +/** + * Initialize our configuration environment. + * * Get the pathname of the directory from which the executable came, - * and save it for future use. Returns NULL on success, and a - * g_mallocated string containing an error on failure. + * and save it for future use. + * + * Set our configuration namespace, which determines the top-level + * configuration directory name and environment variable prefixes. + * Default is "Wireshark". + * + * @param arg0 Executable name hint. Should be argv[0]. + * @param namespace_name The namespace to use. "Wireshark" or NULL uses + * the Wireshark namespace. "Logwolf" uses the Logwolf namespace. + * @return NULL on success, and a g_mallocated string containing an error on failure. */ -WS_DLL_PUBLIC char *init_progfile_dir(const char *arg0); +WS_DLL_PUBLIC char *configuration_init(const char *arg0, const char *namespace_name); /* * Get the directory in which the program resides. @@ -37,7 +46,7 @@ WS_DLL_PUBLIC const char *get_progfile_dir(void); /* * Get the directory in which plugins are stored; this must not be called - * before init_progfile_dir() is called, as they might be stored in a + * before configuration_init() is called, as they might be stored in a * subdirectory of the program file directory. */ WS_DLL_PUBLIC const char *get_plugins_dir(void); @@ -59,7 +68,7 @@ WS_DLL_PUBLIC const char *get_plugins_pers_dir_with_version(void); /* * Get the directory in which extcap hooks are stored; this must not be called - * before init_progfile_dir() is called, as they might be stored in a + * before configuration_init() is called, as they might be stored in a * subdirectory of the program file directory. */ WS_DLL_PUBLIC const char *get_extcap_dir(void);