Add profile support for libdefaults dns_fallback
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 23 Jul 1999 03:24:30 +0000 (03:24 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 23 Jul 1999 03:24:30 +0000 (03:24 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11589 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/locate_kdc.c

index 6666426e0f58b1ce8a53b868afe556b66e98c3d7..ee81f6c086d43ac983098a1f62adcb6c1e77ee0f 100644 (file)
@@ -545,56 +545,73 @@ krb5_locate_kdc(context, realm, addr_pp, naddrs, master_index, nmasters)
      * We always try the local file first
      */
 
-    code = krb5_locate_srv_conf(context, realm, "kdc", addr_pp, naddrs, 
+    code = krb5_locate_srv_conf(context, realm, "kdc", addr_pp, naddrs,
                                  master_index, nmasters);
 
 #ifdef KRB5_DNS_LOOKUP
     if (code) {
-       code = krb5_locate_srv_dns(realm, "_kerberos", "_udp",
-                                  addr_pp, naddrs);
-        if ( master_index && nmasters ) {
-
-            code = krb5_locate_srv_dns(realm, "_kerberos-adm", "_tcp",
-                                        &admin_addr_p, &nadmin_addrs);
-            if ( code ) {
-                free(*addr_pp);
-                *addr_pp = NULL;
+        int use_dns=0;
+        char * string=NULL;
+        krb5_error_code code2; /* preserve error code from krb5_locate_srv_conf */
+
+        code2 = profile_get_string(context->profile, "libdefaults",
+                                   "dns_fallback", 0, 
+                                    context->profile_in_memory?"1":"0",
+                                    &string);
+        if ( code2 )
+            return(code2);
+
+        if ( string ) {
+            use_dns = krb5_conf_boolean(string);
+            free(string);
+        }
+        if ( use_dns ) {
+            code = krb5_locate_srv_dns(realm, "_kerberos", "_udp",
+                                        addr_pp, naddrs);
+            if ( master_index && nmasters ) {
+
+                code = krb5_locate_srv_dns(realm, "_kerberos-adm", "_tcp",
+                                            &admin_addr_p, &nadmin_addrs);
+                if ( code ) {
+                    free(*addr_pp);
+                    *addr_pp = NULL;
+                    *naddrs = 0;
+                    return(code);
+                } 
+
+                kdc_addr_p = *addr_pp;
+                nkdc_addrs = *naddrs;
+
                 *naddrs = 0;
-                return(code);
-            } 
+                *addr_pp = (struct sockaddr *) malloc(sizeof(*kdc_addr_p));
+                if ( *addr_pp == NULL ) {
+                    free(kdc_addr_p);
+                    free(admin_addr_p);
+                    return ENOMEM;
+                }
 
-            kdc_addr_p = *addr_pp;
-            nkdc_addrs = *naddrs;
+                for ( i=0; i<nkdc_addrs; i++ ) {
+                    for ( j=0 ; j<nadmin_addrs; j++) {
+                        if ( !memcmp(&kdc_addr_p[i].sa_data[2],&admin_addr_p[j].sa_data[2],4) ) {
+                            memcpy(&(*addr_pp)[(*naddrs)],&kdc_addr_p[i],
+                                    sizeof(struct sockaddr));
+                            (*naddrs)++;
+                            break;
+                        }
+                    }
+                }
 
-            *naddrs = 0;
-            *addr_pp = (struct sockaddr *) malloc(sizeof(*kdc_addr_p));
-            if ( *addr_pp == NULL ) {
                 free(kdc_addr_p);
                 free(admin_addr_p);
-                return ENOMEM;
-            }
 
-            for ( i=0; i<nkdc_addrs; i++ ) {
-                for ( j=0 ; j<nadmin_addrs; j++) {
-                    if ( !memcmp(&kdc_addr_p[i].sa_data[2],&admin_addr_p[j].sa_data[2],4) ) {
-                        memcpy(&(*addr_pp)[(*naddrs)],&kdc_addr_p[i],
-                                sizeof(struct sockaddr));
-                        (*naddrs)++;
-                        break;
-                    }
+                if ( *naddrs == 0 ) {
+                    free(*addr_pp);
+                    *addr_pp = NULL;
+                    return KRB5_REALM_CANT_RESOLVE;
                 }
+                *master_index = 1;
+                *nmasters = *naddrs;
             }
-            free(kdc_addr_p);
-            free(admin_addr_p);
-
-            if ( *naddrs == 0 ) {
-                free(*addr_pp);
-                *addr_pp = NULL;
-                return KRB5_REALM_CANT_RESOLVE;
-            }
-            *master_index = 1;
-            *nmasters = *naddrs;
         }
     }
 #endif /* KRB5_DNS_LOOKUP */