58
64
g_main_loop_quit (loop);
63
signal_cb (int signum)
67
status_notify ("XSERVER-%d DISCONNECT-CLIENTS", display_number);
71
status_notify ("XSERVER-%d TERMINATE SIGNAL=%d", display_number, signum);
68
sighup_cb (gpointer user_data)
70
status_notify ("%s DISCONNECT-CLIENTS", id);
75
sigint_cb (gpointer user_data)
77
status_notify ("%s TERMINATE SIGNAL=%d", id, SIGINT);
83
sigterm_cb (gpointer user_data)
85
status_notify ("%s TERMINATE SIGNAL=%d", id, SIGTERM);
89
103
xdmcp_willing_cb (XDMCPClient *client, XDMCPWilling *message)
91
gchar **authorization_names;
92
GInetAddress *addresses[2];
94
status_notify ("XSERVER-%d GOT-WILLING AUTHENTICATION-NAME=\"%s\" HOSTNAME=\"%s\" STATUS=\"%s\"", display_number, message->authentication_name, message->hostname, message->status);
96
status_notify ("XSERVER-%d SEND-REQUEST DISPLAY-NUMBER=%d AUTHORIZATION-NAME=\"%s\" MFID=\"%s\"", display_number, display_number, "MIT-MAGIC-COOKIE-1", "TEST XSERVER");
98
authorization_names = g_strsplit ("MIT-MAGIC-COOKIE-1", " ", -1);
99
addresses[0] = xdmcp_client_get_local_address (client);
101
xdmcp_client_send_request (client, display_number,
104
authorization_names, "TEST XSERVER");
105
g_strfreev (authorization_names);
105
status_notify ("%s GOT-WILLING AUTHENTICATION-NAME=\"%s\" HOSTNAME=\"%s\" STATUS=\"%s\"", id, message->authentication_name, message->hostname, message->status);
109
109
xdmcp_accept_cb (XDMCPClient *client, XDMCPAccept *message)
111
status_notify ("XSERVER-%d GOT-ACCEPT SESSION-ID=%d AUTHENTICATION-NAME=\"%s\" AUTHORIZATION-NAME=\"%s\"", display_number, message->session_id, message->authentication_name, message->authorization_name);
111
status_notify ("%s GOT-ACCEPT SESSION-ID=%d AUTHENTICATION-NAME=\"%s\" AUTHORIZATION-NAME=\"%s\"", id, message->session_id, message->authentication_name, message->authorization_name);
113
/* Ignore if haven't picked a valid authorization */
114
if (strcmp (message->authorization_name, "MIT-MAGIC-COOKIE-1") != 0)
113
xdmcp_session_id = message->session_id;
117
115
g_free (xdmcp_cookie);
118
116
xdmcp_cookie_length = message->authorization_data_length;
119
117
xdmcp_cookie = g_malloc (message->authorization_data_length);
120
118
memcpy (xdmcp_cookie, message->authorization_data, message->authorization_data_length);
122
status_notify ("XSERVER-%d SEND-MANAGE SESSION-ID=%d DISPLAY-NUMBER=%d DISPLAY-CLASS=\"%s\"", display_number, message->session_id, display_number, "DISPLAY CLASS");
123
xdmcp_client_send_manage (client, message->session_id, display_number, "DISPLAY CLASS");
127
122
xdmcp_decline_cb (XDMCPClient *client, XDMCPDecline *message)
129
status_notify ("XSERVER-%d GOT-DECLINE STATUS=\"%s\" AUTHENTICATION-NAME=\"%s\"", display_number, message->status, message->authentication_name);
124
status_notify ("%s GOT-DECLINE STATUS=\"%s\" AUTHENTICATION-NAME=\"%s\"", id, message->status, message->authentication_name);
133
128
xdmcp_failed_cb (XDMCPClient *client, XDMCPFailed *message)
135
status_notify ("XSERVER-%d GOT-FAILED SESSION-ID=%d STATUS=\"%s\"", display_number, message->session_id, message->status);
130
status_notify ("%s GOT-FAILED SESSION-ID=%d STATUS=\"%s\"", id, message->session_id, message->status);
139
134
client_connected_cb (XServer *server, XClient *client)
141
gchar *auth_error = NULL;
143
status_notify ("XSERVER-%d ACCEPT-CONNECT", display_number);
146
x_client_send_failed (client, auth_error);
148
x_client_send_success (client);
136
status_notify ("%s ACCEPT-CONNECT", id);
137
x_client_send_success (client);
159
request_cb (const gchar *request)
147
request_cb (const gchar *name, GHashTable *params)
165
151
g_main_loop_quit (loop);
169
r = g_strdup_printf ("XSERVER-%d CRASH", display_number);
170
if (strcmp (request, r) == 0)
155
if (strcmp (name, "CRASH") == 0)
173
158
kill (getpid (), SIGSEGV);
176
r = g_strdup_printf ("XSERVER-%d INDICATE-READY", display_number);
177
if (strcmp (request, r) == 0)
161
else if (strcmp (name, "INDICATE-READY") == 0)
181
165
handler = signal (SIGUSR1, SIG_IGN);
182
166
if (handler == SIG_IGN)
184
status_notify ("XSERVER-%d INDICATE-READY", display_number);
168
status_notify ("%s INDICATE-READY", id);
185
169
kill (getppid (), SIGUSR1);
187
171
signal (SIGUSR1, handler);
190
r = g_strdup_printf ("XSERVER-%d START-XDMCP", display_number);
191
if (strcmp (request, r) == 0)
174
else if (strcmp (name, "START-XDMCP") == 0)
193
176
if (!xdmcp_client_start (xdmcp_client))
194
177
quit (EXIT_FAILURE);
180
else if (strcmp (name, "SEND-REQUEST") == 0)
182
const gchar *addresses_list, *authorization_names_list, *mfid;
183
gchar **list, **authorization_names;
186
GInetAddress **addresses;
188
addresses_list = g_hash_table_lookup (params, "ADDRESSES");
191
authorization_names_list = g_hash_table_lookup (params, "AUTHORIZATION-NAMES");
192
if (!authorization_names_list)
193
authorization_names_list = "";
194
mfid = g_hash_table_lookup (params, "MFID");
198
list = g_strsplit (addresses_list, " ", -1);
199
list_length = g_strv_length (list);
200
addresses = g_malloc (sizeof (GInetAddress *) * (list_length + 1));
201
for (i = 0; i < list_length; i++)
202
addresses[i] = g_inet_address_new_from_string (list[i]);
206
authorization_names = g_strsplit (authorization_names_list, " ", -1);
208
xdmcp_client_send_request (xdmcp_client, display_number,
211
authorization_names, mfid);
212
g_strfreev (authorization_names);
215
else if (strcmp (name, "SEND-MANAGE") == 0)
217
xdmcp_client_send_manage (xdmcp_client, xdmcp_session_id, display_number, "DISPLAY CLASS");
209
231
GString *status_text;
211
signal (SIGINT, signal_cb);
212
signal (SIGTERM, signal_cb);
213
signal (SIGHUP, signal_cb);
215
233
#if !defined(GLIB_VERSION_2_36)
219
237
loop = g_main_loop_new (NULL, FALSE);
221
status_connect (request_cb);
239
g_unix_signal_add (SIGINT, sigint_cb, NULL);
240
g_unix_signal_add (SIGTERM, sigterm_cb, NULL);
241
g_unix_signal_add (SIGHUP, sighup_cb, NULL);
223
243
for (i = 1; i < argc; i++)
313
id = g_strdup_printf ("XSERVER-%d", display_number);
315
status_connect (request_cb, id);
293
317
xserver = x_server_new (display_number);
294
318
g_signal_connect (xserver, "client-connected", G_CALLBACK (client_connected_cb), NULL);
295
319
g_signal_connect (xserver, "client-disconnected", G_CALLBACK (client_disconnected_cb), NULL);
297
321
status_text = g_string_new ("");
298
g_string_printf (status_text, "XSERVER-%d START", display_number);
322
g_string_printf (status_text, "%s START", id);
299
323
if (vt_number >= 0)
300
324
g_string_append_printf (status_text, " VT=%d", vt_number);
301
status_notify (status_text->str);
325
status_notify ("%s", status_text->str);
302
326
g_string_free (status_text, TRUE);
304
328
config = g_key_file_new ();