Author: jelmer
Date: 2007-08-04 18:15:37 +0000 (Sat, 04 Aug 2007)
New Revision: 24214

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24214

Log:
Make existing tests pass for dir hives.

Modified:
   branches/4.0-regwrite/
   branches/4.0-regwrite/source/lib/registry/dir.c
   branches/4.0-regwrite/source/lib/registry/hive.c
   branches/4.0-regwrite/source/lib/registry/hive.h
   branches/4.0-regwrite/source/lib/registry/local.c
   branches/4.0-regwrite/source/lib/registry/regf.c
   branches/4.0-regwrite/source/lib/registry/tests/hive.c


Changeset:

Property changes on: branches/4.0-regwrite
___________________________________________________________________
Name: bzr:revision-info
   - timestamp: Tue 2007-06-12 18:54:40.131000042 +0200
committer: Jelmer Vernooij <[EMAIL PROTECTED]>
properties: 
        branch-nick: 4.0-regwrite
        rebase-of: [EMAIL PROTECTED]

   + timestamp: Tue 2007-06-12 22:08:26.114000082 +0200
committer: Jelmer Vernooij <[EMAIL PROTECTED]>
properties: 
        branch-nick: 4.0-regwrite
        rebase-of: [EMAIL PROTECTED]

Name: bzr:file-ids
   - source/lib/registry/tests/hive.c   hive.c-20070612151642-hsxkm8j4r69ej3px-1

   + 
Name: bzr:revision-id:v3-trunk0
   - 11140 [EMAIL PROTECTED]
11142 [EMAIL PROTECTED]
11143 [EMAIL PROTECTED]
11144 [EMAIL PROTECTED]
11145 [EMAIL PROTECTED]
11146 [EMAIL PROTECTED]
11147 [EMAIL PROTECTED]
11148 [EMAIL PROTECTED]
11149 [EMAIL PROTECTED]
11150 [EMAIL PROTECTED]
11151 [EMAIL PROTECTED]
11152 [EMAIL PROTECTED]
11153 [EMAIL PROTECTED]
11154 [EMAIL PROTECTED]
11155 [EMAIL PROTECTED]
11156 [EMAIL PROTECTED]
11157 [EMAIL PROTECTED]
11158 [EMAIL PROTECTED]
11159 [EMAIL PROTECTED]
11160 [EMAIL PROTECTED]
11161 [EMAIL PROTECTED]
11162 [EMAIL PROTECTED]
11163 [EMAIL PROTECTED]
11164 [EMAIL PROTECTED]
11165 [EMAIL PROTECTED]
11166 [EMAIL PROTECTED]
11167 [EMAIL PROTECTED]
11168 [EMAIL PROTECTED]
11169 [EMAIL PROTECTED]
11170 [EMAIL PROTECTED]
11171 [EMAIL PROTECTED]
11172 [EMAIL PROTECTED]
11173 [EMAIL PROTECTED]
11174 [EMAIL PROTECTED]
11175 [EMAIL PROTECTED]
11176 [EMAIL PROTECTED]
11177 [EMAIL PROTECTED]
11178 [EMAIL PROTECTED]
11179 [EMAIL PROTECTED]
11180 [EMAIL PROTECTED]
11181 [EMAIL PROTECTED]
11182 [EMAIL PROTECTED]
11183 [EMAIL PROTECTED]
11184 [EMAIL PROTECTED]
11185 [EMAIL PROTECTED]
11186 [EMAIL PROTECTED]

   + 11140 [EMAIL PROTECTED]
11142 [EMAIL PROTECTED]
11143 [EMAIL PROTECTED]
11144 [EMAIL PROTECTED]
11145 [EMAIL PROTECTED]
11146 [EMAIL PROTECTED]
11147 [EMAIL PROTECTED]
11148 [EMAIL PROTECTED]
11149 [EMAIL PROTECTED]
11150 [EMAIL PROTECTED]
11151 [EMAIL PROTECTED]
11152 [EMAIL PROTECTED]
11153 [EMAIL PROTECTED]
11154 [EMAIL PROTECTED]
11155 [EMAIL PROTECTED]
11156 [EMAIL PROTECTED]
11157 [EMAIL PROTECTED]
11158 [EMAIL PROTECTED]
11159 [EMAIL PROTECTED]
11160 [EMAIL PROTECTED]
11161 [EMAIL PROTECTED]
11162 [EMAIL PROTECTED]
11163 [EMAIL PROTECTED]
11164 [EMAIL PROTECTED]
11165 [EMAIL PROTECTED]
11166 [EMAIL PROTECTED]
11167 [EMAIL PROTECTED]
11168 [EMAIL PROTECTED]
11169 [EMAIL PROTECTED]
11170 [EMAIL PROTECTED]
11171 [EMAIL PROTECTED]
11172 [EMAIL PROTECTED]
11173 [EMAIL PROTECTED]
11174 [EMAIL PROTECTED]
11175 [EMAIL PROTECTED]
11176 [EMAIL PROTECTED]
11177 [EMAIL PROTECTED]
11178 [EMAIL PROTECTED]
11179 [EMAIL PROTECTED]
11180 [EMAIL PROTECTED]
11181 [EMAIL PROTECTED]
11182 [EMAIL PROTECTED]
11183 [EMAIL PROTECTED]
11184 [EMAIL PROTECTED]
11185 [EMAIL PROTECTED]
11186 [EMAIL PROTECTED]
11187 [EMAIL PROTECTED]


