]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/retcode.c
fix wrong response tags (ITS4182; consequence of fixing ITS#4173)
[openldap] / servers / slapd / overlays / retcode.c
index 5788ccf7b8c7ac247354d8241013ac3ab22eb384..845370a8123df3ab4ad5bd3112d26f907bb3c551 100644 (file)
@@ -39,7 +39,10 @@ static AttributeDescription  *ad_errCode;
 static AttributeDescription    *ad_errText;
 static AttributeDescription    *ad_errOp;
 static AttributeDescription    *ad_errSleepTime;
+static AttributeDescription    *ad_errMatchedDN;
+static ObjectClass             *oc_errAbsObject;
 static ObjectClass             *oc_errObject;
+static ObjectClass             *oc_errAuxObject;
 
 typedef enum retcode_op_e {
        SN_DG_OP_NONE           = 0x0000,
@@ -61,6 +64,7 @@ typedef struct retcode_item_t {
        struct berval           rdi_dn;
        struct berval           rdi_ndn;
        struct berval           rdi_text;
+       struct berval           rdi_matched;
        int                     rdi_err;
        BerVarray               rdi_ref;
        int                     rdi_sleeptime;
@@ -82,7 +86,7 @@ typedef struct retcode_t {
 } retcode_t;
 
 static int
-retcode_entry_response( Operation *op, SlapReply *rs, Entry *e );
+retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e );
 
 static int
 retcode_cleanup_cb( Operation *op, SlapReply *rs )
@@ -157,12 +161,14 @@ done:;
 static int
 retcode_op_add( Operation *op, SlapReply *rs )
 {
-       return retcode_entry_response( op, rs, op->ora_e );
+       return retcode_entry_response( op, rs, NULL, op->ora_e );
 }
 
 typedef struct retcode_cb_t {
+       BackendInfo     *rdc_info;
        unsigned        rdc_flags;
        ber_tag_t       rdc_tag;
+       AttributeName   *rdc_attrs;
 } retcode_cb_t;
 
 static int
@@ -175,14 +181,19 @@ retcode_cb_response( Operation *op, SlapReply *rs )
                int             rc;
 
                op->o_tag = rdc->rdc_tag;
-               rc = retcode_entry_response( op, rs, rs->sr_entry );
+               if ( op->o_tag == LDAP_REQ_SEARCH ) {
+                       rs->sr_attrs = rdc->rdc_attrs;
+               }
+               rc = retcode_entry_response( op, rs, rdc->rdc_info, rs->sr_entry );
                op->o_tag = o_tag;
 
                return rc;
        }
 
        if ( rs->sr_err == LDAP_SUCCESS ) {
-               rdc->rdc_flags = SLAP_CB_CONTINUE;
+               if ( !op->o_abandon ) {
+                       rdc->rdc_flags = SLAP_CB_CONTINUE;
+               }
                return 0;
        }
 
@@ -211,14 +222,19 @@ retcode_op_internal( Operation *op, SlapReply *rs )
        op2.ors_attrsonly = 0;
        op2.ors_attrs = slap_anlist_all_attributes;
 
-       ber_str2bv_x( "(objectClass=errObject)", STRLENOF( "(objectClass=errObject)" ),
+       ber_str2bv_x( "(objectClass=errAbsObject)",
+               STRLENOF( "(objectClass=errAbsObject)" ),
                1, &op2.ors_filterstr, op2.o_tmpmemctx );
        op2.ors_filter = str2filter_x( &op2, op2.ors_filterstr.bv_val );
 
        db.bd_info = on->on_info->oi_orig;
        op2.o_bd = &db;
 
+       rdc.rdc_info = on->on_info->oi_orig;
        rdc.rdc_flags = RETCODE_FINDIR;
+       if ( op->o_tag == LDAP_REQ_SEARCH ) {
+               rdc.rdc_attrs = op->ors_attrs;
+       }
        rdc.rdc_tag = op->o_tag;
        sc.sc_response = retcode_cb_response;
        sc.sc_private = &rdc;
@@ -254,16 +270,27 @@ retcode_op_func( Operation *op, SlapReply *rs )
                                return retcode_op_add( op, rs );
 
                        case LDAP_REQ_BIND:
+                               /* skip if rootdn */
                                if ( be_isroot_pw( op ) ) {
                                        return SLAP_CB_CONTINUE;
                                }
-                               /* fallthru */
+                               return retcode_op_internal( op, rs );
+
+                       case LDAP_REQ_SEARCH:
+                               if ( op->ors_scope == LDAP_SCOPE_BASE ) {
+                                       rs->sr_err = retcode_op_internal( op, rs );
+                                       if ( rs->sr_err == SLAP_CB_CONTINUE ) {
+                                               rs->sr_err = LDAP_SUCCESS;
+                                       }
+                                       send_ldap_result( op, rs );
+                                       return rs->sr_err;
+                               }
+                               break;
 
                        case LDAP_REQ_MODIFY:
                        case LDAP_REQ_DELETE:
                        case LDAP_REQ_MODRDN:
                        case LDAP_REQ_COMPARE:
-                       case LDAP_REQ_SEARCH:
                                return retcode_op_internal( op, rs );
                        }
                }
