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.
35 #include <ac/socket.h>
38 #include "back-ldap.h"
41 * ldap_back_dn_massage
43 * Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
61 dnLength = strlen ( dn );
64 li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
66 int aliasLength = strlen( li->suffix_massage[i+normalized] );
67 int diff = dnLength - aliasLength;
70 /* alias is longer than dn */
72 } else if ( diff > 0 ) {
73 if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
74 /* boundary is not at a DN separator */
77 /* At a DN Separator */
78 /* XXX or an escaped separator... oh well */
81 if ( !strcmp( li->suffix_massage[i+normalized], &dn[diff] ) ) {
83 dn = ch_malloc( diff + strlen( li->suffix_massage[i+2+normalized] ) + 1 );
84 strncpy( dn, oldDN, diff );
85 strcpy( &dn[diff], li->suffix_massage[i+2+normalized] );
86 Debug( LDAP_DEBUG_ARGS,
87 "ldap_back_dn_massage:"
88 " converted \"%s\" to \"%s\"\n",
99 * ldap_back_dn_restore
101 * Restores the original suffix;
102 * based on suffix_alias (servers/slapd/suffixalias.c).
105 ldap_back_dn_restore(
120 dnLength = strlen ( dn );
123 li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
125 int aliasLength = strlen( li->suffix_massage[i+2+normalized] );
126 int diff = dnLength - aliasLength;
129 /* alias is longer than dn */
132 } else if ( diff > 0 ) {
133 if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
134 /* boundary is not at a DN separator */
137 /* At a DN Separator */
138 /* XXX or an escaped separator... oh well */
141 if ( !strcmp( li->suffix_massage[i+2+normalized], &dn[diff] ) ) {
143 dn = ch_malloc( diff + strlen( li->suffix_massage[i+normalized] ) + 1 );
144 strncpy( dn, oldDN, diff );
145 strcpy( &dn[diff], li->suffix_massage[i+normalized] );
146 Debug( LDAP_DEBUG_ARGS,
147 "ldap_back_dn_restore:"
148 " converted \"%s\" to \"%s\"\n",