Changes to implement FCC format version #3, which is architecture
authorTheodore Tso <tytso@mit.edu>
Thu, 17 Nov 1994 07:05:42 +0000 (07:05 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 17 Nov 1994 07:05:42 +0000 (07:05 +0000)
independent, and includes the key encryption type information.

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

src/lib/krb5/ccache/file/ChangeLog
src/lib/krb5/ccache/file/fcc-proto.h
src/lib/krb5/ccache/file/fcc.h
src/lib/krb5/ccache/file/fcc_gennew.c
src/lib/krb5/ccache/file/fcc_maybe.c
src/lib/krb5/ccache/file/fcc_nseq.c
src/lib/krb5/ccache/file/fcc_read.c
src/lib/krb5/ccache/file/fcc_store.c
src/lib/krb5/ccache/file/fcc_write.c

index 6b2c80e449b7d3f72d0c2b8e77808e062afb1921..e66909f9bf334b59a614894031ffbf0928dac17c 100644 (file)
@@ -1,3 +1,19 @@
+Wed Nov 16 23:31:49 1994  Theodore Y. Ts'o  (tytso@dcl)
+
+        * fcc-proto.h, fcc.h, fcc_maybe.c (krb5_fcc_open_file), fcc_nseq.c
+       (krb5_fcc_next_cred), fcc_store.c (krb5_fcc_store), fcc_read.c,
+       fcc_write.c:  Changes to implement FCC format version #3, which
+               is architecture independent, and includes the key
+               encryption type information.
+
+       * fcc_gennew.c (krb5_fcc_generate_new): Generate new ccaches using
+               whatever version is marked as the default.
+
+       * fcc_read.c (krb5_fcc_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.
+
 Mon Oct 31 17:02:04 1994  Theodore Y. Ts'o  (tytso@dcl)
 
        * fcc_maybe.c: Back out POSIX_FILE_LOCKS change.  (Should be
index b6a5e0041db4b36e61b05118c2ff894fcfdff015..56d4a1d3d9b97b9398fad9e7b64b2ca0ad6b7aac 100644 (file)
@@ -61,11 +61,8 @@ krb5_error_code krb5_fcc_read_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock
 krb5_error_code krb5_fcc_read_data PROTOTYPE((krb5_ccache id , krb5_data *data ));
 krb5_error_code krb5_fcc_read_int32 PROTOTYPE((krb5_ccache id , krb5_int32 *i ));
 krb5_error_code krb5_fcc_read_ui_2 PROTOTYPE((krb5_ccache id , krb5_ui_2 *i ));
-krb5_error_code krb5_fcc_read_keytype PROTOTYPE((krb5_ccache id , krb5_keytype *k ));
-krb5_error_code krb5_fcc_read_int PROTOTYPE((krb5_ccache id , int *i ));
-krb5_error_code krb5_fcc_read_bool PROTOTYPE((krb5_ccache id , krb5_boolean *b ));
+krb5_error_code krb5_fcc_read_octet PROTOTYPE((krb5_ccache id , krb5_octet *i ));
 krb5_error_code krb5_fcc_read_times PROTOTYPE((krb5_ccache id , krb5_ticket_times *t ));
-krb5_error_code krb5_fcc_read_flags PROTOTYPE((krb5_ccache id , krb5_flags *f ));
 krb5_error_code krb5_fcc_read_addrs PROTOTYPE((krb5_ccache, krb5_address ***));
 krb5_error_code krb5_fcc_read_addr PROTOTYPE((krb5_ccache, krb5_address *));
 krb5_error_code krb5_fcc_read_authdata PROTOTYPE((krb5_ccache , krb5_authdata ***));
@@ -97,13 +94,10 @@ krb5_error_code krb5_fcc_write PROTOTYPE((krb5_ccache id , krb5_pointer buf , in
 krb5_error_code krb5_fcc_store_principal PROTOTYPE((krb5_ccache id , krb5_principal princ ));
 krb5_error_code krb5_fcc_store_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock *keyblock ));
 krb5_error_code krb5_fcc_store_data PROTOTYPE((krb5_ccache id , krb5_data *data ));
-krb5_error_code krb5_fcc_store_int32 PROTOTYPE((krb5_ccache id , krb5_int32 *i ));
-krb5_error_code krb5_fcc_store_ui_2 PROTOTYPE((krb5_ccache id , krb5_ui_2 *i ));
-krb5_error_code krb5_fcc_store_keytype PROTOTYPE((krb5_ccache id , krb5_keytype *k ));
-krb5_error_code krb5_fcc_store_int PROTOTYPE((krb5_ccache id , int *i ));
-krb5_error_code krb5_fcc_store_bool PROTOTYPE((krb5_ccache id , krb5_boolean *b ));
+krb5_error_code krb5_fcc_store_int32 PROTOTYPE((krb5_ccache id , krb5_int32 i ));
+krb5_error_code krb5_fcc_store_ui_2 PROTOTYPE((krb5_ccache id , krb5_int32 i ));
+krb5_error_code krb5_fcc_store_octet PROTOTYPE((krb5_ccache id , krb5_int32 i ));
 krb5_error_code krb5_fcc_store_times PROTOTYPE((krb5_ccache id , krb5_ticket_times *t ));
-krb5_error_code krb5_fcc_store_flags PROTOTYPE((krb5_ccache id , krb5_flags *f ));
 krb5_error_code krb5_fcc_store_addrs PROTOTYPE((krb5_ccache , krb5_address ** ));
 krb5_error_code krb5_fcc_store_addr PROTOTYPE((krb5_ccache , krb5_address * ));
 krb5_error_code krb5_fcc_store_authdata PROTOTYPE((krb5_ccache , krb5_authdata **));
index f7f461cd3a47040885eb4e81dc18bb74e1e15d1a..18d560a329011cf40931d879f4dc8512c2b4bef7 100644 (file)
 
 /*
  * FCC version 2 contains type information for principals.  FCC
- * version 1 does not.  The code will accept either, and depending on
- * what KRB5_FCC_DEFAULT_FVNO is set to, it will create version 1 or
- * version 2 FCC caches.
+ * version 1 does not.
+ *  
+ * FCC version 3 contains keyblock encryption type information, and is
+ * architecture independent.  Previous versions are not.
  *
- * KRB5_FCC_DEFAULT_FVNO should be set to version 2, unless there is
+ * The code will accept version 1, 2, and 3 ccaches, and depending 
+ * what KRB5_FCC_DEFAULT_FVNO is set to, it will create version 1, 2,
+ * or 3 FCC caches.
+ * 
+ * KRB5_FCC_DEFAULT_FVNO should be set to version 3, unless there is
  * some overriding compatibility reasons not to do so.
  */
 
-#define KRB5_FCC_FVNO_1 0x0501         /* krb v5, fcc v1 */
-#define KRB5_FCC_FVNO   0x0502         /* krb5 v5, fcc v2 */
+#define KRB5_FCC_FVNO_1 0x0501         /* krb5 v5, fcc v1 */
+#define KRB5_FCC_FVNO_2 0x0502         /* krb5 v5, fcc v2 */
+#define KRB5_FCC_FVNO_3 0x0503         /* krb5 v5, fcc v3 */
 
-#define KRB5_FCC_DEFAULT_FVNO KRB5_FCC_FVNO
+#define KRB5_FCC_DEFAULT_FVNO KRB5_FCC_FVNO_3
 
 #define        FCC_OPEN_AND_ERASE      1
 #define        FCC_OPEN_RDWR           2
index 71c85028b3ceb6fadb06b293552c36fc9de28595..36d00aab789c4916cbafbaf289658cf76b8e5a23 100644 (file)
@@ -103,7 +103,7 @@ krb5_fcc_generate_new (id)
          retcode = krb5_fcc_interpret(errno);
           goto err_out;
      } else {
-         krb5_int16 fcc_fvno = htons(KRB5_FCC_FVNO);
+         krb5_int16 fcc_fvno = htons(KRB5_FCC_DEFAULT_FVNO);
          int errsave, cnt;
 
          /* Ignore user's umask, set mode = 0600 */
index 44086f4bb49b825dfcd5505a911179a7beb7e59a..5fcfc3aac450e1cd318da0b7e40e767e2643b077 100644 (file)
@@ -198,7 +198,8 @@ krb5_fcc_open_file (id, mode)
             (void) close(fd);
             return KRB5_CCACHE_BADVNO;
         }
-        if ((fcc_fvno != htons(KRB5_FCC_FVNO)) &&
+        if ((fcc_fvno != htons(KRB5_FCC_FVNO_3)) &&
+            (fcc_fvno != htons(KRB5_FCC_FVNO_2)) &&
             (fcc_fvno != htons(KRB5_FCC_FVNO_1))) {
             (void) fcc_lock_file(data, fd, UNLOCK_IT);
             (void) close(fd);
index febd382a029e0d709f4b2933e5b9f2e8e2c2526a..08746a6b5ce7f17f81a886d41b3cc96e92f31ecf 100644 (file)
@@ -58,6 +58,8 @@ krb5_fcc_next_cred(id, cursor, creds)
      int ret;
      krb5_error_code kret;
      krb5_fcc_cursor *fcursor;
+     krb5_int32 int32;
+     krb5_octet octet;
 
      memset((char *)creds, 0, sizeof(*creds));
 
@@ -80,10 +82,12 @@ krb5_fcc_next_cred(id, cursor, creds)
      TCHECK(kret);
      kret = krb5_fcc_read_times(id, &creds->times);
      TCHECK(kret);
-     kret = krb5_fcc_read_bool(id, &creds->is_skey);
+     kret = krb5_fcc_read_octet(id, &octet);
      TCHECK(kret);
-     kret = krb5_fcc_read_flags(id, &creds->ticket_flags);
+     creds->is_skey = octet;
+     kret = krb5_fcc_read_int32(id, &int32);
      TCHECK(kret);
+     creds->ticket_flags = int32;
      kret = krb5_fcc_read_addrs(id, &creds->addresses);
      TCHECK(kret);
      kret = krb5_fcc_read_authdata(id, &creds->authdata);
index f1b8dcf6605c6b62c839ab5e2a78d3f8e0d3f5be..298442c4a3489fbbfbef47b77321d9fe99a13a08 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * lib/krb5/ccache/file/fcc_read.c
  *
- * Copyright 1990 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991,1992,1993,1994 by the Massachusetts Institute
+ * of Technology. 
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -116,6 +117,7 @@ krb5_fcc_read_principal(id, princ)
            }
     } else
            tmpprinc->data = 0;
+    tmpprinc->magic = KV5M_PRINCIPAL;
     tmpprinc->length = length;
     tmpprinc->type = type;
 
@@ -183,15 +185,29 @@ krb5_fcc_read_keyblock(id, keyblock)
    krb5_ccache id;
    krb5_keyblock *keyblock;
 {
+     krb5_fcc_data *data = (krb5_fcc_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_fcc_read_keytype(id, &keyblock->keytype);
+     kret = krb5_fcc_read_ui_2(id, &ui2);
+     keyblock->keytype = ui2;
      CHECK(kret);
-     kret = krb5_fcc_read_int(id, &keyblock->length);
+     if ((data->version == KRB5_FCC_FVNO_1) ||
+        (data->version == KRB5_FCC_FVNO_2))
+            keyblock->etype = ETYPE_UNKNOWN;
+     else {
+            kret = krb5_fcc_read_ui_2(id, &ui2);
+            keyblock->etype = ui2;
+            CHECK(kret);
+     }
+
+     kret = krb5_fcc_read_int32(id, &int32);
      CHECK(kret);
+     keyblock->length = int32;
      if ( keyblock->length == 0 )
             return KRB5_OK;
      keyblock->contents = (unsigned char *) malloc(keyblock->length*
@@ -199,17 +215,9 @@ krb5_fcc_read_keyblock(id, keyblock)
      if (keyblock->contents == NULL)
          return KRB5_CC_NOMEM;
      
-     ret = read(((krb5_fcc_data *) id->data)->fd, (char *)keyblock->contents,
-               (keyblock->length)*sizeof(krb5_octet));
-
-     if (ret < 0) {
-        krb5_xfree(keyblock->contents);
-        return krb5_fcc_interpret(errno);
-     }
-     if (ret != (keyblock->length)*sizeof(krb5_octet)) {
-        krb5_xfree(keyblock->contents);
-        return KRB5_CC_END;
-     }
+     kret = krb5_fcc_read(id, keyblock->contents, keyblock->length);
+     if (kret)
+        goto errout;
 
      return KRB5_OK;
  errout:
@@ -224,8 +232,8 @@ krb5_fcc_read_data(id, data)
    krb5_data *data;
 {
      krb5_error_code kret;
-     int ret;
 
+     data->magic = KV5M_DATA;
      data->data = 0;
 
      kret = krb5_fcc_read_int32(id, &data->length);
@@ -240,16 +248,9 @@ krb5_fcc_read_data(id, data)
      if (data->data == NULL)
          return KRB5_CC_NOMEM;
 
-     ret = read(((krb5_fcc_data *) id->data)->fd, (char *)data->data,
-               data->length);
-     if (ret == -1) {
-        krb5_xfree(data->data);
-        return krb5_fcc_interpret(errno);
-     }
-     if (ret != data->length) {
-        krb5_xfree(data->data);
-        return KRB5_CC_END;
-     }
+     kret = krb5_fcc_read(id, data->data, data->length);
+     CHECK(kret);
+     
      data->data[data->length] = 0; /* Null terminate, just in case.... */
      return KRB5_OK;
  errout:
@@ -264,15 +265,19 @@ krb5_fcc_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_fcc_read_ui_2(id, &addr->addrtype);
+     kret = krb5_fcc_read_ui_2(id, &ui2);
      CHECK(kret);
-
-     kret = krb5_fcc_read_int(id, &addr->length);
+     addr->addrtype = ui2;
+     
+     kret = krb5_fcc_read_int32(id, &int32);
      CHECK(kret);
+     addr->length = int32;
 
      if (addr->length == 0)
             return KRB5_OK;
@@ -281,16 +286,9 @@ krb5_fcc_read_addr(id, addr)
      if (addr->contents == NULL)
          return KRB5_CC_NOMEM;
 
-     ret = read(((krb5_fcc_data *) id->data)->fd, (char *)addr->contents,
-               (addr->length)*sizeof(krb5_octet));
-     if (ret == -1) {
-         krb5_xfree(addr->contents);
-         return krb5_fcc_interpret(errno);
-     }
-     if (ret != (addr->length)*sizeof(krb5_octet)) {
-         krb5_xfree(addr->contents);
-         return KRB5_CC_END;
-     }
+     kret = krb5_fcc_read(id, addr->contents, addr->length);
+     CHECK(kret);
+
      return KRB5_OK;
  errout:
      if (addr->contents)
@@ -303,7 +301,20 @@ krb5_fcc_read_int32(id, i)
    krb5_ccache id;
    krb5_int32 *i;
 {
-     return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int32));
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+    krb5_error_code retval;
+    unsigned char buf[4];
+
+    if ((data->version == KRB5_FCC_FVNO_1) ||
+       (data->version == KRB5_FCC_FVNO_2)) 
+       return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int32));
+    else {
+       retval = krb5_fcc_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
@@ -311,47 +322,63 @@ krb5_fcc_read_ui_2(id, i)
    krb5_ccache id;
    krb5_ui_2 *i;
 {
-     return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_ui_2));
-}
-
-krb5_error_code
-krb5_fcc_read_keytype(id, k)
-   krb5_ccache id;
-   krb5_keytype *k;
-{
-     return krb5_fcc_read(id, (krb5_pointer) k, sizeof(krb5_keytype));
-}
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+    krb5_error_code retval;
+    unsigned char buf[2];
+    
+    if ((data->version == KRB5_FCC_FVNO_1) ||
+       (data->version == KRB5_FCC_FVNO_2))
+       return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_ui_2));
+    else {
+       retval = krb5_fcc_read(id, buf, 2);
+       if (retval)
+           return retval;
+       *i = (buf[0] << 8) + buf[1];
+       return 0;
+    }
+}    
 
 krb5_error_code
