~ubuntu-branches/debian/stretch/lightdm/stretch

« back to all changes in this revision

Viewing changes to .pc/01_set-default-path.patch/src/session-child.c

  • Committer: Package Import Robot
  • Author(s): Yves-Alexis Perez
  • Date: 2013-10-20 20:45:55 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20131020204555-0ht6bt0lw5bof9fn
Tags: 1.8.2-1
* New upstream release.
* debian/patches:
  - 01_set-default-path, 02_default-config, 05_debianize-pam-files
    refreshed.
  - 03_quit-plymouth disabled for now, to check if problem is really fixed
    upstream.
* debian/control:
  - rename liblightdm-qt-2-0 to liblightdm-qt-3-0 to match updated soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <config.h>
 
2
 
1
3
#include <stdlib.h>
2
4
#include <stdio.h>
3
5
#include <unistd.h>
14
16
#include <utmpx.h>
15
17
#include <sys/mman.h>
16
18
 
 
19
#include "configuration.h"
17
20
#include "session-child.h"
18
21
#include "session.h"
19
22
#include "console-kit.h"
 
23
#include "login1.h"
20
24
#include "privileges.h"
21
 
#include "xauthority.h"
 
25
#include "x-authority.h"
22
26
#include "configuration.h"
23
27
 
24
28
/* Child process being run */
165
169
        exit (EXIT_SUCCESS);
166
170
}
167
171
 
 
172
static XAuthority *
 
173
read_xauth (void)
 
174
{
 
175
    gchar *x_authority_name;
 
176
    guint16 x_authority_family;
 
177
    guint8 *x_authority_address;
 
178
    gsize x_authority_address_length;
 
179
    gchar *x_authority_number;
 
180
    guint8 *x_authority_data;
 
181
    gsize x_authority_data_length;
 
182
 
 
183
    x_authority_name = read_string ();
 
184
    if (!x_authority_name)
 
185
        return NULL;
 
186
 
 
187
    read_data (&x_authority_family, sizeof (x_authority_family));
 
188
    read_data (&x_authority_address_length, sizeof (x_authority_address_length));
 
189
    x_authority_address = g_malloc (x_authority_address_length);
 
190
    read_data (x_authority_address, x_authority_address_length);
 
191
    x_authority_number = read_string ();
 
192
    read_data (&x_authority_data_length, sizeof (x_authority_data_length));
 
193
    x_authority_data = g_malloc (x_authority_data_length);
 
194
    read_data (x_authority_data, x_authority_data_length);
 
195
 
 
196
    return x_authority_new (x_authority_family, x_authority_address, x_authority_address_length, x_authority_number, x_authority_name, x_authority_data, x_authority_data_length);
 
197
}
 
198
 
