1 --- gksu-2.0.2/gksu/gksu.c-orig 2010-12-16 03:43:51.275486079 -0600
2 +++ gksu-2.0.2/gksu/gksu.c 2010-12-16 03:46:11.151315385 -0600
11 #include <glib/gstdio.h>
13 gboolean print_pass = FALSE;
14 gboolean force_grab = FALSE;
15 gboolean prompt = FALSE;
16 +gboolean elevated_privilege = TRUE;
17 +gboolean elevated_role = TRUE;
22 @@ -40,10 +45,14 @@ struct option long_opts[] = {
24 {"help", no_argument, NULL, 'h'},
25 {"login", no_argument, NULL, 'l'},
27 {"preserv-env", no_argument, NULL, 'k'},
28 {"preserve-env", no_argument, NULL, 'k'},
30 {"user", required_argument, NULL, 'u'},
32 {"print-pass", no_argument, NULL, 'p'},
34 {"message", required_argument, NULL, 'm'},
35 {"title", required_argument, NULL, 't'},
36 {"icon", required_argument, NULL, 'i'},
37 @@ -55,6 +64,8 @@ struct option long_opts[] = {
38 {"prompt", optional_argument, NULL, 'P'},
39 {"desktop", required_argument, NULL, 'D'},
40 {"description", required_argument, NULL, 'D'},
41 + {"elevated-privilege", no_argument, NULL, 'p'},
42 + {"elevated-role", no_argument, NULL, 'r'},
46 @@ -106,12 +117,14 @@ help (gchar *cmdname)
47 " Replace the standard message shown to ask for\n"
48 " password for the argument passed to the option.\n"
49 " Only use this if --description does not suffice.\n"),
52 N_(" --print-pass, -p\n"
53 " Ask gksu to print the password to stdout, just\n"
54 " like ssh-askpass. Useful to use in scripts with\n"
55 " programs that accept receiving the password on\n"
59 N_(" --sudo-mode, -S\n"
60 " Make GKSu use sudo instead of su, as if it had been\n"
61 @@ -119,6 +132,13 @@ help (gchar *cmdname)
63 " Make GKSu use su, instead of using libgksu's\n"
67 + N_(" --elevated-privilege, -p\n"
68 + " attempt to elevate user's privilege\n"),
69 + N_(" --elevated-role, -r\n"
70 + " attempt to elevate user's role\n"),
74 help_trans = g_strconcat(_(help_text[0]), _(help_text[1]),
75 @@ -157,6 +177,14 @@ gk_dialog (GtkMessageType type, gchar *f
76 gtk_window_set_resizable (GTK_WINDOW(diag_win), FALSE);
78 gtk_widget_show_all (diag_win);
80 + // we "raise" the window because there is a race here for
81 + // focus-follow-mouse and auto-raise WMs that may put the window
82 + // in the background and confuse users
83 + gtk_window_set_keep_above(GTK_WINDOW (diag_win), TRUE);
85 + gdk_window_set_cursor(diag_win->window, gdk_cursor_new(GDK_LEFT_PTR));
87 gtk_dialog_run (GTK_DIALOG(diag_win));
90 @@ -271,10 +299,12 @@ show_hide_advanced (GtkWidget *button, g
92 gksu_context_set_login_shell (context, FALSE);
95 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(check_presenv)))
96 gksu_context_set_keep_env (context, TRUE);
98 gksu_context_set_keep_env (context, FALSE);
101 gtk_widget_destroy (dialog);
103 @@ -334,8 +364,15 @@ fill_with_user_list(GtkWidget *combobox)
108 +focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
110 + gtk_window_present (GTK_WINDOW(widget));
115 -request_command_and_user (GksuContext *context)
116 +request_command_and_user (GksuContext *context, gchar *command)
120 @@ -347,7 +384,12 @@ request_command_and_user (GksuContext *c
121 GtkWidget *entry_cmd;
123 GtkWidget *label_user;
124 - GtkWidget *combo_user;
125 + GtkWidget *entry_user;
127 + AtkObject *atk_user_label;
128 + AtkObject *atk_user_entry;
129 + AtkObject *atk_command_label;
130 + AtkObject *atk_command_entry;
133 GtkWidget *advanced_button;
134 @@ -362,6 +404,11 @@ request_command_and_user (GksuContext *c
139 + /* make sure that our window will always have the focus */
140 + g_signal_connect (G_OBJECT(dialog), "focus-out-event",
141 + G_CALLBACK(focus_out_cb), NULL);
143 gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
146 @@ -385,14 +432,44 @@ request_command_and_user (GksuContext *c
148 gtk_box_pack_start (GTK_BOX(lvbox), entry_cmd, TRUE, TRUE, 0);
152 + gtk_entry_set_text (GTK_ENTRY (entry_cmd), command);
153 + gtk_editable_set_editable (GTK_EDITABLE (entry_cmd), FALSE);
154 + gtk_widget_set_sensitive (entry_cmd, FALSE);
157 + atk_command_label = gtk_widget_get_accessible (label_cmd);
158 + atk_command_entry = gtk_widget_get_accessible (entry_cmd);
159 + atk_object_add_relationship (atk_command_label, ATK_RELATION_LABEL_FOR,
160 + atk_command_entry);
161 + atk_object_add_relationship (atk_command_entry, ATK_RELATION_LABELLED_BY,
162 + atk_command_label);
165 - label_user = gtk_label_new (_("As user:"));
166 + /* SUN_BRANDING label */
167 + label_user = gtk_label_new (_("As user or role:"));
168 gtk_label_set_justify (GTK_LABEL(label_user), GTK_JUSTIFY_LEFT);
169 gtk_box_pack_start (GTK_BOX(lvbox), label_user, TRUE, TRUE, 0);
170 - combo_user = gtk_combo_box_new_text ();
171 - fill_with_user_list (combo_user);
173 - gtk_box_pack_start (GTK_BOX(lvbox), combo_user, TRUE, TRUE, 0);
174 + entry_user = gtk_entry_new ();
175 + gtk_signal_connect (GTK_OBJECT(entry_user), "activate",
176 + GTK_SIGNAL_FUNC(response_ok_cb),
181 + gtk_entry_set_text (GTK_ENTRY (entry_user), context->user);
184 + atk_user_label = gtk_widget_get_accessible (label_user);
185 + atk_user_entry = gtk_widget_get_accessible (entry_user);
186 + atk_object_add_relationship (atk_user_label, ATK_RELATION_LABEL_FOR,
188 + atk_object_add_relationship (atk_user_entry, ATK_RELATION_LABELLED_BY,
191 + gtk_box_pack_start (GTK_BOX(lvbox), entry_user, TRUE, TRUE, 0);
193 /* right vertical box */
194 rvbox = gtk_vbox_new (FALSE, 2);
195 @@ -430,18 +507,14 @@ request_command_and_user (GksuContext *c
199 - tmp = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo_user));
200 + tmp = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_user)));
203 gksu_context_set_user (context, tmp);
207 - if (!strcmp (gksu_context_get_user (context), ""))
209 - gk_dialog (GTK_MESSAGE_ERROR, _("Missing command to run."));
212 + if (strcmp (gksu_context_get_user (context), ""))
214 gtk_widget_destroy (dialog);
216 @@ -502,7 +575,13 @@ main (int argc, char **argv)
217 gtk_init (&newargc, &newargv);
219 context = gksu_context_new ();
220 - while ((c = getopt_long(newargc, newargv, "?hu:lpm:kt:i:gdsSwP::aD:", long_opts, NULL))
222 + * First character is + since we want gksu to accept all arguments after the
223 + * first operand as part of the operand. So you can run
224 + * "gksu -u root command -x". Without the "+", getopt_long incorrectly
225 + * treats the "-x" as a gksu argument rather than a command argument.
227 + while ((c = getopt_long(newargc, newargv, "+?hu:lpm:kt:i:gdsSwP::aD:", long_opts, NULL))
231 @@ -525,14 +604,20 @@ main (int argc, char **argv)
232 gksu_context_set_login_shell (context, TRUE);
238 + gksu_context_set_elevated_privilege (context, FALSE);
242 gksu_context_set_message (context, optarg);
246 gksu_context_set_keep_env (context, TRUE);
250 gksu_context_set_grab (context, FALSE);
252 @@ -565,6 +650,9 @@ main (int argc, char **argv)
257 + gksu_context_set_elevated_role (context, FALSE);
262 @@ -646,9 +734,14 @@ main (int argc, char **argv)
266 + if (gksu_context_get_pfexec_mode (context))
268 + gksu_context_set_need_pipe (context, FALSE);
271 /* now we can begin to care about a command */
272 if (newargc <= optind)
273 - request_command_and_user (context); /* previously known as gksuexec */
274 + request_command_and_user (context, NULL); /* previously known as gksuexec */
277 gchar *command = g_strdup (newargv[optind]);
278 @@ -693,7 +786,27 @@ main (int argc, char **argv)
282 - gksu_context_set_command (context, command);
284 + context->command = g_strdup (command);
286 + if (strcmp (g_get_user_name (), "root") == 0)
288 + /* If root, just use pfexec */
289 + context->pfexec_mode = TRUE;
290 + context->user = g_strdup ("root");
292 + else if (run_mode != SUDO_MODE)
294 + if (gksu_context_try_need_password (context))
296 + request_command_and_user (context, command);
301 + request_command_and_user (context, command);
307 @@ -714,7 +827,8 @@ main (int argc, char **argv)
311 - if (pwentry->pw_uid == geteuid ())
312 + /* If in pfexec mode, process in gksu_sudo_fuller */
313 + if (!gksu_context_get_pfexec_mode (context) && pwentry->pw_uid == geteuid ())
315 gint retval = g_spawn_command_line_sync (gksu_context_get_command (context),
316 NULL, NULL, NULL, NULL);
317 @@ -722,18 +836,6 @@ main (int argc, char **argv)
324 - for (count = 0; count < 3; count++)
326 - if (error) /* wrong password was given */
328 - gksu_context_set_alert (context, _("<b>Incorrect password... try again.</b>"));
329 - g_error_free (error);
333 if (run_mode == SUDO_MODE)
334 gksu_sudo_fuller (context,
336 @@ -753,18 +855,25 @@ main (int argc, char **argv)
340 - if ((error == NULL) || (error->code != GKSU_ERROR_WRONGPASS))
345 if (error && (error->code != GKSU_ERROR_CANCELED))
349 + if (context->alert != NULL)
351 + msg = context->alert;
355 + msg = error->message;
358 gk_dialog (GTK_MESSAGE_ERROR,
359 _("<b>Failed to run %s as user %s.</b>\n\n%s"),
360 gksu_context_get_command (context),
361 gksu_context_get_user (context),