-krb5_fcc_read_int(id, i)
+krb5_fcc_read_octet(id, i)
    krb5_ccache id;
-   int *i;
+   krb5_octet *i;
 {
-     return krb5_fcc_read(id, (krb5_pointer) i, sizeof(int));
-}
+    return krb5_fcc_read(id, (krb5_pointer) i, 1);
+}    
 
-krb5_error_code
-krb5_fcc_read_bool(id, b)
-   krb5_ccache id;
-   krb5_boolean *b;
-{
-     return krb5_fcc_read(id, (krb5_pointer) b, sizeof(krb5_boolean));
-}
 
 krb5_error_code
 krb5_fcc_read_times(id, t)
    krb5_ccache id;
    krb5_ticket_times *t;
 {
-     return krb5_fcc_read(id, (krb5_pointer) t, sizeof(krb5_ticket_times));
-}
-
-krb5_error_code
-krb5_fcc_read_flags(id, f)
-   krb5_ccache id;
-   krb5_flags *f;
-{
-     return krb5_fcc_read(id, (krb5_pointer) f, sizeof(krb5_flags));
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+    krb5_error_code retval;
+    krb5_int32 i;
+    
+    if ((data->version == KRB5_FCC_FVNO_1) ||
+       (data->version == KRB5_FCC_FVNO_2))
+       return krb5_fcc_read(id, (krb5_pointer) t, sizeof(krb5_ticket_times));
+    else {
+       retval = krb5_fcc_read_int32(id, &i);
+       CHECK(retval);
+       t->authtime = i;
+       
+       retval = krb5_fcc_read_int32(id, &i);
+       CHECK(retval);
+       t->starttime = i;
+
+       retval = krb5_fcc_read_int32(id, &i);
+       CHECK(retval);
+       t->endtime = i;
+
+       retval = krb5_fcc_read_int32(id, &i);
+       CHECK(retval);
+       t->renew_till = i;
+    }
+    return 0;
+errout:
+    return retval;
 }
 
 krb5_error_code
