Changeset 2434
- Timestamp:
- 04/06/08 14:59:10 (8 months ago)
- Files:
-
- main/trunk/libexec/autosu-gtk.c (modified) (4 diffs)
- main/trunk/libexec/autosu-tui.c (modified) (3 diffs)
- main/trunk/libexec/autosu.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
main/trunk/libexec/autosu-gtk.c
r2433 r2434 71 71 } 72 72 73 74 73 void 75 show_error (gchar *format, ...) 76 { 77 GtkWidget *dialog; 78 va_list ap; 79 gchar *msg; 80 81 va_start (ap, format); 82 msg = g_strdup_vprintf (format, ap); 83 va_end (ap); 84 74 show_dialog (GtkMessageType type, GtkButtonsType buttons, gchar *msg) 75 { 85 76 gdk_threads_enter (); 86 dialog = gtk_message_dialog_new ((GtkWindow *) GUI.win,77 GtkWidget *dialog = gtk_message_dialog_new ((GtkWindow *) GUI.win, 87 78 GTK_DIALOG_MODAL, 88 GTK_MESSAGE_ERROR,89 GTK_BUTTONS_CLOSE,79 type, 80 buttons, 90 81 "%s", msg); 91 82 gtk_dialog_run (GTK_DIALOG (dialog)); 92 83 gtk_widget_destroy (dialog); 93 84 gdk_threads_leave (); 85 } 86 87 void 88 show_error (gchar *format, ...) 89 { 90 va_list ap; 91 gchar *msg; 92 93 va_start (ap, format); 94 msg = g_strdup_vprintf (format, ap); 95 va_end (ap); 96 97 show_dialog (GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, msg); 94 98 } 95 99 … … 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[]) … … 699 710 child_command = autosu_child_command (command, &error); 700 711 if (child_command == NULL) { 701 show_error ("%s", error->message); 702 return EXIT_SYSERROR; 712 return exit_nopasswd (error->message); 703 713 } 704 714 … … 706 716 if (ret == -1) { 707 717 /* An error occured */ 708 fprintf (stderr, _("An error occured while trying to ask the user for the password: %s\n"), error->message); 709 fprintf (stderr, _("Attempting to continue without asking for password...\n")); 710 return EXIT_NOPASSWD; 718 return exit_nopasswd (error->message); 711 719 712 720 } else if (ret == 0) { main/trunk/libexec/autosu-tui.c
r2433 r2434 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[]) … … 356 363 child_command = autosu_child_command (command, &error); 357 364 if (child_command == NULL) { 358 show_error ("%s", error->message); 359 return EXIT_SYSERROR; 365 return exit_nopasswd (error->message); 360 366 } 361 367 … … 363 369 if (ret == -1) { 364 370 /* An error occured */ 365 fprintf (stderr, _("An error occured while trying to ask the user for the password: %s\n"), error->message); 366 fprintf (stderr, _("Attempting to continue without asking for password...\n")); 367 return EXIT_NOPASSWD; 371 return exit_nopasswd (error->message); 368 372 369 373 } else if (ret == 0) { main/trunk/libexec/autosu.c
r1641 r2434 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 … … 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 … … 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; … … 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 */ … … 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 */ … … 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); 288 } 289 290 strcpy (deststr, str->str); 280 *error = TRUE; 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 */ 300 291 301 g_string_free (str, TRUE); 292 302 return shmid;
