1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
#!/usr/bin/env smbscript
/* (C) Jelmer Vernooij <jelmer@samba.org> 2005
Published under the GNU GPL
Sponsored by Google Summer of Code
*/
libinclude("base.js");
var mypath = substr(ARGV[0], 0, -strlen("samba3sam"));
var sys = sys_init();
var s3url = "tdb://samba3.ldb";
var s4url = "tdb://samba4.ldb";
var s3 = ldb_init();
var s4 = ldb_init();
var msg;
var ok;
var local = new Object();
local.BASEDN = "dc=vernstok,dc=nl";
var remote = new Object();
remote.BASEDN = "CN=Samba3Sam," + local.BASEDN;
var prt_ldif = sprintf("dn: @PARTITION
partition: %s:%s
partition: %s:%s", remote.BASEDN, s3url, local.BASEDN, s4url);
var map_ldif = sprintf("dn: @MAP=samba3sam
@FROM: %s
@TO: %s", local.BASEDN, remote.BASEDN);
var mod_ldif = "dn: @MODULES
@LIST: rootdse,paged_results,server_sort,extended_dn,asq,samldb,objectclass,password_hash,operational,objectguid,rdn_name,samba3sam,partition";
sys.unlink("samba3.ldb");
ok = s3.connect(s3url);
assert(ok);
println("Initial samba3 LDIF...");
var path = "../../testdata/samba3/samba3.ldif"
var ldif = sys.file_load(mypath + path);
ldif = substitute_var(ldif, remote);
assert(ldif != undefined);
ok = s3.add(ldif);
assert(ok);
sys.unlink("samba4.ldb");
ok = s4.connect("tdb://samba4.ldb");
assert(ok);
println("Initial samba4 LDIF...");
var path = "../../testdata/samba3/provision_samba3sam.ldif"
var ldif = sys.file_load(mypath + path);
ldif = substitute_var(ldif, local);
assert(ldif != undefined);
ok = s4.add(ldif);
assert(ok);
println("Registering partitions...");
var ldif = substitute_var(prt_ldif, local);
assert(ldif != undefined);
ok = s4.add(ldif);
assert(ok);
println("Registering mapping...");
var ldif = substitute_var(map_ldif, local);
assert(ldif != undefined);
ok = s4.add(ldif);
assert(ok);
println("Registering modules...");
var ldif = substitute_var(mod_ldif, local);
assert(ldif != undefined);
ok = s4.add(ldif);
assert(ok);
println("Reconnecting to LDB database...");
s4 = ldb_init();
ok = s4.connect(s4url);
assert(ok);
println("Looking up by non-mapped attribute");
msg = s4.search("(cn=Administrator)");
assert(msg.length == 1);
assert(msg[0].cn == "Administrator");
println("Looking up by mapped attribute");
msg = s4.search("(name=Backup Operators)");
assert(msg.length == 1);
assert(msg[0].name == "Backup Operators");
println("Looking up by old name of renamed attribute");
msg = s4.search("(displayName=Backup Operators)");
assert(msg.length == 0);
println("Looking up mapped entry containing SID");
msg = s4.search("(cn=Replicator)");
assert(msg.length == 1);
assert(msg[0].dn == "cn=Replicator,ou=Groups,sambaDomainName=TESTS,dc=vernstok,dc=nl");
assert(msg[0].objectSid == "S-1-5-21-4231626423-2410014848-2360679739-552");
println("Checking mapping of objectClass");
var oc = msg[0].objectClass;
assert(oc != undefined);
for (var i in oc) {
assert(oc[i] == "posixGroup" || oc[i] == "group");
}
println("Looking up by objectClass");
msg = s4.search("(|(objectClass=user)(cn=Administrator))");
assert(msg != undefined);
assert(msg.length == 2);
for (var i = 0; i < msg.length; i++) {
assert((msg[i].dn == "unixName=Administrator,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl") ||
(msg[i].dn == "unixName=nobody,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl"));
}
println("Looking up by objectClass");
msg = s4.search("(|(objectClass=user)(cn=Administrator))");
assert(msg != undefined);
assert(msg.length == 2);
for (var i = 0; i < msg.length; i++) {
assert((msg[i].dn == "unixName=Administrator,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl") ||
(msg[i].dn == "unixName=nobody,ou=Users,sambaDomainName=TESTS,dc=vernstok,dc=nl"));
}
println("Adding a record that will be fallbacked");
ok = s4.add("
dn: cn=Foo,dc=idealx,dc=org
foo: bar
blah: Blie
cn: Foo
showInAdvancedViewOnly: TRUE
");
assert(ok);
println("Checking for existence of record (local)");
/* TODO: This record must be searched in the local database, which is currently only supported for base searches
msg = s4.search("(cn=Foo)", new Array('foo','blah','cn','showInAdvancedViewOnly'));
TODO: Actually, this version should work as well but doesn't...
msg = s4.search("(cn=Foo)", "dc=idealx,dc=org", s4.LDB_SCOPE_SUBTREE new Array('foo','blah','cn','showInAdvancedViewOnly'));
*/
msg = s4.search("", "cn=Foo,dc=idealx,dc=org", s4.LDB_SCOPE_BASE new Array('foo','blah','cn','showInAdvancedViewOnly'));
assert(msg.length == 1);
assert(msg[0].showInAdvancedViewOnly == "TRUE");
assert(msg[0].foo == "bar");
assert(msg[0].blah == "Blie");
println("Adding record that will be mapped");
ok = s4.add("
dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
objectClass: user
unixName: bin
unicodePwd: geheim
cn: Niemand
");
assert(ok);
println("Checking for existence of record (remote)");
msg = s4.search("(unixName=bin)", new Array('unixName','cn','dn', 'unicodePwd'));
assert(msg.length == 1);
assert(msg[0].cn == "Niemand");
assert(msg[0].unicodePwd == "geheim");
println("Checking for existence of record (local && remote)");
msg = s4.search("(&(unixName=bin)(unicodePwd=geheim))", new Array('unixName','cn','dn', 'unicodePwd'));
assert(msg.length == 1); // TODO: should check with more records
assert(msg[0].cn == "Niemand");
assert(msg[0].unixName == "bin");
assert(msg[0].unicodePwd == "geheim");
println("Checking for existence of record (local || remote)");
msg = s4.search("(|(unixName=bin)(unicodePwd=geheim))", new Array('unixName','cn','dn', 'unicodePwd'));
assert(msg.length == 1); // TODO: should check with more records
assert(msg[0].cn == "Niemand");
assert(msg[0].unixName == "bin" || msg[0].unicodePwd == "geheim");
println("Checking for data in destination database");
msg = s3.search("(cn=Niemand)");
assert(msg.length >= 1);
assert(msg[0].sambaSID == "S-1-5-21-4231626423-2410014848-2360679739-2001");
assert(msg[0].displayName == "Niemand");
println("Adding attribute...");
ok = s4.modify("
dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
changetype: modify
add: description
description: Blah
");
assert(ok);
println("Checking whether changes are still there...");
msg = s4.search("(cn=Niemand)");
assert(msg.length >= 1);
assert(msg[0].cn == "Niemand");
assert(msg[0].description == "Blah");
println("Modifying attribute...");
ok = s4.modify("
dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
changetype: modify
replace: description
description: Blie
");
assert(ok);
println("Checking whether changes are still there...");
msg = s4.search("(cn=Niemand)");
assert(msg.length >= 1);
assert(msg[0].description == "Blie");
println("Deleting attribute...");
ok = s4.modify("
dn: cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl
changetype: modify
delete: description
");
assert(ok);
println("Checking whether changes are no longer there...");
msg = s4.search("(cn=Niemand)");
assert(msg.length >= 1);
assert(msg[0].description == undefined);
println("Renaming record...");
ok = s4.rename("cn=Niemand,sambaDomainName=TESTS,dc=vernstok,dc=nl", "cn=Niemand,dc=vernstok,dc=nl");
println("Checking whether DN has changed...");
msg = s4.search("(cn=Niemand)");
assert(msg.length == 1);
assert(msg[0].dn == "cn=Niemand,dc=vernstok,dc=nl");
println("Deleting record...");
ok = s4.del("cn=Niemand,dc=vernstok,dc=nl");
assert(ok);
println("Checking whether record is gone...");
msg = s4.search("(cn=Niemand)");
assert(msg.length == 0);
return 0;
|