torture/attr: use security_ace_equal instead of sec_ace_equal
[samba.git] / nsswitch / winbind_krb5_locator.c
index 272e7dbab153bacc2a28a468e88a31bbce23228f..91a2d64d84c4eafd2b37e642572b27d984546f26 100644 (file)
 
 #if defined(HAVE_KRB5) && defined(HAVE_KRB5_LOCATE_PLUGIN_H)
 
-#include <krb5/krb5.h>
+#if HAVE_COM_ERR_H
+#include <com_err.h>
+#endif
+
+#include <krb5.h>
 #include <krb5/locate_plugin.h>
 
 #ifndef KRB5_PLUGIN_NO_HANDLE
@@ -138,11 +142,10 @@ static int smb_krb5_locator_lookup_sanity_check(enum locate_service_type svc,
        switch (family) {
                case AF_UNSPEC:
                case AF_INET:
-                       break;
 #if defined(HAVE_IPV6)
                case AF_INET6:
-                       break;
 #endif
+                       break;
                default:
                        return EINVAL;
        }
@@ -178,7 +181,8 @@ static krb5_error_code smb_krb5_locator_call_cbfunc(const char *name,
                                                    void *cbdata)
 {
        struct addrinfo *out = NULL;
-       int ret;
+       int ret = 0;
+       struct addrinfo *res = NULL;
        int count = 3;
 
        while (count) {
@@ -188,7 +192,7 @@ static krb5_error_code smb_krb5_locator_call_cbfunc(const char *name,
                        break;
                }
 
-               if (ret == EAI_AGAIN) {
+               if ((ret == EAI_AGAIN) && (count > 1)) {
                        count--;
                        continue;
                }
@@ -202,16 +206,25 @@ static krb5_error_code smb_krb5_locator_call_cbfunc(const char *name,
                return KRB5_PLUGIN_NO_HANDLE;
        }
 
-       ret = cbfunc(cbdata, out->ai_socktype, out->ai_addr);
+       for (res = out; res; res = res->ai_next) {
+               if (!res->ai_addr || res->ai_addrlen == 0) {
+                       continue;
+               }
+
+               ret = cbfunc(cbdata, res->ai_socktype, res->ai_addr);
+               if (ret) {
 #ifdef DEBUG_KRB5
-       if (ret) {
-               fprintf(stderr, "[%5u]: smb_krb5_locator_lookup: "
-                       "failed to call callback: %s (%d)\n",
-                       (unsigned int)getpid(), error_message(ret), ret);
-       }
+                       fprintf(stderr, "[%5u]: smb_krb5_locator_lookup: "
+                               "failed to call callback: %s (%d)\n",
+                               (unsigned int)getpid(), error_message(ret), ret);
 #endif
+                       break;
+               }
+       }
 
-       freeaddrinfo(out);
+       if (out) {
+               freeaddrinfo(out);
+       }
        return ret;
 }
 
@@ -253,8 +266,7 @@ static bool ask_winbind(const char *realm, char **dcname)
 
        flags = WBC_LOOKUP_DC_KDC_REQUIRED |
                WBC_LOOKUP_DC_IS_DNS_NAME |
-               WBC_LOOKUP_DC_RETURN_DNS_NAME |
-               WBC_LOOKUP_DC_IP_REQUIRED;
+               WBC_LOOKUP_DC_RETURN_DNS_NAME;
 
        wbc_status = wbcLookupDomainControllerEx(realm, NULL, NULL, flags, &dc_info);
 
@@ -266,12 +278,6 @@ static bool ask_winbind(const char *realm, char **dcname)
                return false;
        }
 
-       if (dc_info->dc_address) {
-               dc = dc_info->dc_address;
-               if (dc[0] == '\\') dc++;
-               if (dc[0] == '\\') dc++;
-       }
-
        if (!dc && dc_info->dc_unc) {
                dc = dc_info->dc_unc;
                if (dc[0] == '\\') dc++;