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 );
44 internal_search_entry(
54 int nentries = 0, len = 0, i = 0;
55 Slapi_Entry **head = NULL, **tp;
57 ent2str = slapi_entry2str( e, &len );
58 if ( ent2str == NULL ) {
62 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
63 SLAPI_NENTRIES, &nentries );
64 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
65 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
68 if ( nentries == 0 ) {
69 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
74 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
75 if ( tp[ 0 ] == NULL ) {
80 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
81 sizeof(Slapi_Entry *) * ( i + 1 ) );
85 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
86 if ( tp[ i - 1 ] == NULL ) {
92 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
93 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
94 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
95 SLAPI_NENTRIES, (void *)i );
101 internal_search_result(
111 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
112 SLAPI_NENTRIES, (void *)nentries );
126 struct berval *rspdata,
127 LDAPControl **ctrls )
133 internal_search_reference(
150 Connection *pConn, *c;
151 ber_len_t max = sockbuf_max_incoming;
153 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
155 return (Connection *)NULL;
158 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
160 pConn->c_pending_ops.stqh_first =
161 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
162 if ( pConn->c_pending_ops.stqh_first == NULL ) {
163 slapi_ch_free( (void **)&pConn );
164 return (Connection *)NULL;
167 pConn->c_pending_ops.stqh_first->o_pb =
168 (Slapi_PBlock *) slapi_pblock_new();
169 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
170 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
171 slapi_ch_free( (void **)&pConn );
172 return (Connection *)NULL;
177 /* operation object */
178 c->c_pending_ops.stqh_first->o_tag = OpType;
179 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
180 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
181 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
182 c->c_pending_ops.stqh_first->o_time = slap_get_time();
183 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
184 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );
186 /* connection object */
187 c->c_authmech.bv_val = NULL;
188 c->c_authmech.bv_len = 0;
189 c->c_dn.bv_val = NULL;
191 c->c_ndn.bv_val = NULL;
195 c->c_listener = &slap_unknown_listener;
196 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
197 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
199 LDAP_STAILQ_INIT( &c->c_ops );
201 c->c_sasl_bind_mech.bv_val = NULL;
202 c->c_sasl_bind_mech.bv_len = 0;
203 c->c_sasl_context = NULL;
204 c->c_sasl_extra = NULL;
206 c->c_sb = ber_sockbuf_alloc( );
208 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
210 c->c_currentber = NULL;
212 /* should check status of thread calls */
213 ldap_pvt_thread_mutex_init( &c->c_mutex );
214 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
215 ldap_pvt_thread_cond_init( &c->c_write_cv );
217 c->c_n_ops_received = 0;
218 c->c_n_ops_executing = 0;
219 c->c_n_ops_pending = 0;
220 c->c_n_ops_completed = 0;
226 c->c_protocol = LDAP_VERSION3;
228 c->c_activitytime = c->c_starttime = slap_get_time();
232 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
233 c->c_struct_state = 0x02; /* SLAP_C_USED */
235 c->c_ssf = c->c_transport_ssf = 0;
238 backend_connection_init( c );
240 pConn->c_send_ldap_result = internal_result_v3;
241 pConn->c_send_search_entry = internal_search_entry;
242 pConn->c_send_search_result = internal_search_result;
243 pConn->c_send_ldap_extended = internal_result_ext;
244 pConn->c_send_search_reference = internal_search_reference;
250 * Function : values2obj
251 * Convert an array of strings into a BerVarray.
262 if ( ppValue == NULL ) {
267 for ( i = 0; ppValue[i] != NULL; i++ )
270 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
271 if ( tmpberval == NULL ) {
272 return LDAP_NO_MEMORY;
274 for ( i = 0; ppValue[i] != NULL; i++ ) {
275 tmpberval[i].bv_val = ppValue[i];
276 tmpberval[i].bv_len = strlen( ppValue[i] );
278 tmpberval[i].bv_val = NULL;
279 tmpberval[i].bv_len = 0;
287 freeMods( Modifications *ml )
290 * Free a modification list whose values have been
291 * set with bvptr2obj() or values2obj() (ie. they
292 * do not own the pointer to the underlying values)
296 for ( ; ml != NULL; ml = next ) {
299 slapi_ch_free( (void **)&ml->sml_bvalues );
301 slapi_ch_free( (void **)&ml->sml_nvalues );
303 slapi_ch_free( (void **)&ml );
308 * Function : LDAPModToEntry
309 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
310 * with a link list of the correspondent attributes.
311 * Return value : LDAP_SUCCESS
320 struct berval dn = { 0, NULL };
327 Modifications *modlist = NULL;
328 Modifications **modtail = &modlist;
331 int rc = LDAP_SUCCESS;
334 const char *text = NULL;
337 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
338 if ( pEntry == NULL) {
342 op->o_tag = LDAP_REQ_ADD;
344 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
345 if ( pEntry == NULL) {
350 dn.bv_val = slapi_ch_strdup(ldn);
351 dn.bv_len = strlen(ldn);
353 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
354 if (rc != LDAP_SUCCESS) goto cleanup;
356 if ( rc == LDAP_SUCCESS ) {
357 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
359 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
360 /* attr values are in berval format */
361 /* convert an array of pointers to bervals to an array of bervals */
362 rc = bvptr2obj(pMod->mod_bvalues, &bv);
363 if (rc != LDAP_SUCCESS) goto cleanup;
364 tmp.sml_type.bv_val = pMod->mod_type;
365 tmp.sml_type.bv_len = strlen( pMod->mod_type );
366 tmp.sml_bvalues = bv;
368 tmp.sml_nvalues = NULL;
371 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
373 mod->sml_op = LDAP_MOD_ADD;
374 mod->sml_next = NULL;
375 mod->sml_desc = NULL;
376 mod->sml_type = tmp.sml_type;
377 mod->sml_bvalues = tmp.sml_bvalues;
379 mod->sml_nvalues = tmp.sml_nvalues;
383 modtail = &mod->sml_next;
386 /* attr values are in string format, need to be converted */
387 /* to an array of bervals */
388 if ( pMod->mod_values == NULL ) {
391 rc = values2obj( pMod->mod_values, &bv );
392 if (rc != LDAP_SUCCESS) goto cleanup;
393 tmp.sml_type.bv_val = pMod->mod_type;
394 tmp.sml_type.bv_len = strlen( pMod->mod_type );
395 tmp.sml_bvalues = bv;
397 tmp.sml_nvalues = NULL;
400 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
402 mod->sml_op = LDAP_MOD_ADD;
403 mod->sml_next = NULL;
404 mod->sml_desc = NULL;
405 mod->sml_type = tmp.sml_type;
406 mod->sml_bvalues = tmp.sml_bvalues;
408 mod->sml_nvalues = tmp.sml_nvalues;
412 modtail = &mod->sml_next;
415 } /* for each LDAPMod */
418 be = select_backend(&pEntry->e_nname, 0, 0);
420 rc = LDAP_PARTIAL_RESULTS;
425 int repl_user = be_isupdate(be, &be->be_rootdn );
426 if ( !be->be_update_ndn.bv_len || repl_user ) {
427 int update = be->be_update_ndn.bv_len;
428 char textbuf[SLAP_TEXT_BUFLEN];
429 size_t textlen = sizeof textbuf;
431 rc = slap_mods_check( modlist, update, &text,
433 if ( rc != LDAP_SUCCESS) {
438 rc = slap_mods_opattrs( be, op,
439 modlist, modtail, &text,
441 if ( rc != LDAP_SUCCESS) {
447 * FIXME: slap_mods2entry is declared static
448 * in servers/slapd/add.c
450 rc = slap_mods2entry( modlist, &pEntry, repl_user,
451 &text, textbuf, textlen );
452 if (rc != LDAP_SUCCESS) {
460 rc = LDAP_UNWILLING_TO_PERFORM;
465 if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );
466 if ( op ) slapi_ch_free( (void **)&op );
467 if ( modlist != NULL ) freeMods( modlist );
468 if ( rc != LDAP_SUCCESS ) {
469 if ( pEntry != NULL ) {
470 slapi_entry_free( pEntry );
478 /* Function : slapi_delete_internal
480 * Description : Plugin functions call this routine to delete an entry
481 * in the backend directly
482 * Return values : LDAP_SUCCESS
486 * LDAP_UNWILLING_TO_PERFORM
489 slapi_delete_internal(
491 LDAPControl **controls,
494 #if defined(LDAP_SLAPI)
496 Connection *pConn = NULL;
497 Operation *op = NULL;
498 Slapi_PBlock *pPB = NULL;
499 Slapi_PBlock *pSavePB = NULL;
501 struct berval dn = { 0, NULL };
502 struct berval pdn = { 0, NULL };
503 struct berval ndn = { 0, NULL };
510 rc = LDAP_PARAM_ERROR;
514 pConn = fakeConnection( NULL, LDAP_REQ_DELETE );
520 op = (Operation *)pConn->c_pending_ops.stqh_first;
521 pPB = (Slapi_PBlock *)op->o_pb;
522 op->o_ctrls = controls;
524 dn.bv_val = slapi_ch_strdup(ldn);
525 dn.bv_len = slapi_strlen(ldn);
526 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
527 if ( rc != LDAP_SUCCESS ) goto cleanup;
529 if ( slapi_control_present( controls,
530 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
534 be = select_backend( &ndn, manageDsaIt, 0 );
536 rc = LDAP_PARTIAL_RESULTS;
540 op->o_dn = pConn->c_dn = be->be_rootdn;
541 op->o_ndn = pConn->c_ndn = be->be_rootndn;
543 if ( be->be_delete ) {
544 int repl_user = be_isupdate( be, &op->o_ndn );
545 if ( !be->be_update_ndn.bv_len || repl_user ) {
546 rc = (*be->be_delete)( be, pConn, op, &pdn, &ndn );
549 replog( be, op, &pdn, &ndn, NULL );
559 rc = LDAP_UNWILLING_TO_PERFORM;
564 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
566 if (dn.bv_val) slapi_ch_free( (void **)&dn.bv_val );
567 if (pdn.bv_val) slapi_ch_free( (void **)&pdn.bv_val );
568 if (ndn.bv_val) slapi_ch_free( (void **)&ndn.bv_val );
570 if ( pConn != NULL ) {
571 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
572 if ( op ) slapi_ch_free( (void **)&op );
578 #endif /* LDAP_SLAPI */
583 slapi_add_entry_internal(
585 LDAPControl **controls,
588 #if defined(LDAP_SLAPI)
589 Connection *pConn = NULL;
590 Operation *op = NULL;
591 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
596 int rc = LDAP_SUCCESS;
599 rc = LDAP_PARAM_ERROR;
603 pConn = fakeConnection( NULL, LDAP_REQ_ADD );
604 if ( pConn == NULL ) {
609 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
610 NULL, &isCritical ) ) {
614 op = (Operation *)pConn->c_pending_ops.stqh_first;
615 pPB = (Slapi_PBlock *)op->o_pb;
616 op->o_ctrls = controls;
618 be = select_backend( &e->e_nname, manageDsaIt, 0 );
620 rc = LDAP_PARTIAL_RESULTS;
624 op->o_dn = pConn->c_dn = be->be_rootdn;
625 op->o_ndn = pConn->c_ndn = be->be_rootndn;
628 int repl_user = be_isupdate( be, &op->o_ndn );
629 if ( !be->be_update_ndn.bv_len || repl_user ){
630 if ( (*be->be_add)( be, pConn, op, e ) == 0 ) {
632 replog( be, op, &e->e_name,
641 rc = LDAP_UNWILLING_TO_PERFORM;
647 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
650 if ( pConn != NULL ) {
651 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
652 if ( op != NULL ) slapi_ch_free( (void **)&op );
657 #endif /* LDAP_SLAPI */
666 LDAPControl **controls,
669 #if defined(LDAP_SLAPI)
670 LDAPMod *pMod = NULL;
671 Slapi_PBlock *pb = NULL;
672 Entry *pEntry = NULL;
673 int i, rc=LDAP_SUCCESS;
675 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
676 rc = LDAP_PARAM_ERROR ;
679 if ( rc == LDAP_SUCCESS ) {
680 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
681 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
688 if ( rc == LDAP_SUCCESS ) {
689 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
694 if ( rc != LDAP_SUCCESS ) {
695 pb = slapi_pblock_new();
696 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
698 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
702 slapi_entry_free(pEntry);
706 #endif /* LDAP_SLAPI */
710 /* Function : slapi_modrdn_internal
712 * Description : Plugin functions call this routine to modify the rdn
713 * of an entry in the backend directly
714 * Return values : LDAP_SUCCESS
718 * LDAP_UNWILLING_TO_PERFORM
720 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
723 slapi_modrdn_internal(
727 LDAPControl **controls,
730 #if defined(LDAP_SLAPI)
731 int rc = LDAP_SUCCESS;
733 struct berval dn = { 0, NULL };
734 struct berval pdn = { 0, NULL };
735 struct berval ndn = { 0, NULL };
737 struct berval newrdn = { 0, NULL };
738 struct berval pnewrdn = { 0, NULL };
739 struct berval nnewrdn = { 0, NULL };
741 #if 0 /* currently unused */
742 struct berval newSuperior = { 0, NULL };
744 struct berval pnewSuperior = { 0, NULL };
745 #if 0 /* currently unused */
746 struct berval nnewSuperior = { 0, NULL };
749 struct berval *pnewS = NULL;
750 struct berval *nnewS = NULL;
752 Connection *pConn = NULL;
753 Operation *op = NULL;
754 Slapi_PBlock *pPB = NULL;
755 Slapi_PBlock *pSavePB = NULL;
758 #if 0 /* currently unused */
759 Backend *newSuperior_be = NULL;
764 #if 0 /* currently unused */
765 const char *text = NULL;
768 dn.bv_val = slapi_ch_strdup(olddn);
769 dn.bv_len = slapi_ch_stlen(olddn);
771 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
773 if ( rc != LDAP_SUCCESS ) goto cleanup;
775 if ( ndn.bv_len == 0 ) {
776 rc = LDAP_UNWILLING_TO_PERFORM;
780 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
781 newrdn.bv_len = slapi_ch_stlen( lnewrdn );
783 rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );
785 if ( rc != LDAP_SUCCESS ) goto cleanup;
787 if ( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) goto cleanup;
789 pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);
790 if ( pConn == NULL) {
795 op = (Operation *)pConn->c_pending_ops.stqh_first;
796 pPB = (Slapi_PBlock *)op->o_pb;
797 op->o_ctrls = controls;
799 if ( slapi_control_present( controls,
800 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
804 be = select_backend( &ndn, manageDsaIt, 0 );
806 rc = LDAP_PARTIAL_RESULTS;
810 op->o_dn = pConn->c_dn = be->be_rootdn;
811 op->o_ndn = pConn->c_ndn = be->be_rootndn;
813 if ( be->be_modrdn ) {
814 int repl_user = be_isupdate( be, &op->o_ndn );
815 if ( !be->be_update_ndn.bv_len || repl_user ) {
816 rc = (*be->be_modrdn)( be, pConn, op, &pdn, &ndn,
817 &pnewrdn, &nnewrdn, deloldrdn, pnewS,
820 struct slap_replog_moddn moddn;
821 moddn.newrdn = &pnewrdn;
822 moddn.deloldrdn = deloldrdn;
823 moddn.newsup = &pnewSuperior;
825 replog( be, op, &pdn, &ndn, &moddn );
838 rc = LDAP_UNWILLING_TO_PERFORM;
844 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
847 if ( dn.bv_val ) ch_free( dn.bv_val );
848 if ( pdn.bv_val ) ch_free( pdn.bv_val );
849 if ( ndn.bv_val ) ch_free( ndn.bv_val );
851 if ( newrdn.bv_val ) ch_free( newrdn.bv_val );
852 if ( pnewrdn.bv_val ) ch_free( newrdn.bv_val );
853 if ( nnewrdn.bv_val ) ch_free( newrdn.bv_val );
855 if ( pConn != NULL ) {
856 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
857 if ( op != NULL ) slapi_ch_free( (void **)&op );
863 #endif /* LDAP_SLAPI */
867 /* Function : slapi_modify_internal
869 * Description: Plugin functions call this routine to modify an entry
870 * in the backend directly
871 * Return values : LDAP_SUCCESS
875 * LDAP_UNWILLING_TO_PERFORM
878 slapi_modify_internal(
881 LDAPControl **controls,
884 #if defined(LDAP_SLAPI)
885 int i, rc = LDAP_SUCCESS;
886 Connection *pConn = NULL;
887 Operation *op = NULL;
888 Slapi_PBlock *pPB = NULL;
889 Slapi_PBlock *pSavePB = NULL;
891 struct berval dn = { 0, NULL };
892 struct berval pdn = { 0, NULL };
893 struct berval ndn = { 0, NULL };
901 Modifications *modlist = NULL;
902 Modifications **modtail = &modlist;
905 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
906 rc = LDAP_PARAM_ERROR ;
910 pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );
911 if ( pConn == NULL ) {
916 op = (Operation *)pConn->c_pending_ops.stqh_first;
917 pPB = (Slapi_PBlock *)op->o_pb;
918 op->o_ctrls = controls;
920 dn.bv_val = slapi_ch_strdup( ldn );
921 dn.bv_len = slapi_strlen( ldn );
922 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
923 if ( rc != LDAP_SUCCESS ) goto cleanup;
925 if ( slapi_control_present( controls,
926 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
930 be = select_backend( &ndn, manageDsaIt, 0 );
932 rc = LDAP_PARTIAL_RESULTS;
936 op->o_dn = pConn->c_dn = be->be_rootdn;
937 op->o_ndn = pConn->c_ndn = be->be_rootndn;
939 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL;
942 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
944 * attr values are in berval format
945 * convert an array of pointers to bervals
946 * to an array of bervals
948 rc = bvptr2obj( pMod->mod_bvalues, &bv );
949 if ( rc != LDAP_SUCCESS ) goto cleanup;
950 tmp.sml_type.bv_val = pMod->mod_type;
951 tmp.sml_type.bv_len = strlen( pMod->mod_type );
952 tmp.sml_bvalues = bv;
954 tmp.sml_nvalues = NULL;
957 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
959 mod->sml_op = pMod->mod_op;
960 mod->sml_next = NULL;
961 mod->sml_desc = NULL;
962 mod->sml_type = tmp.sml_type;
963 mod->sml_bvalues = tmp.sml_bvalues;
965 mod->sml_nvalues = tmp.sml_nvalues;
968 rc = values2obj( pMod->mod_values, &bv );
969 if ( rc != LDAP_SUCCESS ) goto cleanup;
970 tmp.sml_type.bv_val = pMod->mod_type;
971 tmp.sml_type.bv_len = strlen( pMod->mod_type );
972 tmp.sml_bvalues = bv;
974 tmp.sml_nvalues = NULL;
977 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
979 mod->sml_op = pMod->mod_op;
980 mod->sml_next = NULL;
981 mod->sml_desc = NULL;
982 mod->sml_type = tmp.sml_type;
983 mod->sml_bvalues = tmp.sml_bvalues;
985 mod->sml_nvalues = tmp.sml_nvalues;
989 modtail = &mod->sml_next;
991 switch( pMod->mod_op ) {
993 if ( mod->sml_bvalues == NULL ) {
994 rc = LDAP_PROTOCOL_ERROR;
999 case LDAP_MOD_DELETE:
1000 case LDAP_MOD_REPLACE:
1004 rc = LDAP_PROTOCOL_ERROR;
1010 if ( ndn.bv_len == 0 ) {
1011 rc = LDAP_UNWILLING_TO_PERFORM;
1015 if ( be->be_modify ) {
1016 int repl_user = be_isupdate( be, &op->o_ndn );
1017 if ( !be->be_update_ndn.bv_len || repl_user ) {
1018 int update = be->be_update_ndn.bv_len;
1019 const char *text = NULL;
1020 char textbuf[SLAP_TEXT_BUFLEN];
1021 size_t textlen = sizeof( textbuf );
1023 rc = slap_mods_check( modlist, update,
1024 &text, textbuf, textlen );
1025 if (rc != LDAP_SUCCESS) {
1030 rc = slap_mods_opattrs( be, op, modlist,
1031 modtail, &text, textbuf,
1033 if (rc != LDAP_SUCCESS) {
1037 rc = (*be->be_modify)( be, pConn, op,
1038 &pdn, &ndn, modlist );
1041 replog( be, op, &pdn, &ndn, modlist );
1051 rc = LDAP_UNWILLING_TO_PERFORM;
1057 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1059 if ( dn.bv_val ) ch_free( dn.bv_val );
1060 if ( pdn.bv_val ) ch_free( pdn.bv_val );
1061 if ( ndn.bv_val ) ch_free( ndn.bv_val );
1063 if ( modlist != NULL ) freeMods( modlist );
1065 if ( pConn != NULL ) {
1066 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
1067 if ( op != NULL ) slapi_ch_free( (void **)&op );
1074 #endif /* LDAP_SLAPI */
1079 slapi_search_internal_bind(
1084 LDAPControl **controls,
1088 #if defined(LDAP_SLAPI)
1091 Operation *op = NULL;
1092 Slapi_PBlock *ptr = NULL;
1093 Slapi_PBlock *pSavePB = NULL;
1094 struct berval dn = { 0, NULL };
1095 struct berval pdn = { 0, NULL };
1096 struct berval ndn = { 0, NULL };
1097 Filter *filter=NULL;
1098 struct berval fstr = { 0, NULL };
1099 AttributeName *an = NULL;
1100 const char *text = NULL;
1103 int sizelimit=-1, timelimit=-1;
1105 int manageDsaIt = 0;
1108 int i, rc = LDAP_SUCCESS;
1110 c = fakeConnection( NULL, LDAP_REQ_SEARCH );
1112 rc = LDAP_NO_MEMORY;
1116 op = (Operation *)c->c_pending_ops.stqh_first;
1117 ptr = (Slapi_PBlock *)op->o_pb;
1118 op->o_ctrls = controls;
1120 dn.bv_val = slapi_ch_strdup(ldn);
1121 dn.bv_len = slapi_strlen(ldn);
1123 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
1124 if (rc != LDAP_SUCCESS) goto cleanup;
1126 if ( scope != LDAP_SCOPE_BASE &&
1127 scope != LDAP_SCOPE_ONELEVEL &&
1128 scope != LDAP_SCOPE_SUBTREE ) {
1129 rc = LDAP_PROTOCOL_ERROR;
1133 filter = slapi_str2filter(filStr);
1134 if ( filter == NULL ) {
1135 rc = LDAP_PROTOCOL_ERROR;
1139 filter2bv( filter, &fstr );
1141 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1142 ; /* count the number of attributes */
1146 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1147 for (i = 0; attrs[i] != 0; i++) {
1148 an[i].an_desc = NULL;
1150 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1151 an[i].an_name.bv_len = slapi_strlen(attrs[i]);
1152 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1154 an[i].an_name.bv_val = NULL;
1157 if ( scope == LDAP_SCOPE_BASE ) {
1158 Entry *entry = NULL;
1160 if ( ndn.bv_len == 0 ) {
1161 rc = root_dse_info( c, &entry, &text );
1164 if( rc != LDAP_SUCCESS ) {
1165 send_ldap_result( c, op, rc, NULL, text, NULL, NULL );
1167 } else if ( entry != NULL ) {
1168 rc = test_filter( NULL, c, op, entry, filter );
1170 if( rc == LDAP_COMPARE_TRUE ) {
1171 send_search_entry( NULL, c, op, entry,
1172 an, attrsonly, NULL );
1175 entry_free( entry );
1177 send_ldap_result( c, op, LDAP_SUCCESS,
1178 NULL, NULL, NULL, NULL );
1186 if ( !ndn.bv_len && default_search_nbase.bv_len ) {
1187 ch_free( pdn.bv_val );
1188 ch_free( ndn.bv_val );
1190 ber_dupbv( &pdn, &default_search_base );
1191 ber_dupbv( &ndn, &default_search_nbase );
1194 if ( slapi_control_present( controls,
1195 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1199 be = select_backend( &ndn, manageDsaIt, 0 );
1201 if ( manageDsaIt == 1 ) {
1202 rc = LDAP_NO_SUCH_OBJECT;
1204 rc = LDAP_PARTIAL_RESULTS;
1209 op->o_dn = c->c_dn = be->be_rootdn;
1210 op->o_ndn = c->c_ndn = be->be_rootndn;
1212 if ( be->be_search ) {
1213 rc = (*be->be_search)( be, c, op, &pdn, &ndn,
1214 scope, deref, sizelimit, timelimit,
1215 filter, &fstr, an, attrsonly );
1222 rc = LDAP_UNWILLING_TO_PERFORM;
1228 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1230 if ( dn.bv_val ) free( dn.bv_val );
1231 if ( ndn.bv_val ) free( ndn.bv_val );
1232 if ( pdn.bv_val ) free( pdn.bv_val );
1234 if ( filter ) slapi_filter_free( filter, 1 );
1235 if ( fstr.bv_val ) free ( fstr.bv_val );
1237 if ( an != NULL ) free( an );
1240 if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );
1241 if ( op != NULL ) slapi_ch_free( (void **)&op );
1246 #endif /* LDAP_SLAPI */
1251 slapi_search_internal(
1255 LDAPControl **controls,
1259 #if defined(LDAP_SLAPI)
1260 return slapi_search_internal_bind( NULL, base, scope, filStr,
1261 controls, attrs, attrsonly );
1264 #endif /* LDAP_SLAPI */