smbd: Add posix create ctx to CREATE_FILE for posix operations
authorVolker Lendecke <vl@samba.org>
Tue, 4 Feb 2020 12:58:02 +0000 (14:58 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 7 Feb 2020 21:01:31 +0000 (21:01 +0000)
This will replace overloading file attributes

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/reply.c
source3/smbd/trans2.c

index 40cd7483750785433124c9c306d0b297bf61498e..b5d9fb78d2d8f4419b3d9e0e8f7b272cb307cbb9 100644 (file)
@@ -46,6 +46,7 @@
 #include "lib/util/sys_rw_data.h"
 #include "librpc/gen_ndr/open_files.h"
 #include "smb1_utils.h"
+#include "libcli/smb/smb2_posix.h"
 
 /****************************************************************************
  Ensure we check the path in *exactly* the same way as W2K for a findfirst/findnext
@@ -3035,6 +3036,7 @@ static NTSTATUS do_unlink(connection_struct *conn,
        NTSTATUS status;
        int ret;
        bool posix_paths = (req != NULL && req->posix_pathnames);
+       struct smb2_create_blobs *posx = NULL;
 
        DEBUG(10,("do_unlink: %s, dirtype = %d\n",
                  smb_fname_str_dbg(smb_fname),
@@ -3106,6 +3108,16 @@ static NTSTATUS do_unlink(connection_struct *conn,
                return NT_STATUS_OBJECT_NAME_INVALID;
 #endif /* JRATEST */
 
+       if (posix_paths) {
+               status = make_smb2_posix_create_ctx(
+                       talloc_tos(), &posx, 0777);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
+                                   nt_errstr(status));
+                       return status;
+               }
+       }
+
        /* On open checks the open itself will check the share mode, so
           don't do it here as we'll get it wrong. */
 
@@ -3129,7 +3141,10 @@ static NTSTATUS do_unlink(connection_struct *conn,
                 NULL,                  /* ea_list */
                 &fsp,                  /* result */
                 NULL,                  /* pinfo */
-                NULL, NULL);           /* create context */
+                posx,                  /* in_context_blobs */
+                NULL);                 /* out_context_blobs */
+
+       TALLOC_FREE(posx);
 
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("SMB_VFS_CREATEFILE failed: %s\n",
@@ -7295,6 +7310,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
        long offset = 0;
        int create_options = 0;
        bool posix_pathnames = (req != NULL && req->posix_pathnames);
+       struct smb2_create_blobs *posx = NULL;
        int rc;
 
        /*
@@ -7334,6 +7350,15 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                }
        }
 
+       if (posix_pathnames) {
+               status = make_smb2_posix_create_ctx(talloc_tos(), &posx, 0777);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
+                                   nt_errstr(status));
+                       goto out;
+               }
+       }
+
        if (!src_has_wild) {
                files_struct *fsp;
 
@@ -7420,7 +7445,8 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                        NULL,                           /* ea_list */
                        &fsp,                           /* result */
                        NULL,                           /* pinfo */
-                       NULL, NULL);                    /* create context */
+                       posx,                           /* in_context_blobs */
+                       NULL);                          /* out_context_blobs */
 
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(3, ("Could not open rename source %s: %s\n",
@@ -7578,7 +7604,8 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                        NULL,                           /* ea_list */
                        &fsp,                           /* result */
                        NULL,                           /* pinfo */
-                       NULL, NULL);                    /* create context */
+                       posx,                           /* in_context_blobs */
+                       NULL);                          /* out_context_blobs */
 
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(3,("rename_internals: SMB_VFS_CREATE_FILE "
@@ -7623,6 +7650,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
        }
 
  out:
+       TALLOC_FREE(posx);
        TALLOC_FREE(talloced);
        TALLOC_FREE(smb_fname_src_dir);
        TALLOC_FREE(fname_src_dir);
index 2617da9b17a4925ba1e9131d92ce17fe065e7413..de5600ec93f31abd350ab82c495bca357bb5473d 100644 (file)
@@ -43,6 +43,7 @@
 #include "lib/readdir_attr.h"
 #include "messages.h"
 #include "smb1_utils.h"
+#include "libcli/smb/smb2_posix.h"
 
 #define DIR_ENTRY_SAFETY_MARGIN 4096
 
@@ -118,6 +119,8 @@ static NTSTATUS get_posix_fsp(connection_struct *conn,
        uint32_t share_access = FILE_SHARE_READ|
                                FILE_SHARE_WRITE|
                                FILE_SHARE_DELETE;
+       struct smb2_create_blobs *posx = NULL;
+
        /*
         * Only FILE_FLAG_POSIX_SEMANTICS matters on existing files,
         * but set reasonable defaults.
@@ -152,6 +155,16 @@ static NTSTATUS get_posix_fsp(connection_struct *conn,
                goto done;
        }
 
+       status = make_smb2_posix_create_ctx(
+               talloc_tos(),
+               &posx,
+               file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
+                           nt_errstr(status));
+               goto done;
+       }
+
        status = SMB_VFS_CREATE_FILE(
                conn,           /* conn */
                req,            /* req */
@@ -170,10 +183,11 @@ static NTSTATUS get_posix_fsp(connection_struct *conn,
                NULL,           /* ea_list */
                ret_fsp,        /* result */
                NULL,           /* pinfo */
-               NULL,           /* in_context */
+               posx,           /* in_context */
                NULL);          /* out_context */
 
 done:
+       TALLOC_FREE(posx);
        TALLOC_FREE(smb_fname_tmp);
        return status;
 }
@@ -8404,6 +8418,7 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
        uint16_t info_level_return = 0;
        int info;
        char *pdata = *ppdata;
+       struct smb2_create_blobs *posx = NULL;
 
        if (total_data < 18) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -8420,6 +8435,13 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
 
        mod_unixmode = (uint32_t)unixmode | FILE_FLAG_POSIX_SEMANTICS;
 
+       status = make_smb2_posix_create_ctx(talloc_tos(), &posx, unixmode);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
+                           nt_errstr(status));
+               return status;
+       }
+
        DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
                  smb_fname_str_dbg(smb_fname), (unsigned int)unixmode));
 
