1 /* suffixmassage.c - massages ldap backend dns */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2016-2018 The OpenLDAP Foundation.
6 * Portions Copyright 2016 Symas Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
19 * This work was developed by Symas Corporation
20 * based on back-meta module for inclusion in OpenLDAP Software.
21 * This work was sponsored by Ericsson. */
23 /* This is an altered version */
26 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
27 * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
29 * Module back-ldap, originally developed by Howard Chu
31 * has been modified by Pierangelo Masarati. The original copyright
32 * notice has been maintained.
34 * Permission is granted to anyone to use this software for any purpose
35 * on any computer system, and to alter it and redistribute it, subject
36 * to the following restrictions:
38 * 1. The author is not responsible for the consequences of use of this
39 * software, no matter how awful, even if they arise from flaws in it.
41 * 2. The origin of this software must not be misrepresented, either by
42 * explicit claim or by omission. Since few users ever read sources,
43 * credits should appear in the documentation.
45 * 3. Altered versions must be plainly marked as such, and must not be
46 * misrepresented as being the original software. Since few users
47 * ever read sources, credits should appear in the documentation.
49 * 4. This notice may not be removed or altered.
56 #include <ac/string.h>
57 #include <ac/socket.h>
60 #include "../back-ldap/back-ldap.h"
61 #include "back-asyncmeta.h"
70 static char *dmy = "";
72 switch ( rewrite_session( dc->target->mt_rwmap.rwm_rw, dc->ctx,
73 ( dn->bv_val ? dn->bv_val : dmy ),
74 dc->conn, &res->bv_val ) )
76 case REWRITE_REGEXEC_OK:
77 if ( res->bv_val != NULL ) {
78 res->bv_len = strlen( res->bv_val );
82 Debug( LDAP_DEBUG_ARGS,
83 "[rw] %s: \"%s\" -> \"%s\"\n",
85 BER_BVISNULL( dn ) ? "" : dn->bv_val,
86 BER_BVISNULL( res ) ? "" : res->bv_val );
90 case REWRITE_REGEXEC_UNWILLING:
92 dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
93 dc->rs->sr_text = "Operation not allowed";
95 rc = LDAP_UNWILLING_TO_PERFORM;
98 case REWRITE_REGEXEC_ERR:
100 dc->rs->sr_err = LDAP_OTHER;
101 dc->rs->sr_text = "Rewrite error";
107 if ( res->bv_val == dmy ) {