4eb30669a958276cefbe4dc972df5a5c2ff82e6a
[kai/samba.git] / source3 / lib / ldb / modules / 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    * NOTICE: this module is NOT released under the GNU LGPL license as
8    * other ldb code. This module is release under the GNU GPL v2 or
9    * later license.
10
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 3 of the License, or
14    (at your option) any later version.
15    
16    This program 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
19    GNU General Public License for more details.
20    
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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         /* struct ldb_context *mapped_ldb; */
138         const struct ldb_dn *local_base_dn;
139         const struct ldb_dn *remote_base_dn;
140 };
141
142 /* Global private data */
143 struct map_private {
144         void *caller_private;
145         struct ldb_map_context *context;
146 };
147
148 /* Initialize global private data. */
149 int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, 
150                  const struct ldb_map_objectclass *ocls,
151                  const char * const *wildcard_attributes,
152                  const char *name);
153
154 /* get copy of map_ops */
155 struct ldb_module_ops
156 ldb_map_get_ops(void);
157
158 #endif /* __LDB_MAP_H__ */