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 #include "ldb_module.h"
31 /* ldb_map is a skeleton LDB module that can be used for any other modules
32 * that need to map attributes.
34 * The term 'remote' in this header refers to the connection where the
35 * original schema is used on while 'local' means the local connection
36 * that any upper layers will use.
38 * All local attributes will have to have a definition. Not all remote
39 * attributes need a definition as LDB is a lot less strict than LDAP
40 * (in other words, sending unknown attributes to an LDAP server hurts us,
41 * while returning too many attributes in ldb_search() doesn't)
45 /* Name of the internal attribute pointing from the local to the
46 * remote part of a record */
47 #define IS_MAPPED "isMapped"
50 struct ldb_map_context
;
52 /* convert a local ldb_val to a remote ldb_val */
53 typedef struct ldb_val (*ldb_map_convert_func
) (struct ldb_module
*module
, void *mem_ctx
, const struct ldb_val
*val
);
55 #define LDB_MAP_MAX_REMOTE_NAMES 10
57 /* map from local to remote attribute */
58 struct ldb_map_attribute
{
59 const char *local_name
; /* local name */
61 enum ldb_map_attr_type
{
62 LDB_MAP_IGNORE
, /* Ignore this local attribute. Doesn't exist remotely. */
63 LDB_MAP_KEEP
, /* Keep as is. Same name locally and remotely. */
64 LDB_MAP_RENAME
, /* Simply rename the attribute. Name changes, data is the same */
65 LDB_MAP_CONVERT
, /* Rename + convert data */
66 LDB_MAP_GENERATE
, /* Use generate function for generating new name/data.
67 Used for generating attributes based on
68 multiple remote attributes. */
69 LDB_MAP_RENDROP
/* Rename the attribute. Strip from Add requests. */
72 /* if set, will be called for search expressions that contain this attribute */
73 int (*convert_operator
)(struct ldb_module
*, TALLOC_CTX
*ctx
, struct ldb_parse_tree
**ntree
, const struct ldb_parse_tree
*otree
);
77 const char *remote_name
;
81 const char *remote_name
;
83 /* Convert local to remote data */
84 ldb_map_convert_func convert_local
;
86 /* Convert remote to local data */
87 /* an entry can have convert_remote set to NULL, as long as there as an entry with the same local_name
88 * that is non-NULL before it. */
89 ldb_map_convert_func convert_remote
;
93 /* Generate the local attribute from remote message */
94 struct ldb_message_element
*(*generate_local
)(struct ldb_module
*, TALLOC_CTX
*mem_ctx
, const char *remote_attr
, const struct ldb_message
*remote
);
96 /* Update remote message with information from local message */
97 void (*generate_remote
)(struct ldb_module
*, const char *local_attr
, const struct ldb_message
*old
, struct ldb_message
*remote
, struct ldb_message
*local
);
99 /* Name(s) for this attribute on the remote server. This is an array since
100 * one local attribute's data can be split up into several attributes
102 const char *remote_names
[LDB_MAP_MAX_REMOTE_NAMES
];
104 /* Names of additional remote attributes
105 * required for the generation. NULL
106 * indicates that `local_attr' suffices. */
108 #define LDB_MAP_MAX_SELF_ATTRIBUTES 10
109 const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES];
116 #define LDB_MAP_MAX_SUBCLASSES 10
117 #define LDB_MAP_MAX_MUSTS 10
118 #define LDB_MAP_MAX_MAYS 50
120 /* map from local to remote objectClass */
121 struct ldb_map_objectclass
{
122 const char *local_name
;
123 const char *remote_name
;
124 const char *base_classes
[LDB_MAP_MAX_SUBCLASSES
];
125 const char *musts
[LDB_MAP_MAX_MUSTS
];
126 const char *mays
[LDB_MAP_MAX_MAYS
];
130 /* private context data */
131 struct ldb_map_context
{
132 struct ldb_map_attribute
*attribute_maps
;
133 /* NOTE: Always declare base classes first here */
134 const struct ldb_map_objectclass
*objectclass_maps
;
136 /* Remote (often operational) attributes that should be added
137 * to any wildcard search */
138 const char * const *wildcard_attributes
;
140 /* ObjectClass (if any) to be added to remote attributes on add */
141 const char *add_objectclass
;
143 /* struct ldb_context *mapped_ldb; */
144 struct ldb_dn
*local_base_dn
;
145 struct ldb_dn
*remote_base_dn
;
148 /* Global private data */
150 void *caller_private
;
151 struct ldb_map_context
*context
;
154 /* Initialize global private data. */
155 int ldb_map_init(struct ldb_module
*module
, const struct ldb_map_attribute
*attrs
,
156 const struct ldb_map_objectclass
*ocls
,
157 const char * const *wildcard_attributes
,
158 const char *add_objectclass
,
161 int ldb_map_add(struct ldb_module
*module
, struct ldb_request
*req
);
162 int ldb_map_search(struct ldb_module
*module
, struct ldb_request
*req
);
163 int ldb_map_rename(struct ldb_module
*module
, struct ldb_request
*req
);
164 int ldb_map_delete(struct ldb_module
*module
, struct ldb_request
*req
);
165 int ldb_map_modify(struct ldb_module
*module
, struct ldb_request
*req
);
167 #define LDB_MAP_OPS \
168 .add = ldb_map_add, \
169 .modify = ldb_map_modify, \
170 .del = ldb_map_delete, \
171 .rename = ldb_map_rename, \
172 .search = ldb_map_search,
174 #endif /* __LDB_MAP_H__ */