Changes to prevent krb5_encode.c from writing to constant structures.
authorTheodore Tso <tytso@mit.edu>
Thu, 11 Aug 1994 04:44:13 +0000 (04:44 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 11 Aug 1994 04:44:13 +0000 (04:44 +0000)
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
src/lib/krb5/asn.1/asn1_encode_k.c
src/lib/krb5/asn.1/asn1_encode_k.h
src/lib/krb5/asn.1/krb5_encode.c

index e9ac5718520aceefe42c6cb98b7348ff26674f72..ab5809219f94ac5ac5431e0fa4c58990961e01b0 100644 (file)
@@ -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
index 894ba95a681227124a05a71a6d14136890a51a11..fe78062fc7ad3edc0de9ea815ffcb6592276853b 100644 (file)
@@ -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();
 
index cb4945573e3f517093f0c3f6b4893dee065ef9c6..7d388a4a2e790fae6b6bd41f8cf81b2bbe712aac 100644 (file)
@@ -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));
 
index 22bc609ed5653561ab709ac8d64fa901317e1813..f61497ff73b55b34b8749b4d0d2a3ea700616eef 100644 (file)
@@ -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;