[SCM] Samba Shared Repository - branch v3-6-test updated

Karolin Seeger kseeger at samba.org
Wed Jun 19 02:57:28 MDT 2013


The branch, v3-6-test has been updated
       via  1f601d1 Ensure we test the dirsort module in make test.
       via  8a1ec80 Remove unneeded initializations (we already talloc_zero).
       via  ffc2d25 Remove the use of dirfd inside the vfs_dirsort.c.
       via  8a761c7 Convert mtime from a time_t to a struct timespec.
       via  052f74c Check SMB_VFS_NEXT_OPENDIR return in dirsort_opendir().
       via  a2da5a7 Clean error paths in opendir and fd_opendir by only setting handle data on success.
       via  582d8ca Protect open_and_sort_dir() from the directory changing size.
       via  f818221 Use an index i rather than re-using a state variable.
       via  f34063e Protect against early error in SMB_VFS_NEXT_READDIR.
       via  e2118fd Change source3/modules/vfs_dirsort.c from MALLOC -> TALLOC.
      from  1e064e9 WHATSNEW: Start release notes for Samba 3.6.17.

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


- Log -----------------------------------------------------------------
commit 1f601d14d0ee440126d7202924e5cf7af88f6ea3
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 9 16:56:24 2013 -0700

    Ensure we test the dirsort module in make test.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Apr 11 21:17:21 CEST 2013 on sn-devel-104
    
    The last 10 patches address bug #9777 - vfs_dirsort uses non-stackable calls,
    dirfd(), malloc instead of talloc and doesn't cope with directories being
    modified whilst reading.

commit 8a1ec80ee233405f2f484c31a8d6e4b2702678e0
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 9 11:02:58 2013 -0700

    Remove unneeded initializations (we already talloc_zero).
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit ffc2d250d2d0fd59a1524e15c4be5cf53d5b0135
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 9 10:50:55 2013 -0700

    Remove the use of dirfd inside the vfs_dirsort.c.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 8a761c7806fddd0faa919f343a079f8d4f343316
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 9 10:43:53 2013 -0700

    Convert mtime from a time_t to a struct timespec.
    
    In preparation for removing the dirfd and using fsp_stat()
    and VFS_STAT functions.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 052f74c2122301a3be19ab84ee4551f3259a3ee5
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 9 10:38:24 2013 -0700

    Check SMB_VFS_NEXT_OPENDIR return in dirsort_opendir().
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit a2da5a78c48e9be6ec2ecad99ddd23d4773b2267
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 9 10:29:47 2013 -0700

    Clean error paths in opendir and fd_opendir by only setting handle data on success.
    
    Pass extra struct dirsort_privates * to open_and_sort_dir() function
    to avoid it having to re-read the handle data.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 582d8ca565ad12133a4319650e886f58246b3bd9
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 8 16:40:35 2013 -0700

    Protect open_and_sort_dir() from the directory changing size.
    
    Otherwise there could be an error between initial count, allocation
    and re-read.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit f81822166d8d41c6c3ee6f17924ebe87e4303211
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 8 16:38:03 2013 -0700

    Use an index i rather than re-using a state variable.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit f34063ed9cd3d6a4542c39ad576c6ecc807878e8
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 8 16:31:53 2013 -0700

    Protect against early error in SMB_VFS_NEXT_READDIR.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit e2118fd251ac64f47a9ee4ea18a441ae1941fe4e
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 8 15:11:28 2013 -0700

    Change source3/modules/vfs_dirsort.c from MALLOC -> TALLOC.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

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

Summary of changes:
 selftest/target/Samba3.pm     |    2 +
 source3/modules/vfs_dirsort.c |  142 ++++++++++++++++++++++++----------------
 2 files changed, 87 insertions(+), 57 deletions(-)


Changeset truncated at 500 lines:

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 864f3dc..01a1c47 100644
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -650,6 +650,8 @@ sub provision($$$$$$)
 	print CONF "
 [tmp]
 	path = $shrdir
+	comment = smb username is [%U]
+	vfs objects = $vfs_modulesdir_abs/dirsort.so
 [tmpguest]
 	path = $shrdir
         guest ok = yes
