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"
39 /* internal functions */
40 /**********************************************************
44 **********************************************************/
45 const char confpath[100] = "Software\\Samba\\smbconf";
47 static int rpc_conf_list_usage(struct net_context *c, int argc,
50 d_printf("%s net rpc conf list\n", _("Usage:"));
54 static int rpc_conf_listshares_usage(struct net_context *c, int argc,
57 d_printf("%s net rpc conf listshares\n", _("Usage:"));
61 static int rpc_conf_delshare_usage(struct net_context *c, int argc,
66 _("net rpc conf delshare <sharename>\n"));
70 static int rpc_conf_showshare_usage(struct net_context *c, int argc,
75 _("net rpc conf showshare <sharename>\n"));
79 static int rpc_conf_drop_usage(struct net_context *c, int argc,
82 d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
86 static int rpc_conf_getparm_usage(struct net_context *c, int argc,
89 d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
94 static int rpc_conf_delparm_usage(struct net_context *c, int argc,
97 d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
102 static int rpc_conf_getincludes_usage(struct net_context *c, int argc,
105 d_printf("%s\nnet rpc conf getincludes <sharename>\n",
110 static int rpc_conf_delincludes_usage(struct net_context *c, int argc,
113 d_printf("%s\nnet rpc conf delincludes <sharename>\n",
118 static NTSTATUS rpc_conf_del_value(TALLOC_CTX *mem_ctx,
119 struct dcerpc_binding_handle *b,
120 struct policy_handle *parent_hnd,
121 const char *share_name,
126 TALLOC_CTX *frame = talloc_stackframe();
127 NTSTATUS status = NT_STATUS_OK;
128 WERROR result = WERR_OK;
131 struct winreg_String keyname, valuename;
132 struct policy_handle child_hnd;
134 ZERO_STRUCT(child_hnd);
135 ZERO_STRUCT(keyname);
136 ZERO_STRUCT(valuename);
138 keyname.name = share_name;
139 valuename.name = value;
141 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, keyname, 0,
142 REG_KEY_WRITE, &child_hnd, &result);
144 if (!(NT_STATUS_IS_OK(status))) {
145 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
146 keyname.name, nt_errstr(status));
150 if (!(W_ERROR_IS_OK(result))) {
151 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
152 keyname.name, win_errstr(result));
156 status = dcerpc_winreg_DeleteValue(b,
162 if (!(NT_STATUS_IS_OK(status))) {
163 d_fprintf(stderr, _("Failed to delete value %s\n"),
168 if (!(W_ERROR_IS_OK(result))) {
169 if (W_ERROR_EQUAL(result, WERR_BADFILE)){
174 d_fprintf(stderr, _("Failed to delete value %s\n"),
182 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
189 static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx,
190 struct dcerpc_binding_handle *b,
191 struct policy_handle *parent_hnd,
192 const char *share_name,
193 struct smbconf_service *share,
196 TALLOC_CTX *frame = talloc_stackframe();
198 NTSTATUS status = NT_STATUS_OK;
199 WERROR result = WERR_OK;
201 struct policy_handle child_hnd;
202 int32_t includes_cnt, includes_idx = -1;
203 uint32_t num_vals, i, param_cnt = 0;
204 const char **val_names;
205 enum winreg_Type *types;
207 struct winreg_String key;
208 const char **multi_s = NULL;
209 const char *s = NULL;
210 struct smbconf_service tmp_share;
212 ZERO_STRUCT(tmp_share);
214 key.name = share_name;
215 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
216 REG_KEY_READ, &child_hnd, &result);
218 if (!(NT_STATUS_IS_OK(status))) {
219 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
223 if (!(W_ERROR_IS_OK(result))) {
224 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
228 /* get all the info from the share key */
229 status = dcerpc_winreg_enumvals(frame,
238 if (!(NT_STATUS_IS_OK(status))) {
239 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
243 if (!(W_ERROR_IS_OK(result))) {
244 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
248 /* check for includes */
249 for (i = 0; i < num_vals; i++) {
250 if (strcmp(val_names[i], "includes") == 0){
251 if (!pull_reg_multi_sz(frame,
257 _("Failed to enumerate values: %s\n"),
264 /* count the number of includes */
266 if (includes_idx != -1) {
267 for (includes_cnt = 0;
268 multi_s[includes_cnt] != NULL;
271 /* place the name of the share in the smbconf_service struct */
272 tmp_share.name = talloc_strdup(frame, share_name);
273 if (tmp_share.name == NULL) {
275 d_fprintf(stderr, _("Failed to create share: %s\n"),
279 /* place the number of parameters in the smbconf_service struct */
280 tmp_share.num_params = num_vals;
281 if (includes_idx != -1) {
282 tmp_share.num_params = num_vals + includes_cnt - 1;
284 /* allocate memory for the param_names and param_values lists */
285 tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
286 if (tmp_share.param_names == NULL) {
288 d_fprintf(stderr, _("Failed to create share: %s\n"),
292 tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
293 if (tmp_share.param_values == NULL) {
295 d_fprintf(stderr, _("Failed to create share: %s\n"),
299 /* place all params except includes */
300 for (i = 0; i < num_vals; i++) {
301 if (strcmp(val_names[i], "includes") != 0) {
302 if (!pull_reg_sz(frame, &data[i], &s)) {
305 _("Failed to enumerate values: %s\n"),
309 /* place param_names */
310 tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
311 if (tmp_share.param_names[param_cnt] == NULL) {
313 d_fprintf(stderr, _("Failed to create share: %s\n"),
318 /* place param_values */
319 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
320 if (tmp_share.param_values[param_cnt - 1] == NULL) {
322 d_fprintf(stderr, _("Failed to create share: %s\n"),
328 /* place the includes last */
329 for (i = 0; i < includes_cnt; i++) {
330 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
331 if (tmp_share.param_names[param_cnt] == NULL) {
333 d_fprintf(stderr, _("Failed to create share: %s\n"),
338 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
339 if (tmp_share.param_values[param_cnt - 1] == NULL) {
341 d_fprintf(stderr, _("Failed to create share: %s\n"),
347 /* move everything to the main memory ctx */
348 for (i = 0; i < param_cnt; i++) {
349 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
350 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
353 tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
354 tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
355 tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
360 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
366 static int rpc_conf_print_shares(uint32_t num_shares,
367 struct smbconf_service *shares)
370 uint32_t share_count, param_count;
371 const char *indent = "\t";
373 if (num_shares == 0) {
377 for (share_count = 0; share_count < num_shares; share_count++) {
379 if (shares[share_count].name != NULL) {
380 d_printf("[%s]\n", shares[share_count].name);
383 for (param_count = 0;
384 param_count < shares[share_count].num_params;
387 d_printf("%s%s = %s\n",
389 shares[share_count].param_names[param_count],
390 shares[share_count].param_values[param_count]);
398 static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
399 struct dcerpc_binding_handle *b,
400 uint32_t access_mask,
401 struct policy_handle *hive_hnd,
402 struct policy_handle *key_hnd,
405 TALLOC_CTX *frame = talloc_stackframe();
406 NTSTATUS status = NT_STATUS_OK;
407 WERROR result = WERR_OK;
409 struct policy_handle tmp_hive_hnd, tmp_key_hnd;
410 struct winreg_String key;
414 status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
415 access_mask, &tmp_hive_hnd, &result);
418 * print no error messages if it is a read only open
419 * and key does not exist
420 * error still gets returned
423 if (access_mask == REG_KEY_READ &&
424 W_ERROR_EQUAL(result, WERR_BADFILE))
429 if (!(NT_STATUS_IS_OK(status))) {
430 d_fprintf(stderr, _("Failed to open hive: %s\n"),
434 if (!W_ERROR_IS_OK(result)) {
435 d_fprintf(stderr, _("Failed to open hive: %s\n"),
441 status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
442 access_mask, &tmp_key_hnd, &result);
445 * print no error messages if it is a read only open
446 * and key does not exist
447 * error still gets returned
450 if (access_mask == REG_KEY_READ &&
451 W_ERROR_EQUAL(result, WERR_BADFILE))
456 if (!(NT_STATUS_IS_OK(status))) {
457 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
459 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
462 if (!(W_ERROR_IS_OK(result))) {
463 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
465 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
469 *hive_hnd = tmp_hive_hnd;
470 *key_hnd = tmp_key_hnd;
479 static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
480 const struct dom_sid *domain_sid,
481 const char *domain_name,
482 struct cli_state *cli,
483 struct rpc_pipe_client *pipe_hnd,
489 TALLOC_CTX *frame = talloc_stackframe();
490 NTSTATUS status = NT_STATUS_OK;
491 WERROR werr = WERR_OK;
494 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
497 struct policy_handle hive_hnd, key_hnd;
498 uint32_t num_subkeys;
500 const char **subkeys = NULL;
503 ZERO_STRUCT(hive_hnd);
504 ZERO_STRUCT(key_hnd);
507 if (argc != 0 || c->display_usage) {
508 rpc_conf_listshares_usage(c, argc, argv);
509 status = NT_STATUS_INVALID_PARAMETER;
514 status = rpc_conf_open_conf(frame,
521 if (!(NT_STATUS_IS_OK(status))) {
525 if (!(W_ERROR_IS_OK(werr))) {
529 status = dcerpc_winreg_enum_keys(frame,
536 if (!(NT_STATUS_IS_OK(status))) {
537 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
542 if (!(W_ERROR_IS_OK(werr))) {
543 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
548 for (i = 0; i < num_subkeys; i++) {
549 d_printf("%s\n", subkeys[i]);
553 if (!(W_ERROR_IS_OK(werr))) {
554 status = werror_to_ntstatus(werr);
557 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
558 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
564 static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
565 const struct dom_sid *domain_sid,
566 const char *domain_name,
567 struct cli_state *cli,
568 struct rpc_pipe_client *pipe_hnd,
574 TALLOC_CTX *frame = talloc_stackframe();
575 NTSTATUS status = NT_STATUS_OK;
576 WERROR werr = WERR_OK;
579 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
582 struct policy_handle hive_hnd, key_hnd;
584 ZERO_STRUCT(hive_hnd);
585 ZERO_STRUCT(key_hnd);
588 if (argc != 1 || c->display_usage) {
589 rpc_conf_delshare_usage(c, argc, argv);
590 status = NT_STATUS_INVALID_PARAMETER;
594 status = rpc_conf_open_conf(frame,
601 if (!(NT_STATUS_IS_OK(status))) {
605 if (!(W_ERROR_IS_OK(werr))) {
609 status = dcerpc_winreg_delete_subkeys_recursive(frame,
616 if (!NT_STATUS_IS_OK(status)) {
618 "winreg_delete_subkeys: Could not delete key %s: %s\n",
619 argv[0], nt_errstr(status));
623 if (W_ERROR_EQUAL(werr, WERR_BADFILE)){
624 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
628 if (!W_ERROR_IS_OK(werr)) {
630 "winreg_delete_subkeys: Could not delete key %s: %s\n",
631 argv[0], win_errstr(werr));
636 if (!(W_ERROR_IS_OK(werr))) {
637 status = werror_to_ntstatus(werr);
640 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
641 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
648 static NTSTATUS rpc_conf_list_internal(struct net_context *c,
649 const struct dom_sid *domain_sid,
650 const char *domain_name,
651 struct cli_state *cli,
652 struct rpc_pipe_client *pipe_hnd,
658 TALLOC_CTX *frame = talloc_stackframe();
659 NTSTATUS status = NT_STATUS_OK;
660 WERROR werr = WERR_OK;
663 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
666 struct policy_handle hive_hnd, key_hnd;
667 uint32_t num_subkeys;
669 struct smbconf_service *shares;
670 const char **subkeys = NULL;
673 ZERO_STRUCT(hive_hnd);
674 ZERO_STRUCT(key_hnd);
677 if (argc != 0 || c->display_usage) {
678 rpc_conf_list_usage(c, argc, argv);
679 status = NT_STATUS_INVALID_PARAMETER;
683 status = rpc_conf_open_conf(frame,
690 if (!(NT_STATUS_IS_OK(status))) {
694 if (!(W_ERROR_IS_OK(werr))) {
698 status = dcerpc_winreg_enum_keys(frame,
705 if (!(NT_STATUS_IS_OK(status))) {
706 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
711 if (!(W_ERROR_IS_OK(werr))) {
712 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
717 if (num_subkeys == 0) {
718 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
719 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
724 /* get info from each subkey */
725 shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
726 if (shares == NULL) {
728 d_fprintf(stderr, _("Failed to create shares: %s\n"),
734 for (i = 0; i < num_subkeys; i++) {
735 /* get each share and place it in the shares array */
736 status = rpc_conf_get_share(frame,
742 if (!(NT_STATUS_IS_OK(status))) {
745 if (!(W_ERROR_IS_OK(werr))) {
750 /* print the shares array */
751 rpc_conf_print_shares(num_subkeys, shares);
754 if (!(W_ERROR_IS_OK(werr))) {
755 status = werror_to_ntstatus(werr);
758 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
759 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
766 static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
767 const struct dom_sid *domain_sid,
768 const char *domain_name,
769 struct cli_state *cli,
770 struct rpc_pipe_client *pipe_hnd,
775 TALLOC_CTX *frame = talloc_stackframe();
776 NTSTATUS status = NT_STATUS_OK;
777 WERROR werr = WERR_OK;
780 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
783 struct policy_handle hive_hnd, key_hnd;
784 const char *keyname = confpath;
785 struct winreg_String wkey, wkeyclass;
786 enum winreg_CreateAction action = REG_ACTION_NONE;
789 ZERO_STRUCT(hive_hnd);
790 ZERO_STRUCT(key_hnd);
793 if (argc != 0 || c->display_usage) {
794 rpc_conf_drop_usage(c, argc, argv);
795 status = NT_STATUS_INVALID_PARAMETER;
799 status = rpc_conf_open_conf(frame,
806 if (!(NT_STATUS_IS_OK(status))) {
810 if (!(W_ERROR_IS_OK(werr))) {
814 status = dcerpc_winreg_delete_subkeys_recursive(frame,
821 if (!NT_STATUS_IS_OK(status)) {
822 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
823 keyname, nt_errstr(status));
827 if (!W_ERROR_IS_OK(werr)) {
828 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
829 keyname, win_errstr(werr));
834 ZERO_STRUCT(wkeyclass);
836 action = REG_ACTION_NONE;
838 status = dcerpc_winreg_CreateKey(b,
850 if (!NT_STATUS_IS_OK(status)) {
851 d_printf("winreg_CreateKey: Could not create smbconf key\n");
855 if (!W_ERROR_IS_OK(werr)) {
856 d_printf("winreg_CreateKey: Could not create smbconf key\n");
862 if (!(W_ERROR_IS_OK(werr))) {
863 status = werror_to_ntstatus(werr);
866 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
867 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
873 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
874 const struct dom_sid *domain_sid,
875 const char *domain_name,
876 struct cli_state *cli,
877 struct rpc_pipe_client *pipe_hnd,
882 TALLOC_CTX *frame = talloc_stackframe();
883 NTSTATUS status = NT_STATUS_OK;
884 WERROR werr = WERR_OK;
887 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
890 struct policy_handle hive_hnd, key_hnd;
891 struct smbconf_service *service = NULL;
892 const char *sharename = NULL;
895 ZERO_STRUCT(hive_hnd);
896 ZERO_STRUCT(key_hnd);
899 if (argc != 1 || c->display_usage) {
900 rpc_conf_showshare_usage(c, argc, argv);
901 status = NT_STATUS_INVALID_PARAMETER;
905 status = rpc_conf_open_conf(frame,
912 if (!(NT_STATUS_IS_OK(status))) {
916 if (!(W_ERROR_IS_OK(werr))) {
920 sharename = talloc_strdup(frame, argv[0]);
921 if (sharename == NULL) {
923 d_fprintf(stderr, _("Failed to create share: %s\n"),
928 service = talloc(frame, struct smbconf_service);
929 if (service == NULL) {
931 d_fprintf(stderr, _("Failed to create share: %s\n"),
936 status = rpc_conf_get_share(frame,
943 if (!(NT_STATUS_IS_OK(status))) {
946 if (!(W_ERROR_IS_OK(werr))) {
950 rpc_conf_print_shares(1, service);
953 if (!(W_ERROR_IS_OK(werr))) {
954 status = werror_to_ntstatus(werr);
957 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
958 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
964 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
965 const struct dom_sid *domain_sid,
966 const char *domain_name,
967 struct cli_state *cli,
968 struct rpc_pipe_client *pipe_hnd,
973 TALLOC_CTX *frame = talloc_stackframe();
974 NTSTATUS status = NT_STATUS_OK;
975 WERROR werr = WERR_OK;
978 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
981 struct policy_handle hive_hnd, key_hnd;
982 struct smbconf_service *service = NULL;
984 bool param_is_set = false;
985 uint32_t param_count;
987 ZERO_STRUCT(hive_hnd);
988 ZERO_STRUCT(key_hnd);
991 if (argc != 2 || c->display_usage) {
992 rpc_conf_getparm_usage(c, argc, argv);
993 status = NT_STATUS_INVALID_PARAMETER;
997 status = rpc_conf_open_conf(frame,
1004 if (!(NT_STATUS_IS_OK(status))) {
1008 if (!(W_ERROR_IS_OK(werr))) {
1013 service = talloc(frame, struct smbconf_service);
1015 status = rpc_conf_get_share(frame,
1022 if (!(NT_STATUS_IS_OK(status))) {
1026 if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1027 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1032 if (!(W_ERROR_IS_OK(werr))) {
1036 for (param_count = 0;
1037 param_count < service->num_params;
1040 /* should includes also be printed? */
1041 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1043 service->param_values[param_count]);
1044 param_is_set = true;
1048 if (!param_is_set) {
1049 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1051 werr = WERR_BADFILE;
1057 if (!(W_ERROR_IS_OK(werr))) {
1058 status = werror_to_ntstatus(werr);
1061 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1062 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1069 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1070 const struct dom_sid *domain_sid,
1071 const char *domain_name,
1072 struct cli_state *cli,
1073 struct rpc_pipe_client *pipe_hnd,
1074 TALLOC_CTX *mem_ctx,
1078 TALLOC_CTX *frame = talloc_stackframe();
1079 NTSTATUS status = NT_STATUS_OK;
1080 WERROR werr = WERR_OK;
1083 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1086 struct policy_handle hive_hnd, key_hnd;
1089 ZERO_STRUCT(hive_hnd);
1090 ZERO_STRUCT(key_hnd);
1093 if (argc != 2 || c->display_usage) {
1094 rpc_conf_delparm_usage(c, argc, argv);
1095 status = NT_STATUS_INVALID_PARAMETER;
1099 status = rpc_conf_open_conf(frame,
1106 if (!(NT_STATUS_IS_OK(status))) {
1110 if (!(W_ERROR_IS_OK(werr))) {
1114 status = rpc_conf_del_value(frame,
1123 if (!(W_ERROR_IS_OK(werr))) {
1124 status = werror_to_ntstatus(werr);
1127 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1128 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1135 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1136 const struct dom_sid *domain_sid,
1137 const char *domain_name,
1138 struct cli_state *cli,
1139 struct rpc_pipe_client *pipe_hnd,
1140 TALLOC_CTX *mem_ctx,
1144 TALLOC_CTX *frame = talloc_stackframe();
1145 NTSTATUS status = NT_STATUS_OK;
1146 WERROR werr = WERR_OK;
1149 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1152 struct policy_handle hive_hnd, key_hnd;
1153 struct smbconf_service *service = NULL;
1155 uint32_t param_count;
1158 ZERO_STRUCT(hive_hnd);
1159 ZERO_STRUCT(key_hnd);
1162 if (argc != 1 || c->display_usage) {
1163 rpc_conf_getincludes_usage(c, argc, argv);
1164 status = NT_STATUS_INVALID_PARAMETER;
1168 status = rpc_conf_open_conf(frame,
1175 if (!(NT_STATUS_IS_OK(status))) {
1179 if (!(W_ERROR_IS_OK(werr))) {
1183 service = talloc(frame, struct smbconf_service);
1185 status = rpc_conf_get_share(frame,
1192 if (!(NT_STATUS_IS_OK(status))) {
1196 if (!(W_ERROR_IS_OK(werr))) {
1200 for (param_count = 0;
1201 param_count < service->num_params;
1204 if (strcmp(service->param_names[param_count], "include") == 0) {
1205 d_printf(_("%s = %s\n"),
1206 service->param_names[param_count],
1207 service->param_values[param_count]);
1213 if (!(W_ERROR_IS_OK(werr))) {
1214 status = werror_to_ntstatus(werr);
1217 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1218 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1225 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
1226 const struct dom_sid *domain_sid,
1227 const char *domain_name,
1228 struct cli_state *cli,
1229 struct rpc_pipe_client *pipe_hnd,
1230 TALLOC_CTX *mem_ctx,
1234 TALLOC_CTX *frame = talloc_stackframe();
1235 NTSTATUS status = NT_STATUS_OK;
1236 WERROR werr = WERR_OK;
1239 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1242 struct policy_handle hive_hnd, key_hnd;
1245 ZERO_STRUCT(hive_hnd);
1246 ZERO_STRUCT(key_hnd);
1249 if (argc != 1 || c->display_usage) {
1250 rpc_conf_delincludes_usage(c, argc, argv);
1251 status = NT_STATUS_INVALID_PARAMETER;
1254 /* try REG_KEY_WRITE */
1255 status = rpc_conf_open_conf(frame,
1262 if (!(NT_STATUS_IS_OK(status))) {
1266 if (!(W_ERROR_IS_OK(werr))) {
1270 status = rpc_conf_del_value(frame,
1279 if (!(W_ERROR_IS_OK(werr))) {
1280 status = werror_to_ntstatus(werr);
1283 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1284 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1291 static int rpc_conf_drop(struct net_context *c, int argc,
1294 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1295 rpc_conf_drop_internal, argc, argv );
1299 static int rpc_conf_showshare(struct net_context *c, int argc,
1302 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1303 rpc_conf_showshare_internal, argc, argv );
1306 static int rpc_conf_listshares(struct net_context *c, int argc,
1309 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1310 rpc_conf_listshares_internal, argc, argv );
1313 static int rpc_conf_list(struct net_context *c, int argc,
1316 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1317 rpc_conf_list_internal, argc, argv );
1320 static int rpc_conf_delshare(struct net_context *c, int argc,
1323 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1324 rpc_conf_delshare_internal, argc, argv );
1327 static int rpc_conf_getparm(struct net_context *c, int argc,
1330 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1331 rpc_conf_getparm_internal, argc, argv );
1334 static int rpc_conf_setparm(struct net_context *c, int argc,
1337 d_printf("Function not yet implemented\n");
1340 static int rpc_conf_delparm(struct net_context *c, int argc,
1343 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1344 rpc_conf_delparm_internal, argc, argv );
1347 static int rpc_conf_getincludes(struct net_context *c, int argc,
1350 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1351 rpc_conf_getincludes_internal, argc, argv );
1354 static int rpc_conf_delincludes(struct net_context *c, int argc,
1357 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
1358 rpc_conf_delincludes_internal, argc, argv );
1360 /* function calls */
1361 int net_rpc_conf(struct net_context *c, int argc,
1364 struct functable func_table[] = {
1369 N_("Dump the complete remote configuration in smb.conf like "
1371 N_("net rpc conf list\n"
1372 " Dump the complete remote configuration in smb.conf "
1378 rpc_conf_listshares,
1380 N_("List the remote share names."),
1381 N_("net rpc conf list\n"
1382 " List the remote share names.")
1389 N_("Delete the complete remote configuration."),
1390 N_("net rpc conf drop\n"
1391 " Delete the complete remote configuration.")
1398 N_("Show the definition of a remote share."),
1399 N_("net rpc conf showshare\n"
1400 " Show the definition of a remote share.")
1407 N_("Delete a remote share."),
1408 N_("net rpc conf delshare\n"
1409 " Delete a remote share.")
1415 N_("Retrieve the value of a parameter."),
1416 N_("net rpc conf getparm\n"
1417 " Retrieve the value of a parameter.")
1423 N_("Store a parameter."),
1424 N_("net rpc conf setparm\n"
1425 " Store a parameter.")
1431 N_("Delete a parameter."),
1432 N_("net rpc conf delparm\n"
1433 " Delete a parameter.")
1437 rpc_conf_getincludes,
1439 N_("Show the includes of a share definition."),
1440 N_("net rpc conf getincludes\n"
1441 " Show the includes of a share definition.")
1445 rpc_conf_delincludes,
1447 N_("Delete includes from a share definition."),
1448 N_("net rpc conf delincludes\n"
1449 " Delete includes from a share definition.")
1451 {NULL, NULL, 0, NULL, NULL}
1454 return net_run_function(c, argc, argv, "net rpc conf", func_table);