/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
*
* Copyright 1992 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Build a principal from a V4 specification, or separate a V5
* principal into name, instance, and realm.
*
* NOTE: This is highly site specific, and is only really necessary
* for sites who need to convert from V4 to V5. It is used by both
* the KDC and the kdb5_convert program. Since its use is highly
* specialized, the necesary information is just going to be
* hard-coded in this file.
*/
#include "k5-int.h"
#include <string.h>
#include <ctype.h>
/* The maximum sizes for V4 aname, realm, sname, and instance +1 */
/* Taken from krb.h */
struct krb_convert {
char *v4_str;
char *v5_str;
};
/*
* Kadmin doesn't do realm conversion because it's currently
* kadmin/REALM.NAME. Zephyr doesn't because it's just zephyr/zephyr.
*
* "Realm conversion" is a bit of a misnomer; really, the v5 name is
* using a FQDN or something that looks like it, where the v4 name is
* just using the first label. Sometimes that second principal name
* component is a hostname, sometimes the realm name, sometimes it's
* neither.
*
* This list should probably be more configurable, and more than
* likely on a per-realm basis, so locally-defined services can be
* added, or not.
*/
/* Realm conversion, Change service name */
/* Realm conversion */
/* No Realm conversion */
NR("kadmin"),
R("discuss"),
R("rvdsrv"),
R("sample"),
R("olc"),
R("pop"),
R("sis"),
R("rfs"),
R("imap"),
R("ftp"),
R("ecat"),
R("daemon"),
R("gnats"),
R("moira"),
R("prms"),
R("mandarin"),
R("register"),
R("changepw"),
R("sms"),
R("afpserver"),
R("gdss"),
R("news"),
R("abs"),
R("nfs"),
R("tftp"),
NR("zephyr"),
R("http"),
R("khttp"),
R("pgpsigner"),
R("irc"),
R("mandarin-agent"),
R("write"),
R("palladium"),
{0, 0, 0, 0},
#undef R
};
/*
* char *strnchr(s, c, n)
* char *s;
* char c;
* unsigned int n;
*
* returns a pointer to the first occurrence of character c in the
* string s, or a NULL pointer if c does not occur in in the string;
* however, at most the first n characters will be considered.
*
* This falls in the "should have been in the ANSI C library"
* category. :-)
*/
static char *strnchr(register char *s, register int c,
register unsigned int n)
{
if (n < 1)
return 0;
while (n-- && *s) {
if (*s == c)
return s;
s++;
}
return 0;
}
/* XXX This calls for a new error code */
{
const struct krb_convert *p;
unsigned int tmp_realm_len;
int retval;
return KRB5_CONFIG_CANTOPEN;
case 2:
/* Check if this principal is listed in the table */
p = sconv_list;
while (p->v4_str) {
/*
* It is, so set the new name now, and chop off
* instance's domain name if requested.
*/
return KRB5_INVALID_PRINCIPAL;
if (p->flags & DO_REALM_CONVERSION) {
return KRB5_INVALID_PRINCIPAL;
}
break;
}
p++;
}
/* If inst isn't set, the service isn't listed in the table, */
/* so just copy it. */
if (*inst == '\0') {
return KRB5_INVALID_PRINCIPAL;
}
/* fall through */
case 1:
/* name may have been set above; otherwise, just copy it */
if (*name == '\0') {
return KRB5_INVALID_PRINCIPAL;
}
break;
default:
return KRB5_INVALID_PRINCIPAL;
}
if (tmp_prealm == NULL)
return ENOMEM;
/* Ask for v4_realm corresponding to
krb5 principal realm from krb5.conf realms stanza */
&tmp_realm);
if (retval) {
return retval;
} else {
if (tmp_realm == 0) {
return KRB5_INVALID_PRINCIPAL;
} else {
return KRB5_INVALID_PRINCIPAL;
}
}
return 0;
}
{
const struct krb_convert *p;
char **full_name = 0;
/* First, convert the realm, since the v4 realm is not necessarily the same as the v5 realm
To do that, iterate over all the realms in the config file, looking for a matching
v4_realm line */
names2 [0] = KRB5_CONF_REALMS;
retval = profile_iterator_create (context -> profile, names2, PROFILE_ITER_LIST_SECTION | PROFILE_ITER_SECTIONS_ONLY, &iterator);
while (retval == 0) {
names [0] = KRB5_CONF_REALMS;
if ((retval == 0) && (v4realms != NULL) && (v4realms [0] != NULL) && (strcmp (v4realms [0], realm) == 0)) {
realm = realm_name;
break;
} else if (retval == PROF_NO_RELATION) {
/* If it's not found, just keep going */
retval = 0;
}
break;
}
}
if (realm_name != NULL) {
realm_name = NULL;
}
if (dummy_value != NULL) {
dummy_value = NULL;
}
}
if (instance) {
if (instance[0] == '\0') {
instance = 0;
goto not_service;
}
p = sconv_list;
while (1) {
if (!p->v4_str)
goto not_service;
break;
p++;
}
names[0] = KRB5_CONF_REALMS;
names[4] = 0;
} else {
if (retval)
return retval;
if (domain) {
}
}
}
}
return retval;
}