]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/rwm.h
dac9f740ac7e07a522ee0329847179e657f15f60
[openldap] / servers / slapd / overlays / rwm.h
1 /* rwm.h - dn rewrite/attribute mapping header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1999-2015 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
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>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #ifndef RWM_H
25 #define RWM_H
26
27 #ifndef ENABLE_REWRITE
28 #error "librewrite must be enabled!"
29 #endif /* ENABLE_REWRITE */
30
31 /* String rewrite library */
32 #include "rewrite.h"
33
34 LDAP_BEGIN_DECL
35
36 /* define to enable referral DN massage by default */
37 #undef RWM_REFERRAL_REWRITE
38
39 struct ldapmap {
40         int drop_missing;
41
42         Avlnode *map;
43         Avlnode *remap;
44 };
45
46 struct ldapmapping {
47         int                     m_flags;
48 #define RWMMAP_F_NONE           0x00
49 #define RWMMAP_F_IS_OC          0x01
50 #define RWMMAP_F_FREE_SRC       0x10
51 #define RWMMAP_F_FREE_DST       0x20
52         struct berval           m_src;
53         union {
54                 AttributeDescription    *m_s_ad;
55                 ObjectClass             *m_s_oc;
56         } m_src_ref;
57 #define m_src_ad        m_src_ref.m_s_ad
58 #define m_src_oc        m_src_ref.m_s_oc
59         struct berval           m_dst;
60         union {
61                 AttributeDescription    *m_d_ad;
62                 ObjectClass             *m_d_oc;
63         } m_dst_ref;
64 #define m_dst_ad        m_dst_ref.m_d_ad
65 #define m_dst_oc        m_dst_ref.m_d_oc
66 };
67
68 struct ldaprwmap {
69         /*
70          * DN rewriting
71          */
72         struct rewrite_info *rwm_rw;
73         BerVarray rwm_bva_rewrite;
74
75         /*
76          * Attribute/objectClass mapping
77          */
78         struct ldapmap rwm_oc;
79         struct ldapmap rwm_at;
80         BerVarray rwm_bva_map;
81
82 #define RWM_F_NONE                      (0x0000U)
83 #define RWM_F_NORMALIZE_MAPPED_ATTRS    (0x0001U)
84 #define RWM_F_DROP_UNREQUESTED_ATTRS    (0x0002U)
85 #define RWM_F_SUPPORT_T_F               (0x4000U)
86 #define RWM_F_SUPPORT_T_F_DISCOVER      (0x8000U)
87 #define RWM_F_SUPPORT_T_F_MASK          (RWM_F_SUPPORT_T_F)
88 #define RWM_F_SUPPORT_T_F_MASK2         (RWM_F_SUPPORT_T_F|RWM_F_SUPPORT_T_F_DISCOVER)
89         unsigned        rwm_flags;
90 };
91
92 /* Whatever context ldap_back_dn_massage needs... */
93 typedef struct dncookie {
94         struct ldaprwmap *rwmap;
95
96         Connection *conn;
97         char *ctx;
98         SlapReply *rs;
99 } dncookie;
100
101 int rwm_dn_massage( dncookie *dc, struct berval *in, struct berval *dn );
102 int rwm_dn_massage_pretty( dncookie *dc, struct berval *in, struct berval *pdn );
103 int rwm_dn_massage_normalize( dncookie *dc, struct berval *in, struct berval *ndn );
104 int rwm_dn_massage_pretty_normalize( dncookie *dc, struct berval *in, struct berval *pdn, struct berval *ndn );
105
106 /* attributeType/objectClass mapping */
107 int rwm_mapping_cmp (const void *, const void *);
108 int rwm_mapping_dup (void *, void *);
109
110 int rwm_map_init ( struct ldapmap *lm, struct ldapmapping ** );
111 void rwm_map ( struct ldapmap *map, struct berval *s, struct berval *m,
112         int remap );
113 int rwm_mapping ( struct ldapmap *map, struct berval *s,
114                 struct ldapmapping **m, int remap );
115 #define RWM_MAP         0
116 #define RWM_REMAP       1
117 char *
118 rwm_map_filter(
119                 struct ldapmap *at_map,
120                 struct ldapmap *oc_map,
121                 struct berval *f );
122
123 #if 0 /* unused! */
124 int
125 rwm_map_attrs(
126                 struct ldapmap *at_map,
127                 AttributeName *a,
128                 int remap,
129                 char ***mapped_attrs );
130 #endif
131
132 int
133 rwm_map_attrnames(
134                 Operation *op,
135                 struct ldapmap *at_map,
136                 struct ldapmap *oc_map,
137                 AttributeName *an,
138                 AttributeName **anp,
139                 int remap );
140
141 extern void rwm_mapping_dst_free ( void *mapping );
142
143 extern void rwm_mapping_free ( void *mapping );
144
145 extern int rwm_map_config(
146                 struct ldapmap  *oc_map,
147                 struct ldapmap  *at_map,
148                 const char      *fname,
149                 int             lineno,
150                 int             argc,
151                 char            **argv );
152
153 extern int
154 rwm_filter_map_rewrite(
155                 Operation               *op,
156                 dncookie                *dc,
157                 Filter                  *f,
158                 struct berval           *fstr );
159
160 /* suffix massaging by means of librewrite */
161 extern int
162 rwm_suffix_massage_config(
163         struct rewrite_info     *info,
164         struct berval           *pvnc,
165         struct berval           *nvnc,
166         struct berval           *prnc,
167         struct berval           *nrnc);
168 extern int
169 rwm_dnattr_rewrite(
170         Operation               *op,
171         SlapReply               *rs,
172         void                    *cookie,
173         BerVarray               a_vals,
174         BerVarray               *pa_nvals );
175 extern int
176 rwm_referral_rewrite(
177         Operation               *op,
178         SlapReply               *rs,
179         void                    *cookie,
180         BerVarray               a_vals,
181         BerVarray               *pa_nvals );
182 extern int rwm_dnattr_result_rewrite( dncookie *dc, BerVarray a_vals, BerVarray a_nvals );
183 extern int rwm_referral_result_rewrite( dncookie *dc, BerVarray a_vals );
184
185 LDAP_END_DECL
186
187 #endif /* RWM_H */