From: Theodore Tso Date: Tue, 18 Aug 1992 23:26:16 +0000 (+0000) Subject: Changes to support new version of ccache file format. (This one handles principal X-Git-Tag: krb5-1.0-beta2~131 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=813d4703e0b4a9ff5eaa93d5d70474dacbae5f06;p=krb5.git Changes to support new version of ccache file format. (This one handles principal types.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2331 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/file/fcc.h b/src/lib/krb5/ccache/file/fcc.h index b3d6e1cdc..011eb6b48 100644 --- a/src/lib/krb5/ccache/file/fcc.h +++ b/src/lib/krb5/ccache/file/fcc.h @@ -41,7 +41,21 @@ #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 */ diff --git a/src/lib/krb5/ccache/file/fcc_maybe.c b/src/lib/krb5/ccache/file/fcc_maybe.c index f729b8e19..93e51f65d 100644 --- a/src/lib/krb5/ccache/file/fcc_maybe.c +++ b/src/lib/krb5/ccache/file/fcc_maybe.c @@ -33,6 +33,8 @@ static char rcsid_fcc_maybe_c[] = #include "fcc.h" #include +int krb5_fcc_default_format = KRB5_FCC_DEFAULT_FVNO; + #ifdef KRB5_USE_INET #include #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; diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c index d1b3baede..e59e8c82a 100644 --- a/src/lib/krb5/ccache/file/fcc_read.c +++ b/src/lib/krb5/ccache/file/fcc_read.c @@ -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)); diff --git a/src/lib/krb5/ccache/file/fcc_write.c b/src/lib/krb5/ccache/file/fcc_write.c index 766463ddd..2d010cdb5 100644 --- a/src/lib/krb5/ccache/file/fcc_write.c +++ b/src/lib/krb5/ccache/file/fcc_write.c @@ -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); diff --git a/src/lib/krb5/ccache/stdio/scc.h b/src/lib/krb5/ccache/stdio/scc.h index cdc620780..78ca896ce 100644 --- a/src/lib/krb5/ccache/stdio/scc.h +++ b/src/lib/krb5/ccache/stdio/scc.h @@ -41,7 +41,20 @@ #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 */ diff --git a/src/lib/krb5/ccache/stdio/scc_maybe.c b/src/lib/krb5/ccache/stdio/scc_maybe.c index b2a6eaadb..addc5dc80 100644 --- a/src/lib/krb5/ccache/stdio/scc_maybe.c +++ b/src/lib/krb5/ccache/stdio/scc_maybe.c @@ -42,6 +42,8 @@ static char rcsid_scc_maybe_c[] = #include #include +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; diff --git a/src/lib/krb5/ccache/stdio/scc_read.c b/src/lib/krb5/ccache/stdio/scc_read.c index 864c885fd..7fe111845 100644 --- a/src/lib/krb5/ccache/stdio/scc_read.c +++ b/src/lib/krb5/ccache/stdio/scc_read.c @@ -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; diff --git a/src/lib/krb5/ccache/stdio/scc_write.c b/src/lib/krb5/ccache/stdio/scc_write.c index 47b23af32..d808b6eb5 100644 --- a/src/lib/krb5/ccache/stdio/scc_write.c +++ b/src/lib/krb5/ccache/stdio/scc_write.c @@ -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);