[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Mon Jul 26 15:02:13 MDT 2010


The branch, master has been updated
       via  2ad4b4f... s3: Convert cli_qpathinfo_streams to cli_qpathinfo_send
       via  27fb920... s3: Factor out parse_streams_blob
       via  7c242ca... s3: Convert cli_qpathinfo_basic to cli_qpathinfo_send
       via  f62bde9... s3: Convert cli_qpathinfo2 to cli_qpathinfo_send
       via  9a2d08b... s3: Use error status instead of cli_errstr
      from  5030ba5... s3: Callers of cli_qpathinfo_recv might ignore the output

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


- Log -----------------------------------------------------------------
commit 2ad4b4f63ef6e8fa8f875135a4fa5764ef57c6ac
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jul 26 10:35:15 2010 +0200

    s3: Convert cli_qpathinfo_streams to cli_qpathinfo_send

commit 27fb920ee8caade141cf0fd39e75afac7f4b5d0b
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jul 26 10:08:38 2010 +0200

    s3: Factor out parse_streams_blob

commit 7c242cab9533ec240756fe1f18e99aef7d4086c2
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jul 26 09:41:25 2010 +0200

    s3: Convert cli_qpathinfo_basic to cli_qpathinfo_send

commit f62bde93ce911445c0f3cb952d17d271a6536385
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jul 26 09:27:11 2010 +0200

    s3: Convert cli_qpathinfo2 to cli_qpathinfo_send

commit 9a2d08bd3c10b8632c1497cfac3f91bcccbed8a7
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jul 26 09:21:17 2010 +0200

    s3: Use error status instead of cli_errstr

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

Summary of changes:
 source3/client/client.c      |   26 ++-
 source3/include/proto.h      |   47 ++++-
 source3/libsmb/clirap.c      |  437 ++++++++++++++++++++++++++++--------------
 source3/libsmb/libsmb_file.c |    4 +-
 source3/torture/torture.c    |   47 ++---
 5 files changed, 366 insertions(+), 195 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/client.c b/source3/client/client.c
index 326c23e..cd41699 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -1566,18 +1566,21 @@ static int do_allinfo(const char *name)
 	unsigned int num_streams;
 	struct stream_struct *streams;
 	unsigned int i;
+	NTSTATUS status;
 
-	if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) {
-		d_printf("%s getting alt name for %s\n",
-			 cli_errstr(cli),name);
+	status = cli_qpathinfo_alt_name(cli, name, altname);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_printf("%s getting alt name for %s\n", nt_errstr(status),
+			 name);
 		return false;
 	}
 	d_printf("altname: %s\n", altname);
 
-	if (!cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time,
-			    &size, &mode, &ino)) {
-		d_printf("%s getting pathinfo for %s\n",
-			 cli_errstr(cli),name);
+	status = cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time,
+				&size, &mode, &ino);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_printf("%s getting pathinfo for %s\n", nt_errstr(status),
+			 name);
 		return false;
 	}
 
@@ -1595,10 +1598,11 @@ static int do_allinfo(const char *name)
 
 	d_printf("attributes: %s\n", attr_str(talloc_tos(), mode));
 
-	if (!cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams,
-				   &streams)) {
-		d_printf("%s getting streams for %s\n",
-			 cli_errstr(cli),name);
+	status = cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams,
+				       &streams);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_printf("%s getting streams for %s\n", nt_errstr(status),
+			 name);
 		return false;
 	}
 
diff --git a/source3/include/proto.h b/source3/include/proto.h
index cbfe103..16110f2 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2665,17 +2665,36 @@ bool cli_setpathinfo(struct cli_state *cli, const char *fname,
                      time_t write_time,
                      time_t change_time,
                      uint16 mode);
-bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
-		    struct timespec *create_time,
-                    struct timespec *access_time,
-                    struct timespec *write_time,
-		    struct timespec *change_time,
-                    SMB_OFF_T *size, uint16 *mode,
-		    SMB_INO_T *ino);
-bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
-			   TALLOC_CTX *mem_ctx,
-			   unsigned int *pnum_streams,
-			   struct stream_struct **pstreams);
+struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx,
+				       struct event_context *ev,
+				       struct cli_state *cli,
+				       const char *fname);
+NTSTATUS cli_qpathinfo2_recv(struct tevent_req *req,
+			     struct timespec *create_time,
+			     struct timespec *access_time,
+			     struct timespec *write_time,
+			     struct timespec *change_time,
+			     SMB_OFF_T *size, uint16 *mode,
+			     SMB_INO_T *ino);
+NTSTATUS cli_qpathinfo2(struct cli_state *cli, const char *fname,
+			struct timespec *create_time,
+			struct timespec *access_time,
+			struct timespec *write_time,
+			struct timespec *change_time,
+			SMB_OFF_T *size, uint16 *mode,
+			SMB_INO_T *ino);
+struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx,
+					      struct tevent_context *ev,
+					      struct cli_state *cli,
+					      const char *fname);
+NTSTATUS cli_qpathinfo_streams_recv(struct tevent_req *req,
+				    TALLOC_CTX *mem_ctx,
+				    unsigned int *pnum_streams,
+				    struct stream_struct **pstreams);
+NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
+			       TALLOC_CTX *mem_ctx,
+			       unsigned int *pnum_streams,
+			       struct stream_struct **pstreams);
 bool cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, size_t namelen);
 bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
 		   uint16 *mode, SMB_OFF_T *size,
@@ -2684,6 +2703,12 @@ bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
                    struct timespec *write_time,
 		   struct timespec *change_time,
                    SMB_INO_T *ino);
+struct tevent_req *cli_qpathinfo_basic_send(TALLOC_CTX *mem_ctx,
+					    struct event_context *ev,
+					    struct cli_state *cli,
+					    const char *fname);
+NTSTATUS cli_qpathinfo_basic_recv(struct tevent_req *req,
+				  SMB_STRUCT_STAT *sbuf, uint32 *attributes);
 NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
 			     SMB_STRUCT_STAT *sbuf, uint32 *attributes);
 bool cli_qfileinfo_test(struct cli_state *cli, uint16_t fnum, int level, char **poutdata, uint32 *poutlen);
diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c
index c4b3648..56d6375 100644
--- a/source3/libsmb/clirap.c
+++ b/source3/libsmb/clirap.c
@@ -768,135 +768,256 @@ bool cli_setpathinfo(struct cli_state *cli, const char *fname,
  Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
 ****************************************************************************/
 
-bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
-		    struct timespec *create_time,
-                    struct timespec *access_time,
-                    struct timespec *write_time,
-		    struct timespec *change_time,
-                    SMB_OFF_T *size, uint16 *mode,
-		    SMB_INO_T *ino)
+struct cli_qpathinfo2_state {
+	uint32_t num_data;
+	uint8_t *data;
+};
+
+static void cli_qpathinfo2_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx,
+				       struct event_context *ev,
+				       struct cli_state *cli,
+				       const char *fname)
 {
-	unsigned int data_len = 0;
-	unsigned int param_len = 0;
-	uint16 setup = TRANSACT2_QPATHINFO;
-	char *param;
-	char *rparam=NULL, *rdata=NULL;
-	char *p;
-	size_t nlen = 2*(strlen(fname)+1);
+	struct tevent_req *req = NULL, *subreq = NULL;
+	struct cli_qpathinfo2_state *state = NULL;
 
-	param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
-	if (!param) {
-		return false;
+	req = tevent_req_create(mem_ctx, &state, struct cli_qpathinfo2_state);
+	if (req == NULL) {
+		return NULL;
 	}
-	p = param;
-	memset(param, '\0', 6);
-	SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
-	p += 6;
-	p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
+	subreq = cli_qpathinfo_send(state, ev, cli, fname,
+				    SMB_QUERY_FILE_ALL_INFO,
+				    68, cli->max_xmit);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, cli_qpathinfo2_done, req);
+	return req;
+}
 
-	param_len = PTR_DIFF(p, param);
+static void cli_qpathinfo2_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_qpathinfo2_state *state = tevent_req_data(
+		req, struct cli_qpathinfo2_state);
+	NTSTATUS status;
 
