2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
5 Copyright (C) Gerald (Jerry) Carter 2005-2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "utils/net.h"
24 #include "reg_objects.h"
26 static BOOL
reg_hive_key(const char *fullname
, uint32
*reg_type
,
27 const char **key_name
)
32 sep
= strchr_m(fullname
, '\\');
39 len
= strlen(fullname
);
43 if (strnequal(fullname
, "HKLM", len
) ||
44 strnequal(fullname
, "HKEY_LOCAL_MACHINE", len
))
45 (*reg_type
) = HKEY_LOCAL_MACHINE
;
46 else if (strnequal(fullname
, "HKCR", len
) ||
47 strnequal(fullname
, "HKEY_CLASSES_ROOT", len
))
48 (*reg_type
) = HKEY_CLASSES_ROOT
;
49 else if (strnequal(fullname
, "HKU", len
) ||
50 strnequal(fullname
, "HKEY_USERS", len
))
51 (*reg_type
) = HKEY_USERS
;
52 else if (strnequal(fullname
, "HKPD", len
) ||
53 strnequal(fullname
, "HKEY_PERFORMANCE_DATA", len
))
54 (*reg_type
) = HKEY_PERFORMANCE_DATA
;
56 DEBUG(10,("reg_hive_key: unrecognised hive key %s\n",
64 static NTSTATUS
registry_openkey(TALLOC_CTX
*mem_ctx
,
65 struct rpc_pipe_client
*pipe_hnd
,
66 const char *name
, uint32 access_mask
,
67 struct policy_handle
*hive_hnd
,
68 struct policy_handle
*key_hnd
)
72 struct winreg_String key
;
74 if (!reg_hive_key(name
, &hive
, &key
.name
)) {
75 return NT_STATUS_INVALID_PARAMETER
;
78 status
= rpccli_winreg_Connect(pipe_hnd
, mem_ctx
, hive
, access_mask
,
80 if (!(NT_STATUS_IS_OK(status
))) {
84 status
= rpccli_winreg_OpenKey(pipe_hnd
, mem_ctx
, hive_hnd
, key
, 0,
85 access_mask
, key_hnd
);
86 if (!(NT_STATUS_IS_OK(status
))) {
87 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, hive_hnd
);
94 static NTSTATUS
registry_enumkeys(TALLOC_CTX
*ctx
,
95 struct rpc_pipe_client
*pipe_hnd
,
96 struct policy_handle
*key_hnd
,
97 uint32
*pnum_keys
, char ***pnames
,
98 char ***pclasses
, NTTIME
***pmodtimes
)
102 uint32 num_subkeys
, max_subkeylen
, max_classlen
;
103 uint32 num_values
, max_valnamelen
, max_valbufsize
;
105 NTTIME last_changed_time
;
107 struct winreg_String classname
;
108 char **names
, **classes
;
111 if (!(mem_ctx
= talloc_new(ctx
))) {
112 return NT_STATUS_NO_MEMORY
;
115 ZERO_STRUCT(classname
);
116 status
= rpccli_winreg_QueryInfoKey(
117 pipe_hnd
, mem_ctx
, key_hnd
, &classname
, &num_subkeys
,
118 &max_subkeylen
, &max_classlen
, &num_values
, &max_valnamelen
,
119 &max_valbufsize
, &secdescsize
, &last_changed_time
);
121 if (!NT_STATUS_IS_OK(status
)) {
125 if (num_subkeys
== 0) {
127 TALLOC_FREE(mem_ctx
);
131 if ((!(names
= TALLOC_ZERO_ARRAY(mem_ctx
, char *, num_subkeys
))) ||
132 (!(classes
= TALLOC_ZERO_ARRAY(mem_ctx
, char *, num_subkeys
))) ||
133 (!(modtimes
= TALLOC_ZERO_ARRAY(mem_ctx
, NTTIME
*,
135 status
= NT_STATUS_NO_MEMORY
;
139 for (i
=0; i
<num_subkeys
; i
++) {
141 struct winreg_StringBuf class_buf
;
142 struct winreg_StringBuf
*pclass_buf
= &class_buf
;
143 struct winreg_StringBuf name_buf
;
145 NTTIME
*pmodtime
= &modtime
;
149 class_buf
.size
= max_classlen
+2;
153 name_buf
.size
= max_subkeylen
+2;
155 ZERO_STRUCT(modtime
);
157 status
= rpccli_winreg_EnumKey(pipe_hnd
, mem_ctx
, key_hnd
,
158 i
, &name_buf
, &pclass_buf
,
161 if (W_ERROR_EQUAL(ntstatus_to_werror(status
),
162 WERR_NO_MORE_ITEMS
) ) {
163 status
= NT_STATUS_OK
;
166 if (!NT_STATUS_IS_OK(status
)) {
173 (!(classes
[i
] = talloc_strdup(classes
,
174 pclass_buf
->name
)))) {
175 status
= NT_STATUS_NO_MEMORY
;
179 if (!(names
[i
] = talloc_strdup(names
, name_buf
.name
))) {
180 status
= NT_STATUS_NO_MEMORY
;
185 (!(modtimes
[i
] = (NTTIME
*)talloc_memdup(
186 modtimes
, pmodtime
, sizeof(*pmodtime
))))) {
187 status
= NT_STATUS_NO_MEMORY
;
192 *pnum_keys
= num_subkeys
;
195 *pnames
= talloc_move(ctx
, &names
);
198 *pclasses
= talloc_move(ctx
, &classes
);
201 *pmodtimes
= talloc_move(ctx
, &modtimes
);
204 status
= NT_STATUS_OK
;
207 TALLOC_FREE(mem_ctx
);
211 static NTSTATUS
registry_pull_value(TALLOC_CTX
*mem_ctx
,
212 struct registry_value
**pvalue
,
213 enum winreg_Type type
, uint8
*data
,
214 uint32 size
, uint32 length
)
216 struct registry_value
*value
;
219 if (!(value
= TALLOC_ZERO_P(mem_ctx
, struct registry_value
))) {
220 return NT_STATUS_NO_MEMORY
;
227 if ((size
!= 4) || (length
!= 4)) {
228 status
= NT_STATUS_INVALID_PARAMETER
;
231 value
->v
.dword
= IVAL(data
, 0);
237 * Make sure we get a NULL terminated string for
238 * convert_string_talloc().
242 uint32 num_ucs2
= length
/ 2;
244 if ((length
% 2) != 0) {
245 status
= NT_STATUS_INVALID_PARAMETER
;
249 if (!(tmp
= SMB_MALLOC_ARRAY(smb_ucs2_t
, num_ucs2
+1))) {
250 status
= NT_STATUS_NO_MEMORY
;
254 memcpy((void *)tmp
, (const void *)data
, length
);
257 value
->v
.sz
.len
= convert_string_talloc(
258 value
, CH_UTF16LE
, CH_UNIX
, tmp
, length
+2,
259 &value
->v
.sz
.str
, False
);
263 if (value
->v
.sz
.len
== (size_t)-1) {
264 status
= NT_STATUS_INVALID_PARAMETER
;
270 status
= reg_pull_multi_sz(value
, (void *)data
, length
,
271 &value
->v
.multi_sz
.num_strings
,
272 &value
->v
.multi_sz
.strings
);
273 if (!(NT_STATUS_IS_OK(status
))) {
278 value
->v
.binary
.data
= talloc_move(value
, &data
);
279 value
->v
.binary
.length
= length
;
282 status
= NT_STATUS_INVALID_PARAMETER
;
294 static NTSTATUS
registry_push_value(TALLOC_CTX
*mem_ctx
,
295 const struct registry_value
*value
,
298 switch (value
->type
) {
301 SIVAL(buf
, 0, value
->v
.dword
);
302 *presult
= data_blob_talloc(mem_ctx
, (void *)buf
, 4);
303 if (presult
->data
== NULL
) {
304 return NT_STATUS_NO_MEMORY
;
309 case REG_EXPAND_SZ
: {
310 presult
->length
= convert_string_talloc(
311 mem_ctx
, CH_UNIX
, CH_UTF16LE
, value
->v
.sz
.str
,
312 MIN(value
->v
.sz
.len
, strlen(value
->v
.sz
.str
)+1),
313 (void *)&(presult
->data
), False
);
314 if (presult
->length
== (size_t)-1) {
315 return NT_STATUS_NO_MEMORY
;
320 return NT_STATUS_INVALID_PARAMETER
;
326 static NTSTATUS
registry_enumvalues(TALLOC_CTX
*ctx
,
327 struct rpc_pipe_client
*pipe_hnd
,
328 struct policy_handle
*key_hnd
,
329 uint32
*pnum_values
, char ***pvalnames
,
330 struct registry_value
***pvalues
)
334 uint32 num_subkeys
, max_subkeylen
, max_classlen
;
335 uint32 num_values
, max_valnamelen
, max_valbufsize
;
337 NTTIME last_changed_time
;
339 struct winreg_String classname
;
340 struct registry_value
**values
;
343 if (!(mem_ctx
= talloc_new(ctx
))) {
344 return NT_STATUS_NO_MEMORY
;
347 ZERO_STRUCT(classname
);
348 status
= rpccli_winreg_QueryInfoKey(
349 pipe_hnd
, mem_ctx
, key_hnd
, &classname
, &num_subkeys
,
350 &max_subkeylen
, &max_classlen
, &num_values
, &max_valnamelen
,
351 &max_valbufsize
, &secdescsize
, &last_changed_time
);
353 if (!NT_STATUS_IS_OK(status
)) {
357 if (num_values
== 0) {
359 TALLOC_FREE(mem_ctx
);
363 if ((!(names
= TALLOC_ARRAY(mem_ctx
, char *, num_values
))) ||
364 (!(values
= TALLOC_ARRAY(mem_ctx
, struct registry_value
*,
366 status
= NT_STATUS_NO_MEMORY
;
370 for (i
=0; i
<num_values
; i
++) {
371 enum winreg_Type type
= REG_NONE
;
372 enum winreg_Type
*ptype
= &type
;
377 uint32
*pdata_size
= &data_size
;
380 uint32
*pvalue_length
= &value_length
;
383 struct winreg_StringBuf name_buf
;
387 name_buf
.size
= max_valnamelen
+ 2;
389 data_size
= max_valbufsize
;
392 status
= rpccli_winreg_EnumValue(pipe_hnd
, mem_ctx
, key_hnd
,
393 i
, &name_buf
, &ptype
,
397 if ( W_ERROR_EQUAL(ntstatus_to_werror(status
),
398 WERR_NO_MORE_ITEMS
) ) {
399 status
= NT_STATUS_OK
;
403 if (!(NT_STATUS_IS_OK(status
))) {
407 if ((name_buf
.name
== NULL
) || (ptype
== NULL
) ||
408 (data
== NULL
) || (pdata_size
== 0) ||
409 (pvalue_length
== NULL
)) {
410 status
= NT_STATUS_INVALID_PARAMETER
;
414 if (!(names
[i
] = talloc_strdup(names
, name_buf
.name
))) {
415 status
= NT_STATUS_NO_MEMORY
;
419 status
= registry_pull_value(values
, &values
[i
], *ptype
, data
,
420 *pdata_size
, *pvalue_length
);
421 if (!(NT_STATUS_IS_OK(status
))) {
426 *pnum_values
= num_values
;
429 *pvalnames
= talloc_move(ctx
, &names
);
432 *pvalues
= talloc_move(ctx
, &values
);
435 status
= NT_STATUS_OK
;
438 TALLOC_FREE(mem_ctx
);
442 static NTSTATUS
registry_setvalue(TALLOC_CTX
*mem_ctx
,
443 struct rpc_pipe_client
*pipe_hnd
,
444 struct policy_handle
*key_hnd
,
446 const struct registry_value
*value
)
448 struct winreg_String name_string
;
452 result
= registry_push_value(mem_ctx
, value
, &blob
);
453 if (!NT_STATUS_IS_OK(result
)) {
457 name_string
.name
= name
;
458 result
= rpccli_winreg_SetValue(pipe_hnd
, blob
.data
, key_hnd
,
459 name_string
, value
->type
,
460 blob
.data
, blob
.length
);
461 TALLOC_FREE(blob
.data
);
465 static NTSTATUS
rpc_registry_setvalue_internal(const DOM_SID
*domain_sid
,
466 const char *domain_name
,
467 struct cli_state
*cli
,
468 struct rpc_pipe_client
*pipe_hnd
,
473 struct policy_handle hive_hnd
, key_hnd
;
475 struct registry_value value
;
478 d_fprintf(stderr
, "usage: net rpc registry setvalue <key> "
479 "<valuename> <type> [<val>]+\n");
480 return NT_STATUS_INVALID_PARAMETER
;
483 status
= registry_openkey(mem_ctx
, pipe_hnd
, argv
[0], REG_KEY_WRITE
,
484 &hive_hnd
, &key_hnd
);
485 if (!NT_STATUS_IS_OK(status
)) {
486 d_fprintf(stderr
, "registry_openkey failed: %s\n",
491 if (!strequal(argv
[2], "multi_sz") && (argc
!= 4)) {
492 d_fprintf(stderr
, "Too many args for type %s\n", argv
[2]);
493 return NT_STATUS_NOT_IMPLEMENTED
;
496 if (strequal(argv
[2], "dword")) {
497 value
.type
= REG_DWORD
;
498 value
.v
.dword
= strtoul(argv
[3], NULL
, 10);
500 else if (strequal(argv
[2], "sz")) {
502 value
.v
.sz
.len
= strlen(argv
[3])+1;
503 value
.v
.sz
.str
= CONST_DISCARD(char *, argv
[3]);
506 d_fprintf(stderr
, "type \"%s\" not implemented\n", argv
[3]);
507 status
= NT_STATUS_NOT_IMPLEMENTED
;
511 status
= registry_setvalue(mem_ctx
, pipe_hnd
, &key_hnd
,
514 if (!NT_STATUS_IS_OK(status
)) {
515 d_fprintf(stderr
, "registry_setvalue failed: %s\n",
520 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, &key_hnd
);
521 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, &hive_hnd
);
526 static int rpc_registry_setvalue( int argc
, const char **argv
)
528 return run_rpc_command( NULL
, PI_WINREG
, 0,
529 rpc_registry_setvalue_internal
, argc
, argv
);
532 /********************************************************************
533 ********************************************************************/
535 static NTSTATUS
rpc_registry_enumerate_internal(const DOM_SID
*domain_sid
,
536 const char *domain_name
,
537 struct cli_state
*cli
,
538 struct rpc_pipe_client
*pipe_hnd
,
543 WERROR result
= WERR_GENERAL_FAILURE
;
546 POLICY_HND pol_hive
, pol_key
;
548 struct winreg_String subkeyname
;
551 char **names
, **classes
;
554 struct registry_value
**values
;
557 d_printf("Usage: net rpc enumerate <path> [recurse]\n");
558 d_printf("Example: net rpc enumerate 'HKLM\\Software\\Samba'\n");
562 if ( !reg_split_hive( argv
[0], &hive
, subpath
) ) {
563 d_fprintf(stderr
, "invalid registry path\n");
567 /* open the top level hive and then the registry key */
569 status
= rpccli_winreg_Connect(pipe_hnd
, mem_ctx
, hive
, MAXIMUM_ALLOWED_ACCESS
, &pol_hive
);
570 if ( !NT_STATUS_IS_OK(status
) ) {
571 d_fprintf(stderr
, "Unable to connect to remote registry: "
572 "%s\n", nt_errstr(status
));
576 subkeyname
.name
= subpath
;
577 status
= rpccli_winreg_OpenKey(pipe_hnd
, mem_ctx
, &pol_hive
, subkeyname
,
578 0, MAXIMUM_ALLOWED_ACCESS
, &pol_key
);
579 if ( !NT_STATUS_IS_OK(status
) ) {
580 d_fprintf(stderr
, "Unable to open [%s]: %s\n", argv
[0],
582 return werror_to_ntstatus(result
);
585 status
= registry_enumkeys(mem_ctx
, pipe_hnd
, &pol_key
, &num_subkeys
,
586 &names
, &classes
, &modtimes
);
587 if (!NT_STATUS_IS_OK(status
)) {
588 d_fprintf(stderr
, "enumerating keys failed: %s\n",
593 for (i
=0; i
<num_subkeys
; i
++) {
594 d_printf("Keyname = %s\n", names
[i
]);
595 d_printf("Modtime = %s\n", modtimes
[i
]
596 ? http_timestring(nt_time_to_unix(*modtimes
[i
]))
601 status
= registry_enumvalues(mem_ctx
, pipe_hnd
, &pol_key
, &num_values
,
603 if (!NT_STATUS_IS_OK(status
)) {
604 d_fprintf(stderr
, "enumerating values failed: %s\n",
609 for (i
=0; i
<num_values
; i
++) {
610 struct registry_value
*v
= values
[i
];
611 d_printf("Valuename = %s\n", names
[i
]);
612 d_printf("Type = %s\n",
613 reg_type_lookup(v
->type
));
616 d_printf("Value = %d\n", v
->v
.dword
);
620 d_printf("Value = \"%s\"\n", v
->v
.sz
.str
);
624 for (j
= 0; j
< v
->v
.multi_sz
.num_strings
; j
++) {
625 d_printf("Value[%3.3d] = \"%s\"\n", j
,
626 v
->v
.multi_sz
.strings
[j
]);
631 d_printf("Value = %d bytes\n",
635 d_printf("Value = <unprintable>\n");
642 if ( strlen( subpath
) != 0 )
643 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, &pol_key
);
644 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, &pol_hive
);
649 /********************************************************************
650 ********************************************************************/
652 static int rpc_registry_enumerate( int argc
, const char **argv
)
654 return run_rpc_command( NULL
, PI_WINREG
, 0,
655 rpc_registry_enumerate_internal
, argc
, argv
);
658 /********************************************************************
659 ********************************************************************/
661 static NTSTATUS
rpc_registry_save_internal(const DOM_SID
*domain_sid
,
662 const char *domain_name
,
663 struct cli_state
*cli
,
664 struct rpc_pipe_client
*pipe_hnd
,
669 WERROR result
= WERR_GENERAL_FAILURE
;
672 POLICY_HND pol_hive
, pol_key
;
673 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
674 struct winreg_String subkeyname
;
675 struct winreg_String filename
;
678 d_printf("Usage: net rpc backup <path> <file> \n");
682 if ( !reg_split_hive( argv
[0], &hive
, subpath
) ) {
683 d_fprintf(stderr
, "invalid registry path\n");
687 /* open the top level hive and then the registry key */
689 status
= rpccli_winreg_Connect(pipe_hnd
, mem_ctx
, hive
, MAXIMUM_ALLOWED_ACCESS
, &pol_hive
);
690 if ( !NT_STATUS_IS_OK(status
) ) {
691 d_fprintf(stderr
, "Unable to connect to remote registry\n");
695 subkeyname
.name
= subpath
;
696 status
= rpccli_winreg_OpenKey(pipe_hnd
, mem_ctx
, &pol_hive
, subkeyname
,
697 0, MAXIMUM_ALLOWED_ACCESS
, &pol_key
);
698 if ( !NT_STATUS_IS_OK(status
) ) {
699 d_fprintf(stderr
, "Unable to open [%s]\n", argv
[0]);
700 return werror_to_ntstatus(result
);
703 filename
.name
= argv
[1];
704 status
= rpccli_winreg_SaveKey( pipe_hnd
, mem_ctx
, &pol_key
, &filename
, NULL
);
705 if ( !W_ERROR_IS_OK(result
) ) {
706 d_fprintf(stderr
, "Unable to save [%s] to %s:%s\n", argv
[0], cli
->desthost
, argv
[1]);
711 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, &pol_key
);
712 rpccli_winreg_CloseKey(pipe_hnd
, mem_ctx
, &pol_hive
);
717 /********************************************************************
718 ********************************************************************/
720 static int rpc_registry_save( int argc
, const char **argv
)
722 return run_rpc_command( NULL
, PI_WINREG
, 0,
723 rpc_registry_save_internal
, argc
, argv
);
727 /********************************************************************
728 ********************************************************************/
730 static void dump_values( REGF_NK_REC
*nk
)
734 uint32 data_size
, data
;
739 for ( i
=0; i
<nk
->num_values
; i
++ ) {
740 d_printf( "\"%s\" = ", nk
->values
[i
].valuename
? nk
->values
[i
].valuename
: "(default)" );
741 d_printf( "(%s) ", reg_type_lookup( nk
->values
[i
].type
) );
743 data_size
= nk
->values
[i
].data_size
& ~VK_DATA_IN_OFFSET
;
744 switch ( nk
->values
[i
].type
) {
746 rpcstr_pull( data_str
, nk
->values
[i
].data
, sizeof(data_str
), -1, STR_TERMINATE
);
747 d_printf( "%s", data_str
);
751 for ( j
=0; j
<data_size
; j
++ ) {
752 d_printf( "%c", nk
->values
[i
].data
[j
] );
756 data
= IVAL( nk
->values
[i
].data
, 0 );
757 d_printf("0x%x", data
);
760 for ( j
=0; j
<data_size
; j
++ ) {
761 d_printf( "%x", nk
->values
[i
].data
[j
] );
774 /********************************************************************
775 ********************************************************************/
777 static BOOL
dump_registry_tree( REGF_FILE
*file
, REGF_NK_REC
*nk
, const char *parent
)
782 /* depth first dump of the registry tree */
784 while ( (key
= regfio_fetch_subkey( file
, nk
)) ) {
785 pstr_sprintf( regpath
, "%s\\%s", parent
, key
->keyname
);
786 d_printf("[%s]\n", regpath
);
789 dump_registry_tree( file
, key
, regpath
);
795 /********************************************************************
796 ********************************************************************/
798 static BOOL
write_registry_tree( REGF_FILE
*infile
, REGF_NK_REC
*nk
,
799 REGF_NK_REC
*parent
, REGF_FILE
*outfile
,
800 const char *parentpath
)
802 REGF_NK_REC
*key
, *subkey
;
804 REGSUBKEY_CTR
*subkeys
;
808 if ( !( subkeys
= TALLOC_ZERO_P( infile
->mem_ctx
, REGSUBKEY_CTR
)) ) {
809 DEBUG(0,("write_registry_tree: talloc() failed!\n"));
813 if ( !(values
= TALLOC_ZERO_P( subkeys
, REGVAL_CTR
)) ) {
814 DEBUG(0,("write_registry_tree: talloc() failed!\n"));
818 /* copy values into the REGVAL_CTR */
820 for ( i
=0; i
<nk
->num_values
; i
++ ) {
821 regval_ctr_addvalue( values
, nk
->values
[i
].valuename
, nk
->values
[i
].type
,
822 (const char *)nk
->values
[i
].data
, (nk
->values
[i
].data_size
& ~VK_DATA_IN_OFFSET
) );
825 /* copy subkeys into the REGSUBKEY_CTR */
827 while ( (subkey
= regfio_fetch_subkey( infile
, nk
)) ) {
828 regsubkey_ctr_addkey( subkeys
, subkey
->keyname
);
831 key
= regfio_write_key( outfile
, nk
->keyname
, values
, subkeys
, nk
->sec_desc
->sec_desc
, parent
);
833 /* write each one of the subkeys out */
835 pstr_sprintf( path
, "%s%s%s", parentpath
, parent
? "\\" : "", nk
->keyname
);
836 nk
->subkey_index
= 0;
837 while ( (subkey
= regfio_fetch_subkey( infile
, nk
)) ) {
838 write_registry_tree( infile
, subkey
, key
, outfile
, path
);
841 TALLOC_FREE( subkeys
);
843 d_printf("[%s]\n", path
);
848 /********************************************************************
849 ********************************************************************/
851 static int rpc_registry_dump( int argc
, const char **argv
)
857 d_printf("Usage: net rpc dump <file> \n");
861 d_printf("Opening %s....", argv
[0]);
862 if ( !(registry
= regfio_open( argv
[0], O_RDONLY
, 0)) ) {
863 d_fprintf(stderr
, "Failed to open %s for reading\n", argv
[0]);
868 /* get the root of the registry file */
870 if ((nk
= regfio_rootkey( registry
)) == NULL
) {
871 d_fprintf(stderr
, "Could not get rootkey\n");
872 regfio_close( registry
);
875 d_printf("[%s]\n", nk
->keyname
);
879 dump_registry_tree( registry
, nk
, nk
->keyname
);
882 talloc_report_full( registry
->mem_ctx
, stderr
);
884 d_printf("Closing registry...");
885 regfio_close( registry
);
891 /********************************************************************
892 ********************************************************************/
894 static int rpc_registry_copy( int argc
, const char **argv
)
896 REGF_FILE
*infile
= NULL
, *outfile
= NULL
;
901 d_printf("Usage: net rpc copy <srcfile> <newfile>\n");
905 d_printf("Opening %s....", argv
[0]);
906 if ( !(infile
= regfio_open( argv
[0], O_RDONLY
, 0 )) ) {
907 d_fprintf(stderr
, "Failed to open %s for reading\n", argv
[0]);
912 d_printf("Opening %s....", argv
[1]);
913 if ( !(outfile
= regfio_open( argv
[1], (O_RDWR
|O_CREAT
|O_TRUNC
), (S_IREAD
|S_IWRITE
) )) ) {
914 d_fprintf(stderr
, "Failed to open %s for writing\n", argv
[1]);
919 /* get the root of the registry file */
921 if ((nk
= regfio_rootkey( infile
)) == NULL
) {
922 d_fprintf(stderr
, "Could not get rootkey\n");
925 d_printf("RootKey: [%s]\n", nk
->keyname
);
927 write_registry_tree( infile
, nk
, NULL
, outfile
, "" );
933 d_printf("Closing %s...", argv
[1]);
935 regfio_close( outfile
);
939 d_printf("Closing %s...", argv
[0]);
941 regfio_close( infile
);
948 /********************************************************************
949 ********************************************************************/
951 static int net_help_registry( int argc
, const char **argv
)
953 d_printf("net rpc registry enumerate <path> [recurse] Enumerate the subkeya and values for a given registry path\n");
954 d_printf("net rpc registry save <path> <file> Backup a registry tree to a file on the server\n");
955 d_printf("net rpc registry dump <file> Dump the contents of a registry file to stdout\n");
960 /********************************************************************
961 ********************************************************************/
963 int net_rpc_registry(int argc
, const char **argv
)
965 struct functable func
[] = {
966 {"enumerate", rpc_registry_enumerate
},
967 {"setvalue", rpc_registry_setvalue
},
968 {"save", rpc_registry_save
},
969 {"dump", rpc_registry_dump
},
970 {"copy", rpc_registry_copy
},
975 return net_run_function( argc
, argv
, func
, net_help_registry
);
977 return net_help_registry( argc
, argv
);