s4-cldap: fix cldap_socket_init to always specify the dest if local is NULL
authorMatthieu Patou <mat@matws.net>
Fri, 21 Oct 2011 18:09:37 +0000 (20:09 +0200)
committerMatthieu Patou <mat@samba.org>
Fri, 21 Oct 2011 22:01:59 +0000 (00:01 +0200)
Autobuild-User: Matthieu Patou <mat@samba.org>
Autobuild-Date: Sat Oct 22 00:02:00 CEST 2011 on sn-devel-104

source4/libcli/finddcs_cldap.c

index 0643135cae9f1a4a4e2e79ffd15b77d61b3e9527..6df15a9b4e80ce8a4cc13554dd7530e7ffd6d773 100644 (file)
@@ -27,6 +27,7 @@
 #include "libcli/finddc.h"
 #include "libcli/security/security.h"
 #include "lib/util/tevent_ntstatus.h"
+#include "lib/tsocket/tsocket.h"
 #include "libcli/composite/composite.h"
 
 struct finddcs_cldap_state {
@@ -131,10 +132,6 @@ static bool finddcs_cldap_ipaddress(struct finddcs_cldap_state *state, struct fi
        }
        state->srv_addresses[1] = NULL;
        state->srv_address_index = 0;
-       status = cldap_socket_init(state, NULL, NULL, &state->cldap);
-       if (tevent_req_nterror(state->req, status)) {
-               return false;
-       }
 
        finddcs_cldap_next_server(state);
        return tevent_req_is_nterror(state->req, &status);
@@ -201,6 +198,9 @@ static bool finddcs_cldap_nbt_lookup(struct finddcs_cldap_state *state,
 static void finddcs_cldap_next_server(struct finddcs_cldap_state *state)
 {
        struct tevent_req *subreq;
+       struct tsocket_address *dest;
+       int ret;
+       NTSTATUS status;
 
        if (state->srv_addresses[state->srv_address_index] == NULL) {
                tevent_req_nterror(state->req, NT_STATUS_OBJECT_NAME_NOT_FOUND);
@@ -208,14 +208,25 @@ static void finddcs_cldap_next_server(struct finddcs_cldap_state *state)
                return;
        }
 
+       /* we should get the port from the SRV response */
+       ret = tsocket_address_inet_from_strings(state, "ip",
+                                               state->srv_addresses[state->srv_address_index],
+                                               389,
+                                               &dest);
+       if (tevent_req_error(state->req, ret)) {
+               return;
+       }
+
+       status = cldap_socket_init(state, NULL, dest, &state->cldap);
+       if (tevent_req_nterror(state->req, status)) {
+               return;
+       }
+
        state->netlogon = talloc_zero(state, struct cldap_netlogon);
        if (tevent_req_nomem(state->netlogon, state->req)) {
                return;
        }
 
-       state->netlogon->in.dest_address = state->srv_addresses[state->srv_address_index];
-       /* we should get the port from the SRV response */
-       state->netlogon->in.dest_port = 389;
        if (strchr(state->domain_name, '.')) {
                state->netlogon->in.realm = state->domain_name;
        }
@@ -307,11 +318,6 @@ static void finddcs_cldap_name_resolved(struct composite_context *ctx)
 
        state->srv_address_index = 0;
 
-       status = cldap_socket_init(state, NULL, NULL, &state->cldap);
-       if (tevent_req_nterror(state->req, status)) {
-               return;
-       }
-
        finddcs_cldap_next_server(state);
 }
 
@@ -338,11 +344,6 @@ static void finddcs_cldap_srv_resolved(struct composite_context *ctx)
 
        state->srv_address_index = 0;
 
-       status = cldap_socket_init(state, NULL, NULL, &state->cldap);
-       if (tevent_req_nterror(state->req, status)) {
-               return;
-       }
-
        finddcs_cldap_next_server(state);
 }