summaryrefslogtreecommitdiff
path: root/gui/greeter/greeter.c
blob: b7a836741df4dd8123911b012365f3c193cef32f (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * GDM - The GNOME Display Manager
 * Copyright (C) 1998, 1999, 2000 Martin K. Petersen <mkp@mkp.net>
 *
 * 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 <libintl.h>
#include <locale.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>

#if HAVE_PAM
#include <security/pam_appl.h>
#define PW_ENTRY_SIZE PAM_MAX_RESP_SIZE
#else
#define PW_ENTRY_SIZE GDM_MAX_PASS
#endif

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>

#include "gdm-common.h"
#include "gdm-settings-client.h"
#include "gdm-settings-keys.h"

#include "gdm-themed-greeter.h"

#include "gdmcommon.h"

#define SERVER_DBUS_PATH      "/org/gnome/DisplayManager/GreeterServer"
#define SERVER_DBUS_INTERFACE "org.gnome.DisplayManager.GreeterServer"

static DBusGProxy       *settings_proxy = NULL;
static DBusGConnection  *connection     = NULL;
static GdmThemedGreeter *greeter        = NULL;
static DBusGProxy       *server_proxy   = NULL;

static void
on_info (DBusGProxy *proxy,
	 const char *text,
	 gpointer    data)
{
	g_debug ("GREETER INFO: %s", text);

	gdm_greeter_info (GDM_GREETER (greeter), text);
}

static void
on_problem (DBusGProxy *proxy,
	    const char *text,
	    gpointer    data)
{
	g_debug ("GREETER PROBLEM: %s", text);

	gdm_greeter_problem (GDM_GREETER (greeter), text);
}

static void
on_info_query (DBusGProxy *proxy,
	       const char *text,
	       gpointer    data)
{
	g_debug ("GREETER Info query: %s", text);

	gdm_greeter_info_query (GDM_GREETER (greeter), text);
}

static void
on_secret_info_query (DBusGProxy *proxy,
		      const char *text,
		      gpointer    data)
{
	g_debug ("GREETER Secret info query: %s", text);

	gdm_greeter_secret_info_query (GDM_GREETER (greeter), text);
}

static void
on_query_answer (GdmGreeter *greeter,
		 const char *text,
		 gpointer    data)
{
	gboolean res;
	GError  *error;

	g_debug ("GREETER answer: %s", text);

	error = NULL;
	res = dbus_g_proxy_call (server_proxy,
				 "AnswerQuery",
				 &error,
				 G_TYPE_STRING, text,
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (! res) {
		g_warning ("Unable to send AnswerQuery: %s", error->message);
		g_error_free (error);
	}
}

static void
on_select_session (GdmGreeter *greeter,
		   const char *text,
		   gpointer    data)
{
	gboolean res;
	GError  *error;

	g_debug ("GREETER session selected: %s", text);

	error = NULL;
	res = dbus_g_proxy_call (server_proxy,
				 "SelectSession",
				 &error,
				 G_TYPE_STRING, text,
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (! res) {
		g_warning ("Unable to send SelectSession: %s", error->message);
		g_error_free (error);
	}
}

static void
on_select_language (GdmGreeter *greeter,
		    const char *text,
		    gpointer    data)
{
	gboolean res;
	GError  *error;

	g_debug ("GREETER session selected: %s", text);

	error = NULL;
	res = dbus_g_proxy_call (server_proxy,
				 "SelectLanguage",
				 &error,
				 G_TYPE_STRING, text,
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (! res) {
		g_warning ("Unable to send SelectLanguage: %s", error->message);
		g_error_free (error);
	}
}

static void
proxy_destroyed (GObject *object,
		 gpointer data)
{
	g_debug ("GREETER Proxy disconnected");
}

int
main (int argc, char *argv[])
{
	GError           *error;
	const char       *address;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	setlocale (LC_ALL, "");

	g_type_init ();

        if (! gdm_settings_client_init (GDMCONFDIR "/gdm.schemas", "/")) {
                exit (1);
        }

	/*
	 * gdm_common_atspi_launch () needs gdk initialized.
	 * We cannot start gtk before the registry is running
	 * because the atk-bridge will crash.
	 */
	gdk_init (&argc, &argv);
	gdm_common_atspi_launch ();
	gtk_init (&argc, &argv);

	gdm_common_log_init ();

	/*gdm_common_log_set_debug (gdm_settings_client_get_bool (GDM_KEY_DEBUG));*/
	gdm_common_log_set_debug (TRUE);

	address = g_getenv ("GDM_GREETER_DBUS_ADDRESS");
	if (address == NULL) {
		g_warning ("GDM_GREETER_DBUS_ADDRESS not set");
		exit (1);
	}

	g_debug ("GREETER connecting to address: %s", address);

        error = NULL;
        connection = dbus_g_connection_open (address, &error);
        if (connection == NULL) {
                if (error != NULL) {
                        g_warning ("error opening connection: %s", error->message);
                        g_error_free (error);
                } else {
			g_warning ("Unable to open connection");
		}
		exit (1);
        }

	g_debug ("GREETER creating proxy for peer: %s", SERVER_DBUS_PATH);
        server_proxy = dbus_g_proxy_new_for_peer (connection,
						  SERVER_DBUS_PATH,
						  SERVER_DBUS_INTERFACE);
	if (server_proxy == NULL) {
		g_warning ("Unable to create proxy for peer");
		exit (1);
	}

	g_signal_connect (server_proxy, "destroy", G_CALLBACK (proxy_destroyed), NULL);

	/* FIXME: not sure why introspection isn't working */
	dbus_g_proxy_add_signal (server_proxy, "InfoQuery", G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_add_signal (server_proxy, "SecretInfoQuery", G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_add_signal (server_proxy, "Info", G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_add_signal (server_proxy, "Problem", G_TYPE_STRING, G_TYPE_INVALID);

	dbus_g_proxy_connect_signal (server_proxy,
				     "InfoQuery",
				     G_CALLBACK (on_info_query),
				     NULL,
				     NULL);
	dbus_g_proxy_connect_signal (server_proxy,
				     "SecretInfoQuery",
				     G_CALLBACK (on_secret_info_query),
				     NULL,
				     NULL);
	dbus_g_proxy_connect_signal (server_proxy,
				     "Info",
				     G_CALLBACK (on_info),
				     NULL,
				     NULL);
	dbus_g_proxy_connect_signal (server_proxy,
				     "Problem",
				     G_CALLBACK (on_problem),
				     NULL,
				     NULL);

	greeter = gdm_themed_greeter_new ();
	g_signal_connect (greeter,
			  "query-answer",
			  G_CALLBACK (on_query_answer),
			  NULL);
	g_signal_connect (greeter,
			  "session-selected",
			  G_CALLBACK (on_select_session),
			  NULL);
	g_signal_connect (greeter,
			  "language-selected",
			  G_CALLBACK (on_select_language),
			  NULL);

	gtk_main ();

	if (greeter != NULL) {
		g_object_unref (greeter);
	}

	return 0;
}