Until the new ldb changes land, make ldb_wait set the error string.
[kai/samba.git] / source / lib / ldb / ldb_map / ldb_map.h
1 /*
2    ldb database mapping module
3
4    Copyright (C) Jelmer Vernooij 2005
5    Copyright (C) Martin Kuehl <mkhl@samba.org> 2006
6
7      ** NOTE! The following LGPL license applies to the ldb
8      ** library. This does NOT imply that all of Samba is released
9      ** under the LGPL
10    
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Lesser General Public
13    License as published by the Free Software Foundation; either
14    version 3 of the License, or (at your option) any later version.
15
16    This library is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    Lesser General Public License for more details.
20
21    You should have received a copy of the GNU Lesser General Public
22    License along with this library; if not, see <http://www.gnu.org/licenses/>.
23
24 */
25
26 #ifndef __LDB_MAP_H__
27 #define __LDB_MAP_H__
28
29 /* ldb_map is a skeleton LDB module that can be used for any other modules
30  * that need to map attributes.
31  *
32  * The term 'remote' in this header refers to the connection where the 
33  * original schema is used on while 'local' means the local connection 
34  * that any upper layers will use.
35  *
36  * All local attributes will have to have a definition. Not all remote 
37  * attributes need a definition as LDB is a lot less strict than LDAP 
38  * (in other words, sending unknown attributes to an LDAP server hurts us, 
39  * while returning too many attributes in ldb_search() doesn't)
40  */
41
42
43 /* Name of the internal attribute pointing from the local to the
44  * remote part of a record */
45 #define IS_MAPPED "isMapped"
46
47
48 struct ldb_map_context;
49
50 /* convert a local ldb_val to a remote ldb_val */
51 typedef struct ldb_val (*ldb_map_convert_func) (struct ldb_module *module, void *mem_ctx, const struct ldb_val *val);
52
53 #define LDB_MAP_MAX_REMOTE_NAMES 10
54
55 /* map from local to remote attribute */
56 struct ldb_map_attribute {
57         const char *local_name; /* local name */
58
59         enum ldb_map_attr_type { 
60                 MAP_IGNORE, /* Ignore this local attribute. Doesn't exist remotely.  */
61                 MAP_KEEP,   /* Keep as is. Same name locally and remotely. */
62                 MAP_RENAME, /* Simply rename the attribute. Name changes, data is the same */
63                 MAP_CONVERT, /* Rename + convert data */
64                 MAP_GENERATE /* Use generate function for generating new name/data. 
65                                                 Used for generating attributes based on 
66                                                 multiple remote attributes. */
67         } type;
68         
69         /* if set, will be called for search expressions that contain this attribute */
70         int (*convert_operator)(struct ldb_module *, TALLOC_CTX *ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *);
71
72         union { 
73                 struct {
74                         const char *remote_name;
75                 } rename;
76                 
77                 struct {
78                         const char *remote_name;
79
80                         /* Convert local to remote data */
81                         ldb_map_convert_func convert_local;
82
83                         /* Convert remote to local data */
84                         /* an entry can have convert_remote set to NULL, as long as there as an entry with the same local_name 
85                          * that is non-NULL before it. */
86                         ldb_map_convert_func convert_remote;
87                 } convert;
88         
89                 struct {
90                         /* Generate the local attribute from remote message */
91                         struct ldb_message_element *(*generate_local)(struct ldb_module *, TALLOC_CTX *mem_ctx, const char *remote_attr, const struct ldb_message *remote);
92
93                         /* Update remote message with information from local message */
94                         void (*generate_remote)(struct ldb_module *, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local);
95
96                         /* Name(s) for this attribute on the remote server. This is an array since 
97                          * one local attribute's data can be split up into several attributes 
98                          * remotely */
99                         const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
100
101                         /* Names of additional remote attributes
102                          * required for the generation.  NULL
103                          * indicates that `local_attr' suffices. */
104                         /*
105 #define LDB_MAP_MAX_SELF_ATTRIBUTES 10
106                         const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES];
107                         */
108                 } generate;
109         } u;
110 };
111
112
113 #define LDB_MAP_MAX_SUBCLASSES  10
114 #define LDB_MAP_MAX_MUSTS               10
115 #define LDB_MAP_MAX_MAYS                50
116
117 /* map from local to remote objectClass */
118 struct ldb_map_objectclass {
119         const char *local_name;
120         const char *remote_name;
121         const char *base_classes[LDB_MAP_MAX_SUBCLASSES];
122         const char *musts[LDB_MAP_MAX_MUSTS];
123         const char *mays[LDB_MAP_MAX_MAYS];
124 };
125
126
127 /* private context data */
128 struct ldb_map_context {
129         struct ldb_map_attribute *attribute_maps;
130         /* NOTE: Always declare base classes first here */
131         const struct ldb_map_objectclass *objectclass_maps;
132
133         /* Remote (often operational) attributes that should be added
134          * to any wildcard search */
135         const char * const *wildcard_attributes;
136
137         /* ObjectClass (if any) to be added to remote attributes on add */
138         const char *add_objectclass;
139
140         /* struct ldb_context *mapped_ldb; */
141         struct ldb_dn *local_base_dn;
142         struct ldb_dn *remote_base_dn;
143 };
144
145 /* Global private data */
146 struct map_private {
147         void *caller_private;
148         struct ldb_map_context *context;
149 };
150
151 /* Initialize global private data. */
152 int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, 
153                  const struct ldb_map_objectclass *ocls,
154                  const char * const *wildcard_attributes,
155                  const char *add_objectclass,
156                  const char *name);
157
158 /* get copy of map_ops */
159 struct ldb_module_ops
160 ldb_map_get_ops(void);
161
162 #endif /* __LDB_MAP_H__ */