| 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 "librpc/gen_ndr/ndr_svcctl_c.h" |
| 35 |
#include "lib/cmdline/cmdline.h" |
| 36 |
#include "torture/rpc/torture_rpc.h" |
| 37 |
#include "libcli/libcli.h" |
| 38 |
#include "libcli/smb_composite/smb_composite.h" |
| 39 |
#include "libcli/auth/libcli_auth.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 |
#include "libcli/smb2/smb2.h" |
| 46 |
#include "libcli/smb2/smb2_calls.h" |
| 47 |
#include "librpc/rpc/dcerpc.h" |
| 48 |
#include "librpc/rpc/dcerpc_proto.h" |
| 49 |
#include "libcli/smb/smbXcli_base.h" |
| 50 |
#include "source3/rpc_client/init_samr.h" |
| 51 |
|
| 52 |
/* |
| 53 |
* open pipe and bind, given an IPC$ context |
| 54 |
*/ |
| 55 |
|
| 56 |
static NTSTATUS pipe_bind_smb(struct torture_context *tctx, |
| 57 |
TALLOC_CTX *mem_ctx, |
| 58 |
struct smbcli_tree *tree, |
| 59 |
const char *pipe_name, |
| 60 |
const struct ndr_interface_table *iface, |
| 61 |
struct dcerpc_pipe **p) |
| 62 |
{ |
| 63 |
struct dcerpc_pipe *result; |
| 64 |
NTSTATUS status; |
| 65 |
|
| 66 |
if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) { |
| 67 |
return NT_STATUS_NO_MEMORY; |
| 68 |
} |
| 69 |
|
| 70 |
status = dcerpc_pipe_open_smb(result, tree, pipe_name); |
| 71 |
if (!NT_STATUS_IS_OK(status)) { |
| 72 |
torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n", |
| 73 |
nt_errstr(status)); |
| 74 |
talloc_free(result); |
| 75 |
return status; |
| 76 |
} |
| 77 |
|
| 78 |
status = dcerpc_bind_auth_none(result, iface); |
| 79 |
if (!NT_STATUS_IS_OK(status)) { |
| 80 |
torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n", nt_errstr(status)); |
| 81 |
talloc_free(result); |
| 82 |
return status; |
| 83 |
} |
| 84 |
|
| 85 |
*p = result; |
| 86 |
return NT_STATUS_OK; |
| 87 |
} |
| 88 |
|
| 89 |
static NTSTATUS pipe_bind_smb2(struct torture_context *tctx, |
| 90 |
TALLOC_CTX *mem_ctx, |
| 91 |
struct smb2_tree *tree, |
| 92 |
const char *pipe_name, |
| 93 |
const struct ndr_interface_table *iface, |
| 94 |
struct dcerpc_pipe **p) |
| 95 |
{ |
| 96 |
struct dcerpc_pipe *result; |
| 97 |
NTSTATUS status; |
| 98 |
|
| 99 |
if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) { |
| 100 |
return NT_STATUS_NO_MEMORY; |
| 101 |
} |
| 102 |
|
| 103 |
status = dcerpc_pipe_open_smb2(result, tree, pipe_name); |
| 104 |
if (!NT_STATUS_IS_OK(status)) { |
| 105 |
torture_comment(tctx, "dcerpc_pipe_open_smb2 failed: %s\n", |
| 106 |
nt_errstr(status)); |
| 107 |
talloc_free(result); |
| 108 |
return status; |
| 109 |
} |
| 110 |
|
| 111 |
status = dcerpc_bind_auth_none(result, iface); |
| 112 |
if (!NT_STATUS_IS_OK(status)) { |
| 113 |
torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n", nt_errstr(status)); |
| 114 |
talloc_free(result); |
| 115 |
return status; |
| 116 |
} |
| 117 |
|
| 118 |
*p = result; |
| 119 |
return NT_STATUS_OK; |
| 120 |
} |
| 121 |
|
| 122 |
static NTSTATUS pipe_bind_smb_auth(struct torture_context *tctx, |
| 123 |
TALLOC_CTX *mem_ctx, |
| 124 |
struct smbcli_tree *tree, |
| 125 |
struct cli_credentials *creds, |
| 126 |
uint8_t auth_type, |
| 127 |
uint8_t auth_level, |
| 128 |
const char *pipe_name, |
| 129 |
const struct ndr_interface_table *iface, |
| 130 |
struct dcerpc_pipe **p) |
| 131 |
{ |
| 132 |
struct dcerpc_pipe *result; |
| 133 |
NTSTATUS status; |
| 134 |
|
| 135 |
if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) { |
| 136 |
return NT_STATUS_NO_MEMORY; |
| 137 |
} |
| 138 |
|
| 139 |
status = dcerpc_pipe_open_smb(result, tree, pipe_name); |
| 140 |
if (!NT_STATUS_IS_OK(status)) { |
| 141 |
torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n", |
| 142 |
nt_errstr(status)); |
| 143 |
talloc_free(result); |
| 144 |
return status; |
| 145 |
} |
| 146 |
|
| 147 |
status = dcerpc_bind_auth(result, iface, creds, |
| 148 |
lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), |
| 149 |
auth_type, auth_level, NULL); |
| 150 |
if (!NT_STATUS_IS_OK(status)) { |
| 151 |
torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status)); |
| 152 |
talloc_free(result); |
| 153 |
return status; |
| 154 |
} |
| 155 |
|
| 156 |
*p = result; |
| 157 |
return NT_STATUS_OK; |
| 158 |
} |
| 159 |
|
| 160 |
/* |
| 161 |
* This tests a RPC call using an invalid vuid |
| 162 |
*/ |
| 163 |
|
| 164 |
bool torture_bind_authcontext(struct torture_context *torture) |
| 165 |
{ |
| 166 |
TALLOC_CTX *mem_ctx; |
| 167 |
NTSTATUS status; |
| 168 |
bool ret = false; |
| 169 |
struct lsa_ObjectAttribute objectattr; |
| 170 |
struct lsa_OpenPolicy2 openpolicy; |
| 171 |
struct policy_handle handle; |
| 172 |
struct lsa_Close close_handle; |
| 173 |
struct smbcli_session *tmp; |
| 174 |
uint16_t tmp_vuid; |
| 175 |
struct smbcli_session *session2; |
| 176 |
struct smbcli_state *cli; |
| 177 |
struct dcerpc_pipe *lsa_pipe; |
| 178 |
struct dcerpc_binding_handle *lsa_handle; |
| 179 |
struct cli_credentials *anon_creds; |
| 180 |
struct smb_composite_sesssetup setup; |
| 181 |
struct smbcli_options options; |
| 182 |
struct smbcli_session_options session_options; |
| 183 |
|
| 184 |
mem_ctx = talloc_init("torture_bind_authcontext"); |
| 185 |
|
| 186 |
if (mem_ctx == NULL) { |
| 187 |
torture_comment(torture, "talloc_init failed\n"); |
| 188 |
return false; |
| 189 |
} |
| 190 |
|
| 191 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 192 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 193 |
|
| 194 |
status = smbcli_full_connection(mem_ctx, &cli, |
| 195 |
torture_setting_string(torture, "host", NULL), |
| 196 |
"IPC$", NULL, |
| 197 |
lpcfg_socket_options(torture->lp_ctx), |
| 198 |
samba_cmdline_get_creds(), |
| 199 |
torture->lp_ctx, |
| 200 |
lpcfg_resolve_context(torture->lp_ctx), |
| 201 |
torture->ev, &options, &session_options, |
| 202 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 203 |
if (!NT_STATUS_IS_OK(status)) { |
| 204 |
torture_comment(torture, "smbcli_full_connection failed: %s\n", |
| 205 |
nt_errstr(status)); |
| 206 |
goto done; |
| 207 |
} |
| 208 |
|
| 209 |
status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\lsarpc", |
| 210 |
&ndr_table_lsarpc, &lsa_pipe); |
| 211 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 212 |
"pipe_bind_smb failed"); |
| 213 |
lsa_handle = lsa_pipe->binding_handle; |
| 214 |
|
| 215 |
openpolicy.in.system_name =talloc_asprintf( |
| 216 |
mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe)); |
| 217 |
ZERO_STRUCT(objectattr); |
| 218 |
openpolicy.in.attr = &objectattr; |
| 219 |
openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 220 |
openpolicy.out.handle = &handle; |
| 221 |
|
| 222 |
status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy); |
| 223 |
|
| 224 |
if (!NT_STATUS_IS_OK(status)) { |
| 225 |
torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n", |
| 226 |
nt_errstr(status)); |
| 227 |
goto done; |
| 228 |
} |
| 229 |
if (!NT_STATUS_IS_OK(openpolicy.out.result)) { |
| 230 |
torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n", |
| 231 |
nt_errstr(openpolicy.out.result)); |
| 232 |
goto done; |
| 233 |
} |
| 234 |
|
| 235 |
close_handle.in.handle = &handle; |
| 236 |
close_handle.out.handle = &handle; |
| 237 |
|
| 238 |
status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle); |
| 239 |
if (!NT_STATUS_IS_OK(status)) { |
| 240 |
torture_comment(torture, "dcerpc_lsa_Close failed: %s\n", |
| 241 |
nt_errstr(status)); |
| 242 |
goto done; |
| 243 |
} |
| 244 |
if (!NT_STATUS_IS_OK(close_handle.out.result)) { |
| 245 |
torture_comment(torture, "dcerpc_lsa_Close failed: %s\n", |
| 246 |
nt_errstr(close_handle.out.result)); |
| 247 |
goto done; |
| 248 |
} |
| 249 |
|
| 250 |
session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options); |
| 251 |
if (session2 == NULL) { |
| 252 |
torture_comment(torture, "smbcli_session_init failed\n"); |
| 253 |
goto done; |
| 254 |
} |
| 255 |
|
| 256 |
if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) { |
| 257 |
torture_comment(torture, "create_anon_creds failed\n"); |
| 258 |
goto done; |
| 259 |
} |
| 260 |
|
| 261 |
setup.in.sesskey = cli->transport->negotiate.sesskey; |
| 262 |
setup.in.capabilities = cli->transport->negotiate.capabilities; |
| 263 |
setup.in.workgroup = ""; |
| 264 |
setup.in.credentials = anon_creds; |
| 265 |
setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx); |
| 266 |
|
| 267 |
status = smb_composite_sesssetup(session2, &setup); |
| 268 |
if (!NT_STATUS_IS_OK(status)) { |
| 269 |
torture_comment(torture, "anon session setup failed: %s\n", |
| 270 |
nt_errstr(status)); |
| 271 |
goto done; |
| 272 |
} |
| 273 |
session2->vuid = setup.out.vuid; |
| 274 |
|
| 275 |
tmp = cli->tree->session; |
| 276 |
tmp_vuid = smb1cli_session_current_id(tmp->smbXcli); |
| 277 |
smb1cli_session_set_id(tmp->smbXcli, session2->vuid); |
| 278 |
cli->tree->session = session2; |
| 279 |
|
| 280 |
status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy); |
| 281 |
|
| 282 |
torture_assert(torture, smbXcli_conn_is_connected(cli->transport->conn), |
| 283 |
"smb still connected"); |
| 284 |
torture_assert(torture, !dcerpc_binding_handle_is_connected(lsa_handle), |
| 285 |
"dcerpc disconnected"); |
| 286 |
|
| 287 |
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) { |
| 288 |
torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, " |
| 289 |
"expected NT_STATUS_CONNECTION_DISCONNECTED\n", |
| 290 |
nt_errstr(status)); |
| 291 |
status = NT_STATUS_CONNECTION_DISCONNECTED; |
| 292 |
} |
| 293 |
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_DEVICE_ERROR)) { |
| 294 |
torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, " |
| 295 |
"expected NT_STATUS_CONNECTION_DISCONNECTED\n", |
| 296 |
nt_errstr(status)); |
| 297 |
status = NT_STATUS_CONNECTION_DISCONNECTED; |
| 298 |
} |
| 299 |
|
| 300 |
torture_assert_ntstatus_equal(torture, status, NT_STATUS_CONNECTION_DISCONNECTED, |
| 301 |
"lsa connection disconnected"); |
| 302 |
|
| 303 |
smb1cli_session_set_id(tmp->smbXcli, tmp_vuid); |
| 304 |
cli->tree->session = tmp; |
| 305 |
talloc_free(lsa_pipe); |
| 306 |
lsa_pipe = NULL; |
| 307 |
|
| 308 |
ret = true; |
| 309 |
done: |
| 310 |
talloc_free(mem_ctx); |
| 311 |
return ret; |
| 312 |
} |
| 313 |
|
| 314 |
/* |
| 315 |
* Bind to lsa using a specific auth method |
| 316 |
*/ |
| 317 |
|
| 318 |
static bool bindtest(struct torture_context *tctx, |
| 319 |
struct smbcli_state *cli, |
| 320 |
struct cli_credentials *credentials, |
| 321 |
uint8_t auth_type, uint8_t auth_level) |
| 322 |
{ |
| 323 |
TALLOC_CTX *mem_ctx; |
| 324 |
bool ret = false; |
| 325 |
NTSTATUS status; |
| 326 |
|
| 327 |
struct dcerpc_pipe *lsa_pipe; |
| 328 |
struct dcerpc_binding_handle *lsa_handle; |
| 329 |
struct lsa_ObjectAttribute objectattr; |
| 330 |
struct lsa_OpenPolicy2 openpolicy; |
| 331 |
struct lsa_QueryInfoPolicy query; |
| 332 |
union lsa_PolicyInformation *info = NULL; |
| 333 |
struct policy_handle handle; |
| 334 |
struct lsa_Close close_handle; |
| 335 |
|
| 336 |
if ((mem_ctx = talloc_init("bindtest")) == NULL) { |
| 337 |
torture_comment(tctx, "talloc_init failed\n"); |
| 338 |
return false; |
| 339 |
} |
| 340 |
|
| 341 |
status = pipe_bind_smb_auth(tctx, mem_ctx, cli->tree, |
| 342 |
credentials, auth_type, auth_level, |
| 343 |
"\\lsarpc", &ndr_table_lsarpc, &lsa_pipe); |
| 344 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 345 |
"pipe_bind_smb_auth failed"); |
| 346 |
lsa_handle = lsa_pipe->binding_handle; |
| 347 |
|
| 348 |
openpolicy.in.system_name =talloc_asprintf( |
| 349 |
mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe)); |
| 350 |
ZERO_STRUCT(objectattr); |
| 351 |
openpolicy.in.attr = &objectattr; |
| 352 |
openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 353 |
openpolicy.out.handle = &handle; |
| 354 |
|
| 355 |
status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy); |
| 356 |
|
| 357 |
if (!NT_STATUS_IS_OK(status)) { |
| 358 |
torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n", |
| 359 |
nt_errstr(status)); |
| 360 |
goto done; |
| 361 |
} |
| 362 |
if (!NT_STATUS_IS_OK(openpolicy.out.result)) { |
| 363 |
torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n", |
| 364 |
nt_errstr(openpolicy.out.result)); |
| 365 |
goto done; |
| 366 |
} |
| 367 |
|
| 368 |
query.in.handle = &handle; |
| 369 |
query.in.level = LSA_POLICY_INFO_DOMAIN; |
| 370 |
query.out.info = &info; |
| 371 |
|
| 372 |
status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query); |
| 373 |
if (!NT_STATUS_IS_OK(status)) { |
| 374 |
torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n", |
| 375 |
nt_errstr(status)); |
| 376 |
goto done; |
| 377 |
} |
| 378 |
if (!NT_STATUS_IS_OK(query.out.result)) { |
| 379 |
torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n", |
| 380 |
nt_errstr(query.out.result)); |
| 381 |
goto done; |
| 382 |
} |
| 383 |
|
| 384 |
close_handle.in.handle = &handle; |
| 385 |
close_handle.out.handle = &handle; |
| 386 |
|
| 387 |
status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle); |
| 388 |
if (!NT_STATUS_IS_OK(status)) { |
| 389 |
torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n", |
| 390 |
nt_errstr(status)); |
| 391 |
goto done; |
| 392 |
} |
| 393 |
if (!NT_STATUS_IS_OK(close_handle.out.result)) { |
| 394 |
torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n", |
| 395 |
nt_errstr(close_handle.out.result)); |
| 396 |
goto done; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
ret = true; |
| 401 |
done: |
| 402 |
talloc_free(mem_ctx); |
| 403 |
return ret; |
| 404 |
} |
| 405 |
|
| 406 |
/* |
| 407 |
* test authenticated RPC binds with the variants Samba3 does support |
| 408 |
*/ |
| 409 |
|
| 410 |
static bool torture_bind_samba3(struct torture_context *torture) |
| 411 |
{ |
| 412 |
TALLOC_CTX *mem_ctx; |
| 413 |
NTSTATUS status; |
| 414 |
bool ret = false; |
| 415 |
struct smbcli_state *cli; |
| 416 |
struct smbcli_options options; |
| 417 |
struct smbcli_session_options session_options; |
| 418 |
|
| 419 |
mem_ctx = talloc_init("torture_bind_authcontext"); |
| 420 |
|
| 421 |
if (mem_ctx == NULL) { |
| 422 |
torture_comment(torture, "talloc_init failed\n"); |
| 423 |
return false; |
| 424 |
} |
| 425 |
|
| 426 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 427 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 428 |
|
| 429 |
status = smbcli_full_connection(mem_ctx, &cli, |
| 430 |
torture_setting_string(torture, "host", NULL), |
| 431 |
"IPC$", NULL, |
| 432 |
lpcfg_socket_options(torture->lp_ctx), |
| 433 |
samba_cmdline_get_creds(), |
| 434 |
torture->lp_ctx, |
| 435 |
lpcfg_resolve_context(torture->lp_ctx), |
| 436 |
torture->ev, &options, &session_options, |
| 437 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 438 |
if (!NT_STATUS_IS_OK(status)) { |
| 439 |
torture_comment(torture, "smbcli_full_connection failed: %s\n", |
| 440 |
nt_errstr(status)); |
| 441 |
goto done; |
| 442 |
} |
| 443 |
|
| 444 |
ret = true; |
| 445 |
|
| 446 |
ret &= bindtest(torture, cli, samba_cmdline_get_creds(), |
| 447 |
DCERPC_AUTH_TYPE_NTLMSSP, |
| 448 |
DCERPC_AUTH_LEVEL_INTEGRITY); |
| 449 |
ret &= bindtest(torture, cli, samba_cmdline_get_creds(), |
| 450 |
DCERPC_AUTH_TYPE_NTLMSSP, |
| 451 |
DCERPC_AUTH_LEVEL_PRIVACY); |
| 452 |
ret &= bindtest(torture, cli, samba_cmdline_get_creds(), |
| 453 |
DCERPC_AUTH_TYPE_SPNEGO, |
| 454 |
DCERPC_AUTH_LEVEL_INTEGRITY); |
| 455 |
ret &= bindtest(torture, cli, samba_cmdline_get_creds(), |
| 456 |
DCERPC_AUTH_TYPE_SPNEGO, |
| 457 |
DCERPC_AUTH_LEVEL_PRIVACY); |
| 458 |
|
| 459 |
done: |
| 460 |
talloc_free(mem_ctx); |
| 461 |
return ret; |
| 462 |
} |
| 463 |
|
| 464 |
/* |
| 465 |
* Lookup or create a user and return all necessary info |
| 466 |
*/ |
| 467 |
|
| 468 |
static bool get_usr_handle(struct torture_context *tctx, |
| 469 |
struct smbcli_state *cli, |
| 470 |
TALLOC_CTX *mem_ctx, |
| 471 |
struct cli_credentials *admin_creds, |
| 472 |
uint8_t auth_type, |
| 473 |
uint8_t auth_level, |
| 474 |
const char *username, |
| 475 |
char **domain, |
| 476 |
struct dcerpc_pipe **result_pipe, |
| 477 |
struct policy_handle **result_handle, |
| 478 |
struct dom_sid **sid_p) |
| 479 |
{ |
| 480 |
struct dcerpc_pipe *samr_pipe; |
| 481 |
struct dcerpc_binding_handle *samr_handle; |
| 482 |
NTSTATUS status; |
| 483 |
struct policy_handle conn_handle; |
| 484 |
struct policy_handle domain_handle; |
| 485 |
struct policy_handle *user_handle; |
| 486 |
struct samr_Connect2 conn; |
| 487 |
struct samr_EnumDomains enumdom; |
| 488 |
uint32_t resume_handle = 0; |
| 489 |
uint32_t num_entries = 0; |
| 490 |
struct samr_SamArray *sam = NULL; |
| 491 |
struct samr_LookupDomain l; |
| 492 |
struct dom_sid2 *sid = NULL; |
| 493 |
int dom_idx; |
| 494 |
struct lsa_String domain_name; |
| 495 |
struct lsa_String user_name; |
| 496 |
struct samr_OpenDomain o; |
| 497 |
struct samr_CreateUser2 c; |
| 498 |
uint32_t user_rid,access_granted; |
| 499 |
|
| 500 |
if (admin_creds != NULL) { |
| 501 |
status = pipe_bind_smb_auth(tctx, mem_ctx, cli->tree, |
| 502 |
admin_creds, auth_type, auth_level, |
| 503 |
"\\samr", &ndr_table_samr, &samr_pipe); |
| 504 |
torture_assert_ntstatus_ok(tctx, status, "pipe_bind_smb_auth failed"); |
| 505 |
} else { |
| 506 |
/* We must have an authenticated SMB connection */ |
| 507 |
status = pipe_bind_smb(tctx, mem_ctx, cli->tree, |
| 508 |
"\\samr", &ndr_table_samr, &samr_pipe); |
| 509 |
torture_assert_ntstatus_ok(tctx, status, "pipe_bind_smb_auth failed"); |
| 510 |
} |
| 511 |
#if 0 |
| 512 |
samr_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT; |
| 513 |
#endif |
| 514 |
samr_handle = samr_pipe->binding_handle; |
| 515 |
|
| 516 |
conn.in.system_name = talloc_asprintf( |
| 517 |
mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe)); |
| 518 |
conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 519 |
conn.out.connect_handle = &conn_handle; |
| 520 |
|
| 521 |
torture_assert_ntstatus_ok(tctx, |
| 522 |
dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn), |
| 523 |
"samr_Connect2 failed"); |
| 524 |
torture_assert_ntstatus_ok(tctx, conn.out.result, |
| 525 |
"samr_Connect2 failed"); |
| 526 |
|
| 527 |
enumdom.in.connect_handle = &conn_handle; |
| 528 |
enumdom.in.resume_handle = &resume_handle; |
| 529 |
enumdom.in.buf_size = (uint32_t)-1; |
| 530 |
enumdom.out.resume_handle = &resume_handle; |
| 531 |
enumdom.out.num_entries = &num_entries; |
| 532 |
enumdom.out.sam = &sam; |
| 533 |
|
| 534 |
torture_assert_ntstatus_ok(tctx, |
| 535 |
dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom), |
| 536 |
"samr_EnumDomains failed"); |
| 537 |
torture_assert_ntstatus_ok(tctx, enumdom.out.result, |
| 538 |
"samr_EnumDomains failed"); |
| 539 |
|
| 540 |
torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2, |
| 541 |
"samr_EnumDomains returned unexpected num_entries"); |
| 542 |
|
| 543 |
dom_idx = strequal(sam->entries[0].name.string, |
| 544 |
"builtin") ? 1:0; |
| 545 |
|
| 546 |
l.in.connect_handle = &conn_handle; |
| 547 |
domain_name.string = sam->entries[dom_idx].name.string; |
| 548 |
*domain = talloc_strdup(mem_ctx, domain_name.string); |
| 549 |
l.in.domain_name = &domain_name; |
| 550 |
l.out.sid = &sid; |
| 551 |
|
| 552 |
torture_assert_ntstatus_ok(tctx, |
| 553 |
dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l), |
| 554 |
"samr_LookupDomain failed"); |
| 555 |
torture_assert_ntstatus_ok(tctx, l.out.result, |
| 556 |
"samr_LookupDomain failed"); |
| 557 |
|
| 558 |
o.in.connect_handle = &conn_handle; |
| 559 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 560 |
o.in.sid = *l.out.sid; |
| 561 |
o.out.domain_handle = &domain_handle; |
| 562 |
|
| 563 |
torture_assert_ntstatus_ok(tctx, |
| 564 |
dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o), |
| 565 |
"samr_OpenDomain failed"); |
| 566 |
torture_assert_ntstatus_ok(tctx, o.out.result, |
| 567 |
"samr_OpenDomain failed"); |
| 568 |
|
| 569 |
c.in.domain_handle = &domain_handle; |
| 570 |
user_name.string = username; |
| 571 |
c.in.account_name = &user_name; |
| 572 |
c.in.acct_flags = ACB_NORMAL; |
| 573 |
c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 574 |
user_handle = talloc(mem_ctx, struct policy_handle); |
| 575 |
c.out.user_handle = user_handle; |
| 576 |
c.out.access_granted = &access_granted; |
| 577 |
c.out.rid = &user_rid; |
| 578 |
|
| 579 |
torture_assert_ntstatus_ok(tctx, |
| 580 |
dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c), |
| 581 |
"samr_CreateUser2 failed"); |
| 582 |
|
| 583 |
if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) { |
| 584 |
struct samr_LookupNames ln; |
| 585 |
struct samr_OpenUser ou; |
| 586 |
struct samr_Ids rids, types; |
| 587 |
|
| 588 |
ln.in.domain_handle = &domain_handle; |
| 589 |
ln.in.num_names = 1; |
| 590 |
ln.in.names = &user_name; |
| 591 |
ln.out.rids = &rids; |
| 592 |
ln.out.types = &types; |
| 593 |
|
| 594 |
torture_assert_ntstatus_ok(tctx, |
| 595 |
dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln), |
| 596 |
"samr_LookupNames failed"); |
| 597 |
torture_assert_ntstatus_ok(tctx, ln.out.result, |
| 598 |
"samr_LookupNames failed"); |
| 599 |
|
| 600 |
ou.in.domain_handle = &domain_handle; |
| 601 |
ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 602 |
user_rid = ou.in.rid = ln.out.rids->ids[0]; |
| 603 |
ou.out.user_handle = user_handle; |
| 604 |
|
| 605 |
torture_assert_ntstatus_ok(tctx, |
| 606 |
dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou), |
| 607 |
"samr_OpenUser failed"); |
| 608 |
status = ou.out.result; |
| 609 |
} else { |
| 610 |
status = c.out.result; |
| 611 |
} |
| 612 |
|
| 613 |
torture_assert_ntstatus_ok(tctx, status, |
| 614 |
"samr_CreateUser failed"); |
| 615 |
|
| 616 |
*result_pipe = samr_pipe; |
| 617 |
*result_handle = user_handle; |
| 618 |
if (sid_p != NULL) { |
| 619 |
*sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid); |
| 620 |
} |
| 621 |
return true; |
| 622 |
|
| 623 |
} |
| 624 |
|
| 625 |
/* |
| 626 |
* Create a test user |
| 627 |
*/ |
| 628 |
|
| 629 |
static bool create_user(struct torture_context *tctx, |
| 630 |
TALLOC_CTX *mem_ctx, struct smbcli_state *cli, |
| 631 |
struct cli_credentials *admin_creds, |
| 632 |
const char *username, const char *password, |
| 633 |
char **domain_name, |
| 634 |
struct dom_sid **user_sid) |
| 635 |
{ |
| 636 |
TALLOC_CTX *tmp_ctx; |
| 637 |
NTSTATUS status; |
| 638 |
struct dcerpc_pipe *samr_pipe; |
| 639 |
struct dcerpc_binding_handle *samr_handle; |
| 640 |
struct policy_handle *wks_handle; |
| 641 |
bool ret = false; |
| 642 |
|
| 643 |
if (!(tmp_ctx = talloc_new(mem_ctx))) { |
| 644 |
torture_comment(tctx, "talloc_init failed\n"); |
| 645 |
return false; |
| 646 |
} |
| 647 |
|
| 648 |
ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds, |
| 649 |
DCERPC_AUTH_TYPE_NTLMSSP, |
| 650 |
DCERPC_AUTH_LEVEL_INTEGRITY, |
| 651 |
username, domain_name, &samr_pipe, &wks_handle, |
| 652 |
user_sid); |
| 653 |
if (ret == false) { |
| 654 |
torture_comment(tctx, "get_usr_handle failed\n"); |
| 655 |
goto done; |
| 656 |
} |
| 657 |
samr_handle = samr_pipe->binding_handle; |
| 658 |
|
| 659 |
{ |
| 660 |
struct samr_SetUserInfo2 sui2; |
| 661 |
struct samr_SetUserInfo sui; |
| 662 |
struct samr_QueryUserInfo qui; |
| 663 |
union samr_UserInfo u_info; |
| 664 |
union samr_UserInfo *info; |
| 665 |
DATA_BLOB session_key; |
| 666 |
|
| 667 |
ZERO_STRUCT(u_info); |
| 668 |
encode_pw_buffer(u_info.info23.password.data, password, |
| 669 |
STR_UNICODE); |
| 670 |
|
| 671 |
status = dcerpc_binding_handle_transport_session_key(samr_handle, |
| 672 |
tctx, |
| 673 |
&session_key); |
| 674 |
if (!NT_STATUS_IS_OK(status)) { |
| 675 |
torture_comment(tctx, "transport_session_key failed\n"); |
| 676 |
goto done; |
| 677 |
} |
| 678 |
|
| 679 |
status = init_samr_CryptPassword(password, |
| 680 |
&session_key, |
| 681 |
&u_info.info23.password); |
| 682 |
if (!NT_STATUS_IS_OK(status)) { |
| 683 |
torture_comment(tctx, "init_samr_CryptPassword failed\n"); |
| 684 |
goto done; |
| 685 |
} |
| 686 |
|
| 687 |
u_info.info23.info.password_expired = 0; |
| 688 |
u_info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT | |
| 689 |
SAMR_FIELD_LM_PASSWORD_PRESENT | |
| 690 |
SAMR_FIELD_EXPIRED_FLAG; |
| 691 |
sui2.in.user_handle = wks_handle; |
| 692 |
sui2.in.info = &u_info; |
| 693 |
sui2.in.level = 23; |
| 694 |
|
| 695 |
status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2); |
| 696 |
if (!NT_STATUS_IS_OK(status)) { |
| 697 |
torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n", |
| 698 |
nt_errstr(status)); |
| 699 |
goto done; |
| 700 |
} |
| 701 |
if (!NT_STATUS_IS_OK(sui2.out.result)) { |
| 702 |
torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n", |
| 703 |
nt_errstr(sui2.out.result)); |
| 704 |
goto done; |
| 705 |
} |
| 706 |
|
| 707 |
u_info.info16.acct_flags = ACB_NORMAL; |
| 708 |
sui.in.user_handle = wks_handle; |
| 709 |
sui.in.info = &u_info; |
| 710 |
sui.in.level = 16; |
| 711 |
|
| 712 |
status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui); |
| 713 |
if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) { |
| 714 |
torture_comment(tctx, "samr_SetUserInfo(16) failed\n"); |
| 715 |
goto done; |
| 716 |
} |
| 717 |
|
| 718 |
qui.in.user_handle = wks_handle; |
| 719 |
qui.in.level = 21; |
| 720 |
qui.out.info = &info; |
| 721 |
|
| 722 |
status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui); |
| 723 |
if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) { |
| 724 |
torture_comment(tctx, "samr_QueryUserInfo(21) failed\n"); |
| 725 |
goto done; |
| 726 |
} |
| 727 |
|
| 728 |
info->info21.allow_password_change = 0; |
| 729 |
info->info21.force_password_change = 0; |
| 730 |
info->info21.account_name.string = NULL; |
| 731 |
info->info21.rid = 0; |
| 732 |
info->info21.acct_expiry = 0; |
| 733 |
info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */ |
| 734 |
|
| 735 |
u_info.info21 = info->info21; |
| 736 |
sui.in.user_handle = wks_handle; |
| 737 |
sui.in.info = &u_info; |
| 738 |
sui.in.level = 21; |
| 739 |
|
| 740 |
status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui); |
| 741 |
if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) { |
| 742 |
torture_comment(tctx, "samr_SetUserInfo(21) failed\n"); |
| 743 |
goto done; |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
*domain_name= talloc_steal(mem_ctx, *domain_name); |
| 748 |
*user_sid = talloc_steal(mem_ctx, *user_sid); |
| 749 |
ret = true; |
| 750 |
done: |
| 751 |
talloc_free(tmp_ctx); |
| 752 |
return ret; |
| 753 |
} |
| 754 |
|
| 755 |
/* |
| 756 |
* Delete a test user |
| 757 |
*/ |
| 758 |
|
| 759 |
static bool delete_user(struct torture_context *tctx, |
| 760 |
struct smbcli_state *cli, |
| 761 |
struct cli_credentials *admin_creds, |
| 762 |
const char *username) |
| 763 |
{ |
| 764 |
TALLOC_CTX *mem_ctx; |
| 765 |
NTSTATUS status; |
| 766 |
char *dom_name; |
| 767 |
struct dcerpc_pipe *samr_pipe; |
| 768 |
struct dcerpc_binding_handle *samr_handle; |
| 769 |
struct policy_handle *user_handle; |
| 770 |
bool ret = false; |
| 771 |
|
| 772 |
if ((mem_ctx = talloc_init("leave")) == NULL) { |
| 773 |
torture_comment(tctx, "talloc_init failed\n"); |
| 774 |
return false; |
| 775 |
} |
| 776 |
|
| 777 |
ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds, |
| 778 |
DCERPC_AUTH_TYPE_NTLMSSP, |
| 779 |
DCERPC_AUTH_LEVEL_INTEGRITY, |
| 780 |
username, &dom_name, &samr_pipe, |
| 781 |
&user_handle, NULL); |
| 782 |
if (ret == false) { |
| 783 |
torture_comment(tctx, "get_wks_handle failed\n"); |
| 784 |
goto done; |
| 785 |
} |
| 786 |
samr_handle = samr_pipe->binding_handle; |
| 787 |
|
| 788 |
{ |
| 789 |
struct samr_DeleteUser d; |
| 790 |
|
| 791 |
d.in.user_handle = user_handle; |
| 792 |
d.out.user_handle = user_handle; |
| 793 |
|
| 794 |
status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d); |
| 795 |
if (!NT_STATUS_IS_OK(status)) { |
| 796 |
torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status)); |
| 797 |
goto done; |
| 798 |
} |
| 799 |
if (!NT_STATUS_IS_OK(d.out.result)) { |
| 800 |
torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result)); |
| 801 |
goto done; |
| 802 |
} |
| 803 |
|
| 804 |
} |
| 805 |
|
| 806 |
ret = true; |
| 807 |
|
| 808 |
done: |
| 809 |
talloc_free(mem_ctx); |
| 810 |
return ret; |
| 811 |
} |
| 812 |
|
| 813 |
/* |
| 814 |
* Do a Samba3-style join |
| 815 |
*/ |
| 816 |
|
| 817 |
static bool join3(struct torture_context *tctx, |
| 818 |
struct smbcli_state *cli, |
| 819 |
bool use_level25, |
| 820 |
struct cli_credentials *admin_creds, |
| 821 |
struct cli_credentials *wks_creds) |
| 822 |
{ |
| 823 |
TALLOC_CTX *mem_ctx; |
| 824 |
NTSTATUS status; |
| 825 |
char *dom_name; |
| 826 |
struct dcerpc_pipe *samr_pipe; |
| 827 |
struct dcerpc_binding_handle *samr_handle; |
| 828 |
struct policy_handle *wks_handle; |
| 829 |
bool ret = false; |
| 830 |
NTTIME last_password_change; |
| 831 |
|
| 832 |
if ((mem_ctx = talloc_init("join3")) == NULL) { |
| 833 |
torture_comment(tctx, "talloc_init failed\n"); |
| 834 |
return false; |
| 835 |
} |
| 836 |
|
| 837 |
ret = get_usr_handle( |
| 838 |
tctx, cli, mem_ctx, admin_creds, |
| 839 |
DCERPC_AUTH_TYPE_NTLMSSP, |
| 840 |
DCERPC_AUTH_LEVEL_PRIVACY, |
| 841 |
talloc_asprintf(mem_ctx, "%s$", |
| 842 |
cli_credentials_get_workstation(wks_creds)), |
| 843 |
&dom_name, &samr_pipe, &wks_handle, NULL); |
| 844 |
if (ret == false) { |
| 845 |
torture_comment(tctx, "get_wks_handle failed\n"); |
| 846 |
goto done; |
| 847 |
} |
| 848 |
samr_handle = samr_pipe->binding_handle; |
| 849 |
ret = false; |
| 850 |
{ |
| 851 |
struct samr_QueryUserInfo q; |
| 852 |
union samr_UserInfo *info; |
| 853 |
|
| 854 |
q.in.user_handle = wks_handle; |
| 855 |
q.in.level = 21; |
| 856 |
q.out.info = &info; |
| 857 |
|
| 858 |
status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q); |
| 859 |
if (!NT_STATUS_IS_OK(status)) { |
| 860 |
torture_warning(tctx, "QueryUserInfo failed: %s\n", |
| 861 |
nt_errstr(status)); |
| 862 |
goto done; |
| 863 |
} |
| 864 |
if (!NT_STATUS_IS_OK(q.out.result)) { |
| 865 |
torture_warning(tctx, "QueryUserInfo failed: %s\n", |
| 866 |
nt_errstr(q.out.result)); |
| 867 |
goto done; |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
last_password_change = info->info21.last_password_change; |
| 872 |
} |
| 873 |
|
| 874 |
cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED); |
| 875 |
|
| 876 |
if (use_level25) { |
| 877 |
struct samr_SetUserInfo2 sui2; |
| 878 |
union samr_UserInfo u_info; |
| 879 |
struct samr_UserInfo21 *i21 = &u_info.info25.info; |
| 880 |
DATA_BLOB session_key; |
| 881 |
|
| 882 |
ZERO_STRUCT(u_info); |
| 883 |
|
| 884 |
i21->full_name.string = talloc_asprintf( |
| 885 |
mem_ctx, "%s$", |
| 886 |
cli_credentials_get_workstation(wks_creds)); |
| 887 |
i21->acct_flags = ACB_WSTRUST; |
| 888 |
i21->fields_present = SAMR_FIELD_FULL_NAME | |
| 889 |
SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_NT_PASSWORD_PRESENT; |
| 890 |
/* this would break the test result expectations |
| 891 |
i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG; |
| 892 |
i21->password_expired = 1; |
| 893 |
*/ |
| 894 |
|
| 895 |
status = dcerpc_binding_handle_transport_session_key(samr_handle, |
| 896 |
tctx, |
| 897 |
&session_key); |
| 898 |
if (!NT_STATUS_IS_OK(status)) { |
| 899 |
torture_comment(tctx, "transport_session_key failed: %s\n", |
| 900 |
nt_errstr(status)); |
| 901 |
goto done; |
| 902 |
} |
| 903 |
|
| 904 |
status = init_samr_CryptPasswordEx(cli_credentials_get_password(wks_creds), |
| 905 |
&session_key, |
| 906 |
&u_info.info25.password); |
| 907 |
|
| 908 |
sui2.in.user_handle = wks_handle; |
| 909 |
sui2.in.level = 25; |
| 910 |
sui2.in.info = &u_info; |
| 911 |
|
| 912 |
status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2); |
| 913 |
if (!NT_STATUS_IS_OK(status)) { |
| 914 |
torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n", |
| 915 |
nt_errstr(status)); |
| 916 |
goto done; |
| 917 |
} |
| 918 |
if (!NT_STATUS_IS_OK(sui2.out.result)) { |
| 919 |
torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n", |
| 920 |
nt_errstr(sui2.out.result)); |
| 921 |
goto done; |
| 922 |
} |
| 923 |
} else { |
| 924 |
struct samr_SetUserInfo2 sui2; |
| 925 |
struct samr_SetUserInfo sui; |
| 926 |
union samr_UserInfo u_info; |
| 927 |
DATA_BLOB session_key; |
| 928 |
|
| 929 |
encode_pw_buffer(u_info.info24.password.data, |
| 930 |
cli_credentials_get_password(wks_creds), |
| 931 |
STR_UNICODE); |
| 932 |
/* just to make this test pass */ |
| 933 |
u_info.info24.password_expired = 1; |
| 934 |
|
| 935 |
status = dcerpc_binding_handle_transport_session_key(samr_handle, |
| 936 |
tctx, |
| 937 |
&session_key); |
| 938 |
if (!NT_STATUS_IS_OK(status)) { |
| 939 |
torture_comment(tctx, "transport_session_key failed\n"); |
| 940 |
goto done; |
| 941 |
} |
| 942 |
|
| 943 |
status = init_samr_CryptPassword(cli_credentials_get_password(wks_creds), |
| 944 |
&session_key, |
| 945 |
&u_info.info24.password); |
| 946 |
|
| 947 |
sui2.in.user_handle = wks_handle; |
| 948 |
sui2.in.info = &u_info; |
| 949 |
sui2.in.level = 24; |
| 950 |
|
| 951 |
status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2); |
| 952 |
if (!NT_STATUS_IS_OK(status)) { |
| 953 |
torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n", |
| 954 |
nt_errstr(status)); |
| 955 |
goto done; |
| 956 |
} |
| 957 |
if (!NT_STATUS_IS_OK(sui2.out.result)) { |
| 958 |
torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n", |
| 959 |
nt_errstr(sui2.out.result)); |
| 960 |
goto done; |
| 961 |
} |
| 962 |
|
| 963 |
u_info.info16.acct_flags = ACB_WSTRUST; |
| 964 |
sui.in.user_handle = wks_handle; |
| 965 |
sui.in.info = &u_info; |
| 966 |
sui.in.level = 16; |
| 967 |
|
| 968 |
status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui); |
| 969 |
if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) { |
| 970 |
torture_comment(tctx, "samr_SetUserInfo(16) failed\n"); |
| 971 |
goto done; |
| 972 |
} |
| 973 |
} |
| 974 |
|
| 975 |
{ |
| 976 |
struct samr_QueryUserInfo q; |
| 977 |
union samr_UserInfo *info; |
| 978 |
|
| 979 |
q.in.user_handle = wks_handle; |
| 980 |
q.in.level = 21; |
| 981 |
q.out.info = &info; |
| 982 |
|
| 983 |
status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q); |
| 984 |
if (!NT_STATUS_IS_OK(status)) { |
| 985 |
torture_warning(tctx, "QueryUserInfo failed: %s\n", |
| 986 |
nt_errstr(status)); |
| 987 |
goto done; |
| 988 |
} |
| 989 |
if (!NT_STATUS_IS_OK(q.out.result)) { |
| 990 |
torture_warning(tctx, "QueryUserInfo failed: %s\n", |
| 991 |
nt_errstr(q.out.result)); |
| 992 |
goto done; |
| 993 |
} |
| 994 |
|
| 995 |
if (use_level25) { |
| 996 |
if (last_password_change |
| 997 |
== info->info21.last_password_change) { |
| 998 |
torture_warning(tctx, "last_password_change unchanged " |
| 999 |
"during join, level25 must change " |
| 1000 |
"it\n"); |
| 1001 |
goto done; |
| 1002 |
} |
| 1003 |
} |
| 1004 |
else { |
| 1005 |
if (last_password_change |
| 1006 |
!= info->info21.last_password_change) { |
| 1007 |
torture_warning(tctx, "last_password_change changed " |
| 1008 |
"during join, level24 doesn't " |
| 1009 |
"change it\n"); |
| 1010 |
goto done; |
| 1011 |
} |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
ret = true; |
| 1016 |
|
| 1017 |
done: |
| 1018 |
talloc_free(mem_ctx); |
| 1019 |
return ret; |
| 1020 |
} |
| 1021 |
|
| 1022 |
/* |
| 1023 |
* Do a ReqChallenge/Auth2 and get the wks creds |
| 1024 |
*/ |
| 1025 |
|
| 1026 |
static bool auth2(struct torture_context *tctx, |
| 1027 |
struct smbcli_state *cli, |
| 1028 |
struct cli_credentials *wks_cred) |
| 1029 |
{ |
| 1030 |
TALLOC_CTX *mem_ctx; |
| 1031 |
struct dcerpc_pipe *net_pipe; |
| 1032 |
struct dcerpc_binding_handle *net_handle; |
| 1033 |
bool result = false; |
| 1034 |
NTSTATUS status; |
| 1035 |
struct netr_ServerReqChallenge r; |
| 1036 |
struct netr_Credential netr_cli_creds; |
| 1037 |
struct netr_Credential netr_srv_creds; |
| 1038 |
uint32_t negotiate_flags; |
| 1039 |
struct netr_ServerAuthenticate2 a; |
| 1040 |
struct netlogon_creds_CredentialState *creds_state; |
| 1041 |
struct netr_Credential netr_cred; |
| 1042 |
struct samr_Password mach_pw; |
| 1043 |
|
| 1044 |
mem_ctx = talloc_new(NULL); |
| 1045 |
if (mem_ctx == NULL) { |
| 1046 |
torture_comment(tctx, "talloc_new failed\n"); |
| 1047 |
return false; |
| 1048 |
} |
| 1049 |
|
| 1050 |
status = pipe_bind_smb(tctx, mem_ctx, cli->tree, "\\netlogon", |
| 1051 |
&ndr_table_netlogon, &net_pipe); |
| 1052 |
torture_assert_ntstatus_ok_goto(tctx, status, result, done, |
| 1053 |
"pipe_bind_smb failed"); |
| 1054 |
net_handle = net_pipe->binding_handle; |
| 1055 |
|
| 1056 |
r.in.computer_name = cli_credentials_get_workstation(wks_cred); |
| 1057 |
r.in.server_name = talloc_asprintf( |
| 1058 |
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe)); |
| 1059 |
if (r.in.server_name == NULL) { |
| 1060 |
torture_comment(tctx, "talloc_asprintf failed\n"); |
| 1061 |
goto done; |
| 1062 |
} |
| 1063 |
generate_random_buffer(netr_cli_creds.data, |
| 1064 |
sizeof(netr_cli_creds.data)); |
| 1065 |
r.in.credentials = &netr_cli_creds; |
| 1066 |
r.out.return_credentials = &netr_srv_creds; |
| 1067 |
|
| 1068 |
status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r); |
| 1069 |
if (!NT_STATUS_IS_OK(status)) { |
| 1070 |
torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n", |
| 1071 |
nt_errstr(status)); |
| 1072 |
goto done; |
| 1073 |
} |
| 1074 |
if (!NT_STATUS_IS_OK(r.out.result)) { |
| 1075 |
torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n", |
| 1076 |
nt_errstr(r.out.result)); |
| 1077 |
goto done; |
| 1078 |
} |
| 1079 |
|
| 1080 |
negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 1081 |
E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash); |
| 1082 |
|
| 1083 |
a.in.server_name = talloc_asprintf( |
| 1084 |
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe)); |
| 1085 |
a.in.account_name = talloc_asprintf( |
| 1086 |
mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred)); |
| 1087 |
a.in.computer_name = cli_credentials_get_workstation(wks_cred); |
| 1088 |
a.in.secure_channel_type = SEC_CHAN_WKSTA; |
| 1089 |
a.in.negotiate_flags = &negotiate_flags; |
| 1090 |
a.out.negotiate_flags = &negotiate_flags; |
| 1091 |
a.in.credentials = &netr_cred; |
| 1092 |
a.out.return_credentials = &netr_cred; |
| 1093 |
|
| 1094 |
creds_state = netlogon_creds_client_init(mem_ctx, |
| 1095 |
a.in.account_name, |
| 1096 |
a.in.computer_name, |
| 1097 |
a.in.secure_channel_type, |
| 1098 |
r.in.credentials, |
| 1099 |
r.out.return_credentials, &mach_pw, |
| 1100 |
&netr_cred, |
| 1101 |
negotiate_flags, |
| 1102 |
negotiate_flags); |
| 1103 |
torture_assert(tctx, (creds_state != NULL), "memory allocation failed"); |
| 1104 |
|
| 1105 |
status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a); |
| 1106 |
if (!NT_STATUS_IS_OK(status)) { |
| 1107 |
torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n", |
| 1108 |
nt_errstr(status)); |
| 1109 |
goto done; |
| 1110 |
} |
| 1111 |
if (!NT_STATUS_IS_OK(a.out.result)) { |
| 1112 |
torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n", |
| 1113 |
nt_errstr(a.out.result)); |
| 1114 |
goto done; |
| 1115 |
} |
| 1116 |
|
| 1117 |
if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) { |
| 1118 |
torture_comment(tctx, "creds_client_check failed\n"); |
| 1119 |
goto done; |
| 1120 |
} |
| 1121 |
|
| 1122 |
cli_credentials_set_netlogon_creds(wks_cred, creds_state); |
| 1123 |
|
| 1124 |
result = true; |
| 1125 |
|
| 1126 |
done: |
| 1127 |
talloc_free(mem_ctx); |
| 1128 |
return result; |
| 1129 |
} |
| 1130 |
|
| 1131 |
/* |
| 1132 |
* Do a couple of schannel protected Netlogon ops: Interactive and Network |
| 1133 |
* login, and change the wks password |
| 1134 |
*/ |
| 1135 |
|
| 1136 |
static bool schan(struct torture_context *tctx, |
| 1137 |
struct smbcli_state *cli, |
| 1138 |
struct cli_credentials *wks_creds, |
| 1139 |
struct cli_credentials *user_creds) |
| 1140 |
{ |
| 1141 |
TALLOC_CTX *mem_ctx; |
| 1142 |
NTSTATUS status; |
| 1143 |
bool ret = false; |
| 1144 |
struct dcerpc_pipe *net_pipe; |
| 1145 |
struct dcerpc_binding_handle *net_handle; |
| 1146 |
int i; |
| 1147 |
|
| 1148 |
mem_ctx = talloc_new(NULL); |
| 1149 |
if (mem_ctx == NULL) { |
| 1150 |
torture_comment(tctx, "talloc_new failed\n"); |
| 1151 |
return false; |
| 1152 |
} |
| 1153 |
|
| 1154 |
#if 1 |
| 1155 |
status = pipe_bind_smb_auth(tctx, mem_ctx, cli->tree, |
| 1156 |
wks_creds, |
| 1157 |
DCERPC_AUTH_TYPE_SCHANNEL, |
| 1158 |
DCERPC_AUTH_LEVEL_PRIVACY, |
| 1159 |
"\\netlogon", &ndr_table_netlogon, &net_pipe); |
| 1160 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1161 |
"pipe_bind_smb_auth failed"); |
| 1162 |
#else |
| 1163 |
status = pipe_bind_smb(tctx, mem_ctx, cli->tree, |
| 1164 |
"\\netlogon", &ndr_table_netlogon, &net_pipe); |
| 1165 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1166 |
"pipe_bind_smb failed"); |
| 1167 |
#endif |
| 1168 |
#if 0 |
| 1169 |
net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN | |
| 1170 |
DCERPC_DEBUG_PRINT_OUT; |
| 1171 |
#endif |
| 1172 |
net_handle = net_pipe->binding_handle; |
| 1173 |
|
| 1174 |
|
| 1175 |
for (i=2; i<4; i++) { |
| 1176 |
int flags; |
| 1177 |
DATA_BLOB chal, nt_resp, lm_resp, names_blob; |
| 1178 |
struct netlogon_creds_CredentialState *creds_state; |
| 1179 |
struct netr_Authenticator netr_auth, netr_auth2; |
| 1180 |
struct netr_NetworkInfo ninfo; |
| 1181 |
struct netr_PasswordInfo pinfo; |
| 1182 |
struct netr_LogonSamLogon r; |
| 1183 |
union netr_LogonLevel logon; |
| 1184 |
union netr_Validation validation; |
| 1185 |
uint8_t authoritative; |
| 1186 |
struct netr_Authenticator return_authenticator; |
| 1187 |
|
| 1188 |
flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH | |
| 1189 |
CLI_CRED_NTLMv2_AUTH; |
| 1190 |
|
| 1191 |
chal = data_blob_talloc(mem_ctx, NULL, 8); |
| 1192 |
if (chal.data == NULL) { |
| 1193 |
torture_comment(tctx, "data_blob_talloc failed\n"); |
| 1194 |
goto done; |
| 1195 |
} |
| 1196 |
|
| 1197 |
generate_random_buffer(chal.data, chal.length); |
| 1198 |
names_blob = NTLMv2_generate_names_blob( |
| 1199 |
mem_ctx, |
| 1200 |
cli_credentials_get_workstation(wks_creds), |
| 1201 |
cli_credentials_get_domain(wks_creds)); |
| 1202 |
status = cli_credentials_get_ntlm_response( |
| 1203 |
user_creds, mem_ctx, &flags, chal, NULL, names_blob, |
| 1204 |
&lm_resp, &nt_resp, NULL, NULL); |
| 1205 |
if (!NT_STATUS_IS_OK(status)) { |
| 1206 |
torture_comment(tctx, "cli_credentials_get_ntlm_response failed:" |
| 1207 |
" %s\n", nt_errstr(status)); |
| 1208 |
goto done; |
| 1209 |
} |
| 1210 |
|
| 1211 |
creds_state = cli_credentials_get_netlogon_creds(wks_creds); |
| 1212 |
netlogon_creds_client_authenticator(creds_state, &netr_auth); |
| 1213 |
|
| 1214 |
ninfo.identity_info.account_name.string = |
| 1215 |
cli_credentials_get_username(user_creds); |
| 1216 |
ninfo.identity_info.domain_name.string = |
| 1217 |
cli_credentials_get_domain(user_creds); |
| 1218 |
ninfo.identity_info.parameter_control = 0; |
| 1219 |
ninfo.identity_info.logon_id = 0; |
| 1220 |
ninfo.identity_info.workstation.string = |
| 1221 |
cli_credentials_get_workstation(user_creds); |
| 1222 |
memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge)); |
| 1223 |
ninfo.nt.length = nt_resp.length; |
| 1224 |
ninfo.nt.data = nt_resp.data; |
| 1225 |
ninfo.lm.length = lm_resp.length; |
| 1226 |
ninfo.lm.data = lm_resp.data; |
| 1227 |
|
| 1228 |
logon.network = &ninfo; |
| 1229 |
|
| 1230 |
r.in.server_name = talloc_asprintf( |
| 1231 |
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe)); |
| 1232 |
ZERO_STRUCT(netr_auth2); |
| 1233 |
r.in.computer_name = |
| 1234 |
cli_credentials_get_workstation(wks_creds); |
| 1235 |
r.in.credential = &netr_auth; |
| 1236 |
r.in.return_authenticator = &netr_auth2; |
| 1237 |
r.in.logon_level = NetlogonNetworkInformation; |
| 1238 |
r.in.validation_level = i; |
| 1239 |
r.in.logon = &logon; |
| 1240 |
r.out.validation = &validation; |
| 1241 |
r.out.authoritative = &authoritative; |
| 1242 |
r.out.return_authenticator = &return_authenticator; |
| 1243 |
|
| 1244 |
status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r); |
| 1245 |
if (!NT_STATUS_IS_OK(status)) { |
| 1246 |
torture_comment(tctx, "netr_LogonSamLogon failed: %s\n", |
| 1247 |
nt_errstr(status)); |
| 1248 |
goto done; |
| 1249 |
} |
| 1250 |
if (!NT_STATUS_IS_OK(r.out.result)) { |
| 1251 |
torture_comment(tctx, "netr_LogonSamLogon failed: %s\n", |
| 1252 |
nt_errstr(r.out.result)); |
| 1253 |
goto done; |
| 1254 |
} |
| 1255 |
|
| 1256 |
if ((r.out.return_authenticator == NULL) || |
| 1257 |
(!netlogon_creds_client_check(creds_state, |
| 1258 |
&r.out.return_authenticator->cred))) { |
| 1259 |
torture_comment(tctx, "Credentials check failed!\n"); |
| 1260 |
goto done; |
| 1261 |
} |
| 1262 |
|
| 1263 |
netlogon_creds_client_authenticator(creds_state, &netr_auth); |
| 1264 |
|
| 1265 |
pinfo.identity_info = ninfo.identity_info; |
| 1266 |
ZERO_STRUCT(pinfo.lmpassword.hash); |
| 1267 |
E_md4hash(cli_credentials_get_password(user_creds), |
| 1268 |
pinfo.ntpassword.hash); |
| 1269 |
|
| 1270 |
logon.password = &pinfo; |
| 1271 |
|
| 1272 |
/* |
| 1273 |
* We don't use this here: |
| 1274 |
* |
| 1275 |
* netlogon_creds_encrypt_samlogon_logon(creds_state, |
| 1276 |
* NetlogonInteractiveInformation, |
| 1277 |
* &logon); |
| 1278 |
* |
| 1279 |
* in order to detect bugs |
| 1280 |
*/ |
| 1281 |
#undef netlogon_creds_aes_encrypt |
| 1282 |
netlogon_creds_aes_encrypt(creds_state, pinfo.ntpassword.hash, 16); |
| 1283 |
#define netlogon_creds_aes_encrypt __DO_NOT_USE_netlogon_creds_aes_encrypt |
| 1284 |
|
| 1285 |
r.in.logon_level = NetlogonInteractiveInformation; |
| 1286 |
r.in.logon = &logon; |
| 1287 |
r.out.return_authenticator = &return_authenticator; |
| 1288 |
|
| 1289 |
status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r); |
| 1290 |
if (!NT_STATUS_IS_OK(status)) { |
| 1291 |
torture_comment(tctx, "netr_LogonSamLogon failed: %s\n", |
| 1292 |
nt_errstr(status)); |
| 1293 |
goto done; |
| 1294 |
} |
| 1295 |
if (!NT_STATUS_IS_OK(r.out.result)) { |
| 1296 |
torture_comment(tctx, "netr_LogonSamLogon failed: %s\n", |
| 1297 |
nt_errstr(r.out.result)); |
| 1298 |
goto done; |
| 1299 |
} |
| 1300 |
|
| 1301 |
if ((r.out.return_authenticator == NULL) || |
| 1302 |
(!netlogon_creds_client_check(creds_state, |
| 1303 |
&r.out.return_authenticator->cred))) { |
| 1304 |
torture_comment(tctx, "Credentials check failed!\n"); |
| 1305 |
goto done; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
|
| 1309 |
{ |
| 1310 |
struct netr_ServerPasswordSet s; |
| 1311 |
char *password = generate_random_password(wks_creds, 8, 255); |
| 1312 |
struct netlogon_creds_CredentialState *creds_state; |
| 1313 |
struct netr_Authenticator credential, return_authenticator; |
| 1314 |
struct samr_Password new_password; |
| 1315 |
enum dcerpc_AuthType auth_type; |
| 1316 |
enum dcerpc_AuthLevel auth_level; |
| 1317 |
|
| 1318 |
s.in.server_name = talloc_asprintf( |
| 1319 |
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe)); |
| 1320 |
s.in.computer_name = cli_credentials_get_workstation(wks_creds); |
| 1321 |
s.in.account_name = talloc_asprintf( |
| 1322 |
mem_ctx, "%s$", s.in.computer_name); |
| 1323 |
s.in.secure_channel_type = SEC_CHAN_WKSTA; |
| 1324 |
s.in.credential = &credential; |
| 1325 |
s.in.new_password = &new_password; |
| 1326 |
s.out.return_authenticator = &return_authenticator; |
| 1327 |
|
| 1328 |
E_md4hash(password, new_password.hash); |
| 1329 |
|
| 1330 |
creds_state = cli_credentials_get_netlogon_creds(wks_creds); |
| 1331 |
dcerpc_binding_handle_auth_info(net_handle, |
| 1332 |
&auth_type, |
| 1333 |
&auth_level); |
| 1334 |
status = netlogon_creds_encrypt_samr_Password(creds_state, |
| 1335 |
&new_password, |
| 1336 |
auth_type, |
| 1337 |
auth_level); |
| 1338 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_Password"); |
| 1339 |
netlogon_creds_client_authenticator(creds_state, &credential); |
| 1340 |
|
| 1341 |
status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s); |
| 1342 |
if (!NT_STATUS_IS_OK(status)) { |
| 1343 |
torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status)); |
| 1344 |
goto done; |
| 1345 |
} |
| 1346 |
if (!NT_STATUS_IS_OK(s.out.result)) { |
| 1347 |
torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result)); |
| 1348 |
goto done; |
| 1349 |
} |
| 1350 |
|
| 1351 |
if (!netlogon_creds_client_check(creds_state, |
| 1352 |
&s.out.return_authenticator->cred)) { |
| 1353 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1354 |
} |
| 1355 |
|
| 1356 |
cli_credentials_set_password(wks_creds, password, |
| 1357 |
CRED_SPECIFIED); |
| 1358 |
} |
| 1359 |
|
| 1360 |
ret = true; |
| 1361 |
done: |
| 1362 |
talloc_free(mem_ctx); |
| 1363 |
return ret; |
| 1364 |
} |
| 1365 |
|
| 1366 |
/* |
| 1367 |
* Delete the wks account again |
| 1368 |
*/ |
| 1369 |
|
| 1370 |
static bool leave(struct torture_context *tctx, |
| 1371 |
struct smbcli_state *cli, |
| 1372 |
struct cli_credentials *admin_creds, |
| 1373 |
struct cli_credentials *wks_creds) |
| 1374 |
{ |
| 1375 |
char *wks_name = talloc_asprintf( |
| 1376 |
NULL, "%s$", cli_credentials_get_workstation(wks_creds)); |
| 1377 |
bool ret; |
| 1378 |
|
| 1379 |
ret = delete_user(tctx, cli, admin_creds, wks_name); |
| 1380 |
talloc_free(wks_name); |
| 1381 |
return ret; |
| 1382 |
} |
| 1383 |
|
| 1384 |
/* |
| 1385 |
* Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave |
| 1386 |
*/ |
| 1387 |
|
| 1388 |
static bool torture_netlogon_samba3(struct torture_context *torture) |
| 1389 |
{ |
| 1390 |
NTSTATUS status; |
| 1391 |
struct smbcli_state *cli; |
| 1392 |
struct cli_credentials *wks_creds; |
| 1393 |
const char *wks_name; |
| 1394 |
int i; |
| 1395 |
struct smbcli_options options; |
| 1396 |
struct smbcli_session_options session_options; |
| 1397 |
|
| 1398 |
wks_name = torture_setting_string(torture, "wksname", NULL); |
| 1399 |
torture_assert(torture, wks_name != NULL, "wksname not set"); |
| 1400 |
|
| 1401 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 1402 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 1403 |
|
| 1404 |
status = smbcli_full_connection(torture, &cli, |
| 1405 |
torture_setting_string(torture, "host", NULL), |
| 1406 |
"IPC$", NULL, |
| 1407 |
lpcfg_socket_options(torture->lp_ctx), |
| 1408 |
samba_cmdline_get_creds(), |
| 1409 |
torture->lp_ctx, |
| 1410 |
lpcfg_resolve_context(torture->lp_ctx), |
| 1411 |
torture->ev, &options, &session_options, |
| 1412 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 1413 |
torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n"); |
| 1414 |
|
| 1415 |
wks_creds = cli_credentials_init(torture); |
| 1416 |
if (wks_creds == NULL) { |
| 1417 |
torture_fail(torture, "cli_credentials_init failed\n"); |
| 1418 |
} |
| 1419 |
|
| 1420 |
cli_credentials_set_conf(wks_creds, torture->lp_ctx); |
| 1421 |
cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA); |
| 1422 |
cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED); |
| 1423 |
cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED); |
| 1424 |
cli_credentials_set_password(wks_creds, |
| 1425 |
generate_random_password(wks_creds, 8, 255), |
| 1426 |
CRED_SPECIFIED); |
| 1427 |
|
| 1428 |
torture_assert(torture, |
| 1429 |
join3(torture, cli, false, NULL, wks_creds), |
| 1430 |
"join failed"); |
| 1431 |
|
| 1432 |
cli_credentials_set_domain( |
| 1433 |
samba_cmdline_get_creds(), |
| 1434 |
cli_credentials_get_domain(wks_creds), |
| 1435 |
CRED_SPECIFIED); |
| 1436 |
|
| 1437 |
for (i=0; i<2; i++) { |
| 1438 |
|
| 1439 |
/* Do this more than once, the routine "schan" changes |
| 1440 |
* the workstation password using the netlogon |
| 1441 |
* password change routine */ |
| 1442 |
|
| 1443 |
int j; |
| 1444 |
|
| 1445 |
torture_assert(torture, |
| 1446 |
auth2(torture, cli, wks_creds), |
| 1447 |
"auth2 failed"); |
| 1448 |
|
| 1449 |
for (j=0; j<2; j++) { |
| 1450 |
torture_assert(torture, |
| 1451 |
schan(torture, cli, wks_creds, |
| 1452 |
samba_cmdline_get_creds()), |
| 1453 |
"schan failed"); |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
torture_assert(torture, |
| 1458 |
leave(torture, cli, NULL, wks_creds), |
| 1459 |
"leave failed"); |
| 1460 |
|
| 1461 |
return true; |
| 1462 |
} |
| 1463 |
|
| 1464 |
/* |
| 1465 |
* Do a simple join, testjoin and leave using specified smb and samr |
| 1466 |
* credentials |
| 1467 |
*/ |
| 1468 |
|
| 1469 |
static bool test_join3(struct torture_context *tctx, |
| 1470 |
bool use_level25, |
| 1471 |
struct cli_credentials *smb_creds, |
| 1472 |
struct cli_credentials *samr_creds, |
| 1473 |
const char *wks_name) |
| 1474 |
{ |
| 1475 |
NTSTATUS status; |
| 1476 |
struct smbcli_state *cli; |
| 1477 |
struct cli_credentials *wks_creds; |
| 1478 |
struct smbcli_options options; |
| 1479 |
struct smbcli_session_options session_options; |
| 1480 |
|
| 1481 |
lpcfg_smbcli_options(tctx->lp_ctx, &options); |
| 1482 |
lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options); |
| 1483 |
|
| 1484 |
status = smbcli_full_connection(tctx, &cli, |
| 1485 |
torture_setting_string(tctx, "host", NULL), |
| 1486 |
"IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx), |
| 1487 |
smb_creds, |
| 1488 |
tctx->lp_ctx, |
| 1489 |
lpcfg_resolve_context(tctx->lp_ctx), |
| 1490 |
tctx->ev, &options, &session_options, |
| 1491 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)); |
| 1492 |
torture_assert_ntstatus_ok(tctx, status, |
| 1493 |
"smbcli_full_connection failed"); |
| 1494 |
|
| 1495 |
wks_creds = cli_credentials_init(cli); |
| 1496 |
torture_assert(tctx, wks_creds, "cli_credentials_init failed"); |
| 1497 |
|
| 1498 |
cli_credentials_set_conf(wks_creds, tctx->lp_ctx); |
| 1499 |
cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA); |
| 1500 |
cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED); |
| 1501 |
cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED); |
| 1502 |
cli_credentials_set_password(wks_creds, |
| 1503 |
generate_random_password(wks_creds, 8, 255), |
| 1504 |
CRED_SPECIFIED); |
| 1505 |
|
| 1506 |
torture_assert(tctx, |
| 1507 |
join3(tctx, cli, use_level25, samr_creds, wks_creds), |
| 1508 |
"join failed"); |
| 1509 |
|
| 1510 |
cli_credentials_set_domain( |
| 1511 |
samba_cmdline_get_creds(), |
| 1512 |
cli_credentials_get_domain(wks_creds), |
| 1513 |
CRED_SPECIFIED); |
| 1514 |
|
| 1515 |
torture_assert(tctx, |
| 1516 |
auth2(tctx, cli, wks_creds), |
| 1517 |
"auth2 failed"); |
| 1518 |
|
| 1519 |
torture_assert(tctx, |
| 1520 |
leave(tctx, cli, samr_creds, wks_creds), |
| 1521 |
"leave failed"); |
| 1522 |
|
| 1523 |
talloc_free(cli); |
| 1524 |
|
| 1525 |
return true; |
| 1526 |
} |
| 1527 |
|
| 1528 |
/* |
| 1529 |
* Test the different session key variants. Do it by joining, this uses the |
| 1530 |
* session key in the setpassword routine. Test the join by doing the auth2. |
| 1531 |
*/ |
| 1532 |
|
| 1533 |
static bool torture_samba3_sessionkey(struct torture_context *torture) |
| 1534 |
{ |
| 1535 |
struct cli_credentials *anon_creds; |
| 1536 |
const char *wks_name; |
| 1537 |
|
| 1538 |
|
| 1539 |
wks_name = torture_setting_string(torture, "wksname", NULL); |
| 1540 |
torture_assert(torture, wks_name != NULL, "wksname not set"); |
| 1541 |
|
| 1542 |
if (!(anon_creds = cli_credentials_init_anon(torture))) { |
| 1543 |
torture_fail(torture, "create_anon_creds failed\n"); |
| 1544 |
} |
| 1545 |
|
| 1546 |
cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED); |
| 1547 |
|
| 1548 |
torture_assert(torture, |
| 1549 |
test_join3(torture, false, samba_cmdline_get_creds(), |
| 1550 |
NULL, wks_name), |
| 1551 |
"join using anonymous bind on an authenticated smb connection failed"); |
| 1552 |
|
| 1553 |
/* |
| 1554 |
* The following two are tests for setuserinfolevel 25 |
| 1555 |
*/ |
| 1556 |
|
| 1557 |
torture_assert(torture, |
| 1558 |
test_join3(torture, true, samba_cmdline_get_creds(), |
| 1559 |
NULL, wks_name), |
| 1560 |
"join using anonymous bind on an authenticated smb connection failed"); |
| 1561 |
|
| 1562 |
return true; |
| 1563 |
} |
| 1564 |
|
| 1565 |
/* |
| 1566 |
* Sane wrapper around lsa_LookupNames |
| 1567 |
*/ |
| 1568 |
|
| 1569 |
static struct dom_sid *name2sid(struct torture_context *tctx, |
| 1570 |
TALLOC_CTX *mem_ctx, |
| 1571 |
struct dcerpc_pipe *p, |
| 1572 |
const char *name, |
| 1573 |
const char *domain) |
| 1574 |
{ |
| 1575 |
struct lsa_ObjectAttribute attr; |
| 1576 |
struct lsa_QosInfo qos; |
| 1577 |
struct lsa_OpenPolicy2 r; |
| 1578 |
struct lsa_Close c; |
| 1579 |
NTSTATUS status; |
| 1580 |
struct policy_handle handle; |
| 1581 |
struct lsa_LookupNames l; |
| 1582 |
struct lsa_TransSidArray sids; |
| 1583 |
struct lsa_RefDomainList *domains = NULL; |
| 1584 |
struct lsa_String lsa_name; |
| 1585 |
uint32_t count = 0; |
| 1586 |
struct dom_sid *result; |
| 1587 |
TALLOC_CTX *tmp_ctx; |
| 1588 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1589 |
|
| 1590 |
if (!(tmp_ctx = talloc_new(mem_ctx))) { |
| 1591 |
return NULL; |
| 1592 |
} |
| 1593 |
|
| 1594 |
qos.len = 0; |
| 1595 |
qos.impersonation_level = 2; |
| 1596 |
qos.context_mode = 1; |
| 1597 |
qos.effective_only = 0; |
| 1598 |
|
| 1599 |
attr.len = 0; |
| 1600 |
attr.root_dir = NULL; |
| 1601 |
attr.object_name = NULL; |
| 1602 |
attr.attributes = 0; |
| 1603 |
attr.sec_desc = NULL; |
| 1604 |
attr.sec_qos = &qos; |
| 1605 |
|
| 1606 |
r.in.system_name = "\\"; |
| 1607 |
r.in.attr = &attr; |
| 1608 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 1609 |
r.out.handle = &handle; |
| 1610 |
|
| 1611 |
status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r); |
| 1612 |
if (!NT_STATUS_IS_OK(status)) { |
| 1613 |
torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status)); |
| 1614 |
talloc_free(tmp_ctx); |
| 1615 |
return NULL; |
| 1616 |
} |
| 1617 |
if (!NT_STATUS_IS_OK(r.out.result)) { |
| 1618 |
torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result)); |
| 1619 |
talloc_free(tmp_ctx); |
| 1620 |
return NULL; |
| 1621 |
} |
| 1622 |
|
| 1623 |
sids.count = 0; |
| 1624 |
sids.sids = NULL; |
| 1625 |
|
| 1626 |
lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name); |
| 1627 |
|
| 1628 |
l.in.handle = &handle; |
| 1629 |
l.in.num_names = 1; |
| 1630 |
l.in.names = &lsa_name; |
| 1631 |
l.in.sids = &sids; |
| 1632 |
l.in.level = 1; |
| 1633 |
l.in.count = &count; |
| 1634 |
l.out.count = &count; |
| 1635 |
l.out.sids = &sids; |
| 1636 |
l.out.domains = &domains; |
| 1637 |
|
| 1638 |
status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l); |
| 1639 |
if (!NT_STATUS_IS_OK(status)) { |
| 1640 |
torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string, |
| 1641 |
nt_errstr(status)); |
| 1642 |
talloc_free(tmp_ctx); |
| 1643 |
return NULL; |
| 1644 |
} |
| 1645 |
if (!NT_STATUS_IS_OK(l.out.result)) { |
| 1646 |
torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string, |
| 1647 |
nt_errstr(l.out.result)); |
| 1648 |
talloc_free(tmp_ctx); |
| 1649 |
return NULL; |
| 1650 |
} |
| 1651 |
|
| 1652 |
result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid, |
| 1653 |
l.out.sids->sids[0].rid); |
| 1654 |
|
| 1655 |
c.in.handle = &handle; |
| 1656 |
c.out.handle = &handle; |
| 1657 |
|
| 1658 |
status = dcerpc_lsa_Close_r(b, tmp_ctx, &c); |
| 1659 |
if (!NT_STATUS_IS_OK(status)) { |
| 1660 |
torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status)); |
| 1661 |
talloc_free(tmp_ctx); |
| 1662 |
return NULL; |
| 1663 |
} |
| 1664 |
if (!NT_STATUS_IS_OK(c.out.result)) { |
| 1665 |
torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result)); |
| 1666 |
talloc_free(tmp_ctx); |
| 1667 |
return NULL; |
| 1668 |
} |
| 1669 |
|
| 1670 |
talloc_free(tmp_ctx); |
| 1671 |
return result; |
| 1672 |
} |
| 1673 |
|
| 1674 |
/* |
| 1675 |
* Find out the user SID on this connection |
| 1676 |
*/ |
| 1677 |
|
| 1678 |
static struct dom_sid *whoami(struct torture_context *tctx, |
| 1679 |
TALLOC_CTX *mem_ctx, |
| 1680 |
struct smbcli_tree *tree) |
| 1681 |
{ |
| 1682 |
struct dcerpc_pipe *lsa; |
| 1683 |
struct dcerpc_binding_handle *lsa_handle; |
| 1684 |
struct lsa_GetUserName r; |
| 1685 |
NTSTATUS status; |
| 1686 |
struct lsa_String *authority_name_p = NULL; |
| 1687 |
struct lsa_String *account_name_p = NULL; |
| 1688 |
struct dom_sid *result; |
| 1689 |
|
| 1690 |
status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc", |
| 1691 |
&ndr_table_lsarpc, &lsa); |
| 1692 |
if (!NT_STATUS_IS_OK(status)) { |
| 1693 |
torture_warning(tctx, "Could not bind to LSA: %s\n", |
| 1694 |
nt_errstr(status)); |
| 1695 |
return NULL; |
| 1696 |
} |
| 1697 |
lsa_handle = lsa->binding_handle; |
| 1698 |
|
| 1699 |
r.in.system_name = "\\"; |
| 1700 |
r.in.account_name = &account_name_p; |
| 1701 |
r.in.authority_name = &authority_name_p; |
| 1702 |
r.out.account_name = &account_name_p; |
| 1703 |
|
| 1704 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 1705 |
|
| 1706 |
authority_name_p = *r.out.authority_name; |
| 1707 |
|
| 1708 |
if (!NT_STATUS_IS_OK(status)) { |
| 1709 |
torture_warning(tctx, "GetUserName failed - %s\n", |
| 1710 |
nt_errstr(status)); |
| 1711 |
talloc_free(lsa); |
| 1712 |
return NULL; |
| 1713 |
} |
| 1714 |
if (!NT_STATUS_IS_OK(r.out.result)) { |
| 1715 |
torture_warning(tctx, "GetUserName failed - %s\n", |
| 1716 |
nt_errstr(r.out.result)); |
| 1717 |
talloc_free(lsa); |
| 1718 |
return NULL; |
| 1719 |
} |
| 1720 |
|
| 1721 |
result = name2sid(tctx, mem_ctx, lsa, account_name_p->string, |
| 1722 |
authority_name_p->string); |
| 1723 |
|
| 1724 |
talloc_free(lsa); |
| 1725 |
return result; |
| 1726 |
} |
| 1727 |
|
| 1728 |
static int destroy_tree(struct smbcli_tree *tree) |
| 1729 |
{ |
| 1730 |
smb_tree_disconnect(tree); |
| 1731 |
return 0; |
| 1732 |
} |
| 1733 |
|
| 1734 |
/* |
| 1735 |
* Do a tcon, given a session |
| 1736 |
*/ |
| 1737 |
|
| 1738 |
static NTSTATUS secondary_tcon(struct torture_context *tctx, |
| 1739 |
TALLOC_CTX *mem_ctx, |
| 1740 |
struct smbcli_session *session, |
| 1741 |
const char *sharename, |
| 1742 |
struct smbcli_tree **res) |
| 1743 |
{ |
| 1744 |
struct smbcli_tree *result; |
| 1745 |
TALLOC_CTX *tmp_ctx; |
| 1746 |
union smb_tcon tcon; |
| 1747 |
NTSTATUS status; |
| 1748 |
|
| 1749 |
if (!(tmp_ctx = talloc_new(mem_ctx))) { |
| 1750 |
return NT_STATUS_NO_MEMORY; |
| 1751 |
} |
| 1752 |
|
| 1753 |
if (!(result = smbcli_tree_init(session, mem_ctx, false))) { |
| 1754 |
talloc_free(tmp_ctx); |
| 1755 |
return NT_STATUS_NO_MEMORY; |
| 1756 |
} |
| 1757 |
|
| 1758 |
tcon.generic.level = RAW_TCON_TCONX; |
| 1759 |
tcon.tconx.in.flags = TCONX_FLAG_EXTENDED_RESPONSE; |
| 1760 |
tcon.tconx.in.flags |= TCONX_FLAG_EXTENDED_SIGNATURES; |
| 1761 |
tcon.tconx.in.password = data_blob(NULL, 0); |
| 1762 |
tcon.tconx.in.path = sharename; |
| 1763 |
tcon.tconx.in.device = "?????"; |
| 1764 |
|
| 1765 |
status = smb_raw_tcon(result, tmp_ctx, &tcon); |
| 1766 |
if (!NT_STATUS_IS_OK(status)) { |
| 1767 |
torture_warning(tctx, "smb_raw_tcon failed: %s\n", |
| 1768 |
nt_errstr(status)); |
| 1769 |
talloc_free(tmp_ctx); |
| 1770 |
return status; |
| 1771 |
} |
| 1772 |
|
| 1773 |
result->tid = tcon.tconx.out.tid; |
| 1774 |
|
| 1775 |
if (tcon.tconx.out.options & SMB_EXTENDED_SIGNATURES) { |
| 1776 |
smb1cli_session_protect_session_key(result->session->smbXcli); |
| 1777 |
} |
| 1778 |
|
| 1779 |
result = talloc_steal(mem_ctx, result); |
| 1780 |
talloc_set_destructor(result, destroy_tree); |
| 1781 |
talloc_free(tmp_ctx); |
| 1782 |
*res = result; |
| 1783 |
return NT_STATUS_OK; |
| 1784 |
} |
| 1785 |
|
| 1786 |
/* |
| 1787 |
* Test the getusername behaviour |
| 1788 |
*/ |
| 1789 |
|
| 1790 |
static bool torture_samba3_rpc_getusername(struct torture_context *torture) |
| 1791 |
{ |
| 1792 |
NTSTATUS status; |
| 1793 |
struct smbcli_state *cli; |
| 1794 |
bool ret = true; |
| 1795 |
struct dom_sid *user_sid; |
| 1796 |
struct dom_sid *created_sid; |
| 1797 |
struct cli_credentials *anon_creds; |
| 1798 |
struct cli_credentials *user_creds; |
| 1799 |
char *domain_name; |
| 1800 |
struct smbcli_options options; |
| 1801 |
struct smbcli_session_options session_options; |
| 1802 |
|
| 1803 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 1804 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 1805 |
|
| 1806 |
if (!(anon_creds = cli_credentials_init_anon(torture))) { |
| 1807 |
torture_fail(torture, "create_anon_creds failed\n"); |
| 1808 |
} |
| 1809 |
|
| 1810 |
status = smbcli_full_connection( |
| 1811 |
torture, &cli, torture_setting_string(torture, "host", NULL), |
| 1812 |
"IPC$", NULL, |
| 1813 |
lpcfg_socket_options(torture->lp_ctx), anon_creds, |
| 1814 |
torture->lp_ctx, |
| 1815 |
lpcfg_resolve_context(torture->lp_ctx), |
| 1816 |
torture->ev, &options, &session_options, |
| 1817 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 1818 |
torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n"); |
| 1819 |
|
| 1820 |
if (!(user_sid = whoami(torture, torture, cli->tree))) { |
| 1821 |
torture_fail(torture, "whoami on anon connection failed\n"); |
| 1822 |
} |
| 1823 |
|
| 1824 |
torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"), |
| 1825 |
"Anon lsa_GetUserName returned unexpected SID"); |
| 1826 |
|
| 1827 |
talloc_free(cli); |
| 1828 |
|
| 1829 |
status = smbcli_full_connection( |
| 1830 |
torture, &cli, torture_setting_string(torture, "host", NULL), |
| 1831 |
"IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), |
| 1832 |
samba_cmdline_get_creds(), |
| 1833 |
torture->lp_ctx, |
| 1834 |
lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options, |
| 1835 |
&session_options, lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 1836 |
torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n"); |
| 1837 |
|
| 1838 |
if (!(user_sid = whoami(torture, torture, cli->tree))) { |
| 1839 |
torture_fail(torture, "whoami on auth'ed connection failed\n"); |
| 1840 |
} |
| 1841 |
|
| 1842 |
if (!(user_creds = cli_credentials_init(torture))) { |
| 1843 |
torture_fail(torture, "cli_credentials_init failed\n"); |
| 1844 |
} |
| 1845 |
|
| 1846 |
cli_credentials_set_conf(user_creds, torture->lp_ctx); |
| 1847 |
cli_credentials_set_username(user_creds, "torture_username", |
| 1848 |
CRED_SPECIFIED); |
| 1849 |
cli_credentials_set_password(user_creds, |
| 1850 |
generate_random_password(user_creds, 8, 255), |
| 1851 |
CRED_SPECIFIED); |
| 1852 |
|
| 1853 |
if (!create_user(torture, torture, cli, NULL, |
| 1854 |
cli_credentials_get_username(user_creds), |
| 1855 |
cli_credentials_get_password(user_creds), |
| 1856 |
&domain_name, &created_sid)) { |
| 1857 |
torture_fail(torture, "create_user failed\n"); |
| 1858 |
} |
| 1859 |
|
| 1860 |
cli_credentials_set_domain(user_creds, domain_name, |
| 1861 |
CRED_SPECIFIED); |
| 1862 |
|
| 1863 |
{ |
| 1864 |
struct smbcli_session *session2; |
| 1865 |
struct smb_composite_sesssetup setup; |
| 1866 |
struct smbcli_tree *tree; |
| 1867 |
|
| 1868 |
session2 = smbcli_session_init(cli->transport, torture, false, session_options); |
| 1869 |
if (session2 == NULL) { |
| 1870 |
torture_fail(torture, "smbcli_session_init failed\n"); |
| 1871 |
} |
| 1872 |
|
| 1873 |
setup.in.sesskey = cli->transport->negotiate.sesskey; |
| 1874 |
setup.in.capabilities = cli->transport->negotiate.capabilities; |
| 1875 |
setup.in.workgroup = ""; |
| 1876 |
setup.in.credentials = user_creds; |
| 1877 |
setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx); |
| 1878 |
|
| 1879 |
status = smb_composite_sesssetup(session2, &setup); |
| 1880 |
torture_assert_ntstatus_ok(torture, status, "session setup with new user failed"); |
| 1881 |
|
| 1882 |
session2->vuid = setup.out.vuid; |
| 1883 |
|
| 1884 |
if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2, |
| 1885 |
"IPC$", &tree))) { |
| 1886 |
torture_fail(torture, "secondary_tcon failed\n"); |
| 1887 |
} |
| 1888 |
|
| 1889 |
if (!(user_sid = whoami(torture, torture, tree))) { |
| 1890 |
torture_fail_goto(torture, del, "whoami on user connection failed\n"); |
| 1891 |
ret = false; |
| 1892 |
goto del; |
| 1893 |
} |
| 1894 |
|
| 1895 |
talloc_free(tree); |
| 1896 |
} |
| 1897 |
|
| 1898 |
torture_comment(torture, "Created %s, found %s\n", |
| 1899 |
dom_sid_string(torture, created_sid), |
| 1900 |
dom_sid_string(torture, user_sid)); |
| 1901 |
|
| 1902 |
if (!dom_sid_equal(created_sid, user_sid)) { |
| 1903 |
ret = false; |
| 1904 |
} |
| 1905 |
|
| 1906 |
del: |
| 1907 |
if (!delete_user(torture, cli, |
| 1908 |
NULL, |
| 1909 |
cli_credentials_get_username(user_creds))) { |
| 1910 |
torture_fail(torture, "delete_user failed\n"); |
| 1911 |
} |
| 1912 |
|
| 1913 |
return ret; |
| 1914 |
} |
| 1915 |
|
| 1916 |
static bool test_NetShareGetInfo(struct torture_context *tctx, |
| 1917 |
struct dcerpc_pipe *p, |
| 1918 |
const char *sharename) |
| 1919 |
{ |
| 1920 |
NTSTATUS status; |
| 1921 |
struct srvsvc_NetShareGetInfo r; |
| 1922 |
union srvsvc_NetShareInfo info; |
| 1923 |
uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 }; |
| 1924 |
size_t i; |
| 1925 |
bool ret = true; |
| 1926 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1927 |
|
| 1928 |
r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", |
| 1929 |
dcerpc_server_name(p)); |
| 1930 |
r.in.share_name = sharename; |
| 1931 |
r.out.info = &info; |
| 1932 |
|
| 1933 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 1934 |
r.in.level = levels[i]; |
| 1935 |
|
| 1936 |
torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n", |
| 1937 |
r.in.level, r.in.share_name); |
| 1938 |
|
| 1939 |
status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r); |
| 1940 |
if (!NT_STATUS_IS_OK(status)) { |
| 1941 |
torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed" |
| 1942 |
" - %s\n", r.in.level, r.in.share_name, |
| 1943 |
nt_errstr(status)); |
| 1944 |
ret = false; |
| 1945 |
continue; |
| 1946 |
} |
| 1947 |
if (!W_ERROR_IS_OK(r.out.result)) { |
| 1948 |
torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed " |
| 1949 |
"- %s\n", r.in.level, r.in.share_name, |
| 1950 |
win_errstr(r.out.result)); |
| 1951 |
ret = false; |
| 1952 |
continue; |
| 1953 |
} |
| 1954 |
} |
| 1955 |
|
| 1956 |
return ret; |
| 1957 |
} |
| 1958 |
|
| 1959 |
static bool test_NetShareEnum(struct torture_context *tctx, |
| 1960 |
struct dcerpc_pipe *p, |
| 1961 |
const char **one_sharename) |
| 1962 |
{ |
| 1963 |
NTSTATUS status; |
| 1964 |
struct srvsvc_NetShareEnum r; |
| 1965 |
struct srvsvc_NetShareInfoCtr info_ctr; |
| 1966 |
struct srvsvc_NetShareCtr0 c0; |
| 1967 |
struct srvsvc_NetShareCtr1 c1; |
| 1968 |
struct srvsvc_NetShareCtr2 c2; |
| 1969 |
struct srvsvc_NetShareCtr501 c501; |
| 1970 |
struct srvsvc_NetShareCtr502 c502; |
| 1971 |
struct srvsvc_NetShareCtr1004 c1004; |
| 1972 |
struct srvsvc_NetShareCtr1005 c1005; |
| 1973 |
struct srvsvc_NetShareCtr1006 c1006; |
| 1974 |
struct srvsvc_NetShareCtr1007 c1007; |
| 1975 |
uint32_t totalentries = 0; |
| 1976 |
uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 }; |
| 1977 |
size_t i; |
| 1978 |
bool ret = true; |
| 1979 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1980 |
|
| 1981 |
ZERO_STRUCT(info_ctr); |
| 1982 |
|
| 1983 |
r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p)); |
| 1984 |
r.in.info_ctr = &info_ctr; |
| 1985 |
r.in.max_buffer = (uint32_t)-1; |
| 1986 |
r.in.resume_handle = NULL; |
| 1987 |
r.out.totalentries = &totalentries; |
| 1988 |
r.out.info_ctr = &info_ctr; |
| 1989 |
|
| 1990 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 1991 |
info_ctr.level = levels[i]; |
| 1992 |
|
| 1993 |
switch (info_ctr.level) { |
| 1994 |
case 0: |
| 1995 |
ZERO_STRUCT(c0); |
| 1996 |
info_ctr.ctr.ctr0 = &c0; |
| 1997 |
break; |
| 1998 |
case 1: |
| 1999 |
ZERO_STRUCT(c1); |
| 2000 |
info_ctr.ctr.ctr1 = &c1; |
| 2001 |
break; |
| 2002 |
case 2: |
| 2003 |
ZERO_STRUCT(c2); |
| 2004 |
info_ctr.ctr.ctr2 = &c2; |
| 2005 |
break; |
| 2006 |
case 501: |
| 2007 |
ZERO_STRUCT(c501); |
| 2008 |
info_ctr.ctr.ctr501 = &c501; |
| 2009 |
break; |
| 2010 |
case 502: |
| 2011 |
ZERO_STRUCT(c502); |
| 2012 |
info_ctr.ctr.ctr502 = &c502; |
| 2013 |
break; |
| 2014 |
case 1004: |
| 2015 |
ZERO_STRUCT(c1004); |
| 2016 |
info_ctr.ctr.ctr1004 = &c1004; |
| 2017 |
break; |
| 2018 |
case 1005: |
| 2019 |
ZERO_STRUCT(c1005); |
| 2020 |
info_ctr.ctr.ctr1005 = &c1005; |
| 2021 |
break; |
| 2022 |
case 1006: |
| 2023 |
ZERO_STRUCT(c1006); |
| 2024 |
info_ctr.ctr.ctr1006 = &c1006; |
| 2025 |
break; |
| 2026 |
case 1007: |
| 2027 |
ZERO_STRUCT(c1007); |
| 2028 |
info_ctr.ctr.ctr1007 = &c1007; |
| 2029 |
break; |
| 2030 |
} |
| 2031 |
|
| 2032 |
torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level); |
| 2033 |
|
| 2034 |
status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r); |
| 2035 |
if (!NT_STATUS_IS_OK(status)) { |
| 2036 |
torture_warning(tctx, "NetShareEnum level %u failed - %s\n", |
| 2037 |
info_ctr.level, nt_errstr(status)); |
| 2038 |
ret = false; |
| 2039 |
continue; |
| 2040 |
} |
| 2041 |
if (!W_ERROR_IS_OK(r.out.result)) { |
| 2042 |
torture_warning(tctx, "NetShareEnum level %u failed - %s\n", |
| 2043 |
info_ctr.level, win_errstr(r.out.result)); |
| 2044 |
continue; |
| 2045 |
} |
| 2046 |
if (info_ctr.level == 0) { |
| 2047 |
struct srvsvc_NetShareCtr0 *ctr = r.out.info_ctr->ctr.ctr0; |
| 2048 |
if (ctr->count > 0) { |
| 2049 |
*one_sharename = ctr->array[0].name; |
| 2050 |
} |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
return ret; |
| 2055 |
} |
| 2056 |
|
| 2057 |
static bool torture_samba3_rpc_srvsvc(struct torture_context *torture) |
| 2058 |
{ |
| 2059 |
struct dcerpc_pipe *p; |
| 2060 |
const char *sharename = NULL; |
| 2061 |
bool ret = true; |
| 2062 |
|
| 2063 |
torture_assert_ntstatus_ok(torture, |
| 2064 |
torture_rpc_connection(torture, &p, &ndr_table_srvsvc), |
| 2065 |
"failed to open srvsvc"); |
| 2066 |
|
| 2067 |
ret &= test_NetShareEnum(torture, p, &sharename); |
| 2068 |
if (sharename == NULL) { |
| 2069 |
torture_comment(torture, "did not get sharename\n"); |
| 2070 |
} else { |
| 2071 |
ret &= test_NetShareGetInfo(torture, p, sharename); |
| 2072 |
} |
| 2073 |
|
| 2074 |
return ret; |
| 2075 |
} |
| 2076 |
|
| 2077 |
/* |
| 2078 |
* Do a ReqChallenge/Auth2 with a random wks name, make sure it returns |
| 2079 |
* NT_STATUS_NO_SAM_ACCOUNT |
| 2080 |
*/ |
| 2081 |
|
| 2082 |
static bool torture_samba3_rpc_randomauth2(struct torture_context *torture) |
| 2083 |
{ |
| 2084 |
TALLOC_CTX *mem_ctx; |
| 2085 |
struct dcerpc_pipe *net_pipe; |
| 2086 |
struct dcerpc_binding_handle *net_handle; |
| 2087 |
char wksname[15]; |
| 2088 |
bool result = false; |
| 2089 |
NTSTATUS status; |
| 2090 |
struct netr_ServerReqChallenge r; |
| 2091 |
struct netr_Credential netr_cli_creds; |
| 2092 |
struct netr_Credential netr_srv_creds; |
| 2093 |
uint32_t negotiate_flags; |
| 2094 |
struct netr_ServerAuthenticate2 a; |
| 2095 |
struct netlogon_creds_CredentialState *creds_state; |
| 2096 |
struct netr_Credential netr_cred; |
| 2097 |
struct samr_Password mach_pw; |
| 2098 |
struct smbcli_state *cli; |
| 2099 |
|
| 2100 |
if (!(mem_ctx = talloc_new(torture))) { |
| 2101 |
torture_comment(torture, "talloc_new failed\n"); |
| 2102 |
return false; |
| 2103 |
} |
| 2104 |
|
| 2105 |
generate_random_str_list_buf(wksname, |
| 2106 |
sizeof(wksname), |
| 2107 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); |
| 2108 |
|
| 2109 |
if (!(torture_open_connection_share( |
| 2110 |
mem_ctx, &cli, |
| 2111 |
torture, torture_setting_string(torture, "host", NULL), |
| 2112 |
"IPC$", torture->ev))) { |
| 2113 |
torture_comment(torture, "IPC$ connection failed\n"); |
| 2114 |
goto done; |
| 2115 |
} |
| 2116 |
|
| 2117 |
status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\netlogon", |
| 2118 |
&ndr_table_netlogon, &net_pipe); |
| 2119 |
torture_assert_ntstatus_ok_goto(torture, status, result, done, |
| 2120 |
"pipe_bind_smb failed"); |
| 2121 |
net_handle = net_pipe->binding_handle; |
| 2122 |
|
| 2123 |
r.in.computer_name = wksname; |
| 2124 |
r.in.server_name = talloc_asprintf( |
| 2125 |
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe)); |
| 2126 |
if (r.in.server_name == NULL) { |
| 2127 |
torture_comment(torture, "talloc_asprintf failed\n"); |
| 2128 |
goto done; |
| 2129 |
} |
| 2130 |
generate_random_buffer(netr_cli_creds.data, |
| 2131 |
sizeof(netr_cli_creds.data)); |
| 2132 |
r.in.credentials = &netr_cli_creds; |
| 2133 |
r.out.return_credentials = &netr_srv_creds; |
| 2134 |
|
| 2135 |
status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r); |
| 2136 |
if (!NT_STATUS_IS_OK(status)) { |
| 2137 |
torture_comment(torture, "netr_ServerReqChallenge failed: %s\n", |
| 2138 |
nt_errstr(status)); |
| 2139 |
goto done; |
| 2140 |
} |
| 2141 |
if (!NT_STATUS_IS_OK(r.out.result)) { |
| 2142 |
torture_comment(torture, "netr_ServerReqChallenge failed: %s\n", |
| 2143 |
nt_errstr(r.out.result)); |
| 2144 |
goto done; |
| 2145 |
} |
| 2146 |
|
| 2147 |
negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS; |
| 2148 |
E_md4hash("foobar", mach_pw.hash); |
| 2149 |
|
| 2150 |
a.in.server_name = talloc_asprintf( |
| 2151 |
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe)); |
| 2152 |
a.in.account_name = talloc_asprintf( |
| 2153 |
mem_ctx, "%s$", wksname); |
| 2154 |
a.in.computer_name = wksname; |
| 2155 |
a.in.secure_channel_type = SEC_CHAN_WKSTA; |
| 2156 |
a.in.negotiate_flags = &negotiate_flags; |
| 2157 |
a.out.negotiate_flags = &negotiate_flags; |
| 2158 |
a.in.credentials = &netr_cred; |
| 2159 |
a.out.return_credentials = &netr_cred; |
| 2160 |
|
| 2161 |
creds_state = netlogon_creds_client_init(mem_ctx, |
| 2162 |
a.in.account_name, |
| 2163 |
a.in.computer_name, |
| 2164 |
a.in.secure_channel_type, |
| 2165 |
r.in.credentials, |
| 2166 |
r.out.return_credentials, &mach_pw, |
| 2167 |
&netr_cred, |
| 2168 |
negotiate_flags, |
| 2169 |
negotiate_flags); |
| 2170 |
torture_assert(torture, (creds_state != NULL), "memory allocation failed"); |
| 2171 |
|
| 2172 |
status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a); |
| 2173 |
if (!NT_STATUS_IS_OK(status)) { |
| 2174 |
goto done; |
| 2175 |
} |
| 2176 |
if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) { |
| 2177 |
torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, " |
| 2178 |
"expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n", |
| 2179 |
nt_errstr(a.out.result)); |
| 2180 |
goto done; |
| 2181 |
} |
| 2182 |
|
| 2183 |
result = true; |
| 2184 |
done: |
| 2185 |
talloc_free(mem_ctx); |
| 2186 |
return result; |
| 2187 |
} |
| 2188 |
|
| 2189 |
static struct security_descriptor *get_sharesec(struct torture_context *tctx, |
| 2190 |
TALLOC_CTX *mem_ctx, |
| 2191 |
struct smbcli_session *sess, |
| 2192 |
const char *sharename) |
| 2193 |
{ |
| 2194 |
struct smbcli_tree *tree; |
| 2195 |
TALLOC_CTX *tmp_ctx; |
| 2196 |
struct dcerpc_pipe *p; |
| 2197 |
struct dcerpc_binding_handle *b; |
| 2198 |
NTSTATUS status; |
| 2199 |
struct srvsvc_NetShareGetInfo r; |
| 2200 |
union srvsvc_NetShareInfo info; |
| 2201 |
struct security_descriptor *result; |
| 2202 |
|
| 2203 |
if (!(tmp_ctx = talloc_new(mem_ctx))) { |
| 2204 |
torture_comment(tctx, "talloc_new failed\n"); |
| 2205 |
return NULL; |
| 2206 |
} |
| 2207 |
|
| 2208 |
if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) { |
| 2209 |
torture_comment(tctx, "secondary_tcon failed\n"); |
| 2210 |
talloc_free(tmp_ctx); |
| 2211 |
return NULL; |
| 2212 |
} |
| 2213 |
|
| 2214 |
status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc", |
| 2215 |
&ndr_table_srvsvc, &p); |
| 2216 |
if (!NT_STATUS_IS_OK(status)) { |
| 2217 |
torture_warning(tctx, "could not bind to srvsvc pipe: %s\n", |
| 2218 |
nt_errstr(status)); |
| 2219 |
talloc_free(tmp_ctx); |
| 2220 |
return NULL; |
| 2221 |
} |
| 2222 |
b = p->binding_handle; |
| 2223 |
|
| 2224 |
#if 0 |
| 2225 |
p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT; |
| 2226 |
#endif |
| 2227 |
|
| 2228 |
r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s", |
| 2229 |
dcerpc_server_name(p)); |
| 2230 |
r.in.share_name = sharename; |
| 2231 |
r.in.level = 502; |
| 2232 |
r.out.info = &info; |
| 2233 |
|
| 2234 |
status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r); |
| 2235 |
if (!NT_STATUS_IS_OK(status)) { |
| 2236 |
torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n", |
| 2237 |
nt_errstr(status)); |
| 2238 |
talloc_free(tmp_ctx); |
| 2239 |
return NULL; |
| 2240 |
} |
| 2241 |
if (!W_ERROR_IS_OK(r.out.result)) { |
| 2242 |
torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n", |
| 2243 |
win_errstr(r.out.result)); |
| 2244 |
talloc_free(tmp_ctx); |
| 2245 |
return NULL; |
| 2246 |
} |
| 2247 |
|
| 2248 |
result = talloc_steal(mem_ctx, info.info502->sd_buf.sd); |
| 2249 |
talloc_free(tmp_ctx); |
| 2250 |
return result; |
| 2251 |
} |
| 2252 |
|
| 2253 |
static NTSTATUS set_sharesec(struct torture_context *tctx, |
| 2254 |
TALLOC_CTX *mem_ctx, |
| 2255 |
struct smbcli_session *sess, |
| 2256 |
const char *sharename, |
| 2257 |
struct security_descriptor *sd) |
| 2258 |
{ |
| 2259 |
struct smbcli_tree *tree; |
| 2260 |
TALLOC_CTX *tmp_ctx; |
| 2261 |
struct dcerpc_pipe *p; |
| 2262 |
struct dcerpc_binding_handle *b; |
| 2263 |
NTSTATUS status; |
| 2264 |
struct sec_desc_buf i; |
| 2265 |
struct srvsvc_NetShareSetInfo r; |
| 2266 |
union srvsvc_NetShareInfo info; |
| 2267 |
uint32_t error = 0; |
| 2268 |
|
| 2269 |
if (!(tmp_ctx = talloc_new(mem_ctx))) { |
| 2270 |
torture_comment(tctx, "talloc_new failed\n"); |
| 2271 |
return NT_STATUS_NO_MEMORY; |
| 2272 |
} |
| 2273 |
|
| 2274 |
if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) { |
| 2275 |
torture_comment(tctx, "secondary_tcon failed\n"); |
| 2276 |
talloc_free(tmp_ctx); |
| 2277 |
return NT_STATUS_UNSUCCESSFUL; |
| 2278 |
} |
| 2279 |
|
| 2280 |
status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc", |
| 2281 |
&ndr_table_srvsvc, &p); |
| 2282 |
if (!NT_STATUS_IS_OK(status)) { |
| 2283 |
torture_warning(tctx, "could not bind to srvsvc pipe: %s\n", |
| 2284 |
nt_errstr(status)); |
| 2285 |
talloc_free(tmp_ctx); |
| 2286 |
return NT_STATUS_UNSUCCESSFUL; |
| 2287 |
} |
| 2288 |
b = p->binding_handle; |
| 2289 |
|
| 2290 |
#if 0 |
| 2291 |
p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT; |
| 2292 |
#endif |
| 2293 |
|
| 2294 |
r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s", |
| 2295 |
dcerpc_server_name(p)); |
| 2296 |
r.in.share_name = sharename; |
| 2297 |
r.in.level = 1501; |
| 2298 |
i.sd = sd; |
| 2299 |
info.info1501 = &i; |
| 2300 |
r.in.info = &info; |
| 2301 |
r.in.parm_error = &error; |
| 2302 |
|
| 2303 |
status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r); |
| 2304 |
if (!NT_STATUS_IS_OK(status)) { |
| 2305 |
torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n", |
| 2306 |
nt_errstr(status)); |
| 2307 |
} |
| 2308 |
if (!W_ERROR_IS_OK(r.out.result)) { |
| 2309 |
torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n", |
| 2310 |
win_errstr(r.out.result)); |
| 2311 |
status = werror_to_ntstatus(r.out.result); |
| 2312 |
} |
| 2313 |
talloc_free(tmp_ctx); |
| 2314 |
return status; |
| 2315 |
} |
| 2316 |
|
| 2317 |
bool try_tcon(struct torture_context *tctx, |
| 2318 |
TALLOC_CTX *mem_ctx, |
| 2319 |
struct security_descriptor *orig_sd, |
| 2320 |
struct smbcli_session *session, |
| 2321 |
const char *sharename, const struct dom_sid *user_sid, |
| 2322 |
unsigned int access_mask, NTSTATUS expected_tcon, |
| 2323 |
NTSTATUS expected_mkdir) |
| 2324 |
{ |
| 2325 |
TALLOC_CTX *tmp_ctx; |
| 2326 |
struct smbcli_tree *rmdir_tree, *tree; |
| 2327 |
struct dom_sid *domain_sid; |
| 2328 |
uint32_t rid; |
| 2329 |
struct security_descriptor *sd; |
| 2330 |
NTSTATUS status; |
| 2331 |
bool ret = true; |
| 2332 |
|
| 2333 |
if (!(tmp_ctx = talloc_new(mem_ctx))) { |
| 2334 |
torture_comment(tctx, "talloc_new failed\n"); |
| 2335 |
return false; |
| 2336 |
} |
| 2337 |
|
| 2338 |
status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree); |
| 2339 |
if (!NT_STATUS_IS_OK(status)) { |
| 2340 |
torture_comment(tctx, "first tcon to delete dir failed\n"); |
| 2341 |
talloc_free(tmp_ctx); |
| 2342 |
return false; |
| 2343 |
} |
| 2344 |
|
| 2345 |
smbcli_rmdir(rmdir_tree, "sharesec_testdir"); |
| 2346 |
|
| 2347 |
if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid, |
| 2348 |
&domain_sid, &rid))) { |
| 2349 |
torture_comment(tctx, "dom_sid_split_rid failed\n"); |
| 2350 |
talloc_free(tmp_ctx); |
| 2351 |
return false; |
| 2352 |
} |
| 2353 |
|
| 2354 |
sd = security_descriptor_dacl_create( |
| 2355 |
tmp_ctx, 0, "S-1-5-32-544", |
| 2356 |
dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid, |
| 2357 |
DOMAIN_RID_USERS)), |
| 2358 |
dom_sid_string(mem_ctx, user_sid), |
| 2359 |
SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL); |
| 2360 |
if (sd == NULL) { |
| 2361 |
torture_comment(tctx, "security_descriptor_dacl_create failed\n"); |
| 2362 |
talloc_free(tmp_ctx); |
| 2363 |
return false; |
| 2364 |
} |
| 2365 |
|
| 2366 |
status = set_sharesec(tctx, mem_ctx, session, sharename, sd); |
| 2367 |
if (!NT_STATUS_IS_OK(status)) { |
| 2368 |
torture_comment(tctx, "custom set_sharesec failed: %s\n", |
| 2369 |
nt_errstr(status)); |
| 2370 |
talloc_free(tmp_ctx); |
| 2371 |
return false; |
| 2372 |
} |
| 2373 |
|
| 2374 |
status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree); |
| 2375 |
if (!NT_STATUS_EQUAL(status, expected_tcon)) { |
| 2376 |
torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon), |
| 2377 |
nt_errstr(status)); |
| 2378 |
ret = false; |
| 2379 |
goto done; |
| 2380 |
} |
| 2381 |
|
| 2382 |
if (!NT_STATUS_IS_OK(status)) { |
| 2383 |
/* An expected non-access, no point in trying to write */ |
| 2384 |
goto done; |
| 2385 |
} |
| 2386 |
|
| 2387 |
status = smbcli_mkdir(tree, "sharesec_testdir"); |
| 2388 |
if (!NT_STATUS_EQUAL(status, expected_mkdir)) { |
| 2389 |
torture_warning(tctx, "Expected %s, got %s\n", |
| 2390 |
nt_errstr(expected_mkdir), nt_errstr(status)); |
| 2391 |
ret = false; |
| 2392 |
} |
| 2393 |
|
| 2394 |
done: |
| 2395 |
smbcli_rmdir(rmdir_tree, "sharesec_testdir"); |
| 2396 |
|
| 2397 |
status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd); |
| 2398 |
if (!NT_STATUS_IS_OK(status)) { |
| 2399 |
torture_comment(tctx, "custom set_sharesec failed: %s\n", |
| 2400 |
nt_errstr(status)); |
| 2401 |
talloc_free(tmp_ctx); |
| 2402 |
return false; |
| 2403 |
} |
| 2404 |
|
| 2405 |
talloc_free(tmp_ctx); |
| 2406 |
return ret; |
| 2407 |
} |
| 2408 |
|
| 2409 |
static bool torture_samba3_rpc_sharesec(struct torture_context *torture) |
| 2410 |
{ |
| 2411 |
struct smbcli_state *cli = NULL; |
| 2412 |
struct security_descriptor *sd = NULL; |
| 2413 |
struct dom_sid *user_sid = NULL; |
| 2414 |
const char *testuser_passwd = NULL; |
| 2415 |
struct cli_credentials *test_credentials = NULL; |
| 2416 |
struct smbcli_options options; |
| 2417 |
struct smbcli_session_options session_options; |
| 2418 |
NTSTATUS status; |
| 2419 |
struct test_join *tj = NULL; |
| 2420 |
struct dcerpc_pipe *lsa_pipe = NULL; |
| 2421 |
const char *priv_array[1]; |
| 2422 |
|
| 2423 |
/* Create a new user. The normal user has SeBackup and SeRestore |
| 2424 |
privs so we can't lock them out with a share security descriptor. */ |
| 2425 |
tj = torture_create_testuser(torture, |
| 2426 |
"sharesec_user", |
| 2427 |
torture_setting_string(torture, "workgroup", NULL), |
| 2428 |
ACB_NORMAL, |
| 2429 |
&testuser_passwd); |
| 2430 |
if (!tj) { |
| 2431 |
torture_fail(torture, "Creating sharesec_user failed\n"); |
| 2432 |
} |
| 2433 |
|
| 2434 |
/* Give them SeDiskOperatorPrivilege but no other privs. */ |
| 2435 |
status = torture_rpc_connection(torture, &lsa_pipe, &ndr_table_lsarpc); |
| 2436 |
if (!NT_STATUS_IS_OK(status)) { |
| 2437 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2438 |
talloc_free(tj); |
| 2439 |
torture_fail(torture, "Error connecting to LSA pipe"); |
| 2440 |
} |
| 2441 |
|
| 2442 |
priv_array[0] = "SeDiskOperatorPrivilege"; |
| 2443 |
if (!torture_setup_privs(torture, |
| 2444 |
lsa_pipe, |
| 2445 |
1, |
| 2446 |
priv_array, |
| 2447 |
torture_join_user_sid(tj))) { |
| 2448 |
talloc_free(lsa_pipe); |
| 2449 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2450 |
talloc_free(tj); |
| 2451 |
torture_fail(torture, "Failed to setup privs\n"); |
| 2452 |
} |
| 2453 |
talloc_free(lsa_pipe); |
| 2454 |
|
| 2455 |
test_credentials = cli_credentials_init(torture); |
| 2456 |
cli_credentials_set_workstation(test_credentials, "localhost", CRED_SPECIFIED); |
| 2457 |
cli_credentials_set_domain(test_credentials, lpcfg_workgroup(torture->lp_ctx), |
| 2458 |
CRED_SPECIFIED); |
| 2459 |
cli_credentials_set_username(test_credentials, "sharesec_user", CRED_SPECIFIED); |
| 2460 |
cli_credentials_set_password(test_credentials, testuser_passwd, CRED_SPECIFIED); |
| 2461 |
|
| 2462 |
ZERO_STRUCT(options); |
| 2463 |
ZERO_STRUCT(session_options); |
| 2464 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 2465 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 2466 |
|
| 2467 |
status = smbcli_full_connection(torture, |
| 2468 |
&cli, |
| 2469 |
torture_setting_string(torture, "host", NULL), |
| 2470 |
"IPC$", |
| 2471 |
NULL, |
| 2472 |
lpcfg_socket_options(torture->lp_ctx), |
| 2473 |
test_credentials, |
| 2474 |
torture->lp_ctx, |
| 2475 |
lpcfg_resolve_context(torture->lp_ctx), |
| 2476 |
torture->ev, |
| 2477 |
&options, |
| 2478 |
&session_options, |
| 2479 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 2480 |
if (!NT_STATUS_IS_OK(status)) { |
| 2481 |
talloc_free(cli); |
| 2482 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2483 |
talloc_free(tj); |
| 2484 |
torture_fail(torture, "Failed to open connection\n"); |
| 2485 |
} |
| 2486 |
|
| 2487 |
if (!(user_sid = whoami(torture, torture, cli->tree))) { |
| 2488 |
talloc_free(cli); |
| 2489 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2490 |
talloc_free(tj); |
| 2491 |
torture_fail(torture, "whoami failed\n"); |
| 2492 |
} |
| 2493 |
|
| 2494 |
sd = get_sharesec(torture, torture, cli->session, |
| 2495 |
torture_setting_string(torture, "share", NULL)); |
| 2496 |
|
| 2497 |
if (!try_tcon(torture, torture, sd, cli->session, |
| 2498 |
torture_setting_string(torture, "share", NULL), |
| 2499 |
user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK)) { |
| 2500 |
talloc_free(cli); |
| 2501 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2502 |
talloc_free(tj); |
| 2503 |
torture_fail(torture, "failed to test tcon with 0 access_mask"); |
| 2504 |
} |
| 2505 |
|
| 2506 |
if (!try_tcon(torture, torture, sd, cli->session, |
| 2507 |
torture_setting_string(torture, "share", NULL), |
| 2508 |
user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK, |
| 2509 |
NT_STATUS_MEDIA_WRITE_PROTECTED)) { |
| 2510 |
talloc_free(cli); |
| 2511 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2512 |
talloc_free(tj); |
| 2513 |
torture_fail(torture, "failed to test tcon with SEC_FILE_READ_DATA access_mask"); |
| 2514 |
} |
| 2515 |
|
| 2516 |
/* sharesec_user doesn't have any rights on the underlying file system. |
| 2517 |
Go back to the normal user. */ |
| 2518 |
|
| 2519 |
talloc_free(cli); |
| 2520 |
cli = NULL; |
| 2521 |
torture_delete_testuser(torture, tj, "sharesec_user"); |
| 2522 |
talloc_free(tj); |
| 2523 |
tj = NULL; |
| 2524 |
|
| 2525 |
if (!(torture_open_connection_share( |
| 2526 |
torture, &cli, torture, torture_setting_string(torture, "host", NULL), |
| 2527 |
"IPC$", torture->ev))) { |
| 2528 |
torture_fail(torture, "IPC$ connection failed\n"); |
| 2529 |
} |
| 2530 |
|
| 2531 |
if (!(user_sid = whoami(torture, torture, cli->tree))) { |
| 2532 |
torture_fail(torture, "whoami failed\n"); |
| 2533 |
} |
| 2534 |
torture_assert(torture, try_tcon( |
| 2535 |
torture, torture, sd, cli->session, |
| 2536 |
torture_setting_string(torture, "share", NULL), |
| 2537 |
user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK), |
| 2538 |
"failed to test tcon with SEC_FILE_ALL access_mask"); |
| 2539 |
|
| 2540 |
return true; |
| 2541 |
} |
| 2542 |
|
| 2543 |
static bool torture_samba3_rpc_lsa(struct torture_context *torture) |
| 2544 |
{ |
| 2545 |
struct dcerpc_pipe *p; |
| 2546 |
struct dcerpc_binding_handle *b; |
| 2547 |
struct policy_handle lsa_handle; |
| 2548 |
|
| 2549 |
torture_assert_ntstatus_ok(torture, |
| 2550 |
torture_rpc_connection(torture, &p, &ndr_table_lsarpc), |
| 2551 |
"failed to setup lsarpc"); |
| 2552 |
|
| 2553 |
b = p->binding_handle; |
| 2554 |
|
| 2555 |
{ |
| 2556 |
struct lsa_ObjectAttribute attr; |
| 2557 |
struct lsa_OpenPolicy2 o; |
| 2558 |
o.in.system_name = talloc_asprintf( |
| 2559 |
torture, "\\\\%s", dcerpc_server_name(p)); |
| 2560 |
ZERO_STRUCT(attr); |
| 2561 |
o.in.attr = &attr; |
| 2562 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 2563 |
o.out.handle = &lsa_handle; |
| 2564 |
|
| 2565 |
torture_assert_ntstatus_ok(torture, |
| 2566 |
dcerpc_lsa_OpenPolicy2_r(b, torture, &o), |
| 2567 |
"dcerpc_lsa_OpenPolicy2 failed"); |
| 2568 |
torture_assert_ntstatus_ok(torture, o.out.result, |
| 2569 |
"dcerpc_lsa_OpenPolicy2 failed"); |
| 2570 |
} |
| 2571 |
|
| 2572 |
{ |
| 2573 |
size_t i; |
| 2574 |
int levels[] = { 2,3,5,6 }; |
| 2575 |
|
| 2576 |
for (i=0; i<ARRAY_SIZE(levels); i++) { |
| 2577 |
struct lsa_QueryInfoPolicy r; |
| 2578 |
union lsa_PolicyInformation *info = NULL; |
| 2579 |
r.in.handle = &lsa_handle; |
| 2580 |
r.in.level = levels[i]; |
| 2581 |
r.out.info = &info; |
| 2582 |
|
| 2583 |
torture_assert_ntstatus_ok(torture, |
| 2584 |
dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r), |
| 2585 |
talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i])); |
| 2586 |
torture_assert_ntstatus_ok(torture, r.out.result, |
| 2587 |
talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i])); |
| 2588 |
} |
| 2589 |
} |
| 2590 |
|
| 2591 |
return true; |
| 2592 |
} |
| 2593 |
|
| 2594 |
static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree, |
| 2595 |
char **name) |
| 2596 |
{ |
| 2597 |
struct rap_WserverGetInfo r; |
| 2598 |
NTSTATUS status; |
| 2599 |
char servername[17]; |
| 2600 |
size_t converted_size; |
| 2601 |
|
| 2602 |
r.in.level = 0; |
| 2603 |
r.in.bufsize = 0xffff; |
| 2604 |
|
| 2605 |
status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r); |
| 2606 |
if (!NT_STATUS_IS_OK(status)) { |
| 2607 |
return status; |
| 2608 |
} |
| 2609 |
|
| 2610 |
memcpy(servername, r.out.info.info0.name, 16); |
| 2611 |
servername[16] = '\0'; |
| 2612 |
|
| 2613 |
if (!pull_ascii_talloc(mem_ctx, name, servername, &converted_size)) { |
| 2614 |
return NT_STATUS_NO_MEMORY; |
| 2615 |
} |
| 2616 |
|
| 2617 |
return NT_STATUS_OK; |
| 2618 |
} |
| 2619 |
|
| 2620 |
static bool rap_get_servername(struct torture_context *tctx, |
| 2621 |
char **servername) |
| 2622 |
{ |
| 2623 |
struct smbcli_state *cli; |
| 2624 |
|
| 2625 |
torture_assert(tctx, |
| 2626 |
torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL), |
| 2627 |
"IPC$", tctx->ev), |
| 2628 |
"IPC$ connection failed"); |
| 2629 |
|
| 2630 |
torture_assert_ntstatus_ok(tctx, |
| 2631 |
get_servername(tctx, cli->tree, servername), |
| 2632 |
"get_servername failed"); |
| 2633 |
|
| 2634 |
talloc_free(cli); |
| 2635 |
|
| 2636 |
return true; |
| 2637 |
} |
| 2638 |
|
| 2639 |
static bool find_printers(struct torture_context *tctx, |
| 2640 |
struct dcerpc_pipe *p, |
| 2641 |
const char ***printers, |
| 2642 |
size_t *num_printers) |
| 2643 |
{ |
| 2644 |
struct srvsvc_NetShareEnum r; |
| 2645 |
struct srvsvc_NetShareInfoCtr info_ctr; |
| 2646 |
struct srvsvc_NetShareCtr1 c1_in; |
| 2647 |
struct srvsvc_NetShareCtr1 *c1; |
| 2648 |
uint32_t totalentries = 0; |
| 2649 |
uint32_t i; |
| 2650 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 2651 |
|
| 2652 |
ZERO_STRUCT(c1_in); |
| 2653 |
info_ctr.level = 1; |
| 2654 |
info_ctr.ctr.ctr1 = &c1_in; |
| 2655 |
|
| 2656 |
r.in.server_unc = talloc_asprintf( |
| 2657 |
tctx, "\\\\%s", dcerpc_server_name(p)); |
| 2658 |
r.in.info_ctr = &info_ctr; |
| 2659 |
r.in.max_buffer = (uint32_t)-1; |
| 2660 |
r.in.resume_handle = NULL; |
| 2661 |
r.out.totalentries = &totalentries; |
| 2662 |
r.out.info_ctr = &info_ctr; |
| 2663 |
|
| 2664 |
torture_assert_ntstatus_ok(tctx, |
| 2665 |
dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r), |
| 2666 |
"NetShareEnum level 1 failed"); |
| 2667 |
torture_assert_werr_ok(tctx, r.out.result, |
| 2668 |
"NetShareEnum level 1 failed"); |
| 2669 |
|
| 2670 |
*printers = NULL; |
| 2671 |
*num_printers = 0; |
| 2672 |
c1 = r.out.info_ctr->ctr.ctr1; |
| 2673 |
for (i=0; i<c1->count; i++) { |
| 2674 |
if (c1->array[i].type != STYPE_PRINTQ) { |
| 2675 |
continue; |
| 2676 |
} |
| 2677 |
if (!add_string_to_array(tctx, c1->array[i].name, |
| 2678 |
printers, num_printers)) { |
| 2679 |
return false; |
| 2680 |
} |
| 2681 |
} |
| 2682 |
|
| 2683 |
return true; |
| 2684 |
} |
| 2685 |
|
| 2686 |
static bool enumprinters(struct torture_context *tctx, |
| 2687 |
struct dcerpc_binding_handle *b, |
| 2688 |
const char *servername, int level, int *num_printers) |
| 2689 |
{ |
| 2690 |
struct spoolss_EnumPrinters r; |
| 2691 |
DATA_BLOB blob; |
| 2692 |
uint32_t needed; |
| 2693 |
uint32_t count; |
| 2694 |
union spoolss_PrinterInfo *info; |
| 2695 |
|
| 2696 |
r.in.flags = PRINTER_ENUM_LOCAL; |
| 2697 |
r.in.server = talloc_asprintf(tctx, "\\\\%s", servername); |
| 2698 |
r.in.level = level; |
| 2699 |
r.in.buffer = NULL; |
| 2700 |
r.in.offered = 0; |
| 2701 |
r.out.needed = &needed; |
| 2702 |
r.out.count = &count; |
| 2703 |
r.out.info = &info; |
| 2704 |
|
| 2705 |
torture_assert_ntstatus_ok(tctx, |
| 2706 |
dcerpc_spoolss_EnumPrinters_r(b, tctx, &r), |
| 2707 |
"dcerpc_spoolss_EnumPrinters failed"); |
| 2708 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 2709 |
"EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER"); |
| 2710 |
|
| 2711 |
blob = data_blob_talloc_zero(tctx, needed); |
| 2712 |
if (blob.data == NULL) { |
| 2713 |
return false; |
| 2714 |
} |
| 2715 |
|
| 2716 |
r.in.buffer = &blob; |
| 2717 |
r.in.offered = needed; |
| 2718 |
|
| 2719 |
torture_assert_ntstatus_ok(tctx, |
| 2720 |
dcerpc_spoolss_EnumPrinters_r(b, tctx, &r), |
| 2721 |
"dcerpc_spoolss_EnumPrinters failed"); |
| 2722 |
torture_assert_werr_ok(tctx, r.out.result, |
| 2723 |
"dcerpc_spoolss_EnumPrinters failed"); |
| 2724 |
|
| 2725 |
*num_printers = count; |
| 2726 |
|
| 2727 |
return true; |
| 2728 |
} |
| 2729 |
|
| 2730 |
static bool getprinterinfo(struct torture_context *tctx, |
| 2731 |
struct dcerpc_binding_handle *b, |
| 2732 |
struct policy_handle *handle, int level, |
| 2733 |
union spoolss_PrinterInfo **res) |
| 2734 |
{ |
| 2735 |
struct spoolss_GetPrinter r; |
| 2736 |
DATA_BLOB blob; |
| 2737 |
uint32_t needed; |
| 2738 |
|
| 2739 |
r.in.handle = handle; |
| 2740 |
r.in.level = level; |
| 2741 |
r.in.buffer = NULL; |
| 2742 |
r.in.offered = 0; |
| 2743 |
r.out.needed = &needed; |
| 2744 |
|
| 2745 |
torture_assert_ntstatus_ok(tctx, |
| 2746 |
dcerpc_spoolss_GetPrinter_r(b, tctx, &r), |
| 2747 |
"dcerpc_spoolss_GetPrinter failed"); |
| 2748 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 2749 |
"GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER"); |
| 2750 |
|
| 2751 |
r.in.handle = handle; |
| 2752 |
r.in.level = level; |
| 2753 |
blob = data_blob_talloc_zero(tctx, needed); |
| 2754 |
if (blob.data == NULL) { |
| 2755 |
return false; |
| 2756 |
} |
| 2757 |
r.in.buffer = &blob; |
| 2758 |
r.in.offered = needed; |
| 2759 |
|
| 2760 |
torture_assert_ntstatus_ok(tctx, |
| 2761 |
dcerpc_spoolss_GetPrinter_r(b, tctx, &r), |
| 2762 |
"dcerpc_spoolss_GetPrinter failed"); |
| 2763 |
torture_assert_werr_ok(tctx, r.out.result, |
| 2764 |
"dcerpc_spoolss_GetPrinter failed"); |
| 2765 |
|
| 2766 |
if (res != NULL) { |
| 2767 |
*res = talloc_steal(tctx, r.out.info); |
| 2768 |
} |
| 2769 |
|
| 2770 |
return true; |
| 2771 |
} |
| 2772 |
|
| 2773 |
static bool torture_samba3_rpc_spoolss(struct torture_context *torture) |
| 2774 |
{ |
| 2775 |
struct dcerpc_pipe *p, *p2; |
| 2776 |
struct dcerpc_binding_handle *b; |
| 2777 |
struct policy_handle server_handle, printer_handle; |
| 2778 |
const char **printers; |
| 2779 |
size_t num_printers; |
| 2780 |
struct spoolss_UserLevel1 userlevel1; |
| 2781 |
char *servername; |
| 2782 |
|
| 2783 |
torture_assert(torture, |
| 2784 |
rap_get_servername(torture, &servername), |
| 2785 |
"failed to rap servername"); |
| 2786 |
|
| 2787 |
torture_assert_ntstatus_ok(torture, |
| 2788 |
torture_rpc_connection(torture, &p2, &ndr_table_srvsvc), |
| 2789 |
"failed to setup srvsvc"); |
| 2790 |
|
| 2791 |
torture_assert(torture, |
| 2792 |
find_printers(torture, p2, &printers, &num_printers), |
| 2793 |
"failed to find printers via srvsvc"); |
| 2794 |
|
| 2795 |
talloc_free(p2); |
| 2796 |
|
| 2797 |
if (num_printers == 0) { |
| 2798 |
torture_skip(torture, "Did not find printers\n"); |
| 2799 |
return true; |
| 2800 |
} |
| 2801 |
|
| 2802 |
torture_assert_ntstatus_ok(torture, |
| 2803 |
torture_rpc_connection(torture, &p, &ndr_table_spoolss), |
| 2804 |
"failed to setup spoolss"); |
| 2805 |
|
| 2806 |
b = p->binding_handle; |
| 2807 |
|
| 2808 |
ZERO_STRUCT(userlevel1); |
| 2809 |
userlevel1.client = talloc_asprintf( |
| 2810 |
torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx)); |
| 2811 |
userlevel1.user = cli_credentials_get_username( |
| 2812 |
samba_cmdline_get_creds()); |
| 2813 |
userlevel1.build = 2600; |
| 2814 |
userlevel1.major = 3; |
| 2815 |
userlevel1.minor = 0; |
| 2816 |
userlevel1.processor = 0; |
| 2817 |
|
| 2818 |
{ |
| 2819 |
struct spoolss_OpenPrinterEx r; |
| 2820 |
|
| 2821 |
ZERO_STRUCT(r); |
| 2822 |
r.in.printername = talloc_asprintf(torture, "\\\\%s", |
| 2823 |
servername); |
| 2824 |
r.in.datatype = NULL; |
| 2825 |
r.in.access_mask = 0; |
| 2826 |
r.in.userlevel_ctr.level = 1; |
| 2827 |
r.in.userlevel_ctr.user_info.level1 = &userlevel1; |
| 2828 |
r.out.handle = &server_handle; |
| 2829 |
|
| 2830 |
torture_assert_ntstatus_ok(torture, |
| 2831 |
dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r), |
| 2832 |
"dcerpc_spoolss_OpenPrinterEx failed"); |
| 2833 |
torture_assert_werr_ok(torture, r.out.result, |
| 2834 |
"dcerpc_spoolss_OpenPrinterEx failed"); |
| 2835 |
} |
| 2836 |
|
| 2837 |
{ |
| 2838 |
struct spoolss_ClosePrinter r; |
| 2839 |
|
| 2840 |
r.in.handle = &server_handle; |
| 2841 |
r.out.handle = &server_handle; |
| 2842 |
|
| 2843 |
torture_assert_ntstatus_ok(torture, |
| 2844 |
dcerpc_spoolss_ClosePrinter_r(b, torture, &r), |
| 2845 |
"dcerpc_spoolss_ClosePrinter failed"); |
| 2846 |
torture_assert_werr_ok(torture, r.out.result, |
| 2847 |
"dcerpc_spoolss_ClosePrinter failed"); |
| 2848 |
} |
| 2849 |
|
| 2850 |
{ |
| 2851 |
struct spoolss_OpenPrinterEx r; |
| 2852 |
|
| 2853 |
ZERO_STRUCT(r); |
| 2854 |
r.in.printername = talloc_asprintf( |
| 2855 |
torture, "\\\\%s\\%s", servername, printers[0]); |
| 2856 |
r.in.datatype = NULL; |
| 2857 |
r.in.access_mask = 0; |
| 2858 |
r.in.userlevel_ctr.level = 1; |
| 2859 |
r.in.userlevel_ctr.user_info.level1 = &userlevel1; |
| 2860 |
r.out.handle = &printer_handle; |
| 2861 |
|
| 2862 |
torture_assert_ntstatus_ok(torture, |
| 2863 |
dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r), |
| 2864 |
"dcerpc_spoolss_OpenPrinterEx failed"); |
| 2865 |
torture_assert_werr_ok(torture, r.out.result, |
| 2866 |
"dcerpc_spoolss_OpenPrinterEx failed"); |
| 2867 |
} |
| 2868 |
|
| 2869 |
{ |
| 2870 |
int i; |
| 2871 |
|
| 2872 |
for (i=0; i<8; i++) { |
| 2873 |
torture_assert(torture, |
| 2874 |
getprinterinfo(torture, b, &printer_handle, i, NULL), |
| 2875 |
talloc_asprintf(torture, "getprinterinfo %d failed", i)); |
| 2876 |
} |
| 2877 |
} |
| 2878 |
|
| 2879 |
{ |
| 2880 |
struct spoolss_ClosePrinter r; |
| 2881 |
|
| 2882 |
r.in.handle = &printer_handle; |
| 2883 |
r.out.handle = &printer_handle; |
| 2884 |
|
| 2885 |
torture_assert_ntstatus_ok(torture, |
| 2886 |
dcerpc_spoolss_ClosePrinter_r(b, torture, &r), |
| 2887 |
"dcerpc_spoolss_ClosePrinter failed"); |
| 2888 |
torture_assert_werr_ok(torture, r.out.result, |
| 2889 |
"dcerpc_spoolss_ClosePrinter failed"); |
| 2890 |
} |
| 2891 |
|
| 2892 |
{ |
| 2893 |
int num_enumerated; |
| 2894 |
|
| 2895 |
torture_assert(torture, |
| 2896 |
enumprinters(torture, b, servername, 1, &num_enumerated), |
| 2897 |
"enumprinters failed"); |
| 2898 |
|
| 2899 |
torture_assert_int_equal(torture, num_printers, num_enumerated, |
| 2900 |
"netshareenum / enumprinters lvl 1 numprinter mismatch"); |
| 2901 |
} |
| 2902 |
|
| 2903 |
{ |
| 2904 |
int num_enumerated; |
| 2905 |
|
| 2906 |
torture_assert(torture, |
| 2907 |
enumprinters(torture, b, servername, 2, &num_enumerated), |
| 2908 |
"enumprinters failed"); |
| 2909 |
|
| 2910 |
torture_assert_int_equal(torture, num_printers, num_enumerated, |
| 2911 |
"netshareenum / enumprinters lvl 2 numprinter mismatch"); |
| 2912 |
} |
| 2913 |
|
| 2914 |
return true; |
| 2915 |
} |
| 2916 |
|
| 2917 |
static bool torture_samba3_rpc_wkssvc(struct torture_context *torture) |
| 2918 |
{ |
| 2919 |
struct dcerpc_pipe *p; |
| 2920 |
struct dcerpc_binding_handle *b; |
| 2921 |
char *servername; |
| 2922 |
|
| 2923 |
torture_assert(torture, |
| 2924 |
rap_get_servername(torture, &servername), |
| 2925 |
"failed to rap servername"); |
| 2926 |
|
| 2927 |
torture_assert_ntstatus_ok(torture, |
| 2928 |
torture_rpc_connection(torture, &p, &ndr_table_wkssvc), |
| 2929 |
"failed to setup wkssvc"); |
| 2930 |
|
| 2931 |
b = p->binding_handle; |
| 2932 |
|
| 2933 |
{ |
| 2934 |
struct wkssvc_NetWkstaInfo100 wks100; |
| 2935 |
union wkssvc_NetWkstaInfo info; |
| 2936 |
struct wkssvc_NetWkstaGetInfo r; |
| 2937 |
|
| 2938 |
r.in.server_name = "\\foo"; |
| 2939 |
r.in.level = 100; |
| 2940 |
info.info100 = &wks100; |
| 2941 |
r.out.info = &info; |
| 2942 |
|
| 2943 |
torture_assert_ntstatus_ok(torture, |
| 2944 |
dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r), |
| 2945 |
"dcerpc_wkssvc_NetWksGetInfo failed"); |
| 2946 |
torture_assert_werr_ok(torture, r.out.result, |
| 2947 |
"dcerpc_wkssvc_NetWksGetInfo failed"); |
| 2948 |
|
| 2949 |
torture_assert_str_equal(torture, servername, r.out.info->info100->server_name, |
| 2950 |
"servername RAP / DCERPC inconsistency"); |
| 2951 |
} |
| 2952 |
|
| 2953 |
return true; |
| 2954 |
} |
| 2955 |
|
| 2956 |
static bool winreg_close(struct torture_context *tctx, |
| 2957 |
struct dcerpc_binding_handle *b, |
| 2958 |
struct policy_handle *handle) |
| 2959 |
{ |
| 2960 |
struct winreg_CloseKey c; |
| 2961 |
|
| 2962 |
c.in.handle = c.out.handle = handle; |
| 2963 |
|
| 2964 |
torture_assert_ntstatus_ok(tctx, |
| 2965 |
dcerpc_winreg_CloseKey_r(b, tctx, &c), |
| 2966 |
"winreg_CloseKey failed"); |
| 2967 |
torture_assert_werr_ok(tctx, c.out.result, |
| 2968 |
"winreg_CloseKey failed"); |
| 2969 |
|
| 2970 |
return true; |
| 2971 |
} |
| 2972 |
|
| 2973 |
static bool enumvalues(struct torture_context *tctx, |
| 2974 |
struct dcerpc_binding_handle *b, |
| 2975 |
struct policy_handle *handle) |
| 2976 |
{ |
| 2977 |
uint32_t enum_index = 0; |
| 2978 |
|
| 2979 |
while (1) { |
| 2980 |
struct winreg_EnumValue r; |
| 2981 |
struct winreg_ValNameBuf name; |
| 2982 |
enum winreg_Type type = 0; |
| 2983 |
uint8_t buf8[1024]; |
| 2984 |
NTSTATUS status; |
| 2985 |
uint32_t size, length; |
| 2986 |
|
| 2987 |
ZERO_STRUCT(buf8); |
| 2988 |
r.in.handle = handle; |
| 2989 |
r.in.enum_index = enum_index; |
| 2990 |
name.name = ""; |
| 2991 |
name.size = 1024; |
| 2992 |
r.in.name = r.out.name = &name; |
| 2993 |
size = 1024; |
| 2994 |
length = 5; |
| 2995 |
r.in.type = &type; |
| 2996 |
r.in.value = buf8; |
| 2997 |
r.in.size = &size; |
| 2998 |
r.in.length = &length; |
| 2999 |
|
| 3000 |
status = dcerpc_winreg_EnumValue_r(b, tctx, &r); |
| 3001 |
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) { |
| 3002 |
return true; |
| 3003 |
} |
| 3004 |
enum_index += 1; |
| 3005 |
} |
| 3006 |
} |
| 3007 |
|
| 3008 |
static bool enumkeys(struct torture_context *tctx, |
| 3009 |
struct dcerpc_binding_handle *b, |
| 3010 |
struct policy_handle *handle, |
| 3011 |
int depth) |
| 3012 |
{ |
| 3013 |
struct winreg_EnumKey r; |
| 3014 |
struct winreg_StringBuf kclass, name; |
| 3015 |
NTSTATUS status; |
| 3016 |
NTTIME t = 0; |
| 3017 |
|
| 3018 |
if (depth <= 0) { |
| 3019 |
return true; |
| 3020 |
} |
| 3021 |
|
| 3022 |
kclass.name = ""; |
| 3023 |
kclass.size = 1024; |
| 3024 |
|
| 3025 |
r.in.handle = handle; |
| 3026 |
r.in.enum_index = 0; |
| 3027 |
r.in.name = &name; |
| 3028 |
r.in.keyclass = &kclass; |
| 3029 |
r.out.name = &name; |
| 3030 |
r.in.last_changed_time = &t; |
| 3031 |
|
| 3032 |
do { |
| 3033 |
struct winreg_OpenKey o; |
| 3034 |
struct policy_handle key_handle; |
| 3035 |
int i; |
| 3036 |
|
| 3037 |
name.name = NULL; |
| 3038 |
name.size = 1024; |
| 3039 |
|
| 3040 |
status = dcerpc_winreg_EnumKey_r(b, tctx, &r); |
| 3041 |
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) { |
| 3042 |
/* We're done enumerating */ |
| 3043 |
return true; |
| 3044 |
} |
| 3045 |
|
| 3046 |
for (i=0; i<10-depth; i++) { |
| 3047 |
torture_comment(tctx, " "); |
| 3048 |
} |
| 3049 |
torture_comment(tctx, "%s\n", r.out.name->name); |
| 3050 |
|
| 3051 |
o.in.parent_handle = handle; |
| 3052 |
o.in.keyname.name = r.out.name->name; |
| 3053 |
o.in.options = 0; |
| 3054 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 3055 |
o.out.handle = &key_handle; |
| 3056 |
|
| 3057 |
status = dcerpc_winreg_OpenKey_r(b, tctx, &o); |
| 3058 |
if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) { |
| 3059 |
enumkeys(tctx, b, &key_handle, depth-1); |
| 3060 |
enumvalues(tctx, b, &key_handle); |
| 3061 |
torture_assert(tctx, winreg_close(tctx, b, &key_handle), ""); |
| 3062 |
} |
| 3063 |
|
| 3064 |
r.in.enum_index += 1; |
| 3065 |
} while(true); |
| 3066 |
|
| 3067 |
return true; |
| 3068 |
} |
| 3069 |
|
| 3070 |
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *); |
| 3071 |
|
| 3072 |
static bool test_Open3(struct torture_context *tctx, |
| 3073 |
struct dcerpc_binding_handle *b, |
| 3074 |
const char *name, winreg_open_fn open_fn) |
| 3075 |
{ |
| 3076 |
struct policy_handle handle; |
| 3077 |
struct winreg_OpenHKLM r; |
| 3078 |
|
| 3079 |
r.in.system_name = 0; |
| 3080 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 3081 |
r.out.handle = &handle; |
| 3082 |
|
| 3083 |
torture_assert_ntstatus_ok(tctx, |
| 3084 |
open_fn(b, tctx, &r), |
| 3085 |
talloc_asprintf(tctx, "%s failed", name)); |
| 3086 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3087 |
talloc_asprintf(tctx, "%s failed", name)); |
| 3088 |
|
| 3089 |
enumkeys(tctx, b, &handle, 4); |
| 3090 |
|
| 3091 |
torture_assert(tctx, |
| 3092 |
winreg_close(tctx, b, &handle), |
| 3093 |
"dcerpc_CloseKey failed"); |
| 3094 |
|
| 3095 |
return true; |
| 3096 |
} |
| 3097 |
|
| 3098 |
static bool torture_samba3_rpc_winreg(struct torture_context *torture) |
| 3099 |
{ |
| 3100 |
struct dcerpc_pipe *p; |
| 3101 |
struct dcerpc_binding_handle *b; |
| 3102 |
bool ret = true; |
| 3103 |
struct { |
| 3104 |
const char *name; |
| 3105 |
winreg_open_fn fn; |
| 3106 |
} open_fns[] = { |
| 3107 |
{"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r }, |
| 3108 |
{"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r }, |
| 3109 |
{"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r }, |
| 3110 |
{"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r }, |
| 3111 |
{"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }}; |
| 3112 |
#if 0 |
| 3113 |
int i; |
| 3114 |
#endif |
| 3115 |
|
| 3116 |
torture_assert_ntstatus_ok(torture, |
| 3117 |
torture_rpc_connection(torture, &p, &ndr_table_winreg), |
| 3118 |
"failed to setup winreg"); |
| 3119 |
|
| 3120 |
b = p->binding_handle; |
| 3121 |
|
| 3122 |
#if 1 |
| 3123 |
ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn); |
| 3124 |
#else |
| 3125 |
for (i = 0; i < ARRAY_SIZE(open_fns); i++) { |
| 3126 |
if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn)) |
| 3127 |
ret = false; |
| 3128 |
} |
| 3129 |
#endif |
| 3130 |
return ret; |
| 3131 |
} |
| 3132 |
|
| 3133 |
static bool get_shareinfo(struct torture_context *tctx, |
| 3134 |
struct dcerpc_binding_handle *b, |
| 3135 |
const char *servername, |
| 3136 |
const char *share, |
| 3137 |
struct srvsvc_NetShareInfo502 **info502) |
| 3138 |
{ |
| 3139 |
struct srvsvc_NetShareGetInfo r; |
| 3140 |
union srvsvc_NetShareInfo info; |
| 3141 |
|
| 3142 |
r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername); |
| 3143 |
r.in.share_name = share; |
| 3144 |
r.in.level = 502; |
| 3145 |
r.out.info = &info; |
| 3146 |
|
| 3147 |
torture_assert_ntstatus_ok(tctx, |
| 3148 |
dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r), |
| 3149 |
"srvsvc_NetShareGetInfo failed"); |
| 3150 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3151 |
"srvsvc_NetShareGetInfo failed"); |
| 3152 |
|
| 3153 |
*info502 = talloc_move(tctx, &info.info502); |
| 3154 |
|
| 3155 |
return true; |
| 3156 |
} |
| 3157 |
|
| 3158 |
/* |
| 3159 |
* Get us a handle on HKLM\ |
| 3160 |
*/ |
| 3161 |
|
| 3162 |
static bool get_hklm_handle(struct torture_context *tctx, |
| 3163 |
struct dcerpc_binding_handle *b, |
| 3164 |
struct policy_handle *handle) |
| 3165 |
{ |
| 3166 |
struct winreg_OpenHKLM r; |
| 3167 |
struct policy_handle result; |
| 3168 |
|
| 3169 |
r.in.system_name = 0; |
| 3170 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 3171 |
r.out.handle = &result; |
| 3172 |
|
| 3173 |
torture_assert_ntstatus_ok(tctx, |
| 3174 |
dcerpc_winreg_OpenHKLM_r(b, tctx, &r), |
| 3175 |
"OpenHKLM failed"); |
| 3176 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3177 |
"OpenHKLM failed"); |
| 3178 |
|
| 3179 |
*handle = result; |
| 3180 |
|
| 3181 |
return true; |
| 3182 |
} |
| 3183 |
|
| 3184 |
static bool torture_samba3_createshare(struct torture_context *tctx, |
| 3185 |
struct dcerpc_binding_handle *b, |
| 3186 |
const char *sharename) |
| 3187 |
{ |
| 3188 |
struct policy_handle hklm; |
| 3189 |
struct policy_handle new_handle; |
| 3190 |
struct winreg_CreateKey c; |
| 3191 |
struct winreg_CloseKey cl; |
| 3192 |
enum winreg_CreateAction action_taken = REG_ACTION_NONE; |
| 3193 |
|
| 3194 |
ZERO_STRUCT(c); |
| 3195 |
ZERO_STRUCT(cl); |
| 3196 |
ZERO_STRUCT(hklm); |
| 3197 |
ZERO_STRUCT(new_handle); |
| 3198 |
|
| 3199 |
c.in.handle = &hklm; |
| 3200 |
c.in.name.name = talloc_asprintf( |
| 3201 |
tctx, "software\\samba\\smbconf\\%s", sharename); |
| 3202 |
torture_assert(tctx, c.in.name.name, "talloc_asprintf failed"); |
| 3203 |
|
| 3204 |
c.in.keyclass.name = ""; |
| 3205 |
c.in.options = 0; |
| 3206 |
c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 3207 |
c.in.secdesc = NULL; |
| 3208 |
c.in.action_taken = &action_taken; |
| 3209 |
c.out.new_handle = &new_handle; |
| 3210 |
c.out.action_taken = &action_taken; |
| 3211 |
|
| 3212 |
torture_assert_ntstatus_ok(tctx, |
| 3213 |
dcerpc_winreg_CreateKey_r(b, tctx, &c), |
| 3214 |
"OpenKey failed"); |
| 3215 |
torture_assert_werr_ok(tctx, c.out.result, |
| 3216 |
"OpenKey failed"); |
| 3217 |
|
| 3218 |
cl.in.handle = &new_handle; |
| 3219 |
cl.out.handle = &new_handle; |
| 3220 |
|
| 3221 |
torture_assert_ntstatus_ok(tctx, |
| 3222 |
dcerpc_winreg_CloseKey_r(b, tctx, &cl), |
| 3223 |
"CloseKey failed"); |
| 3224 |
torture_assert_werr_ok(tctx, cl.out.result, |
| 3225 |
"CloseKey failed"); |
| 3226 |
|
| 3227 |
return true; |
| 3228 |
} |
| 3229 |
|
| 3230 |
static bool torture_samba3_deleteshare(struct torture_context *tctx, |
| 3231 |
struct dcerpc_binding_handle *b, |
| 3232 |
const char *sharename) |
| 3233 |
{ |
| 3234 |
struct policy_handle hklm; |
| 3235 |
struct winreg_DeleteKey d; |
| 3236 |
|
| 3237 |
torture_assert(tctx, |
| 3238 |
get_hklm_handle(tctx, b, &hklm), |
| 3239 |
"get_hklm_handle failed"); |
| 3240 |
|
| 3241 |
d.in.handle = &hklm; |
| 3242 |
d.in.key.name = talloc_asprintf( |
| 3243 |
tctx, "software\\samba\\smbconf\\%s", sharename); |
| 3244 |
torture_assert(tctx, d.in.key.name, "talloc_asprintf failed"); |
| 3245 |
|
| 3246 |
torture_assert_ntstatus_ok(tctx, |
| 3247 |
dcerpc_winreg_DeleteKey_r(b, tctx, &d), |
| 3248 |
"DeleteKey failed"); |
| 3249 |
torture_assert_werr_ok(tctx, d.out.result, |
| 3250 |
"DeleteKey failed"); |
| 3251 |
|
| 3252 |
return true; |
| 3253 |
} |
| 3254 |
|
| 3255 |
static bool torture_samba3_setconfig(struct torture_context *tctx, |
| 3256 |
struct dcerpc_binding_handle *b, |
| 3257 |
const char *sharename, |
| 3258 |
const char *parameter, |
| 3259 |
const char *value) |
| 3260 |
{ |
| 3261 |
struct policy_handle hklm, key_handle; |
| 3262 |
struct winreg_OpenKey o; |
| 3263 |
struct winreg_SetValue s; |
| 3264 |
uint32_t type; |
| 3265 |
DATA_BLOB val; |
| 3266 |
|
| 3267 |
torture_assert(tctx, |
| 3268 |
get_hklm_handle(tctx, b, &hklm), |
| 3269 |
"get_hklm_handle failed"); |
| 3270 |
|
| 3271 |
o.in.parent_handle = &hklm; |
| 3272 |
o.in.keyname.name = talloc_asprintf( |
| 3273 |
tctx, "software\\samba\\smbconf\\%s", sharename); |
| 3274 |
torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed"); |
| 3275 |
|
| 3276 |
o.in.options = 0; |
| 3277 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 3278 |
o.out.handle = &key_handle; |
| 3279 |
|
| 3280 |
torture_assert_ntstatus_ok(tctx, |
| 3281 |
dcerpc_winreg_OpenKey_r(b, tctx, &o), |
| 3282 |
"OpenKey failed"); |
| 3283 |
torture_assert_werr_ok(tctx, o.out.result, |
| 3284 |
"OpenKey failed"); |
| 3285 |
|
| 3286 |
torture_assert(tctx, |
| 3287 |
reg_string_to_val(tctx, "REG_SZ", value, &type, &val), |
| 3288 |
"reg_string_to_val failed"); |
| 3289 |
|
| 3290 |
s.in.handle = &key_handle; |
| 3291 |
s.in.name.name = parameter; |
| 3292 |
s.in.type = type; |
| 3293 |
s.in.data = val.data; |
| 3294 |
s.in.size = val.length; |
| 3295 |
|
| 3296 |
torture_assert_ntstatus_ok(tctx, |
| 3297 |
dcerpc_winreg_SetValue_r(b, tctx, &s), |
| 3298 |
"SetValue failed"); |
| 3299 |
torture_assert_werr_ok(tctx, s.out.result, |
| 3300 |
"SetValue failed"); |
| 3301 |
|
| 3302 |
return true; |
| 3303 |
} |
| 3304 |
|
| 3305 |
static bool torture_samba3_regconfig(struct torture_context *torture) |
| 3306 |
{ |
| 3307 |
struct srvsvc_NetShareInfo502 *i = NULL; |
| 3308 |
const char *comment = "Dummer Kommentar"; |
| 3309 |
struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe; |
| 3310 |
|
| 3311 |
torture_assert_ntstatus_ok(torture, |
| 3312 |
torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc), |
| 3313 |
"failed to setup srvsvc"); |
| 3314 |
|
| 3315 |
torture_assert_ntstatus_ok(torture, |
| 3316 |
torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg), |
| 3317 |
"failed to setup winreg"); |
| 3318 |
|
| 3319 |
torture_assert(torture, |
| 3320 |
torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"), |
| 3321 |
"torture_samba3_createshare failed"); |
| 3322 |
|
| 3323 |
torture_assert(torture, |
| 3324 |
torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment), |
| 3325 |
"torture_samba3_setconfig failed"); |
| 3326 |
|
| 3327 |
torture_assert(torture, |
| 3328 |
get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i), |
| 3329 |
"get_shareinfo failed"); |
| 3330 |
|
| 3331 |
torture_assert_str_equal(torture, comment, i->comment, |
| 3332 |
"got unexpected comment"); |
| 3333 |
|
| 3334 |
torture_assert(torture, |
| 3335 |
torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"), |
| 3336 |
"torture_samba3_deleteshare failed"); |
| 3337 |
|
| 3338 |
return true; |
| 3339 |
} |
| 3340 |
|
| 3341 |
/* |
| 3342 |
* Test that even with a result of 0 rids the array is returned as a |
| 3343 |
* non-NULL pointer. Yes, XP does notice. |
| 3344 |
*/ |
| 3345 |
|
| 3346 |
bool torture_samba3_getaliasmembership_0(struct torture_context *torture) |
| 3347 |
{ |
| 3348 |
struct dcerpc_pipe *p; |
| 3349 |
struct dcerpc_binding_handle *b; |
| 3350 |
struct samr_Connect2 c; |
| 3351 |
struct samr_OpenDomain o; |
| 3352 |
struct dom_sid sid; |
| 3353 |
struct lsa_SidPtr ptr; |
| 3354 |
struct lsa_SidArray sids; |
| 3355 |
struct samr_GetAliasMembership g; |
| 3356 |
struct samr_Ids rids; |
| 3357 |
struct policy_handle samr, domain; |
| 3358 |
|
| 3359 |
torture_assert_ntstatus_ok(torture, |
| 3360 |
torture_rpc_connection(torture, &p, &ndr_table_samr), |
| 3361 |
"failed to setup samr"); |
| 3362 |
|
| 3363 |
b = p->binding_handle; |
| 3364 |
|
| 3365 |
c.in.system_name = NULL; |
| 3366 |
c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN; |
| 3367 |
c.out.connect_handle = &samr; |
| 3368 |
torture_assert_ntstatus_ok(torture, |
| 3369 |
dcerpc_samr_Connect2_r(b, torture, &c), |
| 3370 |
""); |
| 3371 |
torture_assert_ntstatus_ok(torture, c.out.result, |
| 3372 |
""); |
| 3373 |
dom_sid_parse("S-1-5-32", &sid); |
| 3374 |
o.in.connect_handle = &samr; |
| 3375 |
o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS; |
| 3376 |
o.in.sid = &sid; |
| 3377 |
o.out.domain_handle = &domain; |
| 3378 |
torture_assert_ntstatus_ok(torture, |
| 3379 |
dcerpc_samr_OpenDomain_r(b, torture, &o), |
| 3380 |
""); |
| 3381 |
torture_assert_ntstatus_ok(torture, o.out.result, |
| 3382 |
""); |
| 3383 |
dom_sid_parse("S-1-2-3-4-5", &sid); |
| 3384 |
ptr.sid = &sid; |
| 3385 |
sids.num_sids = 1; |
| 3386 |
sids.sids = &ptr; |
| 3387 |
g.in.domain_handle = &domain; |
| 3388 |
g.in.sids = &sids; |
| 3389 |
g.out.rids = &rids; |
| 3390 |
torture_assert_ntstatus_ok(torture, |
| 3391 |
dcerpc_samr_GetAliasMembership_r(b, torture, &g), |
| 3392 |
""); |
| 3393 |
torture_assert_ntstatus_ok(torture, g.out.result, |
| 3394 |
""); |
| 3395 |
if (rids.ids == NULL) { |
| 3396 |
/* This is the piece to test here */ |
| 3397 |
torture_fail(torture, |
| 3398 |
"torture_samba3_getaliasmembership_0: " |
| 3399 |
"Server returns NULL rids array\n"); |
| 3400 |
} |
| 3401 |
|
| 3402 |
return true; |
| 3403 |
} |
| 3404 |
|
| 3405 |
/** |
| 3406 |
* Test smb reauthentication while rpc pipe is in use. |
| 3407 |
*/ |
| 3408 |
static bool torture_rpc_smb_reauth1(struct torture_context *torture) |
| 3409 |
{ |
| 3410 |
TALLOC_CTX *mem_ctx; |
| 3411 |
NTSTATUS status; |
| 3412 |
bool ret = false; |
| 3413 |
struct smbcli_state *cli; |
| 3414 |
struct smbcli_options options; |
| 3415 |
struct smbcli_session_options session_options; |
| 3416 |
|
| 3417 |
struct dcerpc_pipe *lsa_pipe; |
| 3418 |
struct dcerpc_binding_handle *lsa_handle; |
| 3419 |
struct lsa_GetUserName r; |
| 3420 |
struct lsa_String *authority_name_p = NULL; |
| 3421 |
char *authority_name_saved = NULL; |
| 3422 |
struct lsa_String *account_name_p = NULL; |
| 3423 |
char *account_name_saved = NULL; |
| 3424 |
struct cli_credentials *anon_creds = NULL; |
| 3425 |
struct smb_composite_sesssetup io; |
| 3426 |
|
| 3427 |
mem_ctx = talloc_init("torture_samba3_reauth"); |
| 3428 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 3429 |
|
| 3430 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 3431 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 3432 |
|
| 3433 |
status = smbcli_full_connection(mem_ctx, &cli, |
| 3434 |
torture_setting_string(torture, "host", NULL), |
| 3435 |
"IPC$", NULL, |
| 3436 |
lpcfg_socket_options(torture->lp_ctx), |
| 3437 |
samba_cmdline_get_creds(), |
| 3438 |
torture->lp_ctx, |
| 3439 |
lpcfg_resolve_context(torture->lp_ctx), |
| 3440 |
torture->ev, &options, &session_options, |
| 3441 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 3442 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3443 |
"smbcli_full_connection failed"); |
| 3444 |
|
| 3445 |
status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\lsarpc", |
| 3446 |
&ndr_table_lsarpc, &lsa_pipe); |
| 3447 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3448 |
"pipe_bind_smb failed"); |
| 3449 |
lsa_handle = lsa_pipe->binding_handle; |
| 3450 |
|
| 3451 |
/* lsa getusername */ |
| 3452 |
|
| 3453 |
ZERO_STRUCT(r); |
| 3454 |
r.in.system_name = "\\"; |
| 3455 |
r.in.account_name = &account_name_p; |
| 3456 |
r.in.authority_name = &authority_name_p; |
| 3457 |
r.out.account_name = &account_name_p; |
| 3458 |
|
| 3459 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3460 |
|
| 3461 |
authority_name_p = *r.out.authority_name; |
| 3462 |
|
| 3463 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3464 |
"GetUserName failed"); |
| 3465 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3466 |
"GetUserName failed"); |
| 3467 |
|
| 3468 |
torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n", |
| 3469 |
authority_name_p->string, |
| 3470 |
account_name_p->string); |
| 3471 |
|
| 3472 |
account_name_saved = talloc_strdup(mem_ctx, account_name_p->string); |
| 3473 |
torture_assert_goto(torture, (account_name_saved != NULL), ret, done, |
| 3474 |
"talloc failed"); |
| 3475 |
authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string); |
| 3476 |
torture_assert_goto(torture, (authority_name_saved != NULL), ret, done, |
| 3477 |
"talloc failed"); |
| 3478 |
|
| 3479 |
/* smb re-authenticate as anonymous */ |
| 3480 |
|
| 3481 |
anon_creds = cli_credentials_init_anon(mem_ctx); |
| 3482 |
|
| 3483 |
ZERO_STRUCT(io); |
| 3484 |
io.in.sesskey = cli->transport->negotiate.sesskey; |
| 3485 |
io.in.capabilities = cli->transport->negotiate.capabilities; |
| 3486 |
io.in.credentials = anon_creds; |
| 3487 |
io.in.workgroup = lpcfg_workgroup(torture->lp_ctx); |
| 3488 |
io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx); |
| 3489 |
|
| 3490 |
status = smb_composite_sesssetup(cli->session, &io); |
| 3491 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3492 |
"session reauth to anon failed"); |
| 3493 |
|
| 3494 |
/* re-do lsa getusername after reauth */ |
| 3495 |
|
| 3496 |
TALLOC_FREE(authority_name_p); |
| 3497 |
TALLOC_FREE(account_name_p); |
| 3498 |
ZERO_STRUCT(r); |
| 3499 |
r.in.system_name = "\\"; |
| 3500 |
r.in.account_name = &account_name_p; |
| 3501 |
r.in.authority_name = &authority_name_p; |
| 3502 |
r.out.account_name = &account_name_p; |
| 3503 |
|
| 3504 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3505 |
|
| 3506 |
authority_name_p = *r.out.authority_name; |
| 3507 |
|
| 3508 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3509 |
"GetUserName failed"); |
| 3510 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3511 |
"GetUserName failed"); |
| 3512 |
|
| 3513 |
torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0), |
| 3514 |
ret, done, "authority_name not equal after reauth to anon"); |
| 3515 |
torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0), |
| 3516 |
ret, done, "account_name not equal after reauth to anon"); |
| 3517 |
|
| 3518 |
/* smb re-auth again to the original user */ |
| 3519 |
|
| 3520 |
ZERO_STRUCT(io); |
| 3521 |
io.in.sesskey = cli->transport->negotiate.sesskey; |
| 3522 |
io.in.capabilities = cli->transport->negotiate.capabilities; |
| 3523 |
io.in.credentials = samba_cmdline_get_creds(); |
| 3524 |
io.in.workgroup = lpcfg_workgroup(torture->lp_ctx); |
| 3525 |
io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx); |
| 3526 |
|
| 3527 |
status = smb_composite_sesssetup(cli->session, &io); |
| 3528 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3529 |
"session reauth to anon failed"); |
| 3530 |
|
| 3531 |
/* re-do lsa getusername */ |
| 3532 |
|
| 3533 |
TALLOC_FREE(authority_name_p); |
| 3534 |
TALLOC_FREE(account_name_p); |
| 3535 |
ZERO_STRUCT(r); |
| 3536 |
r.in.system_name = "\\"; |
| 3537 |
r.in.account_name = &account_name_p; |
| 3538 |
r.in.authority_name = &authority_name_p; |
| 3539 |
r.out.account_name = &account_name_p; |
| 3540 |
|
| 3541 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3542 |
|
| 3543 |
authority_name_p = *r.out.authority_name; |
| 3544 |
|
| 3545 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3546 |
"GetUserName failed"); |
| 3547 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3548 |
"GetUserName failed"); |
| 3549 |
|
| 3550 |
torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0), |
| 3551 |
ret, done, "authority_name not equal after reauth to anon"); |
| 3552 |
torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0), |
| 3553 |
ret, done, "account_name not equal after reauth to anon"); |
| 3554 |
|
| 3555 |
ret = true; |
| 3556 |
|
| 3557 |
done: |
| 3558 |
talloc_free(mem_ctx); |
| 3559 |
return ret; |
| 3560 |
} |
| 3561 |
|
| 3562 |
/** |
| 3563 |
* Test smb reauthentication while rpc pipe is in use. |
| 3564 |
* Open a second lsa bind after reauth to anon. |
| 3565 |
* Do lsa getusername on that second bind. |
| 3566 |
*/ |
| 3567 |
static bool torture_rpc_smb_reauth2(struct torture_context *torture) |
| 3568 |
{ |
| 3569 |
TALLOC_CTX *mem_ctx; |
| 3570 |
NTSTATUS status; |
| 3571 |
bool ret = false; |
| 3572 |
struct smbcli_state *cli; |
| 3573 |
struct smbcli_options options; |
| 3574 |
struct smbcli_session_options session_options; |
| 3575 |
|
| 3576 |
struct dcerpc_pipe *lsa_pipe; |
| 3577 |
struct dcerpc_binding_handle *lsa_handle; |
| 3578 |
struct lsa_GetUserName r; |
| 3579 |
struct lsa_String *authority_name_p = NULL; |
| 3580 |
char *authority_name_saved = NULL; |
| 3581 |
struct lsa_String *account_name_p = NULL; |
| 3582 |
char *account_name_saved = NULL; |
| 3583 |
struct cli_credentials *anon_creds = NULL; |
| 3584 |
struct smb_composite_sesssetup io; |
| 3585 |
|
| 3586 |
mem_ctx = talloc_init("torture_samba3_reauth"); |
| 3587 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 3588 |
|
| 3589 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 3590 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 3591 |
|
| 3592 |
status = smbcli_full_connection(mem_ctx, &cli, |
| 3593 |
torture_setting_string(torture, "host", NULL), |
| 3594 |
"IPC$", NULL, |
| 3595 |
lpcfg_socket_options(torture->lp_ctx), |
| 3596 |
samba_cmdline_get_creds(), |
| 3597 |
torture->lp_ctx, |
| 3598 |
lpcfg_resolve_context(torture->lp_ctx), |
| 3599 |
torture->ev, &options, &session_options, |
| 3600 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 3601 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3602 |
"smbcli_full_connection failed"); |
| 3603 |
|
| 3604 |
/* smb re-authenticate as anonymous */ |
| 3605 |
|
| 3606 |
anon_creds = cli_credentials_init_anon(mem_ctx); |
| 3607 |
|
| 3608 |
ZERO_STRUCT(io); |
| 3609 |
io.in.sesskey = cli->transport->negotiate.sesskey; |
| 3610 |
io.in.capabilities = cli->transport->negotiate.capabilities; |
| 3611 |
io.in.credentials = anon_creds; |
| 3612 |
io.in.workgroup = lpcfg_workgroup(torture->lp_ctx); |
| 3613 |
io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx); |
| 3614 |
|
| 3615 |
status = smb_composite_sesssetup(cli->session, &io); |
| 3616 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3617 |
"session reauth to anon failed"); |
| 3618 |
|
| 3619 |
/* open the lsa pipe */ |
| 3620 |
|
| 3621 |
status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\lsarpc", |
| 3622 |
&ndr_table_lsarpc, &lsa_pipe); |
| 3623 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3624 |
"pipe_bind_smb failed"); |
| 3625 |
lsa_handle = lsa_pipe->binding_handle; |
| 3626 |
|
| 3627 |
/* lsa getusername */ |
| 3628 |
|
| 3629 |
ZERO_STRUCT(r); |
| 3630 |
r.in.system_name = "\\"; |
| 3631 |
r.in.account_name = &account_name_p; |
| 3632 |
r.in.authority_name = &authority_name_p; |
| 3633 |
r.out.account_name = &account_name_p; |
| 3634 |
|
| 3635 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3636 |
|
| 3637 |
authority_name_p = *r.out.authority_name; |
| 3638 |
|
| 3639 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3640 |
"GetUserName failed"); |
| 3641 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3642 |
"GetUserName failed"); |
| 3643 |
|
| 3644 |
torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n", |
| 3645 |
authority_name_p->string, |
| 3646 |
account_name_p->string); |
| 3647 |
|
| 3648 |
account_name_saved = talloc_strdup(mem_ctx, account_name_p->string); |
| 3649 |
torture_assert_goto(torture, (account_name_saved != NULL), ret, done, |
| 3650 |
"talloc failed"); |
| 3651 |
authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string); |
| 3652 |
torture_assert_goto(torture, (authority_name_saved != NULL), ret, done, |
| 3653 |
"talloc failed"); |
| 3654 |
|
| 3655 |
/* smb re-auth again to the original user */ |
| 3656 |
|
| 3657 |
ZERO_STRUCT(io); |
| 3658 |
io.in.sesskey = cli->transport->negotiate.sesskey; |
| 3659 |
io.in.capabilities = cli->transport->negotiate.capabilities; |
| 3660 |
io.in.credentials = samba_cmdline_get_creds(); |
| 3661 |
io.in.workgroup = lpcfg_workgroup(torture->lp_ctx); |
| 3662 |
io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx); |
| 3663 |
|
| 3664 |
status = smb_composite_sesssetup(cli->session, &io); |
| 3665 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3666 |
"session reauth to anon failed"); |
| 3667 |
|
| 3668 |
/* re-do lsa getusername after reauth */ |
| 3669 |
|
| 3670 |
TALLOC_FREE(authority_name_p); |
| 3671 |
TALLOC_FREE(account_name_p); |
| 3672 |
ZERO_STRUCT(r); |
| 3673 |
r.in.system_name = "\\"; |
| 3674 |
r.in.account_name = &account_name_p; |
| 3675 |
r.in.authority_name = &authority_name_p; |
| 3676 |
r.out.account_name = &account_name_p; |
| 3677 |
|
| 3678 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3679 |
|
| 3680 |
authority_name_p = *r.out.authority_name; |
| 3681 |
|
| 3682 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3683 |
"GetUserName failed"); |
| 3684 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3685 |
"GetUserName failed"); |
| 3686 |
|
| 3687 |
torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0), |
| 3688 |
ret, done, "authority_name not equal after reauth to anon"); |
| 3689 |
torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0), |
| 3690 |
ret, done, "account_name not equal after reauth to anon"); |
| 3691 |
|
| 3692 |
ret = true; |
| 3693 |
|
| 3694 |
done: |
| 3695 |
talloc_free(mem_ctx); |
| 3696 |
return ret; |
| 3697 |
} |
| 3698 |
|
| 3699 |
/** |
| 3700 |
* Test smb2 reauthentication while rpc pipe is in use. |
| 3701 |
*/ |
| 3702 |
static bool torture_rpc_smb2_reauth1(struct torture_context *torture) |
| 3703 |
{ |
| 3704 |
TALLOC_CTX *mem_ctx; |
| 3705 |
NTSTATUS status; |
| 3706 |
bool ret = false; |
| 3707 |
struct smbcli_options options; |
| 3708 |
|
| 3709 |
struct dcerpc_pipe *lsa_pipe; |
| 3710 |
struct dcerpc_binding_handle *lsa_handle; |
| 3711 |
struct lsa_GetUserName r; |
| 3712 |
struct lsa_String *authority_name_p = NULL; |
| 3713 |
char *authority_name_saved = NULL; |
| 3714 |
struct lsa_String *account_name_p = NULL; |
| 3715 |
char *account_name_saved = NULL; |
| 3716 |
struct cli_credentials *anon_creds = NULL; |
| 3717 |
const char *host = torture_setting_string(torture, "host", NULL); |
| 3718 |
struct smb2_tree *tree; |
| 3719 |
|
| 3720 |
mem_ctx = talloc_init("torture_samba3_reauth"); |
| 3721 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 3722 |
|
| 3723 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 3724 |
|
| 3725 |
status = smb2_connect(mem_ctx, |
| 3726 |
host, |
| 3727 |
"IPC$", |
| 3728 |
torture->lp_ctx, |
| 3729 |
lpcfg_resolve_context(torture->lp_ctx), |
| 3730 |
samba_cmdline_get_creds(), |
| 3731 |
&tree, |
| 3732 |
torture->ev, |
| 3733 |
&options, |
| 3734 |
lpcfg_socket_options(torture->lp_ctx), |
| 3735 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 3736 |
); |
| 3737 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3738 |
"smb2_connect failed"); |
| 3739 |
|
| 3740 |
status = pipe_bind_smb2(torture, mem_ctx, tree, "lsarpc", |
| 3741 |
&ndr_table_lsarpc, &lsa_pipe); |
| 3742 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3743 |
"pipe_bind_smb2 failed"); |
| 3744 |
lsa_handle = lsa_pipe->binding_handle; |
| 3745 |
|
| 3746 |
/* lsa getusername */ |
| 3747 |
|
| 3748 |
ZERO_STRUCT(r); |
| 3749 |
r.in.system_name = "\\"; |
| 3750 |
r.in.account_name = &account_name_p; |
| 3751 |
r.in.authority_name = &authority_name_p; |
| 3752 |
r.out.account_name = &account_name_p; |
| 3753 |
|
| 3754 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3755 |
|
| 3756 |
authority_name_p = *r.out.authority_name; |
| 3757 |
|
| 3758 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3759 |
"GetUserName failed"); |
| 3760 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3761 |
"GetUserName failed"); |
| 3762 |
|
| 3763 |
torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n", |
| 3764 |
authority_name_p->string, |
| 3765 |
account_name_p->string); |
| 3766 |
|
| 3767 |
account_name_saved = talloc_strdup(mem_ctx, account_name_p->string); |
| 3768 |
torture_assert_goto(torture, (account_name_saved != NULL), ret, done, |
| 3769 |
"talloc failed"); |
| 3770 |
authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string); |
| 3771 |
torture_assert_goto(torture, (authority_name_saved != NULL), ret, done, |
| 3772 |
"talloc failed"); |
| 3773 |
|
| 3774 |
/* smb re-authenticate as anonymous */ |
| 3775 |
|
| 3776 |
anon_creds = cli_credentials_init_anon(mem_ctx); |
| 3777 |
|
| 3778 |
status = smb2_session_setup_spnego(tree->session, |
| 3779 |
anon_creds, |
| 3780 |
0 /* previous_session_id */); |
| 3781 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3782 |
"session reauth to anon failed"); |
| 3783 |
|
| 3784 |
/* re-do lsa getusername after reauth */ |
| 3785 |
|
| 3786 |
TALLOC_FREE(authority_name_p); |
| 3787 |
TALLOC_FREE(account_name_p); |
| 3788 |
ZERO_STRUCT(r); |
| 3789 |
r.in.system_name = "\\"; |
| 3790 |
r.in.account_name = &account_name_p; |
| 3791 |
r.in.authority_name = &authority_name_p; |
| 3792 |
r.out.account_name = &account_name_p; |
| 3793 |
|
| 3794 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3795 |
|
| 3796 |
authority_name_p = *r.out.authority_name; |
| 3797 |
|
| 3798 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3799 |
"GetUserName failed"); |
| 3800 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3801 |
"GetUserName failed"); |
| 3802 |
|
| 3803 |
torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0), |
| 3804 |
ret, done, "authority_name not equal after reauth to anon"); |
| 3805 |
torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0), |
| 3806 |
ret, done, "account_name not equal after reauth to anon"); |
| 3807 |
|
| 3808 |
/* smb re-auth again to the original user */ |
| 3809 |
|
| 3810 |
status = smb2_session_setup_spnego(tree->session, |
| 3811 |
samba_cmdline_get_creds(), |
| 3812 |
0 /* previous_session_id */); |
| 3813 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3814 |
"session reauth to anon failed"); |
| 3815 |
|
| 3816 |
/* re-do lsa getusername */ |
| 3817 |
|
| 3818 |
TALLOC_FREE(authority_name_p); |
| 3819 |
TALLOC_FREE(account_name_p); |
| 3820 |
ZERO_STRUCT(r); |
| 3821 |
r.in.system_name = "\\"; |
| 3822 |
r.in.account_name = &account_name_p; |
| 3823 |
r.in.authority_name = &authority_name_p; |
| 3824 |
r.out.account_name = &account_name_p; |
| 3825 |
|
| 3826 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3827 |
|
| 3828 |
authority_name_p = *r.out.authority_name; |
| 3829 |
|
| 3830 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3831 |
"GetUserName failed"); |
| 3832 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3833 |
"GetUserName failed"); |
| 3834 |
|
| 3835 |
torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0), |
| 3836 |
ret, done, "authority_name not equal after reauth to anon"); |
| 3837 |
torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0), |
| 3838 |
ret, done, "account_name not equal after reauth to anon"); |
| 3839 |
|
| 3840 |
ret = true; |
| 3841 |
|
| 3842 |
done: |
| 3843 |
talloc_free(mem_ctx); |
| 3844 |
return ret; |
| 3845 |
} |
| 3846 |
|
| 3847 |
/** |
| 3848 |
* Test smb2 reauthentication while rpc pipe is in use. |
| 3849 |
* Open a second lsa bind after reauth to anon. |
| 3850 |
* Do lsa getusername on that second bind. |
| 3851 |
*/ |
| 3852 |
static bool torture_rpc_smb2_reauth2(struct torture_context *torture) |
| 3853 |
{ |
| 3854 |
TALLOC_CTX *mem_ctx; |
| 3855 |
NTSTATUS status; |
| 3856 |
bool ret = false; |
| 3857 |
struct smbcli_options options; |
| 3858 |
|
| 3859 |
struct dcerpc_pipe *lsa_pipe; |
| 3860 |
struct dcerpc_binding_handle *lsa_handle; |
| 3861 |
struct lsa_GetUserName r; |
| 3862 |
struct lsa_String *authority_name_p = NULL; |
| 3863 |
char *authority_name_saved = NULL; |
| 3864 |
struct lsa_String *account_name_p = NULL; |
| 3865 |
char *account_name_saved = NULL; |
| 3866 |
struct cli_credentials *anon_creds = NULL; |
| 3867 |
const char *host = torture_setting_string(torture, "host", NULL); |
| 3868 |
struct smb2_tree *tree; |
| 3869 |
|
| 3870 |
mem_ctx = talloc_init("torture_samba3_reauth"); |
| 3871 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 3872 |
|
| 3873 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 3874 |
|
| 3875 |
status = smb2_connect(mem_ctx, |
| 3876 |
host, |
| 3877 |
"IPC$", |
| 3878 |
torture->lp_ctx, |
| 3879 |
lpcfg_resolve_context(torture->lp_ctx), |
| 3880 |
samba_cmdline_get_creds(), |
| 3881 |
&tree, |
| 3882 |
torture->ev, |
| 3883 |
&options, |
| 3884 |
lpcfg_socket_options(torture->lp_ctx), |
| 3885 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 3886 |
); |
| 3887 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3888 |
"smb2_connect failed"); |
| 3889 |
|
| 3890 |
/* smb re-authenticate as anonymous */ |
| 3891 |
|
| 3892 |
anon_creds = cli_credentials_init_anon(mem_ctx); |
| 3893 |
|
| 3894 |
status = smb2_session_setup_spnego(tree->session, |
| 3895 |
anon_creds, |
| 3896 |
0 /* previous_session_id */); |
| 3897 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3898 |
"session reauth to anon failed"); |
| 3899 |
|
| 3900 |
/* open the lsa pipe */ |
| 3901 |
|
| 3902 |
status = pipe_bind_smb2(torture, mem_ctx, tree, "lsarpc", |
| 3903 |
&ndr_table_lsarpc, &lsa_pipe); |
| 3904 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3905 |
"pipe_bind_smb2 failed"); |
| 3906 |
lsa_handle = lsa_pipe->binding_handle; |
| 3907 |
|
| 3908 |
/* lsa getusername */ |
| 3909 |
|
| 3910 |
ZERO_STRUCT(r); |
| 3911 |
r.in.system_name = "\\"; |
| 3912 |
r.in.account_name = &account_name_p; |
| 3913 |
r.in.authority_name = &authority_name_p; |
| 3914 |
r.out.account_name = &account_name_p; |
| 3915 |
|
| 3916 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3917 |
|
| 3918 |
authority_name_p = *r.out.authority_name; |
| 3919 |
|
| 3920 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3921 |
"GetUserName failed"); |
| 3922 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3923 |
"GetUserName failed"); |
| 3924 |
|
| 3925 |
torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n", |
| 3926 |
authority_name_p->string, |
| 3927 |
account_name_p->string); |
| 3928 |
|
| 3929 |
account_name_saved = talloc_strdup(mem_ctx, account_name_p->string); |
| 3930 |
torture_assert_goto(torture, (account_name_saved != NULL), ret, done, |
| 3931 |
"talloc failed"); |
| 3932 |
authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string); |
| 3933 |
torture_assert_goto(torture, (authority_name_saved != NULL), ret, done, |
| 3934 |
"talloc failed"); |
| 3935 |
|
| 3936 |
/* smb re-auth again to the original user */ |
| 3937 |
|
| 3938 |
status = smb2_session_setup_spnego(tree->session, |
| 3939 |
samba_cmdline_get_creds(), |
| 3940 |
0 /* previous_session_id */); |
| 3941 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3942 |
"session reauth to anon failed"); |
| 3943 |
|
| 3944 |
/* re-do lsa getusername */ |
| 3945 |
|
| 3946 |
TALLOC_FREE(authority_name_p); |
| 3947 |
TALLOC_FREE(account_name_p); |
| 3948 |
ZERO_STRUCT(r); |
| 3949 |
r.in.system_name = "\\"; |
| 3950 |
r.in.account_name = &account_name_p; |
| 3951 |
r.in.authority_name = &authority_name_p; |
| 3952 |
r.out.account_name = &account_name_p; |
| 3953 |
|
| 3954 |
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r); |
| 3955 |
|
| 3956 |
authority_name_p = *r.out.authority_name; |
| 3957 |
|
| 3958 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 3959 |
"GetUserName failed"); |
| 3960 |
torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done, |
| 3961 |
"GetUserName failed"); |
| 3962 |
|
| 3963 |
torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0), |
| 3964 |
ret, done, "authority_name not equal after reauth to anon"); |
| 3965 |
torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0), |
| 3966 |
ret, done, "account_name not equal after reauth to anon"); |
| 3967 |
|
| 3968 |
ret = true; |
| 3969 |
|
| 3970 |
done: |
| 3971 |
talloc_free(mem_ctx); |
| 3972 |
return ret; |
| 3973 |
} |
| 3974 |
|
| 3975 |
static bool torture_rpc_smb1_pipe_name(struct torture_context *torture) |
| 3976 |
{ |
| 3977 |
TALLOC_CTX *mem_ctx; |
| 3978 |
NTSTATUS status; |
| 3979 |
bool ret = false; |
| 3980 |
struct smbcli_state *cli; |
| 3981 |
struct smbcli_options options; |
| 3982 |
struct smbcli_session_options session_options; |
| 3983 |
union smb_open io; |
| 3984 |
union smb_close cl; |
| 3985 |
uint16_t fnum; |
| 3986 |
|
| 3987 |
mem_ctx = talloc_init("torture_samba3_smb1_pipe_name"); |
| 3988 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 3989 |
|
| 3990 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 3991 |
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options); |
| 3992 |
|
| 3993 |
status = smbcli_full_connection(mem_ctx, &cli, |
| 3994 |
torture_setting_string(torture, "host", NULL), |
| 3995 |
"IPC$", NULL, |
| 3996 |
lpcfg_socket_options(torture->lp_ctx), |
| 3997 |
samba_cmdline_get_creds(), |
| 3998 |
torture->lp_ctx, |
| 3999 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4000 |
torture->ev, &options, &session_options, |
| 4001 |
lpcfg_gensec_settings(torture, torture->lp_ctx)); |
| 4002 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4003 |
"smbcli_full_connection failed"); |
| 4004 |
|
| 4005 |
ZERO_STRUCT(io); |
| 4006 |
io.generic.level = RAW_OPEN_NTCREATEX; |
| 4007 |
io.ntcreatex.in.access_mask = DESIRED_ACCESS_PIPE; |
| 4008 |
io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ| |
| 4009 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 4010 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; |
| 4011 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; |
| 4012 |
io.ntcreatex.in.security_flags = 0; |
| 4013 |
|
| 4014 |
io.ntcreatex.in.fname = "__none__"; |
| 4015 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4016 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4017 |
ret, done, |
| 4018 |
"smb_raw_open for '__none__'"); |
| 4019 |
|
| 4020 |
io.ntcreatex.in.fname = "pipe\\srvsvc"; |
| 4021 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4022 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4023 |
ret, done, |
| 4024 |
"smb_raw_open for 'pipe\\srvsvc'"); |
| 4025 |
|
| 4026 |
io.ntcreatex.in.fname = "\\pipe\\srvsvc"; |
| 4027 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4028 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4029 |
ret, done, |
| 4030 |
"smb_raw_open for '\\pipe\\srvsvc'"); |
| 4031 |
|
| 4032 |
io.ntcreatex.in.fname = "srvsvc"; |
| 4033 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4034 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4035 |
"smb2_create failed for 'srvsvc'"); |
| 4036 |
fnum = io.ntcreatex.out.file.fnum; |
| 4037 |
ZERO_STRUCT(cl); |
| 4038 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4039 |
cl.close.in.file.fnum = fnum; |
| 4040 |
status = smb_raw_close(cli->tree, &cl); |
| 4041 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4042 |
"smb_raw_close failed"); |
| 4043 |
|
| 4044 |
io.ntcreatex.in.fname = "\\srvsvc"; |
| 4045 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4046 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4047 |
"smb2_create failed for '\\srvsvc'"); |
| 4048 |
fnum = io.ntcreatex.out.file.fnum; |
| 4049 |
ZERO_STRUCT(cl); |
| 4050 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4051 |
cl.close.in.file.fnum = fnum; |
| 4052 |
status = smb_raw_close(cli->tree, &cl); |
| 4053 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4054 |
"smb_raw_close failed"); |
| 4055 |
|
| 4056 |
io.ntcreatex.in.fname = "\\\\\\\\\\srvsvc"; |
| 4057 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4058 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4059 |
"smb2_create failed for '\\\\\\\\\\srvsvc'"); |
| 4060 |
fnum = io.ntcreatex.out.file.fnum; |
| 4061 |
ZERO_STRUCT(cl); |
| 4062 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4063 |
cl.close.in.file.fnum = fnum; |
| 4064 |
status = smb_raw_close(cli->tree, &cl); |
| 4065 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4066 |
"smb_raw_close failed"); |
| 4067 |
|
| 4068 |
ZERO_STRUCT(io); |
| 4069 |
io.generic.level = RAW_OPEN_NTTRANS_CREATE; |
| 4070 |
io.nttrans.in.access_mask = DESIRED_ACCESS_PIPE; |
| 4071 |
io.nttrans.in.share_access = NTCREATEX_SHARE_ACCESS_READ| |
| 4072 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 4073 |
io.nttrans.in.open_disposition = NTCREATEX_DISP_OPEN; |
| 4074 |
io.nttrans.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; |
| 4075 |
io.nttrans.in.security_flags = 0; |
| 4076 |
|
| 4077 |
io.nttrans.in.fname = "__none__"; |
| 4078 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4079 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4080 |
ret, done, |
| 4081 |
"smb_raw_open for '__none__'"); |
| 4082 |
|
| 4083 |
io.nttrans.in.fname = "pipe\\srvsvc"; |
| 4084 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4085 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4086 |
ret, done, |
| 4087 |
"smb_raw_open for 'pipe\\srvsvc'"); |
| 4088 |
|
| 4089 |
io.nttrans.in.fname = "\\pipe\\srvsvc"; |
| 4090 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4091 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4092 |
ret, done, |
| 4093 |
"smb_raw_open for '\\pipe\\srvsvc'"); |
| 4094 |
|
| 4095 |
io.nttrans.in.fname = "srvsvc"; |
| 4096 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4097 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4098 |
"smb2_create failed for 'srvsvc'"); |
| 4099 |
fnum = io.nttrans.out.file.fnum; |
| 4100 |
ZERO_STRUCT(cl); |
| 4101 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4102 |
cl.close.in.file.fnum = fnum; |
| 4103 |
status = smb_raw_close(cli->tree, &cl); |
| 4104 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4105 |
"smb_raw_close failed"); |
| 4106 |
|
| 4107 |
io.nttrans.in.fname = "\\srvsvc"; |
| 4108 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4109 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4110 |
"smb2_create failed for '\\srvsvc'"); |
| 4111 |
fnum = io.nttrans.out.file.fnum; |
| 4112 |
ZERO_STRUCT(cl); |
| 4113 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4114 |
cl.close.in.file.fnum = fnum; |
| 4115 |
status = smb_raw_close(cli->tree, &cl); |
| 4116 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4117 |
"smb_raw_close failed"); |
| 4118 |
|
| 4119 |
io.nttrans.in.fname = "\\\\\\\\\\srvsvc"; |
| 4120 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4121 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4122 |
"smb2_create failed for '\\\\\\\\\\srvsvc'"); |
| 4123 |
fnum = io.nttrans.out.file.fnum; |
| 4124 |
ZERO_STRUCT(cl); |
| 4125 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4126 |
cl.close.in.file.fnum = fnum; |
| 4127 |
status = smb_raw_close(cli->tree, &cl); |
| 4128 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4129 |
"smb_raw_close failed"); |
| 4130 |
|
| 4131 |
ZERO_STRUCT(io); |
| 4132 |
io.generic.level = RAW_OPEN_OPENX; |
| 4133 |
io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR; |
| 4134 |
io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN; |
| 4135 |
|
| 4136 |
io.openx.in.fname = "__none__"; |
| 4137 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4138 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD, |
| 4139 |
ret, done, |
| 4140 |
"smb_raw_open for '__none__'"); |
| 4141 |
|
| 4142 |
io.openx.in.fname = "srvsvc"; |
| 4143 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4144 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD, |
| 4145 |
ret, done, |
| 4146 |
"smb_raw_open for 'srvsvc'"); |
| 4147 |
|
| 4148 |
io.openx.in.fname = "\\srvsvc"; |
| 4149 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4150 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD, |
| 4151 |
ret, done, |
| 4152 |
"smb_raw_open for '\\srvsvc'"); |
| 4153 |
|
| 4154 |
io.openx.in.fname = "\\pipesrvsvc"; |
| 4155 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4156 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD, |
| 4157 |
ret, done, |
| 4158 |
"smb_raw_open for '\\pipesrvsvc'"); |
| 4159 |
|
| 4160 |
io.openx.in.fname = "pipe\\__none__"; |
| 4161 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4162 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4163 |
ret, done, |
| 4164 |
"smb_raw_open for 'pipe\\__none__'"); |
| 4165 |
|
| 4166 |
io.openx.in.fname = "\\pipe\\__none__"; |
| 4167 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4168 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4169 |
ret, done, |
| 4170 |
"smb_raw_open for '\\pipe\\__none__'"); |
| 4171 |
|
| 4172 |
io.openx.in.fname = "pipe\\srvsvc"; |
| 4173 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4174 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4175 |
"smb2_create failed for 'pipe\\srvsvc'"); |
| 4176 |
fnum = io.openx.out.file.fnum; |
| 4177 |
ZERO_STRUCT(cl); |
| 4178 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4179 |
cl.close.in.file.fnum = fnum; |
| 4180 |
status = smb_raw_close(cli->tree, &cl); |
| 4181 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4182 |
"smb_raw_close failed"); |
| 4183 |
|
| 4184 |
io.openx.in.fname = "\\pipe\\srvsvc"; |
| 4185 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4186 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4187 |
"smb2_create failed for '\\pipe\\srvsvc'"); |
| 4188 |
fnum = io.openx.out.file.fnum; |
| 4189 |
ZERO_STRUCT(cl); |
| 4190 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4191 |
cl.close.in.file.fnum = fnum; |
| 4192 |
status = smb_raw_close(cli->tree, &cl); |
| 4193 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4194 |
"smb_raw_close failed"); |
| 4195 |
|
| 4196 |
io.openx.in.fname = "\\\\\\\\\\pipe\\srvsvc"; |
| 4197 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4198 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4199 |
"smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'"); |
| 4200 |
fnum = io.openx.out.file.fnum; |
| 4201 |
ZERO_STRUCT(cl); |
| 4202 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4203 |
cl.close.in.file.fnum = fnum; |
| 4204 |
status = smb_raw_close(cli->tree, &cl); |
| 4205 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4206 |
"smb_raw_close failed"); |
| 4207 |
|
| 4208 |
io.openx.in.fname = "\\\\\\\\\\pipe\\\\\\\\\\srvsvc"; |
| 4209 |
status = smb_raw_open(cli->tree, torture, &io); |
| 4210 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4211 |
"smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'"); |
| 4212 |
fnum = io.openx.out.file.fnum; |
| 4213 |
ZERO_STRUCT(cl); |
| 4214 |
cl.generic.level = RAW_CLOSE_CLOSE; |
| 4215 |
cl.close.in.file.fnum = fnum; |
| 4216 |
status = smb_raw_close(cli->tree, &cl); |
| 4217 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4218 |
"smb_raw_close failed"); |
| 4219 |
ret = true; |
| 4220 |
|
| 4221 |
done: |
| 4222 |
talloc_free(mem_ctx); |
| 4223 |
return ret; |
| 4224 |
} |
| 4225 |
|
| 4226 |
static bool torture_rpc_smb2_pipe_name(struct torture_context *torture) |
| 4227 |
{ |
| 4228 |
TALLOC_CTX *mem_ctx; |
| 4229 |
NTSTATUS status; |
| 4230 |
bool ret = false; |
| 4231 |
struct smbcli_options options; |
| 4232 |
const char *host = torture_setting_string(torture, "host", NULL); |
| 4233 |
struct smb2_tree *tree; |
| 4234 |
struct smb2_handle h; |
| 4235 |
struct smb2_create io; |
| 4236 |
|
| 4237 |
mem_ctx = talloc_init("torture_samba3_smb2_pipe_name"); |
| 4238 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 4239 |
|
| 4240 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 4241 |
|
| 4242 |
status = smb2_connect(mem_ctx, |
| 4243 |
host, |
| 4244 |
"IPC$", |
| 4245 |
torture->lp_ctx, |
| 4246 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4247 |
samba_cmdline_get_creds(), |
| 4248 |
&tree, |
| 4249 |
torture->ev, |
| 4250 |
&options, |
| 4251 |
lpcfg_socket_options(torture->lp_ctx), |
| 4252 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 4253 |
); |
| 4254 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4255 |
"smb2_connect failed"); |
| 4256 |
|
| 4257 |
ZERO_STRUCT(io); |
| 4258 |
io.in.oplock_level = 0; |
| 4259 |
io.in.desired_access = DESIRED_ACCESS_PIPE; |
| 4260 |
io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION; |
| 4261 |
io.in.file_attributes = 0; |
| 4262 |
io.in.create_disposition = NTCREATEX_DISP_OPEN; |
| 4263 |
io.in.share_access = |
| 4264 |
NTCREATEX_SHARE_ACCESS_READ| |
| 4265 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 4266 |
io.in.create_options = 0; |
| 4267 |
|
| 4268 |
io.in.fname = "__none__"; |
| 4269 |
status = smb2_create(tree, tree, &io); |
| 4270 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4271 |
ret, done, |
| 4272 |
"smb2_create for '__none__'"); |
| 4273 |
|
| 4274 |
io.in.fname = "\\srvsvc"; |
| 4275 |
status = smb2_create(tree, tree, &io); |
| 4276 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4277 |
ret, done, |
| 4278 |
"smb2_create for '\\srvsvc'"); |
| 4279 |
|
| 4280 |
io.in.fname = "\\pipe\\srvsvc"; |
| 4281 |
status = smb2_create(tree, tree, &io); |
| 4282 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4283 |
ret, done, |
| 4284 |
"smb2_create for '\\pipe\\srvsvc'"); |
| 4285 |
|
| 4286 |
io.in.fname = "pipe\\srvsvc"; |
| 4287 |
status = smb2_create(tree, tree, &io); |
| 4288 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 4289 |
ret, done, |
| 4290 |
"smb2_create for 'pipe\\srvsvc'"); |
| 4291 |
|
| 4292 |
io.in.fname = "srvsvc"; |
| 4293 |
status = smb2_create(tree, tree, &io); |
| 4294 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4295 |
"smb2_create failed for 'srvsvc'"); |
| 4296 |
|
| 4297 |
h = io.out.file.handle; |
| 4298 |
|
| 4299 |
status = smb2_util_close(tree, h); |
| 4300 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4301 |
"smb2_util_close failed"); |
| 4302 |
|
| 4303 |
ret = true; |
| 4304 |
done: |
| 4305 |
talloc_free(mem_ctx); |
| 4306 |
return ret; |
| 4307 |
} |
| 4308 |
|
| 4309 |
/** |
| 4310 |
* Test behaviour of a waiting read call on a pipe when |
| 4311 |
* the pipe handle is closed: |
| 4312 |
* - open a pipe via smb2 |
| 4313 |
* - trigger a read which hangs since there is nothing to read |
| 4314 |
* - close the pipe file handle |
| 4315 |
* - wait for the read to return and check the status |
| 4316 |
* (STATUS_PIPE_BROKEN) |
| 4317 |
*/ |
| 4318 |
static bool torture_rpc_smb2_pipe_read_close(struct torture_context *torture) |
| 4319 |
{ |
| 4320 |
TALLOC_CTX *mem_ctx; |
| 4321 |
NTSTATUS status; |
| 4322 |
bool ret = false; |
| 4323 |
struct smbcli_options options; |
| 4324 |
const char *host = torture_setting_string(torture, "host", NULL); |
| 4325 |
struct smb2_tree *tree; |
| 4326 |
struct smb2_handle h; |
| 4327 |
struct smb2_request *smb2req; |
| 4328 |
struct smb2_create io; |
| 4329 |
struct smb2_read rd; |
| 4330 |
|
| 4331 |
mem_ctx = talloc_init("torture_samba3_pipe_read_close"); |
| 4332 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 4333 |
|
| 4334 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 4335 |
|
| 4336 |
status = smb2_connect(mem_ctx, |
| 4337 |
host, |
| 4338 |
"IPC$", |
| 4339 |
torture->lp_ctx, |
| 4340 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4341 |
samba_cmdline_get_creds(), |
| 4342 |
&tree, |
| 4343 |
torture->ev, |
| 4344 |
&options, |
| 4345 |
lpcfg_socket_options(torture->lp_ctx), |
| 4346 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 4347 |
); |
| 4348 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4349 |
"smb2_connect failed"); |
| 4350 |
|
| 4351 |
ZERO_STRUCT(io); |
| 4352 |
io.in.oplock_level = 0; |
| 4353 |
io.in.desired_access = DESIRED_ACCESS_PIPE; |
| 4354 |
io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION; |
| 4355 |
io.in.file_attributes = 0; |
| 4356 |
io.in.create_disposition = NTCREATEX_DISP_OPEN; |
| 4357 |
io.in.share_access = |
| 4358 |
NTCREATEX_SHARE_ACCESS_READ| |
| 4359 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 4360 |
io.in.create_options = 0; |
| 4361 |
io.in.fname = "lsarpc"; |
| 4362 |
|
| 4363 |
status = smb2_create(tree, tree, &io); |
| 4364 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4365 |
"smb2_create failed for 'lsarpc'"); |
| 4366 |
|
| 4367 |
h = io.out.file.handle; |
| 4368 |
|
| 4369 |
ZERO_STRUCT(rd); |
| 4370 |
rd.in.file.handle = h; |
| 4371 |
rd.in.length = 1024; |
| 4372 |
rd.in.offset = 0; |
| 4373 |
rd.in.min_count = 0; |
| 4374 |
|
| 4375 |
smb2req = smb2_read_send(tree, &rd); |
| 4376 |
torture_assert_goto(torture, (smb2req != NULL), ret, done, |
| 4377 |
"smb2_read_send failed"); |
| 4378 |
|
| 4379 |
status = smb2_util_close(tree, h); |
| 4380 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4381 |
"smb2_util_close failed"); |
| 4382 |
|
| 4383 |
status = smb2_read_recv(smb2req, mem_ctx, &rd); |
| 4384 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done, |
| 4385 |
"smb2_read_recv: unexpected return code"); |
| 4386 |
|
| 4387 |
ret = true; |
| 4388 |
done: |
| 4389 |
talloc_free(mem_ctx); |
| 4390 |
return ret; |
| 4391 |
} |
| 4392 |
|
| 4393 |
/** |
| 4394 |
* Test behaviour of a waiting read call on a pipe when |
| 4395 |
* the tree is disconnected. |
| 4396 |
* - open a pipe via smb2 |
| 4397 |
* - trigger a read which hangs since there is nothing to read |
| 4398 |
* - do a tree disconnect |
| 4399 |
* - wait for the read to return and check the status |
| 4400 |
* (STATUS_PIPE_BROKEN) |
| 4401 |
*/ |
| 4402 |
static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context *torture) |
| 4403 |
{ |
| 4404 |
TALLOC_CTX *mem_ctx; |
| 4405 |
NTSTATUS status; |
| 4406 |
bool ret = false; |
| 4407 |
struct smbcli_options options; |
| 4408 |
const char *host = torture_setting_string(torture, "host", NULL); |
| 4409 |
struct smb2_tree *tree; |
| 4410 |
struct smb2_handle h; |
| 4411 |
struct smb2_request *smb2req; |
| 4412 |
struct smb2_create io; |
| 4413 |
struct smb2_read rd; |
| 4414 |
|
| 4415 |
mem_ctx = talloc_init("torture_samba3_pipe_read_tdis"); |
| 4416 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 4417 |
|
| 4418 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 4419 |
|
| 4420 |
status = smb2_connect(mem_ctx, |
| 4421 |
host, |
| 4422 |
"IPC$", |
| 4423 |
torture->lp_ctx, |
| 4424 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4425 |
samba_cmdline_get_creds(), |
| 4426 |
&tree, |
| 4427 |
torture->ev, |
| 4428 |
&options, |
| 4429 |
lpcfg_socket_options(torture->lp_ctx), |
| 4430 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 4431 |
); |
| 4432 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4433 |
"smb2_connect failed"); |
| 4434 |
|
| 4435 |
ZERO_STRUCT(io); |
| 4436 |
io.in.oplock_level = 0; |
| 4437 |
io.in.desired_access = DESIRED_ACCESS_PIPE; |
| 4438 |
io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION; |
| 4439 |
io.in.file_attributes = 0; |
| 4440 |
io.in.create_disposition = NTCREATEX_DISP_OPEN; |
| 4441 |
io.in.share_access = |
| 4442 |
NTCREATEX_SHARE_ACCESS_READ| |
| 4443 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 4444 |
io.in.create_options = 0; |
| 4445 |
io.in.fname = "lsarpc"; |
| 4446 |
|
| 4447 |
status = smb2_create(tree, tree, &io); |
| 4448 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4449 |
"smb2_create failed for 'lsarpc'"); |
| 4450 |
|
| 4451 |
h = io.out.file.handle; |
| 4452 |
|
| 4453 |
ZERO_STRUCT(rd); |
| 4454 |
rd.in.file.handle = h; |
| 4455 |
rd.in.length = 1024; |
| 4456 |
rd.in.offset = 0; |
| 4457 |
rd.in.min_count = 0; |
| 4458 |
|
| 4459 |
smb2req = smb2_read_send(tree, &rd); |
| 4460 |
torture_assert_goto(torture, (smb2req != NULL), ret, done, |
| 4461 |
"smb2_read_send failed"); |
| 4462 |
|
| 4463 |
status = smb2_tdis(tree); |
| 4464 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4465 |
"smb2_tdis failed"); |
| 4466 |
|
| 4467 |
status = smb2_read_recv(smb2req, mem_ctx, &rd); |
| 4468 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done, |
| 4469 |
"smb2_read_recv: unexpected return code"); |
| 4470 |
|
| 4471 |
ret = true; |
| 4472 |
done: |
| 4473 |
talloc_free(mem_ctx); |
| 4474 |
return ret; |
| 4475 |
} |
| 4476 |
|
| 4477 |
/** |
| 4478 |
* Test behaviour of a waiting read call on a pipe when |
| 4479 |
* the user logs off |
| 4480 |
* - open a pipe via smb2 |
| 4481 |
* - trigger a read which hangs since there is nothing to read |
| 4482 |
* - do a logoff |
| 4483 |
* - wait for the read to return and check the status |
| 4484 |
* (STATUS_PIPE_BROKEN) |
| 4485 |
*/ |
| 4486 |
static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context *torture) |
| 4487 |
{ |
| 4488 |
TALLOC_CTX *mem_ctx; |
| 4489 |
NTSTATUS status; |
| 4490 |
bool ret = false; |
| 4491 |
struct smbcli_options options; |
| 4492 |
const char *host = torture_setting_string(torture, "host", NULL); |
| 4493 |
struct smb2_tree *tree; |
| 4494 |
struct smb2_handle h; |
| 4495 |
struct smb2_request *smb2req; |
| 4496 |
struct smb2_create io; |
| 4497 |
struct smb2_read rd; |
| 4498 |
|
| 4499 |
mem_ctx = talloc_init("torture_samba3_pipe_read_tdis"); |
| 4500 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 4501 |
|
| 4502 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 4503 |
|
| 4504 |
status = smb2_connect(mem_ctx, |
| 4505 |
host, |
| 4506 |
"IPC$", |
| 4507 |
torture->lp_ctx, |
| 4508 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4509 |
samba_cmdline_get_creds(), |
| 4510 |
&tree, |
| 4511 |
torture->ev, |
| 4512 |
&options, |
| 4513 |
lpcfg_socket_options(torture->lp_ctx), |
| 4514 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 4515 |
); |
| 4516 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4517 |
"smb2_connect failed"); |
| 4518 |
|
| 4519 |
ZERO_STRUCT(io); |
| 4520 |
io.in.oplock_level = 0; |
| 4521 |
io.in.desired_access = DESIRED_ACCESS_PIPE; |
| 4522 |
io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION; |
| 4523 |
io.in.file_attributes = 0; |
| 4524 |
io.in.create_disposition = NTCREATEX_DISP_OPEN; |
| 4525 |
io.in.share_access = |
| 4526 |
NTCREATEX_SHARE_ACCESS_READ| |
| 4527 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 4528 |
io.in.create_options = 0; |
| 4529 |
io.in.fname = "lsarpc"; |
| 4530 |
|
| 4531 |
status = smb2_create(tree, tree, &io); |
| 4532 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4533 |
"smb2_create failed for 'lsarpc'"); |
| 4534 |
|
| 4535 |
h = io.out.file.handle; |
| 4536 |
|
| 4537 |
ZERO_STRUCT(rd); |
| 4538 |
rd.in.file.handle = h; |
| 4539 |
rd.in.length = 1024; |
| 4540 |
rd.in.offset = 0; |
| 4541 |
rd.in.min_count = 0; |
| 4542 |
|
| 4543 |
smb2req = smb2_read_send(tree, &rd); |
| 4544 |
torture_assert_goto(torture, (smb2req != NULL), ret, done, |
| 4545 |
"smb2_read_send failed"); |
| 4546 |
|
| 4547 |
status = smb2_logoff(tree->session); |
| 4548 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4549 |
"smb2_logoff failed"); |
| 4550 |
|
| 4551 |
status = smb2_read_recv(smb2req, mem_ctx, &rd); |
| 4552 |
torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done, |
| 4553 |
"smb2_read_recv: unexpected return code"); |
| 4554 |
|
| 4555 |
ret = true; |
| 4556 |
done: |
| 4557 |
talloc_free(mem_ctx); |
| 4558 |
return ret; |
| 4559 |
} |
| 4560 |
|
| 4561 |
static bool torture_rpc_lsa_over_netlogon(struct torture_context *torture) |
| 4562 |
{ |
| 4563 |
TALLOC_CTX *mem_ctx; |
| 4564 |
NTSTATUS status; |
| 4565 |
bool ret = false; |
| 4566 |
struct smbcli_options options; |
| 4567 |
struct smb2_tree *tree; |
| 4568 |
struct dcerpc_pipe *netlogon_pipe; |
| 4569 |
struct dcerpc_binding_handle *lsa_handle; |
| 4570 |
struct lsa_ObjectAttribute attr; |
| 4571 |
struct lsa_QosInfo qos; |
| 4572 |
struct lsa_OpenPolicy2 o; |
| 4573 |
struct policy_handle handle; |
| 4574 |
|
| 4575 |
torture_comment(torture, "Testing if we can access LSA server over " |
| 4576 |
"\\\\pipe\\netlogon rather than \\\\pipe\\lsarpc\n"); |
| 4577 |
|
| 4578 |
mem_ctx = talloc_init("torture_samba3_rpc_lsa_over_netlogon"); |
| 4579 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 4580 |
|
| 4581 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 4582 |
|
| 4583 |
status = smb2_connect(mem_ctx, |
| 4584 |
torture_setting_string(torture, "host", NULL), |
| 4585 |
"IPC$", |
| 4586 |
torture->lp_ctx, |
| 4587 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4588 |
samba_cmdline_get_creds(), |
| 4589 |
&tree, |
| 4590 |
torture->ev, |
| 4591 |
&options, |
| 4592 |
lpcfg_socket_options(torture->lp_ctx), |
| 4593 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 4594 |
); |
| 4595 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4596 |
"smb2_connect failed"); |
| 4597 |
|
| 4598 |
status = pipe_bind_smb2(torture, mem_ctx, tree, "netlogon", |
| 4599 |
&ndr_table_lsarpc, &netlogon_pipe); |
| 4600 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4601 |
"pipe_bind_smb2 failed"); |
| 4602 |
lsa_handle = netlogon_pipe->binding_handle; |
| 4603 |
|
| 4604 |
qos.len = 0; |
| 4605 |
qos.impersonation_level = 2; |
| 4606 |
qos.context_mode = 1; |
| 4607 |
qos.effective_only = 0; |
| 4608 |
|
| 4609 |
attr.len = 0; |
| 4610 |
attr.root_dir = NULL; |
| 4611 |
attr.object_name = NULL; |
| 4612 |
attr.attributes = 0; |
| 4613 |
attr.sec_desc = NULL; |
| 4614 |
attr.sec_qos = &qos; |
| 4615 |
|
| 4616 |
o.in.system_name = "\\"; |
| 4617 |
o.in.attr = &attr; |
| 4618 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 4619 |
o.out.handle = &handle; |
| 4620 |
|
| 4621 |
torture_assert_ntstatus_ok(torture, |
| 4622 |
dcerpc_lsa_OpenPolicy2_r(lsa_handle, torture, &o), |
| 4623 |
"OpenPolicy2 failed"); |
| 4624 |
torture_assert_ntstatus_ok(torture, |
| 4625 |
o.out.result, |
| 4626 |
"OpenPolicy2 failed"); |
| 4627 |
|
| 4628 |
ret = true; |
| 4629 |
done: |
| 4630 |
talloc_free(mem_ctx); |
| 4631 |
return ret; |
| 4632 |
} |
| 4633 |
|
| 4634 |
static bool torture_rpc_pipes_supported_interfaces( |
| 4635 |
struct torture_context *torture) |
| 4636 |
{ |
| 4637 |
TALLOC_CTX *mem_ctx; |
| 4638 |
NTSTATUS status; |
| 4639 |
bool ret = false; |
| 4640 |
struct smbcli_options options; |
| 4641 |
struct smb2_tree *tree; |
| 4642 |
struct dcerpc_pipe *pipe1; |
| 4643 |
struct dcerpc_pipe *pipe2; |
| 4644 |
struct dcerpc_pipe *pipe3; |
| 4645 |
|
| 4646 |
torture_comment(torture, "Testing only appropriate interfaces are " |
| 4647 |
"available in smb pipes\n"); |
| 4648 |
|
| 4649 |
mem_ctx = talloc_init("torture_samba3_rpc_pipes_supported_interfaces"); |
| 4650 |
torture_assert(torture, (mem_ctx != NULL), "talloc_init failed"); |
| 4651 |
|
| 4652 |
lpcfg_smbcli_options(torture->lp_ctx, &options); |
| 4653 |
|
| 4654 |
status = smb2_connect(mem_ctx, |
| 4655 |
torture_setting_string(torture, "host", NULL), |
| 4656 |
"IPC$", |
| 4657 |
torture->lp_ctx, |
| 4658 |
lpcfg_resolve_context(torture->lp_ctx), |
| 4659 |
samba_cmdline_get_creds(), |
| 4660 |
&tree, |
| 4661 |
torture->ev, |
| 4662 |
&options, |
| 4663 |
lpcfg_socket_options(torture->lp_ctx), |
| 4664 |
lpcfg_gensec_settings(torture, torture->lp_ctx) |
| 4665 |
); |
| 4666 |
torture_assert_ntstatus_ok_goto(torture, status, ret, done, |
| 4667 |
"smb2_connect failed"); |
| 4668 |
|
| 4669 |
/* Test embedded services pipes. The svcctl interface is |
| 4670 |
* not available if we open the winreg pipe. */ |
| 4671 |
status = pipe_bind_smb2(torture, mem_ctx, tree, "winreg", |
| 4672 |
&ndr_table_svcctl, &pipe1); |
| 4673 |
torture_assert_ntstatus_equal(torture, |
| 4674 |
status, |
| 4675 |
NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX, |
| 4676 |
"svcctl interface not supported in winreg pipe"); |
| 4677 |
|
| 4678 |
/* Test it is not possible to bind to S4 server provided services */ |
| 4679 |
status = pipe_bind_smb2(torture, mem_ctx, tree, "srvsvc", |
| 4680 |
&ndr_table_samr, &pipe2); |
| 4681 |
torture_assert_ntstatus_equal(torture, |
| 4682 |
status, |
| 4683 |
NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX, |
| 4684 |
"samr interface not supported in srvsvc pipe"); |
| 4685 |
|
| 4686 |
/* Test pipes in forked daemons like lsassd. The lsarpc interface is |
| 4687 |
* not available if we open the SAMR pipe. */ |
| 4688 |
status = pipe_bind_smb2(torture, mem_ctx, tree, "samr", |
| 4689 |
&ndr_table_lsarpc, &pipe3); |
| 4690 |
torture_assert_ntstatus_equal(torture, |
| 4691 |
status, |
| 4692 |
NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX, |
| 4693 |
"lsarpc interface not supported in samr pipe"); |
| 4694 |
|
| 4695 |
ret = true; |
| 4696 |
done: |
| 4697 |
talloc_free(mem_ctx); |
| 4698 |
return ret; |
| 4699 |
} |
| 4700 |
|
| 4701 |
struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx) |
| 4702 |
{ |
| 4703 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3"); |
| 4704 |
|
| 4705 |
torture_suite_add_simple_test(suite, "bind", torture_bind_samba3); |
| 4706 |
torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3); |
| 4707 |
torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey); |
| 4708 |
torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc); |
| 4709 |
torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec); |
| 4710 |
torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername); |
| 4711 |
torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2); |
| 4712 |
torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa); |
| 4713 |
torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss); |
| 4714 |
torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc); |
| 4715 |
torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg); |
| 4716 |
torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0); |
| 4717 |
torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig); |
| 4718 |
torture_suite_add_simple_test(suite, "smb-reauth1", torture_rpc_smb_reauth1); |
| 4719 |
torture_suite_add_simple_test(suite, "smb-reauth2", torture_rpc_smb_reauth2); |
| 4720 |
torture_suite_add_simple_test(suite, "smb2-reauth1", torture_rpc_smb2_reauth1); |
| 4721 |
torture_suite_add_simple_test(suite, "smb2-reauth2", torture_rpc_smb2_reauth2); |
| 4722 |
torture_suite_add_simple_test(suite, "smb1-pipe-name", torture_rpc_smb1_pipe_name); |
| 4723 |
torture_suite_add_simple_test(suite, "smb2-pipe-name", torture_rpc_smb2_pipe_name); |
| 4724 |
torture_suite_add_simple_test(suite, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close); |
| 4725 |
torture_suite_add_simple_test(suite, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis); |
| 4726 |
torture_suite_add_simple_test(suite, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff); |
| 4727 |
torture_suite_add_simple_test(suite, |
| 4728 |
"lsa_over_netlogon", |
| 4729 |
torture_rpc_lsa_over_netlogon); |
| 4730 |
torture_suite_add_simple_test(suite, |
| 4731 |
"pipes_supported_interfaces", |
| 4732 |
torture_rpc_pipes_supported_interfaces); |
| 4733 |
|
| 4734 |
suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests"); |
| 4735 |
|
| 4736 |
return suite; |
| 4737 |
} |