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

« back to all changes in this revision

Viewing changes to src/session.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
1
/*
2
2
 * Copyright (C) 2010-2011 Robert Ancell.
3
3
 * Author: Robert Ancell <robert.ancell@canonical.com>
4
 
 * 
 
4
 *
5
5
 * This program is free software: you can redistribute it and/or modify it under
6
6
 * the terms of the GNU General Public License as published by the Free Software
7
7
 * Foundation, either version 3 of the License, or (at your option) any later
9
9
 * license.
10
10
 */
11
11
 
 
12
#include <config.h>
 
13
 
12
14
#include <stdlib.h>
13
15
#include <string.h>
14
16
#include <errno.h>
22
24
#include "session.h"
23
25
#include "configuration.h"
24
26
#include "console-kit.h"
 
27
#include "login1.h"
25
28
#include "guest-account.h"
26
29
 
27
30
enum {
34
37
 
35
38
struct SessionPrivate
36
39
{
 
40
    /* Session type */
 
41
    gchar *session_type;
 
42
 
 
43
    /* Display server running on */
 
44
    DisplayServer *display_server;
 
45
 
37
46
    /* PID of child process */
38
47
    GPid pid;
39
48
 
53
62
    /* User object that matches the current username */
54
63
    User *user;
55
64
 
 
65
    /* PAM service to use */
 
66
    gchar *pam_service;
 
67
 
 
68
    /* TRUE if should run PAM authentication phase */
 
69
    gboolean do_authenticate;
 
70
 
 
71
    /* TRUE if can handle PAM prompts */
 
72
    gboolean is_interactive;
 
73
 
56
74
    /* Messages being requested by PAM */
57
75
    int messages_length;
58
76
    struct pam_message *messages;
62
80
    gboolean authentication_complete;
63
81
    int authentication_result;
64
82
    gchar *authentication_result_string;
65
 
  
 
83
 
66
84
    /* File to log to */
67
85
    gchar *log_filename;
68
 
  
 
86
 
69
87
    /* Seat class */
70
88
    gchar *class;
71
89
 
72
90
    /* tty this session is running on */
73
91
    gchar *tty;
74
 
  
 
92
 
75
93
    /* X display connected to */
76
94
    gchar *xdisplay;
77
 
    XAuthority *xauthority;
78
 
    gboolean xauth_use_system_location;
 
95
    XAuthority *x_authority;
 
96
    gboolean x_authority_use_system_location;
79
97
 
80
98
    /* Remote host this session is being controlled from */
81
99
    gchar *remote_host_name;
83
101
    /* Console kit cookie */
84
102
    gchar *console_kit_cookie;
85
103
 
 
104
    /* login1 session */
 
105
    gchar *login1_session;
 
106
 
86
107
    /* Environment to set in child */
87
108
    GList *env;
 
109
 
 
110
    /* Command to run in child */
 
111
    gchar **argv;
 
112
 
 
113
    /* True if have run command */
 
114
    gboolean command_run;
 
115
 
 
116
    /* TRUE if stopping this session */
 
117
    gboolean stopping;
88
118
};
89
119
 
90
120
/* Maximum length of a string to pass between daemon and session */
91
121
#define MAX_STRING_LENGTH 65535
92
122
 
93
 
G_DEFINE_TYPE (Session, session, G_TYPE_OBJECT);
 
123
static void session_logger_iface_init (LoggerInterface *iface);
 
124
 
 
125
G_DEFINE_TYPE_WITH_CODE (Session, session, G_TYPE_OBJECT,
 
126
                         G_IMPLEMENT_INTERFACE (
 
127
                             LOGGER_TYPE, session_logger_iface_init));
 
128
 
 
129
Session *
 
130
session_new (void)
 
131
{
 
132
    return g_object_new (SESSION_TYPE, NULL);
 
133
}
 
134
 
 
135
void
 
136
session_set_session_type (Session *session, const gchar *session_type)
 
137
{
 
138
    g_return_if_fail (session != NULL);
 
139
    g_free (session->priv->session_type);
 
140
    session->priv->session_type = g_strdup (session_type);
 
141
}
 
142
 
 
143
const gchar *
 
144
session_get_session_type (Session *session)
 
145
{
 
146
    g_return_val_if_fail (session != NULL, NULL);
 
147
    return session->priv->session_type;
 
148
}
 
149
 
 
150
void
 
151
session_set_pam_service (Session *session, const gchar *pam_service)
 
152
{
 
153
    g_return_if_fail (session != NULL);
 
154
    g_free (session->priv->pam_service);
 
155
    session->priv->pam_service = g_strdup (pam_service);
 
156
}
 
157
 
 
158
void
 
159
session_set_username (Session *session, const gchar *username)
 
160
{
 
161
    g_return_if_fail (session != NULL);
 
162
    g_free (session->priv->username);
 
163
    session->priv->username = g_strdup (username);
 
164
}
 
165
 
 
166
void
 
167
session_set_do_authenticate (Session *session, gboolean do_authenticate)
 
168
{
 
169
    g_return_if_fail (session != NULL);
 
170
    session->priv->do_authenticate = do_authenticate;
 
171
}
 
172
 
 
173
void
 
174
session_set_is_interactive (Session *session, gboolean is_interactive)
 
175
{
 
176
    g_return_if_fail (session != NULL);
 
177
    session->priv->is_interactive = is_interactive;
 
178
}
 
179
 
 
180
void
 
181
session_set_is_guest (Session *session, gboolean is_guest)
 
182
{
 
183
    g_return_if_fail (session != NULL);
 
184
    session->priv->is_guest = is_guest;
 
185
}
 
186
 
 
187
gboolean
 
188
session_get_is_guest (Session *session)
 
189
{
 
190
    g_return_val_if_fail (session != NULL, FALSE);
 
191
    return session->priv->is_guest;
 
192
}
94
193
 
95
194
void
96
195
session_set_log_file (Session *session, const gchar *filename)
109
208
}
110
209
 
