use a separate field for a modified entry in SlapReply

This commit is contained in:
Pierangelo Masarati 2004-07-13 22:52:54 +00:00
parent 89b284eef5
commit 3b8111f1c4
4 changed files with 75 additions and 48 deletions

View File

@ -454,6 +454,19 @@ rwm_swap_attrs( Operation *op, SlapReply *rs )
return SLAP_CB_CONTINUE;
}
static int
rwm_mentry_free( Operation *op, SlapReply *rs )
{
slap_callback *cb = op->o_callback;
if ( rs->sr_mentry ) {
entry_free( rs->sr_mentry );
rs->sr_mentry = NULL;
}
return SLAP_CB_CONTINUE;
}
static int
rwm_search( Operation *op, SlapReply *rs )
{
@ -535,14 +548,13 @@ rwm_search( Operation *op, SlapReply *rs )
}
cb->sc_response = rwm_swap_attrs;
cb->sc_cleanup = NULL;
cb->sc_cleanup = rwm_mentry_free;
cb->sc_private = (void *)op->ors_attrs;
cb->sc_next = op->o_callback;
op->o_callback = cb;
op->ors_attrs = an;
/* TODO: rewrite/map filter & attrs */
return SLAP_CB_CONTINUE;
error_return:;
@ -649,8 +661,6 @@ rwm_send_entry( Operation *op, SlapReply *rs )
assert( rs->sr_entry );
e = rs->sr_entry;
/*
* Rewrite the dn of the result, if needed
*/
@ -666,21 +676,28 @@ rwm_send_entry( Operation *op, SlapReply *rs )
flags = rs->sr_flags;
if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
/* FIXME: all we need to duplicate are:
* - dn
* - ndn
* - attributes that are requested
* - no values if attrsonly is set
*/
if ( rs->sr_mentry != NULL ) {
e = rs->sr_mentry;
e = entry_dup( e );
if ( e == NULL ) {
rc = LDAP_NO_MEMORY;
goto fail;
} else {
e = rs->sr_entry;
if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
/* FIXME: all we need to duplicate are:
* - dn
* - ndn
* - attributes that are requested
* - no values if attrsonly is set
*/
e = entry_dup( e );
if ( e == NULL ) {
rc = LDAP_NO_MEMORY;
goto fail;
}
// flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
}
flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
}
/*
@ -830,7 +847,7 @@ next_attr:;
}
rs->sr_entry = e;
rs->sr_mentry = e;
rs->sr_flags = flags;
return SLAP_CB_CONTINUE;
@ -844,7 +861,7 @@ fail:;
ch_free( ndn.bv_val );
}
if ( e != NULL && e != rs->sr_entry ) {
if ( e != NULL && e != rs->sr_mentry ) {
entry_free( e );
}

View File

@ -81,6 +81,7 @@ rwm_map_init( struct ldapmap *lm, struct ldapmapping **m )
return LDAP_NO_MEMORY;
}
/* FIXME: I don't think this is needed any more... */
rc = slap_str2ad( "objectClass", &mapping->m_src_ad, &text );
if ( rc != LDAP_SUCCESS ) {
return rc;
@ -169,6 +170,9 @@ rwm_map_attrnames(
for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
/* just count */ ;
*anp = ch_malloc( ( i + 1 )* sizeof( AttributeName ) );
if ( *anp == NULL ) {
return LDAP_NO_MEMORY;
}
for ( i = 0, j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
struct ldapmapping *m;

View File

@ -746,7 +746,8 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
* returned or filtered out
* e_flags: array of a_flags
*/
char **e_flags = NULL;
char **e_flags = NULL;
Entry *e;
rs->sr_type = REP_SEARCH;
if (op->o_callback) {
@ -763,21 +764,23 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
if ( rc != SLAP_CB_CONTINUE ) goto error_return;
}
e = rs->sr_mentry ? rs->sr_mentry : rs->sr_entry;
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
op->o_connid, rs->sr_entry->e_name.bv_val,
LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
op->o_connid, e->e_name.bv_val,
op->ors_attrsonly ? " (attrsOnly)" : "" );
#else
Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: dn=\"%s\"%s\n",
rs->sr_entry->e_name.bv_val,
op->ors_attrsonly ? " (attrsOnly)" : "", 0 );
Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
op->o_connid, e->e_name.bv_val,
op->ors_attrsonly ? " (attrsOnly)" : "" );
#endif
if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
if ( !access_allowed( op, e, ad_entry, NULL, ACL_READ, NULL )) {
#ifdef NEW_LOGGING
LDAP_LOG( ACL, INFO,
"send_search_entry: conn %lu access to entry (%s) not allowed\n",
op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
op->o_connid, e->e_name.bv_val, 0 );
#else
Debug( LDAP_DEBUG_ACL,
"send_search_entry: access to entry not allowed\n",
@ -788,16 +791,17 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
goto error_return;
}
edn = rs->sr_entry->e_nname.bv_val;
edn = e->e_nname.bv_val;
if ( op->o_res_ber ) {
/* read back control or LDAP_CONNECTIONLESS */
ber = op->o_res_ber;
ber = op->o_res_ber;
} else {
ber_len_t siz, len;
struct berval bv;
entry_flatsize( rs->sr_entry, &siz, &len, 0 );
entry_flatsize( e, &siz, &len, 0 );
bv.bv_len = siz + len;
bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
@ -809,20 +813,20 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
if ( op->o_conn && op->o_conn->c_is_udp ) {
/* CONNECTIONLESS */
if ( op->o_protocol == LDAP_VERSION2 ) {
rc = ber_printf(ber, "t{O{" /*}}*/,
LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
rc = ber_printf(ber, "t{O{" /*}}*/,
LDAP_RES_SEARCH_ENTRY, &e->e_name );
} else {
rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
LDAP_RES_SEARCH_ENTRY, &e->e_name );
}
} else
#endif
if ( op->o_res_ber ) {
/* read back control */
rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
rc = ber_printf( ber, "{O{" /*}}*/, &e->e_name );
} else {
rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
LDAP_RES_SEARCH_ENTRY, &e->e_name );
}
if ( rc == -1 ) {
@ -855,7 +859,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
int k = 0;
size_t size;
for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
}
@ -879,13 +883,13 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
}
a_flags = (char *)(e_flags + i);
memset( a_flags, 0, k );
for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
for ( a = e->e_attrs, i = 0; a != NULL; a = a->a_next, i++ ) {
for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
e_flags[i] = a_flags;
a_flags += j;
}
rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
rc = filter_matched_values(op, e->e_attrs, &e_flags) ;
if ( rc == -1 ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR, "send_search_entry: "
@ -903,7 +907,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
}
}
for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
AttributeDescription *desc = a->a_desc;
int finish = 0;
@ -928,7 +932,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
}
if ( op->ors_attrsonly ) {
if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
if ( ! access_allowed( op, e, desc, NULL,
ACL_READ, &acl_state ) )
{
#ifdef NEW_LOGGING
@ -962,7 +966,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
} else {
int first = 1;
for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
if ( ! access_allowed( op, rs->sr_entry,
if ( ! access_allowed( op, e,
desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
{
#ifdef NEW_LOGGING
@ -1126,7 +1130,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
}
}
if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
if ( ! access_allowed( op, e, desc, NULL,
ACL_READ, &acl_state ) )
{
#ifdef NEW_LOGGING
@ -1163,7 +1167,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
if ( ! op->ors_attrsonly ) {
for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
if ( ! access_allowed( op, rs->sr_entry,
if ( ! access_allowed( op, e,
desc, &a->a_vals[i], ACL_READ, &acl_state ) )
{
#ifdef NEW_LOGGING
@ -1240,7 +1244,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
if ( rs->sr_attrs != NULL ) {
for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
rc = compute_evaluator( &ctx, anp->an_name.bv_val,
rs->sr_entry, slapi_int_compute_output_ber );
e, slapi_int_compute_output_ber );
if ( rc == 1 ) break;
}
} else {
@ -1250,7 +1254,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
* plugin decide whether to be naughty or not.
*/
rc = compute_evaluator( &ctx, "*",
rs->sr_entry, slapi_int_compute_output_ber );
e, slapi_int_compute_output_ber );
}
if ( rc == 1 ) {
if ( op->o_res_ber == NULL ) ber_free_buf( ber );
@ -1329,7 +1333,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
}
Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
op->o_connid, op->o_opid, e->e_dn, 0, 0 );
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ENTRY,

View File

@ -1687,6 +1687,7 @@ typedef struct rep_extended_s {
typedef struct rep_search_s {
Entry *r_entry;
Entry *r_mentry;
AttributeName *r_attrs;
int r_nentries;
BerVarray r_v2ref;
@ -1716,6 +1717,7 @@ typedef struct slap_rep {
/* short hands for response members */
#define sr_attrs sr_un.sru_search.r_attrs
#define sr_entry sr_un.sru_search.r_entry
#define sr_mentry sr_un.sru_search.r_mentry
#define sr_v2ref sr_un.sru_search.r_v2ref
#define sr_nentries sr_un.sru_search.r_nentries
#define sr_rspoid sr_un.sru_extended.r_rspoid