@@ -402,14 +429,17 @@ krb5_fcc_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_fcc_read_ui_2(id, &a->ad_type);
     CHECK(kret);
-    kret = krb5_fcc_read_int(id, &a->length);
+    kret = krb5_fcc_read_int32(id, &int32);
     CHECK(kret);
+    a->length = int32;
     
     if (a->length == 0 )
            return KRB5_OK;
@@ -417,16 +447,10 @@ krb5_fcc_read_authdatum(id, a)
     a->contents = (krb5_octet *) malloc(a->length);
     if (a->contents == NULL)
        return KRB5_CC_NOMEM;
-    ret = read(((krb5_fcc_data *) id->data)->fd, (char *)a->contents,
-               (a->length)*sizeof(krb5_octet));
-     if (ret == -1) {
-         krb5_xfree(a->contents);
-         return krb5_fcc_interpret(errno);
-     }
-     if (ret != (a->length)*sizeof(krb5_octet)) {
-         krb5_xfree(a->contents);
-         return KRB5_CC_END;
-     }
+
+    kret = krb5_fcc_read(id, a->contents, a->length);
+    CHECK(kret);
+    
      return KRB5_OK;
  errout:
      if (a->contents)
index d3bf326524a05f3602ac3eff45b6e1d51525dd10..1bdbb33dab96252bdb7caf553ee7f19c7d29371e 100644 (file)
@@ -48,6 +48,7 @@ krb5_fcc_store(id, creds)
 {
 #define TCHECK(ret) if (ret != KRB5_OK) goto lose;
      krb5_error_code ret;
+     krb5_octet octet;
 
      MAYBE_OPEN(id, FCC_OPEN_RDWR);
 
@@ -66,9 +67,10 @@ krb5_fcc_store(id, creds)
      TCHECK(ret);
      ret = krb5_fcc_store_times(id, &creds->times);
      TCHECK(ret);
-     ret = krb5_fcc_store_bool(id, &creds->is_skey);
+     octet = creds->is_skey;
+     ret = krb5_fcc_store_octet(id, octet);
      TCHECK(ret);
-     ret = krb5_fcc_store_flags(id, &creds->ticket_flags);
+     ret = krb5_fcc_store_int32(id, creds->ticket_flags);
      TCHECK(ret);
      ret = krb5_fcc_store_addrs(id, creds->addresses);
      TCHECK(ret);
index 4ef473054c24fb03f7640962843c267ba5c8cb9b..cbb092f6d430c56568202be48b4e1b70b0c924fe 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * lib/krb5/ccache/file/fcc_write.c
  *
- * Copyright 1990,1991,1992 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991,1992,1993,1994 by the Massachusetts Institute
+ * of Technology. 
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -51,6 +52,8 @@ krb5_fcc_write(id, buf, len)
      ret = write(((krb5_fcc_data *)id->data)->fd, (char *) buf, len);
      if (ret < 0)
          return krb5_fcc_interpret(errno);
+     if (ret != len)
+        return KRB5_CC_WRITE;
      return KRB5_OK;
 }
 