111
210
void
 
211
session_set_display_server (Session *session, DisplayServer *display_server)
 
212
{
 
213
    g_return_if_fail (session != NULL);
 
214
    g_return_if_fail (display_server != NULL);
 
215
    if (session->priv->display_server)
 
216
    {
 
217
        display_server_disconnect_session (session->priv->display_server, session);
 
218
        g_object_unref (session->priv->display_server);
 
219
    }
 
220
    session->priv->display_server = g_object_ref (display_server);
 
221
}
 
222
 
 
223
DisplayServer *
 
224
session_get_display_server (Session *session)
 
225
{
 
226
    g_return_val_if_fail (session != NULL, NULL);
 
227
    return session->priv->display_server;
 
228
}
 
229
 
 
230
void
112
231
session_set_tty (Session *session, const gchar *tty)
113
232
{
114
233
    g_return_if_fail (session != NULL);
125
244
}
126
245
 
127
246
void
128
 
session_set_xauthority (Session *session, XAuthority *authority, gboolean use_system_location)
 
247
session_set_x_authority (Session *session, XAuthority *authority, gboolean use_system_location)
129
248
{
130
249
    g_return_if_fail (session != NULL);
131
 
    if (session->priv->xauthority)
132
 
        g_object_unref (session->priv->xauthority);
133
 
    session->priv->xauthority = g_object_ref (authority);
134
 
    session->priv->xauth_use_system_location = use_system_location;
 
250
    if (session->priv->x_authority)
 
251
    {
 
252
        g_object_unref (session->priv->x_authority);
 
253
        session->priv->x_authority = NULL;
 
254
    }
 
255
    if (authority)
 
256
        session->priv->x_authority = g_object_ref (authority);
 
257
    session->priv->x_authority_use_system_location = use_system_location;
135
258
}
136
259
 
137
260
void
142
265
    session->priv->remote_host_name = g_strdup (remote_host_name);
