Fixed places where code didn't follow CCache API. Integrated some stuff from Windows
authorScott McGuire <smcguire@mit.edu>
Thu, 5 Nov 1998 19:35:54 +0000 (19:35 +0000)
committerScott McGuire <smcguire@mit.edu>
Thu, 5 Nov 1998 19:35:54 +0000 (19:35 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11016 dc483132-0cff-0310-8789-dd5450dbe970

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

index 2b9007bf811477912b3f381540ef7a1927ede353..7eb2272bb98f12afcdd5b5880ff410b03af97864 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "stdcc.h"
 #include "string.h"
+#include <stdio.h>
+
 
 //declare our global object wanna-be
 //must be installed in ccdefops.c
@@ -33,7 +35,7 @@ krb5_cc_ops krb5_cc_stdcc_ops = {
 // -- generate_new  --------------------------------
 // - create a new cache with a unique name, corresponds to creating a named cache
 // - iniitialize the API here if we have to.
-krb5_error_code  krb5_stdcc_generate_new 
+krb5_error_code KRB5_CALLCONV  krb5_stdcc_generate_new 
        (krb5_context context, krb5_ccache *id ) 
        
   {
@@ -58,8 +60,8 @@ krb5_error_code  krb5_stdcc_generate_new
        sprintf(name, "gen_new_cache%d", time);
        
        //create the new cache
-       err = cc_create(gCntrlBlock, name, CC_CRED_V5,  
-                       name, 0L, &(((stdccCacheDataPtr)(newCache->data))->NamedCache) );
+       err = cc_create(gCntrlBlock, name, name, CC_CRED_V5,  
+                       0L, &(((stdccCacheDataPtr)(newCache->data))->NamedCache) );
        if (err != CC_NOERROR) return err;
        
        //setup some fields
@@ -75,11 +77,11 @@ krb5_error_code  krb5_stdcc_generate_new
 // -- resolve ------------------------------
 //
 // - create a new cache with the name stored in residual
-krb5_error_code  krb5_stdcc_resolve 
+krb5_error_code KRB5_CALLCONV  krb5_stdcc_resolve 
         (krb5_context context, krb5_ccache *id , const char *residual ) {
 
        krb5_ccache newCache;
-       int err,pos;
+       int err;
        char *cName;
        
        //make sure the API has been intialized
@@ -95,12 +97,12 @@ krb5_error_code  krb5_stdcc_resolve
        newCache->data = (stdccCacheDataPtr)malloc(sizeof(stdccCacheData));
        if (newCache->data == NULL) return KRB5_CC_NOMEM;
        
-       cName = residual;
+       cName = (char *)residual;
        //attempt to find a cache by the same name before creating it
        err = cc_open(gCntrlBlock, cName, CC_CRED_V5, 0L, &(((stdccCacheDataPtr)(newCache->data))->NamedCache));
        //we didn't find it.. create it.
        if (err) {
-               err = cc_create(gCntrlBlock, cName, CC_CRED_V5,  cName
+               err = cc_create(gCntrlBlock, cName, cName, CC_CRED_V5
                        0L, &(((stdccCacheDataPtr)(newCache->data))->NamedCache) );
                if (err != CC_NOERROR) return err; //still an error, return it
        }
@@ -113,16 +115,15 @@ krb5_error_code  krb5_stdcc_resolve
  // -- initialize --------------------------------
  //-initialize the cache, check to see if one already exists for this principal
  //    if not set our principal to this principal. This searching enables ticket sharing
-  krb5_error_code  krb5_stdcc_initialize 
+krb5_error_code KRB5_CALLCONV  krb5_stdcc_initialize 
        (krb5_context context, krb5_ccache id,  krb5_principal princ) 
 
   {
   
        int err, err1, found;
-       //char cName[kStringLiteralLen];
        char *cName = nil;
        ccache_p *testNC = NULL;
-       ccache_it *it;
+       ccache_cit *it;
        char *p = NULL, *targetName = NULL;
        
        //test id for null
@@ -137,8 +138,6 @@ krb5_error_code  krb5_stdcc_resolve
        if (err)
                return(err);
                
-       //sprintf(cName, "%s@%s", krb5_princ_name(context, princ)->data, krb5_princ_realm(context, princ)->data);
-
        //look for a cache already extant for this principal
        it = NULL;
        found = err = 0;
@@ -175,7 +174,7 @@ krb5_error_code  krb5_stdcc_resolve
 
 // -- store ----------------------------------
 // - store some credentials in our cache
- krb5_error_code  krb5_stdcc_store 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_store 
         (krb5_context context, krb5_ccache id , krb5_creds *creds )  {
        
        cred_union *cu = NULL;
@@ -199,7 +198,7 @@ krb5_error_code  krb5_stdcc_resolve
 
 // -- start_seq_get --------------------------
 // - begin an iterator call to get all of the credentials in the cache
-krb5_error_code  krb5_stdcc_start_seq_get 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_start_seq_get 
 (krb5_context context, krb5_ccache id , krb5_cc_cursor *cursor ) {
 
        //all we have to do is initialize the cursor
@@ -210,7 +209,7 @@ krb5_error_code  krb5_stdcc_start_seq_get
 // -- next cred ---------------------------
 // - get the next credential in the cache as part of an iterator call
 // - this maps to call to cc_seq_fetch_creds
-krb5_error_code  krb5_stdcc_next_cred 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_next_cred 
         (krb5_context context, 
                   krb5_ccache id , 
                   krb5_cc_cursor *cursor , 
@@ -218,10 +217,9 @@ krb5_error_code  krb5_stdcc_next_cred
 
        int err;
        cred_union *credU = NULL;
-       cc_creds *c = NULL;
        
        err = cc_seq_fetch_creds(gCntrlBlock, ((stdccCacheDataPtr)(id->data))->NamedCache,
-                                                        &credU, (ccache_it **)cursor);
+                                                        &credU, (ccache_cit **)cursor);
        
        if (err != CC_NOERROR)
                return err;
@@ -233,13 +231,12 @@ krb5_error_code  krb5_stdcc_next_cred
        cc_free_creds(gCntrlBlock, &credU);
        
        return CC_NOERROR;
-       
 }
 
 
 // -- retreive -------------------
 // - try to find a matching credential in the cache
-krb5_error_code  krb5_stdcc_retrieve 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_retrieve 
                        (krb5_context context, 
                   krb5_ccache id, 
                   krb5_flags whichfields, 
@@ -276,7 +273,7 @@ krb5_error_code  krb5_stdcc_retrieve
 
 // -- end seq ------------------------
 // - just free up the storage assoicated with the cursor (if we could)
- krb5_error_code  krb5_stdcc_end_seq_get 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_end_seq_get 
         (krb5_context context, krb5_ccache id , krb5_cc_cursor *cursor ) {
         
        //the limitation of the Ccache api and the seq calls
@@ -287,28 +284,38 @@ krb5_error_code  krb5_stdcc_retrieve
       
       //LEAK IT!
        *cursor = NULL;
+
+          return(0);
      }
      
 // -- close ---------------------------
 // - free our pointers to the NC
-krb5_error_code  
-krb5_stdcc_close(context, id, princ)
+krb5_error_code KRB5_CALLCONV 
+krb5_stdcc_close(context, id)
    krb5_context context;
    krb5_ccache id;
-   krb5_principal princ;
 {
-               
        //free it
-       free((stdccCacheDataPtr)(id->data));
-       //null it out
-       (stdccCacheDataPtr)(id->data) = NULL;
+       
+       if (id->data != NULL)
+       
+               {
+               free((stdccCacheDataPtr)(id->data));
+               //null it out
+               (stdccCacheDataPtr)(id->data) = NULL;
+               }
+       
+       //I suppose we ought to check if id is null before doing this, but no other place in krb5 does... -smcguire
+       free(id);
+       
+       id = NULL;
        
        return CC_NOERROR;
 }
 
 // -- destroy -------------
 // - free our storage and the cache
-krb5_error_code  
+krb5_error_code KRB5_CALLCONV
 krb5_stdcc_destroy (krb5_context context, krb5_ccache id ) {
 
        int err;
@@ -316,6 +323,8 @@ krb5_stdcc_destroy (krb5_context context, krb5_ccache id ) {
        //destroy the named cache
        err = cc_destroy(gCntrlBlock, &(((stdccCacheDataPtr)(id->data))->NamedCache));
        //free the pointer to the record that held the pointer to the cache
+       cc_shutdown(&gCntrlBlock);
+
        free((stdccCacheDataPtr)(id->data));
        //null it out
        (stdccCacheDataPtr)(id->data) = NULL;
@@ -326,7 +335,7 @@ krb5_stdcc_destroy (krb5_context context, krb5_ccache id ) {
        
 // -- getname ---------------------------
 // - return the name of the named cache
-char *  krb5_stdcc_get_name 
+char * KRB5_CALLCONV krb5_stdcc_get_name 
         (krb5_context context, krb5_ccache id ) {
         
        char *ret = NULL;
@@ -344,7 +353,7 @@ char *  krb5_stdcc_get_name
 
 // -- get_principal ---------------------------
 // - return the principal associated with the named cache
-krb5_error_code  
+krb5_error_code KRB5_CALLCONV
 krb5_stdcc_get_principal (krb5_context context, krb5_ccache id , krb5_principal *princ ) {
 
        int err;
@@ -359,12 +368,25 @@ krb5_stdcc_get_principal (krb5_context context, krb5_ccache id , krb5_principal
        //turn it into a krb principal
        err = krb5_parse_name(context, name, princ);
        
+#if defined(macintosh)
+       /* have to do something special on the Mac because name has been allocated with
+          Mac memory routine NewPtr and held in memory */
+       if (name != NULL)
+       {
+               UnholdMemory(name,GetPtrSize(name));
+               DisposePtr(name);
+       }
+#else
+       if (name != NULL)
+               free(name);
+#endif
+
        return err;     
 }
 
 // -- set_flags ---------------------------
 // - currently a NOP since we don't store any flags in the NC
-krb5_error_code  krb5_stdcc_set_flags 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_set_flags 
         (krb5_context context, krb5_ccache id , krb5_flags flags ) {
 
        return CC_NOERROR;
@@ -372,7 +394,7 @@ krb5_error_code  krb5_stdcc_set_flags
 
 // - remove ---------------------------
 // - remove the specified credentials from the NC
-krb5_error_code  krb5_stdcc_remove 
+krb5_error_code KRB5_CALLCONV krb5_stdcc_remove 
         (krb5_context context, krb5_ccache id , krb5_flags flags, krb5_creds *creds ) {
     
        cred_union *cu = NULL;
@@ -391,4 +413,4 @@ krb5_error_code  krb5_stdcc_remove
 
         return CC_NOERROR;
       }
-     
\ No newline at end of file
+     
index c157770c49673eef1816dc7a93765b5878960cf8..6db85b9d582b6a4321b95ba42a73304f71fe2994 100644 (file)
@@ -23,51 +23,51 @@ typedef struct _stdccCacheData {
 
 //function protoypes complete with bogus windowsesque macros.. 
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_close
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_close
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_destroy 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_destroy 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_end_seq_get 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_end_seq_get 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_cc_cursor *cursor ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_generate_new 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_generate_new 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache *id ));
 
-KRB5_DLLIMP char *  krb5_stdcc_get_name 
+KRB5_DLLIMP char * KRB5_CALLCONV krb5_stdcc_get_name 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_get_principal 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_get_principal 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_principal *princ ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_initialize 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_initialize 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_principal princ ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_next_cred 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_next_cred 
         KRB5_PROTOTYPE((krb5_context, 
                   krb5_ccache id , 
                   krb5_cc_cursor *cursor , 
                   krb5_creds *creds ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_resolve 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_resolve 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache *id , const char *residual ));
      
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_retrieve 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_retrieve 
         KRB5_PROTOTYPE((krb5_context, 
                   krb5_ccache id , 
                   krb5_flags whichfields , 
                   krb5_creds *mcreds , 
                   krb5_creds *creds ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_start_seq_get 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_start_seq_get 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_cc_cursor *cursor ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_store 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_store 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_creds *creds ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_set_flags 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_set_flags 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_flags flags ));
 
-KRB5_DLLIMP krb5_error_code  krb5_stdcc_remove 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_remove 
         KRB5_PROTOTYPE((krb5_context, krb5_ccache id , krb5_flags flags, krb5_creds *creds));
index 4f4fcfc50a6c20e88ec2f6b1692be8f56f403967..7d9891fcc838bddca3f69c968549b14371234e2f 100644 (file)
@@ -199,8 +199,6 @@ void dupCCtoK5(krb5_context context, cc_creds *src, krb5_creds *dest) {
 // - analagous to above but in the reverse direction
 void dupK52cc(krb5_context context, krb5_creds *creds, cred_union **cu) {
 
-               krb5_address **tA;
-               krb5_authdata **tAd;
                cc_creds *c;
                int err;
        #ifdef macintosh
@@ -212,6 +210,7 @@ void dupK52cc(krb5_context context, krb5_creds *creds, cred_union **cu) {
                //allocate the cred_union
                *cu = (cred_union *)sys_alloc(sizeof(cred_union));
                if ((*cu) == NULL) return;
+               
                (*cu)->cred_type = CC_CRED_V5;
                
                //allocate creds structure (and install)
@@ -281,7 +280,6 @@ void dupK52cc(krb5_context context, krb5_creds *creds, cred_union **cu) {
        
        return;
 }
-       
 
 // bitTst
 // - utility function for below function
@@ -300,12 +298,11 @@ int stdccCredsMatch(krb5_context context, krb5_creds *base, krb5_creds *match, i
        krb5_ticket_times b, m;
        krb5_authdata **bp, **mp;
        krb5_boolean retval;
-       krb5_principal_data p1, p2;
        
 
        //always check the standard fields
        if ((krb5_principal_compare(context, base->client, match->client) &&
-           krb5_principal_compare(context, base->server, match->server)) == false)
+           krb5_principal_compare(context, base->server, match->server)) == FALSE)
            return FALSE;
 
        if (bitTst(whichfields, KRB5_TC_MATCH_TIMES)) {
@@ -322,17 +319,17 @@ int stdccCredsMatch(krb5_context context, krb5_creds *base, krb5_creds *match, i
        } //continue search
        
        if (bitTst(whichfields, KRB5_TC_MATCH_IS_SKEY)) 
-               if (base->is_skey != match->is_skey) return false;
+               if (base->is_skey != match->is_skey) return FALSE;
        
        if (bitTst(whichfields, KRB5_TC_MATCH_FLAGS)) 
-               if (base->ticket_flags != match->ticket_flags) return false;
+               if (base->ticket_flags != match->ticket_flags) return FALSE;
                
        if (bitTst(whichfields, KRB5_TC_MATCH_TIMES_EXACT)) {
                b = base->times; m = match->times;
                if ((b.authtime != m.authtime) ||
                        (b.starttime != m.starttime) ||
                        (b.endtime != m.endtime) ||
-                       (b.renew_till != m.renew_till)) return false;
+                       (b.renew_till != m.renew_till)) return FALSE;
                }
                
        if (bitTst(whichfields, KRB5_TC_MATCH_AUTHDATA)) {
@@ -342,7 +339,7 @@ int stdccCredsMatch(krb5_context context, krb5_creds *base, krb5_creds *match, i
                while ( (bp) && (*bp != NULL) ){
                        if (( (*bp)->ad_type != (*mp)->ad_type) ||
                                ( (*bp)->length != (*mp)->length) ||
-                               ( memcmp( (*bp)->contents, (*mp)->contents, (*bp)->length) != 0)) return false;
+                               ( memcmp( (*bp)->contents, (*mp)->contents, (*bp)->length) != 0)) return FALSE;
                        mp++; bp++;
                }
          }
@@ -351,18 +348,18 @@ int stdccCredsMatch(krb5_context context, krb5_creds *base, krb5_creds *match, i
        if (bitTst(whichfields, KRB5_TC_MATCH_SRV_NAMEONLY)) {
                //taken from cc_retrv.c
                retval = krb5_principal_compare(context, base->client,match->client);
-               if (!retval) return false;
+               if (!retval) return FALSE;
          
          }
         
        if (bitTst(whichfields, KRB5_TC_MATCH_2ND_TKT)) 
                if ( (base->second_ticket.length != match->second_ticket.length) ||
                        (memcmp(base->second_ticket.data, match->second_ticket.data, base->second_ticket.length) != 0))
-                       return false;
+                       return FALSE;
                        
        if (bitTst(whichfields, KRB5_TC_MATCH_KTYPE))
-               if (base->keyblock.enctype != match->keyblock.enctype) return false;
+               if (base->keyblock.enctype != match->keyblock.enctype) return FALSE;
                        
        //if we fall through to here, they must match
-       return true;
+       return TRUE;
 }