2 ldb database library - map backend
4 Copyright (C) Jelmer Vernooij 2005
5 Copyright (C) Martin Kuehl <mkhl@samba.org> 2006
6 Development sponsored by the Google Summer of Code program
8 ** NOTE! The following LGPL license applies to the ldb
9 ** library. This does NOT imply that all of Samba is released
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 2 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with this library; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 /* ldb_map is a skeleton LDB module that can be used for any other modules
31 * that need to map attributes.
33 * The term 'remote' in this header refers to the connection where the
34 * original schema is used on while 'local' means the local connection
35 * that any upper layers will use.
37 * All local attributes will have to have a definition. Not all remote
38 * attributes need a definition as LDB is a lot less strict than LDAP
39 * (in other words, sending unknown attributes to an LDAP server hurts us,
40 * while returning too many attributes in ldb_search() doesn't)
44 /* Name of the internal attribute pointing from the local to the
45 * remote part of a record */
46 #define IS_MAPPED "isMapped"
49 struct ldb_map_context;
51 /* convert a local ldb_val to a remote ldb_val */
52 typedef struct ldb_val (*ldb_map_convert_func) (struct ldb_module *module, void *mem_ctx, const struct ldb_val *val);
54 #define LDB_MAP_MAX_REMOTE_NAMES 10
56 /* map from local to remote attribute */
57 struct ldb_map_attribute {
58 const char *local_name; /* local name */
60 enum ldb_map_attr_type {
61 MAP_IGNORE, /* Ignore this local attribute. Doesn't exist remotely. */
62 MAP_KEEP, /* Keep as is. Same name locally and remotely. */
63 MAP_RENAME, /* Simply rename the attribute. Name changes, data is the same */
64 MAP_CONVERT, /* Rename + convert data */
65 MAP_GENERATE /* Use generate function for generating new name/data.
66 Used for generating attributes based on
67 multiple remote attributes. */
70 /* if set, will be called for search expressions that contain this attribute */
71 struct ldb_parse_tree *(*convert_operator)(const struct ldb_map_context *, TALLOC_CTX *ctx, const struct ldb_parse_tree *);
75 const char *remote_name;
79 const char *remote_name;
81 /* Convert local to remote data */
82 ldb_map_convert_func convert_local;
84 /* Convert remote to local data */
85 /* an entry can have convert_remote set to NULL, as long as there as an entry with the same local_name
86 * that is non-NULL before it. */
87 ldb_map_convert_func convert_remote;
91 /* Generate the local attribute from remote message */
92 struct ldb_message_element *(*generate_local)(struct ldb_module *, TALLOC_CTX *mem_ctx, const char *remote_attr, const struct ldb_message *remote);
94 /* Update remote message with information from local message */
95 void (*generate_remote)(struct ldb_module *, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local);
97 /* Name(s) for this attribute on the remote server. This is an array since
98 * one local attribute's data can be split up into several attributes
100 const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
102 /* Names of additional remote attributes
103 * required for the generation. NULL
104 * indicates that `local_attr' suffices. */
106 #define LDB_MAP_MAX_SELF_ATTRIBUTES 10
107 const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES];
114 #define LDB_MAP_MAX_SUBCLASSES 10
115 #define LDB_MAP_MAX_MUSTS 10
116 #define LDB_MAP_MAX_MAYS 50
118 /* map from local to remote objectClass */
119 struct ldb_map_objectclass {
120 const char *local_name;
121 const char *remote_name;
122 const char *base_classes[LDB_MAP_MAX_SUBCLASSES];
123 const char *musts[LDB_MAP_MAX_MUSTS];
124 const char *mays[LDB_MAP_MAX_MAYS];
128 /* private context data */
129 struct ldb_map_context {
130 struct ldb_map_attribute *attribute_maps;
131 /* NOTE: Always declare base classes first here */
132 const struct ldb_map_objectclass *objectclass_maps;
133 /* struct ldb_context *mapped_ldb; */
134 const struct ldb_dn *local_base_dn;
135 const struct ldb_dn *remote_base_dn;
138 /* initialization function */
140 ldb_map_init(struct ldb_module *module,
141 const struct ldb_map_attribute *attrs,
142 const struct ldb_map_objectclass *ocls,
145 /* get copy of map_ops */
146 struct ldb_module_ops
147 ldb_map_get_ops(void);
149 #endif /* __LDB_MAP_H__ */