143
266
}
144
267
 
 
268
static GList *
 
269
find_env_entry (Session *session, const gchar *name)
 
270
{
 
271
    GList *link;
 
272
 
 
273
    for (link = session->priv->env; link; link = link->next)
 
274
    {
 
275
        const gchar *entry = link->data;
 
276
 
 
277
        if (g_str_has_prefix (entry, name) && entry[strlen (name)] == '=')
 
278
            return link;
 
279
    }
 
280
 
 
281
    return NULL;
 
282
}
 
283
 
145
284
void
146
285
session_set_env (Session *session, const gchar *name, const gchar *value)
147
286
{
148
 
    g_return_if_fail (session != NULL);
149
 
    session->priv->env = g_list_append (session->priv->env, g_strdup_printf ("%s=%s", name, value));
 
287
    GList *link;
 
288
    gchar *entry;
 
289
 
 
290
    g_return_if_fail (session != NULL);
 
291
    g_return_if_fail (value != NULL);
 
292
 
 
293
    entry = g_strdup_printf ("%s=%s", name, value);
 
294
 
 
295
    link = find_env_entry (session, name);
 
296
    if (link)
 
297
    {
 
298
        g_free (link->data);
 
299
        link->data = entry;
 
300
    }
 
301
    else
 
302
        session->priv->env = g_list_append (session->priv->env, entry);
 
303
}
 
304
 
 
305
void
 
306
session_unset_env (Session *session, const gchar *name)
 
307
{
 
308
    GList *link;
 
309
 
 
310
    g_return_if_fail (session != NULL);
 
311
  
 
312
    link = find_env_entry (session, name);
 
313
    if (!link)
 
314
        return;
 
315
 
 
316
    g_free (link->data);
 
317
    session->priv->env = g_list_remove_link (session->priv->env, link);
 
318
}
 
319
 
 
320
void
 
321
session_set_argv (Session *session, gchar **argv)
 
322
{
 
323
    g_return_if_fail (session != NULL);
 
324
    session->priv->argv = g_strdupv (argv);
150
325
}
151
326
 
152
327
User *
167
342
write_data (Session *session, const void *buf, size_t count)
168
343
{
169
344
    if (write (session->priv->to_child_input, buf, count) != count)
170
 
        g_warning ("Error writing to session: %s", strerror (errno));
 
345
        l_warning (session, "Error writing to session: %s", strerror (errno));
171
346
}
172
347
 
173
348
static void
181
356
        write_data (session, value, sizeof (char) * length);
182
357
}
183
358
 
 
359
static void
 
360
write_xauth (Session *session, XAuthority *x_authority)
 
361
{
 
362
    guint16 family;
 
363
    gsize length;
 
364
 
 
365
    if (!x_authority)
 
366
    {
 
367
        write_string (session, NULL);
 
368
        return;
 
369
    }
 
370
 
 
371
    write_string (session, x_authority_get_authorization_name (session->priv->x_authority));
 
372
    family = x_authority_get_family (session->priv->x_authority);
 
373
    write_data (session, &family, sizeof (family));
 
374
    length = x_authority_get_address_length (session->priv->x_authority);
 
375
    write_data (session, &length, sizeof (length));
 
376
    write_data (session, x_authority_get_address (session->priv->x_authority), length);
 
377
    write_string (session, x_authority_get_number (session->priv->x_authority));
 
378
    length = x_authority_get_authorization_data_length (session->priv->x_authority);
 
379
    write_data (session, &length, sizeof (length));
 
380
    write_data (session, x_authority_get_authorization_data (session->priv->x_authority), length);
 
381
}
 
382
 
184
383
static ssize_t
185
384
read_from_child (Session *session, void *buf, size_t count)
186
385
{
187
386
    ssize_t n_read;
188
387
    n_read = read (session->priv->from_child_output, buf, count);
189
388
    if (n_read < 0)
190
 
        g_warning ("Error reading from session: %s", strerror (errno));
 
389
        l_warning (session, "Error reading from session: %s", strerror (errno));
191
390
    return n_read;
192
391
}
193
392
 
