s3:net registry import: add option --precheck
[Samba.git] / source3 / utils / net_registry.c
blob8a65e0db510ee2133a0fac16297dae077e498205
1 /*
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/>.
22 #include "includes.h"
23 #include "registry.h"
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"
33 #include "registry/reg_api_util.h"
34 #include <assert.h>
35 #include "../libcli/security/display_sec.h"
36 #include "../libcli/security/sddl.h"
37 #include "../libcli/registry/util_reg.h"
38 #include "passdb/machine_sid.h"
39 #include "net_registry_check.h"
43 * Helper functions
47 /**
48 * split given path into hive and remaining path and open the hive key
50 static WERROR open_hive(TALLOC_CTX *ctx, const char *path,
51 uint32 desired_access,
52 struct registry_key **hive,
53 char **subkeyname)
55 WERROR werr;
56 struct security_token *token = NULL;
57 char *hivename = NULL;
58 char *tmp_subkeyname = NULL;
59 TALLOC_CTX *tmp_ctx = talloc_stackframe();
61 if ((hive == NULL) || (subkeyname == NULL)) {
62 werr = WERR_INVALID_PARAM;
63 goto done;
66 werr = split_hive_key(tmp_ctx, path, &hivename, &tmp_subkeyname);
67 if (!W_ERROR_IS_OK(werr)) {
68 goto done;
70 *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
71 if (*subkeyname == NULL) {
72 werr = WERR_NOMEM;
73 goto done;
76 werr = ntstatus_to_werror(registry_create_admin_token(tmp_ctx, &token));
77 if (!W_ERROR_IS_OK(werr)) {
78 goto done;
81 werr = reg_openhive(ctx, hivename, desired_access, token, hive);
82 if (!W_ERROR_IS_OK(werr)) {
83 goto done;
86 werr = WERR_OK;
88 done:
89 TALLOC_FREE(tmp_ctx);
90 return werr;
93 static WERROR open_key(TALLOC_CTX *ctx, const char *path,
94 uint32 desired_access,
95 struct registry_key **key)
97 WERROR werr;
98 char *subkey_name = NULL;
99 struct registry_key *hive = NULL;
100 TALLOC_CTX *tmp_ctx = talloc_stackframe();
102 if ((path == NULL) || (key == NULL)) {
103 return WERR_INVALID_PARAM;
106 werr = open_hive(tmp_ctx, path, desired_access, &hive, &subkey_name);
107 if (!W_ERROR_IS_OK(werr)) {
108 d_fprintf(stderr, _("open_hive failed: %s\n"),
109 win_errstr(werr));
110 goto done;
113 werr = reg_openkey(ctx, hive, subkey_name, desired_access, key);
114 if (!W_ERROR_IS_OK(werr)) {
115 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
116 win_errstr(werr));
117 goto done;
120 werr = WERR_OK;
122 done:
123 TALLOC_FREE(tmp_ctx);
124 return werr;
127 static WERROR registry_enumkey(struct registry_key* parent, const char* keyname, bool recursive)
129 WERROR werr;
130 TALLOC_CTX *ctx = talloc_stackframe();
131 char* subkey_name;
132 NTTIME modtime;
133 uint32_t count;
134 char* valname = NULL;
135 struct registry_value *valvalue = NULL;
136 struct registry_key* key = NULL;
138 werr = reg_openkey(ctx, parent, keyname, REG_KEY_READ, &key);
139 if (!W_ERROR_IS_OK(werr)) {
140 goto done;
143 if (recursive) {
144 printf("[%s]\n\n", key->key->name);
145 } else {
146 for (count = 0;
147 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
148 W_ERROR_IS_OK(werr);
149 count++)
151 print_registry_key(subkey_name, &modtime);
153 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
154 goto done;
158 for (count = 0;
159 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
160 W_ERROR_IS_OK(werr);
161 count++)
163 print_registry_value_with_name(valname, valvalue);
165 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
166 goto done;
169 if (!recursive) {
170 werr = WERR_OK;
171 goto done;
174 for (count = 0;
175 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
176 W_ERROR_IS_OK(werr);
177 count++)
179 werr = registry_enumkey(key, subkey_name, recursive);
180 if (!W_ERROR_IS_OK(werr)) {
181 goto done;
184 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
185 goto done;
188 werr = WERR_OK;
190 done:
191 TALLOC_FREE(ctx);
192 return werr;
199 * the main "net registry" function implementations
202 static int net_registry_enumerate(struct net_context *c, int argc,
203 const char **argv)
205 WERROR werr;
206 struct registry_key *key = NULL;
207 char* name = NULL;
208 TALLOC_CTX *ctx = talloc_stackframe();
209 int ret = -1;
211 if (argc != 1 || c->display_usage) {
212 d_printf("%s\n%s",
213 _("Usage:"),
214 _("net registry enumerate <path>\n"));
215 d_printf("%s\n%s",
216 _("Example:"),
217 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
218 goto done;
221 werr = open_hive(ctx, argv[0], REG_KEY_READ, &key, &name);
222 if (!W_ERROR_IS_OK(werr)) {
223 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
224 goto done;
227 werr = registry_enumkey(key, name, c->opt_reboot);
228 if (W_ERROR_IS_OK(werr)) {
229 ret = 0;
231 done:
232 TALLOC_FREE(ctx);
233 return ret;
236 static int net_registry_enumerate_recursive(struct net_context *c, int argc,
237 const char **argv)
239 WERROR werr;
240 struct registry_key *key = NULL;
241 char* name = NULL;
242 TALLOC_CTX *ctx = talloc_stackframe();
243 int ret = -1;
245 if (argc != 1 || c->display_usage) {
246 d_printf("%s\n%s",
247 _("Usage:"),
248 _("net registry enumerate <path>\n"));
249 d_printf("%s\n%s",
250 _("Example:"),
251 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
252 goto done;
255 werr = open_hive(ctx, argv[0], REG_KEY_READ, &key, &name);
256 if (!W_ERROR_IS_OK(werr)) {
257 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
258 goto done;
261 werr = registry_enumkey(key, name, true);
262 if (W_ERROR_IS_OK(werr)) {
263 ret = 0;
265 done:
266 TALLOC_FREE(ctx);
267 return ret;
271 static int net_registry_createkey(struct net_context *c, int argc,
272 const char **argv)
274 WERROR werr;
275 enum winreg_CreateAction action;
276 char *subkeyname;
277 struct registry_key *hivekey = NULL;
278 struct registry_key *subkey = NULL;
279 TALLOC_CTX *ctx = talloc_stackframe();
280 int ret = -1;
282 if (argc != 1 || c->display_usage) {
283 d_printf("%s\n%s",
284 _("Usage:"),
285 _("net registry createkey <path>\n"));
286 d_printf("%s\n%s",
287 _("Example:"),
288 _("net registry createkey "
289 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
290 goto done;
292 if (strlen(argv[0]) == 0) {
293 d_fprintf(stderr, _("error: zero length key name given\n"));
294 goto done;
297 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
298 if (!W_ERROR_IS_OK(werr)) {
299 d_fprintf(stderr, _("open_hive failed: %s\n"),
300 win_errstr(werr));
301 goto done;
304 werr = reg_createkey(ctx, hivekey, subkeyname, REG_KEY_WRITE,
305 &subkey, &action);
306 if (!W_ERROR_IS_OK(werr)) {
307 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
308 win_errstr(werr));
309 goto done;
311 switch (action) {
312 case REG_ACTION_NONE:
313 d_printf(_("createkey did nothing -- huh?\n"));
314 break;
315 case REG_CREATED_NEW_KEY:
316 d_printf(_("createkey created %s\n"), argv[0]);
317 break;
318 case REG_OPENED_EXISTING_KEY:
319 d_printf(_("createkey opened existing %s\n"), argv[0]);
320 break;
323 ret = 0;
325 done:
326 TALLOC_FREE(ctx);
327 return ret;
330 static int net_registry_deletekey_internal(struct net_context *c, int argc,
331 const char **argv,
332 bool recursive)
334 WERROR werr;
335 char *subkeyname;
336 struct registry_key *hivekey = NULL;
337 TALLOC_CTX *ctx = talloc_stackframe();
338 int ret = -1;
340 if (argc != 1 || c->display_usage) {
341 d_printf("%s\n%s",
342 _("Usage:"),
343 _("net registry deletekey <path>\n"));
344 d_printf("%s\n%s",
345 _("Example:"),
346 _("net registry deletekey "
347 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
348 goto done;
350 if (strlen(argv[0]) == 0) {
351 d_fprintf(stderr, _("error: zero length key name given\n"));
352 goto done;
355 werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
356 if (!W_ERROR_IS_OK(werr)) {
357 d_fprintf(stderr, "open_hive %s: %s\n", _("failed"),
358 win_errstr(werr));
359 goto done;
362 if (recursive) {
363 werr = reg_deletekey_recursive(hivekey, subkeyname);
364 } else {
365 werr = reg_deletekey(hivekey, subkeyname);
367 if (!W_ERROR_IS_OK(werr) &&
368 !(c->opt_force && W_ERROR_EQUAL(werr, WERR_BADFILE)))
370 d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"),
371 win_errstr(werr));
372 goto done;
375 ret = 0;
377 done:
378 TALLOC_FREE(ctx);
379 return ret;
382 static int net_registry_deletekey(struct net_context *c, int argc,
383 const char **argv)
385 return net_registry_deletekey_internal(c, argc, argv, false);
388 static int net_registry_deletekey_recursive(struct net_context *c, int argc,
389 const char **argv)
391 return net_registry_deletekey_internal(c, argc, argv, true);
394 static int net_registry_getvalue_internal(struct net_context *c, int argc,
395 const char **argv, bool raw)
397 WERROR werr;
398 int ret = -1;
399 struct registry_key *key = NULL;
400 struct registry_value *value = NULL;
401 TALLOC_CTX *ctx = talloc_stackframe();
403 if (argc != 2 || c->display_usage) {
404 d_fprintf(stderr, "%s\n%s",
405 _("Usage:"),
406 _("net registry getvalue <key> <valuename>\n"));
407 goto done;
410 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
411 if (!W_ERROR_IS_OK(werr)) {
412 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
413 goto done;
416 werr = reg_queryvalue(ctx, key, argv[1], &value);
417 if (!W_ERROR_IS_OK(werr)) {
418 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
419 win_errstr(werr));
420 goto done;
423 print_registry_value(value, raw);
425 ret = 0;
427 done:
428 TALLOC_FREE(ctx);
429 return ret;
432 static int net_registry_getvalue(struct net_context *c, int argc,
433 const char **argv)
435 return net_registry_getvalue_internal(c, argc, argv, false);
438 static int net_registry_getvalueraw(struct net_context *c, int argc,
439 const char **argv)
441 return net_registry_getvalue_internal(c, argc, argv, true);
444 static int net_registry_getvaluesraw(struct net_context *c, int argc,
445 const char **argv)
447 WERROR werr;
448 int ret = -1;
449 struct registry_key *key = NULL;
450 TALLOC_CTX *ctx = talloc_stackframe();
451 uint32_t idx;
453 if (argc != 1 || c->display_usage) {
454 d_fprintf(stderr, "usage: net rpc registry getvaluesraw "
455 "<key>\n");
456 goto done;
459 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
460 if (!W_ERROR_IS_OK(werr)) {
461 d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
462 goto done;
465 idx = 0;
466 while (true) {
467 struct registry_value *val;
469 werr = reg_enumvalue(talloc_tos(), key, idx, NULL, &val);
471 if (W_ERROR_EQUAL(werr, WERR_NO_MORE_ITEMS)) {
472 ret = 0;
473 break;
475 if (!W_ERROR_IS_OK(werr)) {
476 break;
478 print_registry_value(val, true);
479 TALLOC_FREE(val);
480 idx += 1;
482 done:
483 TALLOC_FREE(ctx);
484 return ret;
487 static int net_registry_setvalue(struct net_context *c, int argc,
488 const char **argv)
490 WERROR werr;
491 struct registry_value value;
492 struct registry_key *key = NULL;
493 int ret = -1;
494 TALLOC_CTX *ctx = talloc_stackframe();
496 if (argc < 4 || c->display_usage) {
497 d_fprintf(stderr, "%s\n%s",
498 _("Usage:"),
499 _("net registry setvalue <key> <valuename> "
500 "<type> [<val>]+\n"));
501 goto done;
504 if (!strequal(argv[2], "multi_sz") && (argc != 4)) {
505 d_fprintf(stderr, _("Too many args for type %s\n"), argv[2]);
506 goto done;
509 if (strequal(argv[2], "dword")) {
510 uint32_t v = strtoul(argv[3], NULL, 10);
511 value.type = REG_DWORD;
512 value.data = data_blob_talloc(ctx, NULL, 4);
513 SIVAL(value.data.data, 0, v);
514 } else if (strequal(argv[2], "sz")) {
515 value.type = REG_SZ;
516 if (!push_reg_sz(ctx, &value.data, argv[3])) {
517 goto done;
519 } else if (strequal(argv[2], "multi_sz")) {
520 const char **array;
521 int count = argc - 3;
522 int i;
523 value.type = REG_MULTI_SZ;
524 array = talloc_zero_array(ctx, const char *, count + 1);
525 if (array == NULL) {
526 goto done;
528 for (i=0; i < count; i++) {
529 array[i] = talloc_strdup(array, argv[count+i]);
530 if (array[i] == NULL) {
531 goto done;
534 if (!push_reg_multi_sz(ctx, &value.data, array)) {
535 goto done;
537 } else {
538 d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
539 goto done;
542 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
543 if (!W_ERROR_IS_OK(werr)) {
544 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
545 goto done;
548 werr = reg_setvalue(key, argv[1], &value);
549 if (!W_ERROR_IS_OK(werr)) {
550 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
551 win_errstr(werr));
552 goto done;
555 ret = 0;
557 done:
558 TALLOC_FREE(ctx);
559 return ret;
562 struct net_registry_increment_state {
563 const char *keyname;
564 const char *valuename;
565 uint32_t increment;
566 uint32_t newvalue;
567 WERROR werr;
570 static void net_registry_increment_fn(void *private_data)
572 struct net_registry_increment_state *state =
573 (struct net_registry_increment_state *)private_data;
574 struct registry_value *value;
575 struct registry_key *key = NULL;
576 uint32_t v;
578 state->werr = open_key(talloc_tos(), state->keyname,
579 REG_KEY_READ|REG_KEY_WRITE, &key);
580 if (!W_ERROR_IS_OK(state->werr)) {
581 d_fprintf(stderr, _("open_key failed: %s\n"),
582 win_errstr(state->werr));
583 goto done;
586 state->werr = reg_queryvalue(key, key, state->valuename, &value);
587 if (!W_ERROR_IS_OK(state->werr)) {
588 d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
589 win_errstr(state->werr));
590 goto done;
593 if (value->type != REG_DWORD) {
594 d_fprintf(stderr, _("value not a DWORD: %s\n"),
595 str_regtype(value->type));
596 goto done;
599 if (value->data.length < 4) {
600 d_fprintf(stderr, _("value too short for regular DWORD\n"));
601 goto done;
604 v = IVAL(value->data.data, 0);
605 v += state->increment;
606 state->newvalue = v;
608 SIVAL(value->data.data, 0, v);
610 state->werr = reg_setvalue(key, state->valuename, value);
611 if (!W_ERROR_IS_OK(state->werr)) {
612 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
613 win_errstr(state->werr));
614 goto done;
617 done:
618 TALLOC_FREE(key);
619 return;
622 static int net_registry_increment(struct net_context *c, int argc,
623 const char **argv)
625 struct net_registry_increment_state state;
626 NTSTATUS status;
627 int ret = -1;
629 if (argc < 2 || c->display_usage) {
630 d_fprintf(stderr, "%s\n%s",
631 _("Usage:"),
632 _("net registry increment <key> <valuename> "
633 "[<increment>]\n"));
634 goto done;
637 state.keyname = argv[0];
638 state.valuename = argv[1];
640 state.increment = 1;
641 if (argc == 3) {
642 state.increment = strtoul(argv[2], NULL, 10);
645 status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
646 timeval_set(600, 0),
647 net_registry_increment_fn, &state);
648 if (!NT_STATUS_IS_OK(status)) {
649 d_fprintf(stderr, _("g_lock_do failed: %s\n"),
650 nt_errstr(status));
651 goto done;
653 if (!W_ERROR_IS_OK(state.werr)) {
654 d_fprintf(stderr, _("increment failed: %s\n"),
655 win_errstr(state.werr));
656 goto done;
659 d_printf(_("%u\n"), (unsigned)state.newvalue);
661 ret = 0;
663 done:
664 return ret;
667 static int net_registry_deletevalue(struct net_context *c, int argc,
668 const char **argv)
670 WERROR werr;
671 struct registry_key *key = NULL;
672 TALLOC_CTX *ctx = talloc_stackframe();
673 int ret = -1;
675 if (argc != 2 || c->display_usage) {
676 d_fprintf(stderr, "%s\n%s",
677 _("Usage:"),
678 _("net registry deletevalue <key> <valuename>\n"));
679 goto done;
682 werr = open_key(ctx, argv[0], REG_KEY_WRITE, &key);
683 if (!W_ERROR_IS_OK(werr)) {
684 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
685 goto done;
688 werr = reg_deletevalue(key, argv[1]);
689 if (!W_ERROR_IS_OK(werr)) {
690 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
691 win_errstr(werr));
692 goto done;
695 ret = 0;
697 done:
698 TALLOC_FREE(ctx);
699 return ret;
702 static WERROR net_registry_getsd_internal(struct net_context *c,
703 TALLOC_CTX *mem_ctx,
704 const char *keyname,
705 struct security_descriptor **sd)
707 WERROR werr;
708 struct registry_key *key = NULL;
709 TALLOC_CTX *ctx = talloc_stackframe();
710 uint32_t access_mask = REG_KEY_READ |
711 SEC_FLAG_MAXIMUM_ALLOWED |
712 SEC_FLAG_SYSTEM_SECURITY;
715 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
716 * is denied with these perms right now...
718 access_mask = REG_KEY_READ;
720 if (sd == NULL) {
721 d_fprintf(stderr, _("internal error: invalid argument\n"));
722 werr = WERR_INVALID_PARAM;
723 goto done;
726 if (strlen(keyname) == 0) {
727 d_fprintf(stderr, _("error: zero length key name given\n"));
728 werr = WERR_INVALID_PARAM;
729 goto done;
732 werr = open_key(ctx, keyname, access_mask, &key);
733 if (!W_ERROR_IS_OK(werr)) {
734 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
735 win_errstr(werr));
736 goto done;
739 werr = reg_getkeysecurity(mem_ctx, key, sd);
740 if (!W_ERROR_IS_OK(werr)) {
741 d_fprintf(stderr, "%s%s\n", _("reg_getkeysecurity failed: "),
742 win_errstr(werr));
743 goto done;
746 werr = WERR_OK;
748 done:
749 TALLOC_FREE(ctx);
750 return werr;
753 static int net_registry_getsd(struct net_context *c, int argc,
754 const char **argv)
756 WERROR werr;
757 int ret = -1;
758 struct security_descriptor *secdesc = NULL;
759 TALLOC_CTX *ctx = talloc_stackframe();
761 if (argc != 1 || c->display_usage) {
762 d_printf("%s\n%s",
763 _("Usage:"),
764 _("net registry getsd <path>\n"));
765 d_printf("%s\n%s",
766 _("Example:"),
767 _("net registry getsd 'HKLM\\Software\\Samba'\n"));
768 goto done;
771 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
772 if (!W_ERROR_IS_OK(werr)) {
773 goto done;
776 display_sec_desc(secdesc);
778 ret = 0;
780 done:
781 TALLOC_FREE(ctx);
782 return ret;
785 static int net_registry_getsd_sddl(struct net_context *c,
786 int argc, const char **argv)
788 WERROR werr;
789 int ret = -1;
790 struct security_descriptor *secdesc = NULL;
791 TALLOC_CTX *ctx = talloc_stackframe();
793 if (argc != 1 || c->display_usage) {
794 d_printf("%s\n%s",
795 _("Usage:"),
796 _("net registry getsd_sddl <path>\n"));
797 d_printf("%s\n%s",
798 _("Example:"),
799 _("net registry getsd_sddl 'HKLM\\Software\\Samba'\n"));
800 goto done;
803 werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
804 if (!W_ERROR_IS_OK(werr)) {
805 goto done;
808 d_printf("%s\n", sddl_encode(ctx, secdesc, get_global_sam_sid()));
810 ret = 0;
812 done:
813 TALLOC_FREE(ctx);
814 return ret;
817 static WERROR net_registry_setsd_internal(struct net_context *c,
818 TALLOC_CTX *mem_ctx,
819 const char *keyname,
820 struct security_descriptor *sd)
822 WERROR werr;
823 struct registry_key *key = NULL;
824 TALLOC_CTX *ctx = talloc_stackframe();
825 uint32_t access_mask = REG_KEY_WRITE |
826 SEC_FLAG_MAXIMUM_ALLOWED |
827 SEC_FLAG_SYSTEM_SECURITY;
830 * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
831 * is denied with these perms right now...
833 access_mask = REG_KEY_WRITE;
835 if (strlen(keyname) == 0) {
836 d_fprintf(stderr, _("error: zero length key name given\n"));
837 werr = WERR_INVALID_PARAM;
838 goto done;
841 werr = open_key(ctx, keyname, access_mask, &key);
842 if (!W_ERROR_IS_OK(werr)) {
843 d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
844 win_errstr(werr));
845 goto done;
848 werr = reg_setkeysecurity(key, sd);
849 if (!W_ERROR_IS_OK(werr)) {
850 d_fprintf(stderr, "%s%s\n", _("reg_setkeysecurity failed: "),
851 win_errstr(werr));
852 goto done;
855 werr = WERR_OK;
857 done:
858 TALLOC_FREE(ctx);
859 return werr;
862 static int net_registry_setsd_sddl(struct net_context *c,
863 int argc, const char **argv)
865 WERROR werr;
866 int ret = -1;
867 struct security_descriptor *secdesc = NULL;
868 TALLOC_CTX *ctx = talloc_stackframe();
870 if (argc != 2 || c->display_usage) {
871 d_printf("%s\n%s",
872 _("Usage:"),
873 _("net registry setsd_sddl <path> <security_descriptor>\n"));
874 d_printf("%s\n%s",
875 _("Example:"),
876 _("net registry setsd_sddl 'HKLM\\Software\\Samba'\n"));
877 goto done;
880 secdesc = sddl_decode(ctx, argv[1], get_global_sam_sid());
881 if (secdesc == NULL) {
882 goto done;
885 werr = net_registry_setsd_internal(c, ctx, argv[0], secdesc);
886 if (!W_ERROR_IS_OK(werr)) {
887 goto done;
890 ret = 0;
892 done:
893 TALLOC_FREE(ctx);
894 return ret;
897 /******************************************************************************/
899 * @defgroup net_registry net registry
903 * @defgroup net_registry_import Import
904 * @ingroup net_registry
905 * @{
908 struct import_ctx {
909 TALLOC_CTX *mem_ctx;
913 static WERROR import_create_key(struct import_ctx* ctx,
914 struct registry_key* parent,
915 const char* name, void** pkey, bool* existing)
917 WERROR werr;
918 void* mem_ctx = talloc_new(ctx->mem_ctx);
920 struct registry_key* key = NULL;
921 enum winreg_CreateAction action;
923 if (parent == NULL) {
924 char* subkeyname = NULL;
925 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
926 &parent, &subkeyname);
927 if (!W_ERROR_IS_OK(werr)) {
928 d_fprintf(stderr, _("open_hive failed: %s\n"),
929 win_errstr(werr));
930 goto done;
932 name = subkeyname;
935 action = REG_ACTION_NONE;
936 werr = reg_createkey(mem_ctx, parent, name, REG_KEY_WRITE,
937 &key, &action);
938 if (!W_ERROR_IS_OK(werr)) {
939 d_fprintf(stderr, _("reg_createkey failed: %s\n"),
940 win_errstr(werr));
941 goto done;
944 if (action == REG_ACTION_NONE) {
945 d_fprintf(stderr, _("createkey did nothing -- huh?\n"));
946 werr = WERR_CREATE_FAILED;
947 goto done;
950 if (existing != NULL) {
951 *existing = (action == REG_OPENED_EXISTING_KEY);
954 if (pkey!=NULL) {
955 *pkey = talloc_steal(ctx->mem_ctx, key);
958 done:
959 talloc_free(mem_ctx);
960 return werr;
963 static WERROR import_close_key(struct import_ctx* ctx,
964 struct registry_key* key)
966 return WERR_OK;
969 static WERROR import_delete_key(struct import_ctx* ctx,
970 struct registry_key* parent, const char* name)
972 WERROR werr;
973 void* mem_ctx = talloc_new(talloc_tos());
975 if (parent == NULL) {
976 char* subkeyname = NULL;
977 werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
978 &parent, &subkeyname);
979 if (!W_ERROR_IS_OK(werr)) {
980 d_fprintf(stderr, _("open_hive failed: %s\n"),
981 win_errstr(werr));
982 goto done;
984 name = subkeyname;
987 werr = reg_deletekey_recursive(parent, name);
988 if (!W_ERROR_IS_OK(werr)) {
989 d_fprintf(stderr, "reg_deletekey_recursive %s: %s\n", _("failed"),
990 win_errstr(werr));
991 goto done;
994 done:
995 talloc_free(mem_ctx);
996 return werr;
999 static WERROR import_create_val (struct import_ctx* ctx,
1000 struct registry_key* parent, const char* name,
1001 const struct registry_value* value)
1003 WERROR werr;
1005 if (parent == NULL) {
1006 return WERR_INVALID_PARAM;
1009 werr = reg_setvalue(parent, name, value);
1010 if (!W_ERROR_IS_OK(werr)) {
1011 d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
1012 win_errstr(werr));
1014 return werr;
1017 static WERROR import_delete_val (struct import_ctx* ctx, struct registry_key* parent, const char* name) {
1018 WERROR werr;
1020 if (parent == NULL) {
1021 return WERR_INVALID_PARAM;
1024 werr = reg_deletevalue(parent, name);
1025 if (!W_ERROR_IS_OK(werr)) {
1026 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
1027 win_errstr(werr));
1030 return werr;
1033 struct precheck_ctx {
1034 TALLOC_CTX *mem_ctx;
1035 bool failed;
1038 static WERROR precheck_create_key(struct precheck_ctx *ctx,
1039 struct registry_key *parent,
1040 const char *name, void **pkey, bool *existing)
1042 WERROR werr;
1043 TALLOC_CTX *frame = talloc_stackframe();
1044 struct registry_key *key = NULL;
1046 if (parent == NULL) {
1047 char *subkeyname = NULL;
1048 werr = open_hive(frame, name, REG_KEY_READ,
1049 &parent, &subkeyname);
1050 if (!W_ERROR_IS_OK(werr)) {
1051 d_printf("Precheck: open_hive of [%s] failed: %s\n",
1052 name, win_errstr(werr));
1053 goto done;
1055 name = subkeyname;
1058 werr = reg_openkey(frame, parent, name, 0, &key);
1059 if (!W_ERROR_IS_OK(werr)) {
1060 d_printf("Precheck: openkey [%s] failed: %s\n",
1061 name, win_errstr(werr));
1062 goto done;
1065 if (existing != NULL) {
1066 *existing = true;
1069 if (pkey != NULL) {
1070 *pkey = talloc_steal(ctx->mem_ctx, key);
1073 done:
1074 talloc_free(frame);
1075 ctx->failed = !W_ERROR_IS_OK(werr);
1076 return werr;
1079 static WERROR precheck_close_key(struct precheck_ctx *ctx,
1080 struct registry_key *key)
1082 talloc_free(key);
1083 return WERR_OK;
1086 static WERROR precheck_delete_key(struct precheck_ctx *ctx,
1087 struct registry_key *parent, const char *name)
1089 WERROR werr;
1090 TALLOC_CTX *frame = talloc_stackframe();
1091 struct registry_key *key;
1093 if (parent == NULL) {
1094 char *subkeyname = NULL;
1095 werr = open_hive(frame, name, REG_KEY_READ,
1096 &parent, &subkeyname);
1097 if (!W_ERROR_IS_OK(werr)) {
1098 d_printf("Precheck: open_hive of [%s] failed: %s\n",
1099 name, win_errstr(werr));
1100 goto done;
1102 name = subkeyname;
1105 werr = reg_openkey(ctx->mem_ctx, parent, name, 0, &key);
1106 if (W_ERROR_IS_OK(werr)) {
1107 d_printf("Precheck: key [%s\\%s] should not exist\n",
1108 parent->key->name, name);
1109 werr = WERR_FILE_EXISTS;
1110 } else if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1111 werr = WERR_OK;
1112 } else {
1113 d_printf("Precheck: openkey [%s\\%s] failed: %s\n",
1114 parent->key->name, name, win_errstr(werr));
1117 done:
1118 talloc_free(frame);
1119 ctx->failed = !W_ERROR_IS_OK(werr);
1120 return werr;
1123 static WERROR precheck_create_val(struct precheck_ctx *ctx,
1124 struct registry_key *parent,
1125 const char *name,
1126 const struct registry_value *value)
1128 TALLOC_CTX *frame = talloc_stackframe();
1129 struct registry_value *old;
1130 WERROR werr;
1132 SMB_ASSERT(parent);
1134 werr = reg_queryvalue(frame, parent, name, &old);
1135 if (!W_ERROR_IS_OK(werr)) {
1136 d_printf("Precheck: queryvalue \"%s\" of [%s] failed: %s\n",
1137 name, parent->key->name, win_errstr(werr));
1138 goto done;
1140 if (registry_value_cmp(value, old) != 0) {
1141 d_printf("Precheck: unexpected value \"%s\" of key [%s]\n",
1142 name, parent->key->name);
1143 ctx->failed = true;
1145 done:
1146 talloc_free(frame);
1147 return werr;
1150 static WERROR precheck_delete_val(struct precheck_ctx *ctx,
1151 struct registry_key *parent,
1152 const char *name)
1154 TALLOC_CTX *frame = talloc_stackframe();
1155 struct registry_value *old;
1156 WERROR werr;
1158 SMB_ASSERT(parent);
1160 werr = reg_queryvalue(frame, parent, name, &old);
1161 if (W_ERROR_IS_OK(werr)) {
1162 d_printf("Precheck: value \"%s\" of key [%s] should not exist\n",
1163 name, parent->key->name);
1164 werr = WERR_FILE_EXISTS;
1165 } else if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1166 werr = WERR_OK;
1167 } else {
1168 printf("Precheck: queryvalue \"%s\" of key [%s] failed: %s\n",
1169 name, parent->key->name, win_errstr(werr));
1172 talloc_free(frame);
1173 ctx->failed = !W_ERROR_IS_OK(werr);
1174 return werr;
1177 static bool import_precheck(const char *fname, const char *parse_options)
1179 TALLOC_CTX *mem_ctx = talloc_tos();
1180 struct precheck_ctx precheck_ctx = {
1181 .mem_ctx = mem_ctx,
1182 .failed = false,
1184 struct reg_import_callback precheck_callback = {
1185 .openkey = NULL,
1186 .closekey = (reg_import_callback_closekey_t)&precheck_close_key,
1187 .createkey = (reg_import_callback_createkey_t)&precheck_create_key,
1188 .deletekey = (reg_import_callback_deletekey_t)&precheck_delete_key,
1189 .deleteval = (reg_import_callback_deleteval_t)&precheck_delete_val,
1190 .setval = {
1191 .registry_value = (reg_import_callback_setval_registry_value_t)
1192 &precheck_create_val,
1194 .setval_type = REGISTRY_VALUE,
1195 .data = &precheck_ctx
1197 struct reg_parse_callback *parse_callback;
1198 int ret;
1200 if (!fname) {
1201 return true;
1204 parse_callback = reg_import_adapter(mem_ctx, precheck_callback);
1205 if (parse_callback == NULL) {
1206 d_printf("talloc failed\n");
1207 return false;
1210 ret = reg_parse_file(fname, parse_callback, parse_options);
1212 if (ret < 0 || precheck_ctx.failed) {
1213 d_printf("Precheck failed\n");
1214 return false;
1216 return true;
1220 static int net_registry_import(struct net_context *c, int argc,
1221 const char **argv)
1223 TALLOC_CTX *frame = talloc_stackframe();
1224 struct import_ctx import_ctx = {
1225 .mem_ctx = frame,
1227 struct reg_import_callback import_callback = {
1228 .openkey = NULL,
1229 .closekey = (reg_import_callback_closekey_t)&import_close_key,
1230 .createkey = (reg_import_callback_createkey_t)&import_create_key,
1231 .deletekey = (reg_import_callback_deletekey_t)&import_delete_key,
1232 .deleteval = (reg_import_callback_deleteval_t)&import_delete_val,
1233 .setval = {
1234 .registry_value = (reg_import_callback_setval_registry_value_t)
1235 &import_create_val,
1237 .setval_type = REGISTRY_VALUE,
1238 .data = &import_ctx
1240 const char *parse_options = (argc > 1) ? argv[1] : NULL;
1241 int ret = -1;
1242 WERROR werr;
1244 if (argc < 1 || argc > 2 || c->display_usage) {
1245 d_printf("%s\n%s",
1246 _("Usage:"),
1247 _("net registry import <reg> [options]\n"));
1248 d_printf("%s\n%s",
1249 _("Example:"),
1250 _("net registry import file.reg enc=CP1252\n"));
1251 goto done;
1254 werr = regdb_open();
1255 if (!W_ERROR_IS_OK(werr)) {
1256 d_printf("Failed to open regdb: %s\n", win_errstr(werr));
1257 goto done;
1259 werr = regdb_transaction_start();
1260 if (!W_ERROR_IS_OK(werr)) {
1261 d_printf("Failed to start transaction on regdb: %s\n",
1262 win_errstr(werr));
1263 goto done;
1266 if (import_precheck(c->opt_precheck, parse_options)) {
1267 ret = reg_parse_file(argv[0],
1268 reg_import_adapter(frame, import_callback),
1269 parse_options);
1272 if (ret < 0) {
1273 d_printf("Transaction canceled!\n");
1274 regdb_transaction_cancel();
1275 } else {
1276 werr = regdb_transaction_commit();
1277 if (!W_ERROR_IS_OK(werr)) {
1278 d_printf("Failed to commit transaction on regdb: %s\n",
1279 win_errstr(werr));
1280 goto done;
1284 regdb_close();
1285 done:
1286 talloc_free(frame);
1287 return ret;
1289 /**@}*/
1291 /******************************************************************************/
1294 * @defgroup net_registry_export Export
1295 * @ingroup net_registry
1296 * @{
1299 static int registry_export(TALLOC_CTX *ctx, /*const*/ struct registry_key* key,
1300 struct reg_format* f)
1302 int ret=-1;
1303 WERROR werr;
1304 uint32_t count;
1306 struct registry_value *valvalue = NULL;
1307 char *valname = NULL;
1309 char *subkey_name = NULL;
1310 NTTIME modtime = 0;
1312 reg_format_registry_key(f, key, false);
1314 /* print values */
1315 for (count = 0;
1316 werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
1317 W_ERROR_IS_OK(werr);
1318 count++)
1320 reg_format_registry_value(f, valname, valvalue);
1322 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1323 d_fprintf(stderr, _("reg_enumvalue failed: %s\n"),
1324 win_errstr(werr));
1325 goto done;
1328 /* recurse on subkeys */
1329 for (count = 0;
1330 werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
1331 W_ERROR_IS_OK(werr);
1332 count++)
1334 struct registry_key* subkey = NULL;
1336 werr = reg_openkey(ctx, key, subkey_name, REG_KEY_READ,
1337 &subkey);
1338 if (!W_ERROR_IS_OK(werr)) {
1339 d_fprintf(stderr, _("reg_openkey failed: %s\n"),
1340 win_errstr(werr));
1341 goto done;
1344 registry_export(ctx, subkey, f);
1345 TALLOC_FREE(subkey);
1347 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
1348 d_fprintf(stderr, _("reg_enumkey failed: %s\n"),
1349 win_errstr(werr));
1350 goto done;
1352 ret = 0;
1353 done:
1354 return ret;
1357 static int net_registry_export(struct net_context *c, int argc,
1358 const char **argv)
1360 int ret=-1;
1361 WERROR werr;
1362 struct registry_key *key = NULL;
1363 TALLOC_CTX *ctx = talloc_stackframe();
1364 struct reg_format* f=NULL;
1366 if (argc < 2 || argc > 3 || c->display_usage) {
1367 d_printf("%s\n%s",
1368 _("Usage:"),
1369 _("net registry export <path> <file> [opt]\n"));
1370 d_printf("%s\n%s",
1371 _("Example:"),
1372 _("net registry export 'HKLM\\Software\\Samba' "
1373 "samba.reg regedit5\n"));
1374 goto done;
1377 werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
1378 if (!W_ERROR_IS_OK(werr)) {
1379 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
1380 goto done;
1383 f = reg_format_file(ctx, argv[1], (argc > 2) ? argv[2] : NULL);
1384 if (f == NULL) {
1385 d_fprintf(stderr, _("open file failed: %s\n"), strerror(errno));
1386 goto done;
1389 ret = registry_export(ctx, key, f);
1391 done:
1392 TALLOC_FREE(ctx);
1393 return ret;
1395 /**@}*/
1397 /******************************************************************************/
1399 * @defgroup net_registry_convert Convert
1400 * @ingroup net_registry
1401 * @{
1404 static int net_registry_convert(struct net_context *c, int argc,
1405 const char **argv)
1407 int ret;
1408 void* mem_ctx;
1409 const char* in_opt = NULL;
1410 const char* out_opt = NULL;
1412 if (argc < 2 || argc > 4|| c->display_usage) {
1413 d_printf("%s\n%s",
1414 _("Usage:"),
1415 _("net registry convert <in> <out> [in_opt] [out_opt]\n"
1416 "net registry convert <in> <out> [out_opt]\n"));
1417 d_printf("%s\n%s",
1418 _("Example:"),
1419 _("net registry convert in.reg out.reg regedit4,enc=CP1252\n"));
1420 return -1;
1423 mem_ctx = talloc_stackframe();
1425 switch (argc ) {
1426 case 2:
1427 break;
1428 case 3:
1429 out_opt = argv[2];
1430 break;
1431 case 4:
1432 out_opt = argv[3];
1433 in_opt = argv[2];
1434 break;
1435 default:
1436 assert(false);
1440 ret = reg_parse_file(argv[0], (struct reg_parse_callback*)
1441 reg_format_file(mem_ctx, argv[1], out_opt),
1442 in_opt);
1444 talloc_free(mem_ctx);
1446 return ret;
1448 /**@}*/
1450 static int net_registry_check(struct net_context *c, int argc,
1451 const char **argv)
1453 const char* dbfile;
1454 struct check_options opts;
1456 if (argc > 1|| c->display_usage) {
1457 d_printf("%s\n%s",
1458 _("Usage:"),
1459 _("net registry check [-vraTfl] [-o <ODB>] [--wipe] [<TDB>]\n"
1460 " Check a registry database.\n"
1461 " -v|--verbose\t be verbose\n"
1462 " -r|--repair\t\t interactive repair mode\n"
1463 " -a|--auto\t\t noninteractive repair mode\n"
1464 " -T|--test\t\t dry run\n"
1465 " -f|--force\t\t force\n"
1466 " -l|--lock\t\t lock <TDB> while doing the check\n"
1467 " -o|--output=<ODB>\t output database\n"
1468 " --reg-version=n\t assume database format version {n|1,2,3}\n"
1469 " --wipe\t\t create a new database from scratch\n"
1470 " --db=<TDB>\t\t registry database to open\n"));
1471 return c->display_usage ? 0 : -1;
1474 dbfile = c->opt_db ? c->opt_db : (
1475 (argc > 0) ? argv[0] :
1476 state_path("registry.tdb"));
1477 if (dbfile == NULL) {
1478 return -1;
1481 opts = (struct check_options) {
1482 .lock = c->opt_lock || c->opt_long_list_entries,
1483 .test = c->opt_testmode,
1484 .automatic = c->opt_auto,
1485 .verbose = c->opt_verbose,
1486 .force = c->opt_force,
1487 .repair = c->opt_repair || c->opt_reboot,
1488 .version = c->opt_reg_version,
1489 .output = c->opt_output,
1490 .wipe = c->opt_wipe,
1491 .implicit_db = (c->opt_db == NULL) && (argc == 0),
1494 return net_registry_check_db(dbfile, &opts);
1498 /******************************************************************************/
1500 int net_registry(struct net_context *c, int argc, const char **argv)
1502 int ret = -1;
1504 struct functable func[] = {
1506 "enumerate",
1507 net_registry_enumerate,
1508 NET_TRANSPORT_LOCAL,
1509 N_("Enumerate registry keys and values"),
1510 N_("net registry enumerate\n"
1511 " Enumerate registry keys and values")
1514 "enumerate_recursive",
1515 net_registry_enumerate_recursive,
1516 NET_TRANSPORT_LOCAL,
1517 N_("Enumerate registry keys and values"),
1518 N_("net registry enumerate_recursive\n"
1519 " Enumerate registry keys and values")
1522 "createkey",
1523 net_registry_createkey,
1524 NET_TRANSPORT_LOCAL,
1525 N_("Create a new registry key"),
1526 N_("net registry createkey\n"
1527 " Create a new registry key")
1530 "deletekey",
1531 net_registry_deletekey,
1532 NET_TRANSPORT_LOCAL,
1533 N_("Delete a registry key"),
1534 N_("net registry deletekey\n"
1535 " Delete a registry key")
1538 "deletekey_recursive",
1539 net_registry_deletekey_recursive,
1540 NET_TRANSPORT_LOCAL,
1541 N_("Delete a registry key with subkeys"),
1542 N_("net registry deletekey_recursive\n"
1543 " Delete a registry key with subkeys")
1546 "getvalue",
1547 net_registry_getvalue,
1548 NET_TRANSPORT_LOCAL,
1549 N_("Print a registry value"),
1550 N_("net registry getvalue\n"
1551 " Print a registry value")
1554 "getvalueraw",
1555 net_registry_getvalueraw,
1556 NET_TRANSPORT_LOCAL,
1557 N_("Print a registry value (raw format)"),
1558 N_("net registry getvalueraw\n"
1559 " Print a registry value (raw format)")
1562 "getvaluesraw",
1563 net_registry_getvaluesraw,
1564 NET_TRANSPORT_LOCAL,
1565 "Print all values of a key in raw format",
1566 "net registry getvaluesraw <key>\n"
1567 " Print a registry value (raw format)"
1570 "setvalue",
1571 net_registry_setvalue,
1572 NET_TRANSPORT_LOCAL,
1573 N_("Set a new registry value"),
1574 N_("net registry setvalue\n"
1575 " Set a new registry value")
1578 "increment",
1579 net_registry_increment,
1580 NET_TRANSPORT_LOCAL,
1581 N_("Increment a DWORD registry value under a lock"),
1582 N_("net registry increment\n"
1583 " Increment a DWORD registry value under a lock")
1586 "deletevalue",
1587 net_registry_deletevalue,
1588 NET_TRANSPORT_LOCAL,
1589 N_("Delete a registry value"),
1590 N_("net registry deletevalue\n"
1591 " Delete a registry value")
1594 "getsd",
1595 net_registry_getsd,
1596 NET_TRANSPORT_LOCAL,
1597 N_("Get security descriptor"),
1598 N_("net registry getsd\n"
1599 " Get security descriptor")
1602 "getsd_sddl",
1603 net_registry_getsd_sddl,
1604 NET_TRANSPORT_LOCAL,
1605 N_("Get security descriptor in sddl format"),
1606 N_("net registry getsd_sddl\n"
1607 " Get security descriptor in sddl format")
1610 "setsd_sddl",
1611 net_registry_setsd_sddl,
1612 NET_TRANSPORT_LOCAL,
1613 N_("Set security descriptor from sddl format string"),
1614 N_("net registry setsd_sddl\n"
1615 " Set security descriptor from sddl format string")
1618 "import",
1619 net_registry_import,
1620 NET_TRANSPORT_LOCAL,
1621 N_("Import .reg file"),
1622 N_("net registry import\n"
1623 " Import .reg file")
1626 "export",
1627 net_registry_export,
1628 NET_TRANSPORT_LOCAL,
1629 N_("Export .reg file"),
1630 N_("net registry export\n"
1631 " Export .reg file")
1634 "convert",
1635 net_registry_convert,
1636 NET_TRANSPORT_LOCAL,
1637 N_("Convert .reg file"),
1638 N_("net registry convert\n"
1639 " Convert .reg file")
1642 "check",
1643 net_registry_check,
1644 NET_TRANSPORT_LOCAL,
1645 N_("Check a registry database"),
1646 N_("net registry check\n"
1647 " Check a registry database")
1649 { NULL, NULL, 0, NULL, NULL }
1652 if (!c->display_usage
1653 && argc > 0
1654 && (strcasecmp_m(argv[0], "convert") != 0)
1655 && (strcasecmp_m(argv[0], "check") != 0))
1657 if (!W_ERROR_IS_OK(registry_init_basic())) {
1658 return -1;
1662 ret = net_run_function(c, argc, argv, "net registry", func);
1664 return ret;