Remove redundant parameter fd from SMB_VFS_LSEEK().
[ira/wip.git] / source3 / modules / vfs_full_audit.c
index 3e99e52637769459a14dcbc6acd87ac3854512e4..b03f6b53f4811b893d2697f25f69c57508e58908 100644 (file)
@@ -78,7 +78,7 @@ static int smb_full_audit_connect(vfs_handle_struct *handle,
 static void smb_full_audit_disconnect(vfs_handle_struct *handle);
 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
                                    const char *path,
-                                   BOOL small_query, SMB_BIG_UINT *bsize, 
+                                   bool small_query, SMB_BIG_UINT *bsize, 
                                    SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
                           enum SMB_QUOTA_TYPE qtype, unid_t id,
@@ -88,7 +88,7 @@ static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
                           SMB_DISK_QUOTA *qt);
 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
                                 struct files_struct *fsp,
-                                SHADOW_COPY_DATA *shadow_copy_data, BOOL labels);
+                                SHADOW_COPY_DATA *shadow_copy_data, bool labels);
 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
                                const char *path,
                                struct vfs_statvfs_struct *statbuf);
@@ -115,18 +115,22 @@ static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp, in
 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
                          int fd, void *data, size_t n);
 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
-                          int fd, void *data, size_t n, SMB_OFF_T offset);
+                          void *data, size_t n, SMB_OFF_T offset);
 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
                           int fd, const void *data, size_t n);
 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
-                           int fd, const void *data, size_t n,
+                           const void *data, size_t n,
                            SMB_OFF_T offset);
 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
-                            int filedes, SMB_OFF_T offset, int whence);
+                            SMB_OFF_T offset, int whence);
 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
                              files_struct *fsp, int fromfd,
                              const DATA_BLOB *hdr, SMB_OFF_T offset,
                              size_t n);
+static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
+                             files_struct *fsp, int tofd,
+                             SMB_OFF_T offset,
+                             size_t n);
 static int smb_full_audit_rename(vfs_handle_struct *handle,
                        const char *oldname, const char *newname);
 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp, int fd);
@@ -156,14 +160,14 @@ static int smb_full_audit_ntimes(vfs_handle_struct *handle,
                       const char *path, const struct timespec ts[2]);
 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
                           int fd, SMB_OFF_T len);
-static BOOL smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int fd,
+static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int fd,
                       int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
                                       struct files_struct *fsp, int fd,
                                       uint32 share_mode);
 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
                                        int fd, int leasetype);
-static BOOL smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd,
+static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd,
                       SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid);
 static int smb_full_audit_symlink(vfs_handle_struct *handle,
                         const char *oldpath, const char *newpath);
@@ -183,17 +187,17 @@ static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
                                        struct notify_event *ev),
                        void *private_data, void *handle_p);
 static int smb_full_audit_chflags(vfs_handle_struct *handle,
-                           const char *path, uint flags);
+                           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);
-static size_t smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
-                               int fd, uint32 security_info,
+static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
+                               uint32 security_info,
                                SEC_DESC **ppdesc);
-static size_t smb_full_audit_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
+static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                               const char *name, uint32 security_info,
                               SEC_DESC **ppdesc);
 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
-                             int fd, uint32 security_info_sent,
+                             uint32 security_info_sent,
                              SEC_DESC *psd);
 static NTSTATUS smb_full_audit_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                             const char *name, uint32 security_info_sent,
@@ -363,6 +367,8 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_sendfile),   SMB_VFS_OP_SENDFILE,
         SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_recvfile),   SMB_VFS_OP_RECVFILE,
+        SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_rename),     SMB_VFS_OP_RENAME,
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_fsync),      SMB_VFS_OP_FSYNC,
@@ -675,21 +681,25 @@ static int audit_syslog_priority(vfs_handle_struct *handle)
        return priority;
 }
 
-static char *audit_prefix(connection_struct *conn)
+static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
 {
-       static pstring prefix;
+       char *prefix = NULL;
 
-       pstrcpy(prefix, lp_parm_const_string(SNUM(conn), "full_audit",
+       prefix = talloc_strdup(ctx,
+                       lp_parm_const_string(SNUM(conn), "full_audit",
                                             "prefix", "%u|%I"));
-       standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
-                             conn->connectpath, conn->gid,
-                             get_current_username(),
-                             current_user_info.domain,
-                             prefix, sizeof(prefix));
-       return prefix;
+       if (!prefix) {
+               return NULL;
+       }
+       return talloc_sub_advanced(ctx,
+                       lp_servicename(SNUM(conn)), conn->user,
+                       conn->connectpath, conn->gid,
+                       get_current_username(),
+                       current_user_info.domain,
+                       prefix);
 }
 
-static BOOL log_success(vfs_handle_struct *handle, vfs_op_type op)
+static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
 {
        struct vfs_full_audit_private_data *pd = NULL;
 
@@ -704,7 +714,7 @@ static BOOL log_success(vfs_handle_struct *handle, vfs_op_type op)
        return bitmap_query(pd->success_ops, op);
 }
 
-static BOOL log_failure(vfs_handle_struct *handle, vfs_op_type op)
+static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
 {
        struct vfs_full_audit_private_data *pd = NULL;
 
@@ -720,7 +730,7 @@ static BOOL log_failure(vfs_handle_struct *handle, vfs_op_type op)
 
 static void init_bitmap(struct bitmap **bm, const char **ops)
 {
-       BOOL log_all = False;
+       bool log_all = False;
 
        if (*bm != NULL)
                return;
@@ -735,7 +745,7 @@ static void init_bitmap(struct bitmap **bm, const char **ops)
 
        while (*ops != NULL) {
                int i;
-               BOOL found = False;
+               bool found = False;
 
                if (strequal(*ops, "all")) {
                        log_all = True;
@@ -780,12 +790,13 @@ static const char *audit_opname(vfs_op_type op)
        return vfs_op_names[op].name;
 }
 
-static void do_log(vfs_op_type op, BOOL success, vfs_handle_struct *handle,
+static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
                   const char *format, ...)
 {
        fstring err_msg;
-       pstring op_msg;
+       char *audit_pre = NULL;
        va_list ap;
+       char *op_msg = NULL;
 
        if (success && (!log_success(handle, op)))
                return;
@@ -799,11 +810,20 @@ static void do_log(vfs_op_type op, BOOL success, vfs_handle_struct *handle,
                fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
 
        va_start(ap, format);
-       vsnprintf(op_msg, sizeof(op_msg), format, ap);
+       op_msg = talloc_vasprintf(NULL, format, ap);
        va_end(ap);
 
+       if (!op_msg) {
+               return;
+       }
+
+       audit_pre = audit_prefix(NULL, handle->conn);
        syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
-              audit_prefix(handle->conn), audit_opname(op), err_msg, op_msg);
+               audit_pre ? audit_pre : "",
+               audit_opname(op), err_msg, op_msg);
+
+       TALLOC_FREE(audit_pre);
+       TALLOC_FREE(op_msg);
 
        return;
 }
@@ -881,7 +901,7 @@ static void smb_full_audit_disconnect(vfs_handle_struct *handle)
 
 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
                                    const char *path,
-                                   BOOL small_query, SMB_BIG_UINT *bsize, 
+                                   bool small_query, SMB_BIG_UINT *bsize, 
                                    SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
        SMB_BIG_UINT result;
@@ -925,7 +945,7 @@ static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
 
 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
                                struct files_struct *fsp,
-                               SHADOW_COPY_DATA *shadow_copy_data, BOOL labels)
+                               SHADOW_COPY_DATA *shadow_copy_data, bool labels)
 {
        int result;
 
@@ -1080,11 +1100,11 @@ static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
 }
 
 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
-                          int fd, void *data, size_t n, SMB_OFF_T offset)
+                          void *data, size_t n, SMB_OFF_T offset)
 {
        ssize_t result;
 
-       result = SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, n, offset);
+       result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
 
        do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
 
