From: Volker Lendecke Date: Mon, 21 Feb 2022 16:17:24 +0000 (+0100) Subject: smbd: Factor out OpenDir_ntstatus() X-Git-Tag: tevent-0.12.0~671 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be201475167afaeb7824cbb40034b3dde4a182bb;p=thirdparty%2Fsamba.git smbd: Factor out OpenDir_ntstatus() We might have callers interested in the exact NTSTATUS error code. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 3c1ce7ebc17..88c5d2758c8 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1477,11 +1477,12 @@ static int smb_Dir_OpenDir_destructor(struct smb_Dir *dir_hnd) return 0; } -struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, - connection_struct *conn, - const struct smb_filename *smb_dname, - const char *mask, - uint32_t attr) +NTSTATUS OpenDir_ntstatus(TALLOC_CTX *mem_ctx, + connection_struct *conn, + const struct smb_filename *smb_dname, + const char *mask, + uint32_t attr, + struct smb_Dir **_dir_hnd) { struct files_struct *fsp = NULL; struct smb_Dir *dir_hnd = NULL; @@ -1492,15 +1493,12 @@ struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, O_RDONLY, &fsp); if (!NT_STATUS_IS_OK(status)) { - /* Ensure we return the actual error from status in errno. */ - errno = map_errno_from_nt_status(status); - return NULL; + return status; } status = OpenDir_fsp(mem_ctx, conn, fsp, mask, attr, &dir_hnd); if (!NT_STATUS_IS_OK(status)) { - errno = map_errno_from_nt_status(status); - return NULL; + return status; } /* @@ -1508,9 +1506,30 @@ struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, * but smb_Dir_OpenDir_destructor() calls the OpenDir_fsp() destructor. */ talloc_set_destructor(dir_hnd, smb_Dir_OpenDir_destructor); - return dir_hnd; + + *_dir_hnd = dir_hnd; + return NT_STATUS_OK; } +struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, + connection_struct *conn, + const struct smb_filename *smb_dname, + const char *mask, + uint32_t attr) +{ + struct smb_Dir *dir_hnd = NULL; + NTSTATUS status; + + status = OpenDir_ntstatus( + mem_ctx, conn, smb_dname, mask, attr, &dir_hnd); + if (!NT_STATUS_IS_OK(status)) { + /* Ensure we return the actual error from status in errno. */ + errno = map_errno_from_nt_status(status); + return NULL; + } + + return dir_hnd; +} /******************************************************************* Open a directory from an fsp. ********************************************************************/ diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index a5edf6c1fe7..6ca5e125aaf 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -231,6 +231,12 @@ bool get_dir_entry(TALLOC_CTX *ctx, bool ask_sharemode); struct smb_Dir; bool is_visible_fsp(files_struct *fsp); +NTSTATUS OpenDir_ntstatus(TALLOC_CTX *mem_ctx, + connection_struct *conn, + const struct smb_filename *smb_dname, + const char *mask, + uint32_t attr, + struct smb_Dir **_dir_hnd); struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn, const struct smb_filename *smb_fname,