e = ldap_first_entry( ld, res );
oc = ldap_get_values( ld, e, "objectClass" );
- if ( isnonleaf( ld, oc, dn ) ) {
- dn = ldap_get_dn( ld, e );
+ dn = ldap_get_dn( ld, e );
+ if ( isnonleaf( ld, oc, dn ) ) {
rc = do_menu( ld, fp, dn );
free( dn );
return( rc );
}
+ free( dn );
ldap_value_free( oc );
}
/* VARARGS */
setproctitle( fmt, a, b, c )
char *fmt;
+char *a, *b, *c;
{
static char *endargv = (char *)0;
char *s;
return(tmp);
}
-char * code_to_str(i)
+char * code_to_str(int i)
{
switch(i) {
case LDAP_MOD_ADD : return("ADD");
#define NULLAVL ((Avlnode *) NULL)
/* balance factor values */
-#define LH -1
+#define LH (-1)
#define EH 0
#define RH 1
#define AVL_INORDER 2
#define AVL_POSTORDER 3
/* what apply returns if it ran out of nodes */
-#define AVL_NOMORE -6
+#define AVL_NOMORE (-6)
LDAP_END_DECL
#define NULLTMPLITEM ((struct ldap_tmplitem *)0)
#define LDAP_SET_TMPLITEM_APPDATA( ti, datap ) \
- (ti)->ti_appdata = (void *)(datap)
+ ( (ti)->ti_appdata = (void *)(datap) )
#define LDAP_GET_TMPLITEM_APPDATA( ti, type ) \
- (type)((ti)->ti_appdata)
+ ( (type)((ti)->ti_appdata) )
#define LDAP_IS_TMPLITEM_OPTION_SET( ti, option ) \
- (((ti)->ti_options & option ) != 0 )
+ ( ((ti)->ti_options & (option) ) != 0 )
/*
#define NULLDISPTMPL ((struct ldap_disptmpl *)0)
#define LDAP_SET_DISPTMPL_APPDATA( dt, datap ) \
- (dt)->dt_appdata = (void *)(datap)
+ ( (dt)->dt_appdata = (void *)(datap) )
#define LDAP_GET_DISPTMPL_APPDATA( dt, type ) \
- (type)((dt)->dt_appdata)
+ ( (type)((dt)->dt_appdata) )
#define LDAP_IS_DISPTMPL_OPTION_SET( dt, option ) \
- (((dt)->dt_options & option ) != 0 )
+ ( ((dt)->dt_options & (option) ) != 0 )
#define LDAP_TMPL_ERR_VERSION 1
#define LDAP_TMPL_ERR_MEM 2
/*
* in io.c:
*/
+
LDAP_F long ber_read LDAP_P(( BerElement *ber, char *buf, unsigned long len ));
LDAP_F long ber_write LDAP_P(( BerElement *ber, char *buf, unsigned long len,
int nosos ));
#ifdef LDAP_SYSLOG
#define Debug( level, fmt, arg1, arg2, arg3 ) \
{ \
- if ( ldap_debug & level ) \
- fprintf( stderr, fmt, arg1, arg2, arg3 ); \
+ if ( ldap_debug & (level) ) \
+ fprintf( stderr, (fmt), (arg1), (arg2), (arg3) ); \
if ( ldap_syslog & level ) \
- syslog( ldap_syslog_level, fmt, arg1, arg2, arg3 ); \
+ syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \
}
#else /* LDAP_SYSLOG */
#ifndef WINSOCK
#define Debug( level, fmt, arg1, arg2, arg3 ) \
- if ( ldap_debug & level ) \
- fprintf( stderr, fmt, arg1, arg2, arg3 );
+ if ( ldap_debug & (level) ) \
+ fprintf( stderr, (fmt), (arg1), (arg2), (arg3) );
#else /* !WINSOCK */
extern void Debug( int level, char* fmt, ... );
#endif /* !WINSOCK */
/*
* handy macro to check whether LDAP struct is set up for CLDAP or not
*/
-#define LDAP_IS_CLDAP( ld ) ( ld->ld_sb.sb_naddr > 0 )
+#define LDAP_IS_CLDAP( ld ) ( (ld)->ld_sb.sb_naddr > 0 )
/*
*/
/* location of the default slapd config file */
#define SLAPD_DEFAULT_CONFIGFILE "%SYSCONFDIR%/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 */
value.c ava.c bind.c unbind.c abandon.c filterentry.c \
phonetic.c acl.c str2filter.c aclparse.c init.c \
detach.c repl.c lock.c \
- schema.c schemaparse.c monitor.c configinfo.c
+ suffixAlias.c schema.c schemaparse.c monitor.c configinfo.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 repl.o lock.o \
- schema.o schemaparse.o monitor.o configinfo.o
+ suffixalias.o schema.o schemaparse.o monitor.o configinfo.o
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
/* b->a_group is an unexpanded entry name, expanded it should be an
* entry with objectclass group* and we test to see if odn is one of
- * the values in the attribute uniquegroup
+ * the values in the attribute group
*/
Debug( LDAP_DEBUG_ARGS, "<= check a_group: %s\n",
b->a_group, 0, 0);
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 group.c \
modify.c modrdn.c delete.c init.c config.c bind.c attr.c \
- filterindex.c unbind.c kerberos.c close.c
+ filterindex.c unbind.c kerberos.c close.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 group.o \
modify.o modrdn.o delete.o init.o config.o bind.o attr.o \
- filterindex.o unbind.o kerberos.o close.o
+ filterindex.o unbind.o kerberos.o close.o alias.o
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <string.h>
+#include "slap.h"
+#include "back-ldbm.h"
+#include "proto-back-ldbm.h"
+
+/*
+ * given an alias object, dereference it to its end point.
+ * entry returned has reader lock
+ */
+Entry *derefAlias_r ( Backend *be,
+ Connection *conn,
+ Operation *op,
+ Entry *e)
+{
+ Attribute *a;
+ int depth;
+ char **pastAliases;
+ char *matched;
+
+ Debug( LDAP_DEBUG_TRACE, "<= checking for alias for dn %s\n", e->e_dn, 0, 0 );
+
+ /*
+ * try to deref fully, up to a maximum depth. If the max depth exceeded
+ * then send an error
+ */
+ for ( depth = 0;
+ ( ( a = attr_find( e->e_attrs, "aliasedobjectname" ) ) != NULL) &&
+ ( depth < be->be_maxDerefDepth );
+ ++depth)
+ {
+
+ /*
+ * make sure there is a defined aliasedobjectname.
+ * can only have one value so just use first value (0) in the attr list.
+ */
+ if (a->a_vals[0] && a->a_vals[0]->bv_val) {
+ char *newDN, *oldDN;
+
+ Debug( LDAP_DEBUG_TRACE, "<= %s is an alias for %s\n",
+ e->e_dn, a->a_vals[0]->bv_val, 0 );
+ newDN = strdup (a->a_vals[0]->bv_val);
+ oldDN = strdup (e->e_dn);
+
+ /*
+ * ok, so what happens if there is an alias in the DN of a dereferenced
+ * alias object?
+ */
+ if ( (e = dn2entry_r( be, newDN, &matched )) == NULL ) {
+
+ /* could not deref return error */
+ Debug( LDAP_DEBUG_TRACE,
+ "<= %s is a dangling alias to %s\n",
+ oldDN, newDN, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Dangling Alias" );
+
+ if(matched != NULL) free(matched);
+ }
+ free (newDN);
+ free (oldDN);
+ }
+ else {
+ /*
+ * there was an aliasedobjectname defined but no data.
+ * this can't happen, right?
+ */
+ Debug( LDAP_DEBUG_TRACE,
+ "<= %s has no data in aliasedobjectname attribute\n",
+ e->e_dn, 0, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Alias missing aliasedobjectname" );
+ }
+ }
+
+ /*
+ * warn if we pulled out due to exceeding the maximum deref depth
+ */
+ if ( depth >= be->be_maxDerefDepth ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<= %s exceeded maximum deref depth %d\n",
+ e->e_dn, be->be_maxDerefDepth, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Maximum alias dereference depth exceeded" );
+ }
+
+ return e;
+}
+
+/*
+ * given a DN fully deref it and return the real DN or original DN if it fails
+ */
+char *derefDN ( Backend *be,
+ Connection *conn,
+ Operation *op,
+ char *dn
+)
+{
+ struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+ char *matched;
+ char *newDN;
+ int depth;
+ Entry *eMatched;
+ Entry *eDeref;
+ Entry *eNew;
+
+
+ Debug( LDAP_DEBUG_TRACE,
+ "<= dereferencing dn %s\n",
+ dn, 0, 0 );
+
+ newDN = strdup ( dn );
+
+ /* while we don't have a matched dn, deref the DN */
+ for ( depth = 0;
+ ( (eMatched = dn2entry_r( be, newDN, &matched )) == NULL) &&
+ (depth < be->be_maxDerefDepth);
+ ++depth ) {
+
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eMatched);
+
+ if (*matched) {
+ char *submatch;
+
+ /*
+ * make sure there actually is an entry for the matched part
+ */
+ if ( (eMatched = dn2entry_r( be, matched, &submatch )) != NULL) {
+ char *remainder; /* part before the aliased part */
+ int rlen = strlen(newDN) - strlen(matched);
+
+ Debug( LDAP_DEBUG_TRACE, "<= matched %s\n", matched, 0, 0 );
+
+ remainder = ch_malloc (rlen + 1);
+ strncpy ( remainder, newDN, rlen );
+ remainder[rlen] = '\0';
+
+ Debug( LDAP_DEBUG_TRACE, "<= remainder %s\n", remainder, 0, 0 );
+
+ if ((eNew = derefAlias_r( be, conn, op, eMatched )) == NULL) {
+ free (matched);
+ free (newDN);
+ free (remainder);
+ break; /* no associated entry, dont deref */
+ }
+ else {
+
+ Debug( LDAP_DEBUG_TRACE, "<= l&g we have %s vs %s \n", matched, eNew->e_dn, 0 );
+
+ if (!strcasecmp (matched, eNew->e_dn)) {
+ /* newDN same as old so not an alias, no need to go further */
+ free (newDN);
+ free (matched);
+ free (remainder);
+ break;
+ }
+
+ /*
+ * we have dereferenced the aliased part so put
+ * the new dn together
+ */
+ free (newDN);
+ free (matched);
+
+ newDN = ch_malloc (strlen(eMatched->e_dn) + rlen + 1);
+ strcpy (newDN, remainder);
+ strcat (newDN, eMatched->e_dn);
+ Debug( LDAP_DEBUG_TRACE, "<= expanded to %s\n", newDN, 0, 0 );
+
+ free (remainder);
+
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eNew);
+ }
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eMatched);
+ }
+ else {
+ if(submatch != NULL) free(submatch);
+ break; /* there was no entry for the matched part */
+ }
+ }
+ else {
+ break; /* there was no matched part */
+ }
+ }
+
+ /*
+ * the final part of the DN might be an alias
+ * so try to dereference it.
+ */
+ if ( (eNew = dn2entry_r( be, newDN, &matched )) != NULL) {
+ if ((eDeref = derefAlias_r( be, conn, op, eNew )) != NULL) {
+ free (newDN);
+ newDN = strdup (eDeref->e_dn);
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eDeref);
+ }
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eNew);
+ }
+
+ /*
+ * warn if we exceeded the max depth as the resulting DN may not be dereferenced
+ */
+ if (depth >= be->be_maxDerefDepth) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<= max deref depth exceeded in derefDN for %s, result %s\n",
+ dn, newDN, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Maximum alias dereference depth exceeded for base" );
+ }
+
+ Debug( LDAP_DEBUG_TRACE, "<= returning deref DN of %s\n", newDN, 0, 0 );
+
+ free(matched);
+
+ return newDN;
+}
#ifdef SLAPD_ACLGROUPS
/* return 0 IFF edn is a value in uniqueMember attribute
* of entry with bdn AND that entry has an objectClass
- * value of groupOfUniqueNames
+ * value of groupOfNames
*/
int
ldbm_back_group(
Entry *e;
char *matched;
Attribute *objectClass;
- Attribute *uniqueMember;
+ Attribute *member;
int rc;
Debug( LDAP_DEBUG_TRACE, "=> ldbm_back_group: bdn: %s\n", bdn, 0, 0 );
/* check for deleted */
- /* find it's objectClass and uniqueMember attribute values
+ /* find it's objectClass and member attribute values
* make sure this is a group entry
- * finally test if we can find edn in the uniqueMember attribute value list *
+ * finally test if we can find edn in the member attribute value list *
*/
rc = 1;
if ((objectClass = attr_find(e->e_attrs, "objectclass")) == NULL) {
Debug( LDAP_DEBUG_TRACE, "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
}
- else if ((uniqueMember = attr_find(e->e_attrs, "uniquemember")) == NULL) {
- Debug( LDAP_DEBUG_TRACE, "<= ldbm_back_group: failed to find uniqueMember\n", 0, 0, 0 );
+ else if ((member = attr_find(e->e_attrs, "member")) == NULL) {
+ Debug( LDAP_DEBUG_TRACE, "<= ldbm_back_group: failed to find member\n", 0, 0, 0 );
}
else {
struct berval bvObjectClass;
- struct berval bvUniqueMembers;
+ struct berval bvMembers;
- Debug( LDAP_DEBUG_ARGS, "<= ldbm_back_group: found objectClass and uniqueMembers\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_ARGS, "<= ldbm_back_group: found objectClass and members\n", 0, 0, 0 );
- bvObjectClass.bv_val = "groupofuniquenames";
+ bvObjectClass.bv_val = "groupofnames";
bvObjectClass.bv_len = strlen( bvObjectClass.bv_val );
- bvUniqueMembers.bv_val = edn;
- bvUniqueMembers.bv_len = strlen( edn );
+ bvMembers.bv_val = edn;
+ bvMembers.bv_len = strlen( edn );
if (value_find(objectClass->a_vals, &bvObjectClass, SYNTAX_CIS, 1) != 0) {
- Debug( LDAP_DEBUG_TRACE, "<= ldbm_back_group: failed to find objectClass in groupOfUniqueNames\n",
+ Debug( LDAP_DEBUG_TRACE,
+ "<= ldbm_back_group: failed to find objectClass in groupOfNames\n",
0, 0, 0 );
}
- else if (value_find(uniqueMember->a_vals, &bvUniqueMembers, SYNTAX_CIS, 1) != 0) {
- Debug( LDAP_DEBUG_ACL, "<= ldbm_back_group: %s not in %s: groupOfUniqueNames\n",
+ else if (value_find(Member->a_vals, &bvMembers, SYNTAX_CIS, 1) != 0) {
+ Debug( LDAP_DEBUG_ACL, "<= ldbm_back_group: %s not in %s: groupOfNames\n",
edn, bdn, 0 );
}
else {
- Debug( LDAP_DEBUG_ACL, "<= ldbm_back_group: %s is in %s: groupOfUniqueNames\n",
+ Debug( LDAP_DEBUG_ACL, "<= ldbm_back_group: %s is in %s: groupOfNames\n",
edn, bdn, 0 );
rc = 0;
}
/* store it */
flags = LDBM_REPLACE;
- if ( li->li_flush_wrt ) flags != LDBM_SYNC;
+ if ( li->li_flush_wrt ) flags |= LDBM_SYNC;
rc = ldbm_cache_store( db, key, data, flags );
pthread_mutex_unlock( &entry2str_mutex );
LDAP_BEGIN_DECL
+/*
+ * alias.c
+ */
+Entry *derefAlias_r LDAP_P((
+ Backend *be,
+ Connection *conn,
+ Operation *op,
+ Entry *e ));
+char *derefDN LDAP_P((
+ Backend *be,
+ Connection *conn,
+ Operation *op,
+ char *dn ));
+
/*
* attr.c
*/
int dn2id_add LDAP_P(( Backend *be, char *dn, ID id ));
ID dn2id LDAP_P(( Backend *be, char *dn ));
int dn2id_delete LDAP_P(( Backend *be, char *dn ));
-/*Entry * dn2entry LDAP_P(( Backend *be, char *dn, char **matched ));*/
Entry * dn2entry_r LDAP_P(( Backend *be, char *dn, char **matched ));
Entry * dn2entry_w LDAP_P(( Backend *be, char *dn, char **matched ));
int rmaxsize, nrefs;
char *rbuf, *rcur, *r;
int nentries = 0;
+ char *realBase;
Debug(LDAP_DEBUG_ARGS, "=> ldbm_back_search\n", 0, 0, 0);
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;
int i, len;
if ( ref->a_vals == NULL ) {
- Debug( LDAP_DEBUG_ANY, "null ref in (%s)\n", 0,
- 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "null ref in (%s)\n",
+ e->e_dn, 0, 0 );
} else {
for ( i = 0; ref->a_vals[i] != NULL; i++ ) {
/* referral + newline + null */
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++;
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 );
}
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:
+ {
+ Entry *newe = derefAlias_r( be, conn, op, e );
+ cache_return_entry_r( &li->li_cache, e );
+ e = newe;
+ }
+ break;
+ }
+
switch ( send_search_entry( be, conn, op, e,
attrs, attrsonly ) ) {
case 0: /* entry sent ok */
}
}
+ /* 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 );
}
#include "slap.h"
extern Backend *select_backend();
+extern char *suffixAlias();
extern char *default_referral;
free( cred.bv_val );
}
if ( cred.bv_len == 0 ) {
- send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
+ send_ldap_result( conn, op, LDAP_SUCCESS,
+ NULL, NULL );
+ } else if ( default_referral && *default_referral ) {
+ send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS,
+ NULL, default_referral );
} else {
- send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
- default_referral );
+ send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
+ NULL, default_referral );
}
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 );
*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 ) {
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 ) {
#include "slap.h"
extern Backend *select_backend();
+extern char *suffixAlias();
extern char *default_referral;
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;
static void modlist_free();
static void add_lastmods();
+extern char *suffixAlias();
+
void
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;
int value_find LDAP_P(( struct berval **vals, struct berval *v, int syntax,
int normalize ));
+/*
+ * suffixAlias.c
+ */
+char *suffixAlias LDAP_P(( char *dn, Operation *op, Backend *be ));
+
#endif /* _proto_slap */
int rc, sd;
unsigned long tag, bytes;
+ if ( err == LDAP_PARTIAL_RESULTS && (text == NULL || *text == '\0') )
+ err = LDAP_NO_SUCH_OBJECT;
+
Debug( LDAP_DEBUG_TRACE, "send_ldap_result %d:%s:%s\n", err, matched ?
matched : "", text ? text : "" );
extern int get_filter();
extern Backend *select_backend();
+extern char *suffixAlias();
extern char *default_referral;
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,
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 */
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_* */
Filter *
str2filter( char *str )
{
- Filter *f;
+ Filter *f = NULL;
char *end;
Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <string.h>
+#include "slap.h"
+
+/*
+ * given a dn (or root part), return an aliased dn if any of the
+ * alias suffixes match
+ */
+char *suffixAlias ( dn, op, be )
+ char *dn;
+ Operation *op;
+ Backend *be;
+{
+ int i, dnLength;
+
+ dnLength = strlen ( dn );
+ op->o_suffix = NULL;
+ op->o_suffixAliased = NULL;
+ for ( i = 0;
+ be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
+ i += 2) {
+ int aliasLength = strlen (be->be_suffixAlias[i]);
+ if (aliasLength > dnLength) {
+ continue;
+ }
+
+ if (!strcasecmp(be->be_suffixAlias[i],
+ dn + (dnLength - aliasLength))) {
+ char *oldDN = dn;
+ op->o_suffixAliased = strdup ( be->be_suffixAlias[i] );
+ dn = ch_malloc ( (dnLength - aliasLength) +
+ strlen (be->be_suffixAlias[ i+1 ]) + 1);
+ strncpy (dn, oldDN, dnLength - aliasLength);
+ strcpy (dn + (dnLength - aliasLength), be->be_suffixAlias[ i+1 ]);
+ op->o_suffix = strdup (dn);
+ Debug( LDAP_DEBUG_ARGS, "ALIAS: converted %s to %s", oldDN, dn, 0);
+ free (oldDN);
+ break;
+ }
+ }
+ return dn;
+}