203
402
        return NULL;
204
403
    if (length > MAX_STRING_LENGTH)
205
404
    {
206
 
        g_warning ("Invalid string length %d from child", length);
 
405
        l_warning (session, "Invalid string length %d from child", length);
207
406
        return NULL;
208
407
    }
209
 
  
 
408
 
210
409
    value = g_malloc (sizeof (char) * (length + 1));
211
410
    read_from_child (session, value, length);
212
 
    value[length] = '\0';      
 
411
    value[length] = '\0';
213
412
 
214
413
    return value;
215
414
}
219
418
{
220
419
    Session *session = data;
221
420
 
222
 
    session->priv->pid = 0;
223
 
  
224
421
    if (WIFEXITED (status))
225
 
        g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));
 
422
        l_debug (session, "Exited with return value %d", WEXITSTATUS (status));
226
423
    else if (WIFSIGNALED (status))
227
 
        g_debug ("Session %d terminated with signal %d", pid, WTERMSIG (status));
 
424
        l_debug (session, "Terminated with signal %d", WTERMSIG (status));
 
425
 
 
426
    /* do this as late as possible for log messages prefix */
 
427
    session->priv->pid = 0;
228
428
 
229
429
    /* If failed during authentication then report this as an authentication failure */
230
430
    if (session->priv->authentication_started && !session->priv->authentication_complete)
231
431
    {
232
 
        g_debug ("Session %d failed during authentication", pid);
 
432
        l_debug (session, "Failed during authentication");
233
433
        session->priv->authentication_complete = TRUE;
234
434
        session->priv->authentication_result = PAM_CONV_ERR;
235
435
        g_free (session->priv->authentication_result_string);
236
436
        session->priv->authentication_result_string = g_strdup ("Authentication stopped before completion");
237
 
        g_signal_emit (G_OBJECT (session), signals[AUTHENTICATION_COMPLETE], 0);      
 
437
        g_signal_emit (G_OBJECT (session), signals[AUTHENTICATION_COMPLETE], 0);
238
438
    }
239
439
 
240
440
    g_signal_emit (G_OBJECT (session), signals[STOPPED], 0);
278
478
    /* Check if authentication completed */
279
479
    n_read = read_from_child (session, &auth_complete, sizeof (auth_complete));
280
480
    if (n_read < 0)
281
 
        g_debug ("Error reading from child: %s", strerror (errno));
 
481
        l_debug (session, "Error reading from child: %s", strerror (errno));
282
482
    if (n_read <= 0)
283
483
    {
284
484
        session->priv->from_child_watch = 0;
292
492
        g_free (session->priv->authentication_result_string);
293
493
        session->priv->authentication_result_string = read_string_from_child (session);
294
494
 
295
 
        g_debug ("Session %d authentication complete with return value %d: %s", session->priv->pid, session->priv->authentication_result, session->priv->authentication_result_string);
 
495
        l_debug (session, "Authentication complete with return value %d: %s", session->priv->authentication_result, session->priv->authentication_result_string);
296
496
 
297
497
        /* No longer expect any more messages */
298
498
        session->priv->from_child_watch = 0;
311
511
        for (i = 0; i < session->priv->messages_length; i++)
312
512
        {
313
513
            struct pam_message *m = &session->priv->messages[i];
314
 
            read_from_child (session, &m->msg_style, sizeof (m->msg_style));          
 
514
            read_from_child (session, &m->msg_style, sizeof (m->msg_style));
315
515
            m->msg = read_string_from_child (session);
316
516
        }
317
517
 
318
 
        g_debug ("Session %d got %d message(s) from PAM", session->priv->pid, session->priv->messages_length);
 
518
        l_debug (session, "Got %d message(s) from PAM", session->priv->messages_length);
319
519
 
320
520
        g_signal_emit (G_OBJECT (session), signals[GOT_MESSAGES], 0);
321
 
    }    
 
