]> git.sur5r.net Git - openldap/commitdiff
Added Will Ballantyne's General Aliasing code.
authorKurt Zeilenga <kurt@openldap.org>
Sat, 24 Oct 1998 02:42:38 +0000 (02:42 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sat, 24 Oct 1998 02:42:38 +0000 (02:42 +0000)
Not quite sure if the entry lock handling is correct yet.

13 files changed:
include/ldapconfig.h.edit
servers/slapd/Make-template
servers/slapd/back-ldbm/Make-template
servers/slapd/back-ldbm/proto-back-ldbm.h
servers/slapd/back-ldbm/search.c
servers/slapd/backend.c
servers/slapd/bind.c
servers/slapd/config.c
servers/slapd/delete.c
servers/slapd/modify.c
servers/slapd/proto-slap.h
servers/slapd/search.c
servers/slapd/slap.h

index 9bf23812d4e0329bb55930411e1bc4b3600ed559..ea88f22a5de8292ef304006f671abf973ab56eec 100644 (file)
@@ -284,6 +284,8 @@ Please try again later.\r\n"
  */
        /* location of the default slapd config file */
 #define SLAPD_DEFAULT_CONFIGFILE       "%ETCDIR%/slapd.conf"
+       /* default max deref depth for aliases */
+#define SLAPD_DEFAULT_MAXDEREFDEPTH    15      
        /* default sizelimit on number of entries from a search */
 #define SLAPD_DEFAULT_SIZELIMIT                500
        /* default timelimit to spend on a search */
index 9ce0c6cf1cd398a52882fe0f99f44fbdf0d84c76..116ae69a51637e3b2447c53623504fef3277e676 100644 (file)
@@ -23,14 +23,16 @@ SRCS        = main.c daemon.c connection.c search.c filter.c add.c charray.c \
                value.c ava.c bind.c unbind.c abandon.c filterentry.c \
                phonetic.c acl.c str2filter.c aclparse.c init.c \
                detach.c strdup.c tempnam.c repl.c lock.c \
-               schema.c schemaparse.c monitor.c configinfo.c
+               schema.c schemaparse.c monitor.c configinfo.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 \
                value.o ava.o bind.o unbind.o abandon.o filterentry.o \
                phonetic.o acl.o str2filter.o aclparse.o init.o \
                detach.o strdup.o tempnam.o repl.o lock.o \
-               schema.o schemaparse.o monitor.o configinfo.o
+               schema.o schemaparse.o monitor.o configinfo.o \
+               suffixalias.o
 
 INCLUDES= -I. -I$(HDIR) $(KRBINCLUDEFLAG)
 DEFINES = $(DEFS) $(SERVERDEFS)
index 4cc4e0a173e85b13958748efe63c233353cecf53..2a4d5b34936f5cd7fff61c0dde299688284dfadc 100644 (file)
@@ -20,11 +20,13 @@ VERSIONFILE = $(LDAPSRC)/build/version
 SRCS   = idl.c add.c search.c cache.c dbcache.c dn2id.c id2entry.c \
                index.c id2children.c nextid.c abandon.c compare.c \
                modify.c modrdn.c delete.c init.c config.c bind.c attr.c \
-               filterindex.c unbind.c kerberos.c close.c group.c
+               filterindex.c unbind.c kerberos.c close.c group.c \
+               alias.c
 OBJS   = idl.o add.o search.o cache.o dbcache.o dn2id.o id2entry.o \
                index.o id2children.o nextid.o abandon.o compare.o \
                modify.o modrdn.o delete.o init.o config.o bind.o attr.o \
-               filterindex.o unbind.o kerberos.o close.o group.o
+               filterindex.o unbind.o kerberos.o close.o group.o \
+               alias.o
 
 INCLUDES= -I. -I.. -I$(HDIR) $(KRBINCLUDEFLAG)
 DEFINES = $(DEFS) $(SERVERDEFS) $(THREADS)
index 1bc9fdd0e1a686631316c8761af7211a17d1d94d..e834e8eeaf824a4e53c9a187335fc5d2177f004d 100644 (file)
@@ -1,6 +1,20 @@
 #ifndef _PROTO_BACK_LDBM
 #define _PROTO_BACK_LDBM
 
+/*
+ * alias.c
+ */
+Entry *derefAlias ( Backend     *be,
+                   Connection  *conn,
+                   Operation   *op,
+                   Entry       *e
+                   );
+char *derefDN ( Backend     *be,
+                Connection  *conn,
+                Operation   *op,
+                char        *dn
+);
+
 /*
  * attr.c
  */
@@ -41,7 +55,6 @@ int ldbm_cache_delete( struct dbcache *db, Datum key );
 int dn2id_add( Backend *be, char *dn, ID id );
 ID dn2id( Backend *be, char *dn );
 int dn2id_delete( Backend *be, char *dn );
-/*Entry * dn2entry( Backend *be, char *dn, char **matched );*/
 Entry * dn2entry_r( Backend *be, char *dn, char **matched );
 Entry * dn2entry_w( Backend *be, char *dn, char **matched );
 
index fd9db4849158ddfc1a1710829d8cb665bc7d909f..f41483c62035f96fd5949fc9ad4c46072eca605f 100644 (file)
@@ -59,6 +59,7 @@ ldbm_back_search(
        int             rmaxsize, nrefs;
        char            *rbuf, *rcur, *r;
        int             nentries = 0;
+       char            *realBase;
 
        Debug(LDAP_DEBUG_ARGS, "=> ldbm_back_search\n", 0, 0, 0);
 
@@ -76,19 +77,37 @@ ldbm_back_search(
                    be->be_sizelimit : slimit;
        }
 
+       /*
+        * check and apply aliasing where the dereferencing applies to
+        * the subordinates of the base
+        */
+       realBase = strdup (base);
+       switch ( deref ) {
+       case LDAP_DEREF_FINDING:
+       case LDAP_DEREF_ALWAYS:
+               free (realBase);
+               realBase = derefDN ( be, conn, op, base );
+               break;
+       }
+
+       (void) dn_normalize (realBase);
+
+       Debug( LDAP_DEBUG_TRACE, "using base %s\n",
+               realBase, 0, 0 );
+
        switch ( scope ) {
        case LDAP_SCOPE_BASE:
-               candidates = base_candidates( be, conn, op, base, filter,
+               candidates = base_candidates( be, conn, op, realBase, filter,
                    attrs, attrsonly, &matched, &err );
                break;
 
        case LDAP_SCOPE_ONELEVEL:
-               candidates = onelevel_candidates( be, conn, op, base, filter,
+               candidates = onelevel_candidates( be, conn, op, realBase, filter,
                    attrs, attrsonly, &matched, &err );
                break;
 
        case LDAP_SCOPE_SUBTREE:
-               candidates = subtree_candidates( be, conn, op, base, filter,
+               candidates = subtree_candidates( be, conn, op, realBase, filter,
                    attrs, attrsonly, &matched, NULL, &err, 1 );
                break;
 
@@ -165,7 +184,7 @@ ldbm_back_search(
                                        MAKE_SPACE( ref->a_vals[i]->bv_len + 2 );
                                        *rcur++ = '\n';
                                        strncpy( rcur, ref->a_vals[i]->bv_val,
-                                         ref->a_vals[i]->bv_len );
+                                               ref->a_vals[i]->bv_len );
                                        rcur = rcur + ref->a_vals[i]->bv_len;
                                        *rcur = '\0';
                                        nrefs++;
@@ -184,15 +203,15 @@ ldbm_back_search(
                                if ( scope == LDAP_SCOPE_ONELEVEL ) {
                                        if ( (dn = dn_parent( be, e->e_dn )) != NULL ) {
                                                (void) dn_normalize( dn );
-                                               scopeok = (dn == base) ? 1 : (! strcasecmp( dn, base ));
+                                               scopeok = (dn == realBase) ? 1 : (! strcasecmp( dn, realBase ));
                                        } else {
-                                               scopeok = (base == NULL || *base == '\0');
+                                               scopeok = (realBase == NULL || *realBase == '\0');
                                        }
                                        free( dn );
                                } else if ( scope == LDAP_SCOPE_SUBTREE ) {
                                        dn = strdup( e->e_dn );
                                        (void) dn_normalize( dn );
-                                       scopeok = dn_issuffix( dn, base );
+                                       scopeok = dn_issuffix( dn, realBase );
                                        free( dn );
                                }
 
@@ -208,6 +227,17 @@ ldbm_back_search(
                                                return( 0 );
                                        }
 
+                                       /*
+                                        * check and apply aliasing where the dereferencing applies to
+                                        * the subordinates of the base
+                                        */
+                                       switch ( deref ) {
+                                       case LDAP_DEREF_SEARCHING:
+                                       case LDAP_DEREF_ALWAYS:
+                                               e = derefAlias ( be, conn, op, e );
+                                               break;
+                                       }
+
                                        switch ( send_search_entry( be, conn, op, e,
                                                attrs, attrsonly ) ) {
                                        case 0:         /* entry sent ok */
index 67dafc69ec907479d5e58fbf66ad3b05d5bc27bb..076910a4e5380b2b9477504271ca39c02746ca8b 100644 (file)
@@ -186,6 +186,27 @@ select_backend( char * dn )
                }
        }
 
+        /* if no proper suffix could be found then check for aliases */
+        for ( i = 0; i < nbackends; i++ ) {
+                for ( j = 0; 
+                     backends[i].be_suffixAlias != NULL && 
+                      backends[i].be_suffixAlias[j] != NULL; 
+                     j += 2 )
+                {
+                        len = strlen( backends[i].be_suffixAlias[j] );
+
+                        if ( len > dnlen ) {
+                                continue;
+                        }
+
+                        if ( strcasecmp( backends[i].be_suffixAlias[j],
+                            dn + (dnlen - len) ) == 0 ) {
+                                return( &backends[i] );
+                        }
+                }
+        }
+
+
        return( NULL );
 }
 
index fbffeebc9fae67fd80dc51637beccb11ef1e99be..5f6ec17621d4aed779092b93568b2d63e7cda328 100644 (file)
@@ -19,6 +19,7 @@
 #include "slap.h"
 
 extern Backend *select_backend();
+extern char    *suffixAlias();
 
 extern char    *default_referral;
 
@@ -155,6 +156,9 @@ do_bind(
                return;
        }
 
+        /* alias suffix */
+        dn = suffixAlias ( dn, op, be );
+
        if ( be->be_bind != NULL ) {
                if ( (*be->be_bind)( be, conn, op, dn, method, &cred ) == 0 ) {
                        pthread_mutex_lock( &conn->c_dnmutex );
index 66050586ab794ac4f4e258306e58de0e293206ac..6c03ebb5fd6b12cf5562ace3cdca4bb9ceaaffc2 100644 (file)
@@ -81,6 +81,9 @@ read_config( char *fname, Backend **bep, FILE *pfp )
                        *bep = new_backend( cargv[1] );
                        be = *bep;
 
+               /* assign a default depth limit for alias deref */
+               be->be_maxDerefDepth = SLAPD_DEFAULT_MAXDEREFDEPTH; 
+
                /* set size limit */
                } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
                        if ( cargc < 2 ) {
@@ -131,6 +134,54 @@ read_config( char *fname, Backend **bep, FILE *pfp )
                                charray_add( &be->be_suffix, dn );
                        }
 
+                /* set database suffixAlias */
+                } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
+                        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 );
+                                exit( 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 );
+                                exit( 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 {
+                                dn = strdup( cargv[1] );
+                                (void) dn_normalize( dn );
+                                charray_add( &be->be_suffixAlias, dn );
+
+                                dn = strdup( cargv[2] );
+                                (void) dn_normalize( dn );
+                                charray_add( &be->be_suffixAlias, dn );
+                        }
+
+               /* set max deref depth */
+               } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
+                       if ( cargc < 2 ) {
+                               Debug( LDAP_DEBUG_ANY,
+                   "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
+                                   fname, lineno, 0 );
+                               exit( 1 );
+                       }
+                       if ( be == NULL ) {
+                               Debug( LDAP_DEBUG_ANY,
+"%s: line %d: depth line must appear inside a database definition (ignored)\n",
+                                   fname, lineno, 0 );
+                       } else {
+                           be->be_maxDerefDepth = atoi (cargv[1]);
+                       }
+
+
                /* set magic "root" dn for this database */
                } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
                        if ( cargc < 2 ) {
index bbab47806c0d7d24d7181125d39cfc485bdc898f..001d8e161ce3350b8e7dbce458a3a1fba30f7c3c 100644 (file)
@@ -17,6 +17,7 @@
 #include "slap.h"
 
 extern Backend *select_backend();
+extern char     *suffixAlias();
 
 extern char    *default_referral;
 
@@ -62,6 +63,9 @@ do_delete(
                return;
        }
 
+        /* alias suffix if approp */
+        dn = suffixAlias ( dn, op, be );
+
        /*
         * do the delete if 1 && (2 || 3)
         * 1) there is a delete function implemented in this backend;
index 2629291563eeeee9966f43b9d7851fe16178a2cc..2d9958362b564a356bd653c967b748a9e170c643 100644 (file)
@@ -27,6 +27,8 @@ extern int            global_lastmod;
 
 static void    modlist_free();
 static void    add_lastmods();
+extern char     *suffixAlias();
+
 
 void
 do_modify(
@@ -147,6 +149,9 @@ do_modify(
                return;
        }
 
+        /* alias suffix if approp */
+        dn = suffixAlias ( dn, op, be );
+
        /*
         * do the modify if 1 && (2 || 3)
         * 1) there is a modify function implemented in this backend;
index 83e4872d1594aba2b164ec68afde89bd9ee46cc0..095b785bc964b25c0ff1b34bda5e97534f23161a 100644 (file)
@@ -210,4 +210,9 @@ int value_ncmp( struct berval *v1, struct berval *v2, int syntax, int len,
 int value_find( struct berval **vals, struct berval *v, int syntax,
        int normalize );
 
+/*
+ * suffixAlias.c
+ */
+char *suffixAlias ( char *dn, Operation *op, Backend *be );
+
 #endif /* _proto_slap */
index fc96d2fd021727bd9f14c04445f3ace096defa32..0cadfed276af5f34d79395e20bce7377ce342217 100644 (file)
@@ -19,6 +19,7 @@
 
 extern int     get_filter();
 extern Backend *select_backend();
+extern char    *suffixAlias();
 
 extern char    *default_referral;
 
@@ -161,6 +162,9 @@ do_search( conn, op )
                return;
        }
 
+        /* translate the base if it matches an aliased base part */
+        base = suffixAlias ( base, op, be );
+
        /* actually do the search and send the result(s) */
        if ( be->be_search != NULL ) {
                (*be->be_search)( be, conn, op, base, scope, deref, sizelimit,
index 43f1eae8d1e7119572f5705bf74b1450031ab058..5cffeab89c54140cffd37a8f66d3ff35566c8cd3 100644 (file)
@@ -178,9 +178,11 @@ struct objclass {
 
 typedef struct backend {
        char    **be_suffix;    /* the DN suffixes of data in this backend */
+        char    **be_suffixAlias;       /* the DN suffix aliases of data in this backend */
        char    *be_rootdn;     /* the magic "root" dn for this db         */
        char    *be_rootpw;     /* the magic "root" password for this db   */
        int     be_readonly;    /* 1 => db is in "read only" mode          */
+        int     be_maxDerefDepth;       /* limit for depth of an alias deref  */
        int     be_sizelimit;   /* size limit for this backend             */
        int     be_timelimit;   /* time limit for this backend             */
        struct acl *be_acl;     /* access control list for this backend    */
@@ -221,6 +223,8 @@ typedef struct op {
        unsigned long   o_tag;          /* tag of the request             */
        time_t          o_time;         /* time op was initiated          */
        char            *o_dn;          /* dn bound when op was initiated */
+        char            *o_suffix;      /* suffix if aliased              */
+        char            *o_suffixAliased;       /* pending suffix translation     */
        int             o_authtype;     /* auth method used to bind dn    */
                                        /* values taken from ldap.h       */
                                        /* LDAP_AUTH_*                    */