@@ -88,11 +91,11 @@ krb5_fcc_store_principal(id, princ)
         */
        tmp++;
     } else {
-       ret = krb5_fcc_store_int32(id, &type);
+       ret = krb5_fcc_store_int32(id, type);
        CHECK(ret);
     }
     
-    ret = krb5_fcc_store_int32(id, &tmp);
+    ret = krb5_fcc_store_int32(id, tmp);
     CHECK(ret);
 
     ret = krb5_fcc_store_data(id, krb5_princ_realm(princ));
@@ -120,7 +123,7 @@ krb5_fcc_store_addrs(id, addrs)
      while (*temp++)
          length += 1;
 
-     ret = krb5_fcc_store_int32(id, &length);
+     ret = krb5_fcc_store_int32(id, length);
      CHECK(ret);
      for (i=0; i < length; i++) {
          ret = krb5_fcc_store_addr(id, addrs[i]);
@@ -135,20 +138,19 @@ krb5_fcc_store_keyblock(id, keyblock)
    krb5_ccache id;
    krb5_keyblock *keyblock;
 {
+     krb5_fcc_data *data = (krb5_fcc_data *)id->data;
      krb5_error_code ret;
 
-     ret = krb5_fcc_store_keytype(id, &keyblock->keytype);
+     ret = krb5_fcc_store_ui_2(id, keyblock->keytype);
      CHECK(ret);
-     ret = krb5_fcc_store_int(id, &keyblock->length);
+     if ((data->version != KRB5_FCC_FVNO_1) &&
+        (data->version != KRB5_FCC_FVNO_2)) {
+        ret = krb5_fcc_store_ui_2(id, keyblock->etype);
+        CHECK(ret);
+     }
+     ret = krb5_fcc_store_int32(id, keyblock->length);
      CHECK(ret);
-     ret = write(((krb5_fcc_data *) id->data)->fd, (char *)keyblock->contents,
-                (keyblock->length)*sizeof(krb5_octet));
-     if (ret < 0)
-         return krb5_fcc_interpret(errno);
-     if (ret != (keyblock->length)*sizeof(krb5_octet))
-        return KRB5_CC_END;
-     
-     return KRB5_OK;
+     return krb5_fcc_write(id, (char *) keyblock->contents, keyblock->length);
 }
 
 krb5_error_code
@@ -158,17 +160,11 @@ krb5_fcc_store_addr(id, addr)
 {
      krb5_error_code ret;
 
-     ret = krb5_fcc_store_ui_2(id, &addr->addrtype);
+     ret = krb5_fcc_store_ui_2(id, addr->addrtype);
      CHECK(ret);
-     ret = krb5_fcc_store_int(id, &addr->length);
+     ret = krb5_fcc_store_int32(id, addr->length);
      CHECK(ret);
-     ret = write(((krb5_fcc_data *) id->data)->fd, (char *)addr->contents,
-                (addr->length)*sizeof(krb5_octet));
-     if (ret < 0)
-         return krb5_fcc_interpret(errno);
-     if (ret != (addr->length)*sizeof(krb5_octet))
-        return KRB5_CC_END;
-     return KRB5_OK;
+     return krb5_fcc_write(id, (char *) addr->contents, addr->length);
 }
 
 
@@ -179,53 +175,66 @@ krb5_fcc_store_data(id, data)
 {
      krb5_error_code ret;
 
-     ret = krb5_fcc_store_int32(id, &data->length);
+     ret = krb5_fcc_store_int32(id, data->length);
      CHECK(ret);
-     ret = write(((krb5_fcc_data *) id->data)->fd, data->data, data->length);
-     if (ret == -1)
-         return krb5_fcc_interpret(errno);
-
-     return KRB5_OK;
+     return krb5_fcc_write(id, data->data, data->length);
 }
 
 krb5_error_code
 krb5_fcc_store_int32(id, i)
    krb5_ccache id;
-   krb5_int32 *i;
+   krb5_int32 i;
 {
-     return krb5_fcc_write(id, (char *) i, sizeof(krb5_int32));
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+    unsigned char buf[4];
+
+    if ((data->version == KRB5_FCC_FVNO_1) ||
+       (data->version == KRB5_FCC_FVNO_2)) 
+       return krb5_fcc_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_fcc_write(id, buf, 4);
+    }
 }
 
 krb5_error_code
 krb5_fcc_store_ui_2(id, i)
