krb5 commit [krb5-1.10]: Implement switch_to for ccapiv3

Tom Yu tlyu at MIT.EDU
Mon Jul 23 16:26:18 EDT 2012


https://github.com/krb5/krb5/commit/02ea50fe1b211841399eed993eac99a96371582d
commit 02ea50fe1b211841399eed993eac99a96371582d
Author: Kevin Wasserman <kevin.wasserman at painless-security.com>
Date:   Sun May 6 15:23:10 2012 -0400

    Implement switch_to for ccapiv3
    
    krb5_stdccv3_switch_to() calls cc_ccache_set_default().
    krb5_stdccv3_resolve() checks for NULL or empty residual and calls
    cc_context_get_default_ccache_name() in those cases.
    
    Signed-off-by: Kevin Wasserman <kevin.wasserman at painless-security.com>
    
    (cherry picked from commit 2648a94ea1cf3dec91186dfec59b75de9dac793d)
    
    ticket: 7198
    version_fixed: 1.10.3
    status: resolved

 src/lib/krb5/ccache/ccapi/stdcc.c |   25 +++++++++++++++++++++++++
 src/lib/krb5/ccache/ccapi/stdcc.h |    2 ++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/lib/krb5/ccache/ccapi/stdcc.c b/src/lib/krb5/ccache/ccapi/stdcc.c
index b646b76..d361bde 100644
--- a/src/lib/krb5/ccache/ccapi/stdcc.c
+++ b/src/lib/krb5/ccache/ccapi/stdcc.c
@@ -95,6 +95,7 @@ krb5_cc_ops krb5_cc_stdcc_ops = {
     NULL, /* wasdefault */
     krb5_stdccv3_lock,
     krb5_stdccv3_unlock,
+    krb5_stdccv3_switch_to,
 #else
     krb5_stdcc_get_name,
     krb5_stdcc_resolve,
@@ -388,6 +389,7 @@ krb5_stdccv3_resolve (krb5_context context, krb5_ccache *id , const char *residu
     stdccCacheDataPtr ccapi_data = NULL;
     krb5_ccache ccache = NULL;
     char *name = NULL;
+    cc_string_t defname = NULL;
 
     if (id == NULL) { err = KRB5_CC_NOMEM; }
 
@@ -406,6 +408,14 @@ krb5_stdccv3_resolve (krb5_context context, krb5_ccache *id , const char *residu
     }
 
     if (!err) {
+        if ((residual == NULL) || (strlen(residual) == 0)) {
+            err = cc_context_get_default_ccache_name(gCntrlBlock, &defname);
+            if (defname)
+                residual = defname->data;
+        }
+    }
+
+    if (!err) {
         name = strdup (residual);
         if (!name) { err = KRB5_CC_NOMEM; }
     }
@@ -434,6 +444,7 @@ krb5_stdccv3_resolve (krb5_context context, krb5_ccache *id , const char *residu
     if (ccache)     { free (ccache); }
     if (ccapi_data) { free (ccapi_data); }
     if (name)       { free (name); }
+    if (defname)    { cc_string_release(defname); }
 
     return cc_err_xlate (err);
 }
@@ -1070,6 +1081,20 @@ krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_unlock
     return cc_err_xlate(err);
 }
 
+krb5_error_code KRB5_CALLCONV krb5_stdccv3_switch_to
+(krb5_context context, krb5_ccache id)
+{
+    krb5_error_code retval;
+    stdccCacheDataPtr ccapi_data = id->data;
+    int err;
+
+    if ((retval = stdccv3_setup(context, ccapi_data)))
+        return retval;
+
+    err = cc_ccache_set_default(ccapi_data->NamedCache);
+    return cc_err_xlate(err);
+}
+
 #else /* !USE_CCAPI_V3 */
 
 static krb5_error_code stdcc_setup(krb5_context context,
diff --git a/src/lib/krb5/ccache/ccapi/stdcc.h b/src/lib/krb5/ccache/ccapi/stdcc.h
index 6550efc..7519891 100644
--- a/src/lib/krb5/ccache/ccapi/stdcc.h
+++ b/src/lib/krb5/ccache/ccapi/stdcc.h
@@ -117,6 +117,8 @@ krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_lock
 krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_unlock
 (krb5_context context);
 
+krb5_error_code KRB5_CALLCONV krb5_stdccv3_switch_to
+(krb5_context context, krb5_ccache id);
 #else
 
 krb5_error_code KRB5_CALLCONV krb5_stdcc_close


More information about the cvs-krb5 mailing list