cc_remove_cred should only remove one cred
authorAlexandra Ellwood <lxs@mit.edu>
Mon, 10 Mar 2008 21:27:30 +0000 (21:27 +0000)
committerAlexandra Ellwood <lxs@mit.edu>
Mon, 10 Mar 2008 21:27:30 +0000 (21:27 +0000)
Fixed cc_remove_cred so it only removes the first matching
cred.  Also fixed the error handling so it returns errors
other than CC_NOTFOUND.

ticket: new

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

src/ccapi/lib/ccapi_v2.c

index ffeb1d6943ef2b1c4d53219ae8bfa1b7bf6b02a6..ba2ed4a168d437ce473e2858dde5df69dc5a6534 100644 (file)
@@ -544,36 +544,36 @@ cc_result cc_remove_cred (apiCB      *in_context,
 {
     cc_result err = ccNoError;
     cc_credentials_iterator_t iterator = NULL;
+    cc_uint32 found = 0;
     
-    if (!in_context    ) { err = cci_check_error (ccErrBadParam); }
-    if (!in_ccache     ) { err = cci_check_error (ccErrBadParam); }
+    if (!in_context) { err = cci_check_error (ccErrBadParam); }
+    if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
     
     if (!err) {
         err = ccapi_ccache_new_credentials_iterator (in_ccache, &iterator);
     }
     
-    while (!err) {
+    while (!err && !found) {
         cc_credentials_t creds = NULL;
-        cc_uint32 equal = 0;
         
         err = ccapi_credentials_iterator_next (iterator, &creds);
         
         if (!err) {
             err = cci_cred_union_compare_to_credentials_union (&in_credentials, 
                                                                creds->data,
-                                                               &equal);
+                                                               &found);
         }
         
-        if (!err && equal) {
+        if (!err && found) {
             err = ccapi_ccache_remove_credentials (in_ccache, creds);
         }
         
         ccapi_credentials_release (creds);
     }
-    if (err) { err = cci_check_error (ccErrCredentialsNotFound); }
+    if (err == ccIteratorEnd) { err = cci_check_error (ccErrCredentialsNotFound); }
     
     return cci_remap_error (err);    
-}      
+}
 
 #if TARGET_OS_MAC
 #pragma mark -