-   krb5_ccache id;
-   krb5_ui_2 *i;
-{
-     return krb5_fcc_write(id, (char *) i, sizeof(krb5_ui_2));
-}
-   
-krb5_error_code
-krb5_fcc_store_keytype(id, k)
-   krb5_ccache id;
-   krb5_keytype *k;
-{
-     return krb5_fcc_write(id, (char *) k, sizeof(krb5_keytype));
-}
-   
-krb5_error_code
-krb5_fcc_store_int(id, i)
-   krb5_ccache id;
-   int *i;
+    krb5_ccache id;
+    krb5_int32 i;
 {
-     return krb5_fcc_write(id, (char *) i, sizeof(int));
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+    krb5_ui_2 ibuf;
+    unsigned char buf[2];
+    
+    if ((data->version == KRB5_FCC_FVNO_1) ||
+       (data->version == KRB5_FCC_FVNO_2)) {
+       ibuf = i;
+       return krb5_fcc_write(id, (char *) &ibuf, sizeof(krb5_ui_2));
+    } else {
+       buf[1] = i & 0xFF;
+       i >>= 8;
+       buf[0] = i & 0xFF;
+       
+       return krb5_fcc_write(id, buf, 2);
+    }
 }
    
 krb5_error_code
-krb5_fcc_store_bool(id, b)
-   krb5_ccache id;
-   krb5_boolean *b;
+krb5_fcc_store_octet(id, i)
+    krb5_ccache id;
+    krb5_int32 i;
 {
-     return krb5_fcc_write(id, (char *) b, sizeof(krb5_boolean));
+    krb5_octet ibuf;
+
+    ibuf = i;
+    return krb5_fcc_write(id, (char *) &ibuf, 1);
 }
    
 krb5_error_code
