All files:
authorTheodore Tso <tytso@mit.edu>
Fri, 18 Nov 1994 19:56:41 +0000 (19:56 +0000)
committerTheodore Tso <tytso@mit.edu>
Fri, 18 Nov 1994 19:56:41 +0000 (19:56 +0000)
Changes to implement SCC format version #3, which is architecture
independent, and includes the key encryption type information.

scc_gennew.c (krb5_scc_generate_new): Generate new ccaches using
whatever version is marked as the default.

scc_read.c (krb5_scc_read_keyblock): Insert keyblock magic
number and initialize etype value.  Also add magic numbers
for the krb5_principal, krb5_data, krb5_address, and
krb5_authdata structures.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4693 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/stdio/ChangeLog
src/lib/krb5/ccache/stdio/scc-proto.h
src/lib/krb5/ccache/stdio/scc.h
src/lib/krb5/ccache/stdio/scc_gennew.c
src/lib/krb5/ccache/stdio/scc_maybe.c
src/lib/krb5/ccache/stdio/scc_nseq.c
src/lib/krb5/ccache/stdio/scc_read.c
src/lib/krb5/ccache/stdio/scc_store.c
src/lib/krb5/ccache/stdio/scc_write.c

index 01c6641fa64eb2b687d33a212d9224663f264786..576b44ffbf5d655d9211927b8b936d8d15c1b7af 100644 (file)
@@ -1,3 +1,21 @@
+Fri Nov 18 14:47:33 1994  Theodore Y. Ts'o  (tytso@dcl)
+
+        * scc-proto.h, scc.h, scc_maybe.c (krb5_scc_open_file), scc_nseq.c
+       (krb5_scc_next_cred), scc_store.c (krb5_scc_store), scc_read.c,
+       scc_write.c:  Changes to implement SCC format version #3, which
+               is architecture independent, and includes the key
+               encryption type information.
+
+Wed Nov 16 23:40:16 1994  Theodore Y. Ts'o  (tytso@dcl)
+
+       * scc_gennew.c (krb5_scc_generate_new): Generate new ccaches using
+               whatever version is marked as the default.
+
+       * scc_read.c (krb5_scc_read_keyblock): Insert keyblock magic
+               number and initialize etype value.  Also add magic numbers
+               for the krb5_principal, krb5_data, krb5_address, and
+               krb5_authdata structures.
+
 Thu Oct 13 17:24:00 1994  Theodore Y. Ts'o  (tytso@maytag)
 
        * configure.in: Add ISODE_DEFS
index 3e4418c5eabe4b70d5cf233e107b8feb7de753fb..9cae8412314d3d2a3e4585db0963c94b4c4f7b9a 100644 (file)
@@ -65,11 +65,8 @@ krb5_error_code krb5_scc_read_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock
 krb5_error_code krb5_scc_read_data PROTOTYPE((krb5_ccache id , krb5_data *data ));
 krb5_error_code krb5_scc_read_int32 PROTOTYPE((krb5_ccache id , krb5_int32 *i ));
 krb5_error_code krb5_scc_read_ui_2 PROTOTYPE((krb5_ccache id , krb5_ui_2 *i ));
-krb5_error_code krb5_scc_read_keytype PROTOTYPE((krb5_ccache id , krb5_keytype *k ));
-krb5_error_code krb5_scc_read_int PROTOTYPE((krb5_ccache id , int *i ));
-krb5_error_code krb5_scc_read_bool PROTOTYPE((krb5_ccache id , krb5_boolean *b ));
+krb5_error_code krb5_scc_read_octet PROTOTYPE((krb5_ccache id , krb5_octet *i ));
 krb5_error_code krb5_scc_read_times PROTOTYPE((krb5_ccache id , krb5_ticket_times *t ));
-krb5_error_code krb5_scc_read_flags PROTOTYPE((krb5_ccache id , krb5_flags *f ));
 krb5_error_code krb5_scc_read_addrs PROTOTYPE((krb5_ccache, krb5_address ***));
 krb5_error_code krb5_scc_read_addr PROTOTYPE((krb5_ccache, krb5_address *));
 krb5_error_code krb5_scc_read_authdata PROTOTYPE((krb5_ccache, krb5_authdata***));
@@ -101,13 +98,10 @@ krb5_error_code krb5_scc_write PROTOTYPE((krb5_ccache id , krb5_pointer buf , in
 krb5_error_code krb5_scc_store_principal PROTOTYPE((krb5_ccache id , krb5_principal princ ));
 krb5_error_code krb5_scc_store_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock *keyblock ));
 krb5_error_code krb5_scc_store_data PROTOTYPE((krb5_ccache id , krb5_data *data ));
-krb5_error_code krb5_scc_store_int32 PROTOTYPE((krb5_ccache id , krb5_int32 *i ));
-krb5_error_code krb5_scc_store_ui_2 PROTOTYPE((krb5_ccache id , krb5_ui_2 *i ));
-krb5_error_code krb5_scc_store_keytype PROTOTYPE((krb5_ccache id , krb5_keytype *k ));
-krb5_error_code krb5_scc_store_int PROTOTYPE((krb5_ccache id , int *i ));
-krb5_error_code krb5_scc_store_bool PROTOTYPE((krb5_ccache id , krb5_boolean *b ));
+krb5_error_code krb5_scc_store_int32 PROTOTYPE((krb5_ccache id , krb5_int32 i ));
+krb5_error_code krb5_scc_store_ui_2 PROTOTYPE((krb5_ccache id , krb5_int32 i ));
+krb5_error_code krb5_scc_store_octet PROTOTYPE((krb5_ccache id , krb5_int32 i ));
 krb5_error_code krb5_scc_store_times PROTOTYPE((krb5_ccache id , krb5_ticket_times *t ));
-krb5_error_code krb5_scc_store_flags PROTOTYPE((krb5_ccache id , krb5_flags *f ));
 krb5_error_code krb5_scc_store_addrs PROTOTYPE((krb5_ccache , krb5_address ** ));
 krb5_error_code krb5_scc_store_addr PROTOTYPE((krb5_ccache , krb5_address * ));
 krb5_error_code krb5_scc_store_authdata PROTOTYPE((krb5_ccache, krb5_authdata **));
index 6ae8b2e70be7414f04ecb27404d3564bbfcdaca0..203b316b52e9f671f1129787d9e53bb07d1cc4ae 100644 (file)
  */
 
 #define KRB5_SCC_FVNO_1 0x0501         /* krb v5, scc v1 */
-#define KRB5_SCC_FVNO   0x0502         /* krb5 v5, scc v2 */
+#define KRB5_SCC_FVNO_2   0x0502       /* krb v5, scc v2 */
+#define KRB5_SCC_FVNO_3   0x0503       /* krb v5, scc v2 */
 
-#define KRB5_SCC_DEFAULT_FVNO KRB5_SCC_FVNO
+#define KRB5_SCC_DEFAULT_FVNO KRB5_SCC_FVNO_3
 
 #define        SCC_OPEN_AND_ERASE      1
 #define        SCC_OPEN_RDWR           2
index a65241006b98adaa5b2f544dd4c7c98dca070356..7775a6fb20c0d3528c497a6dfab5419be364f180 100644 (file)
@@ -102,7 +102,7 @@ krb5_scc_generate_new (id)
             retcode = krb5_scc_interpret (errno);
             goto err_out;
      } else {
-        krb5_int16 scc_fvno = htons(KRB5_SCC_FVNO);
+        krb5_int16 scc_fvno = htons(KRB5_SCC_DEFAULT_FVNO);
 
         if (!fwrite((char *)&scc_fvno, sizeof(scc_fvno), 1, f)) {
             retcode = krb5_scc_interpret(errno);
index 8237650b22f889967ccf455557da80a821a311b2..410dc6b6c2238d07147e56e04649e58d56407cd6 100644 (file)
@@ -166,8 +166,9 @@ krb5_scc_open_file (id, mode)
             (void) fclose(f);
             return KRB5_CCACHE_BADVNO;
         }
-        if ((scc_fvno != htons(KRB5_SCC_FVNO)) &&
-            (scc_fvno != htons(KRB5_SCC_FVNO_1))) {
+        if ((scc_fvno != htons(KRB5_SCC_FVNO_1)) &&
+            (scc_fvno != htons(KRB5_SCC_FVNO_2)) &&
+            (scc_fvno != htons(KRB5_SCC_FVNO_3))) {
             (void) krb5_unlock_file(f, data->filename);
             (void) fclose(f);
             return KRB5_CCACHE_BADVNO;
index 3f8ce3f84e45773ef709badec06c43d61c5cbc6a..365f57330b3b7484a757c4d98c1b99e54d644a7d 100644 (file)
@@ -58,6 +58,8 @@ krb5_scc_next_cred(id, cursor, creds)
      int ret;
      krb5_error_code kret;
      krb5_scc_cursor *fcursor;
+     krb5_int32 int32;
+     krb5_octet octet;
 
 #define Z(field)       creds->field = 0
      Z (client);
@@ -87,10 +89,12 @@ krb5_scc_next_cred(id, cursor, creds)
      TCHECK(kret);
      kret = krb5_scc_read_times(id, &creds->times);
      TCHECK(kret);
-     kret = krb5_scc_read_bool(id, &creds->is_skey);
+     kret = krb5_scc_read_octet(id, &octet);
      TCHECK(kret);
-     kret = krb5_scc_read_flags(id, &creds->ticket_flags);
+     creds->is_skey = octet;
+     kret = krb5_scc_read_int32(id, &int32);
      TCHECK(kret);
+     creds->ticket_flags = int32;
      kret = krb5_scc_read_addrs(id, &creds->addresses);
      TCHECK(kret);
      kret = krb5_scc_read_authdata (id, &creds->authdata);
index ce3ed3ea29ce3c7b3bdd4d9c15905344b429e91a..1a7ee5a2dbc1d8e0be9d0187793dcc5840bcef92 100644 (file)
@@ -87,12 +87,12 @@ krb5_scc_read_principal(id, princ)
     if (data->version == KRB5_SCC_FVNO_1) {
        type = KRB5_NT_UNKNOWN;
     } else {
-        /* Read the principal type */
+        /* Read principal type */
         kret = krb5_scc_read_int32(id, &type);
         if (kret != KRB5_OK)
            return kret;
     }
-    
+
     /* Read the number of components */
     kret = krb5_scc_read_int32(id, &length);
     if (kret != KRB5_OK)
@@ -108,15 +108,20 @@ krb5_scc_read_principal(id, princ)
     tmpprinc = (krb5_principal) malloc(sizeof(krb5_principal_data));
     if (tmpprinc == NULL)
        return KRB5_CC_NOMEM;
-    tmpprinc->data = (krb5_data *) malloc(length * sizeof(krb5_data));
-    if (tmpprinc->data == 0) {
-       free((char *)tmpprinc);
-       return KRB5_CC_NOMEM;
-    }
+    if (length) {
+           tmpprinc->data = (krb5_data *) malloc(length * sizeof(krb5_data));
+           if (tmpprinc->data == 0) {
+                   free((char *)tmpprinc);
+                   return KRB5_CC_NOMEM;
+           }
+    } else
+           tmpprinc->data = 0;
+    tmpprinc->magic = KV5M_PRINCIPAL;
     tmpprinc->length = length;
     tmpprinc->type = type;
 
     kret = krb5_scc_read_data(id, krb5_princ_realm(tmpprinc));
+
     i = 0;
     CHECK(kret);
 
@@ -179,33 +184,39 @@ krb5_scc_read_keyblock(id, keyblock)
    krb5_ccache id;
    krb5_keyblock *keyblock;
 {
+     krb5_scc_data *data = (krb5_scc_data *)id->data;
      krb5_error_code kret;
-     int ret;
+     krb5_ui_2 ui2;
+     krb5_int32 int32;
 
+     keyblock->magic = KV5M_KEYBLOCK;
      keyblock->contents = 0;
 
-     kret = krb5_scc_read_keytype(id, &keyblock->keytype);
+     kret = krb5_scc_read_ui_2(id, &ui2);
+     keyblock->keytype = ui2;
      CHECK(kret);
-     kret = krb5_scc_read_int(id, &keyblock->length);
+     if ((data->version == KRB5_SCC_FVNO_1) ||
+        (data->version == KRB5_SCC_FVNO_2))
+            keyblock->etype = ETYPE_UNKNOWN;
+     else {
+            kret = krb5_scc_read_ui_2(id, &ui2);
+            keyblock->etype = ui2;
+            CHECK(kret);
+     }
+
+     kret = krb5_scc_read_int32(id, &int32);
      CHECK(kret);
+     keyblock->length = int32;
+     if ( keyblock->length == 0 )
+            return KRB5_OK;
      keyblock->contents = (unsigned char *) malloc(keyblock->length*
                                                   sizeof(krb5_octet));
      if (keyblock->contents == NULL)
          return KRB5_CC_NOMEM;
      
-     errno = 0;
-     ret = fread((char *)keyblock->contents, 1,
-                (keyblock->length)*sizeof(krb5_octet),
-                ((krb5_scc_data *) id->data)->file);
-
-     if ((ret == 0) && errno) {
-        krb5_xfree(keyblock->contents);
-        return krb5_scc_interpret(errno);
-     }
-     if (ret != (keyblock->length)*sizeof(krb5_octet)) {
-        krb5_xfree(keyblock->contents);
-        return KRB5_CC_END;
-     }
+     kret = krb5_scc_read(id, keyblock->contents, keyblock->length);
+     if (kret)
+        goto errout;
 
      return KRB5_OK;
  errout:
@@ -220,29 +231,26 @@ krb5_scc_read_data(id, data)
    krb5_data *data;
 {
      krb5_error_code kret;
-     int ret;
 
+     data->magic = KV5M_DATA;
      data->data = 0;
 
      kret = krb5_scc_read_int32(id, &data->length);
      CHECK(kret);
 
+     if (data->length == 0) {
+       data->data = 0;
+       return KRB5_OK;
+     }
+
      data->data = (char *) malloc(data->length+1);
      if (data->data == NULL)
          return KRB5_CC_NOMEM;
 
-     errno = 0;
-     ret = fread((char *)data->data, 1,
-                data->length, ((krb5_scc_data *) id->data)->file);
-     if ((ret == 0) && errno) {
-        krb5_xfree(data->data);
-        return krb5_scc_interpret(errno);
-     }
-     if (ret != data->length) {
-        krb5_xfree(data->data);
-        return KRB5_CC_END;
-     }
-     data->data[data->length] = 0; /* Null terminate just in case.... */
+     kret = krb5_scc_read(id, data->data, data->length);
+     CHECK(kret);
+     
+     data->data[data->length] = 0; /* Null terminate, just in case.... */
      return KRB5_OK;
  errout:
      if (data->data)
@@ -256,31 +264,30 @@ krb5_scc_read_addr(id, addr)
    krb5_address *addr;
 {
      krb5_error_code kret;
-     int ret;
+     krb5_ui_2 ui2;
+     krb5_int32 int32;
 
+     addr->magic = KV5M_ADDRESS;
      addr->contents = 0;
 
-     kret = krb5_scc_read_ui_2(id, &addr->addrtype);
+     kret = krb5_scc_read_ui_2(id, &ui2);
      CHECK(kret);
-
-     kret = krb5_scc_read_int(id, &addr->length);
+     addr->addrtype = ui2;
+     
+     kret = krb5_scc_read_int32(id, &int32);
      CHECK(kret);
+     addr->length = int32;
+
+     if (addr->length == 0)
+            return KRB5_OK;
 
      addr->contents = (krb5_octet *) malloc(addr->length);
      if (addr->contents == NULL)
          return KRB5_CC_NOMEM;
 
-     errno = 0;
-     ret = fread((char *)addr->contents, 1, (addr->length)*sizeof(krb5_octet),
-                ((krb5_scc_data *) id->data)->file);
-     if ((ret == 0) && errno) {
-         krb5_xfree(addr->contents);
-         return krb5_scc_interpret(errno);
-     }
-     if (ret != (addr->length)*sizeof(krb5_octet)) {
-         krb5_xfree(addr->contents);
-         return KRB5_CC_END;
-     }
+     kret = krb5_scc_read(id, addr->contents, addr->length);
+     CHECK(kret);
+
      return KRB5_OK;
  errout:
      if (addr->contents)
@@ -293,7 +300,20 @@ krb5_scc_read_int32(id, i)
    krb5_ccache id;
    krb5_int32 *i;
 {
-     return krb5_scc_read(id, (krb5_pointer) i, sizeof(krb5_int32));
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
+    krb5_error_code retval;
+    unsigned char buf[4];
+
+    if ((data->version == KRB5_SCC_FVNO_1) ||
+       (data->version == KRB5_SCC_FVNO_2)) 
+       return krb5_scc_read(id, (krb5_pointer) i, sizeof(krb5_int32));
+    else {
+       retval = krb5_scc_read(id, buf, 4);
+       if (retval)
+           return retval;
+       *i = (((((buf[0] << 8) + buf[1]) << 8 ) + buf[2]) << 8) + buf[3];
+       return 0;
+    }
 }
 
 krb5_error_code
@@ -301,47 +321,63 @@ krb5_scc_read_ui_2(id, i)
    krb5_ccache id;
    krb5_ui_2 *i;
 {
-     return krb5_scc_read(id, (krb5_pointer) i, sizeof(krb5_ui_2));
-}
-
-krb5_error_code
-krb5_scc_read_keytype(id, k)
-   krb5_ccache id;
-   krb5_keytype *k;
-{
-     return krb5_scc_read(id, (krb5_pointer) k, sizeof(krb5_keytype));
-}
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
+    krb5_error_code retval;
+    unsigned char buf[2];
+    
+    if ((data->version == KRB5_SCC_FVNO_1) ||
+       (data->version == KRB5_SCC_FVNO_2))
+       return krb5_scc_read(id, (krb5_pointer) i, sizeof(krb5_ui_2));
+    else {
+       retval = krb5_scc_read(id, buf, 2);
+       if (retval)
+           return retval;
+       *i = (buf[0] << 8) + buf[1];
+       return 0;
+    }
+}    
 
 krb5_error_code
-krb5_scc_read_int(id, i)
+krb5_scc_read_octet(id, i)
    krb5_ccache id;
-   int *i;
+   krb5_octet *i;
 {
-     return krb5_scc_read(id, (krb5_pointer) i, sizeof(int));
-}
+    return krb5_scc_read(id, (krb5_pointer) i, 1);
+}    
 
-krb5_error_code
-krb5_scc_read_bool(id, b)
-   krb5_ccache id;
-   krb5_boolean *b;
-{
-     return krb5_scc_read(id, (krb5_pointer) b, sizeof(krb5_boolean));
-}
 
 krb5_error_code
 krb5_scc_read_times(id, t)
    krb5_ccache id;
    krb5_ticket_times *t;
 {
-     return krb5_scc_read(id, (krb5_pointer) t, sizeof(krb5_ticket_times));
-}
-
-krb5_error_code
-krb5_scc_read_flags (id, f)
-    krb5_ccache id;
-    krb5_flags *f;
-{
-    return krb5_scc_read (id, (krb5_pointer) f, sizeof (krb5_flags));
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
+    krb5_error_code retval;
+    krb5_int32 i;
+    
+    if ((data->version == KRB5_SCC_FVNO_1) ||
+       (data->version == KRB5_SCC_FVNO_2))
+       return krb5_scc_read(id, (krb5_pointer) t, sizeof(krb5_ticket_times));
+    else {
+       retval = krb5_scc_read_int32(id, &i);
+       CHECK(retval);
+       t->authtime = i;
+       
+       retval = krb5_scc_read_int32(id, &i);
+       CHECK(retval);
+       t->starttime = i;
+
+       retval = krb5_scc_read_int32(id, &i);
+       CHECK(retval);
+       t->endtime = i;
+
+       retval = krb5_scc_read_int32(id, &i);
+       CHECK(retval);
+       t->renew_till = i;
+    }
+    return 0;
+errout:
+    return retval;
 }
 
 krb5_error_code
@@ -360,29 +396,29 @@ krb5_scc_read_authdata(id, a)
      CHECK(kret);
 
      if (length == 0)
-         return KRB5_OK;
+        return KRB5_OK;
 
      /* Make *a able to hold length pointers to krb5_authdata structs
       * Add one extra for a null-terminated list
       */
      *a = (krb5_authdata **) calloc(length+1, sizeof(krb5_authdata *));
      if (*a == NULL)
-          return KRB5_CC_NOMEM;
+         return KRB5_CC_NOMEM;
 
      for (i=0; i < length; i++) {
-          (*a)[i] = (krb5_authdata *) malloc(sizeof(krb5_authdata));
-          if ((*a)[i] == NULL) {
-              krb5_free_authdata(*a);
-              return KRB5_CC_NOMEM;
-          }
-          kret = krb5_scc_read_authdatum(id, (*a)[i]);
-          CHECK(kret);
+         (*a)[i] = (krb5_authdata *) malloc(sizeof(krb5_authdata));
+         if ((*a)[i] == NULL) {
+             krb5_free_authdata(*a);
+             return KRB5_CC_NOMEM;
+         }       
+         kret = krb5_scc_read_authdatum(id, (*a)[i]);
+         CHECK(kret);
      }
 
      return KRB5_OK;
  errout:
      if (*a)
-         krb5_free_authdata(*a);
+        krb5_free_authdata(*a);
      return kret;
 }
 
@@ -392,33 +428,32 @@ krb5_scc_read_authdatum(id, a)
     krb5_authdata *a;
 {
     krb5_error_code kret;
+    krb5_int32 int32;
     int ret;
-
+    
+    a->magic = KV5M_AUTHDATA;
     a->contents = NULL;
 
     kret = krb5_scc_read_ui_2(id, &a->ad_type);
     CHECK(kret);
-    kret = krb5_scc_read_int(id, &a->length);
+    kret = krb5_scc_read_int32(id, &int32);
     CHECK(kret);
+    a->length = int32;
+    
+    if (a->length == 0 )
+           return KRB5_OK;
 
     a->contents = (krb5_octet *) malloc(a->length);
     if (a->contents == NULL)
-        return KRB5_CC_NOMEM;
-    errno = 0;
-    ret = fread ((char *)a->contents, 1,
-                (a->length)*sizeof(krb5_octet),
-                ((krb5_scc_data *) id->data)->file);
-    if ((ret == 0) && errno) {
-       krb5_xfree(a->contents);
-       return krb5_scc_interpret(errno);
-    }
-    if (ret != (a->length)*sizeof(krb5_octet)) {
-       krb5_xfree(a->contents);
-       return KRB5_CC_END;
-    }
-    return KRB5_OK;
-errout:
-    if (a->contents)
-       krb5_xfree(a->contents);
-    return kret;
+       return KRB5_CC_NOMEM;
+
+    kret = krb5_scc_read(id, a->contents, a->length);
+    CHECK(kret);
+    
+     return KRB5_OK;
+ errout:
+     if (a->contents)
+        krb5_xfree(a->contents);
+     return kret;
+    
 }
index af01ed40b5c541b18e8b259d9d2e03ac2c477435..f8bd0907eb68349d714f9ef94f4378342dc75665 100644 (file)
@@ -62,9 +62,9 @@ krb5_scc_store(id, creds)
      TCHECK(ret);
      ret = krb5_scc_store_times(id, &creds->times);
      TCHECK(ret);
-     ret = krb5_scc_store_bool(id, &creds->is_skey);
+     ret = krb5_scc_store_octet(id, creds->is_skey);
      TCHECK(ret);
-     ret = krb5_scc_store_flags(id, &creds->ticket_flags);
+     ret = krb5_scc_store_int32(id, creds->ticket_flags);
      TCHECK(ret);
      ret = krb5_scc_store_addrs(id, creds->addresses);
      TCHECK(ret);
index a45fdb940aa0682bc54929a62cb9626d325b38e9..346db57ec6bd45970801e95879807d453a233980 100644 (file)
@@ -91,11 +91,11 @@ krb5_scc_store_principal(id, princ)
         */
        tmp++;
     } else {
-        ret = krb5_scc_store_int32(id, &type);
-        CHECK(ret);
+       ret = krb5_scc_store_int32(id, type);
+       CHECK(ret);
     }
     
-    ret = krb5_scc_store_int32(id, &tmp);
+    ret = krb5_scc_store_int32(id, tmp);
     CHECK(ret);
 
     ret = krb5_scc_store_data(id, krb5_princ_realm(princ));
@@ -123,7 +123,7 @@ krb5_scc_store_addrs(id, addrs)
      while (*temp++)
          length += 1;
 
-     ret = krb5_scc_store_int32(id, &length);
+     ret = krb5_scc_store_int32(id, length);
      CHECK(ret);
      for (i=0; i < length; i++) {
          ret = krb5_scc_store_addr(id, addrs[i]);
@@ -138,22 +138,19 @@ krb5_scc_store_keyblock(id, keyblock)
    krb5_ccache id;
    krb5_keyblock *keyblock;
 {
+     krb5_scc_data *data = (krb5_scc_data *)id->data;
      krb5_error_code ret;
 
-     ret = krb5_scc_store_keytype(id, &keyblock->keytype);
+     ret = krb5_scc_store_ui_2(id, keyblock->keytype);
      CHECK(ret);
-     ret = krb5_scc_store_int(id, &keyblock->length);
+     if ((data->version != KRB5_SCC_FVNO_1) &&
+        (data->version != KRB5_SCC_FVNO_2)) {
+        ret = krb5_scc_store_ui_2(id, keyblock->etype);
+        CHECK(ret);
+     }
+     ret = krb5_scc_store_int32(id, keyblock->length);
      CHECK(ret);
-     errno = 0;
-     ret = fwrite((char *)keyblock->contents, 1,
-                 (keyblock->length)*sizeof(krb5_octet),
-                 ((krb5_scc_data *) id->data)->file);
-     if ((ret == 0) && errno)
-         return krb5_scc_interpret(errno);
-     if (ret != (keyblock->length)*sizeof(krb5_octet))
-        return KRB5_CC_END;
-     
-     return KRB5_OK;
+     return krb5_scc_write(id, (char *) keyblock->contents, keyblock->length);
 }
 
 krb5_error_code
@@ -163,19 +160,11 @@ krb5_scc_store_addr(id, addr)
 {
      krb5_error_code ret;
 
-     ret = krb5_scc_store_ui_2(id, &addr->addrtype);
+     ret = krb5_scc_store_ui_2(id, addr->addrtype);
      CHECK(ret);
-     ret = krb5_scc_store_int(id, &addr->length);
+     ret = krb5_scc_store_int32(id, addr->length);
      CHECK(ret);
-     errno = 0;
-     ret = fwrite((char *)addr->contents, 1,
-                 (addr->length)*sizeof(krb5_octet),
-                 ((krb5_scc_data *) id->data)->file);
-     if ((ret == 0) && errno)
-         return krb5_scc_interpret(errno);
-     if (ret != (addr->length)*sizeof(krb5_octet))
-        return KRB5_CC_END;
-     return KRB5_OK;
+     return krb5_scc_write(id, (char *) addr->contents, addr->length);
 }
 
 
@@ -186,56 +175,66 @@ krb5_scc_store_data(id, data)
 {
      krb5_error_code ret;
 
-     ret = krb5_scc_store_int32(id, &data->length);
+     ret = krb5_scc_store_int32(id, data->length);
      CHECK(ret);
-     errno = 0;
-     ret = fwrite(data->data, 1, data->length,
-                 ((krb5_scc_data *) id->data)->file);
-     if ((ret == 0) && errno)
-         return krb5_scc_interpret(errno);
-     else if (ret != data->length)
-        return KRB5_CC_END;
-     return KRB5_OK;
+     return krb5_scc_write(id, data->data, data->length);
 }
 
 krb5_error_code
 krb5_scc_store_int32(id, i)
    krb5_ccache id;
-   krb5_int32 *i;
+   krb5_int32 i;
 {
-     return krb5_scc_write(id, (char *) i, sizeof(krb5_int32));
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
+    unsigned char buf[4];
+
+    if ((data->version == KRB5_SCC_FVNO_1) ||
+       (data->version == KRB5_SCC_FVNO_2)) 
+       return krb5_scc_write(id, (char *) &i, sizeof(krb5_int32));
+    else {
+       buf[3] = i & 0xFF;
+       i >>= 8;
+       buf[2] = i & 0xFF;
+       i >>= 8;
+       buf[1] = i & 0xFF;
+       i >>= 8;
+       buf[0] = i & 0xFF;
+       
+       return krb5_scc_write(id, buf, 4);
+    }
 }
 
 krb5_error_code
 krb5_scc_store_ui_2(id, i)
-   krb5_ccache id;
-   krb5_ui_2 *i;
-{
-     return krb5_scc_write(id, (char *) i, sizeof(krb5_ui_2));
-}
-   
-krb5_error_code
-krb5_scc_store_keytype(id, k)
-   krb5_ccache id;
-   krb5_keytype *k;
-{
-     return krb5_scc_write(id, (char *) k, sizeof(krb5_keytype));
-}
-   
-krb5_error_code
-krb5_scc_store_int(id, i)
-   krb5_ccache id;
-   int *i;
+    krb5_ccache id;
+    krb5_int32 i;
 {
-     return krb5_scc_write(id, (char *) i, sizeof(int));
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
+    krb5_ui_2 ibuf;
+    unsigned char buf[2];
+    
+    if ((data->version == KRB5_SCC_FVNO_1) ||
+       (data->version == KRB5_SCC_FVNO_2)) {
+       ibuf = i;
+       return krb5_scc_write(id, (char *) &ibuf, sizeof(krb5_ui_2));
+    } else {
+       buf[1] = i & 0xFF;
+       i >>= 8;
+       buf[0] = i & 0xFF;
+       
+       return krb5_scc_write(id, buf, 2);
+    }
 }
    
 krb5_error_code
-krb5_scc_store_bool(id, b)
-   krb5_ccache id;
-   krb5_boolean *b;
+krb5_scc_store_octet(id, i)
+    krb5_ccache id;
+    krb5_int32 i;
 {
-     return krb5_scc_write(id, (char *) b, sizeof(krb5_boolean));
+    krb5_octet ibuf;
+
+    ibuf = i;
+    return krb5_scc_write(id, (char *) &ibuf, 1);
 }
    
 krb5_error_code
@@ -243,17 +242,25 @@ krb5_scc_store_times(id, t)
    krb5_ccache id;
    krb5_ticket_times *t;
 {
-     return krb5_scc_write(id, (char *) t, sizeof(krb5_ticket_times));
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
+    krb5_error_code retval;
+
+    if ((data->version == KRB5_SCC_FVNO_1) ||
+       (data->version == KRB5_SCC_FVNO_2))
+       return krb5_scc_write(id, (char *) t, sizeof(krb5_ticket_times));
+    else {
+       retval = krb5_scc_store_int32(id, t->authtime);
+       CHECK(retval);
+       retval = krb5_scc_store_int32(id, t->starttime);
+       CHECK(retval);
+       retval = krb5_scc_store_int32(id, t->endtime);
+       CHECK(retval);
+       retval = krb5_scc_store_int32(id, t->renew_till);
+       CHECK(retval);
+       return 0;
+    }
 }
    
-krb5_error_code
-krb5_scc_store_flags(id, f)
-   krb5_ccache id;
-   krb5_flags *f;
-{
-     return krb5_scc_write(id, (char *) f, sizeof(krb5_flags));
-}
-
 krb5_error_code
 krb5_scc_store_authdata(id, a)
     krb5_ccache id;
@@ -264,15 +271,15 @@ krb5_scc_store_authdata(id, a)
     krb5_int32 i, length=0;
 
     if (a != NULL) {
-        for (temp=a; *temp; temp++)
-            length++;
+       for (temp=a; *temp; temp++)
+           length++;
     }
 
-    ret = krb5_scc_store_int32(id, &length);
+    ret = krb5_scc_store_int32(id, length);
     CHECK(ret);
     for (i=0; i<length; i++) {
-        ret = krb5_scc_store_authdatum (id, a[i]);
-        CHECK(ret);
+       ret = krb5_scc_store_authdatum (id, a[i]);
+       CHECK(ret);
     }
     return KRB5_OK;
 }
@@ -283,9 +290,9 @@ krb5_scc_store_authdatum (id, a)
     krb5_authdata *a;
 {
     krb5_error_code ret;
-    ret = krb5_scc_store_ui_2(id, &a->ad_type);
+    ret = krb5_scc_store_ui_2(id, a->ad_type);
     CHECK(ret);
-    ret = krb5_scc_store_int32(id, &a->length);
+    ret = krb5_scc_store_int32(id, a->length);
     CHECK(ret);
     return krb5_scc_write(id, (krb5_pointer) a->contents, a->length);
 }