s3: Add SMB_VFS_CREATE_FILE to the vfs layer
authorTim Prouty <tprouty@samba.org>
Tue, 21 Oct 2008 00:43:45 +0000 (17:43 -0700)
committerTim Prouty <tprouty@samba.org>
Thu, 4 Dec 2008 01:50:17 +0000 (17:50 -0800)
Modify all callers of create_file to go through SMB_VFS_CREATE_FILE

source3/include/proto.h
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_default.c
source3/rpc_server/srv_srvsvc_nt.c
source3/smbd/nttrans.c
source3/smbd/open.c
source3/smbd/reply.c
source3/smbd/trans2.c

index d9430e2909beb44e1c8973ad97e56b37fd3598fd..05ef17b51cac11522366deef6fef2d0dedc4450a 100644 (file)
@@ -8150,23 +8150,23 @@ NTSTATUS create_file_unixpath(connection_struct *conn,
                              files_struct **result,
                              int *pinfo,
                              SMB_STRUCT_STAT *psbuf);
-NTSTATUS create_file(connection_struct *conn,
-                    struct smb_request *req,
-                    uint16_t root_dir_fid,
-                    const char *fname,
-                    uint32_t access_mask,
-                    uint32_t share_access,
-                    uint32_t create_disposition,
-                    uint32_t create_options,
-                    uint32_t file_attributes,
-                    uint32_t oplock_request,
-                    uint64_t allocation_size,
-                    struct security_descriptor *sd,
-                    struct ea_list *ea_list,
-
-                    files_struct **result,
-                    int *pinfo,
-                    SMB_STRUCT_STAT *psbuf);
+NTSTATUS create_file_default(connection_struct *conn,
+                            struct smb_request *req,
+                            uint16_t root_dir_fid,
+                            const char *fname,
+                            uint32_t access_mask,
+                            uint32_t share_access,
+                            uint32_t create_disposition,
+                            uint32_t create_options,
+                            uint32_t file_attributes,
+                            uint32_t oplock_request,
+                            uint64_t allocation_size,
+                            struct security_descriptor *sd,
+                            struct ea_list *ea_list,
+
+                            files_struct **result,
+                            int *pinfo,
+                            SMB_STRUCT_STAT *psbuf);
 
 /* The following definitions come from smbd/oplock.c  */
 
index 4cedb4a9c6bfcc1895323867a7f69e1a6c796584..03b4b8e70623c3e7faa3d8d02261e17528e90ed0 100644 (file)
    open handle. JRA. */
 /* Changed to version 24 - make security descriptor const in fset_nt_acl. JRA. */
 /* Changed to version 25 - Jelmer's change from SMB_BIG_UINT to uint64_t. */
+/* Leave at 25 - not yet released. Add create_file call. -- tprouty. */
 
 #define SMB_VFS_INTERFACE_VERSION 25
 
@@ -134,6 +135,8 @@ struct connection_struct;
 struct files_struct;
 struct security_descriptor;
 struct vfs_statvfs_struct;
+struct smb_request;
+struct ea_list;
 
 /*
     Available VFS operations. These values must be in sync with vfs_ops struct
@@ -170,6 +173,7 @@ typedef enum _vfs_op_type {
        /* File operations */
 
        SMB_VFS_OP_OPEN,
+       SMB_VFS_OP_CREATE_FILE,
        SMB_VFS_OP_CLOSE,
        SMB_VFS_OP_READ,
        SMB_VFS_OP_PREAD,
@@ -305,6 +309,22 @@ struct vfs_ops {
                /* File operations */
 
                int (*open)(struct vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode);
+               NTSTATUS (*create_file)(struct vfs_handle_struct *handle,
+                                       struct smb_request *req,
+                                       uint16_t root_dir_fid,
+                                       const char *fname,
+                                       uint32_t access_mask,
+                                       uint32_t share_access,
+                                       uint32_t create_disposition,
+                                       uint32_t create_options,
+                                       uint32_t file_attributes,
+                                       uint32_t oplock_request,
+                                       uint64_t allocation_size,
+                                       struct security_descriptor *sd,
+                                       struct ea_list *ea_list,
+                                       files_struct **result,
+                                       int *pinfo,
+                                       SMB_STRUCT_STAT *psbuf);
                int (*close_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp);
                ssize_t (*vfs_read)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n);
                ssize_t (*pread)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n, SMB_OFF_T offset);