521
    }
322
522
 
323
523
    return TRUE;
324
524
}
325
525
 
326
526
gboolean
327
 
session_start (Session *session, const gchar *service, const gchar *username, gboolean do_authenticate, gboolean is_interactive, gboolean is_guest)
 
527
session_start (Session *session)
 
528
{
 
529
    g_return_val_if_fail (session != NULL, FALSE);
 
530
    return SESSION_GET_CLASS (session)->start (session);
 
531
}
 
532
 
 
533
gboolean
 
534
session_get_is_started (Session *session)
 
535
{
 
536
    return session->priv->pid != 0;
 
537
}
 
538
 
 
539
static gboolean
 
540
session_real_start (Session *session)
328
541
{
329
542
    int version;
330
543
    int to_child_pipe[2], from_child_pipe[2];
331
544
    int to_child_output, from_child_input;
332
545
 
333
 
    g_return_val_if_fail (session != NULL, FALSE);
334
 
    g_return_val_if_fail (service != NULL, FALSE);
335
546
    g_return_val_if_fail (session->priv->pid == 0, FALSE);
336
547
 
 
548
    if (session->priv->display_server)
 
549
        display_server_connect_session (session->priv->display_server, session);
 
550
 
337
551
    /* Create pipes to talk to the child */
338
552
    if (pipe (to_child_pipe) < 0 || pipe (from_child_pipe) < 0)
339
553
    {
352
566
    fcntl (session->priv->from_child_output, F_SETFD, FD_CLOEXEC);
353
567
 
354
568
    /* Create the guest account if it is one */
355
 
    session->priv->is_guest = is_guest;
356
 
    if (is_guest && username == NULL)
357
 
        username = guest_account_setup ();
358
 
 
359
 
    /* Remember what username we started with - it will be updated by PAM during authentication */
360
 
    session->priv->username = g_strdup (username);
 
569
    if (session->priv->is_guest && session->priv->username == NULL)
 
570
    {
 
571
        session->priv->username = guest_account_setup ();
 
572
        if (!session->priv->username)
 
573
            return FALSE;
 
574
    }
361
575
 
362
576
    /* Run the child */
363
577
    session->priv->pid = fork ();
391
605
    /* Close the ends of the pipes we don't need */
392
606
    close (to_child_output);
393
607
    close (from_child_input);
394
 
  
 
608
 
395
609
    /* Indicate what version of the protocol we are using */
396
 
    version = 0;
 
610
    version = 1;
397
611
    write_data (session, &version, sizeof (version));
398
612
 
399
613
    /* Send configuration */
400
 
    write_string (session, service);
401
 
    write_string (session, username);
402
 
    write_data (session, &do_authenticate, sizeof (do_authenticate));
403
 
    write_data (session, &is_interactive, sizeof (is_interactive));
 
614
    write_string (session, session->priv->pam_service);
 
615
    write_string (session, session->priv->username);
 
616
    write_data (session, &session->priv->do_authenticate, sizeof (session->priv->do_authenticate));
 
617
    write_data (session, &session->priv->is_interactive, sizeof (session->priv->is_interactive));
404
618
    write_string (session, session->priv->class);
405
619
    write_string (session, session->priv->tty);
406
620
    write_string (session, session->priv->remote_host_name);
407
621
    write_string (session, session->priv->xdisplay);
408
 
    if (session->priv->xauthority)
409
 
    {
410
 
        guint16 family;
411
 
        gsize length;
412
 
 
413
 
        write_string (session, xauth_get_authorization_name (session->priv->xauthority));
414
 
        family = xauth_get_family (session->priv->xauthority);
415
 
        write_data (session, &family, sizeof (family));
416
 
        length = xauth_get_address_length (session->priv->xauthority);
417
 
        write_data (session, &length, sizeof (length));
418
 
        write_data (session, xauth_get_address (session->priv->xauthority), length);
419
 
        write_string (session, xauth_get_number (session->priv->xauthority));
420
 
        length = xauth_get_authorization_data_length (session->priv->xauthority);
421
 
        write_data (session, &length, sizeof (length));
422
 
        write_data (session, xauth_get_authorization_data (session->priv->xauthority), length);
423
 
    }
424
 
    else
425
 
        write_string (session, NULL);    
426
 
 
427
 
    g_debug ("Started session %d with service '%s', username '%s'", session->priv->pid, service, username);
 
622
    write_xauth (session, session->priv->x_authority);
 
623
 
 
624
    l_debug (session, "Started with service '%s', username '%s'", session->priv->pam_service, session->priv->username);
428
625
 
429
626
    return TRUE;
430
627
}
472
669
    g_return_if_fail (session != NULL);
473
670
    g_return_if_fail (error != PAM_SUCCESS);
474
671
 
475
 
    write_data (session, &error, sizeof (error));  
 
672
    write_data (session, &error, sizeof (error));
476
673
}
477
674
 
