s3: vfs: add SMB_VFS_GETXATTRAT_SEND/RECV
[kamenim/samba-autobuild/.git] / source3 / modules / vfs_time_audit.c
index e85ded5e4c360aa5d579a21ead117b939c731d31..07c14415312fb6a13d89b36dcad0448046b82047 100644 (file)
@@ -86,6 +86,23 @@ static void smb_time_audit_log_fsp(const char *syscallname, double elapsed,
        TALLOC_FREE(msg);
 }
 
+static void smb_time_audit_log_at(const char *syscallname,
+                                 double elapsed,
+                                 const struct files_struct *dir_fsp,
+                                 const struct smb_filename *smb_fname)
+{
+       char *msg = NULL;
+
+       msg = talloc_asprintf(talloc_tos(),
+                             "filename = \"%s/%s/%s\"",
+                             dir_fsp->conn->connectpath,
+                             dir_fsp->fsp_name->base_name,
+                             smb_fname->base_name);
+
+       smb_time_audit_log_msg(syscallname, elapsed, msg);
+       TALLOC_FREE(msg);
+}
+
 static void smb_time_audit_log_fname(const char *syscallname, double elapsed,
                                    const char *fname)
 {
@@ -2334,6 +2351,111 @@ static ssize_t smb_time_audit_getxattr(struct vfs_handle_struct *handle,
        return result;
 }
 
+struct smb_time_audit_getxattrat_state {
+       struct vfs_aio_state aio_state;
+       files_struct *dir_fsp;
+       const struct smb_filename *smb_fname;
+       const char *xattr_name;
+       ssize_t xattr_size;
+       uint8_t *xattr_value;
+};
+
+static void smb_time_audit_getxattrat_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_time_audit_getxattrat_send(
+                       TALLOC_CTX *mem_ctx,
+                       const struct smb_vfs_ev_glue *evg,
+                       struct vfs_handle_struct *handle,
+                       files_struct *dir_fsp,
+                       const struct smb_filename *smb_fname,
+                       const char *xattr_name,
+                       size_t alloc_hint)
+{
+       struct tevent_context *ev = smb_vfs_ev_glue_ev_ctx(evg);
+       struct tevent_req *req = NULL;
+       struct tevent_req *subreq = NULL;
+       struct smb_time_audit_getxattrat_state *state = NULL;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct smb_time_audit_getxattrat_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       *state = (struct smb_time_audit_getxattrat_state) {
+               .dir_fsp = dir_fsp,
+               .smb_fname = smb_fname,
+               .xattr_name = xattr_name,
+       };
+
+       subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
+                                             evg,
+                                             handle,
+                                             dir_fsp,
+                                             smb_fname,
+                                             xattr_name,
+                                             alloc_hint);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, smb_time_audit_getxattrat_done, req);
+
+       return req;
+}
+
+static void smb_time_audit_getxattrat_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct smb_time_audit_getxattrat_state *state = tevent_req_data(
+               req, struct smb_time_audit_getxattrat_state);
+
+       state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
+                                                        &state->aio_state,
+                                                        state,
+                                                        &state->xattr_value);
+       TALLOC_FREE(subreq);
+       if (state->xattr_size == -1) {
+               tevent_req_error(req, state->aio_state.error);
+               return;
+       }
+
+       tevent_req_done(req);
+}
+
+static ssize_t smb_time_audit_getxattrat_recv(struct tevent_req *req,
+                                             struct vfs_aio_state *aio_state,
+                                             TALLOC_CTX *mem_ctx,
+                                             uint8_t **xattr_value)
+{
+       struct smb_time_audit_getxattrat_state *state = tevent_req_data(
+               req, struct smb_time_audit_getxattrat_state);
+       ssize_t xattr_size;
+       double timediff;
+
+       timediff = state->aio_state.duration * 1.0e-9;
+
+       if (timediff > audit_timeout) {
+               smb_time_audit_log_at("async getxattrat",
+                                     timediff,
+                                     state->dir_fsp,
+                                     state->smb_fname);
+       }
+
+       if (tevent_req_is_unix_error(req, &aio_state->error)) {
+               tevent_req_received(req);
+               return -1;
+       }
+
+       *aio_state = state->aio_state;
+       xattr_size = state->xattr_size;
+       if (xattr_value != NULL) {
+               *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
+       }
+
+       tevent_req_received(req);
+       return xattr_size;
+}
+
 static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
                                        struct files_struct *fsp,
                                        const char *name, void *value,
@@ -2667,6 +2789,8 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
        .sys_acl_set_fd_fn = smb_time_audit_sys_acl_set_fd,
        .sys_acl_delete_def_file_fn = smb_time_audit_sys_acl_delete_def_file,
        .getxattr_fn = smb_time_audit_getxattr,
+       .getxattrat_send_fn = smb_time_audit_getxattrat_send,
+       .getxattrat_recv_fn = smb_time_audit_getxattrat_recv,
        .fgetxattr_fn = smb_time_audit_fgetxattr,
        .listxattr_fn = smb_time_audit_listxattr,
        .flistxattr_fn = smb_time_audit_flistxattr,