summaryrefslogtreecommitdiff
path: root/source3/smbd/dir.c
diff options
context:
space:
mode:
authorAravind Srinivasan <aravind.srinivasan@isilon.com>2009-05-11 22:39:05 +0000
committerTim Prouty <tprouty@samba.org>2009-05-18 21:50:07 -0700
commit1718e803dc9269f8ba0db4260cc3b8a000da248a (patch)
tree7cac516d3d788add46b5f0567dd5897029dd0fbb /source3/smbd/dir.c
parentd38e5d18a7ad5db0ace78afe3b42ec5f5174752b (diff)
downloadsamba-1718e803dc9269f8ba0db4260cc3b8a000da248a.tar.gz
samba-1718e803dc9269f8ba0db4260cc3b8a000da248a.tar.bz2
samba-1718e803dc9269f8ba0db4260cc3b8a000da248a.zip
s3: Always allocate memory in dptr_ReadDirName
This is a follow up to 69d61453df6019caef4e7960fa78c6a3c51f3d2a to adjust the API to allow the lower layers allocate memory. Now the memory can explicitly be freed rather than relying on talloc_tos(). Signed-off-by: Tim Prouty <tprouty@samba.org>
Diffstat (limited to 'source3/smbd/dir.c')
-rw-r--r--source3/smbd/dir.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index e7902871d3..ab4a0d27e3 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -569,7 +569,7 @@ static const char *dptr_normal_ReadDirName(struct dptr_struct *dptr,
Return the next visible file name, skipping veto'd and invisible files.
****************************************************************************/
-const char *dptr_ReadDirName(TALLOC_CTX *ctx,
+char *dptr_ReadDirName(TALLOC_CTX *ctx,
struct dptr_struct *dptr,
long *poffset,
SMB_STRUCT_STAT *pst)
@@ -578,11 +578,14 @@ const char *dptr_ReadDirName(TALLOC_CTX *ctx,
char *pathreal = NULL;
char *found_name = NULL;
int ret;
+ const char *name_temp = NULL;
SET_STAT_INVALID(*pst);
if (dptr->has_wild || dptr->did_stat) {
- return dptr_normal_ReadDirName(dptr, poffset, pst);
+ name_temp = dptr_normal_ReadDirName(dptr, poffset, pst);
+ name = talloc_strdup(ctx, name_temp);
+ return name;
}
/* If poffset is -1 then we know we returned this name before and we
@@ -610,7 +613,7 @@ const char *dptr_ReadDirName(TALLOC_CTX *ctx,
}
if (VALID_STAT(*pst)) {
- name = dptr->wcard;
+ name = talloc_strdup(ctx, dptr->wcard);
goto ret;
}
@@ -622,13 +625,13 @@ const char *dptr_ReadDirName(TALLOC_CTX *ctx,
return NULL;
if (SMB_VFS_STAT(dptr->conn, pathreal, pst) == 0) {
- name = dptr->wcard;
+ name = talloc_strdup(ctx, dptr->wcard);
goto clean;
} else {
/* If we get any other error than ENOENT or ENOTDIR
then the file exists we just can't stat it. */
if (errno != ENOENT && errno != ENOTDIR) {
- name = dptr->wcard;
+ name = talloc_strdup(ctx, dptr->wcard);
goto clean;
}
}
@@ -659,7 +662,9 @@ const char *dptr_ReadDirName(TALLOC_CTX *ctx,
TALLOC_FREE(pathreal);
- return dptr_normal_ReadDirName(dptr, poffset, pst);
+ name_temp = dptr_normal_ReadDirName(dptr, poffset, pst);
+ name = talloc_strdup(ctx, name_temp);
+ return name;
clean:
TALLOC_FREE(pathreal);
@@ -823,11 +828,11 @@ bool get_dir_entry(TALLOC_CTX *ctx,
bool check_descend,
bool ask_sharemode)
{
- const char *dname = NULL;
+ char *dname = NULL;
bool found = False;
SMB_STRUCT_STAT sbuf;
char *pathreal = NULL;
- const char *filename = NULL;
+ char *filename = NULL;
bool needslash;
*pp_fname_out = NULL;
@@ -863,9 +868,13 @@ bool get_dir_entry(TALLOC_CTX *ctx,
if (!mangle_is_8_3(filename, False, conn->params)) {
if (!name_to_8_3(filename,mname,False,
conn->params)) {
+ TALLOC_FREE(filename);
continue;
}
- filename = mname;
+ filename = talloc_strdup(ctx, mname);
+ if (!filename) {
+ return False;
+ }
}
if (needslash) {
@@ -880,6 +889,7 @@ bool get_dir_entry(TALLOC_CTX *ctx,
dname);
}
if (!pathreal) {
+ TALLOC_FREE(filename);
return False;
}
@@ -887,6 +897,7 @@ bool get_dir_entry(TALLOC_CTX *ctx,
DEBUG(5,("Couldn't stat 1 [%s]. Error = %s\n",
pathreal, strerror(errno) ));
TALLOC_FREE(pathreal);
+ TALLOC_FREE(filename);
continue;
}
@@ -895,6 +906,7 @@ bool get_dir_entry(TALLOC_CTX *ctx,
if (!dir_check_ftype(conn,*mode,dirtype)) {
DEBUG(5,("[%s] attribs 0x%x didn't match 0x%x\n",filename,(unsigned int)*mode,(unsigned int)dirtype));
TALLOC_FREE(pathreal);
+ TALLOC_FREE(filename);
continue;
}
@@ -921,14 +933,15 @@ bool get_dir_entry(TALLOC_CTX *ctx,
found = True;
- *pp_fname_out = talloc_strdup(ctx, filename);
- if (!*pp_fname_out) {
- return False;
- }
+ SMB_ASSERT(filename != NULL);
+ *pp_fname_out = filename;
DirCacheAdd(conn->dirptr->dir_hnd, dname, curoff);
TALLOC_FREE(pathreal);
}
+
+ if (!found)
+ TALLOC_FREE(filename);
}
return(found);