@@ -452,6 +472,7 @@ struct vfs_ops {
                /* File operations */
 
                struct vfs_handle_struct *open;
+               struct vfs_handle_struct *create_file;
                struct vfs_handle_struct *close_hnd;
                struct vfs_handle_struct *vfs_read;
                struct vfs_handle_struct *pread;
index 8fbc21b12d426fc1dc238f60172e8735b715b22b..5c57e92899876b7476ef6f04c514c0c1c60f085d 100644 (file)
@@ -48,6 +48,7 @@
 
 /* File operations */
 #define SMB_VFS_OPEN(conn, fname, fsp, flags, mode) (((conn)->vfs.ops.open)((conn)->vfs.handles.open, (fname), (fsp), (flags), (mode)))
+#define SMB_VFS_CREATE_FILE(conn, req, root_dir_fid, fname, access_mask, share_access, create_disposition, create_options, file_attributes, oplock_request, allocation_size, sd, ea_list, result, pinfo, psbuf) (((conn)->vfs.ops.create_file)((conn)->vfs.handles.create_file, (req), (root_dir_fid), (fname), (access_mask), (share_access), (create_disposition), (create_options), (file_attributes), (oplock_request), (allocation_size), (sd), (ea_list), (result), (pinfo), (psbuf)))
 #define SMB_VFS_CLOSE(fsp) ((fsp)->conn->vfs.ops.close_fn((fsp)->conn->vfs.handles.close_hnd, (fsp)))
 #define SMB_VFS_READ(fsp, data, n) ((fsp)->conn->vfs.ops.vfs_read((fsp)->conn->vfs.handles.vfs_read, (fsp), (data), (n)))
 #define SMB_VFS_PREAD(fsp, data, n, off) ((fsp)->conn->vfs.ops.pread((fsp)->conn->vfs.handles.pread, (fsp), (data), (n), (off)))
 
 /* File operations */
 #define SMB_VFS_OPAQUE_OPEN(conn, fname, fsp, flags, mode) (((conn)->vfs_opaque.ops.open)((conn)->vfs_opaque.handles.open, (fname), (fsp), (flags), (mode)))
+#define SMB_VFS_OPAQUE_CREATE_FILE(conn, req, root_dir_fid, fname, access_mask, share_access, create_disposition, create_options, file_attributes, oplock_request, allocation_size, sd, ea_list, result, pinfo, psbuf) (((conn)->vfs_opaque.ops.create_file)((conn)->vfs_opaque.handles.create_file, (req), (root_dir_fid), (fname), (access_mask), (share_access), (create_disposition), (create_options), (file_attributes), (oplock_request), (allocation_size), (sd), (ea_list), (result), (pinfo), (psbuf)))
 #define SMB_VFS_OPAQUE_CLOSE(fsp) ((fsp)->conn->vfs_opaque.ops.close_fn((fsp)->conn->vfs_opaque.handles.close_hnd, (fsp)))
 #define SMB_VFS_OPAQUE_READ(fsp, data, n) ((fsp)->conn->vfs_opaque.ops.vfs_read((fsp)->conn->vfs_opaque.handles.vfs_read, (fsp), (data), (n)))
 #define SMB_VFS_OPAQUE_PREAD(fsp, data, n, off) ((fsp)->conn->vfs_opaque.ops.pread((fsp)->conn->vfs_opaque.handles.pread, (fsp), (data), (n), (off)))
 
 /* File operations */
 #define SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode) (((handle)->vfs_next.ops.open)((handle)->vfs_next.handles.open, (fname), (fsp), (flags), (mode)))
+#define SMB_VFS_NEXT_CREATE_FILE(handle, req, root_dir_fid, fname, access_mask, share_access, create_disposition, create_options, file_attributes, oplock_request, allocation_size, sd, ea_list, result, pinfo, psbuf) (((handle)->vfs_next.ops.create_file)((handle)->vfs_next.handles.create_file, (req), (root_dir_fid), (fname), (access_mask), (share_access), (create_disposition), (create_options), (file_attributes), (oplock_request), (allocation_size), (sd), (ea_list), (result), (pinfo), (psbuf)))
 #define SMB_VFS_NEXT_CLOSE(handle, fsp) ((handle)->vfs_next.ops.close_fn((handle)->vfs_next.handles.close_hnd, (fsp)))
 #define SMB_VFS_NEXT_READ(handle, fsp, data, n) ((handle)->vfs_next.ops.vfs_read((handle)->vfs_next.handles.vfs_read, (fsp), (data), (n)))
 #define SMB_VFS_NEXT_PREAD(handle, fsp, data, n, off) ((handle)->vfs_next.ops.pread((handle)->vfs_next.handles.pread, (fsp), (data), (n), (off)))
index d972828ba974c6e8f5325e526ccdc6f8e6ea6a72..bca06dfaf7a53a06e1587f247d4ae1146b0fdae7 100644 (file)
@@ -208,6 +208,31 @@ static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
        return result;
 }
 
