summaryrefslogtreecommitdiffstats
path: root/meta/packages/gtk+/gtk+-2.10.14/migration.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/gtk+/gtk+-2.10.14/migration.patch')
-rw-r--r--meta/packages/gtk+/gtk+-2.10.14/migration.patch611
1 files changed, 0 insertions, 611 deletions
diff --git a/meta/packages/gtk+/gtk+-2.10.14/migration.patch b/meta/packages/gtk+/gtk+-2.10.14/migration.patch
deleted file mode 100644
index 4ee786e688..0000000000
--- a/meta/packages/gtk+/gtk+-2.10.14/migration.patch
+++ /dev/null
@@ -1,611 +0,0 @@
1Index: configure.in
2===================================================================
3--- configure.in.orig 2006-10-03 17:54:09.000000000 +0100
4+++ configure.in 2006-10-30 12:58:33.000000000 +0000
5@@ -1529,6 +1529,16 @@
6 GTK_EXTRA_CFLAGS="$msnative_struct"
7 fi
8
9+AC_ARG_ENABLE(display-migration,
10+ [AC_HELP_STRING([--enable-display-migration],
11+ [include support for GPE_CHANGE_DISPLAY protocol])],
12+ enable_migration=yes, enable_migration=no)
13+if test "$enable_migration" = "yes"; then
14+ AC_DEFINE([ENABLE_MIGRATION], 1, [Define if display migration is enabled])
15+ GTK_DEP_LIBS="$GTK_DEP_LIBS -lgcrypt"
16+fi
17+AM_CONDITIONAL(ENABLE_MIGRATION, test $enable_migration = "yes")
18+
19 AC_SUBST(GTK_PACKAGES)
20 AC_SUBST(GTK_EXTRA_LIBS)
21 AC_SUBST(GTK_EXTRA_CFLAGS)
22Index: gtk/Makefile.am
23===================================================================
24--- gtk/Makefile.am.orig 2006-10-02 18:27:53.000000000 +0100
25+++ gtk/Makefile.am 2006-10-30 12:59:14.000000000 +0000
26@@ -589,6 +589,11 @@
27 gtkwindow-decorate.c \
28 gtkwindow.c \
29 $(gtk_clipboard_dnd_c_sources)
30+
31+if ENABLE_MIGRATION
32+gtk_base_c_sources += gtkmigration.c
33+endif
34+
35 gtk_c_sources = $(gtk_base_c_sources)
36 gtk_all_c_sources = $(gtk_base_c_sources)
37
38Index: gtk/gtkmain.c
39===================================================================
40--- gtk/gtkmain.c.orig 2006-09-03 06:31:21.000000000 +0100
41+++ gtk/gtkmain.c 2006-10-30 12:56:34.000000000 +0000
42@@ -507,6 +507,10 @@
43 _gtk_accel_map_init ();
44 _gtk_rc_init ();
45
46+#ifdef ENABLE_MIGRATION
47+ gtk_migration_init ();
48+#endif
49+
50 /* Set the 'initialized' flag.
51 */
52 gtk_initialized = TRUE;
53Index: gtk/gtkmigration.c
54===================================================================
55--- /dev/null 1970-01-01 00:00:00.000000000 +0000
56+++ gtk/gtkmigration.c 2006-10-30 12:56:34.000000000 +0000
57@@ -0,0 +1,529 @@
58+/*
59+ * Copyright (C) 2003, 2005 Philip Blundell <philb@gnu.org>
60+ *
61+ * This program is free software; you can redistribute it and/or
62+ * modify it under the terms of the GNU General Public License
63+ * as published by the Free Software Foundation; either version
64+ * 2 of the License, or (at your option) any later version.
65+ */
66+
67+#include <stdlib.h>
68+#include <ctype.h>
69+#include <libintl.h>
70+#include <string.h>
71+#include <assert.h>
72+
73+#include <X11/X.h>
74+#include <X11/Xlib.h>
75+#include <X11/Xatom.h>
76+
77+#include <gcrypt.h>
78+
79+#include "gtk.h"
80+#include "gdk.h"
81+#include "x11/gdkx.h"
82+
83+#define _(x) gettext(x)
84+
85+static GdkAtom string_gdkatom, display_change_gdkatom;
86+static GdkAtom rsa_challenge_gdkatom;
87+
88+#define DISPLAY_CHANGE_SUCCESS 0
89+#define DISPLAY_CHANGE_UNABLE_TO_CONNECT 1
90+#define DISPLAY_CHANGE_NO_SUCH_SCREEN 2
91+#define DISPLAY_CHANGE_AUTHENTICATION_BAD 3
92+#define DISPLAY_CHANGE_INDETERMINATE_ERROR 4
93+
94+static gboolean no_auth;
95+
96+static GSList *all_widgets;
97+
98+static gboolean gtk_migration_initialised;
99+
100+#define CHALLENGE_LEN 64
101+
102+gchar *gtk_migration_auth_challenge_string;
103+
104+static unsigned char challenge_bytes[CHALLENGE_LEN];
105+static unsigned long challenge_seq;
106+
107+#define hexbyte(x) ((x) >= 10 ? (x) + 'a' - 10 : (x) + '0')
108+
109+struct rsa_key
110+{
111+ gcry_mpi_t n, e, d, p, q, u;
112+};
113+
114+static gcry_mpi_t
115+mpi_from_sexp (gcry_sexp_t r, char *tag)
116+{
117+ gcry_sexp_t s = gcry_sexp_find_token (r, tag, 0);
118+ return gcry_sexp_nth_mpi (s, 1, GCRYMPI_FMT_USG);
119+}
120+
121+static char *
122+hex_from_mpi (gcry_mpi_t m)
123+{
124+ char *buf;
125+ gcry_mpi_aprint (GCRYMPI_FMT_HEX, (void *)&buf, NULL, m);
126+ return buf;
127+}
128+
129+static void
130+gtk_migration_crypt_create_hash (char *display, char *challenge, size_t len, char *result)
131+{
132+ size_t dlen = strlen (display);
133+ gchar *buf = g_malloc (dlen + 1 + len);
134+ strcpy (buf, display);
135+ memcpy (buf + dlen + 1, challenge, len);
136+ gcry_md_hash_buffer (GCRY_MD_SHA1, result, buf, len + dlen + 1);
137+ g_free (buf);
138+}
139+
140+static int
141+do_encode_md (const unsigned char *digest, size_t digestlen, int algo,
142+ unsigned int nbits, gcry_mpi_t *r_val)
143+{
144+ int nframe = (nbits+7) / 8;
145+ unsigned char *frame;
146+ int i, n;
147+ unsigned char asn[100];
148+ size_t asnlen;
149+
150+ asnlen = sizeof(asn);
151+ if (gcry_md_algo_info (algo, GCRYCTL_GET_ASNOID, asn, &asnlen))
152+ return -1;
153+
154+ if (digestlen + asnlen + 4 > nframe )
155+ return -1;
156+
157+ /* We encode the MD in this way:
158+ *
159+ * 0 1 PAD(n bytes) 0 ASN(asnlen bytes) MD(len bytes)
160+ *
161+ * PAD consists of FF bytes.
162+ */
163+ frame = g_malloc (nframe);
164+ n = 0;
165+ frame[n++] = 0;
166+ frame[n++] = 1; /* block type */
167+ i = nframe - digestlen - asnlen -3 ;
168+ assert ( i > 1 );
169+ memset ( frame+n, 0xff, i ); n += i;
170+ frame[n++] = 0;
171+ memcpy ( frame+n, asn, asnlen ); n += asnlen;
172+ memcpy ( frame+n, digest, digestlen ); n += digestlen;
173+ assert ( n == nframe );
174+
175+ gcry_mpi_scan (r_val, GCRYMPI_FMT_USG, frame, nframe, &nframe);
176+ g_free (frame);
177+ return 0;
178+}
179+
180+static gboolean
181+gtk_migration_crypt_check_signature (struct rsa_key *k, char *hash, char *sigbuf)
182+{
183+ gcry_mpi_t mpi, mpi2;
184+ gcry_sexp_t data, sig, key;
185+ int rc;
186+
187+ do_encode_md (hash, 20, GCRY_MD_SHA1, 1024, &mpi);
188+
189+ gcry_sexp_build (&data, NULL, "(data (value %m))", mpi);
190+
191+ gcry_mpi_release (mpi);
192+
193+ gcry_sexp_build (&key, NULL, "(public-key (rsa (n %m) (e %m)))", k->n, k->e);
194+
195+ if (gcry_mpi_scan (&mpi2, GCRYMPI_FMT_HEX, sigbuf, 0, NULL))
196+ {
197+ gcry_sexp_release (data);
198+ return FALSE;
199+ }
200+
201+ gcry_sexp_build (&sig, NULL, "(sig-val (rsa (s %m)))", mpi2);
202+
203+ rc = gcry_pk_verify (sig, data, key);
204+
205+ gcry_sexp_release (data);
206+ gcry_sexp_release (key);
207+ gcry_sexp_release (sig);
208+ gcry_mpi_release (mpi2);
209+
210+ if (rc)
211+ return FALSE;
212+
213+ return TRUE;
214+}
215+
216+static void
217+gtk_migration_auth_update_challenge (void)
218+{
219+ int i;
220+ unsigned char *p;
221+
222+ if (gtk_migration_auth_challenge_string == NULL)
223+ gtk_migration_auth_challenge_string = g_malloc ((CHALLENGE_LEN * 2) + 9);
224+
225+ p = gtk_migration_auth_challenge_string;
226+
227+ for (i = 0; i < CHALLENGE_LEN; i++)
228+ {
229+ *p++ = hexbyte (challenge_bytes[i] >> 4);
230+ *p++ = hexbyte (challenge_bytes[i] & 15);
231+ }
232+
233+ sprintf (p, "%08lx", challenge_seq++);
234+}
235+
236+static void
237+gtk_migration_auth_generate_challenge (void)
238+{
239+ gcry_randomize (challenge_bytes, sizeof (challenge_bytes), GCRY_STRONG_RANDOM);
240+ gtk_migration_auth_update_challenge ();
241+}
242+
243+static struct rsa_key *
244+parse_pubkey (char *s)
245+{
246+ struct rsa_key *r;
247+ gcry_mpi_t n, e;
248+ gchar *sp;
249+
250+ sp = strtok (s, " \n");
251+ gcry_mpi_scan (&e, GCRYMPI_FMT_HEX, sp, 0, NULL);
252+ sp = strtok (NULL, " \n");
253+ gcry_mpi_scan (&n, GCRYMPI_FMT_HEX, sp, 0, NULL);
254+
255+ r = g_malloc0 (sizeof (struct rsa_key));
256+ r->e = e;
257+ r->n = n;
258+ return r;
259+}
260+
261+static struct rsa_key *
262+lookup_pubkey (u_int32_t id)
263+{
264+ const gchar *home_dir = g_get_home_dir ();
265+ gchar *filename = g_strdup_printf ("%s/.gpe/migrate/public", home_dir);
266+ FILE *fp = fopen (filename, "r");
267+ struct rsa_key *r = NULL;
268+
269+ if (fp)
270+ {
271+ while (!feof (fp))
272+ {
273+ char buffer[4096];
274+ if (fgets (buffer, 4096, fp))
275+ {
276+ char *p;
277+ u_int32_t this_id = strtoul (buffer, &p, 16);
278+ if (p != buffer && *p == ' ')
279+ {
280+#ifdef DEBUG
281+ fprintf (stderr, "found id %x\n", this_id);
282+#endif
283+ if (this_id == id)
284+ {
285+ r = parse_pubkey (++p);
286+ break;
287+ }
288+ }
289+ }
290+ }
291+ fclose (fp);
292+ }
293+
294+ g_free (filename);
295+ return r;
296+}
297+
298+static void
299+free_pubkey (struct rsa_key *k)
300+{
301+ gcry_mpi_release (k->n);
302+ gcry_mpi_release (k->e);
303+
304+ g_free (k);
305+}
306+
307+static gboolean
308+gtk_migration_auth_validate_request (char *display, char *data)
309+{
310+ u_int32_t key_id;
311+ char *ep;
312+ char *p;
313+ struct rsa_key *k;
314+ char hash[20];
315+ gboolean rc;
316+
317+ p = strchr (data, ' ');
318+ if (p == NULL)
319+ return FALSE;
320+ *p++ = 0;
321+
322+ key_id = strtoul (data, &ep, 16);
323+ if (*ep)
324+ return FALSE;
325+
326+ k = lookup_pubkey (key_id);
327+ if (k == NULL)
328+ return FALSE;
329+
330+ gtk_migration_crypt_create_hash (display, gtk_migration_auth_challenge_string,
331+ strlen (gtk_migration_auth_challenge_string), hash);
332+
333+ rc = gtk_migration_crypt_check_signature (k, hash, p);
334+
335+ free_pubkey (k);
336+
337+ return rc;
338+}
339+
340+static int
341+do_change_display (GtkWidget *w, char *display_name)
342+{
343+ GdkDisplay *newdisplay;
344+ guint screen_nr = 1;
345+ guint i;
346+
347+ if (display_name[0] == 0)
348+ return DISPLAY_CHANGE_INDETERMINATE_ERROR;
349+
350+ i = strlen (display_name) - 1;
351+ while (i > 0 && isdigit (display_name[i]))
352+ i--;
353+
354+ if (display_name[i] == '.')
355+ {
356+ screen_nr = atoi (display_name + i + 1);
357+ display_name[i] = 0;
358+ }
359+
360+ newdisplay = gdk_display_open (display_name);
361+ if (newdisplay)
362+ {
363+ GdkScreen *screen = gdk_display_get_screen (newdisplay, screen_nr);
364+ if (screen)
365+ {
366+ gtk_window_set_screen (GTK_WINDOW (w), screen);
367+ gdk_display_manager_set_default_display (gdk_display_manager_get (),
368+ newdisplay);
369+ return DISPLAY_CHANGE_SUCCESS;
370+ }
371+ else
372+ return DISPLAY_CHANGE_NO_SUCH_SCREEN;
373+ }
374+
375+ return DISPLAY_CHANGE_UNABLE_TO_CONNECT;
376+}
377+
378+static void
379+set_challenge_on_window (GdkWindow *window)
380+{
381+ gdk_property_change (window, rsa_challenge_gdkatom, string_gdkatom,
382+ 8, GDK_PROP_MODE_REPLACE, gtk_migration_auth_challenge_string,
383+ strlen (gtk_migration_auth_challenge_string));
384+}
385+
386+static void
387+update_challenge_on_windows (void)
388+{
389+ GSList *i;
390+
391+ gtk_migration_auth_update_challenge ();
392+
393+ for (i = all_widgets; i; i = i->next)
394+ {
395+ GtkWidget *w = GTK_WIDGET (i->data);
396+ if (w->window)
397+ set_challenge_on_window (w->window);
398+ }
399+}
400+
401+static void
402+reset_state (GdkWindow *window)
403+{
404+ gdk_property_change (window, display_change_gdkatom, string_gdkatom,
405+ 8, GDK_PROP_MODE_REPLACE, NULL, 0);
406+}
407+
408+static void
409+generate_response (GdkDisplay *gdisplay, Display *dpy, Window window, int code)
410+{
411+ XClientMessageEvent ev;
412+ Atom atom = gdk_x11_atom_to_xatom_for_display (gdisplay,
413+ display_change_gdkatom);
414+
415+ memset (&ev, 0, sizeof (ev));
416+
417+ ev.type = ClientMessage;
418+ ev.window = window;
419+ ev.message_type = atom;
420+ ev.format = 32;
421+
422+ ev.data.l[0] = window;
423+ ev.data.l[1] = code;
424+
425+ XSendEvent (dpy, DefaultRootWindow (dpy), False, SubstructureNotifyMask, (XEvent *)&ev);
426+}
427+
428+static int
429+handle_request (GdkWindow *gwindow, char *prop)
430+{
431+ GtkWidget *widget;
432+ char *target, *auth_method, *auth_data;
433+ char *p;
434+
435+ target = prop;
436+ auth_method = "NULL";
437+ auth_data = NULL;
438+
439+ p = strchr (prop, ' ');
440+ if (p)
441+ {
442+ *p = 0;
443+ auth_method = ++p;
444+
445+ p = strchr (p, ' ');
446+ if (p)
447+ {
448+ *p = 0;
449+ auth_data = ++p;
450+ }
451+ }
452+
453+ if (no_auth == FALSE)
454+ {
455+ if (!strcasecmp (auth_method, "null"))
456+ return DISPLAY_CHANGE_AUTHENTICATION_BAD;
457+ else if (!strcasecmp (auth_method, "rsa-sig"))
458+ {
459+ if (gtk_migration_auth_validate_request (target, auth_data) == FALSE)
460+ return DISPLAY_CHANGE_AUTHENTICATION_BAD;
461+ }
462+ else
463+ return DISPLAY_CHANGE_AUTHENTICATION_BAD;
464+ }
465+
466+ gdk_window_get_user_data (gwindow, (gpointer*) &widget);
467+
468+ if (widget)
469+ return do_change_display (widget, target);
470+
471+ return DISPLAY_CHANGE_INDETERMINATE_ERROR;
472+}
473+
474+static GdkFilterReturn
475+filter_func (GdkXEvent *xevp, GdkEvent *ev, gpointer p)
476+{
477+ XPropertyEvent *xev = (XPropertyEvent *)xevp;
478+
479+ if (xev->type == PropertyNotify)
480+ {
481+ GdkDisplay *gdisplay;
482+ Atom atom;
483+
484+ gdisplay = gdk_x11_lookup_xdisplay (xev->display);
485+ if (gdisplay)
486+ {
487+ atom = gdk_x11_atom_to_xatom_for_display (gdisplay, display_change_gdkatom);
488+
489+ if (xev->atom == atom)
490+ {
491+ GdkWindow *gwindow;
492+
493+ gwindow = gdk_window_lookup_for_display (gdisplay, xev->window);
494+
495+ if (gwindow)
496+ {
497+ GdkAtom actual_type;
498+ gint actual_format;
499+ gint actual_length;
500+ unsigned char *prop = NULL;
501+
502+ if (gdk_property_get (gwindow, display_change_gdkatom, string_gdkatom,
503+ 0, G_MAXLONG, FALSE, &actual_type, &actual_format,
504+ &actual_length, &prop))
505+ {
506+ if (actual_length != 0)
507+ {
508+ if (actual_type == string_gdkatom && actual_length > 8)
509+ {
510+ gchar *buf = g_malloc (actual_length + 1);
511+ int rc;
512+
513+ memcpy (buf, prop, actual_length);
514+ buf[actual_length] = 0;
515+
516+ rc = handle_request (gwindow, buf);
517+
518+ g_free (buf);
519+ generate_response (gdisplay, xev->display, xev->window, rc);
520+
521+ if (rc == DISPLAY_CHANGE_SUCCESS)
522+ update_challenge_on_windows ();
523+ }
524+
525+ reset_state (gwindow);
526+ }
527+ }
528+
529+ if (prop)
530+ g_free (prop);
531+ }
532+ }
533+
534+ return GDK_FILTER_REMOVE;
535+ }
536+ }
537+
538+ return GDK_FILTER_CONTINUE;
539+}
540+
541+static void
542+unrealize_window (GtkWidget *w)
543+{
544+ all_widgets = g_slist_remove (all_widgets, w);
545+}
546+
547+void
548+gtk_migration_mark_window (GtkWidget *w)
549+{
550+ if (! gtk_migration_initialised)
551+ {
552+ g_warning ("gtk_migration not initialised yet");
553+ return;
554+ }
555+
556+ if (GTK_WIDGET_REALIZED (w))
557+ {
558+ GdkWindow *window = w->window;
559+
560+ gdk_window_add_filter (window, filter_func, NULL);
561+
562+ reset_state (window);
563+ set_challenge_on_window (window);
564+
565+ all_widgets = g_slist_append (all_widgets, w);
566+
567+ g_signal_connect (G_OBJECT (w), "unrealize", G_CALLBACK (unrealize_window), NULL);
568+ }
569+ else
570+ g_signal_connect (G_OBJECT (w), "realize", G_CALLBACK (gtk_migration_mark_window), NULL);
571+}
572+
573+void
574+gtk_migration_init (void)
575+{
576+ if (getenv ("GPE_DISPLAY_MIGRATION_NO_AUTH") != NULL)
577+ no_auth = TRUE;
578+
579+ string_gdkatom = gdk_atom_intern ("STRING", FALSE);
580+ display_change_gdkatom = gdk_atom_intern ("_GPE_DISPLAY_CHANGE", FALSE);
581+ rsa_challenge_gdkatom = gdk_atom_intern ("_GPE_DISPLAY_CHANGE_RSA_CHALLENGE", FALSE);
582+
583+ gtk_migration_auth_generate_challenge ();
584+
585+ gtk_migration_initialised = TRUE;
586+}
587Index: gtk/gtkwindow.c
588===================================================================
589--- gtk/gtkwindow.c.orig 2006-10-03 16:51:46.000000000 +0100
590+++ gtk/gtkwindow.c 2006-10-30 12:56:34.000000000 +0000
591@@ -50,6 +50,9 @@
592 #include "x11/gdkx.h"
593 #endif
594
595+extern void gtk_migration_mark_window (GtkWidget *w);
596+
597+
598 enum {
599 SET_FOCUS,
600 FRAME_EVENT,
601@@ -823,6 +826,10 @@
602
603 g_signal_connect (window->screen, "composited_changed",
604 G_CALLBACK (gtk_window_on_composited_changed), window);
605+
606+#ifdef ENABLE_MIGRATION
607+ gtk_migration_mark_window (window);
608+#endif
609 }
610
611 static void