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 );
41 if (op->o_tag == LDAP_REQ_SEARCH)
42 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
43 SLAPI_NENTRIES, (void *)sr->sr_nentries );
49 internal_search_entry(
54 int nentries = 0, len = 0, i = 0;
55 Slapi_Entry **head = NULL, **tp;
57 ent2str = slapi_entry2str( rs->sr_entry, &len );
58 if ( ent2str == NULL ) {
62 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
63 SLAPI_NENTRIES, &nentries );
64 slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
65 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
68 if ( nentries == 0 ) {
69 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
74 tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
75 if ( tp[ 0 ] == NULL ) {
80 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
81 sizeof(Slapi_Entry *) * ( i + 1 ) );
85 tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
86 if ( tp[ i - 1 ] == NULL ) {
92 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
93 SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
94 slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
95 SLAPI_NENTRIES, (void *)i );
109 internal_search_reference(
121 Connection *pConn, *c;
122 ber_len_t max = sockbuf_max_incoming;
124 pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
126 return (Connection *)NULL;
129 LDAP_STAILQ_INIT( &pConn->c_pending_ops );
131 pConn->c_pending_ops.stqh_first =
132 (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
133 if ( pConn->c_pending_ops.stqh_first == NULL ) {
134 slapi_ch_free( (void **)&pConn );
135 return (Connection *)NULL;
138 pConn->c_pending_ops.stqh_first->o_pb =
139 (Slapi_PBlock *) slapi_pblock_new();
140 if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
141 slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
142 slapi_ch_free( (void **)&pConn );
143 return (Connection *)NULL;
148 /* operation object */
149 c->c_pending_ops.stqh_first->o_tag = OpType;
150 c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
151 c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
152 c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
153 c->c_pending_ops.stqh_first->o_time = slap_get_time();
154 c->c_pending_ops.stqh_first->o_do_not_cache = 1;
155 c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );
157 /* connection object */
158 c->c_authmech.bv_val = NULL;
159 c->c_authmech.bv_len = 0;
160 c->c_dn.bv_val = NULL;
162 c->c_ndn.bv_val = NULL;
166 c->c_listener = &slap_unknown_listener;
167 ber_dupbv( &c->c_peer_domain, (struct berval *)&slap_unknown_bv );
168 ber_dupbv( &c->c_peer_name, (struct berval *)&slap_unknown_bv );
170 LDAP_STAILQ_INIT( &c->c_ops );
172 c->c_sasl_bind_mech.bv_val = NULL;
173 c->c_sasl_bind_mech.bv_len = 0;
174 c->c_sasl_context = NULL;
175 c->c_sasl_extra = NULL;
177 c->c_sb = ber_sockbuf_alloc( );
179 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
181 c->c_currentber = NULL;
183 /* should check status of thread calls */
184 ldap_pvt_thread_mutex_init( &c->c_mutex );
185 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
186 ldap_pvt_thread_cond_init( &c->c_write_cv );
188 c->c_n_ops_received = 0;
189 c->c_n_ops_executing = 0;
190 c->c_n_ops_pending = 0;
191 c->c_n_ops_completed = 0;
197 c->c_protocol = LDAP_VERSION3;
199 c->c_activitytime = c->c_starttime = slap_get_time();
203 c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
204 c->c_struct_state = 0x02; /* SLAP_C_USED */
206 c->c_ssf = c->c_transport_ssf = 0;
209 backend_connection_init( c );
211 pConn->c_send_ldap_result = internal_result_v3;
212 pConn->c_send_search_entry = internal_search_entry;
213 pConn->c_send_ldap_extended = internal_result_ext;
214 pConn->c_send_search_reference = internal_search_reference;
219 static void slapiConnectionDestroy( Connection **pConn )
221 Connection *conn = *pConn;
224 if ( pConn == NULL ) {
228 op = (Operation *)conn->c_pending_ops.stqh_first;
230 if ( op->o_req_dn.bv_val != NULL ) {
231 slapi_ch_free( (void **)&op->o_req_dn.bv_val );
233 if ( op->o_req_ndn.bv_val != NULL ) {
234 slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
237 if ( conn->c_sb != NULL ) {
238 ber_sockbuf_free( conn->c_sb );
241 slapi_ch_free( (void **)&op );
243 slapi_ch_free( (void **)pConn );
247 * Function : values2obj
248 * Convert an array of strings into a BerVarray.
259 if ( ppValue == NULL ) {
264 for ( i = 0; ppValue[i] != NULL; i++ )
267 tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
268 if ( tmpberval == NULL ) {
269 return LDAP_NO_MEMORY;
271 for ( i = 0; ppValue[i] != NULL; i++ ) {
272 tmpberval[i].bv_val = ppValue[i];
273 tmpberval[i].bv_len = strlen( ppValue[i] );
275 tmpberval[i].bv_val = NULL;
276 tmpberval[i].bv_len = 0;
284 freeMods( Modifications *ml )
287 * Free a modification list whose values have been
288 * set with bvptr2obj() or values2obj() (ie. they
289 * do not own the pointer to the underlying values)
293 for ( ; ml != NULL; ml = next ) {
296 slapi_ch_free( (void **)&ml->sml_bvalues );
298 slapi_ch_free( (void **)&ml->sml_nvalues );
300 slapi_ch_free( (void **)&ml );
305 * Function : LDAPModToEntry
306 * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
307 * with a link list of the correspondent attributes.
308 * Return value : LDAP_SUCCESS
317 struct berval dn = { 0, NULL };
324 Modifications *modlist = NULL;
325 Modifications **modtail = &modlist;
328 int rc = LDAP_SUCCESS;
331 const char *text = NULL;
334 op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
335 if ( pEntry == NULL) {
339 op->o_tag = LDAP_REQ_ADD;
341 pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
342 if ( pEntry == NULL) {
347 dn.bv_val = slapi_ch_strdup(ldn);
348 dn.bv_len = strlen(ldn);
350 rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
351 if ( rc != LDAP_SUCCESS )
354 if ( rc == LDAP_SUCCESS ) {
355 for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
357 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
358 /* attr values are in berval format */
359 /* convert an array of pointers to bervals to an array of bervals */
360 rc = bvptr2obj(pMod->mod_bvalues, &bv);
361 if (rc != LDAP_SUCCESS) goto cleanup;
362 tmp.sml_type.bv_val = pMod->mod_type;
363 tmp.sml_type.bv_len = strlen( pMod->mod_type );
364 tmp.sml_bvalues = bv;
366 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;
377 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;
395 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;
406 mod->sml_nvalues = tmp.sml_nvalues;
410 modtail = &mod->sml_next;
413 } /* for each LDAPMod */
416 be = select_backend(&pEntry->e_nname, 0, 0);
418 rc = LDAP_PARTIAL_RESULTS;
423 int repl_user = be_isupdate(be, &be->be_rootdn );
424 if ( !be->be_update_ndn.bv_len || repl_user ) {
425 int update = be->be_update_ndn.bv_len;
426 char textbuf[SLAP_TEXT_BUFLEN];
427 size_t textlen = sizeof textbuf;
429 rc = slap_mods_check( modlist, update, &text,
431 if ( rc != LDAP_SUCCESS) {
436 rc = slap_mods_opattrs( op,
437 modlist, modtail, &text,
439 if ( rc != LDAP_SUCCESS) {
445 * FIXME: slap_mods2entry is declared static
446 * in servers/slapd/add.c
448 rc = slap_mods2entry( modlist, &pEntry, repl_user,
449 &text, textbuf, textlen );
450 if (rc != LDAP_SUCCESS) {
458 rc = LDAP_UNWILLING_TO_PERFORM;
464 slapi_ch_free( (void **)&dn.bv_val );
466 slapi_ch_free( (void **)&op );
467 if ( modlist != NULL )
469 if ( rc != LDAP_SUCCESS ) {
470 if ( pEntry != NULL ) {
471 slapi_entry_free( pEntry );
479 /* Function : slapi_delete_internal
481 * Description : Plugin functions call this routine to delete an entry
482 * in the backend directly
483 * Return values : LDAP_SUCCESS
487 * LDAP_UNWILLING_TO_PERFORM
490 slapi_delete_internal(
492 LDAPControl **controls,
497 Connection *pConn = NULL;
498 Operation *op = NULL;
499 Slapi_PBlock *pPB = NULL;
500 Slapi_PBlock *pSavePB = NULL;
501 SlapReply rs = { REP_RESULT };
502 struct berval dn = { 0, NULL };
508 rs.sr_err = LDAP_PARAM_ERROR;
512 pConn = slapiConnectionInit( NULL, LDAP_REQ_DELETE );
514 rs.sr_err = LDAP_NO_MEMORY;
518 op = (Operation *)pConn->c_pending_ops.stqh_first;
519 pPB = (Slapi_PBlock *)op->o_pb;
520 op->o_ctrls = controls;
522 dn.bv_val = slapi_ch_strdup(ldn);
523 dn.bv_len = strlen(ldn);
524 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
525 if ( rs.sr_err != LDAP_SUCCESS )
528 if ( slapi_control_present( controls,
529 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
533 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
535 rs.sr_err = LDAP_PARTIAL_RESULTS;
539 op->o_dn = pConn->c_dn = be->be_rootdn;
540 op->o_ndn = pConn->c_ndn = be->be_rootndn;
542 if ( be->be_delete ) {
543 int repl_user = be_isupdate( be, &op->o_ndn );
544 if ( !be->be_update_ndn.bv_len || repl_user ) {
545 if ( (*be->be_delete)( op, &rs ) == 0 ) {
550 rs.sr_err = LDAP_OTHER;
553 rs.sr_err = LDAP_REFERRAL;
556 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
561 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
564 slapi_ch_free( (void **)&dn.bv_val );
566 if ( pConn != NULL ) {
570 slapiConnectionDestroy( &pConn );
575 #endif /* LDAP_SLAPI */
579 slapi_add_entry_internal(
581 LDAPControl **controls,
585 Connection *pConn = NULL;
586 Operation *op = NULL;
587 Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
592 SlapReply rs = { REP_RESULT };
595 rs.sr_err = LDAP_PARAM_ERROR;
599 pConn = slapiConnectionInit( NULL, LDAP_REQ_ADD );
600 if ( pConn == NULL ) {
601 rs.sr_err = LDAP_NO_MEMORY;
605 if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
606 NULL, &isCritical ) ) {
610 op = (Operation *)pConn->c_pending_ops.stqh_first;
611 pPB = (Slapi_PBlock *)op->o_pb;
612 op->o_ctrls = controls;
614 be = select_backend( &e->e_nname, manageDsaIt, 0 );
616 rs.sr_err = LDAP_PARTIAL_RESULTS;
620 op->o_dn = pConn->c_dn = be->be_rootdn;
621 op->o_ndn = pConn->c_ndn = be->be_rootndn;
625 int repl_user = be_isupdate( be, &op->o_ndn );
626 if ( !be->be_update_ndn.bv_len || repl_user ){
627 if ( (*be->be_add)( op, &rs ) == 0 ) {
633 rs.sr_err = LDAP_REFERRAL;
636 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
642 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
645 if ( pConn != NULL ) {
649 slapiConnectionDestroy( &pConn );
654 #endif /* LDAP_SLAPI */
662 LDAPControl **controls,
666 LDAPMod *pMod = NULL;
667 Slapi_PBlock *pb = NULL;
668 Entry *pEntry = NULL;
669 int i, rc = LDAP_SUCCESS;
671 if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
672 rc = LDAP_PARAM_ERROR ;
675 if ( rc == LDAP_SUCCESS ) {
676 for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
677 if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
684 if ( rc == LDAP_SUCCESS ) {
685 if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
690 if ( rc != LDAP_SUCCESS ) {
691 pb = slapi_pblock_new();
692 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
694 pb = slapi_add_entry_internal( pEntry, controls, log_changes );
698 slapi_entry_free(pEntry);
704 #endif /* LDAP_SLAPI */
707 /* Function : slapi_modrdn_internal
709 * Description : Plugin functions call this routine to modify the rdn
710 * of an entry in the backend directly
711 * Return values : LDAP_SUCCESS
715 * LDAP_UNWILLING_TO_PERFORM
717 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
720 slapi_modrdn_internal(
724 LDAPControl **controls,
728 struct berval dn = { 0, NULL };
729 struct berval newrdn = { 0, NULL };
730 Connection *pConn = NULL;
731 Operation *op = NULL;
732 Slapi_PBlock *pPB = NULL;
733 Slapi_PBlock *pSavePB = NULL;
737 SlapReply rs = { REP_RESULT };
739 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODRDN);
740 if ( pConn == NULL) {
741 rs.sr_err = LDAP_NO_MEMORY;
745 op = (Operation *)pConn->c_pending_ops.stqh_first;
746 pPB = (Slapi_PBlock *)op->o_pb;
747 op->o_ctrls = controls;
749 if ( slapi_control_present( controls,
750 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
754 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
756 rs.sr_err = LDAP_PARTIAL_RESULTS;
760 op->o_dn = pConn->c_dn = be->be_rootdn;
761 op->o_ndn = pConn->c_ndn = be->be_rootndn;
763 dn.bv_val = slapi_ch_strdup( olddn );
764 dn.bv_len = strlen( olddn );
766 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
767 if ( rs.sr_err != LDAP_SUCCESS ) {
771 if ( op->o_req_dn.bv_len == 0 ) {
772 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
776 newrdn.bv_val = slapi_ch_strdup( lnewrdn );
777 newrdn.bv_len = strlen( lnewrdn );
779 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->oq_modrdn.rs_newrdn, &op->oq_modrdn.rs_nnewrdn );
780 if ( rs.sr_err != LDAP_SUCCESS ) {
784 if ( rdnValidate( &op->oq_modrdn.rs_nnewrdn ) != LDAP_SUCCESS ) {
788 op->oq_modrdn.rs_newSup = NULL;
789 op->oq_modrdn.rs_nnewSup = NULL;
790 op->oq_modrdn.rs_deleteoldrdn = deloldrdn;
792 if ( be->be_modrdn ) {
793 int repl_user = be_isupdate( be, &op->o_ndn );
794 if ( !be->be_update_ndn.bv_len || repl_user ) {
795 if ( (*be->be_modrdn)( op, &rs ) == 0 ) {
800 rs.sr_err = LDAP_OTHER;
803 rs.sr_err = LDAP_REFERRAL;
806 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
812 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
816 slapi_ch_free( (void **)&dn.bv_val );
819 slapi_ch_free( (void **)&newrdn.bv_val );
820 if ( op->oq_modrdn.rs_newrdn.bv_val )
821 slapi_ch_free( (void **)&op->oq_modrdn.rs_newrdn.bv_val );
822 if ( op->oq_modrdn.rs_nnewrdn.bv_val )
823 slapi_ch_free( (void **)&op->oq_modrdn.rs_nnewrdn.bv_val );
825 if ( pConn != NULL ) {
829 slapiConnectionDestroy( &pConn );
834 #endif /* LDAP_SLAPI */
837 /* Function : slapi_modify_internal
839 * Description: Plugin functions call this routine to modify an entry
840 * in the backend directly
841 * Return values : LDAP_SUCCESS
845 * LDAP_UNWILLING_TO_PERFORM
848 slapi_modify_internal(
851 LDAPControl **controls,
856 Connection *pConn = NULL;
857 Operation *op = NULL;
858 Slapi_PBlock *pPB = NULL;
859 Slapi_PBlock *pSavePB = NULL;
861 struct berval dn = { 0, NULL };
869 Modifications *modlist = NULL;
870 Modifications **modtail = &modlist;
873 SlapReply rs = { REP_RESULT };
875 if ( mods == NULL || *mods == NULL || ldn == NULL ) {
876 rs.sr_err = LDAP_PARAM_ERROR ;
880 pConn = slapiConnectionInit( NULL, LDAP_REQ_MODIFY );
881 if ( pConn == NULL ) {
882 rs.sr_err = LDAP_NO_MEMORY;
886 op = (Operation *)pConn->c_pending_ops.stqh_first;
887 pPB = (Slapi_PBlock *)op->o_pb;
888 op->o_ctrls = controls;
890 dn.bv_val = slapi_ch_strdup( ldn );
891 dn.bv_len = strlen( ldn );
892 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
893 if ( rs.sr_err != LDAP_SUCCESS ) {
897 if ( slapi_control_present( controls,
898 SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
902 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
904 rs.sr_err = LDAP_PARTIAL_RESULTS;
908 op->o_dn = pConn->c_dn = be->be_rootdn;
909 op->o_ndn = pConn->c_ndn = be->be_rootndn;
911 for ( i = 0, pMod = mods[0];
912 rs.sr_err == LDAP_SUCCESS && pMod != NULL;
917 if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
919 * attr values are in berval format
920 * convert an array of pointers to bervals
921 * to an array of bervals
923 rs.sr_err = bvptr2obj( pMod->mod_bvalues, &bv );
924 if ( rs.sr_err != LDAP_SUCCESS )
926 tmp.sml_type.bv_val = pMod->mod_type;
927 tmp.sml_type.bv_len = strlen( pMod->mod_type );
928 tmp.sml_bvalues = bv;
930 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;
941 mod->sml_nvalues = tmp.sml_nvalues;
944 rs.sr_err = values2obj( pMod->mod_values, &bv );
945 if ( rs.sr_err != LDAP_SUCCESS )
947 tmp.sml_type.bv_val = pMod->mod_type;
948 tmp.sml_type.bv_len = strlen( pMod->mod_type );
949 tmp.sml_bvalues = bv;
951 tmp.sml_nvalues = NULL;
954 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
956 mod->sml_op = pMod->mod_op;
957 mod->sml_next = NULL;
958 mod->sml_desc = NULL;
959 mod->sml_type = tmp.sml_type;
960 mod->sml_bvalues = tmp.sml_bvalues;
962 mod->sml_nvalues = tmp.sml_nvalues;
966 modtail = &mod->sml_next;
968 switch( pMod->mod_op ) {
970 if ( mod->sml_bvalues == NULL ) {
971 rs.sr_err = LDAP_PROTOCOL_ERROR;
976 case LDAP_MOD_DELETE:
977 case LDAP_MOD_REPLACE:
981 rs.sr_err = LDAP_PROTOCOL_ERROR;
987 if ( op->o_req_ndn.bv_len == 0 ) {
988 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
992 op->oq_modify.rs_modlist = modlist;
994 if ( be->be_modify ) {
995 int repl_user = be_isupdate( be, &op->o_ndn );
996 if ( !be->be_update_ndn.bv_len || repl_user ) {
997 int update = be->be_update_ndn.bv_len;
998 const char *text = NULL;
999 char textbuf[SLAP_TEXT_BUFLEN];
1000 size_t textlen = sizeof( textbuf );
1002 rs.sr_err = slap_mods_check( modlist, update,
1003 &text, textbuf, textlen );
1004 if ( rs.sr_err != LDAP_SUCCESS ) {
1009 rs.sr_err = slap_mods_opattrs( op, modlist,
1010 modtail, &text, textbuf,
1012 if ( rs.sr_err != LDAP_SUCCESS ) {
1016 if ( (*be->be_modify)( op, &rs ) == 0 ) {
1021 rs.sr_err = LDAP_OTHER;
1024 rs.sr_err = LDAP_REFERRAL;
1027 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1033 slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1036 slapi_ch_free( (void **)&dn.bv_val );
1038 if ( modlist != NULL )
1039 freeMods( modlist );
1041 if ( pConn != NULL ) {
1045 slapiConnectionDestroy( &pConn );
1050 #endif /* LDAP_SLAPI */
1054 slapi_search_internal_bind(
1059 LDAPControl **controls,
1066 Operation *op = NULL;
1067 Slapi_PBlock *ptr = NULL;
1068 Slapi_PBlock *pSavePB = NULL;
1069 struct berval dn = { 0, NULL };
1070 Filter *filter=NULL;
1071 struct berval fstr = { 0, NULL };
1072 AttributeName *an = NULL;
1073 const char *text = NULL;
1075 int manageDsaIt = 0;
1079 SlapReply rs = { REP_RESULT };
1081 c = slapiConnectionInit( NULL, LDAP_REQ_SEARCH );
1083 rs.sr_err = LDAP_NO_MEMORY;
1087 op = (Operation *)c->c_pending_ops.stqh_first;
1088 ptr = (Slapi_PBlock *)op->o_pb;
1089 op->o_ctrls = controls;
1091 dn.bv_val = slapi_ch_strdup(ldn);
1092 dn.bv_len = strlen(ldn);
1094 rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
1095 if ( rs.sr_err != LDAP_SUCCESS ) {
1099 if ( scope != LDAP_SCOPE_BASE &&
1100 scope != LDAP_SCOPE_ONELEVEL &&
1101 scope != LDAP_SCOPE_SUBTREE ) {
1102 rs.sr_err = LDAP_PROTOCOL_ERROR;
1106 filter = slapi_str2filter(filStr);
1107 if ( filter == NULL ) {
1108 rs.sr_err = LDAP_PROTOCOL_ERROR;
1112 filter2bv( filter, &fstr );
1114 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
1115 ; /* count the number of attributes */
1119 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
1120 for (i = 0; attrs[i] != 0; i++) {
1121 an[i].an_desc = NULL;
1123 an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
1124 an[i].an_name.bv_len = strlen(attrs[i]);
1125 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
1127 an[i].an_name.bv_val = NULL;
1130 memset( &rs, 0, sizeof(rs) );
1131 rs.sr_type = REP_RESULT;
1132 rs.sr_err = LDAP_SUCCESS;
1133 rs.sr_entry = NULL; /* paranoia */
1135 if ( scope == LDAP_SCOPE_BASE ) {
1138 if ( op->o_req_ndn.bv_len == 0 ) {
1139 rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
1142 if( rs.sr_err != LDAP_SUCCESS ) {
1143 send_ldap_result( op, &rs );
1145 } else if ( rs.sr_entry != NULL ) {
1146 rs.sr_err = test_filter( op, rs.sr_entry, filter );
1148 if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
1149 rs.sr_type = REP_SEARCH;
1150 rs.sr_err = LDAP_SUCCESS;
1153 send_search_entry( op, &rs );
1156 entry_free( rs.sr_entry );
1158 rs.sr_type = REP_RESULT;
1159 rs.sr_err = LDAP_SUCCESS;
1161 send_ldap_result( op, &rs );
1167 if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
1168 slapi_ch_free( (void **)op->o_req_dn.bv_val );
1169 slapi_ch_free( (void **)op->o_req_ndn.bv_val );
1171 ber_dupbv( &op->o_req_dn, &default_search_base );
1172 ber_dupbv( &op->o_req_ndn, &default_search_nbase );
1175 if ( slapi_control_present( controls,
1176 LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
1180 be = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
1182 if ( manageDsaIt == 1 ) {
1183 rs.sr_err = LDAP_NO_SUCH_OBJECT;
1185 rs.sr_err = LDAP_PARTIAL_RESULTS;
1190 op->o_dn = c->c_dn = be->be_rootdn;
1191 op->o_ndn = c->c_ndn = be->be_rootndn;
1193 op->oq_search.rs_scope = scope;
1194 op->oq_search.rs_deref = 0;
1195 op->oq_search.rs_slimit = LDAP_NO_LIMIT;
1196 op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
1197 op->oq_search.rs_attrsonly = attrsonly;
1198 op->oq_search.rs_attrs = an;
1199 op->oq_search.rs_filter = filter;
1200 op->oq_search.rs_filterstr = fstr;
1202 if ( be->be_search ) {
1203 if ( (*be->be_search)( op, &rs ) != 0 ) {
1204 rs.sr_err = LDAP_OTHER;
1207 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
1213 slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
1216 slapi_ch_free( (void **)&dn.bv_val );
1218 slapi_filter_free( filter, 1 );
1220 slapi_ch_free( (void **)&fstr.bv_val );
1222 slapi_ch_free( (void **)&an );
1228 slapiConnectionDestroy( &c );
1233 #endif /* LDAP_SLAPI */
1237 slapi_search_internal(
1241 LDAPControl **controls,
1246 return slapi_search_internal_bind( NULL, base, scope, filStr,
1247 controls, attrs, attrsonly );
1250 #endif /* LDAP_SLAPI */