s3: Modify SMB_VFS_FILE_ID_CREATE to take a stat struct
[jra/samba/.git] / source3 / modules / vfs_full_audit.c
index e279772494d752dc1e445d21f515fcc89984a3a0..3c159f10eb1ec1369873fe493134ad155e8a382d 100644 (file)
@@ -90,7 +90,7 @@ static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
                                const char *path,
                                struct vfs_statvfs_struct *statbuf);
-
+static int smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle);
 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
                          const char *fname, const char *mask, uint32 attr);
 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
@@ -108,6 +108,8 @@ static int smb_full_audit_rmdir(vfs_handle_struct *handle,
                       const char *path);
 static int smb_full_audit_closedir(vfs_handle_struct *handle,
                          SMB_STRUCT_DIR *dirp);
+static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
+                       SMB_STRUCT_DIR *dirp);
 static int smb_full_audit_open(vfs_handle_struct *handle,
                      const char *fname, files_struct *fsp, int flags, mode_t mode);
 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
@@ -207,7 +209,7 @@ static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
 static int smb_full_audit_chflags(vfs_handle_struct *handle,
                            const char *path, unsigned int flags);
 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
-                                                   SMB_DEV_T dev, SMB_INO_T inode);
+                                                   const SMB_STRUCT_STAT *sbuf);
 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
                                          struct files_struct *fsp,
                                          const char *fname,
@@ -219,6 +221,19 @@ static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
                                            const char *name,
                                            TALLOC_CTX *mem_ctx,
                                            char **found_name);
+static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
+                                               struct byte_range_lock *br_lck,
+                                               struct lock_struct *plock,
+                                               bool blocking_lock,
+                                               struct blocking_lock_record *blr);
+static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
+                                             struct messaging_context *msg_ctx,
+                                             struct byte_range_lock *br_lck,
+                                             const struct lock_struct *plock);
+static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
+                                             struct byte_range_lock *br_lck,
+                                             struct lock_struct *plock,
+                                             struct blocking_lock_record *blr);
 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                                uint32 security_info,
                                SEC_DESC **ppdesc);
@@ -333,11 +348,13 @@ static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct fi
 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb);
 static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts);
+static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
+                                    struct files_struct *fsp);
 
 /* VFS operations */
 
 static vfs_op_tuple audit_op_tuples[] = {
-    
+
        /* Disk operations */
 
        {SMB_VFS_OP(smb_full_audit_connect),    SMB_VFS_OP_CONNECT,
@@ -354,6 +371,8 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_statvfs),    SMB_VFS_OP_STATVFS,
         SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
+        SMB_VFS_LAYER_LOGGER},
 
        /* Directory operations */
 
@@ -373,6 +392,8 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_closedir),   SMB_VFS_OP_CLOSEDIR,
         SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_init_search_op), SMB_VFS_OP_INIT_SEARCH_OP,
+        SMB_VFS_LAYER_LOGGER},
 
        /* File operations */
 
@@ -456,6 +477,12 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_get_real_filename), SMB_VFS_OP_GET_REAL_FILENAME,
         SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_brl_lock_windows), SMB_VFS_OP_BRL_LOCK_WINDOWS,
+        SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_brl_unlock_windows), SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
+        SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_brl_cancel_windows), SMB_VFS_OP_BRL_CANCEL_WINDOWS,
+        SMB_VFS_LAYER_LOGGER},
 
        /* NT ACL operations. */
 
@@ -516,7 +543,7 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_sys_acl_free_qualifier),     SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
         SMB_VFS_LAYER_LOGGER},
-       
+
        /* EA operations. */
 
        {SMB_VFS_OP(smb_full_audit_getxattr),   SMB_VFS_OP_GETXATTR,
@@ -543,7 +570,7 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_fsetxattr),  SMB_VFS_OP_FSETXATTR,
         SMB_VFS_LAYER_LOGGER},
-       
+
        {SMB_VFS_OP(smb_full_audit_aio_read),   SMB_VFS_OP_AIO_READ,
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_aio_write),  SMB_VFS_OP_AIO_WRITE,
@@ -558,9 +585,11 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
         SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_aio_force),SMB_VFS_OP_AIO_FORCE,
+        SMB_VFS_LAYER_LOGGER},
 
        /* Finish VFS operations definition */
-       
+
        {SMB_VFS_OP(NULL),              SMB_VFS_OP_NOOP,
         SMB_VFS_LAYER_NOOP}
 };
