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.
253 int rc = LDAP_SUCCESS;
257 if ( ppValue == NULL ) {
262 for ( i = 0; ppValue[i] != NULL; i++ )
265 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
266 if ( tmpberval == NULL ) {
267 return LDAP_NO_MEMORY;
269 for ( i = 0; ppValue[i] != NULL; i++ ) {
270 tmpberval[i].bv_val = ppValue[i];
271 tmpberval[i].bv_len = strlen( ppValue[i] );
273 tmpberval[i].bv_val = NULL;
274 tmpberval[i].bv_len = 0;
282 freeMods( Modifications *ml )
285 * Free a modification list whose values have been
286 * set with bvptr2obj() or values2obj() (ie. they
287 * do not own the pointer to the underlying values)
291 for ( ; ml != NULL; ml = next ) {
294 slapi_ch_free( (void **)&ml->sml_bvalues );
296 slapi_ch_free( (void **)&ml->sml_nvalues );
298 slapi_ch_free( (void **)&ml );
303 * Function : LDAPModToEntry
304 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
305 * with a link list of the correspondent attributes.
306 * Return value : LDAP_SUCCESS
315 struct berval dn = { 0, NULL };
322 Modifications *modlist = NULL;
323 Modifications **modtail = &modlist;
326 int rc = LDAP_SUCCESS;
329 const char *text = NULL;
332 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
333 if ( pEntry == NULL) {
337 op->o_tag = LDAP_REQ_ADD;
339 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
340 if ( pEntry == NULL) {
345 dn.bv_val = slapi_ch_strdup(ldn);
346 dn.bv_len = strlen(ldn);
348 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
349 if (rc != LDAP_SUCCESS) goto cleanup;
351 if ( rc == LDAP_SUCCESS ) {
352 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
354 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
355 /* attr values are in berval format */
356 /* convert an array of pointers to bervals to an array of bervals */
357 rc = bvptr2obj(pMod->mod_bvalues, &bv);
358 if (rc != LDAP_SUCCESS) goto cleanup;
359 tmp.sml_type.bv_val = pMod->mod_type;
360 tmp.sml_type.bv_len = strlen( pMod->mod_type );
361 tmp.sml_bvalues = bv;
363 tmp.sml_nvalues = NULL;
366 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
368 mod->sml_op = LDAP_MOD_ADD;
369 mod->sml_next = NULL;
370 mod->sml_desc = NULL;
371 mod->sml_type = tmp.sml_type;
372 mod->sml_bvalues = tmp.sml_bvalues;
374 mod->sml_nvalues = tmp.sml_nvalues;
378 modtail = &mod->sml_next;
381 /* attr values are in string format, need to be converted */
382 /* to an array of bervals */
383 if ( pMod->mod_values == NULL ) {
386 rc = values2obj( pMod->mod_values, &bv );
387 if (rc != LDAP_SUCCESS) goto cleanup;
388 tmp.sml_type.bv_val = pMod->mod_type;
389 tmp.sml_type.bv_len = strlen( pMod->mod_type );
390 tmp.sml_bvalues = bv;
392 tmp.sml_nvalues = NULL;
395 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
397 mod->sml_op = LDAP_MOD_ADD;
398 mod->sml_next = NULL;
399 mod->sml_desc = NULL;
400 mod->sml_type = tmp.sml_type;
401 mod->sml_bvalues = tmp.sml_bvalues;
403 mod->sml_nvalues = tmp.sml_nvalues;
407 modtail = &mod->sml_next;
410 } /* for each LDAPMod */
413 be = select_backend(&pEntry->e_nname, 0, 0);
415 rc = LDAP_PARTIAL_RESULTS;
420 int repl_user = be_isupdate(be, &be->be_rootdn );
421 if ( !be->be_update_ndn.bv_len || repl_user ) {
422 int update = be->be_update_ndn.bv_len;
423 char textbuf[SLAP_TEXT_BUFLEN];
424 size_t textlen = sizeof textbuf;
426 rc = slap_mods_check( modlist, update, &text,
428 if ( rc != LDAP_SUCCESS) {
433 rc = slap_mods_opattrs( be, op,
434 modlist, modtail, &text,
436 if ( rc != LDAP_SUCCESS) {
442 * FIXME: slap_mods2entry is declared static
443 * in servers/slapd/add.c
445 rc = slap_mods2entry( modlist, &pEntry, repl_user,
446 &text, textbuf, textlen );
447 if (rc != LDAP_SUCCESS) {
455 rc = LDAP_UNWILLING_TO_PERFORM;
460 if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );
461 if ( op ) slapi_ch_free( (void **)&op );
462 if ( modlist != NULL ) freeMods( modlist );
463 if ( rc != LDAP_SUCCESS ) {
464 if ( pEntry != NULL ) {
465 slapi_entry_free( pEntry );
473 /* Function : slapi_delete_internal
475 * Description : Plugin functions call this routine to delete an entry
476 * in the backend directly
477 * Return values : LDAP_SUCCESS
481 * LDAP_UNWILLING_TO_PERFORM
484 slapi_delete_internal(
486 LDAPControl **controls,
489 #if defined(LDAP_SLAPI)
491 Connection *pConn = NULL;
492 Operation *op = NULL;
493 Slapi_PBlock *pPB = NULL;
494 Slapi_PBlock *pSavePB = NULL;
496 struct berval dn = { 0, NULL };
497 struct berval pdn = { 0, NULL };
498 struct berval ndn = { 0, NULL };
505 rc = LDAP_PARAM_ERROR;
509 pConn = fakeConnection( NULL, LDAP_REQ_DELETE );
515 op = (Operation *)pConn->c_pending_ops.stqh_first;
516 pPB = (Slapi_PBlock *)op->o_pb;
517 op->o_ctrls = controls;
519 dn.bv_val = slapi_ch_strdup(ldn);
520 dn.bv_len = slapi_strlen(ldn);
521 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
522 if ( rc != LDAP_SUCCESS ) goto cleanup;
524 if ( slapi_control_present( controls,
525 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
529 be = select_backend( &ndn, manageDsaIt, 0 );
531 rc = LDAP_PARTIAL_RESULTS;
535 op->o_dn = pConn->c_dn = be->be_rootdn;
536 op->o_ndn = pConn->c_ndn = be->be_rootndn;
538 if ( be->be_delete ) {
539 int repl_user = be_isupdate( be, &op->o_ndn );
540 if ( !be->be_update_ndn.bv_len || repl_user ) {
541 rc = (*be->be_delete)( be, pConn, op, &pdn, &ndn );
544 replog( be, op, &pdn, &ndn, NULL );
554 rc = LDAP_UNWILLING_TO_PERFORM;
559 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
561 if (dn.bv_val) slapi_ch_free( (void **)&dn.bv_val );
562 if (pdn.bv_val) slapi_ch_free( (void **)&pdn.bv_val );
563 if (ndn.bv_val) slapi_ch_free( (void **)&ndn.bv_val );
565 if ( pConn != NULL ) {
566 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
567 if ( op ) slapi_ch_free( (void **)&op );
573 #endif /* LDAP_SLAPI */
578 slapi_add_entry_internal(
580 LDAPControl **controls,
583 #if defined(LDAP_SLAPI)
584 Connection *pConn = NULL;
585 Operation *op = NULL;
586 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
591 int rc = LDAP_SUCCESS;
594 rc = LDAP_PARAM_ERROR;
598 pConn = fakeConnection( NULL, LDAP_REQ_ADD );
599 if ( pConn == NULL ) {
604 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
605 NULL, &isCritical ) ) {
609 op = (Operation *)pConn->c_pending_ops.stqh_first;
610 pPB = (Slapi_PBlock *)op->o_pb;
611 op->o_ctrls = controls;
613 be = select_backend( &e->e_nname, manageDsaIt, 0 );
615 rc = LDAP_PARTIAL_RESULTS;
619 op->o_dn = pConn->c_dn = be->be_rootdn;
620 op->o_ndn = pConn->c_ndn = be->be_rootndn;
623 int repl_user = be_isupdate( be, &op->o_ndn );
624 if ( !be->be_update_ndn.bv_len || repl_user ){
625 if ( (*be->be_add)( be, pConn, op, e ) == 0 ) {
627 replog( be, op, &e->e_name,
636 rc = LDAP_UNWILLING_TO_PERFORM;
642 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
645 if ( pConn != NULL ) {
646 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
647 if ( op != NULL ) slapi_ch_free( (void **)&op );
652 #endif /* LDAP_SLAPI */
661 LDAPControl **controls,
664 #if defined(LDAP_SLAPI)
665 LDAPMod *pMod = NULL;
666 Slapi_PBlock *pb = NULL;
667 Entry *pEntry = NULL;
668 int i, rc=LDAP_SUCCESS;
670 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
671 rc = LDAP_PARAM_ERROR ;
674 if ( rc == LDAP_SUCCESS ) {
675 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
676 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
683 if ( rc == LDAP_SUCCESS ) {
684 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
689 if ( rc != LDAP_SUCCESS ) {
690 pb = slapi_pblock_new();
691 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
693 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
697 slapi_entry_free(pEntry);
701 #endif /* LDAP_SLAPI */
705 /* Function : slapi_modrdn_internal
707 * Description : Plugin functions call this routine to modify the rdn
708 * of an entry in the backend directly
709 * Return values : LDAP_SUCCESS
713 * LDAP_UNWILLING_TO_PERFORM
715 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
718 slapi_modrdn_internal(
722 LDAPControl **controls,
725 #if defined(LDAP_SLAPI)
726 int rc = LDAP_SUCCESS;
728 struct berval dn = { 0, NULL };
729 struct berval pdn = { 0, NULL };
730 struct berval ndn = { 0, NULL };
732 struct berval newrdn = { 0, NULL };
733 struct berval pnewrdn = { 0, NULL };
734 struct berval nnewrdn = { 0, NULL };
736 #if 0 /* currently unused */
737 struct berval newSuperior = { 0, NULL };
739 struct berval pnewSuperior = { 0, NULL };
740 #if 0 /* currently unused */
741 struct berval nnewSuperior = { 0, NULL };
744 struct berval *pnewS = NULL;
745 struct berval *nnewS = NULL;
747 Connection *pConn = NULL;
748 Operation *op = NULL;
749 Slapi_PBlock *pPB = NULL;
750 Slapi_PBlock *pSavePB = NULL;
753 #if 0 /* currently unused */
754 Backend *newSuperior_be = NULL;
759 #if 0 /* currently unused */
760 const char *text = NULL;
763 dn.bv_val = slapi_ch_strdup(olddn);
764 dn.bv_len = slapi_ch_stlen(olddn);
766 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
768 if ( rc != LDAP_SUCCESS ) goto cleanup;
770 if ( ndn.bv_len == 0 ) {
771 rc = LDAP_UNWILLING_TO_PERFORM;
775 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
776 newrdn.bv_len = slapi_ch_stlen( lnewrdn );
778 rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );
780 if ( rc != LDAP_SUCCESS ) goto cleanup;
782 if ( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) goto cleanup;
784 pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);
785 if ( pConn == NULL) {
790 op = (Operation *)pConn->c_pending_ops.stqh_first;
791 pPB = (Slapi_PBlock *)op->o_pb;
792 op->o_ctrls = controls;
794 if ( slapi_control_present( controls,
795 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
799 be = select_backend( &ndn, manageDsaIt, 0 );
801 rc = LDAP_PARTIAL_RESULTS;
805 op->o_dn = pConn->c_dn = be->be_rootdn;
806 op->o_ndn = pConn->c_ndn = be->be_rootndn;
808 if ( be->be_modrdn ) {
809 int repl_user = be_isupdate( be, &op->o_ndn );
810 if ( !be->be_update_ndn.bv_len || repl_user ) {
811 rc = (*be->be_modrdn)( be, pConn, op, &pdn, &ndn,
812 &pnewrdn, &nnewrdn, deloldrdn, pnewS,
815 struct slap_replog_moddn moddn;
816 moddn.newrdn = &pnewrdn;
817 moddn.deloldrdn = deloldrdn;
818 moddn.newsup = &pnewSuperior;
820 replog( be, op, &pdn, &ndn, &moddn );
833 rc = LDAP_UNWILLING_TO_PERFORM;
839 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
842 if ( dn.bv_val ) ch_free( dn.bv_val );
843 if ( pdn.bv_val ) ch_free( pdn.bv_val );
844 if ( ndn.bv_val ) ch_free( ndn.bv_val );
846 if ( newrdn.bv_val ) ch_free( newrdn.bv_val );
847 if ( pnewrdn.bv_val ) ch_free( newrdn.bv_val );
848 if ( nnewrdn.bv_val ) ch_free( newrdn.bv_val );
850 if ( pConn != NULL ) {
851 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
852 if ( op != NULL ) slapi_ch_free( (void **)&op );
858 #endif /* LDAP_SLAPI */
862 /* Function : slapi_modify_internal
864 * Description: Plugin functions call this routine to modify an entry
865 * in the backend directly
866 * Return values : LDAP_SUCCESS
870 * LDAP_UNWILLING_TO_PERFORM
873 slapi_modify_internal(
876 LDAPControl **controls,
879 #if defined(LDAP_SLAPI)
880 int i, rc = LDAP_SUCCESS;
881 Connection *pConn = NULL;
882 Operation *op = NULL;
883 Slapi_PBlock *pPB = NULL;
884 Slapi_PBlock *pSavePB = NULL;
886 struct berval dn = { 0, NULL };
887 struct berval pdn = { 0, NULL };
888 struct berval ndn = { 0, NULL };
896 Modifications *modlist = NULL;
897 Modifications **modtail = &modlist;
900 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
901 rc = LDAP_PARAM_ERROR ;
905 pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );
906 if ( pConn == NULL ) {
911 op = (Operation *)pConn->c_pending_ops.stqh_first;
912 pPB = (Slapi_PBlock *)op->o_pb;
913 op->o_ctrls = controls;
915 dn.bv_val = slapi_ch_strdup( ldn );
916 dn.bv_len = slapi_strlen( ldn );
917 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
918 if ( rc != LDAP_SUCCESS ) goto cleanup;
920 if ( slapi_control_present( controls,
921 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
925 be = select_backend( &ndn, manageDsaIt, 0 );
927 rc = LDAP_PARTIAL_RESULTS;
931 op->o_dn = pConn->c_dn = be->be_rootdn;
932 op->o_ndn = pConn->c_ndn = be->be_rootndn;
934 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL;
937 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
939 * attr values are in berval format
940 * convert an array of pointers to bervals
941 * to an array of bervals
943 rc = bvptr2obj( pMod->mod_bvalues, &bv );
944 if ( rc != LDAP_SUCCESS ) goto cleanup;
945 tmp.sml_type.bv_val = pMod->mod_type;
946 tmp.sml_type.bv_len = strlen( pMod->mod_type );
947 tmp.sml_bvalues = bv;
949 tmp.sml_nvalues = NULL;
952 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
954 mod->sml_op = pMod->mod_op;
955 mod->sml_next = NULL;
956 mod->sml_desc = NULL;
957 mod->sml_type = tmp.sml_type;
958 mod->sml_bvalues = tmp.sml_bvalues;
960 mod->sml_nvalues = tmp.sml_nvalues;
963 rc = values2obj( pMod->mod_values, &bv );
964 if ( rc != LDAP_SUCCESS ) goto cleanup;
965 tmp.sml_type.bv_val = pMod->mod_type;
966 tmp.sml_type.bv_len = strlen( pMod->mod_type );
967 tmp.sml_bvalues = bv;
969 tmp.sml_nvalues = NULL;
972 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
974 mod->sml_op = pMod->mod_op;
975 mod->sml_next = NULL;
976 mod->sml_desc = NULL;
977 mod->sml_type = tmp.sml_type;
978 mod->sml_bvalues = tmp.sml_bvalues;
980 mod->sml_nvalues = tmp.sml_nvalues;
984 modtail = &mod->sml_next;
986 switch( pMod->mod_op ) {
988 if ( mod->sml_bvalues == NULL ) {
989 rc = LDAP_PROTOCOL_ERROR;
994 case LDAP_MOD_DELETE:
995 case LDAP_MOD_REPLACE:
999 rc = LDAP_PROTOCOL_ERROR;
1005 if ( ndn.bv_len == 0 ) {
1006 rc = LDAP_UNWILLING_TO_PERFORM;
1010 if ( be->be_modify ) {
1011 int repl_user = be_isupdate( be, &op->o_ndn );
1012 if ( !be->be_update_ndn.bv_len || repl_user ) {
1013 int update = be->be_update_ndn.bv_len;
1014 const char *text = NULL;
1015 char textbuf[SLAP_TEXT_BUFLEN];
1016 size_t textlen = sizeof( textbuf );
1018 rc = slap_mods_check( modlist, update,
1019 &text, textbuf, textlen );
1020 if (rc != LDAP_SUCCESS) {
1025 rc = slap_mods_opattrs( be, op, modlist,
1026 modtail, &text, textbuf,
1028 if (rc != LDAP_SUCCESS) {
1032 rc = (*be->be_modify)( be, pConn, op,
1033 &pdn, &ndn, modlist );
1036 replog( be, op, &pdn, &ndn, modlist );
1046 rc = LDAP_UNWILLING_TO_PERFORM;
1052 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1054 if ( dn.bv_val ) ch_free( dn.bv_val );
1055 if ( pdn.bv_val ) ch_free( pdn.bv_val );
1056 if ( ndn.bv_val ) ch_free( ndn.bv_val );
1058 if ( modlist != NULL ) freeMods( modlist );
1060 if ( pConn != NULL ) {
1061 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
1062 if ( op != NULL ) slapi_ch_free( (void **)&op );
1069 #endif /* LDAP_SLAPI */
1074 slapi_search_internal_bind(
1079 LDAPControl **controls,
1083 #if defined(LDAP_SLAPI)
1086 Operation *op = NULL;
1087 Slapi_PBlock *ptr = NULL;
1088 Slapi_PBlock *pSavePB = NULL;
1089 struct berval dn = { 0, NULL };
1090 struct berval pdn = { 0, NULL };
1091 struct berval ndn = { 0, NULL };
1092 Filter *filter=NULL;
1093 struct berval fstr = { 0, NULL };
1094 AttributeName *an = NULL;
1095 const char *text = NULL;
1098 int sizelimit=-1, timelimit=-1;
1100 int manageDsaIt = 0;
1103 int i, rc = LDAP_SUCCESS;
1105 c = fakeConnection( NULL, LDAP_REQ_SEARCH );
1107 rc = LDAP_NO_MEMORY;
1111 op = (Operation *)c->c_pending_ops.stqh_first;
1112 ptr = (Slapi_PBlock *)op->o_pb;
1113 op->o_ctrls = controls;
1115 dn.bv_val = slapi_ch_strdup(ldn);
1116 dn.bv_len = slapi_strlen(ldn);
1118 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
1119 if (rc != LDAP_SUCCESS) goto cleanup;
1121 if ( scope != LDAP_SCOPE_BASE &&
1122 scope != LDAP_SCOPE_ONELEVEL &&
1123 scope != LDAP_SCOPE_SUBTREE ) {
1124 rc = LDAP_PROTOCOL_ERROR;
1128 filter = slapi_str2filter(filStr);
1129 if ( filter == NULL ) {
1130 rc = LDAP_PROTOCOL_ERROR;
1134 filter2bv( filter, &fstr );
1136 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1137 ; /* count the number of attributes */
1141 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1142 for (i = 0; attrs[i] != 0; i++) {
1143 an[i].an_desc = NULL;
1145 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1146 an[i].an_name.bv_len = slapi_strlen(attrs[i]);
1147 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1149 an[i].an_name.bv_val = NULL;
1152 if ( scope == LDAP_SCOPE_BASE ) {
1153 Entry *entry = NULL;
1155 if ( ndn.bv_len == 0 ) {
1156 rc = root_dse_info( c, &entry, &text );
1159 if( rc != LDAP_SUCCESS ) {
1160 send_ldap_result( c, op, rc, NULL, text, NULL, NULL );
1162 } else if ( entry != NULL ) {
1163 rc = test_filter( NULL, c, op, entry, filter );
1165 if( rc == LDAP_COMPARE_TRUE ) {
1166 send_search_entry( NULL, c, op, entry,
1167 an, attrsonly, NULL );
1170 entry_free( entry );
1172 send_ldap_result( c, op, LDAP_SUCCESS,
1173 NULL, NULL, NULL, NULL );
1181 if ( !ndn.bv_len && default_search_nbase.bv_len ) {
1182 ch_free( pdn.bv_val );
1183 ch_free( ndn.bv_val );
1185 ber_dupbv( &pdn, &default_search_base );
1186 ber_dupbv( &ndn, &default_search_nbase );
1189 if ( slapi_control_present( controls,
1190 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1194 be = select_backend( &ndn, manageDsaIt, 0 );
1196 if ( manageDsaIt == 1 ) {
1197 rc = LDAP_NO_SUCH_OBJECT;
1199 rc = LDAP_PARTIAL_RESULTS;
1204 op->o_dn = c->c_dn = be->be_rootdn;
1205 op->o_ndn = c->c_ndn = be->be_rootndn;
1207 if ( be->be_search ) {
1208 rc = (*be->be_search)( be, c, op, &pdn, &ndn,
1209 scope, deref, sizelimit, timelimit,
1210 filter, &fstr, an, attrsonly );
1217 rc = LDAP_UNWILLING_TO_PERFORM;
1223 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1225 if ( dn.bv_val ) free( dn.bv_val );
1226 if ( ndn.bv_val ) free( ndn.bv_val );
1227 if ( pdn.bv_val ) free( pdn.bv_val );
1229 if ( filter ) slapi_filter_free( filter, 1 );
1230 if ( fstr.bv_val ) free ( fstr.bv_val );
1232 if ( an != NULL ) free( an );
1235 if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );
1236 if ( op != NULL ) slapi_ch_free( (void **)&op );
1241 #endif /* LDAP_SLAPI */
1246 slapi_search_internal(
1250 LDAPControl **controls,
1254 #if defined(LDAP_SLAPI)
1255 return slapi_search_internal_bind( NULL, base, scope, filStr,
1256 controls, attrs, attrsonly );
1259 #endif /* LDAP_SLAPI */