net: change split_hive_key() to properly allocate subkeyname
[Samba.git] / source / utils / net_registry_util.c
blob948f8b6153f38417e99812a09133fbbb9ef4e5ba
1 /*
2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * registry utility functions
6 * Copyright (C) Michael Adam 2008
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.
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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "utils/net_registry_util.h"
25 void print_registry_key(const char *keyname, NTTIME *modtime)
27 d_printf("Keyname = %s\n", keyname);
28 d_printf("Modtime = %s\n",
29 modtime
30 ? http_timestring(nt_time_to_unix(*modtime))
31 : "None");
32 d_printf("\n");
35 void print_registry_value(const char *valname,
36 const struct registry_value *valvalue)
38 d_printf("Valuename = %s\n", valname);
39 d_printf("Type = %s\n",
40 reg_type_lookup(valvalue->type));
41 switch(valvalue->type) {
42 case REG_DWORD:
43 d_printf("Value = %d\n", valvalue->v.dword);
44 break;
45 case REG_SZ:
46 case REG_EXPAND_SZ:
47 d_printf("Value = \"%s\"\n", valvalue->v.sz.str);
48 break;
49 case REG_MULTI_SZ: {
50 uint32 j;
51 for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
52 d_printf("Value[%3.3d] = \"%s\"\n", j,
53 valvalue->v.multi_sz.strings[j]);
55 break;
57 case REG_BINARY:
58 d_printf("Value = %d bytes\n",
59 (int)valvalue->v.binary.length);
60 break;
61 default:
62 d_printf("Value = <unprintable>\n");
63 break;
65 d_printf("\n");
68 /**
69 * Split path into hive name and subkeyname
70 * normalizations performed:
71 * - convert '/' to '\\'
72 * - strip trailing '\\' chars
74 WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
75 char **subkeyname)
77 char *p;
78 const char *tmp_subkeyname;
80 if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
81 return WERR_INVALID_PARAM;
84 if (strlen(path) == 0) {
85 return WERR_INVALID_PARAM;
88 *hivename = talloc_string_sub(ctx, path, "/", "\\");
89 if (*hivename == NULL) {
90 return WERR_NOMEM;
93 /* strip trailing '\\' chars */
94 p = strrchr(*hivename, '\\');
95 while ((p != NULL) && (p[1] == '\0')) {
96 *p = '\0';
97 p = strrchr(*hivename, '\\');
100 p = strchr(*hivename, '\\');
102 if ((p == NULL) || (*p == '\0')) {
103 /* just the hive - no subkey given */
104 tmp_subkeyname = "";
105 } else {
106 *p = '\0';
107 tmp_subkeyname = p+1;
109 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
110 if (*subkeyname == NULL) {
111 return WERR_NOMEM;
114 return WERR_OK;