Skip to content

add sudo fallback#24

Merged
Sundownersport merged 1 commit intomainfrom
linux-pkexec-fallback-to-sudo
Feb 4, 2026
Merged

add sudo fallback#24
Sundownersport merged 1 commit intomainfrom
linux-pkexec-fallback-to-sudo

Conversation

@Sundownersport
Copy link
Member

Changes Made:

  1. Cargo.toml (line 34)
  • Added which = "6.0" dependency for detecting available privilege escalation tools
  1. src/main.rs
  • Added use std::path::Path; import
  • Created 4 helper functions:
    • launch_with_pkexec() - Uses pkexec (PolicyKit) with environment variable preservation
    • launch_with_sudo_terminal() - Launches sudo in a terminal emulator (tries 6 different terminals)
    • launch_with_kdesudo() - KDE's graphical sudo
    • launch_with_gksudo() - Older GNOME/GTK graphical sudo
  • Updated check_and_request_privileges() to implement the fallback chain: a. pkexec (most GUI-friendly, modern systems) b. kdesudo (KDE environments) c. gksudo (older GNOME systems) d. sudo in terminal (universal fallback - works on any Linux with sudo) e. Helpful error message if all methods fail

Key Features:

  • Wide compatibility: Now works on Debian-based systems without PolicyKit
  • Terminal emulator detection: Tries 6 different terminals (x-terminal-emulator, gnome-terminal, konsole, xfce4-terminal, mate-terminal, xterm)
  • Preserves environment: DISPLAY and other GUI variables are passed through for each method
  • Clear user feedback: Informative error messages if privilege escalation fails
  • Non-invasive: Only tries methods that are actually installed on the system

 Changes Made:

  1. Cargo.toml (line 34)

  - Added which = "6.0" dependency for detecting available privilege escalation tools

  2. src/main.rs

  - Added use std::path::Path; import
  - Created 4 helper functions:
    - launch_with_pkexec() - Uses pkexec (PolicyKit) with environment variable preservation
    - launch_with_sudo_terminal() - Launches sudo in a terminal emulator (tries 6 different terminals)
    - launch_with_kdesudo() - KDE's graphical sudo
    - launch_with_gksudo() - Older GNOME/GTK graphical sudo
  - Updated check_and_request_privileges() to implement the fallback chain:
    a. pkexec (most GUI-friendly, modern systems)
    b. kdesudo (KDE environments)
    c. gksudo (older GNOME systems)
    d. sudo in terminal (universal fallback - works on any Linux with sudo)
    e. Helpful error message if all methods fail

  Key Features:

  - Wide compatibility: Now works on Debian-based systems without PolicyKit
  - Terminal emulator detection: Tries 6 different terminals (x-terminal-emulator, gnome-terminal, konsole,
  xfce4-terminal, mate-terminal, xterm)
  - Preserves environment: DISPLAY and other GUI variables are passed through for each method
  - Clear user feedback: Informative error messages if privilege escalation fails
  - Non-invasive: Only tries methods that are actually installed on the system
@Sundownersport Sundownersport merged commit 3fe06af into main Feb 4, 2026
8 of 12 checks passed
@Sundownersport Sundownersport deleted the linux-pkexec-fallback-to-sudo branch February 4, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant