Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-test
authorAndrew Tridgell <tridge@samba.org>
Thu, 17 Apr 2008 14:53:36 +0000 (16:53 +0200)
committerAndrew Tridgell <tridge@samba.org>
Thu, 17 Apr 2008 14:53:36 +0000 (16:53 +0200)
source/lib/registry/tests/hive.c
source/lib/registry/tests/registry.c
source/librpc/idl/nbt.idl
source/librpc/idl/security.idl
source/librpc/ndr/libndr.h
source/librpc/ndr/ndr_sec_helper.c

index 83abdd793d668ae97575134f03d473e49db9d21e..29f7e685c102faadf0e15cdedcfa5b8269d7d540 100644 (file)
@@ -68,14 +68,15 @@ static bool test_keyinfo_nums(struct torture_context *tctx, void *test_data)
        struct hive_key *root = (struct hive_key *)test_data;
        WERROR error;
        struct hive_key *subkey;
-       uint32_t data = 42;
+       char data[4];
+       SIVAL(data, 0, 42);
 
        error = hive_key_add_name(tctx, root, "Nested Keyll", NULL,
                                  NULL, &subkey);
        torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
        error = hive_key_set_value(root, "Answer", REG_DWORD,
-                              data_blob_talloc(tctx, &data, sizeof(data)));
+                              data_blob_talloc(tctx, data, sizeof(data)));
        torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
        /* This is a new backend. There should be no subkeys and no
@@ -119,7 +120,8 @@ static bool test_del_recursive(struct torture_context *tctx,
        struct hive_key *subkey2;
        const struct hive_key *root = (const struct hive_key *)test_data;
        TALLOC_CTX *mem_ctx = tctx;
-       uint32_t data = 42;
+       char data[4];
+       SIVAL(data, 0, 42);
 
        /* Create a new key under the root */
        error = hive_key_add_name(mem_ctx, root, "Parent Key", NULL,
@@ -133,7 +135,7 @@ static bool test_del_recursive(struct torture_context *tctx,
 
        /* Create a new value under "Child Key" */
        error = hive_key_set_value(subkey2, "Answer Recursive", REG_DWORD,
-                              data_blob_talloc(mem_ctx, &data, sizeof(data)));
+                              data_blob_talloc(mem_ctx, data, sizeof(data)));
        torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
        /* Deleting "Parent Key" will also delete "Child Key" and the value. */
@@ -179,14 +181,15 @@ static bool test_set_value(struct torture_context *tctx,
        struct hive_key *subkey;
        const struct hive_key *root = (const struct hive_key *)test_data;
        TALLOC_CTX *mem_ctx = tctx;
-       uint32_t data = 42;
+       char data[4];
+       SIVAL(data, 0, 42);
 
        error = hive_key_add_name(mem_ctx, root, "YA Nested Key", NULL,
                                  NULL, &subkey);
        torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
        error = hive_key_set_value(subkey, "Answer", REG_DWORD,
-                              data_blob_talloc(mem_ctx, &data, sizeof(data)));
+                              data_blob_talloc(mem_ctx, data, sizeof(data)));
        torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
        return true;
@@ -198,10 +201,12 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data)
        struct hive_key *subkey;
        const struct hive_key *root = (const struct hive_key *)test_data;
        TALLOC_CTX *mem_ctx = tctx;
-       uint32_t data = 42;
+       char data[4];
        uint32_t type;
        DATA_BLOB value;
 
+       SIVAL(data, 0, 42);
+
        error = hive_key_add_name(mem_ctx, root, "EYA Nested Key", NULL,
                                  NULL, &subkey);
        torture_assert_werr_ok(tctx, error, "hive_key_add_name");
@@ -211,7 +216,7 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data)
                                  "getting missing value");
 
        error = hive_key_set_value(subkey, "Answer", REG_DWORD,
-                              data_blob_talloc(mem_ctx, &data, sizeof(data)));
+                              data_blob_talloc(mem_ctx, data, sizeof(data)));
        torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
        error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value);
@@ -232,16 +237,18 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data)
        struct hive_key *subkey;
        const struct hive_key *root = (const struct hive_key *)test_data;
        TALLOC_CTX *mem_ctx = tctx;
-       uint32_t data = 42;
+       char data[4];
        uint32_t type;
        DATA_BLOB value;
 
+       SIVAL(data, 0, 42);
+
        error = hive_key_add_name(mem_ctx, root, "EEYA Nested Key", NULL,
                                                         NULL, &subkey);
        torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
        error = hive_key_set_value(subkey, "Answer", REG_DWORD,
-                              data_blob_talloc(mem_ctx, &data, sizeof(data)));
+                              data_blob_talloc(mem_ctx, data, sizeof(data)));
        torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
        error = hive_key_del_value(subkey, "Answer");
@@ -264,17 +271,19 @@ static bool test_list_values(struct torture_context *tctx,
        struct hive_key *subkey;
        const struct hive_key *root = (const struct hive_key *)test_data;
        TALLOC_CTX *mem_ctx = tctx;
-       uint32_t data = 42;
+       char data[4];
        uint32_t type;
        DATA_BLOB value;
        const char *name;
+       int data_val = 42;
+       SIVAL(data, 0, data_val);
 
        error = hive_key_add_name(mem_ctx, root, "AYAYA Nested Key", NULL,
                                  NULL, &subkey);
        torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
        error = hive_key_set_value(subkey, "Answer", REG_DWORD,
-                              data_blob_talloc(mem_ctx, &data, sizeof(data)));
+                              data_blob_talloc(mem_ctx, data, sizeof(data)));
        torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
        error = hive_get_value_by_index(mem_ctx, subkey, 0, &name,
@@ -287,7 +296,7 @@ static bool test_list_values(struct torture_context *tctx,
        torture_assert_int_equal(tctx, type, REG_DWORD, "value type");
        
        
-       torture_assert_int_equal(tctx, data, IVAL(value.data, 0), "value data");
+       torture_assert_int_equal(tctx, data_val, IVAL(value.data, 0), "value data");
 
        error = hive_get_value_by_index(mem_ctx, subkey, 1, &name,
                                        &type, &value);
index ec7873a111bb048929e150b12f169154baff248d..ac812823b2edd418368b43cb989482d94f383861 100644 (file)
@@ -281,7 +281,8 @@ static bool test_query_key_nums(struct torture_context *tctx, void *_data)
        struct registry_key *root, *subkey1, *subkey2;
        WERROR error;
        uint32_t num_subkeys, num_values;
-       uint32_t data = 42;
+       char data[4];
+       SIVAL(data, 0, 42);
 
        if (!create_test_key(tctx, rctx, "Berlin", &root, &subkey1))
                return false;
@@ -353,13 +354,15 @@ static bool test_set_value(struct torture_context *tctx, void *_data)
        struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
-       uint32_t data = 42;
+       char data[4];
+
+       SIVAL(data, 0, 42);
 
        if (!create_test_key(tctx, rctx, "Dusseldorf", &root, &subkey))
                return false;
 
        error = reg_val_set(subkey, "Answer", REG_DWORD,
-                           data_blob_talloc(tctx, &data, sizeof(data)));
+                           data_blob_talloc(tctx, data, sizeof(data)));
        torture_assert_werr_ok (tctx, error, "setting value");
 
        return true;
@@ -408,8 +411,9 @@ static bool test_get_value(struct torture_context *tctx, void *_data)
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        DATA_BLOB data;
-       uint32_t value = 42;
+       char value[4];
        uint32_t type;
+       SIVAL(value, 0, 42);
 
        if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey))
                return false;
@@ -420,7 +424,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data)
                                  "getting missing value");
 
        error = reg_val_set(subkey, __FUNCTION__, REG_DWORD,
-                           data_blob_talloc(tctx, &value, 4));
+                           data_blob_talloc(tctx, value, sizeof(value)));
        torture_assert_werr_ok(tctx, error, "setting value");
 
        error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type,
@@ -428,7 +432,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data)
        torture_assert_werr_ok(tctx, error, "getting value");
 
        torture_assert_int_equal(tctx, 4, data.length, "value length ok");
