[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Sun Jun 19 04:41:02 MDT 2011


The branch, master has been updated
       via  bc3261f s3: Fix a memleak in name_resolve_bcast
       via  763941f s3: Test nttrans_create
       via  8e02b70 s3: Add incomplete cli_nttrans_create
       via  ef816f1 s3: Correctly align even
      from  36e674c s3: Allow NULL sd_size in make_sec_desc

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


- Log -----------------------------------------------------------------
commit bc3261f0c52847515bfdc35856f903c3be61c72e
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Jun 19 11:26:55 2011 +0200

    s3: Fix a memleak in name_resolve_bcast
    
    Autobuild-User: Volker Lendecke <vlendec at samba.org>
    Autobuild-Date: Sun Jun 19 12:40:55 CEST 2011 on sn-devel-104

commit 763941f2456f6c50581a1fa54aaba810a2b9efd1
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 18 09:56:12 2011 +0200

    s3: Test nttrans_create
    
    This is a test for the share security descriptor exception for nttrans_create

commit 8e02b70767be0d1e86059b0ecb9bd555896b48fd
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 18 09:10:30 2011 +0200

    s3: Add incomplete cli_nttrans_create
    
    secdesc only at this moment

commit ef816f1c4eb84b6ff72abc1106baf7ab3d53482b
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 18 19:30:52 2011 +0200

    s3: Correctly align even

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

Summary of changes:
 source3/Makefile.in                   |    1 +
 source3/libsmb/clifile.c              |  183 ++++++++++++++++++++++++++++++++-
 source3/libsmb/namequery.c            |   11 ++-
 source3/libsmb/proto.h                |   29 +++++
 source3/torture/proto.h               |    1 +
 source3/torture/test_nttrans_create.c |  108 +++++++++++++++++++
 source3/torture/torture.c             |    1 +
 source3/wscript_build                 |    1 +
 8 files changed, 330 insertions(+), 5 deletions(-)
 create mode 100644 source3/torture/test_nttrans_create.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 9140659..6c17947 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1232,6 +1232,7 @@ SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o torture/scanner.o torture/uta
 		torture/nbench.o \
 		torture/test_async_echo.o \
 		torture/test_smbsock_any_connect.o \
+		torture/test_nttrans_create.o \
 		torture/test_notify_online.o \
 		torture/test_addrchange.o \
 		torture/test_case_insensitive.o \
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 900c04a..88cecd5 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -26,6 +26,7 @@
 #include "libsmb/clirap.h"
 #include "trans2.h"
 #include "ntioctl.h"
+#include "libcli/security/secdesc.h"
 
 /***********************************************************
  Common function for pushing stings, used by smb_bytes_push_str()
@@ -48,7 +49,9 @@ static uint8_t *internal_bytes_push_str(uint8_t *buf, bool ucs2,
 
 	buflen = talloc_get_size(buf);
 
-	if (align_odd && ucs2 && (buflen % 2 == 0)) {
+	if (ucs2 &&
+	    ((align_odd && (buflen % 2 == 0)) ||
+	     (!align_odd && (buflen % 2 == 1)))) {
 		/*
 		 * We're pushing into an SMB buffer, align odd
 		 */
@@ -1904,6 +1907,184 @@ NTSTATUS cli_ntcreate(struct cli_state *cli,
 	return status;
 }
 
+struct cli_nttrans_create_state {
+	uint16_t fnum;
+};
+
+static void cli_nttrans_create_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_nttrans_create_send(TALLOC_CTX *mem_ctx,
+					   struct event_context *ev,
+					   struct cli_state *cli,
+					   const char *fname,
+					   uint32_t CreatFlags,
+					   uint32_t DesiredAccess,
+					   uint32_t FileAttributes,
+					   uint32_t ShareAccess,
+					   uint32_t CreateDisposition,
+					   uint32_t CreateOptions,
+					   uint8_t SecurityFlags,
+					   struct security_descriptor *secdesc,
+					   struct ea_struct *eas,
+					   int num_eas)
+{
+	struct tevent_req *req, *subreq;
+	struct cli_nttrans_create_state *state;
+	uint8_t *param;
+	uint8_t *secdesc_buf;
+	size_t secdesc_len;
+	NTSTATUS status;
+	size_t converted_len;
+
+	req = tevent_req_create(mem_ctx,
+				&state, struct cli_nttrans_create_state);
+	if (req == NULL) {
+		return NULL;
+	}
+
+	if (secdesc != NULL) {
+		status = marshall_sec_desc(talloc_tos(), secdesc,
+					   &secdesc_buf, &secdesc_len);
+		if (tevent_req_nterror(req, status)) {
+			DEBUG(10, ("marshall_sec_desc failed: %s\n",
+				   nt_errstr(status)));
+			return tevent_req_post(req, ev);
+		}
+	} else {
+		secdesc_buf = NULL;
+		secdesc_len = 0;
+	}
+
+	if (num_eas != 0) {
+		/*
+		 * TODO ;-)
+		 */
+		tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
+		return tevent_req_post(req, ev);
+	}
+
+	param = talloc_array(state, uint8_t, 53);
+	if (tevent_req_nomem(param, req)) {
+		return tevent_req_post(req, ev);
+	}
+
+	param = trans2_bytes_push_str(param, cli_ucs2(cli),
+				      fname, strlen(fname),
+				      &converted_len);
+	if (tevent_req_nomem(param, req)) {
+		return tevent_req_post(req, ev);
+	}
+
+	SIVAL(param, 0, CreatFlags);
+	SIVAL(param, 4, 0x0);	/* RootDirectoryFid */
+	SIVAL(param, 8, DesiredAccess);
+	SIVAL(param, 12, 0x0);	/* AllocationSize */
+	SIVAL(param, 16, 0x0);	/* AllocationSize */
+	SIVAL(param, 20, FileAttributes);
+	SIVAL(param, 24, ShareAccess);
+	SIVAL(param, 28, CreateDisposition);
+	SIVAL(param, 32, CreateOptions);
+	SIVAL(param, 36, secdesc_len);
+	SIVAL(param, 40, 0);	 /* EA length*/
+	SIVAL(param, 44, converted_len);
+	SIVAL(param, 48, 0x02); /* ImpersonationLevel */
+	SCVAL(param, 52, SecurityFlags);
+
+	subreq = cli_trans_send(state, ev, cli, SMBnttrans,
+				NULL, -1, /* name, fid */
+				NT_TRANSACT_CREATE, 0,
+				NULL, 0, 0, /* setup */
+				param, talloc_get_size(param), 128, /* param */
+				secdesc_buf, secdesc_len, 0); /* data */
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, cli_nttrans_create_done, req);
+	return req;
+}
+
+static void cli_nttrans_create_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_nttrans_create_state *state = tevent_req_data(
+		req, struct cli_nttrans_create_state);
+	uint8_t *param;
+	uint32_t num_param;
+	NTSTATUS status;
+
+	status = cli_trans_recv(subreq, talloc_tos(), NULL,
+				NULL, 0, NULL, /* rsetup */
+				&param, 69, &num_param,
+				NULL, 0, NULL);
+	if (tevent_req_nterror(req, status)) {
+		return;
+	}
+	state->fnum = SVAL(param, 2);
+	TALLOC_FREE(param);
+	tevent_req_done(req);
+}
+
+NTSTATUS cli_nttrans_create_recv(struct tevent_req *req, uint16_t *fnum)
+{
+	struct cli_nttrans_create_state *state = tevent_req_data(
+		req, struct cli_nttrans_create_state);
+	NTSTATUS status;
+
+	if (tevent_req_is_nterror(req, &status)) {
+		return status;
+	}
+	*fnum = state->fnum;
+	return NT_STATUS_OK;
+}
+
+NTSTATUS cli_nttrans_create(struct cli_state *cli,
+			    const char *fname,
+			    uint32_t CreatFlags,
+			    uint32_t DesiredAccess,
+			    uint32_t FileAttributes,
+			    uint32_t ShareAccess,
+			    uint32_t CreateDisposition,
+			    uint32_t CreateOptions,
+			    uint8_t SecurityFlags,
+			    struct security_descriptor *secdesc,
+			    struct ea_struct *eas,
+			    int num_eas,
+			    uint16_t *pfid)
+{
+	TALLOC_CTX *frame = talloc_stackframe();
+	struct event_context *ev;
+	struct tevent_req *req;
+	NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+	if (cli_has_async_calls(cli)) {
+		/*
+		 * Can't use sync call while an async call is in flight
+		 */
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto fail;
+	}
+	ev = event_context_init(frame);
+	if (ev == NULL) {
+		goto fail;
+	}
+	req = cli_nttrans_create_send(frame, ev, cli, fname, CreatFlags,
+				      DesiredAccess, FileAttributes,
+				      ShareAccess, CreateDisposition,
+				      CreateOptions, SecurityFlags,
+				      secdesc, eas, num_eas);
+	if (req == NULL) {
+		goto fail;
+	}
+	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+		goto fail;
+	}
+	status = cli_nttrans_create_recv(req, pfid);
+ fail:
+	TALLOC_FREE(frame);
+	return status;
+}
+
 /****************************************************************************
  Open a file
  WARNING: if you open with O_WRONLY then getattrE won't work!
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index dc062fb..988840a 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -1768,6 +1768,7 @@ NTSTATUS name_resolve_bcast(const char *name,
 {
 	struct sockaddr_storage *bcast_addrs;
 	int i, num_addrs, num_bcast_addrs;
+	NTSTATUS status;
 
 	if (lp_disable_netbios()) {
 		DEBUG(5,("name_resolve_bcast(%s#%02x): netbios is disabled\n",
@@ -1805,10 +1806,12 @@ NTSTATUS name_resolve_bcast(const char *name,
 		num_bcast_addrs += 1;
 	}
 
-	return name_queries(name, name_type, true, true,
-			    bcast_addrs, num_bcast_addrs, 0, 1000,
-			    mem_ctx, return_iplist, return_count,
-			    NULL, NULL);
+	status = name_queries(name, name_type, true, true,
+			      bcast_addrs, num_bcast_addrs, 0, 1000,
+			      mem_ctx, return_iplist, return_count,
+			      NULL, NULL);
+	TALLOC_FREE(bcast_addrs);
+	return status;
 }
 
 struct query_wins_list_state {
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index 5166ef3..f88a891 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -557,6 +557,35 @@ NTSTATUS cli_notify_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 			 uint32_t *pnum_changes,
 			 struct notify_change **pchanges);
 
+struct tevent_req *cli_nttrans_create_send(TALLOC_CTX *mem_ctx,
+					   struct event_context *ev,
+					   struct cli_state *cli,
+					   const char *fname,
+					   uint32_t CreatFlags,
+					   uint32_t DesiredAccess,
+					   uint32_t FileAttributes,
+					   uint32_t ShareAccess,
+					   uint32_t CreateDisposition,
+					   uint32_t CreateOptions,
+					   uint8_t SecurityFlags,
+					   struct security_descriptor *secdesc,
+					   struct ea_struct *eas,
+					   int num_eas);
+NTSTATUS cli_nttrans_create_recv(struct tevent_req *req, uint16_t *fnum);
+NTSTATUS cli_nttrans_create(struct cli_state *cli,
+			    const char *fname,
+			    uint32_t CreatFlags,
+			    uint32_t DesiredAccess,
+			    uint32_t FileAttributes,
+			    uint32_t ShareAccess,
+			    uint32_t CreateDisposition,
+			    uint32_t CreateOptions,
+			    uint8_t SecurityFlags,
+			    struct security_descriptor *secdesc,
+			    struct ea_struct *eas,
+			    int num_eas,
+			    uint16_t *pfid);
+
 /* The following definitions come from libsmb/clifsinfo.c  */
 
 struct tevent_req *cli_unix_extensions_version_send(TALLOC_CTX *mem_ctx,
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index ebaf6cf..6a47a18 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -90,5 +90,6 @@ bool run_async_echo(int dummy);
 bool run_smb_any_connect(int dummy);
 bool run_addrchange(int dummy);
 bool run_notify_online(int dummy);
+bool run_nttrans_create(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_nttrans_create.c b/source3/torture/test_nttrans_create.c
new file mode 100644
index 0000000..9869f02
--- /dev/null
+++ b/source3/torture/test_nttrans_create.c
@@ -0,0 +1,108 @@
+/*
+   Unix SMB/CIFS implementation.
+   Basic test for share secdescs vs nttrans_create
+   Copyright (C) Volker Lendecke 2011
+
+   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"
+#include "torture/proto.h"
+#include "libsmb/libsmb.h"
+#include "libcli/security/dom_sid.h"
+#include "libcli/security/secdesc.h"
+#include "libcli/security/security.h"
+
+bool run_nttrans_create(int dummy)
+{
+	struct cli_state *cli = NULL;
+	NTSTATUS status, status2;
+	bool ret = false;
+	struct security_ace ace;
+	struct security_acl acl;
+	struct security_descriptor *sd;
+	const char *fname = "transtest";
+	uint16_t fnum, fnum2;
+	struct dom_sid owner;
+
+	printf("Starting NTTRANS_CREATE\n");
+
+	if (!torture_open_connection(&cli, 0)) {
+		printf("torture_open_connection failed\n");
+		goto fail;
+	}
+
+	ZERO_STRUCT(ace);
+	ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
+	ace.access_mask = SEC_RIGHTS_FILE_ALL & ~SEC_STD_WRITE_DAC;
+	sid_copy(&ace.trustee, &global_sid_World);
+
+	acl.revision = SECURITY_ACL_REVISION_NT4;
+	acl.size = 0;
+	acl.num_aces = 1;
+	acl.aces = &ace;
+
+	dom_sid_parse("S-1-22-1-1000", &owner);
+
+	sd = make_sec_desc(talloc_tos(),
+			   SECURITY_DESCRIPTOR_REVISION_1,
+			   SEC_DESC_SELF_RELATIVE|
+			   SEC_DESC_DACL_PRESENT|SEC_DESC_OWNER_DEFAULTED|
+			   SEC_DESC_GROUP_DEFAULTED,
+			   NULL, NULL, NULL, &acl, NULL);
+	if (sd == NULL) {
+		d_fprintf(stderr, "make_sec_desc failed\n");
+		goto fail;
+	}
+
+	status = cli_nttrans_create(
+		cli, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS|
+		READ_CONTROL_ACCESS,
+		FILE_ATTRIBUTE_NORMAL,
+		FILE_SHARE_READ|FILE_SHARE_WRITE| FILE_SHARE_DELETE,
+		FILE_CREATE, 0, 0, sd, NULL, 0, &fnum);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "cli_nttrans_create returned %s\n",
+			  nt_errstr(status));
+		goto fail;
+	}
+
+	cli_query_secdesc(cli, fnum, talloc_tos());
+
+	status2 = cli_ntcreate(cli, fname, 0, WRITE_DAC_ACCESS,
+			       FILE_ATTRIBUTE_NORMAL,
+			       FILE_SHARE_READ|FILE_SHARE_WRITE|
+			       FILE_SHARE_DELETE,
+			       FILE_OPEN, 0, 0, &fnum2);
+
+	status = cli_nt_delete_on_close(cli, fnum, true);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "cli_nt_delete_on_close returned %s\n",
+			  nt_errstr(status));
+		goto fail;
+	}
+
+	if (!NT_STATUS_EQUAL(status2, NT_STATUS_ACCESS_DENIED)) {
+		d_fprintf(stderr, "cli_ntcreate returned %s\n",
+			  nt_errstr(status));
+		goto fail;
+	}
+
+	ret = true;
+fail:
+	if (cli != NULL) {
+		torture_close_connection(cli);
+	}
+	return ret;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 8512a0e..0731326 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -8636,6 +8636,7 @@ static struct {
 	{ "CHAIN1", run_chain1, 0},
 	{ "CHAIN2", run_chain2, 0},
 	{ "WINDOWS-WRITE", run_windows_write, 0},
+	{ "NTTRANS-CREATE", run_nttrans_create, 0},
 	{ "CLI_ECHO", run_cli_echo, 0},
 	{ "GETADDRINFO", run_getaddrinfo_send, 0},
 	{ "TLDAP", run_tldap },
diff --git a/source3/wscript_build b/source3/wscript_build
index 9017215..99e8d95 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -563,6 +563,7 @@ SMBTORTURE_SRC1 = '''torture/torture.c torture/nbio.c torture/scanner.c torture/
                 torture/test_async_echo.c
                 torture/test_addrchange.c
                 torture/test_posix_append.c
+		torture/test_nttrans_create.c
 		torture/test_case_insensitive.c
 		torture/test_notify_online.c
                 torture/test_smbsock_any_connect.c'''


-- 
Samba Shared Repository


More information about the samba-cvs mailing list