summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/VFS/skel_opaque.c18
-rw-r--r--examples/VFS/skel_transparent.c56
-rw-r--r--source3/modules/vfs_full_audit.c75
-rw-r--r--source3/modules/vfs_time_audit.c67
4 files changed, 216 insertions, 0 deletions
diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 56f3b977ac..cf262b661a 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -215,6 +215,22 @@ static ssize_t skel_pwrite(vfs_handle_struct *handle, files_struct *fsp, const v
return -1;
}
+static struct tevent_req *skel_pwrite_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *fsp,
+ const void *data,
+ size_t n, off_t offset)
+{
+ return NULL;
+}
+
+static ssize_t skel_pwrite_recv(struct tevent_req *req, int *err)
+{
+ *err = ENOSYS;
+ return -1;
+}
+
static off_t skel_lseek(vfs_handle_struct *handle, files_struct *fsp, off_t offset, int whence)
{
errno = ENOSYS;
@@ -824,6 +840,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
.pread_recv_fn = skel_pread_recv,
.write_fn = skel_write,
.pwrite_fn = skel_pwrite,
+ .pwrite_send_fn = skel_pwrite_send,
+ .pwrite_recv_fn = skel_pwrite_recv,
.lseek_fn = skel_lseek,
.sendfile_fn = skel_sendfile,
.recvfile_fn = skel_recvfile,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index 55149d7fd8..819f7b9c08 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -257,6 +257,60 @@ static ssize_t skel_pwrite(vfs_handle_struct *handle, files_struct *fsp, const v
return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
}
+struct skel_pwrite_state {
+ ssize_t ret;
+ int err;
+};
+
+static void skel_pwrite_done(struct tevent_req *subreq);
+
+static struct tevent_req *skel_pwrite_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *fsp,
+ const void *data,
+ size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct skel_pwrite_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct skel_pwrite_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
+ n, offset);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, skel_pwrite_done, req);
+ return req;
+}
+
+static void skel_pwrite_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct skel_pwrite_state *state = tevent_req_data(
+ req, struct skel_pwrite_state);
+
+ state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static ssize_t skel_pwrite_recv(struct tevent_req *req, int *err)
+{
+ struct skel_pwrite_state *state = tevent_req_data(
+ req, struct skel_pwrite_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static off_t skel_lseek(vfs_handle_struct *handle, files_struct *fsp, off_t offset, int whence)
{
return SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
@@ -823,6 +877,8 @@ struct vfs_fn_pointers skel_transparent_fns = {
.pread_recv_fn = skel_pread_recv,
.write_fn = skel_write,
.pwrite_fn = skel_pwrite,
+ .pwrite_send_fn = skel_pwrite_send,
+ .pwrite_recv_fn = skel_pwrite_recv,
.lseek_fn = skel_lseek,
.sendfile_fn = skel_sendfile,
.recvfile_fn = skel_recvfile,
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index a1b1f4ef38..6d621f57ae 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -116,6 +116,8 @@ typedef enum _vfs_op_type {
SMB_VFS_OP_PREAD_RECV,
SMB_VFS_OP_WRITE,
SMB_VFS_OP_PWRITE,
+ SMB_VFS_OP_PWRITE_SEND,
+ SMB_VFS_OP_PWRITE_RECV,
SMB_VFS_OP_LSEEK,
SMB_VFS_OP_SENDFILE,
SMB_VFS_OP_RECVFILE,
@@ -1066,6 +1068,77 @@ static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fs
return result;
}
+struct smb_full_audit_pwrite_state {
+ vfs_handle_struct *handle;
+ files_struct *fsp;
+ ssize_t ret;
+ int err;
+};
+
+static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_full_audit_pwrite_send(
+ struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev, struct files_struct *fsp,
+ const void *data, size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct smb_full_audit_pwrite_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct smb_full_audit_pwrite_state);
+ if (req == NULL) {
+ do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
+ fsp_str_do_log(fsp));
+ return NULL;
+ }
+ state->handle = handle;
+ state->fsp = fsp;
+
+ subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
+ n, offset);
+ if (tevent_req_nomem(subreq, req)) {
+ do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
+ fsp_str_do_log(fsp));
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
+
+ do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
+ fsp_str_do_log(fsp));
+ return req;
+}
+
+static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb_full_audit_pwrite_state *state = tevent_req_data(
+ req, struct smb_full_audit_pwrite_state);
+
+ state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
+{
+ struct smb_full_audit_pwrite_state *state = tevent_req_data(
+ req, struct smb_full_audit_pwrite_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
+ fsp_str_do_log(state->fsp));
+ return -1;
+ }
+
+ do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
+ fsp_str_do_log(state->fsp));
+
+ *err = state->err;
+ return state->ret;
+}
+
static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
off_t offset, int whence)
{
@@ -2282,6 +2355,8 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
.pread_recv_fn = smb_full_audit_pread_recv,
.write_fn = smb_full_audit_write,
.pwrite_fn = smb_full_audit_pwrite,
+ .pwrite_send_fn = smb_full_audit_pwrite_send,
+ .pwrite_recv_fn = smb_full_audit_pwrite_recv,
.lseek_fn = smb_full_audit_lseek,
.sendfile_fn = smb_full_audit_sendfile,
.recvfile_fn = smb_full_audit_recvfile,
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 140b856acb..a9b806a69a 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -626,6 +626,71 @@ static ssize_t smb_time_audit_pwrite(vfs_handle_struct *handle,
return result;
}
+struct smb_time_audit_pwrite_state {
+ struct timespec ts1;
+ ssize_t ret;
+ int err;
+};
+
+static void smb_time_audit_pwrite_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_time_audit_pwrite_send(
+ struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev, struct files_struct *fsp,
+ const void *data, size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct smb_time_audit_pwrite_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct smb_time_audit_pwrite_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ clock_gettime_mono(&state->ts1);
+
+ subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
+ n, offset);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smb_time_audit_pwrite_done, req);
+ return req;
+}
+
+static void smb_time_audit_pwrite_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb_time_audit_pwrite_state *state = tevent_req_data(
+ req, struct smb_time_audit_pwrite_state);
+
+ state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static ssize_t smb_time_audit_pwrite_recv(struct tevent_req *req, int *err)
+{
+ struct smb_time_audit_pwrite_state *state = tevent_req_data(
+ req, struct smb_time_audit_pwrite_state);
+ struct timespec ts2;
+ double timediff;
+
+ clock_gettime_mono(&ts2);
+ timediff = nsec_time_diff(&ts2,&state->ts1)*1.0e-9;
+
+ if (timediff > audit_timeout) {
+ smb_time_audit_log("pwrite", timediff);
+ }
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static off_t smb_time_audit_lseek(vfs_handle_struct *handle,
files_struct *fsp,
off_t offset, int whence)
@@ -2352,6 +2417,8 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
.pread_recv_fn = smb_time_audit_pread_recv,
.write_fn = smb_time_audit_write,
.pwrite_fn = smb_time_audit_pwrite,
+ .pwrite_send_fn = smb_time_audit_pwrite_send,
+ .pwrite_recv_fn = smb_time_audit_pwrite_recv,
.lseek_fn = smb_time_audit_lseek,
.sendfile_fn = smb_time_audit_sendfile,
.recvfile_fn = smb_time_audit_recvfile,