2 ldb database mapping module
4 Copyright (C) Jelmer Vernooij 2005
5 Copyright (C) Martin Kuehl <mkhl@samba.org> 2006
7 ** NOTE! The following LGPL license applies to the ldb
8 ** library. This does NOT imply that all of Samba is released
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.
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.
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/>.
29 /* ldb_map is a skeleton LDB module that can be used for any other modules
30 * that need to map attributes.
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.
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)
43 /* Name of the internal attribute pointing from the local to the
44 * remote part of a record */
45 #define IS_MAPPED "isMapped"
48 struct ldb_map_context;
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);
53 #define LDB_MAP_MAX_REMOTE_NAMES 10
55 /* map from local to remote attribute */
56 struct ldb_map_attribute {
57 const char *local_name; /* local name */
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. */
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 *);
74 const char *remote_name;
78 const char *remote_name;
80 /* Convert local to remote data */
81 ldb_map_convert_func convert_local;
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;
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);
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);
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
99 const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
101 /* Names of additional remote attributes
102 * required for the generation. NULL
103 * indicates that `local_attr' suffices. */
105 #define LDB_MAP_MAX_SELF_ATTRIBUTES 10
106 const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES];
113 #define LDB_MAP_MAX_SUBCLASSES 10
114 #define LDB_MAP_MAX_MUSTS 10
115 #define LDB_MAP_MAX_MAYS 50
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];
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;
133 /* Remote (often operational) attributes that should be added
134 * to any wildcard search */
135 const char * const *wildcard_attributes;
137 /* ObjectClass (if any) to be added to remote attributes on add */
138 const char *add_objectclass;
140 /* struct ldb_context *mapped_ldb; */
141 struct ldb_dn *local_base_dn;
142 struct ldb_dn *remote_base_dn;
145 /* Global private data */
147 void *caller_private;
148 struct ldb_map_context *context;
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,
158 int map_add(struct ldb_module *module, struct ldb_request *req);
159 int map_search(struct ldb_module *module, struct ldb_request *req);
160 int map_rename(struct ldb_module *module, struct ldb_request *req);
161 int map_delete(struct ldb_module *module, struct ldb_request *req);
162 int map_modify(struct ldb_module *module, struct ldb_request *req);
164 #define LDB_MAP_OPS \
166 .modify = map_modify, \
168 .rename = map_rename, \
169 .search = map_search,
171 #endif /* __LDB_MAP_H__ */