Implemented CCAPI v3 specific ccache collection cursor
authorJustin Anderson <jander@mit.edu>
Wed, 29 Nov 2006 21:50:02 +0000 (21:50 +0000)
committerJustin Anderson <jander@mit.edu>
Wed, 29 Nov 2006 21:50:02 +0000 (21:50 +0000)
* src/lib/krb5/ccache/ccbase.c: Added CCAPI v3 entry to list of type cursors

* src/lib/krb5/ccache/ccapi/stdcc.h:
* src/lib/krb5/ccache/ccapi/stdcc.c: Implemented CCAPI v3 cursor functionality.

ticket: 4739
status: open

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18877 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/ccapi/stdcc.c
src/lib/krb5/ccache/ccapi/stdcc.h
src/lib/krb5/ccache/ccbase.c

index d2a23be96a2c8ed69909fc03c404ab25fe109da1..ce54b2895c36046a72a3c9f371f90748baecca03 100644 (file)
@@ -84,9 +84,9 @@ krb5_cc_ops krb5_cc_stdcc_ops = {
       krb5_stdccv3_remove, 
       krb5_stdccv3_set_flags,
       krb5_stdccv3_get_flags,
-      NULL,
-      NULL,
-      NULL,
+      krb5_stdccv3_ptcursor_new,
+      krb5_stdccv3_ptcursor_next,
+      krb5_stdccv3_ptcursor_free,
       NULL,
       NULL,
       NULL,
@@ -771,6 +771,135 @@ krb5_stdccv3_remove (krb5_context context,
     return cc_err_xlate (err);
 }
 
+static krb5_error_code KRB5_CALLCONV
+krb5_stdccv3_ptcursor_new(krb5_context context,
+                          krb5_cc_ptcursor *cursor)
+{
+       krb5_error_code err = 0;
+       krb5_cc_ptcursor ptcursor = NULL;
+       cc_ccache_iterator_t iterator = NULL;
+       
+       ptcursor = malloc(sizeof(*ptcursor));
+       if (ptcursor == NULL) {
+               err = ENOMEM;
+       }
+       else {
+               memset(ptcursor, 0, sizeof(*ptcursor));
+       }
+       
+       if (!err) {
+               err = stdccv3_setup(context, NULL);
+       }
+       if (!err) {
+               ptcursor->ops = &krb5_cc_stdcc_ops;
+               err = cc_context_new_ccache_iterator(gCntrlBlock, &iterator);
+       }
+       
+       if (!err) {
+               ptcursor->data = iterator;
+       }
+       
+       if (err) {
+               if (ptcursor) { krb5_stdccv3_ptcursor_free(context, &ptcursor); }
+               // krb5_stdccv3_ptcursor_free sets ptcursor to NULL for us
+       }
+       
+       *cursor = ptcursor;
+       
+       return err;
+}
+
+static krb5_error_code KRB5_CALLCONV
+krb5_stdccv3_ptcursor_next(
+    krb5_context context,
+    krb5_cc_ptcursor cursor,
+    krb5_ccache *ccache)
+{
+       krb5_error_code err = 0;
+       cc_ccache_iterator_t iterator = NULL;
+       
+       krb5_ccache newCache = NULL;
+       stdccCacheDataPtr ccapi_data = NULL;
+       cc_ccache_t ccCache = NULL;
+       cc_string_t ccstring = NULL;
+       char *name = NULL;
+       
+       // TODO set proper errors, check context param
+       if (!cursor || !cursor->data) {
+               err = ccErrInvalidContext;
+       }
+       
+       *ccache = NULL;
+       
+       if (!err) {
+           newCache = (krb5_ccache) malloc (sizeof (*newCache));
+           if (!newCache) { err = KRB5_CC_NOMEM; }
+       }
+
+       if (!err) {
+           ccapi_data = (stdccCacheDataPtr) malloc (sizeof (*ccapi_data));
+           if (!ccapi_data) { err = KRB5_CC_NOMEM; }
+       }
+       
+       if (!err) {
+               iterator = cursor->data;
+               err = cc_ccache_iterator_next(iterator, &ccCache);
+       }
+       
+       if (!err) {
+           err = cc_ccache_get_name (ccCache, &ccstring);
+       }
+
+       if (!err) {
+           name = (char *) malloc (sizeof (*name) * (strlen (ccstring->data) + 1));
+           if (!name) { err = KRB5_CC_NOMEM; }
+       }
+       
+       if (!err) {
+           strcpy (name, ccstring->data);
+           ccapi_data->cache_name = name;
+           name = NULL; /* take ownership */
+    
+           ccapi_data->NamedCache = ccCache;
+           ccCache = NULL; /* take ownership */
+    
+           newCache->ops = &krb5_cc_stdcc_ops;
+           newCache->data = ccapi_data;
+           ccapi_data = NULL; /* take ownership */
+    
+           /* return a pointer to the new cache */
+           *ccache = newCache;
+           newCache = NULL;
+       }
+       if (name)       { free (name); }
+       if (ccstring)   { cc_string_release (ccstring); }
+       if (ccCache)    { cc_ccache_release (ccCache); }
+       if (ccapi_data) { free (ccapi_data); }
+       if (newCache)   { free (newCache); }
+       
+       if (err == ccIteratorEnd) {
+               err = ccNoError;
+       }
+       
+       return err;
+}
+
+static krb5_error_code KRB5_CALLCONV
+krb5_stdccv3_ptcursor_free(
+    krb5_context context,
+    krb5_cc_ptcursor *cursor)
+{
+    if (*cursor != NULL) {
+               if ((*cursor)->data != NULL) {
+                       cc_ccache_iterator_release((cc_ccache_iterator_t)((*cursor)->data));
+               }
+           free(*cursor);
+           *cursor = NULL;
+       }
+    return 0;
+}
+
 #else /* !USE_CCAPI_V3 */
 
 static krb5_error_code stdcc_setup(krb5_context context,
index 03948d1a848fe23a9ac3156c6a5f2a585ce5587e..d548c0531b448c0ed13fb379ec3c86f8e49a5325 100644 (file)
@@ -87,6 +87,17 @@ krb5_error_code KRB5_CALLCONV krb5_stdccv3_get_flags
 
 krb5_error_code KRB5_CALLCONV krb5_stdccv3_remove 
         (krb5_context, krb5_ccache id , krb5_flags flags, krb5_creds *creds);
+
+static krb5_error_code KRB5_CALLCONV krb5_stdccv3_ptcursor_new
+               (krb5_context context, krb5_cc_ptcursor *cursor);
+
+static krb5_error_code KRB5_CALLCONV krb5_stdccv3_ptcursor_next
+               (krb5_context context, krb5_cc_ptcursor cursor, krb5_ccache *ccache);
+
+static krb5_error_code KRB5_CALLCONV krb5_stdccv3_ptcursor_free
+               (krb5_context context, krb5_cc_ptcursor *cursor);
+
+
 #else
 void krb5_stdcc_shutdown(void);
 
index 76360bd6c072a5908e015ba59579d07f69136a84..1a9f5afc5f7878f6727d789309f4fd1e336c85b7 100644 (file)
@@ -53,7 +53,16 @@ extern const krb5_cc_ops krb5_lcc_ops;
 static struct krb5_cc_typelist cc_lcc_entry = { &krb5_lcc_ops, NULL };
 static struct krb5_cc_typelist cc_mcc_entry = { &krb5_mcc_ops, &cc_lcc_entry };
 #else
+
+#ifdef USE_CCAPI_V3
+extern const krb5_cc_ops krb5_cc_stdcc_ops;
+static struct krb5_cc_typelist cc_stdcc_entry = { &krb5_cc_stdcc_ops, NULL };
+static struct krb5_cc_typelist cc_mcc_entry = { &krb5_mcc_ops, &cc_stdcc_entry };
+#else
+
 static struct krb5_cc_typelist cc_mcc_entry = { &krb5_mcc_ops, NULL };
+#endif /* USE_CCAPI_V3 */
+
 #ifdef USE_KEYRING_CCACHE
 static struct krb5_cc_typelist cc_file_entry = { &krb5_cc_file_ops,
                                                 &cc_mcc_entry };