@@ -587,6 +616,7 @@ static struct {
        { SMB_VFS_OP_MKDIR,     "mkdir" },
        { SMB_VFS_OP_RMDIR,     "rmdir" },
        { SMB_VFS_OP_CLOSEDIR,  "closedir" },
+       { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
        { SMB_VFS_OP_OPEN,      "open" },
        { SMB_VFS_OP_CREATE_FILE, "create_file" },
        { SMB_VFS_OP_CLOSE,     "close" },
@@ -627,6 +657,9 @@ static struct {
        { SMB_VFS_OP_FILE_ID_CREATE,    "file_id_create" },
        { SMB_VFS_OP_STREAMINFO,        "streaminfo" },
        { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
+       { SMB_VFS_OP_BRL_LOCK_WINDOWS,  "brl_lock_windows" },
+       { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
+       { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
        { SMB_VFS_OP_FGET_NT_ACL,       "fget_nt_acl" },
        { SMB_VFS_OP_GET_NT_ACL,        "get_nt_acl" },
        { SMB_VFS_OP_FSET_NT_ACL,       "fset_nt_acl" },
@@ -677,7 +710,7 @@ static struct {
        { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
        { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
        { SMB_VFS_OP_LAST, NULL }
-};     
+};
 
 static int audit_syslog_facility(vfs_handle_struct *handle)
 {
@@ -1017,6 +1050,17 @@ static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
        return result;
 }
 
+static int smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle)
+{
+       int result;
+
+       result = SMB_VFS_NEXT_FS_CAPABILITIES(handle);
+
+       do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
+
+       return result;
+}
+
 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
                          const char *fname, const char *mask, uint32 attr)
 {
@@ -1110,6 +1154,15 @@ static int smb_full_audit_closedir(vfs_handle_struct *handle,
        return result;
 }
 
+static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
+                       SMB_STRUCT_DIR *dirp)
+{
+       SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
+
+       do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
+       return;
+}
+
 static int smb_full_audit_open(vfs_handle_struct *handle,
                      const char *fname, files_struct *fsp, int flags, mode_t mode)
 {
@@ -1611,14 +1664,14 @@ static int smb_full_audit_chflags(vfs_handle_struct *handle,
 }
 
 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
-                                                   SMB_DEV_T dev, SMB_INO_T inode)
+                                                   const SMB_STRUCT_STAT *sbuf)
 {
        struct file_id id_zero;
        struct file_id result;
 
        ZERO_STRUCT(id_zero);
 
-       result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
+       result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
 
        do_log(SMB_VFS_OP_FILE_ID_CREATE,
               !file_id_equal(&id_zero, &result),
@@ -1662,6 +1715,57 @@ static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
        return result;
 }
 
+static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
+                                               struct byte_range_lock *br_lck,
+                                               struct lock_struct *plock,
+                                               bool blocking_lock,
+                                               struct blocking_lock_record *blr)
+{
+       NTSTATUS result;
+
+       result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
+           blocking_lock, blr);
+
+       do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
+           "%s:%llu-%llu. type=%d. blocking=%d", br_lck->fsp->fsp_name,
+           plock->start, plock->size, plock->lock_type, blocking_lock );
+
+       return result;
+}
+
+static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
+                                             struct messaging_context *msg_ctx,
+                                             struct byte_range_lock *br_lck,
+                                             const struct lock_struct *plock)
+{
+       bool result;
+
+       result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
+           plock);
+
+       do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
+           "%s:%llu-%llu:%d", br_lck->fsp->fsp_name, plock->start,
+           plock->size, plock->lock_type);
+
+       return result;
+}
+
+static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
+                                             struct byte_range_lock *br_lck,
+                                             struct lock_struct *plock,
+                                             struct blocking_lock_record *blr)
+{
+       bool result;
+
+       result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
+
+       do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
+           "%s:%llu-%llu:%d", br_lck->fsp->fsp_name, plock->start,
+           plock->size);
+
+       return result;
+}
+
 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                                uint32 security_info,
                                SEC_DESC **ppdesc)
@@ -2296,6 +2400,17 @@ static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct f
        return result;
 }
 
+static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
+                                    struct files_struct *fsp)
+{
+       bool result;
+
+       result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
+       do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
+               "%s", fsp->fsp_name);
+
+       return result;
+}
 
 NTSTATUS vfs_full_audit_init(void);
 NTSTATUS vfs_full_audit_init(void)