[SCM] Samba Shared Repository - branch v3-5-test updated

Karolin Seeger kseeger at samba.org
Sun Dec 26 14:14:50 MST 2010


The branch, v3-5-test has been updated
       via  969f452 s3: Use smbsock_any_connect in winbind
       via  6e9e567 s3: Retry *SMBSERVER in nb_connect
       via  b289052 s3: Add smbsock_any_connect
       via  8b6b80e s3: Add an async smbsock_connect
       via  0b13028 v3-5-test: Pull in tevent_req_poll_ntstatus from master
       via  a30258c s3: Add async cli_session_request
       via  1552ace s3: Add some const to name_mangle()
      from  53f163b s3:net ads dns register: use "cluster addresses" option if configured (bug #7871)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-5-test


- Log -----------------------------------------------------------------
commit 969f452de253cd8dbe6f4448168eaa11baed1fbc
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 21 21:55:01 2010 +0100

    s3: Use smbsock_any_connect in winbind
    
    The last 7 patches address bug #7881 (winbind flaky against w2k8).

commit 6e9e567dfeb860c8b9a342bf46765f8c9b8ea7db
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 21 18:52:53 2010 +0100

    s3: Retry *SMBSERVER in nb_connect

commit b289052828eb03b8c353b85691ce6af6aef6bf41
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Dec 13 17:17:51 2010 +0100

    s3: Add smbsock_any_connect

commit 8b6b80ef591031ea6e394cebd6e0fdf8c7b8485a
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Dec 12 18:55:06 2010 +0100

    s3: Add an async smbsock_connect
    
    This connects to 445 and after 5 milliseconds also to 139. It treats a netbios
    session setup failure as equivalent as a TCP connect failure. So if 139 is
    faster but fails the nb session setup, the 445 still has the chance to succeed.

commit 0b13028cb4d6fc2ff267df477b5c2c4291286a43
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 22 15:21:27 2010 +0100

    v3-5-test: Pull in tevent_req_poll_ntstatus from master

commit a30258cf98ff334a786ea1566b607208d82617a0
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Dec 12 18:54:31 2010 +0100

    s3: Add async cli_session_request
    
    This does not do the redirects, but I think that might be obsolete anyway

commit 1552acea9a55dd6bc5f386a5f424e09875ed463c
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Dec 12 18:53:49 2010 +0100

    s3: Add some const to name_mangle()

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

Summary of changes:
 source3/Makefile.in              |    1 +
 source3/include/async_smb.h      |    7 +
 source3/include/proto.h          |   27 ++-
 source3/lib/util.c               |   11 +
 source3/libsmb/async_smb.c       |  127 +++++++++
 source3/libsmb/nmblib.c          |    2 +-
 source3/libsmb/smbsock_connect.c |  573 ++++++++++++++++++++++++++++++++++++++
 source3/winbindd/winbindd_cm.c   |   58 +---
 8 files changed, 759 insertions(+), 47 deletions(-)
 create mode 100644 source3/libsmb/smbsock_connect.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 8cdecef..9f89808 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -519,6 +519,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/smbsock_connect.o \
 	     $(LIBSAMBA_OBJ) \
 	     $(LIBNMB_OBJ) \
 	     $(LIBNBT_OBJ) \
diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h
index 47fed92..8b0eae2 100644
--- a/source3/include/async_smb.h
+++ b/source3/include/async_smb.h
@@ -68,4 +68,11 @@ NTSTATUS cli_smb_oplock_break_waiter_recv(struct tevent_req *req,
 					  uint16_t *pfnum,
 					  uint8_t *plevel);
 
+struct tevent_req *cli_session_request_send(TALLOC_CTX *mem_ctx,
+					    struct tevent_context *ev,
+					    int sock,
+					    const struct nmb_name *called,
+					    const struct nmb_name *calling);
+bool cli_session_request_recv(struct tevent_req *req, int *err, uint8_t *resp);
+
 #endif
diff --git a/source3/include/proto.h b/source3/include/proto.h
index bd5119f..5dfd046 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1238,6 +1238,9 @@ bool is_valid_policy_hnd(const struct policy_handle *hnd);
 bool policy_hnd_equal(const struct policy_handle *hnd1,
 		      const struct policy_handle *hnd2);
 const char *strip_hostname(const char *s);
+bool tevent_req_poll_ntstatus(struct tevent_req *req,
+			      struct tevent_context *ev,
+			      NTSTATUS *status);
 
 /* The following definitions come from lib/util_file.c  */
 
@@ -3192,7 +3195,7 @@ struct packet_struct *receive_dgram_packet(int fd, int t,
 bool match_mailslot_name(struct packet_struct *p, const char *mailslot_name);
 int matching_len_bits(unsigned char *p1, unsigned char *p2, size_t len);
 void sort_query_replies(char *data, int n, struct in_addr ip);
-char *name_mangle(TALLOC_CTX *mem_ctx, char *In, char name_type);
+char *name_mangle(TALLOC_CTX *mem_ctx, const char *In, char name_type);
 int name_extract(unsigned char *buf,size_t buf_len, unsigned int ofs, fstring name);
 int name_len(unsigned char *s1, size_t buf_len);
 
@@ -7304,6 +7307,28 @@ struct tevent_req *fncall_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
 			       void *private_data);
 int fncall_recv(struct tevent_req *req, int *perr);
 
+struct tevent_req *smbsock_connect_send(TALLOC_CTX *mem_ctx,
+					struct tevent_context *ev,
+					const struct sockaddr_storage *addr,
+					const char *called_name,
+					const char *calling_name);
+NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock,
+			      uint16_t *port);
+NTSTATUS smbsock_connect(const struct sockaddr_storage *addr,
+			 const char *called_name, const char *calling_name,
+			 int *pfd, uint16_t *port);
+
+struct tevent_req *smbsock_any_connect_send(TALLOC_CTX *mem_ctx,
+					    struct tevent_context *ev,
+					    const struct sockaddr_storage *addrs,
+					    const char **called_names,
+					    size_t num_addrs);
+NTSTATUS smbsock_any_connect_recv(struct tevent_req *req, int *pfd,
+				  size_t *chosen_index, uint16_t *port);
+NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs,
+			     const char **called_names, size_t num_addrs,
+			     int *pfd, size_t *chosen_index, uint16_t *port);
+
 /* The following definitions come from rpc_server/srv_samr_nt.c */
 NTSTATUS access_check_object( SEC_DESC *psd, NT_USER_TOKEN *token,
 				SE_PRIV *rights, uint32 rights_mask,
diff --git a/source3/lib/util.c b/source3/lib/util.c
index fad6c7a..ee45da0 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3070,3 +3070,14 @@ const char *strip_hostname(const char *s)
 
 	return s;
 }
+
+bool tevent_req_poll_ntstatus(struct tevent_req *req,
+			      struct tevent_context *ev,
+			      NTSTATUS *status)
+{
+	bool ret = tevent_req_poll(req, ev);
+	if (!ret) {
+		*status = map_nt_error_from_unix(errno);
+	}
+	return ret;
+}
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index 1f4ef6f..4d53028 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -1071,3 +1071,130 @@ NTSTATUS cli_smb_oplock_break_waiter_recv(struct tevent_req *req,
 	*plevel = state->level;
 	return NT_STATUS_OK;
 }
+
+
+struct cli_session_request_state {
+	struct tevent_context *ev;
+	int sock;
+	uint32 len_hdr;
+	struct iovec iov[3];
+	uint8_t nb_session_response;
+};
+
+static void cli_session_request_sent(struct tevent_req *subreq);
+static void cli_session_request_recvd(struct tevent_req *subreq);
+
+struct tevent_req *cli_session_request_send(TALLOC_CTX *mem_ctx,
+					    struct tevent_context *ev,
+					    int sock,
+					    const struct nmb_name *called,
+					    const struct nmb_name *calling)
+{
+	struct tevent_req *req, *subreq;
+	struct cli_session_request_state *state;
+
+	req = tevent_req_create(mem_ctx, &state,
+				struct cli_session_request_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	state->ev = ev;
+	state->sock = sock;
+
+	state->iov[1].iov_base = name_mangle(
+		state, called->name, called->name_type);
+	if (tevent_req_nomem(state->iov[1].iov_base, req)) {
+		return tevent_req_post(req, ev);
+	}
+	state->iov[1].iov_len = name_len(
+		(unsigned char *)state->iov[1].iov_base,
+		talloc_get_size(state->iov[1].iov_base));
+
+	state->iov[2].iov_base = name_mangle(
+		state, calling->name, calling->name_type);
+	if (tevent_req_nomem(state->iov[2].iov_base, req)) {
+		return tevent_req_post(req, ev);
+	}
+	state->iov[2].iov_len = name_len(
+		(unsigned char *)state->iov[2].iov_base,
+		talloc_get_size(state->iov[2].iov_base));
+
+	_smb_setlen(((char *)&state->len_hdr),
+		    state->iov[1].iov_len + state->iov[2].iov_len);
+	SCVAL((char *)&state->len_hdr, 0, 0x81);
+
+	state->iov[0].iov_base = &state->len_hdr;
+	state->iov[0].iov_len = sizeof(state->len_hdr);
+
+	subreq = writev_send(state, ev, NULL, sock, true, state->iov, 3);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, cli_session_request_sent, req);
+	return req;
+}
+
+static void cli_session_request_sent(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_session_request_state *state = tevent_req_data(
+		req, struct cli_session_request_state);
+	ssize_t ret;
+	int err;
+
+	ret = writev_recv(subreq, &err);
+	TALLOC_FREE(subreq);
+	if (ret == -1) {
+		tevent_req_error(req, err);
+		return;
+	}
+	subreq = read_smb_send(state, state->ev, state->sock);
+	if (tevent_req_nomem(subreq, req)) {
+		return;
+	}
+	tevent_req_set_callback(subreq, cli_session_request_recvd, req);
+}
+
+static void cli_session_request_recvd(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_session_request_state *state = tevent_req_data(
+		req, struct cli_session_request_state);
+	uint8_t *buf;
+	ssize_t ret;
+	int err;
+
+	ret = read_smb_recv(subreq, talloc_tos(), &buf, &err);
+	TALLOC_FREE(subreq);
+
+	if (ret < 4) {
+		ret = -1;
+		err = EIO;
+	}
+	if (ret == -1) {
+		tevent_req_error(req, err);
+		return;
+	}
+	/*
+	 * In case of an error there is more information in the data
+	 * portion according to RFC1002. We're not subtle enough to
+	 * respond to the different error conditions, so drop the
+	 * error info here.
+	 */
+	state->nb_session_response = CVAL(buf, 0);
+	tevent_req_done(req);
+}
+
+bool cli_session_request_recv(struct tevent_req *req, int *err, uint8_t *resp)
+{
+	struct cli_session_request_state *state = tevent_req_data(
+		req, struct cli_session_request_state);
+
+	if (tevent_req_is_unix_error(req, err)) {
+		return false;
+	}
+	*resp = state->nb_session_response;
+	return true;
+}
diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index cf7023a..267a49f 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -1288,7 +1288,7 @@ static int name_interpret(unsigned char *buf, size_t buf_len,
  Note:  <Out> must be (33 + strlen(scope) + 2) bytes long, at minimum.
 ****************************************************************************/
 
-char *name_mangle(TALLOC_CTX *mem_ctx, char *In, char name_type)
+char *name_mangle(TALLOC_CTX *mem_ctx, const char *In, char name_type)
 {
 	int   i;
 	int   len;
diff --git a/source3/libsmb/smbsock_connect.c b/source3/libsmb/smbsock_connect.c
new file mode 100644
index 0000000..8ab12c5
--- /dev/null
+++ b/source3/libsmb/smbsock_connect.c
@@ -0,0 +1,573 @@
+/*
+   Unix SMB/CIFS implementation.
+   Connect to 445 and 139/nbsesssetup
+   Copyright (C) Volker Lendecke 2010
+
+   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 "../lib/async_req/async_sock.h"
+#include "async_smb.h"
+
+struct nb_connect_state {
+	struct tevent_context *ev;
+	const struct sockaddr_storage *addr;
+	const char *called_name;
+	int sock;
+
+	struct nmb_name called;
+	struct nmb_name calling;
+};
+
+static int nb_connect_state_destructor(struct nb_connect_state *state);
+static void nb_connect_connected(struct tevent_req *subreq);
+static void nb_connect_done(struct tevent_req *subreq);
+
+static struct tevent_req *nb_connect_send(TALLOC_CTX *mem_ctx,
+					  struct tevent_context *ev,
+					  const struct sockaddr_storage *addr,
+					  const char *called_name,
+					  int called_type,
+					  const char *calling_name,
+					  int calling_type)
+{
+	struct tevent_req *req, *subreq;
+	struct nb_connect_state *state;
+
+	req = tevent_req_create(mem_ctx, &state, struct nb_connect_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	state->ev = ev;
+	state->called_name = called_name;
+	state->addr = addr;
+
+	state->sock = -1;
+	make_nmb_name(&state->called, called_name, called_type);
+	make_nmb_name(&state->calling, calling_name, calling_type);
+
+	talloc_set_destructor(state, nb_connect_state_destructor);
+
+	subreq = open_socket_out_send(state, ev, addr, 139, 5000);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, nb_connect_connected, req);
+	return req;
+}
+
+static int nb_connect_state_destructor(struct nb_connect_state *state)
+{
+	if (state->sock != -1) {
+		close(state->sock);
+	}
+	return 0;
+}
+
+static void nb_connect_connected(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct nb_connect_state *state = tevent_req_data(
+		req, struct nb_connect_state);
+	NTSTATUS status;
+
+	status = open_socket_out_recv(subreq, &state->sock);
+	TALLOC_FREE(subreq);
+	if (!NT_STATUS_IS_OK(status)) {
+		tevent_req_nterror(req, status);
+		return;
+	}
+	subreq = cli_session_request_send(state, state->ev, state->sock,
+					  &state->called, &state->calling);
+	if (tevent_req_nomem(subreq, req)) {
+		return;
+	}
+	tevent_req_set_callback(subreq, nb_connect_done, req);
+}
+
+static void nb_connect_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct nb_connect_state *state = tevent_req_data(
+		req, struct nb_connect_state);
+	bool ret;
+	int err;
+	uint8_t resp;
+
+	ret = cli_session_request_recv(subreq, &err, &resp);
+	TALLOC_FREE(subreq);
+	if (!ret) {
+		tevent_req_nterror(req, map_nt_error_from_unix(err));
+		return;
+	}
+
+	/*
+	 * RFC1002: 0x82 - POSITIVE SESSION RESPONSE
+	 */
+
+	if (resp != 0x82) {
+		/*
+		 * The server did not like our session request
+		 */
+		close(state->sock);
+		state->sock = -1;
+
+		if (strequal(state->called_name, "*SMBSERVER")) {
+			/*
+			 * Here we could try a name status request and
+			 * use the first 0x20 type name.
+			 */
+			tevent_req_nterror(
+				req, NT_STATUS_RESOURCE_NAME_NOT_FOUND);
+			return;
+		}
+
+		/*
+		 * We could be subtle and distinguish between
+		 * different failure modes, but what we do here
+		 * instead is just retry with *SMBSERVER type 0x20.
+		 */
+		state->called_name = "*SMBSERVER";
+		make_nmb_name(&state->called, state->called_name, 0x20);
+
+		subreq = open_socket_out_send(state, state->ev, state->addr,
+					      139, 5000);
+		if (tevent_req_nomem(subreq, req)) {
+			return;
+		}
+		tevent_req_set_callback(subreq, nb_connect_connected, req);
+		return;
+	}
+
+	tevent_req_done(req);
+	return;
+
+}
+
+static NTSTATUS nb_connect_recv(struct tevent_req *req, int *sock)
+{
+	struct nb_connect_state *state = tevent_req_data(
+		req, struct nb_connect_state);
+	NTSTATUS status;
+
+	if (tevent_req_is_nterror(req, &status)) {
+		return status;
+	}
+	*sock = state->sock;
+	state->sock = -1;
+	return NT_STATUS_OK;
+}
+
+struct smbsock_connect_state {
+	struct tevent_context *ev;
+	const struct sockaddr_storage *addr;
+	const char *called_name;
+	const char *calling_name;
+	struct tevent_req *req_139;
+	struct tevent_req *req_445;
+	int sock;
+	uint16_t port;
+};
+
+static int smbsock_connect_state_destructor(
+	struct smbsock_connect_state *state);
+static void smbsock_connect_connected(struct tevent_req *subreq);
+static void smbsock_connect_do_139(struct tevent_req *subreq);
+
+struct tevent_req *smbsock_connect_send(TALLOC_CTX *mem_ctx,
+					struct tevent_context *ev,
+					const struct sockaddr_storage *addr,
+					const char *called_name,
+					const char *calling_name)
+{
+	struct tevent_req *req, *subreq;
+	struct smbsock_connect_state *state;
+
+	req = tevent_req_create(mem_ctx, &state, struct smbsock_connect_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	state->ev = ev;
+	state->addr = addr;
+	state->sock = -1;
+	state->called_name =
+		(called_name != NULL) ? called_name : "*SMBSERVER";
+	state->calling_name =
+		(calling_name != NULL) ? calling_name : global_myname();
+
+	talloc_set_destructor(state, smbsock_connect_state_destructor);
+
+	state->req_445 = open_socket_out_send(state, ev, addr, 445, 5000);
+	if (tevent_req_nomem(state->req_445, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(state->req_445, smbsock_connect_connected,
+				req);
+
+	/*
+	 * After 5 msecs, fire the 139 request
+	 */
+	subreq = tevent_wakeup_send(state, ev, timeval_current_ofs(0, 5000));
+	if (tevent_req_nomem(subreq, req)) {
+		TALLOC_FREE(state->req_445);
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, smbsock_connect_do_139, req);
+	return req;
+}
+
+static int smbsock_connect_state_destructor(
+	struct smbsock_connect_state *state)
+{
+	if (state->sock != -1) {
+		close(state->sock);
+	}
+	return 0;
+}
+
+static void smbsock_connect_do_139(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct smbsock_connect_state *state = tevent_req_data(
+		req, struct smbsock_connect_state);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list