2 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Portions Copyright IBM Corp. 1997,2002-2003
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License, version 2.7 or later.
12 * Portions (C) Copyright PADL Software Pty Ltd. 2003
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that this notice is preserved
15 * and that due credit is given to PADL Software Pty Ltd. This software
16 * is provided ``as is'' without express or implied warranty.
21 #include <ac/string.h>
22 #include <ac/stdarg.h>
24 #include <ac/unistd.h>
31 * use a fake listener when faking a connection,
32 * so it can be used in ACLs
34 static struct slap_listener slap_unknown_listener = {
35 BER_BVC("unknown"), /* FIXME: use a URI form? (e.g. slapi://) */
45 /* XXX needs review after internal API change */
46 /* rs->sr_nentries appears to always be 0 */
47 if (op->o_tag == LDAP_REQ_SEARCH)
48 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
49 SLAPI_NENTRIES, (void *)rs->sr_nentries );
56 internal_search_entry(
60 int nentries = 0, len = 0, i = 0;
61 Slapi_Entry **head = NULL, **tp;
64 entry = slapi_entry_dup( rs->sr_entry );
65 if ( entry == NULL ) {
69 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
70 SLAPI_NENTRIES, &nentries );
71 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
72 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
75 if ( nentries == 0 ) {
76 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
78 slapi_entry_free( entry );
84 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
85 sizeof(Slapi_Entry *) * ( i + 1 ) );
87 slapi_entry_free( entry );
94 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
95 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
96 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
97 SLAPI_NENTRIES, (void *)i );
111 internal_search_reference(
123 Connection *pConn, *c;
124 ber_len_t max = sockbuf_max_incoming;
126 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
128 return (Connection *)NULL;
131 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
133 pConn->c_pending_ops.stqh_first =
134 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
135 if ( pConn->c_pending_ops.stqh_first == NULL ) {
136 slapi_ch_free( (void **)&pConn );
137 return (Connection *)NULL;
140 pConn->c_pending_ops.stqh_first->o_pb =
141 (Slapi_PBlock *) slapi_pblock_new();
142 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
143 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
144 slapi_ch_free( (void **)&pConn );
145 return (Connection *)NULL;
150 /* operation object */
151 c->c_pending_ops.stqh_first->o_tag = OpType;
152 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
153 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
154 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
155 c->c_pending_ops.stqh_first->o_time = slap_get_time();
156 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
157 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context();
158 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
159 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
160 c->c_pending_ops.stqh_first->o_conn = c;
162 /* connection object */
163 c->c_authmech.bv_val = NULL;
164 c->c_authmech.bv_len = 0;
165 c->c_dn.bv_val = NULL;
167 c->c_ndn.bv_val = NULL;
170 c->c_listener = &slap_unknown_listener;
171 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
172 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
174 LDAP_STAILQ_INIT( &c->c_ops );
176 c->c_sasl_bind_mech.bv_val = NULL;
177 c->c_sasl_bind_mech.bv_len = 0;
178 c->c_sasl_authctx = NULL;
179 c->c_sasl_sockctx = NULL;
180 c->c_sasl_extra = NULL;
182 c->c_sb = ber_sockbuf_alloc( );
184 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
186 c->c_currentber = NULL;
188 /* should check status of thread calls */
189 ldap_pvt_thread_mutex_init( &c->c_mutex );
190 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
191 ldap_pvt_thread_cond_init( &c->c_write_cv );
193 c->c_n_ops_received = 0;
194 c->c_n_ops_executing = 0;
195 c->c_n_ops_pending = 0;
196 c->c_n_ops_completed = 0;
202 c->c_protocol = LDAP_VERSION3;
204 c->c_activitytime = c->c_starttime = slap_get_time();
208 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
209 c->c_struct_state = 0x02; /* SLAP_C_USED */
211 c->c_ssf = c->c_transport_ssf = 0;
214 backend_connection_init( c );
216 pConn->c_send_ldap_result = internal_result_v3;
217 pConn->c_send_search_entry = internal_search_entry;
218 pConn->c_send_ldap_extended = internal_result_ext;
219 pConn->c_send_search_reference = internal_search_reference;
224 static void slapiConnectionDestroy( Connection **pConn )
226 Connection *conn = *pConn;
229 if ( pConn == NULL ) {
233 op = (Operation *)conn->c_pending_ops.stqh_first;
235 if ( op->o_req_dn.bv_val != NULL ) {
236 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
238 if ( op->o_req_ndn.bv_val != NULL ) {
239 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
242 if ( conn->c_sb != NULL ) {
243 ber_sockbuf_free( conn->c_sb );
246 slapi_ch_free( (void **)&op );
248 slapi_ch_free( (void **)pConn );
252 * Function : values2obj
253 * Convert an array of strings into a BerVarray.
264 if ( ppValue == NULL ) {
269 for ( i = 0; ppValue[i] != NULL; i++ )
272 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
273 if ( tmpberval == NULL ) {
274 return LDAP_NO_MEMORY;
276 for ( i = 0; ppValue[i] != NULL; i++ ) {
277 size_t len = strlen( ppValue[i] );
279 tmpberval[i].bv_val = slapi_ch_malloc( len + 1 );
280 AC_MEMCPY( tmpberval[i].bv_val, ppValue[i], len + 1 );
281 tmpberval[i].bv_len = len;
283 tmpberval[i].bv_val = NULL;
284 tmpberval[i].bv_len = 0;
293 struct berval **bvptr,
296 int rc = LDAP_SUCCESS;
300 if ( bvptr == NULL || *bvptr == NULL ) {
304 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
308 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
309 if ( tmpberval == NULL ) {
310 return LDAP_NO_MEMORY;
313 for ( i = 0; bvptr[i] != NULL; i++ ) {
314 tmpberval[i].bv_val = slapi_ch_malloc( bvptr[i]->bv_len );
315 tmpberval[i].bv_len = bvptr[i]->bv_len;
316 AC_MEMCPY( tmpberval[i].bv_val, bvptr[i]->bv_val, bvptr[i]->bv_len );
318 tmpberval[i].bv_val = NULL;
319 tmpberval[i].bv_len = 0;
321 if ( rc == LDAP_SUCCESS ) {
329 * Function : LDAPModToEntry
330 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
331 * with a link list of the correspondent attributes.
332 * Return value : LDAP_SUCCESS
341 struct berval dn = { 0, NULL };
347 Modifications *modlist = NULL;
348 Modifications **modtail = &modlist;
351 int rc = LDAP_SUCCESS;
354 const char *text = NULL;
357 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
362 op->o_tag = LDAP_REQ_ADD;
364 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
365 if ( pEntry == NULL) {
370 dn.bv_val = slapi_ch_strdup(ldn);
371 dn.bv_len = strlen(ldn);
373 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
374 if ( rc != LDAP_SUCCESS ) {
378 if ( rc == LDAP_SUCCESS ) {
379 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
382 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
384 * Convert an array of pointers to bervals to
385 * an array of bervals. Note that we need to copy the
386 * values too, as the slap_mods_check() will free the
387 * original values after prettying; the modifications
388 * being passed in may not have been allocated on the
391 rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
392 if ( rc != LDAP_SUCCESS ) goto cleanup;
393 tmp.sml_type.bv_val = pMod->mod_type;
394 tmp.sml_type.bv_len = strlen( pMod->mod_type );
395 tmp.sml_bvalues = bv;
396 tmp.sml_nvalues = NULL;
398 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
400 mod->sml_op = LDAP_MOD_ADD;
401 mod->sml_next = NULL;
402 mod->sml_desc = NULL;
403 mod->sml_type = tmp.sml_type;
404 mod->sml_bvalues = tmp.sml_bvalues;
405 mod->sml_nvalues = tmp.sml_nvalues;
408 modtail = &mod->sml_next;
411 /* attr values are in string format, need to be converted */
412 /* to an array of bervals */
413 if ( pMod->mod_values == NULL ) {
416 rc = values2obj_copy( pMod->mod_values, &bv );
417 if ( rc != LDAP_SUCCESS ) goto cleanup;
418 tmp.sml_type.bv_val = pMod->mod_type;
419 tmp.sml_type.bv_len = strlen( pMod->mod_type );
420 tmp.sml_bvalues = bv;
421 tmp.sml_nvalues = NULL;
423 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
425 mod->sml_op = LDAP_MOD_ADD;
426 mod->sml_next = NULL;
427 mod->sml_desc = NULL;
428 mod->sml_type = tmp.sml_type;
429 mod->sml_bvalues = tmp.sml_bvalues;
430 mod->sml_nvalues = tmp.sml_nvalues;
433 modtail = &mod->sml_next;
436 } /* for each LDAPMod */
439 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
440 if ( op->o_bd == NULL ) {
441 rc = LDAP_PARTIAL_RESULTS;
443 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
444 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
445 int update = op->o_bd->be_update_ndn.bv_len;
446 char textbuf[SLAP_TEXT_BUFLEN];
447 size_t textlen = sizeof textbuf;
449 rc = slap_mods_check( modlist, update, &text,
450 textbuf, textlen, NULL );
451 if ( rc != LDAP_SUCCESS) {
456 rc = slap_mods_opattrs( op,
457 modlist, modtail, &text,
459 if ( rc != LDAP_SUCCESS) {
464 rc = slap_mods2entry( modlist, &pEntry, repl_user,
465 0, &text, textbuf, textlen );
466 if (rc != LDAP_SUCCESS) {
478 slapi_ch_free( (void **)&dn.bv_val );
480 slapi_ch_free( (void **)&op );
481 if ( modlist != NULL )
482 slap_mods_free( modlist );
483 if ( rc != LDAP_SUCCESS ) {
484 if ( pEntry != NULL ) {
485 slapi_entry_free( pEntry );
493 /* Function : slapi_delete_internal
495 * Description : Plugin functions call this routine to delete an entry
496 * in the backend directly
497 * Return values : LDAP_SUCCESS
501 * LDAP_UNWILLING_TO_PERFORM
504 slapi_delete_internal(
506 LDAPControl **controls,
510 Connection *pConn = NULL;
511 Operation *op = NULL;
512 Slapi_PBlock *pPB = NULL;
513 Slapi_PBlock *pSavePB = NULL;
514 SlapReply rs = { REP_RESULT };
515 struct berval dn = { 0, NULL };
521 rs.sr_err = LDAP_PARAM_ERROR;
525 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
527 rs.sr_err = LDAP_NO_MEMORY;
531 op = (Operation *)pConn->c_pending_ops.stqh_first;
532 pPB = (Slapi_PBlock *)op->o_pb;
533 op->o_ctrls = controls;
535 dn.bv_val = slapi_ch_strdup(ldn);
536 dn.bv_len = strlen(ldn);
537 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
538 if ( rs.sr_err != LDAP_SUCCESS )
541 if ( slapi_control_present( controls,
542 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
546 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
547 if ( op->o_bd == NULL ) {
548 rs.sr_err = LDAP_PARTIAL_RESULTS;
552 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
553 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
555 if ( op->o_bd->be_delete ) {
556 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
557 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
558 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
563 rs.sr_err = LDAP_OTHER;
566 rs.sr_err = LDAP_REFERRAL;
569 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
574 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
577 slapi_ch_free( (void **)&dn.bv_val );
579 if ( pConn != NULL ) {
583 slapiConnectionDestroy( &pConn );
588 #endif /* LDAP_SLAPI */
592 static Slapi_PBlock *
593 slapi_add_entry_internal_locked(
595 LDAPControl **controls,
598 Connection *pConn = NULL;
599 Operation *op = NULL;
600 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
604 SlapReply rs = { REP_RESULT };
607 rs.sr_err = LDAP_PARAM_ERROR;
611 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
612 if ( pConn == NULL ) {
613 rs.sr_err = LDAP_NO_MEMORY;
617 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
618 NULL, &isCritical ) ) {
622 op = (Operation *)pConn->c_pending_ops.stqh_first;
623 pPB = (Slapi_PBlock *)op->o_pb;
624 op->o_ctrls = controls;
626 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
627 if ( op->o_bd == NULL ) {
628 rs.sr_err = LDAP_PARTIAL_RESULTS;
632 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
633 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
634 op->oq_add.rs_e = *e;
636 if ( op->o_bd->be_add ) {
637 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
638 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
639 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
643 be_entry_release_w( op, *e );
647 rs.sr_err = LDAP_REFERRAL;
650 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
656 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
659 if ( pConn != NULL ) {
663 slapiConnectionDestroy( &pConn );
667 #endif /* LDAP_SLAPI */
670 slapi_add_entry_internal(
672 LDAPControl **controls,
680 * We make a copy to avoid an entry that may be freed later
681 * by the caller being placed in the cache.
683 entry = slapi_entry_dup( e );
684 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
685 if ( entry != NULL ) {
686 slapi_entry_free( entry );
698 LDAPControl **controls,
702 LDAPMod *pMod = NULL;
703 Slapi_PBlock *pb = NULL;
704 Entry *pEntry = NULL;
705 int i, rc = LDAP_SUCCESS;
707 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
708 rc = LDAP_PARAM_ERROR ;
711 if ( rc == LDAP_SUCCESS ) {
712 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
713 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
720 if ( rc == LDAP_SUCCESS ) {
721 pEntry = LDAPModToEntry( dn, mods );
722 if ( pEntry == NULL ) {
727 if ( rc != LDAP_SUCCESS ) {
728 pb = slapi_pblock_new();
729 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
731 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
734 if ( pEntry != NULL ) {
735 slapi_entry_free(pEntry);
741 #endif /* LDAP_SLAPI */
744 /* Function : slapi_modrdn_internal
746 * Description : Plugin functions call this routine to modify the rdn
747 * of an entry in the backend directly
748 * Return values : LDAP_SUCCESS
752 * LDAP_UNWILLING_TO_PERFORM
754 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
757 slapi_modrdn_internal(
761 LDAPControl **controls,
765 struct berval dn = { 0, NULL };
766 struct berval newrdn = { 0, NULL };
767 Connection *pConn = NULL;
768 Operation *op = NULL;
769 Slapi_PBlock *pPB = NULL;
770 Slapi_PBlock *pSavePB = NULL;
773 SlapReply rs = { REP_RESULT };
775 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
776 if ( pConn == NULL) {
777 rs.sr_err = LDAP_NO_MEMORY;
781 op = (Operation *)pConn->c_pending_ops.stqh_first;
782 pPB = (Slapi_PBlock *)op->o_pb;
783 op->o_ctrls = controls;
785 if ( slapi_control_present( controls,
786 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
790 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
791 if ( op->o_bd == NULL ) {
792 rs.sr_err = LDAP_PARTIAL_RESULTS;
796 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
797 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
799 dn.bv_val = slapi_ch_strdup( olddn );
800 dn.bv_len = strlen( olddn );
802 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
803 if ( rs.sr_err != LDAP_SUCCESS ) {
807 if ( op->o_req_dn.bv_len == 0 ) {
808 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
812 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
813 newrdn.bv_len = strlen( lnewrdn );
815 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
816 if ( rs.sr_err != LDAP_SUCCESS ) {
820 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
824 op->oq_modrdn.rs_newSup = NULL;
825 op->oq_modrdn.rs_nnewSup = NULL;
826 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
828 if ( op->o_bd->be_modrdn ) {
829 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
830 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
831 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
836 rs.sr_err = LDAP_OTHER;
839 rs.sr_err = LDAP_REFERRAL;
842 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
848 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
852 slapi_ch_free( (void **)&dn.bv_val );
855 slapi_ch_free( (void **)&newrdn.bv_val );
856 if ( op->oq_modrdn.rs_newrdn.bv_val )
857 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
858 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
859 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
861 if ( pConn != NULL ) {
865 slapiConnectionDestroy( &pConn );
870 #endif /* LDAP_SLAPI */
873 /* Function : slapi_modify_internal
875 * Description: Plugin functions call this routine to modify an entry
876 * in the backend directly
877 * Return values : LDAP_SUCCESS
881 * LDAP_UNWILLING_TO_PERFORM
884 slapi_modify_internal(
887 LDAPControl **controls,
892 Connection *pConn = NULL;
893 Operation *op = NULL;
894 Slapi_PBlock *pPB = NULL;
895 Slapi_PBlock *pSavePB = NULL;
897 struct berval dn = { 0, NULL };
904 Modifications *modlist = NULL;
905 Modifications **modtail = &modlist;
908 SlapReply rs = { REP_RESULT };
910 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
911 rs.sr_err = LDAP_PARAM_ERROR ;
915 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
916 if ( pConn == NULL ) {
917 rs.sr_err = LDAP_NO_MEMORY;
921 op = (Operation *)pConn->c_pending_ops.stqh_first;
922 pPB = (Slapi_PBlock *)op->o_pb;
923 op->o_ctrls = controls;
925 dn.bv_val = slapi_ch_strdup( ldn );
926 dn.bv_len = strlen( ldn );
927 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
928 if ( rs.sr_err != LDAP_SUCCESS ) {
932 if ( slapi_control_present( controls,
933 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
937 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
938 if ( op->o_bd == NULL ) {
939 rs.sr_err = LDAP_PARTIAL_RESULTS;
943 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
944 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
946 for ( i = 0, pMod = mods[0];
947 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
952 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
954 * attr values are in berval format
955 * convert an array of pointers to bervals
956 * to an array of bervals
958 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
959 if ( rs.sr_err != LDAP_SUCCESS )
961 tmp.sml_type.bv_val = pMod->mod_type;
962 tmp.sml_type.bv_len = strlen( pMod->mod_type );
963 tmp.sml_bvalues = bv;
964 tmp.sml_nvalues = NULL;
966 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
968 mod->sml_op = pMod->mod_op;
969 mod->sml_next = NULL;
970 mod->sml_desc = NULL;
971 mod->sml_type = tmp.sml_type;
972 mod->sml_bvalues = tmp.sml_bvalues;
973 mod->sml_nvalues = tmp.sml_nvalues;
975 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
976 if ( rs.sr_err != LDAP_SUCCESS )
978 tmp.sml_type.bv_val = pMod->mod_type;
979 tmp.sml_type.bv_len = strlen( pMod->mod_type );
980 tmp.sml_bvalues = bv;
981 tmp.sml_nvalues = NULL;
983 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
985 mod->sml_op = pMod->mod_op;
986 mod->sml_next = NULL;
987 mod->sml_desc = NULL;
988 mod->sml_type = tmp.sml_type;
989 mod->sml_bvalues = tmp.sml_bvalues;
990 mod->sml_nvalues = tmp.sml_nvalues;
993 modtail = &mod->sml_next;
995 switch( pMod->mod_op ) {
997 if ( mod->sml_bvalues == NULL ) {
998 rs.sr_err = LDAP_PROTOCOL_ERROR;
1003 case LDAP_MOD_DELETE:
1004 case LDAP_MOD_REPLACE:
1008 rs.sr_err = LDAP_PROTOCOL_ERROR;
1014 if ( op->o_req_ndn.bv_len == 0 ) {
1015 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1019 op->oq_modify.rs_modlist = modlist;
1021 if ( op->o_bd->be_modify ) {
1022 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1023 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1024 int update = op->o_bd->be_update_ndn.bv_len;
1025 const char *text = NULL;
1026 char textbuf[SLAP_TEXT_BUFLEN];
1027 size_t textlen = sizeof( textbuf );
1029 rs.sr_err = slap_mods_check( modlist, update,
1030 &text, textbuf, textlen, NULL );
1031 if ( rs.sr_err != LDAP_SUCCESS ) {
1036 rs.sr_err = slap_mods_opattrs( op, modlist,
1037 modtail, &text, textbuf,
1039 if ( rs.sr_err != LDAP_SUCCESS ) {
1043 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1048 rs.sr_err = LDAP_OTHER;
1051 rs.sr_err = LDAP_REFERRAL;
1054 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1060 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1063 slapi_ch_free( (void **)&dn.bv_val );
1065 if ( modlist != NULL )
1066 slap_mods_free( modlist );
1068 if ( pConn != NULL ) {
1072 slapiConnectionDestroy( &pConn );
1077 #endif /* LDAP_SLAPI */
1081 slapi_search_internal_bind(
1086 LDAPControl **controls,
1092 Operation *op = NULL;
1093 Slapi_PBlock *ptr = NULL;
1094 Slapi_PBlock *pSavePB = NULL;
1095 struct berval dn = { 0, NULL };
1096 Filter *filter=NULL;
1097 struct berval fstr = { 0, NULL };
1098 AttributeName *an = NULL;
1099 const char *text = NULL;
1101 int manageDsaIt = 0;
1105 SlapReply rs = { REP_RESULT };
1107 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1109 rs.sr_err = LDAP_NO_MEMORY;
1113 op = (Operation *)c->c_pending_ops.stqh_first;
1114 ptr = (Slapi_PBlock *)op->o_pb;
1115 op->o_ctrls = controls;
1117 if ( ldn != NULL ) {
1118 dn.bv_val = slapi_ch_strdup(ldn);
1119 dn.bv_len = strlen(ldn);
1122 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1123 if ( rs.sr_err != LDAP_SUCCESS ) {
1127 if ( scope != LDAP_SCOPE_BASE &&
1128 scope != LDAP_SCOPE_ONELEVEL &&
1129 scope != LDAP_SCOPE_SUBTREE ) {
1130 rs.sr_err = LDAP_PROTOCOL_ERROR;
1134 filter = slapi_str2filter(filStr);
1135 if ( filter == NULL ) {
1136 rs.sr_err = LDAP_PROTOCOL_ERROR;
1140 filter2bv( filter, &fstr );
1142 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1143 ; /* count the number of attributes */
1147 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1148 for (i = 0; attrs[i] != 0; i++) {
1149 an[i].an_desc = NULL;
1151 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1152 an[i].an_name.bv_len = strlen(attrs[i]);
1153 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1155 an[i].an_name.bv_val = NULL;
1158 memset( &rs, 0, sizeof(rs) );
1159 rs.sr_type = REP_RESULT;
1160 rs.sr_err = LDAP_SUCCESS;
1161 rs.sr_entry = NULL; /* paranoia */
1163 if ( scope == LDAP_SCOPE_BASE ) {
1166 if ( op->o_req_ndn.bv_len == 0 ) {
1167 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1170 if( rs.sr_err != LDAP_SUCCESS ) {
1171 send_ldap_result( op, &rs );
1173 } else if ( rs.sr_entry != NULL ) {
1174 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1176 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1177 rs.sr_type = REP_SEARCH;
1178 rs.sr_err = LDAP_SUCCESS;
1181 send_search_entry( op, &rs );
1184 entry_free( rs.sr_entry );
1186 rs.sr_type = REP_RESULT;
1187 rs.sr_err = LDAP_SUCCESS;
1189 send_ldap_result( op, &rs );
1195 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1196 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1197 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1199 ber_dupbv( &op->o_req_dn, &default_search_base );
1200 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1203 if ( slapi_control_present( controls,
1204 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1208 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1209 if ( op->o_bd == NULL ) {
1210 if ( manageDsaIt == 1 ) {
1211 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1213 rs.sr_err = LDAP_PARTIAL_RESULTS;
1218 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1219 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1221 op->oq_search.rs_scope = scope;
1222 op->oq_search.rs_deref = 0;
1223 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1224 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1225 op->oq_search.rs_attrsonly = attrsonly;
1226 op->oq_search.rs_attrs = an;
1227 op->oq_search.rs_filter = filter;
1228 op->oq_search.rs_filterstr = fstr;
1230 if ( op->o_bd->be_search ) {
1231 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1232 rs.sr_err = LDAP_OTHER;
1235 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1241 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1244 slapi_ch_free( (void **)&dn.bv_val );
1246 slapi_filter_free( filter, 1 );
1248 slapi_ch_free( (void **)&fstr.bv_val );
1250 slapi_ch_free( (void **)&an );
1256 slapiConnectionDestroy( &c );
1261 #endif /* LDAP_SLAPI */
1265 slapi_search_internal(
1269 LDAPControl **controls,
1274 return slapi_search_internal_bind( NULL, base, scope, filStr,
1275 controls, attrs, attrsonly );
1278 #endif /* LDAP_SLAPI */