krb5_425_conv_principal_ext with better control of resulting
principal. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3075 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -440,14 +440,17 @@ krb5_realm_compare(krb5_context context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
krb5_error_code
|
krb5_error_code
|
||||||
krb5_425_conv_principal(krb5_context context,
|
krb5_425_conv_principal_ext(krb5_context context,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *instance,
|
const char *instance,
|
||||||
const char *realm,
|
const char *realm,
|
||||||
|
krb5_boolean (*func)(krb5_context, krb5_principal),
|
||||||
|
krb5_boolean resolve,
|
||||||
krb5_principal *princ)
|
krb5_principal *princ)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
krb5_error_code ret;
|
krb5_error_code ret;
|
||||||
|
krb5_principal pr;
|
||||||
char host[128];
|
char host[128];
|
||||||
|
|
||||||
/* do the following: if the name is found in the
|
/* do the following: if the name is found in the
|
||||||
@@ -469,22 +472,53 @@ krb5_425_conv_principal(krb5_context context,
|
|||||||
if(p == NULL)
|
if(p == NULL)
|
||||||
p = krb5_config_get_string(context->cf, "libdefaults",
|
p = krb5_config_get_string(context->cf, "libdefaults",
|
||||||
"v4_name_convert", "host", name, NULL);
|
"v4_name_convert", "host", name, NULL);
|
||||||
if(p){
|
if(p == NULL)
|
||||||
|
goto no_host;
|
||||||
name = p;
|
name = p;
|
||||||
p = krb5_config_get_string(context->cf, "realms", realm,
|
p = krb5_config_get_string(context->cf, "realms", realm,
|
||||||
"v4_instance_convert", instance, NULL);
|
"v4_instance_convert", instance, NULL);
|
||||||
if(p){
|
if(p){
|
||||||
instance = p;
|
instance = p;
|
||||||
goto done;
|
ret = krb5_make_principal(context, &pr, realm, name, instance, NULL);
|
||||||
|
if(func == NULL || (*func)(context, pr)){
|
||||||
|
*princ = pr;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if(krb5_config_get_bool(context->cf, "libdefaults",
|
krb5_free_principal(context, pr);
|
||||||
"v4_instance_resolve", NULL)){
|
*princ = NULL;
|
||||||
|
return HEIM_ERR_V4_PRINC_NO_CONV;
|
||||||
|
}
|
||||||
|
if(resolve){
|
||||||
struct hostent *hp = gethostbyname(instance);
|
struct hostent *hp = gethostbyname(instance);
|
||||||
if(hp){
|
if(hp){
|
||||||
instance = hp->h_name;
|
instance = hp->h_name;
|
||||||
goto done;
|
ret = krb5_make_principal(context, &pr,
|
||||||
|
realm, name, instance, NULL);
|
||||||
|
if(func == NULL || (*func)(context, pr)){
|
||||||
|
*princ = pr;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
krb5_free_principal(context, pr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
char **domains, **d;
|
||||||
|
domains = krb5_config_get_strings(context->cf, "realms", realm,
|
||||||
|
"v4_domains", NULL);
|
||||||
|
for(d = domains; d && *d; d++){
|
||||||
|
snprintf(host, sizeof(host), "%s.%s", instance, *d);
|
||||||
|
ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
|
||||||
|
if(func == NULL || (*func)(context, pr)){
|
||||||
|
*princ = pr;
|
||||||
|
krb5_config_free_strings(domains);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
krb5_free_principal(context, pr);
|
||||||
|
}
|
||||||
|
krb5_config_free_strings(domains);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
p = krb5_config_get_string(context->cf, "realms", realm,
|
p = krb5_config_get_string(context->cf, "realms", realm,
|
||||||
"default_domain", NULL);
|
"default_domain", NULL);
|
||||||
if(p == NULL){
|
if(p == NULL){
|
||||||
@@ -494,9 +528,13 @@ krb5_425_conv_principal(krb5_context context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(host, sizeof(host), "%s.%s", instance, p);
|
snprintf(host, sizeof(host), "%s.%s", instance, p);
|
||||||
instance = host;
|
ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
|
||||||
goto done;
|
if(func == NULL || (*func)(context, pr)){
|
||||||
|
*princ = pr;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
krb5_free_principal(context, pr);
|
||||||
|
return HEIM_ERR_V4_PRINC_NO_CONV;
|
||||||
no_host:
|
no_host:
|
||||||
p = krb5_config_get_string(context->cf,
|
p = krb5_config_get_string(context->cf,
|
||||||
"realms",
|
"realms",
|
||||||
@@ -515,9 +553,31 @@ no_host:
|
|||||||
if(p)
|
if(p)
|
||||||
name = p;
|
name = p;
|
||||||
|
|
||||||
done:
|
ret = krb5_make_principal(context, &pr, realm, name, instance, NULL);
|
||||||
return krb5_make_principal(context, princ, realm, name, instance, NULL);
|
if(func == NULL || (*func)(context, pr)){
|
||||||
|
*princ = pr;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
krb5_free_principal(context, pr);
|
||||||
|
return HEIM_ERR_V4_PRINC_NO_CONV;
|
||||||
|
}
|
||||||
|
|
||||||
|
krb5_error_code
|
||||||
|
krb5_425_conv_principal(krb5_context context,
|
||||||
|
const char *name,
|
||||||
|
const char *instance,
|
||||||
|
const char *realm,
|
||||||
|
krb5_principal *princ)
|
||||||
|
{
|
||||||
|
krb5_boolean resolve = krb5_config_get_bool(context->cf,
|
||||||
|
"libdefaults",
|
||||||
|
"v4_instance_resolve",
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return krb5_425_conv_principal_ext(context, name, instance, realm,
|
||||||
|
NULL, resolve, princ);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
name_convert(krb5_context context, const char *name, const char *realm,
|
name_convert(krb5_context context, const char *name, const char *realm,
|
||||||
|
Reference in New Issue
Block a user