[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Apr 11 13:18:02 MDT 2013


The branch, master has been updated
       via  8956c0d Ensure we test the dirsort module in make test.
       via  3347805 Remove unneeded initializations (we already talloc_zero).
       via  353718c Remove the use of dirfd inside the vfs_dirsort.c.
       via  6ae58dd Convert mtime from a time_t to a struct timespec.
       via  770512e Check SMB_VFS_NEXT_OPENDIR return in dirsort_opendir().
       via  7e437a3 Clean error paths in opendir and fd_opendir by only setting handle data on success.
       via  cdcb631 Protect open_and_sort_dir() from the directory changing size.
       via  53d980b Use an index i rather than re-using a state variable.
       via  b30697f Protect against early error in SMB_VFS_NEXT_READDIR.
       via  c55eb37 Change source3/modules/vfs_dirsort.c from MALLOC -> TALLOC.
      from  f775613 scripting-provision: Do not enforce domain != realm if we are joining an existing domain

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 8956c0d53bd4e34ec4a93ac5bc1c72ad44e4b004
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

commit 33478058c78e4c4a384cad2fbe8198b4a4aed101
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 353718c3f9fa49f6c3b5d6de2afd79fbfade4295
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 6ae58dd153e3a53af52d896fff83ec76f40984d6
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 770512e3bd785a977351ba82ab08c556573c79dd
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 7e437a39abaee1133ea4c30e75ef53eb47ca64b6
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 cdcb6319127883d724508da3f6140a1e2aca75af
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 53d980bb0e70e40a07092c07d5fbd59fc8957f49
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 b30697f6388600d1557a96ff3ff3a3548ee99d69
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 c55eb371144d0ab91b1254b85f2b2a3d4aab8b68
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     |    1 +
 source3/modules/vfs_dirsort.c |  140 +++++++++++++++++++++++++----------------
 2 files changed, 86 insertions(+), 55 deletions(-)


Changeset truncated at 500 lines:

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 72c1116..1b14f1c 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1026,6 +1026,7 @@ sub provision($$$$$$)
 	path = $shrdir
 	comment = encrypt smb username is [%U]
 	smb encrypt = required
+	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 98472f8..64d74d5 100644
--- a/source3/modules/vfs_dirsort.c
+++ b/source3/modules/vfs_dirsort.c
@@ -30,38 +30,60 @@ static int compare_dirent (const struct dirent *da, const struct dirent *db)
 struct dirsort_privates {
 	long pos;
 	struct dirent *directory_list;
-	long number_of_entries;
-	time_t mtime;
+	unsigned int number_of_entries;
+	struct timespec mtime;
 	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;
+	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)
 {
-	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
@@ -69,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 = (struct dirent *)SMB_MALLOC(
-		data->number_of_entries * sizeof(struct dirent));
+	TALLOC_FREE(data->directory_list); /* destroy previous cache if needed */
+	data->directory_list = talloc_zero_array(data,
+					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++) {
+		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;
 }
@@ -92,33 +119,43 @@ static 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;
 }
 
@@ -130,37 +167,33 @@ static 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;
 }
 
@@ -169,21 +202,18 @@ static 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