19928N/A--- gksu-2.0.2/gksu/gksu.c-orig 2010-12-16 03:43:51.275486079 -0600
19928N/A+++ gksu-2.0.2/gksu/gksu.c 2010-12-16 03:46:11.151315385 -0600
19928N/A@@ -9,6 +9,8 @@
18566N/A #include <string.h>
18566N/A #include <getopt.h>
19928N/A #include <locale.h>
18566N/A+#include <dlfcn.h>
18566N/A+#include <link.h>
18566N/A
19928N/A #include <glib.h>
19928N/A #include <glib/gstdio.h>
19928N/A@@ -27,6 +29,9 @@
19928N/A gboolean print_pass = FALSE;
19928N/A gboolean force_grab = FALSE;
9135N/A gboolean prompt = FALSE;
19928N/A+gboolean elevated_privilege = TRUE;
9135N/A+gboolean elevated_role = TRUE;
19928N/A+
19928N/A enum
19928N/A {
19928N/A SUDO_MODE,
19928N/A@@ -40,10 +45,14 @@ struct option long_opts[] = {
9135N/A */
9135N/A {"help", no_argument, NULL, 'h'},
9135N/A {"login", no_argument, NULL, 'l'},
9135N/A+#ifndef __sun
9135N/A {"preserv-env", no_argument, NULL, 'k'},
9135N/A {"preserve-env", no_argument, NULL, 'k'},
9135N/A+#endif
9135N/A {"user", required_argument, NULL, 'u'},
9135N/A+#ifndef __sun
9135N/A {"print-pass", no_argument, NULL, 'p'},
9135N/A+#endif
9135N/A {"message", required_argument, NULL, 'm'},
9135N/A {"title", required_argument, NULL, 't'},
9135N/A {"icon", required_argument, NULL, 'i'},
19928N/A@@ -55,6 +64,8 @@ struct option long_opts[] = {
9135N/A {"prompt", optional_argument, NULL, 'P'},
19928N/A {"desktop", required_argument, NULL, 'D'},
19928N/A {"description", required_argument, NULL, 'D'},
19928N/A+ {"elevated-privilege", no_argument, NULL, 'p'},
9135N/A+ {"elevated-role", no_argument, NULL, 'r'},
9135N/A {0, 0, 0, 0}
9135N/A };
9135N/A
19928N/A@@ -106,12 +117,14 @@ help (gchar *cmdname)
19928N/A " Replace the standard message shown to ask for\n"
19928N/A " password for the argument passed to the option.\n"
19928N/A " Only use this if --description does not suffice.\n"),
9135N/A+#ifndef __sun
19928N/A N_("\n"),
19928N/A N_(" --print-pass, -p\n"
19928N/A " Ask gksu to print the password to stdout, just\n"
19928N/A " like ssh-askpass. Useful to use in scripts with\n"
19928N/A " programs that accept receiving the password on\n"
19928N/A " stdin.\n"),
19928N/A+#endif
19928N/A N_("\n"),
19928N/A N_(" --sudo-mode, -S\n"
19928N/A " Make GKSu use sudo instead of su, as if it had been\n"
19928N/A@@ -119,6 +132,13 @@ help (gchar *cmdname)
19928N/A N_(" --su-mode, -w\n"
19928N/A " Make GKSu use su, instead of using libgksu's\n"
19928N/A " default.\n"),
19928N/A+#ifdef __sun
19928N/A+ N_("\n"),
19928N/A+ N_(" --elevated-privilege, -p\n"
19928N/A+ " attempt to elevate user's privilege\n"),
19928N/A+ N_(" --elevated-role, -r\n"
19928N/A+ " attempt to elevate user's role\n"),
9135N/A+#endif
19928N/A };
19928N/A
19928N/A help_trans = g_strconcat(_(help_text[0]), _(help_text[1]),
19928N/A@@ -157,6 +177,14 @@ gk_dialog (GtkMessageType type, gchar *f
19928N/A gtk_window_set_resizable (GTK_WINDOW(diag_win), FALSE);
19928N/A
19928N/A gtk_widget_show_all (diag_win);
19928N/A+
19928N/A+ // we "raise" the window because there is a race here for
19928N/A+ // focus-follow-mouse and auto-raise WMs that may put the window
19928N/A+ // in the background and confuse users
19928N/A+ gtk_window_set_keep_above(GTK_WINDOW (diag_win), TRUE);
19928N/A+ // reset cursor
19928N/A+ gdk_window_set_cursor(diag_win->window, gdk_cursor_new(GDK_LEFT_PTR));
19928N/A+
19928N/A gtk_dialog_run (GTK_DIALOG(diag_win));
19928N/A
19928N/A g_free (msg);
19928N/A@@ -271,10 +299,12 @@ show_hide_advanced (GtkWidget *button, g
19928N/A else
19928N/A gksu_context_set_login_shell (context, FALSE);
19928N/A
9135N/A+#ifndef __sun
19928N/A if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(check_presenv)))
19928N/A gksu_context_set_keep_env (context, TRUE);
19928N/A else
19928N/A gksu_context_set_keep_env (context, FALSE);
9135N/A+#endif
19928N/A
19928N/A gtk_widget_destroy (dialog);
19928N/A }
19928N/A@@ -334,8 +364,15 @@ fill_with_user_list(GtkWidget *combobox)
19928N/A endpwent();
9135N/A }
19928N/A
19928N/A+static gboolean
19928N/A+focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
19928N/A+{
19928N/A+ gtk_window_present (GTK_WINDOW(widget));
19928N/A+ return TRUE;
19928N/A+}
19928N/A+
19928N/A void
19928N/A-request_command_and_user (GksuContext *context)
19928N/A+request_command_and_user (GksuContext *context, gchar *command)
19928N/A {
19928N/A GtkWidget *dialog;
19928N/A GtkWidget *hbox;
19928N/A@@ -347,7 +384,12 @@ request_command_and_user (GksuContext *c
19928N/A GtkWidget *entry_cmd;
8595N/A
19928N/A GtkWidget *label_user;
19928N/A- GtkWidget *combo_user;
19928N/A+ GtkWidget *entry_user;
19928N/A+
19928N/A+ AtkObject *atk_user_label;
19928N/A+ AtkObject *atk_user_entry;
19928N/A+ AtkObject *atk_command_label;
19928N/A+ AtkObject *atk_command_entry;
19928N/A
19928N/A /* advanced stuff */
19928N/A GtkWidget *advanced_button;
19928N/A@@ -362,6 +404,11 @@ request_command_and_user (GksuContext *c
19928N/A GTK_STOCK_OK,
19928N/A GTK_RESPONSE_OK,
19928N/A NULL);
19928N/A+
19928N/A+ /* make sure that our window will always have the focus */
19928N/A+ g_signal_connect (G_OBJECT(dialog), "focus-out-event",
19928N/A+ G_CALLBACK(focus_out_cb), NULL);
19928N/A+
19928N/A gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
19928N/A
19928N/A /* horizontal box */
19928N/A@@ -385,14 +432,44 @@ request_command_and_user (GksuContext *c
19928N/A dialog);
19928N/A gtk_box_pack_start (GTK_BOX(lvbox), entry_cmd, TRUE, TRUE, 0);
8595N/A
19928N/A+ if (command)
19928N/A+ {
19928N/A+ gtk_entry_set_text (GTK_ENTRY (entry_cmd), command);
19928N/A+ gtk_editable_set_editable (GTK_EDITABLE (entry_cmd), FALSE);
19928N/A+ gtk_widget_set_sensitive (entry_cmd, FALSE);
19928N/A+ }
19928N/A+
19928N/A+ atk_command_label = gtk_widget_get_accessible (label_cmd);
19928N/A+ atk_command_entry = gtk_widget_get_accessible (entry_cmd);
19928N/A+ atk_object_add_relationship (atk_command_label, ATK_RELATION_LABEL_FOR,
19928N/A+ atk_command_entry);
19928N/A+ atk_object_add_relationship (atk_command_entry, ATK_RELATION_LABELLED_BY,
19928N/A+ atk_command_label);
19928N/A+
19928N/A /* user name */
19928N/A- label_user = gtk_label_new (_("As user:"));
19928N/A+ /* SUN_BRANDING label */
19928N/A+ label_user = gtk_label_new (_("As user or role:"));
19928N/A gtk_label_set_justify (GTK_LABEL(label_user), GTK_JUSTIFY_LEFT);
19928N/A gtk_box_pack_start (GTK_BOX(lvbox), label_user, TRUE, TRUE, 0);
19928N/A- combo_user = gtk_combo_box_new_text ();
19928N/A- fill_with_user_list (combo_user);
19928N/A
19928N/A- gtk_box_pack_start (GTK_BOX(lvbox), combo_user, TRUE, TRUE, 0);
19928N/A+ entry_user = gtk_entry_new ();
19928N/A+ gtk_signal_connect (GTK_OBJECT(entry_user), "activate",
19928N/A+ GTK_SIGNAL_FUNC(response_ok_cb),
19928N/A+ dialog);
8595N/A+
19928N/A+ if (context->user)
19928N/A+ {
19928N/A+ gtk_entry_set_text (GTK_ENTRY (entry_user), context->user);
19928N/A+ }
19928N/A+
19928N/A+ atk_user_label = gtk_widget_get_accessible (label_user);
19928N/A+ atk_user_entry = gtk_widget_get_accessible (entry_user);
19928N/A+ atk_object_add_relationship (atk_user_label, ATK_RELATION_LABEL_FOR,
19928N/A+ atk_user_entry);
19928N/A+ atk_object_add_relationship (atk_user_entry, ATK_RELATION_LABELLED_BY,
19928N/A+ atk_user_label);
19928N/A+
19928N/A+ gtk_box_pack_start (GTK_BOX(lvbox), entry_user, TRUE, TRUE, 0);
19928N/A
19928N/A /* right vertical box */
19928N/A rvbox = gtk_vbox_new (FALSE, 2);
19928N/A@@ -430,18 +507,14 @@ request_command_and_user (GksuContext *c
19928N/A g_free (tmp);
19928N/A }
19928N/A
19928N/A- tmp = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo_user));
19928N/A+ tmp = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_user)));
19928N/A if (tmp)
19928N/A {
19928N/A gksu_context_set_user (context, tmp);
19928N/A g_free (tmp);
19928N/A }
19928N/A
19928N/A- if (!strcmp (gksu_context_get_user (context), ""))
19928N/A- {
19928N/A- gk_dialog (GTK_MESSAGE_ERROR, _("Missing command to run."));
19928N/A- }
19928N/A- else
19928N/A+ if (strcmp (gksu_context_get_user (context), ""))
19928N/A {
19928N/A gtk_widget_destroy (dialog);
19928N/A break;
19928N/A@@ -465,7 +538,7 @@ main (int argc, char **argv)
19928N/A
8595N/A int c = 0;
8595N/A
8595N/A- setlocale (LC_ALL, "");
8595N/A+ setlocale (6, "");
19928N/A bindtextdomain(PACKAGE_NAME, LOCALEDIR);
8595N/A bind_textdomain_codeset (PACKAGE_NAME, "UTF-8");
8595N/A textdomain(PACKAGE_NAME);
19935N/A@@ -502,7 +575,13 @@ main (int argc, char **argv)
19935N/A gtk_init (&newargc, &newargv);
19935N/A
19935N/A context = gksu_context_new ();
19935N/A- while ((c = getopt_long(newargc, newargv, "?hu:lpm:kt:i:gdsSwP::aD:", long_opts, NULL))
19935N/A+ /*
20153N/A+ * First character is + since we want gksu to accept all arguments after the
20153N/A+ * first operand as part of the operand. So you can run
20153N/A+ * "gksu -u root command -x". Without the "+", getopt_long incorrectly
20153N/A+ * treats the "-x" as a gksu argument rather than a command argument.
19935N/A+ */
19935N/A+ while ((c = getopt_long(newargc, newargv, "+?hu:lpm:kt:i:gdsSwP::aD:", long_opts, NULL))
19935N/A != EOF)
19935N/A {
19935N/A switch (c)
19935N/A@@ -525,14 +604,20 @@ main (int argc, char **argv)
9135N/A gksu_context_set_login_shell (context, TRUE);
9135N/A break;
9135N/A case 'p':
9135N/A+#ifndef __sun
9135N/A print_pass = TRUE;
9135N/A+#else
9135N/A+ gksu_context_set_elevated_privilege (context, FALSE);
9135N/A+#endif
9135N/A break;
19928N/A case 'm':
19928N/A gksu_context_set_message (context, optarg);
9135N/A break;
9135N/A+#ifndef __sun
9135N/A case 'k':
9135N/A gksu_context_set_keep_env (context, TRUE);
9135N/A break;
9135N/A+#endif
9135N/A case 'g':
19928N/A gksu_context_set_grab (context, FALSE);
9135N/A
19935N/A@@ -565,6 +650,9 @@ main (int argc, char **argv)
19928N/A case 'w':
19928N/A run_mode = SU_MODE;
9135N/A break;
19928N/A+ case 'r':
19928N/A+ gksu_context_set_elevated_role (context, FALSE);
9135N/A+ break;
19928N/A case 'P':
19928N/A prompt = TRUE;
19928N/A
19935N/A@@ -646,9 +734,14 @@ main (int argc, char **argv)
19928N/A return 0;
19928N/A }
19928N/A
19928N/A+ if (gksu_context_get_pfexec_mode (context))
19928N/A+ {
19928N/A+ gksu_context_set_need_pipe (context, FALSE);
19928N/A+ }
19928N/A+
19928N/A /* now we can begin to care about a command */
19928N/A if (newargc <= optind)
19928N/A- request_command_and_user (context); /* previously known as gksuexec */
19928N/A+ request_command_and_user (context, NULL); /* previously known as gksuexec */
19928N/A else
19928N/A {
19928N/A gchar *command = g_strdup (newargv[optind]);
20153N/A@@ -693,7 +786,27 @@ main (int argc, char **argv)
19928N/A g_free (command);
19928N/A command = tmp;
9135N/A }
19928N/A- gksu_context_set_command (context, command);
19928N/A+
19935N/A+ context->command = g_strdup (command);
20153N/A+
20153N/A+ if (strcmp (g_get_user_name (), "root") == 0)
20153N/A+ {
20153N/A+ /* If root, just use pfexec */
20153N/A+ context->pfexec_mode = TRUE;
20153N/A+ context->user = g_strdup ("root");
20153N/A+ }
20153N/A+ else if (run_mode != SUDO_MODE)
20153N/A+ {
20153N/A+ if (gksu_context_try_need_password (context))
20153N/A+ {
20153N/A+ request_command_and_user (context, command);
20153N/A+ }
20153N/A+ }
20153N/A+ else
19935N/A+ {
19935N/A+ request_command_and_user (context, command);
19935N/A+ }
19928N/A+
19928N/A g_free (command);
9135N/A }
9135N/A
20153N/A@@ -714,7 +827,8 @@ main (int argc, char **argv)
19935N/A return 1;
19935N/A }
19935N/A
19935N/A- if (pwentry->pw_uid == geteuid ())
19935N/A+ /* If in pfexec mode, process in gksu_sudo_fuller */
19935N/A+ if (!gksu_context_get_pfexec_mode (context) && pwentry->pw_uid == geteuid ())
19935N/A {
19935N/A gint retval = g_spawn_command_line_sync (gksu_context_get_command (context),
19935N/A NULL, NULL, NULL, NULL);
20153N/A@@ -722,18 +836,6 @@ main (int argc, char **argv)
19928N/A }
19928N/A }
15173N/A
19928N/A- {
19928N/A- gint count = 0;
19928N/A-
19928N/A- for (count = 0; count < 3; count++)
19928N/A- {
19928N/A- if (error) /* wrong password was given */
19928N/A- {
19928N/A- gksu_context_set_alert (context, _("<b>Incorrect password... try again.</b>"));
19928N/A- g_error_free (error);
19928N/A- error = NULL;
19928N/A- }
19928N/A-
19928N/A if (run_mode == SUDO_MODE)
19928N/A gksu_sudo_fuller (context,
19928N/A NULL, NULL,
20153N/A@@ -753,18 +855,25 @@ main (int argc, char **argv)
19928N/A NULL, NULL,
19928N/A &exit_status,
19928N/A &error);
19928N/A- if ((error == NULL) || (error->code != GKSU_ERROR_WRONGPASS))
19928N/A- break;
19928N/A- }
19928N/A- }
19928N/A
19928N/A if (error && (error->code != GKSU_ERROR_CANCELED))
19928N/A {
19928N/A+ char *msg;
15173N/A+
19928N/A+ if (context->alert != NULL)
19928N/A+ {
19928N/A+ msg = context->alert;
19928N/A+ }
19928N/A+ else
18566N/A+ {
19928N/A+ msg = error->message;
18566N/A+ }
19928N/A+
19928N/A gk_dialog (GTK_MESSAGE_ERROR,
19928N/A _("<b>Failed to run %s as user %s.</b>\n\n%s"),
19928N/A gksu_context_get_command (context),
19928N/A gksu_context_get_user (context),
19928N/A- error->message);
19928N/A+ msg);
19928N/A return 3;
19928N/A }
8595N/A