kov changed libgksu/trunk/ChangeLog, libgksu/trunk/aclocal.m4, libgksu/trunk/config.h.in, libgksu/trunk/configure.ac, libgksu/trunk/libgksu/Makefile.am, libgksu/trunk/libgksu/libgksu.c

Gustavo Noronha kov at alioth.debian.org
Sun Aug 16 22:19:24 UTC 2009


Mensagem de log: 
Make forkpty-based sudo a configure option

-----


Modified: libgksu/trunk/ChangeLog
===================================================================
--- libgksu/trunk/ChangeLog	2009-06-29 18:12:05 UTC (rev 872)
+++ libgksu/trunk/ChangeLog	2009-08-16 22:19:24 UTC (rev 873)
@@ -1,3 +1,9 @@
+2009-08-16  Gustavo Noronha Silva  <kov at debian.org>
+
+	* libgksu/libgksu.c: - turn the new forkpty-based code into a
+	configure option, since this doesn't seem to play that nice with
+	Debian/Ubuntu
+
 2009-06-29  Gustavo Noronha Silva  <kov at debian.org>
 
 	* Release 2.0.12

Modified: libgksu/trunk/aclocal.m4
===================================================================
--- libgksu/trunk/aclocal.m4	2009-06-29 18:12:05 UTC (rev 872)
+++ libgksu/trunk/aclocal.m4	2009-08-16 22:19:24 UTC (rev 873)
@@ -13,8 +13,8 @@
 
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.63],,
-[m4_warning([this file was generated for autoconf 2.63.
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.64],,
+[m4_warning([this file was generated for autoconf 2.64.
 You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically `autoreconf'.])])

Modified: libgksu/trunk/config.h.in
===================================================================
--- libgksu/trunk/config.h.in	2009-06-29 18:12:05 UTC (rev 872)
+++ libgksu/trunk/config.h.in	2009-08-16 22:19:24 UTC (rev 873)
@@ -73,6 +73,9 @@
 /* Define to the one symbol short name of this package. */
 #undef PACKAGE_TARNAME
 
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 

Modified: libgksu/trunk/configure.ac
===================================================================
--- libgksu/trunk/configure.ac	2009-06-29 18:12:05 UTC (rev 872)
+++ libgksu/trunk/configure.ac	2009-08-16 22:19:24 UTC (rev 873)
@@ -53,6 +53,9 @@
 IT_PROG_INTLTOOL
 AM_GLIB_GNU_GETTEXT
 
+AC_ARG_ENABLE(sudo-forkpty, [  --enable-sudo-forkpty  Use forkpty when dealing with sudo; this is required if you have requiretty as an option in your sudoers file [default=no]], sudo_forkpty="$enableval", sudo_forkpty=no)
+AM_CONDITIONAL(SUDO_FORKPTY, test x$sudo_forkpty = xyes)
+
 ##################################################
 # Check for gtk-doc.
 ##################################################

Modified: libgksu/trunk/libgksu/Makefile.am
===================================================================
--- libgksu/trunk/libgksu/Makefile.am	2009-06-29 18:12:05 UTC (rev 872)
+++ libgksu/trunk/libgksu/Makefile.am	2009-08-16 22:19:24 UTC (rev 873)
@@ -2,6 +2,10 @@
 INCLUDES = ${LIBGKSU_CFLAGS}
 AM_CPPFLAGS = -DLOCALEDIR=\"$(datadir)/locale\" -DDATA_DIR=\"$(datadir)\" -DPREFIX=\"$(prefix)\"
 
+if SUDO_FORKPTY
+AM_CPPFLAGS += -DSUDO_FORKPTY
+endif
+
 lib_LTLIBRARIES = libgksu2.la
 libgksu2_la_SOURCES = libgksu.c libgksu.h
 # 0.0.0 -> major.minor.micro

Modified: libgksu/trunk/libgksu/libgksu.c
===================================================================
--- libgksu/trunk/libgksu/libgksu.c	2009-06-29 18:12:05 UTC (rev 872)
+++ libgksu/trunk/libgksu/libgksu.c	2009-08-16 22:19:24 UTC (rev 873)
@@ -2474,11 +2474,15 @@
   char **cmd;
   char buffer[256] = {0};
   char *child_stderr = NULL;
+
+#ifdef SUDO_FORKPTY
   /* This command is used to gain a token */
   char *const verifycmd[] =
     {
       "/usr/bin/sudo", "-p", "GNOME_SUDO_PASS", "-v", NULL
     };
+#endif
+
   int argcount = 8;
   int i, j;
 
@@ -2489,8 +2493,14 @@
 
   pid_t pid;
   int status;
+#ifdef SUDO_FORKPTY
   FILE *fdfile = NULL;
   int fdpty = -1;
+#else
+  FILE *infile, *outfile;
+  int parent_pipe[2];  /* For talking to the parent */
+  int child_pipe[2];   /* For talking to the child */
+#endif
 
   context->sudo_mode = TRUE;
 
@@ -2565,9 +2575,11 @@
   cmd[argcount] = g_strdup("-S");
   argcount++;
 
+#ifdef SUDO_FORKPTY
   /* Make sudo noninteractive (we should already have a token) */
   cmd[argcount] = g_strdup("-n");
   argcount++;
+#endif
 
   /* Make sudo use next arg as prompt */
   cmd[argcount] = g_strdup("-p");
@@ -2647,13 +2659,42 @@
 	fprintf (stderr, "cmd[%d]: %s\n", i, cmd[i]);
     }
 
+#ifdef SUDO_FORKPTY
   pid = forkpty(&fdpty, NULL, NULL, NULL);
+#else
+  if ((pipe(parent_pipe)) == -1)
+    {
+      g_set_error (error, gksu_quark, GKSU_ERROR_PIPE,
+                   _("Error creating pipe: %s"),
+                   strerror(errno));
+      sudo_reset_xauth (context, xauth, xauth_env);
+      return FALSE;
+    }
+  if ((pipe(child_pipe)) == -1)
+    {
+      g_set_error (error, gksu_quark, GKSU_ERROR_PIPE,
+                   _("Error creating pipe: %s"),
+                   strerror(errno));
+      sudo_reset_xauth (context, xauth, xauth_env);
+      return FALSE;
+    }
+
+  pid = fork();
+#endif
+
   if (pid == 0)
     {
       // Child
-      setsid();   // make us session leader
+      setsid ();   // make us session leader
 
-      execv(verifycmd[0], verifycmd);
+#ifdef SUDO_FORKPTY
+      execv (verifycmd[0], verifycmd);
+#else
+      close (child_pipe[1]);
+      dup2 (child_pipe[0], STDIN_FILENO);
+      dup2 (parent_pipe[1], STDERR_FILENO);
+      execv (cmd[0], cmd);
+#endif
 
       g_set_error (error, gksu_quark, GKSU_ERROR_EXEC,
 		   _("Failed to exec new process: %s"),
@@ -2674,22 +2715,38 @@
     {
       gint counter = 0;
       gchar *cmdline = NULL;
-      struct termios tio;
 
       // Parent
+#ifdef SUDO_FORKPTY
       fdfile = fdopen(fdpty, "w+");
 
-      /* make sure we notice that ECHO is turned off, if it gets
-         turned off */
-      tcgetattr (fdpty, &tio);
-      for (counter = 0; (tio.c_lflag & ECHO) && counter < 15; counter++)
-      {
-        usleep (1000);
-        tcgetattr (fdpty, &tio);
-      }
-
       fcntl (fdpty, F_SETFL, O_NONBLOCK);
+#else
+      close(parent_pipe[1]);
 
+      infile = fdopen(parent_pipe[0], "r");
+      if (!infile)
+       {
+         g_set_error (error, gksu_quark, GKSU_ERROR_PIPE,
+                      _("Error opening pipe: %s"),
+                      strerror(errno));
+         sudo_reset_xauth (context, xauth, xauth_env);
+         return FALSE;
+       }
+
+      outfile = fdopen(child_pipe[1], "w");
+      if (!outfile)
+       {
+         g_set_error (error, gksu_quark, GKSU_ERROR_PIPE,
+                      _("Error opening pipe: %s"),
+                      strerror(errno));
+         sudo_reset_xauth (context, xauth, xauth_env);
+         return FALSE;
+       }
+
+      fcntl (parent_pipe[0], F_SETFL, O_NONBLOCK);
+#endif
+
       { /* no matter if we can read, since we're using
 	   O_NONBLOCK; this is just to avoid the prompt
 	   showing up after the read */
@@ -2697,11 +2754,19 @@
 	struct timeval tv;
 
 	FD_ZERO(&rfds);
+#ifdef SUDO_FORKPTY
 	FD_SET(fdpty, &rfds);
+#else
+        FD_SET(parent_pipe[0], &rfds);
+#endif
 	tv.tv_sec = 1;
 	tv.tv_usec = 0;
 
+#ifdef SUDO_FORKPTY
 	select (fdpty + 1, &rfds, NULL, NULL, &tv);
+#else
+        select (parent_pipe[0] + 1, &rfds, NULL, NULL, &tv);
+#endif
       }
 
       /* Try hard to find the prompt; it may happen that we're
@@ -2713,7 +2778,11 @@
 	  if (strncmp (buffer, "GNOME_SUDO_PASS", 15) == 0)
 	    break;
 
+#ifdef SUDO_FORKPTY
 	  read_line (fdpty, buffer, 256);
+#else
+          read_line (parent_pipe[0], buffer, 256);
+#endif
 
 	  if (context->debug)
 	    fprintf (stderr, "buffer: -%s-\n", buffer);
@@ -2747,17 +2816,33 @@
 
 	  usleep (1000);
 
+#ifdef SUDO_FORKPTY
 	  write (fdpty, password, strlen(password) + 1);
 	  write (fdpty, "\n", 1);
+#else
+         fprintf (outfile, "%s\n", password);
+         fclose (outfile);
+#endif
 
 	  nullify_password (password);
 
+#ifdef SUDO_FORKPTY
 	  fcntl(fdpty, F_SETFL, fcntl(fdpty, F_GETFL) & ~O_NONBLOCK);
+
 	  /* ignore the first newline that comes right after sudo receives
 	     the password */
 	  fgets (buffer, 255, fdfile);
 	  /* this is the status we are interested in */
 	  fgets (buffer, 255, fdfile);
+#else
+          fcntl(parent_pipe[0], F_SETFL, fcntl(parent_pipe[0], F_GETFL) & ~O_NONBLOCK);
+
+	  /* ignore the first newline that comes right after sudo receives
+	     the password */
+	  fgets (buffer, 255, infile);
+	  /* this is the status we are interested in */
+	  fgets (buffer, 255, infile);
+#endif
 	}
       else
 	{
@@ -2766,7 +2851,11 @@
 	    fprintf (stderr, "No password prompt found; we'll assume we don't need a password.\n");
 
           /* turn NONBLOCK off, also if have no prompt */
+#ifdef SUDO_FORKPTY
           fcntl(fdpty, F_SETFL, fcntl(fdpty, F_GETFL) & ~O_NONBLOCK);
+#else
+          fcntl(parent_pipe[0], F_SETFL, fcntl(parent_pipe[0], F_GETFL) & ~O_NONBLOCK);
+#endif
 
 	  should_display = gconf_client_get_bool (context->gconf_client,
 						  BASE_PATH "display-no-pass-info", NULL);
@@ -2806,8 +2895,13 @@
 	}
 
       /* If we have an error, let's just stop sudo right there. */
+#ifdef SUDO_FORKPTY
       if (error)
         close(fdpty);
+#else
+      if (error)
+        fclose(infile);
+#endif
 
       cmdline = g_strdup("sudo");
       /* wait for the child process to end or become something other
@@ -2830,6 +2924,7 @@
 	waitpid(pid, &status, 0);
       sudo_reset_xauth (context, xauth, xauth_env);
 
+#if SUDO_FORKPTY
       /*
        * Did token acquisition succeed? If so, spawn sudo in
        * non-interactive mode. It should either succeed or die
@@ -2841,6 +2936,7 @@
                        NULL, &child_stderr, &status,
                        error);
         }
+#endif
 
       if (exit_status)
       {




More information about the gksu-commits mailing list