~darkxst/ubuntu/saucy/gdm/lp1212408

« back to all changes in this revision

Viewing changes to daemon/errorgui.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2008-09-02 10:37:20 UTC
  • mfrom: (1.4.27 upstream)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: james.westby@ubuntu.com-20080902103720-p810vv530hqj45wg
Tags: 2.20.7-3
* Install the debian-moreblue-orbit theme, thanks Andre Luiz Rodrigues 
  Ferreira. Closes: #497440.
* 35_gdm.conf.patch: make it the default.
* copyright: fix encoding.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GDM - The GNOME Display Manager
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 *
 
3
 * GDM - The GNOME Display Manager
2
4
 * Copyright (C) 1998, 1999, 2000 Martin K. Petersen <mkp@mkp.net>
3
5
 *
4
6
 * This program is free software; you can redistribute it and/or modify
16
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
19
 */
18
20
 
19
 
/* This is the gdm slave process. gdmslave runs the chooser, greeter
20
 
 * and the user's session scripts. */
21
 
 
22
21
#include "config.h"
23
22
 
 
23
#include <stdlib.h>
24
24
#include <unistd.h>
25
 
#include <syslog.h>
 
25
#include <string.h>
26
26
#include <grp.h>
27
27
#include <sys/types.h>
28
28
#include <sys/wait.h>
39
39
#include "gdm.h"
40
40
#include "misc.h"
41
41
#include "auth.h"
42
 
#include "gdmconfig.h"
43
42
#include "errorgui.h"
44
 
 
45
 
/* set in the main function */
46
 
extern char **stored_argv;
47
 
extern int stored_argc;
48
 
extern char *stored_path;
 
43
#include "slave.h"
 
44
 
 
45
#include "gdm-common.h"
 
46
#include "gdm-log.h"
 
47
#include "gdm-daemon-config.h"
 
48
 
 
49
#include "gdm-socket-protocol.h"
49
50
 
50
51
static int screenx = 0;
51
52
static int screeny = 0;
192
193
        char **argv;
193
194
        struct passwd *pw;
194
195
 
195
 
        closelog ();
196
 
 
197
 
        gdm_close_all_descriptors (0 /* from */, closefdexcept /* except */, -1 /* except2 */);
 
196
        gdm_log_shutdown ();
198
197
 
199
198
        /* No error checking here - if it's messed the best response
200
199
         * is to ignore & try to continue */
203
202
        gdm_open_dev_null (O_RDWR); /* open stderr - fd 2 */
204
203
 
