summaryrefslogtreecommitdiff
path: root/gui/gdmcommon.c
blob: c2be434aa999581fb7c52c4fb47d41082d11d0e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * GDM - The GNOME Display Manager
 * Copyright (C) 1999, 2000 Martin K. Petersen <mkp@mkp.net>
 *
 * This file Copyright (c) 2003 George Lebl
 * - Common routines for the greeters.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <signal.h>

#include <glib/gi18n.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>

#include "gdm.h"
#include "gdmcommon.h"
#include "gdmcomm.h"
#include "gdmconfig.h"

gint gdm_timed_delay = 0;
static Atom AT_SPI_IOR;

/*
 * Some slaves want to send output to syslog and others (such as 
 * gdmflexiserver and gdmdynamic send error messages to stdout.  
 * Calling gdm_common_openlog to open the syslog sets the
 * using_syslog flag so that calls to gdm_common_fail, 
 * gdm_common_info, gdm_common_error, and gdm_common_debug sends 
 * output to the syslog if the syslog has been opened, otherwise
 * send to stdout.
 */
static gboolean using_syslog = FALSE;

void
gdm_common_openlog (const char *ident, int logopt, int facility)
{
   openlog (ident, logopt, facility);
   using_syslog = TRUE;
}

void
gdm_common_fail_exit (const gchar *format, ...)
{
    va_list args;
    gchar *s;

    if (!format) {
	_exit (EXIT_FAILURE);
    }

    va_start (args, format);
    s = g_strdup_vprintf (format, args);
    va_end (args);
    
    if (using_syslog) {
        syslog (LOG_ERR, "%s", s);
        closelog ();
    } else
        g_printf ("%s\n", s);

    g_free (s);

    _exit (EXIT_FAILURE);
}

void
gdm_common_fail_greeter (const gchar *format, ...)
{
    va_list args;
    gchar *s;

    if (!format) {
	_exit (DISPLAY_GREETERFAILED);
    }

    va_start (args, format);
    s = g_strdup_vprintf (format, args);
    va_end (args);
    
    if (using_syslog) {
        syslog (LOG_ERR, "%s", s);
        closelog ();
    } else
        g_printf ("%s\n", s);

    g_free (s);

    _exit (DISPLAY_GREETERFAILED);
}

void
gdm_common_info (const gchar *format, ...)
{
    va_list args;
    gchar *s;

    va_start (args, format);
    s = g_strdup_vprintf (format, args);
    va_end (args);

    if (using_syslog)
        syslog (LOG_INFO, "%s", s);
    else
        g_printf ("%s\n", s);
 
    g_free (s);
}

void
gdm_common_error (const gchar *format, ...)
{
    va_list args;
    gchar *s;

    va_start (args, format);
    s = g_strdup_vprintf (format, args);
    va_end (args);

    if (using_syslog)
        syslog (LOG_ERR, "%s", s);
    else
        g_printf ("%s\n", s);
    
    g_free (s);
}

void
gdm_common_warning (const gchar *format, ...)
{
    va_list args;
    gchar *s;

    va_start (args, format);
    s = g_strdup_vprintf (format, args);
    va_end (args);

    if (using_syslog)
        syslog (LOG_WARNING, "%s", s);
    else
        g_printf ("%s\n", s);
    
    g_free (s);
}

void
gdm_common_debug (const gchar *format, ...)
{
    va_list args;
    gchar *s;

    if G_LIKELY (! gdm_config_get_bool (GDM_KEY_DEBUG))
        return;

    va_start (args, format);
    s = g_strdup_vprintf (format, args);
    va_end (args);

    syslog (LOG_ERR, "%s", s);
    closelog ();
    g_free (s);
}

void
gdm_common_setup_cursor (GdkCursorType type)
{
	GdkCursor *cursor = gdk_cursor_new (type);
	gdk_window_set_cursor (gdk_get_default_root_window (), cursor);
	gdk_cursor_unref (cursor);
}

void
gdm_common_login_sound (const gchar *GdmSoundProgram,
			const gchar *GdmSoundOnLoginReadyFile,
			gboolean     GdmSoundOnLoginReady)
{
	if ( ! GdmSoundOnLoginReady)
		return;

	if (ve_string_empty (g_getenv ("GDM_IS_LOCAL")) ||
	    ve_string_empty (GdmSoundProgram) ||
	    ve_string_empty (GdmSoundOnLoginReadyFile) ||
	    g_access (GdmSoundProgram, F_OK) != 0 ||
	    g_access (GdmSoundOnLoginReadyFile, F_OK) != 0) {
		gdk_beep ();
	} else {
		/* login sound interruption */
		printf ("%c%c%c\n", STX, BEL, GDM_INTERRUPT_LOGIN_SOUND);
		fflush (stdout);
	}
}

