X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fsuffixalias.c;h=848364897b679808a6ff9db80f4ebd94d7cf57a2;hb=a5ee438c9394a19a241716d3d922299c20b0365d;hp=7b11e63b75b730eea53a09ce3cbfe93dc830961e;hpb=e2ee741ea86edb97a08b3f217760f1cd5972302e;p=openldap diff --git a/servers/slapd/suffixalias.c b/servers/slapd/suffixalias.c index 7b11e63b75..848364897b 100644 --- a/servers/slapd/suffixalias.c +++ b/servers/slapd/suffixalias.c @@ -1,4 +1,11 @@ +/* $OpenLDAP$ */ /* + * Copyright 1999-2000 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,42 +20,56 @@ #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) +char *suffix_alias( + Backend *be, + char *dn ) { int i, dnLength; + if(dn == NULL) return NULL; + if(be == NULL) return dn; + 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); + + 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 ( ! DN_SEPARATOR(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; }