@@ -352,6 +379,7 @@ retcode_op_func( Operation *op, SlapReply *rs )
        } else {
                rs->sr_err = rdi->rdi_err;
                rs->sr_text = rdi->rdi_text.bv_val;
+               rs->sr_matched = rdi->rdi_matched.bv_val;
 
                /* FIXME: we only honor the rdi_ref field in case rdi_err
                 * is LDAP_REFERRAL otherwise send_ldap_result() bails out */
@@ -394,6 +422,7 @@ retcode_op_func( Operation *op, SlapReply *rs )
                send_ldap_result( op, rs );
                if ( rs->sr_ref != NULL ) {
                        ber_bvarray_free( rs->sr_ref );
+                       rs->sr_ref = NULL;
                }
                rs->sr_matched = NULL;
                rs->sr_text = NULL;
@@ -436,10 +465,8 @@ retcode_op2str( ber_tag_t op, struct berval *bv )
 }
 
 static int
-retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
+retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e )
 {
-       slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
-
        Attribute       *a;
        int             err;
        char            *next;
@@ -448,7 +475,7 @@ retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
                return SLAP_CB_CONTINUE;
        }
 
-       if ( !is_entry_objectclass( e, oc_errObject, 0 ) ) {
+       if ( !is_entry_objectclass_or_sub( e, oc_errAbsObject ) ) {
                return SLAP_CB_CONTINUE;
        }
 
@@ -500,7 +527,8 @@ retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
        }
 
        if ( rs->sr_err != LDAP_SUCCESS ) {
-               BackendDB       db = *op->o_bd;
+               BackendDB       db = *op->o_bd,
+                               *o_bd = op->o_bd;
                void            *o_callback = op->o_callback;
 
                /* message text */
@@ -509,7 +537,19 @@ retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
                        rs->sr_text = a->a_vals[ 0 ].bv_val;
                }
 
-               db.bd_info = on->on_info->oi_orig;
+               /* matched DN */
+               a = attr_find( e->e_attrs, ad_errMatchedDN );
+               if ( a != NULL ) {
+                       rs->sr_matched = a->a_vals[ 0 ].bv_val;
+               }
+
+               if ( bi == NULL ) {
+                       slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
+
+                       bi = on->on_info->oi_orig;
+               }
+
+               db.bd_info = bi;
                op->o_bd = &db;
                op->o_callback = NULL;
 
@@ -533,6 +573,8 @@ retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
                }
 
                rs->sr_text = NULL;
+               rs->sr_matched = NULL;
+               op->o_bd = o_bd;
                op->o_callback = o_callback;
        }
        
@@ -554,7 +596,7 @@ retcode_response( Operation *op, SlapReply *rs )
                return SLAP_CB_CONTINUE;
        }
 
-       return retcode_entry_response( op, rs, rs->sr_entry );
+       return retcode_entry_response( op, rs, NULL, rs->sr_entry );
 }
 
 static int
