vfs: remove dirfsp arg from SMB_VFS_CREATE_FILE()
[bbaumbach/samba-autobuild/.git] / source3 / modules / vfs_time_audit.c
index e2236f16af04dde8958238a03e19cd0d9bdbd014..c6b0130bb93889fab5fa7ec97b7018690da20454 100644 (file)
@@ -323,6 +323,60 @@ static NTSTATUS smb_time_audit_get_dfs_referrals(
        return result;
 }
 
+static NTSTATUS smb_time_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       const struct referral *reflist,
+                       size_t referral_count)
+{
+       NTSTATUS result;
+       struct timespec ts1,ts2;
+       double timediff;
+
+       clock_gettime_mono(&ts1);
+       result = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
+                       dirfsp,
+                       smb_fname,
+                       reflist,
+                       referral_count);
+       clock_gettime_mono(&ts2);
+       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
+
+       if (timediff > audit_timeout) {
+               smb_time_audit_log("get_dfs_referrals", timediff);
+       }
+
+       return result;
+}
+
+static NTSTATUS smb_time_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
+                       TALLOC_CTX *mem_ctx,
+                       struct files_struct *dirfsp,
+                       struct smb_filename *smb_fname,
+                       struct referral **ppreflist,
+                       size_t *preferral_count)
+{
+       NTSTATUS result;
+       struct timespec ts1,ts2;
+       double timediff;
+
+       clock_gettime_mono(&ts1);
+       result = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
+                       mem_ctx,
+                       dirfsp,
+                       smb_fname,
+                       ppreflist,
+                       preferral_count);
+       clock_gettime_mono(&ts2);
+       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
+
+       if (timediff > audit_timeout) {
+               smb_time_audit_log("read_dfs_pathat", timediff);
+       }
+
+       return result;
+}
+
 static NTSTATUS smb_time_audit_snap_check_path(struct vfs_handle_struct *handle,
                                               TALLOC_CTX *mem_ctx,
                                               const char *service_path,
@@ -392,26 +446,6 @@ static NTSTATUS smb_time_audit_snap_delete(struct vfs_handle_struct *handle,
        return status;
 }
 
-static DIR *smb_time_audit_opendir(vfs_handle_struct *handle,
-                                  const struct smb_filename *smb_fname,
-                                  const char *mask, uint32_t attr)
-{
-       DIR *result;
-       struct timespec ts1,ts2;
-       double timediff;
-
-       clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
-       clock_gettime_mono(&ts2);
-       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
-
-       if (timediff > audit_timeout) {
-               smb_time_audit_log_smb_fname("opendir", timediff, smb_fname);
-       }
-
-       return result;
-}
-
 static DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
                                              files_struct *fsp,
                                              const char *mask, uint32_t attr)
@@ -505,7 +539,8 @@ static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
 
 }
 
