Registration is now invite-only. Any user can make an invite, you need to create it here and give resulting link to someone to register.

About project

GParted stands for Gnome Partition Editor and is a graphical frontend to
libparted. Among other features it supports creating, resizing, moving
and copying of partitions.

Last commit

avatar
mikhailnov has added 14d5917a62
Patch: fallback to xdg-su for non-wheel users, upd to 0.33.0, remove ...

...consolehelper usage (pkexec, xdg-su will be used)

Files in

100644 | 127 lines (118 sloc) | 3.59 KB
From ec9ae37816082176ff1ae7875802f1e9bb816bb8 Mon Sep 17 00:00:00 2001
From: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
Date: Wed, 13 Mar 2019 06:45:30 +0300
Subject: [PATCH] Define main and runtime fallback graphical su programs as
 build options

---
 Makefile.am  |  1 +
 configure.ac | 32 ++++++++++++++++++++++++++++----
 gparted.in   | 17 +++++++++++++++--
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index aa2aaf76..7b438f5c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,7 @@ CLEANFILES = $(bin_SCRIPTS) $(DESKTOP_IN_FILES) $(polkit_action_in_FILES)
 do_subst = sed -e 's,[@]sbindir[@],$(sbindir),g' \
 	-e 's,[@]bindir[@],$(bindir),g' \
 	-e 's,[@]gksuprog[@],$(GKSUPROG),g' \
+	-e 's,[@]gksuprog_fallback[@],$(GKSUPROG_FALLBACK),g' \
 	-e 's,[@]enable_xhost_root[@],$(ENABLE_XHOST_ROOT),g'
 
 gparted.desktop.in:  gparted.desktop.in.in Makefile
diff --git a/configure.ac b/configure.ac
index 40ae777d..f2fb9d93 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,26 @@ PKG_CHECK_EXISTS
 dnl======================
 dnl Find graphical privilege escalation program
 dnl======================
+
+AC_ARG_WITH(
+	[gksuprog],
+	AS_HELP_STRING(
+		[--with-gksuprog=XXX],
+		[Graphical program to get root permisisons, default is pkexec (polkit)]),
+	[GKSUPROG="$withval"],
+	[GKSUPROG="pkexec --disable-internal-agent"]
+)
+
+AC_ARG_WITH(
+	[gksuprog-fallback],
+	AS_HELP_STRING(
+		[--with-gksuprog-fallback=XXX],
+		[Enable runtime fallback to another graphical program to get root permisisons]),
+	[GKSUPROG_FALLBACK="$withval"],
+	[GKSUPROG_FALLBACK=""]
+)
+
+if echo "$GKSUPROG" | grep -q ^pkexec; then
 dnl Check for pkexec >= 0.102 for it's ability to run X11 apps.
 AM_CONDITIONAL([INSTALL_POLKIT_ACTIONS], false)
 PKEXEC_REQUIRED_VERSION='0.102'
@@ -35,14 +55,19 @@ if test "x$PKEXEC_VERSION_OUTPUT" != 'x'; then
 	PKEXEC_FOUND_INT=`echo "$PKEXEC_FOUND_VERSION" | $AWK -F. '{print $1 * 10000 + $2}'`
 	AC_MSG_RESULT([$PKEXEC_FOUND_VERSION found])
 	if test "$PKEXEC_FOUND_INT" -ge "$PKEXEC_REQUIRED_INT"; then
-		GKSUPROG='pkexec --disable-internal-agent'
-		AC_SUBST([GKSUPROG])
 		AM_CONDITIONAL([INSTALL_POLKIT_ACTIONS], true)
+	else
+		# unset default GKSUPROG from pkexec
+		GKSUPROG=''
 	fi
 fi
+fi
+
+AC_SUBST(GKSUPROG)
+AC_SUBST(GKSUPROG_FALLBACK)
 
 dnl Check for alternative graphical privilege escalation programs.
-if test "x$GKSUPROG" = 'x'; then
+if test "x$GKSUPROG" = 'x' && test "x$GKSUPROG_FALLBACK" = 'x'; then
 	AC_CHECK_PROGS([GKSUPROG], [gksudo gksu kdesudo "xdg-su -c"], [])
 fi
 
@@ -346,7 +371,6 @@ else
 fi
 AC_SUBST([ENABLE_XHOST_ROOT], $enable_xhost_root)
 
-
 AC_CONFIG_FILES([
 Makefile
 compose/Makefile
diff --git a/gparted.in b/gparted.in
index 3f9b0f1a..e5763009 100755
--- a/gparted.in
+++ b/gparted.in
@@ -50,10 +50,15 @@ if test "x`id -u`" != "x0"; then
 	#  non-root to display the graphical error about needing root
 	#  privileges.
 	#
-	if test "x@gksuprog@" = "x"; then
+
+	run_noroot(){
 		echo "Root privileges are required for running gparted."
 		$BASE_CMD
 		exit 1
+	}
+
+	if test "x@gksuprog@" = "x" && test "x@gksuprog_fallback@" = "x"; then
+		run_noroot
 	fi
 
 	#
@@ -75,7 +80,15 @@ if test "x`id -u`" != "x0"; then
 	#
 	# Run gparted as root.
 	#
-	@gksuprog@ '@bindir@/gparted' "$@"
+	if [ -x "$(command -v @gksuprog@)" ]; then
+		GKSUPROG="@gksuprog@"
+	# check if fallback program was defined at build time and if it is available
+	elif [ -n "@gksuprog_fallback@" ] && [ -x "$(command -v @gksuprog_fallback@)" ]; then
+		GKSUPROG="@gksuprog_fallback@"
+	else
+		run_noroot
+	fi
+	${GKSUPROG} '@bindir@/gparted' "$@"
 	status=$?
 
 	#
-- 
2.20.1