[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu May 19 10:47:02 MDT 2011


The branch, master has been updated
       via  d753b3b fix the WAF build
       via  0645deb s3: Do central cli_set_error
       via  bc7df52 s3: Remove the use of cli->inbuf/outbuf from cli_session_request
       via  efbed2c s3: Add sync read_smb
       via  e7e43ba s3: Make read_smb_send/recv public
      from  66c3d5d Fix bug found when building on an IPv6-only system by Kai Blin.

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


- Log -----------------------------------------------------------------
commit d753b3b0639d88579ce4d7118bfb586207017316
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 19 17:37:19 2011 +0200

    fix the WAF build
    
    Autobuild-User: Volker Lendecke <vlendec at samba.org>
    Autobuild-Date: Thu May 19 18:46:51 CEST 2011 on sn-devel-104

commit 0645deb1b4a70e45f88116fae16ec7f3a1b4d5ed
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 19 13:43:15 2011 +0200

    s3: Do central cli_set_error

commit bc7df5265345c6dfc32dcdc02826d6c73179805f
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 19 09:12:13 2011 +0200

    s3: Remove the use of cli->inbuf/outbuf from cli_session_request

commit efbed2ce90ff10cd82543f22cba1fe0a4cfbb7fd
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 19 08:36:54 2011 +0200

    s3: Add sync read_smb

commit e7e43ba6a135b23865a7c9363a0ee0f479696067
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 19 08:23:50 2011 +0200

    s3: Make read_smb_send/recv public

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

Summary of changes:
 source3/Makefile.in                                |    1 +
 source3/libsmb/async_smb.c                         |   90 +-------------
 source3/libsmb/cliconnect.c                        |  125 ++++++++-----------
 source3/libsmb/clifile.c                           |  116 -----------------
 source3/libsmb/clifsinfo.c                         |    9 --
 source3/libsmb/clilist.c                           |    9 --
 source3/libsmb/clioplock.c                         |    3 -
 source3/libsmb/clirap.c                            |   12 --
 source3/libsmb/clireadwrite.c                      |   10 --
 source3/libsmb/clitrans.c                          |    3 -
 source3/libsmb/read_smb.c                          |  134 ++++++++++++++++++++
 .../testspoolss.h => source3/libsmb/read_smb.h     |   39 ++----
 source3/wscript_build                              |    2 +-
 13 files changed, 203 insertions(+), 350 deletions(-)
 create mode 100644 source3/libsmb/read_smb.c
 copy testprogs/win32/spoolss/testspoolss.h => source3/libsmb/read_smb.h (58%)


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 847f811..03b4273 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -595,6 +595,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
 	     libsmb/clistr.o libsmb/cliquota.o libsmb/clifsinfo.o libsmb/clidfs.o \
 	     libsmb/clioplock.o libsmb/clirap2.o \
 	     libsmb/smb_seal.o libsmb/async_smb.o \
+	     libsmb/read_smb.o \
 	     libsmb/cli_np_tstream.o \
 	     libsmb/smbsock_connect.o \
 	     $(LIBSAMBA_OBJ) \
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index 82dbc74..dfab82a 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -25,93 +25,7 @@
 #include "async_smb.h"
 #include "smb_crypt.h"
 #include "libsmb/nmblib.h"
-
-/*
- * Read an smb packet asynchronously, discard keepalives
- */
-
-struct read_smb_state {
-	struct tevent_context *ev;
-	int fd;
-	uint8_t *buf;
-};
-
-static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data);
-static void read_smb_done(struct tevent_req *subreq);
-
-static struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
-					struct tevent_context *ev,
-					int fd)
-{
-	struct tevent_req *result, *subreq;
-	struct read_smb_state *state;
-
-	result = tevent_req_create(mem_ctx, &state, struct read_smb_state);
-	if (result == NULL) {
-		return NULL;
-	}
-	state->ev = ev;
-	state->fd = fd;
-
-	subreq = read_packet_send(state, ev, fd, 4, read_smb_more, NULL);
-	if (subreq == NULL) {
-		goto fail;
-	}
-	tevent_req_set_callback(subreq, read_smb_done, result);
-	return result;
- fail:
-	TALLOC_FREE(result);
-	return NULL;
-}
-
-static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data)
-{
-	if (buflen > 4) {
-		return 0;	/* We've been here, we're done */
-	}
-	return smb_len_large(buf);
-}
-
-static void read_smb_done(struct tevent_req *subreq)
-{
-	struct tevent_req *req = tevent_req_callback_data(
-		subreq, struct tevent_req);
-	struct read_smb_state *state = tevent_req_data(
-		req, struct read_smb_state);
-	ssize_t len;
-	int err;
-
-	len = read_packet_recv(subreq, state, &state->buf, &err);
-	TALLOC_FREE(subreq);
-	if (len == -1) {
-		tevent_req_error(req, err);
-		return;
-	}
-
-	if (CVAL(state->buf, 0) == SMBkeepalive) {
-		subreq = read_packet_send(state, state->ev, state->fd, 4,
-					  read_smb_more, NULL);
-		if (tevent_req_nomem(subreq, req)) {
-			return;
-		}
-		tevent_req_set_callback(subreq, read_smb_done, req);
-		return;
-	}
-	tevent_req_done(req);
-}
-
-static ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-			     uint8_t **pbuf, int *perrno)
-{
-	struct read_smb_state *state = tevent_req_data(
-		req, struct read_smb_state);
-
-	if (tevent_req_is_unix_error(req, perrno)) {
-		return -1;
-	}
-	*pbuf = talloc_move(mem_ctx, &state->buf);
-	return talloc_get_size(*pbuf);
-}
+#include "read_smb.h"
 
 /**
  * Fetch an error out of a NBT packet
@@ -825,6 +739,8 @@ NTSTATUS cli_smb_recv(struct tevent_req *req,
 
 	status = cli_pull_error((char *)state->inbuf);
 
+	cli_set_error(state->cli, status);
+
 	if (!have_andx_command((char *)state->inbuf, wct_ofs)) {
 
 		if ((cmd == SMBsesssetupX)
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 828cb2c..374dd97 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -32,6 +32,7 @@
 #include "../lib/util/tevent_ntstatus.h"
 #include "async_smb.h"
 #include "libsmb/nmblib.h"
+#include "read_smb.h"
 
 static const struct {
 	int prot;
@@ -358,9 +359,6 @@ static NTSTATUS cli_session_setup_lanman2(struct cli_state *cli, const char *use
 	status = cli_session_setup_lanman2_recv(req);
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -592,9 +590,6 @@ static NTSTATUS cli_session_setup_guest(struct cli_state *cli)
 	status = cli_session_setup_guest_recv(req);
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -793,9 +788,6 @@ static NTSTATUS cli_session_setup_plain(struct cli_state *cli,
 	status = cli_session_setup_plain_recv(req);
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1158,9 +1150,6 @@ static NTSTATUS cli_session_setup_nt1(struct cli_state *cli, const char *user,
 	status = cli_session_setup_nt1_recv(req);
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1775,9 +1764,6 @@ static NTSTATUS cli_session_setup_ntlmssp(struct cli_state *cli,
 	status = cli_session_setup_ntlmssp_recv(req);
 fail:
 	TALLOC_FREE(ev);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -2145,9 +2131,6 @@ NTSTATUS cli_ulogoff(struct cli_state *cli)
 	status = cli_ulogoff_recv(req);
 fail:
 	TALLOC_FREE(ev);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -2441,9 +2424,6 @@ NTSTATUS cli_tcon_andx(struct cli_state *cli, const char *share,
 	status = cli_tcon_andx_recv(req);
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -2524,9 +2504,6 @@ NTSTATUS cli_tdis(struct cli_state *cli)
 	status = cli_tdis_recv(req);
 fail:
 	TALLOC_FREE(ev);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -2776,9 +2753,6 @@ NTSTATUS cli_negprot(struct cli_state *cli)
 	status = cli_negprot_recv(req);
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -2789,10 +2763,13 @@ NTSTATUS cli_negprot(struct cli_state *cli)
 bool cli_session_request(struct cli_state *cli,
 			 struct nmb_name *calling, struct nmb_name *called)
 {
-	char *p;
-	int len = 4;
-	int namelen = 0;
-	char *tmp;
+	TALLOC_CTX *frame;
+	uint8_t len_buf[4];
+	struct iovec iov[3];
+	ssize_t len;
+	uint8_t *inbuf;
+	int err;
+	bool ret = false;
 
 	/* 445 doesn't have session request */
 	if (cli->port == 445)
