Merge branch 'master' of git://git.samba.org/samba into teventfix
[samba.git] / source4 / libcli / cldap / cldap.c
index d10eeb8ffd7e7e4f36bdc53aca76e7e4a4444e76..b18ba12b1fc2ac8a77681bed834c6a1154fa2fcc 100644 (file)
 
 #include "includes.h"
 #include "lib/events/events.h"
-#include "lib/util/dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "libcli/ldap/ldap.h"
 #include "libcli/ldap/ldap_ndr.h"
 #include "libcli/cldap/cldap.h"
 #include "lib/socket/socket.h"
 #include "libcli/security/security.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
-#include "param/param.h"
 
 /*
   destroy a pending request
@@ -109,7 +108,7 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
        }
 
        /* this initial decode is used to find the message id */
-       status = ldap_decode(asn1, ldap_msg);
+       status = ldap_decode(asn1, NULL, ldap_msg);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(2,("Failed to decode ldap message: %s\n", nt_errstr(status)));
                talloc_free(tmp_ctx);
@@ -145,11 +144,11 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
 /*
   handle request timeouts
 */
-static void cldap_request_timeout(struct event_context *event_ctx, 
-                                 struct timed_event *te, struct timeval t,
-                                 void *private)
+static void cldap_request_timeout(struct tevent_context *event_ctx, 
+                                 struct tevent_timer *te, struct timeval t,
+                                 void *private_data)
 {
-       struct cldap_request *req = talloc_get_type(private, struct cldap_request);
+       struct cldap_request *req = talloc_get_type(private_data, struct cldap_request);
 
        /* possibly try again */
        if (req->num_retries != 0) {
@@ -224,10 +223,10 @@ static void cldap_socket_send(struct cldap_socket *cldap)
 /*
   handle fd events on a cldap_socket
 */
-static void cldap_socket_handler(struct event_context *ev, struct fd_event *fde,
-                                uint16_t flags, void *private)
+static void cldap_socket_handler(struct tevent_context *ev, struct tevent_fd *fde,
+                                uint16_t flags, void *private_data)
 {
-       struct cldap_socket *cldap = talloc_get_type(private, struct cldap_socket);
+       struct cldap_socket *cldap = talloc_get_type(private_data, struct cldap_socket);
        if (flags & EVENT_FD_WRITE) {
                cldap_socket_send(cldap);
        } 
@@ -241,7 +240,7 @@ static void cldap_socket_handler(struct event_context *ev, struct fd_event *fde,
   then operations will use that event context
 */
 struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx, 
-                                      struct event_context *event_ctx,
+                                      struct tevent_context *event_ctx,
                                       struct smb_iconv_convenience *iconv_convenience)
 {
        struct cldap_socket *cldap;
@@ -250,11 +249,7 @@ struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx,
        cldap = talloc(mem_ctx, struct cldap_socket);
        if (cldap == NULL) goto failed;
 
-       if (event_ctx == NULL) {
-               cldap->event_ctx = event_context_init(cldap);
-       } else {
-               cldap->event_ctx = talloc_reference(cldap, event_ctx);
-       }
+       cldap->event_ctx = talloc_reference(cldap, event_ctx);
        if (cldap->event_ctx == NULL) goto failed;
 
        cldap->idr = idr_init(cldap);
@@ -287,10 +282,10 @@ failed:
 NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
                                  void (*handler)(struct cldap_socket *, struct ldap_message *, 
                                                  struct socket_address *),
-                                 void *private)
+                                 void *private_data)
 {
        cldap->incoming.handler = handler;
-       cldap->incoming.private = private;
+       cldap->incoming.private_data = private_data;
        EVENT_FD_READABLE(cldap->fde);
        return NT_STATUS_OK;
 }
@@ -348,7 +343,7 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
                goto failed;
        }
 
-       if (!ldap_encode(msg, &req->encoded, req)) {
+       if (!ldap_encode(msg, NULL, &req->encoded, req)) {
                DEBUG(0,("Failed to encode cldap message to %s:%d\n",
                         req->dest->addr, req->dest->port));
                goto failed;
@@ -401,7 +396,7 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
                msg->type = LDAP_TAG_SearchResultEntry;
                msg->r.SearchResultEntry = *io->response;
 
-               if (!ldap_encode(msg, &blob1, req)) {
+               if (!ldap_encode(msg, NULL, &blob1, req)) {
                        DEBUG(0,("Failed to encode cldap message to %s:%d\n",
                                 req->dest->addr, req->dest->port));
                        status = NT_STATUS_INVALID_PARAMETER;
@@ -414,7 +409,7 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
        msg->type = LDAP_TAG_SearchResultDone;
        msg->r.SearchResultDone = *io->result;
 
-       if (!ldap_encode(msg, &blob2, req)) {
+       if (!ldap_encode(msg, NULL, &blob2, req)) {
                DEBUG(0,("Failed to encode cldap message to %s:%d\n",
                         req->dest->addr, req->dest->port));
                status = NT_STATUS_INVALID_PARAMETER;
@@ -468,7 +463,7 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
        ldap_msg = talloc(mem_ctx, struct ldap_message);
        NT_STATUS_HAVE_NO_MEMORY(ldap_msg);
 
-       status = ldap_decode(req->asn1, ldap_msg);
+       status = ldap_decode(req->asn1, NULL, ldap_msg);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(2,("Failed to decode cldap search reply: %s\n", nt_errstr(status)));
                talloc_free(req);
@@ -484,7 +479,7 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
                *io->out.response = ldap_msg->r.SearchResultEntry;
 
                /* decode the 2nd part */
-               status = ldap_decode(req->asn1, ldap_msg);
+               status = ldap_decode(req->asn1, NULL, ldap_msg);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(2,("Failed to decode cldap search result entry: %s\n", nt_errstr(status)));
                        talloc_free(req);
@@ -599,10 +594,12 @@ NTSTATUS cldap_netlogon_recv(struct cldap_request *req,
                             struct cldap_netlogon *io)
 {
        NTSTATUS status;
-       enum ndr_err_code ndr_err;
        struct cldap_search search;
+       struct cldap_socket *cldap;
        DATA_BLOB *data;
 
+       cldap = req->cldap;
+
        status = cldap_search_recv(req, mem_ctx, &search);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -619,18 +616,15 @@ NTSTATUS cldap_netlogon_recv(struct cldap_request *req,
        }
        data = search.out.response->attributes[0].values;
 
-       ndr_err = ndr_pull_union_blob_all(data, mem_ctx, 
-                                         req->cldap->iconv_convenience,
-                                         &io->out.netlogon,
-                                         io->in.version & 0xF,
-                                         (ndr_pull_flags_fn_t)ndr_pull_nbt_cldap_netlogon);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               DEBUG(2,("cldap failed to parse netlogon response of type 0x%02x\n",
-                        SVAL(data->data, 0)));
-               dump_data(10, data->data, data->length);
-               return ndr_map_error2ntstatus(ndr_err);
+       status = pull_netlogon_samlogon_response(data, mem_ctx, req->cldap->iconv_convenience,
+                                                &io->out.netlogon);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       
+       if (io->in.map_response) {
+               map_netlogon_samlogon_response(&io->out.netlogon);
        }
-
        return NT_STATUS_OK;
 }
 
@@ -705,25 +699,20 @@ NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
                              uint32_t message_id,
                              struct socket_address *src,
                              uint32_t version,
-                             union nbt_cldap_netlogon *netlogon)
+                             struct netlogon_samlogon_response *netlogon)
 {
        NTSTATUS status;
-       enum ndr_err_code ndr_err;
        struct cldap_reply reply;
        struct ldap_SearchResEntry response;
        struct ldap_Result result;
        TALLOC_CTX *tmp_ctx = talloc_new(cldap);
        DATA_BLOB blob;
 
-       ndr_err = ndr_push_union_blob(&blob, tmp_ctx, 
-                                     cldap->iconv_convenience,
-                                     netlogon, version & 0xF,
-                                    (ndr_push_flags_fn_t)ndr_push_nbt_cldap_netlogon);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               talloc_free(tmp_ctx);
-               return ndr_map_error2ntstatus(ndr_err);
+       status = push_netlogon_samlogon_response(&blob, tmp_ctx, cldap->iconv_convenience,
+                                                netlogon);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
-
        reply.messageid    = message_id;
        reply.dest         = src;
        reply.response     = &response;