Modified: branches/4.0-regwrite/source/lib/registry/dir.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/dir.c     2007-08-04 18:15:26 UTC 
(rev 24213)
+++ branches/4.0-regwrite/source/lib/registry/dir.c     2007-08-04 18:15:37 UTC 
(rev 24214)
@@ -28,9 +28,11 @@
        const char *path;
 };
 
+static struct hive_operations reg_backend_dir;
+
 static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, 
-                                                         struct hive_key 
*parent, 
-                                                         const char *name, 
uint32_t access_mask, 
+                                                         const struct hive_key 
*parent, 
+                                                         const char *name, 
const char *classname,
                                                          struct 
security_descriptor *desc, 
                                                          struct hive_key 
**result)
 {
@@ -42,20 +44,30 @@
        ret = mkdir(path, 0700);
        if (ret == 0) {
                struct dir_key *key = talloc(mem_ctx, struct dir_key);
+               key->key.ops = &reg_backend_dir;
                key->path = talloc_steal(key, path);
                *result = (struct hive_key *)key;
                return WERR_OK;
        }
-       return WERR_INVALID_PARAM;
+
+       if (errno == EEXIST)
+               return WERR_ALREADY_EXISTS;
+       printf("FAILED %s BECAUSE: %s\n", path, strerror(errno));
+       return WERR_GENERAL_FAILURE;
 }
 
-static WERROR reg_dir_del_key(struct hive_key *k, const char *name)
+static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
 {
        struct dir_key *dk = talloc_get_type(k, struct dir_key);
        char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);
        WERROR ret;
 
-       if (rmdir(child) == 0) ret = WERR_OK; else ret = WERR_GENERAL_FAILURE;
+       if (rmdir(child) == 0) 
+               ret = WERR_OK; 
+       else if (errno == ENOENT)
+               ret = WERR_NOT_FOUND;
+       else
+               ret = WERR_GENERAL_FAILURE;
 
        talloc_free(child);
 
@@ -85,6 +97,7 @@
        }
        closedir(d);
        ret = talloc(mem_ctx, struct dir_key);
+       ret->key.ops = &reg_backend_dir;
        ret->path = talloc_steal(ret, fullpath);
        *subkey = (struct hive_key *)ret;
        return WERR_OK;
@@ -150,6 +163,7 @@
                return WERR_INVALID_PARAM;
 
        dk = talloc(parent_ctx, struct dir_key);
+       dk->key.ops = &reg_backend_dir;
        dk->path = talloc_strdup(dk, location);
        *key = (struct hive_key *)dk;
        return WERR_OK;
@@ -158,16 +172,39 @@
 WERROR reg_create_directory(TALLOC_CTX *parent_ctx, 
                                                        const char *location, 
struct hive_key **key)
 {
-       if (mkdir(location, 0644) != 0) {
+       if (mkdir(location, 0700) != 0) {
+               *key = NULL;
                return WERR_GENERAL_FAILURE;
        }
 
        return reg_open_directory(parent_ctx, location, key);
 }
 
+static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key, 
+                                                          const char 
**classname,
+                                                          uint32_t 
*num_subkeys,
+                                                          uint32_t *num_values,
+                                                          NTTIME *lastmod)
+{
+       /* FIXME */
+       if (classname != NULL)
+               *classname = NULL;
+
+       if (num_subkeys != NULL)
+               *num_subkeys = 0;
+
+       if (num_values != NULL)
+               *num_values = 0;
+
+       if (lastmod != NULL)
+               *lastmod = 0;
+       return WERR_OK;
+}
+
 static struct hive_operations reg_backend_dir = {
        .name = "dir",
        .get_key_by_name = reg_dir_open_key,
+       .get_key_info = reg_dir_get_info,
        .add_key = reg_dir_add_key,
        .del_key = reg_dir_del_key,
        .enum_key = reg_dir_key_by_index

Modified: branches/4.0-regwrite/source/lib/registry/hive.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/hive.c    2007-08-04 18:15:26 UTC 
(rev 24213)
+++ branches/4.0-regwrite/source/lib/registry/hive.c    2007-08-04 18:15:37 UTC 
(rev 24214)
@@ -66,7 +66,7 @@
                                                 uint32_t *num_values,
                                                 NTTIME *last_change_time)
 {
-       return key->context->ops->get_key_info(mem_ctx, key, classname, 
num_subkeys, 
+       return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys, 
                                                                        
num_values, last_change_time);
 }
 
@@ -74,10 +74,10 @@
                                                 const char *name, const char 
*classname, struct security_descriptor *desc,
                                                 struct hive_key **key)
 {
-       return parent_key->context->ops->add_key(ctx, parent_key, name, 
classname, desc, key);
+       return parent_key->ops->add_key(ctx, parent_key, name, classname, desc, 
key);
 }
 
 _PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name)
 {
-       return key->context->ops->del_key(key, name);
+       return key->ops->del_key(key, name);
 }

Modified: branches/4.0-regwrite/source/lib/registry/hive.h
===================================================================
--- branches/4.0-regwrite/source/lib/registry/hive.h    2007-08-04 18:15:26 UTC 
(rev 24213)
+++ branches/4.0-regwrite/source/lib/registry/hive.h    2007-08-04 18:15:37 UTC 
(rev 24214)
@@ -36,22 +36,13 @@
  * does it understand what predefined keys are.
  */
 
-struct hive_context {
+struct hive_key {
        const struct hive_operations *ops;
 };
 
-struct hive_key {
-       struct hive_context *context;
-};
-
 struct hive_operations {
        const char *name;       
 
-       /** 
-        * Open the root key of this hive
-        */
-       WERROR (*open_root) (struct hive_context *hive, struct hive_key **key);
-       
        /**
         * Open a specific subkey
         */

Modified: branches/4.0-regwrite/source/lib/registry/local.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/local.c   2007-08-04 18:15:26 UTC 
(rev 24213)
+++ branches/4.0-regwrite/source/lib/registry/local.c   2007-08-04 18:15:37 UTC 
(rev 24214)
@@ -46,8 +46,8 @@
 };
 
 WERROR reg_mount_hive(struct registry_context *ctx, struct reg_key_path *path, 
-                                         struct hive_context *hive);
-WERROR reg_unmount_hive(struct registry_context *ctx, struct hive_context 
*hive);
+                                         struct hive_key *hive);
+WERROR reg_unmount_hive(struct registry_context *ctx, struct hive_key *hive);
 
 static WERROR local_open_key(TALLOC_CTX *mem_ctx,
                                                   struct registry_key *parent, 

Modified: branches/4.0-regwrite/source/lib/registry/regf.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/regf.c    2007-08-04 18:15:26 UTC 
(rev 24213)
+++ branches/4.0-regwrite/source/lib/registry/regf.c    2007-08-04 18:15:37 UTC 
(rev 24214)
@@ -43,7 +43,6 @@
  */
 
 struct regf_data {
-       struct hive_context context;
        int fd;
        struct hbin_block **hbins;
        struct regf_hdr *header;
@@ -53,9 +52,7 @@
 
 struct regf_key_data {
        struct hive_key key;
-       struct regf_data *hive; /* Duplicaton, as it's already in 
-                                                          (struct regf_data 
*)key.context as well, 
-                                                          but that's harder to 
get at */
+       struct regf_data *hive; 
        uint32_t offset;
        struct nk_block *nk;
 };
@@ -408,7 +405,8 @@
                                                         const struct hive_key 
*key, 
                                                         const char **classname,
                                                         uint32_t *num_subkeys,
-                                                        uint32_t *num_values)
+                                                        uint32_t *num_values,
+                                                        NTTIME *last_mod_time)
 {
        const struct regf_key_data *private_data = 
                (const struct regf_key_data *)key;
@@ -423,6 +421,8 @@
                                                 (char*)data.data, 
private_data->nk->clsname_length);
        } else 
                *classname = NULL;
+
+       /* FIXME: Last mod time */
        
        return WERR_OK;
 }
@@ -435,7 +435,7 @@
        struct regf_key_data *ret;
 
        ret = talloc_zero(ctx, struct regf_key_data);
-       ret->key.context = talloc_reference(ret, regf);
+       ret->hive = talloc_reference(ret, regf);
        ret->offset = offset;
        nk = talloc(ret, struct nk_block);
        ret->nk = nk;
@@ -460,7 +460,7 @@
        const struct regf_key_data *private_data = 
                        (const struct regf_key_data *)key;
        struct vk_block *vk;
-       struct regf_data *regf = (struct regf_data *)key->context;
+       struct regf_data *regf = private_data->hive;
        uint32_t vk_offset;
        DATA_BLOB tmp;
 
