Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/crypto/dist/heimdal/lib/krb5 Pullup from trunk:



details:   https://anonhg.NetBSD.org/src/rev/f5e6cfa54040
branches:  netbsd-1-5
changeset: 489065:f5e6cfa54040
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Aug 11 20:36:15 2000 +0000

description:
Pullup from trunk:
Flesh out the Memory Credential Cache for Heimdal Kerberos 5, some
applications expect to be able to resolve MCC names.

diffstat:

 crypto/dist/heimdal/lib/krb5/mcache.c |  143 +++++++++++++++++++++++++++++----
 1 files changed, 125 insertions(+), 18 deletions(-)

diffs (245 lines):

diff -r 3bbc32fbdd5f -r f5e6cfa54040 crypto/dist/heimdal/lib/krb5/mcache.c
--- a/crypto/dist/heimdal/lib/krb5/mcache.c     Fri Aug 11 20:17:56 2000 +0000
+++ b/crypto/dist/heimdal/lib/krb5/mcache.c     Fri Aug 11 20:36:15 2000 +0000
@@ -33,9 +33,13 @@
 
 #include "krb5_locl.h"
 
-RCSID("$Id: mcache.c,v 1.1.1.1 2000/06/16 18:33:00 thorpej Exp $");
+RCSID("$Id: mcache.c,v 1.1.1.1.2.1 2000/08/11 20:36:15 thorpej Exp $");
 
 typedef struct krb5_mcache {
+    struct krb5_mcache *next;
+    char *filename;
+    unsigned int refcnt;
+    int dead;
     krb5_principal primary_principal;
     struct link {
        krb5_creds cred;
@@ -43,33 +47,87 @@
     } *creds;
 } krb5_mcache;
 
+static struct krb5_mcache *mcc_head;
+
+#define        MCACHE(X)       ((krb5_mcache *)(X)->data.data)
+
+#define        FILENAME(X)     (MCACHE(X)->filename)
+
 #define MCC_CURSOR(C) ((struct link*)(C))
 
 static char*
 mcc_get_name(krb5_context context,
             krb5_ccache id)
 {
-    return "";                 /* XXX */
+    return FILENAME(id);
 }
 
 static krb5_error_code
 mcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
 {
-    krb5_abortx(context, "unimplemented mcc_resolve called");
+    krb5_mcache *m;
+
+    for (m = mcc_head; m != NULL; m = m->next)
+       if (m->dead == 0 && strcmp(m->filename, res) == 0)
+           break;
+
+    if (m != NULL) {
+       m->refcnt++;
+       (*id)->data.data = m;
+       (*id)->data.length = sizeof(*m);
+       return 0;
+    }
+
+    m = malloc(sizeof(*m));
+    if (m == NULL)
+       return KRB5_CC_NOMEM;
+
+    m->filename = strdup(res);
+    if (m->filename == NULL) {
+       free(m);
+       return KRB5_CC_NOMEM;
+    }
+
+    m->refcnt = 1;
+    m->dead = 0;
+    m->primary_principal = NULL;
+    m->creds = NULL;
+    (*id)->data.data = m;
+    (*id)->data.length = sizeof(*m);
+
+    m->next = mcc_head;
+    mcc_head = m;
+
+    return 0;
 }
 
 static krb5_error_code
 mcc_gen_new(krb5_context context, krb5_ccache *id)
 {
     krb5_mcache *m;
+    char *file;
 
     m = malloc (sizeof(*m));
     if (m == NULL)
        return KRB5_CC_NOMEM;
+
+    asprintf(&file, "%lX", (unsigned long)m);
+    if (file == NULL) {
+       free(m);
+       return KRB5_CC_NOMEM;
+    }
+
+    m->filename = file;
+    m->refcnt = 1;
+    m->dead = 0;
     m->primary_principal = NULL;
     m->creds = NULL;
     (*id)->data.data = m;
     (*id)->data.length = sizeof(*m);
+
+    m->next = mcc_head;
+    mcc_head = m;
+
     return 0;
 }
 
