rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / desktop / gksu / patches / gksu-02-gksu.patch
blob6cff18516113dbf7fd537f8e3186feeeb3792fea
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
3 @@ -9,6 +9,8 @@
4 #include <string.h>
5 #include <getopt.h>
6 #include <locale.h>
7 +#include <dlfcn.h>
8 +#include <link.h>
10 #include <glib.h>
11 #include <glib/gstdio.h>
12 @@ -27,6 +29,9 @@
13 gboolean print_pass = FALSE;
14 gboolean force_grab = FALSE;
15 gboolean prompt = FALSE;
16 +gboolean elevated_privilege = TRUE;
17 +gboolean elevated_role = TRUE;
19 enum
21 SUDO_MODE,
22 @@ -40,10 +45,14 @@ struct option long_opts[] = {
24 {"help", no_argument, NULL, 'h'},
25 {"login", no_argument, NULL, 'l'},
26 +#ifndef __sun
27 {"preserv-env", no_argument, NULL, 'k'},
28 {"preserve-env", no_argument, NULL, 'k'},
29 +#endif
30 {"user", required_argument, NULL, 'u'},
31 +#ifndef __sun
32 {"print-pass", no_argument, NULL, 'p'},
33 +#endif
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'},
43 {0, 0, 0, 0}
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"),
50 +#ifndef __sun
51 N_("\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"
56 " stdin.\n"),
57 +#endif
58 N_("\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)
62 N_(" --su-mode, -w\n"
63 " Make GKSu use su, instead of using libgksu's\n"
64 " default.\n"),
65 +#ifdef __sun
66 + N_("\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"),
71 +#endif
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);
84 + // reset cursor
85 + gdk_window_set_cursor(diag_win->window, gdk_cursor_new(GDK_LEFT_PTR));
87 gtk_dialog_run (GTK_DIALOG(diag_win));
89 g_free (msg);
90 @@ -271,10 +299,12 @@ show_hide_advanced (GtkWidget *button, g
91 else
92 gksu_context_set_login_shell (context, FALSE);
94 +#ifndef __sun
95 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(check_presenv)))
96 gksu_context_set_keep_env (context, TRUE);
97 else
98 gksu_context_set_keep_env (context, FALSE);
99 +#endif
101 gtk_widget_destroy (dialog);
103 @@ -334,8 +364,15 @@ fill_with_user_list(GtkWidget *combobox)
104 endpwent();
107 +static gboolean
108 +focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
110 + gtk_window_present (GTK_WINDOW(widget));
111 + return TRUE;
114 void
115 -request_command_and_user (GksuContext *context)
116 +request_command_and_user (GksuContext *context, gchar *command)
118 GtkWidget *dialog;
119 GtkWidget *hbox;
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;
132 /* advanced stuff */
133 GtkWidget *advanced_button;
134 @@ -362,6 +404,11 @@ request_command_and_user (GksuContext *c
135 GTK_STOCK_OK,
136 GTK_RESPONSE_OK,
137 NULL);
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);
145 /* horizontal box */
146 @@ -385,14 +432,44 @@ request_command_and_user (GksuContext *c
147 dialog);
148 gtk_box_pack_start (GTK_BOX(lvbox), entry_cmd, TRUE, TRUE, 0);
150 + if (command)
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);
164 /* user name */
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),
177 + dialog);
179 + if (context->user)
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,
187 + atk_user_entry);
188 + atk_object_add_relationship (atk_user_entry, ATK_RELATION_LABELLED_BY,
189 + atk_user_label);
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
196 g_free (tmp);
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)));
201 if (tmp)
203 gksu_context_set_user (context, tmp);
204 g_free (tmp);
207 - if (!strcmp (gksu_context_get_user (context), ""))
209 - gk_dialog (GTK_MESSAGE_ERROR, _("Missing command to run."));
211 - else
212 + if (strcmp (gksu_context_get_user (context), ""))
214 gtk_widget_destroy (dialog);
215 break;
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))
221 + /*
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.
226 + */
227 + while ((c = getopt_long(newargc, newargv, "+?hu:lpm:kt:i:gdsSwP::aD:", long_opts, NULL))
228 != EOF)
230 switch (c)
231 @@ -525,14 +604,20 @@ main (int argc, char **argv)
232 gksu_context_set_login_shell (context, TRUE);
233 break;
234 case 'p':
235 +#ifndef __sun
236 print_pass = TRUE;
237 +#else
238 + gksu_context_set_elevated_privilege (context, FALSE);
239 +#endif
240 break;
241 case 'm':
242 gksu_context_set_message (context, optarg);
243 break;
244 +#ifndef __sun
245 case 'k':
246 gksu_context_set_keep_env (context, TRUE);
247 break;
248 +#endif
249 case 'g':
250 gksu_context_set_grab (context, FALSE);
252 @@ -565,6 +650,9 @@ main (int argc, char **argv)
253 case 'w':
254 run_mode = SU_MODE;
255 break;
256 + case 'r':
257 + gksu_context_set_elevated_role (context, FALSE);
258 + break;
259 case 'P':
260 prompt = TRUE;
262 @@ -646,9 +734,14 @@ main (int argc, char **argv)
263 return 0;
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 */
275 else
277 gchar *command = g_strdup (newargv[optind]);
278 @@ -693,7 +786,27 @@ main (int argc, char **argv)
279 g_free (command);
280 command = tmp;
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);
299 + else
301 + request_command_and_user (context, command);
304 g_free (command);
307 @@ -714,7 +827,8 @@ main (int argc, char **argv)
308 return 1;
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)
322 - gint count = 0;
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);
330 - error = NULL;
333 if (run_mode == SUDO_MODE)
334 gksu_sudo_fuller (context,
335 NULL, NULL,
336 @@ -753,18 +855,25 @@ main (int argc, char **argv)
337 NULL, NULL,
338 &exit_status,
339 &error);
340 - if ((error == NULL) || (error->code != GKSU_ERROR_WRONGPASS))
341 - break;
345 if (error && (error->code != GKSU_ERROR_CANCELED))
347 + char *msg;
349 + if (context->alert != NULL)
351 + msg = context->alert;
353 + else
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),
362 - error->message);
363 + msg);
364 return 3;