r4138: initialise 'type' in RPC-WINREG EnumValue test
[samba.git] / source4 / torture / rpc / winreg.c
index 42326b1468eaa838b4f3b40fb26a69b8c8433f07..8f3e543fb59bd3b6c0c2a5cbe29ee4adf9decb34 100644 (file)
@@ -3,6 +3,7 @@
    test suite for winreg rpc operations
 
    Copyright (C) Tim Potter 2003
+   Copyright (C) Jelmer Vernooij 2004
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,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)
 {
@@ -50,17 +52,22 @@ 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;
        NTSTATUS status;
-       struct sec_desc_buf sec_desc;
-       uint32 sec_info = 0;
+       uint32_t sec_info = 0;
 
        printf("\ntesting CreateKey\n");
 
@@ -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,64 +260,106 @@ 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_EnumValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
-                          struct policy_handle *handle)
+static BOOL test_QueryValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *valuename)
 {
-       struct winreg_EnumValue r;
-       struct winreg_Uint8buf value;
-       struct winreg_String name;
-       uint32 type, requested_len, returned_len;
+       struct winreg_QueryValue r;
        NTSTATUS status;
+       uint32 zero = 0;
+       uint32 offered = 0xfff;
+
+       printf("Testing QueryValue\n");
 
        r.in.handle = handle;
-       r.in.enum_index = 0;
+       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;
+       }
 
-       init_winreg_String(&name, NULL);
-       r.in.name = r.out.name = &name;
-       
-       type = 0;
-       r.in.type = &type;
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("QueryValue failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
 
-       value.max_len = 0xffff;
-       value.offset = 0;
-       value.len = 0;
-       value.buffer = NULL;
+       return True;
+}
 
-       r.in.value = &value;
+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;
+       uint32 type = 0;
+       uint32 size = max_valbufsize, zero = 0;
+       BOOL ret = True;
+       uint8_t buf8;
+       uint16_t buf16;
 
-       requested_len = value.max_len;
-       r.in.requested_len = &requested_len;
-       returned_len = 0;
-       r.in.returned_len = &returned_len;
+       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 {
+               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);
+               }
 
-               status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
                r.in.enum_index++;
        } while (W_ERROR_IS_OK(r.out.result));
-                       
-       return True;
+
+       if(!W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
+               printf("EnumValue failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
+       return ret;
 }
 
 static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
@@ -313,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);
@@ -323,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;
 }
 
@@ -339,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);
@@ -365,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);
@@ -379,11 +446,12 @@ static BOOL test_OpenHKCR(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 }
 
 static BOOL test_InitiateSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
-                       const char *msg, uint32 timeout)
+                       const char *msg, uint32_t timeout)
 {
        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;
@@ -407,7 +475,7 @@ static BOOL test_AbortSystemShutdown(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
 {
        struct winreg_AbortSystemShutdown r;
        NTSTATUS status;
-       uint16 server = 0x0;
+       uint16_t server = 0x0;
 
        r.in.server = &server;
        
@@ -439,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);
@@ -466,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)) {
+       if (!test_EnumValue(p, mem_ctx, handle, 0xFF, 0xFFFF)) {
        }
 
-       /* Enumerate values */
-
        test_CloseKey(p, mem_ctx, handle);
 
        return True;
@@ -485,14 +551,20 @@ 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");
                ret = False;
        }
 
+       if (!test_FlushKey(p, mem_ctx, &handle)) {
+               printf("FlushKey failed\n");
+               ret = False;
+       }
+
        if (!test_OpenKey(p, mem_ctx, &handle, "spottyfoot", &newhandle)) {
                printf("CreateKey failed (OpenKey after Create didn't work)\n");
                ret = False;
@@ -503,6 +575,11 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
                ret = False;
        }
 
+       if (!test_FlushKey(p, mem_ctx, &handle)) {
+               printf("FlushKey failed\n");
+               ret = False;
+       }
+
        if (test_OpenKey(p, mem_ctx, &handle, "spottyfoot", &newhandle)) {
                printf("DeleteKey failed (OpenKey after Delete didn't work)\n");
                ret = False;
@@ -513,12 +590,6 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
                ret = False;
        }
 
-       if (!test_FlushKey(p, mem_ctx, &handle)) {
-               printf("FlushKey failed\n");
-               ret = False;
-       }
-
-
        /* The HKCR hive has a very large fanout */
 
        if (open_fn == test_OpenHKCR) {
@@ -534,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;