r4138: initialise 'type' in RPC-WINREG EnumValue test
[samba.git] / source4 / torture / rpc / winreg.c
index 3a1d7be68b28926db47867ebb4e5b6c30b4f6402..8f3e543fb59bd3b6c0c2a5cbe29ee4adf9decb34 100644 (file)
@@ -21,6 +21,7 @@
 */
 
 #include "includes.h"
+#include "librpc/gen_ndr/ndr_winreg.h"
 
 static void init_winreg_String(struct winreg_String *name, const char *s)
 {
@@ -51,11 +52,17 @@ static BOOL test_GetVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                return False;
        }
 
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("GetVersion failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
        return True;
 }
 
 static BOOL test_CreateKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
-                         struct policy_handle *handle, char *name, const char *class)
+                         struct policy_handle *handle, const char *name, 
+                          const char *class)
 {
        struct winreg_CreateKey r;
        struct policy_handle newhandle;
@@ -105,6 +112,11 @@ static BOOL test_CloseKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                return False;
        }
 
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("CloseKey failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
        return True;
 }
 
@@ -125,6 +137,11 @@ static BOOL test_FlushKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                return False;
        }
 
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("FlushKey failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
        return True;
 }
 
@@ -152,6 +169,7 @@ static BOOL test_OpenKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        if (!W_ERROR_IS_OK(r.out.result)) {
                printf("OpenKey failed - %s\n", win_errstr(r.out.result));
+
                return False;
        }
 
@@ -222,6 +240,8 @@ static BOOL test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        struct winreg_Time tm;
        NTSTATUS status;
 
+       printf("Testing EnumKey\n\n");
+
        r.in.handle = handle;
        r.in.enum_index = 0;
        r.in.key_name_len = r.out.key_name_len = 0;
@@ -240,23 +260,60 @@ static BOOL test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
                        struct policy_handle key_handle;
 
+                       printf("EnumKey: %d: %s\n", r.in.enum_index, r.out.out_name->name);
+
                        if (!test_OpenKey(
                                    p, mem_ctx, handle, r.out.out_name->name,
                                    &key_handle)) {
-                               printf("OpenKey(%s) failed - %s\n",
-                                      r.out.out_name->name, 
-                                      win_errstr(r.out.result));
-                               goto next_key;
+                       } else {
+                               test_key(p, mem_ctx, &key_handle, depth + 1);
                        }
-
-                       test_key(p, mem_ctx, &key_handle, depth + 1);
                }
 
-       next_key:
-
                r.in.enum_index++;
 
-       } while (W_ERROR_IS_OK(r.out.result));
+       } while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result));
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("EnumKey failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       if (!W_ERROR_IS_OK(r.out.result) && !W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
+               printf("EnumKey failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
+
+
+       return True;
+}
+
+static BOOL test_QueryValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *valuename)
+{
+       struct winreg_QueryValue r;
+       NTSTATUS status;
+       uint32 zero = 0;
+       uint32 offered = 0xfff;
+
+       printf("Testing QueryValue\n");
+
+       r.in.handle = handle;
+       r.in.value_name.name = valuename;
+       r.in.type = &zero;
+       r.in.size = &offered;
+       r.in.length = &zero;
+
+       status = dcerpc_winreg_QueryValue(p, mem_ctx, &r);
+       if(NT_STATUS_IS_ERR(status)) {
+               printf("QueryValue failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("QueryValue failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
 
        return True;
 }
@@ -265,32 +322,35 @@ static BOOL test_EnumValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                           struct policy_handle *handle, int max_valnamelen, int max_valbufsize)
 {
        struct winreg_EnumValue r;
-    struct winreg_Uint8buf vb;
-    struct winreg_EnumValueName vn;
-       uint32_t type = 0, requested_len = max_valbufsize, returned_len = 0;
-       NTSTATUS status;
+       uint32 type = 0;
+       uint32 size = max_valbufsize, zero = 0;
+       BOOL ret = True;
+       uint8_t buf8;
+       uint16_t buf16;
 
-    r.in.handle = handle;
-    r.in.enum_index = 0;
-    r.in.type = &type;
-    r.in.requested_len = &requested_len;
-    r.in.returned_len = &returned_len;
-    vn.max_len = 0;
-    vn.len = 0;
-    vn.buf = NULL;
-    r.in.name = r.out.name = &vn;
-    vb.max_len = max_valbufsize;
-    vb.offset = 0x0;
-    vb.len = 0x0;
-    vb.buffer = NULL;
-    r.in.value = &vb;
+       printf("testing EnumValue\n");
 
+       r.in.handle = handle;
+       r.in.enum_index = 0;
+       r.in.name_in.length = 0;
+       r.in.name_in.size = 0x200;
+       r.in.name_in.name = &buf16;
+       r.in.type = &type;
+       r.in.value = &buf8;
+       r.in.length = &zero;
+       r.in.size = &size;
+       
        do {
-               status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
+               NTSTATUS status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
                if(NT_STATUS_IS_ERR(status)) {
                        printf("EnumValue failed - %s\n", nt_errstr(status));
                        return False;
                }
+
+               if (W_ERROR_IS_OK(r.out.result)) {
+                       ret &= test_QueryValue(p, mem_ctx, handle, r.out.name_out.name);
+               }
+
                r.in.enum_index++;
        } while (W_ERROR_IS_OK(r.out.result));
 
@@ -298,8 +358,8 @@ static BOOL test_EnumValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                printf("EnumValue failed - %s\n", win_errstr(r.out.result));
                return False;
        }
-                       
-       return True;
+
+       return ret;
 }
 
 static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
