From: Ken Raeburn Date: Thu, 8 Nov 1990 13:43:44 +0000 (+0000) Subject: Fixed up error catching in a couple of cases; added routines to read X-Git-Tag: krb5-1.0-alpha3~170 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9d050a3aef9f2a6ffc3ef478f659bf473812bb97;p=krb5.git Fixed up error catching in a couple of cases; added routines to read authdata. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1422 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/stdio/scc_read.c b/src/lib/krb5/ccache/stdio/scc_read.c index 481b5011a..790a3779f 100644 --- a/src/lib/krb5/ccache/stdio/scc_read.c +++ b/src/lib/krb5/ccache/stdio/scc_read.c @@ -37,7 +37,7 @@ krb5_scc_read(id, buf, len) int ret; ret = fread((char *) buf, 1, len, ((krb5_scc_data *) id->data)->file); - if (ret == -1) + if (ret == 0) return krb5_scc_interpret(errno); else if (ret != len) return KRB5_CC_END; @@ -170,7 +170,7 @@ krb5_scc_read_keyblock(id, keyblock) (keyblock->length)*sizeof(krb5_octet), ((krb5_scc_data *) id->data)->file); - if (ret < 0) { + if (ret == 0) { xfree(keyblock->contents); return krb5_scc_interpret(errno); } @@ -306,9 +306,87 @@ krb5_scc_read_times(id, t) } krb5_error_code -krb5_scc_read_flags(id, f) - krb5_ccache id; - krb5_flags *f; +krb5_scc_read_flags (id, f) + krb5_ccache id; + krb5_flags *f; +{ + return krb5_scc_read (id, (krb5_pointer) f, sizeof (krb5_flags)); +} + +krb5_error_code +krb5_scc_read_authdata(id, a) + krb5_ccache id; + krb5_authdata ***a; +{ + krb5_error_code kret; + krb5_int32 length; + int i; + + *a = 0; + + /* Read the number of components */ + kret = krb5_scc_read_int32(id, &length); + CHECK(kret); + + if (length == 0) + 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; + + 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); + } + + return KRB5_OK; + errout: + if (*a) + krb5_free_authdata(*a); + return kret; +} + +krb5_error_code +krb5_scc_read_authdatum(id, a) + krb5_ccache id; + krb5_authdata *a; { - return krb5_scc_read(id, (krb5_pointer) f, sizeof(krb5_flags)); + krb5_error_code kret; + int ret; + + a->contents = NULL; + + kret = krb5_scc_read_ui_2(id, &a->ad_type); + CHECK(kret); + kret = krb5_scc_read_int(id, &a->length); + CHECK(kret); + + a->contents = (krb5_octet *) malloc(a->length); + if (a->contents == NULL) + return KRB5_CC_NOMEM; + ret = fread ((char *)a->contents, 1, + (a->length)*sizeof(krb5_octet), + ((krb5_scc_data *) id->data)->file); + if (ret == 0) { + xfree(a->contents); + return krb5_scc_interpret(errno); + } + if (ret != (a->length)*sizeof(krb5_octet)) { + xfree(a->contents); + return KRB5_CC_END; + } + return KRB5_OK; +errout: + if (a->contents) + xfree(a->contents); + return kret; }