s3-dcerpc: Pull packet in the caller, before validation
[Samba.git] / source3 / utils / net_registry_util.c
blob7cbf238aeb95236c3fa41d1a682f5a8155dc14c3
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 "registry.h"
24 #include "utils/net_registry_util.h"
25 #include "utils/net.h"
27 void print_registry_key(const char *keyname, NTTIME *modtime)
29 d_printf(_("Keyname = %s\n"), keyname);
30 d_printf(_("Modtime = %s\n"),
31 modtime
32 ? http_timestring(talloc_tos(), nt_time_to_unix(*modtime))
33 : _("None"));
34 d_printf("\n");
37 void print_registry_value(const struct registry_value *valvalue, bool raw)
39 if (!raw) {
40 d_printf(_("Type = %s\n"),
41 str_regtype(valvalue->type));
43 switch(valvalue->type) {
44 case REG_DWORD: {
45 uint32_t v = 0;
46 if (valvalue->data.length >= 4) {
47 v = IVAL(valvalue->data.data, 0);
49 if (!raw) {
50 d_printf(_("Value = "));
52 d_printf("%d\n", v);
53 break;
55 case REG_SZ:
56 case REG_EXPAND_SZ: {
57 const char *s;
59 if (!pull_reg_sz(talloc_tos(), &valvalue->data, &s)) {
60 break;
62 if (!raw) {
63 d_printf(_("Value = \""));
65 d_printf("%s", s);
66 if (!raw) {
67 d_printf("\"");
69 d_printf("\n");
70 break;
72 case REG_MULTI_SZ: {
73 uint32 j;
74 const char **a;
76 if (!pull_reg_multi_sz(talloc_tos(), &valvalue->data, &a)) {
77 break;
79 for (j = 0; a[j] != NULL; j++) {
80 if (!raw) {
81 d_printf(_("Value[%3.3d] = \""), j);
83 d_printf("%s", a[j]);
84 if (!raw) {
85 d_printf("\"");
87 d_printf("\n");
89 break;
91 case REG_BINARY:
92 if (!raw) {
93 d_printf(_("Value = "));
95 d_printf(_("%d bytes\n"), (int)valvalue->data.length);
96 break;
97 default:
98 if (!raw) {
99 d_printf(_("Value = "));
101 d_printf(_("<unprintable>\n"));
102 break;
106 void print_registry_value_with_name(const char *valname,
107 const struct registry_value *valvalue)
109 d_printf(_("Valuename = %s\n"), valname);
110 print_registry_value(valvalue, false);
111 d_printf("\n");
115 * Split path into hive name and subkeyname
116 * normalizations performed:
117 * - if the path contains no '\\' characters,
118 * assume that the legacy format of using '/'
119 * as a separator is used and convert '/' to '\\'
120 * - strip trailing '\\' chars
122 WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
123 char **subkeyname)
125 char *p;
126 const char *tmp_subkeyname;
128 if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
129 return WERR_INVALID_PARAM;
132 if (strlen(path) == 0) {
133 return WERR_INVALID_PARAM;
136 if (strchr(path, '\\') == NULL) {
137 *hivename = talloc_string_sub(ctx, path, "/", "\\");
138 } else {
139 *hivename = talloc_strdup(ctx, path);
142 if (*hivename == NULL) {
143 return WERR_NOMEM;
146 /* strip trailing '\\' chars */
147 p = strrchr(*hivename, '\\');
148 while ((p != NULL) && (p[1] == '\0')) {
149 *p = '\0';
150 p = strrchr(*hivename, '\\');
153 p = strchr(*hivename, '\\');
155 if ((p == NULL) || (*p == '\0')) {
156 /* just the hive - no subkey given */
157 tmp_subkeyname = "";
158 } else {
159 *p = '\0';
160 tmp_subkeyname = p+1;
162 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
163 if (*subkeyname == NULL) {
164 return WERR_NOMEM;
167 return WERR_OK;