2 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * (C) Copyright IBM Corp. 1997,2002
7 * Redistribution and use in source and binary forms are permitted
8 * provided that this notice is preserved and that due credit is
9 * given to IBM Corporation. This software is provided ``as is''
10 * without express or implied warranty.
14 //#include "../../../libraries/liblber/lber-int.h"
20 * use a fake listener when faking a connection,
21 * so it can be used in ACLs
23 static struct slap_listener slap_unknown_listener = {
24 BER_BVC("unknown"), /* FIXME: use a URI form? */
28 int bvptr2obj( struct berval **bvptr, struct berval **bvobj );
39 internal_search_entry(
44 int nentries = 0, len = 0, i = 0;
45 Slapi_Entry **head = NULL, **tp;
47 ent2str = slapi_entry2str( rs->sr_entry, &len );
48 if ( ent2str == NULL ) {
52 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
53 SLAPI_NENTRIES, &nentries );
54 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
55 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
58 if ( nentries == 0 ) {
59 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
64 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
65 if ( tp[ 0 ] == NULL ) {
70 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
71 sizeof(Slapi_Entry *) * ( i + 1 ) );
75 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
76 if ( tp[ i - 1 ] == NULL ) {
82 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
83 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
84 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
85 SLAPI_NENTRIES, (void *)i );
91 internal_search_result(
95 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
96 SLAPI_NENTRIES, (void *)sr->sr_nentries );
110 internal_search_reference(
122 Connection *pConn, *c;
123 ber_len_t max = sockbuf_max_incoming;
125 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
127 return (Connection *)NULL;
130 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
132 pConn->c_pending_ops.stqh_first =
133 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
134 if ( pConn->c_pending_ops.stqh_first == NULL ) {
135 slapi_ch_free( (void **)&pConn );
136 return (Connection *)NULL;
139 pConn->c_pending_ops.stqh_first->o_pb =
140 (Slapi_PBlock *) slapi_pblock_new();
141 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
142 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
143 slapi_ch_free( (void **)&pConn );
144 return (Connection *)NULL;
149 /* operation object */
150 c->c_pending_ops.stqh_first->o_tag = OpType;
151 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
152 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
153 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
154 c->c_pending_ops.stqh_first->o_time = slap_get_time();
155 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
156 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );
158 /* connection object */
159 c->c_authmech.bv_val = NULL;
160 c->c_authmech.bv_len = 0;
161 c->c_dn.bv_val = NULL;
163 c->c_ndn.bv_val = NULL;
167 c->c_listener = &slap_unknown_listener;
168 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
169 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
171 LDAP_STAILQ_INIT( &c->c_ops );
173 c->c_sasl_bind_mech.bv_val = NULL;
174 c->c_sasl_bind_mech.bv_len = 0;
175 c->c_sasl_context = NULL;
176 c->c_sasl_extra = NULL;
178 c->c_sb = ber_sockbuf_alloc( );
180 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
182 c->c_currentber = NULL;
184 /* should check status of thread calls */
185 ldap_pvt_thread_mutex_init( &c->c_mutex );
186 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
187 ldap_pvt_thread_cond_init( &c->c_write_cv );
189 c->c_n_ops_received = 0;
190 c->c_n_ops_executing = 0;
191 c->c_n_ops_pending = 0;
192 c->c_n_ops_completed = 0;
198 c->c_protocol = LDAP_VERSION3;
200 c->c_activitytime = c->c_starttime = slap_get_time();
204 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
205 c->c_struct_state = 0x02; /* SLAP_C_USED */
207 c->c_ssf = c->c_transport_ssf = 0;
210 backend_connection_init( c );
212 pConn->c_send_ldap_result = internal_result_v3;
213 pConn->c_send_search_entry = internal_search_entry;
214 pConn->c_send_search_result = internal_search_result;
215 pConn->c_send_ldap_extended = internal_result_ext;
216 pConn->c_send_search_reference = internal_search_reference;
222 * Function : values2obj
223 * Convert an array of strings into a BerVarray.
234 if ( ppValue == NULL ) {
239 for ( i = 0; ppValue[i] != NULL; i++ )
242 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
243 if ( tmpberval == NULL ) {
244 return LDAP_NO_MEMORY;
246 for ( i = 0; ppValue[i] != NULL; i++ ) {
247 tmpberval[i].bv_val = ppValue[i];
248 tmpberval[i].bv_len = strlen( ppValue[i] );
250 tmpberval[i].bv_val = NULL;
251 tmpberval[i].bv_len = 0;
259 freeMods( Modifications *ml )
262 * Free a modification list whose values have been
263 * set with bvptr2obj() or values2obj() (ie. they
264 * do not own the pointer to the underlying values)
268 for ( ; ml != NULL; ml = next ) {
271 slapi_ch_free( (void **)&ml->sml_bvalues );
273 slapi_ch_free( (void **)&ml->sml_nvalues );
275 slapi_ch_free( (void **)&ml );
280 * Function : LDAPModToEntry
281 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
282 * with a link list of the correspondent attributes.
283 * Return value : LDAP_SUCCESS
292 struct berval dn = { 0, NULL };
299 Modifications *modlist = NULL;
300 Modifications **modtail = &modlist;
303 int rc = LDAP_SUCCESS;
306 const char *text = NULL;
309 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
310 if ( pEntry == NULL) {
314 op->o_tag = LDAP_REQ_ADD;
316 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
317 if ( pEntry == NULL) {
322 dn.bv_val = slapi_ch_strdup(ldn);
323 dn.bv_len = strlen(ldn);
325 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
326 if (rc != LDAP_SUCCESS) goto cleanup;
328 if ( rc == LDAP_SUCCESS ) {
329 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
331 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
332 /* attr values are in berval format */
333 /* convert an array of pointers to bervals to an array of bervals */
334 rc = bvptr2obj(pMod->mod_bvalues, &bv);
335 if (rc != LDAP_SUCCESS) goto cleanup;
336 tmp.sml_type.bv_val = pMod->mod_type;
337 tmp.sml_type.bv_len = strlen( pMod->mod_type );
338 tmp.sml_bvalues = bv;
340 tmp.sml_nvalues = NULL;
343 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
345 mod->sml_op = LDAP_MOD_ADD;
346 mod->sml_next = NULL;
347 mod->sml_desc = NULL;
348 mod->sml_type = tmp.sml_type;
349 mod->sml_bvalues = tmp.sml_bvalues;
351 mod->sml_nvalues = tmp.sml_nvalues;
355 modtail = &mod->sml_next;
358 /* attr values are in string format, need to be converted */
359 /* to an array of bervals */
360 if ( pMod->mod_values == NULL ) {
363 rc = values2obj( pMod->mod_values, &bv );
364 if (rc != LDAP_SUCCESS) goto cleanup;
365 tmp.sml_type.bv_val = pMod->mod_type;
366 tmp.sml_type.bv_len = strlen( pMod->mod_type );
367 tmp.sml_bvalues = bv;
369 tmp.sml_nvalues = NULL;
372 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
374 mod->sml_op = LDAP_MOD_ADD;
375 mod->sml_next = NULL;
376 mod->sml_desc = NULL;
377 mod->sml_type = tmp.sml_type;
378 mod->sml_bvalues = tmp.sml_bvalues;
380 mod->sml_nvalues = tmp.sml_nvalues;
384 modtail = &mod->sml_next;
387 } /* for each LDAPMod */
390 be = select_backend(&pEntry->e_nname, 0, 0);
392 rc = LDAP_PARTIAL_RESULTS;
397 int repl_user = be_isupdate(be, &be->be_rootdn );
398 if ( !be->be_update_ndn.bv_len || repl_user ) {
399 int update = be->be_update_ndn.bv_len;
400 char textbuf[SLAP_TEXT_BUFLEN];
401 size_t textlen = sizeof textbuf;
403 rc = slap_mods_check( modlist, update, &text,
405 if ( rc != LDAP_SUCCESS) {
410 rc = slap_mods_opattrs( op,
411 modlist, modtail, &text,
413 if ( rc != LDAP_SUCCESS) {
419 * FIXME: slap_mods2entry is declared static
420 * in servers/slapd/add.c
422 rc = slap_mods2entry( modlist, &pEntry, repl_user,
423 &text, textbuf, textlen );
424 if (rc != LDAP_SUCCESS) {
432 rc = LDAP_UNWILLING_TO_PERFORM;
437 if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );
438 if ( op ) slapi_ch_free( (void **)&op );
439 if ( modlist != NULL ) freeMods( modlist );
440 if ( rc != LDAP_SUCCESS ) {
441 if ( pEntry != NULL ) {
442 slapi_entry_free( pEntry );
450 /* Function : slapi_delete_internal
452 * Description : Plugin functions call this routine to delete an entry
453 * in the backend directly
454 * Return values : LDAP_SUCCESS
458 * LDAP_UNWILLING_TO_PERFORM
461 slapi_delete_internal(
463 LDAPControl **controls,
466 #if defined(LDAP_SLAPI)
468 Connection *pConn = NULL;
469 Operation *op = NULL;
470 Slapi_PBlock *pPB = NULL;
471 Slapi_PBlock *pSavePB = NULL;
472 SlapReply rs = { REP_RESULT };
474 struct berval dn = { 0, NULL };
481 rc = LDAP_PARAM_ERROR;
485 pConn = fakeConnection( NULL, LDAP_REQ_DELETE );
491 op = (Operation *)pConn->c_pending_ops.stqh_first;
492 pPB = (Slapi_PBlock *)op->o_pb;
493 op->o_ctrls = controls;
495 dn.bv_val = slapi_ch_strdup(ldn);
496 dn.bv_len = strlen(ldn);
497 rc = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
498 if ( rc != LDAP_SUCCESS ) goto cleanup;
500 if ( slapi_control_present( controls,
501 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
505 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
507 rc = LDAP_PARTIAL_RESULTS;
511 op->o_dn = pConn->c_dn = be->be_rootdn;
512 op->o_ndn = pConn->c_ndn = be->be_rootndn;
514 if ( be->be_delete ) {
515 int repl_user = be_isupdate( be, &op->o_ndn );
516 if ( !be->be_update_ndn.bv_len || repl_user ) {
517 rc = (*be->be_delete)( op, &rs );
530 rc = LDAP_UNWILLING_TO_PERFORM;
535 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
538 slapi_ch_free( (void **)&dn.bv_val );
539 if ( op->o_req_dn.bv_val )
540 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
541 if ( op->o_req_ndn.bv_val )
542 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
544 if ( pConn != NULL ) {
545 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
546 if ( op ) slapi_ch_free( (void **)&op );
552 #endif /* LDAP_SLAPI */
557 slapi_add_entry_internal(
559 LDAPControl **controls,
562 #if defined(LDAP_SLAPI)
563 Connection *pConn = NULL;
564 Operation *op = NULL;
565 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
570 int rc = LDAP_SUCCESS;
571 SlapReply rs = { REP_RESULT };
574 rc = LDAP_PARAM_ERROR;
578 pConn = fakeConnection( NULL, LDAP_REQ_ADD );
579 if ( pConn == NULL ) {
584 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
585 NULL, &isCritical ) ) {
589 op = (Operation *)pConn->c_pending_ops.stqh_first;
590 pPB = (Slapi_PBlock *)op->o_pb;
591 op->o_ctrls = controls;
593 be = select_backend( &e->e_nname, manageDsaIt, 0 );
595 rc = LDAP_PARTIAL_RESULTS;
599 op->o_dn = pConn->c_dn = be->be_rootdn;
600 op->o_ndn = pConn->c_ndn = be->be_rootndn;
604 int repl_user = be_isupdate( be, &op->o_ndn );
605 if ( !be->be_update_ndn.bv_len || repl_user ){
606 if ( (*be->be_add)( op, &rs ) == 0 ) {
616 rc = LDAP_UNWILLING_TO_PERFORM;
622 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
625 if ( pConn != NULL ) {
626 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
627 if ( op != NULL ) slapi_ch_free( (void **)&op );
632 #endif /* LDAP_SLAPI */
641 LDAPControl **controls,
644 #if defined(LDAP_SLAPI)
645 LDAPMod *pMod = NULL;
646 Slapi_PBlock *pb = NULL;
647 Entry *pEntry = NULL;
648 int i, rc=LDAP_SUCCESS;
650 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
651 rc = LDAP_PARAM_ERROR ;
654 if ( rc == LDAP_SUCCESS ) {
655 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
656 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
663 if ( rc == LDAP_SUCCESS ) {
664 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
669 if ( rc != LDAP_SUCCESS ) {
670 pb = slapi_pblock_new();
671 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
673 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
677 slapi_entry_free(pEntry);
681 #endif /* LDAP_SLAPI */
685 /* Function : slapi_modrdn_internal
687 * Description : Plugin functions call this routine to modify the rdn
688 * of an entry in the backend directly
689 * Return values : LDAP_SUCCESS
693 * LDAP_UNWILLING_TO_PERFORM
695 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
698 slapi_modrdn_internal(
702 LDAPControl **controls,
705 #if defined(LDAP_SLAPI)
706 int rc = LDAP_SUCCESS;
707 struct berval dn = { 0, NULL };
708 struct berval newrdn = { 0, NULL };
709 Connection *pConn = NULL;
710 Operation *op = NULL;
711 Slapi_PBlock *pPB = NULL;
712 Slapi_PBlock *pSavePB = NULL;
716 SlapReply rs = { REP_RESULT };
718 pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);
719 if ( pConn == NULL) {
724 op = (Operation *)pConn->c_pending_ops.stqh_first;
725 pPB = (Slapi_PBlock *)op->o_pb;
726 op->o_ctrls = controls;
728 if ( slapi_control_present( controls,
729 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
733 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
735 rc = LDAP_PARTIAL_RESULTS;
739 op->o_dn = pConn->c_dn = be->be_rootdn;
740 op->o_ndn = pConn->c_ndn = be->be_rootndn;
742 dn.bv_val = slapi_ch_strdup( olddn );
743 dn.bv_len = strlen( olddn );
745 rc = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
746 if ( rc != LDAP_SUCCESS ) {
750 if ( op->o_req_dn.bv_len == 0 ) {
751 rc = LDAP_UNWILLING_TO_PERFORM;
755 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
756 newrdn.bv_len = strlen( lnewrdn );
758 rc = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn );
759 if ( rc != LDAP_SUCCESS ) {
763 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
767 op->oq_modrdn.rs_newSup = NULL;
768 op->oq_modrdn.rs_nnewSup = NULL;
769 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
771 if ( be->be_modrdn ) {
772 int repl_user = be_isupdate( be, &op->o_ndn );
773 if ( !be->be_update_ndn.bv_len || repl_user ) {
774 rc = (*be->be_modrdn)( op, &rs );
790 rc = LDAP_UNWILLING_TO_PERFORM;
796 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
800 slapi_ch_free( (void **)&dn.bv_val );
801 if ( op->o_req_dn.bv_val )
802 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
803 if ( op->o_req_ndn.bv_val )
804 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
807 slapi_ch_free( (void **)&newrdn.bv_val );
808 if ( op->oq_modrdn.rs_newrdn.bv_val )
809 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
810 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
811 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
813 if ( pConn != NULL ) {
814 if ( pConn->c_sb != NULL )
815 ber_sockbuf_free( pConn->c_sb );
817 slapi_ch_free( (void **)&op );
823 #endif /* LDAP_SLAPI */
827 /* Function : slapi_modify_internal
829 * Description: Plugin functions call this routine to modify an entry
830 * in the backend directly
831 * Return values : LDAP_SUCCESS
835 * LDAP_UNWILLING_TO_PERFORM
838 slapi_modify_internal(
841 LDAPControl **controls,
844 #if defined(LDAP_SLAPI)
845 int i, rc = LDAP_SUCCESS;
846 Connection *pConn = NULL;
847 Operation *op = NULL;
848 Slapi_PBlock *pPB = NULL;
849 Slapi_PBlock *pSavePB = NULL;
851 struct berval dn = { 0, NULL };
859 Modifications *modlist = NULL;
860 Modifications **modtail = &modlist;
863 SlapReply rs = { REP_RESULT };
865 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
866 rc = LDAP_PARAM_ERROR ;
870 pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );
871 if ( pConn == NULL ) {
876 op = (Operation *)pConn->c_pending_ops.stqh_first;
877 pPB = (Slapi_PBlock *)op->o_pb;
878 op->o_ctrls = controls;
880 dn.bv_val = slapi_ch_strdup( ldn );
881 dn.bv_len = strlen( ldn );
882 rc = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
883 if ( rc != LDAP_SUCCESS ) {
887 if ( slapi_control_present( controls,
888 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
892 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
894 rc = LDAP_PARTIAL_RESULTS;
898 op->o_dn = pConn->c_dn = be->be_rootdn;
899 op->o_ndn = pConn->c_ndn = be->be_rootndn;
901 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL;
904 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
906 * attr values are in berval format
907 * convert an array of pointers to bervals
908 * to an array of bervals
910 rc = bvptr2obj( pMod->mod_bvalues, &bv );
911 if ( rc != LDAP_SUCCESS ) goto cleanup;
912 tmp.sml_type.bv_val = pMod->mod_type;
913 tmp.sml_type.bv_len = strlen( pMod->mod_type );
914 tmp.sml_bvalues = bv;
916 tmp.sml_nvalues = NULL;
919 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
921 mod->sml_op = pMod->mod_op;
922 mod->sml_next = NULL;
923 mod->sml_desc = NULL;
924 mod->sml_type = tmp.sml_type;
925 mod->sml_bvalues = tmp.sml_bvalues;
927 mod->sml_nvalues = tmp.sml_nvalues;
930 rc = values2obj( pMod->mod_values, &bv );
931 if ( rc != LDAP_SUCCESS ) goto cleanup;
932 tmp.sml_type.bv_val = pMod->mod_type;
933 tmp.sml_type.bv_len = strlen( pMod->mod_type );
934 tmp.sml_bvalues = bv;
936 tmp.sml_nvalues = NULL;
939 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
941 mod->sml_op = pMod->mod_op;
942 mod->sml_next = NULL;
943 mod->sml_desc = NULL;
944 mod->sml_type = tmp.sml_type;
945 mod->sml_bvalues = tmp.sml_bvalues;
947 mod->sml_nvalues = tmp.sml_nvalues;
951 modtail = &mod->sml_next;
953 switch( pMod->mod_op ) {
955 if ( mod->sml_bvalues == NULL ) {
956 rc = LDAP_PROTOCOL_ERROR;
961 case LDAP_MOD_DELETE:
962 case LDAP_MOD_REPLACE:
966 rc = LDAP_PROTOCOL_ERROR;
972 if ( op->o_req_ndn.bv_len == 0 ) {
973 rc = LDAP_UNWILLING_TO_PERFORM;
977 op->oq_modify.rs_modlist = modlist;
979 if ( be->be_modify ) {
980 int repl_user = be_isupdate( be, &op->o_ndn );
981 if ( !be->be_update_ndn.bv_len || repl_user ) {
982 int update = be->be_update_ndn.bv_len;
983 const char *text = NULL;
984 char textbuf[SLAP_TEXT_BUFLEN];
985 size_t textlen = sizeof( textbuf );
987 rc = slap_mods_check( modlist, update,
988 &text, textbuf, textlen );
989 if (rc != LDAP_SUCCESS) {
994 rc = slap_mods_opattrs( op, modlist,
995 modtail, &text, textbuf,
997 if (rc != LDAP_SUCCESS) {
1001 rc = (*be->be_modify)( op, &rs );
1014 rc = LDAP_UNWILLING_TO_PERFORM;
1020 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1023 slapi_ch_free( (void **)&dn.bv_val );
1024 if ( op->o_req_dn.bv_val )
1025 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1026 if ( op->o_req_ndn.bv_val )
1027 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1029 if ( modlist != NULL ) freeMods( modlist );
1031 if ( pConn != NULL ) {
1032 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
1033 if ( op != NULL ) slapi_ch_free( (void **)&op );
1040 #endif /* LDAP_SLAPI */
1045 slapi_search_internal_bind(
1050 LDAPControl **controls,
1054 #if defined(LDAP_SLAPI)
1057 Operation *op = NULL;
1058 Slapi_PBlock *ptr = NULL;
1059 Slapi_PBlock *pSavePB = NULL;
1060 struct berval dn = { 0, NULL };
1061 Filter *filter=NULL;
1062 struct berval fstr = { 0, NULL };
1063 AttributeName *an = NULL;
1064 const char *text = NULL;
1066 int manageDsaIt = 0;
1069 int i, rc = LDAP_SUCCESS;
1071 SlapReply rs = { REP_RESULT };
1073 c = fakeConnection( NULL, LDAP_REQ_SEARCH );
1075 rc = LDAP_NO_MEMORY;
1079 op = (Operation *)c->c_pending_ops.stqh_first;
1080 ptr = (Slapi_PBlock *)op->o_pb;
1081 op->o_ctrls = controls;
1083 dn.bv_val = slapi_ch_strdup(ldn);
1084 dn.bv_len = strlen(ldn);
1086 rc = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
1087 if ( rc != LDAP_SUCCESS ) {
1091 if ( scope != LDAP_SCOPE_BASE &&
1092 scope != LDAP_SCOPE_ONELEVEL &&
1093 scope != LDAP_SCOPE_SUBTREE ) {
1094 rc = LDAP_PROTOCOL_ERROR;
1098 filter = slapi_str2filter(filStr);
1099 if ( filter == NULL ) {
1100 rc = LDAP_PROTOCOL_ERROR;
1104 filter2bv( filter, &fstr );
1106 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1107 ; /* count the number of attributes */
1111 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1112 for (i = 0; attrs[i] != 0; i++) {
1113 an[i].an_desc = NULL;
1115 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1116 an[i].an_name.bv_len = strlen(attrs[i]);
1117 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1119 an[i].an_name.bv_val = NULL;
1122 memset( &rs, 0, sizeof(rs) );
1123 rs.sr_type = REP_RESULT;
1124 rs.sr_err = LDAP_OTHER;
1126 if ( scope == LDAP_SCOPE_BASE ) {
1129 if ( op->o_req_ndn.bv_len == 0 ) {
1130 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1133 if( rs.sr_err != LDAP_SUCCESS ) {
1134 send_ldap_result( op, &rs );
1136 } else if ( rs.sr_entry != NULL ) {
1137 rc = test_filter( op, rs.sr_entry, filter );
1139 if( rc == LDAP_COMPARE_TRUE ) {
1140 rs.sr_type = REP_SEARCH;
1141 rs.sr_err = LDAP_SUCCESS;
1144 send_search_entry( op, &rs );
1147 entry_free( rs.sr_entry );
1149 rs.sr_type = REP_RESULT;
1150 rs.sr_err = LDAP_SUCCESS;
1152 send_ldap_result( op, &rs );
1160 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1161 slapi_ch_free( (void **)op->o_req_dn.bv_val );
1162 slapi_ch_free( (void **)op->o_req_ndn.bv_val );
1164 ber_dupbv( &op->o_req_dn, &default_search_base );
1165 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1168 if ( slapi_control_present( controls,
1169 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1173 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1175 if ( manageDsaIt == 1 ) {
1176 rc = LDAP_NO_SUCH_OBJECT;
1178 rc = LDAP_PARTIAL_RESULTS;
1183 op->o_dn = c->c_dn = be->be_rootdn;
1184 op->o_ndn = c->c_ndn = be->be_rootndn;
1186 op->oq_search.rs_scope = scope;
1187 op->oq_search.rs_deref = 0;
1188 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1189 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1190 op->oq_search.rs_attrsonly = attrsonly;
1191 op->oq_search.rs_attrs = an;
1192 op->oq_search.rs_filter = filter;
1193 op->oq_search.rs_filterstr = fstr;
1195 if ( be->be_search ) {
1196 rc = (*be->be_search)( op, &rs );
1203 rc = LDAP_UNWILLING_TO_PERFORM;
1209 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1212 slapi_ch_free( (void **)&dn.bv_val );
1213 if ( op->o_req_dn.bv_val )
1214 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1215 if ( op->o_req_ndn.bv_val )
1216 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1218 if ( filter ) slapi_filter_free( filter, 1 );
1219 if ( fstr.bv_val ) free ( fstr.bv_val );
1221 if ( an != NULL ) free( an );
1224 if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );
1225 if ( op != NULL ) slapi_ch_free( (void **)&op );
1230 #endif /* LDAP_SLAPI */
1235 slapi_search_internal(
1239 LDAPControl **controls,
1243 #if defined(LDAP_SLAPI)
1244 return slapi_search_internal_bind( NULL, base, scope, filStr,
1245 controls, attrs, attrsonly );
1248 #endif /* LDAP_SLAPI */