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

Gustavo Noronha kov at costa.debian.org
Sun Oct 8 15:31:57 UTC 2006


Mensagem de log: 
make libgksu be able to handle sudo lecture


-----


Modified: libgksu/trunk/ChangeLog
===================================================================
--- libgksu/trunk/ChangeLog	2006-10-01 13:55:31 UTC (rev 728)
+++ libgksu/trunk/ChangeLog	2006-10-08 15:31:56 UTC (rev 729)
@@ -1,3 +1,9 @@
+2006-10-08  Gustavo Noronha Silva  <kov at debian.org>
+
+	* libgksu/libgksu.c:
+	- use some brute force reading when using sudo, to be able
+	  to handle stuff like the sudo lecture and pam modules debugging
+
 2006-10-01  Gustavo Noronha Silva  <kov at debian.org>
 
 	* libgksu/libgksu.c:

Modified: libgksu/trunk/libgksu/libgksu.c
===================================================================
--- libgksu/trunk/libgksu/libgksu.c	2006-10-01 13:55:31 UTC (rev 728)
+++ libgksu/trunk/libgksu/libgksu.c	2006-10-08 15:31:56 UTC (rev 729)
@@ -2180,6 +2180,22 @@
   return retval;
 }
 
+static void
+read_line (int fd, gchar *buffer, int n)
+{
+  gint counter = 0;
+  gchar tmp[2] = {0};
+
+  for (; counter < (n - 1); counter++)
+    {
+      read (fd, tmp, 1);
+      if (tmp[0] == '\n')
+	break;
+      buffer[counter] = tmp[0];
+    }
+  buffer[counter+1] = '\0';
+}
+
 /**
  * gksu_sudo_full:
  * @context: a #GksuContext
@@ -2227,7 +2243,6 @@
 
   pid_t pid;
   int status;
-  size_t r;
   FILE *infile, *outfile;
   int parent_pipe[2];	/* For talking to the parent */
   int child_pipe[2];	/* For talking to the child */
@@ -2422,6 +2437,7 @@
     }
   else
     {
+      gint counter = 0;
       gchar *cmdline = NULL;
 
       // Parent
@@ -2468,10 +2484,23 @@
 	select (parent_pipe[0] + 1, &rfds, NULL, NULL, &tv);
       }
 
-      r = read(parent_pipe[0], buffer, 16);
+      /* Try hard to find the prompt; it may happen that we're
+       * seeing sudo's lecture, or that some pam module is spitting
+       * debugging stuff at the screen
+       */
+      for (counter = 0; counter < 50; counter++)
+	{
+	  if (strncmp (buffer, "GNOME_SUDO_PASS", 15) == 0)
+	    break;
 
+	  read_line (parent_pipe[0], buffer, 256);
+
+	  if (context->debug)
+	    fprintf (stderr, "buffer: -%s-\n", buffer);
+	}
+
       if (context->debug)
-	fprintf (stderr, "buffer: -%s-\n", buffer);
+	fprintf (stderr, "brute force GNOME_SUDO_PASS ended...\n");
 
       if (strncmp(buffer, "GNOME_SUDO_PASS", 15) == 0)
 	{




More information about the gksu-commits mailing list