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.
13 * Portions (C) Copyright PADL Software Pty Ltd. 2003
14 * Redistribution and use in source and binary forms are permitted
15 * provided that this notice is preserved and that due credit is
16 * given to PADL Software Pty Ltd. This software is provided ``as is''
17 * without express or implied warranty.
26 * use a fake listener when faking a connection,
27 * so it can be used in ACLs
29 static struct slap_listener slap_unknown_listener = {
30 BER_BVC("unknown"), /* FIXME: use a URI form? */
34 int bvptr2obj( struct berval **bvptr, struct berval **bvobj );
42 /* XXX needs review after internal API change */
43 /* rs->sr_nentries appears to always be 0 */
44 if (op->o_tag == LDAP_REQ_SEARCH)
45 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
46 SLAPI_NENTRIES, (void *)rs->sr_nentries );
53 internal_search_entry(
58 int nentries = 0, len = 0, i = 0;
59 Slapi_Entry **head = NULL, **tp;
61 ent2str = slapi_entry2str( rs->sr_entry, &len );
62 if ( ent2str == NULL ) {
66 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
67 SLAPI_NENTRIES, &nentries );
68 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
69 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
72 if ( nentries == 0 ) {
73 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
78 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
79 if ( tp[ 0 ] == NULL ) {
84 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
85 sizeof(Slapi_Entry *) * ( i + 1 ) );
89 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
90 if ( tp[ i - 1 ] == NULL ) {
96 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
97 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
98 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
99 SLAPI_NENTRIES, (void *)i );
113 internal_search_reference(
125 Connection *pConn, *c;
126 ber_len_t max = sockbuf_max_incoming;
128 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
130 return (Connection *)NULL;
133 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
135 pConn->c_pending_ops.stqh_first =
136 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
137 if ( pConn->c_pending_ops.stqh_first == NULL ) {
138 slapi_ch_free( (void **)&pConn );
139 return (Connection *)NULL;
142 pConn->c_pending_ops.stqh_first->o_pb =
143 (Slapi_PBlock *) slapi_pblock_new();
144 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
145 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
146 slapi_ch_free( (void **)&pConn );
147 return (Connection *)NULL;
152 /* operation object */
153 c->c_pending_ops.stqh_first->o_tag = OpType;
154 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
155 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
156 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
157 c->c_pending_ops.stqh_first->o_time = slap_get_time();
158 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
159 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );
160 c->c_pending_ops.stqh_first->o_conn = c;
162 /* connection object */
163 c->c_authmech.bv_val = NULL;
164 c->c_authmech.bv_len = 0;
165 c->c_dn.bv_val = NULL;
167 c->c_ndn.bv_val = NULL;
171 c->c_listener = &slap_unknown_listener;
172 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
173 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
175 LDAP_STAILQ_INIT( &c->c_ops );
177 c->c_sasl_bind_mech.bv_val = NULL;
178 c->c_sasl_bind_mech.bv_len = 0;
179 c->c_sasl_context = NULL;
180 c->c_sasl_extra = NULL;
182 c->c_sb = ber_sockbuf_alloc( );
184 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
186 c->c_currentber = NULL;
188 /* should check status of thread calls */
189 ldap_pvt_thread_mutex_init( &c->c_mutex );
190 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
191 ldap_pvt_thread_cond_init( &c->c_write_cv );
193 c->c_n_ops_received = 0;
194 c->c_n_ops_executing = 0;
195 c->c_n_ops_pending = 0;
196 c->c_n_ops_completed = 0;
202 c->c_protocol = LDAP_VERSION3;
204 c->c_activitytime = c->c_starttime = slap_get_time();
208 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
209 c->c_struct_state = 0x02; /* SLAP_C_USED */
211 c->c_ssf = c->c_transport_ssf = 0;
214 backend_connection_init( c );
216 pConn->c_send_ldap_result = internal_result_v3;
217 pConn->c_send_search_entry = internal_search_entry;
218 pConn->c_send_ldap_extended = internal_result_ext;
219 pConn->c_send_search_reference = internal_search_reference;
224 static void slapiConnectionDestroy( Connection **pConn )
226 Connection *conn = *pConn;
229 if ( pConn == NULL ) {
233 op = (Operation *)conn->c_pending_ops.stqh_first;
235 if ( op->o_req_dn.bv_val != NULL ) {
236 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
238 if ( op->o_req_ndn.bv_val != NULL ) {
239 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
242 if ( conn->c_sb != NULL ) {
243 ber_sockbuf_free( conn->c_sb );
246 slapi_ch_free( (void **)&op );
248 slapi_ch_free( (void **)pConn );
252 * Function : values2obj
253 * Convert an array of strings into a BerVarray.
264 if ( ppValue == NULL ) {
269 for ( i = 0; ppValue[i] != NULL; i++ )
272 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
273 if ( tmpberval == NULL ) {
274 return LDAP_NO_MEMORY;
276 for ( i = 0; ppValue[i] != NULL; i++ ) {
277 tmpberval[i].bv_val = ppValue[i];
278 tmpberval[i].bv_len = strlen( ppValue[i] );
280 tmpberval[i].bv_val = NULL;
281 tmpberval[i].bv_len = 0;
289 freeMods( Modifications *ml )
292 * Free a modification list whose values have been
293 * set with bvptr2obj() or values2obj() (ie. they
294 * do not own the pointer to the underlying values)
298 for ( ; ml != NULL; ml = next ) {
301 slapi_ch_free( (void **)&ml->sml_bvalues );
303 slapi_ch_free( (void **)&ml->sml_nvalues );
305 slapi_ch_free( (void **)&ml );
310 * Function : LDAPModToEntry
311 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
312 * with a link list of the correspondent attributes.
313 * Return value : LDAP_SUCCESS
322 struct berval dn = { 0, NULL };
328 Modifications *modlist = NULL;
329 Modifications **modtail = &modlist;
332 int rc = LDAP_SUCCESS;
335 const char *text = NULL;
338 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
339 if ( pEntry == NULL) {
343 op->o_tag = LDAP_REQ_ADD;
345 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
346 if ( pEntry == NULL) {
351 dn.bv_val = slapi_ch_strdup(ldn);
352 dn.bv_len = strlen(ldn);
354 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
355 if ( rc != LDAP_SUCCESS )
358 if ( rc == LDAP_SUCCESS ) {
359 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
361 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
362 /* attr values are in berval format */
363 /* convert an array of pointers to bervals to an array of bervals */
364 rc = bvptr2obj(pMod->mod_bvalues, &bv);
365 if (rc != LDAP_SUCCESS) goto cleanup;
366 tmp.sml_type.bv_val = pMod->mod_type;
367 tmp.sml_type.bv_len = strlen( pMod->mod_type );
368 tmp.sml_bvalues = bv;
370 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;
381 mod->sml_nvalues = tmp.sml_nvalues;
385 modtail = &mod->sml_next;
388 /* attr values are in string format, need to be converted */
389 /* to an array of bervals */
390 if ( pMod->mod_values == NULL ) {
393 rc = values2obj( pMod->mod_values, &bv );
394 if (rc != LDAP_SUCCESS) goto cleanup;
395 tmp.sml_type.bv_val = pMod->mod_type;
396 tmp.sml_type.bv_len = strlen( pMod->mod_type );
397 tmp.sml_bvalues = bv;
399 tmp.sml_nvalues = NULL;
402 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
404 mod->sml_op = LDAP_MOD_ADD;
405 mod->sml_next = NULL;
406 mod->sml_desc = NULL;
407 mod->sml_type = tmp.sml_type;
408 mod->sml_bvalues = tmp.sml_bvalues;
410 mod->sml_nvalues = tmp.sml_nvalues;
414 modtail = &mod->sml_next;
417 } /* for each LDAPMod */
420 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
421 if ( op->o_bd == NULL ) {
422 rc = LDAP_PARTIAL_RESULTS;
424 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
425 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
426 int update = op->o_bd->be_update_ndn.bv_len;
427 char textbuf[SLAP_TEXT_BUFLEN];
428 size_t textlen = sizeof textbuf;
430 rc = slap_mods_check( modlist, update, &text,
432 if ( rc != LDAP_SUCCESS) {
437 rc = slap_mods_opattrs( op,
438 modlist, modtail, &text,
440 if ( rc != LDAP_SUCCESS) {
446 * FIXME: slap_mods2entry is declared static
447 * in servers/slapd/add.c
449 rc = slap_mods2entry( modlist, &pEntry, repl_user,
450 &text, textbuf, textlen );
451 if (rc != LDAP_SUCCESS) {
463 slapi_ch_free( (void **)&dn.bv_val );
465 slapi_ch_free( (void **)&op );
466 if ( modlist != NULL )
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,
495 Connection *pConn = NULL;
496 Operation *op = NULL;
497 Slapi_PBlock *pPB = NULL;
498 Slapi_PBlock *pSavePB = NULL;
499 SlapReply rs = { REP_RESULT };
500 struct berval dn = { 0, NULL };
506 rs.sr_err = LDAP_PARAM_ERROR;
510 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
512 rs.sr_err = LDAP_NO_MEMORY;
516 op = (Operation *)pConn->c_pending_ops.stqh_first;
517 pPB = (Slapi_PBlock *)op->o_pb;
518 op->o_ctrls = controls;
520 dn.bv_val = slapi_ch_strdup(ldn);
521 dn.bv_len = strlen(ldn);
522 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
523 if ( rs.sr_err != LDAP_SUCCESS )
526 if ( slapi_control_present( controls,
527 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
531 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
532 if ( op->o_bd == NULL ) {
533 rs.sr_err = LDAP_PARTIAL_RESULTS;
537 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
538 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
540 if ( op->o_bd->be_delete ) {
541 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
542 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
543 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
548 rs.sr_err = LDAP_OTHER;
551 rs.sr_err = LDAP_REFERRAL;
554 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
559 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
562 slapi_ch_free( (void **)&dn.bv_val );
564 if ( pConn != NULL ) {
568 slapiConnectionDestroy( &pConn );
573 #endif /* LDAP_SLAPI */
577 slapi_add_entry_internal(
579 LDAPControl **controls,
583 Connection *pConn = NULL;
584 Operation *op = NULL;
585 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
589 SlapReply rs = { REP_RESULT };
592 rs.sr_err = LDAP_PARAM_ERROR;
596 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
597 if ( pConn == NULL ) {
598 rs.sr_err = LDAP_NO_MEMORY;
602 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
603 NULL, &isCritical ) ) {
607 op = (Operation *)pConn->c_pending_ops.stqh_first;
608 pPB = (Slapi_PBlock *)op->o_pb;
609 op->o_ctrls = controls;
611 op->o_bd = select_backend( &e->e_nname, manageDsaIt, 0 );
612 if ( op->o_bd == NULL ) {
613 rs.sr_err = LDAP_PARTIAL_RESULTS;
617 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
618 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
621 if ( op->o_bd->be_add ) {
622 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
623 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ){
624 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
630 rs.sr_err = LDAP_REFERRAL;
633 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
639 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
642 if ( pConn != NULL ) {
646 slapiConnectionDestroy( &pConn );
651 #endif /* LDAP_SLAPI */
659 LDAPControl **controls,
663 LDAPMod *pMod = NULL;
664 Slapi_PBlock *pb = NULL;
665 Entry *pEntry = NULL;
666 int i, rc = LDAP_SUCCESS;
668 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
669 rc = LDAP_PARAM_ERROR ;
672 if ( rc == LDAP_SUCCESS ) {
673 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
674 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
681 if ( rc == LDAP_SUCCESS ) {
682 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
687 if ( rc != LDAP_SUCCESS ) {
688 pb = slapi_pblock_new();
689 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
691 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
695 slapi_entry_free(pEntry);
701 #endif /* LDAP_SLAPI */
704 /* Function : slapi_modrdn_internal
706 * Description : Plugin functions call this routine to modify the rdn
707 * of an entry in the backend directly
708 * Return values : LDAP_SUCCESS
712 * LDAP_UNWILLING_TO_PERFORM
714 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
717 slapi_modrdn_internal(
721 LDAPControl **controls,
725 struct berval dn = { 0, NULL };
726 struct berval newrdn = { 0, NULL };
727 Connection *pConn = NULL;
728 Operation *op = NULL;
729 Slapi_PBlock *pPB = NULL;
730 Slapi_PBlock *pSavePB = NULL;
733 SlapReply rs = { REP_RESULT };
735 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
736 if ( pConn == NULL) {
737 rs.sr_err = LDAP_NO_MEMORY;
741 op = (Operation *)pConn->c_pending_ops.stqh_first;
742 pPB = (Slapi_PBlock *)op->o_pb;
743 op->o_ctrls = controls;
745 if ( slapi_control_present( controls,
746 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
750 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
751 if ( op->o_bd == NULL ) {
752 rs.sr_err = LDAP_PARTIAL_RESULTS;
756 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
757 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
759 dn.bv_val = slapi_ch_strdup( olddn );
760 dn.bv_len = strlen( olddn );
762 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
763 if ( rs.sr_err != LDAP_SUCCESS ) {
767 if ( op->o_req_dn.bv_len == 0 ) {
768 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
772 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
773 newrdn.bv_len = strlen( lnewrdn );
775 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn );
776 if ( rs.sr_err != LDAP_SUCCESS ) {
780 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
784 op->oq_modrdn.rs_newSup = NULL;
785 op->oq_modrdn.rs_nnewSup = NULL;
786 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
788 if ( op->o_bd->be_modrdn ) {
789 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
790 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
791 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
796 rs.sr_err = LDAP_OTHER;
799 rs.sr_err = LDAP_REFERRAL;
802 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
808 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
812 slapi_ch_free( (void **)&dn.bv_val );
815 slapi_ch_free( (void **)&newrdn.bv_val );
816 if ( op->oq_modrdn.rs_newrdn.bv_val )
817 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
818 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
819 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
821 if ( pConn != NULL ) {
825 slapiConnectionDestroy( &pConn );
830 #endif /* LDAP_SLAPI */
833 /* Function : slapi_modify_internal
835 * Description: Plugin functions call this routine to modify an entry
836 * in the backend directly
837 * Return values : LDAP_SUCCESS
841 * LDAP_UNWILLING_TO_PERFORM
844 slapi_modify_internal(
847 LDAPControl **controls,
852 Connection *pConn = NULL;
853 Operation *op = NULL;
854 Slapi_PBlock *pPB = NULL;
855 Slapi_PBlock *pSavePB = NULL;
857 struct berval dn = { 0, NULL };
864 Modifications *modlist = NULL;
865 Modifications **modtail = &modlist;
868 SlapReply rs = { REP_RESULT };
870 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
871 rs.sr_err = LDAP_PARAM_ERROR ;
875 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
876 if ( pConn == NULL ) {
877 rs.sr_err = LDAP_NO_MEMORY;
881 op = (Operation *)pConn->c_pending_ops.stqh_first;
882 pPB = (Slapi_PBlock *)op->o_pb;
883 op->o_ctrls = controls;
885 dn.bv_val = slapi_ch_strdup( ldn );
886 dn.bv_len = strlen( ldn );
887 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
888 if ( rs.sr_err != LDAP_SUCCESS ) {
892 if ( slapi_control_present( controls,
893 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
897 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
898 if ( op->o_bd == NULL ) {
899 rs.sr_err = LDAP_PARTIAL_RESULTS;
903 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
904 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
906 for ( i = 0, pMod = mods[0];
907 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
912 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
914 * attr values are in berval format
915 * convert an array of pointers to bervals
916 * to an array of bervals
918 rs.sr_err = bvptr2obj( pMod->mod_bvalues, &bv );
919 if ( rs.sr_err != LDAP_SUCCESS )
921 tmp.sml_type.bv_val = pMod->mod_type;
922 tmp.sml_type.bv_len = strlen( pMod->mod_type );
923 tmp.sml_bvalues = bv;
925 tmp.sml_nvalues = NULL;
928 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
930 mod->sml_op = pMod->mod_op;
931 mod->sml_next = NULL;
932 mod->sml_desc = NULL;
933 mod->sml_type = tmp.sml_type;
934 mod->sml_bvalues = tmp.sml_bvalues;
936 mod->sml_nvalues = tmp.sml_nvalues;
939 rs.sr_err = values2obj( pMod->mod_values, &bv );
940 if ( rs.sr_err != LDAP_SUCCESS )
942 tmp.sml_type.bv_val = pMod->mod_type;
943 tmp.sml_type.bv_len = strlen( pMod->mod_type );
944 tmp.sml_bvalues = bv;
946 tmp.sml_nvalues = NULL;
949 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
951 mod->sml_op = pMod->mod_op;
952 mod->sml_next = NULL;
953 mod->sml_desc = NULL;
954 mod->sml_type = tmp.sml_type;
955 mod->sml_bvalues = tmp.sml_bvalues;
957 mod->sml_nvalues = tmp.sml_nvalues;
961 modtail = &mod->sml_next;
963 switch( pMod->mod_op ) {
965 if ( mod->sml_bvalues == NULL ) {
966 rs.sr_err = LDAP_PROTOCOL_ERROR;
971 case LDAP_MOD_DELETE:
972 case LDAP_MOD_REPLACE:
976 rs.sr_err = LDAP_PROTOCOL_ERROR;
982 if ( op->o_req_ndn.bv_len == 0 ) {
983 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
987 op->oq_modify.rs_modlist = modlist;
989 if ( op->o_bd->be_modify ) {
990 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
991 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
992 int update = op->o_bd->be_update_ndn.bv_len;
993 const char *text = NULL;
994 char textbuf[SLAP_TEXT_BUFLEN];
995 size_t textlen = sizeof( textbuf );
997 rs.sr_err = slap_mods_check( modlist, update,
998 &text, textbuf, textlen );
999 if ( rs.sr_err != LDAP_SUCCESS ) {
1004 rs.sr_err = slap_mods_opattrs( op, modlist,
1005 modtail, &text, textbuf,
1007 if ( rs.sr_err != LDAP_SUCCESS ) {
1011 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1016 rs.sr_err = LDAP_OTHER;
1019 rs.sr_err = LDAP_REFERRAL;
1022 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1028 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1031 slapi_ch_free( (void **)&dn.bv_val );
1033 if ( modlist != NULL )
1034 freeMods( modlist );
1036 if ( pConn != NULL ) {
1040 slapiConnectionDestroy( &pConn );
1045 #endif /* LDAP_SLAPI */
1049 slapi_search_internal_bind(
1054 LDAPControl **controls,
1060 Operation *op = NULL;
1061 Slapi_PBlock *ptr = NULL;
1062 Slapi_PBlock *pSavePB = NULL;
1063 struct berval dn = { 0, NULL };
1064 Filter *filter=NULL;
1065 struct berval fstr = { 0, NULL };
1066 AttributeName *an = NULL;
1067 const char *text = NULL;
1069 int manageDsaIt = 0;
1073 SlapReply rs = { REP_RESULT };
1075 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1077 rs.sr_err = LDAP_NO_MEMORY;
1081 op = (Operation *)c->c_pending_ops.stqh_first;
1082 ptr = (Slapi_PBlock *)op->o_pb;
1083 op->o_ctrls = controls;
1085 dn.bv_val = slapi_ch_strdup(ldn);
1086 dn.bv_len = strlen(ldn);
1088 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
1089 if ( rs.sr_err != LDAP_SUCCESS ) {
1093 if ( scope != LDAP_SCOPE_BASE &&
1094 scope != LDAP_SCOPE_ONELEVEL &&
1095 scope != LDAP_SCOPE_SUBTREE ) {
1096 rs.sr_err = LDAP_PROTOCOL_ERROR;
1100 filter = slapi_str2filter(filStr);
1101 if ( filter == NULL ) {
1102 rs.sr_err = LDAP_PROTOCOL_ERROR;
1106 filter2bv( filter, &fstr );
1108 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1109 ; /* count the number of attributes */
1113 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1114 for (i = 0; attrs[i] != 0; i++) {
1115 an[i].an_desc = NULL;
1117 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1118 an[i].an_name.bv_len = strlen(attrs[i]);
1119 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1121 an[i].an_name.bv_val = NULL;
1124 memset( &rs, 0, sizeof(rs) );
1125 rs.sr_type = REP_RESULT;
1126 rs.sr_err = LDAP_SUCCESS;
1127 rs.sr_entry = NULL; /* paranoia */
1129 if ( scope == LDAP_SCOPE_BASE ) {
1132 if ( op->o_req_ndn.bv_len == 0 ) {
1133 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1136 if( rs.sr_err != LDAP_SUCCESS ) {
1137 send_ldap_result( op, &rs );
1139 } else if ( rs.sr_entry != NULL ) {
1140 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1142 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1143 rs.sr_type = REP_SEARCH;
1144 rs.sr_err = LDAP_SUCCESS;
1147 send_search_entry( op, &rs );
1150 entry_free( rs.sr_entry );
1152 rs.sr_type = REP_RESULT;
1153 rs.sr_err = LDAP_SUCCESS;
1155 send_ldap_result( op, &rs );
1161 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1162 slapi_ch_free( (void **)op->o_req_dn.bv_val );
1163 slapi_ch_free( (void **)op->o_req_ndn.bv_val );
1165 ber_dupbv( &op->o_req_dn, &default_search_base );
1166 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1169 if ( slapi_control_present( controls,
1170 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1174 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1175 if ( op->o_bd == NULL ) {
1176 if ( manageDsaIt == 1 ) {
1177 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1179 rs.sr_err = LDAP_PARTIAL_RESULTS;
1184 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1185 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1187 op->oq_search.rs_scope = scope;
1188 op->oq_search.rs_deref = 0;
1189 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1190 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1191 op->oq_search.rs_attrsonly = attrsonly;
1192 op->oq_search.rs_attrs = an;
1193 op->oq_search.rs_filter = filter;
1194 op->oq_search.rs_filterstr = fstr;
1196 if ( op->o_bd->be_search ) {
1197 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1198 rs.sr_err = LDAP_OTHER;
1201 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1207 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1210 slapi_ch_free( (void **)&dn.bv_val );
1212 slapi_filter_free( filter, 1 );
1214 slapi_ch_free( (void **)&fstr.bv_val );
1216 slapi_ch_free( (void **)&an );
1222 slapiConnectionDestroy( &c );
1227 #endif /* LDAP_SLAPI */
1231 slapi_search_internal(
1235 LDAPControl **controls,
1240 return slapi_search_internal_bind( NULL, base, scope, filStr,
1241 controls, attrs, attrsonly );
1244 #endif /* LDAP_SLAPI */