Ticket #42: mc-smbfs-dont-trash-connections.patch

File mc-smbfs-dont-trash-connections.patch, 5.1 KB (added by slavazanko, 11 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 
    911911 
    912912/* Extract the hostname and username from the path */ 
    913913/* 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) 
     914static char * 
     915smbfs_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} 
    916965 
    917966/*****************************************************  
    918967        return a connection to a SMB server 
    smbfs_get_free_bucket (void) 
    10751124/* This routine keeps track of open connections */ 
    10761125/* Returns a connected socket to host */ 
    10771126static smbfs_connection * 
    1078 smbfs_open_link (char *host, char *path, const char *user, int *port, 
    1079                  char *this_pass) 
     1127smbfs_open_link (char *host, char *service, char *path, const char *user, 
     1128                 int *port, char *this_pass) 
    10801129{ 
    10811130    int i; 
    10821131    smbfs_connection *bucket; 
    1083     pstring service; 
    10841132    struct in_addr *dest_ip = NULL; 
    10851133 
    10861134    DEBUG (3, ("smbfs_open_link(host:%s, path:%s)\n", host, path)); 
    10871135 
    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) 
    11061137        user = username;        /* global from getenv */ 
    11071138 
    11081139    /* Is the link actually open? */ 
    smbfs_open_link (char *host, char *path, 
    11791210static char * 
    11801211smbfs_get_path (smbfs_connection ** sc, const char *path) 
    11811212{ 
    1182     char *user, *host, *remote_path, *pass; 
     1213    char *user, *host, *remote_path, *pass, *service; 
    11831214    int port = SMB_PORT; 
    11841215 
    11851216    DEBUG (3, ("smbfs_get_path(%s)\n", path)); 
    smbfs_get_path (smbfs_connection ** sc,  
    11911222        path++;                 /* probably came from server browsing */ 
    11921223 
    11931224    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))) 
    11951226        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) { 
    11971228            g_free (remote_path); 
    11981229            remote_path = NULL; 
    11991230        } 
    12001231    g_free (host); 
     1232    g_free (service); 
    12011233    g_free (user); 
    12021234    if (pass) 
    12031235        wipe_password (pass); 
    smbfs_free (vfsid id) 
    17431775static void 
    17441776smbfs_forget (const char *path) 
    17451777{ 
    1746     char *host, *user, *p; 
     1778    char *host, *user, *p, *service; 
    17471779    int port, i; 
    17481780 
    17491781    if (strncmp (path, URL_HEADER, HEADER_LEN)) 
    smbfs_forget (const char *path) 
    17551787    if (path[0] == '/' && path[1] == '/') 
    17561788        path += 2; 
    17571789 
    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))) { 
    17591791        g_free (p); 
    17601792        for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++) { 
    17611793            if (smbfs_connections[i].cli 
    smbfs_forget (const char *path) 
    17731805        } 
    17741806    } 
    17751807    g_free (host); 
     1808    g_free (service); 
    17761809    g_free (user); 
    17771810} 
    17781811