libcli/cldap: make sure the local and remote address family matches
authorStefan Metzmacher <metze@samba.org>
Fri, 21 Oct 2011 07:49:30 +0000 (09:49 +0200)
committerKarolin Seeger <kseeger@samba.org>
Wed, 16 Nov 2011 19:36:17 +0000 (20:36 +0100)
metze

Signed-off-by: Matthieu Patou <mat@matws.net>
(cherry picked from commit 66530e91498cfa77a9d2e3a031f8a2e1c5ee6804)

libcli/cldap/cldap.c

index f5585c2b730e16d7cd0484233f4ed20f0d6700da..443292113ef4d8c56b7c3cd796f48f66e03b0501 100644 (file)
@@ -313,6 +313,27 @@ NTSTATUS cldap_socket_init(TALLOC_CTX *mem_ctx,
        struct tsocket_address *any = NULL;
        NTSTATUS status;
        int ret;
+       const char *fam = NULL;
+
+       if (local_addr == NULL && remote_addr == NULL) {
+               return NT_STATUS_INVALID_PARAMETER_MIX;
+       }
+
+       if (remote_addr) {
+               bool is_ipv4;
+               bool is_ipv6;
+
+               is_ipv4 = tsocket_address_is_inet(remote_addr, "ipv4");
+               is_ipv6 = tsocket_address_is_inet(remote_addr, "ipv6");
+
+               if (is_ipv4) {
+                       fam = "ipv4";
+               } else if (is_ipv6) {
+                       fam = "ipv6";
+               } else {
+                       return NT_STATUS_INVALID_ADDRESS;
+               }
+       }
 
        c = talloc_zero(mem_ctx, struct cldap_socket);
        if (!c) {
@@ -329,11 +350,10 @@ NTSTATUS cldap_socket_init(TALLOC_CTX *mem_ctx,
        c->event.ctx = ev;
 
        if (!local_addr) {
-               /* we use ipv4 here instead of ip, as otherwise we end
-                  up with a PF_INET6 socket, and sendto() for ipv4
-                  addresses will fail. That breaks cldap name
-                  resolution for winbind to IPv4 hosts. */
-               ret = tsocket_address_inet_from_strings(c, "ipv4",
+               /*
+                * Here we the address family of the remote address.
+                */
+               ret = tsocket_address_inet_from_strings(c, fam,
                                                        NULL, 0,
                                                        &any);
                if (ret != 0) {