Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ See Contributing.md for how to contribute or get in touch.

Usage
---------
By default synaptic uses pkexec to obtain root privileges needed.
By default synaptic uses pkexec to obtain root privileges, with run0 as a
fallback when available.

Synaptic is used very much like apt/apt-get. Aside from a graphical interface, another key difference is it let's you stage several changes and only applies package changes when you click apply.

Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Vcs-Browser: https://github.com/mvo5/synaptic

Package: synaptic
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, hicolor-icon-theme, polkitd | policykit-1, pkexec | policykit-1
Depends: ${shlibs:Depends}, ${misc:Depends}, hicolor-icon-theme, polkitd, pkexec | systemd
Recommends: libgtk3-perl, xdg-utils
Suggests: dwww, deborphan, apt-xapian-index, tasksel, software-properties-gtk
Description: Graphical package manager
Expand Down
28 changes: 27 additions & 1 deletion debian/synaptic-pkexec
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
#!/bin/sh
pkexec "/usr/sbin/synaptic" "$@"

if command -v pkexec >/dev/null 2>&1; then
exec pkexec "/usr/sbin/synaptic" "$@"
fi

if command -v run0 >/dev/null 2>&1; then
set -- "/usr/sbin/synaptic" "$@"
if [ -n "${DBUS_SESSION_BUS_ADDRESS+x}" ]; then
set -- "--setenv=DBUS_SESSION_BUS_ADDRESS" "$@"
fi
if [ -n "${XDG_RUNTIME_DIR+x}" ]; then
set -- "--setenv=XDG_RUNTIME_DIR" "$@"
fi
if [ -n "${XAUTHORITY+x}" ]; then
set -- "--setenv=XAUTHORITY" "$@"
fi
if [ -n "${WAYLAND_DISPLAY+x}" ]; then
set -- "--setenv=WAYLAND_DISPLAY" "$@"
fi
if [ -n "${DISPLAY+x}" ]; then
set -- "--setenv=DISPLAY" "$@"
fi
exec run0 "$@"
fi

echo "synaptic-pkexec: pkexec or run0 is required" >&2
exit 1
23 changes: 22 additions & 1 deletion gtk/rgutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ void RGFlushInterface()
}
}

static void AddRun0Environment(std::vector<const gchar*> &prefix)
{
if(getenv("DISPLAY") != NULL)
prefix.push_back("--setenv=DISPLAY");
if(getenv("WAYLAND_DISPLAY") != NULL)
prefix.push_back("--setenv=WAYLAND_DISPLAY");
if(getenv("XAUTHORITY") != NULL)
prefix.push_back("--setenv=XAUTHORITY");
if(getenv("XDG_RUNTIME_DIR") != NULL)
prefix.push_back("--setenv=XDG_RUNTIME_DIR");
if(getenv("DBUS_SESSION_BUS_ADDRESS") != NULL)
prefix.push_back("--setenv=DBUS_SESSION_BUS_ADDRESS");
}

/*
* SizeToStr: Converts a size long into a human-readable SI string
* ----------------------------------------------------
Expand Down Expand Up @@ -121,7 +135,7 @@ bool RunAsSudoUserCommand(std::vector<const gchar*> cmd)
return true;
}
bool getuidbyname = false;
// try pkexec first, then sudo
// try pkexec first, then sudo, then run0
sudo_user = getenv("PKEXEC_UID");

if (sudo_user == NULL) {
Expand Down Expand Up @@ -158,6 +172,13 @@ bool RunAsSudoUserCommand(std::vector<const gchar*> cmd)
prefix.push_back("-u");
prefix.push_back(sudo_user);
}
else if(FileExists("/usr/bin/run0") && sudo_user != NULL)
{
prefix.push_back("/usr/bin/run0");
AddRun0Environment(prefix);
prefix.push_back("-u");
prefix.push_back(sudo_user);
}
// insert the prefix string
cmd.insert(cmd.begin(), prefix.begin(), prefix.end());

Expand Down
Loading