2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Local registry interface
6 * Copyright (C) Michael Adam 2008
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.
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.
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/>.
24 #include "registry/reg_api.h"
25 #include "registry/reg_util_token.h"
26 #include "registry/reg_init_basic.h"
27 #include "utils/net.h"
28 #include "utils/net_registry_util.h"
29 #include "include/g_lock.h"
30 #include "registry/reg_backend_db.h"
31 #include "registry/reg_import.h"
32 #include "registry/reg_format.h"
42 * split given path into hive and remaining path and open the hive key
44 static WERROR
open_hive(TALLOC_CTX
*ctx
, const char *path
,
45 uint32 desired_access
,
46 struct registry_key
**hive
,
50 struct security_token
*token
= NULL
;
51 char *hivename
= NULL
;
52 char *tmp_subkeyname
= NULL
;
53 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
55 if ((hive
== NULL
) || (subkeyname
== NULL
)) {
56 werr
= WERR_INVALID_PARAM
;
60 werr
= split_hive_key(tmp_ctx
, path
, &hivename
, &tmp_subkeyname
);
61 if (!W_ERROR_IS_OK(werr
)) {
64 *subkeyname
= talloc_strdup(ctx
, tmp_subkeyname
);
65 if (*subkeyname
== NULL
) {
70 werr
= ntstatus_to_werror(registry_create_admin_token(tmp_ctx
, &token
));
71 if (!W_ERROR_IS_OK(werr
)) {
75 werr
= reg_openhive(ctx
, hivename
, desired_access
, token
, hive
);
76 if (!W_ERROR_IS_OK(werr
)) {
87 static WERROR
open_key(TALLOC_CTX
*ctx
, const char *path
,
88 uint32 desired_access
,
89 struct registry_key
**key
)
92 char *subkey_name
= NULL
;
93 struct registry_key
*hive
= NULL
;
94 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
96 if ((path
== NULL
) || (key
== NULL
)) {
97 return WERR_INVALID_PARAM
;
100 werr
= open_hive(tmp_ctx
, path
, desired_access
, &hive
, &subkey_name
);
101 if (!W_ERROR_IS_OK(werr
)) {
102 d_fprintf(stderr
, _("open_hive failed: %s\n"),
107 werr
= reg_openkey(ctx
, hive
, subkey_name
, desired_access
, key
);
108 if (!W_ERROR_IS_OK(werr
)) {
109 d_fprintf(stderr
, _("reg_openkey failed: %s\n"),
117 TALLOC_FREE(tmp_ctx
);
123 * the main "net registry" function implementations
127 static int net_registry_enumerate(struct net_context
*c
, int argc
,
131 struct registry_key
*key
= NULL
;
132 TALLOC_CTX
*ctx
= talloc_stackframe();
136 char *valname
= NULL
;
137 struct registry_value
*valvalue
= NULL
;
140 if (argc
!= 1 || c
->display_usage
) {
143 _("net registry enumerate <path>\n"));
146 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
150 werr
= open_key(ctx
, argv
[0], REG_KEY_READ
, &key
);
151 if (!W_ERROR_IS_OK(werr
)) {
152 d_fprintf(stderr
, _("open_key failed: %s\n"), win_errstr(werr
));
157 werr
= reg_enumkey(ctx
, key
, count
, &subkey_name
, &modtime
),
161 print_registry_key(subkey_name
, &modtime
);
163 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
168 werr
= reg_enumvalue(ctx
, key
, count
, &valname
, &valvalue
),
172 print_registry_value_with_name(valname
, valvalue
);
174 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
184 static int net_registry_createkey(struct net_context
*c
, int argc
,
188 enum winreg_CreateAction action
;
190 struct registry_key
*hivekey
= NULL
;
191 struct registry_key
*subkey
= NULL
;
192 TALLOC_CTX
*ctx
= talloc_stackframe();
195 if (argc
!= 1 || c
->display_usage
) {
198 _("net registry createkey <path>\n"));
201 _("net registry createkey "
202 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
205 if (strlen(argv
[0]) == 0) {
206 d_fprintf(stderr
, _("error: zero length key name given\n"));
210 werr
= open_hive(ctx
, argv
[0], REG_KEY_WRITE
, &hivekey
, &subkeyname
);
211 if (!W_ERROR_IS_OK(werr
)) {
212 d_fprintf(stderr
, _("open_hive failed: %s\n"),
217 werr
= reg_createkey(ctx
, hivekey
, subkeyname
, REG_KEY_WRITE
,
219 if (!W_ERROR_IS_OK(werr
)) {
220 d_fprintf(stderr
, _("reg_createkey failed: %s\n"),
225 case REG_ACTION_NONE
:
226 d_printf(_("createkey did nothing -- huh?\n"));
228 case REG_CREATED_NEW_KEY
:
229 d_printf(_("createkey created %s\n"), argv
[0]);
231 case REG_OPENED_EXISTING_KEY
:
232 d_printf(_("createkey opened existing %s\n"), argv
[0]);
243 static int net_registry_deletekey_internal(struct net_context
*c
, int argc
,
249 struct registry_key
*hivekey
= NULL
;
250 TALLOC_CTX
*ctx
= talloc_stackframe();
253 if (argc
!= 1 || c
->display_usage
) {
256 _("net registry deletekey <path>\n"));
259 _("net registry deletekey "
260 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
263 if (strlen(argv
[0]) == 0) {
264 d_fprintf(stderr
, _("error: zero length key name given\n"));
268 werr
= open_hive(ctx
, argv
[0], REG_KEY_WRITE
, &hivekey
, &subkeyname
);
269 if (!W_ERROR_IS_OK(werr
)) {
270 d_fprintf(stderr
, "open_hive %s: %s\n", _("failed"),
276 werr
= reg_deletekey_recursive(hivekey
, subkeyname
);
278 werr
= reg_deletekey(hivekey
, subkeyname
);
280 if (!W_ERROR_IS_OK(werr
)) {
281 d_fprintf(stderr
, "reg_deletekey %s: %s\n", _("failed"),
293 static int net_registry_deletekey(struct net_context
*c
, int argc
,
296 return net_registry_deletekey_internal(c
, argc
, argv
, false);
299 static int net_registry_deletekey_recursive(struct net_context
*c
, int argc
,
302 return net_registry_deletekey_internal(c
, argc
, argv
, true);
305 static int net_registry_getvalue_internal(struct net_context
*c
, int argc
,
306 const char **argv
, bool raw
)
310 struct registry_key
*key
= NULL
;
311 struct registry_value
*value
= NULL
;
312 TALLOC_CTX
*ctx
= talloc_stackframe();
314 if (argc
!= 2 || c
->display_usage
) {
315 d_fprintf(stderr
, "%s\n%s",
317 _("net registry getvalue <key> <valuename>\n"));
321 werr
= open_key(ctx
, argv
[0], REG_KEY_READ
, &key
);
322 if (!W_ERROR_IS_OK(werr
)) {
323 d_fprintf(stderr
, _("open_key failed: %s\n"), win_errstr(werr
));
327 werr
= reg_queryvalue(ctx
, key
, argv
[1], &value
);
328 if (!W_ERROR_IS_OK(werr
)) {
329 d_fprintf(stderr
, _("reg_queryvalue failed: %s\n"),
334 print_registry_value(value
, raw
);
343 static int net_registry_getvalue(struct net_context
*c
, int argc
,
346 return net_registry_getvalue_internal(c
, argc
, argv
, false);
349 static int net_registry_getvalueraw(struct net_context
*c
, int argc
,
352 return net_registry_getvalue_internal(c
, argc
, argv
, true);
355 static int net_registry_getvaluesraw(struct net_context
*c
, int argc
,
360 struct registry_key
*key
= NULL
;
361 TALLOC_CTX
*ctx
= talloc_stackframe();
364 if (argc
!= 1 || c
->display_usage
) {
365 d_fprintf(stderr
, "usage: net rpc registry getvaluesraw "
370 werr
= open_key(ctx
, argv
[0], REG_KEY_READ
, &key
);
371 if (!W_ERROR_IS_OK(werr
)) {
372 d_fprintf(stderr
, "open_key failed: %s\n", win_errstr(werr
));
378 struct registry_value
*val
;
380 werr
= reg_enumvalue(talloc_tos(), key
, idx
, NULL
, &val
);
382 if (W_ERROR_EQUAL(werr
, WERR_NO_MORE_ITEMS
)) {
386 if (!W_ERROR_IS_OK(werr
)) {
389 print_registry_value(val
, true);
398 static int net_registry_setvalue(struct net_context
*c
, int argc
,
402 struct registry_value value
;
403 struct registry_key
*key
= NULL
;
405 TALLOC_CTX
*ctx
= talloc_stackframe();
407 if (argc
< 4 || c
->display_usage
) {
408 d_fprintf(stderr
, "%s\n%s",
410 _("net registry setvalue <key> <valuename> "
411 "<type> [<val>]+\n"));
415 if (!strequal(argv
[2], "multi_sz") && (argc
!= 4)) {
416 d_fprintf(stderr
, _("Too many args for type %s\n"), argv
[2]);
420 if (strequal(argv
[2], "dword")) {
421 uint32_t v
= strtoul(argv
[3], NULL
, 10);
422 value
.type
= REG_DWORD
;
423 value
.data
= data_blob_talloc(ctx
, NULL
, 4);
424 SIVAL(value
.data
.data
, 0, v
);
425 } else if (strequal(argv
[2], "sz")) {
427 if (!push_reg_sz(ctx
, &value
.data
, argv
[3])) {
430 } else if (strequal(argv
[2], "multi_sz")) {
432 int count
= argc
- 3;
434 value
.type
= REG_MULTI_SZ
;
435 array
= talloc_zero_array(ctx
, const char *, count
+ 1);
439 for (i
=0; i
< count
; i
++) {
440 array
[i
] = talloc_strdup(array
, argv
[count
+i
]);
441 if (array
[i
] == NULL
) {
445 if (!push_reg_multi_sz(ctx
, &value
.data
, array
)) {
449 d_fprintf(stderr
, _("type \"%s\" not implemented\n"), argv
[2]);
453 werr
= open_key(ctx
, argv
[0], REG_KEY_WRITE
, &key
);
454 if (!W_ERROR_IS_OK(werr
)) {
455 d_fprintf(stderr
, _("open_key failed: %s\n"), win_errstr(werr
));
459 werr
= reg_setvalue(key
, argv
[1], &value
);
460 if (!W_ERROR_IS_OK(werr
)) {
461 d_fprintf(stderr
, _("reg_setvalue failed: %s\n"),
473 struct net_registry_increment_state
{
475 const char *valuename
;
481 static void net_registry_increment_fn(void *private_data
)
483 struct net_registry_increment_state
*state
=
484 (struct net_registry_increment_state
*)private_data
;
485 struct registry_value
*value
;
486 struct registry_key
*key
= NULL
;
489 state
->werr
= open_key(talloc_tos(), state
->keyname
,
490 REG_KEY_READ
|REG_KEY_WRITE
, &key
);
491 if (!W_ERROR_IS_OK(state
->werr
)) {
492 d_fprintf(stderr
, _("open_key failed: %s\n"),
493 win_errstr(state
->werr
));
497 state
->werr
= reg_queryvalue(key
, key
, state
->valuename
, &value
);
498 if (!W_ERROR_IS_OK(state
->werr
)) {
499 d_fprintf(stderr
, _("reg_queryvalue failed: %s\n"),
500 win_errstr(state
->werr
));
504 if (value
->type
!= REG_DWORD
) {
505 d_fprintf(stderr
, _("value not a DWORD: %s\n"),
506 str_regtype(value
->type
));
510 if (value
->data
.length
< 4) {
511 d_fprintf(stderr
, _("value too short for regular DWORD\n"));
515 v
= IVAL(value
->data
.data
, 0);
516 v
+= state
->increment
;
519 SIVAL(value
->data
.data
, 0, v
);
521 state
->werr
= reg_setvalue(key
, state
->valuename
, value
);
522 if (!W_ERROR_IS_OK(state
->werr
)) {
523 d_fprintf(stderr
, _("reg_setvalue failed: %s\n"),
524 win_errstr(state
->werr
));
533 static int net_registry_increment(struct net_context
*c
, int argc
,
536 struct net_registry_increment_state state
;
540 if (argc
< 2 || c
->display_usage
) {
541 d_fprintf(stderr
, "%s\n%s",
543 _("net registry increment <key> <valuename> "
548 state
.keyname
= argv
[0];
549 state
.valuename
= argv
[1];
553 state
.increment
= strtoul(argv
[2], NULL
, 10);
556 status
= g_lock_do("registry_increment_lock", G_LOCK_WRITE
,
557 timeval_set(600, 0), procid_self(),
558 net_registry_increment_fn
, &state
);
559 if (!NT_STATUS_IS_OK(status
)) {
560 d_fprintf(stderr
, _("g_lock_do failed: %s\n"),
564 if (!W_ERROR_IS_OK(state
.werr
)) {
565 d_fprintf(stderr
, _("increment failed: %s\n"),
566 win_errstr(state
.werr
));
570 d_printf(_("%u\n"), (unsigned)state
.newvalue
);
578 static int net_registry_deletevalue(struct net_context
*c
, int argc
,
582 struct registry_key
*key
= NULL
;
583 TALLOC_CTX
*ctx
= talloc_stackframe();
586 if (argc
!= 2 || c
->display_usage
) {
587 d_fprintf(stderr
, "%s\n%s",
589 _("net registry deletevalue <key> <valuename>\n"));
593 werr
= open_key(ctx
, argv
[0], REG_KEY_WRITE
, &key
);
594 if (!W_ERROR_IS_OK(werr
)) {
595 d_fprintf(stderr
, _("open_key failed: %s\n"), win_errstr(werr
));
599 werr
= reg_deletevalue(key
, argv
[1]);
600 if (!W_ERROR_IS_OK(werr
)) {
601 d_fprintf(stderr
, _("reg_deletekey failed: %s\n"),
613 static WERROR
net_registry_getsd_internal(struct net_context
*c
,
616 struct security_descriptor
**sd
)
619 struct registry_key
*key
= NULL
;
620 TALLOC_CTX
*ctx
= talloc_stackframe();
621 uint32_t access_mask
= REG_KEY_READ
|
622 SEC_FLAG_MAXIMUM_ALLOWED
|
623 SEC_FLAG_SYSTEM_SECURITY
;
626 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
627 * is denied with these perms right now...
629 access_mask
= REG_KEY_READ
;
632 d_fprintf(stderr
, _("internal error: invalid argument\n"));
633 werr
= WERR_INVALID_PARAM
;
637 if (strlen(keyname
) == 0) {
638 d_fprintf(stderr
, _("error: zero length key name given\n"));
639 werr
= WERR_INVALID_PARAM
;
643 werr
= open_key(ctx
, keyname
, access_mask
, &key
);
644 if (!W_ERROR_IS_OK(werr
)) {
645 d_fprintf(stderr
, "%s%s\n", _("open_key failed: "),
650 werr
= reg_getkeysecurity(mem_ctx
, key
, sd
);
651 if (!W_ERROR_IS_OK(werr
)) {
652 d_fprintf(stderr
, "%s%s\n", _("reg_getkeysecurity failed: "),
664 static int net_registry_getsd(struct net_context
*c
, int argc
,
669 struct security_descriptor
*secdesc
= NULL
;
670 TALLOC_CTX
*ctx
= talloc_stackframe();
672 if (argc
!= 1 || c
->display_usage
) {
675 _("net registry getsd <path>\n"));
678 _("net registry getsd 'HKLM\\Software\\Samba'\n"));
682 werr
= net_registry_getsd_internal(c
, ctx
, argv
[0], &secdesc
);
683 if (!W_ERROR_IS_OK(werr
)) {
687 display_sec_desc(secdesc
);
696 static int net_registry_getsd_sddl(struct net_context
*c
,
697 int argc
, const char **argv
)
701 struct security_descriptor
*secdesc
= NULL
;
702 TALLOC_CTX
*ctx
= talloc_stackframe();
704 if (argc
!= 1 || c
->display_usage
) {
707 _("net registry getsd_sddl <path>\n"));
710 _("net registry getsd_sddl 'HKLM\\Software\\Samba'\n"));
714 werr
= net_registry_getsd_internal(c
, ctx
, argv
[0], &secdesc
);
715 if (!W_ERROR_IS_OK(werr
)) {
719 d_printf("%s\n", sddl_encode(ctx
, secdesc
, get_global_sam_sid()));
728 static WERROR
net_registry_setsd_internal(struct net_context
*c
,
731 struct security_descriptor
*sd
)
734 struct registry_key
*key
= NULL
;
735 TALLOC_CTX
*ctx
= talloc_stackframe();
736 uint32_t access_mask
= REG_KEY_WRITE
|
737 SEC_FLAG_MAXIMUM_ALLOWED
|
738 SEC_FLAG_SYSTEM_SECURITY
;
741 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
742 * is denied with these perms right now...
744 access_mask
= REG_KEY_WRITE
;
746 if (strlen(keyname
) == 0) {
747 d_fprintf(stderr
, _("error: zero length key name given\n"));
748 werr
= WERR_INVALID_PARAM
;
752 werr
= open_key(ctx
, keyname
, access_mask
, &key
);
753 if (!W_ERROR_IS_OK(werr
)) {
754 d_fprintf(stderr
, "%s%s\n", _("open_key failed: "),
759 werr
= reg_setkeysecurity(key
, sd
);
760 if (!W_ERROR_IS_OK(werr
)) {
761 d_fprintf(stderr
, "%s%s\n", _("reg_setkeysecurity failed: "),
773 static int net_registry_setsd_sddl(struct net_context
*c
,
774 int argc
, const char **argv
)
778 struct security_descriptor
*secdesc
= NULL
;
779 TALLOC_CTX
*ctx
= talloc_stackframe();
781 if (argc
!= 2 || c
->display_usage
) {
784 _("net registry setsd_sddl <path> <security_descriptor>\n"));
787 _("net registry setsd_sddl 'HKLM\\Software\\Samba'\n"));
791 secdesc
= sddl_decode(ctx
, argv
[1], get_global_sam_sid());
792 if (secdesc
== NULL
) {
796 werr
= net_registry_setsd_internal(c
, ctx
, argv
[0], secdesc
);
797 if (!W_ERROR_IS_OK(werr
)) {
808 /******************************************************************************/
810 * @defgroup net_registry net registry
814 * @defgroup net_registry_import Import
815 * @ingroup net_registry
824 static WERROR
import_create_key(struct import_ctx
* ctx
,
825 struct registry_key
* parent
,
826 const char* name
, void** pkey
, bool* existing
)
829 void* mem_ctx
= talloc_new(ctx
->mem_ctx
);
831 struct registry_key
* key
= NULL
;
832 enum winreg_CreateAction action
;
834 if (parent
== NULL
) {
835 char* subkeyname
= NULL
;
836 werr
= open_hive(mem_ctx
, name
, REG_KEY_WRITE
,
837 &parent
, &subkeyname
);
838 if (!W_ERROR_IS_OK(werr
)) {
839 d_fprintf(stderr
, _("open_hive failed: %s\n"),
846 action
= REG_ACTION_NONE
;
847 werr
= reg_createkey(mem_ctx
, parent
, name
, REG_KEY_WRITE
,
849 if (!W_ERROR_IS_OK(werr
)) {
850 d_fprintf(stderr
, _("reg_createkey failed: %s\n"),
855 if (action
== REG_ACTION_NONE
) {
856 d_fprintf(stderr
, _("createkey did nothing -- huh?\n"));
857 werr
= WERR_CREATE_FAILED
;
861 if (existing
!= NULL
) {
862 *existing
= (action
== REG_OPENED_EXISTING_KEY
);
866 *pkey
= talloc_steal(ctx
->mem_ctx
, key
);
870 talloc_free(mem_ctx
);
874 static WERROR
import_close_key(struct import_ctx
* ctx
,
875 struct registry_key
* key
)
880 static WERROR
import_delete_key(struct import_ctx
* ctx
,
881 struct registry_key
* parent
, const char* name
)
884 void* mem_ctx
= talloc_new(talloc_tos());
886 if (parent
== NULL
) {
887 char* subkeyname
= NULL
;
888 werr
= open_hive(mem_ctx
, name
, REG_KEY_WRITE
,
889 &parent
, &subkeyname
);
890 if (!W_ERROR_IS_OK(werr
)) {
891 d_fprintf(stderr
, _("open_hive failed: %s\n"),
898 werr
= reg_deletekey_recursive(parent
, name
);
899 if (!W_ERROR_IS_OK(werr
)) {
900 d_fprintf(stderr
, "reg_deletekey_recursive %s: %s\n", _("failed"),
906 talloc_free(mem_ctx
);
910 static WERROR
import_create_val (struct import_ctx
* ctx
,
911 struct registry_key
* parent
, const char* name
,
912 const struct registry_value
* value
)
916 if (parent
== NULL
) {
917 return WERR_INVALID_PARAM
;
920 werr
= reg_setvalue(parent
, name
, value
);
921 if (!W_ERROR_IS_OK(werr
)) {
922 d_fprintf(stderr
, _("reg_setvalue failed: %s\n"),
928 static WERROR
import_delete_val (struct import_ctx
* ctx
, struct registry_key
* parent
, const char* name
) {
931 if (parent
== NULL
) {
932 return WERR_INVALID_PARAM
;
935 werr
= reg_deletevalue(parent
, name
);
936 if (!W_ERROR_IS_OK(werr
)) {
937 d_fprintf(stderr
, _("reg_deletekey failed: %s\n"),
945 static int net_registry_import(struct net_context
*c
, int argc
,
948 struct import_ctx import_ctx
;
949 struct reg_import_callback import_callback
= {
951 .closekey
= (reg_import_callback_closekey_t
)&import_close_key
,
952 .createkey
= (reg_import_callback_createkey_t
)&import_create_key
,
953 .deletekey
= (reg_import_callback_deletekey_t
)&import_delete_key
,
954 .deleteval
= (reg_import_callback_deleteval_t
)&import_delete_val
,
955 .setval
.registry_value
= (reg_import_callback_setval_registry_value_t
)
957 .setval_type
= REGISTRY_VALUE
,
963 if (argc
< 1 || argc
> 2 || c
->display_usage
) {
966 _("net registry import <reg> [options]\n"));
969 _("net registry import file.reg enc=CP1252\n"));
973 ZERO_STRUCT(import_ctx
);
974 import_ctx
.mem_ctx
= talloc_stackframe();
977 regdb_transaction_start();
979 ret
= reg_parse_file(argv
[0],
980 reg_import_adapter(import_ctx
.mem_ctx
,
982 (argc
> 1) ? argv
[1] : NULL
985 d_printf("reg_parse_file failed: transaction canceled\n");
986 regdb_transaction_cancel();
988 regdb_transaction_commit();
992 talloc_free(import_ctx
.mem_ctx
);
998 /******************************************************************************/
1001 * @defgroup net_registry_export Export
1002 * @ingroup net_registry
1006 static int registry_export(TALLOC_CTX
*ctx
, /*const*/ struct registry_key
* key
,
1007 struct reg_format
* f
)
1013 struct registry_value
*valvalue
= NULL
;
1014 char *valname
= NULL
;
1016 struct registry_key
* subkey
= NULL
;
1017 char *subkey_name
= NULL
;
1020 reg_format_registry_key(f
, key
, false);
1024 werr
= reg_enumvalue(ctx
, key
, count
, &valname
, &valvalue
),
1025 W_ERROR_IS_OK(werr
);
1028 reg_format_registry_value(f
, valname
, valvalue
);
1030 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
1031 d_fprintf(stderr
, _("reg_enumvalue failed: %s\n"),
1036 /* recurse on subkeys */
1038 werr
= reg_enumkey(ctx
, key
, count
, &subkey_name
, &modtime
),
1039 W_ERROR_IS_OK(werr
);
1042 werr
= reg_openkey(ctx
, key
, subkey_name
, REG_KEY_READ
,
1044 if (!W_ERROR_IS_OK(werr
)) {
1045 d_fprintf(stderr
, _("reg_openkey failed: %s\n"),
1050 registry_export(ctx
, subkey
, f
);
1052 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
1053 d_fprintf(stderr
, _("reg_enumkey failed: %s\n"),
1062 static int net_registry_export(struct net_context
*c
, int argc
,
1067 struct registry_key
*key
= NULL
;
1068 TALLOC_CTX
*ctx
= talloc_stackframe();
1069 struct reg_format
* f
=NULL
;
1071 if (argc
< 2 || argc
> 3 || c
->display_usage
) {
1074 _("net registry export <path> <file> [opt]\n"));
1077 _("net registry export 'HKLM\\Software\\Samba' "
1078 "samba.reg regedit5\n"));
1082 werr
= open_key(ctx
, argv
[0], REG_KEY_READ
, &key
);
1083 if (!W_ERROR_IS_OK(werr
)) {
1084 d_fprintf(stderr
, _("open_key failed: %s\n"), win_errstr(werr
));
1088 f
= reg_format_file(ctx
, argv
[1], (argc
> 2) ? argv
[2] : NULL
);
1090 d_fprintf(stderr
, _("open file failed: %s\n"), strerror(errno
));
1094 ret
= registry_export(ctx
, key
, f
);
1102 /******************************************************************************/
1104 * @defgroup net_registry_convert Convert
1105 * @ingroup net_registry
1109 static int net_registry_convert(struct net_context
*c
, int argc
,
1114 const char* in_opt
= NULL
;
1115 const char* out_opt
= NULL
;
1117 if (argc
< 2 || argc
> 4|| c
->display_usage
) {
1120 _("net registry convert <in> <out> [in_opt] [out_opt]\n"
1121 "net registry convert <in> <out> [out_opt]\n"));
1124 _("net registry convert in.reg out.reg regedit4,enc=CP1252\n"));
1128 mem_ctx
= talloc_stackframe();
1145 ret
= reg_parse_file(argv
[0], (struct reg_parse_callback
*)
1146 reg_format_file(mem_ctx
, argv
[1], out_opt
),
1149 talloc_free(mem_ctx
);
1155 /******************************************************************************/
1157 int net_registry(struct net_context
*c
, int argc
, const char **argv
)
1161 struct functable func
[] = {
1164 net_registry_enumerate
,
1165 NET_TRANSPORT_LOCAL
,
1166 N_("Enumerate registry keys and values"),
1167 N_("net registry enumerate\n"
1168 " Enumerate registry keys and values")
1172 net_registry_createkey
,
1173 NET_TRANSPORT_LOCAL
,
1174 N_("Create a new registry key"),
1175 N_("net registry createkey\n"
1176 " Create a new registry key")
1180 net_registry_deletekey
,
1181 NET_TRANSPORT_LOCAL
,
1182 N_("Delete a registry key"),
1183 N_("net registry deletekey\n"
1184 " Delete a registry key")
1187 "deletekey_recursive",
1188 net_registry_deletekey_recursive
,
1189 NET_TRANSPORT_LOCAL
,
1190 N_("Delete a registry key with subkeys"),
1191 N_("net registry deletekey_recursive\n"
1192 " Delete a registry key with subkeys")
1196 net_registry_getvalue
,
1197 NET_TRANSPORT_LOCAL
,
1198 N_("Print a registry value"),
1199 N_("net registry getvalue\n"
1200 " Print a registry value")
1204 net_registry_getvalueraw
,
1205 NET_TRANSPORT_LOCAL
,
1206 N_("Print a registry value (raw format)"),
1207 N_("net registry getvalueraw\n"
1208 " Print a registry value (raw format)")
1212 net_registry_getvaluesraw
,
1213 NET_TRANSPORT_LOCAL
,
1214 "Print all values of a key in raw format",
1215 "net registry getvaluesraw <key>\n"
1216 " Print a registry value (raw format)"
1220 net_registry_setvalue
,
1221 NET_TRANSPORT_LOCAL
,
1222 N_("Set a new registry value"),
1223 N_("net registry setvalue\n"
1224 " Set a new registry value")
1228 net_registry_increment
,
1229 NET_TRANSPORT_LOCAL
,
1230 N_("Increment a DWORD registry value under a lock"),
1231 N_("net registry increment\n"
1232 " Increment a DWORD registry value under a lock")
1236 net_registry_deletevalue
,
1237 NET_TRANSPORT_LOCAL
,
1238 N_("Delete a registry value"),
1239 N_("net registry deletevalue\n"
1240 " Delete a registry value")
1245 NET_TRANSPORT_LOCAL
,
1246 N_("Get security descriptor"),
1247 N_("net registry getsd\n"
1248 " Get security descriptor")
1252 net_registry_getsd_sddl
,
1253 NET_TRANSPORT_LOCAL
,
1254 N_("Get security descriptor in sddl format"),
1255 N_("net registry getsd_sddl\n"
1256 " Get security descriptor in sddl format")
1260 net_registry_setsd_sddl
,
1261 NET_TRANSPORT_LOCAL
,
1262 N_("Set security descriptor from sddl format string"),
1263 N_("net registry setsd_sddl\n"
1264 " Set security descriptor from sddl format string")
1268 net_registry_import
,
1269 NET_TRANSPORT_LOCAL
,
1270 N_("Import .reg file"),
1271 N_("net registry import\n"
1272 " Import .reg file")
1276 net_registry_export
,
1277 NET_TRANSPORT_LOCAL
,
1278 N_("Export .reg file"),
1279 N_("net registry export\n"
1280 " Export .reg file")
1284 net_registry_convert
,
1285 NET_TRANSPORT_LOCAL
,
1286 N_("Convert .reg file"),
1287 N_("net registry convert\n"
1288 " Convert .reg file")
1290 { NULL
, NULL
, 0, NULL
, NULL
}
1293 if (!W_ERROR_IS_OK(registry_init_basic())) {
1297 ret
= net_run_function(c
, argc
, argv
, "net registry", func
);