The branch, master has been updated
       via  8e22e38c9c4a08f9f49f3f8f29dab8d6a948948e (commit)
       via  f5321ffea8fd9e3b4cbf236883664832a0425075 (commit)
       via  55dae4469c1c2ba571bfaeb93de7494480e0d72b (commit)
       via  c687eb15d953006f1de1e02abad40365040a29f1 (commit)
      from  53b9a24ce38acc79d8086b502f0e8ff048ef67bc (commit)

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


- Log -----------------------------------------------------------------
commit 8e22e38c9c4a08f9f49f3f8f29dab8d6a948948e
Author: Volker Lendecke <[email protected]>
Date:   Sat Jun 27 20:03:55 2009 +0200

    Move read_ldap_done after read_ldap_send

commit f5321ffea8fd9e3b4cbf236883664832a0425075
Author: Volker Lendecke <[email protected]>
Date:   Sat Jun 27 18:14:25 2009 +0200

    Convert tldap to tstream

commit 55dae4469c1c2ba571bfaeb93de7494480e0d72b
Author: Volker Lendecke <[email protected]>
Date:   Sat Jun 27 17:21:19 2009 +0200

    Add tstream_read_packet

commit c687eb15d953006f1de1e02abad40365040a29f1
Author: Volker Lendecke <[email protected]>
Date:   Sat Jun 27 20:04:37 2009 +0200

    Properly free a downlevel readv request. Metze, please check

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

Summary of changes:
 lib/tsocket/tsocket.c      |    1 +
 source3/Makefile.in        |    6 +-
 source3/include/includes.h |    1 +
 source3/include/proto.h    |   10 +++
 source3/lib/tldap.c        |   71 ++++++++++++----------
 source3/lib/util_tsock.c   |  139 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 193 insertions(+), 35 deletions(-)
 create mode 100644 source3/lib/util_tsock.c


Changeset truncated at 500 lines:

diff --git a/lib/tsocket/tsocket.c b/lib/tsocket/tsocket.c
index e05c8d5..55f1af3 100644
--- a/lib/tsocket/tsocket.c
+++ b/lib/tsocket/tsocket.c
@@ -594,6 +594,7 @@ static void tstream_readv_done(struct tevent_req *subreq)
        int sys_errno;
 
        ret = state->ops->readv_recv(subreq, &sys_errno);
+       TALLOC_FREE(subreq);
        if (ret == -1) {
                tevent_req_error(req, sys_errno);
                return;
diff --git a/source3/Makefile.in b/source3/Makefile.in
index ddc344d..cdca9c1 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -486,7 +486,7 @@ CLDAP_OBJ = libads/cldap.o \
        ../lib/util/idtree.o \
        $(LIBCLI_LDAP_MESSAGE_OBJ) $(LIBCLI_LDAP_NDR_OBJ) $(LIBTSOCKET_OBJ)
 
-TLDAP_OBJ = lib/tldap.o lib/tldap_util.o
+TLDAP_OBJ = lib/tldap.o lib/tldap_util.o lib/util_tsock.o
 
 LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
             libsmb/clikrb5.o libsmb/clispnego.o ../lib/util/asn1.o \
@@ -859,7 +859,7 @@ SMBPASSWD_OBJ = utils/smbpasswd.o $(PASSWD_UTIL_OBJ) 
$(PASSCHANGE_OBJ) \
                $(LIBMSRPC_GEN_OBJ) $(LIBMSRPC_OBJ) $(LDB_OBJ)
 
 PDBEDIT_OBJ = utils/pdbedit.o $(PASSWD_UTIL_OBJ) $(PARAM_OBJ) $(PASSDB_OBJ) \
-               $(LIBSAMBA_OBJ) \
+               $(LIBSAMBA_OBJ) $(LIBTSOCKET_OBJ) \
                $(LIB_NONSMBD_OBJ) $(GROUPDB_OBJ) \
                $(POPT_LIB_OBJ) $(SMBLDAP_OBJ) ../lib/util/asn1.o \
                $(LDB_OBJ)
@@ -1219,7 +1219,7 @@ NTLM_AUTH_OBJ1 = utils/ntlm_auth.o 
utils/ntlm_auth_diagnostics.o
 NTLM_AUTH_OBJ = ${NTLM_AUTH_OBJ1} $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \
                ../lib/util/asn1.o libsmb/spnego.o libsmb/clikrb5.o 
libads/kerberos.o \
                $(LIBADS_SERVER_OBJ) \
-               $(PASSDB_OBJ) $(GROUPDB_OBJ) \
+               $(PASSDB_OBJ) $(LIBTSOCKET_OBJ) $(GROUPDB_OBJ) \
                $(SMBLDAP_OBJ) $(LIBNMB_OBJ) \
                $(LDB_OBJ) $(WBCOMMON_OBJ) \
                $(LIBNDR_GEN_OBJ0) $(LIBNDR_GEN_OBJ1) @BUILD_INIPARSER@
diff --git a/source3/include/includes.h b/source3/include/includes.h
index b7ba703..c1aeaf9 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -611,6 +611,7 @@ struct smb_iconv_convenience *lp_iconv_convenience(void 
*lp_ctx);
 #include "event.h"
 #include "../lib/util/tevent_unix.h"
 #include "../lib/util/tevent_ntstatus.h"
+#include "../lib/tsocket/tsocket.h"
 
 #include "../lib/util/data_blob.h"
 #include "../lib/util/time.h"
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 3da1caf..07a749d 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1418,6 +1418,16 @@ struct tevent_req *getaddrinfo_send(TALLOC_CTX *mem_ctx,
                                    const char *service,
                                    const struct addrinfo *hints);
 int getaddrinfo_recv(struct tevent_req *req, struct addrinfo **res);
+struct tevent_req *tstream_read_packet_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct tstream_context *stream,
+                                           size_t initial,
+                                           ssize_t (*more)(uint8_t *buf,
+                                                           size_t buflen,
+                                                           void *private_data),
+                                           void *private_data);
+ssize_t tstream_read_packet_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                uint8_t **pbuf, int *perrno);
 
 /* The following definitions come from lib/util_str.c  */
 
diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index 0f9e678..aba8a25 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -54,7 +54,7 @@ struct tldap_context {
        int ld_deref;
        int ld_sizelimit;
        int ld_timelimit;
-       int fd;
+       struct tstream_context *conn;
        int msgid;
        struct tevent_queue *outgoing;
        struct tevent_req **pending;
@@ -132,12 +132,17 @@ static int tldap_next_msgid(struct tldap_context *ld)
 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd)
 {
        struct tldap_context *ctx;
+       int ret;
 
        ctx = talloc_zero(mem_ctx, struct tldap_context);
        if (ctx == NULL) {
                return NULL;
        }
-       ctx->fd = fd;
+       ret = tstream_bsd_existing_socket(ctx, fd, &ctx->conn);
+       if (ret == -1) {
+               TALLOC_FREE(ctx);
+               return NULL;
+       }
        ctx->msgid = 1;
        ctx->ld_version = 3;
        ctx->outgoing = tevent_queue_create(ctx, "tldap_outgoing");
@@ -224,6 +229,31 @@ struct read_ldap_state {
        bool done;
 };
 
+static ssize_t read_ldap_more(uint8_t *buf, size_t buflen, void *private_data);
+static void read_ldap_done(struct tevent_req *subreq);
+
+static struct tevent_req *read_ldap_send(TALLOC_CTX *mem_ctx,
+                                        struct tevent_context *ev,
+                                        struct tstream_context *conn)
+{
+       struct tevent_req *req, *subreq;
+       struct read_ldap_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct read_ldap_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->done = false;
+
+       subreq = tstream_read_packet_send(state, ev, conn, 2, read_ldap_more,
+                                         state);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, read_ldap_done, req);
+       return req;
+}
+
 static ssize_t read_ldap_more(uint8_t *buf, size_t buflen, void *private_data)
 {
        struct read_ldap_state *state = talloc_get_type_abort(
@@ -270,29 +300,6 @@ static ssize_t read_ldap_more(uint8_t *buf, size_t buflen, 
void *private_data)
        return len;
 }
 
-static void read_ldap_done(struct tevent_req *subreq);
-
-static struct tevent_req *read_ldap_send(TALLOC_CTX *mem_ctx,
-                                        struct tevent_context *ev,
-                                        int fd)
-{
-       struct tevent_req *req, *subreq;
-       struct read_ldap_state *state;
-
-       req = tevent_req_create(mem_ctx, &state, struct read_ldap_state);
-       if (req == NULL) {
-               return NULL;
-       }
-       state->done = false;
-
-       subreq = read_packet_send(state, ev, fd, 2, read_ldap_more, state);
-       if (tevent_req_nomem(subreq, req)) {
-               return tevent_req_post(req, ev);
-       }
-       tevent_req_set_callback(subreq, read_ldap_done, req);
-       return req;
-}
-
 static void read_ldap_done(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
@@ -302,7 +309,7 @@ static void read_ldap_done(struct tevent_req *subreq)
        ssize_t nread;
        int err;
 
-       nread = read_packet_recv(subreq, state, &state->buf, &err);
+       nread = tstream_read_packet_recv(subreq, state, &state->buf, &err);
        TALLOC_FREE(subreq);
        if (nread == -1) {
                tevent_req_error(req, err);
@@ -400,8 +407,8 @@ static struct tevent_req *tldap_msg_send(TALLOC_CTX 
*mem_ctx,
        state->iov.iov_base = blob.data;
        state->iov.iov_len = blob.length;
 
-       subreq = writev_send(state, ev, ld->outgoing, ld->fd, false,
-                            &state->iov, 1);
+       subreq = tstream_writev_queue_send(state, ev, ld->conn, ld->outgoing,
+                                          &state->iov, 1);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -487,7 +494,7 @@ static bool tldap_msg_set_pending(struct tevent_req *req)
         * We're the first ones, add the read_ldap request that waits for the
         * answer from the server
         */
-       subreq = read_ldap_send(ld->pending, state->ev, ld->fd);
+       subreq = read_ldap_send(ld->pending, state->ev, ld->conn);
        if (subreq == NULL) {
                tldap_msg_unset_pending(req);
                return false;
@@ -503,7 +510,7 @@ static void tldap_msg_sent(struct tevent_req *subreq)
        ssize_t nwritten;
        int err;
 
-       nwritten = writev_recv(subreq, &err);
+       nwritten = tstream_writev_queue_recv(subreq, &err);
        TALLOC_FREE(subreq);
        if (nwritten == -1) {
                tevent_req_error(req, TLDAP_SERVER_DOWN);
@@ -610,8 +617,8 @@ static void tldap_msg_received(struct tevent_req *subreq)
                return;
        }
 
-       state = tevent_req_data(ld->pending[0], struct tldap_msg_state);
-       subreq = read_ldap_send(ld->pending, state->ev, ld->fd);
+       state = tevent_req_data(ld->pending[0], struct tldap_msg_state);
+       subreq = read_ldap_send(ld->pending, state->ev, ld->conn);
        if (subreq == NULL) {
                status = TLDAP_NO_MEMORY;
                goto fail;
diff --git a/source3/lib/util_tsock.c b/source3/lib/util_tsock.c
new file mode 100644
index 0000000..7588857
--- /dev/null
+++ b/source3/lib/util_tsock.c
@@ -0,0 +1,139 @@
+/*
+   Unix SMB/CIFS implementation.
+   Utilities around tsocket
+   Copyright (C) Volker Lendecke 2009
+
+   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"
+
+struct tstream_read_packet_state {
+       struct tevent_context *ev;
+       struct tstream_context *stream;
+       ssize_t (*more)(uint8_t *buf, size_t buflen, void *private_data);
+       void *private_data;
+       uint8_t *buf;
+       struct iovec iov;
+};
+
+static void tstream_read_packet_done(struct tevent_req *subreq);
+
+struct tevent_req *tstream_read_packet_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct tstream_context *stream,
+                                           size_t initial,
+                                           ssize_t (*more)(uint8_t *buf,
+                                                           size_t buflen,
+                                                           void *private_data),
+                                           void *private_data)
+{
+       struct tevent_req *req, *subreq;
+       struct tstream_read_packet_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct tstream_read_packet_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->buf = talloc_array(state, uint8_t, initial);
+       if (tevent_req_nomem(state->buf, req)) {
+               return tevent_req_post(req, ev);
+       }
+       state->iov.iov_base = state->buf;
+       state->iov.iov_len = initial;
+
+       state->ev = ev;
+       state->stream = stream;
+       state->more = more;
+       state->private_data = private_data;
+
+       subreq = tstream_readv_send(state, ev, stream, &state->iov, 1);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, tstream_read_packet_done, req);
+
+       return req;
+}
+
+static void tstream_read_packet_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct tstream_read_packet_state *state = tevent_req_data(
+               req, struct tstream_read_packet_state);
+       int ret, err;
+       size_t total;
+       ssize_t more;
+       uint8_t *tmp;
+
+       ret = tstream_readv_recv(subreq, &err);
+       TALLOC_FREE(subreq);
+       if (ret == 0) {
+               err = EPIPE;
+       }
+       if (ret <= 0) {
+               tevent_req_error(req, err);
+               return;
+       }
+
+       if (state->more == NULL) {
+               /* Nobody to ask, this is a async read_data */
+               tevent_req_done(req);
+               return;
+       }
+       total = talloc_array_length(state->buf);
+
+       more = state->more(state->buf, total, state->private_data);
+       if (more == -1) {
+               /* We got an invalid packet, tell the caller */
+               tevent_req_error(req, EIO);
+               return;
+       }
+       if (more == 0) {
+               /* We're done, full packet received */
+               tevent_req_done(req);
+               return;
+       }
+
+       tmp = talloc_realloc(state, state->buf, uint8_t, total+more);
+       if (tevent_req_nomem(tmp, req)) {
+               return;
+       }
+       state->buf = tmp;
+
+       state->iov.iov_base = state->buf + total;
+       state->iov.iov_len = more;
+
+       subreq = tstream_readv_send(state, state->ev, state->stream,
+                                   &state->iov, 1);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+       tevent_req_set_callback(subreq, tstream_read_packet_done, req);
+}
+
+ssize_t tstream_read_packet_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                uint8_t **pbuf, int *perrno)
+{
+       struct tstream_read_packet_state *state =
+               tevent_req_data(req, struct tstream_read_packet_state);
+
+       if (tevent_req_is_unix_error(req, perrno)) {
+               return -1;
+       }
+       *pbuf = talloc_move(mem_ctx, &state->buf);
+       return talloc_array_length(*pbuf);
+}


-- 
Samba Shared Repository

Reply via email to