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(
63 int nentries = 0, len = 0, i = 0;
64 Slapi_Entry **head = NULL, **tp;
66 ent2str = slapi_entry2str( rs->sr_entry, &len );
67 if ( ent2str == 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 *) );
83 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
84 if ( tp[ 0 ] == NULL ) {
89 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
90 sizeof(Slapi_Entry *) * ( i + 1 ) );
94 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
95 if ( tp[ i - 1 ] == NULL ) {
101 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
102 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
103 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
104 SLAPI_NENTRIES, (void *)i );
118 internal_search_reference(
130 Connection *pConn, *c;
131 ber_len_t max = sockbuf_max_incoming;
133 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
135 return (Connection *)NULL;
138 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
140 pConn->c_pending_ops.stqh_first =
141 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
142 if ( pConn->c_pending_ops.stqh_first == NULL ) {
143 slapi_ch_free( (void **)&pConn );
144 return (Connection *)NULL;
147 pConn->c_pending_ops.stqh_first->o_pb =
148 (Slapi_PBlock *) slapi_pblock_new();
149 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
150 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
151 slapi_ch_free( (void **)&pConn );
152 return (Connection *)NULL;
157 /* operation object */
158 c->c_pending_ops.stqh_first->o_tag = OpType;
159 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
160 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
161 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
162 c->c_pending_ops.stqh_first->o_time = slap_get_time();
163 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
164 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context();
165 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
166 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
167 c->c_pending_ops.stqh_first->o_conn = c;
169 /* connection object */
170 c->c_authmech.bv_val = NULL;
171 c->c_authmech.bv_len = 0;
172 c->c_dn.bv_val = NULL;
174 c->c_ndn.bv_val = NULL;
178 c->c_listener = &slap_unknown_listener;
179 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
180 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
182 LDAP_STAILQ_INIT( &c->c_ops );
184 c->c_sasl_bind_mech.bv_val = NULL;
185 c->c_sasl_bind_mech.bv_len = 0;
186 c->c_sasl_authctx = NULL;
187 c->c_sasl_sockctx = NULL;
188 c->c_sasl_extra = NULL;
190 c->c_sb = ber_sockbuf_alloc( );
192 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
194 c->c_currentber = NULL;
196 /* should check status of thread calls */
197 ldap_pvt_thread_mutex_init( &c->c_mutex );
198 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
199 ldap_pvt_thread_cond_init( &c->c_write_cv );
201 c->c_n_ops_received = 0;
202 c->c_n_ops_executing = 0;
203 c->c_n_ops_pending = 0;
204 c->c_n_ops_completed = 0;
210 c->c_protocol = LDAP_VERSION3;
212 c->c_activitytime = c->c_starttime = slap_get_time();
216 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
217 c->c_struct_state = 0x02; /* SLAP_C_USED */
219 c->c_ssf = c->c_transport_ssf = 0;
222 backend_connection_init( c );
224 pConn->c_send_ldap_result = internal_result_v3;
225 pConn->c_send_search_entry = internal_search_entry;
226 pConn->c_send_ldap_extended = internal_result_ext;
227 pConn->c_send_search_reference = internal_search_reference;
232 static void slapiConnectionDestroy( Connection **pConn )
234 Connection *conn = *pConn;
237 if ( pConn == NULL ) {
241 op = (Operation *)conn->c_pending_ops.stqh_first;
243 if ( op->o_req_dn.bv_val != NULL ) {
244 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
246 if ( op->o_req_ndn.bv_val != NULL ) {
247 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
250 if ( conn->c_sb != NULL ) {
251 ber_sockbuf_free( conn->c_sb );
254 slapi_ch_free( (void **)&op );
256 slapi_ch_free( (void **)pConn );
260 * Function : values2obj
261 * Convert an array of strings into a BerVarray.
272 if ( ppValue == NULL ) {
277 for ( i = 0; ppValue[i] != NULL; i++ )
280 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
281 if ( tmpberval == NULL ) {
282 return LDAP_NO_MEMORY;
284 for ( i = 0; ppValue[i] != NULL; i++ ) {
285 size_t len = strlen( ppValue[i] );
287 tmpberval[i].bv_val = slapi_ch_malloc( len + 1 );
288 AC_MEMCPY( tmpberval[i].bv_val, ppValue[i], len + 1 );
289 tmpberval[i].bv_len = len;
291 tmpberval[i].bv_val = NULL;
292 tmpberval[i].bv_len = 0;
301 struct berval **bvptr,
304 int rc = LDAP_SUCCESS;
308 if ( bvptr == NULL || *bvptr == NULL ) {
312 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
316 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
317 if ( tmpberval == NULL ) {
318 return LDAP_NO_MEMORY;
321 for ( i = 0; bvptr[i] != NULL; i++ ) {
322 tmpberval[i].bv_val = slapi_ch_malloc( bvptr[i]->bv_len );
323 tmpberval[i].bv_len = bvptr[i]->bv_len;
324 AC_MEMCPY( tmpberval[i].bv_val, bvptr[i]->bv_val, bvptr[i]->bv_len );
326 tmpberval[i].bv_val = NULL;
327 tmpberval[i].bv_len = 0;
329 if ( rc == LDAP_SUCCESS ) {
337 * Function : LDAPModToEntry
338 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
339 * with a link list of the correspondent attributes.
340 * Return value : LDAP_SUCCESS
349 struct berval dn = { 0, NULL };
355 Modifications *modlist = NULL;
356 Modifications **modtail = &modlist;
359 int rc = LDAP_SUCCESS;
362 const char *text = NULL;
365 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
370 op->o_tag = LDAP_REQ_ADD;
372 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
373 if ( pEntry == NULL) {
378 dn.bv_val = slapi_ch_strdup(ldn);
379 dn.bv_len = strlen(ldn);
381 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
382 if ( rc != LDAP_SUCCESS ) {
386 if ( rc == LDAP_SUCCESS ) {
387 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
390 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
392 * Convert an array of pointers to bervals to
393 * an array of bervals. Note that we need to copy the
394 * values too, as the slap_mods_check() will free the
395 * original values after prettying; the modifications
396 * being passed in may not have been allocated on the
399 rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
400 if ( rc != LDAP_SUCCESS ) goto cleanup;
401 tmp.sml_type.bv_val = pMod->mod_type;
402 tmp.sml_type.bv_len = strlen( pMod->mod_type );
403 tmp.sml_bvalues = bv;
404 tmp.sml_nvalues = NULL;
406 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
408 mod->sml_op = LDAP_MOD_ADD;
409 mod->sml_next = NULL;
410 mod->sml_desc = NULL;
411 mod->sml_type = tmp.sml_type;
412 mod->sml_bvalues = tmp.sml_bvalues;
413 mod->sml_nvalues = tmp.sml_nvalues;
416 modtail = &mod->sml_next;
419 /* attr values are in string format, need to be converted */
420 /* to an array of bervals */
421 if ( pMod->mod_values == NULL ) {
424 rc = values2obj_copy( pMod->mod_values, &bv );
425 if ( rc != LDAP_SUCCESS ) goto cleanup;
426 tmp.sml_type.bv_val = pMod->mod_type;
427 tmp.sml_type.bv_len = strlen( pMod->mod_type );
428 tmp.sml_bvalues = bv;
429 tmp.sml_nvalues = NULL;
431 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
433 mod->sml_op = LDAP_MOD_ADD;
434 mod->sml_next = NULL;
435 mod->sml_desc = NULL;
436 mod->sml_type = tmp.sml_type;
437 mod->sml_bvalues = tmp.sml_bvalues;
438 mod->sml_nvalues = tmp.sml_nvalues;
441 modtail = &mod->sml_next;
444 } /* for each LDAPMod */
447 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
448 if ( op->o_bd == NULL ) {
449 rc = LDAP_PARTIAL_RESULTS;
451 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
452 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
453 int update = op->o_bd->be_update_ndn.bv_len;
454 char textbuf[SLAP_TEXT_BUFLEN];
455 size_t textlen = sizeof textbuf;
457 rc = slap_mods_check( modlist, update, &text,
458 textbuf, textlen, NULL );
459 if ( rc != LDAP_SUCCESS) {
464 rc = slap_mods_opattrs( op,
465 modlist, modtail, &text,
467 if ( rc != LDAP_SUCCESS) {
472 rc = slap_mods2entry( modlist, &pEntry, repl_user,
473 0, &text, textbuf, textlen );
474 if (rc != LDAP_SUCCESS) {
486 slapi_ch_free( (void **)&dn.bv_val );
488 slapi_ch_free( (void **)&op );
489 if ( modlist != NULL )
490 slap_mods_free( modlist );
491 if ( rc != LDAP_SUCCESS ) {
492 if ( pEntry != NULL ) {
493 slapi_entry_free( pEntry );
501 /* Function : slapi_delete_internal
503 * Description : Plugin functions call this routine to delete an entry
504 * in the backend directly
505 * Return values : LDAP_SUCCESS
509 * LDAP_UNWILLING_TO_PERFORM
512 slapi_delete_internal(
514 LDAPControl **controls,
518 Connection *pConn = NULL;
519 Operation *op = NULL;
520 Slapi_PBlock *pPB = NULL;
521 Slapi_PBlock *pSavePB = NULL;
522 SlapReply rs = { REP_RESULT };
523 struct berval dn = { 0, NULL };
529 rs.sr_err = LDAP_PARAM_ERROR;
533 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
535 rs.sr_err = LDAP_NO_MEMORY;
539 op = (Operation *)pConn->c_pending_ops.stqh_first;
540 pPB = (Slapi_PBlock *)op->o_pb;
541 op->o_ctrls = controls;
543 dn.bv_val = slapi_ch_strdup(ldn);
544 dn.bv_len = strlen(ldn);
545 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
546 if ( rs.sr_err != LDAP_SUCCESS )
549 if ( slapi_control_present( controls,
550 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
554 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
555 if ( op->o_bd == NULL ) {
556 rs.sr_err = LDAP_PARTIAL_RESULTS;
560 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
561 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
563 if ( op->o_bd->be_delete ) {
564 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
565 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
566 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
571 rs.sr_err = LDAP_OTHER;
574 rs.sr_err = LDAP_REFERRAL;
577 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
582 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
585 slapi_ch_free( (void **)&dn.bv_val );
587 if ( pConn != NULL ) {
591 slapiConnectionDestroy( &pConn );
596 #endif /* LDAP_SLAPI */
600 static Slapi_PBlock *
601 slapi_add_entry_internal_locked(
603 LDAPControl **controls,
606 Connection *pConn = NULL;
607 Operation *op = NULL;
608 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
612 SlapReply rs = { REP_RESULT };
615 rs.sr_err = LDAP_PARAM_ERROR;
619 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
620 if ( pConn == NULL ) {
621 rs.sr_err = LDAP_NO_MEMORY;
625 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
626 NULL, &isCritical ) ) {
630 op = (Operation *)pConn->c_pending_ops.stqh_first;
631 pPB = (Slapi_PBlock *)op->o_pb;
632 op->o_ctrls = controls;
634 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
635 if ( op->o_bd == NULL ) {
636 rs.sr_err = LDAP_PARTIAL_RESULTS;
640 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
641 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
642 op->oq_add.rs_e = *e;
644 if ( op->o_bd->be_add ) {
645 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
646 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
647 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
651 be_entry_release_w( op, *e );
655 rs.sr_err = LDAP_REFERRAL;
658 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
664 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
667 if ( pConn != NULL ) {
671 slapiConnectionDestroy( &pConn );
675 #endif /* LDAP_SLAPI */
678 slapi_add_entry_internal(
680 LDAPControl **controls,
688 * We make a copy to avoid an entry that may be freed later
689 * by the caller being placed in the cache.
691 entry = slapi_entry_dup( e );
692 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
693 if ( entry != NULL ) {
694 slapi_entry_free( entry );
706 LDAPControl **controls,
710 LDAPMod *pMod = NULL;
711 Slapi_PBlock *pb = NULL;
712 Entry *pEntry = NULL;
713 int i, rc = LDAP_SUCCESS;
715 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
716 rc = LDAP_PARAM_ERROR ;
719 if ( rc == LDAP_SUCCESS ) {
720 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
721 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
728 if ( rc == LDAP_SUCCESS ) {
729 pEntry = LDAPModToEntry( dn, mods );
730 if ( pEntry == NULL ) {
735 if ( rc != LDAP_SUCCESS ) {
736 pb = slapi_pblock_new();
737 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
739 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
742 if ( pEntry != NULL ) {
743 slapi_entry_free(pEntry);
749 #endif /* LDAP_SLAPI */
752 /* Function : slapi_modrdn_internal
754 * Description : Plugin functions call this routine to modify the rdn
755 * of an entry in the backend directly
756 * Return values : LDAP_SUCCESS
760 * LDAP_UNWILLING_TO_PERFORM
762 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
765 slapi_modrdn_internal(
769 LDAPControl **controls,
773 struct berval dn = { 0, NULL };
774 struct berval newrdn = { 0, NULL };
775 Connection *pConn = NULL;
776 Operation *op = NULL;
777 Slapi_PBlock *pPB = NULL;
778 Slapi_PBlock *pSavePB = NULL;
781 SlapReply rs = { REP_RESULT };
783 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
784 if ( pConn == NULL) {
785 rs.sr_err = LDAP_NO_MEMORY;
789 op = (Operation *)pConn->c_pending_ops.stqh_first;
790 pPB = (Slapi_PBlock *)op->o_pb;
791 op->o_ctrls = controls;
793 if ( slapi_control_present( controls,
794 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
798 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
799 if ( op->o_bd == NULL ) {
800 rs.sr_err = LDAP_PARTIAL_RESULTS;
804 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
805 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
807 dn.bv_val = slapi_ch_strdup( olddn );
808 dn.bv_len = strlen( olddn );
810 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
811 if ( rs.sr_err != LDAP_SUCCESS ) {
815 if ( op->o_req_dn.bv_len == 0 ) {
816 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
820 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
821 newrdn.bv_len = strlen( lnewrdn );
823 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
824 if ( rs.sr_err != LDAP_SUCCESS ) {
828 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
832 op->oq_modrdn.rs_newSup = NULL;
833 op->oq_modrdn.rs_nnewSup = NULL;
834 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
836 if ( op->o_bd->be_modrdn ) {
837 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
838 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
839 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
844 rs.sr_err = LDAP_OTHER;
847 rs.sr_err = LDAP_REFERRAL;
850 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
856 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
860 slapi_ch_free( (void **)&dn.bv_val );
863 slapi_ch_free( (void **)&newrdn.bv_val );
864 if ( op->oq_modrdn.rs_newrdn.bv_val )
865 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
866 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
867 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
869 if ( pConn != NULL ) {
873 slapiConnectionDestroy( &pConn );
878 #endif /* LDAP_SLAPI */
881 /* Function : slapi_modify_internal
883 * Description: Plugin functions call this routine to modify an entry
884 * in the backend directly
885 * Return values : LDAP_SUCCESS
889 * LDAP_UNWILLING_TO_PERFORM
892 slapi_modify_internal(
895 LDAPControl **controls,
900 Connection *pConn = NULL;
901 Operation *op = NULL;
902 Slapi_PBlock *pPB = NULL;
903 Slapi_PBlock *pSavePB = NULL;
905 struct berval dn = { 0, NULL };
912 Modifications *modlist = NULL;
913 Modifications **modtail = &modlist;
916 SlapReply rs = { REP_RESULT };
918 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
919 rs.sr_err = LDAP_PARAM_ERROR ;
923 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
924 if ( pConn == NULL ) {
925 rs.sr_err = LDAP_NO_MEMORY;
929 op = (Operation *)pConn->c_pending_ops.stqh_first;
930 pPB = (Slapi_PBlock *)op->o_pb;
931 op->o_ctrls = controls;
933 dn.bv_val = slapi_ch_strdup( ldn );
934 dn.bv_len = strlen( ldn );
935 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
936 if ( rs.sr_err != LDAP_SUCCESS ) {
940 if ( slapi_control_present( controls,
941 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
945 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
946 if ( op->o_bd == NULL ) {
947 rs.sr_err = LDAP_PARTIAL_RESULTS;
951 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
952 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
954 for ( i = 0, pMod = mods[0];
955 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
960 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
962 * attr values are in berval format
963 * convert an array of pointers to bervals
964 * to an array of bervals
966 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
967 if ( rs.sr_err != LDAP_SUCCESS )
969 tmp.sml_type.bv_val = pMod->mod_type;
970 tmp.sml_type.bv_len = strlen( pMod->mod_type );
971 tmp.sml_bvalues = bv;
972 tmp.sml_nvalues = NULL;
974 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
976 mod->sml_op = pMod->mod_op;
977 mod->sml_next = NULL;
978 mod->sml_desc = NULL;
979 mod->sml_type = tmp.sml_type;
980 mod->sml_bvalues = tmp.sml_bvalues;
981 mod->sml_nvalues = tmp.sml_nvalues;
983 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
984 if ( rs.sr_err != LDAP_SUCCESS )
986 tmp.sml_type.bv_val = pMod->mod_type;
987 tmp.sml_type.bv_len = strlen( pMod->mod_type );
988 tmp.sml_bvalues = bv;
989 tmp.sml_nvalues = NULL;
991 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
993 mod->sml_op = pMod->mod_op;
994 mod->sml_next = NULL;
995 mod->sml_desc = NULL;
996 mod->sml_type = tmp.sml_type;
997 mod->sml_bvalues = tmp.sml_bvalues;
998 mod->sml_nvalues = tmp.sml_nvalues;
1001 modtail = &mod->sml_next;
1003 switch( pMod->mod_op ) {
1005 if ( mod->sml_bvalues == NULL ) {
1006 rs.sr_err = LDAP_PROTOCOL_ERROR;
1011 case LDAP_MOD_DELETE:
1012 case LDAP_MOD_REPLACE:
1016 rs.sr_err = LDAP_PROTOCOL_ERROR;
1022 if ( op->o_req_ndn.bv_len == 0 ) {
1023 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1027 op->oq_modify.rs_modlist = modlist;
1029 if ( op->o_bd->be_modify ) {
1030 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1031 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1032 int update = op->o_bd->be_update_ndn.bv_len;
1033 const char *text = NULL;
1034 char textbuf[SLAP_TEXT_BUFLEN];
1035 size_t textlen = sizeof( textbuf );
1037 rs.sr_err = slap_mods_check( modlist, update,
1038 &text, textbuf, textlen, NULL );
1039 if ( rs.sr_err != LDAP_SUCCESS ) {
1044 rs.sr_err = slap_mods_opattrs( op, modlist,
1045 modtail, &text, textbuf,
1047 if ( rs.sr_err != LDAP_SUCCESS ) {
1051 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1056 rs.sr_err = LDAP_OTHER;
1059 rs.sr_err = LDAP_REFERRAL;
1062 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1068 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1071 slapi_ch_free( (void **)&dn.bv_val );
1073 if ( modlist != NULL )
1074 slap_mods_free( modlist );
1076 if ( pConn != NULL ) {
1080 slapiConnectionDestroy( &pConn );
1085 #endif /* LDAP_SLAPI */
1089 slapi_search_internal_bind(
1094 LDAPControl **controls,
1100 Operation *op = NULL;
1101 Slapi_PBlock *ptr = NULL;
1102 Slapi_PBlock *pSavePB = NULL;
1103 struct berval dn = { 0, NULL };
1104 Filter *filter=NULL;
1105 struct berval fstr = { 0, NULL };
1106 AttributeName *an = NULL;
1107 const char *text = NULL;
1109 int manageDsaIt = 0;
1113 SlapReply rs = { REP_RESULT };
1115 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1117 rs.sr_err = LDAP_NO_MEMORY;
1121 op = (Operation *)c->c_pending_ops.stqh_first;
1122 ptr = (Slapi_PBlock *)op->o_pb;
1123 op->o_ctrls = controls;
1125 if ( ldn != NULL ) {
1126 dn.bv_val = slapi_ch_strdup(ldn);
1127 dn.bv_len = strlen(ldn);
1130 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1131 if ( rs.sr_err != LDAP_SUCCESS ) {
1135 if ( scope != LDAP_SCOPE_BASE &&
1136 scope != LDAP_SCOPE_ONELEVEL &&
1137 scope != LDAP_SCOPE_SUBTREE ) {
1138 rs.sr_err = LDAP_PROTOCOL_ERROR;
1142 filter = slapi_str2filter(filStr);
1143 if ( filter == NULL ) {
1144 rs.sr_err = LDAP_PROTOCOL_ERROR;
1148 filter2bv( filter, &fstr );
1150 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1151 ; /* count the number of attributes */
1155 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1156 for (i = 0; attrs[i] != 0; i++) {
1157 an[i].an_desc = NULL;
1159 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1160 an[i].an_name.bv_len = strlen(attrs[i]);
1161 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1163 an[i].an_name.bv_val = NULL;
1166 memset( &rs, 0, sizeof(rs) );
1167 rs.sr_type = REP_RESULT;
1168 rs.sr_err = LDAP_SUCCESS;
1169 rs.sr_entry = NULL; /* paranoia */
1171 if ( scope == LDAP_SCOPE_BASE ) {
1174 if ( op->o_req_ndn.bv_len == 0 ) {
1175 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1178 if( rs.sr_err != LDAP_SUCCESS ) {
1179 send_ldap_result( op, &rs );
1181 } else if ( rs.sr_entry != NULL ) {
1182 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1184 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1185 rs.sr_type = REP_SEARCH;
1186 rs.sr_err = LDAP_SUCCESS;
1189 send_search_entry( op, &rs );
1192 entry_free( rs.sr_entry );
1194 rs.sr_type = REP_RESULT;
1195 rs.sr_err = LDAP_SUCCESS;
1197 send_ldap_result( op, &rs );
1203 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1204 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1205 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1207 ber_dupbv( &op->o_req_dn, &default_search_base );
1208 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1211 if ( slapi_control_present( controls,
1212 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1216 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1217 if ( op->o_bd == NULL ) {
1218 if ( manageDsaIt == 1 ) {
1219 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1221 rs.sr_err = LDAP_PARTIAL_RESULTS;
1226 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1227 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1229 op->oq_search.rs_scope = scope;
1230 op->oq_search.rs_deref = 0;
1231 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1232 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1233 op->oq_search.rs_attrsonly = attrsonly;
1234 op->oq_search.rs_attrs = an;
1235 op->oq_search.rs_filter = filter;
1236 op->oq_search.rs_filterstr = fstr;
1238 if ( op->o_bd->be_search ) {
1239 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1240 rs.sr_err = LDAP_OTHER;
1243 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1249 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1252 slapi_ch_free( (void **)&dn.bv_val );
1254 slapi_filter_free( filter, 1 );
1256 slapi_ch_free( (void **)&fstr.bv_val );
1258 slapi_ch_free( (void **)&an );
1264 slapiConnectionDestroy( &c );
1269 #endif /* LDAP_SLAPI */
1273 slapi_search_internal(
1277 LDAPControl **controls,
1282 return slapi_search_internal_bind( NULL, base, scope, filStr,
1283 controls, attrs, attrsonly );
1286 #endif /* LDAP_SLAPI */