From: Tom Yu Date: Sat, 18 Nov 2006 01:53:27 +0000 (+0000) Subject: * src/lib/krb5/ccache/ccbase.c (krb5int_cc_getops): Internal X-Git-Tag: krb5-1.7-alpha1~1437 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ea34547e917e0b72b41c453ec60e9784fdff079c;p=krb5.git * src/lib/krb5/ccache/ccbase.c (krb5int_cc_getops): Internal function to fetch ops vector given ccache prefix string. (krb5_cc_new_unique): New function to generate a new unique ccache of a given type. * src/include/krb5/krb5.hin: Prototype for krb5_cc_new_unique(). * src/lib/krb5/libkrb5.exports: * src/lib/krb5_32.def: Add krb5_cc_new_unique(). ticket: 3091 tags: pullup git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18857 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin index 7dacc5737..9d9920efd 100644 --- a/src/include/krb5/krb5.hin +++ b/src/include/krb5/krb5.hin @@ -1310,6 +1310,12 @@ krb5_cccol_cursor_next( krb5_error_code KRB5_CALLCONV krb5_cccol_cursor_free(krb5_context context, krb5_cccol_cursor *cursor); +krb5_error_code KRB5_CALLCONV +krb5_cc_new_unique( + krb5_context context, + const char *type, + const char *hint, + krb5_ccache *id); /* * end "ccache.h" diff --git a/src/lib/krb5/ccache/ccbase.c b/src/lib/krb5/ccache/ccbase.c index 044f48e48..76360bd6c 100644 --- a/src/lib/krb5/ccache/ccbase.c +++ b/src/lib/krb5/ccache/ccbase.c @@ -72,6 +72,9 @@ static struct krb5_cc_typelist cc_fcc_entry = { &krb5_cc_file_ops, static struct krb5_cc_typelist *cc_typehead = INITIAL_TYPEHEAD; static k5_mutex_t cc_typelist_lock = K5_MUTEX_PARTIAL_INITIALIZER; +static krb5_error_code +krb5int_cc_getops(krb5_context, const char *, const krb5_cc_ops **); + int krb5int_cc_initialize(void) { @@ -162,12 +165,13 @@ krb5_cc_register(krb5_context context, krb5_cc_ops *ops, krb5_boolean override) krb5_error_code KRB5_CALLCONV krb5_cc_resolve (krb5_context context, const char *name, krb5_ccache *cache) { - struct krb5_cc_typelist *tlist; char *pfx, *cp; const char *resid; unsigned int pfxlen; krb5_error_code err; - + const krb5_cc_ops *ops; + + pfx = NULL; cp = strchr (name, ':'); if (!cp) { if (krb5_cc_dfl_ops) @@ -198,28 +202,74 @@ krb5_cc_resolve (krb5_context context, const char *name, krb5_ccache *cache) *cache = (krb5_ccache) 0; - err = k5_mutex_lock(&cc_typelist_lock); - if (err) { + err = krb5int_cc_getops(context, pfx, &ops); + if (pfx != NULL) free(pfx); + if (err) return err; - } + + return ops->resolve(context, cache, resid); +} + +/* + * cc_getops + * + * Internal function to return the ops vector for a given ccache + * prefix string. + */ +static krb5_error_code +krb5int_cc_getops( + krb5_context context, + const char *pfx, + const krb5_cc_ops **ops) +{ + krb5_error_code err; + struct krb5_cc_typelist *tlist; + + err = k5_mutex_lock(&cc_typelist_lock); + if (err) + return err; + for (tlist = cc_typehead; tlist; tlist = tlist->next) { if (strcmp (tlist->ops->prefix, pfx) == 0) { - krb5_error_code (KRB5_CALLCONV *ccresolver)() = tlist->ops->resolve; + *ops = tlist->ops; k5_mutex_unlock(&cc_typelist_lock); - free(pfx); - return (*ccresolver)(context, cache, resid); + return 0; } } k5_mutex_unlock(&cc_typelist_lock); if (krb5_cc_dfl_ops && !strcmp (pfx, krb5_cc_dfl_ops->prefix)) { - free (pfx); - return (*krb5_cc_dfl_ops->resolve)(context, cache, resid); + *ops = krb5_cc_dfl_ops; + return 0; } - free(pfx); return KRB5_CC_UNKNOWN_TYPE; } +/* + * cc_new_unique + * + * Generate a new unique ccache, given a ccache type and a hint + * string. Ignores the hint string for now. + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_new_unique( + krb5_context context, + const char *type, + const char *hint, + krb5_ccache *id) +{ + const krb5_cc_ops *ops; + krb5_error_code err; + + *id = NULL; + + err = krb5int_cc_getops(context, type, &ops); + if (err) + return err; + + return ops->gen_new(context, id); +} + /* * cc_typecursor * diff --git a/src/lib/krb5/libkrb5.exports b/src/lib/krb5/libkrb5.exports index add04020b..d7998f977 100644 --- a/src/lib/krb5/libkrb5.exports +++ b/src/lib/krb5/libkrb5.exports @@ -306,6 +306,7 @@ krb5_cc_get_name krb5_cc_get_principal krb5_cc_get_type krb5_cc_initialize +krb5_cc_new_unique krb5_cc_next_cred krb5_cc_register krb5_cc_remove_cred diff --git a/src/lib/krb5_32.def b/src/lib/krb5_32.def index 07527c977..6a9060bf8 100644 --- a/src/lib/krb5_32.def +++ b/src/lib/krb5_32.def @@ -88,6 +88,7 @@ krb5_c_string_to_key_with_params krb5_cc_get_principal krb5_cc_get_type krb5_cc_initialize + krb5_cc_new_unique krb5_cc_next_cred krb5_cc_remove_cred krb5_cc_resolve