425_conv: make `v4_instance_resolve' a boolean

525_conv: major fixing
sname_to: cleanup


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2966 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-08-13 22:20:57 +00:00
parent 60938e3be2
commit 5dcc44932e

View File

@@ -466,6 +466,9 @@ krb5_425_conv_principal(krb5_context context,
} }
p = krb5_config_get_string(context->cf, "realms", realm, p = krb5_config_get_string(context->cf, "realms", realm,
"v4_name_convert", "host", name, NULL); "v4_name_convert", "host", name, NULL);
if(p == NULL)
p = krb5_config_get_string(context->cf, "libdefaults",
"v4_name_convert", "host", name, NULL);
if(p){ if(p){
name = p; name = p;
p = krb5_config_get_string(context->cf, "realms", realm, p = krb5_config_get_string(context->cf, "realms", realm,
@@ -474,8 +477,8 @@ krb5_425_conv_principal(krb5_context context,
instance = p; instance = p;
goto done; goto done;
} }
if(krb5_config_get_string(context->cf, "libdefaults", if(krb5_config_get_bool(context->cf, "libdefaults",
"v4_instance_resolve", NULL)){ "v4_instance_resolve", NULL)){
struct hostent *hp = gethostbyname(instance); struct hostent *hp = gethostbyname(instance);
if(hp){ if(hp){
instance = hp->h_name; instance = hp->h_name;
@@ -502,6 +505,13 @@ no_host:
"plain", "plain",
name, name,
NULL); NULL);
if(p == NULL)
p = krb5_config_get_string(context->cf,
"libdefaults",
"v4_name_convert",
"plain",
name,
NULL);
if(p) if(p)
name = p; name = p;
@@ -509,6 +519,34 @@ done:
return krb5_make_principal(context, princ, realm, name, instance, NULL); return krb5_make_principal(context, princ, realm, name, instance, NULL);
} }
static char*
name_convert(krb5_context context, const char *name, const char *realm,
const char *section)
{
const krb5_config_binding *l;
l = krb5_config_get_list (context->cf,
"realms",
realm,
"v4_name_convert",
section,
NULL);
if(l == NULL)
l = krb5_config_get_list (context->cf,
"libdefaults",
"v4_name_convert",
section,
NULL);
while(l){
if (l->type != STRING)
continue;
if(strcmp(name, l->u.string) == 0)
return l->name;
l = l->next;
}
return NULL;
}
krb5_error_code krb5_error_code
krb5_524_conv_principal(krb5_context context, krb5_524_conv_principal(krb5_context context,
const krb5_principal principal, const krb5_principal principal,
@@ -518,6 +556,8 @@ krb5_524_conv_principal(krb5_context context,
{ {
char *n, *i, *r; char *n, *i, *r;
char tmpinst[40]; char tmpinst[40];
int type = princ_type(principal);
r = principal->realm; r = principal->realm;
switch(principal->name.name_string.len){ switch(principal->name.name_string.len){
@@ -532,16 +572,30 @@ krb5_524_conv_principal(krb5_context context,
default: default:
return KRB5_PARSE_MALFORMED; return KRB5_PARSE_MALFORMED;
} }
if(strcmp(n, "host") == 0){ {
char *tmp = name_convert(context, n, r, "host");
if(tmp){
type = KRB5_NT_SRV_HST;
n = tmp;
}else{
tmp = name_convert(context, n, r, "plain");
if(tmp){
type = KRB5_NT_UNKNOWN;
n = tmp;
}
}
}
if(type == KRB5_NT_SRV_HST){
char *p; char *p;
n = "rcmd";
strncpy(tmpinst, i, sizeof(tmpinst)); strncpy(tmpinst, i, sizeof(tmpinst));
tmpinst[sizeof(tmpinst) - 1] = 0; tmpinst[sizeof(tmpinst) - 1] = 0;
p = strchr(tmpinst, '.'); p = strchr(tmpinst, '.');
if(p) *p = 0; if(p) *p = 0;
i = tmpinst; i = tmpinst;
} }
if(strlen(r) >= 40) if(strlen(r) >= 40)
return KRB5_PARSE_MALFORMED; return KRB5_PARSE_MALFORMED;
if(strlen(n) >= 40) if(strlen(n) >= 40)
@@ -564,47 +618,38 @@ krb5_sname_to_principal (krb5_context context,
krb5_principal *ret_princ) krb5_principal *ret_princ)
{ {
krb5_error_code ret; krb5_error_code ret;
char **r; char localhost[128];
char **realms, *host = NULL;
ret = krb5_get_host_realm (context, hostname, &r);
if (ret)
return ret;
if (type == KRB5_NT_SRV_HST) { if(type != KRB5_NT_SRV_HST && type != KRB5_NT_UNKNOWN)
struct hostent *hostent; return KRB5_SNAME_UNSUPP_NAMETYPE;
char *h; if(hostname == NULL){
gethostname(localhost, sizeof(localhost));
hostent = gethostbyname (hostname); hostname = localhost;
if (hostent != NULL) }
hostname = hostent->h_name; if(sname == NULL)
h = strdup (hostname); sname = "host";
if (h == NULL) { if(type == KRB5_NT_SRV_HST){
krb5_free_host_realm (context, r); struct hostent *hp;
hp = gethostbyname(hostname);
if(hp != NULL)
hostname = hp->h_name;
}
ret = krb5_get_host_realm(context, hostname, &realms);
if(ret)
return ret;
if(type == KRB5_NT_SRV_HST){
host = strdup(hostname);
if(host == NULL){
krb5_free_host_realm(context, realms);
return ENOMEM; return ENOMEM;
} }
strlwr (h); strlwr(host);
ret = krb5_build_principal (context, hostname = host;
ret_princ,
strlen(r[0]),
r[0],
sname,
h,
NULL);
krb5_free_host_realm (context, r);
free (h);
return ret;
} else if (type == KRB5_NT_UNKNOWNN) {
ret = krb5_build_principal (context,
ret_princ,
strlen(r[0]),
r[0],
sname,
hostname,
NULL);
krb5_free_host_realm (context, r);
return ret;
} else {
krb5_free_host_realm (context, r);
return KRB5_SNAME_UNSUPP_NAMETYPE;
} }
ret = krb5_make_principal(context, ret_princ, realms[0], sname, hostname, NULL);
if(host)
free(host);
krb5_free_host_realm(context, realms);
return ret;
} }