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/>.
24 #include "utils/net_registry_util.h"
25 #include "utils/net.h"
26 #include "../libcli/registry/util_reg.h"
28 void print_registry_key(const char *keyname
, NTTIME
*modtime
)
30 const char *ts
= _("None");
34 freeme
= http_timestring(talloc_tos(),
35 nt_time_to_unix(*modtime
));
39 d_printf(_("Keyname = %s\n"), keyname
);
40 d_printf(_("Modtime = %s\n"), ts
);
46 void print_registry_value(const struct registry_value
*valvalue
, bool raw
)
49 d_printf(_("Type = %s\n"),
50 str_regtype(valvalue
->type
));
52 switch(valvalue
->type
) {
55 if (valvalue
->data
.length
>= 4) {
56 v
= IVAL(valvalue
->data
.data
, 0);
59 d_printf(_("Value = "));
68 if (!pull_reg_sz(talloc_tos(), &valvalue
->data
, &s
)) {
72 d_printf(_("Value = \""));
85 if (!pull_reg_multi_sz(talloc_tos(), &valvalue
->data
, &a
)) {
88 for (j
= 0; a
[j
] != NULL
; j
++) {
90 d_printf(_("Value[%3.3d] = \""), j
);
102 d_printf(_("Value = "));
104 d_printf(_("%d bytes\n"), (int)valvalue
->data
.length
);
108 d_printf(_("Value = "));
110 d_printf(_("<unprintable>\n"));
115 void print_registry_value_with_name(const char *valname
,
116 const struct registry_value
*valvalue
)
118 d_printf(_("Valuename = %s\n"), valname
);
119 print_registry_value(valvalue
, false);
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
131 WERROR
split_hive_key(TALLOC_CTX
*ctx
, const char *path
, char **hivename
,
135 const char *tmp_subkeyname
;
137 if ((path
== NULL
) || (hivename
== NULL
) || (subkeyname
== NULL
)) {
138 return WERR_INVALID_PARAM
;
141 if (strlen(path
) == 0) {
142 return WERR_INVALID_PARAM
;
145 if (strchr(path
, '\\') == NULL
) {
146 *hivename
= talloc_string_sub(ctx
, path
, "/", "\\");
148 *hivename
= talloc_strdup(ctx
, path
);
151 if (*hivename
== NULL
) {
155 /* strip trailing '\\' chars */
156 p
= strrchr(*hivename
, '\\');
157 while ((p
!= NULL
) && (p
[1] == '\0')) {
159 p
= strrchr(*hivename
, '\\');
162 p
= strchr(*hivename
, '\\');
164 if ((p
== NULL
) || (*p
== '\0')) {
165 /* just the hive - no subkey given */
169 tmp_subkeyname
= p
+1;
171 *subkeyname
= talloc_strdup(ctx
, tmp_subkeyname
);
172 if (*subkeyname
== NULL
) {