2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * These are more general use functions shared among the tests.
26 #include "torture/rpc/rpc.h"
27 #include "libnet/libnet.h"
28 #include "librpc/gen_ndr/ndr_samr_c.h"
29 #include "torture/libnet/utils.h"
32 bool test_opendomain(struct torture_context
*tctx
,
33 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
34 struct policy_handle
*handle
, struct lsa_String
*domname
,
35 struct dom_sid2
*sid_p
)
38 struct policy_handle h
, domain_handle
;
39 struct samr_Connect r1
;
40 struct samr_LookupDomain r2
;
41 struct dom_sid2
*sid
= NULL
;
42 struct samr_OpenDomain r3
;
44 torture_comment(tctx
, "connecting\n");
46 r1
.in
.system_name
= 0;
47 r1
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
48 r1
.out
.connect_handle
= &h
;
50 status
= dcerpc_samr_Connect(p
, mem_ctx
, &r1
);
51 torture_assert_ntstatus_ok(tctx
, status
, "Connect failed");
53 r2
.in
.connect_handle
= &h
;
54 r2
.in
.domain_name
= domname
;
57 torture_comment(tctx
, "domain lookup on %s\n", domname
->string
);
59 status
= dcerpc_samr_LookupDomain(p
, mem_ctx
, &r2
);
60 torture_assert_ntstatus_ok(tctx
, status
, "LookupDomain failed");
62 r3
.in
.connect_handle
= &h
;
63 r3
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
64 r3
.in
.sid
= *r2
.out
.sid
;
65 r3
.out
.domain_handle
= &domain_handle
;
67 torture_comment(tctx
, "opening domain\n");
69 status
= dcerpc_samr_OpenDomain(p
, mem_ctx
, &r3
);
70 torture_assert_ntstatus_ok(tctx
, status
, "OpenDomain failed");
71 *handle
= domain_handle
;
73 *sid_p
= **r2
.out
.sid
;
78 bool test_user_cleanup(struct torture_context
*tctx
, struct dcerpc_pipe
*p
,
79 TALLOC_CTX
*mem_ctx
, struct policy_handle
*domain_handle
,
83 struct samr_LookupNames r1
;
84 struct samr_OpenUser r2
;
85 struct samr_DeleteUser r3
;
86 struct lsa_String names
[2];
88 struct policy_handle user_handle
;
89 struct samr_Ids rids
, types
;
91 names
[0].string
= name
;
93 r1
.in
.domain_handle
= domain_handle
;
97 r1
.out
.types
= &types
;
99 torture_comment(tctx
, "user account lookup '%s'\n", name
);
101 status
= dcerpc_samr_LookupNames(p
, mem_ctx
, &r1
);
102 torture_assert_ntstatus_ok(tctx
, status
, "LookupNames failed");
104 rid
= r1
.out
.rids
->ids
[0];
106 r2
.in
.domain_handle
= domain_handle
;
107 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
109 r2
.out
.user_handle
= &user_handle
;
111 torture_comment(tctx
, "opening user account\n");
113 status
= dcerpc_samr_OpenUser(p
, mem_ctx
, &r2
);
114 torture_assert_ntstatus_ok(tctx
, status
, "OpenUser failed");
116 r3
.in
.user_handle
= &user_handle
;
117 r3
.out
.user_handle
= &user_handle
;
119 torture_comment(tctx
, "deleting user account\n");
121 status
= dcerpc_samr_DeleteUser(p
, mem_ctx
, &r3
);
122 torture_assert_ntstatus_ok(tctx
, status
, "DeleteUser failed");
128 bool test_user_create(struct torture_context
*tctx
,
129 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
130 struct policy_handle
*handle
, const char *name
,
134 struct lsa_String username
;
135 struct samr_CreateUser r
;
136 struct policy_handle user_handle
;
138 username
.string
= name
;
140 r
.in
.domain_handle
= handle
;
141 r
.in
.account_name
= &username
;
142 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
143 r
.out
.user_handle
= &user_handle
;
146 torture_comment(tctx
, "creating user account %s\n", name
);
148 status
= dcerpc_samr_CreateUser(p
, mem_ctx
, &r
);
149 if (!NT_STATUS_IS_OK(status
)) {
150 printf("CreateUser failed - %s\n", nt_errstr(status
));
152 if (NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
153 torture_comment(tctx
, "User (%s) already exists - attempting to delete and recreate account again\n", name
);
154 if (!test_user_cleanup(tctx
, p
, mem_ctx
, handle
, name
)) {
158 torture_comment(tctx
, "creating user account\n");
160 status
= dcerpc_samr_CreateUser(p
, mem_ctx
, &r
);
161 torture_assert_ntstatus_ok(tctx
, status
, "CreateUser failed");
171 bool test_group_cleanup(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
172 struct policy_handle
*domain_handle
,
176 struct samr_LookupNames r1
;
177 struct samr_OpenGroup r2
;
178 struct samr_DeleteDomainGroup r3
;
179 struct lsa_String names
[2];
181 struct policy_handle group_handle
;
182 struct samr_Ids rids
, types
;
184 names
[0].string
= name
;
186 r1
.in
.domain_handle
= domain_handle
;
190 r1
.out
.types
= &types
;
192 printf("group account lookup '%s'\n", name
);
194 status
= dcerpc_samr_LookupNames(p
, mem_ctx
, &r1
);
195 if (!NT_STATUS_IS_OK(status
)) {
196 printf("LookupNames failed - %s\n", nt_errstr(status
));
200 rid
= r1
.out
.rids
->ids
[0];
202 r2
.in
.domain_handle
= domain_handle
;
203 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
205 r2
.out
.group_handle
= &group_handle
;
207 printf("opening group account\n");
209 status
= dcerpc_samr_OpenGroup(p
, mem_ctx
, &r2
);
210 if (!NT_STATUS_IS_OK(status
)) {
211 printf("OpenGroup failed - %s\n", nt_errstr(status
));
215 r3
.in
.group_handle
= &group_handle
;
216 r3
.out
.group_handle
= &group_handle
;
218 printf("deleting group account\n");
220 status
= dcerpc_samr_DeleteDomainGroup(p
, mem_ctx
, &r3
);
221 if (!NT_STATUS_IS_OK(status
)) {
222 printf("DeleteGroup failed - %s\n", nt_errstr(status
));
230 bool test_group_create(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
231 struct policy_handle
*handle
, const char *name
,
235 struct lsa_String groupname
;
236 struct samr_CreateDomainGroup r
;
237 struct policy_handle group_handle
;
239 groupname
.string
= name
;
241 r
.in
.domain_handle
= handle
;
242 r
.in
.name
= &groupname
;
243 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
244 r
.out
.group_handle
= &group_handle
;
247 printf("creating group account %s\n", name
);
249 status
= dcerpc_samr_CreateDomainGroup(p
, mem_ctx
, &r
);
250 if (!NT_STATUS_IS_OK(status
)) {
251 printf("CreateGroup failed - %s\n", nt_errstr(status
));
253 if (NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
254 printf("Group (%s) already exists - attempting to delete and recreate account again\n", name
);
255 if (!test_group_cleanup(p
, mem_ctx
, handle
, name
)) {
259 printf("creating group account\n");
261 status
= dcerpc_samr_CreateDomainGroup(p
, mem_ctx
, &r
);
262 if (!NT_STATUS_IS_OK(status
)) {
263 printf("CreateGroup failed - %s\n", nt_errstr(status
));
275 void msg_handler(struct monitor_msg
*m
)
277 struct msg_rpc_open_user
*msg_open
;
278 struct msg_rpc_query_user
*msg_query
;
279 struct msg_rpc_close_user
*msg_close
;
280 struct msg_rpc_create_user
*msg_create
;
283 case mon_SamrOpenUser
:
284 msg_open
= (struct msg_rpc_open_user
*)m
->data
;
285 printf("monitor_msg: user opened (rid=%d, access_mask=0x%08x)\n",
286 msg_open
->rid
, msg_open
->access_mask
);
288 case mon_SamrQueryUser
:
289 msg_query
= (struct msg_rpc_query_user
*)m
->data
;
290 printf("monitor_msg: user queried (level=%d)\n", msg_query
->level
);
292 case mon_SamrCloseUser
:
293 msg_close
= (struct msg_rpc_close_user
*)m
->data
;
294 printf("monitor_msg: user closed (rid=%d)\n", msg_close
->rid
);
296 case mon_SamrCreateUser
:
297 msg_create
= (struct msg_rpc_create_user
*)m
->data
;
298 printf("monitor_msg: user created (rid=%d)\n", msg_create
->rid
);