2 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright IBM Corp. 1997,2002
7 * Use of this source code is subject to the terms of The OpenLDAP Public
8 * License (version 2.7 or later).
9 * No trademarks of the IBM Corporation are to be used to identify, endorse
10 * or promote any products derived from this code without the prior
11 * written consent of IBM
14 * Portions (C) Copyright PADL Software Pty Ltd. 2003
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that this notice is preserved
17 * and that due credit is given to PADL Software Pty Ltd. This software
18 * is provided ``as is'' without express or implied warranty.
23 #include <ac/string.h>
24 #include <ac/stdarg.h>
26 #include <ac/unistd.h>
33 * use a fake listener when faking a connection,
34 * so it can be used in ACLs
36 static struct slap_listener slap_unknown_listener = {
37 BER_BVC("unknown"), /* FIXME: use a URI form? (e.g. slapi://) */
47 /* XXX needs review after internal API change */
48 /* rs->sr_nentries appears to always be 0 */
49 if (op->o_tag == LDAP_REQ_SEARCH)
50 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
51 SLAPI_NENTRIES, (void *)rs->sr_nentries );
58 internal_search_entry(
62 int nentries = 0, len = 0, i = 0;
63 Slapi_Entry **head = NULL, **tp;
66 entry = slapi_entry_dup( rs->sr_entry );
67 if ( entry == NULL ) {
71 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
72 SLAPI_NENTRIES, &nentries );
73 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
74 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
77 if ( nentries == 0 ) {
78 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
80 slapi_entry_free( entry );
86 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
87 sizeof(Slapi_Entry *) * ( i + 1 ) );
89 slapi_entry_free( entry );
96 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
97 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
98 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
99 SLAPI_NENTRIES, (void *)i );
113 internal_search_reference(
125 Connection *pConn, *c;
126 ber_len_t max = sockbuf_max_incoming;
128 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
130 return (Connection *)NULL;
133 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
135 pConn->c_pending_ops.stqh_first =
136 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
137 if ( pConn->c_pending_ops.stqh_first == NULL ) {
138 slapi_ch_free( (void **)&pConn );
139 return (Connection *)NULL;
142 pConn->c_pending_ops.stqh_first->o_pb =
143 (Slapi_PBlock *) slapi_pblock_new();
144 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
145 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
146 slapi_ch_free( (void **)&pConn );
147 return (Connection *)NULL;
152 /* operation object */
153 c->c_pending_ops.stqh_first->o_tag = OpType;
154 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
155 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
156 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
157 c->c_pending_ops.stqh_first->o_time = slap_get_time();
158 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
159 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context();
160 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
161 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
162 c->c_pending_ops.stqh_first->o_conn = c;
164 /* connection object */
165 c->c_authmech.bv_val = NULL;
166 c->c_authmech.bv_len = 0;
167 c->c_dn.bv_val = NULL;
169 c->c_ndn.bv_val = NULL;
172 c->c_listener = &slap_unknown_listener;
173 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
174 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
176 LDAP_STAILQ_INIT( &c->c_ops );
178 c->c_sasl_bind_mech.bv_val = NULL;
179 c->c_sasl_bind_mech.bv_len = 0;
180 c->c_sasl_authctx = NULL;
181 c->c_sasl_sockctx = NULL;
182 c->c_sasl_extra = NULL;
184 c->c_sb = ber_sockbuf_alloc( );
186 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
188 c->c_currentber = NULL;
190 /* should check status of thread calls */
191 ldap_pvt_thread_mutex_init( &c->c_mutex );
192 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
193 ldap_pvt_thread_cond_init( &c->c_write_cv );
195 c->c_n_ops_received = 0;
196 c->c_n_ops_executing = 0;
197 c->c_n_ops_pending = 0;
198 c->c_n_ops_completed = 0;
204 c->c_protocol = LDAP_VERSION3;
206 c->c_activitytime = c->c_starttime = slap_get_time();
210 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
211 c->c_struct_state = 0x02; /* SLAP_C_USED */
213 c->c_ssf = c->c_transport_ssf = 0;
216 backend_connection_init( c );
218 pConn->c_send_ldap_result = internal_result_v3;
219 pConn->c_send_search_entry = internal_search_entry;
220 pConn->c_send_ldap_extended = internal_result_ext;
221 pConn->c_send_search_reference = internal_search_reference;
226 static void slapiConnectionDestroy( Connection **pConn )
228 Connection *conn = *pConn;
231 if ( pConn == NULL ) {
235 op = (Operation *)conn->c_pending_ops.stqh_first;
237 if ( op->o_req_dn.bv_val != NULL ) {
238 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
240 if ( op->o_req_ndn.bv_val != NULL ) {
241 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
244 if ( conn->c_sb != NULL ) {
245 ber_sockbuf_free( conn->c_sb );
248 slapi_ch_free( (void **)&op );
250 slapi_ch_free( (void **)pConn );
254 * Function : values2obj
255 * Convert an array of strings into a BerVarray.
266 if ( ppValue == NULL ) {
271 for ( i = 0; ppValue[i] != NULL; i++ )
274 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
275 if ( tmpberval == NULL ) {
276 return LDAP_NO_MEMORY;
278 for ( i = 0; ppValue[i] != NULL; i++ ) {
279 size_t len = strlen( ppValue[i] );
281 tmpberval[i].bv_val = slapi_ch_malloc( len + 1 );
282 AC_MEMCPY( tmpberval[i].bv_val, ppValue[i], len + 1 );
283 tmpberval[i].bv_len = len;
285 tmpberval[i].bv_val = NULL;
286 tmpberval[i].bv_len = 0;
295 struct berval **bvptr,
298 int rc = LDAP_SUCCESS;
302 if ( bvptr == NULL || *bvptr == NULL ) {
306 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
310 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
311 if ( tmpberval == NULL ) {
312 return LDAP_NO_MEMORY;
315 for ( i = 0; bvptr[i] != NULL; i++ ) {
316 tmpberval[i].bv_val = slapi_ch_malloc( bvptr[i]->bv_len );
317 tmpberval[i].bv_len = bvptr[i]->bv_len;
318 AC_MEMCPY( tmpberval[i].bv_val, bvptr[i]->bv_val, bvptr[i]->bv_len );
320 tmpberval[i].bv_val = NULL;
321 tmpberval[i].bv_len = 0;
323 if ( rc == LDAP_SUCCESS ) {
331 * Function : LDAPModToEntry
332 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
333 * with a link list of the correspondent attributes.
334 * Return value : LDAP_SUCCESS
343 struct berval dn = { 0, NULL };
349 Modifications *modlist = NULL;
350 Modifications **modtail = &modlist;
353 int rc = LDAP_SUCCESS;
356 const char *text = NULL;
359 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
364 op->o_tag = LDAP_REQ_ADD;
366 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
367 if ( pEntry == NULL) {
372 dn.bv_val = slapi_ch_strdup(ldn);
373 dn.bv_len = strlen(ldn);
375 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
376 if ( rc != LDAP_SUCCESS ) {
380 if ( rc == LDAP_SUCCESS ) {
381 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
384 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
386 * Convert an array of pointers to bervals to
387 * an array of bervals. Note that we need to copy the
388 * values too, as the slap_mods_check() will free the
389 * original values after prettying; the modifications
390 * being passed in may not have been allocated on the
393 rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
394 if ( rc != LDAP_SUCCESS ) goto cleanup;
395 tmp.sml_type.bv_val = pMod->mod_type;
396 tmp.sml_type.bv_len = strlen( pMod->mod_type );
397 tmp.sml_bvalues = bv;
398 tmp.sml_nvalues = NULL;
400 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
402 mod->sml_op = LDAP_MOD_ADD;
403 mod->sml_next = NULL;
404 mod->sml_desc = NULL;
405 mod->sml_type = tmp.sml_type;
406 mod->sml_bvalues = tmp.sml_bvalues;
407 mod->sml_nvalues = tmp.sml_nvalues;
410 modtail = &mod->sml_next;
413 /* attr values are in string format, need to be converted */
414 /* to an array of bervals */
415 if ( pMod->mod_values == NULL ) {
418 rc = values2obj_copy( pMod->mod_values, &bv );
419 if ( rc != LDAP_SUCCESS ) goto cleanup;
420 tmp.sml_type.bv_val = pMod->mod_type;
421 tmp.sml_type.bv_len = strlen( pMod->mod_type );
422 tmp.sml_bvalues = bv;
423 tmp.sml_nvalues = NULL;
425 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
427 mod->sml_op = LDAP_MOD_ADD;
428 mod->sml_next = NULL;
429 mod->sml_desc = NULL;
430 mod->sml_type = tmp.sml_type;
431 mod->sml_bvalues = tmp.sml_bvalues;
432 mod->sml_nvalues = tmp.sml_nvalues;
435 modtail = &mod->sml_next;
438 } /* for each LDAPMod */
441 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
442 if ( op->o_bd == NULL ) {
443 rc = LDAP_PARTIAL_RESULTS;
445 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
446 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
447 int update = op->o_bd->be_update_ndn.bv_len;
448 char textbuf[SLAP_TEXT_BUFLEN];
449 size_t textlen = sizeof textbuf;
451 rc = slap_mods_check( modlist, update, &text,
452 textbuf, textlen, NULL );
453 if ( rc != LDAP_SUCCESS) {
458 rc = slap_mods_opattrs( op,
459 modlist, modtail, &text,
461 if ( rc != LDAP_SUCCESS) {
466 rc = slap_mods2entry( modlist, &pEntry, repl_user,
467 0, &text, textbuf, textlen );
468 if (rc != LDAP_SUCCESS) {
480 slapi_ch_free( (void **)&dn.bv_val );
482 slapi_ch_free( (void **)&op );
483 if ( modlist != NULL )
484 slap_mods_free( modlist );
485 if ( rc != LDAP_SUCCESS ) {
486 if ( pEntry != NULL ) {
487 slapi_entry_free( pEntry );
495 /* Function : slapi_delete_internal
497 * Description : Plugin functions call this routine to delete an entry
498 * in the backend directly
499 * Return values : LDAP_SUCCESS
503 * LDAP_UNWILLING_TO_PERFORM
506 slapi_delete_internal(
508 LDAPControl **controls,
512 Connection *pConn = NULL;
513 Operation *op = NULL;
514 Slapi_PBlock *pPB = NULL;
515 Slapi_PBlock *pSavePB = NULL;
516 SlapReply rs = { REP_RESULT };
517 struct berval dn = { 0, NULL };
523 rs.sr_err = LDAP_PARAM_ERROR;
527 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
529 rs.sr_err = LDAP_NO_MEMORY;
533 op = (Operation *)pConn->c_pending_ops.stqh_first;
534 pPB = (Slapi_PBlock *)op->o_pb;
535 op->o_ctrls = controls;
537 dn.bv_val = slapi_ch_strdup(ldn);
538 dn.bv_len = strlen(ldn);
539 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
540 if ( rs.sr_err != LDAP_SUCCESS )
543 if ( slapi_control_present( controls,
544 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
548 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
549 if ( op->o_bd == NULL ) {
550 rs.sr_err = LDAP_PARTIAL_RESULTS;
554 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
555 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
557 if ( op->o_bd->be_delete ) {
558 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
559 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
560 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
565 rs.sr_err = LDAP_OTHER;
568 rs.sr_err = LDAP_REFERRAL;
571 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
576 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
579 slapi_ch_free( (void **)&dn.bv_val );
581 if ( pConn != NULL ) {
585 slapiConnectionDestroy( &pConn );
590 #endif /* LDAP_SLAPI */
594 static Slapi_PBlock *
595 slapi_add_entry_internal_locked(
597 LDAPControl **controls,
600 Connection *pConn = NULL;
601 Operation *op = NULL;
602 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
606 SlapReply rs = { REP_RESULT };
609 rs.sr_err = LDAP_PARAM_ERROR;
613 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
614 if ( pConn == NULL ) {
615 rs.sr_err = LDAP_NO_MEMORY;
619 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
620 NULL, &isCritical ) ) {
624 op = (Operation *)pConn->c_pending_ops.stqh_first;
625 pPB = (Slapi_PBlock *)op->o_pb;
626 op->o_ctrls = controls;
628 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
629 if ( op->o_bd == NULL ) {
630 rs.sr_err = LDAP_PARTIAL_RESULTS;
634 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
635 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
636 op->oq_add.rs_e = *e;
638 if ( op->o_bd->be_add ) {
639 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
640 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
641 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
645 be_entry_release_w( op, *e );
649 rs.sr_err = LDAP_REFERRAL;
652 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
658 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
661 if ( pConn != NULL ) {
665 slapiConnectionDestroy( &pConn );
669 #endif /* LDAP_SLAPI */
672 slapi_add_entry_internal(
674 LDAPControl **controls,
682 * We make a copy to avoid an entry that may be freed later
683 * by the caller being placed in the cache.
685 entry = slapi_entry_dup( e );
686 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
687 if ( entry != NULL ) {
688 slapi_entry_free( entry );
700 LDAPControl **controls,
704 LDAPMod *pMod = NULL;
705 Slapi_PBlock *pb = NULL;
706 Entry *pEntry = NULL;
707 int i, rc = LDAP_SUCCESS;
709 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
710 rc = LDAP_PARAM_ERROR ;
713 if ( rc == LDAP_SUCCESS ) {
714 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
715 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
722 if ( rc == LDAP_SUCCESS ) {
723 pEntry = LDAPModToEntry( dn, mods );
724 if ( pEntry == NULL ) {
729 if ( rc != LDAP_SUCCESS ) {
730 pb = slapi_pblock_new();
731 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
733 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
736 if ( pEntry != NULL ) {
737 slapi_entry_free(pEntry);
743 #endif /* LDAP_SLAPI */
746 /* Function : slapi_modrdn_internal
748 * Description : Plugin functions call this routine to modify the rdn
749 * of an entry in the backend directly
750 * Return values : LDAP_SUCCESS
754 * LDAP_UNWILLING_TO_PERFORM
756 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
759 slapi_modrdn_internal(
763 LDAPControl **controls,
767 struct berval dn = { 0, NULL };
768 struct berval newrdn = { 0, NULL };
769 Connection *pConn = NULL;
770 Operation *op = NULL;
771 Slapi_PBlock *pPB = NULL;
772 Slapi_PBlock *pSavePB = NULL;
775 SlapReply rs = { REP_RESULT };
777 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
778 if ( pConn == NULL) {
779 rs.sr_err = LDAP_NO_MEMORY;
783 op = (Operation *)pConn->c_pending_ops.stqh_first;
784 pPB = (Slapi_PBlock *)op->o_pb;
785 op->o_ctrls = controls;
787 if ( slapi_control_present( controls,
788 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
792 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
793 if ( op->o_bd == NULL ) {
794 rs.sr_err = LDAP_PARTIAL_RESULTS;
798 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
799 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
801 dn.bv_val = slapi_ch_strdup( olddn );
802 dn.bv_len = strlen( olddn );
804 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
805 if ( rs.sr_err != LDAP_SUCCESS ) {
809 if ( op->o_req_dn.bv_len == 0 ) {
810 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
814 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
815 newrdn.bv_len = strlen( lnewrdn );
817 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
818 if ( rs.sr_err != LDAP_SUCCESS ) {
822 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
826 op->oq_modrdn.rs_newSup = NULL;
827 op->oq_modrdn.rs_nnewSup = NULL;
828 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
830 if ( op->o_bd->be_modrdn ) {
831 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
832 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
833 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
838 rs.sr_err = LDAP_OTHER;
841 rs.sr_err = LDAP_REFERRAL;
844 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
850 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
854 slapi_ch_free( (void **)&dn.bv_val );
857 slapi_ch_free( (void **)&newrdn.bv_val );
858 if ( op->oq_modrdn.rs_newrdn.bv_val )
859 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
860 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
861 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
863 if ( pConn != NULL ) {
867 slapiConnectionDestroy( &pConn );
872 #endif /* LDAP_SLAPI */
875 /* Function : slapi_modify_internal
877 * Description: Plugin functions call this routine to modify an entry
878 * in the backend directly
879 * Return values : LDAP_SUCCESS
883 * LDAP_UNWILLING_TO_PERFORM
886 slapi_modify_internal(
889 LDAPControl **controls,
894 Connection *pConn = NULL;
895 Operation *op = NULL;
896 Slapi_PBlock *pPB = NULL;
897 Slapi_PBlock *pSavePB = NULL;
899 struct berval dn = { 0, NULL };
906 Modifications *modlist = NULL;
907 Modifications **modtail = &modlist;
910 SlapReply rs = { REP_RESULT };
912 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
913 rs.sr_err = LDAP_PARAM_ERROR ;
917 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
918 if ( pConn == NULL ) {
919 rs.sr_err = LDAP_NO_MEMORY;
923 op = (Operation *)pConn->c_pending_ops.stqh_first;
924 pPB = (Slapi_PBlock *)op->o_pb;
925 op->o_ctrls = controls;
927 dn.bv_val = slapi_ch_strdup( ldn );
928 dn.bv_len = strlen( ldn );
929 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
930 if ( rs.sr_err != LDAP_SUCCESS ) {
934 if ( slapi_control_present( controls,
935 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
939 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
940 if ( op->o_bd == NULL ) {
941 rs.sr_err = LDAP_PARTIAL_RESULTS;
945 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
946 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
948 for ( i = 0, pMod = mods[0];
949 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
954 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
956 * attr values are in berval format
957 * convert an array of pointers to bervals
958 * to an array of bervals
960 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
961 if ( rs.sr_err != LDAP_SUCCESS )
963 tmp.sml_type.bv_val = pMod->mod_type;
964 tmp.sml_type.bv_len = strlen( pMod->mod_type );
965 tmp.sml_bvalues = bv;
966 tmp.sml_nvalues = NULL;
968 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
970 mod->sml_op = pMod->mod_op;
971 mod->sml_next = NULL;
972 mod->sml_desc = NULL;
973 mod->sml_type = tmp.sml_type;
974 mod->sml_bvalues = tmp.sml_bvalues;
975 mod->sml_nvalues = tmp.sml_nvalues;
977 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
978 if ( rs.sr_err != LDAP_SUCCESS )
980 tmp.sml_type.bv_val = pMod->mod_type;
981 tmp.sml_type.bv_len = strlen( pMod->mod_type );
982 tmp.sml_bvalues = bv;
983 tmp.sml_nvalues = NULL;
985 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
987 mod->sml_op = pMod->mod_op;
988 mod->sml_next = NULL;
989 mod->sml_desc = NULL;
990 mod->sml_type = tmp.sml_type;
991 mod->sml_bvalues = tmp.sml_bvalues;
992 mod->sml_nvalues = tmp.sml_nvalues;
995 modtail = &mod->sml_next;
997 switch( pMod->mod_op ) {
999 if ( mod->sml_bvalues == NULL ) {
1000 rs.sr_err = LDAP_PROTOCOL_ERROR;
1005 case LDAP_MOD_DELETE:
1006 case LDAP_MOD_REPLACE:
1010 rs.sr_err = LDAP_PROTOCOL_ERROR;
1016 if ( op->o_req_ndn.bv_len == 0 ) {
1017 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1021 op->oq_modify.rs_modlist = modlist;
1023 if ( op->o_bd->be_modify ) {
1024 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1025 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1026 int update = op->o_bd->be_update_ndn.bv_len;
1027 const char *text = NULL;
1028 char textbuf[SLAP_TEXT_BUFLEN];
1029 size_t textlen = sizeof( textbuf );
1031 rs.sr_err = slap_mods_check( modlist, update,
1032 &text, textbuf, textlen, NULL );
1033 if ( rs.sr_err != LDAP_SUCCESS ) {
1038 rs.sr_err = slap_mods_opattrs( op, modlist,
1039 modtail, &text, textbuf,
1041 if ( rs.sr_err != LDAP_SUCCESS ) {
1045 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1050 rs.sr_err = LDAP_OTHER;
1053 rs.sr_err = LDAP_REFERRAL;
1056 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1062 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1065 slapi_ch_free( (void **)&dn.bv_val );
1067 if ( modlist != NULL )
1068 slap_mods_free( modlist );
1070 if ( pConn != NULL ) {
1074 slapiConnectionDestroy( &pConn );
1079 #endif /* LDAP_SLAPI */
1083 slapi_search_internal_bind(
1088 LDAPControl **controls,
1094 Operation *op = NULL;
1095 Slapi_PBlock *ptr = NULL;
1096 Slapi_PBlock *pSavePB = NULL;
1097 struct berval dn = { 0, NULL };
1098 Filter *filter=NULL;
1099 struct berval fstr = { 0, NULL };
1100 AttributeName *an = NULL;
1101 const char *text = NULL;
1103 int manageDsaIt = 0;
1107 SlapReply rs = { REP_RESULT };
1109 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1111 rs.sr_err = LDAP_NO_MEMORY;
1115 op = (Operation *)c->c_pending_ops.stqh_first;
1116 ptr = (Slapi_PBlock *)op->o_pb;
1117 op->o_ctrls = controls;
1119 if ( ldn != NULL ) {
1120 dn.bv_val = slapi_ch_strdup(ldn);
1121 dn.bv_len = strlen(ldn);
1124 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1125 if ( rs.sr_err != LDAP_SUCCESS ) {
1129 if ( scope != LDAP_SCOPE_BASE &&
1130 scope != LDAP_SCOPE_ONELEVEL &&
1131 scope != LDAP_SCOPE_SUBTREE ) {
1132 rs.sr_err = LDAP_PROTOCOL_ERROR;
1136 filter = slapi_str2filter(filStr);
1137 if ( filter == NULL ) {
1138 rs.sr_err = LDAP_PROTOCOL_ERROR;
1142 filter2bv( filter, &fstr );
1144 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1145 ; /* count the number of attributes */
1149 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1150 for (i = 0; attrs[i] != 0; i++) {
1151 an[i].an_desc = NULL;
1153 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1154 an[i].an_name.bv_len = strlen(attrs[i]);
1155 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1157 an[i].an_name.bv_val = NULL;
1160 memset( &rs, 0, sizeof(rs) );
1161 rs.sr_type = REP_RESULT;
1162 rs.sr_err = LDAP_SUCCESS;
1163 rs.sr_entry = NULL; /* paranoia */
1165 if ( scope == LDAP_SCOPE_BASE ) {
1168 if ( op->o_req_ndn.bv_len == 0 ) {
1169 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1172 if( rs.sr_err != LDAP_SUCCESS ) {
1173 send_ldap_result( op, &rs );
1175 } else if ( rs.sr_entry != NULL ) {
1176 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1178 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1179 rs.sr_type = REP_SEARCH;
1180 rs.sr_err = LDAP_SUCCESS;
1183 send_search_entry( op, &rs );
1186 entry_free( rs.sr_entry );
1188 rs.sr_type = REP_RESULT;
1189 rs.sr_err = LDAP_SUCCESS;
1191 send_ldap_result( op, &rs );
1197 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1198 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1199 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1201 ber_dupbv( &op->o_req_dn, &default_search_base );
1202 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1205 if ( slapi_control_present( controls,
1206 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1210 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1211 if ( op->o_bd == NULL ) {
1212 if ( manageDsaIt == 1 ) {
1213 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1215 rs.sr_err = LDAP_PARTIAL_RESULTS;
1220 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1221 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1223 op->oq_search.rs_scope = scope;
1224 op->oq_search.rs_deref = 0;
1225 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1226 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1227 op->oq_search.rs_attrsonly = attrsonly;
1228 op->oq_search.rs_attrs = an;
1229 op->oq_search.rs_filter = filter;
1230 op->oq_search.rs_filterstr = fstr;
1232 if ( op->o_bd->be_search ) {
1233 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1234 rs.sr_err = LDAP_OTHER;
1237 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1243 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1246 slapi_ch_free( (void **)&dn.bv_val );
1248 slapi_filter_free( filter, 1 );
1250 slapi_ch_free( (void **)&fstr.bv_val );
1252 slapi_ch_free( (void **)&an );
1258 slapiConnectionDestroy( &c );
1263 #endif /* LDAP_SLAPI */
1267 slapi_search_internal(
1271 LDAPControl **controls,
1276 return slapi_search_internal_bind( NULL, base, scope, filStr,
1277 controls, attrs, attrsonly );
1280 #endif /* LDAP_SLAPI */