1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | dcerpc torture tests, designed to walk Samba3 code paths
|
---|
5 |
|
---|
6 | Copyright (C) Volker Lendecke 2006
|
---|
7 |
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 3 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 | #include "libcli/raw/libcliraw.h"
|
---|
24 | #include "libcli/raw/raw_proto.h"
|
---|
25 | #include "torture/util.h"
|
---|
26 | #include "libcli/rap/rap.h"
|
---|
27 | #include "librpc/gen_ndr/ndr_lsa_c.h"
|
---|
28 | #include "librpc/gen_ndr/ndr_samr_c.h"
|
---|
29 | #include "librpc/gen_ndr/ndr_netlogon_c.h"
|
---|
30 | #include "librpc/gen_ndr/ndr_srvsvc_c.h"
|
---|
31 | #include "librpc/gen_ndr/ndr_spoolss_c.h"
|
---|
32 | #include "librpc/gen_ndr/ndr_winreg_c.h"
|
---|
33 | #include "librpc/gen_ndr/ndr_wkssvc_c.h"
|
---|
34 | #include "lib/cmdline/popt_common.h"
|
---|
35 | #include "torture/rpc/torture_rpc.h"
|
---|
36 | #include "libcli/libcli.h"
|
---|
37 | #include "libcli/smb_composite/smb_composite.h"
|
---|
38 | #include "libcli/auth/libcli_auth.h"
|
---|
39 | #include "../lib/crypto/crypto.h"
|
---|
40 | #include "libcli/security/security.h"
|
---|
41 | #include "param/param.h"
|
---|
42 | #include "lib/registry/registry.h"
|
---|
43 | #include "libcli/resolve/resolve.h"
|
---|
44 | #include "torture/ndr/ndr.h"
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * This tests a RPC call using an invalid vuid
|
---|
48 | */
|
---|
49 |
|
---|
50 | bool torture_bind_authcontext(struct torture_context *torture)
|
---|
51 | {
|
---|
52 | TALLOC_CTX *mem_ctx;
|
---|
53 | NTSTATUS status;
|
---|
54 | bool ret = false;
|
---|
55 | struct lsa_ObjectAttribute objectattr;
|
---|
56 | struct lsa_OpenPolicy2 openpolicy;
|
---|
57 | struct policy_handle handle;
|
---|
58 | struct lsa_Close close_handle;
|
---|
59 | struct smbcli_session *tmp;
|
---|
60 | struct smbcli_session *session2;
|
---|
61 | struct smbcli_state *cli;
|
---|
62 | struct dcerpc_pipe *lsa_pipe;
|
---|
63 | struct dcerpc_binding_handle *lsa_handle;
|
---|
64 | struct cli_credentials *anon_creds;
|
---|
65 | struct smb_composite_sesssetup setup;
|
---|
66 | struct smbcli_options options;
|
---|
67 | struct smbcli_session_options session_options;
|
---|
68 |
|
---|
69 | mem_ctx = talloc_init("torture_bind_authcontext");
|
---|
70 |
|
---|
71 | if (mem_ctx == NULL) {
|
---|
72 | torture_comment(torture, "talloc_init failed\n");
|
---|
73 | return false;
|
---|
74 | }
|
---|
75 |
|
---|
76 | lpcfg_smbcli_options(torture->lp_ctx, &options);
|
---|
77 | lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
|
---|
78 |
|
---|
79 | status = smbcli_full_connection(mem_ctx, &cli,
|
---|
80 | torture_setting_string(torture, "host", NULL),
|
---|
81 | lpcfg_smb_ports(torture->lp_ctx),
|
---|
82 | "IPC$", NULL,
|
---|
83 | lpcfg_socket_options(torture->lp_ctx),
|
---|
84 | cmdline_credentials,
|
---|
85 | lpcfg_resolve_context(torture->lp_ctx),
|
---|
86 | torture->ev, &options, &session_options,
|
---|
87 | lpcfg_gensec_settings(torture, torture->lp_ctx));
|
---|
88 | if (!NT_STATUS_IS_OK(status)) {
|
---|
89 | torture_comment(torture, "smbcli_full_connection failed: %s\n",
|
---|
90 | nt_errstr(status));
|
---|
91 | goto done;
|
---|
92 | }
|
---|
93 |
|
---|
94 | lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
|
---|
95 | if (lsa_pipe == NULL) {
|
---|
96 | torture_comment(torture, "dcerpc_pipe_init failed\n");
|
---|
97 | goto done;
|
---|
98 | }
|
---|
99 | lsa_handle = lsa_pipe->binding_handle;
|
---|
100 |
|
---|
101 | status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
|
---|
102 | if (!NT_STATUS_IS_OK(status)) {
|
---|
103 | torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
|
---|
104 | nt_errstr(status));
|
---|
105 | goto done;
|
---|
106 | }
|
---|
107 |
|
---|
108 | status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
|
---|
109 | if (!NT_STATUS_IS_OK(status)) {
|
---|
110 | torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
|
---|
111 | nt_errstr(status));
|
---|
112 | goto done;
|
---|
113 | }
|
---|
114 |
|
---|
115 | openpolicy.in.system_name =talloc_asprintf(
|
---|
116 | mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
|
---|
117 | ZERO_STRUCT(objectattr);
|
---|
118 | openpolicy.in.attr = &objectattr;
|
---|
119 | openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
120 | openpolicy.out.handle = &handle;
|
---|
121 |
|
---|
122 | status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
|
---|
123 |
|
---|
124 | if (!NT_STATUS_IS_OK(status)) {
|
---|
125 | torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
|
---|
126 | nt_errstr(status));
|
---|
127 | goto done;
|
---|
128 | }
|
---|
129 | if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
|
---|
130 | torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
|
---|
131 | nt_errstr(openpolicy.out.result));
|
---|
132 | goto done;
|
---|
133 | }
|
---|
134 |
|
---|
135 | close_handle.in.handle = &handle;
|
---|
136 | close_handle.out.handle = &handle;
|
---|
137 |
|
---|
138 | status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
|
---|
139 | if (!NT_STATUS_IS_OK(status)) {
|
---|
140 | torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
|
---|
141 | nt_errstr(status));
|
---|
142 | goto done;
|
---|
143 | }
|
---|
144 | if (!NT_STATUS_IS_OK(close_handle.out.result)) {
|
---|
145 | torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
|
---|
146 | nt_errstr(close_handle.out.result));
|
---|
147 | goto done;
|
---|
148 | }
|
---|
149 |
|
---|
150 | session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
|
---|
151 | if (session2 == NULL) {
|
---|
152 | torture_comment(torture, "smbcli_session_init failed\n");
|
---|
153 | goto done;
|
---|
154 | }
|
---|
155 |
|
---|
156 | if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
|
---|
157 | torture_comment(torture, "create_anon_creds failed\n");
|
---|
158 | goto done;
|
---|
159 | }
|
---|
160 |
|
---|
161 | setup.in.sesskey = cli->transport->negotiate.sesskey;
|
---|
162 | setup.in.capabilities = cli->transport->negotiate.capabilities;
|
---|
163 | setup.in.workgroup = "";
|
---|
164 | setup.in.credentials = anon_creds;
|
---|
165 | setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
|
---|
166 |
|
---|
167 | status = smb_composite_sesssetup(session2, &setup);
|
---|
168 | if (!NT_STATUS_IS_OK(status)) {
|
---|
169 | torture_comment(torture, "anon session setup failed: %s\n",
|
---|
170 | nt_errstr(status));
|
---|
171 | goto done;
|
---|
172 | }
|
---|
173 | session2->vuid = setup.out.vuid;
|
---|
174 |
|
---|
175 | tmp = cli->tree->session;
|
---|
176 | cli->tree->session = session2;
|
---|
177 |
|
---|
178 | status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
|
---|
179 |
|
---|
180 | cli->tree->session = tmp;
|
---|
181 | talloc_free(lsa_pipe);
|
---|
182 | lsa_pipe = NULL;
|
---|
183 |
|
---|
184 | if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
|
---|
185 | torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
|
---|
186 | "expected NT_STATUS_INVALID_HANDLE\n",
|
---|
187 | nt_errstr(status));
|
---|
188 | goto done;
|
---|
189 | }
|
---|
190 |
|
---|
191 | ret = true;
|
---|
192 | done:
|
---|
193 | talloc_free(mem_ctx);
|
---|
194 | return ret;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * Bind to lsa using a specific auth method
|
---|
199 | */
|
---|
200 |
|
---|
201 | static bool bindtest(struct torture_context *tctx,
|
---|
202 | struct smbcli_state *cli,
|
---|
203 | struct cli_credentials *credentials,
|
---|
204 | uint8_t auth_type, uint8_t auth_level)
|
---|
205 | {
|
---|
206 | TALLOC_CTX *mem_ctx;
|
---|
207 | bool ret = false;
|
---|
208 | NTSTATUS status;
|
---|
209 |
|
---|
210 | struct dcerpc_pipe *lsa_pipe;
|
---|
211 | struct dcerpc_binding_handle *lsa_handle;
|
---|
212 | struct lsa_ObjectAttribute objectattr;
|
---|
213 | struct lsa_OpenPolicy2 openpolicy;
|
---|
214 | struct lsa_QueryInfoPolicy query;
|
---|
215 | union lsa_PolicyInformation *info = NULL;
|
---|
216 | struct policy_handle handle;
|
---|
217 | struct lsa_Close close_handle;
|
---|
218 |
|
---|
219 | if ((mem_ctx = talloc_init("bindtest")) == NULL) {
|
---|
220 | torture_comment(tctx, "talloc_init failed\n");
|
---|
221 | return false;
|
---|
222 | }
|
---|
223 |
|
---|
224 | lsa_pipe = dcerpc_pipe_init(mem_ctx,
|
---|
225 | cli->transport->socket->event.ctx);
|
---|
226 | if (lsa_pipe == NULL) {
|
---|
227 | torture_comment(tctx, "dcerpc_pipe_init failed\n");
|
---|
228 | goto done;
|
---|
229 | }
|
---|
230 | lsa_handle = lsa_pipe->binding_handle;
|
---|
231 |
|
---|
232 | status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
|
---|
233 | if (!NT_STATUS_IS_OK(status)) {
|
---|
234 | torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
|
---|
235 | nt_errstr(status));
|
---|
236 | goto done;
|
---|
237 | }
|
---|
238 |
|
---|
239 | status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
|
---|
240 | credentials, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
|
---|
241 | NULL);
|
---|
242 | if (!NT_STATUS_IS_OK(status)) {
|
---|
243 | torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status));
|
---|
244 | goto done;
|
---|
245 | }
|
---|
246 |
|
---|
247 | openpolicy.in.system_name =talloc_asprintf(
|
---|
248 | mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
|
---|
249 | ZERO_STRUCT(objectattr);
|
---|
250 | openpolicy.in.attr = &objectattr;
|
---|
251 | openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
252 | openpolicy.out.handle = &handle;
|
---|
253 |
|
---|
254 | status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
|
---|
255 |
|
---|
256 | if (!NT_STATUS_IS_OK(status)) {
|
---|
257 | torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
|
---|
258 | nt_errstr(status));
|
---|
259 | goto done;
|
---|
260 | }
|
---|
261 | if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
|
---|
262 | torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
|
---|
263 | nt_errstr(openpolicy.out.result));
|
---|
264 | goto done;
|
---|
265 | }
|
---|
266 |
|
---|
267 | query.in.handle = &handle;
|
---|
268 | query.in.level = LSA_POLICY_INFO_DOMAIN;
|
---|
269 | query.out.info = &info;
|
---|
270 |
|
---|
271 | status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query);
|
---|
272 | if (!NT_STATUS_IS_OK(status)) {
|
---|
273 | torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
|
---|
274 | nt_errstr(status));
|
---|
275 | goto done;
|
---|
276 | }
|
---|
277 | if (!NT_STATUS_IS_OK(query.out.result)) {
|
---|
278 | torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
|
---|
279 | nt_errstr(query.out.result));
|
---|
280 | goto done;
|
---|
281 | }
|
---|
282 |
|
---|
283 | close_handle.in.handle = &handle;
|
---|
284 | close_handle.out.handle = &handle;
|
---|
285 |
|
---|
286 | status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
|
---|
287 | if (!NT_STATUS_IS_OK(status)) {
|
---|
288 | torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
|
---|
289 | nt_errstr(status));
|
---|
290 | goto done;
|
---|
291 | }
|
---|
292 | if (!NT_STATUS_IS_OK(close_handle.out.result)) {
|
---|
293 | torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
|
---|
294 | nt_errstr(close_handle.out.result));
|
---|
295 | goto done;
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | ret = true;
|
---|
300 | done:
|
---|
301 | talloc_free(mem_ctx);
|
---|
302 | return ret;
|
---|
303 | }
|
---|
304 |
|
---|
305 | /*
|
---|
306 | * test authenticated RPC binds with the variants Samba3 does support
|
---|
307 | */
|
---|
308 |
|
---|
309 | static bool torture_bind_samba3(struct torture_context *torture)
|
---|
310 | {
|
---|
311 | TALLOC_CTX *mem_ctx;
|
---|
312 | NTSTATUS status;
|
---|
313 | bool ret = false;
|
---|
314 | struct smbcli_state *cli;
|
---|
315 | struct smbcli_options options;
|
---|
316 | struct smbcli_session_options session_options;
|
---|
317 |
|
---|
318 | mem_ctx = talloc_init("torture_bind_authcontext");
|
---|
319 |
|
---|
320 | if (mem_ctx == NULL) {
|
---|
321 | torture_comment(torture, "talloc_init failed\n");
|
---|
322 | return false;
|
---|
323 | }
|
---|
324 |
|
---|
325 | lpcfg_smbcli_options(torture->lp_ctx, &options);
|
---|
326 | lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
|
---|
327 |
|
---|
328 | status = smbcli_full_connection(mem_ctx, &cli,
|
---|
329 | torture_setting_string(torture, "host", NULL),
|
---|
330 | lpcfg_smb_ports(torture->lp_ctx),
|
---|
331 | "IPC$", NULL,
|
---|
332 | lpcfg_socket_options(torture->lp_ctx),
|
---|
333 | cmdline_credentials,
|
---|
334 | lpcfg_resolve_context(torture->lp_ctx),
|
---|
335 | torture->ev, &options, &session_options,
|
---|
336 | lpcfg_gensec_settings(torture, torture->lp_ctx));
|
---|
337 | if (!NT_STATUS_IS_OK(status)) {
|
---|
338 | torture_comment(torture, "smbcli_full_connection failed: %s\n",
|
---|
339 | nt_errstr(status));
|
---|
340 | goto done;
|
---|
341 | }
|
---|
342 |
|
---|
343 | ret = true;
|
---|
344 |
|
---|
345 | ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
|
---|
346 | DCERPC_AUTH_LEVEL_INTEGRITY);
|
---|
347 | ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
|
---|
348 | DCERPC_AUTH_LEVEL_PRIVACY);
|
---|
349 | ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
|
---|
350 | DCERPC_AUTH_LEVEL_INTEGRITY);
|
---|
351 | ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
|
---|
352 | DCERPC_AUTH_LEVEL_PRIVACY);
|
---|
353 |
|
---|
354 | done:
|
---|
355 | talloc_free(mem_ctx);
|
---|
356 | return ret;
|
---|
357 | }
|
---|
358 |
|
---|
359 | /*
|
---|
360 | * Lookup or create a user and return all necessary info
|
---|
361 | */
|
---|
362 |
|
---|
363 | static bool get_usr_handle(struct torture_context *tctx,
|
---|
364 | struct smbcli_state *cli,
|
---|
365 | TALLOC_CTX *mem_ctx,
|
---|
366 | struct cli_credentials *admin_creds,
|
---|
367 | uint8_t auth_type,
|
---|
368 | uint8_t auth_level,
|
---|
369 | const char *username,
|
---|
370 | char **domain,
|
---|
371 | struct dcerpc_pipe **result_pipe,
|
---|
372 | struct policy_handle **result_handle,
|
---|
373 | struct dom_sid **sid_p)
|
---|
374 | {
|
---|
375 | struct dcerpc_pipe *samr_pipe;
|
---|
376 | struct dcerpc_binding_handle *samr_handle;
|
---|
377 | NTSTATUS status;
|
---|
378 | struct policy_handle conn_handle;
|
---|
379 | struct policy_handle domain_handle;
|
---|
380 | struct policy_handle *user_handle;
|
---|
381 | struct samr_Connect2 conn;
|
---|
382 | struct samr_EnumDomains enumdom;
|
---|
383 | uint32_t resume_handle = 0;
|
---|
384 | uint32_t num_entries = 0;
|
---|
385 | struct samr_SamArray *sam = NULL;
|
---|
386 | struct samr_LookupDomain l;
|
---|
387 | struct dom_sid2 *sid = NULL;
|
---|
388 | int dom_idx;
|
---|
389 | struct lsa_String domain_name;
|
---|
390 | struct lsa_String user_name;
|
---|
391 | struct samr_OpenDomain o;
|
---|
392 | struct samr_CreateUser2 c;
|
---|
393 | uint32_t user_rid,access_granted;
|
---|
394 |
|
---|
395 | samr_pipe = dcerpc_pipe_init(mem_ctx,
|
---|
396 | cli->transport->socket->event.ctx);
|
---|
397 | torture_assert(tctx, samr_pipe, "dcerpc_pipe_init failed");
|
---|
398 |
|
---|
399 | samr_handle = samr_pipe->binding_handle;
|
---|
400 |
|
---|
401 | torture_assert_ntstatus_ok(tctx,
|
---|
402 | dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr"),
|
---|
403 | "dcerpc_pipe_open_smb failed");
|
---|
404 |
|
---|
405 | if (admin_creds != NULL) {
|
---|
406 | torture_assert_ntstatus_ok(tctx,
|
---|
407 | dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
|
---|
408 | admin_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
|
---|
409 | NULL),
|
---|
410 | "dcerpc_bind_auth failed");
|
---|
411 | } else {
|
---|
412 | /* We must have an authenticated SMB connection */
|
---|
413 | torture_assert_ntstatus_ok(tctx,
|
---|
414 | dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr),
|
---|
415 | "dcerpc_bind_auth_none failed");
|
---|
416 | }
|
---|
417 |
|
---|
418 | conn.in.system_name = talloc_asprintf(
|
---|
419 | mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
|
---|
420 | conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
421 | conn.out.connect_handle = &conn_handle;
|
---|
422 |
|
---|
423 | torture_assert_ntstatus_ok(tctx,
|
---|
424 | dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn),
|
---|
425 | "samr_Connect2 failed");
|
---|
426 | torture_assert_ntstatus_ok(tctx, conn.out.result,
|
---|
427 | "samr_Connect2 failed");
|
---|
428 |
|
---|
429 | enumdom.in.connect_handle = &conn_handle;
|
---|
430 | enumdom.in.resume_handle = &resume_handle;
|
---|
431 | enumdom.in.buf_size = (uint32_t)-1;
|
---|
432 | enumdom.out.resume_handle = &resume_handle;
|
---|
433 | enumdom.out.num_entries = &num_entries;
|
---|
434 | enumdom.out.sam = &sam;
|
---|
435 |
|
---|
436 | torture_assert_ntstatus_ok(tctx,
|
---|
437 | dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom),
|
---|
438 | "samr_EnumDomains failed");
|
---|
439 | torture_assert_ntstatus_ok(tctx, enumdom.out.result,
|
---|
440 | "samr_EnumDomains failed");
|
---|
441 |
|
---|
442 | torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2,
|
---|
443 | "samr_EnumDomains returned unexpected num_entries");
|
---|
444 |
|
---|
445 | dom_idx = strequal(sam->entries[0].name.string,
|
---|
446 | "builtin") ? 1:0;
|
---|
447 |
|
---|
448 | l.in.connect_handle = &conn_handle;
|
---|
449 | domain_name.string = sam->entries[dom_idx].name.string;
|
---|
450 | *domain = talloc_strdup(mem_ctx, domain_name.string);
|
---|
451 | l.in.domain_name = &domain_name;
|
---|
452 | l.out.sid = &sid;
|
---|
453 |
|
---|
454 | torture_assert_ntstatus_ok(tctx,
|
---|
455 | dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l),
|
---|
456 | "samr_LookupDomain failed");
|
---|
457 | torture_assert_ntstatus_ok(tctx, l.out.result,
|
---|
458 | "samr_LookupDomain failed");
|
---|
459 |
|
---|
460 | o.in.connect_handle = &conn_handle;
|
---|
461 | o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
462 | o.in.sid = *l.out.sid;
|
---|
463 | o.out.domain_handle = &domain_handle;
|
---|
464 |
|
---|
465 | torture_assert_ntstatus_ok(tctx,
|
---|
466 | dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o),
|
---|
467 | "samr_OpenDomain failed");
|
---|
468 | torture_assert_ntstatus_ok(tctx, o.out.result,
|
---|
469 | "samr_OpenDomain failed");
|
---|
470 |
|
---|
471 | c.in.domain_handle = &domain_handle;
|
---|
472 | user_name.string = username;
|
---|
473 | c.in.account_name = &user_name;
|
---|
474 | c.in.acct_flags = ACB_NORMAL;
|
---|
475 | c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
476 | user_handle = talloc(mem_ctx, struct policy_handle);
|
---|
477 | c.out.user_handle = user_handle;
|
---|
478 | c.out.access_granted = &access_granted;
|
---|
479 | c.out.rid = &user_rid;
|
---|
480 |
|
---|
481 | torture_assert_ntstatus_ok(tctx,
|
---|
482 | dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c),
|
---|
483 | "samr_CreateUser2 failed");
|
---|
484 |
|
---|
485 | if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) {
|
---|
486 | struct samr_LookupNames ln;
|
---|
487 | struct samr_OpenUser ou;
|
---|
488 | struct samr_Ids rids, types;
|
---|
489 |
|
---|
490 | ln.in.domain_handle = &domain_handle;
|
---|
491 | ln.in.num_names = 1;
|
---|
492 | ln.in.names = &user_name;
|
---|
493 | ln.out.rids = &rids;
|
---|
494 | ln.out.types = &types;
|
---|
495 |
|
---|
496 | torture_assert_ntstatus_ok(tctx,
|
---|
497 | dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln),
|
---|
498 | "samr_LookupNames failed");
|
---|
499 | torture_assert_ntstatus_ok(tctx, ln.out.result,
|
---|
500 | "samr_LookupNames failed");
|
---|
501 |
|
---|
502 | ou.in.domain_handle = &domain_handle;
|
---|
503 | ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
504 | user_rid = ou.in.rid = ln.out.rids->ids[0];
|
---|
505 | ou.out.user_handle = user_handle;
|
---|
506 |
|
---|
507 | torture_assert_ntstatus_ok(tctx,
|
---|
508 | dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou),
|
---|
509 | "samr_OpenUser failed");
|
---|
510 | status = ou.out.result;
|
---|
511 | } else {
|
---|
512 | status = c.out.result;
|
---|
513 | }
|
---|
514 |
|
---|
515 | torture_assert_ntstatus_ok(tctx, status,
|
---|
516 | "samr_CreateUser failed");
|
---|
517 |
|
---|
518 | *result_pipe = samr_pipe;
|
---|
519 | *result_handle = user_handle;
|
---|
520 | if (sid_p != NULL) {
|
---|
521 | *sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
|
---|
522 | }
|
---|
523 | return true;
|
---|
524 |
|
---|
525 | }
|
---|
526 |
|
---|
527 | /*
|
---|
528 | * Create a test user
|
---|
529 | */
|
---|
530 |
|
---|
531 | static bool create_user(struct torture_context *tctx,
|
---|
532 | TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
|
---|
533 | struct cli_credentials *admin_creds,
|
---|
534 | const char *username, const char *password,
|
---|
535 | char **domain_name,
|
---|
536 | struct dom_sid **user_sid)
|
---|
537 | {
|
---|
538 | TALLOC_CTX *tmp_ctx;
|
---|
539 | NTSTATUS status;
|
---|
540 | struct dcerpc_pipe *samr_pipe;
|
---|
541 | struct dcerpc_binding_handle *samr_handle;
|
---|
542 | struct policy_handle *wks_handle;
|
---|
543 | bool ret = false;
|
---|
544 |
|
---|
545 | if (!(tmp_ctx = talloc_new(mem_ctx))) {
|
---|
546 | torture_comment(tctx, "talloc_init failed\n");
|
---|
547 | return false;
|
---|
548 | }
|
---|
549 |
|
---|
550 | ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds,
|
---|
551 | DCERPC_AUTH_TYPE_NTLMSSP,
|
---|
552 | DCERPC_AUTH_LEVEL_INTEGRITY,
|
---|
553 | username, domain_name, &samr_pipe, &wks_handle,
|
---|
554 | user_sid);
|
---|
555 | if (ret == false) {
|
---|
556 | torture_comment(tctx, "get_usr_handle failed\n");
|
---|
557 | goto done;
|
---|
558 | }
|
---|
559 | samr_handle = samr_pipe->binding_handle;
|
---|
560 |
|
---|
561 | {
|
---|
562 | struct samr_SetUserInfo2 sui2;
|
---|
563 | struct samr_SetUserInfo sui;
|
---|
564 | struct samr_QueryUserInfo qui;
|
---|
565 | union samr_UserInfo u_info;
|
---|
566 | union samr_UserInfo *info;
|
---|
567 | DATA_BLOB session_key;
|
---|
568 |
|
---|
569 |
|
---|
570 | ZERO_STRUCT(u_info);
|
---|
571 | encode_pw_buffer(u_info.info23.password.data, password,
|
---|
572 | STR_UNICODE);
|
---|
573 |
|
---|
574 | status = dcerpc_fetch_session_key(samr_pipe, &session_key);
|
---|
575 | if (!NT_STATUS_IS_OK(status)) {
|
---|
576 | torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
|
---|
577 | goto done;
|
---|
578 | }
|
---|
579 | arcfour_crypt_blob(u_info.info23.password.data, 516,
|
---|
580 | &session_key);
|
---|
581 | u_info.info23.info.password_expired = 0;
|
---|
582 | u_info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
|
---|
583 | SAMR_FIELD_LM_PASSWORD_PRESENT |
|
---|
584 | SAMR_FIELD_EXPIRED_FLAG;
|
---|
585 | sui2.in.user_handle = wks_handle;
|
---|
586 | sui2.in.info = &u_info;
|
---|
587 | sui2.in.level = 23;
|
---|
588 |
|
---|
589 | status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2);
|
---|
590 | if (!NT_STATUS_IS_OK(status)) {
|
---|
591 | torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
|
---|
592 | nt_errstr(status));
|
---|
593 | goto done;
|
---|
594 | }
|
---|
595 | if (!NT_STATUS_IS_OK(sui2.out.result)) {
|
---|
596 | torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
|
---|
597 | nt_errstr(sui2.out.result));
|
---|
598 | goto done;
|
---|
599 | }
|
---|
600 |
|
---|
601 | u_info.info16.acct_flags = ACB_NORMAL;
|
---|
602 | sui.in.user_handle = wks_handle;
|
---|
603 | sui.in.info = &u_info;
|
---|
604 | sui.in.level = 16;
|
---|
605 |
|
---|
606 | status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
|
---|
607 | if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
|
---|
608 | torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
|
---|
609 | goto done;
|
---|
610 | }
|
---|
611 |
|
---|
612 | qui.in.user_handle = wks_handle;
|
---|
613 | qui.in.level = 21;
|
---|
614 | qui.out.info = &info;
|
---|
615 |
|
---|
616 | status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui);
|
---|
617 | if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) {
|
---|
618 | torture_comment(tctx, "samr_QueryUserInfo(21) failed\n");
|
---|
619 | goto done;
|
---|
620 | }
|
---|
621 |
|
---|
622 | info->info21.allow_password_change = 0;
|
---|
623 | info->info21.force_password_change = 0;
|
---|
624 | info->info21.account_name.string = NULL;
|
---|
625 | info->info21.rid = 0;
|
---|
626 | info->info21.acct_expiry = 0;
|
---|
627 | info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
|
---|
628 |
|
---|
629 | u_info.info21 = info->info21;
|
---|
630 | sui.in.user_handle = wks_handle;
|
---|
631 | sui.in.info = &u_info;
|
---|
632 | sui.in.level = 21;
|
---|
633 |
|
---|
634 | status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
|
---|
635 | if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
|
---|
636 | torture_comment(tctx, "samr_SetUserInfo(21) failed\n");
|
---|
637 | goto done;
|
---|
638 | }
|
---|
639 | }
|
---|
640 |
|
---|
641 | *domain_name= talloc_steal(mem_ctx, *domain_name);
|
---|
642 | *user_sid = talloc_steal(mem_ctx, *user_sid);
|
---|
643 | ret = true;
|
---|
644 | done:
|
---|
645 | talloc_free(tmp_ctx);
|
---|
646 | return ret;
|
---|
647 | }
|
---|
648 |
|
---|
649 | /*
|
---|
650 | * Delete a test user
|
---|
651 | */
|
---|
652 |
|
---|
653 | static bool delete_user(struct torture_context *tctx,
|
---|
654 | struct smbcli_state *cli,
|
---|
655 | struct cli_credentials *admin_creds,
|
---|
656 | const char *username)
|
---|
657 | {
|
---|
658 | TALLOC_CTX *mem_ctx;
|
---|
659 | NTSTATUS status;
|
---|
660 | char *dom_name;
|
---|
661 | struct dcerpc_pipe *samr_pipe;
|
---|
662 | struct dcerpc_binding_handle *samr_handle;
|
---|
663 | struct policy_handle *user_handle;
|
---|
664 | bool ret = false;
|
---|
665 |
|
---|
666 | if ((mem_ctx = talloc_init("leave")) == NULL) {
|
---|
667 | torture_comment(tctx, "talloc_init failed\n");
|
---|
668 | return false;
|
---|
669 | }
|
---|
670 |
|
---|
671 | ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds,
|
---|
672 | DCERPC_AUTH_TYPE_NTLMSSP,
|
---|
673 | DCERPC_AUTH_LEVEL_INTEGRITY,
|
---|
674 | username, &dom_name, &samr_pipe,
|
---|
675 | &user_handle, NULL);
|
---|
676 | if (ret == false) {
|
---|
677 | torture_comment(tctx, "get_wks_handle failed\n");
|
---|
678 | goto done;
|
---|
679 | }
|
---|
680 | samr_handle = samr_pipe->binding_handle;
|
---|
681 |
|
---|
682 | {
|
---|
683 | struct samr_DeleteUser d;
|
---|
684 |
|
---|
685 | d.in.user_handle = user_handle;
|
---|
686 | d.out.user_handle = user_handle;
|
---|
687 |
|
---|
688 | status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d);
|
---|
689 | if (!NT_STATUS_IS_OK(status)) {
|
---|
690 | torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status));
|
---|
691 | goto done;
|
---|
692 | }
|
---|
693 | if (!NT_STATUS_IS_OK(d.out.result)) {
|
---|
694 | torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result));
|
---|
695 | goto done;
|
---|
696 | }
|
---|
697 |
|
---|
698 | }
|
---|
699 |
|
---|
700 | ret = true;
|
---|
701 |
|
---|
702 | done:
|
---|
703 | talloc_free(mem_ctx);
|
---|
704 | return ret;
|
---|
705 | }
|
---|
706 |
|
---|
707 | /*
|
---|
708 | * Do a Samba3-style join
|
---|
709 | */
|
---|
710 |
|
---|
711 | static bool join3(struct torture_context *tctx,
|
---|
712 | struct smbcli_state *cli,
|
---|
713 | bool use_level25,
|
---|
714 | struct cli_credentials *admin_creds,
|
---|
715 | struct cli_credentials *wks_creds)
|
---|
716 | {
|
---|
717 | TALLOC_CTX *mem_ctx;
|
---|
718 | NTSTATUS status;
|
---|
719 | char *dom_name;
|
---|
720 | struct dcerpc_pipe *samr_pipe;
|
---|
721 | struct dcerpc_binding_handle *samr_handle;
|
---|
722 | struct policy_handle *wks_handle;
|
---|
723 | bool ret = false;
|
---|
724 | NTTIME last_password_change;
|
---|
725 |
|
---|
726 | if ((mem_ctx = talloc_init("join3")) == NULL) {
|
---|
727 | torture_comment(tctx, "talloc_init failed\n");
|
---|
728 | return false;
|
---|
729 | }
|
---|
730 |
|
---|
731 | ret = get_usr_handle(
|
---|
732 | tctx, cli, mem_ctx, admin_creds,
|
---|
733 | DCERPC_AUTH_TYPE_NTLMSSP,
|
---|
734 | DCERPC_AUTH_LEVEL_PRIVACY,
|
---|
735 | talloc_asprintf(mem_ctx, "%s$",
|
---|
736 | cli_credentials_get_workstation(wks_creds)),
|
---|
737 | &dom_name, &samr_pipe, &wks_handle, NULL);
|
---|
738 | if (ret == false) {
|
---|
739 | torture_comment(tctx, "get_wks_handle failed\n");
|
---|
740 | goto done;
|
---|
741 | }
|
---|
742 | samr_handle = samr_pipe->binding_handle;
|
---|
743 |
|
---|
744 | {
|
---|
745 | struct samr_QueryUserInfo q;
|
---|
746 | union samr_UserInfo *info;
|
---|
747 |
|
---|
748 | q.in.user_handle = wks_handle;
|
---|
749 | q.in.level = 21;
|
---|
750 | q.out.info = &info;
|
---|
751 |
|
---|
752 | status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
|
---|
753 | if (!NT_STATUS_IS_OK(status)) {
|
---|
754 | torture_warning(tctx, "QueryUserInfo failed: %s\n",
|
---|
755 | nt_errstr(status));
|
---|
756 | goto done;
|
---|
757 | }
|
---|
758 | if (!NT_STATUS_IS_OK(q.out.result)) {
|
---|
759 | torture_warning(tctx, "QueryUserInfo failed: %s\n",
|
---|
760 | nt_errstr(q.out.result));
|
---|
761 | goto done;
|
---|
762 | }
|
---|
763 |
|
---|
764 |
|
---|
765 | last_password_change = info->info21.last_password_change;
|
---|
766 | }
|
---|
767 |
|
---|
768 | cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
|
---|
769 |
|
---|
770 | if (use_level25) {
|
---|
771 | struct samr_SetUserInfo2 sui2;
|
---|
772 | union samr_UserInfo u_info;
|
---|
773 | struct samr_UserInfo21 *i21 = &u_info.info25.info;
|
---|
774 | DATA_BLOB session_key;
|
---|
775 | DATA_BLOB confounded_session_key = data_blob_talloc(
|
---|
776 | mem_ctx, NULL, 16);
|
---|
777 | MD5_CTX ctx;
|
---|
778 | uint8_t confounder[16];
|
---|
779 |
|
---|
780 | ZERO_STRUCT(u_info);
|
---|
781 |
|
---|
782 | i21->full_name.string = talloc_asprintf(
|
---|
783 | mem_ctx, "%s$",
|
---|
784 | cli_credentials_get_workstation(wks_creds));
|
---|
785 | i21->acct_flags = ACB_WSTRUST;
|
---|
786 | i21->fields_present = SAMR_FIELD_FULL_NAME |
|
---|
787 | SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_NT_PASSWORD_PRESENT;
|
---|
788 | /* this would break the test result expectations
|
---|
789 | i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
|
---|
790 | i21->password_expired = 1;
|
---|
791 | */
|
---|
792 |
|
---|
793 | encode_pw_buffer(u_info.info25.password.data,
|
---|
794 | cli_credentials_get_password(wks_creds),
|
---|
795 | STR_UNICODE);
|
---|
796 | status = dcerpc_fetch_session_key(samr_pipe, &session_key);
|
---|
797 | if (!NT_STATUS_IS_OK(status)) {
|
---|
798 | torture_comment(tctx, "dcerpc_fetch_session_key failed: %s\n",
|
---|
799 | nt_errstr(status));
|
---|
800 | goto done;
|
---|
801 | }
|
---|
802 | generate_random_buffer((uint8_t *)confounder, 16);
|
---|
803 |
|
---|
804 | MD5Init(&ctx);
|
---|
805 | MD5Update(&ctx, confounder, 16);
|
---|
806 | MD5Update(&ctx, session_key.data, session_key.length);
|
---|
807 | MD5Final(confounded_session_key.data, &ctx);
|
---|
808 |
|
---|
809 | arcfour_crypt_blob(u_info.info25.password.data, 516,
|
---|
810 | &confounded_session_key);
|
---|
811 | memcpy(&u_info.info25.password.data[516], confounder, 16);
|
---|
812 |
|
---|
813 | sui2.in.user_handle = wks_handle;
|
---|
814 | sui2.in.level = 25;
|
---|
815 | sui2.in.info = &u_info;
|
---|
816 |
|
---|
817 | status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
|
---|
818 | if (!NT_STATUS_IS_OK(status)) {
|
---|
819 | torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
|
---|
820 | nt_errstr(status));
|
---|
821 | goto done;
|
---|
822 | }
|
---|
823 | if (!NT_STATUS_IS_OK(sui2.out.result)) {
|
---|
824 | torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
|
---|
825 | nt_errstr(sui2.out.result));
|
---|
826 | goto done;
|
---|
827 | }
|
---|
828 | } else {
|
---|
829 | struct samr_SetUserInfo2 sui2;
|
---|
830 | struct samr_SetUserInfo sui;
|
---|
831 | union samr_UserInfo u_info;
|
---|
832 | DATA_BLOB session_key;
|
---|
833 |
|
---|
834 | encode_pw_buffer(u_info.info24.password.data,
|
---|
835 | cli_credentials_get_password(wks_creds),
|
---|
836 | STR_UNICODE);
|
---|
837 | /* just to make this test pass */
|
---|
838 | u_info.info24.password_expired = 1;
|
---|
839 |
|
---|
840 | status = dcerpc_fetch_session_key(samr_pipe, &session_key);
|
---|
841 | if (!NT_STATUS_IS_OK(status)) {
|
---|
842 | torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
|
---|
843 | goto done;
|
---|
844 | }
|
---|
845 | arcfour_crypt_blob(u_info.info24.password.data, 516,
|
---|
846 | &session_key);
|
---|
847 | sui2.in.user_handle = wks_handle;
|
---|
848 | sui2.in.info = &u_info;
|
---|
849 | sui2.in.level = 24;
|
---|
850 |
|
---|
851 | status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
|
---|
852 | if (!NT_STATUS_IS_OK(status)) {
|
---|
853 | torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
|
---|
854 | nt_errstr(status));
|
---|
855 | goto done;
|
---|
856 | }
|
---|
857 | if (!NT_STATUS_IS_OK(sui2.out.result)) {
|
---|
858 | torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
|
---|
859 | nt_errstr(sui2.out.result));
|
---|
860 | goto done;
|
---|
861 | }
|
---|
862 |
|
---|
863 | u_info.info16.acct_flags = ACB_WSTRUST;
|
---|
864 | sui.in.user_handle = wks_handle;
|
---|
865 | sui.in.info = &u_info;
|
---|
866 | sui.in.level = 16;
|
---|
867 |
|
---|
868 | status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui);
|
---|
869 | if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
|
---|
870 | torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
|
---|
871 | goto done;
|
---|
872 | }
|
---|
873 | }
|
---|
874 |
|
---|
875 | {
|
---|
876 | struct samr_QueryUserInfo q;
|
---|
877 | union samr_UserInfo *info;
|
---|
878 |
|
---|
879 | q.in.user_handle = wks_handle;
|
---|
880 | q.in.level = 21;
|
---|
881 | q.out.info = &info;
|
---|
882 |
|
---|
883 | status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
|
---|
884 | if (!NT_STATUS_IS_OK(status)) {
|
---|
885 | torture_warning(tctx, "QueryUserInfo failed: %s\n",
|
---|
886 | nt_errstr(status));
|
---|
887 | goto done;
|
---|
888 | }
|
---|
889 | if (!NT_STATUS_IS_OK(q.out.result)) {
|
---|
890 | torture_warning(tctx, "QueryUserInfo failed: %s\n",
|
---|
891 | nt_errstr(q.out.result));
|
---|
892 | goto done;
|
---|
893 | }
|
---|
894 |
|
---|
895 | if (use_level25) {
|
---|
896 | if (last_password_change
|
---|
897 | == info->info21.last_password_change) {
|
---|
898 | torture_warning(tctx, "last_password_change unchanged "
|
---|
899 | "during join, level25 must change "
|
---|
900 | "it\n");
|
---|
901 | goto done;
|
---|
902 | }
|
---|
903 | }
|
---|
904 | else {
|
---|
905 | if (last_password_change
|
---|
906 | != info->info21.last_password_change) {
|
---|
907 | torture_warning(tctx, "last_password_change changed "
|
---|
908 | "during join, level24 doesn't "
|
---|
909 | "change it\n");
|
---|
910 | goto done;
|
---|
911 | }
|
---|
912 | }
|
---|
913 | }
|
---|
914 |
|
---|
915 | ret = true;
|
---|
916 |
|
---|
917 | done:
|
---|
918 | talloc_free(mem_ctx);
|
---|
919 | return ret;
|
---|
920 | }
|
---|
921 |
|
---|
922 | /*
|
---|
923 | * Do a ReqChallenge/Auth2 and get the wks creds
|
---|
924 | */
|
---|
925 |
|
---|
926 | static bool auth2(struct torture_context *tctx,
|
---|
927 | struct smbcli_state *cli,
|
---|
928 | struct cli_credentials *wks_cred)
|
---|
929 | {
|
---|
930 | TALLOC_CTX *mem_ctx;
|
---|
931 | struct dcerpc_pipe *net_pipe;
|
---|
932 | struct dcerpc_binding_handle *net_handle;
|
---|
933 | bool result = false;
|
---|
934 | NTSTATUS status;
|
---|
935 | struct netr_ServerReqChallenge r;
|
---|
936 | struct netr_Credential netr_cli_creds;
|
---|
937 | struct netr_Credential netr_srv_creds;
|
---|
938 | uint32_t negotiate_flags;
|
---|
939 | struct netr_ServerAuthenticate2 a;
|
---|
940 | struct netlogon_creds_CredentialState *creds_state;
|
---|
941 | struct netr_Credential netr_cred;
|
---|
942 | struct samr_Password mach_pw;
|
---|
943 |
|
---|
944 | mem_ctx = talloc_new(NULL);
|
---|
945 | if (mem_ctx == NULL) {
|
---|
946 | torture_comment(tctx, "talloc_new failed\n");
|
---|
947 | return false;
|
---|
948 | }
|
---|
949 |
|
---|
950 | net_pipe = dcerpc_pipe_init(mem_ctx,
|
---|
951 | cli->transport->socket->event.ctx);
|
---|
952 | if (net_pipe == NULL) {
|
---|
953 | torture_comment(tctx, "dcerpc_pipe_init failed\n");
|
---|
954 | goto done;
|
---|
955 | }
|
---|
956 | net_handle = net_pipe->binding_handle;
|
---|
957 |
|
---|
958 | status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
|
---|
959 | if (!NT_STATUS_IS_OK(status)) {
|
---|
960 | torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
|
---|
961 | nt_errstr(status));
|
---|
962 | goto done;
|
---|
963 | }
|
---|
964 |
|
---|
965 | status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
|
---|
966 | if (!NT_STATUS_IS_OK(status)) {
|
---|
967 | torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n",
|
---|
968 | nt_errstr(status));
|
---|
969 | goto done;
|
---|
970 | }
|
---|
971 |
|
---|
972 | r.in.computer_name = cli_credentials_get_workstation(wks_cred);
|
---|
973 | r.in.server_name = talloc_asprintf(
|
---|
974 | mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
|
---|
975 | if (r.in.server_name == NULL) {
|
---|
976 | torture_comment(tctx, "talloc_asprintf failed\n");
|
---|
977 | goto done;
|
---|
978 | }
|
---|
979 | generate_random_buffer(netr_cli_creds.data,
|
---|
980 | sizeof(netr_cli_creds.data));
|
---|
981 | r.in.credentials = &netr_cli_creds;
|
---|
982 | r.out.return_credentials = &netr_srv_creds;
|
---|
983 |
|
---|
984 | status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
|
---|
985 | if (!NT_STATUS_IS_OK(status)) {
|
---|
986 | torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
|
---|
987 | nt_errstr(status));
|
---|
988 | goto done;
|
---|
989 | }
|
---|
990 | if (!NT_STATUS_IS_OK(r.out.result)) {
|
---|
991 | torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
|
---|
992 | nt_errstr(r.out.result));
|
---|
993 | goto done;
|
---|
994 | }
|
---|
995 |
|
---|
996 | negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
|
---|
997 | E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
|
---|
998 |
|
---|
999 | a.in.server_name = talloc_asprintf(
|
---|
1000 | mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
|
---|
1001 | a.in.account_name = talloc_asprintf(
|
---|
1002 | mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
|
---|
1003 | a.in.computer_name = cli_credentials_get_workstation(wks_cred);
|
---|
1004 | a.in.secure_channel_type = SEC_CHAN_WKSTA;
|
---|
1005 | a.in.negotiate_flags = &negotiate_flags;
|
---|
1006 | a.out.negotiate_flags = &negotiate_flags;
|
---|
1007 | a.in.credentials = &netr_cred;
|
---|
1008 | a.out.return_credentials = &netr_cred;
|
---|
1009 |
|
---|
1010 | creds_state = netlogon_creds_client_init(mem_ctx,
|
---|
1011 | a.in.account_name,
|
---|
1012 | a.in.computer_name,
|
---|
1013 | r.in.credentials,
|
---|
1014 | r.out.return_credentials, &mach_pw,
|
---|
1015 | &netr_cred, negotiate_flags);
|
---|
1016 |
|
---|
1017 | status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
|
---|
1018 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1019 | torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
|
---|
1020 | nt_errstr(status));
|
---|
1021 | goto done;
|
---|
1022 | }
|
---|
1023 | if (!NT_STATUS_IS_OK(a.out.result)) {
|
---|
1024 | torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
|
---|
1025 | nt_errstr(a.out.result));
|
---|
1026 | goto done;
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
|
---|
1030 | torture_comment(tctx, "creds_client_check failed\n");
|
---|
1031 | goto done;
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | cli_credentials_set_netlogon_creds(wks_cred, creds_state);
|
---|
1035 |
|
---|
1036 | result = true;
|
---|
1037 |
|
---|
1038 | done:
|
---|
1039 | talloc_free(mem_ctx);
|
---|
1040 | return result;
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | /*
|
---|
1044 | * Do a couple of schannel protected Netlogon ops: Interactive and Network
|
---|
1045 | * login, and change the wks password
|
---|
1046 | */
|
---|
1047 |
|
---|
1048 | static bool schan(struct torture_context *tctx,
|
---|
1049 | struct smbcli_state *cli,
|
---|
1050 | struct cli_credentials *wks_creds,
|
---|
1051 | struct cli_credentials *user_creds)
|
---|
1052 | {
|
---|
1053 | TALLOC_CTX *mem_ctx;
|
---|
1054 | NTSTATUS status;
|
---|
1055 | bool ret = false;
|
---|
1056 | struct dcerpc_pipe *net_pipe;
|
---|
1057 | struct dcerpc_binding_handle *net_handle;
|
---|
1058 | int i;
|
---|
1059 |
|
---|
1060 | mem_ctx = talloc_new(NULL);
|
---|
1061 | if (mem_ctx == NULL) {
|
---|
1062 | torture_comment(tctx, "talloc_new failed\n");
|
---|
1063 | return false;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | net_pipe = dcerpc_pipe_init(mem_ctx,
|
---|
1067 | cli->transport->socket->event.ctx);
|
---|
1068 | if (net_pipe == NULL) {
|
---|
1069 | torture_comment(tctx, "dcerpc_pipe_init failed\n");
|
---|
1070 | goto done;
|
---|
1071 | }
|
---|
1072 | net_handle = net_pipe->binding_handle;
|
---|
1073 |
|
---|
1074 | status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
|
---|
1075 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1076 | torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
|
---|
1077 | nt_errstr(status));
|
---|
1078 | goto done;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | #if 0
|
---|
1082 | net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
|
---|
1083 | DCERPC_DEBUG_PRINT_OUT;
|
---|
1084 | #endif
|
---|
1085 | #if 1
|
---|
1086 | net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
|
---|
1087 | status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
|
---|
1088 | wks_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
|
---|
1089 | DCERPC_AUTH_LEVEL_PRIVACY,
|
---|
1090 | NULL);
|
---|
1091 | #else
|
---|
1092 | status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
|
---|
1093 | #endif
|
---|
1094 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1095 | torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
|
---|
1096 | goto done;
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 |
|
---|
1100 | for (i=2; i<4; i++) {
|
---|
1101 | int flags;
|
---|
1102 | DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
|
---|
1103 | struct netlogon_creds_CredentialState *creds_state;
|
---|
1104 | struct netr_Authenticator netr_auth, netr_auth2;
|
---|
1105 | struct netr_NetworkInfo ninfo;
|
---|
1106 | struct netr_PasswordInfo pinfo;
|
---|
1107 | struct netr_LogonSamLogon r;
|
---|
1108 | union netr_LogonLevel logon;
|
---|
1109 | union netr_Validation validation;
|
---|
1110 | uint8_t authoritative;
|
---|
1111 | struct netr_Authenticator return_authenticator;
|
---|
1112 |
|
---|
1113 | flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
|
---|
1114 | CLI_CRED_NTLMv2_AUTH;
|
---|
1115 |
|
---|
1116 | chal = data_blob_talloc(mem_ctx, NULL, 8);
|
---|
1117 | if (chal.data == NULL) {
|
---|
1118 | torture_comment(tctx, "data_blob_talloc failed\n");
|
---|
1119 | goto done;
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | generate_random_buffer(chal.data, chal.length);
|
---|
1123 | names_blob = NTLMv2_generate_names_blob(
|
---|
1124 | mem_ctx,
|
---|
1125 | cli_credentials_get_workstation(wks_creds),
|
---|
1126 | cli_credentials_get_domain(wks_creds));
|
---|
1127 | status = cli_credentials_get_ntlm_response(
|
---|
1128 | user_creds, mem_ctx, &flags, chal, names_blob,
|
---|
1129 | &lm_resp, &nt_resp, NULL, NULL);
|
---|
1130 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1131 | torture_comment(tctx, "cli_credentials_get_ntlm_response failed:"
|
---|
1132 | " %s\n", nt_errstr(status));
|
---|
1133 | goto done;
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | creds_state = cli_credentials_get_netlogon_creds(wks_creds);
|
---|
1137 | netlogon_creds_client_authenticator(creds_state, &netr_auth);
|
---|
1138 |
|
---|
1139 | ninfo.identity_info.account_name.string =
|
---|
1140 | cli_credentials_get_username(user_creds);
|
---|
1141 | ninfo.identity_info.domain_name.string =
|
---|
1142 | cli_credentials_get_domain(user_creds);
|
---|
1143 | ninfo.identity_info.parameter_control = 0;
|
---|
1144 | ninfo.identity_info.logon_id_low = 0;
|
---|
1145 | ninfo.identity_info.logon_id_high = 0;
|
---|
1146 | ninfo.identity_info.workstation.string =
|
---|
1147 | cli_credentials_get_workstation(user_creds);
|
---|
1148 | memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
|
---|
1149 | ninfo.nt.length = nt_resp.length;
|
---|
1150 | ninfo.nt.data = nt_resp.data;
|
---|
1151 | ninfo.lm.length = lm_resp.length;
|
---|
1152 | ninfo.lm.data = lm_resp.data;
|
---|
1153 |
|
---|
1154 | logon.network = &ninfo;
|
---|
1155 |
|
---|
1156 | r.in.server_name = talloc_asprintf(
|
---|
1157 | mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
|
---|
1158 | ZERO_STRUCT(netr_auth2);
|
---|
1159 | r.in.computer_name =
|
---|
1160 | cli_credentials_get_workstation(wks_creds);
|
---|
1161 | r.in.credential = &netr_auth;
|
---|
1162 | r.in.return_authenticator = &netr_auth2;
|
---|
1163 | r.in.logon_level = 2;
|
---|
1164 | r.in.validation_level = i;
|
---|
1165 | r.in.logon = &logon;
|
---|
1166 | r.out.validation = &validation;
|
---|
1167 | r.out.authoritative = &authoritative;
|
---|
1168 | r.out.return_authenticator = &return_authenticator;
|
---|
1169 |
|
---|
1170 | status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
|
---|
1171 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1172 | torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
|
---|
1173 | nt_errstr(status));
|
---|
1174 | goto done;
|
---|
1175 | }
|
---|
1176 | if (!NT_STATUS_IS_OK(r.out.result)) {
|
---|
1177 | torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
|
---|
1178 | nt_errstr(r.out.result));
|
---|
1179 | goto done;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | if ((r.out.return_authenticator == NULL) ||
|
---|
1183 | (!netlogon_creds_client_check(creds_state,
|
---|
1184 | &r.out.return_authenticator->cred))) {
|
---|
1185 | torture_comment(tctx, "Credentials check failed!\n");
|
---|
1186 | goto done;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | netlogon_creds_client_authenticator(creds_state, &netr_auth);
|
---|
1190 |
|
---|
1191 | pinfo.identity_info = ninfo.identity_info;
|
---|
1192 | ZERO_STRUCT(pinfo.lmpassword.hash);
|
---|
1193 | E_md4hash(cli_credentials_get_password(user_creds),
|
---|
1194 | pinfo.ntpassword.hash);
|
---|
1195 | session_key = data_blob_talloc(mem_ctx,
|
---|
1196 | creds_state->session_key, 16);
|
---|
1197 | arcfour_crypt_blob(pinfo.ntpassword.hash,
|
---|
1198 | sizeof(pinfo.ntpassword.hash),
|
---|
1199 | &session_key);
|
---|
1200 |
|
---|
1201 | logon.password = &pinfo;
|
---|
1202 |
|
---|
1203 | r.in.logon_level = 1;
|
---|
1204 | r.in.logon = &logon;
|
---|
1205 | r.out.return_authenticator = &return_authenticator;
|
---|
1206 |
|
---|
1207 | status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
|
---|
1208 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1209 | torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
|
---|
1210 | nt_errstr(status));
|
---|
1211 | goto done;
|
---|
1212 | }
|
---|
1213 | if (!NT_STATUS_IS_OK(r.out.result)) {
|
---|
1214 | torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
|
---|
1215 | nt_errstr(r.out.result));
|
---|
1216 | goto done;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | if ((r.out.return_authenticator == NULL) ||
|
---|
1220 | (!netlogon_creds_client_check(creds_state,
|
---|
1221 | &r.out.return_authenticator->cred))) {
|
---|
1222 | torture_comment(tctx, "Credentials check failed!\n");
|
---|
1223 | goto done;
|
---|
1224 | }
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | {
|
---|
1228 | struct netr_ServerPasswordSet s;
|
---|
1229 | char *password = generate_random_password(wks_creds, 8, 255);
|
---|
1230 | struct netlogon_creds_CredentialState *creds_state;
|
---|
1231 | struct netr_Authenticator credential, return_authenticator;
|
---|
1232 | struct samr_Password new_password;
|
---|
1233 |
|
---|
1234 | s.in.server_name = talloc_asprintf(
|
---|
1235 | mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
|
---|
1236 | s.in.computer_name = cli_credentials_get_workstation(wks_creds);
|
---|
1237 | s.in.account_name = talloc_asprintf(
|
---|
1238 | mem_ctx, "%s$", s.in.computer_name);
|
---|
1239 | s.in.secure_channel_type = SEC_CHAN_WKSTA;
|
---|
1240 | s.in.credential = &credential;
|
---|
1241 | s.in.new_password = &new_password;
|
---|
1242 | s.out.return_authenticator = &return_authenticator;
|
---|
1243 |
|
---|
1244 | E_md4hash(password, new_password.hash);
|
---|
1245 |
|
---|
1246 | creds_state = cli_credentials_get_netlogon_creds(wks_creds);
|
---|
1247 | netlogon_creds_des_encrypt(creds_state, &new_password);
|
---|
1248 | netlogon_creds_client_authenticator(creds_state, &credential);
|
---|
1249 |
|
---|
1250 | status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s);
|
---|
1251 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1252 | torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status));
|
---|
1253 | goto done;
|
---|
1254 | }
|
---|
1255 | if (!NT_STATUS_IS_OK(s.out.result)) {
|
---|
1256 | torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result));
|
---|
1257 | goto done;
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | if (!netlogon_creds_client_check(creds_state,
|
---|
1261 | &s.out.return_authenticator->cred)) {
|
---|
1262 | torture_comment(tctx, "Credential chaining failed\n");
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | cli_credentials_set_password(wks_creds, password,
|
---|
1266 | CRED_SPECIFIED);
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | ret = true;
|
---|
1270 | done:
|
---|
1271 | talloc_free(mem_ctx);
|
---|
1272 | return ret;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | /*
|
---|
1276 | * Delete the wks account again
|
---|
1277 | */
|
---|
1278 |
|
---|
1279 | static bool leave(struct torture_context *tctx,
|
---|
1280 | struct smbcli_state *cli,
|
---|
1281 | struct cli_credentials *admin_creds,
|
---|
1282 | struct cli_credentials *wks_creds)
|
---|
1283 | {
|
---|
1284 | char *wks_name = talloc_asprintf(
|
---|
1285 | NULL, "%s$", cli_credentials_get_workstation(wks_creds));
|
---|
1286 | bool ret;
|
---|
1287 |
|
---|
1288 | ret = delete_user(tctx, cli, admin_creds, wks_name);
|
---|
1289 | talloc_free(wks_name);
|
---|
1290 | return ret;
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | /*
|
---|
1294 | * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
|
---|
1295 | */
|
---|
1296 |
|
---|
1297 | static bool torture_netlogon_samba3(struct torture_context *torture)
|
---|
1298 | {
|
---|
1299 | NTSTATUS status;
|
---|
1300 | struct smbcli_state *cli;
|
---|
1301 | struct cli_credentials *anon_creds;
|
---|
1302 | struct cli_credentials *wks_creds;
|
---|
1303 | const char *wks_name;
|
---|
1304 | int i;
|
---|
1305 | struct smbcli_options options;
|
---|
1306 | struct smbcli_session_options session_options;
|
---|
1307 |
|
---|
1308 | wks_name = torture_setting_string(torture, "wksname", NULL);
|
---|
1309 | if (wks_name == NULL) {
|
---|
1310 | wks_name = get_myname(torture);
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | if (!(anon_creds = cli_credentials_init_anon(torture))) {
|
---|
1314 | torture_fail(torture, "create_anon_creds failed\n");
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | lpcfg_smbcli_options(torture->lp_ctx, &options);
|
---|
1318 | lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
|
---|
1319 |
|
---|
1320 | status = smbcli_full_connection(torture, &cli,
|
---|
1321 | torture_setting_string(torture, "host", NULL),
|
---|
1322 | lpcfg_smb_ports(torture->lp_ctx),
|
---|
1323 | "IPC$", NULL,
|
---|
1324 | lpcfg_socket_options(torture->lp_ctx),
|
---|
1325 | anon_creds,
|
---|
1326 | lpcfg_resolve_context(torture->lp_ctx),
|
---|
1327 | torture->ev, &options, &session_options,
|
---|
1328 | lpcfg_gensec_settings(torture, torture->lp_ctx));
|
---|
1329 | torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
|
---|
1330 |
|
---|
1331 | wks_creds = cli_credentials_init(torture);
|
---|
1332 | if (wks_creds == NULL) {
|
---|
1333 | torture_fail(torture, "cli_credentials_init failed\n");
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | cli_credentials_set_conf(wks_creds, torture->lp_ctx);
|
---|
1337 | cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
|
---|
1338 | cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
|
---|
1339 | cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
|
---|
1340 | cli_credentials_set_password(wks_creds,
|
---|
1341 | generate_random_password(wks_creds, 8, 255),
|
---|
1342 | CRED_SPECIFIED);
|
---|
1343 |
|
---|
1344 | torture_assert(torture,
|
---|
1345 | join3(torture, cli, false, cmdline_credentials, wks_creds),
|
---|
1346 | "join failed");
|
---|
1347 |
|
---|
1348 | cli_credentials_set_domain(
|
---|
1349 | cmdline_credentials, cli_credentials_get_domain(wks_creds),
|
---|
1350 | CRED_SPECIFIED);
|
---|
1351 |
|
---|
1352 | for (i=0; i<2; i++) {
|
---|
1353 |
|
---|
1354 | /* Do this more than once, the routine "schan" changes
|
---|
1355 | * the workstation password using the netlogon
|
---|
1356 | * password change routine */
|
---|
1357 |
|
---|
1358 | int j;
|
---|
1359 |
|
---|
1360 | torture_assert(torture,
|
---|
1361 | auth2(torture, cli, wks_creds),
|
---|
1362 | "auth2 failed");
|
---|
1363 |
|
---|
1364 | for (j=0; j<2; j++) {
|
---|
1365 | torture_assert(torture,
|
---|
1366 | schan(torture, cli, wks_creds, cmdline_credentials),
|
---|
1367 | "schan failed");
|
---|
1368 | }
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | torture_assert(torture,
|
---|
1372 | leave(torture, cli, cmdline_credentials, wks_creds),
|
---|
1373 | "leave failed");
|
---|
1374 |
|
---|
1375 | return true;
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 | /*
|
---|
1379 | * Do a simple join, testjoin and leave using specified smb and samr
|
---|
1380 | * credentials
|
---|
1381 | */
|
---|
1382 |
|
---|
1383 | static bool test_join3(struct torture_context *tctx,
|
---|
1384 | bool use_level25,
|
---|
1385 | struct cli_credentials *smb_creds,
|
---|
1386 | struct cli_credentials *samr_creds,
|
---|
1387 | const char *wks_name)
|
---|
1388 | {
|
---|
1389 | NTSTATUS status;
|
---|
1390 | struct smbcli_state *cli;
|
---|
1391 | struct cli_credentials *wks_creds;
|
---|
1392 | struct smbcli_options options;
|
---|
1393 | struct smbcli_session_options session_options;
|
---|
1394 |
|
---|
1395 | lpcfg_smbcli_options(tctx->lp_ctx, &options);
|
---|
1396 | lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
|
---|
1397 |
|
---|
1398 | status = smbcli_full_connection(tctx, &cli,
|
---|
1399 | torture_setting_string(tctx, "host", NULL),
|
---|
1400 | lpcfg_smb_ports(tctx->lp_ctx),
|
---|
1401 | "IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
|
---|
1402 | smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
|
---|
1403 | tctx->ev, &options, &session_options,
|
---|
1404 | lpcfg_gensec_settings(tctx, tctx->lp_ctx));
|
---|
1405 | torture_assert_ntstatus_ok(tctx, status,
|
---|
1406 | "smbcli_full_connection failed");
|
---|
1407 |
|
---|
1408 | wks_creds = cli_credentials_init(cli);
|
---|
1409 | torture_assert(tctx, wks_creds, "cli_credentials_init failed");
|
---|
1410 |
|
---|
1411 | cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
|
---|
1412 | cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
|
---|
1413 | cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
|
---|
1414 | cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
|
---|
1415 | cli_credentials_set_password(wks_creds,
|
---|
1416 | generate_random_password(wks_creds, 8, 255),
|
---|
1417 | CRED_SPECIFIED);
|
---|
1418 |
|
---|
1419 | torture_assert(tctx,
|
---|
1420 | join3(tctx, cli, use_level25, samr_creds, wks_creds),
|
---|
1421 | "join failed");
|
---|
1422 |
|
---|
1423 | cli_credentials_set_domain(
|
---|
1424 | cmdline_credentials, cli_credentials_get_domain(wks_creds),
|
---|
1425 | CRED_SPECIFIED);
|
---|
1426 |
|
---|
1427 | torture_assert(tctx,
|
---|
1428 | auth2(tctx, cli, wks_creds),
|
---|
1429 | "auth2 failed");
|
---|
1430 |
|
---|
1431 | torture_assert(tctx,
|
---|
1432 | leave(tctx, cli, samr_creds, wks_creds),
|
---|
1433 | "leave failed");
|
---|
1434 |
|
---|
1435 | talloc_free(cli);
|
---|
1436 |
|
---|
1437 | return true;
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | /*
|
---|
1441 | * Test the different session key variants. Do it by joining, this uses the
|
---|
1442 | * session key in the setpassword routine. Test the join by doing the auth2.
|
---|
1443 | */
|
---|
1444 |
|
---|
1445 | static bool torture_samba3_sessionkey(struct torture_context *torture)
|
---|
1446 | {
|
---|
1447 | struct cli_credentials *anon_creds;
|
---|
1448 | const char *wks_name;
|
---|
1449 |
|
---|
1450 | wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
|
---|
1451 |
|
---|
1452 | if (!(anon_creds = cli_credentials_init_anon(torture))) {
|
---|
1453 | torture_fail(torture, "create_anon_creds failed\n");
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
|
---|
1457 |
|
---|
1458 |
|
---|
1459 | if (!torture_setting_bool(torture, "samba3", false)) {
|
---|
1460 |
|
---|
1461 | /* Samba3 in the build farm right now does this happily. Need
|
---|
1462 | * to fix :-) */
|
---|
1463 |
|
---|
1464 | if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
|
---|
1465 | torture_fail(torture, "join using anonymous bind on an anonymous smb "
|
---|
1466 | "connection succeeded -- HUH??\n");
|
---|
1467 | }
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 | torture_assert(torture,
|
---|
1471 | test_join3(torture, false, anon_creds, cmdline_credentials, wks_name),
|
---|
1472 | "join using ntlmssp bind on an anonymous smb connection failed");
|
---|
1473 |
|
---|
1474 | torture_assert(torture,
|
---|
1475 | test_join3(torture, false, cmdline_credentials, NULL, wks_name),
|
---|
1476 | "join using anonymous bind on an authenticated smb connection failed");
|
---|
1477 |
|
---|
1478 | torture_assert(torture,
|
---|
1479 | test_join3(torture, false, cmdline_credentials, cmdline_credentials, wks_name),
|
---|
1480 | "join using ntlmssp bind on an authenticated smb connection failed");
|
---|
1481 |
|
---|
1482 | /*
|
---|
1483 | * The following two are tests for setuserinfolevel 25
|
---|
1484 | */
|
---|
1485 |
|
---|
1486 | torture_assert(torture,
|
---|
1487 | test_join3(torture, true, anon_creds, cmdline_credentials, wks_name),
|
---|
1488 | "join using ntlmssp bind on an anonymous smb connection failed");
|
---|
1489 |
|
---|
1490 | torture_assert(torture,
|
---|
1491 | test_join3(torture, true, cmdline_credentials, NULL, wks_name),
|
---|
1492 | "join using anonymous bind on an authenticated smb connection failed");
|
---|
1493 |
|
---|
1494 | return true;
|
---|
1495 | }
|
---|
1496 |
|
---|
1497 | /*
|
---|
1498 | * open pipe and bind, given an IPC$ context
|
---|
1499 | */
|
---|
1500 |
|
---|
1501 | static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
|
---|
1502 | TALLOC_CTX *mem_ctx,
|
---|
1503 | struct smbcli_tree *tree,
|
---|
1504 | const char *pipe_name,
|
---|
1505 | const struct ndr_interface_table *iface,
|
---|
1506 | struct dcerpc_pipe **p)
|
---|
1507 | {
|
---|
1508 | struct dcerpc_pipe *result;
|
---|
1509 | NTSTATUS status;
|
---|
1510 |
|
---|
1511 | if (!(result = dcerpc_pipe_init(
|
---|
1512 | mem_ctx, tree->session->transport->socket->event.ctx))) {
|
---|
1513 | return NT_STATUS_NO_MEMORY;
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | status = dcerpc_pipe_open_smb(result, tree, pipe_name);
|
---|
1517 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1518 | torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
|
---|
1519 | nt_errstr(status));
|
---|
1520 | talloc_free(result);
|
---|
1521 | return status;
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | status = dcerpc_bind_auth_none(result, iface);
|
---|
1525 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1526 | torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
|
---|
1527 | talloc_free(result);
|
---|
1528 | return status;
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | *p = result;
|
---|
1532 | return NT_STATUS_OK;
|
---|
1533 | }
|
---|
1534 |
|
---|
1535 | /*
|
---|
1536 | * Sane wrapper around lsa_LookupNames
|
---|
1537 | */
|
---|
1538 |
|
---|
1539 | static struct dom_sid *name2sid(struct torture_context *tctx,
|
---|
1540 | TALLOC_CTX *mem_ctx,
|
---|
1541 | struct dcerpc_pipe *p,
|
---|
1542 | const char *name,
|
---|
1543 | const char *domain)
|
---|
1544 | {
|
---|
1545 | struct lsa_ObjectAttribute attr;
|
---|
1546 | struct lsa_QosInfo qos;
|
---|
1547 | struct lsa_OpenPolicy2 r;
|
---|
1548 | struct lsa_Close c;
|
---|
1549 | NTSTATUS status;
|
---|
1550 | struct policy_handle handle;
|
---|
1551 | struct lsa_LookupNames l;
|
---|
1552 | struct lsa_TransSidArray sids;
|
---|
1553 | struct lsa_RefDomainList *domains = NULL;
|
---|
1554 | struct lsa_String lsa_name;
|
---|
1555 | uint32_t count = 0;
|
---|
1556 | struct dom_sid *result;
|
---|
1557 | TALLOC_CTX *tmp_ctx;
|
---|
1558 | struct dcerpc_binding_handle *b = p->binding_handle;
|
---|
1559 |
|
---|
1560 | if (!(tmp_ctx = talloc_new(mem_ctx))) {
|
---|
1561 | return NULL;
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 | qos.len = 0;
|
---|
1565 | qos.impersonation_level = 2;
|
---|
1566 | qos.context_mode = 1;
|
---|
1567 | qos.effective_only = 0;
|
---|
1568 |
|
---|
1569 | attr.len = 0;
|
---|
1570 | attr.root_dir = NULL;
|
---|
1571 | attr.object_name = NULL;
|
---|
1572 | attr.attributes = 0;
|
---|
1573 | attr.sec_desc = NULL;
|
---|
1574 | attr.sec_qos = &qos;
|
---|
1575 |
|
---|
1576 | r.in.system_name = "\\";
|
---|
1577 | r.in.attr = &attr;
|
---|
1578 | r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
1579 | r.out.handle = &handle;
|
---|
1580 |
|
---|
1581 | status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r);
|
---|
1582 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1583 | torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status));
|
---|
1584 | talloc_free(tmp_ctx);
|
---|
1585 | return NULL;
|
---|
1586 | }
|
---|
1587 | if (!NT_STATUS_IS_OK(r.out.result)) {
|
---|
1588 | torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result));
|
---|
1589 | talloc_free(tmp_ctx);
|
---|
1590 | return NULL;
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | sids.count = 0;
|
---|
1594 | sids.sids = NULL;
|
---|
1595 |
|
---|
1596 | lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
|
---|
1597 |
|
---|
1598 | l.in.handle = &handle;
|
---|
1599 | l.in.num_names = 1;
|
---|
1600 | l.in.names = &lsa_name;
|
---|
1601 | l.in.sids = &sids;
|
---|
1602 | l.in.level = 1;
|
---|
1603 | l.in.count = &count;
|
---|
1604 | l.out.count = &count;
|
---|
1605 | l.out.sids = &sids;
|
---|
1606 | l.out.domains = &domains;
|
---|
1607 |
|
---|
1608 | status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l);
|
---|
1609 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1610 | torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
|
---|
1611 | nt_errstr(status));
|
---|
1612 | talloc_free(tmp_ctx);
|
---|
1613 | return NULL;
|
---|
1614 | }
|
---|
1615 | if (!NT_STATUS_IS_OK(l.out.result)) {
|
---|
1616 | torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
|
---|
1617 | nt_errstr(l.out.result));
|
---|
1618 | talloc_free(tmp_ctx);
|
---|
1619 | return NULL;
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
|
---|
1623 | l.out.sids->sids[0].rid);
|
---|
1624 |
|
---|
1625 | c.in.handle = &handle;
|
---|
1626 | c.out.handle = &handle;
|
---|
1627 |
|
---|
1628 | status = dcerpc_lsa_Close_r(b, tmp_ctx, &c);
|
---|
1629 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1630 | torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
|
---|
1631 | talloc_free(tmp_ctx);
|
---|
1632 | return NULL;
|
---|
1633 | }
|
---|
1634 | if (!NT_STATUS_IS_OK(c.out.result)) {
|
---|
1635 | torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result));
|
---|
1636 | talloc_free(tmp_ctx);
|
---|
1637 | return NULL;
|
---|
1638 | }
|
---|
1639 |
|
---|
1640 | talloc_free(tmp_ctx);
|
---|
1641 | return result;
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | /*
|
---|
1645 | * Find out the user SID on this connection
|
---|
1646 | */
|
---|
1647 |
|
---|
1648 | static struct dom_sid *whoami(struct torture_context *tctx,
|
---|
1649 | TALLOC_CTX *mem_ctx,
|
---|
1650 | struct smbcli_tree *tree)
|
---|
1651 | {
|
---|
1652 | struct dcerpc_pipe *lsa;
|
---|
1653 | struct dcerpc_binding_handle *lsa_handle;
|
---|
1654 | struct lsa_GetUserName r;
|
---|
1655 | NTSTATUS status;
|
---|
1656 | struct lsa_String *authority_name_p = NULL;
|
---|
1657 | struct lsa_String *account_name_p = NULL;
|
---|
1658 | struct dom_sid *result;
|
---|
1659 |
|
---|
1660 | status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
|
---|
1661 | &ndr_table_lsarpc, &lsa);
|
---|
1662 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1663 | torture_warning(tctx, "Could not bind to LSA: %s\n",
|
---|
1664 | nt_errstr(status));
|
---|
1665 | return NULL;
|
---|
1666 | }
|
---|
1667 | lsa_handle = lsa->binding_handle;
|
---|
1668 |
|
---|
1669 | r.in.system_name = "\\";
|
---|
1670 | r.in.account_name = &account_name_p;
|
---|
1671 | r.in.authority_name = &authority_name_p;
|
---|
1672 | r.out.account_name = &account_name_p;
|
---|
1673 |
|
---|
1674 | status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
|
---|
1675 |
|
---|
1676 | authority_name_p = *r.out.authority_name;
|
---|
1677 |
|
---|
1678 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1679 | torture_warning(tctx, "GetUserName failed - %s\n",
|
---|
1680 | nt_errstr(status));
|
---|
1681 | talloc_free(lsa);
|
---|
1682 | return NULL;
|
---|
1683 | }
|
---|
1684 | if (!NT_STATUS_IS_OK(r.out.result)) {
|
---|
1685 | torture_warning(tctx, "GetUserName failed - %s\n",
|
---|
1686 | nt_errstr(r.out.result));
|
---|
1687 | talloc_free(lsa);
|
---|
1688 | return NULL;
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
|
---|
1692 | authority_name_p->string);
|
---|
1693 |
|
---|
1694 | talloc_free(lsa);
|
---|
1695 | return result;
|
---|
1696 | }
|
---|
1697 |
|
---|
1698 | static int destroy_tree(struct smbcli_tree *tree)
|
---|
1699 | {
|
---|
1700 | smb_tree_disconnect(tree);
|
---|
1701 | return 0;
|
---|
1702 | }
|
---|
1703 |
|
---|
1704 | /*
|
---|
1705 | * Do a tcon, given a session
|
---|
1706 | */
|
---|
1707 |
|
---|
1708 | static NTSTATUS secondary_tcon(struct torture_context *tctx,
|
---|
1709 | TALLOC_CTX *mem_ctx,
|
---|
1710 | struct smbcli_session *session,
|
---|
1711 | const char *sharename,
|
---|
1712 | struct smbcli_tree **res)
|
---|
1713 | {
|
---|
1714 | struct smbcli_tree *result;
|
---|
1715 | TALLOC_CTX *tmp_ctx;
|
---|
1716 | union smb_tcon tcon;
|
---|
1717 | NTSTATUS status;
|
---|
1718 |
|
---|
1719 | if (!(tmp_ctx = talloc_new(mem_ctx))) {
|
---|
1720 | return NT_STATUS_NO_MEMORY;
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 | if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
|
---|
1724 | talloc_free(tmp_ctx);
|
---|
1725 | return NT_STATUS_NO_MEMORY;
|
---|
1726 | }
|
---|
1727 |
|
---|
1728 | tcon.generic.level = RAW_TCON_TCONX;
|
---|
1729 | tcon.tconx.in.flags = 0;
|
---|
1730 | tcon.tconx.in.password = data_blob(NULL, 0);
|
---|
1731 | tcon.tconx.in.path = sharename;
|
---|
1732 | tcon.tconx.in.device = "?????";
|
---|
1733 |
|
---|
1734 | status = smb_raw_tcon(result, tmp_ctx, &tcon);
|
---|
1735 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1736 | torture_warning(tctx, "smb_raw_tcon failed: %s\n",
|
---|
1737 | nt_errstr(status));
|
---|
1738 | talloc_free(tmp_ctx);
|
---|
1739 | return status;
|
---|
1740 | }
|
---|
1741 |
|
---|
1742 | result->tid = tcon.tconx.out.tid;
|
---|
1743 | result = talloc_steal(mem_ctx, result);
|
---|
1744 | talloc_set_destructor(result, destroy_tree);
|
---|
1745 | talloc_free(tmp_ctx);
|
---|
1746 | *res = result;
|
---|
1747 | return NT_STATUS_OK;
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | /*
|
---|
1751 | * Test the getusername behaviour
|
---|
1752 | */
|
---|
1753 |
|
---|
1754 | static bool torture_samba3_rpc_getusername(struct torture_context *torture)
|
---|
1755 | {
|
---|
1756 | NTSTATUS status;
|
---|
1757 | struct smbcli_state *cli;
|
---|
1758 | bool ret = true;
|
---|
1759 | struct dom_sid *user_sid;
|
---|
1760 | struct dom_sid *created_sid;
|
---|
1761 | struct cli_credentials *anon_creds;
|
---|
1762 | struct cli_credentials *user_creds;
|
---|
1763 | char *domain_name;
|
---|
1764 | struct smbcli_options options;
|
---|
1765 | struct smbcli_session_options session_options;
|
---|
1766 |
|
---|
1767 | lpcfg_smbcli_options(torture->lp_ctx, &options);
|
---|
1768 | lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
|
---|
1769 |
|
---|
1770 | status = smbcli_full_connection(
|
---|
1771 | torture, &cli, torture_setting_string(torture, "host", NULL),
|
---|
1772 | lpcfg_smb_ports(torture->lp_ctx),
|
---|
1773 | "IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
|
---|
1774 | lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
|
---|
1775 | &session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
|
---|
1776 | torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
|
---|
1777 |
|
---|
1778 | if (!(user_sid = whoami(torture, torture, cli->tree))) {
|
---|
1779 | torture_fail(torture, "whoami on auth'ed connection failed\n");
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | talloc_free(cli);
|
---|
1783 |
|
---|
1784 | if (!(anon_creds = cli_credentials_init_anon(torture))) {
|
---|
1785 | torture_fail(torture, "create_anon_creds failed\n");
|
---|
1786 | }
|
---|
1787 |
|
---|
1788 | status = smbcli_full_connection(
|
---|
1789 | torture, &cli, torture_setting_string(torture, "host", NULL),
|
---|
1790 | lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
|
---|
1791 | lpcfg_socket_options(torture->lp_ctx), anon_creds,
|
---|
1792 | lpcfg_resolve_context(torture->lp_ctx),
|
---|
1793 | torture->ev, &options, &session_options,
|
---|
1794 | lpcfg_gensec_settings(torture, torture->lp_ctx));
|
---|
1795 | torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
|
---|
1796 |
|
---|
1797 | if (!(user_sid = whoami(torture, torture, cli->tree))) {
|
---|
1798 | torture_fail(torture, "whoami on anon connection failed\n");
|
---|
1799 | }
|
---|
1800 |
|
---|
1801 | torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
|
---|
1802 | "Anon lsa_GetUserName returned unexpected SID");
|
---|
1803 |
|
---|
1804 | if (!(user_creds = cli_credentials_init(torture))) {
|
---|
1805 | torture_fail(torture, "cli_credentials_init failed\n");
|
---|
1806 | }
|
---|
1807 |
|
---|
1808 | cli_credentials_set_conf(user_creds, torture->lp_ctx);
|
---|
1809 | cli_credentials_set_username(user_creds, "torture_username",
|
---|
1810 | CRED_SPECIFIED);
|
---|
1811 | cli_credentials_set_password(user_creds,
|
---|
1812 | generate_random_password(user_creds, 8, 255),
|
---|
1813 | CRED_SPECIFIED);
|
---|
1814 |
|
---|
1815 | if (!create_user(torture, torture, cli, cmdline_credentials,
|
---|
1816 | cli_credentials_get_username(user_creds),
|
---|
1817 | cli_credentials_get_password(user_creds),
|
---|
1818 | &domain_name, &created_sid)) {
|
---|
1819 | torture_fail(torture, "create_user failed\n");
|
---|
1820 | }
|
---|
1821 |
|
---|
1822 | cli_credentials_set_domain(user_creds, domain_name,
|
---|
1823 | CRED_SPECIFIED);
|
---|
1824 |
|
---|
1825 | {
|
---|
1826 | struct smbcli_session *session2;
|
---|
1827 | struct smb_composite_sesssetup setup;
|
---|
1828 | struct smbcli_tree *tree;
|
---|
1829 |
|
---|
1830 | session2 = smbcli_session_init(cli->transport, torture, false, session_options);
|
---|
1831 | if (session2 == NULL) {
|
---|
1832 | torture_fail(torture, "smbcli_session_init failed\n");
|
---|
1833 | }
|
---|
1834 |
|
---|
1835 | setup.in.sesskey = cli->transport->negotiate.sesskey;
|
---|
1836 | setup.in.capabilities = cli->transport->negotiate.capabilities;
|
---|
1837 | setup.in.workgroup = "";
|
---|
1838 | setup.in.credentials = user_creds;
|
---|
1839 | setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
|
---|
1840 |
|
---|
1841 | status = smb_composite_sesssetup(session2, &setup);
|
---|
1842 | torture_assert_ntstatus_ok(torture, status, "session setup with new user failed");
|
---|
1843 |
|
---|
1844 | session2->vuid = setup.out.vuid;
|
---|
1845 |
|
---|
1846 | if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2,
|
---|
1847 | "IPC$", &tree))) {
|
---|
1848 | torture_fail(torture, "secondary_tcon failed\n");
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 | if (!(user_sid = whoami(torture, torture, tree))) {
|
---|
1852 | torture_fail_goto(torture, del, "whoami on user connection failed\n");
|
---|
1853 | ret = false;
|
---|
1854 | goto del;
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | talloc_free(tree);
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | torture_comment(torture, "Created %s, found %s\n",
|
---|
1861 | dom_sid_string(torture, created_sid),
|
---|
1862 | dom_sid_string(torture, user_sid));
|
---|
1863 |
|
---|
1864 | if (!dom_sid_equal(created_sid, user_sid)) {
|
---|
1865 | ret = false;
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 | del:
|
---|
1869 | if (!delete_user(torture, cli,
|
---|
1870 | cmdline_credentials,
|
---|
1871 | cli_credentials_get_username(user_creds))) {
|
---|
1872 | torture_fail(torture, "delete_user failed\n");
|
---|
1873 | }
|
---|
1874 |
|
---|
1875 | return ret;
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | static bool test_NetShareGetInfo(struct torture_context *tctx,
|
---|
1879 | struct dcerpc_pipe *p,
|
---|
1880 | const char *sharename)
|
---|
1881 | {
|
---|
1882 | NTSTATUS status;
|
---|
1883 | struct srvsvc_NetShareGetInfo r;
|
---|
1884 | union srvsvc_NetShareInfo info;
|
---|
1885 | uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
|
---|
1886 | int i;
|
---|
1887 | bool ret = true;
|
---|
1888 | struct dcerpc_binding_handle *b = p->binding_handle;
|
---|
1889 |
|
---|
1890 | r.in.server_unc = talloc_asprintf(tctx, "\\\\%s",
|
---|
1891 | dcerpc_server_name(p));
|
---|
1892 | r.in.share_name = sharename;
|
---|
1893 | r.out.info = &info;
|
---|
1894 |
|
---|
1895 | for (i=0;i<ARRAY_SIZE(levels);i++) {
|
---|
1896 | r.in.level = levels[i];
|
---|
1897 |
|
---|
1898 | torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
|
---|
1899 | r.in.level, r.in.share_name);
|
---|
1900 |
|
---|
1901 | status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
|
---|
1902 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1903 | torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed"
|
---|
1904 | " - %s\n", r.in.level, r.in.share_name,
|
---|
1905 | nt_errstr(status));
|
---|
1906 | ret = false;
|
---|
1907 | continue;
|
---|
1908 | }
|
---|
1909 | if (!W_ERROR_IS_OK(r.out.result)) {
|
---|
1910 | torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed "
|
---|
1911 | "- %s\n", r.in.level, r.in.share_name,
|
---|
1912 | win_errstr(r.out.result));
|
---|
1913 | ret = false;
|
---|
1914 | continue;
|
---|
1915 | }
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | return ret;
|
---|
1919 | }
|
---|
1920 |
|
---|
1921 | static bool test_NetShareEnum(struct torture_context *tctx,
|
---|
1922 | struct dcerpc_pipe *p,
|
---|
1923 | const char **one_sharename)
|
---|
1924 | {
|
---|
1925 | NTSTATUS status;
|
---|
1926 | struct srvsvc_NetShareEnum r;
|
---|
1927 | struct srvsvc_NetShareInfoCtr info_ctr;
|
---|
1928 | struct srvsvc_NetShareCtr0 c0;
|
---|
1929 | struct srvsvc_NetShareCtr1 c1;
|
---|
1930 | struct srvsvc_NetShareCtr2 c2;
|
---|
1931 | struct srvsvc_NetShareCtr501 c501;
|
---|
1932 | struct srvsvc_NetShareCtr502 c502;
|
---|
1933 | struct srvsvc_NetShareCtr1004 c1004;
|
---|
1934 | struct srvsvc_NetShareCtr1005 c1005;
|
---|
1935 | struct srvsvc_NetShareCtr1006 c1006;
|
---|
1936 | struct srvsvc_NetShareCtr1007 c1007;
|
---|
1937 | uint32_t totalentries = 0;
|
---|
1938 | uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
|
---|
1939 | int i;
|
---|
1940 | bool ret = true;
|
---|
1941 | struct dcerpc_binding_handle *b = p->binding_handle;
|
---|
1942 |
|
---|
1943 | ZERO_STRUCT(info_ctr);
|
---|
1944 |
|
---|
1945 | r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
|
---|
1946 | r.in.info_ctr = &info_ctr;
|
---|
1947 | r.in.max_buffer = (uint32_t)-1;
|
---|
1948 | r.in.resume_handle = NULL;
|
---|
1949 | r.out.totalentries = &totalentries;
|
---|
1950 | r.out.info_ctr = &info_ctr;
|
---|
1951 |
|
---|
1952 | for (i=0;i<ARRAY_SIZE(levels);i++) {
|
---|
1953 | info_ctr.level = levels[i];
|
---|
1954 |
|
---|
1955 | switch (info_ctr.level) {
|
---|
1956 | case 0:
|
---|
1957 | ZERO_STRUCT(c0);
|
---|
1958 | info_ctr.ctr.ctr0 = &c0;
|
---|
1959 | break;
|
---|
1960 | case 1:
|
---|
1961 | ZERO_STRUCT(c1);
|
---|
1962 | info_ctr.ctr.ctr1 = &c1;
|
---|
1963 | break;
|
---|
1964 | case 2:
|
---|
1965 | ZERO_STRUCT(c2);
|
---|
1966 | info_ctr.ctr.ctr2 = &c2;
|
---|
1967 | break;
|
---|
1968 | case 501:
|
---|
1969 | ZERO_STRUCT(c501);
|
---|
1970 | info_ctr.ctr.ctr501 = &c501;
|
---|
1971 | break;
|
---|
1972 | case 502:
|
---|
1973 | ZERO_STRUCT(c502);
|
---|
1974 | info_ctr.ctr.ctr502 = &c502;
|
---|
1975 | break;
|
---|
1976 | case 1004:
|
---|
1977 | ZERO_STRUCT(c1004);
|
---|
1978 | info_ctr.ctr.ctr1004 = &c1004;
|
---|
1979 | break;
|
---|
1980 | case 1005:
|
---|
1981 | ZERO_STRUCT(c1005);
|
---|
1982 | info_ctr.ctr.ctr1005 = &c1005;
|
---|
1983 | break;
|
---|
1984 | case 1006:
|
---|
1985 | ZERO_STRUCT(c1006);
|
---|
1986 | info_ctr.ctr.ctr1006 = &c1006;
|
---|
1987 | break;
|
---|
1988 | case 1007:
|
---|
1989 | ZERO_STRUCT(c1007);
|
---|
1990 | info_ctr.ctr.ctr1007 = &c1007;
|
---|
1991 | break;
|
---|
1992 | }
|
---|
1993 |
|
---|
1994 | torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
|
---|
1995 |
|
---|
1996 | status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
|
---|
1997 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1998 | torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
|
---|
1999 | info_ctr.level, nt_errstr(status));
|
---|
2000 | ret = false;
|
---|
2001 | continue;
|
---|
2002 | }
|
---|
2003 | if (!W_ERROR_IS_OK(r.out.result)) {
|
---|
2004 | torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
|
---|
2005 | info_ctr.level, win_errstr(r.out.result));
|
---|
2006 | continue;
|
---|
2007 | }
|
---|
2008 | if (info_ctr.level == 0) {
|
---|
2009 | struct srvsvc_NetShareCtr0 *ctr = r.out.info_ctr->ctr.ctr0;
|
---|
2010 | if (ctr->count > 0) {
|
---|
2011 | *one_sharename = ctr->array[0].name;
|
---|
2012 | }
|
---|
2013 | }
|
---|
2014 | }
|
---|
2015 |
|
---|
2016 | return ret;
|
---|
2017 | }
|
---|
2018 |
|
---|
2019 | static bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
|
---|
2020 | {
|
---|
2021 | struct dcerpc_pipe *p;
|
---|
2022 | const char *sharename = NULL;
|
---|
2023 | bool ret = true;
|
---|
2024 |
|
---|
2025 | torture_assert_ntstatus_ok(torture,
|
---|
2026 | torture_rpc_connection(torture, &p, &ndr_table_srvsvc),
|
---|
2027 | "failed to open srvsvc");
|
---|
2028 |
|
---|
2029 | ret &= test_NetShareEnum(torture, p, &sharename);
|
---|
2030 | if (sharename == NULL) {
|
---|
2031 | torture_comment(torture, "did not get sharename\n");
|
---|
2032 | } else {
|
---|
2033 | ret &= test_NetShareGetInfo(torture, p, sharename);
|
---|
2034 | }
|
---|
2035 |
|
---|
2036 | return ret;
|
---|
2037 | }
|
---|
2038 |
|
---|
2039 | /*
|
---|
2040 | * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
|
---|
2041 | * NT_STATUS_NO_SAM_ACCOUNT
|
---|
2042 | */
|
---|
2043 |
|
---|
2044 | static bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
|
---|
2045 | {
|
---|
2046 | TALLOC_CTX *mem_ctx;
|
---|
2047 | struct dcerpc_pipe *net_pipe;
|
---|
2048 | struct dcerpc_binding_handle *net_handle;
|
---|
2049 | char *wksname;
|
---|
2050 | bool result = false;
|
---|
2051 | NTSTATUS status;
|
---|
2052 | struct netr_ServerReqChallenge r;
|
---|
2053 | struct netr_Credential netr_cli_creds;
|
---|
2054 | struct netr_Credential netr_srv_creds;
|
---|
2055 | uint32_t negotiate_flags;
|
---|
2056 | struct netr_ServerAuthenticate2 a;
|
---|
2057 | struct netlogon_creds_CredentialState *creds_state;
|
---|
2058 | struct netr_Credential netr_cred;
|
---|
2059 | struct samr_Password mach_pw;
|
---|
2060 | struct smbcli_state *cli;
|
---|
2061 |
|
---|
2062 | if (!(mem_ctx = talloc_new(torture))) {
|
---|
2063 | torture_comment(torture, "talloc_new failed\n");
|
---|
2064 | return false;
|
---|
2065 | }
|
---|
2066 |
|
---|
2067 | if (!(wksname = generate_random_str_list(
|
---|
2068 | mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
|
---|
2069 | torture_comment(torture, "generate_random_str_list failed\n");
|
---|
2070 | goto done;
|
---|
2071 | }
|
---|
2072 |
|
---|
2073 | if (!(torture_open_connection_share(
|
---|
2074 | mem_ctx, &cli,
|
---|
2075 | torture, torture_setting_string(torture, "host", NULL),
|
---|
2076 | "IPC$", torture->ev))) {
|
---|
2077 | torture_comment(torture, "IPC$ connection failed\n");
|
---|
2078 | goto done;
|
---|
2079 | }
|
---|
2080 |
|
---|
2081 | if (!(net_pipe = dcerpc_pipe_init(
|
---|
2082 | mem_ctx, cli->transport->socket->event.ctx))) {
|
---|
2083 | torture_comment(torture, "dcerpc_pipe_init failed\n");
|
---|
2084 | goto done;
|
---|
2085 | }
|
---|
2086 | net_handle = net_pipe->binding_handle;
|
---|
2087 |
|
---|
2088 | status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
|
---|
2089 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2090 | torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
|
---|
2091 | nt_errstr(status));
|
---|
2092 | goto done;
|
---|
2093 | }
|
---|
2094 |
|
---|
2095 | status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
|
---|
2096 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2097 | torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
|
---|
2098 | nt_errstr(status));
|
---|
2099 | goto done;
|
---|
2100 | }
|
---|
2101 |
|
---|
2102 | r.in.computer_name = wksname;
|
---|
2103 | r.in.server_name = talloc_asprintf(
|
---|
2104 | mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
|
---|
2105 | if (r.in.server_name == NULL) {
|
---|
2106 | torture_comment(torture, "talloc_asprintf failed\n");
|
---|
2107 | goto done;
|
---|
2108 | }
|
---|
2109 | generate_random_buffer(netr_cli_creds.data,
|
---|
2110 | sizeof(netr_cli_creds.data));
|
---|
2111 | r.in.credentials = &netr_cli_creds;
|
---|
2112 | r.out.return_credentials = &netr_srv_creds;
|
---|
2113 |
|
---|
2114 | status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
|
---|
2115 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2116 | torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
|
---|
2117 | nt_errstr(status));
|
---|
2118 | goto done;
|
---|
2119 | }
|
---|
2120 | if (!NT_STATUS_IS_OK(r.out.result)) {
|
---|
2121 | torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
|
---|
2122 | nt_errstr(r.out.result));
|
---|
2123 | goto done;
|
---|
2124 | }
|
---|
2125 |
|
---|
2126 | negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
|
---|
2127 | E_md4hash("foobar", mach_pw.hash);
|
---|
2128 |
|
---|
2129 | a.in.server_name = talloc_asprintf(
|
---|
2130 | mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
|
---|
2131 | a.in.account_name = talloc_asprintf(
|
---|
2132 | mem_ctx, "%s$", wksname);
|
---|
2133 | a.in.computer_name = wksname;
|
---|
2134 | a.in.secure_channel_type = SEC_CHAN_WKSTA;
|
---|
2135 | a.in.negotiate_flags = &negotiate_flags;
|
---|
2136 | a.out.negotiate_flags = &negotiate_flags;
|
---|
2137 | a.in.credentials = &netr_cred;
|
---|
2138 | a.out.return_credentials = &netr_cred;
|
---|
2139 |
|
---|
2140 | creds_state = netlogon_creds_client_init(mem_ctx,
|
---|
2141 | a.in.account_name,
|
---|
2142 | a.in.computer_name,
|
---|
2143 | r.in.credentials,
|
---|
2144 | r.out.return_credentials, &mach_pw,
|
---|
2145 | &netr_cred, negotiate_flags);
|
---|
2146 |
|
---|
2147 |
|
---|
2148 | status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
|
---|
2149 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2150 | goto done;
|
---|
2151 | }
|
---|
2152 | if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
|
---|
2153 | torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, "
|
---|
2154 | "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
|
---|
2155 | nt_errstr(a.out.result));
|
---|
2156 | goto done;
|
---|
2157 | }
|
---|
2158 |
|
---|
2159 | result = true;
|
---|
2160 | done:
|
---|
2161 | talloc_free(mem_ctx);
|
---|
2162 | return result;
|
---|
2163 | }
|
---|
2164 |
|
---|
2165 | static struct security_descriptor *get_sharesec(struct torture_context *tctx,
|
---|
2166 | TALLOC_CTX *mem_ctx,
|
---|
2167 | struct smbcli_session *sess,
|
---|
2168 | const char *sharename)
|
---|
2169 | {
|
---|
2170 | struct smbcli_tree *tree;
|
---|
2171 | TALLOC_CTX *tmp_ctx;
|
---|
2172 | struct dcerpc_pipe *p;
|
---|
2173 | struct dcerpc_binding_handle *b;
|
---|
2174 | NTSTATUS status;
|
---|
2175 | struct srvsvc_NetShareGetInfo r;
|
---|
2176 | union srvsvc_NetShareInfo info;
|
---|
2177 | struct security_descriptor *result;
|
---|
2178 |
|
---|
2179 | if (!(tmp_ctx = talloc_new(mem_ctx))) {
|
---|
2180 | torture_comment(tctx, "talloc_new failed\n");
|
---|
2181 | return NULL;
|
---|
2182 | }
|
---|
2183 |
|
---|
2184 | if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
|
---|
2185 | torture_comment(tctx, "secondary_tcon failed\n");
|
---|
2186 | talloc_free(tmp_ctx);
|
---|
2187 | return NULL;
|
---|
2188 | }
|
---|
2189 |
|
---|
2190 | status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
|
---|
2191 | &ndr_table_srvsvc, &p);
|
---|
2192 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2193 | torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
|
---|
2194 | nt_errstr(status));
|
---|
2195 | talloc_free(tmp_ctx);
|
---|
2196 | return NULL;
|
---|
2197 | }
|
---|
2198 | b = p->binding_handle;
|
---|
2199 |
|
---|
2200 | #if 0
|
---|
2201 | p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
|
---|
2202 | #endif
|
---|
2203 |
|
---|
2204 | r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
|
---|
2205 | dcerpc_server_name(p));
|
---|
2206 | r.in.share_name = sharename;
|
---|
2207 | r.in.level = 502;
|
---|
2208 | r.out.info = &info;
|
---|
2209 |
|
---|
2210 | status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r);
|
---|
2211 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2212 | torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
|
---|
2213 | nt_errstr(status));
|
---|
2214 | talloc_free(tmp_ctx);
|
---|
2215 | return NULL;
|
---|
2216 | }
|
---|
2217 | if (!W_ERROR_IS_OK(r.out.result)) {
|
---|
2218 | torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
|
---|
2219 | win_errstr(r.out.result));
|
---|
2220 | talloc_free(tmp_ctx);
|
---|
2221 | return NULL;
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
|
---|
2225 | talloc_free(tmp_ctx);
|
---|
2226 | return result;
|
---|
2227 | }
|
---|
2228 |
|
---|
2229 | static NTSTATUS set_sharesec(struct torture_context *tctx,
|
---|
2230 | TALLOC_CTX *mem_ctx,
|
---|
2231 | struct smbcli_session *sess,
|
---|
2232 | const char *sharename,
|
---|
2233 | struct security_descriptor *sd)
|
---|
2234 | {
|
---|
2235 | struct smbcli_tree *tree;
|
---|
2236 | TALLOC_CTX *tmp_ctx;
|
---|
2237 | struct dcerpc_pipe *p;
|
---|
2238 | struct dcerpc_binding_handle *b;
|
---|
2239 | NTSTATUS status;
|
---|
2240 | struct sec_desc_buf i;
|
---|
2241 | struct srvsvc_NetShareSetInfo r;
|
---|
2242 | union srvsvc_NetShareInfo info;
|
---|
2243 | uint32_t error = 0;
|
---|
2244 |
|
---|
2245 | if (!(tmp_ctx = talloc_new(mem_ctx))) {
|
---|
2246 | torture_comment(tctx, "talloc_new failed\n");
|
---|
2247 | return NT_STATUS_NO_MEMORY;
|
---|
2248 | }
|
---|
2249 |
|
---|
2250 | if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
|
---|
2251 | torture_comment(tctx, "secondary_tcon failed\n");
|
---|
2252 | talloc_free(tmp_ctx);
|
---|
2253 | return NT_STATUS_UNSUCCESSFUL;
|
---|
2254 | }
|
---|
2255 |
|
---|
2256 | status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
|
---|
2257 | &ndr_table_srvsvc, &p);
|
---|
2258 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2259 | torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
|
---|
2260 | nt_errstr(status));
|
---|
2261 | talloc_free(tmp_ctx);
|
---|
2262 | return NT_STATUS_UNSUCCESSFUL;
|
---|
2263 | }
|
---|
2264 | b = p->binding_handle;
|
---|
2265 |
|
---|
2266 | #if 0
|
---|
2267 | p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
|
---|
2268 | #endif
|
---|
2269 |
|
---|
2270 | r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
|
---|
2271 | dcerpc_server_name(p));
|
---|
2272 | r.in.share_name = sharename;
|
---|
2273 | r.in.level = 1501;
|
---|
2274 | i.sd = sd;
|
---|
2275 | info.info1501 = &i;
|
---|
2276 | r.in.info = &info;
|
---|
2277 | r.in.parm_error = &error;
|
---|
2278 |
|
---|
2279 | status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r);
|
---|
2280 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2281 | torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
|
---|
2282 | nt_errstr(status));
|
---|
2283 | }
|
---|
2284 | if (!W_ERROR_IS_OK(r.out.result)) {
|
---|
2285 | torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
|
---|
2286 | win_errstr(r.out.result));
|
---|
2287 | status = werror_to_ntstatus(r.out.result);
|
---|
2288 | }
|
---|
2289 | talloc_free(tmp_ctx);
|
---|
2290 | return status;
|
---|
2291 | }
|
---|
2292 |
|
---|
2293 | bool try_tcon(struct torture_context *tctx,
|
---|
2294 | TALLOC_CTX *mem_ctx,
|
---|
2295 | struct security_descriptor *orig_sd,
|
---|
2296 | struct smbcli_session *session,
|
---|
2297 | const char *sharename, const struct dom_sid *user_sid,
|
---|
2298 | unsigned int access_mask, NTSTATUS expected_tcon,
|
---|
2299 | NTSTATUS expected_mkdir)
|
---|
2300 | {
|
---|
2301 | TALLOC_CTX *tmp_ctx;
|
---|
2302 | struct smbcli_tree *rmdir_tree, *tree;
|
---|
2303 | struct dom_sid *domain_sid;
|
---|
2304 | uint32_t rid;
|
---|
2305 | struct security_descriptor *sd;
|
---|
2306 | NTSTATUS status;
|
---|
2307 | bool ret = true;
|
---|
2308 |
|
---|
2309 | if (!(tmp_ctx = talloc_new(mem_ctx))) {
|
---|
2310 | torture_comment(tctx, "talloc_new failed\n");
|
---|
2311 | return false;
|
---|
2312 | }
|
---|
2313 |
|
---|
2314 | status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree);
|
---|
2315 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2316 | torture_comment(tctx, "first tcon to delete dir failed\n");
|
---|
2317 | talloc_free(tmp_ctx);
|
---|
2318 | return false;
|
---|
2319 | }
|
---|
2320 |
|
---|
2321 | smbcli_rmdir(rmdir_tree, "sharesec_testdir");
|
---|
2322 |
|
---|
2323 | if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
|
---|
2324 | &domain_sid, &rid))) {
|
---|
2325 | torture_comment(tctx, "dom_sid_split_rid failed\n");
|
---|
2326 | talloc_free(tmp_ctx);
|
---|
2327 | return false;
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | sd = security_descriptor_dacl_create(
|
---|
2331 | tmp_ctx, 0, "S-1-5-32-544",
|
---|
2332 | dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
|
---|
2333 | DOMAIN_RID_USERS)),
|
---|
2334 | dom_sid_string(mem_ctx, user_sid),
|
---|
2335 | SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
|
---|
2336 | if (sd == NULL) {
|
---|
2337 | torture_comment(tctx, "security_descriptor_dacl_create failed\n");
|
---|
2338 | talloc_free(tmp_ctx);
|
---|
2339 | return false;
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | status = set_sharesec(tctx, mem_ctx, session, sharename, sd);
|
---|
2343 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2344 | torture_comment(tctx, "custom set_sharesec failed: %s\n",
|
---|
2345 | nt_errstr(status));
|
---|
2346 | talloc_free(tmp_ctx);
|
---|
2347 | return false;
|
---|
2348 | }
|
---|
2349 |
|
---|
2350 | status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree);
|
---|
2351 | if (!NT_STATUS_EQUAL(status, expected_tcon)) {
|
---|
2352 | torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon),
|
---|
2353 | nt_errstr(status));
|
---|
2354 | ret = false;
|
---|
2355 | goto done;
|
---|
2356 | }
|
---|
2357 |
|
---|
2358 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2359 | /* An expected non-access, no point in trying to write */
|
---|
2360 | goto done;
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | status = smbcli_mkdir(tree, "sharesec_testdir");
|
---|
2364 | if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
|
---|
2365 | torture_warning(tctx, "Expected %s, got %s\n",
|
---|
2366 | nt_errstr(expected_mkdir), nt_errstr(status));
|
---|
2367 | ret = false;
|
---|
2368 | }
|
---|
2369 |
|
---|
2370 | done:
|
---|
2371 | smbcli_rmdir(rmdir_tree, "sharesec_testdir");
|
---|
2372 |
|
---|
2373 | status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd);
|
---|
2374 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2375 | torture_comment(tctx, "custom set_sharesec failed: %s\n",
|
---|
2376 | nt_errstr(status));
|
---|
2377 | talloc_free(tmp_ctx);
|
---|
2378 | return false;
|
---|
2379 | }
|
---|
2380 |
|
---|
2381 | talloc_free(tmp_ctx);
|
---|
2382 | return ret;
|
---|
2383 | }
|
---|
2384 |
|
---|
2385 | static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
|
---|
2386 | {
|
---|
2387 | struct smbcli_state *cli;
|
---|
2388 | struct security_descriptor *sd;
|
---|
2389 | struct dom_sid *user_sid;
|
---|
2390 |
|
---|
2391 | if (!(torture_open_connection_share(
|
---|
2392 | torture, &cli, torture, torture_setting_string(torture, "host", NULL),
|
---|
2393 | "IPC$", torture->ev))) {
|
---|
2394 | torture_fail(torture, "IPC$ connection failed\n");
|
---|
2395 | }
|
---|
2396 |
|
---|
2397 | if (!(user_sid = whoami(torture, torture, cli->tree))) {
|
---|
2398 | torture_fail(torture, "whoami failed\n");
|
---|
2399 | }
|
---|
2400 |
|
---|
2401 | sd = get_sharesec(torture, torture, cli->session,
|
---|
2402 | torture_setting_string(torture, "share", NULL));
|
---|
2403 |
|
---|
2404 | torture_assert(torture, try_tcon(
|
---|
2405 | torture, torture, sd, cli->session,
|
---|
2406 | torture_setting_string(torture, "share", NULL),
|
---|
2407 | user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK),
|
---|
2408 | "failed to test tcon with 0 access_mask");
|
---|
2409 |
|
---|
2410 | torture_assert(torture, try_tcon(
|
---|
2411 | torture, torture, sd, cli->session,
|
---|
2412 | torture_setting_string(torture, "share", NULL),
|
---|
2413 | user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
|
---|
2414 | NT_STATUS_MEDIA_WRITE_PROTECTED),
|
---|
2415 | "failed to test tcon with SEC_FILE_READ_DATA access_mask");
|
---|
2416 |
|
---|
2417 | torture_assert(torture, try_tcon(
|
---|
2418 | torture, torture, sd, cli->session,
|
---|
2419 | torture_setting_string(torture, "share", NULL),
|
---|
2420 | user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
|
---|
2421 | "failed to test tcon with SEC_FILE_ALL access_mask")
|
---|
2422 |
|
---|
2423 | return true;
|
---|
2424 | }
|
---|
2425 |
|
---|
2426 | static bool torture_samba3_rpc_lsa(struct torture_context *torture)
|
---|
2427 | {
|
---|
2428 | struct dcerpc_pipe *p;
|
---|
2429 | struct dcerpc_binding_handle *b;
|
---|
2430 | struct policy_handle lsa_handle;
|
---|
2431 |
|
---|
2432 | torture_assert_ntstatus_ok(torture,
|
---|
2433 | torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
|
---|
2434 | "failed to setup lsarpc");
|
---|
2435 |
|
---|
2436 | b = p->binding_handle;
|
---|
2437 |
|
---|
2438 | {
|
---|
2439 | struct lsa_ObjectAttribute attr;
|
---|
2440 | struct lsa_OpenPolicy2 o;
|
---|
2441 | o.in.system_name = talloc_asprintf(
|
---|
2442 | torture, "\\\\%s", dcerpc_server_name(p));
|
---|
2443 | ZERO_STRUCT(attr);
|
---|
2444 | o.in.attr = &attr;
|
---|
2445 | o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
2446 | o.out.handle = &lsa_handle;
|
---|
2447 |
|
---|
2448 | torture_assert_ntstatus_ok(torture,
|
---|
2449 | dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
|
---|
2450 | "dcerpc_lsa_OpenPolicy2 failed");
|
---|
2451 | torture_assert_ntstatus_ok(torture, o.out.result,
|
---|
2452 | "dcerpc_lsa_OpenPolicy2 failed");
|
---|
2453 | }
|
---|
2454 |
|
---|
2455 | {
|
---|
2456 | int i;
|
---|
2457 | int levels[] = { 2,3,5,6 };
|
---|
2458 |
|
---|
2459 | for (i=0; i<ARRAY_SIZE(levels); i++) {
|
---|
2460 | struct lsa_QueryInfoPolicy r;
|
---|
2461 | union lsa_PolicyInformation *info = NULL;
|
---|
2462 | r.in.handle = &lsa_handle;
|
---|
2463 | r.in.level = levels[i];
|
---|
2464 | r.out.info = &info;
|
---|
2465 |
|
---|
2466 | torture_assert_ntstatus_ok(torture,
|
---|
2467 | dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r),
|
---|
2468 | talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
|
---|
2469 | torture_assert_ntstatus_ok(torture, r.out.result,
|
---|
2470 | talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
|
---|
2471 | }
|
---|
2472 | }
|
---|
2473 |
|
---|
2474 | return true;
|
---|
2475 | }
|
---|
2476 |
|
---|
2477 | static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
|
---|
2478 | char **name)
|
---|
2479 | {
|
---|
2480 | struct rap_WserverGetInfo r;
|
---|
2481 | NTSTATUS status;
|
---|
2482 | char servername[17];
|
---|
2483 |
|
---|
2484 | r.in.level = 0;
|
---|
2485 | r.in.bufsize = 0xffff;
|
---|
2486 |
|
---|
2487 | status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
|
---|
2488 | if (!NT_STATUS_IS_OK(status)) {
|
---|
2489 | return status;
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 | memcpy(servername, r.out.info.info0.name, 16);
|
---|
2493 | servername[16] = '\0';
|
---|
2494 |
|
---|
2495 | if (!pull_ascii_talloc(mem_ctx, name, servername, NULL)) {
|
---|
2496 | return NT_STATUS_NO_MEMORY;
|
---|
2497 | }
|
---|
2498 |
|
---|
2499 | return NT_STATUS_OK;
|
---|
2500 | }
|
---|
2501 |
|
---|
2502 | static bool rap_get_servername(struct torture_context *tctx,
|
---|
2503 | char **servername)
|
---|
2504 | {
|
---|
2505 | struct smbcli_state *cli;
|
---|
2506 |
|
---|
2507 | torture_assert(tctx,
|
---|
2508 | torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
|
---|
2509 | "IPC$", tctx->ev),
|
---|
2510 | "IPC$ connection failed");
|
---|
2511 |
|
---|
2512 | torture_assert_ntstatus_ok(tctx,
|
---|
2513 | get_servername(tctx, cli->tree, servername),
|
---|
2514 | "get_servername failed");
|
---|
2515 |
|
---|
2516 | talloc_free(cli);
|
---|
2517 |
|
---|
2518 | return true;
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | static bool find_printers(struct torture_context *tctx,
|
---|
2522 | struct dcerpc_pipe *p,
|
---|
2523 | const char ***printers,
|
---|
2524 | int *num_printers)
|
---|
2525 | {
|
---|
2526 | struct srvsvc_NetShareEnum r;
|
---|
2527 | struct srvsvc_NetShareInfoCtr info_ctr;
|
---|
2528 | struct srvsvc_NetShareCtr1 c1_in;
|
---|
2529 | struct srvsvc_NetShareCtr1 *c1;
|
---|
2530 | uint32_t totalentries = 0;
|
---|
2531 | int i;
|
---|
2532 | struct dcerpc_binding_handle *b = p->binding_handle;
|
---|
2533 |
|
---|
2534 | ZERO_STRUCT(c1_in);
|
---|
2535 | info_ctr.level = 1;
|
---|
2536 | info_ctr.ctr.ctr1 = &c1_in;
|
---|
2537 |
|
---|
2538 | r.in.server_unc = talloc_asprintf(
|
---|
2539 | tctx, "\\\\%s", dcerpc_server_name(p));
|
---|
2540 | r.in.info_ctr = &info_ctr;
|
---|
2541 | r.in.max_buffer = (uint32_t)-1;
|
---|
2542 | r.in.resume_handle = NULL;
|
---|
2543 | r.out.totalentries = &totalentries;
|
---|
2544 | r.out.info_ctr = &info_ctr;
|
---|
2545 |
|
---|
2546 | torture_assert_ntstatus_ok(tctx,
|
---|
2547 | dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
|
---|
2548 | "NetShareEnum level 1 failed");
|
---|
2549 | torture_assert_werr_ok(tctx, r.out.result,
|
---|
2550 | "NetShareEnum level 1 failed");
|
---|
2551 |
|
---|
2552 | *printers = NULL;
|
---|
2553 | *num_printers = 0;
|
---|
2554 | c1 = r.out.info_ctr->ctr.ctr1;
|
---|
2555 | for (i=0; i<c1->count; i++) {
|
---|
2556 | if (c1->array[i].type != STYPE_PRINTQ) {
|
---|
2557 | continue;
|
---|
2558 | }
|
---|
2559 | if (!add_string_to_array(tctx, c1->array[i].name,
|
---|
2560 | printers, num_printers)) {
|
---|
2561 | return false;
|
---|
2562 | }
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 | return true;
|
---|
2566 | }
|
---|
2567 |
|
---|
2568 | static bool enumprinters(struct torture_context *tctx,
|
---|
2569 | struct dcerpc_binding_handle *b,
|
---|
2570 | const char *servername, int level, int *num_printers)
|
---|
2571 | {
|
---|
2572 | struct spoolss_EnumPrinters r;
|
---|
2573 | DATA_BLOB blob;
|
---|
2574 | uint32_t needed;
|
---|
2575 | uint32_t count;
|
---|
2576 | union spoolss_PrinterInfo *info;
|
---|
2577 |
|
---|
2578 | r.in.flags = PRINTER_ENUM_LOCAL;
|
---|
2579 | r.in.server = talloc_asprintf(tctx, "\\\\%s", servername);
|
---|
2580 | r.in.level = level;
|
---|
2581 | r.in.buffer = NULL;
|
---|
2582 | r.in.offered = 0;
|
---|
2583 | r.out.needed = &needed;
|
---|
2584 | r.out.count = &count;
|
---|
2585 | r.out.info = &info;
|
---|
2586 |
|
---|
2587 | torture_assert_ntstatus_ok(tctx,
|
---|
2588 | dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
|
---|
2589 | "dcerpc_spoolss_EnumPrinters failed");
|
---|
2590 | torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
|
---|
2591 | "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
|
---|
2592 |
|
---|
2593 | blob = data_blob_talloc_zero(tctx, needed);
|
---|
2594 | if (blob.data == NULL) {
|
---|
2595 | return false;
|
---|
2596 | }
|
---|
2597 |
|
---|
2598 | r.in.buffer = &blob;
|
---|
2599 | r.in.offered = needed;
|
---|
2600 |
|
---|
2601 | torture_assert_ntstatus_ok(tctx,
|
---|
2602 | dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
|
---|
2603 | "dcerpc_spoolss_EnumPrinters failed");
|
---|
2604 | torture_assert_werr_ok(tctx, r.out.result,
|
---|
2605 | "dcerpc_spoolss_EnumPrinters failed");
|
---|
2606 |
|
---|
2607 | *num_printers = count;
|
---|
2608 |
|
---|
2609 | return true;
|
---|
2610 | }
|
---|
2611 |
|
---|
2612 | static bool getprinterinfo(struct torture_context *tctx,
|
---|
2613 | struct dcerpc_binding_handle *b,
|
---|
2614 | struct policy_handle *handle, int level,
|
---|
2615 | union spoolss_PrinterInfo **res)
|
---|
2616 | {
|
---|
2617 | struct spoolss_GetPrinter r;
|
---|
2618 | DATA_BLOB blob;
|
---|
2619 | uint32_t needed;
|
---|
2620 |
|
---|
2621 | r.in.handle = handle;
|
---|
2622 | r.in.level = level;
|
---|
2623 | r.in.buffer = NULL;
|
---|
2624 | r.in.offered = 0;
|
---|
2625 | r.out.needed = &needed;
|
---|
2626 |
|
---|
2627 | torture_assert_ntstatus_ok(tctx,
|
---|
2628 | dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
|
---|
2629 | "dcerpc_spoolss_GetPrinter failed");
|
---|
2630 | torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
|
---|
2631 | "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
|
---|
2632 |
|
---|
2633 | r.in.handle = handle;
|
---|
2634 | r.in.level = level;
|
---|
2635 | blob = data_blob_talloc_zero(tctx, needed);
|
---|
2636 | if (blob.data == NULL) {
|
---|
2637 | return false;
|
---|
2638 | }
|
---|
2639 | r.in.buffer = &blob;
|
---|
2640 | r.in.offered = needed;
|
---|
2641 |
|
---|
2642 | torture_assert_ntstatus_ok(tctx,
|
---|
2643 | dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
|
---|
2644 | "dcerpc_spoolss_GetPrinter failed");
|
---|
2645 | torture_assert_werr_ok(tctx, r.out.result,
|
---|
2646 | "dcerpc_spoolss_GetPrinter failed");
|
---|
2647 |
|
---|
2648 | if (res != NULL) {
|
---|
2649 | *res = talloc_steal(tctx, r.out.info);
|
---|
2650 | }
|
---|
2651 |
|
---|
2652 | return true;
|
---|
2653 | }
|
---|
2654 |
|
---|
2655 | static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
|
---|
2656 | {
|
---|
2657 | struct dcerpc_pipe *p, *p2;
|
---|
2658 | struct dcerpc_binding_handle *b;
|
---|
2659 | struct policy_handle server_handle, printer_handle;
|
---|
2660 | const char **printers;
|
---|
2661 | int num_printers;
|
---|
2662 | struct spoolss_UserLevel1 userlevel1;
|
---|
2663 | char *servername;
|
---|
2664 |
|
---|
2665 | torture_assert(torture,
|
---|
2666 | rap_get_servername(torture, &servername),
|
---|
2667 | "failed to rap servername");
|
---|
2668 |
|
---|
2669 | torture_assert_ntstatus_ok(torture,
|
---|
2670 | torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
|
---|
2671 | "failed to setup srvsvc");
|
---|
2672 |
|
---|
2673 | torture_assert(torture,
|
---|
2674 | find_printers(torture, p2, &printers, &num_printers),
|
---|
2675 | "failed to find printers via srvsvc");
|
---|
2676 |
|
---|
2677 | talloc_free(p2);
|
---|
2678 |
|
---|
2679 | if (num_printers == 0) {
|
---|
2680 | torture_skip(torture, "Did not find printers\n");
|
---|
2681 | return true;
|
---|
2682 | }
|
---|
2683 |
|
---|
2684 | torture_assert_ntstatus_ok(torture,
|
---|
2685 | torture_rpc_connection(torture, &p, &ndr_table_spoolss),
|
---|
2686 | "failed to setup spoolss");
|
---|
2687 |
|
---|
2688 | b = p->binding_handle;
|
---|
2689 |
|
---|
2690 | ZERO_STRUCT(userlevel1);
|
---|
2691 | userlevel1.client = talloc_asprintf(
|
---|
2692 | torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
|
---|
2693 | userlevel1.user = cli_credentials_get_username(cmdline_credentials);
|
---|
2694 | userlevel1.build = 2600;
|
---|
2695 | userlevel1.major = 3;
|
---|
2696 | userlevel1.minor = 0;
|
---|
2697 | userlevel1.processor = 0;
|
---|
2698 |
|
---|
2699 | {
|
---|
2700 | struct spoolss_OpenPrinterEx r;
|
---|
2701 |
|
---|
2702 | ZERO_STRUCT(r);
|
---|
2703 | r.in.printername = talloc_asprintf(torture, "\\\\%s",
|
---|
2704 | servername);
|
---|
2705 | r.in.datatype = NULL;
|
---|
2706 | r.in.access_mask = 0;
|
---|
2707 | r.in.level = 1;
|
---|
2708 | r.in.userlevel.level1 = &userlevel1;
|
---|
2709 | r.out.handle = &server_handle;
|
---|
2710 |
|
---|
2711 | torture_assert_ntstatus_ok(torture,
|
---|
2712 | dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
|
---|
2713 | "dcerpc_spoolss_OpenPrinterEx failed");
|
---|
2714 | torture_assert_werr_ok(torture, r.out.result,
|
---|
2715 | "dcerpc_spoolss_OpenPrinterEx failed");
|
---|
2716 | }
|
---|
2717 |
|
---|
2718 | {
|
---|
2719 | struct spoolss_ClosePrinter r;
|
---|
2720 |
|
---|
2721 | r.in.handle = &server_handle;
|
---|
2722 | r.out.handle = &server_handle;
|
---|
2723 |
|
---|
2724 | torture_assert_ntstatus_ok(torture,
|
---|
2725 | dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
|
---|
2726 | "dcerpc_spoolss_ClosePrinter failed");
|
---|
2727 | torture_assert_werr_ok(torture, r.out.result,
|
---|
2728 | "dcerpc_spoolss_ClosePrinter failed");
|
---|
2729 | }
|
---|
2730 |
|
---|
2731 | {
|
---|
2732 | struct spoolss_OpenPrinterEx r;
|
---|
2733 |
|
---|
2734 | ZERO_STRUCT(r);
|
---|
2735 | r.in.printername = talloc_asprintf(
|
---|
2736 | torture, "\\\\%s\\%s", servername, printers[0]);
|
---|
2737 | r.in.datatype = NULL;
|
---|
2738 | r.in.access_mask = 0;
|
---|
2739 | r.in.level = 1;
|
---|
2740 | r.in.userlevel.level1 = &userlevel1;
|
---|
2741 | r.out.handle = &printer_handle;
|
---|
2742 |
|
---|
2743 | torture_assert_ntstatus_ok(torture,
|
---|
2744 | dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
|
---|
2745 | "dcerpc_spoolss_OpenPrinterEx failed");
|
---|
2746 | torture_assert_werr_ok(torture, r.out.result,
|
---|
2747 | "dcerpc_spoolss_OpenPrinterEx failed");
|
---|
2748 | }
|
---|
2749 |
|
---|
2750 | {
|
---|
2751 | int i;
|
---|
2752 |
|
---|
2753 | for (i=0; i<8; i++) {
|
---|
2754 | torture_assert(torture,
|
---|
2755 | getprinterinfo(torture, b, &printer_handle, i, NULL),
|
---|
2756 | talloc_asprintf(torture, "getprinterinfo %d failed", i));
|
---|
2757 | }
|
---|
2758 | }
|
---|
2759 |
|
---|
2760 | {
|
---|
2761 | struct spoolss_ClosePrinter r;
|
---|
2762 |
|
---|
2763 | r.in.handle = &printer_handle;
|
---|
2764 | r.out.handle = &printer_handle;
|
---|
2765 |
|
---|
2766 | torture_assert_ntstatus_ok(torture,
|
---|
2767 | dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
|
---|
2768 | "dcerpc_spoolss_ClosePrinter failed");
|
---|
2769 | torture_assert_werr_ok(torture, r.out.result,
|
---|
2770 | "dcerpc_spoolss_ClosePrinter failed");
|
---|
2771 | }
|
---|
2772 |
|
---|
2773 | {
|
---|
2774 | int num_enumerated;
|
---|
2775 |
|
---|
2776 | torture_assert(torture,
|
---|
2777 | enumprinters(torture, b, servername, 1, &num_enumerated),
|
---|
2778 | "enumprinters failed");
|
---|
2779 |
|
---|
2780 | torture_assert_int_equal(torture, num_printers, num_enumerated,
|
---|
2781 | "netshareenum / enumprinters lvl 1 numprinter mismatch");
|
---|
2782 | }
|
---|
2783 |
|
---|
2784 | {
|
---|
2785 | int num_enumerated;
|
---|
2786 |
|
---|
2787 | torture_assert(torture,
|
---|
2788 | enumprinters(torture, b, servername, 2, &num_enumerated),
|
---|
2789 | "enumprinters failed");
|
---|
2790 |
|
---|
2791 | torture_assert_int_equal(torture, num_printers, num_enumerated,
|
---|
2792 | "netshareenum / enumprinters lvl 2 numprinter mismatch");
|
---|
2793 | }
|
---|
2794 |
|
---|
2795 | return true;
|
---|
2796 | }
|
---|
2797 |
|
---|
2798 | static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
|
---|
2799 | {
|
---|
2800 | struct dcerpc_pipe *p;
|
---|
2801 | struct dcerpc_binding_handle *b;
|
---|
2802 | char *servername;
|
---|
2803 |
|
---|
2804 | torture_assert(torture,
|
---|
2805 | rap_get_servername(torture, &servername),
|
---|
2806 | "failed to rap servername");
|
---|
2807 |
|
---|
2808 | torture_assert_ntstatus_ok(torture,
|
---|
2809 | torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
|
---|
2810 | "failed to setup wkssvc");
|
---|
2811 |
|
---|
2812 | b = p->binding_handle;
|
---|
2813 |
|
---|
2814 | {
|
---|
2815 | struct wkssvc_NetWkstaInfo100 wks100;
|
---|
2816 | union wkssvc_NetWkstaInfo info;
|
---|
2817 | struct wkssvc_NetWkstaGetInfo r;
|
---|
2818 |
|
---|
2819 | r.in.server_name = "\\foo";
|
---|
2820 | r.in.level = 100;
|
---|
2821 | info.info100 = &wks100;
|
---|
2822 | r.out.info = &info;
|
---|
2823 |
|
---|
2824 | torture_assert_ntstatus_ok(torture,
|
---|
2825 | dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
|
---|
2826 | "dcerpc_wkssvc_NetWksGetInfo failed");
|
---|
2827 | torture_assert_werr_ok(torture, r.out.result,
|
---|
2828 | "dcerpc_wkssvc_NetWksGetInfo failed");
|
---|
2829 |
|
---|
2830 | torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
|
---|
2831 | "servername RAP / DCERPC inconsistency");
|
---|
2832 | }
|
---|
2833 |
|
---|
2834 | return true;
|
---|
2835 | }
|
---|
2836 |
|
---|
2837 | static bool winreg_close(struct torture_context *tctx,
|
---|
2838 | struct dcerpc_binding_handle *b,
|
---|
2839 | struct policy_handle *handle)
|
---|
2840 | {
|
---|
2841 | struct winreg_CloseKey c;
|
---|
2842 |
|
---|
2843 | c.in.handle = c.out.handle = handle;
|
---|
2844 |
|
---|
2845 | torture_assert_ntstatus_ok(tctx,
|
---|
2846 | dcerpc_winreg_CloseKey_r(b, tctx, &c),
|
---|
2847 | "winreg_CloseKey failed");
|
---|
2848 | torture_assert_werr_ok(tctx, c.out.result,
|
---|
2849 | "winreg_CloseKey failed");
|
---|
2850 |
|
---|
2851 | return true;
|
---|
2852 | }
|
---|
2853 |
|
---|
2854 | static bool enumvalues(struct torture_context *tctx,
|
---|
2855 | struct dcerpc_binding_handle *b,
|
---|
2856 | struct policy_handle *handle)
|
---|
2857 | {
|
---|
2858 | uint32_t enum_index = 0;
|
---|
2859 |
|
---|
2860 | while (1) {
|
---|
2861 | struct winreg_EnumValue r;
|
---|
2862 | struct winreg_ValNameBuf name;
|
---|
2863 | enum winreg_Type type = 0;
|
---|
2864 | uint8_t buf8[1024];
|
---|
2865 | NTSTATUS status;
|
---|
2866 | uint32_t size, length;
|
---|
2867 |
|
---|
2868 | r.in.handle = handle;
|
---|
2869 | r.in.enum_index = enum_index;
|
---|
2870 | name.name = "";
|
---|
2871 | name.size = 1024;
|
---|
2872 | r.in.name = r.out.name = &name;
|
---|
2873 | size = 1024;
|
---|
2874 | length = 5;
|
---|
2875 | r.in.type = &type;
|
---|
2876 | r.in.value = buf8;
|
---|
2877 | r.in.size = &size;
|
---|
2878 | r.in.length = &length;
|
---|
2879 |
|
---|
2880 | status = dcerpc_winreg_EnumValue_r(b, tctx, &r);
|
---|
2881 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
|
---|
2882 | return true;
|
---|
2883 | }
|
---|
2884 | enum_index += 1;
|
---|
2885 | }
|
---|
2886 | }
|
---|
2887 |
|
---|
2888 | static bool enumkeys(struct torture_context *tctx,
|
---|
2889 | struct dcerpc_binding_handle *b,
|
---|
2890 | struct policy_handle *handle,
|
---|
2891 | int depth)
|
---|
2892 | {
|
---|
2893 | struct winreg_EnumKey r;
|
---|
2894 | struct winreg_StringBuf kclass, name;
|
---|
2895 | NTSTATUS status;
|
---|
2896 | NTTIME t = 0;
|
---|
2897 |
|
---|
2898 | if (depth <= 0) {
|
---|
2899 | return true;
|
---|
2900 | }
|
---|
2901 |
|
---|
2902 | kclass.name = "";
|
---|
2903 | kclass.size = 1024;
|
---|
2904 |
|
---|
2905 | r.in.handle = handle;
|
---|
2906 | r.in.enum_index = 0;
|
---|
2907 | r.in.name = &name;
|
---|
2908 | r.in.keyclass = &kclass;
|
---|
2909 | r.out.name = &name;
|
---|
2910 | r.in.last_changed_time = &t;
|
---|
2911 |
|
---|
2912 | do {
|
---|
2913 | struct winreg_OpenKey o;
|
---|
2914 | struct policy_handle key_handle;
|
---|
2915 | int i;
|
---|
2916 |
|
---|
2917 | name.name = NULL;
|
---|
2918 | name.size = 1024;
|
---|
2919 |
|
---|
2920 | status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
|
---|
2921 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
|
---|
2922 | /* We're done enumerating */
|
---|
2923 | return true;
|
---|
2924 | }
|
---|
2925 |
|
---|
2926 | for (i=0; i<10-depth; i++) {
|
---|
2927 | torture_comment(tctx, " ");
|
---|
2928 | }
|
---|
2929 | torture_comment(tctx, "%s\n", r.out.name->name);
|
---|
2930 |
|
---|
2931 | o.in.parent_handle = handle;
|
---|
2932 | o.in.keyname.name = r.out.name->name;
|
---|
2933 | o.in.options = 0;
|
---|
2934 | o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
2935 | o.out.handle = &key_handle;
|
---|
2936 |
|
---|
2937 | status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
|
---|
2938 | if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
|
---|
2939 | enumkeys(tctx, b, &key_handle, depth-1);
|
---|
2940 | enumvalues(tctx, b, &key_handle);
|
---|
2941 | torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
|
---|
2942 | }
|
---|
2943 |
|
---|
2944 | r.in.enum_index += 1;
|
---|
2945 | } while(true);
|
---|
2946 |
|
---|
2947 | return true;
|
---|
2948 | }
|
---|
2949 |
|
---|
2950 | typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
|
---|
2951 |
|
---|
2952 | static bool test_Open3(struct torture_context *tctx,
|
---|
2953 | struct dcerpc_binding_handle *b,
|
---|
2954 | const char *name, winreg_open_fn open_fn)
|
---|
2955 | {
|
---|
2956 | struct policy_handle handle;
|
---|
2957 | struct winreg_OpenHKLM r;
|
---|
2958 |
|
---|
2959 | r.in.system_name = 0;
|
---|
2960 | r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
2961 | r.out.handle = &handle;
|
---|
2962 |
|
---|
2963 | torture_assert_ntstatus_ok(tctx,
|
---|
2964 | open_fn(b, tctx, &r),
|
---|
2965 | talloc_asprintf(tctx, "%s failed", name));
|
---|
2966 | torture_assert_werr_ok(tctx, r.out.result,
|
---|
2967 | talloc_asprintf(tctx, "%s failed", name));
|
---|
2968 |
|
---|
2969 | enumkeys(tctx, b, &handle, 4);
|
---|
2970 |
|
---|
2971 | torture_assert(tctx,
|
---|
2972 | winreg_close(tctx, b, &handle),
|
---|
2973 | "dcerpc_CloseKey failed");
|
---|
2974 |
|
---|
2975 | return true;
|
---|
2976 | }
|
---|
2977 |
|
---|
2978 | static bool torture_samba3_rpc_winreg(struct torture_context *torture)
|
---|
2979 | {
|
---|
2980 | struct dcerpc_pipe *p;
|
---|
2981 | struct dcerpc_binding_handle *b;
|
---|
2982 | bool ret = true;
|
---|
2983 | struct {
|
---|
2984 | const char *name;
|
---|
2985 | winreg_open_fn fn;
|
---|
2986 | } open_fns[] = {
|
---|
2987 | {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
|
---|
2988 | {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
|
---|
2989 | {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
|
---|
2990 | {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
|
---|
2991 | {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
|
---|
2992 | #if 0
|
---|
2993 | int i;
|
---|
2994 | #endif
|
---|
2995 |
|
---|
2996 | torture_assert_ntstatus_ok(torture,
|
---|
2997 | torture_rpc_connection(torture, &p, &ndr_table_winreg),
|
---|
2998 | "failed to setup winreg");
|
---|
2999 |
|
---|
3000 | b = p->binding_handle;
|
---|
3001 |
|
---|
3002 | #if 1
|
---|
3003 | ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
|
---|
3004 | #else
|
---|
3005 | for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
|
---|
3006 | if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
|
---|
3007 | ret = false;
|
---|
3008 | }
|
---|
3009 | #endif
|
---|
3010 | return ret;
|
---|
3011 | }
|
---|
3012 |
|
---|
3013 | static bool get_shareinfo(struct torture_context *tctx,
|
---|
3014 | struct dcerpc_binding_handle *b,
|
---|
3015 | const char *servername,
|
---|
3016 | const char *share,
|
---|
3017 | struct srvsvc_NetShareInfo502 **info502)
|
---|
3018 | {
|
---|
3019 | struct srvsvc_NetShareGetInfo r;
|
---|
3020 | union srvsvc_NetShareInfo info;
|
---|
3021 |
|
---|
3022 | r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
|
---|
3023 | r.in.share_name = share;
|
---|
3024 | r.in.level = 502;
|
---|
3025 | r.out.info = &info;
|
---|
3026 |
|
---|
3027 | torture_assert_ntstatus_ok(tctx,
|
---|
3028 | dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
|
---|
3029 | "srvsvc_NetShareGetInfo failed");
|
---|
3030 | torture_assert_werr_ok(tctx, r.out.result,
|
---|
3031 | "srvsvc_NetShareGetInfo failed");
|
---|
3032 |
|
---|
3033 | *info502 = talloc_move(tctx, &info.info502);
|
---|
3034 |
|
---|
3035 | return true;
|
---|
3036 | }
|
---|
3037 |
|
---|
3038 | /*
|
---|
3039 | * Get us a handle on HKLM\
|
---|
3040 | */
|
---|
3041 |
|
---|
3042 | static bool get_hklm_handle(struct torture_context *tctx,
|
---|
3043 | struct dcerpc_binding_handle *b,
|
---|
3044 | struct policy_handle *handle)
|
---|
3045 | {
|
---|
3046 | struct winreg_OpenHKLM r;
|
---|
3047 | struct policy_handle result;
|
---|
3048 |
|
---|
3049 | r.in.system_name = 0;
|
---|
3050 | r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
3051 | r.out.handle = &result;
|
---|
3052 |
|
---|
3053 | torture_assert_ntstatus_ok(tctx,
|
---|
3054 | dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
|
---|
3055 | "OpenHKLM failed");
|
---|
3056 | torture_assert_werr_ok(tctx, r.out.result,
|
---|
3057 | "OpenHKLM failed");
|
---|
3058 |
|
---|
3059 | *handle = result;
|
---|
3060 |
|
---|
3061 | return true;
|
---|
3062 | }
|
---|
3063 |
|
---|
3064 | static bool torture_samba3_createshare(struct torture_context *tctx,
|
---|
3065 | struct dcerpc_binding_handle *b,
|
---|
3066 | const char *sharename)
|
---|
3067 | {
|
---|
3068 | struct policy_handle hklm;
|
---|
3069 | struct policy_handle new_handle;
|
---|
3070 | struct winreg_CreateKey c;
|
---|
3071 | struct winreg_CloseKey cl;
|
---|
3072 | enum winreg_CreateAction action_taken;
|
---|
3073 |
|
---|
3074 | c.in.handle = &hklm;
|
---|
3075 | c.in.name.name = talloc_asprintf(
|
---|
3076 | tctx, "software\\samba\\smbconf\\%s", sharename);
|
---|
3077 | torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
|
---|
3078 |
|
---|
3079 | c.in.keyclass.name = "";
|
---|
3080 | c.in.options = 0;
|
---|
3081 | c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
3082 | c.in.secdesc = NULL;
|
---|
3083 | c.in.action_taken = &action_taken;
|
---|
3084 | c.out.new_handle = &new_handle;
|
---|
3085 | c.out.action_taken = &action_taken;
|
---|
3086 |
|
---|
3087 | torture_assert_ntstatus_ok(tctx,
|
---|
3088 | dcerpc_winreg_CreateKey_r(b, tctx, &c),
|
---|
3089 | "OpenKey failed");
|
---|
3090 | torture_assert_werr_ok(tctx, c.out.result,
|
---|
3091 | "OpenKey failed");
|
---|
3092 |
|
---|
3093 | cl.in.handle = &new_handle;
|
---|
3094 | cl.out.handle = &new_handle;
|
---|
3095 |
|
---|
3096 | torture_assert_ntstatus_ok(tctx,
|
---|
3097 | dcerpc_winreg_CloseKey_r(b, tctx, &cl),
|
---|
3098 | "CloseKey failed");
|
---|
3099 | torture_assert_werr_ok(tctx, cl.out.result,
|
---|
3100 | "CloseKey failed");
|
---|
3101 |
|
---|
3102 | return true;
|
---|
3103 | }
|
---|
3104 |
|
---|
3105 | static bool torture_samba3_deleteshare(struct torture_context *tctx,
|
---|
3106 | struct dcerpc_binding_handle *b,
|
---|
3107 | const char *sharename)
|
---|
3108 | {
|
---|
3109 | struct policy_handle hklm;
|
---|
3110 | struct winreg_DeleteKey d;
|
---|
3111 |
|
---|
3112 | torture_assert(tctx,
|
---|
3113 | get_hklm_handle(tctx, b, &hklm),
|
---|
3114 | "get_hklm_handle failed");
|
---|
3115 |
|
---|
3116 | d.in.handle = &hklm;
|
---|
3117 | d.in.key.name = talloc_asprintf(
|
---|
3118 | tctx, "software\\samba\\smbconf\\%s", sharename);
|
---|
3119 | torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
|
---|
3120 |
|
---|
3121 | torture_assert_ntstatus_ok(tctx,
|
---|
3122 | dcerpc_winreg_DeleteKey_r(b, tctx, &d),
|
---|
3123 | "DeleteKey failed");
|
---|
3124 | torture_assert_werr_ok(tctx, d.out.result,
|
---|
3125 | "DeleteKey failed");
|
---|
3126 |
|
---|
3127 | return true;
|
---|
3128 | }
|
---|
3129 |
|
---|
3130 | static bool torture_samba3_setconfig(struct torture_context *tctx,
|
---|
3131 | struct dcerpc_binding_handle *b,
|
---|
3132 | const char *sharename,
|
---|
3133 | const char *parameter,
|
---|
3134 | const char *value)
|
---|
3135 | {
|
---|
3136 | struct policy_handle hklm, key_handle;
|
---|
3137 | struct winreg_OpenKey o;
|
---|
3138 | struct winreg_SetValue s;
|
---|
3139 | uint32_t type;
|
---|
3140 | DATA_BLOB val;
|
---|
3141 |
|
---|
3142 | torture_assert(tctx,
|
---|
3143 | get_hklm_handle(tctx, b, &hklm),
|
---|
3144 | "get_hklm_handle failed");
|
---|
3145 |
|
---|
3146 | o.in.parent_handle = &hklm;
|
---|
3147 | o.in.keyname.name = talloc_asprintf(
|
---|
3148 | tctx, "software\\samba\\smbconf\\%s", sharename);
|
---|
3149 | torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
|
---|
3150 |
|
---|
3151 | o.in.options = 0;
|
---|
3152 | o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
|
---|
3153 | o.out.handle = &key_handle;
|
---|
3154 |
|
---|
3155 | torture_assert_ntstatus_ok(tctx,
|
---|
3156 | dcerpc_winreg_OpenKey_r(b, tctx, &o),
|
---|
3157 | "OpenKey failed");
|
---|
3158 | torture_assert_werr_ok(tctx, o.out.result,
|
---|
3159 | "OpenKey failed");
|
---|
3160 |
|
---|
3161 | torture_assert(tctx,
|
---|
3162 | reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
|
---|
3163 | "reg_string_to_val failed");
|
---|
3164 |
|
---|
3165 | s.in.handle = &key_handle;
|
---|
3166 | s.in.name.name = parameter;
|
---|
3167 | s.in.type = type;
|
---|
3168 | s.in.data = val.data;
|
---|
3169 | s.in.size = val.length;
|
---|
3170 |
|
---|
3171 | torture_assert_ntstatus_ok(tctx,
|
---|
3172 | dcerpc_winreg_SetValue_r(b, tctx, &s),
|
---|
3173 | "SetValue failed");
|
---|
3174 | torture_assert_werr_ok(tctx, s.out.result,
|
---|
3175 | "SetValue failed");
|
---|
3176 |
|
---|
3177 | return true;
|
---|
3178 | }
|
---|
3179 |
|
---|
3180 | static bool torture_samba3_regconfig(struct torture_context *torture)
|
---|
3181 | {
|
---|
3182 | struct srvsvc_NetShareInfo502 *i = NULL;
|
---|
3183 | const char *comment = "Dummer Kommentar";
|
---|
3184 | struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
|
---|
3185 |
|
---|
3186 | torture_assert_ntstatus_ok(torture,
|
---|
3187 | torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
|
---|
3188 | "failed to setup srvsvc");
|
---|
3189 |
|
---|
3190 | torture_assert_ntstatus_ok(torture,
|
---|
3191 | torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
|
---|
3192 | "failed to setup winreg");
|
---|
3193 |
|
---|
3194 | torture_assert(torture,
|
---|
3195 | torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
|
---|
3196 | "torture_samba3_createshare failed");
|
---|
3197 |
|
---|
3198 | torture_assert(torture,
|
---|
3199 | torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
|
---|
3200 | "torture_samba3_setconfig failed");
|
---|
3201 |
|
---|
3202 | torture_assert(torture,
|
---|
3203 | get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
|
---|
3204 | "get_shareinfo failed");
|
---|
3205 |
|
---|
3206 | torture_assert_str_equal(torture, comment, i->comment,
|
---|
3207 | "got unexpected comment");
|
---|
3208 |
|
---|
3209 | torture_assert(torture,
|
---|
3210 | torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
|
---|
3211 | "torture_samba3_deleteshare failed");
|
---|
3212 |
|
---|
3213 | return true;
|
---|
3214 | }
|
---|
3215 |
|
---|
3216 | /*
|
---|
3217 | * Test that even with a result of 0 rids the array is returned as a
|
---|
3218 | * non-NULL pointer. Yes, XP does notice.
|
---|
3219 | */
|
---|
3220 |
|
---|
3221 | bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
|
---|
3222 | {
|
---|
3223 | struct dcerpc_pipe *p;
|
---|
3224 | struct dcerpc_binding_handle *b;
|
---|
3225 | struct samr_Connect2 c;
|
---|
3226 | struct samr_OpenDomain o;
|
---|
3227 | struct dom_sid sid;
|
---|
3228 | struct lsa_SidPtr ptr;
|
---|
3229 | struct lsa_SidArray sids;
|
---|
3230 | struct samr_GetAliasMembership g;
|
---|
3231 | struct samr_Ids rids;
|
---|
3232 | struct policy_handle samr, domain;
|
---|
3233 |
|
---|
3234 | torture_assert_ntstatus_ok(torture,
|
---|
3235 | torture_rpc_connection(torture, &p, &ndr_table_samr),
|
---|
3236 | "failed to setup samr");
|
---|
3237 |
|
---|
3238 | b = p->binding_handle;
|
---|
3239 |
|
---|
3240 | c.in.system_name = NULL;
|
---|
3241 | c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
|
---|
3242 | c.out.connect_handle = &samr;
|
---|
3243 | torture_assert_ntstatus_ok(torture,
|
---|
3244 | dcerpc_samr_Connect2_r(b, torture, &c),
|
---|
3245 | "");
|
---|
3246 | torture_assert_ntstatus_ok(torture, c.out.result,
|
---|
3247 | "");
|
---|
3248 | dom_sid_parse("S-1-5-32", &sid);
|
---|
3249 | o.in.connect_handle = &samr;
|
---|
3250 | o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
|
---|
3251 | o.in.sid = &sid;
|
---|
3252 | o.out.domain_handle = &domain;
|
---|
3253 | torture_assert_ntstatus_ok(torture,
|
---|
3254 | dcerpc_samr_OpenDomain_r(b, torture, &o),
|
---|
3255 | "");
|
---|
3256 | torture_assert_ntstatus_ok(torture, o.out.result,
|
---|
3257 | "");
|
---|
3258 | dom_sid_parse("S-1-2-3-4-5", &sid);
|
---|
3259 | ptr.sid = &sid;
|
---|
3260 | sids.num_sids = 1;
|
---|
3261 | sids.sids = &ptr;
|
---|
3262 | g.in.domain_handle = &domain;
|
---|
3263 | g.in.sids = &sids;
|
---|
3264 | g.out.rids = &rids;
|
---|
3265 | torture_assert_ntstatus_ok(torture,
|
---|
3266 | dcerpc_samr_GetAliasMembership_r(b, torture, &g),
|
---|
3267 | "");
|
---|
3268 | torture_assert_ntstatus_ok(torture, g.out.result,
|
---|
3269 | "");
|
---|
3270 | if (rids.ids == NULL) {
|
---|
3271 | /* This is the piece to test here */
|
---|
3272 | torture_fail(torture,
|
---|
3273 | "torture_samba3_getaliasmembership_0: "
|
---|
3274 | "Server returns NULL rids array\n");
|
---|
3275 | }
|
---|
3276 |
|
---|
3277 | return true;
|
---|
3278 | }
|
---|
3279 |
|
---|
3280 | struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
|
---|
3281 | {
|
---|
3282 | struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
|
---|
3283 |
|
---|
3284 | torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
|
---|
3285 | torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
|
---|
3286 | torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
|
---|
3287 | torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
|
---|
3288 | torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
|
---|
3289 | torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
|
---|
3290 | torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
|
---|
3291 | torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
|
---|
3292 | torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
|
---|
3293 | torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
|
---|
3294 | torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
|
---|
3295 | torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
|
---|
3296 | torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
|
---|
3297 |
|
---|
3298 | suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");
|
---|
3299 |
|
---|
3300 | return suite;
|
---|
3301 | }
|
---|