@@ -1402,7 +1402,7 @@
 }
 
 
-static WERROR regf_del_key(struct hive_key *parent, const char *name)
+static WERROR regf_del_key(const struct hive_key *parent, const char *name)
 {
        const struct regf_key_data *private_data = 
                (const struct regf_key_data *)parent;
@@ -1454,8 +1454,8 @@
        return regf_save_hbin(private_data->hive);
 }
 
-static WERROR regf_add_key(TALLOC_CTX *ctx, struct hive_key *parent, 
-                                                  const char *name, uint32_t 
access_mask, 
+static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent, 
+                                                  const char *name, const char 
*classname,
                                                   struct security_descriptor 
*sec_desc, 
                                                   struct hive_key **ret)
 {
@@ -1479,7 +1479,7 @@
        nk.num_values = 0;
        nk.values_offset = -1;
        memset(nk.unk3, 0, 5);
-       nk.clsname_offset = -1;
+       nk.clsname_offset = -1; /* FIXME: fill in */
        nk.clsname_length = 0;
        nk.key_name = name;
        

Modified: branches/4.0-regwrite/source/lib/registry/tests/hive.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/tests/hive.c      2007-08-04 
18:15:26 UTC (rev 24213)
+++ branches/4.0-regwrite/source/lib/registry/tests/hive.c      2007-08-04 
18:15:37 UTC (rev 24214)
@@ -31,7 +31,7 @@
 {
        const struct hive_key *root = test_data;
        WERROR error = hive_key_del(root, "bla");
-       torture_assert_werr_equal(tctx, error, WERR_BADFILE, 
+       torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, 
                                                          "invalid return 
code");
 
        return true;
@@ -50,11 +50,11 @@
                                                          NULL);
        torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()");
 
-       torture_assert(tctx, num_subkeys != 0, "New key has non-zero subkey 
count");
+       torture_assert_int_equal(tctx, num_subkeys, 0, "New key has non-zero 
subkey count");
 
        torture_assert_werr_ok(tctx, error, "reg_key_num_values");
 
-       torture_assert(tctx, num_values != 0, "New key has non-zero value 
count");
+       torture_assert_int_equal(tctx, num_values, 0, "New key has non-zero 
value count");
 
        return true;
 }
@@ -69,7 +69,7 @@
 
        error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, 
                                                         NULL, &subkey);
-       torture_assert_werr_ok(tctx, error, "reg_key_add_name");
+       torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
        error = hive_key_del(root, "Nested Key");
        torture_assert_werr_ok(tctx, error, "reg_key_del");
@@ -77,17 +77,8 @@
        return true;
 }
 
-struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx) 
+static void tcase_add_tests(struct torture_tcase *tcase) 
 {
-       struct torture_tcase *tcase;
-       struct torture_suite *suite = torture_suite_create(mem_ctx, 
-                                                                               
                           "HIVE");
-
-       struct hive_key *key;
-
-       reg_create_directory(mem_ctx, "bla", &key);
-
-       tcase = torture_suite_add_tcase(suite, "dir");
        torture_tcase_add_simple_test(tcase, "del_nonexistant_key", 
                                                                  
test_del_nonexistant_key);
 
@@ -96,6 +87,45 @@
 
        torture_tcase_add_simple_test(tcase, "get_info", 
                                                                  
test_keyinfo_root);
+}
 
+static bool hive_setup_dir(struct torture_context *tctx, void **data)
+{
+
+       struct hive_key *key;
+       WERROR error;
+
+       error = reg_create_directory(tctx, "bla", &key);
+       if (!W_ERROR_IS_OK(error)) {
+               fprintf(stderr, "Unable to initialize dir hive\n");
+               return false;
+       }
+
+       *data = key;
+
+       return true;
+}
+
+static bool test_dir_refuses_null_location(struct torture_context *tctx)
+{
+       torture_assert_werr_equal(tctx, WERR_INVALID_PARAM, 
+                                                         
reg_open_directory(NULL, NULL, NULL),
+                                                         "reg_open_directory 
accepts NULL location");
+       return true;
+}
+
+struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx) 
+{
+       struct torture_tcase *tcase;
+       struct torture_suite *suite = torture_suite_create(mem_ctx, 
+                                                                               
                           "HIVE");
+
+       torture_suite_add_simple_test(suite, "dir-refuses-null-location", 
+                                                                 
test_dir_refuses_null_location);
+
+
+       tcase = torture_suite_add_tcase(suite, "dir");
+       torture_tcase_set_fixture(tcase, hive_setup_dir, NULL);
+       tcase_add_tests(tcase);
        return suite;
 }

Reply via email to