1 /* rwmdn.c - massages dns */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2004 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
31 #include <ac/string.h>
32 #include <ac/socket.h>
37 /* FIXME: after rewriting, we should also remap attributes ... */
49 rc = rewrite_session( dc->rwmap->rwm_rw, dc->ctx,
50 ( dn->bv_len ? dn->bv_val : "" ),
51 dc->conn, &res->bv_val );
53 case REWRITE_REGEXEC_OK:
54 if ( res->bv_val != NULL ) {
55 res->bv_len = strlen( res->bv_val );
60 LDAP_LOG( BACK_LDAP, DETAIL1,
61 "[rw] %s: \"%s\" -> \"%s\"\n",
62 dc->ctx, dn->bv_val, res->bv_val );
63 #else /* !NEW_LOGGING */
64 Debug( LDAP_DEBUG_ARGS,
65 "[rw] %s: \"%s\" -> \"%s\"\n",
66 dc->ctx, dn->bv_val, res->bv_val );
67 #endif /* !NEW_LOGGING */
71 case REWRITE_REGEXEC_UNWILLING:
73 dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
74 dc->rs->sr_text = "Operation not allowed";
76 rc = LDAP_UNWILLING_TO_PERFORM;
79 case REWRITE_REGEXEC_ERR:
81 dc->rs->sr_err = LDAP_OTHER;
82 dc->rs->sr_text = "Rewrite error";
95 * Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
105 struct berval pretty = {0,NULL}, *dn = odn;
114 if ( dc->rwmap == NULL || dc->rwmap->rwm_suffix_massage == NULL ) {
120 src = 0 + dc->normalized;
121 dst = 2 + dc->normalized;
123 src = 2 + dc->normalized;
124 dst = 0 + dc->normalized;
125 /* DN from remote server may be in arbitrary form.
126 * Pretty it so we can parse reliably.
128 dnPretty( NULL, dn, &pretty, NULL );
129 if (pretty.bv_val) dn = &pretty;
133 dc->rwmap->rwm_suffix_massage[i].bv_val != NULL;
135 int aliasLength = dc->rwmap->rwm_suffix_massage[i+src].bv_len;
136 int diff = dn->bv_len - aliasLength;
139 /* alias is longer than dn */
141 } else if ( diff > 0 && ( !DN_SEPARATOR(dn->bv_val[diff-1]))) {
142 /* boundary is not at a DN separator */
144 /* At a DN Separator */
147 if ( !strcmp( dc->rwmap->rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
148 res->bv_len = diff + dc->rwmap->rwm_suffix_massage[i+dst].bv_len;
149 res->bv_val = ch_malloc( res->bv_len + 1 );
150 strncpy( res->bv_val, dn->bv_val, diff );
151 strcpy( &res->bv_val[diff], dc->rwmap->rwm_suffix_massage[i+dst].bv_val );
153 LDAP_LOG ( BACK_LDAP, ARGS,
154 "rwm_dn_massage: converted \"%s\" to \"%s\"\n",
155 dn->bv_val, res->bv_val, 0 );
157 Debug( LDAP_DEBUG_ARGS,
159 " converted \"%s\" to \"%s\"\n",
160 dn->bv_val, res->bv_val, 0 );
166 ch_free(pretty.bv_val);
169 /* Nothing matched, just return the original DN */
170 if (res->bv_val == NULL) {
176 #endif /* !ENABLE_REWRITE */
178 #endif /* SLAPD_OVER_RWM */