+static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
+                                   struct smb_request *req,
+                                   uint16_t root_dir_fid,
+                                   const char *fname,
+                                   uint32_t access_mask,
+                                   uint32_t share_access,
+                                   uint32_t create_disposition,
+                                   uint32_t create_options,
+                                   uint32_t file_attributes,
+                                   uint32_t oplock_request,
+                                   uint64_t allocation_size,
+                                   struct security_descriptor *sd,
+                                   struct ea_list *ea_list,
+                                   files_struct **result,
+                                   int *pinfo,
+                                   SMB_STRUCT_STAT *psbuf)
+{
+       return create_file_default(handle->conn, req, root_dir_fid, fname,
+                                  access_mask, share_access,
+                                  create_disposition, create_options,
+                                  file_attributes, oplock_request,
+                                  allocation_size, sd, ea_list, result, pinfo,
+                                  psbuf);
+}
+
 static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
 {
        int result;
@@ -1359,6 +1384,8 @@ static vfs_op_tuple vfs_default_ops[] = {
 
        {SMB_VFS_OP(vfswrap_open),      SMB_VFS_OP_OPEN,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_create_file),       SMB_VFS_OP_CREATE_FILE,
+        SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_close),     SMB_VFS_OP_CLOSE,
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_read),      SMB_VFS_OP_READ,
index bf3669022de4af2349b8cf88c918e18c01fd8e76..b1a31f17611df71b21412a9cc240f7ad32eb543d 100644 (file)
@@ -2048,7 +2048,7 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       nt_status = create_file(
+       nt_status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
                0,                                      /* root_dir_fid */
@@ -2162,7 +2162,7 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       nt_status = create_file(
+       nt_status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
                0,                                      /* root_dir_fid */
index 777073e6ba7d1296d3cee776caf2220bd35fc611..f2c6eaccca31baf734ed37aa584e806e8913687b 100644 (file)
@@ -474,10 +474,23 @@ void reply_ntcreate_and_X(struct smb_request *req)
                        ? BATCH_OPLOCK : 0;
        }
 
-       status = create_file(conn, req, root_dir_fid, fname,
-                            access_mask, share_access, create_disposition,
-                            create_options, file_attributes, oplock_request,
-                            allocation_size, NULL, NULL, &fsp, &info, &sbuf);
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               root_dir_fid,                           /* root_dir_fid */
+               fname,                                  /* fname */
+               access_mask,                            /* access_mask */
+               share_access,                           /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               file_attributes,                        /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               allocation_size,                        /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &fsp,                                   /* result */
+               &info,                                  /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
@@ -932,10 +945,23 @@ static void call_nt_transact_create(connection_struct *conn,
                        ? BATCH_OPLOCK : 0;
        }
 
-       status = create_file(conn, req, root_dir_fid, fname,
-                            access_mask, share_access, create_disposition,
-                            create_options, file_attributes, oplock_request,
-                            allocation_size, sd, ea_list, &fsp, &info, &sbuf);
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               root_dir_fid,                           /* root_dir_fid */
+               fname,                                  /* fname */
+               access_mask,                            /* access_mask */
+               share_access,                           /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               file_attributes,                        /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               allocation_size,                        /* allocation_size */
+               sd,                                     /* sd */
+               ea_list,                                /* ea_list */
+               &fsp,                                   /* result */
+               &info,                                  /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if(!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
index f98415ee33f350c8831a3e3f0e84009b2f14c2d2..924b6c5905ddc22c4814b66fe0c7889b9aef4222 100644 (file)
@@ -3082,23 +3082,23 @@ NTSTATUS create_file_unixpath(connection_struct *conn,
        return status;
 }
 
-NTSTATUS create_file(connection_struct *conn,
-                    struct smb_request *req,
-                    uint16_t root_dir_fid,
-                    const char *fname,
-                    uint32_t access_mask,
-                    uint32_t share_access,
-                    uint32_t create_disposition,
-                    uint32_t create_options,
-                    uint32_t file_attributes,
-                    uint32_t oplock_request,
-                    uint64_t allocation_size,
-                    struct security_descriptor *sd,
-                    struct ea_list *ea_list,
-
-                    files_struct **result,
-                    int *pinfo,
-                    SMB_STRUCT_STAT *psbuf)
+NTSTATUS create_file_default(connection_struct *conn,
+                            struct smb_request *req,
+                            uint16_t root_dir_fid,
+                            const char *fname,
+                            uint32_t access_mask,
+                            uint32_t share_access,
+                            uint32_t create_disposition,
+                            uint32_t create_options,
+                            uint32_t file_attributes,
+                            uint32_t oplock_request,
+                            uint64_t allocation_size,
+                            struct security_descriptor *sd,
+                            struct ea_list *ea_list,
+
+                            files_struct **result,
+                            int *pinfo,
+                            SMB_STRUCT_STAT *psbuf)
 {
        struct case_semantics_state *case_state = NULL;
        SMB_STRUCT_STAT sbuf;
index 11c713ab4ad14df4bc4e59ce9ab71ef235b63472..dfd4b47608ad564234b5cebd133849c70393b0e9 100644 (file)
@@ -1630,22 +1630,23 @@ void reply_open(struct smb_request *req)
                return;
        }
 
-       status = create_file(conn,                      /* conn */
-                            req,                       /* req */
-                            0,                         /* root_dir_fid */
-                            fname,                     /* fname */
-                            access_mask,               /* access_mask */
-                            share_mode,                /* share_access */
-                            create_disposition,        /* create_disposition*/
-                            create_options,            /* create_options */
-                            dos_attr,                  /* file_attributes */
-                            oplock_request,            /* oplock_request */
-                            0,                         /* allocation_size */
-                            NULL,                      /* sd */
-                            NULL,                      /* ea_list */
-                            &fsp,                      /* result */
-                            &info,                     /* pinfo */
-                            &sbuf);                    /* psbuf */
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               access_mask,                            /* access_mask */
+               share_mode,                             /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               dos_attr,                               /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &fsp,                                   /* result */
+               &info,                                  /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
@@ -1774,22 +1775,23 @@ void reply_open_and_X(struct smb_request *req)
                return;
        }
 
-       status = create_file(conn,                      /* conn */
-                            req,                       /* req */
-                            0,                         /* root_dir_fid */
-                            fname,                     /* fname */
-                            access_mask,               /* access_mask */
-                            share_mode,                /* share_access */
-                            create_disposition,        /* create_disposition*/
-                            create_options,            /* create_options */
-                            smb_attr,                  /* file_attributes */
-                            oplock_request,            /* oplock_request */
-                            0,                         /* allocation_size */
-                            NULL,                      /* sd */
-                            NULL,                      /* ea_list */
-                            &fsp,                      /* result */
-                            &smb_action,               /* pinfo */
-                            &sbuf);                    /* psbuf */
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               access_mask,                            /* access_mask */
+               share_mode,                             /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               smb_attr,                               /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &fsp,                                   /* result */
+               &smb_action,                            /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                END_PROFILE(SMBopenX);
@@ -1972,22 +1974,23 @@ void reply_mknew(struct smb_request *req)
                create_disposition = FILE_OVERWRITE_IF;
        }
 
