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.
17 #include "../../../libraries/liblber/lber-int.h"
20 int bvptr2obj( struct berval **bvptr, struct berval **bvobj );
36 internal_search_entry(
46 int nentries = 0, len = 0, i = 0;
47 Slapi_Entry **head = NULL, **tp;
49 ent2str = slapi_entry2str( e, &len );
50 if ( ent2str == NULL ) {
54 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
55 SLAPI_NENTRIES, &nentries );
56 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
57 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
60 if ( nentries == 0 ) {
61 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
66 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
67 if ( tp[ 0 ] == NULL ) {
72 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
73 sizeof(Slapi_Entry *) * ( i + 1 ) );
77 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
78 if ( tp[ i - 1 ] == NULL ) {
84 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
85 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
86 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
87 SLAPI_NENTRIES, (void *)i );
93 internal_search_result(
103 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
104 SLAPI_NENTRIES, (void *)nentries );
118 struct berval *rspdata,
119 LDAPControl **ctrls )
125 internal_search_reference(
142 Connection *pConn, *c;
143 ber_len_t max = sockbuf_max_incoming;
145 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
147 return (Connection *)NULL;
150 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
152 pConn->c_pending_ops.stqh_first =
153 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
154 if ( pConn->c_pending_ops.stqh_first == NULL ) {
155 slapi_ch_free( (void **)&pConn );
156 return (Connection *)NULL;
159 pConn->c_pending_ops.stqh_first->o_pb =
160 (Slapi_PBlock *) slapi_pblock_new();
161 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
162 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
163 slapi_ch_free( (void **)&pConn );
164 return (Connection *)NULL;
169 /* operation object */
170 c->c_pending_ops.stqh_first->o_tag = OpType;
171 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
172 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
173 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
174 c->c_pending_ops.stqh_first->o_time = slap_get_time();
175 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
176 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );
178 /* connection object */
179 c->c_authmech.bv_val = NULL;
180 c->c_authmech.bv_len = 0;
181 c->c_dn.bv_val = NULL;
183 c->c_ndn.bv_val = NULL;
187 c->c_listener = NULL;
188 c->c_peer_domain.bv_val = NULL;
189 c->c_peer_domain.bv_len = 0;
190 c->c_peer_name.bv_val = NULL;
191 c->c_peer_name.bv_len = 0;
193 LDAP_STAILQ_INIT( &c->c_ops );
195 c->c_sasl_bind_mech.bv_val = NULL;
196 c->c_sasl_bind_mech.bv_len = 0;
197 c->c_sasl_context = NULL;
198 c->c_sasl_extra = NULL;
200 c->c_sb = ber_sockbuf_alloc( );
202 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
204 c->c_currentber = NULL;
206 /* should check status of thread calls */
207 ldap_pvt_thread_mutex_init( &c->c_mutex );
208 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
209 ldap_pvt_thread_cond_init( &c->c_write_cv );
211 c->c_n_ops_received = 0;
212 c->c_n_ops_executing = 0;
213 c->c_n_ops_pending = 0;
214 c->c_n_ops_completed = 0;
220 c->c_protocol = LDAP_VERSION3;
222 c->c_activitytime = c->c_starttime = slap_get_time();
226 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
227 c->c_struct_state = 0x02; /* SLAP_C_USED */
229 c->c_ssf = c->c_transport_ssf = 0;
232 backend_connection_init( c );
234 pConn->c_send_ldap_result = internal_result_v3;
235 pConn->c_send_search_entry = internal_search_entry;
236 pConn->c_send_search_result = internal_search_result;
237 pConn->c_send_ldap_extended = internal_result_ext;
238 pConn->c_send_search_reference = internal_search_reference;
244 * Function : values2obj
245 * Convert an array of strings into a BerVarray.
256 if ( ppValue == NULL ) {
261 for ( i = 0; ppValue[i] != NULL; i++ )
264 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
265 if ( tmpberval == NULL ) {
266 return LDAP_NO_MEMORY;
268 for ( i = 0; ppValue[i] != NULL; i++ ) {
269 tmpberval[i].bv_val = ppValue[i];
270 tmpberval[i].bv_len = strlen( ppValue[i] );
272 tmpberval[i].bv_val = NULL;
273 tmpberval[i].bv_len = 0;
281 freeMods( Modifications *ml )
284 * Free a modification list whose values have been
285 * set with bvptr2obj() or values2obj() (ie. they
286 * do not own the pointer to the underlying values)
290 for ( ; ml != NULL; ml = next ) {
293 slapi_ch_free( (void **)&ml->sml_bvalues );
295 slapi_ch_free( (void **)&ml->sml_nvalues );
297 slapi_ch_free( (void **)&ml );
302 * Function : LDAPModToEntry
303 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
304 * with a link list of the correspondent attributes.
305 * Return value : LDAP_SUCCESS
314 struct berval dn = { 0, NULL };
321 Modifications *modlist = NULL;
322 Modifications **modtail = &modlist;
325 int rc = LDAP_SUCCESS;
328 const char *text = NULL;
331 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
332 if ( pEntry == NULL) {
336 op->o_tag = LDAP_REQ_ADD;
338 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
339 if ( pEntry == NULL) {
344 dn.bv_val = slapi_ch_strdup(ldn);
345 dn.bv_len = strlen(ldn);
347 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
348 if (rc != LDAP_SUCCESS) goto cleanup;
350 if ( rc == LDAP_SUCCESS ) {
351 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
353 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
354 /* attr values are in berval format */
355 /* convert an array of pointers to bervals to an array of bervals */
356 rc = bvptr2obj(pMod->mod_bvalues, &bv);
357 if (rc != LDAP_SUCCESS) goto cleanup;
358 tmp.sml_type.bv_val = pMod->mod_type;
359 tmp.sml_type.bv_len = strlen( pMod->mod_type );
360 tmp.sml_bvalues = bv;
362 tmp.sml_nvalues = NULL;
365 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
367 mod->sml_op = LDAP_MOD_ADD;
368 mod->sml_next = NULL;
369 mod->sml_desc = NULL;
370 mod->sml_type = tmp.sml_type;
371 mod->sml_bvalues = tmp.sml_bvalues;
373 mod->sml_nvalues = tmp.sml_nvalues;
377 modtail = &mod->sml_next;
380 /* attr values are in string format, need to be converted */
381 /* to an array of bervals */
382 if ( pMod->mod_values == NULL ) {
385 rc = values2obj( pMod->mod_values, &bv );
386 if (rc != LDAP_SUCCESS) goto cleanup;
387 tmp.sml_type.bv_val = pMod->mod_type;
388 tmp.sml_type.bv_len = strlen( pMod->mod_type );
389 tmp.sml_bvalues = bv;
391 tmp.sml_nvalues = NULL;
394 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
396 mod->sml_op = LDAP_MOD_ADD;
397 mod->sml_next = NULL;
398 mod->sml_desc = NULL;
399 mod->sml_type = tmp.sml_type;
400 mod->sml_bvalues = tmp.sml_bvalues;
402 mod->sml_nvalues = tmp.sml_nvalues;
406 modtail = &mod->sml_next;
409 } /* for each LDAPMod */
412 be = select_backend(&pEntry->e_nname, 0, 0);
414 rc = LDAP_PARTIAL_RESULTS;
419 int repl_user = be_isupdate(be, &be->be_rootdn );
420 if ( !be->be_update_ndn.bv_len || repl_user ) {
421 int update = be->be_update_ndn.bv_len;
422 char textbuf[SLAP_TEXT_BUFLEN];
423 size_t textlen = sizeof textbuf;
425 rc = slap_mods_check( modlist, update, &text,
427 if ( rc != LDAP_SUCCESS) {
432 rc = slap_mods_opattrs( be, op,
433 modlist, modtail, &text,
435 if ( rc != LDAP_SUCCESS) {
441 * FIXME: slap_mods2entry is declared static
442 * in servers/slapd/add.c
444 rc = slap_mods2entry( modlist, &pEntry, repl_user,
445 &text, textbuf, textlen );
446 if (rc != LDAP_SUCCESS) {
454 rc = LDAP_UNWILLING_TO_PERFORM;
459 if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );
460 if ( op ) slapi_ch_free( (void **)&op );
461 if ( modlist != NULL ) freeMods( modlist );
462 if ( rc != LDAP_SUCCESS ) {
463 if ( pEntry != NULL ) {
464 slapi_entry_free( pEntry );
472 /* Function : slapi_delete_internal
474 * Description : Plugin functions call this routine to delete an entry
475 * in the backend directly
476 * Return values : LDAP_SUCCESS
480 * LDAP_UNWILLING_TO_PERFORM
483 slapi_delete_internal(
485 LDAPControl **controls,
488 #if defined(LDAP_SLAPI)
490 Connection *pConn = NULL;
491 Operation *op = NULL;
492 Slapi_PBlock *pPB = NULL;
493 Slapi_PBlock *pSavePB = NULL;
495 struct berval dn = { 0, NULL };
496 struct berval pdn = { 0, NULL };
497 struct berval ndn = { 0, NULL };
504 rc = LDAP_PARAM_ERROR;
508 pConn = fakeConnection( NULL, LDAP_REQ_DELETE );
514 op = (Operation *)pConn->c_pending_ops.stqh_first;
515 pPB = (Slapi_PBlock *)op->o_pb;
516 op->o_ctrls = controls;
518 dn.bv_val = slapi_ch_strdup(ldn);
519 dn.bv_len = slapi_strlen(ldn);
520 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
521 if ( rc != LDAP_SUCCESS ) goto cleanup;
523 if ( slapi_control_present( controls,
524 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
528 be = select_backend( &ndn, manageDsaIt, 0 );
530 rc = LDAP_PARTIAL_RESULTS;
534 op->o_dn = pConn->c_dn = be->be_rootdn;
535 op->o_ndn = pConn->c_ndn = be->be_rootndn;
537 if ( be->be_delete ) {
538 int repl_user = be_isupdate( be, &op->o_ndn );
539 if ( !be->be_update_ndn.bv_len || repl_user ) {
540 rc = (*be->be_delete)( be, pConn, op, &pdn, &ndn );
543 replog( be, op, &pdn, &ndn, NULL );
553 rc = LDAP_UNWILLING_TO_PERFORM;
558 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
560 if (dn.bv_val) slapi_ch_free( (void **)&dn.bv_val );
561 if (pdn.bv_val) slapi_ch_free( (void **)&pdn.bv_val );
562 if (ndn.bv_val) slapi_ch_free( (void **)&ndn.bv_val );
564 if ( pConn != NULL ) {
565 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
566 if ( op ) slapi_ch_free( (void **)&op );
572 #endif /* LDAP_SLAPI */
577 slapi_add_entry_internal(
579 LDAPControl **controls,
582 #if defined(LDAP_SLAPI)
583 Connection *pConn = NULL;
584 Operation *op = NULL;
585 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
590 int rc = LDAP_SUCCESS;
593 rc = LDAP_PARAM_ERROR;
597 pConn = fakeConnection( NULL, LDAP_REQ_ADD );
598 if ( pConn == NULL ) {
603 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
604 NULL, &isCritical ) ) {
608 op = (Operation *)pConn->c_pending_ops.stqh_first;
609 pPB = (Slapi_PBlock *)op->o_pb;
610 op->o_ctrls = controls;
612 be = select_backend( &e->e_nname, manageDsaIt, 0 );
614 rc = LDAP_PARTIAL_RESULTS;
618 op->o_dn = pConn->c_dn = be->be_rootdn;
619 op->o_ndn = pConn->c_ndn = be->be_rootndn;
622 int repl_user = be_isupdate( be, &op->o_ndn );
623 if ( !be->be_update_ndn.bv_len || repl_user ){
624 if ( (*be->be_add)( be, pConn, op, e ) == 0 ) {
626 replog( be, op, &e->e_name,
635 rc = LDAP_UNWILLING_TO_PERFORM;
641 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
644 if ( pConn != NULL ) {
645 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
646 if ( op != NULL ) slapi_ch_free( (void **)&op );
651 #endif /* LDAP_SLAPI */
660 LDAPControl **controls,
663 #if defined(LDAP_SLAPI)
664 LDAPMod *pMod = NULL;
665 Slapi_PBlock *pb = NULL;
666 Entry *pEntry = NULL;
667 int i, rc=LDAP_SUCCESS;
669 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
670 rc = LDAP_PARAM_ERROR ;
673 if ( rc == LDAP_SUCCESS ) {
674 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
675 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
682 if ( rc == LDAP_SUCCESS ) {
683 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
688 if ( rc != LDAP_SUCCESS ) {
689 pb = slapi_pblock_new();
690 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
692 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
696 slapi_entry_free(pEntry);
700 #endif /* LDAP_SLAPI */
704 /* Function : slapi_modrdn_internal
706 * Description : Plugin functions call this routine to modify the rdn
707 * of an entry in the backend directly
708 * Return values : LDAP_SUCCESS
712 * LDAP_UNWILLING_TO_PERFORM
714 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
717 slapi_modrdn_internal(
721 LDAPControl **controls,
724 #if defined(LDAP_SLAPI)
725 int rc = LDAP_SUCCESS;
727 struct berval dn = { 0, NULL };
728 struct berval pdn = { 0, NULL };
729 struct berval ndn = { 0, NULL };
731 struct berval newrdn = { 0, NULL };
732 struct berval pnewrdn = { 0, NULL };
733 struct berval nnewrdn = { 0, NULL };
735 #if 0 /* currently unused */
736 struct berval newSuperior = { 0, NULL };
738 struct berval pnewSuperior = { 0, NULL };
739 #if 0 /* currently unused */
740 struct berval nnewSuperior = { 0, NULL };
743 struct berval *pnewS = NULL;
744 struct berval *nnewS = NULL;
746 Connection *pConn = NULL;
747 Operation *op = NULL;
748 Slapi_PBlock *pPB = NULL;
749 Slapi_PBlock *pSavePB = NULL;
752 #if 0 /* currently unused */
753 Backend *newSuperior_be = NULL;
758 #if 0 /* currently unused */
759 const char *text = NULL;
762 dn.bv_val = slapi_ch_strdup(olddn);
763 dn.bv_len = slapi_ch_stlen(olddn);
765 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
767 if ( rc != LDAP_SUCCESS ) goto cleanup;
769 if ( ndn.bv_len == 0 ) {
770 rc = LDAP_UNWILLING_TO_PERFORM;
774 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
775 newrdn.bv_len = slapi_ch_stlen( lnewrdn );
777 rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );
779 if ( rc != LDAP_SUCCESS ) goto cleanup;
781 if ( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) goto cleanup;
783 pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);
784 if ( pConn == NULL) {
789 op = (Operation *)pConn->c_pending_ops.stqh_first;
790 pPB = (Slapi_PBlock *)op->o_pb;
791 op->o_ctrls = controls;
793 if ( slapi_control_present( controls,
794 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
798 be = select_backend( &ndn, manageDsaIt, 0 );
800 rc = LDAP_PARTIAL_RESULTS;
804 op->o_dn = pConn->c_dn = be->be_rootdn;
805 op->o_ndn = pConn->c_ndn = be->be_rootndn;
807 if ( be->be_modrdn ) {
808 int repl_user = be_isupdate( be, &op->o_ndn );
809 if ( !be->be_update_ndn.bv_len || repl_user ) {
810 rc = (*be->be_modrdn)( be, pConn, op, &pdn, &ndn,
811 &pnewrdn, &nnewrdn, deloldrdn, pnewS,
814 struct slap_replog_moddn moddn;
815 moddn.newrdn = &pnewrdn;
816 moddn.deloldrdn = deloldrdn;
817 moddn.newsup = &pnewSuperior;
819 replog( be, op, &pdn, &ndn, &moddn );
832 rc = LDAP_UNWILLING_TO_PERFORM;
838 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
841 if ( dn.bv_val ) ch_free( dn.bv_val );
842 if ( pdn.bv_val ) ch_free( pdn.bv_val );
843 if ( ndn.bv_val ) ch_free( ndn.bv_val );
845 if ( newrdn.bv_val ) ch_free( newrdn.bv_val );
846 if ( pnewrdn.bv_val ) ch_free( newrdn.bv_val );
847 if ( nnewrdn.bv_val ) ch_free( newrdn.bv_val );
849 if ( pConn != NULL ) {
850 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
851 if ( op != NULL ) slapi_ch_free( (void **)&op );
857 #endif /* LDAP_SLAPI */
861 /* Function : slapi_modify_internal
863 * Description: Plugin functions call this routine to modify an entry
864 * in the backend directly
865 * Return values : LDAP_SUCCESS
869 * LDAP_UNWILLING_TO_PERFORM
872 slapi_modify_internal(
875 LDAPControl **controls,
878 #if defined(LDAP_SLAPI)
879 int i, rc = LDAP_SUCCESS;
880 Connection *pConn = NULL;
881 Operation *op = NULL;
882 Slapi_PBlock *pPB = NULL;
883 Slapi_PBlock *pSavePB = NULL;
885 struct berval dn = { 0, NULL };
886 struct berval pdn = { 0, NULL };
887 struct berval ndn = { 0, NULL };
895 Modifications *modlist = NULL;
896 Modifications **modtail = &modlist;
899 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
900 rc = LDAP_PARAM_ERROR ;
904 pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );
905 if ( pConn == NULL ) {
910 op = (Operation *)pConn->c_pending_ops.stqh_first;
911 pPB = (Slapi_PBlock *)op->o_pb;
912 op->o_ctrls = controls;
914 dn.bv_val = slapi_ch_strdup( ldn );
915 dn.bv_len = slapi_strlen( ldn );
916 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
917 if ( rc != LDAP_SUCCESS ) goto cleanup;
919 if ( slapi_control_present( controls,
920 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
924 be = select_backend( &ndn, manageDsaIt, 0 );
926 rc = LDAP_PARTIAL_RESULTS;
930 op->o_dn = pConn->c_dn = be->be_rootdn;
931 op->o_ndn = pConn->c_ndn = be->be_rootndn;
933 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL;
936 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
938 * attr values are in berval format
939 * convert an array of pointers to bervals
940 * to an array of bervals
942 rc = bvptr2obj( pMod->mod_bvalues, &bv );
943 if ( rc != LDAP_SUCCESS ) goto cleanup;
944 tmp.sml_type.bv_val = pMod->mod_type;
945 tmp.sml_type.bv_len = strlen( pMod->mod_type );
946 tmp.sml_bvalues = bv;
948 tmp.sml_nvalues = NULL;
951 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
953 mod->sml_op = pMod->mod_op;
954 mod->sml_next = NULL;
955 mod->sml_desc = NULL;
956 mod->sml_type = tmp.sml_type;
957 mod->sml_bvalues = tmp.sml_bvalues;
959 mod->sml_nvalues = tmp.sml_nvalues;
962 rc = values2obj( pMod->mod_values, &bv );
963 if ( rc != LDAP_SUCCESS ) goto cleanup;
964 tmp.sml_type.bv_val = pMod->mod_type;
965 tmp.sml_type.bv_len = strlen( pMod->mod_type );
966 tmp.sml_bvalues = bv;
968 tmp.sml_nvalues = NULL;
971 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
973 mod->sml_op = pMod->mod_op;
974 mod->sml_next = NULL;
975 mod->sml_desc = NULL;
976 mod->sml_type = tmp.sml_type;
977 mod->sml_bvalues = tmp.sml_bvalues;
979 mod->sml_nvalues = tmp.sml_nvalues;
983 modtail = &mod->sml_next;
985 switch( pMod->mod_op ) {
987 if ( mod->sml_bvalues == NULL ) {
988 rc = LDAP_PROTOCOL_ERROR;
993 case LDAP_MOD_DELETE:
994 case LDAP_MOD_REPLACE:
998 rc = LDAP_PROTOCOL_ERROR;
1004 if ( ndn.bv_len == 0 ) {
1005 rc = LDAP_UNWILLING_TO_PERFORM;
1009 if ( be->be_modify ) {
1010 int repl_user = be_isupdate( be, &op->o_ndn );
1011 if ( !be->be_update_ndn.bv_len || repl_user ) {
1012 int update = be->be_update_ndn.bv_len;
1013 const char *text = NULL;
1014 char textbuf[SLAP_TEXT_BUFLEN];
1015 size_t textlen = sizeof( textbuf );
1017 rc = slap_mods_check( modlist, update,
1018 &text, textbuf, textlen );
1019 if (rc != LDAP_SUCCESS) {
1024 rc = slap_mods_opattrs( be, op, modlist,
1025 modtail, &text, textbuf,
1027 if (rc != LDAP_SUCCESS) {
1031 rc = (*be->be_modify)( be, pConn, op,
1032 &pdn, &ndn, modlist );
1035 replog( be, op, &pdn, &ndn, modlist );
1045 rc = LDAP_UNWILLING_TO_PERFORM;
1051 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1053 if ( dn.bv_val ) ch_free( dn.bv_val );
1054 if ( pdn.bv_val ) ch_free( pdn.bv_val );
1055 if ( ndn.bv_val ) ch_free( ndn.bv_val );
1057 if ( modlist != NULL ) freeMods( modlist );
1059 if ( pConn != NULL ) {
1060 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
1061 if ( op != NULL ) slapi_ch_free( (void **)&op );
1068 #endif /* LDAP_SLAPI */
1073 slapi_search_internal_bind(
1078 LDAPControl **controls,
1082 #if defined(LDAP_SLAPI)
1085 Operation *op = NULL;
1086 Slapi_PBlock *ptr = NULL;
1087 Slapi_PBlock *pSavePB = NULL;
1088 struct berval dn = { 0, NULL };
1089 struct berval pdn = { 0, NULL };
1090 struct berval ndn = { 0, NULL };
1091 Filter *filter=NULL;
1092 struct berval fstr = { 0, NULL };
1093 AttributeName *an = NULL;
1094 const char *text = NULL;
1097 int sizelimit=-1, timelimit=-1;
1099 int manageDsaIt = 0;
1102 int i, rc = LDAP_SUCCESS;
1104 c = fakeConnection( NULL, LDAP_REQ_SEARCH );
1106 rc = LDAP_NO_MEMORY;
1110 op = (Operation *)c->c_pending_ops.stqh_first;
1111 ptr = (Slapi_PBlock *)op->o_pb;
1112 op->o_ctrls = controls;
1114 dn.bv_val = slapi_ch_strdup(ldn);
1115 dn.bv_len = slapi_strlen(ldn);
1117 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
1118 if (rc != LDAP_SUCCESS) goto cleanup;
1120 if ( scope != LDAP_SCOPE_BASE &&
1121 scope != LDAP_SCOPE_ONELEVEL &&
1122 scope != LDAP_SCOPE_SUBTREE ) {
1123 rc = LDAP_PROTOCOL_ERROR;
1127 filter = slapi_str2filter(filStr);
1128 if ( filter == NULL ) {
1129 rc = LDAP_PROTOCOL_ERROR;
1133 filter2bv( filter, &fstr );
1135 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1136 ; /* count the number of attributes */
1140 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1141 for (i = 0; attrs[i] != 0; i++) {
1142 an[i].an_desc = NULL;
1144 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1145 an[i].an_name.bv_len = slapi_strlen(attrs[i]);
1146 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1148 an[i].an_name.bv_val = NULL;
1151 if ( scope == LDAP_SCOPE_BASE ) {
1152 Entry *entry = NULL;
1154 if ( ndn.bv_len == 0 ) {
1155 rc = root_dse_info( c, &entry, &text );
1158 if( rc != LDAP_SUCCESS ) {
1159 send_ldap_result( c, op, rc, NULL, text, NULL, NULL );
1161 } else if ( entry != NULL ) {
1162 rc = test_filter( NULL, c, op, entry, filter );
1164 if( rc == LDAP_COMPARE_TRUE ) {
1165 send_search_entry( NULL, c, op, entry,
1166 an, attrsonly, NULL );
1169 entry_free( entry );
1171 send_ldap_result( c, op, LDAP_SUCCESS,
1172 NULL, NULL, NULL, NULL );
1180 if ( !ndn.bv_len && default_search_nbase.bv_len ) {
1181 ch_free( pdn.bv_val );
1182 ch_free( ndn.bv_val );
1184 ber_dupbv( &pdn, &default_search_base );
1185 ber_dupbv( &ndn, &default_search_nbase );
1188 if ( slapi_control_present( controls,
1189 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1193 be = select_backend( &ndn, manageDsaIt, 0 );
1195 if ( manageDsaIt == 1 ) {
1196 rc = LDAP_NO_SUCH_OBJECT;
1198 rc = LDAP_PARTIAL_RESULTS;
1203 op->o_dn = c->c_dn = be->be_rootdn;
1204 op->o_ndn = c->c_ndn = be->be_rootndn;
1206 if ( be->be_search ) {
1207 rc = (*be->be_search)( be, c, op, &pdn, &ndn,
1208 scope, deref, sizelimit, timelimit,
1209 filter, &fstr, an, attrsonly );
1216 rc = LDAP_UNWILLING_TO_PERFORM;
1222 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1224 if ( dn.bv_val ) free( dn.bv_val );
1225 if ( ndn.bv_val ) free( ndn.bv_val );
1226 if ( pdn.bv_val ) free( pdn.bv_val );
1228 if ( filter ) slapi_filter_free( filter, 1 );
1229 if ( fstr.bv_val ) free ( fstr.bv_val );
1231 if ( an != NULL ) free( an );
1234 if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );
1235 if ( op != NULL ) slapi_ch_free( (void **)&op );
1240 #endif /* LDAP_SLAPI */
1245 slapi_search_internal(
1249 LDAPControl **controls,
1253 #if defined(LDAP_SLAPI)
1254 return slapi_search_internal_bind( NULL, base, scope, filStr,
1255 controls, attrs, attrsonly );
1258 #endif /* LDAP_SLAPI */