X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Fdds.c;h=56d299fdb0142148d5c7df7895458bab568b3100;hb=9e80eab803512c2c9bff39c20ebfe48e98451ffa;hp=ebf70ec878b8fde65af3d5032a01f13a42fbc799;hpb=0f2b1d551b676a7928ed1af67a20dcef43b42b65;p=openldap diff --git a/servers/slapd/overlays/dds.c b/servers/slapd/overlays/dds.c index ebf70ec878..56d299fdb0 100644 --- a/servers/slapd/overlays/dds.c +++ b/servers/slapd/overlays/dds.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2005-2007 The OpenLDAP Foundation. + * Copyright 2005-2011 The OpenLDAP Foundation. * Portions Copyright 2005-2006 SysNet s.n.c. * All rights reserved. * @@ -134,7 +134,10 @@ dds_expire( void *ctx, dds_info_t *di ) int ndeletes, ntotdeletes; - connection_fake_init( &conn, &opbuf, ctx ); + int rc; + char *extra = ""; + + connection_fake_init2( &conn, &opbuf, ctx, 0 ); op = &opbuf.ob_op; op->o_tag = LDAP_REQ_SEARCH; @@ -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; } @@ -229,10 +243,9 @@ done_search:; de->de_ndn.bv_val, rs.sr_err ); break; } - + if ( de != NULL ) { *dep = de->de_next; - dep = &de->de_next; op->o_tmpfree( de, op->o_tmpmemctx ); } } @@ -381,7 +394,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 +413,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, @@ -566,11 +581,13 @@ dds_op_modify( Operation *op, SlapReply *rs ) } } else if ( mod->sml_desc == slap_schema.si_ad_entryTtl ) { - unsigned long ttl; + unsigned long uttl; + time_t ttl; int rc; switch ( mod->sml_op ) { case LDAP_MOD_DELETE: + case SLAP_MOD_SOFTDEL: /* FIXME? */ if ( mod->sml_values != NULL ) { if ( BER_BVISEMPTY( &bv_entryTtl ) || !bvmatch( &bv_entryTtl, &mod->sml_values[ 0 ] ) ) @@ -595,8 +612,9 @@ dds_op_modify( Operation *op, SlapReply *rs ) entryTtl = -1; /* fallthru */ - case SLAP_MOD_SOFTADD: /* FIXME? */ case LDAP_MOD_ADD: + case SLAP_MOD_SOFTADD: /* FIXME? */ + case SLAP_MOD_ADD_IF_NOT_PRESENT: /* FIXME? */ assert( mod->sml_values != NULL ); assert( BER_BVISNULL( &mod->sml_values[ 1 ] ) ); @@ -613,7 +631,8 @@ dds_op_modify( Operation *op, SlapReply *rs ) goto done; } - rc = lutil_atoul( &ttl, mod->sml_values[ 0 ].bv_val ); + rc = lutil_atoul( &uttl, mod->sml_values[ 0 ].bv_val ); + ttl = (time_t)uttl; assert( rc == 0 ); if ( ttl > DDS_RF2589_MAX_TTL ) { rs->sr_err = LDAP_PROTOCOL_ERROR; @@ -630,7 +649,7 @@ dds_op_modify( Operation *op, SlapReply *rs ) goto done; } - entryTtl = (time_t)ttl; + entryTtl = ttl; bv_entryTtl.bv_len = mod->sml_values[ 0 ].bv_len; AC_MEMCPY( bv_entryTtl.bv_val, mod->sml_values[ 0 ].bv_val, bv_entryTtl.bv_len ); bv_entryTtl.bv_val[ bv_entryTtl.bv_len ] = '\0'; @@ -990,7 +1009,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 ); @@ -1105,26 +1124,24 @@ dds_op_extended( Operation *op, SlapReply *rs ) BerElementBuffer berbuf; BerElement *ber = (BerElement *)&berbuf; - if ( rs->sr_err == LDAP_SUCCESS ) { - ber_init_w_nullc( ber, LBER_USE_DER ); - - rc = ber_printf( ber, "{tiN}", LDAP_TAG_EXOP_REFRESH_RES_TTL, (int)ttl ); + ber_init_w_nullc( ber, LBER_USE_DER ); - if ( rc < 0 ) { - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error"; + rc = ber_printf( ber, "{tiN}", LDAP_TAG_EXOP_REFRESH_RES_TTL, (int)ttl ); - } else { - (void)ber_flatten( ber, &rs->sr_rspdata ); - rs->sr_rspoid = ch_strdup( slap_EXOP_REFRESH.bv_val ); + if ( rc < 0 ) { + rs->sr_err = LDAP_OTHER; + rs->sr_text = "internal error"; - Log3( LDAP_DEBUG_TRACE, LDAP_LEVEL_INFO, - "%s REFRESH dn=\"%s\" TTL=%ld\n", - op->o_log_prefix, op->o_req_ndn.bv_val, ttl ); - } + } else { + (void)ber_flatten( ber, &rs->sr_rspdata ); + rs->sr_rspoid = ch_strdup( slap_EXOP_REFRESH.bv_val ); - ber_free_buf( ber ); + Log3( LDAP_DEBUG_TRACE, LDAP_LEVEL_INFO, + "%s REFRESH dn=\"%s\" TTL=%ld\n", + op->o_log_prefix, op->o_req_ndn.bv_val, ttl ); } + + ber_free_buf( ber ); } return rs->sr_err; @@ -1375,7 +1392,7 @@ dds_cfgen( ConfigArgs *c ) if ( t < DDS_RF2589_DEFAULT_TTL || t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), - "DDS invalid dds-max-ttl=%ld; must be between %d and %d", + "DDS invalid dds-max-ttl=%lu; 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->cr_msg ); @@ -1395,9 +1412,9 @@ dds_cfgen( ConfigArgs *c ) return 1; } - if ( t < 0 || t > DDS_RF2589_MAX_TTL ) { + if ( t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), - "DDS invalid dds-min-ttl=%ld", + "DDS invalid dds-min-ttl=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); @@ -1422,9 +1439,9 @@ dds_cfgen( ConfigArgs *c ) return 1; } - if ( t < 0 || t > DDS_RF2589_MAX_TTL ) { + if ( t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), - "DDS invalid dds-default-ttl=%ld", + "DDS invalid dds-default-ttl=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); @@ -1451,7 +1468,7 @@ dds_cfgen( ConfigArgs *c ) if ( t <= 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), - "DDS invalid dds-interval=%ld", + "DDS invalid dds-interval=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); @@ -1486,9 +1503,9 @@ dds_cfgen( ConfigArgs *c ) return 1; } - if ( t < 0 || t > DDS_RF2589_MAX_TTL ) { + if ( t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), - "DDS invalid dds-tolerance=%ld", + "DDS invalid dds-tolerance=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); @@ -1609,7 +1626,10 @@ dds_count( void *ctx, BackendDB *be ) slap_callback sc = { 0 }; SlapReply rs = { REP_RESULT }; - connection_fake_init( &conn, &opbuf, ctx ); + int rc; + char *extra = ""; + + connection_fake_init2( &conn, &opbuf, ctx, 0 ); op = &opbuf.ob_op; op->o_tag = LDAP_REQ_SEARCH; @@ -1644,6 +1664,7 @@ dds_count( void *ctx, BackendDB *be ) op->o_callback = ≻ 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 +1672,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; @@ -1792,6 +1823,12 @@ slap_exop_refresh( op->o_req_dn = op->o_req_ndn; op->o_bd = select_backend( &op->o_req_ndn, 0 ); + if ( op->o_bd == NULL ) { + send_ldap_error( op, rs, LDAP_NO_SUCH_OBJECT, + "no global superior knowledge" ); + goto done; + } + if ( !SLAP_DYNAMIC( op->o_bd ) ) { send_ldap_error( op, rs, LDAP_UNAVAILABLE_CRITICAL_EXTENSION, "backend does not support dynamic directory services" );