summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/gnome-ssh-askpass2.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/contrib/gnome-ssh-askpass2.c b/contrib/gnome-ssh-askpass2.c
index 89a412aa8..9e8eaf920 100644
--- a/contrib/gnome-ssh-askpass2.c
+++ b/contrib/gnome-ssh-askpass2.c
@@ -36,10 +36,13 @@
36 * you don't trust your X server. We grab the keyboard always. 36 * you don't trust your X server. We grab the keyboard always.
37 */ 37 */
38 38
39#define GRAB_TRIES 16
40#define GRAB_WAIT 250 /* milliseconds */
41
39/* 42/*
40 * Compile with: 43 * Compile with:
41 * 44 *
42 * cc `pkg-config --cflags gtk+-2.0` \ 45 * cc -Wall `pkg-config --cflags gtk+-2.0` \
43 * gnome-ssh-askpass2.c -o gnome-ssh-askpass \ 46 * gnome-ssh-askpass2.c -o gnome-ssh-askpass \
44 * `pkg-config --libs gtk+-2.0` 47 * `pkg-config --libs gtk+-2.0`
45 * 48 *
@@ -48,6 +51,7 @@
48#include <stdlib.h> 51#include <stdlib.h>
49#include <stdio.h> 52#include <stdio.h>
50#include <string.h> 53#include <string.h>
54#include <unistd.h>
51#include <X11/Xlib.h> 55#include <X11/Xlib.h>
52#include <gtk/gtk.h> 56#include <gtk/gtk.h>
53#include <gdk/gdkx.h> 57#include <gdk/gdkx.h>
@@ -84,13 +88,13 @@ passphrase_dialog(char *message)
84{ 88{
85 const char *failed; 89 const char *failed;
86 char *passphrase, *local; 90 char *passphrase, *local;
87 char **messages; 91 int result, grab_tries, grab_server, grab_pointer;
88 int result, i, grab_server, grab_pointer; 92 GtkWidget *dialog, *entry;
89 GtkWidget *dialog, *entry, *label;
90 GdkGrabStatus status; 93 GdkGrabStatus status;
91 94
92 grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL); 95 grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL);
93 grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL); 96 grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL);
97 grab_tries = 0;
94 98
95 dialog = gtk_message_dialog_new(NULL, 0, 99 dialog = gtk_message_dialog_new(NULL, 0,
96 GTK_MESSAGE_QUESTION, 100 GTK_MESSAGE_QUESTION,
@@ -117,23 +121,35 @@ passphrase_dialog(char *message)
117 121
118 /* Grab focus */ 122 /* Grab focus */
119 gtk_widget_show_now(dialog); 123 gtk_widget_show_now(dialog);
120 if (grab_server) {
121 gdk_x11_grab_server();
122 }
123 if (grab_pointer) { 124 if (grab_pointer) {
124 status = gdk_pointer_grab((GTK_WIDGET(dialog))->window, TRUE, 125 for(;;) {
125 0, NULL, NULL, GDK_CURRENT_TIME); 126 status = gdk_pointer_grab(
126 if (status != GDK_GRAB_SUCCESS) { 127 (GTK_WIDGET(dialog))->window, TRUE, 0, NULL,
127 failed = "mouse"; 128 NULL, GDK_CURRENT_TIME);
128 goto nograb; 129 if (status == GDK_GRAB_SUCCESS)
130 break;
131 usleep(GRAB_WAIT * 1000);
132 if (++grab_tries > GRAB_TRIES) {
133 failed = "mouse";
134 goto nograb;
135 }
129 } 136 }
130 } 137 }
131 status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window, FALSE, 138 for(;;) {
132 GDK_CURRENT_TIME); 139 status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window,
133 if (status != GDK_GRAB_SUCCESS) { 140 FALSE, GDK_CURRENT_TIME);
134 failed = "keyboard"; 141 if (status == GDK_GRAB_SUCCESS)
135 goto nograbkb; 142 break;
143 usleep(GRAB_WAIT * 1000);
144 if (++grab_tries > GRAB_TRIES) {
145 failed = "keyboard";
146 goto nograbkb;
147 }
136 } 148 }
149 if (grab_server) {
150 gdk_x11_grab_server();
151 }
152
137 result = gtk_dialog_run(GTK_DIALOG(dialog)); 153 result = gtk_dialog_run(GTK_DIALOG(dialog));
138 154
139 /* Ungrab */ 155 /* Ungrab */