Author: vlendec Date: 2006-06-24 20:06:01 +0000 (Sat, 24 Jun 2006) New Revision: 16501
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16501 Log: Add a routine reg_pull_multi_sz, make use of it. Get real error msgs for net rpc registry enumerate Add --tallocreport to net Volker Added: trunk/source/lib/util_reg.c Modified: trunk/source/Makefile.in trunk/source/include/rpc_reg.h trunk/source/rpcclient/cmd_spoolss.c trunk/source/utils/net.c trunk/source/utils/net_rpc_printer.c trunk/source/utils/net_rpc_registry.c Changeset: Modified: trunk/source/Makefile.in =================================================================== --- trunk/source/Makefile.in 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/Makefile.in 2006-06-24 20:06:01 UTC (rev 16501) @@ -214,7 +214,7 @@ lib/ufc.o lib/genrand.o lib/username.o \ lib/util_pw.o lib/access.o lib/smbrun.o \ lib/bitmap.o lib/crc32.o $(SNPRINTF_OBJ) lib/dprintf.o \ - lib/xfile.o lib/wins_srv.o \ + lib/xfile.o lib/wins_srv.o lib/util_reg.o \ lib/util_str.o lib/clobber.o lib/util_sid.o lib/util_uuid.o \ lib/util_unistr.o lib/util_file.o lib/data_blob.o \ lib/util.o lib/util_sock.o lib/sock_exec.o lib/util_sec.o \ Modified: trunk/source/include/rpc_reg.h =================================================================== --- trunk/source/include/rpc_reg.h 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/include/rpc_reg.h 2006-06-24 20:06:01 UTC (rev 16501) @@ -86,6 +86,7 @@ #define REG_RESOURCE_LIST 8 #define REG_FULL_RESOURCE_DESCRIPTOR 9 #define REG_RESOURCE_REQUIREMENTS_LIST 10 +#define REG_QWORD 11 /* * Registry key types Added: trunk/source/lib/util_reg.c =================================================================== --- trunk/source/lib/util_reg.c 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/lib/util_reg.c 2006-06-24 20:06:01 UTC (rev 16501) @@ -0,0 +1,119 @@ +/* + * Unix SMB/CIFS implementation. + * Registry helper routines + * Copyright (C) Volker Lendecke 2006 + * + * 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 2 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, write to the Free Software Foundation, Inc., 675 + * Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +const char *reg_type_lookup(uint32 type) +{ + const char *result; + + switch(type) { + case REG_NONE: + result = "REG_NONE"; + break; + case REG_SZ: + result = "REG_SZ"; + break; + case REG_EXPAND_SZ: + result = "REG_EXPAND_SZ"; + break; + case REG_BINARY: + result = "REG_BINARY"; + break; + case REG_DWORD: + result = "REG_DWORD"; + break; + case REG_DWORD_BE: + result = "REG_DWORD_BE"; + break; + case REG_LINK: + result = "REG_LINK"; + break; + case REG_MULTI_SZ: + result = "REG_MULTI_SZ"; + break; + case REG_RESOURCE_LIST: + result = "REG_RESOURCE_LIST"; + break; + case REG_FULL_RESOURCE_DESCRIPTOR: + result = "REG_FULL_RESOURCE_DESCRIPTOR"; + break; + case REG_RESOURCE_REQUIREMENTS_LIST: + result = "REG_RESOURCE_REQUIREMENTS_LIST"; + break; + case REG_QWORD: + result = "REG_QWORD"; + break; + default: + result = "REG TYPE IS UNKNOWN"; + break; + } + return result; +} + +NTSTATUS reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len, + int *num_values, char ***values) +{ + int nvals; + char **vals; + const smb_ucs2_t *p = buf; + TALLOC_CTX *tmp_ctx; + NTSTATUS result = NT_STATUS_NO_MEMORY; + + if (!(tmp_ctx = talloc_new(mem_ctx))) { + return NT_STATUS_NO_MEMORY; + } + + nvals = 0; + vals = NULL; + + len /= 2; /* buf is a set of UCS2 strings */ + + while (len > 0) { + char *val; + size_t dstlen, thislen; + + thislen = strnlen_w(p, len) + 1; + dstlen = convert_string_allocate(tmp_ctx, CH_UCS2, CH_UNIX, + p, thislen*2, (void *)&val, + True); + if (dstlen == (size_t)-1) { + goto done; + } + + ADD_TO_ARRAY(tmp_ctx, char *, val, &vals, &nvals); + if (vals == NULL) { + goto done; + } + + talloc_steal(vals, val); + + p += thislen; + len -= thislen; + } + + *num_values = nvals; + *values = talloc_steal(mem_ctx, vals); + result = NT_STATUS_OK; + + done: + TALLOC_FREE(tmp_ctx); + return result; +} Modified: trunk/source/rpcclient/cmd_spoolss.c =================================================================== --- trunk/source/rpcclient/cmd_spoolss.c 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/rpcclient/cmd_spoolss.c 2006-06-24 20:06:01 UTC (rev 16501) @@ -709,17 +709,23 @@ break; } case REG_MULTI_SZ: { - uint16 *curstr = (uint16 *) value.data_p; - uint8 *start = value.data_p; - printf("%s: REG_MULTI_SZ:\n", value.valuename); - while (((uint8 *) curstr < start + value.size)) { - rpcstr_pull(text, curstr, sizeof(text), -1, - STR_TERMINATE); - printf(" %s\n", *text != 0 ? text : "NULL"); - curstr += strlen(text) + 1; + int i, num_values; + char **values; + + if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, value.data_p, + value.size, + &num_values, + &values))) { + d_printf("reg_pull_multi_sz failed\n"); + break; } + + for (i=0; i<num_values; i++) { + d_printf("%s\n", values[i]); + } + TALLOC_FREE(values); + break; } - break; default: printf("%s: unknown type %d\n", value.valuename, value.type); } Modified: trunk/source/utils/net.c =================================================================== --- trunk/source/utils/net.c 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/utils/net.c 2006-06-24 20:06:01 UTC (rev 16501) @@ -852,6 +852,7 @@ int argc_new = 0; const char ** argv_new; poptContext pc; + BOOL do_talloc_report=False; struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, 'h'}, @@ -884,6 +885,7 @@ {"timestamps", 0, POPT_ARG_NONE, &opt_timestamps}, {"exclude", 'e', POPT_ARG_STRING, &opt_exclude}, {"destination", 0, POPT_ARG_STRING, &opt_destination}, + {"tallocreport", 0, POPT_ARG_NONE, &do_talloc_report}, POPT_COMMON_SAMBA { 0, 0, 0, 0} @@ -947,6 +949,10 @@ } } + if (do_talloc_report) { + talloc_enable_leak_report(); + } + if (opt_requester_name) { set_global_myname(opt_requester_name); } Modified: trunk/source/utils/net_rpc_printer.c =================================================================== --- trunk/source/utils/net_rpc_printer.c 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/utils/net_rpc_printer.c 2006-06-24 20:06:01 UTC (rev 16501) @@ -129,18 +129,23 @@ break; case REG_MULTI_SZ: { - uint16 *curstr = (uint16 *) value.data_p; - uint8 *start = value.data_p; - d_printf("\t[%s:%s]: REG_MULTI_SZ:\n", subkey, value.valuename); - while ((*curstr != 0) && - ((uint8 *) curstr < start + value.size)) { - rpcstr_pull(text, curstr, sizeof(text), -1, - STR_TERMINATE); - d_printf("%s\n", text); - curstr += strlen(text) + 1; + int i, num_values; + char **values; + + if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, value.data_p, + value.size, + &num_values, + &values))) { + d_printf("reg_pull_multi_sz failed\n"); + break; } + + for (i=0; i<num_values; i++) { + d_printf("%s\n", values[i]); + } + TALLOC_FREE(values); + break; } - break; default: d_printf("\t%s: unknown type %d\n", value.valuename, value.type); Modified: trunk/source/utils/net_rpc_registry.c =================================================================== --- trunk/source/utils/net_rpc_registry.c 2006-06-24 19:29:10 UTC (rev 16500) +++ trunk/source/utils/net_rpc_registry.c 2006-06-24 20:06:01 UTC (rev 16501) @@ -25,35 +25,6 @@ /******************************************************************** ********************************************************************/ -char* dump_regval_type( uint32 type ) -{ - static fstring string; - - switch (type) { - case REG_SZ: - fstrcpy( string, "REG_SZ" ); - break; - case REG_MULTI_SZ: - fstrcpy( string, "REG_MULTI_SZ" ); - break; - case REG_EXPAND_SZ: - fstrcpy( string, "REG_EXPAND_SZ" ); - break; - case REG_DWORD: - fstrcpy( string, "REG_DWORD" ); - break; - case REG_BINARY: - fstrcpy( string, "REG_BINARY" ); - break; - default: - fstr_sprintf( string, "UNKNOWN [%d]", type ); - } - - return string; -} -/******************************************************************** -********************************************************************/ - void dump_regval_buffer( uint32 type, REGVAL_BUFFER *buffer ) { pstring string; @@ -64,9 +35,26 @@ rpcstr_pull( string, buffer->buffer, sizeof(string), -1, STR_TERMINATE ); d_printf("%s\n", string); break; - case REG_MULTI_SZ: + case REG_MULTI_SZ: { + int i, num_values; + char **values; + d_printf("\n"); + + if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, buffer->buffer, + buffer->buf_len, + &num_values, + &values))) { + d_printf("reg_pull_multi_sz failed\n"); + break; + } + + for (i=0; i<num_values; i++) { + d_printf("%s\n", values[i]); + } + TALLOC_FREE(values); break; + } case REG_DWORD: value = IVAL( buffer->buffer, 0 ); d_printf( "0x%x\n", value ); @@ -113,14 +101,16 @@ result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive ); if ( !W_ERROR_IS_OK(result) ) { - d_fprintf(stderr, "Unable to connect to remote registry\n"); + d_fprintf(stderr, "Unable to connect to remote registry: " + "%s\n", dos_errstr(result)); return werror_to_ntstatus(result); } result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key ); if ( !W_ERROR_IS_OK(result) ) { - d_fprintf(stderr, "Unable to open [%s]\n", argv[0]); + d_fprintf(stderr, "Unable to open [%s]: %s\n", argv[0], + dos_errstr(result)); return werror_to_ntstatus(result); } @@ -172,7 +162,7 @@ } d_printf("Valuename = %s\n", name ); - d_printf("Type = %s\n", dump_regval_type(type) ); + d_printf("Type = %s\n", reg_type_lookup(type)); d_printf("Data = " ); dump_regval_buffer( type, &value ); d_printf("\n" ); @@ -278,7 +268,7 @@ for ( i=0; i<nk->num_values; i++ ) { d_printf( "\"%s\" = ", nk->values[i].valuename ? nk->values[i].valuename : "(default)" ); - d_printf( "(%s) ", dump_regval_type( nk->values[i].type ) ); + d_printf( "(%s) ", reg_type_lookup( nk->values[i].type ) ); data_size = nk->values[i].data_size & ~VK_DATA_IN_OFFSET; switch ( nk->values[i].type ) {
