LCOV - code coverage report
Current view: top level - libcli/registry - util_reg.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 34 40 85.0 %
Date: 2024-04-21 15:09:00 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * Registry helper routines
       4             :  * Copyright (C) Volker Lendecke 2006
       5             :  * Copyright (C) Guenther Deschner 2009
       6             :  * Copyright (C) Jelmer Vernooij 2003-2007
       7             :  *
       8             :  * This program is free software; you can redistribute it and/or modify it
       9             :  * under the terms of the GNU General Public License as published by the Free
      10             :  * Software Foundation; either version 3 of the License, or (at your option)
      11             :  * any later version.
      12             :  *
      13             :  * This program is distributed in the hope that it will be useful, but WITHOUT
      14             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15             :  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      16             :  * more details.
      17             :  *
      18             :  * You should have received a copy of the GNU General Public License along with
      19             :  * this program; if not, see <http://www.gnu.org/licenses/>.
      20             :  */
      21             : 
      22             : #include "includes.h"
      23             : #include "../librpc/gen_ndr/ndr_misc.h"
      24             : #include "../libcli/registry/util_reg.h"
      25             : 
      26             : /**
      27             :  * @file
      28             :  * @brief Registry utility functions
      29             :  */
      30             : 
      31             : static const struct {
      32             :         uint32_t id;
      33             :         const char *name;
      34             : } reg_value_types[] = {
      35             :         { REG_NONE, "REG_NONE" },
      36             :         { REG_SZ, "REG_SZ" },
      37             :         { REG_EXPAND_SZ, "REG_EXPAND_SZ" },
      38             :         { REG_BINARY, "REG_BINARY" },
      39             :         { REG_DWORD, "REG_DWORD" },
      40             :         { REG_DWORD_BIG_ENDIAN, "REG_DWORD_BIG_ENDIAN" },
      41             :         { REG_LINK, "REG_LINK" },
      42             :         { REG_MULTI_SZ, "REG_MULTI_SZ" },
      43             :         { REG_RESOURCE_LIST, "REG_RESOURCE_LIST" },
      44             :         { REG_FULL_RESOURCE_DESCRIPTOR, "REG_FULL_RESOURCE_DESCRIPTOR" },
      45             :         { REG_RESOURCE_REQUIREMENTS_LIST, "REG_RESOURCE_REQUIREMENTS_LIST" },
      46             :         { REG_QWORD, "REG_QWORD" },
      47             : 
      48             :         { 0, NULL }
      49             : };
      50             : 
      51             : /** Return string description of registry value type */
      52        5207 : _PUBLIC_ const char *str_regtype(int type)
      53             : {
      54          15 :         unsigned int i;
      55       28564 :         for (i = 0; reg_value_types[i].name; i++) {
      56       28116 :                 if (reg_value_types[i].id == type)
      57        4759 :                         return reg_value_types[i].name;
      58             :         }
      59             : 
      60         448 :         return "Unknown";
      61             : }
      62             : 
      63             : /** Return registry value type for string description */
      64         616 : _PUBLIC_ int regtype_by_string(const char *str)
      65             : {
      66          70 :         unsigned int i;
      67        3498 :         for (i = 0; reg_value_types[i].name; i++) {
      68        3292 :                 if (strequal(reg_value_types[i].name, str))
      69         410 :                         return reg_value_types[i].id;
      70             :         }
      71             : 
      72         182 :         return -1;
      73             : }
      74             : 
      75             : /*******************************************************************
      76             :  push a string in unix charset into a REG_SZ UCS2 null terminated blob
      77             :  ********************************************************************/
      78             : 
      79        9974 : bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s)
      80             : {
      81          24 :         union winreg_Data data;
      82          24 :         enum ndr_err_code ndr_err;
      83        9974 :         data.string = s;
      84        9974 :         ndr_err = ndr_push_union_blob(blob, mem_ctx, &data, REG_SZ,
      85             :                         (ndr_push_flags_fn_t)ndr_push_winreg_Data);
      86        9974 :         return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
      87             : }
      88             : 
      89             : /*******************************************************************
      90             :  push a string_array in unix charset into a REG_MULTI_SZ UCS2 double-null
      91             :  terminated blob
      92             :  ********************************************************************/
      93             : 
      94        3885 : bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a)
      95             : {
      96           0 :         union winreg_Data data;
      97           0 :         enum ndr_err_code ndr_err;
      98        3885 :         data.string_array = a;
      99        3885 :         ndr_err = ndr_push_union_blob(blob, mem_ctx, &data, REG_MULTI_SZ,
     100             :                         (ndr_push_flags_fn_t)ndr_push_winreg_Data);
     101        3885 :         return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
     102             : }
     103             : 
     104             : /*******************************************************************
     105             :  pull a string in unix charset out of a REG_SZ UCS2 null terminated blob
     106             :  ********************************************************************/
     107             : 
     108      111171 : bool pull_reg_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char **s)
     109             : {
     110          28 :         union winreg_Data data;
     111          28 :         enum ndr_err_code ndr_err;
     112      111171 :         ndr_err = ndr_pull_union_blob(blob, mem_ctx, &data, REG_SZ,
     113             :                         (ndr_pull_flags_fn_t)ndr_pull_winreg_Data);
     114      111171 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     115           0 :                 return false;
     116             :         }
     117      111171 :         *s = data.string;
     118      111171 :         return true;
     119             : }
     120             : 
     121             : /*******************************************************************
     122             :  pull a string_array in unix charset out of a REG_MULTI_SZ UCS2 double-null
     123             :  terminated blob
     124             :  ********************************************************************/
     125             : 
     126          10 : bool pull_reg_multi_sz(TALLOC_CTX *mem_ctx, 
     127             :                        const DATA_BLOB *blob, const char ***a)
     128             : {
     129           0 :         union winreg_Data data;
     130           0 :         enum ndr_err_code ndr_err;
     131          10 :         ndr_err = ndr_pull_union_blob(blob, mem_ctx, &data, REG_MULTI_SZ,
     132             :                         (ndr_pull_flags_fn_t)ndr_pull_winreg_Data);
     133          10 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     134           0 :                 return false;
     135             :         }
     136          10 :         *a = data.string_array;
     137          10 :         return true;
     138             : }

Generated by: LCOV version 1.14