From: Sang Seok Lim Date: Mon, 29 Nov 2004 20:21:38 +0000 (+0000) Subject: 1) type component reference support X-Git-Tag: OPENLDAP_REL_ENG_2_3_0ALPHA~176 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=decfd7217f384ce3030eb4ece043732b89b7c32e;p=openldap 1) type component reference support 2) nibble type memory support when decoding 3) description type object identifier support 4) OPTIONAL, DEFAULT support in certificate decoder/extractor/matching 5) Misc bug fix --- diff --git a/configure b/configure index 21e210688c..422a15287c 100755 --- a/configure +++ b/configure @@ -1797,9 +1797,11 @@ if test "${enable_modules+set}" = set; then { echo "configure: error: bad value $enableval for --enable-modules" 1>&2; exit 1; } fi ol_enable_modules="$ol_arg" + WITH_MODULES_ENABLED=yes else ol_enable_modules="no" + WITH_MODULES_ENABLED=no fi # end --enable-modules ol_enable_multimaster=${ol_enable_multimaster-no} @@ -24839,6 +24841,7 @@ EOF fi +WITH_MODULES_ENABLED=no if test "$ol_link_modules" != no ; then cat >> confdefs.h <<\EOF #define SLAPD_MODULES 1 @@ -24846,6 +24849,7 @@ EOF BUILD_SLAPD=yes SLAPD_MODULES_LDFLAGS="-dlopen self" + WITH_MODULES_ENABLED=yes fi cat >> confdefs.h <<\EOF diff --git a/configure.in b/configure.in index d9b2f865d5..cdaf1f3ca1 100644 --- a/configure.in +++ b/configure.in @@ -2588,6 +2588,7 @@ if test "$ol_link_modules" != no ; then AC_DEFINE(SLAPD_MODULES,1,[define to support modules]) BUILD_SLAPD=yes SLAPD_MODULES_LDFLAGS="-dlopen self" + WITH_MODULES_ENABLED=yes fi AC_DEFINE(SLAPD_MOD_STATIC,1,[statically linked module]) diff --git a/contrib/slapd-modules/comp_match/README b/contrib/slapd-modules/comp_match/README index be79884274..846706ff4e 100644 --- a/contrib/slapd-modules/comp_match/README +++ b/contrib/slapd-modules/comp_match/README @@ -51,7 +51,7 @@ you will get compmatch.la and other necessary files in ./libs --component search filter example "componentCertificate:componentCertificateMatch:=item:{ component \"tbsCertificate.serialNumber\", rule allComponentsMatch, value 2 }" -You can find more examples in "test031-component-filter", a test script. +You can find more examples in "test031-component-filter", the test script. How to add a new ASN.1 syntax other than the example @@ -83,5 +83,5 @@ before using it, don't forget to check following status of development, See componentlib.c to check which ASN.1 types are currently supported 2) Component version of GSER encoders are not supported yet 3) Not all ComponentId of a component reference are supported yet -supported : identifier, from-beginning, count, from-end -not supported : all, select, content +supported : identifier, from-beginning, count, from-end, +not supported : select, content diff --git a/contrib/slapd-modules/comp_match/certificate.c b/contrib/slapd-modules/comp_match/certificate.c index 3b15643125..08ba91d12d 100644 --- a/contrib/slapd-modules/comp_match/certificate.c +++ b/contrib/slapd-modules/comp_match/certificate.c @@ -1,7 +1,7 @@ /* * certificate.c * "AuthenticationFramework" ASN.1 module encode/decode/extracting/matching/free C src. - * This file was generated by modified eSMACC compiler Sat Oct 23 20:25:08 2004 + * This file was generated by modified eSMACC compiler Tue Nov 23 23:28:16 2004 * The generated files are supposed to be compiled as a module for OpenLDAP Software */ @@ -52,16 +52,16 @@ MatchingComponentAlgorithmIdentifier ( char* oid, ComponentSyntaxInfo* csi_attr, } /* BMatchingComponentAlgorithmIdentifier */ void* -ExtractingComponentAlgorithmIdentifier ( ComponentReference* cr, ComponentAlgorithmIdentifier *comp ) +ExtractingComponentAlgorithmIdentifier ( void* mem_op, ComponentReference* cr, ComponentAlgorithmIdentifier *comp ) { - if ( ( strncmp(comp->algorithm.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->algorithm.identifier.bv_val && strncmp(comp->algorithm.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->algorithm; else return NULL; } - if ( ( strncmp(comp->parameters.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->parameters.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->parameters.identifier.bv_val && strncmp(comp->parameters.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->parameters.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->parameters; else @@ -72,6 +72,7 @@ ExtractingComponentAlgorithmIdentifier ( ComponentReference* cr, ComponentAlgori int BDecComponentAlgorithmIdentifier PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -88,7 +89,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -98,7 +99,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentOid (b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode); + BDecComponentOid (mem_op, b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode); (&k->algorithm)->identifier.bv_val = (&k->algorithm)->id_buf; (&k->algorithm)->identifier.bv_len = strlen("algorithm"); strcpy( (&k->algorithm)->identifier.bv_val, "algorithm"); @@ -121,7 +122,7 @@ int mode) if (!seqDone) { SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm)); - BDecComponentAnyDefinedBy (b, (&k->parameters), &totalElmtsLen1, mode ); + BDecComponentAnyDefinedBy (mem_op,b, (&k->parameters), &totalElmtsLen1, mode ); (&k->parameters)->identifier.bv_val = (&k->parameters)->id_buf; (&k->parameters)->identifier.bv_len = strlen("parameters"); strcpy( (&k->parameters)->identifier.bv_val, "parameters"); @@ -138,19 +139,19 @@ int mode) return -1; if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentAlgorithmIdentifier*) malloc( sizeof(ComponentAlgorithmIdentifier) ); + *v = t = (ComponentAlgorithmIdentifier*) CompAlloc( mem_op, sizeof(ComponentAlgorithmIdentifier) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAlgorithmIdentifier ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAlgorithmIdentifier ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentAlgorithmIdentifier ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -160,7 +161,8 @@ int mode) } /* BDecAlgorithmIdentifier*/ int -GDecComponentAlgorithmIdentifier PARAMS ((b, v, bytesDecoded, mode), +GDecComponentAlgorithmIdentifier PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentAlgorithmIdentifier **v _AND_ AsnLen *bytesDecoded _AND_ @@ -172,44 +174,49 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentOid (b, (&k->algorithm), bytesDecoded, mode); + if ( strncmp( peek_head, "algorithm", strlen("algorithm") ) == 0 ) { + GDecComponentOid (mem_op, b, (&k->algorithm), bytesDecoded, mode); (&k->algorithm)->identifier.bv_val = peek_head; (&k->algorithm)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } + } + if ( strncmp( peek_head, "parameters", strlen("parameters") ) == 0 ) { SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm)); - GDecComponentAnyDefinedBy (b, (&k->parameters), bytesDecoded, mode ); + GDecComponentAnyDefinedBy (mem_op, b, (&k->parameters), bytesDecoded, mode ); (&k->parameters)->identifier.bv_val = peek_head; (&k->parameters)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -218,19 +225,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentAlgorithmIdentifier*) malloc( sizeof(ComponentAlgorithmIdentifier) ); + *v = t = (ComponentAlgorithmIdentifier*) CompAlloc( mem_op, sizeof(ComponentAlgorithmIdentifier) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAlgorithmIdentifier ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAlgorithmIdentifier ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentAlgorithmIdentifier ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -238,23 +245,6 @@ int mode) return LDAP_SUCCESS; } /* GDecAlgorithmIdentifier*/ -void FreeComponentAlgorithmIdentifier(ComponentAlgorithmIdentifier *v) -{ - - if(v == NULL) - return; - FreeComponentOid((&v->algorithm)); - free ((v->algorithm).comp_desc); - - if(COMPONENTNOT_NULL ((&v->parameters))) - { - FreeComponentAnyDefinedBy((&v->parameters)); - free ((v->parameters).comp_desc); - - } - -} /* FreeAlgorithmIdentifier */ - int MatchingComponentTime ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -287,28 +277,28 @@ MatchingComponentTime ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSynta } /* BMatchingComponentTimeContent */ void* -ExtractingComponentTime ( ComponentReference* cr, ComponentTime *comp ) +ExtractingComponentTime ( void* mem_op, ComponentReference* cr, ComponentTime *comp ) { if( (comp->choiceId) == TIME_UTCTIME && - ((strncmp(comp->a.utcTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || + (( comp->a.utcTime->identifier.bv_val && strncmp(comp->a.utcTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || ( strncmp(comp->a.utcTime->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) { if ( cr->cr_curr->ci_next == NULL ) return (comp->a.utcTime); else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentUTCTime ( cr, (comp->a.utcTime) ); + return ExtractingComponentUTCTime ( mem_op, cr, (comp->a.utcTime) ); }; } if( (comp->choiceId) == TIME_GENERALIZEDTIME && - ((strncmp(comp->a.generalizedTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || + (( comp->a.generalizedTime->identifier.bv_val && strncmp(comp->a.generalizedTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || ( strncmp(comp->a.generalizedTime->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) { if ( cr->cr_curr->ci_next == NULL ) return (comp->a.generalizedTime); else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentGeneralizedTime ( cr, (comp->a.generalizedTime) ); + return ExtractingComponentGeneralizedTime ( mem_op, cr, (comp->a.generalizedTime) ); }; } return NULL; @@ -316,6 +306,7 @@ ExtractingComponentTime ( ComponentReference* cr, ComponentTime *comp ) int BDecComponentTime PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -332,7 +323,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -342,7 +333,7 @@ int mode) case MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE): case MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE): (k->choiceId) = TIME_UTCTIME; - BDecComponentUTCTime (b, tagId0, elmtLen0, (&k->a.utcTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); + BDecComponentUTCTime (mem_op, b, tagId0, elmtLen0, (&k->a.utcTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); (k->a.utcTime)->identifier.bv_val = (k->a.utcTime)->id_buf; (k->a.utcTime)->identifier.bv_len = strlen("utcTime"); strcpy( (k->a.utcTime)->identifier.bv_val, "utcTime"); @@ -351,7 +342,7 @@ int mode) case MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE): case MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE): (k->choiceId) = TIME_GENERALIZEDTIME; - BDecComponentGeneralizedTime (b, tagId0, elmtLen0, (&k->a.generalizedTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); + BDecComponentGeneralizedTime (mem_op, b, tagId0, elmtLen0, (&k->a.generalizedTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); (k->a.generalizedTime)->identifier.bv_val = (k->a.generalizedTime)->id_buf; (k->a.generalizedTime)->identifier.bv_len = strlen("generalizedTime"); strcpy( (k->a.generalizedTime)->identifier.bv_val, "generalizedTime"); @@ -363,19 +354,19 @@ int mode) break; } /* end switch */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentTime*) malloc( sizeof(ComponentTime) ); + *v = t = (ComponentTime*) CompAlloc( mem_op, sizeof(ComponentTime) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTime ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTime ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentTime ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTime; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -385,7 +376,8 @@ int mode) } /* BDecTimeContent */ int -GDecComponentTime PARAMS ((b, v, bytesDecoded, mode), +GDecComponentTime PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentTime **v _AND_ AsnLen *bytesDecoded _AND_ @@ -397,16 +389,16 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen2 = LocateNextGSERToken(b,&peek_head2,GSER_NO_COPY)) ){ + if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } @@ -416,14 +408,14 @@ int mode) } if( strncmp("utcTime",peek_head,sizeof("utcTime")-1) == 0){ (k->choiceId) = TIME_UTCTIME; - rc = GDecComponentUTCTime (b, (&k->a.utcTime), bytesDecoded, DEC_ALLOC_MODE_0 ); + rc = GDecComponentUTCTime (mem_op, b, (&k->a.utcTime), bytesDecoded, DEC_ALLOC_MODE_0 ); if ( rc != LDAP_SUCCESS ) return rc; (k->a.utcTime)->identifier.bv_val = peek_head; (k->a.utcTime)->identifier.bv_len = strLen; } else if( strncmp("generalizedTime",peek_head,sizeof("generalizedTime")-1) == 0){ (k->choiceId) = TIME_GENERALIZEDTIME; - rc = GDecComponentGeneralizedTime (b, (&k->a.generalizedTime), bytesDecoded, DEC_ALLOC_MODE_0 ); + rc = GDecComponentGeneralizedTime (mem_op, b, (&k->a.generalizedTime), bytesDecoded, DEC_ALLOC_MODE_0 ); if ( rc != LDAP_SUCCESS ) return rc; (k->a.generalizedTime)->identifier.bv_val = peek_head; (k->a.generalizedTime)->identifier.bv_len = strLen; @@ -433,19 +425,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentTime*) malloc( sizeof(ComponentTime) ); + *v = t = (ComponentTime*) CompAlloc( mem_op, sizeof(ComponentTime) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTime ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTime ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentTime ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTime; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -453,30 +445,6 @@ int mode) return LDAP_SUCCESS; } /* GDecTimeContent */ -void FreeComponentTime(ComponentTime *v) -{ - - if(v == NULL) - return; - switch(v->choiceId) - { - case TIME_UTCTIME: - FreeComponentUTCTime((v->a.utcTime)); - free ((v->a.utcTime)->comp_desc); - free ((v->a.utcTime)); - - break; - - case TIME_GENERALIZEDTIME: - FreeComponentGeneralizedTime((v->a.generalizedTime)); - free ((v->a.generalizedTime)->comp_desc); - free ((v->a.generalizedTime)); - - break; - - } -} /* FreeTime */ - int MatchingComponentExtension ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -499,16 +467,16 @@ MatchingComponentExtension ( char* oid, ComponentSyntaxInfo* csi_attr, Component } /* BMatchingComponentExtension */ void* -ExtractingComponentExtension ( ComponentReference* cr, ComponentExtension *comp ) +ExtractingComponentExtension ( void* mem_op, ComponentReference* cr, ComponentExtension *comp ) { - if ( ( strncmp(comp->extnID.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnID.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->extnID.identifier.bv_val && strncmp(comp->extnID.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnID.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->extnID; else return NULL; } - if ( ( strncmp(comp->extnValue.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnValue.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->extnValue.identifier.bv_val && strncmp(comp->extnValue.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnValue.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->extnValue; else @@ -519,6 +487,7 @@ ExtractingComponentExtension ( ComponentReference* cr, ComponentExtension *comp int BDecComponentExtension PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -535,7 +504,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -545,7 +514,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentOid (b, tagId1, elmtLen1, (&k->extnID), &totalElmtsLen1, mode); + BDecComponentOid (mem_op, b, tagId1, elmtLen1, (&k->extnID), &totalElmtsLen1, mode); (&k->extnID)->identifier.bv_val = (&k->extnID)->id_buf; (&k->extnID)->identifier.bv_len = strlen("extnID"); strcpy( (&k->extnID)->identifier.bv_val, "extnID"); @@ -560,7 +529,7 @@ int mode) (tagId1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentOcts (b, tagId1, elmtLen1, (&k->extnValue), &totalElmtsLen1, mode); + BDecComponentOcts (mem_op, b, tagId1, elmtLen1, (&k->extnValue), &totalElmtsLen1, mode); (&k->extnValue)->identifier.bv_val = (&k->extnValue)->id_buf; (&k->extnValue)->identifier.bv_len = strlen("extnValue"); strcpy( (&k->extnValue)->identifier.bv_val, "extnValue"); @@ -580,19 +549,19 @@ int mode) return -1; if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentExtension*) malloc( sizeof(ComponentExtension) ); + *v = t = (ComponentExtension*) CompAlloc( mem_op, sizeof(ComponentExtension) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtension ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtension ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentExtension ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -602,7 +571,8 @@ int mode) } /* BDecExtension*/ int -GDecComponentExtension PARAMS ((b, v, bytesDecoded, mode), +GDecComponentExtension PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentExtension **v _AND_ AsnLen *bytesDecoded _AND_ @@ -614,43 +584,48 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentOid (b, (&k->extnID), bytesDecoded, mode); + if ( strncmp( peek_head, "extnID", strlen("extnID") ) == 0 ) { + GDecComponentOid (mem_op, b, (&k->extnID), bytesDecoded, mode); (&k->extnID)->identifier.bv_val = peek_head; (&k->extnID)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentOcts (b, (&k->extnValue), bytesDecoded, mode); + } + if ( strncmp( peek_head, "extnValue", strlen("extnValue") ) == 0 ) { + GDecComponentOcts (mem_op, b, (&k->extnValue), bytesDecoded, mode); (&k->extnValue)->identifier.bv_val = peek_head; (&k->extnValue)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -659,19 +634,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentExtension*) malloc( sizeof(ComponentExtension) ); + *v = t = (ComponentExtension*) CompAlloc( mem_op, sizeof(ComponentExtension) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtension ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtension ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentExtension ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -679,19 +654,6 @@ int mode) return LDAP_SUCCESS; } /* GDecExtension*/ -void FreeComponentExtension(ComponentExtension *v) -{ - - if(v == NULL) - return; - FreeComponentOid((&v->extnID)); - free ((v->extnID).comp_desc); - - FreeComponentOcts((&v->extnValue)); - free ((v->extnValue).comp_desc); - -} /* FreeExtension */ - int MatchingComponentAttributeTypeAndValue ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -715,16 +677,16 @@ MatchingComponentAttributeTypeAndValue ( char* oid, ComponentSyntaxInfo* csi_att } /* BMatchingComponentAttributeTypeAndValue */ void* -ExtractingComponentAttributeTypeAndValue ( ComponentReference* cr, ComponentAttributeTypeAndValue *comp ) +ExtractingComponentAttributeTypeAndValue ( void* mem_op, ComponentReference* cr, ComponentAttributeTypeAndValue *comp ) { - if ( ( strncmp(comp->type.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->type.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->type.identifier.bv_val && strncmp(comp->type.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->type.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->type; else return NULL; } - if ( ( strncmp(comp->value.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->value.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->value.identifier.bv_val && strncmp(comp->value.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->value.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->value; else @@ -735,6 +697,7 @@ ExtractingComponentAttributeTypeAndValue ( ComponentReference* cr, ComponentAttr int BDecComponentAttributeTypeAndValue PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -751,7 +714,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -761,7 +724,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentAttributeType (b, tagId1, elmtLen1, (&k->type), &totalElmtsLen1, mode); + BDecComponentAttributeType (mem_op, b, tagId1, elmtLen1, (&k->type), &totalElmtsLen1, mode); (&k->type)->identifier.bv_val = (&k->type)->id_buf; (&k->type)->identifier.bv_len = strlen("type"); strcpy( (&k->type)->identifier.bv_val, "type"); @@ -773,7 +736,7 @@ int mode) { SetAnyTypeByComponentOid ((&k->value), (&k->type)); - BDecComponentAnyDefinedBy (b, (&k->value), &totalElmtsLen1, mode ); + BDecComponentAnyDefinedBy (mem_op,b, (&k->value), &totalElmtsLen1, mode ); (&k->value)->identifier.bv_val = (&k->value)->id_buf; (&k->value)->identifier.bv_len = strlen("value"); strcpy( (&k->value)->identifier.bv_val, "value"); @@ -790,19 +753,19 @@ int mode) return -1; if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentAttributeTypeAndValue*) malloc( sizeof(ComponentAttributeTypeAndValue) ); + *v = t = (ComponentAttributeTypeAndValue*) CompAlloc( mem_op, sizeof(ComponentAttributeTypeAndValue) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAttributeTypeAndValue ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAttributeTypeAndValue ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentAttributeTypeAndValue ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -812,7 +775,8 @@ int mode) } /* BDecAttributeTypeAndValue*/ int -GDecComponentAttributeTypeAndValue PARAMS ((b, v, bytesDecoded, mode), +GDecComponentAttributeTypeAndValue PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentAttributeTypeAndValue **v _AND_ AsnLen *bytesDecoded _AND_ @@ -824,44 +788,49 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentAttributeType (b, (&k->type), bytesDecoded, mode); + if ( strncmp( peek_head, "type", strlen("type") ) == 0 ) { + GDecComponentAttributeType (mem_op, b, (&k->type), bytesDecoded, mode); (&k->type)->identifier.bv_val = peek_head; (&k->type)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } + } + if ( strncmp( peek_head, "value", strlen("value") ) == 0 ) { SetAnyTypeByComponentOid ((&k->value), (&k->type)); - GDecComponentAnyDefinedBy (b, (&k->value), bytesDecoded, mode ); + GDecComponentAnyDefinedBy (mem_op, b, (&k->value), bytesDecoded, mode ); (&k->value)->identifier.bv_val = peek_head; (&k->value)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -870,19 +839,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentAttributeTypeAndValue*) malloc( sizeof(ComponentAttributeTypeAndValue) ); + *v = t = (ComponentAttributeTypeAndValue*) CompAlloc( mem_op, sizeof(ComponentAttributeTypeAndValue) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAttributeTypeAndValue ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAttributeTypeAndValue ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentAttributeTypeAndValue ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -890,19 +859,6 @@ int mode) return LDAP_SUCCESS; } /* GDecAttributeTypeAndValue*/ -void FreeComponentAttributeTypeAndValue(ComponentAttributeTypeAndValue *v) -{ - - if(v == NULL) - return; - FreeComponentAttributeType((&v->type)); - free ((v->type).comp_desc); - - FreeComponentAnyDefinedBy((&v->value)); - free ((v->value).comp_desc); - -} /* FreeAttributeTypeAndValue */ - int MatchingComponentValidity ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -925,23 +881,23 @@ MatchingComponentValidity ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentS } /* BMatchingComponentValidity */ void* -ExtractingComponentValidity ( ComponentReference* cr, ComponentValidity *comp ) +ExtractingComponentValidity ( void* mem_op, ComponentReference* cr, ComponentValidity *comp ) { - if ( ( strncmp(comp->notBefore->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notBefore->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->notBefore->identifier.bv_val && strncmp(comp->notBefore->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notBefore->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->notBefore; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentTime ( cr, comp->notBefore ); + return ExtractingComponentTime ( mem_op, cr, comp->notBefore ); } } - if ( ( strncmp(comp->notAfter->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notAfter->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->notAfter->identifier.bv_val && strncmp(comp->notAfter->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notAfter->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->notAfter; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentTime ( cr, comp->notAfter ); + return ExtractingComponentTime ( mem_op, cr, comp->notAfter ); } } return NULL; @@ -949,6 +905,7 @@ ExtractingComponentValidity ( ComponentReference* cr, ComponentValidity *comp ) int BDecComponentValidity PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -968,7 +925,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -981,7 +938,7 @@ int mode) (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentTime (b, tagId1, elmtLen1, (&k->notBefore), &totalElmtsLen1, mode); + BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->notBefore), &totalElmtsLen1, mode); (k->notBefore)->identifier.bv_val = (k->notBefore)->id_buf; (k->notBefore)->identifier.bv_len = strlen("notBefore"); strcpy( (k->notBefore)->identifier.bv_val, "notBefore"); @@ -998,7 +955,7 @@ int mode) (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentTime (b, tagId1, elmtLen1, (&k->notAfter), &totalElmtsLen1, mode); + BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->notAfter), &totalElmtsLen1, mode); (k->notAfter)->identifier.bv_val = (k->notAfter)->id_buf; (k->notAfter)->identifier.bv_len = strlen("notAfter"); strcpy( (k->notAfter)->identifier.bv_val, "notAfter"); @@ -1018,19 +975,19 @@ int mode) return -1; if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentValidity*) malloc( sizeof(ComponentValidity) ); + *v = t = (ComponentValidity*) CompAlloc( mem_op, sizeof(ComponentValidity) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentValidity ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentValidity ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentValidity ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1040,7 +997,8 @@ int mode) } /* BDecValidity*/ int -GDecComponentValidity PARAMS ((b, v, bytesDecoded, mode), +GDecComponentValidity PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentValidity **v _AND_ AsnLen *bytesDecoded _AND_ @@ -1052,43 +1010,48 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentTime (b, (&k->notBefore), bytesDecoded, mode); + if ( strncmp( peek_head, "notBefore", strlen("notBefore") ) == 0 ) { + GDecComponentTime (mem_op, b, (&k->notBefore), bytesDecoded, mode); ( k->notBefore)->identifier.bv_val = peek_head; ( k->notBefore)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentTime (b, (&k->notAfter), bytesDecoded, mode); + } + if ( strncmp( peek_head, "notAfter", strlen("notAfter") ) == 0 ) { + GDecComponentTime (mem_op, b, (&k->notAfter), bytesDecoded, mode); ( k->notAfter)->identifier.bv_val = peek_head; ( k->notAfter)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -1097,19 +1060,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentValidity*) malloc( sizeof(ComponentValidity) ); + *v = t = (ComponentValidity*) CompAlloc( mem_op, sizeof(ComponentValidity) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentValidity ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentValidity ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentValidity ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1117,21 +1080,6 @@ int mode) return LDAP_SUCCESS; } /* GDecValidity*/ -void FreeComponentValidity(ComponentValidity *v) -{ - - if(v == NULL) - return; - FreeComponentTime((v->notBefore)); - free ((v->notBefore)->comp_desc); - free ((v->notBefore)); - - FreeComponentTime((v->notAfter)); - free ((v->notAfter)->comp_desc); - free ((v->notAfter)); - -} /* FreeValidity */ - int MatchingComponentSubjectPublicKeyInfo ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -1154,18 +1102,18 @@ MatchingComponentSubjectPublicKeyInfo ( char* oid, ComponentSyntaxInfo* csi_attr } /* BMatchingComponentSubjectPublicKeyInfo */ void* -ExtractingComponentSubjectPublicKeyInfo ( ComponentReference* cr, ComponentSubjectPublicKeyInfo *comp ) +ExtractingComponentSubjectPublicKeyInfo ( void* mem_op, ComponentReference* cr, ComponentSubjectPublicKeyInfo *comp ) { - if ( ( strncmp(comp->algorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->algorithm->identifier.bv_val && strncmp(comp->algorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->algorithm; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentAlgorithmIdentifier ( cr, comp->algorithm ); + return ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->algorithm ); } } - if ( ( strncmp(comp->subjectPublicKey.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKey.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->subjectPublicKey.identifier.bv_val && strncmp(comp->subjectPublicKey.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKey.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->subjectPublicKey; else @@ -1176,6 +1124,7 @@ ExtractingComponentSubjectPublicKeyInfo ( ComponentReference* cr, ComponentSubje int BDecComponentSubjectPublicKeyInfo PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -1192,7 +1141,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -1202,7 +1151,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentAlgorithmIdentifier (b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode); + BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode); (k->algorithm)->identifier.bv_val = (k->algorithm)->id_buf; (k->algorithm)->identifier.bv_len = strlen("algorithm"); strcpy( (k->algorithm)->identifier.bv_val, "algorithm"); @@ -1217,7 +1166,7 @@ int mode) (tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentBits (b, tagId1, elmtLen1, (&k->subjectPublicKey), &totalElmtsLen1, mode); + BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKey), &totalElmtsLen1, mode); (&k->subjectPublicKey)->identifier.bv_val = (&k->subjectPublicKey)->id_buf; (&k->subjectPublicKey)->identifier.bv_len = strlen("subjectPublicKey"); strcpy( (&k->subjectPublicKey)->identifier.bv_val, "subjectPublicKey"); @@ -1237,19 +1186,19 @@ int mode) return -1; if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentSubjectPublicKeyInfo*) malloc( sizeof(ComponentSubjectPublicKeyInfo) ); + *v = t = (ComponentSubjectPublicKeyInfo*) CompAlloc( mem_op, sizeof(ComponentSubjectPublicKeyInfo) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentSubjectPublicKeyInfo ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentSubjectPublicKeyInfo ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentSubjectPublicKeyInfo ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1259,7 +1208,8 @@ int mode) } /* BDecSubjectPublicKeyInfo*/ int -GDecComponentSubjectPublicKeyInfo PARAMS ((b, v, bytesDecoded, mode), +GDecComponentSubjectPublicKeyInfo PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentSubjectPublicKeyInfo **v _AND_ AsnLen *bytesDecoded _AND_ @@ -1271,43 +1221,48 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentAlgorithmIdentifier (b, (&k->algorithm), bytesDecoded, mode); + if ( strncmp( peek_head, "algorithm", strlen("algorithm") ) == 0 ) { + GDecComponentAlgorithmIdentifier (mem_op, b, (&k->algorithm), bytesDecoded, mode); ( k->algorithm)->identifier.bv_val = peek_head; ( k->algorithm)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentBits (b, (&k->subjectPublicKey), bytesDecoded, mode); + } + if ( strncmp( peek_head, "subjectPublicKey", strlen("subjectPublicKey") ) == 0 ) { + GDecComponentBits (mem_op, b, (&k->subjectPublicKey), bytesDecoded, mode); (&k->subjectPublicKey)->identifier.bv_val = peek_head; (&k->subjectPublicKey)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -1316,19 +1271,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentSubjectPublicKeyInfo*) malloc( sizeof(ComponentSubjectPublicKeyInfo) ); + *v = t = (ComponentSubjectPublicKeyInfo*) CompAlloc( mem_op, sizeof(ComponentSubjectPublicKeyInfo) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentSubjectPublicKeyInfo ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentSubjectPublicKeyInfo ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentSubjectPublicKeyInfo ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1336,20 +1291,6 @@ int mode) return LDAP_SUCCESS; } /* GDecSubjectPublicKeyInfo*/ -void FreeComponentSubjectPublicKeyInfo(ComponentSubjectPublicKeyInfo *v) -{ - - if(v == NULL) - return; - FreeComponentAlgorithmIdentifier((v->algorithm)); - free ((v->algorithm)->comp_desc); - free ((v->algorithm)); - - FreeComponentBits((&v->subjectPublicKey)); - free ((v->subjectPublicKey).comp_desc); - -} /* FreeSubjectPublicKeyInfo */ - int MatchingComponentExtensions ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -1373,6 +1314,8 @@ MatchingComponentExtensions ( char* oid, ComponentSyntaxInfo* csi_attr, Componen } } /* end of for */ + AsnListFirst( v1 ); + AsnListFirst( v2 ); if( (!component1 && component2) || (component1 && !component2)) return LDAP_COMPARE_FALSE; else @@ -1380,7 +1323,7 @@ MatchingComponentExtensions ( char* oid, ComponentSyntaxInfo* csi_attr, Componen } /* BMatchingComponentExtensionsContent */ void* -ExtractingComponentExtensions ( ComponentReference* cr, ComponentExtensions *comp ) +ExtractingComponentExtensions ( void* mem_op, ComponentReference* cr, ComponentExtensions *comp ) { int count = 0; int total; @@ -1398,8 +1341,7 @@ ExtractingComponentExtensions ( ComponentReference* cr, ComponentExtensions *com return component; else { cr->cr_curr = cr->cr_curr->ci_next; - return - ExtractingComponentExtension ( cr, component ); + return ExtractingComponentExtension ( mem_op, cr, component ); } } } @@ -1414,16 +1356,16 @@ ExtractingComponentExtensions ( ComponentReference* cr, ComponentExtensions *com return component; else { cr->cr_curr = cr->cr_curr->ci_next; - return - ExtractingComponentExtension ( cr, component ); + return ExtractingComponentExtension ( mem_op, cr, component ); } } } break; case LDAP_COMPREF_ALL : return comp; - k = (ComponentInt*)malloc(sizeof(ComponentInt)); - k->comp_desc = malloc( sizeof( ComponentDesc ) ); + case LDAP_COMPREF_COUNT : + k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt)); + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); k->comp_desc->cd_tag = NULL; k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; @@ -1440,6 +1382,7 @@ ExtractingComponentExtensions ( ComponentReference* cr, ComponentExtensions *com int BDecComponentExtensions PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -1456,7 +1399,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -1476,7 +1419,7 @@ int mode) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); tmpVar = (ComponentExtension**) AsnListAppend (&k->comp_list); - BDecComponentExtension (b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); + BDecComponentExtension (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); } /* end of tag check if */ else /* wrong tag */ { @@ -1486,19 +1429,19 @@ int mode) } /* end of for */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentExtensions*) malloc( sizeof(ComponentExtensions) ); + *v = t = (ComponentExtensions*) CompAlloc( mem_op, sizeof(ComponentExtensions) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtensions ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtensions ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentExtensions ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1508,7 +1451,8 @@ int mode) } /* BDecExtensionsContent */ int -GDecComponentExtensions PARAMS ((b, v, bytesDecoded, mode), +GDecComponentExtensions PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentExtensions **v _AND_ AsnLen *bytesDecoded _AND_ @@ -1521,14 +1465,14 @@ int mode) int ElmtsLen1; if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; AsnListInit( &k->comp_list, sizeof( ComponentExtension ) ); - bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_PEEK)) ){ + *bytesDecoded = 0; + if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){ Asn1Error("Error during Reading { in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -1540,7 +1484,7 @@ int mode) for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) { ComponentExtension **tmpVar; - if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){ Asn1Error("Error during Reading{ in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -1553,23 +1497,23 @@ int mode) Asn1Error("Error during Reading{ in encoding"); return LDAP_PROTOCOL_ERROR; } - GDecComponentExtension (b, tmpVar, bytesDecoded, mode); + GDecComponentExtension (mem_op, b, tmpVar, bytesDecoded, mode); } /* end of for */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentExtensions*) malloc( sizeof(ComponentExtensions) ); + *v = t = (ComponentExtensions*) CompAlloc( mem_op, sizeof(ComponentExtensions) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtensions ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtensions ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentExtensions ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1577,24 +1521,6 @@ int mode) return LDAP_SUCCESS; } /* GDecExtensionsContent */ -void FreeComponentExtensions(ComponentExtensions *v) -{ - - AsnListNode *l; - AsnListNode *tmp; - if(v == NULL) - return; - for (l = FIRST_LIST_NODE (&v->comp_list); l != NULL; ) - { - FreeComponentExtension ((l->data)); - tmp = l->next; - free (((ComponentSyntaxInfo*)l->data)->csi_comp_desc); - free (l->data); - free (l); - l = tmp; - } -} /* FreeExtensions */ - int MatchingComponentRelativeDistinguishedName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -1630,13 +1556,13 @@ MatchingComponentRelativeDistinguishedName ( char* oid, ComponentSyntaxInfo* csi else rc = LDAP_COMPARE_FALSE; AsnListMove( &t_list, v2 ); - AsnListFirst(v1); - AsnListFirst(v2); + AsnListFirst( v1 ); + AsnListFirst( v2 ); return rc; } /* BMatchingComponentRelativeDistinguishedNameContent */ void* -ExtractingComponentRelativeDistinguishedName ( ComponentReference* cr, ComponentRelativeDistinguishedName *comp ) +ExtractingComponentRelativeDistinguishedName ( void* mem_op, ComponentReference* cr, ComponentRelativeDistinguishedName *comp ) { int count = 0; int total; @@ -1654,8 +1580,7 @@ ExtractingComponentRelativeDistinguishedName ( ComponentReference* cr, Component return component; else { cr->cr_curr = cr->cr_curr->ci_next; - return - ExtractingComponentAttributeTypeAndValue ( cr, component ); + return ExtractingComponentAttributeTypeAndValue ( mem_op, cr, component ); } } } @@ -1670,16 +1595,16 @@ ExtractingComponentRelativeDistinguishedName ( ComponentReference* cr, Component return component; else { cr->cr_curr = cr->cr_curr->ci_next; - return - ExtractingComponentAttributeTypeAndValue ( cr, component ); + return ExtractingComponentAttributeTypeAndValue ( mem_op, cr, component ); } } } break; case LDAP_COMPREF_ALL : return comp; - k = (ComponentInt*)malloc(sizeof(ComponentInt)); - k->comp_desc = malloc( sizeof( ComponentDesc ) ); + case LDAP_COMPREF_COUNT : + k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt)); + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); k->comp_desc->cd_tag = NULL; k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; @@ -1696,6 +1621,7 @@ ExtractingComponentRelativeDistinguishedName ( ComponentReference* cr, Component int BDecComponentRelativeDistinguishedName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -1712,7 +1638,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -1732,7 +1658,7 @@ int mode) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); tmpVar = (ComponentAttributeTypeAndValue**) AsnListAppend (&k->comp_list); - BDecComponentAttributeTypeAndValue (b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); + BDecComponentAttributeTypeAndValue (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); } /* end of tag check if */ else /* wrong tag */ { @@ -1742,19 +1668,19 @@ int mode) } /* end of for */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentRelativeDistinguishedName*) malloc( sizeof(ComponentRelativeDistinguishedName) ); + *v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeDistinguishedName ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1764,7 +1690,8 @@ int mode) } /* BDecRelativeDistinguishedNameContent */ int -GDecComponentRelativeDistinguishedName PARAMS ((b, v, bytesDecoded, mode), +GDecComponentRelativeDistinguishedName PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentRelativeDistinguishedName **v _AND_ AsnLen *bytesDecoded _AND_ @@ -1777,14 +1704,14 @@ int mode) int ElmtsLen1; if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; AsnListInit( &k->comp_list, sizeof( ComponentAttributeTypeAndValue ) ); *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_PEEK)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){ Asn1Error("Error during Reading { in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -1796,7 +1723,7 @@ int mode) for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) { ComponentAttributeTypeAndValue **tmpVar; - if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){ Asn1Error("Error during Reading{ in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -1809,23 +1736,23 @@ int mode) Asn1Error("Error during Reading{ in encoding"); return LDAP_PROTOCOL_ERROR; } - GDecComponentAttributeTypeAndValue (b, tmpVar, bytesDecoded, mode); + GDecComponentAttributeTypeAndValue (mem_op, b, tmpVar, bytesDecoded, mode); } /* end of for */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentRelativeDistinguishedName*) malloc( sizeof(ComponentRelativeDistinguishedName) ); + *v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeDistinguishedName ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -1833,24 +1760,6 @@ int mode) return LDAP_SUCCESS; } /* GDecRelativeDistinguishedNameContent */ -void FreeComponentRelativeDistinguishedName(ComponentRelativeDistinguishedName *v) -{ - - AsnListNode *l; - AsnListNode *tmp; - if(v == NULL) - return; - for (l = FIRST_LIST_NODE (&v->comp_list); l != NULL; ) - { - FreeComponentAttributeTypeAndValue ((l->data)); - tmp = l->next; - free (((ComponentSyntaxInfo*)l->data)->csi_comp_desc); - free (l->data); - free (l); - l = tmp; - } -} /* FreeRelativeDistinguishedName */ - int MatchingComponentRDNSequence ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -1874,9 +1783,8 @@ MatchingComponentRDNSequence ( char* oid, ComponentSyntaxInfo* csi_attr, Compone } } /* end of for */ - AsnListFirst(v1); - AsnListFirst(v2); - + AsnListFirst( v1 ); + AsnListFirst( v2 ); if( (!component1 && component2) || (component1 && !component2)) return LDAP_COMPARE_FALSE; else @@ -1884,7 +1792,7 @@ MatchingComponentRDNSequence ( char* oid, ComponentSyntaxInfo* csi_attr, Compone } /* BMatchingComponentRDNSequenceContent */ void* -ExtractingComponentRDNSequence ( ComponentReference* cr, ComponentRDNSequence *comp ) +ExtractingComponentRDNSequence ( void* mem_op, ComponentReference* cr, ComponentRDNSequence *comp ) { int count = 0; int total; @@ -1902,8 +1810,7 @@ ExtractingComponentRDNSequence ( ComponentReference* cr, ComponentRDNSequence *c return component; else { cr->cr_curr = cr->cr_curr->ci_next; - return - ExtractingComponentRelativeDistinguishedName ( cr, component ); + return ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component ); } } } @@ -1918,16 +1825,16 @@ ExtractingComponentRDNSequence ( ComponentReference* cr, ComponentRDNSequence *c return component; else { cr->cr_curr = cr->cr_curr->ci_next; - return - ExtractingComponentRelativeDistinguishedName ( cr, component ); + return ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component ); } } } break; case LDAP_COMPREF_ALL : return comp; - k = (ComponentInt*)malloc(sizeof(ComponentInt)); - k->comp_desc = malloc( sizeof( ComponentDesc ) ); + case LDAP_COMPREF_COUNT : + k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt)); + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); k->comp_desc->cd_tag = NULL; k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; @@ -1944,6 +1851,7 @@ ExtractingComponentRDNSequence ( ComponentReference* cr, ComponentRDNSequence *c int BDecComponentRDNSequence PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -1960,7 +1868,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -1980,7 +1888,7 @@ int mode) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); tmpVar = (ComponentRelativeDistinguishedName**) AsnListAppend (&k->comp_list); - BDecComponentRelativeDistinguishedName (b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); + BDecComponentRelativeDistinguishedName (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); } /* end of tag check if */ else /* wrong tag */ { @@ -1990,19 +1898,19 @@ int mode) } /* end of for */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentRDNSequence*) malloc( sizeof(ComponentRDNSequence) ); + *v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentRDNSequence ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -2012,7 +1920,8 @@ int mode) } /* BDecRDNSequenceContent */ int -GDecComponentRDNSequence PARAMS ((b, v, bytesDecoded, mode), +GDecComponentRDNSequence PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentRDNSequence **v _AND_ AsnLen *bytesDecoded _AND_ @@ -2025,14 +1934,14 @@ int mode) int ElmtsLen1; if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; AsnListInit( &k->comp_list, sizeof( ComponentRelativeDistinguishedName ) ); *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_PEEK)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){ Asn1Error("Error during Reading { in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -2044,7 +1953,7 @@ int mode) for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) { ComponentRelativeDistinguishedName **tmpVar; - if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){ Asn1Error("Error during Reading{ in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -2057,23 +1966,23 @@ int mode) Asn1Error("Error during Reading{ in encoding"); return LDAP_PROTOCOL_ERROR; } - GDecComponentRelativeDistinguishedName (b, tmpVar, bytesDecoded, mode); + GDecComponentRelativeDistinguishedName (mem_op, b, tmpVar, bytesDecoded, mode); } /* end of for */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentRDNSequence*) malloc( sizeof(ComponentRDNSequence) ); + *v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentRDNSequence ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -2081,24 +1990,6 @@ int mode) return LDAP_SUCCESS; } /* GDecRDNSequenceContent */ -void FreeComponentRDNSequence(ComponentRDNSequence *v) -{ - - AsnListNode *l; - AsnListNode *tmp; - if(v == NULL) - return; - for (l = FIRST_LIST_NODE (&v->comp_list); l != NULL; ) - { - FreeComponentRelativeDistinguishedName ((l->data)); - tmp = l->next; - free (((ComponentSyntaxInfo*)l->data)->csi_comp_desc); - free (l->data); - free (l); - l = tmp; - } -} /* FreeRDNSequence */ - int MatchingComponentName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -2128,18 +2019,18 @@ MatchingComponentName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSynta } /* BMatchingComponentNameContent */ void* -ExtractingComponentName ( ComponentReference* cr, ComponentName *comp ) +ExtractingComponentName ( void* mem_op, ComponentReference* cr, ComponentName *comp ) { if( (comp->choiceId) == NAME_RDNSEQUENCE && - ((strncmp(comp->a.rdnSequence->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || + (( comp->a.rdnSequence->identifier.bv_val && strncmp(comp->a.rdnSequence->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || ( strncmp(comp->a.rdnSequence->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) { if ( cr->cr_curr->ci_next == NULL ) return (comp->a.rdnSequence); else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentRDNSequence ( cr, (comp->a.rdnSequence) ); + return ExtractingComponentRDNSequence ( mem_op, cr, (comp->a.rdnSequence) ); }; } return NULL; @@ -2147,6 +2038,7 @@ ExtractingComponentName ( ComponentReference* cr, ComponentName *comp ) int BDecComponentName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -2163,7 +2055,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -2172,7 +2064,7 @@ int mode) { case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE): (k->choiceId) = NAME_RDNSEQUENCE; - BDecComponentRDNSequence (b, tagId0, elmtLen0, (&k->a.rdnSequence), &totalElmtsLen1, mode); + BDecComponentRDNSequence (mem_op, b, tagId0, elmtLen0, (&k->a.rdnSequence), &totalElmtsLen1, mode); (k->a.rdnSequence)->identifier.bv_val = (k->a.rdnSequence)->id_buf; (k->a.rdnSequence)->identifier.bv_len = strlen("rdnSequence"); strcpy( (k->a.rdnSequence)->identifier.bv_val, "rdnSequence"); @@ -2184,19 +2076,19 @@ int mode) break; } /* end switch */ if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentName*) malloc( sizeof(ComponentName) ); + *v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentName ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -2206,7 +2098,8 @@ int mode) } /* BDecNameContent */ int -GDecComponentName PARAMS ((b, v, bytesDecoded, mode), +GDecComponentName PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentName **v _AND_ AsnLen *bytesDecoded _AND_ @@ -2218,16 +2111,16 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen2 = LocateNextGSERToken(b,&peek_head2,GSER_NO_COPY)) ){ + if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } @@ -2237,7 +2130,7 @@ int mode) } if( strncmp("rdnSequence",peek_head,sizeof("rdnSequence")-1) == 0){ (k->choiceId) = NAME_RDNSEQUENCE; - rc = GDecComponentRDNSequence (b, (&k->a.rdnSequence), bytesDecoded, mode); + rc = GDecComponentRDNSequence (mem_op, b, (&k->a.rdnSequence), bytesDecoded, mode); if ( rc != LDAP_SUCCESS ) return rc; (k->a.rdnSequence)->identifier.bv_val = peek_head; (k->a.rdnSequence)->identifier.bv_len = strLen; @@ -2247,19 +2140,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentName*) malloc( sizeof(ComponentName) ); + *v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentName ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -2267,23 +2160,6 @@ int mode) return LDAP_SUCCESS; } /* GDecNameContent */ -void FreeComponentName(ComponentName *v) -{ - - if(v == NULL) - return; - switch(v->choiceId) - { - case NAME_RDNSEQUENCE: - FreeComponentRDNSequence((v->a.rdnSequence)); - free ((v->a.rdnSequence)->comp_desc); - free ((v->a.rdnSequence)); - - break; - - } -} /* FreeName */ - int MatchingComponentTBSCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -2323,88 +2199,90 @@ MatchingComponentTBSCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, Comp rc = MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->subjectUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->subjectUniqueIdentifier ); if ( rc != LDAP_COMPARE_TRUE ) return rc; + if(COMPONENTNOT_NULL( ((ComponentTBSCertificate*)csi_attr)->extensions ) ) { rc = MatchingComponentExtensions ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->extensions, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->extensions ); if ( rc != LDAP_COMPARE_TRUE ) return rc; + } return LDAP_COMPARE_TRUE; } /* BMatchingComponentTBSCertificate */ void* -ExtractingComponentTBSCertificate ( ComponentReference* cr, ComponentTBSCertificate *comp ) +ExtractingComponentTBSCertificate ( void* mem_op, ComponentReference* cr, ComponentTBSCertificate *comp ) { - if ( ( strncmp(comp->version->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->version->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->version->identifier.bv_val && strncmp(comp->version->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->version->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->version; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentVersion ( cr, comp->version ); + return ExtractingComponentVersion ( mem_op, cr, comp->version ); } } - if ( ( strncmp(comp->serialNumber.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->serialNumber.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->serialNumber.identifier.bv_val && strncmp(comp->serialNumber.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->serialNumber.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->serialNumber; else return NULL; } - if ( ( strncmp(comp->signature->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->signature->identifier.bv_val && strncmp(comp->signature->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->signature; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentAlgorithmIdentifier ( cr, comp->signature ); + return ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signature ); } } - if ( ( strncmp(comp->issuer->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuer->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->issuer->identifier.bv_val && strncmp(comp->issuer->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuer->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->issuer; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentName ( cr, comp->issuer ); + return ExtractingComponentName ( mem_op, cr, comp->issuer ); } } - if ( ( strncmp(comp->validity->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->validity->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->validity->identifier.bv_val && strncmp(comp->validity->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->validity->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->validity; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentValidity ( cr, comp->validity ); + return ExtractingComponentValidity ( mem_op, cr, comp->validity ); } } - if ( ( strncmp(comp->subject->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subject->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->subject->identifier.bv_val && strncmp(comp->subject->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subject->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->subject; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentName ( cr, comp->subject ); + return ExtractingComponentName ( mem_op, cr, comp->subject ); } } - if ( ( strncmp(comp->subjectPublicKeyInfo->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKeyInfo->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->subjectPublicKeyInfo->identifier.bv_val && strncmp(comp->subjectPublicKeyInfo->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKeyInfo->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->subjectPublicKeyInfo; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentSubjectPublicKeyInfo ( cr, comp->subjectPublicKeyInfo ); + return ExtractingComponentSubjectPublicKeyInfo ( mem_op, cr, comp->subjectPublicKeyInfo ); } } - if ( ( strncmp(comp->issuerUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuerUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->issuerUniqueIdentifier.identifier.bv_val && strncmp(comp->issuerUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuerUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->issuerUniqueIdentifier; else return NULL; } - if ( ( strncmp(comp->subjectUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->subjectUniqueIdentifier.identifier.bv_val && strncmp(comp->subjectUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->subjectUniqueIdentifier; else return NULL; } - if ( ( strncmp(comp->extensions->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extensions->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->extensions->identifier.bv_val && strncmp(comp->extensions->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extensions->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->extensions; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentExtensions ( cr, comp->extensions ); + return ExtractingComponentExtensions ( mem_op, cr, comp->extensions ); } } return NULL; @@ -2412,6 +2290,7 @@ ExtractingComponentTBSCertificate ( ComponentReference* cr, ComponentTBSCertific int BDecComponentTBSCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -2431,7 +2310,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -2450,7 +2329,7 @@ int mode) } elmtLen2 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentVersion (b, tagId2, elmtLen2, (&k->version), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); + BDecComponentVersion (mem_op, b, tagId2, elmtLen2, (&k->version), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); (k->version)->identifier.bv_val = (k->version)->id_buf; (k->version)->identifier.bv_len = strlen("version"); strcpy( (k->version)->identifier.bv_val, "version"); @@ -2463,7 +2342,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentCertificateSerialNumber (b, tagId1, elmtLen1, (&k->serialNumber), &totalElmtsLen1, mode); + BDecComponentCertificateSerialNumber (mem_op, b, tagId1, elmtLen1, (&k->serialNumber), &totalElmtsLen1, mode); (&k->serialNumber)->identifier.bv_val = (&k->serialNumber)->id_buf; (&k->serialNumber)->identifier.bv_len = strlen("serialNumber"); strcpy( (&k->serialNumber)->identifier.bv_val, "serialNumber"); @@ -2477,7 +2356,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentAlgorithmIdentifier (b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode); + BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode); (k->signature)->identifier.bv_val = (k->signature)->id_buf; (k->signature)->identifier.bv_len = strlen("signature"); strcpy( (k->signature)->identifier.bv_val, "signature"); @@ -2491,7 +2370,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentName (b, tagId1, elmtLen1, (&k->issuer), &totalElmtsLen1, mode); + BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->issuer), &totalElmtsLen1, mode); (k->issuer)->identifier.bv_val = (k->issuer)->id_buf; (k->issuer)->identifier.bv_len = strlen("issuer"); strcpy( (k->issuer)->identifier.bv_val, "issuer"); @@ -2505,7 +2384,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentValidity (b, tagId1, elmtLen1, (&k->validity), &totalElmtsLen1, mode); + BDecComponentValidity (mem_op, b, tagId1, elmtLen1, (&k->validity), &totalElmtsLen1, mode); (k->validity)->identifier.bv_val = (k->validity)->id_buf; (k->validity)->identifier.bv_len = strlen("validity"); strcpy( (k->validity)->identifier.bv_val, "validity"); @@ -2519,7 +2398,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentName (b, tagId1, elmtLen1, (&k->subject), &totalElmtsLen1, mode); + BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->subject), &totalElmtsLen1, mode); (k->subject)->identifier.bv_val = (k->subject)->id_buf; (k->subject)->identifier.bv_len = strlen("subject"); strcpy( (k->subject)->identifier.bv_val, "subject"); @@ -2533,7 +2412,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentSubjectPublicKeyInfo (b, tagId1, elmtLen1, (&k->subjectPublicKeyInfo), &totalElmtsLen1, mode); + BDecComponentSubjectPublicKeyInfo (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKeyInfo), &totalElmtsLen1, mode); (k->subjectPublicKeyInfo)->identifier.bv_val = (k->subjectPublicKeyInfo)->id_buf; (k->subjectPublicKeyInfo)->identifier.bv_len = strlen("subjectPublicKeyInfo"); strcpy( (k->subjectPublicKeyInfo)->identifier.bv_val, "subjectPublicKeyInfo"); @@ -2559,7 +2438,7 @@ int mode) (tagId1 == MAKE_TAG_ID (CNTX, CONS, 1)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentUniqueIdentifier (b, tagId1, elmtLen1, (&k->issuerUniqueIdentifier), &totalElmtsLen1, mode); + BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->issuerUniqueIdentifier), &totalElmtsLen1, mode); (&k->issuerUniqueIdentifier)->identifier.bv_val = (&k->issuerUniqueIdentifier)->id_buf; (&k->issuerUniqueIdentifier)->identifier.bv_len = strlen("issuerUniqueIdentifier"); strcpy( (&k->issuerUniqueIdentifier)->identifier.bv_val, "issuerUniqueIdentifier"); @@ -2582,7 +2461,7 @@ int mode) (tagId1 == MAKE_TAG_ID (CNTX, CONS, 2)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentUniqueIdentifier (b, tagId1, elmtLen1, (&k->subjectUniqueIdentifier), &totalElmtsLen1, mode); + BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->subjectUniqueIdentifier), &totalElmtsLen1, mode); (&k->subjectUniqueIdentifier)->identifier.bv_val = (&k->subjectUniqueIdentifier)->id_buf; (&k->subjectUniqueIdentifier)->identifier.bv_len = strlen("subjectUniqueIdentifier"); strcpy( (&k->subjectUniqueIdentifier)->identifier.bv_val, "subjectUniqueIdentifier"); @@ -2613,7 +2492,7 @@ int mode) } elmtLen2 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentExtensions (b, tagId2, elmtLen2, (&k->extensions), &totalElmtsLen1, mode); + BDecComponentExtensions (mem_op, b, tagId2, elmtLen2, (&k->extensions), &totalElmtsLen1, mode); (k->extensions)->identifier.bv_val = (k->extensions)->id_buf; (k->extensions)->identifier.bv_len = strlen("extensions"); strcpy( (k->extensions)->identifier.bv_val, "extensions"); @@ -2631,20 +2510,24 @@ int mode) if (!seqDone) return -1; + if(!COMPONENTNOT_NULL ((k->version))) + { + (k->version)->value = 0; + } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentTBSCertificate*) malloc( sizeof(ComponentTBSCertificate) ); + *v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentTBSCertificate ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -2654,7 +2537,8 @@ int mode) } /* BDecTBSCertificate*/ int -GDecComponentTBSCertificate PARAMS ((b, v, bytesDecoded, mode), +GDecComponentTBSCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentTBSCertificate **v _AND_ AsnLen *bytesDecoded _AND_ @@ -2666,163 +2550,187 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentVersion (b, (&k->version), bytesDecoded, DEC_ALLOC_MODE_0 ); + if ( strncmp( peek_head, "version", strlen("version") ) == 0 ) { + GDecComponentVersion (mem_op, b, (&k->version), bytesDecoded, DEC_ALLOC_MODE_0 ); ( k->version)->identifier.bv_val = peek_head; ( k->version)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentCertificateSerialNumber (b, (&k->serialNumber), bytesDecoded, mode); + } + else { + (k->version)->value = 0; + } + if ( strncmp( peek_head, "serialNumber", strlen("serialNumber") ) == 0 ) { + GDecComponentCertificateSerialNumber (mem_op, b, (&k->serialNumber), bytesDecoded, mode); (&k->serialNumber)->identifier.bv_val = peek_head; (&k->serialNumber)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentAlgorithmIdentifier (b, (&k->signature), bytesDecoded, mode); + } + if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) { + GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signature), bytesDecoded, mode); ( k->signature)->identifier.bv_val = peek_head; ( k->signature)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentName (b, (&k->issuer), bytesDecoded, mode); + } + if ( strncmp( peek_head, "issuer", strlen("issuer") ) == 0 ) { + GDecComponentName (mem_op, b, (&k->issuer), bytesDecoded, mode); ( k->issuer)->identifier.bv_val = peek_head; ( k->issuer)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentValidity (b, (&k->validity), bytesDecoded, mode); + } + if ( strncmp( peek_head, "validity", strlen("validity") ) == 0 ) { + GDecComponentValidity (mem_op, b, (&k->validity), bytesDecoded, mode); ( k->validity)->identifier.bv_val = peek_head; ( k->validity)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentName (b, (&k->subject), bytesDecoded, mode); + } + if ( strncmp( peek_head, "subject", strlen("subject") ) == 0 ) { + GDecComponentName (mem_op, b, (&k->subject), bytesDecoded, mode); ( k->subject)->identifier.bv_val = peek_head; ( k->subject)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentSubjectPublicKeyInfo (b, (&k->subjectPublicKeyInfo), bytesDecoded, mode); + } + if ( strncmp( peek_head, "subjectPublicKeyInfo", strlen("subjectPublicKeyInfo") ) == 0 ) { + GDecComponentSubjectPublicKeyInfo (mem_op, b, (&k->subjectPublicKeyInfo), bytesDecoded, mode); ( k->subjectPublicKeyInfo)->identifier.bv_val = peek_head; ( k->subjectPublicKeyInfo)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentUniqueIdentifier (b, (&k->issuerUniqueIdentifier), bytesDecoded, mode); + } + if ( strncmp( peek_head, "issuerUniqueIdentifier", strlen("issuerUniqueIdentifier") ) == 0 ) { + GDecComponentUniqueIdentifier (mem_op, b, (&k->issuerUniqueIdentifier), bytesDecoded, mode); (&k->issuerUniqueIdentifier)->identifier.bv_val = peek_head; (&k->issuerUniqueIdentifier)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentUniqueIdentifier (b, (&k->subjectUniqueIdentifier), bytesDecoded, mode); + } + if ( strncmp( peek_head, "subjectUniqueIdentifier", strlen("subjectUniqueIdentifier") ) == 0 ) { + GDecComponentUniqueIdentifier (mem_op, b, (&k->subjectUniqueIdentifier), bytesDecoded, mode); (&k->subjectUniqueIdentifier)->identifier.bv_val = peek_head; (&k->subjectUniqueIdentifier)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentExtensions (b, (&k->extensions), bytesDecoded, mode); + } + if ( strncmp( peek_head, "extensions", strlen("extensions") ) == 0 ) { + GDecComponentExtensions (mem_op, b, (&k->extensions), bytesDecoded, mode); ( k->extensions)->identifier.bv_val = peek_head; ( k->extensions)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -2831,19 +2739,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentTBSCertificate*) malloc( sizeof(ComponentTBSCertificate) ); + *v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentTBSCertificate ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -2851,66 +2759,6 @@ int mode) return LDAP_SUCCESS; } /* GDecTBSCertificate*/ -void FreeComponentTBSCertificate(ComponentTBSCertificate *v) -{ - - if(v == NULL) - return; - if(COMPONENTNOT_NULL ((v->version))) - { - FreeComponentVersion((v->version)); - free ((v->version)->comp_desc); - free ((v->version)); - - } - - FreeComponentCertificateSerialNumber((&v->serialNumber)); - free ((v->serialNumber).comp_desc); - - FreeComponentAlgorithmIdentifier((v->signature)); - free ((v->signature)->comp_desc); - free ((v->signature)); - - FreeComponentName((v->issuer)); - free ((v->issuer)->comp_desc); - free ((v->issuer)); - - FreeComponentValidity((v->validity)); - free ((v->validity)->comp_desc); - free ((v->validity)); - - FreeComponentName((v->subject)); - free ((v->subject)->comp_desc); - free ((v->subject)); - - FreeComponentSubjectPublicKeyInfo((v->subjectPublicKeyInfo)); - free ((v->subjectPublicKeyInfo)->comp_desc); - free ((v->subjectPublicKeyInfo)); - - if(COMPONENTBITS_PRESENT ((&v->issuerUniqueIdentifier))) - { - FreeComponentUniqueIdentifier((&v->issuerUniqueIdentifier)); - free ((v->issuerUniqueIdentifier).comp_desc); - - } - - if(COMPONENTBITS_PRESENT ((&v->subjectUniqueIdentifier))) - { - FreeComponentUniqueIdentifier((&v->subjectUniqueIdentifier)); - free ((v->subjectUniqueIdentifier).comp_desc); - - } - - if(COMPONENTNOT_NULL ((v->extensions))) - { - FreeComponentExtensions((v->extensions)); - free ((v->extensions)->comp_desc); - free ((v->extensions)); - - } - -} /* FreeTBSCertificate */ - int MatchingComponentCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { @@ -2936,26 +2784,26 @@ MatchingComponentCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, Compone } /* BMatchingComponentCertificate */ void* -ExtractingComponentCertificate ( ComponentReference* cr, ComponentCertificate *comp ) +ExtractingComponentCertificate ( void* mem_op, ComponentReference* cr, ComponentCertificate *comp ) { - if ( ( strncmp(comp->tbsCertificate->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->tbsCertificate->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->tbsCertificate->identifier.bv_val && strncmp(comp->tbsCertificate->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->tbsCertificate->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->tbsCertificate; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentTBSCertificate ( cr, comp->tbsCertificate ); + return ExtractingComponentTBSCertificate ( mem_op, cr, comp->tbsCertificate ); } } - if ( ( strncmp(comp->signatureAlgorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signatureAlgorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->signatureAlgorithm->identifier.bv_val && strncmp(comp->signatureAlgorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signatureAlgorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return comp->signatureAlgorithm; else { cr->cr_curr = cr->cr_curr->ci_next; - return ExtractingComponentAlgorithmIdentifier ( cr, comp->signatureAlgorithm ); + return ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signatureAlgorithm ); } } - if ( ( strncmp(comp->signature.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { + if ( ( comp->signature.identifier.bv_val && strncmp(comp->signature.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { if ( cr->cr_curr->ci_next == NULL ) return &comp->signature; else @@ -2966,6 +2814,7 @@ ExtractingComponentCertificate ( ComponentReference* cr, ComponentCertificate *c int BDecComponentCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ AsnTag tagId0 _AND_ AsnLen elmtLen0 _AND_ @@ -2982,7 +2831,7 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; @@ -2992,7 +2841,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentTBSCertificate (b, tagId1, elmtLen1, (&k->tbsCertificate), &totalElmtsLen1, mode); + BDecComponentTBSCertificate (mem_op, b, tagId1, elmtLen1, (&k->tbsCertificate), &totalElmtsLen1, mode); (k->tbsCertificate)->identifier.bv_val = (k->tbsCertificate)->id_buf; (k->tbsCertificate)->identifier.bv_len = strlen("tbsCertificate"); strcpy( (k->tbsCertificate)->identifier.bv_val, "tbsCertificate"); @@ -3006,7 +2855,7 @@ int mode) if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentAlgorithmIdentifier (b, tagId1, elmtLen1, (&k->signatureAlgorithm), &totalElmtsLen1, mode); + BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signatureAlgorithm), &totalElmtsLen1, mode); (k->signatureAlgorithm)->identifier.bv_val = (k->signatureAlgorithm)->id_buf; (k->signatureAlgorithm)->identifier.bv_len = strlen("signatureAlgorithm"); strcpy( (k->signatureAlgorithm)->identifier.bv_val, "signatureAlgorithm"); @@ -3021,7 +2870,7 @@ int mode) (tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))) { elmtLen1 = BDecLen (b, &totalElmtsLen1 ); - BDecComponentBits (b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode); + BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode); (&k->signature)->identifier.bv_val = (&k->signature)->id_buf; (&k->signature)->identifier.bv_len = strlen("signature"); strcpy( (&k->signature)->identifier.bv_val, "signature"); @@ -3041,19 +2890,19 @@ int mode) return -1; if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentCertificate*) malloc( sizeof(ComponentCertificate) ); + *v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentCertificate ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -3063,7 +2912,8 @@ int mode) } /* BDecCertificate*/ int -GDecComponentCertificate PARAMS ((b, v, bytesDecoded, mode), +GDecComponentCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode), +void* mem_op _AND_ GenBuf * b _AND_ ComponentCertificate **v _AND_ AsnLen *bytesDecoded _AND_ @@ -3075,58 +2925,65 @@ int mode) if ( !(mode & DEC_ALLOC_MODE_1) ) { - memset(&c_temp,0,sizeof(c_temp)); + memset(&c_temp,0,sizeof(c_temp)); k = &c_temp; } else k = t = *v; mode = DEC_ALLOC_MODE_2; *bytesDecoded = 0; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading , in encoded data"); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading { in encoded data"); return LDAP_PROTOCOL_ERROR; } if(*peek_head != '{'){ Asn1Error("Missing { in encoded data"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading identifier"); + + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentTBSCertificate (b, (&k->tbsCertificate), bytesDecoded, mode); + if ( strncmp( peek_head, "tbsCertificate", strlen("tbsCertificate") ) == 0 ) { + GDecComponentTBSCertificate (mem_op, b, (&k->tbsCertificate), bytesDecoded, mode); ( k->tbsCertificate)->identifier.bv_val = peek_head; ( k->tbsCertificate)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentAlgorithmIdentifier (b, (&k->signatureAlgorithm), bytesDecoded, mode); + } + if ( strncmp( peek_head, "signatureAlgorithm", strlen("signatureAlgorithm") ) == 0 ) { + GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signatureAlgorithm), bytesDecoded, mode); ( k->signatureAlgorithm)->identifier.bv_val = peek_head; ( k->signatureAlgorithm)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ - Asn1Error("Error during Reading { "); + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading , "); return LDAP_PROTOCOL_ERROR; } if(*peek_head != ','){ Asn1Error("Missing , in encoding"); return LDAP_PROTOCOL_ERROR; } - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ Asn1Error("Error during Reading identifier"); return LDAP_PROTOCOL_ERROR; } - GDecComponentBits (b, (&k->signature), bytesDecoded, mode); + } + if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) { + GDecComponentBits (mem_op, b, (&k->signature), bytesDecoded, mode); (&k->signature)->identifier.bv_val = peek_head; (&k->signature)->identifier.bv_len = strLen; - if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ) { + } + if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { Asn1Error("Error during Reading } in encoding"); return LDAP_PROTOCOL_ERROR; } @@ -3135,19 +2992,19 @@ int mode) return LDAP_PROTOCOL_ERROR; } if( !(old_mode & DEC_ALLOC_MODE_1) ) { - *v = t = (ComponentCertificate*) malloc( sizeof(ComponentCertificate) ); + *v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) ); if ( !t ) return -1; *t = *k; } t->syntax = (Syntax*)NULL; - t->comp_desc = malloc( sizeof( ComponentDesc ) ); + t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); if ( !t->comp_desc ) { free ( t ); return -1; } t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ; t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ; - t->comp_desc->cd_free = (comp_free_func*)FreeComponentCertificate ; + t->comp_desc->cd_free = (comp_free_func*)NULL; t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate; t->comp_desc->cd_type = ASN_COMPOSITE; t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; @@ -3155,22 +3012,4 @@ int mode) return LDAP_SUCCESS; } /* GDecCertificate*/ -void FreeComponentCertificate(ComponentCertificate *v) -{ - - if(v == NULL) - return; - FreeComponentTBSCertificate((v->tbsCertificate)); - free ((v->tbsCertificate)->comp_desc); - free ((v->tbsCertificate)); - - FreeComponentAlgorithmIdentifier((v->signatureAlgorithm)); - free ((v->signatureAlgorithm)->comp_desc); - free ((v->signatureAlgorithm)); - - FreeComponentBits((&v->signature)); - free ((v->signature).comp_desc); - -} /* FreeCertificate */ - diff --git a/contrib/slapd-modules/comp_match/certificate.h b/contrib/slapd-modules/comp_match/certificate.h index 3299b07e25..660a075e1f 100644 --- a/contrib/slapd-modules/comp_match/certificate.h +++ b/contrib/slapd-modules/comp_match/certificate.h @@ -3,7 +3,7 @@ /* * certificate.h * "AuthenticationFramework" ASN.1 module encode/decode/extracting/matching/free C src. - * This file was generated by modified eSMACC compiler Sat Oct 23 20:25:08 2004 + * This file was generated by modified eSMACC compiler Tue Nov 23 23:28:16 2004 * The generated files are strongly encouraged to be * compiled as a module for OpenLDAP Software */ @@ -45,7 +45,6 @@ typedef ComponentInt ComponentVersion; /* INTEGER { V1 (0), V2 (1), V3 (2) } */ #define GDecComponentVersion GDecComponentInt -#define FreeComponentVersion FreeComponentInt typedef ComponentInt ComponentCertificateSerialNumber; /* INTEGER */ @@ -57,7 +56,6 @@ typedef ComponentInt ComponentCertificateSerialNumber; /* INTEGER */ #define GDecComponentCertificateSerialNumber GDecComponentInt -#define FreeComponentCertificateSerialNumber FreeComponentInt typedef ComponentOid ComponentAttributeType; /* OBJECT IDENTIFIER */ @@ -69,7 +67,6 @@ typedef ComponentOid ComponentAttributeType; /* OBJECT IDENTIFIER */ #define GDecComponentAttributeType GDecComponentOid -#define FreeComponentAttributeType FreeComponentOid typedef ComponentBits ComponentUniqueIdentifier; /* BIT STRING */ @@ -81,7 +78,6 @@ typedef ComponentBits ComponentUniqueIdentifier; /* BIT STRING */ #define GDecComponentUniqueIdentifier GDecComponentBits -#define FreeComponentUniqueIdentifier FreeComponentBits typedef struct AlgorithmIdentifier /* SEQUENCE */ { @@ -96,16 +92,13 @@ typedef struct AlgorithmIdentifier /* SEQUENCE */ int MatchingComponentAlgorithmIdentifier PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentAlgorithmIdentifier PROTO ((ComponentReference *cr, ComponentAlgorithmIdentifier *comp )); +void* ExtractingComponentAlgorithmIdentifier PROTO (( void* mem_op, ComponentReference *cr, ComponentAlgorithmIdentifier *comp )); -int BDecComponentAlgorithmIdentifier PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentAlgorithmIdentifier **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentAlgorithmIdentifier PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentAlgorithmIdentifier **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentAlgorithmIdentifier PROTO ((GenBuf * b, ComponentAlgorithmIdentifier **v, AsnLen *bytesDecoded, int mode)); - - -void FreeComponentAlgorithmIdentifier(ComponentAlgorithmIdentifier *v); +int GDecComponentAlgorithmIdentifier PROTO (( void* mem_op, GenBuf * b, ComponentAlgorithmIdentifier **v, AsnLen *bytesDecoded, int mode)); @@ -130,16 +123,13 @@ typedef struct Time /* CHOICE */ int MatchingComponentTime PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentTime PROTO ((ComponentReference *cr, ComponentTime *comp )); - +void* ExtractingComponentTime PROTO (( void* mem_op, ComponentReference *cr, ComponentTime *comp )); -int BDecComponentTime PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentTime **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentTime PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentTime **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentTime PROTO ((GenBuf * b, ComponentTime **v, AsnLen *bytesDecoded, int mode)); - -void FreeComponentTime(ComponentTime *v); +int GDecComponentTime PROTO (( void* mem_op, GenBuf * b, ComponentTime **v, AsnLen *bytesDecoded, int mode)); @@ -156,16 +146,13 @@ typedef struct Extension /* SEQUENCE */ int MatchingComponentExtension PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentExtension PROTO ((ComponentReference *cr, ComponentExtension *comp )); - - -int BDecComponentExtension PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentExtension **v, AsnLen *bytesDecoded, int mode)); +void* ExtractingComponentExtension PROTO (( void* mem_op, ComponentReference *cr, ComponentExtension *comp )); -int GDecComponentExtension PROTO ((GenBuf * b, ComponentExtension **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentExtension PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentExtension **v, AsnLen *bytesDecoded, int mode)); -void FreeComponentExtension(ComponentExtension *v); +int GDecComponentExtension PROTO (( void* mem_op, GenBuf * b, ComponentExtension **v, AsnLen *bytesDecoded, int mode)); @@ -182,16 +169,13 @@ typedef struct AttributeTypeAndValue /* SEQUENCE */ int MatchingComponentAttributeTypeAndValue PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentAttributeTypeAndValue PROTO ((ComponentReference *cr, ComponentAttributeTypeAndValue *comp )); +void* ExtractingComponentAttributeTypeAndValue PROTO (( void* mem_op, ComponentReference *cr, ComponentAttributeTypeAndValue *comp )); -int BDecComponentAttributeTypeAndValue PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentAttributeTypeAndValue **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentAttributeTypeAndValue PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentAttributeTypeAndValue **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentAttributeTypeAndValue PROTO ((GenBuf * b, ComponentAttributeTypeAndValue **v, AsnLen *bytesDecoded, int mode)); - - -void FreeComponentAttributeTypeAndValue(ComponentAttributeTypeAndValue *v); +int GDecComponentAttributeTypeAndValue PROTO (( void* mem_op, GenBuf * b, ComponentAttributeTypeAndValue **v, AsnLen *bytesDecoded, int mode)); @@ -208,16 +192,13 @@ typedef struct Validity /* SEQUENCE */ int MatchingComponentValidity PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentValidity PROTO ((ComponentReference *cr, ComponentValidity *comp )); - +void* ExtractingComponentValidity PROTO (( void* mem_op, ComponentReference *cr, ComponentValidity *comp )); -int BDecComponentValidity PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentValidity **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentValidity PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentValidity **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentValidity PROTO ((GenBuf * b, ComponentValidity **v, AsnLen *bytesDecoded, int mode)); - -void FreeComponentValidity(ComponentValidity *v); +int GDecComponentValidity PROTO (( void* mem_op, GenBuf * b, ComponentValidity **v, AsnLen *bytesDecoded, int mode)); @@ -234,16 +215,13 @@ typedef struct SubjectPublicKeyInfo /* SEQUENCE */ int MatchingComponentSubjectPublicKeyInfo PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentSubjectPublicKeyInfo PROTO ((ComponentReference *cr, ComponentSubjectPublicKeyInfo *comp )); - - -int BDecComponentSubjectPublicKeyInfo PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentSubjectPublicKeyInfo **v, AsnLen *bytesDecoded, int mode)); +void* ExtractingComponentSubjectPublicKeyInfo PROTO (( void* mem_op, ComponentReference *cr, ComponentSubjectPublicKeyInfo *comp )); -int GDecComponentSubjectPublicKeyInfo PROTO ((GenBuf * b, ComponentSubjectPublicKeyInfo **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentSubjectPublicKeyInfo PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentSubjectPublicKeyInfo **v, AsnLen *bytesDecoded, int mode)); -void FreeComponentSubjectPublicKeyInfo(ComponentSubjectPublicKeyInfo *v); +int GDecComponentSubjectPublicKeyInfo PROTO (( void* mem_op, GenBuf * b, ComponentSubjectPublicKeyInfo **v, AsnLen *bytesDecoded, int mode)); @@ -252,16 +230,13 @@ typedef ComponentList ComponentExtensions; /* SEQUENCE SIZE 1..MAX OF Extension int MatchingComponentExtensions PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentExtensions PROTO ((ComponentReference *cr, ComponentExtensions *comp )); +void* ExtractingComponentExtensions PROTO (( void* mem_op, ComponentReference *cr, ComponentExtensions *comp )); -int BDecComponentExtensions PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentExtensions **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentExtensions PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentExtensions **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentExtensions PROTO ((GenBuf * b, ComponentExtensions **v, AsnLen *bytesDecoded, int mode)); - - -void FreeComponentExtensions(ComponentExtensions *v); +int GDecComponentExtensions PROTO (( void* mem_op, GenBuf * b, ComponentExtensions **v, AsnLen *bytesDecoded, int mode)); @@ -270,16 +245,13 @@ typedef ComponentList ComponentRelativeDistinguishedName; /* SET OF AttributeTyp int MatchingComponentRelativeDistinguishedName PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentRelativeDistinguishedName PROTO ((ComponentReference *cr, ComponentRelativeDistinguishedName *comp )); - +void* ExtractingComponentRelativeDistinguishedName PROTO (( void* mem_op, ComponentReference *cr, ComponentRelativeDistinguishedName *comp )); -int BDecComponentRelativeDistinguishedName PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentRelativeDistinguishedName **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentRelativeDistinguishedName PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentRelativeDistinguishedName **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentRelativeDistinguishedName PROTO ((GenBuf * b, ComponentRelativeDistinguishedName **v, AsnLen *bytesDecoded, int mode)); - -void FreeComponentRelativeDistinguishedName(ComponentRelativeDistinguishedName *v); +int GDecComponentRelativeDistinguishedName PROTO (( void* mem_op, GenBuf * b, ComponentRelativeDistinguishedName **v, AsnLen *bytesDecoded, int mode)); @@ -288,16 +260,13 @@ typedef ComponentList ComponentRDNSequence; /* SEQUENCE OF RelativeDistinguished int MatchingComponentRDNSequence PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentRDNSequence PROTO ((ComponentReference *cr, ComponentRDNSequence *comp )); - - -int BDecComponentRDNSequence PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentRDNSequence **v, AsnLen *bytesDecoded, int mode)); +void* ExtractingComponentRDNSequence PROTO (( void* mem_op, ComponentReference *cr, ComponentRDNSequence *comp )); -int GDecComponentRDNSequence PROTO ((GenBuf * b, ComponentRDNSequence **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentRDNSequence PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentRDNSequence **v, AsnLen *bytesDecoded, int mode)); -void FreeComponentRDNSequence(ComponentRDNSequence *v); +int GDecComponentRDNSequence PROTO (( void* mem_op, GenBuf * b, ComponentRDNSequence **v, AsnLen *bytesDecoded, int mode)); @@ -320,16 +289,13 @@ typedef struct Name /* CHOICE */ int MatchingComponentName PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentName PROTO ((ComponentReference *cr, ComponentName *comp )); +void* ExtractingComponentName PROTO (( void* mem_op, ComponentReference *cr, ComponentName *comp )); -int BDecComponentName PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentName **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentName PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentName **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentName PROTO ((GenBuf * b, ComponentName **v, AsnLen *bytesDecoded, int mode)); - - -void FreeComponentName(ComponentName *v); +int GDecComponentName PROTO (( void* mem_op, GenBuf * b, ComponentName **v, AsnLen *bytesDecoded, int mode)); @@ -354,16 +320,13 @@ typedef struct TBSCertificate /* SEQUENCE */ int MatchingComponentTBSCertificate PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentTBSCertificate PROTO ((ComponentReference *cr, ComponentTBSCertificate *comp )); - +void* ExtractingComponentTBSCertificate PROTO (( void* mem_op, ComponentReference *cr, ComponentTBSCertificate *comp )); -int BDecComponentTBSCertificate PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentTBSCertificate **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentTBSCertificate PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentTBSCertificate **v, AsnLen *bytesDecoded, int mode)); -int GDecComponentTBSCertificate PROTO ((GenBuf * b, ComponentTBSCertificate **v, AsnLen *bytesDecoded, int mode)); - -void FreeComponentTBSCertificate(ComponentTBSCertificate *v); +int GDecComponentTBSCertificate PROTO (( void* mem_op, GenBuf * b, ComponentTBSCertificate **v, AsnLen *bytesDecoded, int mode)); @@ -381,16 +344,13 @@ typedef struct Certificate /* SEQUENCE */ int MatchingComponentCertificate PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); -void* ExtractingComponentCertificate PROTO ((ComponentReference *cr, ComponentCertificate *comp )); - - -int BDecComponentCertificate PROTO ((GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentCertificate **v, AsnLen *bytesDecoded, int mode)); +void* ExtractingComponentCertificate PROTO (( void* mem_op, ComponentReference *cr, ComponentCertificate *comp )); -int GDecComponentCertificate PROTO ((GenBuf * b, ComponentCertificate **v, AsnLen *bytesDecoded, int mode)); +int BDecComponentCertificate PROTO ((void* mem_op, GenBuf * b, AsnTag tagId0, AsnLen elmtLen0, ComponentCertificate **v, AsnLen *bytesDecoded, int mode)); -void FreeComponentCertificate(ComponentCertificate *v); +int GDecComponentCertificate PROTO (( void* mem_op, GenBuf * b, ComponentCertificate **v, AsnLen *bytesDecoded, int mode)); diff --git a/contrib/slapd-modules/comp_match/component.h b/contrib/slapd-modules/comp_match/component.h index a8fe88a81b..f39b55e62f 100644 --- a/contrib/slapd-modules/comp_match/component.h +++ b/contrib/slapd-modules/comp_match/component.h @@ -41,11 +41,10 @@ typedef struct ComponentBits { #define GASNBITS_PRESENT(abits) ((abits)->value.bits != NULL) #define COMPONENTBITS_PRESENT(abits) ((abits)->value.bits != NULL) -int GDecComponentBits (GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); -int BDecComponentBits (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); +int GDecComponentBits (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentBits (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentBits (char* oid, ComponentSyntaxInfo *bits1 , ComponentSyntaxInfo* bits2); -#define ExtractingComponentBits(cr,data) NULL +#define ExtractingComponentBits( mem_op, cr,data ) NULL /* * BMP String @@ -58,12 +57,10 @@ typedef struct ComponentBMPString { BMPString value; } ComponentBMPString; -int GDecComponentBMPString (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentBMPString (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); +int GDecComponentBMPString (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentBMPString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); #define MatchingComponentBMPString MatchingComponentOcts -#define ExtractingComponentBMPString(cr,data) NULL +#define ExtractingComponentBMPString( mem_op, cr, data ) NULL #define FreeComponentBMPString FreeComponentOcts /* @@ -77,12 +74,10 @@ typedef struct ComponentBool { AsnBool value; } ComponentBool; -int GDecComponentBool (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentBool (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); +int GDecComponentBool ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentBool (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentBool(cr,data) NULL +#define ExtractingComponentBool( mem_op, cr, data ) NULL #define FreeComponentBool(v) NULL /* @@ -97,11 +92,10 @@ typedef struct ComponentEnum { struct berval value_identifier;/*Why this value is defined here?*/ } ComponentEnum; -int GDecComponentEnum (GenBuf *a, void *result, AsnLen *bytesDecoded,int mode); -int BDecComponentEnum (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); +int GDecComponentEnum ( void* mem_op, GenBuf *a, void *result, AsnLen *bytesDecoded,int mode); +int BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentEnum (char *oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo * b); -#define ExtractingComponentEnum(cr,data) NULL +#define ExtractingComponentEnum( mem_op, cr, data ) NULL #define FreeComponentEnum FreeComponentInt /* @@ -116,10 +110,9 @@ typedef struct ComponentIA5String { } ComponentIA5String; #define GDecComponentIA5String GDecComponentUTF8String -int BDecComponentIA5String (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); +int BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); #define MatchingComponentIA5String MatchingComponentOcts -#define ExtractingComponentIA5String(cr,data) NULL +#define ExtractingComponentIA5String(mem_op, cr,data) NULL #define FreeComponentIA5String FreeComponentOcts @@ -136,11 +129,10 @@ typedef struct ComponentInt { #define GNOT_NULL(ptr) ((ptr) != NULL) -int GDecComponentInt (GenBuf *b, void *result, AsnLen *bytesDecoded, int mode ); -int BDecComponentInt (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); +int GDecComponentInt ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode ); +int BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentInt (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentInt(cr,data) NULL +#define ExtractingComponentInt(mem_op, cr,data) NULL #define FreeComponentInt(v) NULL /* @@ -165,13 +157,11 @@ typedef struct ComponentNull { AsnNull value; } ComponentNull; -int GDecComponentNull (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentNull (GenBuf *b, AsnTag tagId, AsnLen len, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentNullTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ); +int GDecComponentNull ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ); int MatchingComponentNull (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentNull(cr,data) NULL +#define ExtractingComponentNull(mem_op, cr, data) NULL #define FreeComponentNull NULL /* @@ -186,10 +176,9 @@ typedef struct ComponentNumericString { } ComponentNumericString; #define GDecComponentNumericString GDecComponentUTF8String -int BDecComponentNumericString (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); #define MatchingComponentNumericString MatchingComponentOcts -#define ExtractingComponentNumericString(cr,data) NULL +#define ExtractingComponentNumericString(mem_op, cr,data) NULL #define FreeComponentNumericString FreeComponentOcts /* @@ -205,12 +194,10 @@ typedef struct ComponentOcts { #define GASNOCTS_PRESENT(aocts) ((aocts)->value.octs != NULL) -int GDecComponentOcts (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentOcts (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int GDecComponentOcts (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentOcts (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentOcts (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentOcts(cr,data) NULL +#define ExtractingComponentOcts(mem_op,cr,data) NULL void FreeComponentOcts( ComponentOcts* octs ); /* @@ -226,12 +213,10 @@ typedef struct ComponentOid { #define GASNOID_PRESENT(aoid) ASNOCTS_PRESENT(aoid) -int GDecComponentOid (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentOid (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int GDecComponentOid (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentOid (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentOid(cr,data) NULL +#define ExtractingComponentOid(mem_op, cr, data) NULL #define FreeComponentOid FreeComponentOcts /* @@ -246,11 +231,10 @@ typedef struct ComponentPrintableString{ } ComponentPrintableString; #define GDecComponentPrintableString GDecComponentUTF8String -int BDecComponentPrintableString (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); -int BDecComponentPrintableStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ); +int BDecComponentPrintableString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentPrintableStringTag (void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ); #define MatchingComponentPrintableString MatchingComponentOcts -#define ExtractingComponentPrintableString(cr,data) NULL +#define ExtractingComponentPrintableString(mem_op, cr, data) NULL #define FreeComponentPrintableString FreeComponentOcts /* @@ -264,12 +248,10 @@ typedef struct ComponentReal{ AsnReal value; } ComponentReal; -int GDecComponentReal (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentReal (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int GDecComponentReal (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentReal (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentReal (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentReal(cr,data) NULL +#define ExtractingComponentReal( mem_op, cr, data ) NULL #define FreeComponentReal(v) NULL /* @@ -284,12 +266,10 @@ typedef struct ComponentRelativeOid { AsnRelativeOid value; } ComponentRelativeOid; -int GDecComponentRelativeOid (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentRelativeOid (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int GDecComponentRelativeOid ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); int MatchingComponentRelativeOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); -#define ExtractingComponentRelativeOid(cr,data) +#define ExtractingComponentRelativeOid( mem_op, cr, data ) NULL #define FreeComponentRelativeOid FreeComponentOid /* @@ -303,11 +283,10 @@ typedef struct ComponentTeletexString { TeletexString value; } ComponentTeletexString; -int GDecComponentTeletexString (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); +int GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode ); #define BDecComponentTeletexString BDecComponentOcts #define MatchingComponentTeletexString MatchingComponentOcts -#define ExtractingComponentTeletexString(cr,data) +#define ExtractingComponentTeletexString(mem_op,cr,data) #define FreeComponentTeletexString FreeComponentOcts @@ -322,12 +301,10 @@ typedef struct ComponentUniversalString{ UniversalString value; } ComponentUniversalString; -int GDecComponentUniversalString (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentUniversalString (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); #define MatchingComponentUniversalString MatchingComponentOcts -#define ExtractingComponentUniversalString(cr,data) +#define ExtractingComponentUniversalString(mem_op,cr,data) #define FreeComponentUniversalString FreeComponentOcts /* @@ -341,12 +318,10 @@ typedef struct ComponentUTF8String{ UTF8String value; } ComponentUTF8String; -int GDecComponentUTF8String (GenBuf *b, void *result, - AsnLen *bytesDecoded, int mode); -int BDecComponentUTF8String (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int GDecComponentUTF8String (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentUTF8String (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); #define MatchingComponentUTF8String MatchingComponentOcts -#define ExtractingComponentUTF8String(cr,data) +#define ExtractingComponentUTF8String(mem_op,cr,data) #define FreeComponentUTF8String FreeComponentOcts /* @@ -361,10 +336,9 @@ typedef struct ComponentVisibleString{ } ComponentVisibleString; #define GDecComponentVisibleString GDecComponentUTF8String -int BDecComponentVisibleString (GenBuf *b, AsnTag tagId, AsnLen len, - void *result, AsnLen *bytesDecoded, int mode); +int BDecComponentVisibleString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode); #define MatchingComponentVisibleString MatchingComponentOcts -#define ExtractingComponentVisibleString(cr,data) +#define ExtractingComponentVisibleString(mem_op,cr,data) #define FreeComponentVisibleString FreeComponentOcts /* @@ -372,7 +346,7 @@ int BDecComponentVisibleString (GenBuf *b, AsnTag tagId, AsnLen len, */ typedef int (*MatchFcn) (char*, void*, void*); -typedef void* (*ExtractFcn) (ComponentReference*, void * ); +typedef void* (*ExtractFcn) (void*, ComponentReference*, void * ); typedef struct ComponentAnyInfo { @@ -405,8 +379,8 @@ typedef ComponentAny ComponentAnyDefinedBy; #define MatchingComponentAnyDefinedBy MatchingComponentAny #define FreeComponentAnyDefinedBy FreeComponentAny -int BDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode); -int GDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode); +int BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode); +int GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode); int MatchingComponentAny (char* oid, ComponentAny *a, ComponentAny *b); void FreeComponentAny ( ComponentAny*); @@ -422,7 +396,7 @@ typedef ComponentVisibleString ComponentUTCTime; #define GDecComponentUTCTime GDecComponentVisibleString #define BDecComponentUTCTime BDecComponentOcts #define MatchingComponentUTCTime MatchingComponentOcts -#define ExtractingComponentUTCTime(cr,data) +#define ExtractingComponentUTCTime(mem_op,cr,data) NULL #define FreeComponentUTCTime FreeComponentOcts /* @@ -432,7 +406,7 @@ typedef ComponentVisibleString ComponentGeneralizedTime; #define GDecComponentGeneralizedTime GDecComponentVisibleString #define BDecComponentGeneralizedTime BDecComponentOcts #define MatchingComponentGeneralizedTime MatchingComponentOcts -#define ExtractingComponentGeneralizedTime(cr,data) +#define ExtractingComponentGeneralizedTime(mem_op,cr,data) NULL #define FreeComponentGeneralizedTime FreeComponentOcts typedef int converter_func LDAP_P (( @@ -479,7 +453,7 @@ typedef struct OID_Decoder_entry { } OD_entry; void -m_convert_asn_to_ldap( ComponentSyntaxInfo* csi, struct berval* bv); +m_convert_asn_to_ldap ( ComponentSyntaxInfo* csi, struct berval* bv); int m_convert_assert_to_comp ( gser_decoder_func* decoder, struct berval* bv, ComponentSyntaxInfo** csi, int len, int mode ); @@ -511,6 +485,10 @@ m_convert_attr_to_comp ( Attribute* a, struct berval* bv ); #define CALL_TAG_DECODER 0x08 #define CALL_CONTENT_DECODER ~0x08 +#define OID_ALL_COMP_MATCH "1.2.36.79672281.1.13.6" +#define OID_COMP_FILTER_MATCH "1.2.36.79672281.1.13.2" +#define MAX_LDAP_STR_LEN 128 + MatchingRule* retrieve_matching_rule( char* mr_oid, AsnTypeId type ); diff --git a/contrib/slapd-modules/comp_match/componentlib.c b/contrib/slapd-modules/comp_match/componentlib.c index d1ef3d46b8..fa160e8d09 100644 --- a/contrib/slapd-modules/comp_match/componentlib.c +++ b/contrib/slapd-modules/comp_match/componentlib.c @@ -64,7 +64,7 @@ FreeComponentBits ( ComponentBits* v ) { * GSER Decoder : BIT STRING */ int -GDecComponentBits ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentBits ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen; @@ -76,17 +76,21 @@ GDecComponentBits ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentBits**) v; - *k2 = (ComponentBits*) malloc( sizeof( ComponentBits ) ); + *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnBitsContent (b, &result, bytesDecoded ); + if ( GDecAsnBitsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits; @@ -106,16 +110,16 @@ GDecComponentBits ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : BIT STRING */ int -BDecComponentBitsTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentBits ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentBits ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentBits ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentBits* k, **k2; AsnBits result; @@ -124,23 +128,29 @@ BDecComponentBits ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentBits**) v; - *k2 = (ComponentBits*) malloc( sizeof( ComponentBits ) ); - if ( !*k2 ) return -1; + *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnBits (b, &result, bytesDecoded ); + rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnBitsContent (b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnBitsContent ( mem_op, b, tagId, len, &result, bytesDecoded ); } + + if ( rc < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits; @@ -159,7 +169,7 @@ BDecComponentBits ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, * Component GSER BMPString Decoder */ int -GDecComponentBMPString (GenBuf *b, void *v, AsnLen *bytesDecoded, int mode) +GDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode) { char* peek_head; int i, strLen; @@ -171,20 +181,24 @@ GDecComponentBMPString (GenBuf *b, void *v, AsnLen *bytesDecoded, int mode) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentBMPString**) v; - *k2 = (ComponentBMPString*) malloc( sizeof( ComponentBMPString ) ); - if ( !*k2 ) return -1; + *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } *bytesDecoded = 0; - GDecBMPStringContent ( b, &result, bytesDecoded ); + if ( GDecBMPStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString; @@ -204,16 +218,16 @@ GDecComponentBMPString (GenBuf *b, void *v, AsnLen *bytesDecoded, int mode) * Component BER BMPString Decoder */ int -BDecComponentBMPStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentBMPString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentBMPString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentBMPString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentBMPString* k, **k2; BMPString result; @@ -222,22 +236,29 @@ BDecComponentBMPString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentBMPString**) v; - *k2 = (ComponentBMPString*) malloc( sizeof( ComponentBMPString ) ); + *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecBMPString ( b, &result, bytesDecoded ); + rc = BDecBMPString ( mem_op, b, &result, bytesDecoded ); } else { - BDecBMPStringContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecBMPStringContent ( mem_op, b, tagId, len, &result, bytesDecoded ); } + + if ( rc < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString; @@ -257,8 +278,8 @@ BDecComponentBMPString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, * Component GSER Decoder : UTF8 String */ int -GDecComponentUTF8String (GenBuf *b, void *v, - AsnLen *bytesDecoded, int mode) { +GDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v, + AsnLen *bytesDecoded, int mode) { char* peek_head; int i, strLen; void* component_values; @@ -269,19 +290,24 @@ GDecComponentUTF8String (GenBuf *b, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentUTF8String**) v; - *k2 = (ComponentUTF8String*)malloc( sizeof( ComponentUTF8String ) ); + *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } *bytesDecoded = 0; - GDecUTF8StringContent ( b, &result, bytesDecoded ); + if ( GDecUTF8StringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String; @@ -300,16 +326,16 @@ GDecComponentUTF8String (GenBuf *b, void *v, * Component BER Decoder : UTF8String */ int -BDecComponentUTF8StringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentUTF8String ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentUTF8String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentUTF8String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, + void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentUTF8String* k, **k2; UTF8String result; @@ -318,22 +344,28 @@ BDecComponentUTF8String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentUTF8String**) v; - *k2 = (ComponentUTF8String*) malloc( sizeof( ComponentUTF8String ) ); + *k2 = (ComponentUTF8String*) CompAlloc( mem_op, sizeof( ComponentUTF8String ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecUTF8String ( b, &result, bytesDecoded ); + rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded ); } else { - BDecUTF8StringContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecUTF8StringContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; } + k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String; @@ -350,7 +382,7 @@ BDecComponentUTF8String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, * Component GSER Decoder : Teletex String */ int -GDecComponentTeletexString (GenBuf *b, void *v, +GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode) { char* peek_head; int i, strLen; @@ -362,19 +394,24 @@ GDecComponentTeletexString (GenBuf *b, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentTeletexString**) v; - *k2 = (ComponentTeletexString*)malloc( sizeof( ComponentTeletexString ) ); + *k2 = (ComponentTeletexString*)CompAlloc( mem_op, sizeof( ComponentTeletexString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } *bytesDecoded = 0; - GDecTeletexStringContent ( b, &result, bytesDecoded ); + if ( GDecTeletexStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTeletexString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTeletexString; @@ -416,7 +453,7 @@ MatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr, * GSER Decoder : BOOLEAN */ int -GDecComponentBool ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen; @@ -427,17 +464,22 @@ GDecComponentBool ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentBool**) v; - *k2 = (ComponentBool*) malloc( sizeof( ComponentBool ) ); + *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnBoolContent( b, &result, bytesDecoded ); + if ( GDecAsnBoolContent( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool; @@ -456,16 +498,16 @@ GDecComponentBool ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : BOOLEAN */ int -BDecComponentBoolTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentBool ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentBoolTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentBool ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentBool ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; ComponentBool* k, **k2; AsnBool result; @@ -473,22 +515,28 @@ BDecComponentBool ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentBool**) v; - *k2 = (ComponentBool*) malloc( sizeof( ComponentBool ) ); + *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnBool ( b, &result, bytesDecoded ); + rc = BDecAsnBool ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnBoolContent( b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnBoolContent( mem_op, b, tagId, len, &result, bytesDecoded ); } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool; @@ -530,7 +578,7 @@ MatchingComponentEnum ( char* oid, ComponentSyntaxInfo *csi_attr, * GSER Decoder : ENUMERATE */ int -GDecComponentEnum ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentEnum ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen; @@ -542,18 +590,23 @@ GDecComponentEnum ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentEnum**) v; - *k2 = (ComponentEnum*) malloc( sizeof( ComponentEnum ) ); + *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnEnumContent ( b, &result, bytesDecoded ); + if ( GDecAsnEnumContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } + k->value_identifier.bv_val = result.value_identifier; k->value_identifier.bv_len = result.len; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum; @@ -572,16 +625,16 @@ GDecComponentEnum ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : ENUMERATE */ int -BDecComponentEnumTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentEnum ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentEnumTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentEnum ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentEnum ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentEnum* k, **k2; AsnEnum result; @@ -590,22 +643,28 @@ BDecComponentEnum ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentEnum**) v; - *k2 = (ComponentEnum*) malloc( sizeof( ComponentEnum ) ); + *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) ); + if ( k ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnEnum ( b, &result, bytesDecoded ); + rc = BDecAsnEnum ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnEnumContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnEnumContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } + k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum; @@ -627,16 +686,16 @@ BDecComponentEnum ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, * Component BER Decoder : IA5String */ int -BDecComponentIA5StringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentIA5String ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentIA5String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentIA5String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentIA5String* k, **k2; IA5String result; @@ -645,22 +704,28 @@ BDecComponentIA5String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentIA5String**) v; - *k2 = (ComponentIA5String*) malloc( sizeof( ComponentIA5String ) ); + *k2 = (ComponentIA5String*) CompAlloc( mem_op, sizeof( ComponentIA5String ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecIA5String ( b, &result, bytesDecoded ); + rc = BDecIA5String ( mem_op, b, &result, bytesDecoded ); } else { - BDecIA5StringContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecIA5StringContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } + k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String; @@ -703,7 +768,7 @@ function*/ * GSER Decoder : INTEGER */ int -GDecComponentInt( GenBuf * b, void *v, AsnLen *bytesDecoded, int mode) +GDecComponentInt( void* mem_op, GenBuf * b, void *v, AsnLen *bytesDecoded, int mode) { char* peek_head; int i, strLen; @@ -715,17 +780,21 @@ GDecComponentInt( GenBuf * b, void *v, AsnLen *bytesDecoded, int mode) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentInt**) v; - *k2 = (ComponentInt*) malloc( sizeof( ComponentInt ) ); + *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnIntContent (b, &result, bytesDecoded ); + if ( GDecAsnIntContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; @@ -744,16 +813,16 @@ GDecComponentInt( GenBuf * b, void *v, AsnLen *bytesDecoded, int mode) * Component BER Decoder : INTEGER */ int -BDecComponentIntTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentInt ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentIntTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentInt ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentInt ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentInt* k, **k2; AsnInt result; @@ -762,22 +831,23 @@ BDecComponentInt ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentInt**) v; - *k2 = (ComponentInt*) malloc( sizeof( ComponentInt ) ); + *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnInt (b, &result, bytesDecoded ); + rc = BDecAsnInt ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnIntContent (b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnIntContent ( mem_op, b, tagId, len, &result, bytesDecoded ); } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; @@ -817,7 +887,7 @@ MatchingComponentNull ( char *oid, ComponentSyntaxInfo *csi_attr, * GSER Decoder : NULL */ int -GDecComponentNull ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentNull ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen; @@ -829,17 +899,21 @@ GDecComponentNull ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentNull**) v; - *k2 = (ComponentNull*) malloc( sizeof( ComponentNull ) ); + *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnNullContent ( b, &result, bytesDecoded ); + if ( GDecAsnNullContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull; @@ -858,18 +932,17 @@ GDecComponentNull ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : NULL */ int -BDecComponentNullTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentNull ( b, 0, 0, v,bytesDecoded, - mode|CALL_TAG_DECODER ); + return BDecComponentNull ( mem_op, b, 0, 0, v,bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentNull ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentNull* k, **k2; AsnNull result; @@ -878,23 +951,28 @@ BDecComponentNull ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentNull**) v; - *k2 = (ComponentNull*) malloc( sizeof( ComponentNull ) ); + *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnNull ( b, &result, bytesDecoded ); + rc = BDecAsnNull ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnNullContent ( b, tagId, len, &result, bytesDecoded); + rc = BDecAsnNullContent ( mem_op, b, tagId, len, &result, bytesDecoded); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull; @@ -912,17 +990,15 @@ BDecComponentNull ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, * Component BER Decoder : NumericString */ int -BDecComponentNumericStringTag ( GenBuf *b, void *v, - AsnLen *bytesDecoded, int mode ) { - BDecComponentNumericString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentNumericStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentNumericString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentNumericString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentNumericString* k, **k2; NumericString result; @@ -931,22 +1007,27 @@ BDecComponentNumericString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentNumericString**) v; - *k2 = (ComponentNumericString*) malloc( sizeof( ComponentNumericString ) ); + *k2 = (ComponentNumericString*) CompAlloc( mem_op, sizeof( ComponentNumericString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecNumericString ( b, &result, bytesDecoded ); + rc = BDecNumericString ( mem_op, b, &result, bytesDecoded ); } else { - BDecNumericStringContent ( b, tagId, len, &result, bytesDecoded); + rc = BDecNumericStringContent ( mem_op, b, tagId, len, &result, bytesDecoded); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString; @@ -1000,7 +1081,7 @@ MatchingComponentOcts ( char* oid, ComponentSyntaxInfo* csi_attr, * GSER Decoder : OCTET STRING */ int -GDecComponentOcts ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentOcts ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char *peek_head, *data; int i, j, strLen; @@ -1012,17 +1093,21 @@ GDecComponentOcts ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentOcts**) v; - *k2 = (ComponentOcts*) malloc( sizeof( ComponentOcts ) ); + *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnOctsContent ( b, &result, bytesDecoded ); + if ( GDecAsnOctsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts; @@ -1041,16 +1126,16 @@ GDecComponentOcts ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : OCTET STRING */ int -BDecComponentOctsTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentOcts ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentOcts ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentOcts ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentOcts ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char *peek_head, *data; - int i, j, strLen; + int i, strLen, rc; void* component_values; ComponentOcts* k, **k2; AsnOcts result; @@ -1059,22 +1144,27 @@ BDecComponentOcts ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentOcts**) v; - *k2 = (ComponentOcts*) malloc( sizeof( ComponentOcts ) ); + *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnOcts ( b, &result, bytesDecoded ); + rc = BDecAsnOcts ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnOctsContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnOctsContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts; @@ -1117,9 +1207,47 @@ MatchingComponentOid ( char *oid, ComponentSyntaxInfo *csi_attr , /* * GSER Decoder : OID */ +int +GDecAsnDescOidContent ( void* mem_op, GenBuf *b, GAsnOid *result, AsnLen *bytesDecoded ){ + AttributeType *ad_type; + struct berval name; + char* peek_head; + int strLen; + + strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_NO_COPY ); + name.bv_val = peek_head; + name.bv_len = strLen; + + ad_type = at_bvfind( &name ); + + if ( !ad_type ) + return LDAP_DECODING_ERROR; + + peek_head = ad_type->sat_atype.at_oid; + strLen = strlen ( peek_head ); + + result->value.octs = EncodeComponentOid ( mem_op, peek_head , &strLen ); + result->value.octetLen = strLen; + return LDAP_SUCCESS; +} int -GDecComponentOid ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +IsNumericOid ( char* peek_head , int strLen ) { + int i; + int num_dot; + for ( i = 0, num_dot = 0 ; i < strLen ; i++ ) { + if ( peek_head[i] == '.' ) num_dot++; + else if ( peek_head[i] > '9' || peek_head[i] < '0' ) + return (-1); + } + if ( num_dot ) + return (1); + else + return (-1); +} + +int +GDecComponentOid ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen, rc; @@ -1131,18 +1259,32 @@ GDecComponentOid ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentOid**) v; - *k2 = (ComponentOid*) malloc( sizeof( ComponentOid ) ); + *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - - if ( (rc = GDecAsnOidContent ( b, &result, bytesDecoded )) == -1 ) - return rc; + + strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_PEEK ); + if ( IsNumericOid ( peek_head , strLen ) >= 1 ) { + /* numeric-oid */ + if ( GDecAsnOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } + } + else { + /*descr*/ + if ( GDecAsnDescOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ){ + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid; @@ -1161,16 +1303,16 @@ GDecComponentOid ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : OID */ int -BDecComponentOidTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentOid ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, +BDecComponentOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentOid* k, **k2; AsnOid result; @@ -1179,22 +1321,27 @@ BDecComponentOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentOid**) v; - *k2 = (ComponentOid*) malloc( sizeof( ComponentOid ) ); + *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnOid ( b, &result, bytesDecoded ); + rc = BDecAsnOid ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnOidContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnOidContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid; @@ -1213,19 +1360,16 @@ BDecComponentOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, */ int -BDecComponentPrintableStringTag ( GenBuf *b, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentPrintableStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentPrintableString ( b, 0, 0, v, bytesDecoded, - mode|CALL_TAG_DECODER ); + return BDecComponentPrintableString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentPrintableString( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentPrintableString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentPrintableString* k, **k2; AsnOid result; @@ -1234,22 +1378,27 @@ BDecComponentPrintableString( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentPrintableString**) v; - *k2 = (ComponentPrintableString*) malloc( sizeof( ComponentPrintableString ) ); + *k2 = (ComponentPrintableString*) CompAlloc( mem_op, sizeof( ComponentPrintableString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ) { mode = mode & CALL_CONTENT_DECODER; - BDecPrintableString ( b, &result, bytesDecoded ); + rc = BDecPrintableString ( mem_op, b, &result, bytesDecoded ); } else { - BDecPrintableStringContent ( b, tagId, len, &result, bytesDecoded ); - } + rc = BDecPrintableStringContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentPrintableString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentPrintableString; @@ -1290,7 +1439,7 @@ MatchingComponentReal (char* oid, ComponentSyntaxInfo *csi_attr, * GSER Decoder : Real */ int -GDecComponentReal ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentReal ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen; @@ -1302,17 +1451,21 @@ GDecComponentReal ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentReal**) v; - *k2 = (ComponentReal*) malloc( sizeof( ComponentReal ) ); + *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnRealContent ( b, &result, bytesDecoded ); + if ( GDecAsnRealContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal; @@ -1331,16 +1484,15 @@ GDecComponentReal ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : Real */ int -BDecComponentRealTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentReal ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentRealTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentReal ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentReal ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentReal ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentReal* k, **k2; AsnReal result; @@ -1349,22 +1501,27 @@ BDecComponentReal ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentReal**) v; - *k2 = (ComponentReal*) malloc( sizeof( ComponentReal ) ); + *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnReal ( b, &result, bytesDecoded ); + rc = BDecAsnReal ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnRealContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnRealContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal; @@ -1410,7 +1567,7 @@ MatchingComponentRelativeOid ( char* oid, ComponentSyntaxInfo *csi_attr, * GSER Decoder : RELATIVE_OID. */ int -GDecComponentRelativeOid ( GenBuf *b,void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentRelativeOid ( void* mem_op, GenBuf *b,void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; int i, strLen; @@ -1422,17 +1579,21 @@ GDecComponentRelativeOid ( GenBuf *b,void *v, AsnLen *bytesDecoded, int mode ) if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentRelativeOid**) v; - *k2 = (ComponentRelativeOid*) malloc( sizeof( ComponentRelativeOid ) ); + *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } - GDecAsnRelativeOidContent ( b, &result, bytesDecoded ); + if ( GDecAsnRelativeOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; + } k->value = result.value; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid; @@ -1451,16 +1612,15 @@ GDecComponentRelativeOid ( GenBuf *b,void *v, AsnLen *bytesDecoded, int mode ) * Component BER Decoder : RELATIVE_OID. */ int -BDecComponentRelativeOidTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentRelativeOid ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentRelativeOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentRelativeOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentRelativeOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentRelativeOid* k, **k2; AsnRelativeOid result; @@ -1469,22 +1629,27 @@ BDecComponentRelativeOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentRelativeOid**) v; - *k2 = (ComponentRelativeOid*) malloc( sizeof( ComponentRelativeOid ) ); + *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecAsnRelativeOid ( b, &result, bytesDecoded ); + rc = BDecAsnRelativeOid ( mem_op, b, &result, bytesDecoded ); } else { - BDecAsnRelativeOidContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecAsnRelativeOidContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid; @@ -1504,56 +1669,59 @@ BDecComponentRelativeOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, static int UTF8toUniversalString( char* octs, int len){ /* Need to be Implemented */ - return 1; + return LDAP_SUCCESS; } int -GDecComponentUniversalString ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - GDecComponentUTF8String (b, v, bytesDecoded, mode); - UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, - ((ComponentUniversalString*)v)->value.octetLen ); + if ( GDecComponentUTF8String ( mem_op, b, v, bytesDecoded, mode) < 0 ) + UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, ((ComponentUniversalString*)v)->value.octetLen ); + return LDAP_DECODING_ERROR; } /* * Component BER Decoder : UniverseString */ int -BDecComponentUniversalStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, - int mode ) { - BDecComponentUniversalString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentUniversalStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentUniversalString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentUniversalString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentUniversalString* k, **k2; UniversalString result; - + k = (ComponentUniversalString*) v; - + if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentUniversalString**) v; - *k2 = (ComponentUniversalString*) malloc( sizeof( ComponentUniversalString ) ); + *k2 = (ComponentUniversalString*) CompAlloc( mem_op, sizeof( ComponentUniversalString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecUniversalString ( b, &result, bytesDecoded ); + rc = BDecUniversalString ( mem_op, b, &result, bytesDecoded ); } else { - BDecUniversalStringContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecUniversalStringContent ( mem_op, b, tagId, len, &result, bytesDecoded ); + } + if ( rc < 0 ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUniversalString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUniversalString; @@ -1567,22 +1735,19 @@ BDecComponentUniversalString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, return LDAP_SUCCESS; } - - /* * Component BER Decoder : VisibleString */ int -BDecComponentVisibleStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { - BDecComponentVisibleString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +BDecComponentVisibleStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + return BDecComponentVisibleString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); } int -BDecComponentVisibleString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, - AsnLen *bytesDecoded, int mode ) +BDecComponentVisibleString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode ) { char* peek_head; - int i, strLen; + int i, strLen, rc; void* component_values; ComponentVisibleString* k, **k2; VisibleString result; @@ -1591,22 +1756,23 @@ BDecComponentVisibleString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentVisibleString**) v; - *k2 = (ComponentVisibleString*) malloc( sizeof( ComponentVisibleString ) ); + *k2 = (ComponentVisibleString*) CompAlloc( mem_op, sizeof( ComponentVisibleString ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ( mode & CALL_TAG_DECODER ){ mode = mode & CALL_CONTENT_DECODER; - BDecVisibleString ( b, &result, bytesDecoded ); + rc = BDecVisibleString ( mem_op, b, &result, bytesDecoded ); } else { - BDecVisibleStringContent ( b, tagId, len, &result, bytesDecoded ); + rc = BDecVisibleStringContent ( mem_op, b, tagId, len, &result, bytesDecoded ); } k->value = result; - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentVisibleString; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentVisibleString; @@ -1656,27 +1822,27 @@ SetAnyTypeByComponentInt( ComponentAny *v, ComponentInt id) { } int -BDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) { +BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) { ComponentAny *k, **k2; k = (ComponentAny*) result; if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentAny**) result; - *k2 = (ComponentAny*) malloc( sizeof( ComponentAny) ); + *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) { - result->value = (void*) malloc ( result->cai->size ); + result->value = (void*) CompAlloc ( mem_op, result->cai->size ); if ( !result->value ) return 0; - result->cai->BER_Decode (b, result->value, (int*)bytesDecoded, - DEC_ALLOC_MODE_1); + result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1); - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny; @@ -1696,25 +1862,25 @@ BDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mod } int -GDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) { +GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) { ComponentAny *k, **k2; k = (ComponentAny*) result; if ( mode & DEC_ALLOC_MODE_0 ) { k2 = (ComponentAny**) result; - *k2 = (ComponentAny*) malloc( sizeof( ComponentAny) ); + *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) ); + if ( !*k2 ) return LDAP_DECODING_ERROR; k = *k2; } if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) { - result->value = (void*) malloc ( result->cai->size ); + result->value = (void*) CompAlloc ( mem_op, result->cai->size ); if ( !result->value ) return 0; - result->cai->GSER_Decode (b, result->value, (int*)bytesDecoded, - DEC_ALLOC_MODE_1); - k->comp_desc = malloc( sizeof( ComponentDesc ) ); - if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) { - free ( *k2 ); - return -1; + result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1); + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + if ( !k->comp_desc ) { + if ( k ) CompFree ( mem_op, k ); + return LDAP_DECODING_ERROR; } k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny; k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny; @@ -1760,9 +1926,9 @@ MatchingComponentAny (char* oid, ComponentAny *result, ComponentAny *result2) { } void* -ExtractingComponentAny ( ComponentReference* cr, ComponentAny *result ) { +ExtractingComponentAny ( void* mem_op, ComponentReference* cr, ComponentAny *result ) { if ((result->cai != NULL) && (result->cai->Extract != NULL)) { - return (void*) result->cai->Extract( cr , result->value ); + return (void*) result->cai->Extract( mem_op, cr , result->value ); } else { Asn1Error ("ERROR - ANY Extracting routine is NULL\n"); @@ -1791,7 +1957,7 @@ InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size, ComponentAnyInfo *a; Hash h; - a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo)); + a = (ComponentAnyInfo*) malloc(sizeof (ComponentAnyInfo)); a->anyId = anyId; a->oid.octs = NULL; a->oid.octetLen = 0; @@ -1848,6 +2014,7 @@ InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size, int BDecComponentTop ( ber_decoder_func *decoder _AND_ +void* mem_op _AND_ GenBuf *b _AND_ AsnTag tag _AND_ AsnLen elmtLen _AND_ @@ -1861,7 +2028,7 @@ int mode) { exit (1); } - return (*decoder)( b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode ); + return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode ); } #endif diff --git a/contrib/slapd-modules/comp_match/init.c b/contrib/slapd-modules/comp_match/init.c index c41de4270c..0858efb75a 100644 --- a/contrib/slapd-modules/comp_match/init.c +++ b/contrib/slapd-modules/comp_match/init.c @@ -147,30 +147,34 @@ comp_convert_attr_to_comp LDAP_P (( Attribute* a, Syntax *syn, struct berval* bv * The flag of Attribute will say something about it in the future */ if ( slap_syntax_is_ber ( syn ) ) { - rc =BDecComponentTop(od_entry->oe_ber_decoder, b, 0,0, - &component,&bytesDecoded,mode ) ; + rc =BDecComponentTop(od_entry->oe_ber_decoder, a->a_comp_data->cd_mem_op, b, 0,0, &component,&bytesDecoded,mode ) ; } else { - rc = od_entry->oe_gser_decoder(b, component,&bytesDecoded,mode); + rc = od_entry->oe_gser_decoder( a->a_comp_data->cd_mem_op, b, component,&bytesDecoded,mode); } - if ( rc == -1 ) + + if ( rc == -1 ) { + ShutdownNibbleMemLocal ( a->a_comp_data->cd_mem_op ); + a->a_comp_data->cd_mem_op = NULL; return (void*)NULL; + } else return component; } +#include void -comp_free_component LDAP_P (( ComponentSyntaxInfo *csi )) { - if ( csi->csi_comp_desc->cd_free ) - csi->csi_comp_desc->cd_free(csi); - free ( csi->csi_comp_desc ); - free ( csi ); +comp_free_component ( void* mem_op ) { + ShutdownNibbleMemLocal( (NibbleMem*)mem_op ); return; } int -comp_convert_assert_to_comp LDAP_P (( ComponentSyntaxInfo *csi_attr, struct berval* bv, - ComponentSyntaxInfo** csi, int* len, int mode )) +comp_convert_assert_to_comp ( + void* mem_op, + ComponentSyntaxInfo *csi_attr, + struct berval* bv, + ComponentSyntaxInfo** csi, int* len, int mode ) { GenBuf* genBuf; ExpBuf* buf; @@ -186,12 +190,11 @@ comp_convert_assert_to_comp LDAP_P (( ComponentSyntaxInfo *csi_attr, struct berv if ( csi_attr->csi_comp_desc->cd_type_id == BASICTYPE_ANY ) decoder = ((ComponentAny*)csi_attr)->cai->GSER_Decode; - return (*decoder)( genBuf, csi, len, mode ); + return (*decoder)( mem_op, genBuf, csi, len, mode ); } int intToAscii( int value, char* buf ) { int minus=0,i,temp; - char digit; int total_num_digits; if ( value == 0 ){ @@ -212,7 +215,7 @@ int intToAscii( int value, char* buf ) { total_num_digits += minus; for ( i = minus ; value ; i++ ) { - buf[ total_num_digits - i ]= (char)(value%10 + '0'); + buf[ total_num_digits - i - 1 ]= (char)(value%10 + '0'); value = value/10; } return i; @@ -312,6 +315,283 @@ comp_convert_asn_to_ldap LDAP_P(( ComponentSyntaxInfo* csi, struct berval* bv )) return LDAP_SUCCESS; } +/* + * If type component referenced is used + * more than one component will be tested + */ +#define IS_TERMINAL_COMPREF(cr) (cr->cr_curr->ci_next == NULL) +int +comp_test_all_components ( + void* mem_op, + ComponentSyntaxInfo *csi_attr, + ComponentAssertion* ca ) +{ + int rc; + ComponentSyntaxInfo *csi_temp = NULL, *csi_assert = NULL, *comp_elmt = NULL; + ComponentReference *cr = ca->ca_comp_ref; + struct berval *ca_val = &ca->ca_ma_value; + + switch ( cr->cr_curr->ci_type ) { + case LDAP_COMPREF_IDENTIFIER: + case LDAP_COMPREF_FROM_BEGINNING: + case LDAP_COMPREF_FROM_END: + csi_temp = (ComponentSyntaxInfo*)csi_attr->csi_comp_desc->cd_extract_i( mem_op, cr, csi_attr ); + if ( cr->cr_curr->ci_type == LDAP_COMPREF_ALL ) { + rc = comp_test_all_components ( mem_op, csi_temp, ca ); + } else { + rc = comp_test_one_component( mem_op, csi_temp, ca ); + } + break; + case LDAP_COMPREF_COUNT: + /* "count" component reference should be the last component id */ + if ( IS_TERMINAL_COMPREF(cr) ) { + ComponentInt *k; + k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt) ); + k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); + k->comp_desc->cd_tag = 0; + k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; + k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_INTEGER; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt; + k->value = AsnListCount(&((ComponentList*)csi_attr)->comp_list); + rc = comp_test_one_component( mem_op, k, ca ); + } else { + rc = LDAP_INVALID_SYNTAX; + } + break; + case LDAP_COMPREF_ALL: + if ( IS_TERMINAL_COMPREF(cr) ) { + FOR_EACH_LIST_ELMT( comp_elmt, &((ComponentList*)csi_attr)->comp_list ) + { + rc = comp_test_one_component( mem_op, comp_elmt, ca ); + if ( rc == LDAP_COMPARE_TRUE ) { + break; + } + } + } else { + ComponentId *start_compid = ca->ca_comp_ref->cr_curr->ci_next; + FOR_EACH_LIST_ELMT( comp_elmt, &((ComponentList*)csi_attr)->comp_list ) + { + cr->cr_curr = start_compid; + csi_temp = comp_elmt->csi_comp_desc->cd_extract_i( mem_op, cr, comp_elmt ); + if ( cr->cr_curr->ci_type == LDAP_COMPREF_ALL ) { + rc = comp_test_all_components ( mem_op, csi_temp, ca ); + } else { + rc = comp_test_one_component ( mem_op, csi_temp, ca ); + } + + if ( rc == LDAP_COMPARE_TRUE ) { + break; + } + } + } + break; + case LDAP_COMPREF_CONTENT: + case LDAP_COMPREF_SELECT: + case LDAP_COMPREF_DEFINED: + case LDAP_COMPREF_UNDEFINED: + rc = LDAP_OPERATIONS_ERROR; + break; + default: + rc = LDAP_OPERATIONS_ERROR; + } + return rc; +} + +void +eat_bv_whsp ( struct berval* in ) +{ + char* end = in->bv_val + in->bv_len; + for ( ; ( *in->bv_val == ' ' ) && ( in->bv_val < end ) ; ) { + in->bv_val++; + } +} + +int +get_primitive_GSER_value ( struct berval* in ) +{ + int count, sequent_dquote, unclosed_brace, succeed; + char* ptr = in->bv_val; + char* end = in->bv_val + in->bv_len; + + eat_bv_whsp( in ); + /* + * Four cases of GSER + * 1) "..." : + * StringVal, GeneralizedTimeVal, UTCTimeVal, ObjectDescriptorVal + * 2) '...'B or '...'H : + * BitStringVal, OctetStringVal + * 3) {...} : + * SEQUENCE, SEQUENCEOF, SETOF, SET, CHOICE, BIT STRING(bit list) + * 4) Between two white spaces + * INTEGER, BOOLEAN, NULL,ENUMERATE, REAL + */ + + if ( in->bv_len <= 0 ) + return LDAP_INVALID_SYNTAX; + + succeed = 0; + if ( ptr[0] == '"' ) { + for( count = 1, sequent_dquote = 0 ; ; count++ ) { + /* In order to find escaped double quote */ + if ( ptr[count] == '"' ) sequent_dquote++; + else sequent_dquote = 0; + + if ( ptr[count] == '\0' || (ptr + count) > end ) { + break; + } + + if ( ( ptr[count] == '"' && ptr[count-1] != '"') || + ( sequent_dquote > 2 && (sequent_dquote%2) == 1 ) ) { + succeed = 1; + break; + } + } + + if ( !succeed || ptr[count] != '"' ) + return LDAP_FILTER_ERROR; + + in->bv_val = ptr+1; /*the next to '"'*/ + in->bv_len = count - 1; /* exclude '"' */ + } + else if ( ptr[0] == '\'' ) { + for( count = 1 ; ; count++ ) { + if ( ptr[count] == '\0' || (ptr+count) > end ) { + break; + } + if ((ptr[count-1] == '\'' && ptr[count] == 'B')|| + (ptr[count-1] == '\'' && ptr[count] == 'H') ) { + succeed = 1; + break; + } + } + + if ( !succeed || !(ptr[count] == 'H' || ptr[count] == 'B') ) + return LDAP_FILTER_ERROR; + + in->bv_val = ptr+1; /* the next to '"' */ + in->bv_len = count - 2; /* exclude "'H" or "'B" */ + + } + else if ( ptr[0] == '{' ) { + for( count = 1, unclosed_brace = 1 ; ; count++ ) { + if ( ptr[count] == '{' ) unclosed_brace++; + if ( ptr[count] == '}' ) unclosed_brace--; + + if ( ptr[count] == '\0' || (ptr+count) > end ) + break; + if ( unclosed_brace == 0 ) { + succeed = 1; + break; + } + } + + if ( !succeed || ptr[count] != '}' ) + return LDAP_FILTER_ERROR; + + in->bv_val = ptr+1; /*the next to '"'*/ + in->bv_len = count - 1; /* exclude '"' */ + } + else { + /*Find following white space where the value is ended*/ + for( count = 1 ; ; count++ ) { + if ( ptr[count] == '\0' || ptr[count] == ' ' || + (ptr+count) >end ) { + break; + } + } + if ( ptr[count] != ' ' ) + return LDAP_FILTER_ERROR; + + in->bv_val = ptr; /*the next to '"'*/ + in->bv_len = count; /* exclude '"' */ + } + + return LDAP_SUCCESS; +} + +/* + * Perform matching one referenced component against assertion + * If the matching rule in a component filter is allComponentsMatch + * or its derivatives the extracted component's ASN.1 specification + * is applied to the assertion value as its syntax + * Otherwise, the matching rule's syntax is applied to the assertion value + * By RFC 3687 + */ +int +comp_test_one_component ( + void* mem_op, + ComponentSyntaxInfo *csi_attr, + ComponentAssertion *ca ) +{ + int len; + ComponentSyntaxInfo *csi_assert = NULL; + char* oid = NULL; + MatchingRule* mr = ca->ca_ma_rule; + + if ( mr->smr_usage & SLAP_MR_COMPONENT ) { + /* If allComponentsMatch or its derivatives */ + if ( !ca->ca_comp_data.cd_tree ) { + comp_convert_assert_to_comp( mem_op, csi_attr, &ca->ca_ma_value, &csi_assert, &len, DEC_ALLOC_MODE_0 ); + ca->ca_comp_data.cd_tree = (void*)csi_assert; + } else { + csi_assert = ca->ca_comp_data.cd_tree; + } + + if ( !csi_assert ) + return LDAP_PROTOCOL_ERROR; + + if ( strcmp( mr->smr_mrule.mr_oid, OID_ALL_COMP_MATCH ) != 0 ) + { + /* allComponentMatch's derivatives */ + oid = mr->smr_mrule.mr_oid; + } + return csi_attr->csi_comp_desc->cd_all_match( + oid, csi_attr, csi_assert ); + + } else { + /* LDAP existing matching rules */ + struct berval attr_bv; + struct berval* assert_bv = &ca->ca_ma_value; + char attr_buf[MAX_LDAP_STR_LEN]; + if ( csi_attr->csi_comp_desc->cd_type == ASN_BASIC ) { + /*Attribute component is converted to compatible LDAP encodings*/ + attr_bv.bv_val = attr_buf; + if ( comp_convert_asn_to_ldap( csi_attr, &attr_bv ) != LDAP_SUCCESS ) + return LDAP_INAPPROPRIATE_MATCHING; + + /*Assertion value is validated by MR's syntax*/ + if ( get_primitive_GSER_value( assert_bv ) != LDAP_SUCCESS ) + return LDAP_INVALID_SYNTAX; + + if ( mr->smr_syntax->ssyn_validate( mr->smr_syntax, assert_bv ) != LDAP_SUCCESS ) { + return LDAP_INVALID_SYNTAX; + } + + return csi_value_match( mr, &attr_bv, assert_bv ); + + } else if ( csi_attr->csi_comp_desc->cd_type == ASN_COMPOSITE ) { + return LDAP_INAPPROPRIATE_MATCHING; + } + + } +} + +void* +comp_nibble_memory_allocator ( int init_mem, int inc_mem ) { + void* nm; + nm = InitNibbleMemLocal( init_mem, inc_mem ); + if ( !nm ) return NULL; + else return (void*)nm; +} + +void +comp_nibble_memory_free ( void* nm ) { + ShutdownNibbleMemLocal( nm ); +} + #if SLAPD_COMP_MATCH == SLAPD_MOD_DYNAMIC #include "certificate.h" @@ -320,6 +600,11 @@ extern convert_attr_to_comp_func* attr_converter; extern convert_assert_to_comp_func* assert_converter; extern convert_asn_to_ldap_func* csi_converter; extern free_component_func* component_destructor; +extern test_component_func* test_one_component; +extern test_component_func* test_all_components; +extern alloc_nibble_func* nibble_mem_allocator; +extern free_nibble_func* nibble_mem_free; + int init_module(int argc, char *argv[]) { /* @@ -329,8 +614,14 @@ int init_module(int argc, char *argv[]) { assert_converter = comp_convert_assert_to_comp; csi_converter = comp_convert_asn_to_ldap; component_destructor = comp_free_component; + test_one_component = comp_test_one_component; + test_all_components = comp_test_all_components; + nibble_mem_allocator = comp_nibble_memory_allocator; + nibble_mem_free = comp_nibble_memory_free; + /* file path needs to be */ load_derived_matching_rule ("derived_mr.cfg"); + /* the initialization for example X.509 certificate */ init_module_AuthenticationFramework(); return 0; diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index 0513a9d2d5..07c3e4df31 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -50,9 +50,9 @@ attr_free( Attribute *a ) ber_bvarray_free( a->a_nvals ); ber_bvarray_free( a->a_vals ); #ifdef LDAP_COMP_MATCH - if ( component_destructor && a->a_component_values ) { - component_destructor(a->a_component_values); - a->a_component_values = NULL; + if ( component_destructor && a->a_comp_data && a->a_comp_data->cd_mem_op ) { + component_destructor( a->a_comp_data->cd_mem_op ); + free ( a->a_comp_data ); } #endif free( a ); @@ -118,7 +118,7 @@ attr_dup( Attribute *a ) tmp->a_next = NULL; tmp->a_flags = 0; #ifdef LDAP_COMP_MATCH - tmp->a_component_values = NULL; + tmp->a_comp_data = NULL; #endif return tmp; @@ -181,7 +181,7 @@ attr_merge( (*a)->a_next = NULL; (*a)->a_flags = 0; #ifdef LDAP_COMP_MATCH - (*a)->a_component_values = NULL; + (*a)->a_comp_data = NULL; #endif } @@ -265,7 +265,7 @@ attr_merge_one( (*a)->a_next = NULL; (*a)->a_flags = 0; #ifdef LDAP_COMP_MATCH - (*a)->a_component_values = NULL; + (*a)->a_comp_data = NULL; #endif } diff --git a/servers/slapd/component.c b/servers/slapd/component.c index fea68cb748..8060adb285 100644 --- a/servers/slapd/component.c +++ b/servers/slapd/component.c @@ -32,10 +32,14 @@ * This three function pointers are initialized * when a component module is loaded */ +alloc_nibble_func* nibble_mem_allocator = NULL; +free_nibble_func* nibble_mem_free = NULL; convert_attr_to_comp_func* attr_converter = NULL ; convert_assert_to_comp_func* assert_converter = NULL ; convert_asn_to_ldap_func* csi_converter = NULL ; free_component_func* component_destructor = NULL ; +test_component_func* test_one_component = NULL; +test_component_func* test_all_components = NULL; #define OID_ALL_COMP_MATCH "1.2.36.79672281.1.13.6" #define OID_COMP_FILTER_MATCH "1.2.36.79672281.1.13.2" @@ -117,6 +121,19 @@ componentFilterMatch ( } } +int +directoryComponentsMatch( + int *matchp, + slap_mask_t flags, + Syntax *syntax, + MatchingRule *mr, + struct berval *value, + void *assertedValue ) +{ + /* Only for Registeration */ + *matchp = 0; + return LDAP_SUCCESS; +} int allComponentsMatch( @@ -137,12 +154,8 @@ slapd_ber2cav( struct berval* bv, ComponentAssertionValue* cav) { int len; - len = ldap_pvt_filter_value_unescape( bv->bv_val ); - if ( len == -1 ) { - return LDAP_FILTER_ERROR; - } cav->cav_ptr = cav->cav_buf = bv->bv_val; - cav->cav_end = bv->bv_val + len; + cav->cav_end = bv->bv_val + bv->bv_len; return LDAP_SUCCESS; } @@ -273,15 +286,22 @@ get_componentId( Operation *op, ComponentAssertionValue* cav, cav->cav_ptr++; break; case LDAP_COMPREF_CONTENT : - /* FIXEME: yet to be implemented */ + _cid.ci_val.ci_content = 1; + cav->cav_ptr += strlen("content"); break; case LDAP_COMPREF_SELECT : - /* FIXEME: yet to be implemented */ + if ( cav->cav_ptr[len] != '(' ) + return LDAP_COMPREF_UNDEFINED; + for( ;cav->cav_ptr[len] != ' ' && cav->cav_ptr[len] != '\0' && + cav->cav_ptr[len] != '.' && cav->cav_ptr[len] != '\"' && + cav->cav_ptr[len] != ')' ; len++ ); + _cid.ci_val.ci_select_value.bv_val = cav->cav_ptr + 1; + _cid.ci_val.ci_select_value.bv_len = len - 1 ; + cav->cav_ptr += len; break; case LDAP_COMPREF_ALL : _cid.ci_val.ci_all = '*'; cav->cav_ptr++; - Debug( LDAP_DEBUG_FILTER, "get_compId : ALL\n", 0, 0, 0 ); break; default : return LDAP_COMPREF_UNDEFINED; @@ -302,6 +322,8 @@ peek_componentId_type( ComponentAssertionValue* cav ) return LDAP_COMPREF_SELECT; else if ( cav->cav_ptr[0] == '*' ) return LDAP_COMPREF_ALL; + else if ( strncmp(cav->cav_ptr,"all",3) == 0 ) + return LDAP_COMPREF_ALL; else if ( cav->cav_ptr[0] == '0' ) return LDAP_COMPREF_COUNT; else if ( cav->cav_ptr[0] > '0' && cav->cav_ptr[0] <= '9' ) @@ -338,11 +360,15 @@ get_component_reference( Operation *op, ComponentAssertionValue* cav, ComponentId** cr_list; eat_whsp( cav ); + + if ( ( rc = strip_cav_str( cav,"\"") ) != LDAP_SUCCESS ) + return rc; + ca_comp_ref = op->o_tmpalloc( sizeof( ComponentReference ), op->o_tmpmemctx ); cr_list = &ca_comp_ref->cr_list; - strip_cav_str( cav, "\""); + for ( type = peek_componentId_type( cav ) ; type != LDAP_COMPREF_UNDEFINED ; type = comp_next_id( cav ), count++ ) { rc = get_componentId( op, cav, cr_list, text ); @@ -354,7 +380,11 @@ get_component_reference( Operation *op, ComponentAssertionValue* cav, return rc; } ca_comp_ref->cr_len = count; - strip_cav_str( cav, "\""); + + if ( ( rc = strip_cav_str( cav,"\"") ) != LDAP_SUCCESS ) { + op->o_tmpfree( ca_comp_ref , op->o_tmpmemctx ); + return rc; + } if ( rc == LDAP_SUCCESS ) { *cr = ca_comp_ref; @@ -369,21 +399,15 @@ static int get_ca_use_default( Operation *op, ComponentAssertionValue* cav, int* ca_use_def, const char** text ) { - if ( peek_cav_str( cav, "useDefaultValues" ) == LDAP_SUCCESS ) { - strip_cav_str( cav, "useDefaultValues" ); - if ( peek_cav_str( cav, "TRUE" ) == LDAP_SUCCESS ) { - strip_cav_str( cav, "TRUE" ); - *ca_use_def = 1; - } else if ( peek_cav_str( cav, "FALSE" ) == LDAP_SUCCESS ) { - strip_cav_str( cav, "FALSE" ); - *ca_use_def = 0; - } else { - return LDAP_INVALID_SYNTAX; - } - - } else { - /* If not defined, default value is TRUE */ + strip_cav_str( cav, "useDefaultValues" ); + if ( peek_cav_str( cav, "TRUE" ) == LDAP_SUCCESS ) { + strip_cav_str( cav, "TRUE" ); *ca_use_def = 1; + } else if ( peek_cav_str( cav, "FALSE" ) == LDAP_SUCCESS ) { + strip_cav_str( cav, "FALSE" ); + *ca_use_def = 0; + } else { + return LDAP_INVALID_SYNTAX; } return LDAP_SUCCESS; @@ -447,7 +471,7 @@ get_GSER_value( ComponentAssertionValue* cav, struct berval* bv ) if ( cav->cav_ptr[count] == '"' ) sequent_dquote++; else sequent_dquote = 0; - if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) { + if ( cav->cav_ptr[count] == '\0' || (cav->cav_ptr+count) > cav->cav_end ) { break; } @@ -460,7 +484,7 @@ get_GSER_value( ComponentAssertionValue* cav, struct berval* bv ) } else if ( cav->cav_ptr[0] == '\'' ) { for( count = 1 ; ; count++ ) { - if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) { + if ( cav->cav_ptr[count] == '\0' || (cav->cav_ptr+count) > cav->cav_end ) { break; } if ((cav->cav_ptr[count-1] == '\'' && cav->cav_ptr[count] == 'B')|| @@ -476,7 +500,7 @@ get_GSER_value( ComponentAssertionValue* cav, struct berval* bv ) if ( cav->cav_ptr[count] == '{' ) unclosed_brace++; if ( cav->cav_ptr[count] == '}' ) unclosed_brace--; - if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) + if ( cav->cav_ptr[count] == '\0' || (cav->cav_ptr+count) > cav->cav_end ) break; if ( unclosed_brace == 0 ) { succeed = 1; @@ -486,13 +510,18 @@ get_GSER_value( ComponentAssertionValue* cav, struct berval* bv ) } else { succeed = 1; - count = cav->cav_end - cav->cav_ptr; + /*Find following white space where the value is ended*/ + for( count = 1 ; ; count++ ) { + if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr[count] == ' ' || (cav->cav_ptr+count) > cav->cav_end ) { + break; + } + } } if ( !succeed ) return LDAP_FILTER_ERROR; bv->bv_val = cav->cav_ptr; - bv->bv_len = count + 1 ; + bv->bv_len = count ; cav->cav_ptr += count; return LDAP_SUCCESS; } @@ -587,7 +616,8 @@ get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca, Debug( LDAP_DEBUG_FILTER, "get_item: %s\n", 0, 0, 0 ); _ca = op->o_tmpalloc( sizeof( ComponentAssertion ), op->o_tmpmemctx ); - _ca->ca_component_values = NULL; + _ca->ca_comp_data.cd_tree = NULL; + _ca->ca_comp_data.cd_mem_op = NULL; rc = peek_cav_str( cav, "component" ); if ( rc == LDAP_SUCCESS ) { @@ -600,7 +630,9 @@ get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca, } } - strip_cav_str( cav,","); + if ( ( rc = strip_cav_str( cav,",") ) != LDAP_SUCCESS ) + return rc; + rc = peek_cav_str( cav, "useDefaultValues"); if ( rc == LDAP_SUCCESS ) { rc = get_ca_use_default( op, cav, &_ca->ca_use_def, text ); @@ -609,8 +641,10 @@ get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca, op->o_tmpfree( _ca, op->o_tmpmemctx ); return rc; } - strip_cav_str( cav,","); + if ( ( rc = strip_cav_str( cav,",") ) != LDAP_SUCCESS ) + return rc; } + else _ca->ca_use_def = 1; if ( !( strip_cav_str( cav, "rule" ) == LDAP_SUCCESS && get_matching_rule( op, cav , &_ca->ca_ma_rule, text ) == LDAP_SUCCESS )) { @@ -619,7 +653,8 @@ get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca, return rc; } - strip_cav_str( cav,","); + if ( ( rc = strip_cav_str( cav,",") ) != LDAP_SUCCESS ) + return rc; if ( !(strip_cav_str( cav, "value" ) == LDAP_SUCCESS && get_matching_value( op, _ca, cav, &_ca->ca_ma_value,text ) == LDAP_SUCCESS )) { rc = LDAP_INVALID_SYNTAX; @@ -815,7 +850,7 @@ test_comp_filter_or( return rtn; } -static int +int csi_value_match( MatchingRule *mr, struct berval* bv_attr, struct berval* bv_assert ) { @@ -873,15 +908,11 @@ component_value_match( MatchingRule* mr, return LDAP_INAPPROPRIATE_MATCHING; } } - - /* FIXME: what should be returned here? Is this rachable at all? */ - return LDAP_INAPPROPRIATE_MATCHING; } /* * return codes : LDAP_COMPARE_TRUE, LDAP_COMPARE_FALSE */ - static int test_comp_filter_item( Syntax *syn, @@ -891,6 +922,7 @@ test_comp_filter_item( { int rc, len; ComponentSyntaxInfo* csi_attr, *csi_assert=NULL; + void *attr_nm, *assert_nm; if ( strcmp(ca->ca_ma_rule->smr_mrule.mr_oid, OID_COMP_FILTER_MATCH ) == 0 && ca->ca_cf ) { @@ -900,32 +932,54 @@ test_comp_filter_item( } /* load attribute containg components */ - /* For a testing purpose, link following function here */ - if ( !a->a_component_values && attr_converter ) - a->a_component_values = attr_converter (a, syn, bv); + if ( !a->a_comp_data && attr_converter && nibble_mem_allocator ) { + a->a_comp_data = malloc( sizeof( ComponentData ) ); + /* Memory chunk pre-allocation for decoders */ + a->a_comp_data->cd_mem_op = (void*) nibble_mem_allocator ( 1024, 128 ); + a->a_comp_data->cd_tree = attr_converter (a, syn, bv); + } - if ( a->a_component_values == NULL ) + if ( a->a_comp_data->cd_tree == NULL ) { + free ( a->a_comp_data ); return LDAP_PROTOCOL_ERROR; + } - /* load component containg the referenced component */ + /* Memory for storing will-be-extracted attribute values */ + attr_nm = nibble_mem_allocator ( 256, 64 ); + if ( !attr_nm )return LDAP_PROTOCOL_ERROR; + /* component reference initialization */ ca->ca_comp_ref->cr_curr = ca->ca_comp_ref->cr_list; - csi_attr = (((ComponentSyntaxInfo*)a->a_component_values)->csi_comp_desc->cd_extract_i)( ca->ca_comp_ref, a->a_component_values ); - + /* load component containg the referenced component */ + csi_attr = (((ComponentSyntaxInfo*)a->a_comp_data->cd_tree)->csi_comp_desc->cd_extract_i)( attr_nm, ca->ca_comp_ref, a->a_comp_data->cd_tree ); if ( !csi_attr ) return LDAP_PROTOCOL_ERROR; - /* decode the asserted value */ - if( !ca->ca_component_values && assert_converter ) { - assert_converter ( csi_attr, &ca->ca_ma_value, - &csi_assert, &len, DEC_ALLOC_MODE_0 ); - ca->ca_component_values = (void*)csi_assert; + /* Memory for storing component assertion values */ + assert_nm = nibble_mem_allocator ( 256, 64 ); + if ( !assert_nm ) return LDAP_PROTOCOL_ERROR; + /* perform matching */ + if ( ca->ca_comp_ref->cr_curr->ci_type == LDAP_COMPREF_ALL ) { + /* + * If type component referenced is used + * more than one component will be tested + */ + if ( test_all_components ) + rc = test_all_components ( assert_nm, csi_attr, ca ); + else + rc = LDAP_PROTOCOL_ERROR; + } else { + /* + * Exactly one component is referenced + * Fast Path for matching for this case + */ + if ( test_one_component ) + rc = test_one_component ( assert_nm, csi_attr, ca ); + else + rc = LDAP_PROTOCOL_ERROR; } - else csi_assert = ca->ca_component_values; - - if ( !csi_assert ) - return LDAP_PROTOCOL_ERROR; - - return component_value_match( ca->ca_ma_rule, csi_attr, csi_assert); + /* free memory used for storing extracted attribute value */ + nibble_mem_free ( attr_nm ); + return rc; } static int @@ -993,8 +1047,8 @@ free_comp_filter( ComponentFilter* f ) break; case LDAP_COMP_FILTER_ITEM: - if ( component_destructor && f->cf_ca->ca_component_values ) - component_destructor( f->cf_ca->ca_component_values ); + if ( nibble_mem_free && f->cf_ca->ca_comp_data.cd_mem_op ) + nibble_mem_free( f->cf_ca->ca_comp_data.cd_mem_op ); break; default: diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index c636b130c6..e89772e985 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -663,7 +663,7 @@ int entry_decode(struct berval *bv, Entry **e) a->a_vals = bptr; a->a_flags = 0; #ifdef LDAP_COMP_MATCH - a->a_component_values = NULL; + a->a_comp_data = NULL; #endif count = j = entry_getlen(&ptr); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index e27d7e973a..06a6d469cd 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -352,11 +352,13 @@ LDAP_SLAPD_F (int) componentFilterMatch LDAP_P(( struct berval *value, void *assertedValue )); -#define componentCertificateMatch componentFilterMatch - -LDAP_SLAPD_F (int) componentCertificateValidate LDAP_P(( - Syntax *syntax, - struct berval* bv )); +LDAP_SLAPD_F (int) directoryComponentsMatch LDAP_P(( + int *matchp, + slap_mask_t flags, + Syntax *syntax, + MatchingRule *mr, + struct berval *value, + void *assertedValue )); LDAP_SLAPD_F (int) allComponentsMatch LDAP_P(( int *matchp, diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 0c87aadb59..a63f3492dd 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -3339,6 +3339,13 @@ static slap_mrule_defs_rec mrule_defs[] = { NULL, NULL , allComponentsMatch, octetStringIndexer, octetStringFilter, NULL }, + + {"( 1.2.36.79672281.1.13.7 NAME 'directoryComponentsMatch' " + "SYNTAX 1.2.36.79672281.1.5.3 )", + SLAP_MR_EQUALITY|SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL, + NULL, NULL , directoryComponentsMatch, + octetStringIndexer, octetStringFilter, + NULL }, #endif {"( 2.5.13.2 NAME 'caseIgnoreMatch' " diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 116b060d6f..3b917b1e63 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1028,6 +1028,13 @@ typedef struct slap_valuesreturnfilter { struct slap_valuesreturnfilter *vrf_next; } ValuesReturnFilter; +#ifdef LDAP_COMP_MATCH +typedef struct slap_component_data { + void* cd_mem_op;/* nibble memory handler */ + void* cd_tree; /* component tree */ +} ComponentData; +#endif + /* * represents an attribute (description + values) */ @@ -1035,13 +1042,13 @@ typedef struct slap_attr { AttributeDescription *a_desc; BerVarray a_vals; /* preserved values */ BerVarray a_nvals; /* normalized values */ +#ifdef LDAP_COMP_MATCH + ComponentData *a_comp_data; /* component values */ +#endif struct slap_attr *a_next; unsigned a_flags; #define SLAP_ATTR_IXADD 0x1U #define SLAP_ATTR_IXDEL 0x2U -#ifdef LDAP_COMP_MATCH - void* a_component_values; /* component values */ -#endif } Attribute; @@ -2677,6 +2684,7 @@ typedef struct slap_component_id{ ber_int_t ci_from_beginning; ber_int_t ci_count; ber_int_t ci_from_end; + ber_int_t ci_content; BerValue ci_select_value; char ci_all; } ci_val; @@ -2694,7 +2702,7 @@ typedef struct slap_component_assertion { ber_int_t ca_use_def; MatchingRule *ca_ma_rule; struct berval ca_ma_value; - void* ca_component_values; + ComponentData ca_comp_data; /* componentized assertion */ struct slap_component_filter *ca_cf; MatchingRuleAssertion *ca_mra; } ComponentAssertion; @@ -2730,6 +2738,7 @@ typedef int encoder_func LDAP_P(( struct slap_component_syntax_info; typedef int gser_decoder_func LDAP_P(( + void* mem_op, void* b, struct slap_component_syntax_info** comp_syn_info, int* len, @@ -2739,6 +2748,7 @@ typedef int comp_free_func LDAP_P(( void* b)); typedef int ber_decoder_func LDAP_P(( + void* mem_op, void* b, int tag, int elmtLen, @@ -2747,12 +2757,14 @@ typedef int ber_decoder_func LDAP_P(( int mode)); typedef int ber_tag_decoder_func LDAP_P(( + void* mem_op, void* b, struct slap_component_syntax_info* comp_syn_info, int* len, int mode)); typedef void* extract_component_from_id_func LDAP_P(( + void* mem_op, ComponentReference* cr, void* comp )); @@ -2761,8 +2773,15 @@ typedef void* convert_attr_to_comp_func LDAP_P (( Syntax* syn, struct berval* bv )); +typedef void* alloc_nibble_func LDAP_P (( + int initial_size, + int increment_size )); + +typedef void free_nibble_func LDAP_P (( + void* nm )); + struct slap_component_syntax_info; -typedef int convert_assert_to_comp_func LDAP_P (( +typedef void* convert_assert_to_comp_func LDAP_P (( struct slap_component_syntax_info* csi_attr, struct berval* bv, struct slap_component_syntax_info** csi, @@ -2774,7 +2793,12 @@ typedef int convert_asn_to_ldap_func LDAP_P (( struct berval *bv )); typedef void free_component_func LDAP_P (( - struct slap_component_syntax_info* csi )); + void* mem_op)); + +typedef int test_component_func LDAP_P (( + void* mem_op, + struct slap_component_syntax_info* csi, + struct slap_component_assertion* ca)); typedef int allcomponent_matching_func LDAP_P(( char* oid, @@ -2785,6 +2809,7 @@ typedef struct slap_component_desc{ int cd_tag; int cd_type; int cd_type_id; + int cd_compref_type; gser_decoder_func *cd_gser_decoder; ber_decoder_func *cd_ber_decoder; comp_free_func *cd_free; diff --git a/tests/data/compsearch.out b/tests/data/compsearch.out index 6142363b16..eac55a008a 100644 --- a/tests/data/compsearch.out +++ b/tests/data/compsearch.out @@ -32,6 +32,57 @@ userCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQswCQYDV dAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9a+4Xr EkBJ/Q= +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com +objectClass: OpenLDAPperson +objectClass: extensibleObject +uid:: Y2hhcmxpZSA= +cn: charlie +sn: Jee +userCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQswCQYDV + QQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTMIGfMA + 0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2QP3MO + NBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+tTMnA + KUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4EFgQUA + zNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihEaQPMA + 0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44laoKcTyS + uz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5rD5Ue + dAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9a+4Xr + EkBJ/Q= + +dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com +objectClass: OpenLDAPperson +objectClass: extensibleObject +uid:: Y2hhcmxpZSA= +cn: beta +sn: Jee +userCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQswCQYDV + QQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTMIGfMA + 0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2QP3MO + NBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+tTMnA + KUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4EFgQUA + zNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihEaQPMA + 0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44laoKcTyS + uz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5rD5Ue + dAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9a+4Xr + EkBJ/Q= + +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com +objectClass: OpenLDAPperson +objectClass: extensibleObject +uid:: Y2hhcmxpZSA= +cn: charlie +sn: Jee +userCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQswCQYDV + QQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTMIGfMA + 0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2QP3MO + NBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+tTMnA + KUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4EFgQUA + zNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihEaQPMA + 0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44laoKcTyS + uz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5rD5Ue + dAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9a+4Xr + EkBJ/Q= + dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject diff --git a/tests/scripts/test031-component-filter b/tests/scripts/test031-component-filter index d9adf0928b..ed9147515f 100755 --- a/tests/scripts/test031-component-filter +++ b/tests/scripts/test031-component-filter @@ -147,6 +147,45 @@ if test $RC != 0 ; then exit $RC fi +FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.extensions.0\", rule integerMatch, value 3 })" +echo " f=$FILTER ..." +echo "# f=$FILTER ..." >> $SEARCHOUT +$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ + "$FILTER" >> $SEARCHOUT 2>&1 + +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +FILTER="(userCertificate:componentFilterMatch:=item:{component \"tbsCertificate.extensions.\2a.extnID\",rule allComponentsMatch, value 2.5.29.14 })" +echo " f=$FILTER ..." +echo "# f=$FILTER ..." >> $SEARCHOUT +$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ + "$FILTER" >> $SEARCHOUT 2>&1 + +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +FILTER="(userCertificate:componentFilterMatch:=not:item:{component \"tbsCertificate.extensions.\2a\",rule allComponentsMatch, value { extnID 2.5.29.19 , extnValue '30030101FF'H })" +echo " f=$FILTER ..." +echo "# f=$FILTER ..." >> $SEARCHOUT +$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ + "$FILTER" >> $SEARCHOUT 2>&1 + +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + test $KILLSERVERS != no && kill -HUP $KILLPIDS