1 /* suffixmassage.c - massages ldap backend dns */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2003 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
29 #include <ac/string.h>
30 #include <ac/socket.h>
33 #include "back-ldap.h"
45 switch (rewrite_session( dc->rwmap->rwm_rw, dc->ctx, (dn->bv_len ? dn->bv_val : ""), dc->conn,
47 case REWRITE_REGEXEC_OK:
48 if ( res->bv_val != NULL ) {
49 res->bv_len = strlen( res->bv_val );
54 LDAP_LOG( BACK_LDAP, DETAIL1,
55 "[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val );
56 #else /* !NEW_LOGGING */
57 Debug( LDAP_DEBUG_ARGS,
58 "[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val );
59 #endif /* !NEW_LOGGING */
63 case REWRITE_REGEXEC_UNWILLING:
65 dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
66 dc->rs->sr_text = "Operation not allowed";
68 rc = LDAP_UNWILLING_TO_PERFORM;
71 case REWRITE_REGEXEC_ERR:
73 dc->rs->sr_err = LDAP_OTHER;
74 dc->rs->sr_text = "Rewrite error";
84 * ldap_back_dn_massage
86 * Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
96 struct berval pretty = {0,NULL}, *dn = odn;
105 if ( dc->rwmap == NULL || dc->rwmap->rwm_suffix_massage == NULL ) {
111 src = 0 + dc->normalized;
112 dst = 2 + dc->normalized;
114 src = 2 + dc->normalized;
115 dst = 0 + dc->normalized;
116 /* DN from remote server may be in arbitrary form.
117 * Pretty it so we can parse reliably.
119 dnPretty( NULL, dn, &pretty, NULL );
120 if (pretty.bv_val) dn = &pretty;
124 dc->rwmap->rwm_suffix_massage[i].bv_val != NULL;
126 int aliasLength = dc->rwmap->rwm_suffix_massage[i+src].bv_len;
127 int diff = dn->bv_len - aliasLength;
130 /* alias is longer than dn */
132 } else if ( diff > 0 && ( !DN_SEPARATOR(dn->bv_val[diff-1]))) {
133 /* boundary is not at a DN separator */
135 /* At a DN Separator */
138 if ( !strcmp( dc->rwmap->rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
139 res->bv_len = diff + dc->rwmap->rwm_suffix_massage[i+dst].bv_len;
140 res->bv_val = ch_malloc( res->bv_len + 1 );
141 strncpy( res->bv_val, dn->bv_val, diff );
142 strcpy( &res->bv_val[diff], dc->rwmap->rwm_suffix_massage[i+dst].bv_val );
144 LDAP_LOG ( BACK_LDAP, ARGS,
145 "ldap_back_dn_massage: converted \"%s\" to \"%s\"\n",
146 dn->bv_val, res->bv_val, 0 );
148 Debug( LDAP_DEBUG_ARGS,
149 "ldap_back_dn_massage:"
150 " converted \"%s\" to \"%s\"\n",
151 dn->bv_val, res->bv_val, 0 );
157 ch_free(pretty.bv_val);
160 /* Nothing matched, just return the original DN */
161 if (res->bv_val == NULL) {
167 #endif /* !ENABLE_REWRITE */