]> git.sur5r.net Git - openldap/blob - servers/slapd/back-asyncmeta/suffixmassage.c
c32f8472c2c4c8494aead80cb6b86bdf5d60d5b6
[openldap] / servers / slapd / back-asyncmeta / suffixmassage.c
1 /* suffixmassage.c - massages ldap backend dns */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2016-2017 The OpenLDAP Foundation.
6  * Portions Copyright 2016 Symas Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17
18 /* ACKNOWLEDGEMENTS:
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. */
22
23 /* This is an altered version */
24
25 /*
26  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
27  * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
28  *
29  * Module back-ldap, originally developed by Howard Chu
30  *
31  * has been modified by Pierangelo Masarati. The original copyright
32  * notice has been maintained.
33  *
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:
37  *
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.
40  *
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.
44  *
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.
48  *
49  * 4. This notice may not be removed or altered.
50  */
51
52 #include "portable.h"
53
54 #include <stdio.h>
55
56 #include <ac/string.h>
57 #include <ac/socket.h>
58
59 #include "slap.h"
60 #include "../back-ldap/back-ldap.h"
61 #include "back-asyncmeta.h"
62
63 int
64 asyncmeta_dn_massage(
65         a_dncookie      *dc,
66         struct berval   *dn,
67         struct berval   *res )
68 {
69         int             rc = 0;
70         static char     *dmy = "";
71
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 ) )
75         {
76         case REWRITE_REGEXEC_OK:
77                 if ( res->bv_val != NULL ) {
78                         res->bv_len = strlen( res->bv_val );
79                 } else {
80                         *res = *dn;
81                 }
82                 Debug( LDAP_DEBUG_ARGS,
83                         "[rw] %s: \"%s\" -> \"%s\"\n",
84                         dc->ctx,
85                         BER_BVISNULL( dn ) ? "" : dn->bv_val,
86                         BER_BVISNULL( res ) ? "" : res->bv_val );
87                 rc = LDAP_SUCCESS;
88                 break;
89
90         case REWRITE_REGEXEC_UNWILLING:
91                 if ( dc->rs ) {
92                         dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
93                         dc->rs->sr_text = "Operation not allowed";
94                 }
95                 rc = LDAP_UNWILLING_TO_PERFORM;
96                 break;
97
98         case REWRITE_REGEXEC_ERR:
99                 if ( dc->rs ) {
100                         dc->rs->sr_err = LDAP_OTHER;
101                         dc->rs->sr_text = "Rewrite error";
102                 }
103                 rc = LDAP_OTHER;
104                 break;
105         }
106
107         if ( res->bv_val == dmy ) {
108                 BER_BVZERO( res );
109         }
110
111         return rc;
112 }