Ticket #70: xauth.patch

File xauth.patch, 5.9 kB (added by Jan-Nik, 5 months ago)

continue as normal user if load_xauth fails

  • old/main/libexec/autosu.c

    old new  
    3636static char *helper_exe[2]; 
    3737static int xauth_id = -1; 
    3838 
    39 static int load_xauth (); 
     39static int load_xauth (gboolean *error); 
    4040 
    4141 
    4242static gboolean 
     
    6262 
    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 
    6873        return TRUE; 
     
    242247 
    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; 
    248253        FILE *in; 
    249254        #define BUFSIZE 1024 * 5 
    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 */ 
    255260        command = g_strdup_printf ("%s list", get_xauth_path ()); 
     
    258263 
    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 */ 
    265271        str = g_string_new (""); 
     
    271277 
    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); 
     280                *error = TRUE; 
    288281        } 
     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 */ 
    289300 
    290         strcpy (deststr, str->str); 
    291301        g_string_free (str, TRUE); 
    292302        return shmid; 
    293303} 
  • old/main/libexec/autosu-gtk.c

    old new  
    7070        gtk_entry_set_text (GTK_ENTRY (entry), ""); 
    7171} 
    7272 
     73void 
     74show_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} 
    7386 
    7487void 
    7588show_error (gchar *format, ...) 
    7689{ 
    77         GtkWidget *dialog; 
    7890        va_list ap; 
    7991        gchar *msg; 
    8092 
     
    8294        msg = g_strdup_vprintf (format, ap); 
    8395        va_end (ap); 
    8496 
    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); 
    9498} 
    9599 
    96100 
     
    658662        exit (EXIT_CANCEL); 
    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[]) 
    663674{ 
     
    696707 
    697708        child_command = autosu_child_command (command, &error); 
    698709        if (child_command == NULL) { 
    699                 show_error ("%s", error->message); 
    700                 return EXIT_SYSERROR; 
     710                return exit_nopasswd (error->message); 
    701711        } 
    702712 
    703713        ret = su_needs_password (user, &error); 
    704714        if (ret == -1) { 
    705715                /* 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); 
    709717 
    710718        } else if (ret == 0) { 
    711719                /* No password required for this account. */ 
  • old/main/libexec/autosu-tui.c

    old new  
    316316        exit (EXIT_CANCEL); 
    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[]) 
    321328{ 
     
    353360        /* Initialize autosu core */ 
    354361        child_command = autosu_child_command (command, &error); 
    355362        if (child_command == NULL) { 
    356                 show_error ("%s", error->message); 
    357                 return EXIT_SYSERROR; 
     363                return exit_nopasswd (error->message); 
    358364        } 
    359365 
    360366        ret = su_needs_password (user, &error); 
    361367        if (ret == -1) { 
    362368                /* 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); 
    366370 
    367371        } else if (ret == 0) { 
    368372                /* No password required for this account. */