1 /* suffixmassage.c - massages ldap backend dns */
5 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
6 * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
8 * Module back-ldap, originally developed by Howard Chu
10 * has been modified by Pierangelo Masarati. The original copyright
11 * notice has been maintained.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author is not responsible for the consequences of use of this
18 * software, no matter how awful, even if they arise from flaws in it.
20 * 2. The origin of this software must not be misrepresented, either by
21 * explicit claim or by omission. Since few users ever read sources,
22 * credits should appear in the documentation.
24 * 3. Altered versions must be plainly marked as such, and must not be
25 * misrepresented as being the original software. Since few users
26 * ever read sources, credits should appear in the documentation.
28 * 4. This notice may not be removed or altered.
33 #ifndef ENABLE_REWRITE
37 #include <ac/socket.h>
40 #include "back-ldap.h"
43 * ldap_back_dn_massage
45 * Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
65 if ( li == NULL || li->suffix_massage == NULL ) {
79 li->suffix_massage[i].bv_val != NULL;
81 int aliasLength = li->suffix_massage[i+src].bv_len;
82 int diff = dn->bv_len - aliasLength;
85 /* alias is longer than dn */
87 } else if ( diff > 0 ) {
88 if ( normalized && ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) ) {
89 /* boundary is not at a DN separator */
92 /* At a DN Separator */
93 /* XXX or an escaped separator... oh well */
96 if ( !strcmp( li->suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
97 res->bv_len = diff + li->suffix_massage[i+dst].bv_len;
98 res->bv_val = ch_malloc( res->bv_len + 1 );
99 strncpy( res->bv_val, dn->bv_val, diff );
100 strcpy( &res->bv_val[diff], li->suffix_massage[i+dst].bv_val );
102 LDAP_LOG ( BACK_LDAP, ARGS,
103 "ldap_back_dn_massage: converted \"%s\" to \"%s\"\n",
104 dn->bv_val, res->bv_val, 0 );
106 Debug( LDAP_DEBUG_ARGS,
107 "ldap_back_dn_massage:"
108 " converted \"%s\" to \"%s\"\n",
109 dn->bv_val, res->bv_val, 0 );
117 #endif /* !ENABLE_REWRITE */