]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/dds.c
ITS#5710 fix stupid updateCookie hack, use explicit o_dont_replicate flag
[openldap] / servers / slapd / overlays / dds.c
index ebf70ec878b8fde65af3d5032a01f13a42fbc799..8230c1bbe5ec65ea7d48b655d95db6e7c9db6512 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2005-2007 The OpenLDAP Foundation.
+ * Copyright 2005-2008 The OpenLDAP Foundation.
  * Portions Copyright 2005-2006 SysNet s.n.c.
  * All rights reserved.
  *
@@ -134,6 +134,9 @@ dds_expire( void *ctx, dds_info_t *di )
 
        int             ndeletes, ntotdeletes;
 
+       int             rc;
+       char            *extra = "";
+
        connection_fake_init( &conn, &opbuf, ctx );
        op = &opbuf.ob_op;
 
@@ -182,12 +185,23 @@ dds_expire( void *ctx, dds_info_t *di )
 
 done_search:;
        op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
-       filter_free_x( op, op->ors_filter );
+       filter_free_x( op, op->ors_filter, 1 );
 
-       if ( rs.sr_err != LDAP_SUCCESS ) {
-               Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                       "DDS expired objects lookup failed err=%d\n",
-                       rs.sr_err );
+       rc = rs.sr_err;
+       switch ( rs.sr_err ) {
+       case LDAP_SUCCESS:
+               break;
+
+       case LDAP_NO_SUCH_OBJECT:
+               /* (ITS#5267) database not created yet? */
+               rs.sr_err = LDAP_SUCCESS;
+               extra = " (ignored)";
+               /* fallthru */
+
+       default:
+               Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
+                       "DDS expired objects lookup failed err=%d%s\n",
+                       rc, extra );
                goto done;
        }
 
@@ -381,7 +395,7 @@ dds_op_add( Operation *op, SlapReply *rs )
        /* handle dynamic object operational attr(s) */
        if ( is_dynamicObject ) {
                time_t          ttl, expire;
-               char            ttlbuf[] = "31557600";
+               char            ttlbuf[STRLENOF("31557600") + 1];
                char            tsbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
                struct berval   bv;
 
@@ -400,10 +414,12 @@ dds_op_add( Operation *op, SlapReply *rs )
 
                ttl = DDS_DEFAULT_TTL( di );
 
+               /* assert because should be checked at configure */
                assert( ttl <= DDS_RF2589_MAX_TTL );
 
                bv.bv_val = ttlbuf;
                bv.bv_len = snprintf( ttlbuf, sizeof( ttlbuf ), "%ld", ttl );
+               assert( bv.bv_len < sizeof( ttlbuf ) );
 
                /* FIXME: apparently, values in op->ora_e are malloc'ed
                 * on the thread's slab; works fine by chance,
@@ -990,7 +1006,7 @@ dds_op_extended( Operation *op, SlapReply *rs )
                slap_callback   sc = { 0 };
                Modifications   ttlmod = { { 0 } };
                struct berval   ttlvalues[ 2 ];
-               char            ttlbuf[] = "31557600";
+               char            ttlbuf[STRLENOF("31557600") + 1];
 
                rs->sr_err = slap_parse_refresh( op->ore_reqdata, NULL, &ttl,
                        &rs->sr_text, NULL );
@@ -1609,6 +1625,9 @@ dds_count( void *ctx, BackendDB *be )
        slap_callback   sc = { 0 };
        SlapReply       rs = { REP_RESULT };
 
+       int             rc;
+       char            *extra = "";
+
        connection_fake_init( &conn, &opbuf, ctx );
        op = &opbuf.ob_op;
 
@@ -1644,6 +1663,7 @@ dds_count( void *ctx, BackendDB *be )
        op->o_callback = &sc;
        sc.sc_response = dds_count_cb;
        sc.sc_private = &di->di_num_dynamicObjects;
+       di->di_num_dynamicObjects = 0;
 
        op->o_bd->bd_info = (BackendInfo *)on->on_info;
        (void)op->o_bd->bd_info->bi_op_search( op, &rs );
@@ -1651,17 +1671,27 @@ dds_count( void *ctx, BackendDB *be )
 
 done_search:;
        op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
-       filter_free_x( op, op->ors_filter );
+       filter_free_x( op, op->ors_filter, 1 );
 
-       if ( rs.sr_err == LDAP_SUCCESS ) {
+       rc = rs.sr_err;
+       switch ( rs.sr_err ) {
+       case LDAP_SUCCESS:
                Log1( LDAP_DEBUG_STATS, LDAP_LEVEL_INFO,
                        "DDS non-expired=%d\n",
                        di->di_num_dynamicObjects );
+               break;
 
-       } else {
-               Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
-                       "DDS non-expired objects lookup failed err=%d\n",
-                       rs.sr_err );
+       case LDAP_NO_SUCH_OBJECT:
+               /* (ITS#5267) database not created yet? */
+               rs.sr_err = LDAP_SUCCESS;
+               extra = " (ignored)";
+               /* fallthru */
+
+       default:
+               Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
+                       "DDS non-expired objects lookup failed err=%d%s\n",
+                       rc, extra );
+               break;
        }
 
        return rs.sr_err;