From: Johannes Date: Sat, 24 Jul 2021 14:02:29 +0000 (+0200) Subject: Don't ask for login data when reconnecting X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=633e75b5263cbde04a16a0f2c04165807db1bd91;p=tigervnc.git Don't ask for login data when reconnecting --- diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 219c850b..e1c75962 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -275,6 +275,7 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) vlog.info("%s", e.str()); disconnect(); } catch (rfb::AuthFailureException& e) { + reset_password_data(); vlog.error(_("Authentication failed: %s"), e.str()); abort_connection(_("Failed to authenticate with the server. Reason " "given by the server:\n\n%s"), e.str()); diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index 2ddc5ecc..a3767857 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,12 @@ UserDialog::~UserDialog() { } +void UserDialog::resetPassword() +{ + savedUsername.clear(); + savedPassword.clear(); +} + void UserDialog::getUserPasswd(bool secure_, std::string* user, std::string* password) { @@ -90,6 +97,17 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, return; } + if (user && !savedUsername.empty() && !savedPassword.empty()) { + *user = savedUsername; + *password = savedPassword; + return; + } + + if (!user && !savedPassword.empty()) { + *password = savedPassword; + return; + } + if (!user && passwordFileName[0]) { std::vector obfPwd(256); FILE* fp; @@ -112,6 +130,7 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, Fl_Secret_Input *passwd; Fl_Box *icon; Fl_Button *button; + Fl_Check_Button *keepPasswdCheckbox; int x, y; @@ -165,6 +184,16 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, passwd->align(FL_ALIGN_LEFT | FL_ALIGN_TOP); y += INPUT_HEIGHT + INNER_MARGIN; + if (reconnectOnError) { + keepPasswdCheckbox = new Fl_Check_Button(LBLRIGHT(x, y, + CHECK_MIN_WIDTH, + CHECK_HEIGHT, + _("Keep password for reconnect"))); + y += CHECK_HEIGHT + INNER_MARGIN; + } else { + keepPasswdCheckbox = nullptr; + } + x = win->w() - OUTER_MARGIN; y += OUTER_MARGIN - INNER_MARGIN; @@ -196,9 +225,21 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, while (win->shown()) Fl::wait(); if (ret_val == 0) { - if (user) + bool keepPasswd; + + if (reconnectOnError) + keepPasswd = keepPasswdCheckbox->value(); + else + keepPasswd = false; + + if (user) { *user = username->value(); + if (keepPasswd) + savedUsername = username->value(); + } *password = passwd->value(); + if (keepPasswd) + savedPassword = passwd->value(); } delete win; diff --git a/vncviewer/UserDialog.h b/vncviewer/UserDialog.h index db4e7c45..aa50127e 100644 --- a/vncviewer/UserDialog.h +++ b/vncviewer/UserDialog.h @@ -37,6 +37,12 @@ public: // UserMsgBox callbacks bool showMsgBox(int flags, const char* title, const char* text) override; + + void resetPassword(); + + private: + std::string savedUsername; + std::string savedPassword; }; #endif diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 6ddff947..27946f3f 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -93,6 +93,8 @@ static bool exitMainloop = false; static char *exitError = nullptr; static bool fatalError = false; +static UserDialog dlg; + static const char *about_text() { static char buffer[1024]; @@ -169,6 +171,11 @@ bool should_disconnect() return exitMainloop; } +void reset_password_data() +{ + dlg.resetPassword(); +} + void about_vncviewer() { fl_message_title(_("About TigerVNC Viewer")); @@ -607,7 +614,6 @@ static int mktunnel() int main(int argc, char** argv) { const char *localedir; - UserDialog dlg; argv0 = argv[0]; diff --git a/vncviewer/vncviewer.h b/vncviewer/vncviewer.h index f39a5776..c864805c 100644 --- a/vncviewer/vncviewer.h +++ b/vncviewer/vncviewer.h @@ -33,6 +33,7 @@ void abort_connection_with_unexpected_error(const rdr::Exception &); void disconnect(); bool should_disconnect(); +void reset_password_data(); void about_vncviewer();