diff --git a/source3/modules/vfs_dirsort.c b/source3/modules/vfs_dirsort.c
index adeab04..698e96b 100644
--- a/source3/modules/vfs_dirsort.c
+++ b/source3/modules/vfs_dirsort.c
@@ -30,40 +30,60 @@ static int compare_dirent (const SMB_STRUCT_DIRENT *da, const SMB_STRUCT_DIRENT
 struct dirsort_privates {
 	long pos;
 	SMB_STRUCT_DIRENT *directory_list;
-	long number_of_entries;
-	time_t mtime;
+	unsigned int number_of_entries;
+	struct timespec mtime;
 	SMB_STRUCT_DIR *source_directory;
-	int fd;
+	files_struct *fsp; /* If open via FDOPENDIR. */
+	struct smb_filename *smb_fname; /* If open via OPENDIR */
 };
 
 static void free_dirsort_privates(void **datap) {
-	struct dirsort_privates *data = (struct dirsort_privates *) *datap;
-	SAFE_FREE(data->directory_list);
-	SAFE_FREE(data);
-	*datap = NULL;
-
-	return;
+	TALLOC_FREE(*datap);
 }
 
-static bool open_and_sort_dir (vfs_handle_struct *handle)
+static bool get_sorted_dir_mtime(vfs_handle_struct *handle,
+				struct dirsort_privates *data,
+				struct timespec *ret_mtime)
 {
-	SMB_STRUCT_DIRENT *dp;
-	struct stat dir_stat;
-	long current_pos;
-	struct dirsort_privates *data = NULL;
+	int ret;
+	struct timespec mtime;
+
+	if (data->fsp) {
+		ret = fsp_stat(data->fsp);
+		mtime = data->fsp->fsp_name->st.st_ex_mtime;
+	} else {
+		ret = SMB_VFS_STAT(handle->conn, data->smb_fname);
+		mtime = data->smb_fname->st.st_ex_mtime;
+	}
 
-	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates,
-				return false);
+	if (ret == -1) {
+		return false;
+	}
+
+	*ret_mtime = mtime;
+
+	return true;
+}
+
+static bool open_and_sort_dir(vfs_handle_struct *handle,
+				struct dirsort_privates *data)
+{
+	unsigned int i = 0;
+	unsigned int total_count = 0;
 
 	data->number_of_entries = 0;
 
-	if (fstat(data->fd, &dir_stat) == 0) {
-		data->mtime = dir_stat.st_mtime;
+	if (get_sorted_dir_mtime(handle, data, &data->mtime) == false) {
+		return false;
 	}
 
 	while (SMB_VFS_NEXT_READDIR(handle, data->source_directory, NULL)
 	       != NULL) {
-		data->number_of_entries++;
+		total_count++;
+	}
+
+	if (total_count == 0) {
+		return false;
 	}
 
 	/* Open the underlying directory and count the number of entries
@@ -71,21 +91,26 @@ static bool open_and_sort_dir (vfs_handle_struct *handle)
 	SMB_VFS_NEXT_REWINDDIR(handle, data->source_directory);
 
 	/* Set up an array and read the directory entries into it */
-	SAFE_FREE(data->directory_list); /* destroy previous cache if needed */
-	data->directory_list = (SMB_STRUCT_DIRENT *)SMB_MALLOC(
-		data->number_of_entries * sizeof(SMB_STRUCT_DIRENT));
+	TALLOC_FREE(data->directory_list); /* destroy previous cache if needed */
+	data->directory_list = talloc_zero_array(data,
+						 SMB_STRUCT_DIRENT,
+						 total_count);
 	if (!data->directory_list) {
 		return false;
 	}
-	current_pos = data->pos;
-	data->pos = 0;
-	while ((dp = SMB_VFS_NEXT_READDIR(handle, data->source_directory,
-					  NULL)) != NULL) {
-		data->directory_list[data->pos++] = *dp;
+	for (i = 0; i < total_count; i++) {
+		SMB_STRUCT_DIRENT *dp = SMB_VFS_NEXT_READDIR(handle,
+						data->source_directory,
+						NULL);
+		if (dp == NULL) {
+			break;
+		}
+		data->directory_list[i] = *dp;
 	}
 
+	data->number_of_entries = i;
+
 	/* Sort the directory entries by name */
-	data->pos = current_pos;
 	TYPESAFE_QSORT(data->directory_list, data->number_of_entries, compare_dirent);
 	return true;
 }
@@ -94,33 +119,43 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
 				       const char *fname, const char *mask,
 				       uint32 attr)
 {
+	NTSTATUS status;
 	struct dirsort_privates *data = NULL;
 
 	/* set up our private data about this directory */
-	data = (struct dirsort_privates *)SMB_MALLOC(
-		sizeof(struct dirsort_privates));
-
+	data = talloc_zero(handle->conn, struct dirsort_privates);
 	if (!data) {
 		return NULL;
 	}
 
-	data->directory_list = NULL;
-	data->pos = 0;
+	status = create_synthetic_smb_fname(data,
+					fname,
+					NULL,
+					NULL,
+					&data->smb_fname);
+	if (!NT_STATUS_IS_OK(status)) {
+		TALLOC_FREE(data);
+		return NULL;
+	}
 
 	/* Open the underlying directory and count the number of entries */
 	data->source_directory = SMB_VFS_NEXT_OPENDIR(handle, fname, mask,
 						      attr);
 
-	data->fd = dirfd(data->source_directory);
-
-	SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
-				struct dirsort_privates, return NULL);
+	if (data->source_directory == NULL) {
+		TALLOC_FREE(data);
+		return NULL;
+	}
 
-	if (!open_and_sort_dir(handle)) {
+	if (!open_and_sort_dir(handle, data)) {
 		SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
+		TALLOC_FREE(data);
 		return NULL;
 	}
 
+	SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
+				struct dirsort_privates, return NULL);
+
 	return data->source_directory;
 }
 
