[PATCHES] Check for missing VFS functions in time_audit and full_audit

Christof Schmitt cs at samba.org
Fri Apr 1 05:50:47 UTC 2016


The goal of time_audit and full_audit is to intercept all VFS functions.
Everytime a new VFS functions is added, this is easily forgotten. The
attached patches add a hack to check for missing functions in developer
mode. It is ugly, but i could not find a better way to achieve this.

On current master it already spots missing functions:

samba_init_module: Missing function at 8 in full_audit
samba_init_module: Missing function at 79 in full_audit
samba_init_module: Missing function at 87 in full_audit
samba_init_module: Missing function at 108 in full_audit
samba_init_module: Missing function at 109 in full_audit
samba_init_module: Missing function at 110 in full_audit
samba_init_module: Missing function at 8 in time_audit
samba_init_module: Missing function at 79 in time_audit
samba_init_module: Missing function at 80 in time_audit
samba_init_module: Missing function at 81 in time_audit
samba_init_module: Missing function at 82 in time_audit
samba_init_module: Missing function at 83 in time_audit
samba_init_module: Missing function at 87 in time_audit

Comments?

Christof
-------------- next part --------------
From 1262ac93de20761b7af879179ed61cb73ad9878a Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Thu, 31 Mar 2016 22:30:14 -0700
Subject: [PATCH 1/3] vfs_full_audit: Print message for missing callbacks in
 developer mode

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/modules/vfs_full_audit.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index 79c57e8..04435b9 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -2436,9 +2436,25 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
 static_decl_vfs;
 NTSTATUS vfs_full_audit_init(void)
 {
-	NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
-					"full_audit", &vfs_full_audit_fns);
-	
+	NTSTATUS ret;
+
+#ifdef DEVELOPER
+	/*
+	 * Ensure this module catches all VFS functions.
+	 */
+	unsigned int idx;
+	uintptr_t *end = (uintptr_t *)(&vfs_full_audit_fns + 1);
+
+	for (idx = 0; ((uintptr_t *)&vfs_full_audit_fns + idx) < end; idx++) {
+		if (*((uintptr_t *)&vfs_full_audit_fns + idx) == 0) {
+			DBG_ERR("Missing function at %d in full_audit\n", idx);
+		}
+	}
+#endif
+
+	ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
+			       &vfs_full_audit_fns);
+
 	if (!NT_STATUS_IS_OK(ret))
 		return ret;
 
-- 
1.8.3.1


From b36dd80baefeaf4074f9df45ffa020e71cce9f05 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Thu, 31 Mar 2016 22:30:41 -0700
Subject: [PATCH 2/3] vfs_time_audit: Print warning for missing functions in
 developer mode

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/modules/vfs_time_audit.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 3bdc98b..c5120eb 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -2539,6 +2539,19 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
 NTSTATUS vfs_time_audit_init(void);
 NTSTATUS vfs_time_audit_init(void)
 {
+#ifdef DEVELOPER
+	/*
+	 * Ensure this module catches all VFS functions.
+	 */
+	unsigned int idx;
+	uintptr_t *end = (uintptr_t *)(&vfs_time_audit_fns + 1);
+
+	for (idx = 0; ((uintptr_t *)&vfs_time_audit_fns + idx) < end; idx++) {
+		if (*((uintptr_t *)&vfs_time_audit_fns + idx) == 0) {
+			DBG_ERR("Missing function at %d in time_audit\n", idx);
+		}
+	}
+#endif
 	audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
 					    10000) / 1000.0;
 	return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
-- 
1.8.3.1


From 343218bfe22647c751d85d1ca54a55dd27cc2864 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Thu, 31 Mar 2016 22:31:19 -0700
Subject: [PATCH 3/3] selftest: Load time_audit and full_audit

This triggers the check for missing VFS functions in these modules.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 selftest/target/Samba3.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index bdeebc9..f4d7403 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -548,7 +548,7 @@ sub setup_simpleserver($$)
 
 	my $simpleserver_options = "
 	lanman auth = yes
-	vfs objects = xattr_tdb streams_depot
+	vfs objects = xattr_tdb streams_depot time_audit full_audit
 	change notify = no
 
 [vfs_aio_fork]
-- 
1.8.3.1



More information about the samba-technical mailing list