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 );
302 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 };
326 Modifications *modlist = NULL;
327 Modifications **modtail = &modlist;
330 int rc = LDAP_SUCCESS;
333 const char *text = NULL;
336 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
337 if ( pEntry == NULL) {
341 op->o_tag = LDAP_REQ_ADD;
343 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
344 if ( pEntry == NULL) {
349 dn.bv_val = slapi_ch_strdup(ldn);
350 dn.bv_len = strlen(ldn);
352 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
353 if ( rc != LDAP_SUCCESS )
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;
367 tmp.sml_nvalues = NULL;
369 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
371 mod->sml_op = LDAP_MOD_ADD;
372 mod->sml_next = NULL;
373 mod->sml_desc = NULL;
374 mod->sml_type = tmp.sml_type;
375 mod->sml_bvalues = tmp.sml_bvalues;
376 mod->sml_nvalues = tmp.sml_nvalues;
379 modtail = &mod->sml_next;
382 /* attr values are in string format, need to be converted */
383 /* to an array of bervals */
384 if ( pMod->mod_values == NULL ) {
387 rc = values2obj( pMod->mod_values, &bv );
388 if (rc != LDAP_SUCCESS) goto cleanup;
389 tmp.sml_type.bv_val = pMod->mod_type;
390 tmp.sml_type.bv_len = strlen( pMod->mod_type );
391 tmp.sml_bvalues = bv;
392 tmp.sml_nvalues = NULL;
394 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
396 mod->sml_op = LDAP_MOD_ADD;
397 mod->sml_next = NULL;
398 mod->sml_desc = NULL;
399 mod->sml_type = tmp.sml_type;
400 mod->sml_bvalues = tmp.sml_bvalues;
401 mod->sml_nvalues = tmp.sml_nvalues;
404 modtail = &mod->sml_next;
407 } /* for each LDAPMod */
410 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
411 if ( op->o_bd == NULL ) {
412 rc = LDAP_PARTIAL_RESULTS;
414 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
415 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
416 int update = op->o_bd->be_update_ndn.bv_len;
417 char textbuf[SLAP_TEXT_BUFLEN];
418 size_t textlen = sizeof textbuf;
420 rc = slap_mods_check( modlist, update, &text,
422 if ( rc != LDAP_SUCCESS) {
427 rc = slap_mods_opattrs( op,
428 modlist, modtail, &text,
430 if ( rc != LDAP_SUCCESS) {
436 * FIXME: slap_mods2entry is declared static
437 * in servers/slapd/add.c
439 rc = slap_mods2entry( modlist, &pEntry, repl_user,
440 &text, textbuf, textlen );
441 if (rc != LDAP_SUCCESS) {
453 slapi_ch_free( (void **)&dn.bv_val );
455 slapi_ch_free( (void **)&op );
456 if ( modlist != NULL )
458 if ( rc != LDAP_SUCCESS ) {
459 if ( pEntry != NULL ) {
460 slapi_entry_free( pEntry );
468 /* Function : slapi_delete_internal
470 * Description : Plugin functions call this routine to delete an entry
471 * in the backend directly
472 * Return values : LDAP_SUCCESS
476 * LDAP_UNWILLING_TO_PERFORM
479 slapi_delete_internal(
481 LDAPControl **controls,
485 Connection *pConn = NULL;
486 Operation *op = NULL;
487 Slapi_PBlock *pPB = NULL;
488 Slapi_PBlock *pSavePB = NULL;
489 SlapReply rs = { REP_RESULT };
490 struct berval dn = { 0, NULL };
496 rs.sr_err = LDAP_PARAM_ERROR;
500 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
502 rs.sr_err = LDAP_NO_MEMORY;
506 op = (Operation *)pConn->c_pending_ops.stqh_first;
507 pPB = (Slapi_PBlock *)op->o_pb;
508 op->o_ctrls = controls;
510 dn.bv_val = slapi_ch_strdup(ldn);
511 dn.bv_len = strlen(ldn);
512 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
513 if ( rs.sr_err != LDAP_SUCCESS )
516 if ( slapi_control_present( controls,
517 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
521 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
522 if ( op->o_bd == NULL ) {
523 rs.sr_err = LDAP_PARTIAL_RESULTS;
527 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
528 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
530 if ( op->o_bd->be_delete ) {
531 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
532 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
533 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
538 rs.sr_err = LDAP_OTHER;
541 rs.sr_err = LDAP_REFERRAL;
544 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
549 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
552 slapi_ch_free( (void **)&dn.bv_val );
554 if ( pConn != NULL ) {
558 slapiConnectionDestroy( &pConn );
563 #endif /* LDAP_SLAPI */
567 slapi_add_entry_internal(
569 LDAPControl **controls,
573 Connection *pConn = NULL;
574 Operation *op = NULL;
575 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
579 SlapReply rs = { REP_RESULT };
582 rs.sr_err = LDAP_PARAM_ERROR;
586 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
587 if ( pConn == NULL ) {
588 rs.sr_err = LDAP_NO_MEMORY;
592 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
593 NULL, &isCritical ) ) {
597 op = (Operation *)pConn->c_pending_ops.stqh_first;
598 pPB = (Slapi_PBlock *)op->o_pb;
599 op->o_ctrls = controls;
601 op->o_bd = select_backend( &e->e_nname, manageDsaIt, 0 );
602 if ( op->o_bd == NULL ) {
603 rs.sr_err = LDAP_PARTIAL_RESULTS;
607 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
608 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
611 if ( op->o_bd->be_add ) {
612 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
613 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ){
614 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
620 rs.sr_err = LDAP_REFERRAL;
623 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
629 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
632 if ( pConn != NULL ) {
636 slapiConnectionDestroy( &pConn );
641 #endif /* LDAP_SLAPI */
649 LDAPControl **controls,
653 LDAPMod *pMod = NULL;
654 Slapi_PBlock *pb = NULL;
655 Entry *pEntry = NULL;
656 int i, rc = LDAP_SUCCESS;
658 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
659 rc = LDAP_PARAM_ERROR ;
662 if ( rc == LDAP_SUCCESS ) {
663 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
664 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
671 if ( rc == LDAP_SUCCESS ) {
672 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
677 if ( rc != LDAP_SUCCESS ) {
678 pb = slapi_pblock_new();
679 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
681 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
685 slapi_entry_free(pEntry);
691 #endif /* LDAP_SLAPI */
694 /* Function : slapi_modrdn_internal
696 * Description : Plugin functions call this routine to modify the rdn
697 * of an entry in the backend directly
698 * Return values : LDAP_SUCCESS
702 * LDAP_UNWILLING_TO_PERFORM
704 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
707 slapi_modrdn_internal(
711 LDAPControl **controls,
715 struct berval dn = { 0, NULL };
716 struct berval newrdn = { 0, NULL };
717 Connection *pConn = NULL;
718 Operation *op = NULL;
719 Slapi_PBlock *pPB = NULL;
720 Slapi_PBlock *pSavePB = NULL;
723 SlapReply rs = { REP_RESULT };
725 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
726 if ( pConn == NULL) {
727 rs.sr_err = LDAP_NO_MEMORY;
731 op = (Operation *)pConn->c_pending_ops.stqh_first;
732 pPB = (Slapi_PBlock *)op->o_pb;
733 op->o_ctrls = controls;
735 if ( slapi_control_present( controls,
736 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
740 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
741 if ( op->o_bd == NULL ) {
742 rs.sr_err = LDAP_PARTIAL_RESULTS;
746 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
747 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
749 dn.bv_val = slapi_ch_strdup( olddn );
750 dn.bv_len = strlen( olddn );
752 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
753 if ( rs.sr_err != LDAP_SUCCESS ) {
757 if ( op->o_req_dn.bv_len == 0 ) {
758 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
762 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
763 newrdn.bv_len = strlen( lnewrdn );
765 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn );
766 if ( rs.sr_err != LDAP_SUCCESS ) {
770 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
774 op->oq_modrdn.rs_newSup = NULL;
775 op->oq_modrdn.rs_nnewSup = NULL;
776 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
778 if ( op->o_bd->be_modrdn ) {
779 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
780 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
781 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
786 rs.sr_err = LDAP_OTHER;
789 rs.sr_err = LDAP_REFERRAL;
792 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
798 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
802 slapi_ch_free( (void **)&dn.bv_val );
805 slapi_ch_free( (void **)&newrdn.bv_val );
806 if ( op->oq_modrdn.rs_newrdn.bv_val )
807 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
808 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
809 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
811 if ( pConn != NULL ) {
815 slapiConnectionDestroy( &pConn );
820 #endif /* LDAP_SLAPI */
823 /* Function : slapi_modify_internal
825 * Description: Plugin functions call this routine to modify an entry
826 * in the backend directly
827 * Return values : LDAP_SUCCESS
831 * LDAP_UNWILLING_TO_PERFORM
834 slapi_modify_internal(
837 LDAPControl **controls,
842 Connection *pConn = NULL;
843 Operation *op = NULL;
844 Slapi_PBlock *pPB = NULL;
845 Slapi_PBlock *pSavePB = NULL;
847 struct berval dn = { 0, NULL };
854 Modifications *modlist = NULL;
855 Modifications **modtail = &modlist;
858 SlapReply rs = { REP_RESULT };
860 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
861 rs.sr_err = LDAP_PARAM_ERROR ;
865 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
866 if ( pConn == NULL ) {
867 rs.sr_err = LDAP_NO_MEMORY;
871 op = (Operation *)pConn->c_pending_ops.stqh_first;
872 pPB = (Slapi_PBlock *)op->o_pb;
873 op->o_ctrls = controls;
875 dn.bv_val = slapi_ch_strdup( ldn );
876 dn.bv_len = strlen( ldn );
877 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
878 if ( rs.sr_err != LDAP_SUCCESS ) {
882 if ( slapi_control_present( controls,
883 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
887 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
888 if ( op->o_bd == NULL ) {
889 rs.sr_err = LDAP_PARTIAL_RESULTS;
893 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
894 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
896 for ( i = 0, pMod = mods[0];
897 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
902 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
904 * attr values are in berval format
905 * convert an array of pointers to bervals
906 * to an array of bervals
908 rs.sr_err = bvptr2obj( pMod->mod_bvalues, &bv );
909 if ( rs.sr_err != LDAP_SUCCESS )
911 tmp.sml_type.bv_val = pMod->mod_type;
912 tmp.sml_type.bv_len = strlen( pMod->mod_type );
913 tmp.sml_bvalues = bv;
914 tmp.sml_nvalues = NULL;
916 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
918 mod->sml_op = pMod->mod_op;
919 mod->sml_next = NULL;
920 mod->sml_desc = NULL;
921 mod->sml_type = tmp.sml_type;
922 mod->sml_bvalues = tmp.sml_bvalues;
923 mod->sml_nvalues = tmp.sml_nvalues;
925 rs.sr_err = values2obj( pMod->mod_values, &bv );
926 if ( rs.sr_err != LDAP_SUCCESS )
928 tmp.sml_type.bv_val = pMod->mod_type;
929 tmp.sml_type.bv_len = strlen( pMod->mod_type );
930 tmp.sml_bvalues = bv;
931 tmp.sml_nvalues = NULL;
933 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
935 mod->sml_op = pMod->mod_op;
936 mod->sml_next = NULL;
937 mod->sml_desc = NULL;
938 mod->sml_type = tmp.sml_type;
939 mod->sml_bvalues = tmp.sml_bvalues;
940 mod->sml_nvalues = tmp.sml_nvalues;
943 modtail = &mod->sml_next;
945 switch( pMod->mod_op ) {
947 if ( mod->sml_bvalues == NULL ) {
948 rs.sr_err = LDAP_PROTOCOL_ERROR;
953 case LDAP_MOD_DELETE:
954 case LDAP_MOD_REPLACE:
958 rs.sr_err = LDAP_PROTOCOL_ERROR;
964 if ( op->o_req_ndn.bv_len == 0 ) {
965 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
969 op->oq_modify.rs_modlist = modlist;
971 if ( op->o_bd->be_modify ) {
972 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
973 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
974 int update = op->o_bd->be_update_ndn.bv_len;
975 const char *text = NULL;
976 char textbuf[SLAP_TEXT_BUFLEN];
977 size_t textlen = sizeof( textbuf );
979 rs.sr_err = slap_mods_check( modlist, update,
980 &text, textbuf, textlen );
981 if ( rs.sr_err != LDAP_SUCCESS ) {
986 rs.sr_err = slap_mods_opattrs( op, modlist,
987 modtail, &text, textbuf,
989 if ( rs.sr_err != LDAP_SUCCESS ) {
993 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
998 rs.sr_err = LDAP_OTHER;
1001 rs.sr_err = LDAP_REFERRAL;
1004 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1010 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1013 slapi_ch_free( (void **)&dn.bv_val );
1015 if ( modlist != NULL )
1016 freeMods( modlist );
1018 if ( pConn != NULL ) {
1022 slapiConnectionDestroy( &pConn );
1027 #endif /* LDAP_SLAPI */
1031 slapi_search_internal_bind(
1036 LDAPControl **controls,
1042 Operation *op = NULL;
1043 Slapi_PBlock *ptr = NULL;
1044 Slapi_PBlock *pSavePB = NULL;
1045 struct berval dn = { 0, NULL };
1046 Filter *filter=NULL;
1047 struct berval fstr = { 0, NULL };
1048 AttributeName *an = NULL;
1049 const char *text = NULL;
1051 int manageDsaIt = 0;
1055 SlapReply rs = { REP_RESULT };
1057 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1059 rs.sr_err = LDAP_NO_MEMORY;
1063 op = (Operation *)c->c_pending_ops.stqh_first;
1064 ptr = (Slapi_PBlock *)op->o_pb;
1065 op->o_ctrls = controls;
1067 dn.bv_val = slapi_ch_strdup(ldn);
1068 dn.bv_len = strlen(ldn);
1070 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
1071 if ( rs.sr_err != LDAP_SUCCESS ) {
1075 if ( scope != LDAP_SCOPE_BASE &&
1076 scope != LDAP_SCOPE_ONELEVEL &&
1077 scope != LDAP_SCOPE_SUBTREE ) {
1078 rs.sr_err = LDAP_PROTOCOL_ERROR;
1082 filter = slapi_str2filter(filStr);
1083 if ( filter == NULL ) {
1084 rs.sr_err = LDAP_PROTOCOL_ERROR;
1088 filter2bv( filter, &fstr );
1090 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1091 ; /* count the number of attributes */
1095 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1096 for (i = 0; attrs[i] != 0; i++) {
1097 an[i].an_desc = NULL;
1099 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1100 an[i].an_name.bv_len = strlen(attrs[i]);
1101 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1103 an[i].an_name.bv_val = NULL;
1106 memset( &rs, 0, sizeof(rs) );
1107 rs.sr_type = REP_RESULT;
1108 rs.sr_err = LDAP_SUCCESS;
1109 rs.sr_entry = NULL; /* paranoia */
1111 if ( scope == LDAP_SCOPE_BASE ) {
1114 if ( op->o_req_ndn.bv_len == 0 ) {
1115 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1118 if( rs.sr_err != LDAP_SUCCESS ) {
1119 send_ldap_result( op, &rs );
1121 } else if ( rs.sr_entry != NULL ) {
1122 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1124 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1125 rs.sr_type = REP_SEARCH;
1126 rs.sr_err = LDAP_SUCCESS;
1129 send_search_entry( op, &rs );
1132 entry_free( rs.sr_entry );
1134 rs.sr_type = REP_RESULT;
1135 rs.sr_err = LDAP_SUCCESS;
1137 send_ldap_result( op, &rs );
1143 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1144 slapi_ch_free( (void **)op->o_req_dn.bv_val );
1145 slapi_ch_free( (void **)op->o_req_ndn.bv_val );
1147 ber_dupbv( &op->o_req_dn, &default_search_base );
1148 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1151 if ( slapi_control_present( controls,
1152 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1156 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1157 if ( op->o_bd == NULL ) {
1158 if ( manageDsaIt == 1 ) {
1159 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1161 rs.sr_err = LDAP_PARTIAL_RESULTS;
1166 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1167 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1169 op->oq_search.rs_scope = scope;
1170 op->oq_search.rs_deref = 0;
1171 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1172 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1173 op->oq_search.rs_attrsonly = attrsonly;
1174 op->oq_search.rs_attrs = an;
1175 op->oq_search.rs_filter = filter;
1176 op->oq_search.rs_filterstr = fstr;
1178 if ( op->o_bd->be_search ) {
1179 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1180 rs.sr_err = LDAP_OTHER;
1183 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1189 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1192 slapi_ch_free( (void **)&dn.bv_val );
1194 slapi_filter_free( filter, 1 );
1196 slapi_ch_free( (void **)&fstr.bv_val );
1198 slapi_ch_free( (void **)&an );
1204 slapiConnectionDestroy( &c );
1209 #endif /* LDAP_SLAPI */
1213 slapi_search_internal(
1217 LDAPControl **controls,
1222 return slapi_search_internal_bind( NULL, base, scope, filStr,
1223 controls, attrs, attrsonly );
1226 #endif /* LDAP_SLAPI */