typedef struct {
	GtkWidget *entry;
	gboolean   blink;
} EntryBlink;

static GSList *entries = NULL;
static guint noblink_timeout = 0;

#define NOBLINK_TIMEOUT (20*1000)

static void
setup_blink (gboolean blink)
{
	GSList *li;
	for (li = entries; li != NULL; li = li->next) {
		EntryBlink *eb = li->data;
		if (eb->blink) {
			GtkSettings *settings
				= gtk_widget_get_settings (eb->entry);
			g_object_set (settings,
				      "gtk-cursor-blink", blink, NULL);
			gtk_widget_queue_resize (eb->entry);
		}
	}
}

static gboolean
no_blink (gpointer data)
{
	noblink_timeout = 0;
	setup_blink (FALSE);
	return FALSE;
}

static gboolean
delay_noblink (GSignalInvocationHint *ihint,
	       guint	           n_param_values,
	       const GValue	  *param_values,
	       gpointer		   data)
{
	setup_blink (TRUE);
	if (noblink_timeout > 0)
		g_source_remove (noblink_timeout);
	noblink_timeout
		= g_timeout_add (NOBLINK_TIMEOUT, no_blink, NULL);
	return TRUE;
}      


void
gdm_common_setup_blinking (void)
{
	guint sid;

	if ( ! ve_string_empty (g_getenv ("GDM_IS_LOCAL")) &&
	    strncmp (ve_sure_string (g_getenv ("DISPLAY")), ":0", 2) == 0)
		return;

	sid = g_signal_lookup ("activate",
			       GTK_TYPE_MENU_ITEM);
	if (sid != 0) {
	   g_signal_add_emission_hook (sid,
				       0 /* detail */,
				       delay_noblink,
				       NULL /* data */,
				       NULL /* destroy_notify */);
	}

	sid = g_signal_lookup ("key_press_event",
			       GTK_TYPE_WIDGET);
	if (sid != 0) {
	   g_signal_add_emission_hook (sid,
				       0 /* detail */,
				       delay_noblink,
				       NULL /* data */,
				       NULL /* destroy_notify */);
	}

	sid = g_signal_lookup ("button_press_event",
			       GTK_TYPE_WIDGET);
	if (sid != 0) {
	   g_signal_add_emission_hook (sid,
				       0 /* detail */,
				       delay_noblink,
				       NULL /* data */,
				       NULL /* destroy_notify */);
	}

	noblink_timeout = g_timeout_add (NOBLINK_TIMEOUT, no_blink, NULL);
}

void
gdm_common_setup_blinking_entry (GtkWidget *entry)
{
	EntryBlink *eb;
	GtkSettings *settings;

	if ( ! ve_string_empty (g_getenv ("GDM_IS_LOCAL")) &&
	    strncmp (ve_sure_string (g_getenv ("DISPLAY")), ":0", 2) == 0)
		return;

	eb = g_new0 (EntryBlink, 1);

	eb->entry = entry;
	settings = gtk_widget_get_settings (eb->entry);
	g_object_get (settings, "gtk-cursor-blink", &(eb->blink), NULL);

	entries = g_slist_prepend (entries, eb);
}

GdkPixbuf *
gdm_common_get_face (const char *filename,
		     const char *fallback_filename,
		     guint       max_width,
		     guint       max_height)
{
	GdkPixbuf *pixbuf    = NULL;

	/* If we don't have a filename then try the fallback */
	if (! filename) {
		GtkIconTheme *theme;
		int           icon_size = 48;

		/* If we don't have a fallback then return NULL */
		if (! fallback_filename)
			return NULL;

		/* Try to load an icon from the theme before the fallback */
		theme = gtk_icon_theme_get_default ();
		pixbuf = gtk_icon_theme_load_icon (theme, "stock_person", icon_size, 0, NULL);
		if (! pixbuf)
			pixbuf = gdk_pixbuf_new_from_file (fallback_filename, NULL);
	} else {
		pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
	}

	if (pixbuf) {
		guint w, h;
	
		w = gdk_pixbuf_get_width (pixbuf);
		h = gdk_pixbuf_get_height (pixbuf);

		if (w > h && w > max_width) {
			h = h * ((gfloat) max_width / w);
			w = max_width;
		} else if (h > max_height) {
			w = w * ((gfloat) max_height / h);
			h = max_height;
		}

		if (w != gdk_pixbuf_get_width (pixbuf) ||
		    h != gdk_pixbuf_get_height (pixbuf)) {
			GdkPixbuf *img;

			img = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR);
			g_object_unref (pixbuf);
			pixbuf = img;
		}
        }

	return pixbuf;
}

