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();
160 c->c_pending_ops.stqh_first->o_tmpmemctx = NULL;
161 c->c_pending_ops.stqh_first->o_tmpmfuncs = &ch_mfuncs;
162 c->c_pending_ops.stqh_first->o_conn = c;
164 /* connection object */
165 c->c_authmech.bv_val = NULL;
166 c->c_authmech.bv_len = 0;
167 c->c_dn.bv_val = NULL;
169 c->c_ndn.bv_val = NULL;
173 c->c_listener = &slap_unknown_listener;
174 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
175 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
177 LDAP_STAILQ_INIT( &c->c_ops );
179 c->c_sasl_bind_mech.bv_val = NULL;
180 c->c_sasl_bind_mech.bv_len = 0;
181 c->c_sasl_context = NULL;
182 c->c_sasl_extra = NULL;
184 c->c_sb = ber_sockbuf_alloc( );
186 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
188 c->c_currentber = NULL;
190 /* should check status of thread calls */
191 ldap_pvt_thread_mutex_init( &c->c_mutex );
192 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
193 ldap_pvt_thread_cond_init( &c->c_write_cv );
195 c->c_n_ops_received = 0;
196 c->c_n_ops_executing = 0;
197 c->c_n_ops_pending = 0;
198 c->c_n_ops_completed = 0;
204 c->c_protocol = LDAP_VERSION3;
206 c->c_activitytime = c->c_starttime = slap_get_time();
210 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
211 c->c_struct_state = 0x02; /* SLAP_C_USED */
213 c->c_ssf = c->c_transport_ssf = 0;
216 backend_connection_init( c );
218 pConn->c_send_ldap_result = internal_result_v3;
219 pConn->c_send_search_entry = internal_search_entry;
220 pConn->c_send_ldap_extended = internal_result_ext;
221 pConn->c_send_search_reference = internal_search_reference;
226 static void slapiConnectionDestroy( Connection **pConn )
228 Connection *conn = *pConn;
231 if ( pConn == NULL ) {
235 op = (Operation *)conn->c_pending_ops.stqh_first;
237 if ( op->o_req_dn.bv_val != NULL ) {
238 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
240 if ( op->o_req_ndn.bv_val != NULL ) {
241 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
244 if ( conn->c_sb != NULL ) {
245 ber_sockbuf_free( conn->c_sb );
248 slapi_ch_free( (void **)&op );
250 slapi_ch_free( (void **)pConn );
254 * Function : values2obj
255 * Convert an array of strings into a BerVarray.
266 if ( ppValue == NULL ) {
271 for ( i = 0; ppValue[i] != NULL; i++ )
274 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
275 if ( tmpberval == NULL ) {
276 return LDAP_NO_MEMORY;
278 for ( i = 0; ppValue[i] != NULL; i++ ) {
279 tmpberval[i].bv_val = ppValue[i];
280 tmpberval[i].bv_len = strlen( ppValue[i] );
282 tmpberval[i].bv_val = NULL;
283 tmpberval[i].bv_len = 0;
291 freeMods( Modifications *ml )
294 * Free a modification list whose values have been
295 * set with bvptr2obj() or values2obj() (ie. they
296 * do not own the pointer to the underlying values)
300 for ( ; ml != NULL; ml = next ) {
303 slapi_ch_free( (void **)&ml->sml_bvalues );
304 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, NULL );
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;
369 tmp.sml_nvalues = NULL;
371 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
373 mod->sml_op = LDAP_MOD_ADD;
374 mod->sml_next = NULL;
375 mod->sml_desc = NULL;
376 mod->sml_type = tmp.sml_type;
377 mod->sml_bvalues = tmp.sml_bvalues;
378 mod->sml_nvalues = tmp.sml_nvalues;
381 modtail = &mod->sml_next;
384 /* attr values are in string format, need to be converted */
385 /* to an array of bervals */
386 if ( pMod->mod_values == NULL ) {
389 rc = values2obj( pMod->mod_values, &bv );
390 if (rc != LDAP_SUCCESS) goto cleanup;
391 tmp.sml_type.bv_val = pMod->mod_type;
392 tmp.sml_type.bv_len = strlen( pMod->mod_type );
393 tmp.sml_bvalues = bv;
394 tmp.sml_nvalues = NULL;
396 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
398 mod->sml_op = LDAP_MOD_ADD;
399 mod->sml_next = NULL;
400 mod->sml_desc = NULL;
401 mod->sml_type = tmp.sml_type;
402 mod->sml_bvalues = tmp.sml_bvalues;
403 mod->sml_nvalues = tmp.sml_nvalues;
406 modtail = &mod->sml_next;
409 } /* for each LDAPMod */
412 op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
413 if ( op->o_bd == NULL ) {
414 rc = LDAP_PARTIAL_RESULTS;
416 int repl_user = be_isupdate( op->o_bd, &op->o_bd->be_rootdn );
417 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
418 int update = op->o_bd->be_update_ndn.bv_len;
419 char textbuf[SLAP_TEXT_BUFLEN];
420 size_t textlen = sizeof textbuf;
422 rc = slap_mods_check( modlist, update, &text,
423 textbuf, textlen, NULL );
424 if ( rc != LDAP_SUCCESS) {
429 rc = slap_mods_opattrs( op,
430 modlist, modtail, &text,
432 if ( rc != LDAP_SUCCESS) {
438 * FIXME: slap_mods2entry is declared static
439 * in servers/slapd/add.c
441 rc = slap_mods2entry( modlist, &pEntry, repl_user,
442 &text, textbuf, textlen );
443 if (rc != LDAP_SUCCESS) {
455 slapi_ch_free( (void **)&dn.bv_val );
457 slapi_ch_free( (void **)&op );
458 if ( modlist != NULL )
460 if ( rc != LDAP_SUCCESS ) {
461 if ( pEntry != NULL ) {
462 slapi_entry_free( pEntry );
470 /* Function : slapi_delete_internal
472 * Description : Plugin functions call this routine to delete an entry
473 * in the backend directly
474 * Return values : LDAP_SUCCESS
478 * LDAP_UNWILLING_TO_PERFORM
481 slapi_delete_internal(
483 LDAPControl **controls,
487 Connection *pConn = NULL;
488 Operation *op = NULL;
489 Slapi_PBlock *pPB = NULL;
490 Slapi_PBlock *pSavePB = NULL;
491 SlapReply rs = { REP_RESULT };
492 struct berval dn = { 0, NULL };
498 rs.sr_err = LDAP_PARAM_ERROR;
502 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
504 rs.sr_err = LDAP_NO_MEMORY;
508 op = (Operation *)pConn->c_pending_ops.stqh_first;
509 pPB = (Slapi_PBlock *)op->o_pb;
510 op->o_ctrls = controls;
512 dn.bv_val = slapi_ch_strdup(ldn);
513 dn.bv_len = strlen(ldn);
514 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
515 if ( rs.sr_err != LDAP_SUCCESS )
518 if ( slapi_control_present( controls,
519 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
523 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
524 if ( op->o_bd == NULL ) {
525 rs.sr_err = LDAP_PARTIAL_RESULTS;
529 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
530 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
532 if ( op->o_bd->be_delete ) {
533 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
534 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
535 if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
540 rs.sr_err = LDAP_OTHER;
543 rs.sr_err = LDAP_REFERRAL;
546 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
551 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
554 slapi_ch_free( (void **)&dn.bv_val );
556 if ( pConn != NULL ) {
560 slapiConnectionDestroy( &pConn );
565 #endif /* LDAP_SLAPI */
569 slapi_add_entry_internal(
571 LDAPControl **controls,
575 Connection *pConn = NULL;
576 Operation *op = NULL;
577 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
581 SlapReply rs = { REP_RESULT };
584 rs.sr_err = LDAP_PARAM_ERROR;
588 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
589 if ( pConn == NULL ) {
590 rs.sr_err = LDAP_NO_MEMORY;
594 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
595 NULL, &isCritical ) ) {
599 op = (Operation *)pConn->c_pending_ops.stqh_first;
600 pPB = (Slapi_PBlock *)op->o_pb;
601 op->o_ctrls = controls;
603 op->o_bd = select_backend( &e->e_nname, manageDsaIt, 0 );
604 if ( op->o_bd == NULL ) {
605 rs.sr_err = LDAP_PARTIAL_RESULTS;
609 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
610 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
613 if ( op->o_bd->be_add ) {
614 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
615 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ){
616 if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
622 rs.sr_err = LDAP_REFERRAL;
625 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
631 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
634 if ( pConn != NULL ) {
638 slapiConnectionDestroy( &pConn );
643 #endif /* LDAP_SLAPI */
651 LDAPControl **controls,
655 LDAPMod *pMod = NULL;
656 Slapi_PBlock *pb = NULL;
657 Entry *pEntry = NULL;
658 int i, rc = LDAP_SUCCESS;
660 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
661 rc = LDAP_PARAM_ERROR ;
664 if ( rc == LDAP_SUCCESS ) {
665 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
666 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
673 if ( rc == LDAP_SUCCESS ) {
674 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
679 if ( rc != LDAP_SUCCESS ) {
680 pb = slapi_pblock_new();
681 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
683 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
687 slapi_entry_free(pEntry);
693 #endif /* LDAP_SLAPI */
696 /* Function : slapi_modrdn_internal
698 * Description : Plugin functions call this routine to modify the rdn
699 * of an entry in the backend directly
700 * Return values : LDAP_SUCCESS
704 * LDAP_UNWILLING_TO_PERFORM
706 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
709 slapi_modrdn_internal(
713 LDAPControl **controls,
717 struct berval dn = { 0, NULL };
718 struct berval newrdn = { 0, NULL };
719 Connection *pConn = NULL;
720 Operation *op = NULL;
721 Slapi_PBlock *pPB = NULL;
722 Slapi_PBlock *pSavePB = NULL;
725 SlapReply rs = { REP_RESULT };
727 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
728 if ( pConn == NULL) {
729 rs.sr_err = LDAP_NO_MEMORY;
733 op = (Operation *)pConn->c_pending_ops.stqh_first;
734 pPB = (Slapi_PBlock *)op->o_pb;
735 op->o_ctrls = controls;
737 if ( slapi_control_present( controls,
738 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
742 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
743 if ( op->o_bd == NULL ) {
744 rs.sr_err = LDAP_PARTIAL_RESULTS;
748 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
749 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
751 dn.bv_val = slapi_ch_strdup( olddn );
752 dn.bv_len = strlen( olddn );
754 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
755 if ( rs.sr_err != LDAP_SUCCESS ) {
759 if ( op->o_req_dn.bv_len == 0 ) {
760 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
764 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
765 newrdn.bv_len = strlen( lnewrdn );
767 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn, NULL );
768 if ( rs.sr_err != LDAP_SUCCESS ) {
772 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
776 op->oq_modrdn.rs_newSup = NULL;
777 op->oq_modrdn.rs_nnewSup = NULL;
778 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
780 if ( op->o_bd->be_modrdn ) {
781 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
782 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
783 if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
788 rs.sr_err = LDAP_OTHER;
791 rs.sr_err = LDAP_REFERRAL;
794 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
800 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
804 slapi_ch_free( (void **)&dn.bv_val );
807 slapi_ch_free( (void **)&newrdn.bv_val );
808 if ( op->oq_modrdn.rs_newrdn.bv_val )
809 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
810 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
811 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
813 if ( pConn != NULL ) {
817 slapiConnectionDestroy( &pConn );
822 #endif /* LDAP_SLAPI */
825 /* Function : slapi_modify_internal
827 * Description: Plugin functions call this routine to modify an entry
828 * in the backend directly
829 * Return values : LDAP_SUCCESS
833 * LDAP_UNWILLING_TO_PERFORM
836 slapi_modify_internal(
839 LDAPControl **controls,
844 Connection *pConn = NULL;
845 Operation *op = NULL;
846 Slapi_PBlock *pPB = NULL;
847 Slapi_PBlock *pSavePB = NULL;
849 struct berval dn = { 0, NULL };
856 Modifications *modlist = NULL;
857 Modifications **modtail = &modlist;
860 SlapReply rs = { REP_RESULT };
862 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
863 rs.sr_err = LDAP_PARAM_ERROR ;
867 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
868 if ( pConn == NULL ) {
869 rs.sr_err = LDAP_NO_MEMORY;
873 op = (Operation *)pConn->c_pending_ops.stqh_first;
874 pPB = (Slapi_PBlock *)op->o_pb;
875 op->o_ctrls = controls;
877 dn.bv_val = slapi_ch_strdup( ldn );
878 dn.bv_len = strlen( ldn );
879 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
880 if ( rs.sr_err != LDAP_SUCCESS ) {
884 if ( slapi_control_present( controls,
885 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
889 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
890 if ( op->o_bd == NULL ) {
891 rs.sr_err = LDAP_PARTIAL_RESULTS;
895 op->o_dn = pConn->c_dn = op->o_bd->be_rootdn;
896 op->o_ndn = pConn->c_ndn = op->o_bd->be_rootndn;
898 for ( i = 0, pMod = mods[0];
899 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
904 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
906 * attr values are in berval format
907 * convert an array of pointers to bervals
908 * to an array of bervals
910 rs.sr_err = bvptr2obj( pMod->mod_bvalues, &bv );
911 if ( rs.sr_err != LDAP_SUCCESS )
913 tmp.sml_type.bv_val = pMod->mod_type;
914 tmp.sml_type.bv_len = strlen( pMod->mod_type );
915 tmp.sml_bvalues = bv;
916 tmp.sml_nvalues = NULL;
918 mod = (Modifications *)ch_malloc( sizeof(Modifications) );
920 mod->sml_op = pMod->mod_op;
921 mod->sml_next = NULL;
922 mod->sml_desc = NULL;
923 mod->sml_type = tmp.sml_type;
924 mod->sml_bvalues = tmp.sml_bvalues;
925 mod->sml_nvalues = tmp.sml_nvalues;
927 rs.sr_err = values2obj( pMod->mod_values, &bv );
928 if ( rs.sr_err != LDAP_SUCCESS )
930 tmp.sml_type.bv_val = pMod->mod_type;
931 tmp.sml_type.bv_len = strlen( pMod->mod_type );
932 tmp.sml_bvalues = bv;
933 tmp.sml_nvalues = NULL;
935 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
937 mod->sml_op = pMod->mod_op;
938 mod->sml_next = NULL;
939 mod->sml_desc = NULL;
940 mod->sml_type = tmp.sml_type;
941 mod->sml_bvalues = tmp.sml_bvalues;
942 mod->sml_nvalues = tmp.sml_nvalues;
945 modtail = &mod->sml_next;
947 switch( pMod->mod_op ) {
949 if ( mod->sml_bvalues == NULL ) {
950 rs.sr_err = LDAP_PROTOCOL_ERROR;
955 case LDAP_MOD_DELETE:
956 case LDAP_MOD_REPLACE:
960 rs.sr_err = LDAP_PROTOCOL_ERROR;
966 if ( op->o_req_ndn.bv_len == 0 ) {
967 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
971 op->oq_modify.rs_modlist = modlist;
973 if ( op->o_bd->be_modify ) {
974 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
975 if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
976 int update = op->o_bd->be_update_ndn.bv_len;
977 const char *text = NULL;
978 char textbuf[SLAP_TEXT_BUFLEN];
979 size_t textlen = sizeof( textbuf );
981 rs.sr_err = slap_mods_check( modlist, update,
982 &text, textbuf, textlen, NULL );
983 if ( rs.sr_err != LDAP_SUCCESS ) {
988 rs.sr_err = slap_mods_opattrs( op, modlist,
989 modtail, &text, textbuf,
991 if ( rs.sr_err != LDAP_SUCCESS ) {
995 if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
1000 rs.sr_err = LDAP_OTHER;
1003 rs.sr_err = LDAP_REFERRAL;
1006 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1012 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1015 slapi_ch_free( (void **)&dn.bv_val );
1017 if ( modlist != NULL )
1018 freeMods( modlist );
1020 if ( pConn != NULL ) {
1024 slapiConnectionDestroy( &pConn );
1029 #endif /* LDAP_SLAPI */
1033 slapi_search_internal_bind(
1038 LDAPControl **controls,
1044 Operation *op = NULL;
1045 Slapi_PBlock *ptr = NULL;
1046 Slapi_PBlock *pSavePB = NULL;
1047 struct berval dn = { 0, NULL };
1048 Filter *filter=NULL;
1049 struct berval fstr = { 0, NULL };
1050 AttributeName *an = NULL;
1051 const char *text = NULL;
1053 int manageDsaIt = 0;
1057 SlapReply rs = { REP_RESULT };
1059 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1061 rs.sr_err = LDAP_NO_MEMORY;
1065 op = (Operation *)c->c_pending_ops.stqh_first;
1066 ptr = (Slapi_PBlock *)op->o_pb;
1067 op->o_ctrls = controls;
1069 dn.bv_val = slapi_ch_strdup(ldn);
1070 dn.bv_len = strlen(ldn);
1072 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
1073 if ( rs.sr_err != LDAP_SUCCESS ) {
1077 if ( scope != LDAP_SCOPE_BASE &&
1078 scope != LDAP_SCOPE_ONELEVEL &&
1079 scope != LDAP_SCOPE_SUBTREE ) {
1080 rs.sr_err = LDAP_PROTOCOL_ERROR;
1084 filter = slapi_str2filter(filStr);
1085 if ( filter == NULL ) {
1086 rs.sr_err = LDAP_PROTOCOL_ERROR;
1090 filter2bv( filter, &fstr );
1092 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1093 ; /* count the number of attributes */
1097 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1098 for (i = 0; attrs[i] != 0; i++) {
1099 an[i].an_desc = NULL;
1101 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1102 an[i].an_name.bv_len = strlen(attrs[i]);
1103 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1105 an[i].an_name.bv_val = NULL;
1108 memset( &rs, 0, sizeof(rs) );
1109 rs.sr_type = REP_RESULT;
1110 rs.sr_err = LDAP_SUCCESS;
1111 rs.sr_entry = NULL; /* paranoia */
1113 if ( scope == LDAP_SCOPE_BASE ) {
1116 if ( op->o_req_ndn.bv_len == 0 ) {
1117 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1120 if( rs.sr_err != LDAP_SUCCESS ) {
1121 send_ldap_result( op, &rs );
1123 } else if ( rs.sr_entry != NULL ) {
1124 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1126 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1127 rs.sr_type = REP_SEARCH;
1128 rs.sr_err = LDAP_SUCCESS;
1131 send_search_entry( op, &rs );
1134 entry_free( rs.sr_entry );
1136 rs.sr_type = REP_RESULT;
1137 rs.sr_err = LDAP_SUCCESS;
1139 send_ldap_result( op, &rs );
1145 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1146 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
1147 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
1149 ber_dupbv( &op->o_req_dn, &default_search_base );
1150 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1153 if ( slapi_control_present( controls,
1154 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1158 op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1159 if ( op->o_bd == NULL ) {
1160 if ( manageDsaIt == 1 ) {
1161 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1163 rs.sr_err = LDAP_PARTIAL_RESULTS;
1168 op->o_dn = c->c_dn = op->o_bd->be_rootdn;
1169 op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
1171 op->oq_search.rs_scope = scope;
1172 op->oq_search.rs_deref = 0;
1173 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1174 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1175 op->oq_search.rs_attrsonly = attrsonly;
1176 op->oq_search.rs_attrs = an;
1177 op->oq_search.rs_filter = filter;
1178 op->oq_search.rs_filterstr = fstr;
1180 if ( op->o_bd->be_search ) {
1181 if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
1182 rs.sr_err = LDAP_OTHER;
1185 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1191 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1194 slapi_ch_free( (void **)&dn.bv_val );
1196 slapi_filter_free( filter, 1 );
1198 slapi_ch_free( (void **)&fstr.bv_val );
1200 slapi_ch_free( (void **)&an );
1206 slapiConnectionDestroy( &c );
1211 #endif /* LDAP_SLAPI */
1215 slapi_search_internal(
1219 LDAPControl **controls,
1224 return slapi_search_internal_bind( NULL, base, scope, filStr,
1225 controls, attrs, attrsonly );
1228 #endif /* LDAP_SLAPI */