@@ -233,17 +242,25 @@ krb5_fcc_store_times(id, t)
    krb5_ccache id;
    krb5_ticket_times *t;
 {
-     return krb5_fcc_write(id, (char *) t, sizeof(krb5_ticket_times));
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+    krb5_error_code retval;
+
+    if ((data->version == KRB5_FCC_FVNO_1) ||
+       (data->version == KRB5_FCC_FVNO_2))
+       return krb5_fcc_write(id, (char *) t, sizeof(krb5_ticket_times));
+    else {
+       retval = krb5_fcc_store_int32(id, t->authtime);
+       CHECK(retval);
+       retval = krb5_fcc_store_int32(id, t->starttime);
+       CHECK(retval);
+       retval = krb5_fcc_store_int32(id, t->endtime);
+       CHECK(retval);
+       retval = krb5_fcc_store_int32(id, t->renew_till);
+       CHECK(retval);
+       return 0;
+    }
 }
    
-krb5_error_code
-krb5_fcc_store_flags(id, f)
-   krb5_ccache id;
-   krb5_flags *f;
-{
-     return krb5_fcc_write(id, (char *) f, sizeof(krb5_flags));
-}
-
 krb5_error_code
 krb5_fcc_store_authdata(id, a)
     krb5_ccache id;
@@ -258,7 +275,7 @@ krb5_fcc_store_authdata(id, a)
            length++;
     }
 
-    ret = krb5_fcc_store_int32(id, &length);
+    ret = krb5_fcc_store_int32(id, length);
     CHECK(ret);
     for (i=0; i<length; i++) {
        ret = krb5_fcc_store_authdatum (id, a[i]);
@@ -273,9 +290,9 @@ krb5_fcc_store_authdatum (id, a)
     krb5_authdata *a;
 {
     krb5_error_code ret;
-    ret = krb5_fcc_store_ui_2(id, &a->ad_type);
+    ret = krb5_fcc_store_ui_2(id, a->ad_type);
     CHECK(ret);
-    ret = krb5_fcc_store_int32(id, &a->length);
+    ret = krb5_fcc_store_int32(id, a->length);
     CHECK(ret);
     return krb5_fcc_write(id, (krb5_pointer) a->contents, a->length);
 }