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 ( log_change ) repstamp( op );
563 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
568 rs.sr_err = LDAP_OTHER;
571 rs.sr_err = LDAP_REFERRAL;
574 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
579 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
582 slapi_ch_free( (void **)&dn.bv_val );
584 if ( pConn != NULL ) {
588 slapiConnectionDestroy( &pConn );
593 #endif /* LDAP_SLAPI */
597 static Slapi_PBlock *
598 slapi_add_entry_internal_locked(
600 LDAPControl **controls,
603 Connection *pConn = NULL;
604 Operation *op = NULL;
605 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
609 SlapReply rs = { REP_RESULT };
612 rs.sr_err = LDAP_PARAM_ERROR;
616 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
617 if ( pConn == NULL ) {
618 rs.sr_err = LDAP_NO_MEMORY;
622 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
623 NULL, &isCritical ) ) {
627 op = (Operation *)pConn->c_pending_ops.stqh_first;
628 pPB = (Slapi_PBlock *)op->o_pb;
629 op->o_ctrls = controls;
631 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
632 if ( op->o_bd == NULL ) {
633 rs.sr_err = LDAP_PARTIAL_RESULTS;
637 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
638 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
639 op->oq_add.rs_e = *e;
641 if ( op->o_bd->be_add ) {
642 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
643 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
644 if ( log_changes ) repstamp( op );
645 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
649 be_entry_release_w( op, *e );
653 rs.sr_err = LDAP_REFERRAL;
656 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
662 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
665 if ( pConn != NULL ) {
669 slapiConnectionDestroy( &pConn );
673 #endif /* LDAP_SLAPI */
676 slapi_add_entry_internal(
678 LDAPControl **controls,
686 * We make a copy to avoid an entry that may be freed later
687 * by the caller being placed in the cache.
689 entry = slapi_entry_dup( e );
690 pb = slapi_add_entry_internal_locked( &entry, controls, log_changes );
691 if ( entry != NULL ) {
692 slapi_entry_free( entry );
704 LDAPControl **controls,
708 LDAPMod *pMod = NULL;
709 Slapi_PBlock *pb = NULL;
710 Entry *pEntry = NULL;
711 int i, rc = LDAP_SUCCESS;
713 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
714 rc = LDAP_PARAM_ERROR ;
717 if ( rc == LDAP_SUCCESS ) {
718 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
719 if ( (pMod->mod_op & LDAP_MOD_OP ) != LDAP_MOD_ADD ) {
726 if ( rc == LDAP_SUCCESS ) {
727 pEntry = LDAPModToEntry( dn, mods );
728 if ( pEntry == NULL ) {
733 if ( rc != LDAP_SUCCESS ) {
734 pb = slapi_pblock_new();
735 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
737 pb = slapi_add_entry_internal_locked( &pEntry, controls, log_changes );
740 if ( pEntry != NULL ) {
741 slapi_entry_free(pEntry);
747 #endif /* LDAP_SLAPI */
750 /* Function : slapi_modrdn_internal
752 * Description : Plugin functions call this routine to modify the rdn
753 * of an entry in the backend directly
754 * Return values : LDAP_SUCCESS
758 * LDAP_UNWILLING_TO_PERFORM
760 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
763 slapi_modrdn_internal(
767 LDAPControl **controls,
771 struct berval dn = { 0, NULL };
772 struct berval newrdn = { 0, NULL };
773 Connection *pConn = NULL;
774 Operation *op = NULL;
775 Slapi_PBlock *pPB = NULL;
776 Slapi_PBlock *pSavePB = NULL;
779 SlapReply rs = { REP_RESULT };
781 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
782 if ( pConn == NULL) {
783 rs.sr_err = LDAP_NO_MEMORY;
787 op = (Operation *)pConn->c_pending_ops.stqh_first;
788 pPB = (Slapi_PBlock *)op->o_pb;
789 op->o_ctrls = controls;
791 if ( slapi_control_present( controls,
792 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
796 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
797 if ( op->o_bd == NULL ) {
798 rs.sr_err = LDAP_PARTIAL_RESULTS;
802 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
803 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
805 dn.bv_val = slapi_ch_strdup( olddn );
806 dn.bv_len = strlen( olddn );
808 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
809 if ( rs.sr_err != LDAP_SUCCESS ) {
813 if ( op->o_req_dn.bv_len == 0 ) {
814 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
818 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
819 newrdn.bv_len = strlen( lnewrdn );
821 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
822 if ( rs.sr_err != LDAP_SUCCESS ) {
826 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
830 op->oq_modrdn.rs_newSup = NULL;
831 op->oq_modrdn.rs_nnewSup = NULL;
832 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
834 if ( op->o_bd->be_modrdn ) {
835 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
836 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
837 if ( log_change ) repstamp( op );
838 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
843 rs.sr_err = LDAP_OTHER;
846 rs.sr_err = LDAP_REFERRAL;
849 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
855 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
859 slapi_ch_free( (void **)&dn.bv_val );
862 slapi_ch_free( (void **)&newrdn.bv_val );
863 if ( op->oq_modrdn.rs_newrdn.bv_val )
864 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
865 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
866 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
868 if ( pConn != NULL ) {
872 slapiConnectionDestroy( &pConn );
877 #endif /* LDAP_SLAPI */
880 /* Function : slapi_modify_internal
882 * Description: Plugin functions call this routine to modify an entry
883 * in the backend directly
884 * Return values : LDAP_SUCCESS
888 * LDAP_UNWILLING_TO_PERFORM
891 slapi_modify_internal(
894 LDAPControl **controls,
899 Connection *pConn = NULL;
900 Operation *op = NULL;
901 Slapi_PBlock *pPB = NULL;
902 Slapi_PBlock *pSavePB = NULL;
904 struct berval dn = { 0, NULL };
911 Modifications *modlist = NULL;
912 Modifications **modtail = &modlist;
915 SlapReply rs = { REP_RESULT };
917 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
918 rs.sr_err = LDAP_PARAM_ERROR ;
922 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
923 if ( pConn == NULL ) {
924 rs.sr_err = LDAP_NO_MEMORY;
928 op = (Operation *)pConn->c_pending_ops.stqh_first;
929 pPB = (Slapi_PBlock *)op->o_pb;
930 op->o_ctrls = controls;
932 dn.bv_val = slapi_ch_strdup( ldn );
933 dn.bv_len = strlen( ldn );
934 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
935 if ( rs.sr_err != LDAP_SUCCESS ) {
939 if ( slapi_control_present( controls,
940 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
944 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
945 if ( op->o_bd == NULL ) {
946 rs.sr_err = LDAP_PARTIAL_RESULTS;
950 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
951 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
953 for ( i = 0, pMod = mods[0];
954 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
959 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
961 * attr values are in berval format
962 * convert an array of pointers to bervals
963 * to an array of bervals
965 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
966 if ( rs.sr_err != LDAP_SUCCESS )
968 tmp.sml_type.bv_val = pMod->mod_type;
969 tmp.sml_type.bv_len = strlen( pMod->mod_type );
970 tmp.sml_bvalues = bv;
971 tmp.sml_nvalues = NULL;
973 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
975 mod->sml_op = pMod->mod_op & LDAP_MOD_OP;
976 mod->sml_next = NULL;
977 mod->sml_desc = NULL;
978 mod->sml_type = tmp.sml_type;
979 mod->sml_bvalues = tmp.sml_bvalues;
980 mod->sml_nvalues = tmp.sml_nvalues;
982 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
983 if ( rs.sr_err != LDAP_SUCCESS )
985 tmp.sml_type.bv_val = pMod->mod_type;
986 tmp.sml_type.bv_len = strlen( pMod->mod_type );
987 tmp.sml_bvalues = bv;
988 tmp.sml_nvalues = NULL;
990 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
992 mod->sml_op = pMod->mod_op & LDAP_MOD_OP;
993 mod->sml_next = NULL;
994 mod->sml_desc = NULL;
995 mod->sml_type = tmp.sml_type;
996 mod->sml_bvalues = tmp.sml_bvalues;
997 mod->sml_nvalues = tmp.sml_nvalues;
1000 modtail = &mod->sml_next;
1002 switch( pMod->mod_op & LDAP_MOD_OP ) {
1004 if ( mod->sml_bvalues == NULL ) {
1005 rs.sr_err = LDAP_PROTOCOL_ERROR;
1010 case LDAP_MOD_DELETE:
1011 case LDAP_MOD_REPLACE:
1015 rs.sr_err = LDAP_PROTOCOL_ERROR;
1021 if ( op->o_req_ndn.bv_len == 0 ) {
1022 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1026 op->oq_modify.rs_modlist = modlist;
1028 if ( op->o_bd->be_modify ) {
1029 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1030 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1031 int update = op->o_bd->be_update_ndn.bv_len;
1032 const char *text = NULL;
1033 char textbuf[SLAP_TEXT_BUFLEN];
1034 size_t textlen = sizeof( textbuf );
1036 rs.sr_err = slap_mods_check( modlist, update,
1037 &text, textbuf, textlen, NULL );
1038 if ( rs.sr_err != LDAP_SUCCESS ) {
1043 rs.sr_err = slap_mods_opattrs( op, modlist,
1044 modtail, &text, textbuf,
1046 if ( rs.sr_err != LDAP_SUCCESS ) {
1050 if ( log_change ) repstamp( op );
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_oc_exclude = 0;
1160 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1161 an[i].an_name.bv_len = strlen(attrs[i]);
1162 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1164 an[i].an_name.bv_val = NULL;
1167 memset( &rs, 0, sizeof(rs) );
1168 rs.sr_type = REP_RESULT;
1169 rs.sr_err = LDAP_SUCCESS;
1170 rs.sr_entry = NULL; /* paranoia */
1172 if ( scope == LDAP_SCOPE_BASE ) {
1175 if ( op->o_req_ndn.bv_len == 0 ) {
1176 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1179 if( rs.sr_err != LDAP_SUCCESS ) {
1180 send_ldap_result( op, &rs );
1182 } else if ( rs.sr_entry != NULL ) {
1183 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1185 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1186 rs.sr_type = REP_SEARCH;
1187 rs.sr_err = LDAP_SUCCESS;
1190 send_search_entry( op, &rs );
1193 entry_free( rs.sr_entry );
1195 rs.sr_type = REP_RESULT;
1196 rs.sr_err = LDAP_SUCCESS;
1198 send_ldap_result( op, &rs );
1204 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1205 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1206 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1208 ber_dupbv( &op->o_req_dn, &default_search_base );
1209 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1212 if ( slapi_control_present( controls,
1213 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1217 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1218 if ( op->o_bd == NULL ) {
1219 if ( manageDsaIt == 1 ) {
1220 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1222 rs.sr_err = LDAP_PARTIAL_RESULTS;
1227 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1228 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1230 op->oq_search.rs_scope = scope;
1231 op->oq_search.rs_deref = 0;
1232 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1233 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1234 op->oq_search.rs_attrsonly = attrsonly;
1235 op->oq_search.rs_attrs = an;
1236 op->oq_search.rs_filter = filter;
1237 op->oq_search.rs_filterstr = fstr;
1239 if ( op->o_bd->be_search ) {
1240 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1241 rs.sr_err = LDAP_OTHER;
1244 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1250 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1253 slapi_ch_free( (void **)&dn.bv_val );
1255 slapi_filter_free( filter, 1 );
1257 slapi_ch_free( (void **)&fstr.bv_val );
1259 slapi_ch_free( (void **)&an );
1265 slapiConnectionDestroy( &c );
1270 #endif /* LDAP_SLAPI */
1274 slapi_search_internal(
1278 LDAPControl **controls,
1283 return slapi_search_internal_bind( NULL, base, scope, filStr,
1284 controls, attrs, attrsonly );
1287 #endif /* LDAP_SLAPI */