2 * Unix SMB/CIFS implementation.
3 * test suite for samr rpc operations
5 * Copyright (c) 2011 Andreas Schneider
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 #include "param/param.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_samr_c.h"
25 #include "librpc/rpc/dcerpc_proto.h"
26 #include "torture/rpc/torture_rpc.h"
28 #define TEST_ACCOUNT_NAME "guru"
30 static void init_lsa_String(struct lsa_String *name, const char *s)
35 static bool test_samr_queryUserInfo(struct torture_context *tctx,
36 struct dcerpc_binding_handle *b,
37 struct policy_handle *user_handle)
39 struct samr_QueryUserInfo r;
40 union samr_UserInfo *info;
43 r.in.level = UserGeneralInformation;
44 r.in.user_handle = user_handle;
47 status = dcerpc_samr_QueryUserInfo_r(b,
50 torture_assert_ntstatus_ok(tctx, status, "queryUserInfo failed");
51 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_OK)) {
52 torture_comment(tctx, "queryUserInfo failed");
59 static bool test_LookupName(struct dcerpc_binding_handle *b,
60 struct torture_context *tctx,
61 struct policy_handle *domain_handle,
66 struct samr_LookupNames n;
67 struct lsa_String sname[1];
68 struct samr_Ids rids, types;
70 init_lsa_String(&sname[0], name);
72 n.in.domain_handle = domain_handle;
78 status = dcerpc_samr_LookupNames_r(b, tctx, &n);
79 if (!NT_STATUS_IS_OK(status)) {
82 if (!NT_STATUS_IS_OK(n.out.result)) {
86 *rid = n.out.rids->ids[0];
90 static bool test_samr_OpenUser(struct torture_context *tctx,
91 struct dcerpc_binding_handle *b,
92 struct policy_handle *domain_handle,
94 struct policy_handle *user_handle,
97 struct samr_OpenUser r;
102 ok = test_LookupName(b, tctx, domain_handle, name, &rid);
103 if (!ok && expected) {
104 torture_comment(tctx, " - lookup name for %s failed\n", name);
110 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
111 r.in.domain_handle = domain_handle;
113 r.out.user_handle = user_handle;
115 status = dcerpc_samr_OpenUser_r(b, tctx, &r);
116 torture_assert_ntstatus_ok(tctx, status, "CreateUser failed");
117 if (!NT_STATUS_IS_OK(r.out.result)) {
118 torture_comment(tctx, "CreateUser failed");
125 static bool test_samr_openDomain(struct torture_context *tctx,
126 struct dcerpc_binding_handle *b,
127 struct policy_handle *connect_handle,
129 struct policy_handle *domain_handle)
131 struct samr_LookupDomain r;
132 struct samr_OpenDomain r2;
137 r.in.connect_handle = connect_handle;
138 init_lsa_String(&n, domain);
139 r.in.domain_name = &n;
142 status = dcerpc_samr_LookupDomain_r(b, tctx, &r);
143 torture_assert_ntstatus_ok(tctx, status, "LookupDomain failed");
144 if (!NT_STATUS_IS_OK(r.out.result)) {
145 torture_comment(tctx, "LookupDomain failed - %s\n", nt_errstr(r.out.result));
149 r2.in.connect_handle = connect_handle;
150 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
152 r2.out.domain_handle = domain_handle;
154 status = dcerpc_samr_OpenDomain_r(b, tctx, &r2);
155 torture_assert_ntstatus_ok(tctx, status, "OpenDomain failed");
156 if (!NT_STATUS_IS_OK(r2.out.result)) {
157 torture_comment(tctx, "OpenDomain failed - %s\n", nt_errstr(r.out.result));
164 static bool test_samr_Connect(struct torture_context *tctx,
165 struct dcerpc_binding_handle *b,
166 struct policy_handle *connect_handle)
168 struct samr_Connect r;
171 r.in.system_name = 0;
172 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
173 r.out.connect_handle = connect_handle;
175 status = dcerpc_samr_Connect_r(b, tctx, &r);
176 torture_assert_ntstatus_ok(tctx, status, "SAMR connect failed");
177 if (!NT_STATUS_IS_OK(r.out.result)) {
178 torture_comment(tctx, "Connect failed - %s\n", nt_errstr(r.out.result));
185 static bool test_samr_userinfo_getinfo(struct torture_context *tctx,
186 struct dcerpc_pipe *p,
190 struct dcerpc_pipe *p2 = NULL;
191 struct dcerpc_binding_handle *b;
192 struct policy_handle connect_handle;
193 struct policy_handle domain_handle;
194 struct policy_handle user_handle;
199 status = torture_rpc_connection(tctx, &p2, &ndr_table_samr);
200 torture_assert_ntstatus_ok(tctx, status,
201 "Creating secondary connection failed");
202 b = p2->binding_handle;
204 torture_comment(tctx, " - 2nd connect\n");
206 ZERO_STRUCT(connect_handle);
207 ok = test_samr_Connect(tctx, b, &connect_handle);
208 torture_assert(tctx, ok, "Unable to connect to domain");
210 torture_comment(tctx, " - 2nd open domain\n");
212 ZERO_STRUCT(domain_handle);
213 ok = test_samr_openDomain(tctx,
216 torture_setting_string(tctx, "workgroup",
217 lpcfg_workgroup(tctx->lp_ctx)),
219 torture_assert(tctx, ok, "Unable to open to domain");
222 name = talloc_asprintf(tctx,
227 torture_comment(tctx, " - 2nd open user\n");
228 ZERO_STRUCT(user_handle);
229 ok = test_samr_OpenUser(tctx,
235 torture_assert(tctx, ok, "Unable to open user");
238 torture_comment(tctx, " - 2nd query user\n");
239 ok = test_samr_queryUserInfo(tctx, b, &user_handle);
240 torture_assert(tctx, ok, "Unable to query user");
242 test_samr_handle_Close(b, tctx, &user_handle);
245 test_samr_handle_Close(b, tctx, &domain_handle);
246 test_samr_handle_Close(b, tctx, &connect_handle);
254 static bool torture_rpc_samr_caching(struct torture_context *tctx,
255 struct dcerpc_pipe *p)
257 struct test_join *join;
258 const char *password = NULL;
264 torture_comment(tctx, ">>> Testing User Info Caching\n");
267 name = talloc_asprintf(tctx,
272 torture_comment(tctx, "- Creating user %s\n", name);
274 join = torture_create_testuser(tctx,
276 torture_setting_string(tctx, "workgroup",
277 lpcfg_workgroup(tctx->lp_ctx)),
284 torture_comment(tctx, "- Query user information\n");
285 for (i = 0; i < NUM_RUNS; i++) {
286 ok = test_samr_userinfo_getinfo(tctx, p, false);
287 torture_assert(tctx, ok, "test_samr_userinfo_getinfo failed");
290 torture_comment(tctx, "- Delete user\n");
291 status = torture_delete_testuser(tctx,
294 if (!NT_STATUS_IS_OK(status)) {
295 torture_comment(tctx, "DeleteUser failed - %s\n",
300 torture_comment(tctx, "- Try to query user information again (should fail)\n");
301 for (i = 0; i < NUM_RUNS; i++) {
302 ok = test_samr_userinfo_getinfo(tctx,
305 torture_assert(tctx, ok, "test_samr_userinfo_getinfo failed");
312 struct torture_suite *torture_rpc_samr_priv(TALLOC_CTX *mem_ctx)
314 struct torture_suite *suite =
315 torture_suite_create(mem_ctx, "samr.priv");
316 struct torture_rpc_tcase *tcase;
318 tcase = torture_suite_add_rpc_iface_tcase(suite,
322 torture_rpc_tcase_add_test(tcase,
324 torture_rpc_samr_caching);