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 );
548 rc = LDAP_OPERATIONS_ERROR;
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
711 * LDAP_OPERATIONS_ERROR
714 * LDAP_UNWILLING_TO_PERFORM
716 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
719 slapi_modrdn_internal(
723 LDAPControl **controls,
726 #if defined(LDAP_SLAPI)
727 int rc = LDAP_SUCCESS;
729 struct berval dn = { 0, NULL };
730 struct berval pdn = { 0, NULL };
731 struct berval ndn = { 0, NULL };
733 struct berval newrdn = { 0, NULL };
734 struct berval pnewrdn = { 0, NULL };
735 struct berval nnewrdn = { 0, NULL };
737 #if 0 /* currently unused */
738 struct berval newSuperior = { 0, NULL };
740 struct berval pnewSuperior = { 0, NULL };
741 #if 0 /* currently unused */
742 struct berval nnewSuperior = { 0, NULL };
745 struct berval *pnewS = NULL;
746 struct berval *nnewS = NULL;
748 Connection *pConn = NULL;
749 Operation *op = NULL;
750 Slapi_PBlock *pPB = NULL;
751 Slapi_PBlock *pSavePB = NULL;
754 #if 0 /* currently unused */
755 Backend *newSuperior_be = NULL;
760 #if 0 /* currently unused */
761 const char *text = NULL;
764 dn.bv_val = slapi_ch_strdup(olddn);
765 dn.bv_len = slapi_ch_stlen(olddn);
767 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
769 if ( rc != LDAP_SUCCESS ) goto cleanup;
771 if ( ndn.bv_len == 0 ) {
772 rc = LDAP_UNWILLING_TO_PERFORM;
776 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
777 newrdn.bv_len = slapi_ch_stlen( lnewrdn );
779 rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );
781 if ( rc != LDAP_SUCCESS ) goto cleanup;
783 if ( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) goto cleanup;
785 pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);
786 if ( pConn == NULL) {
791 op = (Operation *)pConn->c_pending_ops.stqh_first;
792 pPB = (Slapi_PBlock *)op->o_pb;
793 op->o_ctrls = controls;
795 if ( slapi_control_present( controls,
796 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
800 be = select_backend( &ndn, manageDsaIt, 0 );
802 rc = LDAP_PARTIAL_RESULTS;
806 op->o_dn = pConn->c_dn = be->be_rootdn;
807 op->o_ndn = pConn->c_ndn = be->be_rootndn;
809 if ( be->be_modrdn ) {
810 int repl_user = be_isupdate( be, &op->o_ndn );
811 if ( !be->be_update_ndn.bv_len || repl_user ) {
812 rc = (*be->be_modrdn)( be, pConn, op, &pdn, &ndn,
813 &pnewrdn, &nnewrdn, deloldrdn, pnewS,
816 struct slap_replog_moddn moddn;
817 moddn.newrdn = &pnewrdn;
818 moddn.deloldrdn = deloldrdn;
819 moddn.newsup = &pnewSuperior;
821 replog( be, op, &pdn, &ndn, &moddn );
826 rc = LDAP_OPERATIONS_ERROR;
834 rc = LDAP_UNWILLING_TO_PERFORM;
840 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
843 if ( dn.bv_val ) ch_free( dn.bv_val );
844 if ( pdn.bv_val ) ch_free( pdn.bv_val );
845 if ( ndn.bv_val ) ch_free( ndn.bv_val );
847 if ( newrdn.bv_val ) ch_free( newrdn.bv_val );
848 if ( pnewrdn.bv_val ) ch_free( newrdn.bv_val );
849 if ( nnewrdn.bv_val ) ch_free( newrdn.bv_val );
851 if ( pConn != NULL ) {
852 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
853 if ( op != NULL ) slapi_ch_free( (void **)&op );
859 #endif /* LDAP_SLAPI */
863 /* Function : slapi_modify_internal
865 * Description: Plugin functions call this routine to modify an entry
866 * in the backend directly
867 * Return values : LDAP_SUCCESS
870 * LDAP_OPERATIONS_ERROR
872 * LDAP_UNWILLING_TO_PERFORM
875 slapi_modify_internal(
878 LDAPControl **controls,
881 #if defined(LDAP_SLAPI)
882 int i, rc = LDAP_SUCCESS;
883 Connection *pConn = NULL;
884 Operation *op = NULL;
885 Slapi_PBlock *pPB = NULL;
886 Slapi_PBlock *pSavePB = NULL;
888 struct berval dn = { 0, NULL };
889 struct berval pdn = { 0, NULL };
890 struct berval ndn = { 0, NULL };
898 Modifications *modlist = NULL;
899 Modifications **modtail = &modlist;
902 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
903 rc = LDAP_PARAM_ERROR ;
907 pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );
908 if ( pConn == NULL ) {
913 op = (Operation *)pConn->c_pending_ops.stqh_first;
914 pPB = (Slapi_PBlock *)op->o_pb;
915 op->o_ctrls = controls;
917 dn.bv_val = slapi_ch_strdup( ldn );
918 dn.bv_len = slapi_strlen( ldn );
919 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
920 if ( rc != LDAP_SUCCESS ) goto cleanup;
922 if ( slapi_control_present( controls,
923 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
927 be = select_backend( &ndn, manageDsaIt, 0 );
929 rc = LDAP_PARTIAL_RESULTS;
933 op->o_dn = pConn->c_dn = be->be_rootdn;
934 op->o_ndn = pConn->c_ndn = be->be_rootndn;
936 for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL;
939 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
941 * attr values are in berval format
942 * convert an array of pointers to bervals
943 * to an array of bervals
945 rc = bvptr2obj( pMod->mod_bvalues, &bv );
946 if ( rc != LDAP_SUCCESS ) goto cleanup;
947 tmp.sml_type.bv_val = pMod->mod_type;
948 tmp.sml_type.bv_len = strlen( pMod->mod_type );
949 tmp.sml_bvalues = bv;
951 tmp.sml_nvalues = NULL;
954 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
956 mod->sml_op = pMod->mod_op;
957 mod->sml_next = NULL;
958 mod->sml_desc = NULL;
959 mod->sml_type = tmp.sml_type;
960 mod->sml_bvalues = tmp.sml_bvalues;
962 mod->sml_nvalues = tmp.sml_nvalues;
965 rc = values2obj( pMod->mod_values, &bv );
966 if ( rc != LDAP_SUCCESS ) goto cleanup;
967 tmp.sml_type.bv_val = pMod->mod_type;
968 tmp.sml_type.bv_len = strlen( pMod->mod_type );
969 tmp.sml_bvalues = bv;
971 tmp.sml_nvalues = NULL;
974 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
976 mod->sml_op = pMod->mod_op;
977 mod->sml_next = NULL;
978 mod->sml_desc = NULL;
979 mod->sml_type = tmp.sml_type;
980 mod->sml_bvalues = tmp.sml_bvalues;
982 mod->sml_nvalues = tmp.sml_nvalues;
986 modtail = &mod->sml_next;
988 switch( pMod->mod_op ) {
990 if ( mod->sml_bvalues == NULL ) {
991 rc = LDAP_PROTOCOL_ERROR;
996 case LDAP_MOD_DELETE:
997 case LDAP_MOD_REPLACE:
1001 rc = LDAP_PROTOCOL_ERROR;
1007 if ( ndn.bv_len == 0 ) {
1008 rc = LDAP_UNWILLING_TO_PERFORM;
1012 if ( be->be_modify ) {
1013 int repl_user = be_isupdate( be, &op->o_ndn );
1014 if ( !be->be_update_ndn.bv_len || repl_user ) {
1015 int update = be->be_update_ndn.bv_len;
1016 const char *text = NULL;
1017 char textbuf[SLAP_TEXT_BUFLEN];
1018 size_t textlen = sizeof( textbuf );
1020 rc = slap_mods_check( modlist, update,
1021 &text, textbuf, textlen );
1022 if (rc != LDAP_SUCCESS) {
1027 rc = slap_mods_opattrs( be, op, modlist,
1028 modtail, &text, textbuf,
1030 if (rc != LDAP_SUCCESS) {
1034 rc = (*be->be_modify)( be, pConn, op,
1035 &pdn, &ndn, modlist );
1038 replog( be, op, &pdn, &ndn, modlist );
1042 rc = LDAP_OPERATIONS_ERROR;
1048 rc = LDAP_UNWILLING_TO_PERFORM;
1054 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1056 if ( dn.bv_val ) ch_free( dn.bv_val );
1057 if ( pdn.bv_val ) ch_free( pdn.bv_val );
1058 if ( ndn.bv_val ) ch_free( ndn.bv_val );
1060 if ( modlist != NULL ) freeMods( modlist );
1062 if ( pConn != NULL ) {
1063 if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
1064 if ( op != NULL ) slapi_ch_free( (void **)&op );
1071 #endif /* LDAP_SLAPI */
1076 slapi_search_internal_bind(
1081 LDAPControl **controls,
1085 #if defined(LDAP_SLAPI)
1088 Operation *op = NULL;
1089 Slapi_PBlock *ptr = NULL;
1090 Slapi_PBlock *pSavePB = NULL;
1091 struct berval dn = { 0, NULL };
1092 struct berval pdn = { 0, NULL };
1093 struct berval ndn = { 0, NULL };
1094 Filter *filter=NULL;
1095 struct berval fstr = { 0, NULL };
1096 AttributeName *an = NULL;
1097 const char *text = NULL;
1100 int sizelimit=-1, timelimit=-1;
1102 int manageDsaIt = 0;
1105 int i, rc = LDAP_SUCCESS;
1107 c = fakeConnection( NULL, LDAP_REQ_SEARCH );
1109 rc = LDAP_NO_MEMORY;
1113 op = (Operation *)c->c_pending_ops.stqh_first;
1114 ptr = (Slapi_PBlock *)op->o_pb;
1115 op->o_ctrls = controls;
1117 dn.bv_val = slapi_ch_strdup(ldn);
1118 dn.bv_len = slapi_strlen(ldn);
1120 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
1121 if (rc != LDAP_SUCCESS) goto cleanup;
1123 if ( scope != LDAP_SCOPE_BASE &&
1124 scope != LDAP_SCOPE_ONELEVEL &&
1125 scope != LDAP_SCOPE_SUBTREE ) {
1126 rc = LDAP_PROTOCOL_ERROR;
1130 filter = slapi_str2filter(filStr);
1131 if ( filter == NULL ) {
1132 rc = 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_name.bv_val = slapi_ch_strdup(attrs[i]);
1148 an[i].an_name.bv_len = slapi_strlen(attrs[i]);
1149 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1151 an[i].an_name.bv_val = NULL;
1154 if ( scope == LDAP_SCOPE_BASE ) {
1155 Entry *entry = NULL;
1157 if ( ndn.bv_len == 0 ) {
1158 rc = root_dse_info( c, &entry, &text );
1161 if( rc != LDAP_SUCCESS ) {
1162 send_ldap_result( c, op, rc, NULL, text, NULL, NULL );
1164 } else if ( entry != NULL ) {
1165 rc = test_filter( NULL, c, op, entry, filter );
1167 if( rc == LDAP_COMPARE_TRUE ) {
1168 send_search_entry( NULL, c, op, entry,
1169 an, attrsonly, NULL );
1172 entry_free( entry );
1174 send_ldap_result( c, op, LDAP_SUCCESS,
1175 NULL, NULL, NULL, NULL );
1183 if ( !ndn.bv_len && default_search_nbase.bv_len ) {
1184 ch_free( pdn.bv_val );
1185 ch_free( ndn.bv_val );
1187 ber_dupbv( &pdn, &default_search_base );
1188 ber_dupbv( &ndn, &default_search_nbase );
1191 if ( slapi_control_present( controls,
1192 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1196 be = select_backend( &ndn, manageDsaIt, 0 );
1198 if ( manageDsaIt == 1 ) {
1199 rc = LDAP_NO_SUCH_OBJECT;
1201 rc = LDAP_PARTIAL_RESULTS;
1206 op->o_dn = c->c_dn = be->be_rootdn;
1207 op->o_ndn = c->c_ndn = be->be_rootndn;
1209 if ( be->be_search ) {
1210 rc = (*be->be_search)( be, c, op, &pdn, &ndn,
1211 scope, deref, sizelimit, timelimit,
1212 filter, &fstr, an, attrsonly );
1216 rc = LDAP_OPERATIONS_ERROR;
1219 rc = LDAP_UNWILLING_TO_PERFORM;
1225 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
1227 if ( dn.bv_val ) free( dn.bv_val );
1228 if ( ndn.bv_val ) free( ndn.bv_val );
1229 if ( pdn.bv_val ) free( pdn.bv_val );
1231 if ( filter ) slapi_filter_free( filter, 1 );
1232 if ( fstr.bv_val ) free ( fstr.bv_val );
1234 if ( an != NULL ) free( an );
1237 if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );
1238 if ( op != NULL ) slapi_ch_free( (void **)&op );
1243 #endif /* LDAP_SLAPI */
1248 slapi_search_internal(
1252 LDAPControl **controls,
1256 #if defined(LDAP_SLAPI)
1257 return slapi_search_internal_bind( NULL, base, scope, filStr,
1258 controls, attrs, attrsonly );
1261 #endif /* LDAP_SLAPI */