Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e229d80
Bump third-party/moonlight-common-c from `07beb0f` to `d3cb813` (#968)
dependabot[bot] Feb 21, 2023
9e0c72e
github: move feature requests to moonlight board (#970)
ReenigneArcher Feb 24, 2023
845749d
windows: input: activate US keyboard layout for scancode mapping (#975)
psyke83 Feb 25, 2023
4ac8c5c
docs: improve examples (#1000)
ReenigneArcher Mar 6, 2023
a1e6f44
Bump babel from 2.11.0 to 2.12.1 (#991)
dependabot[bot] Mar 7, 2023
3188543
docs: add doxygen (#1004)
ReenigneArcher Mar 8, 2023
f238cf5
Add setting for suppressing input from mouse, keyboard, or gamepads (…
briankendall Mar 8, 2023
7d01b50
feat: implemented unicode input mode (#966)
ABeltramo Mar 8, 2023
8227e8f
Add XTest input fallback (#997)
Doridian Mar 8, 2023
91f5d39
Bump @fortawesome/fontawesome-free from 6.2.1 to 6.3.0 (#900)
dependabot[bot] Mar 8, 2023
c89fd83
Bump third-party/ViGEmClient from `9e842ba` to `726404e` (#913)
dependabot[bot] Mar 8, 2023
8f1465d
Docs improve source code documentation (#1016)
ReenigneArcher Mar 8, 2023
c3f3e16
Fix linux clang build errors (#879)
HomerSp Mar 8, 2023
889b93d
input: invert default config settings (#1017)
ReenigneArcher Mar 9, 2023
c29c917
Versioning improvements (#768)
TheElixZammuto Mar 9, 2023
bf4ed89
Skip irrelevant submodules when building on Arch (#817)
Tea23 Mar 10, 2023
dfb5293
archlinux: disable downlaod timeout (#1024)
ReenigneArcher Mar 10, 2023
6d54356
logging: change client verified messages to debug (#1020)
ReenigneArcher Mar 10, 2023
80aa61b
Support compiling for earlier releases of macOS (#960)
briankendall Mar 10, 2023
a72b77d
Bump third-party/moonlight-common-c from `d3cb813` to `02f12e4` (#1003)
dependabot[bot] Mar 10, 2023
21a728c
Bump ffmpeg (#1026)
LizardByte-bot Mar 10, 2023
fbe5e24
Fix startup when /dev/dri doesn't exist (#1027)
Doridian Mar 11, 2023
27c9c0e
docs: add wayland resolution example (#1028)
ReenigneArcher Mar 11, 2023
237f215
Bump third-party/miniupnp from `014c9df` to `e439318` (#944)
dependabot[bot] Mar 11, 2023
014d693
add tray icon (#1035)
ReenigneArcher Mar 15, 2023
afc6966
config: only save non default values (#1023)
ReenigneArcher Mar 15, 2023
d85b234
docs: add favicon (#1044)
ReenigneArcher Mar 16, 2023
7e9b184
ui: fix apply settings (#1045)
ReenigneArcher Mar 16, 2023
e20ca7a
tray-icon: execute as user (#1046)
ReenigneArcher Mar 17, 2023
a192c50
Use xdg-desktop-autostart.target for systemd service. (#901)
HomerSp Mar 20, 2023
744b54f
ci: add qodana (#1052)
ReenigneArcher Mar 21, 2023
c820f0a
qodana: fix notification conditions (#1053)
ReenigneArcher Mar 21, 2023
7999165
Bump furo from 2022.12.7 to 2023.3.23 (#1065)
dependabot[bot] Mar 24, 2023
5cdc0ac
qodana: use workflow dispatch (#1069)
ReenigneArcher Mar 24, 2023
8162d5f
Change text input to select (#1067)
KuleRucket Mar 24, 2023
a0d7250
docs: update config defaults (#1070)
ReenigneArcher Mar 24, 2023
455155a
Add missing <string> include (#1057)
luk1337 Mar 24, 2023
c6548f4
Provide ability to force a capture method via configuration. (#1063)
KuleRucket Mar 26, 2023
a487fb3
Fix compiler warnings due to deprecated elements in C++17 (#1077)
KuleRucket Mar 26, 2023
9b0e056
Nightly Notification Bug Fixes (#1073)
Nonary Mar 26, 2023
bf24d0e
Flatpak: update to org.freedesktop.Platform 22.08 (#936)
psyke83 Mar 27, 2023
6f02274
docs: suppress epub mimetype warnings (#1081)
ReenigneArcher Mar 27, 2023
6a914f7
Execute do/undo commands non-elevated (#1022)
pgrunzjr Mar 27, 2023
c2fba6f
Add Support for Safely Elevating Administrator Privileges (#1036)
Nonary Mar 27, 2023
8c86baf
Add support for global prep commands (#977)
pgrunzjr Mar 27, 2023
e18e4f4
Bump furo from 2023.3.23 to 2023.3.27 (#1082)
dependabot[bot] Mar 27, 2023
1dfe9ea
Bump third-party/moonlight-common-c from `02f12e4` to `c9426a6` (#1038)
dependabot[bot] Mar 27, 2023
3791edc
Bump third-party/nanors from `395e5ad` to `e9e242e` (#1039)
dependabot[bot] Mar 27, 2023
e1fddcc
versioning: fix dirty commit notifications (#1084)
ReenigneArcher Mar 27, 2023
014ca7e
commands: fix prep commands when empty (#1083)
ReenigneArcher Mar 27, 2023
be74b74
Properly handle libcurl flags in CMakeLists.txt on Windows (#1079)
ns6089 Mar 27, 2023
79cf382
Add missing setup for default global prep command exclusion dropdown …
pgrunzjr Mar 28, 2023
21eb4eb
clang: adjust formatting rules (#1015)
ReenigneArcher Mar 28, 2023
648df66
Fix X11 fallback during init (#1087)
luk1337 Mar 28, 2023
c222e34
Bump third-party/miniupnp from `014c9df` to `e439318` (#1093)
dependabot[bot] Mar 28, 2023
4b2f5be
Bump @fortawesome/fontawesome-free from 6.3.0 to 6.4.0 (#1088)
dependabot[bot] Mar 28, 2023
44f1984
Bump third-party/moonlight-common-c from `d3cb813` to `c9426a6` (#1089)
dependabot[bot] Mar 28, 2023
1ab1b79
Don't skip disconnected X11 outputs (#1071)
luk1337 Mar 28, 2023
57a722a
Continue in the face of failure (#1094)
KuleRucket Mar 28, 2023
7067432
Fix system tray Open Sunshine (#1095)
KuleRucket Mar 28, 2023
f169c6d
v0.19.0 release prep (#1097)
ReenigneArcher Mar 29, 2023
972f726
installer: auto install vigembus (#1100)
ReenigneArcher Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Support for Safely Elevating Administrator Privileges (#1036)
  • Loading branch information
Nonary authored Mar 27, 2023
commit c2fba6f65132355fb6e4e9bcf7e12f29db1c9dbd
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ if(WIN32) # see options at: https://cmake.org/cmake/help/latest/cpack_gen/nsis.h
install(TARGETS dxgi-info RUNTIME DESTINATION "tools" COMPONENT dxgi)
install(TARGETS audio-info RUNTIME DESTINATION "tools" COMPONENT audio)
install(TARGETS sunshinesvc RUNTIME DESTINATION "tools" COMPONENT sunshinesvc)
install(TARGETS elevator RUNTIME DESTINATION "tools" COMPONENT elevator)

# Mandatory tools
install(TARGETS ddprobe RUNTIME DESTINATION "tools" COMPONENT application)
Expand Down Expand Up @@ -801,6 +802,12 @@ if(WIN32) # see options at: https://cmake.org/cmake/help/latest/cpack_gen/nsis.h
set(CPACK_COMPONENT_AUDIO_DESCRIPTION "CLI tool providing information about sound devices.")
set(CPACK_COMPONENT_AUDIO_GROUP "tools")

# elevation tool
set(CPACK_COMPONENT_ELEVATION_DISPLAY_NAME "elevator")
set(CPACK_COMPONENT_ELEVATION_DESCRIPTION "CLI tool that assists with elevating \
commands when permissions have been denied.")
set(CPACK_COMPONENT_ELEVATION_GROUP "tools")

# display tool
set(CPACK_COMPONENT_DXGI_DISPLAY_NAME "dxgi-info")
set(CPACK_COMPONENT_DXGI_DESCRIPTION "CLI tool providing information about graphics cards and displays.")
Expand Down
40 changes: 35 additions & 5 deletions src/platform/windows/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@

// prevent clang format from "optimizing" the header include order
// clang-format off
#include <winsock2.h>
#include <dwmapi.h>
#include <iphlpapi.h>
#include <iterator>
#include <timeapi.h>
#include <userenv.h>
#include <winsock2.h>
#include <windows.h>
#include <winuser.h>
#include <ws2tcpip.h>
#include <userenv.h>
#include <dwmapi.h>
#include <timeapi.h>
#include <wlanapi.h>
#include <ws2tcpip.h>
// clang-format on

#include "src/main.h"
#include "src/platform/common.h"
#include "src/utility.h"
#include <iterator>

// UDP_SEND_MSG_SIZE was added in the Windows 10 20H1 SDK
#ifndef UDP_SEND_MSG_SIZE
Expand Down Expand Up @@ -464,6 +466,34 @@ bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &work
(LPSTARTUPINFOW)&startup_info,
&process_info);

if(!ret) {
auto error = GetLastError();

if(error == 740) {
BOOST_LOG(info) << "Could not execute previous command because it required elevation. Running the command again with elevation, for security reasons this will prompt user interaction."sv;
startup_info.StartupInfo.wShowWindow = SW_HIDE;
startup_info.StartupInfo.dwFlags = startup_info.StartupInfo.dwFlags | STARTF_USESHOWWINDOW;
std::wstring elevated_command = L"tools\\elevator.exe ";
elevated_command += wcmd;

// For security reasons, Windows enforces that an application can have only one "interactive thread" responsible for processing user input and managing the user interface (UI).
// Since UAC prompts are interactive, we cannot have a UAC prompt while Sunshine is already running because it would block the thread.
// To work around this issue, we will launch a separate process that will elevate the command, which will prompt the user to confirm the elevation.
// This is our intended behavior: to require interaction before elevating the command.
ret = CreateProcessAsUserW(shell_token,
nullptr,
(LPWSTR)elevated_command.c_str(),
nullptr,
nullptr,
!!(startup_info.StartupInfo.dwFlags & STARTF_USESTDHANDLES),
EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE | CREATE_BREAKAWAY_FROM_JOB,
env_block.data(),
start_dir.empty() ? nullptr : start_dir.c_str(),
(LPSTARTUPINFOW)&startup_info,
&process_info);
}
}

// End impersonation of the logged on user. If this fails (which is extremely unlikely),
// we will be running with an unknown user token. The only safe thing to do in that case
// is terminate ourselves.
Expand Down
8 changes: 8 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ target_link_libraries(dxgi-info
${PLATFORM_LIBRARIES})
target_compile_options(dxgi-info PRIVATE ${SUNSHINE_COMPILE_OPTIONS})

add_executable(elevator elevator.cpp)
set_target_properties(elevator PROPERTIES CXX_STANDARD 17)
target_link_libraries(elevator
shell32
${PLATFORM_LIBRARIES})
target_compile_options(elevator PRIVATE ${SUNSHINE_COMPILE_OPTIONS})

add_executable(audio-info audio.cpp)
set_target_properties(audio-info PROPERTIES CXX_STANDARD 17)
target_link_libraries(audio-info
Expand All @@ -36,3 +43,4 @@ target_link_libraries(ddprobe
d3d11
${PLATFORM_LIBRARIES})
target_compile_options(ddprobe PRIVATE ${SUNSHINE_COMPILE_OPTIONS})

70 changes: 70 additions & 0 deletions tools/elevator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <Windows.h>
#include <iostream>
#include <string>

/**
* @file elevator.cpp
* @brief A simple command line utility to run a given command with administrative privileges.
*
* This utility helps run a command with administrative privileges on Windows
* by leveraging the ShellExecuteExW function. The program accepts a command
* and optional arguments, then attempts to run the command with elevated
* privileges. If successful, it waits for the process to complete and
* returns the exit code of the launched process.
*
* @example
* To run the command prompt with administrative privileges, execute the following command:
* elevator.exe cmd
*
* To run a command, such as 'ipconfig /flushdns', with administrative privileges, execute:
* elevator.exe cmd /C "ipconfig /flushdns"
*/
int main(int argc, char *argv[]) {
// Check if the user provided at least one argument (the command to run)
if(argc < 2) {
std::cout << "Usage: " << argv[0] << " <command> [arguments]" << std::endl;
return 1;
}

// Convert the command and arguments from char* to wstring for use with ShellExecuteExW
std::wstring command = std::wstring(argv[1], argv[1] + strlen(argv[1]));
std::wstring arguments;

// Concatenate the remaining arguments (if any) into a single wstring
for(int i = 2; i < argc; ++i) {
arguments += std::wstring(argv[i], argv[i] + strlen(argv[i]));
if(i < argc - 1) {
arguments += L" ";
}
}

// Prepare the SHELLEXECUTEINFOW structure with the necessary information
SHELLEXECUTEINFOW info = { sizeof(SHELLEXECUTEINFOW) };
info.lpVerb = L"runas"; // Request elevation
info.lpFile = command.c_str();
info.lpParameters = arguments.empty() ? nullptr : arguments.c_str();
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_NOCLOSEPROCESS; // So we can wait for the process to finish

// Attempt to execute the command with elevation
if(!ShellExecuteExW(&info)) {
std::cout << "Error: ShellExecuteExW failed with code " << GetLastError() << std::endl;
return 1;
}

// Wait for the launched process to finish
WaitForSingleObject(info.hProcess, INFINITE);

DWORD exitCode = 0;

// Retrieve the exit code of the launched process
if(!GetExitCodeProcess(info.hProcess, &exitCode)) {
std::cout << "Error: GetExitCodeProcess failed with code " << GetLastError() << std::endl;
}

// Close the process handle
CloseHandle(info.hProcess);

// Return the exit code of the launched process
return exitCode;
}