9025fdd9786e10f1a6ea0ee1559d72e22a6dca4a
[samba.git] / source4 / scripting / swig / torture / torture_samr.py
1 #!/usr/bin/python
2
3 import sys
4 import dcerpc, samr
5
6 def test_Connect(pipe):
7
8     handle = samr.Connect(pipe)
9     handle = samr.Connect2(pipe)
10     handle = samr.Connect3(pipe)
11     handle = samr.Connect4(pipe)
12
13     # WIN2K3 only?
14     
15     try:
16         handle = samr.Connect5(pipe)
17     except dcerpc.NTSTATUS, arg:
18         if arg[0] != 0xc00000d2L:       # NT_STATUS_NET_WRITE_FAULT
19             raise
20
21     return handle
22     
23 def test_UserHandle(user_handle):
24
25     # QuerySecurity()/SetSecurity()
26
27     user_handle.SetSecurity(user_handle.QuerySecurity())
28
29     # GetUserPwInfo()
30
31     user_handle.GetUserPwInfo()
32
33     # GetUserInfo()
34
35     for level in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 20,
36                   21, 23, 24, 25, 26]:
37
38         try:
39             user_handle.QueryUserInfo(level)
40             user_handle.QueryUserInfo2(level)
41         except dcerpc.NTSTATUS, arg:
42             if arg[0] != 0xc0000003L:   # NT_STATUS_INVALID_INFO_CLASS
43                 raise
44
45 def test_GroupHandle(group_handle):
46
47     # QuerySecurity()/SetSecurity()
48
49     group_handle.SetSecurity(group_handle.QuerySecurity())
50
51 def test_AliasHandle(alias_handle):
52
53     # QuerySecurity()/SetSecurity()
54
55     alias_handle.SetSecurity(alias_handle.QuerySecurity())
56
57 def test_DomainHandle(name, sid, domain_handle):
58
59     print 'testing %s (%s)' % (name, sid)
60
61     # QuerySecurity()/SetSecurity()
62
63     domain_handle.SetSecurity(domain_handle.QuerySecurity())
64
65     # LookupNames(), none mapped
66
67     try:
68         domain_handle.LookupNames(['xxNONAMExx'])
69     except dcerpc.NTSTATUS, arg:
70         if arg[0] != 0xc0000073L:
71             raise dcerpc.NTSTATUS(arg)
72
73     # LookupNames(), some mapped
74
75     if name != 'Builtin':
76         domain_handle.LookupNames(['Administrator', 'xxNONAMExx'])
77
78     # QueryDomainInfo()/SetDomainInfo()
79
80     levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13]
81     set_ok = [1, 0, 1, 1, 0, 1, 1, 0, 1,  0,  1,  0]
82     
83     for i in range(len(levels)):
84
85         info = domain_handle.QueryDomainInfo(level = levels[i])
86
87         try:
88             domain_handle.SetDomainInfo(levels[i], info)
89         except dcerpc.NTSTATUS, arg:
90             if not (arg[0] == 0xc0000003L and not set_ok[i]):
91                 raise
92
93     # QueryDomainInfo2()
94
95     levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13]
96
97     for i in range(len(levels)):
98         domain_handle.QueryDomainInfo2(level = levels[i])
99
100     # EnumDomainUsers
101
102     print 'testing users'
103
104     users = domain_handle.EnumDomainUsers()
105     rids = domain_handle.LookupNames(users)
106     
107     for i in range(len(users)):
108         test_UserHandle(domain_handle.OpenUser(rids[0][i]))
109     
110     # QueryDisplayInfo
111
112     for i in [1, 2, 3, 4, 5]:
113         domain_handle.QueryDisplayInfo(level = i)
114         domain_handle.QueryDisplayInfo2(level = i)
115         domain_handle.QueryDisplayInfo3(level = i)
116             
117     # EnumDomainGroups
118
119     print 'testing groups'
120
121     groups = domain_handle.EnumDomainGroups()
122     rids = domain_handle.LookupNames(groups)
123
124     for i in range(len(groups)):
125         test_GroupHandle(domain_handle.OpenGroup(rids[0][i]))
126
127     # EnumDomainAliases
128
129     print 'testing aliases'
130
131     aliases = domain_handle.EnumDomainAliases()
132     rids = domain_handle.LookupNames(aliases)
133
134     for i in range(len(aliases)):
135         test_AliasHandle(domain_handle.OpenAlias(rids[0][i]))
136     
137     # CreateUser
138     # CreateUser2
139     # CreateDomAlias
140     # RidToSid
141     # RemoveMemberFromForeignDomain
142     # CreateDomainGroup
143     # GetAliasMembership
144
145 def test_ConnectHandle(connect_handle):
146
147     print 'testing connect handle'
148
149     # QuerySecurity/SetSecurity
150
151     connect_handle.SetSecurity(connect_handle.QuerySecurity())
152
153     # Lookup bogus domain
154
155     try:
156         connect_handle.LookupDomain('xxNODOMAINxx')
157     except dcerpc.NTSTATUS, arg:
158         if arg[0] != 0xC00000DFL:          # NT_STATUS_NO_SUCH_DOMAIN
159             raise
160
161     # Test all domains
162
163     for domain_name in connect_handle.EnumDomains():
164
165         connect_handle.GetDomPwInfo(domain_name)
166         sid = connect_handle.LookupDomain(domain_name)
167         domain_handle = connect_handle.OpenDomain(sid)
168
169         test_DomainHandle(domain_name, sid, domain_handle)
170
171     # TODO: Test Shutdown() function
172
173 def runtests(binding, creds):
174
175     print 'Testing SAMR pipe'
176
177     pipe = dcerpc.pipe_connect(binding,
178             dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), creds)
179
180     handle = test_Connect(pipe)
181     test_ConnectHandle(handle)