[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-test-1538-g5f5fc72

Volker Lendecke vl at samba.org
Sat Jan 19 22:51:09 GMT 2008


The branch, v3-2-test has been updated
       via  5f5fc72b01c8e8fc096375c7cb4a97186c387259 (commit)
       via  83a805220e52742119546c76a054d50582e33a24 (commit)
      from  6022873cc155bdbbd3fb620689715f07a24d6ed1 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 5f5fc72b01c8e8fc096375c7cb4a97186c387259
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jan 19 23:36:34 2008 +0100

    vfs_streams_depot
    
    Store streams in a file each. Not 100% finished, and not built by default.

commit 83a805220e52742119546c76a054d50582e33a24
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jan 19 23:33:11 2008 +0100

    vfs_streams_xattr module
    
    Store streams in posix xattrs. A kludge, as xattrs are limited in many ways,
    but it might be a help for some situations.

-----------------------------------------------------------------------

Summary of changes:
 source/Makefile.in                 |   10 +
 source/configure.in                |    4 +-
 source/modules/vfs_streams_depot.c |  648 ++++++++++++++++++++++++++++++++++
 source/modules/vfs_streams_xattr.c |  672 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1333 insertions(+), 1 deletions(-)
 create mode 100644 source/modules/vfs_streams_depot.c
 create mode 100644 source/modules/vfs_streams_xattr.c


Changeset truncated at 500 lines:

diff --git a/source/Makefile.in b/source/Makefile.in
index d3e3782..ea5e5a8 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -526,6 +526,8 @@ VFS_HPUXACL_OBJ = modules/vfs_hpuxacl.o
 VFS_IRIXACL_OBJ = modules/vfs_irixacl.o
 VFS_TRU64ACL_OBJ = modules/vfs_tru64acl.o
 VFS_CATIA_OBJ = modules/vfs_catia.o
+VFS_STREAMS_XATTR_OBJ = modules/vfs_streams_xattr.o
+VFS_STREAMS_DEPOT_OBJ = modules/vfs_streams_depot.o
 VFS_CACHEPRIME_OBJ = modules/vfs_cacheprime.o
 VFS_PREALLOC_OBJ = modules/vfs_prealloc.o
 VFS_COMMIT_OBJ = modules/vfs_commit.o
@@ -1747,6 +1749,14 @@ bin/catia. at SHLIBEXT@: $(BINARY_PREREQS) $(VFS_CATIA_OBJ)
 	@echo "Building plugin $@"
 	@$(SHLD_MODULE) $(VFS_CATIA_OBJ)
 
+bin/streams_xattr. at SHLIBEXT@: $(BINARY_PREREQS) $(VFS_STREAMS_XATTR_OBJ)
+	@echo "Building plugin $@"
+	@$(SHLD_MODULE) $(VFS_STREAMS_XATTR_OBJ)
+
+bin/streams_depot. at SHLIBEXT@: $(BINARY_PREREQS) $(VFS_STREAMS_DEPOT_OBJ)
+	@echo "Building plugin $@"
+	@$(SHLD_MODULE) $(VFS_STREAMS_DEPOT_OBJ)
+
 bin/cacheprime. at SHLIBEXT@: $(BINARY_PREREQS) $(VFS_CACHEPRIME_OBJ)
 	@echo "Building plugin $@"
 	@$(SHLD_MODULE) $(VFS_CACHEPRIME_OBJ)
diff --git a/source/configure.in b/source/configure.in
index a34d42c..25e3b36 100644
--- a/source/configure.in
+++ b/source/configure.in
@@ -707,7 +707,7 @@ dnl These have to be built static:
 default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_winreg rpc_initshutdown rpc_lsa_ds rpc_wkssvc rpc_svcctl2 rpc_ntsvcs rpc_net rpc_netdfs rpc_srvsvc2 rpc_spoolss rpc_eventlog2 auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default nss_info_template"
 
 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 vfs_shadow_copy2 charset_CP850 charset_CP437 auth_script vfs_readahead vfs_syncops vfs_xattr_tdb"
+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 vfs_shadow_copy2 charset_CP850 charset_CP437 auth_script vfs_readahead vfs_syncops vfs_xattr_tdb vfs_streams_xattr"
 
 if test "x$developer" = xyes; then
    default_static_modules="$default_static_modules rpc_rpcecho"
@@ -6497,6 +6497,8 @@ SMB_MODULE(vfs_irixacl, \$(VFS_IRIXACL_OBJ), "bin/irixacl.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_hpuxacl, \$(VFS_HPUXACL_OBJ), "bin/hpuxacl.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_tru64acl, \$(VFS_TRU64ACL_OBJ), "bin/tru64acl.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_catia, \$(VFS_CATIA_OBJ), "bin/catia.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_streams_xattr, \$(VFS_STREAMS_XATTR_OBJ), "bin/streams_xattr.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_streams_depot, \$(VFS_STREAMS_DEPOT_OBJ), "bin/streams_depot.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_cacheprime, \$(VFS_CACHEPRIME_OBJ), "bin/cacheprime.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_prealloc, \$(VFS_PREALLOC_OBJ), "bin/prealloc.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_commit, \$(VFS_COMMIT_OBJ), "bin/commit.$SHLIBEXT", VFS)
diff --git a/source/modules/vfs_streams_depot.c b/source/modules/vfs_streams_depot.c
new file mode 100644
index 0000000..68e7a75
--- /dev/null
+++ b/source/modules/vfs_streams_depot.c
@@ -0,0 +1,648 @@
+/*
+ * Store streams in a separate subdirectory
+ *
+ * Copyright (C) Volker Lendecke, 2007
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_VFS
+
+/*
+ * Excerpt from a mail from tridge:
+ *
+ * Volker, what I'm thinking of is this:
+ * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream1
+ * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream2
+ *
+ * where XX/YY is a 2 level hash based on the fsid/inode. "aaaa.bbbb"
+ * is the fsid/inode. "namedstreamX" is a file named after the stream
+ * name.
+ */
+
+static uint32_t hash_fn(DATA_BLOB key)
+{
+	uint32_t value;	/* Used to compute the hash value.  */
+	uint32_t i;	/* Used to cycle through random values. */
+
+	/* Set the initial value from the key size. */
+	for (value = 0x238F13AF * key.length, i=0; i < key.length; i++)
+		value = (value + (key.data[i] << (i*5 % 24)));
+
+	return (1103515243 * value + 12345);
+}
+
+/*
+ * With the hashing scheme based on the inode we need to protect against
+ * streams showing up on files with re-used inodes. This can happen if we
+ * create a stream directory from within Samba, and a local process or NFS
+ * client deletes the file without deleting the streams directory. When the
+ * inode is re-used and the stream directory is still around, the streams in
+ * there would be show up as belonging to the new file.
+ *
+ * There are several workarounds for this, probably the easiest one is on
+ * systems which have a true birthtime stat element: When the file has a later
+ * birthtime than the streams directory, then we have to recreate the
+ * directory.
+ *
+ * The other workaround is to somehow mark the file as generated by Samba with
+ * something that a NFS client would not do. The closest one is a special
+ * xattr value being set. On systems which do not support xattrs, it might be
+ * an option to put in a special ACL entry for a non-existing group.
+ */
+
+#define SAMBA_XATTR_MARKER "user.SAMBA_STREAMS"
+
+static bool file_is_valid(vfs_handle_struct *handle, const char *path)
+{
+	char buf;
+
+	DEBUG(10, ("file_is_valid (%s) called\n", path));
+
+	if (SMB_VFS_NEXT_GETXATTR(handle, path, SAMBA_XATTR_MARKER,
+				  &buf, sizeof(buf)) != sizeof(buf)) {
+		DEBUG(10, ("GETXATTR failed: %s\n", strerror(errno)));
+		return false;
+	}
+
+	if (buf != '1') {
+		DEBUG(10, ("got wrong buffer content: '%c'\n", buf));
+		return false;
+	}
+
+	return true;
+}
+
+static bool mark_file_valid(vfs_handle_struct *handle, const char *path)
+{
+	char buf = '1';
+	int ret;
+
+	DEBUG(10, ("marking file %s as valid\n", path));
+
+	ret = SMB_VFS_NEXT_SETXATTR(handle, path, SAMBA_XATTR_MARKER,
+				    &buf, sizeof(buf), 0);
+
+	if (ret == -1) {
+		DEBUG(10, ("SETXATTR failed: %s\n", strerror(errno)));
+		return false;
+	}
+
+	return true;
+}
+
+static char *stream_dir(vfs_handle_struct *handle, const char *base_path,
+			const SMB_STRUCT_STAT *base_sbuf, bool create_it)
+{
+	uint32_t hash;
+	char *result = NULL;
+	SMB_STRUCT_STAT sbuf;
+	uint8_t first, second;
+	char *tmp;
+	char *id_hex;
+	struct file_id id;
+	uint8 id_buf[16];
+
+	const char *rootdir = lp_parm_const_string(
+		SNUM(handle->conn), "streams", "directory",
+		handle->conn->connectpath);
+
+	if (base_sbuf == NULL) {
+		if (SMB_VFS_NEXT_STAT(handle, base_path, &sbuf) == -1) {
+			/*
+			 * base file is not there
+			 */
+			goto fail;
+		}
+		base_sbuf = &sbuf;
+	}
+
+	id = SMB_VFS_FILE_ID_CREATE(handle->conn, base_sbuf->st_dev,
+				    base_sbuf->st_ino);
+
+	push_file_id_16((char *)id_buf, &id);
+
+	hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
+
+	first = hash & 0xff;
+	second = (hash >> 8) & 0xff;
+
+	id_hex = hex_encode(talloc_tos(), id_buf, sizeof(id_buf));
+
+	if (id_hex == NULL) {
+		errno = ENOMEM;
+		goto fail;
+	}
+
+	result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
+				 first, second, id_hex);
+
+	TALLOC_FREE(id_hex);
+
+	if (result == NULL) {
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	if (SMB_VFS_NEXT_STAT(handle, result, &sbuf) == 0) {
+		char *newname;
+
+		if (!S_ISDIR(sbuf.st_mode)) {
+			errno = EINVAL;
+			goto fail;
+		}
+
+		if (file_is_valid(handle, base_path)) {
+			return result;
+		}
+
+		/*
+		 * Someone has recreated a file under an existing inode
+		 * without deleting the streams directory. For now, just move
+		 * it away.
+		 */
+
+	again:
+		newname = talloc_asprintf(talloc_tos(), "lost-%lu", random());
+		if (newname == NULL) {
+			errno = ENOMEM;
+			goto fail;
+		}
+
+		if (SMB_VFS_NEXT_RENAME(handle, result, newname) == -1) {
+			if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
+				TALLOC_FREE(newname);
+				goto again;
+			}
+			goto fail;
+		}
+
+		TALLOC_FREE(newname);
+	}
+
+	if (!create_it) {
+		errno = ENOENT;
+		goto fail;
+	}
+
+	if ((SMB_VFS_NEXT_MKDIR(handle, rootdir, 0755) != 0)
+	    && (errno != EEXIST)) {
+		goto fail;
+	}
+
+	tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
+	if (tmp == NULL) {
+		errno = ENOMEM;
+		goto fail;
+	}
+
+	if ((SMB_VFS_NEXT_MKDIR(handle, tmp, 0755) != 0)
+	    && (errno != EEXIST)) {
+		goto fail;
+	}
+
+	TALLOC_FREE(tmp);
+
+	tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
+			      second);
+	if (tmp == NULL) {
+		errno = ENOMEM;
+		goto fail;
+	}
+
+	if ((SMB_VFS_NEXT_MKDIR(handle, tmp, 0755) != 0)
+	    && (errno != EEXIST)) {
+		goto fail;
+	}
+
+	TALLOC_FREE(tmp);
+
+	if ((SMB_VFS_NEXT_MKDIR(handle, result, 0755) != 0)
+	    && (errno != EEXIST)) {
+		goto fail;
+	}
+
+	if (!mark_file_valid(handle, base_path)) {
+		goto fail;
+	}
+
+	return result;
+
+ fail:
+	TALLOC_FREE(result);
+	return NULL;
+}
+
+static char *stream_name(vfs_handle_struct *handle, const char *fname,
+			 bool create_dir)
+{
+	char *base = NULL;
+	char *sname = NULL;
+	char *id_hex = NULL;
+	char *dirname, *stream_fname;
+
+	if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), fname,
+						    &base, &sname))) {
+		DEBUG(10, ("split_ntfs_stream_name failed\n"));
+		errno = ENOMEM;
+		goto fail;
+	}
+
+	dirname = stream_dir(handle, base, NULL, create_dir);
+
+	if (dirname == NULL) {
+		goto fail;
+	}
+
+	stream_fname = talloc_asprintf(talloc_tos(), "%s/:%s", dirname, sname);
+
+	if (stream_fname == NULL) {
+		errno = ENOMEM;
+		goto fail;
+	}
+
+	DEBUG(10, ("stream filename = %s\n", stream_fname));
+
+	TALLOC_FREE(base);
+	TALLOC_FREE(sname);
+	TALLOC_FREE(id_hex);
+
+	return stream_fname;
+
+ fail:
+	DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
+	TALLOC_FREE(base);
+	TALLOC_FREE(sname);
+	TALLOC_FREE(id_hex);
+	return NULL;
+}
+
+static NTSTATUS walk_streams(vfs_handle_struct *handle,
+			     const char *fname,
+			     const SMB_STRUCT_STAT *sbuf,
+			     char **pdirname,
+			     bool (*fn)(const char *dirname,
+					const char *dirent,
+					void *private_data),
+			     void *private_data)
+{
+	char *dirname;
+	SMB_STRUCT_DIR *dirhandle = NULL;
+	char *dirent;
+
+	dirname = stream_dir(handle, fname, sbuf, false);
+
+	if (dirname == NULL) {
+		if (errno == ENOENT) {
+			/*
+			 * no stream around
+			 */
+			return NT_STATUS_OK;
+		}
+		return map_nt_error_from_unix(errno);
+	}
+
+	DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
+
+	dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dirname, NULL, 0);
+
+	if (dirhandle == NULL) {
+		TALLOC_FREE(dirname);
+		return map_nt_error_from_unix(errno);
+	}
+
+	while ((dirent = vfs_readdirname(handle->conn, dirhandle)) != NULL) {
+
+		if (ISDOT(dirent) || ISDOTDOT(dirent)) {
+			continue;
+		}
+
+		DEBUG(10, ("walk_streams: dirent=%s\n", dirent));
+
+		if (!fn(dirname, dirent, private_data)) {
+			break;
+		}
+	}
+
+	SMB_VFS_NEXT_CLOSEDIR(handle, dirhandle);
+
+	if (pdirname != NULL) {
+		*pdirname = dirname;
+	}
+	else {
+		TALLOC_FREE(dirname);
+	}
+
+	return NT_STATUS_OK;
+}
+
+static int streams_depot_stat(vfs_handle_struct *handle, const char *fname,
+			      SMB_STRUCT_STAT *sbuf)
+{
+	char *stream_fname;
+	int ret = -1;
+
+	DEBUG(10, ("streams_depot_stat called for [%s]\n", fname));
+
+	if (!is_ntfs_stream_name(fname)) {
+		return SMB_VFS_NEXT_STAT(handle, fname, sbuf);
+	}
+
+	stream_fname = stream_name(handle, fname, false);
+	if (stream_fname == NULL) {
+		goto done;
+	}
+
+	ret = SMB_VFS_NEXT_STAT(handle, stream_fname, sbuf);
+
+ done:
+	TALLOC_FREE(stream_fname);
+	return ret;
+}
+
+static int streams_depot_lstat(vfs_handle_struct *handle, const char *fname,
+			       SMB_STRUCT_STAT *sbuf)
+{
+	char *stream_fname;
+	int ret = -1;
+
+	if (!is_ntfs_stream_name(fname)) {
+		return SMB_VFS_NEXT_LSTAT(handle, fname, sbuf);
+	}
+
+	stream_fname = stream_name(handle, fname, false);
+	if (stream_fname == NULL) {
+		goto done;
+	}
+
+	ret = SMB_VFS_NEXT_LSTAT(handle, stream_fname, sbuf);
+
+ done:
+	TALLOC_FREE(stream_fname);
+	return ret;
+}
+
+static int streams_depot_open(vfs_handle_struct *handle,  const char *fname,
+			      files_struct *fsp, int flags, mode_t mode)
+{
+	TALLOC_CTX *frame;
+	char *base = NULL;
+	SMB_STRUCT_STAT base_sbuf;
+	char *stream_fname;
+	int ret = -1;
+
+	if (!is_ntfs_stream_name(fname)) {
+		return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+	}
+
+	frame = talloc_stackframe();
+
+	if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), fname,
+						    &base, NULL))) {
+		errno = ENOMEM;
+		goto done;
+	}
+
+	ret = SMB_VFS_NEXT_STAT(handle, base, &base_sbuf);
+
+	if (ret == -1) {
+		goto done;
+	}
+
+	TALLOC_FREE(base);
+
+	stream_fname = stream_name(handle, fname, true);
+	if (stream_fname == NULL) {
+		goto done;
+	}
+
+	ret = SMB_VFS_NEXT_OPEN(handle, stream_fname, fsp, flags, mode);
+
+ done:
+	TALLOC_FREE(frame);
+	return ret;
+}
+
+static int streams_depot_unlink(vfs_handle_struct *handle,  const char *fname)
+{
+	int ret = -1;
+	SMB_STRUCT_STAT sbuf;
+


-- 
Samba Shared Repository


More information about the samba-cvs mailing list