-       status = create_file(conn,                      /* conn */
-                            req,                       /* req */
-                            0,                         /* root_dir_fid */
-                            fname,                     /* fname */
-                            access_mask,               /* access_mask */
-                            share_mode,                /* share_access */
-                            create_disposition,        /* create_disposition*/
-                            create_options,            /* create_options */
-                            fattr,                     /* file_attributes */
-                            oplock_request,            /* oplock_request */
-                            0,                         /* allocation_size */
-                            NULL,                      /* sd */
-                            NULL,                      /* ea_list */
-                            &fsp,                      /* result */
-                            NULL,                      /* pinfo */
-                            &sbuf);                    /* psbuf */
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               access_mask,                            /* access_mask */
+               share_mode,                             /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               fattr,                                  /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &fsp,                                   /* result */
+               NULL,                                   /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                END_PROFILE(SMBcreate);
index 7b051d389f98cd76f8c2159ddc281e79c2528297..4669e883fdc422923743a9118d1df2ae58f33234 100644 (file)
@@ -1006,22 +1006,23 @@ static void call_trans2open(connection_struct *conn,
                return;
        }
 
-       status = create_file(conn,                      /* conn */
-                            req,                       /* req */
-                            0,                         /* root_dir_fid */
-                            fname,                     /* fname */
-                            access_mask,               /* access_mask */
-                            share_mode,                /* share_access */
-                            create_disposition,        /* create_disposition*/
-                            create_options,            /* create_options */
-                            open_attr,                 /* file_attributes */
-                            oplock_request,            /* oplock_request */
-                            open_size,                 /* allocation_size */
-                            NULL,                      /* sd */
-                            ea_list,                   /* ea_list */
-                            &fsp,                      /* result */
-                            &smb_action,               /* pinfo */
-                            &sbuf);                    /* psbuf */
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               access_mask,                            /* access_mask */
+               share_mode,                             /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               open_attr,                              /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               open_size,                              /* allocation_size */
+               NULL,                                   /* sd */
+               ea_list,                                /* ea_list */
+               &fsp,                                   /* result */
+               &smb_action,                            /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {