The branch, v3-6-test has been updated
       via  7a1e041 s3:lib/gencache: fix memory leak in error path
       via  591a22dd s3: Remove unused open_any_socket_out
       via  e5cd7c5 s3: Use smbsock_any_connect in winbind (cherry picked from 
commit 5d4ac40f69aed6de033c0ca637dbab02db01740b)
       via  54e258c s3: Retry *SMBSERVER in nb_connect (cherry picked from 
commit d5188fcd185f518c2b2b78f9e4aa6c49b3d139c7)
       via  a3097d0 s3: Test smbsock_any_connect (cherry picked from commit 
3ae7ef73b020789634df40d4b74dd4bad36ba4fa)
       via  b21ee1a s3: Add smbsock_any_connect (cherry picked from commit 
d8e3d0af9e52c46fa2ab37dc263ae3a5ea5ce020)
       via  fbfd083 s3: Add an async smbsock_connect
       via  9c879ee s3: Add async cli_session_request
       via  8f64b1b s3: Add some const to name_mangle() (cherry picked from 
commit 444dcc59c2b0fe616c833efa75a061c46ac12274)
      from  7cdea69 All calls to event_add_to_select_args() call GetTimeOfDay() 
and pass this in as the &now parameter. Push this call inside of 
event_add_to_select_args() to the correct point so it doesn't get called unless 
needed.

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


- Log -----------------------------------------------------------------
commit 7a1e041252e47e3bece0c1d44c6c2da2a4d55cdd
Author: Stefan Metzmacher <me...@samba.org>
Date:   Fri Dec 17 13:26:16 2010 +0100

    s3:lib/gencache: fix memory leak in error path
    
    metze
    
    Autobuild-User: Stefan Metzmacher <me...@samba.org>
    Autobuild-Date: Wed Dec 22 15:08:30 CET 2010 on sn-devel-104
    (cherry picked from commit d9be7e9368fc373a2b7978228ce723869f0ad0ac)

commit 591a22dd079e069d1e5540af5fa913376a0d3d2a
Author: Volker Lendecke <v...@samba.org>
Date:   Wed Dec 22 14:40:16 2010 +0100

    s3: Remove unused open_any_socket_out
    
    Autobuild-User: Volker Lendecke <vlen...@samba.org>
    Autobuild-Date: Wed Dec 22 17:27:29 CET 2010 on sn-devel-104
    (cherry picked from commit 03b8b8e19952c40eb3eb22e16e7fbae4073b7b4b)

commit e5cd7c56d5954c5af75f6291e305202bbef3a929
Author: Volker Lendecke <v...@samba.org>
Date:   Tue Dec 21 21:55:01 2010 +0100

    s3: Use smbsock_any_connect in winbind
    (cherry picked from commit 5d4ac40f69aed6de033c0ca637dbab02db01740b)

commit 54e258cc2fa589ca9873638bb9e0c3aa40c43679
Author: Volker Lendecke <v...@samba.org>
Date:   Tue Dec 21 18:52:53 2010 +0100

    s3: Retry *SMBSERVER in nb_connect
    (cherry picked from commit d5188fcd185f518c2b2b78f9e4aa6c49b3d139c7)

commit a3097d028e0223a6824fb06e071683f791429e74
Author: Volker Lendecke <v...@samba.org>
Date:   Tue Dec 14 12:50:57 2010 +0100

    s3: Test smbsock_any_connect
    (cherry picked from commit 3ae7ef73b020789634df40d4b74dd4bad36ba4fa)

commit b21ee1a40b5a90ba79a281004ee93a939888cac0
Author: Volker Lendecke <v...@samba.org>
Date:   Mon Dec 13 17:17:51 2010 +0100

    s3: Add smbsock_any_connect
    (cherry picked from commit d8e3d0af9e52c46fa2ab37dc263ae3a5ea5ce020)

commit fbfd083de828d18e853f9a1d886b5cff5ce7b52a
Author: Volker Lendecke <v...@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.
    (cherry picked from commit 49cd92b2186addebba79efffc435083e6086aab1)

commit 9c879ee628a0d5e3ce7eb80b06dcce4f6c8d488b
Author: Volker Lendecke <v...@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
    (cherry picked from commit 02a74fd36db962eaf6da14b920bccbee7d25f07e)

commit 8f64b1bb510a07b062bae187f55010e085478ab6
Author: Volker Lendecke <v...@samba.org>
Date:   Sun Dec 12 18:53:49 2010 +0100

    s3: Add some const to name_mangle()
    (cherry picked from commit 444dcc59c2b0fe616c833efa75a061c46ac12274)

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

Summary of changes:
 source3/Makefile.in                        |    2 +
 source3/include/async_smb.h                |    7 +
 source3/include/proto.h                    |   26 ++-
 source3/lib/gencache.c                     |    3 +
 source3/lib/util_sock.c                    |  165 --------
 source3/libsmb/async_smb.c                 |  127 ++++++
 source3/libsmb/nmblib.c                    |    2 +-
 source3/libsmb/smbsock_connect.c           |  573 ++++++++++++++++++++++++++++
 source3/torture/proto.h                    |    1 +
 source3/torture/test_smbsock_any_connect.c |   46 +++
 source3/torture/torture.c                  |    1 +
 source3/winbindd/winbindd_cm.c             |   58 +---
 12 files changed, 797 insertions(+), 214 deletions(-)
 create mode 100644 source3/libsmb/smbsock_connect.c
 create mode 100644 source3/torture/test_smbsock_any_connect.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index c1b6c8b..874c2a8 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -592,6 +592,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o 
libsmb/clifile.o \
             libsmb/clioplock.o libsmb/clirap2.o \
             libsmb/smb_seal.o libsmb/async_smb.o \
             libsmb/cli_np_tstream.o \
+            libsmb/smbsock_connect.o \
             $(LIBSAMBA_OBJ) \
             $(LIBNMB_OBJ) \
             $(LIBNBT_OBJ) \
@@ -1198,6 +1199,7 @@ SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o 
torture/scanner.o torture/uta
                torture/denytest.o torture/mangle_test.o \
                torture/nbench.o \
                torture/test_async_echo.o \
+               torture/test_smbsock_any_connect.o \
                torture/test_posix_append.o
 
 SMBTORTURE_OBJ = $(SMBTORTURE_OBJ1) $(PARAM_OBJ) $(TLDAP_OBJ) \
diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h
index b73aed0..d2303cc 100644
--- a/source3/include/async_smb.h
+++ b/source3/include/async_smb.h
@@ -69,4 +69,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 403cf0b..2541ac3 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1331,8 +1331,6 @@ struct tevent_req *open_socket_out_defer_send(TALLOC_CTX 
*mem_ctx,
                                              uint16_t port,
                                              int timeout);
 NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd);
-bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
-                        int timeout, int *fd_index, int *fd);
 int open_udp_socket(const char *host, int port);
 const char *get_peer_name(int fd, bool force_lookup);
 const char *get_peer_addr(int fd, char *addr, size_t addr_len);
@@ -2788,7 +2786,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);
 
@@ -5619,6 +5617,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( struct security_descriptor *psd, struct 
security_token *token,
                              enum sec_privilege needed_priv_1, enum 
sec_privilege needed_priv_2,
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index db0b179..7bab925 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -431,6 +431,9 @@ fail:
        if (was_expired != NULL) {
                *was_expired = expired;
        }
+       if (state.result && state.blob) {
+               data_blob_free(state.blob);
+       }
        return false;
 } 
 
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 64cd74c..8b25e01 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1111,171 +1111,6 @@ NTSTATUS open_socket_out_defer_recv(struct tevent_req 
*req, int *pfd)
        return NT_STATUS_OK;
 }
 
-/*******************************************************************
- Create an outgoing TCP socket to the first addr that connects.
-
- This is for simultaneous connection attempts to port 445 and 139 of a host
- or for simultatneous connection attempts to multiple DCs at once.  We return
- a socket fd of the first successful connection.
-
- @param[in] addrs list of Internet addresses and ports to connect to
- @param[in] num_addrs number of address/port pairs in the addrs list
- @param[in] timeout time after which we stop waiting for a socket connection
-            to succeed, given in milliseconds
- @param[out] fd_index the entry in addrs which we successfully connected to
- @param[out] fd fd of the open and connected socket
- @return true on a successful connection, false if all connection attempts
-         failed or we timed out
-*******************************************************************/
-
-bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
-                        int timeout, int *fd_index, int *fd)
-{
-       int i, resulting_index, res;
-       int *sockets;
-       bool good_connect;
-
-       fd_set r_fds, wr_fds;
-       struct timeval tv;
-       int maxfd;
-
-       int connect_loop = 10000; /* 10 milliseconds */
-
-       timeout *= 1000;        /* convert to microseconds */
-
-       sockets = SMB_MALLOC_ARRAY(int, num_addrs);
-
-       if (sockets == NULL)
-               return false;
-
-       resulting_index = -1;
-
-       for (i=0; i<num_addrs; i++)
-               sockets[i] = -1;
-
-       for (i=0; i<num_addrs; i++) {
-               sockets[i] = socket(addrs[i].ss_family, SOCK_STREAM, 0);
-               if (sockets[i] < 0)
-                       goto done;
-               set_blocking(sockets[i], false);
-       }
-
- connect_again:
-       good_connect = false;
-
-       for (i=0; i<num_addrs; i++) {
-               const struct sockaddr * a = 
-                   (const struct sockaddr *)&(addrs[i]);
-
-               if (sockets[i] == -1)
-                       continue;
-
-               if (sys_connect(sockets[i], a) == 0) {
-                       /* Rather unlikely as we are non-blocking, but it
-                        * might actually happen. */
-                       resulting_index = i;
-                       goto done;
-               }
-
-               if (errno == EINPROGRESS || errno == EALREADY ||
-#ifdef EISCONN
-                       errno == EISCONN ||
-#endif
-                   errno == EAGAIN || errno == EINTR) {
-                       /* These are the error messages that something is
-                          progressing. */
-                       good_connect = true;
-               } else if (errno != 0) {
-                       /* There was a direct error */
-                       close(sockets[i]);
-                       sockets[i] = -1;
-               }
-       }
-
-       if (!good_connect) {
-               /* All of the connect's resulted in real error conditions */
-               goto done;
-       }
-
-       /* Lets see if any of the connect attempts succeeded */
-
-       maxfd = 0;
-       FD_ZERO(&wr_fds);
-       FD_ZERO(&r_fds);
-
-       for (i=0; i<num_addrs; i++) {
-               if (sockets[i] == -1)
-                       continue;
-               FD_SET(sockets[i], &wr_fds);
-               FD_SET(sockets[i], &r_fds);
-               if (sockets[i]>maxfd)
-                       maxfd = sockets[i];
-       }
-
-       tv.tv_sec = 0;
-       tv.tv_usec = connect_loop;
-
-       res = sys_select_intr(maxfd+1, &r_fds, &wr_fds, NULL, &tv);
-
-       if (res < 0)
-               goto done;
-
-       if (res == 0)
-               goto next_round;
-
-       for (i=0; i<num_addrs; i++) {
-
-               if (sockets[i] == -1)
-                       continue;
-
-               /* Stevens, Network Programming says that if there's a
-                * successful connect, the socket is only writable. Upon an
-                * error, it's both readable and writable. */
-
-               if (FD_ISSET(sockets[i], &r_fds) &&
-                   FD_ISSET(sockets[i], &wr_fds)) {
-                       /* readable and writable, so it's an error */
-                       close(sockets[i]);
-                       sockets[i] = -1;
-                       continue;
-               }
-
-               if (!FD_ISSET(sockets[i], &r_fds) &&
-                   FD_ISSET(sockets[i], &wr_fds)) {
-                       /* Only writable, so it's connected */
-                       resulting_index = i;
-                       goto done;
-               }
-       }
-
- next_round:
-
-       timeout -= connect_loop;
-       if (timeout <= 0)
-               goto done;
-       connect_loop *= 1.5;
-       if (connect_loop > timeout)
-               connect_loop = timeout;
-       goto connect_again;
-
- done:
-       for (i=0; i<num_addrs; i++) {
-               if (i == resulting_index)
-                       continue;
-               if (sockets[i] >= 0)
-                       close(sockets[i]);
-       }
-
-       if (resulting_index >= 0) {
-               *fd_index = resulting_index;
-               *fd = sockets[*fd_index];
-               set_blocking(*fd, true);
-       }
-
-       free(sockets);
-
-       return (resulting_index >= 0);
-}
 /****************************************************************************
  Open a connected UDP socket to host on port
 **************************************************************************/
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index b04c274..24df6a6 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -1095,3 +1095,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 943cbcb..e10bd7a 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -1293,7 +1293,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;
+}


-- 
Samba Shared Repository

Reply via email to