Line data Source code
1 : /*
2 : * Samba Unix/Linux SMB client library
3 : * Distributed SMB/CIFS Server Management Utility
4 : * registry utility functions
5 : *
6 : * Copyright (C) Michael Adam 2008
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, see <http://www.gnu.org/licenses/>.
20 : */
21 :
22 : #include "includes.h"
23 : #include "registry.h"
24 : #include "utils/net_registry_util.h"
25 : #include "utils/net.h"
26 : #include "../libcli/registry/util_reg.h"
27 :
28 128 : void print_registry_key(const char *keyname, NTTIME *modtime)
29 : {
30 128 : const char *ts = _("None");
31 128 : char *freeme = NULL;
32 :
33 128 : if (modtime != 0) {
34 128 : freeme = http_timestring(talloc_tos(),
35 : nt_time_to_unix(*modtime));
36 128 : ts = freeme;
37 : }
38 :
39 128 : d_printf(_("Keyname = %s\n"), keyname);
40 128 : d_printf(_("Modtime = %s\n"), ts);
41 128 : d_printf("\n");
42 :
43 128 : TALLOC_FREE(freeme);
44 128 : }
45 :
46 20 : void print_registry_value(const struct registry_value *valvalue, bool raw)
47 : {
48 20 : if (!raw) {
49 8 : d_printf(_("Type = %s\n"),
50 8 : str_regtype(valvalue->type));
51 : }
52 20 : switch(valvalue->type) {
53 8 : case REG_DWORD: {
54 8 : uint32_t v = 0;
55 8 : if (valvalue->data.length >= 4) {
56 8 : v = IVAL(valvalue->data.data, 0);
57 : }
58 8 : if (!raw) {
59 8 : d_printf(_("Value = "));
60 : }
61 8 : d_printf("%u\n", v);
62 8 : break;
63 : }
64 12 : case REG_SZ:
65 : case REG_EXPAND_SZ: {
66 0 : const char *s;
67 :
68 12 : if (!pull_reg_sz(talloc_tos(), &valvalue->data, &s)) {
69 0 : break;
70 : }
71 12 : if (!raw) {
72 0 : d_printf(_("Value = \""));
73 : }
74 12 : d_printf("%s", s);
75 12 : if (!raw) {
76 0 : d_printf("\"");
77 : }
78 12 : d_printf("\n");
79 12 : break;
80 : }
81 0 : case REG_MULTI_SZ: {
82 0 : uint32_t j;
83 0 : const char **a;
84 :
85 0 : if (!pull_reg_multi_sz(talloc_tos(), &valvalue->data, &a)) {
86 0 : break;
87 : }
88 0 : for (j = 0; a[j] != NULL; j++) {
89 0 : if (!raw) {
90 0 : d_printf(_("Value[%3.3d] = \""), j);
91 : }
92 0 : d_printf("%s", a[j]);
93 0 : if (!raw) {
94 0 : d_printf("\"");
95 : }
96 0 : d_printf("\n");
97 : }
98 0 : break;
99 : }
100 0 : case REG_BINARY:
101 0 : if (!raw) {
102 0 : d_printf(_("Value = "));
103 : }
104 0 : d_printf(_("%d bytes\n"), (int)valvalue->data.length);
105 0 : break;
106 0 : default:
107 0 : if (!raw) {
108 0 : d_printf(_("Value = "));
109 : }
110 0 : d_printf(_("<unprintable>\n"));
111 0 : break;
112 : }
113 20 : }
114 :
115 8 : void print_registry_value_with_name(const char *valname,
116 : const struct registry_value *valvalue)
117 : {
118 8 : d_printf(_("Valuename = %s\n"), valname);
119 8 : print_registry_value(valvalue, false);
120 8 : d_printf("\n");
121 8 : }
122 :
123 : /**
124 : * Split path into hive name and subkeyname
125 : * normalizations performed:
126 : * - if the path contains no '\\' characters,
127 : * assume that the legacy format of using '/'
128 : * as a separator is used and convert '/' to '\\'
129 : * - strip trailing '\\' chars
130 : */
131 488 : WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
132 : char **subkeyname)
133 : {
134 0 : char *p;
135 0 : const char *tmp_subkeyname;
136 :
137 488 : if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
138 0 : return WERR_INVALID_PARAMETER;
139 : }
140 :
141 488 : if (strlen(path) == 0) {
142 0 : return WERR_INVALID_PARAMETER;
143 : }
144 :
145 488 : if (strchr(path, '\\') == NULL) {
146 226 : *hivename = talloc_string_sub(ctx, path, "/", "\\");
147 : } else {
148 262 : *hivename = talloc_strdup(ctx, path);
149 : }
150 :
151 488 : if (*hivename == NULL) {
152 0 : return WERR_NOT_ENOUGH_MEMORY;
153 : }
154 :
155 : /* strip trailing '\\' chars */
156 488 : p = strrchr(*hivename, '\\');
157 488 : while ((p != NULL) && (p[1] == '\0')) {
158 0 : *p = '\0';
159 0 : p = strrchr(*hivename, '\\');
160 : }
161 :
162 488 : p = strchr(*hivename, '\\');
163 :
164 488 : if ((p == NULL) || (*p == '\0')) {
165 : /* just the hive - no subkey given */
166 62 : tmp_subkeyname = "";
167 : } else {
168 426 : *p = '\0';
169 426 : tmp_subkeyname = p+1;
170 : }
171 488 : *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
172 488 : if (*subkeyname == NULL) {
173 0 : return WERR_NOT_ENOUGH_MEMORY;
174 : }
175 :
176 488 : return WERR_OK;
177 : }
|