Commit 3aefa943 authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

major improvement: baseline support for back-config; minor improvement: trim...

major improvement: baseline support for back-config; minor improvement: trim code to handle absence of librewrite (enable forced when slapo-rwm is configured...)
parent 4066e22c
This diff is collapsed.
......@@ -24,10 +24,12 @@
#ifndef RWM_H
#define RWM_H
#ifndef ENABLE_REWRITE
#error "librewrite must be enabled!"
#endif /* ENABLE_REWRITE */
/* String rewrite library */
#ifdef ENABLE_REWRITE
#include "rewrite.h"
#endif /* ENABLE_REWRITE */
LDAP_BEGIN_DECL
......@@ -67,24 +69,22 @@ struct ldaprwmap {
/*
* DN rewriting
*/
#ifdef ENABLE_REWRITE
struct rewrite_info *rwm_rw;
#else /* !ENABLE_REWRITE */
/* some time the suffix massaging without librewrite
* will be disabled */
BerVarray rwm_suffix_massage;
#endif /* !ENABLE_REWRITE */
BerVarray rwm_bva_rewrite;
/*
* Attribute/objectClass mapping
*/
struct ldapmap rwm_oc;
struct ldapmap rwm_at;
#define RWM_F_NONE 0x0000U
#define RWM_F_NORMALIZE_MAPPED_ATTRS 0x0001U
#define RWM_F_SUPPORT_T_F 0x4000U
#define RWM_F_SUPPORT_T_F_DISCOVER 0x8000U
BerVarray rwm_bva_map;
#define RWM_F_NONE (0x0000U)
#define RWM_F_NORMALIZE_MAPPED_ATTRS (0x0001U)
#define RWM_F_SUPPORT_T_F (0x4000U)
#define RWM_F_SUPPORT_T_F_DISCOVER (0x8000U)
#define RWM_F_SUPPORT_T_F_MASK (RWM_F_SUPPORT_T_F)
#define RWM_F_SUPPORT_T_F_MASK2 (RWM_F_SUPPORT_T_F|RWM_F_SUPPORT_T_F_DISCOVER)
unsigned rwm_flags;
};
......@@ -92,14 +92,9 @@ struct ldaprwmap {
typedef struct dncookie {
struct ldaprwmap *rwmap;
#ifdef ENABLE_REWRITE
Connection *conn;
char *ctx;
SlapReply *rs;
#else /* !ENABLE_REWRITE */
int normalized;
int tofrom;
#endif /* !ENABLE_REWRITE */
} dncookie;
int rwm_dn_massage( dncookie *dc, struct berval *in, struct berval *dn );
......@@ -159,18 +154,22 @@ rwm_filter_map_rewrite(
struct berval *fstr );
/* suffix massaging by means of librewrite */
#ifdef ENABLE_REWRITE
extern int rwm_suffix_massage_config( struct rewrite_info *info,
struct berval *pvnc, struct berval *nvnc,
struct berval *prnc, struct berval *nrnc);
#endif /* ENABLE_REWRITE */
extern int rwm_dnattr_rewrite(
extern int
rwm_suffix_massage_config(
struct rewrite_info *info,
struct berval *pvnc,
struct berval *nvnc,
struct berval *prnc,
struct berval *nrnc);
extern int
rwm_dnattr_rewrite(
Operation *op,
SlapReply *rs,
void *cookie,
BerVarray a_vals,
BerVarray *pa_nvals );
extern int rwm_referral_rewrite(
extern int
rwm_referral_rewrite(
Operation *op,
SlapReply *rs,
void *cookie,
......
......@@ -149,13 +149,6 @@ rwm_map_config(
fname, lineno, dst );
goto error_return;
}
#if 0
mapping[0].m_dst_oc = ch_malloc( sizeof( ObjectClass ) );
memset( mapping[0].m_dst_oc, 0, sizeof( ObjectClass ) );
mapping[0].m_dst_oc->soc_cname = mapping[0].m_dst;
mapping[0].m_flags |= RWMMAP_F_FREE_DST;
#endif
}
mapping[1].m_src_oc = mapping[0].m_dst_oc;
......@@ -247,7 +240,6 @@ error_return:;
return 1;
}
#ifdef ENABLE_REWRITE
static char *
rwm_suffix_massage_regexize( const char *s )
{
......@@ -413,6 +405,5 @@ rwm_suffix_massage_config(
return 0;
}
#endif /* ENABLE_REWRITE */
#endif /* SLAPD_OVER_RWM */
......@@ -142,7 +142,6 @@ rwm_dn_massage_pretty_normalize(
return rc;
}
#ifdef ENABLE_REWRITE
/*
* massages "in" into "dn"
*
......@@ -209,111 +208,4 @@ rwm_dn_massage(
return rc;
}
#else /* ! ENABLE_REWRITE */
/*
* rwm_dn_massage
*
* Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
*/
int
rwm_dn_massage(
dncookie *dc,
struct berval *in,
struct berval *dn
)
{
int i, src, dst;
struct berval tmpin;
assert( dc != NULL );
assert( in != NULL );
assert( dn != NULL );
BER_BVZERO( dn );
if ( BER_BVISNULL( in ) ) {
return LDAP_SUCCESS;
}
if ( dc->rwmap == NULL || dc->rwmap->rwm_suffix_massage == NULL ) {
*dn = *in;
return LDAP_SUCCESS;
}
if ( dc->tofrom ) {
src = 0 + dc->normalized;
dst = 2 + dc->normalized;
tmpin = *in;
} else {
int rc;
src = 2 + dc->normalized;
dst = 0 + dc->normalized;
/* DN from remote server may be in arbitrary form.
* Pretty it so we can parse reliably.
*/
if ( dc->normalized ) {
rc = dnNormalize( 0, NULL, NULL, in, &tmpin, NULL );
} else {
rc = dnPretty( NULL, in, &tmpin, NULL );
}
if ( rc != LDAP_SUCCESS ) {
return rc;
}
}
for ( i = 0;
!BER_BVISNULL( &dc->rwmap->rwm_suffix_massage[i] );
i += 4 )
{
int aliasLength = dc->rwmap->rwm_suffix_massage[i+src].bv_len;
int diff = tmpin.bv_len - aliasLength;
if ( diff < 0 ) {
/* alias is longer than dn */
continue;
} else if ( diff > 0 && ( !DN_SEPARATOR(tmpin.bv_val[diff-1])))
{
/* FIXME: DN_SEPARATOR() is intended to work
* on a normalized/pretty DN, so that ';'
* is never used as a DN separator */
continue;
/* At a DN Separator */
}
if ( !strcmp( dc->rwmap->rwm_suffix_massage[i+src].bv_val,
&tmpin.bv_val[diff] ) )
{
dn->bv_len = diff + dc->rwmap->rwm_suffix_massage[i+dst].bv_len;
dn->bv_val = ch_malloc( dn->bv_len + 1 );
strncpy( dn->bv_val, tmpin.bv_val, diff );
strcpy( &dn->bv_val[diff], dc->rwmap->rwm_suffix_massage[i+dst].bv_val );
Debug( LDAP_DEBUG_ARGS,
"rwm_dn_massage:"
" converted \"%s\" to \"%s\"\n",
in->bv_val, dn->bv_val, 0 );
break;
}
}
if ( tmpin.bv_val != in->bv_val ) {
ch_free( tmpin.bv_val );
}
/* Nothing matched, just return the original DN */
if ( BER_BVISNULL( dn ) ) {
*dn = *in;
}
return LDAP_SUCCESS;
}
#endif /* ! ENABLE_REWRITE */
#endif /* SLAPD_OVER_RWM */
......@@ -403,9 +403,7 @@ map_attr_value(
dncookie fdc = *dc;
int rc;
#ifdef ENABLE_REWRITE
fdc.ctx = "searchFilterAttrDN";
#endif /* ENABLE_REWRITE */
vtmp = *value;
rc = rwm_dn_massage_normalize( &fdc, value, &vtmp );
......@@ -751,7 +749,6 @@ rwm_filter_map_rewrite(
rc = rwm_int_filter_map_rewrite( op, dc, f, fstr );
#ifdef ENABLE_REWRITE
if ( rc != 0 ) {
return rc;
}
......@@ -798,7 +795,6 @@ rwm_filter_map_rewrite(
rc = LDAP_OTHER;
break;
}
#endif /* ENABLE_REWRITE */
return rc;
}
......@@ -834,14 +830,9 @@ rwm_referral_rewrite(
* Rewrite the dn if needed
*/
dc.rwmap = rwmap;
#ifdef ENABLE_REWRITE
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = (char *)cookie;
#else /* ! ENABLE_REWRITE */
dc.tofrom = ((int *)cookie)[0];
dc.normalized = 0;
#endif /* ! ENABLE_REWRITE */
for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
;
......@@ -1007,14 +998,9 @@ rwm_dnattr_rewrite(
* Rewrite the dn if needed
*/
dc.rwmap = rwmap;
#ifdef ENABLE_REWRITE
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = (char *)cookie;
#else /* ! ENABLE_REWRITE */
dc.tofrom = ((int *)cookie)[0];
dc.normalized = 0;
#endif /* ! ENABLE_REWRITE */
for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
last--;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment