Add Windows manifest to dbus-update-activation-environment.exe
authorRalf Habacker <ralf.habacker@freenet.de>
Tue, 26 Sep 2017 10:06:10 +0000 (12:06 +0200)
committerRalf Habacker <ralf.habacker@freenet.de>
Wed, 27 Sep 2017 20:05:13 +0000 (22:05 +0200)
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.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=102558
Reviewed-by: Simon McVittie <smcv@collabora.com>
cmake/tools/CMakeLists.txt
tools/Makefile.am
tools/Win32.Manifest [new file with mode: 0644]

index 8b3de0c..5613269 100644 (file)
@@ -62,6 +62,15 @@ 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)
+    # avoid dbus-update-activation-environment triggering UAC
+    # 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}/disable-uac.rc "1 24 \"${CMAKE_SOURCE_DIR}/../tools/Win32.Manifest\"\n")
+    list(APPEND dbus_update_activation_environment_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/disable-uac.rc)
+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})
index 19aaf36..96ce03f 100644 (file)
@@ -114,9 +114,22 @@ dbus_update_activation_environment_SOURCES = \
        $(NULL)
 dbus_update_activation_environment_LDADD = $(top_builddir)/dbus/libdbus-1.la
 
-EXTRA_DIST = run-with-tmp-session-bus.sh strtoll.c strtoull.c
+if DBUS_WIN
+SUFFIXES = .rc
+
+.rc.o:
+       $(WINDRES) $< -o $@
+
+nodist_dbus_update_activation_environment_SOURCES = disable-uac.rc
+
+disable-uac.rc: Win32.Manifest
+       echo -e "1 24 \"$<\"" > $@
+endif
+
+EXTRA_DIST = run-with-tmp-session-bus.sh strtoll.c strtoull.c Win32.Manifest
 CLEANFILES =                           \
-       run-with-tmp-session-bus.conf
+       run-with-tmp-session-bus.conf \
+       $(nodist_dbus_update_activation_environment_SOURCES)
 
 # create the /var/lib/dbus directory for dbus-uuidgen
 install-data-local:
diff --git a/tools/Win32.Manifest b/tools/Win32.Manifest
new file mode 100644 (file)
index 0000000..b926d06
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+  <security>
+   <requestedPrivileges>
+    <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
+   </requestedPrivileges>
+  </security>
+ </trustInfo>
+</assembly>