r9685: Add tests for samba3sam mapping module
[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
64
65 const struct ldb_map_objectclass samba3_objectclasses[] = {
66         { "group", "sambaGroupMapping" },
67         { "user", "sambaSAMAccount" },
68         { "domain", "sambaDomain" },
69 };
70
71 const struct ldb_map_attribute samba3_attributes[] = 
72 {
73         /* sambaNextRid -> nextRid */
74         {
75                 .local_name = "nextRid",
76                 .type = MAP_RENAME,
77                 .u.rename.remote_name = "sambaNextRid",
78         },
79
80         /* sambaBadPasswordTime -> badPasswordtime*/
81         {
82                 .local_name = "badPasswordTime",
83                 .type = MAP_RENAME,
84                 .u.rename.remote_name = "sambaBadPasswordTime",
85         },
86
87         /* sambaLMPassword -> lmPwdHash*/
88         {
89                 .local_name = "lmPwdHash",
90                 .type = MAP_RENAME,
91                 .u.rename.remote_name = "sambaLMPassword",
92         },
93
94         /* sambaGroupType -> groupType */
95         {
96                 .local_name = "groupType",
97                 .type = MAP_RENAME,
98                 .u.rename.remote_name = "sambaGroupType",
99         },
100
101         /* sambaNTPassword -> ntPwdHash*/
102         {
103                 .local_name = "badPwdCount",
104                 .type = MAP_RENAME,
105                 .u.rename.remote_name = "sambaNTPassword",
106         },
107
108         /* sambaPrimaryGroupSID -> primaryGroupID */
109         {
110                 .local_name = "primaryGroupID",
111                 .type = MAP_CONVERT,
112                 .u.convert.remote_name = "sambaPrimaryGroupSID",
113                 .u.convert.convert_local = NULL, /* FIXME: Add domain SID */
114                 .u.convert.convert_remote = NULL, /* FIXME: Extract RID */
115         },
116
117         /* sambaBadPasswordCount -> badPwdCount */
118         {
119                 .local_name = "badPwdCount",
120                 .type = MAP_RENAME,
121                 .u.rename.remote_name = "sambaBadPasswordCount",
122         },
123
124         /* sambaLogonTime -> lastLogon*/
125         {
126                 .local_name = "lastLogon",
127                 .type = MAP_RENAME,
128                 .u.rename.remote_name = "sambaLogonTime",
129         },
130
131         /* sambaLogoffTime -> lastLogoff*/
132         {
133                 .local_name = "lastLogoff",
134                 .type = MAP_RENAME,
135                 .u.rename.remote_name = "sambaLogoffTime",
136         },
137
138         /* gidNumber -> unixName */
139         {
140                 .local_name = "unixName",
141                 .type = MAP_CONVERT,
142                 .u.convert.remote_name = "gidNumber",
143                 .u.convert.convert_local = NULL, /* FIXME: Lookup gid */
144                 .u.convert.convert_remote = NULL, /* FIXME: Lookup groupname */
145         },
146
147         /* uid -> unixName */
148         {
149                 .local_name = "unixName",
150                 .type = MAP_CONVERT,
151                 .u.convert.remote_name = "uid",
152                 .u.convert.convert_local = NULL, /* FIXME: Lookup uid */
153                 .u.convert.convert_remote = NULL, /* FIXME: Lookup username */
154         },
155
156         /* displayName -> name */
157         {
158                 .local_name = "name",
159                 .type = MAP_RENAME,
160                 .u.rename.remote_name = "displayName",
161         },
162
163         /* cn */
164         {
165                 .local_name = "cn",
166                 .type = MAP_KEEP,
167         },
168
169         /* description */
170         {
171                 .local_name = "description",
172                 .type = MAP_KEEP,
173         },
174
175         /* sambaSID -> objectSid*/
176         {
177                 .local_name = "objectSid",
178                 .type = MAP_RENAME,
179                 .u.rename.remote_name = "sambaSID", 
180         },
181
182         /* sambaPwdLastSet -> pwdLastSet*/
183         {
184                 .local_name = "pwdLastSet",
185                 .type = MAP_RENAME,
186                 .u.rename.remote_name = "sambaPwdLastSet",
187         },      
188 };
189
190         /* the init function */
191 #ifdef HAVE_DLOPEN_DISABLED
192 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
193 #else
194 struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
195 #endif
196 {
197         return ldb_map_init(ldb, &samba3_attributes, &samba3_objectclasses, options);
198 }