diff options
author | Damien Miller <djm@mindrot.org> | 2002-09-05 16:46:24 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2002-09-05 16:46:24 +1000 |
commit | 44d5b60336e2233813083e254a9ca751b7f3c172 (patch) | |
tree | 522a8eda1a191ccef40590317dd3be703853eef0 | |
parent | 539983800df7924a3c43e0c06b8ff2817efa2ce1 (diff) |
- (djm) Add gnome-ssh-askpass2.c (gtk2) by merge with patch from
Nalin Dahyabhai <nalin@redhat.com>
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | contrib/README | 6 | ||||
-rw-r--r-- | contrib/gnome-ssh-askpass1.c (renamed from contrib/gnome-ssh-askpass.c) | 0 | ||||
-rw-r--r-- | contrib/gnome-ssh-askpass2.c | 201 |
4 files changed, 207 insertions, 4 deletions
@@ -5,6 +5,8 @@ | |||
5 | default LoginGraceTime to 2m; 1m may be too short for slow systems. | 5 | default LoginGraceTime to 2m; 1m may be too short for slow systems. |
6 | ok markus@ | 6 | ok markus@ |
7 | - (djm) Merge openssh-TODO.patch from Redhat (null) beta | 7 | - (djm) Merge openssh-TODO.patch from Redhat (null) beta |
8 | - (djm) Add gnome-ssh-askpass2.c (gtk2) by merge with patch from | ||
9 | Nalin Dahyabhai <nalin@redhat.com> | ||
8 | 10 | ||
9 | 20020903 | 11 | 20020903 |
10 | - (djm) Patch from itojun@ for Darwin OS: test getaddrinfo, reorder libcrypt | 12 | - (djm) Patch from itojun@ for Darwin OS: test getaddrinfo, reorder libcrypt |
@@ -1605,4 +1607,4 @@ | |||
1605 | - (stevesk) entropy.c: typo in debug message | 1607 | - (stevesk) entropy.c: typo in debug message |
1606 | - (djm) ssh-keygen -i needs seeded RNG; report from markus@ | 1608 | - (djm) ssh-keygen -i needs seeded RNG; report from markus@ |
1607 | 1609 | ||
1608 | $Id: ChangeLog,v 1.2446 2002/09/05 06:32:02 djm Exp $ | 1610 | $Id: ChangeLog,v 1.2447 2002/09/05 06:46:24 djm Exp $ |
diff --git a/contrib/README b/contrib/README index 648bb2f3a..dde6ccb19 100644 --- a/contrib/README +++ b/contrib/README | |||
@@ -21,10 +21,10 @@ ssh-copy-id: | |||
21 | Phil Hands' <phil@hands.com> shell script to automate the process of adding | 21 | Phil Hands' <phil@hands.com> shell script to automate the process of adding |
22 | your public key to a remote machine's ~/.ssh/authorized_keys file. | 22 | your public key to a remote machine's ~/.ssh/authorized_keys file. |
23 | 23 | ||
24 | gnome-ssh-askpass: | 24 | gnome-ssh-askpass[12]: |
25 | 25 | ||
26 | A GNOME passphrase requester of my own creation. Compilation instructions | 26 | A GNOME/Gtk2 passphrase requester of my own creation. Compilation instructions |
27 | are in the top of the file. | 27 | are in the top of the files. |
28 | 28 | ||
29 | sshd.pam.generic: | 29 | sshd.pam.generic: |
30 | 30 | ||
diff --git a/contrib/gnome-ssh-askpass.c b/contrib/gnome-ssh-askpass1.c index 7cece5620..7cece5620 100644 --- a/contrib/gnome-ssh-askpass.c +++ b/contrib/gnome-ssh-askpass1.c | |||
diff --git a/contrib/gnome-ssh-askpass2.c b/contrib/gnome-ssh-askpass2.c new file mode 100644 index 000000000..8cccf9e60 --- /dev/null +++ b/contrib/gnome-ssh-askpass2.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2000-2002 Damien Miller. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * 1. Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * | ||
13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | |||
25 | /* GTK2 support by Nalin Dahyabhai <nalin@redhat.com> */ | ||
26 | |||
27 | /* | ||
28 | * This is a simple GNOME SSH passphrase grabber. To use it, set the | ||
29 | * environment variable SSH_ASKPASS to point to the location of | ||
30 | * gnome-ssh-askpass before calling "ssh-add < /dev/null". | ||
31 | * | ||
32 | * There is only two run-time options: if you set the environment variable | ||
33 | * "GNOME_SSH_ASKPASS_GRAB_SERVER=true" then gnome-ssh-askpass will grab | ||
34 | * the X server. If you set "GNOME_SSH_ASKPASS_GRAB_POINTER=true", then the | ||
35 | * pointer will be grabbed too. These may have some benefit to security if | ||
36 | * you don't trust your X server. We grab the keyboard always. | ||
37 | */ | ||
38 | |||
39 | /* | ||
40 | * Compile with: | ||
41 | * | ||
42 | * cc `pkg-config --cflags gtk+-2.0` \ | ||
43 | * gnome-ssh-askpass.c -o gnome-ssh-askpass \ | ||
44 | * `pkg-config --libs gtk+-2.0` | ||
45 | * | ||
46 | */ | ||
47 | |||
48 | #include <stdlib.h> | ||
49 | #include <stdio.h> | ||
50 | #include <string.h> | ||
51 | #include <X11/Xlib.h> | ||
52 | #include <gtk/gtk.h> | ||
53 | #include <gdk/gdkx.h> | ||
54 | |||
55 | static void | ||
56 | report_failed_grab (const char *what) | ||
57 | { | ||
58 | GtkWidget *err; | ||
59 | |||
60 | err = gtk_message_dialog_new(NULL, 0, | ||
61 | GTK_MESSAGE_ERROR, | ||
62 | GTK_BUTTONS_CLOSE, | ||
63 | "Could not grab %s. " | ||
64 | "A malicious client may be eavesdropping " | ||
65 | "on your session.", what); | ||
66 | gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER); | ||
67 | gtk_label_set_line_wrap(GTK_LABEL((GTK_MESSAGE_DIALOG(err))->label), | ||
68 | TRUE); | ||
69 | |||
70 | gtk_dialog_run(GTK_DIALOG(err)); | ||
71 | |||
72 | gtk_widget_destroy(err); | ||
73 | } | ||
74 | |||
75 | static void | ||
76 | ok_dialog(GtkWidget *entry, gpointer dialog) | ||
77 | { | ||
78 | g_return_if_fail(GTK_IS_DIALOG(dialog)); | ||
79 | gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | passphrase_dialog(char *message) | ||
84 | { | ||
85 | const char *failed; | ||
86 | char *passphrase, *local; | ||
87 | char **messages; | ||
88 | int result, i, grab_server, grab_pointer; | ||
89 | GtkWidget *dialog, *entry, *label; | ||
90 | GdkGrabStatus status; | ||
91 | |||
92 | grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL); | ||
93 | grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL); | ||
94 | |||
95 | dialog = gtk_message_dialog_new(NULL, 0, | ||
96 | GTK_MESSAGE_QUESTION, | ||
97 | GTK_BUTTONS_OK_CANCEL, | ||
98 | "%s", | ||
99 | message); | ||
100 | |||
101 | entry = gtk_entry_new(); | ||
102 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, | ||
103 | FALSE, 0); | ||
104 | gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); | ||
105 | gtk_widget_grab_focus(entry); | ||
106 | gtk_widget_show(entry); | ||
107 | |||
108 | gtk_window_set_title(GTK_WINDOW(dialog), "OpenSSH"); | ||
109 | gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | ||
110 | gtk_label_set_line_wrap(GTK_LABEL((GTK_MESSAGE_DIALOG(dialog))->label), | ||
111 | TRUE); | ||
112 | |||
113 | /* Make <enter> close dialog */ | ||
114 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); | ||
115 | g_signal_connect(G_OBJECT(entry), "activate", | ||
116 | G_CALLBACK(ok_dialog), dialog); | ||
117 | |||
118 | /* Grab focus */ | ||
119 | gtk_widget_show_now(dialog); | ||
120 | if (grab_server) { | ||
121 | gdk_x11_grab_server(); | ||
122 | } | ||
123 | if (grab_pointer) { | ||
124 | status = gdk_pointer_grab((GTK_WIDGET(dialog))->window, TRUE, | ||
125 | 0, NULL, NULL, GDK_CURRENT_TIME); | ||
126 | if (status != GDK_GRAB_SUCCESS) { | ||
127 | failed = "mouse"; | ||
128 | goto nograb; | ||
129 | } | ||
130 | } | ||
131 | status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window, FALSE, | ||
132 | GDK_CURRENT_TIME); | ||
133 | if (status != GDK_GRAB_SUCCESS) { | ||
134 | failed = "keyboard"; | ||
135 | goto nograbkb; | ||
136 | } | ||
137 | result = gtk_dialog_run(GTK_DIALOG(dialog)); | ||
138 | |||
139 | /* Ungrab */ | ||
140 | if (grab_server) | ||
141 | XUngrabServer(GDK_DISPLAY()); | ||
142 | if (grab_pointer) | ||
143 | gdk_pointer_ungrab(GDK_CURRENT_TIME); | ||
144 | gdk_keyboard_ungrab(GDK_CURRENT_TIME); | ||
145 | gdk_flush(); | ||
146 | |||
147 | /* Report passphrase if user selected OK */ | ||
148 | passphrase = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); | ||
149 | if (result == GTK_RESPONSE_OK) { | ||
150 | local = g_locale_from_utf8(passphrase, strlen(passphrase), | ||
151 | NULL, NULL, NULL); | ||
152 | if (local != NULL) { | ||
153 | puts(local); | ||
154 | memset(local, '\0', strlen(local)); | ||
155 | g_free(local); | ||
156 | } else { | ||
157 | puts(passphrase); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | /* Zero passphrase in memory */ | ||
162 | memset(passphrase, '\b', strlen(passphrase)); | ||
163 | gtk_entry_set_text(GTK_ENTRY(entry), passphrase); | ||
164 | memset(passphrase, '\0', strlen(passphrase)); | ||
165 | g_free(passphrase); | ||
166 | |||
167 | gtk_widget_destroy(dialog); | ||
168 | return; | ||
169 | |||
170 | /* At least one grab failed - ungrab what we got, and report | ||
171 | the failure to the user. Note that XGrabServer() cannot | ||
172 | fail. */ | ||
173 | nograbkb: | ||
174 | gdk_pointer_ungrab(GDK_CURRENT_TIME); | ||
175 | nograb: | ||
176 | if (grab_server) | ||
177 | XUngrabServer(GDK_DISPLAY()); | ||
178 | gtk_widget_destroy(dialog); | ||
179 | |||
180 | report_failed_grab(failed); | ||
181 | } | ||
182 | |||
183 | int | ||
184 | main(int argc, char **argv) | ||
185 | { | ||
186 | char *message; | ||
187 | |||
188 | gtk_init(&argc, &argv); | ||
189 | |||
190 | if (argc > 1) { | ||
191 | message = g_strjoinv(" ", argv + 1); | ||
192 | } else { | ||
193 | message = g_strdup("Enter your OpenSSH passphrase:"); | ||
194 | } | ||
195 | |||
196 | setvbuf(stdout, 0, _IONBF, 0); | ||
197 | passphrase_dialog(message); | ||
198 | g_free(message); | ||
199 | |||
200 | return 0; | ||
201 | } | ||