Ticket #70: xauth.patch
| File xauth.patch, 5.9 kB (added by Jan-Nik, 5 months ago) |
|---|
-
old/main/libexec/autosu.c
old new 36 36 static char *helper_exe[2]; 37 37 static int xauth_id = -1; 38 38 39 static int load_xauth ( );39 static int load_xauth (gboolean *error); 40 40 41 41 42 42 static gboolean … … 62 62 63 63 if (system ("grep -q pam_xauth /etc/pam.d/su 2>/dev/null") != 0) { 64 64 /* Su doesn't use the pam_xauth module; setup xauth stuff */ 65 xauth_id = load_xauth (); 65 gboolean error_occurred = FALSE; 66 xauth_id = load_xauth (&error_occurred); 67 if (error_occurred) { 68 g_set_error (error, 0, 0, _("Unable to load xauth.")); 69 return FALSE; 70 } 66 71 } 67 72 68 73 return TRUE; … … 242 247 243 248 /* Return a shmid for a segment containing the X authentication tokens for this system */ 244 249 static int 245 load_xauth ( )250 load_xauth (gboolean *error) 246 251 { 247 252 char *command, *deststr; 248 253 FILE *in; 249 254 #define BUFSIZE 1024 * 5 250 255 void *buffer; 251 256 GString *str; 252 int shmid ;257 int shmid = -1; /* If an error occurs return -1 */ 253 258 254 259 /* Run 'xauth list' and get it's output */ 255 260 command = g_strdup_printf ("%s list", get_xauth_path ()); … … 258 263 259 264 if (in == NULL) { 260 265 perror ("could not run xauth"); 261 exit (EXIT_SYSERROR); 262 } 266 *error = TRUE; 267 return -1; 268 } 263 269 264 270 buffer = malloc (BUFSIZE); /* unlikely a token line will go >5k chars */ 265 271 str = g_string_new (""); … … 271 277 272 278 if (pclose (in) != 0) { 273 279 perror ("could not run xauth, pclose != 0"); 274 exit (EXIT_SYSERROR); 275 } 276 277 /* Now we need to move the buffer to a shared memory segment */ 278 shmid = shmget (IPC_PRIVATE, str->len + 1, IPC_CREAT | IPC_EXCL | 0666); 279 if (shmid == -1) { 280 perror ("could not generate shared memory segment for X authentication tokens"); 281 exit (EXIT_SYSERROR); 282 } 283 284 deststr = shmat (shmid, NULL, 0); 285 if (deststr == (char *) - 1) { 286 perror ("could not attach to shared memory segment for X authentication tokens"); 287 exit (EXIT_SYSERROR); 280 *error = TRUE; 288 281 } 282 else { 283 /* Now we need to move the buffer to a shared memory segment */ 284 shmid = shmget (IPC_PRIVATE, str->len + 1, IPC_CREAT | IPC_EXCL | 0666); 285 if (shmid == -1) { 286 perror ("could not generate shared memory segment for X authentication tokens"); 287 *error = TRUE; 288 } 289 else { 290 deststr = shmat (shmid, NULL, 0); 291 if (deststr == (char *) - 1) { 292 perror ("could not attach to shared memory segment for X authentication tokens"); 293 *error = TRUE; 294 } 295 else { 296 strcpy (deststr, str->str); 297 } 298 } 299 } /* Do not return before we haven't freed str */ 289 300 290 strcpy (deststr, str->str);291 301 g_string_free (str, TRUE); 292 302 return shmid; 293 303 } -
old/main/libexec/autosu-gtk.c
old new 70 70 gtk_entry_set_text (GTK_ENTRY (entry), ""); 71 71 } 72 72 73 void 74 show_dialog (GtkMessageType type, GtkButtonsType buttons, gchar *msg) 75 { 76 gdk_threads_enter (); 77 GtkWidget *dialog = gtk_message_dialog_new ((GtkWindow *) GUI.win, 78 GTK_DIALOG_MODAL, 79 type, 80 buttons, 81 "%s", msg); 82 gtk_dialog_run (GTK_DIALOG (dialog)); 83 gtk_widget_destroy (dialog); 84 gdk_threads_leave (); 85 } 73 86 74 87 void 75 88 show_error (gchar *format, ...) 76 89 { 77 GtkWidget *dialog;78 90 va_list ap; 79 91 gchar *msg; 80 92 … … 82 94 msg = g_strdup_vprintf (format, ap); 83 95 va_end (ap); 84 96 85 gdk_threads_enter (); 86 dialog = gtk_message_dialog_new ((GtkWindow *) GUI.win, 87 GTK_DIALOG_MODAL, 88 GTK_MESSAGE_ERROR, 89 GTK_BUTTONS_CLOSE, 90 "%s", msg); 91 gtk_dialog_run (GTK_DIALOG (dialog)); 92 gtk_widget_destroy (dialog); 93 gdk_threads_leave (); 97 show_dialog (GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, msg); 94 98 } 95 99 96 100 … … 658 662 exit (EXIT_CANCEL); 659 663 } 660 664 665 static int 666 exit_nopasswd (const gchar *message) 667 { 668 show_error (_("An error occured while trying to ask the user for the password: %s\n"), message); 669 show_dialog (GTK_MESSAGE_INFO, GTK_BUTTONS_OK, _("Attempting to continue without asking for password...\n")); 670 return EXIT_NOPASSWD; 671 } 661 672 662 673 int main (int argc, char *argv[]) 663 674 { … … 696 707 697 708 child_command = autosu_child_command (command, &error); 698 709 if (child_command == NULL) { 699 show_error ("%s", error->message); 700 return EXIT_SYSERROR; 710 return exit_nopasswd (error->message); 701 711 } 702 712 703 713 ret = su_needs_password (user, &error); 704 714 if (ret == -1) { 705 715 /* An error occured */ 706 fprintf (stderr, _("An error occured while trying to ask the user for the password: %s\n"), error->message); 707 fprintf (stderr, _("Attempting to continue without asking for password...\n")); 708 return EXIT_NOPASSWD; 716 return exit_nopasswd (error->message); 709 717 710 718 } else if (ret == 0) { 711 719 /* No password required for this account. */ -
old/main/libexec/autosu-tui.c
old new 316 316 exit (EXIT_CANCEL); 317 317 } 318 318 319 static int 320 exit_nopasswd (const gchar *message) 321 { 322 fprintf (stderr, _("An error occured while trying to ask the user for the password: %s\n"), message); 323 fprintf (stderr, _("Attempting to continue without asking for password...\n")); 324 return EXIT_NOPASSWD; 325 } 319 326 320 327 int main (int argc, char *argv[]) 321 328 { … … 353 360 /* Initialize autosu core */ 354 361 child_command = autosu_child_command (command, &error); 355 362 if (child_command == NULL) { 356 show_error ("%s", error->message); 357 return EXIT_SYSERROR; 363 return exit_nopasswd (error->message); 358 364 } 359 365 360 366 ret = su_needs_password (user, &error); 361 367 if (ret == -1) { 362 368 /* An error occured */ 363 fprintf (stderr, _("An error occured while trying to ask the user for the password: %s\n"), error->message); 364 fprintf (stderr, _("Attempting to continue without asking for password...\n")); 365 return EXIT_NOPASSWD; 369 return exit_nopasswd (error->message); 366 370 367 371 } else if (ret == 0) { 368 372 /* No password required for this account. */
