79
69
mem_ctx = talloc_init("torture_bind_authcontext");
81
71
if (mem_ctx == NULL) {
82
d_printf("talloc_init failed\n");
72
torture_comment(torture, "talloc_init failed\n");
86
lp_smbcli_options(torture->lp_ctx, &options);
87
lp_smbcli_session_options(torture->lp_ctx, &session_options);
76
lpcfg_smbcli_options(torture->lp_ctx, &options);
77
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
89
79
status = smbcli_full_connection(mem_ctx, &cli,
90
80
torture_setting_string(torture, "host", NULL),
91
lp_smb_ports(torture->lp_ctx),
93
lp_socket_options(torture->lp_ctx),
81
lpcfg_smb_ports(torture->lp_ctx),
83
lpcfg_socket_options(torture->lp_ctx),
94
84
cmdline_credentials,
95
lp_resolve_context(torture->lp_ctx),
85
lpcfg_resolve_context(torture->lp_ctx),
96
86
torture->ev, &options, &session_options,
97
lp_iconv_convenience(torture->lp_ctx),
98
lp_gensec_settings(torture, torture->lp_ctx));
87
lpcfg_gensec_settings(torture, torture->lp_ctx));
99
88
if (!NT_STATUS_IS_OK(status)) {
100
d_printf("smbcli_full_connection failed: %s\n",
89
torture_comment(torture, "smbcli_full_connection failed: %s\n",
101
90
nt_errstr(status));
105
lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx,
106
lp_iconv_convenience(torture->lp_ctx));
94
lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
107
95
if (lsa_pipe == NULL) {
108
d_printf("dcerpc_pipe_init failed\n");
96
torture_comment(torture, "dcerpc_pipe_init failed\n");
99
lsa_handle = lsa_pipe->binding_handle;
112
101
status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
113
102
if (!NT_STATUS_IS_OK(status)) {
114
d_printf("dcerpc_pipe_open_smb failed: %s\n",
103
torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
115
104
nt_errstr(status));
119
108
status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
120
109
if (!NT_STATUS_IS_OK(status)) {
121
d_printf("dcerpc_bind_auth_none failed: %s\n",
110
torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
122
111
nt_errstr(status));
302
318
mem_ctx = talloc_init("torture_bind_authcontext");
304
320
if (mem_ctx == NULL) {
305
d_printf("talloc_init failed\n");
321
torture_comment(torture, "talloc_init failed\n");
309
lp_smbcli_options(torture->lp_ctx, &options);
310
lp_smbcli_session_options(torture->lp_ctx, &session_options);
325
lpcfg_smbcli_options(torture->lp_ctx, &options);
326
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
312
328
status = smbcli_full_connection(mem_ctx, &cli,
313
329
torture_setting_string(torture, "host", NULL),
314
lp_smb_ports(torture->lp_ctx),
316
lp_socket_options(torture->lp_ctx),
330
lpcfg_smb_ports(torture->lp_ctx),
332
lpcfg_socket_options(torture->lp_ctx),
317
333
cmdline_credentials,
318
lp_resolve_context(torture->lp_ctx),
334
lpcfg_resolve_context(torture->lp_ctx),
319
335
torture->ev, &options, &session_options,
320
lp_iconv_convenience(torture->lp_ctx),
321
lp_gensec_settings(torture, torture->lp_ctx));
336
lpcfg_gensec_settings(torture, torture->lp_ctx));
322
337
if (!NT_STATUS_IS_OK(status)) {
323
d_printf("smbcli_full_connection failed: %s\n",
338
torture_comment(torture, "smbcli_full_connection failed: %s\n",
324
339
nt_errstr(status));
330
ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
345
ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
331
346
DCERPC_AUTH_LEVEL_INTEGRITY);
332
ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
347
ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
333
348
DCERPC_AUTH_LEVEL_PRIVACY);
334
ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
349
ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
335
350
DCERPC_AUTH_LEVEL_INTEGRITY);
336
ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
351
ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
337
352
DCERPC_AUTH_LEVEL_PRIVACY);
377
393
uint32_t user_rid,access_granted;
379
395
samr_pipe = dcerpc_pipe_init(mem_ctx,
380
cli->transport->socket->event.ctx,
381
lp_iconv_convenience(lp_ctx));
382
if (samr_pipe == NULL) {
383
d_printf("dcerpc_pipe_init failed\n");
384
status = NT_STATUS_NO_MEMORY;
388
status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
389
if (!NT_STATUS_IS_OK(status)) {
390
d_printf("dcerpc_pipe_open_smb failed: %s\n",
396
cli->transport->socket->event.ctx);
397
torture_assert(tctx, samr_pipe, "dcerpc_pipe_init failed");
399
samr_handle = samr_pipe->binding_handle;
401
torture_assert_ntstatus_ok(tctx,
402
dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr"),
403
"dcerpc_pipe_open_smb failed");
395
405
if (admin_creds != NULL) {
396
status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
397
admin_creds, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
399
if (!NT_STATUS_IS_OK(status)) {
400
d_printf("dcerpc_bind_auth failed: %s\n",
406
torture_assert_ntstatus_ok(tctx,
407
dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
408
admin_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
410
"dcerpc_bind_auth failed");
405
412
/* We must have an authenticated SMB connection */
406
status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
407
if (!NT_STATUS_IS_OK(status)) {
408
d_printf("dcerpc_bind_auth_none failed: %s\n",
413
torture_assert_ntstatus_ok(tctx,
414
dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr),
415
"dcerpc_bind_auth_none failed");
414
418
conn.in.system_name = talloc_asprintf(
1353
1387
const char *wks_name)
1355
1389
NTSTATUS status;
1357
1390
struct smbcli_state *cli;
1358
1391
struct cli_credentials *wks_creds;
1359
1392
struct smbcli_options options;
1360
1393
struct smbcli_session_options session_options;
1362
lp_smbcli_options(tctx->lp_ctx, &options);
1363
lp_smbcli_session_options(tctx->lp_ctx, &session_options);
1395
lpcfg_smbcli_options(tctx->lp_ctx, &options);
1396
lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
1365
1398
status = smbcli_full_connection(tctx, &cli,
1366
1399
torture_setting_string(tctx, "host", NULL),
1367
lp_smb_ports(tctx->lp_ctx),
1368
"IPC$", NULL, lp_socket_options(tctx->lp_ctx),
1369
smb_creds, lp_resolve_context(tctx->lp_ctx),
1400
lpcfg_smb_ports(tctx->lp_ctx),
1401
"IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
1402
smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
1370
1403
tctx->ev, &options, &session_options,
1371
lp_iconv_convenience(tctx->lp_ctx),
1372
lp_gensec_settings(tctx, tctx->lp_ctx));
1373
if (!NT_STATUS_IS_OK(status)) {
1374
d_printf("smbcli_full_connection failed: %s\n",
1404
lpcfg_gensec_settings(tctx, tctx->lp_ctx));
1405
torture_assert_ntstatus_ok(tctx, status,
1406
"smbcli_full_connection failed");
1379
1408
wks_creds = cli_credentials_init(cli);
1380
if (wks_creds == NULL) {
1381
d_printf("cli_credentials_init failed\n");
1409
torture_assert(tctx, wks_creds, "cli_credentials_init failed");
1385
1411
cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1386
1412
cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1387
1413
cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1388
1414
cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1389
1415
cli_credentials_set_password(wks_creds,
1390
generate_random_str(wks_creds, 8),
1416
generate_random_password(wks_creds, 8, 255),
1391
1417
CRED_SPECIFIED);
1393
if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
1394
d_printf("join failed\n");
1419
torture_assert(tctx,
1420
join3(tctx, cli, use_level25, samr_creds, wks_creds),
1398
1423
cli_credentials_set_domain(
1399
1424
cmdline_credentials, cli_credentials_get_domain(wks_creds),
1400
1425
CRED_SPECIFIED);
1402
if (!auth2(cli, tctx->lp_ctx, wks_creds)) {
1403
d_printf("auth2 failed\n");
1427
torture_assert(tctx,
1428
auth2(tctx, cli, wks_creds),
1407
if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
1408
d_printf("leave failed\n");
1431
torture_assert(tctx,
1432
leave(tctx, cli, samr_creds, wks_creds),
1412
1435
talloc_free(cli);
1445
1462
* to fix :-) */
1447
1464
if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1448
d_printf("join using anonymous bind on an anonymous smb "
1465
torture_fail(torture, "join using anonymous bind on an anonymous smb "
1449
1466
"connection succeeded -- HUH??\n");
1454
if (!test_join3(torture, false, anon_creds, cmdline_credentials,
1456
d_printf("join using ntlmssp bind on an anonymous smb "
1457
"connection failed\n");
1461
if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
1462
d_printf("join using anonymous bind on an authenticated smb "
1463
"connection failed\n");
1467
if (!test_join3(torture, false, cmdline_credentials,
1468
cmdline_credentials,
1470
d_printf("join using ntlmssp bind on an authenticated smb "
1471
"connection failed\n");
1470
torture_assert(torture,
1471
test_join3(torture, false, anon_creds, cmdline_credentials, wks_name),
1472
"join using ntlmssp bind on an anonymous smb connection failed");
1474
torture_assert(torture,
1475
test_join3(torture, false, cmdline_credentials, NULL, wks_name),
1476
"join using anonymous bind on an authenticated smb connection failed");
1478
torture_assert(torture,
1479
test_join3(torture, false, cmdline_credentials, cmdline_credentials, wks_name),
1480
"join using ntlmssp bind on an authenticated smb connection failed");
1476
1483
* The following two are tests for setuserinfolevel 25
1479
if (!test_join3(torture, true, anon_creds, cmdline_credentials,
1481
d_printf("join using ntlmssp bind on an anonymous smb "
1482
"connection failed\n");
1486
if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
1487
d_printf("join using anonymous bind on an authenticated smb "
1488
"connection failed\n");
1486
torture_assert(torture,
1487
test_join3(torture, true, anon_creds, cmdline_credentials, wks_name),
1488
"join using ntlmssp bind on an anonymous smb connection failed");
1490
torture_assert(torture,
1491
test_join3(torture, true, cmdline_credentials, NULL, wks_name),
1492
"join using anonymous bind on an authenticated smb connection failed");
1498
1498
* open pipe and bind, given an IPC$ context
1501
static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
1502
struct loadparm_context *lp_ctx,
1501
static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
1502
TALLOC_CTX *mem_ctx,
1503
1503
struct smbcli_tree *tree,
1504
1504
const char *pipe_name,
1505
1505
const struct ndr_interface_table *iface,
1628
1645
* Find out the user SID on this connection
1631
static struct dom_sid *whoami(TALLOC_CTX *mem_ctx,
1632
struct loadparm_context *lp_ctx,
1648
static struct dom_sid *whoami(struct torture_context *tctx,
1649
TALLOC_CTX *mem_ctx,
1633
1650
struct smbcli_tree *tree)
1635
1652
struct dcerpc_pipe *lsa;
1653
struct dcerpc_binding_handle *lsa_handle;
1636
1654
struct lsa_GetUserName r;
1637
1655
NTSTATUS status;
1638
1656
struct lsa_String *authority_name_p = NULL;
1639
1657
struct lsa_String *account_name_p = NULL;
1640
1658
struct dom_sid *result;
1642
status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\lsarpc",
1660
status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
1643
1661
&ndr_table_lsarpc, &lsa);
1644
1662
if (!NT_STATUS_IS_OK(status)) {
1645
d_printf("(%s) Could not bind to LSA: %s\n",
1646
__location__, nt_errstr(status));
1663
torture_warning(tctx, "Could not bind to LSA: %s\n",
1667
lsa_handle = lsa->binding_handle;
1650
1669
r.in.system_name = "\\";
1651
1670
r.in.account_name = &account_name_p;
1652
1671
r.in.authority_name = &authority_name_p;
1653
1672
r.out.account_name = &account_name_p;
1655
status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
1674
status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
1657
1676
authority_name_p = *r.out.authority_name;
1659
1678
if (!NT_STATUS_IS_OK(status)) {
1660
printf("(%s) GetUserName failed - %s\n",
1661
__location__, nt_errstr(status));
1679
torture_warning(tctx, "GetUserName failed - %s\n",
1684
if (!NT_STATUS_IS_OK(r.out.result)) {
1685
torture_warning(tctx, "GetUserName failed - %s\n",
1686
nt_errstr(r.out.result));
1662
1687
talloc_free(lsa);
1666
result = name2sid(mem_ctx, lsa, account_name_p->string,
1691
result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
1667
1692
authority_name_p->string);
1669
1694
talloc_free(lsa);
1739
1764
struct smbcli_options options;
1740
1765
struct smbcli_session_options session_options;
1742
if (!(mem_ctx = talloc_new(torture))) {
1746
lp_smbcli_options(torture->lp_ctx, &options);
1747
lp_smbcli_session_options(torture->lp_ctx, &session_options);
1767
lpcfg_smbcli_options(torture->lp_ctx, &options);
1768
lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1749
1770
status = smbcli_full_connection(
1750
mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1751
lp_smb_ports(torture->lp_ctx),
1752
"IPC$", NULL, lp_socket_options(torture->lp_ctx), cmdline_credentials,
1753
lp_resolve_context(torture->lp_ctx),
1754
torture->ev, &options, &session_options,
1755
lp_iconv_convenience(torture->lp_ctx),
1756
lp_gensec_settings(torture, torture->lp_ctx));
1757
if (!NT_STATUS_IS_OK(status)) {
1758
d_printf("(%s) smbcli_full_connection failed: %s\n",
1759
__location__, nt_errstr(status));
1771
torture, &cli, torture_setting_string(torture, "host", NULL),
1772
lpcfg_smb_ports(torture->lp_ctx),
1773
"IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
1774
lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
1775
&session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
1776
torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1764
if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
1765
d_printf("(%s) whoami on auth'ed connection failed\n",
1778
if (!(user_sid = whoami(torture, torture, cli->tree))) {
1779
torture_fail(torture, "whoami on auth'ed connection failed\n");
1770
1782
talloc_free(cli);
1772
if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1773
d_printf("(%s) create_anon_creds failed\n", __location__);
1784
if (!(anon_creds = cli_credentials_init_anon(torture))) {
1785
torture_fail(torture, "create_anon_creds failed\n");
1778
1788
status = smbcli_full_connection(
1779
mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1780
lp_smb_ports(torture->lp_ctx), "IPC$", NULL,
1781
lp_socket_options(torture->lp_ctx), anon_creds,
1782
lp_resolve_context(torture->lp_ctx),
1789
torture, &cli, torture_setting_string(torture, "host", NULL),
1790
lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
1791
lpcfg_socket_options(torture->lp_ctx), anon_creds,
1792
lpcfg_resolve_context(torture->lp_ctx),
1783
1793
torture->ev, &options, &session_options,
1784
lp_iconv_convenience(torture->lp_ctx),
1785
lp_gensec_settings(torture, torture->lp_ctx));
1786
if (!NT_STATUS_IS_OK(status)) {
1787
d_printf("(%s) anon smbcli_full_connection failed: %s\n",
1788
__location__, nt_errstr(status));
1793
if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
1794
d_printf("(%s) whoami on anon connection failed\n",
1800
if (!dom_sid_equal(user_sid,
1801
dom_sid_parse_talloc(mem_ctx, "s-1-5-7"))) {
1802
d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
1803
"S-1-5-7", __location__,
1804
dom_sid_string(mem_ctx, user_sid));
1808
if (!(user_creds = cli_credentials_init(mem_ctx))) {
1809
d_printf("(%s) cli_credentials_init failed\n", __location__);
1794
lpcfg_gensec_settings(torture, torture->lp_ctx));
1795
torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
1797
if (!(user_sid = whoami(torture, torture, cli->tree))) {
1798
torture_fail(torture, "whoami on anon connection failed\n");
1801
torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
1802
"Anon lsa_GetUserName returned unexpected SID");
1804
if (!(user_creds = cli_credentials_init(torture))) {
1805
torture_fail(torture, "cli_credentials_init failed\n");
1814
1808
cli_credentials_set_conf(user_creds, torture->lp_ctx);
1815
1809
cli_credentials_set_username(user_creds, "torture_username",
1816
1810
CRED_SPECIFIED);
1817
1811
cli_credentials_set_password(user_creds,
1818
generate_random_str(user_creds, 8),
1812
generate_random_password(user_creds, 8, 255),
1819
1813
CRED_SPECIFIED);
1821
if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
1815
if (!create_user(torture, torture, cli, cmdline_credentials,
1822
1816
cli_credentials_get_username(user_creds),
1823
1817
cli_credentials_get_password(user_creds),
1824
1818
&domain_name, &created_sid)) {
1825
d_printf("(%s) create_user failed\n", __location__);
1819
torture_fail(torture, "create_user failed\n");
1830
1822
cli_credentials_set_domain(user_creds, domain_name,
2400
bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2385
static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2402
TALLOC_CTX *mem_ctx;
2404
2387
struct smbcli_state *cli;
2405
2388
struct security_descriptor *sd;
2406
2389
struct dom_sid *user_sid;
2408
if (!(mem_ctx = talloc_new(torture))) {
2412
2391
if (!(torture_open_connection_share(
2413
mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2392
torture, &cli, torture, torture_setting_string(torture, "host", NULL),
2414
2393
"IPC$", torture->ev))) {
2415
d_printf("IPC$ connection failed\n");
2416
talloc_free(mem_ctx);
2420
if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
2421
d_printf("whoami failed\n");
2422
talloc_free(mem_ctx);
2426
sd = get_sharesec(mem_ctx, torture->lp_ctx, cli->session,
2394
torture_fail(torture, "IPC$ connection failed\n");
2397
if (!(user_sid = whoami(torture, torture, cli->tree))) {
2398
torture_fail(torture, "whoami failed\n");
2401
sd = get_sharesec(torture, torture, cli->session,
2427
2402
torture_setting_string(torture, "share", NULL));
2429
ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
2404
torture_assert(torture, try_tcon(
2405
torture, torture, sd, cli->session,
2430
2406
torture_setting_string(torture, "share", NULL),
2431
user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
2407
user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK),
2408
"failed to test tcon with 0 access_mask");
2433
ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
2410
torture_assert(torture, try_tcon(
2411
torture, torture, sd, cli->session,
2434
2412
torture_setting_string(torture, "share", NULL),
2435
2413
user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2436
NT_STATUS_MEDIA_WRITE_PROTECTED);
2414
NT_STATUS_MEDIA_WRITE_PROTECTED),
2415
"failed to test tcon with SEC_FILE_READ_DATA access_mask");
2438
ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
2417
torture_assert(torture, try_tcon(
2418
torture, torture, sd, cli->session,
2439
2419
torture_setting_string(torture, "share", NULL),
2440
user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
2420
user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
2421
"failed to test tcon with SEC_FILE_ALL access_mask")
2442
talloc_free(mem_ctx);
2446
bool torture_samba3_rpc_lsa(struct torture_context *torture)
2426
static bool torture_samba3_rpc_lsa(struct torture_context *torture)
2448
TALLOC_CTX *mem_ctx;
2450
struct smbcli_state *cli;
2451
2428
struct dcerpc_pipe *p;
2429
struct dcerpc_binding_handle *b;
2452
2430
struct policy_handle lsa_handle;
2454
struct dom_sid *domain_sid;
2456
if (!(mem_ctx = talloc_new(torture))) {
2460
if (!(torture_open_connection_share(
2461
mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2462
"IPC$", torture->ev))) {
2463
d_printf("IPC$ connection failed\n");
2464
talloc_free(mem_ctx);
2468
status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\lsarpc",
2469
&ndr_table_lsarpc, &p);
2470
if (!NT_STATUS_IS_OK(status)) {
2471
d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2473
talloc_free(mem_ctx);
2432
torture_assert_ntstatus_ok(torture,
2433
torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
2434
"failed to setup lsarpc");
2436
b = p->binding_handle;
2478
2439
struct lsa_ObjectAttribute attr;
2479
2440
struct lsa_OpenPolicy2 o;
2480
2441
o.in.system_name = talloc_asprintf(
2481
mem_ctx, "\\\\%s", dcerpc_server_name(p));
2442
torture, "\\\\%s", dcerpc_server_name(p));
2482
2443
ZERO_STRUCT(attr);
2483
2444
o.in.attr = &attr;
2484
2445
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2485
2446
o.out.handle = &lsa_handle;
2486
status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &o);
2487
if (!NT_STATUS_IS_OK(status)) {
2488
d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
2489
__location__, nt_errstr(status));
2490
talloc_free(mem_ctx);
2448
torture_assert_ntstatus_ok(torture,
2449
dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
2450
"dcerpc_lsa_OpenPolicy2 failed");
2451
torture_assert_ntstatus_ok(torture, o.out.result,
2452
"dcerpc_lsa_OpenPolicy2 failed");
2496
p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2501
2457
int levels[] = { 2,3,5,6 };
2549
2499
return NT_STATUS_OK;
2553
static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
2554
struct smbcli_tree *tree,
2555
const char ***printers, int *num_printers)
2557
TALLOC_CTX *mem_ctx;
2559
struct dcerpc_pipe *p;
2502
static bool rap_get_servername(struct torture_context *tctx,
2505
struct smbcli_state *cli;
2507
torture_assert(tctx,
2508
torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
2510
"IPC$ connection failed");
2512
torture_assert_ntstatus_ok(tctx,
2513
get_servername(tctx, cli->tree, servername),
2514
"get_servername failed");
2521
static bool find_printers(struct torture_context *tctx,
2522
struct dcerpc_pipe *p,
2523
const char ***printers,
2560
2526
struct srvsvc_NetShareEnum r;
2561
2527
struct srvsvc_NetShareInfoCtr info_ctr;
2562
2528
struct srvsvc_NetShareCtr1 c1_in;
2563
2529
struct srvsvc_NetShareCtr1 *c1;
2564
2530
uint32_t totalentries = 0;
2567
mem_ctx = talloc_new(ctx);
2568
if (mem_ctx == NULL) {
2569
return NT_STATUS_NO_MEMORY;
2572
status = pipe_bind_smb(mem_ctx, lp_ctx,
2573
tree, "\\srvsvc", &ndr_table_srvsvc,
2575
if (!NT_STATUS_IS_OK(status)) {
2576
d_printf("could not bind to srvsvc pipe\n");
2577
talloc_free(mem_ctx);
2532
struct dcerpc_binding_handle *b = p->binding_handle;
2581
2534
ZERO_STRUCT(c1_in);
2582
2535
info_ctr.level = 1;
2583
2536
info_ctr.ctr.ctr1 = &c1_in;
2585
2538
r.in.server_unc = talloc_asprintf(
2586
mem_ctx, "\\\\%s", dcerpc_server_name(p));
2539
tctx, "\\\\%s", dcerpc_server_name(p));
2587
2540
r.in.info_ctr = &info_ctr;
2588
2541
r.in.max_buffer = (uint32_t)-1;
2589
2542
r.in.resume_handle = NULL;
2590
2543
r.out.totalentries = &totalentries;
2591
2544
r.out.info_ctr = &info_ctr;
2593
status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
2594
if (!NT_STATUS_IS_OK(status)) {
2595
d_printf("NetShareEnum level %u failed - %s\n",
2596
info_ctr.level, nt_errstr(status));
2597
talloc_free(mem_ctx);
2546
torture_assert_ntstatus_ok(tctx,
2547
dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
2548
"NetShareEnum level 1 failed");
2549
torture_assert_werr_ok(tctx, r.out.result,
2550
"NetShareEnum level 1 failed");
2601
2552
*printers = NULL;
2602
2553
*num_printers = 0;
2635
2584
r.out.count = &count;
2636
2585
r.out.info = &info;
2638
status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2639
if (!NT_STATUS_IS_OK(status)) {
2640
d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
2641
__location__, nt_errstr(status));
2645
if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2646
d_printf("(%s) EnumPrinters unexpected return code %s, should "
2647
"be WERR_INSUFFICIENT_BUFFER\n", __location__,
2648
win_errstr(r.out.result));
2652
blob = data_blob_talloc_zero(mem_ctx, needed);
2587
torture_assert_ntstatus_ok(tctx,
2588
dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2589
"dcerpc_spoolss_EnumPrinters failed");
2590
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2591
"EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2593
blob = data_blob_talloc_zero(tctx, needed);
2653
2594
if (blob.data == NULL) {
2654
d_printf("(%s) data_blob_talloc failed\n", __location__);
2658
2598
r.in.buffer = &blob;
2659
2599
r.in.offered = needed;
2661
status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2662
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2663
d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
2664
"%s\n", __location__, nt_errstr(status),
2665
win_errstr(r.out.result));
2601
torture_assert_ntstatus_ok(tctx,
2602
dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2603
"dcerpc_spoolss_EnumPrinters failed");
2604
torture_assert_werr_ok(tctx, r.out.result,
2605
"dcerpc_spoolss_EnumPrinters failed");
2669
2607
*num_printers = count;
2674
static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
2675
struct policy_handle *handle, int level,
2676
union spoolss_PrinterInfo **res)
2612
static bool getprinterinfo(struct torture_context *tctx,
2613
struct dcerpc_binding_handle *b,
2614
struct policy_handle *handle, int level,
2615
union spoolss_PrinterInfo **res)
2678
TALLOC_CTX *mem_ctx;
2679
2617
struct spoolss_GetPrinter r;
2680
2618
DATA_BLOB blob;
2682
2619
uint32_t needed;
2684
mem_ctx = talloc_new(ctx);
2685
if (mem_ctx == NULL) {
2686
return NT_STATUS_NO_MEMORY;
2689
2621
r.in.handle = handle;
2690
2622
r.in.level = level;
2691
2623
r.in.buffer = NULL;
2692
2624
r.in.offered = 0;
2693
2625
r.out.needed = &needed;
2695
status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2696
if (!NT_STATUS_IS_OK(status)) {
2697
d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s\n",
2698
__location__, nt_errstr(status));
2699
talloc_free(mem_ctx);
2703
if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2704
printf("GetPrinter unexpected return code %s, should "
2705
"be WERR_INSUFFICIENT_BUFFER\n",
2706
win_errstr(r.out.result));
2707
talloc_free(mem_ctx);
2708
return NT_STATUS_UNSUCCESSFUL;
2627
torture_assert_ntstatus_ok(tctx,
2628
dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2629
"dcerpc_spoolss_GetPrinter failed");
2630
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2631
"GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2711
2633
r.in.handle = handle;
2712
2634
r.in.level = level;
2713
blob = data_blob_talloc(mem_ctx, NULL, needed);
2635
blob = data_blob_talloc_zero(tctx, needed);
2714
2636
if (blob.data == NULL) {
2715
talloc_free(mem_ctx);
2716
return NT_STATUS_NO_MEMORY;
2718
memset(blob.data, 0, blob.length);
2719
2639
r.in.buffer = &blob;
2720
2640
r.in.offered = needed;
2722
status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2723
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2724
d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s, "
2725
"%s\n", __location__, nt_errstr(status),
2726
win_errstr(r.out.result));
2727
talloc_free(mem_ctx);
2728
return NT_STATUS_IS_OK(status) ?
2729
NT_STATUS_UNSUCCESSFUL : status;
2642
torture_assert_ntstatus_ok(tctx,
2643
dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2644
"dcerpc_spoolss_GetPrinter failed");
2645
torture_assert_werr_ok(tctx, r.out.result,
2646
"dcerpc_spoolss_GetPrinter failed");
2732
2648
if (res != NULL) {
2733
*res = talloc_steal(ctx, r.out.info);
2649
*res = talloc_steal(tctx, r.out.info);
2736
talloc_free(mem_ctx);
2737
return NT_STATUS_OK;
2740
bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2655
static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2742
TALLOC_CTX *mem_ctx;
2744
struct smbcli_state *cli;
2745
struct dcerpc_pipe *p;
2657
struct dcerpc_pipe *p, *p2;
2658
struct dcerpc_binding_handle *b;
2747
2659
struct policy_handle server_handle, printer_handle;
2748
2660
const char **printers;
2749
2661
int num_printers;
2750
2662
struct spoolss_UserLevel1 userlevel1;
2751
2663
char *servername;
2753
if (!(mem_ctx = talloc_new(torture))) {
2757
if (!(torture_open_connection_share(
2758
mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2759
"IPC$", torture->ev))) {
2760
d_printf("IPC$ connection failed\n");
2761
talloc_free(mem_ctx);
2765
status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
2766
if (!NT_STATUS_IS_OK(status)) {
2767
d_fprintf(stderr, "(%s) get_servername returned %s\n",
2768
__location__, nt_errstr(status));
2769
talloc_free(mem_ctx);
2773
if (!NT_STATUS_IS_OK(find_printers(mem_ctx, torture->lp_ctx, cli->tree,
2774
&printers, &num_printers))) {
2775
talloc_free(mem_ctx);
2665
torture_assert(torture,
2666
rap_get_servername(torture, &servername),
2667
"failed to rap servername");
2669
torture_assert_ntstatus_ok(torture,
2670
torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
2671
"failed to setup srvsvc");
2673
torture_assert(torture,
2674
find_printers(torture, p2, &printers, &num_printers),
2675
"failed to find printers via srvsvc");
2779
2679
if (num_printers == 0) {
2780
d_printf("Did not find printers\n");
2781
talloc_free(mem_ctx);
2680
torture_skip(torture, "Did not find printers\n");
2785
status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\spoolss",
2786
&ndr_table_spoolss, &p);
2787
if (!NT_STATUS_IS_OK(status)) {
2788
d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2790
talloc_free(mem_ctx);
2684
torture_assert_ntstatus_ok(torture,
2685
torture_rpc_connection(torture, &p, &ndr_table_spoolss),
2686
"failed to setup spoolss");
2688
b = p->binding_handle;
2794
2690
ZERO_STRUCT(userlevel1);
2795
2691
userlevel1.client = talloc_asprintf(
2796
mem_ctx, "\\\\%s", lp_netbios_name(torture->lp_ctx));
2692
torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
2797
2693
userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2798
2694
userlevel1.build = 2600;
2799
2695
userlevel1.major = 3;
2880
2763
r.in.handle = &printer_handle;
2881
2764
r.out.handle = &printer_handle;
2883
status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2884
if (!NT_STATUS_IS_OK(status)) {
2885
d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2886
"%s\n", __location__, nt_errstr(status));
2887
talloc_free(mem_ctx);
2894
if (!enumprinters(mem_ctx, p, servername, 1,
2896
d_printf("(%s) enumprinters failed\n", __location__);
2897
talloc_free(mem_ctx);
2900
if (num_printers != num_enumerated) {
2901
d_printf("(%s) netshareenum gave %d printers, "
2902
"enumprinters lvl 1 gave %d\n", __location__,
2903
num_printers, num_enumerated);
2904
talloc_free(mem_ctx);
2911
if (!enumprinters(mem_ctx, p, servername, 2,
2913
d_printf("(%s) enumprinters failed\n", __location__);
2914
talloc_free(mem_ctx);
2917
if (num_printers != num_enumerated) {
2918
d_printf("(%s) netshareenum gave %d printers, "
2919
"enumprinters lvl 2 gave %d\n", __location__,
2920
num_printers, num_enumerated);
2921
talloc_free(mem_ctx);
2926
talloc_free(mem_ctx);
2766
torture_assert_ntstatus_ok(torture,
2767
dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2768
"dcerpc_spoolss_ClosePrinter failed");
2769
torture_assert_werr_ok(torture, r.out.result,
2770
"dcerpc_spoolss_ClosePrinter failed");
2776
torture_assert(torture,
2777
enumprinters(torture, b, servername, 1, &num_enumerated),
2778
"enumprinters failed");
2780
torture_assert_int_equal(torture, num_printers, num_enumerated,
2781
"netshareenum / enumprinters lvl 1 numprinter mismatch");
2787
torture_assert(torture,
2788
enumprinters(torture, b, servername, 2, &num_enumerated),
2789
"enumprinters failed");
2791
torture_assert_int_equal(torture, num_printers, num_enumerated,
2792
"netshareenum / enumprinters lvl 2 numprinter mismatch");
2931
bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2798
static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2933
TALLOC_CTX *mem_ctx;
2934
struct smbcli_state *cli;
2935
2800
struct dcerpc_pipe *p;
2801
struct dcerpc_binding_handle *b;
2937
2802
char *servername;
2939
if (!(mem_ctx = talloc_new(torture))) {
2943
if (!(torture_open_connection_share(
2944
mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2945
"IPC$", torture->ev))) {
2946
d_printf("IPC$ connection failed\n");
2947
talloc_free(mem_ctx);
2951
status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
2952
if (!NT_STATUS_IS_OK(status)) {
2953
d_fprintf(stderr, "(%s) get_servername returned %s\n",
2954
__location__, nt_errstr(status));
2955
talloc_free(mem_ctx);
2959
status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\wkssvc",
2960
&ndr_table_wkssvc, &p);
2961
if (!NT_STATUS_IS_OK(status)) {
2962
d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2964
talloc_free(mem_ctx);
2804
torture_assert(torture,
2805
rap_get_servername(torture, &servername),
2806
"failed to rap servername");
2808
torture_assert_ntstatus_ok(torture,
2809
torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
2810
"failed to setup wkssvc");
2812
b = p->binding_handle;
2969
2815
struct wkssvc_NetWkstaInfo100 wks100;
2975
2821
info.info100 = &wks100;
2976
2822
r.out.info = &info;
2978
status = dcerpc_wkssvc_NetWkstaGetInfo(p, mem_ctx, &r);
2979
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2980
d_printf("(%s) dcerpc_wkssvc_NetWksGetInfo failed: "
2981
"%s, %s\n", __location__, nt_errstr(status),
2982
win_errstr(r.out.result));
2983
talloc_free(mem_ctx);
2824
torture_assert_ntstatus_ok(torture,
2825
dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
2826
"dcerpc_wkssvc_NetWksGetInfo failed");
2827
torture_assert_werr_ok(torture, r.out.result,
2828
"dcerpc_wkssvc_NetWksGetInfo failed");
2987
if (strcmp(servername,
2988
r.out.info->info100->server_name) != 0) {
2989
d_printf("(%s) servername inconsistency: RAP=%s, "
2990
"dcerpc_wkssvc_NetWksGetInfo=%s",
2991
__location__, servername,
2992
r.out.info->info100->server_name);
2993
talloc_free(mem_ctx);
2830
torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
2831
"servername RAP / DCERPC inconsistency");
2998
talloc_free(mem_ctx);
3002
static NTSTATUS winreg_close(struct dcerpc_pipe *p,
3003
struct policy_handle *handle)
2837
static bool winreg_close(struct torture_context *tctx,
2838
struct dcerpc_binding_handle *b,
2839
struct policy_handle *handle)
3005
2841
struct winreg_CloseKey c;
3007
TALLOC_CTX *mem_ctx;
3009
2843
c.in.handle = c.out.handle = handle;
3011
if (!(mem_ctx = talloc_new(p))) {
3012
return NT_STATUS_NO_MEMORY;
3015
status = dcerpc_winreg_CloseKey(p, mem_ctx, &c);
3016
talloc_free(mem_ctx);
3018
if (!NT_STATUS_IS_OK(status)) {
3022
if (!W_ERROR_IS_OK(c.out.result)) {
3023
return werror_to_ntstatus(c.out.result);
3026
return NT_STATUS_OK;
2845
torture_assert_ntstatus_ok(tctx,
2846
dcerpc_winreg_CloseKey_r(b, tctx, &c),
2847
"winreg_CloseKey failed");
2848
torture_assert_werr_ok(tctx, c.out.result,
2849
"winreg_CloseKey failed");
3029
static NTSTATUS enumvalues(struct dcerpc_pipe *p, struct policy_handle *handle,
3030
TALLOC_CTX *mem_ctx)
2854
static bool enumvalues(struct torture_context *tctx,
2855
struct dcerpc_binding_handle *b,
2856
struct policy_handle *handle)
3032
2858
uint32_t enum_index = 0;
3082
2910
r.in.last_changed_time = &t;
3085
TALLOC_CTX *tmp_ctx;
3086
2913
struct winreg_OpenKey o;
3087
2914
struct policy_handle key_handle;
3090
if (!(tmp_ctx = talloc_new(mem_ctx))) {
3091
return NT_STATUS_NO_MEMORY;
3094
2917
name.name = NULL;
3095
2918
name.size = 1024;
3097
status = dcerpc_winreg_EnumKey(p, tmp_ctx, &r);
2920
status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
3098
2921
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3099
2922
/* We're done enumerating */
3100
talloc_free(tmp_ctx);
3101
return NT_STATUS_OK;
3104
for (i=0; i<10-depth; i++)
3106
printf("%s\n", r.out.name->name);
2926
for (i=0; i<10-depth; i++) {
2927
torture_comment(tctx, " ");
2929
torture_comment(tctx, "%s\n", r.out.name->name);
3109
2931
o.in.parent_handle = handle;
3110
2932
o.in.keyname.name = r.out.name->name;
3112
2934
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3113
2935
o.out.handle = &key_handle;
3115
status = dcerpc_winreg_OpenKey(p, tmp_ctx, &o);
2937
status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
3116
2938
if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
3117
enumkeys(p, &key_handle, tmp_ctx, depth-1);
3118
enumvalues(p, &key_handle, tmp_ctx);
3119
status = winreg_close(p, &key_handle);
3120
if (!NT_STATUS_IS_OK(status)) {
2939
enumkeys(tctx, b, &key_handle, depth-1);
2940
enumvalues(tctx, b, &key_handle);
2941
torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
3125
talloc_free(tmp_ctx);
3127
2944
r.in.enum_index += 1;
3130
return NT_STATUS_OK;
3133
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
2950
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
3135
static bool test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
2952
static bool test_Open3(struct torture_context *tctx,
2953
struct dcerpc_binding_handle *b,
3136
2954
const char *name, winreg_open_fn open_fn)
3138
2956
struct policy_handle handle;
3139
2957
struct winreg_OpenHKLM r;
3142
2959
r.in.system_name = 0;
3143
2960
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3144
2961
r.out.handle = &handle;
3146
status = open_fn(p, mem_ctx, &r);
3147
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3148
d_printf("(%s) %s failed: %s, %s\n", __location__, name,
3149
nt_errstr(status), win_errstr(r.out.result));
3153
enumkeys(p, &handle, mem_ctx, 4);
3155
status = winreg_close(p, &handle);
3156
if (!NT_STATUS_IS_OK(status)) {
3157
d_printf("(%s) dcerpc_CloseKey failed: %s\n",
3158
__location__, nt_errstr(status));
2963
torture_assert_ntstatus_ok(tctx,
2964
open_fn(b, tctx, &r),
2965
talloc_asprintf(tctx, "%s failed", name));
2966
torture_assert_werr_ok(tctx, r.out.result,
2967
talloc_asprintf(tctx, "%s failed", name));
2969
enumkeys(tctx, b, &handle, 4);
2971
torture_assert(tctx,
2972
winreg_close(tctx, b, &handle),
2973
"dcerpc_CloseKey failed");
3165
bool torture_samba3_rpc_winreg(struct torture_context *torture)
2978
static bool torture_samba3_rpc_winreg(struct torture_context *torture)
3168
2980
struct dcerpc_pipe *p;
3169
TALLOC_CTX *mem_ctx;
2981
struct dcerpc_binding_handle *b;
3170
2982
bool ret = true;
3172
2984
const char *name;
3173
2985
winreg_open_fn fn;
3174
2986
} open_fns[] = {
3175
{"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM },
3176
{"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU },
3177
{"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD },
3178
{"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT },
3179
{"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }};
2987
{"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
2988
{"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
2989
{"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
2990
{"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
2991
{"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
3184
mem_ctx = talloc_init("torture_rpc_winreg");
3186
status = torture_rpc_connection(torture, &p, &ndr_table_winreg);
3188
if (!NT_STATUS_IS_OK(status)) {
3189
talloc_free(mem_ctx);
2996
torture_assert_ntstatus_ok(torture,
2997
torture_rpc_connection(torture, &p, &ndr_table_winreg),
2998
"failed to setup winreg");
3000
b = p->binding_handle;
3194
ret = test_Open3(p, mem_ctx, open_fns[0].name, open_fns[0].fn);
3003
ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
3196
3005
for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
3197
if (!test_Open3(p, mem_ctx, open_fns[i].name, open_fns[i].fn))
3006
if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
3202
talloc_free(mem_ctx);
3207
static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
3208
struct loadparm_context *lp_ctx,
3209
struct smbcli_state *cli,
3211
struct srvsvc_NetShareInfo502 **info502)
3013
static bool get_shareinfo(struct torture_context *tctx,
3014
struct dcerpc_binding_handle *b,
3015
const char *servername,
3017
struct srvsvc_NetShareInfo502 **info502)
3213
struct smbcli_tree *ipc;
3214
struct dcerpc_pipe *p;
3215
3019
struct srvsvc_NetShareGetInfo r;
3216
3020
union srvsvc_NetShareInfo info;
3219
if (!(p = dcerpc_pipe_init(cli,
3220
cli->transport->socket->event.ctx,
3221
lp_iconv_convenience(lp_ctx)))) {
3222
status = NT_STATUS_NO_MEMORY;
3226
status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3227
if (!NT_STATUS_IS_OK(status)) {
3231
status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
3232
if (!NT_STATUS_IS_OK(status)) {
3233
d_printf("dcerpc_pipe_open_smb failed: %s\n",
3238
status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
3239
if (!NT_STATUS_IS_OK(status)) {
3240
d_printf("dcerpc_bind_auth_none failed: %s\n",
3245
r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
3246
dcerpc_server_name(p));
3022
r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
3247
3023
r.in.share_name = share;
3248
3024
r.in.level = 502;
3249
3025
r.out.info = &info;
3251
status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
3252
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3253
d_printf("(%s) srvsvc_NetShareGetInfo failed: %s, %s\n", __location__,
3254
nt_errstr(status), win_errstr(r.out.result));
3255
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(r.out.result) : status;
3259
*info502 = talloc_move(mem_ctx, &info.info502);
3260
return NT_STATUS_OK;
3027
torture_assert_ntstatus_ok(tctx,
3028
dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
3029
"srvsvc_NetShareGetInfo failed");
3030
torture_assert_werr_ok(tctx, r.out.result,
3031
"srvsvc_NetShareGetInfo failed");
3033
*info502 = talloc_move(tctx, &info.info502);
3268
3039
* Get us a handle on HKLM\
3271
static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
3272
struct smbcli_state *cli,
3273
struct smb_iconv_convenience *iconv_convenience,
3274
struct dcerpc_pipe **pipe_p,
3275
struct policy_handle **handle)
3042
static bool get_hklm_handle(struct torture_context *tctx,
3043
struct dcerpc_binding_handle *b,
3044
struct policy_handle *handle)
3277
struct smbcli_tree *ipc;
3278
struct dcerpc_pipe *p;
3279
3046
struct winreg_OpenHKLM r;
3281
struct policy_handle *result;
3283
result = talloc(mem_ctx, struct policy_handle);
3285
if (result == NULL) {
3286
return NT_STATUS_NO_MEMORY;
3289
if (!(p = dcerpc_pipe_init(result,
3290
cli->transport->socket->event.ctx,
3291
iconv_convenience))) {
3292
status = NT_STATUS_NO_MEMORY;
3296
status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3297
if (!NT_STATUS_IS_OK(status)) {
3301
status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
3302
if (!NT_STATUS_IS_OK(status)) {
3303
d_printf("dcerpc_pipe_open_smb failed: %s\n",
3308
status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
3309
if (!NT_STATUS_IS_OK(status)) {
3310
d_printf("dcerpc_bind_auth_none failed: %s\n",
3047
struct policy_handle result;
3315
3049
r.in.system_name = 0;
3316
3050
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3317
r.out.handle = result;
3319
status = dcerpc_winreg_OpenHKLM(p, p, &r);
3320
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3321
d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3322
nt_errstr(status), win_errstr(r.out.result));
3323
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(r.out.result) : status;
3051
r.out.handle = &result;
3053
torture_assert_ntstatus_ok(tctx,
3054
dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
3056
torture_assert_werr_ok(tctx, r.out.result,
3328
3059
*handle = result;
3329
return NT_STATUS_OK;
3332
talloc_free(result);
3336
static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
3337
struct smb_iconv_convenience *iconv_convenience,
3338
const char *sharename)
3064
static bool torture_samba3_createshare(struct torture_context *tctx,
3065
struct dcerpc_binding_handle *b,
3066
const char *sharename)
3340
struct dcerpc_pipe *p;
3341
struct policy_handle *hklm = NULL;
3068
struct policy_handle hklm;
3342
3069
struct policy_handle new_handle;
3343
3070
struct winreg_CreateKey c;
3344
3071
struct winreg_CloseKey cl;
3345
3072
enum winreg_CreateAction action_taken;
3347
TALLOC_CTX *mem_ctx;
3349
mem_ctx = talloc_new(cli);
3350
NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3352
status = get_hklm_handle(mem_ctx, cli, iconv_convenience, &p, &hklm);
3353
if (!NT_STATUS_IS_OK(status)) {
3354
d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3074
c.in.handle = &hklm;
3359
3075
c.in.name.name = talloc_asprintf(
3360
mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3361
if (c.in.name.name == NULL) {
3362
d_printf("talloc_asprintf failed\n");
3363
status = NT_STATUS_NO_MEMORY;
3076
tctx, "software\\samba\\smbconf\\%s", sharename);
3077
torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
3366
3079
c.in.keyclass.name = "";
3367
3080
c.in.options = 0;
3368
3081
c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3371
3084
c.out.new_handle = &new_handle;
3372
3085
c.out.action_taken = &action_taken;
3374
status = dcerpc_winreg_CreateKey(p, p, &c);
3375
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
3376
d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3377
nt_errstr(status), win_errstr(c.out.result));
3378
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(c.out.result) : status;
3087
torture_assert_ntstatus_ok(tctx,
3088
dcerpc_winreg_CreateKey_r(b, tctx, &c),
3090
torture_assert_werr_ok(tctx, c.out.result,
3382
3093
cl.in.handle = &new_handle;
3383
3094
cl.out.handle = &new_handle;
3384
status = dcerpc_winreg_CloseKey(p, p, &cl);
3385
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
3386
d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3387
nt_errstr(status), win_errstr(cl.out.result));
3388
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(cl.out.result) : status;
3394
talloc_free(mem_ctx);
3096
torture_assert_ntstatus_ok(tctx,
3097
dcerpc_winreg_CloseKey_r(b, tctx, &cl),
3099
torture_assert_werr_ok(tctx, cl.out.result,
3398
static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
3399
struct smbcli_state *cli,
3400
const char *sharename)
3105
static bool torture_samba3_deleteshare(struct torture_context *tctx,
3106
struct dcerpc_binding_handle *b,
3107
const char *sharename)
3402
struct dcerpc_pipe *p;
3403
struct policy_handle *hklm = NULL;
3109
struct policy_handle hklm;
3404
3110
struct winreg_DeleteKey d;
3406
TALLOC_CTX *mem_ctx;
3408
mem_ctx = talloc_new(cli);
3409
NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3411
status = get_hklm_handle(cli, cli, lp_iconv_convenience(torture->lp_ctx),
3413
if (!NT_STATUS_IS_OK(status)) {
3414
d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3112
torture_assert(tctx,
3113
get_hklm_handle(tctx, b, &hklm),
3114
"get_hklm_handle failed");
3116
d.in.handle = &hklm;
3419
3117
d.in.key.name = talloc_asprintf(
3420
mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3421
if (d.in.key.name == NULL) {
3422
d_printf("talloc_asprintf failed\n");
3423
status = NT_STATUS_NO_MEMORY;
3426
status = dcerpc_winreg_DeleteKey(p, p, &d);
3427
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
3428
d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3429
nt_errstr(status), win_errstr(d.out.result));
3430
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(d.out.result) : status;
3435
talloc_free(mem_ctx);
3118
tctx, "software\\samba\\smbconf\\%s", sharename);
3119
torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
3121
torture_assert_ntstatus_ok(tctx,
3122
dcerpc_winreg_DeleteKey_r(b, tctx, &d),
3123
"DeleteKey failed");
3124
torture_assert_werr_ok(tctx, d.out.result,
3125
"DeleteKey failed");
3439
static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
3440
struct loadparm_context *lp_ctx,
3441
const char *sharename,
3442
const char *parameter,
3130
static bool torture_samba3_setconfig(struct torture_context *tctx,
3131
struct dcerpc_binding_handle *b,
3132
const char *sharename,
3133
const char *parameter,
3445
struct dcerpc_pipe *p = NULL;
3446
struct policy_handle *hklm = NULL, key_handle;
3136
struct policy_handle hklm, key_handle;
3447
3137
struct winreg_OpenKey o;
3448
3138
struct winreg_SetValue s;
3453
status = get_hklm_handle(cli, cli, lp_iconv_convenience(lp_ctx), &p, &hklm);
3454
if (!NT_STATUS_IS_OK(status)) {
3455
d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3459
o.in.parent_handle = hklm;
3142
torture_assert(tctx,
3143
get_hklm_handle(tctx, b, &hklm),
3144
"get_hklm_handle failed");
3146
o.in.parent_handle = &hklm;
3460
3147
o.in.keyname.name = talloc_asprintf(
3461
hklm, "software\\samba\\smbconf\\%s", sharename);
3462
if (o.in.keyname.name == NULL) {
3463
d_printf("talloc_asprintf failed\n");
3464
status = NT_STATUS_NO_MEMORY;
3148
tctx, "software\\samba\\smbconf\\%s", sharename);
3149
torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
3468
3152
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3469
3153
o.out.handle = &key_handle;
3471
status = dcerpc_winreg_OpenKey(p, p, &o);
3472
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
3473
d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3474
nt_errstr(status), win_errstr(o.out.result));
3475
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(o.out.result) : status;
3155
torture_assert_ntstatus_ok(tctx,
3156
dcerpc_winreg_OpenKey_r(b, tctx, &o),
3158
torture_assert_werr_ok(tctx, o.out.result,
3479
if (!reg_string_to_val(hklm, lp_iconv_convenience(lp_ctx), "REG_SZ",
3480
value, &type, &val)) {
3481
d_printf("(%s) reg_string_to_val failed\n", __location__);
3161
torture_assert(tctx,
3162
reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
3163
"reg_string_to_val failed");
3485
3165
s.in.handle = &key_handle;
3486
3166
s.in.name.name = parameter;
3488
3168
s.in.data = val.data;
3489
3169
s.in.size = val.length;
3491
status = dcerpc_winreg_SetValue(p, p, &s);
3492
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
3493
d_printf("(%s) SetValue failed: %s, %s\n", __location__,
3494
nt_errstr(status), win_errstr(s.out.result));
3495
status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(s.out.result) : status;
3171
torture_assert_ntstatus_ok(tctx,
3172
dcerpc_winreg_SetValue_r(b, tctx, &s),
3174
torture_assert_werr_ok(tctx, s.out.result,
3504
bool torture_samba3_regconfig(struct torture_context *torture)
3180
static bool torture_samba3_regconfig(struct torture_context *torture)
3506
struct smbcli_state *cli;
3507
3182
struct srvsvc_NetShareInfo502 *i = NULL;
3510
3183
const char *comment = "Dummer Kommentar";
3512
if (!(torture_open_connection(&cli, torture, 0))) {
3516
status = torture_samba3_createshare(cli, lp_iconv_convenience(torture->lp_ctx), "blubber");
3517
if (!NT_STATUS_IS_OK(status)) {
3518
torture_warning(torture, "torture_samba3_createshare failed: "
3519
"%s\n", nt_errstr(status));
3523
status = torture_samba3_setconfig(cli, torture->lp_ctx, "blubber", "comment", comment);
3524
if (!NT_STATUS_IS_OK(status)) {
3525
torture_warning(torture, "torture_samba3_setconfig failed: "
3526
"%s\n", nt_errstr(status));
3530
status = get_shareinfo(torture, torture->lp_ctx, cli, "blubber", &i);
3531
if (!NT_STATUS_IS_OK(status)) {
3532
torture_warning(torture, "get_shareinfo failed: "
3533
"%s\n", nt_errstr(status));
3537
if (strcmp(comment, i->comment) != 0) {
3538
torture_warning(torture, "Expected comment [%s], got [%s]\n",
3539
comment, i->comment);
3543
status = torture_samba3_deleteshare(torture, cli, "blubber");
3544
if (!NT_STATUS_IS_OK(status)) {
3545
torture_warning(torture, "torture_samba3_deleteshare failed: "
3546
"%s\n", nt_errstr(status));
3184
struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
3186
torture_assert_ntstatus_ok(torture,
3187
torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
3188
"failed to setup srvsvc");
3190
torture_assert_ntstatus_ok(torture,
3191
torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
3192
"failed to setup winreg");
3194
torture_assert(torture,
3195
torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
3196
"torture_samba3_createshare failed");
3198
torture_assert(torture,
3199
torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
3200
"torture_samba3_setconfig failed");
3202
torture_assert(torture,
3203
get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
3204
"get_shareinfo failed");
3206
torture_assert_str_equal(torture, comment, i->comment,
3207
"got unexpected comment");
3209
torture_assert(torture,
3210
torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
3211
"torture_samba3_deleteshare failed");
3217
* Test that even with a result of 0 rids the array is returned as a
3218
* non-NULL pointer. Yes, XP does notice.
3221
bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
3223
struct dcerpc_pipe *p;
3224
struct dcerpc_binding_handle *b;
3225
struct samr_Connect2 c;
3226
struct samr_OpenDomain o;
3228
struct lsa_SidPtr ptr;
3229
struct lsa_SidArray sids;
3230
struct samr_GetAliasMembership g;
3231
struct samr_Ids rids;
3232
struct policy_handle samr, domain;
3234
torture_assert_ntstatus_ok(torture,
3235
torture_rpc_connection(torture, &p, &ndr_table_samr),
3236
"failed to setup samr");
3238
b = p->binding_handle;
3240
c.in.system_name = NULL;
3241
c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
3242
c.out.connect_handle = &samr;
3243
torture_assert_ntstatus_ok(torture,
3244
dcerpc_samr_Connect2_r(b, torture, &c),
3246
torture_assert_ntstatus_ok(torture, c.out.result,
3248
dom_sid_parse("S-1-5-32", &sid);
3249
o.in.connect_handle = &samr;
3250
o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
3252
o.out.domain_handle = &domain;
3253
torture_assert_ntstatus_ok(torture,
3254
dcerpc_samr_OpenDomain_r(b, torture, &o),
3256
torture_assert_ntstatus_ok(torture, o.out.result,
3258
dom_sid_parse("S-1-2-3-4-5", &sid);
3262
g.in.domain_handle = &domain;
3265
torture_assert_ntstatus_ok(torture,
3266
dcerpc_samr_GetAliasMembership_r(b, torture, &g),
3268
torture_assert_ntstatus_ok(torture, g.out.result,
3270
if (rids.ids == NULL) {
3271
/* This is the piece to test here */
3272
torture_fail(torture,
3273
"torture_samba3_getaliasmembership_0: "
3274
"Server returns NULL rids array\n");
3280
struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
3282
struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
3284
torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
3285
torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
3286
torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
3287
torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
3288
torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
3289
torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
3290
torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
3291
torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
3292
torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
3293
torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
3294
torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
3295
torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
3296
torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
3298
suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");