phonetic.c acl.c str2filter.c aclparse.c init.c user.c \
repl.c lock.c controls.c extended.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 \
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 \
phonetic.o acl.o str2filter.o aclparse.o init.o user.o \
repl.o lock.o controls.o extended.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_LIBDIR= ../../libraries
/* alias suffix */
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 ) {
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
return 1;
}
+ /* deref suffix alias if appropriate */
+ ndn = suffix_alias( be, ndn );
+
if ( be->be_compare ) {
(*be->be_compare)( be, conn, op, ndn, &ava );
} else {
/* set database suffix */
} else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
+ Backend *tmp_be;
if ( cargc < 2 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing dn in \"suffix <dn>\" line\n",
Debug( LDAP_DEBUG_ANY,
"%s: line %d: suffix line must appear inside a database definition (ignored)\n",
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 {
char *dn = ch_strdup( cargv[1] );
(void) dn_normalize( 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 */
} else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
int i;
return rc;
}
+ /* deref suffix alias if appropriate */
+ ndn = suffix_alias( be, ndn );
+
/*
* do the delete if 1 && (2 || 3)
* 1) there is a delete function implemented in this backend;
return rc;
}
+ /* deref suffix alias if appropriate */
+ ndn = suffix_alias( be, ndn );
+
/*
* do the modify if 1 && (2 || 3)
* 1) there is a modify function implemented in this backend;
return rc;
}
-
/* Make sure that the entry being changed and the newSuperior are in
* the same backend, otherwise we return an error.
*/
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)
* 1) there is an add function implemented in this backend;
Filter * str2filter LDAP_P(( char *str ));
+/*
+ * suffixalias.c
+ */
+char *suffix_alias LDAP_P(( Backend *be, char *ndn ));
+
/*
* value.c
*/
goto return_results;
}
+ /* deref the base if needed */
+ base = suffix_alias( be, base );
+
/* actually do the search and send the result(s) */
if ( be->be_search ) {
(*be->be_search)( be, conn, op, base, scope, deref, sizelimit,
/* these should be renamed from be_ to bd_ */
char **be_suffix; /* the DN suffixes of data 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_ndn; /* the magic "root" normalized dn for this db */
char *be_root_pw; /* the magic "root" password for this db */
--- /dev/null
+/*
+ * 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;
+}