upgradeprovision: never use xattr it's pointless in this usecase
[Samba/ekacnet.git] / source3 / lib / ldb / modules / ldb_map.h
blob4457c6fc1d73dded7004533c8e58f21bf42aa1be
1 /*
2 ldb database mapping module
4 Copyright (C) Jelmer Vernooij 2005
5 Copyright (C) Martin Kuehl <mkhl@samba.org> 2006
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.
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.
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.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #ifndef __LDB_MAP_H__
26 #define __LDB_MAP_H__
28 /* ldb_map is a skeleton LDB module that can be used for any other modules
29 * that need to map attributes.
31 * The term 'remote' in this header refers to the connection where the
32 * original schema is used on while 'local' means the local connection
33 * that any upper layers will use.
35 * All local attributes will have to have a definition. Not all remote
36 * attributes need a definition as LDB is a lot less strict than LDAP
37 * (in other words, sending unknown attributes to an LDAP server hurts us,
38 * while returning too many attributes in ldb_search() doesn't)
42 /* Name of the internal attribute pointing from the local to the
43 * remote part of a record */
44 #define IS_MAPPED "isMapped"
47 struct ldb_map_context;
49 /* convert a local ldb_val to a remote ldb_val */
50 typedef struct ldb_val (*ldb_map_convert_func) (struct ldb_module *module, void *mem_ctx, const struct ldb_val *val);
52 #define LDB_MAP_MAX_REMOTE_NAMES 10
54 /* map from local to remote attribute */
55 struct ldb_map_attribute {
56 const char *local_name; /* local name */
58 enum ldb_map_attr_type {
59 MAP_IGNORE, /* Ignore this local attribute. Doesn't exist remotely. */
60 MAP_KEEP, /* Keep as is. Same name locally and remotely. */
61 MAP_RENAME, /* Simply rename the attribute. Name changes, data is the same */
62 MAP_CONVERT, /* Rename + convert data */
63 MAP_GENERATE /* Use generate function for generating new name/data.
64 Used for generating attributes based on
65 multiple remote attributes. */
66 } type;
68 /* if set, will be called for search expressions that contain this attribute */
69 int (*convert_operator)(struct ldb_module *, TALLOC_CTX *ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *);
71 union {
72 struct {
73 const char *remote_name;
74 } rename;
76 struct {
77 const char *remote_name;
79 /* Convert local to remote data */
80 ldb_map_convert_func convert_local;
82 /* Convert remote to local data */
83 /* an entry can have convert_remote set to NULL, as long as there as an entry with the same local_name
84 * that is non-NULL before it. */
85 ldb_map_convert_func convert_remote;
86 } convert;
88 struct {
89 /* Generate the local attribute from remote message */
90 struct ldb_message_element *(*generate_local)(struct ldb_module *, TALLOC_CTX *mem_ctx, const char *remote_attr, const struct ldb_message *remote);
92 /* Update remote message with information from local message */
93 void (*generate_remote)(struct ldb_module *, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local);
95 /* Name(s) for this attribute on the remote server. This is an array since
96 * one local attribute's data can be split up into several attributes
97 * remotely */
98 const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
100 /* Names of additional remote attributes
101 * required for the generation. NULL
102 * indicates that `local_attr' suffices. */
104 #define LDB_MAP_MAX_SELF_ATTRIBUTES 10
105 const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES];
107 } generate;
108 } u;
112 #define LDB_MAP_MAX_SUBCLASSES 10
113 #define LDB_MAP_MAX_MUSTS 10
114 #define LDB_MAP_MAX_MAYS 50
116 /* map from local to remote objectClass */
117 struct ldb_map_objectclass {
118 const char *local_name;
119 const char *remote_name;
120 const char *base_classes[LDB_MAP_MAX_SUBCLASSES];
121 const char *musts[LDB_MAP_MAX_MUSTS];
122 const char *mays[LDB_MAP_MAX_MAYS];
126 /* private context data */
127 struct ldb_map_context {
128 struct ldb_map_attribute *attribute_maps;
129 /* NOTE: Always declare base classes first here */
130 const struct ldb_map_objectclass *objectclass_maps;
132 /* Remote (often operational) attributes that should be added
133 * to any wildcard search */
134 const char * const *wildcard_attributes;
136 /* struct ldb_context *mapped_ldb; */
137 const struct ldb_dn *local_base_dn;
138 const struct ldb_dn *remote_base_dn;
141 /* Global private data */
142 struct map_private {
143 void *caller_private;
144 struct ldb_map_context *context;
147 /* Initialize global private data. */
148 int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs,
149 const struct ldb_map_objectclass *ocls,
150 const char * const *wildcard_attributes,
151 const char *name);
153 /* get copy of map_ops */
154 struct ldb_module_ops
155 ldb_map_get_ops(void);
157 #endif /* __LDB_MAP_H__ */