vfs: Make function pointer names consistent. They all end in _fn
[Samba/gebeck_regimport.git] / source3 / utils / net_rpc_conf.c
blob68d5df2edf85e4a0aec0f3dd4999f4735071f3ea
1 /*
2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Local configuration interface
5 * Copyright (C) Vicentiu Ciorbaru 2011
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 * This is an interface to Samba's configuration.
24 * This tool supports local as well as remote interaction via rpc
25 * with the configuration stored in the registry.
29 #include "includes.h"
30 #include "utils/net.h"
31 #include "rpc_client/cli_pipe.h"
32 #include "../librpc/gen_ndr/ndr_samr_c.h"
33 #include "rpc_client/init_samr.h"
34 #include "../librpc/gen_ndr/ndr_winreg_c.h"
35 #include "../libcli/registry/util_reg.h"
36 #include "rpc_client/cli_winreg.h"
37 #include "lib/smbconf/smbconf.h"
38 #include "lib/smbconf/smbconf_init.h"
39 #include "lib/smbconf/smbconf_reg.h"
40 #include "lib/param/loadparm.h"
44 /* internal functions */
45 /**********************************************************
47 * usage functions
49 **********************************************************/
50 const char confpath[100] = "Software\\Samba\\smbconf";
52 static int rpc_conf_list_usage(struct net_context *c, int argc,
53 const char **argv)
55 d_printf("%s net rpc conf list\n", _("Usage:"));
56 return -1;
59 static int rpc_conf_listshares_usage(struct net_context *c, int argc,
60 const char **argv)
62 d_printf("%s net rpc conf listshares\n", _("Usage:"));
63 return -1;
66 static int rpc_conf_delshare_usage(struct net_context *c, int argc,
67 const char **argv)
69 d_printf("%s\n%s",
70 _("Usage:"),
71 _("net rpc conf delshare <sharename>\n"));
72 return -1;
75 static int rpc_conf_addshare_usage(struct net_context *c, int argc,
76 const char **argv)
78 d_printf("%s\n%s",
79 _("Usage:"),
80 _(" net rpc conf addshare <sharename> <path> "
81 "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
82 "\t<sharename> the new share name.\n"
83 "\t<path> the path on the filesystem to export.\n"
84 "\twriteable={y|N} set \"writeable to \"yes\" or "
85 "\"no\" (default) on this share.\n"
86 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
87 "\"no\" (default) on this share.\n"
88 "\t<comment> optional comment for the new share.\n"));
89 return -1;
93 static int rpc_conf_import_usage(struct net_context *c, int argc,
94 const char**argv)
96 d_printf("%s\n%s",
97 _("Usage:"),
98 _(" net rpc conf import [--test|-T] <filename> "
99 "[<servicename>]\n"
100 "\t[--test|-T] testmode - do not act, just print "
101 "what would be done\n"
102 "\t<servicename> only import service <servicename>, "
103 "ignore the rest\n"));
104 return -1;
107 static int rpc_conf_showshare_usage(struct net_context *c, int argc,
108 const char **argv)
110 d_printf("%s\n%s",
111 _("Usage:"),
112 _("net rpc conf showshare <sharename>\n"));
113 return -1;
116 static int rpc_conf_drop_usage(struct net_context *c, int argc,
117 const char **argv)
119 d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
120 return -1;
123 static int rpc_conf_getparm_usage(struct net_context *c, int argc,
124 const char **argv)
126 d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
127 _("Usage:"));
128 return -1;
131 static int rpc_conf_setparm_usage(struct net_context *c, int argc,
132 const char **argv)
134 d_printf("%s\n%s",
135 _("Usage:"),
136 _(" net rpc conf setparm <section> <param> <value>\n"));
137 return -1;
140 static int rpc_conf_delparm_usage(struct net_context *c, int argc,
141 const char **argv)
143 d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
144 _("Usage:"));
145 return -1;
148 static int rpc_conf_getincludes_usage(struct net_context *c, int argc,
149 const char **argv)
151 d_printf("%s\nnet rpc conf getincludes <sharename>\n",
152 _("Usage:"));
153 return -1;
156 static int rpc_conf_setincludes_usage(struct net_context *c, int argc,
157 const char **argv)
159 d_printf("%s\nnet rpc conf setincludes <sharename> [<filename>]*\n",
160 _("Usage:"));
161 return -1;
164 static int rpc_conf_delincludes_usage(struct net_context *c, int argc,
165 const char **argv)
167 d_printf("%s\nnet rpc conf delincludes <sharename>\n",
168 _("Usage:"));
169 return -1;
172 /**********************************************************
174 * helper functions
176 **********************************************************/
178 static bool rpc_conf_reg_valname_forbidden(const char * valname)
180 const char *forbidden_valnames[] = {
181 "lock directory",
182 "lock dir",
183 "config backend",
184 "include",
185 "includes", /* this has a special meaning internally */
186 NULL
188 const char **forbidden = NULL;
190 for (forbidden = forbidden_valnames; *forbidden != NULL; forbidden++) {
191 if (strwicmp(valname, *forbidden) == 0) {
192 return true;
195 return false;
200 * The function deletes a registry value with the name 'value' from the share
201 * with the name 'share_name'. 'parent_hnd' is the handle for the smbconf key.
203 static NTSTATUS rpc_conf_del_value(TALLOC_CTX *mem_ctx,
204 struct dcerpc_binding_handle *b,
205 struct policy_handle *parent_hnd,
206 const char *share_name,
207 const char *value,
208 WERROR *werr)
211 TALLOC_CTX *frame = talloc_stackframe();
212 NTSTATUS status = NT_STATUS_OK;
213 WERROR result = WERR_OK;
214 WERROR _werr;
216 struct winreg_String keyname, valuename;
217 struct policy_handle child_hnd;
219 ZERO_STRUCT(child_hnd);
220 ZERO_STRUCT(keyname);
221 ZERO_STRUCT(valuename);
223 keyname.name = share_name;
224 valuename.name = value;
226 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, keyname, 0,
227 REG_KEY_WRITE, &child_hnd, &result);
229 if (!(NT_STATUS_IS_OK(status))) {
230 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
231 keyname.name, nt_errstr(status));
232 goto error;
235 if (!(W_ERROR_IS_OK(result))) {
236 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
237 keyname.name, win_errstr(result));
238 goto error;
241 status = dcerpc_winreg_DeleteValue(b,
242 frame,
243 &child_hnd,
244 valuename,
245 &result);
247 if (!(NT_STATUS_IS_OK(status))) {
248 d_fprintf(stderr, _("Failed to delete value %s\n"),
249 nt_errstr(status));
250 goto error;
253 if (!(W_ERROR_IS_OK(result))) {
254 if (W_ERROR_EQUAL(result, WERR_BADFILE)){
255 result = WERR_OK;
256 goto error;
259 d_fprintf(stderr, _("Failed to delete value %s\n"),
260 win_errstr(result));
261 goto error;
264 error:
265 *werr = result;
267 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
269 TALLOC_FREE(frame);
270 return status;;
275 * The function sets a share in the registry with the parameters
276 * held in the smbconf_service struct
278 static NTSTATUS rpc_conf_set_share(TALLOC_CTX *mem_ctx,
279 struct dcerpc_binding_handle *b,
280 struct policy_handle *parent_hnd,
281 struct smbconf_service *service,
282 WERROR *werr)
284 TALLOC_CTX *frame = talloc_stackframe();
286 NTSTATUS status = NT_STATUS_OK;
287 WERROR result = WERR_OK;
288 WERROR _werr;
289 enum winreg_CreateAction action;
290 uint32_t i, j;
292 const char **includes;
294 struct winreg_String wkey, wkeyclass;
295 struct policy_handle share_hnd;
297 ZERO_STRUCT(share_hnd);
298 ZERO_STRUCT(wkey);
299 ZERO_STRUCT(wkeyclass);
301 wkey.name = service->name;
302 wkeyclass.name = "";
303 action = REG_ACTION_NONE;
305 status = dcerpc_winreg_CreateKey(b,
306 frame,
307 parent_hnd,
308 wkey,
309 wkeyclass,
311 REG_KEY_ALL,
312 NULL,
313 &share_hnd,
314 &action,
315 &result);
317 if (!NT_STATUS_IS_OK(status)) {
318 d_printf("winreg_CreateKey: Could not create smbconf key\n");
319 goto error;
322 if (!W_ERROR_IS_OK(result)) {
323 d_printf("winreg_CreateKey: Could not create smbconf key\n");
324 goto error;
327 for (i = 0; i < service->num_params; i++) {
328 if (strequal(service->param_names[i], "include") == 0)
331 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
332 service->param_names[i],
333 service->param_values[i],
334 &result);
336 if (!(NT_STATUS_IS_OK(status))) {
337 d_fprintf(stderr,
338 "ERROR: Share: '%s'\n"
339 "Could not set parameter '%s'"
340 " with value %s\n %s\n",
341 service->name,
342 service->param_names[i],
343 service->param_values[i],
344 nt_errstr(status));
345 goto error;
348 if (!(W_ERROR_IS_OK(result))) {
349 d_fprintf(stderr,
350 "ERROR: Share: '%s'\n"
351 "Could not set parameter '%s'"
352 " with value %s\n %s\n",
353 service->name,
354 service->param_names[i],
355 service->param_values[i],
356 win_errstr(result));
357 goto error;
359 } else {
361 includes = talloc_zero_array(frame,
362 const char *,
363 service->num_params + 1);
364 if (includes == NULL) {
365 result = WERR_NOMEM;
366 d_fprintf(stderr, "ERROR: out of memory\n");
367 goto error;
370 for (j = i; j < service->num_params; j++) {
372 includes[j - i] = talloc_strdup(
373 frame,
374 service->param_values[j]);
376 if (includes[j-i] == NULL) {
377 result = WERR_NOMEM;
378 d_fprintf(stderr, "ERROR: out of memory\n");
379 goto error;
383 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
384 "includes",
385 includes,
386 &result);
388 if (!(NT_STATUS_IS_OK(status))) {
389 d_fprintf(stderr, "ERROR: Share: '%s'\n"
390 "Could not set includes\n %s\n",
391 service->name,
392 nt_errstr(status));
393 goto error;
396 if (!(W_ERROR_IS_OK(result))) {
397 d_fprintf(stderr, "ERROR: Share: '%s'\n"
398 "Could not set includes\n %s\n",
399 service->name,
400 win_errstr(result));
401 goto error;
404 i = service->num_params;
408 error:
409 /* in case of error, should it delete the created key? */
410 if (!(W_ERROR_IS_OK(result))) {
411 status = werror_to_ntstatus(result);
415 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
417 TALLOC_FREE(frame);
418 return status;
423 * The function opens the registry database and retrieves
424 * as a smbconf_service struct the share with the name
425 * 'share_name'
427 static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx,
428 struct dcerpc_binding_handle *b,
429 struct policy_handle *parent_hnd,
430 const char *share_name,
431 struct smbconf_service *share,
432 WERROR *werr)
434 TALLOC_CTX *frame = talloc_stackframe();
436 NTSTATUS status = NT_STATUS_OK;
437 WERROR result = WERR_OK;
438 WERROR _werr;
439 struct policy_handle child_hnd;
440 int32_t includes_cnt, includes_idx = -1;
441 uint32_t num_vals, i, param_cnt = 0;
442 const char **val_names;
443 enum winreg_Type *types;
444 DATA_BLOB *data;
445 struct winreg_String key;
446 const char **multi_s = NULL;
447 const char *s = NULL;
448 struct smbconf_service tmp_share;
450 ZERO_STRUCT(tmp_share);
452 key.name = share_name;
453 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
454 REG_KEY_READ, &child_hnd, &result);
456 if (!(NT_STATUS_IS_OK(status))) {
457 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
458 nt_errstr(status));
459 goto error;
461 if (!(W_ERROR_IS_OK(result))) {
462 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
463 win_errstr(result));
464 goto error;
466 /* get all the info from the share key */
467 status = dcerpc_winreg_enumvals(frame,
469 &child_hnd,
470 &num_vals,
471 &val_names,
472 &types,
473 &data,
474 &result);
476 if (!(NT_STATUS_IS_OK(status))) {
477 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
478 nt_errstr(status));
479 goto error;
481 if (!(W_ERROR_IS_OK(result))) {
482 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
483 win_errstr(result));
484 goto error;
486 /* check for includes */
487 for (i = 0; i < num_vals; i++) {
488 if (strcmp(val_names[i], "includes") == 0){
489 if (!pull_reg_multi_sz(frame,
490 &data[i],
491 &multi_s))
493 result = WERR_NOMEM;
494 d_fprintf(stderr,
495 _("Failed to enumerate values: %s\n"),
496 win_errstr(result));
497 goto error;
499 includes_idx = i;
502 /* count the number of includes */
503 includes_cnt = 0;
504 if (includes_idx != -1) {
505 for (includes_cnt = 0;
506 multi_s[includes_cnt] != NULL;
507 includes_cnt ++);
509 /* place the name of the share in the smbconf_service struct */
510 tmp_share.name = talloc_strdup(frame, share_name);
511 if (tmp_share.name == NULL) {
512 result = WERR_NOMEM;
513 d_fprintf(stderr, _("Failed to create share: %s\n"),
514 win_errstr(result));
515 goto error;
517 /* place the number of parameters in the smbconf_service struct */
518 tmp_share.num_params = num_vals;
519 if (includes_idx != -1) {
520 tmp_share.num_params = num_vals + includes_cnt - 1;
522 /* allocate memory for the param_names and param_values lists */
523 tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
524 if (tmp_share.param_names == NULL) {
525 result = WERR_NOMEM;
526 d_fprintf(stderr, _("Failed to create share: %s\n"),
527 win_errstr(result));
528 goto error;
530 tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
531 if (tmp_share.param_values == NULL) {
532 result = WERR_NOMEM;
533 d_fprintf(stderr, _("Failed to create share: %s\n"),
534 win_errstr(result));
535 goto error;
537 /* place all params except includes */
538 for (i = 0; i < num_vals; i++) {
539 if (strcmp(val_names[i], "includes") != 0) {
540 if (!pull_reg_sz(frame, &data[i], &s)) {
541 result = WERR_NOMEM;
542 d_fprintf(stderr,
543 _("Failed to enumerate values: %s\n"),
544 win_errstr(result));
545 goto error;
547 /* place param_names */
548 tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
549 if (tmp_share.param_names[param_cnt] == NULL) {
550 result = WERR_NOMEM;
551 d_fprintf(stderr, _("Failed to create share: %s\n"),
552 win_errstr(result));
553 goto error;
556 /* place param_values */
557 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
558 if (tmp_share.param_values[param_cnt - 1] == NULL) {
559 result = WERR_NOMEM;
560 d_fprintf(stderr, _("Failed to create share: %s\n"),
561 win_errstr(result));
562 goto error;
566 /* place the includes last */
567 for (i = 0; i < includes_cnt; i++) {
568 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
569 if (tmp_share.param_names[param_cnt] == NULL) {
570 result = WERR_NOMEM;
571 d_fprintf(stderr, _("Failed to create share: %s\n"),
572 win_errstr(result));
573 goto error;
576 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
577 if (tmp_share.param_values[param_cnt - 1] == NULL) {
578 result = WERR_NOMEM;
579 d_fprintf(stderr, _("Failed to create share: %s\n"),
580 win_errstr(result));
581 goto error;
585 /* move everything to the main memory ctx */
586 for (i = 0; i < param_cnt; i++) {
587 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
588 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
591 tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
592 tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
593 tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
594 /* out parameter */
595 *share = tmp_share;
596 error:
597 /* close child */
598 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
599 *werr = result;
600 TALLOC_FREE(frame);
601 return status;
605 * The function prints the shares held as smbconf_service structs
606 * in a smbconf file format.
608 static int rpc_conf_print_shares(uint32_t num_shares,
609 struct smbconf_service *shares)
612 uint32_t share_count, param_count;
613 const char *indent = "\t";
615 if (num_shares == 0) {
616 return 0;
619 for (share_count = 0; share_count < num_shares; share_count++) {
620 d_printf("\n");
621 if (shares[share_count].name != NULL) {
622 d_printf("[%s]\n", shares[share_count].name);
625 for (param_count = 0;
626 param_count < shares[share_count].num_params;
627 param_count++)
629 d_printf("%s%s = %s\n",
630 indent,
631 shares[share_count].param_names[param_count],
632 shares[share_count].param_values[param_count]);
635 d_printf("\n");
637 return 0;
642 * The function openes the registry key
643 * HKLM/Software/Samba/smbconf with the give access_mask
645 static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
646 struct dcerpc_binding_handle *b,
647 uint32_t access_mask,
648 struct policy_handle *hive_hnd,
649 struct policy_handle *key_hnd,
650 WERROR *werr)
652 TALLOC_CTX *frame = talloc_stackframe();
653 NTSTATUS status = NT_STATUS_OK;
654 WERROR result = WERR_OK;
655 WERROR _werr;
656 struct policy_handle tmp_hive_hnd, tmp_key_hnd;
657 struct winreg_String key;
659 ZERO_STRUCT(key);
661 status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
662 access_mask, &tmp_hive_hnd, &result);
665 * print no error messages if it is a read only open
666 * and key does not exist
667 * error still gets returned
670 if (access_mask == REG_KEY_READ &&
671 W_ERROR_EQUAL(result, WERR_BADFILE))
673 goto error;
676 if (!(NT_STATUS_IS_OK(status))) {
677 d_fprintf(stderr, _("Failed to open hive: %s\n"),
678 nt_errstr(status));
679 goto error;
681 if (!W_ERROR_IS_OK(result)) {
682 d_fprintf(stderr, _("Failed to open hive: %s\n"),
683 win_errstr(result));
684 goto error;
687 key.name = confpath;
688 status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
689 access_mask, &tmp_key_hnd, &result);
692 * print no error messages if it is a read only open
693 * and key does not exist
694 * error still gets returned
697 if (access_mask == REG_KEY_READ &&
698 W_ERROR_EQUAL(result, WERR_BADFILE))
700 goto error;
703 if (!(NT_STATUS_IS_OK(status))) {
704 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
705 nt_errstr(status));
706 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
707 goto error;
709 if (!(W_ERROR_IS_OK(result))) {
710 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
711 win_errstr(result));
712 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
713 goto error;
716 *hive_hnd = tmp_hive_hnd;
717 *key_hnd = tmp_key_hnd;
719 error:
720 TALLOC_FREE(frame);
721 *werr = result;
723 return status;
726 /**********************************************************
728 * internal functions that provide the functionality
729 * net rpc conf
731 **********************************************************/
733 static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
734 const struct dom_sid *domain_sid,
735 const char *domain_name,
736 struct cli_state *cli,
737 struct rpc_pipe_client *pipe_hnd,
738 TALLOC_CTX *mem_ctx,
739 int argc,
740 const char **argv )
743 TALLOC_CTX *frame = talloc_stackframe();
744 NTSTATUS status = NT_STATUS_OK;
745 WERROR werr = WERR_OK;
746 WERROR _werr;
748 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
750 /* key info */
751 struct policy_handle hive_hnd, key_hnd;
752 uint32_t num_subkeys;
753 uint32_t i;
754 const char **subkeys = NULL;
757 ZERO_STRUCT(hive_hnd);
758 ZERO_STRUCT(key_hnd);
761 if (argc != 0 || c->display_usage) {
762 rpc_conf_listshares_usage(c, argc, argv);
763 status = NT_STATUS_INVALID_PARAMETER;
764 goto error;
768 status = rpc_conf_open_conf(frame,
770 REG_KEY_READ,
771 &hive_hnd,
772 &key_hnd,
773 &werr);
775 if (!(NT_STATUS_IS_OK(status))) {
776 goto error;
779 if (!(W_ERROR_IS_OK(werr))) {
780 goto error;
783 status = dcerpc_winreg_enum_keys(frame,
785 &key_hnd,
786 &num_subkeys,
787 &subkeys,
788 &werr);
790 if (!(NT_STATUS_IS_OK(status))) {
791 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
792 nt_errstr(status));
793 goto error;
796 if (!(W_ERROR_IS_OK(werr))) {
797 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
798 win_errstr(werr));
799 goto error;
802 for (i = 0; i < num_subkeys; i++) {
803 d_printf("%s\n", subkeys[i]);
806 error:
807 if (!(W_ERROR_IS_OK(werr))) {
808 status = werror_to_ntstatus(werr);
811 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
812 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
814 TALLOC_FREE(frame);
815 return status;;
818 static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
819 const struct dom_sid *domain_sid,
820 const char *domain_name,
821 struct cli_state *cli,
822 struct rpc_pipe_client *pipe_hnd,
823 TALLOC_CTX *mem_ctx,
824 int argc,
825 const char **argv )
828 TALLOC_CTX *frame = talloc_stackframe();
829 NTSTATUS status = NT_STATUS_OK;
830 WERROR werr = WERR_OK;
831 WERROR _werr;
833 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
835 /* key info */
836 struct policy_handle hive_hnd, key_hnd;
838 ZERO_STRUCT(hive_hnd);
839 ZERO_STRUCT(key_hnd);
842 if (argc != 1 || c->display_usage) {
843 rpc_conf_delshare_usage(c, argc, argv);
844 status = NT_STATUS_INVALID_PARAMETER;
845 goto error;
848 status = rpc_conf_open_conf(frame,
850 REG_KEY_ALL,
851 &hive_hnd,
852 &key_hnd,
853 &werr);
855 if (!(NT_STATUS_IS_OK(status))) {
856 goto error;
859 if (!(W_ERROR_IS_OK(werr))) {
860 goto error;
863 status = dcerpc_winreg_delete_subkeys_recursive(frame,
865 &key_hnd,
866 REG_KEY_ALL,
867 argv[0],
868 &werr);
870 if (!NT_STATUS_IS_OK(status)) {
871 d_fprintf(stderr,
872 "winreg_delete_subkeys: Could not delete key %s: %s\n",
873 argv[0], nt_errstr(status));
874 goto error;
877 if (W_ERROR_EQUAL(werr, WERR_BADFILE)){
878 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
882 if (!W_ERROR_IS_OK(werr)) {
883 d_fprintf(stderr,
884 "winreg_delete_subkeys: Could not delete key %s: %s\n",
885 argv[0], win_errstr(werr));
886 goto error;
889 error:
890 if (!(W_ERROR_IS_OK(werr))) {
891 status = werror_to_ntstatus(werr);
894 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
895 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
897 TALLOC_FREE(frame);
899 return status;
902 static NTSTATUS rpc_conf_list_internal(struct net_context *c,
903 const struct dom_sid *domain_sid,
904 const char *domain_name,
905 struct cli_state *cli,
906 struct rpc_pipe_client *pipe_hnd,
907 TALLOC_CTX *mem_ctx,
908 int argc,
909 const char **argv )
912 TALLOC_CTX *frame = talloc_stackframe();
913 NTSTATUS status = NT_STATUS_OK;
914 WERROR werr = WERR_OK;
915 WERROR _werr;
917 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
919 /* key info */
920 struct policy_handle hive_hnd, key_hnd;
921 uint32_t num_subkeys;
922 uint32_t i;
923 struct smbconf_service *shares;
924 const char **subkeys = NULL;
927 ZERO_STRUCT(hive_hnd);
928 ZERO_STRUCT(key_hnd);
931 if (argc != 0 || c->display_usage) {
932 rpc_conf_list_usage(c, argc, argv);
933 status = NT_STATUS_INVALID_PARAMETER;
934 goto error;
937 status = rpc_conf_open_conf(frame,
939 REG_KEY_READ,
940 &hive_hnd,
941 &key_hnd,
942 &werr);
944 if (!(NT_STATUS_IS_OK(status))) {
945 goto error;
948 if (!(W_ERROR_IS_OK(werr))) {
949 goto error;
952 status = dcerpc_winreg_enum_keys(frame,
954 &key_hnd,
955 &num_subkeys,
956 &subkeys,
957 &werr);
959 if (!(NT_STATUS_IS_OK(status))) {
960 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
961 nt_errstr(status));
962 goto error;
965 if (!(W_ERROR_IS_OK(werr))) {
966 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
967 win_errstr(werr));
968 goto error;
971 if (num_subkeys == 0) {
972 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
973 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
974 TALLOC_FREE(frame);
975 return NT_STATUS_OK;
978 /* get info from each subkey */
979 shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
980 if (shares == NULL) {
981 werr = WERR_NOMEM;
982 d_fprintf(stderr, _("Failed to create shares: %s\n"),
983 win_errstr(werr));
984 goto error;
988 for (i = 0; i < num_subkeys; i++) {
989 /* get each share and place it in the shares array */
990 status = rpc_conf_get_share(frame,
992 &key_hnd,
993 subkeys[i],
994 &shares[i],
995 &werr);
996 if (!(NT_STATUS_IS_OK(status))) {
997 goto error;
999 if (!(W_ERROR_IS_OK(werr))) {
1000 goto error;
1004 /* print the shares array */
1005 rpc_conf_print_shares(num_subkeys, shares);
1007 error:
1008 if (!(W_ERROR_IS_OK(werr))) {
1009 status = werror_to_ntstatus(werr);
1012 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1013 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1015 TALLOC_FREE(frame);
1016 return status;
1020 static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
1021 const struct dom_sid *domain_sid,
1022 const char *domain_name,
1023 struct cli_state *cli,
1024 struct rpc_pipe_client *pipe_hnd,
1025 TALLOC_CTX *mem_ctx,
1026 int argc,
1027 const char **argv )
1029 TALLOC_CTX *frame = talloc_stackframe();
1030 NTSTATUS status = NT_STATUS_OK;
1031 WERROR werr = WERR_OK;
1032 WERROR _werr;
1034 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1036 /* key info */
1037 struct policy_handle hive_hnd, key_hnd;
1038 const char *keyname = confpath;
1039 struct winreg_String wkey, wkeyclass;
1040 enum winreg_CreateAction action = REG_ACTION_NONE;
1043 ZERO_STRUCT(hive_hnd);
1044 ZERO_STRUCT(key_hnd);
1047 if (argc != 0 || c->display_usage) {
1048 rpc_conf_drop_usage(c, argc, argv);
1049 status = NT_STATUS_INVALID_PARAMETER;
1050 goto error;
1053 status = rpc_conf_open_conf(frame,
1055 REG_KEY_ALL,
1056 &hive_hnd,
1057 &key_hnd,
1058 &werr);
1060 if (!(NT_STATUS_IS_OK(status))) {
1061 goto error;
1064 if (!(W_ERROR_IS_OK(werr))) {
1065 goto error;
1068 status = dcerpc_winreg_delete_subkeys_recursive(frame,
1070 &hive_hnd,
1071 REG_KEY_ALL,
1072 keyname,
1073 &werr);
1075 if (!NT_STATUS_IS_OK(status)) {
1076 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1077 keyname, nt_errstr(status));
1078 goto error;
1081 if (!W_ERROR_IS_OK(werr)) {
1082 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1083 keyname, win_errstr(werr));
1084 goto error;
1087 wkey.name = keyname;
1088 ZERO_STRUCT(wkeyclass);
1089 wkeyclass.name = "";
1090 action = REG_ACTION_NONE;
1092 status = dcerpc_winreg_CreateKey(b,
1093 frame,
1094 &hive_hnd,
1095 wkey,
1096 wkeyclass,
1098 REG_KEY_ALL,
1099 NULL,
1100 &key_hnd,
1101 &action,
1102 &werr);
1104 if (!NT_STATUS_IS_OK(status)) {
1105 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1106 goto error;
1109 if (!W_ERROR_IS_OK(werr)) {
1110 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1111 goto error;
1115 error:
1116 if (!(W_ERROR_IS_OK(werr))) {
1117 status = werror_to_ntstatus(werr);
1120 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1121 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1123 TALLOC_FREE(frame);
1124 return status;
1127 static NTSTATUS rpc_conf_import_internal(struct net_context *c,
1128 const struct dom_sid *domain_sid,
1129 const char *domain_name,
1130 struct cli_state *cli,
1131 struct rpc_pipe_client *pipe_hnd,
1132 TALLOC_CTX *mem_ctx,
1133 int argc,
1134 const char **argv )
1137 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1139 struct policy_handle hive_hnd, key_hnd;
1141 const char *filename = NULL;
1142 const char *servicename = NULL;
1143 char *conf_source = NULL;
1144 TALLOC_CTX *frame;
1145 struct smbconf_ctx *txt_ctx;
1146 struct smbconf_service *service = NULL;
1147 struct smbconf_service **services = NULL;
1148 uint32_t num_shares, i;
1149 sbcErr err = SBC_ERR_UNKNOWN_FAILURE;
1151 WERROR werr = WERR_OK;
1152 NTSTATUS status = NT_STATUS_OK;
1154 ZERO_STRUCT(hive_hnd);
1155 ZERO_STRUCT(key_hnd);
1157 frame = talloc_stackframe();
1159 if (c->display_usage) {
1160 rpc_conf_import_usage(c, argc, argv);
1161 status = NT_STATUS_INVALID_PARAMETER;
1162 goto error;
1165 switch (argc) {
1166 case 0:
1167 default:
1168 rpc_conf_import_usage(c, argc, argv);
1169 status = NT_STATUS_INVALID_PARAMETER;
1170 goto error;
1171 case 2:
1172 servicename = talloc_strdup(frame, argv[1]);
1173 if (servicename == NULL) {
1174 d_printf(_("error: out of memory!\n"));
1175 goto error;
1177 case 1:
1178 filename = argv[0];
1179 break;
1182 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1183 filename));
1185 conf_source = talloc_asprintf(frame, "file:%s", filename);
1186 if (conf_source == NULL) {
1187 d_fprintf(stderr, _("error: out of memory!\n"));
1188 goto error;
1191 err = smbconf_init(frame, &txt_ctx, conf_source);
1192 if (!SBC_ERROR_IS_OK(err)) {
1193 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
1194 sbcErrorString(err));
1195 goto error;
1198 if (c->opt_testmode) {
1199 d_printf(_("\nTEST MODE - "
1200 "would import the following configuration:\n\n"));
1203 if (servicename != NULL) {
1204 err = smbconf_get_share(txt_ctx, frame,
1205 servicename,
1206 &service);
1207 if (!SBC_ERROR_IS_OK(err)) {
1208 goto error;
1211 num_shares = 1;
1213 } else {
1215 err = smbconf_get_config(txt_ctx, frame,
1216 &num_shares,
1217 &services);
1218 if (!SBC_ERROR_IS_OK(err)) {
1219 goto error;
1223 if (c->opt_testmode) {
1224 if (servicename != NULL) {
1225 rpc_conf_print_shares(1, service);
1227 for (i = 0; i < num_shares; i++) {
1228 rpc_conf_print_shares(1, services[i]);
1230 goto error;
1233 status = rpc_conf_drop_internal(c,
1234 domain_sid,
1235 domain_name,
1236 cli,
1237 pipe_hnd,
1238 frame,
1240 NULL );
1242 if (!(NT_STATUS_IS_OK(status))) {
1243 goto error;
1246 status = rpc_conf_open_conf(frame,
1248 REG_KEY_READ,
1249 &hive_hnd,
1250 &key_hnd,
1251 &werr);
1253 if (!(NT_STATUS_IS_OK(status))) {
1254 goto error;
1257 if (!(W_ERROR_IS_OK(werr))) {
1258 goto error;
1261 if (servicename != NULL) {
1262 status = rpc_conf_set_share(frame,
1264 &key_hnd,
1265 service,
1266 &werr);
1268 if (!(NT_STATUS_IS_OK(status))) {
1269 goto error;
1272 if (!(W_ERROR_IS_OK(werr))) {
1273 goto error;
1276 } else {
1278 for (i = 0; i < num_shares; i++) {
1279 status = rpc_conf_set_share(frame,
1281 &key_hnd,
1282 services[i],
1283 &werr);
1285 if (!(NT_STATUS_IS_OK(status))) {
1286 goto error;
1289 if (!(W_ERROR_IS_OK(werr))) {
1290 goto error;
1296 error:
1297 if (!SBC_ERROR_IS_OK(err)) {
1298 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
1301 if (!(W_ERROR_IS_OK(werr))) {
1302 status = werror_to_ntstatus(werr);
1304 TALLOC_FREE(frame);
1305 return status;
1308 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
1309 const struct dom_sid *domain_sid,
1310 const char *domain_name,
1311 struct cli_state *cli,
1312 struct rpc_pipe_client *pipe_hnd,
1313 TALLOC_CTX *mem_ctx,
1314 int argc,
1315 const char **argv )
1317 TALLOC_CTX *frame = talloc_stackframe();
1318 NTSTATUS status = NT_STATUS_OK;
1319 WERROR werr = WERR_OK;
1320 WERROR _werr;
1322 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1324 /* key info */
1325 struct policy_handle hive_hnd, key_hnd;
1326 struct smbconf_service *service = NULL;
1327 const char *sharename = NULL;
1330 ZERO_STRUCT(hive_hnd);
1331 ZERO_STRUCT(key_hnd);
1334 if (argc != 1 || c->display_usage) {
1335 rpc_conf_showshare_usage(c, argc, argv);
1336 status = NT_STATUS_INVALID_PARAMETER;
1337 goto error;
1340 status = rpc_conf_open_conf(frame,
1342 REG_KEY_READ,
1343 &hive_hnd,
1344 &key_hnd,
1345 &werr);
1347 if (!(NT_STATUS_IS_OK(status))) {
1348 goto error;
1351 if (!(W_ERROR_IS_OK(werr))) {
1352 goto error;
1355 sharename = talloc_strdup(frame, argv[0]);
1356 if (sharename == NULL) {
1357 werr = WERR_NOMEM;
1358 d_fprintf(stderr, _("Failed to create share: %s\n"),
1359 win_errstr(werr));
1360 goto error;
1363 service = talloc(frame, struct smbconf_service);
1364 if (service == NULL) {
1365 werr = WERR_NOMEM;
1366 d_fprintf(stderr, _("Failed to create share: %s\n"),
1367 win_errstr(werr));
1368 goto error;
1371 status = rpc_conf_get_share(frame,
1373 &key_hnd,
1374 sharename,
1375 service,
1376 &werr);
1378 if (!(NT_STATUS_IS_OK(status))) {
1379 goto error;
1381 if (!(W_ERROR_IS_OK(werr))) {
1382 goto error;
1385 rpc_conf_print_shares(1, service);
1387 error:
1388 if (!(W_ERROR_IS_OK(werr))) {
1389 status = werror_to_ntstatus(werr);
1392 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1393 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1395 TALLOC_FREE(frame);
1396 return status;
1399 static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
1400 const struct dom_sid *domain_sid,
1401 const char *domain_name,
1402 struct cli_state *cli,
1403 struct rpc_pipe_client *pipe_hnd,
1404 TALLOC_CTX *mem_ctx,
1405 int argc,
1406 const char **argv )
1408 TALLOC_CTX *frame = talloc_stackframe();
1409 NTSTATUS status = NT_STATUS_OK;
1410 WERROR werr = WERR_OK;
1411 WERROR _werr;
1413 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1415 /* key info */
1416 struct policy_handle hive_hnd, key_hnd, share_hnd;
1417 char *sharename = NULL;
1418 const char *path = NULL;
1419 const char *comment = NULL;
1420 const char *guest_ok = "no";
1421 const char *read_only = "yes";
1422 struct winreg_String key, keyclass;
1423 enum winreg_CreateAction action = 0;
1426 ZERO_STRUCT(hive_hnd);
1427 ZERO_STRUCT(key_hnd);
1428 ZERO_STRUCT(share_hnd);
1430 ZERO_STRUCT(key);
1431 ZERO_STRUCT(keyclass);
1433 if (c->display_usage) {
1434 rpc_conf_addshare_usage(c, argc, argv);
1435 status = NT_STATUS_INVALID_PARAMETER;
1436 goto error;
1439 switch (argc) {
1440 case 0:
1441 case 1:
1442 default:
1443 rpc_conf_addshare_usage(c, argc, argv);
1444 status = NT_STATUS_INVALID_PARAMETER;
1445 goto error;
1446 case 5:
1447 comment = argv[4];
1448 case 4:
1449 if (!strnequal(argv[3], "guest_ok=", 9)) {
1450 rpc_conf_addshare_usage(c, argc, argv);
1451 status = NT_STATUS_INVALID_PARAMETER;
1452 goto error;
1454 switch (argv[3][9]) {
1455 case 'y':
1456 case 'Y':
1457 guest_ok = "yes";
1458 break;
1459 case 'n':
1460 case 'N':
1461 guest_ok = "no";
1462 break;
1463 default:
1464 rpc_conf_addshare_usage(c, argc, argv);
1465 status = NT_STATUS_INVALID_PARAMETER;
1466 goto error;
1468 case 3:
1469 if (!strnequal(argv[2], "writeable=", 10)) {
1470 rpc_conf_addshare_usage(c, argc, argv);
1471 status = NT_STATUS_INVALID_PARAMETER;
1472 goto error;
1474 switch (argv[2][10]) {
1475 case 'y':
1476 case 'Y':
1477 read_only = "no";
1478 break;
1479 case 'n':
1480 case 'N':
1481 read_only = "yes";
1482 break;
1483 default:
1484 rpc_conf_addshare_usage(c, argc, argv);
1485 status = NT_STATUS_INVALID_PARAMETER;
1486 goto error;
1488 case 2:
1489 path = argv[1];
1490 sharename = talloc_strdup(frame, argv[0]);
1491 if (sharename == NULL) {
1492 d_printf(_("error: out of memory!\n"));
1493 goto error;
1496 break;
1499 status = rpc_conf_open_conf(frame,
1501 REG_KEY_READ,
1502 &hive_hnd,
1503 &key_hnd,
1504 &werr);
1506 if (!(NT_STATUS_IS_OK(status))) {
1507 goto error;
1510 if (!(W_ERROR_IS_OK(werr))) {
1511 goto error;
1514 key.name = argv[0];
1515 keyclass.name = "";
1517 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1518 0, REG_KEY_READ, NULL, &share_hnd,
1519 &action, &werr);
1521 if (!(NT_STATUS_IS_OK(status))) {
1522 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1523 argv[0], nt_errstr(status));
1524 goto error;
1527 if (!W_ERROR_IS_OK(werr)) {
1528 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1529 argv[0], win_errstr(werr));
1530 goto error;
1533 switch (action) {
1534 case REG_ACTION_NONE:
1535 werr = WERR_CREATE_FAILED;
1536 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1537 argv[0], win_errstr(werr));
1538 goto error;
1539 case REG_CREATED_NEW_KEY:
1540 DEBUG(5, ("net rpc conf setincludes:"
1541 "createkey created %s\n", argv[0]));
1542 break;
1543 case REG_OPENED_EXISTING_KEY:
1544 d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
1545 status = NT_STATUS_INVALID_PARAMETER;
1546 goto error;
1549 /* set the path parameter */
1550 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1551 "path", path, &werr);
1553 if (!(NT_STATUS_IS_OK(status))) {
1554 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1555 " with value %s\n %s\n",
1556 "path", path, nt_errstr(status));
1557 goto error;
1560 if (!(W_ERROR_IS_OK(werr))) {
1561 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1562 " with value %s\n %s\n",
1563 "path", path, win_errstr(werr));
1564 goto error;
1567 /* set the writeable parameter */
1568 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1569 "read only", read_only, &werr);
1571 if (!(NT_STATUS_IS_OK(status))) {
1572 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1573 " with value %s\n %s\n",
1574 "read only", read_only, nt_errstr(status));
1575 goto error;
1578 if (!(W_ERROR_IS_OK(werr))) {
1579 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1580 " with value %s\n %s\n",
1581 "read only", read_only, win_errstr(werr));
1582 goto error;
1585 /* set the guest ok parameter */
1586 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1587 "guest ok", guest_ok, &werr);
1589 if (!(NT_STATUS_IS_OK(status))) {
1590 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1591 " with value %s\n %s\n",
1592 "guest ok", guest_ok, nt_errstr(status));
1593 goto error;
1596 if (!(W_ERROR_IS_OK(werr))) {
1597 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1598 " with value %s\n %s\n",
1599 "guest ok", guest_ok, win_errstr(werr));
1600 goto error;
1603 if (argc == 5) {
1604 /* set the comment parameter */
1605 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1606 "comment", comment, &werr);
1608 if (!(NT_STATUS_IS_OK(status))) {
1609 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1610 " with value %s\n %s\n",
1611 "comment", comment, nt_errstr(status));
1612 goto error;
1615 if (!(W_ERROR_IS_OK(werr))) {
1616 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1617 " with value %s\n %s\n",
1618 "comment", comment, win_errstr(werr));
1619 goto error;
1622 error:
1623 if (!(W_ERROR_IS_OK(werr))) {
1624 status = werror_to_ntstatus(werr);
1627 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1628 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1629 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1631 TALLOC_FREE(frame);
1632 return status;
1635 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
1636 const struct dom_sid *domain_sid,
1637 const char *domain_name,
1638 struct cli_state *cli,
1639 struct rpc_pipe_client *pipe_hnd,
1640 TALLOC_CTX *mem_ctx,
1641 int argc,
1642 const char **argv )
1644 TALLOC_CTX *frame = talloc_stackframe();
1645 NTSTATUS status = NT_STATUS_OK;
1646 WERROR werr = WERR_OK;
1647 WERROR _werr;
1649 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1651 /* key info */
1652 struct policy_handle hive_hnd, key_hnd;
1653 struct smbconf_service *service = NULL;
1655 bool param_is_set = false;
1656 uint32_t param_count;
1658 ZERO_STRUCT(hive_hnd);
1659 ZERO_STRUCT(key_hnd);
1662 if (argc != 2 || c->display_usage) {
1663 rpc_conf_getparm_usage(c, argc, argv);
1664 status = NT_STATUS_INVALID_PARAMETER;
1665 goto error;
1668 status = rpc_conf_open_conf(frame,
1670 REG_KEY_READ,
1671 &hive_hnd,
1672 &key_hnd,
1673 &werr);
1675 if (!(NT_STATUS_IS_OK(status))) {
1676 goto error;
1679 if (!(W_ERROR_IS_OK(werr))) {
1680 goto error;
1684 service = talloc(frame, struct smbconf_service);
1686 status = rpc_conf_get_share(frame,
1688 &key_hnd,
1689 argv[0],
1690 service,
1691 &werr);
1693 if (!(NT_STATUS_IS_OK(status))) {
1694 goto error;
1697 if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1698 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1699 argv[0]);
1700 goto error;
1703 if (!(W_ERROR_IS_OK(werr))) {
1704 goto error;
1707 for (param_count = 0;
1708 param_count < service->num_params;
1709 param_count++)
1711 /* should includes also be printed? */
1712 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1713 d_printf(_("%s\n"),
1714 service->param_values[param_count]);
1715 param_is_set = true;
1719 if (!param_is_set) {
1720 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1721 argv[1]);
1722 werr = WERR_BADFILE;
1723 goto error;
1726 error:
1728 if (!(W_ERROR_IS_OK(werr))) {
1729 status = werror_to_ntstatus(werr);
1732 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1733 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1735 TALLOC_FREE(frame);
1736 return status;
1740 static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
1741 const struct dom_sid *domain_sid,
1742 const char *domain_name,
1743 struct cli_state *cli,
1744 struct rpc_pipe_client *pipe_hnd,
1745 TALLOC_CTX *mem_ctx,
1746 int argc,
1747 const char **argv )
1749 TALLOC_CTX *frame = talloc_stackframe();
1750 NTSTATUS status = NT_STATUS_OK;
1751 WERROR werr = WERR_OK;
1752 WERROR _werr;
1754 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1756 /* key info */
1757 struct policy_handle hive_hnd, key_hnd, share_hnd;
1759 struct winreg_String key, keyclass;
1760 enum winreg_CreateAction action = 0;
1762 const char *canon_valname;
1763 const char *canon_valstr;
1765 ZERO_STRUCT(hive_hnd);
1766 ZERO_STRUCT(key_hnd);
1767 ZERO_STRUCT(share_hnd);
1769 ZERO_STRUCT(key);
1770 ZERO_STRUCT(keyclass);
1772 if (argc != 3 || c->display_usage) {
1773 rpc_conf_setparm_usage(c, argc, argv);
1774 status = NT_STATUS_INVALID_PARAMETER;
1775 goto error;
1778 status = rpc_conf_open_conf(frame,
1780 REG_KEY_READ,
1781 &hive_hnd,
1782 &key_hnd,
1783 &werr);
1785 if (!(NT_STATUS_IS_OK(status))) {
1786 goto error;
1789 if (!(W_ERROR_IS_OK(werr))) {
1790 goto error;
1793 key.name = argv[0];
1794 keyclass.name = "";
1796 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1797 0, REG_KEY_READ, NULL, &share_hnd,
1798 &action, &werr);
1800 if (!(NT_STATUS_IS_OK(status))) {
1801 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1802 argv[0], nt_errstr(status));
1803 goto error;
1806 if (!W_ERROR_IS_OK(werr)) {
1807 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1808 argv[0], win_errstr(werr));
1809 goto error;
1812 switch (action) {
1813 case REG_ACTION_NONE:
1814 werr = WERR_CREATE_FAILED;
1815 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1816 argv[0], win_errstr(werr));
1817 goto error;
1818 case REG_CREATED_NEW_KEY:
1819 DEBUG(5, ("net rpc conf setparm:"
1820 "createkey created %s\n", argv[0]));
1821 break;
1822 case REG_OPENED_EXISTING_KEY:
1823 DEBUG(5, ("net rpc conf setparm:"
1824 "createkey opened existing %s\n", argv[0]));
1826 /* delete posibly existing value */
1827 status = rpc_conf_del_value(frame,
1829 &key_hnd,
1830 argv[0],
1831 argv[1],
1832 &werr);
1834 if (!(NT_STATUS_IS_OK(status))) {
1835 goto error;
1838 if (!(W_ERROR_IS_OK(werr))) {
1839 goto error;
1842 break;
1845 /* check if parameter is valid for writing */
1846 if (!lp_canonicalize_parameter_with_value(argv[1], argv[2],
1847 &canon_valname,
1848 &canon_valstr))
1850 if (canon_valname == NULL) {
1851 d_fprintf(stderr, "invalid parameter '%s' given\n",
1852 argv[1]);
1853 } else {
1854 d_fprintf(stderr, "invalid value '%s' given for "
1855 "parameter '%s'\n", argv[1], argv[2]);
1857 werr = WERR_INVALID_PARAM;
1858 goto error;
1861 if (rpc_conf_reg_valname_forbidden(canon_valname)) {
1862 d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n",
1863 canon_valname);
1864 werr = WERR_INVALID_PARAM;
1865 goto error;
1868 if (!strequal(argv[0], "global") &&
1869 lp_parameter_is_global(argv[1]))
1871 d_fprintf(stderr, "Global parameter '%s' not allowed in "
1872 "service definition ('%s').\n", canon_valname,
1873 argv[0]);
1874 werr = WERR_INVALID_PARAM;
1875 goto error;
1878 /* set the parameter */
1879 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1880 argv[1], argv[2], &werr);
1882 if (!(NT_STATUS_IS_OK(status))) {
1883 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1884 " with value %s\n %s\n",
1885 argv[1], argv[2], nt_errstr(status));
1886 goto error;
1889 if (!(W_ERROR_IS_OK(werr))) {
1890 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1891 " with value %s\n %s\n",
1892 argv[1], argv[2], win_errstr(werr));
1893 goto error;
1896 error:
1898 if (!(W_ERROR_IS_OK(werr))) {
1899 status = werror_to_ntstatus(werr);
1902 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1903 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1904 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1906 TALLOC_FREE(frame);
1907 return status;
1910 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1911 const struct dom_sid *domain_sid,
1912 const char *domain_name,
1913 struct cli_state *cli,
1914 struct rpc_pipe_client *pipe_hnd,
1915 TALLOC_CTX *mem_ctx,
1916 int argc,
1917 const char **argv )
1919 TALLOC_CTX *frame = talloc_stackframe();
1920 NTSTATUS status = NT_STATUS_OK;
1921 WERROR werr = WERR_OK;
1922 WERROR _werr;
1924 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1926 /* key info */
1927 struct policy_handle hive_hnd, key_hnd;
1930 ZERO_STRUCT(hive_hnd);
1931 ZERO_STRUCT(key_hnd);
1934 if (argc != 2 || c->display_usage) {
1935 rpc_conf_delparm_usage(c, argc, argv);
1936 status = NT_STATUS_INVALID_PARAMETER;
1937 goto error;
1940 status = rpc_conf_open_conf(frame,
1942 REG_KEY_READ,
1943 &hive_hnd,
1944 &key_hnd,
1945 &werr);
1947 if (!(NT_STATUS_IS_OK(status))) {
1948 goto error;
1951 if (!(W_ERROR_IS_OK(werr))) {
1952 goto error;
1955 status = rpc_conf_del_value(frame,
1957 &key_hnd,
1958 argv[0],
1959 argv[1],
1960 &werr);
1962 error:
1964 if (!(W_ERROR_IS_OK(werr))) {
1965 status = werror_to_ntstatus(werr);
1968 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1969 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1971 TALLOC_FREE(frame);
1972 return status;
1976 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1977 const struct dom_sid *domain_sid,
1978 const char *domain_name,
1979 struct cli_state *cli,
1980 struct rpc_pipe_client *pipe_hnd,
1981 TALLOC_CTX *mem_ctx,
1982 int argc,
1983 const char **argv )
1985 TALLOC_CTX *frame = talloc_stackframe();
1986 NTSTATUS status = NT_STATUS_OK;
1987 WERROR werr = WERR_OK;
1988 WERROR _werr;
1990 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1992 /* key info */
1993 struct policy_handle hive_hnd, key_hnd;
1994 struct smbconf_service *service = NULL;
1996 uint32_t param_count;
1999 ZERO_STRUCT(hive_hnd);
2000 ZERO_STRUCT(key_hnd);
2003 if (argc != 1 || c->display_usage) {
2004 rpc_conf_getincludes_usage(c, argc, argv);
2005 status = NT_STATUS_INVALID_PARAMETER;
2006 goto error;
2009 status = rpc_conf_open_conf(frame,
2011 REG_KEY_READ,
2012 &hive_hnd,
2013 &key_hnd,
2014 &werr);
2016 if (!(NT_STATUS_IS_OK(status))) {
2017 goto error;
2020 if (!(W_ERROR_IS_OK(werr))) {
2021 goto error;
2024 service = talloc(frame, struct smbconf_service);
2026 status = rpc_conf_get_share(frame,
2028 &key_hnd,
2029 argv[0],
2030 service,
2031 &werr);
2033 if (!(NT_STATUS_IS_OK(status))) {
2034 goto error;
2037 if (!(W_ERROR_IS_OK(werr))) {
2038 goto error;
2041 for (param_count = 0;
2042 param_count < service->num_params;
2043 param_count++)
2045 if (strcmp(service->param_names[param_count], "include") == 0) {
2046 d_printf(_("%s = %s\n"),
2047 service->param_names[param_count],
2048 service->param_values[param_count]);
2052 error:
2054 if (!(W_ERROR_IS_OK(werr))) {
2055 status = werror_to_ntstatus(werr);
2058 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2059 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2061 TALLOC_FREE(frame);
2062 return status;
2066 static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
2067 const struct dom_sid *domain_sid,
2068 const char *domain_name,
2069 struct cli_state *cli,
2070 struct rpc_pipe_client *pipe_hnd,
2071 TALLOC_CTX *mem_ctx,
2072 int argc,
2073 const char **argv )
2075 TALLOC_CTX *frame = talloc_stackframe();
2076 NTSTATUS status = NT_STATUS_OK;
2077 WERROR werr = WERR_OK;
2078 WERROR _werr;
2080 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2082 /* key info */
2083 struct policy_handle hive_hnd, key_hnd, share_hnd;
2085 struct winreg_String key, keyclass;
2086 enum winreg_CreateAction action = 0;
2088 ZERO_STRUCT(hive_hnd);
2089 ZERO_STRUCT(key_hnd);
2090 ZERO_STRUCT(share_hnd);
2092 ZERO_STRUCT(key);
2093 ZERO_STRUCT(keyclass);
2095 if (argc < 1 || c->display_usage) {
2096 rpc_conf_setincludes_usage(c, argc, argv);
2097 status = NT_STATUS_INVALID_PARAMETER;
2098 goto error;
2101 status = rpc_conf_open_conf(frame,
2103 REG_KEY_READ,
2104 &hive_hnd,
2105 &key_hnd,
2106 &werr);
2108 if (!(NT_STATUS_IS_OK(status))) {
2109 goto error;
2112 if (!(W_ERROR_IS_OK(werr))) {
2113 goto error;
2116 key.name = argv[0];
2117 keyclass.name = "";
2119 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
2120 0, REG_KEY_READ, NULL, &share_hnd,
2121 &action, &werr);
2123 if (!(NT_STATUS_IS_OK(status))) {
2124 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2125 argv[0], nt_errstr(status));
2126 goto error;
2129 if (!W_ERROR_IS_OK(werr)) {
2130 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2131 argv[0], win_errstr(werr));
2132 goto error;
2135 switch (action) {
2136 case REG_ACTION_NONE:
2137 /* Is there any other way to treat this? */
2138 werr = WERR_CREATE_FAILED;
2139 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2140 argv[0], win_errstr(werr));
2141 goto error;
2142 case REG_CREATED_NEW_KEY:
2143 DEBUG(5, ("net rpc conf setincludes:"
2144 "createkey created %s\n", argv[0]));
2145 break;
2146 case REG_OPENED_EXISTING_KEY:
2147 DEBUG(5, ("net rpc conf setincludes:"
2148 "createkey opened existing %s\n", argv[0]));
2150 /* delete posibly existing value */
2151 status = rpc_conf_del_value(frame,
2153 &key_hnd,
2154 argv[0],
2155 "includes",
2156 &werr);
2158 if (!(NT_STATUS_IS_OK(status))) {
2159 goto error;
2162 if (!(W_ERROR_IS_OK(werr))) {
2163 goto error;
2165 break;
2168 /* set the 'includes' values */
2169 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
2170 "includes", argv + 1, &werr);
2171 if (!(NT_STATUS_IS_OK(status))) {
2172 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2173 nt_errstr(status));
2174 goto error;
2177 if (!(W_ERROR_IS_OK(werr))) {
2178 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2179 win_errstr(werr));
2180 goto error;
2183 error:
2185 if (!(W_ERROR_IS_OK(werr))) {
2186 status = werror_to_ntstatus(werr);
2189 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2190 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2191 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
2193 TALLOC_FREE(frame);
2194 return status;
2197 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
2198 const struct dom_sid *domain_sid,
2199 const char *domain_name,
2200 struct cli_state *cli,
2201 struct rpc_pipe_client *pipe_hnd,
2202 TALLOC_CTX *mem_ctx,
2203 int argc,
2204 const char **argv )
2206 TALLOC_CTX *frame = talloc_stackframe();
2207 NTSTATUS status = NT_STATUS_OK;
2208 WERROR werr = WERR_OK;
2209 WERROR _werr;
2211 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2213 /* key info */
2214 struct policy_handle hive_hnd, key_hnd;
2217 ZERO_STRUCT(hive_hnd);
2218 ZERO_STRUCT(key_hnd);
2221 if (argc != 1 || c->display_usage) {
2222 rpc_conf_delincludes_usage(c, argc, argv);
2223 status = NT_STATUS_INVALID_PARAMETER;
2224 goto error;
2227 status = rpc_conf_open_conf(frame,
2229 REG_KEY_READ,
2230 &hive_hnd,
2231 &key_hnd,
2232 &werr);
2234 if (!(NT_STATUS_IS_OK(status))) {
2235 goto error;
2238 if (!(W_ERROR_IS_OK(werr))) {
2239 goto error;
2242 status = rpc_conf_del_value(frame,
2244 &key_hnd,
2245 argv[0],
2246 "includes",
2247 &werr);
2249 error:
2251 if (!(W_ERROR_IS_OK(werr))) {
2252 status = werror_to_ntstatus(werr);
2255 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2256 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2258 TALLOC_FREE(frame);
2259 return status;
2263 /**********************************************************
2265 * Functions that run the rpc commands for net rpc conf modules
2267 **********************************************************/
2269 static int rpc_conf_drop(struct net_context *c, int argc,
2270 const char **argv)
2272 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2273 rpc_conf_drop_internal, argc, argv );
2277 static int rpc_conf_showshare(struct net_context *c, int argc,
2278 const char **argv)
2280 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2281 rpc_conf_showshare_internal, argc, argv );
2284 static int rpc_conf_addshare(struct net_context *c, int argc,
2285 const char **argv)
2287 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2288 rpc_conf_addshare_internal, argc, argv );
2291 static int rpc_conf_listshares(struct net_context *c, int argc,
2292 const char **argv)
2294 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2295 rpc_conf_listshares_internal, argc, argv );
2298 static int rpc_conf_list(struct net_context *c, int argc,
2299 const char **argv)
2301 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2302 rpc_conf_list_internal, argc, argv );
2305 static int rpc_conf_import(struct net_context *c, int argc,
2306 const char **argv)
2308 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2309 rpc_conf_import_internal, argc, argv );
2311 static int rpc_conf_delshare(struct net_context *c, int argc,
2312 const char **argv)
2314 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2315 rpc_conf_delshare_internal, argc, argv );
2318 static int rpc_conf_getparm(struct net_context *c, int argc,
2319 const char **argv)
2321 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2322 rpc_conf_getparm_internal, argc, argv );
2325 static int rpc_conf_setparm(struct net_context *c, int argc,
2326 const char **argv)
2328 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2329 rpc_conf_setparm_internal, argc, argv );
2331 static int rpc_conf_delparm(struct net_context *c, int argc,
2332 const char **argv)
2334 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2335 rpc_conf_delparm_internal, argc, argv );
2338 static int rpc_conf_getincludes(struct net_context *c, int argc,
2339 const char **argv)
2341 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2342 rpc_conf_getincludes_internal, argc, argv );
2345 static int rpc_conf_setincludes(struct net_context *c, int argc,
2346 const char **argv)
2348 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2349 rpc_conf_setincludes_internal, argc, argv );
2352 static int rpc_conf_delincludes(struct net_context *c, int argc,
2353 const char **argv)
2355 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
2356 rpc_conf_delincludes_internal, argc, argv );
2359 /* function calls */
2360 int net_rpc_conf(struct net_context *c, int argc,
2361 const char **argv)
2363 struct functable func_table[] = {
2365 "list",
2366 rpc_conf_list,
2367 NET_TRANSPORT_RPC,
2368 N_("Dump the complete remote configuration in smb.conf like "
2369 "format."),
2370 N_("net rpc conf list\n"
2371 " Dump the complete remote configuration in smb.conf "
2372 "like format.")
2376 "import",
2377 rpc_conf_import,
2378 NET_TRANSPORT_RPC,
2379 N_("Import configuration from file in smb.conf "
2380 "format."),
2381 N_("net rpc conf import\n"
2382 " Import configuration from file in smb.conf "
2383 "format.")
2386 "listshares",
2387 rpc_conf_listshares,
2388 NET_TRANSPORT_RPC,
2389 N_("List the remote share names."),
2390 N_("net rpc conf list\n"
2391 " List the remote share names.")
2395 "drop",
2396 rpc_conf_drop,
2397 NET_TRANSPORT_RPC,
2398 N_("Delete the complete remote configuration."),
2399 N_("net rpc conf drop\n"
2400 " Delete the complete remote configuration.")
2404 "showshare",
2405 rpc_conf_showshare,
2406 NET_TRANSPORT_RPC,
2407 N_("Show the definition of a remote share."),
2408 N_("net rpc conf showshare\n"
2409 " Show the definition of a remote share.")
2413 "addshare",
2414 rpc_conf_addshare,
2415 NET_TRANSPORT_RPC,
2416 N_("Create a new remote share."),
2417 N_("net rpc conf addshare\n"
2418 " Create a new remote share.")
2421 "delshare",
2422 rpc_conf_delshare,
2423 NET_TRANSPORT_RPC,
2424 N_("Delete a remote share."),
2425 N_("net rpc conf delshare\n"
2426 " Delete a remote share.")
2429 "getparm",
2430 rpc_conf_getparm,
2431 NET_TRANSPORT_RPC,
2432 N_("Retrieve the value of a parameter."),
2433 N_("net rpc conf getparm\n"
2434 " Retrieve the value of a parameter.")
2437 "setparm",
2438 rpc_conf_setparm,
2439 NET_TRANSPORT_RPC,
2440 N_("Store a parameter."),
2441 N_("net rpc conf setparm\n"
2442 " Store a parameter.")
2445 "delparm",
2446 rpc_conf_delparm,
2447 NET_TRANSPORT_RPC,
2448 N_("Delete a parameter."),
2449 N_("net rpc conf delparm\n"
2450 " Delete a parameter.")
2453 "getincludes",
2454 rpc_conf_getincludes,
2455 NET_TRANSPORT_RPC,
2456 N_("Show the includes of a share definition."),
2457 N_("net rpc conf getincludes\n"
2458 " Show the includes of a share definition.")
2461 "setincludes",
2462 rpc_conf_setincludes,
2463 NET_TRANSPORT_RPC,
2464 N_("Set includes for a share."),
2465 N_("net rpc conf setincludes\n"
2466 " Set includes for a share.")
2469 "delincludes",
2470 rpc_conf_delincludes,
2471 NET_TRANSPORT_RPC,
2472 N_("Delete includes from a share definition."),
2473 N_("net rpc conf delincludes\n"
2474 " Delete includes from a share definition.")
2476 {NULL, NULL, 0, NULL, NULL}
2479 return net_run_function(c, argc, argv, "net rpc conf", func_table);