gchar * 
gdm_common_get_config_file (void)
{
	gchar *result;
	gchar *config_file;

	/* Get config file */
	result = gdmcomm_call_gdm ("GET_CONFIG_FILE", NULL /* auth cookie */, "2.8.0.2", 5);
	if (! result)
		return NULL;

	if (ve_string_empty (result) ||
		strncmp (result, "OK ", 3) != 0) {
		g_free (result);
		return NULL;
	}

	/* skip the "OK " */
	config_file = g_strdup (result + 3);

	g_free (result);

	return config_file;
}

gchar * 
gdm_common_get_custom_config_file (void)
{
	gchar *result;
	gchar *config_file;

	/* Get config file */
	result = gdmcomm_call_gdm ("GET_CUSTOM_CONFIG_FILE", NULL /* auth cookie */, "2.8.0.2", 5);
	if (! result)
		return NULL;

	if (ve_string_empty (result) ||
		strncmp (result, "OK ", 3) != 0) {
		g_free (result);
		return NULL;
	}

	/* skip the "OK " */
	config_file = g_strdup (result + 3);

	g_free (result);

	return config_file;
}

gboolean
gdm_common_select_time_format (void)
{
	gchar *val = gdm_config_get_string (GDM_KEY_USE_24_CLOCK);

	if (val != NULL &&
	    (val[0] == 'T' ||
	     val[0] == 't' ||
	     val[0] == 'Y' ||
	     val[0] == 'y' ||
	     atoi (val) != 0)) {
		return TRUE;
	} else if (val != NULL &&
	    (val[0] == 'F' ||
	     val[0] == 'f' ||
	     val[0] == 'N' ||
	     val[0] == 'n')) {
		return FALSE;
	} else {
		/* Value is "auto" (default), thus select according to
		   "locale" settings. */
		char outstr[20];
		time_t t;
		struct tm *tmp;

		t = time(NULL);
		tmp = localtime (&t);

		/* if the locale does not have an AM/PM string, use 24h time */
		return (strftime (outstr, sizeof(outstr), "%p", tmp) == 0);
	}
	/* NOTREACHED */
	return TRUE;
}

/* Not to look too shaby on Xinerama setups */
void
gdm_common_setup_background_color (gchar *bg_color)
{
  GdkColormap *colormap;
  GdkColor color;

  if (bg_color == NULL ||
      bg_color[0] == '\0' ||
      ! gdk_color_parse (bg_color, &color))
    {
      gdk_color_parse ("#007777", &color);
    }

  g_free (bg_color);

  colormap = gdk_drawable_get_colormap
          (gdk_get_default_root_window ());
  /* paranoia */
  if (colormap != NULL)
    {
      gboolean success;
      gdk_error_trap_push ();

      gdk_colormap_alloc_colors (colormap, &color, 1,
                                 FALSE, TRUE, &success);
      gdk_window_set_background (gdk_get_default_root_window (), &color);
      gdk_window_clear (gdk_get_default_root_window ());

      gdk_flush ();
      gdk_error_trap_pop ();
    }
}

