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 "utils/net_conf_util.h"
32 #include "rpc_client/cli_pipe.h"
33 #include "../librpc/gen_ndr/ndr_samr_c.h"
34 #include "rpc_client/init_samr.h"
35 #include "../librpc/gen_ndr/ndr_winreg_c.h"
36 #include "../libcli/registry/util_reg.h"
37 #include "rpc_client/cli_winreg.h"
38 #include "lib/smbconf/smbconf.h"
39 #include "lib/smbconf/smbconf_init.h"
40 #include "lib/smbconf/smbconf_reg.h"
41 #include "lib/param/loadparm.h"
45 /* internal functions */
46 /**********************************************************
50 **********************************************************/
51 const char confpath[100] = "Software\\Samba\\smbconf";
53 static int rpc_conf_list_usage(struct net_context *c, int argc,
56 d_printf("%s net rpc conf list\n", _("Usage:"));
60 static int rpc_conf_listshares_usage(struct net_context *c, int argc,
63 d_printf("%s net rpc conf listshares\n", _("Usage:"));
67 static int rpc_conf_delshare_usage(struct net_context *c, int argc,
72 _("net rpc conf delshare <sharename>\n"));
76 static int rpc_conf_addshare_usage(struct net_context *c, int argc,
81 _(" net rpc conf addshare <sharename> <path> "
82 "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
83 "\t<sharename> the new share name.\n"
84 "\t<path> the path on the filesystem to export.\n"
85 "\twriteable={y|N} set \"writeable to \"yes\" or "
86 "\"no\" (default) on this share.\n"
87 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
88 "\"no\" (default) on this share.\n"
89 "\t<comment> optional comment for the new share.\n"));
94 static int rpc_conf_import_usage(struct net_context *c, int argc,
99 _(" net rpc conf import [--test|-T] <filename> "
101 "\t[--test|-T] testmode - do not act, just print "
102 "what would be done\n"
103 "\t<servicename> only import service <servicename>, "
104 "ignore the rest\n"));
108 static int rpc_conf_showshare_usage(struct net_context *c, int argc,
113 _("net rpc conf showshare <sharename>\n"));
117 static int rpc_conf_drop_usage(struct net_context *c, int argc,
120 d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
124 static int rpc_conf_getparm_usage(struct net_context *c, int argc,
127 d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
132 static int rpc_conf_setparm_usage(struct net_context *c, int argc,
137 _(" net rpc conf setparm <section> <param> <value>\n"));
141 static int rpc_conf_delparm_usage(struct net_context *c, int argc,
144 d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
149 static int rpc_conf_getincludes_usage(struct net_context *c, int argc,
152 d_printf("%s\nnet rpc conf getincludes <sharename>\n",
157 static int rpc_conf_setincludes_usage(struct net_context *c, int argc,
160 d_printf("%s\nnet rpc conf setincludes <sharename> [<filename>]*\n",
165 static int rpc_conf_delincludes_usage(struct net_context *c, int argc,
168 d_printf("%s\nnet rpc conf delincludes <sharename>\n",
173 /**********************************************************
177 **********************************************************/
180 * The function deletes a registry value with the name 'value' from the share
181 * with the name 'share_name'. 'parent_hnd' is the handle for the smbconf key.
183 static NTSTATUS rpc_conf_del_value(TALLOC_CTX *mem_ctx,
184 struct dcerpc_binding_handle *b,
185 struct policy_handle *parent_hnd,
186 const char *share_name,
191 TALLOC_CTX *frame = talloc_stackframe();
192 NTSTATUS status = NT_STATUS_OK;
193 WERROR result = WERR_OK;
196 struct winreg_String keyname, valuename;
197 struct policy_handle child_hnd;
199 ZERO_STRUCT(child_hnd);
200 ZERO_STRUCT(keyname);
201 ZERO_STRUCT(valuename);
203 keyname.name = share_name;
204 valuename.name = value;
206 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, keyname, 0,
207 REG_KEY_WRITE, &child_hnd, &result);
209 if (!(NT_STATUS_IS_OK(status))) {
210 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
211 keyname.name, nt_errstr(status));
215 if (!(W_ERROR_IS_OK(result))) {
216 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
217 keyname.name, win_errstr(result));
221 status = dcerpc_winreg_DeleteValue(b,
227 if (!(NT_STATUS_IS_OK(status))) {
228 d_fprintf(stderr, _("Failed to delete value %s\n"),
233 if (!(W_ERROR_IS_OK(result))) {
234 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)){
239 d_fprintf(stderr, _("Failed to delete value %s\n"),
247 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
255 * The function sets a share in the registry with the parameters
256 * held in the smbconf_service struct
258 static NTSTATUS rpc_conf_set_share(TALLOC_CTX *mem_ctx,
259 struct dcerpc_binding_handle *b,
260 struct policy_handle *parent_hnd,
261 struct smbconf_service *service,
264 TALLOC_CTX *frame = talloc_stackframe();
266 NTSTATUS status = NT_STATUS_OK;
267 WERROR result = WERR_OK;
269 enum winreg_CreateAction action;
272 const char **includes;
274 struct winreg_String wkey, wkeyclass;
275 struct policy_handle share_hnd;
277 ZERO_STRUCT(share_hnd);
279 ZERO_STRUCT(wkeyclass);
281 wkey.name = service->name;
283 action = REG_ACTION_NONE;
285 status = dcerpc_winreg_CreateKey(b,
297 if (!NT_STATUS_IS_OK(status)) {
298 d_printf("winreg_CreateKey: Could not create smbconf key\n");
302 if (!W_ERROR_IS_OK(result)) {
303 d_printf("winreg_CreateKey: Could not create smbconf key\n");
307 for (i = 0; i < service->num_params; i++) {
308 if (strequal(service->param_names[i], "include") == 0)
311 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
312 service->param_names[i],
313 service->param_values[i],
316 if (!(NT_STATUS_IS_OK(status))) {
318 "ERROR: Share: '%s'\n"
319 "Could not set parameter '%s'"
320 " with value %s\n %s\n",
322 service->param_names[i],
323 service->param_values[i],
328 if (!(W_ERROR_IS_OK(result))) {
330 "ERROR: Share: '%s'\n"
331 "Could not set parameter '%s'"
332 " with value %s\n %s\n",
334 service->param_names[i],
335 service->param_values[i],
341 includes = talloc_zero_array(frame,
343 service->num_params + 1);
344 if (includes == NULL) {
345 result = WERR_NOT_ENOUGH_MEMORY;
346 d_fprintf(stderr, "ERROR: out of memory\n");
350 for (j = i; j < service->num_params; j++) {
352 includes[j - i] = talloc_strdup(
354 service->param_values[j]);
356 if (includes[j-i] == NULL) {
357 result = WERR_NOT_ENOUGH_MEMORY;
358 d_fprintf(stderr, "ERROR: out of memory\n");
363 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
368 if (!(NT_STATUS_IS_OK(status))) {
369 d_fprintf(stderr, "ERROR: Share: '%s'\n"
370 "Could not set includes\n %s\n",
376 if (!(W_ERROR_IS_OK(result))) {
377 d_fprintf(stderr, "ERROR: Share: '%s'\n"
378 "Could not set includes\n %s\n",
384 i = service->num_params;
389 /* in case of error, should it delete the created key? */
390 if (!(W_ERROR_IS_OK(result))) {
391 status = werror_to_ntstatus(result);
395 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
403 * The function opens the registry database and retrieves
404 * as a smbconf_service struct the share with the name
407 static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx,
408 struct dcerpc_binding_handle *b,
409 struct policy_handle *parent_hnd,
410 const char *share_name,
411 struct smbconf_service *share,
414 TALLOC_CTX *frame = talloc_stackframe();
416 NTSTATUS status = NT_STATUS_OK;
417 WERROR result = WERR_OK;
419 struct policy_handle child_hnd;
420 int32_t includes_cnt, includes_idx = -1;
421 uint32_t num_vals, num_subkeys, i, param_cnt = 0;
422 const char **val_names;
423 const char **subkeys = NULL;
424 enum winreg_Type *types;
426 struct winreg_String key = { 0, };
427 const char **multi_s = NULL;
428 const char *s = NULL;
429 struct smbconf_service tmp_share;
431 ZERO_STRUCT(tmp_share);
434 * Determine correct upper/lowercase.
436 status = dcerpc_winreg_enum_keys(frame,
442 if (!(NT_STATUS_IS_OK(status))) {
443 d_fprintf(stderr, _("Failed to enumerate shares: %s\n"),
447 if (!(W_ERROR_IS_OK(result))) {
448 d_fprintf(stderr, _("Failed to enumerate shares: %s\n"),
453 for (i = 0; i < num_subkeys; i++) {
454 if (!strequal(share_name, subkeys[i])) {
458 key.name = subkeys[i];
461 if (key.name == NULL) {
462 d_fprintf(stderr, _("Could not find share.\n"));
466 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
467 REG_KEY_READ, &child_hnd, &result);
469 if (!(NT_STATUS_IS_OK(status))) {
470 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
474 if (!(W_ERROR_IS_OK(result))) {
475 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
479 /* get all the info from the share key */
480 status = dcerpc_winreg_enumvals(frame,
489 if (!(NT_STATUS_IS_OK(status))) {
490 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
494 if (!(W_ERROR_IS_OK(result))) {
495 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
499 /* check for includes */
500 for (i = 0; i < num_vals; i++) {
501 if (strcmp(val_names[i], "includes") == 0){
502 if (!pull_reg_multi_sz(frame,
506 result = WERR_NOT_ENOUGH_MEMORY;
508 _("Failed to enumerate values: %s\n"),
515 /* count the number of includes */
517 if (includes_idx != -1) {
518 for (includes_cnt = 0;
519 multi_s[includes_cnt] != NULL;
522 /* place the name of the share in the smbconf_service struct */
523 tmp_share.name = talloc_strdup(frame, key.name);
524 if (tmp_share.name == NULL) {
525 result = WERR_NOT_ENOUGH_MEMORY;
526 d_fprintf(stderr, _("Failed to create share: %s\n"),
530 /* place the number of parameters in the smbconf_service struct */
531 tmp_share.num_params = num_vals;
532 if (includes_idx != -1) {
533 tmp_share.num_params = num_vals + includes_cnt - 1;
535 /* allocate memory for the param_names and param_values lists */
536 tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
537 if (tmp_share.param_names == NULL) {
538 result = WERR_NOT_ENOUGH_MEMORY;
539 d_fprintf(stderr, _("Failed to create share: %s\n"),
543 tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
544 if (tmp_share.param_values == NULL) {
545 result = WERR_NOT_ENOUGH_MEMORY;
546 d_fprintf(stderr, _("Failed to create share: %s\n"),
550 /* place all params except includes */
551 for (i = 0; i < num_vals; i++) {
552 if (strcmp(val_names[i], "includes") != 0) {
553 if (!pull_reg_sz(frame, &data[i], &s)) {
554 result = WERR_NOT_ENOUGH_MEMORY;
556 _("Failed to enumerate values: %s\n"),
560 /* place param_names */
561 tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
562 if (tmp_share.param_names[param_cnt] == NULL) {
563 result = WERR_NOT_ENOUGH_MEMORY;
564 d_fprintf(stderr, _("Failed to create share: %s\n"),
569 /* place param_values */
570 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
571 if (tmp_share.param_values[param_cnt - 1] == NULL) {
572 result = WERR_NOT_ENOUGH_MEMORY;
573 d_fprintf(stderr, _("Failed to create share: %s\n"),
579 /* place the includes last */
580 for (i = 0; i < includes_cnt; i++) {
581 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
582 if (tmp_share.param_names[param_cnt] == NULL) {
583 result = WERR_NOT_ENOUGH_MEMORY;
584 d_fprintf(stderr, _("Failed to create share: %s\n"),
589 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
590 if (tmp_share.param_values[param_cnt - 1] == NULL) {
591 result = WERR_NOT_ENOUGH_MEMORY;
592 d_fprintf(stderr, _("Failed to create share: %s\n"),
598 /* move everything to the main memory ctx */
599 for (i = 0; i < param_cnt; i++) {
600 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
601 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
604 tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
605 tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
606 tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
611 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
618 * The function prints the shares held as smbconf_service structs
619 * in a smbconf file format.
621 static int rpc_conf_print_shares(uint32_t num_shares,
622 struct smbconf_service *shares)
625 uint32_t share_count, param_count;
626 const char *indent = "\t";
628 if (num_shares == 0) {
632 for (share_count = 0; share_count < num_shares; share_count++) {
634 if (shares[share_count].name != NULL) {
635 d_printf("[%s]\n", shares[share_count].name);
638 for (param_count = 0;
639 param_count < shares[share_count].num_params;
642 d_printf("%s%s = %s\n",
644 shares[share_count].param_names[param_count],
645 shares[share_count].param_values[param_count]);
655 * The function opens the registry key
656 * HKLM/Software/Samba/smbconf with the give access_mask
658 static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
659 struct dcerpc_binding_handle *b,
660 uint32_t access_mask,
661 struct policy_handle *hive_hnd,
662 struct policy_handle *key_hnd,
665 TALLOC_CTX *frame = talloc_stackframe();
666 NTSTATUS status = NT_STATUS_OK;
667 WERROR result = WERR_OK;
669 struct policy_handle tmp_hive_hnd, tmp_key_hnd;
670 struct winreg_String key;
674 status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
675 access_mask, &tmp_hive_hnd, &result);
678 * print no error messages if it is a read only open
679 * and key does not exist
680 * error still gets returned
683 if (access_mask == REG_KEY_READ &&
684 W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND))
689 if (!(NT_STATUS_IS_OK(status))) {
690 d_fprintf(stderr, _("Failed to open hive: %s\n"),
694 if (!W_ERROR_IS_OK(result)) {
695 d_fprintf(stderr, _("Failed to open hive: %s\n"),
701 status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
702 access_mask, &tmp_key_hnd, &result);
705 * print no error messages if it is a read only open
706 * and key does not exist
707 * error still gets returned
710 if (access_mask == REG_KEY_READ &&
711 W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND))
716 if (!(NT_STATUS_IS_OK(status))) {
717 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
719 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
722 if (!(W_ERROR_IS_OK(result))) {
723 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
725 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
729 *hive_hnd = tmp_hive_hnd;
730 *key_hnd = tmp_key_hnd;
739 /**********************************************************
741 * internal functions that provide the functionality
744 **********************************************************/
746 static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
747 const struct dom_sid *domain_sid,
748 const char *domain_name,
749 struct cli_state *cli,
750 struct rpc_pipe_client *pipe_hnd,
756 TALLOC_CTX *frame = talloc_stackframe();
757 NTSTATUS status = NT_STATUS_OK;
758 WERROR werr = WERR_OK;
761 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
764 struct policy_handle hive_hnd, key_hnd;
765 uint32_t num_subkeys;
767 const char **subkeys = NULL;
770 ZERO_STRUCT(hive_hnd);
771 ZERO_STRUCT(key_hnd);
774 if (argc != 0 || c->display_usage) {
775 rpc_conf_listshares_usage(c, argc, argv);
776 status = NT_STATUS_INVALID_PARAMETER;
781 status = rpc_conf_open_conf(frame,
788 if (!(NT_STATUS_IS_OK(status))) {
792 if (!(W_ERROR_IS_OK(werr))) {
796 status = dcerpc_winreg_enum_keys(frame,
803 if (!(NT_STATUS_IS_OK(status))) {
804 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
809 if (!(W_ERROR_IS_OK(werr))) {
810 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
815 for (i = 0; i < num_subkeys; i++) {
816 d_printf("%s\n", subkeys[i]);
820 if (!(W_ERROR_IS_OK(werr))) {
821 status = werror_to_ntstatus(werr);
824 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
825 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
831 static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
832 const struct dom_sid *domain_sid,
833 const char *domain_name,
834 struct cli_state *cli,
835 struct rpc_pipe_client *pipe_hnd,
841 TALLOC_CTX *frame = talloc_stackframe();
842 NTSTATUS status = NT_STATUS_OK;
843 WERROR werr = WERR_OK;
846 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
849 struct policy_handle hive_hnd, key_hnd;
851 ZERO_STRUCT(hive_hnd);
852 ZERO_STRUCT(key_hnd);
855 if (argc != 1 || c->display_usage) {
856 rpc_conf_delshare_usage(c, argc, argv);
857 status = NT_STATUS_INVALID_PARAMETER;
861 status = rpc_conf_open_conf(frame,
868 if (!(NT_STATUS_IS_OK(status))) {
872 if (!(W_ERROR_IS_OK(werr))) {
876 status = dcerpc_winreg_delete_subkeys_recursive(frame,
883 if (!NT_STATUS_IS_OK(status)) {
885 "winreg_delete_subkeys: Could not delete key %s: %s\n",
886 argv[0], nt_errstr(status));
890 if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)){
891 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
895 if (!W_ERROR_IS_OK(werr)) {
897 "winreg_delete_subkeys: Could not delete key %s: %s\n",
898 argv[0], win_errstr(werr));
903 if (!(W_ERROR_IS_OK(werr))) {
904 status = werror_to_ntstatus(werr);
907 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
908 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
915 static NTSTATUS rpc_conf_list_internal(struct net_context *c,
916 const struct dom_sid *domain_sid,
917 const char *domain_name,
918 struct cli_state *cli,
919 struct rpc_pipe_client *pipe_hnd,
925 TALLOC_CTX *frame = talloc_stackframe();
926 NTSTATUS status = NT_STATUS_OK;
927 WERROR werr = WERR_OK;
930 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
933 struct policy_handle hive_hnd, key_hnd;
934 uint32_t num_subkeys;
936 struct smbconf_service *shares;
937 const char **subkeys = NULL;
940 ZERO_STRUCT(hive_hnd);
941 ZERO_STRUCT(key_hnd);
944 if (argc != 0 || c->display_usage) {
945 rpc_conf_list_usage(c, argc, argv);
946 status = NT_STATUS_INVALID_PARAMETER;
950 status = rpc_conf_open_conf(frame,
957 if (!(NT_STATUS_IS_OK(status))) {
961 if (!(W_ERROR_IS_OK(werr))) {
965 status = dcerpc_winreg_enum_keys(frame,
972 if (!(NT_STATUS_IS_OK(status))) {
973 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
978 if (!(W_ERROR_IS_OK(werr))) {
979 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
984 if (num_subkeys == 0) {
985 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
986 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
991 /* get info from each subkey */
992 shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
993 if (shares == NULL) {
994 werr = WERR_NOT_ENOUGH_MEMORY;
995 d_fprintf(stderr, _("Failed to create shares: %s\n"),
1001 for (i = 0; i < num_subkeys; i++) {
1002 /* get each share and place it in the shares array */
1003 status = rpc_conf_get_share(frame,
1009 if (!(NT_STATUS_IS_OK(status))) {
1012 if (!(W_ERROR_IS_OK(werr))) {
1017 /* print the shares array */
1018 rpc_conf_print_shares(num_subkeys, shares);
1021 if (!(W_ERROR_IS_OK(werr))) {
1022 status = werror_to_ntstatus(werr);
1025 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1026 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1033 static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
1034 const struct dom_sid *domain_sid,
1035 const char *domain_name,
1036 struct cli_state *cli,
1037 struct rpc_pipe_client *pipe_hnd,
1038 TALLOC_CTX *mem_ctx,
1042 TALLOC_CTX *frame = talloc_stackframe();
1043 NTSTATUS status = NT_STATUS_OK;
1044 WERROR werr = WERR_OK;
1047 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1050 struct policy_handle hive_hnd, key_hnd;
1051 const char *keyname = confpath;
1052 struct winreg_String wkey, wkeyclass;
1053 enum winreg_CreateAction action = REG_ACTION_NONE;
1056 ZERO_STRUCT(hive_hnd);
1057 ZERO_STRUCT(key_hnd);
1060 if (argc != 0 || c->display_usage) {
1061 rpc_conf_drop_usage(c, argc, argv);
1062 status = NT_STATUS_INVALID_PARAMETER;
1066 status = rpc_conf_open_conf(frame,
1073 if (!(NT_STATUS_IS_OK(status))) {
1077 if (!(W_ERROR_IS_OK(werr))) {
1081 status = dcerpc_winreg_delete_subkeys_recursive(frame,
1088 if (!NT_STATUS_IS_OK(status)) {
1089 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1090 keyname, nt_errstr(status));
1094 if (!W_ERROR_IS_OK(werr)) {
1095 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1096 keyname, win_errstr(werr));
1101 wkey.name = keyname;
1102 ZERO_STRUCT(wkeyclass);
1103 wkeyclass.name = "";
1104 action = REG_ACTION_NONE;
1106 status = dcerpc_winreg_CreateKey(b,
1118 if (!NT_STATUS_IS_OK(status)) {
1119 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1123 if (!W_ERROR_IS_OK(werr)) {
1124 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1130 if (!(W_ERROR_IS_OK(werr))) {
1131 status = werror_to_ntstatus(werr);
1134 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1135 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1141 static NTSTATUS rpc_conf_import_internal(struct net_context *c,
1142 const struct dom_sid *domain_sid,
1143 const char *domain_name,
1144 struct cli_state *cli,
1145 struct rpc_pipe_client *pipe_hnd,
1146 TALLOC_CTX *mem_ctx,
1151 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1153 struct policy_handle hive_hnd, key_hnd;
1155 const char *filename = NULL;
1156 const char *servicename = NULL;
1157 char *conf_source = NULL;
1159 struct smbconf_ctx *txt_ctx;
1160 struct smbconf_service *service = NULL;
1161 struct smbconf_service **services = NULL;
1162 uint32_t num_shares, i;
1163 sbcErr err = SBC_ERR_UNKNOWN_FAILURE;
1165 WERROR werr = WERR_OK;
1166 NTSTATUS status = NT_STATUS_OK;
1168 ZERO_STRUCT(hive_hnd);
1169 ZERO_STRUCT(key_hnd);
1171 frame = talloc_stackframe();
1173 if (c->display_usage) {
1174 rpc_conf_import_usage(c, argc, argv);
1175 status = NT_STATUS_INVALID_PARAMETER;
1182 rpc_conf_import_usage(c, argc, argv);
1183 status = NT_STATUS_INVALID_PARAMETER;
1186 servicename = talloc_strdup(frame, argv[1]);
1187 if (servicename == NULL) {
1188 d_printf(_("error: out of memory!\n"));
1198 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1201 conf_source = talloc_asprintf(frame, "file:%s", filename);
1202 if (conf_source == NULL) {
1203 d_fprintf(stderr, _("error: out of memory!\n"));
1207 err = smbconf_init(frame, &txt_ctx, conf_source);
1208 if (!SBC_ERROR_IS_OK(err)) {
1209 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
1210 sbcErrorString(err));
1214 if (c->opt_testmode) {
1215 d_printf(_("\nTEST MODE - "
1216 "would import the following configuration:\n\n"));
1219 if (servicename != NULL) {
1220 err = smbconf_get_share(txt_ctx, frame,
1223 if (!SBC_ERROR_IS_OK(err)) {
1231 err = smbconf_get_config(txt_ctx, frame,
1234 if (!SBC_ERROR_IS_OK(err)) {
1239 if (c->opt_testmode) {
1240 if (servicename != NULL) {
1241 rpc_conf_print_shares(1, service);
1243 for (i = 0; i < num_shares; i++) {
1244 rpc_conf_print_shares(1, services[i]);
1249 status = rpc_conf_drop_internal(c,
1258 if (!(NT_STATUS_IS_OK(status))) {
1262 status = rpc_conf_open_conf(frame,
1269 if (!(NT_STATUS_IS_OK(status))) {
1273 if (!(W_ERROR_IS_OK(werr))) {
1277 if (servicename != NULL) {
1278 status = rpc_conf_set_share(frame,
1284 if (!(NT_STATUS_IS_OK(status))) {
1288 if (!(W_ERROR_IS_OK(werr))) {
1294 for (i = 0; i < num_shares; i++) {
1295 status = rpc_conf_set_share(frame,
1301 if (!(NT_STATUS_IS_OK(status))) {
1305 if (!(W_ERROR_IS_OK(werr))) {
1313 if (!SBC_ERROR_IS_OK(err)) {
1314 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
1317 if (!(W_ERROR_IS_OK(werr))) {
1318 status = werror_to_ntstatus(werr);
1324 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
1325 const struct dom_sid *domain_sid,
1326 const char *domain_name,
1327 struct cli_state *cli,
1328 struct rpc_pipe_client *pipe_hnd,
1329 TALLOC_CTX *mem_ctx,
1333 TALLOC_CTX *frame = talloc_stackframe();
1334 NTSTATUS status = NT_STATUS_OK;
1335 WERROR werr = WERR_OK;
1338 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1341 struct policy_handle hive_hnd, key_hnd;
1342 struct smbconf_service *service = NULL;
1343 const char *sharename = NULL;
1346 ZERO_STRUCT(hive_hnd);
1347 ZERO_STRUCT(key_hnd);
1350 if (argc != 1 || c->display_usage) {
1351 rpc_conf_showshare_usage(c, argc, argv);
1352 status = NT_STATUS_INVALID_PARAMETER;
1356 status = rpc_conf_open_conf(frame,
1363 if (!(NT_STATUS_IS_OK(status))) {
1367 if (!(W_ERROR_IS_OK(werr))) {
1371 sharename = talloc_strdup(frame, argv[0]);
1372 if (sharename == NULL) {
1373 werr = WERR_NOT_ENOUGH_MEMORY;
1374 d_fprintf(stderr, _("Failed to create share: %s\n"),
1379 service = talloc(frame, struct smbconf_service);
1380 if (service == NULL) {
1381 werr = WERR_NOT_ENOUGH_MEMORY;
1382 d_fprintf(stderr, _("Failed to create share: %s\n"),
1387 status = rpc_conf_get_share(frame,
1394 if (!(NT_STATUS_IS_OK(status))) {
1397 if (!(W_ERROR_IS_OK(werr))) {
1401 rpc_conf_print_shares(1, service);
1404 if (!(W_ERROR_IS_OK(werr))) {
1405 status = werror_to_ntstatus(werr);
1408 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1409 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1415 static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
1416 const struct dom_sid *domain_sid,
1417 const char *domain_name,
1418 struct cli_state *cli,
1419 struct rpc_pipe_client *pipe_hnd,
1420 TALLOC_CTX *mem_ctx,
1424 TALLOC_CTX *frame = talloc_stackframe();
1425 NTSTATUS status = NT_STATUS_OK;
1426 WERROR werr = WERR_OK;
1429 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1432 struct policy_handle hive_hnd, key_hnd, share_hnd;
1433 char *sharename = NULL;
1434 const char *path = NULL;
1435 const char *comment = NULL;
1436 const char *guest_ok = "no";
1437 const char *read_only = "yes";
1438 struct winreg_String key, keyclass;
1439 enum winreg_CreateAction action = 0;
1442 ZERO_STRUCT(hive_hnd);
1443 ZERO_STRUCT(key_hnd);
1444 ZERO_STRUCT(share_hnd);
1447 ZERO_STRUCT(keyclass);
1449 if (c->display_usage) {
1450 rpc_conf_addshare_usage(c, argc, argv);
1451 status = NT_STATUS_INVALID_PARAMETER;
1459 rpc_conf_addshare_usage(c, argc, argv);
1460 status = NT_STATUS_INVALID_PARAMETER;
1467 if (!strnequal(argv[3], "guest_ok=", 9)) {
1468 rpc_conf_addshare_usage(c, argc, argv);
1469 status = NT_STATUS_INVALID_PARAMETER;
1472 switch (argv[3][9]) {
1482 rpc_conf_addshare_usage(c, argc, argv);
1483 status = NT_STATUS_INVALID_PARAMETER;
1489 if (!strnequal(argv[2], "writeable=", 10)) {
1490 rpc_conf_addshare_usage(c, argc, argv);
1491 status = NT_STATUS_INVALID_PARAMETER;
1494 switch (argv[2][10]) {
1504 rpc_conf_addshare_usage(c, argc, argv);
1505 status = NT_STATUS_INVALID_PARAMETER;
1512 sharename = talloc_strdup(frame, argv[0]);
1513 if (sharename == NULL) {
1514 d_printf(_("error: out of memory!\n"));
1521 status = rpc_conf_open_conf(frame,
1528 if (!(NT_STATUS_IS_OK(status))) {
1532 if (!(W_ERROR_IS_OK(werr))) {
1539 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1540 0, REG_KEY_READ, NULL, &share_hnd,
1543 if (!(NT_STATUS_IS_OK(status))) {
1544 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1545 argv[0], nt_errstr(status));
1549 if (!W_ERROR_IS_OK(werr)) {
1550 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1551 argv[0], win_errstr(werr));
1556 case REG_ACTION_NONE:
1557 werr = WERR_CREATE_FAILED;
1558 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1559 argv[0], win_errstr(werr));
1561 case REG_CREATED_NEW_KEY:
1562 DEBUG(5, ("net rpc conf setincludes:"
1563 "createkey created %s\n", argv[0]));
1565 case REG_OPENED_EXISTING_KEY:
1566 d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
1567 status = NT_STATUS_INVALID_PARAMETER;
1571 /* set the path parameter */
1572 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1573 "path", path, &werr);
1575 if (!(NT_STATUS_IS_OK(status))) {
1576 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1577 " with value %s\n %s\n",
1578 "path", path, nt_errstr(status));
1582 if (!(W_ERROR_IS_OK(werr))) {
1583 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1584 " with value %s\n %s\n",
1585 "path", path, win_errstr(werr));
1589 /* set the writeable parameter */
1590 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1591 "read only", read_only, &werr);
1593 if (!(NT_STATUS_IS_OK(status))) {
1594 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1595 " with value %s\n %s\n",
1596 "read only", read_only, nt_errstr(status));
1600 if (!(W_ERROR_IS_OK(werr))) {
1601 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1602 " with value %s\n %s\n",
1603 "read only", read_only, win_errstr(werr));
1607 /* set the guest ok parameter */
1608 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1609 "guest ok", guest_ok, &werr);
1611 if (!(NT_STATUS_IS_OK(status))) {
1612 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1613 " with value %s\n %s\n",
1614 "guest ok", guest_ok, nt_errstr(status));
1618 if (!(W_ERROR_IS_OK(werr))) {
1619 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1620 " with value %s\n %s\n",
1621 "guest ok", guest_ok, win_errstr(werr));
1626 /* set the comment parameter */
1627 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1628 "comment", comment, &werr);
1630 if (!(NT_STATUS_IS_OK(status))) {
1631 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1632 " with value %s\n %s\n",
1633 "comment", comment, nt_errstr(status));
1637 if (!(W_ERROR_IS_OK(werr))) {
1638 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1639 " with value %s\n %s\n",
1640 "comment", comment, win_errstr(werr));
1645 if (!(W_ERROR_IS_OK(werr))) {
1646 status = werror_to_ntstatus(werr);
1649 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1650 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1651 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1657 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
1658 const struct dom_sid *domain_sid,
1659 const char *domain_name,
1660 struct cli_state *cli,
1661 struct rpc_pipe_client *pipe_hnd,
1662 TALLOC_CTX *mem_ctx,
1666 TALLOC_CTX *frame = talloc_stackframe();
1667 NTSTATUS status = NT_STATUS_OK;
1668 WERROR werr = WERR_OK;
1671 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1674 struct policy_handle hive_hnd, key_hnd;
1675 struct smbconf_service *service = NULL;
1677 bool param_is_set = false;
1678 uint32_t param_count;
1680 ZERO_STRUCT(hive_hnd);
1681 ZERO_STRUCT(key_hnd);
1684 if (argc != 2 || c->display_usage) {
1685 rpc_conf_getparm_usage(c, argc, argv);
1686 status = NT_STATUS_INVALID_PARAMETER;
1690 status = rpc_conf_open_conf(frame,
1697 if (!(NT_STATUS_IS_OK(status))) {
1701 if (!(W_ERROR_IS_OK(werr))) {
1706 service = talloc(frame, struct smbconf_service);
1708 status = rpc_conf_get_share(frame,
1715 if (!(NT_STATUS_IS_OK(status))) {
1719 if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)) {
1720 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1725 if (!(W_ERROR_IS_OK(werr))) {
1729 for (param_count = 0;
1730 param_count < service->num_params;
1733 /* should includes also be printed? */
1734 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1736 service->param_values[param_count]);
1737 param_is_set = true;
1741 if (!param_is_set) {
1742 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1744 werr = WERR_FILE_NOT_FOUND;
1750 if (!(W_ERROR_IS_OK(werr))) {
1751 status = werror_to_ntstatus(werr);
1754 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1755 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1762 static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
1763 const struct dom_sid *domain_sid,
1764 const char *domain_name,
1765 struct cli_state *cli,
1766 struct rpc_pipe_client *pipe_hnd,
1767 TALLOC_CTX *mem_ctx,
1771 TALLOC_CTX *frame = talloc_stackframe();
1772 NTSTATUS status = NT_STATUS_OK;
1773 WERROR werr = WERR_OK;
1776 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1779 struct policy_handle hive_hnd, key_hnd, share_hnd;
1781 struct winreg_String key, keyclass;
1782 enum winreg_CreateAction action = 0;
1784 const char *service_name, *param_name, *valstr;
1786 ZERO_STRUCT(hive_hnd);
1787 ZERO_STRUCT(key_hnd);
1788 ZERO_STRUCT(share_hnd);
1791 ZERO_STRUCT(keyclass);
1793 if (argc != 3 || c->display_usage) {
1794 rpc_conf_setparm_usage(c, argc, argv);
1795 status = NT_STATUS_INVALID_PARAMETER;
1799 status = rpc_conf_open_conf(frame,
1806 if (!(NT_STATUS_IS_OK(status))) {
1810 if (!(W_ERROR_IS_OK(werr))) {
1814 service_name = argv[0];
1815 param_name = argv[1];
1818 key.name = service_name;
1821 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1822 0, REG_KEY_READ, NULL, &share_hnd,
1825 if (!(NT_STATUS_IS_OK(status))) {
1826 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1827 service_name, nt_errstr(status));
1831 if (!W_ERROR_IS_OK(werr)) {
1832 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1833 service_name, win_errstr(werr));
1838 case REG_ACTION_NONE:
1839 werr = WERR_CREATE_FAILED;
1840 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1841 service_name, win_errstr(werr));
1843 case REG_CREATED_NEW_KEY:
1844 DEBUG(5, ("net rpc conf setparm:"
1845 "createkey created %s\n", service_name));
1847 case REG_OPENED_EXISTING_KEY:
1848 DEBUG(5, ("net rpc conf setparm:"
1849 "createkey opened existing %s\n",
1852 /* delete possibly existing value */
1853 status = rpc_conf_del_value(frame,
1860 if (!(NT_STATUS_IS_OK(status))) {
1864 if (!(W_ERROR_IS_OK(werr))) {
1872 * check if parameter is valid for writing
1875 if (!net_conf_param_valid(service_name, param_name, valstr)) {
1876 werr = WERR_INVALID_PARAMETER;
1880 /* set the parameter */
1881 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1882 param_name, valstr, &werr);
1884 if (!(NT_STATUS_IS_OK(status))) {
1885 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1886 " with value %s\n %s\n",
1887 param_name, valstr, nt_errstr(status));
1891 if (!(W_ERROR_IS_OK(werr))) {
1892 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1893 " with value %s\n %s\n",
1894 param_name, valstr, win_errstr(werr));
1900 if (!(W_ERROR_IS_OK(werr))) {
1901 status = werror_to_ntstatus(werr);
1904 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1905 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1906 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1912 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1913 const struct dom_sid *domain_sid,
1914 const char *domain_name,
1915 struct cli_state *cli,
1916 struct rpc_pipe_client *pipe_hnd,
1917 TALLOC_CTX *mem_ctx,
1921 TALLOC_CTX *frame = talloc_stackframe();
1922 NTSTATUS status = NT_STATUS_OK;
1923 WERROR werr = WERR_OK;
1926 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1929 struct policy_handle hive_hnd, key_hnd;
1932 ZERO_STRUCT(hive_hnd);
1933 ZERO_STRUCT(key_hnd);
1936 if (argc != 2 || c->display_usage) {
1937 rpc_conf_delparm_usage(c, argc, argv);
1938 status = NT_STATUS_INVALID_PARAMETER;
1942 status = rpc_conf_open_conf(frame,
1949 if (!(NT_STATUS_IS_OK(status))) {
1953 if (!(W_ERROR_IS_OK(werr))) {
1957 status = rpc_conf_del_value(frame,
1966 if (!(W_ERROR_IS_OK(werr))) {
1967 status = werror_to_ntstatus(werr);
1970 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1971 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1978 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1979 const struct dom_sid *domain_sid,
1980 const char *domain_name,
1981 struct cli_state *cli,
1982 struct rpc_pipe_client *pipe_hnd,
1983 TALLOC_CTX *mem_ctx,
1987 TALLOC_CTX *frame = talloc_stackframe();
1988 NTSTATUS status = NT_STATUS_OK;
1989 WERROR werr = WERR_OK;
1992 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1995 struct policy_handle hive_hnd, key_hnd;
1996 struct smbconf_service *service = NULL;
1998 uint32_t param_count;
2001 ZERO_STRUCT(hive_hnd);
2002 ZERO_STRUCT(key_hnd);
2005 if (argc != 1 || c->display_usage) {
2006 rpc_conf_getincludes_usage(c, argc, argv);
2007 status = NT_STATUS_INVALID_PARAMETER;
2011 status = rpc_conf_open_conf(frame,
2018 if (!(NT_STATUS_IS_OK(status))) {
2022 if (!(W_ERROR_IS_OK(werr))) {
2026 service = talloc(frame, struct smbconf_service);
2028 status = rpc_conf_get_share(frame,
2035 if (!(NT_STATUS_IS_OK(status))) {
2039 if (!(W_ERROR_IS_OK(werr))) {
2043 for (param_count = 0;
2044 param_count < service->num_params;
2047 if (strcmp(service->param_names[param_count], "include") == 0) {
2048 d_printf(_("%s = %s\n"),
2049 service->param_names[param_count],
2050 service->param_values[param_count]);
2056 if (!(W_ERROR_IS_OK(werr))) {
2057 status = werror_to_ntstatus(werr);
2060 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2061 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2068 static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
2069 const struct dom_sid *domain_sid,
2070 const char *domain_name,
2071 struct cli_state *cli,
2072 struct rpc_pipe_client *pipe_hnd,
2073 TALLOC_CTX *mem_ctx,
2077 TALLOC_CTX *frame = talloc_stackframe();
2078 NTSTATUS status = NT_STATUS_OK;
2079 WERROR werr = WERR_OK;
2082 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2085 struct policy_handle hive_hnd, key_hnd, share_hnd;
2087 struct winreg_String key, keyclass;
2088 enum winreg_CreateAction action = 0;
2090 ZERO_STRUCT(hive_hnd);
2091 ZERO_STRUCT(key_hnd);
2092 ZERO_STRUCT(share_hnd);
2095 ZERO_STRUCT(keyclass);
2097 if (argc < 1 || c->display_usage) {
2098 rpc_conf_setincludes_usage(c, argc, argv);
2099 status = NT_STATUS_INVALID_PARAMETER;
2103 status = rpc_conf_open_conf(frame,
2110 if (!(NT_STATUS_IS_OK(status))) {
2114 if (!(W_ERROR_IS_OK(werr))) {
2121 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
2122 0, REG_KEY_READ, NULL, &share_hnd,
2125 if (!(NT_STATUS_IS_OK(status))) {
2126 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2127 argv[0], nt_errstr(status));
2131 if (!W_ERROR_IS_OK(werr)) {
2132 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2133 argv[0], win_errstr(werr));
2138 case REG_ACTION_NONE:
2139 /* Is there any other way to treat this? */
2140 werr = WERR_CREATE_FAILED;
2141 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2142 argv[0], win_errstr(werr));
2144 case REG_CREATED_NEW_KEY:
2145 DEBUG(5, ("net rpc conf setincludes:"
2146 "createkey created %s\n", argv[0]));
2148 case REG_OPENED_EXISTING_KEY:
2149 DEBUG(5, ("net rpc conf setincludes:"
2150 "createkey opened existing %s\n", argv[0]));
2152 /* delete possibly existing value */
2153 status = rpc_conf_del_value(frame,
2160 if (!(NT_STATUS_IS_OK(status))) {
2164 if (!(W_ERROR_IS_OK(werr))) {
2170 /* set the 'includes' values */
2171 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
2172 "includes", argv + 1, &werr);
2173 if (!(NT_STATUS_IS_OK(status))) {
2174 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2179 if (!(W_ERROR_IS_OK(werr))) {
2180 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2187 if (!(W_ERROR_IS_OK(werr))) {
2188 status = werror_to_ntstatus(werr);
2191 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2192 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2193 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
2199 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
2200 const struct dom_sid *domain_sid,
2201 const char *domain_name,
2202 struct cli_state *cli,
2203 struct rpc_pipe_client *pipe_hnd,
2204 TALLOC_CTX *mem_ctx,
2208 TALLOC_CTX *frame = talloc_stackframe();
2209 NTSTATUS status = NT_STATUS_OK;
2210 WERROR werr = WERR_OK;
2213 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2216 struct policy_handle hive_hnd, key_hnd;
2219 ZERO_STRUCT(hive_hnd);
2220 ZERO_STRUCT(key_hnd);
2223 if (argc != 1 || c->display_usage) {
2224 rpc_conf_delincludes_usage(c, argc, argv);
2225 status = NT_STATUS_INVALID_PARAMETER;
2229 status = rpc_conf_open_conf(frame,
2236 if (!(NT_STATUS_IS_OK(status))) {
2240 if (!(W_ERROR_IS_OK(werr))) {
2244 status = rpc_conf_del_value(frame,
2253 if (!(W_ERROR_IS_OK(werr))) {
2254 status = werror_to_ntstatus(werr);
2257 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2258 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2265 /**********************************************************
2267 * Functions that run the rpc commands for net rpc conf modules
2269 **********************************************************/
2271 static int rpc_conf_drop(struct net_context *c, int argc,
2274 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2275 rpc_conf_drop_internal, argc, argv );
2279 static int rpc_conf_showshare(struct net_context *c, int argc,
2282 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2283 rpc_conf_showshare_internal, argc, argv );
2286 static int rpc_conf_addshare(struct net_context *c, int argc,
2289 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2290 rpc_conf_addshare_internal, argc, argv );
2293 static int rpc_conf_listshares(struct net_context *c, int argc,
2296 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2297 rpc_conf_listshares_internal, argc, argv );
2300 static int rpc_conf_list(struct net_context *c, int argc,
2303 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2304 rpc_conf_list_internal, argc, argv );
2307 static int rpc_conf_import(struct net_context *c, int argc,
2310 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2311 rpc_conf_import_internal, argc, argv );
2313 static int rpc_conf_delshare(struct net_context *c, int argc,
2316 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2317 rpc_conf_delshare_internal, argc, argv );
2320 static int rpc_conf_getparm(struct net_context *c, int argc,
2323 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2324 rpc_conf_getparm_internal, argc, argv );
2327 static int rpc_conf_setparm(struct net_context *c, int argc,
2330 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2331 rpc_conf_setparm_internal, argc, argv );
2333 static int rpc_conf_delparm(struct net_context *c, int argc,
2336 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2337 rpc_conf_delparm_internal, argc, argv );
2340 static int rpc_conf_getincludes(struct net_context *c, int argc,
2343 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2344 rpc_conf_getincludes_internal, argc, argv );
2347 static int rpc_conf_setincludes(struct net_context *c, int argc,
2350 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2351 rpc_conf_setincludes_internal, argc, argv );
2354 static int rpc_conf_delincludes(struct net_context *c, int argc,
2357 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2358 rpc_conf_delincludes_internal, argc, argv );
2361 /* function calls */
2362 int net_rpc_conf(struct net_context *c, int argc,
2365 struct functable func_table[] = {
2370 N_("Dump the complete remote configuration in smb.conf like "
2372 N_("net rpc conf list\n"
2373 " Dump the complete remote configuration in smb.conf "
2381 N_("Import configuration from file in smb.conf "
2383 N_("net rpc conf import\n"
2384 " Import configuration from file in smb.conf "
2389 rpc_conf_listshares,
2391 N_("List the remote share names."),
2392 N_("net rpc conf list\n"
2393 " List the remote share names.")
2400 N_("Delete the complete remote configuration."),
2401 N_("net rpc conf drop\n"
2402 " Delete the complete remote configuration.")
2409 N_("Show the definition of a remote share."),
2410 N_("net rpc conf showshare\n"
2411 " Show the definition of a remote share.")
2418 N_("Create a new remote share."),
2419 N_("net rpc conf addshare\n"
2420 " Create a new remote share.")
2426 N_("Delete a remote share."),
2427 N_("net rpc conf delshare\n"
2428 " Delete a remote share.")
2434 N_("Retrieve the value of a parameter."),
2435 N_("net rpc conf getparm\n"
2436 " Retrieve the value of a parameter.")
2442 N_("Store a parameter."),
2443 N_("net rpc conf setparm\n"
2444 " Store a parameter.")
2450 N_("Delete a parameter."),
2451 N_("net rpc conf delparm\n"
2452 " Delete a parameter.")
2456 rpc_conf_getincludes,
2458 N_("Show the includes of a share definition."),
2459 N_("net rpc conf getincludes\n"
2460 " Show the includes of a share definition.")
2464 rpc_conf_setincludes,
2466 N_("Set includes for a share."),
2467 N_("net rpc conf setincludes\n"
2468 " Set includes for a share.")
2472 rpc_conf_delincludes,
2474 N_("Delete includes from a share definition."),
2475 N_("net rpc conf delincludes\n"
2476 " Delete includes from a share definition.")
2478 {NULL, NULL, 0, NULL, NULL}
2481 return net_run_function(c, argc, argv, "net rpc conf", func_table);