From 0c4e29a152b6a571a7bb3cca940254380a7c595d Mon Sep 17 00:00:00 2001 From: John Kohl Date: Fri, 20 Apr 1990 12:58:35 +0000 Subject: [PATCH] not tested, but compiles git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@538 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/an_to_ln.c | 143 +++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/lib/krb5/os/an_to_ln.c diff --git a/src/lib/krb5/os/an_to_ln.c b/src/lib/krb5/os/an_to_ln.c new file mode 100644 index 000000000..d8fc2b333 --- /dev/null +++ b/src/lib/krb5/os/an_to_ln.c @@ -0,0 +1,143 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_aname_to_localname() + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_an_to_ln_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#ifdef USE_DBM_LNAME +#include +#include +#endif + +#ifndef min +#define min(a,b) ((a) > (b) ? (b) : (a)) +#endif /* min */ + +/* + Converts an authentication name to a local name suitable for use by + programs wishing a translation to an environment-specific name (e.g. + user account name). + + lnsize specifies the maximum length name that is to be filled into + lname. + + returns system errors, NOT_ENOUGH_SPACE +*/ + +#ifdef USE_DBM_LNAME +extern char *krb5_lname_file; + +/* + * Implementation: This version uses a DBM database, indexed by aname, + * to generate a lname. + * + * 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) +const krb5_principal aname; +const int lnsize; +char *lname; +{ + DBM *db; + krb5_error_code retval; + datum key, contents; + char *princ_name; + + if (retval = krb5_unparse_name(aname, &princ_name)) + return(retval); + key.dptr = princ_name; + key.dsize = strlen(princ_name)+1; /* need to store the NULL for + decoding */ + + db = dbm_open(krb5_lname_file, O_RDONLY, 0600); + if (!db) { + xfree(princ_name); + return KRB5_LNAME_CANTOPEN; + } + + contents = dbm_fetch(db, key); + + xfree(princ_name); + (void) dbm_close(db); + + if (contents.dptr == NULL) { + retval = KRB5_LNAME_NOTRANS; + } else { + strncpy(lname, contents.dptr, lnsize); + if (lnsize < contents.dsize-1) /* -1 for the null */ + retval = KRB5_CONFIG_NOTENUFSPACE; + else + retval = 0; + } + 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) +const krb5_principal aname; +const int lnsize; +char *lname; +{ + krb5_error_code retval; + 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 (!(def_realm = malloc(realm_length + 1))) + return ENOMEM; + + if (retval = krb5_get_default_realm(realm_length+1,def_realm)) { + free(def_realm); + return KRB5_LNAME_NOTRANS; + } + + if (strncmp(def_realm, krb5_princ_realm(aname)->data, realm_length)) { + free(def_realm); + return KRB5_LNAME_NOTRANS; + } + free(def_realm); + strncpy(lname, aname[1]->data, min(aname[1]->length,lnsize)); + if (lnsize < aname[1]->length+1) { + retval = KRB5_CONFIG_NOTENUFSPACE; + } else { + lname[aname[1]->length] = '\0'; + retval = 0; + } + return retval; +} +#endif -- 2.26.2