168
199
int
169
200
session_child_run (int argc, char **argv)
170
201
{
186
217
    gchar *tty;
187
218
    gchar *remote_host_name;
188
219
    gchar *xdisplay;
189
 
    gchar *xauth_name;
190
 
    XAuthority *xauthority = NULL;
191
 
    gchar *xauth_filename;
 
220
    XAuthority *x_authority = NULL;
 
221
    gchar *x_authority_filename;
192
222
    GDBusConnection *bus;
193
 
    gchar *console_kit_cookie;
 
223
    gchar *console_kit_cookie = NULL;
 
224
    gchar *login1_session = NULL;
 
225
 
194
226
    const gchar *path;
195
227
    GError *error = NULL;
 
228
    const gchar *locale_value;
 
229
    gchar *locale_var;
 
230
    static const gchar * const locale_var_names[] = {
 
231
        "LC_COLLATE",
 
232
        "LC_CTYPE",
 
233
        "LC_MONETARY",
 
234
        "LC_NUMERIC",
 
235
        "LC_TIME",
 
236
        "LC_MESSAGES",
 
237
        "LC_ALL",
 
238
        "LANG",
 
239
        NULL
 
240
    };
196
241
 
197
242
#if !defined(GLIB_VERSION_2_36)
198
243
    g_type_init ();
243
288
    tty = read_string ();
244
289
    remote_host_name = read_string ();
245
290
    xdisplay = read_string ();
246
 
    xauth_name = read_string ();
247
 
    if (xauth_name)
248
 
    {
249
 
        guint16 xauth_family;
250
 
        guint8 *xauth_address;
251
 
        gsize xauth_address_length;
252
 
        gchar *xauth_number;
253
 
        guint8 *xauth_data;
254
 
        gsize xauth_data_length;
255
 
 
256
 
        read_data (&xauth_family, sizeof (xauth_family));
257
 
        read_data (&xauth_address_length, sizeof (xauth_address_length));
258
 
        xauth_address = g_malloc (xauth_address_length);
259
 
        read_data (xauth_address, xauth_address_length);
260
 
        xauth_number = read_string ();
261
 
        read_data (&xauth_data_length, sizeof (xauth_data_length));
262
 
        xauth_data = g_malloc (xauth_data_length);
263
 
        read_data (xauth_data, xauth_data_length);
264
 
 
265
 
        xauthority = xauth_new (xauth_family, xauth_address, xauth_address_length, xauth_number, xauth_name, xauth_data, xauth_data_length);
266
 
    }
 
291
    x_authority = read_xauth ();
267
292
 
268
293
    /* Setup PAM */
269
294
    result = pam_start (service, username, &conversation, &pam_handle);
283
308
        pam_set_item (pam_handle, PAM_TTY, tty);    
284
309
 
285
310
#ifdef PAM_XAUTHDATA
286
 
    if (xauthority)
 
311
    if (x_authority)
287
312
    {
288
313
        struct pam_xauth_data value;
289
314
 
290
 
        value.name = (char *) xauth_get_authorization_name (xauthority);
291
 
        value.namelen = strlen (xauth_get_authorization_name (xauthority));
292
 
        value.data = (char *) xauth_get_authorization_data (xauthority);
293
 
        value.datalen = xauth_get_authorization_data_length (xauthority);
 
315
        value.name = (char *) x_authority_get_authorization_name (x_authority);
 
316
        value.namelen = strlen (x_authority_get_authorization_name (x_authority));
 
317
        value.data = (char *) x_authority_get_authorization_data (x_authority);
 
318
        value.datalen = x_authority_get_authorization_data_length (x_authority);
294
319
        pam_set_item (pam_handle, PAM_XAUTHDATA, &value);
295
320
    }
296
321
#endif
335
360
            pam_putenv (pam_handle, g_strdup_printf ("LOGNAME=%s", username));
336
361
            pam_putenv (pam_handle, g_strdup_printf ("HOME=%s", user_get_home_directory (user)));
337
362
            pam_putenv (pam_handle, g_strdup_printf ("SHELL=%s", user_get_shell (user)));
 
363
 
 
364
            /* Let the greeter and user session inherit the system default locale */
 
365
            for (i = 0; locale_var_names[i] != NULL; i++)
 
366
            {
 
367
                if ((locale_value = g_getenv (locale_var_names[i])) != NULL)
 
368
                {
 
369
                    locale_var = g_strdup_printf ("%s=%s", locale_var_names[i], locale_value);
 
370
                    pam_putenv (pam_handle, locale_var);
 
371
                    g_free (locale_var);
 
372
                }
 
373
            }
338
374
        }
339
375
    }
340
376
 
359
395
 
360
396
    /* Get the command to run (blocks) */
361
397
    log_filename = read_string ();
362
 
    xauth_filename = read_string ();
 
398
    if (version >= 1)
 
399
    {
 
400
        g_free (tty);
 
401
        tty = read_string ();      
 
402
    }
 
403
    x_authority_filename = read_string ();
 
404
    if (version >= 1)
 
405
    {
 
406
        g_free (xdisplay);
 
407
        xdisplay = read_string ();
 
408
        if (x_authority)
 
409
            g_object_unref (x_authority);
 
410
        x_authority = read_xauth ();
 
411
    }
363
412
    read_data (&env_length, sizeof (env_length));
364
413
    for (i = 0; i < env_length; i++)
365
414
        pam_putenv (pam_handle, read_string ());
419
468
    if (!bus)
420
469
        return EXIT_FAILURE;
421
470
 
422
 
    /* Open a Console Kit session */
423
 
    g_variant_builder_init (&ck_parameters, G_VARIANT_TYPE ("(a(sv))"));
424
 
    g_variant_builder_open (&ck_parameters, G_VARIANT_TYPE ("a(sv)"));
425
 
    g_variant_builder_add (&ck_parameters, "(sv)", "unix-user", g_variant_new_int32 (user_get_uid (user)));
426
 
    if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0)
427
 
        g_variant_builder_add (&ck_parameters, "(sv)", "session-type", g_variant_new_string ("LoginWindow"));
428
 
    if (xdisplay)
429
 
    {
430
 
        g_variant_builder_add (&ck_parameters, "(sv)", "x11-display", g_variant_new_string (xdisplay));
431
 
        if (tty)
432
 
            g_variant_builder_add (&ck_parameters, "(sv)", "x11-display-device", g_variant_new_string (tty));
433
 
    }
434
 
    if (remote_host_name)
435
 
    {
436
 
        g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (FALSE));
437
 
        g_variant_builder_add (&ck_parameters, "(sv)", "remote-host-name", g_variant_new_string (remote_host_name));
438
 
    }
439
 
    else
440
 
        g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (TRUE));
441
 
    console_kit_cookie = ck_open_session (&ck_parameters);
442
 
    write_string (console_kit_cookie);
443
 
    if (console_kit_cookie)
