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"
34 #include "../libcli/security/display_sec.h"
35 #include "../libcli/security/sddl.h"
36 #include "../libcli/registry/util_reg.h"
37 #include "passdb/machine_sid.h"
46 * split given path into hive and remaining path and open the hive key
48 static WERROR open_hive(TALLOC_CTX *ctx, const char *path,
49 uint32 desired_access,
50 struct registry_key **hive,
54 struct security_token *token = NULL;
55 char *hivename = NULL;
56 char *tmp_subkeyname = NULL;
57 TALLOC_CTX *tmp_ctx = talloc_stackframe();
59 if ((hive == NULL) || (subkeyname == NULL)) {
60 werr = WERR_INVALID_PARAM;
64 werr = split_hive_key(tmp_ctx, path, &hivename, &tmp_subkeyname);
65 if (!W_ERROR_IS_OK(werr)) {
68 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
69 if (*subkeyname == NULL) {
74 werr = ntstatus_to_werror(registry_create_admin_token(tmp_ctx, &token));
75 if (!W_ERROR_IS_OK(werr)) {
79 werr = reg_openhive(ctx, hivename, desired_access, token, hive);
80 if (!W_ERROR_IS_OK(werr)) {
91 static WERROR open_key(TALLOC_CTX *ctx, const char *path,
92 uint32 desired_access,
93 struct registry_key **key)
96 char *subkey_name = NULL;
97 struct registry_key *hive = NULL;
98 TALLOC_CTX *tmp_ctx = talloc_stackframe();
100 if ((path == NULL) || (key == NULL)) {
101 return WERR_INVALID_PARAM;
104 werr = open_hive(tmp_ctx, path, desired_access, &hive, &subkey_name);
105 if (!W_ERROR_IS_OK(werr)) {
106 d_fprintf(stderr, _("open_hive failed: %s\n"),
111 werr = reg_openkey(ctx, hive, subkey_name, desired_access, key);
112 if (!W_ERROR_IS_OK(werr)) {
113 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
121 TALLOC_FREE(tmp_ctx);
127 * the main "net registry" function implementations
131 static int net_registry_enumerate(struct net_context *c, int argc,
135 struct registry_key *key = NULL;
136 TALLOC_CTX *ctx = talloc_stackframe();
140 char *valname = NULL;
141 struct registry_value *valvalue = NULL;
144 if (argc != 1 || c->display_usage) {
147 _("net registry enumerate <path>\n"));
150 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
154 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
155 if (!W_ERROR_IS_OK(werr)) {
156 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
161 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
165 print_registry_key(subkey_name, &modtime);
167 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
172 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
176 print_registry_value_with_name(valname, valvalue);
178 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
188 static int net_registry_createkey(struct net_context *c, int argc,
192 enum winreg_CreateAction action;
194 struct registry_key *hivekey = NULL;
195 struct registry_key *subkey = NULL;
196 TALLOC_CTX *ctx = talloc_stackframe();
199 if (argc != 1 || c->display_usage) {
202 _("net registry createkey <path>\n"));
205 _("net registry createkey "
206 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
209 if (strlen(argv[0]) == 0) {
210 d_fprintf(stderr, _("error: zero length key name given\n"));
214 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
215 if (!W_ERROR_IS_OK(werr)) {
216 d_fprintf(stderr, _("open_hive failed: %s\n"),
221 werr = reg_createkey(ctx, hivekey, subkeyname, REG_KEY_WRITE,
223 if (!W_ERROR_IS_OK(werr)) {
224 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
229 case REG_ACTION_NONE:
230 d_printf(_("createkey did nothing -- huh?\n"));
232 case REG_CREATED_NEW_KEY:
233 d_printf(_("createkey created %s\n"), argv[0]);
235 case REG_OPENED_EXISTING_KEY:
236 d_printf(_("createkey opened existing %s\n"), argv[0]);
247 static int net_registry_deletekey_internal(struct net_context *c, int argc,
253 struct registry_key *hivekey = NULL;
254 TALLOC_CTX *ctx = talloc_stackframe();
257 if (argc != 1 || c->display_usage) {
260 _("net registry deletekey <path>\n"));
263 _("net registry deletekey "
264 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
267 if (strlen(argv[0]) == 0) {
268 d_fprintf(stderr, _("error: zero length key name given\n"));
272 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
273 if (!W_ERROR_IS_OK(werr)) {
274 d_fprintf(stderr, "open_hive %s: %s\n", _("failed"),
280 werr = reg_deletekey_recursive(hivekey, subkeyname);
282 werr = reg_deletekey(hivekey, subkeyname);
284 if (!W_ERROR_IS_OK(werr) &&
285 !(c->opt_force && W_ERROR_EQUAL(werr, WERR_BADFILE)))
287 d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"),
299 static int net_registry_deletekey(struct net_context *c, int argc,
302 return net_registry_deletekey_internal(c, argc, argv, false);
305 static int net_registry_deletekey_recursive(struct net_context *c, int argc,
308 return net_registry_deletekey_internal(c, argc, argv, true);
311 static int net_registry_getvalue_internal(struct net_context *c, int argc,
312 const char **argv, bool raw)
316 struct registry_key *key = NULL;
317 struct registry_value *value = NULL;
318 TALLOC_CTX *ctx = talloc_stackframe();
320 if (argc != 2 || c->display_usage) {
321 d_fprintf(stderr, "%s\n%s",
323 _("net registry getvalue <key> <valuename>\n"));
327 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
328 if (!W_ERROR_IS_OK(werr)) {
329 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
333 werr = reg_queryvalue(ctx, key, argv[1], &value);
334 if (!W_ERROR_IS_OK(werr)) {
335 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
340 print_registry_value(value, raw);
349 static int net_registry_getvalue(struct net_context *c, int argc,
352 return net_registry_getvalue_internal(c, argc, argv, false);
355 static int net_registry_getvalueraw(struct net_context *c, int argc,
358 return net_registry_getvalue_internal(c, argc, argv, true);
361 static int net_registry_getvaluesraw(struct net_context *c, int argc,
366 struct registry_key *key = NULL;
367 TALLOC_CTX *ctx = talloc_stackframe();
370 if (argc != 1 || c->display_usage) {
371 d_fprintf(stderr, "usage: net rpc registry getvaluesraw "
376 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
377 if (!W_ERROR_IS_OK(werr)) {
378 d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
384 struct registry_value *val;
386 werr = reg_enumvalue(talloc_tos(), key, idx, NULL, &val);
388 if (W_ERROR_EQUAL(werr, WERR_NO_MORE_ITEMS)) {
392 if (!W_ERROR_IS_OK(werr)) {
395 print_registry_value(val, true);
404 static int net_registry_setvalue(struct net_context *c, int argc,
408 struct registry_value value;
409 struct registry_key *key = NULL;
411 TALLOC_CTX *ctx = talloc_stackframe();
413 if (argc < 4 || c->display_usage) {
414 d_fprintf(stderr, "%s\n%s",
416 _("net registry setvalue <key> <valuename> "
417 "<type> [<val>]+\n"));
421 if (!strequal(argv[2], "multi_sz") && (argc != 4)) {
422 d_fprintf(stderr, _("Too many args for type %s\n"), argv[2]);
426 if (strequal(argv[2], "dword")) {
427 uint32_t v = strtoul(argv[3], NULL, 10);
428 value.type = REG_DWORD;
429 value.data = data_blob_talloc(ctx, NULL, 4);
430 SIVAL(value.data.data, 0, v);
431 } else if (strequal(argv[2], "sz")) {
433 if (!push_reg_sz(ctx, &value.data, argv[3])) {
436 } else if (strequal(argv[2], "multi_sz")) {
438 int count = argc - 3;
440 value.type = REG_MULTI_SZ;
441 array = talloc_zero_array(ctx, const char *, count + 1);
445 for (i=0; i < count; i++) {
446 array[i] = talloc_strdup(array, argv[count+i]);
447 if (array[i] == NULL) {
451 if (!push_reg_multi_sz(ctx, &value.data, array)) {
455 d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
459 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
460 if (!W_ERROR_IS_OK(werr)) {
461 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
465 werr = reg_setvalue(key, argv[1], &value);
466 if (!W_ERROR_IS_OK(werr)) {
467 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
479 struct net_registry_increment_state {
481 const char *valuename;
487 static void net_registry_increment_fn(void *private_data)
489 struct net_registry_increment_state *state =
490 (struct net_registry_increment_state *)private_data;
491 struct registry_value *value;
492 struct registry_key *key = NULL;
495 state->werr = open_key(talloc_tos(), state->keyname,
496 REG_KEY_READ|REG_KEY_WRITE, &key);
497 if (!W_ERROR_IS_OK(state->werr)) {
498 d_fprintf(stderr, _("open_key failed: %s\n"),
499 win_errstr(state->werr));
503 state->werr = reg_queryvalue(key, key, state->valuename, &value);
504 if (!W_ERROR_IS_OK(state->werr)) {
505 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
506 win_errstr(state->werr));
510 if (value->type != REG_DWORD) {
511 d_fprintf(stderr, _("value not a DWORD: %s\n"),
512 str_regtype(value->type));
516 if (value->data.length < 4) {
517 d_fprintf(stderr, _("value too short for regular DWORD\n"));
521 v = IVAL(value->data.data, 0);
522 v += state->increment;
525 SIVAL(value->data.data, 0, v);
527 state->werr = reg_setvalue(key, state->valuename, value);
528 if (!W_ERROR_IS_OK(state->werr)) {
529 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
530 win_errstr(state->werr));
539 static int net_registry_increment(struct net_context *c, int argc,
542 struct net_registry_increment_state state;
546 if (argc < 2 || c->display_usage) {
547 d_fprintf(stderr, "%s\n%s",
549 _("net registry increment <key> <valuename> "
554 state.keyname = argv[0];
555 state.valuename = argv[1];
559 state.increment = strtoul(argv[2], NULL, 10);
562 status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
563 timeval_set(600, 0), procid_self(),
564 net_registry_increment_fn, &state);
565 if (!NT_STATUS_IS_OK(status)) {
566 d_fprintf(stderr, _("g_lock_do failed: %s\n"),
570 if (!W_ERROR_IS_OK(state.werr)) {
571 d_fprintf(stderr, _("increment failed: %s\n"),
572 win_errstr(state.werr));
576 d_printf(_("%u\n"), (unsigned)state.newvalue);
584 static int net_registry_deletevalue(struct net_context *c, int argc,
588 struct registry_key *key = NULL;
589 TALLOC_CTX *ctx = talloc_stackframe();
592 if (argc != 2 || c->display_usage) {
593 d_fprintf(stderr, "%s\n%s",
595 _("net registry deletevalue <key> <valuename>\n"));
599 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
600 if (!W_ERROR_IS_OK(werr)) {
601 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
605 werr = reg_deletevalue(key, argv[1]);
606 if (!W_ERROR_IS_OK(werr)) {
607 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
619 static WERROR net_registry_getsd_internal(struct net_context *c,
622 struct security_descriptor **sd)
625 struct registry_key *key = NULL;
626 TALLOC_CTX *ctx = talloc_stackframe();
627 uint32_t access_mask = REG_KEY_READ |
628 SEC_FLAG_MAXIMUM_ALLOWED |
629 SEC_FLAG_SYSTEM_SECURITY;
632 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
633 * is denied with these perms right now...
635 access_mask = REG_KEY_READ;
638 d_fprintf(stderr, _("internal error: invalid argument\n"));
639 werr = WERR_INVALID_PARAM;
643 if (strlen(keyname) == 0) {
644 d_fprintf(stderr, _("error: zero length key name given\n"));
645 werr = WERR_INVALID_PARAM;
649 werr = open_key(ctx, keyname, access_mask, &key);
650 if (!W_ERROR_IS_OK(werr)) {
651 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
656 werr = reg_getkeysecurity(mem_ctx, key, sd);
657 if (!W_ERROR_IS_OK(werr)) {
658 d_fprintf(stderr, "%s%s\n", _("reg_getkeysecurity failed: "),
670 static int net_registry_getsd(struct net_context *c, int argc,
675 struct security_descriptor *secdesc = NULL;
676 TALLOC_CTX *ctx = talloc_stackframe();
678 if (argc != 1 || c->display_usage) {
681 _("net registry getsd <path>\n"));
684 _("net registry getsd 'HKLM\\Software\\Samba'\n"));
688 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
689 if (!W_ERROR_IS_OK(werr)) {
693 display_sec_desc(secdesc);
702 static int net_registry_getsd_sddl(struct net_context *c,
703 int argc, const char **argv)
707 struct security_descriptor *secdesc = NULL;
708 TALLOC_CTX *ctx = talloc_stackframe();
710 if (argc != 1 || c->display_usage) {
713 _("net registry getsd_sddl <path>\n"));
716 _("net registry getsd_sddl 'HKLM\\Software\\Samba'\n"));
720 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
721 if (!W_ERROR_IS_OK(werr)) {
725 d_printf("%s\n", sddl_encode(ctx, secdesc, get_global_sam_sid()));
734 static WERROR net_registry_setsd_internal(struct net_context *c,
737 struct security_descriptor *sd)
740 struct registry_key *key = NULL;
741 TALLOC_CTX *ctx = talloc_stackframe();
742 uint32_t access_mask = REG_KEY_WRITE |
743 SEC_FLAG_MAXIMUM_ALLOWED |
744 SEC_FLAG_SYSTEM_SECURITY;
747 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
748 * is denied with these perms right now...
750 access_mask = REG_KEY_WRITE;
752 if (strlen(keyname) == 0) {
753 d_fprintf(stderr, _("error: zero length key name given\n"));
754 werr = WERR_INVALID_PARAM;
758 werr = open_key(ctx, keyname, access_mask, &key);
759 if (!W_ERROR_IS_OK(werr)) {
760 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
765 werr = reg_setkeysecurity(key, sd);
766 if (!W_ERROR_IS_OK(werr)) {
767 d_fprintf(stderr, "%s%s\n", _("reg_setkeysecurity failed: "),
779 static int net_registry_setsd_sddl(struct net_context *c,
780 int argc, const char **argv)
784 struct security_descriptor *secdesc = NULL;
785 TALLOC_CTX *ctx = talloc_stackframe();
787 if (argc != 2 || c->display_usage) {
790 _("net registry setsd_sddl <path> <security_descriptor>\n"));
793 _("net registry setsd_sddl 'HKLM\\Software\\Samba'\n"));
797 secdesc = sddl_decode(ctx, argv[1], get_global_sam_sid());
798 if (secdesc == NULL) {
802 werr = net_registry_setsd_internal(c, ctx, argv[0], secdesc);
803 if (!W_ERROR_IS_OK(werr)) {
814 /******************************************************************************/
816 * @defgroup net_registry net registry
820 * @defgroup net_registry_import Import
821 * @ingroup net_registry
830 static WERROR import_create_key(struct import_ctx* ctx,
831 struct registry_key* parent,
832 const char* name, void** pkey, bool* existing)
835 void* mem_ctx = talloc_new(ctx->mem_ctx);
837 struct registry_key* key = NULL;
838 enum winreg_CreateAction action;
840 if (parent == NULL) {
841 char* subkeyname = NULL;
842 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
843 &parent, &subkeyname);
844 if (!W_ERROR_IS_OK(werr)) {
845 d_fprintf(stderr, _("open_hive failed: %s\n"),
852 action = REG_ACTION_NONE;
853 werr = reg_createkey(mem_ctx, parent, name, REG_KEY_WRITE,
855 if (!W_ERROR_IS_OK(werr)) {
856 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
861 if (action == REG_ACTION_NONE) {
862 d_fprintf(stderr, _("createkey did nothing -- huh?\n"));
863 werr = WERR_CREATE_FAILED;
867 if (existing != NULL) {
868 *existing = (action == REG_OPENED_EXISTING_KEY);
872 *pkey = talloc_steal(ctx->mem_ctx, key);
876 talloc_free(mem_ctx);
880 static WERROR import_close_key(struct import_ctx* ctx,
881 struct registry_key* key)
886 static WERROR import_delete_key(struct import_ctx* ctx,
887 struct registry_key* parent, const char* name)
890 void* mem_ctx = talloc_new(talloc_tos());
892 if (parent == NULL) {
893 char* subkeyname = NULL;
894 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
895 &parent, &subkeyname);
896 if (!W_ERROR_IS_OK(werr)) {
897 d_fprintf(stderr, _("open_hive failed: %s\n"),
904 werr = reg_deletekey_recursive(parent, name);
905 if (!W_ERROR_IS_OK(werr)) {
906 d_fprintf(stderr, "reg_deletekey_recursive %s: %s\n", _("failed"),
912 talloc_free(mem_ctx);
916 static WERROR import_create_val (struct import_ctx* ctx,
917 struct registry_key* parent, const char* name,
918 const struct registry_value* value)
922 if (parent == NULL) {
923 return WERR_INVALID_PARAM;
926 werr = reg_setvalue(parent, name, value);
927 if (!W_ERROR_IS_OK(werr)) {
928 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
934 static WERROR import_delete_val (struct import_ctx* ctx, struct registry_key* parent, const char* name) {
937 if (parent == NULL) {
938 return WERR_INVALID_PARAM;
941 werr = reg_deletevalue(parent, name);
942 if (!W_ERROR_IS_OK(werr)) {
943 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
951 static int net_registry_import(struct net_context *c, int argc,
954 struct import_ctx import_ctx;
955 struct reg_import_callback import_callback = {
957 .closekey = (reg_import_callback_closekey_t)&import_close_key,
958 .createkey = (reg_import_callback_createkey_t)&import_create_key,
959 .deletekey = (reg_import_callback_deletekey_t)&import_delete_key,
960 .deleteval = (reg_import_callback_deleteval_t)&import_delete_val,
961 .setval.registry_value = (reg_import_callback_setval_registry_value_t)
963 .setval_type = REGISTRY_VALUE,
969 if (argc < 1 || argc > 2 || c->display_usage) {
972 _("net registry import <reg> [options]\n"));
975 _("net registry import file.reg enc=CP1252\n"));
979 ZERO_STRUCT(import_ctx);
980 import_ctx.mem_ctx = talloc_stackframe();
983 regdb_transaction_start();
985 ret = reg_parse_file(argv[0],
986 reg_import_adapter(import_ctx.mem_ctx,
988 (argc > 1) ? argv[1] : NULL
991 d_printf("reg_parse_file failed: transaction canceled\n");
992 regdb_transaction_cancel();
994 regdb_transaction_commit();
998 talloc_free(import_ctx.mem_ctx);
1004 /******************************************************************************/
1007 * @defgroup net_registry_export Export
1008 * @ingroup net_registry
1012 static int registry_export(TALLOC_CTX *ctx, /*const*/ struct registry_key* key,
1013 struct reg_format* f)
1019 struct registry_value *valvalue = NULL;
1020 char *valname = NULL;
1022 struct registry_key* subkey = NULL;
1023 char *subkey_name = NULL;
1026 reg_format_registry_key(f, key, false);
1030 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
1031 W_ERROR_IS_OK(werr);
1034 reg_format_registry_value(f, valname, valvalue);
1036 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1037 d_fprintf(stderr, _("reg_enumvalue failed: %s\n"),
1042 /* recurse on subkeys */
1044 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
1045 W_ERROR_IS_OK(werr);
1048 werr = reg_openkey(ctx, key, subkey_name, REG_KEY_READ,
1050 if (!W_ERROR_IS_OK(werr)) {
1051 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
1056 registry_export(ctx, subkey, f);
1058 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1059 d_fprintf(stderr, _("reg_enumkey failed: %s\n"),
1068 static int net_registry_export(struct net_context *c, int argc,
1073 struct registry_key *key = NULL;
1074 TALLOC_CTX *ctx = talloc_stackframe();
1075 struct reg_format* f=NULL;
1077 if (argc < 2 || argc > 3 || c->display_usage) {
1080 _("net registry export <path> <file> [opt]\n"));
1083 _("net registry export 'HKLM\\Software\\Samba' "
1084 "samba.reg regedit5\n"));
1088 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
1089 if (!W_ERROR_IS_OK(werr)) {
1090 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
1094 f = reg_format_file(ctx, argv[1], (argc > 2) ? argv[2] : NULL);
1096 d_fprintf(stderr, _("open file failed: %s\n"), strerror(errno));
1100 ret = registry_export(ctx, key, f);
1108 /******************************************************************************/
1110 * @defgroup net_registry_convert Convert
1111 * @ingroup net_registry
1115 static int net_registry_convert(struct net_context *c, int argc,
1120 const char* in_opt = NULL;
1121 const char* out_opt = NULL;
1123 if (argc < 2 || argc > 4|| c->display_usage) {
1126 _("net registry convert <in> <out> [in_opt] [out_opt]\n"
1127 "net registry convert <in> <out> [out_opt]\n"));
1130 _("net registry convert in.reg out.reg regedit4,enc=CP1252\n"));
1134 mem_ctx = talloc_stackframe();
1151 ret = reg_parse_file(argv[0], (struct reg_parse_callback*)
1152 reg_format_file(mem_ctx, argv[1], out_opt),
1155 talloc_free(mem_ctx);
1161 /******************************************************************************/
1163 int net_registry(struct net_context *c, int argc, const char **argv)
1167 struct functable func[] = {
1170 net_registry_enumerate,
1171 NET_TRANSPORT_LOCAL,
1172 N_("Enumerate registry keys and values"),
1173 N_("net registry enumerate\n"
1174 " Enumerate registry keys and values")
1178 net_registry_createkey,
1179 NET_TRANSPORT_LOCAL,
1180 N_("Create a new registry key"),
1181 N_("net registry createkey\n"
1182 " Create a new registry key")
1186 net_registry_deletekey,
1187 NET_TRANSPORT_LOCAL,
1188 N_("Delete a registry key"),
1189 N_("net registry deletekey\n"
1190 " Delete a registry key")
1193 "deletekey_recursive",
1194 net_registry_deletekey_recursive,
1195 NET_TRANSPORT_LOCAL,
1196 N_("Delete a registry key with subkeys"),
1197 N_("net registry deletekey_recursive\n"
1198 " Delete a registry key with subkeys")
1202 net_registry_getvalue,
1203 NET_TRANSPORT_LOCAL,
1204 N_("Print a registry value"),
1205 N_("net registry getvalue\n"
1206 " Print a registry value")
1210 net_registry_getvalueraw,
1211 NET_TRANSPORT_LOCAL,
1212 N_("Print a registry value (raw format)"),
1213 N_("net registry getvalueraw\n"
1214 " Print a registry value (raw format)")
1218 net_registry_getvaluesraw,
1219 NET_TRANSPORT_LOCAL,
1220 "Print all values of a key in raw format",
1221 "net registry getvaluesraw <key>\n"
1222 " Print a registry value (raw format)"
1226 net_registry_setvalue,
1227 NET_TRANSPORT_LOCAL,
1228 N_("Set a new registry value"),
1229 N_("net registry setvalue\n"
1230 " Set a new registry value")
1234 net_registry_increment,
1235 NET_TRANSPORT_LOCAL,
1236 N_("Increment a DWORD registry value under a lock"),
1237 N_("net registry increment\n"
1238 " Increment a DWORD registry value under a lock")
1242 net_registry_deletevalue,
1243 NET_TRANSPORT_LOCAL,
1244 N_("Delete a registry value"),
1245 N_("net registry deletevalue\n"
1246 " Delete a registry value")
1251 NET_TRANSPORT_LOCAL,
1252 N_("Get security descriptor"),
1253 N_("net registry getsd\n"
1254 " Get security descriptor")
1258 net_registry_getsd_sddl,
1259 NET_TRANSPORT_LOCAL,
1260 N_("Get security descriptor in sddl format"),
1261 N_("net registry getsd_sddl\n"
1262 " Get security descriptor in sddl format")
1266 net_registry_setsd_sddl,
1267 NET_TRANSPORT_LOCAL,
1268 N_("Set security descriptor from sddl format string"),
1269 N_("net registry setsd_sddl\n"
1270 " Set security descriptor from sddl format string")
1274 net_registry_import,
1275 NET_TRANSPORT_LOCAL,
1276 N_("Import .reg file"),
1277 N_("net registry import\n"
1278 " Import .reg file")
1282 net_registry_export,
1283 NET_TRANSPORT_LOCAL,
1284 N_("Export .reg file"),
1285 N_("net registry export\n"
1286 " Export .reg file")
1290 net_registry_convert,
1291 NET_TRANSPORT_LOCAL,
1292 N_("Convert .reg file"),
1293 N_("net registry convert\n"
1294 " Convert .reg file")
1296 { NULL, NULL, 0, NULL, NULL }
1299 if (!W_ERROR_IS_OK(registry_init_basic())) {
1303 ret = net_run_function(c, argc, argv, "net registry", func);