478
675
int
511
708
}
512
709
 
513
710
void
514
 
session_run (Session *session, gchar **argv)
 
711
session_run (Session *session)
 
712
{
 
713
    g_return_if_fail (session->priv->display_server != NULL);
 
714
    return SESSION_GET_CLASS (session)->run (session);
 
715
}
 
716
 
 
717
static void
 
718
session_real_run (Session *session)
515
719
{
516
720
    gsize i, argc;
517
 
    gchar *command, *filename;
 
721
    gchar *command, *x_authority_filename;
518
722
    GList *link;
519
723
 
520
724
    g_return_if_fail (session != NULL);
 
725
    g_return_if_fail (!session->priv->command_run);
521
726
    g_return_if_fail (session_get_is_authenticated (session));
522
 
 
523
 
    command = g_strjoinv (" ", argv);
524
 
    g_debug ("Session %d running command %s", session->priv->pid, command);
 
727
    g_return_if_fail (session->priv->argv != NULL);
 
728
    g_return_if_fail (session->priv->pid != 0);
 
729
 
 
730
    display_server_connect_session (session->priv->display_server, session);
 
731
 
 
732
    session->priv->command_run = TRUE;
 
733
 
 
734
    command = g_strjoinv (" ", session->priv->argv);
 
735
    l_debug (session, "Running command %s", command);
525
736
    g_free (command);
526
737
 
527
738
    /* Create authority location */
528
 
    if (session->priv->xauth_use_system_location)
 
739
    if (session->priv->x_authority_use_system_location)
529
740
    {
530
741
        gchar *run_dir, *dir;
531
742
 
532
 
        run_dir = config_get_string (config_get_instance (), "LightDM", "run-directory");          
 
743
        run_dir = config_get_string (config_get_instance (), "LightDM", "run-directory");
533
744
        dir = g_build_filename (run_dir, session->priv->username, NULL);
534
745
        g_free (run_dir);
535
746
 
536
747
        if (g_mkdir_with_parents (dir, S_IRWXU) < 0)
537
 
            g_warning ("Failed to set create system authority dir %s: %s", dir, strerror (errno));          
 
748
            l_warning (session, "Failed to set create system authority dir %s: %s", dir, strerror (errno));
538
749
        if (getuid () == 0)
539
750
        {
540
751
            if (chown (dir, user_get_uid (session_get_user (session)), user_get_gid (session_get_user (session))) < 0)
541
 
                g_warning ("Failed to set ownership of user authority dir: %s", strerror (errno));
 
752
                l_warning (session, "Failed to set ownership of user authority dir: %s", strerror (errno));
542
753
        }
543
754
 
544
 
        filename = g_build_filename (dir, "xauthority", NULL);
 
755
        x_authority_filename = g_build_filename (dir, "xauthority", NULL);
545
756
        g_free (dir);
546
757
    }
547
758
    else
548
 
        filename = g_build_filename (user_get_home_directory (session_get_user (session)), ".Xauthority", NULL);
 
759
        x_authority_filename = g_build_filename (user_get_home_directory (session_get_user (session)), ".Xauthority", NULL);
549
760
 
 
761
    if (session->priv->log_filename)
 
762
        l_debug (session, "Logging to %s", session->priv->log_filename);
550
763
    write_string (session, session->priv->log_filename);
551
 
    write_string (session, filename);
552
 
    g_free (filename);
 
764
    write_string (session, session->priv->tty);
 
765
    write_string (session, x_authority_filename);
 
766
    g_free (x_authority_filename);
 
767
    write_string (session, session->priv->xdisplay);
 
768
    write_xauth (session, session->priv->x_authority);
553
769
    argc = g_list_length (session->priv->env);
554
770
    write_data (session, &argc, sizeof (argc));
555
771
    for (link = session->priv->env; link; link = link->next)
556
772
        write_string (session, (gchar *) link->data);
557
 
    argc = g_strv_length (argv);
 
773
    argc = g_strv_length (session->priv->argv);
558
774
    write_data (session, &argc, sizeof (argc));
559
775
    for (i = 0; i < argc; i++)
560
 
        write_string (session, argv[i]);
 
776
        write_string (session, session->priv->argv[i]);
561
777
 
562
 
    session->priv->console_kit_cookie = read_string_from_child (session);
 
778
    if (login1_is_running ())
 
779
        session->priv->login1_session = read_string_from_child (session);
 
780
    if (!session->priv->login1_session)
 
781
        session->priv->console_kit_cookie = read_string_from_child (session);
563
782
}
564
783
 
