Use krb5_config_get_strings.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4254 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -45,63 +45,23 @@ krb5_get_krbhst (krb5_context context,
|
|||||||
const krb5_realm *realm,
|
const krb5_realm *realm,
|
||||||
char ***hostlist)
|
char ***hostlist)
|
||||||
{
|
{
|
||||||
char **res;
|
char **res, **r;
|
||||||
unsigned max, count;
|
int count;
|
||||||
krb5_config_binding *pointer;
|
res = krb5_config_get_strings(context, NULL,
|
||||||
char *r;
|
"realms", *realm, "kdc", NULL);
|
||||||
krb5_boolean done;
|
for(r = res, count = 0; r && *r; r++, count++);
|
||||||
char **tmp;
|
r = realloc(res, (count + 2) * sizeof(*res));
|
||||||
|
if(r == NULL){
|
||||||
r = *realm;
|
krb5_config_free_strings(res);
|
||||||
|
return ENOMEM;
|
||||||
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,
|
|
||||||
krb5_config_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;
|
|
||||||
}
|
}
|
||||||
|
res = r;
|
||||||
/* There should always be room for the NULL here */
|
asprintf(&res[count], "kerberos.%s", *realm);
|
||||||
res[count++] = NULL;
|
if(res[count] == NULL){
|
||||||
tmp = realloc (res, count * sizeof(*res));
|
krb5_config_free_strings(res);
|
||||||
if (tmp == NULL) {
|
return ENOMEM;
|
||||||
krb5_free_krbhst (context, res);
|
|
||||||
return KRB5_REALM_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
res = tmp;
|
res[count + 1] = NULL;
|
||||||
*hostlist = res;
|
*hostlist = res;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user