implemented

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2080 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1997-07-09 01:34:46 +00:00
parent e370465a6e
commit 372bd0bd0e

View File

@@ -1,14 +1,83 @@
#include "krb5_locl.h"
#include "config_file.h"
RCSID("$Id$");
static int
exact_match (const char *s, const char *pattern)
{
return strcasecmp (s, pattern) == 0;
}
static int
domain_match (const char *s, const char *pattern)
{
const char *dot = strchr (s, '.');
return dot && strcasecmp (dot, pattern) == 0;
}
krb5_error_code
krb5_get_host_realm(krb5_context context,
const char *host,
char ***realms)
{
krb5_config_binding *state = NULL;
char hostname[MAXHOSTNAMELEN];
char *res = NULL;
const char *partial = NULL;
krb5_config_binding *l;
if (host == NULL) {
if (gethostname (hostname, sizeof(hostname)))
return errno;
host = hostname;
}
*realms = malloc(2 * sizeof(char*));
(*realms)[0] = strdup("FOO.SE");
if (*realms == NULL)
return ENOMEM;
(*realms)[0] = NULL;
(*realms)[1] = NULL;
for(l = krb5_config_get_next (context->cf,
&state,
LIST,
"domain_realm",
NULL);
l;
l = l->next) {
if (l->type != STRING)
continue;
if (exact_match (host, l->name)) {
res = l->u.string;
break;
} else if (domain_match (host, l->name)) {
res = l->u.string;
}
}
if (res) {
(*realms)[0] = strdup(res);
if ((*realms)[0] == NULL) {
free (*realms);
return ENOMEM;
}
} else {
const char *dot = strchr (host, '.');
if (dot != NULL) {
(*realms)[0] = strdup (dot + 1);
if ((*realms)[0] == NULL) {
free (*realms);
return ENOMEM;
}
strupr ((*realms)[0]);
} else {
free (*realms);
*realms = NULL;
}
}
return 0;
}