444
 
    {
445
 
        gchar *value;
446
 
        value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie);
447
 
        pam_putenv (pam_handle, value);
448
 
        g_free (value);
 
471
    if (login1_is_running ())
 
472
    {
 
473
        login1_session = login1_get_session_id ();
 
474
        write_string (login1_session);
 
475
    }
 
476
 
 
477
    if (!login1_session)
 
478
    {
 
479
        /* Open a Console Kit session */
 
480
        g_variant_builder_init (&ck_parameters, G_VARIANT_TYPE ("(a(sv))"));
 
481
        g_variant_builder_open (&ck_parameters, G_VARIANT_TYPE ("a(sv)"));
 
482
        g_variant_builder_add (&ck_parameters, "(sv)", "unix-user", g_variant_new_int32 (user_get_uid (user)));
 
483
        if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0)
 
484
            g_variant_builder_add (&ck_parameters, "(sv)", "session-type", g_variant_new_string ("LoginWindow"));
 
485
        if (xdisplay)
 
486
        {
 
487
            g_variant_builder_add (&ck_parameters, "(sv)", "x11-display", g_variant_new_string (xdisplay));
 
488
            if (tty)
 
489
                g_variant_builder_add (&ck_parameters, "(sv)", "x11-display-device", g_variant_new_string (tty));
 
490
        }
 
491
        if (remote_host_name)
 
492
        {
 
493
            g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (FALSE));
 
494
            g_variant_builder_add (&ck_parameters, "(sv)", "remote-host-name", g_variant_new_string (remote_host_name));
 
495
        }
 
496
        else
 
497
            g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (TRUE));
 
498
        console_kit_cookie = ck_open_session (&ck_parameters);
 
499
        write_string (console_kit_cookie);
 
500
        if (console_kit_cookie)
 
501
        {
 
502
            gchar *value;
 
503
            value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie);
 
504
            pam_putenv (pam_handle, value);
 
505
            g_free (value);
 
506
        }
449
507
    }
450
508
 
451
509
    /* Write X authority */
452
 
    if (xauthority)
 
510
    if (x_authority)
453
511
    {
454
512
        gboolean drop_privileges, result;
455
513
        gchar *value;
458
516
        drop_privileges = geteuid () == 0;
459
517
        if (drop_privileges)
460
518
            privileges_drop (user);
461
 
        result = xauth_write (xauthority, XAUTH_WRITE_MODE_REPLACE, xauth_filename, &error);
 
519
        result = x_authority_write (x_authority, XAUTH_WRITE_MODE_REPLACE, x_authority_filename, &error);
462
520
        if (drop_privileges)
463
521
            privileges_reclaim ();
464
522
 
468
526
        if (!result)
469
527
            return EXIT_FAILURE;
470
528
 
471
 
        value = g_strdup_printf ("XAUTHORITY=%s", xauth_filename);
 
529
        value = g_strdup_printf ("XAUTHORITY=%s", x_authority_filename);
472
530
        pam_putenv (pam_handle, value);
473
531
        g_free (value);
474
532
    }
551
609
            memset (&ut, 0, sizeof (ut));
552
610
            ut.ut_type = USER_PROCESS;
553
611
            ut.ut_pid = child_pid;
554
 
            strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
555
 
            strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
 
612
            if (tty)
 
613
                strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
 
614
            if (xdisplay)
 
615
                strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
556
616
            strncpy (ut.ut_user, username, sizeof (ut.ut_user));
557
617
            if (xdisplay)
558
618
                strncpy (ut.ut_host, xdisplay, sizeof (ut.ut_host));
580
640
            memset (&ut, 0, sizeof (ut));
581
641
            ut.ut_type = DEAD_PROCESS;
582
642
            ut.ut_pid = child_pid;
583
 
            strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
584
 
            strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
 
643
            if (tty)
 
644
                strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
 
645
            if (xdisplay)
 
646
                strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
585
647
            strncpy (ut.ut_user, username, sizeof (ut.ut_user));
586
648
            if (xdisplay)
587
649
                strncpy (ut.ut_host, xdisplay, sizeof (ut.ut_host));
599
661
    }
600
662
 
601
663
    /* Remove X authority */
602
 
    if (xauthority)
 
664
    if (x_authority)
603
665
    {
604
666
        gboolean drop_privileges, result;
605
667
        GError *error = NULL;
607
669
        drop_privileges = geteuid () == 0;
608
670
        if (drop_privileges)
609
671
            privileges_drop (user);
610
 
        result = xauth_write (xauthority, XAUTH_WRITE_MODE_REMOVE, xauth_filename, &error);
 
672
        result = x_authority_write (x_authority, XAUTH_WRITE_MODE_REMOVE, x_authority_filename, &error);
611
673
        if (drop_privileges)
612
674
            privileges_reclaim ();
613
675