Yet another VFS Module

Thomas Reifferscheid reiffert at Student.Physik.Uni-Mainz.DE
Thu Sep 8 14:27:45 GMT 2005


My module does the following:

Limit write() to a given file size limit.

Please tell me what is missing or which parts are broken
by design. Is there any chance to get this module in the
official samba-source-tree?


The diff as an attachment.

Kind regards,
Thomas Reifferscheid


-------------- next part --------------
diff -Naur samba-3.0.14a.old/source/Makefile.in samba-3.0.14a.new/source/Makefile.in
--- samba-3.0.14a.old/source/Makefile.in	2005-04-14 08:14:19.000000000 +0200
+++ samba-3.0.14a.new/source/Makefile.in	2005-09-08 16:07:27.000000000 +0200
@@ -333,6 +333,7 @@
 VFS_AUDIT_OBJ = modules/vfs_audit.o
 VFS_EXTD_AUDIT_OBJ = modules/vfs_extd_audit.o
 VFS_FULL_AUDIT_OBJ = modules/vfs_full_audit.o
+VFS_LIMIT_OBJ = modules/vfs_limit.o
 VFS_FAKE_PERMS_OBJ = modules/vfs_fake_perms.o
 VFS_RECYCLE_OBJ = modules/vfs_recycle.o
 VFS_NETATALK_OBJ = modules/vfs_netatalk.o
@@ -1183,6 +1184,11 @@
 	@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_FULL_AUDIT_OBJ:.o=. at PICSUFFIX@) \
 		@SONAMEFLAG@`basename $@`
 
+bin/limit. at SHLIBEXT@: $(VFS_LIMIT_OBJ:.o=. at PICSUFFIX@)
+	@echo "Building plugin $@"
+	@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_LIMIT_OBJ:.o=. at PICSUFFIX@) \
+		@SONAMEFLAG@`basename $@`
+
 bin/recycle. at SHLIBEXT@: $(VFS_RECYCLE_OBJ:.o=. at PICSUFFIX@)
 	@echo "Building plugin $@"
 	@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_RECYCLE_OBJ:.o=. at PICSUFFIX@) \
diff -Naur samba-3.0.14a.old/source/configure.in samba-3.0.14a.new/source/configure.in
--- samba-3.0.14a.old/source/configure.in	2005-04-14 08:14:26.000000000 +0200
+++ samba-3.0.14a.new/source/configure.in	2005-09-08 16:08:03.000000000 +0200
@@ -419,7 +419,7 @@
 default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_reg rpc_lsa_ds rpc_wks rpc_net rpc_dfs rpc_srv rpc_spoolss auth_rhosts auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin"
 
 dnl These are preferably build shared, and static if dlopen() is not available
-default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437"
+default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_limit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437"
 
 if test "x$developer" = xyes; then
    default_static_modules="$default_static_modules rpc_echo"
@@ -4587,6 +4587,7 @@
 SMB_MODULE(vfs_audit, \$(VFS_AUDIT_OBJ), "bin/audit.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_extd_audit, \$(VFS_EXTD_AUDIT_OBJ), "bin/extd_audit.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_full_audit, \$(VFS_FULL_AUDIT_OBJ), "bin/full_audit.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_limit, \$(VFS_LIMIT_OBJ), "bin/limit.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_netatalk, \$(VFS_NETATALK_OBJ), "bin/netatalk.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_fake_perms, \$(VFS_FAKE_PERMS_OBJ), "bin/fake_perms.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_default_quota, \$(VFS_DEFAULT_QUOTA_OBJ), "bin/default_quota.$SHLIBEXT", VFS)
diff -Naur samba-3.0.14a.old/source/include/config.h.in samba-3.0.14a.new/source/include/config.h.in
--- samba-3.0.14a.old/source/include/config.h.in	2005-04-14 08:23:49.000000000 +0200
+++ samba-3.0.14a.new/source/include/config.h.in	2005-09-08 16:08:43.000000000 +0200
@@ -2043,6 +2043,9 @@
 /* Whether to build vfs_full_audit as shared module */
 #undef vfs_full_audit_init
 
+/* Whether to build vfs_limit as shared module */
+#undef vfs_limit_init
+
 /* Whether to build vfs_netatalk as shared module */
 #undef vfs_netatalk_init
 
diff -Naur samba-3.0.14a.old/source/modules/vfs_limit.c samba-3.0.14a.new/source/modules/vfs_limit.c
--- samba-3.0.14a.old/source/modules/vfs_limit.c	1970-01-01 01:00:00.000000000 +0100
+++ samba-3.0.14a.new/source/modules/vfs_limit.c	2005-09-08 16:21:39.000000000 +0200
@@ -0,0 +1,105 @@
+/* 
+ * Limit Maximum File Size module for samba.
+ *
+ * Copyright (C) Thomas Reifferscheid, 2005
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *  
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * This module implements a maximum file size for writing files on a share
+ *
+ * You use it as follows:
+ *
+ * [tmp]
+ * path = /tmp
+ * vfs objects = limit
+ * limit:maxsize = 100
+ * Where 100 stands for 100 Megabytes, 100*1024*1024 bytes.
+ *
+ * When the limit has reached, NT_STATUS_DISK_FULL get's returned.
+ */
+
+#include "includes.h"
+
+static int vfs_limit_debug_level = DBGC_VFS;
+
+#undef DBGC_CLASS
+#define DBGC_CLASS vfs_limit_debug_level
+
+/* Function prototypes */
+
+static ssize_t smb_limit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
+			    int fd, const void *data, size_t n,
+			    SMB_OFF_T offset);
+
+/* VFS operations */
+
+static vfs_op_tuple limit_op_tuples[] = {
+    
+	{SMB_VFS_OP(smb_limit_pwrite),	SMB_VFS_OP_PWRITE,
+	 SMB_VFS_LAYER_TRANSPARENT},
+};
+
+
+unsigned long long limit_getlimit(connection_struct *conn)
+{
+	unsigned long long maxsize; 
+	
+        maxsize = lp_parm_int(SNUM(conn), "limit", "maxsize", 0) * 1024 * 1024;
+        
+        return maxsize;
+}
+
+static ssize_t smb_limit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
+			    int fd, const void *data, size_t n,
+			    SMB_OFF_T offset)
+{
+	ssize_t result;
+
+	if ((offset + n) > limit_getlimit(handle->conn))
+	{
+		if ( (result = SMB_VFS_NEXT_PWRITE(handle, fsp, fd, data, limit_getlimit(handle->conn) - offset , offset)))
+			return result;
+		errno = ENOSPC;
+		return -1;
+	}
+
+	result = SMB_VFS_NEXT_PWRITE(handle, fsp, fd, data, n, offset);
+
+	return result;
+}
+
+NTSTATUS vfs_limit_init(void)
+{
+	NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
+					"limit", limit_op_tuples);
+	
+	if (!NT_STATUS_IS_OK(ret))
+		return ret;
+
+	vfs_limit_debug_level = debug_add_class("limit");
+	if (vfs_limit_debug_level == -1) {
+		vfs_limit_debug_level = DBGC_VFS;
+		DEBUG(0, ("vfs_limit: Couldn't register custom debugging "
+			  "class!\n"));
+	} else {
+		DEBUG(10, ("vfs_limit: Debug class number of "
+			   "'limit': %d\n", vfs_limit_debug_level));
+	}
+	
+	return ret;
+}
+


More information about the samba-technical mailing list