]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/dds.c
check for ee == NULL
[openldap] / servers / slapd / overlays / dds.c
index 137712b8ca0a9fa452727c976aeab72eda573074..ebf70ec878b8fde65af3d5032a01f13a42fbc799 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2005-2006 The OpenLDAP Foundation.
+ * Copyright 2005-2007 The OpenLDAP Foundation.
  * Portions Copyright 2005-2006 SysNet s.n.c.
  * All rights reserved.
  *
@@ -123,7 +123,7 @@ dds_expire( void *ctx, dds_info_t *di )
        Connection      conn = { 0 };
        OperationBuffer opbuf;
        Operation       *op;
-       slap_callback   sc = { 0 }, sc2 = { 0 };
+       slap_callback   sc = { 0 };
        dds_cb_t        dc = { 0 };
        dds_expire_t    *de = NULL, **dep;
        SlapReply       rs = { REP_RESULT };
@@ -134,13 +134,13 @@ dds_expire( void *ctx, dds_info_t *di )
 
        int             ndeletes, ntotdeletes;
 
-       op = (Operation *)&opbuf;
-       connection_fake_init( &conn, op, ctx );
+       connection_fake_init( &conn, &opbuf, ctx );
+       op = &opbuf.ob_op;
 
        op->o_tag = LDAP_REQ_SEARCH;
        memset( &op->oq_search, 0, sizeof( op->oq_search ) );
 
-       op->o_bd = select_backend( &di->di_nsuffix[ 0 ], 0, 0 );
+       op->o_bd = select_backend( &di->di_nsuffix[ 0 ], 0 );
 
        op->o_req_dn = op->o_bd->be_suffix[ 0 ];
        op->o_req_ndn = op->o_bd->be_nsuffix[ 0 ];
@@ -193,10 +193,8 @@ done_search:;
 
        op->o_tag = LDAP_REQ_DELETE;
        op->o_callback = &sc;
-       sc.sc_response = slap_replog_cb;
+       sc.sc_response = slap_null_cb;
        sc.sc_private = NULL;
