From 198cd52c488b77ee741f094fdd64055d520f51df Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Fri, 18 Nov 1994 19:56:41 +0000 Subject: [PATCH] All files: 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 | 18 ++ src/lib/krb5/ccache/stdio/scc-proto.h | 14 +- src/lib/krb5/ccache/stdio/scc.h | 5 +- src/lib/krb5/ccache/stdio/scc_gennew.c | 2 +- src/lib/krb5/ccache/stdio/scc_maybe.c | 5 +- src/lib/krb5/ccache/stdio/scc_nseq.c | 8 +- src/lib/krb5/ccache/stdio/scc_read.c | 259 ++++++++++++++----------- src/lib/krb5/ccache/stdio/scc_store.c | 4 +- src/lib/krb5/ccache/stdio/scc_write.c | 161 +++++++-------- 9 files changed, 268 insertions(+), 208 deletions(-) diff --git a/src/lib/krb5/ccache/stdio/ChangeLog b/src/lib/krb5/ccache/stdio/ChangeLog index 01c6641fa..576b44ffb 100644 --- a/src/lib/krb5/ccache/stdio/ChangeLog +++ b/src/lib/krb5/ccache/stdio/ChangeLog @@ -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 diff --git a/src/lib/krb5/ccache/stdio/scc-proto.h b/src/lib/krb5/ccache/stdio/scc-proto.h index 3e4418c5e..9cae84123 100644 --- a/src/lib/krb5/ccache/stdio/scc-proto.h +++ b/src/lib/krb5/ccache/stdio/scc-proto.h @@ -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 **)); diff --git a/src/lib/krb5/ccache/stdio/scc.h b/src/lib/krb5/ccache/stdio/scc.h index 6ae8b2e70..203b316b5 100644 --- a/src/lib/krb5/ccache/stdio/scc.h +++ b/src/lib/krb5/ccache/stdio/scc.h @@ -50,9 +50,10 @@ */ #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 diff --git a/src/lib/krb5/ccache/stdio/scc_gennew.c b/src/lib/krb5/ccache/stdio/scc_gennew.c index a65241006..7775a6fb2 100644 --- a/src/lib/krb5/ccache/stdio/scc_gennew.c +++ b/src/lib/krb5/ccache/stdio/scc_gennew.c @@ -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); diff --git a/src/lib/krb5/ccache/stdio/scc_maybe.c b/src/lib/krb5/ccache/stdio/scc_maybe.c index 8237650b2..410dc6b6c 100644 --- a/src/lib/krb5/ccache/stdio/scc_maybe.c +++ b/src/lib/krb5/ccache/stdio/scc_maybe.c @@ -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; diff --git a/src/lib/krb5/ccache/stdio/scc_nseq.c b/src/lib/krb5/ccache/stdio/scc_nseq.c index 3f8ce3f84..365f57330 100644 --- a/src/lib/krb5/ccache/stdio/scc_nseq.c +++ b/src/lib/krb5/ccache/stdio/scc_nseq.c @@ -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); diff --git a/src/lib/krb5/ccache/stdio/scc_read.c b/src/lib/krb5/ccache/stdio/scc_read.c index ce3ed3ea2..1a7ee5a2d 100644 --- a/src/lib/krb5/ccache/stdio/scc_read.c +++ b/src/lib/krb5/ccache/stdio/scc_read.c @@ -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; + } diff --git a/src/lib/krb5/ccache/stdio/scc_store.c b/src/lib/krb5/ccache/stdio/scc_store.c index af01ed40b..f8bd0907e 100644 --- a/src/lib/krb5/ccache/stdio/scc_store.c +++ b/src/lib/krb5/ccache/stdio/scc_store.c @@ -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); diff --git a/src/lib/krb5/ccache/stdio/scc_write.c b/src/lib/krb5/ccache/stdio/scc_write.c index a45fdb940..346db57ec 100644 --- a/src/lib/krb5/ccache/stdio/scc_write.c +++ b/src/lib/krb5/ccache/stdio/scc_write.c @@ -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; iad_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); } -- 2.26.2