From be773340f439e993c1ff0cd534b85e59e4d6adb9 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Fri, 4 May 1990 17:46:00 +0000 Subject: [PATCH] add address support git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@742 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/file/fcc-proto.h | 6 ++ src/lib/krb5/ccache/file/fcc_nseq.c | 7 +- src/lib/krb5/ccache/file/fcc_read.c | 138 ++++++++++++++++++++++++--- src/lib/krb5/ccache/file/fcc_store.c | 2 + src/lib/krb5/ccache/file/fcc_write.c | 54 +++++++++++ 5 files changed, 194 insertions(+), 13 deletions(-) diff --git a/src/lib/krb5/ccache/file/fcc-proto.h b/src/lib/krb5/ccache/file/fcc-proto.h index a59a35a11..920222422 100644 --- a/src/lib/krb5/ccache/file/fcc-proto.h +++ b/src/lib/krb5/ccache/file/fcc-proto.h @@ -48,11 +48,14 @@ krb5_error_code krb5_fcc_read_principal PROTOTYPE((krb5_ccache id , krb5_princip krb5_error_code krb5_fcc_read_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock *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_int16 PROTOTYPE((krb5_ccache id , krb5_int16 *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_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 *)); /* fcc_reslv.c */ krb5_error_code krb5_fcc_resolve PROTOTYPE((krb5_ccache *id , char *residual )); @@ -80,11 +83,14 @@ krb5_error_code krb5_fcc_store_principal PROTOTYPE((krb5_ccache id , krb5_princi 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_int16 PROTOTYPE((krb5_ccache id , krb5_int16 *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_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 id , krb5_addresses ** )); +krb5_error_code krb5_fcc_store_addr PROTOTYPE((krb5_ccache id , krb5_address * )); /* fcc_test.c */ void init_test_cred PROTOTYPE((void )); diff --git a/src/lib/krb5/ccache/file/fcc_nseq.c b/src/lib/krb5/ccache/file/fcc_nseq.c index a6dc1b7f4..8038ba6de 100644 --- a/src/lib/krb5/ccache/file/fcc_nseq.c +++ b/src/lib/krb5/ccache/file/fcc_nseq.c @@ -51,6 +51,8 @@ krb5_fcc_next_cred(id, cursor, creds) krb5_error_code kret; krb5_fcc_cursor *fcursor; + bzero((char *)creds, sizeof(*creds)); + if (OPENCLOSE(id)) { ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0); if (ret < 0) @@ -76,6 +78,8 @@ krb5_fcc_next_cred(id, cursor, creds) TCHECK(kret); kret = krb5_fcc_read_flags(id, &creds->ticket_flags); TCHECK(kret); + kret = krb5_fcc_read_addrs(id, &creds->addresses); + TCHECK(kret); kret = krb5_fcc_read_data(id, &creds->ticket); TCHECK(kret); kret = krb5_fcc_read_data(id, &creds->second_ticket); @@ -89,6 +93,7 @@ krb5_fcc_next_cred(id, cursor, creds) ((krb5_fcc_data *) id->data)->fd = -1; } lose: - + if (kret != KRB5_OK) + krb5_free_creds(creds); return kret; } diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c index c3a94ab71..3886062b7 100644 --- a/src/lib/krb5/ccache/file/fcc_read.c +++ b/src/lib/krb5/ccache/file/fcc_read.c @@ -18,7 +18,7 @@ static char fcc_read_c[] = "$Id$"; #include #include "fcc.h" -#define CHECK(ret) if (ret != KRB5_OK) return ret; +#define CHECK(ret) if (ret != KRB5_OK) goto errout; /* * Effects: @@ -71,6 +71,8 @@ krb5_fcc_read_principal(id, princ) krb5_int32 length; int i; + *princ = 0; + /* Read the number of components */ kret = krb5_fcc_read_int32(id, &length); CHECK(kret); @@ -89,17 +91,60 @@ krb5_fcc_read_principal(id, princ) if (*princ == NULL) return KRB5_NOMEM; - /* XXX Memory leak XXX */ for (i=0; i < length; i++) { (*princ)[i] = (krb5_data *) malloc(sizeof(krb5_data)); - if ((*princ)[i] == NULL) - return KRB5_NOMEM; - + if ((*princ)[i] == NULL) { + krb5_free_principal(*princ); + return KRB5_NOMEM; + } kret = krb5_fcc_read_data(id, (*princ)[i]); CHECK(kret); } + return kret; + errout: + if (*princ) + krb5_free_principal(*princ); + return kret; +} + +krb5_error_code +krb5_fcc_read_addrs(id, addrs) + krb5_ccache id; + krb5_address ***addrs; +{ + krb5_error_code kret; + krb5_int32 length; + int i; + + *addrs = 0; + + /* Read the number of components */ + kret = krb5_fcc_read_int32(id, &length); + CHECK(kret); + + /* Make *addrs able to hold length pointers to krb5_address structs + * Add one extra for a null-terminated list + */ + *addrs = (krb5_address **) calloc(length+1, sizeof(krb5_address *)); + if (*addrs == NULL) + return KRB5_NOMEM; + + for (i=0; i < length; i++) { + (*addrs)[i] = (krb5_address *) malloc(sizeof(krb5_address)); + if ((*addrs)[i] == NULL) { + krb5_free_address(*addrs); + return KRB5_NOMEM; + } + kret = krb5_fcc_read_addr(id, (*addrs)[i]); + CHECK(kret); + } + return KRB5_OK; + errout: + if (*addrs) + krb5_free_address(*addrs); + return kret; } krb5_error_code @@ -110,6 +155,8 @@ krb5_fcc_read_keyblock(id, keyblock) krb5_error_code kret; int ret; + keyblock->contents = 0; + kret = krb5_fcc_read_keytype(id, &keyblock->keytype); CHECK(kret); kret = krb5_fcc_read_int(id, &keyblock->length); @@ -122,10 +169,20 @@ krb5_fcc_read_keyblock(id, keyblock) ret = read(((krb5_fcc_data *) id->data)->fd, (char *)keyblock->contents, (keyblock->length)*sizeof(krb5_octet)); - if (ret < 0) - return errno; - else - return KRB5_OK; + if (ret < 0) { + xfree(keyblock->contents); + return errno; + } + if (ret != (keyblock->length)*sizeof(krb5_octet)) { + xfree(keyblock->contents); + return KRB5_EOF; + } + + return KRB5_OK; + errout: + if (keyblock->contents) + xfree(keyblock->contents); + return kret; } krb5_error_code @@ -136,6 +193,8 @@ krb5_fcc_read_data(id, data) krb5_error_code kret; int ret; + data->data = 0; + kret = krb5_fcc_read_int32(id, &data->length); CHECK(kret); @@ -143,11 +202,58 @@ krb5_fcc_read_data(id, data) if (data->data == NULL) return KRB5_NOMEM; - ret = read(((krb5_fcc_data *) id->data)->fd, data->data, data->length); - if (ret == -1) - return errno; + ret = read(((krb5_fcc_data *) id->data)->fd, (char *)data->data, + data->length); + if (ret == -1) { + xfree(data->data); + return errno; + } + if (ret != data->length) { + xfree(data->data); + return KRB5_EOF; + } + return KRB5_OK; + errout: + if (data->data) + xfree(data->data); + return kret; +} + +krb5_error_code +krb5_fcc_read_addr(id, addr) + krb5_ccache id; + krb5_address *addr; +{ + krb5_error_code kret; + int ret; + + addr->contents = 0; + kret = krb5_fcc_read_int16(id, &addr->addrtype); + CHECK(kret); + + kret = krb5_fcc_read_int(id, &addr->length); + CHECK(kret); + + addr->contents = (krb5_octet *) malloc(addr->length); + if (addr->contents == NULL) + return KRB5_NOMEM; + + ret = read(((krb5_fcc_data *) id->data)->fd, (char *)addr->contents, + (addr->length)*sizeof(krb5_octet)); + if (ret == -1) { + xfree(addr->contents); + return errno; + } + if (ret != (addr->length)*sizeof(krb5_octet)) { + xfree(addr->contents); + return KRB5_EOF; + } return KRB5_OK; + errout: + if (addr->contents) + xfree(addr->contents); + return kret; } krb5_error_code @@ -158,6 +264,14 @@ krb5_fcc_read_int32(id, i) return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int32)); } +krb5_error_code +krb5_fcc_read_int16(id, i) + krb5_ccache id; + krb5_int16 *i; +{ + return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int16)); +} + krb5_error_code krb5_fcc_read_keytype(id, k) krb5_ccache id; diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c index af5d3cf38..26f350c8b 100644 --- a/src/lib/krb5/ccache/file/fcc_store.c +++ b/src/lib/krb5/ccache/file/fcc_store.c @@ -64,6 +64,8 @@ krb5_fcc_store(id, creds) TCHECK(ret); ret = krb5_fcc_store_flags(id, &creds->ticket_flags); TCHECK(ret); + ret = krb5_fcc_store_addrs(id, creds->addresses); + TCHECK(ret); ret = krb5_fcc_store_data(id, &creds->ticket); TCHECK(ret); ret = krb5_fcc_store_data(id, &creds->second_ticket); diff --git a/src/lib/krb5/ccache/file/fcc_write.c b/src/lib/krb5/ccache/file/fcc_write.c index afff300de..827d92b35 100644 --- a/src/lib/krb5/ccache/file/fcc_write.c +++ b/src/lib/krb5/ccache/file/fcc_write.c @@ -82,6 +82,30 @@ krb5_fcc_store_principal(id, princ) return KRB5_OK; } +krb5_error_code +krb5_fcc_store_addrs(id, addrs) + krb5_ccache id; + krb5_address ** addrs; +{ + krb5_error_code ret; + krb5_address **temp; + krb5_int32 i, length = 0; + + /* Count the number of components */ + temp = addrs; + while (*temp++) + length += 1; + + ret = krb5_fcc_store_int32(id, &length); + CHECK(ret); + for (i=0; i < length; i++) { + ret = krb5_fcc_store_addr(id, addrs[i]); + CHECK(ret); + } + + return KRB5_OK; +} + krb5_error_code krb5_fcc_store_keyblock(id, keyblock) krb5_ccache id; @@ -97,10 +121,32 @@ krb5_fcc_store_keyblock(id, keyblock) (keyblock->length)*sizeof(krb5_octet)); if (ret < 0) return errno; + if (ret != (keyblock->length)*sizeof(krb5_octet)) + return KRB5_EOF; return KRB5_OK; } +krb5_error_code +krb5_fcc_store_addr(id, addr) + krb5_ccache id; + krb5_address *addr; +{ + krb5_error_code ret; + + ret = krb5_fcc_store_int16(id, &addr->addrtype); + CHECK(ret); + ret = krb5_fcc_store_int(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 errno; + if (ret != (addr->length)*sizeof(krb5_octet)) + return KRB5_EOF; + return KRB5_OK; +} + krb5_error_code krb5_fcc_store_data(id, data) @@ -125,6 +171,14 @@ krb5_fcc_store_int32(id, i) { return krb5_fcc_write(id, (char *) i, sizeof(krb5_int32)); } + +krb5_error_code +krb5_fcc_store_int16(id, i) + krb5_ccache id; + krb5_int16 *i; +{ + return krb5_fcc_write(id, (char *) i, sizeof(krb5_int16)); +} krb5_error_code krb5_fcc_store_keytype(id, k) -- 2.26.2