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).
63 dnLength = strlen ( dn );
66 li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
68 int aliasLength = strlen( li->suffix_massage[i+normalized] );
69 int diff = dnLength - aliasLength;
72 /* alias is longer than dn */
74 } else if ( diff > 0 ) {
75 if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
76 /* boundary is not at a DN separator */
79 /* At a DN Separator */
80 /* XXX or an escaped separator... oh well */
83 if ( !strcmp( li->suffix_massage[i+normalized], &dn[diff] ) ) {
85 dn = ch_malloc( diff + strlen( li->suffix_massage[i+2+normalized] ) + 1 );
86 strncpy( dn, oldDN, diff );
87 strcpy( &dn[diff], li->suffix_massage[i+2+normalized] );
88 Debug( LDAP_DEBUG_ARGS,
89 "ldap_back_dn_massage:"
90 " converted \"%s\" to \"%s\"\n",
101 * ldap_back_dn_restore
103 * Restores the original suffix;
104 * based on suffix_alias (servers/slapd/suffixalias.c).
107 ldap_back_dn_restore(
122 dnLength = strlen ( dn );
125 li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
127 int aliasLength = strlen( li->suffix_massage[i+2+normalized] );
128 int diff = dnLength - aliasLength;
131 /* alias is longer than dn */
134 } else if ( diff > 0 ) {
135 if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
136 /* boundary is not at a DN separator */
139 /* At a DN Separator */
140 /* XXX or an escaped separator... oh well */
143 if ( !strcmp( li->suffix_massage[i+2+normalized], &dn[diff] ) ) {
145 dn = ch_malloc( diff + strlen( li->suffix_massage[i+normalized] ) + 1 );
146 strncpy( dn, oldDN, diff );
147 strcpy( &dn[diff], li->suffix_massage[i+normalized] );
148 Debug( LDAP_DEBUG_ARGS,
149 "ldap_back_dn_restore:"
150 " converted \"%s\" to \"%s\"\n",
159 #endif /* !ENABLE_REWRITE */