123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <gnome.h>
- #include <X11/Xlib.h>
- #include <gdk/gdkx.h>
- void
- report_failed_grab (void)
- {
- GtkWidget *err;
- err = gnome_message_box_new("Could not grab keyboard or mouse.\n"
- "A malicious client may be eavesdropping on your session.",
- GNOME_MESSAGE_BOX_ERROR, "EXIT", NULL);
- gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER);
- gtk_object_set(GTK_OBJECT(err), "type", GTK_WINDOW_POPUP, NULL);
- gnome_dialog_run_and_close(GNOME_DIALOG(err));
- }
- int
- passphrase_dialog(char *message)
- {
- char *passphrase;
- char **messages;
- int result, i, grab_server, grab_pointer;
- GtkWidget *dialog, *entry, *label;
- grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL);
- grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL);
- dialog = gnome_dialog_new("OpenSSH", GNOME_STOCK_BUTTON_OK,
- GNOME_STOCK_BUTTON_CANCEL, NULL);
- messages = g_strsplit(message, "\\n", 0);
- if (messages)
- for(i = 0; messages[i]; i++) {
- label = gtk_label_new(messages[i]);
- gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
- label, FALSE, FALSE, 0);
- }
- entry = gtk_entry_new();
- gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox), entry, FALSE,
- FALSE, 0);
- gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
- gtk_widget_grab_focus(entry);
-
- gtk_object_set(GTK_OBJECT(dialog), "type", GTK_WINDOW_POPUP, NULL);
- gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
- gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
- gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE);
- gnome_dialog_close_hides(GNOME_DIALOG(dialog), TRUE);
- gtk_container_set_border_width(GTK_CONTAINER(GNOME_DIALOG(dialog)->vbox),
- GNOME_PAD);
- gtk_widget_show_all(dialog);
-
- if (grab_server)
- XGrabServer(GDK_DISPLAY());
- if (grab_pointer && gdk_pointer_grab(dialog->window, TRUE, 0,
- NULL, NULL, GDK_CURRENT_TIME))
- goto nograb;
- if (gdk_keyboard_grab(dialog->window, FALSE, GDK_CURRENT_TIME))
- goto nograbkb;
-
- gnome_dialog_editable_enters(GNOME_DIALOG(dialog), GTK_EDITABLE(entry));
-
- result = gnome_dialog_run(GNOME_DIALOG(dialog));
-
- if (grab_server)
- XUngrabServer(GDK_DISPLAY());
- if (grab_pointer)
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
- gdk_keyboard_ungrab(GDK_CURRENT_TIME);
- gdk_flush();
-
- passphrase = gtk_entry_get_text(GTK_ENTRY(entry));
- if (result == 0)
- puts(passphrase);
-
-
- memset(passphrase, '\0', strlen(passphrase));
- gtk_entry_set_text(GTK_ENTRY(entry), passphrase);
-
- gnome_dialog_close(GNOME_DIALOG(dialog));
- return (result == 0 ? 0 : -1);
-
- nograbkb:
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
- nograb:
- if (grab_server)
- XUngrabServer(GDK_DISPLAY());
- gnome_dialog_close(GNOME_DIALOG(dialog));
-
- report_failed_grab();
- return (-1);
- }
- int
- main(int argc, char **argv)
- {
- char *message;
- int result;
- gnome_init("GNOME ssh-askpass", "0.1", argc, argv);
- if (argc == 2)
- message = argv[1];
- else
- message = "Enter your OpenSSH passphrase:";
- setvbuf(stdout, 0, _IONBF, 0);
- result = passphrase_dialog(message);
- return (result);
- }
|