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

Jeremy Allison jra at samba.org
Wed Feb 9 11:31:56 MST 2011


The branch, v3-6-test has been updated
       via  127691c Don't use asprintf in this library - breaks the build on many systems. Fake with malloc/memcpy. (cherry picked from commit 8d0c16a68bac7c75b4b637c6d6e3377c5461e5d4)
       via  bd01d86 Move to opening an fd on directory opens. Get more careful about symlink races.
       via  bf48da1 Remove unneeded stat call.
       via  3691538 tevent: Fix typos
       via  f35ecd0 dlinklist: Change license to LGPLv3+ (checked with tridge).(cherry picked from commit d2740976cde8b875c91cff311a688e8a10e4bf30)
      from  2dd37f6 s3-rpc_server: We need a messaging context for rpc.

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


- Log -----------------------------------------------------------------
commit 127691c1b76e9be52b7cf016a2b7f26961ad0d8a
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Feb 9 10:28:08 2011 -0800

    Don't use asprintf in this library - breaks the build on many systems. Fake with malloc/memcpy.
    (cherry picked from commit 8d0c16a68bac7c75b4b637c6d6e3377c5461e5d4)

commit bd01d8638f49714541913922a22e39af66068e8e
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Feb 8 17:04:19 2011 -0800

    Move to opening an fd on directory opens. Get more careful about symlink races.

commit bf48da1c6c4fc67fd8db9277594e4edd34f7deb0
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Feb 8 16:51:17 2011 -0800

    Remove unneeded stat call.

commit 36915388da90b4e5f71ba40936c34391a8c16a83
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Feb 9 15:50:34 2011 +0100

    tevent: Fix typos
    
    Autobuild-User: Volker Lendecke <vlendec at samba.org>
    Autobuild-Date: Wed Feb  9 18:13:18 CET 2011 on sn-devel-104
    (cherry picked from commit dcd6764dad7ec636201faf724b011cf03edd4beb)

commit f35ecd0986704850a18a500ce6636266c5010528
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Jan 30 10:59:14 2011 +0100

    dlinklist: Change license to LGPLv3+ (checked with tridge).(cherry picked from commit d2740976cde8b875c91cff311a688e8a10e4bf30)

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

Summary of changes:
 lib/tevent/tevent_timed.c           |    4 +-
 source3/libsmb/smb_share_modes.c    |   11 +++++--
 source3/smbd/open.c                 |   51 ++++++++++++++++++++++++++++-------
 source4/lib/ldb/include/dlinklist.h |   26 ++++++++++-------
 4 files changed, 66 insertions(+), 26 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c
index cc51bf6..f7c3969 100644
--- a/lib/tevent/tevent_timed.c
+++ b/lib/tevent/tevent_timed.c
@@ -197,7 +197,7 @@ struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev, TALLOC_C
 /*
   do a single event loop using the events defined in ev
 
-  return the delay untill the next timed event,
+  return the delay until the next timed event,
   or zero if a timed event was triggered
 */
 struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev)
@@ -208,7 +208,7 @@ struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev)
 	if (!te) {
 		/* have a default tick time of 30 seconds. This guarantees
 		   that code that uses its own timeout checking will be
-		   able to proceeed eventually */
+		   able to proceed eventually */
 		return tevent_timeval_set(30, 0);
 	}
 
diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c
index 3174500..e752f61 100644
--- a/source3/libsmb/smb_share_modes.c
+++ b/source3/libsmb/smb_share_modes.c
@@ -267,15 +267,20 @@ static uint32_t smb_name_hash(const char *sharepath, const char *filename, int *
 {
 	TDB_DATA key;
 	char *fullpath = NULL;
-	int ret;
+	size_t sharepath_size = strlen(sharepath);
+	size_t filename_size = strlen(filename);
 	uint32_t name_hash;
 
 	*err = 0;
-	ret = asprintf(&fullpath, "%s/%s", sharepath, filename);
-	if (ret == -1) {
+	fullpath = malloc(sharepath_size + filename_size + 2);
+	if (fullpath == NULL) {
 		*err = 1;
 		return 0;
 	}
+	memcpy(fullpath, sharepath, sharepath_size);
+	fullpath[sharepath_size] = '/';
+	memcpy(&fullpath[sharepath_size + 1], filename, filename_size + 1);
+
 	key.dptr = (uint8_t *)fullpath;
 	key.dsize = strlen(fullpath) + 1;
 	name_hash = tdb_jenkins_hash(&key);
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index a9a12ea..89d1375 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2525,6 +2525,22 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
 }
 
 /****************************************************************************
+ Ensure we didn't get symlink raced on opening a directory.
+****************************************************************************/
+
+static bool check_same_stat(const SMB_STRUCT_STAT *sbuf1,
+			const SMB_STRUCT_STAT *sbuf2)
+{
+	if (sbuf1->st_ex_uid != sbuf2->st_ex_uid ||
+			sbuf1->st_ex_gid != sbuf2->st_ex_gid ||
+			sbuf1->st_ex_dev != sbuf2->st_ex_dev ||
+			sbuf1->st_ex_ino != sbuf2->st_ex_ino) {
+		return false;
+	}
+	return true;
+}
+
+/****************************************************************************
  Open a directory from an NT SMB call.
 ****************************************************************************/
 
@@ -2591,16 +2607,11 @@ static NTSTATUS open_directory(connection_struct *conn,
 	switch( create_disposition ) {
 		case FILE_OPEN:
 
-			info = FILE_WAS_OPENED;
-
-			/*
-			 * We want to follow symlinks here.
-			 */
-
-			if (SMB_VFS_STAT(conn, smb_dname) != 0) {
-				return map_nt_error_from_unix(errno);
+			if (!dir_existed) {
+				return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 			}
-				
+
+			info = FILE_WAS_OPENED;
 			break;
 
 		case FILE_CREATE:
@@ -2731,6 +2742,10 @@ static NTSTATUS open_directory(connection_struct *conn,
 
 #ifdef O_DIRECTORY
 	status = fd_open(conn, fsp, O_RDONLY|O_DIRECTORY, 0);
+#else
+	/* POSIX allows us to open a directory with O_RDONLY. */
+	status = fd_open(conn, fsp, O_RDONLY, 0);
+#endif
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(5, ("open_directory: Could not open fd for "
 			"%s (%s)\n",
@@ -2739,7 +2754,23 @@ static NTSTATUS open_directory(connection_struct *conn,
 		file_free(req, fsp);
 		return status;
 	}
-#endif
+
+	status = vfs_stat_fsp(fsp);
+	if (NT_STATUS_IS_OK(status)) {
+		fd_close(fsp);
+		file_free(req, fsp);
+		return status;
+	}
+
+	/* Ensure there was no race condition. */
+	if (!check_same_stat(&smb_dname->st, &fsp->fsp_name->st)) {
+		DEBUG(5,("open_directory: stat struct differs for "
+			"directory %s.\n",
+			smb_fname_str_dbg(smb_dname)));
+		fd_close(fsp);
+		file_free(req, fsp);
+		return NT_STATUS_ACCESS_DENIED;
+	}
 
 	lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
 				  conn->connectpath, smb_dname, &mtimespec);
diff --git a/source4/lib/ldb/include/dlinklist.h b/source4/lib/ldb/include/dlinklist.h
index 6d525f9..1c577bb 100644
--- a/source4/lib/ldb/include/dlinklist.h
+++ b/source4/lib/ldb/include/dlinklist.h
@@ -3,19 +3,23 @@
    some simple double linked list macros
 
    Copyright (C) Andrew Tridgell 1998-2010
+
+     ** NOTE! The following LGPL license applies to the ldb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
    
-   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,
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library 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/>.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
 /* To use these macros you must have a structure containing a next and


-- 
Samba Shared Repository


More information about the samba-cvs mailing list