git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2303 ec53bebd-3082-4978-b11e-865c3cabbd6b
		
			
				
	
	
		
			92 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "krb5_locl.h"
 | 
						|
 | 
						|
RCSID("$Id$");
 | 
						|
 | 
						|
krb5_error_code
 | 
						|
krb5_get_krbhst (krb5_context context,
 | 
						|
		 const krb5_realm *realm,
 | 
						|
		 char ***hostlist)
 | 
						|
{
 | 
						|
    char **res;
 | 
						|
    unsigned max, count;
 | 
						|
    krb5_config_binding *pointer;
 | 
						|
    char *r;
 | 
						|
    char *h;
 | 
						|
    krb5_boolean done;
 | 
						|
    char **tmp;
 | 
						|
 | 
						|
#ifdef USE_ASN1_PRINCIPAL
 | 
						|
     r = *realm;
 | 
						|
#else
 | 
						|
     r = malloc (realm->length + 1);
 | 
						|
     strncpy (r, realm->data, realm->length);
 | 
						|
     r[realm->length] = '\0';
 | 
						|
#endif
 | 
						|
 | 
						|
    count = 0;
 | 
						|
    max = 10;
 | 
						|
    res = malloc(max * sizeof(*res));
 | 
						|
    if(res == NULL)
 | 
						|
	return KRB5_REALM_UNKNOWN;
 | 
						|
    pointer = NULL;
 | 
						|
    for(done = FALSE; !done;) {
 | 
						|
	char *h = (char *)krb5_config_get_next (context->cf,
 | 
						|
						&pointer,
 | 
						|
						STRING,
 | 
						|
						"realms",
 | 
						|
						r,
 | 
						|
						"kdc",
 | 
						|
						NULL);
 | 
						|
 | 
						|
	if (count > max - 2) {
 | 
						|
	    max += 10;
 | 
						|
	    tmp = realloc (res, max * sizeof(*res));
 | 
						|
	    if (tmp == NULL) {
 | 
						|
		res[count] = NULL;
 | 
						|
		free (r);
 | 
						|
		krb5_free_krbhst (context, res);
 | 
						|
		return KRB5_REALM_UNKNOWN;
 | 
						|
	    }
 | 
						|
	    res = tmp;
 | 
						|
	}
 | 
						|
	if (h == NULL) {
 | 
						|
	    done = TRUE;
 | 
						|
	    asprintf(&res[count], "kerberos.%s", r);
 | 
						|
	} else {
 | 
						|
	    res[count] = strdup(h);
 | 
						|
	}
 | 
						|
	if (res[count] == NULL) {
 | 
						|
	    free(r);
 | 
						|
	    krb5_free_krbhst (context, res);
 | 
						|
	    return KRB5_REALM_UNKNOWN;
 | 
						|
	}
 | 
						|
	++count;
 | 
						|
    }
 | 
						|
#ifndef USE_ASN1_PRINCIPAL
 | 
						|
     free (r);
 | 
						|
#endif
 | 
						|
 | 
						|
    /* There should always be room for the NULL here */
 | 
						|
    res[count++] = NULL;
 | 
						|
    tmp = realloc (res, count * sizeof(*res));
 | 
						|
    if (tmp == NULL) {
 | 
						|
	krb5_free_krbhst (context, res);
 | 
						|
	return KRB5_REALM_UNKNOWN;
 | 
						|
    }
 | 
						|
    res = tmp;
 | 
						|
    *hostlist = res;
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
krb5_error_code
 | 
						|
krb5_free_krbhst (krb5_context context,
 | 
						|
		  char **hostlist)
 | 
						|
{
 | 
						|
    char **p;
 | 
						|
 | 
						|
    for (p = hostlist; *p; ++p)
 | 
						|
	free (*p);
 | 
						|
    free (hostlist);
 | 
						|
    return 0;
 | 
						|
}
 |