]> git.sur5r.net Git - openldap/commitdiff
tag optional stuff
authorPierangelo Masarati <ando@openldap.org>
Wed, 22 Oct 2008 23:38:09 +0000 (23:38 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 22 Oct 2008 23:38:09 +0000 (23:38 +0000)
libraries/libldap/deref.c
servers/slapd/overlays/deref.c

index d5a52ae43bd9df6e986de5a67d8c05304b374335..003941d9a1de1a2bcaea179258910245fff3b1fb 100644 (file)
@@ -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, "}" );
index 44300ea8ee8c730a7fe32ffeda4579d89ef2679a..b6d0b0b637167c43df5284d4ff794060eaaf13e0 100644 (file)
@@ -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, /*{*/ "}" );