General cleanups of python code, hinted by pyflakes.
[Samba/eduardoll.git] / source4 / scripting / python / samba / torture / torture_samr.py
blobe73bb4f21ec4fb318accf9d0591f75b2d84ce217
1 #!/usr/bin/python
3 import dcerpc, samr
5 def test_Connect(pipe):
7 handle = samr.Connect(pipe)
8 handle = samr.Connect2(pipe)
9 handle = samr.Connect3(pipe)
10 handle = samr.Connect4(pipe)
12 # WIN2K3 only?
14 try:
15 handle = samr.Connect5(pipe)
16 except dcerpc.NTSTATUS, arg:
17 if arg[0] != 0xc00000d2L: # NT_STATUS_NET_WRITE_FAULT
18 raise
20 return handle
22 def test_UserHandle(user_handle):
24 # QuerySecurity()/SetSecurity()
26 user_handle.SetSecurity(user_handle.QuerySecurity())
28 # GetUserPwInfo()
30 user_handle.GetUserPwInfo()
32 # GetUserInfo()
34 for level in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 20,
35 21, 23, 24, 25, 26]:
37 try:
38 user_handle.QueryUserInfo(level)
39 user_handle.QueryUserInfo2(level)
40 except dcerpc.NTSTATUS, arg:
41 if arg[0] != 0xc0000003L: # NT_STATUS_INVALID_INFO_CLASS
42 raise
44 # GetGroupsForUser()
46 user_handle.GetGroupsForUser()
48 # TestPrivateFunctionsUser()
50 try:
51 user_handle.TestPrivateFunctionsUser()
52 except dcerpc.NTSTATUS, arg:
53 if arg[0] != 0xC0000002L:
54 raise
56 def test_GroupHandle(group_handle):
58 # QuerySecurity()/SetSecurity()
60 group_handle.SetSecurity(group_handle.QuerySecurity())
62 # QueryGroupInfo()
64 for level in [1, 2, 3, 4, 5]:
65 info = group_handle.QueryGroupInfo(level)
67 # TODO: SetGroupinfo()
69 # QueryGroupMember()
71 group_handle.QueryGroupMember()
73 def test_AliasHandle(alias_handle):
75 # QuerySecurity()/SetSecurity()
77 alias_handle.SetSecurity(alias_handle.QuerySecurity())
79 print alias_handle.GetMembersInAlias()
81 def test_DomainHandle(name, sid, domain_handle):
83 print 'testing %s (%s)' % (name, sid)
85 # QuerySecurity()/SetSecurity()
87 domain_handle.SetSecurity(domain_handle.QuerySecurity())
89 # LookupNames(), none mapped
91 try:
92 domain_handle.LookupNames(['xxNONAMExx'])
93 except dcerpc.NTSTATUS, arg:
94 if arg[0] != 0xc0000073L:
95 raise dcerpc.NTSTATUS(arg)
97 # LookupNames(), some mapped
99 if name != 'Builtin':
100 domain_handle.LookupNames(['Administrator', 'xxNONAMExx'])
102 # QueryDomainInfo()/SetDomainInfo()
104 levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13]
105 set_ok = [1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0]
107 for i in range(len(levels)):
109 info = domain_handle.QueryDomainInfo(level = levels[i])
111 try:
112 domain_handle.SetDomainInfo(levels[i], info)
113 except dcerpc.NTSTATUS, arg:
114 if not (arg[0] == 0xc0000003L and not set_ok[i]):
115 raise
117 # QueryDomainInfo2()
119 levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13]
121 for i in range(len(levels)):
122 domain_handle.QueryDomainInfo2(level = levels[i])
124 # EnumDomainUsers
126 print 'testing users'
128 users = domain_handle.EnumDomainUsers()
129 rids = domain_handle.LookupNames(users)
131 for i in range(len(users)):
132 test_UserHandle(domain_handle.OpenUser(rids[0][i]))
134 # QueryDisplayInfo
136 for i in [1, 2, 3, 4, 5]:
137 domain_handle.QueryDisplayInfo(level = i)
138 domain_handle.QueryDisplayInfo2(level = i)
139 domain_handle.QueryDisplayInfo3(level = i)
141 # EnumDomainGroups
143 print 'testing groups'
145 groups = domain_handle.EnumDomainGroups()
146 rids = domain_handle.LookupNames(groups)
148 for i in range(len(groups)):
149 test_GroupHandle(domain_handle.OpenGroup(rids[0][i]))
151 # EnumDomainAliases
153 print 'testing aliases'
155 aliases = domain_handle.EnumDomainAliases()
156 rids = domain_handle.LookupNames(aliases)
158 for i in range(len(aliases)):
159 test_AliasHandle(domain_handle.OpenAlias(rids[0][i]))
161 # CreateUser
162 # CreateUser2
163 # CreateDomAlias
164 # RidToSid
165 # RemoveMemberFromForeignDomain
166 # CreateDomainGroup
167 # GetAliasMembership
169 # GetBootKeyInformation()
171 try:
172 domain_handle.GetBootKeyInformation()
173 except dcerpc.NTSTATUS, arg:
174 pass
176 # TestPrivateFunctionsDomain()
178 try:
179 domain_handle.TestPrivateFunctionsDomain()
180 except dcerpc.NTSTATUS, arg:
181 if arg[0] != 0xC0000002L:
182 raise
184 def test_ConnectHandle(connect_handle):
186 print 'testing connect handle'
188 # QuerySecurity/SetSecurity
190 connect_handle.SetSecurity(connect_handle.QuerySecurity())
192 # Lookup bogus domain
194 try:
195 connect_handle.LookupDomain('xxNODOMAINxx')
196 except dcerpc.NTSTATUS, arg:
197 if arg[0] != 0xC00000DFL: # NT_STATUS_NO_SUCH_DOMAIN
198 raise
200 # Test all domains
202 for domain_name in connect_handle.EnumDomains():
204 connect_handle.GetDomPwInfo(domain_name)
205 sid = connect_handle.LookupDomain(domain_name)
206 domain_handle = connect_handle.OpenDomain(sid)
208 test_DomainHandle(domain_name, sid, domain_handle)
210 # TODO: Test Shutdown() function
212 def runtests(binding, creds):
214 print 'Testing SAMR pipe'
216 pipe = dcerpc.pipe_connect(binding,
217 dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), creds)
219 handle = test_Connect(pipe)
220 test_ConnectHandle(handle)