1528
static bool test_QueryValue(struct dcerpc_pipe *p,
1659
static bool test_QueryMultipleValues_full(struct dcerpc_binding_handle *b,
1660
struct torture_context *tctx,
1661
struct policy_handle *handle,
1662
uint32_t num_values,
1663
const char * const *valuenames,
1664
bool existing_value)
1666
struct winreg_QueryMultipleValues r;
1667
uint32_t bufsize = 0;
1670
torture_comment(tctx, "Testing QueryMultipleValues\n");
1674
r.in.key_handle = handle;
1675
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 0);
1676
r.in.buffer_size = r.out.buffer_size = &bufsize;
1678
torture_assert_ntstatus_ok(tctx,
1679
dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1680
"QueryMultipleValues failed");
1681
torture_assert_werr_ok(tctx, r.out.result,
1682
"QueryMultipleValues failed");
1684
/* this test crashes w2k8 remote registry */
1686
r.in.num_values = num_values;
1687
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1689
torture_assert_ntstatus_ok(tctx,
1690
dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1691
"QueryMultipleValues failed");
1692
torture_assert_werr_ok(tctx, r.out.result,
1693
"QueryMultipleValues failed");
1695
r.in.num_values = num_values;
1696
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1697
for (i=0; i < r.in.num_values; i++) {
1698
r.in.values_in[i].ve_valuename = talloc_zero(tctx, struct winreg_ValNameBuf);
1699
r.in.values_in[i].ve_valuename->name = talloc_strdup(tctx, valuenames[i]);
1700
r.in.values_in[i].ve_valuename->size = strlen_m_term(r.in.values_in[i].ve_valuename->name)*2;
1703
torture_assert_ntstatus_ok(tctx,
1704
dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1705
"QueryMultipleValues failed");
1706
torture_assert_werr_equal(tctx, r.out.result, existing_value ? WERR_MORE_DATA : WERR_BADFILE,
1707
"QueryMultipleValues failed");
1709
if (W_ERROR_EQUAL(r.out.result, WERR_BADFILE)) {
1713
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1714
*r.in.buffer_size = 0xff;
1715
r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.buffer_size);
1717
torture_assert_ntstatus_ok(tctx,
1718
dcerpc_winreg_QueryMultipleValues_r(b, tctx, &r),
1719
"QueryMultipleValues failed");
1722
torture_assert_werr_ok(tctx, r.out.result,
1723
"QueryMultipleValues failed");
1729
static bool test_QueryMultipleValues2_full(struct dcerpc_binding_handle *b,
1730
struct torture_context *tctx,
1731
struct policy_handle *handle,
1732
uint32_t num_values,
1733
const char * const *valuenames,
1734
bool existing_value)
1736
struct winreg_QueryMultipleValues2 r;
1737
uint32_t offered = 0, needed;
1740
torture_comment(tctx, "Testing QueryMultipleValues2\n");
1744
r.in.key_handle = handle;
1745
r.in.offered = &offered;
1746
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 0);
1747
r.out.needed = &needed;
1749
torture_assert_ntstatus_ok(tctx,
1750
dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1751
"QueryMultipleValues2 failed");
1752
torture_assert_werr_ok(tctx, r.out.result,
1753
"QueryMultipleValues2 failed");
1755
/* this test crashes w2k8 remote registry */
1757
r.in.num_values = num_values;
1758
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1760
torture_assert_ntstatus_ok(tctx,
1761
dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1762
"QueryMultipleValues2 failed");
1763
torture_assert_werr_ok(tctx, r.out.result,
1764
"QueryMultipleValues2 failed");
1766
r.in.num_values = num_values;
1767
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, num_values);
1768
for (i=0; i < r.in.num_values; i++) {
1769
r.in.values_in[i].ve_valuename = talloc_zero(tctx, struct winreg_ValNameBuf);
1770
r.in.values_in[i].ve_valuename->name = talloc_strdup(tctx, valuenames[i]);
1771
r.in.values_in[i].ve_valuename->size = strlen_m_term(r.in.values_in[i].ve_valuename->name)*2;
1774
torture_assert_ntstatus_ok(tctx,
1775
dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1776
"QueryMultipleValues2 failed");
1777
torture_assert_werr_equal(tctx, r.out.result, existing_value ? WERR_MORE_DATA : WERR_BADFILE,
1778
"QueryMultipleValues2 failed");
1780
if (W_ERROR_EQUAL(r.out.result, WERR_BADFILE)) {
1784
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1785
*r.in.offered = *r.out.needed;
1786
r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.offered);
1788
torture_assert_ntstatus_ok(tctx,
1789
dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1790
"QueryMultipleValues2 failed");
1793
torture_assert_werr_ok(tctx, r.out.result,
1794
"QueryMultipleValues2 failed");
1799
static bool test_QueryMultipleValues2(struct dcerpc_binding_handle *b,
1800
struct torture_context *tctx,
1801
struct policy_handle *handle,
1802
const char *valuename)
1804
struct winreg_QueryMultipleValues2 r;
1805
uint32_t offered = 0, needed;
1809
r.in.key_handle = handle;
1810
r.in.values_in = r.out.values_out = talloc_zero_array(tctx, struct QueryMultipleValue, 1);
1811
r.in.values_in[0].ve_valuename = talloc(tctx, struct winreg_ValNameBuf);
1812
r.in.values_in[0].ve_valuename->name = valuename;
1813
/* size needs to be set manually for winreg_ValNameBuf */
1814
r.in.values_in[0].ve_valuename->size = strlen_m_term(valuename)*2;
1816
r.in.num_values = 1;
1817
r.in.offered = &offered;
1818
r.out.needed = &needed;
1820
torture_assert_ntstatus_ok(tctx,
1821
dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1822
"QueryMultipleValues2 failed");
1823
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1824
*r.in.offered = *r.out.needed;
1825
r.in.buffer = r.out.buffer = talloc_zero_array(tctx, uint8_t, *r.in.offered);
1827
torture_assert_ntstatus_ok(tctx,
1828
dcerpc_winreg_QueryMultipleValues2_r(b, tctx, &r),
1829
"QueryMultipleValues2 failed");
1832
torture_assert_werr_ok(tctx, r.out.result,
1833
"QueryMultipleValues2 failed");
1838
static bool test_QueryValue(struct dcerpc_binding_handle *b,
1529
1839
struct torture_context *tctx,
1530
1840
struct policy_handle *handle,
1531
1841
const char *valuename)
1689
2121
if (!test_EnumKey(p, tctx, handle, depth, test_security)) {
1692
if (!test_EnumValue(p, tctx, handle, 0xFF, 0xFFFF)) {
1695
test_CloseKey(p, tctx, handle);
1700
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
1702
static bool test_Open_Security(struct torture_context *tctx,
1703
struct dcerpc_pipe *p, void *userdata)
1705
struct policy_handle handle, newhandle;
1706
bool ret = true, created2 = false;
1707
bool created4 = false;
2124
if (!test_EnumValue(b, tctx, handle, max_valnamelen, max_valbufsize)) {
2127
if (!test_EnumValue(b, tctx, handle, max_valnamelen, 0xFFFF)) {
2130
test_CloseKey(b, tctx, handle);
2135
static bool test_SetValue_simple(struct dcerpc_binding_handle *b,
2136
struct torture_context *tctx,
2137
struct policy_handle *handle)
2139
const char *value_name = TEST_VALUE;
2140
uint32_t value = 0x12345678;
2141
uint64_t value2 = 0x12345678;
2142
const char *string = "torture";
2143
const char *array[2];
2145
enum winreg_Type types[] = {
2147
REG_DWORD_BIG_ENDIAN,
2155
array[0] = "array0";
2158
torture_comment(tctx, "Testing SetValue (standard formats)\n");
2160
for (t=0; t < ARRAY_SIZE(types); t++) {
2162
enum winreg_Type w_type;
2163
uint32_t w_size, w_length;
2168
case REG_DWORD_BIG_ENDIAN:
2169
blob = data_blob_talloc_zero(tctx, 4);
2170
SIVAL(blob.data, 0, value);
2173
blob = data_blob_talloc_zero(tctx, 8);
2174
SBVAL(blob.data, 0, value2);
2177
blob = data_blob_string_const("binary_blob");
2180
torture_assert(tctx, push_reg_sz(tctx, &blob, string), "failed to push REG_SZ");
2183
torture_assert(tctx, push_reg_multi_sz(tctx, &blob, array), "failed to push REG_MULTI_SZ");
2189
torture_assert(tctx,
2190
test_SetValue(b, tctx, handle, value_name, types[t], blob.data, blob.length),
2191
"test_SetValue failed");
2192
torture_assert(tctx,
2193
test_QueryValue_full(b, tctx, handle, value_name, true),
2194
talloc_asprintf(tctx, "test_QueryValue_full for %s value failed", value_name));
2195
torture_assert(tctx,
2196
test_winreg_QueryValue(tctx, b, handle, value_name, &w_type, &w_size, &w_length, &w_data),
2197
"test_winreg_QueryValue failed");
2198
torture_assert(tctx,
2199
test_DeleteValue(b, tctx, handle, value_name),
2200
"test_DeleteValue failed");
2202
torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
2203
torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
2204
torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
2205
torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
2208
torture_comment(tctx, "Testing SetValue (standard formats) succeeded\n");
2213
static bool test_SetValue_values(struct dcerpc_binding_handle *b,
2214
struct torture_context *tctx,
2215
struct policy_handle *handle)
2218
const char *values[] = {
2225
"torture_value_name",
2226
"torture value name",
2227
"torture,value,name",
2228
"torture;value;name",
2229
"torture/value/name",
2230
"torture\\value\\name",
2234
torture_comment(tctx, "Testing SetValue (values)\n");
2236
for (i=0; i < ARRAY_SIZE(values); i++) {
2238
enum winreg_Type w_type;
2239
uint32_t w_size, w_length;
2242
blob = data_blob_talloc(tctx, NULL, 32);
2244
generate_random_buffer(blob.data, 32);
2246
torture_assert(tctx,
2247
test_SetValue(b, tctx, handle, values[i], REG_BINARY, blob.data, blob.length),
2248
"test_SetValue failed");
2249
torture_assert(tctx,
2250
test_QueryValue_full(b, tctx, handle, values[i], true),
2251
talloc_asprintf(tctx, "test_QueryValue_full for %s value failed", values[i]));
2252
torture_assert(tctx,
2253
test_winreg_QueryValue(tctx, b, handle, values[i], &w_type, &w_size, &w_length, &w_data),
2254
"test_winreg_QueryValue failed");
2255
torture_assert(tctx,
2256
test_DeleteValue(b, tctx, handle, values[i]),
2257
"test_DeleteValue failed");
2259
torture_assert_int_equal(tctx, w_type, REG_BINARY, "winreg type mismatch");
2260
torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
2261
torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
2262
torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
2265
torture_comment(tctx, "Testing SetValue (values) succeeded\n");
2270
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
2272
static bool test_SetValue_extended(struct dcerpc_binding_handle *b,
2273
struct torture_context *tctx,
2274
struct policy_handle *handle)
2276
const char *value_name = TEST_VALUE;
2277
enum winreg_Type types[] = {
2283
REG_DWORD_BIG_ENDIAN,
2287
REG_FULL_RESOURCE_DESCRIPTOR,
2288
REG_RESOURCE_REQUIREMENTS_LIST,
2300
if (torture_setting_bool(tctx, "samba4", false)) {
2301
torture_skip(tctx, "skipping extended SetValue test against Samba4");
2304
torture_comment(tctx, "Testing SetValue (extended formats)\n");
2306
for (t=0; t < ARRAY_SIZE(types); t++) {
2307
for (l=0; l < 16; l++) {
2309
enum winreg_Type w_type;
2310
uint32_t w_size, w_length;
2317
data = talloc_array(tctx, uint8_t, size);
2319
generate_random_buffer(data, size);
2321
torture_assert(tctx,
2322
test_SetValue(b, tctx, handle, value_name, types[t], data, size),
2323
"test_SetValue failed");
2325
torture_assert(tctx,
2326
test_winreg_QueryValue(tctx, b, handle, value_name, &w_type, &w_size, &w_length, &w_data),
2327
"test_winreg_QueryValue failed");
2329
torture_assert(tctx,
2330
test_DeleteValue(b, tctx, handle, value_name),
2331
"test_DeleteValue failed");
2333
torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
2334
torture_assert_int_equal(tctx, w_size, size, "winreg size mismatch");
2335
torture_assert_int_equal(tctx, w_length, size, "winreg length mismatch");
2336
torture_assert_mem_equal(tctx, w_data, data, size, "winreg buffer mismatch");
2340
torture_comment(tctx, "Testing SetValue (extended formats) succeeded\n");
2345
static bool test_create_keynames(struct dcerpc_binding_handle *b,
2346
struct torture_context *tctx,
2347
struct policy_handle *handle)
2349
const char *keys[] = {
2358
for (i=0; i < ARRAY_SIZE(keys); i++) {
2360
enum winreg_CreateAction action_taken;
2361
struct policy_handle new_handle;
2364
torture_assert(tctx,
2365
test_CreateKey_opts(tctx, b, handle, keys[i], NULL,
2366
REG_OPTION_NON_VOLATILE,
2367
SEC_FLAG_MAXIMUM_ALLOWED,
2372
talloc_asprintf(tctx, "failed to create '%s' key", keys[i]));
2374
torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2376
torture_assert(tctx,
2377
test_DeleteKey_opts(b, tctx, handle, keys[i], WERR_OK),
2378
"failed to delete key");
2380
torture_assert(tctx,
2381
test_DeleteKey_opts(b, tctx, handle, keys[i], WERR_BADFILE),
2382
"failed 2nd delete key");
2384
tmp = talloc_strdup(tctx, keys[i]);
2386
q = strchr(tmp, '\\');
2391
torture_assert(tctx,
2392
test_DeleteKey_opts(b, tctx, handle, tmp, WERR_OK),
2393
"failed to delete key");
2395
torture_assert(tctx,
2396
test_DeleteKey_opts(b, tctx, handle, tmp, WERR_BADFILE),
2397
"failed 2nd delete key");
2404
#define KEY_CURRENT_VERSION "SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION"
2405
#define VALUE_CURRENT_VERSION "CurrentVersion"
2406
#define VALUE_SYSTEM_ROOT "SystemRoot"
2408
static const struct {
2409
const char *values[3];
2410
uint32_t num_values;
2411
bool existing_value;
2412
const char *error_message;
2413
} multiple_values_tests[] = {
2415
.values = { VALUE_CURRENT_VERSION, NULL, NULL },
2417
.existing_value = true,
2418
.error_message = NULL
2420
.values = { VALUE_SYSTEM_ROOT, NULL, NULL },
2422
.existing_value = true,
2423
.error_message = NULL
2425
.values = { VALUE_CURRENT_VERSION, VALUE_SYSTEM_ROOT, NULL },
2427
.existing_value = true,
2428
.error_message = NULL
2430
.values = { VALUE_CURRENT_VERSION, VALUE_SYSTEM_ROOT,
2431
VALUE_CURRENT_VERSION },
2433
.existing_value = true,
2434
.error_message = NULL
2436
.values = { VALUE_CURRENT_VERSION, NULL, VALUE_SYSTEM_ROOT },
2438
.existing_value = false,
2439
.error_message = NULL
2441
.values = { VALUE_CURRENT_VERSION, "", VALUE_SYSTEM_ROOT },
2443
.existing_value = false,
2444
.error_message = NULL
2446
.values = { "IDoNotExist", NULL, NULL },
2448
.existing_value = false,
2449
.error_message = NULL
2451
.values = { "IDoNotExist", VALUE_CURRENT_VERSION, NULL },
2453
.existing_value = false,
2454
.error_message = NULL
2456
.values = { VALUE_CURRENT_VERSION, "IDoNotExist", NULL },
2458
.existing_value = false,
2459
.error_message = NULL
2463
static bool test_HKLM_wellknown(struct torture_context *tctx,
2464
struct dcerpc_binding_handle *b,
2465
struct policy_handle *handle)
2467
struct policy_handle newhandle;
2470
/* FIXME: s3 does not support SEC_FLAG_MAXIMUM_ALLOWED yet */
2471
if (torture_setting_bool(tctx, "samba3", false)) {
2472
torture_assert(tctx, test_OpenKey_opts(tctx, b, handle,
2473
KEY_CURRENT_VERSION,
2474
REG_OPTION_NON_VOLATILE,
2478
"failed to open current version key");
2480
torture_assert(tctx, test_OpenKey(b, tctx, handle, KEY_CURRENT_VERSION, &newhandle),
2481
"failed to open current version key");
2484
torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, VALUE_CURRENT_VERSION, true),
2485
"failed to query current version");
2486
torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, "IDoNotExist", false),
2487
"succeeded to query nonexistent value");
2488
torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, NULL, false),
2489
"succeeded to query value with NULL name");
2490
torture_assert(tctx, test_QueryValue_full(b, tctx, &newhandle, "", false),
2491
"succeeded to query nonexistent default value (\"\")");
2493
if (torture_setting_bool(tctx, "samba4", false)) {
2494
torture_comment(tctx, "skipping QueryMultipleValues{2} tests against Samba4\n");
2498
for (i=0; i < ARRAY_SIZE(multiple_values_tests); i++) {
2500
msg = talloc_asprintf(tctx,
2501
"failed to query %d %sexisting values\n",
2502
multiple_values_tests[i].num_values,
2503
multiple_values_tests[i].existing_value ? "":"non");
2505
torture_assert(tctx,
2506
test_QueryMultipleValues_full(b, tctx, &newhandle,
2507
multiple_values_tests[i].num_values,
2508
multiple_values_tests[i].values,
2509
multiple_values_tests[i].existing_value),
2511
torture_assert(tctx,
2512
test_QueryMultipleValues2_full(b, tctx, &newhandle,
2513
multiple_values_tests[i].num_values,
2514
multiple_values_tests[i].values,
2515
multiple_values_tests[i].existing_value),
2520
torture_assert(tctx, test_CloseKey(b, tctx, &newhandle),
2521
"failed to close current version key");
2526
static bool test_OpenHive(struct torture_context *tctx,
2527
struct dcerpc_binding_handle *b,
2528
struct policy_handle *handle,
1708
2531
struct winreg_OpenHKLM r;
1710
winreg_open_fn open_fn = userdata;
1713
2533
r.in.system_name = 0;
1714
2534
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1715
r.out.handle = &handle;
1717
torture_assert_ntstatus_ok(tctx, open_fn(p, tctx, &r),
1720
test_Cleanup(p, tctx, &handle, TEST_KEY_BASE);
1722
if (!test_CreateKey(p, tctx, &handle, TEST_KEY_BASE, NULL)) {
1723
torture_comment(tctx,
1724
"CreateKey (TEST_KEY_BASE) failed\n");
1727
if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY2,
2535
r.out.handle = handle;
2538
case HKEY_LOCAL_MACHINE:
2539
torture_assert_ntstatus_ok(tctx,
2540
dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
2541
"failed to open HKLM");
2542
torture_assert_werr_ok(tctx, r.out.result,
2543
"failed to open HKLM");
2545
case HKEY_CURRENT_USER:
2546
torture_assert_ntstatus_ok(tctx,
2547
dcerpc_winreg_OpenHKCU_r(b, tctx, (struct winreg_OpenHKCU *)(void *)&r),
2548
"failed to open HKCU");
2549
torture_assert_werr_ok(tctx, r.out.result,
2550
"failed to open HKCU");
2553
torture_assert_ntstatus_ok(tctx,
2554
dcerpc_winreg_OpenHKU_r(b, tctx, (struct winreg_OpenHKU *)(void *)&r),
2555
"failed to open HKU");
2556
torture_assert_werr_ok(tctx, r.out.result,
2557
"failed to open HKU");
2559
case HKEY_CLASSES_ROOT:
2560
torture_assert_ntstatus_ok(tctx,
2561
dcerpc_winreg_OpenHKCR_r(b, tctx, (struct winreg_OpenHKCR *)(void *)&r),
2562
"failed to open HKCR");
2563
torture_assert_werr_ok(tctx, r.out.result,
2564
"failed to open HKCR");
2567
torture_warning(tctx, "unsupported hkey: 0x%08x\n", hkey);
2574
static bool test_volatile_keys(struct torture_context *tctx,
2575
struct dcerpc_binding_handle *b,
2576
struct policy_handle *handle,
2579
struct policy_handle new_handle, hive_handle;
2580
enum winreg_CreateAction action_taken;
2582
torture_comment(tctx, "Testing VOLATILE key\n");
2584
test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE);
2586
torture_assert(tctx,
2587
test_CreateKey_opts(tctx, b, handle, TEST_KEY_VOLATILE, NULL,
2588
REG_OPTION_VOLATILE,
2589
SEC_FLAG_MAXIMUM_ALLOWED,
2594
"failed to create REG_OPTION_VOLATILE type key");
2596
torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2598
torture_assert(tctx,
2599
test_CreateKey_opts(tctx, b, &new_handle, TEST_SUBKEY_VOLATILE, NULL,
2600
REG_OPTION_NON_VOLATILE,
2601
SEC_FLAG_MAXIMUM_ALLOWED,
2603
WERR_CHILD_MUST_BE_VOLATILE,
2606
"failed to fail create REG_OPTION_VOLATILE type key");
2608
torture_assert(tctx,
2609
test_CloseKey(b, tctx, &new_handle),
2612
torture_assert(tctx,
2613
test_OpenKey_opts(tctx, b, handle, TEST_KEY_VOLATILE,
2614
REG_OPTION_NON_VOLATILE,
2615
SEC_FLAG_MAXIMUM_ALLOWED,
2618
"failed to open volatile key");
2620
torture_assert(tctx,
2621
test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE),
2622
"failed to delete key");
2624
torture_assert(tctx,
2625
test_CreateKey_opts(tctx, b, handle, TEST_KEY_VOLATILE, NULL,
2626
REG_OPTION_VOLATILE,
2627
SEC_FLAG_MAXIMUM_ALLOWED,
2632
"failed to create REG_OPTION_VOLATILE type key");
2634
torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2636
torture_assert(tctx,
2637
test_CloseKey(b, tctx, &new_handle),
2640
torture_assert(tctx,
2641
test_OpenKey_opts(tctx, b, handle, TEST_KEY_VOLATILE,
2642
REG_OPTION_VOLATILE,
2643
SEC_FLAG_MAXIMUM_ALLOWED,
2646
"failed to open volatile key");
2648
torture_assert(tctx,
2649
test_CloseKey(b, tctx, &new_handle),
2652
torture_assert(tctx,
2653
test_OpenHive(tctx, b, &hive_handle, hkey),
2654
"failed top open hive");
2656
torture_assert(tctx,
2657
test_OpenKey_opts(tctx, b, &hive_handle, TEST_KEY_VOLATILE,
2658
REG_OPTION_VOLATILE,
2659
SEC_FLAG_MAXIMUM_ALLOWED,
2662
"failed to open volatile key");
2664
torture_assert(tctx,
2665
test_OpenKey_opts(tctx, b, &hive_handle, TEST_KEY_VOLATILE,
2666
REG_OPTION_NON_VOLATILE,
2667
SEC_FLAG_MAXIMUM_ALLOWED,
2670
"failed to open volatile key");
2672
torture_assert(tctx,
2673
test_CloseKey(b, tctx, &hive_handle),
2676
torture_assert(tctx,
2677
test_DeleteKey(b, tctx, handle, TEST_KEY_VOLATILE),
2678
"failed to delete key");
2681
torture_comment(tctx, "Testing VOLATILE key succeeded\n");
2686
static const char *kernel_mode_registry_path(struct torture_context *tctx,
2688
const char *sid_string,
2692
case HKEY_LOCAL_MACHINE:
2693
return talloc_asprintf(tctx, "\\Registry\\MACHINE\\%s", path);
2694
case HKEY_CURRENT_USER:
2695
return talloc_asprintf(tctx, "\\Registry\\USER\\%s\\%s", sid_string, path);
2697
return talloc_asprintf(tctx, "\\Registry\\USER\\%s", path);
2698
case HKEY_CLASSES_ROOT:
2699
return talloc_asprintf(tctx, "\\Registry\\MACHINE\\Software\\Classes\\%s", path);
2701
torture_warning(tctx, "unsupported hkey: 0x%08x\n", hkey);
2706
static bool test_symlink_keys(struct torture_context *tctx,
2707
struct dcerpc_binding_handle *b,
2708
struct policy_handle *handle,
2712
struct policy_handle new_handle;
2713
enum winreg_CreateAction action_taken;
2715
uint32_t value = 42;
2716
const char *test_key_symlink_dest;
2717
const char *test_key_symlink;
2718
const char *kernel_mode_path;
2720
/* disable until we know how to delete a symbolic link */
2721
torture_skip(tctx, "symlink test disabled");
2723
torture_comment(tctx, "Testing REG_OPTION_CREATE_LINK key\n");
2725
/* create destination key with testvalue */
2726
test_key_symlink = talloc_asprintf(tctx, "%s\\%s",
2727
key, TEST_KEY_SYMLINK);
2728
test_key_symlink_dest = talloc_asprintf(tctx, "%s\\%s",
2729
key, TEST_KEY_SYMLINK_DEST);
2731
test_DeleteKey(b, tctx, handle, test_key_symlink);
2733
torture_assert(tctx,
2734
test_CreateKey_opts(tctx, b, handle, test_key_symlink_dest, NULL,
2736
SEC_FLAG_MAXIMUM_ALLOWED,
2741
"failed to create symlink destination");
2743
blob = data_blob_talloc_zero(tctx, 4);
2744
SIVAL(blob.data, 0, value);
2746
torture_assert(tctx,
2747
test_SetValue(b, tctx, &new_handle, "TestValue", REG_DWORD, blob.data, blob.length),
2748
"failed to create TestValue");
2750
torture_assert(tctx,
2751
test_CloseKey(b, tctx, &new_handle),
2754
/* create symlink */
2756
torture_assert(tctx,
2757
test_CreateKey_opts(tctx, b, handle, test_key_symlink, NULL,
2758
REG_OPTION_CREATE_LINK | REG_OPTION_VOLATILE,
2759
SEC_FLAG_MAXIMUM_ALLOWED,
2764
"failed to create REG_OPTION_CREATE_LINK type key");
2766
torture_assert_int_equal(tctx, action_taken, REG_CREATED_NEW_KEY, "unexpected action");
2768
kernel_mode_path = kernel_mode_registry_path(tctx, hkey, NULL, test_key_symlink_dest);
2770
torture_assert(tctx,
2771
convert_string_talloc(tctx, CH_UNIX, CH_UTF16,
2773
strlen(kernel_mode_path), /* not NULL terminated */
2774
&blob.data, &blob.length,
2776
"failed to convert");
2778
torture_assert(tctx,
2779
test_SetValue(b, tctx, &new_handle, "SymbolicLinkValue", REG_LINK, blob.data, blob.length),
2780
"failed to create SymbolicLinkValue value");
2782
torture_assert(tctx,
2783
test_CloseKey(b, tctx, &new_handle),
2786
/* test follow symlink */
2788
torture_assert(tctx,
2789
test_OpenKey_opts(tctx, b, handle, test_key_symlink,
2791
SEC_FLAG_MAXIMUM_ALLOWED,
2794
"failed to follow symlink key");
2796
torture_assert(tctx,
2797
test_QueryValue(b, tctx, &new_handle, "TestValue"),
2798
"failed to query value");
2800
torture_assert(tctx,
2801
test_CloseKey(b, tctx, &new_handle),
2806
torture_assert(tctx,
2807
test_OpenKey_opts(tctx, b, handle, test_key_symlink,
2808
REG_OPTION_OPEN_LINK | REG_OPTION_VOLATILE,
2809
SEC_FLAG_MAXIMUM_ALLOWED,
2812
"failed to open symlink key");
2814
torture_assert(tctx,
2815
test_DeleteValue(b, tctx, &new_handle, "SymbolicLinkValue"),
2816
"failed to delete value SymbolicLinkValue");
2818
torture_assert(tctx,
2819
test_CloseKey(b, tctx, &new_handle),
2822
torture_assert(tctx,
2823
test_DeleteKey(b, tctx, handle, test_key_symlink),
2824
"failed to delete key");
2826
/* delete destination */
2828
torture_assert(tctx,
2829
test_DeleteKey(b, tctx, handle, test_key_symlink_dest),
2830
"failed to delete key");
2835
static bool test_CreateKey_keytypes(struct torture_context *tctx,
2836
struct dcerpc_binding_handle *b,
2837
struct policy_handle *handle,
2842
if (torture_setting_bool(tctx, "samba3", false) ||
2843
torture_setting_bool(tctx, "samba4", false)) {
2844
torture_skip(tctx, "skipping CreateKey keytypes test against Samba");
2847
torture_assert(tctx,
2848
test_volatile_keys(tctx, b, handle, hkey),
2849
"failed to test volatile keys");
2851
torture_assert(tctx,
2852
test_symlink_keys(tctx, b, handle, key, hkey),
2853
"failed to test symlink keys");
2858
static bool test_key_base(struct torture_context *tctx,
2859
struct dcerpc_binding_handle *b,
2860
struct policy_handle *handle,
2861
const char *base_key,
2864
struct policy_handle newhandle;
2865
bool ret = true, created = false, deleted = false;
2866
bool created3 = false;
2867
const char *test_key1;
2868
const char *test_key3;
2869
const char *test_subkey;
2871
test_Cleanup(b, tctx, handle, base_key);
2873
if (!test_CreateKey(b, tctx, handle, base_key, NULL)) {
2874
torture_comment(tctx,
2875
"CreateKey(%s) failed\n", base_key);
2878
test_key1 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY1);
2880
if (!test_CreateKey(b, tctx, handle, test_key1, NULL)) {
2881
torture_comment(tctx,
2882
"CreateKey failed - not considering a failure\n");
2888
if (!test_FlushKey(b, tctx, handle)) {
2889
torture_comment(tctx, "FlushKey failed\n");
2893
if (!test_OpenKey(b, tctx, handle, test_key1, &newhandle)) {
2895
"CreateKey failed (OpenKey after Create didn't work)\n");
2898
if (hkey == HKEY_CURRENT_USER) {
2899
torture_assert(tctx, test_SetValue_simple(b, tctx, &newhandle),
2900
"simple SetValue test failed");
2901
torture_assert(tctx, test_SetValue_values(b, tctx, &newhandle),
2902
"values SetValue test failed");
2903
torture_assert(tctx, test_SetValue_extended(b, tctx, &newhandle),
2904
"extended SetValue test failed");
2905
torture_assert(tctx, test_create_keynames(b, tctx, &newhandle),
2906
"keyname CreateKey test failed");
2908
torture_assert(tctx, test_CreateKey_keytypes(tctx, b, &newhandle, test_key1, hkey),
2909
"keytype test failed");
2912
if (!test_CloseKey(b, tctx, &newhandle)) {
2914
"CreateKey failed (CloseKey after Open didn't work)\n");
2917
if (!test_DeleteKey(b, tctx, handle, test_key1)) {
2918
torture_comment(tctx, "DeleteKey(%s) failed\n",
2925
if (!test_FlushKey(b, tctx, handle)) {
2926
torture_comment(tctx, "FlushKey failed\n");
2931
if (!test_OpenKey_opts(tctx, b, handle, test_key1,
2932
REG_OPTION_NON_VOLATILE,
2933
SEC_FLAG_MAXIMUM_ALLOWED,
2936
torture_comment(tctx,
2937
"DeleteKey failed (OpenKey after Delete "
2938
"did not return WERR_BADFILE)\n");
2943
test_key3 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY3);
2945
if (test_CreateKey(b, tctx, handle, test_key3, NULL)) {
2949
test_subkey = talloc_asprintf(tctx, "%s\\%s", test_key3, TEST_SUBKEY);
2952
if (test_CreateKey(b, tctx, handle, test_subkey, NULL)) {
2953
if (!test_DeleteKey(b, tctx, handle, test_subkey)) {
2954
torture_comment(tctx, "DeleteKey(%s) failed\n", test_subkey);
2959
if (!test_DeleteKey(b, tctx, handle, test_key3)) {
2960
torture_comment(tctx, "DeleteKey(%s) failed\n", test_key3);
2966
test_Cleanup(b, tctx, handle, base_key);
2971
static bool test_key_base_sd(struct torture_context *tctx,
2972
struct dcerpc_pipe *p,
2973
struct policy_handle *handle,
2974
const char *base_key)
2976
struct policy_handle newhandle;
2977
bool ret = true, created2 = false, created4 = false;
2978
struct dcerpc_binding_handle *b = p->binding_handle;
2979
const char *test_key2;
2980
const char *test_key4;
2982
torture_skip(tctx, "security descriptor test disabled\n");
2984
if (torture_setting_bool(tctx, "samba3", false) ||
2985
torture_setting_bool(tctx, "samba4", false)) {
2986
torture_skip(tctx, "skipping security descriptor tests against Samba");
2989
test_Cleanup(b, tctx, handle, base_key);
2991
if (!test_CreateKey(b, tctx, handle, base_key, NULL)) {
2992
torture_comment(tctx,
2993
"CreateKey(%s) failed\n", base_key);
2996
test_key2 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY2);
2998
if (test_CreateKey_sd(b, tctx, handle, test_key2,
1728
2999
NULL, &newhandle)) {
1729
3000
created2 = true;
1732
if (created2 && !test_CloseKey(p, tctx, &newhandle)) {
1733
printf("CloseKey failed\n");
3003
if (created2 && !test_CloseKey(b, tctx, &newhandle)) {
3004
torture_comment(tctx, "CloseKey failed\n");
1737
if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY4, NULL, &newhandle)) {
3008
test_key4 = talloc_asprintf(tctx, "%s\\%s", base_key, TEST_KEY4);
3010
if (test_CreateKey_sd(b, tctx, handle, test_key4, NULL, &newhandle)) {
1738
3011
created4 = true;
1741
if (created4 && !test_CloseKey(p, tctx, &newhandle)) {
1742
printf("CloseKey failed\n");
1746
if (created4 && !test_SecurityDescriptors(p, tctx, &handle, TEST_KEY4)) {
1750
if (created4 && !test_DeleteKey(p, tctx, &handle, TEST_KEY4)) {
1751
printf("DeleteKey failed\n");
1755
if (created2 && !test_DeleteKey(p, tctx, &handle, TEST_KEY2)) {
1756
printf("DeleteKey failed\n");
1760
/* The HKCR hive has a very large fanout */
1761
if (open_fn == (void *)dcerpc_winreg_OpenHKCR) {
1762
if(!test_key(p, tctx, &handle, MAX_DEPTH - 1, true)) {
1766
if (!test_key(p, tctx, &handle, 0, true)) {
1771
test_Cleanup(p, tctx, &handle, TEST_KEY_BASE);
3014
if (created4 && !test_CloseKey(b, tctx, &newhandle)) {
3015
torture_comment(tctx, "CloseKey failed\n");
3019
if (created4 && !test_SecurityDescriptors(p, tctx, handle, test_key4)) {
3023
if (created4 && !test_DeleteKey(b, tctx, handle, test_key4)) {
3024
torture_comment(tctx, "DeleteKey(%s) failed\n", test_key4);
3028
if (created2 && !test_DeleteKey(b, tctx, handle, test_key4)) {
3029
torture_comment(tctx, "DeleteKey(%s) failed\n", test_key4);
3033
test_Cleanup(b, tctx, handle, base_key);