summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/VFS/skel_opaque.c17
-rw-r--r--examples/VFS/skel_transparent.c56
-rw-r--r--source3/modules/vfs_full_audit.c77
-rw-r--r--source3/modules/vfs_time_audit.c68
4 files changed, 218 insertions, 0 deletions
diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 89d69928eb..56f3b977ac 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -188,6 +188,21 @@ static ssize_t skel_pread(vfs_handle_struct *handle, files_struct *fsp, void *da
return -1;
}
+static struct tevent_req *skel_pread_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *fsp,
+ void *data, size_t n, off_t offset)
+{
+ return NULL;
+}
+
+static ssize_t skel_pread_recv(struct tevent_req *req, int *err)
+{
+ *err = ENOSYS;
+ return -1;
+}
+
static ssize_t skel_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
{
errno = ENOSYS;
@@ -805,6 +820,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
.close_fn = skel_close_fn,
.read_fn = skel_vfs_read,
.pread_fn = skel_pread,
+ .pread_send_fn = skel_pread_send,
+ .pread_recv_fn = skel_pread_recv,
.write_fn = skel_write,
.pwrite_fn = skel_pwrite,
.lseek_fn = skel_lseek,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index 8f55d6aa8a..55149d7fd8 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -23,6 +23,7 @@
#include "../source3/include/includes.h"
+#include "lib/util/tevent_unix.h"
/* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE
SAMBA DEVELOPERS GUIDE!!!!!!
@@ -193,6 +194,59 @@ static ssize_t skel_pread(vfs_handle_struct *handle, files_struct *fsp, void *da
return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
}
+struct skel_pread_state {
+ ssize_t ret;
+ int err;
+};
+
+static void skel_pread_done(struct tevent_req *subreq);
+
+static struct tevent_req *skel_pread_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *fsp,
+ void *data, size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct skel_pread_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct skel_pread_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ subreq = SMB_VFS_NEXT_PREAD_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_pread_done, req);
+ return req;
+}
+
+static void skel_pread_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct skel_pread_state *state = tevent_req_data(
+ req, struct skel_pread_state);
+
+ state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static ssize_t skel_pread_recv(struct tevent_req *req, int *err)
+{
+ struct skel_pread_state *state = tevent_req_data(
+ req, struct skel_pread_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static ssize_t skel_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
{
return SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
@@ -765,6 +819,8 @@ struct vfs_fn_pointers skel_transparent_fns = {
.close_fn = skel_close_fn,
.read_fn = skel_vfs_read,
.pread_fn = skel_pread,
+ .pread_send_fn = skel_pread_send,
+ .pread_recv_fn = skel_pread_recv,
.write_fn = skel_write,
.pwrite_fn = skel_pwrite,
.lseek_fn = skel_lseek,
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index b93df5090d..a1b1f4ef38 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -66,6 +66,7 @@
#include "ntioctl.h"
#include "lib/param/loadparm.h"
#include "lib/util/bitmap.h"
+#include "lib/util/tevent_unix.h"
static int vfs_full_audit_debug_level = DBGC_VFS;
@@ -111,6 +112,8 @@ typedef enum _vfs_op_type {
SMB_VFS_OP_CLOSE,
SMB_VFS_OP_READ,
SMB_VFS_OP_PREAD,
+ SMB_VFS_OP_PREAD_SEND,
+ SMB_VFS_OP_PREAD_RECV,
SMB_VFS_OP_WRITE,
SMB_VFS_OP_PWRITE,
SMB_VFS_OP_LSEEK,
@@ -247,6 +250,8 @@ static struct {
{ SMB_VFS_OP_CLOSE, "close" },
{ SMB_VFS_OP_READ, "read" },
{ SMB_VFS_OP_PREAD, "pread" },
+ { SMB_VFS_OP_PREAD_SEND, "pread_send" },
+ { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
{ SMB_VFS_OP_WRITE, "write" },
{ SMB_VFS_OP_PWRITE, "pwrite" },
{ SMB_VFS_OP_LSEEK, "lseek" },
@@ -964,6 +969,76 @@ static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp
return result;
}
+struct smb_full_audit_pread_state {
+ vfs_handle_struct *handle;
+ files_struct *fsp;
+ ssize_t ret;
+ int err;
+};
+
+static void smb_full_audit_pread_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_full_audit_pread_send(
+ struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev, struct files_struct *fsp,
+ void *data, size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct smb_full_audit_pread_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct smb_full_audit_pread_state);
+ if (req == NULL) {
+ do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
+ fsp_str_do_log(fsp));
+ return NULL;
+ }
+ state->handle = handle;
+ state->fsp = fsp;
+
+ subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
+ n, offset);
+ if (tevent_req_nomem(subreq, req)) {
+ do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
+ fsp_str_do_log(fsp));
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
+
+ do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
+ return req;
+}
+
+static void smb_full_audit_pread_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb_full_audit_pread_state *state = tevent_req_data(
+ req, struct smb_full_audit_pread_state);
+
+ state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
+{
+ struct smb_full_audit_pread_state *state = tevent_req_data(
+ req, struct smb_full_audit_pread_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
+ fsp_str_do_log(state->fsp));
+ return -1;
+ }
+
+ do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
+ fsp_str_do_log(state->fsp));
+
+ *err = state->err;
+ return state->ret;
+}
+
static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
const void *data, size_t n)
{
@@ -2203,6 +2278,8 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
.close_fn = smb_full_audit_close,
.read_fn = smb_full_audit_read,
.pread_fn = smb_full_audit_pread,
+ .pread_send_fn = smb_full_audit_pread_send,
+ .pread_recv_fn = smb_full_audit_pread_recv,
.write_fn = smb_full_audit_write,
.pwrite_fn = smb_full_audit_pwrite,
.lseek_fn = smb_full_audit_lseek,
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index a5ca407673..140b856acb 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -28,6 +28,7 @@
#include "includes.h"
#include "smbd/smbd.h"
#include "ntioctl.h"
+#include "lib/util/tevent_unix.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
@@ -519,6 +520,71 @@ static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
return result;
}
+struct smb_time_audit_pread_state {
+ struct timespec ts1;
+ ssize_t ret;
+ int err;
+};
+
+static void smb_time_audit_pread_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_time_audit_pread_send(
+ struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev, struct files_struct *fsp,
+ void *data, size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct smb_time_audit_pread_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct smb_time_audit_pread_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ clock_gettime_mono(&state->ts1);
+
+ subreq = SMB_VFS_NEXT_PREAD_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_pread_done, req);
+ return req;
+}
+
+static void smb_time_audit_pread_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb_time_audit_pread_state *state = tevent_req_data(
+ req, struct smb_time_audit_pread_state);
+
+ state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static ssize_t smb_time_audit_pread_recv(struct tevent_req *req, int *err)
+{
+ struct smb_time_audit_pread_state *state = tevent_req_data(
+ req, struct smb_time_audit_pread_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("pread", timediff);
+ }
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static ssize_t smb_time_audit_write(vfs_handle_struct *handle,
files_struct *fsp,
const void *data, size_t n)
@@ -2282,6 +2348,8 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
.close_fn = smb_time_audit_close,
.read_fn = smb_time_audit_read,
.pread_fn = smb_time_audit_pread,
+ .pread_send_fn = smb_time_audit_pread_send,
+ .pread_recv_fn = smb_time_audit_pread_recv,
.write_fn = smb_time_audit_write,
.pwrite_fn = smb_time_audit_pwrite,
.lseek_fn = smb_time_audit_lseek,