-       sc.sc_next = &sc2;
-       sc2.sc_response = slap_null_cb;
 
        for ( ntotdeletes = 0, ndeletes = 1; dc.dc_ndnlist != NULL  && ndeletes > 0; ) {
                ndeletes = 0;
@@ -694,7 +692,7 @@ done:;
        if ( rs->sr_err == LDAP_SUCCESS ) {
                int     rc;
 
-               /* FIXME: this could be allowed when manageDIT is used...
+               /* FIXME: this could be allowed when the Relax control is used...
                 * in that case:
                 *
                 * TODO
@@ -713,7 +711,7 @@ done:;
                rc = is_dynamicObject - was_dynamicObject;
                if ( rc ) {
 #if 0 /* fix subordinate issues first */
-                       if ( get_manageDIT( op ) ) {
+                       if ( get_relax( op ) ) {
                                switch ( rc ) {
                                case -1:
                                        /* need to delete entryTtl to have a consistent entry */
@@ -790,6 +788,7 @@ done:;
                        tmpmod->sml_op = LDAP_MOD_REPLACE;
                        value_add_one( &tmpmod->sml_values, &bv );
                        value_add_one( &tmpmod->sml_nvalues, &bv );
+                       tmpmod->sml_numvals = 1;
                }
        }
 
@@ -950,7 +949,7 @@ slap_parse_refresh(
 
        tag = ber_peek_tag( ber, &len );
 
-       if ( len != 0 ) {
+       if ( tag != LBER_DEFAULT || len != 0 ) {
 decoding_error:;
                Log1( LDAP_DEBUG_TRACE, LDAP_LEVEL_ERR,
                        "slap_parse_refresh: decoding error, len=%ld\n",
@@ -989,7 +988,6 @@ dds_op_extended( Operation *op, SlapReply *rs )
                SlapReply       rs2 = { REP_RESULT };
                Operation       op2 = *op;
                slap_callback   sc = { 0 };
-               slap_callback   sc2 = { 0 };
                Modifications   ttlmod = { { 0 } };
                struct berval   ttlvalues[ 2 ];
                char            ttlbuf[] = "31557600";
@@ -1077,21 +1075,20 @@ dds_op_extended( Operation *op, SlapReply *rs )
                }
 
                /* we require manage privileges on the entryTtl,
-                * and fake a manageDIT control */
+                * and fake a Relax control */
                op2.o_tag = LDAP_REQ_MODIFY;
                op2.o_bd = &db;
                db.bd_info = (BackendInfo *)on->on_info;
                op2.o_callback = &sc;
-               sc.sc_response = slap_replog_cb;
-               sc.sc_next = &sc2;
-               sc2.sc_response = slap_null_cb;
-               op2.o_managedit = SLAP_CONTROL_CRITICAL;
+               sc.sc_response = slap_null_cb;
+               op2.o_relax = SLAP_CONTROL_CRITICAL;
                op2.orm_modlist = &ttlmod;
 
                ttlmod.sml_op = LDAP_MOD_REPLACE;
                ttlmod.sml_flags = SLAP_MOD_MANAGING;
                ttlmod.sml_desc = slap_schema.si_ad_entryTtl;
                ttlmod.sml_values = ttlvalues;
+               ttlmod.sml_numvals = 1;
                ttlvalues[ 0 ].bv_val = ttlbuf;
                ttlvalues[ 0 ].bv_len = snprintf( ttlbuf, sizeof( ttlbuf ), "%ld", ttl );
                BER_BVZERO( &ttlvalues[ 1 ] );
@@ -1368,20 +1365,20 @@ dds_cfgen( ConfigArgs *c )
 
        case DDS_MAXTTL:
                if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
-                       snprintf( c->msg, sizeof( c->msg),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg),
                                "DDS unable to parse dds-max-ttl \"%s\"",
                                c->argv[ 1 ] );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
                if ( t < DDS_RF2589_DEFAULT_TTL || t > DDS_RF2589_MAX_TTL ) {
-                       snprintf( c->msg, sizeof( c->msg ),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "DDS invalid dds-max-ttl=%ld; must be between %d and %d",
                                t, DDS_RF2589_DEFAULT_TTL, DDS_RF2589_MAX_TTL );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
@@ -1390,20 +1387,20 @@ dds_cfgen( ConfigArgs *c )
 
        case DDS_MINTTL:
                if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
-                       snprintf( c->msg, sizeof( c->msg),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg),
                                "DDS unable to parse dds-min-ttl \"%s\"",
                                c->argv[ 1 ] );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
                if ( t < 0 || t > DDS_RF2589_MAX_TTL ) {
-                       snprintf( c->msg, sizeof( c->msg ),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "DDS invalid dds-min-ttl=%ld",
                                t );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
@@ -1417,20 +1414,20 @@ dds_cfgen( ConfigArgs *c )
 
        case DDS_DEFAULTTTL:
                if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
-                       snprintf( c->msg, sizeof( c->msg),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg),
                                "DDS unable to parse dds-default-ttl \"%s\"",
                                c->argv[ 1 ] );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
                if ( t < 0 || t > DDS_RF2589_MAX_TTL ) {
-                       snprintf( c->msg, sizeof( c->msg ),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "DDS invalid dds-default-ttl=%ld",
                                t );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
@@ -1444,20 +1441,20 @@ dds_cfgen( ConfigArgs *c )
 
        case DDS_INTERVAL:
                if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
-                       snprintf( c->msg, sizeof( c->msg),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg),
                                "DDS unable to parse dds-interval \"%s\"",
                                c->argv[ 1 ] );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
                if ( t <= 0 ) {
-                       snprintf( c->msg, sizeof( c->msg ),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "DDS invalid dds-interval=%ld",
                                t );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
@@ -1481,20 +1478,20 @@ dds_cfgen( ConfigArgs *c )
 
        case DDS_TOLERANCE:
                if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
-                       snprintf( c->msg, sizeof( c->msg),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg),
                                "DDS unable to parse dds-tolerance \"%s\"",
                                c->argv[ 1 ] );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
                if ( t < 0 || t > DDS_RF2589_MAX_TTL ) {
-                       snprintf( c->msg, sizeof( c->msg ),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "DDS invalid dds-tolerance=%ld",
                                t );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
 
@@ -1503,10 +1500,10 @@ dds_cfgen( ConfigArgs *c )
 
        case DDS_MAXDYNAMICOBJS:
                if ( c->value_int < 0 ) {
-                       snprintf( c->msg, sizeof( c->msg ),
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "DDS invalid dds-max-dynamicObjects=%d", c->value_int );
                        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                               "%s: %s.\n", c->log, c->msg );
+                               "%s: %s.\n", c->log, c->cr_msg );
                        return 1;
                }
                di->di_max_dynamicObjects = c->value_int;
@@ -1522,7 +1519,8 @@ dds_cfgen( ConfigArgs *c )
 
 static int
 dds_db_init(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *cr)
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        dds_info_t      *di;
@@ -1611,8 +1609,8 @@ dds_count( void *ctx, BackendDB *be )
        slap_callback   sc = { 0 };
        SlapReply       rs = { REP_RESULT };
 
-       op = (Operation *)&opbuf;
-       connection_fake_init( &conn, op, ctx );
+       connection_fake_init( &conn, &opbuf, ctx );
+       op = &opbuf.ob_op;
 
        op->o_tag = LDAP_REQ_SEARCH;
        memset( &op->oq_search, 0, sizeof( op->oq_search ) );
@@ -1671,7 +1669,8 @@ done_search:;
 
 static int
 dds_db_open(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *cr )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        dds_info_t      *di = on->on_bi.bi_private;
@@ -1730,14 +1729,14 @@ dds_db_open(
        rc = entry_info_register( dds_entry_info, (void *)di );
 
 done:;
-       ldap_pvt_thread_pool_context_reset( thrctx );
 
        return rc;
 }
 
 static int
 dds_db_close(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *cr )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        dds_info_t      *di = on->on_bi.bi_private;
@@ -1759,7 +1758,8 @@ dds_db_close(
 
 static int
 dds_db_destroy(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *cr )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        dds_info_t      *di = on->on_bi.bi_private;
@@ -1791,7 +1791,7 @@ slap_exop_refresh(
                op->o_log_prefix, op->o_req_ndn.bv_val );
        op->o_req_dn = op->o_req_ndn;
 
-       op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
+       op->o_bd = select_backend( &op->o_req_ndn, 0 );
        if ( !SLAP_DYNAMIC( op->o_bd ) ) {
                send_ldap_error( op, rs, LDAP_UNAVAILABLE_CRITICAL_EXTENSION,
                        "backend does not support dynamic directory services" );
@@ -1837,18 +1837,17 @@ dds_initialize()
 {
        int             rc = 0;
        int             i, code;
-       const char      *err;
 
        /* Make sure we don't exceed the bits reserved for userland */
        config_check_userland( DDS_LAST );
 
        if ( !do_not_load_schema ) {
                static struct {
-                       char                    *name;
                        char                    *desc;
+                       slap_mask_t             flags;
                        AttributeDescription    **ad;
                }               s_at[] = {
-                       { "entryExpireTimestamp", "( 1.3.6.1.4.1.4203.666.1.57 "
+                       { "( 1.3.6.1.4.1.4203.666.1.57 "
                                "NAME ( 'entryExpireTimestamp' ) "
                                "DESC 'RFC2589 OpenLDAP extension: expire time of a dynamic object, "
                                        "computed as now + entryTtl' "
@@ -1858,39 +1857,19 @@ dds_initialize()
                                "SINGLE-VALUE "
                                "NO-USER-MODIFICATION "
                                "USAGE dSAOperation )",
+                               SLAP_AT_HIDE,
                                &ad_entryExpireTimestamp },
                        { NULL }
                };
 
-               for ( i = 0; s_at[ i ].name != NULL; i++ ) {
-                       LDAPAttributeType       *at;
-
-                       at = ldap_str2attributetype( s_at[ i ].desc,
-                               &code, &err, LDAP_SCHEMA_ALLOW_ALL );
-                       if ( !at ) {
-                               fprintf( stderr, "dds_initialize: "
-                                       "AttributeType load failed: %s %s\n",
-                                       ldap_scherr2str( code ), err );
+               for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
+                       code = register_at( s_at[ i ].desc, s_at[ i ].ad, 0 );
+                       if ( code ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "dds_initialize: register_at failed\n", 0, 0, 0 );
                                return code;
                        }
-
-                       code = at_add( at, 0, NULL, &err );
-                       ldap_memfree( at );
-                       if ( code != LDAP_SUCCESS ) {
-                               fprintf( stderr, "dds_initialize: "
-                                       "AttributeType load failed: %s %s\n",
-                                       scherr2str( code ), err );
-                               return code;
-                       }
-
-                       code = slap_str2ad( s_at[ i ].name, s_at[ i ].ad, &err );
-                       if ( code != LDAP_SUCCESS ) {
-                               fprintf( stderr, "dds_initialize: "
-                                       "unable to find AttributeDescription "
-                                       "\"%s\": %d (%s)\n",
-                                       s_at[ i ].name, code, err );
-                               return 1;
-                       }
+                       (*s_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
                }
        }