From 203d9e39a05da90bb340a22f406717832508bdff Mon Sep 17 00:00:00 2001 From: 21pages Date: Tue, 13 Sep 2022 18:10:20 +0800 Subject: [PATCH] add polkit for custom authentication && update build.rs Signed-off-by: 21pages --- build.py | 18 ++++++++++-------- com.rustdesk.RustDesk.policy | 22 ++++++++++++++++++++++ src/platform/linux.rs | 10 ++++++++-- 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 com.rustdesk.RustDesk.policy diff --git a/build.py b/build.py index cdca16645..5be59503c 100755 --- a/build.py +++ b/build.py @@ -71,7 +71,7 @@ def make_parser(): parser.add_argument( '--hwcodec', action='store_true', - help='Enable feature hwcodec, windows only.' + help='Enable feature hwcodec' ) return parser @@ -124,26 +124,28 @@ def get_features(args): def build_flutter_deb(version): os.chdir('flutter') + os.system('/bin/rm -rf tmpdeb/') os.system('dpkg-deb -R rustdesk.deb tmpdeb') - # os.system('flutter build linux --release') + os.system('flutter build linux --release') os.system('rm tmpdeb/usr/bin/rustdesk') - os.system('strip build/linux/x64/release/liblibrustdesk.so') os.system('mkdir -p tmpdeb/usr/lib/rustdesk') os.system('mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/') + os.system('mkdir -p tmpdeb/usr/share/polkit-1/actions') os.system( 'cp -r build/linux/x64/release/bundle/* tmpdeb/usr/lib/rustdesk/') os.system( 'pushd tmpdeb && ln -s /usr/lib/rustdesk/flutter_hbb usr/bin/rustdesk && popd') os.system( - 'cp build/linux/x64/release/liblibrustdesk.so tmpdeb/usr/lib/rustdesk/librustdesk.so') + 'cp ../rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/') os.system( - 'cp rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/') - os.system( - 'cp rustdesk.service.user tmpdeb/usr/share/rustdesk/files/systemd/') + 'cp ../rustdesk.service.user tmpdeb/usr/share/rustdesk/files/systemd/') os.system( 'cp ../128x128@2x.png tmpdeb/usr/share/rustdesk/files/rustdesk.png') os.system( - 'cp rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop') + 'cp ../rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop') + os.system( + 'cp ../com.rustdesk.RustDesk.policy tmpdeb/usr/share/polkit-1/actions/') + os.system("echo \"#!/bin/sh\" >> tmpdeb/usr/share/rustdesk/files/polkit && chmod a+x tmpdeb/usr/share/rustdesk/files/polkit") os.system('mkdir -p tmpdeb/DEBIAN') os.system('cp -a ../DEBIAN/* tmpdeb/DEBIAN/') md5_file('usr/share/rustdesk/files/systemd/rustdesk.service') diff --git a/com.rustdesk.RustDesk.policy b/com.rustdesk.RustDesk.policy new file mode 100644 index 000000000..a77223120 --- /dev/null +++ b/com.rustdesk.RustDesk.policy @@ -0,0 +1,22 @@ + + + + RustDesk + https://rustdesk.com/ + rustdesk + + Change RustDesk options + Authentication is required to change RustDesk options + 要更改RustDesk选项, 需要您先通过身份验证 + 要變更RustDesk選項, 需要您先通過身份驗證 + /usr/share/rustdesk/files/polkit + true + + auth_admin + auth_admin + auth_admin + + + diff --git a/src/platform/linux.rs b/src/platform/linux.rs index fe2673832..89e2d296d 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -638,7 +638,13 @@ pub fn quit_gui() { } pub fn check_super_user_permission() -> ResultType { - // TODO: replace echo with a rustdesk's program, which is location-fixed and non-gui. - let status = std::process::Command::new("pkexec").arg("echo").status()?; + let file = "/usr/share/rustdesk/files/polkit"; + let arg; + if std::path::Path::new(file).is_file() { + arg = file; + } else { + arg = "echo"; + } + let status = std::process::Command::new("pkexec").arg(arg).status()?; Ok(status.success() && status.code() == Some(0)) }