From b0d8d1166571b9d74bb99ba99e4ff9f58a706ba9 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Thu, 17 Nov 1994 07:05:42 +0000 Subject: [PATCH] Changes to implement FCC format version #3, which is architecture 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 | 16 +++ src/lib/krb5/ccache/file/fcc-proto.h | 14 +- src/lib/krb5/ccache/file/fcc.h | 20 ++- src/lib/krb5/ccache/file/fcc_gennew.c | 2 +- src/lib/krb5/ccache/file/fcc_maybe.c | 3 +- src/lib/krb5/ccache/file/fcc_nseq.c | 8 +- src/lib/krb5/ccache/file/fcc_read.c | 188 +++++++++++++++----------- src/lib/krb5/ccache/file/fcc_store.c | 6 +- src/lib/krb5/ccache/file/fcc_write.c | 149 +++++++++++--------- 9 files changed, 235 insertions(+), 171 deletions(-) diff --git a/src/lib/krb5/ccache/file/ChangeLog b/src/lib/krb5/ccache/file/ChangeLog index 6b2c80e44..e66909f9b 100644 --- a/src/lib/krb5/ccache/file/ChangeLog +++ b/src/lib/krb5/ccache/file/ChangeLog @@ -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 diff --git a/src/lib/krb5/ccache/file/fcc-proto.h b/src/lib/krb5/ccache/file/fcc-proto.h index b6a5e0041..56d4a1d3d 100644 --- a/src/lib/krb5/ccache/file/fcc-proto.h +++ b/src/lib/krb5/ccache/file/fcc-proto.h @@ -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 **)); diff --git a/src/lib/krb5/ccache/file/fcc.h b/src/lib/krb5/ccache/file/fcc.h index f7f461cd3..18d560a32 100644 --- a/src/lib/krb5/ccache/file/fcc.h +++ b/src/lib/krb5/ccache/file/fcc.h @@ -42,18 +42,24 @@ /* * 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 diff --git a/src/lib/krb5/ccache/file/fcc_gennew.c b/src/lib/krb5/ccache/file/fcc_gennew.c index 71c85028b..36d00aab7 100644 --- a/src/lib/krb5/ccache/file/fcc_gennew.c +++ b/src/lib/krb5/ccache/file/fcc_gennew.c @@ -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 */ diff --git a/src/lib/krb5/ccache/file/fcc_maybe.c b/src/lib/krb5/ccache/file/fcc_maybe.c index 44086f4bb..5fcfc3aac 100644 --- a/src/lib/krb5/ccache/file/fcc_maybe.c +++ b/src/lib/krb5/ccache/file/fcc_maybe.c @@ -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); diff --git a/src/lib/krb5/ccache/file/fcc_nseq.c b/src/lib/krb5/ccache/file/fcc_nseq.c index febd382a0..08746a6b5 100644 --- a/src/lib/krb5/ccache/file/fcc_nseq.c +++ b/src/lib/krb5/ccache/file/fcc_nseq.c @@ -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); diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c index f1b8dcf66..298442c4a 100644 --- a/src/lib/krb5/ccache/file/fcc_read.c +++ b/src/lib/krb5/ccache/file/fcc_read.c @@ -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) diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c index d3bf32652..1bdbb33da 100644 --- a/src/lib/krb5/ccache/file/fcc_store.c +++ b/src/lib/krb5/ccache/file/fcc_store.c @@ -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); diff --git a/src/lib/krb5/ccache/file/fcc_write.c b/src/lib/krb5/ccache/file/fcc_write.c index 4ef473054..cbb092f6d 100644 --- a/src/lib/krb5/ccache/file/fcc_write.c +++ b/src/lib/krb5/ccache/file/fcc_write.c @@ -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; iad_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); } -- 2.26.2