* src/lib/krb5/ccache/ccbase.c (krb5int_cc_getops): Internal
authorTom Yu <tlyu@mit.edu>
Sat, 18 Nov 2006 01:53:27 +0000 (01:53 +0000)
committerTom Yu <tlyu@mit.edu>
Sat, 18 Nov 2006 01:53:27 +0000 (01:53 +0000)
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

src/include/krb5/krb5.hin
src/lib/krb5/ccache/ccbase.c
src/lib/krb5/libkrb5.exports
src/lib/krb5_32.def

index 7dacc5737cad4f3f5613808e397659f38a4f95ed..9d9920efd880cc45c3039c57de16b714f42fd00c 100644 (file)
@@ -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"
index 044f48e488d564b85448197aa606c48d842b24e8..76360bd6c072a5908e015ba59579d07f69136a84 100644 (file)
@@ -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
  *
index add04020b3669d9eb17ce06718e63d1d210197d0..d7998f977dba131e2ad22272bb0fde330c5f29fa 100644 (file)
@@ -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
index 07527c9774a37e862ab7503af28632c1d7eef5c2..6a9060bf8a3c714d0b41bb0422fc3e2f2a5bdc6c 100644 (file)
@@ -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