]> source.dussan.org Git - tigervnc.git/commitdiff
Don't ask for login data when reconnecting
authorJohannes <bensky@arcor.de>
Sat, 24 Jul 2021 14:02:29 +0000 (16:02 +0200)
committerPierre Ossman <ossman@cendio.se>
Wed, 7 Aug 2024 09:18:01 +0000 (11:18 +0200)
vncviewer/CConn.cxx
vncviewer/UserDialog.cxx
vncviewer/UserDialog.h
vncviewer/vncviewer.cxx
vncviewer/vncviewer.h

index 219c850b990743feda413093e45dc66dd0f680ef..e1c7596203932aa34ffb5e47c1740f975328f2fc 100644 (file)
@@ -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());
index 2ddc5ecc853df998f15e0a55314e128333c30fb3..a376785768acf27208ace437eece212915f7ddcf 100644 (file)
@@ -31,6 +31,7 @@
 #include <FL/Fl_Input.H>
 #include <FL/Fl_Secret_Input.H>
 #include <FL/Fl_Button.H>
+#include <FL/Fl_Check_Button.H>
 #include <FL/Fl_Return_Button.H>
 #include <FL/Fl_Pixmap.H>
 
@@ -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<uint8_t> 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;
index db4e7c45a5cad4e27d6310670629ebb1330adcdf..aa50127e74ca2414186800a76dbacb2046293110 100644 (file)
@@ -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
index 6ddff947039aa96ff39a6f9560b771a3fd87adba..27946f3fc5d8aba9b5bd694696fd03d86cdbe36e 100644 (file)
@@ -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];
 
index f39a57761897099df19d3af74bf5ca2955c79951..c864805cd7b3e42c4496d44415ddaaf205a37281 100644 (file)
@@ -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();