X-Git-Url: http://andersk.mit.edu/gitweb/gssapi-openssh.git/blobdiff_plain/41b2f31402be54e00944779e69cf43bc23fa413a..b51b59a5fa4fe0bc5dc4ac12a044339d87db206d:/openssh/contrib/gnome-ssh-askpass2.c diff --git a/openssh/contrib/gnome-ssh-askpass2.c b/openssh/contrib/gnome-ssh-askpass2.c index 89a412a..9e8eaf9 100644 --- a/openssh/contrib/gnome-ssh-askpass2.c +++ b/openssh/contrib/gnome-ssh-askpass2.c @@ -36,10 +36,13 @@ * you don't trust your X server. We grab the keyboard always. */ +#define GRAB_TRIES 16 +#define GRAB_WAIT 250 /* milliseconds */ + /* * Compile with: * - * cc `pkg-config --cflags gtk+-2.0` \ + * cc -Wall `pkg-config --cflags gtk+-2.0` \ * gnome-ssh-askpass2.c -o gnome-ssh-askpass \ * `pkg-config --libs gtk+-2.0` * @@ -48,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -84,13 +88,13 @@ passphrase_dialog(char *message) { const char *failed; char *passphrase, *local; - char **messages; - int result, i, grab_server, grab_pointer; - GtkWidget *dialog, *entry, *label; + int result, grab_tries, grab_server, grab_pointer; + GtkWidget *dialog, *entry; GdkGrabStatus status; grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL); grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL); + grab_tries = 0; dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION, @@ -117,23 +121,35 @@ passphrase_dialog(char *message) /* Grab focus */ gtk_widget_show_now(dialog); - if (grab_server) { - gdk_x11_grab_server(); - } if (grab_pointer) { - status = gdk_pointer_grab((GTK_WIDGET(dialog))->window, TRUE, - 0, NULL, NULL, GDK_CURRENT_TIME); - if (status != GDK_GRAB_SUCCESS) { - failed = "mouse"; - goto nograb; + for(;;) { + status = gdk_pointer_grab( + (GTK_WIDGET(dialog))->window, TRUE, 0, NULL, + NULL, GDK_CURRENT_TIME); + if (status == GDK_GRAB_SUCCESS) + break; + usleep(GRAB_WAIT * 1000); + if (++grab_tries > GRAB_TRIES) { + failed = "mouse"; + goto nograb; + } } } - status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window, FALSE, - GDK_CURRENT_TIME); - if (status != GDK_GRAB_SUCCESS) { - failed = "keyboard"; - goto nograbkb; + for(;;) { + status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window, + FALSE, GDK_CURRENT_TIME); + if (status == GDK_GRAB_SUCCESS) + break; + usleep(GRAB_WAIT * 1000); + if (++grab_tries > GRAB_TRIES) { + failed = "keyboard"; + goto nograbkb; + } } + if (grab_server) { + gdk_x11_grab_server(); + } + result = gtk_dialog_run(GTK_DIALOG(dialog)); /* Ungrab */