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"
43 * split given path into hive and remaining path and open the hive key
45 static WERROR open_hive(TALLOC_CTX *ctx, const char *path,
46 uint32 desired_access,
47 struct registry_key **hive,
51 struct security_token *token = NULL;
52 char *hivename = NULL;
53 char *tmp_subkeyname = NULL;
54 TALLOC_CTX *tmp_ctx = talloc_stackframe();
56 if ((hive == NULL) || (subkeyname == NULL)) {
57 werr = WERR_INVALID_PARAM;
61 werr = split_hive_key(tmp_ctx, path, &hivename, &tmp_subkeyname);
62 if (!W_ERROR_IS_OK(werr)) {
65 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
66 if (*subkeyname == NULL) {
71 werr = ntstatus_to_werror(registry_create_admin_token(tmp_ctx, &token));
72 if (!W_ERROR_IS_OK(werr)) {
76 werr = reg_openhive(ctx, hivename, desired_access, token, hive);
77 if (!W_ERROR_IS_OK(werr)) {
88 static WERROR open_key(TALLOC_CTX *ctx, const char *path,
89 uint32 desired_access,
90 struct registry_key **key)
93 char *subkey_name = NULL;
94 struct registry_key *hive = NULL;
95 TALLOC_CTX *tmp_ctx = talloc_stackframe();
97 if ((path == NULL) || (key == NULL)) {
98 return WERR_INVALID_PARAM;
101 werr = open_hive(tmp_ctx, path, desired_access, &hive, &subkey_name);
102 if (!W_ERROR_IS_OK(werr)) {
103 d_fprintf(stderr, _("open_hive failed: %s\n"),
108 werr = reg_openkey(ctx, hive, subkey_name, desired_access, key);
109 if (!W_ERROR_IS_OK(werr)) {
110 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
118 TALLOC_FREE(tmp_ctx);
124 * the main "net registry" function implementations
128 static int net_registry_enumerate(struct net_context *c, int argc,
132 struct registry_key *key = NULL;
133 TALLOC_CTX *ctx = talloc_stackframe();
137 char *valname = NULL;
138 struct registry_value *valvalue = NULL;
141 if (argc != 1 || c->display_usage) {
144 _("net registry enumerate <path>\n"));
147 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
151 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
152 if (!W_ERROR_IS_OK(werr)) {
153 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
158 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
162 print_registry_key(subkey_name, &modtime);
164 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
169 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
173 print_registry_value_with_name(valname, valvalue);
175 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
185 static int net_registry_createkey(struct net_context *c, int argc,
189 enum winreg_CreateAction action;
191 struct registry_key *hivekey = NULL;
192 struct registry_key *subkey = NULL;
193 TALLOC_CTX *ctx = talloc_stackframe();
196 if (argc != 1 || c->display_usage) {
199 _("net registry createkey <path>\n"));
202 _("net registry createkey "
203 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
206 if (strlen(argv[0]) == 0) {
207 d_fprintf(stderr, _("error: zero length key name given\n"));
211 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
212 if (!W_ERROR_IS_OK(werr)) {
213 d_fprintf(stderr, _("open_hive failed: %s\n"),
218 werr = reg_createkey(ctx, hivekey, subkeyname, REG_KEY_WRITE,
220 if (!W_ERROR_IS_OK(werr)) {
221 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
226 case REG_ACTION_NONE:
227 d_printf(_("createkey did nothing -- huh?\n"));
229 case REG_CREATED_NEW_KEY:
230 d_printf(_("createkey created %s\n"), argv[0]);
232 case REG_OPENED_EXISTING_KEY:
233 d_printf(_("createkey opened existing %s\n"), argv[0]);
244 static int net_registry_deletekey_internal(struct net_context *c, int argc,
250 struct registry_key *hivekey = NULL;
251 TALLOC_CTX *ctx = talloc_stackframe();
254 if (argc != 1 || c->display_usage) {
257 _("net registry deletekey <path>\n"));
260 _("net registry deletekey "
261 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
264 if (strlen(argv[0]) == 0) {
265 d_fprintf(stderr, _("error: zero length key name given\n"));
269 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
270 if (!W_ERROR_IS_OK(werr)) {
271 d_fprintf(stderr, "open_hive %s: %s\n", _("failed"),
277 werr = reg_deletekey_recursive(hivekey, subkeyname);
279 werr = reg_deletekey(hivekey, subkeyname);
281 if (!W_ERROR_IS_OK(werr) &&
282 !(c->opt_force && W_ERROR_EQUAL(werr, WERR_BADFILE)))
284 d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"),
296 static int net_registry_deletekey(struct net_context *c, int argc,
299 return net_registry_deletekey_internal(c, argc, argv, false);
302 static int net_registry_deletekey_recursive(struct net_context *c, int argc,
305 return net_registry_deletekey_internal(c, argc, argv, true);
308 static int net_registry_getvalue_internal(struct net_context *c, int argc,
309 const char **argv, bool raw)
313 struct registry_key *key = NULL;
314 struct registry_value *value = NULL;
315 TALLOC_CTX *ctx = talloc_stackframe();
317 if (argc != 2 || c->display_usage) {
318 d_fprintf(stderr, "%s\n%s",
320 _("net registry getvalue <key> <valuename>\n"));
324 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
325 if (!W_ERROR_IS_OK(werr)) {
326 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
330 werr = reg_queryvalue(ctx, key, argv[1], &value);
331 if (!W_ERROR_IS_OK(werr)) {
332 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
337 print_registry_value(value, raw);
346 static int net_registry_getvalue(struct net_context *c, int argc,
349 return net_registry_getvalue_internal(c, argc, argv, false);
352 static int net_registry_getvalueraw(struct net_context *c, int argc,
355 return net_registry_getvalue_internal(c, argc, argv, true);
358 static int net_registry_getvaluesraw(struct net_context *c, int argc,
363 struct registry_key *key = NULL;
364 TALLOC_CTX *ctx = talloc_stackframe();
367 if (argc != 1 || c->display_usage) {
368 d_fprintf(stderr, "usage: net rpc registry getvaluesraw "
373 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
374 if (!W_ERROR_IS_OK(werr)) {
375 d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
381 struct registry_value *val;
383 werr = reg_enumvalue(talloc_tos(), key, idx, NULL, &val);
385 if (W_ERROR_EQUAL(werr, WERR_NO_MORE_ITEMS)) {
389 if (!W_ERROR_IS_OK(werr)) {
392 print_registry_value(val, true);
401 static int net_registry_setvalue(struct net_context *c, int argc,
405 struct registry_value value;
406 struct registry_key *key = NULL;
408 TALLOC_CTX *ctx = talloc_stackframe();
410 if (argc < 4 || c->display_usage) {
411 d_fprintf(stderr, "%s\n%s",
413 _("net registry setvalue <key> <valuename> "
414 "<type> [<val>]+\n"));
418 if (!strequal(argv[2], "multi_sz") && (argc != 4)) {
419 d_fprintf(stderr, _("Too many args for type %s\n"), argv[2]);
423 if (strequal(argv[2], "dword")) {
424 uint32_t v = strtoul(argv[3], NULL, 10);
425 value.type = REG_DWORD;
426 value.data = data_blob_talloc(ctx, NULL, 4);
427 SIVAL(value.data.data, 0, v);
428 } else if (strequal(argv[2], "sz")) {
430 if (!push_reg_sz(ctx, &value.data, argv[3])) {
433 } else if (strequal(argv[2], "multi_sz")) {
435 int count = argc - 3;
437 value.type = REG_MULTI_SZ;
438 array = talloc_zero_array(ctx, const char *, count + 1);
442 for (i=0; i < count; i++) {
443 array[i] = talloc_strdup(array, argv[count+i]);
444 if (array[i] == NULL) {
448 if (!push_reg_multi_sz(ctx, &value.data, array)) {
452 d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
456 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
457 if (!W_ERROR_IS_OK(werr)) {
458 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
462 werr = reg_setvalue(key, argv[1], &value);
463 if (!W_ERROR_IS_OK(werr)) {
464 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
476 struct net_registry_increment_state {
478 const char *valuename;
484 static void net_registry_increment_fn(void *private_data)
486 struct net_registry_increment_state *state =
487 (struct net_registry_increment_state *)private_data;
488 struct registry_value *value;
489 struct registry_key *key = NULL;
492 state->werr = open_key(talloc_tos(), state->keyname,
493 REG_KEY_READ|REG_KEY_WRITE, &key);
494 if (!W_ERROR_IS_OK(state->werr)) {
495 d_fprintf(stderr, _("open_key failed: %s\n"),
496 win_errstr(state->werr));
500 state->werr = reg_queryvalue(key, key, state->valuename, &value);
501 if (!W_ERROR_IS_OK(state->werr)) {
502 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
503 win_errstr(state->werr));
507 if (value->type != REG_DWORD) {
508 d_fprintf(stderr, _("value not a DWORD: %s\n"),
509 str_regtype(value->type));
513 if (value->data.length < 4) {
514 d_fprintf(stderr, _("value too short for regular DWORD\n"));
518 v = IVAL(value->data.data, 0);
519 v += state->increment;
522 SIVAL(value->data.data, 0, v);
524 state->werr = reg_setvalue(key, state->valuename, value);
525 if (!W_ERROR_IS_OK(state->werr)) {
526 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
527 win_errstr(state->werr));
536 static int net_registry_increment(struct net_context *c, int argc,
539 struct net_registry_increment_state state;
543 if (argc < 2 || c->display_usage) {
544 d_fprintf(stderr, "%s\n%s",
546 _("net registry increment <key> <valuename> "
551 state.keyname = argv[0];
552 state.valuename = argv[1];
556 state.increment = strtoul(argv[2], NULL, 10);
559 status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
560 timeval_set(600, 0), procid_self(),
561 net_registry_increment_fn, &state);
562 if (!NT_STATUS_IS_OK(status)) {
563 d_fprintf(stderr, _("g_lock_do failed: %s\n"),
567 if (!W_ERROR_IS_OK(state.werr)) {
568 d_fprintf(stderr, _("increment failed: %s\n"),
569 win_errstr(state.werr));
573 d_printf(_("%u\n"), (unsigned)state.newvalue);
581 static int net_registry_deletevalue(struct net_context *c, int argc,
585 struct registry_key *key = NULL;
586 TALLOC_CTX *ctx = talloc_stackframe();
589 if (argc != 2 || c->display_usage) {
590 d_fprintf(stderr, "%s\n%s",
592 _("net registry deletevalue <key> <valuename>\n"));
596 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
597 if (!W_ERROR_IS_OK(werr)) {
598 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
602 werr = reg_deletevalue(key, argv[1]);
603 if (!W_ERROR_IS_OK(werr)) {
604 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
616 static WERROR net_registry_getsd_internal(struct net_context *c,
619 struct security_descriptor **sd)
622 struct registry_key *key = NULL;
623 TALLOC_CTX *ctx = talloc_stackframe();
624 uint32_t access_mask = REG_KEY_READ |
625 SEC_FLAG_MAXIMUM_ALLOWED |
626 SEC_FLAG_SYSTEM_SECURITY;
629 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
630 * is denied with these perms right now...
632 access_mask = REG_KEY_READ;
635 d_fprintf(stderr, _("internal error: invalid argument\n"));
636 werr = WERR_INVALID_PARAM;
640 if (strlen(keyname) == 0) {
641 d_fprintf(stderr, _("error: zero length key name given\n"));
642 werr = WERR_INVALID_PARAM;
646 werr = open_key(ctx, keyname, access_mask, &key);
647 if (!W_ERROR_IS_OK(werr)) {
648 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
653 werr = reg_getkeysecurity(mem_ctx, key, sd);
654 if (!W_ERROR_IS_OK(werr)) {
655 d_fprintf(stderr, "%s%s\n", _("reg_getkeysecurity failed: "),
667 static int net_registry_getsd(struct net_context *c, int argc,
672 struct security_descriptor *secdesc = NULL;
673 TALLOC_CTX *ctx = talloc_stackframe();
675 if (argc != 1 || c->display_usage) {
678 _("net registry getsd <path>\n"));
681 _("net registry getsd 'HKLM\\Software\\Samba'\n"));
685 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
686 if (!W_ERROR_IS_OK(werr)) {
690 display_sec_desc(secdesc);
699 static int net_registry_getsd_sddl(struct net_context *c,
700 int argc, const char **argv)
704 struct security_descriptor *secdesc = NULL;
705 TALLOC_CTX *ctx = talloc_stackframe();
707 if (argc != 1 || c->display_usage) {
710 _("net registry getsd_sddl <path>\n"));
713 _("net registry getsd_sddl 'HKLM\\Software\\Samba'\n"));
717 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
718 if (!W_ERROR_IS_OK(werr)) {
722 d_printf("%s\n", sddl_encode(ctx, secdesc, get_global_sam_sid()));
731 static WERROR net_registry_setsd_internal(struct net_context *c,
734 struct security_descriptor *sd)
737 struct registry_key *key = NULL;
738 TALLOC_CTX *ctx = talloc_stackframe();
739 uint32_t access_mask = REG_KEY_WRITE |
740 SEC_FLAG_MAXIMUM_ALLOWED |
741 SEC_FLAG_SYSTEM_SECURITY;
744 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
745 * is denied with these perms right now...
747 access_mask = REG_KEY_WRITE;
749 if (strlen(keyname) == 0) {
750 d_fprintf(stderr, _("error: zero length key name given\n"));
751 werr = WERR_INVALID_PARAM;
755 werr = open_key(ctx, keyname, access_mask, &key);
756 if (!W_ERROR_IS_OK(werr)) {
757 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
762 werr = reg_setkeysecurity(key, sd);
763 if (!W_ERROR_IS_OK(werr)) {
764 d_fprintf(stderr, "%s%s\n", _("reg_setkeysecurity failed: "),
776 static int net_registry_setsd_sddl(struct net_context *c,
777 int argc, const char **argv)
781 struct security_descriptor *secdesc = NULL;
782 TALLOC_CTX *ctx = talloc_stackframe();
784 if (argc != 2 || c->display_usage) {
787 _("net registry setsd_sddl <path> <security_descriptor>\n"));
790 _("net registry setsd_sddl 'HKLM\\Software\\Samba'\n"));
794 secdesc = sddl_decode(ctx, argv[1], get_global_sam_sid());
795 if (secdesc == NULL) {
799 werr = net_registry_setsd_internal(c, ctx, argv[0], secdesc);
800 if (!W_ERROR_IS_OK(werr)) {
811 /******************************************************************************/
813 * @defgroup net_registry net registry
817 * @defgroup net_registry_import Import
818 * @ingroup net_registry
827 static WERROR import_create_key(struct import_ctx* ctx,
828 struct registry_key* parent,
829 const char* name, void** pkey, bool* existing)
832 void* mem_ctx = talloc_new(ctx->mem_ctx);
834 struct registry_key* key = NULL;
835 enum winreg_CreateAction action;
837 if (parent == NULL) {
838 char* subkeyname = NULL;
839 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
840 &parent, &subkeyname);
841 if (!W_ERROR_IS_OK(werr)) {
842 d_fprintf(stderr, _("open_hive failed: %s\n"),
849 action = REG_ACTION_NONE;
850 werr = reg_createkey(mem_ctx, parent, name, REG_KEY_WRITE,
852 if (!W_ERROR_IS_OK(werr)) {
853 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
858 if (action == REG_ACTION_NONE) {
859 d_fprintf(stderr, _("createkey did nothing -- huh?\n"));
860 werr = WERR_CREATE_FAILED;
864 if (existing != NULL) {
865 *existing = (action == REG_OPENED_EXISTING_KEY);
869 *pkey = talloc_steal(ctx->mem_ctx, key);
873 talloc_free(mem_ctx);
877 static WERROR import_close_key(struct import_ctx* ctx,
878 struct registry_key* key)
883 static WERROR import_delete_key(struct import_ctx* ctx,
884 struct registry_key* parent, const char* name)
887 void* mem_ctx = talloc_new(talloc_tos());
889 if (parent == NULL) {
890 char* subkeyname = NULL;
891 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
892 &parent, &subkeyname);
893 if (!W_ERROR_IS_OK(werr)) {
894 d_fprintf(stderr, _("open_hive failed: %s\n"),
901 werr = reg_deletekey_recursive(parent, name);
902 if (!W_ERROR_IS_OK(werr)) {
903 d_fprintf(stderr, "reg_deletekey_recursive %s: %s\n", _("failed"),
909 talloc_free(mem_ctx);
913 static WERROR import_create_val (struct import_ctx* ctx,
914 struct registry_key* parent, const char* name,
915 const struct registry_value* value)
919 if (parent == NULL) {
920 return WERR_INVALID_PARAM;
923 werr = reg_setvalue(parent, name, value);
924 if (!W_ERROR_IS_OK(werr)) {
925 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
931 static WERROR import_delete_val (struct import_ctx* ctx, struct registry_key* parent, const char* name) {
934 if (parent == NULL) {
935 return WERR_INVALID_PARAM;
938 werr = reg_deletevalue(parent, name);
939 if (!W_ERROR_IS_OK(werr)) {
940 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
948 static int net_registry_import(struct net_context *c, int argc,
951 struct import_ctx import_ctx;
952 struct reg_import_callback import_callback = {
954 .closekey = (reg_import_callback_closekey_t)&import_close_key,
955 .createkey = (reg_import_callback_createkey_t)&import_create_key,
956 .deletekey = (reg_import_callback_deletekey_t)&import_delete_key,
957 .deleteval = (reg_import_callback_deleteval_t)&import_delete_val,
958 .setval.registry_value = (reg_import_callback_setval_registry_value_t)
960 .setval_type = REGISTRY_VALUE,
966 if (argc < 1 || argc > 2 || c->display_usage) {
969 _("net registry import <reg> [options]\n"));
972 _("net registry import file.reg enc=CP1252\n"));
976 ZERO_STRUCT(import_ctx);
977 import_ctx.mem_ctx = talloc_stackframe();
980 regdb_transaction_start();
982 ret = reg_parse_file(argv[0],
983 reg_import_adapter(import_ctx.mem_ctx,
985 (argc > 1) ? argv[1] : NULL
988 d_printf("reg_parse_file failed: transaction canceled\n");
989 regdb_transaction_cancel();
991 regdb_transaction_commit();
995 talloc_free(import_ctx.mem_ctx);
1001 /******************************************************************************/
1004 * @defgroup net_registry_export Export
1005 * @ingroup net_registry
1009 static int registry_export(TALLOC_CTX *ctx, /*const*/ struct registry_key* key,
1010 struct reg_format* f)
1016 struct registry_value *valvalue = NULL;
1017 char *valname = NULL;
1019 struct registry_key* subkey = NULL;
1020 char *subkey_name = NULL;
1023 reg_format_registry_key(f, key, false);
1027 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
1028 W_ERROR_IS_OK(werr);
1031 reg_format_registry_value(f, valname, valvalue);
1033 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1034 d_fprintf(stderr, _("reg_enumvalue failed: %s\n"),
1039 /* recurse on subkeys */
1041 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
1042 W_ERROR_IS_OK(werr);
1045 werr = reg_openkey(ctx, key, subkey_name, REG_KEY_READ,
1047 if (!W_ERROR_IS_OK(werr)) {
1048 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
1053 registry_export(ctx, subkey, f);
1055 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1056 d_fprintf(stderr, _("reg_enumkey failed: %s\n"),
1065 static int net_registry_export(struct net_context *c, int argc,
1070 struct registry_key *key = NULL;
1071 TALLOC_CTX *ctx = talloc_stackframe();
1072 struct reg_format* f=NULL;
1074 if (argc < 2 || argc > 3 || c->display_usage) {
1077 _("net registry export <path> <file> [opt]\n"));
1080 _("net registry export 'HKLM\\Software\\Samba' "
1081 "samba.reg regedit5\n"));
1085 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
1086 if (!W_ERROR_IS_OK(werr)) {
1087 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
1091 f = reg_format_file(ctx, argv[1], (argc > 2) ? argv[2] : NULL);
1093 d_fprintf(stderr, _("open file failed: %s\n"), strerror(errno));
1097 ret = registry_export(ctx, key, f);
1105 /******************************************************************************/
1107 * @defgroup net_registry_convert Convert
1108 * @ingroup net_registry
1112 static int net_registry_convert(struct net_context *c, int argc,
1117 const char* in_opt = NULL;
1118 const char* out_opt = NULL;
1120 if (argc < 2 || argc > 4|| c->display_usage) {
1123 _("net registry convert <in> <out> [in_opt] [out_opt]\n"
1124 "net registry convert <in> <out> [out_opt]\n"));
1127 _("net registry convert in.reg out.reg regedit4,enc=CP1252\n"));
1131 mem_ctx = talloc_stackframe();
1148 ret = reg_parse_file(argv[0], (struct reg_parse_callback*)
1149 reg_format_file(mem_ctx, argv[1], out_opt),
1152 talloc_free(mem_ctx);
1158 /******************************************************************************/
1160 int net_registry(struct net_context *c, int argc, const char **argv)
1164 struct functable func[] = {
1167 net_registry_enumerate,
1168 NET_TRANSPORT_LOCAL,
1169 N_("Enumerate registry keys and values"),
1170 N_("net registry enumerate\n"
1171 " Enumerate registry keys and values")
1175 net_registry_createkey,
1176 NET_TRANSPORT_LOCAL,
1177 N_("Create a new registry key"),
1178 N_("net registry createkey\n"
1179 " Create a new registry key")
1183 net_registry_deletekey,
1184 NET_TRANSPORT_LOCAL,
1185 N_("Delete a registry key"),
1186 N_("net registry deletekey\n"
1187 " Delete a registry key")
1190 "deletekey_recursive",
1191 net_registry_deletekey_recursive,
1192 NET_TRANSPORT_LOCAL,
1193 N_("Delete a registry key with subkeys"),
1194 N_("net registry deletekey_recursive\n"
1195 " Delete a registry key with subkeys")
1199 net_registry_getvalue,
1200 NET_TRANSPORT_LOCAL,
1201 N_("Print a registry value"),
1202 N_("net registry getvalue\n"
1203 " Print a registry value")
1207 net_registry_getvalueraw,
1208 NET_TRANSPORT_LOCAL,
1209 N_("Print a registry value (raw format)"),
1210 N_("net registry getvalueraw\n"
1211 " Print a registry value (raw format)")
1215 net_registry_getvaluesraw,
1216 NET_TRANSPORT_LOCAL,
1217 "Print all values of a key in raw format",
1218 "net registry getvaluesraw <key>\n"
1219 " Print a registry value (raw format)"
1223 net_registry_setvalue,
1224 NET_TRANSPORT_LOCAL,
1225 N_("Set a new registry value"),
1226 N_("net registry setvalue\n"
1227 " Set a new registry value")
1231 net_registry_increment,
1232 NET_TRANSPORT_LOCAL,
1233 N_("Increment a DWORD registry value under a lock"),
1234 N_("net registry increment\n"
1235 " Increment a DWORD registry value under a lock")
1239 net_registry_deletevalue,
1240 NET_TRANSPORT_LOCAL,
1241 N_("Delete a registry value"),
1242 N_("net registry deletevalue\n"
1243 " Delete a registry value")
1248 NET_TRANSPORT_LOCAL,
1249 N_("Get security descriptor"),
1250 N_("net registry getsd\n"
1251 " Get security descriptor")
1255 net_registry_getsd_sddl,
1256 NET_TRANSPORT_LOCAL,
1257 N_("Get security descriptor in sddl format"),
1258 N_("net registry getsd_sddl\n"
1259 " Get security descriptor in sddl format")
1263 net_registry_setsd_sddl,
1264 NET_TRANSPORT_LOCAL,
1265 N_("Set security descriptor from sddl format string"),
1266 N_("net registry setsd_sddl\n"
1267 " Set security descriptor from sddl format string")
1271 net_registry_import,
1272 NET_TRANSPORT_LOCAL,
1273 N_("Import .reg file"),
1274 N_("net registry import\n"
1275 " Import .reg file")
1279 net_registry_export,
1280 NET_TRANSPORT_LOCAL,
1281 N_("Export .reg file"),
1282 N_("net registry export\n"
1283 " Export .reg file")
1287 net_registry_convert,
1288 NET_TRANSPORT_LOCAL,
1289 N_("Convert .reg file"),
1290 N_("net registry convert\n"
1291 " Convert .reg file")
1293 { NULL, NULL, 0, NULL, NULL }
1296 if (!W_ERROR_IS_OK(registry_init_basic())) {
1300 ret = net_run_function(c, argc, argv, "net registry", func);