]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat-xvnc.c
Load all users only when really needed
[sojka/lightdm.git] / src / seat-xvnc.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 #include <string.h>
13
14 #include "seat-xvnc.h"
15 #include "x-server-xvnc.h"
16 #include "configuration.h"
17
18 G_DEFINE_TYPE (SeatXVNC, seat_xvnc, SEAT_TYPE);
19
20 struct SeatXVNCPrivate
21 {
22     /* VNC connection */
23     GSocket *connection;
24 };
25
26 SeatXVNC *seat_xvnc_new (GSocket *connection)
27 {
28     SeatXVNC *seat;
29
30     seat = g_object_new (SEAT_XVNC_TYPE, NULL);
31     seat->priv->connection = g_object_ref (connection);
32
33     return seat;
34 }
35
36 static DisplayServer *
37 seat_xvnc_create_display_server (Seat *seat, Session *session)
38 {
39     XServerXVNC *x_server;
40     gchar *number;
41     XAuthority *cookie;
42     const gchar *command = NULL;
43
44     if (strcmp (session_get_session_type (session), "x") != 0)
45         return NULL;
46
47     x_server = x_server_xvnc_new ();
48     number = g_strdup_printf ("%d", x_server_get_display_number (X_SERVER (x_server)));
49     cookie = x_authority_new_local_cookie (number);
50     x_server_set_authority (X_SERVER (x_server), cookie);
51     g_free (number);
52     g_object_unref (cookie);
53     x_server_xvnc_set_socket (x_server, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
54
55     command = config_get_string (config_get_instance (), "VNCServer", "command");
56     if (command)
57         x_server_local_set_command (X_SERVER_LOCAL (x_server), command);
58
59     if (config_has_key (config_get_instance (), "VNCServer", "width") &&
60         config_has_key (config_get_instance (), "VNCServer", "height"))
61     {
62         gint width, height;
63         width = config_get_integer (config_get_instance (), "VNCServer", "width");
64         height = config_get_integer (config_get_instance (), "VNCServer", "height");
65         if (height > 0 && width > 0)
66             x_server_xvnc_set_geometry (x_server, width, height);
67     }
68     if (config_has_key (config_get_instance (), "VNCServer", "depth"))
69     {
70         gint depth;
71         depth = config_get_integer (config_get_instance (), "VNCServer", "depth");
72         if (depth == 8 || depth == 16 || depth == 24 || depth == 32)
73             x_server_xvnc_set_depth (x_server, depth);
74     }
75
76     return DISPLAY_SERVER (x_server);
77 }
78
79 static void
80 seat_xvnc_run_script (Seat *seat, DisplayServer *display_server, Process *script)
81 {
82     XServerXVNC *x_server;
83     GInetSocketAddress *address;
84     gchar *hostname;
85     const gchar *path;
86
87     x_server = X_SERVER_XVNC (display_server);
88
89     address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
90     hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
91     path = x_server_local_get_authority_file_path (X_SERVER_LOCAL (x_server));
92
93     process_set_env (script, "REMOTE_HOST", hostname);
94     process_set_env (script, "DISPLAY", x_server_get_address (X_SERVER (x_server)));
95     process_set_env (script, "XAUTHORITY", path);
96
97     g_free (hostname);
98
99     SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display_server, script);
100 }
101
102 static void
103 seat_xvnc_init (SeatXVNC *seat)
104 {
105     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_XVNC_TYPE, SeatXVNCPrivate);
106 }
107
108 static void
109 seat_xvnc_session_finalize (GObject *object)
110 {
111     SeatXVNC *self = SEAT_XVNC (object);
112
113     g_clear_object (&self->priv->connection);
114
115     G_OBJECT_CLASS (seat_xvnc_parent_class)->finalize (object);
116 }
117
118 static void
119 seat_xvnc_class_init (SeatXVNCClass *klass)
120 {
121     SeatClass *seat_class = SEAT_CLASS (klass);
122     GObjectClass *object_class = G_OBJECT_CLASS (klass);
123
124     seat_class->create_display_server = seat_xvnc_create_display_server;
125     seat_class->run_script = seat_xvnc_run_script;
126     object_class->finalize = seat_xvnc_session_finalize;
127
128     g_type_class_add_private (klass, sizeof (SeatXVNCPrivate));
129 }