[gparted] Only when configured, grant root access to the X11 display (#776437)



commit f38ccd028425552a1116180387e5307f23b8a688
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Jul 17 18:31:51 2017 +0100

    Only when configured, grant root access to the X11 display (#776437)
    
    GParted fails to display when run under Wayland [1][2][3].  This is
    because by intentional design Wayland doesn't allow applications with
    root privileges access to the display [4].
    
    As an interim workaround make the gparted shell wrapper use xhost to
    grant root access to the X11 server if root doesn't already have access,
    but only when configured.  Granting root access must be explicitly
    enabled when building GParted like this:
        ./configure --enable-xhost-root
    It defaults to disabled.  When gpartedbin binary ends the shell wrapper
    revokes root access only if it granted such access.
    
    [1] GNOME Bug 776437 - GParted fails to run as root under Wayland
        https://bugzilla.gnome.org/show_bug.cgi?id=776437
    
    [2] Ubuntu Bug 1652282 - GParted does not work in GNOME on Wayland
        https://bugs.launchpad.net/ubuntu/+source/gparted/+bug/1652282
    
    [3] Fedora Bug 1397103 - gparted not working under Wayland
        https://bugzilla.redhat.com/show_bug.cgi?id=1397103
    
    [4] Common Fedora 25 bugs
        Running graphical apps with root privileges (e.g. gparted) does not
        work on Wayland
        https://fedoraproject.org/wiki/Common_F25_bugs#wayland-root-apps
    
    Bug 776437 - GParted fails to run as root under Wayland

 Makefile.am  |    3 ++-
 README       |    7 +++++++
 configure.ac |   21 +++++++++++++++++++++
 gparted.in   |   29 ++++++++++++++++++++++++++++-
 4 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4edcd82..549d2a1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,7 +34,8 @@ 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[@],$(GKSUPROG),g' \
+       -e 's,[@]enable_xhost_root[@],$(ENABLE_XHOST_ROOT),g'
 
 gparted.desktop.in:  gparted.desktop.in.in Makefile
        $(do_subst) < $(srcdir)/gparted.desktop.in.in > gparted.desktop.in
diff --git a/README b/README
index 374073f..d3398b1 100644
--- a/README
+++ b/README
@@ -145,6 +145,11 @@ b. Building from Source
               specifically enabled with the --enable-online-resize flag:
                 E.g., ./configure --enable-online-resize
 
+   If you wish to build GParted to allow it to use xhost to grant root
+   access to the X11 server use the --enable-xhost-root flag.  This is
+   required to allow GParted to display under Wayland.
+      ./configure --enable-xhost-root
+
    Please note that more than one configure flag can be used:
       E.g., ./configure --disable-doc --enable-libparted-dmraid
 
@@ -332,4 +337,6 @@ system.  These commands include:
    udevinfo        - used in dmraid to query udev name
    udevadm         - used in dmraid to query udev name
    yelp            - used to display help manual
+   xhost           - used to grant root access to the X11 server, only
+                     when configured to do so
 
diff --git a/configure.ac b/configure.ac
index 7d31f07..e22034f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -392,6 +392,25 @@ else
 fi
 
 
+dnl Check whether to explicitly grant root access to the display.
+AC_ARG_ENABLE(
+       [xhost-root],
+       AS_HELP_STRING(
+               [--enable-xhost-root],
+               [enable explicitly granting root access to the display @<:@default=disabled@:>@]),
+       [enable_xhost_root=$enableval],
+       [enable_xhost_root=no]
+)
+
+AC_MSG_CHECKING([whether to explicitly grant root access to the display])
+if test "x$enable_xhost_root" = 'xyes'; then
+       AC_MSG_RESULT([yes])
+else
+       AC_MSG_RESULT([no])
+fi
+AC_SUBST([ENABLE_XHOST_ROOT], $enable_xhost_root)
+
+
 AC_CONFIG_FILES([
 Makefile
 compose/Makefile
@@ -422,6 +441,8 @@ echo "                      Build help documentation?  :  $enable_doc"
 echo ""
 echo "           Use native libparted dmraid support?  :  $enable_libparted_dmraid"
 echo ""
+echo "   Explicitly grant root access to the display?  :  $enable_xhost_root"
+echo ""
 echo "       --- Features Based On Libparted Version ---"
 echo "       Need delete old partitions before"
 echo "              creating a loop table workaround?  :  $need_loop_delete_old_ptns_workaround"
diff --git a/gparted.in b/gparted.in
index 4eb6300..9ff0512 100755
--- a/gparted.in
+++ b/gparted.in
@@ -56,8 +56,35 @@ if test "x`id -u`" != "x0"; then
                exit 1
        fi
 
+       #
+       # Interim workaround to allow GParted run by root access to the
+       # X11 display server under Wayland.  If configured with
+       # './configure --enable-xhost-root', the xhost command is
+       # available and root has not been granted access to the X11
+       # display via xhost, then grant access.
+       #
+       ENABLE_XHOST_ROOT=@enable_xhost_root@
+       GRANTED_XHOST_ROOT=no
+       if test "x$ENABLE_XHOST_ROOT" = 'xyes' && xhost 1> /dev/null 2>&1; then
+               if ! xhost | grep -qi 'SI:localuser:root$'; then
+                       xhost +SI:localuser:root
+                       GRANTED_XHOST_ROOT=yes
+               fi
+       fi
+
+       #
+       # Run gparted as root.
+       #
        @gksuprog@ '@bindir@/gparted' "$@"
-       exit $?
+       status=$?
+
+       #
+       # Revoke root access to the X11 display, only if we granted it.
+       #
+       if test "x$GRANTED_XHOST_ROOT" = 'xyes'; then
+               xhost -SI:localuser:root
+       fi
+       exit $status
 fi
 
 #


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]