From a81a6645427211aa4fffc7444700b202341f4bd3 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Thu, 3 Jun 1993 00:17:53 +0000 Subject: [PATCH] Changed so that if there is to DBM translation file, to fall back to conversion to a username. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2558 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/an_to_ln.c | 66 ++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/src/lib/krb5/os/an_to_ln.c b/src/lib/krb5/os/an_to_ln.c index b5188183d..ec24cf37c 100644 --- a/src/lib/krb5/os/an_to_ln.c +++ b/src/lib/krb5/os/an_to_ln.c @@ -57,9 +57,25 @@ static char rcsid_an_to_ln_c[] = returns system errors, NOT_ENOUGH_SPACE */ -#ifdef USE_DBM_LNAME +int krb5_lname_username_fallback = 1; + extern char *krb5_lname_file; +krb5_error_code +krb5_aname_to_localname(aname, lnsize, lname) + krb5_const_principal aname; + const int lnsize; + char *lname; +{ + struct stat statbuf; + + if (!stat(krb5_lname_file,&statbuf)) + return dbm_an_to_ln(aname, lnsize, lname); + if (krb5_lname_username_fallback) + return username_an_to_ln(aname, lnsize, lname); + return KRB5_LNAME_CANTOPEN; +} + /* * Implementation: This version uses a DBM database, indexed by aname, * to generate a lname. @@ -67,8 +83,8 @@ extern char *krb5_lname_file; * The entries in the database are normal C strings, and include the trailing * null in the DBM datum.size. */ -krb5_error_code -krb5_aname_to_localname(aname, lnsize, lname) +static krb5_error_code +dbm_an_to_ln(aname, lnsize, lname) krb5_const_principal aname; const int lnsize; char *lname; @@ -109,14 +125,14 @@ char *lname; (void) dbm_close(db); return retval; } -#else + /* * Implementation: This version checks the realm to see if it is the local * realm; if so, and there is exactly one non-realm component to the name, * that name is returned as the lname. */ -krb5_error_code -krb5_aname_to_localname(aname, lnsize, lname) +static krb5_error_code +username_an_to_ln(aname, lnsize, lname) krb5_const_principal aname; const int lnsize; char *lname; @@ -125,31 +141,39 @@ char *lname; char *def_realm; int realm_length; - if (!aname[1] || aname[2]) { - /* no components or more than one component to non-realm part of name - --no translation. */ - return KRB5_LNAME_NOTRANS; - } - realm_length = krb5_princ_realm(aname)->length; if (retval = krb5_get_default_realm(&def_realm)) { return(retval); } - if ((realm_length != strlen(def_realm)) || - (memcmp(def_realm, krb5_princ_realm(aname)->data, realm_legth))) { - free(def_realm); - return KRB5_LNAME_NOTRANS; - } + (memcmp(def_realm, krb5_princ_realm(aname)->data, realm_length))) { + free(def_realm); + return KRB5_LNAME_NOTRANS; + } + + if (krb5_princ_size(aname) != 1) { + if (krb5_princ_size(aname) == 2 ) { + /* Check to see if 2nd component is the local realm. */ + if ( strncmp(krb5_princ_component(aname,1)->data,def_realm, + realm_length) || + realm_length != krb5_princ_component(aname,1)->length) + return KRB5_LNAME_NOTRANS; + } + else + /* no components or more than one component to non-realm part of name + --no translation. */ + return KRB5_LNAME_NOTRANS; + } + free(def_realm); - strncpy(lname, aname[1]->data, min(aname[1]->length,lnsize)); - if (lnsize < aname[1]->length+1) { + strncpy(lname, krb5_princ_component(aname,0)->data, + min(krb5_princ_component(aname,0)->length,lnsize)); + if (lnsize < krb5_princ_component(aname,0)->length ) { retval = KRB5_CONFIG_NOTENUFSPACE; } else { - lname[aname[1]->length] = '\0'; + lname[krb5_princ_component(aname,0)->length] = '\0'; retval = 0; } return retval; } -#endif -- 2.26.2