From a7735754e826b831e8249cfb31718699d164ceed Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Mon, 6 Oct 2008 20:25:45 +0000 Subject: [PATCH] Change LDAP key-sequence encoder to use a single data structure git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20829 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/k5-int.h | 24 +++++++++---------- src/lib/krb5/asn.1/ldap_key_seq.c | 23 ++++++++++++------ .../kdb/ldap/libkdb_ldap/ldap_principal2.c | 19 +++++++++++---- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/include/k5-int.h b/src/include/k5-int.h index 111b12159..f05adecf3 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -1595,17 +1595,21 @@ krb5_error_code decode_krb5_sam_key (const krb5_data *, krb5_sam_key **); struct _krb5_key_data; /* kdb.h */ + +struct ldap_seqof_key_data { + krb5_int32 mkvno; /* Master key version number */ + struct _krb5_key_data *key_data; + krb5_int16 n_key_data; +}; +typedef struct ldap_seqof_key_data ldap_seqof_key_data; + krb5_error_code -krb5int_ldap_encode_sequence_of_keys (struct _krb5_key_data *key_data, - krb5_int16 n_key_data, - krb5_int32 mkvno, +krb5int_ldap_encode_sequence_of_keys (ldap_seqof_key_data *val, krb5_data **code); krb5_error_code krb5int_ldap_decode_sequence_of_keys (krb5_data *in, - struct _krb5_key_data **out, - krb5_int16 *n_key_data, - int *mkvno); + ldap_seqof_key_data **rep); /************************************************************************* * End of prototypes for krb5_decode.c @@ -1864,16 +1868,12 @@ typedef struct _krb5int_access { /* Used for KDB LDAP back end. */ krb5_error_code - (*asn1_ldap_encode_sequence_of_keys) (struct _krb5_key_data *key_data, - krb5_int16 n_key_data, - krb5_int32 mkvno, + (*asn1_ldap_encode_sequence_of_keys) (ldap_seqof_key_data *val, krb5_data **code); krb5_error_code (*asn1_ldap_decode_sequence_of_keys) (krb5_data *in, - struct _krb5_key_data **out, - krb5_int16 *n_key_data, - int *mkvno); + ldap_seqof_key_data **); /* * pkinit asn.1 encode/decode functions diff --git a/src/lib/krb5/asn.1/ldap_key_seq.c b/src/lib/krb5/asn.1/ldap_key_seq.c index 7f0355d9f..1d48f9b57 100644 --- a/src/lib/krb5/asn.1/ldap_key_seq.c +++ b/src/lib/krb5/asn.1/ldap_key_seq.c @@ -133,11 +133,11 @@ last: /* Major version and minor version are both '1' - first version */ /* asn1_error_code asn1_encode_sequence_of_keys (krb5_key_data *key_data, */ krb5_error_code -asn1_encode_sequence_of_keys (krb5_key_data *key_data, - krb5_int16 n_key_data, - krb5_int32 mkvno, /* Master key version number */ - krb5_data **code) +asn1_encode_sequence_of_keys (ldap_seqof_key_data *val, krb5_data **code) { + krb5_key_data *key_data = val->key_data; + krb5_int16 n_key_data = val->n_key_data; + krb5_int32 mkvno = val->mkvno; asn1_error_code ret = 0; asn1buf *buf = NULL; unsigned int length, sum = 0; @@ -392,10 +392,13 @@ last: /* asn1_error_code asn1_decode_sequence_of_keys (krb5_data *in, */ krb5_error_code asn1_decode_sequence_of_keys (krb5_data *in, - krb5_key_data **out, - krb5_int16 *n_key_data, - int *mkvno) + ldap_seqof_key_data **rep) { + ldap_seqof_key_data *repval; + krb5_key_data **out; + krb5_int16 *n_key_data; + int *mkvno; + asn1_error_code ret; asn1buf buf, subbuf; int seqindef; @@ -404,6 +407,12 @@ krb5_error_code asn1_decode_sequence_of_keys (krb5_data *in, int kvno, maj, min; long lval; + repval = calloc(1,sizeof(ldap_seqof_key_data)); + *rep = repval; + out = &repval->key_data; + n_key_data = &repval->n_key_data; + mkvno = &repval->mkvno; + *n_key_data = 0; *out = NULL; diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c index 6e7ba33f1..12f0dd360 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c @@ -325,6 +325,7 @@ asn1_encode_sequence_of_keys (krb5_key_data *key_data, krb5_int16 n_key_data, krb5_int32 mkvno, krb5_data **code) { krb5_error_code err; + ldap_seqof_key_data val; /* * This should be pushed back into other library initialization @@ -334,8 +335,11 @@ asn1_encode_sequence_of_keys (krb5_key_data *key_data, krb5_int16 n_key_data, if (err) return err; - return accessor.asn1_ldap_encode_sequence_of_keys(key_data, n_key_data, - mkvno, code); + val.key_data = key_data; + val.n_key_data = n_key_data; + val.mkvno = mkvno; + + return accessor.asn1_ldap_encode_sequence_of_keys(&val, code); } static krb5_error_code @@ -343,6 +347,7 @@ asn1_decode_sequence_of_keys (krb5_data *in, krb5_key_data **out, krb5_int16 *n_key_data, int *mkvno) { krb5_error_code err; + ldap_seqof_key_data *p; /* * This should be pushed back into other library initialization @@ -352,8 +357,14 @@ asn1_decode_sequence_of_keys (krb5_data *in, krb5_key_data **out, if (err) return err; - return accessor.asn1_ldap_decode_sequence_of_keys(in, out, n_key_data, - mkvno); + err = accessor.asn1_ldap_decode_sequence_of_keys(in, &p); + if (err) + return err; + *out = p->key_data; + *n_key_data = p->n_key_data; + *mkvno = p->mkvno; + free(p); + return 0; } -- 2.26.2