void dptr_idlecnum(connection_struct *conn);
void dptr_closepath(struct smbd_server_connection *sconn,
char *path,uint16 spid);
-NTSTATUS dptr_create(connection_struct *conn, const char *path, bool old_handle, bool expect_close,uint16 spid,
+NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
+ const char *path, bool old_handle, bool expect_close,uint16 spid,
const char *wcard, bool wcard_has_wild, uint32 attr, struct dptr_struct **dptr_ret);
void dptr_CloseDir(files_struct *fsp);
void dptr_SeekDir(struct dptr_struct *dptr, long offset);
bool ask_sharemode);
bool is_visible_file(connection_struct *conn, const char *dir_path, const char *name, SMB_STRUCT_STAT *pst, bool use_veto);
struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn,
+ files_struct *fsp,
const char *name, const char *mask, uint32 attr);
const char *ReadDirName(struct smb_Dir *dirp, long *poffset,
SMB_STRUCT_STAT *sbuf, char **talloced);
dptr_idleoldest(sconn);
DEBUG(4,("dptr_get: Reopening dptr key %d\n",key));
if (!(dptr->dir_hnd = OpenDir(
- NULL, dptr->conn, dptr->path,
+ NULL, dptr->conn, NULL, dptr->path,
dptr->wcard, dptr->attr))) {
DEBUG(4,("dptr_get: Failed to open %s (%s)\n",dptr->path,
strerror(errno)));
wcard must not be zero.
****************************************************************************/
-NTSTATUS dptr_create(connection_struct *conn, const char *path, bool old_handle, bool expect_close,uint16 spid,
+NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
+ const char *path, bool old_handle, bool expect_close,uint16 spid,
const char *wcard, bool wcard_has_wild, uint32 attr, struct dptr_struct **dptr_ret)
{
struct smbd_server_connection *sconn = conn->sconn;
struct smb_Dir *dir_hnd;
NTSTATUS status;
+ if (fsp && fsp->is_directory && fsp->fh->fd != -1) {
+ path = fsp->fsp_name->base_name;
+ }
+
DEBUG(5,("dptr_create dir=%s\n", path));
if (sconn == NULL) {
return NT_STATUS_INVALID_PARAMETER;
}
- status = check_name(conn,path);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
+ if (!fsp) {
+ status = check_name(conn,path);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
}
- dir_hnd = OpenDir(NULL, conn, path, wcard, attr);
+ dir_hnd = OpenDir(NULL, conn, fsp, path, wcard, attr);
if (!dir_hnd) {
return map_nt_error_from_unix(errno);
}
********************************************************************/
struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn,
- const char *name, const char *mask, uint32 attr)
+ files_struct *fsp,
+ const char *name,
+ const char *mask,
+ uint32 attr)
{
struct smb_Dir *dirp = TALLOC_ZERO_P(mem_ctx, struct smb_Dir);
struct smbd_server_connection *sconn = conn->sconn;
dirp->conn = conn;
dirp->name_cache_size = lp_directory_name_cache_size(SNUM(conn));
- dirp->dir_path = talloc_strdup(dirp, name);
+ if (fsp) {
+ dirp->dir_path = talloc_strdup(dirp, fsp->fsp_name->base_name);
+ } else {
+ dirp->dir_path = talloc_strdup(dirp, name);
+ }
if (!dirp->dir_path) {
errno = ENOMEM;
goto fail;
}
talloc_set_destructor(dirp, smb_Dir_destructor);
- dirp->dir = SMB_VFS_OPENDIR(conn, dirp->dir_path, mask, attr);
+ if (fsp && fsp->is_directory && fsp->fh->fd != -1) {
+ dirp->dir = SMB_VFS_FDOPENDIR(fsp, mask, attr);
+ if (dirp->dir == NULL) {
+ DEBUG(10,("OpenDir: SMB_VFS_FDOPENDIR on %s returned "
+ "NULL (%s)\n",
+ dirp->dir_path,
+ strerror(errno)));
+ if (errno != ENOSYS) {
+ return NULL;
+ }
+ }
+ }
+
+ if (dirp->dir == NULL) {
+ /* FDOPENDIR didn't work - or fsp == NULL. Use
+ OPENDIR instead. */
+ dirp->dir = SMB_VFS_OPENDIR(conn, dirp->dir_path, mask, attr);
+ }
+
if (!dirp->dir) {
DEBUG(5,("OpenDir: Can't open %s. %s\n", dirp->dir_path,
strerror(errno) ));
const char *dname = NULL;
char *talloced = NULL;
SMB_STRUCT_STAT st;
- struct smb_Dir *dir_hnd = OpenDir(talloc_tos(), conn, dirname,
- NULL, 0);
+ struct smb_Dir *dir_hnd = OpenDir(talloc_tos(), conn, NULL,
+ dirname, NULL, 0);
if (!dir_hnd) {
return map_nt_error_from_unix(errno);
SCVAL(status,0,(dirtype & 0x1F));
nt_status = dptr_create(conn,
+ NULL, /* fsp */
directory,
True,
expect_close,
goto out;
}
- dir_hnd = OpenDir(talloc_tos(), conn, fname_dir, fname_mask,
+ dir_hnd = OpenDir(talloc_tos(), conn, NULL, fname_dir, fname_mask,
dirtype);
if (dir_hnd == NULL) {
status = map_nt_error_from_unix(errno);
goto out;
}
- dir_hnd = OpenDir(talloc_tos(), conn, fname_src_dir, fname_src_mask,
+ dir_hnd = OpenDir(talloc_tos(), conn, NULL, fname_src_dir, fname_src_mask,
attrs);
if (dir_hnd == NULL) {
status = map_nt_error_from_unix(errno);
goto out;
}
- dir_hnd = OpenDir(ctx, conn, fname_src_dir, fname_src_mask, 0);
+ dir_hnd = OpenDir(ctx, conn, NULL, fname_src_dir, fname_src_mask, 0);
if (dir_hnd == NULL) {
status = map_nt_error_from_unix(errno);
reply_nterror(req, status);