Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When reconnecting don't ask for login data again #1330

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.lo
.deps
.libs
*~

CMakeFiles
CMakeCache.txt
Expand Down
6 changes: 6 additions & 0 deletions vncviewer/CConn.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <rfb/screenTypes.h>
#include <rfb/fenceTypes.h>
#include <rfb/Timer.h>
#include <rfb/Exception.h>
#include <network/TcpSocket.h>
#ifndef WIN32
#include <network/UnixSocket.h>
Expand Down Expand Up @@ -275,6 +276,11 @@ void CConn::socketEvent(FL_SOCKET fd, void *data)
} else {
disconnect();
}
} catch (rfb::AuthFailureException& e) {
reset_password_data();
vlog.error("%s", e.str());
abort_connection(_("An authentication error occurred when communicating "
"with the server:\n\n%s"), e.str());
} catch (rdr::Exception& e) {
vlog.error("%s", e.str());
abort_connection(_("An unexpected error occurred when communicating "
Expand Down
57 changes: 47 additions & 10 deletions vncviewer/UserDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -62,34 +63,49 @@ static void button_cb(Fl_Widget *widget, void *val) {
widget->window()->hide();
}

UserDialog::UserDialog()
UserDialog::UserDialog() : user_(NULL), password_(NULL), keepPasswd_(true)
{
}

UserDialog::~UserDialog()
{
resetPassword();
}

void UserDialog::resetPassword()
{
if(user_) {
delete [] user_;
user_ = NULL;
}
if(password_) {
delete [] password_;
password_ = NULL;
}
}

void UserDialog::getUserPasswd(bool secure, char** user, char** password)
{
CharArray passwordFileStr(passwordFile.getData());

assert(password);
char *envUsername = getenv("VNC_USERNAME");
char *envPassword = getenv("VNC_PASSWORD");

if(user && envUsername && envPassword) {
*user = strdup(envUsername);
*password = strdup(envPassword);
if(password_) {
if(user_ && user) *user = strDup(user_);
*password = strDup(password_);
return;
}

if (!user && envPassword) {
*password = strdup(envPassword);
if(user) *user = getenv("VNC_USERNAME");
*password = getenv("VNC_PASSWORD");
johahauf marked this conversation as resolved.
Show resolved Hide resolved

if(*password) {
setPassword(*password);
if (user) user_ = strDup(*user);
return;
}

if (!user && passwordFileStr.buf[0]) {
if (!user_ && passwordFileStr.buf[0]) {
ObfuscatedPasswd obfPwd(256);
FILE* fp;

Expand All @@ -102,6 +118,7 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password)

PlainPasswd passwd(obfPwd);
*password = passwd.takeBuf();
setPassword(*password);

return;
}
Expand All @@ -112,6 +129,7 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password)
Fl_Secret_Input *passwd;
Fl_Box *icon;
Fl_Button *button;
Fl_Check_Button *keepPasswdCheckbox;

int y;

Expand Down Expand Up @@ -164,6 +182,14 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password)

y += 5;

if (reconnectOnError) {
keepPasswdCheckbox = new Fl_Check_Button(70, y, win->w()-70-10, 20,
_("Keep password for reconnect"));
keepPasswdCheckbox->value(keepPasswd_);

y += 25 + 5;
}

button = new Fl_Return_Button(310, y, 90, 25, fl_ok);
button->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
button->callback(button_cb, (void*)0);
Expand All @@ -187,15 +213,20 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password)
while (win->shown()) Fl::wait();

if (ret_val == 0) {
if (user)
keepPasswd_ = keepPasswdCheckbox->value();
if (user) {
*user = strDup(username->value());
if(keepPasswd_) user_ = strDup(username->value());
}
*password = strDup(passwd->value());
setPassword(passwd->value());
}

delete win;

if (ret_val != 0)
throw rfb::Exception(_("Authentication cancelled"));

}

bool UserDialog::showMsgBox(int flags, const char* title, const char* text)
Expand Down Expand Up @@ -227,3 +258,9 @@ bool UserDialog::showMsgBox(int flags, const char* title, const char* text)

return false;
}

void UserDialog::setPassword(const char* password)
{
if (keepPasswd_)
password_ = strDup(password);
}
9 changes: 9 additions & 0 deletions vncviewer/UserDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class UserDialog : public rfb::UserPasswdGetter,
// UserMsgBox callbacks

bool showMsgBox(int flags, const char* title, const char* text);

void resetPassword();

private:
void setPassword(const char* password);

char *user_;
char *password_;
bool keepPasswd_;
};

#endif
8 changes: 6 additions & 2 deletions vncviewer/vncviewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool inMainloop = false;
static bool exitMainloop = false;
static char *exitError = NULL;
static bool fatalError = false;

static UserDialog dlg;
static const char *about_text()
{
static char buffer[1024];
Expand Down Expand Up @@ -167,6 +167,11 @@ bool should_disconnect()
return exitMainloop;
}

void reset_password_data()
{
dlg.resetPassword();
}

void about_vncviewer()
{
fl_message_title(_("About TigerVNC Viewer"));
Expand Down Expand Up @@ -643,7 +648,6 @@ static int mktunnel()
int main(int argc, char** argv)
{
const char *localedir;
UserDialog dlg;

argv0 = argv[0];

Expand Down
1 change: 1 addition & 0 deletions vncviewer/vncviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void abort_vncviewer(const char *error, ...) __printf_attr(1, 2);
void abort_connection(const char *error, ...) __printf_attr(1, 2);
void disconnect();
bool should_disconnect();
void reset_password_data();

void about_vncviewer();

Expand Down