@@ -315,7 +375,7 @@ static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        unknown.unknown0 = 0x84e0;
        unknown.unknown1 = 0x0000;
        r.in.unknown = &unknown;
-       r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
+       r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
        r.out.handle = handle;
 
        status = dcerpc_winreg_OpenHKLM(p, mem_ctx, &r);
@@ -325,6 +385,11 @@ static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                return False;
        }
 
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("OpenHKLM failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
        return ret;
 }
 
@@ -341,7 +406,7 @@ static BOOL test_OpenHKU(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        unknown.unknown0 = 0x84e0;
        unknown.unknown1 = 0x0000;
        r.in.unknown = &unknown;
-       r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
+       r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
        r.out.handle = handle;
 
        status = dcerpc_winreg_OpenHKU(p, mem_ctx, &r);
@@ -367,7 +432,7 @@ static BOOL test_OpenHKCR(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        unknown.unknown0 = 0x84e0;
        unknown.unknown1 = 0x0000;
        r.in.unknown = &unknown;
-       r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
+       r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
        r.out.handle = handle;
 
        status = dcerpc_winreg_OpenHKCR(p, mem_ctx, &r);
@@ -386,6 +451,7 @@ static BOOL test_InitiateSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_c
        struct winreg_InitiateSystemShutdown r;
        NTSTATUS status;
        
+       init_winreg_String(&r.in.hostname, NULL);
        init_winreg_String(&r.in.message, msg);
        r.in.flags = 0;
        r.in.timeout = timeout;
@@ -441,7 +507,7 @@ static BOOL test_OpenHKCU(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        unknown.unknown0 = 0x84e0;
        unknown.unknown1 = 0x0000;
        r.in.unknown = &unknown;
-       r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
+       r.in.access_required = SEC_FLAG_MAXIMUM_ALLOWED;
        r.out.handle = handle;
 
        status = dcerpc_winreg_OpenHKCU(p, mem_ctx, &r);
@@ -468,11 +534,9 @@ static BOOL test_key(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        if (!test_EnumKey(p, mem_ctx, handle, depth)) {
        }
 
-       if (!test_EnumValue(p, mem_ctx, handle, 200, 200)) {
+       if (!test_EnumValue(p, mem_ctx, handle, 0xFF, 0xFFFF)) {
        }
 
-       /* Enumerate values */
-
        test_CloseKey(p, mem_ctx, handle);
 
        return True;
@@ -487,8 +551,9 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
        BOOL ret = True;
        winreg_open_fn *open_fn = (winreg_open_fn *)fn;
 
-       if (!open_fn(p, mem_ctx, &handle))
+       if (!open_fn(p, mem_ctx, &handle)) {
                return False;
+       }
 
        if (!test_CreateKey(p, mem_ctx, &handle, "spottyfoot", NULL)) {
                printf("CreateKey failed\n");
@@ -540,7 +605,7 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
        return ret;
 }
 
-BOOL torture_rpc_winreg(int dummy)
+BOOL torture_rpc_winreg(void)
 {
         NTSTATUS status;
        struct dcerpc_pipe *p;