if (err != CC_NOERROR)
return cc_err_xlate(err);
- /* free the cred union */
- err = cc_free_creds(gCntrlBlock, &cu);
+ /* free the cred union using our local version of cc_free_creds()
+ since we allocated it locally */
+ err = krb5_free_cc_cred_union(&cu);
cache_changed();
return err;
/* copy data (with translation) */
dupCCtoK5(context, credU->cred.pV5Cred, creds);
- /* free our version of the cred */
+ /* free our version of the cred - okay to use cc_free_creds() here
+ because we got it from the CCache library */
cc_free_creds(gCntrlBlock, &credU);
return 0;
if (err)
break;
+ /* okay to call cc_free_creds() here because we got credU from CCache lib */
cc_free_creds(gCntrlBlock, &credU);
}
#endif
if (err != CC_NOERROR)
return cc_err_xlate(err);
- /* free the temp cred union */
- err = cc_free_creds(gCntrlBlock, &cu);
+ /* free the cred union using our local version of cc_free_creds()
+ since we allocated it locally */
+ err = krb5_free_cc_cred_union(&cu);
cache_changed();
if (err != CC_NOERROR)
return cc_err_xlate(err);
#define fieldSize 255
-/* on the Mac, we need the calls which allocate memory for the Credentials Cache to use
- Ptr's in the system help, so that they stay global and so that bad things don't happen
- when we call DisposePtr() on them. However, on other systems, malloc is probably the
- right thing to use.
- So for any place where we allocate memory for the Credentials Cache, use sys_alloc() and
- define it accordingly.
-*/
-
-#if defined(macintosh)
-#define sys_alloc(size) NewSafePtrSys(size)
-#else
-#define sys_alloc(size) malloc(size)
-#endif
-
-#if defined(macintosh)
-/*
- * stolen from CCacheUtils.c
- * -- NewSafePtrSys -----------------
- * - analagous to NewSafePtr but memory is allocated in the system heap
- */
-static Ptr NewSafePtrSys(long size) {
-
- Ptr retPtr;
-
- retPtr = NewPtrSys(size);
-
- if (retPtr != NULL)
- HoldMemory(retPtr, size);
-
- return retPtr;
-}
-#endif
-
/*
* CopyCCDataArrayToK5
* - copy and translate the null terminated arrays of data records
//calc number of records
while (*kbase++ != NULL) numRecords++;
//allocate new array
- constCBase = cbase = (cc_data **)sys_alloc((numRecords+1)*sizeof(char *));
+ constCBase = cbase = (cc_data **)malloc((numRecords+1)*sizeof(char *));
//reset base
kbase = (whichArray == kAddressArray) ? kc->addresses : (krb5_address **)kc->authdata;
//copy records
while (*kbase != NULL) {
- *cbase = (cc_data *)sys_alloc(sizeof(krb5_address));
+ *cbase = (cc_data *)malloc(sizeof(krb5_address));
kAdr = *kbase;
ccAdr = *cbase;
ccAdr->type = kAdr->addrtype;
ccAdr->length = kAdr->length;
- ccAdr->data = (unsigned char *)sys_alloc(ccAdr->length);
+ ccAdr->data = (unsigned char *)malloc(ccAdr->length);
memcpy(ccAdr->data, kAdr->contents, kAdr->length);
//next element please
kbase++; cbase++;
if (cu == NULL) return;
/* allocate the cred_union */
- *cu = (cred_union *)sys_alloc(sizeof(cred_union));
+ *cu = (cred_union *)malloc(sizeof(cred_union));
if ((*cu) == NULL)
return;
(*cu)->cred_type = CC_CRED_V5;
/* allocate creds structure (and install) */
- c = (cc_creds *)sys_alloc(sizeof(cc_creds));
+ c = (cc_creds *)malloc(sizeof(cc_creds));
if (c == NULL) return;
(*cu)->cred.pV5Cred = c;
* puts it in appl heap with malloc)
*/
err = krb5_unparse_name(context, creds->client, &tempname);
- c->client = sys_alloc(strlen(tempname));
+ c->client = malloc(strlen(tempname));
if (c->client != NULL)
strcpy(c->client,tempname);
free(tempname);
tempname = NULL;
err = krb5_unparse_name(context, creds->server, &tempname);
- c->server = sys_alloc(strlen(tempname));
+ c->server = malloc(strlen(tempname));
if (c->server != NULL)
strcpy(c->server,tempname);
free(tempname);
c->keyblock.length = creds->keyblock.length;
if (creds->keyblock.contents != NULL) {
- c->keyblock.data = (unsigned char *)sys_alloc(creds->keyblock.length);
+ c->keyblock.data = (unsigned char *)malloc(creds->keyblock.length);
memcpy(c->keyblock.data, creds->keyblock.contents, creds->keyblock.length);
} else {
c->keyblock.data = NULL;
c->ticket.length = creds->ticket.length;
if (creds->ticket.data != NULL) {
- c->ticket.data = (unsigned char *)sys_alloc(creds->ticket.length);
+ c->ticket.data = (unsigned char *)malloc(creds->ticket.length);
memcpy(c->ticket.data, creds->ticket.data, creds->ticket.length);
} else {
c->ticket.data = NULL;
c->second_ticket.length = creds->second_ticket.length;
if (creds->second_ticket.data != NULL) {
- c->second_ticket.data = (unsigned char *)sys_alloc(creds->second_ticket.length);
+ c->second_ticket.data = (unsigned char *)malloc(creds->second_ticket.length);
memcpy(c->second_ticket.data, creds->second_ticket.data, creds->second_ticket.length);
} else {
c->second_ticket.data = NULL;
return FALSE;
}
+
+// ----- free_cc_cred_union, etc --------------
+/*
+ Since the Kerberos5 library allocates a credentials cache structure
+ (in dupK5toCC() above) with its own memory allocation routines - which
+ may be different than how the CCache allocates memory - the Kerb5 library
+ must have its own version of cc_free_creds() to deallocate it. These
+ functions do that. The top-level function to substitue for cc_free_creds()
+ is krb5_free_cc_cred_union().
+
+ If the CCache library wants to use a cred_union structure created by
+ the Kerb5 library, it should make a deep copy of it to "translate" to its
+ own memory allocation space.
+*/
+static void deep_free_cc_data (cc_data data) {
+
+ if (data.data != NULL)
+ free (data.data);
+}
+
+static void deep_free_cc_data_array (cc_data** data) {
+
+ cc_uint32 index;
+
+ if (data == NULL)
+ return;
+
+ for (index = 0; data [index] != NULL; index++) {
+ deep_free_cc_data (*(data [index]));
+ free (data [index]);
+ }
+
+ free (data);
+}
+
+static void deep_free_cc_v5_creds (cc_creds* creds) {
+
+ if (creds == NULL)
+ return;
+
+ if (creds -> client != NULL)
+ free (creds -> client);
+ if (creds -> server != NULL)
+ free (creds -> server);
+
+ deep_free_cc_data (creds -> keyblock);
+ deep_free_cc_data (creds -> ticket);
+ deep_free_cc_data (creds -> second_ticket);
+
+ deep_free_cc_data_array (creds -> addresses);
+ deep_free_cc_data_array (creds -> authdata);
+}
+
+static void deep_free_cc_creds (cred_union creds) {
+
+ if (creds.cred_type == CC_CRED_V4) { // we shouldn't get this, of course
+ free (creds.cred.pV4Cred);
+ } else if (creds.cred_type == CC_CRED_V5) {
+ deep_free_cc_v5_creds (creds.cred.pV5Cred);
+ }
+}
+
+// top-level exported function
+cc_int32 krb5_free_cc_cred_union (cred_union** creds) {
+
+ if (creds == NULL)
+ return CC_BAD_PARM;
+
+ if (*creds != NULL) {
+ deep_free_cc_creds (**creds);
+ free (*creds);
+ *creds = NULL;
+ }
+
+ return CC_NOERROR;
+}
\ No newline at end of file