]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/retcode.c
trim listed modules
[openldap] / servers / slapd / overlays / retcode.c
index a92430a9045c07b52918c0643fbb430f59b6fc9e..4c8af8898695bcc2e7c3cb3509c6e1f9ccb2da3f 100644 (file)
@@ -43,6 +43,8 @@ static AttributeDescription   *ad_errSleepTime;
 static AttributeDescription    *ad_errMatchedDN;
 static AttributeDescription    *ad_errUnsolicitedOID;
 static AttributeDescription    *ad_errUnsolicitedData;
+static AttributeDescription    *ad_errDisconnect;
+
 static ObjectClass             *oc_errAbsObject;
 static ObjectClass             *oc_errObject;
 static ObjectClass             *oc_errAuxObject;
@@ -75,6 +77,11 @@ typedef struct retcode_item_t {
        slap_mask_t             rdi_mask;
        struct berval           rdi_unsolicited_oid;
        struct berval           rdi_unsolicited_data;
+
+       unsigned                rdi_flags;
+#define        RDI_PRE_DISCONNECT      (0x1U)
+#define        RDI_POST_DISCONNECT     (0x2U)
+
        struct retcode_item_t   *rdi_next;
 } retcode_item_t;
 
@@ -407,6 +414,10 @@ retcode_op_func( Operation *op, SlapReply *rs )
                rs->sr_text = "retcode not found";
 
        } else {
+               if ( rdi->rdi_flags & RDI_PRE_DISCONNECT ) {
+                       return rs->sr_err = SLAPD_DISCONNECT;
+               }
+
                rs->sr_err = rdi->rdi_err;
                rs->sr_text = rdi->rdi_text.bv_val;
                rs->sr_matched = rdi->rdi_matched.bv_val;
@@ -482,6 +493,10 @@ retcode_op_func( Operation *op, SlapReply *rs )
                }
                rs->sr_matched = NULL;
                rs->sr_text = NULL;
+
+               if ( rdi && rdi->rdi_flags & RDI_POST_DISCONNECT ) {
+                       return rs->sr_err = SLAPD_DISCONNECT;
+               }
                break;
        }
 
@@ -526,6 +541,7 @@ retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e
        Attribute       *a;
        int             err;
        char            *next;
+       int             disconnect = 0;
 
        if ( get_manageDSAit( op ) ) {
                return SLAP_CB_CONTINUE;
@@ -560,6 +576,15 @@ retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e
                }
        }
 
+       /* disconnect */
+       a = attr_find( e->e_attrs, ad_errDisconnect );
+       if ( a != NULL ) {
+               if ( bvmatch( &a->a_nvals[ 0 ], &slap_true_bv ) ) {
+                       return rs->sr_err = SLAPD_DISCONNECT;
+               }
+               disconnect = 1;
+       }
+
        /* error code */
        a = attr_find( e->e_attrs, ad_errCode );
        if ( a == NULL ) {
@@ -669,8 +694,12 @@ retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e
                op->o_bd = o_bd;
                op->o_callback = o_callback;
        }
-       
+
        if ( rs->sr_err != LDAP_SUCCESS ) {
+               if ( disconnect ) {
+                       return rs->sr_err = SLAPD_DISCONNECT;
+               }
+       
                op->o_abandon = 1;
                return rs->sr_err;
        }
@@ -983,10 +1012,29 @@ retcode_db_config(
                                                        &rdi.rdi_unsolicited_oid );
                                        }
 
+                               } else if ( strncasecmp( argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 )
+                               {
+                                       char *arg = &argv[ i ][ STRLENOF( "flags=" ) ];
+                                       if ( strcasecmp( arg, "disconnect" ) == 0 ) {
+                                               rdi.rdi_flags |= RDI_PRE_DISCONNECT;
+
+                                       } else if ( strcasecmp( arg, "pre-disconnect" ) == 0 ) {
+                                               rdi.rdi_flags |= RDI_PRE_DISCONNECT;
+
+                                       } else if ( strcasecmp( arg, "post-disconnect" ) == 0 ) {
+                                               rdi.rdi_flags |= RDI_POST_DISCONNECT;
+
+                                       } else {
+                                               fprintf( stderr, "%s: line %d: retcode: "
+                                                       "unknown flag \"%s\".\n",
+                                                       fname, lineno, arg );
+                                               return 1;
+                                       }
+
                                } else {
                                        fprintf( stderr, "%s: line %d: retcode: "
                                                "unknown option \"%s\".\n",
-                                                       fname, lineno, argv[ i ] );
+                                               fname, lineno, argv[ i ] );
                                        return 1;
                                }
                        }
@@ -1269,6 +1317,12 @@ retcode_initialize( void )
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 "
                        "SINGLE-VALUE )",
                        &ad_errUnsolicitedData },
+               { "( 1.3.6.1.4.1.4203.666.11.4.1.8 "
+                       "NAME ( 'errDisconnect' ) "
+                       "DESC 'Disconnect without notice' "
+                       "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
+                       "SINGLE-VALUE )",
+                       &ad_errDisconnect },
                { NULL }
        };
 
@@ -1289,6 +1343,7 @@ retcode_initialize( void )
                                "$ errMatchedDN "
                                "$ errUnsolicitedOID "
                                "$ errUnsolicitedData "
+                               "$ errDisconnect "
                        ") )",
                        &oc_errAbsObject },
                { "( 1.3.6.1.4.1.4203.666.11.4.3.1 "