@@ -700,13 +742,15 @@ retcode_db_config(
                                                } else if ( strcasecmp( ops[ j ], "compare" ) == 0 ) {
                                                        rdi.rdi_mask |= SN_DG_OP_COMPARE;
 
-                                               } else if ( strcasecmp( ops[ j ], "add" ) == 0 ) {
+                                               } else if ( strcasecmp( ops[ j ], "delete" ) == 0 ) {
                                                        rdi.rdi_mask |= SN_DG_OP_DELETE;
 
                                                } else if ( strcasecmp( ops[ j ], "modify" ) == 0 ) {
                                                        rdi.rdi_mask |= SN_DG_OP_MODIFY;
 
-                                               } else if ( strcasecmp( ops[ j ], "rename" ) == 0 ) {
+                                               } else if ( strcasecmp( ops[ j ], "rename" ) == 0
+                                                       || strcasecmp( ops[ j ], "modrdn" ) == 0 )
+                                               {
                                                        rdi.rdi_mask |= SN_DG_OP_RENAME;
 
                                                } else if ( strcasecmp( ops[ j ], "search" ) == 0 ) {
@@ -746,6 +790,24 @@ retcode_db_config(
                                        }
                                        ber_str2bv( &argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text );
 
+                               } else if ( strncasecmp( argv[ i ], "matched=", STRLENOF( "matched=" ) ) == 0 )
+                               {
+                                       struct berval   dn;
+
+                                       if ( !BER_BVISNULL( &rdi.rdi_matched ) ) {
+                                               fprintf( stderr, "%s: line %d: retcode: "
+                                                       "\"matched\" already provided.\n",
+                                                       fname, lineno );
+                                               return 1;
+                                       }
+                                       ber_str2bv( &argv[ i ][ STRLENOF( "matched=" ) ], 0, 0, &dn );
+                                       if ( dnPretty( NULL, &dn, &rdi.rdi_matched, NULL ) != LDAP_SUCCESS ) {
+                                               fprintf( stderr, "%s: line %d: retcode: "
+                                                       "unable to prettify matched DN \"%s\".\n",
+                                                       fname, lineno, &argv[ i ][ STRLENOF( "matched=" ) ] );
+                                               return 1;
+                                       }
+
                                } else if ( strncasecmp( argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 )
                                {
                                        char            **refs;
@@ -887,6 +949,13 @@ retcode_db_open( BackendDB *be )
                        attr_merge_normalize_one( &rdi->rdi_e, ad_errText, &val[ 0 ], NULL );
                }
 
+               /* matched */
+               if ( !BER_BVISNULL( &rdi->rdi_matched ) ) {
+                       val[ 0 ] = rdi->rdi_matched;
+
+                       attr_merge_normalize_one( &rdi->rdi_e, ad_errMatchedDN, &val[ 0 ], NULL );
+               }
+
                /* sleep time */
                if ( rdi->rdi_sleeptime > 0 ) {
                        snprintf( buf, sizeof( buf ), "%d", rdi->rdi_sleeptime );
@@ -957,6 +1026,14 @@ retcode_db_destroy( BackendDB *be )
                                ber_memfree( rdi->rdi_text.bv_val );
                        }
 
+                       if ( !BER_BVISNULL( &rdi->rdi_matched ) ) {
+                               ber_memfree( rdi->rdi_matched.bv_val );
+                       }
+
+                       if ( rdi->rdi_ref ) {
+                               ber_bvarray_free( rdi->rdi_ref );
+                       }
+
                        BER_BVZERO( &rdi->rdi_e.e_name );
                        BER_BVZERO( &rdi->rdi_e.e_nname );
 
@@ -967,6 +1044,14 @@ retcode_db_destroy( BackendDB *be )
                        ch_free( rdi );
                }
 
+               if ( !BER_BVISNULL( &rd->rd_pdn ) ) {
+                       ber_memfree( rd->rd_pdn.bv_val );
+               }
+
+               if ( !BER_BVISNULL( &rd->rd_npdn ) ) {
+                       ber_memfree( rd->rd_npdn.bv_val );
+               }
+
                ber_memfree( rd );
        }
 
@@ -1017,6 +1102,13 @@ retcode_init( void )
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
                        "SINGLE-VALUE )",
                        &ad_errSleepTime },
+               { "errMatchedDN", "( 1.3.6.1.4.1.4203.666.11.4.1.5 "
+                       "NAME ( 'errMatchedDN' ) "
+                       "DESC 'Value to be returned as matched DN' "
+                       "EQUALITY distinguishedNameMatch "
+                       "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
+                       "SINGLE-VALUE )",
+                       &ad_errMatchedDN },
                { NULL }
        };
 
@@ -1025,9 +1117,9 @@ retcode_init( void )
                char            *desc;
                ObjectClass     **oc;
        } retcode_oc[] = {
-               { "errObject", "( 1.3.6.1.4.1.4203.666.11.4.3.1 "
-                       "NAME ( 'errObject' ) "
-                       "SUP top STRUCTURAL "
+               { "errAbsObject", "( 1.3.6.1.4.1.4203.666.11.4.3.0 "
+                       "NAME ( 'errAbsObject' ) "
+                       "SUP top ABSTRACT "
                        "MUST ( errCode ) "
                        "MAY ( "
                                "cn "
@@ -1035,8 +1127,19 @@ retcode_init( void )
                                "$ errOp "
                                "$ errText "
                                "$ errSleepTime "
+                               "$ errMatchedDN "
                        ") )",
+                       &oc_errAbsObject },
+               { "errObject", "( 1.3.6.1.4.1.4203.666.11.4.3.1 "
+                       "NAME ( 'errObject' ) "
+                       "SUP errAbsObject STRUCTURAL "
+                       ")",
                        &oc_errObject },
+               { "errAuxObject", "( 1.3.6.1.4.1.4203.666.11.4.3.2 "
+                       "NAME ( 'errAuxObject' ) "
+                       "SUP errAbsObject AUXILIARY "
+                       ")",
+                       &oc_errAuxObject },
                { NULL }
        };