@@ -78,10 +136,8 @@
               krb5_ccache id,
               krb5_principal primary_principal)
 {
+    krb5_mcache *m = MCACHE(id);
     krb5_error_code ret;
-    krb5_mcache *m;
-
-    m = (krb5_mcache *)id->data.data;
 
     ret = krb5_copy_principal (context,
                               primary_principal,
@@ -95,10 +151,46 @@
 mcc_close(krb5_context context,
          krb5_ccache id)
 {
-    krb5_mcache *m = (krb5_mcache *)id->data.data;
+    krb5_mcache *m = MCACHE(id);
+
+    if (--m->refcnt != 0)
+       return 0;
+
+    if (m->dead) {
+       free(FILENAME(id));
+       krb5_data_free(&id->data);
+    }
+
+    return 0;
+}
+
+static krb5_error_code
+mcc_destroy(krb5_context context,
+           krb5_ccache id)
+{
+    krb5_mcache *n, *m = MCACHE(id);
     struct link *l;
 
-    krb5_free_principal (context, m->primary_principal);
+    if (m->refcnt == 0)
+       krb5_abortx(context, "mcc_destroy: refcnt already 0");
+
+    if (m->dead == 0) {
+       if (m == mcc_head)
+           mcc_head = m->next;
+       else {
+           for (n = mcc_head; n != NULL; n = n->next) {
+               if (n->next == m) {
+                   n->next = m->next;
+                   break;
+               }
+           }
+       }
+    }
+
+    if (m->primary_principal != NULL) {
+       krb5_free_principal (context, m->primary_principal);
+       m->primary_principal = NULL;
+    }
     l = m->creds;
     while (l != NULL) {
        struct link *old;
@@ -108,14 +200,15 @@
        l = l->next;
        free (old);
     }
-    krb5_data_free(&id->data);
-    return 0;
-}
+    m->creds = NULL;
+    m->dead = 1;
 
-static krb5_error_code
-mcc_destroy(krb5_context context,
-           krb5_ccache id)
-{
+    if (--m->refcnt != 0)
+       return 0;
+
+    free (FILENAME(id));
+    krb5_data_free(&id->data);
+
     return 0;
 }
 
@@ -124,10 +217,13 @@
               krb5_ccache id,
               krb5_creds *creds)
 {
+    krb5_mcache *m = MCACHE(id);
     krb5_error_code ret;
-    krb5_mcache *m = (krb5_mcache *)id->data.data;
     struct link *l;
 
+    if (m->dead)
+       return ENOENT;
+
     l = malloc (sizeof(*l));
     if (l == NULL)
        return KRB5_CC_NOMEM;
@@ -148,7 +244,10 @@
                  krb5_ccache id,
                  krb5_principal *principal)
 {
-    krb5_mcache *m = (krb5_mcache *)id->data.data;
+    krb5_mcache *m = MCACHE(id);
+
+    if (m->dead)
+       return ENOENT;
 
     return krb5_copy_principal (context,
                                m->primary_principal,
@@ -160,7 +259,11 @@
               krb5_ccache id,
               krb5_cc_cursor *cursor)
 {
-    krb5_mcache *m = (krb5_mcache *)id->data.data;
+    krb5_mcache *m = MCACHE(id);
+
+    if (m->dead)
+       return ENOENT;
+
     *cursor = m->creds;
     return 0;
 }
@@ -171,8 +274,12 @@
              krb5_cc_cursor *cursor,
              krb5_creds *creds)
 {
+    krb5_mcache *m = MCACHE(id);
     struct link *l;
 
+    if (m->dead)
+       return ENOENT;
+
     l = *cursor;
     if (l != NULL) {
        *cursor = l->next;



Home | Main Index | Thread Index | Old Index