/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2003-2008 The OpenLDAP Foundation.
+ * Copyright 2003-2009 The OpenLDAP Foundation.
* Portions Copyright 2003 Pierangelo Masarati.
* All rights reserved.
*
enum {
/* rewrite */
RWM_CF_REWRITE = 1,
- RWM_CF_SUFFIXMASSAGE,
/* map */
RWM_CF_MAP,
};
static slap_verbmasks t_f_mode[] = {
+ { BER_BVC( "true" ), RWM_F_SUPPORT_T_F },
{ BER_BVC( "yes" ), RWM_F_SUPPORT_T_F },
{ BER_BVC( "discover" ), RWM_F_SUPPORT_T_F_DISCOVER },
+ { BER_BVC( "false" ), RWM_F_NONE },
{ BER_BVC( "no" ), RWM_F_NONE },
{ BER_BVNULL, 0 }
};
static ConfigTable rwmcfg[] = {
{ "rwm-rewrite", "rewrite",
2, 0, STRLENOF("rwm-rewrite"),
- ARG_MAGIC|ARG_QUOTE|RWM_CF_REWRITE, rwm_cf_gen,
+ ARG_MAGIC|RWM_CF_REWRITE, rwm_cf_gen,
"( OLcfgOvAt:16.1 NAME 'olcRwmRewrite' "
"DESC 'Rewrites strings' "
"EQUALITY caseIgnoreMatch "
NULL, NULL },
{ "rwm-suffixmassage", "[virtual]> <real",
- 2, 3, 0, ARG_MAGIC|RWM_CF_SUFFIXMASSAGE, rwm_cf_gen,
+ 2, 3, 0, ARG_MAGIC|RWM_CF_REWRITE, rwm_cf_gen,
NULL, NULL, NULL },
{ "rwm-t-f-support", "true|false|discover",
*out = bva;
}
+static int
+rwm_bva_rewrite_add(
+ struct ldaprwmap *rwmap,
+ const char *argv[] )
+{
+ char *line;
+ struct berval bv;
+
+ line = ldap_charray2str( argv, "\" \"" );
+ if ( line != NULL ) {
+ int len = strlen( argv[ 0 ] );
+
+ ber_str2bv( line, 0, 0, &bv );
+ AC_MEMCPY( &bv.bv_val[ len ], &bv.bv_val[ len + 1 ],
+ bv.bv_len - ( len + 1 ) );
+ bv.bv_val[ bv.bv_len - 1 ] = '"';
+ ber_bvarray_add( &rwmap->rwm_bva_rewrite, &bv );
+ }
+
+ return 0;
+}
+
+static int
+rwm_info_init( struct ldaprwmap *rwmap )
+{
+ char *rargv[ 3 ];
+
+ rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
+ if ( rwmap->rwm_rw == NULL ) {
+ return -1;
+ }
+
+ /* this rewriteContext by default must be null;
+ * rules can be added if required */
+ rargv[ 0 ] = "rewriteContext";
+ rargv[ 1 ] = "searchFilter";
+ rargv[ 2 ] = NULL;
+ rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
+
+ rargv[ 0 ] = "rewriteContext";
+ rargv[ 1 ] = "default";
+ rargv[ 2 ] = NULL;
+ rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
+
+ return 0;
+}
+
static int
rwm_cf_gen( ConfigArgs *c )
{
BackendDB db;
char *argv0;
+ int idx0 = 0;
int rc = 0;
db = *c->be;
switch ( c->type ) {
case RWM_CF_REWRITE:
if ( c->valx >= 0 ) {
- /* single modification is not allowed */
rc = 1;
} else if ( rwmap->rwm_rw != NULL ) {
ber_bvarray_free( rwmap->rwm_bva_rewrite );
rwmap->rwm_bva_rewrite = NULL;
+
+ rc = rwm_info_init( rwmap );
}
break;
return rc;
}
+ if ( strncasecmp( c->argv[ 0 ], "olcRwm", STRLENOF( "olcRwm" ) ) == 0 ) {
+ idx0 = 1;
+ }
+
switch ( c->type ) {
case RWM_CF_REWRITE:
- argv0 = c->argv[ 0 ];
- c->argv[ 0 ] += STRLENOF( "rwm-" );
- rc = rwm_rw_config( &db, c->fname, c->lineno, c->argc, c->argv );
- c->argv[ 0 ] = argv0;
- if ( rc ) {
+ if ( c->valx >= 0 ) {
return 1;
+ }
- } else {
- char *line;
- struct berval bv;
-
- line = ldap_charray2str( c->argv, "\" \"" );
- if ( line != NULL ) {
- int len = strlen( c->argv[ 0 ] );
-
- ber_str2bv( line, 0, 0, &bv );
- AC_MEMCPY( &bv.bv_val[ len ], &bv.bv_val[ len + 1 ],
- bv.bv_len - ( len + 1 ) );
- bv.bv_val[ bv.bv_len - 1 ] = '"';
- ber_bvarray_add( &rwmap->rwm_bva_rewrite, &bv );
- }
+ argv0 = c->argv[ idx0 ];
+ if ( strncasecmp( argv0, "rwm-", STRLENOF( "rwm-" ) ) != 0 ) {
+ return 1;
}
- break;
+ c->argv[ idx0 ] += STRLENOF( "rwm-" );
+ if ( strcasecmp( c->argv[ idx0 ], "suffixmassage" ) == 0 ) {
+ rc = rwm_suffixmassage_config( &db, c->fname, c->lineno,
+ c->argc - idx0, &c->argv[ idx0 ] );
- case RWM_CF_SUFFIXMASSAGE:
- argv0 = c->argv[ 0 ];
- c->argv[ 0 ] += STRLENOF( "rwm-" );
- rc = rwm_suffixmassage_config( &db, c->fname, c->lineno, c->argc, c->argv );
- c->argv[ 0 ] = argv0;
+ } else {
+ rc = rwm_rw_config( &db, c->fname, c->lineno,
+ c->argc - idx0, &c->argv[ idx0 ] );
+ }
+ c->argv[ idx0 ] = argv0;
if ( rc ) {
return 1;
} else {
- char *line;
- struct berval bv;
-
- /* FIXME: not optimal; in fact, this keeps track
- * of the fact that a set of rules was added
- * using the rwm-suffixmassage shortcut, but the
- * rules are not clarified */
-
- line = ldap_charray2str( c->argv, "\" \"" );
- if ( line != NULL ) {
- int len = strlen( c->argv[ 0 ] );
-
- ber_str2bv( line, 0, 0, &bv );
- AC_MEMCPY( &bv.bv_val[ len ], &bv.bv_val[ len + 1 ],
- bv.bv_len - ( len + 1 ) );
- bv.bv_val[ bv.bv_len - 1 ] = '"';
- ber_bvarray_add( &rwmap->rwm_bva_rewrite, &bv );
- }
+ rwm_bva_rewrite_add( rwmap, &c->argv[ idx0 ] );
}
break;
break;
case RWM_CF_MAP:
+ if ( c->valx >= 0 ) {
+ return 1;
+ }
+
argv0 = c->argv[ 0 ];
c->argv[ 0 ] += STRLENOF( "rwm-" );
rc = rwm_m_config( &db, c->fname, c->lineno, c->argc, c->argv );
{
slap_overinst *on = (slap_overinst *) be->bd_info;
struct ldaprwmap *rwmap;
- char *rargv[ 3 ];
int rc = 0;
rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
- rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
- if ( rwmap->rwm_rw == NULL ) {
- rc = -1;
- goto error_return;
- }
-
- /* this rewriteContext by default must be null;
- * rules can be added if required */
- rargv[ 0 ] = "rewriteContext";
- rargv[ 1 ] = "searchFilter";
- rargv[ 2 ] = NULL;
- rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
-
- rargv[ 0 ] = "rewriteContext";
- rargv[ 1 ] = "default";
- rargv[ 2 ] = NULL;
- rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
+ rc = rwm_info_init( rwmap );
error_return:;
on->on_bi.bi_private = (void *)rwmap;