source: branches/samba-3.5.x/source3/utils/net_registry_util.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 3.3 KB
Line 
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 "utils/net_registry_util.h"
24#include "utils/net.h"
25
26void print_registry_key(const char *keyname, NTTIME *modtime)
27{
28 d_printf(_("Keyname = %s\n"), keyname);
29 d_printf(_("Modtime = %s\n"),
30 modtime
31 ? http_timestring(talloc_tos(), nt_time_to_unix(*modtime))
32 : _("None"));
33 d_printf("\n");
34}
35
36void print_registry_value(const struct registry_value *valvalue, bool raw)
37{
38 if (!raw) {
39 d_printf(_("Type = %s\n"),
40 reg_type_lookup(valvalue->type));
41 }
42 switch(valvalue->type) {
43 case REG_DWORD:
44 if (!raw) {
45 d_printf(_("Value = "));
46 }
47 d_printf("%d\n", valvalue->v.dword);
48 break;
49 case REG_SZ:
50 case REG_EXPAND_SZ:
51 if (!raw) {
52 d_printf(_("Value = \""));
53 }
54 d_printf("%s", valvalue->v.sz.str);
55 if (!raw) {
56 d_printf("\"");
57 }
58 d_printf("\n");
59 break;
60 case REG_MULTI_SZ: {
61 uint32 j;
62 for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
63 if (!raw) {
64 d_printf(_("Value[%3.3d] = \""), j);
65 }
66 d_printf("%s", valvalue->v.multi_sz.strings[j]);
67 if (!raw) {
68 d_printf("\"");
69 }
70 d_printf("\n");
71 }
72 break;
73 }
74 case REG_BINARY:
75 if (!raw) {
76 d_printf(_("Value = "));
77 }
78 d_printf(_("%d bytes\n"), (int)valvalue->v.binary.length);
79 break;
80 default:
81 if (!raw) {
82 d_printf(_("Value = "));
83 }
84 d_printf(_("<unprintable>\n"));
85 break;
86 }
87}
88
89void print_registry_value_with_name(const char *valname,
90 const struct registry_value *valvalue)
91{
92 d_printf(_("Valuename = %s\n"), valname);
93 print_registry_value(valvalue, false);
94 d_printf("\n");
95}
96
97/**
98 * Split path into hive name and subkeyname
99 * normalizations performed:
100 * - convert '/' to '\\'
101 * - strip trailing '\\' chars
102 */
103WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
104 char **subkeyname)
105{
106 char *p;
107 const char *tmp_subkeyname;
108
109 if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
110 return WERR_INVALID_PARAM;
111 }
112
113 if (strlen(path) == 0) {
114 return WERR_INVALID_PARAM;
115 }
116
117 *hivename = talloc_string_sub(ctx, path, "/", "\\");
118 if (*hivename == NULL) {
119 return WERR_NOMEM;
120 }
121
122 /* strip trailing '\\' chars */
123 p = strrchr(*hivename, '\\');
124 while ((p != NULL) && (p[1] == '\0')) {
125 *p = '\0';
126 p = strrchr(*hivename, '\\');
127 }
128
129 p = strchr(*hivename, '\\');
130
131 if ((p == NULL) || (*p == '\0')) {
132 /* just the hive - no subkey given */
133 tmp_subkeyname = "";
134 } else {
135 *p = '\0';
136 tmp_subkeyname = p+1;
137 }
138 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
139 if (*subkeyname == NULL) {
140 return WERR_NOMEM;
141 }
142
143 return WERR_OK;
144}
Note: See TracBrowser for help on using the repository browser.