From 338fb396b1f6211994bd31fc153b717d5e675356 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Thu, 11 Aug 1994 04:44:13 +0000 Subject: [PATCH] Changes to prevent krb5_encode.c from writing to constant structures. Internals of ASN.1 code cleaned up a bit in the process.... git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4121 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/asn.1/ChangeLog | 16 ++++++++++ src/lib/krb5/asn.1/asn1_encode_k.c | 51 +++++++----------------------- src/lib/krb5/asn.1/asn1_encode_k.h | 6 ++-- src/lib/krb5/asn.1/krb5_encode.c | 25 +++------------ 4 files changed, 36 insertions(+), 62 deletions(-) diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index e9ac57185..ab5809219 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,19 @@ +Thu Aug 11 00:38:10 1994 Theodore Y. Ts'o (tytso@dcl) + + * asn1_encode_k.c (asn1_encode_kdc_req): Add extra argument which + specifies the msg_type of the encoding; don't use req->msg_type + which is generally not set right. (That output is only as a place + to stash the msg_type from decode). All callers updated. + + * asn1_encode_k.c (asn1_encode_kdc_rep): Add extra argument which + specifies the msg_type of the encoding; don't use rep->msg_type + which is generally not set right. (That output is only as a place + to stash the msg_type from decode). All callers updated. + + * asn1_encode_k.c (asn1_encode_msgtype): Routine removed. Not + really necessary, since a msg_type is really just an integer. + + Thu Aug 4 13:19:14 1994 Tom Yu (tlyu@dragons-lair) * asn1_decode_k.c (asn1_decode_sequence_of_enctype): fix typo diff --git a/src/lib/krb5/asn.1/asn1_encode_k.c b/src/lib/krb5/asn.1/asn1_encode_k.c index 894ba95a6..fe78062fc 100644 --- a/src/lib/krb5/asn.1/asn1_encode_k.c +++ b/src/lib/krb5/asn.1/asn1_encode_k.c @@ -130,37 +130,6 @@ asn1_error_code asn1_encode_ui_4(buf, val, retlen) } -asn1_error_code asn1_encode_msgtype(buf, val, retlen) - asn1buf * buf; - const /*krb5_msgtype*/int val; - int * retlen; -{ - switch(val){ - case KRB5_AS_REQ: - return asn1_encode_integer(buf,ASN1_KRB_AS_REQ,retlen); - case KRB5_AS_REP: - return asn1_encode_integer(buf,ASN1_KRB_AS_REP,retlen); - case KRB5_TGS_REQ: - return asn1_encode_integer(buf,ASN1_KRB_TGS_REQ,retlen); - case KRB5_TGS_REP: - return asn1_encode_integer(buf,ASN1_KRB_TGS_REP,retlen); - case KRB5_AP_REQ: - return asn1_encode_integer(buf,ASN1_KRB_AP_REQ,retlen); - case KRB5_AP_REP: - return asn1_encode_integer(buf,ASN1_KRB_AP_REP,retlen); - case KRB5_SAFE: - return asn1_encode_integer(buf,ASN1_KRB_SAFE,retlen); - case KRB5_PRIV: - return asn1_encode_integer(buf,ASN1_KRB_PRIV,retlen); - case KRB5_CRED: - return asn1_encode_integer(buf,ASN1_KRB_CRED,retlen); - case KRB5_ERROR: - return asn1_encode_integer(buf,ASN1_KRB_ERROR,retlen); - default: - return KRB5_BADMSGTYPE; - } -} - asn1_error_code asn1_encode_realm(DECLARG(asn1buf *, buf), DECLARG(const krb5_principal, val), DECLARG(int *, retlen)) @@ -383,9 +352,11 @@ asn1_error_code asn1_encode_krb5_authdata_elt(DECLARG(asn1buf *, buf), asn1_cleanup(); } -asn1_error_code asn1_encode_kdc_rep(DECLARG(asn1buf *, buf), +asn1_error_code asn1_encode_kdc_rep(DECLARG(int, msg_type), + DECLARG(asn1buf *, buf), DECLARG(const krb5_kdc_rep *, val), DECLARG(int *, retlen)) + OLDDECLARG(int, msg_type) OLDDECLARG(asn1buf *, buf) OLDDECLARG(const krb5_kdc_rep *, val) OLDDECLARG(int *, retlen) @@ -400,7 +371,9 @@ asn1_error_code asn1_encode_kdc_rep(DECLARG(asn1buf *, buf), asn1_addfield(val->client,3,asn1_encode_realm); if(val->padata != NULL && val->padata[0] != NULL) asn1_addfield((const krb5_pa_data**)val->padata,2,asn1_encode_sequence_of_pa_data); - asn1_addfield(val->msg_type,1,asn1_encode_msgtype); + if (msg_type != KRB5_AS_REP && msg_type != KRB5_TGS_REP) + return KRB5_BADMSGTYPE; + asn1_addfield(msg_type,1,asn1_encode_integer); asn1_addfield(KVNO,0,asn1_encode_integer); asn1_makeseq(); @@ -743,9 +716,11 @@ asn1_error_code asn1_encode_sequence_of_enctype(DECLARG(asn1buf *, buf), asn1_cleanup(); } -asn1_error_code asn1_encode_kdc_req(DECLARG(asn1buf *, buf), +asn1_error_code asn1_encode_kdc_req(DECLARG(int, msg_type), + DECLARG(asn1buf *, buf), DECLARG(const krb5_kdc_req *, val), DECLARG(int *, retlen)) + OLDDECLARG(int, msg_type) OLDDECLARG(asn1buf *, buf) OLDDECLARG(const krb5_kdc_req *, val) OLDDECLARG(int *, retlen) @@ -757,11 +732,9 @@ asn1_error_code asn1_encode_kdc_req(DECLARG(asn1buf *, buf), asn1_addfield(val,4,asn1_encode_kdc_req_body); if(val->padata != NULL && val->padata[0] != NULL) asn1_addfield((const krb5_pa_data**)val->padata,3,asn1_encode_sequence_of_pa_data); - if(val->msg_type == KRB5_AS_REQ){ - asn1_addfield(ASN1_KRB_AS_REQ,2,asn1_encode_integer); - }else if(val->msg_type == KRB5_TGS_REQ){ - asn1_addfield(ASN1_KRB_TGS_REQ,2,asn1_encode_integer); - }else return KRB5_BADMSGTYPE; + if (msg_type != KRB5_AS_REQ && msg_type != KRB5_TGS_REQ) + return KRB5_BADMSGTYPE; + asn1_addfield(msg_type,2,asn1_encode_integer); asn1_addfield(KVNO,1,asn1_encode_integer); asn1_makeseq(); diff --git a/src/lib/krb5/asn.1/asn1_encode_k.h b/src/lib/krb5/asn.1/asn1_encode_k.h index cb4945573..7d388a4a2 100644 --- a/src/lib/krb5/asn.1/asn1_encode_k.h +++ b/src/lib/krb5/asn.1/asn1_encode_k.h @@ -139,7 +139,8 @@ asn1_error_code asn1_encode_krb5_authdata_elt PROTOTYPE((asn1buf *buf, const krb5_authdata *val, int *retlen)); asn1_error_code asn1_encode_kdc_rep - PROTOTYPE((asn1buf *buf, const krb5_kdc_rep *val, int *retlen)); + PROTOTYPE((int msg_type, asn1buf *buf, const krb5_kdc_rep *val, + int *retlen)); asn1_error_code asn1_encode_enc_kdc_rep_part PROTOTYPE((asn1buf *buf, const krb5_enc_kdc_rep_part *val, @@ -186,7 +187,8 @@ asn1_error_code asn1_encode_sequence_of_enctype int *retlen)); asn1_error_code asn1_encode_kdc_req - PROTOTYPE((asn1buf *buf, + PROTOTYPE((int msg_type, + asn1buf *buf, const krb5_kdc_req *val, int *retlen)); diff --git a/src/lib/krb5/asn.1/krb5_encode.c b/src/lib/krb5/asn.1/krb5_encode.c index 22bc609ed..f61497ff7 100644 --- a/src/lib/krb5/asn.1/krb5_encode.c +++ b/src/lib/krb5/asn.1/krb5_encode.c @@ -333,16 +333,8 @@ krb5_error_code encode_krb5_as_rep(DECLARG(const krb5_kdc_rep *, rep), { krb5_setup(); - /* Not all applications set this. The sample app "sclient", for - example. So I guess it should just be ignored. */ -/* if(rep->msg_type != KRB5_AS_REP) return KRB5_BADMSGTYPE;*/ - /* In fact, I may have to be even more forgiving in order for the - encoding to come out properly. I'm explicitly fixing up the - msg_type here. */ - rep->msg_type = KRB5_AS_REP; - /* AS-REP ::= [APPLICATION 11] KDC-REP */ - retval = asn1_encode_kdc_rep(buf,rep,&length); + retval = asn1_encode_kdc_rep(KRB5_AS_REP,buf,rep,&length); if(retval) return retval; sum += length; @@ -359,11 +351,8 @@ krb5_error_code encode_krb5_tgs_rep(DECLARG(const krb5_kdc_rep *, rep), { krb5_setup(); -/* if(rep->msg_type != KRB5_TGS_REP) return KRB5_BADMSGTYPE;*/ - rep->msg_type = KRB5_TGS_REP; - /* TGS-REP ::= [APPLICATION 13] KDC-REP */ - retval = asn1_encode_kdc_rep(buf,rep,&length); + retval = asn1_encode_kdc_rep(KRB5_TGS_REP,buf,rep,&length); if(retval) return retval; sum += length; @@ -460,11 +449,8 @@ krb5_error_code encode_krb5_as_req(DECLARG(const krb5_kdc_req *, rep), { krb5_setup(); -/* if(rep->msg_type != KRB5_AS_REQ) return KRB5_BADMSGTYPE;*/ - rep->msg_type = KRB5_AS_REQ; - /* AS-REQ ::= [APPLICATION 10] KDC-REQ */ - retval = asn1_encode_kdc_req(buf,rep,&length); + retval = asn1_encode_kdc_req(KRB5_AS_REQ,buf,rep,&length); if(retval) return retval; sum += length; @@ -480,11 +466,8 @@ krb5_error_code encode_krb5_tgs_req(DECLARG(const krb5_kdc_req *, rep), { krb5_setup(); -/* if(rep->msg_type != KRB5_TGS_REQ) return KRB5_BADMSGTYPE;*/ - rep->msg_type = KRB5_TGS_REQ; - /* TGS-REQ ::= [APPLICATION 12] KDC-REQ */ - retval = asn1_encode_kdc_req(buf,rep,&length); + retval = asn1_encode_kdc_req(KRB5_TGS_REQ,buf,rep,&length); if(retval) return retval; sum += length; -- 2.26.2