kov changed libgksu/trunk/ChangeLog, libgksu/trunk/libgksu/libgksu.c

Gustavo Noronha kov at costa.debian.org
Sun Oct 1 13:55:31 UTC 2006


Mensagem de log: 
if xauth is an empty string when using the su backend,
then try to get it again by striping the hostname part
of the display string; this is needed for ssh X forwarding


-----


Modified: libgksu/trunk/ChangeLog
===================================================================
--- libgksu/trunk/ChangeLog	2006-10-01 13:53:33 UTC (rev 727)
+++ libgksu/trunk/ChangeLog	2006-10-01 13:55:31 UTC (rev 728)
@@ -1,3 +1,10 @@
+2006-10-01  Gustavo Noronha Silva  <kov at debian.org>
+
+	* libgksu/libgksu.c:
+	- if xauth is an empty string when using the su backend,
+	  then try to get it again by striping the hostname part
+	  of the display string; this is needed for ssh X forwarding
+
 2006-09-23  Gustavo Noronha Silva  <kov at debian.org>
 
 	* configure.ac:

Modified: libgksu/trunk/libgksu/libgksu.c
===================================================================
--- libgksu/trunk/libgksu/libgksu.c	2006-10-01 13:53:33 UTC (rev 727)
+++ libgksu/trunk/libgksu/libgksu.c	2006-10-01 13:55:31 UTC (rev 728)
@@ -1048,27 +1048,14 @@
   return strdup(buf.cmd);
 }
 
-/**
- * prepare_xauth:
- *
- * Sets up the variables with values for the $DISPLAY
- * environment variable and xauth-related stuff. Also
- * creates a temporary directory to hold a .Xauthority
- *
- * Returns: TRUE if it suceeds, FALSE if it fails.
- */
-static int
-prepare_xauth (GksuContext *context)
+static gchar *
+get_xauth_token (GksuContext *context, gchar *display)
 {
   gchar *xauth_bin = NULL;
-
   FILE *xauth_output;
-  gchar xauth[256] = {0};
-
   gchar *tmp = NULL;
+  gchar *xauth = g_new0 (gchar, 256);
 
-  context->display = g_strdup (getenv ("DISPLAY"));
-
   /* find out where the xauth binary is located */
   if (g_file_test ("/usr/bin/xauth", G_FILE_TEST_IS_EXECUTABLE))
     xauth_bin = "/usr/bin/xauth";
@@ -1080,32 +1067,83 @@
 	       "Failed to obtain xauth key: xauth binary not found "
 	       "at usual locations");
 
-      return FALSE;
+      return NULL;
     }
 
   /* get the authorization token */
   tmp = g_strdup_printf ("%s list %s | "
 			 "head -1 | awk '{ print $3 }'",
 			 xauth_bin,
-			 context->display);
+			 display);
   if ((xauth_output = popen (tmp, "r")) == NULL)
     {
       fprintf (stderr,
 	       "Failed to obtain xauth key: %s",
 	       strerror(errno));
-      return FALSE;
+      return NULL;
     }
   fread (xauth, sizeof(char), 255, xauth_output);
   pclose (xauth_output);
   g_free (tmp);
 
-  context->xauth = g_strdup (xauth);
-
   if (context->debug)
     {
       fprintf(stderr,
 	      "xauth: -%s-\n"
 	      "display: -%s-\n",
+	      xauth, display);
+    }
+
+  return xauth;
+}
+
+/**
+ * prepare_xauth:
+ *
+ * Sets up the variables with values for the $DISPLAY
+ * environment variable and xauth-related stuff. Also
+ * creates a temporary directory to hold a .Xauthority
+ *
+ * Returns: TRUE if it suceeds, FALSE if it fails.
+ */
+static int
+prepare_xauth (GksuContext *context)
+{
+  gchar *display = NULL;
+  gchar *xauth = NULL;
+
+  display = g_strdup (getenv ("DISPLAY"));
+  xauth = get_xauth_token (context, display);
+  if (xauth == NULL)
+    {
+      g_free (display);
+      return FALSE;
+    }
+
+  /* If xauth is the empty string, then try striping the
+   * hostname part of the DISPLAY string for getting the
+   * auth token; this is needed for ssh-forwarded usage
+   */
+  if (!strcmp ("", xauth))
+    {
+      gchar *cut_display = NULL;
+
+      g_free (xauth);
+      cut_display = g_strdup (g_strrstr (display, ":"));
+      xauth = get_xauth_token (context, cut_display);
+
+      g_free (display);
+      display = cut_display;
+    }
+
+  context->xauth = xauth;
+  context->display = display;
+
+  if (context->debug)
+    {
+      fprintf(stderr,
+	      "final xauth: -%s-\n"
+	      "final display: -%s-\n",
 	      context->xauth, context->display);
     }
 




More information about the gksu-commits mailing list