bool expect_close;
char *wcard;
uint32_t attr;
- char *path;
+ struct smb_filename *smb_dname;
bool has_wild; /* Set to true if the wcard entry has MS wildcard characters in it. */
bool did_stat; /* Optimisation for non-wcard searches. */
bool priv; /* Directory handle opened with privilege. */
for(dptr = sconn->searches.dirptrs; dptr; dptr = dptr->next) {
if(dptr->dnum == key) {
if (!forclose && !dptr->dir_hnd) {
- struct smb_filename *smb_dname = NULL;
-
if (sconn->searches.dirhandles_open >= MAX_OPEN_DIRECTORIES)
dptr_idleoldest(sconn);
DEBUG(4,("dptr_get: Reopening dptr key %d\n",key));
- smb_dname = synthetic_smb_fname(talloc_tos(),
- dptr->path,
- NULL,
- NULL);
- if (smb_dname == NULL) {
- return NULL;
- }
-
if (!(dptr->dir_hnd = OpenDir(NULL,
dptr->conn,
- smb_dname,
+ dptr->smb_dname,
dptr->wcard,
dptr->attr))) {
DEBUG(4,("dptr_get: Failed to "
"open %s (%s)\n",
- dptr->path,
+ dptr->smb_dname->base_name,
strerror(errno)));
- TALLOC_FREE(smb_dname);
return NULL;
}
- TALLOC_FREE(smb_dname);
}
DLIST_PROMOTE(sconn->searches.dirptrs,dptr);
return dptr;
{
struct dptr_struct *dptr = dptr_get(sconn, key, false);
if (dptr)
- return(dptr->path);
+ return(dptr->smb_dname->base_name);
return(NULL);
}
struct dptr_struct *dptr, *next;
for(dptr = sconn->searches.dirptrs; dptr; dptr = next) {
next = dptr->next;
- if (spid == dptr->spid && strequal(dptr->path,path))
+ if (spid == dptr->spid &&
+ strequal(dptr->smb_dname->base_name,path)) {
dptr_close_internal(dptr);
+ }
}
}
static struct smb_Dir *open_dir_with_privilege(connection_struct *conn,
struct smb_request *req,
- const char *path,
+ const struct smb_filename *smb_dname,
const char *wcard,
uint32_t attr)
{
return NULL;
}
- if (vfs_ChDir(conn, path) == -1) {
+ if (vfs_ChDir(conn, smb_dname->base_name) == -1) {
return NULL;
}
if (!check_same_stat(&smb_fname_cwd->st, &priv_paths->parent_name.st)) {
DEBUG(0,("open_dir_with_privilege: stat mismatch between %s "
"and %s\n",
- path,
+ smb_dname->base_name,
smb_fname_str_dbg(&priv_paths->parent_name)));
goto out;
}
NTSTATUS dptr_create(connection_struct *conn,
struct smb_request *req,
files_struct *fsp,
- const char *path, bool old_handle, bool expect_close,uint16_t spid,
- const char *wcard, bool wcard_has_wild, uint32_t attr, struct dptr_struct **dptr_ret)
+ const struct smb_filename *smb_dname,
+ bool old_handle,
+ bool expect_close,
+ uint16_t spid,
+ const char *wcard,
+ bool wcard_has_wild,
+ uint32_t attr,
+ struct dptr_struct **dptr_ret)
{
struct smbd_server_connection *sconn = conn->sconn;
struct dptr_struct *dptr = NULL;
struct smb_Dir *dir_hnd;
if (fsp && fsp->is_directory && fsp->fh->fd != -1) {
- path = fsp->fsp_name->base_name;
+ smb_dname = fsp->fsp_name;
}
- DEBUG(5,("dptr_create dir=%s\n", path));
+ DEBUG(5,("dptr_create dir=%s\n", smb_dname->base_name));
if (sconn == NULL) {
DEBUG(0,("dptr_create: called with fake connection_struct\n"));
if (!(fsp->access_mask & SEC_DIR_LIST)) {
DEBUG(5,("dptr_create: directory %s "
"not open for LIST access\n",
- path));
+ smb_dname->base_name));
return NT_STATUS_ACCESS_DENIED;
}
dir_hnd = OpenDir_fsp(NULL, conn, fsp, wcard, attr);
} else {
int ret;
bool backup_intent = (req && req->priv_paths);
- struct smb_filename *smb_dname;
NTSTATUS status;
+ struct smb_filename *smb_dname_cp =
+ cp_smb_filename(talloc_tos(), smb_dname);
- smb_dname = synthetic_smb_fname(talloc_tos(), path,
- NULL, NULL);
- if (smb_dname == NULL) {
+ if (smb_dname_cp == NULL) {
return NT_STATUS_NO_MEMORY;
}
+
if (req != NULL && req->posix_pathnames) {
- ret = SMB_VFS_LSTAT(conn, smb_dname);
+ ret = SMB_VFS_LSTAT(conn, smb_dname_cp);
} else {
- ret = SMB_VFS_STAT(conn, smb_dname);
+ ret = SMB_VFS_STAT(conn, smb_dname_cp);
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ TALLOC_FREE(smb_dname_cp);
+ return status;
}
- if (!S_ISDIR(smb_dname->st.st_ex_mode)) {
+ if (!S_ISDIR(smb_dname_cp->st.st_ex_mode)) {
+ TALLOC_FREE(smb_dname_cp);
return NT_STATUS_NOT_A_DIRECTORY;
}
status = smbd_check_access_rights(conn,
- smb_dname,
+ smb_dname_cp,
backup_intent,
SEC_DIR_LIST);
if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(smb_dname_cp);
return status;
}
if (backup_intent) {
dir_hnd = open_dir_with_privilege(conn,
req,
- path,
+ smb_dname_cp,
wcard,
attr);
} else {
- dir_hnd = OpenDir(NULL, conn, smb_dname, wcard, attr);
+ dir_hnd = OpenDir(NULL,
+ conn,
+ smb_dname_cp,
+ wcard,
+ attr);
}
+ TALLOC_FREE(smb_dname_cp);
}
if (!dir_hnd) {
return NT_STATUS_NO_MEMORY;
}
- dptr->path = talloc_strdup(dptr, path);
- if (!dptr->path) {
+ dptr->smb_dname = cp_smb_filename(dptr, smb_dname);
+ if (!dptr->smb_dname) {
TALLOC_FREE(dptr);
TALLOC_FREE(dir_hnd);
return NT_STATUS_NO_MEMORY;
done:
DEBUG(3,("creating new dirptr %d for path %s, expect_close = %d\n",
- dptr->dnum,path,expect_close));
+ dptr->dnum,
+ dptr->smb_dname->base_name,
+ expect_close));
*dptr_ret = dptr;
while ((name = ReadDirName(dptr->dir_hnd, poffset, pst, &talloced))
!= NULL) {
- if (is_visible_file(dptr->conn, dptr->path, name, pst, True)) {
+ if (is_visible_file(dptr->conn,
+ dptr->smb_dname->base_name,
+ name,
+ pst,
+ true)) {
*ptalloced = talloced;
return name;
}
dptr->did_stat = true;
/* First check if it should be visible. */
- if (!is_visible_file(dptr->conn, dptr->path, dptr->wcard,
- pst, true))
- {
+ if (!is_visible_file(dptr->conn,
+ dptr->smb_dname->base_name,
+ dptr->wcard,
+ pst,
+ true)) {
/* This only returns false if the file was found, but
is explicitly not visible. Set us to end of
directory, but return NULL as we know we can't ever
pathreal = talloc_asprintf(ctx,
"%s/%s",
- dptr->path,
+ dptr->smb_dname->base_name,
dptr->wcard);
if (!pathreal)
return NULL;
* Try case-insensitive stat if the fs has the ability. This avoids
* scanning the whole directory.
*/
- ret = SMB_VFS_GET_REAL_FILENAME(dptr->conn, dptr->path, dptr->wcard,
- ctx, &found_name);
+ ret = SMB_VFS_GET_REAL_FILENAME(dptr->conn,
+ dptr->smb_dname->base_name,
+ dptr->wcard,
+ ctx,
+ &found_name);
if (ret == 0) {
name = found_name;
goto clean;
seekoff = map_wire_to_dir_offset(dptr, wire_offset);
SeekDir(dptr->dir_hnd,seekoff);
DEBUG(3,("fetching dirptr %d for path %s at offset %d\n",
- key, dptr->path, (int)seekoff));
+ key, dptr->smb_dname->base_name, (int)seekoff));
return(dptr);
}
DEBUG(3,("fetched null dirptr %d\n",dptr_num));
return(NULL);
}
- DEBUG(3,("fetching dirptr %d for path %s\n",dptr_num,dptr->path));
+ DEBUG(3,("fetching dirptr %d for path %s\n",
+ dptr_num,
+ dptr->smb_dname->base_name));
return(dptr);
}
connection_struct *conn = dirptr->conn;
size_t slashlen;
size_t pathlen;
- bool dirptr_path_is_dot = ISDOT(dirptr->path);
+ const char *dpath = dirptr->smb_dname->base_name;
+ bool dirptr_path_is_dot = ISDOT(dpath);
*_smb_fname = NULL;
*_mode = 0;
- pathlen = strlen(dirptr->path);
- slashlen = ( dirptr->path[pathlen-1] != '/') ? 1 : 0;
+ pathlen = strlen(dpath);
+ slashlen = ( dpath[pathlen-1] != '/') ? 1 : 0;
while (true) {
long cur_offset;
if (dirptr_path_is_dot) {
memcpy(pathreal, dname, talloc_get_size(dname));
} else {
- memcpy(pathreal, dirptr->path, pathlen);
+ memcpy(pathreal, dpath, pathlen);
pathreal[pathlen] = '/';
memcpy(pathreal + slashlen + pathlen, dname,
talloc_get_size(dname));