]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/rwm.h
59e440c58744beb2a70b0c8a07b0f22714d008d1
[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-2005 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 /* String rewrite library */
28 #ifdef ENABLE_REWRITE
29 #include "rewrite.h"
30 #endif /* ENABLE_REWRITE */
31
32 LDAP_BEGIN_DECL
33
34 /* define to enable referral DN massage by default */
35 #undef RWM_REFERRAL_REWRITE
36
37 struct ldapmap {
38         int drop_missing;
39
40         Avlnode *map;
41         Avlnode *remap;
42 };
43
44 struct ldapmapping {
45         int                     m_flags;
46 #define RWMMAP_F_NONE           0x00
47 #define RWMMAP_F_IS_OC          0x01
48 #define RWMMAP_F_FREE_SRC       0x10
49 #define RWMMAP_F_FREE_DST       0x20
50         struct berval           m_src;
51         union {
52                 AttributeDescription    *m_s_ad;
53                 ObjectClass             *m_s_oc;
54         } m_src_ref;
55 #define m_src_ad        m_src_ref.m_s_ad
56 #define m_src_oc        m_src_ref.m_s_oc
57         struct berval           m_dst;
58         union {
59                 AttributeDescription    *m_d_ad;
60                 ObjectClass             *m_d_oc;
61         } m_dst_ref;
62 #define m_dst_ad        m_dst_ref.m_d_ad
63 #define m_dst_oc        m_dst_ref.m_d_oc
64 };
65
66 struct ldaprwmap {
67         /*
68          * DN rewriting
69          */
70 #ifdef ENABLE_REWRITE
71         struct rewrite_info *rwm_rw;
72 #else /* !ENABLE_REWRITE */
73         /* some time the suffix massaging without librewrite
74          * will be disabled */
75         BerVarray rwm_suffix_massage;
76 #endif /* !ENABLE_REWRITE */
77
78         /*
79          * Attribute/objectClass mapping
80          */
81         struct ldapmap rwm_oc;
82         struct ldapmap rwm_at;
83 };
84
85 /* Whatever context ldap_back_dn_massage needs... */
86 typedef struct dncookie {
87         struct ldaprwmap *rwmap;
88
89 #ifdef ENABLE_REWRITE
90         Connection *conn;
91         char *ctx;
92         SlapReply *rs;
93 #else /* !ENABLE_REWRITE */
94         int normalized;
95         int tofrom;
96 #endif /* !ENABLE_REWRITE */
97 } dncookie;
98
99 int rwm_dn_massage( dncookie *dc, struct berval *in, struct berval *dn );
100 int rwm_dn_massage_pretty( dncookie *dc, struct berval *in, struct berval *pdn );
101 int rwm_dn_massage_normalize( dncookie *dc, struct berval *in, struct berval *ndn );
102 int rwm_dn_massage_pretty_normalize( dncookie *dc, struct berval *in, struct berval *pdn, struct berval *ndn );
103
104 /* attributeType/objectClass mapping */
105 int rwm_mapping_cmp (const void *, const void *);
106 int rwm_mapping_dup (void *, void *);
107
108 int rwm_map_init ( struct ldapmap *lm, struct ldapmapping ** );
109 void rwm_map ( struct ldapmap *map, struct berval *s, struct berval *m,
110         int remap );
111 int rwm_mapping ( struct ldapmap *map, struct berval *s,
112                 struct ldapmapping **m, int remap );
113 #define RWM_MAP 0
114 #define RWM_REMAP       1
115 char *
116 rwm_map_filter(
117                 struct ldapmap *at_map,
118                 struct ldapmap *oc_map,
119                 struct berval *f );
120
121 int
122 rwm_map_attrs(
123                 struct ldapmap *at_map,
124                 AttributeName *a,
125                 int remap,
126                 char ***mapped_attrs );
127
128 int
129 rwm_map_attrnames(
130                 struct ldapmap *at_map,
131                 struct ldapmap *oc_map,
132                 AttributeName *an,
133                 AttributeName **anp,
134                 int remap );
135
136 extern void rwm_mapping_free ( void *mapping );
137
138 extern int rwm_map_config(
139                 struct ldapmap  *oc_map,
140                 struct ldapmap  *at_map,
141                 const char      *fname,
142                 int             lineno,
143                 int             argc,
144                 char            **argv );
145
146 extern int
147 rwm_filter_map_rewrite(
148                 dncookie                *dc,
149                 Filter                  *f,
150                 struct berval           *fstr );
151
152 /* suffix massaging by means of librewrite */
153 #ifdef ENABLE_REWRITE
154 extern int rwm_suffix_massage_config( struct rewrite_info *info,
155                 struct berval *pvnc, struct berval *nvnc,
156                 struct berval *prnc, struct berval *nrnc);
157 #endif /* ENABLE_REWRITE */
158 extern int rwm_dnattr_rewrite(
159         Operation               *op,
160         SlapReply               *rs,
161         void                    *cookie,
162         BerVarray               a_vals,
163         BerVarray               *pa_nvals );
164 extern int rwm_referral_rewrite(
165         Operation               *op,
166         SlapReply               *rs,
167         void                    *cookie,
168         BerVarray               a_vals,
169         BerVarray               *pa_nvals );
170 extern int rwm_dnattr_result_rewrite( dncookie *dc, BerVarray a_vals );
171 extern int rwm_referral_result_rewrite( dncookie *dc, BerVarray a_vals );
172
173 LDAP_END_DECL
174
175 #endif /* RWM_H */