The branch, v3-2-test has been updated via 68d08ecf92be3444b759300237b2b7cf5238d022 (commit) via 61d09caef340d2fee303e429f6f25d011cb3023c (commit) via 3d039b518f04b9dd3c87b9af2ec816e049554e27 (commit) via cc1da3ee2c369181efa6d150c966571d0aff0728 (commit) via 3bf890783fadd245c59280173627a6caca2dbefe (commit) from 2be2188a97060f04c2dea3ca9ed0fd3db0b3df7c (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test - Log ----------------------------------------------------------------- commit 68d08ecf92be3444b759300237b2b7cf5238d022 Author: Michael Adam <[EMAIL PROTECTED]> Date: Fri Apr 4 17:24:53 2008 +0200 net: change split_hive_key() to properly allocate subkeyname instead of returning a pointer into another string. Michael commit 61d09caef340d2fee303e429f6f25d011cb3023c Author: Michael Adam <[EMAIL PROTECTED]> Date: Fri Apr 4 16:46:01 2008 +0200 net_rpc_registry: use split_hive_key to normalize hive befor open. THis allows to specify keys in the form "HKLM/Software/samba", i.e. "/" instead of "\\". Michael commit 3d039b518f04b9dd3c87b9af2ec816e049554e27 Author: Michael Adam <[EMAIL PROTECTED]> Date: Fri Apr 4 13:30:49 2008 +0200 net_rpc_registry: use utility function print_registry_value(). Michael commit cc1da3ee2c369181efa6d150c966571d0aff0728 Author: Michael Adam <[EMAIL PROTECTED]> Date: Fri Apr 4 13:26:03 2008 +0200 net_rpc_registy: use function print_registry_key Michael commit 3bf890783fadd245c59280173627a6caca2dbefe Author: Michael Adam <[EMAIL PROTECTED]> Date: Fri Apr 4 13:21:03 2008 +0200 net_registry: split utility function of common interest out into util module. Michael ----------------------------------------------------------------------- Summary of changes: source/Makefile.in | 1 + source/utils/net_registry.c | 90 +--------------- source/utils/net_registry_util.c | 115 ++++++++++++++++++++ .../transfer_file.h => utils/net_registry_util.h} | 29 +++-- source/utils/net_rpc_registry.c | 105 +++++++----------- 5 files changed, 178 insertions(+), 162 deletions(-) create mode 100644 source/utils/net_registry_util.c copy source/{include/transfer_file.h => utils/net_registry_util.h} (54%) Changeset truncated at 500 lines: diff --git a/source/Makefile.in b/source/Makefile.in index 60f03e4..6846d80 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -844,6 +844,7 @@ NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_help.o \ $(PASSWD_UTIL_OBJ) utils/net_dns.o utils/net_ads_gpo.o \ utils/net_conf.o \ utils/net_registry.o \ + utils/net_registry_util.o \ auth/token_util.o utils/net_dom.o nsswitch/wb_client.o NET_OBJ = $(NET_OBJ1) $(PARAM_WITHOUT_REG_OBJ) $(SECRETS_OBJ) $(LIBSMB_OBJ) \ diff --git a/source/utils/net_registry.c b/source/utils/net_registry.c index 3d24500..8a45dec 100644 --- a/source/utils/net_registry.c +++ b/source/utils/net_registry.c @@ -21,6 +21,7 @@ #include "includes.h" #include "utils/net.h" +#include "utils/net_registry_util.h" /* @@ -29,93 +30,6 @@ * */ -static 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"); -} - -static 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 = <unprintable>\n"); - break; - } - d_printf("\n"); -} - -/** - * Split path into hive name and subkeyname - * normalizations performed: - * - convert '/' to '\\' - * - strip trailing '\\' chars - */ -static 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; -} - /** * split given path into hive and remaining path and open the hive key */ @@ -127,7 +41,7 @@ static WERROR open_hive(TALLOC_CTX *ctx, const char *path, WERROR werr; NT_USER_TOKEN *token = NULL; char *hivename = NULL; - const char *tmp_subkeyname = NULL; + char *tmp_subkeyname = NULL; TALLOC_CTX *tmp_ctx = talloc_stackframe(); if ((hive == NULL) || (subkeyname == NULL)) { diff --git a/source/utils/net_registry_util.c b/source/utils/net_registry_util.c new file mode 100644 index 0000000..948f8b6 --- /dev/null +++ b/source/utils/net_registry_util.c @@ -0,0 +1,115 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ + +#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 = <unprintable>\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, + char **subkeyname) +{ + char *p; + const char *tmp_subkeyname; + + 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 */ + tmp_subkeyname = ""; + } else { + *p = '\0'; + tmp_subkeyname = p+1; + } + *subkeyname = talloc_strdup(ctx, tmp_subkeyname); + if (*subkeyname == NULL) { + return WERR_NOMEM; + } + + return WERR_OK; +} diff --git a/source/include/transfer_file.h b/source/utils/net_registry_util.h similarity index 54% copy from source/include/transfer_file.h copy to source/utils/net_registry_util.h index 79ad9c4..13ec6eb 100644 --- a/source/include/transfer_file.h +++ b/source/utils/net_registry_util.h @@ -1,6 +1,7 @@ /* - * Unix SMB/CIFS implementation. - * Utility functions to transfer files. + * Samba Unix/Linux SMB client library + * Distributed SMB/CIFS Server Management Utility + * registry utility functions * * Copyright (C) Michael Adam 2008 * @@ -18,15 +19,21 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __TRANSFER_FILE_H__ -#define __TRANSFER_FILE_H__ +#ifndef __NET_REGISTRY_UTIL_H__ +#define __NET_REGISTRY_UTIL_H__ -ssize_t transfer_file_internal(void *in_file, - void *out_file, - size_t n, - ssize_t (*read_fn)(void *, void *, size_t), - ssize_t (*write_fn)(void *, const void *, size_t)); +void print_registry_key(const char *keyname, NTTIME *modtime); -SMB_OFF_T transfer_file(int infd, int outfd, SMB_OFF_T n); +void print_registry_value(const char *valname, + const struct registry_value *valvalue); -#endif /* __TRANSFER_FILE_H__ */ +/** + * 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, + char **subkeyname); + +#endif diff --git a/source/utils/net_rpc_registry.c b/source/utils/net_rpc_registry.c index 2d33594..92aaf06 100644 --- a/source/utils/net_rpc_registry.c +++ b/source/utils/net_rpc_registry.c @@ -19,48 +19,60 @@ #include "includes.h" #include "utils/net.h" +#include "utils/net_registry_util.h" #include "regfio.h" #include "reg_objects.h" -static bool reg_hive_key(const char *fullname, uint32 *reg_type, - const char **key_name) +static bool reg_hive_key(TALLOC_CTX *ctx, const char *fullname, + uint32 *reg_type, const char **key_name) { - const char *sep; - ptrdiff_t len; + WERROR werr; + char *hivename = NULL; + char *tmp_keyname = NULL; + bool ret = false; + TALLOC_CTX *tmp_ctx = talloc_stackframe(); - sep = strchr_m(fullname, '\\'); - - if (sep != NULL) { - len = sep - fullname; - *key_name = sep+1; + werr = split_hive_key(tmp_ctx, fullname, &hivename, &tmp_keyname); + if (!W_ERROR_IS_OK(werr)) { + goto done; } - else { - len = strlen(fullname); - *key_name = ""; + + *key_name = talloc_strdup(ctx, tmp_keyname); + if (*key_name == NULL) { + goto done; } - if (strnequal(fullname, "HKLM", len) || - strnequal(fullname, "HKEY_LOCAL_MACHINE", len)) + if (strequal(hivename, "HKLM") || + strequal(hivename, "HKEY_LOCAL_MACHINE")) + { (*reg_type) = HKEY_LOCAL_MACHINE; - else if (strnequal(fullname, "HKCR", len) || - strnequal(fullname, "HKEY_CLASSES_ROOT", len)) + } else if (strequal(hivename, "HKCR") || + strequal(hivename, "HKEY_CLASSES_ROOT")) + { (*reg_type) = HKEY_CLASSES_ROOT; - else if (strnequal(fullname, "HKU", len) || - strnequal(fullname, "HKEY_USERS", len)) + } else if (strequal(hivename, "HKU") || + strequal(hivename, "HKEY_USERS")) + { (*reg_type) = HKEY_USERS; - else if (strnequal(fullname, "HKCU", len) || - strnequal(fullname, "HKEY_CURRENT_USER", len)) + } else if (strequal(hivename, "HKCU") || + strequal(hivename, "HKEY_CURRENT_USER")) + { (*reg_type) = HKEY_CURRENT_USER; - else if (strnequal(fullname, "HKPD", len) || - strnequal(fullname, "HKEY_PERFORMANCE_DATA", len)) + } else if (strequal(hivename, "HKPD") || + strequal(hivename, "HKEY_PERFORMANCE_DATA")) + { (*reg_type) = HKEY_PERFORMANCE_DATA; - else { + } else { DEBUG(10,("reg_hive_key: unrecognised hive key %s\n", fullname)); - return False; + goto done; } - return True; + ret = true; + +done: + TALLOC_FREE(tmp_ctx); + return ret; } static NTSTATUS registry_openkey(TALLOC_CTX *mem_ctx, @@ -75,7 +87,7 @@ static NTSTATUS registry_openkey(TALLOC_CTX *mem_ctx, ZERO_STRUCT(key); - if (!reg_hive_key(name, &hive, &key.name)) { + if (!reg_hive_key(mem_ctx, name, &hive, &key.name)) { return NT_STATUS_INVALID_PARAMETER; } @@ -493,7 +505,7 @@ static NTSTATUS rpc_registry_createkey_internal(const DOM_SID *domain_sid, ZERO_STRUCT(key); ZERO_STRUCT(keyclass); - if (!reg_hive_key(argv[0], &hive, &key.name)) { + if (!reg_hive_key(mem_ctx, argv[0], &hive, &key.name)) { return NT_STATUS_INVALID_PARAMETER; } @@ -561,7 +573,7 @@ static NTSTATUS rpc_registry_deletekey_internal(const DOM_SID *domain_sid, ZERO_STRUCT(key); - if (!reg_hive_key(argv[0], &hive, &key.name)) { + if (!reg_hive_key(mem_ctx, argv[0], &hive, &key.name)) { return NT_STATUS_INVALID_PARAMETER; } @@ -637,11 +649,7 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, } for (i=0; i<num_subkeys; i++) { - d_printf("Keyname = %s\n", names[i]); - d_printf("Modtime = %s\n", modtimes[i] - ? http_timestring(nt_time_to_unix(*modtimes[i])) - : "None"); - d_printf("\n" ); + print_registry_key(names[i], modtimes[i]); } status = registry_enumvalues(mem_ctx, pipe_hnd, &pol_key, &num_values, @@ -653,36 +661,7 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, } for (i=0; i<num_values; i++) { - struct registry_value *v = values[i]; - d_printf("Valuename = %s\n", names[i]); - d_printf("Type = %s\n", - reg_type_lookup(v->type)); - switch(v->type) { - case REG_DWORD: - d_printf("Value = %d\n", v->v.dword); - break; - case REG_SZ: - case REG_EXPAND_SZ: - d_printf("Value = \"%s\"\n", v->v.sz.str); - break; - case REG_MULTI_SZ: { - uint32 j; - for (j = 0; j < v->v.multi_sz.num_strings; j++) { - d_printf("Value[%3.3d] = \"%s\"\n", j, - v->v.multi_sz.strings[j]); - } - break; - } - case REG_BINARY: - d_printf("Value = %d bytes\n", - (int)v->v.binary.length); - break; - default: - d_printf("Value = <unprintable>\n"); - break; - } - - d_printf("\n"); + print_registry_value(names[i], values[i]); } rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key, NULL); -- Samba Shared Repository