Home | History | Annotate | Line # | Download | only in comp_match
      1  1.2  christos /*	$NetBSD: init.c,v 1.2 2021/08/14 16:14:51 christos Exp $	*/
      2  1.2  christos 
      3  1.1     lukem /* Copyright 2004 IBM Corporation
      4  1.1     lukem  * All rights reserved.
      5  1.2  christos  * Redistribution and use in source and binary forms, with or without
      6  1.2  christos  * modification, are permitted only as authorized by the OpenLDAP
      7  1.1     lukem  * Public License.
      8  1.1     lukem  */
      9  1.1     lukem /* ACKNOWLEDGEMENTS
     10  1.1     lukem  * This work originally developed by Sang Seok Lim
     11  1.1     lukem  * 2004/06/18	03:20:00	slim (at) OpenLDAP.org
     12  1.1     lukem  */
     13  1.1     lukem 
     14  1.2  christos #include <sys/cdefs.h>
     15  1.2  christos __RCSID("$NetBSD: init.c,v 1.2 2021/08/14 16:14:51 christos Exp $");
     16  1.2  christos 
     17  1.1     lukem #include "portable.h"
     18  1.1     lukem #include <ac/string.h>
     19  1.1     lukem #include <ac/socket.h>
     20  1.1     lukem #include <ldap_pvt.h>
     21  1.1     lukem #include "lutil.h"
     22  1.1     lukem #include <ldap.h>
     23  1.1     lukem #include "slap.h"
     24  1.1     lukem #include "component.h"
     25  1.1     lukem 
     26  1.1     lukem #include "componentlib.h"
     27  1.1     lukem #include "asn.h"
     28  1.1     lukem #include <asn-gser.h>
     29  1.1     lukem 
     30  1.1     lukem #include <string.h>
     31  1.1     lukem 
     32  1.1     lukem #ifndef SLAPD_COMP_MATCH
     33  1.1     lukem #define SLAPD_COMP_MATCH SLAPD_MOD_DYNAMIC
     34  1.1     lukem #endif
     35  1.1     lukem 
     36  1.1     lukem /*
     37  1.1     lukem  * Attribute and MatchingRule aliasing table
     38  1.1     lukem  */
     39  1.1     lukem AttributeAliasing aa_table [ MAX_ALIASING_ENTRY ];
     40  1.1     lukem MatchingRuleAliasing mra_table [ MAX_ALIASING_ENTRY ];
     41  1.1     lukem 
     42  1.1     lukem OD_entry* gOD_table = NULL;
     43  1.1     lukem AsnTypetoMatchingRuleTable* gATMR_table = NULL;
     44  1.1     lukem 
     45  1.1     lukem int
     46  1.1     lukem load_derived_matching_rule ( char* cfg_path ){
     47  1.1     lukem }
     48  1.1     lukem 
     49  1.1     lukem AttributeAliasing*
     50  1.1     lukem comp_is_aliased_attribute( void *in  )
     51  1.1     lukem {
     52  1.1     lukem 	AttributeAliasing* curr_aa;
     53  1.1     lukem 	int i;
     54  1.1     lukem 	AttributeDescription *ad = (AttributeDescription*)in;
     55  1.1     lukem 
     56  1.1     lukem 	for ( i = 0; aa_table[i].aa_aliasing_ad && i < MAX_ALIASING_ENTRY; i++ ) {
     57  1.1     lukem 		if ( strncmp(aa_table[i].aa_aliasing_ad->ad_cname.bv_val , ad->ad_cname.bv_val, ad->ad_cname.bv_len) == 0 )
     58  1.1     lukem 			return &aa_table[i];
     59  1.1     lukem 	}
     60  1.1     lukem 	return NULL;
     61  1.1     lukem }
     62  1.1     lukem 
     63  1.1     lukem static int
     64  1.1     lukem add_aa_entry( int index, char* aliasing_at_name, char* aliased_at_name, char* mr_name, char* component_filter )
     65  1.1     lukem {
     66  1.1     lukem 	char text[1][128];
     67  1.1     lukem 	int rc;
     68  1.1     lukem 	struct berval type;
     69  1.1     lukem 
     70  1.1     lukem 	/* get and store aliasing AttributeDescription */
     71  1.1     lukem 	type.bv_val = aliasing_at_name;
     72  1.1     lukem 	type.bv_len = strlen ( aliasing_at_name );
     73  1.1     lukem 	rc = slap_bv2ad ( &type, &aa_table[index].aa_aliasing_ad,(const char**)text );
     74  1.1     lukem 	if ( rc != LDAP_SUCCESS ) return rc;
     75  1.1     lukem 
     76  1.1     lukem 	/* get and store aliased AttributeDescription */
     77  1.1     lukem 	type.bv_val = aliased_at_name;
     78  1.1     lukem 	type.bv_len = strlen ( aliased_at_name );
     79  1.1     lukem 	rc = slap_bv2ad ( &type, &aa_table[index].aa_aliased_ad,(const char**)text );
     80  1.1     lukem 	if ( rc != LDAP_SUCCESS ) return rc;
     81  1.1     lukem 
     82  1.1     lukem 	/* get and store componentFilterMatch */
     83  1.1     lukem 	type.bv_val = mr_name;
     84  1.1     lukem 	type.bv_len = strlen ( mr_name);
     85  1.1     lukem 	aa_table[index].aa_mr = mr_bvfind ( &type );
     86  1.1     lukem 
     87  1.1     lukem 	/* get and store a component filter */
     88  1.1     lukem 	type.bv_val = component_filter;
     89  1.1     lukem 	type.bv_len = strlen ( component_filter );
     90  1.1     lukem 	rc = get_comp_filter( NULL, &type, &aa_table[index].aa_cf,(const char**)text);
     91  1.1     lukem 
     92  1.1     lukem 	aa_table[index].aa_cf_str = component_filter;
     93  1.1     lukem 
     94  1.1     lukem 	return rc;
     95  1.1     lukem }
     96  1.1     lukem 
     97  1.1     lukem /*
     98  1.1     lukem  * Initialize attribute aliasing table when this module is loaded
     99  1.1     lukem  * add_aa_entry ( index for the global table,
    100  1.1     lukem  *                name of the aliasing attribute,
    101  1.1     lukem  *                component filter with filling value parts "xxx"
    102  1.1     lukem  *              )
    103  1.1     lukem  * "xxx" will be replaced with effective values later.
    104  1.1     lukem  * See RFC3687 to understand the content of a component filter.
    105  1.1     lukem  */
    106  1.1     lukem char* pre_processed_comp_filter[] = {
    107  1.1     lukem /*1*/"item:{ component \"toBeSigned.issuer.rdnSequence\", rule distinguishedNameMatch, value xxx }",
    108  1.1     lukem /*2*/"item:{ component \"toBeSigned.serialNumber\", rule integerMatch, value xxx }",
    109  1.1     lukem /*3*/"and:{ item:{ component \"toBeSigned.serialNumber\", rule integerMatch, value xxx }, item:{ component \"toBeSigned.issuer.rdnSequence\", rule distinguishedNameMatch, value xxx } }"
    110  1.1     lukem };
    111  1.1     lukem 
    112  1.1     lukem static int
    113  1.1     lukem init_attribute_aliasing_table ()
    114  1.1     lukem {
    115  1.1     lukem 	int rc;
    116  1.1     lukem 	int index = 0 ;
    117  1.1     lukem 
    118  1.1     lukem 	rc = add_aa_entry ( index, "x509CertificateIssuer", "userCertificate","componentFilterMatch", pre_processed_comp_filter[index] );
    119  1.1     lukem 	if ( rc != LDAP_SUCCESS ) return LDAP_PARAM_ERROR;
    120  1.1     lukem 	index++;
    121  1.1     lukem 
    122  1.1     lukem 	rc = add_aa_entry ( index, "x509CertificateSerial","userCertificate", "componentFilterMatch", pre_processed_comp_filter[index] );
    123  1.1     lukem 	if ( rc != LDAP_SUCCESS ) return LDAP_PARAM_ERROR;
    124  1.1     lukem 	index++;
    125  1.1     lukem 
    126  1.1     lukem 	rc = add_aa_entry ( index, "x509CertificateSerialAndIssuer", "userCertificate", "componentFilterMatch", pre_processed_comp_filter[index] );
    127  1.1     lukem 	if ( rc != LDAP_SUCCESS ) return LDAP_PARAM_ERROR;
    128  1.1     lukem 	index++;
    129  1.1     lukem 
    130  1.1     lukem 	return LDAP_SUCCESS;
    131  1.1     lukem }
    132  1.1     lukem 
    133  1.1     lukem void
    134  1.1     lukem init_component_description_table () {
    135  1.1     lukem 	AsnTypeId id;
    136  1.1     lukem 	struct berval mr;
    137  1.1     lukem 	AsnTypetoSyntax* asn_to_syn;
    138  1.1     lukem 	Syntax* syn;
    139  1.1     lukem 
    140  1.1     lukem 	for ( id = BASICTYPE_BOOLEAN; id != ASNTYPE_END ; id++ ) {
    141  1.1     lukem 		asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_subtypes = NULL;
    142  1.1     lukem 		asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_syntax =  NULL;
    143  1.1     lukem 
    144  1.1     lukem 		/* Equality Matching Rule */
    145  1.1     lukem 		if ( asntype_to_compMR_mapping_tbl[id].atc_equality ) {
    146  1.1     lukem 			mr.bv_val = asntype_to_compMR_mapping_tbl[id].atc_equality;
    147  1.1     lukem 			mr.bv_len = strlen(asntype_to_compMR_mapping_tbl[id].atc_equality);
    148  1.1     lukem 			asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_equality = mr_bvfind( &mr );
    149  1.1     lukem 		}
    150  1.1     lukem 		/* Approx Matching Rule */
    151  1.1     lukem 		if ( asntype_to_compMR_mapping_tbl[id].atc_approx ) {
    152  1.1     lukem 			mr.bv_val = asntype_to_compMR_mapping_tbl[id].atc_approx;
    153  1.1     lukem 			mr.bv_len = strlen(asntype_to_compMR_mapping_tbl[id].atc_approx);
    154  1.1     lukem 			asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_approx = mr_bvfind( &mr );
    155  1.1     lukem 		}
    156  1.1     lukem 
    157  1.1     lukem 		/* Ordering Matching Rule */
    158  1.1     lukem 		if ( asntype_to_compMR_mapping_tbl[id].atc_ordering ) {
    159  1.1     lukem 			mr.bv_val = asntype_to_compMR_mapping_tbl[id].atc_ordering;
    160  1.1     lukem 			mr.bv_len = strlen(asntype_to_compMR_mapping_tbl[id].atc_ordering);
    161  1.1     lukem 			asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_ordering= mr_bvfind( &mr );
    162  1.1     lukem 		}
    163  1.1     lukem 
    164  1.1     lukem 		/* Substr Matching Rule */
    165  1.1     lukem 		if ( asntype_to_compMR_mapping_tbl[id].atc_substr ) {
    166  1.1     lukem 			mr.bv_val = asntype_to_compMR_mapping_tbl[id].atc_substr;
    167  1.1     lukem 			mr.bv_len = strlen(asntype_to_compMR_mapping_tbl[id].atc_substr);
    168  1.1     lukem 			asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_substr = mr_bvfind( &mr );
    169  1.1     lukem 		}
    170  1.1     lukem 		/* Syntax */
    171  1.1     lukem 
    172  1.1     lukem 		asn_to_syn = &asn_to_syntax_mapping_tbl[ id ];
    173  1.1     lukem 		if ( asn_to_syn->ats_syn_oid )
    174  1.1     lukem 			syn = syn_find ( asn_to_syn->ats_syn_oid );
    175  1.1     lukem 		else
    176  1.1     lukem 			syn = NULL;
    177  1.1     lukem 		asntype_to_compType_mapping_tbl[id].ac_comp_type.ct_syntax = syn;
    178  1.1     lukem 
    179  1.1     lukem 		/* Initialize Component Descriptions of primitive ASN.1 types */
    180  1.1     lukem 		asntype_to_compdesc_mapping_tbl[id].atcd_cd.cd_comp_type = (AttributeType*)&asntype_to_compType_mapping_tbl[id].ac_comp_type;
    181  1.1     lukem 	}
    182  1.1     lukem }
    183  1.1     lukem 
    184  1.1     lukem MatchingRule*
    185  1.1     lukem retrieve_matching_rule( char* mr_oid, AsnTypeId type ) {
    186  1.1     lukem 	char* tmp;
    187  1.1     lukem 	struct berval mr_name = BER_BVNULL;
    188  1.1     lukem 	AsnTypetoMatchingRuleTable* atmr;
    189  1.1     lukem 
    190  1.1     lukem 	for ( atmr = gATMR_table ; atmr ; atmr = atmr->atmr_table_next ) {
    191  1.1     lukem 		if ( strcmp( atmr->atmr_oid, mr_oid ) == 0 ) {
    192  1.1     lukem 			tmp = atmr->atmr_table[type].atmr_mr_name;
    193  1.1     lukem 			if ( tmp ) {
    194  1.1     lukem 				mr_name.bv_val = tmp;
    195  1.1     lukem 				mr_name.bv_len = strlen( tmp );
    196  1.1     lukem 				return mr_bvfind ( &mr_name );
    197  1.1     lukem 			}
    198  1.1     lukem 		}
    199  1.1     lukem 	}
    200  1.1     lukem 	return (MatchingRule*)NULL;
    201  1.1     lukem }
    202  1.1     lukem 
    203  1.1     lukem void*
    204  1.1     lukem comp_convert_attr_to_comp LDAP_P (( Attribute* a, Syntax *syn, struct berval* bv ))
    205  1.1     lukem {
    206  1.1     lukem 	char* peek_head;
    207  1.1     lukem         int mode, bytesDecoded, size, rc;
    208  1.1     lukem         void* component;
    209  1.1     lukem 	char* oid = a->a_desc->ad_type->sat_atype.at_oid ;
    210  1.1     lukem         GenBuf* b = NULL;
    211  1.1     lukem         ExpBuf* buf = NULL;
    212  1.1     lukem 	OidDecoderMapping* odm;
    213  1.1     lukem 
    214  1.1     lukem 	/* look for the decoder registered for the given attribute */
    215  1.1     lukem 	odm = RetrieveOidDecoderMappingbyOid( oid, strlen(oid) );
    216  1.1     lukem 
    217  1.1     lukem 	if ( !odm || (!odm->BER_Decode && !odm->GSER_Decode) )
    218  1.1     lukem 		return (void*)NULL;
    219  1.1     lukem 
    220  1.1     lukem 	buf = ExpBufAllocBuf();
    221  1.1     lukem 	ExpBuftoGenBuf( buf, &b );
    222  1.1     lukem 	ExpBufInstallDataInBuf ( buf, bv->bv_val, bv->bv_len );
    223  1.1     lukem 	BufResetInReadMode( b );
    224  1.1     lukem 
    225  1.1     lukem 	mode = DEC_ALLOC_MODE_2;
    226  1.1     lukem 	/*
    227  1.1     lukem 	 * How can we decide which decoder will be called, GSER or BER?
    228  1.1     lukem 	 * Currently BER decoder is called for a certificate.
    229  1.1     lukem 	 * The flag of Attribute will say something about it in the future
    230  1.1     lukem 	 */
    231  1.1     lukem 	if ( syn && slap_syntax_is_ber ( syn ) ) {
    232  1.1     lukem #if 0
    233  1.1     lukem 		rc =BDecComponentTop(odm->BER_Decode, a->a_comp_data->cd_mem_op, b, 0,0, &component,&bytesDecoded,mode ) ;
    234  1.1     lukem #endif
    235  1.1     lukem 		rc = odm->BER_Decode ( a->a_comp_data->cd_mem_op, b, (ComponentSyntaxInfo*)&component, &bytesDecoded, mode );
    236  1.1     lukem 	}
    237  1.1     lukem 	else {
    238  1.1     lukem 		rc = odm->GSER_Decode( a->a_comp_data->cd_mem_op, b, (ComponentSyntaxInfo**)component, &bytesDecoded, mode);
    239  1.1     lukem 	}
    240  1.1     lukem 
    241  1.1     lukem 	ExpBufFreeBuf( buf );
    242  1.1     lukem 	GenBufFreeBuf( b );
    243  1.1     lukem 	if ( rc == -1 ) {
    244  1.1     lukem #if 0
    245  1.1     lukem 		ShutdownNibbleMemLocal ( a->a_comp_data->cd_mem_op );
    246  1.1     lukem 		free ( a->a_comp_data );
    247  1.1     lukem 		a->a_comp_data = NULL;
    248  1.1     lukem #endif
    249  1.1     lukem 		return (void*)NULL;
    250  1.1     lukem 	}
    251  1.1     lukem 	else {
    252  1.1     lukem 		return component;
    253  1.1     lukem 	}
    254  1.1     lukem }
    255  1.1     lukem 
    256  1.1     lukem #include <nibble-alloc.h>
    257  1.1     lukem void
    258  1.1     lukem comp_free_component ( void* mem_op ) {
    259  1.1     lukem 	ShutdownNibbleMemLocal( (NibbleMem*)mem_op );
    260  1.1     lukem 	return;
    261  1.1     lukem }
    262  1.1     lukem 
    263  1.1     lukem void
    264  1.1     lukem comp_convert_assert_to_comp (
    265  1.1     lukem 	void* mem_op,
    266  1.1     lukem 	ComponentSyntaxInfo *csi_attr,
    267  1.1     lukem 	struct berval* bv,
    268  1.1     lukem 	ComponentSyntaxInfo** csi, int* len, int mode )
    269  1.1     lukem {
    270  1.1     lukem 	int rc;
    271  1.1     lukem 	GenBuf* genBuf;
    272  1.1     lukem 	ExpBuf* buf;
    273  1.1     lukem 	gser_decoder_func *decoder = csi_attr->csi_comp_desc->cd_gser_decoder;
    274  1.1     lukem 
    275  1.1     lukem 	buf = ExpBufAllocBuf();
    276  1.1     lukem 	ExpBuftoGenBuf( buf, &genBuf );
    277  1.1     lukem 	ExpBufInstallDataInBuf ( buf, bv->bv_val, bv->bv_len );
    278  1.1     lukem 	BufResetInReadMode( genBuf );
    279  1.1     lukem 
    280  1.1     lukem 	if ( csi_attr->csi_comp_desc->cd_type_id == BASICTYPE_ANY )
    281  1.1     lukem 		decoder = ((ComponentAny*)csi_attr)->cai->GSER_Decode;
    282  1.1     lukem 
    283  1.1     lukem 	rc = (*decoder)( mem_op, genBuf, csi, len, mode );
    284  1.1     lukem 	ExpBufFreeBuf ( buf );
    285  1.1     lukem 	GenBufFreeBuf( genBuf );
    286  1.1     lukem }
    287  1.1     lukem 
    288  1.1     lukem int intToAscii( int value, char* buf ) {
    289  1.1     lukem 	int minus=0,i,temp;
    290  1.1     lukem 	int total_num_digits;
    291  1.1     lukem 
    292  1.1     lukem 	if ( value == 0 ){
    293  1.1     lukem 		buf[0] = '0';
    294  1.1     lukem 		return 1;
    295  1.1     lukem 	}
    296  1.1     lukem 
    297  1.1     lukem 	if ( value < 0 ){
    298  1.1     lukem 		minus = 1;
    299  1.1     lukem 		value = value*(-1);
    300  1.1     lukem 		buf[0] = '-';
    301  1.1     lukem 	}
    302  1.1     lukem 
    303  1.1     lukem 	/* How many digits */
    304  1.1     lukem 	for ( temp = value, total_num_digits=0 ; temp ; total_num_digits++ )
    305  1.1     lukem 		temp = temp/10;
    306  1.1     lukem 
    307  1.1     lukem 	total_num_digits += minus;
    308  1.1     lukem 
    309  1.1     lukem 	for ( i = minus ; value ; i++ ) {
    310  1.1     lukem 		buf[ total_num_digits - i - 1 ]= (char)(value%10 + '0');
    311  1.1     lukem 		value = value/10;
    312  1.1     lukem 	}
    313  1.1     lukem 	return i;
    314  1.1     lukem }
    315  1.1     lukem 
    316  1.1     lukem int
    317  1.1     lukem comp_convert_asn_to_ldap ( MatchingRule* mr, ComponentSyntaxInfo* csi, struct berval* bv, int *allocated )
    318  1.1     lukem {
    319  1.1     lukem 	int rc;
    320  1.1     lukem 	struct berval prettied;
    321  1.1     lukem 	Syntax* syn;
    322  1.1     lukem 
    323  1.1     lukem 	AsnTypetoSyntax* asn_to_syn =
    324  1.1     lukem 		&asn_to_syntax_mapping_tbl[csi->csi_comp_desc->cd_type_id];
    325  1.1     lukem 	if ( asn_to_syn->ats_syn_oid )
    326  1.1     lukem 		csi->csi_syntax = syn_find ( asn_to_syn->ats_syn_oid );
    327  1.1     lukem 	else
    328  1.1     lukem 		csi->csi_syntax = NULL;
    329  1.1     lukem 
    330  1.1     lukem 
    331  1.1     lukem         switch ( csi->csi_comp_desc->cd_type_id ) {
    332  1.1     lukem           case BASICTYPE_BOOLEAN :
    333  1.1     lukem 		bv->bv_val = (char*)malloc( 5 );
    334  1.1     lukem 		*allocated = 1;
    335  1.1     lukem 		bv->bv_len = 5;
    336  1.1     lukem 		if ( ((ComponentBool*)csi)->value > 0 ) {
    337  1.1     lukem 			strcpy ( bv->bv_val , "TRUE" );
    338  1.1     lukem 			bv->bv_len = 4;
    339  1.1     lukem 		}
    340  1.1     lukem 		else {
    341  1.1     lukem 			strcpy ( bv->bv_val , "FALSE" );
    342  1.1     lukem 			bv->bv_len = 5;
    343  1.1     lukem 		}
    344  1.1     lukem                 break ;
    345  1.1     lukem           case BASICTYPE_NULL :
    346  1.1     lukem                 bv->bv_len = 0;
    347  1.1     lukem                 break;
    348  1.1     lukem           case BASICTYPE_INTEGER :
    349  1.1     lukem 		bv->bv_val = (char*)malloc( INITIAL_ATTR_SIZE );
    350  1.1     lukem 		*allocated = 1;
    351  1.1     lukem 		bv->bv_len = INITIAL_ATTR_SIZE;
    352  1.1     lukem 		bv->bv_len = intToAscii(((ComponentInt*)csi)->value, bv->bv_val );
    353  1.1     lukem 		if ( bv->bv_len <= 0 )
    354  1.1     lukem 			return LDAP_INVALID_SYNTAX;
    355  1.1     lukem                 break;
    356  1.1     lukem           case BASICTYPE_REAL :
    357  1.1     lukem 		return LDAP_INVALID_SYNTAX;
    358  1.1     lukem           case BASICTYPE_ENUMERATED :
    359  1.1     lukem 		bv->bv_val = (char*)malloc( INITIAL_ATTR_SIZE );
    360  1.1     lukem 		*allocated = 1;
    361  1.1     lukem 		bv->bv_len = INITIAL_ATTR_SIZE;
    362  1.1     lukem 		bv->bv_len = intToAscii(((ComponentEnum*)csi)->value, bv->bv_val );
    363  1.1     lukem 		if ( bv->bv_len <= 0 )
    364  1.1     lukem 			return LDAP_INVALID_SYNTAX;
    365  1.1     lukem                 break;
    366  1.1     lukem           case BASICTYPE_OID :
    367  1.1     lukem           case BASICTYPE_OCTETSTRING :
    368  1.1     lukem           case BASICTYPE_BITSTRING :
    369  1.1     lukem           case BASICTYPE_NUMERIC_STR :
    370  1.1     lukem           case BASICTYPE_PRINTABLE_STR :
    371  1.1     lukem           case BASICTYPE_UNIVERSAL_STR :
    372  1.1     lukem           case BASICTYPE_IA5_STR :
    373  1.1     lukem           case BASICTYPE_BMP_STR :
    374  1.1     lukem           case BASICTYPE_UTF8_STR :
    375  1.1     lukem           case BASICTYPE_UTCTIME :
    376  1.1     lukem           case BASICTYPE_GENERALIZEDTIME :
    377  1.1     lukem           case BASICTYPE_GRAPHIC_STR :
    378  1.1     lukem           case BASICTYPE_VISIBLE_STR :
    379  1.1     lukem           case BASICTYPE_GENERAL_STR :
    380  1.1     lukem           case BASICTYPE_OBJECTDESCRIPTOR :
    381  1.1     lukem           case BASICTYPE_VIDEOTEX_STR :
    382  1.1     lukem           case BASICTYPE_T61_STR :
    383  1.1     lukem           case BASICTYPE_OCTETCONTAINING :
    384  1.1     lukem           case BASICTYPE_BITCONTAINING :
    385  1.1     lukem           case BASICTYPE_RELATIVE_OID :
    386  1.1     lukem 		bv->bv_val = ((ComponentOcts*)csi)->value.octs;
    387  1.1     lukem 		bv->bv_len = ((ComponentOcts*)csi)->value.octetLen;
    388  1.1     lukem                 break;
    389  1.1     lukem 	  case BASICTYPE_ANY :
    390  1.1     lukem 		csi = ((ComponentAny*)csi)->value;
    391  1.1     lukem 		if ( csi->csi_comp_desc->cd_type != ASN_BASIC ||
    392  1.1     lukem 			csi->csi_comp_desc->cd_type_id == BASICTYPE_ANY )
    393  1.1     lukem 			return LDAP_INVALID_SYNTAX;
    394  1.1     lukem 		return comp_convert_asn_to_ldap( mr, csi, bv, allocated );
    395  1.1     lukem           case COMPOSITE_ASN1_TYPE :
    396  1.1     lukem 		break;
    397  1.1     lukem           case RDNSequence :
    398  1.1     lukem 		/*dnMatch*/
    399  1.1     lukem 		if( strncmp( mr->smr_mrule.mr_oid, DN_MATCH_OID, strlen(DN_MATCH_OID) ) != 0 )
    400  1.1     lukem 			return LDAP_INVALID_SYNTAX;
    401  1.1     lukem 		*allocated = 1;
    402  1.1     lukem 		rc = ConvertRDNSequence2RFC2253( (irRDNSequence*)csi, bv );
    403  1.1     lukem 		if ( rc != LDAP_SUCCESS ) return rc;
    404  1.1     lukem 		break;
    405  1.1     lukem           case RelativeDistinguishedName :
    406  1.1     lukem 		/*rdnMatch*/
    407  1.1     lukem 		if( strncmp( mr->smr_mrule.mr_oid, RDN_MATCH_OID, strlen(RDN_MATCH_OID) ) != 0 )
    408  1.1     lukem 			return LDAP_INVALID_SYNTAX;
    409  1.1     lukem 		*allocated = 1;
    410  1.1     lukem 		rc = ConvertRDN2RFC2253((irRelativeDistinguishedName*)csi,bv);
    411  1.1     lukem 		if ( rc != LDAP_SUCCESS ) return rc;
    412  1.1     lukem 		break;
    413  1.1     lukem           case TelephoneNumber :
    414  1.1     lukem           case FacsimileTelephoneNumber__telephoneNumber :
    415  1.1     lukem 		break;
    416  1.1     lukem           case DirectoryString :
    417  1.1     lukem 		return LDAP_INVALID_SYNTAX;
    418  1.1     lukem           case ASN_COMP_CERTIFICATE :
    419  1.1     lukem           case ASNTYPE_END :
    420  1.1     lukem 		break;
    421  1.1     lukem           default :
    422  1.1     lukem                 /*Only ASN Basic Type can be converted into LDAP string*/
    423  1.1     lukem 		return LDAP_INVALID_SYNTAX;
    424  1.1     lukem         }
    425  1.1     lukem 
    426  1.1     lukem 	if ( csi->csi_syntax ) {
    427  1.1     lukem 		if ( csi->csi_syntax->ssyn_validate ) {
    428  1.1     lukem  			rc = csi->csi_syntax->ssyn_validate(csi->csi_syntax, bv);
    429  1.1     lukem 			if ( rc != LDAP_SUCCESS )
    430  1.1     lukem 				return LDAP_INVALID_SYNTAX;
    431  1.1     lukem 		}
    432  1.1     lukem 		if ( csi->csi_syntax->ssyn_pretty ) {
    433  1.1     lukem 			rc = csi->csi_syntax->ssyn_pretty(csi->csi_syntax, bv, &prettied , NULL );
    434  1.1     lukem 			if ( rc != LDAP_SUCCESS )
    435  1.1     lukem 				return LDAP_INVALID_SYNTAX;
    436  1.1     lukem #if 0
    437  1.1     lukem 			free ( bv->bv_val );/*potential memory leak?*/
    438  1.1     lukem #endif
    439  1.1     lukem 			bv->bv_val = prettied.bv_val;
    440  1.1     lukem 			bv->bv_len = prettied.bv_len;
    441  1.1     lukem 		}
    442  1.1     lukem 	}
    443  1.1     lukem 
    444  1.1     lukem 	return LDAP_SUCCESS;
    445  1.1     lukem }
    446  1.1     lukem 
    447  1.1     lukem /*
    448  1.1     lukem  * If <all> type component referenced is used
    449  1.1     lukem  * more than one component will be tested
    450  1.1     lukem  */
    451  1.1     lukem #define IS_TERMINAL_COMPREF(cr) (cr->cr_curr->ci_next == NULL)
    452  1.1     lukem int
    453  1.1     lukem comp_test_all_components (
    454  1.1     lukem 	void* attr_mem_op,
    455  1.1     lukem 	void* assert_mem_op,
    456  1.1     lukem 	ComponentSyntaxInfo *csi_attr,
    457  1.1     lukem 	ComponentAssertion* ca )
    458  1.1     lukem {
    459  1.1     lukem 	int rc;
    460  1.1     lukem 	ComponentSyntaxInfo *csi_temp = NULL, *csi_assert = NULL, *comp_elmt = NULL;
    461  1.1     lukem 	ComponentReference *cr = ca->ca_comp_ref;
    462  1.1     lukem 	struct berval *ca_val = &ca->ca_ma_value;
    463  1.1     lukem 
    464  1.1     lukem 	switch ( cr->cr_curr->ci_type ) {
    465  1.1     lukem 	    case LDAP_COMPREF_ALL:
    466  1.1     lukem 		if ( IS_TERMINAL_COMPREF(cr) ) {
    467  1.1     lukem 			FOR_EACH_LIST_ELMT( comp_elmt, &((ComponentList*)csi_attr)->comp_list )
    468  1.1     lukem 			{
    469  1.1     lukem 				rc = comp_test_one_component( attr_mem_op, assert_mem_op, comp_elmt, ca );
    470  1.1     lukem 				if ( rc == LDAP_COMPARE_TRUE ) {
    471  1.1     lukem 					break;
    472  1.1     lukem 				}
    473  1.1     lukem 			}
    474  1.1     lukem 		} else {
    475  1.1     lukem 			ComponentId *start_compid = ca->ca_comp_ref->cr_curr->ci_next;
    476  1.1     lukem 			FOR_EACH_LIST_ELMT( comp_elmt, &((ComponentList*)csi_attr)->comp_list )
    477  1.1     lukem 			{
    478  1.1     lukem 				cr->cr_curr = start_compid;
    479  1.1     lukem 				rc = comp_test_components ( attr_mem_op, assert_mem_op, comp_elmt, ca );
    480  1.1     lukem 				if ( rc != LDAP_COMPARE_FALSE ) {
    481  1.1     lukem 					break;
    482  1.1     lukem 				}
    483  1.1     lukem #if 0
    484  1.1     lukem 				if ( rc == LDAP_COMPARE_TRUE ) {
    485  1.1     lukem 					break;
    486  1.1     lukem 				}
    487  1.1     lukem #endif
    488  1.1     lukem 			}
    489  1.1     lukem 		}
    490  1.1     lukem 		break;
    491  1.1     lukem 	    case LDAP_COMPREF_CONTENT:
    492  1.1     lukem 	    case LDAP_COMPREF_SELECT:
    493  1.1     lukem 	    case LDAP_COMPREF_DEFINED:
    494  1.1     lukem 	    case LDAP_COMPREF_UNDEFINED:
    495  1.1     lukem 	    case LDAP_COMPREF_IDENTIFIER:
    496  1.1     lukem 	    case LDAP_COMPREF_FROM_BEGINNING:
    497  1.1     lukem 	    case LDAP_COMPREF_FROM_END:
    498  1.1     lukem 	    case LDAP_COMPREF_COUNT:
    499  1.1     lukem 		rc = LDAP_OPERATIONS_ERROR;
    500  1.1     lukem 		break;
    501  1.1     lukem 	    default:
    502  1.1     lukem 		rc = LDAP_OPERATIONS_ERROR;
    503  1.1     lukem 	}
    504  1.1     lukem 	return rc;
    505  1.1     lukem }
    506  1.1     lukem 
    507  1.1     lukem void
    508  1.1     lukem eat_bv_whsp ( struct berval* in )
    509  1.1     lukem {
    510  1.1     lukem 	char* end = in->bv_val + in->bv_len;
    511  1.1     lukem         for ( ; ( *in->bv_val == ' ' ) && ( in->bv_val < end ) ; ) {
    512  1.1     lukem                 in->bv_val++;
    513  1.1     lukem         }
    514  1.1     lukem }
    515  1.1     lukem 
    516  1.1     lukem /*
    517  1.1     lukem  * Perform matching one referenced component against assertion
    518  1.1     lukem  * If the matching rule in a component filter is allComponentsMatch
    519  1.1     lukem  * or its derivatives the extracted component's ASN.1 specification
    520  1.1     lukem  * is applied to the assertion value as its syntax
    521  1.1     lukem  * Otherwise, the matching rule's syntax is applied to the assertion value
    522  1.1     lukem  * By RFC 3687
    523  1.1     lukem  */
    524  1.1     lukem int
    525  1.1     lukem comp_test_one_component (
    526  1.1     lukem 	void* attr_mem_op,
    527  1.1     lukem 	void* assert_mem_op,
    528  1.1     lukem 	ComponentSyntaxInfo *csi_attr,
    529  1.1     lukem 	ComponentAssertion *ca )
    530  1.1     lukem {
    531  1.1     lukem 	int len, rc;
    532  1.1     lukem 	ComponentSyntaxInfo *csi_assert = NULL;
    533  1.1     lukem 	char* oid = NULL;
    534  1.1     lukem 	MatchingRule* mr = ca->ca_ma_rule;
    535  1.1     lukem 
    536  1.1     lukem 	if ( mr->smr_usage & SLAP_MR_COMPONENT ) {
    537  1.1     lukem 		/* If allComponentsMatch or its derivatives */
    538  1.1     lukem 		if ( !ca->ca_comp_data.cd_tree ) {
    539  1.1     lukem 			comp_convert_assert_to_comp( assert_mem_op, csi_attr, &ca->ca_ma_value, &csi_assert, &len, DEC_ALLOC_MODE_0 );
    540  1.1     lukem 			ca->ca_comp_data.cd_tree = (void*)csi_assert;
    541  1.1     lukem 		} else {
    542  1.1     lukem 			csi_assert = ca->ca_comp_data.cd_tree;
    543  1.1     lukem 		}
    544  1.1     lukem 
    545  1.1     lukem 		if ( !csi_assert )
    546  1.1     lukem 			return LDAP_PROTOCOL_ERROR;
    547  1.1     lukem 
    548  1.1     lukem 		if ( strcmp( mr->smr_mrule.mr_oid, OID_ALL_COMP_MATCH ) != 0 )
    549  1.1     lukem                 {
    550  1.1     lukem                         /* allComponentMatch's derivatives */
    551  1.1     lukem 			oid =  mr->smr_mrule.mr_oid;
    552  1.1     lukem                 }
    553  1.1     lukem                         return csi_attr->csi_comp_desc->cd_all_match(
    554  1.1     lukem                                			 oid, csi_attr, csi_assert );
    555  1.1     lukem 
    556  1.1     lukem 	} else {
    557  1.1     lukem 		/* LDAP existing matching rules */
    558  1.1     lukem 		struct berval attr_bv = BER_BVNULL;
    559  1.1     lukem 		struct berval n_attr_bv = BER_BVNULL;
    560  1.1     lukem 		struct berval* assert_bv = &ca->ca_ma_value;
    561  1.1     lukem 		int allocated = 0;
    562  1.1     lukem 		/*Attribute is converted to compatible LDAP encodings*/
    563  1.1     lukem 		if ( comp_convert_asn_to_ldap( mr, csi_attr, &attr_bv, &allocated ) != LDAP_SUCCESS )
    564  1.1     lukem 			return LDAP_INAPPROPRIATE_MATCHING;
    565  1.1     lukem 		/* extracted component value is not normalized */
    566  1.1     lukem 		if ( ca->ca_ma_rule->smr_normalize ) {
    567  1.1     lukem 			rc = ca->ca_ma_rule->smr_normalize (
    568  1.1     lukem 				SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
    569  1.1     lukem 				NULL, ca->ca_ma_rule,
    570  1.1     lukem 				&attr_bv, &n_attr_bv, NULL );
    571  1.1     lukem 			if ( rc != LDAP_SUCCESS )
    572  1.1     lukem 				return rc;
    573  1.1     lukem 			if ( allocated && attr_bv.bv_val )
    574  1.1     lukem 				free (attr_bv.bv_val);
    575  1.1     lukem 		} else {
    576  1.1     lukem 			n_attr_bv = attr_bv;
    577  1.1     lukem 		}
    578  1.1     lukem #if 0
    579  1.1     lukem 		/*Assertion value is validated by MR's syntax*/
    580  1.1     lukem 		if ( !ca->ca_comp_data.cd_tree ) {
    581  1.1     lukem 			ca->ca_comp_data.cd_tree = assert_bv;
    582  1.1     lukem 		}
    583  1.1     lukem 		else {
    584  1.1     lukem 			assert_bv = ca->ca_comp_data.cd_tree;
    585  1.1     lukem 		}
    586  1.1     lukem #endif
    587  1.1     lukem 		if ( !n_attr_bv.bv_val )
    588  1.1     lukem 			return LDAP_COMPARE_FALSE;
    589  1.1     lukem 		rc = csi_value_match( mr, &n_attr_bv, assert_bv );
    590  1.1     lukem 		if ( n_attr_bv.bv_val )
    591  1.1     lukem 			free ( n_attr_bv.bv_val );
    592  1.1     lukem 		return rc;
    593  1.1     lukem 	}
    594  1.1     lukem }
    595  1.1     lukem 
    596  1.1     lukem int
    597  1.1     lukem comp_test_components( void* attr_nm, void* assert_nm, ComponentSyntaxInfo* csi_attr, ComponentAssertion* ca) {
    598  1.1     lukem 	char* peek_head;
    599  1.1     lukem 	int mode, bytesDecoded = 0, rc;
    600  1.1     lukem 	GenBuf* b;
    601  1.1     lukem 	ExpBuf* buf;
    602  1.1     lukem 	OidDecoderMapping* odm;
    603  1.1     lukem 	struct berval bv;
    604  1.1     lukem 	char oid[MAX_OID_LEN];
    605  1.1     lukem 	void* contained_comp, *anytype_comp;
    606  1.1     lukem 	ComponentReference* cr = ca->ca_comp_ref;
    607  1.1     lukem 
    608  1.1     lukem 	if ( !cr )
    609  1.1     lukem 		return comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca );
    610  1.2  christos 	/* Extracting the component referenced by ca->ca_comp_ref */
    611  1.1     lukem 	csi_attr = (ComponentSyntaxInfo*)csi_attr->csi_comp_desc->cd_extract_i( attr_nm, cr, csi_attr );
    612  1.1     lukem 	if ( !csi_attr ) return LDAP_INVALID_SYNTAX;
    613  1.1     lukem 	/* perform matching, considering the type of a Component Reference(CR)*/
    614  1.1     lukem 	switch( cr->cr_curr->ci_type ) {
    615  1.1     lukem 	   case LDAP_COMPREF_IDENTIFIER:
    616  1.1     lukem 	   case LDAP_COMPREF_FROM_BEGINNING:
    617  1.1     lukem 	   case LDAP_COMPREF_FROM_END:
    618  1.1     lukem 	   case LDAP_COMPREF_COUNT:
    619  1.1     lukem 		/*
    620  1.1     lukem 		 * Exactly one component is referenced
    621  1.1     lukem 		 * Fast Path for matching for this case
    622  1.1     lukem 		 */
    623  1.1     lukem 		rc = comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca );
    624  1.1     lukem 		break;
    625  1.1     lukem 	   case LDAP_COMPREF_ALL:
    626  1.1     lukem 		/*
    627  1.1     lukem 		 * If <all> type CR is used
    628  1.1     lukem 		 * more than one component will be tested
    629  1.1     lukem 		 */
    630  1.1     lukem 		rc = comp_test_all_components ( attr_nm, assert_nm, csi_attr, ca );
    631  1.1     lukem 		break;
    632  1.1     lukem 
    633  1.1     lukem 	   case LDAP_COMPREF_CONTENT:
    634  1.1     lukem 		/*
    635  1.1     lukem 		 * <content> type CR is used
    636  1.1     lukem 		 * check if it is followed by <select> type CR.
    637  1.1     lukem 		 * 1) If so, look up the corresponding decoder  in the mapping
    638  1.1     lukem 		 * table(OID to decoder) by <select>
    639  1.1     lukem 		 * and then decode the OCTET/BIT STRING with the decoder
    640  1.2  christos 		 * Finally, extract the target component with the remaining CR.
    641  1.1     lukem 		 * 2) If not, just return the current component, It SHOULD not be
    642  1.1     lukem 		 * extracted further, because the component MUST be BIT/OCTET
    643  1.1     lukem                  * string.
    644  1.1     lukem                  */
    645  1.1     lukem 
    646  1.1     lukem 		cr->cr_curr = cr->cr_curr->ci_next;
    647  1.1     lukem 		if ( !cr->cr_curr ) {
    648  1.1     lukem 			/* case 2) in above description */
    649  1.1     lukem 			rc = comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca );
    650  1.1     lukem 			break;
    651  1.1     lukem 		}
    652  1.1     lukem 
    653  1.1     lukem 		if ( cr->cr_curr->ci_type == LDAP_COMPREF_SELECT ) {
    654  1.1     lukem 			/* Look up OID mapping table */
    655  1.1     lukem 			odm = RetrieveOidDecoderMappingbyBV( &cr->cr_curr->ci_val.ci_select_value );
    656  1.1     lukem 
    657  1.1     lukem 			if ( !odm || !odm->BER_Decode )
    658  1.1     lukem 				return  LDAP_PROTOCOL_ERROR;
    659  1.1     lukem 
    660  1.2  christos 			/* current component MUST be either BIT or OCTET STRING */
    661  1.1     lukem 			if ( csi_attr->csi_comp_desc->cd_type_id != BASICTYPE_BITSTRING ) {
    662  1.1     lukem 				bv.bv_val = ((ComponentBits*)csi_attr)->value.bits;
    663  1.1     lukem 				bv.bv_len = ((ComponentBits*)csi_attr)->value.bitLen;
    664  1.1     lukem 			}
    665  1.1     lukem 			else if ( csi_attr->csi_comp_desc->cd_type_id != BASICTYPE_BITSTRING ) {
    666  1.1     lukem 				bv.bv_val = ((ComponentOcts*)csi_attr)->value.octs;
    667  1.1     lukem 				bv.bv_len = ((ComponentOcts*)csi_attr)->value.octetLen;
    668  1.1     lukem 			}
    669  1.1     lukem 			else
    670  1.1     lukem 				return LDAP_PROTOCOL_ERROR;
    671  1.1     lukem 
    672  1.1     lukem 			buf = ExpBufAllocBuf();
    673  1.1     lukem 			ExpBuftoGenBuf( buf, &b );
    674  1.1     lukem 			ExpBufInstallDataInBuf ( buf, bv.bv_val, bv.bv_len );
    675  1.1     lukem 			BufResetInReadMode( b );
    676  1.1     lukem 			mode = DEC_ALLOC_MODE_2;
    677  1.1     lukem 
    678  1.1     lukem 			/* Try to decode with BER/DER decoder */
    679  1.1     lukem 			rc = odm->BER_Decode ( attr_nm, b, (ComponentSyntaxInfo*)&contained_comp, &bytesDecoded, mode );
    680  1.1     lukem 
    681  1.1     lukem 			ExpBufFreeBuf( buf );
    682  1.1     lukem 			GenBufFreeBuf( b );
    683  1.1     lukem 
    684  1.1     lukem 			if ( rc != LDAP_SUCCESS ) return LDAP_PROTOCOL_ERROR;
    685  1.1     lukem 
    686  1.1     lukem 			/* xxx.content.(x.xy.xyz).rfc822Name */
    687  1.1     lukem 			/* In the aboe Ex. move CR to the right to (x.xy.xyz)*/
    688  1.1     lukem 			cr->cr_curr = cr->cr_curr->ci_next;
    689  1.1     lukem 			if (!cr->cr_curr )
    690  1.1     lukem 				rc = comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca );
    691  1.1     lukem 			else
    692  1.1     lukem 				rc = comp_test_components( attr_nm, assert_nm, contained_comp, ca );
    693  1.1     lukem 		}
    694  1.1     lukem 		else {
    695  1.2  christos 			/* Invalid Component reference */
    696  1.1     lukem 			rc = LDAP_PROTOCOL_ERROR;
    697  1.1     lukem 		}
    698  1.1     lukem 		break;
    699  1.1     lukem 	   case LDAP_COMPREF_SELECT:
    700  1.1     lukem 		if (csi_attr->csi_comp_desc->cd_type_id != BASICTYPE_ANY )
    701  1.1     lukem 			return LDAP_INVALID_SYNTAX;
    702  1.1     lukem 		rc = CheckSelectTypeCorrect( attr_nm, ((ComponentAny*)csi_attr)->cai, &cr->cr_curr->ci_val.ci_select_value );
    703  1.1     lukem 		if ( rc < 0 ) return LDAP_INVALID_SYNTAX;
    704  1.1     lukem 
    705  1.1     lukem 		/* point to the real component, not any type component */
    706  1.1     lukem 		csi_attr = ((ComponentAny*)csi_attr)->value;
    707  1.1     lukem 		cr->cr_curr = cr->cr_curr->ci_next;
    708  1.1     lukem 		if ( cr->cr_curr )
    709  1.1     lukem 			rc =  comp_test_components( attr_nm, assert_nm, csi_attr, ca);
    710  1.1     lukem 		else
    711  1.1     lukem 			rc =  comp_test_one_component( attr_nm, assert_nm, csi_attr, ca);
    712  1.1     lukem 		break;
    713  1.1     lukem 	   default:
    714  1.1     lukem 		rc = LDAP_INVALID_SYNTAX;
    715  1.1     lukem 	}
    716  1.1     lukem 	return rc;
    717  1.1     lukem }
    718  1.1     lukem 
    719  1.1     lukem 
    720  1.1     lukem void*
    721  1.1     lukem comp_nibble_memory_allocator ( int init_mem, int inc_mem ) {
    722  1.1     lukem 	void* nm;
    723  1.1     lukem 	nm = (void*)InitNibbleMemLocal( (unsigned long)init_mem, (unsigned long)inc_mem );
    724  1.1     lukem 	if ( !nm ) return NULL;
    725  1.1     lukem 	else return (void*)nm;
    726  1.1     lukem }
    727  1.1     lukem 
    728  1.1     lukem void
    729  1.1     lukem comp_nibble_memory_free ( void* nm ) {
    730  1.1     lukem 	ShutdownNibbleMemLocal( nm );
    731  1.1     lukem }
    732  1.1     lukem 
    733  1.1     lukem void*
    734  1.1     lukem comp_get_component_description ( int id ) {
    735  1.1     lukem 	if ( asntype_to_compdesc_mapping_tbl[id].atcd_typeId == id )
    736  1.1     lukem 		return &asntype_to_compdesc_mapping_tbl[id].atcd_cd;
    737  1.1     lukem 	else
    738  1.1     lukem 		return NULL;
    739  1.1     lukem }
    740  1.1     lukem 
    741  1.1     lukem int
    742  1.1     lukem comp_component_encoder ( void* mem_op, ComponentSyntaxInfo* csi , struct berval* nval ) {
    743  1.1     lukem         int size, rc;
    744  1.1     lukem         GenBuf* b;
    745  1.1     lukem         ExpBuf* buf;
    746  1.1     lukem 	struct berval bv;
    747  1.1     lukem 
    748  1.1     lukem 	buf = ExpBufAllocBufAndData();
    749  1.1     lukem 	ExpBufResetInWriteRvsMode(buf);
    750  1.1     lukem 	ExpBuftoGenBuf( buf, &b );
    751  1.1     lukem 
    752  1.1     lukem 	if ( !csi->csi_comp_desc->cd_gser_encoder && !csi->csi_comp_desc->cd_ldap_encoder )
    753  1.1     lukem 		return (-1);
    754  1.1     lukem 
    755  1.1     lukem 	/*
    756  1.1     lukem 	 * if an LDAP specific encoder is provided :
    757  1.1     lukem 	 * dn and rdn have their LDAP specific encoder
    758  1.1     lukem 	 */
    759  1.1     lukem 	if ( csi->csi_comp_desc->cd_ldap_encoder ) {
    760  1.1     lukem 		rc = csi->csi_comp_desc->cd_ldap_encoder( csi, &bv );
    761  1.1     lukem 		if ( rc != LDAP_SUCCESS )
    762  1.1     lukem 			return rc;
    763  1.1     lukem 		if ( mem_op )
    764  1.1     lukem 			nval->bv_val = CompAlloc( mem_op, bv.bv_len );
    765  1.1     lukem 		else
    766  1.1     lukem 			nval->bv_val = malloc( size );
    767  1.1     lukem 		memcpy( nval->bv_val, bv.bv_val, bv.bv_len );
    768  1.1     lukem 		nval->bv_len = bv.bv_len;
    769  1.1     lukem 		/*
    770  1.1     lukem 		 * This free will be eliminated by making ldap_encoder
    771  1.1     lukem 		 * use nibble memory in it
    772  1.1     lukem 		 */
    773  1.1     lukem 		free ( bv.bv_val );
    774  1.1     lukem 		GenBufFreeBuf( b );
    775  1.1     lukem 		BufFreeBuf( buf );
    776  1.1     lukem 		return LDAP_SUCCESS;
    777  1.1     lukem 	}
    778  1.1     lukem 
    779  1.1     lukem 	rc = csi->csi_comp_desc->cd_gser_encoder( b, csi );
    780  1.1     lukem 	if ( rc < 0 ) {
    781  1.1     lukem 		GenBufFreeBuf( b );
    782  1.1     lukem 		BufFreeBuf( buf );
    783  1.1     lukem 		return rc;
    784  1.1     lukem 	}
    785  1.1     lukem 
    786  1.1     lukem 	size = ExpBufDataSize( buf );
    787  1.1     lukem 	if ( size > 0 ) {
    788  1.1     lukem 		if ( mem_op )
    789  1.1     lukem 			nval->bv_val = CompAlloc ( mem_op, size );
    790  1.1     lukem 		else
    791  1.1     lukem 			nval->bv_val = malloc( size );
    792  1.1     lukem 		nval->bv_len = size;
    793  1.1     lukem 		BufResetInReadMode(b);
    794  1.1     lukem 		BufCopy( nval->bv_val, b, size );
    795  1.1     lukem 	}
    796  1.1     lukem 	ExpBufFreeBuf( buf );
    797  1.1     lukem 	GenBufFreeBuf( b );
    798  1.1     lukem 
    799  1.1     lukem 	return LDAP_SUCCESS;
    800  1.1     lukem }
    801  1.1     lukem 
    802  1.1     lukem #if SLAPD_COMP_MATCH == SLAPD_MOD_DYNAMIC
    803  1.1     lukem 
    804  1.1     lukem #include "certificate.h"
    805  1.1     lukem 
    806  1.1     lukem extern convert_attr_to_comp_func* attr_converter;
    807  1.1     lukem extern convert_assert_to_comp_func* assert_converter;
    808  1.1     lukem extern convert_asn_to_ldap_func* csi_converter;
    809  1.1     lukem extern free_component_func* component_destructor;
    810  1.1     lukem extern test_component_func* test_components;
    811  1.1     lukem extern alloc_nibble_func* nibble_mem_allocator;
    812  1.1     lukem extern free_nibble_func* nibble_mem_free;
    813  1.1     lukem extern test_membership_func* is_aliased_attribute;
    814  1.1     lukem extern get_component_info_func* get_component_description;
    815  1.1     lukem extern component_encoder_func* component_encoder;
    816  1.1     lukem 
    817  1.1     lukem 
    818  1.1     lukem int init_module(int argc, char *argv[]) {
    819  1.1     lukem 	/*
    820  1.1     lukem 	 * Initialize function pointers in slapd
    821  1.1     lukem 	 */
    822  1.1     lukem 	attr_converter = (convert_attr_to_comp_func*)comp_convert_attr_to_comp;
    823  1.1     lukem 	assert_converter = (convert_assert_to_comp_func*)comp_convert_assert_to_comp;
    824  1.1     lukem 	component_destructor = (free_component_func*)comp_free_component;
    825  1.1     lukem 	test_components = (test_component_func*)comp_test_components;
    826  1.1     lukem 	nibble_mem_allocator = (free_nibble_func*)comp_nibble_memory_allocator;
    827  1.1     lukem 	nibble_mem_free = (free_nibble_func*)comp_nibble_memory_free;
    828  1.1     lukem 	is_aliased_attribute = (test_membership_func*)comp_is_aliased_attribute;
    829  1.1     lukem 	get_component_description = (get_component_info_func*)comp_get_component_description;
    830  1.1     lukem 	component_encoder = (component_encoder_func*)comp_component_encoder;
    831  1.1     lukem 
    832  1.1     lukem 	/* file path needs to be */
    833  1.1     lukem 	load_derived_matching_rule ("derived_mr.cfg");
    834  1.1     lukem 
    835  1.1     lukem 	/* the initialization for example X.509 certificate */
    836  1.1     lukem 	init_module_AuthenticationFramework();
    837  1.1     lukem 	init_module_AuthorityKeyIdentifierDefinition();
    838  1.1     lukem 	init_module_CertificateRevokationList();
    839  1.1     lukem 	init_attribute_aliasing_table ();
    840  1.1     lukem 	init_component_description_table ();
    841  1.1     lukem 	return 0;
    842  1.1     lukem }
    843  1.1     lukem 
    844  1.1     lukem #endif /* SLAPD_PASSWD */
    845