1999-05-26 10:35:20 +08:00
|
|
|
/* config.c - ldap backend configuration file routine */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2001-01-17 15:09:22 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
2001-01-17 15:09:22 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
/* This is an altered version */
|
1999-05-26 10:35:20 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose
|
|
|
|
* on any computer system, and to alter it and redistribute it, subject
|
|
|
|
* to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The author is not responsible for the consequences of use of this
|
|
|
|
* software, no matter how awful, even if they arise from flaws in it.
|
|
|
|
*
|
|
|
|
* 2. The origin of this software must not be misrepresented, either by
|
|
|
|
* explicit claim or by omission. Since few users ever read sources,
|
|
|
|
* credits should appear in the documentation.
|
|
|
|
*
|
|
|
|
* 3. Altered versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software. Since few users
|
|
|
|
* ever read sources, credits should appear in the documentation.
|
|
|
|
*
|
|
|
|
* 4. This notice may not be removed or altered.
|
2001-01-20 05:27:20 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
|
|
|
|
*
|
|
|
|
* This software is being modified by Pierangelo Masarati.
|
|
|
|
* The previously reported conditions apply to the modified code as well.
|
|
|
|
* Changes in the original code are highlighted where required.
|
|
|
|
* Credits for the original code go to the author, Howard Chu.
|
1999-05-26 10:35:20 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldap.h"
|
2002-08-06 10:36:34 +08:00
|
|
|
#include "lutil.h"
|
1999-05-26 10:35:20 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldap_back_db_config(
|
|
|
|
BackendDB *be,
|
1999-08-21 03:29:43 +08:00
|
|
|
const char *fname,
|
1999-05-26 10:35:20 +08:00
|
|
|
int lineno,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
|
|
|
|
|
|
|
|
if ( li == NULL ) {
|
|
|
|
fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
2000-06-05 12:59:26 +08:00
|
|
|
/* server address to query (depricated, use "uri" directive) */
|
1999-05-26 10:35:20 +08:00
|
|
|
if ( strcasecmp( argv[0], "server" ) == 0 ) {
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing address in \"server <address>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
2000-06-05 12:59:26 +08:00
|
|
|
if (li->url != NULL)
|
|
|
|
ch_free(li->url);
|
|
|
|
li->url = ch_calloc(strlen(argv[1]) + 9, sizeof(char));
|
|
|
|
if (li->url != NULL) {
|
|
|
|
strcpy(li->url, "ldap://");
|
|
|
|
strcat(li->url, argv[1]);
|
|
|
|
strcat(li->url, "/");
|
1999-05-26 10:35:20 +08:00
|
|
|
}
|
2000-06-05 12:59:26 +08:00
|
|
|
|
|
|
|
/* URI of server to query (preferred over "server" directive) */
|
|
|
|
} else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing address in \"uri <address>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
if (li->url != NULL)
|
|
|
|
ch_free(li->url);
|
|
|
|
li->url = ch_strdup(argv[1]);
|
|
|
|
|
|
|
|
/* name to use for ldap_back_group */
|
|
|
|
} else if ( strcasecmp( argv[0], "binddn" ) == 0 ) {
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing name in \"binddn <name>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
li->binddn = ch_strdup(argv[1]);
|
|
|
|
|
|
|
|
/* password to use for ldap_back_group */
|
|
|
|
} else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing password in \"bindpw <password>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
li->bindpw = ch_strdup(argv[1]);
|
2001-01-20 05:27:20 +08:00
|
|
|
|
2002-04-25 10:05:34 +08:00
|
|
|
/* save bind creds for referral rebinds? */
|
|
|
|
} else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
|
|
|
|
if (argc != 1) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: rebind-as-user takes no arguments\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
li->savecred = 1;
|
|
|
|
|
2001-01-20 05:27:20 +08:00
|
|
|
/* dn massaging */
|
|
|
|
} else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
|
|
|
|
BackendDB *tmp_be;
|
2002-05-02 03:05:09 +08:00
|
|
|
struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
|
2002-05-02 01:45:03 +08:00
|
|
|
#ifdef ENABLE_REWRITE
|
2002-05-01 19:41:57 +08:00
|
|
|
int rc;
|
2002-05-02 01:45:03 +08:00
|
|
|
#endif /* ENABLE_REWRITE */
|
2001-01-20 05:27:20 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* syntax:
|
|
|
|
*
|
|
|
|
* suffixmassage <suffix> <massaged suffix>
|
|
|
|
*
|
|
|
|
* the <suffix> field must be defined as a valid suffix
|
|
|
|
* (or suffixAlias?) for the current database;
|
|
|
|
* the <massaged suffix> shouldn't have already been
|
|
|
|
* defined as a valid suffix or suffixAlias for the
|
|
|
|
* current server
|
|
|
|
*/
|
2001-01-20 05:27:20 +08:00
|
|
|
if ( argc != 3 ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
fprintf( stderr, "%s: line %d: syntax is"
|
|
|
|
" \"suffixMassage <suffix>"
|
|
|
|
" <massaged suffix>\"\n",
|
2001-01-20 05:27:20 +08:00
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
2002-05-01 19:41:57 +08:00
|
|
|
ber_str2bv( argv[1], 0, 0, &bvnc );
|
2002-05-02 03:05:09 +08:00
|
|
|
if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc ) != LDAP_SUCCESS ) {
|
2001-12-26 17:19:57 +08:00
|
|
|
fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
|
2002-05-01 19:41:57 +08:00
|
|
|
fname, lineno, bvnc.bv_val );
|
2001-12-26 17:19:57 +08:00
|
|
|
return( 1 );
|
|
|
|
}
|
2002-05-02 03:05:09 +08:00
|
|
|
tmp_be = select_backend( &nvnc, 0, 0 );
|
2001-01-20 05:27:20 +08:00
|
|
|
if ( tmp_be != NULL && tmp_be != be ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
fprintf( stderr, "%s: line %d: suffix already in use"
|
|
|
|
" by another backend in"
|
|
|
|
" \"suffixMassage <suffix>"
|
|
|
|
" <massaged suffix>\"\n",
|
2001-01-20 05:27:20 +08:00
|
|
|
fname, lineno );
|
2002-05-02 03:05:09 +08:00
|
|
|
free( nvnc.bv_val );
|
|
|
|
free( pvnc.bv_val );
|
2002-05-01 19:41:57 +08:00
|
|
|
return( 1 );
|
2001-01-20 05:27:20 +08:00
|
|
|
}
|
|
|
|
|
2002-05-01 19:41:57 +08:00
|
|
|
ber_str2bv( argv[2], 0, 0, &brnc );
|
2002-05-02 03:05:09 +08:00
|
|
|
if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc ) != LDAP_SUCCESS ) {
|
2001-12-26 17:19:57 +08:00
|
|
|
fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
|
2002-05-01 19:41:57 +08:00
|
|
|
fname, lineno, brnc.bv_val );
|
2002-05-02 03:05:09 +08:00
|
|
|
free( nvnc.bv_val );
|
|
|
|
free( pvnc.bv_val );
|
2001-12-26 17:19:57 +08:00
|
|
|
return( 1 );
|
|
|
|
}
|
2002-05-01 19:41:57 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
tmp_be = select_backend( &nrnc, 0, 0 );
|
2001-01-20 05:27:20 +08:00
|
|
|
if ( tmp_be != NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
fprintf( stderr, "%s: line %d: massaged suffix"
|
|
|
|
" already in use by another backend in"
|
|
|
|
" \"suffixMassage <suffix>"
|
|
|
|
" <massaged suffix>\"\n",
|
2001-01-20 05:27:20 +08:00
|
|
|
fname, lineno );
|
2002-05-02 03:05:09 +08:00
|
|
|
free( nvnc.bv_val );
|
|
|
|
free( pvnc.bv_val );
|
|
|
|
free( nrnc.bv_val );
|
|
|
|
free( prnc.bv_val );
|
2001-01-20 05:27:20 +08:00
|
|
|
return( 1 );
|
|
|
|
}
|
2002-05-01 19:41:57 +08:00
|
|
|
#endif
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_REWRITE
|
|
|
|
/*
|
|
|
|
* The suffix massaging is emulated by means of the
|
|
|
|
* rewrite capabilities
|
|
|
|
* FIXME: no extra rewrite capabilities should be added
|
|
|
|
* to the database
|
|
|
|
*/
|
2002-05-02 03:05:09 +08:00
|
|
|
rc = suffix_massage_config( li->rwinfo, &pvnc, &nvnc, &prnc, &nrnc );
|
|
|
|
free( nvnc.bv_val );
|
|
|
|
free( pvnc.bv_val );
|
|
|
|
free( nrnc.bv_val );
|
|
|
|
free( prnc.bv_val );
|
2002-05-01 19:41:57 +08:00
|
|
|
|
|
|
|
return( rc );
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
#else /* !ENABLE_REWRITE */
|
2002-05-02 03:05:09 +08:00
|
|
|
ber_bvarray_add( &li->suffix_massage, &pvnc );
|
|
|
|
ber_bvarray_add( &li->suffix_massage, &nvnc );
|
2001-01-20 05:27:20 +08:00
|
|
|
|
2002-05-02 03:05:09 +08:00
|
|
|
ber_bvarray_add( &li->suffix_massage, &prnc );
|
|
|
|
ber_bvarray_add( &li->suffix_massage, &nrnc );
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* !ENABLE_REWRITE */
|
2000-06-05 12:59:26 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/* rewrite stuff ... */
|
|
|
|
} else if ( strncasecmp( argv[0], "rewrite", 7 ) == 0 ) {
|
2002-05-01 19:41:57 +08:00
|
|
|
#ifdef ENABLE_REWRITE
|
2001-05-12 08:51:28 +08:00
|
|
|
return rewrite_parse( li->rwinfo, fname, lineno, argc, argv );
|
2002-05-01 19:41:57 +08:00
|
|
|
|
|
|
|
#else /* !ENABLE_REWRITE */
|
|
|
|
fprintf( stderr, "%s: line %d: rewrite capabilities "
|
|
|
|
"are not enabled\n", fname, lineno );
|
|
|
|
#endif /* !ENABLE_REWRITE */
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2001-02-20 03:14:12 +08:00
|
|
|
/* objectclass/attribute mapping */
|
|
|
|
} else if ( strcasecmp( argv[0], "map" ) == 0 ) {
|
|
|
|
struct ldapmap *map;
|
|
|
|
struct ldapmapping *mapping;
|
|
|
|
char *src, *dst;
|
|
|
|
|
|
|
|
if ( argc < 3 || argc > 4 ) {
|
|
|
|
fprintf( stderr,
|
2002-06-13 00:39:05 +08:00
|
|
|
"%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
|
2001-02-20 03:14:12 +08:00
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
|
|
|
|
map = &li->oc_map;
|
|
|
|
} else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
|
|
|
|
map = &li->at_map;
|
|
|
|
} else {
|
2002-01-03 00:58:37 +08:00
|
|
|
fprintf( stderr, "%s: line %d: syntax is "
|
2002-06-13 00:39:05 +08:00
|
|
|
"\"map {objectclass | attribute} [<local> | *] "
|
|
|
|
"{<foreign> | *}\"\n",
|
2001-02-20 03:14:12 +08:00
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
2002-06-13 00:39:05 +08:00
|
|
|
if ( strcmp( argv[2], "*" ) == 0 ) {
|
|
|
|
if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
|
|
|
|
map->drop_missing = ( argc < 4 );
|
2001-02-20 03:14:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2002-06-13 00:39:05 +08:00
|
|
|
src = dst = argv[3];
|
|
|
|
} else if ( argc < 4 ) {
|
|
|
|
src = "";
|
|
|
|
dst = argv[2];
|
|
|
|
} else {
|
|
|
|
src = argv[2];
|
|
|
|
dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
|
2001-02-20 03:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( map == &li->at_map )
|
|
|
|
&& ( strcasecmp( src, "objectclass" ) == 0
|
|
|
|
|| strcasecmp( dst, "objectclass" ) == 0 ) )
|
|
|
|
{
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: objectclass attribute cannot be mapped\n",
|
|
|
|
fname, lineno );
|
|
|
|
}
|
|
|
|
|
2002-01-03 00:58:37 +08:00
|
|
|
mapping = (struct ldapmapping *)ch_calloc( 2,
|
|
|
|
sizeof(struct ldapmapping) );
|
2001-02-20 03:14:12 +08:00
|
|
|
if ( mapping == NULL ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: out of memory\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
2002-01-02 19:00:36 +08:00
|
|
|
ber_str2bv( src, 0, 1, &mapping->src );
|
|
|
|
ber_str2bv( dst, 0, 1, &mapping->dst );
|
2002-06-13 00:39:05 +08:00
|
|
|
mapping[1].src = mapping->dst;
|
|
|
|
mapping[1].dst = mapping->src;
|
2001-02-20 03:14:12 +08:00
|
|
|
|
2002-06-13 00:39:05 +08:00
|
|
|
if ( (*src != '\0' &&
|
|
|
|
avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL) ||
|
2002-01-03 00:58:37 +08:00
|
|
|
avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
|
2001-02-20 03:14:12 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: duplicate mapping found (ignored)\n",
|
|
|
|
fname, lineno );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-13 00:39:05 +08:00
|
|
|
if ( *src != '\0' )
|
|
|
|
avl_insert( &map->map, (caddr_t)mapping,
|
|
|
|
mapping_cmp, mapping_dup );
|
2001-02-20 03:14:12 +08:00
|
|
|
avl_insert( &map->remap, (caddr_t)&mapping[1],
|
|
|
|
mapping_cmp, mapping_dup );
|
|
|
|
|
1999-05-26 10:35:20 +08:00
|
|
|
/* anything else */
|
|
|
|
} else {
|
2002-01-03 00:58:37 +08:00
|
|
|
fprintf( stderr, "%s: line %d: unknown directive \"%s\" "
|
|
|
|
"in ldap database definition (ignored)\n",
|
1999-05-26 10:35:20 +08:00
|
|
|
fname, lineno, argv[0] );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-20 03:14:12 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
#ifdef ENABLE_REWRITE
|
|
|
|
static char *
|
|
|
|
suffix_massage_regexize( const char *s )
|
|
|
|
{
|
2002-04-08 17:43:22 +08:00
|
|
|
char *res, *ptr;
|
|
|
|
const char *p, *r;
|
2001-05-12 08:51:28 +08:00
|
|
|
int i;
|
|
|
|
|
2002-04-08 17:43:22 +08:00
|
|
|
for ( i = 0, p = s;
|
2001-05-12 08:51:28 +08:00
|
|
|
( r = strchr( p, ',' ) ) != NULL;
|
|
|
|
p = r + 1, i++ )
|
|
|
|
;
|
|
|
|
|
|
|
|
res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
|
|
|
|
|
2002-07-27 08:24:02 +08:00
|
|
|
ptr = lutil_strcopy( res, "(.*)" );
|
2002-04-08 17:43:22 +08:00
|
|
|
for ( i = 0, p = s;
|
2001-05-12 08:51:28 +08:00
|
|
|
( r = strchr( p, ',' ) ) != NULL;
|
|
|
|
p = r + 1 , i++ ) {
|
2002-07-27 08:24:02 +08:00
|
|
|
ptr = lutil_strncopy( ptr, p, r - p + 1 );
|
|
|
|
ptr = lutil_strcopy( ptr, "[ ]?" );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
if ( r[ 1 ] == ' ' ) {
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
}
|
2002-07-27 08:24:02 +08:00
|
|
|
lutil_strcopy( ptr, p );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2002-05-01 19:41:57 +08:00
|
|
|
suffix_massage_patternize( const char *s )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2002-05-01 19:41:57 +08:00
|
|
|
ber_len_t len;
|
2002-01-13 00:04:15 +08:00
|
|
|
char *res;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-05-01 19:41:57 +08:00
|
|
|
len = strlen( s );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-05-01 19:41:57 +08:00
|
|
|
res = ch_calloc( sizeof( char ), len + sizeof( "%1" ) );
|
2002-01-13 00:04:15 +08:00
|
|
|
if ( res == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy( res, "%1" );
|
2002-05-01 19:41:57 +08:00
|
|
|
strcpy( res + sizeof( "%1" ) - 1, s );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
suffix_massage_config(
|
|
|
|
struct rewrite_info *info,
|
2002-05-01 19:41:57 +08:00
|
|
|
struct berval *pvnc,
|
|
|
|
struct berval *nvnc,
|
|
|
|
struct berval *prnc,
|
|
|
|
struct berval *nrnc
|
2001-05-12 08:51:28 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
char *rargv[ 5 ];
|
2002-05-01 19:41:57 +08:00
|
|
|
int line = 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteEngine";
|
|
|
|
rargv[ 1 ] = "on";
|
|
|
|
rargv[ 2 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteContext";
|
|
|
|
rargv[ 1 ] = "default";
|
|
|
|
rargv[ 2 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteRule";
|
2002-05-01 19:41:57 +08:00
|
|
|
rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
|
|
|
|
rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
rargv[ 3 ] = ":";
|
|
|
|
rargv[ 4 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
ch_free( rargv[ 1 ] );
|
|
|
|
ch_free( rargv[ 2 ] );
|
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteContext";
|
|
|
|
rargv[ 1 ] = "searchResult";
|
|
|
|
rargv[ 2 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteRule";
|
2002-05-01 19:41:57 +08:00
|
|
|
rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
|
|
|
|
rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
rargv[ 3 ] = ":";
|
|
|
|
rargv[ 4 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
ch_free( rargv[ 1 ] );
|
|
|
|
ch_free( rargv[ 2 ] );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the filter should be rewritten as
|
|
|
|
*
|
|
|
|
* rewriteRule
|
|
|
|
* "(.*)member=([^)]+),o=Foo Bar,[ ]?c=US(.*)"
|
|
|
|
* "%1member=%2,dc=example,dc=com%3"
|
|
|
|
*
|
|
|
|
* where "o=Foo Bar, c=US" is the virtual naming context,
|
|
|
|
* and "dc=example, dc=com" is the real naming context
|
|
|
|
*/
|
|
|
|
rargv[ 0 ] = "rewriteContext";
|
|
|
|
rargv[ 1 ] = "searchFilter";
|
|
|
|
rargv[ 2 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
|
|
|
|
|
|
|
|
#if 1 /* rewrite filters */
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Note: this is far more optimistic than desirable:
|
|
|
|
* for any AVA value ending with the virtual naming
|
|
|
|
* context the terminal part will be replaced by the
|
|
|
|
* real naming context; a better solution would be to
|
|
|
|
* walk the filter looking for DN-valued attributes,
|
|
|
|
* and only rewrite those that require rewriting
|
|
|
|
*/
|
2002-08-09 21:51:35 +08:00
|
|
|
char vbuf_[BUFSIZ], *vbuf = vbuf_,
|
|
|
|
rbuf_[BUFSIZ], *rbuf = rbuf_;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf( vbuf, sizeof( vbuf_ ),
|
|
|
|
"(.*)%s\\)(.*)", nvnc->bv_val );
|
|
|
|
if ( len == -1 ) {
|
|
|
|
/*
|
|
|
|
* traditional behavior: snprintf returns -1
|
|
|
|
* if buffer is insufficient
|
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
|
2003-01-19 23:03:25 +08:00
|
|
|
} else if ( len >= (int)sizeof( vbuf_ ) ) {
|
2002-08-09 21:51:35 +08:00
|
|
|
/*
|
|
|
|
* C99: snprintf returns the required size
|
|
|
|
*/
|
|
|
|
vbuf = ch_malloc( len + 1 );
|
|
|
|
len = snprintf( vbuf, len,
|
|
|
|
"(.*)%s\\)(.*)", nvnc->bv_val );
|
|
|
|
assert( len > 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2",
|
|
|
|
nrnc->bv_val );
|
|
|
|
if ( len == -1 ) {
|
|
|
|
return -1;
|
2002-05-01 19:41:57 +08:00
|
|
|
|
2003-01-19 23:03:25 +08:00
|
|
|
} else if ( len >= (int)sizeof( rbuf_ ) ) {
|
2002-08-09 21:51:35 +08:00
|
|
|
rbuf = ch_malloc( len + 1 );
|
|
|
|
len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2",
|
|
|
|
nrnc->bv_val );
|
|
|
|
assert( len > 0 );
|
|
|
|
}
|
2002-05-01 19:41:57 +08:00
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteRule";
|
|
|
|
rargv[ 1 ] = vbuf;
|
|
|
|
rargv[ 2 ] = rbuf;
|
|
|
|
rargv[ 3 ] = ":";
|
|
|
|
rargv[ 4 ] = NULL;
|
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
|
2002-08-09 21:51:35 +08:00
|
|
|
|
|
|
|
if ( vbuf != vbuf_ ) {
|
|
|
|
ch_free( vbuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rbuf != rbuf_ ) {
|
|
|
|
ch_free( rbuf );
|
|
|
|
}
|
2002-05-01 19:41:57 +08:00
|
|
|
}
|
|
|
|
#endif /* rewrite filters */
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-05-01 19:41:57 +08:00
|
|
|
#if 0 /* "matched" is not normalized */
|
2001-05-12 08:51:28 +08:00
|
|
|
rargv[ 0 ] = "rewriteContext";
|
|
|
|
rargv[ 1 ] = "matchedDn";
|
|
|
|
rargv[ 2 ] = "alias";
|
|
|
|
rargv[ 3 ] = "searchResult";
|
|
|
|
rargv[ 4 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
|
|
|
|
#else /* normalize "matched" */
|
2001-05-12 08:51:28 +08:00
|
|
|
rargv[ 0 ] = "rewriteContext";
|
|
|
|
rargv[ 1 ] = "matchedDn";
|
|
|
|
rargv[ 2 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
rargv[ 0 ] = "rewriteRule";
|
2002-05-01 19:41:57 +08:00
|
|
|
rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
|
|
|
|
rargv[ 2 ] = suffix_massage_patternize( nvnc->bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
rargv[ 3 ] = ":";
|
|
|
|
rargv[ 4 ] = NULL;
|
2002-05-01 19:41:57 +08:00
|
|
|
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
|
2001-05-12 08:51:28 +08:00
|
|
|
ch_free( rargv[ 1 ] );
|
|
|
|
ch_free( rargv[ 2 ] );
|
2002-05-01 19:41:57 +08:00
|
|
|
#endif /* normalize "matched" */
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_REWRITE */
|