From: Barry Jaspan Date: Sun, 21 Jan 1990 16:50:43 +0000 (+0000) Subject: a slightly debugged version (not really), leaving for usenix now X-Git-Tag: krb5-1.0-alpha2~1222 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=587f799ffea0b9e35c2633be0ebbc263c03c1083;p=krb5.git a slightly debugged version (not really), leaving for usenix now git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@161 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/file/fcc.h b/src/lib/krb5/ccache/file/fcc.h index b04024046..a407f8348 100644 --- a/src/lib/krb5/ccache/file/fcc.h +++ b/src/lib/krb5/ccache/file/fcc.h @@ -18,6 +18,7 @@ #define __KRB5_FILE_CCACHE__ #include +#include "fcc-proto.h" #include "fcc-os.h" /* XXX Until I find out the right #define for this.. XXX */ diff --git a/src/lib/krb5/ccache/file/fcc_close.c b/src/lib/krb5/ccache/file/fcc_close.c index 891f55053..7c808b5c1 100644 --- a/src/lib/krb5/ccache/file/fcc_close.c +++ b/src/lib/krb5/ccache/file/fcc_close.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_close. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_resolve_c[] = "$Id$"; -#endif /* lint */ +#endif /* !lint && !SABER */ #include diff --git a/src/lib/krb5/ccache/file/fcc_defnam.c b/src/lib/krb5/ccache/file/fcc_defnam.c index 43a8286e2..d54efb2d1 100644 --- a/src/lib/krb5/ccache/file/fcc_defnam.c +++ b/src/lib/krb5/ccache/file/fcc_defnam.c @@ -16,9 +16,9 @@ * This file contains the source code for krb5_fcc_default_name. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_defnam_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include "fcc.h" diff --git a/src/lib/krb5/ccache/file/fcc_destry.c b/src/lib/krb5/ccache/file/fcc_destry.c index 52c91538c..596c4c6a6 100644 --- a/src/lib/krb5/ccache/file/fcc_destry.c +++ b/src/lib/krb5/ccache/file/fcc_destry.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_destroy. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_destry_c[] = "$Id$"; -#endif /* lint */ +#endif /* !lint && !SABER */ #include diff --git a/src/lib/krb5/ccache/file/fcc_eseq.c b/src/lib/krb5/ccache/file/fcc_eseq.c index d1cf1a596..54190985d 100644 --- a/src/lib/krb5/ccache/file/fcc_eseq.c +++ b/src/lib/krb5/ccache/file/fcc_eseq.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_end_seq_get. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_eseq_c[] = "$Id$"; -#endif /* lint */ +#endif /* !lint && !SABER */ #include #include "fcc.h" diff --git a/src/lib/krb5/ccache/file/fcc_gennew.c b/src/lib/krb5/ccache/file/fcc_gennew.c index 8a64f57dd..be8675ea8 100644 --- a/src/lib/krb5/ccache/file/fcc_gennew.c +++ b/src/lib/krb5/ccache/file/fcc_gennew.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_generate_new. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_resolve_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include "fcc.h" @@ -49,8 +49,7 @@ krb5_fcc_generate_new (id) sprintf(scratch, "%sXXXXXX", TKT_ROOT); mktemp(scratch); - ((krb5_fcc_data *) id->data) = (krb5_fcc_data *) - malloc(sizeof(krb5_fcc_data)); + id->data = (krb5_fcc_data *) malloc(sizeof(krb5_fcc_data)); if (((krb5_fcc_data *) id->data) == NULL) { free(id); return KRB5_NOMEM; @@ -68,11 +67,11 @@ krb5_fcc_generate_new (id) strcpy(((krb5_fcc_data *) id->data)->filename, scratch); /* Copy the virtual operation pointers into id */ - bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(struct _krb5_ccache)); + bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(krb5_cc_ops)); /* Make sure the file name is reserved */ - ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_EXCL, 0); - if (ret == -1 && errno != EEXIST) + ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT| O_EXCL,0600); + if (ret == -1) return ret; else { close(ret); diff --git a/src/lib/krb5/ccache/file/fcc_getnam.c b/src/lib/krb5/ccache/file/fcc_getnam.c index 290665a01..f5405c522 100644 --- a/src/lib/krb5/ccache/file/fcc_getnam.c +++ b/src/lib/krb5/ccache/file/fcc_getnam.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_get_name. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_resolve_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include diff --git a/src/lib/krb5/ccache/file/fcc_gprin.c b/src/lib/krb5/ccache/file/fcc_gprin.c index c4dc97a09..b644f0e57 100644 --- a/src/lib/krb5/ccache/file/fcc_gprin.c +++ b/src/lib/krb5/ccache/file/fcc_gprin.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_get_principal. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_gprinc_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include #include "fcc.h" diff --git a/src/lib/krb5/ccache/file/fcc_init.c b/src/lib/krb5/ccache/file/fcc_init.c index ba8367793..bf337e03c 100644 --- a/src/lib/krb5/ccache/file/fcc_init.c +++ b/src/lib/krb5/ccache/file/fcc_init.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_initialize. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_resolve_c[] = "$Id$"; -#endif /* lint */ +#endif /* !lint && !SABER */ #include @@ -46,7 +46,7 @@ krb5_fcc_initialize(id, princ) if (ret == -1) return ret; - krb5_fcc_write_principal(id, princ); + krb5_fcc_store_principal(id, princ); #ifdef OPENCLOSE close(((krb5_fcc_data *) id->data)->fd); diff --git a/src/lib/krb5/ccache/file/fcc_nseq.c b/src/lib/krb5/ccache/file/fcc_nseq.c index c5bdbf0e4..3f3a0159f 100644 --- a/src/lib/krb5/ccache/file/fcc_nseq.c +++ b/src/lib/krb5/ccache/file/fcc_nseq.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_next_cred. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_nseq_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include @@ -31,8 +31,9 @@ static char fcc_nseq_c[] = "$Id$"; * Effects: * Fills in creds with the "next" credentals structure from the cache * id. The actual order the creds are returned in is arbitrary. - * creds is set to allocated storage which must be freed by the caller - * via a call to krb5_free_credentials. + * Space is allocated for the variable length fields in the + * credentials structure, so the object returned must be passed to + * krb5_destroy_credential. * * The cursor is updated for the next call to krb5_fcc_next_cred. * @@ -40,11 +41,12 @@ static char fcc_nseq_c[] = "$Id$"; * system errors */ krb5_error_code -krb5_fcc_next_cred(id, creds, cursor) +krb5_fcc_next_cred(id, cursor, creds) krb5_ccache id; - krb5_creds *creds; krb5_cc_cursor *cursor; + krb5_creds *creds; { +#define TCHECK(ret) if (ret != KRB5_OK) goto lose; int ret; krb5_error_code kret; krb5_fcc_cursor *fcursor; @@ -62,25 +64,30 @@ krb5_fcc_next_cred(id, creds, cursor) if (ret < 0) return errno; - creds = (krb5_creds *) malloc(sizeof(krb5_creds)); - if (creds == NULL) - return KRB5_NOMEM; - - kret = krb5_fcc_read_principal(&creds->client); - kret = krb5_fcc_read_principal(&creds->server); - kret = krb5_fcc_read_keyblock(&creds->keyblock); - kret = krb5_fcc_read_times(&creds->times); - kret = krb5_fcc_read_bool(&creds->is_skey); - kret = krb5_fcc_read_flags(&creds->ticket_flags); - kret = krb5_fcc_read_data(&creds->ticket); - kret = krb5_fcc_read_data(&creds->second_ticket); - + kret = krb5_fcc_read_principal(id, &creds->client); + TCHECK(kret); + kret = krb5_fcc_read_principal(id, &creds->server); + TCHECK(kret); + kret = krb5_fcc_read_keyblock(id, &creds->keyblock); + TCHECK(kret); + kret = krb5_fcc_read_times(id, &creds->times); + TCHECK(kret); + kret = krb5_fcc_read_bool(id, &creds->is_skey); + TCHECK(kret); + kret = krb5_fcc_read_flags(id, &creds->ticket_flags); + TCHECK(kret); + kret = krb5_fcc_read_data(id, &creds->ticket); + TCHECK(kret); + kret = krb5_fcc_read_data(id, &creds->second_ticket); + TCHECK(kret); + fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd); cursor = (krb5_cc_cursor *) fcursor; #ifdef OPENCLOSE close(((krb5_fcc_data *) id->data)->fd); #endif - - return KRB5_OK; +lose: + + return kret; } diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c index c70bd75c7..9a6cb2709 100644 --- a/src/lib/krb5/ccache/file/fcc_read.c +++ b/src/lib/krb5/ccache/file/fcc_read.c @@ -1,18 +1,3 @@ -/* - * ************************************** - * Major problem: - * This code is really confused (meaning that I was confused when I - * wrote it). The declarations are set up such that the functions - * below can copy data into a structure it is given a pointer to, but - * they are written to allocate memory and return a pointer to that. - * Of course, the pointer is never returned because I have one too few - * levels of directory, so essentially nothing will work. - * - * Have fun, Bill. - * ************************************** - */ - - /* * $Source$ * $Author$ @@ -26,15 +11,16 @@ * credentials cache. These are not library-exported functions. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_read_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include #include "fcc.h" /* XXX Deal with kret return values */ - +#define CHECK(ret) if (ret != KRB5_OK) return ret; + /* XXX Doesn't deal if < sizeof(o) bytes are written XXX */ #define krb5_fcc_read(i,b,l) (read(((krb5_fcc_data *)i->data)->fd,b,l) == -1 \ ? errno : KRB5_OK) @@ -43,42 +29,52 @@ static char fcc_read_c[] = "$Id$"; * FOR ALL OF THE FOLLOWING FUNCTIONS: * * Requires: - * ((krb5_fcc_data *) id->data)->fd is open and at the right position - * in the file. + * id is open and set to read at the appropriate place in the file * * Effects: - * Allocates memory for and decodes the appropriate type from the - * cache id. The memory must be freed by the caller. + * Fills in the second argument with data of the appropriate type from + * the file. In some cases, the functions have to allocate space for + * variable length fields; therefore, krb5_destroy_ must be + * called for each filled in structure. * * Errors: - * system errors + * system errors (read errors) * KRB5_NOMEM */ krb5_error_code krb5_fcc_read_principal(id, princ) krb5_ccache id; - krb5_principal princ; + krb5_principal *princ; { krb5_error_code kret; krb5_int32 length; int i; /* Read the number of components */ - krb5_fcc_read_int32(id, &length); - - /* Get memory for length components */ - princ = (krb5_principal) malloc(sizeof(krb5_data *)*length); - if (princ == NULL) + kret = krb5_fcc_read_int32(id, &length); + CHECK(kret); + + /* + * The # of levels of indirection is confusing. A krb5_principal + * is an array of pointers to krb5_data. princ is a pointer to + * an array of pointers to krb5_data. (*princ)[i] a pointer to + * krb5_data. + */ + + /* Make *princ able to hold length pointers to krb5_data structs */ + *princ = (krb5_principal) malloc(sizeof(krb5_data *)*length); + if (*princ == NULL) return KRB5_NOMEM; - /* Read length components */ + /* XXX Memory leak XXX */ for (i=0; i < length; i++) { - kret = krb5_fcc_read_data(id, princ[i]); - if (kret != KRB5_OK) { - free(princ); - return kret; - } + (*princ)[i] = (krb5_data *) malloc(sizeof(krb5_data)); + if ((*princ)[i] == NULL) + return KRB5_NOMEM; + + kret = krb5_fcc_read_data(id, (*princ)[i]); + CHECK(kret); } return KRB5_OK; @@ -90,18 +86,39 @@ krb5_fcc_read_keyblock(id, keyblock) krb5_keyblock *keyblock; { krb5_error_code kret; + char *temp; /* HACK! */ int ret; - keyblock = (krb5_keyblock *) malloc(sizeof(krb5_keyblock)); - if (keyblock == NULL) - return KRB5_NOMEM; - + /* + * XXX The third field should be a char *, not a char[1]. + * Alternatively, I am *VERY* confused. + */ + kret = krb5_fcc_read_keytype(id, &keyblock->keytype); + CHECK(kret); kret = krb5_fcc_read_int(id, &keyblock->length); + CHECK(kret); + + temp = (char *) malloc(keyblock->length*sizeof(krb5_octet)); + if (temp == NULL) + return KRB5_NOMEM; + + ret = read(((krb5_fcc_data *) id->data)->fd, temp, + (keyblock->length)*sizeof(krb5_octet)); + + /* + keyblock->contents = (char *) malloc(keyblock->length*sizeof(krb5_octet)); + if (keyblock->contents == NULL) + return KRB5_NOMEM; + ret = read(((krb5_fcc_data *) id->data)->fd, keyblock->contents, (keyblock->length)*sizeof(krb5_octet)); + */ - return KRB5_OK; + if (ret < 0) + return errno; + else + return KRB5_OK; } krb5_error_code @@ -112,17 +129,12 @@ krb5_fcc_read_data(id, data) krb5_error_code kret; int ret; - data = (krb5_data *) malloc(sizeof(krb5_data)); - if (data == NULL) - return KRB5_NOMEM; - - kret = krb5_fcc_read_int32(id, data->length); + kret = krb5_fcc_read_int(id, &data->length); + CHECK(kret); data->data = (char *) malloc(data->length); - if (data->data == NULL) { - free(data); + if (data->data == NULL) return KRB5_NOMEM; - } ret = read(((krb5_fcc_data *) id->data)->fd, data->data, data->length); if (ret == -1) @@ -171,3 +183,10 @@ krb5_fcc_read_times(id, t) return krb5_fcc_read(id, 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, f, sizeof(krb5_flags)); +} diff --git a/src/lib/krb5/ccache/file/fcc_reslv.c b/src/lib/krb5/ccache/file/fcc_reslv.c index aee9d4ded..b4c2e3a5b 100644 --- a/src/lib/krb5/ccache/file/fcc_reslv.c +++ b/src/lib/krb5/ccache/file/fcc_reslv.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_resolve. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_resolve_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include @@ -41,42 +41,51 @@ extern krb5_cc_ops krb5_fcc_ops; */ krb5_error_code krb5_fcc_resolve (id, residual) - krb5_ccache id; + krb5_ccache *id; char *residual; { + krb5_ccache lid; int ret; - id = (krb5_ccache) malloc(sizeof(struct _krb5_ccache)); - if (id == NULL) + lid = (krb5_ccache) malloc(sizeof(struct _krb5_ccache)); + if (lid == NULL) return KRB5_NOMEM; - ((krb5_fcc_data *) id->data) = (krb5_fcc_data *) - malloc(sizeof(krb5_fcc_data)); - if (((krb5_fcc_data *) id->data) == NULL) { - free(id); + lid->ops = (krb5_cc_ops *) malloc(sizeof(krb5_cc_ops)); + if (lid->ops == NULL) { + free(lid); return KRB5_NOMEM; } - ((krb5_fcc_data *) id->data)->filename = (char *) + lid->data = (krb5_fcc_data *) malloc(sizeof(krb5_fcc_data)); + if (((krb5_fcc_data *) lid->data) == NULL) { + free(lid->ops); + free(lid); + return KRB5_NOMEM; + } + + ((krb5_fcc_data *) lid->data)->filename = (char *) malloc(strlen(residual) + 1); - if (((krb5_fcc_data *) id->data)->filename == NULL) { - free(((krb5_fcc_data *) id->data)); - free(id); + if (((krb5_fcc_data *) lid->data)->filename == NULL) { + free(((krb5_fcc_data *) lid->data)); + free(lid->ops); + free(lid); return KRB5_NOMEM; } - /* Copy the virtual operation pointers into id */ - bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(struct _krb5_ccache)); + /* Copy the virtual operation pointers into lid */ + bcopy((char *) &krb5_fcc_ops, lid->ops, sizeof(krb5_cc_ops)); /* Set up the filename */ - strcpy(((krb5_fcc_data *) id->data)->filename, residual); + strcpy(((krb5_fcc_data *) lid->data)->filename, residual); /* Make sure the file name is reserved */ - ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_EXCL, 0); - if (ret == -1 && errno != EEXIST) - return ret; + ret = open(((krb5_fcc_data *) lid->data)->filename, O_CREAT|O_EXCL,0600); + if (ret == -1) + return errno; else { close(ret); + *id = lid; return KRB5_OK; } } diff --git a/src/lib/krb5/ccache/file/fcc_retrv.c b/src/lib/krb5/ccache/file/fcc_retrv.c index cdda70e5d..daf18844f 100644 --- a/src/lib/krb5/ccache/file/fcc_retrv.c +++ b/src/lib/krb5/ccache/file/fcc_retrv.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_retrieve. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_retrieve_c[] = "$Id$"; -#endif /* lint */ +#endif /* !lint && !SABER */ #include @@ -53,15 +53,15 @@ krb5_fcc_retrieve(id, whichfields, mcreds, creds) /* This function could be considerably faster if it kept indexing */ /* information.. sounds like a "next version" idea to me. :-) */ - krb5_cc_cursor *cursor; + krb5_cc_cursor cursor; krb5_error_code kret; - kret = krb5_fcc_start_seq_get(id, cursor); + kret = krb5_fcc_start_seq_get(id, &cursor); if (kret != KRB5_OK) return kret; - while ((kret = krb5_fcc_next_cred(id, creds, cursor)) == KRB5_OK) { - if (standard_fields_match(mcreds, creds) + while ((kret = krb5_fcc_next_cred(id, &cursor, creds)) == KRB5_OK) { + if (1 /* XXX standard_fields_match(mcreds, creds) */ && (! set(KRB5_TC_MATCH_IS_SKEY) || mcreds->is_skey == creds->is_skey) @@ -83,11 +83,11 @@ krb5_fcc_retrieve(id, whichfields, mcreds, creds) } /* This one doesn't match */ - krb5_free_credentials(creds); + /* XXX krb5_free_credentials(creds); */ } /* If we get here, a match wasn't found */ - krb5_fcc_end_seq_get(id, cursor); + krb5_fcc_end_seq_get(id, &cursor); return KRB5_NOTFOUND; } diff --git a/src/lib/krb5/ccache/file/fcc_sseq.c b/src/lib/krb5/ccache/file/fcc_sseq.c index e0b7bda61..5daaff57e 100644 --- a/src/lib/krb5/ccache/file/fcc_sseq.c +++ b/src/lib/krb5/ccache/file/fcc_sseq.c @@ -10,9 +10,9 @@ * This file contains the source code for krb5_fcc_start_seq_get. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_sseq_c[] = "$Id$"; -#endif lint +#endif /* !lint && !SABER */ #include @@ -53,9 +53,9 @@ krb5_fcc_start_seq_get(id, cursor) lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET); #endif - krb5_fcc_skip_pprincipal(id); + krb5_fcc_skip_principal(id); fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd); - cursor = (krb5_cc_cursor *) fcursor; + *cursor = (krb5_cc_cursor *) fcursor; #ifdef OPENCLOSE close(((krb5_fcc_data *) id->data)->fd); diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c index e0240fc4d..3f20b3260 100644 --- a/src/lib/krb5/ccache/file/fcc_store.c +++ b/src/lib/krb5/ccache/file/fcc_store.c @@ -10,24 +10,14 @@ * This file contains the source code for krb5_fcc_store. */ -#ifndef lint +#if !defined(lint) && !defined(SABER) static char fcc_store_c[] = "$Id$"; -#endif /* lint */ +#endif /* !lint && !SABER */ #include #include "fcc.h" -/* XXX Doesn't deal if < sizeof(o) bytes are written XXX */ -#define krb5_fcc_write(i,b,l) (write(((krb5_fcc_data *)i->data)->fd,b,l) == -1\ - ? errno : KRB5_OK) - -#define krb5_fcc_store_int32(id,i) krb5_fcc_write(id, i, sizeof(krb5_int32)) -#define krb5_fcc_store_keytype(id,k) krb5_fcc_write(id,k,sizeof(krb5_keytype)) -#define krb5_fcc_store_int(id,i) krb5_fcc_write(id,i,sizeof(int)) -#define krb5_fcc_store_bool(id,b) krb5_fcc_write(id,b,sizeof(krb5_boolean)) -#define krb5_fcc_store_times(id,t) krb5_fcc_write(id,t,sizeof(krb5_ticket_times)) - #define CHECK(ret) if (ret != KRB5_OK) return ret; /* @@ -51,14 +41,15 @@ krb5_fcc_store(id, creds) /* Make sure we are writing to the end of the file */ #ifdef OPENCLOSE - ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)->filename, O_APPEND, 0); + ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)-> + filename, O_RDWR|O_APPEND, 0); if (((krb5_fcc_data *) id->data)->fd < 0) return errno; -#else - ret = lseek(((krb5_fcc_data *) id->data)->fd, L_XTND, 0); +#endif + + ret = lseek(((krb5_fcc_data *) id->data)->fd, 0, L_XTND); if (ret < 0) return errno; -#endif ret = krb5_fcc_store_principal(id, creds->client); TCHECK(ret); @@ -84,78 +75,3 @@ lose: return ret; #undef TCHECK } - -/* - * FOR ALL OF THE FOLLOWING FUNCTIONS: - * - * Requires: - * ((krb5_fcc_data *) id->data)->fd is open and at the right position. - * - * Effects: - * Stores an encoded version of the second argument in the - * cache file. - * - * Errors: - * system errors - */ - -static krb5_error_code -krb5_fcc_store_principal(id, princ) - krb5_ccache id; - krb5_principal princ; -{ - krb5_error_code ret; - krb5_principal temp; - krb5_int32 i, length = 0; - - /* Count the number of components */ - temp = princ; - while (temp++) - length += 1; - - ret = krb5_fcc_store_int32(id, &length); - CHECK(ret); - for (i=0; i < length; i++) { - ret = krb5_store_data(id, princ[i]); - CHECK(ret); - } - - return KRB5_OK; -} - -static krb5_error_code -krb5_store_keyblock(id, keyblock) - krb5_ccache id; - krb5_keyblock *keyblock; -{ - krb5_error_code ret; - - ret = krb5_fcc_store_keytype(id, &keyblock->keytype); - CHECK(ret); - ret = krb5_fcc_store_int(id, &keyblock->length); - CHECK(ret); - ret = write(((krb5_fcc_data *) id->data)->fd, keyblock->contents, - (keyblock->length)*sizeof(krb5_octet)); - CHECK(ret); - - return KRB5_OK; -} - - -static krb5_error_code -krb5_fcc_store_data(id, data) - krb5_ccache id; - krb5_data *data; -{ - krb5_error_code ret; - - 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 errno; - - return KRB5_OK; -} - - diff --git a/src/lib/krb5/ccache/file/fcc_test.c b/src/lib/krb5/ccache/file/fcc_test.c index 3b6edcecc..7a755ab50 100644 --- a/src/lib/krb5/ccache/file/fcc_test.c +++ b/src/lib/krb5/ccache/file/fcc_test.c @@ -2,34 +2,32 @@ #include "fcc.h" -krb5_data client[] = { - { +krb5_data client1 = { #define DATA "client1-comp1" - sizeof(DATA), - DATA, + sizeof(DATA), + DATA, #undef DATA - }, - { +}; + +krb5_data client2 = { #define DATA "client1-comp2" - sizeof(DATA), - DATA, + sizeof(DATA), + DATA, #undef DATA - }, }; -krb5_data server[] = { - { +krb5_data server1 = { #define DATA "server1-comp1" - sizeof(DATA), - DATA, + sizeof(DATA), + DATA, #undef DATA - }, - { +}; + +krb5_data server2 = { #define DATA "server1-comp2" - sizeof(DATA), - DATA, + sizeof(DATA), + DATA, #undef DATA - }, }; krb5_creds test_creds = { @@ -37,7 +35,7 @@ krb5_creds test_creds = { NULL, { 1, - 5, + 1, "1" }, { @@ -64,6 +62,13 @@ krb5_creds test_creds = { void init_test_cred() { - test_creds.client = &client; - test_creds.server = &server; + test_creds.client = (krb5_principal) malloc(sizeof(krb5_data *)*3); + test_creds.client[0] = &client1; + test_creds.client[1] = &client2; + test_creds.client[2] = NULL; + + test_creds.server = (krb5_principal) malloc(sizeof(krb5_data *)*3); + test_creds.server[0] = &server1; + test_creds.server[1] = &server2; + test_creds.server[2] = NULL; }