📄 init.c
字号:
if ( csi->csi_syntax ) { if ( csi->csi_syntax->ssyn_validate ) { rc = csi->csi_syntax->ssyn_validate(csi->csi_syntax, bv); if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX; } if ( csi->csi_syntax->ssyn_pretty ) { rc = csi->csi_syntax->ssyn_pretty(csi->csi_syntax, bv, &prettied , NULL ); if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;#if 0 free ( bv->bv_val );/*potential memory leak?*/#endif bv->bv_val = prettied.bv_val; bv->bv_len = prettied.bv_len; } } return LDAP_SUCCESS;}/* * If <all> type component referenced is used * more than one component will be tested */#define IS_TERMINAL_COMPREF(cr) (cr->cr_curr->ci_next == NULL)intcomp_test_all_components ( void* attr_mem_op, void* assert_mem_op, ComponentSyntaxInfo *csi_attr, ComponentAssertion* ca ){ int rc; ComponentSyntaxInfo *csi_temp = NULL, *csi_assert = NULL, *comp_elmt = NULL; ComponentReference *cr = ca->ca_comp_ref; struct berval *ca_val = &ca->ca_ma_value; switch ( cr->cr_curr->ci_type ) { case LDAP_COMPREF_ALL: if ( IS_TERMINAL_COMPREF(cr) ) { FOR_EACH_LIST_ELMT( comp_elmt, &((ComponentList*)csi_attr)->comp_list ) { rc = comp_test_one_component( attr_mem_op, assert_mem_op, comp_elmt, ca ); if ( rc == LDAP_COMPARE_TRUE ) { break; } } } else { ComponentId *start_compid = ca->ca_comp_ref->cr_curr->ci_next; FOR_EACH_LIST_ELMT( comp_elmt, &((ComponentList*)csi_attr)->comp_list ) { cr->cr_curr = start_compid; rc = comp_test_components ( attr_mem_op, assert_mem_op, comp_elmt, ca ); if ( rc != LDAP_COMPARE_FALSE ) { break; }#if 0 if ( rc == LDAP_COMPARE_TRUE ) { break; }#endif } } break; case LDAP_COMPREF_CONTENT: case LDAP_COMPREF_SELECT: case LDAP_COMPREF_DEFINED: case LDAP_COMPREF_UNDEFINED: case LDAP_COMPREF_IDENTIFIER: case LDAP_COMPREF_FROM_BEGINNING: case LDAP_COMPREF_FROM_END: case LDAP_COMPREF_COUNT: rc = LDAP_OPERATIONS_ERROR; break; default: rc = LDAP_OPERATIONS_ERROR; } return rc;}voideat_bv_whsp ( struct berval* in ){ char* end = in->bv_val + in->bv_len; for ( ; ( *in->bv_val == ' ' ) && ( in->bv_val < end ) ; ) { in->bv_val++; }}/* * Perform matching one referenced component against assertion * If the matching rule in a component filter is allComponentsMatch * or its derivatives the extracted component's ASN.1 specification * is applied to the assertion value as its syntax * Otherwise, the matching rule's syntax is applied to the assertion value * By RFC 3687 */intcomp_test_one_component ( void* attr_mem_op, void* assert_mem_op, ComponentSyntaxInfo *csi_attr, ComponentAssertion *ca ){ int len, rc; ComponentSyntaxInfo *csi_assert = NULL; char* oid = NULL; MatchingRule* mr = ca->ca_ma_rule; if ( mr->smr_usage & SLAP_MR_COMPONENT ) { /* If allComponentsMatch or its derivatives */ if ( !ca->ca_comp_data.cd_tree ) { comp_convert_assert_to_comp( assert_mem_op, csi_attr, &ca->ca_ma_value, &csi_assert, &len, DEC_ALLOC_MODE_0 ); ca->ca_comp_data.cd_tree = (void*)csi_assert; } else { csi_assert = ca->ca_comp_data.cd_tree; } if ( !csi_assert ) return LDAP_PROTOCOL_ERROR; if ( strcmp( mr->smr_mrule.mr_oid, OID_ALL_COMP_MATCH ) != 0 ) { /* allComponentMatch's derivatives */ oid = mr->smr_mrule.mr_oid; } return csi_attr->csi_comp_desc->cd_all_match( oid, csi_attr, csi_assert ); } else { /* LDAP existing matching rules */ struct berval attr_bv = BER_BVNULL; struct berval n_attr_bv = BER_BVNULL; struct berval* assert_bv = &ca->ca_ma_value; int allocated = 0; /*Attribute is converted to compatible LDAP encodings*/ if ( comp_convert_asn_to_ldap( mr, csi_attr, &attr_bv, &allocated ) != LDAP_SUCCESS ) return LDAP_INAPPROPRIATE_MATCHING; /* extracted component value is not normalized */ if ( ca->ca_ma_rule->smr_normalize ) { rc = ca->ca_ma_rule->smr_normalize ( SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, NULL, ca->ca_ma_rule, &attr_bv, &n_attr_bv, NULL ); if ( rc != LDAP_SUCCESS ) return rc; if ( allocated && attr_bv.bv_val ) free (attr_bv.bv_val); } else { n_attr_bv = attr_bv; }#if 0 /*Assertion value is validated by MR's syntax*/ if ( !ca->ca_comp_data.cd_tree ) { ca->ca_comp_data.cd_tree = assert_bv; } else { assert_bv = ca->ca_comp_data.cd_tree; }#endif if ( !n_attr_bv.bv_val ) return LDAP_COMPARE_FALSE; rc = csi_value_match( mr, &n_attr_bv, assert_bv ); if ( n_attr_bv.bv_val ) free ( n_attr_bv.bv_val ); return rc; }}intcomp_test_components( void* attr_nm, void* assert_nm, ComponentSyntaxInfo* csi_attr, ComponentAssertion* ca) { char* peek_head; int mode, bytesDecoded = 0, rc; GenBuf* b; ExpBuf* buf; OidDecoderMapping* odm; struct berval bv; char oid[MAX_OID_LEN]; void* contained_comp, *anytype_comp; ComponentReference* cr = ca->ca_comp_ref; if ( !cr ) return comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca ); /* Extracting the component refrenced by ca->ca_comp_ref */ csi_attr = (ComponentSyntaxInfo*)csi_attr->csi_comp_desc->cd_extract_i( attr_nm, cr, csi_attr ); if ( !csi_attr ) return LDAP_INVALID_SYNTAX; /* perform matching, considering the type of a Component Reference(CR)*/ switch( cr->cr_curr->ci_type ) { case LDAP_COMPREF_IDENTIFIER: case LDAP_COMPREF_FROM_BEGINNING: case LDAP_COMPREF_FROM_END: case LDAP_COMPREF_COUNT: /* * Exactly one component is referenced * Fast Path for matching for this case */ rc = comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca ); break; case LDAP_COMPREF_ALL: /* * If <all> type CR is used * more than one component will be tested */ rc = comp_test_all_components ( attr_nm, assert_nm, csi_attr, ca ); break; case LDAP_COMPREF_CONTENT: /* * <content> type CR is used * check if it is followed by <select> type CR. * 1) If so, look up the corresponding decoder in the mapping * table(OID to decoder) by <select> * and then decode the OCTET/BIT STRING with the decoder * Finially, extreact the target component with the remaining CR. * 2) If not, just return the current component, It SHOULD not be * extracted further, because the component MUST be BIT/OCTET * string. */ cr->cr_curr = cr->cr_curr->ci_next; if ( !cr->cr_curr ) { /* case 2) in above description */ rc = comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca ); break; } if ( cr->cr_curr->ci_type == LDAP_COMPREF_SELECT ) { /* Look up OID mapping table */ odm = RetrieveOidDecoderMappingbyBV( &cr->cr_curr->ci_val.ci_select_value ); if ( !odm || !odm->BER_Decode ) return LDAP_PROTOCOL_ERROR; /* current componet MUST be either BIT or OCTET STRING */ if ( csi_attr->csi_comp_desc->cd_type_id != BASICTYPE_BITSTRING ) { bv.bv_val = ((ComponentBits*)csi_attr)->value.bits; bv.bv_len = ((ComponentBits*)csi_attr)->value.bitLen; } else if ( csi_attr->csi_comp_desc->cd_type_id != BASICTYPE_BITSTRING ) { bv.bv_val = ((ComponentOcts*)csi_attr)->value.octs; bv.bv_len = ((ComponentOcts*)csi_attr)->value.octetLen; } else return LDAP_PROTOCOL_ERROR; buf = ExpBufAllocBuf(); ExpBuftoGenBuf( buf, &b ); ExpBufInstallDataInBuf ( buf, bv.bv_val, bv.bv_len ); BufResetInReadMode( b ); mode = DEC_ALLOC_MODE_2; /* Try to decode with BER/DER decoder */ rc = odm->BER_Decode ( attr_nm, b, (ComponentSyntaxInfo*)&contained_comp, &bytesDecoded, mode ); ExpBufFreeBuf( buf ); GenBufFreeBuf( b ); if ( rc != LDAP_SUCCESS ) return LDAP_PROTOCOL_ERROR; /* xxx.content.(x.xy.xyz).rfc822Name */ /* In the aboe Ex. move CR to the right to (x.xy.xyz)*/ cr->cr_curr = cr->cr_curr->ci_next; if (!cr->cr_curr ) rc = comp_test_one_component ( attr_nm, assert_nm, csi_attr, ca ); else rc = comp_test_components( attr_nm, assert_nm, contained_comp, ca ); } else { /* Ivalid Component reference */ rc = LDAP_PROTOCOL_ERROR; } break; case LDAP_COMPREF_SELECT: if (csi_attr->csi_comp_desc->cd_type_id != BASICTYPE_ANY ) return LDAP_INVALID_SYNTAX; rc = CheckSelectTypeCorrect( attr_nm, ((ComponentAny*)csi_attr)->cai, &cr->cr_curr->ci_val.ci_select_value ); if ( rc < 0 ) return LDAP_INVALID_SYNTAX; /* point to the real component, not any type component */ csi_attr = ((ComponentAny*)csi_attr)->value; cr->cr_curr = cr->cr_curr->ci_next; if ( cr->cr_curr ) rc = comp_test_components( attr_nm, assert_nm, csi_attr, ca); else rc = comp_test_one_component( attr_nm, assert_nm, csi_attr, ca); break; default: rc = LDAP_INVALID_SYNTAX; } return rc;}void*comp_nibble_memory_allocator ( int init_mem, int inc_mem ) { void* nm; nm = (void*)InitNibbleMemLocal( (unsigned long)init_mem, (unsigned long)inc_mem ); if ( !nm ) return NULL; else return (void*)nm;}voidcomp_nibble_memory_free ( void* nm ) { ShutdownNibbleMemLocal( nm );}void*comp_get_component_description ( int id ) { if ( asntype_to_compdesc_mapping_tbl[id].atcd_typeId == id ) return &asntype_to_compdesc_mapping_tbl[id].atcd_cd; else return NULL;}intcomp_component_encoder ( void* mem_op, ComponentSyntaxInfo* csi , struct berval* nval ) { int size, rc; GenBuf* b; ExpBuf* buf; struct berval bv; buf = ExpBufAllocBufAndData(); ExpBufResetInWriteRvsMode(buf); ExpBuftoGenBuf( buf, &b ); if ( !csi->csi_comp_desc->cd_gser_encoder && !csi->csi_comp_desc->cd_ldap_encoder ) return (-1); /* * if an LDAP specific encoder is provided : * dn and rdn have their LDAP specific encoder */ if ( csi->csi_comp_desc->cd_ldap_encoder ) { rc = csi->csi_comp_desc->cd_ldap_encoder( csi, &bv ); if ( rc != LDAP_SUCCESS ) return rc; if ( mem_op ) nval->bv_val = CompAlloc( mem_op, bv.bv_len ); else nval->bv_val = malloc( size ); memcpy( nval->bv_val, bv.bv_val, bv.bv_len ); nval->bv_len = bv.bv_len; /* * This free will be eliminated by making ldap_encoder * use nibble memory in it */ free ( bv.bv_val ); GenBufFreeBuf( b ); BufFreeBuf( buf ); return LDAP_SUCCESS; } rc = csi->csi_comp_desc->cd_gser_encoder( b, csi ); if ( rc < 0 ) { GenBufFreeBuf( b ); BufFreeBuf( buf ); return rc; } size = ExpBufDataSize( buf ); if ( size > 0 ) { if ( mem_op ) nval->bv_val = CompAlloc ( mem_op, size ); else nval->bv_val = malloc( size ); nval->bv_len = size; BufResetInReadMode(b); BufCopy( nval->bv_val, b, size ); } ExpBufFreeBuf( buf ); GenBufFreeBuf( b ); 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;extern test_component_func* test_components;extern alloc_nibble_func* nibble_mem_allocator;extern free_nibble_func* nibble_mem_free;extern test_membership_func* is_aliased_attribute;extern get_component_info_func* get_component_description;extern component_encoder_func* component_encoder;int init_module(int argc, char *argv[]) { /* * Initialize function pointers in slapd */ attr_converter = (convert_attr_to_comp_func*)comp_convert_attr_to_comp; assert_converter = (convert_assert_to_comp_func*)comp_convert_assert_to_comp; component_destructor = (free_component_func*)comp_free_component; test_components = (test_component_func*)comp_test_components; nibble_mem_allocator = (free_nibble_func*)comp_nibble_memory_allocator; nibble_mem_free = (free_nibble_func*)comp_nibble_memory_free; is_aliased_attribute = (test_membership_func*)comp_is_aliased_attribute; get_component_description = (get_component_info_func*)comp_get_component_description; component_encoder = (component_encoder_func*)comp_component_encoder; /* file path needs to be */ load_derived_matching_rule ("derived_mr.cfg"); /* the initialization for example X.509 certificate */ init_module_AuthenticationFramework(); init_module_AuthorityKeyIdentifierDefinition(); init_module_CertificateRevokationList(); init_attribute_aliasing_table (); init_component_description_table (); return 0;}#endif /* SLAPD_PASSWD */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -