LCOV - code coverage report
Current view: top level - source4/lib/registry - hive.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 46 56 82.1 %
Date: 2024-04-21 15:09:00 Functions: 13 13 100.0 %

          Line data    Source code
       1             : 
       2             : /*
       3             :    Unix SMB/CIFS implementation.
       4             :    Registry hive interface
       5             :    Copyright (C) Jelmer Vernooij                                  2003-2007.
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "registry.h"
      24             : #include "system/filesys.h"
      25             : #include "param/param.h"
      26             : 
      27             : /** Open a registry file/host/etc */
      28        1292 : _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
      29             :                               struct auth_session_info *session_info,
      30             :                               struct cli_credentials *credentials,
      31             :                               struct tevent_context *ev_ctx,
      32             :                               struct loadparm_context *lp_ctx,
      33             :                               struct hive_key **root)
      34             : {
      35           0 :         int fd, num;
      36           0 :         char peek[20];
      37             : 
      38        1292 :         fd = open(location, O_RDWR);
      39        1292 :         if (fd == -1) {
      40          27 :                 if (errno == ENOENT)
      41          27 :                         return WERR_FILE_NOT_FOUND;
      42           0 :                 return WERR_FILE_NOT_FOUND;
      43             :         }
      44             : 
      45        1265 :         num = read(fd, peek, 20);
      46        1265 :         close(fd);
      47        1265 :         if (num == -1) {
      48           0 :                 return WERR_FILE_NOT_FOUND;
      49             :         }
      50             : 
      51        1265 :         if (!strncmp(peek, "regf", 4)) {
      52           0 :                 return reg_open_regf_file(parent_ctx, location, root);
      53        1265 :         } else if (!strncmp(peek, "TDB file", 8)) {
      54        1265 :                 return reg_open_ldb_file(parent_ctx, location, session_info,
      55             :                                          credentials, ev_ctx, lp_ctx, root);
      56             :         }
      57             : 
      58           0 :         return WERR_FILE_NOT_FOUND;
      59             : }
      60             : 
      61         272 : _PUBLIC_ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx,
      62             :                                   const struct hive_key *key,
      63             :                                   const char **classname, uint32_t *num_subkeys,
      64             :                                   uint32_t *num_values,
      65             :                                   NTTIME *last_change_time,
      66             :                                   uint32_t *max_subkeynamelen,
      67             :                                   uint32_t *max_valnamelen,
      68             :                                   uint32_t *max_valbufsize)
      69             : {
      70         272 :         return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys,
      71             :                                       num_values, last_change_time,
      72             :                                       max_subkeynamelen,
      73             :                                       max_valnamelen, max_valbufsize);
      74             : }
      75             : 
      76        4892 : _PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx,
      77             :                                   const struct hive_key *parent_key,
      78             :                                   const char *name, const char *classname,
      79             :                                   struct security_descriptor *desc,
      80             :                                   struct hive_key **key)
      81             : {
      82        4892 :         SMB_ASSERT(strchr(name, '\\') == NULL);
      83             : 
      84        4892 :         return parent_key->ops->add_key(ctx, parent_key, name, classname,
      85             :                                         desc, key);
      86             : }
      87             : 
      88        2574 : _PUBLIC_ WERROR hive_key_del(TALLOC_CTX *mem_ctx, const struct hive_key *key,
      89             :                              const char *name)
      90             : {
      91        2574 :         return key->ops->del_key(mem_ctx, key, name);
      92             : }
      93             : 
      94       33024 : _PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
      95             :                                      const struct hive_key *key,
      96             :                                      const char *name,
      97             :                                      struct hive_key **subkey)
      98             : {
      99       33024 :         return key->ops->get_key_by_name(mem_ctx, key, name, subkey);
     100             : }
     101             : 
     102         260 : WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
     103             :                      const struct hive_key *key, uint32_t idx,
     104             :                      const char **name,
     105             :                      const char **classname,
     106             :                      NTTIME *last_mod_time)
     107             : {
     108         260 :         return key->ops->enum_key(mem_ctx, key, idx, name, classname,
     109             :                                   last_mod_time);
     110             : }
     111             : 
     112        3043 : WERROR hive_key_set_value(struct hive_key *key, const char *name, uint32_t type,
     113             :                                           const DATA_BLOB data)
     114             : {
     115        3043 :         if (key->ops->set_value == NULL)
     116           0 :                 return WERR_NOT_SUPPORTED;
     117             : 
     118        3043 :         return key->ops->set_value(key, name, type, data);
     119             : }
     120             : 
     121        7931 : WERROR hive_get_value(TALLOC_CTX *mem_ctx,
     122             :                       struct hive_key *key, const char *name,
     123             :                       uint32_t *type, DATA_BLOB *data)
     124             : {
     125        7931 :         if (key->ops->get_value_by_name == NULL)
     126           0 :                 return WERR_NOT_SUPPORTED;
     127             : 
     128        7931 :         return key->ops->get_value_by_name(mem_ctx, key, name, type, data);
     129             : }
     130             : 
     131        2889 : WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
     132             :                                struct hive_key *key, uint32_t idx,
     133             :                                const char **name,
     134             :                                uint32_t *type, DATA_BLOB *data)
     135             : {
     136        2889 :         if (key->ops->enum_value == NULL)
     137           0 :                 return WERR_NOT_SUPPORTED;
     138             : 
     139        2889 :         return key->ops->enum_value(mem_ctx, key, idx, name, type, data);
     140             : }
     141             : 
     142           3 : WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx,
     143             :                          struct hive_key *key, 
     144             :                          struct security_descriptor **security)
     145             : {
     146           3 :         if (key->ops->get_sec_desc == NULL)
     147           1 :                 return WERR_NOT_SUPPORTED;
     148             : 
     149           2 :         return key->ops->get_sec_desc(mem_ctx, key, security);
     150             : }
     151             : 
     152           2 : WERROR hive_set_sec_desc(struct hive_key *key, 
     153             :                          const struct security_descriptor *security)
     154             : {
     155           2 :         if (key->ops->set_sec_desc == NULL)
     156           1 :                 return WERR_NOT_SUPPORTED;
     157             : 
     158           1 :         return key->ops->set_sec_desc(key, security);
     159             : }
     160             : 
     161        2409 : WERROR hive_key_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
     162             :                           const char *name)
     163             : {
     164        2409 :         if (key->ops->delete_value == NULL)
     165           0 :                 return WERR_NOT_SUPPORTED;
     166             : 
     167        2409 :         return key->ops->delete_value(mem_ctx, key, name);
     168             : }
     169             : 
     170         644 : WERROR hive_key_flush(struct hive_key *key)
     171             : {
     172         644 :         if (key->ops->flush_key == NULL)
     173         643 :                 return WERR_OK;
     174             : 
     175           1 :         return key->ops->flush_key(key);
     176             : }

Generated by: LCOV version 1.14