565
784
void
566
785
session_lock (Session *session)
567
 
{    
 
786
{
568
787
    g_return_if_fail (session != NULL);
569
788
    if (getuid () == 0)
570
 
        ck_lock_session (session->priv->console_kit_cookie);
 
789
    {
 
790
        if (session->priv->login1_session)
 
791
            login1_lock_session (session->priv->login1_session);
 
792
        else if (session->priv->console_kit_cookie)
 
793
            ck_lock_session (session->priv->console_kit_cookie);
 
794
    }
571
795
}
572
796
 
573
797
void
574
798
session_unlock (Session *session)
575
 
{    
 
799
{
576
800
    g_return_if_fail (session != NULL);
577
801
    if (getuid () == 0)
578
 
        ck_unlock_session (session->priv->console_kit_cookie);
 
802
    {
 
803
        if (session->priv->login1_session)
 
804
            login1_unlock_session (session->priv->login1_session);
 
805
        else if (session->priv->console_kit_cookie)
 
806
            ck_unlock_session (session->priv->console_kit_cookie);
 
807
    }
579
808
}
580
809
 
581
810
void
582
811
session_stop (Session *session)
583
812
{
584
813
    g_return_if_fail (session != NULL);
585
 
  
 
814
 
 
815
    if (session->priv->stopping)
 
816
        return;
 
817
    session->priv->stopping = TRUE;
 
818
 
 
819
    return SESSION_GET_CLASS (session)->stop (session);
 
820
}
 
821
 
 
822
static void
 
823
session_real_stop (Session *session)
 
824
{
 
825
    g_return_if_fail (session != NULL);
 
826
 
586
827
    if (session->priv->pid > 0)
587
828
    {
588
 
        g_debug ("Session %d: Sending SIGTERM", session->priv->pid);
 
829
        l_debug (session, "Sending SIGTERM");
589
830
        kill (session->priv->pid, SIGTERM);
590
831
        // FIXME: Handle timeout
591
832
    }
 
833
    else
 
834
        g_signal_emit (G_OBJECT (session), signals[STOPPED], 0);
592
835
}
593
836
 
594
837
gboolean
595
 
session_get_is_stopped (Session *session)
 
838
session_get_is_stopping (Session *session)
596
839
{
597
 
    g_return_val_if_fail (session != NULL, TRUE);
598
 
    return session->priv->pid == 0;
 
840
    g_return_val_if_fail (session != NULL, FALSE);
 
841
    return session->priv->stopping;
599
842
}
600
843
 
601
844
static void
602
845
session_init (Session *session)
603
846
{
604
847
    session->priv = G_TYPE_INSTANCE_GET_PRIVATE (session, SESSION_TYPE, SessionPrivate);
 
848
    session->priv->log_filename = g_strdup (".xsession-errors");
605
849
}
606
850
 
607
851
static void
610
854
    Session *self = SESSION (object);
611
855
    int i;
612
856
 
 
857
    g_free (self->priv->session_type);
 
858
    if (self->priv->display_server)
 
859
        g_object_unref (self->priv->display_server);
613
860
    if (self->priv->pid)
614
861
        kill (self->priv->pid, SIGKILL);
615
862
    if (self->priv->from_child_channel)
621
868
    g_free (self->priv->username);
622
869
    if (self->priv->user)
623
870
        g_object_unref (self->priv->user);
 
871
    g_free (self->priv->pam_service);
624
872
    for (i = 0; i < self->priv->messages_length; i++)
625
873
        g_free ((char *) self->priv->messages[i].msg);
626
874
    g_free (self->priv->messages);
629
877
    g_free (self->priv->class);
630
878
    g_free (self->priv->tty);
631
879
    g_free (self->priv->xdisplay);
632
 
    if (self->priv->xauthority)
633
 
        g_object_unref (self->priv->xauthority);
 
880
    if (self->priv->x_authority)
 
881
        g_object_unref (self->priv->x_authority);
634
882
    g_free (self->priv->remote_host_name);
 
883
    g_free (self->priv->login1_session);
635
884
    g_free (self->priv->console_kit_cookie);
636
885
    g_list_free_full (self->priv->env, g_free);
 
886
    g_strfreev (self->priv->argv);
637
887
 
638
888
    G_OBJECT_CLASS (session_parent_class)->finalize (object);
639
889
}
643
893
{
644
894
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
645
895
 
 
896
    klass->start = session_real_start;
 
897
    klass->run = session_real_run;
 
898
    klass->stop = session_real_stop;
646
899
    object_class->finalize = session_finalize;
647
900
 
648
901
    g_type_class_add_private (klass, sizeof (SessionPrivate));
653
906
                      G_SIGNAL_RUN_LAST,
654
907
                      G_STRUCT_OFFSET (SessionClass, got_messages),
655
908
                      NULL, NULL,
656
 
                      g_cclosure_marshal_VOID__VOID,
 
909
                      NULL,
657
910
                      G_TYPE_NONE, 0);
658
911
 
659
912
    signals[AUTHENTICATION_COMPLETE] =
662
915
                      G_SIGNAL_RUN_LAST,
663
916
                      G_STRUCT_OFFSET (SessionClass, authentication_complete),
664
917
                      NULL, NULL,
665
 
                      g_cclosure_marshal_VOID__VOID,
 
918
                      NULL,
666
919
                      G_TYPE_NONE, 0);
667
920
 
668
921
    signals[STOPPED] =
671
924
                      G_SIGNAL_RUN_LAST,
672
925
                      G_STRUCT_OFFSET (SessionClass, stopped),
673
926
                      NULL, NULL,
674
 
                      g_cclosure_marshal_VOID__VOID,
 
927
                      NULL,
675
928
                      G_TYPE_NONE, 0);
676
929
}
 
930
 
 
931
static gint
 
932
session_real_logprefix (Logger *self, gchar *buf, gulong buflen)
 
933
{
 
934
    Session *session = SESSION (self);
 
935
    if (session->priv->pid != 0)
 
936
        return g_snprintf (buf, buflen, "Session pid=%d: ", session->priv->pid);
 
937
    else
 
938
        return g_snprintf (buf, buflen, "Session: ");
 
939
}
 
940
 
 
941
static void
 
942
session_logger_iface_init (LoggerInterface *iface)
 
943
{
 
944
    iface->logprefix = &session_real_logprefix;
 
945
}