-       torture_assert_mem_equal(tctx, data.data, &value, 4,
+       torture_assert_mem_equal(tctx, data.data, value, 4,
                                    "value content ok");
        torture_assert_int_equal(tctx, REG_DWORD, type, "value type");
 
index aa8836088258342a45240273f6c9189bf5166043..dddfa4e1ce7d1a1e9f9b3fdfce8b4e5d3d127a53 100644 (file)
@@ -440,9 +440,8 @@ interface nbt
                nstring          unicode_domain;
                uint32           db_count;
                nbt_db_change    dbchange[db_count];
-               [value(ndr_size_dom_sid(&sid, ndr->flags))] uint32 sid_size;
-               [flag(NDR_ALIGN4)] DATA_BLOB _pad2;
-               dom_sid          sid;
+               [value(ndr_size_dom_sid0(&sid, ndr->flags))] uint32 sid_size;
+               [subcontext(0),subcontext_size(sid_size)] dom_sid0 sid;
                uint32           nt_version;
                uint16           lmnt_token;
                uint16           lm20_token;
@@ -560,9 +559,8 @@ interface nbt
                nstring              user_name;
                astring              mailslot_name;
                uint32               acct_control;
-               [value(ndr_size_dom_sid(&sid, ndr->flags))] uint32 sid_size;
-               [flag(NDR_ALIGN4)]   DATA_BLOB _pad;
-               dom_sid              sid;
+               [value(ndr_size_dom_sid0(&sid, ndr->flags))] uint32 sid_size;
+               [subcontext(0),subcontext_size(sid_size)] dom_sid0 sid;
                uint32               nt_version;
                uint16               lmnt_token;
                uint16               lm20_token;
index 753fad85cf96ee009877fcab00ddcc71d2f38aa9..314846c53f29b2ca00a9c8d1f082396ae5f883a1 100644 (file)
@@ -22,6 +22,9 @@ cpp_quote("#define dom_sid2 dom_sid")
 /* same struct as dom_sid but inside a 28 bytes fixed buffer in NDR */
 cpp_quote("#define dom_sid28 dom_sid")
 
+/* same struct as dom_sid but in a variable byte buffer, which is maybe empty in NDR */
+cpp_quote("#define dom_sid0 dom_sid")
+
 [
        pointer_default(unique)
 ]
index 2439c386db81fe1e3fd3796abd42c9f7afe9e39c..b719be2bab68c064347585c2e6ddcd05050bc1b7 100644 (file)
@@ -336,6 +336,10 @@ enum ndr_err_code ndr_push_dom_sid28(struct ndr_push *ndr, int ndr_flags, const
 enum ndr_err_code ndr_pull_dom_sid28(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid);
 void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid);
 size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags);
+enum ndr_err_code ndr_push_dom_sid0(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid);
+enum ndr_err_code ndr_pull_dom_sid0(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid);
+void ndr_print_dom_sid0(struct ndr_print *ndr, const char *name, const struct dom_sid *sid);
+size_t ndr_size_dom_sid0(const struct dom_sid *sid, int flags);
 void ndr_print_ipv4_addr(struct ndr_print *ndr, const char *name, const struct in_addr *_ip);
 void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid);
 enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const void *p, ndr_push_flags_fn_t fn);
index 5a0178bd25bbee897b5b8731060b0821ce5b2b6e..1256d7dd2d26769948ceaaef7ceeada42fbb351c 100644 (file)
@@ -48,6 +48,11 @@ size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags)
        return 8 + 4*sid->num_auths;
 }
 
+size_t ndr_size_dom_sid0(const struct dom_sid *sid, int flags)
+{
+       return ndr_size_dom_sid28(sid, flags);
+}
+
 /*
   return the wire size of a security_ace
 */
@@ -128,6 +133,11 @@ void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct d
        ndr_print_dom_sid(ndr, name, sid);
 }
 
+void ndr_print_dom_sid0(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
+{
+       ndr_print_dom_sid(ndr, name, sid);
+}
+
 
 /*
   parse a dom_sid2 - this is a dom_sid but with an extra copy of the num_auths field
@@ -225,3 +235,44 @@ enum ndr_err_code ndr_push_dom_sid28(struct ndr_push *ndr, int ndr_flags, const
        return NDR_ERR_SUCCESS;
 }
 
+/*
+  parse a dom_sid0 - this is a dom_sid in a variable byte buffer, which is maybe empty
+*/
+enum ndr_err_code ndr_pull_dom_sid0(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid)
+{
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NDR_ERR_SUCCESS;
+       }
+
+       if (ndr->data_size == ndr->offset) {
+               ZERO_STRUCTP(sid);
+               return NDR_ERR_SUCCESS;
+       }
+
+       return ndr_pull_dom_sid(ndr, ndr_flags, sid);
+}
+
+/*
+  push a dom_sid0 - this is a dom_sid in a variable byte buffer, which is maybe empty
+*/
+enum ndr_err_code ndr_push_dom_sid0(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid)
+{
+       struct dom_sid zero_sid;
+
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NDR_ERR_SUCCESS;
+       }
+
+       if (!sid) {
+               return NDR_ERR_SUCCESS;
+       }
+
+       ZERO_STRUCT(zero_sid);
+
+       if (memcmp(&zero_sid, sid, sizeof(zero_sid)) == 0) {
+               return NDR_ERR_SUCCESS;
+       }
+
+       return ndr_push_dom_sid(ndr, ndr_flags, sid);
+}
+