7c1e61ca4d34f37deb224fac273aac53cfcde934
[sfrench/samba-autobuild/.git] / source4 / lib / ldb / samba / samba3sam.c
1 /* 
2    ldb database library - Samba3 SAM compatibility 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 #include "includes.h"
26 #include "ldb/ldb_map/ldb_map.h"
27 #include "ldb/include/ldb.h"
28 #include "ldb/include/ldb_private.h"
29
30 /* FIXME: 
31  * sambaSID -> member 
32  * sambaSIDList -> member (special!) 
33  * sambaDomainName -> name 
34  * sambaTrustPassword 
35  * sambaUnixIdPool 
36  * sambaIdmapEntry 
37  * sambaAccountPolicy 
38  * sambaSidEntry 
39  * sambaAcctFlags -> systemFlags ?
40  * sambaPasswordHistory  -> ntPwdHistory*/
41
42 /* Not necessary:
43  * sambaConfig
44  * sambaShare
45  * sambaConfigOption 
46  * sambaNextGroupRid
47  * sambaNextUserRid
48  * sambaAlgorithmicRidBase
49  */
50
51 /* Not in Samba4: 
52  * sambaKickoffTime
53  * sambaPwdCanChange
54  * sambaPwdMustChange
55  * sambaHomePath
56  * sambaHomeDrive
57  * sambaLogonScript
58  * sambaProfilePath
59  * sambaUserWorkstations
60  * sambaMungedDial
61  * sambaLogonHours */
62
63 static struct ldb_message_element *convert_sid_rid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
64 {
65         printf("Converting SID TO RID *\n");
66
67         return talloc_memdup(ctx, el, sizeof(*el));
68 }
69
70 static struct ldb_message_element *convert_rid_sid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
71 {
72         printf("Converting RID TO SID *\n");
73
74         return talloc_memdup(ctx, el, sizeof(*el));
75 }
76
77 static struct ldb_message_element *convert_unix_id2name(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
78 {
79         printf("Converting UNIX ID to name\n");
80
81         return talloc_memdup(ctx, el, sizeof(*el));
82 }
83
84 static struct ldb_message_element *convert_unix_name2id(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
85 {
86         printf("Converting UNIX name to ID\n");
87
88         return talloc_memdup(ctx, el, sizeof(*el));
89 }
90
91 const struct ldb_map_objectclass samba3_objectclasses[] = {
92         { "group", "sambaGroupMapping" },
93         { "user", "sambaSAMAccount" },
94         { "domain", "sambaDomain" },
95 };
96
97 const struct ldb_map_attribute samba3_attributes[] = 
98 {
99         /* sambaNextRid -> nextRid */
100         {
101                 .local_name = "nextRid",
102                 .type = MAP_RENAME,
103                 .u.rename.remote_name = "sambaNextRid",
104         },
105
106         /* sambaBadPasswordTime -> badPasswordtime*/
107         {
108                 .local_name = "badPasswordTime",
109                 .type = MAP_RENAME,
110                 .u.rename.remote_name = "sambaBadPasswordTime",
111         },
112
113         /* sambaLMPassword -> lmPwdHash*/
114         {
115                 .local_name = "lmPwdHash",
116                 .type = MAP_RENAME,
117                 .u.rename.remote_name = "sambaLMPassword",
118         },
119
120         /* sambaGroupType -> groupType */
121         {
122                 .local_name = "groupType",
123                 .type = MAP_RENAME,
124                 .u.rename.remote_name = "sambaGroupType",
125         },
126
127         /* sambaNTPassword -> ntPwdHash*/
128         {
129                 .local_name = "badPwdCount",
130                 .type = MAP_RENAME,
131                 .u.rename.remote_name = "sambaNTPassword",
132         },
133
134         /* sambaPrimaryGroupSID -> primaryGroupID */
135         {
136                 .local_name = "primaryGroupID",
137                 .type = MAP_CONVERT,
138                 .u.convert.remote_name = "sambaPrimaryGroupSID",
139                 .u.convert.convert_local = convert_rid_sid,
140                 .u.convert.convert_remote = convert_sid_rid, 
141         },
142
143         /* sambaBadPasswordCount -> badPwdCount */
144         {
145                 .local_name = "badPwdCount",
146                 .type = MAP_RENAME,
147                 .u.rename.remote_name = "sambaBadPasswordCount",
148         },
149
150         /* sambaLogonTime -> lastLogon*/
151         {
152                 .local_name = "lastLogon",
153                 .type = MAP_RENAME,
154                 .u.rename.remote_name = "sambaLogonTime",
155         },
156
157         /* sambaLogoffTime -> lastLogoff*/
158         {
159                 .local_name = "lastLogoff",
160                 .type = MAP_RENAME,
161                 .u.rename.remote_name = "sambaLogoffTime",
162         },
163
164         /* gidNumber -> unixName */
165         {
166                 .local_name = "unixName",
167                 .type = MAP_CONVERT,
168                 .u.convert.remote_name = "gidNumber",
169                 .u.convert.convert_local = convert_unix_id2name,
170                 .u.convert.convert_remote = convert_unix_name2id, 
171         },
172
173         /* uid -> unixName */
174         {
175                 .local_name = "unixName",
176                 .type = MAP_CONVERT,
177                 .u.convert.remote_name = "uid",
178                 .u.convert.convert_local = convert_unix_id2name,
179                 .u.convert.convert_remote = convert_unix_name2id,
180         },
181
182         /* displayName -> name */
183         {
184                 .local_name = "name",
185                 .type = MAP_RENAME,
186                 .u.rename.remote_name = "displayName",
187         },
188
189         /* cn */
190         {
191                 .local_name = "cn",
192                 .type = MAP_KEEP,
193         },
194
195         /* description */
196         {
197                 .local_name = "description",
198                 .type = MAP_KEEP,
199         },
200
201         /* sambaSID -> objectSid*/
202         {
203                 .local_name = "objectSid",
204                 .type = MAP_RENAME,
205                 .u.rename.remote_name = "sambaSID", 
206         },
207
208         /* sambaPwdLastSet -> pwdLastSet*/
209         {
210                 .local_name = "pwdLastSet",
211                 .type = MAP_RENAME,
212                 .u.rename.remote_name = "sambaPwdLastSet",
213         },      
214 };
215
216         /* the init function */
217 #ifdef HAVE_DLOPEN_DISABLED
218 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
219 #else
220 struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
221 #endif
222 {
223         return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, options);
224 }