Debian Codegraph @

servers/slapd/back-meta/suffixmassage.c

raw
1 /* suffixmassage.c - massages ldap backend dns */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2003-2024 The OpenLDAP Foundation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
11 *
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
15 */
16 /* ACKNOWLEDGEMENTS:
17 * This work was initially developed by the Howard Chu for inclusion
18 * in OpenLDAP Software and subsequently enhanced by Pierangelo
19 * Masarati.
20 */
21 /* This is an altered version */
22
23 /*
24 * Copyright 1999, Howard Chu, All rights reserved. <[email protected]>
25 * Copyright 2000, Pierangelo Masarati, All rights reserved. <[email protected]>
26 *
27 * Module back-ldap, originally developed by Howard Chu
28 *
29 * has been modified by Pierangelo Masarati. The original copyright
30 * notice has been maintained.
31 *
32 * Permission is granted to anyone to use this software for any purpose
33 * on any computer system, and to alter it and redistribute it, subject
34 * to the following restrictions:
35 *
36 * 1. The author is not responsible for the consequences of use of this
37 * software, no matter how awful, even if they arise from flaws in it.
38 *
39 * 2. The origin of this software must not be misrepresented, either by
40 * explicit claim or by omission. Since few users ever read sources,
41 * credits should appear in the documentation.
42 *
43 * 3. Altered versions must be plainly marked as such, and must not be
44 * misrepresented as being the original software. Since few users
45 * ever read sources, credits should appear in the documentation.
46 *
47 * 4. This notice may not be removed or altered.
48 */
49
50 #include "portable.h"
51
52 #include <stdio.h>
53
54 #include <ac/string.h>
55 #include <ac/socket.h>
56
57 #include "slap.h"
58 #include "../back-ldap/back-ldap.h"
59 #include "back-meta.h"
60
61 int
62 ldap_back_dn_massage(
63 dncookie *dc,
64 struct berval *dn,
65 struct berval *res )
66 {
67 int rc = 0;
68 static char *dmy = "";
69
70 switch ( rewrite_session( dc->target->mt_rwmap.rwm_rw, dc->ctx,
71 ( dn->bv_val ? dn->bv_val : dmy ),
72 dc->conn, &res->bv_val ) )
73 {
74 case REWRITE_REGEXEC_OK:
75 if ( res->bv_val != NULL ) {
76 res->bv_len = strlen( res->bv_val );
77 } else {
78 *res = *dn;
79 }
80 Debug( LDAP_DEBUG_ARGS,
81 "[rw] %s: \"%s\" -> \"%s\"\n",
82 dc->ctx,
83 BER_BVISNULL( dn ) ? "" : dn->bv_val,
84 BER_BVISNULL( res ) ? "" : res->bv_val );
85 rc = LDAP_SUCCESS;
86 break;
87
88 case REWRITE_REGEXEC_UNWILLING:
89 if ( dc->rs ) {
90 dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
91 dc->rs->sr_text = "Operation not allowed";
92 }
93 rc = LDAP_UNWILLING_TO_PERFORM;
94 break;
95
96 case REWRITE_REGEXEC_ERR:
97 if ( dc->rs ) {
98 dc->rs->sr_err = LDAP_OTHER;
99 dc->rs->sr_text = "Rewrite error";
100 }
101 rc = LDAP_OTHER;
102 break;
103 }
104
105 if ( res->bv_val == dmy ) {
106 BER_BVZERO( res );
107 }
108
109 return rc;
110 }