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;
173 c->c_listener = &slap_unknown_listener;
174 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
175 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
177 LDAP_STAILQ_INIT( &c->c_ops );
179 c->c_sasl_bind_mech.bv_val = NULL;
180 c->c_sasl_bind_mech.bv_len = 0;
181 c->c_sasl_authctx = NULL;
182 c->c_sasl_sockctx = NULL;
183 c->c_sasl_extra = NULL;
185 c->c_sb = ber_sockbuf_alloc( );
187 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
189 c->c_currentber = NULL;
191 /* should check status of thread calls */
192 ldap_pvt_thread_mutex_init( &c->c_mutex );
193 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
194 ldap_pvt_thread_cond_init( &c->c_write_cv );
196 c->c_n_ops_received = 0;
197 c->c_n_ops_executing = 0;
198 c->c_n_ops_pending = 0;
199 c->c_n_ops_completed = 0;
205 c->c_protocol = LDAP_VERSION3;
207 c->c_activitytime = c->c_starttime = slap_get_time();
211 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
212 c->c_struct_state = 0x02; /* SLAP_C_USED */
214 c->c_ssf = c->c_transport_ssf = 0;
217 backend_connection_init( c );
219 pConn->c_send_ldap_result = internal_result_v3;
220 pConn->c_send_search_entry = internal_search_entry;
221 pConn->c_send_ldap_extended = internal_result_ext;
222 pConn->c_send_search_reference = internal_search_reference;
227 static void slapiConnectionDestroy( Connection **pConn )
229 Connection *conn = *pConn;
232 if ( pConn == NULL ) {
236 op = (Operation *)conn->c_pending_ops.stqh_first;
238 if ( op->o_req_dn.bv_val != NULL ) {
239 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
241 if ( op->o_req_ndn.bv_val != NULL ) {
242 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
245 if ( conn->c_sb != NULL ) {
246 ber_sockbuf_free( conn->c_sb );
249 slapi_ch_free( (void **)&op );
251 slapi_ch_free( (void **)pConn );
255 * Function : values2obj
256 * Convert an array of strings into a BerVarray.
267 if ( ppValue == NULL ) {
272 for ( i = 0; ppValue[i] != NULL; i++ )
275 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
276 if ( tmpberval == NULL ) {
277 return LDAP_NO_MEMORY;
279 for ( i = 0; ppValue[i] != NULL; i++ ) {
280 size_t len = strlen( ppValue[i] );
282 tmpberval[i].bv_val = slapi_ch_malloc( len + 1 );
283 AC_MEMCPY( tmpberval[i].bv_val, ppValue[i], len + 1 );
284 tmpberval[i].bv_len = len;
286 tmpberval[i].bv_val = NULL;
287 tmpberval[i].bv_len = 0;
296 struct berval **bvptr,
299 int rc = LDAP_SUCCESS;
303 if ( bvptr == NULL || *bvptr == NULL ) {
307 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
311 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
312 if ( tmpberval == NULL ) {
313 return LDAP_NO_MEMORY;
316 for ( i = 0; bvptr[i] != NULL; i++ ) {
317 tmpberval[i].bv_val = slapi_ch_malloc( bvptr[i]->bv_len );
318 tmpberval[i].bv_len = bvptr[i]->bv_len;
319 AC_MEMCPY( tmpberval[i].bv_val, bvptr[i]->bv_val, bvptr[i]->bv_len );
321 tmpberval[i].bv_val = NULL;
322 tmpberval[i].bv_len = 0;
324 if ( rc == LDAP_SUCCESS ) {
332 * Function : LDAPModToEntry
333 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
334 * with a link list of the correspondent attributes.
335 * Return value : LDAP_SUCCESS
344 struct berval dn = { 0, NULL };
350 Modifications *modlist = NULL;
351 Modifications **modtail = &modlist;
354 int rc = LDAP_SUCCESS;
357 const char *text = NULL;
360 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
365 op->o_tag = LDAP_REQ_ADD;
367 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
368 if ( pEntry == NULL) {
373 dn.bv_val = slapi_ch_strdup(ldn);
374 dn.bv_len = strlen(ldn);
376 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
377 if ( rc != LDAP_SUCCESS ) {
381 if ( rc == LDAP_SUCCESS ) {
382 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
385 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
387 * Convert an array of pointers to bervals to
388 * an array of bervals. Note that we need to copy the
389 * values too, as the slap_mods_check() will free the
390 * original values after prettying; the modifications
391 * being passed in may not have been allocated on the
394 rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
395 if ( rc != LDAP_SUCCESS ) goto cleanup;
396 tmp.sml_type.bv_val = pMod->mod_type;
397 tmp.sml_type.bv_len = strlen( pMod->mod_type );
398 tmp.sml_bvalues = bv;
399 tmp.sml_nvalues = NULL;
401 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
403 mod->sml_op = LDAP_MOD_ADD;
404 mod->sml_next = NULL;
405 mod->sml_desc = NULL;
406 mod->sml_type = tmp.sml_type;
407 mod->sml_bvalues = tmp.sml_bvalues;
408 mod->sml_nvalues = tmp.sml_nvalues;
411 modtail = &mod->sml_next;
414 /* attr values are in string format, need to be converted */
415 /* to an array of bervals */
416 if ( pMod->mod_values == NULL ) {
419 rc = values2obj_copy( pMod->mod_values, &bv );
420 if ( rc != LDAP_SUCCESS ) goto cleanup;
421 tmp.sml_type.bv_val = pMod->mod_type;
422 tmp.sml_type.bv_len = strlen( pMod->mod_type );
423 tmp.sml_bvalues = bv;
424 tmp.sml_nvalues = NULL;
426 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
428 mod->sml_op = LDAP_MOD_ADD;
429 mod->sml_next = NULL;
430 mod->sml_desc = NULL;
431 mod->sml_type = tmp.sml_type;
432 mod->sml_bvalues = tmp.sml_bvalues;
433 mod->sml_nvalues = tmp.sml_nvalues;
436 modtail = &mod->sml_next;
439 } /* for each LDAPMod */
442 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
443 if ( op->o_bd == NULL ) {
444 rc = LDAP_PARTIAL_RESULTS;
446 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
447 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
448 int update = op->o_bd->be_update_ndn.bv_len;
449 char textbuf[SLAP_TEXT_BUFLEN];
450 size_t textlen = sizeof textbuf;
452 rc = slap_mods_check( modlist, update, &text,
453 textbuf, textlen, NULL );
454 if ( rc != LDAP_SUCCESS) {
459 rc = slap_mods_opattrs( op,
460 modlist, modtail, &text,
462 if ( rc != LDAP_SUCCESS) {
467 rc = slap_mods2entry( modlist, &pEntry, repl_user,
468 0, &text, textbuf, textlen );
469 if (rc != LDAP_SUCCESS) {
481 slapi_ch_free( (void **)&dn.bv_val );
483 slapi_ch_free( (void **)&op );
484 if ( modlist != NULL )
485 slap_mods_free( modlist );
486 if ( rc != LDAP_SUCCESS ) {
487 if ( pEntry != NULL ) {
488 slapi_entry_free( pEntry );
496 /* Function : slapi_delete_internal
498 * Description : Plugin functions call this routine to delete an entry
499 * in the backend directly
500 * Return values : LDAP_SUCCESS
504 * LDAP_UNWILLING_TO_PERFORM
507 slapi_delete_internal(
509 LDAPControl **controls,
513 Connection *pConn = NULL;
514 Operation *op = NULL;
515 Slapi_PBlock *pPB = NULL;
516 Slapi_PBlock *pSavePB = NULL;
517 SlapReply rs = { REP_RESULT };
518 struct berval dn = { 0, NULL };
524 rs.sr_err = LDAP_PARAM_ERROR;
528 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
530 rs.sr_err = LDAP_NO_MEMORY;
534 op = (Operation *)pConn->c_pending_ops.stqh_first;
535 pPB = (Slapi_PBlock *)op->o_pb;
536 op->o_ctrls = controls;
538 dn.bv_val = slapi_ch_strdup(ldn);
539 dn.bv_len = strlen(ldn);
540 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
541 if ( rs.sr_err != LDAP_SUCCESS )
544 if ( slapi_control_present( controls,
545 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
549 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
550 if ( op->o_bd == NULL ) {
551 rs.sr_err = LDAP_PARTIAL_RESULTS;
555 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
556 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
558 if ( op->o_bd->be_delete ) {
559 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
560 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
561 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
566 rs.sr_err = LDAP_OTHER;
569 rs.sr_err = LDAP_REFERRAL;
572 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
577 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
580 slapi_ch_free( (void **)&dn.bv_val );
582 if ( pConn != NULL ) {
586 slapiConnectionDestroy( &pConn );
591 #endif /* LDAP_SLAPI */
595 static Slapi_PBlock *
596 slapi_add_entry_internal_locked(
598 LDAPControl **controls,
601 Connection *pConn = NULL;
602 Operation *op = NULL;
603 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
607 SlapReply rs = { REP_RESULT };
610 rs.sr_err = LDAP_PARAM_ERROR;
614 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
615 if ( pConn == NULL ) {
616 rs.sr_err = LDAP_NO_MEMORY;
620 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
621 NULL, &isCritical ) ) {
625 op = (Operation *)pConn->c_pending_ops.stqh_first;
626 pPB = (Slapi_PBlock *)op->o_pb;
627 op->o_ctrls = controls;
629 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
630 if ( op->o_bd == NULL ) {
631 rs.sr_err = LDAP_PARTIAL_RESULTS;
635 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
636 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
637 op->oq_add.rs_e = *e;
639 if ( op->o_bd->be_add ) {
640 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
641 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
642 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
646 be_entry_release_w( op, *e );
650 rs.sr_err = LDAP_REFERRAL;
653 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
659 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
662 if ( pConn != NULL ) {
666 slapiConnectionDestroy( &pConn );
670 #endif /* LDAP_SLAPI */
673 slapi_add_entry_internal(
675 LDAPControl **controls,
683 * We make a copy to avoid an entry that may be freed later
684 * by the caller being placed in the cache.
686 entry = slapi_entry_dup( e );
687 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
688 if ( entry != NULL ) {
689 slapi_entry_free( entry );
701 LDAPControl **controls,
705 LDAPMod *pMod = NULL;
706 Slapi_PBlock *pb = NULL;
707 Entry *pEntry = NULL;
708 int i, rc = LDAP_SUCCESS;
710 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
711 rc = LDAP_PARAM_ERROR ;
714 if ( rc == LDAP_SUCCESS ) {
715 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
716 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
723 if ( rc == LDAP_SUCCESS ) {
724 pEntry = LDAPModToEntry( dn, mods );
725 if ( pEntry == NULL ) {
730 if ( rc != LDAP_SUCCESS ) {
731 pb = slapi_pblock_new();
732 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
734 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
737 if ( pEntry != NULL ) {
738 slapi_entry_free(pEntry);
744 #endif /* LDAP_SLAPI */
747 /* Function : slapi_modrdn_internal
749 * Description : Plugin functions call this routine to modify the rdn
750 * of an entry in the backend directly
751 * Return values : LDAP_SUCCESS
755 * LDAP_UNWILLING_TO_PERFORM
757 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
760 slapi_modrdn_internal(
764 LDAPControl **controls,
768 struct berval dn = { 0, NULL };
769 struct berval newrdn = { 0, NULL };
770 Connection *pConn = NULL;
771 Operation *op = NULL;
772 Slapi_PBlock *pPB = NULL;
773 Slapi_PBlock *pSavePB = NULL;
776 SlapReply rs = { REP_RESULT };
778 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
779 if ( pConn == NULL) {
780 rs.sr_err = LDAP_NO_MEMORY;
784 op = (Operation *)pConn->c_pending_ops.stqh_first;
785 pPB = (Slapi_PBlock *)op->o_pb;
786 op->o_ctrls = controls;
788 if ( slapi_control_present( controls,
789 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
793 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
794 if ( op->o_bd == NULL ) {
795 rs.sr_err = LDAP_PARTIAL_RESULTS;
799 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
800 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
802 dn.bv_val = slapi_ch_strdup( olddn );
803 dn.bv_len = strlen( olddn );
805 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
806 if ( rs.sr_err != LDAP_SUCCESS ) {
810 if ( op->o_req_dn.bv_len == 0 ) {
811 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
815 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
816 newrdn.bv_len = strlen( lnewrdn );
818 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
819 if ( rs.sr_err != LDAP_SUCCESS ) {
823 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
827 op->oq_modrdn.rs_newSup = NULL;
828 op->oq_modrdn.rs_nnewSup = NULL;
829 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
831 if ( op->o_bd->be_modrdn ) {
832 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
833 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
834 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
839 rs.sr_err = LDAP_OTHER;
842 rs.sr_err = LDAP_REFERRAL;
845 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
851 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
855 slapi_ch_free( (void **)&dn.bv_val );
858 slapi_ch_free( (void **)&newrdn.bv_val );
859 if ( op->oq_modrdn.rs_newrdn.bv_val )
860 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
861 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
862 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
864 if ( pConn != NULL ) {
868 slapiConnectionDestroy( &pConn );
873 #endif /* LDAP_SLAPI */
876 /* Function : slapi_modify_internal
878 * Description: Plugin functions call this routine to modify an entry
879 * in the backend directly
880 * Return values : LDAP_SUCCESS
884 * LDAP_UNWILLING_TO_PERFORM
887 slapi_modify_internal(
890 LDAPControl **controls,
895 Connection *pConn = NULL;
896 Operation *op = NULL;
897 Slapi_PBlock *pPB = NULL;
898 Slapi_PBlock *pSavePB = NULL;
900 struct berval dn = { 0, NULL };
907 Modifications *modlist = NULL;
908 Modifications **modtail = &modlist;
911 SlapReply rs = { REP_RESULT };
913 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
914 rs.sr_err = LDAP_PARAM_ERROR ;
918 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
919 if ( pConn == NULL ) {
920 rs.sr_err = LDAP_NO_MEMORY;
924 op = (Operation *)pConn->c_pending_ops.stqh_first;
925 pPB = (Slapi_PBlock *)op->o_pb;
926 op->o_ctrls = controls;
928 dn.bv_val = slapi_ch_strdup( ldn );
929 dn.bv_len = strlen( ldn );
930 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
931 if ( rs.sr_err != LDAP_SUCCESS ) {
935 if ( slapi_control_present( controls,
936 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
940 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
941 if ( op->o_bd == NULL ) {
942 rs.sr_err = LDAP_PARTIAL_RESULTS;
946 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
947 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
949 for ( i = 0, pMod = mods[0];
950 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
955 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
957 * attr values are in berval format
958 * convert an array of pointers to bervals
959 * to an array of bervals
961 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
962 if ( rs.sr_err != LDAP_SUCCESS )
964 tmp.sml_type.bv_val = pMod->mod_type;
965 tmp.sml_type.bv_len = strlen( pMod->mod_type );
966 tmp.sml_bvalues = bv;
967 tmp.sml_nvalues = NULL;
969 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
971 mod->sml_op = pMod->mod_op;
972 mod->sml_next = NULL;
973 mod->sml_desc = NULL;
974 mod->sml_type = tmp.sml_type;
975 mod->sml_bvalues = tmp.sml_bvalues;
976 mod->sml_nvalues = tmp.sml_nvalues;
978 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
979 if ( rs.sr_err != LDAP_SUCCESS )
981 tmp.sml_type.bv_val = pMod->mod_type;
982 tmp.sml_type.bv_len = strlen( pMod->mod_type );
983 tmp.sml_bvalues = bv;
984 tmp.sml_nvalues = NULL;
986 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
988 mod->sml_op = pMod->mod_op;
989 mod->sml_next = NULL;
990 mod->sml_desc = NULL;
991 mod->sml_type = tmp.sml_type;
992 mod->sml_bvalues = tmp.sml_bvalues;
993 mod->sml_nvalues = tmp.sml_nvalues;
996 modtail = &mod->sml_next;
998 switch( pMod->mod_op ) {
1000 if ( mod->sml_bvalues == NULL ) {
1001 rs.sr_err = LDAP_PROTOCOL_ERROR;
1006 case LDAP_MOD_DELETE:
1007 case LDAP_MOD_REPLACE:
1011 rs.sr_err = LDAP_PROTOCOL_ERROR;
1017 if ( op->o_req_ndn.bv_len == 0 ) {
1018 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1022 op->oq_modify.rs_modlist = modlist;
1024 if ( op->o_bd->be_modify ) {
1025 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1026 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1027 int update = op->o_bd->be_update_ndn.bv_len;
1028 const char *text = NULL;
1029 char textbuf[SLAP_TEXT_BUFLEN];
1030 size_t textlen = sizeof( textbuf );
1032 rs.sr_err = slap_mods_check( modlist, update,
1033 &text, textbuf, textlen, NULL );
1034 if ( rs.sr_err != LDAP_SUCCESS ) {
1039 rs.sr_err = slap_mods_opattrs( op, modlist,
1040 modtail, &text, textbuf,
1042 if ( rs.sr_err != LDAP_SUCCESS ) {
1046 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1051 rs.sr_err = LDAP_OTHER;
1054 rs.sr_err = LDAP_REFERRAL;
1057 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1063 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1066 slapi_ch_free( (void **)&dn.bv_val );
1068 if ( modlist != NULL )
1069 slap_mods_free( modlist );
1071 if ( pConn != NULL ) {
1075 slapiConnectionDestroy( &pConn );
1080 #endif /* LDAP_SLAPI */
1084 slapi_search_internal_bind(
1089 LDAPControl **controls,
1095 Operation *op = NULL;
1096 Slapi_PBlock *ptr = NULL;
1097 Slapi_PBlock *pSavePB = NULL;
1098 struct berval dn = { 0, NULL };
1099 Filter *filter=NULL;
1100 struct berval fstr = { 0, NULL };
1101 AttributeName *an = NULL;
1102 const char *text = NULL;
1104 int manageDsaIt = 0;
1108 SlapReply rs = { REP_RESULT };
1110 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1112 rs.sr_err = LDAP_NO_MEMORY;
1116 op = (Operation *)c->c_pending_ops.stqh_first;
1117 ptr = (Slapi_PBlock *)op->o_pb;
1118 op->o_ctrls = controls;
1120 if ( ldn != NULL ) {
1121 dn.bv_val = slapi_ch_strdup(ldn);
1122 dn.bv_len = strlen(ldn);
1125 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1126 if ( rs.sr_err != LDAP_SUCCESS ) {
1130 if ( scope != LDAP_SCOPE_BASE &&
1131 scope != LDAP_SCOPE_ONELEVEL &&
1132 scope != LDAP_SCOPE_SUBTREE ) {
1133 rs.sr_err = LDAP_PROTOCOL_ERROR;
1137 filter = slapi_str2filter(filStr);
1138 if ( filter == NULL ) {
1139 rs.sr_err = LDAP_PROTOCOL_ERROR;
1143 filter2bv( filter, &fstr );
1145 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1146 ; /* count the number of attributes */
1150 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1151 for (i = 0; attrs[i] != 0; i++) {
1152 an[i].an_desc = NULL;
1154 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1155 an[i].an_name.bv_len = strlen(attrs[i]);
1156 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1158 an[i].an_name.bv_val = NULL;
1161 memset( &rs, 0, sizeof(rs) );
1162 rs.sr_type = REP_RESULT;
1163 rs.sr_err = LDAP_SUCCESS;
1164 rs.sr_entry = NULL; /* paranoia */
1166 if ( scope == LDAP_SCOPE_BASE ) {
1169 if ( op->o_req_ndn.bv_len == 0 ) {
1170 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1173 if( rs.sr_err != LDAP_SUCCESS ) {
1174 send_ldap_result( op, &rs );
1176 } else if ( rs.sr_entry != NULL ) {
1177 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1179 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1180 rs.sr_type = REP_SEARCH;
1181 rs.sr_err = LDAP_SUCCESS;
1184 send_search_entry( op, &rs );
1187 entry_free( rs.sr_entry );
1189 rs.sr_type = REP_RESULT;
1190 rs.sr_err = LDAP_SUCCESS;
1192 send_ldap_result( op, &rs );
1198 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1199 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1200 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1202 ber_dupbv( &op->o_req_dn, &default_search_base );
1203 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1206 if ( slapi_control_present( controls,
1207 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1211 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1212 if ( op->o_bd == NULL ) {
1213 if ( manageDsaIt == 1 ) {
1214 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1216 rs.sr_err = LDAP_PARTIAL_RESULTS;
1221 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1222 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1224 op->oq_search.rs_scope = scope;
1225 op->oq_search.rs_deref = 0;
1226 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1227 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1228 op->oq_search.rs_attrsonly = attrsonly;
1229 op->oq_search.rs_attrs = an;
1230 op->oq_search.rs_filter = filter;
1231 op->oq_search.rs_filterstr = fstr;
1233 if ( op->o_bd->be_search ) {
1234 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1235 rs.sr_err = LDAP_OTHER;
1238 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1244 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1247 slapi_ch_free( (void **)&dn.bv_val );
1249 slapi_filter_free( filter, 1 );
1251 slapi_ch_free( (void **)&fstr.bv_val );
1253 slapi_ch_free( (void **)&an );
1259 slapiConnectionDestroy( &c );
1264 #endif /* LDAP_SLAPI */
1268 slapi_search_internal(
1272 LDAPControl **controls,
1277 return slapi_search_internal_bind( NULL, base, scope, filStr,
1278 controls, attrs, attrsonly );
1281 #endif /* LDAP_SLAPI */