@@ -8441,7 +8463,10 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
                &info,                                  /* pinfo */
-               NULL, NULL);                            /* create context */
+               posx,                                   /* in_context_blobs */
+               NULL);                                  /* out_context_blobs */
+
+       TALLOC_FREE(posx);
 
         if (NT_STATUS_IS_OK(status)) {
                 close_file(req, fsp, NORMAL_CLOSE);
@@ -8520,6 +8545,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
        int oplock_request = 0;
        int info = 0;
        uint16_t info_level_return = 0;
+       struct smb2_create_blobs *posx = NULL;
 
        if (total_data < 18) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -8630,6 +8656,13 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                return status;
        }
 
+       status = make_smb2_posix_create_ctx(talloc_tos(), &posx, unixmode);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
+                           nt_errstr(status));
+               return status;
+       }
+
        mod_unixmode = (uint32_t)unixmode | FILE_FLAG_POSIX_SEMANTICS;
 
        if (wire_open_mode & SMB_O_SYNC) {
@@ -8675,7 +8708,10 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
                &info,                                  /* pinfo */
-               NULL, NULL);                            /* create context */
+               posx,                                   /* in_context_blobs */
+               NULL);                                  /* out_context_blobs */
+
+       TALLOC_FREE(posx);
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -8764,6 +8800,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
        int create_options = 0;
        struct share_mode_lock *lck = NULL;
        bool other_nonposix_opens;
+       struct smb2_create_blobs *posx = NULL;
 
        if (total_data < 2) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -8788,6 +8825,13 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                create_options |= FILE_DIRECTORY_FILE;
        }
 
+       status = make_smb2_posix_create_ctx(talloc_tos(), &posx, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
+                           nt_errstr(status));
+               return status;
+       }
+
         status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -8807,7 +8851,10 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
                &info,                                  /* pinfo */
-               NULL, NULL);                            /* create context */
+               posx,                                   /* in_context_blobs */
+               NULL);                                  /* out_context_blobs */
+
+       TALLOC_FREE(posx);
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;