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 are permitted
8 * provided that this notice is preserved and that due credit is
9 * given to IBM Corporation. This software is provided ``as is''
10 * without express or implied warranty.
13 * Portions (C) Copyright PADL Software Pty Ltd. 2003
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that this notice is preserved
16 * and that due credit is given to PADL Software Pty Ltd. This software
17 * is provided ``as is'' without express or implied warranty.
22 #include <ac/string.h>
23 #include <ac/stdarg.h>
25 #include <ac/unistd.h>
32 * use a fake listener when faking a connection,
33 * so it can be used in ACLs
35 static struct slap_listener slap_unknown_listener = {
36 BER_BVC("unknown"), /* FIXME: use a URI form? (e.g. slapi://) */
46 /* XXX needs review after internal API change */
47 /* rs->sr_nentries appears to always be 0 */
48 if (op->o_tag == LDAP_REQ_SEARCH)
49 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
50 SLAPI_NENTRIES, (void *)rs->sr_nentries );
57 internal_search_entry(
61 int nentries = 0, len = 0, i = 0;
62 Slapi_Entry **head = NULL, **tp;
65 entry = slapi_entry_dup( rs->sr_entry );
66 if ( entry == NULL ) {
70 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
71 SLAPI_NENTRIES, &nentries );
72 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
73 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
76 if ( nentries == 0 ) {
77 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
79 slapi_entry_free( entry );
85 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
86 sizeof(Slapi_Entry *) * ( i + 1 ) );
88 slapi_entry_free( entry );
95 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
96 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
97 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
98 SLAPI_NENTRIES, (void *)i );
112 internal_search_reference(
124 Connection *pConn, *c;
125 ber_len_t max = sockbuf_max_incoming;
127 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
129 return (Connection *)NULL;
132 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
134 pConn->c_pending_ops.stqh_first =
135 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
136 if ( pConn->c_pending_ops.stqh_first == NULL ) {
137 slapi_ch_free( (void **)&pConn );
138 return (Connection *)NULL;
141 pConn->c_pending_ops.stqh_first->o_pb =
142 (Slapi_PBlock *) slapi_pblock_new();
143 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
144 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
145 slapi_ch_free( (void **)&pConn );
146 return (Connection *)NULL;
151 /* operation object */
152 c->c_pending_ops.stqh_first->o_tag = OpType;
153 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
154 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
155 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
156 c->c_pending_ops.stqh_first->o_time = slap_get_time();
157 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
158 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context();
159 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
160 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
161 c->c_pending_ops.stqh_first->o_conn = c;
163 /* connection object */
164 c->c_authmech.bv_val = NULL;
165 c->c_authmech.bv_len = 0;
166 c->c_dn.bv_val = NULL;
168 c->c_ndn.bv_val = NULL;
171 c->c_listener = &slap_unknown_listener;
172 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
173 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
175 LDAP_STAILQ_INIT( &c->c_ops );
177 c->c_sasl_bind_mech.bv_val = NULL;
178 c->c_sasl_bind_mech.bv_len = 0;
179 c->c_sasl_authctx = NULL;
180 c->c_sasl_sockctx = NULL;
181 c->c_sasl_extra = NULL;
183 c->c_sb = ber_sockbuf_alloc( );
185 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
187 c->c_currentber = NULL;
189 /* should check status of thread calls */
190 ldap_pvt_thread_mutex_init( &c->c_mutex );
191 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
192 ldap_pvt_thread_cond_init( &c->c_write_cv );
194 c->c_n_ops_received = 0;
195 c->c_n_ops_executing = 0;
196 c->c_n_ops_pending = 0;
197 c->c_n_ops_completed = 0;
203 c->c_protocol = LDAP_VERSION3;
205 c->c_activitytime = c->c_starttime = slap_get_time();
209 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
210 c->c_struct_state = 0x02; /* SLAP_C_USED */
212 c->c_ssf = c->c_transport_ssf = 0;
215 backend_connection_init( c );
217 pConn->c_send_ldap_result = internal_result_v3;
218 pConn->c_send_search_entry = internal_search_entry;
219 pConn->c_send_ldap_extended = internal_result_ext;
220 pConn->c_send_search_reference = internal_search_reference;
225 static void slapiConnectionDestroy( Connection **pConn )
227 Connection *conn = *pConn;
230 if ( pConn == NULL ) {
234 op = (Operation *)conn->c_pending_ops.stqh_first;
236 if ( op->o_req_dn.bv_val != NULL ) {
237 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
239 if ( op->o_req_ndn.bv_val != NULL ) {
240 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
243 if ( conn->c_sb != NULL ) {
244 ber_sockbuf_free( conn->c_sb );
247 slapi_ch_free( (void **)&op );
249 slapi_ch_free( (void **)pConn );
253 * Function : values2obj
254 * Convert an array of strings into a BerVarray.
265 if ( ppValue == NULL ) {
270 for ( i = 0; ppValue[i] != NULL; i++ )
273 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
274 if ( tmpberval == NULL ) {
275 return LDAP_NO_MEMORY;
277 for ( i = 0; ppValue[i] != NULL; i++ ) {
278 size_t len = strlen( ppValue[i] );
280 tmpberval[i].bv_val = slapi_ch_malloc( len + 1 );
281 AC_MEMCPY( tmpberval[i].bv_val, ppValue[i], len + 1 );
282 tmpberval[i].bv_len = len;
284 tmpberval[i].bv_val = NULL;
285 tmpberval[i].bv_len = 0;
294 struct berval **bvptr,
297 int rc = LDAP_SUCCESS;
301 if ( bvptr == NULL || *bvptr == NULL ) {
305 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
309 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
310 if ( tmpberval == NULL ) {
311 return LDAP_NO_MEMORY;
314 for ( i = 0; bvptr[i] != NULL; i++ ) {
315 tmpberval[i].bv_val = slapi_ch_malloc( bvptr[i]->bv_len );
316 tmpberval[i].bv_len = bvptr[i]->bv_len;
317 AC_MEMCPY( tmpberval[i].bv_val, bvptr[i]->bv_val, bvptr[i]->bv_len );
319 tmpberval[i].bv_val = NULL;
320 tmpberval[i].bv_len = 0;
322 if ( rc == LDAP_SUCCESS ) {
330 * Function : LDAPModToEntry
331 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
332 * with a link list of the correspondent attributes.
333 * Return value : LDAP_SUCCESS
342 struct berval dn = { 0, NULL };
348 Modifications *modlist = NULL;
349 Modifications **modtail = &modlist;
352 int rc = LDAP_SUCCESS;
355 const char *text = NULL;
358 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
363 op->o_tag = LDAP_REQ_ADD;
365 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
366 if ( pEntry == NULL) {
371 dn.bv_val = slapi_ch_strdup(ldn);
372 dn.bv_len = strlen(ldn);
374 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
375 if ( rc != LDAP_SUCCESS ) {
379 if ( rc == LDAP_SUCCESS ) {
380 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
383 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
385 * Convert an array of pointers to bervals to
386 * an array of bervals. Note that we need to copy the
387 * values too, as the slap_mods_check() will free the
388 * original values after prettying; the modifications
389 * being passed in may not have been allocated on the
392 rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
393 if ( rc != LDAP_SUCCESS ) goto cleanup;
394 tmp.sml_type.bv_val = pMod->mod_type;
395 tmp.sml_type.bv_len = strlen( pMod->mod_type );
396 tmp.sml_bvalues = bv;
397 tmp.sml_nvalues = NULL;
399 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
401 mod->sml_op = LDAP_MOD_ADD;
402 mod->sml_next = NULL;
403 mod->sml_desc = NULL;
404 mod->sml_type = tmp.sml_type;
405 mod->sml_bvalues = tmp.sml_bvalues;
406 mod->sml_nvalues = tmp.sml_nvalues;
409 modtail = &mod->sml_next;
412 /* attr values are in string format, need to be converted */
413 /* to an array of bervals */
414 if ( pMod->mod_values == NULL ) {
417 rc = values2obj_copy( pMod->mod_values, &bv );
418 if ( rc != LDAP_SUCCESS ) goto cleanup;
419 tmp.sml_type.bv_val = pMod->mod_type;
420 tmp.sml_type.bv_len = strlen( pMod->mod_type );
421 tmp.sml_bvalues = bv;
422 tmp.sml_nvalues = NULL;
424 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
426 mod->sml_op = LDAP_MOD_ADD;
427 mod->sml_next = NULL;
428 mod->sml_desc = NULL;
429 mod->sml_type = tmp.sml_type;
430 mod->sml_bvalues = tmp.sml_bvalues;
431 mod->sml_nvalues = tmp.sml_nvalues;
434 modtail = &mod->sml_next;
437 } /* for each LDAPMod */
440 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
441 if ( op->o_bd == NULL ) {
442 rc = LDAP_PARTIAL_RESULTS;
444 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
445 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
446 int update = op->o_bd->be_update_ndn.bv_len;
447 char textbuf[SLAP_TEXT_BUFLEN];
448 size_t textlen = sizeof textbuf;
450 rc = slap_mods_check( modlist, update, &text,
451 textbuf, textlen, NULL );
452 if ( rc != LDAP_SUCCESS) {
457 rc = slap_mods_opattrs( op,
458 modlist, modtail, &text,
460 if ( rc != LDAP_SUCCESS) {
465 rc = slap_mods2entry( modlist, &pEntry, repl_user,
466 0, &text, textbuf, textlen );
467 if (rc != LDAP_SUCCESS) {
479 slapi_ch_free( (void **)&dn.bv_val );
481 slapi_ch_free( (void **)&op );
482 if ( modlist != NULL )
483 slap_mods_free( modlist );
484 if ( rc != LDAP_SUCCESS ) {
485 if ( pEntry != NULL ) {
486 slapi_entry_free( pEntry );
494 /* Function : slapi_delete_internal
496 * Description : Plugin functions call this routine to delete an entry
497 * in the backend directly
498 * Return values : LDAP_SUCCESS
502 * LDAP_UNWILLING_TO_PERFORM
505 slapi_delete_internal(
507 LDAPControl **controls,
511 Connection *pConn = NULL;
512 Operation *op = NULL;
513 Slapi_PBlock *pPB = NULL;
514 Slapi_PBlock *pSavePB = NULL;
515 SlapReply rs = { REP_RESULT };
516 struct berval dn = { 0, NULL };
522 rs.sr_err = LDAP_PARAM_ERROR;
526 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
528 rs.sr_err = LDAP_NO_MEMORY;
532 op = (Operation *)pConn->c_pending_ops.stqh_first;
533 pPB = (Slapi_PBlock *)op->o_pb;
534 op->o_ctrls = controls;
536 dn.bv_val = slapi_ch_strdup(ldn);
537 dn.bv_len = strlen(ldn);
538 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
539 if ( rs.sr_err != LDAP_SUCCESS )
542 if ( slapi_control_present( controls,
543 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
547 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
548 if ( op->o_bd == NULL ) {
549 rs.sr_err = LDAP_PARTIAL_RESULTS;
553 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
554 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
556 if ( op->o_bd->be_delete ) {
557 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
558 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
559 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
564 rs.sr_err = LDAP_OTHER;
567 rs.sr_err = LDAP_REFERRAL;
570 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
575 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
578 slapi_ch_free( (void **)&dn.bv_val );
580 if ( pConn != NULL ) {
584 slapiConnectionDestroy( &pConn );
589 #endif /* LDAP_SLAPI */
593 static Slapi_PBlock *
594 slapi_add_entry_internal_locked(
596 LDAPControl **controls,
599 Connection *pConn = NULL;
600 Operation *op = NULL;
601 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
605 SlapReply rs = { REP_RESULT };
608 rs.sr_err = LDAP_PARAM_ERROR;
612 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
613 if ( pConn == NULL ) {
614 rs.sr_err = LDAP_NO_MEMORY;
618 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
619 NULL, &isCritical ) ) {
623 op = (Operation *)pConn->c_pending_ops.stqh_first;
624 pPB = (Slapi_PBlock *)op->o_pb;
625 op->o_ctrls = controls;
627 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
628 if ( op->o_bd == NULL ) {
629 rs.sr_err = LDAP_PARTIAL_RESULTS;
633 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
634 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
635 op->oq_add.rs_e = *e;
637 if ( op->o_bd->be_add ) {
638 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
639 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
640 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
644 be_entry_release_w( op, *e );
648 rs.sr_err = LDAP_REFERRAL;
651 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
657 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
660 if ( pConn != NULL ) {
664 slapiConnectionDestroy( &pConn );
668 #endif /* LDAP_SLAPI */
671 slapi_add_entry_internal(
673 LDAPControl **controls,
681 * We make a copy to avoid an entry that may be freed later
682 * by the caller being placed in the cache.
684 entry = slapi_entry_dup( e );
685 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
686 if ( entry != NULL ) {
687 slapi_entry_free( entry );
699 LDAPControl **controls,
703 LDAPMod *pMod = NULL;
704 Slapi_PBlock *pb = NULL;
705 Entry *pEntry = NULL;
706 int i, rc = LDAP_SUCCESS;
708 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
709 rc = LDAP_PARAM_ERROR ;
712 if ( rc == LDAP_SUCCESS ) {
713 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
714 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
721 if ( rc == LDAP_SUCCESS ) {
722 pEntry = LDAPModToEntry( dn, mods );
723 if ( pEntry == NULL ) {
728 if ( rc != LDAP_SUCCESS ) {
729 pb = slapi_pblock_new();
730 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
732 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
735 if ( pEntry != NULL ) {
736 slapi_entry_free(pEntry);
742 #endif /* LDAP_SLAPI */
745 /* Function : slapi_modrdn_internal
747 * Description : Plugin functions call this routine to modify the rdn
748 * of an entry in the backend directly
749 * Return values : LDAP_SUCCESS
753 * LDAP_UNWILLING_TO_PERFORM
755 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
758 slapi_modrdn_internal(
762 LDAPControl **controls,
766 struct berval dn = { 0, NULL };
767 struct berval newrdn = { 0, NULL };
768 Connection *pConn = NULL;
769 Operation *op = NULL;
770 Slapi_PBlock *pPB = NULL;
771 Slapi_PBlock *pSavePB = NULL;
774 SlapReply rs = { REP_RESULT };
776 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
777 if ( pConn == NULL) {
778 rs.sr_err = LDAP_NO_MEMORY;
782 op = (Operation *)pConn->c_pending_ops.stqh_first;
783 pPB = (Slapi_PBlock *)op->o_pb;
784 op->o_ctrls = controls;
786 if ( slapi_control_present( controls,
787 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
791 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
792 if ( op->o_bd == NULL ) {
793 rs.sr_err = LDAP_PARTIAL_RESULTS;
797 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
798 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
800 dn.bv_val = slapi_ch_strdup( olddn );
801 dn.bv_len = strlen( olddn );
803 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
804 if ( rs.sr_err != LDAP_SUCCESS ) {
808 if ( op->o_req_dn.bv_len == 0 ) {
809 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
813 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
814 newrdn.bv_len = strlen( lnewrdn );
816 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
817 if ( rs.sr_err != LDAP_SUCCESS ) {
821 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
825 op->oq_modrdn.rs_newSup = NULL;
826 op->oq_modrdn.rs_nnewSup = NULL;
827 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
829 if ( op->o_bd->be_modrdn ) {
830 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
831 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
832 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
837 rs.sr_err = LDAP_OTHER;
840 rs.sr_err = LDAP_REFERRAL;
843 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
849 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
853 slapi_ch_free( (void **)&dn.bv_val );
856 slapi_ch_free( (void **)&newrdn.bv_val );
857 if ( op->oq_modrdn.rs_newrdn.bv_val )
858 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
859 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
860 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
862 if ( pConn != NULL ) {
866 slapiConnectionDestroy( &pConn );
871 #endif /* LDAP_SLAPI */
874 /* Function : slapi_modify_internal
876 * Description: Plugin functions call this routine to modify an entry
877 * in the backend directly
878 * Return values : LDAP_SUCCESS
882 * LDAP_UNWILLING_TO_PERFORM
885 slapi_modify_internal(
888 LDAPControl **controls,
893 Connection *pConn = NULL;
894 Operation *op = NULL;
895 Slapi_PBlock *pPB = NULL;
896 Slapi_PBlock *pSavePB = NULL;
898 struct berval dn = { 0, NULL };
905 Modifications *modlist = NULL;
906 Modifications **modtail = &modlist;
909 SlapReply rs = { REP_RESULT };
911 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
912 rs.sr_err = LDAP_PARAM_ERROR ;
916 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
917 if ( pConn == NULL ) {
918 rs.sr_err = LDAP_NO_MEMORY;
922 op = (Operation *)pConn->c_pending_ops.stqh_first;
923 pPB = (Slapi_PBlock *)op->o_pb;
924 op->o_ctrls = controls;
926 dn.bv_val = slapi_ch_strdup( ldn );
927 dn.bv_len = strlen( ldn );
928 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
929 if ( rs.sr_err != LDAP_SUCCESS ) {
933 if ( slapi_control_present( controls,
934 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
938 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
939 if ( op->o_bd == NULL ) {
940 rs.sr_err = LDAP_PARTIAL_RESULTS;
944 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
945 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
947 for ( i = 0, pMod = mods[0];
948 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
953 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
955 * attr values are in berval format
956 * convert an array of pointers to bervals
957 * to an array of bervals
959 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
960 if ( rs.sr_err != LDAP_SUCCESS )
962 tmp.sml_type.bv_val = pMod->mod_type;
963 tmp.sml_type.bv_len = strlen( pMod->mod_type );
964 tmp.sml_bvalues = bv;
965 tmp.sml_nvalues = NULL;
967 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
969 mod->sml_op = pMod->mod_op;
970 mod->sml_next = NULL;
971 mod->sml_desc = NULL;
972 mod->sml_type = tmp.sml_type;
973 mod->sml_bvalues = tmp.sml_bvalues;
974 mod->sml_nvalues = tmp.sml_nvalues;
976 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
977 if ( rs.sr_err != LDAP_SUCCESS )
979 tmp.sml_type.bv_val = pMod->mod_type;
980 tmp.sml_type.bv_len = strlen( pMod->mod_type );
981 tmp.sml_bvalues = bv;
982 tmp.sml_nvalues = NULL;
984 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
986 mod->sml_op = pMod->mod_op;
987 mod->sml_next = NULL;
988 mod->sml_desc = NULL;
989 mod->sml_type = tmp.sml_type;
990 mod->sml_bvalues = tmp.sml_bvalues;
991 mod->sml_nvalues = tmp.sml_nvalues;
994 modtail = &mod->sml_next;
996 switch( pMod->mod_op ) {
998 if ( mod->sml_bvalues == NULL ) {
999 rs.sr_err = LDAP_PROTOCOL_ERROR;
1004 case LDAP_MOD_DELETE:
1005 case LDAP_MOD_REPLACE:
1009 rs.sr_err = LDAP_PROTOCOL_ERROR;
1015 if ( op->o_req_ndn.bv_len == 0 ) {
1016 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1020 op->oq_modify.rs_modlist = modlist;
1022 if ( op->o_bd->be_modify ) {
1023 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1024 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1025 int update = op->o_bd->be_update_ndn.bv_len;
1026 const char *text = NULL;
1027 char textbuf[SLAP_TEXT_BUFLEN];
1028 size_t textlen = sizeof( textbuf );
1030 rs.sr_err = slap_mods_check( modlist, update,
1031 &text, textbuf, textlen, NULL );
1032 if ( rs.sr_err != LDAP_SUCCESS ) {
1037 rs.sr_err = slap_mods_opattrs( op, modlist,
1038 modtail, &text, textbuf,
1040 if ( rs.sr_err != LDAP_SUCCESS ) {
1044 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1049 rs.sr_err = LDAP_OTHER;
1052 rs.sr_err = LDAP_REFERRAL;
1055 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1061 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1064 slapi_ch_free( (void **)&dn.bv_val );
1066 if ( modlist != NULL )
1067 slap_mods_free( modlist );
1069 if ( pConn != NULL ) {
1073 slapiConnectionDestroy( &pConn );
1078 #endif /* LDAP_SLAPI */
1082 slapi_search_internal_bind(
1087 LDAPControl **controls,
1093 Operation *op = NULL;
1094 Slapi_PBlock *ptr = NULL;
1095 Slapi_PBlock *pSavePB = NULL;
1096 struct berval dn = { 0, NULL };
1097 Filter *filter=NULL;
1098 struct berval fstr = { 0, NULL };
1099 AttributeName *an = NULL;
1100 const char *text = NULL;
1102 int manageDsaIt = 0;
1106 SlapReply rs = { REP_RESULT };
1108 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1110 rs.sr_err = LDAP_NO_MEMORY;
1114 op = (Operation *)c->c_pending_ops.stqh_first;
1115 ptr = (Slapi_PBlock *)op->o_pb;
1116 op->o_ctrls = controls;
1118 if ( ldn != NULL ) {
1119 dn.bv_val = slapi_ch_strdup(ldn);
1120 dn.bv_len = strlen(ldn);
1123 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1124 if ( rs.sr_err != LDAP_SUCCESS ) {
1128 if ( scope != LDAP_SCOPE_BASE &&
1129 scope != LDAP_SCOPE_ONELEVEL &&
1130 scope != LDAP_SCOPE_SUBTREE ) {
1131 rs.sr_err = LDAP_PROTOCOL_ERROR;
1135 filter = slapi_str2filter(filStr);
1136 if ( filter == NULL ) {
1137 rs.sr_err = LDAP_PROTOCOL_ERROR;
1141 filter2bv( filter, &fstr );
1143 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1144 ; /* count the number of attributes */
1148 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1149 for (i = 0; attrs[i] != 0; i++) {
1150 an[i].an_desc = NULL;
1152 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1153 an[i].an_name.bv_len = strlen(attrs[i]);
1154 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1156 an[i].an_name.bv_val = NULL;
1159 memset( &rs, 0, sizeof(rs) );
1160 rs.sr_type = REP_RESULT;
1161 rs.sr_err = LDAP_SUCCESS;
1162 rs.sr_entry = NULL; /* paranoia */
1164 if ( scope == LDAP_SCOPE_BASE ) {
1167 if ( op->o_req_ndn.bv_len == 0 ) {
1168 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1171 if( rs.sr_err != LDAP_SUCCESS ) {
1172 send_ldap_result( op, &rs );
1174 } else if ( rs.sr_entry != NULL ) {
1175 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1177 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1178 rs.sr_type = REP_SEARCH;
1179 rs.sr_err = LDAP_SUCCESS;
1182 send_search_entry( op, &rs );
1185 entry_free( rs.sr_entry );
1187 rs.sr_type = REP_RESULT;
1188 rs.sr_err = LDAP_SUCCESS;
1190 send_ldap_result( op, &rs );
1196 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1197 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1198 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1200 ber_dupbv( &op->o_req_dn, &default_search_base );
1201 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1204 if ( slapi_control_present( controls,
1205 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1209 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1210 if ( op->o_bd == NULL ) {
1211 if ( manageDsaIt == 1 ) {
1212 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1214 rs.sr_err = LDAP_PARTIAL_RESULTS;
1219 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1220 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1222 op->oq_search.rs_scope = scope;
1223 op->oq_search.rs_deref = 0;
1224 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1225 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1226 op->oq_search.rs_attrsonly = attrsonly;
1227 op->oq_search.rs_attrs = an;
1228 op->oq_search.rs_filter = filter;
1229 op->oq_search.rs_filterstr = fstr;
1231 if ( op->o_bd->be_search ) {
1232 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1233 rs.sr_err = LDAP_OTHER;
1236 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1242 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1245 slapi_ch_free( (void **)&dn.bv_val );
1247 slapi_filter_free( filter, 1 );
1249 slapi_ch_free( (void **)&fstr.bv_val );
1251 slapi_ch_free( (void **)&an );
1257 slapiConnectionDestroy( &c );
1262 #endif /* LDAP_SLAPI */
1266 slapi_search_internal(
1270 LDAPControl **controls,
1275 return slapi_search_internal_bind( NULL, base, scope, filStr,
1276 controls, attrs, attrsonly );
1279 #endif /* LDAP_SLAPI */