#include "stdcc.h"
#include "string.h"
+#include <stdio.h>
+
//declare our global object wanna-be
//must be installed in ccdefops.c
// -- 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 )
{
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
// -- 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
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
}
// -- 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
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;
// -- 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;
// -- 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
// -- 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 ,
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;
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,
// -- 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
//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;
//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;
// -- 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;
// -- 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;
//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;
// - 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;
return CC_NOERROR;
}
-
\ No newline at end of file
+
//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));
// - 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
//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)
return;
}
-
// bitTst
// - utility function for below function
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)) {
} //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)) {
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++;
}
}
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;
}