-	if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                         /* name */
-                            -1, 0,                        /* fid, flags */
-                            &setup, 1, 0,                 /* setup, length, max */
-                            param, param_len, 10,         /* param, length, max */
-                            NULL, data_len, cli->max_xmit /* data, length, max */
-                           )) {
-		SAFE_FREE(param);
-		return False;
+	status = cli_qpathinfo_recv(subreq, state, &state->data,
+				    &state->num_data);
+	TALLOC_FREE(subreq);
+	if (!NT_STATUS_IS_OK(status)) {
+		tevent_req_nterror(req, status);
+		return;
 	}
+	tevent_req_done(req);
+}
 
-	SAFE_FREE(param);
-	if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-		return False;
-	}
+NTSTATUS cli_qpathinfo2_recv(struct tevent_req *req,
+			     struct timespec *create_time,
+			     struct timespec *access_time,
+			     struct timespec *write_time,
+			     struct timespec *change_time,
+			     SMB_OFF_T *size, uint16 *mode,
+			     SMB_INO_T *ino)
+{
+	struct cli_qpathinfo2_state *state = tevent_req_data(
+		req, struct cli_qpathinfo2_state);
+	NTSTATUS status;
 
-	if (!rdata || data_len < 68) {
-		return False;
+	if (tevent_req_is_nterror(req, &status)) {
+		return status;
 	}
 
 	if (create_time) {
-                *create_time = interpret_long_date(rdata+0);
+                *create_time = interpret_long_date((char *)state->data+0);
 	}
 	if (access_time) {
-		*access_time = interpret_long_date(rdata+8);
+		*access_time = interpret_long_date((char *)state->data+8);
 	}
 	if (write_time) {
-		*write_time = interpret_long_date(rdata+16);
+		*write_time = interpret_long_date((char *)state->data+16);
 	}
 	if (change_time) {
-		*change_time = interpret_long_date(rdata+24);
+		*change_time = interpret_long_date((char *)state->data+24);
 	}
 	if (mode) {
-		*mode = SVAL(rdata, 32);
+		*mode = SVAL(state->data, 32);
 	}
 	if (size) {
-                *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
+                *size = IVAL2_TO_SMB_BIG_UINT(state->data,48);
 	}
 	if (ino) {
-		*ino = IVAL(rdata, 64);
+		*ino = IVAL(state->data, 64);
 	}
+	return NT_STATUS_OK;
+}
 
-	SAFE_FREE(rdata);
-	SAFE_FREE(rparam);
-	return True;
+NTSTATUS cli_qpathinfo2(struct cli_state *cli, const char *fname,
+			struct timespec *create_time,
+			struct timespec *access_time,
+			struct timespec *write_time,
+			struct timespec *change_time,
+			SMB_OFF_T *size, uint16 *mode,
+			SMB_INO_T *ino)
+{
+	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_qpathinfo2_send(frame, ev, cli, fname);
+	if (req == NULL) {
+		goto fail;
+	}
+	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+		goto fail;
+	}
+	status = cli_qpathinfo2_recv(req, change_time, access_time,
+				     write_time, change_time, size, mode, ino);
+ fail:
+	TALLOC_FREE(frame);
+	if (!NT_STATUS_IS_OK(status)) {
+		cli_set_error(cli, status);
+	}
+	return status;
 }
 
 /****************************************************************************
  Get the stream info
 ****************************************************************************/
 
-bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
-			   TALLOC_CTX *mem_ctx,
-			   unsigned int *pnum_streams,
-			   struct stream_struct **pstreams)
+static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *data,
+			       size_t data_len,
+			       unsigned int *pnum_streams,
+			       struct stream_struct **pstreams);
+
+struct cli_qpathinfo_streams_state {
+	uint32_t num_data;
+	uint8_t *data;
+};
+
+static void cli_qpathinfo_streams_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx,
+					      struct tevent_context *ev,
+					      struct cli_state *cli,
+					      const char *fname)
 {
-	unsigned int data_len = 0;
-	unsigned int param_len = 0;
-	uint16 setup = TRANSACT2_QPATHINFO;
-	char *param;
-	char *rparam=NULL, *rdata=NULL;
-	char *p;
-	unsigned int num_streams;
-	struct stream_struct *streams;
-	unsigned int ofs;
-	size_t namelen = 2*(strlen(fname)+1);
+	struct tevent_req *req = NULL, *subreq = NULL;
+	struct cli_qpathinfo_streams_state *state = NULL;
 
-	param = SMB_MALLOC_ARRAY(char, 6+namelen+2);
-	if (param == NULL) {
-		return false;
+	req = tevent_req_create(mem_ctx, &state,
+				struct cli_qpathinfo_streams_state);
+	if (req == NULL) {
+		return NULL;
 	}
-	p = param;
-	memset(p, 0, 6);
-	SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION);
-	p += 6;
-	p += clistr_push(cli, p, fname, namelen, STR_TERMINATE);
+	subreq = cli_qpathinfo_send(state, ev, cli, fname,
+				    SMB_FILE_STREAM_INFORMATION,
+				    0, cli->max_xmit);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, cli_qpathinfo_streams_done, req);
+	return req;
+}
 
-	param_len = PTR_DIFF(p, param);
+static void cli_qpathinfo_streams_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_qpathinfo_streams_state *state = tevent_req_data(
+		req, struct cli_qpathinfo_streams_state);
+	NTSTATUS status;
 
-	if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                     /* name */
-                            -1, 0,                    /* fid, flags */
-                            &setup, 1, 0,             /* setup, len, max */
-                            param, param_len, 10,     /* param, len, max */
-                            NULL, data_len, cli->max_xmit /* data, len, max */
-                           )) {
-		return false;
+	status = cli_qpathinfo_recv(subreq, state, &state->data,
+				    &state->num_data);
+	TALLOC_FREE(subreq);
+	if (!NT_STATUS_IS_OK(status)) {
+		tevent_req_nterror(req, status);
+		return;
 	}
+	tevent_req_done(req);
+}
 
-	if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-		return false;
+NTSTATUS cli_qpathinfo_streams_recv(struct tevent_req *req,
+				    TALLOC_CTX *mem_ctx,
+				    unsigned int *pnum_streams,
+				    struct stream_struct **pstreams)
+{
+	struct cli_qpathinfo_streams_state *state = tevent_req_data(
+                req, struct cli_qpathinfo_streams_state);
+        NTSTATUS status;
+
+	if (tevent_req_is_nterror(req, &status)) {
+		return status;
 	}
+	if (!parse_streams_blob(mem_ctx, state->data, state->num_data,
+				pnum_streams, pstreams)) {
+		return NT_STATUS_INVALID_NETWORK_RESPONSE;
+	}
+	return NT_STATUS_OK;
+}
 
-	if (!rdata) {
-		SAFE_FREE(rparam);
-		return false;
+NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
+			       TALLOC_CTX *mem_ctx,
+			       unsigned int *pnum_streams,
+			       struct stream_struct **pstreams)
+{
+	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_qpathinfo_streams_send(frame, ev, cli, fname);
+	if (req == NULL) {
+		goto fail;
+	}
+	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+		goto fail;
+	}
+	status = cli_qpathinfo_streams_recv(req, mem_ctx, pnum_streams,
+					    pstreams);
+ fail:
+	TALLOC_FREE(frame);
+	if (!NT_STATUS_IS_OK(status)) {
+		cli_set_error(cli, status);
+	}
+	return status;
+}
+
+static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
+			       size_t data_len,
+			       unsigned int *pnum_streams,
+			       struct stream_struct **pstreams)
+{
+	unsigned int num_streams;
+	struct stream_struct *streams;
+	unsigned int ofs;
 
 	num_streams = 0;
 	streams = NULL;
@@ -962,17 +1083,12 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
 		ofs += len;
 	}
 
-	SAFE_FREE(rdata);
-	SAFE_FREE(rparam);
-
 	*pnum_streams = num_streams;
 	*pstreams = streams;
 	return true;
 
  fail:
 	TALLOC_FREE(streams);
-	SAFE_FREE(rdata);
-	SAFE_FREE(rparam);
 	return false;
 }
 
@@ -1093,68 +1209,105 @@ bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
  Send a qpathinfo BASIC_INFO call.
 ****************************************************************************/
 
-NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
-			     SMB_STRUCT_STAT *sbuf, uint32 *attributes)
+struct cli_qpathinfo_basic_state {
+	uint32_t num_data;
+	uint8_t *data;
+};
+
+static void cli_qpathinfo_basic_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_qpathinfo_basic_send(TALLOC_CTX *mem_ctx,
+					    struct event_context *ev,
+					    struct cli_state *cli,
+					    const char *fname)
 {
-	unsigned int param_len = 0;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list