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.
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 /**********************************************************
49 **********************************************************/
50 const char confpath[100] = "Software\\Samba\\smbconf";
52 static int rpc_conf_list_usage(struct net_context *c, int argc,
55 d_printf("%s net rpc conf list\n", _("Usage:"));
59 static int rpc_conf_listshares_usage(struct net_context *c, int argc,
62 d_printf("%s net rpc conf listshares\n", _("Usage:"));
66 static int rpc_conf_delshare_usage(struct net_context *c, int argc,
71 _("net rpc conf delshare <sharename>\n"));
75 static int rpc_conf_addshare_usage(struct net_context *c, int argc,
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"));
93 static int rpc_conf_import_usage(struct net_context *c, int argc,
98 _(" net rpc conf import [--test|-T] <filename> "
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"));
107 static int rpc_conf_showshare_usage(struct net_context *c, int argc,
112 _("net rpc conf showshare <sharename>\n"));
116 static int rpc_conf_drop_usage(struct net_context *c, int argc,
119 d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
123 static int rpc_conf_getparm_usage(struct net_context *c, int argc,
126 d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
131 static int rpc_conf_setparm_usage(struct net_context *c, int argc,
136 _(" net rpc conf setparm <section> <param> <value>\n"));
140 static int rpc_conf_delparm_usage(struct net_context *c, int argc,
143 d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
148 static int rpc_conf_getincludes_usage(struct net_context *c, int argc,
151 d_printf("%s\nnet rpc conf getincludes <sharename>\n",
156 static int rpc_conf_setincludes_usage(struct net_context *c, int argc,
159 d_printf("%s\nnet rpc conf setincludes <sharename> [<filename>]*\n",
164 static int rpc_conf_delincludes_usage(struct net_context *c, int argc,
167 d_printf("%s\nnet rpc conf delincludes <sharename>\n",
172 /**********************************************************
176 **********************************************************/
179 * The function deletes a registry value with the name 'value' from the share
180 * with the name 'share_name'. 'parent_hnd' is the handle for the smbconf key.
182 static NTSTATUS rpc_conf_del_value(TALLOC_CTX *mem_ctx,
183 struct dcerpc_binding_handle *b,
184 struct policy_handle *parent_hnd,
185 const char *share_name,
190 TALLOC_CTX *frame = talloc_stackframe();
191 NTSTATUS status = NT_STATUS_OK;
192 WERROR result = WERR_OK;
195 struct winreg_String keyname, valuename;
196 struct policy_handle child_hnd;
198 ZERO_STRUCT(child_hnd);
199 ZERO_STRUCT(keyname);
200 ZERO_STRUCT(valuename);
202 keyname.name = share_name;
203 valuename.name = value;
205 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, keyname, 0,
206 REG_KEY_WRITE, &child_hnd, &result);
208 if (!(NT_STATUS_IS_OK(status))) {
209 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
210 keyname.name, nt_errstr(status));
214 if (!(W_ERROR_IS_OK(result))) {
215 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
216 keyname.name, win_errstr(result));
220 status = dcerpc_winreg_DeleteValue(b,
226 if (!(NT_STATUS_IS_OK(status))) {
227 d_fprintf(stderr, _("Failed to delete value %s\n"),
232 if (!(W_ERROR_IS_OK(result))) {
233 if (W_ERROR_EQUAL(result, WERR_BADFILE)){
238 d_fprintf(stderr, _("Failed to delete value %s\n"),
246 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
254 * The function sets a share in the registry with the parameters
255 * held in the smbconf_service struct
257 static NTSTATUS rpc_conf_set_share(TALLOC_CTX *mem_ctx,
258 struct dcerpc_binding_handle *b,
259 struct policy_handle *parent_hnd,
260 struct smbconf_service *service,
263 TALLOC_CTX *frame = talloc_stackframe();
265 NTSTATUS status = NT_STATUS_OK;
266 WERROR result = WERR_OK;
268 enum winreg_CreateAction action;
271 const char **includes;
273 struct winreg_String wkey, wkeyclass;
274 struct policy_handle share_hnd;
276 ZERO_STRUCT(share_hnd);
278 ZERO_STRUCT(wkeyclass);
280 wkey.name = service->name;
282 action = REG_ACTION_NONE;
284 status = dcerpc_winreg_CreateKey(b,
296 if (!NT_STATUS_IS_OK(status)) {
297 d_printf("winreg_CreateKey: Could not create smbconf key\n");
301 if (!W_ERROR_IS_OK(result)) {
302 d_printf("winreg_CreateKey: Could not create smbconf key\n");
306 for (i = 0; i < service->num_params; i++) {
307 if (strequal(service->param_names[i], "include") == 0)
310 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
311 service->param_names[i],
312 service->param_values[i],
315 if (!(NT_STATUS_IS_OK(status))) {
317 "ERROR: Share: '%s'\n"
318 "Could not set parameter '%s'"
319 " with value %s\n %s\n",
321 service->param_names[i],
322 service->param_values[i],
327 if (!(W_ERROR_IS_OK(result))) {
329 "ERROR: Share: '%s'\n"
330 "Could not set parameter '%s'"
331 " with value %s\n %s\n",
333 service->param_names[i],
334 service->param_values[i],
340 includes = talloc_zero_array(frame,
342 service->num_params + 1);
343 if (includes == NULL) {
345 d_fprintf(stderr, "ERROR: out of memory\n");
349 for (j = i; j < service->num_params; j++) {
351 includes[j - i] = talloc_strdup(
353 service->param_values[j]);
355 if (includes[j-i] == NULL) {
357 d_fprintf(stderr, "ERROR: out of memory\n");
362 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
367 if (!(NT_STATUS_IS_OK(status))) {
368 d_fprintf(stderr, "ERROR: Share: '%s'\n"
369 "Could not set includes\n %s\n",
375 if (!(W_ERROR_IS_OK(result))) {
376 d_fprintf(stderr, "ERROR: Share: '%s'\n"
377 "Could not set includes\n %s\n",
383 i = service->num_params;
388 /* in case of error, should it delete the created key? */
389 if (!(W_ERROR_IS_OK(result))) {
390 status = werror_to_ntstatus(result);
394 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
402 * The function opens the registry database and retrieves
403 * as a smbconf_service struct the share with the name
406 static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx,
407 struct dcerpc_binding_handle *b,
408 struct policy_handle *parent_hnd,
409 const char *share_name,
410 struct smbconf_service *share,
413 TALLOC_CTX *frame = talloc_stackframe();
415 NTSTATUS status = NT_STATUS_OK;
416 WERROR result = WERR_OK;
418 struct policy_handle child_hnd;
419 int32_t includes_cnt, includes_idx = -1;
420 uint32_t num_vals, i, param_cnt = 0;
421 const char **val_names;
422 enum winreg_Type *types;
424 struct winreg_String key = { 0, };
425 const char **multi_s = NULL;
426 const char *s = NULL;
427 struct smbconf_service tmp_share;
429 ZERO_STRUCT(tmp_share);
431 key.name = share_name;
432 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
433 REG_KEY_READ, &child_hnd, &result);
435 if (!(NT_STATUS_IS_OK(status))) {
436 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
440 if (!(W_ERROR_IS_OK(result))) {
441 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
445 /* get all the info from the share key */
446 status = dcerpc_winreg_enumvals(frame,
455 if (!(NT_STATUS_IS_OK(status))) {
456 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
460 if (!(W_ERROR_IS_OK(result))) {
461 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
465 /* check for includes */
466 for (i = 0; i < num_vals; i++) {
467 if (strcmp(val_names[i], "includes") == 0){
468 if (!pull_reg_multi_sz(frame,
474 _("Failed to enumerate values: %s\n"),
481 /* count the number of includes */
483 if (includes_idx != -1) {
484 for (includes_cnt = 0;
485 multi_s[includes_cnt] != NULL;
488 /* place the name of the share in the smbconf_service struct */
489 tmp_share.name = talloc_strdup(frame, share_name);
490 if (tmp_share.name == NULL) {
492 d_fprintf(stderr, _("Failed to create share: %s\n"),
496 /* place the number of parameters in the smbconf_service struct */
497 tmp_share.num_params = num_vals;
498 if (includes_idx != -1) {
499 tmp_share.num_params = num_vals + includes_cnt - 1;
501 /* allocate memory for the param_names and param_values lists */
502 tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
503 if (tmp_share.param_names == NULL) {
505 d_fprintf(stderr, _("Failed to create share: %s\n"),
509 tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
510 if (tmp_share.param_values == NULL) {
512 d_fprintf(stderr, _("Failed to create share: %s\n"),
516 /* place all params except includes */
517 for (i = 0; i < num_vals; i++) {
518 if (strcmp(val_names[i], "includes") != 0) {
519 if (!pull_reg_sz(frame, &data[i], &s)) {
522 _("Failed to enumerate values: %s\n"),
526 /* place param_names */
527 tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
528 if (tmp_share.param_names[param_cnt] == NULL) {
530 d_fprintf(stderr, _("Failed to create share: %s\n"),
535 /* place param_values */
536 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
537 if (tmp_share.param_values[param_cnt - 1] == NULL) {
539 d_fprintf(stderr, _("Failed to create share: %s\n"),
545 /* place the includes last */
546 for (i = 0; i < includes_cnt; i++) {
547 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
548 if (tmp_share.param_names[param_cnt] == NULL) {
550 d_fprintf(stderr, _("Failed to create share: %s\n"),
555 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
556 if (tmp_share.param_values[param_cnt - 1] == NULL) {
558 d_fprintf(stderr, _("Failed to create share: %s\n"),
564 /* move everything to the main memory ctx */
565 for (i = 0; i < param_cnt; i++) {
566 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
567 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
570 tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
571 tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
572 tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
577 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
584 * The function prints the shares held as smbconf_service structs
585 * in a smbconf file format.
587 static int rpc_conf_print_shares(uint32_t num_shares,
588 struct smbconf_service *shares)
591 uint32_t share_count, param_count;
592 const char *indent = "\t";
594 if (num_shares == 0) {
598 for (share_count = 0; share_count < num_shares; share_count++) {
600 if (shares[share_count].name != NULL) {
601 d_printf("[%s]\n", shares[share_count].name);
604 for (param_count = 0;
605 param_count < shares[share_count].num_params;
608 d_printf("%s%s = %s\n",
610 shares[share_count].param_names[param_count],
611 shares[share_count].param_values[param_count]);
621 * The function openes the registry key
622 * HKLM/Software/Samba/smbconf with the give access_mask
624 static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
625 struct dcerpc_binding_handle *b,
626 uint32_t access_mask,
627 struct policy_handle *hive_hnd,
628 struct policy_handle *key_hnd,
631 TALLOC_CTX *frame = talloc_stackframe();
632 NTSTATUS status = NT_STATUS_OK;
633 WERROR result = WERR_OK;
635 struct policy_handle tmp_hive_hnd, tmp_key_hnd;
636 struct winreg_String key;
640 status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
641 access_mask, &tmp_hive_hnd, &result);
644 * print no error messages if it is a read only open
645 * and key does not exist
646 * error still gets returned
649 if (access_mask == REG_KEY_READ &&
650 W_ERROR_EQUAL(result, WERR_BADFILE))
655 if (!(NT_STATUS_IS_OK(status))) {
656 d_fprintf(stderr, _("Failed to open hive: %s\n"),
660 if (!W_ERROR_IS_OK(result)) {
661 d_fprintf(stderr, _("Failed to open hive: %s\n"),
667 status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
668 access_mask, &tmp_key_hnd, &result);
671 * print no error messages if it is a read only open
672 * and key does not exist
673 * error still gets returned
676 if (access_mask == REG_KEY_READ &&
677 W_ERROR_EQUAL(result, WERR_BADFILE))
682 if (!(NT_STATUS_IS_OK(status))) {
683 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
685 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
688 if (!(W_ERROR_IS_OK(result))) {
689 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
691 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
695 *hive_hnd = tmp_hive_hnd;
696 *key_hnd = tmp_key_hnd;
705 /**********************************************************
707 * internal functions that provide the functionality
710 **********************************************************/
712 static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
713 const struct dom_sid *domain_sid,
714 const char *domain_name,
715 struct cli_state *cli,
716 struct rpc_pipe_client *pipe_hnd,
722 TALLOC_CTX *frame = talloc_stackframe();
723 NTSTATUS status = NT_STATUS_OK;
724 WERROR werr = WERR_OK;
727 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
730 struct policy_handle hive_hnd, key_hnd;
731 uint32_t num_subkeys;
733 const char **subkeys = NULL;
736 ZERO_STRUCT(hive_hnd);
737 ZERO_STRUCT(key_hnd);
740 if (argc != 0 || c->display_usage) {
741 rpc_conf_listshares_usage(c, argc, argv);
742 status = NT_STATUS_INVALID_PARAMETER;
747 status = rpc_conf_open_conf(frame,
754 if (!(NT_STATUS_IS_OK(status))) {
758 if (!(W_ERROR_IS_OK(werr))) {
762 status = dcerpc_winreg_enum_keys(frame,
769 if (!(NT_STATUS_IS_OK(status))) {
770 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
775 if (!(W_ERROR_IS_OK(werr))) {
776 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
781 for (i = 0; i < num_subkeys; i++) {
782 d_printf("%s\n", subkeys[i]);
786 if (!(W_ERROR_IS_OK(werr))) {
787 status = werror_to_ntstatus(werr);
790 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
791 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
797 static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
798 const struct dom_sid *domain_sid,
799 const char *domain_name,
800 struct cli_state *cli,
801 struct rpc_pipe_client *pipe_hnd,
807 TALLOC_CTX *frame = talloc_stackframe();
808 NTSTATUS status = NT_STATUS_OK;
809 WERROR werr = WERR_OK;
812 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
815 struct policy_handle hive_hnd, key_hnd;
817 ZERO_STRUCT(hive_hnd);
818 ZERO_STRUCT(key_hnd);
821 if (argc != 1 || c->display_usage) {
822 rpc_conf_delshare_usage(c, argc, argv);
823 status = NT_STATUS_INVALID_PARAMETER;
827 status = rpc_conf_open_conf(frame,
834 if (!(NT_STATUS_IS_OK(status))) {
838 if (!(W_ERROR_IS_OK(werr))) {
842 status = dcerpc_winreg_delete_subkeys_recursive(frame,
849 if (!NT_STATUS_IS_OK(status)) {
851 "winreg_delete_subkeys: Could not delete key %s: %s\n",
852 argv[0], nt_errstr(status));
856 if (W_ERROR_EQUAL(werr, WERR_BADFILE)){
857 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
861 if (!W_ERROR_IS_OK(werr)) {
863 "winreg_delete_subkeys: Could not delete key %s: %s\n",
864 argv[0], win_errstr(werr));
869 if (!(W_ERROR_IS_OK(werr))) {
870 status = werror_to_ntstatus(werr);
873 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
874 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
881 static NTSTATUS rpc_conf_list_internal(struct net_context *c,
882 const struct dom_sid *domain_sid,
883 const char *domain_name,
884 struct cli_state *cli,
885 struct rpc_pipe_client *pipe_hnd,
891 TALLOC_CTX *frame = talloc_stackframe();
892 NTSTATUS status = NT_STATUS_OK;
893 WERROR werr = WERR_OK;
896 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
899 struct policy_handle hive_hnd, key_hnd;
900 uint32_t num_subkeys;
902 struct smbconf_service *shares;
903 const char **subkeys = NULL;
906 ZERO_STRUCT(hive_hnd);
907 ZERO_STRUCT(key_hnd);
910 if (argc != 0 || c->display_usage) {
911 rpc_conf_list_usage(c, argc, argv);
912 status = NT_STATUS_INVALID_PARAMETER;
916 status = rpc_conf_open_conf(frame,
923 if (!(NT_STATUS_IS_OK(status))) {
927 if (!(W_ERROR_IS_OK(werr))) {
931 status = dcerpc_winreg_enum_keys(frame,
938 if (!(NT_STATUS_IS_OK(status))) {
939 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
944 if (!(W_ERROR_IS_OK(werr))) {
945 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
950 if (num_subkeys == 0) {
951 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
952 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
957 /* get info from each subkey */
958 shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
959 if (shares == NULL) {
961 d_fprintf(stderr, _("Failed to create shares: %s\n"),
967 for (i = 0; i < num_subkeys; i++) {
968 /* get each share and place it in the shares array */
969 status = rpc_conf_get_share(frame,
975 if (!(NT_STATUS_IS_OK(status))) {
978 if (!(W_ERROR_IS_OK(werr))) {
983 /* print the shares array */
984 rpc_conf_print_shares(num_subkeys, shares);
987 if (!(W_ERROR_IS_OK(werr))) {
988 status = werror_to_ntstatus(werr);
991 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
992 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
999 static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
1000 const struct dom_sid *domain_sid,
1001 const char *domain_name,
1002 struct cli_state *cli,
1003 struct rpc_pipe_client *pipe_hnd,
1004 TALLOC_CTX *mem_ctx,
1008 TALLOC_CTX *frame = talloc_stackframe();
1009 NTSTATUS status = NT_STATUS_OK;
1010 WERROR werr = WERR_OK;
1013 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1016 struct policy_handle hive_hnd, key_hnd;
1017 const char *keyname = confpath;
1018 struct winreg_String wkey, wkeyclass;
1019 enum winreg_CreateAction action = REG_ACTION_NONE;
1022 ZERO_STRUCT(hive_hnd);
1023 ZERO_STRUCT(key_hnd);
1026 if (argc != 0 || c->display_usage) {
1027 rpc_conf_drop_usage(c, argc, argv);
1028 status = NT_STATUS_INVALID_PARAMETER;
1032 status = rpc_conf_open_conf(frame,
1039 if (!(NT_STATUS_IS_OK(status))) {
1043 if (!(W_ERROR_IS_OK(werr))) {
1047 status = dcerpc_winreg_delete_subkeys_recursive(frame,
1054 if (!NT_STATUS_IS_OK(status)) {
1055 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1056 keyname, nt_errstr(status));
1060 if (!W_ERROR_IS_OK(werr)) {
1061 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1062 keyname, win_errstr(werr));
1067 wkey.name = keyname;
1068 ZERO_STRUCT(wkeyclass);
1069 wkeyclass.name = "";
1070 action = REG_ACTION_NONE;
1072 status = dcerpc_winreg_CreateKey(b,
1084 if (!NT_STATUS_IS_OK(status)) {
1085 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1089 if (!W_ERROR_IS_OK(werr)) {
1090 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1096 if (!(W_ERROR_IS_OK(werr))) {
1097 status = werror_to_ntstatus(werr);
1100 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1101 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1107 static NTSTATUS rpc_conf_import_internal(struct net_context *c,
1108 const struct dom_sid *domain_sid,
1109 const char *domain_name,
1110 struct cli_state *cli,
1111 struct rpc_pipe_client *pipe_hnd,
1112 TALLOC_CTX *mem_ctx,
1117 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1119 struct policy_handle hive_hnd, key_hnd;
1121 const char *filename = NULL;
1122 const char *servicename = NULL;
1123 char *conf_source = NULL;
1125 struct smbconf_ctx *txt_ctx;
1126 struct smbconf_service *service = NULL;
1127 struct smbconf_service **services = NULL;
1128 uint32_t num_shares, i;
1129 sbcErr err = SBC_ERR_UNKNOWN_FAILURE;
1131 WERROR werr = WERR_OK;
1132 NTSTATUS status = NT_STATUS_OK;
1134 ZERO_STRUCT(hive_hnd);
1135 ZERO_STRUCT(key_hnd);
1137 frame = talloc_stackframe();
1139 if (c->display_usage) {
1140 rpc_conf_import_usage(c, argc, argv);
1141 status = NT_STATUS_INVALID_PARAMETER;
1148 rpc_conf_import_usage(c, argc, argv);
1149 status = NT_STATUS_INVALID_PARAMETER;
1152 servicename = talloc_strdup(frame, argv[1]);
1153 if (servicename == NULL) {
1154 d_printf(_("error: out of memory!\n"));
1162 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1165 conf_source = talloc_asprintf(frame, "file:%s", filename);
1166 if (conf_source == NULL) {
1167 d_fprintf(stderr, _("error: out of memory!\n"));
1171 err = smbconf_init(frame, &txt_ctx, conf_source);
1172 if (!SBC_ERROR_IS_OK(err)) {
1173 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
1174 sbcErrorString(err));
1178 if (c->opt_testmode) {
1179 d_printf(_("\nTEST MODE - "
1180 "would import the following configuration:\n\n"));
1183 if (servicename != NULL) {
1184 err = smbconf_get_share(txt_ctx, frame,
1187 if (!SBC_ERROR_IS_OK(err)) {
1195 err = smbconf_get_config(txt_ctx, frame,
1198 if (!SBC_ERROR_IS_OK(err)) {
1203 if (c->opt_testmode) {
1204 if (servicename != NULL) {
1205 rpc_conf_print_shares(1, service);
1207 for (i = 0; i < num_shares; i++) {
1208 rpc_conf_print_shares(1, services[i]);
1213 status = rpc_conf_drop_internal(c,
1222 if (!(NT_STATUS_IS_OK(status))) {
1226 status = rpc_conf_open_conf(frame,
1233 if (!(NT_STATUS_IS_OK(status))) {
1237 if (!(W_ERROR_IS_OK(werr))) {
1241 if (servicename != NULL) {
1242 status = rpc_conf_set_share(frame,
1248 if (!(NT_STATUS_IS_OK(status))) {
1252 if (!(W_ERROR_IS_OK(werr))) {
1258 for (i = 0; i < num_shares; i++) {
1259 status = rpc_conf_set_share(frame,
1265 if (!(NT_STATUS_IS_OK(status))) {
1269 if (!(W_ERROR_IS_OK(werr))) {
1277 if (!SBC_ERROR_IS_OK(err)) {
1278 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
1281 if (!(W_ERROR_IS_OK(werr))) {
1282 status = werror_to_ntstatus(werr);
1288 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
1289 const struct dom_sid *domain_sid,
1290 const char *domain_name,
1291 struct cli_state *cli,
1292 struct rpc_pipe_client *pipe_hnd,
1293 TALLOC_CTX *mem_ctx,
1297 TALLOC_CTX *frame = talloc_stackframe();
1298 NTSTATUS status = NT_STATUS_OK;
1299 WERROR werr = WERR_OK;
1302 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1305 struct policy_handle hive_hnd, key_hnd;
1306 struct smbconf_service *service = NULL;
1307 const char *sharename = NULL;
1310 ZERO_STRUCT(hive_hnd);
1311 ZERO_STRUCT(key_hnd);
1314 if (argc != 1 || c->display_usage) {
1315 rpc_conf_showshare_usage(c, argc, argv);
1316 status = NT_STATUS_INVALID_PARAMETER;
1320 status = rpc_conf_open_conf(frame,
1327 if (!(NT_STATUS_IS_OK(status))) {
1331 if (!(W_ERROR_IS_OK(werr))) {
1335 sharename = talloc_strdup(frame, argv[0]);
1336 if (sharename == NULL) {
1338 d_fprintf(stderr, _("Failed to create share: %s\n"),
1343 service = talloc(frame, struct smbconf_service);
1344 if (service == NULL) {
1346 d_fprintf(stderr, _("Failed to create share: %s\n"),
1351 status = rpc_conf_get_share(frame,
1358 if (!(NT_STATUS_IS_OK(status))) {
1361 if (!(W_ERROR_IS_OK(werr))) {
1365 rpc_conf_print_shares(1, service);
1368 if (!(W_ERROR_IS_OK(werr))) {
1369 status = werror_to_ntstatus(werr);
1372 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1373 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1379 static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
1380 const struct dom_sid *domain_sid,
1381 const char *domain_name,
1382 struct cli_state *cli,
1383 struct rpc_pipe_client *pipe_hnd,
1384 TALLOC_CTX *mem_ctx,
1388 TALLOC_CTX *frame = talloc_stackframe();
1389 NTSTATUS status = NT_STATUS_OK;
1390 WERROR werr = WERR_OK;
1393 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1396 struct policy_handle hive_hnd, key_hnd, share_hnd;
1397 char *sharename = NULL;
1398 const char *path = NULL;
1399 const char *comment = NULL;
1400 const char *guest_ok = "no";
1401 const char *read_only = "yes";
1402 struct winreg_String key, keyclass;
1403 enum winreg_CreateAction action = 0;
1406 ZERO_STRUCT(hive_hnd);
1407 ZERO_STRUCT(key_hnd);
1408 ZERO_STRUCT(share_hnd);
1411 ZERO_STRUCT(keyclass);
1413 if (c->display_usage) {
1414 rpc_conf_addshare_usage(c, argc, argv);
1415 status = NT_STATUS_INVALID_PARAMETER;
1423 rpc_conf_addshare_usage(c, argc, argv);
1424 status = NT_STATUS_INVALID_PARAMETER;
1429 if (!strnequal(argv[3], "guest_ok=", 9)) {
1430 rpc_conf_addshare_usage(c, argc, argv);
1431 status = NT_STATUS_INVALID_PARAMETER;
1434 switch (argv[3][9]) {
1444 rpc_conf_addshare_usage(c, argc, argv);
1445 status = NT_STATUS_INVALID_PARAMETER;
1449 if (!strnequal(argv[2], "writeable=", 10)) {
1450 rpc_conf_addshare_usage(c, argc, argv);
1451 status = NT_STATUS_INVALID_PARAMETER;
1454 switch (argv[2][10]) {
1464 rpc_conf_addshare_usage(c, argc, argv);
1465 status = NT_STATUS_INVALID_PARAMETER;
1470 sharename = talloc_strdup(frame, argv[0]);
1471 if (sharename == NULL) {
1472 d_printf(_("error: out of memory!\n"));
1479 status = rpc_conf_open_conf(frame,
1486 if (!(NT_STATUS_IS_OK(status))) {
1490 if (!(W_ERROR_IS_OK(werr))) {
1497 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1498 0, REG_KEY_READ, NULL, &share_hnd,
1501 if (!(NT_STATUS_IS_OK(status))) {
1502 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1503 argv[0], nt_errstr(status));
1507 if (!W_ERROR_IS_OK(werr)) {
1508 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1509 argv[0], win_errstr(werr));
1514 case REG_ACTION_NONE:
1515 werr = WERR_CREATE_FAILED;
1516 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1517 argv[0], win_errstr(werr));
1519 case REG_CREATED_NEW_KEY:
1520 DEBUG(5, ("net rpc conf setincludes:"
1521 "createkey created %s\n", argv[0]));
1523 case REG_OPENED_EXISTING_KEY:
1524 d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
1525 status = NT_STATUS_INVALID_PARAMETER;
1529 /* set the path parameter */
1530 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1531 "path", path, &werr);
1533 if (!(NT_STATUS_IS_OK(status))) {
1534 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1535 " with value %s\n %s\n",
1536 "path", path, nt_errstr(status));
1540 if (!(W_ERROR_IS_OK(werr))) {
1541 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1542 " with value %s\n %s\n",
1543 "path", path, win_errstr(werr));
1547 /* set the writeable parameter */
1548 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1549 "read only", read_only, &werr);
1551 if (!(NT_STATUS_IS_OK(status))) {
1552 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1553 " with value %s\n %s\n",
1554 "read only", read_only, nt_errstr(status));
1558 if (!(W_ERROR_IS_OK(werr))) {
1559 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1560 " with value %s\n %s\n",
1561 "read only", read_only, win_errstr(werr));
1565 /* set the guest ok parameter */
1566 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1567 "guest ok", guest_ok, &werr);
1569 if (!(NT_STATUS_IS_OK(status))) {
1570 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1571 " with value %s\n %s\n",
1572 "guest ok", guest_ok, nt_errstr(status));
1576 if (!(W_ERROR_IS_OK(werr))) {
1577 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1578 " with value %s\n %s\n",
1579 "guest ok", guest_ok, win_errstr(werr));
1584 /* set the comment parameter */
1585 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1586 "comment", comment, &werr);
1588 if (!(NT_STATUS_IS_OK(status))) {
1589 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1590 " with value %s\n %s\n",
1591 "comment", comment, nt_errstr(status));
1595 if (!(W_ERROR_IS_OK(werr))) {
1596 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1597 " with value %s\n %s\n",
1598 "comment", comment, win_errstr(werr));
1603 if (!(W_ERROR_IS_OK(werr))) {
1604 status = werror_to_ntstatus(werr);
1607 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1608 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1609 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1615 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
1616 const struct dom_sid *domain_sid,
1617 const char *domain_name,
1618 struct cli_state *cli,
1619 struct rpc_pipe_client *pipe_hnd,
1620 TALLOC_CTX *mem_ctx,
1624 TALLOC_CTX *frame = talloc_stackframe();
1625 NTSTATUS status = NT_STATUS_OK;
1626 WERROR werr = WERR_OK;
1629 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1632 struct policy_handle hive_hnd, key_hnd;
1633 struct smbconf_service *service = NULL;
1635 bool param_is_set = false;
1636 uint32_t param_count;
1638 ZERO_STRUCT(hive_hnd);
1639 ZERO_STRUCT(key_hnd);
1642 if (argc != 2 || c->display_usage) {
1643 rpc_conf_getparm_usage(c, argc, argv);
1644 status = NT_STATUS_INVALID_PARAMETER;
1648 status = rpc_conf_open_conf(frame,
1655 if (!(NT_STATUS_IS_OK(status))) {
1659 if (!(W_ERROR_IS_OK(werr))) {
1664 service = talloc(frame, struct smbconf_service);
1666 status = rpc_conf_get_share(frame,
1673 if (!(NT_STATUS_IS_OK(status))) {
1677 if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1678 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1683 if (!(W_ERROR_IS_OK(werr))) {
1687 for (param_count = 0;
1688 param_count < service->num_params;
1691 /* should includes also be printed? */
1692 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1694 service->param_values[param_count]);
1695 param_is_set = true;
1699 if (!param_is_set) {
1700 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1702 werr = WERR_BADFILE;
1708 if (!(W_ERROR_IS_OK(werr))) {
1709 status = werror_to_ntstatus(werr);
1712 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1713 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1720 static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
1721 const struct dom_sid *domain_sid,
1722 const char *domain_name,
1723 struct cli_state *cli,
1724 struct rpc_pipe_client *pipe_hnd,
1725 TALLOC_CTX *mem_ctx,
1729 TALLOC_CTX *frame = talloc_stackframe();
1730 NTSTATUS status = NT_STATUS_OK;
1731 WERROR werr = WERR_OK;
1734 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1737 struct policy_handle hive_hnd, key_hnd, share_hnd;
1739 struct winreg_String key, keyclass;
1740 enum winreg_CreateAction action = 0;
1742 const char *canon_valname;
1743 const char *canon_valstr;
1745 ZERO_STRUCT(hive_hnd);
1746 ZERO_STRUCT(key_hnd);
1747 ZERO_STRUCT(share_hnd);
1750 ZERO_STRUCT(keyclass);
1752 if (argc != 3 || c->display_usage) {
1753 rpc_conf_setparm_usage(c, argc, argv);
1754 status = NT_STATUS_INVALID_PARAMETER;
1758 status = rpc_conf_open_conf(frame,
1765 if (!(NT_STATUS_IS_OK(status))) {
1769 if (!(W_ERROR_IS_OK(werr))) {
1776 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1777 0, REG_KEY_READ, NULL, &share_hnd,
1780 if (!(NT_STATUS_IS_OK(status))) {
1781 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1782 argv[0], nt_errstr(status));
1786 if (!W_ERROR_IS_OK(werr)) {
1787 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1788 argv[0], win_errstr(werr));
1793 case REG_ACTION_NONE:
1794 werr = WERR_CREATE_FAILED;
1795 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1796 argv[0], win_errstr(werr));
1798 case REG_CREATED_NEW_KEY:
1799 DEBUG(5, ("net rpc conf setparm:"
1800 "createkey created %s\n", argv[0]));
1802 case REG_OPENED_EXISTING_KEY:
1803 DEBUG(5, ("net rpc conf setparm:"
1804 "createkey opened existing %s\n", argv[0]));
1806 /* delete posibly existing value */
1807 status = rpc_conf_del_value(frame,
1814 if (!(NT_STATUS_IS_OK(status))) {
1818 if (!(W_ERROR_IS_OK(werr))) {
1825 /* check if parameter is valid for writing */
1826 if (!lp_canonicalize_parameter_with_value(argv[1], argv[2],
1830 if (canon_valname == NULL) {
1831 d_fprintf(stderr, "invalid parameter '%s' given\n",
1834 d_fprintf(stderr, "invalid value '%s' given for "
1835 "parameter '%s'\n", argv[1], argv[2]);
1837 werr = WERR_INVALID_PARAM;
1841 if (!smbconf_reg_parameter_is_valid(canon_valname)) {
1842 d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n",
1844 werr = WERR_INVALID_PARAM;
1848 if (!strequal(argv[0], "global") &&
1849 lp_parameter_is_global(argv[1]))
1851 d_fprintf(stderr, "Global parameter '%s' not allowed in "
1852 "service definition ('%s').\n", canon_valname,
1854 werr = WERR_INVALID_PARAM;
1858 /* set the parameter */
1859 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1860 argv[1], argv[2], &werr);
1862 if (!(NT_STATUS_IS_OK(status))) {
1863 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1864 " with value %s\n %s\n",
1865 argv[1], argv[2], nt_errstr(status));
1869 if (!(W_ERROR_IS_OK(werr))) {
1870 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1871 " with value %s\n %s\n",
1872 argv[1], argv[2], win_errstr(werr));
1878 if (!(W_ERROR_IS_OK(werr))) {
1879 status = werror_to_ntstatus(werr);
1882 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1883 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1884 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1890 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1891 const struct dom_sid *domain_sid,
1892 const char *domain_name,
1893 struct cli_state *cli,
1894 struct rpc_pipe_client *pipe_hnd,
1895 TALLOC_CTX *mem_ctx,
1899 TALLOC_CTX *frame = talloc_stackframe();
1900 NTSTATUS status = NT_STATUS_OK;
1901 WERROR werr = WERR_OK;
1904 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1907 struct policy_handle hive_hnd, key_hnd;
1910 ZERO_STRUCT(hive_hnd);
1911 ZERO_STRUCT(key_hnd);
1914 if (argc != 2 || c->display_usage) {
1915 rpc_conf_delparm_usage(c, argc, argv);
1916 status = NT_STATUS_INVALID_PARAMETER;
1920 status = rpc_conf_open_conf(frame,
1927 if (!(NT_STATUS_IS_OK(status))) {
1931 if (!(W_ERROR_IS_OK(werr))) {
1935 status = rpc_conf_del_value(frame,
1944 if (!(W_ERROR_IS_OK(werr))) {
1945 status = werror_to_ntstatus(werr);
1948 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1949 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1956 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1957 const struct dom_sid *domain_sid,
1958 const char *domain_name,
1959 struct cli_state *cli,
1960 struct rpc_pipe_client *pipe_hnd,
1961 TALLOC_CTX *mem_ctx,
1965 TALLOC_CTX *frame = talloc_stackframe();
1966 NTSTATUS status = NT_STATUS_OK;
1967 WERROR werr = WERR_OK;
1970 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1973 struct policy_handle hive_hnd, key_hnd;
1974 struct smbconf_service *service = NULL;
1976 uint32_t param_count;
1979 ZERO_STRUCT(hive_hnd);
1980 ZERO_STRUCT(key_hnd);
1983 if (argc != 1 || c->display_usage) {
1984 rpc_conf_getincludes_usage(c, argc, argv);
1985 status = NT_STATUS_INVALID_PARAMETER;
1989 status = rpc_conf_open_conf(frame,
1996 if (!(NT_STATUS_IS_OK(status))) {
2000 if (!(W_ERROR_IS_OK(werr))) {
2004 service = talloc(frame, struct smbconf_service);
2006 status = rpc_conf_get_share(frame,
2013 if (!(NT_STATUS_IS_OK(status))) {
2017 if (!(W_ERROR_IS_OK(werr))) {
2021 for (param_count = 0;
2022 param_count < service->num_params;
2025 if (strcmp(service->param_names[param_count], "include") == 0) {
2026 d_printf(_("%s = %s\n"),
2027 service->param_names[param_count],
2028 service->param_values[param_count]);
2034 if (!(W_ERROR_IS_OK(werr))) {
2035 status = werror_to_ntstatus(werr);
2038 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2039 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2046 static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
2047 const struct dom_sid *domain_sid,
2048 const char *domain_name,
2049 struct cli_state *cli,
2050 struct rpc_pipe_client *pipe_hnd,
2051 TALLOC_CTX *mem_ctx,
2055 TALLOC_CTX *frame = talloc_stackframe();
2056 NTSTATUS status = NT_STATUS_OK;
2057 WERROR werr = WERR_OK;
2060 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2063 struct policy_handle hive_hnd, key_hnd, share_hnd;
2065 struct winreg_String key, keyclass;
2066 enum winreg_CreateAction action = 0;
2068 ZERO_STRUCT(hive_hnd);
2069 ZERO_STRUCT(key_hnd);
2070 ZERO_STRUCT(share_hnd);
2073 ZERO_STRUCT(keyclass);
2075 if (argc < 1 || c->display_usage) {
2076 rpc_conf_setincludes_usage(c, argc, argv);
2077 status = NT_STATUS_INVALID_PARAMETER;
2081 status = rpc_conf_open_conf(frame,
2088 if (!(NT_STATUS_IS_OK(status))) {
2092 if (!(W_ERROR_IS_OK(werr))) {
2099 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
2100 0, REG_KEY_READ, NULL, &share_hnd,
2103 if (!(NT_STATUS_IS_OK(status))) {
2104 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2105 argv[0], nt_errstr(status));
2109 if (!W_ERROR_IS_OK(werr)) {
2110 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2111 argv[0], win_errstr(werr));
2116 case REG_ACTION_NONE:
2117 /* Is there any other way to treat this? */
2118 werr = WERR_CREATE_FAILED;
2119 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2120 argv[0], win_errstr(werr));
2122 case REG_CREATED_NEW_KEY:
2123 DEBUG(5, ("net rpc conf setincludes:"
2124 "createkey created %s\n", argv[0]));
2126 case REG_OPENED_EXISTING_KEY:
2127 DEBUG(5, ("net rpc conf setincludes:"
2128 "createkey opened existing %s\n", argv[0]));
2130 /* delete posibly existing value */
2131 status = rpc_conf_del_value(frame,
2138 if (!(NT_STATUS_IS_OK(status))) {
2142 if (!(W_ERROR_IS_OK(werr))) {
2148 /* set the 'includes' values */
2149 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
2150 "includes", argv + 1, &werr);
2151 if (!(NT_STATUS_IS_OK(status))) {
2152 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2157 if (!(W_ERROR_IS_OK(werr))) {
2158 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2165 if (!(W_ERROR_IS_OK(werr))) {
2166 status = werror_to_ntstatus(werr);
2169 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2170 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2171 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
2177 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
2178 const struct dom_sid *domain_sid,
2179 const char *domain_name,
2180 struct cli_state *cli,
2181 struct rpc_pipe_client *pipe_hnd,
2182 TALLOC_CTX *mem_ctx,
2186 TALLOC_CTX *frame = talloc_stackframe();
2187 NTSTATUS status = NT_STATUS_OK;
2188 WERROR werr = WERR_OK;
2191 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2194 struct policy_handle hive_hnd, key_hnd;
2197 ZERO_STRUCT(hive_hnd);
2198 ZERO_STRUCT(key_hnd);
2201 if (argc != 1 || c->display_usage) {
2202 rpc_conf_delincludes_usage(c, argc, argv);
2203 status = NT_STATUS_INVALID_PARAMETER;
2207 status = rpc_conf_open_conf(frame,
2214 if (!(NT_STATUS_IS_OK(status))) {
2218 if (!(W_ERROR_IS_OK(werr))) {
2222 status = rpc_conf_del_value(frame,
2231 if (!(W_ERROR_IS_OK(werr))) {
2232 status = werror_to_ntstatus(werr);
2235 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2236 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2243 /**********************************************************
2245 * Functions that run the rpc commands for net rpc conf modules
2247 **********************************************************/
2249 static int rpc_conf_drop(struct net_context *c, int argc,
2252 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2253 rpc_conf_drop_internal, argc, argv );
2257 static int rpc_conf_showshare(struct net_context *c, int argc,
2260 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2261 rpc_conf_showshare_internal, argc, argv );
2264 static int rpc_conf_addshare(struct net_context *c, int argc,
2267 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2268 rpc_conf_addshare_internal, argc, argv );
2271 static int rpc_conf_listshares(struct net_context *c, int argc,
2274 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2275 rpc_conf_listshares_internal, argc, argv );
2278 static int rpc_conf_list(struct net_context *c, int argc,
2281 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2282 rpc_conf_list_internal, argc, argv );
2285 static int rpc_conf_import(struct net_context *c, int argc,
2288 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2289 rpc_conf_import_internal, argc, argv );
2291 static int rpc_conf_delshare(struct net_context *c, int argc,
2294 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2295 rpc_conf_delshare_internal, argc, argv );
2298 static int rpc_conf_getparm(struct net_context *c, int argc,
2301 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2302 rpc_conf_getparm_internal, argc, argv );
2305 static int rpc_conf_setparm(struct net_context *c, int argc,
2308 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2309 rpc_conf_setparm_internal, argc, argv );
2311 static int rpc_conf_delparm(struct net_context *c, int argc,
2314 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2315 rpc_conf_delparm_internal, argc, argv );
2318 static int rpc_conf_getincludes(struct net_context *c, int argc,
2321 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2322 rpc_conf_getincludes_internal, argc, argv );
2325 static int rpc_conf_setincludes(struct net_context *c, int argc,
2328 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2329 rpc_conf_setincludes_internal, argc, argv );
2332 static int rpc_conf_delincludes(struct net_context *c, int argc,
2335 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2336 rpc_conf_delincludes_internal, argc, argv );
2339 /* function calls */
2340 int net_rpc_conf(struct net_context *c, int argc,
2343 struct functable func_table[] = {
2348 N_("Dump the complete remote configuration in smb.conf like "
2350 N_("net rpc conf list\n"
2351 " Dump the complete remote configuration in smb.conf "
2359 N_("Import configuration from file in smb.conf "
2361 N_("net rpc conf import\n"
2362 " Import configuration from file in smb.conf "
2367 rpc_conf_listshares,
2369 N_("List the remote share names."),
2370 N_("net rpc conf list\n"
2371 " List the remote share names.")
2378 N_("Delete the complete remote configuration."),
2379 N_("net rpc conf drop\n"
2380 " Delete the complete remote configuration.")
2387 N_("Show the definition of a remote share."),
2388 N_("net rpc conf showshare\n"
2389 " Show the definition of a remote share.")
2396 N_("Create a new remote share."),
2397 N_("net rpc conf addshare\n"
2398 " Create a new remote share.")
2404 N_("Delete a remote share."),
2405 N_("net rpc conf delshare\n"
2406 " Delete a remote share.")
2412 N_("Retrieve the value of a parameter."),
2413 N_("net rpc conf getparm\n"
2414 " Retrieve the value of a parameter.")
2420 N_("Store a parameter."),
2421 N_("net rpc conf setparm\n"
2422 " Store a parameter.")
2428 N_("Delete a parameter."),
2429 N_("net rpc conf delparm\n"
2430 " Delete a parameter.")
2434 rpc_conf_getincludes,
2436 N_("Show the includes of a share definition."),
2437 N_("net rpc conf getincludes\n"
2438 " Show the includes of a share definition.")
2442 rpc_conf_setincludes,
2444 N_("Set includes for a share."),
2445 N_("net rpc conf setincludes\n"
2446 " Set includes for a share.")
2450 rpc_conf_delincludes,
2452 N_("Delete includes from a share definition."),
2453 N_("net rpc conf delincludes\n"
2454 " Delete includes from a share definition.")
2456 {NULL, NULL, 0, NULL, NULL}
2459 return net_run_function(c, argc, argv, "net rpc conf", func_table);