Back to index

openldap  2.4.31
slapi_pblock.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 2002-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 1997,2002-2003 IBM Corporation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by IBM Corporation for use in
00018  * IBM products and subsequently ported to OpenLDAP Software by
00019  * Steve Omrani.  Additional significant contributors include:
00020  *   Luke Howard
00021  */
00022 
00023 #include "portable.h"
00024 #include <slap.h>
00025 #include <slapi.h>
00026 
00027 #ifdef LDAP_SLAPI
00028 
00029 /* some parameters require a valid connection and operation */
00030 #define PBLOCK_LOCK_CONN( _pb )           do { \
00031               ldap_pvt_thread_mutex_lock( &(_pb)->pb_conn->c_mutex ); \
00032        } while (0)
00033 
00034 #define PBLOCK_UNLOCK_CONN( _pb )  do { \
00035               ldap_pvt_thread_mutex_unlock( &(_pb)->pb_conn->c_mutex ); \
00036        } while (0)
00037 
00038 /* some parameters are only settable for internal operations */
00039 #define PBLOCK_VALIDATE_IS_INTOP( _pb )   do { if ( (_pb)->pb_intop == 0 ) break; } while ( 0 )
00040 
00041 static slapi_pblock_class_t 
00042 pblock_get_param_class( int param ) 
00043 {
00044        switch ( param ) {
00045        case SLAPI_PLUGIN_TYPE:
00046        case SLAPI_PLUGIN_ARGC:
00047        case SLAPI_PLUGIN_OPRETURN:
00048        case SLAPI_PLUGIN_INTOP_RESULT:
00049        case SLAPI_CONFIG_LINENO:
00050        case SLAPI_CONFIG_ARGC:
00051        case SLAPI_BIND_METHOD:
00052        case SLAPI_MODRDN_DELOLDRDN:
00053        case SLAPI_SEARCH_SCOPE:
00054        case SLAPI_SEARCH_DEREF:
00055        case SLAPI_SEARCH_SIZELIMIT:
00056        case SLAPI_SEARCH_TIMELIMIT:
00057        case SLAPI_SEARCH_ATTRSONLY:
00058        case SLAPI_NENTRIES:
00059        case SLAPI_CHANGENUMBER:
00060        case SLAPI_DBSIZE:
00061        case SLAPI_REQUESTOR_ISROOT:
00062        case SLAPI_BE_READONLY:
00063        case SLAPI_BE_LASTMOD:
00064        case SLAPI_DB2LDIF_PRINTKEY:
00065        case SLAPI_LDIF2DB_REMOVEDUPVALS:
00066        case SLAPI_MANAGEDSAIT:
00067        case SLAPI_X_RELAX:
00068        case SLAPI_X_OPERATION_NO_SCHEMA_CHECK:
00069        case SLAPI_IS_REPLICATED_OPERATION:
00070        case SLAPI_X_CONN_IS_UDP:
00071        case SLAPI_X_CONN_SSF:
00072        case SLAPI_RESULT_CODE:
00073        case SLAPI_LOG_OPERATION:
00074        case SLAPI_IS_INTERNAL_OPERATION:
00075               return PBLOCK_CLASS_INTEGER;
00076               break;
00077 
00078        case SLAPI_CONN_ID:
00079        case SLAPI_OPERATION_ID:
00080        case SLAPI_OPINITIATED_TIME:
00081        case SLAPI_ABANDON_MSGID:
00082        case SLAPI_X_OPERATION_DELETE_GLUE_PARENT:
00083        case SLAPI_OPERATION_MSGID:
00084               return PBLOCK_CLASS_LONG_INTEGER;
00085               break;
00086 
00087        case SLAPI_PLUGIN_DESTROY_FN:
00088        case SLAPI_PLUGIN_DB_BIND_FN:
00089        case SLAPI_PLUGIN_DB_UNBIND_FN:
00090        case SLAPI_PLUGIN_DB_SEARCH_FN:
00091        case SLAPI_PLUGIN_DB_COMPARE_FN:
00092        case SLAPI_PLUGIN_DB_MODIFY_FN:
00093        case SLAPI_PLUGIN_DB_MODRDN_FN:
00094        case SLAPI_PLUGIN_DB_ADD_FN:
00095        case SLAPI_PLUGIN_DB_DELETE_FN:
00096        case SLAPI_PLUGIN_DB_ABANDON_FN:
00097        case SLAPI_PLUGIN_DB_CONFIG_FN:
00098        case SLAPI_PLUGIN_CLOSE_FN:
00099        case SLAPI_PLUGIN_DB_FLUSH_FN:
00100        case SLAPI_PLUGIN_START_FN:
00101        case SLAPI_PLUGIN_DB_SEQ_FN:
00102        case SLAPI_PLUGIN_DB_ENTRY_FN:
00103        case SLAPI_PLUGIN_DB_REFERRAL_FN:
00104        case SLAPI_PLUGIN_DB_RESULT_FN:
00105        case SLAPI_PLUGIN_DB_LDIF2DB_FN:
00106        case SLAPI_PLUGIN_DB_DB2LDIF_FN:
00107        case SLAPI_PLUGIN_DB_BEGIN_FN:
00108        case SLAPI_PLUGIN_DB_COMMIT_FN:
00109        case SLAPI_PLUGIN_DB_ABORT_FN:
00110        case SLAPI_PLUGIN_DB_ARCHIVE2DB_FN:
00111        case SLAPI_PLUGIN_DB_DB2ARCHIVE_FN:
00112        case SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_FN:
00113        case SLAPI_PLUGIN_DB_FREE_RESULT_SET_FN:
00114        case SLAPI_PLUGIN_DB_SIZE_FN:
00115        case SLAPI_PLUGIN_DB_TEST_FN:
00116        case SLAPI_PLUGIN_DB_NO_ACL:
00117        case SLAPI_PLUGIN_EXT_OP_FN:
00118        case SLAPI_PLUGIN_EXT_OP_OIDLIST:
00119        case SLAPI_PLUGIN_PRE_BIND_FN:
00120        case SLAPI_PLUGIN_PRE_UNBIND_FN:
00121        case SLAPI_PLUGIN_PRE_SEARCH_FN:
00122        case SLAPI_PLUGIN_PRE_COMPARE_FN:
00123        case SLAPI_PLUGIN_PRE_MODIFY_FN:
00124        case SLAPI_PLUGIN_PRE_MODRDN_FN:
00125        case SLAPI_PLUGIN_PRE_ADD_FN:
00126        case SLAPI_PLUGIN_PRE_DELETE_FN:
00127        case SLAPI_PLUGIN_PRE_ABANDON_FN:
00128        case SLAPI_PLUGIN_PRE_ENTRY_FN:
00129        case SLAPI_PLUGIN_PRE_REFERRAL_FN:
00130        case SLAPI_PLUGIN_PRE_RESULT_FN:
00131        case SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN:
00132        case SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN:
00133        case SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN:
00134        case SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN:
00135        case SLAPI_PLUGIN_BE_PRE_ADD_FN:
00136        case SLAPI_PLUGIN_BE_PRE_MODIFY_FN:
00137        case SLAPI_PLUGIN_BE_PRE_MODRDN_FN:
00138        case SLAPI_PLUGIN_BE_PRE_DELETE_FN:
00139        case SLAPI_PLUGIN_POST_BIND_FN:
00140        case SLAPI_PLUGIN_POST_UNBIND_FN:
00141        case SLAPI_PLUGIN_POST_SEARCH_FN:
00142        case SLAPI_PLUGIN_POST_COMPARE_FN:
00143        case SLAPI_PLUGIN_POST_MODIFY_FN:
00144        case SLAPI_PLUGIN_POST_MODRDN_FN:
00145        case SLAPI_PLUGIN_POST_ADD_FN:
00146        case SLAPI_PLUGIN_POST_DELETE_FN:
00147        case SLAPI_PLUGIN_POST_ABANDON_FN:
00148        case SLAPI_PLUGIN_POST_ENTRY_FN:
00149        case SLAPI_PLUGIN_POST_REFERRAL_FN:
00150        case SLAPI_PLUGIN_POST_RESULT_FN:
00151        case SLAPI_PLUGIN_INTERNAL_POST_ADD_FN:
00152        case SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN:
00153        case SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN:
00154        case SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN:
00155        case SLAPI_PLUGIN_BE_POST_ADD_FN:
00156        case SLAPI_PLUGIN_BE_POST_MODIFY_FN:
00157        case SLAPI_PLUGIN_BE_POST_MODRDN_FN:
00158        case SLAPI_PLUGIN_BE_POST_DELETE_FN:
00159        case SLAPI_PLUGIN_MR_FILTER_CREATE_FN:
00160        case SLAPI_PLUGIN_MR_INDEXER_CREATE_FN:
00161        case SLAPI_PLUGIN_MR_FILTER_MATCH_FN:
00162        case SLAPI_PLUGIN_MR_FILTER_INDEX_FN:
00163        case SLAPI_PLUGIN_MR_FILTER_RESET_FN:
00164        case SLAPI_PLUGIN_MR_INDEX_FN:
00165        case SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN:
00166        case SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN:
00167        case SLAPI_PLUGIN_ACL_ALLOW_ACCESS:
00168        case SLAPI_X_PLUGIN_PRE_GROUP_FN:
00169        case SLAPI_X_PLUGIN_POST_GROUP_FN:
00170        case SLAPI_PLUGIN_AUDIT_FN:
00171        case SLAPI_PLUGIN_INTERNAL_PRE_BIND_FN:
00172        case SLAPI_PLUGIN_INTERNAL_PRE_UNBIND_FN:
00173        case SLAPI_PLUGIN_INTERNAL_PRE_SEARCH_FN:
00174        case SLAPI_PLUGIN_INTERNAL_PRE_COMPARE_FN:
00175        case SLAPI_PLUGIN_INTERNAL_PRE_ABANDON_FN:
00176        case SLAPI_PLUGIN_INTERNAL_POST_BIND_FN:
00177        case SLAPI_PLUGIN_INTERNAL_POST_UNBIND_FN:
00178        case SLAPI_PLUGIN_INTERNAL_POST_SEARCH_FN:
00179        case SLAPI_PLUGIN_INTERNAL_POST_COMPARE_FN:
00180        case SLAPI_PLUGIN_INTERNAL_POST_ABANDON_FN:
00181               return PBLOCK_CLASS_FUNCTION_POINTER;
00182               break;
00183 
00184        case SLAPI_BACKEND:
00185        case SLAPI_CONNECTION:
00186        case SLAPI_OPERATION:
00187        case SLAPI_OPERATION_PARAMETERS:
00188        case SLAPI_OPERATION_TYPE:
00189        case SLAPI_OPERATION_AUTHTYPE:
00190        case SLAPI_BE_MONITORDN:
00191        case SLAPI_BE_TYPE:
00192        case SLAPI_REQUESTOR_DN:
00193        case SLAPI_CONN_DN:
00194        case SLAPI_CONN_CLIENTIP:
00195        case SLAPI_CONN_SERVERIP:
00196        case SLAPI_CONN_AUTHTYPE:
00197        case SLAPI_CONN_AUTHMETHOD:
00198        case SLAPI_CONN_CERT:
00199        case SLAPI_X_CONN_CLIENTPATH:
00200        case SLAPI_X_CONN_SERVERPATH:
00201        case SLAPI_X_CONN_SASL_CONTEXT:
00202        case SLAPI_X_CONFIG_ARGV:
00203        case SLAPI_X_INTOP_FLAGS:
00204        case SLAPI_X_INTOP_RESULT_CALLBACK:
00205        case SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK:
00206        case SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK:
00207        case SLAPI_X_INTOP_CALLBACK_DATA:
00208        case SLAPI_PLUGIN_MR_OID:
00209        case SLAPI_PLUGIN_MR_TYPE:
00210        case SLAPI_PLUGIN_MR_VALUE:
00211        case SLAPI_PLUGIN_MR_VALUES:
00212        case SLAPI_PLUGIN_MR_KEYS:
00213        case SLAPI_PLUGIN:
00214        case SLAPI_PLUGIN_PRIVATE:
00215        case SLAPI_PLUGIN_ARGV:
00216        case SLAPI_PLUGIN_OBJECT:
00217        case SLAPI_PLUGIN_DESCRIPTION:
00218        case SLAPI_PLUGIN_IDENTITY:
00219        case SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES:
00220        case SLAPI_PLUGIN_INTOP_SEARCH_REFERRALS:
00221        case SLAPI_PLUGIN_MR_FILTER_REUSABLE:
00222        case SLAPI_PLUGIN_MR_QUERY_OPERATOR:
00223        case SLAPI_PLUGIN_MR_USAGE:
00224        case SLAPI_OP_LESS:
00225        case SLAPI_OP_LESS_OR_EQUAL:
00226        case SLAPI_PLUGIN_MR_USAGE_INDEX:
00227        case SLAPI_PLUGIN_SYNTAX_FILTER_AVA:
00228        case SLAPI_PLUGIN_SYNTAX_FILTER_SUB:
00229        case SLAPI_PLUGIN_SYNTAX_VALUES2KEYS:
00230        case SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA:
00231        case SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB:
00232        case SLAPI_PLUGIN_SYNTAX_NAMES:
00233        case SLAPI_PLUGIN_SYNTAX_OID:
00234        case SLAPI_PLUGIN_SYNTAX_FLAGS:
00235        case SLAPI_PLUGIN_SYNTAX_COMPARE:
00236        case SLAPI_CONFIG_FILENAME:
00237        case SLAPI_CONFIG_ARGV:
00238        case SLAPI_TARGET_ADDRESS:
00239        case SLAPI_TARGET_UNIQUEID:
00240        case SLAPI_TARGET_DN:
00241        case SLAPI_REQCONTROLS:
00242        case SLAPI_ENTRY_PRE_OP:
00243        case SLAPI_ENTRY_POST_OP:
00244        case SLAPI_RESCONTROLS:
00245        case SLAPI_X_OLD_RESCONTROLS:
00246        case SLAPI_ADD_RESCONTROL:
00247        case SLAPI_CONTROLS_ARG:
00248        case SLAPI_ADD_ENTRY:
00249        case SLAPI_ADD_EXISTING_DN_ENTRY:
00250        case SLAPI_ADD_PARENT_ENTRY:
00251        case SLAPI_ADD_PARENT_UNIQUEID:
00252        case SLAPI_ADD_EXISTING_UNIQUEID_ENTRY:
00253        case SLAPI_BIND_CREDENTIALS:
00254        case SLAPI_BIND_SASLMECHANISM:
00255        case SLAPI_BIND_RET_SASLCREDS:
00256        case SLAPI_COMPARE_TYPE:
00257        case SLAPI_COMPARE_VALUE:
00258        case SLAPI_MODIFY_MODS:
00259        case SLAPI_MODRDN_NEWRDN:
00260        case SLAPI_MODRDN_NEWSUPERIOR:
00261        case SLAPI_MODRDN_PARENT_ENTRY:
00262        case SLAPI_MODRDN_NEWPARENT_ENTRY:
00263        case SLAPI_MODRDN_TARGET_ENTRY:
00264        case SLAPI_MODRDN_NEWSUPERIOR_ADDRESS:
00265        case SLAPI_SEARCH_FILTER:
00266        case SLAPI_SEARCH_STRFILTER:
00267        case SLAPI_SEARCH_ATTRS:
00268        case SLAPI_SEQ_TYPE:
00269        case SLAPI_SEQ_ATTRNAME:
00270        case SLAPI_SEQ_VAL:
00271        case SLAPI_EXT_OP_REQ_OID:
00272        case SLAPI_EXT_OP_REQ_VALUE:
00273        case SLAPI_EXT_OP_RET_OID:
00274        case SLAPI_EXT_OP_RET_VALUE:
00275        case SLAPI_MR_FILTER_ENTRY:
00276        case SLAPI_MR_FILTER_TYPE:
00277        case SLAPI_MR_FILTER_VALUE:
00278        case SLAPI_MR_FILTER_OID:
00279        case SLAPI_MR_FILTER_DNATTRS:
00280        case SLAPI_LDIF2DB_FILE:
00281        case SLAPI_PARENT_TXN:
00282        case SLAPI_TXN:
00283        case SLAPI_SEARCH_RESULT_SET:
00284        case SLAPI_SEARCH_RESULT_ENTRY:
00285        case SLAPI_SEARCH_REFERRALS:
00286        case SLAPI_RESULT_TEXT:
00287        case SLAPI_RESULT_MATCHED:
00288        case SLAPI_X_GROUP_ENTRY:
00289        case SLAPI_X_GROUP_ATTRIBUTE:
00290        case SLAPI_X_GROUP_OPERATION_DN:
00291        case SLAPI_X_GROUP_TARGET_ENTRY:
00292        case SLAPI_X_ADD_STRUCTURAL_CLASS:
00293        case SLAPI_PLUGIN_AUDIT_DATA:
00294        case SLAPI_IBM_PBLOCK:
00295        case SLAPI_PLUGIN_VERSION:
00296               return PBLOCK_CLASS_POINTER;
00297               break;
00298        default:
00299               break;
00300        }
00301 
00302        return PBLOCK_CLASS_INVALID;
00303 }
00304 
00305 static void
00306 pblock_lock( Slapi_PBlock *pb )
00307 {
00308        ldap_pvt_thread_mutex_lock( &pb->pb_mutex );
00309 }
00310 
00311 static void
00312 pblock_unlock( Slapi_PBlock *pb )
00313 {
00314        ldap_pvt_thread_mutex_unlock( &pb->pb_mutex );
00315 }
00316 
00317 static int 
00318 pblock_get_default( Slapi_PBlock *pb, int param, void **value ) 
00319 {      
00320        int i;
00321        slapi_pblock_class_t pbClass;
00322 
00323        pbClass = pblock_get_param_class( param );
00324        if ( pbClass == PBLOCK_CLASS_INVALID ) {
00325               return PBLOCK_ERROR;
00326        }
00327        
00328        switch ( pbClass ) {
00329        case PBLOCK_CLASS_INTEGER:
00330               *((int *)value) = 0;
00331               break;
00332        case PBLOCK_CLASS_LONG_INTEGER:
00333               *((long *)value) = 0L;
00334               break;
00335        case PBLOCK_CLASS_POINTER:
00336        case PBLOCK_CLASS_FUNCTION_POINTER:
00337               *value = NULL;
00338               break;
00339        case PBLOCK_CLASS_INVALID:
00340               return PBLOCK_ERROR;
00341        }
00342 
00343        for ( i = 0; i < pb->pb_nParams; i++ ) {
00344               if ( pb->pb_params[i] == param ) {
00345                      switch ( pbClass ) {
00346                      case PBLOCK_CLASS_INTEGER:
00347                             *((int *)value) = pb->pb_values[i].pv_integer;
00348                             break;
00349                      case PBLOCK_CLASS_LONG_INTEGER:
00350                             *((long *)value) = pb->pb_values[i].pv_long_integer;
00351                             break;
00352                      case PBLOCK_CLASS_POINTER:
00353                             *value = pb->pb_values[i].pv_pointer;
00354                             break;
00355                      case PBLOCK_CLASS_FUNCTION_POINTER:
00356                             *value = pb->pb_values[i].pv_function_pointer;
00357                             break;
00358                      default:
00359                             break;
00360                      }
00361                      break;
00362               }
00363        }
00364 
00365        return PBLOCK_SUCCESS;
00366 }
00367 
00368 static char *
00369 pblock_get_authtype( AuthorizationInformation *authz, int is_tls )
00370 {
00371        char *authType;
00372 
00373        switch ( authz->sai_method ) {
00374        case LDAP_AUTH_SASL:
00375               authType = SLAPD_AUTH_SASL;
00376               break;
00377        case LDAP_AUTH_SIMPLE:
00378               authType = SLAPD_AUTH_SIMPLE;
00379               break;
00380        case LDAP_AUTH_NONE:
00381               authType = SLAPD_AUTH_NONE;
00382               break;
00383        default:
00384               authType = NULL;
00385               break;
00386        }
00387 
00388        if ( is_tls && authType == NULL ) {
00389               authType = SLAPD_AUTH_SSL;
00390        }
00391 
00392        return authType;
00393 }
00394 
00395 static int 
00396 pblock_set_default( Slapi_PBlock *pb, int param, void *value ) 
00397 {
00398        slapi_pblock_class_t pbClass;
00399        int i;
00400 
00401        pbClass = pblock_get_param_class( param );
00402        if ( pbClass == PBLOCK_CLASS_INVALID ) {
00403               return PBLOCK_ERROR;
00404        }
00405 
00406        if ( pb->pb_nParams == PBLOCK_MAX_PARAMS ) {
00407               return PBLOCK_ERROR;
00408        }
00409 
00410        for ( i = 0; i < pb->pb_nParams; i++ ) {
00411               if ( pb->pb_params[i] == param )
00412                      break;
00413        }
00414        if ( i >= pb->pb_nParams ) {
00415               pb->pb_params[i] = param;
00416               pb->pb_nParams++;
00417        }
00418 
00419        switch ( pbClass ) {
00420        case PBLOCK_CLASS_INTEGER:
00421               pb->pb_values[i].pv_integer = (*((int *)value));
00422               break;
00423        case PBLOCK_CLASS_LONG_INTEGER:
00424               pb->pb_values[i].pv_long_integer = (*((long *)value));
00425               break;
00426        case PBLOCK_CLASS_POINTER:
00427               pb->pb_values[i].pv_pointer = value;
00428               break;
00429        case PBLOCK_CLASS_FUNCTION_POINTER:
00430               pb->pb_values[i].pv_function_pointer = value;
00431               break;
00432        default:
00433               break;
00434        }
00435 
00436        return PBLOCK_SUCCESS;
00437 }
00438 
00439 static int
00440 pblock_be_call( Slapi_PBlock *pb, int (*bep)(Operation *) )
00441 {
00442        BackendDB *be_orig;
00443        Operation *op;
00444        int rc;
00445 
00446        PBLOCK_ASSERT_OP( pb, 0 );
00447        op = pb->pb_op;
00448 
00449        be_orig = op->o_bd;
00450        op->o_bd = select_backend( &op->o_req_ndn, 0 );
00451        rc = (*bep)( op );
00452        op->o_bd = be_orig;
00453 
00454        return rc;
00455 }
00456 
00457 static int 
00458 pblock_get( Slapi_PBlock *pb, int param, void **value ) 
00459 {
00460        int rc = PBLOCK_SUCCESS;
00461 
00462        pblock_lock( pb );
00463 
00464        switch ( param ) {
00465        case SLAPI_OPERATION:
00466               *value = pb->pb_op;
00467               break;
00468        case SLAPI_OPINITIATED_TIME:
00469               PBLOCK_ASSERT_OP( pb, 0 );
00470               *((long *)value) = pb->pb_op->o_time;
00471               break;
00472        case SLAPI_OPERATION_ID:
00473               PBLOCK_ASSERT_OP( pb, 0 );
00474               *((long *)value) = pb->pb_op->o_opid;
00475               break;
00476        case SLAPI_OPERATION_TYPE:
00477               PBLOCK_ASSERT_OP( pb, 0 );
00478               *((ber_tag_t *)value) = pb->pb_op->o_tag;
00479               break;
00480        case SLAPI_OPERATION_MSGID:
00481               PBLOCK_ASSERT_OP( pb, 0 );
00482               *((long *)value) = pb->pb_op->o_msgid;
00483               break;
00484        case SLAPI_X_OPERATION_DELETE_GLUE_PARENT:
00485               PBLOCK_ASSERT_OP( pb, 0 );
00486               *((int *)value) = pb->pb_op->o_delete_glue_parent;
00487               break;
00488        case SLAPI_X_OPERATION_NO_SCHEMA_CHECK:
00489               PBLOCK_ASSERT_OP( pb, 0 );
00490               *((int *)value) = get_no_schema_check( pb->pb_op );
00491               break;
00492        case SLAPI_X_ADD_STRUCTURAL_CLASS:
00493               PBLOCK_ASSERT_OP( pb, 0 );
00494 
00495               if ( pb->pb_op->o_tag == LDAP_REQ_ADD ) {
00496                      struct berval tmpval = BER_BVNULL;
00497 
00498                      rc = mods_structural_class( pb->pb_op->ora_modlist,
00499                             &tmpval, &pb->pb_rs->sr_text,
00500                             pb->pb_textbuf, sizeof( pb->pb_textbuf ),
00501                             pb->pb_op->o_tmpmemctx );
00502                      *((char **)value) = tmpval.bv_val;
00503               } else {
00504                      rc = PBLOCK_ERROR;
00505               }
00506               break;
00507        case SLAPI_X_OPERATION_NO_SUBORDINATE_GLUE:
00508               PBLOCK_ASSERT_OP( pb, 0 );
00509               *((int *)value) = pb->pb_op->o_no_subordinate_glue;
00510               break;
00511        case SLAPI_REQCONTROLS:
00512               PBLOCK_ASSERT_OP( pb, 0 );
00513               *((LDAPControl ***)value) = pb->pb_op->o_ctrls;
00514               break;
00515        case SLAPI_REQUESTOR_DN:
00516               PBLOCK_ASSERT_OP( pb, 0 );
00517               *((char **)value) = pb->pb_op->o_dn.bv_val;
00518               break;
00519        case SLAPI_MANAGEDSAIT:
00520               PBLOCK_ASSERT_OP( pb, 0 );
00521               *((int *)value) = get_manageDSAit( pb->pb_op );
00522               break;
00523        case SLAPI_X_RELAX:
00524               PBLOCK_ASSERT_OP( pb, 0 );
00525               *((int *)value) = get_relax( pb->pb_op );
00526               break;
00527        case SLAPI_BACKEND:
00528               PBLOCK_ASSERT_OP( pb, 0 );
00529               *((BackendDB **)value) = select_backend( &pb->pb_op->o_req_ndn, 0 );
00530               break;
00531        case SLAPI_BE_TYPE:
00532               PBLOCK_ASSERT_OP( pb, 0 );
00533               if ( pb->pb_op->o_bd != NULL )
00534                      *((char **)value) = pb->pb_op->o_bd->bd_info->bi_type;
00535               else
00536                      *value = NULL;
00537               break;
00538        case SLAPI_CONNECTION:
00539               *value = pb->pb_conn;
00540               break;
00541        case SLAPI_X_CONN_SSF:
00542               PBLOCK_ASSERT_OP( pb, 0 );
00543               *((slap_ssf_t *)value) = pb->pb_conn->c_ssf;
00544               break;
00545        case SLAPI_X_CONN_SASL_CONTEXT:
00546               PBLOCK_ASSERT_CONN( pb );
00547               if ( pb->pb_conn->c_sasl_authctx != NULL )
00548                      *value = pb->pb_conn->c_sasl_authctx;
00549               else
00550                      *value = pb->pb_conn->c_sasl_sockctx;
00551               break;
00552        case SLAPI_TARGET_DN:
00553               PBLOCK_ASSERT_OP( pb, 0 );
00554               *((char **)value) = pb->pb_op->o_req_dn.bv_val;
00555               break;
00556        case SLAPI_REQUESTOR_ISROOT:
00557               *((int *)value) = pblock_be_call( pb, be_isroot );
00558               break;
00559        case SLAPI_IS_REPLICATED_OPERATION:
00560               *((int *)value) = pblock_be_call( pb, be_slurp_update );
00561               break;
00562        case SLAPI_CONN_AUTHTYPE:
00563        case SLAPI_CONN_AUTHMETHOD: /* XXX should return SASL mech */
00564               PBLOCK_ASSERT_CONN( pb );
00565               *((char **)value) = pblock_get_authtype( &pb->pb_conn->c_authz,
00566 #ifdef HAVE_TLS
00567                                                   pb->pb_conn->c_is_tls
00568 #else
00569                                                   0
00570 #endif
00571                                                   );
00572               break;
00573        case SLAPI_IS_INTERNAL_OPERATION:
00574               *((int *)value) = pb->pb_intop;
00575               break;
00576        case SLAPI_X_CONN_IS_UDP:
00577               PBLOCK_ASSERT_CONN( pb );
00578 #ifdef LDAP_CONNECTIONLESS
00579               *((int *)value) = pb->pb_conn->c_is_udp;
00580 #else
00581               *((int *)value) = 0;
00582 #endif
00583               break;
00584        case SLAPI_CONN_ID:
00585               PBLOCK_ASSERT_CONN( pb );
00586               *((long *)value) = pb->pb_conn->c_connid;
00587               break;
00588        case SLAPI_CONN_DN:
00589               PBLOCK_ASSERT_CONN( pb );
00590 #if 0
00591               /* This would be necessary to keep plugin compat after the fix in ITS#4158 */
00592               if ( pb->pb_op->o_tag == LDAP_REQ_BIND && pb->pb_rs->sr_err == LDAP_SUCCESS )
00593                      *((char **)value) = pb->pb_op->orb_edn.bv_val;
00594               else
00595 #endif
00596               *((char **)value) = pb->pb_conn->c_dn.bv_val;
00597               break;
00598        case SLAPI_CONN_CLIENTIP:
00599               PBLOCK_ASSERT_CONN( pb );
00600               if ( strncmp( pb->pb_conn->c_peer_name.bv_val, "IP=", 3 ) == 0 )
00601                      *((char **)value) = &pb->pb_conn->c_peer_name.bv_val[3];
00602               else
00603                      *value = NULL;
00604               break;
00605        case SLAPI_X_CONN_CLIENTPATH:
00606               PBLOCK_ASSERT_CONN( pb );
00607               if ( strncmp( pb->pb_conn->c_peer_name.bv_val, "PATH=", 3 ) == 0 )
00608                      *((char **)value) = &pb->pb_conn->c_peer_name.bv_val[5];
00609               else
00610                      *value = NULL;
00611               break;
00612        case SLAPI_CONN_SERVERIP:
00613               PBLOCK_ASSERT_CONN( pb );
00614               if ( strncmp( pb->pb_conn->c_sock_name.bv_val, "IP=", 3 ) == 0 )
00615                      *((char **)value) = &pb->pb_conn->c_sock_name.bv_val[3];
00616               else
00617                      *value = NULL;
00618               break;
00619        case SLAPI_X_CONN_SERVERPATH:
00620               PBLOCK_ASSERT_CONN( pb );
00621               if ( strncmp( pb->pb_conn->c_sock_name.bv_val, "PATH=", 3 ) == 0 )
00622                      *((char **)value) = &pb->pb_conn->c_sock_name.bv_val[5];
00623               else
00624                      *value = NULL;
00625               break;
00626        case SLAPI_RESULT_CODE:
00627        case SLAPI_PLUGIN_INTOP_RESULT:
00628               PBLOCK_ASSERT_OP( pb, 0 );
00629               *((int *)value) = pb->pb_rs->sr_err;
00630               break;
00631         case SLAPI_RESULT_TEXT:
00632               PBLOCK_ASSERT_OP( pb, 0 );
00633               *((const char **)value) = pb->pb_rs->sr_text;
00634               break;
00635         case SLAPI_RESULT_MATCHED:
00636               PBLOCK_ASSERT_OP( pb, 0 );
00637               *((const char **)value) = pb->pb_rs->sr_matched;
00638               break;
00639        case SLAPI_ADD_ENTRY:
00640               PBLOCK_ASSERT_OP( pb, 0 );
00641               if ( pb->pb_op->o_tag == LDAP_REQ_ADD )
00642                      *((Slapi_Entry **)value) = pb->pb_op->ora_e;
00643               else
00644                      *value = NULL;
00645               break;
00646        case SLAPI_MODIFY_MODS: {
00647               LDAPMod **mods = NULL;
00648               Modifications *ml = NULL;
00649 
00650               pblock_get_default( pb, param, (void **)&mods );
00651               if ( mods == NULL && pb->pb_intop == 0 ) {
00652                      switch ( pb->pb_op->o_tag ) {
00653                      case LDAP_REQ_MODIFY:
00654                             ml = pb->pb_op->orm_modlist;
00655                             break;
00656                      case LDAP_REQ_MODRDN:
00657                             ml = pb->pb_op->orr_modlist;
00658                             break;
00659                      default:
00660                             rc = PBLOCK_ERROR;
00661                             break;
00662                      }
00663                      if ( rc != PBLOCK_ERROR ) {
00664                             mods = slapi_int_modifications2ldapmods( ml );
00665                             pblock_set_default( pb, param, (void *)mods );
00666                      }
00667               }
00668               *((LDAPMod ***)value) = mods;
00669               break;
00670        }
00671        case SLAPI_MODRDN_NEWRDN:
00672               PBLOCK_ASSERT_OP( pb, 0 );
00673               if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN )
00674                      *((char **)value) = pb->pb_op->orr_newrdn.bv_val;
00675               else
00676                      *value = NULL;
00677               break;
00678        case SLAPI_MODRDN_NEWSUPERIOR:
00679               PBLOCK_ASSERT_OP( pb, 0 );
00680               if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN && pb->pb_op->orr_newSup != NULL )
00681                      *((char **)value) = pb->pb_op->orr_newSup->bv_val;
00682               else
00683                      *value = NULL;
00684               break;
00685        case SLAPI_MODRDN_DELOLDRDN:
00686               PBLOCK_ASSERT_OP( pb, 0 );
00687               if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN )
00688                      *((int *)value) = pb->pb_op->orr_deleteoldrdn;
00689               else
00690                      *((int *)value) = 0;
00691               break;
00692        case SLAPI_SEARCH_SCOPE:
00693               PBLOCK_ASSERT_OP( pb, 0 );
00694               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00695                      *((int *)value) = pb->pb_op->ors_scope;
00696               else
00697                      *((int *)value) = 0;
00698               break;
00699        case SLAPI_SEARCH_DEREF:
00700               PBLOCK_ASSERT_OP( pb, 0 );
00701               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00702                      *((int *)value) = pb->pb_op->ors_deref;
00703               else
00704                      *((int *)value) = 0;
00705               break;
00706        case SLAPI_SEARCH_SIZELIMIT:
00707               PBLOCK_ASSERT_OP( pb, 0 );
00708               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00709                      *((int *)value) = pb->pb_op->ors_slimit;
00710               else
00711                      *((int *)value) = 0;
00712               break;
00713        case SLAPI_SEARCH_TIMELIMIT:
00714               PBLOCK_ASSERT_OP( pb, 0 );
00715               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00716                      *((int *)value) = pb->pb_op->ors_tlimit;
00717               else
00718                      *((int *)value) = 0;
00719               break;
00720        case SLAPI_SEARCH_FILTER:
00721               PBLOCK_ASSERT_OP( pb, 0 );
00722               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00723                      *((Slapi_Filter **)value) = pb->pb_op->ors_filter;
00724               else
00725                      *((Slapi_Filter **)value) = NULL;
00726               break;
00727        case SLAPI_SEARCH_STRFILTER:
00728               PBLOCK_ASSERT_OP( pb, 0 );
00729               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00730                      *((char **)value) = pb->pb_op->ors_filterstr.bv_val;
00731               else
00732                      *((char **)value) = NULL;
00733               break;
00734        case SLAPI_SEARCH_ATTRS: {
00735               char **attrs = NULL;
00736 
00737               PBLOCK_ASSERT_OP( pb, 0 );
00738               if ( pb->pb_op->o_tag != LDAP_REQ_SEARCH ) {
00739                      rc = PBLOCK_ERROR;
00740                      break;
00741               }
00742               pblock_get_default( pb, param, (void **)&attrs );
00743               if ( attrs == NULL && pb->pb_intop == 0 ) {
00744                      attrs = anlist2charray_x( pb->pb_op->ors_attrs, 0, pb->pb_op->o_tmpmemctx );
00745                      pblock_set_default( pb, param, (void *)attrs );
00746               }
00747               *((char ***)value) = attrs;
00748               break;
00749        }
00750        case SLAPI_SEARCH_ATTRSONLY:
00751               PBLOCK_ASSERT_OP( pb, 0 );
00752               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
00753                      *((int *)value) = pb->pb_op->ors_attrsonly;
00754               else
00755                      *((int *)value) = 0;
00756               break;
00757        case SLAPI_SEARCH_RESULT_ENTRY:
00758               PBLOCK_ASSERT_OP( pb, 0 );
00759               *((Slapi_Entry **)value) = pb->pb_rs->sr_entry;
00760               break;
00761        case SLAPI_BIND_RET_SASLCREDS:
00762               PBLOCK_ASSERT_OP( pb, 0 );
00763               *((struct berval **)value) = pb->pb_rs->sr_sasldata;
00764               break;
00765        case SLAPI_EXT_OP_REQ_OID:
00766               *((const char **)value) = pb->pb_op->ore_reqoid.bv_val;
00767               break;
00768        case SLAPI_EXT_OP_REQ_VALUE:
00769               *((struct berval **)value) = pb->pb_op->ore_reqdata;
00770               break;
00771        case SLAPI_EXT_OP_RET_OID:
00772               PBLOCK_ASSERT_OP( pb, 0 );
00773               *((const char **)value) = pb->pb_rs->sr_rspoid;
00774               break;
00775        case SLAPI_EXT_OP_RET_VALUE:
00776               PBLOCK_ASSERT_OP( pb, 0 );
00777               *((struct berval **)value) = pb->pb_rs->sr_rspdata;
00778               break;
00779        case SLAPI_BIND_METHOD:
00780               if ( pb->pb_op->o_tag == LDAP_REQ_BIND )
00781                      *((int *)value) = pb->pb_op->orb_method;
00782               else
00783                      *((int *)value) = 0;
00784               break;
00785        case SLAPI_BIND_CREDENTIALS:
00786               if ( pb->pb_op->o_tag == LDAP_REQ_BIND )
00787                      *((struct berval **)value) = &pb->pb_op->orb_cred;
00788               else
00789                      *value = NULL;
00790               break;
00791        case SLAPI_COMPARE_TYPE:
00792               if ( pb->pb_op->o_tag == LDAP_REQ_COMPARE )
00793                      *((char **)value) = pb->pb_op->orc_ava->aa_desc->ad_cname.bv_val;
00794               else
00795                      *value = NULL;
00796               break;
00797        case SLAPI_COMPARE_VALUE:
00798               if ( pb->pb_op->o_tag == LDAP_REQ_COMPARE )
00799                      *((struct berval **)value) = &pb->pb_op->orc_ava->aa_value;
00800               else
00801                      *value = NULL;
00802               break;
00803        case SLAPI_ABANDON_MSGID:
00804               if ( pb->pb_op->o_tag == LDAP_REQ_ABANDON )
00805                      *((int *)value) = pb->pb_op->orn_msgid;
00806               else
00807                      *((int *)value) = 0;
00808               break;
00809        default:
00810               rc = pblock_get_default( pb, param, value );
00811               break;
00812        }
00813 
00814        pblock_unlock( pb );
00815 
00816        return rc;
00817 }
00818 
00819 static int
00820 pblock_add_control( Slapi_PBlock *pb, LDAPControl *control )
00821 {
00822        LDAPControl **controls = NULL;
00823        size_t i;
00824 
00825        pblock_get_default( pb, SLAPI_RESCONTROLS, (void **)&controls );
00826 
00827        if ( controls != NULL ) {
00828               for ( i = 0; controls[i] != NULL; i++ )
00829                      ;
00830        } else {
00831               i = 0;
00832        }
00833 
00834        controls = (LDAPControl **)slapi_ch_realloc( (char *)controls,
00835               ( i + 2 ) * sizeof(LDAPControl *));
00836        controls[i++] = slapi_dup_control( control );
00837        controls[i] = NULL;
00838 
00839        return pblock_set_default( pb, SLAPI_RESCONTROLS, (void *)controls );
00840 }
00841 
00842 static int
00843 pblock_set_dn( void *value, struct berval *dn, struct berval *ndn, void *memctx )
00844 {
00845        struct berval bv;
00846 
00847        if ( !BER_BVISNULL( dn )) {
00848               slap_sl_free( dn->bv_val, memctx );
00849               BER_BVZERO( dn );
00850        }
00851        if ( !BER_BVISNULL( ndn )) {
00852               slap_sl_free( ndn->bv_val, memctx );
00853               BER_BVZERO( ndn );
00854        }
00855 
00856        bv.bv_val = (char *)value;
00857        bv.bv_len = ( value != NULL ) ? strlen( bv.bv_val ) : 0;
00858 
00859        return dnPrettyNormal( NULL, &bv, dn, ndn, memctx );
00860 }
00861 
00862 static int 
00863 pblock_set( Slapi_PBlock *pb, int param, void *value ) 
00864 {
00865        int rc = PBLOCK_SUCCESS;
00866 
00867        pblock_lock( pb );   
00868 
00869        switch ( param ) {
00870        case SLAPI_OPERATION:
00871               pb->pb_op = (Operation *)value;
00872               break;
00873        case SLAPI_OPINITIATED_TIME:
00874               PBLOCK_ASSERT_OP( pb, 0 );
00875               pb->pb_op->o_time = *((long *)value);
00876               break;
00877        case SLAPI_OPERATION_ID:
00878               PBLOCK_ASSERT_OP( pb, 0 );
00879               pb->pb_op->o_opid = *((long *)value);
00880               break;
00881        case SLAPI_OPERATION_TYPE:
00882               PBLOCK_ASSERT_OP( pb, 0 );
00883               pb->pb_op->o_tag = *((ber_tag_t *)value);
00884               break;
00885        case SLAPI_OPERATION_MSGID:
00886               PBLOCK_ASSERT_OP( pb, 0 );
00887               pb->pb_op->o_msgid = *((long *)value);
00888               break;
00889        case SLAPI_X_OPERATION_DELETE_GLUE_PARENT:
00890               PBLOCK_ASSERT_OP( pb, 0 );
00891               pb->pb_op->o_delete_glue_parent = *((int *)value);
00892               break;
00893        case SLAPI_X_OPERATION_NO_SCHEMA_CHECK:
00894               PBLOCK_ASSERT_OP( pb, 0 );
00895               pb->pb_op->o_no_schema_check = *((int *)value);
00896               break;
00897        case SLAPI_X_OPERATION_NO_SUBORDINATE_GLUE:
00898               PBLOCK_ASSERT_OP( pb, 0 );
00899               pb->pb_op->o_no_subordinate_glue = *((int *)value);
00900               break;
00901        case SLAPI_REQCONTROLS:
00902               PBLOCK_ASSERT_OP( pb, 0 );
00903               pb->pb_op->o_ctrls = (LDAPControl **)value;
00904               break;
00905        case SLAPI_RESCONTROLS: {
00906               LDAPControl **ctrls = NULL;
00907 
00908               pblock_get_default( pb, param, (void **)&ctrls );
00909               if ( ctrls != NULL ) {
00910                      /* free old ones first */
00911                      ldap_controls_free( ctrls );
00912               }
00913               rc = pblock_set_default( pb, param, value );
00914               break;
00915        }
00916        case SLAPI_ADD_RESCONTROL:
00917               PBLOCK_ASSERT_OP( pb, 0 );
00918               rc = pblock_add_control( pb, (LDAPControl *)value );
00919               break;
00920        case SLAPI_REQUESTOR_DN:
00921               PBLOCK_ASSERT_OP( pb, 0 );
00922               rc = pblock_set_dn( value, &pb->pb_op->o_dn, &pb->pb_op->o_ndn, pb->pb_op->o_tmpmemctx );
00923               break;
00924        case SLAPI_MANAGEDSAIT:
00925               PBLOCK_ASSERT_OP( pb, 0 );
00926               pb->pb_op->o_managedsait = *((int *)value);
00927               break;
00928        case SLAPI_X_RELAX:
00929               PBLOCK_ASSERT_OP( pb, 0 );
00930               pb->pb_op->o_relax = *((int *)value);
00931               break;
00932        case SLAPI_BACKEND:
00933               PBLOCK_ASSERT_OP( pb, 0 );
00934               pb->pb_op->o_bd = (BackendDB *)value;
00935               break;
00936        case SLAPI_CONNECTION:
00937               pb->pb_conn = (Connection *)value;
00938               break;
00939        case SLAPI_X_CONN_SSF:
00940               PBLOCK_ASSERT_CONN( pb );
00941               PBLOCK_LOCK_CONN( pb );
00942               pb->pb_conn->c_ssf = (slap_ssf_t)(long)value;
00943               PBLOCK_UNLOCK_CONN( pb );
00944               break;
00945        case SLAPI_X_CONN_SASL_CONTEXT:
00946               PBLOCK_ASSERT_CONN( pb );
00947               PBLOCK_LOCK_CONN( pb );
00948               pb->pb_conn->c_sasl_authctx = value;
00949               PBLOCK_UNLOCK_CONN( pb );
00950               break;
00951        case SLAPI_TARGET_DN:
00952               PBLOCK_ASSERT_OP( pb, 0 );
00953               rc = pblock_set_dn( value, &pb->pb_op->o_req_dn, &pb->pb_op->o_req_ndn, pb->pb_op->o_tmpmemctx );
00954               break;
00955        case SLAPI_CONN_ID:
00956               PBLOCK_ASSERT_CONN( pb );
00957               PBLOCK_LOCK_CONN( pb );
00958               pb->pb_conn->c_connid = *((long *)value);
00959               PBLOCK_UNLOCK_CONN( pb );
00960               break;
00961        case SLAPI_CONN_DN:
00962               PBLOCK_ASSERT_CONN( pb );
00963               PBLOCK_LOCK_CONN( pb );
00964               rc = pblock_set_dn( value, &pb->pb_conn->c_dn, &pb->pb_conn->c_ndn, NULL );
00965               PBLOCK_UNLOCK_CONN( pb );
00966               break;
00967        case SLAPI_RESULT_CODE:
00968        case SLAPI_PLUGIN_INTOP_RESULT:
00969               PBLOCK_ASSERT_OP( pb, 0 );
00970               pb->pb_rs->sr_err = *((int *)value);
00971               break;
00972        case SLAPI_RESULT_TEXT:
00973               PBLOCK_ASSERT_OP( pb, 0 );
00974               snprintf( pb->pb_textbuf, sizeof( pb->pb_textbuf ), "%s", (char *)value );
00975               pb->pb_rs->sr_text = pb->pb_textbuf;
00976               break;
00977        case SLAPI_RESULT_MATCHED:
00978               PBLOCK_ASSERT_OP( pb, 0 );
00979               pb->pb_rs->sr_matched = (char *)value; /* XXX should dup? */
00980               break;
00981        case SLAPI_ADD_ENTRY:
00982               PBLOCK_ASSERT_OP( pb, 0 );
00983               if ( pb->pb_op->o_tag == LDAP_REQ_ADD )
00984                      pb->pb_op->ora_e = (Slapi_Entry *)value;
00985               else
00986                      rc = PBLOCK_ERROR;
00987               break;
00988        case SLAPI_MODIFY_MODS: {
00989               Modifications **mlp;
00990               Modifications *newmods;
00991 
00992               PBLOCK_ASSERT_OP( pb, 0 );
00993               rc = pblock_set_default( pb, param, value );
00994               if ( rc != PBLOCK_SUCCESS ) {
00995                      break;
00996               }
00997 
00998               if ( pb->pb_op->o_tag == LDAP_REQ_MODIFY ) {
00999                      mlp = &pb->pb_op->orm_modlist;
01000               } else if ( pb->pb_op->o_tag == LDAP_REQ_ADD ) {
01001                      mlp = &pb->pb_op->ora_modlist;
01002               } else if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN ) {
01003                      mlp = &pb->pb_op->orr_modlist;
01004               } else {
01005                      break;
01006               }
01007 
01008               newmods = slapi_int_ldapmods2modifications( pb->pb_op, (LDAPMod **)value );
01009               if ( newmods != NULL ) {
01010                      slap_mods_free( *mlp, 1 );
01011                      *mlp = newmods;
01012               }
01013               break;
01014        }
01015        case SLAPI_MODRDN_NEWRDN:
01016               PBLOCK_ASSERT_OP( pb, 0 );
01017               PBLOCK_VALIDATE_IS_INTOP( pb );
01018               if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN ) {
01019                      rc = pblock_set_dn( value, &pb->pb_op->orr_newrdn, &pb->pb_op->orr_nnewrdn, pb->pb_op->o_tmpmemctx );
01020                      if ( rc == LDAP_SUCCESS )
01021                             rc = rdn_validate( &pb->pb_op->orr_nnewrdn );
01022               } else {
01023                      rc = PBLOCK_ERROR;
01024               }
01025               break;
01026        case SLAPI_MODRDN_NEWSUPERIOR:
01027               PBLOCK_ASSERT_OP( pb, 0 );
01028               PBLOCK_VALIDATE_IS_INTOP( pb );
01029               if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN ) {
01030                      if ( value == NULL ) {
01031                             if ( pb->pb_op->orr_newSup != NULL ) {
01032                                    pb->pb_op->o_tmpfree( pb->pb_op->orr_newSup, pb->pb_op->o_tmpmemctx );
01033                                    BER_BVZERO( pb->pb_op->orr_newSup );
01034                                    pb->pb_op->orr_newSup = NULL;
01035                             }
01036                             if ( pb->pb_op->orr_newSup != NULL ) {
01037                                    pb->pb_op->o_tmpfree( pb->pb_op->orr_nnewSup, pb->pb_op->o_tmpmemctx );
01038                                    BER_BVZERO( pb->pb_op->orr_nnewSup );
01039                                    pb->pb_op->orr_nnewSup = NULL;
01040                             }
01041                      } else {
01042                             if ( pb->pb_op->orr_newSup == NULL ) {
01043                                    pb->pb_op->orr_newSup = (struct berval *)pb->pb_op->o_tmpalloc(
01044                                           sizeof(struct berval), pb->pb_op->o_tmpmemctx );
01045                                    BER_BVZERO( pb->pb_op->orr_newSup );
01046                             }
01047                             if ( pb->pb_op->orr_nnewSup == NULL ) {
01048                                    pb->pb_op->orr_nnewSup = (struct berval *)pb->pb_op->o_tmpalloc(
01049                                           sizeof(struct berval), pb->pb_op->o_tmpmemctx );
01050                                    BER_BVZERO( pb->pb_op->orr_nnewSup );
01051                             }
01052                             rc = pblock_set_dn( value, pb->pb_op->orr_newSup, pb->pb_op->orr_nnewSup, pb->pb_op->o_tmpmemctx );
01053                      }
01054               } else {
01055                      rc = PBLOCK_ERROR;
01056               }
01057               break;
01058        case SLAPI_MODRDN_DELOLDRDN:
01059               PBLOCK_ASSERT_OP( pb, 0 );
01060               PBLOCK_VALIDATE_IS_INTOP( pb );
01061               if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN )
01062                      pb->pb_op->orr_deleteoldrdn = *((int *)value);
01063               else
01064                      rc = PBLOCK_ERROR;
01065               break;
01066        case SLAPI_SEARCH_SCOPE: {
01067               int scope = *((int *)value);
01068 
01069               PBLOCK_ASSERT_OP( pb, 0 );
01070               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH ) {
01071                      switch ( *((int *)value) ) {
01072                      case LDAP_SCOPE_BASE:
01073                      case LDAP_SCOPE_ONELEVEL:
01074                      case LDAP_SCOPE_SUBTREE:
01075                      case LDAP_SCOPE_SUBORDINATE:
01076                             pb->pb_op->ors_scope = scope;
01077                             break;
01078                      default:
01079                             rc = PBLOCK_ERROR;
01080                             break;
01081                      }
01082               } else {
01083                      rc = PBLOCK_ERROR;
01084               }
01085               break;
01086        }
01087        case SLAPI_SEARCH_DEREF:
01088               PBLOCK_ASSERT_OP( pb, 0 );
01089               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
01090                      pb->pb_op->ors_deref = *((int *)value);
01091               else
01092                      rc = PBLOCK_ERROR;
01093               break;
01094        case SLAPI_SEARCH_SIZELIMIT:
01095               PBLOCK_ASSERT_OP( pb, 0 );
01096               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
01097                      pb->pb_op->ors_slimit = *((int *)value);
01098               else
01099                      rc = PBLOCK_ERROR;
01100               break;
01101        case SLAPI_SEARCH_TIMELIMIT:
01102               PBLOCK_ASSERT_OP( pb, 0 );
01103               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
01104                      pb->pb_op->ors_tlimit = *((int *)value);
01105               else
01106                      rc = PBLOCK_ERROR;
01107               break;
01108        case SLAPI_SEARCH_FILTER:
01109               PBLOCK_ASSERT_OP( pb, 0 );
01110               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
01111                      pb->pb_op->ors_filter = (Slapi_Filter *)value;
01112               else
01113                      rc = PBLOCK_ERROR;
01114               break;
01115        case SLAPI_SEARCH_STRFILTER:
01116               PBLOCK_ASSERT_OP( pb, 0 );
01117               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH ) {
01118                      pb->pb_op->ors_filterstr.bv_val = (char *)value;
01119                      pb->pb_op->ors_filterstr.bv_len = strlen((char *)value);
01120               } else {
01121                      rc = PBLOCK_ERROR;
01122               }
01123               break;
01124        case SLAPI_SEARCH_ATTRS: {
01125               AttributeName *an = NULL;
01126               size_t i = 0, j = 0;
01127               char **attrs = (char **)value;
01128 
01129               PBLOCK_ASSERT_OP( pb, 0 );
01130               PBLOCK_VALIDATE_IS_INTOP( pb );
01131 
01132               if ( pb->pb_op->o_tag != LDAP_REQ_SEARCH ) {
01133                      rc = PBLOCK_ERROR;
01134                      break;
01135               }
01136               /* also set mapped attrs */
01137               rc = pblock_set_default( pb, param, value );
01138               if ( rc != PBLOCK_SUCCESS ) {
01139                      break;
01140               }
01141               if ( pb->pb_op->ors_attrs != NULL ) {
01142                      pb->pb_op->o_tmpfree( pb->pb_op->ors_attrs, pb->pb_op->o_tmpmemctx );
01143                      pb->pb_op->ors_attrs = NULL;
01144               }
01145               if ( attrs != NULL ) {
01146                      for ( i = 0; attrs[i] != NULL; i++ )
01147                             ;
01148               }
01149               if ( i ) {
01150                      an = (AttributeName *)pb->pb_op->o_tmpcalloc( i + 1,
01151                             sizeof(AttributeName), pb->pb_op->o_tmpmemctx );
01152                      for ( i = 0; attrs[i] != NULL; i++ ) {
01153                             an[j].an_desc = NULL;
01154                             an[j].an_oc = NULL;
01155                             an[j].an_flags = 0;
01156                             an[j].an_name.bv_val = attrs[i];
01157                             an[j].an_name.bv_len = strlen( attrs[i] );
01158                             if ( slap_bv2ad( &an[j].an_name, &an[j].an_desc, &pb->pb_rs->sr_text ) == LDAP_SUCCESS ) {
01159                                    j++;
01160                             }
01161                      }
01162                      an[j].an_name.bv_val = NULL;
01163                      an[j].an_name.bv_len = 0;
01164               }      
01165               pb->pb_op->ors_attrs = an;
01166               break;
01167        }
01168        case SLAPI_SEARCH_ATTRSONLY:
01169               PBLOCK_ASSERT_OP( pb, 0 );
01170               PBLOCK_VALIDATE_IS_INTOP( pb );
01171 
01172               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
01173                      pb->pb_op->ors_attrsonly = *((int *)value);
01174               else
01175                      rc = PBLOCK_ERROR;
01176               break;
01177        case SLAPI_SEARCH_RESULT_ENTRY:
01178               PBLOCK_ASSERT_OP( pb, 0 );
01179               rs_replace_entry( pb->pb_op, pb->pb_rs, NULL, (Slapi_Entry *)value );
01180               /* TODO: Should REP_ENTRY_MODIFIABLE be set? */
01181               pb->pb_rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
01182               break;
01183        case SLAPI_BIND_RET_SASLCREDS:
01184               PBLOCK_ASSERT_OP( pb, 0 );
01185               pb->pb_rs->sr_sasldata = (struct berval *)value;
01186               break;
01187        case SLAPI_EXT_OP_REQ_OID:
01188               PBLOCK_ASSERT_OP( pb, 0 );
01189               PBLOCK_VALIDATE_IS_INTOP( pb );
01190 
01191               if ( pb->pb_op->o_tag == LDAP_REQ_EXTENDED ) {
01192                      pb->pb_op->ore_reqoid.bv_val = (char *)value;
01193                      pb->pb_op->ore_reqoid.bv_len = strlen((char *)value);
01194               } else {
01195                      rc = PBLOCK_ERROR;
01196               }
01197               break;
01198        case SLAPI_EXT_OP_REQ_VALUE:
01199               PBLOCK_ASSERT_OP( pb, 0 );
01200               PBLOCK_VALIDATE_IS_INTOP( pb );
01201 
01202               if ( pb->pb_op->o_tag == LDAP_REQ_EXTENDED )
01203                      pb->pb_op->ore_reqdata = (struct berval *)value;
01204               else
01205                      rc = PBLOCK_ERROR;
01206               break;
01207        case SLAPI_EXT_OP_RET_OID:
01208               PBLOCK_ASSERT_OP( pb, 0 );
01209               pb->pb_rs->sr_rspoid = (char *)value;
01210               break;
01211        case SLAPI_EXT_OP_RET_VALUE:
01212               PBLOCK_ASSERT_OP( pb, 0 );
01213               pb->pb_rs->sr_rspdata = (struct berval *)value;
01214               break;
01215        case SLAPI_BIND_METHOD:
01216               PBLOCK_ASSERT_OP( pb, 0 );
01217               PBLOCK_VALIDATE_IS_INTOP( pb );
01218 
01219               if ( pb->pb_op->o_tag == LDAP_REQ_BIND )
01220                      pb->pb_op->orb_method = *((int *)value);
01221               else
01222                      rc = PBLOCK_ERROR;
01223               break;
01224        case SLAPI_BIND_CREDENTIALS:
01225               PBLOCK_ASSERT_OP( pb, 0 );
01226               PBLOCK_VALIDATE_IS_INTOP( pb );
01227 
01228               if ( pb->pb_op->o_tag == LDAP_REQ_BIND )
01229                      pb->pb_op->orb_cred = *((struct berval *)value);
01230               else
01231                      rc = PBLOCK_ERROR;
01232               break;
01233        case SLAPI_COMPARE_TYPE:
01234               PBLOCK_ASSERT_OP( pb, 0 );
01235               PBLOCK_VALIDATE_IS_INTOP( pb );
01236 
01237               if ( pb->pb_op->o_tag == LDAP_REQ_COMPARE ) {
01238                      const char *text;
01239 
01240                      pb->pb_op->orc_ava->aa_desc = NULL;
01241                      rc = slap_str2ad( (char *)value, &pb->pb_op->orc_ava->aa_desc, &text );
01242               } else {
01243                      rc = PBLOCK_ERROR;
01244               }
01245               break;
01246        case SLAPI_COMPARE_VALUE:
01247               PBLOCK_ASSERT_OP( pb, 0 );
01248               PBLOCK_VALIDATE_IS_INTOP( pb );
01249 
01250               if ( pb->pb_op->o_tag == LDAP_REQ_COMPARE )
01251                      pb->pb_op->orc_ava->aa_value = *((struct berval *)value);
01252               else
01253                      rc = PBLOCK_ERROR;
01254               break;
01255        case SLAPI_ABANDON_MSGID:
01256               PBLOCK_ASSERT_OP( pb, 0 );
01257               PBLOCK_VALIDATE_IS_INTOP( pb );
01258 
01259               if ( pb->pb_op->o_tag == LDAP_REQ_ABANDON)
01260                      pb->pb_op->orn_msgid = *((int *)value);
01261               else
01262                      rc = PBLOCK_ERROR;
01263               break;
01264        case SLAPI_REQUESTOR_ISROOT:
01265        case SLAPI_IS_REPLICATED_OPERATION:
01266        case SLAPI_CONN_AUTHTYPE:
01267        case SLAPI_CONN_AUTHMETHOD:
01268        case SLAPI_IS_INTERNAL_OPERATION:
01269        case SLAPI_X_CONN_IS_UDP:
01270        case SLAPI_CONN_CLIENTIP:
01271        case SLAPI_X_CONN_CLIENTPATH:
01272        case SLAPI_CONN_SERVERIP:
01273        case SLAPI_X_CONN_SERVERPATH:
01274        case SLAPI_X_ADD_STRUCTURAL_CLASS:
01275               /* These parameters cannot be set */
01276               rc = PBLOCK_ERROR;
01277               break;
01278        default:
01279               rc = pblock_set_default( pb, param, value );
01280               break;
01281        }
01282 
01283        pblock_unlock( pb );
01284 
01285        return rc;
01286 }
01287 
01288 static void
01289 pblock_clear( Slapi_PBlock *pb ) 
01290 {
01291        pb->pb_nParams = 1;
01292 }
01293 
01294 static int
01295 pblock_delete_param( Slapi_PBlock *p, int param ) 
01296 {
01297        int i;
01298 
01299        pblock_lock(p);
01300 
01301        for ( i = 0; i < p->pb_nParams; i++ ) { 
01302               if ( p->pb_params[i] == param ) {
01303                      break;
01304               }
01305        }
01306     
01307        if (i >= p->pb_nParams ) {
01308               pblock_unlock( p );
01309               return PBLOCK_ERROR;
01310        }
01311 
01312        /* move last parameter to index of deleted parameter */
01313        if ( p->pb_nParams > 1 ) {
01314               p->pb_params[i] = p->pb_params[p->pb_nParams - 1];
01315               p->pb_values[i] = p->pb_values[p->pb_nParams - 1];
01316        }
01317        p->pb_nParams--;
01318 
01319        pblock_unlock( p );  
01320 
01321        return PBLOCK_SUCCESS;
01322 }
01323 
01324 Slapi_PBlock *
01325 slapi_pblock_new(void) 
01326 {
01327        Slapi_PBlock *pb;
01328 
01329        pb = (Slapi_PBlock *) ch_calloc( 1, sizeof(Slapi_PBlock) );
01330        if ( pb != NULL ) {
01331               ldap_pvt_thread_mutex_init( &pb->pb_mutex );
01332 
01333               pb->pb_params[0] = SLAPI_IBM_PBLOCK;
01334               pb->pb_values[0].pv_pointer = NULL;
01335               pb->pb_nParams = 1;
01336               pb->pb_conn = NULL;
01337               pb->pb_op = NULL;
01338               pb->pb_rs = NULL;
01339               pb->pb_intop = 0;
01340        }
01341        return pb;
01342 }
01343 
01344 static void
01345 pblock_destroy( Slapi_PBlock *pb )
01346 {
01347        LDAPControl **controls = NULL;
01348        LDAPMod **mods = NULL;
01349        char **attrs = NULL;
01350 
01351        assert( pb != NULL );
01352 
01353        pblock_get_default( pb, SLAPI_RESCONTROLS, (void **)&controls );
01354        if ( controls != NULL ) {
01355               ldap_controls_free( controls );
01356        }
01357 
01358        if ( pb->pb_intop ) {
01359               slapi_int_connection_done_pb( pb );
01360        } else {
01361               pblock_get_default( pb, SLAPI_MODIFY_MODS, (void **)&mods );
01362               ldap_mods_free( mods, 1 );
01363 
01364               pblock_get_default( pb, SLAPI_SEARCH_ATTRS, (void **)&attrs );
01365               if ( attrs != NULL )
01366                      pb->pb_op->o_tmpfree( attrs, pb->pb_op->o_tmpmemctx );
01367        }
01368 
01369        ldap_pvt_thread_mutex_destroy( &pb->pb_mutex );
01370        slapi_ch_free( (void **)&pb ); 
01371 }
01372 
01373 void 
01374 slapi_pblock_destroy( Slapi_PBlock *pb ) 
01375 {
01376        if ( pb != NULL ) {
01377               pblock_destroy( pb );
01378        }
01379 }
01380 
01381 int 
01382 slapi_pblock_get( Slapi_PBlock *pb, int arg, void *value ) 
01383 {
01384        return pblock_get( pb, arg, (void **)value );
01385 }
01386 
01387 int 
01388 slapi_pblock_set( Slapi_PBlock *pb, int arg, void *value ) 
01389 {
01390        return pblock_set( pb, arg, value );
01391 }
01392 
01393 void
01394 slapi_pblock_clear( Slapi_PBlock *pb ) 
01395 {
01396        pblock_clear( pb );
01397 }
01398 
01399 int 
01400 slapi_pblock_delete_param( Slapi_PBlock *p, int param ) 
01401 {
01402        return pblock_delete_param( p, param );
01403 }
01404 
01405 /*
01406  * OpenLDAP extension
01407  */
01408 int
01409 slapi_int_pblock_get_first( Backend *be, Slapi_PBlock **pb )
01410 {
01411        assert( pb != NULL );
01412        *pb = SLAPI_BACKEND_PBLOCK( be );
01413        return (*pb == NULL ? LDAP_OTHER : LDAP_SUCCESS);
01414 }
01415 
01416 /*
01417  * OpenLDAP extension
01418  */
01419 int
01420 slapi_int_pblock_get_next( Slapi_PBlock **pb )
01421 {
01422        assert( pb != NULL );
01423        return slapi_pblock_get( *pb, SLAPI_IBM_PBLOCK, pb );
01424 }
01425 
01426 #endif /* LDAP_SLAPI */