X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fsuffixalias.c;h=78a1a18cb32816087284a2fa68608227d7bc4107;hb=08059f1633bfd9d0a709761b026bdb8e4441c6e6;hp=31a09838cba2742725b4b0b2bd6e4d1f84aa04d7;hpb=e05e9dd9557682ee34dcc5934f8709add3782ca5;p=openldap diff --git a/servers/slapd/suffixalias.c b/servers/slapd/suffixalias.c index 31a09838cb..78a1a18cb3 100644 --- a/servers/slapd/suffixalias.c +++ b/servers/slapd/suffixalias.c @@ -1,4 +1,11 @@ +/* $OpenLDAP$ */ /* + * Copyright 1999-2002 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. * @@ -13,44 +20,62 @@ #include "portable.h" #include -#include -#include /* Get struct sockaddr for slap.h */ +#include +#include #include "slap.h" /* - * given a dn (or root part), return an aliased dn if any of the - * alias suffixes match + * given a normalized uppercased dn (or root part), + * return an aliased dn if any of the alias suffixes match */ -char *suffixAlias (char *dn, Operation *op, Backend *be) +void suffix_alias( + Backend *be, + struct berval *dn ) { - int i, dnLength; - - if(dn == NULL) return NULL; - - 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 = ch_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 = ch_strdup (dn); - Debug( LDAP_DEBUG_ARGS, "ALIAS: converted %s to %s", oldDN, dn, 0); - free (oldDN); + int i, dnLength; + + if(dn == NULL || be == NULL || dn->bv_len == 0) + return; + + dnLength = dn->bv_len; + + for ( i = 0; + be->be_suffixAlias != NULL && be->be_suffixAlias[i].bv_val != NULL; + i += 2 ) + { + int aliasLength = be->be_suffixAlias[i].bv_len; + int diff = dnLength - aliasLength; + + if ( diff < 0 ) { + /* alias is longer than dn */ + continue; + } else if ( diff > 0 ) { + if ( ! DN_SEPARATOR(dn->bv_val[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].bv_val, &dn->bv_val[diff])) { + char *oldDN = dn->bv_val; + dn->bv_len = diff + be->be_suffixAlias[i+1].bv_len; + dn->bv_val = ch_malloc( dn->bv_len + 1 ); + strncpy( dn->bv_val, oldDN, diff ); + strcpy( &dn->bv_val[diff], be->be_suffixAlias[i+1].bv_val ); +#ifdef NEW_LOGGING + LDAP_LOG( OPERATION, INFO, + "suffix_alias: converted \"%s\" to \"%s\"\n", + oldDN, dn->bv_val, 0 ); +#else + Debug( LDAP_DEBUG_ARGS, + "suffix_alias: converted \"%s\" to \"%s\"\n", + oldDN, dn->bv_val, 0); +#endif + + free (oldDN); break; } } - return dn; }