(krb5_get_krb524hst): add and restructure the support functions

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9999 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2001-05-24 23:51:37 +00:00
parent c7fa6c77ef
commit fdf9c7294d

View File

@@ -121,6 +121,22 @@ srv_find_realm(krb5_context context, char ***res, int *count,
return 0;
}
/*
* lookup the servers for realm `realm', looking for the config string
* `conf_string' in krb5.conf.
* return a malloc-ed list of servers in hostlist or NULL if ther are none
*/
static void
get_krbhst_conf (krb5_context context,
const krb5_realm *realm,
const char *conf_string,
char ***hostlist)
{
*hostlist = krb5_config_get_strings(context, NULL,
"realms", *realm, conf_string, NULL);
}
/*
* lookup the servers for realm `realm', looking for the config string
* `conf_string' in krb5.conf or for `serv_string' in SRV records.
@@ -128,21 +144,17 @@ srv_find_realm(krb5_context context, char ***res, int *count,
*/
static krb5_error_code
get_krbhst (krb5_context context,
const krb5_realm *realm,
const char *conf_string,
const char *serv_string,
char ***hostlist)
get_krbhst_dns (krb5_context context,
const krb5_realm *realm,
const char *serv_string,
char ***hostlist,
krb5_boolean fallback)
{
char **res, **r;
char **res;
int count;
krb5_error_code ret;
res = krb5_config_get_strings(context, NULL,
"realms", *realm, conf_string, NULL);
for(r = res, count = 0; r && *r; r++, count++);
if(count == 0 && context->srv_lookup) {
if(context->srv_lookup) {
char *s[] = { "udp", "tcp", "http" }, **q;
for(q = s; q < s + sizeof(s) / sizeof(s[0]); q++) {
ret = srv_find_realm(context, &res, &count, *realm, *q,
@@ -154,7 +166,7 @@ get_krbhst (krb5_context context,
}
}
if(count == 0) {
if(fallback && count == 0) {
char buf[1024];
snprintf(buf, sizeof(buf), "kerberos.%s", *realm);
ret = add_string(context, &res, &count, buf);
@@ -168,6 +180,28 @@ get_krbhst (krb5_context context,
return 0;
}
/*
* lookup the servers for realm `realm', looking for the config string
* `conf_string' in krb5.conf or for `serv_string' in SRV records.
* return a malloc-ed list of servers in hostlist.
*/
static krb5_error_code
get_krbhst (krb5_context context,
const krb5_realm *realm,
const char *conf_string,
const char *serv_string,
char ***hostlist,
krb5_boolean fallback)
{
krb5_error_code ret = 0;
get_krbhst_conf(context, realm, conf_string, hostlist);
if (*hostlist == NULL)
ret = get_krbhst_dns(context, realm, serv_string, hostlist, fallback);
return ret;
}
/*
* set `hostlist' to a malloced list of kadmin servers.
*/
@@ -178,7 +212,7 @@ krb5_get_krb_admin_hst (krb5_context context,
char ***hostlist)
{
return get_krbhst (context, realm, "admin_server", "kerberos-adm",
hostlist);
hostlist, TRUE);
}
/*
@@ -190,14 +224,37 @@ krb5_get_krb_changepw_hst (krb5_context context,
const krb5_realm *realm,
char ***hostlist)
{
krb5_error_code ret;
krb5_error_code ret = 0;
ret = get_krbhst (context, realm, "kpasswd_server", "kpasswd",
hostlist);
if (ret)
return ret;
ret = get_krbhst (context, realm, "admin_server", "kpasswd",
hostlist);
get_krbhst_conf (context, realm, "kpasswd_server",
hostlist);
if (hostlist == NULL)
ret = get_krbhst (context, realm, "admin_server", "kpasswd",
hostlist, TRUE);
return ret;
}
/*
* set `hostlist' to a malloced list of 524 servers (per default the
* KDCs)
*/
krb5_error_code
krb5_get_krb524hst (krb5_context context,
const krb5_realm *realm,
char ***hostlist)
{
krb5_error_code ret = 0;
get_krbhst_conf (context, realm, "krb524_server", hostlist);
if (hostlist == NULL) {
ret = get_krbhst (context, realm, "krb524_server", "krb524", hostlist,
FALSE);
if (ret)
return ret;
if (hostlist == NULL)
return krb5_get_krbhst(context, realm, hostlist);
}
return ret;
}
@@ -210,7 +267,7 @@ krb5_get_krbhst (krb5_context context,
const krb5_realm *realm,
char ***hostlist)
{
return get_krbhst (context, realm, "kdc", "kerberos", hostlist);
return get_krbhst (context, realm, "kdc", "kerberos", hostlist, TRUE);
}
/*