Changeset 2434

Show
Ignore:
Timestamp:
04/06/08 14:59:10 (8 months ago)
Author:
isak
Message:

Applied patch from Jan Nicklas Hasse that doesn't kill autosu when it fails to load xauth. This will allow autopackage to continue with local installation. Fixes ticket #70.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • main/trunk/libexec/autosu-gtk.c

    r2433 r2434  
    7171} 
    7272 
    73  
    7473void 
    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  
     74show_dialog (GtkMessageType type, GtkButtonsType buttons, gchar *msg) 
     75
    8576        gdk_threads_enter (); 
    86         dialog = gtk_message_dialog_new ((GtkWindow *) GUI.win, 
     77        GtkWidget *dialog = gtk_message_dialog_new ((GtkWindow *) GUI.win, 
    8778                GTK_DIALOG_MODAL, 
    88                 GTK_MESSAGE_ERROR
    89                 GTK_BUTTONS_CLOSE
     79                type
     80                buttons
    9081                "%s", msg); 
    9182        gtk_dialog_run (GTK_DIALOG (dialog)); 
    9283        gtk_widget_destroy (dialog); 
    9384        gdk_threads_leave (); 
     85} 
     86 
     87void 
     88show_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); 
    9498} 
    9599 
     
    659663} 
    660664 
     665static int 
     666exit_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} 
    661672 
    662673int main (int argc, char *argv[]) 
     
    699710        child_command = autosu_child_command (command, &error); 
    700711        if (child_command == NULL) { 
    701                 show_error ("%s", error->message); 
    702                 return EXIT_SYSERROR; 
     712                return exit_nopasswd (error->message); 
    703713        } 
    704714 
     
    706716        if (ret == -1) { 
    707717                /* 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); 
    711719 
    712720        } else if (ret == 0) { 
  • main/trunk/libexec/autosu-tui.c

    r2433 r2434  
    317317} 
    318318 
     319static int 
     320exit_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} 
    319326 
    320327int main (int argc, char *argv[]) 
     
    356363        child_command = autosu_child_command (command, &error); 
    357364        if (child_command == NULL) { 
    358                 show_error ("%s", error->message); 
    359                 return EXIT_SYSERROR; 
     365                return exit_nopasswd (error->message); 
    360366        } 
    361367 
     
    363369        if (ret == -1) { 
    364370                /* 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); 
    368372 
    369373        } else if (ret == 0) { 
  • main/trunk/libexec/autosu.c

    r1641 r2434  
    3737static int xauth_id = -1; 
    3838 
    39 static int load_xauth (); 
     39static int load_xauth (gboolean *error); 
    4040 
    4141 
     
    6363        if (system ("grep -q pam_xauth /etc/pam.d/su 2>/dev/null") != 0) { 
    6464                /* 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                } 
    6671        } 
    6772 
     
    243248/* Return a shmid for a segment containing the X authentication tokens for this system */ 
    244249static int 
    245 load_xauth (
     250load_xauth (gboolean *error
    246251{ 
    247252        char *command, *deststr; 
     
    250255        void *buffer; 
    251256        GString *str; 
    252         int shmid; 
     257        int shmid = -1; /* If an error occurs return -1 */ 
    253258 
    254259        /* Run 'xauth list' and get it's output */ 
     
    259264        if (in == NULL) { 
    260265                perror ("could not run xauth"); 
    261                 exit (EXIT_SYSERROR); 
    262         } 
     266                *error = TRUE; 
     267                return -1; 
     268        } 
    263269 
    264270        buffer = malloc (BUFSIZE);      /* unlikely a token line will go >5k chars */ 
     
    272278        if (pclose (in) != 0) { 
    273279                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 
    291301        g_string_free (str, TRUE); 
    292302        return shmid;