[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Tue Jun 18 14:48:03 UTC 2019


The branch, master has been updated
       via  80f648b1695 smbd: Deprecate "blocking locks" parameter
       via  7dce1d3eebd smbd: Slightly simplify smb_set_posix_lock()
       via  8d4f7e564ff smbd: Add a explanation for num_aio_requests
       via  a5b1897397e smbd: Align integer types in reply_lockingX
       via  d8c75ec734f smbd: Avoid casts
       via  beeb9d51c6f smbtorture: Match comment with test
       via  70e77acb7c5 smbd: Fix a typo
       via  8cfb37010fd smbd: smbd_do_locking() does not use the "type" param anymore
       via  e335b87503e smbd: Simplify smbd_do_locking()
       via  fbe9ec63802 smbd: Slightly simplify reply_lockingX()
       via  8e2b40baadc smbd: Slightly simplify reply_lockingX()
       via  ebe2ceb3d9c smbd: Slightly simplify reply_lockingX()
       via  22aeb005d97 libsmb: Use cli_lockingx() in cli_unlock()
       via  5211f6afdff libsmb: Use cli_lockingx() in cli_locktype()
       via  25c7b92fc2a libsmb: Use cli_lockingx() in cli_oplock_ack()
       via  cc69f49cbab libsmb: Add async cli_lockingx()
       via  a8301bfbe88 libsmb: Remove unused is_andx_req
       via  888bff50acc smbd: Use smb1cli_is_andx_req()
       via  aec8b4a2a92 libsmb: Remove unused cli_[un]lock64()
       via  52096b498d1 libsmb: Align integer types
       via  c9a7754c887 smbd: Avoid a "?true:false" in smbd_do_locking
      from  3a0fd53f7c3 lib/replace: Remove #undef TCP_NODELAY

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


- Log -----------------------------------------------------------------
commit 80f648b1695b1e3ef3c6e97f3def2694d219a5ff
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jun 13 12:21:09 2019 -0700

    smbd: Deprecate "blocking locks" parameter
    
    This parameter adds complexity to our brlock implementation that I don't think
    is justified. Not a lot of complexity, but if we would want to really support
    it we'd need tests. Instead of doing those, I think removing the parameter is
    the better choice.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Tue Jun 18 14:47:08 UTC 2019 on sn-devel-184

commit 7dce1d3eebdc3e2e61a40decb975dc3de361a306
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jun 11 05:04:39 2019 -0700

    smbd: Slightly simplify smb_set_posix_lock()
    
    Avoid indentation by an early return;
    
    Best viewed with git show -b
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 8d4f7e564ff299545008bbf3227bb6c27a66a6c7
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 3 13:41:30 2019 +0200

    smbd: Add a explanation for num_aio_requests
    
    We could have used talloc_array_length()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a5b1897397e30b1875d8fac2016581fe72bb8597
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 3 11:16:33 2019 +0200

    smbd: Align integer types in reply_lockingX
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit d8c75ec734f0b4be0ab5d8a1b8f69afdc09ef7ba
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 3 21:31:26 2019 +0200

    smbd: Avoid casts
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit beeb9d51c6f8ae6d9ae9738d3cda1398d1b08ed5
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Jun 2 12:50:50 2019 +0200

    smbtorture: Match comment with test
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 70e77acb7c50667de5ca0149580d34323efc21a4
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 1 14:46:55 2019 +0200

    smbd: Fix a typo
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 8cfb37010fdb4c8dc0fc29cc72cf21063b7d534d
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 3 11:34:51 2019 +0200

    smbd: smbd_do_locking() does not use the "type" param anymore
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit e335b87503ea7f12e012d2aec84cd2946d71c161
Author: Volker Lendecke <vl at samba.org>
Date:   Fri May 31 12:19:25 2019 +0200

    smbd: Simplify smbd_do_locking()
    
    LOCKING_ANDX_CANCEL_LOCK only is used in SMB1. Move its handling out
    of the shared smb1/smb2 code.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit fbe9ec63802931edfb485c93fea56c6b4aa54f0b
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 11:42:16 2019 +0200

    smbd: Slightly simplify reply_lockingX()
    
    Make the data dependencies more obvious. "locks" and "ulocks" are used
    only for short time spans. Any sane compiler will coalesce them to
    just one stack variable.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 8e2b40baadc750a78488227c1d99aa261793354f
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 11:39:10 2019 +0200

    smbd: Slightly simplify reply_lockingX()
    
    The brltype only depends upon the central locktype, don't calculate it
    every time in the loop parsing the lock requests
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit ebe2ceb3d9cd1d89cb6f5047e105b9b0dc368a5b
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 11:31:56 2019 +0200

    smbd: Slightly simplify reply_lockingX()
    
    Don't do an "else" after an early return
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 22aeb005d971dc9929dfd58fe7c943fbfedbe723
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 09:52:22 2019 +0200

    libsmb: Use cli_lockingx() in cli_unlock()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 5211f6afdff4dc5031556b43e02cd054b748ea18
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 09:42:36 2019 +0200

    libsmb: Use cli_lockingx() in cli_locktype()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 25c7b92fc2a7b3545646fc3ae491f554c7c8f556
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 09:25:41 2019 +0200

    libsmb: Use cli_lockingx() in cli_oplock_ack()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit cc69f49cbabf4717428e20bfffd8ea6047134865
Author: Volker Lendecke <vl at samba.org>
Date:   Wed May 29 17:45:19 2019 +0200

    libsmb: Add async cli_lockingx()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a8301bfbe8885df60317e0a7765baf0f96588803
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 10:02:47 2019 +0200

    libsmb: Remove unused is_andx_req
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 888bff50accb89949101a71f766bec9853524509
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 10:01:34 2019 +0200

    smbd: Use smb1cli_is_andx_req()
    
    We have two implementations of this -- use the one from common libs
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit aec8b4a2a92ac4a53ab92e54fcc87179859bf116
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 09:55:30 2019 +0200

    libsmb: Remove unused cli_[un]lock64()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 52096b498d144e66b926d7401513e70a1114760c
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 30 09:55:11 2019 +0200

    libsmb: Align integer types
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit c9a7754c887f8ba41754fcc5b0ab53092cbf6dcf
Author: Volker Lendecke <vl at samba.org>
Date:   Sun May 26 10:59:01 2019 +0200

    smbd: Avoid a "?true:false" in smbd_do_locking
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 docs-xml/smbdotconf/locking/blockinglocks.xml |   1 +
 source3/include/vfs.h                         |   4 +
 source3/libsmb/clidfs.c                       |   2 +-
 source3/libsmb/clientgen.c                    |  25 --
 source3/libsmb/clifile.c                      | 430 ++++++++++++++------------
 source3/libsmb/clioplock.c                    |  41 +--
 source3/libsmb/proto.h                        |  55 +++-
 source3/smbd/blocking.c                       |   3 +-
 source3/smbd/globals.h                        |   1 -
 source3/smbd/process.c                        |  14 +-
 source3/smbd/reply.c                          | 201 ++++++------
 source3/smbd/smb2_lock.c                      |   4 +-
 source3/smbd/trans2.c                         |  69 +++--
 source4/torture/raw/lock.c                    |   2 +-
 14 files changed, 439 insertions(+), 413 deletions(-)


Changeset truncated at 500 lines:

diff --git a/docs-xml/smbdotconf/locking/blockinglocks.xml b/docs-xml/smbdotconf/locking/blockinglocks.xml
index 2794124ba59..3c13995d739 100644
--- a/docs-xml/smbdotconf/locking/blockinglocks.xml
+++ b/docs-xml/smbdotconf/locking/blockinglocks.xml
@@ -1,6 +1,7 @@
 <samba:parameter name="blocking locks"
                  context="S"
                  type="boolean"
+                 deprecated="1"
                  xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
 <description>
 	<para>This parameter controls the behavior 
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 8c35fa5ecc7..10d7fb0621a 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -378,6 +378,10 @@ typedef struct files_struct {
 	/* if not NULL, means this is a print file */
 	struct print_file_data *print_file;
 
+	/*
+	 * Optimize the aio_requests array for high performance: Never
+	 * shrink it, maintain num_aio_requests separately
+	 */
 	unsigned num_aio_requests;
 	struct tevent_req **aio_requests;
 
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index 4342a3b1d1b..f617307bb03 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -901,7 +901,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
 	int pathlen;
 	struct cli_state *newcli = NULL;
 	struct cli_state *ccli = NULL;
-	int count = 0;
+	size_t count = 0;
 	char *newpath = NULL;
 	char *newmount = NULL;
 	char *ppath = NULL;
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 2e4dd15ab62..6c946ff17d6 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -585,31 +585,6 @@ NTSTATUS cli_echo(struct cli_state *cli, uint16_t num_echos, DATA_BLOB data)
 	return status;
 }
 
-/**
- * Is the SMB command able to hold an AND_X successor
- * @param[in] cmd	The SMB command in question
- * @retval Can we add a chained request after "cmd"?
- */
-bool is_andx_req(uint8_t cmd)
-{
-	switch (cmd) {
-	case SMBtconX:
-	case SMBlockingX:
-	case SMBopenX:
-	case SMBreadX:
-	case SMBwriteX:
-	case SMBsesssetupX:
-	case SMBulogoffX:
-	case SMBntcreateX:
-		return true;
-		break;
-	default:
-		break;
-	}
-
-	return false;
-}
-
 NTSTATUS cli_smb(TALLOC_CTX *mem_ctx, struct cli_state *cli,
 		 uint8_t smb_command, uint8_t additional_flags,
 		 uint8_t wct, uint16_t *vwv,
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index b0d02395273..3738904f894 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -3405,246 +3405,273 @@ NTSTATUS cli_ftruncate(struct cli_state *cli, uint16_t fnum, uint64_t size)
 	return status;
 }
 
-/****************************************************************************
- send a lock with a specified locktype
- this is used for testing LOCKING_ANDX_CANCEL_LOCK
-****************************************************************************/
-
-NTSTATUS cli_locktype(struct cli_state *cli, uint16_t fnum,
-		      uint32_t offset, uint32_t len,
-		      int timeout, unsigned char locktype)
-{
-	uint16_t vwv[8];
-	uint8_t bytes[10];
-	NTSTATUS status;
-	unsigned int set_timeout = 0;
-	unsigned int saved_timeout = 0;
-
-	SCVAL(vwv + 0, 0, 0xff);
-	SCVAL(vwv + 0, 1, 0);
-	SSVAL(vwv + 1, 0, 0);
-	SSVAL(vwv + 2, 0, fnum);
-	SCVAL(vwv + 3, 0, locktype);
-	SCVAL(vwv + 3, 1, 0);
-	SIVALS(vwv + 4, 0, timeout);
-	SSVAL(vwv + 6, 0, 0);
-	SSVAL(vwv + 7, 0, 1);
-
-	SSVAL(bytes, 0, cli_getpid(cli));
-	SIVAL(bytes, 2, offset);
-	SIVAL(bytes, 6, len);
-
-	if (timeout != 0) {
-		if (timeout == -1) {
-			set_timeout = 0x7FFFFFFF;
+static uint8_t *cli_lockingx_put_locks(
+	uint8_t *buf,
+	bool large,
+	uint16_t num_locks,
+	const struct smb1_lock_element *locks)
+{
+	uint16_t i;
+
+	for (i=0; i<num_locks; i++) {
+		const struct smb1_lock_element *e = &locks[i];
+		if (large) {
+			SSVAL(buf, 0, e->pid);
+			SSVAL(buf, 2, 0);
+			SOFF_T_R(buf, 4, e->offset);
+			SOFF_T_R(buf, 12, e->length);
+			buf += 20;
 		} else {
-			set_timeout = timeout + 2*1000;
+			SSVAL(buf, 0, e->pid);
+			SIVAL(buf, 2, e->offset);
+			SIVAL(buf, 6, e->length);
+			buf += 10;
 		}
-		saved_timeout = cli_set_timeout(cli, set_timeout);
 	}
-
-	status = cli_smb(talloc_tos(), cli, SMBlockingX, 0, 8, vwv,
-			 10, bytes, NULL, 0, NULL, NULL, NULL, NULL);
-
-	if (saved_timeout != 0) {
-		cli_set_timeout(cli, saved_timeout);
-	}
-
-	return status;
-}
-
-/****************************************************************************
- Lock a file.
- note that timeout is in units of 2 milliseconds
-****************************************************************************/
-
-NTSTATUS cli_lock32(struct cli_state *cli, uint16_t fnum,
-		  uint32_t offset, uint32_t len, int timeout,
-		  enum brl_type lock_type)
-{
-	NTSTATUS status;
-
-	status = cli_locktype(cli, fnum, offset, len, timeout,
-			      (lock_type == READ_LOCK? 1 : 0));
-	return status;
+	return buf;
 }
 
-/****************************************************************************
- Unlock a file.
-****************************************************************************/
-
-struct cli_unlock_state {
+struct cli_lockingx_state {
 	uint16_t vwv[8];
-	uint8_t data[10];
+	struct iovec bytes;
 };
 
-static void cli_unlock_done(struct tevent_req *subreq);
-
-struct tevent_req *cli_unlock_send(TALLOC_CTX *mem_ctx,
-				struct tevent_context *ev,
-				struct cli_state *cli,
-				uint16_t fnum,
-				uint64_t offset,
-				uint64_t len)
+static void cli_lockingx_done(struct tevent_req *subreq);
 
+struct tevent_req *cli_lockingx_create(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	struct cli_state *cli,
+	uint16_t fnum,
+	uint8_t typeoflock,
+	uint8_t newoplocklevel,
+	int32_t timeout,
+	uint16_t num_unlocks,
+	const struct smb1_lock_element *unlocks,
+	uint16_t num_locks,
+	const struct smb1_lock_element *locks,
+	struct tevent_req **psmbreq)
 {
 	struct tevent_req *req = NULL, *subreq = NULL;
-	struct cli_unlock_state *state = NULL;
-	uint8_t additional_flags = 0;
+	struct cli_lockingx_state *state = NULL;
+	uint16_t *vwv;
+	uint8_t *p;
+	const bool large = (typeoflock & LOCKING_ANDX_LARGE_FILES);
+	const size_t element_len = large ? 20 : 10;
 
-	req = tevent_req_create(mem_ctx, &state, struct cli_unlock_state);
+	/* uint16->size_t, no overflow */
+	const size_t num_elements = (size_t)num_locks + (size_t)num_unlocks;
+
+	/* at most 20*2*65535 = 2621400, no overflow */
+	const size_t num_bytes = num_elements * element_len;
+
+	req = tevent_req_create(mem_ctx, &state, struct cli_lockingx_state);
 	if (req == NULL) {
 		return NULL;
 	}
+	vwv = state->vwv;
 
-	SCVAL(state->vwv+0, 0, 0xFF);
-	SSVAL(state->vwv+2, 0, fnum);
-	SCVAL(state->vwv+3, 0, 0);
-	SIVALS(state->vwv+4, 0, 0);
-	SSVAL(state->vwv+6, 0, 1);
-	SSVAL(state->vwv+7, 0, 0);
+	SCVAL(vwv + 0, 0, 0xFF);
+	SCVAL(vwv + 0, 1, 0);
+	SSVAL(vwv + 1, 0, 0);
+	SSVAL(vwv + 2, 0, fnum);
+	SCVAL(vwv + 3, 0, typeoflock);
+	SCVAL(vwv + 3, 1, newoplocklevel);
+	SIVALS(vwv + 4, 0, timeout);
+	SSVAL(vwv + 6, 0, num_unlocks);
+	SSVAL(vwv + 7, 0, num_locks);
+
+	state->bytes.iov_len = num_bytes;
+	state->bytes.iov_base = talloc_array(state, uint8_t, num_bytes);
+	if (tevent_req_nomem(state->bytes.iov_base, req)) {
+		return tevent_req_post(req, ev);
+	}
 
-	SSVAL(state->data, 0, cli_getpid(cli));
-	SIVAL(state->data, 2, offset);
-	SIVAL(state->data, 6, len);
+	p = cli_lockingx_put_locks(
+		state->bytes.iov_base, large, num_unlocks, unlocks);
+	cli_lockingx_put_locks(p, large, num_locks, locks);
 
-	subreq = cli_smb_send(state, ev, cli, SMBlockingX, additional_flags, 0,
-				8, state->vwv, 10, state->data);
+	subreq = cli_smb_req_create(
+		state, ev, cli, SMBlockingX, 0, 0, 8, vwv, 1, &state->bytes);
 	if (tevent_req_nomem(subreq, req)) {
 		return tevent_req_post(req, ev);
 	}
-	tevent_req_set_callback(subreq, cli_unlock_done, req);
+	tevent_req_set_callback(subreq, cli_lockingx_done, req);
+	*psmbreq = subreq;
 	return req;
 }
 
-static void cli_unlock_done(struct tevent_req *subreq)
+struct tevent_req *cli_lockingx_send(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	struct cli_state *cli,
+	uint16_t fnum,
+	uint8_t typeoflock,
+	uint8_t newoplocklevel,
+	int32_t timeout,
+	uint16_t num_unlocks,
+	const struct smb1_lock_element *unlocks,
+	uint16_t num_locks,
+	const struct smb1_lock_element *locks)
 {
-	struct tevent_req *req = tevent_req_callback_data(
-				subreq, struct tevent_req);
+	struct tevent_req *req = NULL, *subreq = NULL;
 	NTSTATUS status;
 
-	status = cli_smb_recv(subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL);
-	TALLOC_FREE(subreq);
+	req = cli_lockingx_create(
+		mem_ctx,
+		ev,
+		cli,
+		fnum,
+		typeoflock,
+		newoplocklevel,
+		timeout,
+		num_unlocks,
+		unlocks,
+		num_locks,
+		locks,
+		&subreq);
+	if (req == NULL) {
+		return NULL;
+	}
+
+	status = smb1cli_req_chain_submit(&subreq, 1);
 	if (tevent_req_nterror(req, status)) {
-		return;
+		return tevent_req_post(req, ev);
 	}
-	tevent_req_done(req);
+	return req;
 }
 
-NTSTATUS cli_unlock_recv(struct tevent_req *req)
+static void cli_lockingx_done(struct tevent_req *subreq)
+{
+	NTSTATUS status = cli_smb_recv(
+		subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL);
+	tevent_req_simple_finish_ntstatus(subreq, status);
+}
+
+NTSTATUS cli_lockingx_recv(struct tevent_req *req)
 {
 	return tevent_req_simple_recv_ntstatus(req);
 }
 
-NTSTATUS cli_unlock(struct cli_state *cli,
-			uint16_t fnum,
-			uint32_t offset,
-			uint32_t len)
+NTSTATUS cli_lockingx(
+	struct cli_state *cli,
+	uint16_t fnum,
+	uint8_t typeoflock,
+	uint8_t newoplocklevel,
+	int32_t timeout,
+	uint16_t num_unlocks,
+	const struct smb1_lock_element *unlocks,
+	uint16_t num_locks,
+	const struct smb1_lock_element *locks)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
-	struct tevent_context *ev;
-	struct tevent_req *req;
-	NTSTATUS status = NT_STATUS_OK;
+	struct tevent_context *ev = NULL;
+	struct tevent_req *req = NULL;
+	NTSTATUS status = NT_STATUS_NO_MEMORY;
+	unsigned int set_timeout = 0;
+	unsigned int saved_timeout = 0;
 
 	if (smbXcli_conn_has_async_calls(cli->conn)) {
-		/*
-		 * Can't use sync call while an async call is in flight
-		 */
-		status = NT_STATUS_INVALID_PARAMETER;
-		goto fail;
+		return NT_STATUS_INVALID_PARAMETER;
 	}
-
 	ev = samba_tevent_context_init(frame);
 	if (ev == NULL) {
-		status = NT_STATUS_NO_MEMORY;
 		goto fail;
 	}
 
-	req = cli_unlock_send(frame, ev, cli,
-			fnum, offset, len);
+	if (timeout != 0) {
+		if (timeout == -1) {
+			set_timeout = 0x7FFFFFFF;
+		} else {
+			set_timeout = timeout + 2*1000;
+		}
+		saved_timeout = cli_set_timeout(cli, set_timeout);
+	}
+
+	req = cli_lockingx_send(
+		frame,
+		ev,
+		cli,
+		fnum,
+		typeoflock,
+		newoplocklevel,
+		timeout,
+		num_unlocks,
+		unlocks,
+		num_locks,
+		locks);
 	if (req == NULL) {
-		status = NT_STATUS_NO_MEMORY;
 		goto fail;
 	}
-
 	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
 		goto fail;
 	}
+	status = cli_lockingx_recv(req);
 
-	status = cli_unlock_recv(req);
-
- fail:
+	if (saved_timeout != 0) {
+		cli_set_timeout(cli, saved_timeout);
+	}
+fail:
 	TALLOC_FREE(frame);
 	return status;
 }
 
 /****************************************************************************
- Lock a file with 64 bit offsets.
+ send a lock with a specified locktype
+ this is used for testing LOCKING_ANDX_CANCEL_LOCK
 ****************************************************************************/
 
-NTSTATUS cli_lock64(struct cli_state *cli, uint16_t fnum,
-		    uint64_t offset, uint64_t len, int timeout,
-		    enum brl_type lock_type)
+NTSTATUS cli_locktype(struct cli_state *cli, uint16_t fnum,
+		      uint32_t offset, uint32_t len,
+		      int timeout, unsigned char locktype)
 {
-	uint16_t vwv[8];
-	uint8_t bytes[20];
-	unsigned int set_timeout = 0;
-	unsigned int saved_timeout = 0;
-	int ltype;
+	struct smb1_lock_element lck = {
+		.pid = cli_getpid(cli),
+		.offset = offset,
+		.length = len,
+	};
 	NTSTATUS status;
 
-	if (! (smb1cli_conn_capabilities(cli->conn) & CAP_LARGE_FILES)) {
-		return cli_lock32(cli, fnum, offset, len, timeout, lock_type);
-	}
-
-	ltype = (lock_type == READ_LOCK? 1 : 0);
-	ltype |= LOCKING_ANDX_LARGE_FILES;
-
-	SCVAL(vwv + 0, 0, 0xff);
-	SCVAL(vwv + 0, 1, 0);
-	SSVAL(vwv + 1, 0, 0);
-	SSVAL(vwv + 2, 0, fnum);
-	SCVAL(vwv + 3, 0, ltype);
-	SCVAL(vwv + 3, 1, 0);
-	SIVALS(vwv + 4, 0, timeout);
-	SSVAL(vwv + 6, 0, 0);
-	SSVAL(vwv + 7, 0, 1);
-
-	SIVAL(bytes, 0, cli_getpid(cli));
-	SOFF_T_R(bytes, 4, offset);
-	SOFF_T_R(bytes, 12, len);
-
-	if (timeout != 0) {
-		if (timeout == -1) {
-			set_timeout = 0x7FFFFFFF;
-		} else {
-			set_timeout = timeout + 2*1000;
-		}
-		saved_timeout = cli_set_timeout(cli, set_timeout);
-	}
+	status = cli_lockingx(
+		cli,				/* cli */
+		fnum,				/* fnum */
+		locktype,			/* typeoflock */
+		0,				/* newoplocklevel */
+		timeout,			/* timeout */
+		0,				/* num_unlocks */
+		NULL,				/* unlocks */
+		1,				/* num_locks */
+		&lck);				/* locks */
+	return status;
+}
 
-	status = cli_smb(talloc_tos(), cli, SMBlockingX, 0, 8, vwv,
-			 20, bytes, NULL, 0, NULL, NULL, NULL, NULL);
+/****************************************************************************
+ Lock a file.
+ note that timeout is in units of 2 milliseconds
+****************************************************************************/
 
-	if (saved_timeout != 0) {
-		cli_set_timeout(cli, saved_timeout);
-	}
+NTSTATUS cli_lock32(struct cli_state *cli, uint16_t fnum,
+		  uint32_t offset, uint32_t len, int timeout,
+		  enum brl_type lock_type)
+{
+	NTSTATUS status;
 
+	status = cli_locktype(cli, fnum, offset, len, timeout,
+			      (lock_type == READ_LOCK? 1 : 0));
 	return status;
 }
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list