LCOV - code coverage report
Current view: top level - source4/lib/registry/tests - registry.c (source / functions) Hit Total Coverage
Test: coverage report for master 469b22b8 Lines: 286 316 90.5 %
Date: 2024-06-10 12:05:21 Functions: 22 22 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    local testing of registry library - registry backend
       5             : 
       6             :    Copyright (C) Jelmer Vernooij 2005-2007
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program; if not, write to the Free Software
      20             :    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "lib/registry/registry.h"
      25             : #include "torture/torture.h"
      26             : #include "librpc/gen_ndr/winreg.h"
      27             : #include "libcli/security/security.h"
      28             : #include "system/filesys.h"
      29             : #include "lib/registry/tests/proto.h"
      30             : 
      31             : /**
      32             :  * Test obtaining a predefined key.
      33             :  */
      34           1 : static bool test_get_predefined(struct torture_context *tctx, void *_data)
      35             : {
      36           1 :         struct registry_context *rctx = (struct registry_context *)_data;
      37           1 :         struct registry_key *root;
      38           1 :         WERROR error;
      39             : 
      40           1 :         error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);
      41           1 :         torture_assert_werr_ok(tctx, error,
      42             :                                "getting predefined key failed");
      43           0 :         return true;
      44             : }
      45             : 
      46             : /**
      47             :  * Test obtaining a predefined key.
      48             :  */
      49           1 : static bool test_get_predefined_unknown(struct torture_context *tctx,
      50             :                 void *_data)
      51             : {
      52           1 :         struct registry_context *rctx = _data;
      53           1 :         struct registry_key *root;
      54           1 :         WERROR error;
      55             : 
      56           1 :         error = reg_get_predefined_key(rctx, 1337, &root);
      57           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
      58             :                                   "getting predefined key failed");
      59           0 :         return true;
      60             : }
      61             : 
      62           1 : static bool test_predef_key_by_name(struct torture_context *tctx, void *_data)
      63             : {
      64           1 :         struct registry_context *rctx = (struct registry_context *)_data;
      65           1 :         struct registry_key *root;
      66           1 :         WERROR error;
      67             : 
      68           1 :         error = reg_get_predefined_key_by_name(rctx, "HKEY_CLASSES_ROOT",
      69             :                                                &root);
      70           1 :         torture_assert_werr_ok(tctx, error,
      71             :                                "getting predefined key failed");
      72             : 
      73           1 :         error = reg_get_predefined_key_by_name(rctx, "HKEY_classes_ROOT",
      74             :                                                &root);
      75           1 :         torture_assert_werr_ok(tctx, error,
      76             :                                "getting predefined key case insensitively failed");
      77             : 
      78           0 :         return true;
      79             : }
      80             : 
      81           1 : static bool test_predef_key_by_name_invalid(struct torture_context *tctx,
      82             :                 void *_data)
      83             : {
      84           1 :         struct registry_context *rctx = (struct registry_context *)_data;
      85           1 :         struct registry_key *root;
      86           1 :         WERROR error;
      87             : 
      88           1 :         error = reg_get_predefined_key_by_name(rctx, "BLA", &root);
      89           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
      90             :                                   "getting predefined key failed");
      91           0 :         return true;
      92             : }
      93             : 
      94             : /**
      95             :  * Test creating a new subkey
      96             :  */
      97           1 : static bool test_create_subkey(struct torture_context *tctx, void *_data)
      98             : {
      99           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     100           1 :         struct registry_key *root, *newkey;
     101           1 :         WERROR error;
     102             : 
     103           1 :         error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);
     104           1 :         torture_assert_werr_ok(tctx, error,
     105             :                                "getting predefined key failed");
     106             : 
     107           1 :         error = reg_key_add_name(rctx, root, "Bad Bentheim", NULL, NULL,
     108             :                                  &newkey);
     109           1 :         torture_assert_werr_ok(tctx, error, "Creating key return code");
     110           1 :         torture_assert(tctx, newkey != NULL, "Creating new key");
     111             : 
     112           0 :         return true;
     113             : }
     114             : 
     115             : /**
     116             :  * Test creating a new nested subkey
     117             :  */
     118           1 : static bool test_create_nested_subkey(struct torture_context *tctx, void *_data)
     119             : {
     120           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     121           1 :         struct registry_key *root, *newkey;
     122           1 :         WERROR error;
     123             : 
     124           1 :         error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);
     125           1 :         torture_assert_werr_ok(tctx, error,
     126             :                                "getting predefined key failed");
     127             : 
     128           1 :         error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL,
     129             :                                  &newkey);
     130           1 :         torture_assert_werr_ok(tctx, error, "Creating key return code");
     131           1 :         torture_assert(tctx, newkey != NULL, "Creating new key");
     132             : 
     133           0 :         return true;
     134             : }
     135             : 
     136             : /**
     137             :  * Test creating a new subkey
     138             :  */
     139           1 : static bool test_key_add_abs_top(struct torture_context *tctx, void *_data)
     140             : {
     141           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     142           1 :         struct registry_key *root;
     143           1 :         WERROR error;
     144             : 
     145           1 :         error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT", 0, NULL,
     146             :                                 &root);
     147           1 :         torture_assert_werr_equal(tctx, error, WERR_ALREADY_EXISTS,
     148             :                                   "create top level");
     149             : 
     150           0 :         return true;
     151             : }
     152             : 
     153             : /**
     154             :  * Test creating a new subkey
     155             :  */
     156           1 : static bool test_key_add_abs(struct torture_context *tctx, void *_data)
     157             : {
     158           1 :         WERROR error;
     159           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     160           1 :         struct registry_key *root, *result1, *result2;
     161             : 
     162           1 :         error = reg_key_add_abs(tctx, rctx,  "HKEY_CLASSES_ROOT\\bloe", 0, NULL,
     163             :                                 &result1);
     164           1 :         torture_assert_werr_ok(tctx, error, "create lowest");
     165             : 
     166           1 :         error = reg_key_add_abs(tctx, rctx,  "HKEY_CLASSES_ROOT\\bloe\\bla", 0,
     167             :                                 NULL, &result1);
     168           1 :         torture_assert_werr_ok(tctx, error, "create nested");
     169             : 
     170           1 :         error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);
     171           1 :         torture_assert_werr_ok(tctx, error,
     172             :                                "getting predefined key failed");
     173             : 
     174           1 :         error = reg_open_key(tctx, root, "bloe", &result2);
     175           1 :         torture_assert_werr_ok(tctx, error, "opening key");
     176             : 
     177           1 :         error = reg_open_key(tctx, root, "bloe\\bla", &result2);
     178           1 :         torture_assert_werr_ok(tctx, error, "opening key");
     179             : 
     180           0 :         return true;
     181             : }
     182             : 
     183             : 
     184           1 : static bool test_del_key(struct torture_context *tctx, void *_data)
     185             : {
     186           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     187           1 :         struct registry_key *root, *newkey;
     188           1 :         WERROR error;
     189             : 
     190           1 :         error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);
     191           1 :         torture_assert_werr_ok(tctx, error,
     192             :                                "getting predefined key failed");
     193             : 
     194           1 :         error = reg_key_add_name(rctx, root, "Polen", NULL, NULL, &newkey);
     195             : 
     196           1 :         torture_assert_werr_ok(tctx, error, "Creating key return code");
     197           1 :         torture_assert(tctx, newkey != NULL, "Creating new key");
     198             : 
     199           1 :         error = reg_key_del(tctx, root, "Polen");
     200           1 :         torture_assert_werr_ok(tctx, error, "Delete key");
     201             : 
     202           1 :         error = reg_key_del(tctx, root, "Polen");
     203           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
     204             :                                   "Delete missing key");
     205             : 
     206           0 :         return true;
     207             : }
     208             : 
     209             : /**
     210             :  * Convenience function for opening the HKEY_CLASSES_ROOT hive and
     211             :  * creating a single key for testing purposes.
     212             :  */
     213           9 : static bool create_test_key(struct torture_context *tctx,
     214             :                             struct registry_context *rctx,
     215             :                             const char *name,
     216             :                             struct registry_key **root,
     217             :                             struct registry_key **subkey)
     218             : {
     219           9 :         WERROR error;
     220             : 
     221           9 :         error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, root);
     222           9 :         torture_assert_werr_ok(tctx, error,
     223             :                                "getting predefined key failed");
     224             : 
     225           9 :         error = reg_key_add_name(rctx, *root, name, NULL, NULL, subkey);
     226           9 :         torture_assert_werr_ok(tctx, error, "Creating key return code");
     227             : 
     228           0 :         return true;
     229             : }
     230             : 
     231             : 
     232           1 : static bool test_flush_key(struct torture_context *tctx, void *_data)
     233             : {
     234           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     235           1 :         struct registry_key *root, *subkey;
     236           1 :         WERROR error;
     237             : 
     238           1 :         if (!create_test_key(tctx, rctx, "Bremen", &root, &subkey))
     239           0 :                 return false;
     240             : 
     241           1 :         error = reg_key_flush(subkey);
     242           1 :         torture_assert_werr_ok(tctx, error, "flush key");
     243             : 
     244           1 :         torture_assert_werr_equal(tctx, reg_key_flush(NULL),
     245             :                                   WERR_INVALID_PARAMETER, "flush key");
     246             : 
     247           1 :         return true;
     248             : }
     249             : 
     250           1 : static bool test_query_key(struct torture_context *tctx, void *_data)
     251             : {
     252           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     253           1 :         struct registry_key *root, *subkey;
     254           1 :         WERROR error;
     255           1 :         NTTIME last_changed_time;
     256           1 :         uint32_t num_subkeys, num_values;
     257           1 :         const char *classname;
     258           1 :         const char *data = "temp";
     259             : 
     260           1 :         if (!create_test_key(tctx, rctx, "Muenchen", &root, &subkey))
     261           0 :                 return false;
     262             : 
     263           1 :         error = reg_key_get_info(tctx, subkey, &classname,
     264             :                                  &num_subkeys, &num_values,
     265             :                                  &last_changed_time, NULL, NULL, NULL);
     266             : 
     267           1 :         torture_assert_werr_ok(tctx, error, "get info key");
     268           1 :         torture_assert(tctx, classname == NULL, "classname");
     269           1 :         torture_assert_int_equal(tctx, num_subkeys, 0, "num subkeys");
     270           1 :         torture_assert_int_equal(tctx, num_values, 0, "num values");
     271             : 
     272           1 :         error = reg_val_set(subkey, "", REG_SZ,
     273             :                             data_blob_string_const(data));
     274           1 :         torture_assert_werr_ok(tctx, error, "set default value");
     275             : 
     276           1 :         error = reg_key_get_info(tctx, subkey, &classname,
     277             :                                  &num_subkeys, &num_values,
     278             :                                  &last_changed_time, NULL, NULL, NULL);
     279             : 
     280           1 :         torture_assert_werr_ok(tctx, error, "get info key");
     281           1 :         torture_assert(tctx, classname == NULL, "classname");
     282           1 :         torture_assert_int_equal(tctx, num_subkeys, 0, "num subkeys");
     283           1 :         torture_assert_int_equal(tctx, num_values, 1, "num values");
     284             : 
     285           0 :         return true;
     286             : }
     287             : 
     288           1 : static bool test_query_key_nums(struct torture_context *tctx, void *_data)
     289             : {
     290           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     291           1 :         struct registry_key *root, *subkey1, *subkey2;
     292           1 :         WERROR error;
     293           1 :         uint32_t num_subkeys, num_values;
     294           1 :         char data[4];
     295           1 :         SIVAL(data, 0, 42);
     296             : 
     297           1 :         if (!create_test_key(tctx, rctx, "Berlin", &root, &subkey1))
     298           0 :                 return false;
     299             : 
     300           1 :         error = reg_key_add_name(rctx, subkey1, "Bentheim", NULL, NULL,
     301             :                                  &subkey2);
     302           1 :         torture_assert_werr_ok(tctx, error, "Creating key return code");
     303             : 
     304           1 :         error = reg_val_set(subkey1, "Answer", REG_DWORD,
     305             :                             data_blob_talloc(tctx, &data, sizeof(data)));
     306           1 :         torture_assert_werr_ok(tctx, error, "set value");
     307             : 
     308           1 :         error = reg_key_get_info(tctx, subkey1, NULL, &num_subkeys,
     309             :                                  &num_values, NULL, NULL, NULL, NULL);
     310             : 
     311           1 :         torture_assert_werr_ok(tctx, error, "get info key");
     312           1 :         torture_assert_int_equal(tctx, num_subkeys, 1, "num subkeys");
     313           1 :         torture_assert_int_equal(tctx, num_values, 1, "num values");
     314             : 
     315           0 :         return true;
     316             : }
     317             : 
     318             : /**
     319             :  * Test that the subkeys of a key can be enumerated, that
     320             :  * the returned parameters for get_subkey_by_index are optional and
     321             :  * that enumerating the parents of a non-top-level node works.
     322             :  */
     323           1 : static bool test_list_subkeys(struct torture_context *tctx, void *_data)
     324             : {
     325           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     326           1 :         struct registry_key *subkey = NULL, *root;
     327           1 :         WERROR error;
     328           1 :         NTTIME last_mod_time;
     329           1 :         const char *classname, *name;
     330             : 
     331           1 :         if (!create_test_key(tctx, rctx, "Goettingen", &root, &subkey))
     332           0 :                 return false;
     333             : 
     334           1 :         error = reg_key_get_subkey_by_index(tctx, root, 0, &name, &classname,
     335             :                                             &last_mod_time);
     336             : 
     337           1 :         torture_assert_werr_ok(tctx, error, "Enum keys return code");
     338           1 :         torture_assert_str_equal(tctx, name, "Goettingen", "Enum keys data");
     339             : 
     340             : 
     341           1 :         error = reg_key_get_subkey_by_index(tctx, root, 0, NULL, NULL, NULL);
     342             : 
     343           1 :         torture_assert_werr_ok(tctx, error,
     344             :                                "Enum keys with NULL arguments return code");
     345             : 
     346           1 :         error = reg_key_get_subkey_by_index(tctx, root, 1, NULL, NULL, NULL);
     347             : 
     348           1 :         torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS,
     349             :                                   "Invalid error for no more items");
     350             : 
     351           1 :         error = reg_key_get_subkey_by_index(tctx, subkey, 0, NULL, NULL, NULL);
     352             : 
     353           1 :         torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS,
     354             :                                   "Invalid error for no more items");
     355             : 
     356           0 :         return true;
     357             : }
     358             : 
     359             : /**
     360             :  * Test setting a value
     361             :  */
     362           1 : static bool test_set_value(struct torture_context *tctx, void *_data)
     363             : {
     364           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     365           1 :         struct registry_key *subkey = NULL, *root;
     366           1 :         WERROR error;
     367           1 :         char data[4];
     368             : 
     369           1 :         SIVAL(data, 0, 42);
     370             : 
     371           1 :         if (!create_test_key(tctx, rctx, "Dusseldorf", &root, &subkey))
     372           0 :                 return false;
     373             : 
     374           1 :         error = reg_val_set(subkey, "Answer", REG_DWORD,
     375             :                             data_blob_talloc(tctx, data, sizeof(data)));
     376           1 :         torture_assert_werr_ok (tctx, error, "setting value");
     377             : 
     378           0 :         return true;
     379             : }
     380             : 
     381             : /**
     382             :  * Test getting/setting security descriptors
     383             :  */
     384           1 : static bool test_security(struct torture_context *tctx, void *_data)
     385             : {
     386           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     387           1 :         struct registry_key *subkey = NULL, *root;
     388           1 :         WERROR error;
     389           1 :         struct security_descriptor *osd, *nsd;
     390             : 
     391           1 :         if (!create_test_key(tctx, rctx, "Düsseldorf", &root, &subkey))
     392           0 :                 return false;
     393             : 
     394           1 :         osd = security_descriptor_dacl_create(tctx,
     395             :                                          0,
     396             :                                          NULL, NULL,
     397             :                                          SID_NT_AUTHENTICATED_USERS,
     398             :                                          SEC_ACE_TYPE_ACCESS_ALLOWED,
     399             :                                          SEC_GENERIC_ALL,
     400             :                                          SEC_ACE_FLAG_OBJECT_INHERIT,
     401             :                                          NULL);
     402             : 
     403           1 :         error = reg_set_sec_desc(subkey, osd);
     404           1 :         torture_assert_werr_ok(tctx, error, "setting security descriptor");
     405             : 
     406           0 :         error = reg_get_sec_desc(tctx, subkey, &nsd);
     407           0 :         torture_assert_werr_ok (tctx, error, "getting security descriptor");
     408             : 
     409           0 :         torture_assert(tctx, security_descriptor_equal(osd, nsd),
     410             :                        "security descriptor changed!");
     411             : 
     412           0 :         return true;
     413             : }
     414             : 
     415             : /**
     416             :  * Test getting a value
     417             :  */
     418           1 : static bool test_get_value(struct torture_context *tctx, void *_data)
     419             : {
     420           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     421           1 :         struct registry_key *subkey = NULL, *root;
     422           1 :         WERROR error;
     423           1 :         DATA_BLOB data;
     424           1 :         char value[4];
     425           1 :         uint32_t type;
     426           1 :         const char *data_val = "temp";
     427             : 
     428           1 :         SIVAL(value, 0, 42);
     429             : 
     430           1 :         if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey))
     431           0 :                 return false;
     432             : 
     433           1 :         error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type,
     434             :                                           &data);
     435           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
     436             :                                   "getting missing value");
     437             : 
     438           1 :         error = reg_val_set(subkey, __FUNCTION__, REG_DWORD,
     439             :                             data_blob_talloc(tctx, value, sizeof(value)));
     440           1 :         torture_assert_werr_ok(tctx, error, "setting value");
     441             : 
     442           1 :         error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type,
     443             :                                           &data);
     444           1 :         torture_assert_werr_ok(tctx, error, "getting value");
     445             : 
     446           1 :         torture_assert_int_equal(tctx, sizeof(value), data.length, "value length ok");
     447           1 :         torture_assert_mem_equal(tctx, data.data, value, sizeof(value),
     448             :                                  "value content ok");
     449           1 :         torture_assert_int_equal(tctx, REG_DWORD, type, "value type");
     450             : 
     451           1 :         error = reg_val_set(subkey, "", REG_SZ,
     452             :                             data_blob_talloc(tctx, data_val,
     453             :                                              strlen(data_val)));
     454           1 :         torture_assert_werr_ok(tctx, error, "set default value");
     455             : 
     456           1 :         error = reg_key_get_value_by_name(tctx, subkey, "", &type,
     457             :                                           &data);
     458           1 :         torture_assert_werr_ok(tctx, error, "getting default value");
     459           1 :         torture_assert_int_equal(tctx, REG_SZ, type, "value type ok");
     460           1 :         torture_assert_int_equal(tctx, strlen(data_val), data.length, "value length ok");
     461           1 :         torture_assert_str_equal(tctx, data_val, (char *)data.data, "value ok");
     462             : 
     463           0 :         return true;
     464             : }
     465             : 
     466             : /**
     467             :  * Test unsetting a value
     468             :  */
     469           1 : static bool test_del_value(struct torture_context *tctx, void *_data)
     470             : {
     471           1 :         struct registry_context *rctx =(struct registry_context *)_data;
     472           1 :         struct registry_key *subkey = NULL, *root;
     473           1 :         WERROR error;
     474           1 :         DATA_BLOB data;
     475           1 :         uint32_t type;
     476           1 :         char value[4];
     477           1 :         const char *data_val = "temp";
     478             : 
     479           1 :         SIVAL(value, 0, 42);
     480             : 
     481           1 :         if (!create_test_key(tctx, rctx, "Warschau", &root, &subkey))
     482           0 :                 return false;
     483             : 
     484           1 :         error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type,
     485             :                                           &data);
     486           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
     487             :                                   "getting missing value");
     488             : 
     489           1 :         error = reg_val_set(subkey, __FUNCTION__, REG_DWORD,
     490             :                             data_blob_talloc(tctx, value, sizeof(value)));
     491           1 :         torture_assert_werr_ok (tctx, error, "setting value");
     492             : 
     493           1 :         error = reg_del_value(tctx, subkey, __FUNCTION__);
     494           1 :         torture_assert_werr_ok (tctx, error, "unsetting value");
     495             : 
     496           1 :         error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__,
     497             :                                           &type, &data);
     498           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
     499             :                                   "getting missing value");
     500             : 
     501           1 :         error = reg_del_value(tctx, subkey, "");
     502           1 :         torture_assert_werr_equal(tctx, error, WERR_FILE_NOT_FOUND,
     503             :                                   "unsetting missing default value");
     504             : 
     505           1 :         error = reg_val_set(subkey, "", REG_SZ,
     506             :                             data_blob_talloc(tctx, data_val,
     507             :                                              strlen(data_val)));
     508           1 :         torture_assert_werr_ok(tctx, error, "set default value");
     509             : 
     510           1 :         error = reg_del_value(tctx, subkey, "");
     511           1 :         torture_assert_werr_ok (tctx, error, "unsetting default value");
     512             : 
     513           0 :         return true;
     514             : }
     515             : 
     516             : /**
     517             :  * Test listing values
     518             :  */
     519           1 : static bool test_list_values(struct torture_context *tctx, void *_data)
     520             : {
     521           1 :         struct registry_context *rctx = (struct registry_context *)_data;
     522           1 :         struct registry_key *subkey = NULL, *root;
     523           1 :         WERROR error;
     524           1 :         DATA_BLOB data;
     525           1 :         uint32_t type;
     526           1 :         const char *name;
     527           1 :         char value[4];
     528           1 :         const char *data_val = "temp";
     529             : 
     530           1 :         SIVAL(value, 0, 42);
     531             : 
     532           1 :         if (!create_test_key(tctx, rctx, "Bonn", &root, &subkey))
     533           0 :                 return false;
     534             : 
     535           1 :         error = reg_val_set(subkey, "bar", REG_DWORD,
     536             :                             data_blob_talloc(tctx, value, sizeof(value)));
     537           1 :         torture_assert_werr_ok (tctx, error, "setting value");
     538             : 
     539           1 :         error = reg_key_get_value_by_index(tctx, subkey, 0, &name,
     540             :                                            &type, &data);
     541           1 :         torture_assert_werr_ok(tctx, error, "getting value");
     542             : 
     543           1 :         torture_assert_str_equal(tctx, name, "bar", "value name");
     544           1 :         torture_assert_int_equal(tctx, sizeof(value), data.length, "value length");
     545           1 :         torture_assert_mem_equal(tctx, data.data, value, sizeof(value),
     546             :                        "value content");
     547           1 :         torture_assert_int_equal(tctx, REG_DWORD, type, "value type");
     548             : 
     549           1 :         error = reg_key_get_value_by_index(tctx, subkey, 1, &name,
     550             :                                            &type, &data);
     551           1 :         torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS,
     552             :                                   "getting missing value");
     553             : 
     554           1 :         error = reg_val_set(subkey, "", REG_SZ,
     555             :                             data_blob_talloc(tctx, data_val, strlen(data_val)));
     556           1 :         torture_assert_werr_ok(tctx, error, "set default value");
     557             : 
     558           1 :         error = reg_key_get_value_by_index(tctx, subkey, 0, &name,
     559             :                                            &type, &data);
     560           1 :         torture_assert_werr_ok(tctx, error, "getting default value");
     561           1 :         torture_assert_int_equal(tctx, REG_SZ, type, "value type ok");
     562           1 :         torture_assert_int_equal(tctx, strlen(data_val), data.length, "value length ok");
     563           1 :         torture_assert_str_equal(tctx, data_val, (char *)data.data, "value ok");
     564             : 
     565           0 :         return true;
     566             : }
     567             : 
     568           1 : static bool setup_local_registry(struct torture_context *tctx, void **data)
     569             : {
     570           1 :         struct registry_context *rctx;
     571           1 :         WERROR error;
     572           1 :         char *tempdir;
     573           1 :         NTSTATUS status;
     574           1 :         struct hive_key *hive_key;
     575           1 :         const char *filename;
     576             : 
     577           1 :         error = reg_open_local(tctx, &rctx);
     578           1 :         torture_assert_werr_ok(tctx, error, "Opening local registry failed");
     579             : 
     580           1 :         status = torture_temp_dir(tctx, "registry-local", &tempdir);
     581           1 :         torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed");
     582             : 
     583           1 :         filename = talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir);
     584           1 :         error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &hive_key);
     585           1 :         torture_assert_werr_ok(tctx, error, "Opening classes_root file failed");
     586             : 
     587           1 :         error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL);
     588           1 :         torture_assert_werr_ok(tctx, error, "Mounting hive failed");
     589             : 
     590           1 :         *data = rctx;
     591             : 
     592           1 :         return true;
     593             : }
     594             : 
     595        2363 : static void tcase_add_tests(struct torture_tcase *tcase)
     596             : {
     597        2363 :         torture_tcase_add_simple_test(tcase, "list_subkeys",
     598             :                                         test_list_subkeys);
     599        2363 :         torture_tcase_add_simple_test(tcase, "get_predefined_key",
     600             :                                         test_get_predefined);
     601        2363 :         torture_tcase_add_simple_test(tcase, "get_predefined_key",
     602             :                                         test_get_predefined_unknown);
     603        2363 :         torture_tcase_add_simple_test(tcase, "create_key",
     604             :                                         test_create_subkey);
     605        2363 :         torture_tcase_add_simple_test(tcase, "create_key",
     606             :                                         test_create_nested_subkey);
     607        2363 :         torture_tcase_add_simple_test(tcase, "key_add_abs",
     608             :                                         test_key_add_abs);
     609        2363 :         torture_tcase_add_simple_test(tcase, "key_add_abs_top",
     610             :                                         test_key_add_abs_top);
     611        2363 :         torture_tcase_add_simple_test(tcase, "set_value",
     612             :                                         test_set_value);
     613        2363 :         torture_tcase_add_simple_test(tcase, "get_value",
     614             :                                         test_get_value);
     615        2363 :         torture_tcase_add_simple_test(tcase, "list_values",
     616             :                                         test_list_values);
     617        2363 :         torture_tcase_add_simple_test(tcase, "del_key",
     618             :                                         test_del_key);
     619        2363 :         torture_tcase_add_simple_test(tcase, "del_value",
     620             :                                         test_del_value);
     621        2363 :         torture_tcase_add_simple_test(tcase, "flush_key",
     622             :                                         test_flush_key);
     623        2363 :         torture_tcase_add_simple_test(tcase, "query_key",
     624             :                                         test_query_key);
     625        2363 :         torture_tcase_add_simple_test(tcase, "query_key_nums",
     626             :                                         test_query_key_nums);
     627        2363 :         torture_tcase_add_simple_test(tcase, "test_predef_key_by_name",
     628             :                                         test_predef_key_by_name);
     629        2363 :         torture_tcase_add_simple_test(tcase, "security",
     630             :                                         test_security);
     631        2363 :         torture_tcase_add_simple_test(tcase,"test_predef_key_by_name_invalid",
     632             :                                         test_predef_key_by_name_invalid);
     633        2363 : }
     634             : 
     635        2363 : struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx)
     636             : {
     637         125 :         struct torture_tcase *tcase;
     638        2363 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "registry");
     639             : 
     640        2363 :         tcase = torture_suite_add_tcase(suite, "local");
     641        2363 :         torture_tcase_set_fixture(tcase, setup_local_registry, NULL);
     642        2363 :         tcase_add_tests(tcase);
     643             : 
     644        2363 :         return suite;
     645             : }

Generated by: LCOV version 1.14