r9698: Fix a bit of memory management
[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_val convert_sid_rid(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
64 {
65         printf("Converting SID TO RID *\n");
66
67         return ldb_val_dup(ctx, val);
68 }
69
70 static struct ldb_val convert_rid_sid(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
71 {
72         printf("Converting RID TO SID *\n");
73
74         return ldb_val_dup(ctx, val);
75 }
76
77 static struct ldb_val convert_unix_id2name(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
78 {
79         printf("Converting UNIX ID to name\n");
80
81         return ldb_val_dup(ctx, val);
82 }
83
84 static struct ldb_val convert_unix_name2id(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
85 {
86         printf("Converting UNIX name to ID\n");
87
88         return ldb_val_dup(ctx, val);
89 }
90
91 const struct ldb_map_objectclass samba3_objectclasses[] = {
92         { "group", "sambaGroupMapping" },
93         { "user", "sambaSAMAccount" },
94         { "domain", "sambaDomain" },
95         { NULL, NULL }
96 };
97
98 const struct ldb_map_attribute samba3_attributes[] = 
99 {
100         /* sambaNextRid -> nextRid */
101         {
102                 .local_name = "nextRid",
103                 .type = MAP_RENAME,
104                 .u.rename.remote_name = "sambaNextRid",
105         },
106
107         /* sambaBadPasswordTime -> badPasswordtime*/
108         {
109                 .local_name = "badPasswordTime",
110                 .type = MAP_RENAME,
111                 .u.rename.remote_name = "sambaBadPasswordTime",
112         },
113
114         /* sambaLMPassword -> lmPwdHash*/
115         {
116                 .local_name = "lmPwdHash",
117                 .type = MAP_RENAME,
118                 .u.rename.remote_name = "sambaLMPassword",
119         },
120
121         /* sambaGroupType -> groupType */
122         {
123                 .local_name = "groupType",
124                 .type = MAP_RENAME,
125                 .u.rename.remote_name = "sambaGroupType",
126         },
127
128         /* sambaNTPassword -> ntPwdHash*/
129         {
130                 .local_name = "badPwdCount",
131                 .type = MAP_RENAME,
132                 .u.rename.remote_name = "sambaNTPassword",
133         },
134
135         /* sambaPrimaryGroupSID -> primaryGroupID */
136         {
137                 .local_name = "primaryGroupID",
138                 .type = MAP_CONVERT,
139                 .u.convert.remote_name = "sambaPrimaryGroupSID",
140                 .u.convert.convert_local = convert_rid_sid,
141                 .u.convert.convert_remote = convert_sid_rid, 
142         },
143
144         /* sambaBadPasswordCount -> badPwdCount */
145         {
146                 .local_name = "badPwdCount",
147                 .type = MAP_RENAME,
148                 .u.rename.remote_name = "sambaBadPasswordCount",
149         },
150
151         /* sambaLogonTime -> lastLogon*/
152         {
153                 .local_name = "lastLogon",
154                 .type = MAP_RENAME,
155                 .u.rename.remote_name = "sambaLogonTime",
156         },
157
158         /* sambaLogoffTime -> lastLogoff*/
159         {
160                 .local_name = "lastLogoff",
161                 .type = MAP_RENAME,
162                 .u.rename.remote_name = "sambaLogoffTime",
163         },
164
165         /* gidNumber -> unixName */
166         {
167                 .local_name = "unixName",
168                 .type = MAP_CONVERT,
169                 .u.convert.remote_name = "gidNumber",
170                 .u.convert.convert_local = convert_unix_name2id,
171                 .u.convert.convert_remote = convert_unix_id2name, 
172         },
173
174         /* uid -> unixName */
175         {
176                 .local_name = "unixName",
177                 .type = MAP_CONVERT,
178                 .u.convert.remote_name = "uid",
179                 .u.convert.convert_local = convert_unix_name2id,
180                 .u.convert.convert_remote = convert_unix_id2name,
181         },
182
183         /* displayName -> name */
184         {
185                 .local_name = "name",
186                 .type = MAP_RENAME,
187                 .u.rename.remote_name = "displayName",
188         },
189
190         /* cn */
191         {
192                 .local_name = "cn",
193                 .type = MAP_KEEP,
194         },
195
196         /* description */
197         {
198                 .local_name = "description",
199                 .type = MAP_KEEP,
200         },
201
202         /* sambaSID -> objectSid*/
203         {
204                 .local_name = "objectSid",
205                 .type = MAP_RENAME,
206                 .u.rename.remote_name = "sambaSID", 
207         },
208
209         /* sambaPwdLastSet -> pwdLastSet */
210         {
211                 .local_name = "pwdLastSet",
212                 .type = MAP_RENAME,
213                 .u.rename.remote_name = "sambaPwdLastSet",
214         },      
215         
216         /* cn -> cn */
217         {
218                 .local_name = "cn",
219                 .type = MAP_KEEP,
220         },
221         {
222                 .local_name = NULL,
223         }
224 };
225
226         /* the init function */
227 #ifdef HAVE_DLOPEN_DISABLED
228 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
229 #else
230 struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
231 #endif
232 {
233         return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, options);
234 }