diff options
Diffstat (limited to 'source/smbd/dir.c')
-rw-r--r-- | source/smbd/dir.c | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/source/smbd/dir.c b/source/smbd/dir.c index ac6f918b9da..42bd54c2703 100644 --- a/source/smbd/dir.c +++ b/source/smbd/dir.c @@ -20,7 +20,6 @@ */ #include "includes.h" -#include "loadparm.h" extern int DEBUGLEVEL; extern connection_struct Connections[]; @@ -186,6 +185,19 @@ close a dptr ****************************************************************************/ void dptr_close(int key) { + /* OS/2 seems to use -1 to indicate "close all directories" */ + if (key == -1) { + int i; + for (i=0;i<NUMDIRPTRS;i++) + dptr_close(i); + return; + } + + if (key < 0 || key >= NUMDIRPTRS) { + DEBUG(3,("Invalid key %d given to dptr_close\n",key)); + return; + } + if (dirptrs[key].valid) { DEBUG(4,("closing dptr key %d\n",key)); if (dirptrs[key].ptr) { @@ -399,6 +411,16 @@ void *dptr_fetch_lanman2(char *params,int dptr_num) } /**************************************************************************** +check a filetype for being valid +****************************************************************************/ +BOOL dir_check_ftype(int cnum,int mode,struct stat *st,int dirtype) +{ + if (((mode & ~dirtype) & (aHIDDEN | aSYSTEM | aDIR)) != 0) + return False; + return True; +} + +/**************************************************************************** get a directory entry ****************************************************************************/ BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend) @@ -461,11 +483,11 @@ BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mo *mode = dos_mode(cnum,pathreal,&sbuf); - if (((*mode & ~dirtype) & (aHIDDEN | aSYSTEM | aDIR)) != 0) - { - DEBUG(5,("[%s] attribs didn't match %x\n",filename,dirtype)); - continue; - } + if (!dir_check_ftype(cnum,*mode,&sbuf,dirtype)) { + DEBUG(5,("[%s] attribs didn't match %x\n",filename,dirtype)); + continue; + } + *size = sbuf.st_size; *date = sbuf.st_mtime; @@ -609,6 +631,7 @@ add an entry to the directory cache ********************************************************************/ void DirCacheAdd(char *path,char *name,char *dname,int snum) { + int count; struct dir_cache *entry = (struct dir_cache *)malloc(sizeof(*entry)); if (!entry) return; entry->path = strdup(path); @@ -625,7 +648,12 @@ void DirCacheAdd(char *path,char *name,char *dname,int snum) DEBUG(4,("Added dir cache entry %s %s -> %s\n",path,name,dname)); if (dir_cache_size == DIRCACHESIZE) { - for (entry=dir_cache; entry->next; entry=entry->next) ; + for (entry=dir_cache, count=1; + entry->next && count < dir_cache_size; + entry=entry->next, count++) ; + if (entry->next || count != dir_cache_size) { + DEBUG(0,("DirCache bug - please report\n")); + } free(entry->path); free(entry->name); free(entry->dname); @@ -673,6 +701,7 @@ void DirCacheFlush(int snum) if (entry->next) entry->next->prev = entry->prev; if (dir_cache == entry) dir_cache = entry->next; free(entry); + dir_cache_size--; } else { next = entry->next; } |