openldap/servers/slapd/suffixalias.c

82 lines
2.1 KiB
C
Raw Normal View History

/* $OpenLDAP$ */
1999-07-28 02:43:30 +08:00
/*
2002-01-05 05:17:25 +08:00
* Copyright 1999-2002 The OpenLDAP Foundation, All Rights Reserved.
1999-07-28 02:43:30 +08:00
*
* 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
*/
void suffix_alias(
1999-07-28 02:43:30 +08:00
Backend *be,
struct berval *dn )
1999-07-28 02:43:30 +08:00
{
2001-01-18 00:35:53 +08:00
int i, dnLength;
1999-07-28 02:43:30 +08:00
if(dn == NULL || be == NULL || dn->bv_len == 0)
return;
1999-07-28 02:43:30 +08:00
dnLength = dn->bv_len;
1999-07-28 02:43:30 +08:00
for ( i = 0;
be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
i += 2 )
{
int aliasLength = be->be_suffixAlias[i]->bv_len;
1999-07-28 02:43:30 +08:00
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]) ) {
1999-07-28 02:43:30 +08:00
/* 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 );
2001-01-16 03:17:29 +08:00
#ifdef NEW_LOGGING
2001-01-18 00:35:53 +08:00
LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
"suffix_alias: converted \"%s\" to \"%s\"\n",
oldDN, dn->bv_val ));
2001-01-16 03:17:29 +08:00
#else
1999-07-28 02:43:30 +08:00
Debug( LDAP_DEBUG_ARGS,
"suffix_alias: converted \"%s\" to \"%s\"\n",
oldDN, dn->bv_val, 0);
2001-01-16 03:17:29 +08:00
#endif
1999-07-28 02:43:30 +08:00
free (oldDN);
break;
}
}
}