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"
45 * split given path into hive and remaining path and open the hive key
47 static WERROR open_hive(TALLOC_CTX *ctx, const char *path,
48 uint32 desired_access,
49 struct registry_key **hive,
53 struct security_token *token = NULL;
54 char *hivename = NULL;
55 char *tmp_subkeyname = NULL;
56 TALLOC_CTX *tmp_ctx = talloc_stackframe();
58 if ((hive == NULL) || (subkeyname == NULL)) {
59 werr = WERR_INVALID_PARAM;
63 werr = split_hive_key(tmp_ctx, path, &hivename, &tmp_subkeyname);
64 if (!W_ERROR_IS_OK(werr)) {
67 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
68 if (*subkeyname == NULL) {
73 werr = ntstatus_to_werror(registry_create_admin_token(tmp_ctx, &token));
74 if (!W_ERROR_IS_OK(werr)) {
78 werr = reg_openhive(ctx, hivename, desired_access, token, hive);
79 if (!W_ERROR_IS_OK(werr)) {
90 static WERROR open_key(TALLOC_CTX *ctx, const char *path,
91 uint32 desired_access,
92 struct registry_key **key)
95 char *subkey_name = NULL;
96 struct registry_key *hive = NULL;
97 TALLOC_CTX *tmp_ctx = talloc_stackframe();
99 if ((path == NULL) || (key == NULL)) {
100 return WERR_INVALID_PARAM;
103 werr = open_hive(tmp_ctx, path, desired_access, &hive, &subkey_name);
104 if (!W_ERROR_IS_OK(werr)) {
105 d_fprintf(stderr, _("open_hive failed: %s\n"),
110 werr = reg_openkey(ctx, hive, subkey_name, desired_access, key);
111 if (!W_ERROR_IS_OK(werr)) {
112 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
120 TALLOC_FREE(tmp_ctx);
126 * the main "net registry" function implementations
130 static int net_registry_enumerate(struct net_context *c, int argc,
134 struct registry_key *key = NULL;
135 TALLOC_CTX *ctx = talloc_stackframe();
139 char *valname = NULL;
140 struct registry_value *valvalue = NULL;
143 if (argc != 1 || c->display_usage) {
146 _("net registry enumerate <path>\n"));
149 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
153 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
154 if (!W_ERROR_IS_OK(werr)) {
155 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
160 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
164 print_registry_key(subkey_name, &modtime);
166 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
171 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
175 print_registry_value_with_name(valname, valvalue);
177 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
187 static int net_registry_createkey(struct net_context *c, int argc,
191 enum winreg_CreateAction action;
193 struct registry_key *hivekey = NULL;
194 struct registry_key *subkey = NULL;
195 TALLOC_CTX *ctx = talloc_stackframe();
198 if (argc != 1 || c->display_usage) {
201 _("net registry createkey <path>\n"));
204 _("net registry createkey "
205 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
208 if (strlen(argv[0]) == 0) {
209 d_fprintf(stderr, _("error: zero length key name given\n"));
213 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
214 if (!W_ERROR_IS_OK(werr)) {
215 d_fprintf(stderr, _("open_hive failed: %s\n"),
220 werr = reg_createkey(ctx, hivekey, subkeyname, REG_KEY_WRITE,
222 if (!W_ERROR_IS_OK(werr)) {
223 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
228 case REG_ACTION_NONE:
229 d_printf(_("createkey did nothing -- huh?\n"));
231 case REG_CREATED_NEW_KEY:
232 d_printf(_("createkey created %s\n"), argv[0]);
234 case REG_OPENED_EXISTING_KEY:
235 d_printf(_("createkey opened existing %s\n"), argv[0]);
246 static int net_registry_deletekey_internal(struct net_context *c, int argc,
252 struct registry_key *hivekey = NULL;
253 TALLOC_CTX *ctx = talloc_stackframe();
256 if (argc != 1 || c->display_usage) {
259 _("net registry deletekey <path>\n"));
262 _("net registry deletekey "
263 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
266 if (strlen(argv[0]) == 0) {
267 d_fprintf(stderr, _("error: zero length key name given\n"));
271 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
272 if (!W_ERROR_IS_OK(werr)) {
273 d_fprintf(stderr, "open_hive %s: %s\n", _("failed"),
279 werr = reg_deletekey_recursive(hivekey, subkeyname);
281 werr = reg_deletekey(hivekey, subkeyname);
283 if (!W_ERROR_IS_OK(werr) &&
284 !(c->opt_force && W_ERROR_EQUAL(werr, WERR_BADFILE)))
286 d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"),
298 static int net_registry_deletekey(struct net_context *c, int argc,
301 return net_registry_deletekey_internal(c, argc, argv, false);
304 static int net_registry_deletekey_recursive(struct net_context *c, int argc,
307 return net_registry_deletekey_internal(c, argc, argv, true);
310 static int net_registry_getvalue_internal(struct net_context *c, int argc,
311 const char **argv, bool raw)
315 struct registry_key *key = NULL;
316 struct registry_value *value = NULL;
317 TALLOC_CTX *ctx = talloc_stackframe();
319 if (argc != 2 || c->display_usage) {
320 d_fprintf(stderr, "%s\n%s",
322 _("net registry getvalue <key> <valuename>\n"));
326 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
327 if (!W_ERROR_IS_OK(werr)) {
328 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
332 werr = reg_queryvalue(ctx, key, argv[1], &value);
333 if (!W_ERROR_IS_OK(werr)) {
334 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
339 print_registry_value(value, raw);
348 static int net_registry_getvalue(struct net_context *c, int argc,
351 return net_registry_getvalue_internal(c, argc, argv, false);
354 static int net_registry_getvalueraw(struct net_context *c, int argc,
357 return net_registry_getvalue_internal(c, argc, argv, true);
360 static int net_registry_getvaluesraw(struct net_context *c, int argc,
365 struct registry_key *key = NULL;
366 TALLOC_CTX *ctx = talloc_stackframe();
369 if (argc != 1 || c->display_usage) {
370 d_fprintf(stderr, "usage: net rpc registry getvaluesraw "
375 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
376 if (!W_ERROR_IS_OK(werr)) {
377 d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
383 struct registry_value *val;
385 werr = reg_enumvalue(talloc_tos(), key, idx, NULL, &val);
387 if (W_ERROR_EQUAL(werr, WERR_NO_MORE_ITEMS)) {
391 if (!W_ERROR_IS_OK(werr)) {
394 print_registry_value(val, true);
403 static int net_registry_setvalue(struct net_context *c, int argc,
407 struct registry_value value;
408 struct registry_key *key = NULL;
410 TALLOC_CTX *ctx = talloc_stackframe();
412 if (argc < 4 || c->display_usage) {
413 d_fprintf(stderr, "%s\n%s",
415 _("net registry setvalue <key> <valuename> "
416 "<type> [<val>]+\n"));
420 if (!strequal(argv[2], "multi_sz") && (argc != 4)) {
421 d_fprintf(stderr, _("Too many args for type %s\n"), argv[2]);
425 if (strequal(argv[2], "dword")) {
426 uint32_t v = strtoul(argv[3], NULL, 10);
427 value.type = REG_DWORD;
428 value.data = data_blob_talloc(ctx, NULL, 4);
429 SIVAL(value.data.data, 0, v);
430 } else if (strequal(argv[2], "sz")) {
432 if (!push_reg_sz(ctx, &value.data, argv[3])) {
435 } else if (strequal(argv[2], "multi_sz")) {
437 int count = argc - 3;
439 value.type = REG_MULTI_SZ;
440 array = talloc_zero_array(ctx, const char *, count + 1);
444 for (i=0; i < count; i++) {
445 array[i] = talloc_strdup(array, argv[count+i]);
446 if (array[i] == NULL) {
450 if (!push_reg_multi_sz(ctx, &value.data, array)) {
454 d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
458 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
459 if (!W_ERROR_IS_OK(werr)) {
460 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
464 werr = reg_setvalue(key, argv[1], &value);
465 if (!W_ERROR_IS_OK(werr)) {
466 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
478 struct net_registry_increment_state {
480 const char *valuename;
486 static void net_registry_increment_fn(void *private_data)
488 struct net_registry_increment_state *state =
489 (struct net_registry_increment_state *)private_data;
490 struct registry_value *value;
491 struct registry_key *key = NULL;
494 state->werr = open_key(talloc_tos(), state->keyname,
495 REG_KEY_READ|REG_KEY_WRITE, &key);
496 if (!W_ERROR_IS_OK(state->werr)) {
497 d_fprintf(stderr, _("open_key failed: %s\n"),
498 win_errstr(state->werr));
502 state->werr = reg_queryvalue(key, key, state->valuename, &value);
503 if (!W_ERROR_IS_OK(state->werr)) {
504 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
505 win_errstr(state->werr));
509 if (value->type != REG_DWORD) {
510 d_fprintf(stderr, _("value not a DWORD: %s\n"),
511 str_regtype(value->type));
515 if (value->data.length < 4) {
516 d_fprintf(stderr, _("value too short for regular DWORD\n"));
520 v = IVAL(value->data.data, 0);
521 v += state->increment;
524 SIVAL(value->data.data, 0, v);
526 state->werr = reg_setvalue(key, state->valuename, value);
527 if (!W_ERROR_IS_OK(state->werr)) {
528 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
529 win_errstr(state->werr));
538 static int net_registry_increment(struct net_context *c, int argc,
541 struct net_registry_increment_state state;
545 if (argc < 2 || c->display_usage) {
546 d_fprintf(stderr, "%s\n%s",
548 _("net registry increment <key> <valuename> "
553 state.keyname = argv[0];
554 state.valuename = argv[1];
558 state.increment = strtoul(argv[2], NULL, 10);
561 status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
562 timeval_set(600, 0), procid_self(),
563 net_registry_increment_fn, &state);
564 if (!NT_STATUS_IS_OK(status)) {
565 d_fprintf(stderr, _("g_lock_do failed: %s\n"),
569 if (!W_ERROR_IS_OK(state.werr)) {
570 d_fprintf(stderr, _("increment failed: %s\n"),
571 win_errstr(state.werr));
575 d_printf(_("%u\n"), (unsigned)state.newvalue);
583 static int net_registry_deletevalue(struct net_context *c, int argc,
587 struct registry_key *key = NULL;
588 TALLOC_CTX *ctx = talloc_stackframe();
591 if (argc != 2 || c->display_usage) {
592 d_fprintf(stderr, "%s\n%s",
594 _("net registry deletevalue <key> <valuename>\n"));
598 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
599 if (!W_ERROR_IS_OK(werr)) {
600 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
604 werr = reg_deletevalue(key, argv[1]);
605 if (!W_ERROR_IS_OK(werr)) {
606 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
618 static WERROR net_registry_getsd_internal(struct net_context *c,
621 struct security_descriptor **sd)
624 struct registry_key *key = NULL;
625 TALLOC_CTX *ctx = talloc_stackframe();
626 uint32_t access_mask = REG_KEY_READ |
627 SEC_FLAG_MAXIMUM_ALLOWED |
628 SEC_FLAG_SYSTEM_SECURITY;
631 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
632 * is denied with these perms right now...
634 access_mask = REG_KEY_READ;
637 d_fprintf(stderr, _("internal error: invalid argument\n"));
638 werr = WERR_INVALID_PARAM;
642 if (strlen(keyname) == 0) {
643 d_fprintf(stderr, _("error: zero length key name given\n"));
644 werr = WERR_INVALID_PARAM;
648 werr = open_key(ctx, keyname, access_mask, &key);
649 if (!W_ERROR_IS_OK(werr)) {
650 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
655 werr = reg_getkeysecurity(mem_ctx, key, sd);
656 if (!W_ERROR_IS_OK(werr)) {
657 d_fprintf(stderr, "%s%s\n", _("reg_getkeysecurity failed: "),
669 static int net_registry_getsd(struct net_context *c, int argc,
674 struct security_descriptor *secdesc = NULL;
675 TALLOC_CTX *ctx = talloc_stackframe();
677 if (argc != 1 || c->display_usage) {
680 _("net registry getsd <path>\n"));
683 _("net registry getsd 'HKLM\\Software\\Samba'\n"));
687 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
688 if (!W_ERROR_IS_OK(werr)) {
692 display_sec_desc(secdesc);
701 static int net_registry_getsd_sddl(struct net_context *c,
702 int argc, const char **argv)
706 struct security_descriptor *secdesc = NULL;
707 TALLOC_CTX *ctx = talloc_stackframe();
709 if (argc != 1 || c->display_usage) {
712 _("net registry getsd_sddl <path>\n"));
715 _("net registry getsd_sddl 'HKLM\\Software\\Samba'\n"));
719 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
720 if (!W_ERROR_IS_OK(werr)) {
724 d_printf("%s\n", sddl_encode(ctx, secdesc, get_global_sam_sid()));
733 static WERROR net_registry_setsd_internal(struct net_context *c,
736 struct security_descriptor *sd)
739 struct registry_key *key = NULL;
740 TALLOC_CTX *ctx = talloc_stackframe();
741 uint32_t access_mask = REG_KEY_WRITE |
742 SEC_FLAG_MAXIMUM_ALLOWED |
743 SEC_FLAG_SYSTEM_SECURITY;
746 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
747 * is denied with these perms right now...
749 access_mask = REG_KEY_WRITE;
751 if (strlen(keyname) == 0) {
752 d_fprintf(stderr, _("error: zero length key name given\n"));
753 werr = WERR_INVALID_PARAM;
757 werr = open_key(ctx, keyname, access_mask, &key);
758 if (!W_ERROR_IS_OK(werr)) {
759 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
764 werr = reg_setkeysecurity(key, sd);
765 if (!W_ERROR_IS_OK(werr)) {
766 d_fprintf(stderr, "%s%s\n", _("reg_setkeysecurity failed: "),
778 static int net_registry_setsd_sddl(struct net_context *c,
779 int argc, const char **argv)
783 struct security_descriptor *secdesc = NULL;
784 TALLOC_CTX *ctx = talloc_stackframe();
786 if (argc != 2 || c->display_usage) {
789 _("net registry setsd_sddl <path> <security_descriptor>\n"));
792 _("net registry setsd_sddl 'HKLM\\Software\\Samba'\n"));
796 secdesc = sddl_decode(ctx, argv[1], get_global_sam_sid());
797 if (secdesc == NULL) {
801 werr = net_registry_setsd_internal(c, ctx, argv[0], secdesc);
802 if (!W_ERROR_IS_OK(werr)) {
813 /******************************************************************************/
815 * @defgroup net_registry net registry
819 * @defgroup net_registry_import Import
820 * @ingroup net_registry
829 static WERROR import_create_key(struct import_ctx* ctx,
830 struct registry_key* parent,
831 const char* name, void** pkey, bool* existing)
834 void* mem_ctx = talloc_new(ctx->mem_ctx);
836 struct registry_key* key = NULL;
837 enum winreg_CreateAction action;
839 if (parent == NULL) {
840 char* subkeyname = NULL;
841 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
842 &parent, &subkeyname);
843 if (!W_ERROR_IS_OK(werr)) {
844 d_fprintf(stderr, _("open_hive failed: %s\n"),
851 action = REG_ACTION_NONE;
852 werr = reg_createkey(mem_ctx, parent, name, REG_KEY_WRITE,
854 if (!W_ERROR_IS_OK(werr)) {
855 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
860 if (action == REG_ACTION_NONE) {
861 d_fprintf(stderr, _("createkey did nothing -- huh?\n"));
862 werr = WERR_CREATE_FAILED;
866 if (existing != NULL) {
867 *existing = (action == REG_OPENED_EXISTING_KEY);
871 *pkey = talloc_steal(ctx->mem_ctx, key);
875 talloc_free(mem_ctx);
879 static WERROR import_close_key(struct import_ctx* ctx,
880 struct registry_key* key)
885 static WERROR import_delete_key(struct import_ctx* ctx,
886 struct registry_key* parent, const char* name)
889 void* mem_ctx = talloc_new(talloc_tos());
891 if (parent == NULL) {
892 char* subkeyname = NULL;
893 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
894 &parent, &subkeyname);
895 if (!W_ERROR_IS_OK(werr)) {
896 d_fprintf(stderr, _("open_hive failed: %s\n"),
903 werr = reg_deletekey_recursive(parent, name);
904 if (!W_ERROR_IS_OK(werr)) {
905 d_fprintf(stderr, "reg_deletekey_recursive %s: %s\n", _("failed"),
911 talloc_free(mem_ctx);
915 static WERROR import_create_val (struct import_ctx* ctx,
916 struct registry_key* parent, const char* name,
917 const struct registry_value* value)
921 if (parent == NULL) {
922 return WERR_INVALID_PARAM;
925 werr = reg_setvalue(parent, name, value);
926 if (!W_ERROR_IS_OK(werr)) {
927 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
933 static WERROR import_delete_val (struct import_ctx* ctx, struct registry_key* parent, const char* name) {
936 if (parent == NULL) {
937 return WERR_INVALID_PARAM;
940 werr = reg_deletevalue(parent, name);
941 if (!W_ERROR_IS_OK(werr)) {
942 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
950 static int net_registry_import(struct net_context *c, int argc,
953 struct import_ctx import_ctx;
954 struct reg_import_callback import_callback = {
956 .closekey = (reg_import_callback_closekey_t)&import_close_key,
957 .createkey = (reg_import_callback_createkey_t)&import_create_key,
958 .deletekey = (reg_import_callback_deletekey_t)&import_delete_key,
959 .deleteval = (reg_import_callback_deleteval_t)&import_delete_val,
960 .setval.registry_value = (reg_import_callback_setval_registry_value_t)
962 .setval_type = REGISTRY_VALUE,
968 if (argc < 1 || argc > 2 || c->display_usage) {
971 _("net registry import <reg> [options]\n"));
974 _("net registry import file.reg enc=CP1252\n"));
978 ZERO_STRUCT(import_ctx);
979 import_ctx.mem_ctx = talloc_stackframe();
982 regdb_transaction_start();
984 ret = reg_parse_file(argv[0],
985 reg_import_adapter(import_ctx.mem_ctx,
987 (argc > 1) ? argv[1] : NULL
990 d_printf("reg_parse_file failed: transaction canceled\n");
991 regdb_transaction_cancel();
993 regdb_transaction_commit();
997 talloc_free(import_ctx.mem_ctx);
1003 /******************************************************************************/
1006 * @defgroup net_registry_export Export
1007 * @ingroup net_registry
1011 static int registry_export(TALLOC_CTX *ctx, /*const*/ struct registry_key* key,
1012 struct reg_format* f)
1018 struct registry_value *valvalue = NULL;
1019 char *valname = NULL;
1021 struct registry_key* subkey = NULL;
1022 char *subkey_name = NULL;
1025 reg_format_registry_key(f, key, false);
1029 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
1030 W_ERROR_IS_OK(werr);
1033 reg_format_registry_value(f, valname, valvalue);
1035 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1036 d_fprintf(stderr, _("reg_enumvalue failed: %s\n"),
1041 /* recurse on subkeys */
1043 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
1044 W_ERROR_IS_OK(werr);
1047 werr = reg_openkey(ctx, key, subkey_name, REG_KEY_READ,
1049 if (!W_ERROR_IS_OK(werr)) {
1050 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
1055 registry_export(ctx, subkey, f);
1057 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1058 d_fprintf(stderr, _("reg_enumkey failed: %s\n"),
1067 static int net_registry_export(struct net_context *c, int argc,
1072 struct registry_key *key = NULL;
1073 TALLOC_CTX *ctx = talloc_stackframe();
1074 struct reg_format* f=NULL;
1076 if (argc < 2 || argc > 3 || c->display_usage) {
1079 _("net registry export <path> <file> [opt]\n"));
1082 _("net registry export 'HKLM\\Software\\Samba' "
1083 "samba.reg regedit5\n"));
1087 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
1088 if (!W_ERROR_IS_OK(werr)) {
1089 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
1093 f = reg_format_file(ctx, argv[1], (argc > 2) ? argv[2] : NULL);
1095 d_fprintf(stderr, _("open file failed: %s\n"), strerror(errno));
1099 ret = registry_export(ctx, key, f);
1107 /******************************************************************************/
1109 * @defgroup net_registry_convert Convert
1110 * @ingroup net_registry
1114 static int net_registry_convert(struct net_context *c, int argc,
1119 const char* in_opt = NULL;
1120 const char* out_opt = NULL;
1122 if (argc < 2 || argc > 4|| c->display_usage) {
1125 _("net registry convert <in> <out> [in_opt] [out_opt]\n"
1126 "net registry convert <in> <out> [out_opt]\n"));
1129 _("net registry convert in.reg out.reg regedit4,enc=CP1252\n"));
1133 mem_ctx = talloc_stackframe();
1150 ret = reg_parse_file(argv[0], (struct reg_parse_callback*)
1151 reg_format_file(mem_ctx, argv[1], out_opt),
1154 talloc_free(mem_ctx);
1160 /******************************************************************************/
1162 int net_registry(struct net_context *c, int argc, const char **argv)
1166 struct functable func[] = {
1169 net_registry_enumerate,
1170 NET_TRANSPORT_LOCAL,
1171 N_("Enumerate registry keys and values"),
1172 N_("net registry enumerate\n"
1173 " Enumerate registry keys and values")
1177 net_registry_createkey,
1178 NET_TRANSPORT_LOCAL,
1179 N_("Create a new registry key"),
1180 N_("net registry createkey\n"
1181 " Create a new registry key")
1185 net_registry_deletekey,
1186 NET_TRANSPORT_LOCAL,
1187 N_("Delete a registry key"),
1188 N_("net registry deletekey\n"
1189 " Delete a registry key")
1192 "deletekey_recursive",
1193 net_registry_deletekey_recursive,
1194 NET_TRANSPORT_LOCAL,
1195 N_("Delete a registry key with subkeys"),
1196 N_("net registry deletekey_recursive\n"
1197 " Delete a registry key with subkeys")
1201 net_registry_getvalue,
1202 NET_TRANSPORT_LOCAL,
1203 N_("Print a registry value"),
1204 N_("net registry getvalue\n"
1205 " Print a registry value")
1209 net_registry_getvalueraw,
1210 NET_TRANSPORT_LOCAL,
1211 N_("Print a registry value (raw format)"),
1212 N_("net registry getvalueraw\n"
1213 " Print a registry value (raw format)")
1217 net_registry_getvaluesraw,
1218 NET_TRANSPORT_LOCAL,
1219 "Print all values of a key in raw format",
1220 "net registry getvaluesraw <key>\n"
1221 " Print a registry value (raw format)"
1225 net_registry_setvalue,
1226 NET_TRANSPORT_LOCAL,
1227 N_("Set a new registry value"),
1228 N_("net registry setvalue\n"
1229 " Set a new registry value")
1233 net_registry_increment,
1234 NET_TRANSPORT_LOCAL,
1235 N_("Increment a DWORD registry value under a lock"),
1236 N_("net registry increment\n"
1237 " Increment a DWORD registry value under a lock")
1241 net_registry_deletevalue,
1242 NET_TRANSPORT_LOCAL,
1243 N_("Delete a registry value"),
1244 N_("net registry deletevalue\n"
1245 " Delete a registry value")
1250 NET_TRANSPORT_LOCAL,
1251 N_("Get security descriptor"),
1252 N_("net registry getsd\n"
1253 " Get security descriptor")
1257 net_registry_getsd_sddl,
1258 NET_TRANSPORT_LOCAL,
1259 N_("Get security descriptor in sddl format"),
1260 N_("net registry getsd_sddl\n"
1261 " Get security descriptor in sddl format")
1265 net_registry_setsd_sddl,
1266 NET_TRANSPORT_LOCAL,
1267 N_("Set security descriptor from sddl format string"),
1268 N_("net registry setsd_sddl\n"
1269 " Set security descriptor from sddl format string")
1273 net_registry_import,
1274 NET_TRANSPORT_LOCAL,
1275 N_("Import .reg file"),
1276 N_("net registry import\n"
1277 " Import .reg file")
1281 net_registry_export,
1282 NET_TRANSPORT_LOCAL,
1283 N_("Export .reg file"),
1284 N_("net registry export\n"
1285 " Export .reg file")
1289 net_registry_convert,
1290 NET_TRANSPORT_LOCAL,
1291 N_("Convert .reg file"),
1292 N_("net registry convert\n"
1293 " Convert .reg file")
1295 { NULL, NULL, 0, NULL, NULL }
1298 if (!W_ERROR_IS_OK(registry_init_basic())) {
1302 ret = net_run_function(c, argc, argv, "net registry", func);