gchar *
gdm_common_get_welcomemsg (void)
{
        gchar *welcomemsg;
	gchar *tempstr;

	/*
	 * Translate the welcome msg in the client program since it is running as the
	 * user and therefore has the appropriate language environment set.
	 */
        if (ve_string_empty (g_getenv ("GDM_IS_LOCAL"))) {
                if (gdm_config_get_bool (GDM_KEY_DEFAULT_REMOTE_WELCOME))
                        welcomemsg = g_strdup (_(GDM_DEFAULT_REMOTE_WELCOME_MSG));
                else {
			tempstr = gdm_config_get_translated_string (GDM_KEY_REMOTE_WELCOME);

			if (tempstr == NULL ||
			    strcmp (ve_sure_string (tempstr), GDM_DEFAULT_REMOTE_WELCOME_MSG) == 0)
				welcomemsg = g_strdup (_(GDM_DEFAULT_REMOTE_WELCOME_MSG));
			else
				welcomemsg = g_strdup (tempstr);
		}
        } else {
                if (gdm_config_get_bool (GDM_KEY_DEFAULT_WELCOME))
                        welcomemsg = g_strdup (_(GDM_DEFAULT_WELCOME_MSG));
                else {
                        tempstr = gdm_config_get_translated_string (GDM_KEY_WELCOME);

			if (tempstr == NULL ||
			    strcmp (ve_sure_string (tempstr), GDM_DEFAULT_WELCOME_MSG) == 0)
				welcomemsg = g_strdup (_(GDM_DEFAULT_WELCOME_MSG));
			else
				welcomemsg = g_strdup (tempstr);
		}
        }

	return welcomemsg;
}

static gchar *
pre_fetch_prog_get_path (void)
{
	gchar *prefetchprog;

	prefetchprog = gdm_config_get_string (GDM_KEY_PRE_FETCH_PROGRAM);
	if  (! ve_string_empty (prefetchprog)) {
		return prefetchprog;
	} else
		return NULL;
}

static gboolean
pre_fetch_run (gpointer data)
{
	GPid pid = -1;
	GError *error = NULL;
	char *command = NULL;
	gchar **pre_fetch_prog_argv =  NULL;

	command = pre_fetch_prog_get_path ();

	if (! command)
		return FALSE;

	pre_fetch_prog_argv = ve_split (command);

	g_spawn_async (".",
		       pre_fetch_prog_argv,
		       NULL,
		       (GSpawnFlags) (G_SPAWN_SEARCH_PATH),
		       NULL,
		       NULL,
		       &pid,
		       &error);

	return FALSE;
}

static gboolean 
pre_atspi_launch (void){
	gboolean a11y = gdm_config_get_bool (GDM_KEY_ADD_GTK_MODULES);
	GPid pid = -1;
	GError *error = NULL;
	char *command = NULL;
	gchar **atspi_prog_argv =  NULL;
	
	if (! a11y)
		return FALSE;

	command = g_strdup (LIBEXECDIR "/at-spi-registryd");

	atspi_prog_argv = ve_split (command);
	
	g_spawn_async (".",
		       atspi_prog_argv,
		       NULL,
		       (GSpawnFlags) (G_SPAWN_SEARCH_PATH),
		       NULL,
		       NULL,
		       &pid,
		       &error);

	if (kill (pid, 0) < 0) {
		fprintf (stderr, "at-spi-registryd not running: %s\n", error->message);
		return FALSE;
	}

	return TRUE;

}


static GdkFilterReturn 
filter_watch (GdkXEvent *xevent, GdkEvent *event, gpointer data){
     XEvent *xev = (XEvent *)xevent;

     if (xev->xany.type == PropertyNotify &&
	 xev->xproperty.atom == AT_SPI_IOR){
	     gtk_main_quit ();
	  
	  return GDK_FILTER_REMOVE;
     }

     return GDK_FILTER_CONTINUE;
}

static gboolean
filter_timeout (gpointer data)
{
	gdm_common_info (_("The accessibility registry was not found."));

	gtk_main_quit ();

	return FALSE;
}

void
gdm_common_atspi_launch (void)
{
	GdkWindow *w = gdk_get_default_root_window (); 
	gboolean a11y = gdm_config_get_bool (GDM_KEY_ADD_GTK_MODULES);
	guint tid;

	if (! a11y)
		return;
 
	if ( ! AT_SPI_IOR)
		AT_SPI_IOR = XInternAtom (GDK_DISPLAY (), "AT_SPI_IOR", False);

	gdk_window_set_events (w,  GDK_PROPERTY_CHANGE_MASK); 
	
	if ( ! pre_atspi_launch ()) {
		gdm_common_info (_("The accessibility registry could not be started."));
		
		return;
	}
	gdk_window_add_filter (w, filter_watch, NULL);
	tid = g_timeout_add (1e3, filter_timeout, NULL);

	gtk_main ();

	gdk_window_remove_filter (w, filter_watch, NULL);
	g_source_remove (tid);
}

void
gdm_common_pre_fetch_launch (void)
{
	if (! pre_fetch_prog_get_path ())
		return;

	g_idle_add (pre_fetch_run, NULL);
}

