2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2004 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(
123 slapi_int_init_connection(
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 slapi_int_connection_destroy( 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 : slapi_int_ldapmod_to_entry
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
341 slapi_int_ldapmod_to_entry(
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 = slapi_int_init_connection( 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 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
563 if ( log_change ) op->o_callback = &cb;
564 if ( (*op->o_bd->be_delete)( op, &rs ) ) {
565 rs.sr_err = LDAP_OTHER;
568 rs.sr_err = LDAP_REFERRAL;
571 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
576 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
579 slapi_ch_free( (void **)&dn.bv_val );
581 if ( pConn != NULL ) {
585 slapi_int_connection_destroy( &pConn );
590 #endif /* LDAP_SLAPI */
594 static Slapi_PBlock *
595 slapi_int_add_entry_locked(
597 LDAPControl **controls,
600 Connection *pConn = NULL;
601 Operation *op = NULL;
602 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
606 SlapReply rs = { REP_RESULT };
609 rs.sr_err = LDAP_PARAM_ERROR;
613 pConn = slapi_int_init_connection( NULL, LDAP_REQ_ADD );
614 if ( pConn == NULL ) {
615 rs.sr_err = LDAP_NO_MEMORY;
619 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
620 NULL, &isCritical ) ) {
624 op = (Operation *)pConn->c_pending_ops.stqh_first;
625 pPB = (Slapi_PBlock *)op->o_pb;
626 op->o_ctrls = controls;
628 op->o_bd = select_backend( &((*e)->e_nname), manageDsaIt, 0 );
629 if ( op->o_bd == NULL ) {
630 rs.sr_err = LDAP_PARTIAL_RESULTS;
634 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
635 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
636 op->oq_add.rs_e = *e;
638 if ( op->o_bd->be_add ) {
639 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
640 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
641 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
642 if ( log_changes ) op->o_callback = &cb;
643 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
644 be_entry_release_w( op, *e );
648 rs.sr_err = LDAP_REFERRAL;
651 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
657 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
660 if ( pConn != NULL ) {
664 slapi_int_connection_destroy( &pConn );
668 #endif /* LDAP_SLAPI */
671 slapi_add_entry_internal(
673 LDAPControl **controls,
681 * We make a copy to avoid an entry that may be freed later
682 * by the caller being placed in the cache.
684 entry = slapi_entry_dup( e );
685 pb = slapi_int_add_entry_locked( &entry, controls, log_changes );
686 if ( entry != NULL ) {
687 slapi_entry_free( entry );
699 LDAPControl **controls,
703 LDAPMod *pMod = NULL;
704 Slapi_PBlock *pb = NULL;
705 Entry *pEntry = NULL;
706 int i, rc = LDAP_SUCCESS;
708 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
709 rc = LDAP_PARAM_ERROR ;
712 if ( rc == LDAP_SUCCESS ) {
713 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
714 if ( (pMod->mod_op & LDAP_MOD_OP ) != LDAP_MOD_ADD ) {
721 if ( rc == LDAP_SUCCESS ) {
722 pEntry = slapi_int_ldapmod_to_entry( dn, mods );
723 if ( pEntry == NULL ) {
728 if ( rc != LDAP_SUCCESS ) {
729 pb = slapi_pblock_new();
730 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
732 pb = slapi_int_add_entry_locked( &pEntry, controls, log_changes );
735 if ( pEntry != NULL ) {
736 slapi_entry_free(pEntry);
742 #endif /* LDAP_SLAPI */
745 /* Function : slapi_modrdn_internal
747 * Description : Plugin functions call this routine to modify the rdn
748 * of an entry in the backend directly
749 * Return values : LDAP_SUCCESS
753 * LDAP_UNWILLING_TO_PERFORM
755 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
758 slapi_modrdn_internal(
762 LDAPControl **controls,
766 struct berval dn = { 0, NULL };
767 struct berval newrdn = { 0, NULL };
768 Connection *pConn = NULL;
769 Operation *op = NULL;
770 Slapi_PBlock *pPB = NULL;
771 Slapi_PBlock *pSavePB = NULL;
774 SlapReply rs = { REP_RESULT };
776 pConn = slapi_int_init_connection( NULL, LDAP_REQ_MODRDN);
777 if ( pConn == NULL) {
778 rs.sr_err = LDAP_NO_MEMORY;
782 op = (Operation *)pConn->c_pending_ops.stqh_first;
783 pPB = (Slapi_PBlock *)op->o_pb;
784 op->o_ctrls = controls;
786 if ( slapi_control_present( controls,
787 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
791 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
792 if ( op->o_bd == NULL ) {
793 rs.sr_err = LDAP_PARTIAL_RESULTS;
797 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
798 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
800 dn.bv_val = slapi_ch_strdup( olddn );
801 dn.bv_len = strlen( olddn );
803 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
804 if ( rs.sr_err != LDAP_SUCCESS ) {
808 if ( op->o_req_dn.bv_len == 0 ) {
809 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
813 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
814 newrdn.bv_len = strlen( lnewrdn );
816 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
817 if ( rs.sr_err != LDAP_SUCCESS ) {
821 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
825 op->oq_modrdn.rs_newSup = NULL;
826 op->oq_modrdn.rs_nnewSup = NULL;
827 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
829 if ( op->o_bd->be_modrdn ) {
830 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
831 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
832 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
833 if ( log_change ) op->o_callback = &cb;
834 if ( (*op->o_bd->be_modrdn)( op, &rs ) ) {
835 rs.sr_err = LDAP_OTHER;
838 rs.sr_err = LDAP_REFERRAL;
841 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
847 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
851 slapi_ch_free( (void **)&dn.bv_val );
854 slapi_ch_free( (void **)&newrdn.bv_val );
855 if ( op->oq_modrdn.rs_newrdn.bv_val )
856 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
857 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
858 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
860 if ( pConn != NULL ) {
864 slapi_int_connection_destroy( &pConn );
869 #endif /* LDAP_SLAPI */
872 /* Function : slapi_modify_internal
874 * Description: Plugin functions call this routine to modify an entry
875 * in the backend directly
876 * Return values : LDAP_SUCCESS
880 * LDAP_UNWILLING_TO_PERFORM
883 slapi_modify_internal(
886 LDAPControl **controls,
891 Connection *pConn = NULL;
892 Operation *op = NULL;
893 Slapi_PBlock *pPB = NULL;
894 Slapi_PBlock *pSavePB = NULL;
896 struct berval dn = { 0, NULL };
903 Modifications *modlist = NULL;
904 Modifications **modtail = &modlist;
907 SlapReply rs = { REP_RESULT };
909 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
910 rs.sr_err = LDAP_PARAM_ERROR ;
914 pConn = slapi_int_init_connection( NULL, LDAP_REQ_MODIFY );
915 if ( pConn == NULL ) {
916 rs.sr_err = LDAP_NO_MEMORY;
920 op = (Operation *)pConn->c_pending_ops.stqh_first;
921 pPB = (Slapi_PBlock *)op->o_pb;
922 op->o_ctrls = controls;
924 dn.bv_val = slapi_ch_strdup( ldn );
925 dn.bv_len = strlen( ldn );
926 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
927 if ( rs.sr_err != LDAP_SUCCESS ) {
931 if ( slapi_control_present( controls,
932 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
936 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
937 if ( op->o_bd == NULL ) {
938 rs.sr_err = LDAP_PARTIAL_RESULTS;
942 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
943 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
945 for ( i = 0, pMod = mods[0];
946 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
951 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
953 * attr values are in berval format
954 * convert an array of pointers to bervals
955 * to an array of bervals
957 rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv );
958 if ( rs.sr_err != LDAP_SUCCESS )
960 tmp.sml_type.bv_val = pMod->mod_type;
961 tmp.sml_type.bv_len = strlen( pMod->mod_type );
962 tmp.sml_bvalues = bv;
963 tmp.sml_nvalues = NULL;
965 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
967 mod->sml_op = pMod->mod_op & LDAP_MOD_OP;
968 mod->sml_next = NULL;
969 mod->sml_desc = NULL;
970 mod->sml_type = tmp.sml_type;
971 mod->sml_bvalues = tmp.sml_bvalues;
972 mod->sml_nvalues = tmp.sml_nvalues;
974 rs.sr_err = values2obj_copy( pMod->mod_values, &bv );
975 if ( rs.sr_err != LDAP_SUCCESS )
977 tmp.sml_type.bv_val = pMod->mod_type;
978 tmp.sml_type.bv_len = strlen( pMod->mod_type );
979 tmp.sml_bvalues = bv;
980 tmp.sml_nvalues = NULL;
982 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
984 mod->sml_op = pMod->mod_op & LDAP_MOD_OP;
985 mod->sml_next = NULL;
986 mod->sml_desc = NULL;
987 mod->sml_type = tmp.sml_type;
988 mod->sml_bvalues = tmp.sml_bvalues;
989 mod->sml_nvalues = tmp.sml_nvalues;
992 modtail = &mod->sml_next;
994 switch( pMod->mod_op & LDAP_MOD_OP ) {
996 if ( mod->sml_bvalues == NULL ) {
997 rs.sr_err = LDAP_PROTOCOL_ERROR;
1002 case LDAP_MOD_DELETE:
1003 case LDAP_MOD_REPLACE:
1007 rs.sr_err = LDAP_PROTOCOL_ERROR;
1013 if ( op->o_req_ndn.bv_len == 0 ) {
1014 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1018 op->oq_modify.rs_modlist = modlist;
1020 if ( op->o_bd->be_modify ) {
1021 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
1022 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
1023 int update = op->o_bd->be_update_ndn.bv_len;
1024 const char *text = NULL;
1025 char textbuf[SLAP_TEXT_BUFLEN];
1026 size_t textlen = sizeof( textbuf );
1027 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
1029 rs.sr_err = slap_mods_check( modlist, update,
1030 &text, textbuf, textlen, NULL );
1031 if ( rs.sr_err != LDAP_SUCCESS ) {
1036 rs.sr_err = slap_mods_opattrs( op, modlist,
1037 modtail, &text, textbuf,
1039 if ( rs.sr_err != LDAP_SUCCESS ) {
1043 if ( log_change ) op->o_callback = &cb;
1044 if ( (*op->o_bd->be_modify)( op, &rs ) ) {
1045 rs.sr_err = LDAP_OTHER;
1048 rs.sr_err = LDAP_REFERRAL;
1051 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1057 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1060 slapi_ch_free( (void **)&dn.bv_val );
1062 if ( modlist != NULL )
1063 slap_mods_free( modlist );
1065 if ( pConn != NULL ) {
1069 slapi_int_connection_destroy( &pConn );
1074 #endif /* LDAP_SLAPI */
1078 slapi_search_internal(
1082 LDAPControl **controls,
1088 Operation *op = NULL;
1089 Slapi_PBlock *ptr = NULL;
1090 Slapi_PBlock *pSavePB = NULL;
1091 struct berval dn = { 0, NULL };
1092 Filter *filter=NULL;
1093 struct berval fstr = { 0, NULL };
1094 AttributeName *an = NULL;
1095 const char *text = NULL;
1097 int manageDsaIt = 0;
1101 SlapReply rs = { REP_RESULT };
1103 c = slapi_int_init_connection( NULL, LDAP_REQ_SEARCH );
1105 rs.sr_err = LDAP_NO_MEMORY;
1109 op = (Operation *)c->c_pending_ops.stqh_first;
1110 ptr = (Slapi_PBlock *)op->o_pb;
1111 op->o_ctrls = controls;
1113 if ( ldn != NULL ) {
1114 dn.bv_val = slapi_ch_strdup(ldn);
1115 dn.bv_len = strlen(ldn);
1118 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1119 if ( rs.sr_err != LDAP_SUCCESS ) {
1123 if ( scope != LDAP_SCOPE_BASE &&
1124 scope != LDAP_SCOPE_ONELEVEL &&
1125 scope != LDAP_SCOPE_SUBTREE ) {
1126 rs.sr_err = LDAP_PROTOCOL_ERROR;
1130 filter = slapi_str2filter(filStr);
1131 if ( filter == NULL ) {
1132 rs.sr_err = LDAP_PROTOCOL_ERROR;
1136 filter2bv( filter, &fstr );
1138 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1139 ; /* count the number of attributes */
1143 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1144 for (i = 0; attrs[i] != 0; i++) {
1145 an[i].an_desc = NULL;
1147 an[i].an_oc_exclude = 0;
1148 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1149 an[i].an_name.bv_len = strlen(attrs[i]);
1150 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1152 an[i].an_name.bv_val = NULL;
1155 memset( &rs, 0, sizeof(rs) );
1156 rs.sr_type = REP_RESULT;
1157 rs.sr_err = LDAP_SUCCESS;
1158 rs.sr_entry = NULL; /* paranoia */
1160 if ( scope == LDAP_SCOPE_BASE ) {
1163 if ( op->o_req_ndn.bv_len == 0 ) {
1164 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1167 if( rs.sr_err != LDAP_SUCCESS ) {
1168 send_ldap_result( op, &rs );
1170 } else if ( rs.sr_entry != NULL ) {
1171 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1173 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1174 rs.sr_type = REP_SEARCH;
1175 rs.sr_err = LDAP_SUCCESS;
1178 send_search_entry( op, &rs );
1181 entry_free( rs.sr_entry );
1183 rs.sr_type = REP_RESULT;
1184 rs.sr_err = LDAP_SUCCESS;
1186 send_ldap_result( op, &rs );
1192 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1193 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1194 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1196 ber_dupbv( &op->o_req_dn, &default_search_base );
1197 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1200 if ( slapi_control_present( controls,
1201 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1205 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1206 if ( op->o_bd == NULL ) {
1207 if ( manageDsaIt == 1 ) {
1208 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1210 rs.sr_err = LDAP_PARTIAL_RESULTS;
1215 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1216 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1218 op->oq_search.rs_scope = scope;
1219 op->oq_search.rs_deref = 0;
1220 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1221 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1222 op->oq_search.rs_attrsonly = attrsonly;
1223 op->oq_search.rs_attrs = an;
1224 op->oq_search.rs_filter = filter;
1225 op->oq_search.rs_filterstr = fstr;
1227 if ( op->o_bd->be_search ) {
1228 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1229 rs.sr_err = LDAP_OTHER;
1232 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1238 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1241 slapi_ch_free( (void **)&dn.bv_val );
1243 slapi_filter_free( filter, 1 );
1245 slapi_ch_free( (void **)&fstr.bv_val );
1247 slapi_ch_free( (void **)&an );
1253 slapi_int_connection_destroy( &c );
1258 #endif /* LDAP_SLAPI */