From: Pierangelo Masarati Date: Sat, 27 Nov 2004 15:08:24 +0000 (+0000) Subject: make unregistered known controls show up as undefined; move LDAPsync cid to frontend... X-Git-Tag: OPENLDAP_REL_ENG_2_3_0ALPHA~196 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6f182a754712cdecc7e824bc6b64465de31e864a;p=openldap make unregistered known controls show up as undefined; move LDAPsync cid to frontend; some cleanup --- diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index dbefc8c54e..5496811ec1 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -47,11 +47,6 @@ sql_back_initialize( Debug( LDAP_DEBUG_TRACE,"==>sql_back_initialize()\n", 0, 0, 0 ); - bi->bi_open = 0; - bi->bi_config = 0; - bi->bi_close = 0; - bi->bi_destroy = 0; - bi->bi_db_init = backsql_db_init; bi->bi_db_config = backsql_db_config; bi->bi_db_open = backsql_db_open; @@ -78,7 +73,6 @@ sql_back_initialize( return 0; } - int backsql_destroy( BackendInfo *bi ) diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 09a4f3fc57..fff39dc3c1 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -676,14 +676,12 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) * TODO: introduce appropriate entryCSN filtering * to support syncrepl as producer... */ -#if 0 /* wait until syncprov.c freezes */ - if ( bsi->bsi_op->o_sync_mode & SLAP_SYNC_PERSIST ) { + if ( bsi->bsi_op->o_sync ) { /* unsupported at present... */ bsi->bsi_status = LDAP_OTHER; rc = -1; goto done; } -#endif } else if ( ad == slap_schema.si_ad_hasSubordinates || ad == NULL ) { diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index e43c685794..9b98a91190 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -74,8 +74,19 @@ static LDAP_SLIST_HEAD(ControlsList, slap_control) controls_list /* * all known request control OIDs should be added to this list */ +/* + * NOTE: initialize num_known_controls to 1 so that cid = 0 always + * addresses an undefined control; this allows to safely test for + * well known controls even if they are not registered, e.g. if + * they get moved to modules. An example is sc_LDAPsync, which + * is implemented in the syncprov overlay and thus, if configured + * as dynamic module, may not be registered. One side effect is that + * slap_known_controls[0] == NULL, so it should always be used + * starting from 1. + * FIXME: should we define the "undefined control" oid? + */ char *slap_known_controls[SLAP_MAX_CIDS+1]; -static int num_known_controls; +static int num_known_controls = 1; static char *proxy_authz_extops[] = { LDAP_EXOP_MODIFY_PASSWD, @@ -169,6 +180,7 @@ register_supported_control(const char *controloid, int *controlcid) { struct slap_control *sc; + int i; if ( num_known_controls >= SLAP_MAX_CIDS ) { Debug( LDAP_DEBUG_ANY, "Too many controls registered." @@ -179,6 +191,16 @@ register_supported_control(const char *controloid, if ( controloid == NULL ) return LDAP_PARAM_ERROR; + /* sanity check - should never happen */ + for ( i = 1; slap_known_controls[ i ]; i++ ) { + if ( strcmp( controloid, slap_known_controls[ i ] ) == 0 ) { + Debug( LDAP_DEBUG_ANY, + "Control %s already registered.\n", + controloid, 0, 0 ); + return LDAP_PARAM_ERROR; + } + } + sc = (struct slap_control *)SLAP_MALLOC( sizeof( *sc ) ); if ( sc == NULL ) return LDAP_NO_MEMORY; @@ -353,7 +375,7 @@ slap_find_control_id( const char *oid, int *cid ) { - slap_control *ctrl = find_ctrl( oid ); + struct slap_control *ctrl = find_ctrl( oid ); if ( ctrl ) { if ( cid ) *cid = ctrl->sc_cid; return LDAP_SUCCESS; diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 68af511759..7cd42efb29 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -65,17 +65,17 @@ typedef struct syncops { ldap_pvt_thread_mutex_t s_mutex; } syncops; -static int sync_cid; - /* A received sync control */ typedef struct sync_control { struct sync_cookie sr_state; int sr_rhint; } sync_control; +#if 0 /* moved back to slap.h */ +#define o_sync o_ctrlflag[slap_cids.sc_LDAPsync] +#endif /* o_sync_mode uses data bits of o_sync */ -#define o_sync o_ctrlflag[sync_cid] -#define o_sync_mode o_ctrlflag[sync_cid] +#define o_sync_mode o_ctrlflag[slap_cids.sc_LDAPsync] #define SLAP_SYNC_NONE (LDAP_SYNC_NONE<o_controls[sync_cid]; + sync_control *srs = op->o_controls[slap_cids.sc_LDAPsync]; if ( srs->sr_state.ctxcsn->bv_len >= LDAP_LUTIL_CSNSTR_BUFSIZE ) { return LDAP_OTHER; @@ -700,9 +700,7 @@ syncprov_sendresp( Operation *op, opcookie *opc, syncops *so, Entry *e, int mode e_uuid.e_nname = opc->sndn; rs.sr_entry = &e_uuid; if ( opc->sreference ) { - struct berval bv; - bv.bv_val = NULL; - bv.bv_len = 0; + struct berval bv = BER_BVNULL; rs.sr_ref = &bv; send_search_reference( &sop, &rs ); } else { @@ -977,7 +975,7 @@ syncprov_op_response( Operation *op, SlapReply *rs ) cbuf[0] = '\0'; ldap_pvt_thread_mutex_lock( &si->si_csn_mutex ); slap_get_commit_csn( op, &maxcsn ); - if ( maxcsn.bv_val ) { + if ( !BER_BVISNULL( &maxcsn ) ) { strcpy( cbuf, maxcsn.bv_val ); if ( ber_bvcmp( &maxcsn, &si->si_ctxcsn ) > 0 ) { strcpy( si->si_ctxcsnbuf, cbuf ); @@ -1056,7 +1054,7 @@ syncprov_op_compare( Operation *op, SlapReply *rs ) e.e_name = op->o_bd->be_suffix[0]; e.e_nname = op->o_bd->be_nsuffix[0]; - bv[1].bv_val = NULL; + BER_BVZERO( &bv[1] ); bv[0] = si->si_ctxcsn; a.a_desc = slap_schema.si_ad_contextCSN; @@ -1202,7 +1200,7 @@ syncprov_detach_op( Operation *op, syncops *so ) char *ptr; /* count the search attrs */ - for (i=0; op->ors_attrs && op->ors_attrs[i].an_name.bv_val; i++) { + for (i=0; op->ors_attrs && !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++) { alen += op->ors_attrs[i].an_name.bv_len + 1; } /* Make a new copy of the operation */ @@ -1219,13 +1217,12 @@ syncprov_detach_op( Operation *op, syncops *so ) if ( i ) { op2->ors_attrs = (AttributeName *)(op2->o_hdr + 1); ptr = (char *)(op2->ors_attrs+i+1); - for (i=0; op->ors_attrs[i].an_name.bv_val; i++) { + for (i=0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++) { op2->ors_attrs[i] = op->ors_attrs[i]; op2->ors_attrs[i].an_name.bv_val = ptr; ptr = lutil_strcopy( ptr, op->ors_attrs[i].an_name.bv_val ) + 1; } - op2->ors_attrs[i].an_name.bv_val = NULL; - op2->ors_attrs[i].an_name.bv_len = 0; + BER_BVZERO( &op2->ors_attrs[i].an_name ); } else { ptr = (char *)(op2->o_hdr + 1); } @@ -1257,7 +1254,7 @@ syncprov_search_response( Operation *op, SlapReply *rs ) searchstate *ss = op->o_callback->sc_private; slap_overinst *on = ss->ss_on; syncprov_info_t *si = on->on_bi.bi_private; - sync_control *srs = op->o_controls[sync_cid]; + sync_control *srs = op->o_controls[slap_cids.sc_LDAPsync]; if ( rs->sr_type == REP_SEARCH || rs->sr_type == REP_SEARCHREF ) { int i; @@ -1366,7 +1363,7 @@ syncprov_op_search( Operation *op, SlapReply *rs ) return rs->sr_err; } - srs = op->o_controls[sync_cid]; + srs = op->o_controls[slap_cids.sc_LDAPsync]; /* If this is a persistent search, set it up right away */ if ( op->o_sync_mode & SLAP_SYNC_PERSIST ) { @@ -1738,7 +1735,7 @@ static int syncprov_parseCtrl ( return LDAP_PROTOCOL_ERROR; } - if ( ctrl->ldctl_value.bv_len == 0 ) { + if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) { rs->sr_text = "Sync control value is empty (or absent)"; return LDAP_PROTOCOL_ERROR; } @@ -1803,7 +1800,7 @@ static int syncprov_parseCtrl ( slap_parse_sync_cookie( &sr->sr_state ); } - op->o_controls[sync_cid] = sr; + op->o_controls[slap_cids.sc_LDAPsync] = sr; (void) ber_free( ber, 1 ); @@ -1830,7 +1827,7 @@ syncprov_init() rc = register_supported_control( LDAP_CONTROL_SYNC, SLAP_CTRL_HIDE|SLAP_CTRL_SEARCH, NULL, - syncprov_parseCtrl, &sync_cid ); + syncprov_parseCtrl, &slap_cids.sc_LDAPsync ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "Failed to register control %d\n", rc ); return rc; diff --git a/servers/slapd/sl_malloc.c b/servers/slapd/sl_malloc.c index ec8393a8a7..ae15818888 100644 --- a/servers/slapd/sl_malloc.c +++ b/servers/slapd/sl_malloc.c @@ -435,7 +435,7 @@ slap_sl_free(void *ptr, void *ctx) unsigned long diff; int i, k, inserted = 0; - Debug( LDAP_DEBUG_ANY, "slap_sl_free \n", 0, 0, 0); + Debug( LDAP_DEBUG_ANY, "==> slap_sl_free \n", 0, 0, 0); if (!sh || ptr < sh->sh_base || ptr >= sh->sh_end) { ber_memfree_x(ptr, NULL); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 8c25d43e80..d9186d040c 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -2131,6 +2131,7 @@ struct slap_control_ids { int sc_treeDelete; int sc_searchOptions; int sc_subentries; + int sc_LDAPsync; }; /* @@ -2330,6 +2331,8 @@ typedef struct slap_op { #define o_pagedresults o_ctrlflag[slap_cids.sc_pagedResults] #define o_pagedresults_state o_controls[slap_cids.sc_pagedResults] +#define o_sync o_ctrlflag[slap_cids.sc_LDAPsync] + #define get_pagedresults(op) ((int)(op)->o_pagedresults) #ifdef BDB_PSEARCH