From 06466de5e9636dc2934c8f52f20d71ed0f4e6da0 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Apr 2008 13:21:03 +0200 Subject: net_registry: split utility function of common interest out into util module. Michael (This used to be commit 3bf890783fadd245c59280173627a6caca2dbefe) --- source3/utils/net_registry_util.c | 110 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 source3/utils/net_registry_util.c (limited to 'source3/utils/net_registry_util.c') diff --git a/source3/utils/net_registry_util.c b/source3/utils/net_registry_util.c new file mode 100644 index 0000000000..b1d0c7765c --- /dev/null +++ b/source3/utils/net_registry_util.c @@ -0,0 +1,110 @@ +/* + * Samba Unix/Linux SMB client library + * Distributed SMB/CIFS Server Management Utility + * registry utility functions + * + * Copyright (C) Michael Adam 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "includes.h" +#include "utils/net_registry_util.h" + +void print_registry_key(const char *keyname, NTTIME *modtime) +{ + d_printf("Keyname = %s\n", keyname); + d_printf("Modtime = %s\n", + modtime + ? http_timestring(nt_time_to_unix(*modtime)) + : "None"); + d_printf("\n"); +} + +void print_registry_value(const char *valname, + const struct registry_value *valvalue) +{ + d_printf("Valuename = %s\n", valname); + d_printf("Type = %s\n", + reg_type_lookup(valvalue->type)); + switch(valvalue->type) { + case REG_DWORD: + d_printf("Value = %d\n", valvalue->v.dword); + break; + case REG_SZ: + case REG_EXPAND_SZ: + d_printf("Value = \"%s\"\n", valvalue->v.sz.str); + break; + case REG_MULTI_SZ: { + uint32 j; + for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) { + d_printf("Value[%3.3d] = \"%s\"\n", j, + valvalue->v.multi_sz.strings[j]); + } + break; + } + case REG_BINARY: + d_printf("Value = %d bytes\n", + (int)valvalue->v.binary.length); + break; + default: + d_printf("Value = \n"); + break; + } + d_printf("\n"); +} + +/** + * Split path into hive name and subkeyname + * normalizations performed: + * - convert '/' to '\\' + * - strip trailing '\\' chars + */ +WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename, + const char **subkeyname) +{ + char *p; + + if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) { + return WERR_INVALID_PARAM; + } + + if (strlen(path) == 0) { + return WERR_INVALID_PARAM; + } + + *hivename = talloc_string_sub(ctx, path, "/", "\\"); + if (*hivename == NULL) { + return WERR_NOMEM; + } + + /* strip trailing '\\' chars */ + p = strrchr(*hivename, '\\'); + while ((p != NULL) && (p[1] == '\0')) { + *p = '\0'; + p = strrchr(*hivename, '\\'); + } + + p = strchr(*hivename, '\\'); + + if ((p == NULL) || (*p == '\0')) { + /* just the hive - no subkey given */ + *subkeyname = ""; + } else { + *p = '\0'; + *subkeyname = p+1; + } + + return WERR_OK; +} -- cgit From ae790f9b89779a0fa1ba4ecfb5b99df160d222fd Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Apr 2008 17:24:53 +0200 Subject: net: change split_hive_key() to properly allocate subkeyname instead of returning a pointer into another string. Michael (This used to be commit 68d08ecf92be3444b759300237b2b7cf5238d022) --- source3/utils/net_registry_util.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_registry_util.c') diff --git a/source3/utils/net_registry_util.c b/source3/utils/net_registry_util.c index b1d0c7765c..948f8b6153 100644 --- a/source3/utils/net_registry_util.c +++ b/source3/utils/net_registry_util.c @@ -72,9 +72,10 @@ void print_registry_value(const char *valname, * - strip trailing '\\' chars */ WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename, - const char **subkeyname) + char **subkeyname) { char *p; + const char *tmp_subkeyname; if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) { return WERR_INVALID_PARAM; @@ -100,10 +101,14 @@ WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename, if ((p == NULL) || (*p == '\0')) { /* just the hive - no subkey given */ - *subkeyname = ""; + tmp_subkeyname = ""; } else { *p = '\0'; - *subkeyname = p+1; + tmp_subkeyname = p+1; + } + *subkeyname = talloc_strdup(ctx, tmp_subkeyname); + if (*subkeyname == NULL) { + return WERR_NOMEM; } return WERR_OK; -- cgit From d3dcaac176212a20c2bb71a08b4ac39ea2689047 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 12:29:34 +0200 Subject: net (registry util): refactor printing of value without name out. This renames print_registry_value() to print_registry_value_with_name(). The new function is called print_registry_value(). Michael (This used to be commit 88c4851ad7240bc4f72a5ef92e21629e6a4c99c6) --- source3/utils/net_registry_util.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_registry_util.c') diff --git a/source3/utils/net_registry_util.c b/source3/utils/net_registry_util.c index 948f8b6153..ca80e60ec3 100644 --- a/source3/utils/net_registry_util.c +++ b/source3/utils/net_registry_util.c @@ -32,10 +32,8 @@ void print_registry_key(const char *keyname, NTTIME *modtime) d_printf("\n"); } -void print_registry_value(const char *valname, - const struct registry_value *valvalue) +void print_registry_value(const struct registry_value *valvalue) { - d_printf("Valuename = %s\n", valname); d_printf("Type = %s\n", reg_type_lookup(valvalue->type)); switch(valvalue->type) { @@ -62,6 +60,13 @@ void print_registry_value(const char *valname, d_printf("Value = \n"); break; } +} + +void print_registry_value_with_name(const char *valname, + const struct registry_value *valvalue) +{ + d_printf("Valuename = %s\n", valname); + print_registry_value(valvalue); d_printf("\n"); } -- cgit From 49835c6d9e5b838484e6e806b80d8acb7ef2ef5a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 15 May 2008 12:55:54 +0200 Subject: net_registry: add raw output of value to print_registry_value(). Michael (This used to be commit 340a706422cbca45cc63fa94d36c88f6751f4f31) --- source3/utils/net_registry_util.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'source3/utils/net_registry_util.c') diff --git a/source3/utils/net_registry_util.c b/source3/utils/net_registry_util.c index ca80e60ec3..278377867a 100644 --- a/source3/utils/net_registry_util.c +++ b/source3/utils/net_registry_util.c @@ -32,32 +32,55 @@ void print_registry_key(const char *keyname, NTTIME *modtime) d_printf("\n"); } -void print_registry_value(const struct registry_value *valvalue) +void print_registry_value(const struct registry_value *valvalue, bool raw) { - d_printf("Type = %s\n", - reg_type_lookup(valvalue->type)); + if (!raw) { + d_printf("Type = %s\n", + reg_type_lookup(valvalue->type)); + } switch(valvalue->type) { case REG_DWORD: - d_printf("Value = %d\n", valvalue->v.dword); + if (!raw) { + d_printf("Value = "); + } + d_printf("%d\n", valvalue->v.dword); break; case REG_SZ: case REG_EXPAND_SZ: - d_printf("Value = \"%s\"\n", valvalue->v.sz.str); + if (!raw) { + d_printf("Value = \""); + } + d_printf("%s", valvalue->v.sz.str); + if (!raw) { + d_printf("\""); + } + d_printf("\n"); break; case REG_MULTI_SZ: { uint32 j; for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) { - d_printf("Value[%3.3d] = \"%s\"\n", j, - valvalue->v.multi_sz.strings[j]); + if (!raw) { + d_printf("Value[%3.3d] = \"", j); + } + d_printf("%s", valvalue->v.multi_sz.strings[j]); + if (!raw) { + d_printf("\""); + } + d_printf("\n"); } break; } case REG_BINARY: - d_printf("Value = %d bytes\n", - (int)valvalue->v.binary.length); + if (!raw) { + d_printf("Value = "); + } + d_printf("%d bytes\n", (int)valvalue->v.binary.length); break; default: - d_printf("Value = \n"); + if (!raw) { + d_printf("Value = "); + } + d_printf("\n"); break; } } @@ -66,7 +89,7 @@ void print_registry_value_with_name(const char *valname, const struct registry_value *valvalue) { d_printf("Valuename = %s\n", valname); - print_registry_value(valvalue); + print_registry_value(valvalue, false); d_printf("\n"); } -- cgit