summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/gnome-ssh-askpass.c61
1 files changed, 41 insertions, 20 deletions
diff --git a/contrib/gnome-ssh-askpass.c b/contrib/gnome-ssh-askpass.c
index fd537e676..5b6f65e88 100644
--- a/contrib/gnome-ssh-askpass.c
+++ b/contrib/gnome-ssh-askpass.c
@@ -49,7 +49,22 @@
49#include <X11/Xlib.h> 49#include <X11/Xlib.h>
50#include <gdk/gdkx.h> 50#include <gdk/gdkx.h>
51 51
52int passphrase_dialog(char **passphrase_p, char *message) 52void
53report_failed_grab (void)
54{
55 GtkWidget *err;
56
57 err = gnome_message_box_new("Could not grab keyboard or mouse.\n"
58 "A malicious client may be eavesdropping on your session.",
59 GNOME_MESSAGE_BOX_ERROR, "EXIT", NULL);
60 gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER);
61 gtk_object_set(GTK_OBJECT(err), "type", GTK_WINDOW_POPUP, NULL);
62
63 gnome_dialog_run_and_close(GNOME_DIALOG(err));
64}
65
66void
67passphrase_dialog(char *message)
53{ 68{
54 char *passphrase; 69 char *passphrase;
55 int result; 70 int result;
@@ -80,41 +95,51 @@ int passphrase_dialog(char **passphrase_p, char *message)
80 95
81 /* Grab focus */ 96 /* Grab focus */
82 XGrabServer(GDK_DISPLAY()); 97 XGrabServer(GDK_DISPLAY());
83 gdk_pointer_grab(dialog->window, TRUE, 0, NULL, NULL, GDK_CURRENT_TIME); 98 if (gdk_pointer_grab(dialog->window, TRUE, 0,
84 gdk_keyboard_grab(dialog->window, FALSE, GDK_CURRENT_TIME); 99 NULL, NULL, GDK_CURRENT_TIME))
100 goto nograb;
101 if (gdk_keyboard_grab(dialog->window, FALSE, GDK_CURRENT_TIME))
102 goto nograbkb;
85 103
86 /* Make <enter> close dialog */ 104 /* Make <enter> close dialog */
87 gnome_dialog_editable_enters(GNOME_DIALOG(dialog), GTK_EDITABLE(entry)); 105 gnome_dialog_editable_enters(GNOME_DIALOG(dialog), GTK_EDITABLE(entry));
88 106
89 /* Run dialog */ 107 /* Run dialog */
90 result = gnome_dialog_run(GNOME_DIALOG(dialog)); 108 result = gnome_dialog_run(GNOME_DIALOG(dialog));
91 109
92 /* Ungrab */ 110 /* Ungrab */
93 XUngrabServer(GDK_DISPLAY()); 111 XUngrabServer(GDK_DISPLAY());
94 gdk_pointer_ungrab(GDK_CURRENT_TIME); 112 gdk_pointer_ungrab(GDK_CURRENT_TIME);
95 gdk_keyboard_ungrab(GDK_CURRENT_TIME); 113 gdk_keyboard_ungrab(GDK_CURRENT_TIME);
96 gdk_flush(); 114 gdk_flush();
97 115
116 /* Report passphrase if user selected OK */
98 passphrase = gtk_entry_get_text(GTK_ENTRY(entry)); 117 passphrase = gtk_entry_get_text(GTK_ENTRY(entry));
99 118 if (result == 0)
100 /* Take copy of passphrase if user selected OK */ 119 puts(passphrase);
101 if (result == 0)
102 *passphrase_p = strdup(passphrase);
103 else
104 *passphrase_p = NULL;
105 120
106 /* Zero existing passphrase */ 121 /* Zero passphrase in memory */
107 memset(passphrase, '\0', strlen(passphrase)); 122 memset(passphrase, '\0', strlen(passphrase));
108 gtk_entry_set_text(GTK_ENTRY(entry), passphrase); 123 gtk_entry_set_text(GTK_ENTRY(entry), passphrase);
109 124
110 gnome_dialog_close(GNOME_DIALOG(dialog)); 125 gnome_dialog_close(GNOME_DIALOG(dialog));
126 return;
111 127
112 return (result == 0); 128 /* At least one grab failed - ungrab what we got, and report
129 the failure to the user. Note that XGrabServer() cannot
130 fail. */
131 nograbkb:
132 gdk_pointer_ungrab(GDK_CURRENT_TIME);
133 nograb:
134 XUngrabServer(GDK_DISPLAY());
135 gnome_dialog_close(GNOME_DIALOG(dialog));
136
137 report_failed_grab();
113} 138}
114 139
115int main(int argc, char **argv) 140int
141main(int argc, char **argv)
116{ 142{
117 char *passphrase;
118 char *message; 143 char *message;
119 144
120 gnome_init("GNOME ssh-askpass", "0.1", argc, argv); 145 gnome_init("GNOME ssh-askpass", "0.1", argc, argv);
@@ -124,11 +149,7 @@ int main(int argc, char **argv)
124 else 149 else
125 message = "Enter your OpenSSH passphrase:"; 150 message = "Enter your OpenSSH passphrase:";
126 151
127 if (passphrase_dialog(&passphrase, message)) 152 setvbuf(stdout, 0, _IONBF, 0);
128 { 153 passphrase_dialog(message);
129 puts(passphrase);
130 memset(passphrase, '\0', strlen(passphrase));
131 }
132
133 return 0; 154 return 0;
134} 155}