Changes to support new version of ccache file format. (This one handles principal
authorTheodore Tso <tytso@mit.edu>
Tue, 18 Aug 1992 23:26:16 +0000 (23:26 +0000)
committerTheodore Tso <tytso@mit.edu>
Tue, 18 Aug 1992 23:26:16 +0000 (23:26 +0000)
types.)

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

src/lib/krb5/ccache/file/fcc.h
src/lib/krb5/ccache/file/fcc_maybe.c
src/lib/krb5/ccache/file/fcc_read.c
src/lib/krb5/ccache/file/fcc_write.c
src/lib/krb5/ccache/stdio/scc.h
src/lib/krb5/ccache/stdio/scc_maybe.c
src/lib/krb5/ccache/stdio/scc_read.c
src/lib/krb5/ccache/stdio/scc_write.c

index b3d6e1cdcf4c9d939533559981ddc91af3b629b9..011eb6b48c4607a900e84021dee6f28933459a2c 100644 (file)
 
 #define KRB5_FCC_MAXLEN 100
 
-#define KRB5_FCC_FVNO 0x0501           /* krb v5, fcc v1 */
+/*
+ * 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.
+ *
+ * KRB5_FCC_DEFAULT_FVNO should be set to version 2, 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_DEFAULT_FVNO KRB5_FCC_FVNO
+
 #define        FCC_OPEN_AND_ERASE      1
 #define        FCC_OPEN_RDWR           2
 #define        FCC_OPEN_RDONLY         3
@@ -58,6 +72,7 @@ typedef struct _krb5_fcc_data {
      int fd;
      krb5_flags flags;
      int mode;                         /* needed for locking code */
+     int version;                      /* version number of the file */
 } krb5_fcc_data;
 
 /* An off_t can be arbitrarily complex */
index f729b8e1976ad70ecee47bb827e08dee9c74211d..93e51f65d70dc802fe4d088dcd060b30b847d716 100644 (file)
@@ -33,6 +33,8 @@ static char rcsid_fcc_maybe_c[] =
 #include "fcc.h"
 #include <krb5/osconf.h>
 
+int krb5_fcc_default_format = KRB5_FCC_DEFAULT_FVNO;
+
 #ifdef KRB5_USE_INET
 #include <netinet/in.h>
 #else
@@ -139,7 +141,7 @@ krb5_fcc_open_file (id, mode)
     int mode;
 {
      krb5_fcc_data *data = (krb5_fcc_data *)id->data;
-     krb5_int16 fcc_fvno = htons(KRB5_FCC_FVNO);
+     krb5_int16 fcc_fvno;
      int fd;
      int open_flag;
      krb5_error_code retval;
@@ -177,6 +179,8 @@ krb5_fcc_open_file (id, mode)
         /* write the version number */
         int errsave, cnt;
 
+        fcc_fvno = htons(krb5_fcc_default_format);
+        data->version = krb5_fcc_default_format;
         if ((cnt = write(fd, (char *)&fcc_fvno, sizeof(fcc_fvno))) !=
             sizeof(fcc_fvno)) {
             errsave = errno;
@@ -192,11 +196,13 @@ 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)) &&
+            (fcc_fvno != htons(KRB5_FCC_FVNO_1))) {
             (void) fcc_lock_file(data, fd, UNLOCK_IT);
             (void) close(fd);
             return KRB5_CCACHE_BADVNO;
         }
+        data->version = ntohs(fcc_fvno);
      }
      data->fd = fd;
      return 0;
index d1b3baede8d8e16ba168fc0f221d687abea74a6e..e59e8c82ab161e84c04b9260922d9df5916b3a95 100644 (file)
@@ -82,11 +82,21 @@ krb5_fcc_read_principal(id, princ)
    krb5_ccache id;
    krb5_principal *princ;
 {
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
     krb5_error_code kret;
     register krb5_principal tmpprinc;
-    krb5_int32 length;
+    krb5_int32 length, type;
     int i;
 
+    if (data->version == KRB5_FCC_FVNO_1) {
+       type = KRB5_NT_UNKNOWN;
+    } else {
+        /* Read principal type */
+        kret = krb5_fcc_read_int32(id, &type);
+        if (kret != KRB5_OK)
+           return kret;
+    }
+
     /* Read the number of components */
     kret = krb5_fcc_read_int32(id, &length);
     if (kret != KRB5_OK)
@@ -101,6 +111,7 @@ krb5_fcc_read_principal(id, princ)
        return KRB5_CC_NOMEM;
     }
     tmpprinc->length = length;
+    tmpprinc->type = type;
 
     kret = krb5_fcc_read_data(id, krb5_princ_realm(tmpprinc));
 
index 766463ddd371b5038565521982d50a59a9252829..2d010cdb561e060d90196a1a6b145146b50f658e 100644 (file)
@@ -2,7 +2,7 @@
  * $Source$
  * $Author$
  *
- * Copyright 1990,1991 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991,1992 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America is assumed
@@ -73,18 +73,23 @@ krb5_fcc_write(id, buf, len)
  * system errors
  */
 
-/* XXX TODO: write principal type to file XXX */
-
 krb5_error_code
 krb5_fcc_store_principal(id, princ)
    krb5_ccache id;
    krb5_principal princ;
 {
+    krb5_fcc_data *data = (krb5_fcc_data *)id->data;
     krb5_error_code ret;
-    krb5_int32 i, length;
+    krb5_int32 i, length, type;
 
+    type = krb5_princ_type(princ);
     length = krb5_princ_size(princ);
 
+    if (data->version != KRB5_FCC_FVNO_1) {
+           ret = krb5_fcc_store_int32(id, &type);
+           CHECK(ret);
+    }
+    
     ret = krb5_fcc_store_int32(id, &length);
     CHECK(ret);
 
index cdc6207804b60bbf03c69c19fc150c79910d863f..78ca896cea278d3861d16cceec82af92fb3c99be 100644 (file)
 
 #define KRB5_SCC_MAXLEN 100
 
-#define KRB5_SCC_FVNO 0x0501           /* krb v5, scc v1 */
+/*
+ * SCC version 2 contains type information for principals.  SCC
+ * version 1 does not.  The code will accept either, and depending on
+ * what KRB5_SCC_DEFAULT_FVNO is set to, it will create version 1 or
+ * version 2 SCC caches.
+ *
+ * KRB5_SCC_DEFAULT_FVNO should be set to version 2, unless there is
+ * some overriding compatibility reasons not to do so.
+ */
+
+#define KRB5_SCC_FVNO_1 0x0501         /* krb v5, scc v1 */
+#define KRB5_SCC_FVNO   0x0502         /* krb5 v5, scc v2 */
+
+#define KRB5_SCC_DEFAULT_FVNO KRB5_SCC_FVNO
 
 #define        SCC_OPEN_AND_ERASE      1
 #define        SCC_OPEN_RDWR           2
@@ -59,6 +72,7 @@ typedef struct _krb5_scc_data {
      FILE *file;
      krb5_flags flags;
      char stdio_buffer[BUFSIZ];
+     int version;
 } krb5_scc_data;
 
 /* An off_t can be arbitrarily complex */
index b2a6eaadb8ca81d75bb6a6aafe4a3c185c660f16..addc5dc801e7ddb33c1cca900f5b37969139e48b 100644 (file)
@@ -42,6 +42,8 @@ static char rcsid_scc_maybe_c[] =
 #include <krb5/libos.h>
 #include <krb5/los-proto.h>
 
+int krb5_scc_default_format = KRB5_SCC_DEFAULT_FVNO;
+
 krb5_error_code
 krb5_scc_close_file (id)
     krb5_ccache id;
@@ -85,7 +87,7 @@ krb5_scc_open_file (id, mode)
     krb5_ccache id;
     int mode;
 {
-     krb5_int16 scc_fvno = htons(KRB5_SCC_FVNO);
+     krb5_int16 scc_fvno;
      krb5_scc_data *data;
      FILE *f;
      char *open_flag;
@@ -154,6 +156,8 @@ krb5_scc_open_file (id, mode)
         /* write the version number */
         int errsave;
 
+        scc_fvno = htons(krb5_scc_default_format);
+        data->version = krb5_scc_default_format;
         if (!fwrite((char *)&scc_fvno, sizeof(scc_fvno), 1, f)) {
             errsave = errno;
             (void) krb5_unlock_file(f, data->filename);
@@ -167,11 +171,13 @@ krb5_scc_open_file (id, mode)
             (void) fclose(f);
             return KRB5_CCACHE_BADVNO;
         }
-        if (scc_fvno != (krb5_int16)htons(KRB5_SCC_FVNO)) {
+        if ((scc_fvno != htons(KRB5_SCC_FVNO)) &&
+            (scc_fvno != htons(KRB5_SCC_FVNO_1))) {
             (void) krb5_unlock_file(f, data->filename);
             (void) fclose(f);
             return KRB5_CCACHE_BADVNO;
         }
+        data->version = ntohs(scc_fvno);
      }
      data->file = f;
      return 0;
index 864c885fd2d346de5a607d381a47b08a2d2bc6d1..7fe1118454f8c7c9c1cc76255ba097cac913e0b0 100644 (file)
@@ -83,11 +83,21 @@ krb5_scc_read_principal(id, princ)
    krb5_ccache id;
    krb5_principal *princ;
 {
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
     krb5_error_code kret;
     register krb5_principal tmpprinc;
-    krb5_int32 length;
+    krb5_int32 length, type;
     int i;
 
+    if (data->version == KRB5_SCC_FVNO_1) {
+       type = KRB5_NT_UNKNOWN;
+    } else {
+        /* Read the 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)
@@ -102,6 +112,7 @@ krb5_scc_read_principal(id, princ)
        return KRB5_CC_NOMEM;
     }
     tmpprinc->length = length;
+    tmpprinc->type = type;
 
     kret = krb5_scc_read_data(id, krb5_princ_realm(tmpprinc));
     i = 0;
index 47b23af32c36674a0e37fb904c458161851aa66b..d808b6eb5a3238c3f1550cfbfe9b600887259837 100644 (file)
@@ -81,11 +81,18 @@ krb5_scc_store_principal(id, princ)
    krb5_ccache id;
    krb5_principal princ;
 {
+    krb5_scc_data *data = (krb5_scc_data *)id->data;
     krb5_error_code ret;
-    krb5_int32 i, length;
+    krb5_int32 i, length, type;
 
+    type = krb5_princ_type(princ);
     length = krb5_princ_size(princ);
 
+    if (data->version != KRB5_SCC_FVNO_1) {
+        ret = krb5_scc_store_int32(id, &type);
+        CHECK(ret);
+    }
+    
     ret = krb5_scc_store_int32(id, &length);
     CHECK(ret);