@@ -1104,12 +1124,12 @@ static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp
 }
 
 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
-                           int fd, const void *data, size_t n,
+                           const void *data, size_t n,
                            SMB_OFF_T offset)
 {
        ssize_t result;
 
-       result = SMB_VFS_NEXT_PWRITE(handle, fsp, fd, data, n, offset);
+       result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
 
        do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
 
@@ -1117,11 +1137,11 @@ static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fs
 }
 
 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
-                            int filedes, SMB_OFF_T offset, int whence)
+                            SMB_OFF_T offset, int whence)
 {
        ssize_t result;
 
-       result = SMB_VFS_NEXT_LSEEK(handle, fsp, filedes, offset, whence);
+       result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
 
        do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
               "%s", fsp->fsp_name);
@@ -1145,6 +1165,22 @@ static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
        return result;
 }
 
+static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
+                             files_struct *fsp, int tofd,
+                             SMB_OFF_T offset,
+                             size_t n)
+{
+       ssize_t result;
+
+       result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, fsp, tofd,
+                                      offset, n);
+
+       do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
+              "%s", fsp->fsp_name);
+
+       return result;
+}
+
 static int smb_full_audit_rename(vfs_handle_struct *handle,
                        const char *oldname, const char *newname)
 {
@@ -1329,14 +1365,14 @@ static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp
        return result;
 }
 
-static BOOL smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int fd,
+static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int fd,
                       int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
 {
-       BOOL result;
+       bool result;
 
        result = SMB_VFS_NEXT_LOCK(handle, fsp, fd, op, offset, count, type);
 
-       do_log(SMB_VFS_OP_LOCK, (result >= 0), handle, "%s", fsp->fsp_name);
+       do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
 
        return result;
 }
@@ -1368,14 +1404,14 @@ static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct
         return result;
 }
 
-static BOOL smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd,
+static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd,
                       SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
 {
-       BOOL result;
+       bool result;
 
        result = SMB_VFS_NEXT_GETLOCK(handle, fsp, fd, poffset, pcount, ptype, ppid);
 
-       do_log(SMB_VFS_OP_GETLOCK, (result >= 0), handle, "%s", fsp->fsp_name);
+       do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
 
        return result;
 }
@@ -1460,7 +1496,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, uint flags)
+                           const char *path, unsigned int flags)
 {
        int result;
 
@@ -1488,44 +1524,43 @@ static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *ha
        return result;
 }
 
-static size_t smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
-                               int fd, uint32 security_info,
+static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
+                               uint32 security_info,
                                SEC_DESC **ppdesc)
 {
-       size_t result;
+       NTSTATUS result;
 
-       result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, fd, security_info,
-                                         ppdesc);
+       result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
 
-       do_log(SMB_VFS_OP_FGET_NT_ACL, (result > 0), handle,
+       do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
               "%s", fsp->fsp_name);
 
        return result;
 }
 
-static size_t smb_full_audit_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
-                              const char *name, uint32 security_info,
-                              SEC_DESC **ppdesc)
+static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
+                                         files_struct *fsp,
+                                         const char *name,
+                                         uint32 security_info,
+                                         SEC_DESC **ppdesc)
 {
-       size_t result;
+       NTSTATUS result;
 
-       result = SMB_VFS_NEXT_GET_NT_ACL(handle, fsp, name, security_info,
-                                        ppdesc);
+       result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
 
-       do_log(SMB_VFS_OP_GET_NT_ACL, (result > 0), handle,
+       do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
               "%s", fsp->fsp_name);
 
        return result;
 }
 
 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
-                             int fd, uint32 security_info_sent,
+                             uint32 security_info_sent,
                              SEC_DESC *psd)
 {
        NTSTATUS result;
 
-       result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, fd, security_info_sent,
-                                         psd);
+       result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
 
        do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);