From: Theodore Tso Date: Tue, 29 Sep 1992 14:35:35 +0000 (+0000) Subject: Fold in ISI changes for asn.1 fixes X-Git-Tag: krb5-1.0-beta2~26 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=47d1b4272ba559d1fca882baf39b69232be54e4e;p=krb5.git Fold in ISI changes for asn.1 fixes git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2436 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/kprin2prin.c b/src/lib/krb5/asn.1/kprin2prin.c index 585d09e41..652e4cddd 100644 --- a/src/lib/krb5/asn.1/kprin2prin.c +++ b/src/lib/krb5/asn.1/kprin2prin.c @@ -46,46 +46,22 @@ krb5_principal2KRB5_PrincipalName(val, error) krb5_const_principal val; register int *error; { -#if 0 - /* this code is for -h2 style ISODE structures. However, pepsy - generates horribly broken when given -h2. */ - + register struct type_KRB5_PrincipalName *retval = 0; + register struct element_KRB5_6 *namestring = 0, *rv1 = 0, *rv2; register int i; - register struct type_KRB5_PrincipalName *retval; - - /* count elements */ - for (i = 0; val[i]; i++); - - i--; /* skip the realm */ + int nelem = krb5_princ_size(val); - retval = (struct type_KRB5_PrincipalName *) - xmalloc(sizeof(*retval)+max(0,i-1)*sizeof(retval->GeneralString[0])); + retval = (struct type_KRB5_PrincipalName *) xmalloc(sizeof(*retval)); if (!retval) { *error = ENOMEM; return(0); } - retval->nelem = i; - for (i = 1; i <= retval->nelem; i++) { /* still skipping realm */ - retval->GeneralString[i-1] = krb5_data2qbuf(val[i]); - if (!retval->GeneralString[i-1]) { - /* clean up */ - retval->nelem = i-1; - free_KRB5_PrincipalName(retval); - *error = ENOMEM; - return(0); - } - } - return(retval); - -#endif - register struct type_KRB5_PrincipalName *retval = 0, *rv1 = 0, *rv2; - register int i; - int nelem = krb5_princ_size(val); - + + retval->name__type = krb5_princ_type(val); /* still skipping realm */ for (i = 0; i < nelem; i++, rv1 = rv2) { - rv2 = (struct type_KRB5_PrincipalName *) xmalloc(sizeof(*rv2)); + rv2 = (struct element_KRB5_6 *) xmalloc(sizeof(*rv2)); if (!rv2) { if (retval) free_KRB5_PrincipalName(retval); @@ -95,8 +71,8 @@ register int *error; if (rv1) rv1->next = rv2; xbzero((char *)rv2, sizeof (*rv2)); - if (!retval) - retval = rv2; + if (!namestring) + namestring = rv2; rv2->GeneralString = krb5_data2qbuf(krb5_princ_component(val, i)); if (!rv2->GeneralString) { @@ -107,5 +83,8 @@ register int *error; return(0); } } + + retval->name__string = namestring; + return(retval); } diff --git a/src/lib/krb5/asn.1/kpwds2pwds.c b/src/lib/krb5/asn.1/kpwds2pwds.c index 9bc17e505..54be0b261 100644 --- a/src/lib/krb5/asn.1/kpwds2pwds.c +++ b/src/lib/krb5/asn.1/kpwds2pwds.c @@ -72,7 +72,7 @@ static char rcsid_kpwds2pwds[] = struct type_KRB5_PasswdData * krb5_pwd_data2KRB5_PWD__DATA(val, error) -register krb5_pwd_data *val; +register const krb5_pwd_data *val; register int *error; { register struct type_KRB5_PasswdData *retval = 0; diff --git a/src/lib/krb5/asn.1/ktgrq2tgrq.c b/src/lib/krb5/asn.1/ktgrq2tgrq.c index 47f74db5f..bc7c9eeb9 100644 --- a/src/lib/krb5/asn.1/ktgrq2tgrq.c +++ b/src/lib/krb5/asn.1/ktgrq2tgrq.c @@ -246,8 +246,13 @@ struct element_KRB5_7 *krb5_pa_data2element_KRB5_7(val, error) rv2 = (struct element_KRB5_7 *) xmalloc(sizeof(*rv2)); if (!rv2) { - if (retval) - free_KRB5_PA__DATA(retval); + errout: + while (retval) { + free_KRB5_PA__DATA(retval->PA__DATA); + rv1 = retval->next; + free(retval); + retval = rv1; + } *error = ENOMEM; return(0); } @@ -259,13 +264,8 @@ struct element_KRB5_7 *krb5_pa_data2element_KRB5_7(val, error) rv2->PA__DATA = (struct type_KRB5_PA__DATA *) xmalloc(sizeof(*(rv2->PA__DATA))); - if (!rv2->PA__DATA) { - errout: - if (retval) - free_KRB5_PA__DATA(retval); - *error = ENOMEM; - return(0); - } + if (!rv2->PA__DATA) + goto errout; rv2->PA__DATA->padata__type = val[i]->pa_type; rv2->PA__DATA->pa__data = str2qb((char *)(val[i])->contents, (val[i])->length, 1); diff --git a/src/lib/krb5/asn.1/prin2kprin.c b/src/lib/krb5/asn.1/prin2kprin.c index 36701d7ba..9f54fd5e5 100644 --- a/src/lib/krb5/asn.1/prin2kprin.c +++ b/src/lib/krb5/asn.1/prin2kprin.c @@ -63,50 +63,19 @@ const struct type_KRB5_PrincipalName *val; const struct type_KRB5_Realm *realm; register int *error; { -#if 0 - /* this code is for -h2 style ISODE structures. However, pepsy - generates horribly broken when given -h2. */ - register krb5_principal retval; register int i; + register const struct element_KRB5_6 *rv; - /* plus one for the realm, plus one for null term */ - retval = (krb5_principal) xcalloc(val->nelem + 2, sizeof(krb5_data *)); - + retval = (krb5_principal) malloc(sizeof(krb5_principal_data)); if (!retval) { *error = ENOMEM; return(0); } - retval[0] = qbuf2krb5_data(realm, error); - if (!retval[0]) { - xfree(retval); - return(0); - } - for (i = 0; i < val->nelem; i++) { - retval[i+1] = qbuf2krb5_data(val->GeneralString[i], error); - if (!retval[i+1]) { - krb5_free_principal(retval); - return(0); - } - } - retval[i+1] = 0; - return(retval); -#endif - - register krb5_principal retval; - register int i; - register const struct type_KRB5_PrincipalName *rv; - - for (i = 1, rv = val; rv->next; i++, rv = rv->next) + for (i = 1, rv = val->name__string; rv->next; i++, rv = rv->next) ; - retval = (krb5_principal) malloc(sizeof(krb5_principal_data)); - - if (!retval) { - *error = ENOMEM; - return(0); - } /* plus one for the realm */ retval->length = i; retval->data = (krb5_data *)malloc(i * sizeof(krb5_data)); @@ -116,6 +85,8 @@ register int *error; return 0; } + retval->type = val->name__type; + if (qbuf_to_data(realm, krb5_princ_realm(retval))) { xfree(retval->data); xfree(retval); @@ -123,7 +94,7 @@ register int *error; return 0; } - for (i = 0, rv = val; rv; rv = rv->next, i++) + for (i = 0, rv = val->name__string; rv; rv = rv->next, i++) if (qbuf_to_data(rv->GeneralString, krb5_princ_component(retval, i))) { while (--i >= 0) free(krb5_princ_component(retval, i)->data); diff --git a/src/lib/krb5/asn.1/tgrq2ktgrq.c b/src/lib/krb5/asn.1/tgrq2ktgrq.c index 9ea7dee41..8a08d880c 100644 --- a/src/lib/krb5/asn.1/tgrq2ktgrq.c +++ b/src/lib/krb5/asn.1/tgrq2ktgrq.c @@ -201,6 +201,54 @@ register int *error; return retval; } + +krb5_pa_data ** +element_KRB5_72krb5_pa_data(val, error) + struct element_KRB5_7 *val; + register int *error; +{ + register krb5_pa_data **retval; + register int i; + register struct element_KRB5_7 *rv; + + for (i = 0, rv = val; rv; i++, rv = rv->next) + ; + + /* plus one for null terminator */ + retval = (krb5_pa_data **) xcalloc(i + 1, sizeof(*retval)); + if (!retval) { + *error = ENOMEM; + return(0); + } + for (i = 0, rv = val; rv; rv = rv->next, i++) { + if (qb_pullup(rv->PA__DATA->pa__data) != OK) { + xfree(retval); + *error = ENOMEM; + return(0); + } + retval[i] = (krb5_pa_data *) xmalloc(sizeof(*retval[i])); + if (!retval[i]) { + krb5_free_pa_data(retval); + *error = ENOMEM; + return(0); + } + retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len); + if (!retval[i]->contents) { + xfree(retval[i]); + retval[i] = 0; + krb5_free_pa_data(retval); + *error = ENOMEM; + return(0); + } + retval[i]->pa_type = rv->PA__DATA->padata__type; + retval[i]->length = rv->PA__DATA->pa__data->qb_forw->qb_len; + xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data, + retval[i]->contents, retval[i]->length); + } + retval[i] = 0; + return(retval); +} + krb5_kdc_req * KRB5_KDC__REQ2krb5_kdc_req(val, error) const register struct type_KRB5_KDC__REQ *val; @@ -213,7 +261,7 @@ register int *error; retval->msg_type = val->msg__type; if (val->padata) { - retval->padata = KRB5_PA__DATA2krb5_pa_data(val->padata, error); + retval->padata = element_KRB5_72krb5_pa_data(val->padata, error); if (!retval->padata) { krb5_free_kdc_req(retval); return(0);