3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from samba.samba3 import (GroupMappingDatabase, Registry, PolicyDatabase,
21 SecretsDatabase, TdbSam)
22 from samba.samba3 import (WinsDatabase, SmbpasswdFile, ACB_NORMAL,
23 IdmapDatabase, SAMUser, ParamFile)
24 from samba.tests import TestCase
27 DATADIR=os.path.join(os.path.dirname(__file__), "../../../../../testdata/samba3")
28 print "Samba 3 data dir: %s" % DATADIR
30 class RegistryTestCase(TestCase):
33 super(RegistryTestCase, self).setUp()
34 self.registry = Registry(os.path.join(DATADIR, "registry.tdb"))
39 def test_length(self):
40 self.assertEquals(28, len(self.registry))
43 self.assertTrue("HKLM" in self.registry.keys())
45 def test_subkeys(self):
46 self.assertEquals(["SOFTWARE", "SYSTEM"], self.registry.subkeys("HKLM"))
48 def test_values(self):
49 self.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'),
50 'ErrorControl': (4L, '\x01\x00\x00\x00')},
51 self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG"))
54 class PolicyTestCase(TestCase):
57 super(PolicyTestCase, self).setUp()
58 self.policy = PolicyDatabase(os.path.join(DATADIR, "account_policy.tdb"))
60 def test_policy(self):
61 self.assertEquals(self.policy.min_password_length, 5)
62 self.assertEquals(self.policy.minimum_password_age, 0)
63 self.assertEquals(self.policy.maximum_password_age, 999999999)
64 self.assertEquals(self.policy.refuse_machine_password_change, 0)
65 self.assertEquals(self.policy.reset_count_minutes, 0)
66 self.assertEquals(self.policy.disconnect_time, -1)
67 self.assertEquals(self.policy.user_must_logon_to_change_password, None)
68 self.assertEquals(self.policy.password_history, 0)
69 self.assertEquals(self.policy.lockout_duration, 0)
70 self.assertEquals(self.policy.bad_lockout_minutes, None)
73 class GroupsTestCase(TestCase):
76 super(GroupsTestCase, self).setUp()
77 self.groupdb = GroupMappingDatabase(os.path.join(DATADIR, "group_mapping.tdb"))
81 super(GroupsTestCase, self).tearDown()
83 def test_group_length(self):
84 self.assertEquals(13, len(list(self.groupdb.groupsids())))
86 def test_get_group(self):
87 self.assertEquals((-1, 5L, 'Administrators', ''), self.groupdb.get_group("S-1-5-32-544"))
89 def test_groupsids(self):
90 sids = list(self.groupdb.groupsids())
91 self.assertTrue("S-1-5-32-544" in sids)
93 def test_alias_length(self):
94 self.assertEquals(0, len(list(self.groupdb.aliases())))
97 class SecretsDbTestCase(TestCase):
100 super(SecretsDbTestCase, self).setUp()
101 self.secretsdb = SecretsDatabase(os.path.join(DATADIR, "secrets.tdb"))
104 self.secretsdb.close()
105 super(SecretsDbTestCase, self).tearDown()
107 def test_get_sid(self):
108 self.assertTrue(self.secretsdb.get_sid("BEDWYR") is not None)
111 class TdbSamTestCase(TestCase):
114 super(TdbSamTestCase, self).setUp()
115 self.samdb = TdbSam(os.path.join(DATADIR, "passdb.tdb"))
119 super(TdbSamTestCase, self).tearDown()
121 def test_usernames(self):
122 self.assertEquals(3, len(list(self.samdb.usernames())))
124 def test_getuser(self):
125 user = SAMUser("root")
126 user.logoff_time = 2147483647
127 user.kickoff_time = 2147483647
128 user.pass_can_change_time = 1125418267
129 user.username = "root"
131 user.lm_password = 'U)\x02\x03\x1b\xed\xe9\xef\xaa\xd3\xb45\xb5\x14\x04\xee'
132 user.nt_password = '\x87\x8d\x80\x14`l\xda)gzD\xef\xa15?\xc7'
134 user.pass_last_set_time = 1125418267
135 user.fullname = "root"
136 user.nt_username = ""
137 user.logoff_time = 2147483647
139 user.group_rid = 1001
141 user.bad_password_count = 0
142 user.domain = "BEDWYR"
143 user.munged_dial = ""
144 user.workstations = ""
146 user.kickoff_time = 2147483647
147 user.logoff_time = 2147483647
148 user.unknown_6 = 1260L
150 user.hours = [True for i in range(168)]
151 other = self.samdb["root"]
152 for name in other.__dict__:
153 if other.__dict__[name] != user.__dict__[name]:
154 print "%s: %r != %r" % (name, other.__dict__[name], user.__dict__[name])
155 self.assertEquals(user, other)
158 class WinsDatabaseTestCase(TestCase):
161 super(WinsDatabaseTestCase, self).setUp()
162 self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
164 def test_length(self):
165 self.assertEquals(22, len(self.winsdb))
167 def test_first_entry(self):
168 self.assertEqual((1124185120, ["192.168.1.5"], 0x64), self.winsdb["ADMINISTRATOR#03"])
172 super(WinsDatabaseTestCase, self).tearDown()
175 class SmbpasswdTestCase(TestCase):
178 super(SmbpasswdTestCase, self).setUp()
179 self.samdb = SmbpasswdFile(os.path.join(DATADIR, "smbpasswd"))
181 def test_length(self):
182 self.assertEquals(3, len(self.samdb))
184 def test_get_user(self):
185 user = SAMUser("rootpw")
186 user.lm_password = "552902031BEDE9EFAAD3B435B51404EE"
187 user.nt_password = "878D8014606CDA29677A44EFA1353FC7"
188 user.acct_ctrl = ACB_NORMAL
189 user.pass_last_set_time = int(1125418267)
191 self.assertEquals(user, self.samdb["rootpw"])
195 super(SmbpasswdTestCase, self).tearDown()
198 class IdmapDbTestCase(TestCase):
201 super(IdmapDbTestCase, self).setUp()
202 self.idmapdb = IdmapDatabase(os.path.join(DATADIR,
203 "winbindd_idmap.tdb"))
205 def test_user_hwm(self):
206 self.assertEquals(10000, self.idmapdb.get_user_hwm())
208 def test_group_hwm(self):
209 self.assertEquals(10002, self.idmapdb.get_group_hwm())
212 self.assertEquals(1, len(list(self.idmapdb.uids())))
215 self.assertEquals(3, len(list(self.idmapdb.gids())))
217 def test_get_user_sid(self):
218 self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534))
220 def test_get_group_sid(self):
221 self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001))
225 super(IdmapDbTestCase, self).tearDown()
228 class ParamTestCase(TestCase):
232 self.assertTrue(file is not None)
234 def test_add_section(self):
236 file.add_section("global")
237 self.assertTrue(file["global"] is not None)
239 def test_set_param_string(self):
241 file.add_section("global")
242 file.set_string("data", "bar")
243 self.assertEquals("bar", file.get_string("data"))
245 def test_get_section(self):
247 self.assertEquals(None, file.get_section("unknown"))
248 self.assertRaises(KeyError, lambda: file["unknown"])