[SCM] Samba Shared Repository - branch master updated
Jeremy Allison
jra at samba.org
Wed Feb 9 14:07:02 MST 2011
The branch, master has been updated
via 4ccb7e5 Oops. Need to test for if(!NT_STATUS_IS_OK(..)) for error.
via c377b0e Fix up some buildfarm warnings.
via 344e4cd Don't use asprintf in this library - breaks the build on many systems. Fake with malloc/memcpy.
via 8c363e9 Move to opening an fd on directory opens. Get more careful about symlink races.
via 65e6dea Remove unneeded stat call.
from be80812 s4:WAF build - remove "source4/configure.developer"
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 4ccb7e5bddd16c2b1cc7c057d8219c271ff5fe8c
Author: Jeremy Allison <jra at samba.org>
Date: Wed Feb 9 12:18:55 2011 -0800
Oops. Need to test for if(!NT_STATUS_IS_OK(..)) for error.
Autobuild-User: Jeremy Allison <jra at samba.org>
Autobuild-Date: Wed Feb 9 22:06:05 CET 2011 on sn-devel-104
commit c377b0e71893e2c054a179aa6e3f8c6742be0371
Author: Jeremy Allison <jra at samba.org>
Date: Wed Feb 9 10:43:56 2011 -0800
Fix up some buildfarm warnings.
commit 344e4cd2801805faf38b86f7f33b05e204452532
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.
commit 8c363e9252cfaeb1a7d30870e3a0d44cb9d8a39b
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 65e6dea73fe6b15171dfea5c620d37bab5e77483
Author: Jeremy Allison <jra at samba.org>
Date: Tue Feb 8 16:51:17 2011 -0800
Remove unneeded stat call.
-----------------------------------------------------------------------
Summary of changes:
source3/lib/dbwrap_util.c | 2 +-
source3/lib/system.c | 2 +-
source3/lib/util_str.c | 2 +-
source3/libsmb/cli_np_tstream.c | 2 +-
source3/libsmb/smb_share_modes.c | 11 ++++++--
source3/smbd/open.c | 51 ++++++++++++++++++++++++++++++-------
6 files changed, 53 insertions(+), 17 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c
index 8ebc4f4..0020fc6 100644
--- a/source3/lib/dbwrap_util.c
+++ b/source3/lib/dbwrap_util.c
@@ -118,7 +118,7 @@ static NTSTATUS dbwrap_change_uint32_atomic_action(struct db_context *db,
void *private_data)
{
struct db_record *rec;
- uint32 val = -1;
+ uint32_t val = (uint32_t)-1;
uint32_t v_store;
NTSTATUS ret;
struct dbwrap_change_uint32_atomic_context *state;
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 57434f2..1783fda 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -2716,7 +2716,7 @@ int sys_getnameinfo(const struct sockaddr *psa,
int sys_connect(int fd, const struct sockaddr * addr)
{
- socklen_t salen = -1;
+ socklen_t salen = (socklen_t)-1;
if (addr->sa_family == AF_INET) {
salen = sizeof(struct sockaddr_in);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index fcc4b8d..6edf64d 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -2020,7 +2020,7 @@ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
{
- uint64_t val = -1;
+ uint64_t val = (uint64_t)-1;
const char *p = nptr;
if (!p) {
diff --git a/source3/libsmb/cli_np_tstream.c b/source3/libsmb/cli_np_tstream.c
index 898b405..1f9e5ff 100644
--- a/source3/libsmb/cli_np_tstream.c
+++ b/source3/libsmb/cli_np_tstream.c
@@ -82,7 +82,7 @@ static int tstream_cli_np_destructor(struct tstream_cli_np *cli_nps)
* We can't do much on failure
*/
return 0;
-};
+}
struct tstream_cli_np_open_state {
struct cli_state *cli;
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..b6a75bb 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);
--
Samba Shared Repository
More information about the samba-cvs
mailing list