]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Factor out OpenDir_ntstatus()
authorVolker Lendecke <vl@samba.org>
Mon, 21 Feb 2022 16:17:24 +0000 (17:17 +0100)
committerRalph Boehme <slow@samba.org>
Tue, 22 Feb 2022 09:21:29 +0000 (09:21 +0000)
We might have callers interested in the exact NTSTATUS error code.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/dir.c
source3/smbd/proto.h

index 3c1ce7ebc179e3b7dc6a3cb09ccca269e2af1353..88c5d2758c83940d95c3c7507a6ddac48e1bb209 100644 (file)
@@ -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.
 ********************************************************************/
index a5edf6c1fe7f3d3e98e50772f1073c7bb68b5639..6ca5e125aaf6583b92e5582ce3a6e86fb3972a51 100644 (file)
@@ -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,