From: Pierangelo Masarati Date: Wed, 22 Oct 2008 23:38:09 +0000 (+0000) Subject: tag optional stuff X-Git-Tag: ACLCHECK_0~1199 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6bedf74c413578805aa47db913ea24d1a0806192;p=openldap tag optional stuff --- diff --git a/libraries/libldap/deref.c b/libraries/libldap/deref.c index d5a52ae43b..003941d9a1 100644 --- a/libraries/libldap/deref.c +++ b/libraries/libldap/deref.c @@ -198,21 +198,24 @@ ldap_parse_derefresponse_control( goto done; } - for ( tag = ber_first_element( ber, &len, &last2 ); - tag != LBER_DEFAULT; - tag = ber_next_element( ber, &len, last2 ) ) - { - LDAPDerefVal *dv; - - dv = LDAP_CALLOC( 1, sizeof(LDAPDerefVal) ); - - tag = ber_scanf( ber, "{a[W]}", &dv->type, &dv->vals ); - if ( tag == LBER_ERROR ) { - goto done; + tag = ber_peek_tag( ber, &len ); + if ( tag == (LBER_CONSTRUCTED|LBER_CLASS_CONTEXT) ) { + for ( tag = ber_first_element( ber, &len, &last2 ); + tag != LBER_DEFAULT; + tag = ber_next_element( ber, &len, last2 ) ) + { + LDAPDerefVal *dv; + + dv = LDAP_CALLOC( 1, sizeof(LDAPDerefVal) ); + + tag = ber_scanf( ber, "{a[W]}", &dv->type, &dv->vals ); + if ( tag == LBER_ERROR ) { + goto done; + } + + *dvp = dv; + dvp = &dv->next; } - - *dvp = dv; - dvp = &dv->next; } tag = ber_scanf( ber, "}" ); diff --git a/servers/slapd/overlays/deref.c b/servers/slapd/overlays/deref.c index 44300ea8ee..b6d0b0b637 100644 --- a/servers/slapd/overlays/deref.c +++ b/servers/slapd/overlays/deref.c @@ -64,7 +64,7 @@ * DerefRes ::= SEQUENCE { * derefAttr AttributeDescription, * derefVal LDAPDN, - * attrVals PartialAttributeList OPTIONAL } + * attrVals [0] PartialAttributeList OPTIONAL } * * If vals is empty, partialAttribute is omitted. * If all vals in attrVals are empty, attrVals is omitted. @@ -345,19 +345,28 @@ deref_response( Operation *op, SlapReply *rs ) rc = ber_printf( ber, "{" /*}*/ ); for ( dr = drhead; dr != NULL; dr = dr->dr_next ) { for ( i = 0; !BER_BVISNULL( &dr->dr_vals[ i ].dv_derefSpecVal ); i++ ) { - int j; + int j, first = 1; - rc = ber_printf( ber, "{OO{" /*}*/, + rc = ber_printf( ber, "{OO" /*}*/, &dr->dr_spec.ds_derefAttr->ad_cname, &dr->dr_vals[ i ].dv_derefSpecVal ); for ( j = 0; j < dr->dr_spec.ds_nattrs; j++ ) { if ( dr->dr_vals[ i ].dv_attrVals[ j ] != NULL ) { + if ( first ) { + rc = ber_printf( ber, "t{" /*}*/, + (LBER_CONSTRUCTED|LBER_CLASS_CONTEXT) ); + first = 0; + } rc = ber_printf( ber, "{O[W]}", &dr->dr_spec.ds_attributes[ j ]->ad_cname, dr->dr_vals[ i ].dv_attrVals[ j ] ); } } - rc = ber_printf( ber, /*{*/ "}N}" ); + if ( !first ) { + rc = ber_printf( ber, /*{{*/ "}N}" ); + } else { + rc = ber_printf( ber, /*{*/ "}" ); + } } } rc = ber_printf( ber, /*{*/ "}" );