| 1 | /* |
| 2 | * Copyright (c) 1993-2017, 2020 Paul Mattes. |
| 3 | * Copyright (c) 2004, Don Russell. |
| 4 | * Copyright (c) 1990, Jeff Sparkes. |
| 5 | * Copyright (c) 1989, Georgia Tech Research Corporation (GTRC), Atlanta, |
| 6 | * GA 30332. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * * Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * * Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * * Neither the names of Paul Mattes, Don Russell, Jeff Sparkes, GTRC |
| 18 | * nor their contributors may be used to endorse or promote products |
| 19 | * derived from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY PAUL MATTES, DON RUSSELL, JEFF SPARKES AND |
| 22 | * GTRC "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PAUL MATTES, |
| 25 | * DON RUSSELL, JEFF SPARKES OR GTRC BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 28 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 29 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * tls_passwd_gui.c |
| 36 | * TLS certificate password dialog for x3270. |
| 37 | */ |
| 38 | |
| 39 | #include "globals.h" |
| 40 | |
| 41 | #include <X11/StringDefs.h> |
| 42 | #include <X11/Xaw/Dialog.h> |
| 43 | |
| 44 | #include "appres.h" |
| 45 | #include "host.h" |
| 46 | #include "objects.h" |
| 47 | #include "popups.h" |
| 48 | #include "sio.h" |
| 49 | #include "telnet.h" |
| 50 | #include "telnet_private.h" |
| 51 | #include "tls_passwd_gui.h" |
| 52 | #include "xglobals.h" |
| 53 | #include "xpopups.h" |
| 54 | |
| 55 | /* Statics. */ |
| 56 | static char *tls_password; |
| 57 | static Widget password_shell = NULL; |
| 58 | |
| 59 | /* Callback for "OK" button on the password popup. */ |
| 60 | static void |
| 61 | password_callback(Widget w _is_unused, XtPointer client_data, |
| 62 | XtPointer call_data _is_unused) |
| 63 | { |
| 64 | char *password; |
| 65 | |
| 66 | password = XawDialogGetValueString((Widget)client_data); |
| 67 | tls_password = NewString(password); |
| 68 | XtPopdown(password_shell); |
| 69 | |
| 70 | net_password_continue(tls_password); |
| 71 | } |
| 72 | |
| 73 | /* The password dialog was popped down. */ |
| 74 | static void |
| 75 | password_popdown(Widget w _is_unused, XtPointer client_data _is_unused, |
| 76 | XtPointer call_data _is_unused) |
| 77 | { |
| 78 | /* If there's no password (they cancelled), don't pop up again. */ |
| 79 | if (tls_password == NULL) { |
| 80 | /* We might want to do something more sophisticated here. */ |
| 81 | host_disconnect(true); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /* Pop up the password dialog. */ |
| 86 | static void |
| 87 | popup_password(void) |
| 88 | { |
| 89 | if (password_shell == NULL) { |
| 90 | password_shell = create_form_popup("Password", password_callback, NULL, |
| 91 | FORM_AS_IS); |
| 92 | XtAddCallback(password_shell, XtNpopdownCallback, password_popdown, |
| 93 | NULL); |
| 94 | } |
| 95 | XtVaSetValues(XtNameToWidget(password_shell, ObjDialog), |
| 96 | XtNvalue, "", |
| 97 | NULL); |
| 98 | Replace(tls_password, NULL); |
| 99 | |
| 100 | popup_popup(password_shell, XtGrabExclusive); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Password callback. |
| 105 | */ |
| 106 | tls_passwd_ret_t |
| 107 | tls_passwd_gui_callback(char *buf, int size, bool again) |
| 108 | { |
| 109 | /* Pop up the dialog. */ |
| 110 | popup_password(); |
| 111 | if (again) { |
| 112 | popup_an_error("Password is incorrect."); |
| 113 | } |
| 114 | return SP_PENDING; |
| 115 | } |