From 8745c5e5dede5a0247e466af1f19e3da2d2eaf2b Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 6 Sep 2017 13:17:57 +0200 Subject: [PATCH] Add Windows manifest to dbus-update-activation-environment.exe This explicitly sets the execution level to 'asInvoker', preventing Windows' UAC heuristics from deciding that because its name mentions "update", it probably needs to escalate privileges. [smcv: flatten CMake and Autotools parts into one commit, add more explanation to commit message] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=102558 --- cmake/modules/Win32.Manifest.in | 10 ++++++++++ cmake/modules/Win32Macros.cmake | 26 +++++++++++++++++++++++++- cmake/tools/CMakeLists.txt | 3 +++ tools/Makefile.am | 18 +++++++++++++++++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/Win32.Manifest.in diff --git a/cmake/modules/Win32.Manifest.in b/cmake/modules/Win32.Manifest.in new file mode 100644 index 00000000..c416d49f --- /dev/null +++ b/cmake/modules/Win32.Manifest.in @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/cmake/modules/Win32Macros.cmake b/cmake/modules/Win32Macros.cmake index 4385cc97..0846c748 100644 --- a/cmake/modules/Win32Macros.cmake +++ b/cmake/modules/Win32Macros.cmake @@ -1,7 +1,7 @@ # # win32 macros # -# Copyright (c) 2006-2007, Ralf Habacker +# Copyright (c) 2006-2017, Ralf Habacker # # Redistribution and use is allowed according to the terms of the BSD license. # @@ -41,4 +41,28 @@ if (WIN32) endif (CMAKE_BUILD_TOOL STREQUAL "nmake") endif (MINGW) ENDMACRO (addExplorerWrapper) + + # + # Set execution level for a target to 'asInvoker' + # + # Syntax: + # set_execution_level_as_invoker(_source) + # + # @param _source name of source list for a given target + # + # Example: + # set (SOURCE test.c) + # set_execution_level_as_invoker(SOURCE) + # add_executable(atarget, ${SOURCE}) + # + MACRO (set_execution_level_as_invoker _source) + # create rc file + # 1 is the resource ID, ID_MANIFEST + # 24 is the resource type, RT_MANIFEST + # constants are used because of a bug in windres + # see https://stackoverflow.com/questions/33000158/embed-manifest-file-to-require-administrator-execution-level-with-mingw32 + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_source}.rc "1 24 \"${CMAKE_SOURCE_DIR}/modules/Win32.Manifest.in\"\n") + # add to source list + list(APPEND ${_source} ${CMAKE_CURRENT_BINARY_DIR}/${_source}.rc) + ENDMACRO (set_execution_level_as_invoker) endif(WIN32) diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt index 8b3de0c9..6c721005 100644 --- a/cmake/tools/CMakeLists.txt +++ b/cmake/tools/CMakeLists.txt @@ -62,6 +62,9 @@ add_executable(dbus-test-tool ${dbus_test_tool_SOURCES}) target_link_libraries(dbus-test-tool ${DBUS_LIBRARIES}) install(TARGETS dbus-test-tool ${INSTALL_TARGETS_DEFAULT_ARGS}) +if(WIN32) + set_execution_level_as_invoker(dbus_update_activation_environment_SOURCES) +endif() add_executable(dbus-update-activation-environment ${dbus_update_activation_environment_SOURCES}) target_link_libraries(dbus-update-activation-environment ${DBUS_LIBRARIES}) install(TARGETS dbus-update-activation-environment ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/tools/Makefile.am b/tools/Makefile.am index 19aaf363..bb138592 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -114,9 +114,25 @@ dbus_update_activation_environment_SOURCES = \ $(NULL) dbus_update_activation_environment_LDADD = $(top_builddir)/dbus/libdbus-1.la +if DBUS_WIN +SUFFIXES = .rc + +.rc.o: + $(WINDRES) $< -o $@ + +duae-manifest.rc: $(top_srcdir)/cmake/modules/Win32.Manifest.in + echo -e "1 24 \"$<\"" > $@ + +duae_res = duae-manifest.o +duae_res_ldflag = -Wl,$(duae_res) +EXTRA_dbus_update_activation_environment_DEPENDENCIES = $(duae_res) + +endif + EXTRA_DIST = run-with-tmp-session-bus.sh strtoll.c strtoull.c CLEANFILES = \ - run-with-tmp-session-bus.conf + run-with-tmp-session-bus.conf \ + duae-manifest.rc # create the /var/lib/dbus directory for dbus-uuidgen install-data-local: -- 2.14.1