2 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright IBM Corp. 1997,2002
7 * Use of this source code is subject to the terms of The OpenLDAP Public
8 * License (version 2.7 or later).
9 * No trademarks of the IBM Corporation are to be used to identify, endorse
10 * or promote any products derived from this code without the prior
11 * written consent of IBM
14 * Portions (C) Copyright PADL Software Pty Ltd. 2003
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that this notice is preserved
17 * and that due credit is given to PADL Software Pty Ltd. This software
18 * is provided ``as is'' without express or implied warranty.
27 * use a fake listener when faking a connection,
28 * so it can be used in ACLs
30 static struct slap_listener slap_unknown_listener = {
31 BER_BVC("unknown"), /* FIXME: use a URI form? (e.g. slapi://) */
35 int bvptr2obj( struct berval **bvptr, struct berval **bvobj );
43 /* XXX needs review after internal API change */
44 /* rs->sr_nentries appears to always be 0 */
45 if (op->o_tag == LDAP_REQ_SEARCH)
46 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
47 SLAPI_NENTRIES, (void *)rs->sr_nentries );
54 internal_search_entry(
59 int nentries = 0, len = 0, i = 0;
60 Slapi_Entry **head = NULL, **tp;
62 ent2str = slapi_entry2str( rs->sr_entry, &len );
63 if ( ent2str == NULL ) {
67 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
68 SLAPI_NENTRIES, &nentries );
69 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
70 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
73 if ( nentries == 0 ) {
74 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
79 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
80 if ( tp[ 0 ] == NULL ) {
85 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
86 sizeof(Slapi_Entry *) * ( i + 1 ) );
90 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
91 if ( tp[ i - 1 ] == NULL ) {
97 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
98 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
99 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
100 SLAPI_NENTRIES, (void *)i );
114 internal_search_reference(
126 Connection *pConn, *c;
127 ber_len_t max = sockbuf_max_incoming;
129 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
131 return (Connection *)NULL;
134 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
136 pConn->c_pending_ops.stqh_first =
137 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
138 if ( pConn->c_pending_ops.stqh_first == NULL ) {
139 slapi_ch_free( (void **)&pConn );
140 return (Connection *)NULL;
143 pConn->c_pending_ops.stqh_first->o_pb =
144 (Slapi_PBlock *) slapi_pblock_new();
145 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
146 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
147 slapi_ch_free( (void **)&pConn );
148 return (Connection *)NULL;
153 /* operation object */
154 c->c_pending_ops.stqh_first->o_tag = OpType;
155 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
156 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
157 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
158 c->c_pending_ops.stqh_first->o_time = slap_get_time();
159 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
160 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context();
161 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
162 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
163 c->c_pending_ops.stqh_first->o_conn = c;
165 /* connection object */
166 c->c_authmech.bv_val = NULL;
167 c->c_authmech.bv_len = 0;
168 c->c_dn.bv_val = NULL;
170 c->c_ndn.bv_val = NULL;
174 c->c_listener = &slap_unknown_listener;
175 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
176 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
178 LDAP_STAILQ_INIT( &c->c_ops );
180 c->c_sasl_bind_mech.bv_val = NULL;
181 c->c_sasl_bind_mech.bv_len = 0;
182 c->c_sasl_authctx = NULL;
183 c->c_sasl_sockctx = NULL;
184 c->c_sasl_extra = NULL;
186 c->c_sb = ber_sockbuf_alloc( );
188 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
190 c->c_currentber = NULL;
192 /* should check status of thread calls */
193 ldap_pvt_thread_mutex_init( &c->c_mutex );
194 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
195 ldap_pvt_thread_cond_init( &c->c_write_cv );
197 c->c_n_ops_received = 0;
198 c->c_n_ops_executing = 0;
199 c->c_n_ops_pending = 0;
200 c->c_n_ops_completed = 0;
206 c->c_protocol = LDAP_VERSION3;
208 c->c_activitytime = c->c_starttime = slap_get_time();
212 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
213 c->c_struct_state = 0x02; /* SLAP_C_USED */
215 c->c_ssf = c->c_transport_ssf = 0;
218 backend_connection_init( c );
220 pConn->c_send_ldap_result = internal_result_v3;
221 pConn->c_send_search_entry = internal_search_entry;
222 pConn->c_send_ldap_extended = internal_result_ext;
223 pConn->c_send_search_reference = internal_search_reference;
228 static void slapiConnectionDestroy( Connection **pConn )
230 Connection *conn = *pConn;
233 if ( pConn == NULL ) {
237 op = (Operation *)conn->c_pending_ops.stqh_first;
239 if ( op->o_req_dn.bv_val != NULL ) {
240 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
242 if ( op->o_req_ndn.bv_val != NULL ) {
243 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
246 if ( conn->c_sb != NULL ) {
247 ber_sockbuf_free( conn->c_sb );
250 slapi_ch_free( (void **)&op );
252 slapi_ch_free( (void **)pConn );
256 * Function : values2obj
257 * Convert an array of strings into a BerVarray.
268 if ( ppValue == NULL ) {
273 for ( i = 0; ppValue[i] != NULL; i++ )
276 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
277 if ( tmpberval == NULL ) {
278 return LDAP_NO_MEMORY;
280 for ( i = 0; ppValue[i] != NULL; i++ ) {
281 tmpberval[i].bv_val = ppValue[i];
282 tmpberval[i].bv_len = strlen( ppValue[i] );
284 tmpberval[i].bv_val = NULL;
285 tmpberval[i].bv_len = 0;
293 freeMods( Modifications *ml )
296 * Free a modification list whose values have been
297 * set with bvptr2obj() or values2obj() (ie. they
298 * do not own the pointer to the underlying values)
302 for ( ; ml != NULL; ml = next ) {
305 if ( ml->sml_bvalues ) slapi_ch_free( (void **)&ml->sml_bvalues );
306 if ( ml->sml_nvalues ) slapi_ch_free( (void **)&ml->sml_nvalues );
307 slapi_ch_free( (void **)&ml );
312 * Function : LDAPModToEntry
313 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
314 * with a link list of the correspondent attributes.
315 * Return value : LDAP_SUCCESS
324 struct berval dn = { 0, NULL };
330 Modifications *modlist = NULL;
331 Modifications **modtail = &modlist;
334 int rc = LDAP_SUCCESS;
337 const char *text = NULL;
340 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
341 if ( pEntry == NULL) {
345 op->o_tag = LDAP_REQ_ADD;
347 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
348 if ( pEntry == NULL) {
353 dn.bv_val = slapi_ch_strdup(ldn);
354 dn.bv_len = strlen(ldn);
356 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
357 if ( rc != LDAP_SUCCESS )
360 if ( rc == LDAP_SUCCESS ) {
361 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
363 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
364 /* attr values are in berval format */
365 /* convert an array of pointers to bervals to an array of bervals */
366 rc = bvptr2obj(pMod->mod_bvalues, &bv);
367 if (rc != LDAP_SUCCESS) goto cleanup;
368 tmp.sml_type.bv_val = pMod->mod_type;
369 tmp.sml_type.bv_len = strlen( pMod->mod_type );
370 tmp.sml_bvalues = bv;
371 tmp.sml_nvalues = NULL;
373 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
375 mod->sml_op = LDAP_MOD_ADD;
376 mod->sml_next = NULL;
377 mod->sml_desc = NULL;
378 mod->sml_type = tmp.sml_type;
379 mod->sml_bvalues = tmp.sml_bvalues;
380 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;
396 tmp.sml_nvalues = NULL;
398 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
400 mod->sml_op = LDAP_MOD_ADD;
401 mod->sml_next = NULL;
402 mod->sml_desc = NULL;
403 mod->sml_type = tmp.sml_type;
404 mod->sml_bvalues = tmp.sml_bvalues;
405 mod->sml_nvalues = tmp.sml_nvalues;
408 modtail = &mod->sml_next;
411 } /* for each LDAPMod */
414 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
415 if ( op->o_bd == NULL ) {
416 rc = LDAP_PARTIAL_RESULTS;
418 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
419 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
420 int update = op->o_bd->be_update_ndn.bv_len;
421 char textbuf[SLAP_TEXT_BUFLEN];
422 size_t textlen = sizeof textbuf;
424 rc = slap_mods_check( modlist, update, &text,
425 textbuf, textlen, NULL );
426 if ( rc != LDAP_SUCCESS) {
431 rc = slap_mods_opattrs( op,
432 modlist, modtail, &text,
434 if ( rc != LDAP_SUCCESS) {
440 * FIXME: slap_mods2entry is declared static
441 * in servers/slapd/add.c
443 rc = slap_mods2entry( modlist, &pEntry, repl_user,
444 0, &text, textbuf, textlen );
445 if (rc != LDAP_SUCCESS) {
457 slapi_ch_free( (void **)&dn.bv_val );
459 slapi_ch_free( (void **)&op );
460 if ( modlist != NULL )
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,
489 Connection *pConn = NULL;
490 Operation *op = NULL;
491 Slapi_PBlock *pPB = NULL;
492 Slapi_PBlock *pSavePB = NULL;
493 SlapReply rs = { REP_RESULT };
494 struct berval dn = { 0, NULL };
500 rs.sr_err = LDAP_PARAM_ERROR;
504 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
506 rs.sr_err = LDAP_NO_MEMORY;
510 op = (Operation *)pConn->c_pending_ops.stqh_first;
511 pPB = (Slapi_PBlock *)op->o_pb;
512 op->o_ctrls = controls;
514 dn.bv_val = slapi_ch_strdup(ldn);
515 dn.bv_len = strlen(ldn);
516 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
517 if ( rs.sr_err != LDAP_SUCCESS )
520 if ( slapi_control_present( controls,
521 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
525 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
526 if ( op->o_bd == NULL ) {
527 rs.sr_err = LDAP_PARTIAL_RESULTS;
531 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
532 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
534 if ( op->o_bd->be_delete ) {
535 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
536 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
537 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
542 rs.sr_err = LDAP_OTHER;
545 rs.sr_err = LDAP_REFERRAL;
548 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
553 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
556 slapi_ch_free( (void **)&dn.bv_val );
558 if ( pConn != NULL ) {
562 slapiConnectionDestroy( &pConn );
567 #endif /* LDAP_SLAPI */
571 slapi_add_entry_internal(
573 LDAPControl **controls,
577 Connection *pConn = NULL;
578 Operation *op = NULL;
579 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
583 SlapReply rs = { REP_RESULT };
586 rs.sr_err = LDAP_PARAM_ERROR;
590 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
591 if ( pConn == NULL ) {
592 rs.sr_err = LDAP_NO_MEMORY;
596 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
597 NULL, &isCritical ) ) {
601 op = (Operation *)pConn->c_pending_ops.stqh_first;
602 pPB = (Slapi_PBlock *)op->o_pb;
603 op->o_ctrls = controls;
605 op->o_bd = select_backend( &e->e_nname, manageDsaIt, 0 );
606 if ( op->o_bd == NULL ) {
607 rs.sr_err = LDAP_PARTIAL_RESULTS;
611 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
612 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
615 if ( op->o_bd->be_add ) {
616 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
617 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ){
618 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
624 rs.sr_err = LDAP_REFERRAL;
627 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
633 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
636 if ( pConn != NULL ) {
640 slapiConnectionDestroy( &pConn );
645 #endif /* LDAP_SLAPI */
653 LDAPControl **controls,
657 LDAPMod *pMod = NULL;
658 Slapi_PBlock *pb = NULL;
659 Entry *pEntry = NULL;
660 int i, rc = LDAP_SUCCESS;
662 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
663 rc = LDAP_PARAM_ERROR ;
666 if ( rc == LDAP_SUCCESS ) {
667 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
668 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
675 if ( rc == LDAP_SUCCESS ) {
676 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
681 if ( rc != LDAP_SUCCESS ) {
682 pb = slapi_pblock_new();
683 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
685 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
689 slapi_entry_free(pEntry);
695 #endif /* LDAP_SLAPI */
698 /* Function : slapi_modrdn_internal
700 * Description : Plugin functions call this routine to modify the rdn
701 * of an entry in the backend directly
702 * Return values : LDAP_SUCCESS
706 * LDAP_UNWILLING_TO_PERFORM
708 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
711 slapi_modrdn_internal(
715 LDAPControl **controls,
719 struct berval dn = { 0, NULL };
720 struct berval newrdn = { 0, NULL };
721 Connection *pConn = NULL;
722 Operation *op = NULL;
723 Slapi_PBlock *pPB = NULL;
724 Slapi_PBlock *pSavePB = NULL;
727 SlapReply rs = { REP_RESULT };
729 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
730 if ( pConn == NULL) {
731 rs.sr_err = LDAP_NO_MEMORY;
735 op = (Operation *)pConn->c_pending_ops.stqh_first;
736 pPB = (Slapi_PBlock *)op->o_pb;
737 op->o_ctrls = controls;
739 if ( slapi_control_present( controls,
740 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
744 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
745 if ( op->o_bd == NULL ) {
746 rs.sr_err = LDAP_PARTIAL_RESULTS;
750 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
751 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
753 dn.bv_val = slapi_ch_strdup( olddn );
754 dn.bv_len = strlen( olddn );
756 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
757 if ( rs.sr_err != LDAP_SUCCESS ) {
761 if ( op->o_req_dn.bv_len == 0 ) {
762 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
766 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
767 newrdn.bv_len = strlen( lnewrdn );
769 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
770 if ( rs.sr_err != LDAP_SUCCESS ) {
774 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
778 op->oq_modrdn.rs_newSup = NULL;
779 op->oq_modrdn.rs_nnewSup = NULL;
780 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
782 if ( op->o_bd->be_modrdn ) {
783 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
784 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
785 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
790 rs.sr_err = LDAP_OTHER;
793 rs.sr_err = LDAP_REFERRAL;
796 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
802 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
806 slapi_ch_free( (void **)&dn.bv_val );
809 slapi_ch_free( (void **)&newrdn.bv_val );
810 if ( op->oq_modrdn.rs_newrdn.bv_val )
811 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
812 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
813 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
815 if ( pConn != NULL ) {
819 slapiConnectionDestroy( &pConn );
824 #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,
846 Connection *pConn = NULL;
847 Operation *op = NULL;
848 Slapi_PBlock *pPB = NULL;
849 Slapi_PBlock *pSavePB = NULL;
851 struct berval dn = { 0, NULL };
858 Modifications *modlist = NULL;
859 Modifications **modtail = &modlist;
862 SlapReply rs = { REP_RESULT };
864 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
865 rs.sr_err = LDAP_PARAM_ERROR ;
869 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
870 if ( pConn == NULL ) {
871 rs.sr_err = LDAP_NO_MEMORY;
875 op = (Operation *)pConn->c_pending_ops.stqh_first;
876 pPB = (Slapi_PBlock *)op->o_pb;
877 op->o_ctrls = controls;
879 dn.bv_val = slapi_ch_strdup( ldn );
880 dn.bv_len = strlen( ldn );
881 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
882 if ( rs.sr_err != LDAP_SUCCESS ) {
886 if ( slapi_control_present( controls,
887 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
891 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
892 if ( op->o_bd == NULL ) {
893 rs.sr_err = LDAP_PARTIAL_RESULTS;
897 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
898 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
900 for ( i = 0, pMod = mods[0];
901 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
906 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
908 * attr values are in berval format
909 * convert an array of pointers to bervals
910 * to an array of bervals
912 rs.sr_err = bvptr2obj( pMod->mod_bvalues, &bv );
913 if ( rs.sr_err != LDAP_SUCCESS )
915 tmp.sml_type.bv_val = pMod->mod_type;
916 tmp.sml_type.bv_len = strlen( pMod->mod_type );
917 tmp.sml_bvalues = bv;
918 tmp.sml_nvalues = NULL;
920 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
922 mod->sml_op = pMod->mod_op;
923 mod->sml_next = NULL;
924 mod->sml_desc = NULL;
925 mod->sml_type = tmp.sml_type;
926 mod->sml_bvalues = tmp.sml_bvalues;
927 mod->sml_nvalues = tmp.sml_nvalues;
929 rs.sr_err = values2obj( pMod->mod_values, &bv );
930 if ( rs.sr_err != LDAP_SUCCESS )
932 tmp.sml_type.bv_val = pMod->mod_type;
933 tmp.sml_type.bv_len = strlen( pMod->mod_type );
934 tmp.sml_bvalues = bv;
935 tmp.sml_nvalues = NULL;
937 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
939 mod->sml_op = pMod->mod_op;
940 mod->sml_next = NULL;
941 mod->sml_desc = NULL;
942 mod->sml_type = tmp.sml_type;
943 mod->sml_bvalues = tmp.sml_bvalues;
944 mod->sml_nvalues = tmp.sml_nvalues;
947 modtail = &mod->sml_next;
949 switch( pMod->mod_op ) {
951 if ( mod->sml_bvalues == NULL ) {
952 rs.sr_err = LDAP_PROTOCOL_ERROR;
957 case LDAP_MOD_DELETE:
958 case LDAP_MOD_REPLACE:
962 rs.sr_err = LDAP_PROTOCOL_ERROR;
968 if ( op->o_req_ndn.bv_len == 0 ) {
969 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
973 op->oq_modify.rs_modlist = modlist;
975 if ( op->o_bd->be_modify ) {
976 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
977 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
978 int update = op->o_bd->be_update_ndn.bv_len;
979 const char *text = NULL;
980 char textbuf[SLAP_TEXT_BUFLEN];
981 size_t textlen = sizeof( textbuf );
983 rs.sr_err = slap_mods_check( modlist, update,
984 &text, textbuf, textlen, NULL );
985 if ( rs.sr_err != LDAP_SUCCESS ) {
990 rs.sr_err = slap_mods_opattrs( op, modlist,
991 modtail, &text, textbuf,
993 if ( rs.sr_err != LDAP_SUCCESS ) {
997 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1002 rs.sr_err = LDAP_OTHER;
1005 rs.sr_err = LDAP_REFERRAL;
1008 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1014 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1017 slapi_ch_free( (void **)&dn.bv_val );
1019 if ( modlist != NULL )
1020 freeMods( modlist );
1022 if ( pConn != NULL ) {
1026 slapiConnectionDestroy( &pConn );
1031 #endif /* LDAP_SLAPI */
1035 slapi_search_internal_bind(
1040 LDAPControl **controls,
1046 Operation *op = NULL;
1047 Slapi_PBlock *ptr = NULL;
1048 Slapi_PBlock *pSavePB = NULL;
1049 struct berval dn = { 0, NULL };
1050 Filter *filter=NULL;
1051 struct berval fstr = { 0, NULL };
1052 AttributeName *an = NULL;
1053 const char *text = NULL;
1055 int manageDsaIt = 0;
1059 SlapReply rs = { REP_RESULT };
1061 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1063 rs.sr_err = LDAP_NO_MEMORY;
1067 op = (Operation *)c->c_pending_ops.stqh_first;
1068 ptr = (Slapi_PBlock *)op->o_pb;
1069 op->o_ctrls = controls;
1071 if ( ldn != NULL ) {
1072 dn.bv_val = slapi_ch_strdup(ldn);
1073 dn.bv_len = strlen(ldn);
1076 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1077 if ( rs.sr_err != LDAP_SUCCESS ) {
1081 if ( scope != LDAP_SCOPE_BASE &&
1082 scope != LDAP_SCOPE_ONELEVEL &&
1083 scope != LDAP_SCOPE_SUBTREE ) {
1084 rs.sr_err = LDAP_PROTOCOL_ERROR;
1088 filter = slapi_str2filter(filStr);
1089 if ( filter == NULL ) {
1090 rs.sr_err = LDAP_PROTOCOL_ERROR;
1094 filter2bv( filter, &fstr );
1096 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1097 ; /* count the number of attributes */
1101 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1102 for (i = 0; attrs[i] != 0; i++) {
1103 an[i].an_desc = NULL;
1105 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1106 an[i].an_name.bv_len = strlen(attrs[i]);
1107 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1109 an[i].an_name.bv_val = NULL;
1112 memset( &rs, 0, sizeof(rs) );
1113 rs.sr_type = REP_RESULT;
1114 rs.sr_err = LDAP_SUCCESS;
1115 rs.sr_entry = NULL; /* paranoia */
1117 if ( scope == LDAP_SCOPE_BASE ) {
1120 if ( op->o_req_ndn.bv_len == 0 ) {
1121 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1124 if( rs.sr_err != LDAP_SUCCESS ) {
1125 send_ldap_result( op, &rs );
1127 } else if ( rs.sr_entry != NULL ) {
1128 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1130 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1131 rs.sr_type = REP_SEARCH;
1132 rs.sr_err = LDAP_SUCCESS;
1135 send_search_entry( op, &rs );
1138 entry_free( rs.sr_entry );
1140 rs.sr_type = REP_RESULT;
1141 rs.sr_err = LDAP_SUCCESS;
1143 send_ldap_result( op, &rs );
1149 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1150 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1151 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1153 ber_dupbv( &op->o_req_dn, &default_search_base );
1154 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1157 if ( slapi_control_present( controls,
1158 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1162 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1163 if ( op->o_bd == NULL ) {
1164 if ( manageDsaIt == 1 ) {
1165 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1167 rs.sr_err = LDAP_PARTIAL_RESULTS;
1172 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1173 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1175 op->oq_search.rs_scope = scope;
1176 op->oq_search.rs_deref = 0;
1177 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1178 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1179 op->oq_search.rs_attrsonly = attrsonly;
1180 op->oq_search.rs_attrs = an;
1181 op->oq_search.rs_filter = filter;
1182 op->oq_search.rs_filterstr = fstr;
1184 if ( op->o_bd->be_search ) {
1185 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1186 rs.sr_err = LDAP_OTHER;
1189 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1195 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1198 slapi_ch_free( (void **)&dn.bv_val );
1200 slapi_filter_free( filter, 1 );
1202 slapi_ch_free( (void **)&fstr.bv_val );
1204 slapi_ch_free( (void **)&an );
1210 slapiConnectionDestroy( &c );
1215 #endif /* LDAP_SLAPI */
1219 slapi_search_internal(
1223 LDAPControl **controls,
1228 return slapi_search_internal_bind( NULL, base, scope, filStr,
1229 controls, attrs, attrsonly );
1232 #endif /* LDAP_SLAPI */