talloc: Allow nested pools.
[Samba.git] / python / samba / tests / samba3.py
blob51d76dd94c077ced86d9f5c6498500f6b4ff4d56
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.samba3."""
20 from samba.samba3 import (
21 Registry,
22 WinsDatabase,
23 IdmapDatabase,
25 from samba.samba3 import passdb
26 from samba.samba3 import param as s3param
27 from samba.tests import TestCase, TestCaseInTempDir
28 from samba.dcerpc.security import dom_sid
29 import os
32 for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
33 DATADIR = os.path.join(os.path.dirname(__file__), p)
34 if os.path.exists(DATADIR):
35 break
38 class RegistryTestCase(TestCase):
40 def setUp(self):
41 super(RegistryTestCase, self).setUp()
42 self.registry = Registry(os.path.join(DATADIR, "registry"))
44 def tearDown(self):
45 self.registry.close()
46 super(RegistryTestCase, self).tearDown()
48 def test_length(self):
49 self.assertEquals(28, len(self.registry))
51 def test_keys(self):
52 self.assertTrue("HKLM" in self.registry.keys())
54 def test_subkeys(self):
55 self.assertEquals(["SOFTWARE", "SYSTEM"], self.registry.subkeys("HKLM"))
57 def test_values(self):
58 self.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'),
59 'ErrorControl': (4L, '\x01\x00\x00\x00')},
60 self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG"))
63 class PassdbTestCase(TestCaseInTempDir):
65 def setUp(self):
66 super (PassdbTestCase, self).setUp()
67 os.system("cp -r %s %s" % (DATADIR, self.tempdir))
68 datadir = os.path.join(self.tempdir, "samba3")
70 self.lp = s3param.get_context()
71 self.lp.load(os.path.join(datadir, "smb.conf"))
72 self.lp.set("private dir", datadir)
73 self.lp.set("state directory", datadir)
74 self.lp.set("lock directory", datadir)
75 passdb.set_secrets_dir(datadir)
76 self.pdb = passdb.PDB("tdbsam")
78 def tearDown(self):
79 self.lp = []
80 self.pdb = []
81 os.system("rm -rf %s" % os.path.join(self.tempdir, "samba3"))
82 super(PassdbTestCase, self).tearDown()
84 def test_param(self):
85 self.assertEquals("BEDWYR", self.lp.get("netbios name"))
86 self.assertEquals("SAMBA", self.lp.get("workgroup"))
87 self.assertEquals("USER", self.lp.get("security"))
89 def test_policy(self):
90 policy = self.pdb.get_account_policy()
91 self.assertEquals(0, policy['bad lockout attempt'])
92 self.assertEquals(-1, policy['disconnect time'])
93 self.assertEquals(0, policy['lockout duration'])
94 self.assertEquals(999999999, policy['maximum password age'])
95 self.assertEquals(0, policy['minimum password age'])
96 self.assertEquals(5, policy['min password length'])
97 self.assertEquals(0, policy['password history'])
98 self.assertEquals(0, policy['refuse machine password change'])
99 self.assertEquals(0, policy['reset count minutes'])
100 self.assertEquals(0, policy['user must logon to change password'])
102 def test_get_sid(self):
103 domain_sid = passdb.get_global_sam_sid()
104 self.assertEquals(dom_sid("S-1-5-21-2470180966-3899876309-2637894779"), domain_sid)
106 def test_usernames(self):
107 userlist = self.pdb.search_users(0)
108 self.assertEquals(3, len(userlist))
110 def test_getuser(self):
111 user = self.pdb.getsampwnam("root")
113 self.assertEquals(16, user.acct_ctrl)
114 self.assertEquals("", user.acct_desc)
115 self.assertEquals(0, user.bad_password_count)
116 self.assertEquals(0, user.bad_password_time)
117 self.assertEquals(0, user.code_page)
118 self.assertEquals(0, user.country_code)
119 self.assertEquals("", user.dir_drive)
120 self.assertEquals("BEDWYR", user.domain)
121 self.assertEquals("root", user.full_name)
122 self.assertEquals(dom_sid('S-1-5-21-2470180966-3899876309-2637894779-513'), user.group_sid)
123 self.assertEquals("\\\\BEDWYR\\root", user.home_dir)
124 self.assertEquals([-1 for i in range(21)], user.hours)
125 self.assertEquals(21, user.hours_len)
126 self.assertEquals(9223372036854775807, user.kickoff_time)
127 self.assertEquals(None, user.lanman_passwd)
128 self.assertEquals(9223372036854775807, user.logoff_time)
129 self.assertEquals(0, user.logon_count)
130 self.assertEquals(168, user.logon_divs)
131 self.assertEquals("", user.logon_script)
132 self.assertEquals(0, user.logon_time)
133 self.assertEquals("", user.munged_dial)
134 self.assertEquals('\x87\x8d\x80\x14`l\xda)gzD\xef\xa15?\xc7', user.nt_passwd)
135 self.assertEquals("", user.nt_username)
136 self.assertEquals(1125418267, user.pass_can_change_time)
137 self.assertEquals(1125418267, user.pass_last_set_time)
138 self.assertEquals(2125418266, user.pass_must_change_time)
139 self.assertEquals(None, user.plaintext_passwd)
140 self.assertEquals("\\\\BEDWYR\\root\\profile", user.profile_path)
141 self.assertEquals(None, user.pw_history)
142 self.assertEquals(dom_sid("S-1-5-21-2470180966-3899876309-2637894779-1000"), user.user_sid)
143 self.assertEquals("root", user.username)
144 self.assertEquals("", user.workstations)
146 def test_group_length(self):
147 grouplist = self.pdb.enum_group_mapping()
148 self.assertEquals(13, len(grouplist))
150 def test_get_group(self):
151 group = self.pdb.getgrsid(dom_sid("S-1-5-32-544"))
152 self.assertEquals("Administrators", group.nt_name)
153 self.assertEquals(-1, group.gid)
154 self.assertEquals(5, group.sid_name_use)
156 def test_groupsids(self):
157 grouplist = self.pdb.enum_group_mapping()
158 sids = []
159 for g in grouplist:
160 sids.append(str(g.sid))
161 self.assertTrue("S-1-5-32-544" in sids)
162 self.assertTrue("S-1-5-32-545" in sids)
163 self.assertTrue("S-1-5-32-546" in sids)
164 self.assertTrue("S-1-5-32-548" in sids)
165 self.assertTrue("S-1-5-32-549" in sids)
166 self.assertTrue("S-1-5-32-550" in sids)
167 self.assertTrue("S-1-5-32-551" in sids)
169 def test_alias_length(self):
170 aliaslist = self.pdb.search_aliases()
171 self.assertEquals(1, len(aliaslist))
172 self.assertEquals("Jelmers NT Group", aliaslist[0]['account_name'])
175 class WinsDatabaseTestCase(TestCase):
177 def setUp(self):
178 super(WinsDatabaseTestCase, self).setUp()
179 self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
181 def test_length(self):
182 self.assertEquals(22, len(self.winsdb))
184 def test_first_entry(self):
185 self.assertEqual((1124185120, ["192.168.1.5"], 0x64), self.winsdb["ADMINISTRATOR#03"])
187 def tearDown(self):
188 self.winsdb.close()
189 super(WinsDatabaseTestCase, self).tearDown()
192 class IdmapDbTestCase(TestCase):
194 def setUp(self):
195 super(IdmapDbTestCase, self).setUp()
196 self.idmapdb = IdmapDatabase(os.path.join(DATADIR,
197 "winbindd_idmap"))
199 def test_user_hwm(self):
200 self.assertEquals(10000, self.idmapdb.get_user_hwm())
202 def test_group_hwm(self):
203 self.assertEquals(10002, self.idmapdb.get_group_hwm())
205 def test_uids(self):
206 self.assertEquals(1, len(list(self.idmapdb.uids())))
208 def test_gids(self):
209 self.assertEquals(3, len(list(self.idmapdb.gids())))
211 def test_get_user_sid(self):
212 self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534))
214 def test_get_group_sid(self):
215 self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001))
217 def tearDown(self):
218 self.idmapdb.close()
219 super(IdmapDbTestCase, self).tearDown()