mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
Resurrect suffix aliasing...
This commit is contained in:
parent
67cdcb8df9
commit
c12547cf3b
@ -11,7 +11,7 @@ SRCS = main.c daemon.c connection.c search.c filter.c add.c charray.c \
|
|||||||
phonetic.c acl.c str2filter.c aclparse.c init.c user.c \
|
phonetic.c acl.c str2filter.c aclparse.c init.c user.c \
|
||||||
repl.c lock.c controls.c extended.c \
|
repl.c lock.c controls.c extended.c \
|
||||||
schema.c schemaparse.c monitor.c configinfo.c \
|
schema.c schemaparse.c monitor.c configinfo.c \
|
||||||
root_dse.c module.c
|
root_dse.c module.c suffixalias.c
|
||||||
OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \
|
OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \
|
||||||
attr.o entry.o config.o backend.o result.o operation.o \
|
attr.o entry.o config.o backend.o result.o operation.o \
|
||||||
dn.o compare.o modify.o delete.o modrdn.o ch_malloc.o \
|
dn.o compare.o modify.o delete.o modrdn.o ch_malloc.o \
|
||||||
@ -19,7 +19,7 @@ OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \
|
|||||||
phonetic.o acl.o str2filter.o aclparse.o init.o user.o \
|
phonetic.o acl.o str2filter.o aclparse.o init.o user.o \
|
||||||
repl.o lock.o controls.o extended.o \
|
repl.o lock.o controls.o extended.o \
|
||||||
schema.o schemaparse.o monitor.o configinfo.o \
|
schema.o schemaparse.o monitor.o configinfo.o \
|
||||||
root_dse.o module.o
|
root_dse.o module.o suffixalias.o
|
||||||
|
|
||||||
LDAP_INCDIR= ../../include
|
LDAP_INCDIR= ../../include
|
||||||
LDAP_LIBDIR= ../../libraries
|
LDAP_LIBDIR= ../../libraries
|
||||||
|
@ -281,6 +281,9 @@ do_bind(
|
|||||||
/* alias suffix */
|
/* alias suffix */
|
||||||
char *edn;
|
char *edn;
|
||||||
|
|
||||||
|
/* deref suffix alias if appropriate */
|
||||||
|
ndn = suffix_alias( be, ndn );
|
||||||
|
|
||||||
if ( (*be->be_bind)( be, conn, op, ndn, method, mech, &cred, &edn ) == 0 ) {
|
if ( (*be->be_bind)( be, conn, op, ndn, method, mech, &cred, &edn ) == 0 ) {
|
||||||
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
|
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
|
||||||
|
|
||||||
|
@ -97,6 +97,9 @@ do_compare(
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deref suffix alias if appropriate */
|
||||||
|
ndn = suffix_alias( be, ndn );
|
||||||
|
|
||||||
if ( be->be_compare ) {
|
if ( be->be_compare ) {
|
||||||
(*be->be_compare)( be, conn, op, ndn, &ava );
|
(*be->be_compare)( be, conn, op, ndn, &ava );
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,6 +204,7 @@ read_config( char *fname )
|
|||||||
|
|
||||||
/* set database suffix */
|
/* set database suffix */
|
||||||
} else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
|
} else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
|
||||||
|
Backend *tmp_be;
|
||||||
if ( cargc < 2 ) {
|
if ( cargc < 2 ) {
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"%s: line %d: missing dn in \"suffix <dn>\" line\n",
|
"%s: line %d: missing dn in \"suffix <dn>\" line\n",
|
||||||
@ -218,6 +219,14 @@ read_config( char *fname )
|
|||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"%s: line %d: suffix line must appear inside a database definition (ignored)\n",
|
"%s: line %d: suffix line must appear inside a database definition (ignored)\n",
|
||||||
fname, lineno, 0 );
|
fname, lineno, 0 );
|
||||||
|
} else if ( ( tmp_be = select_backend( cargv[1] ) ) == be ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: suffix already served by this backend (ignored)\n",
|
||||||
|
fname, lineno, 0 );
|
||||||
|
} else if ( tmp_be != NULL ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: suffix already served by a preceeding backend \"%s\" (ignored)\n",
|
||||||
|
fname, lineno, tmp_be->be_suffix[0] );
|
||||||
} else {
|
} else {
|
||||||
char *dn = ch_strdup( cargv[1] );
|
char *dn = ch_strdup( cargv[1] );
|
||||||
(void) dn_normalize( dn );
|
(void) dn_normalize( dn );
|
||||||
@ -227,6 +236,60 @@ read_config( char *fname )
|
|||||||
free( dn );
|
free( dn );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set database suffixAlias */
|
||||||
|
} else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
|
||||||
|
Backend *tmp_be;
|
||||||
|
if ( cargc < 2 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
|
||||||
|
fname, lineno, 0 );
|
||||||
|
return( 1 );
|
||||||
|
} else if ( cargc < 3 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
|
||||||
|
fname, lineno, 0 );
|
||||||
|
return( 1 );
|
||||||
|
} else if ( cargc > 3 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: extra cruft in suffixAlias line (ignored)\n",
|
||||||
|
fname, lineno, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( be == NULL ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: suffixAlias line"
|
||||||
|
" must appear inside a database definition (ignored)\n",
|
||||||
|
fname, lineno, 0 );
|
||||||
|
} else if ( (tmp_be = select_backend( cargv[1] )) != NULL ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: suffixAlias served by"
|
||||||
|
" a preceeding backend \"%s\" (ignored)\n",
|
||||||
|
fname, lineno, tmp_be->be_suffix[0] );
|
||||||
|
|
||||||
|
} else if ( (tmp_be = select_backend( cargv[2] )) != NULL ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"%s: line %d: suffixAlias derefs to differnet backend"
|
||||||
|
" a preceeding backend \"%s\" (ignored)\n",
|
||||||
|
fname, lineno, tmp_be->be_suffix[0] );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
char *alias, *aliased_dn;
|
||||||
|
|
||||||
|
alias = ch_strdup( cargv[1] );
|
||||||
|
(void) dn_normalize( alias );
|
||||||
|
|
||||||
|
aliased_dn = ch_strdup( cargv[2] );
|
||||||
|
(void) dn_normalize( aliased_dn );
|
||||||
|
|
||||||
|
(void) dn_normalize_case( alias );
|
||||||
|
(void) dn_normalize_case( aliased_dn );
|
||||||
|
charray_add( &be->be_suffixAlias, alias );
|
||||||
|
charray_add( &be->be_suffixAlias, aliased_dn );
|
||||||
|
|
||||||
|
free(alias);
|
||||||
|
free(aliased_dn);
|
||||||
|
}
|
||||||
|
|
||||||
/* set max deref depth */
|
/* set max deref depth */
|
||||||
} else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
|
} else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -81,6 +81,9 @@ do_delete(
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deref suffix alias if appropriate */
|
||||||
|
ndn = suffix_alias( be, ndn );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* do the delete if 1 && (2 || 3)
|
* do the delete if 1 && (2 || 3)
|
||||||
* 1) there is a delete function implemented in this backend;
|
* 1) there is a delete function implemented in this backend;
|
||||||
|
@ -172,6 +172,9 @@ do_modify(
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deref suffix alias if appropriate */
|
||||||
|
ndn = suffix_alias( be, ndn );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* do the modify if 1 && (2 || 3)
|
* do the modify if 1 && (2 || 3)
|
||||||
* 1) there is a modify function implemented in this backend;
|
* 1) there is a modify function implemented in this backend;
|
||||||
|
@ -187,7 +187,6 @@ do_modrdn(
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Make sure that the entry being changed and the newSuperior are in
|
/* Make sure that the entry being changed and the newSuperior are in
|
||||||
* the same backend, otherwise we return an error.
|
* the same backend, otherwise we return an error.
|
||||||
*/
|
*/
|
||||||
@ -208,8 +207,14 @@ do_modrdn(
|
|||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deref suffix alias if appropriate */
|
||||||
|
nnewSuperior = suffix_alias( be, nnewSuperior );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deref suffix alias if appropriate */
|
||||||
|
ndn = suffix_alias( be, ndn );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* do the add if 1 && (2 || 3)
|
* do the add if 1 && (2 || 3)
|
||||||
* 1) there is an add function implemented in this backend;
|
* 1) there is an add function implemented in this backend;
|
||||||
|
@ -350,6 +350,11 @@ char *scherr2str LDAP_P((int code));
|
|||||||
|
|
||||||
Filter * str2filter LDAP_P(( char *str ));
|
Filter * str2filter LDAP_P(( char *str ));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* suffixalias.c
|
||||||
|
*/
|
||||||
|
char *suffix_alias LDAP_P(( Backend *be, char *ndn ));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* value.c
|
* value.c
|
||||||
*/
|
*/
|
||||||
|
@ -200,6 +200,9 @@ do_search(
|
|||||||
goto return_results;
|
goto return_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* deref the base if needed */
|
||||||
|
base = suffix_alias( be, base );
|
||||||
|
|
||||||
/* actually do the search and send the result(s) */
|
/* actually do the search and send the result(s) */
|
||||||
if ( be->be_search ) {
|
if ( be->be_search ) {
|
||||||
(*be->be_search)( be, conn, op, base, scope, deref, sizelimit,
|
(*be->be_search)( be, conn, op, base, scope, deref, sizelimit,
|
||||||
|
@ -416,6 +416,7 @@ struct slap_backend_db {
|
|||||||
/* these should be renamed from be_ to bd_ */
|
/* these should be renamed from be_ to bd_ */
|
||||||
char **be_suffix; /* the DN suffixes of data in this backend */
|
char **be_suffix; /* the DN suffixes of data in this backend */
|
||||||
char **be_nsuffix; /* the normalized DN suffixes in this backend */
|
char **be_nsuffix; /* the normalized DN suffixes in this backend */
|
||||||
|
char **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
|
||||||
char *be_root_dn; /* the magic "root" dn for this db */
|
char *be_root_dn; /* the magic "root" dn for this db */
|
||||||
char *be_root_ndn; /* the magic "root" normalized dn for this db */
|
char *be_root_ndn; /* the magic "root" normalized dn for this db */
|
||||||
char *be_root_pw; /* the magic "root" password for this db */
|
char *be_root_pw; /* the magic "root" password for this db */
|
||||||
|
74
servers/slapd/suffixalias.c
Normal file
74
servers/slapd/suffixalias.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999 The OpenLDAP Foundation, All Rights Reserved.
|
||||||
|
*
|
||||||
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file in the top level
|
||||||
|
* directory of this package.
|
||||||
|
*/
|
||||||
|
/* Portions
|
||||||
|
* Copyright (c) 1998 Will Ballantyne, ITSD, Government of BC
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms are permitted
|
||||||
|
* provided that this notice is preserved and that due credit is given
|
||||||
|
* to ITSD, Government of BC. The name of ITSD
|
||||||
|
* may not be used to endorse or promote products derived from this
|
||||||
|
* software without specific prior written permission. This software
|
||||||
|
* is provided ``as is'' without express or implied warranty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "portable.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ac/string.h>
|
||||||
|
#include <ac/socket.h>
|
||||||
|
#include "slap.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* given a normalized uppercased dn (or root part),
|
||||||
|
* return an aliased dn if any of the alias suffixes match
|
||||||
|
*/
|
||||||
|
char *suffix_alias(
|
||||||
|
Backend *be,
|
||||||
|
char *dn )
|
||||||
|
{
|
||||||
|
int i, dnLength;
|
||||||
|
|
||||||
|
if(dn == NULL) return NULL;
|
||||||
|
if(be == NULL) return dn;
|
||||||
|
|
||||||
|
dnLength = strlen ( dn );
|
||||||
|
|
||||||
|
for ( i = 0;
|
||||||
|
be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
|
||||||
|
i += 2 )
|
||||||
|
{
|
||||||
|
int aliasLength = strlen (be->be_suffixAlias[i]);
|
||||||
|
int diff = dnLength - aliasLength;
|
||||||
|
|
||||||
|
if ( diff < 0 ) {
|
||||||
|
/* alias is longer than dn */
|
||||||
|
continue;
|
||||||
|
} else if ( diff > 0 ) {
|
||||||
|
if ( ! DNSEPARATOR(dn[diff-1]) ) {
|
||||||
|
/* boundary is not at a DN separator */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* At a DN Separator */
|
||||||
|
/* XXX or an escaped separator... oh well */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(be->be_suffixAlias[i], &dn[diff])) {
|
||||||
|
char *oldDN = dn;
|
||||||
|
dn = ch_malloc( diff + strlen(be->be_suffixAlias[i+1]) + 1 );
|
||||||
|
strncpy( dn, oldDN, diff );
|
||||||
|
strcpy( &dn[diff], be->be_suffixAlias[i+1] );
|
||||||
|
Debug( LDAP_DEBUG_ARGS,
|
||||||
|
"suffix_alias: converted \"%s\" to \"%s\"\n",
|
||||||
|
oldDN, dn, 0);
|
||||||
|
free (oldDN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dn;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user