Skip to content

Commit

Permalink
HEIMDAL:lib/krb5: destroy a memory ccache on reinit
Browse files Browse the repository at this point in the history
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12369

Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Günther Deschner <[email protected]>
Reviewed-by: Uri Simchoni <[email protected]>
(cherry picked from commit 2abc371)
  • Loading branch information
metze-samba authored and kseeger committed Oct 20, 2016
1 parent 0b7656b commit e6c2921
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions source4/heimdal/lib/krb5/mcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,47 @@ mcc_gen_new(krb5_context context, krb5_ccache *id)
return 0;
}

static void KRB5_CALLCONV
mcc_destroy_internal(krb5_context context,
krb5_mcache *m)
{
struct link *l;

if (m->primary_principal != NULL) {
krb5_free_principal (context, m->primary_principal);
m->primary_principal = NULL;
}
m->dead = 1;

l = m->creds;
while (l != NULL) {
struct link *old;

krb5_free_cred_contents (context, &l->cred);
old = l;
l = l->next;
free (old);
}

m->creds = NULL;
return;
}

static krb5_error_code KRB5_CALLCONV
mcc_initialize(krb5_context context,
krb5_ccache id,
krb5_principal primary_principal)
{
krb5_mcache *m = MCACHE(id);
/*
* It's important to destroy any existing
* creds here, that matches the baheviour
* of all other backends and also the
* MEMORY: backend in MIT.
*/
mcc_destroy_internal(context, m);
m->dead = 0;
m->kdc_offset = 0;
m->mtime = time(NULL);
return krb5_copy_principal (context,
primary_principal,
Expand Down Expand Up @@ -195,7 +229,6 @@ mcc_destroy(krb5_context context,
krb5_ccache id)
{
krb5_mcache **n, *m = MCACHE(id);
struct link *l;

if (m->refcnt == 0)
krb5_abortx(context, "mcc_destroy: refcnt already 0");
Expand All @@ -211,22 +244,7 @@ mcc_destroy(krb5_context context,
}
}
HEIMDAL_MUTEX_unlock(&mcc_mutex);
if (m->primary_principal != NULL) {
krb5_free_principal (context, m->primary_principal);
m->primary_principal = NULL;
}
m->dead = 1;

l = m->creds;
while (l != NULL) {
struct link *old;

krb5_free_cred_contents (context, &l->cred);
old = l;
l = l->next;
free (old);
}
m->creds = NULL;
mcc_destroy_internal(context, m);
}
return 0;
}
Expand Down

0 comments on commit e6c2921

Please sign in to comment.