forked from osmocom/wireshark
Enable rpathification and working relocation on Linux (take 2)
Dumpcap depends on wsutil.so. The path to the shared library is encoded in the RPATH (or RUNPATH) property of ELF binaries. This is currently an absolute path on most Unixy systems. Dumpcap could not be made to work with a relative RPATH because it uses elevated privileges and some loaders will ignore relative RPATHs and non-standard paths under those circumstances, because of (justified) security concerns. To enable relocation of the program we link dumpcap statically with wsutil instead. This provides a fully working relocatable installation on Linux and other platforms that support relative RPATHs.
This commit is contained in:
parent
877498ad0b
commit
8dfe8737c5
|
@ -270,26 +270,25 @@ if(NOT (WIN32 OR APPLE OR USE_STATIC))
|
|||
# Some systems support $ORIGIN in RPATH to enable relocatable
|
||||
# binaries. In other cases, only absolute paths can be used.
|
||||
# https://www.lekensteyn.nl/rpath.html
|
||||
#
|
||||
# Also note that some systems (notably those using GNU libc)
|
||||
# silently ignore $ORIGIN in RPATH for binaries that are
|
||||
# setuid root or use privileged capabilities.
|
||||
#
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
|
||||
set(_enable_rpath_origin TRUE)
|
||||
if(BUILD_dumpcap AND ENABLE_PCAP)
|
||||
# dumpcap will most likely be installed with
|
||||
# capabilities or setuid. Relative RPATHs that
|
||||
# resolve to non-standard library directories
|
||||
# are ignored for such binaries and since we
|
||||
# cannot achieve relocatable builds, just
|
||||
# disable it by default.
|
||||
else()
|
||||
set(_enable_rpath_origin FALSE)
|
||||
endif()
|
||||
|
||||
# Provide a knob to optionally force absolute rpaths,
|
||||
# to support old/buggy systems and as a user preference
|
||||
# for hardening.
|
||||
# XXX Should this be a CMake option?
|
||||
set(ENABLE_RPATH_ORIGIN ${_enable_rpath_origin} CACHE BOOL
|
||||
"Use $ORIGIN with INSTALL_RPATH")
|
||||
mark_as_advanced(ENABLE_RPATH_ORIGIN)
|
||||
else()
|
||||
set(ENABLE_RPATH_ORIGIN FALSE)
|
||||
endif()
|
||||
|
||||
if(ENABLE_RPATH_ORIGIN)
|
||||
set(LIBRARY_INSTALL_RPATH "$ORIGIN")
|
||||
set(EXECUTABLE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
||||
|
@ -3120,28 +3119,47 @@ endif()
|
|||
if(BUILD_dumpcap AND PCAP_FOUND)
|
||||
set(dumpcap_LIBS
|
||||
writecap
|
||||
wsutil
|
||||
caputils
|
||||
iface_monitor
|
||||
wsutil_static
|
||||
pcap::pcap
|
||||
${CAP_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
${NL_LIBRARIES}
|
||||
${APPLE_CORE_FOUNDATION_LIBRARY}
|
||||
${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
|
||||
${WIN_WS2_32_LIBRARY}
|
||||
)
|
||||
if(UNIX)
|
||||
list(APPEND CAPUTILS_SRC
|
||||
capture/capture-pcap-util-unix.c)
|
||||
endif()
|
||||
if(WIN32)
|
||||
list(APPEND CAPUTILS_SRC
|
||||
capture/capture_win_ifnames.c
|
||||
capture/capture-wpcap.c
|
||||
)
|
||||
endif()
|
||||
list(APPEND CAPUTILS_SRC
|
||||
capture/capture-pcap-util.c
|
||||
)
|
||||
if (AIRPCAP_FOUND)
|
||||
list(APPEND CAPUTILS_SRC capture/airpcap_loader.c)
|
||||
endif()
|
||||
set(dumpcap_FILES
|
||||
$<TARGET_OBJECTS:capture_opts>
|
||||
$<TARGET_OBJECTS:cli_main>
|
||||
capture_opts.c
|
||||
cli_main.c
|
||||
dumpcap.c
|
||||
ringbuffer.c
|
||||
sync_pipe_write.c
|
||||
capture/iface_monitor.c
|
||||
capture/ws80211_utils.c
|
||||
${CAPUTILS_SRC}
|
||||
)
|
||||
set_executable_resources(dumpcap "Dumpcap" UNIQUE_RC)
|
||||
add_executable(dumpcap ${dumpcap_FILES})
|
||||
set_extra_executable_properties(dumpcap "Executables")
|
||||
target_link_libraries(dumpcap ${dumpcap_LIBS})
|
||||
target_include_directories(dumpcap SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS})
|
||||
target_include_directories(dumpcap SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS} ${NL_INCLUDE_DIRS})
|
||||
target_compile_definitions(dumpcap PRIVATE ENABLE_STATIC)
|
||||
executable_link_mingw_unicode(dumpcap)
|
||||
install(TARGETS dumpcap
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
|
|
|
@ -36,6 +36,9 @@ Previously it was ``$XDG_CONFIG_HOME/wireshark/extcap``.
|
|||
The installation target no longer installs development headers by default.
|
||||
That must be done explicitly using ``cmake --install <builddir> --component Development``.
|
||||
|
||||
The Wireshark installation is relocatable on Linux (and other ELF platforms
|
||||
with support for relative RPATHs).
|
||||
|
||||
Many other improvements have been made.
|
||||
See the “New and Updated Features” section below for more details.
|
||||
|
||||
|
|
|
@ -406,6 +406,45 @@ install(FILES ${WSUTIL_PUBLIC_HEADERS}
|
|||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
add_library(wsutil_static STATIC
|
||||
${WSUTIL_FILES}
|
||||
)
|
||||
|
||||
target_compile_definitions(wsutil_static PRIVATE
|
||||
ENABLE_STATIC
|
||||
BUILD_WSUTIL
|
||||
)
|
||||
|
||||
target_link_libraries(wsutil_static
|
||||
PUBLIC
|
||||
${GLIB2_LIBRARIES}
|
||||
PRIVATE
|
||||
${GMODULE2_LIBRARIES}
|
||||
${APPLE_CORE_FOUNDATION_LIBRARY}
|
||||
${CMAKE_DL_LIBS}
|
||||
${GCRYPT_LIBRARIES}
|
||||
${GNUTLS_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
${PCRE2_LIBRARIES}
|
||||
${WIN_IPHLPAPI_LIBRARY}
|
||||
${WIN_WS2_32_LIBRARY}
|
||||
)
|
||||
|
||||
target_include_directories(wsutil_static SYSTEM
|
||||
PUBLIC
|
||||
${GLIB2_INCLUDE_DIRS}
|
||||
${GCRYPT_INCLUDE_DIRS}
|
||||
${GNUTLS_INCLUDE_DIRS}
|
||||
PRIVATE
|
||||
${GMODULE2_INCLUDE_DIRS}
|
||||
${ZLIB_INCLUDE_DIRS}
|
||||
${PCRE2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
if(NOT VCSVERSION_OVERRIDE)
|
||||
add_dependencies(wsutil_static vcs_version)
|
||||
endif()
|
||||
|
||||
add_executable(wmem_test EXCLUDE_FROM_ALL wmem/wmem_test.c ${WMEM_FILES})
|
||||
|
||||
target_link_libraries(wmem_test wsutil)
|
||||
|
|
Loading…
Reference in New Issue