diff options
-rw-r--r-- | src/remmina_file_editor.c | 45 | ||||
-rw-r--r-- | src/remmina_protocol_widget.c | 32 | ||||
-rw-r--r-- | src/remmina_protocol_widget.h | 2 | ||||
-rw-r--r-- | src/remmina_ssh.c | 26 |
4 files changed, 81 insertions, 24 deletions
diff --git a/src/remmina_file_editor.c b/src/remmina_file_editor.c index c37a867e4..93a39246c 100644 --- a/src/remmina_file_editor.c +++ b/src/remmina_file_editor.c @@ -132,6 +132,7 @@ struct _RemminaFileEditorPriv { GtkWidget* ssh_server_entry; GtkWidget* ssh_auth_agent_radio; GtkWidget* ssh_auth_password_radio; + GtkWidget* ssh_auth_password; GtkWidget* ssh_auth_publickey_radio; GtkWidget* ssh_auth_auto_publickey_radio; GtkWidget* ssh_username_entry; @@ -305,6 +306,7 @@ static void remmina_file_editor_ssh_enabled_check_on_toggled(GtkToggleButton* to RemminaFileEditorPriv* priv = gfe->priv; gboolean enabled = TRUE; gchar* p; + const gchar* cp; if (gfe->priv->ssh_enabled_check) { enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gfe->priv->ssh_enabled_check)); @@ -321,6 +323,7 @@ static void remmina_file_editor_ssh_enabled_check_on_toggled(GtkToggleButton* to gtk_widget_set_sensitive(gfe->priv->ssh_username_entry, enabled); gtk_widget_set_sensitive(gfe->priv->ssh_auth_agent_radio, enabled); gtk_widget_set_sensitive(gfe->priv->ssh_auth_password_radio, enabled); + gtk_widget_set_sensitive(gfe->priv->ssh_auth_password, enabled); gtk_widget_set_sensitive(gfe->priv->ssh_auth_publickey_radio, enabled); gtk_widget_set_sensitive(gfe->priv->ssh_auth_auto_publickey_radio, enabled); } @@ -330,9 +333,17 @@ static void remmina_file_editor_ssh_enabled_check_on_toggled(GtkToggleButton* to if (gfe->priv->ssh_username_entry) if (enabled && gtk_entry_get_text(GTK_ENTRY(gfe->priv->ssh_username_entry)) [0] == '\0') { - gtk_entry_set_text(GTK_ENTRY(gfe->priv->ssh_username_entry), - remmina_file_get_string(priv->remmina_file, "ssh_username")); + cp = remmina_file_get_string(priv->remmina_file, "ssh_username"); + gtk_entry_set_text(GTK_ENTRY(gfe->priv->ssh_username_entry), cp ? cp : ""); } + + if (gfe->priv->ssh_auth_password) { + if (enabled && gtk_entry_get_text(GTK_ENTRY(gfe->priv->ssh_auth_password)) [0] == '\0') { + cp = remmina_file_get_string(priv->remmina_file, "ssh_password"); + gtk_entry_set_text(GTK_ENTRY(gfe->priv->ssh_auth_password), cp ? cp : ""); + } + } + } static void remmina_file_editor_create_ssh_privatekey(RemminaFileEditor* gfe, GtkWidget* grid, gint row, gint column) @@ -819,7 +830,7 @@ static void remmina_file_editor_create_ssh_tab(RemminaFileEditor* gfe, RemminaPr /* The SSH tab (implementation) */ grid = remmina_file_editor_create_notebook_tab(gfe, NULL, - "SSH Tunnel", 9, 3); + _("SSH Tunnel"), 9, 3); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_show(hbox); @@ -927,6 +938,14 @@ static void remmina_file_editor_create_ssh_tab(RemminaFileEditor* gfe, RemminaPr gtk_widget_show(widget); gtk_grid_attach(GTK_GRID(grid), widget, 0, row + 21, 1, 1); priv->ssh_auth_password_radio = widget; + + widget = gtk_entry_new(); + gtk_widget_show(widget); + gtk_grid_attach(GTK_GRID(grid), widget, 1, row + 21, 2, 1); + gtk_entry_set_max_length(GTK_ENTRY(widget), 300); + gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE); + gtk_widget_set_hexpand(widget, TRUE); + priv->ssh_auth_password = widget; row++; widget = gtk_radio_button_new_with_label_from_widget( @@ -1052,6 +1071,7 @@ static void remmina_file_editor_update_ssh(RemminaFileEditor* gfe) TRACE_CALL(__func__); RemminaFileEditorPriv* priv = gfe->priv; gboolean ssh_enabled; + int ssh_auth; if (priv->ssh_charset_combo) { remmina_file_set_string_ref(priv->remmina_file, "ssh_charset", @@ -1076,10 +1096,8 @@ static void remmina_file_editor_update_ssh(RemminaFileEditor* gfe) || gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(priv->ssh_server_custom_radio))) ? gtk_entry_get_text(GTK_ENTRY(priv->ssh_server_entry)) : NULL)); - remmina_file_set_int( - priv->remmina_file, - "ssh_auth", - (priv->ssh_auth_publickey_radio + + ssh_auth = (priv->ssh_auth_publickey_radio && gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(priv->ssh_auth_publickey_radio)) ? SSH_AUTH_PUBLICKEY : @@ -1090,12 +1108,23 @@ static void remmina_file_editor_update_ssh(RemminaFileEditor* gfe) priv->ssh_auth_agent_radio && gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(priv->ssh_auth_agent_radio)) ? - SSH_AUTH_AGENT : SSH_AUTH_PASSWORD)); + SSH_AUTH_AGENT : SSH_AUTH_PASSWORD); + + remmina_file_set_int( + priv->remmina_file, + "ssh_auth", + ssh_auth + ); remmina_file_set_string( priv->remmina_file, "ssh_privatekey", (priv->ssh_privatekey_chooser ? gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(priv->ssh_privatekey_chooser)) : NULL)); + + remmina_file_set_string( + priv->remmina_file, + "ssh_password", + (ssh_enabled && (ssh_auth == SSH_AUTH_PASSWORD)) ? gtk_entry_get_text(GTK_ENTRY(priv->ssh_auth_password)) : NULL); } static void remmina_file_editor_update_settings(RemminaFileEditor* gfe) diff --git a/src/remmina_protocol_widget.c b/src/remmina_protocol_widget.c index bc03fa7a2..0b84ce3fd 100644 --- a/src/remmina_protocol_widget.c +++ b/src/remmina_protocol_widget.c @@ -102,6 +102,7 @@ struct _RemminaProtocolWidgetPriv { enum panel_type { RPWDT_AUTHUSERPWD, + RPWDT_AUTHUSERPWD_SSHTUNNEL, RPWDT_AUTHPWD, RPWDT_QUESTIONYESNO, RPWDT_AUTHX509 @@ -1080,7 +1081,7 @@ static void authuserpwd_mt_cb(void *user_data, int button) struct remmina_protocol_widget_dialog_mt_data_t *d = (struct remmina_protocol_widget_dialog_mt_data_t *)user_data; d->rcbutton = button; if (button == GTK_RESPONSE_OK) { - if (d->dtype == RPWDT_AUTHUSERPWD || d->dtype == RPWDT_AUTHPWD) { + if (d->dtype == RPWDT_AUTHUSERPWD || d->dtype == RPWDT_AUTHPWD || d->dtype == RPWDT_AUTHUSERPWD_SSHTUNNEL) { d->gp->priv->password = remmina_message_panel_field_get_string(d->gp->priv->auth_message_panel, REMMINA_MESSAGE_PANEL_PASSWORD); d->gp->priv->username = remmina_message_panel_field_get_string(d->gp->priv->auth_message_panel, REMMINA_MESSAGE_PANEL_USERNAME); d->gp->priv->domain = remmina_message_panel_field_get_string(d->gp->priv->auth_message_panel, REMMINA_MESSAGE_PANEL_DOMAIN); @@ -1114,17 +1115,22 @@ static gboolean remmina_protocol_widget_dialog_mt_setup(gpointer user_data) RemminaFile* remminafile = d->gp->priv->remmina_file; RemminaMessagePanel *mp; + const gchar *key; const gchar *s; mp = remmina_message_panel_new(); - if (d->dtype == RPWDT_AUTHUSERPWD) { - remmina_message_panel_setup_auth(mp, authuserpwd_mt_cb, d, _("Enter authentication credentials"), d->str1, d->pflags); - if ((s = remmina_file_get_string(remminafile, "username")) != NULL) + if (d->dtype == RPWDT_AUTHUSERPWD || d->dtype == RPWDT_AUTHUSERPWD_SSHTUNNEL) { + remmina_message_panel_setup_auth(mp, authuserpwd_mt_cb, d, + d->dtype == RPWDT_AUTHUSERPWD_SSHTUNNEL ? _("Enter SSH tunnel authentication credentials") : _("Enter authentication credentials"), + d->str1, d->pflags); + key = (d->dtype == RPWDT_AUTHUSERPWD_SSHTUNNEL ? "ssh_username" : "username"); + if ((s = remmina_file_get_string(remminafile, key)) != NULL) remmina_message_panel_field_set_string(mp, REMMINA_MESSAGE_PANEL_USERNAME, s); - if ((d->pflags & REMMINA_MESSAGE_PANEL_FLAG_DOMAIN) && (s = remmina_file_get_string(remminafile, "domain")) != NULL) + if (d->dtype == RPWDT_AUTHUSERPWD && (d->pflags & REMMINA_MESSAGE_PANEL_FLAG_DOMAIN) && (s = remmina_file_get_string(remminafile, "domain")) != NULL) remmina_message_panel_field_set_string(mp, REMMINA_MESSAGE_PANEL_DOMAIN, s); - if ((s = remmina_file_get_string(remminafile, "password")) != NULL) + key = (d->dtype == RPWDT_AUTHUSERPWD_SSHTUNNEL ? "ssh_password" : "password"); + if ((s = remmina_file_get_string(remminafile, key)) != NULL) remmina_message_panel_field_set_string(mp, REMMINA_MESSAGE_PANEL_PASSWORD, s); if (d->pflags & REMMINA_MESSAGE_PANEL_FLAG_SAVEPASSRORD) { remmina_message_panel_field_set_switch(mp, REMMINA_MESSAGE_PANEL_FLAG_SAVEPASSRORD, FALSE); @@ -1283,6 +1289,20 @@ gint remmina_protocol_widget_panel_authuserpwd(RemminaProtocolWidget* gp, gboole return remmina_protocol_widget_dialog(RPWDT_AUTHUSERPWD, gp, pflags, _("Password")); } +gint remmina_protocol_widget_panel_authuserpwd_ssh_tunnel(RemminaProtocolWidget* gp, gboolean want_domain, gboolean allow_password_saving) +{ + TRACE_CALL(__func__); + unsigned pflags; + RemminaFile* remminafile = gp->priv->remmina_file; + + pflags = REMMINA_MESSAGE_PANEL_FLAG_USERNAME; + if (remmina_file_get_filename(remminafile) != NULL && + !remminafile->prevent_saving && allow_password_saving) + pflags |= REMMINA_MESSAGE_PANEL_FLAG_SAVEPASSRORD; + + return remmina_protocol_widget_dialog(RPWDT_AUTHUSERPWD_SSHTUNNEL, gp, pflags, _("Password")); +} + gint remmina_protocol_widget_panel_authpwd(RemminaProtocolWidget* gp, RemminaAuthpwdType authpwd_type, gboolean allow_password_saving) { TRACE_CALL(__func__); diff --git a/src/remmina_protocol_widget.h b/src/remmina_protocol_widget.h index 1afb377d3..9b8d87407 100644 --- a/src/remmina_protocol_widget.h +++ b/src/remmina_protocol_widget.h @@ -120,6 +120,8 @@ gboolean remmina_protocol_widget_start_reverse_tunnel(RemminaProtocolWidget *gp, gboolean remmina_protocol_widget_start_xport_tunnel(RemminaProtocolWidget *gp, RemminaXPortTunnelInitFunc init_func); void remmina_protocol_widget_set_display(RemminaProtocolWidget *gp, gint display); +/* Extension for remmina_protocol_widget_panel_authuserpwd() not currently exported to plugins */ +gint remmina_protocol_widget_panel_authuserpwd_ssh_tunnel(RemminaProtocolWidget* gp, gboolean want_domain, gboolean allow_password_saving); /* Dialog panel API used by the plugins */ diff --git a/src/remmina_ssh.c b/src/remmina_ssh.c index b0eb76bf3..512e7a07d 100644 --- a/src/remmina_ssh.c +++ b/src/remmina_ssh.c @@ -183,8 +183,7 @@ remmina_ssh_auth_interactive(RemminaSSH *ssh) } if (ret != SSH_AUTH_SUCCESS) { - /* We pass the control to remmina_ssh_auth_password */ - return 0; + return 0; // Generic error } ssh->authenticated = TRUE; @@ -326,13 +325,19 @@ remmina_ssh_auth(RemminaSSH *ssh, const gchar *password) switch (ssh->auth) { case SSH_AUTH_PASSWORD: - ret = 0; - if (method & SSH_AUTH_METHOD_INTERACTIVE || method & SSH_AUTH_METHOD_PASSWORD) { - ret = remmina_ssh_auth_interactive(ssh); - if (!ssh->authenticated) - return remmina_ssh_auth_password(ssh); + if (ssh->authenticated) + return 1; + if (method & SSH_AUTH_METHOD_PASSWORD) { + if (remmina_ssh_auth_password(ssh) <= 0) + return -1; // Re-prompt password + } + if (method & SSH_AUTH_METHOD_INTERACTIVE) { + /* SSH server is requesting us to do interactive auth. + * But we just send the saved password */ + if (remmina_ssh_auth_interactive(ssh) <= 0) + return -1; // Re-prompt password } - return ret; + return 1; case SSH_AUTH_PUBLICKEY: if (method & SSH_AUTH_METHOD_PUBLICKEY) @@ -460,9 +465,10 @@ remmina_ssh_auth_gui(RemminaSSH *ssh, RemminaProtocolWidget *gp, RemminaFile *re if (g_strcmp0(pwdtype, "ssh_passphrase") == 0) { ret = remmina_protocol_widget_panel_authpwd(gp, REMMINA_AUTHPWD_TYPE_SSH_PRIVKEY, !disablepasswordstoring); - }else { + }else if (g_strcmp0(pwdtype, "ssh_password") == 0) { + ret = remmina_protocol_widget_panel_authuserpwd_ssh_tunnel(gp, FALSE, !disablepasswordstoring); + } else ret = remmina_protocol_widget_panel_authuserpwd(gp, FALSE, !disablepasswordstoring); - } save_password = remmina_protocol_widget_get_savepassword(gp); if (ret == GTK_RESPONSE_OK) { |