From 483f552a1ff2e00643ef9a6ec947523c50d28dfc Mon Sep 17 00:00:00 2001 From: John Kohl Date: Fri, 27 Apr 1990 15:43:28 +0000 Subject: [PATCH] need fullname argument, so re-write git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@613 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/setup_mkey.c | 57 +++++++++++++++------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/src/lib/kdb/setup_mkey.c b/src/lib/kdb/setup_mkey.c index 55b7a834d..451221a9c 100644 --- a/src/lib/kdb/setup_mkey.c +++ b/src/lib/kdb/setup_mkey.c @@ -24,8 +24,12 @@ static char rcsid_setup_mkey_c[] = /* * Given a key name and a realm name, construct a principal which can be used * to fetch the master key from the database. + * + * If the key name is NULL, the default key name will be used. */ +#define REALM_SEP_STRING "@" + krb5_error_code krb5_db_setup_mkey_name(keyname, realm, fullname, principal) const char *keyname; @@ -34,47 +38,28 @@ char **fullname; krb5_principal *principal; { krb5_error_code retval; - krb5_principal retprinc; - int keylen = strlen(keyname); + int keylen; int rlen = strlen(realm); + char *fname; - retprinc = (krb5_principal) calloc(3, sizeof(krb5_data)); - if (!retprinc) + if (!keyname) + keyname = KRB5_KDB_M_NAME; /* XXX external? */ + + keylen = strlen(keyname); + + fname = malloc(keylen+rlen+2); + if (!fname) return ENOMEM; - retprinc[0] = (krb5_data *) malloc(sizeof(krb5_data)); - if (!retprinc[0]) { - goto freeprinc; - } - retprinc[1] = (krb5_data *) malloc(sizeof(krb5_data)); - if (!retprinc[1]) { - goto free0; - } - if (!(retprinc[0]->data = malloc(rlen))) { - goto free1; - } - if (!(retprinc[1]->data = malloc(keylen))) { - xfree(retprinc[0]->data); - goto free1; - } - bcopy(realm, retprinc[0]->data, rlen); - retprinc[0]->length = rlen; - bcopy(keyname, retprinc[1]->data, keylen); - retprinc[1]->length = keylen; + strcpy(fname, keyname); + strcat(fname, REALM_SEP_STRING); + strcat(fname, realm); - if (fullname && (retval = krb5_unparse_name(retprinc, fullname))) { - xfree(retprinc[1]); - xfree(retprinc[0]); - xfree(retprinc); + if (retval = krb5_parse_name(fname, principal)) return retval; - } + if (fullname) + *fullname = fname; + else + free(fname); return 0; - - free1: - xfree(retprinc[1]); - free0: - xfree(retprinc[0]); - freeprinc: - xfree(retprinc); - return ENOMEM; } -- 2.26.2