From 6a5f29b60a1564a71ec34127a7effb28cafaec76 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sun, 19 Jan 2003 15:30:10 +0000 Subject: [PATCH] Use new SLAPI API for setting associated parameters associated with the Connection, Operation and Backend structures. Ensure that SLAPI_MODIFY_MODS is set to an array of LDAPMods. --- servers/slapd/add.c | 7 ++-- servers/slapd/backend.c | 4 +- servers/slapd/bind.c | 6 +-- servers/slapd/compare.c | 9 ++-- servers/slapd/delete.c | 9 ++-- servers/slapd/extended.c | 4 +- servers/slapd/modify.c | 91 +++++++++++++++++++++++++++++++++++++--- servers/slapd/modrdn.c | 9 ++-- servers/slapd/search.c | 9 ++-- 9 files changed, 111 insertions(+), 37 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 703fb508cb..46de08c935 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -226,13 +226,12 @@ do_add( Connection *conn, Operation *op ) } #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); slapi_pblock_set( pb, SLAPI_ADD_ENTRY, (void *)e ); slapi_pblock_set( pb, SLAPI_ADD_TARGET, (void *)dn.bv_val ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); - slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls ); rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_ADD_FN, pb ); if ( rc != 0 && rc != LDAP_OTHER ) { diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index f2568537d7..f38b8c7539 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -693,8 +693,8 @@ backend_unbind( Slapi_PBlock *pb = op->o_pb; #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); #endif /* defined( LDAP_SLAPI ) */ for ( i = 0; i < nbackends; i++ ) { diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index 7c078dc7bc..24de0218e8 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -531,9 +531,9 @@ do_bind( } #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val ); slapi_pblock_set( pb, SLAPI_BIND_METHOD, (void *)method ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index 0eba5c92d2..c1f3db3f9c 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -272,12 +272,11 @@ do_compare( suffix_alias( be, &ndn ); #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); - slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); + slapi_pblock_set( pb, SLAPI_COMPARE_TARGET, (void *)dn.bv_val ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); - slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls ); slapi_pblock_set( pb, SLAPI_COMPARE_TYPE, (void *)desc.bv_val ); slapi_pblock_set( pb, SLAPI_COMPARE_VALUE, (void *)&value ); diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 8b00c39b71..acab86bba6 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -158,12 +158,11 @@ do_delete( suffix_alias( be, &ndn ); #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); - slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); + slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); - slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls ); rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_DELETE_FN, pb ); if ( rc != 0 && rc != LDAP_OTHER ) { diff --git a/servers/slapd/extended.c b/servers/slapd/extended.c index fdc0c0fca7..481e22b962 100644 --- a/servers/slapd/extended.c +++ b/servers/slapd/extended.c @@ -267,13 +267,13 @@ do_extended( goto done; } - rc = slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); + rc = slapi_connection_set_pb( pb, conn ); if ( rc != LDAP_SUCCESS ) { rc = LDAP_OPERATIONS_ERROR; goto done; } - rc = slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op); + rc = slapi_operation_set_pb( pb, op ); if ( rc != LDAP_SUCCESS ) { rc = LDAP_OPERATIONS_ERROR; goto done; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 7cb5b6f452..4181101800 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -30,6 +30,11 @@ #include "slap.h" #include "slapi.h" +#ifdef LDAP_SLAPI +static LDAPMod **Modifications2LDAPMods (Modifications *modlist); +static void FreeLDAPMods (LDAPMod **); +#endif /* LDAP_SLAPI */ + int do_modify( Connection *conn, @@ -43,6 +48,9 @@ do_modify( ber_len_t len; Modifications *modlist = NULL; Modifications **modtail = &modlist; +#ifdef LDAP_SLAPI + LDAPMod **modv = NULL; +#endif #ifdef LDAP_DEBUG Modifications *tmp; #endif @@ -50,7 +58,6 @@ do_modify( int rc; const char *text; int manageDSAit; - Slapi_PBlock *pb = op->o_pb; #ifdef NEW_LOGGING @@ -332,12 +339,13 @@ do_modify( suffix_alias( be, &ndn ); #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); - slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val ); - slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); + slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn.bv_val ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); + modv = Modifications2LDAPMods(modlist); + slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv); rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_MODIFY_FN, pb ); if ( rc != 0 && rc != LDAP_OTHER ) { @@ -458,6 +466,8 @@ cleanup: free( ndn.bv_val ); if ( modlist != NULL ) slap_mods_free( modlist ); + if ( modv != NULL ) + FreeLDAPMods( modv ); return rc; } @@ -752,3 +762,72 @@ int slap_mods_opattrs( *modtail = NULL; return LDAP_SUCCESS; } + +#ifdef LDAP_SLAPI +/* + * Synthesise an LDAPMod array from a Modifications list to pass + * to SLAPI. + */ +static LDAPMod **Modifications2LDAPMods(Modifications *modlist) +{ + LDAPMod *mods, **modv; + int i, j; + Modifications *ml; + + /* based on back-ldap/modify.c */ + for (i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next) + ; + + mods = (LDAPMod *)ch_malloc(i * sizeof(LDAPMod)); + if (mods == NULL) { + return NULL; + } + + modv = (LDAPMod **)ch_malloc((i + 1) * sizeof(LDAPMod *)); + if (modv == NULL) { + ch_free(mods); + return NULL; + } + + for (i = 0, ml = modlist; ml != NULL; ml = ml->sml_next) { + if (ml->sml_desc->ad_type->sat_no_user_mod) { + continue; + } + modv[i] = &mods[i]; + mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES; + mods[i].mod_type = ml->sml_desc->ad_cname.bv_val; + if (ml->sml_bvalues != NULL) { + for (j = 0; ml->sml_bvalues[j].bv_val != NULL; j++) + ; + mods[i].mod_bvalues = (struct berval **)ch_malloc((j + 1) * + sizeof(struct berval *)); + for (j = 0; ml->sml_bvalues[j].bv_val != NULL; j++) + mods[i].mod_bvalues[j] = &ml->sml_bvalues[j]; + } else { + mods[i].mod_bvalues = NULL; + } + i++; + } + modv[i] = NULL; + + return modv; +} + +/* + * Free a contiguous block of LDAP modifications. + */ +void FreeLDAPMods(LDAPMod **modv) +{ + int i; + LDAPMod *mods; + + mods = modv[0]; + + for (i = 0; modv[i] != NULL; i++) { + ch_free(modv[i]->mod_bvalues); + } + ch_free(mods); + ch_free(modv); +} +#endif /* LDAP_SLAPI */ + diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 7e865a584d..1238050cb1 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -329,15 +329,14 @@ do_modrdn( suffix_alias( be, &ndn ); #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); - slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); + slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)dn.bv_val ); slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn.bv_val ); slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)newSuperior.bv_val ); slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)deloldrdn ); - slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_MODRDN_FN, pb ); diff --git a/servers/slapd/search.c b/servers/slapd/search.c index d03975634d..8a1cac660b 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -340,10 +340,10 @@ do_search( suffix_alias( be, &nbase ); #if defined( LDAP_SLAPI ) - slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); - slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); - slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op ); - slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)base.bv_val ); + slapi_backend_set_pb( pb, be ); + slapi_connection_set_pb( pb, conn ); + slapi_operation_set_pb( pb, op ); + slapi_pblock_set( pb, SLAPI_SEARCH_TARGET, (void *)base.bv_val ); slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE, (void *)scope ); slapi_pblock_set( pb, SLAPI_SEARCH_DEREF, (void *)deref ); slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT, (void *)sizelimit ); @@ -351,7 +351,6 @@ do_search( slapi_pblock_set( pb, SLAPI_SEARCH_FILTER, (void *)filter ); slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)fstr.bv_val ); slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly ); - slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) ); rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_SEARCH_FN, pb ); -- 2.39.5