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 """Tests for samba.samba3."""
22 from samba
.samba3
import (Registry
, SecretsDatabase
)
23 from samba
.samba3
import (WinsDatabase
, IdmapDatabase
)
24 from samba
.samba3
import passdb
25 from samba
.samba3
import param
as s3param
26 from samba
.tests
import TestCase
27 from samba
.dcerpc
.security
import dom_sid
30 for p
in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
31 DATADIR
= os
.path
.join(os
.path
.dirname(__file__
), p
)
32 if os
.path
.exists(DATADIR
):
36 class RegistryTestCase(TestCase
):
39 super(RegistryTestCase
, self
).setUp()
40 self
.registry
= Registry(os
.path
.join(DATADIR
, "registry.tdb"))
44 super(RegistryTestCase
, self
).tearDown()
46 def test_length(self
):
47 self
.assertEquals(28, len(self
.registry
))
50 self
.assertTrue("HKLM" in self
.registry
.keys())
52 def test_subkeys(self
):
53 self
.assertEquals(["SOFTWARE", "SYSTEM"], self
.registry
.subkeys("HKLM"))
55 def test_values(self
):
56 self
.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'),
57 'ErrorControl': (4L, '\x01\x00\x00\x00')},
58 self
.registry
.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG"))
61 class PassdbTestCase(TestCase
):
64 super (PassdbTestCase
, self
).setUp()
65 self
.lp
= s3param
.get_context()
66 self
.lp
.load(os
.path
.join(DATADIR
, "smb.conf"))
67 self
.lp
.set("private dir", DATADIR
)
68 self
.lp
.set("state directory", DATADIR
)
69 self
.lp
.set("lock directory", DATADIR
)
70 passdb
.set_secrets_dir(DATADIR
)
71 self
.pdb
= passdb
.PDB("tdbsam")
76 super(PassdbTestCase
, self
).tearDown()
79 self
.assertEquals("BEDWYR", self
.lp
.get("netbios name"))
80 self
.assertEquals("SAMBA", self
.lp
.get("workgroup"))
81 self
.assertEquals("USER", self
.lp
.get("security"))
83 def test_policy(self
):
84 policy
= self
.pdb
.get_account_policy()
85 self
.assertEquals(0, policy
['bad lockout attempt'])
86 self
.assertEquals(4294967295, policy
['disconnect time'])
87 self
.assertEquals(0, policy
['lockout duration'])
88 self
.assertEquals(999999999, policy
['maximum password age'])
89 self
.assertEquals(0, policy
['minimum password age'])
90 self
.assertEquals(5, policy
['min password length'])
91 self
.assertEquals(0, policy
['password history'])
92 self
.assertEquals(0, policy
['refuse machine password change'])
93 self
.assertEquals(0, policy
['reset count minutes'])
94 self
.assertEquals(0, policy
['user must logon to change password'])
96 def test_get_sid(self
):
97 domain_sid
= passdb
.get_global_sam_sid()
98 self
.assertEquals(dom_sid("S-1-5-21-2470180966-3899876309-2637894779"), domain_sid
)
100 def test_usernames(self
):
101 userlist
= self
.pdb
.search_users(0)
102 self
.assertEquals(3, len(userlist
))
104 def test_getuser(self
):
105 user
= self
.pdb
.getsampwnam("root")
107 self
.assertEquals(16, user
.acct_ctrl
)
108 self
.assertEquals("", user
.acct_desc
)
109 self
.assertEquals(0, user
.bad_password_count
)
110 self
.assertEquals(0, user
.bad_password_time
)
111 self
.assertEquals(0, user
.code_page
)
112 self
.assertEquals(0, user
.country_code
)
113 self
.assertEquals("", user
.dir_drive
)
114 self
.assertEquals("BEDWYR", user
.domain
)
115 self
.assertEquals("root", user
.full_name
)
116 self
.assertEquals(dom_sid('S-1-5-21-2470180966-3899876309-2637894779-513'), user
.group_sid
)
117 self
.assertEquals("\\\\BEDWYR\\root", user
.home_dir
)
118 self
.assertEquals([-1 for i
in range(21)], user
.hours
)
119 self
.assertEquals(21, user
.hours_len
)
120 self
.assertEquals(9223372036854775807, user
.kickoff_time
)
121 self
.assertEquals(None, user
.lanman_passwd
)
122 self
.assertEquals(9223372036854775807, user
.logoff_time
)
123 self
.assertEquals(0, user
.logon_count
)
124 self
.assertEquals(168, user
.logon_divs
)
125 self
.assertEquals("", user
.logon_script
)
126 self
.assertEquals(0, user
.logon_time
)
127 self
.assertEquals("", user
.munged_dial
)
128 self
.assertEquals('\x87\x8d\x80\x14`l\xda)gzD\xef\xa15?\xc7', user
.nt_passwd
)
129 self
.assertEquals("", user
.nt_username
)
130 self
.assertEquals(1125418267, user
.pass_can_change_time
)
131 self
.assertEquals(1125418267, user
.pass_last_set_time
)
132 self
.assertEquals(2125418266, user
.pass_must_change_time
)
133 self
.assertEquals(None, user
.plaintext_passwd
)
134 self
.assertEquals("\\\\BEDWYR\\root\\profile", user
.profile_path
)
135 self
.assertEquals(None, user
.pw_history
)
136 self
.assertEquals(dom_sid("S-1-5-21-2470180966-3899876309-2637894779-1000"), user
.user_sid
)
137 self
.assertEquals("root", user
.username
)
138 self
.assertEquals("", user
.workstations
)
140 def test_group_length(self
):
141 grouplist
= self
.pdb
.enum_group_mapping()
142 self
.assertEquals(13, len(grouplist
))
144 def test_get_group(self
):
145 group
= self
.pdb
.getgrsid(dom_sid("S-1-5-32-544"))
146 self
.assertEquals("Administrators", group
.nt_name
)
147 self
.assertEquals(4294967295, group
.gid
)
148 self
.assertEquals(5, group
.sid_name_use
)
150 def test_groupsids(self
):
151 grouplist
= self
.pdb
.enum_group_mapping()
154 sids
.append(str(g
.sid
))
155 self
.assertTrue("S-1-5-32-544" in sids
)
156 self
.assertTrue("S-1-5-32-545" in sids
)
157 self
.assertTrue("S-1-5-32-546" in sids
)
158 self
.assertTrue("S-1-5-32-548" in sids
)
159 self
.assertTrue("S-1-5-32-549" in sids
)
160 self
.assertTrue("S-1-5-32-550" in sids
)
161 self
.assertTrue("S-1-5-32-551" in sids
)
163 def test_alias_length(self
):
164 aliaslist
= self
.pdb
.search_aliases()
165 self
.assertEquals(1, len(aliaslist
))
166 self
.assertEquals("Jelmers NT Group", aliaslist
[0]['account_name'])
169 class WinsDatabaseTestCase(TestCase
):
172 super(WinsDatabaseTestCase
, self
).setUp()
173 self
.winsdb
= WinsDatabase(os
.path
.join(DATADIR
, "wins.dat"))
175 def test_length(self
):
176 self
.assertEquals(22, len(self
.winsdb
))
178 def test_first_entry(self
):
179 self
.assertEqual((1124185120, ["192.168.1.5"], 0x64), self
.winsdb
["ADMINISTRATOR#03"])
183 super(WinsDatabaseTestCase
, self
).tearDown()
186 class IdmapDbTestCase(TestCase
):
189 super(IdmapDbTestCase
, self
).setUp()
190 self
.idmapdb
= IdmapDatabase(os
.path
.join(DATADIR
,
191 "winbindd_idmap.tdb"))
193 def test_user_hwm(self
):
194 self
.assertEquals(10000, self
.idmapdb
.get_user_hwm())
196 def test_group_hwm(self
):
197 self
.assertEquals(10002, self
.idmapdb
.get_group_hwm())
200 self
.assertEquals(1, len(list(self
.idmapdb
.uids())))
203 self
.assertEquals(3, len(list(self
.idmapdb
.gids())))
205 def test_get_user_sid(self
):
206 self
.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self
.idmapdb
.get_user_sid(65534))
208 def test_get_group_sid(self
):
209 self
.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self
.idmapdb
.get_group_sid(10001))
213 super(IdmapDbTestCase
, self
).tearDown()