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