From 266c6ad1ea68a0db48359b0d5c3b04de668f18f1 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 16 Dec 2005 01:58:36 +0000 Subject: [PATCH] plug one-time leaks; misc cleanup --- servers/slapd/add.c | 17 +++++++-------- servers/slapd/backend.c | 12 +++++++++++ servers/slapd/backover.c | 2 +- servers/slapd/bconfig.c | 5 +++-- servers/slapd/config.c | 46 ++++++++++++++++++++++++---------------- servers/slapd/delete.c | 6 +++--- servers/slapd/modify.c | 42 +++++++++++++++++++----------------- servers/slapd/modrdn.c | 6 +++--- servers/slapd/referral.c | 1 + servers/slapd/repl.c | 6 +++--- servers/slapd/slap.h | 1 + 11 files changed, 86 insertions(+), 58 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index c35cafc96f..6bfebbd7c8 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -214,10 +214,9 @@ int fe_op_add( Operation *op, SlapReply *rs ) { int manageDSAit; - Modifications *modlist = op->ora_modlist; - Modifications **modtail = &modlist; + Modifications **modtail = &op->ora_modlist; int rc = 0; - BackendDB *op_be; + BackendDB *op_be; char textbuf[ SLAP_TEXT_BUFLEN ]; size_t textlen = sizeof( textbuf ); @@ -268,7 +267,7 @@ fe_op_add( Operation *op, SlapReply *rs ) goto done; } - rs->sr_err = slap_mods_obsolete_check( op, modlist, + rs->sr_err = slap_mods_obsolete_check( op, op->ora_modlist, &rs->sr_text, textbuf, textlen ); if ( rs->sr_err != LDAP_SUCCESS ) { @@ -287,7 +286,7 @@ fe_op_add( Operation *op, SlapReply *rs ) int repl_user = be_isupdate( op ); #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#endif +#endif /* ! SLAPD_MULTIMASTER */ { int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn ); slap_callback cb = { NULL, slap_replog_cb, NULL, NULL }; @@ -295,7 +294,7 @@ fe_op_add( Operation *op, SlapReply *rs ) op->o_bd = op_be; if ( !update ) { - rs->sr_err = slap_mods_no_user_mod_check( op, modlist, + rs->sr_err = slap_mods_no_user_mod_check( op, op->ora_modlist, &rs->sr_text, textbuf, textlen ); if ( rs->sr_err != LDAP_SUCCESS ) { @@ -306,7 +305,7 @@ fe_op_add( Operation *op, SlapReply *rs ) if ( !repl_user ) { /* go to the last mod */ - for ( modtail = &modlist; + for ( modtail = &op->ora_modlist; *modtail != NULL; modtail = &(*modtail)->sml_next ) { @@ -317,7 +316,7 @@ fe_op_add( Operation *op, SlapReply *rs ) /* check for duplicate values */ rs->sr_err = slap_mods_no_repl_user_mod_check( op, - modlist, &rs->sr_text, textbuf, textlen ); + op->ora_modlist, &rs->sr_text, textbuf, textlen ); if ( rs->sr_err != LDAP_SUCCESS ) { send_ldap_result( op, rs ); goto done; @@ -333,7 +332,7 @@ fe_op_add( Operation *op, SlapReply *rs ) #ifdef SLAPD_MULTIMASTER if ( !repl_user ) -#endif +#endif /* SLAPD_MULTIMASTER */ { cb.sc_next = op->o_callback; op->o_callback = &cb; diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 1bb7e618b7..708233cfba 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -425,6 +425,12 @@ void backend_destroy_one( BackendDB *bd, int dynamic ) if ( bd->be_replogfile ) { ch_free( bd->be_replogfile ); } + if ( bd->be_replica_argsfile ) { + ch_free( bd->be_replica_argsfile ); + } + if ( bd->be_replica_pidfile ) { + ch_free( bd->be_replica_pidfile ); + } destroy_replica_info( bd ); if ( !BER_BVISNULL( &bd->be_update_ndn ) ) { ch_free( bd->be_update_ndn.bv_val ); @@ -480,6 +486,12 @@ int backend_destroy(void) if ( bd->be_replogfile != NULL ) { free( bd->be_replogfile ); } + if ( bd->be_replica_argsfile ) { + ch_free( bd->be_replica_argsfile ); + } + if ( bd->be_replica_pidfile ) { + ch_free( bd->be_replica_pidfile ); + } assert( bd->be_replica == NULL ); } diff --git a/servers/slapd/backover.c b/servers/slapd/backover.c index 0aa4a72be9..68415383c3 100644 --- a/servers/slapd/backover.c +++ b/servers/slapd/backover.c @@ -890,7 +890,7 @@ overlay_register_control( BackendDB *be, const char *oid ) return -1; } - if ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_GLOBAL_OVERLAY ) { + if ( SLAP_ISGLOBALOVERLAY( be ) ) { BackendDB *bd; /* add to all backends... */ diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index a080eb992b..c500b9971f 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -1820,10 +1820,11 @@ config_suffix(ConfigArgs *c) int i = c->valx; ch_free( c->be->be_suffix[i].bv_val ); ch_free( c->be->be_nsuffix[i].bv_val ); - for (; c->be->be_suffix[i].bv_val; i++) { + do { c->be->be_suffix[i] = c->be->be_suffix[i+1]; c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1]; - } + i++; + } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) ); } return 0; } diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 2f8cd60f4c..8f169ce478 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -237,20 +237,20 @@ int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) { { iarg = 0; } else { - snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value, ignored", + snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] ); - Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", + Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 ); - return(0); + return(ARG_BAD_CONF); } break; } j = (arg_type & ARG_NONZERO) ? 1 : 0; if(iarg < j && larg < j && barg < j ) { larg = larg ? larg : (barg ? barg : iarg); - snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value, ignored", + snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] ); - Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", + Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 ); return(ARG_BAD_CONF); } @@ -805,20 +805,29 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft) rc = (*c->be->be_config)(c->be, c->fname, c->lineno, c->argc, c->argv); } - if ( rc ) { - switch(rc) { - case SLAP_CONF_UNKNOWN: - Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: " - "unknown directive <%s> inside backend database " - "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n", - c->log, *c->argv, 0); + if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) ) { + /* global overlays may need + * definitions inside other databases... + */ + rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv); + } + + switch ( rc ) { + case 0: + break; + + case SLAP_CONF_UNKNOWN: + Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: " + "unknown directive <%s> inside backend database " + "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n", + c->log, *c->argv, 0); #ifndef SLAPD_CONF_UNKNOWN_BAILOUT - continue; + break; #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */ - default: - rc = 1; - goto done; - } + + default: + rc = 1; + goto done; } } else if ( frontendDB->be_config ) { @@ -831,8 +840,9 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft) SLAPD_CONF_UNKNOWN_IGNORED ".\n", c->log, *c->argv, 0); #ifndef SLAPD_CONF_UNKNOWN_BAILOUT - continue; + break; #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */ + default: rc = 1; goto done; diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 078505cd22..2eb56d42ab 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -161,7 +161,7 @@ fe_op_delete( Operation *op, SlapReply *rs ) int repl_user = be_isupdate( op ); #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#endif +#endif /* ! SLAPD_MULTIMASTER */ { struct berval org_req_dn = BER_BVNULL; struct berval org_req_ndn = BER_BVNULL; @@ -174,7 +174,7 @@ fe_op_delete( Operation *op, SlapReply *rs ) #ifdef SLAPD_MULTIMASTER if ( !op->o_bd->be_update_ndn.bv_len || !repl_user ) -#endif +#endif /* SLAPD_MULTIMASTER */ { cb.sc_next = op->o_callback; op->o_callback = &cb; @@ -234,7 +234,7 @@ fe_op_delete( Operation *op, SlapReply *rs ) LDAP_UNWILLING_TO_PERFORM, "shadow context; no update referral" ); } -#endif +#endif /* ! SLAPD_MULTIMASTER */ } } else { diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 116dc3cb17..ff7669dca8 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -214,13 +214,11 @@ fe_op_modify( Operation *op, SlapReply *rs ) Modifications *tmp; #endif int manageDSAit; - Modifications *modlist = op->orm_modlist; - int increment = op->orm_increment; - BackendDB *op_be; + BackendDB *op_be; char textbuf[ SLAP_TEXT_BUFLEN ]; size_t textlen = sizeof( textbuf ); - if( BER_BVISEMPTY( &op->o_req_ndn ) ) { + if ( BER_BVISEMPTY( &op->o_req_ndn ) ) { Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 ); send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, @@ -238,7 +236,7 @@ fe_op_modify( Operation *op, SlapReply *rs ) #ifdef LDAP_DEBUG Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 ); - for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) { + for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) { Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n", tmp->sml_op == LDAP_MOD_ADD ? "add" : (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" : @@ -267,7 +265,7 @@ fe_op_modify( Operation *op, SlapReply *rs ) Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n", op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 ); - for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) { + for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) { if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) { Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n", op->o_log_prefix, abuf, 0, 0, 0 ); @@ -306,15 +304,20 @@ fe_op_modify( Operation *op, SlapReply *rs ) if ( op->o_bd == NULL ) { rs->sr_ref = referral_rewrite( default_referral, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); - if (!rs->sr_ref) rs->sr_ref = default_referral; + if ( !rs->sr_ref ) { + rs->sr_ref = default_referral; + } - if (rs->sr_ref != NULL ) { + if ( rs->sr_ref != NULL ) { rs->sr_err = LDAP_REFERRAL; op->o_bd = frontendDB; send_ldap_result( op, rs ); op->o_bd = NULL; - if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref ); + if ( rs->sr_ref != default_referral ) { + ber_bvarray_free( rs->sr_ref ); + } + } else { op->o_bd = frontendDB; send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, @@ -331,17 +334,17 @@ fe_op_modify( Operation *op, SlapReply *rs ) } /* check restrictions */ - if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) { + if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) { send_ldap_result( op, rs ); goto cleanup; } /* check for referrals */ - if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) { + if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) { goto cleanup; } - rs->sr_err = slap_mods_obsolete_check( op, modlist, + rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist, &rs->sr_text, textbuf, textlen ); if ( rs->sr_err != LDAP_SUCCESS ) { send_ldap_result( op, rs ); @@ -349,7 +352,7 @@ fe_op_modify( Operation *op, SlapReply *rs ) } /* check for modify/increment support */ - if( increment && !SLAP_INCREMENT( op->o_bd ) ) { + if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) { send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, "modify/increment not supported in context" ); } @@ -369,7 +372,7 @@ fe_op_modify( Operation *op, SlapReply *rs ) */ #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#endif +#endif /* ! SLAPD_MULTIMASTER */ { int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn ); slap_callback cb = { NULL, slap_replog_cb, NULL, NULL }; @@ -377,7 +380,7 @@ fe_op_modify( Operation *op, SlapReply *rs ) op->o_bd = op_be; if ( !update ) { - rs->sr_err = slap_mods_no_user_mod_check( op, modlist, + rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist, &rs->sr_text, textbuf, textlen ); if ( rs->sr_err != LDAP_SUCCESS ) { send_ldap_result( op, rs ); @@ -385,10 +388,9 @@ fe_op_modify( Operation *op, SlapReply *rs ) } } - op->orm_modlist = modlist; #ifdef SLAPD_MULTIMASTER if ( !repl_user ) -#endif +#endif /* SLAPD_MULTIMASTER */ { /* but multimaster slapd logs only the ones * not from a replicator user */ @@ -421,7 +423,7 @@ fe_op_modify( Operation *op, SlapReply *rs ) send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, "shadow context; no update referral" ); } -#endif +#endif /* ! SLAPD_MULTIMASTER */ } } else { send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, @@ -478,7 +480,9 @@ slap_mods_no_user_mod_check( size_t textlen ) { for ( ; ml != NULL; ml = ml->sml_next ) { - if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue; + if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) { + continue; + } if ( get_manageDIT( op ) ) { if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) { diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 97f4997826..39165a37b0 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -291,7 +291,7 @@ fe_op_modrdn( Operation *op, SlapReply *rs ) int repl_user = be_isupdate( op ); #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#endif +#endif /* ! SLAPD_MULTIMASTER */ { slap_callback cb = { NULL, slap_replog_cb, NULL, NULL }; @@ -299,7 +299,7 @@ fe_op_modrdn( Operation *op, SlapReply *rs ) #ifdef SLAPD_MULTIMASTER if ( !op->o_bd->be_update_ndn.bv_len || !repl_user ) -#endif +#endif /* SLAPD_MULTIMASTER */ { cb.sc_next = op->o_callback; op->o_callback = &cb; @@ -363,7 +363,7 @@ fe_op_modrdn( Operation *op, SlapReply *rs ) send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, "shadow context; no update referral" ); } -#endif +#endif /* ! SLAPD_MULTIMASTER */ } } else { send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, diff --git a/servers/slapd/referral.c b/servers/slapd/referral.c index ce3e4529f2..3403852859 100644 --- a/servers/slapd/referral.c +++ b/servers/slapd/referral.c @@ -153,6 +153,7 @@ int validate_global_referral( const char *url ) case LDAP_URL_ERR_BADSCHEME: /* not LDAP hence valid */ + Debug( LDAP_DEBUG_CONFIG, "referral \"%s\": not LDAP.\n", url, 0, 0 ); return 0; default: diff --git a/servers/slapd/repl.c b/servers/slapd/repl.c index 73b3c8ca96..96a982e38f 100644 --- a/servers/slapd/repl.c +++ b/servers/slapd/repl.c @@ -166,7 +166,7 @@ replog( Operation *op ) /* undef NO_LOG_WHEN_NO_REPLICAS */ #ifdef NO_LOG_WHEN_NO_REPLICAS int count = 0; -#endif +#endif /* NO_LOG_WHEN_NO_REPLICAS */ int subsets = 0; long now = slap_get_time(); char *replogfile; @@ -212,7 +212,7 @@ replog( Operation *op ) fprintf( fp, "replica: %s\n", op->o_bd->be_replica[i]->ri_host ); #ifdef NO_LOG_WHEN_NO_REPLICAS ++count; -#endif +#endif /* NO_LOG_WHEN_NO_REPLICAS */ } #ifdef NO_LOG_WHEN_NO_REPLICAS @@ -224,7 +224,7 @@ replog( Operation *op ) return; } -#endif +#endif /* NO_LOG_WHEN_NO_REPLICAS */ replog1( NULL, op, fp, now ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 330cd93cdd..34105c657d 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1741,6 +1741,7 @@ struct slap_backend_db { #define SLAP_NOLASTMOD(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_NOLASTMOD) #define SLAP_LASTMOD(be) (!SLAP_NOLASTMOD(be)) #define SLAP_ISOVERLAY(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_OVERLAY) +#define SLAP_ISGLOBALOVERLAY(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_GLOBAL_OVERLAY) #define SLAP_NO_SCHEMA_CHECK(be) \ (SLAP_DBFLAGS(be) & SLAP_DBFLAG_NO_SCHEMA_CHECK) #define SLAP_GLUE_INSTANCE(be) \ -- 2.39.5