/*
 * Returns the string version of the time that the user
 * will need to free.  Requires the user pass in the
 * the_tm structure to be used.  This way the caller
 * has access to the time data as well.
 */
gchar *
gdm_common_get_clock (struct tm **the_tm)
{
        char *str;
        time_t the_time;

        time (&the_time);
        *the_tm = localtime (&the_time);

        if (gdm_common_select_time_format ()) {
                str = ve_strftime (*the_tm, _("%a %b %d, %H:%M"));
        } else {
                /* Translators: You should translate time part as
                   %H:%M if your language does not have AM and PM
                   equivalent.  Note: %l is a strftime option for
                   12-hour clock format */
                str = ve_strftime (*the_tm, _("%a %b %d, %l:%M %p"));
        }

        return str;
}

char *
gdm_common_expand_text (const gchar *text)
{
  GString *str;
  const char *p;
  gchar *clock, *display;
  int r, i, n_chars;
  gboolean underline = FALSE;
  gchar buf[256];
  struct utsname name;
  struct tm *the_tm;

  str = g_string_sized_new (strlen (text));

  p = text;
  n_chars = g_utf8_strlen (text, -1);
  i = 0;
  
  while (i < n_chars)
    {
      gunichar ch;

      ch = g_utf8_get_char (p);

      /* Backslash commands */
      if (ch == '\\')
        {
	  p = g_utf8_next_char (p);
	  i++;
	  ch = g_utf8_get_char (p);

	  if (i >= n_chars || ch == '\0')
	    {
	      g_warning ("Unescaped \\ at end of text\n");
	      goto bail;
	    }
	  else if (ch == 'n')
	    g_string_append_unichar (str, '\n');
	  else
	    g_string_append_unichar (str, ch);
	}
      else if (ch == '%')
	{
	  p = g_utf8_next_char (p);
	  i++;
	  ch = g_utf8_get_char (p);

	  if (i >= n_chars || ch == '\0')
	    {
	      g_warning ("Unescaped %% at end of text\n");
	      goto bail;
	    }

	  switch (ch)
	    {
	    case '%':
	      g_string_append (str, "%");
	      break;
	    case 'c':
	      clock = gdm_common_get_clock (&the_tm);
	      g_string_append (str, clock);
	      g_free (clock);
	      break;
	    case 'd':
	      display = g_strdup (g_getenv ("DISPLAY"));
	      g_string_append (str, display);
	      break;
	    case 'h':
	      buf[sizeof (buf) - 1] = '\0';
	      r = gethostname (buf, sizeof (buf) - 1);
	      if (r)
		g_string_append (str, "localhost");
	      else
		g_string_append (str, buf);
	      break;
	    case 'm':
	      uname (&name);
	      g_string_append (str, name.machine);
	      break;
	    case 'n':
	      uname (&name);
	      g_string_append (str, name.nodename);
	      break;
	    case 'o':
	      buf[sizeof (buf) - 1] = '\0';
	      r = getdomainname (buf, sizeof (buf) - 1);
	      if (r)
		g_string_append (str, "localdomain");
	      else
		g_string_append (str, buf);
	      break;
	    case 'r':
	      uname (&name);
	      g_string_append (str, name.release);
	      break;
	    case 's':
	      uname (&name);
	      g_string_append (str, name.sysname);
	      break;
	    case 't':
	      g_string_append_printf (str, ngettext("%d second", "%d seconds", gdm_timed_delay),
				      gdm_timed_delay);
	      break;
	    case 'u':
	      g_string_append (str, ve_sure_string (g_getenv("GDM_TIMED_LOGIN_OK")));
	      break;
	    default:
	      if (ch < 127)
	        g_warning ("unknown escape code %%%c in text\n", (char)ch);
	      else
		g_warning ("unknown escape code %%(U%x) in text\n", (int)ch);
	    }
	}
      else if (ch == '_')
        {
          /*
           * Could be true if an underscore was put right before a special
           * character like % or /
           */
          if (underline == FALSE) {
            underline = TRUE;
	    g_string_append (str, "<u>");
	  }
	}
      else
	{
	  g_string_append_unichar (str, ch);
	  if (underline)
	    {
	      underline = FALSE;
	      g_string_append (str, "</u>");
	    }
	}
      p = g_utf8_next_char (p);
      i++;
    }
  
 bail:

  if (underline)
    g_string_append (str, "</u>");

  return g_string_free (str, FALSE);
}