kov changed gksu/branches/gksu2/ChangeLog, gksu/branches/gksu2/gksu/gksu.c

Gustavo Noronha kov at costa.debian.org
Tue Apr 25 02:36:49 UTC 2006


Mensagem de log: 
provide a clear way of forcing sudo and su modes, and
fall back to the default, using the new gksu_run_full,
if none is given


-----


Modified: gksu/branches/gksu2/ChangeLog
===================================================================
--- gksu/branches/gksu2/ChangeLog	2006-04-25 02:31:11 UTC (rev 573)
+++ gksu/branches/gksu2/ChangeLog	2006-04-25 02:36:48 UTC (rev 574)
@@ -1,6 +1,11 @@
 2006-04-24  Gustavo Noronha Silva  <kov at debian.org>
 
 	* gksu/gksu.c:
+	- provide a clear way of forcing sudo and su modes, and
+	  fall back to the default, using the new gksu_run_full,
+	  if none is given
+
+	* gksu/gksu.c:
 	- ignore -i and -t, reimplemented -m using functionality
 	  that has just been added to libgksu2
 

Modified: gksu/branches/gksu2/gksu/gksu.c
===================================================================
--- gksu/branches/gksu2/gksu/gksu.c	2006-04-25 02:31:11 UTC (rev 573)
+++ gksu/branches/gksu2/gksu/gksu.c	2006-04-25 02:36:48 UTC (rev 574)
@@ -24,8 +24,13 @@
 /* GLOBALS */
 gboolean print_pass = FALSE;
 gboolean force_grab = FALSE;
-gboolean sudo_mode = FALSE;
 gboolean prompt = FALSE;
+enum
+  {
+    SUDO_MODE,
+    SU_MODE,
+    DEFAULT_MODE
+  };
 
 struct option long_opts[] = {
     /*
@@ -43,7 +48,8 @@
     {"disable-grab", optional_argument, NULL, 'g'},
     {"ssh-fwd", no_argument, NULL, 's'},
     {"debug", no_argument, NULL, 'd'},
-    {"sudo-mode", optional_argument, NULL, 'S'},
+    {"sudo-mode", no_argument, NULL, 'S'},
+    {"su-mode", no_argument, NULL, 'w'},
     {"prompt", optional_argument, NULL, 'P'},
     {"desktop", required_argument, NULL, 'D'},
     {0, 0, 0, 0}
@@ -82,12 +88,12 @@
     N_("  --prompt, -P\n"
        "    Ask the user if they want to have their keyboard\n"
        "    and mouse grabbed before doing so.\n"),
-    N_("  --ssh-fwd, -s\n"
-       "    Strip the host part of the $DISPLAY variable, so that\n"
-       "    GKSu will work on SSH X11 Forwarding.\n"),
     N_("  --sudo-mode, -S\n"
        "    Make GKSu use sudo instead of su, as if it had been\n"
        "    run as \"gksudo\".\n"),
+    N_("  --su-mode, -w\n"
+       "    Make GKSu use su, even if instead of using libgksu's\n"
+       "    default.\n"),
     N_("  --user <user>, -u <user>\n"
        "    Call <command> as the specified user.\n"),
     N_("  --desktop <file>, -D <file>\n"
@@ -159,6 +165,7 @@
   gint newargc = 0;
   gchar **newargv = NULL;
 
+  guint run_mode = DEFAULT_MODE;
   gchar *desktop_file_name = NULL;
 
   int c = 0;
@@ -200,7 +207,7 @@
   gtk_init (&newargc, &newargv);
 
   context = gksu_context_new ();
-  while ((c = getopt_long(newargc, newargv, "?hu:lpm:kt:i:gdsS::P::aD:", long_opts, NULL))
+  while ((c = getopt_long(newargc, newargv, "?hu:lpm:kt:i:gdsSwP::aD:", long_opts, NULL))
 	 != EOF)
     {
       switch (c)
@@ -253,22 +260,11 @@
 	  gksu_context_set_debug (context, TRUE);
 	  break;
 	case 'S':
-	  sudo_mode = TRUE;
-
-	  if (optarg != NULL)
-	    {
-	      if (!strcasecmp (optarg, "yes")); /* ignore, already set */
-	      else if (!strcasecmp (optarg, "no"))
-		sudo_mode = FALSE;
-	      else
-		{
-		  fprintf (stderr, _("Option not accepted for --sudo-mode: %s\n"),
-			   optarg);
-		  return 1;
-		}
-	    }
-
+	  run_mode = SUDO_MODE;
 	  break;
+	case 'w':
+	  run_mode = SU_MODE;
+	  break;
 	case 'P':
 	  prompt = TRUE;
 
@@ -296,7 +292,7 @@
   { /* support gksu_sudo_run */
     gchar *myname = g_path_get_basename (argv[0]);
     if (!strcmp(myname, "gksudo"))
-      sudo_mode = TRUE;
+      run_mode = SUDO_MODE;
     g_free (myname);
   }
 
@@ -378,38 +374,31 @@
   }
 
 
-  if (sudo_mode)
-    {
-      gksu_sudo_full (context,
-		      NULL, NULL,
-		      NULL, NULL,
-		      &error);
-      if (error)
-	{
-	  gk_dialog (GTK_MESSAGE_ERROR,
-		     _("<b>Failed to run %s as user %s.</b>\n\n%s"),
-		     gksu_context_get_command (context),
-		     gksu_context_get_user (context),
-		     error->message);
-	  return 3;
-	}
-    }
-  else
-    {
-      gksu_su_full (context,
+  if (run_mode == SUDO_MODE)
+    gksu_sudo_full (context,
 		    NULL, NULL,
 		    NULL, NULL,
 		    &error);
+  else if (run_mode == SU_MODE)
+    gksu_su_full (context,
+		  NULL, NULL,
+		  NULL, NULL,
+		  &error);
 
-      if (error)
-	{
-	  gk_dialog (GTK_MESSAGE_ERROR,
-		     _("<b>Failed to run %s as user %s.</b>\n\n%s"),
-		     gksu_context_get_command (context),
-		     gksu_context_get_user (context),
-		     error->message);
-	  return 3;
-	}
+  else
+    gksu_run_full (context,
+		   NULL, NULL,
+		   NULL, NULL,
+		   &error);
+
+  if (error)
+    {
+      gk_dialog (GTK_MESSAGE_ERROR,
+		 _("<b>Failed to run %s as user %s.</b>\n\n%s"),
+		 gksu_context_get_command (context),
+		 gksu_context_get_user (context),
+		 error->message);
+      return 3;
     }
 
   return 0;




More information about the gksu-commits mailing list