⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 componentlib.c

📁 ldap服务器源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		ad_type = at_bvfind( select );		if ( !ad_type )			return LDAP_DECODING_ERROR;		oid = ad_type->sat_atype.at_oid;		strLen = strlen ( oid );	}	result = EncodeComponentOid ( mem_op, oid , &strLen );	if ( !result || strLen <= 0 ) return (-1);	if ( cai->oid.octetLen == strLen &&		strncmp ( cai->oid.octs, result, strLen ) == 0 )		return (1);	else		return (-1);}intSetAnyTypeByComponentOid ( 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	 */	}	return LDAP_SUCCESS;}voidSetAnyTypeByComponentInt( 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;}intGEncComponentAny ( GenBuf *b, ComponentAny *in ){	if ( in->cai != NULL  && in->cai->Encode != NULL )		return in->cai->Encode(b, &in->value );	else		return (-1);}intBEncComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode){        ComponentAny *k, **k2;                                                                                  k = (ComponentAny*) result;	if ( !k ) return (-1);                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentAny**) result;                *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );		if ( !*k2 ) return LDAP_DECODING_ERROR;                k = *k2;        }		if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {		result->value = (void*) CompAlloc ( mem_op, result->cai->size );		if ( !result->value ) return 0;		result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );		if ( !k->comp_desc )  {			if ( k ) CompFree ( mem_op, k );			return LDAP_DECODING_ERROR;		}		k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;		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_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;	}}intBDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {	int rc;        ComponentAny *k, **k2;                                                                                  k = (ComponentAny*) result;	if ( !k ) return (-1);                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentAny**) result;                *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );		if ( !*k2 ) return LDAP_DECODING_ERROR;                k = *k2;        }		if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {		result->cai->BER_Decode ( mem_op, b, (ComponentSyntaxInfo*)&result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_0 );		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );		if ( !k->comp_desc )  {			if ( k ) CompFree ( mem_op, k );			return LDAP_DECODING_ERROR;		}		k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;		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_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;	}}intGDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {        ComponentAny *k, **k2;                                                                                  k = (ComponentAny*) result;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentAny**) result;                *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );		if ( !*k2 ) return LDAP_DECODING_ERROR;                k = *k2;        }	if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) {		result->value = (void*) CompAlloc ( mem_op, result->cai->size );		if ( !result->value ) return 0;		result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );		if ( !k->comp_desc )  {			if ( k ) CompFree ( mem_op, k );			return LDAP_DECODING_ERROR;		}		k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;		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;	}}intMatchingComponentAny (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 ( void* mem_op, ComponentReference* cr,  ComponentAny *result ) {	if ((result->cai != NULL) && (result->cai->Extract != NULL)) {		return (void*) result->cai->Extract( mem_op, cr , result->value );	}	else {		Asn1Error ("ERROR - ANY Extracting routine is NULL\n");		return (void*)NULL;	}}voidFreeComponentAny (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");}voidInstallAnyByComponentInt (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);}/* * OID and its corresponding decoder can be registerd with this func. * If contained types constrained by <select> are used, * their OID and decoder MUST be registered, otherwise it will return no entry. * An open type(ANY type) also need be registered. */voidInstallOidDecoderMapping ( char* ch_oid, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match ) {	AsnOid oid;	int strLen;	void* mem_op;	strLen = strlen( ch_oid );	if( strLen <= 0 ) return;	mem_op = comp_nibble_memory_allocator ( 128, 16 );	oid.octs = EncodeComponentOid ( mem_op, ch_oid, &strLen );	oid.octetLen = strLen;	if( strLen <= 0 ) return;		InstallAnyByComponentOid ( 0, &oid, 0, encode, G_decode, B_decode,						extract, match, NULL, NULL);	comp_nibble_memory_free(mem_op);}/* * Look up Oid-decoder mapping table by berval have either * oid or description */OidDecoderMapping*RetrieveOidDecoderMappingbyBV( struct berval* in ) {	if ( IsNumericOid ( in->bv_val, in->bv_len ) )		return RetrieveOidDecoderMappingbyOid( in->bv_val, in->bv_len );	else		return RetrieveOidDecoderMappingbyDesc( in->bv_val, in->bv_len );}/* * Look up Oid-decoder mapping table by dotted OID */OidDecoderMapping*RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len ) {	Hash hash;	void *anyInfo;	AsnOid oid;	int strLen;	void* mem_op;	mem_op = comp_nibble_memory_allocator ( 128, 16 );	oid.octs = EncodeComponentOid ( mem_op, ch_oid, &oid_len);	oid.octetLen = oid_len;	if( oid_len <= 0 ) {		comp_nibble_memory_free( mem_op );		return NULL;	}		/* use encoded oid as hash string */	hash = MakeHash ( oid.octs, oid.octetLen);	comp_nibble_memory_free( mem_op );	if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))		return (OidDecoderMapping*) anyInfo;	else		return (OidDecoderMapping*) NULL;}/* * Look up Oid-decoder mapping table by description */OidDecoderMapping*RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len ) {	Hash hash;	void *anyInfo;	AsnOid oid;	AttributeType* ad_type;	struct berval bv;	void* mem_op;	bv.bv_val = desc;	bv.bv_len = desc_len;	ad_type = at_bvfind( &bv );	oid.octs = ad_type->sat_atype.at_oid;	oid.octetLen = strlen ( oid.octs );	if ( !ad_type )		return (OidDecoderMapping*) NULL;	mem_op = comp_nibble_memory_allocator ( 128, 16 );	oid.octs = EncodeComponentOid ( mem_op, oid.octs , (int*)&oid.octetLen );	if( oid.octetLen <= 0 ) {		comp_nibble_memory_free( mem_op );		return (OidDecoderMapping*) NULL;	}		/* use encoded oid as hash string */	hash = MakeHash ( oid.octs, oid.octetLen);	comp_nibble_memory_free( mem_op );	if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))		return (OidDecoderMapping*) anyInfo;	else		return (OidDecoderMapping*) NULL;}voidInstallAnyByComponentOid (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;	if ( oid ) {		a->oid.octs = malloc( oid->octetLen );		memcpy ( a->oid.octs, oid->octs, oid->octetLen );		a->oid.octetLen = oid->octetLen;	}	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);}intBDecComponentTop  (ber_decoder_func *decoder _AND_void* mem_op _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 ( elmtLen <= 0 ) return (-1);	if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {		return (-1);	}			return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );}/* * ASN.1 specification of a distinguished name * DistinguishedName ::= RDNSequence * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName * RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeandValue * AttributeTypeandValue ::= SEQUENCE { * 	type	AttributeType *	value	AttributeValue * } * When dnMatch/rdnMatch is used in a component assertion value * the component in DistinguishedName/RelativeDistinguishedName * need to be converted to the LDAP encodings in RFC2253 * in order to be matched against the assertion value * If allComponentMatch is used, the assertion value may be * decoded into the Inte

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -