3 * Copyright 1999-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file in the top level
6 * directory of this package.
9 * Copyright (c) 1998 Will Ballantyne, ITSD, Government of BC
10 * All rights reserved.
12 * Redistribution and use in source and binary forms are permitted
13 * provided that this notice is preserved and that due credit is given
14 * to ITSD, Government of BC. The name of ITSD
15 * may not be used to endorse or promote products derived from this
16 * software without specific prior written permission. This software
17 * is provided ``as is'' without express or implied warranty.
23 #include <ac/string.h>
24 #include <ac/socket.h>
28 * given a normalized uppercased dn (or root part),
29 * return an aliased dn if any of the alias suffixes match
37 if(dn == NULL || be == NULL || dn->bv_len == 0)
40 dnLength = dn->bv_len;
43 be->be_suffixAlias != NULL && be->be_suffixAlias[i].bv_val != NULL;
46 int aliasLength = be->be_suffixAlias[i].bv_len;
47 int diff = dnLength - aliasLength;
50 /* alias is longer than dn */
52 } else if ( diff > 0 ) {
53 if ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) {
54 /* boundary is not at a DN separator */
57 /* At a DN Separator */
58 /* XXX or an escaped separator... oh well */
61 if (!strcmp(be->be_suffixAlias[i].bv_val, &dn->bv_val[diff])) {
62 char *oldDN = dn->bv_val;
63 dn->bv_len = diff + be->be_suffixAlias[i+1].bv_len;
64 dn->bv_val = ch_malloc( dn->bv_len + 1 );
65 strncpy( dn->bv_val, oldDN, diff );
66 strcpy( &dn->bv_val[diff], be->be_suffixAlias[i+1].bv_val );
68 LDAP_LOG( OPERATION, INFO,
69 "suffix_alias: converted \"%s\" to \"%s\"\n",
70 oldDN, dn->bv_val, 0 );
72 Debug( LDAP_DEBUG_ARGS,
73 "suffix_alias: converted \"%s\" to \"%s\"\n",
74 oldDN, dn->bv_val, 0);