trying to get HEAD building again. If you want the code
[samba.git] / source3 / smbwrapper / smbw_dir.c
index 4f6c18eb7f6e87a64c15c597daf6ca082b0f67a1..6d55c1d9da2bf30fe9e37d36a608d31442ae6c56 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 2.0
+   Unix SMB/CIFS implementation.
    SMB wrapper directory functions
    Copyright (C) Andrew Tridgell 1998
    
@@ -28,7 +27,6 @@ extern fstring smbw_prefix;
 static struct smbw_dir *smbw_dirs;
 
 extern struct bitmap *smbw_file_bmap;
-extern int DEBUGLEVEL;
 
 extern int smbw_busy;
 
@@ -64,12 +62,12 @@ free a smbw_dir structure and all entries
 *******************************************************/
 static void free_dir(struct smbw_dir *dir)
 {
-       if (dir->list) {
-               free(dir->list);
-       }
-       if (dir->path) free(dir->path);
+       if(!dir) return;
+
+       SAFE_FREE(dir->list);
+       SAFE_FREE(dir->path);
        ZERO_STRUCTP(dir);
-       free(dir);
+       SAFE_FREE(dir);
 }
 
 static struct smbw_dir *cur_dir;
@@ -80,16 +78,19 @@ add a entry to a directory listing
 static void smbw_dir_add(struct file_info *finfo, const char *mask, 
                         void *state)
 {
+       struct file_info *cdl;
+
        DEBUG(5,("%s\n", finfo->name));
 
        if (cur_dir->malloced == cur_dir->count) {
-               cur_dir->list = (struct file_info *)Realloc(cur_dir->list, 
+               cdl = (struct file_info *)Realloc(cur_dir->list, 
                                                            sizeof(cur_dir->list[0])*
                                                            (cur_dir->count+100));
-               if (!cur_dir->list) {
+               if (!cdl) {
                        /* oops */
                        return;
                }
+               cur_dir->list = cdl;
                cur_dir->malloced += 100;
        }
 
@@ -215,7 +216,7 @@ int smbw_dir_open(const char *fname)
                smbw_NetServerEnum(&srv->cli, srv->server_name, SV_TYPE_ALL,
                                   smbw_server_add, NULL);
                *p = '#';
-       } else if (strcmp(srv->cli.dev,"IPC") == 0) {
+       } else if ((strcmp(srv->cli.dev,"IPC") == 0) || (strcasecmp(share,"IPC$") == 0)) {
                DEBUG(4,("doing NetShareEnum\n"));
                smbw_share_add(".",0,"", NULL);
                smbw_share_add("..",0,"", NULL);
@@ -271,10 +272,8 @@ int smbw_dir_open(const char *fname)
        return dir->fd;
 
  failed:
-       if (dir) {
-               free_dir(dir);
-       }
-
+       free_dir(dir);
+       
        return -1;
 }
 
@@ -413,7 +412,8 @@ int smbw_chdir(const char *name)
                goto failed;
        }
 
-       if (strncmp(srv->cli.dev,"IPC",3) &&
+       if (strncmp(srv->cli.dev,"IPC",3) && 
+           strcasecmp(share, "IPC$") &&
            strncmp(srv->cli.dev,"LPT",3) &&
            !smbw_getatr(srv, path, 
                         &mode, NULL, NULL, NULL, NULL, NULL)) {
@@ -687,4 +687,3 @@ off_t smbw_telldir(DIR *dirp)
        struct smbw_dir *d = (struct smbw_dir *)dirp;
        return smbw_dir_lseek(d->fd,0,SEEK_CUR);
 }
-