From 71e78dd7f9abf7ad73dce19a3ceb44af99efe009 Mon Sep 17 00:00:00 2001 From: Sang Seok Lim Date: Wed, 27 Oct 2004 19:37:02 +0000 Subject: [PATCH] Component Matching module See "contrib/slapd-modules/comp_match/README" to understand what's the purpose of this patch is and how to use it. --- configure | 5 + configure.in | 1 + contrib/slapd-modules/comp_match/Makefile | 60 + contrib/slapd-modules/comp_match/README | 87 + contrib/slapd-modules/comp_match/asn.h | 58 + .../slapd-modules/comp_match/asn_to_syn_mr.c | 77 + .../slapd-modules/comp_match/certificate.asn1 | 91 + .../slapd-modules/comp_match/certificate.c | 3171 +++++++++++++++++ .../slapd-modules/comp_match/certificate.h | 405 +++ contrib/slapd-modules/comp_match/component.h | 517 +++ .../slapd-modules/comp_match/componentlib.c | 1867 ++++++++++ contrib/slapd-modules/comp_match/init.c | 339 ++ servers/slapd/asn.h | 3 +- servers/slapd/component.c | 380 +- servers/slapd/filterentry.c | 33 +- servers/slapd/mra.c | 6 +- servers/slapd/proto-slap.h | 19 + servers/slapd/schema/core.schema | 6 +- servers/slapd/schema_init.c | 22 +- servers/slapd/search.c | 2 +- servers/slapd/slap.h | 83 +- servers/slapd/value.c | 1 - tests/data/compsearch.out | 161 +- tests/data/slapd-component.conf | 2 +- tests/data/test-compmatch.ldif | 18 +- tests/run.in | 4 +- tests/scripts/test031-component-filter | 40 +- 27 files changed, 7217 insertions(+), 241 deletions(-) create mode 100644 contrib/slapd-modules/comp_match/Makefile create mode 100644 contrib/slapd-modules/comp_match/README create mode 100644 contrib/slapd-modules/comp_match/asn.h create mode 100644 contrib/slapd-modules/comp_match/asn_to_syn_mr.c create mode 100644 contrib/slapd-modules/comp_match/certificate.asn1 create mode 100644 contrib/slapd-modules/comp_match/certificate.c create mode 100644 contrib/slapd-modules/comp_match/certificate.h create mode 100644 contrib/slapd-modules/comp_match/component.h create mode 100644 contrib/slapd-modules/comp_match/componentlib.c create mode 100644 contrib/slapd-modules/comp_match/init.c diff --git a/configure b/configure index 89f783d4d4..fed488a250 100755 --- a/configure +++ b/configure @@ -1795,9 +1795,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} @@ -24051,6 +24053,7 @@ EOF fi +WITH_MODULES_ENABLED=no if test "$ol_link_modules" != no ; then cat >> confdefs.h <<\EOF #define SLAPD_MODULES 1 @@ -24058,6 +24061,7 @@ EOF BUILD_SLAPD=yes SLAPD_MODULES_LDFLAGS="-dlopen self" + WITH_MODULES_ENABLED=yes fi cat >> confdefs.h <<\EOF @@ -24707,6 +24711,7 @@ s%@LIBSRCS@%$LIBSRCS%g s%@PLAT@%$PLAT%g s%@WITH_SASL@%$WITH_SASL%g s%@WITH_TLS@%$WITH_TLS%g +s%@WITH_MODULES_ENABLED@%$WITH_MODULES_ENABLED%g s%@BUILD_LIBS_DYNAMIC@%$BUILD_LIBS_DYNAMIC%g s%@BUILD_SLAPD@%$BUILD_SLAPD%g s%@BUILD_SLAPI@%$BUILD_SLAPI%g diff --git a/configure.in b/configure.in index c931ce07e8..6c233ee2bd 100644 --- a/configure.in +++ b/configure.in @@ -2883,6 +2883,7 @@ AC_SUBST(LIBSRCS) AC_SUBST(PLAT) AC_SUBST(WITH_SASL) AC_SUBST(WITH_TLS) +AC_SUBST(WITH_MODULES_ENABLED) AC_SUBST(BUILD_LIBS_DYNAMIC) AC_SUBST(BUILD_SLAPD) diff --git a/contrib/slapd-modules/comp_match/Makefile b/contrib/slapd-modules/comp_match/Makefile new file mode 100644 index 0000000000..ddddb505fb --- /dev/null +++ b/contrib/slapd-modules/comp_match/Makefile @@ -0,0 +1,60 @@ +# $OpenLDAP$ +# This work is part of OpenLDAP Software . +# +# Copyright 2003-2004 The OpenLDAP Foundation. +# Portions Copyright 2004 by IBM Corporation. +# All rights reserved. + +# Copyright 2004 Sang Seok Lim, IBM Corp. All Rights Reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted only as authorized by the OpenLDAP +# Public License. +# +# A copy of this license is available in the file LICENSE in the +# top-level directory of the distribution or, alternatively, at +# . + +topbuilddir = ../../../../build +topsrcdir = ../../.. +snaccdir = /home/slim/snacc + +LIBTOOL=$(topbuilddir)/libtool +OPT=-g -finstrument-functions -DLDAP_COMPONENT +CC=gcc + +SNACC_INC=-I$(snaccdir) -I$(snaccdir)/c-lib/inc + +LDAP_INC=-I$(topsrcdir)/include -I$(topsrcdir)/servers/slapd -I$(topbuilddir)/include +INCS=$(LDAP_INC) $(SNACC_INC) + +SNACC_LIB=$(snaccdir)/c-lib/libcasn1.a +SSL_LIB=-lcrypto +LDAP_LIB=-lldap_r -llber +LIBS=$(LDAP_LIB) $(SNACC_LIB) $(SSL_LIB) /home/slim/local/lib/libfnccheck.a + +all: compmatch.la + + +componentlib.lo: componentlib.c + $(LIBTOOL) --mode=compile $(CC) $(OPT) $(INCS) -c $? + +certificate.lo: certificate.c + $(LIBTOOL) --mode=compile $(CC) $(OPT) $(INCS) -c $? + +asn_to_syn_mr.lo: asn_to_syn_mr.c + $(LIBTOOL) --mode=compile $(CC) $(OPT) $(INCS) -c $? + +init.lo: init.c + $(LIBTOOL) --mode=compile $(CC) $(OPT) $(INCS) -c $? + +compmatch.la: componentlib.lo init.lo certificate.lo asn_to_syn_mr.lo + $(LIBTOOL) --mode=link $(CC) $(OPT) $(LIBS) -version-info 0:0:0 \ + -rpath /home/slim/ldap/local/libexec/openldap -module -o $@ $? $(LIBS) + +clean: + \rm compmatch.la componentlib.lo certificate.lo asn_to_syn_mr.lo\ + init.o init.lo componentlib.o certificate.o asn_to_syn_mr.o +install: + cp -r .libs $(topsrcdir)/tests/data/comp_libs + cp compmatch.la $(topsrcdir)/tests/data/comp_libs diff --git a/contrib/slapd-modules/comp_match/README b/contrib/slapd-modules/comp_match/README new file mode 100644 index 0000000000..be79884274 --- /dev/null +++ b/contrib/slapd-modules/comp_match/README @@ -0,0 +1,87 @@ +Copyright 2004 Sang Seok Lim, IBM . All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted only as authorized by the OpenLDAP +Public License. + +A copy of this license is available in the file LICENSE in the +top-level directory of the distribution or, alternatively, at +. + +This directory contains a Component Matching module +and a X.509 Certificate example. +In order to understand Component Matching, see RFC 3687 +and http://www.openldap.org/conf/odd-sandiego-2004/Sangseok.pdf + +Brief introduction about files in this directory + +1) init.c +module_init() and four functions which are dynamically linked into the main slapd codes +comp_convert_attr_to_comp : decode an attribute value into a component tree +comp_convert_assert_to_comp : decode an assertion value into a component tree + using the decoder of the extracted component. +comp_convert_asn_to_ldap : transform ASN.1 type values into a LDAP string. +comp_free_component : free memory allocated by GSER or BER decoders + +2) componentlib.c and component.h +GSER and BER decoder library of each ASN.1 type. They +use component representation to store ASN.1 values. + +3) certificate.c certificate.h cacert.pem +eSNACC generated BER and GSER decoder routines of the X.509 certificate +specification, or certificate.asn1 in the directory. cacert.pem +is generated by openssl to test this module. + +4) asn_to_syn_mr.c asn.h +An mapping table from ASN.1 types to corresponding Syntaxes and +matching rules in slapd. If the validate function of the mapped syntax +exists, it will be called to validate the decoded ASN.1 value. + +How to compile and test the module with the certificate example + +1) be sure to configure slapd with enable-modules on. +2) install an eSNACC compiler. At least, you should have library and +header files to compile the module. +3) modify Makefile accordingly. then execute make. +you will get compmatch.la and other necessary files in ./libs +4) modify slapd.conf to include the following module command + moduleload compmatch.la +5) run slapd and perform ldapsearch on the attribute, or componentCertificatea +(preregistered example attribute defined by the certificate) +--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. + +How to add a new ASN.1 syntax other than the example + +1) download and install an eSNACC compiler supporting Component Matching +in www.openldap.org. Before compiling, be sure to define +a "LDAP_COMPONENT" macro to obtain component +supported version of C library and back-ends of eSNACC. Otherwise compiled +library fails to be linked to module. +2) using eSNACc, compile your ASN.1 specifications and copy the generated c files +to this directory +Ex) $ esnacc -E BER_COMP -E GSER -t -d -f example.asn +For Component Matching, set BOTH BER_COMP and GSER on. +After compiling, you will get example.c and example.h +3) modify example.c accordingly, seeing certificate.c and certificate.asn +as a reference. +- modify parameters of add_OD_entry(...) in init_module_xxx(...) in example.c. +you need a new OID to register this module into slapd. +- add init_module_xxx() into init_module() in init.c +4) modify asn.h and asn_to_syn_mr.c accordingly. add new enum ID. +5) register a new attribute syntax with a new OID in a schema file +6) then goto 3) above. + +Current Status +The generated functions such as GSER/BER decoders, extractor +allComponentMatch for a X.509 certificate ASN.1 specification (certificate.asn) +have been tested successfully. But this is currently under development. +before using it, don't forget to check following status of development, +1) Not all ASN.1 types are supported yet. +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 diff --git a/contrib/slapd-modules/comp_match/asn.h b/contrib/slapd-modules/comp_match/asn.h new file mode 100644 index 0000000000..d018598b9d --- /dev/null +++ b/contrib/slapd-modules/comp_match/asn.h @@ -0,0 +1,58 @@ +/* Copyright 2004 IBM Corporation + * All rights reserved. + * Redisribution and use in source and binary forms, with or without + * modification, are permitted only as authorizd by the OpenLADP + * Public License. + */ +/* ACKNOWLEDGEMENTS + * This work originally developed by Sang Seok Lim + * 2004/06/18 03:20:00 slim@OpenLDAP.org + */ +#ifndef _H_ASN_MODULE +#define _H_ASN_MODULE + +typedef enum { BER, GSER } EncRulesType; +typedef enum { ASN_BASIC, ASN_COMPOSITE } AsnType; + +typedef enum AsnTypeId { + BASICTYPE_BOOLEAN, + BASICTYPE_INTEGER, + BASICTYPE_BITSTRING, + BASICTYPE_OCTETSTRING, + BASICTYPE_NULL, + BASICTYPE_OID, + BASICTYPE_REAL, + BASICTYPE_ENUMERATED, + BASICTYPE_NUMERIC_STR, + BASICTYPE_PRINTABLE_STR, + BASICTYPE_UNIVERSAL_STR, + BASICTYPE_IA5_STR, + BASICTYPE_BMP_STR, + BASICTYPE_UTF8_STR, + BASICTYPE_UTCTIME, + BASICTYPE_GENERALIZEDTIME, + BASICTYPE_GRAPHIC_STR, + BASICTYPE_VISIBLE_STR, + BASICTYPE_GENERAL_STR, + BASICTYPE_OBJECTDESCRIPTOR, + BASICTYPE_VIDEOTEX_STR, + BASICTYPE_T61_STR, + BASICTYPE_OCTETCONTAINING, + BASICTYPE_BITCONTAINING, + BASICTYPE_RELATIVE_OID, /* 25 */ + BASICTYPE_ANY, + /* Embedded Composite Types*/ + COMPOSITE_ASN1_TYPE, + /* A New ASN.1 types including type reference */ + RDNSequence, + RelativeDistinguishedName, + TelephoneNumber, + FacsimileTelephoneNumber__telephoneNumber, + DirectoryString, + /* Newly Defined ASN.1 Type, Manually registered */ + ASN_COMP_CERTIFICATE, + /* ASN.1 Type End */ + ASNTYPE_END +} AsnTypeId; + +#endif diff --git a/contrib/slapd-modules/comp_match/asn_to_syn_mr.c b/contrib/slapd-modules/comp_match/asn_to_syn_mr.c new file mode 100644 index 0000000000..faf616df62 --- /dev/null +++ b/contrib/slapd-modules/comp_match/asn_to_syn_mr.c @@ -0,0 +1,77 @@ +#include "asn.h" +#include "component.h" + +AsnTypetoMatchingRuleTable directory_component_matching_table = { + "1.2.36.79672281.1.13.7", +{ + { BASICTYPE_BOOLEAN,NULL,"1.3.6.1.4.1.1466.115.121.1.7", NULL }, + { BASICTYPE_INTEGER,NULL ,"1.3.6.1.4.1.1466.115.121.1.27", NULL }, + { BASICTYPE_BITSTRING,NULL ,"1.3.6.1.4.1.1466.115.121.1.6", NULL }, + { BASICTYPE_OCTETSTRING,NULL , "1.3.6.1.4.1.1466.115.121.1.40", NULL }, + { BASICTYPE_NULL,NULL , NULL, NULL }, + { BASICTYPE_OID,NULL ,"1.3.6.1.4.1.1466.115.121.1.38", NULL }, + { BASICTYPE_REAL,NULL , NULL, NULL }, + { BASICTYPE_ENUMERATED,NULL , NULL, NULL }, + { BASICTYPE_NUMERIC_STR, "numericStringMatch", "1.3.6.1.4.1.1466.115.121.1.36", NULL }, + { BASICTYPE_PRINTABLE_STR, "caseIgnoreMatch", "1.3.6.1.4.1.1466.115.121.1.44", NULL }, + { BASICTYPE_UNIVERSAL_STR, "caseIgnoreMatch" , NULL, NULL }, + { BASICTYPE_IA5_STR, "caseIgnoreMatch", "1.3.6.1.4.1.1466.115.121.1.26", NULL }, + { BASICTYPE_BMP_STR, "caseIgnoreMatch" , NULL, NULL }, + { BASICTYPE_UTF8_STR, "caseIgnoreMatch" , NULL, NULL }, + { BASICTYPE_UTCTIME, "uTCTimeMatch" , "1.3.6.1.4.1.1466.115.121.1.53", NULL }, + { BASICTYPE_GENERALIZEDTIME, "generalizedTimeMatch" ,"1.3.6.1.4.1.1466.115.121.1.24", NULL }, + { BASICTYPE_GRAPHIC_STR, "caseIgnoreMatch", NULL, NULL }, + { BASICTYPE_VISIBLE_STR, "caseIgnoreMatch", NULL, NULL }, + { BASICTYPE_GENERAL_STR, "caseIgnoreMatch", NULL, NULL }, + { BASICTYPE_OBJECTDESCRIPTOR, NULL , NULL, NULL }, + { BASICTYPE_VIDEOTEX_STR, "caseIgnoreMatch", NULL, NULL }, + { BASICTYPE_T61_STR, "caseIgnoreMatch", NULL, NULL }, + { BASICTYPE_OCTETCONTAINING, NULL , NULL, NULL }, + { BASICTYPE_BITCONTAINING, NULL , NULL, NULL }, + { BASICTYPE_RELATIVE_OID, NULL, "1.2.36.79672281.1.5.0", NULL }, + { RDNSequence, "distinguishedNameMatch" , NULL, NULL }, + { RelativeDistinguishedName, NULL , NULL, NULL }, + { TelephoneNumber, "telephoneNumberMatch" , "1.3.6.1.4.1.1466.115.121.1.50", NULL }, + { FacsimileTelephoneNumber__telephoneNumber, "telephoneNumberMatch","1.3.6.1.4.1.1466.115.121.1.22", NULL }, + { DirectoryString, "caseIgnoreMatch" ,"1.3.6.1.4.1.1466.115.121.1.15", NULL }, + { ASN_COMP_CERTIFICATE, NULL , "1.2.36.79672281.1.5.2" , NULL }, + { ASNTYPE_END , NULL , NULL, NULL } +}, + NULL +}; + +struct asntype_to_syntax asn_to_syntax_mapping_tbl[] = { +{ BASICTYPE_BOOLEAN,"Boolean","1.3.6.1.4.1.1466.115.121.1.7", NULL }, +{ BASICTYPE_INTEGER,"Integer","1.3.6.1.4.1.1466.115.121.1.27", NULL }, +{ BASICTYPE_BITSTRING,"Bit String","1.3.6.1.4.1.1466.115.121.1.6", NULL }, +{ BASICTYPE_OCTETSTRING,"Octet String", "1.3.6.1.4.1.1466.115.121.1.40", NULL }, +{ BASICTYPE_NULL,NULL, NULL, NULL }, +{ BASICTYPE_OID,"OID","1.3.6.1.4.1.1466.115.121.1.38", NULL }, +{ BASICTYPE_REAL,NULL, NULL, NULL }, +{ BASICTYPE_ENUMERATED,"Integer", "1.3.6.1.4.1.1466.115.121.1.27", NULL }, +{ BASICTYPE_NUMERIC_STR, "Numeric String", "1.3.6.1.4.1.1466.115.121.1.36", NULL }, +{ BASICTYPE_PRINTABLE_STR, "Printable String", "1.3.6.1.4.1.1466.115.121.1.44", NULL }, +{ BASICTYPE_UNIVERSAL_STR, NULL , NULL, NULL }, +{ BASICTYPE_IA5_STR, "IA5 String", "1.3.6.1.4.1.1466.115.121.1.26", NULL }, +{ BASICTYPE_BMP_STR, NULL , NULL, NULL }, +{ BASICTYPE_UTF8_STR, "Directory String" , "1.3.6.1.4.1.1466.115.121.1.15", NULL }, +{ BASICTYPE_UTCTIME, "UTC Time" , "1.3.6.1.4.1.1466.115.121.1.53", NULL }, +{ BASICTYPE_GENERALIZEDTIME, "Generalized Time" ,"1.3.6.1.4.1.1466.115.121.1.24", NULL }, +{ BASICTYPE_GRAPHIC_STR, NULL, NULL, NULL }, +{ BASICTYPE_VISIBLE_STR, "Directory String", "1.3.6.1.4.1.1466.115.121.1.15", NULL }, +{ BASICTYPE_GENERAL_STR, NULL, NULL, NULL }, +{ BASICTYPE_OBJECTDESCRIPTOR, "Object Class Description", "1.3.6.1.4.1.1466.115.121.1.37", NULL }, +{ BASICTYPE_VIDEOTEX_STR, NULL, NULL, NULL }, +{ BASICTYPE_T61_STR, NULL, NULL, NULL }, +{ BASICTYPE_OCTETCONTAINING, NULL , NULL, NULL }, +{ BASICTYPE_BITCONTAINING, NULL , NULL, NULL }, +{ BASICTYPE_RELATIVE_OID, "OID", "1.3.6.1.4.1.1466.115.121.1.38", NULL }, +{ BASICTYPE_ANY, NULL, NULL, NULL }, +{ RDNSequence, "RDN" , "1.2.36.79672281.1.5.0", NULL }, +{ RelativeDistinguishedName, "RDN", "1.2.36.79672281.1.5.0", NULL }, +{ TelephoneNumber, "Telephone Number" , "1.3.6.1.4.1.1466.115.121.1.50", NULL }, +{ FacsimileTelephoneNumber__telephoneNumber, "Facsimile Telephone Number","1.3.6.1.4.1.1466.115.121.1.22", NULL }, +{ DirectoryString, "Directory String" ,"1.3.6.1.4.1.1466.115.121.1.15", NULL }, +{ ASN_COMP_CERTIFICATE, "componentCertificate", "1.2.36.79672281.1.5.2" , NULL }, +{ ASNTYPE_END , NULL , NULL, NULL } +}; diff --git a/contrib/slapd-modules/comp_match/certificate.asn1 b/contrib/slapd-modules/comp_match/certificate.asn1 new file mode 100644 index 0000000000..ee85d08395 --- /dev/null +++ b/contrib/slapd-modules/comp_match/certificate.asn1 @@ -0,0 +1,91 @@ +AuthenticationFramework {joint-iso-itu-t ds(5) module(1) authenticationFramework(7) 4} DEFINITIONS ::= +BEGIN +-- based on RFC 3280 and X.509 + +Certificate ::= SEQUENCE { + tbsCertificate TBSCertificate, + signatureAlgorithm AlgorithmIdentifier, + signature BIT STRING +} + +TBSCertificate ::= SEQUENCE { + version [0] Version DEFAULT v1, + serialNumber CertificateSerialNumber, + signature AlgorithmIdentifier, + issuer Name, + validity Validity, + subject Name, + subjectPublicKeyInfo SubjectPublicKeyInfo, + issuerUniqueIdentifier [1] IMPLICIT UniqueIdentifier OPTIONAL, + -- if present, version shall be v2 or v3 + subjectUniqueIdentifier [2] IMPLICIT UniqueIdentifier OPTIONAL, + -- if present, version shall be v2 or v3 + extensions [3] Extensions OPTIONAL + -- If present, version shall be v3 -- } + +Version ::= INTEGER { v1(0), v2(1), v3(2) } + +CertificateSerialNumber ::= INTEGER + +AlgorithmIdentifier ::= SEQUENCE { + algorithm OBJECT IDENTIFIER, + parameters ANY DEFINED BY algorithm OPTIONAL -- DSA, SHA-1-- +} + +Name ::= CHOICE { + rdnSequence RDNSequence } + +RDNSequence ::= SEQUENCE OF RelativeDistinguishedName + +RelativeDistinguishedName ::= SET OF AttributeTypeAndValue + +AttributeTypeAndValue ::= SEQUENCE { + type AttributeType, + value ANY DEFINED BY type} + +AttributeType ::= OBJECT IDENTIFIER + +Validity ::= SEQUENCE { + notBefore Time, + notAfter Time } + +UniqueIdentifier ::= BIT STRING + +SubjectPublicKeyInfo ::= SEQUENCE { + algorithm AlgorithmIdentifier, + subjectPublicKey BIT STRING } + +Time ::= CHOICE { + utcTime UTCTime, + generalizedTime GeneralizedTime } + +Extensions ::= SEQUENCE SIZE(1..MAX) OF Extension + +Extension ::= SEQUENCE { + extnID OBJECT IDENTIFIER, +-- critical BOOLEAN DEFAULT FALSE, + extnValue OCTET STRING +-- contains a DER encoding of a value of type &ExtnType +-- for the extension object identified by extnId -- +} + +nullOid OBJECT-TYPE + SYNTAX NULL + ACCESS read-write + STATUS mandatory + ::= { 1 2 840 113549 1 1 4 } + +nullOid2 OBJECT-TYPE + SYNTAX NULL + ACCESS read-write + STATUS mandatory + ::= { 1 2 840 113549 1 1 1 } + +printableStringOid OBJECT-TYPE + SYNTAX PrintableString + ACCESS read-write + STATUS mandatory + ::= { 2 5 4 6 } + + +END diff --git a/contrib/slapd-modules/comp_match/certificate.c b/contrib/slapd-modules/comp_match/certificate.c new file mode 100644 index 0000000000..89da6cf7c4 --- /dev/null +++ b/contrib/slapd-modules/comp_match/certificate.c @@ -0,0 +1,3171 @@ +/* + * 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 + * The generated files are supposed to be compiled as a module for OpenLDAP Software + */ + +#include "certificate.h" + + +void init_module_AuthenticationFramework() { + add_OD_entry ( "1.3.6.1.4.1.4203.666.1.34", GDecComponentCertificate, + BDecComponentCertificate, NULL); + InitAnyAuthenticationFramework(); +} + +void InitAnyAuthenticationFramework() +{ + AsnOid oid0 ={ 9, "\52\206\110\206\367\15\1\1\4" }; + AsnOid oid1 ={ 9, "\52\206\110\206\367\15\1\1\1" }; + AsnOid oid2 ={ 3, "\125\4\6" }; + + + InstallAnyByComponentOid (nullOid_ANY_ID, &oid0, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL); + + InstallAnyByComponentOid (nullOid2_ANY_ID, &oid1, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL); + + InstallAnyByComponentOid (printableStringOid_ANY_ID, &oid2, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); + +} /* InitAnyAuthenticationFramework */ + + +int +MatchingComponentAlgorithmIdentifier ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentOid ( oid, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->algorithm, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_assert)->algorithm ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = SetAnyTypeByComponentOid ((ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (&((ComponentAlgorithmIdentifier*)csi_attr)->algorithm)); + rc = MatchingComponentAnyDefinedBy ( oid, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_assert)->parameters); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentAlgorithmIdentifier */ + +void* +ExtractingComponentAlgorithmIdentifier ( 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 ( 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 ( cr->cr_curr->ci_next == NULL ) + return &comp->parameters; + else + return NULL; + } + return NULL; +} /* ExtractingComponentAlgorithmIdentifier */ + +int +BDecComponentAlgorithmIdentifier PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentAlgorithmIdentifier **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentAlgorithmIdentifier *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentOid (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"); + if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) + seqDone = TRUE; + else + { + tagId1 = BufPeekByte (b); + if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) + { + BDecEoc (b, &totalElmtsLen1 ); + seqDone = TRUE; + } + } + } + else + return -1; + + + + if (!seqDone) { + SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm)); + BDecComponentAnyDefinedBy (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"); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentAlgorithmIdentifier*) malloc( sizeof(ComponentAlgorithmIdentifier) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAlgorithmIdentifier; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecAlgorithmIdentifier*/ + +int +GDecComponentAlgorithmIdentifier PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentAlgorithmIdentifier **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentAlgorithmIdentifier *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentOid (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm)); + GDecComponentAnyDefinedBy (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)) ) { + Asn1Error("Error during Reading } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentAlgorithmIdentifier*) malloc( sizeof(ComponentAlgorithmIdentifier) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAlgorithmIdentifier; + 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 ) { + int rc; + MatchingRule* mr; + ComponentTime *v1, *v2; + + + v1 = (ComponentTime*)csi_attr; + v2 = (ComponentTime*)csi_assert; + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + if( (v1->choiceId != v2->choiceId ) ) + return LDAP_COMPARE_FALSE; + switch( v1->choiceId ) + { + case TIME_UTCTIME : + rc = MatchingComponentUTCTime ( oid, (ComponentSyntaxInfo*)(v1->a.utcTime), (ComponentSyntaxInfo*)(v2->a.utcTime) ); + break; + case TIME_GENERALIZEDTIME : + rc = MatchingComponentGeneralizedTime ( oid, (ComponentSyntaxInfo*)(v1->a.generalizedTime), (ComponentSyntaxInfo*)(v2->a.generalizedTime) ); + break; + default : + return LDAP_PROTOCOL_ERROR; + } + return rc; +} /* BMatchingComponentTimeContent */ + +void* +ExtractingComponentTime ( 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) || + ( 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) ); + }; + } + 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) || + ( 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 NULL; +} /* ExtractingComponentTime */ + +int +BDecComponentTime PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentTime **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentTime *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + switch (tagId0) + { + 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 ); + (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"); + break; + + 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 ); + (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"); + break; + + default: + Asn1Error ("ERROR - unexpected tag in CHOICE\n"); + return -1; + break; + } /* end switch */ + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentTime*) malloc( sizeof(ComponentTime) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentTime; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTime; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecTimeContent */ + +int +GDecComponentTime PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentTime **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentTime *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen2 = LocateNextGSERToken(b,&peek_head2,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head2 != ':'){ + Asn1Error("Missing : in encoded data"); + return LDAP_PROTOCOL_ERROR; + } + if( strncmp("utcTime",peek_head,sizeof("utcTime")-1) == 0){ + (k->choiceId) = TIME_UTCTIME; + rc = GDecComponentUTCTime (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 ); + if ( rc != LDAP_SUCCESS ) return rc; + (k->a.generalizedTime)->identifier.bv_val = peek_head; + (k->a.generalizedTime)->identifier.bv_len = strLen; + } + else { + Asn1Error("Undefined Identifier"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentTime*) malloc( sizeof(ComponentTime) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentTime; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTime; + 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 ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentOid ( oid, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_attr)->extnID, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_assert)->extnID ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentOcts ( oid, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_attr)->extnValue, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_assert)->extnValue ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentExtension */ + +void* +ExtractingComponentExtension ( 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 ( 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 ( cr->cr_curr->ci_next == NULL ) + return &comp->extnValue; + else + return NULL; + } + return NULL; +} /* ExtractingComponentExtension */ + +int +BDecComponentExtension PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentExtension **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentExtension *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentOid (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE)) || +(tagId1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentOcts (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"); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + else + return -1; + + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentExtension*) malloc( sizeof(ComponentExtension) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtension; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecExtension*/ + +int +GDecComponentExtension PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentExtension **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentExtension *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentOid (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentOcts (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)) ) { + Asn1Error("Error during Reading } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentExtension*) malloc( sizeof(ComponentExtension) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtension; + 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 ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentAttributeType ( oid, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->type, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_assert)->type ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = SetAnyTypeByComponentOid ((ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (&((ComponentAttributeTypeAndValue*)csi_attr)->type)); + rc = MatchingComponentAnyDefinedBy ( oid, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_assert)->value); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentAttributeTypeAndValue */ + +void* +ExtractingComponentAttributeTypeAndValue ( 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 ( 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 ( cr->cr_curr->ci_next == NULL ) + return &comp->value; + else + return NULL; + } + return NULL; +} /* ExtractingComponentAttributeTypeAndValue */ + +int +BDecComponentAttributeTypeAndValue PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentAttributeTypeAndValue **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentAttributeTypeAndValue *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentAttributeType (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"); + } + else + return -1; + + + + { + SetAnyTypeByComponentOid ((&k->value), (&k->type)); + BDecComponentAnyDefinedBy (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"); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentAttributeTypeAndValue*) malloc( sizeof(ComponentAttributeTypeAndValue) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAttributeTypeAndValue; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecAttributeTypeAndValue*/ + +int +GDecComponentAttributeTypeAndValue PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentAttributeTypeAndValue **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentAttributeTypeAndValue *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentAttributeType (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + SetAnyTypeByComponentOid ((&k->value), (&k->type)); + GDecComponentAnyDefinedBy (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)) ) { + Asn1Error("Error during Reading } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentAttributeTypeAndValue*) malloc( sizeof(ComponentAttributeTypeAndValue) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAttributeTypeAndValue; + 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 ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentValidity*)csi_attr)->notBefore, (ComponentSyntaxInfo*)((ComponentValidity*)csi_assert)->notBefore ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentValidity*)csi_attr)->notAfter, (ComponentSyntaxInfo*)((ComponentValidity*)csi_assert)->notAfter ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentValidity */ + +void* +ExtractingComponentValidity ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->notBefore; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentTime ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->notAfter; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentTime ( cr, comp->notAfter ); + } + } + return NULL; +} /* ExtractingComponentValidity */ + +int +BDecComponentValidity PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentValidity **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + AsnLen totalElmtsLen2 = 0; + AsnLen elmtLen2; + AsnTag tagId2; + ComponentValidity *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) || +(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) || + (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))|| + (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentTime (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) || +(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) || + (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))|| + (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentTime (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"); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + else + return -1; + + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentValidity*) malloc( sizeof(ComponentValidity) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentValidity; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecValidity*/ + +int +GDecComponentValidity PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentValidity **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentValidity *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentTime (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentTime (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)) ) { + Asn1Error("Error during Reading } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentValidity*) malloc( sizeof(ComponentValidity) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentValidity; + 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 ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentSubjectPublicKeyInfo*)csi_attr)->algorithm, (ComponentSyntaxInfo*)((ComponentSubjectPublicKeyInfo*)csi_assert)->algorithm ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentSubjectPublicKeyInfo*)csi_attr)->subjectPublicKey, (ComponentSyntaxInfo*)&((ComponentSubjectPublicKeyInfo*)csi_assert)->subjectPublicKey ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentSubjectPublicKeyInfo */ + +void* +ExtractingComponentSubjectPublicKeyInfo ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->algorithm; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentAlgorithmIdentifier ( 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 ( cr->cr_curr->ci_next == NULL ) + return &comp->subjectPublicKey; + else + return NULL; + } + return NULL; +} /* ExtractingComponentSubjectPublicKeyInfo */ + +int +BDecComponentSubjectPublicKeyInfo PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentSubjectPublicKeyInfo **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentSubjectPublicKeyInfo *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentAlgorithmIdentifier (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) || +(tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentBits (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"); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + else + return -1; + + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentSubjectPublicKeyInfo*) malloc( sizeof(ComponentSubjectPublicKeyInfo) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentSubjectPublicKeyInfo; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecSubjectPublicKeyInfo*/ + +int +GDecComponentSubjectPublicKeyInfo PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentSubjectPublicKeyInfo **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentSubjectPublicKeyInfo *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentAlgorithmIdentifier (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentBits (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)) ) { + Asn1Error("Error during Reading } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentSubjectPublicKeyInfo*) malloc( sizeof(ComponentSubjectPublicKeyInfo) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentSubjectPublicKeyInfo; + 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 ) { + int rc; + MatchingRule* mr; + void* component1, *component2; + AsnList *v1, *v2, t_list; + + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + v1 = &((ComponentExtensions*)csi_attr)->comp_list; + v2 = &((ComponentExtensions*)csi_assert)->comp_list; + FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2) + { + if( MatchingComponentExtension(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) { + return LDAP_COMPARE_FALSE; + } + } /* end of for */ + + if( (!component1 && component2) || (component1 && !component2)) + return LDAP_COMPARE_FALSE; + else + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentExtensionsContent */ + +void* +ExtractingComponentExtensions ( ComponentReference* cr, ComponentExtensions *comp ) +{ + int count = 0; + int total; + AsnList *v = &comp->comp_list; + ComponentInt *k; + ComponentExtension *component; + + + switch ( cr->cr_curr->ci_type ) { + case LDAP_COMPREF_FROM_BEGINNING : + count = cr->cr_curr->ci_val.ci_from_beginning; + FOR_EACH_LIST_ELMT( component , v ) { + if( --count == 0 ) { + if( cr->cr_curr->ci_next == NULL ) + return component; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return + ExtractingComponentExtension ( cr, component ); + } + } + } + break; + case LDAP_COMPREF_FROM_END : + total = AsnListCount ( v ); + count = cr->cr_curr->ci_val.ci_from_end; + count = total + count +1; + FOR_EACH_LIST_ELMT ( component, v ) { + if( --count == 0 ) { + if( cr->cr_curr->ci_next == NULL ) + return component; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return + ExtractingComponentExtension ( cr, component ); + } + } + } + break; + case LDAP_COMPREF_ALL : + return comp; + k = (ComponentInt*)malloc(sizeof(ComponentInt)); + k->comp_desc = malloc( 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; + 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(v); + return k; + default : + return NULL; + } +} /* ExtractingComponentExtensions */ + +int +BDecComponentExtensions PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentExtensions **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentExtensions *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)); + for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);) + { + ComponentExtension **tmpVar; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) + { + BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) + break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/ + } + if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + tmpVar = (ComponentExtension**) AsnListAppend (&k->comp_list); + BDecComponentExtension (b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); + } /* end of tag check if */ + else /* wrong tag */ + { + Asn1Error ("Unexpected Tag\n"); + return -1; + } + } /* end of for */ + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentExtensions*) malloc( sizeof(ComponentExtensions) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtensions; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecExtensionsContent */ + +int +GDecComponentExtensions PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentExtensions **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentExtensions *k,*t, c_temp; + + + int ElmtsLen1; + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)) ){ + Asn1Error("Error during Reading { in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '{'){ + Asn1Error("Missing { in encoded data"); + return LDAP_PROTOCOL_ERROR; + } + + for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) + { + ComponentExtension **tmpVar; + if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_NO_COPY)) ){ + Asn1Error("Error during Reading{ in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head == '}') break; + if( !(*peek_head == '{' || *peek_head ==',') ) { + return LDAP_PROTOCOL_ERROR; + } + tmpVar = (ComponentExtension**) AsnListAppend (&k->comp_list); + if ( tmpVar == NULL ) { + Asn1Error("Error during Reading{ in encoding"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentExtension (b, tmpVar, bytesDecoded, mode); + } /* end of for */ + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentExtensions*) malloc( sizeof(ComponentExtensions) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtensions; + 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 ) { + int rc; + MatchingRule* mr; + void* component1, *component2; + AsnList *v1, *v2, t_list; + + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + v1 = &((ComponentRelativeDistinguishedName*)csi_attr)->comp_list; + v2 = &((ComponentRelativeDistinguishedName*)csi_assert)->comp_list; + AsnListInit( &t_list, 0 ); + if( AsnListCount( v1 ) != AsnListCount( v2 ) ) + return LDAP_COMPARE_FALSE; + FOR_EACH_LIST_ELMT (component1, v1) + { + FOR_EACH_LIST_ELMT(component2, v2) + { + if( MatchingComponentAttributeTypeAndValue(oid, (ComponentSyntaxInfo*)component1,(ComponentSyntaxInfo*)component2) == LDAP_COMPARE_TRUE ) { + AsnElmtMove( v2, &t_list ); + break; + } + } /* end of inner for */ + } /* end of outer for */ + + if( AsnListCount( v2 ) == 0 ) + rc = LDAP_COMPARE_TRUE; + else + rc = LDAP_COMPARE_FALSE; + AsnListMove( &t_list, v2 ); + return rc; +} /* BMatchingComponentRelativeDistinguishedNameContent */ + +void* +ExtractingComponentRelativeDistinguishedName ( ComponentReference* cr, ComponentRelativeDistinguishedName *comp ) +{ + int count = 0; + int total; + AsnList *v = &comp->comp_list; + ComponentInt *k; + ComponentAttributeTypeAndValue *component; + + + switch ( cr->cr_curr->ci_type ) { + case LDAP_COMPREF_FROM_BEGINNING : + count = cr->cr_curr->ci_val.ci_from_beginning; + FOR_EACH_LIST_ELMT( component , v ) { + if( --count == 0 ) { + if( cr->cr_curr->ci_next == NULL ) + return component; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return + ExtractingComponentAttributeTypeAndValue ( cr, component ); + } + } + } + break; + case LDAP_COMPREF_FROM_END : + total = AsnListCount ( v ); + count = cr->cr_curr->ci_val.ci_from_end; + count = total + count +1; + FOR_EACH_LIST_ELMT ( component, v ) { + if( --count == 0 ) { + if( cr->cr_curr->ci_next == NULL ) + return component; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return + ExtractingComponentAttributeTypeAndValue ( cr, component ); + } + } + } + break; + case LDAP_COMPREF_ALL : + return comp; + k = (ComponentInt*)malloc(sizeof(ComponentInt)); + k->comp_desc = malloc( 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; + 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(v); + return k; + default : + return NULL; + } +} /* ExtractingComponentRelativeDistinguishedName */ + +int +BDecComponentRelativeDistinguishedName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentRelativeDistinguishedName **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentRelativeDistinguishedName *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)); + for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);) + { + ComponentAttributeTypeAndValue **tmpVar; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) + { + BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) + break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/ + } + if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + tmpVar = (ComponentAttributeTypeAndValue**) AsnListAppend (&k->comp_list); + BDecComponentAttributeTypeAndValue (b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); + } /* end of tag check if */ + else /* wrong tag */ + { + Asn1Error ("Unexpected Tag\n"); + return -1; + } + } /* end of for */ + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentRelativeDistinguishedName*) malloc( sizeof(ComponentRelativeDistinguishedName) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecRelativeDistinguishedNameContent */ + +int +GDecComponentRelativeDistinguishedName PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentRelativeDistinguishedName **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentRelativeDistinguishedName *k,*t, c_temp; + + + int ElmtsLen1; + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)) ){ + Asn1Error("Error during Reading { in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '{'){ + Asn1Error("Missing { in encoded data"); + return LDAP_PROTOCOL_ERROR; + } + + for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) + { + ComponentAttributeTypeAndValue **tmpVar; + if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_NO_COPY)) ){ + Asn1Error("Error during Reading{ in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head == '}') break; + if( !(*peek_head == '{' || *peek_head ==',') ) { + return LDAP_PROTOCOL_ERROR; + } + tmpVar = (ComponentAttributeTypeAndValue**) AsnListAppend (&k->comp_list); + if ( tmpVar == NULL ) { + Asn1Error("Error during Reading{ in encoding"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentAttributeTypeAndValue (b, tmpVar, bytesDecoded, mode); + } /* end of for */ + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentRelativeDistinguishedName*) malloc( sizeof(ComponentRelativeDistinguishedName) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName; + 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 ) { + int rc; + MatchingRule* mr; + void* component1, *component2; + AsnList *v1, *v2, t_list; + + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + v1 = &((ComponentRDNSequence*)csi_attr)->comp_list; + v2 = &((ComponentRDNSequence*)csi_assert)->comp_list; + FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2) + { + if( MatchingComponentRelativeDistinguishedName(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) { + return LDAP_COMPARE_FALSE; + } + } /* end of for */ + + if( (!component1 && component2) || (component1 && !component2)) + return LDAP_COMPARE_FALSE; + else + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentRDNSequenceContent */ + +void* +ExtractingComponentRDNSequence ( ComponentReference* cr, ComponentRDNSequence *comp ) +{ + int count = 0; + int total; + AsnList *v = &comp->comp_list; + ComponentInt *k; + ComponentRelativeDistinguishedName *component; + + + switch ( cr->cr_curr->ci_type ) { + case LDAP_COMPREF_FROM_BEGINNING : + count = cr->cr_curr->ci_val.ci_from_beginning; + FOR_EACH_LIST_ELMT( component , v ) { + if( --count == 0 ) { + if( cr->cr_curr->ci_next == NULL ) + return component; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return + ExtractingComponentRelativeDistinguishedName ( cr, component ); + } + } + } + break; + case LDAP_COMPREF_FROM_END : + total = AsnListCount ( v ); + count = cr->cr_curr->ci_val.ci_from_end; + count = total + count +1; + FOR_EACH_LIST_ELMT ( component, v ) { + if( --count == 0 ) { + if( cr->cr_curr->ci_next == NULL ) + return component; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return + ExtractingComponentRelativeDistinguishedName ( cr, component ); + } + } + } + break; + case LDAP_COMPREF_ALL : + return comp; + k = (ComponentInt*)malloc(sizeof(ComponentInt)); + k->comp_desc = malloc( 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; + 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(v); + return k; + default : + return NULL; + } +} /* ExtractingComponentRDNSequence */ + +int +BDecComponentRDNSequence PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentRDNSequence **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentRDNSequence *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)); + for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);) + { + ComponentRelativeDistinguishedName **tmpVar; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) + { + BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) + break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/ + } + if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + tmpVar = (ComponentRelativeDistinguishedName**) AsnListAppend (&k->comp_list); + BDecComponentRelativeDistinguishedName (b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); + } /* end of tag check if */ + else /* wrong tag */ + { + Asn1Error ("Unexpected Tag\n"); + return -1; + } + } /* end of for */ + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentRDNSequence*) malloc( sizeof(ComponentRDNSequence) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecRDNSequenceContent */ + +int +GDecComponentRDNSequence PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentRDNSequence **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentRDNSequence *k,*t, c_temp; + + + int ElmtsLen1; + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)) ){ + Asn1Error("Error during Reading { in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '{'){ + Asn1Error("Missing { in encoded data"); + return LDAP_PROTOCOL_ERROR; + } + + for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) + { + ComponentRelativeDistinguishedName **tmpVar; + if( !(strLen = LocateNextGSERToken(b, &peek_head, GSER_NO_COPY)) ){ + Asn1Error("Error during Reading{ in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head == '}') break; + if( !(*peek_head == '{' || *peek_head ==',') ) { + return LDAP_PROTOCOL_ERROR; + } + tmpVar = (ComponentRelativeDistinguishedName**) AsnListAppend (&k->comp_list); + if ( tmpVar == NULL ) { + Asn1Error("Error during Reading{ in encoding"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentRelativeDistinguishedName (b, tmpVar, bytesDecoded, mode); + } /* end of for */ + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentRDNSequence*) malloc( sizeof(ComponentRDNSequence) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence; + 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 ) { + int rc; + MatchingRule* mr; + ComponentName *v1, *v2; + + + v1 = (ComponentName*)csi_attr; + v2 = (ComponentName*)csi_assert; + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + if( (v1->choiceId != v2->choiceId ) ) + return LDAP_COMPARE_FALSE; + switch( v1->choiceId ) + { + case NAME_RDNSEQUENCE : + rc = MatchingComponentRDNSequence ( oid, (ComponentSyntaxInfo*)(v1->a.rdnSequence), (ComponentSyntaxInfo*)(v2->a.rdnSequence) ); + break; + default : + return LDAP_PROTOCOL_ERROR; + } + return rc; +} /* BMatchingComponentNameContent */ + +void* +ExtractingComponentName ( 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) || + ( 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 NULL; +} /* ExtractingComponentName */ + +int +BDecComponentName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentName **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentName *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + switch (tagId0) + { + case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE): + (k->choiceId) = NAME_RDNSEQUENCE; + BDecComponentRDNSequence (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"); + break; + + default: + Asn1Error ("ERROR - unexpected tag in CHOICE\n"); + return -1; + break; + } /* end switch */ + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentName*) malloc( sizeof(ComponentName) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentName; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecNameContent */ + +int +GDecComponentName PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentName **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentName *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen2 = LocateNextGSERToken(b,&peek_head2,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head2 != ':'){ + Asn1Error("Missing : in encoded data"); + return LDAP_PROTOCOL_ERROR; + } + if( strncmp("rdnSequence",peek_head,sizeof("rdnSequence")-1) == 0){ + (k->choiceId) = NAME_RDNSEQUENCE; + rc = GDecComponentRDNSequence (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; + } + else { + Asn1Error("Undefined Identifier"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentName*) malloc( sizeof(ComponentName) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentName; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName; + 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 ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentVersion ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->version, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->version ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentCertificateSerialNumber ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->serialNumber, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->serialNumber ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->signature ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->issuer, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->issuer ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentValidity ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->validity, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->validity ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subject, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subject ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentSubjectPublicKeyInfo ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subjectPublicKeyInfo, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subjectPublicKeyInfo ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->issuerUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->issuerUniqueIdentifier ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->subjectUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->subjectUniqueIdentifier ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + 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 ) +{ + + 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 ( cr->cr_curr->ci_next == NULL ) + return comp->version; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentVersion ( 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 ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->signature; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentAlgorithmIdentifier ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->issuer; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentName ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->validity; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentValidity ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->subject; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentName ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->subjectPublicKeyInfo; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentSubjectPublicKeyInfo ( 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 ( 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 ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->extensions; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentExtensions ( cr, comp->extensions ); + } + } + return NULL; +} /* ExtractingComponentTBSCertificate */ + +int +BDecComponentTBSCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentTBSCertificate **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + AsnLen totalElmtsLen2 = 0; + AsnLen elmtLen2; + AsnTag tagId2; + ComponentTBSCertificate *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (CNTX, CONS, 0)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + tagId2 = BDecTag (b, &totalElmtsLen1 ); + + if (tagId2 != MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)) + { + Asn1Error ("Unexpected Tag\n"); + return -1; + } + + elmtLen2 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentVersion (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"); + if (elmtLen1 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentCertificateSerialNumber (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentAlgorithmIdentifier (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentName (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentValidity (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentName (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentSubjectPublicKeyInfo (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"); + if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) + seqDone = TRUE; + else + { + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) + { + BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) + seqDone = TRUE; + } + } + } + else + return -1; + + + + if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 1)) || +(tagId1 == MAKE_TAG_ID (CNTX, CONS, 1)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentUniqueIdentifier (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"); + if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) + seqDone = TRUE; + else + { + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) + { + BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) + seqDone = TRUE; + } + } + } + + + if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 2)) || +(tagId1 == MAKE_TAG_ID (CNTX, CONS, 2)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentUniqueIdentifier (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"); + if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) + seqDone = TRUE; + else + { + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) + { + BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) + seqDone = TRUE; + } + } + } + + + if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, CONS, 3)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + tagId2 = BDecTag (b, &totalElmtsLen1 ); + + if (tagId2 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)) + { + Asn1Error ("Unexpected Tag\n"); + return -1; + } + + elmtLen2 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentExtensions (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"); + if (elmtLen1 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentTBSCertificate*) malloc( sizeof(ComponentTBSCertificate) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecTBSCertificate*/ + +int +GDecComponentTBSCertificate PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentTBSCertificate **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentTBSCertificate *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentVersion (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentCertificateSerialNumber (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentAlgorithmIdentifier (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentName (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentValidity (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentName (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentSubjectPublicKeyInfo (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentUniqueIdentifier (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentUniqueIdentifier (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentExtensions (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)) ) { + Asn1Error("Error during Reading } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentTBSCertificate*) malloc( sizeof(ComponentTBSCertificate) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate; + 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 ) { + int rc; + MatchingRule* mr; + + if ( oid ) { + mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); + if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); + } + + rc = 1; + rc = MatchingComponentTBSCertificate ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->tbsCertificate, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->tbsCertificate ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->signatureAlgorithm, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->signatureAlgorithm ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + rc = MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_assert)->signature ); + if ( rc != LDAP_COMPARE_TRUE ) + return rc; + return LDAP_COMPARE_TRUE; +} /* BMatchingComponentCertificate */ + +void* +ExtractingComponentCertificate ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->tbsCertificate; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentTBSCertificate ( 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 ( cr->cr_curr->ci_next == NULL ) + return comp->signatureAlgorithm; + else { + cr->cr_curr = cr->cr_curr->ci_next; + return ExtractingComponentAlgorithmIdentifier ( 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 ( cr->cr_curr->ci_next == NULL ) + return &comp->signature; + else + return NULL; + } + return NULL; +} /* ExtractingComponentCertificate */ + +int +BDecComponentCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), +GenBuf * b _AND_ +AsnTag tagId0 _AND_ +AsnLen elmtLen0 _AND_ +ComponentCertificate **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + int seqDone = FALSE, old_mode = mode; + AsnLen totalElmtsLen1 = 0; + AsnLen elmtLen1; + AsnTag tagId1; + int mandatoryElmtCount1 = 0; + ComponentCertificate *k, *t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + memset(&c_temp,0,sizeof(c_temp)); + k = &c_temp; + } else + k = t = *v; + mode = DEC_ALLOC_MODE_2; + tagId1 = BDecTag (b, &totalElmtsLen1 ); + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentTBSCertificate (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentAlgorithmIdentifier (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"); + tagId1 = BDecTag (b, &totalElmtsLen1); + } + else + return -1; + + + + if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) || +(tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))) + { + elmtLen1 = BDecLen (b, &totalElmtsLen1 ); + BDecComponentBits (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"); + seqDone = TRUE; + if (elmtLen0 == INDEFINITE_LEN) + BDecEoc (b, &totalElmtsLen1 ); + else if (totalElmtsLen1 != elmtLen0) + return -1; + + } + else + return -1; + + + + if (!seqDone) + return -1; + + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentCertificate*) malloc( sizeof(ComponentCertificate) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate; + (*bytesDecoded) += totalElmtsLen1; + return LDAP_SUCCESS; +} /* BDecCertificate*/ + +int +GDecComponentCertificate PARAMS ((b, v, bytesDecoded, mode), +GenBuf * b _AND_ +ComponentCertificate **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) +{ + char* peek_head,*peek_head2; + int i, strLen,strLen2, rc, old_mode = mode; + ComponentCertificate *k,*t, c_temp; + + + if ( !(mode & DEC_ALLOC_MODE_1) ) { + 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"); + 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"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentTBSCertificate (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentAlgorithmIdentifier (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 { "); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != ','){ + Asn1Error("Missing , in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(strLen = LocateNextGSERToken(b,&peek_head,GSER_NO_COPY)) ){ + Asn1Error("Error during Reading identifier"); + return LDAP_PROTOCOL_ERROR; + } + GDecComponentBits (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 } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if(*peek_head != '}'){ + Asn1Error("Missing } in encoding"); + return LDAP_PROTOCOL_ERROR; + } + if( !(old_mode & DEC_ALLOC_MODE_1) ) { + *v = t = (ComponentCertificate*) malloc( sizeof(ComponentCertificate) ); + if ( !t ) return -1; + *t = *k; + } + t->syntax = (Syntax*)NULL; + t->comp_desc = malloc( 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_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate; + t->comp_desc->cd_type = ASN_COMPOSITE; + t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; + t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate; + 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 new file mode 100644 index 0000000000..3299b07e25 --- /dev/null +++ b/contrib/slapd-modules/comp_match/certificate.h @@ -0,0 +1,405 @@ + +#include "asn-incl.h" +/* + * 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 + * The generated files are strongly encouraged to be + * compiled as a module for OpenLDAP Software + */ + +#ifndef _certificate_h_ +#define _certificate_h_ + + + + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef _WIN32 +#pragma warning( disable : 4101 ) +#endif +#include "component.h" +typedef enum AuthenticationFrameworkAnyId +{ + nullOid_ANY_ID = 0, + nullOid2_ANY_ID = 1, + printableStringOid_ANY_ID = 2} AuthenticationFrameworkAnyId; + + +void InitAnyAuthenticationFramework(); + + +#define V1 0 +#define V2 1 +#define V3 2 + +typedef ComponentInt ComponentVersion; /* INTEGER { V1 (0), V2 (1), V3 (2) } */ + +#define MatchingComponentVersion MatchingComponentInt + +#define ExtractingComponentVersion ExtractingComponentInt + +#define BDecComponentVersion BDecComponentInt + +#define GDecComponentVersion GDecComponentInt + +#define FreeComponentVersion FreeComponentInt + +typedef ComponentInt ComponentCertificateSerialNumber; /* INTEGER */ + +#define MatchingComponentCertificateSerialNumber MatchingComponentInt + +#define ExtractingComponentCertificateSerialNumber ExtractingComponentInt + +#define BDecComponentCertificateSerialNumber BDecComponentInt + +#define GDecComponentCertificateSerialNumber GDecComponentInt + +#define FreeComponentCertificateSerialNumber FreeComponentInt + +typedef ComponentOid ComponentAttributeType; /* OBJECT IDENTIFIER */ + +#define MatchingComponentAttributeType MatchingComponentOid + +#define ExtractingComponentAttributeType ExtractingComponentOid + +#define BDecComponentAttributeType BDecComponentOid + +#define GDecComponentAttributeType GDecComponentOid + +#define FreeComponentAttributeType FreeComponentOid + +typedef ComponentBits ComponentUniqueIdentifier; /* BIT STRING */ + +#define MatchingComponentUniqueIdentifier MatchingComponentBits + +#define ExtractingComponentUniqueIdentifier ExtractingComponentBits + +#define BDecComponentUniqueIdentifier BDecComponentBits + +#define GDecComponentUniqueIdentifier GDecComponentBits + +#define FreeComponentUniqueIdentifier FreeComponentBits + +typedef struct AlgorithmIdentifier /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentOid algorithm; /* OBJECT IDENTIFIER */ + ComponentAnyDefinedBy parameters; /* ANY DEFINED BY algorithm OPTIONAL */ +} ComponentAlgorithmIdentifier; + +int MatchingComponentAlgorithmIdentifier PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentAlgorithmIdentifier PROTO ((ComponentReference *cr, ComponentAlgorithmIdentifier *comp )); + + +int BDecComponentAlgorithmIdentifier PROTO ((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); + + + +typedef struct Time /* CHOICE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + enum TimeChoiceId + { + TIME_UTCTIME, + TIME_GENERALIZEDTIME + } choiceId; + union TimeChoiceUnion + { + ComponentUTCTime* utcTime; /* < unknown type id ?! > */ + ComponentGeneralizedTime* generalizedTime; /* < unknown type id ?! > */ + } a; +} ComponentTime; + +int MatchingComponentTime PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentTime PROTO ((ComponentReference *cr, ComponentTime *comp )); + + +int BDecComponentTime PROTO ((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); + + + +typedef struct Extension /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentOid extnID; /* OBJECT IDENTIFIER */ + ComponentOcts extnValue; /* OCTET STRING */ +} ComponentExtension; + +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)); + + +int GDecComponentExtension PROTO ((GenBuf * b, ComponentExtension **v, AsnLen *bytesDecoded, int mode)); + + +void FreeComponentExtension(ComponentExtension *v); + + + +typedef struct AttributeTypeAndValue /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentAttributeType type; /* AttributeType */ + ComponentAnyDefinedBy value; /* ANY DEFINED BY type */ +} ComponentAttributeTypeAndValue; + +int MatchingComponentAttributeTypeAndValue PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentAttributeTypeAndValue PROTO ((ComponentReference *cr, ComponentAttributeTypeAndValue *comp )); + + +int BDecComponentAttributeTypeAndValue PROTO ((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); + + + +typedef struct Validity /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentTime* notBefore; /* Time */ + ComponentTime* notAfter; /* Time */ +} ComponentValidity; + +int MatchingComponentValidity PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentValidity PROTO ((ComponentReference *cr, ComponentValidity *comp )); + + +int BDecComponentValidity PROTO ((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); + + + +typedef struct SubjectPublicKeyInfo /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentAlgorithmIdentifier* algorithm; /* AlgorithmIdentifier */ + ComponentBits subjectPublicKey; /* BIT STRING */ +} ComponentSubjectPublicKeyInfo; + +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)); + + +int GDecComponentSubjectPublicKeyInfo PROTO ((GenBuf * b, ComponentSubjectPublicKeyInfo **v, AsnLen *bytesDecoded, int mode)); + + +void FreeComponentSubjectPublicKeyInfo(ComponentSubjectPublicKeyInfo *v); + + + +typedef ComponentList ComponentExtensions; /* SEQUENCE SIZE 1..MAX OF Extension */ + +int MatchingComponentExtensions PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentExtensions PROTO ((ComponentReference *cr, ComponentExtensions *comp )); + + +int BDecComponentExtensions PROTO ((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); + + + +typedef ComponentList ComponentRelativeDistinguishedName; /* SET OF AttributeTypeAndValue */ + +int MatchingComponentRelativeDistinguishedName PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentRelativeDistinguishedName PROTO ((ComponentReference *cr, ComponentRelativeDistinguishedName *comp )); + + +int BDecComponentRelativeDistinguishedName PROTO ((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); + + + +typedef ComponentList ComponentRDNSequence; /* SEQUENCE OF RelativeDistinguishedName */ + +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)); + + +int GDecComponentRDNSequence PROTO ((GenBuf * b, ComponentRDNSequence **v, AsnLen *bytesDecoded, int mode)); + + +void FreeComponentRDNSequence(ComponentRDNSequence *v); + + + +typedef struct Name /* CHOICE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + enum NameChoiceId + { + NAME_RDNSEQUENCE + } choiceId; + union NameChoiceUnion + { + ComponentRDNSequence* rdnSequence; /* RDNSequence */ + } a; +} ComponentName; + +int MatchingComponentName PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentName PROTO ((ComponentReference *cr, ComponentName *comp )); + + +int BDecComponentName PROTO ((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); + + + +typedef struct TBSCertificate /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentVersion* version; /* [0] Version DEFAULT v1 */ + ComponentCertificateSerialNumber serialNumber; /* CertificateSerialNumber */ + ComponentAlgorithmIdentifier* signature; /* AlgorithmIdentifier */ + ComponentName* issuer; /* Name */ + ComponentValidity* validity; /* Validity */ + ComponentName* subject; /* Name */ + ComponentSubjectPublicKeyInfo* subjectPublicKeyInfo; /* SubjectPublicKeyInfo */ + ComponentUniqueIdentifier issuerUniqueIdentifier; /* [1] IMPLICIT UniqueIdentifier OPTIONAL */ + ComponentUniqueIdentifier subjectUniqueIdentifier; /* [2] IMPLICIT UniqueIdentifier OPTIONAL */ + ComponentExtensions* extensions; /* [3] Extensions OPTIONAL */ +} ComponentTBSCertificate; + +int MatchingComponentTBSCertificate PROTO (( char *oid, ComponentSyntaxInfo *, ComponentSyntaxInfo *v2 )); + + +void* ExtractingComponentTBSCertificate PROTO ((ComponentReference *cr, ComponentTBSCertificate *comp )); + + +int BDecComponentTBSCertificate PROTO ((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); + + + +typedef struct Certificate /* SEQUENCE */ +{ + Syntax* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentTBSCertificate* tbsCertificate; /* TBSCertificate */ + ComponentAlgorithmIdentifier* signatureAlgorithm; /* AlgorithmIdentifier */ + ComponentBits signature; /* BIT STRING */ +} ComponentCertificate; + +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)); + + +int GDecComponentCertificate PROTO ((GenBuf * b, ComponentCertificate **v, AsnLen *bytesDecoded, int mode)); + + +void FreeComponentCertificate(ComponentCertificate *v); + + + +/* ========== Object Declarations ========== */ + + +/* ========== Object Set Declarations ========== */ +#ifdef __cplusplus +extern "C" { +#endif + +#endif /* conditional include of certificate.h */ diff --git a/contrib/slapd-modules/comp_match/component.h b/contrib/slapd-modules/comp_match/component.h new file mode 100644 index 0000000000..a8fe88a81b --- /dev/null +++ b/contrib/slapd-modules/comp_match/component.h @@ -0,0 +1,517 @@ +/* Copyright 2004 IBM Corporation + * All rights reserved. + * Redisribution and use in source and binary forms, with or without + * modification, are permitted only as authorizd by the OpenLADP + * Public License. + */ +/* ACKNOWLEDGEMENTS + * This work originally developed by Sang Seok Lim + * 2004/06/18 03:20:00 slim@OpenLDAP.org + */ + +#ifndef _H_COMPONENT_MODULE +#define _H_COMPONENT_MODULE + +#include "portable.h" +#include +#include +#include +#include "lutil.h" +#include +#include + +#include +#include "asn.h" +#include +#include + +#define MAX_IDENTIFIER_LEN 128 +#define COMPONENTNOT_NULL(ptr) ((ptr) != NULL) + +/* + * BIT STRING + */ +typedef struct ComponentBits { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + AsnBits value; +} 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 MatchingComponentBits (char* oid, ComponentSyntaxInfo *bits1 , ComponentSyntaxInfo* bits2); +#define ExtractingComponentBits(cr,data) NULL + +/* + * BMP String + */ +typedef struct ComponentBMPString { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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); +#define MatchingComponentBMPString MatchingComponentOcts +#define ExtractingComponentBMPString(cr,data) NULL +#define FreeComponentBMPString FreeComponentOcts + +/* + * BOOLEAN + */ +typedef struct ComponentBool { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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 MatchingComponentBool (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentBool(cr,data) NULL +#define FreeComponentBool(v) NULL + +/* + * ENUMERTED + */ +typedef struct ComponentEnum { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + AsnEnum value; + 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 MatchingComponentEnum (char *oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo * b); +#define ExtractingComponentEnum(cr,data) NULL +#define FreeComponentEnum FreeComponentInt + +/* + * IA5 String + */ +typedef struct ComponentIA5String { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + IA5String value; +} ComponentIA5String; + +#define GDecComponentIA5String GDecComponentUTF8String +int BDecComponentIA5String (GenBuf *b, AsnTag tagId, AsnLen len, void *result, + AsnLen *bytesDecoded, int mode); +#define MatchingComponentIA5String MatchingComponentOcts +#define ExtractingComponentIA5String(cr,data) NULL +#define FreeComponentIA5String FreeComponentOcts + + +/* + * INTEGER + */ +typedef struct ComponentInt { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + int value; +} 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 MatchingComponentInt (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentInt(cr,data) NULL +#define FreeComponentInt(v) NULL + +/* + * LIST Data Structure for C_LIST + */ +typedef struct ComponentList { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + AsnList comp_list; +} ComponentList; + +/* + * NULL + */ +typedef struct ComponentNull { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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 MatchingComponentNull (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentNull(cr,data) NULL +#define FreeComponentNull NULL + +/* + * Numeric String + */ +typedef struct ComponentNumericString { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + NumericString value; +} ComponentNumericString; + +#define GDecComponentNumericString GDecComponentUTF8String +int BDecComponentNumericString (GenBuf *b, AsnTag tagId, AsnLen len, + void *result, AsnLen *bytesDecoded, int mode); +#define MatchingComponentNumericString MatchingComponentOcts +#define ExtractingComponentNumericString(cr,data) NULL +#define FreeComponentNumericString FreeComponentOcts + +/* + * OCTETS STRING + */ +typedef struct ComponentOcts { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + AsnOcts value; +} 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 MatchingComponentOcts (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentOcts(cr,data) NULL +void FreeComponentOcts( ComponentOcts* octs ); + +/* + * OID (Object Identifier) + */ +typedef struct ComponentOid { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + AsnOid value; +} 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 MatchingComponentOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentOid(cr,data) NULL +#define FreeComponentOid FreeComponentOcts + +/* + * Printable String + */ +typedef struct ComponentPrintableString{ + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + PrintableString value; +} 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 ); +#define MatchingComponentPrintableString MatchingComponentOcts +#define ExtractingComponentPrintableString(cr,data) NULL +#define FreeComponentPrintableString FreeComponentOcts + +/* + * REAL + */ +typedef struct ComponentReal{ + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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 MatchingComponentReal (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentReal(cr,data) NULL +#define FreeComponentReal(v) NULL + +/* + * Relative OID + */ + +typedef struct ComponentRelativeOid { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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 MatchingComponentRelativeOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b); +#define ExtractingComponentRelativeOid(cr,data) +#define FreeComponentRelativeOid FreeComponentOid + +/* + * Teletex String + */ +typedef struct ComponentTeletexString { + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + TeletexString value; +} ComponentTeletexString; + +int GDecComponentTeletexString (GenBuf *b, void *result, + AsnLen *bytesDecoded, int mode); +#define BDecComponentTeletexString BDecComponentOcts +#define MatchingComponentTeletexString MatchingComponentOcts +#define ExtractingComponentTeletexString(cr,data) +#define FreeComponentTeletexString FreeComponentOcts + + +/* + * Universal String + */ +typedef struct ComponentUniversalString{ + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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); +#define MatchingComponentUniversalString MatchingComponentOcts +#define ExtractingComponentUniversalString(cr,data) +#define FreeComponentUniversalString FreeComponentOcts + +/* + * UTF8 String + */ +typedef struct ComponentUTF8String{ + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + 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); +#define MatchingComponentUTF8String MatchingComponentOcts +#define ExtractingComponentUTF8String(cr,data) +#define FreeComponentUTF8String FreeComponentOcts + +/* + * Visible String + */ +typedef struct ComponentVisibleString{ + void* syntax; + ComponentDesc* comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + VisibleString value; +} ComponentVisibleString; + +#define GDecComponentVisibleString GDecComponentUTF8String +int BDecComponentVisibleString (GenBuf *b, AsnTag tagId, AsnLen len, + void *result, AsnLen *bytesDecoded, int mode); +#define MatchingComponentVisibleString MatchingComponentOcts +#define ExtractingComponentVisibleString(cr,data) +#define FreeComponentVisibleString FreeComponentOcts + +/* + * ANY and ANY DEFINED BY + */ + +typedef int (*MatchFcn) (char*, void*, void*); +typedef void* (*ExtractFcn) (ComponentReference*, void * ); + +typedef struct ComponentAnyInfo +{ + int anyId; + AsnOid oid; + ComponentInt intId; + unsigned int size; + EncodeFcn Encode; + gser_decoder_func* GSER_Decode; + ber_tag_decoder_func* BER_Decode; + ExtractFcn Extract; + MatchFcn Match; + FreeFcn Free; + PrintFcn Print; +} ComponentAnyInfo; + +typedef struct ComponentAny{ + void* syntax; + ComponentDesc *comp_desc; + struct berval identifier; + char id_buf[MAX_IDENTIFIER_LEN]; + ComponentAnyInfo *cai; + void *value; +} ComponentAny; + +typedef ComponentAny ComponentAnyDefinedBy; + +#define BDecComponentAnyDefinedBy BDecComponentAny +#define GDecComponentAnyDefinedBy GDecComponentAny +#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 MatchingComponentAny (char* oid, ComponentAny *a, ComponentAny *b); +void FreeComponentAny ( ComponentAny*); + +void InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func B_decode, ExtractFcn extract, MatchFcn match, FreeFcn free, PrintFcn print); + +void InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match, FreeFcn free, PrintFcn print); + + +/* + * UTCTime + */ +typedef ComponentVisibleString ComponentUTCTime; +#define GDecComponentUTCTime GDecComponentVisibleString +#define BDecComponentUTCTime BDecComponentOcts +#define MatchingComponentUTCTime MatchingComponentOcts +#define ExtractingComponentUTCTime(cr,data) +#define FreeComponentUTCTime FreeComponentOcts + +/* + * GeneralizedTime + */ +typedef ComponentVisibleString ComponentGeneralizedTime; +#define GDecComponentGeneralizedTime GDecComponentVisibleString +#define BDecComponentGeneralizedTime BDecComponentOcts +#define MatchingComponentGeneralizedTime MatchingComponentOcts +#define ExtractingComponentGeneralizedTime(cr,data) +#define FreeComponentGeneralizedTime FreeComponentOcts + +typedef int converter_func LDAP_P (( + struct berval* in )); + +typedef struct asntype_to_syntax { + AsnTypeId ats_typeId; + /* Syntax Descriptor */ + char *ats_syn_name; + /* Syntax OID */ + char *ats_syn_oid; + Syntax *ats_syn; +} AsnTypetoSyntax; + +typedef struct asntype_to_matchingrule { + AsnTypeId atmr_typeId; + char* atmr_mr_name; + /*Implicitly corresponding LDAP syntax OID*/ + char* atmr_syn_oid; + MatchingRule *atmr_mr; +} AsnTypetoMatchingRule; + +typedef struct asntype_to_matchingrule_table { + char* atmr_oid; + struct asntype_to_matchingrule atmr_table[ASNTYPE_END]; + struct asntype_to_matchingrule_table* atmr_table_next; +} AsnTypetoMatchingRuleTable; + +extern AsnTypetoSyntax asn_to_syntax_mapping_tbl[]; + +#define MAX_OID_LEN 256 +#define MAX_OD_ENTRY 8 + +/* + * Object Identifier and corresponding Syntax Decoder Table + */ +typedef struct OID_Decoder_entry { + char oe_oid[MAX_OID_LEN]; + gser_decoder_func* oe_gser_decoder; + ber_decoder_func* oe_ber_decoder; + converter_func* oe_converter; + struct OID_Decoder_entry* oe_next; + struct OID_Decoder_entry* oe_prev; +} OD_entry; + +void +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 ); +void* +m_convert_attr_to_comp ( Attribute* a, struct berval* bv ); + +/* + * Decoder Modes + * Different operation is required to handle Decoding(2), Extracted Component + * decoding(0), ANY DEFINED TYPe(2) + * b0 : Component Alloc(yes) + * Constructed type : Component Alloc (Yes) + * Primitive type : Component Alloc (Yes) + * set to mode 2 in inner decoders + * b1 : Component Alloc (No) + * Constructed type : Component Alloc (No) + * Primitive type : Component Alloc (No) + * set to mode 2 in inner decoders + * b2 : Default Mode + * Constructed type : Component Alloc (Yes) + * Primitive type : Component Alloc (No) + * in addition to above modes, the 4th bit has special meaning, + * b4 : if the 4th bit is clear, DecxxxContent is called + * b4 : if the 4th bit is set, Decxxx is called, then it is cleared. + */ +#define DEC_ALLOC_MODE_0 0x01 +#define DEC_ALLOC_MODE_1 0x02 +#define DEC_ALLOC_MODE_2 0x04 +#define CALL_TAG_DECODER 0x08 +#define CALL_CONTENT_DECODER ~0x08 + +MatchingRule* +retrieve_matching_rule( char* mr_oid, AsnTypeId type ); + +#endif diff --git a/contrib/slapd-modules/comp_match/componentlib.c b/contrib/slapd-modules/comp_match/componentlib.c new file mode 100644 index 0000000000..d1ef3d46b8 --- /dev/null +++ b/contrib/slapd-modules/comp_match/componentlib.c @@ -0,0 +1,1867 @@ +/* Copyright 2004 IBM Corporation + * All rights reserved. + * Redisribution and use in source and binary forms, with or without + * modification, are permitted only as authorizd by the OpenLADP + * Public License. + */ +/* ACKNOWLEDGEMENTS + * This work originally developed by Sang Seok Lim + * 2004/06/18 03:20:00 slim@OpenLDAP.org + */ + +#include "portable.h" +#include +#include +#include +#include "lutil.h" +#include +#include "slap.h" + +#include "component.h" +#include "asn.h" +#include +#include + +#include + +#ifndef SLAPD_COMP_MATCH +#define SLAPD_COMP_MATCH SLAPD_MOD_DYNAMIC +#endif + +#ifdef SLAPD_COMP_MATCH +/* + * Matching function : BIT STRING + */ +int +MatchingComponentBits ( char* oid, ComponentSyntaxInfo *csi_attr, + ComponentSyntaxInfo *csi_assert ) +{ + int rc; + MatchingRule* mr; + ComponentBits *a, *b; + + if ( oid ) { + mr = retrieve_matching_rule(oid, (AsnTypeId)csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + a = ((ComponentBits*)csi_attr); + b = ((ComponentBits*)csi_assert); + rc = ( a->value.bitLen == b->value.bitLen && + strncmp( a->value.bits,b->value.bits,a->value.bitLen ) == 0 ); + return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * Free function: BIT STRING + */ +void +FreeComponentBits ( ComponentBits* v ) { + FreeAsnBits( &v->value ); +} + +/* + * GSER Decoder : BIT STRING + */ +int +GDecComponentBits ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentBits* k, **k2; + GAsnBits result; + + k = (ComponentBits*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentBits**) v; + *k2 = (ComponentBits*) malloc( sizeof( ComponentBits ) ); + k = *k2; + } + + GDecAsnBitsContent (b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_BITSTRING; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits; + + /* Real Decoding code need to be followed */ + return LDAP_SUCCESS; +} + +/* + * 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 ); +} + +int +BDecComponentBits ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentBits* k, **k2; + AsnBits result; + + k = (ComponentBits*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentBits**) v; + *k2 = (ComponentBits*) malloc( sizeof( ComponentBits ) ); + if ( !*k2 ) return -1; + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnBits (b, &result, bytesDecoded ); + } else { + BDecAsnBitsContent (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->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_BITSTRING; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits; + + return LDAP_SUCCESS; +} + +/* + * Component GSER BMPString Decoder + */ +int +GDecComponentBMPString (GenBuf *b, void *v, AsnLen *bytesDecoded, int mode) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentBMPString* k, **k2; + GBMPString result; + + k = (ComponentBMPString*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentBMPString**) v; + *k2 = (ComponentBMPString*) malloc( sizeof( ComponentBMPString ) ); + if ( !*k2 ) return -1; + k = *k2; + } + + *bytesDecoded = 0; + + GDecBMPStringContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_BMP_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString; + + return LDAP_SUCCESS; + +} + +/* + * Component BER BMPString Decoder + */ +int +BDecComponentBMPStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentBMPString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentBMPString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentBMPString* k, **k2; + BMPString result; + + k = (ComponentBMPString*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentBMPString**) v; + *k2 = (ComponentBMPString*) malloc( sizeof( ComponentBMPString ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecBMPString ( b, &result, bytesDecoded ); + } else { + BDecBMPStringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_BMP_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString; + + return LDAP_SUCCESS; + +} + +/* + * Component GSER Decoder : UTF8 String + */ +int +GDecComponentUTF8String (GenBuf *b, void *v, + AsnLen *bytesDecoded, int mode) { + char* peek_head; + int i, strLen; + void* component_values; + ComponentUTF8String* k, **k2; + GUTF8String result; + + k = (ComponentUTF8String*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentUTF8String**) v; + *k2 = (ComponentUTF8String*)malloc( sizeof( ComponentUTF8String ) ); + k = *k2; + } + + *bytesDecoded = 0; + + GDecUTF8StringContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : UTF8String + */ +int +BDecComponentUTF8StringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentUTF8String ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentUTF8String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentUTF8String* k, **k2; + UTF8String result; + + k = (ComponentUTF8String*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentUTF8String**) v; + *k2 = (ComponentUTF8String*) malloc( sizeof( ComponentUTF8String ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecUTF8String ( b, &result, bytesDecoded ); + } else { + BDecUTF8StringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String; +} + +/* + * Component GSER Decoder : Teletex String + */ +int +GDecComponentTeletexString (GenBuf *b, void *v, + AsnLen *bytesDecoded, int mode) { + char* peek_head; + int i, strLen; + void* component_values; + ComponentTeletexString* k, **k2; + GTeletexString result; + + k = (ComponentTeletexString*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentTeletexString**) v; + *k2 = (ComponentTeletexString*)malloc( sizeof( ComponentTeletexString ) ); + k = *k2; + } + + *bytesDecoded = 0; + + GDecTeletexStringContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentTeletexString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTeletexString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentTeletexString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_VIDEOTEX_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTeletexString; + + return LDAP_SUCCESS; +} + + +/* + * Matching function : BOOLEAN + */ +int +MatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr, + ComponentSyntaxInfo* csi_assert ) +{ + MatchingRule* mr; + ComponentBool *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + + a = ((ComponentBool*)csi_attr); + b = ((ComponentBool*)csi_assert); + + return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : BOOLEAN + */ +int +GDecComponentBool ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + ComponentBool* k, **k2; + GAsnBool result; + + k = (ComponentBool*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentBool**) v; + *k2 = (ComponentBool*) malloc( sizeof( ComponentBool ) ); + k = *k2; + } + + GDecAsnBoolContent( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : BOOLEAN + */ +int +BDecComponentBoolTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentBool ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentBool ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + ComponentBool* k, **k2; + AsnBool result; + + k = (ComponentBool*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentBool**) v; + *k2 = (ComponentBool*) malloc( sizeof( ComponentBool ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnBool ( b, &result, bytesDecoded ); + } else { + BDecAsnBoolContent( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool; + + return LDAP_SUCCESS; +} + +/* + * Matching function : ENUMERATE + */ +int +MatchingComponentEnum ( char* oid, ComponentSyntaxInfo *csi_attr, + ComponentSyntaxInfo *csi_assert ) +{ + int rc; + MatchingRule* mr; + ComponentEnum *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + a = ((ComponentEnum*)csi_attr); + b = ((ComponentEnum*)csi_assert); + rc = (a->value == b->value); + + return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : ENUMERATE + */ +int +GDecComponentEnum ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentEnum* k, **k2; + GAsnEnum result; + + k = (ComponentEnum*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentEnum**) v; + *k2 = (ComponentEnum*) malloc( sizeof( ComponentEnum ) ); + k = *k2; + } + + GDecAsnEnumContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : ENUMERATE + */ +int +BDecComponentEnumTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentEnum ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentEnum ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentEnum* k, **k2; + AsnEnum result; + + k = (ComponentEnum*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentEnum**) v; + *k2 = (ComponentEnum*) malloc( sizeof( ComponentEnum ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnEnum ( b, &result, bytesDecoded ); + } else { + BDecAsnEnumContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum; + + return LDAP_SUCCESS; +} + +/* + * IA5String + */ +/* + * Component BER Decoder : IA5String + */ +int +BDecComponentIA5StringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentIA5String ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentIA5String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentIA5String* k, **k2; + IA5String result; + + k = (ComponentIA5String*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentIA5String**) v; + *k2 = (ComponentIA5String*) malloc( sizeof( ComponentIA5String ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecIA5String ( b, &result, bytesDecoded ); + } else { + BDecIA5StringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentIA5String; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_IA5_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentIA5String; + + return LDAP_SUCCESS; +} + +/* + * Matching function : INTEGER + */ +int +MatchingComponentInt(char* oid, ComponentSyntaxInfo* csi_attr, + ComponentSyntaxInfo* csi_assert ) +{ + MatchingRule* mr; + ComponentInt *a, *b; + + if( oid ) { + /* check if this ASN type's matching rule is overrided */ + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + /* if existing function is overrided, call the overriding +function*/ + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + a = ((ComponentInt*)csi_attr); + b = ((ComponentInt*)csi_assert); + + return ( a->value == b->value ) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : INTEGER + */ +int +GDecComponentInt( GenBuf * b, void *v, AsnLen *bytesDecoded, int mode) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentInt* k, **k2; + GAsnInt result; + + k = (ComponentInt*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentInt**) v; + *k2 = (ComponentInt*) malloc( sizeof( ComponentInt ) ); + k = *k2; + } + + GDecAsnIntContent (b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = 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; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : INTEGER + */ +int +BDecComponentIntTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentInt ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentInt ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentInt* k, **k2; + AsnInt result; + + k = (ComponentInt*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentInt**) v; + *k2 = (ComponentInt*) malloc( sizeof( ComponentInt ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnInt (b, &result, bytesDecoded ); + } else { + BDecAsnIntContent (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->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = 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; + + return LDAP_SUCCESS; +} + +/* + * Matching function : NULL + */ +int +MatchingComponentNull ( char *oid, ComponentSyntaxInfo *csi_attr, + ComponentSyntaxInfo *csi_assert ) +{ + MatchingRule* mr; + ComponentNull *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + a = ((ComponentNull*)csi_attr); + b = ((ComponentNull*)csi_assert); + + return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : NULL + */ +int +GDecComponentNull ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentNull* k, **k2; + GAsnNull result; + + k = (ComponentNull*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentNull**) v; + *k2 = (ComponentNull*) malloc( sizeof( ComponentNull ) ); + k = *k2; + } + + GDecAsnNullContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_NULL; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : NULL + */ +int +BDecComponentNullTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + BDecComponentNull ( b, 0, 0, v,bytesDecoded, + mode|CALL_TAG_DECODER ); +} + +int +BDecComponentNull ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentNull* k, **k2; + AsnNull result; + + k = (ComponentNull*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentNull**) v; + *k2 = (ComponentNull*) malloc( sizeof( ComponentNull ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnNull ( b, &result, bytesDecoded ); + } + else { + BDecAsnNullContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_NULL; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull; + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : NumericString + */ +int +BDecComponentNumericStringTag ( GenBuf *b, void *v, + AsnLen *bytesDecoded, int mode ) { + BDecComponentNumericString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentNumericString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentNumericString* k, **k2; + NumericString result; + + k = (ComponentNumericString*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentNumericString**) v; + *k2 = (ComponentNumericString*) malloc( sizeof( ComponentNumericString ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecNumericString ( b, &result, bytesDecoded ); + } else { + BDecNumericStringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentNumericString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_NUMERIC_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNumericString; + + return LDAP_SUCCESS; +} + + +/* + * Free function : OCTET STRING + */ +void +FreeComponentOcts ( ComponentOcts* v) { + FreeAsnOcts( &v->value ); +} + +/* + * Matching function : OCTET STRING + */ +int +MatchingComponentOcts ( char* oid, ComponentSyntaxInfo* csi_attr, + ComponentSyntaxInfo* csi_assert ) +{ + int rc; + MatchingRule* mr; + ComponentOcts *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + a = (ComponentOcts*) csi_attr; + b = (ComponentOcts*) csi_assert; + /* Assume that both of OCTET string has end of string character */ + if ( (a->value.octetLen == b->value.octetLen) && + strncmp ( a->value.octs, b->value.octs, a->value.octetLen ) == 0 ) + return LDAP_COMPARE_TRUE; + else + return LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : OCTET STRING + */ +int +GDecComponentOcts ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char *peek_head, *data; + int i, j, strLen; + void* component_values; + ComponentOcts* k, **k2; + GAsnOcts result; + + k = (ComponentOcts*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentOcts**) v; + *k2 = (ComponentOcts*) malloc( sizeof( ComponentOcts ) ); + k = *k2; + } + + GDecAsnOctsContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts; + + return LDAP_SUCCESS; +} + +/* + * 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 ); +} + +int +BDecComponentOcts ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char *peek_head, *data; + int i, j, strLen; + void* component_values; + ComponentOcts* k, **k2; + AsnOcts result; + + k = (ComponentOcts*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentOcts**) v; + *k2 = (ComponentOcts*) malloc( sizeof( ComponentOcts ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnOcts ( b, &result, bytesDecoded ); + } else { + BDecAsnOctsContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts; + return LDAP_SUCCESS; +} + +/* + * Matching function : OBJECT IDENTIFIER + */ +int +MatchingComponentOid ( char *oid, ComponentSyntaxInfo *csi_attr , + ComponentSyntaxInfo *csi_assert ) +{ + int rc; + MatchingRule* mr; + ComponentOid *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + + a = (ComponentOid*)csi_attr; + b = (ComponentOid*)csi_assert; + if ( a->value.octetLen != b->value.octetLen ) + return LDAP_COMPARE_FALSE; + rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 ); + + return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : OID + */ + +int +GDecComponentOid ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen, rc; + void* component_values; + ComponentOid* k, **k2; + GAsnOid result; + + k = (ComponentOid*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentOid**) v; + *k2 = (ComponentOid*) malloc( sizeof( ComponentOid ) ); + k = *k2; + } + + if ( (rc = GDecAsnOidContent ( b, &result, bytesDecoded )) == -1 ) + return rc; + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_OID; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : OID + */ +int +BDecComponentOidTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentOid ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentOid* k, **k2; + AsnOid result; + + k = (ComponentOid*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentOid**) v; + *k2 = (ComponentOid*) malloc( sizeof( ComponentOid ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnOid ( b, &result, bytesDecoded ); + } else { + BDecAsnOidContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_OID; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid; + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : PrintiableString + */ + +int +BDecComponentPrintableStringTag ( GenBuf *b, void *v, + AsnLen *bytesDecoded, int mode ) +{ + BDecComponentPrintableString ( b, 0, 0, v, bytesDecoded, + mode|CALL_TAG_DECODER ); +} + +int +BDecComponentPrintableString( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentPrintableString* k, **k2; + AsnOid result; + + k = (ComponentPrintableString*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentPrintableString**) v; + *k2 = (ComponentPrintableString*) malloc( sizeof( ComponentPrintableString ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ) { + mode = mode & CALL_CONTENT_DECODER; + BDecPrintableString ( b, &result, bytesDecoded ); + } else { + BDecPrintableStringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentPrintableString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentPrintableString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentPrintableString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_PRINTABLE_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentPrintableString; + return LDAP_SUCCESS; +} + +/* + * Matching function : Real + */ +int +MatchingComponentReal (char* oid, ComponentSyntaxInfo *csi_attr, + ComponentSyntaxInfo *csi_assert ) +{ + int rc; + MatchingRule* mr; + ComponentReal *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + a = (ComponentReal*)csi_attr; + b = (ComponentReal*)csi_assert; + rc = (a->value == b->value); + + return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : Real + */ +int +GDecComponentReal ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentReal* k, **k2; + GAsnReal result; + + k = (ComponentReal*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentReal**) v; + *k2 = (ComponentReal*) malloc( sizeof( ComponentReal ) ); + k = *k2; + } + + GDecAsnRealContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_REAL; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal; + + return LDAP_SUCCESS; +} + +/* + * Component BER Decoder : Real + */ +int +BDecComponentRealTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) { + BDecComponentReal ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentReal ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentReal* k, **k2; + AsnReal result; + + k = (ComponentReal*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentReal**) v; + *k2 = (ComponentReal*) malloc( sizeof( ComponentReal ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnReal ( b, &result, bytesDecoded ); + } else { + BDecAsnRealContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal; + k->comp_desc->cd_free = (comp_free_func*)NULL; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_REAL; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal; + + return LDAP_SUCCESS; +} + +/* + * Matching function : Relative OID + */ +int +MatchingComponentRelativeOid ( char* oid, ComponentSyntaxInfo *csi_attr, + ComponentSyntaxInfo *csi_assert ) +{ + int rc; + MatchingRule* mr; + ComponentRelativeOid *a, *b; + + if( oid ) { + mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id ); + if ( mr ) + return component_value_match( mr, csi_attr , csi_assert ); + } + + a = (ComponentRelativeOid*)csi_attr; + b = (ComponentRelativeOid*)csi_assert; + + if ( a->value.octetLen != b->value.octetLen ) + return LDAP_COMPARE_FALSE; + rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 ); + + return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE; +} + +/* + * GSER Decoder : RELATIVE_OID. + */ +int +GDecComponentRelativeOid ( GenBuf *b,void *v, AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentRelativeOid* k, **k2; + GAsnRelativeOid result; + + k = (ComponentRelativeOid*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentRelativeOid**) v; + *k2 = (ComponentRelativeOid*) malloc( sizeof( ComponentRelativeOid ) ); + k = *k2; + } + + GDecAsnRelativeOidContent ( b, &result, bytesDecoded ); + 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_OID; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid; + + return LDAP_SUCCESS; +} + +/* + * 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 ); +} + +int +BDecComponentRelativeOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentRelativeOid* k, **k2; + AsnRelativeOid result; + + k = (ComponentRelativeOid*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentRelativeOid**) v; + *k2 = (ComponentRelativeOid*) malloc( sizeof( ComponentRelativeOid ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecAsnRelativeOid ( b, &result, bytesDecoded ); + } else { + BDecAsnRelativeOidContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_RELATIVE_OID; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid; + return LDAP_SUCCESS; +} + +/* + * GSER Decoder : UniverseString + */ +static int +UTF8toUniversalString( char* octs, int len){ + /* Need to be Implemented */ + return 1; +} + +int +GDecComponentUniversalString ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) +{ + GDecComponentUTF8String (b, v, bytesDecoded, mode); + UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, + ((ComponentUniversalString*)v)->value.octetLen ); +} + +/* + * Component BER Decoder : UniverseString + */ +int +BDecComponentUniversalStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, + int mode ) { + BDecComponentUniversalString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER ); +} + +int +BDecComponentUniversalString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + 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 ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecUniversalString ( b, &result, bytesDecoded ); + } else { + BDecUniversalStringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentUniversalString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUniversalString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentUniversalString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_UNIVERSAL_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUniversalString; + 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 ); +} + +int +BDecComponentVisibleString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v, + AsnLen *bytesDecoded, int mode ) +{ + char* peek_head; + int i, strLen; + void* component_values; + ComponentVisibleString* k, **k2; + VisibleString result; + + k = (ComponentVisibleString*) v; + + if ( mode & DEC_ALLOC_MODE_0 ) { + k2 = (ComponentVisibleString**) v; + *k2 = (ComponentVisibleString*) malloc( sizeof( ComponentVisibleString ) ); + k = *k2; + } + + if ( mode & CALL_TAG_DECODER ){ + mode = mode & CALL_CONTENT_DECODER; + BDecVisibleString ( b, &result, bytesDecoded ); + } else { + BDecVisibleStringContent ( 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->cd_gser_decoder = (gser_decoder_func*)GDecComponentVisibleString; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentVisibleString; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentVisibleString; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_VISIBLE_STR; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentVisibleString; + return LDAP_SUCCESS; +} + +/* + * Routines for handling an ANY DEFINED Type + */ +void +SetAnyTypeByComponentOid ( ComponentAny *v, ComponentOid *id ) { + Hash hash; + void *anyInfo; + + /* use encoded oid as hash string */ + hash = MakeHash (id->value.octs, id->value.octetLen); + if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo)) + v->cai = (ComponentAnyInfo*) anyInfo; + else + v->cai = NULL; + + if ( !v->cai ) { + /* + * If not found, the data considered as octet chunk + * Yet-to-be-Implemented + */ + } +} + +void +SetAnyTypeByComponentInt( ComponentAny *v, ComponentInt id) { + Hash hash; + void *anyInfo; + + hash = MakeHash ((char*)&id, sizeof (id)); + if (CheckForAndReturnValue (anyIntHashTblG, hash, &anyInfo)) + v->cai = (ComponentAnyInfo*) anyInfo; + else + v->cai = NULL; +} + +int +BDecComponentAny (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) ); + k = *k2; + } + + if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) { + result->value = (void*) malloc ( result->cai->size ); + if ( !result->value ) return 0; + result->cai->BER_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; + } + k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny; + k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL; + k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_type_id = BASICTYPE_ANY; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny; + return LDAP_SUCCESS; + } + else { + Asn1Error ("ERROR - Component ANY Decode routine is NULL\n"); + return 0; + } +} + +int +GDecComponentAny (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) ); + k = *k2; + } + if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) { + result->value = (void*) malloc ( 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; + } + k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny; + k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny; + k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny; + k->comp_desc->cd_type = ASN_BASIC; + k->comp_desc->cd_extract_i = NULL; + k->comp_desc->cd_type_id = BASICTYPE_ANY; + k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny; + return LDAP_SUCCESS; + } + else { + Asn1Error ("ERROR - ANY Decode routine is NULL\n"); + return 0; + } +} + +int +MatchingComponentAny (char* oid, ComponentAny *result, ComponentAny *result2) { + void *comp1, *comp2; + + if ( result->comp_desc->cd_type_id == BASICTYPE_ANY ) + comp1 = result->value; + else + comp1 = result; + + if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY ) + comp2 = result2->value; + else + comp2 = result2; + + if ((result->cai != NULL) && (result->cai->Match != NULL)) { + if ( result->comp_desc->cd_type_id == BASICTYPE_ANY ) + return result->cai->Match(oid, comp1, comp2 ); + else if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY ) + return result2->cai->Match(oid, comp1, comp2); + else + return LDAP_INVALID_SYNTAX; + } + else { + Asn1Error ("ERROR - ANY Matching routine is NULL\n"); + return LDAP_INVALID_SYNTAX; + } +} + +void* +ExtractingComponentAny ( ComponentReference* cr, ComponentAny *result ) { + if ((result->cai != NULL) && (result->cai->Extract != NULL)) { + return (void*) result->cai->Extract( cr , result->value ); + } + else { + Asn1Error ("ERROR - ANY Extracting routine is NULL\n"); + return (void*)NULL; + } +} + +void +FreeComponentAny (ComponentAny* any) { + if ( any->cai != NULL && any->cai->Free != NULL ) { + any->cai->Free( any->value ); + free ( ((ComponentSyntaxInfo*)any->value)->csi_comp_desc ); + free ( any->value ); + } + else + Asn1Error ("ERROR - ANY Free routine is NULL\n"); +} + +void +InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size, + EncodeFcn encode, gser_decoder_func* G_decode, + ber_tag_decoder_func* B_decode, ExtractFcn extract, + MatchFcn match, FreeFcn free, + PrintFcn print) +{ + ComponentAnyInfo *a; + Hash h; + + a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo)); + a->anyId = anyId; + a->oid.octs = NULL; + a->oid.octetLen = 0; + a->intId = intId; + a->size = size; + a->Encode = encode; + a->GSER_Decode = G_decode; + a->BER_Decode = B_decode; + a->Match = match; + a->Extract = extract; + a->Free = free; + a->Print = print; + + if (anyIntHashTblG == NULL) + anyIntHashTblG = InitHash(); + + h = MakeHash ((char*)&intId, sizeof (intId)); + + if(anyIntHashTblG != NULL) + Insert(anyIntHashTblG, a, h); +} + +void +InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size, + EncodeFcn encode, gser_decoder_func* G_decode, + ber_tag_decoder_func* B_decode, ExtractFcn extract, + MatchFcn match, FreeFcn free, PrintFcn print) +{ + ComponentAnyInfo *a; + Hash h; + + a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo)); + a->anyId = anyId; + a->oid.octs = NULL; + a->oid.octetLen = 0; + a->size = size; + a->Encode = encode; + a->GSER_Decode = G_decode; + a->BER_Decode = B_decode; + a->Match = match; + a->Extract = extract; + a->Free = free; + a->Print = print; + + h = MakeHash (oid->octs, oid->octetLen); + + if (anyOidHashTblG == NULL) + anyOidHashTblG = InitHash(); + + if(anyOidHashTblG != NULL) + Insert(anyOidHashTblG, a, h); +} + +int +BDecComponentTop ( +ber_decoder_func *decoder _AND_ +GenBuf *b _AND_ +AsnTag tag _AND_ +AsnLen elmtLen _AND_ +void **v _AND_ +AsnLen *bytesDecoded _AND_ +int mode) { + tag = BDecTag ( b, bytesDecoded ); + elmtLen = BDecLen ( b, bytesDecoded ); + if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) { + printf("Invliad Tag\n"); + exit (1); + } + + return (*decoder)( 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 new file mode 100644 index 0000000000..c41de4270c --- /dev/null +++ b/contrib/slapd-modules/comp_match/init.c @@ -0,0 +1,339 @@ +/* Copyright 2004 IBM Corporation + * All rights reserved. + * Redisribution and use in source and binary forms, with or without + * modification, are permitted only as authorizd by the OpenLADP + * Public License. + */ +/* ACKNOWLEDGEMENTS + * This work originally developed by Sang Seok Lim + * 2004/06/18 03:20:00 slim@OpenLDAP.org + */ + +#include "portable.h" +#include +#include +#include +#include "lutil.h" +#include +#include "slap.h" + +#include "component.h" +#include "asn.h" +#include + +#include + +#ifndef SLAPD_COMP_MATCH +#define SLAPD_COMP_MATCH SLAPD_MOD_DYNAMIC +#endif + + +OD_entry* gOD_table = NULL; +AsnTypetoMatchingRuleTable* gATMR_table = NULL; + +int +load_derived_matching_rule ( char* cfg_path ){ +} + +MatchingRule* +retrieve_matching_rule( char* mr_oid, AsnTypeId type ) { + char* tmp; + struct berval mr_name = BER_BVNULL; + AsnTypetoMatchingRuleTable* atmr; + + for ( atmr = gATMR_table ; atmr ; atmr = atmr->atmr_table_next ) { + if ( strcmp( atmr->atmr_oid, mr_oid ) == 0 ) { + tmp = atmr->atmr_table[type].atmr_mr_name; + if ( tmp ) { + mr_name.bv_val = tmp; + mr_name.bv_len = strlen( tmp ); + return mr_bvfind ( &mr_name ); + } + } + } + return (MatchingRule*)NULL; +} + +OD_entry* +retrieve_oid_decoder_table ( char* oid ) { + OD_entry* curr_entry; + for ( curr_entry = gOD_table ; curr_entry != NULL ; + curr_entry = curr_entry->oe_next ) { + if ( strcmp ( curr_entry->oe_oid , oid ) == 0 ) + return curr_entry; + } + return (OD_entry*) NULL; +} + +int +add_OD_entry ( char* oid, gser_decoder_func* gser_decoder , + ber_decoder_func ber_decoder, converter_func* converter ) { + OD_entry* new_entry; + + if ( !gOD_table ) { + gOD_table = new_entry = (OD_entry*) malloc( sizeof ( OD_entry ) ); + gOD_table->oe_next = NULL; + gOD_table->oe_prev = NULL; + } + else { + new_entry = (OD_entry*) malloc( sizeof ( OD_entry ) ); + if ( !new_entry ) return -1; + gOD_table->oe_prev = new_entry; + new_entry->oe_next = gOD_table; + new_entry->oe_prev = NULL; + gOD_table = new_entry; + } + + strcpy ( new_entry->oe_oid ,oid ); + new_entry->oe_gser_decoder = gser_decoder; + new_entry->oe_ber_decoder = ber_decoder; + new_entry->oe_converter = converter; + + return 1; +} + +int +remove_OD_entry ( char* oid ) { + OD_entry* curr_entry; + for ( curr_entry = gOD_table ; curr_entry != NULL ; + curr_entry = curr_entry->oe_next ) { + if ( strcmp ( curr_entry->oe_oid , oid ) == 0 ) { + if ( !curr_entry->oe_next ) { + if ( curr_entry->oe_prev ) { + curr_entry->oe_prev->oe_next = NULL; + } + } else { + curr_entry->oe_prev->oe_next = curr_entry->oe_next; + curr_entry->oe_next->oe_prev = curr_entry->oe_prev; + } + free ( curr_entry ); + return 1; + } + } + return -1; +} + +void* +comp_convert_attr_to_comp LDAP_P (( Attribute* a, Syntax *syn, struct berval* bv )) +{ + + char* peek_head; + int mode, bytesDecoded, size, rc; + void* component; + char* oid = a->a_desc->ad_type->sat_atype.at_oid ; + GenBuf* b; + ExpBuf* buf; + OD_entry* od_entry; + + /* look for the decoder registered for the given attribute */ + od_entry = retrieve_oid_decoder_table ( oid ); + if ( !od_entry || !od_entry->oe_ber_decoder ) return (void*)NULL; + if ( od_entry->oe_converter ) { + size = (*od_entry->oe_converter)( bv ); + if ( size <= 0 ) return (void*)NULL; + } + + ExpBufInit( 2048 ); + buf = ExpBufAllocBufAndData(); + ExpBufResetInWriteRvsMode( buf ); + ExpBuftoGenBuf( buf, &b ); + BufPutSegRvs( b, bv->bv_val, bv->bv_len ); + BufResetInReadMode( b ); + + mode = DEC_ALLOC_MODE_2; + /* + * How can we decide which decoder will be called, GSER or BER? + * Currently BER decoder is called for a certificate. + * 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 ) ; + } + else { + rc = od_entry->oe_gser_decoder(b, component,&bytesDecoded,mode); + } + if ( rc == -1 ) + return (void*)NULL; + else + return component; +} + +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 ); + return; +} + +int +comp_convert_assert_to_comp LDAP_P (( ComponentSyntaxInfo *csi_attr, struct berval* bv, + ComponentSyntaxInfo** csi, int* len, int mode )) +{ + GenBuf* genBuf; + ExpBuf* buf; + gser_decoder_func *decoder = csi_attr->csi_comp_desc->cd_gser_decoder; + + ExpBufInit( 2048 ); + buf = ExpBufAllocBufAndData(); + ExpBufResetInWriteRvsMode( buf ); + ExpBuftoGenBuf( buf, &genBuf ); + BufPutSegRvs( genBuf, bv->bv_val, bv->bv_len ); + BufResetInReadMode( genBuf ); + + if ( csi_attr->csi_comp_desc->cd_type_id == BASICTYPE_ANY ) + decoder = ((ComponentAny*)csi_attr)->cai->GSER_Decode; + + return (*decoder)( genBuf, csi, len, mode ); +} + +int intToAscii( int value, char* buf ) { + int minus=0,i,temp; + char digit; + int total_num_digits; + + if ( value == 0 ){ + buf[0] = '0'; + return 1; + } + + if ( value < 0 ){ + minus = 1; + value = value*(-1); + buf[0] = '-'; + } + + /* How many digits */ + for ( temp = value, total_num_digits=0 ; temp ; total_num_digits++ ) + temp = temp/10; + + total_num_digits += minus; + + for ( i = minus ; value ; i++ ) { + buf[ total_num_digits - i ]= (char)(value%10 + '0'); + value = value/10; + } + return i; +} + +int +comp_convert_asn_to_ldap LDAP_P(( ComponentSyntaxInfo* csi, struct berval* bv )) +{ + int value; + Syntax* syn; + AsnTypetoSyntax* asn_to_syn = + &asn_to_syntax_mapping_tbl[csi->csi_comp_desc->cd_type_id]; + if ( asn_to_syn->ats_syn_oid ) + csi->csi_syntax = syn_find ( asn_to_syn->ats_syn_oid ); + else + csi->csi_syntax = NULL; + + switch ( csi->csi_comp_desc->cd_type_id ) { + case BASICTYPE_BOOLEAN : + if ( ((ComponentBool*)csi)->value > 0 ) { + strcpy ( bv->bv_val , "TRUE" ); + bv->bv_len = 4; + } + else { + strcpy ( bv->bv_val , "FALSE" ); + bv->bv_len = 5; + } + break ; + case BASICTYPE_NULL : + bv->bv_val = (char *) &((ComponentNull*)csi)->value; + bv->bv_len = sizeof(char); + break; + case BASICTYPE_INTEGER : + bv->bv_len = intToAscii(((ComponentInt*)csi)->value, bv->bv_val ); + if ( bv->bv_len <= 0 ) return LDAP_INVALID_SYNTAX; + break; + case BASICTYPE_REAL : + bv->bv_val = (char *) &((ComponentReal*)csi)->value; + bv->bv_len = sizeof(double); + break; + case BASICTYPE_ENUMERATED : + bv->bv_val = (char *) &((ComponentEnum*)csi)->value; + bv->bv_len = sizeof(int); + break; + case BASICTYPE_OID : + case BASICTYPE_OCTETSTRING : + case BASICTYPE_BITSTRING : + case BASICTYPE_NUMERIC_STR : + case BASICTYPE_PRINTABLE_STR : + case BASICTYPE_UNIVERSAL_STR : + case BASICTYPE_IA5_STR : + case BASICTYPE_BMP_STR : + case BASICTYPE_UTF8_STR : + case BASICTYPE_UTCTIME : + case BASICTYPE_GENERALIZEDTIME : + case BASICTYPE_GRAPHIC_STR : + case BASICTYPE_VISIBLE_STR : + case BASICTYPE_GENERAL_STR : + case BASICTYPE_OBJECTDESCRIPTOR : + case BASICTYPE_VIDEOTEX_STR : + case BASICTYPE_T61_STR : + case BASICTYPE_OCTETCONTAINING : + case BASICTYPE_BITCONTAINING : + case BASICTYPE_RELATIVE_OID : + bv->bv_val = ((ComponentOcts*)csi)->value.octs; + bv->bv_len = ((ComponentOcts*)csi)->value.octetLen; + break; + case BASICTYPE_ANY : + csi = ((ComponentAny*)csi)->value; + if ( csi->csi_comp_desc->cd_type != ASN_BASIC || + csi->csi_comp_desc->cd_type_id == BASICTYPE_ANY ) + return LDAP_INVALID_SYNTAX; + return comp_convert_asn_to_ldap( csi, bv ); + case COMPOSITE_ASN1_TYPE : + case RDNSequence : + case RelativeDistinguishedName : + case TelephoneNumber : + case FacsimileTelephoneNumber__telephoneNumber : + break; + case DirectoryString : + bv->bv_val = ((ComponentOcts*)csi)->value.octs; + bv->bv_len = ((ComponentOcts*)csi)->value.octetLen; + break; + case ASN_COMP_CERTIFICATE : + case ASNTYPE_END : + break; + default : + /*Only ASN Basic Type can be converted into LDAP string*/ + return LDAP_INVALID_SYNTAX; + } + + if ( csi->csi_syntax && csi->csi_syntax->ssyn_validate ) { + if ( csi->csi_syntax->ssyn_validate(csi->csi_syntax, bv) != LDAP_SUCCESS ) + return LDAP_INVALID_SYNTAX; + } + + return LDAP_SUCCESS; +} + +#if SLAPD_COMP_MATCH == SLAPD_MOD_DYNAMIC + +#include "certificate.h" + +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; + +int init_module(int argc, char *argv[]) { + /* + * Initialize function pointers in slapd + */ + attr_converter = comp_convert_attr_to_comp; + assert_converter = comp_convert_assert_to_comp; + csi_converter = comp_convert_asn_to_ldap; + component_destructor = comp_free_component; + /* file path needs to be */ + load_derived_matching_rule ("derived_mr.cfg"); + /* the initialization for example X.509 certificate */ + init_module_AuthenticationFramework(); + return 0; +} + +#endif /* SLAPD_PASSWD */ diff --git a/servers/slapd/asn.h b/servers/slapd/asn.h index 17ed6f3f42..43f566ad8b 100644 --- a/servers/slapd/asn.h +++ b/servers/slapd/asn.h @@ -49,6 +49,7 @@ typedef enum AsnTypeId { BASICTYPE_OCTETCONTAINING, BASICTYPE_BITCONTAINING, BASICTYPE_RELATIVE_OID, /* 25 */ + BASICTYPE_ANY, /* 25 */ /* Embedded Composite Types*/ COMPOSITE_ASN1_TYPE, /* A New ASN.1 types including type reference */ @@ -58,7 +59,7 @@ typedef enum AsnTypeId { FacsimileTelephoneNumber_telephoneNumber, DirectoryString, /* Newly Defined ASN.1 Type, Manually registered */ - ASN_T1, + ASN_COMP_CERTIFICATE, /* ASN.1 Type End */ ASNTYPE_END } AsnTypeId; diff --git a/servers/slapd/component.c b/servers/slapd/component.c index 46559c760c..24d38becbe 100644 --- a/servers/slapd/component.c +++ b/servers/slapd/component.c @@ -26,8 +26,20 @@ #ifdef LDAP_COMP_MATCH -#include "asn.h" +#include "component.h" +/* + * This three function pointers are initialized + * when a component module is loaded + */ +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 ; + +#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 static int peek_componentId_type( ComponentAssertionValue* cav ); @@ -42,10 +54,16 @@ parse_comp_filter( Operation* op, ComponentAssertionValue* cav, ComponentFilter** filt, const char** text ); static int -test_comp_filter_attr( Operation *op, Attribute *a, struct berval *bv, +test_comp_filter( Syntax *syn, Attribute *a, struct berval *bv, ComponentFilter *f ); -int +componentCertificateValidate( + Syntax *syntax, + struct berval *val ) +{ + return LDAP_SUCCESS; +} + componentFilterValidate( Syntax *syntax, struct berval *val ) @@ -53,6 +71,14 @@ componentFilterValidate( return LDAP_SUCCESS; } +int +allComponentsValidate( + Syntax *syntax, + struct berval *val ) +{ + return LDAP_SUCCESS; +} + int componentFilterMatch ( int *matchp, @@ -62,12 +88,47 @@ componentFilterMatch ( struct berval *value, void *assertedValue ) { - /* FIXME: to be implemented */ + Attribute *a = (Attribute*)value; + MatchingRuleAssertion * ma = (MatchingRuleAssertion*)assertedValue; + + int rc; + + if ( !(mr && mr->smr_usage & SLAP_MR_COMPONENT) || !ma->ma_cf ) + return LDAP_INAPPROPRIATE_MATCHING; + + rc = test_comp_filter( syntax, a, a->a_vals, ma->ma_cf ); + if ( component_destructor && a->a_component_values ) { + component_destructor(a->a_component_values); + a->a_component_values = NULL; + } + if ( rc == LDAP_COMPARE_TRUE ) { + *matchp = 0; + return LDAP_SUCCESS; + } + else if ( rc == LDAP_COMPARE_FALSE ) { + *matchp = 1; + return LDAP_SUCCESS; + } + else { + return LDAP_INAPPROPRIATE_MATCHING; + } + +} + +int +allComponentsMatch( + int *matchp, + slap_mask_t flags, + Syntax *syntax, + MatchingRule *mr, + struct berval *value, + void *assertedValue ) +{ + /* Only for Registeration */ *matchp = 0; return LDAP_SUCCESS; } - static int slapd_ber2cav( struct berval* bv, ComponentAssertionValue* cav) { @@ -94,8 +155,9 @@ get_comp_filter ( Operation* op, struct berval* bv, ComponentFilter** filt, static void eat_whsp( ComponentAssertionValue* cav ) { - while ( ( cav->cav_ptr <= cav->cav_end ) && ( *cav->cav_ptr == ' ' ) ) - cav->cav_ptr++; + for ( ; ( *cav->cav_ptr == ' ' ) && ( cav->cav_ptr < cav->cav_end ) ; ) { + cav->cav_ptr++; + } } static int @@ -238,7 +300,9 @@ peek_componentId_type( ComponentAssertionValue* cav ) else if ( (cav->cav_end - cav->cav_ptr) >= 7 && strncmp(cav->cav_ptr,"content",7) == 0 ) return LDAP_COMPREF_CONTENT; - else if ( cav->cav_ptr[0] >= 'a' && cav->cav_ptr[0] <= 'z' ) + else if ( (cav->cav_ptr[0] >= 'a' && cav->cav_ptr[0] <= 'z') || + (cav->cav_ptr[0] >= 'A' && cav->cav_ptr[0] <= 'Z') ) + return LDAP_COMPREF_IDENTIFIER; else return LDAP_COMPREF_UNDEFINED; @@ -277,6 +341,8 @@ get_component_reference( Operation *op, ComponentAssertionValue* cav, if ( count == 0 ) ca_comp_ref->cr_curr = ca_comp_ref->cr_list; cr_list = &(*cr_list)->ci_next; } + else if ( rc == LDAP_COMPREF_UNDEFINED ) + return rc; } ca_comp_ref->cr_len = count; strip_cav_str( cav, "\""); @@ -347,10 +413,10 @@ get_matching_rule( Operation *op, ComponentAssertionValue* cav, return LDAP_SUCCESS; } -static void +static int get_GSER_value( ComponentAssertionValue* cav, struct berval* bv ) { - int count; + int count, sequent_dquote, unclosed_brace, succeed; eat_whsp( cav ); /* @@ -365,39 +431,61 @@ get_GSER_value( ComponentAssertionValue* cav, struct berval* bv ) * INTEGER, BOOLEAN, NULL,ENUMERATE, etc */ + succeed = 0; if ( cav->cav_ptr[0] == '"' ) { - for( count = 0 ; ; count++ ) { - if ( cav->cav_ptr[count] == '\0' || - ( cav->cav_ptr[count] == '"' && cav->cav_ptr[count-1] != '"') ) + for( count = 1, sequent_dquote = 0 ; ; count++ ) { + /* In order to find escaped double quote */ + if ( cav->cav_ptr[count] == '"' ) sequent_dquote++; + else sequent_dquote = 0; + + if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) { + break; + } + + if ( ( cav->cav_ptr[count] == '"' && cav->cav_ptr[count-1] != '"') || + ( sequent_dquote > 2 && (sequent_dquote%2) == 1 ) ) { + succeed = 1; break; + } } } else if ( cav->cav_ptr[0] == '\'' ) { - for( count = 0 ; ; count++ ) { - if ( cav->cav_ptr[count] == '\0' || - (cav->cav_ptr[count] == '\'' && cav->cav_ptr[count] == 'B')|| - (cav->cav_ptr[count] == '\'' && cav->cav_ptr[count] == 'H') ) + for( count = 1 ; ; count++ ) { + if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) { + break; + } + if ((cav->cav_ptr[count-1] == '\'' && cav->cav_ptr[count] == 'B')|| + (cav->cav_ptr[count-1] == '\'' && cav->cav_ptr[count] == 'H') ) { + succeed = 1; break; + } } } else if ( cav->cav_ptr[0] == '{' ) { - for( count = 0 ; ; count++ ) { - if ( cav->cav_ptr[count] == '\0' || - (cav->cav_ptr[count] == '}' && cav->cav_ptr[count] == ' ') ) + for( count = 1, unclosed_brace = 1 ; ; count++ ) { + 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 ) + break; + if ( unclosed_brace == 0 ) { + succeed = 1; break; + } } } else { - for( count = 0 ; ; count++ ) { - if ( cav->cav_ptr[count] == ' ') - break; - } + succeed = 1; + count = cav->cav_end - cav->cav_ptr; } + if ( !succeed ) return LDAP_FILTER_ERROR; + bv->bv_val = cav->cav_ptr; - bv->bv_len = count; + bv->bv_len = count + 1 ; cav->cav_ptr += count; + return LDAP_SUCCESS; } static int @@ -409,7 +497,8 @@ get_matching_value( Operation *op, ComponentAssertion* ca, ber_tag_t tag; if ( !(ca->ca_ma_rule->smr_usage & (SLAP_MR_COMPONENT)) ) { - get_GSER_value( cav, bv ); + if ( get_GSER_value( cav, bv ) != LDAP_SUCCESS ) + return LDAP_FILTER_ERROR; } else { /* embeded componentFilterMatch Description */ @@ -491,6 +580,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; + rc = peek_cav_str( cav, "component" ); if ( rc == LDAP_SUCCESS ) { strip_cav_str( cav, "component" ); @@ -511,6 +602,7 @@ get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca, op->o_tmpfree( _ca, op->o_tmpmemctx ); return rc; } + strip_cav_str( cav,","); } if ( !( strip_cav_str( cav, "rule" ) == LDAP_SUCCESS && @@ -529,7 +621,7 @@ get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca, } /* componentFilterMatch contains componentFilterMatch in it */ - if ( _ca->ca_ma_rule->smr_usage & (SLAP_MR_COMPONENT) ) { + if ( strcmp(_ca->ca_ma_rule->smr_mrule.mr_oid, OID_COMP_FILTER_MATCH ) == 0) { struct berval bv; bv.bv_val = cav->cav_ptr; bv.bv_len = cav_cur_len( cav ); @@ -669,7 +761,7 @@ parse_comp_filter( Operation* op, ComponentAssertionValue* cav, static int test_comp_filter_and( - Operation *op, + Syntax *syn, Attribute *a, struct berval *bv, ComponentFilter *flist ) @@ -678,7 +770,7 @@ test_comp_filter_and( int rtn = LDAP_COMPARE_TRUE; for ( f = flist ; f != NULL; f = f->cf_next ) { - int rc = test_comp_filter_attr( op, a, bv, f ); + int rc = test_comp_filter( syn, a, bv, f ); if ( rc == LDAP_COMPARE_FALSE ) { rtn = rc; break; @@ -694,7 +786,7 @@ test_comp_filter_and( static int test_comp_filter_or( - Operation *op, + Syntax *syn, Attribute *a, struct berval *bv, ComponentFilter *flist ) @@ -703,7 +795,7 @@ test_comp_filter_or( int rtn = LDAP_COMPARE_TRUE; for ( f = flist ; f != NULL; f = f->cf_next ) { - int rc = test_comp_filter_attr( op, a, bv, f ); + int rc = test_comp_filter( syn, a, bv, f ); if ( rc == LDAP_COMPARE_TRUE ) { rtn = rc; break; @@ -717,136 +809,138 @@ test_comp_filter_or( return rtn; } -/* - * Convert attribute value to C internal data structure - * This function has an associated ASN.1 type - * bv must contain the value for the type( type name is T1 ) - * This function is linked to ssyn_attr2comp - */ +static int +csi_value_match( MatchingRule *mr, struct berval* bv_attr, + struct berval* bv_assert ) +{ + int rc; + int match; + + assert( mr != NULL ); + assert( !(mr->smr_usage & SLAP_MR_COMPONENT) ); + + if( !mr->smr_match ) { + return LDAP_INAPPROPRIATE_MATCHING; + } + + rc = (mr->smr_match)( &match, 0, NULL /*ad->ad_type->sat_syntax*/, + mr, bv_attr, bv_assert ); + if ( rc == LDAP_SUCCESS ) + return match? LDAP_COMPARE_FALSE:LDAP_COMPARE_TRUE; + else + return rc; +} + +int +component_value_match( MatchingRule* mr, + ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) +{ + int rc; + + if ( mr->smr_usage & SLAP_MR_COMPONENT ){ + if( strcmp( mr->smr_mrule.mr_oid, OID_ALL_COMP_MATCH ) == 0 ){ + /* allComponentMatch */ + return csi_attr->csi_comp_desc->cd_all_match( NULL, + csi_attr, csi_assert ); + } + else { + return csi_assert->csi_comp_desc->cd_all_match( + mr->smr_mrule.mr_oid, csi_attr, csi_assert ); + } + } + else { + if ( csi_attr->csi_comp_desc->cd_type == ASN_BASIC ) { + struct berval bv1, bv2; + char attr_buf[MAX_LDAP_STR_LEN],assert_buf[MAX_LDAP_STR_LEN]; + bv1.bv_val = attr_buf; + bv2.bv_val = assert_buf; + if ( csi_converter && + ( csi_converter ( csi_attr, &bv1 ) == LDAP_SUCCESS ) && ( csi_converter ( csi_assert, &bv2 ) == LDAP_SUCCESS ) ) + return csi_value_match( mr, &bv1, &bv2 ); + else + return LDAP_INAPPROPRIATE_MATCHING; + + } + else if ( csi_attr->csi_comp_desc->cd_type == ASN_COMPOSITE ) { + return LDAP_INAPPROPRIATE_MATCHING; + } + } +} /* * return codes : LDAP_COMPARE_TRUE, LDAP_COMPARE_FALSE */ + static int test_comp_filter_item( - Operation *op, + Syntax *syn, Attribute *a, struct berval *bv, ComponentAssertion *ca ) { - int rc = LDAP_COMPARE_TRUE; - int len; - ComponentSyntaxInfo* csi_attr, *csi_assert; + int rc, len; + ComponentSyntaxInfo* csi_attr, *csi_assert=NULL; - if ( (ca->ca_ma_rule->smr_usage & SLAP_MR_COMPONENT) && ca->ca_cf ) { + if ( strcmp(ca->ca_ma_rule->smr_mrule.mr_oid, + OID_COMP_FILTER_MATCH ) == 0 && ca->ca_cf ) { /* componentFilterMatch inside of componentFilterMatch */ - rc = test_comp_filter_attr( op, a, bv, ca->ca_cf ); + rc = test_comp_filter( syn, a, bv, ca->ca_cf ); return rc; } - assert( !(ca->ca_ma_rule->smr_usage & SLAP_MR_COMPONENT) ); - /* FIXME : Return ALWAYS true */ - return LDAP_COMPARE_TRUE; -} + /* 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 matched, LDAP_COMPARE_TRUE is returned - */ -int -test_comp_filter_entry( - Operation *op, - Entry *e, - MatchingRuleAssertion *mra ) -{ - Attribute *a; - void *memctx; - - mra->ma_cf->cf_ca->ca_mra = mra; - - Debug( LDAP_DEBUG_FILTER, "test_comp_filter_entry\n", 0, 0, 0 ); - if ( mra->ma_desc ) { - /* - * ma_desc is available, so filtering for one attribute - * SEARCH permissionc can be checked directly - */ - if ( !access_allowed( op, e, mra->ma_desc, - &mra->ma_value, ACL_SEARCH, NULL ) ) - { - return LDAP_INSUFFICIENT_ACCESS; - } - /* Find attributes that componentFilter Match can be applied to */ - for( a=attrs_find( e->e_attrs, mra->ma_desc ); - a != NULL ; - a = attrs_find( a->a_next, mra->ma_desc ) ) - { - struct berval *bv = a->a_vals; - - for ( ; bv->bv_val != NULL ; bv++ ) { - int ret, rc; - const char *text; - rc = test_comp_filter_attr( op, a, bv, mra->ma_cf ); - if ( rc == LDAP_COMPARE_TRUE ) return rc; - } - } + if ( a->a_component_values == NULL ) + return LDAP_PROTOCOL_ERROR; - } else { - /* - * No attribute description : test all - */ - for ( a = e->e_attrs; a != NULL; a = a->a_next ) { - struct berval *bv, value; - const char *text = NULL; - int rc; - - /* check if matching is appropriate */ - if ( !mr_usable_with_at( mra->ma_rule, a->a_desc->ad_type -)) { - continue; - } - - /* check search access */ - if ( !access_allowed( op, e, - a->a_desc, &value, ACL_SEARCH, NULL ) ) { - continue; - } - - bv = a->a_vals; - - for ( ; bv->bv_val != NULL ; bv++ ) { - int ret, rc; - const char *text; - rc = test_comp_filter_attr( op, a, bv, mra->ma_cf ); - if ( rc == LDAP_COMPARE_TRUE ) break; - } - if ( rc != LDAP_SUCCESS ) return rc; - } + /* load component containg the referenced component */ + 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 ); + + 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; } + else csi_assert = ca->ca_component_values; - return LDAP_COMPARE_FALSE; + if ( !csi_assert ) + return LDAP_PROTOCOL_ERROR; + + return component_value_match( ca->ca_ma_rule, csi_attr, csi_assert); } static int -test_comp_filter_attr( - Operation *op, +test_comp_filter( + Syntax *syn, Attribute *a, struct berval *bv, ComponentFilter *f ) { int rc; - Debug( LDAP_DEBUG_FILTER, "test_comp_filter_attr\n", 0, 0, 0 ); + if ( !f ) return LDAP_PROTOCOL_ERROR; + + Debug( LDAP_DEBUG_FILTER, "test_comp_filter\n", 0, 0, 0 ); switch ( f->cf_choice ) { case SLAPD_FILTER_COMPUTED: rc = f->cf_result; break; case LDAP_COMP_FILTER_AND: - rc = test_comp_filter_and( op, a, bv, f->cf_and ); + rc = test_comp_filter_and( syn, a, bv, f->cf_and ); break; case LDAP_COMP_FILTER_OR: - rc = test_comp_filter_or( op, a, bv, f->cf_or ); + rc = test_comp_filter_or( syn, a, bv, f->cf_or ); break; case LDAP_COMP_FILTER_NOT: - rc = test_comp_filter_attr( op, a, bv, f->cf_not ); + rc = test_comp_filter( syn, a, bv, f->cf_not ); switch ( rc ) { case LDAP_COMPARE_TRUE: @@ -858,7 +952,7 @@ test_comp_filter_attr( } break; case LDAP_COMP_FILTER_ITEM: - rc = test_comp_filter_item( op, a, bv, f->cf_ca ); + rc = test_comp_filter_item( syn, a, bv, f->cf_ca ); break; default: rc = LDAP_PROTOCOL_ERROR; @@ -866,4 +960,40 @@ test_comp_filter_attr( return( rc ); } + +static void +free_comp_filter_list( ComponentFilter* f ) +{ + ComponentFilter* tmp; + for ( tmp = f ; tmp; tmp = tmp->cf_next ); + { + free_comp_filter( tmp ); + } +} + +static void +free_comp_filter( ComponentFilter* f ) +{ + switch ( f->cf_choice ) { + case LDAP_COMP_FILTER_AND: + case LDAP_COMP_FILTER_OR: + case LDAP_COMP_FILTER_NOT: + free_comp_filter( f->cf_any ); + break; + + case LDAP_COMP_FILTER_ITEM: + if ( component_destructor && f->cf_ca->ca_component_values ) + component_destructor( f->cf_ca->ca_component_values ); + break; + + default: + break; + } +} + +void +component_free( ComponentFilter *f ) { + free_comp_filter( f ); +} + #endif diff --git a/servers/slapd/filterentry.c b/servers/slapd/filterentry.c index 9092a5951b..fc090eb3fc 100644 --- a/servers/slapd/filterentry.c +++ b/servers/slapd/filterentry.c @@ -163,13 +163,6 @@ static int test_mra_filter( memfree = op->o_tmpfree; } -#ifdef LDAP_COMP_MATCH - /* Component Matching */ - if( mra->ma_cf && mra->ma_rule->smr_usage & SLAP_MR_COMPONENT ) { - return test_comp_filter_entry( op, e, mra ); - } -#endif - if ( mra->ma_desc ) { /* * if ma_desc is available, then we're filtering for @@ -189,6 +182,7 @@ static int test_mra_filter( rc = value_match( &ret, slap_schema.si_ad_entryDN, mra->ma_rule, 0, &e->e_nname, &mra->ma_value, &text ); + if( rc != LDAP_SUCCESS ) return rc; if ( ret == 0 ) return LDAP_COMPARE_TRUE; return LDAP_COMPARE_FALSE; @@ -213,9 +207,19 @@ static int test_mra_filter( int rc; const char *text; +#ifdef LDAP_COMP_MATCH + /* Component Matching */ + if( mra->ma_cf && mra->ma_rule->smr_usage & SLAP_MR_COMPONENT ) { + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, + (struct berval *)a,(void*) mra , &text ); + } + else { +#endif rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, bv, &mra->ma_value, &text ); - +#ifdef LDAP_COMP_MATCH + } +#endif if( rc != LDAP_SUCCESS ) return rc; if ( ret == 0 ) return LDAP_COMPARE_TRUE; } @@ -258,9 +262,21 @@ static int test_mra_filter( for ( ; bv->bv_val != NULL; bv++ ) { int ret; +#ifdef LDAP_COMP_MATCH + /* Component Matching */ + if( mra->ma_cf && + mra->ma_rule->smr_usage & SLAP_MR_COMPONENT) { + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, + (struct berval*)a, (void*)mra, &text ); + } + else { +#endif rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, bv, &value, &text ); +#ifdef LDAP_COMP_MATCH + } +#endif if( rc != LDAP_SUCCESS ) break; if ( ret == 0 ) { @@ -333,7 +349,6 @@ static int test_mra_filter( /* check match */ rc = value_match( &ret, ad, mra->ma_rule, 0, bv, &value, &text ); - if ( value.bv_val != mra->ma_value.bv_val ) { memfree( value.bv_val, memctx ); } diff --git a/servers/slapd/mra.c b/servers/slapd/mra.c index 7d43bba1f0..097f34b25c 100644 --- a/servers/slapd/mra.c +++ b/servers/slapd/mra.c @@ -29,6 +29,11 @@ mra_free( MatchingRuleAssertion *mra, int freeit ) { +#ifdef LDAP_COMP_MATCH + /* free component assertion */ + if ( mra->ma_rule->smr_usage & SLAP_MR_COMPONENT ) + component_free( mra->ma_cf ); +#endif /* op->o_tmpfree( mra->ma_value.bv_val, op->o_tmpmemctx ); */ ch_free( mra->ma_value.bv_val ); if ( freeit ) op->o_tmpfree( (char *) mra, op->o_tmpmemctx ); @@ -186,7 +191,6 @@ get_mra( /* Matching Rule for Component Matching */ Debug( LDAP_DEBUG_FILTER, "matchingrule %s\n", ma.ma_rule->smr_mrule.mr_oid, 0, 0); - if( ma.ma_rule && ma.ma_rule->smr_usage & SLAP_MR_COMPONENT ) { rc = get_comp_filter( op, &ma.ma_value, &ma.ma_cf, text ); if ( rc != LDAP_SUCCESS ) return rc; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index c1b316d8fc..5aa62876e8 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -342,9 +342,28 @@ 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) allComponentsMatch LDAP_P(( + int *matchp, + slap_mask_t flags, + Syntax *syntax, + MatchingRule *mr, + struct berval *value, + void *assertedValue )); + LDAP_SLAPD_F (int) componentFilterValidate LDAP_P(( Syntax *syntax, struct berval* bv )); + +LDAP_SLAPD_F (int) allComponentsValidate LDAP_P(( + Syntax *syntax, + struct berval* bv )); + #endif /* diff --git a/servers/slapd/schema/core.schema b/servers/slapd/schema/core.schema index 0694860720..199e5c72c5 100644 --- a/servers/slapd/schema/core.schema +++ b/servers/slapd/schema/core.schema @@ -248,6 +248,10 @@ attributetype ( 2.5.4.36 NAME 'userCertificate' EQUALITY certificateExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 ) +attributetype ( 1.3.6.1.4.1.4203.666.1.34 NAME 'componentCertificate' + DESC 'RFC 3687 Component Matching, use ;binary' + SYNTAX 1.3.6.1.4.1.4203.666.2.7 ) + # Must be transferred using ;binary # with certificateExactMatch rule (per X.509) attributetype ( 2.5.4.37 NAME 'cACertificate' @@ -392,7 +396,7 @@ objectclass ( 2.5.6.7 NAME 'organizationalPerson' SUP person STRUCTURAL MAY ( title $ x121Address $ registeredAddress $ destinationIndicator $ preferredDeliveryMethod $ telexNumber $ teletexTerminalIdentifier $ - telephoneNumber $ internationaliSDNNumber $ + telephoneNumber $ internationaliSDNNumber $ componentCertificate $ facsimileTelephoneNumber $ street $ postOfficeBox $ postalCode $ postalAddress $ physicalDeliveryOfficeName $ ou $ st $ l ) ) diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 7c85723617..8c6e5fef6f 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -3073,8 +3073,13 @@ static slap_syntax_defs_rec syntax_defs[] = { {"( 1.2.36.79672281.1.5.0 DESC 'RDN' )", 0, rdnValidate, rdnPretty}, #ifdef LDAP_COMP_MATCH - {"( 1.2.36.79672281.1.5.2 DESC 'ComponentFilter' )", + {"( 1.2.36.79672281.1.5.3 DESC 'allComponents' )", + 0, allComponentsValidate, NULL}, + {"( 1.2.36.79672281.1.5.2 DESC 'componentFilter') ", 0, componentFilterValidate, NULL}, + {"( 1.3.6.1.4.1.4203.666.2.7 DESC 'componentCertificate' " + X_BINARY X_NOT_H_R ")", + SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, componentCertificateValidate, NULL}, #endif {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )", 0, NULL, NULL}, @@ -3320,10 +3325,23 @@ static slap_mrule_defs_rec mrule_defs[] = { #ifdef LDAP_COMP_MATCH {"( 1.2.36.79672281.1.13.2 NAME 'componentFilterMatch' " "SYNTAX 1.2.36.79672281.1.5.2 )", - SLAP_MR_EQUALITY|SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL, + SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL, NULL, NULL , componentFilterMatch, octetStringIndexer, octetStringFilter, NULL }, + + {"( 1.2.36.79672281.1.13.6 NAME 'allComponentsMatch' " + "SYNTAX 1.2.36.79672281.1.5.3 )", + SLAP_MR_EQUALITY|SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL, + NULL, NULL , allComponentsMatch, + octetStringIndexer, octetStringFilter, + NULL }, + {"( 1.3.6.1.4.1.4203.666.4.12 NAME 'componentCertificateMatch' " + "SYNTAX 1.3.6.1.4.1.4203.666.2.7 )", + SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL, + NULL, NULL , componentCertificateMatch, + octetStringIndexer, octetStringFilter, + NULL }, #endif {"( 2.5.13.2 NAME 'caseIgnoreMatch' " diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 9c8043e5c6..a817ce2d46 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -147,7 +147,7 @@ do_search( goto return_results; } filter2bv_x( op, op->ors_filter, &op->ors_filterstr ); - + Debug( LDAP_DEBUG_ARGS, " filter: %s\n", !BER_BVISEMPTY( &op->ors_filterstr ) ? op->ors_filterstr.bv_val : "empty", 0, 0 ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 02e128ff39..7e2c36f1ee 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -2572,6 +2572,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; struct slap_component_filter *ca_cf; MatchingRuleAssertion *ca_mra; } ComponentAssertion; @@ -2589,6 +2590,7 @@ typedef struct slap_component_filter { #define cf_and cf_un.cf_un_complex #define cf_or cf_un.cf_un_complex #define cf_not cf_un.cf_un_complex +#define cf_any cf_un.cf_un_complex struct slap_component_filter *cf_next; } ComponentFilter; @@ -2598,43 +2600,76 @@ typedef struct slap_component_assertion_value { char* cav_ptr; char* cav_end; } ComponentAssertionValue; - -#include "asn.h" - +/* typedef int encoder_func LDAP_P(( void* b, - void* comp)); + void* comp));*/ struct slap_component_syntax_info; -typedef int decoder_func LDAP_P(( +typedef int gser_decoder_func LDAP_P(( void* b, - struct slap_component_syntax_info** comp_syn_info, - unsigned int* len, + struct slap_component_syntax_info* comp_syn_info, + int* len, int mode)); -typedef void* extract_component_from_tag_func LDAP_P(( - int *tag)); +typedef int comp_free_func LDAP_P(( + void* b)); + +typedef int ber_decoder_func LDAP_P(( + void* b, + int tag, + int elmtLen, + struct slap_component_syntax_info* comp_syn_info, + int* len, + int mode)); + +typedef int ber_tag_decoder_func LDAP_P(( + void* b, + struct slap_component_syntax_info* comp_syn_info, + int* len, + int mode)); typedef void* extract_component_from_id_func LDAP_P(( ComponentReference* cr, void* comp )); +typedef void* convert_attr_to_comp_func LDAP_P (( + Attribute* a, + Syntax* syn, + struct berval* bv )); + +struct slap_component_syntax_info; +typedef int convert_assert_to_comp_func LDAP_P (( + struct slap_component_syntax_info* csi_attr, + struct berval* bv, + struct slap_component_syntax_info** csi, + int* len, + int mode )); + +typedef int convert_asn_to_ldap_func LDAP_P (( + struct slap_component_syntax_info* csi, + struct berval *bv )); + +typedef void free_component_func LDAP_P (( + struct slap_component_syntax_info* csi )); + typedef int allcomponent_matching_func LDAP_P(( char* oid, - void* component1, - void* component2 )); + struct slap_component_syntax_info* comp1, + struct slap_component_syntax_info* comp)); typedef struct slap_component_desc{ int cd_tag; - ComponentId* cd_identifier; - encoder_func *cd_encoder; - decoder_func *cd_decoder; - extract_component_from_tag_func* cd_extract_t; + int cd_type; + int cd_type_id; + gser_decoder_func *cd_gser_decoder; + ber_decoder_func *cd_ber_decoder; + comp_free_func *cd_free; extract_component_from_id_func* cd_extract_i; - AsnType cd_type; - AsnTypeId cd_type_id; - allcomponent_matching_func* cd_all_match; + slap_syntax_validate_func *cd_validate; + slap_syntax_transform_func *cd_pretty; + allcomponent_matching_func *cd_all_match; } ComponentDesc; typedef struct slap_component_syntax_info { @@ -2642,18 +2677,6 @@ typedef struct slap_component_syntax_info { ComponentDesc* csi_comp_desc; } ComponentSyntaxInfo; -typedef struct asntype_to_matchingrule { - AsnTypeId atmr_typeId; - char* atmr_mr_name; - MatchingRule *atmr_mr; -} AsnTypetoMatchingRule; - -typedef struct asntype_to_matchingrule_table { - char* atmr_oid; - struct asntype_to_matchingrule atmr_table[ASNTYPE_END]; - struct asntype_to_matchingrule_table* atmr_table_next; -} AsnTypetoMatchingRuleTable; - #endif LDAP_END_DECL diff --git a/servers/slapd/value.c b/servers/slapd/value.c index cf46e7765b..7612dddd34 100644 --- a/servers/slapd/value.c +++ b/servers/slapd/value.c @@ -185,7 +185,6 @@ int asserted_value_validate_normalize( return LDAP_SUCCESS; } - int value_match( int *match, diff --git a/tests/data/compsearch.out b/tests/data/compsearch.out index fb55ca6636..81ae1478e1 100644 --- a/tests/data/compsearch.out +++ b/tests/data/compsearch.out @@ -1,64 +1,153 @@ -dn: uid=sangseoklim,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: sangseoklim -cn: Sang Seok Lim -sn: Lim -componentTest: component1 +uid:: Y2hhcmxpZSA= +cn: beta +sn: Jee +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= + +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com +objectClass: OpenLDAPperson +objectClass: extensibleObject +uid:: Y2hhcmxpZSA= +cn: charlie +sn: Jee +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=seotaejee,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: seotaejee -cn: Seo Tae Jee +uid:: Y2hhcmxpZSA= +cn: beta sn: Jee -componentTest: component2 +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=sangseoklim,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: sangseoklim -cn: Sang Seok Lim -sn: Lim -componentTest: component1 +uid:: Y2hhcmxpZSA= +cn: charlie +sn: Jee +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=seotaejee,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: seotaejee -cn: Seo Tae Jee +uid:: Y2hhcmxpZSA= +cn: beta sn: Jee -componentTest: component2 +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=sangseoklim,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: sangseoklim -cn: Sang Seok Lim -sn: Lim -componentTest: component1 +uid:: Y2hhcmxpZSA= +cn: charlie +sn: Jee +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=seotaejee,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: seotaejee -cn: Seo Tae Jee +uid:: Y2hhcmxpZSA= +cn: beta sn: Jee -componentTest: component2 +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=sangseoklim,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: sangseoklim -cn: Sang Seok Lim -sn: Lim -componentTest: component1 +uid:: Y2hhcmxpZSA= +cn: charlie +sn: Jee +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= -dn: uid=seotaejee,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com objectClass: OpenLDAPperson objectClass: extensibleObject -uid: seotaejee -cn: Seo Tae Jee +uid:: Y2hhcmxpZSA= +cn: charlie sn: Jee -componentTest: component2 +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQsw + CQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTM + IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2 + QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+ + tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4E + FgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihE + aQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44lao + KcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5 + rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9 + a+4XrEkBJ/Q= diff --git a/tests/data/slapd-component.conf b/tests/data/slapd-component.conf index 4759439c58..0bc594844c 100644 --- a/tests/data/slapd-component.conf +++ b/tests/data/slapd-component.conf @@ -19,13 +19,13 @@ include ./schema/cosine.schema include ./schema/inetorgperson.schema include ./schema/openldap.schema include ./schema/nis.schema -include ./schema/test.schema include ./testdata/ditcontentrules.conf pidfile ./testrun/slapd.1.pid argsfile ./testrun/slapd.1.args +moduleload ./testdata/comp_libs/compmatch.la #mod#modulepath ../servers/slapd/back-@BACKEND@/ #mod#moduleload back_@BACKEND@.la #monitormod#modulepath ../servers/slapd/back-monitor/ diff --git a/tests/data/test-compmatch.ldif b/tests/data/test-compmatch.ldif index 3782b93903..bbec2aaac0 100644 --- a/tests/data/test-compmatch.ldif +++ b/tests/data/test-compmatch.ldif @@ -395,18 +395,18 @@ pager: +1 313 555 7671 facsimiletelephonenumber: +1 313 555 7762 telephonenumber: +1 313 555 4177 -dn: uid=sangseoklim,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=charlie,ou=Alumni Association,ou=People,dc=example,dc=com objectclass: OpenLDAPperson objectclass: extensibleObject -uid: sangseoklim -cn: Sang Seok Lim -sn: Lim -componentTest: component1 +uid: charlie +cn: charlie +sn: Jee +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQswCQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4EFgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihEaQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44laoKcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9a+4XrEkBJ/Q= -dn: uid=seotaejee,ou=Alumni Association,ou=People,dc=example,dc=com +dn: cn=beta,ou=Alumni Association,ou=People,dc=example,dc=com objectclass: OpenLDAPperson objectclass: extensibleObject -uid: seotaejee -cn: Seo Tae Jee +uid: charlie +cn: beta sn: Jee -componentTest: component2 +componentCertificate;binary:: MIIB9jCCAV+gAwIBAgIBADANBgkqhkiG9w0BAQQFADANMQswCQYDVQQGEwJVUzAeFw0wNDEwMTIwMDAxNTBaFw0wNDExMTEwMDAxNTBaMA0xCzAJBgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQcTs4uD+gAoQ1XkYN4woLtZaEi7XVEVIJQ6Rsn2QP3MONBT9jvrhVcnUJQtvEEkfnsNANKeYntUTvih76jErFNTmg7zl0govFSkiuS+tfrZnn/Ebix3+tTMnAKUQXkYi5Mr+x3U44yYo1EPLpZlcV1Caafc30EMRQ/Gv/PdrqYwIDAQABo2YwZDAdBgNVHQ4EFgQUAzNnruNiI38IPf39ZJGFx8mDsxgwNQYDVR0jBC4wLIAUAzNnruNiI38IPf39ZJGFx8mDsxihEaQPMA0xCzAJBgNVBAYTAlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAf44laoKcTySuz3yQb/lfOBVDh6oMxysal0eEij+nypQJ1H+rsZ+ebUlKMiTYhrTk3n3H6moHaxICENIu4P5rD5UedAWtMjWq2ZJIa26bbvB4enGOF66KH5S823ZdKa0Kr2JcHAAYFpf+TQoGg5JO7TD3AECd7Qo9a+4XrEkBJ/Q= diff --git a/tests/run.in b/tests/run.in index 3f9043ad6e..b51da157eb 100644 --- a/tests/run.in +++ b/tests/run.in @@ -41,11 +41,11 @@ AC_rwm=rwm@BUILD_RWM@ # misc AC_WITH_SASL=@WITH_SASL@ AC_WITH_TLS=@WITH_TLS@ -AC_WITH_COMP_MATCH=yes +AC_WITH_MODULES_ENABLED=@WITH_MODULES_ENABLED@ export AC_bdb AC_hdb AC_ldap AC_ldbm AC_monitor AC_relay AC_sql export AC_pcache AC_ppolicy AC_refint AC_unique AC_rwm -export AC_WITH_SASL AC_WITH_TLS AC_WITH_COMP_MATCH +export AC_WITH_SASL AC_WITH_TLS AC_WITH_MODULES_ENABLED if test ! -x ../servers/slapd/slapd ; then echo "Could not locate slapd(8)" diff --git a/tests/scripts/test031-component-filter b/tests/scripts/test031-component-filter index b0bb66b697..7568ab73b2 100755 --- a/tests/scripts/test031-component-filter +++ b/tests/scripts/test031-component-filter @@ -18,21 +18,27 @@ echo "running defines.sh" ## If you use this script then ## Make sure that you turn on LDAP_COMP_MATCH in slapd source codes -## To disable, set "WITH_COMP_MATCH=no" in source_root/openldap/tests/run.in -if test "$AC_WITH_COMP_MATCH" != "yes" ; then - echo "test disabled " +## and --enable-modules is configured yes +if test "$AC_WITH_MODULES_ENABLED" != "yes" ; then + echo "dynamic module disabled " exit fi mkdir -p $TESTDIR $DBDIR1 +## Make sure that you set a proper path to component matching +## module directory in $COMPCONF +## moduleload path/to/component/library/compmatch.la +## otherwise it fails to execute slapd echo "Running slapadd to build slapd database..." . $CONFFILTER $BACKEND $MONITORDB < $COMPCONF > $ADDCONF $SLAPADD -f $ADDCONF -l $LDIFCOMPMATCH RC=$? if test $RC != 0 ; then echo "slapadd failed ($RC)!" - exit $RC + echo "Be sure to have a certificate module in tests/data/comp_libs " + echo "The module is in openldap/contrib/slapd-modules/comp_match" + exit fi echo "Running slapindex to index slapd database..." @@ -73,10 +79,10 @@ fi cat /dev/null > $SEARCHOUT -echo "Testing Component Filter Match RFC3687 searching:" -echo "# Testing Component Filter Match RFC3687 searching:" >> $SEARCHOUT +echo "Testing Component Filter Match RFC3687 Certificate searching:" +echo "# Testing Component Filter Match RFC3687 Certificate searching:" >> $SEARCHOUT -FILTER="(componentTest:componentFilterMatch:=item:{ component \"id\", rule caseExactMatch, value \"worldcup\" )" +FILTER="(componentCertificate:componentCertificateMatch:=item:{ component \"tbsCertificate.serialNumber\", rule allComponentsMatch, value 0 })" echo " f=$FILTER ..." echo "# f=$FILTER ..." >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ @@ -89,7 +95,7 @@ if test $RC != 0 ; then exit $RC fi -FILTER="(componentTest:componentFilterMatch:=not:item:{ component \"id2\", rule caseExactMatch, value \"worldcup\" )" +FILTER="(componentCertificate:componentCertificateMatch:=item:{ component \"tbsCertificate.version\", rule allComponentsMatch, value 2 })" echo " f=$FILTER ..." echo "# f=$FILTER ..." >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ @@ -102,7 +108,7 @@ if test $RC != 0 ; then exit $RC fi -FILTER="(componentTest:componentFilterMatch:=not:item:{ component \"id2\", rule componentFilterMatch, value not:item:{ component \"id.0\", rule integerMatch, value 5 }})" +FILTER="(componentCertificate:componentCertificateMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence.1.1.value\", rule octetStringMatch, value \"US\" })" echo " f=$FILTER ..." echo "# f=$FILTER ..." >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ @@ -115,7 +121,7 @@ if test $RC != 0 ; then exit $RC fi -FILTER="(componentTest:componentFilterMatch:=and:{item:{ component \"100\", rule caseIgnoreMatch, value "foobar" },item:{ component \"id2.rr.kk\", rule componentFilterMatch, value item:{ component \"id3\", rule integerMatch, value 1 }}})" +FILTER="(componentCertificate:componentCertificateMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence.1.1.value\", rule allComponentsMatch, value \"US\" })" echo " f=$FILTER ..." echo "# f=$FILTER ..." >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ @@ -128,7 +134,7 @@ if test $RC != 0 ; then exit $RC fi -FILTER="(componentTest:componentFilterMatch:=and:{not:item:{ component \"100\", rule caseIgnoreMatch, value "foobar" },not:item:{ component \"id2.rr.kk\", rule componentFilterMatch, value item:{ component \"id3\", rule integerMatch, value 1 }}})" +FILTER="(componentCertificate:componentCertificateMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence\", rule allComponentsMatch, value { { { type 2.5.4.6 , value \"US\" } } } })" echo " f=$FILTER ..." echo "# f=$FILTER ..." >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ @@ -141,18 +147,8 @@ if test $RC != 0 ; then exit $RC fi -FILTER="(componentTest:componentFilterMatch:=or:{not:item:{ component \"100\", rule caseIgnoreMatch, value "foobar" },not:item:{ component \"id2.rr.kk\", rule componentFilterMatch, value item:{ component \"id3\", rule integerMatch, value 1 }}})" -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 echo "Filtering ldapsearch results..." -- 2.39.5