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 | #include "ldb_module.h"
|
---|
30 |
|
---|
31 | /* ldb_map is a skeleton LDB module that can be used for any other modules
|
---|
32 | * that need to map attributes.
|
---|
33 | *
|
---|
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.
|
---|
37 | *
|
---|
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)
|
---|
42 | */
|
---|
43 |
|
---|
44 |
|
---|
45 | /* Name of the internal attribute pointing from the local to the
|
---|
46 | * remote part of a record */
|
---|
47 | #define IS_MAPPED "isMapped"
|
---|
48 |
|
---|
49 |
|
---|
50 | struct ldb_map_context;
|
---|
51 |
|
---|
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);
|
---|
54 |
|
---|
55 | #define LDB_MAP_MAX_REMOTE_NAMES 10
|
---|
56 |
|
---|
57 | /* map from local to remote attribute */
|
---|
58 | struct ldb_map_attribute {
|
---|
59 | const char *local_name; /* local name */
|
---|
60 |
|
---|
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 | } type;
|
---|
70 |
|
---|
71 | /* if set, will be called for search expressions that contain this attribute */
|
---|
72 | int (*convert_operator)(struct ldb_module *, TALLOC_CTX *ctx, struct ldb_parse_tree **ntree, const struct ldb_parse_tree *otree);
|
---|
73 |
|
---|
74 | union {
|
---|
75 | struct {
|
---|
76 | const char *remote_name;
|
---|
77 | } rename;
|
---|
78 |
|
---|
79 | struct {
|
---|
80 | const char *remote_name;
|
---|
81 |
|
---|
82 | /* Convert local to remote data */
|
---|
83 | ldb_map_convert_func convert_local;
|
---|
84 |
|
---|
85 | /* Convert remote to local data */
|
---|
86 | /* an entry can have convert_remote set to NULL, as long as there as an entry with the same local_name
|
---|
87 | * that is non-NULL before it. */
|
---|
88 | ldb_map_convert_func convert_remote;
|
---|
89 | } convert;
|
---|
90 |
|
---|
91 | struct {
|
---|
92 | /* Generate the local attribute from remote message */
|
---|
93 | struct ldb_message_element *(*generate_local)(struct ldb_module *, TALLOC_CTX *mem_ctx, const char *remote_attr, const struct ldb_message *remote);
|
---|
94 |
|
---|
95 | /* Update remote message with information from local message */
|
---|
96 | void (*generate_remote)(struct ldb_module *, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local);
|
---|
97 |
|
---|
98 | /* Name(s) for this attribute on the remote server. This is an array since
|
---|
99 | * one local attribute's data can be split up into several attributes
|
---|
100 | * remotely */
|
---|
101 | const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
|
---|
102 |
|
---|
103 | /* Names of additional remote attributes
|
---|
104 | * required for the generation. NULL
|
---|
105 | * indicates that `local_attr' suffices. */
|
---|
106 | /*
|
---|
107 | #define LDB_MAP_MAX_SELF_ATTRIBUTES 10
|
---|
108 | const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES];
|
---|
109 | */
|
---|
110 | } generate;
|
---|
111 | } u;
|
---|
112 | };
|
---|
113 |
|
---|
114 |
|
---|
115 | #define LDB_MAP_MAX_SUBCLASSES 10
|
---|
116 | #define LDB_MAP_MAX_MUSTS 10
|
---|
117 | #define LDB_MAP_MAX_MAYS 50
|
---|
118 |
|
---|
119 | /* map from local to remote objectClass */
|
---|
120 | struct ldb_map_objectclass {
|
---|
121 | const char *local_name;
|
---|
122 | const char *remote_name;
|
---|
123 | const char *base_classes[LDB_MAP_MAX_SUBCLASSES];
|
---|
124 | const char *musts[LDB_MAP_MAX_MUSTS];
|
---|
125 | const char *mays[LDB_MAP_MAX_MAYS];
|
---|
126 | };
|
---|
127 |
|
---|
128 |
|
---|
129 | /* private context data */
|
---|
130 | struct ldb_map_context {
|
---|
131 | struct ldb_map_attribute *attribute_maps;
|
---|
132 | /* NOTE: Always declare base classes first here */
|
---|
133 | const struct ldb_map_objectclass *objectclass_maps;
|
---|
134 |
|
---|
135 | /* Remote (often operational) attributes that should be added
|
---|
136 | * to any wildcard search */
|
---|
137 | const char * const *wildcard_attributes;
|
---|
138 |
|
---|
139 | /* ObjectClass (if any) to be added to remote attributes on add */
|
---|
140 | const char *add_objectclass;
|
---|
141 |
|
---|
142 | /* struct ldb_context *mapped_ldb; */
|
---|
143 | struct ldb_dn *local_base_dn;
|
---|
144 | struct ldb_dn *remote_base_dn;
|
---|
145 | };
|
---|
146 |
|
---|
147 | /* Global private data */
|
---|
148 | struct map_private {
|
---|
149 | void *caller_private;
|
---|
150 | struct ldb_map_context *context;
|
---|
151 | };
|
---|
152 |
|
---|
153 | /* Initialize global private data. */
|
---|
154 | int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs,
|
---|
155 | const struct ldb_map_objectclass *ocls,
|
---|
156 | const char * const *wildcard_attributes,
|
---|
157 | const char *add_objectclass,
|
---|
158 | const char *name);
|
---|
159 |
|
---|
160 | int ldb_map_add(struct ldb_module *module, struct ldb_request *req);
|
---|
161 | int ldb_map_search(struct ldb_module *module, struct ldb_request *req);
|
---|
162 | int ldb_map_rename(struct ldb_module *module, struct ldb_request *req);
|
---|
163 | int ldb_map_delete(struct ldb_module *module, struct ldb_request *req);
|
---|
164 | int ldb_map_modify(struct ldb_module *module, struct ldb_request *req);
|
---|
165 |
|
---|
166 | #define LDB_MAP_OPS \
|
---|
167 | .add = ldb_map_add, \
|
---|
168 | .modify = ldb_map_modify, \
|
---|
169 | .del = ldb_map_delete, \
|
---|
170 | .rename = ldb_map_rename, \
|
---|
171 | .search = ldb_map_search,
|
---|
172 |
|
---|
173 | #endif /* __LDB_MAP_H__ */
|
---|