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, 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,
473 result = WERR_NOT_ENOUGH_MEMORY;
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) {
492 result = WERR_NOT_ENOUGH_MEMORY;
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) {
505 result = WERR_NOT_ENOUGH_MEMORY;
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) {
512 result = WERR_NOT_ENOUGH_MEMORY;
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)) {
521 result = WERR_NOT_ENOUGH_MEMORY;
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) {
530 result = WERR_NOT_ENOUGH_MEMORY;
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) {
539 result = WERR_NOT_ENOUGH_MEMORY;
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) {
550 result = WERR_NOT_ENOUGH_MEMORY;
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) {
558 result = WERR_NOT_ENOUGH_MEMORY;
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_FILE_NOT_FOUND))
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_FILE_NOT_FOUND))
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_FILE_NOT_FOUND)){
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) {
961 werr = WERR_NOT_ENOUGH_MEMORY;
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"));
1165 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1168 conf_source = talloc_asprintf(frame, "file:%s", filename);
1169 if (conf_source == NULL) {
1170 d_fprintf(stderr, _("error: out of memory!\n"));
1174 err = smbconf_init(frame, &txt_ctx, conf_source);
1175 if (!SBC_ERROR_IS_OK(err)) {
1176 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
1177 sbcErrorString(err));
1181 if (c->opt_testmode) {
1182 d_printf(_("\nTEST MODE - "
1183 "would import the following configuration:\n\n"));
1186 if (servicename != NULL) {
1187 err = smbconf_get_share(txt_ctx, frame,
1190 if (!SBC_ERROR_IS_OK(err)) {
1198 err = smbconf_get_config(txt_ctx, frame,
1201 if (!SBC_ERROR_IS_OK(err)) {
1206 if (c->opt_testmode) {
1207 if (servicename != NULL) {
1208 rpc_conf_print_shares(1, service);
1210 for (i = 0; i < num_shares; i++) {
1211 rpc_conf_print_shares(1, services[i]);
1216 status = rpc_conf_drop_internal(c,
1225 if (!(NT_STATUS_IS_OK(status))) {
1229 status = rpc_conf_open_conf(frame,
1236 if (!(NT_STATUS_IS_OK(status))) {
1240 if (!(W_ERROR_IS_OK(werr))) {
1244 if (servicename != NULL) {
1245 status = rpc_conf_set_share(frame,
1251 if (!(NT_STATUS_IS_OK(status))) {
1255 if (!(W_ERROR_IS_OK(werr))) {
1261 for (i = 0; i < num_shares; i++) {
1262 status = rpc_conf_set_share(frame,
1268 if (!(NT_STATUS_IS_OK(status))) {
1272 if (!(W_ERROR_IS_OK(werr))) {
1280 if (!SBC_ERROR_IS_OK(err)) {
1281 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
1284 if (!(W_ERROR_IS_OK(werr))) {
1285 status = werror_to_ntstatus(werr);
1291 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
1292 const struct dom_sid *domain_sid,
1293 const char *domain_name,
1294 struct cli_state *cli,
1295 struct rpc_pipe_client *pipe_hnd,
1296 TALLOC_CTX *mem_ctx,
1300 TALLOC_CTX *frame = talloc_stackframe();
1301 NTSTATUS status = NT_STATUS_OK;
1302 WERROR werr = WERR_OK;
1305 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1308 struct policy_handle hive_hnd, key_hnd;
1309 struct smbconf_service *service = NULL;
1310 const char *sharename = NULL;
1313 ZERO_STRUCT(hive_hnd);
1314 ZERO_STRUCT(key_hnd);
1317 if (argc != 1 || c->display_usage) {
1318 rpc_conf_showshare_usage(c, argc, argv);
1319 status = NT_STATUS_INVALID_PARAMETER;
1323 status = rpc_conf_open_conf(frame,
1330 if (!(NT_STATUS_IS_OK(status))) {
1334 if (!(W_ERROR_IS_OK(werr))) {
1338 sharename = talloc_strdup(frame, argv[0]);
1339 if (sharename == NULL) {
1340 werr = WERR_NOT_ENOUGH_MEMORY;
1341 d_fprintf(stderr, _("Failed to create share: %s\n"),
1346 service = talloc(frame, struct smbconf_service);
1347 if (service == NULL) {
1348 werr = WERR_NOT_ENOUGH_MEMORY;
1349 d_fprintf(stderr, _("Failed to create share: %s\n"),
1354 status = rpc_conf_get_share(frame,
1361 if (!(NT_STATUS_IS_OK(status))) {
1364 if (!(W_ERROR_IS_OK(werr))) {
1368 rpc_conf_print_shares(1, service);
1371 if (!(W_ERROR_IS_OK(werr))) {
1372 status = werror_to_ntstatus(werr);
1375 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1376 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1382 static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
1383 const struct dom_sid *domain_sid,
1384 const char *domain_name,
1385 struct cli_state *cli,
1386 struct rpc_pipe_client *pipe_hnd,
1387 TALLOC_CTX *mem_ctx,
1391 TALLOC_CTX *frame = talloc_stackframe();
1392 NTSTATUS status = NT_STATUS_OK;
1393 WERROR werr = WERR_OK;
1396 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1399 struct policy_handle hive_hnd, key_hnd, share_hnd;
1400 char *sharename = NULL;
1401 const char *path = NULL;
1402 const char *comment = NULL;
1403 const char *guest_ok = "no";
1404 const char *read_only = "yes";
1405 struct winreg_String key, keyclass;
1406 enum winreg_CreateAction action = 0;
1409 ZERO_STRUCT(hive_hnd);
1410 ZERO_STRUCT(key_hnd);
1411 ZERO_STRUCT(share_hnd);
1414 ZERO_STRUCT(keyclass);
1416 if (c->display_usage) {
1417 rpc_conf_addshare_usage(c, argc, argv);
1418 status = NT_STATUS_INVALID_PARAMETER;
1426 rpc_conf_addshare_usage(c, argc, argv);
1427 status = NT_STATUS_INVALID_PARAMETER;
1434 if (!strnequal(argv[3], "guest_ok=", 9)) {
1435 rpc_conf_addshare_usage(c, argc, argv);
1436 status = NT_STATUS_INVALID_PARAMETER;
1439 switch (argv[3][9]) {
1449 rpc_conf_addshare_usage(c, argc, argv);
1450 status = NT_STATUS_INVALID_PARAMETER;
1456 if (!strnequal(argv[2], "writeable=", 10)) {
1457 rpc_conf_addshare_usage(c, argc, argv);
1458 status = NT_STATUS_INVALID_PARAMETER;
1461 switch (argv[2][10]) {
1471 rpc_conf_addshare_usage(c, argc, argv);
1472 status = NT_STATUS_INVALID_PARAMETER;
1479 sharename = talloc_strdup(frame, argv[0]);
1480 if (sharename == NULL) {
1481 d_printf(_("error: out of memory!\n"));
1488 status = rpc_conf_open_conf(frame,
1495 if (!(NT_STATUS_IS_OK(status))) {
1499 if (!(W_ERROR_IS_OK(werr))) {
1506 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1507 0, REG_KEY_READ, NULL, &share_hnd,
1510 if (!(NT_STATUS_IS_OK(status))) {
1511 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1512 argv[0], nt_errstr(status));
1516 if (!W_ERROR_IS_OK(werr)) {
1517 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1518 argv[0], win_errstr(werr));
1523 case REG_ACTION_NONE:
1524 werr = WERR_CREATE_FAILED;
1525 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1526 argv[0], win_errstr(werr));
1528 case REG_CREATED_NEW_KEY:
1529 DEBUG(5, ("net rpc conf setincludes:"
1530 "createkey created %s\n", argv[0]));
1532 case REG_OPENED_EXISTING_KEY:
1533 d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
1534 status = NT_STATUS_INVALID_PARAMETER;
1538 /* set the path parameter */
1539 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1540 "path", path, &werr);
1542 if (!(NT_STATUS_IS_OK(status))) {
1543 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1544 " with value %s\n %s\n",
1545 "path", path, nt_errstr(status));
1549 if (!(W_ERROR_IS_OK(werr))) {
1550 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1551 " with value %s\n %s\n",
1552 "path", path, win_errstr(werr));
1556 /* set the writeable parameter */
1557 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1558 "read only", read_only, &werr);
1560 if (!(NT_STATUS_IS_OK(status))) {
1561 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1562 " with value %s\n %s\n",
1563 "read only", read_only, nt_errstr(status));
1567 if (!(W_ERROR_IS_OK(werr))) {
1568 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1569 " with value %s\n %s\n",
1570 "read only", read_only, win_errstr(werr));
1574 /* set the guest ok parameter */
1575 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1576 "guest ok", guest_ok, &werr);
1578 if (!(NT_STATUS_IS_OK(status))) {
1579 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1580 " with value %s\n %s\n",
1581 "guest ok", guest_ok, nt_errstr(status));
1585 if (!(W_ERROR_IS_OK(werr))) {
1586 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1587 " with value %s\n %s\n",
1588 "guest ok", guest_ok, win_errstr(werr));
1593 /* set the comment parameter */
1594 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1595 "comment", comment, &werr);
1597 if (!(NT_STATUS_IS_OK(status))) {
1598 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1599 " with value %s\n %s\n",
1600 "comment", comment, nt_errstr(status));
1604 if (!(W_ERROR_IS_OK(werr))) {
1605 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1606 " with value %s\n %s\n",
1607 "comment", comment, win_errstr(werr));
1612 if (!(W_ERROR_IS_OK(werr))) {
1613 status = werror_to_ntstatus(werr);
1616 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1617 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1618 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1624 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
1625 const struct dom_sid *domain_sid,
1626 const char *domain_name,
1627 struct cli_state *cli,
1628 struct rpc_pipe_client *pipe_hnd,
1629 TALLOC_CTX *mem_ctx,
1633 TALLOC_CTX *frame = talloc_stackframe();
1634 NTSTATUS status = NT_STATUS_OK;
1635 WERROR werr = WERR_OK;
1638 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1641 struct policy_handle hive_hnd, key_hnd;
1642 struct smbconf_service *service = NULL;
1644 bool param_is_set = false;
1645 uint32_t param_count;
1647 ZERO_STRUCT(hive_hnd);
1648 ZERO_STRUCT(key_hnd);
1651 if (argc != 2 || c->display_usage) {
1652 rpc_conf_getparm_usage(c, argc, argv);
1653 status = NT_STATUS_INVALID_PARAMETER;
1657 status = rpc_conf_open_conf(frame,
1664 if (!(NT_STATUS_IS_OK(status))) {
1668 if (!(W_ERROR_IS_OK(werr))) {
1673 service = talloc(frame, struct smbconf_service);
1675 status = rpc_conf_get_share(frame,
1682 if (!(NT_STATUS_IS_OK(status))) {
1686 if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)) {
1687 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1692 if (!(W_ERROR_IS_OK(werr))) {
1696 for (param_count = 0;
1697 param_count < service->num_params;
1700 /* should includes also be printed? */
1701 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1703 service->param_values[param_count]);
1704 param_is_set = true;
1708 if (!param_is_set) {
1709 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1711 werr = WERR_FILE_NOT_FOUND;
1717 if (!(W_ERROR_IS_OK(werr))) {
1718 status = werror_to_ntstatus(werr);
1721 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1722 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1729 static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
1730 const struct dom_sid *domain_sid,
1731 const char *domain_name,
1732 struct cli_state *cli,
1733 struct rpc_pipe_client *pipe_hnd,
1734 TALLOC_CTX *mem_ctx,
1738 TALLOC_CTX *frame = talloc_stackframe();
1739 NTSTATUS status = NT_STATUS_OK;
1740 WERROR werr = WERR_OK;
1743 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1746 struct policy_handle hive_hnd, key_hnd, share_hnd;
1748 struct winreg_String key, keyclass;
1749 enum winreg_CreateAction action = 0;
1751 const char *service_name, *param_name, *valstr;
1753 ZERO_STRUCT(hive_hnd);
1754 ZERO_STRUCT(key_hnd);
1755 ZERO_STRUCT(share_hnd);
1758 ZERO_STRUCT(keyclass);
1760 if (argc != 3 || c->display_usage) {
1761 rpc_conf_setparm_usage(c, argc, argv);
1762 status = NT_STATUS_INVALID_PARAMETER;
1766 status = rpc_conf_open_conf(frame,
1773 if (!(NT_STATUS_IS_OK(status))) {
1777 if (!(W_ERROR_IS_OK(werr))) {
1781 service_name = argv[0];
1782 param_name = argv[1];
1785 key.name = service_name;
1788 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1789 0, REG_KEY_READ, NULL, &share_hnd,
1792 if (!(NT_STATUS_IS_OK(status))) {
1793 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1794 service_name, nt_errstr(status));
1798 if (!W_ERROR_IS_OK(werr)) {
1799 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1800 service_name, win_errstr(werr));
1805 case REG_ACTION_NONE:
1806 werr = WERR_CREATE_FAILED;
1807 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1808 service_name, win_errstr(werr));
1810 case REG_CREATED_NEW_KEY:
1811 DEBUG(5, ("net rpc conf setparm:"
1812 "createkey created %s\n", service_name));
1814 case REG_OPENED_EXISTING_KEY:
1815 DEBUG(5, ("net rpc conf setparm:"
1816 "createkey opened existing %s\n",
1819 /* delete posibly existing value */
1820 status = rpc_conf_del_value(frame,
1827 if (!(NT_STATUS_IS_OK(status))) {
1831 if (!(W_ERROR_IS_OK(werr))) {
1839 * check if parameter is valid for writing
1842 if (!net_conf_param_valid(service_name, param_name, valstr)) {
1843 werr = WERR_INVALID_PARAMETER;
1847 /* set the parameter */
1848 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1849 param_name, valstr, &werr);
1851 if (!(NT_STATUS_IS_OK(status))) {
1852 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1853 " with value %s\n %s\n",
1854 param_name, valstr, nt_errstr(status));
1858 if (!(W_ERROR_IS_OK(werr))) {
1859 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1860 " with value %s\n %s\n",
1861 param_name, valstr, win_errstr(werr));
1867 if (!(W_ERROR_IS_OK(werr))) {
1868 status = werror_to_ntstatus(werr);
1871 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1872 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1873 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1879 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1880 const struct dom_sid *domain_sid,
1881 const char *domain_name,
1882 struct cli_state *cli,
1883 struct rpc_pipe_client *pipe_hnd,
1884 TALLOC_CTX *mem_ctx,
1888 TALLOC_CTX *frame = talloc_stackframe();
1889 NTSTATUS status = NT_STATUS_OK;
1890 WERROR werr = WERR_OK;
1893 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1896 struct policy_handle hive_hnd, key_hnd;
1899 ZERO_STRUCT(hive_hnd);
1900 ZERO_STRUCT(key_hnd);
1903 if (argc != 2 || c->display_usage) {
1904 rpc_conf_delparm_usage(c, argc, argv);
1905 status = NT_STATUS_INVALID_PARAMETER;
1909 status = rpc_conf_open_conf(frame,
1916 if (!(NT_STATUS_IS_OK(status))) {
1920 if (!(W_ERROR_IS_OK(werr))) {
1924 status = rpc_conf_del_value(frame,
1933 if (!(W_ERROR_IS_OK(werr))) {
1934 status = werror_to_ntstatus(werr);
1937 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1938 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1945 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1946 const struct dom_sid *domain_sid,
1947 const char *domain_name,
1948 struct cli_state *cli,
1949 struct rpc_pipe_client *pipe_hnd,
1950 TALLOC_CTX *mem_ctx,
1954 TALLOC_CTX *frame = talloc_stackframe();
1955 NTSTATUS status = NT_STATUS_OK;
1956 WERROR werr = WERR_OK;
1959 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1962 struct policy_handle hive_hnd, key_hnd;
1963 struct smbconf_service *service = NULL;
1965 uint32_t param_count;
1968 ZERO_STRUCT(hive_hnd);
1969 ZERO_STRUCT(key_hnd);
1972 if (argc != 1 || c->display_usage) {
1973 rpc_conf_getincludes_usage(c, argc, argv);
1974 status = NT_STATUS_INVALID_PARAMETER;
1978 status = rpc_conf_open_conf(frame,
1985 if (!(NT_STATUS_IS_OK(status))) {
1989 if (!(W_ERROR_IS_OK(werr))) {
1993 service = talloc(frame, struct smbconf_service);
1995 status = rpc_conf_get_share(frame,
2002 if (!(NT_STATUS_IS_OK(status))) {
2006 if (!(W_ERROR_IS_OK(werr))) {
2010 for (param_count = 0;
2011 param_count < service->num_params;
2014 if (strcmp(service->param_names[param_count], "include") == 0) {
2015 d_printf(_("%s = %s\n"),
2016 service->param_names[param_count],
2017 service->param_values[param_count]);
2023 if (!(W_ERROR_IS_OK(werr))) {
2024 status = werror_to_ntstatus(werr);
2027 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2028 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2035 static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
2036 const struct dom_sid *domain_sid,
2037 const char *domain_name,
2038 struct cli_state *cli,
2039 struct rpc_pipe_client *pipe_hnd,
2040 TALLOC_CTX *mem_ctx,
2044 TALLOC_CTX *frame = talloc_stackframe();
2045 NTSTATUS status = NT_STATUS_OK;
2046 WERROR werr = WERR_OK;
2049 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2052 struct policy_handle hive_hnd, key_hnd, share_hnd;
2054 struct winreg_String key, keyclass;
2055 enum winreg_CreateAction action = 0;
2057 ZERO_STRUCT(hive_hnd);
2058 ZERO_STRUCT(key_hnd);
2059 ZERO_STRUCT(share_hnd);
2062 ZERO_STRUCT(keyclass);
2064 if (argc < 1 || c->display_usage) {
2065 rpc_conf_setincludes_usage(c, argc, argv);
2066 status = NT_STATUS_INVALID_PARAMETER;
2070 status = rpc_conf_open_conf(frame,
2077 if (!(NT_STATUS_IS_OK(status))) {
2081 if (!(W_ERROR_IS_OK(werr))) {
2088 status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
2089 0, REG_KEY_READ, NULL, &share_hnd,
2092 if (!(NT_STATUS_IS_OK(status))) {
2093 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2094 argv[0], nt_errstr(status));
2098 if (!W_ERROR_IS_OK(werr)) {
2099 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2100 argv[0], win_errstr(werr));
2105 case REG_ACTION_NONE:
2106 /* Is there any other way to treat this? */
2107 werr = WERR_CREATE_FAILED;
2108 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2109 argv[0], win_errstr(werr));
2111 case REG_CREATED_NEW_KEY:
2112 DEBUG(5, ("net rpc conf setincludes:"
2113 "createkey created %s\n", argv[0]));
2115 case REG_OPENED_EXISTING_KEY:
2116 DEBUG(5, ("net rpc conf setincludes:"
2117 "createkey opened existing %s\n", argv[0]));
2119 /* delete posibly existing value */
2120 status = rpc_conf_del_value(frame,
2127 if (!(NT_STATUS_IS_OK(status))) {
2131 if (!(W_ERROR_IS_OK(werr))) {
2137 /* set the 'includes' values */
2138 status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
2139 "includes", argv + 1, &werr);
2140 if (!(NT_STATUS_IS_OK(status))) {
2141 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2146 if (!(W_ERROR_IS_OK(werr))) {
2147 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2154 if (!(W_ERROR_IS_OK(werr))) {
2155 status = werror_to_ntstatus(werr);
2158 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2159 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2160 dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
2166 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
2167 const struct dom_sid *domain_sid,
2168 const char *domain_name,
2169 struct cli_state *cli,
2170 struct rpc_pipe_client *pipe_hnd,
2171 TALLOC_CTX *mem_ctx,
2175 TALLOC_CTX *frame = talloc_stackframe();
2176 NTSTATUS status = NT_STATUS_OK;
2177 WERROR werr = WERR_OK;
2180 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2183 struct policy_handle hive_hnd, key_hnd;
2186 ZERO_STRUCT(hive_hnd);
2187 ZERO_STRUCT(key_hnd);
2190 if (argc != 1 || c->display_usage) {
2191 rpc_conf_delincludes_usage(c, argc, argv);
2192 status = NT_STATUS_INVALID_PARAMETER;
2196 status = rpc_conf_open_conf(frame,
2203 if (!(NT_STATUS_IS_OK(status))) {
2207 if (!(W_ERROR_IS_OK(werr))) {
2211 status = rpc_conf_del_value(frame,
2220 if (!(W_ERROR_IS_OK(werr))) {
2221 status = werror_to_ntstatus(werr);
2224 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2225 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2232 /**********************************************************
2234 * Functions that run the rpc commands for net rpc conf modules
2236 **********************************************************/
2238 static int rpc_conf_drop(struct net_context *c, int argc,
2241 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2242 rpc_conf_drop_internal, argc, argv );
2246 static int rpc_conf_showshare(struct net_context *c, int argc,
2249 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2250 rpc_conf_showshare_internal, argc, argv );
2253 static int rpc_conf_addshare(struct net_context *c, int argc,
2256 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2257 rpc_conf_addshare_internal, argc, argv );
2260 static int rpc_conf_listshares(struct net_context *c, int argc,
2263 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2264 rpc_conf_listshares_internal, argc, argv );
2267 static int rpc_conf_list(struct net_context *c, int argc,
2270 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2271 rpc_conf_list_internal, argc, argv );
2274 static int rpc_conf_import(struct net_context *c, int argc,
2277 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2278 rpc_conf_import_internal, argc, argv );
2280 static int rpc_conf_delshare(struct net_context *c, int argc,
2283 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2284 rpc_conf_delshare_internal, argc, argv );
2287 static int rpc_conf_getparm(struct net_context *c, int argc,
2290 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2291 rpc_conf_getparm_internal, argc, argv );
2294 static int rpc_conf_setparm(struct net_context *c, int argc,
2297 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2298 rpc_conf_setparm_internal, argc, argv );
2300 static int rpc_conf_delparm(struct net_context *c, int argc,
2303 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2304 rpc_conf_delparm_internal, argc, argv );
2307 static int rpc_conf_getincludes(struct net_context *c, int argc,
2310 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2311 rpc_conf_getincludes_internal, argc, argv );
2314 static int rpc_conf_setincludes(struct net_context *c, int argc,
2317 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2318 rpc_conf_setincludes_internal, argc, argv );
2321 static int rpc_conf_delincludes(struct net_context *c, int argc,
2324 return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2325 rpc_conf_delincludes_internal, argc, argv );
2328 /* function calls */
2329 int net_rpc_conf(struct net_context *c, int argc,
2332 struct functable func_table[] = {
2337 N_("Dump the complete remote configuration in smb.conf like "
2339 N_("net rpc conf list\n"
2340 " Dump the complete remote configuration in smb.conf "
2348 N_("Import configuration from file in smb.conf "
2350 N_("net rpc conf import\n"
2351 " Import configuration from file in smb.conf "
2356 rpc_conf_listshares,
2358 N_("List the remote share names."),
2359 N_("net rpc conf list\n"
2360 " List the remote share names.")
2367 N_("Delete the complete remote configuration."),
2368 N_("net rpc conf drop\n"
2369 " Delete the complete remote configuration.")
2376 N_("Show the definition of a remote share."),
2377 N_("net rpc conf showshare\n"
2378 " Show the definition of a remote share.")
2385 N_("Create a new remote share."),
2386 N_("net rpc conf addshare\n"
2387 " Create a new remote share.")
2393 N_("Delete a remote share."),
2394 N_("net rpc conf delshare\n"
2395 " Delete a remote share.")
2401 N_("Retrieve the value of a parameter."),
2402 N_("net rpc conf getparm\n"
2403 " Retrieve the value of a parameter.")
2409 N_("Store a parameter."),
2410 N_("net rpc conf setparm\n"
2411 " Store a parameter.")
2417 N_("Delete a parameter."),
2418 N_("net rpc conf delparm\n"
2419 " Delete a parameter.")
2423 rpc_conf_getincludes,
2425 N_("Show the includes of a share definition."),
2426 N_("net rpc conf getincludes\n"
2427 " Show the includes of a share definition.")
2431 rpc_conf_setincludes,
2433 N_("Set includes for a share."),
2434 N_("net rpc conf setincludes\n"
2435 " Set includes for a share.")
2439 rpc_conf_delincludes,
2441 N_("Delete includes from a share definition."),
2442 N_("net rpc conf delincludes\n"
2443 " Delete includes from a share definition.")
2445 {NULL, NULL, 0, NULL, NULL}
2448 return net_run_function(c, argc, argv, "net rpc conf", func_table);