r9744: - [upgrade.js] Start working on smb.conf conversion.
[samba.git] / source4 / lib / ldb / ldb_map / ldb_map.h
1 /* 
2    ldb database library - map backend
3
4    Copyright (C) Jelmer Vernooij 2005
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 #ifndef __LDB_MAP_H__
26 #define __LDB_MAP_H__
27
28 /* ldb_map is a skeleton LDB module that can be used for any other modules
29  * that need to map attributes.
30  *
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.
34  *
35  * All local attributes will have to have a definition. Not all remote 
36  * attributes need a definition as LDB is a lot less stricter then LDAP 
37  * (in other words, sending unknown attributes to an LDAP server hurts us, 
38  * returning too much attributes in ldb_search() doesn't)
39  */
40
41 struct ldb_map_context;
42
43 struct ldb_map_attribute 
44 {
45         const char *local_name; /* local name */
46
47         enum ldb_map_attr_type { 
48                 MAP_IGNORE, /* Ignore this local attribute. Doesn't exist remotely.  */
49                 MAP_KEEP,   /* Keep as is. Same name locally and remotely. */
50                 MAP_RENAME, /* Simply rename the attribute. Name changes, data is the same */
51                 MAP_CONVERT, /* Rename + convert data */
52                 MAP_GENERATE /* Use generate function for generating new name/data. 
53                                                 Used for generating attributes based on 
54                                                 multiple remote attributes. */
55         } type;
56         
57         /* if set, will be called for expressions that contain this attribute */
58         struct ldb_parse_tree *(*convert_operator) (struct ldb_map_context *, TALLOC_CTX *ctx, const struct ldb_parse_tree *);  
59
60         union { 
61                 struct {
62                         const char *remote_name;
63                 } rename;
64                 
65                 struct {
66                         const char *remote_name;
67                         struct ldb_val (*convert_local) (struct ldb_map_context *, TALLOC_CTX *, const struct ldb_val *);
68                         struct ldb_val (*convert_remote) (struct ldb_map_context *, TALLOC_CTX *, const struct ldb_val *);
69                 } convert;
70         
71                 struct {
72                         /* Generate the local attribute from remote message */
73                         struct ldb_message_element *(*generate_local) (
74                                         struct ldb_map_context *, 
75                                         TALLOC_CTX *ctx, 
76                                         const char *attr,
77                                         const struct ldb_message *remote);
78
79                         /* Update remote message with information from local message */
80                         void (*generate_remote) (
81                                         struct ldb_map_context *, 
82                                         const char *local_attr,
83                                         const struct ldb_message *local, 
84                                         struct ldb_message *remote);
85
86                         /* Name(s) for this attribute on the remote server. This is an array since 
87                          * one local attribute's data can be split up into several attributes 
88                          * remotely */
89 #define LDB_MAP_MAX_REMOTE_NAMES 10
90                         const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
91                 } generate;
92         } u;
93 };
94
95 struct ldb_map_objectclass 
96 {
97         const char *local_name;
98         const char *remote_name;
99 };
100
101 struct ldb_map_context
102 {
103         struct ldb_map_attribute *attribute_maps;
104         const struct ldb_map_objectclass *objectclass_maps;
105         struct ldb_context *mapped_ldb;
106 };
107
108 #endif /* __LDB_MAP_H__ */