2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2003 The OpenLDAP Foundation.
5 * Portions Copyright 1997,2002-2003 IBM Corporation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by IBM Corporation for use in
18 * IBM products and subsequently ported to OpenLDAP Software by
19 * Steve Omrani. Additional significant contributors include:
25 #include <ac/string.h>
26 #include <ac/stdarg.h>
28 #include <ac/unistd.h>
35 * use a fake listener when faking a connection,
36 * so it can be used in ACLs
38 static struct slap_listener slap_unknown_listener = {
39 BER_BVC("unknown"), /* FIXME: use a URI form? (e.g. slapi://) */
49 /* XXX needs review after internal API change */
50 /* rs->sr_nentries appears to always be 0 */
51 if (op->o_tag == LDAP_REQ_SEARCH)
52 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
53 SLAPI_NENTRIES, (void *)rs->sr_nentries );
60 internal_search_entry(
64 int nentries = 0, len = 0, i = 0;
65 Slapi_Entry **head = NULL, **tp;
68 entry = slapi_entry_dup( rs->sr_entry );
69 if ( entry == NULL ) {
73 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
74 SLAPI_NENTRIES, &nentries );
75 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
76 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
79 if ( nentries == 0 ) {
80 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
82 slapi_entry_free( entry );
88 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
89 sizeof(Slapi_Entry *) * ( i + 1 ) );
91 slapi_entry_free( entry );
98 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
99 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
100 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
101 SLAPI_NENTRIES, (void *)i );
115 internal_search_reference(
127 Connection *pConn, *c;
128 ber_len_t max = sockbuf_max_incoming;
130 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
132 return (Connection *)NULL;
135 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
137 pConn->c_pending_ops.stqh_first =
138 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
139 if ( pConn->c_pending_ops.stqh_first == NULL ) {
140 slapi_ch_free( (void **)&pConn );
141 return (Connection *)NULL;
144 pConn->c_pending_ops.stqh_first->o_pb =
145 (Slapi_PBlock *) slapi_pblock_new();
146 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
147 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
148 slapi_ch_free( (void **)&pConn );
149 return (Connection *)NULL;
154 /* operation object */
155 c->c_pending_ops.stqh_first->o_tag = OpType;
156 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
157 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
158 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
159 c->c_pending_ops.stqh_first->o_time = slap_get_time();
160 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
161 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context();
162 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
163 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
164 c->c_pending_ops.stqh_first->o_conn = c;
166 /* connection object */
167 c->c_authmech.bv_val = NULL;
168 c->c_authmech.bv_len = 0;
169 c->c_dn.bv_val = NULL;
171 c->c_ndn.bv_val = NULL;
174 c->c_listener = &slap_unknown_listener;
175 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
176 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
178 LDAP_STAILQ_INIT( &c->c_ops );
180 c->c_sasl_bind_mech.bv_val = NULL;
181 c->c_sasl_bind_mech.bv_len = 0;
182 c->c_sasl_authctx = NULL;
183 c->c_sasl_sockctx = NULL;
184 c->c_sasl_extra = NULL;
186 c->c_sb = ber_sockbuf_alloc( );
188 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
190 c->c_currentber = NULL;
192 /* should check status of thread calls */
193 ldap_pvt_thread_mutex_init( &c->c_mutex );
194 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
195 ldap_pvt_thread_cond_init( &c->c_write_cv );
197 c->c_n_ops_received = 0;
198 c->c_n_ops_executing = 0;
199 c->c_n_ops_pending = 0;
200 c->c_n_ops_completed = 0;
206 c->c_protocol = LDAP_VERSION3;
208 c->c_activitytime = c->c_starttime = slap_get_time();
212 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
213 c->c_struct_state = 0x02; /* SLAP_C_USED */
215 c->c_ssf = c->c_transport_ssf = 0;
218 backend_connection_init( c );
220 pConn->c_send_ldap_result = internal_result_v3;
221 pConn->c_send_search_entry = internal_search_entry;
222 pConn->c_send_ldap_extended = internal_result_ext;
223 pConn->c_send_search_reference = internal_search_reference;
228 static void slapiConnectionDestroy( Connection **pConn )
230 Connection *conn = *pConn;
233 if ( pConn == NULL ) {
237 op = (Operation *)conn->c_pending_ops.stqh_first;
239 if ( op->o_req_dn.bv_val != NULL ) {
240 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
242 if ( op->o_req_ndn.bv_val != NULL ) {
243 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
246 if ( conn->c_sb != NULL ) {
247 ber_sockbuf_free( conn->c_sb );
250 slapi_ch_free( (void **)&op );
252 slapi_ch_free( (void **)pConn );
256 * Function : values2obj
257 * Convert an array of strings into a BerVarray.
268 if ( ppValue == NULL ) {
273 for ( i = 0; ppValue[i] != NULL; i++ )
276 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
277 if ( tmpberval == NULL ) {
278 return LDAP_NO_MEMORY;
280 for ( i = 0; ppValue[i] != NULL; i++ ) {
281 size_t len = strlen( ppValue[i] );
283 tmpberval[i].bv_val = slapi_ch_malloc( len + 1 );
284 AC_MEMCPY( tmpberval[i].bv_val, ppValue[i], len + 1 );
285 tmpberval[i].bv_len = len;
287 tmpberval[i].bv_val = NULL;
288 tmpberval[i].bv_len = 0;
297 struct berval **bvptr,
300 int rc = LDAP_SUCCESS;
304 if ( bvptr == NULL || *bvptr == NULL ) {
308 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
312 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
313 if ( tmpberval == NULL ) {
314 return LDAP_NO_MEMORY;
317 for ( i = 0; bvptr[i] != NULL; i++ ) {
318 tmpberval[i].bv_val = slapi_ch_malloc( bvptr[i]->bv_len );
319 tmpberval[i].bv_len = bvptr[i]->bv_len;
320 AC_MEMCPY( tmpberval[i].bv_val, bvptr[i]->bv_val, bvptr[i]->bv_len );
322 tmpberval[i].bv_val = NULL;
323 tmpberval[i].bv_len = 0;
325 if ( rc == LDAP_SUCCESS ) {
333 * Function : LDAPModToEntry
334 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
335 * with a link list of the correspondent attributes.
336 * Return value : LDAP_SUCCESS
345 struct berval dn = { 0, NULL };
351 Modifications *modlist = NULL;
352 Modifications **modtail = &modlist;
355 int rc = LDAP_SUCCESS;
358 const char *text = NULL;
361 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
366 op->o_tag = LDAP_REQ_ADD;
368 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
369 if ( pEntry == NULL) {
374 dn.bv_val = slapi_ch_strdup(ldn);
375 dn.bv_len = strlen(ldn);
377 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
378 if ( rc != LDAP_SUCCESS ) {
382 if ( rc == LDAP_SUCCESS ) {
383 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
386 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
388 * Convert an array of pointers to bervals to
389 * an array of bervals. Note that we need to copy the
390 * values too, as the slap_mods_check() will free the
391 * original values after prettying; the modifications
392 * being passed in may not have been allocated on the
395 rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
396 if ( rc != LDAP_SUCCESS ) goto cleanup;
397 tmp.sml_type.bv_val = pMod->mod_type;
398 tmp.sml_type.bv_len = strlen( pMod->mod_type );
399 tmp.sml_bvalues = bv;
400 tmp.sml_nvalues = NULL;
402 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
404 mod->sml_op = LDAP_MOD_ADD;
405 mod->sml_next = NULL;
406 mod->sml_desc = NULL;
407 mod->sml_type = tmp.sml_type;
408 mod->sml_bvalues = tmp.sml_bvalues;
409 mod->sml_nvalues = tmp.sml_nvalues;
412 modtail = &mod->sml_next;
415 /* attr values are in string format, need to be converted */
416 /* to an array of bervals */
417 if ( pMod->mod_values == NULL ) {
420 rc = values2obj_copy( pMod->mod_values, &bv );
421 if ( rc != LDAP_SUCCESS ) goto cleanup;
422 tmp.sml_type.bv_val = pMod->mod_type;
423 tmp.sml_type.bv_len = strlen( pMod->mod_type );
424 tmp.sml_bvalues = bv;
425 tmp.sml_nvalues = NULL;
427 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
429 mod->sml_op = LDAP_MOD_ADD;
430 mod->sml_next = NULL;
431 mod->sml_desc = NULL;
432 mod->sml_type = tmp.sml_type;
433 mod->sml_bvalues = tmp.sml_bvalues;
434 mod->sml_nvalues = tmp.sml_nvalues;
437 modtail = &mod->sml_next;
440 } /* for each LDAPMod */
443 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
444 if ( op->o_bd == NULL ) {
445 rc = LDAP_PARTIAL_RESULTS;
447 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
448 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
449 int update = op->o_bd->be_update_ndn.bv_len;
450 char textbuf[SLAP_TEXT_BUFLEN];
451 size_t textlen = sizeof textbuf;
453 rc = slap_mods_check( modlist, update, &text,
454 textbuf, textlen, NULL );
455 if ( rc != LDAP_SUCCESS) {
460 rc = slap_mods_opattrs( op,
461 modlist, modtail, &text,
463 if ( rc != LDAP_SUCCESS) {
468 rc = slap_mods2entry( modlist, &pEntry, repl_user,
469 0, &text, textbuf, textlen );
470 if (rc != LDAP_SUCCESS) {
482 slapi_ch_free( (void **)&dn.bv_val );
484 slapi_ch_free( (void **)&op );
485 if ( modlist != NULL )
486 slap_mods_free( modlist );
487 if ( rc != LDAP_SUCCESS ) {
488 if ( pEntry != NULL ) {
489 slapi_entry_free( pEntry );
497 /* Function : slapi_delete_internal
499 * Description : Plugin functions call this routine to delete an entry
500 * in the backend directly
501 * Return values : LDAP_SUCCESS
505 * LDAP_UNWILLING_TO_PERFORM
508 slapi_delete_internal(
510 LDAPControl **controls,
514 Connection *pConn = NULL;
515 Operation *op = NULL;
516 Slapi_PBlock *pPB = NULL;
517 Slapi_PBlock *pSavePB = NULL;
518 SlapReply rs = { REP_RESULT };
519 struct berval dn = { 0, NULL };
525 rs.sr_err = LDAP_PARAM_ERROR;
529 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
531 rs.sr_err = LDAP_NO_MEMORY;
535 op = (Operation *)pConn->c_pending_ops.stqh_first;
536 pPB = (Slapi_PBlock *)op->o_pb;
537 op->o_ctrls = controls;
539 dn.bv_val = slapi_ch_strdup(ldn);
540 dn.bv_len = strlen(ldn);
541 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
542 if ( rs.sr_err != LDAP_SUCCESS )
545 if ( slapi_control_present( controls,
546 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
550 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
551 if ( op->o_bd == NULL ) {
552 rs.sr_err = LDAP_PARTIAL_RESULTS;
556 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
557 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
559 if ( op->o_bd->be_delete ) {
560 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
561 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
562 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
567 rs.sr_err = LDAP_OTHER;
570 rs.sr_err = LDAP_REFERRAL;
573 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
578 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
581 slapi_ch_free( (void **)&dn.bv_val );
583 if ( pConn != NULL ) {
587 slapiConnectionDestroy( &pConn );
592 #endif /* LDAP_SLAPI */
596 static Slapi_PBlock *
597 slapi_add_entry_internal_locked(
599 LDAPControl **controls,
602 Connection *pConn = NULL;
603 Operation *op = NULL;
604 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
608 SlapReply rs = { REP_RESULT };
611 rs.sr_err = LDAP_PARAM_ERROR;
615 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
616 if ( pConn == NULL ) {
617 rs.sr_err = LDAP_NO_MEMORY;
621 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
622 NULL, &isCritical ) ) {
626 op = (Operation *)pConn->c_pending_ops.stqh_first;
627 pPB = (Slapi_PBlock *)op->o_pb;
628 op->o_ctrls = controls;
630 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
631 if ( op->o_bd == NULL ) {
632 rs.sr_err = LDAP_PARTIAL_RESULTS;
636 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
637 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
638 op->oq_add.rs_e = *e;
640 if ( op->o_bd->be_add ) {
641 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
642 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
643 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
647 be_entry_release_w( op, *e );
651 rs.sr_err = LDAP_REFERRAL;
654 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
660 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
663 if ( pConn != NULL ) {
667 slapiConnectionDestroy( &pConn );
671 #endif /* LDAP_SLAPI */
674 slapi_add_entry_internal(
676 LDAPControl **controls,
684 * We make a copy to avoid an entry that may be freed later
685 * by the caller being placed in the cache.
687 entry = slapi_entry_dup( e );
688 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
689 if ( entry != NULL ) {
690 slapi_entry_free( entry );
702 LDAPControl **controls,
706 LDAPMod *pMod = NULL;
707 Slapi_PBlock *pb = NULL;
708 Entry *pEntry = NULL;
709 int i, rc = LDAP_SUCCESS;
711 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
712 rc = LDAP_PARAM_ERROR ;
715 if ( rc == LDAP_SUCCESS ) {
716 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
717 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
724 if ( rc == LDAP_SUCCESS ) {
725 pEntry = LDAPModToEntry( dn, mods );
726 if ( pEntry == NULL ) {
731 if ( rc != LDAP_SUCCESS ) {
732 pb = slapi_pblock_new();
733 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
735 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
738 if ( pEntry != NULL ) {
739 slapi_entry_free(pEntry);
745 #endif /* LDAP_SLAPI */
748 /* Function : slapi_modrdn_internal
750 * Description : Plugin functions call this routine to modify the rdn
751 * of an entry in the backend directly
752 * Return values : LDAP_SUCCESS
756 * LDAP_UNWILLING_TO_PERFORM
758 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
761 slapi_modrdn_internal(
765 LDAPControl **controls,
769 struct berval dn = { 0, NULL };
770 struct berval newrdn = { 0, NULL };
771 Connection *pConn = NULL;
772 Operation *op = NULL;
773 Slapi_PBlock *pPB = NULL;
774 Slapi_PBlock *pSavePB = NULL;
777 SlapReply rs = { REP_RESULT };
779 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
780 if ( pConn == NULL) {
781 rs.sr_err = LDAP_NO_MEMORY;
785 op = (Operation *)pConn->c_pending_ops.stqh_first;
786 pPB = (Slapi_PBlock *)op->o_pb;
787 op->o_ctrls = controls;
789 if ( slapi_control_present( controls,
790 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
794 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
795 if ( op->o_bd == NULL ) {
796 rs.sr_err = LDAP_PARTIAL_RESULTS;
800 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
801 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
803 dn.bv_val = slapi_ch_strdup( olddn );
804 dn.bv_len = strlen( olddn );
806 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
807 if ( rs.sr_err != LDAP_SUCCESS ) {
811 if ( op->o_req_dn.bv_len == 0 ) {
812 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
816 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
817 newrdn.bv_len = strlen( lnewrdn );
819 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
820 if ( rs.sr_err != LDAP_SUCCESS ) {
824 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
828 op->oq_modrdn.rs_newSup = NULL;
829 op->oq_modrdn.rs_nnewSup = NULL;
830 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
832 if ( op->o_bd->be_modrdn ) {
833 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
834 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
835 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
840 rs.sr_err = LDAP_OTHER;
843 rs.sr_err = LDAP_REFERRAL;
846 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
852 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
856 slapi_ch_free( (void **)&dn.bv_val );
859 slapi_ch_free( (void **)&newrdn.bv_val );
860 if ( op->oq_modrdn.rs_newrdn.bv_val )
861 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
862 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
863 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
865 if ( pConn != NULL ) {
869 slapiConnectionDestroy( &pConn );
874 #endif /* LDAP_SLAPI */
877 /* Function : slapi_modify_internal
879 * Description: Plugin functions call this routine to modify an entry
880 * in the backend directly
881 * Return values : LDAP_SUCCESS
885 * LDAP_UNWILLING_TO_PERFORM
888 slapi_modify_internal(
891 LDAPControl **controls,
896 Connection *pConn = NULL;
897 Operation *op = NULL;
898 Slapi_PBlock *pPB = NULL;
899 Slapi_PBlock *pSavePB = NULL;
901 struct berval dn = { 0, NULL };
908 Modifications *modlist = NULL;
909 Modifications **modtail = &modlist;
912 SlapReply rs = { REP_RESULT };
914 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
915 rs.sr_err = LDAP_PARAM_ERROR ;
919 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
920 if ( pConn == NULL ) {
921 rs.sr_err = LDAP_NO_MEMORY;
925 op = (Operation *)pConn->c_pending_ops.stqh_first;
926 pPB = (Slapi_PBlock *)op->o_pb;
927 op->o_ctrls = controls;
929 dn.bv_val = slapi_ch_strdup( ldn );
930 dn.bv_len = strlen( ldn );
931 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
932 if ( rs.sr_err != LDAP_SUCCESS ) {
936 if ( slapi_control_present( controls,
937 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
941 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
942 if ( op->o_bd == NULL ) {
943 rs.sr_err = LDAP_PARTIAL_RESULTS;
947 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
948 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
950 for ( i = 0, pMod = mods[0];
951 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
956 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
958 * attr values are in berval format
959 * convert an array of pointers to bervals
960 * to an array of bervals
962 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
963 if ( rs.sr_err != LDAP_SUCCESS )
965 tmp.sml_type.bv_val = pMod->mod_type;
966 tmp.sml_type.bv_len = strlen( pMod->mod_type );
967 tmp.sml_bvalues = bv;
968 tmp.sml_nvalues = NULL;
970 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
972 mod->sml_op = pMod->mod_op;
973 mod->sml_next = NULL;
974 mod->sml_desc = NULL;
975 mod->sml_type = tmp.sml_type;
976 mod->sml_bvalues = tmp.sml_bvalues;
977 mod->sml_nvalues = tmp.sml_nvalues;
979 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
980 if ( rs.sr_err != LDAP_SUCCESS )
982 tmp.sml_type.bv_val = pMod->mod_type;
983 tmp.sml_type.bv_len = strlen( pMod->mod_type );
984 tmp.sml_bvalues = bv;
985 tmp.sml_nvalues = NULL;
987 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
989 mod->sml_op = pMod->mod_op;
990 mod->sml_next = NULL;
991 mod->sml_desc = NULL;
992 mod->sml_type = tmp.sml_type;
993 mod->sml_bvalues = tmp.sml_bvalues;
994 mod->sml_nvalues = tmp.sml_nvalues;
997 modtail = &mod->sml_next;
999 switch( pMod->mod_op ) {
1001 if ( mod->sml_bvalues == NULL ) {
1002 rs.sr_err = LDAP_PROTOCOL_ERROR;
1007 case LDAP_MOD_DELETE:
1008 case LDAP_MOD_REPLACE:
1012 rs.sr_err = LDAP_PROTOCOL_ERROR;
1018 if ( op->o_req_ndn.bv_len == 0 ) {
1019 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1023 op->oq_modify.rs_modlist = modlist;
1025 if ( op->o_bd->be_modify ) {
1026 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1027 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1028 int update = op->o_bd->be_update_ndn.bv_len;
1029 const char *text = NULL;
1030 char textbuf[SLAP_TEXT_BUFLEN];
1031 size_t textlen = sizeof( textbuf );
1033 rs.sr_err = slap_mods_check( modlist, update,
1034 &text, textbuf, textlen, NULL );
1035 if ( rs.sr_err != LDAP_SUCCESS ) {
1040 rs.sr_err = slap_mods_opattrs( op, modlist,
1041 modtail, &text, textbuf,
1043 if ( rs.sr_err != LDAP_SUCCESS ) {
1047 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1052 rs.sr_err = LDAP_OTHER;
1055 rs.sr_err = LDAP_REFERRAL;
1058 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1064 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1067 slapi_ch_free( (void **)&dn.bv_val );
1069 if ( modlist != NULL )
1070 slap_mods_free( modlist );
1072 if ( pConn != NULL ) {
1076 slapiConnectionDestroy( &pConn );
1081 #endif /* LDAP_SLAPI */
1085 slapi_search_internal_bind(
1090 LDAPControl **controls,
1096 Operation *op = NULL;
1097 Slapi_PBlock *ptr = NULL;
1098 Slapi_PBlock *pSavePB = NULL;
1099 struct berval dn = { 0, NULL };
1100 Filter *filter=NULL;
1101 struct berval fstr = { 0, NULL };
1102 AttributeName *an = NULL;
1103 const char *text = NULL;
1105 int manageDsaIt = 0;
1109 SlapReply rs = { REP_RESULT };
1111 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1113 rs.sr_err = LDAP_NO_MEMORY;
1117 op = (Operation *)c->c_pending_ops.stqh_first;
1118 ptr = (Slapi_PBlock *)op->o_pb;
1119 op->o_ctrls = controls;
1121 if ( ldn != NULL ) {
1122 dn.bv_val = slapi_ch_strdup(ldn);
1123 dn.bv_len = strlen(ldn);
1126 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1127 if ( rs.sr_err != LDAP_SUCCESS ) {
1131 if ( scope != LDAP_SCOPE_BASE &&
1132 scope != LDAP_SCOPE_ONELEVEL &&
1133 scope != LDAP_SCOPE_SUBTREE ) {
1134 rs.sr_err = LDAP_PROTOCOL_ERROR;
1138 filter = slapi_str2filter(filStr);
1139 if ( filter == NULL ) {
1140 rs.sr_err = LDAP_PROTOCOL_ERROR;
1144 filter2bv( filter, &fstr );
1146 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1147 ; /* count the number of attributes */
1151 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1152 for (i = 0; attrs[i] != 0; i++) {
1153 an[i].an_desc = NULL;
1155 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1156 an[i].an_name.bv_len = strlen(attrs[i]);
1157 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1159 an[i].an_name.bv_val = NULL;
1162 memset( &rs, 0, sizeof(rs) );
1163 rs.sr_type = REP_RESULT;
1164 rs.sr_err = LDAP_SUCCESS;
1165 rs.sr_entry = NULL; /* paranoia */
1167 if ( scope == LDAP_SCOPE_BASE ) {
1170 if ( op->o_req_ndn.bv_len == 0 ) {
1171 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1174 if( rs.sr_err != LDAP_SUCCESS ) {
1175 send_ldap_result( op, &rs );
1177 } else if ( rs.sr_entry != NULL ) {
1178 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1180 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1181 rs.sr_type = REP_SEARCH;
1182 rs.sr_err = LDAP_SUCCESS;
1185 send_search_entry( op, &rs );
1188 entry_free( rs.sr_entry );
1190 rs.sr_type = REP_RESULT;
1191 rs.sr_err = LDAP_SUCCESS;
1193 send_ldap_result( op, &rs );
1199 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1200 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1201 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1203 ber_dupbv( &op->o_req_dn, &default_search_base );
1204 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1207 if ( slapi_control_present( controls,
1208 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1212 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1213 if ( op->o_bd == NULL ) {
1214 if ( manageDsaIt == 1 ) {
1215 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1217 rs.sr_err = LDAP_PARTIAL_RESULTS;
1222 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1223 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1225 op->oq_search.rs_scope = scope;
1226 op->oq_search.rs_deref = 0;
1227 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1228 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1229 op->oq_search.rs_attrsonly = attrsonly;
1230 op->oq_search.rs_attrs = an;
1231 op->oq_search.rs_filter = filter;
1232 op->oq_search.rs_filterstr = fstr;
1234 if ( op->o_bd->be_search ) {
1235 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1236 rs.sr_err = LDAP_OTHER;
1239 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1245 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1248 slapi_ch_free( (void **)&dn.bv_val );
1250 slapi_filter_free( filter, 1 );
1252 slapi_ch_free( (void **)&fstr.bv_val );
1254 slapi_ch_free( (void **)&an );
1260 slapiConnectionDestroy( &c );
1265 #endif /* LDAP_SLAPI */
1269 slapi_search_internal(
1273 LDAPControl **controls,
1278 return slapi_search_internal_bind( NULL, base, scope, filStr,
1279 controls, attrs, attrsonly );
1282 #endif /* LDAP_SLAPI */