205
204
        if (set_gdm_ids) {
206
 
                setgid (gdm_get_gdmgid ());
207
 
                initgroups (gdm_get_value_string (GDM_KEY_USER), gdm_get_gdmgid ());
208
 
                setuid (gdm_get_gdmuid ());
 
205
                setgid (gdm_daemon_config_get_gdmgid ());
 
206
                initgroups (gdm_daemon_config_get_value_string (GDM_KEY_USER), gdm_daemon_config_get_gdmgid ());
 
207
                setuid (gdm_daemon_config_get_gdmuid ());
209
208
                pw = NULL;
210
209
        } else {
211
210
                pw = getpwuid (uid);
216
215
        /* restore initial environment */
217
216
        gdm_restoreenv ();
218
217
 
219
 
        openlog ("gdm", LOG_PID, LOG_DAEMON);
 
218
        gdm_log_init ();
220
219
 
221
 
        g_setenv ("LOGNAME", gdm_get_value_string (GDM_KEY_USER), TRUE);
222
 
        g_setenv ("USER", gdm_get_value_string (GDM_KEY_USER), TRUE);
223
 
        g_setenv ("USERNAME", gdm_get_value_string (GDM_KEY_USER), TRUE);
 
220
        g_setenv ("LOGNAME", gdm_daemon_config_get_value_string (GDM_KEY_USER), TRUE);
 
221
        g_setenv ("USER", gdm_daemon_config_get_value_string (GDM_KEY_USER), TRUE);
 
222
        g_setenv ("USERNAME", gdm_daemon_config_get_value_string (GDM_KEY_USER), TRUE);
224
223
 
225
224
        g_setenv ("DISPLAY", d->name, TRUE);
226
225
        g_unsetenv ("XAUTHORITY");
227
226
 
228
 
        gdm_auth_set_local_auth (d);
 
227
        g_setenv ("XAUTHORITY", GDM_AUTHFILE (d), TRUE);
229
228
 
230
229
        /* sanity env stuff */
231
230
        g_setenv ("SHELL", "/bin/sh", TRUE);
232
231
        /* set HOME to /, we don't need no stinking HOME anyway */
233
232
        if (pw == NULL ||
234
233
            ve_string_empty (pw->pw_dir))
235
 
                g_setenv ("HOME", ve_sure_string (gdm_get_value_string (GDM_KEY_SERV_AUTHDIR)), TRUE);
 
234
                g_setenv ("HOME", ve_sure_string (gdm_daemon_config_get_value_string (GDM_KEY_SERV_AUTHDIR)), TRUE);
236
235
        else
237
236
                g_setenv ("HOME", pw->pw_dir, TRUE);
238
237
 
241
240
        argc = 1;
242
241
 
243
242
        if ( ! inhibit_gtk_modules &&
244
 
            gdm_get_value_bool (GDM_KEY_ADD_GTK_MODULES) &&
245
 
             ! ve_string_empty (gdm_get_value_string (GDM_KEY_GTK_MODULES_LIST))) {
246
 
                argv[1] = g_strdup_printf ("--gtk-module=%s", gdm_get_value_string (GDM_KEY_GTK_MODULES_LIST));
 
243
            gdm_daemon_config_get_value_bool (GDM_KEY_ADD_GTK_MODULES) &&
 
244
             ! ve_string_empty (gdm_daemon_config_get_value_string (GDM_KEY_GTK_MODULES_LIST))) {
 
245
                argv[1] = g_strdup_printf ("--gtk-module=%s", gdm_daemon_config_get_value_string (GDM_KEY_GTK_MODULES_LIST));
247
246
                argc = 2;
248
247
        }
249
248
 
255
254
 
256
255
        if ( ! inhibit_gtk_themes) {
257
256
                const char *theme_name;
258
 
                gchar *gtkrc = gdm_get_value_string (GDM_KEY_GTKRC);
 
257
                const gchar *gtkrc = gdm_daemon_config_get_value_string (GDM_KEY_GTKRC);
259
258
 
260
259
                if ( ! ve_string_empty (gtkrc) &&
261
260
                     g_access (gtkrc, R_OK) == 0)
263
262
 
264
263
                theme_name = d->theme_name;
265
264
                if (ve_string_empty (theme_name))
266
 
                        theme_name = gdm_get_value_string (GDM_KEY_GTK_THEME);
 
265
                        theme_name = gdm_daemon_config_get_value_string (GDM_KEY_GTK_THEME);
267
266
                if ( ! ve_string_empty (theme_name)) {
268
267
                        gchar *theme_dir = gtk_rc_get_theme_dir ();
269
268
                        char *theme = g_strdup_printf ("%s/%s/gtk-2.0/gtkrc", theme_dir, theme_name);
300
299
}
301
300
 
302
301
void
303
 
gdm_error_box_full (GdmDisplay *d, GtkMessageType type, const char *error,
304
 
                    const char *details_label, const char *details_file,
305
 
                    uid_t uid, gid_t gid)
 
302
gdm_errorgui_error_box_full (GdmDisplay *d,
 
303
                             GtkMessageType type,
 
304
                             const char *error,
 
305
                             const char *details_label,
 
306
                             const char *details_file,
 
307
                             uid_t uid,
 
308
                             gid_t gid)
306
309
{
307
310
        GdkDisplay *gdk_display;
308
311
        pid_t pid;
309
312
 
 
313
        gdm_debug ("Forking extra process: error dialog");
 
314
 
310
315
        pid = gdm_fork_extra ();
311
316
 
312
317
        if (pid == 0) {
316
321
                char *loc;
317
322
                char *details;
318
323
 
 
324
                if (details_label != NULL) {
 
325
                        if (strncmp (details_label, "NIL", 3) == 0)
 
326
                                details_label = NULL;
 
327
                }
 
328
                if (details_file != NULL) {
 
329
                        if (strncmp (details_file, "NIL", 3) == 0)
 
330
                                details_file = NULL;
 
331
                }
 
332
 
319
333
                if (uid != 0) {
320
334
                        gid_t groups[1] = { gid };
321
335
 
345
359
                                if (S_ISREG (s.st_mode)) {
346
360
                                        VE_IGNORE_EINTR (fp = fopen (details_file, "r"));
347
361
                                } else {
348
 
                                        loc = gdm_locale_to_utf8 (_("%s not a regular file!\n"));
 
362
                                        loc = g_locale_to_utf8 (_("%s not a regular file!\n"), -1, NULL, NULL, NULL);
349
363
                                        g_string_printf (gs, loc, details_file);
350
364
                                        g_free (loc);
351
365
                                }
362
376
                                        /* cap the lines at 500, that's already
363
377
                                           a possibility of 128k of data */
364
378
                                        if (lines++ > 500) {
365
 
                                                loc = gdm_locale_to_utf8 (_("\n... File too long to display ...\n"));
 
379
                                                loc = g_locale_to_utf8 (_("\n... File too long to display ...\n"), -1, NULL, NULL, NULL);
366
380
                                                g_string_append (gs, loc);
367
381
                                                g_free (loc);
368
382
                                                break;
371
385
                                }
372
386
                                VE_IGNORE_EINTR (fclose (fp));
373
387
                        } else {
374
 
                                loc = gdm_locale_to_utf8 (_("%s could not be opened"));
 
388
                                loc = g_locale_to_utf8 (_("%s could not be opened"), -1, NULL, NULL, NULL);
375
389
                                g_string_append_printf (gs, loc, details_file);
376
390
                                g_free (loc);
377
391
                        }
379
393
                        details = g_string_free (gs, FALSE);
380
394
 
381
395
                        if ( ! valid_utf8) {
382
 
                                char *tmp = gdm_locale_to_utf8 (details);
 
396
                                char *tmp = g_locale_to_utf8 (details, -1, NULL, NULL, NULL);
383
397
                                g_free (details);
384
398
                                details = tmp;
385
399
                        }
389
403
 
390
404
                setup_dialog (d, "gtk-error-box", -1, TRUE, uid);
391
405
 
392
 
                loc = gdm_locale_to_utf8 (error);
 
406
                loc = g_locale_to_utf8 (error, -1, NULL, NULL, NULL);
393
407
 
394
408
                dlg = gtk_message_dialog_new (NULL /* parent */,
395
409
                                              0 /* flags */,
404
418
                if (details_label != NULL) {
405
419
                        GtkWidget *text = get_error_text_view (details);
406
420
 
407
 
                        loc = gdm_locale_to_utf8 (details_label);
 
421
                        loc = g_locale_to_utf8 (details_label, -1, NULL, NULL, NULL);
408
422
                        button = gtk_check_button_new_with_label (loc);
409
423
                        g_free (loc);
410
424
 
465
479
                _exit (0);
466
480
        } else if (pid > 0) {
467
481
                int status;
468
 
                gdm_wait_for_extra (&status);
 
482
                gdm_wait_for_extra (pid, &status);
469
483
 
470
484
                if (dialog_failed (status)) {
471
485
                        if ( ! inhibit_gtk_themes) {
472
486
                                /* on failure try again, this time without any themes
473
487
                                   which may be causing a crash */
474
488
                                inhibit_gtk_themes = TRUE;
475
 
                                gdm_error_box_full (d, type, error, details_label, details_file, uid, gid);
 
489
                                gdm_errorgui_error_box_full (d, type, error, details_label, details_file, uid, gid);
476
490
                                inhibit_gtk_themes = FALSE;
477
491
                        } else if ( ! inhibit_gtk_modules) {
478
492
                                /* on failure try again, this time without any modules
479
493
                                   which may be causing a crash */
480
494
                                inhibit_gtk_modules = TRUE;
481
 
                                gdm_error_box_full (d, type, error, details_label, details_file, uid, gid);
 
495
                                gdm_errorgui_error_box_full (d, type, error, details_label, details_file, uid, gid);
482
496
                                inhibit_gtk_modules = FALSE;
483
497
                        }
484
498
                }
485
499
        } else {
486
500
                gdm_error (_("%s: Cannot fork to display error/info box"),
487
 
                           "gdm_error_box");
 
501
                           "gdm_errorgui_error_box");
488
502
        }
489
503
}
490
504
 
496
510
}
497
511
 
498
512
void
499
 
gdm_error_box (GdmDisplay *d, GtkMessageType type, const char *error)
 
513
gdm_errorgui_error_box (GdmDisplay *d, GtkMessageType type, const char *error)
500
514
{
501
 
        gdm_error_box_full (d, type, error, NULL, NULL,
502
 
                            /* zero for uid/gid doesn't mean root, but
503
 
                               it means to use the gdm user/group */
504
 
                            0, 0);
 
515
        char *msg;
 
516
        int id = 0;
 
517
 
 
518
        msg = g_strdup_printf ("type=%d$$error=%s$$details_label=%s$$details_file=%s$$uid=%d$$gid=%d", type, error, "NIL", "NIL", id, id);
 
519
 
 
520
        gdm_slave_send_string (GDM_SOP_SHOW_ERROR_DIALOG, msg);
 
521
 
 
522
        g_free (msg);
505
523
}
506
524
 
507
525
char *
508
 
gdm_failsafe_question (GdmDisplay *d,
509
 
                       const char *question,
510
 
                       gboolean echo)
 
526
gdm_errorgui_failsafe_question (GdmDisplay *d,
 
527
                                const char *question,
 
528
                                gboolean echo)
511
529
{
512
530
        GdkDisplay *gdk_display;
513
531
        pid_t pid;
516
534
        if G_UNLIKELY (pipe (p) < 0)
517
535
                return NULL;
518
536
 
 
537
        gdm_debug ("Forking extra process: failsafe question");
 
538
 
519
539
        pid = gdm_fork_extra ();
520
540
        if (pid == 0) {
521
541
                guint sid;
524
544
 
525
545
                setup_dialog (d, "gtk-failsafe-question", p[1], TRUE /* set_gdm_ids */, 0);
526
546
 
527
 
                loc = gdm_locale_to_utf8 (question);
 
547
                loc = g_locale_to_utf8 (question, -1, NULL, NULL, NULL);
528
548
 
529
549
                dlg = gtk_dialog_new_with_buttons (loc,
530
550
                                                   NULL /* parent */,
581
601
 
582
602
                gtk_dialog_run (GTK_DIALOG (dlg));
583
603
 
584
 
                loc = gdm_locale_from_utf8 (ve_sure_string (gtk_entry_get_text (GTK_ENTRY (entry))));
 
604
                loc = g_locale_from_utf8 (ve_sure_string (gtk_entry_get_text (GTK_ENTRY (entry))), -1, NULL, NULL, NULL);
585
605
 
586
606
                gdm_fdprintf (p[1], "%s", ve_sure_string (loc));
587
607
 
598
618
 
599
619
                VE_IGNORE_EINTR (close (p[1]));
600
620
 
601
 
                gdm_wait_for_extra (&status);
 
621
                gdm_wait_for_extra (pid, &status);
602
622
 
603
623
                if (dialog_failed (status)) {
604
624
                        char *ret = NULL;
607
627
                                /* on failure try again, this time without any themes
608
628
                                   which may be causing a crash */
609
629
                                inhibit_gtk_themes = TRUE;
610
 
                                ret = gdm_failsafe_question (d, question, echo);
 
630
                                ret = gdm_errorgui_failsafe_question (d, question, echo);
611
631
                                inhibit_gtk_themes = FALSE;
612
632
                        } else if ( ! inhibit_gtk_modules) {
613
633
                                /* on failure try again, this time without any modules
614
634
                                   which may be causing a crash */
615
635
                                inhibit_gtk_modules = TRUE;
616
 
                                ret = gdm_failsafe_question (d, question, echo);
 
636
                                ret = gdm_errorgui_failsafe_question (d, question, echo);
617
637
                                inhibit_gtk_modules = FALSE;
618
638
                        }
619
639
                        return ret;
628
648
                VE_IGNORE_EINTR (close (p[0]));
629
649
        } else {
630
650
                gdm_error (_("%s: Cannot fork to display error/info box"),
631
 
                           "gdm_failsafe_question");
 
651
                           "gdm_errorgui_failsafe_question");
632
652
        }
633
653
        return NULL;
634
654
}
635
655
 
636
656
gboolean
637
 
gdm_failsafe_yesno (GdmDisplay *d,
638
 
                    const char *question)
 
657
gdm_errorgui_failsafe_yesno (GdmDisplay *d,
 
658
                             const char *question)
639
659
{
640
660
        GdkDisplay *gdk_display;
641
661
        pid_t pid;
644
664
        if G_UNLIKELY (pipe (p) < 0)
645
665
                return FALSE;
646
666
 
 
667
        gdm_debug ("Forking extra process: failsafe yes/no");
 
668
 
647
669
        pid = gdm_fork_extra ();
648
670
        if (pid == 0) {
649
671
                guint sid;
652
674
 
653
675
                setup_dialog (d, "gtk-failsafe-yesno", p[1], TRUE /* set_gdm_ids */, 0);
654
676
 
655
 
                loc = gdm_locale_to_utf8 (question);
 
677
                loc = g_locale_to_utf8 (question, -1, NULL, NULL, NULL);
656
678
 
657
679
                dlg = gtk_message_dialog_new (NULL /* parent */,
658
680
                                              0 /* flags */,
707
729
 
708
730
                VE_IGNORE_EINTR (close (p[1]));
709
731
 
710
 
                gdm_wait_for_extra (&status);
 
732
                gdm_wait_for_extra (pid, &status);
711
733
 
712
734
                if (dialog_failed (status)) {
713
735
                        gboolean ret = FALSE;
716
738
                                /* on failure try again, this time without any themes
717
739
                                   which may be causing a crash */
718
740
                                inhibit_gtk_themes = TRUE;
719
 
                                ret = gdm_failsafe_yesno (d, question);
 
741
                                ret = gdm_errorgui_failsafe_yesno (d, question);
720
742
                                inhibit_gtk_themes = FALSE;
721
743
                        } else if ( ! inhibit_gtk_modules) {
722
744
                                /* on failure try again, this time without any modules
723
745
                                   which may be causing a crash */
724
746
                                inhibit_gtk_modules = TRUE;
725
 
                                ret = gdm_failsafe_yesno (d, question);
 
747
                                ret = gdm_errorgui_failsafe_yesno (d, question);
726
748
                                inhibit_gtk_modules = FALSE;
727
749
                        }
728
750
                        return ret;
739
761
                VE_IGNORE_EINTR (close (p[0]));
740
762
        } else {
741
763
                gdm_error (_("%s: Cannot fork to display error/info box"),
742
 
                           "gdm_failsafe_yesno");
 
764
                           "gdm_errorgui_failsafe_yesno");
743
765
        }
744
766
        return FALSE;
745
767
}
746
768
 
747
769
int
748
 
gdm_failsafe_ask_buttons (GdmDisplay *d,
749
 
                          const char *question,
750
 
                          char **but)
 
770
gdm_errorgui_failsafe_ask_buttons (GdmDisplay *d,
 
771
                                   const char *question,
 
772
                                   char **but)
751
773
{
752
774
        GdkDisplay *gdk_display;
753
775
        pid_t pid;
756
778
        if G_UNLIKELY (pipe (p) < 0)
757
779
                return -1;
758
780
 
 
781
        gdm_debug ("Forking extra process: failsafe ask buttons");
 
782
 
759
783
        pid = gdm_fork_extra ();
760
784
        if (pid == 0) {
761
785
                int i;
765
789
 
766
790
                setup_dialog (d, "gtk-failsafe-ask-buttons", p[1], TRUE /* set_gdm_ids */, 0);
767
791
 
768
 
                loc = gdm_locale_to_utf8 (question);
 
792
                loc = g_locale_to_utf8 (question, -1, NULL, NULL, NULL);
769
793
 
770
794
                dlg = gtk_message_dialog_new (NULL /* parent */,
771
795
                                              0 /* flags */,
775
799
                                              loc);
776
800
                g_free (loc);
777
801
                gtk_widget_set_events (dlg, GDK_ALL_EVENTS_MASK);
778
 
                for (i = 0; but[i] != NULL; i++) {
779
 
                        loc = gdm_locale_to_utf8 (but[i]);
 
802
                for (i = 0; but[i] != NULL && strcmp (but[i], "NIL"); i++) {
 
803
                        loc = g_locale_to_utf8 (but[i], -1, NULL, NULL, NULL);
780
804
                        gtk_dialog_add_button (GTK_DIALOG (dlg),
781
805
                                               loc, i);
782
806
                        g_free (loc);
826
850
 
827
851
                VE_IGNORE_EINTR (close (p[1]));
828
852
 
829
 
                gdm_wait_for_extra (&status);
 
853
                gdm_wait_for_extra (pid, &status);
830
854
 
831
855
                if (dialog_failed (status)) {
832
856
                        int ret = -1;
835
859
                                /* on failure try again, this time without any themes
836
860
                                   which may be causing a crash */
837
861
                                inhibit_gtk_themes = TRUE;
838
 
                                ret = gdm_failsafe_ask_buttons (d, question, but);
 
862
                                ret = gdm_errorgui_failsafe_ask_buttons (d, question, but);
839
863
                                inhibit_gtk_themes = FALSE;
840
864
                        } else if ( ! inhibit_gtk_modules) {
841
865
                                /* on failure try again, this time without any modules
842
866
                                   which may be causing a crash */
843
867
                                inhibit_gtk_modules = TRUE;
844
 
                                ret = gdm_failsafe_ask_buttons (d, question, but);
 
868
                                ret = gdm_errorgui_failsafe_ask_buttons (d, question, but);
845
869
                                inhibit_gtk_modules = FALSE;
846
870
                        }
847
871
                        return ret;
860
884
                VE_IGNORE_EINTR (close (p[0]));
861
885
        } else {
862
886
                gdm_error (_("%s: Cannot fork to display error/info box"),
863
 
                           "gdm_failsafe_ask_buttons");
 
887
                           "gdm_errorgui_failsafe_ask_buttons");
864
888
        }
865
889
        return -1;
866
890
}
867
 
 
868
 
/* EOF */