444d7e8d12f6158a6a41dfc7b975c282ccae96c5
[kai/samba.git] / source / dsdb / samdb / ldb_modules / 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/modules/ldb_map.h"
27 #include "ldb/include/ldb.h"
28 #include "ldb/include/ldb_private.h"
29
30 /* FIXME: 
31  * sambaSID -> member  (dn!)
32  * sambaSIDList -> member (dn!) 
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 /* In Samba4 but not in Samba3:
64 */
65
66 static struct ldb_val convert_sid_rid(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
67 {
68         printf("Converting SID TO RID *\n");
69
70         return ldb_val_dup(ctx, val);
71 }
72
73 static struct ldb_val convert_rid_sid(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
74 {
75         printf("Converting RID TO SID *\n");
76
77         return ldb_val_dup(ctx, val);
78 }
79
80 static struct ldb_val convert_unix_id2name(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
81 {
82         printf("Converting UNIX ID to name\n");
83
84         return ldb_val_dup(ctx, val);
85 }
86
87 static struct ldb_val convert_unix_name2id(struct ldb_map_context *map, TALLOC_CTX *ctx, const struct ldb_val *val)
88 {
89         printf("Converting UNIX name to ID\n");
90
91         return ldb_val_dup(ctx, val);
92 }
93
94 const struct ldb_map_objectclass samba3_objectclasses[] = {
95         { "group", "sambaGroupMapping" },
96         { "user", "sambaSAMAccount" },
97         { "domain", "sambaDomain" },
98         { NULL, NULL }
99 };
100
101 const struct ldb_map_attribute samba3_attributes[] = 
102 {
103         /* sambaNextRid -> nextRid */
104         {
105                 .local_name = "nextRid",
106                 .type = MAP_RENAME,
107                 .u.rename.remote_name = "sambaNextRid",
108         },
109
110         /* sambaBadPasswordTime -> badPasswordtime*/
111         {
112                 .local_name = "badPasswordTime",
113                 .type = MAP_RENAME,
114                 .u.rename.remote_name = "sambaBadPasswordTime",
115         },
116
117         /* sambaLMPassword -> lmPwdHash*/
118         {
119                 .local_name = "lmPwdHash",
120                 .type = MAP_RENAME,
121                 .u.rename.remote_name = "sambaLMPassword",
122         },
123
124         /* sambaGroupType -> groupType */
125         {
126                 .local_name = "groupType",
127                 .type = MAP_RENAME,
128                 .u.rename.remote_name = "sambaGroupType",
129         },
130
131         /* sambaNTPassword -> ntPwdHash*/
132         {
133                 .local_name = "badPwdCount",
134                 .type = MAP_RENAME,
135                 .u.rename.remote_name = "sambaNTPassword",
136         },
137
138         /* sambaPrimaryGroupSID -> primaryGroupID */
139         {
140                 .local_name = "primaryGroupID",
141                 .type = MAP_CONVERT,
142                 .u.convert.remote_name = "sambaPrimaryGroupSID",
143                 .u.convert.convert_local = convert_rid_sid,
144                 .u.convert.convert_remote = convert_sid_rid, 
145         },
146
147         /* sambaBadPasswordCount -> badPwdCount */
148         {
149                 .local_name = "badPwdCount",
150                 .type = MAP_RENAME,
151                 .u.rename.remote_name = "sambaBadPasswordCount",
152         },
153
154         /* sambaLogonTime -> lastLogon*/
155         {
156                 .local_name = "lastLogon",
157                 .type = MAP_RENAME,
158                 .u.rename.remote_name = "sambaLogonTime",
159         },
160
161         /* sambaLogoffTime -> lastLogoff*/
162         {
163                 .local_name = "lastLogoff",
164                 .type = MAP_RENAME,
165                 .u.rename.remote_name = "sambaLogoffTime",
166         },
167
168         /* gidNumber -> unixName */
169         {
170                 .local_name = "unixName",
171                 .type = MAP_CONVERT,
172                 .u.convert.remote_name = "gidNumber",
173                 .u.convert.convert_local = convert_unix_name2id,
174                 .u.convert.convert_remote = convert_unix_id2name, 
175         },
176
177         /* uid -> unixName */
178         {
179                 .local_name = "unixName",
180                 .type = MAP_CONVERT,
181                 .u.convert.remote_name = "uid",
182                 .u.convert.convert_local = convert_unix_name2id,
183                 .u.convert.convert_remote = convert_unix_id2name,
184         },
185
186         /* displayName -> name */
187         {
188                 .local_name = "name",
189                 .type = MAP_RENAME,
190                 .u.rename.remote_name = "displayName",
191         },
192
193         /* cn */
194         {
195                 .local_name = "cn",
196                 .type = MAP_KEEP,
197         },
198
199         /* sAMAccountName -> cn */
200         {
201                 .local_name = "sAMAccountName",
202                 .type = MAP_RENAME,
203                 .u.rename.remote_name = "uid",
204         },
205
206         /* objectCategory */
207         {
208                 .local_name = "objectCategory",
209                 .type = MAP_IGNORE,
210         },
211
212         /* objectGUID */
213         {
214                 .local_name = "objectGUID",
215                 .type = MAP_IGNORE,
216         },
217
218         /* objectVersion */
219         {
220                 .local_name = "objectVersion",
221                 .type = MAP_IGNORE,
222         },
223
224         /* codePage */
225         { 
226                 .local_name = "codePage",
227                 .type = MAP_IGNORE,
228         },
229
230         /* dNSHostName */
231         {
232                 .local_name = "dNSHostName",
233                 .type = MAP_IGNORE,
234         },
235
236
237         /* dnsDomain */
238         {
239                 .local_name = "dnsDomain",
240                 .type = MAP_IGNORE,
241         },
242
243         /* dnsRoot */
244         {
245                 .local_name = "dnsRoot",
246                 .type = MAP_IGNORE,
247         },
248
249         /* countryCode */
250         {
251                 .local_name = "countryCode",
252                 .type = MAP_IGNORE,
253         },
254
255         /* nTMixedDomain */
256         { 
257                 .local_name = "nTMixedDomain",
258                 .type = MAP_IGNORE,
259         },
260
261         /* operatingSystem */
262         { 
263                 .local_name = "operatingSystem",
264                 .type = MAP_IGNORE,
265         },
266
267         /* operatingSystemVersion */
268         {
269                 .local_name = "operatingSystemVersion",
270                 .type = MAP_IGNORE,
271         },
272
273
274         /* servicePrincipalName */
275         {
276                 .local_name = "servicePrincipalName",
277                 .type = MAP_IGNORE,
278         },
279
280         /* msDS-Behavior-Version */
281         {
282                 .local_name = "msDS-Behavior-Version",
283                 .type = MAP_IGNORE,
284         },
285
286         /* msDS-KeyVersionNumber */
287         {
288                 .local_name = "msDS-KeyVersionNumber",
289                 .type = MAP_IGNORE,
290         },
291
292         /* msDs-masteredBy */
293         {
294                 .local_name = "msDs-masteredBy",
295                 .type = MAP_IGNORE,
296         },
297
298         /* ou */
299         {
300                 .local_name = "ou",
301                 .type = MAP_KEEP,
302         },
303
304         /* dc */
305         {
306                 .local_name = "dc",
307                 .type = MAP_KEEP,
308         },
309
310         /* description */
311         {
312                 .local_name = "description",
313                 .type = MAP_KEEP,
314         },
315
316         /* sambaSID -> objectSid*/
317         {
318                 .local_name = "objectSid",
319                 .type = MAP_RENAME,
320                 .u.rename.remote_name = "sambaSID", 
321         },
322
323         /* sambaPwdLastSet -> pwdLastSet */
324         {
325                 .local_name = "pwdLastSet",
326                 .type = MAP_RENAME,
327                 .u.rename.remote_name = "sambaPwdLastSet",
328         },      
329
330         /* accountExpires */
331         {
332                 .local_name = "accountExpires", 
333                 .type = MAP_IGNORE,
334         },
335
336         /* adminCount */
337         {
338                 .local_name = "adminCount",
339                 .type = MAP_IGNORE,
340         },
341
342         /* canonicalName */
343         {
344                 .local_name = "canonicalName",
345                 .type = MAP_IGNORE,
346         },
347
348         /* createTimestamp */
349         {
350                 .local_name = "createTimestamp",
351                 .type = MAP_IGNORE,
352         },
353         
354         /* creationTime */
355         {
356                 .local_name = "creationTime",
357                 .type = MAP_IGNORE,
358         },
359         
360         /* dMDLocation */
361         {
362                 .local_name = "dMDLocation",
363                 .type = MAP_IGNORE,
364         },
365         
366         /* fSMORoleOwner */
367         {
368                 .local_name = "fSMORoleOwner",
369                 .type = MAP_IGNORE,
370         },
371         
372         /* forceLogoff */
373         {
374                 .local_name = "forceLogoff",
375                 .type = MAP_IGNORE,
376         },
377         
378         /* instanceType */
379         {
380                 .local_name = "instanceType",
381                 .type = MAP_IGNORE,
382         },
383         
384         /* invocationId */
385         {
386                 .local_name = "invocationId",
387                 .type = MAP_IGNORE,
388         },
389         
390         /* isCriticalSystemObject */
391         {
392                 .local_name = "isCriticalSystemObject",
393                 .type = MAP_IGNORE,
394         },
395         
396         /* localPolicyFlags */
397         {
398                 .local_name = "localPolicyFlags",
399                 .type = MAP_IGNORE,
400         },
401         
402         /* lockOutObservationWindow */
403         {
404                 .local_name = "lockOutObservationWindow",
405                 .type = MAP_IGNORE,
406         },
407
408         /* lockoutDuration */
409         {
410                 .local_name = "lockoutDuration",
411                 .type = MAP_IGNORE,
412         },
413
414         /* lockoutThreshold */
415         {
416                 .local_name = "lockoutThreshold",
417                 .type = MAP_IGNORE,
418         },
419
420         /* logonCount */
421         {
422                 .local_name = "logonCount",
423                 .type = MAP_IGNORE,
424         },
425
426         /* masteredBy */
427         {
428                 .local_name = "masteredBy",
429                 .type = MAP_IGNORE,
430         },
431
432         /* maxPwdAge */
433         {
434                 .local_name = "maxPwdAge",
435                 .type = MAP_IGNORE,
436         },
437
438         /* member */
439         {
440                 .local_name = "member",
441                 .type = MAP_IGNORE,
442         },
443
444         /* memberOf */
445         {
446                 .local_name = "memberOf",
447                 .type = MAP_IGNORE,
448         },
449
450         /* minPwdAge */
451         {
452                 .local_name = "minPwdAge",
453                 .type = MAP_IGNORE,
454         },
455
456         /* minPwdLength */
457         {
458                 .local_name = "minPwdLength",
459                 .type = MAP_IGNORE,
460         },
461
462         /* modifiedCount */
463         {
464                 .local_name = "modifiedCount",
465                 .type = MAP_IGNORE,
466         },
467
468         /* modifiedCountAtLastProm */
469         {
470                 .local_name = "modifiedCountAtLastProm",
471                 .type = MAP_IGNORE,
472         },
473
474         /* modifyTimestamp */
475         {
476                 .local_name = "modifyTimestamp",
477                 .type = MAP_IGNORE,
478         },
479
480         /* nCName */
481         {
482                 .local_name = "nCName",
483                 .type = MAP_IGNORE,
484         },
485
486         /* nETBIOSName */
487         {
488                 .local_name = "nETBIOSName",
489                 .type = MAP_IGNORE,
490         },
491
492         /* oEMInformation */
493         {
494                 .local_name = "oEMInformation",
495                 .type = MAP_IGNORE,
496         },
497
498         /* privilege */
499         {
500                 .local_name = "privilege",
501                 .type = MAP_IGNORE,
502         },
503
504         /* pwdHistoryLength */
505         {
506                 .local_name = "pwdHistoryLength",
507                 .type = MAP_IGNORE,
508         },
509
510         /* pwdProperties */
511         {
512                 .local_name = "pwdProperties",
513                 .type = MAP_IGNORE,
514         },
515
516         /* rIDAvailablePool */
517         {
518                 .local_name = "rIDAvailablePool",
519                 .type = MAP_IGNORE,
520         },
521
522         /* revision */
523         {
524                 .local_name = "revision",
525                 .type = MAP_IGNORE,
526         },
527
528         /* ridManagerReference */
529         {
530                 .local_name = "ridManagerReference",
531                 .type = MAP_IGNORE,
532         },
533
534         /* sAMAccountType */
535         {
536                 .local_name = "sAMAccountType",
537                 .type = MAP_IGNORE,
538         },
539
540         /* sPNMappings */
541         {
542                 .local_name = "sPNMappings",
543                 .type = MAP_IGNORE,
544         },
545
546         /* serverReference */
547         {
548                 .local_name = "serverReference",
549                 .type = MAP_IGNORE,
550         },
551
552         /* serverState */
553         {
554                 .local_name = "serverState",
555                 .type = MAP_IGNORE,
556         },
557
558         /* showInAdvancedViewOnly */
559         {
560                 .local_name = "showInAdvancedViewOnly",
561                 .type = MAP_IGNORE,
562         },
563
564         /* subRefs */
565         {
566                 .local_name = "subRefs",
567                 .type = MAP_IGNORE,
568         },
569
570         /* systemFlags */
571         {
572                 .local_name = "systemFlags",
573                 .type = MAP_IGNORE,
574         },
575
576         /* uASCompat */
577         {
578                 .local_name = "uASCompat",
579                 .type = MAP_IGNORE,
580         },
581
582         /* uSNChanged */
583         {
584                 .local_name = "uSNChanged",
585                 .type = MAP_IGNORE,
586         },
587
588         /* uSNCreated */
589         {
590                 .local_name = "uSNCreated",
591                 .type = MAP_IGNORE,
592         },
593
594         /* unicodePwd */
595         {
596                 .local_name = "unicodePwd",
597                 .type = MAP_IGNORE,
598         },
599
600         /* userAccountControl */
601         {
602                 .local_name = "userAccountControl",
603                 .type = MAP_IGNORE,
604         },
605
606         /* whenChanged */
607         {
608                 .local_name = "whenChanged",
609                 .type = MAP_IGNORE,
610         },
611
612         /* whenCreated */
613         {
614                 .local_name = "whenCreated",
615                 .type = MAP_IGNORE,
616         },
617
618         {
619                 .local_name = NULL,
620         }
621 };
622
623         /* the init function */
624 #ifdef HAVE_DLOPEN_DISABLED
625 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
626 #else
627 struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
628 #endif
629 {
630         return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, "samba3sam");
631 }