@@ -132,37 +167,33 @@ static SMB_STRUCT_DIR *dirsort_fdopendir(vfs_handle_struct *handle,
 	struct dirsort_privates *data = NULL;
 
 	/* set up our private data about this directory */
-	data = (struct dirsort_privates *)SMB_MALLOC(
-		sizeof(struct dirsort_privates));
-
+	data = talloc_zero(handle->conn, struct dirsort_privates);
 	if (!data) {
 		return NULL;
 	}
 
-	data->directory_list = NULL;
-	data->pos = 0;
+	data->fsp = fsp;
 
 	/* Open the underlying directory and count the number of entries */
 	data->source_directory = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask,
 						      attr);
 
 	if (data->source_directory == NULL) {
-		SAFE_FREE(data);
+		TALLOC_FREE(data);
 		return NULL;
 	}
 
-	data->fd = dirfd(data->source_directory);
-
-	SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
-				struct dirsort_privates, return NULL);
-
-	if (!open_and_sort_dir(handle)) {
+	if (!open_and_sort_dir(handle, data)) {
 		SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
+		TALLOC_FREE(data);
 		/* fd is now closed. */
 		fsp->fh->fd = -1;
 		return NULL;
 	}
 
+	SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
+				struct dirsort_privates, return NULL);
+
 	return data->source_directory;
 }
 
@@ -171,21 +202,18 @@ static SMB_STRUCT_DIRENT *dirsort_readdir(vfs_handle_struct *handle,
 					  SMB_STRUCT_STAT *sbuf)
 {
 	struct dirsort_privates *data = NULL;
-	time_t current_mtime;
-	struct stat dir_stat;
+	struct timespec current_mtime;
 
 	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates,
 				return NULL);
 
-	if (fstat(data->fd, &dir_stat) == -1) {
+	if (get_sorted_dir_mtime(handle, data, &current_mtime) == false) {
 		return NULL;
 	}
 
-	current_mtime = dir_stat.st_mtime;
-
 	/* throw away cache and re-read the directory if we've changed */
-	if (current_mtime > data->mtime) {
-		open_and_sort_dir(handle);
+	if (timespec_compare(&current_mtime, &data->mtime) > 1) {
+		open_and_sort_dir(handle, data);
 	}
 
 	if (data->pos >= data->number_of_entries) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list