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_BADFILE)){
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) {
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) {
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, i, param_cnt = 0;
422 const char **val_names;
423 enum winreg_Type *types;
425 struct winreg_String key = { 0, };
426 const char **multi_s = NULL;
427 const char *s = NULL;
428 struct smbconf_service tmp_share;
430 ZERO_STRUCT(tmp_share);
432 key.name = share_name;
433 status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
434 REG_KEY_READ, &child_hnd, &result);
436 if (!(NT_STATUS_IS_OK(status))) {
437 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
441 if (!(W_ERROR_IS_OK(result))) {
442 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
446 /* get all the info from the share key */
447 status = dcerpc_winreg_enumvals(frame,
456 if (!(NT_STATUS_IS_OK(status))) {
457 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
461 if (!(W_ERROR_IS_OK(result))) {
462 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
466 /* check for includes */
467 for (i = 0; i < num_vals; i++) {
468 if (strcmp(val_names[i], "includes") == 0){
469 if (!pull_reg_multi_sz(frame,
475 _("Failed to enumerate values: %s\n"),
482 /* count the number of includes */
484 if (includes_idx != -1) {
485 for (includes_cnt = 0;
486 multi_s[includes_cnt] != NULL;
489 /* place the name of the share in the smbconf_service struct */
490 tmp_share.name = talloc_strdup(frame, share_name);
491 if (tmp_share.name == NULL) {
493 d_fprintf(stderr, _("Failed to create share: %s\n"),
497 /* place the number of parameters in the smbconf_service struct */
498 tmp_share.num_params = num_vals;
499 if (includes_idx != -1) {
500 tmp_share.num_params = num_vals + includes_cnt - 1;
502 /* allocate memory for the param_names and param_values lists */
503 tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
504 if (tmp_share.param_names == NULL) {
506 d_fprintf(stderr, _("Failed to create share: %s\n"),
510 tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
511 if (tmp_share.param_values == NULL) {
513 d_fprintf(stderr, _("Failed to create share: %s\n"),
517 /* place all params except includes */
518 for (i = 0; i < num_vals; i++) {
519 if (strcmp(val_names[i], "includes") != 0) {
520 if (!pull_reg_sz(frame, &data[i], &s)) {
523 _("Failed to enumerate values: %s\n"),
527 /* place param_names */
528 tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
529 if (tmp_share.param_names[param_cnt] == NULL) {
531 d_fprintf(stderr, _("Failed to create share: %s\n"),
536 /* place param_values */
537 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
538 if (tmp_share.param_values[param_cnt - 1] == NULL) {
540 d_fprintf(stderr, _("Failed to create share: %s\n"),
546 /* place the includes last */
547 for (i = 0; i < includes_cnt; i++) {
548 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
549 if (tmp_share.param_names[param_cnt] == NULL) {
551 d_fprintf(stderr, _("Failed to create share: %s\n"),
556 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
557 if (tmp_share.param_values[param_cnt - 1] == NULL) {
559 d_fprintf(stderr, _("Failed to create share: %s\n"),
565 /* move everything to the main memory ctx */
566 for (i = 0; i < param_cnt; i++) {
567 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
568 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
571 tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
572 tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
573 tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
578 dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
585 * The function prints the shares held as smbconf_service structs
586 * in a smbconf file format.
588 static int rpc_conf_print_shares(uint32_t num_shares,
589 struct smbconf_service *shares)
592 uint32_t share_count, param_count;
593 const char *indent = "\t";
595 if (num_shares == 0) {
599 for (share_count = 0; share_count < num_shares; share_count++) {
601 if (shares[share_count].name != NULL) {
602 d_printf("[%s]\n", shares[share_count].name);
605 for (param_count = 0;
606 param_count < shares[share_count].num_params;
609 d_printf("%s%s = %s\n",
611 shares[share_count].param_names[param_count],
612 shares[share_count].param_values[param_count]);
622 * The function openes the registry key
623 * HKLM/Software/Samba/smbconf with the give access_mask
625 static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
626 struct dcerpc_binding_handle *b,
627 uint32_t access_mask,
628 struct policy_handle *hive_hnd,
629 struct policy_handle *key_hnd,
632 TALLOC_CTX *frame = talloc_stackframe();
633 NTSTATUS status = NT_STATUS_OK;
634 WERROR result = WERR_OK;
636 struct policy_handle tmp_hive_hnd, tmp_key_hnd;
637 struct winreg_String key;
641 status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
642 access_mask, &tmp_hive_hnd, &result);
645 * print no error messages if it is a read only open
646 * and key does not exist
647 * error still gets returned
650 if (access_mask == REG_KEY_READ &&
651 W_ERROR_EQUAL(result, WERR_BADFILE))
656 if (!(NT_STATUS_IS_OK(status))) {
657 d_fprintf(stderr, _("Failed to open hive: %s\n"),
661 if (!W_ERROR_IS_OK(result)) {
662 d_fprintf(stderr, _("Failed to open hive: %s\n"),
668 status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
669 access_mask, &tmp_key_hnd, &result);
672 * print no error messages if it is a read only open
673 * and key does not exist
674 * error still gets returned
677 if (access_mask == REG_KEY_READ &&
678 W_ERROR_EQUAL(result, WERR_BADFILE))
683 if (!(NT_STATUS_IS_OK(status))) {
684 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
686 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
689 if (!(W_ERROR_IS_OK(result))) {
690 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
692 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
696 *hive_hnd = tmp_hive_hnd;
697 *key_hnd = tmp_key_hnd;
706 /**********************************************************
708 * internal functions that provide the functionality
711 **********************************************************/
713 static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
714 const struct dom_sid *domain_sid,
715 const char *domain_name,
716 struct cli_state *cli,
717 struct rpc_pipe_client *pipe_hnd,
723 TALLOC_CTX *frame = talloc_stackframe();
724 NTSTATUS status = NT_STATUS_OK;
725 WERROR werr = WERR_OK;
728 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
731 struct policy_handle hive_hnd, key_hnd;
732 uint32_t num_subkeys;
734 const char **subkeys = NULL;
737 ZERO_STRUCT(hive_hnd);
738 ZERO_STRUCT(key_hnd);
741 if (argc != 0 || c->display_usage) {
742 rpc_conf_listshares_usage(c, argc, argv);
743 status = NT_STATUS_INVALID_PARAMETER;
748 status = rpc_conf_open_conf(frame,
755 if (!(NT_STATUS_IS_OK(status))) {
759 if (!(W_ERROR_IS_OK(werr))) {
763 status = dcerpc_winreg_enum_keys(frame,
770 if (!(NT_STATUS_IS_OK(status))) {
771 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
776 if (!(W_ERROR_IS_OK(werr))) {
777 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
782 for (i = 0; i < num_subkeys; i++) {
783 d_printf("%s\n", subkeys[i]);
787 if (!(W_ERROR_IS_OK(werr))) {
788 status = werror_to_ntstatus(werr);
791 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
792 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
798 static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
799 const struct dom_sid *domain_sid,
800 const char *domain_name,
801 struct cli_state *cli,
802 struct rpc_pipe_client *pipe_hnd,
808 TALLOC_CTX *frame = talloc_stackframe();
809 NTSTATUS status = NT_STATUS_OK;
810 WERROR werr = WERR_OK;
813 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
816 struct policy_handle hive_hnd, key_hnd;
818 ZERO_STRUCT(hive_hnd);
819 ZERO_STRUCT(key_hnd);
822 if (argc != 1 || c->display_usage) {
823 rpc_conf_delshare_usage(c, argc, argv);
824 status = NT_STATUS_INVALID_PARAMETER;
828 status = rpc_conf_open_conf(frame,
835 if (!(NT_STATUS_IS_OK(status))) {
839 if (!(W_ERROR_IS_OK(werr))) {
843 status = dcerpc_winreg_delete_subkeys_recursive(frame,
850 if (!NT_STATUS_IS_OK(status)) {
852 "winreg_delete_subkeys: Could not delete key %s: %s\n",
853 argv[0], nt_errstr(status));
857 if (W_ERROR_EQUAL(werr, WERR_BADFILE)){
858 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
862 if (!W_ERROR_IS_OK(werr)) {
864 "winreg_delete_subkeys: Could not delete key %s: %s\n",
865 argv[0], win_errstr(werr));
870 if (!(W_ERROR_IS_OK(werr))) {
871 status = werror_to_ntstatus(werr);
874 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
875 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
882 static NTSTATUS rpc_conf_list_internal(struct net_context *c,
883 const struct dom_sid *domain_sid,
884 const char *domain_name,
885 struct cli_state *cli,
886 struct rpc_pipe_client *pipe_hnd,
892 TALLOC_CTX *frame = talloc_stackframe();
893 NTSTATUS status = NT_STATUS_OK;
894 WERROR werr = WERR_OK;
897 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
900 struct policy_handle hive_hnd, key_hnd;
901 uint32_t num_subkeys;
903 struct smbconf_service *shares;
904 const char **subkeys = NULL;
907 ZERO_STRUCT(hive_hnd);
908 ZERO_STRUCT(key_hnd);
911 if (argc != 0 || c->display_usage) {
912 rpc_conf_list_usage(c, argc, argv);
913 status = NT_STATUS_INVALID_PARAMETER;
917 status = rpc_conf_open_conf(frame,
924 if (!(NT_STATUS_IS_OK(status))) {
928 if (!(W_ERROR_IS_OK(werr))) {
932 status = dcerpc_winreg_enum_keys(frame,
939 if (!(NT_STATUS_IS_OK(status))) {
940 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
945 if (!(W_ERROR_IS_OK(werr))) {
946 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
951 if (num_subkeys == 0) {
952 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
953 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
958 /* get info from each subkey */
959 shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
960 if (shares == NULL) {
962 d_fprintf(stderr, _("Failed to create shares: %s\n"),
968 for (i = 0; i < num_subkeys; i++) {
969 /* get each share and place it in the shares array */
970 status = rpc_conf_get_share(frame,
976 if (!(NT_STATUS_IS_OK(status))) {
979 if (!(W_ERROR_IS_OK(werr))) {
984 /* print the shares array */
985 rpc_conf_print_shares(num_subkeys, shares);
988 if (!(W_ERROR_IS_OK(werr))) {
989 status = werror_to_ntstatus(werr);
992 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
993 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1000 static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
1001 const struct dom_sid *domain_sid,
1002 const char *domain_name,
1003 struct cli_state *cli,
1004 struct rpc_pipe_client *pipe_hnd,
1005 TALLOC_CTX *mem_ctx,
1009 TALLOC_CTX *frame = talloc_stackframe();
1010 NTSTATUS status = NT_STATUS_OK;
1011 WERROR werr = WERR_OK;
1014 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1017 struct policy_handle hive_hnd, key_hnd;
1018 const char *keyname = confpath;
1019 struct winreg_String wkey, wkeyclass;
1020 enum winreg_CreateAction action = REG_ACTION_NONE;
1023 ZERO_STRUCT(hive_hnd);
1024 ZERO_STRUCT(key_hnd);
1027 if (argc != 0 || c->display_usage) {
1028 rpc_conf_drop_usage(c, argc, argv);
1029 status = NT_STATUS_INVALID_PARAMETER;
1033 status = rpc_conf_open_conf(frame,
1040 if (!(NT_STATUS_IS_OK(status))) {
1044 if (!(W_ERROR_IS_OK(werr))) {
1048 status = dcerpc_winreg_delete_subkeys_recursive(frame,
1055 if (!NT_STATUS_IS_OK(status)) {
1056 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1057 keyname, nt_errstr(status));
1061 if (!W_ERROR_IS_OK(werr)) {
1062 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1063 keyname, win_errstr(werr));
1068 wkey.name = keyname;
1069 ZERO_STRUCT(wkeyclass);
1070 wkeyclass.name = "";
1071 action = REG_ACTION_NONE;
1073 status = dcerpc_winreg_CreateKey(b,
1085 if (!NT_STATUS_IS_OK(status)) {
1086 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1090 if (!W_ERROR_IS_OK(werr)) {
1091 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1097 if (!(W_ERROR_IS_OK(werr))) {
1098 status = werror_to_ntstatus(werr);
1101 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1102 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1108 static NTSTATUS rpc_conf_import_internal(struct net_context *c,
1109 const struct dom_sid *domain_sid,
1110 const char *domain_name,
1111 struct cli_state *cli,
1112 struct rpc_pipe_client *pipe_hnd,
1113 TALLOC_CTX *mem_ctx,
1118 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1120 struct policy_handle hive_hnd, key_hnd;
1122 const char *filename = NULL;
1123 const char *servicename = NULL;
1124 char *conf_source = NULL;
1126 struct smbconf_ctx *txt_ctx;
1127 struct smbconf_service *service = NULL;
1128 struct smbconf_service **services = NULL;
1129 uint32_t num_shares, i;
1130 sbcErr err = SBC_ERR_UNKNOWN_FAILURE;
1132 WERROR werr = WERR_OK;
1133 NTSTATUS status = NT_STATUS_OK;
1135 ZERO_STRUCT(hive_hnd);
1136 ZERO_STRUCT(key_hnd);
1138 frame = talloc_stackframe();
1140 if (c->display_usage) {
1141 rpc_conf_import_usage(c, argc, argv);
1142 status = NT_STATUS_INVALID_PARAMETER;
1149 rpc_conf_import_usage(c, argc, argv);
1150 status = NT_STATUS_INVALID_PARAMETER;
1153 servicename = talloc_strdup(frame, argv[1]);
1154 if (servicename == NULL) {
1155 d_printf(_("error: out of memory!\n"));
1163 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1166 conf_source = talloc_asprintf(frame, "file:%s", filename);
1167 if (conf_source == NULL) {
1168 d_fprintf(stderr, _("error: out of memory!\n"));
1172 err = smbconf_init(frame, &txt_ctx, conf_source);
1173 if (!SBC_ERROR_IS_OK(err)) {
1174 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
1175 sbcErrorString(err));
1179 if (c->opt_testmode) {
1180 d_printf(_("\nTEST MODE - "
1181 "would import the following configuration:\n\n"));
1184 if (servicename != NULL) {
1185 err = smbconf_get_share(txt_ctx, frame,
1188 if (!SBC_ERROR_IS_OK(err)) {
1196 err = smbconf_get_config(txt_ctx, frame,
1199 if (!SBC_ERROR_IS_OK(err)) {
1204 if (c->opt_testmode) {
1205 if (servicename != NULL) {
1206 rpc_conf_print_shares(1, service);
1208 for (i = 0; i < num_shares; i++) {
1209 rpc_conf_print_shares(1, services[i]);
1214 status = rpc_conf_drop_internal(c,
1223 if (!(NT_STATUS_IS_OK(status))) {
1227 status = rpc_conf_open_conf(frame,
1234 if (!(NT_STATUS_IS_OK(status))) {
1238 if (!(W_ERROR_IS_OK(werr))) {
1242 if (servicename != NULL) {
1243 status = rpc_conf_set_share(frame,
1249 if (!(NT_STATUS_IS_OK(status))) {
1253 if (!(W_ERROR_IS_OK(werr))) {
1259 for (i = 0; i < num_shares; i++) {
1260 status = rpc_conf_set_share(frame,
1266 if (!(NT_STATUS_IS_OK(status))) {
1270 if (!(W_ERROR_IS_OK(werr))) {
1278 if (!SBC_ERROR_IS_OK(err)) {
1279 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
1282 if (!(W_ERROR_IS_OK(werr))) {
1283 status = werror_to_ntstatus(werr);
1289 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
1290 const struct dom_sid *domain_sid,
1291 const char *domain_name,
1292 struct cli_state *cli,
1293 struct rpc_pipe_client *pipe_hnd,
1294 TALLOC_CTX *mem_ctx,
1298 TALLOC_CTX *frame = talloc_stackframe();
1299 NTSTATUS status = NT_STATUS_OK;
1300 WERROR werr = WERR_OK;
1303 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1306 struct policy_handle hive_hnd, key_hnd;
1307 struct smbconf_service *service = NULL;
1308 const char *sharename = NULL;
1311 ZERO_STRUCT(hive_hnd);
1312 ZERO_STRUCT(key_hnd);
1315 if (argc != 1 || c->display_usage) {
1316 rpc_conf_showshare_usage(c, argc, argv);
1317 status = NT_STATUS_INVALID_PARAMETER;
1321 status = rpc_conf_open_conf(frame,
1328 if (!(NT_STATUS_IS_OK(status))) {
1332 if (!(W_ERROR_IS_OK(werr))) {
1336 sharename = talloc_strdup(frame, argv[0]);
1337 if (sharename == NULL) {
1339 d_fprintf(stderr, _("Failed to create share: %s\n"),
1344 service = talloc(frame, struct smbconf_service);
1345 if (service == NULL) {
1347 d_fprintf(stderr, _("Failed to create share: %s\n"),
1352 status = rpc_conf_get_share(frame,
1359 if (!(NT_STATUS_IS_OK(status))) {
1362 if (!(W_ERROR_IS_OK(werr))) {
1366 rpc_conf_print_shares(1, service);
1369 if (!(W_ERROR_IS_OK(werr))) {
1370 status = werror_to_ntstatus(werr);
1373 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1374 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1380 static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
1381 const struct dom_sid *domain_sid,
1382 const char *domain_name,
1383 struct cli_state *cli,
1384 struct rpc_pipe_client *pipe_hnd,
1385 TALLOC_CTX *mem_ctx,
1389 TALLOC_CTX *frame = talloc_stackframe();
1390 NTSTATUS status = NT_STATUS_OK;
1391 WERROR werr = WERR_OK;
1394 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1397 struct policy_handle hive_hnd, key_hnd, share_hnd;
1398 char *sharename = NULL;
1399 const char *path = NULL;
1400 const char *comment = NULL;
1401 const char *guest_ok = "no";
1402 const char *read_only = "yes";
1403 struct winreg_String key, keyclass;
1404 enum winreg_CreateAction action = 0;
1407 ZERO_STRUCT(hive_hnd);
1408 ZERO_STRUCT(key_hnd);
1409 ZERO_STRUCT(share_hnd);
1412 ZERO_STRUCT(keyclass);
1414 if (c->display_usage) {
1415 rpc_conf_addshare_usage(c, argc, argv);
1416 status = NT_STATUS_INVALID_PARAMETER;
1424 rpc_conf_addshare_usage(c, argc, argv);
1425 status = NT_STATUS_INVALID_PARAMETER;
1430 if (!strnequal(argv[3], "guest_ok=", 9)) {
1431 rpc_conf_addshare_usage(c, argc, argv);
1432 status = NT_STATUS_INVALID_PARAMETER;
1435 switch (argv[3][9]) {
1445 rpc_conf_addshare_usage(c, argc, argv);
1446 status = NT_STATUS_INVALID_PARAMETER;
1450 if (!strnequal(argv[2], "writeable=", 10)) {
1451 rpc_conf_addshare_usage(c, argc, argv);
1452 status = NT_STATUS_INVALID_PARAMETER;
1455 switch (argv[2][10]) {
1465 rpc_conf_addshare_usage(c, argc, argv);
1466 status = NT_STATUS_INVALID_PARAMETER;
1471 sharename = talloc_strdup(frame, argv[0]);
1472 if (sharename == NULL) {
1473 d_printf(_("error: out of memory!\n"));
1480 status = rpc_conf_open_conf(frame,
1487 if (!(NT_STATUS_IS_OK(status))) {
1491 if (!(W_ERROR_IS_OK(werr))) {
1498 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1499 0, REG_KEY_READ, NULL, &share_hnd,
1502 if (!(NT_STATUS_IS_OK(status))) {
1503 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1504 argv[0], nt_errstr(status));
1508 if (!W_ERROR_IS_OK(werr)) {
1509 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1510 argv[0], win_errstr(werr));
1515 case REG_ACTION_NONE:
1516 werr = WERR_CREATE_FAILED;
1517 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1518 argv[0], win_errstr(werr));
1520 case REG_CREATED_NEW_KEY:
1521 DEBUG(5, ("net rpc conf setincludes:"
1522 "createkey created %s\n", argv[0]));
1524 case REG_OPENED_EXISTING_KEY:
1525 d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
1526 status = NT_STATUS_INVALID_PARAMETER;
1530 /* set the path parameter */
1531 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1532 "path", path, &werr);
1534 if (!(NT_STATUS_IS_OK(status))) {
1535 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1536 " with value %s\n %s\n",
1537 "path", path, nt_errstr(status));
1541 if (!(W_ERROR_IS_OK(werr))) {
1542 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1543 " with value %s\n %s\n",
1544 "path", path, win_errstr(werr));
1548 /* set the writeable parameter */
1549 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1550 "read only", read_only, &werr);
1552 if (!(NT_STATUS_IS_OK(status))) {
1553 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1554 " with value %s\n %s\n",
1555 "read only", read_only, nt_errstr(status));
1559 if (!(W_ERROR_IS_OK(werr))) {
1560 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1561 " with value %s\n %s\n",
1562 "read only", read_only, win_errstr(werr));
1566 /* set the guest ok parameter */
1567 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1568 "guest ok", guest_ok, &werr);
1570 if (!(NT_STATUS_IS_OK(status))) {
1571 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1572 " with value %s\n %s\n",
1573 "guest ok", guest_ok, nt_errstr(status));
1577 if (!(W_ERROR_IS_OK(werr))) {
1578 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1579 " with value %s\n %s\n",
1580 "guest ok", guest_ok, win_errstr(werr));
1585 /* set the comment parameter */
1586 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1587 "comment", comment, &werr);
1589 if (!(NT_STATUS_IS_OK(status))) {
1590 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1591 " with value %s\n %s\n",
1592 "comment", comment, nt_errstr(status));
1596 if (!(W_ERROR_IS_OK(werr))) {
1597 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1598 " with value %s\n %s\n",
1599 "comment", comment, win_errstr(werr));
1604 if (!(W_ERROR_IS_OK(werr))) {
1605 status = werror_to_ntstatus(werr);
1608 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1609 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1610 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1616 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
1617 const struct dom_sid *domain_sid,
1618 const char *domain_name,
1619 struct cli_state *cli,
1620 struct rpc_pipe_client *pipe_hnd,
1621 TALLOC_CTX *mem_ctx,
1625 TALLOC_CTX *frame = talloc_stackframe();
1626 NTSTATUS status = NT_STATUS_OK;
1627 WERROR werr = WERR_OK;
1630 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1633 struct policy_handle hive_hnd, key_hnd;
1634 struct smbconf_service *service = NULL;
1636 bool param_is_set = false;
1637 uint32_t param_count;
1639 ZERO_STRUCT(hive_hnd);
1640 ZERO_STRUCT(key_hnd);
1643 if (argc != 2 || c->display_usage) {
1644 rpc_conf_getparm_usage(c, argc, argv);
1645 status = NT_STATUS_INVALID_PARAMETER;
1649 status = rpc_conf_open_conf(frame,
1656 if (!(NT_STATUS_IS_OK(status))) {
1660 if (!(W_ERROR_IS_OK(werr))) {
1665 service = talloc(frame, struct smbconf_service);
1667 status = rpc_conf_get_share(frame,
1674 if (!(NT_STATUS_IS_OK(status))) {
1678 if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1679 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1684 if (!(W_ERROR_IS_OK(werr))) {
1688 for (param_count = 0;
1689 param_count < service->num_params;
1692 /* should includes also be printed? */
1693 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1695 service->param_values[param_count]);
1696 param_is_set = true;
1700 if (!param_is_set) {
1701 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1703 werr = WERR_BADFILE;
1709 if (!(W_ERROR_IS_OK(werr))) {
1710 status = werror_to_ntstatus(werr);
1713 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1714 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1721 static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
1722 const struct dom_sid *domain_sid,
1723 const char *domain_name,
1724 struct cli_state *cli,
1725 struct rpc_pipe_client *pipe_hnd,
1726 TALLOC_CTX *mem_ctx,
1730 TALLOC_CTX *frame = talloc_stackframe();
1731 NTSTATUS status = NT_STATUS_OK;
1732 WERROR werr = WERR_OK;
1735 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1738 struct policy_handle hive_hnd, key_hnd, share_hnd;
1740 struct winreg_String key, keyclass;
1741 enum winreg_CreateAction action = 0;
1743 const char *service_name, *param_name, *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))) {
1773 service_name = argv[0];
1774 param_name = argv[1];
1777 key.name = service_name;
1780 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1781 0, REG_KEY_READ, NULL, &share_hnd,
1784 if (!(NT_STATUS_IS_OK(status))) {
1785 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1786 service_name, nt_errstr(status));
1790 if (!W_ERROR_IS_OK(werr)) {
1791 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1792 service_name, win_errstr(werr));
1797 case REG_ACTION_NONE:
1798 werr = WERR_CREATE_FAILED;
1799 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1800 service_name, win_errstr(werr));
1802 case REG_CREATED_NEW_KEY:
1803 DEBUG(5, ("net rpc conf setparm:"
1804 "createkey created %s\n", service_name));
1806 case REG_OPENED_EXISTING_KEY:
1807 DEBUG(5, ("net rpc conf setparm:"
1808 "createkey opened existing %s\n",
1811 /* delete posibly existing value */
1812 status = rpc_conf_del_value(frame,
1819 if (!(NT_STATUS_IS_OK(status))) {
1823 if (!(W_ERROR_IS_OK(werr))) {
1831 * check if parameter is valid for writing
1834 if (!net_conf_param_valid(service_name, param_name, valstr)) {
1835 werr = WERR_INVALID_PARAM;
1839 /* set the parameter */
1840 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1841 param_name, valstr, &werr);
1843 if (!(NT_STATUS_IS_OK(status))) {
1844 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1845 " with value %s\n %s\n",
1846 param_name, valstr, nt_errstr(status));
1850 if (!(W_ERROR_IS_OK(werr))) {
1851 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1852 " with value %s\n %s\n",
1853 param_name, valstr, win_errstr(werr));
1859 if (!(W_ERROR_IS_OK(werr))) {
1860 status = werror_to_ntstatus(werr);
1863 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1864 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1865 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1871 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1872 const struct dom_sid *domain_sid,
1873 const char *domain_name,
1874 struct cli_state *cli,
1875 struct rpc_pipe_client *pipe_hnd,
1876 TALLOC_CTX *mem_ctx,
1880 TALLOC_CTX *frame = talloc_stackframe();
1881 NTSTATUS status = NT_STATUS_OK;
1882 WERROR werr = WERR_OK;
1885 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1888 struct policy_handle hive_hnd, key_hnd;
1891 ZERO_STRUCT(hive_hnd);
1892 ZERO_STRUCT(key_hnd);
1895 if (argc != 2 || c->display_usage) {
1896 rpc_conf_delparm_usage(c, argc, argv);
1897 status = NT_STATUS_INVALID_PARAMETER;
1901 status = rpc_conf_open_conf(frame,
1908 if (!(NT_STATUS_IS_OK(status))) {
1912 if (!(W_ERROR_IS_OK(werr))) {
1916 status = rpc_conf_del_value(frame,
1925 if (!(W_ERROR_IS_OK(werr))) {
1926 status = werror_to_ntstatus(werr);
1929 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1930 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1937 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1938 const struct dom_sid *domain_sid,
1939 const char *domain_name,
1940 struct cli_state *cli,
1941 struct rpc_pipe_client *pipe_hnd,
1942 TALLOC_CTX *mem_ctx,
1946 TALLOC_CTX *frame = talloc_stackframe();
1947 NTSTATUS status = NT_STATUS_OK;
1948 WERROR werr = WERR_OK;
1951 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1954 struct policy_handle hive_hnd, key_hnd;
1955 struct smbconf_service *service = NULL;
1957 uint32_t param_count;
1960 ZERO_STRUCT(hive_hnd);
1961 ZERO_STRUCT(key_hnd);
1964 if (argc != 1 || c->display_usage) {
1965 rpc_conf_getincludes_usage(c, argc, argv);
1966 status = NT_STATUS_INVALID_PARAMETER;
1970 status = rpc_conf_open_conf(frame,
1977 if (!(NT_STATUS_IS_OK(status))) {
1981 if (!(W_ERROR_IS_OK(werr))) {
1985 service = talloc(frame, struct smbconf_service);
1987 status = rpc_conf_get_share(frame,
1994 if (!(NT_STATUS_IS_OK(status))) {
1998 if (!(W_ERROR_IS_OK(werr))) {
2002 for (param_count = 0;
2003 param_count < service->num_params;
2006 if (strcmp(service->param_names[param_count], "include") == 0) {
2007 d_printf(_("%s = %s\n"),
2008 service->param_names[param_count],
2009 service->param_values[param_count]);
2015 if (!(W_ERROR_IS_OK(werr))) {
2016 status = werror_to_ntstatus(werr);
2019 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2020 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2027 static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
2028 const struct dom_sid *domain_sid,
2029 const char *domain_name,
2030 struct cli_state *cli,
2031 struct rpc_pipe_client *pipe_hnd,
2032 TALLOC_CTX *mem_ctx,
2036 TALLOC_CTX *frame = talloc_stackframe();
2037 NTSTATUS status = NT_STATUS_OK;
2038 WERROR werr = WERR_OK;
2041 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2044 struct policy_handle hive_hnd, key_hnd, share_hnd;
2046 struct winreg_String key, keyclass;
2047 enum winreg_CreateAction action = 0;
2049 ZERO_STRUCT(hive_hnd);
2050 ZERO_STRUCT(key_hnd);
2051 ZERO_STRUCT(share_hnd);
2054 ZERO_STRUCT(keyclass);
2056 if (argc < 1 || c->display_usage) {
2057 rpc_conf_setincludes_usage(c, argc, argv);
2058 status = NT_STATUS_INVALID_PARAMETER;
2062 status = rpc_conf_open_conf(frame,
2069 if (!(NT_STATUS_IS_OK(status))) {
2073 if (!(W_ERROR_IS_OK(werr))) {
2080 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
2081 0, REG_KEY_READ, NULL, &share_hnd,
2084 if (!(NT_STATUS_IS_OK(status))) {
2085 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2086 argv[0], nt_errstr(status));
2090 if (!W_ERROR_IS_OK(werr)) {
2091 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2092 argv[0], win_errstr(werr));
2097 case REG_ACTION_NONE:
2098 /* Is there any other way to treat this? */
2099 werr = WERR_CREATE_FAILED;
2100 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2101 argv[0], win_errstr(werr));
2103 case REG_CREATED_NEW_KEY:
2104 DEBUG(5, ("net rpc conf setincludes:"
2105 "createkey created %s\n", argv[0]));
2107 case REG_OPENED_EXISTING_KEY:
2108 DEBUG(5, ("net rpc conf setincludes:"
2109 "createkey opened existing %s\n", argv[0]));
2111 /* delete posibly existing value */
2112 status = rpc_conf_del_value(frame,
2119 if (!(NT_STATUS_IS_OK(status))) {
2123 if (!(W_ERROR_IS_OK(werr))) {
2129 /* set the 'includes' values */
2130 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
2131 "includes", argv + 1, &werr);
2132 if (!(NT_STATUS_IS_OK(status))) {
2133 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2138 if (!(W_ERROR_IS_OK(werr))) {
2139 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2146 if (!(W_ERROR_IS_OK(werr))) {
2147 status = werror_to_ntstatus(werr);
2150 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2151 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2152 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
2158 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
2159 const struct dom_sid *domain_sid,
2160 const char *domain_name,
2161 struct cli_state *cli,
2162 struct rpc_pipe_client *pipe_hnd,
2163 TALLOC_CTX *mem_ctx,
2167 TALLOC_CTX *frame = talloc_stackframe();
2168 NTSTATUS status = NT_STATUS_OK;
2169 WERROR werr = WERR_OK;
2172 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2175 struct policy_handle hive_hnd, key_hnd;
2178 ZERO_STRUCT(hive_hnd);
2179 ZERO_STRUCT(key_hnd);
2182 if (argc != 1 || c->display_usage) {
2183 rpc_conf_delincludes_usage(c, argc, argv);
2184 status = NT_STATUS_INVALID_PARAMETER;
2188 status = rpc_conf_open_conf(frame,
2195 if (!(NT_STATUS_IS_OK(status))) {
2199 if (!(W_ERROR_IS_OK(werr))) {
2203 status = rpc_conf_del_value(frame,
2212 if (!(W_ERROR_IS_OK(werr))) {
2213 status = werror_to_ntstatus(werr);
2216 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2217 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2224 /**********************************************************
2226 * Functions that run the rpc commands for net rpc conf modules
2228 **********************************************************/
2230 static int rpc_conf_drop(struct net_context *c, int argc,
2233 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2234 rpc_conf_drop_internal, argc, argv );
2238 static int rpc_conf_showshare(struct net_context *c, int argc,
2241 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2242 rpc_conf_showshare_internal, argc, argv );
2245 static int rpc_conf_addshare(struct net_context *c, int argc,
2248 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2249 rpc_conf_addshare_internal, argc, argv );
2252 static int rpc_conf_listshares(struct net_context *c, int argc,
2255 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2256 rpc_conf_listshares_internal, argc, argv );
2259 static int rpc_conf_list(struct net_context *c, int argc,
2262 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2263 rpc_conf_list_internal, argc, argv );
2266 static int rpc_conf_import(struct net_context *c, int argc,
2269 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2270 rpc_conf_import_internal, argc, argv );
2272 static int rpc_conf_delshare(struct net_context *c, int argc,
2275 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2276 rpc_conf_delshare_internal, argc, argv );
2279 static int rpc_conf_getparm(struct net_context *c, int argc,
2282 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2283 rpc_conf_getparm_internal, argc, argv );
2286 static int rpc_conf_setparm(struct net_context *c, int argc,
2289 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2290 rpc_conf_setparm_internal, argc, argv );
2292 static int rpc_conf_delparm(struct net_context *c, int argc,
2295 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2296 rpc_conf_delparm_internal, argc, argv );
2299 static int rpc_conf_getincludes(struct net_context *c, int argc,
2302 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2303 rpc_conf_getincludes_internal, argc, argv );
2306 static int rpc_conf_setincludes(struct net_context *c, int argc,
2309 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2310 rpc_conf_setincludes_internal, argc, argv );
2313 static int rpc_conf_delincludes(struct net_context *c, int argc,
2316 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2317 rpc_conf_delincludes_internal, argc, argv );
2320 /* function calls */
2321 int net_rpc_conf(struct net_context *c, int argc,
2324 struct functable func_table[] = {
2329 N_("Dump the complete remote configuration in smb.conf like "
2331 N_("net rpc conf list\n"
2332 " Dump the complete remote configuration in smb.conf "
2340 N_("Import configuration from file in smb.conf "
2342 N_("net rpc conf import\n"
2343 " Import configuration from file in smb.conf "
2348 rpc_conf_listshares,
2350 N_("List the remote share names."),
2351 N_("net rpc conf list\n"
2352 " List the remote share names.")
2359 N_("Delete the complete remote configuration."),
2360 N_("net rpc conf drop\n"
2361 " Delete the complete remote configuration.")
2368 N_("Show the definition of a remote share."),
2369 N_("net rpc conf showshare\n"
2370 " Show the definition of a remote share.")
2377 N_("Create a new remote share."),
2378 N_("net rpc conf addshare\n"
2379 " Create a new remote share.")
2385 N_("Delete a remote share."),
2386 N_("net rpc conf delshare\n"
2387 " Delete a remote share.")
2393 N_("Retrieve the value of a parameter."),
2394 N_("net rpc conf getparm\n"
2395 " Retrieve the value of a parameter.")
2401 N_("Store a parameter."),
2402 N_("net rpc conf setparm\n"
2403 " Store a parameter.")
2409 N_("Delete a parameter."),
2410 N_("net rpc conf delparm\n"
2411 " Delete a parameter.")
2415 rpc_conf_getincludes,
2417 N_("Show the includes of a share definition."),
2418 N_("net rpc conf getincludes\n"
2419 " Show the includes of a share definition.")
2423 rpc_conf_setincludes,
2425 N_("Set includes for a share."),
2426 N_("net rpc conf setincludes\n"
2427 " Set includes for a share.")
2431 rpc_conf_delincludes,
2433 N_("Delete includes from a share definition."),
2434 N_("net rpc conf delincludes\n"
2435 " Delete includes from a share definition.")
2437 {NULL, NULL, 0, NULL, NULL}
2440 return net_run_function(c, argc, argv, "net rpc conf", func_table);