Fix: sftp: password ask too often if hostname was bring from ~/.ssh/config file

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2013-04-16 17:33:06 +03:00
parent f2c94d53d2
commit cb08c1d0bf
5 changed files with 49 additions and 24 deletions

View File

@ -1,11 +1,11 @@
/*
GLIB - Library of useful routines for C programming
Copyright (C) 2009, 2011
Copyright (C) 2009, 2011, 2013
The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009, 2013.
This file is part of the Midnight Commander.
@ -31,6 +31,7 @@
*/
#include <config.h>
#include <string.h>
#include "global.h"
#include "glibcompat.h"
@ -68,3 +69,30 @@ g_unichar_iszerowidth (gunichar c)
#endif /* ! GLIB_CHECK_VERSION (2, 13, 0) */
/* --------------------------------------------------------------------------------------------- */
#if ! GLIB_CHECK_VERSION (2, 16, 0)
/**
* g_strcmp0:
* @str1: (allow-none): a C string or %NULL
* @str2: (allow-none): another C string or %NULL
*
* Compares @str1 and @str2 like strcmp(). Handles %NULL
* gracefully by sorting it before non-%NULL strings.
* Comparing two %NULL pointers returns 0.
*
* Returns: an integer less than, equal to, or greater than zero, if @str1 is <, == or > than @str2.
*
* Since: 2.16
*/
int
g_strcmp0 (const char *str1, const char *str2)
{
if (!str1)
return -(str1 != str2);
if (!str2)
return str1 != str2;
return strcmp (str1, str2);
}
#endif /* ! GLIB_CHECK_VERSION (2, 16, 0) */
/* --------------------------------------------------------------------------------------------- */

View File

@ -15,6 +15,10 @@
gboolean g_unichar_iszerowidth (gunichar);
#endif /* ! GLIB_CHECK_VERSION (2, 13, 0) */
#if ! GLIB_CHECK_VERSION (2, 16, 0)
int g_strcmp0 (const char *str1, const char *str2);
#endif /* ! GLIB_CHECK_VERSION (2, 16, 0) */
/*** inline functions ****************************************************************************/
#endif /* MC_GLIBCOMPAT_H */

View File

@ -1,12 +1,12 @@
/* Virtual File System: SFTP file system.
The internal functions: connections
Copyright (C) 2011
Copyright (C) 2011, 2013
The Free Software Foundation, Inc.
Written by:
Ilia Maslakov <il.smind@gmail.com>, 2011
Slava Zanko <slavazanko@gmail.com>, 2011, 2012
Slava Zanko <slavazanko@gmail.com>, 2011, 2012, 2013
This file is part of the Midnight Commander.
@ -437,6 +437,7 @@ sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message
if (super_data == NULL)
return;
vfs_path_element_free (super_data->original_connection_info);
if (super_data->agent != NULL)
{
libssh2_agent_disconnect (super_data->agent);

View File

@ -43,6 +43,7 @@ typedef struct
int socket_handle;
const char *fingerprint;
vfs_path_element_t *original_connection_info;
} sftpfs_super_data_t;
/*** global variables defined in .c file *********************************************************/

View File

@ -1,12 +1,12 @@
/* Virtual File System: SFTP file system.
The VFS subclass functions
Copyright (C) 2011
Copyright (C) 2011, 2013
The Free Software Foundation, Inc.
Written by:
Ilia Maslakov <il.smind@gmail.com>, 2011
Slava Zanko <slavazanko@gmail.com>, 2011, 2012
Slava Zanko <slavazanko@gmail.com>, 2011, 2012, 2013
This file is part of the Midnight Commander.
@ -58,29 +58,17 @@ static gboolean
sftpfs_cb_is_equal_connection (const vfs_path_element_t * vpath_element, struct vfs_s_super *super,
const vfs_path_t * vpath, void *cookie)
{
int port;
char *user_name;
int result;
vfs_path_element_t *orig_connect_info;
(void) vpath;
(void) cookie;
if (vpath_element->user != NULL)
user_name = vpath_element->user;
else
user_name = vfs_get_local_username ();
orig_connect_info = ((sftpfs_super_data_t *) super->data)->original_connection_info;
if (vpath_element->port != 0)
port = vpath_element->port;
else
port = SFTP_DEFAULT_PORT;
result = ((strcmp (vpath_element->host, super->path_element->host) == 0)
&& (strcmp (user_name, super->path_element->user) == 0)
&& (port == super->path_element->port));
if (user_name != vpath_element->user)
g_free (user_name);
result = ((g_strcmp0 (vpath_element->host, orig_connect_info->host) == 0)
&& (g_strcmp0 (vpath_element->user, orig_connect_info->user) == 0)
&& (vpath_element->port == orig_connect_info->port));
return result;
}
@ -100,6 +88,7 @@ sftpfs_cb_open_connection (struct vfs_s_super *super,
const vfs_path_t * vpath, const vfs_path_element_t * vpath_element)
{
GError *error = NULL;
sftpfs_super_data_t *sftpfs_super_data;
int ret_value;
(void) vpath;
@ -111,7 +100,9 @@ sftpfs_cb_open_connection (struct vfs_s_super *super,
return -1;
}
super->data = g_new0 (sftpfs_super_data_t, 1);
sftpfs_super_data = g_new0 (sftpfs_super_data_t, 1);
sftpfs_super_data->original_connection_info = vfs_path_element_clone (vpath_element);
super->data = sftpfs_super_data;
super->path_element = vfs_path_element_clone (vpath_element);
sftpfs_fill_connection_data_from_config (super, &error);