-static int smb_time_audit_mkdir(vfs_handle_struct *handle,
+static int smb_time_audit_mkdirat(vfs_handle_struct *handle,
+                               struct files_struct *dirfsp,
                                const struct smb_filename *smb_fname,
                                mode_t mode)
 {
@@ -514,33 +549,15 @@ static int smb_time_audit_mkdir(vfs_handle_struct *handle,
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
-       clock_gettime_mono(&ts2);
-       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
-
-       if (timediff > audit_timeout) {
-               smb_time_audit_log_smb_fname("mkdir",
-                       timediff,
-                       smb_fname);
-       }
-
-       return result;
-}
-
-static int smb_time_audit_rmdir(vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname)
-{
-       int result;
-       struct timespec ts1,ts2;
-       double timediff;
-
-       clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
+       result = SMB_VFS_NEXT_MKDIRAT(handle,
+                               dirfsp,
+                               smb_fname,
+                               mode);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_smb_fname("rmdir",
+               smb_time_audit_log_smb_fname("mkdirat",
                        timediff,
                        smb_fname);
        }
@@ -567,22 +584,29 @@ static int smb_time_audit_closedir(vfs_handle_struct *handle,
        return result;
 }
 
-static int smb_time_audit_open(vfs_handle_struct *handle,
-                              struct smb_filename *fname,
-                              files_struct *fsp,
-                              int flags, mode_t mode)
+static int smb_time_audit_openat(vfs_handle_struct *handle,
+                                const struct files_struct *dirfsp,
+                                const struct smb_filename *smb_fname,
+                                struct files_struct *fsp,
+                                int flags,
+                                mode_t mode)
 {
        int result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+       result = SMB_VFS_NEXT_OPENAT(handle,
+                                    dirfsp,
+                                    smb_fname,
+                                    fsp,
+                                    flags,
+                                    mode);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fsp("open", timediff, fsp);
+               smb_time_audit_log_fsp("openat", timediff, fsp);
        }
 
        return result;
@@ -590,7 +614,6 @@ static int smb_time_audit_open(vfs_handle_struct *handle,
 
 static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
                                           struct smb_request *req,
-                                          uint16_t root_dir_fid,
                                           struct smb_filename *fname,
                                           uint32_t access_mask,
                                           uint32_t share_access,
@@ -616,7 +639,6 @@ static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
        result = SMB_VFS_NEXT_CREATE_FILE(
                handle,                                 /* handle */
                req,                                    /* req */
-               root_dir_fid,                           /* root_dir_fid */
                fname,                                  /* fname */
                access_mask,                            /* access_mask */
                share_access,                           /* share_access */
@@ -1061,20 +1083,25 @@ static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
        return result;
 }
 
-static int smb_time_audit_unlink(vfs_handle_struct *handle,
-                                const struct smb_filename *path)
+static int smb_time_audit_unlinkat(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *path,
+                       int flags)
 {
        int result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_UNLINK(handle, path);
+       result = SMB_VFS_NEXT_UNLINKAT(handle,
+                               dirfsp,
+                               path,
+                               flags);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_smb_fname("unlink", timediff, path);
+               smb_time_audit_log_smb_fname("unlinkat", timediff, path);
        }
 
        return result;
@@ -1121,29 +1148,6 @@ static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
        return result;
 }
 
-static int smb_time_audit_chown(vfs_handle_struct *handle,
-                       const struct smb_filename *smb_fname,
-                       uid_t uid,
-                       gid_t gid)
-{
-       int result;
-       struct timespec ts1,ts2;
-       double timediff;
-
-       clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
-       clock_gettime_mono(&ts2);
-       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
-
-       if (timediff > audit_timeout) {
-               smb_time_audit_log_fname("chown",
-                       timediff,
-                       smb_fname->base_name);
-       }
-
-       return result;
-}
-
 static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
                                 uid_t uid, gid_t gid)
 {
@@ -1316,14 +1320,15 @@ static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
 
 static int smb_time_audit_kernel_flock(struct vfs_handle_struct *handle,
                                       struct files_struct *fsp,
-                                      uint32_t share_mode, uint32_t access_mask)
+                                      uint32_t share_access,
+                                      uint32_t access_mask)
 {
        int result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode,
+       result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_access,
                                           access_mask);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
@@ -1335,71 +1340,75 @@ static int smb_time_audit_kernel_flock(struct vfs_handle_struct *handle,
        return result;
 }
 
-static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
-                                        files_struct *fsp,
-                                        int leasetype)
+static int smb_time_audit_fcntl(struct vfs_handle_struct *handle,
+                               struct files_struct *fsp,
+                               int cmd, va_list cmd_arg)
 {
+       void *arg;
+       va_list dup_cmd_arg;
        int result;
        struct timespec ts1,ts2;
        double timediff;
 
+       va_copy(dup_cmd_arg, cmd_arg);
+       arg = va_arg(dup_cmd_arg, void *);
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
+       result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
        clock_gettime_mono(&ts2);
-       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
+       va_end(dup_cmd_arg);
 
+       timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
+               smb_time_audit_log_fsp("kernel_flock", timediff, fsp);
        }
 
        return result;
 }
 
-static bool smb_time_audit_getlock(vfs_handle_struct *handle,
-                                  files_struct *fsp,
-                                  off_t *poffset, off_t *pcount,
-                                  int *ptype, pid_t *ppid)
+static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
+                                        files_struct *fsp,
+                                        int leasetype)
 {
-       bool result;
+       int result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
-                                     ppid);
+       result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fsp("getlock", timediff, fsp);
+               smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
        }
 
        return result;
 }
 
-static int smb_time_audit_symlink(vfs_handle_struct *handle,
-                               const char *link_contents,
-                               const struct smb_filename *new_smb_fname)
+static bool smb_time_audit_getlock(vfs_handle_struct *handle,
+                                  files_struct *fsp,
+                                  off_t *poffset, off_t *pcount,
+                                  int *ptype, pid_t *ppid)
 {
-       int result;
+       bool result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_SYMLINK(handle, link_contents, new_smb_fname);
+       result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
+                                     ppid);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fname("symlink", timediff,
-                       new_smb_fname->base_name);
+               smb_time_audit_log_fsp("getlock", timediff, fsp);
        }
 
        return result;
 }
 
 static int smb_time_audit_symlinkat(vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname)
 {
@@ -1612,7 +1621,7 @@ static NTSTATUS smb_time_audit_streaminfo(vfs_handle_struct *handle,
 }
 
 static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle,
-                                           const char *path,
+                                           const struct smb_filename *path,
                                            const char *name,
                                            TALLOC_CTX *mem_ctx,
                                            char **found_name)