@@ -2803,35 +2780,30 @@ bool cli_session_request(struct cli_state *cli,
 
 	/* put in the destination name */
 
-	tmp = name_mangle(talloc_tos(), cli->called.name,
-			  cli->called.name_type);
-	if (tmp == NULL) {
-		return false;
-	}
+	frame = talloc_stackframe();
 
-	p = cli->outbuf+len;
-	namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
-	if (namelen > 0) {
-		memcpy(p, tmp, namelen);
-		len += namelen;
-	}
-	TALLOC_FREE(tmp);
+	iov[0].iov_base = len_buf;
+	iov[0].iov_len  = sizeof(len_buf);
 
-	/* and my name */
+	/* put in the destination name */
 
-	tmp = name_mangle(talloc_tos(), cli->calling.name,
-			  cli->calling.name_type);
-	if (tmp == NULL) {
-		return false;
+	iov[1].iov_base = name_mangle(talloc_tos(), called->name,
+				      called->name_type);
+	if (iov[1].iov_base == NULL) {
+		goto fail;
 	}
+	iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
+				  talloc_get_size(iov[1].iov_base));
+
+	/* and my name */
 
-	p = cli->outbuf+len;
-	namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
-	if (namelen > 0) {
-		memcpy(p, tmp, namelen);
-		len += namelen;
+	iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
+				      calling->name_type);
+	if (iov[2].iov_base == NULL) {
+		goto fail;
 	}
-	TALLOC_FREE(tmp);
+	iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
+				  talloc_get_size(iov[2].iov_base));
 
 	/* send a session request (RFC 1002) */
 	/* setup the packet length
@@ -2841,17 +2813,21 @@ bool cli_session_request(struct cli_state *cli,
          * about this and accounts for those four bytes.
          * CRH.
          */
-        len -= 4;
-	_smb_setlen(cli->outbuf,len);
-	SCVAL(cli->outbuf,0,0x81);
 
-	cli_send_smb(cli);
-	DEBUG(5,("Sent session request\n"));
+	_smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
+	SCVAL(len_buf,0,0x81);
 
-	if (!cli_receive_smb(cli))
-		return False;
+	len = write_data_iov(cli->fd, iov, 3);
+	if (len == -1) {
+		goto fail;
+	}
+	len = read_smb(cli->fd, talloc_tos(), &inbuf, &err);
+	if (len == -1) {
+		errno = err;
+		goto fail;
+	}
 
-	if (CVAL(cli->inbuf,0) == 0x84) {
+	if (CVAL(inbuf,0) == 0x84) {
 		/* C. Hoch  9/14/95 Start */
 		/* For information, here is the response structure.
 		 * We do the byte-twiddling to for portability.
@@ -2863,18 +2839,18 @@ bool cli_session_request(struct cli_state *cli,
 		int16 port;
 		};
 		*/
-		uint16_t port = (CVAL(cli->inbuf,8)<<8)+CVAL(cli->inbuf,9);
+		uint16_t port = (CVAL(inbuf,8)<<8)+CVAL(inbuf,9);
 		struct in_addr dest_ip;
 		NTSTATUS status;
 
 		/* SESSION RETARGET */
-		putip((char *)&dest_ip,cli->inbuf+4);
+		putip((char *)&dest_ip,inbuf+4);
 		in_addr_to_sockaddr_storage(&cli->dest_ss, dest_ip);
 
 		status = open_socket_out(&cli->dest_ss, port,
 					 LONG_CONNECT_TIMEOUT, &cli->fd);
 		if (!NT_STATUS_IS_OK(status)) {
-			return False;
+			goto fail;
 		}
 
 		DEBUG(3,("Retargeted\n"));
@@ -2884,24 +2860,29 @@ bool cli_session_request(struct cli_state *cli,
 		/* Try again */
 		{
 			static int depth;
-			bool ret;
 			if (depth > 4) {
 				DEBUG(0,("Retarget recursion - failing\n"));
-				return False;
+				goto fail;
 			}
 			depth++;
 			ret = cli_session_request(cli, calling, called);
 			depth--;
-			return ret;
+			goto done;
 		}
 	} /* C. Hoch 9/14/95 End */
 
-	if (CVAL(cli->inbuf,0) != 0x82) {
+	if (CVAL(inbuf,0) != 0x82) {
                 /* This is the wrong place to put the error... JRA. */
-		cli->rap_error = CVAL(cli->inbuf,4);
-		return False;
+		cli->rap_error = CVAL(inbuf,4);
+		goto fail;
 	}
-	return(True);
+done:
+	ret = true;
+fail:
+	err = errno;
+	TALLOC_FREE(frame);
+	errno = err;
+	return ret;
 }
 
 struct fd_struct {
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index f5b6fab..1bf72aa 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -358,9 +358,6 @@ NTSTATUS cli_posix_symlink(struct cli_state *cli,
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -502,9 +499,6 @@ NTSTATUS cli_posix_readlink(struct cli_state *cli, const char *fname,
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -569,9 +563,6 @@ NTSTATUS cli_posix_hardlink(struct cli_state *cli,
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -683,9 +674,6 @@ NTSTATUS cli_posix_getfacl(struct cli_state *cli,
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -817,9 +805,6 @@ NTSTATUS cli_posix_stat(struct cli_state *cli,
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -934,9 +919,6 @@ NTSTATUS cli_posix_chmod(struct cli_state *cli, const char *fname, mode_t mode)
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1007,9 +989,6 @@ NTSTATUS cli_posix_chown(struct cli_state *cli,
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1129,9 +1108,6 @@ NTSTATUS cli_rename(struct cli_state *cli, const char *fname_src, const char *fn
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1273,9 +1249,6 @@ NTSTATUS cli_ntrename(struct cli_state *cli, const char *fname_src, const char *
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1338,9 +1311,6 @@ NTSTATUS cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const cha
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1448,9 +1418,6 @@ NTSTATUS cli_unlink(struct cli_state *cli, const char *fname, uint16_t mayhave_a
 
  fail:
 	TALLOC_FREE(frame);
-	if (!NT_STATUS_IS_OK(status)) {
-		cli_set_error(cli, status);
-	}
 	return status;
 }
 
@@ -1555,9 +1522,6 @@ NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname)
 
  fail:


-- 
Samba Shared Repository


More information about the samba-cvs mailing list