Ticket #42: mc-smbfs-dont-trash-connections.patch
File mc-smbfs-dont-trash-connections.patch, 5.1 KB (added by slavazanko, 16 years ago) |
---|
-
vfs/smbfs.c
RCS file: /cvsroot/mc/mc/vfs/smbfs.c,v retrieving revision 1.94 diff -u -p -r1.94 smbfs.c
smbfs_symlink (struct vfs_class *me, con 911 911 912 912 /* Extract the hostname and username from the path */ 913 913 /* path is in the form: [user@]hostname/share/remote-dir */ 914 #define smbfs_get_host_and_username(path, host, user, port, pass) \ 915 vfs_split_url (*path, host, user, port, pass, SMB_PORT, 0) 914 static char * 915 smbfs_get_host_and_username (const char *path, char **host, char **service, char **user, int *port, 916 char **pass) { 917 char *remote_path; 918 919 remote_path = vfs_split_url (path, host, user, port, pass, 920 SMB_PORT, URL_ALLOW_ANON); 921 922 if (strcmp (*host, remote_path) == 0) /* if host & path are same: */ 923 *service = g_strdup (IPC); /* setup for browse */ 924 else { /* get share name from path, path starts with server name */ 925 char *p; 926 if ((p = strchr (remote_path, '/'))) { /* get share aka */ 927 *service = g_strdup (++p); /* service name from path */ 928 929 /* now check for trailing directory/filenames */ 930 p = strchr (*service, '/'); 931 if (p) 932 *p = 0; /* cut off dir/files: sharename only */ 933 p = *service; 934 if (!*p) { 935 g_free (*service); 936 *service = g_strdup (IPC); /* setup for browse */ 937 } 938 } else 939 *service = g_strdup (IPC); 940 DEBUG (6, ("smbfs_get_host_and_username: service from path:%s\n", *service)); 941 } 942 943 if (*user == NULL) { 944 struct smb_authinfo key; 945 struct smb_authinfo *value; 946 GSList *list; 947 948 key.host = *host; 949 key.share = *service; 950 list = g_slist_find_custom (auth_list, &key, 951 smbfs_auth_cmp_host_and_share); 952 953 if (list == NULL) 954 list = g_slist_find_custom (auth_list, &key, 955 smbfs_auth_cmp_host); 956 957 if (list != NULL) { 958 value = list->data; 959 *user = g_strdup (value->user); 960 } 961 } 962 963 return remote_path; 964 } 916 965 917 966 /***************************************************** 918 967 return a connection to a SMB server … … smbfs_get_free_bucket (void) 1075 1124 /* This routine keeps track of open connections */ 1076 1125 /* Returns a connected socket to host */ 1077 1126 static smbfs_connection * 1078 smbfs_open_link (char *host, char * path, const char *user, int *port,1079 char *this_pass)1127 smbfs_open_link (char *host, char *service, char *path, const char *user, 1128 int *port, char *this_pass) 1080 1129 { 1081 1130 int i; 1082 1131 smbfs_connection *bucket; 1083 pstring service;1084 1132 struct in_addr *dest_ip = NULL; 1085 1133 1086 1134 DEBUG (3, ("smbfs_open_link(host:%s, path:%s)\n", host, path)); 1087 1135 1088 if (strcmp (host, path) == 0) /* if host & path are same: */ 1089 pstrcpy (service, IPC); /* setup for browse */ 1090 else { /* get share name from path, path starts with server name */ 1091 char *p; 1092 if ((p = strchr (path, '/'))) /* get share aka */ 1093 pstrcpy (service, ++p); /* service name from path */ 1094 else 1095 pstrcpy (service, ""); 1096 /* now check for trailing directory/filenames */ 1097 p = strchr (service, '/'); 1098 if (p) 1099 *p = 0; /* cut off dir/files: sharename only */ 1100 if (!*service) 1101 pstrcpy (service, IPC); /* setup for browse */ 1102 DEBUG (6, ("smbfs_open_link: service from path:%s\n", service)); 1103 } 1104 1105 if (got_user) 1136 if (user == NULL && got_user) 1106 1137 user = username; /* global from getenv */ 1107 1138 1108 1139 /* Is the link actually open? */ … … smbfs_open_link (char *host, char *path, 1179 1210 static char * 1180 1211 smbfs_get_path (smbfs_connection ** sc, const char *path) 1181 1212 { 1182 char *user, *host, *remote_path, *pass ;1213 char *user, *host, *remote_path, *pass, *service; 1183 1214 int port = SMB_PORT; 1184 1215 1185 1216 DEBUG (3, ("smbfs_get_path(%s)\n", path)); … … smbfs_get_path (smbfs_connection ** sc, 1191 1222 path++; /* probably came from server browsing */ 1192 1223 1193 1224 if ((remote_path = 1194 smbfs_get_host_and_username ( &path, &host, &user, &port, &pass)))1225 smbfs_get_host_and_username (path, &host, &service, &user, &port, &pass))) 1195 1226 if ((*sc = 1196 smbfs_open_link (host, remote_path, user, &port, pass)) == NULL) {1227 smbfs_open_link (host, service, remote_path, user, &port, pass)) == NULL) { 1197 1228 g_free (remote_path); 1198 1229 remote_path = NULL; 1199 1230 } 1200 1231 g_free (host); 1232 g_free (service); 1201 1233 g_free (user); 1202 1234 if (pass) 1203 1235 wipe_password (pass); … … smbfs_free (vfsid id) 1743 1775 static void 1744 1776 smbfs_forget (const char *path) 1745 1777 { 1746 char *host, *user, *p ;1778 char *host, *user, *p, *service; 1747 1779 int port, i; 1748 1780 1749 1781 if (strncmp (path, URL_HEADER, HEADER_LEN)) … … smbfs_forget (const char *path) 1755 1787 if (path[0] == '/' && path[1] == '/') 1756 1788 path += 2; 1757 1789 1758 if ((p = smbfs_get_host_and_username ( &path, &host, &user, &port, NULL))) {1790 if ((p = smbfs_get_host_and_username (path, &host, &service, &user, &port, NULL))) { 1759 1791 g_free (p); 1760 1792 for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++) { 1761 1793 if (smbfs_connections[i].cli … … smbfs_forget (const char *path) 1773 1805 } 1774 1806 } 1775 1807 g_free (host); 1808 g_free (service); 1776 1809 g_free (user); 1777 1810 } 1778 1811