@@ -1628,7 +1637,8 @@ static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle,
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fname("get_real_filename", timediff, path);
+               smb_time_audit_log_fname("get_real_filename",
+                                        timediff, path->base_name);
        }
 
        return result;
@@ -2234,19 +2244,24 @@ static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
        return result;
 }
 
-static NTSTATUS smb_time_audit_get_nt_acl(vfs_handle_struct *handle,
-                                         const struct smb_filename *smb_fname,
-                                         uint32_t security_info,
-                                         TALLOC_CTX *mem_ctx,
-                                         struct security_descriptor **ppdesc)
+static NTSTATUS smb_time_audit_get_nt_acl_at(vfs_handle_struct *handle,
+                               struct files_struct *dirfsp,
+                               const struct smb_filename *smb_fname,
+                               uint32_t security_info,
+                               TALLOC_CTX *mem_ctx,
+                               struct security_descriptor **ppdesc)
 {
        NTSTATUS result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
-                                        mem_ctx, ppdesc);
+       result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
+                                       dirfsp,
+                                       smb_fname,
+                                       security_info,
+                                       mem_ctx,
+                                       ppdesc);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
@@ -2837,16 +2852,16 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
        .statvfs_fn = smb_time_audit_statvfs,
        .fs_capabilities_fn = smb_time_audit_fs_capabilities,
        .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals,
-       .opendir_fn = smb_time_audit_opendir,
+       .create_dfs_pathat_fn = smb_time_audit_create_dfs_pathat,
+       .read_dfs_pathat_fn = smb_time_audit_read_dfs_pathat,
        .fdopendir_fn = smb_time_audit_fdopendir,
        .readdir_fn = smb_time_audit_readdir,
        .seekdir_fn = smb_time_audit_seekdir,
        .telldir_fn = smb_time_audit_telldir,
        .rewind_dir_fn = smb_time_audit_rewinddir,
-       .mkdir_fn = smb_time_audit_mkdir,
-       .rmdir_fn = smb_time_audit_rmdir,
+       .mkdirat_fn = smb_time_audit_mkdirat,
        .closedir_fn = smb_time_audit_closedir,
-       .open_fn = smb_time_audit_open,
+       .openat_fn = smb_time_audit_openat,
        .create_file_fn = smb_time_audit_create_file,
        .close_fn = smb_time_audit_close,
        .pread_fn = smb_time_audit_pread,
@@ -2865,10 +2880,9 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
        .fstat_fn = smb_time_audit_fstat,
        .lstat_fn = smb_time_audit_lstat,
        .get_alloc_size_fn = smb_time_audit_get_alloc_size,
-       .unlink_fn = smb_time_audit_unlink,
+       .unlinkat_fn = smb_time_audit_unlinkat,
        .chmod_fn = smb_time_audit_chmod,
        .fchmod_fn = smb_time_audit_fchmod,
-       .chown_fn = smb_time_audit_chown,
        .fchown_fn = smb_time_audit_fchown,
        .lchown_fn = smb_time_audit_lchown,
        .chdir_fn = smb_time_audit_chdir,
@@ -2878,9 +2892,9 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
        .fallocate_fn = smb_time_audit_fallocate,
        .lock_fn = smb_time_audit_lock,
        .kernel_flock_fn = smb_time_audit_kernel_flock,
+       .fcntl_fn = smb_time_audit_fcntl,
        .linux_setlease_fn = smb_time_audit_linux_setlease,
        .getlock_fn = smb_time_audit_getlock,
-       .symlink_fn = smb_time_audit_symlink,
        .symlinkat_fn = smb_time_audit_symlinkat,
        .readlinkat_fn = smb_time_audit_readlinkat,
        .linkat_fn = smb_time_audit_linkat,
@@ -2913,7 +2927,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
        .set_dos_attributes_fn = smb_time_set_dos_attributes,
        .fset_dos_attributes_fn = smb_time_fset_dos_attributes,
        .fget_nt_acl_fn = smb_time_audit_fget_nt_acl,
-       .get_nt_acl_fn = smb_time_audit_get_nt_acl,
+       .get_nt_acl_at_fn = smb_time_audit_get_nt_acl_at,
        .fset_nt_acl_fn = smb_time_audit_fset_nt_acl,
        .audit_file_fn = smb_time_audit_audit_file,
        .sys_acl_get_file_fn = smb_time_audit_sys_acl_get_file,