Checked in jfc's changes to handle the new principal structure
authorTheodore Tso <tytso@mit.edu>
Wed, 10 Jun 1992 22:50:57 +0000 (22:50 +0000)
committerTheodore Tso <tytso@mit.edu>
Wed, 10 Jun 1992 22:50:57 +0000 (22:50 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2296 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/stdio/scc_read.c
src/lib/krb5/ccache/stdio/scc_write.c

index 62514fc6f3f2cea7004dc28148552e76594c2bdd..864c885fd2d346de5a607d381a47b08a2d2bc6d1 100644 (file)
@@ -83,45 +83,43 @@ krb5_scc_read_principal(id, princ)
    krb5_ccache id;
    krb5_principal *princ;
 {
-     krb5_error_code kret;
-     krb5_int32 length;
-     int i;
-
-     *princ = 0;
-
-     /* Read the number of components */
-     kret = krb5_scc_read_int32(id, &length);
-     CHECK(kret);
-
-     /*
-      * The # of levels of indirection is confusing.  A krb5_principal
-      * is an array of pointers to krb5_data.  princ is a pointer to
-      * an array of pointers to krb5_data.  (*princ)[i] a pointer to
-      * krb5_data.
-      */
+    krb5_error_code kret;
+    register krb5_principal tmpprinc;
+    krb5_int32 length;
+    int i;
+
+    /* Read the number of components */
+    kret = krb5_scc_read_int32(id, &length);
+    if (kret != KRB5_OK)
+       return kret;
+
+    tmpprinc = (krb5_principal) malloc(sizeof(krb5_principal_data));
+    if (tmpprinc == NULL)
+       return KRB5_CC_NOMEM;
+    tmpprinc->data = malloc(length * sizeof(krb5_principal_data));
+    if (tmpprinc->data == 0) {
+       free((char *)tmpprinc);
+       return KRB5_CC_NOMEM;
+    }
+    tmpprinc->length = length;
 
-     /* Make *princ able to hold length pointers to krb5_data structs
-      * Add one extra for a null-terminated list
-      */
-     *princ = (krb5_principal) calloc(length+1, sizeof(krb5_data *));
-     if (*princ == NULL)
-         return KRB5_CC_NOMEM;
+    kret = krb5_scc_read_data(id, krb5_princ_realm(tmpprinc));
+    i = 0;
+    CHECK(kret);
 
-     for (i=0; i < length; i++) {
-         (*princ)[i] = (krb5_data *) malloc(sizeof(krb5_data));
-         if ((*princ)[i] == NULL) {
-             krb5_free_principal(*princ);
-             return KRB5_CC_NOMEM;
-          }      
-         kret = krb5_scc_read_data(id, (*princ)[i]);
-         CHECK(kret);
-     }
+    for (i=0; i < length; i++) {
+       kret = krb5_scc_read_data(id, krb5_princ_component(tmpprinc, i));
+       CHECK(kret);
+    }
+    *princ = tmpprinc;
+    return KRB5_OK;
 
-     return kret;
  errout:
-     if (*princ)
-        krb5_free_principal(*princ);
-     return kret;
+    while(--i >= 0)
+       free(krb5_princ_component(tmpprinc, i)->data);
+    free((char *)tmpprinc->data);
+    free((char *)tmpprinc);
+    return KRB5_CC_NOMEM;
 }
 
 krb5_error_code
index 5db04a66938d741eba037f8108b3cd03cf119f9b..47b23af32c36674a0e37fb904c458161851aa66b 100644 (file)
@@ -81,23 +81,23 @@ krb5_scc_store_principal(id, princ)
    krb5_ccache id;
    krb5_principal princ;
 {
-     krb5_error_code ret;
-     krb5_principal temp;
-     krb5_int32 i, length = 0;
+    krb5_error_code ret;
+    krb5_int32 i, length;
 
-     /* Count the number of components */
-     temp = princ;
-     while (*temp++)
-         length += 1;
+    length = krb5_princ_size(princ);
 
-     ret = krb5_scc_store_int32(id, &length);
-     CHECK(ret);
-     for (i=0; i < length; i++) {
-         ret = krb5_scc_store_data(id, princ[i]);
-         CHECK(ret);
-     }
+    ret = krb5_scc_store_int32(id, &length);
+    CHECK(ret);
 
-     return KRB5_OK;
+    ret = krb5_scc_store_data(id, krb5_princ_realm(princ));
+    CHECK(ret);
+
+    for (i=0; i < length; i++) {
+       ret = krb5_scc_store_data(id, krb5_princ_component(princ, i));
+       CHECK(ret);
+    }
+
+    return KRB5_OK;
 }
 
 krb5_error_code