2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Local configuration interface
5 * Copyright (C) Vicentiu Ciorbaru 2011
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 * This is an interface to Samba's configuration.
24 * This tool supports local as well as remote interaction via rpc
25 * with the configuration stored in the registry.
30 #include "utils/net.h"
31 #include "rpc_client/cli_pipe.h"
32 #include "../librpc/gen_ndr/ndr_samr_c.h"
33 #include "rpc_client/init_samr.h"
34 #include "../librpc/gen_ndr/ndr_winreg_c.h"
35 #include "../libcli/registry/util_reg.h"
36 #include "rpc_client/cli_winreg.h"
37 #include "lib/smbconf/smbconf.h"
38 #include "lib/smbconf/smbconf_init.h"
39 #include "lib/smbconf/smbconf_reg.h"
40 #include "lib/param/loadparm.h"
44 /* internal functions */
45 /**********************************************************
49 **********************************************************/
50 const char confpath
[100] = "Software\\Samba\\smbconf";
52 static int rpc_conf_list_usage(struct net_context
*c
, int argc
,
55 d_printf("%s net rpc conf list\n", _("Usage:"));
59 static int rpc_conf_listshares_usage(struct net_context
*c
, int argc
,
62 d_printf("%s net rpc conf listshares\n", _("Usage:"));
66 static int rpc_conf_delshare_usage(struct net_context
*c
, int argc
,
71 _("net rpc conf delshare <sharename>\n"));
75 static int rpc_conf_addshare_usage(struct net_context
*c
, int argc
,
80 _(" net rpc conf addshare <sharename> <path> "
81 "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
82 "\t<sharename> the new share name.\n"
83 "\t<path> the path on the filesystem to export.\n"
84 "\twriteable={y|N} set \"writeable to \"yes\" or "
85 "\"no\" (default) on this share.\n"
86 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
87 "\"no\" (default) on this share.\n"
88 "\t<comment> optional comment for the new share.\n"));
93 static int rpc_conf_import_usage(struct net_context
*c
, int argc
,
98 _(" net rpc conf import [--test|-T] <filename> "
100 "\t[--test|-T] testmode - do not act, just print "
101 "what would be done\n"
102 "\t<servicename> only import service <servicename>, "
103 "ignore the rest\n"));
107 static int rpc_conf_showshare_usage(struct net_context
*c
, int argc
,
112 _("net rpc conf showshare <sharename>\n"));
116 static int rpc_conf_drop_usage(struct net_context
*c
, int argc
,
119 d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
123 static int rpc_conf_getparm_usage(struct net_context
*c
, int argc
,
126 d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
131 static int rpc_conf_setparm_usage(struct net_context
*c
, int argc
,
136 _(" net rpc conf setparm <section> <param> <value>\n"));
140 static int rpc_conf_delparm_usage(struct net_context
*c
, int argc
,
143 d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
148 static int rpc_conf_getincludes_usage(struct net_context
*c
, int argc
,
151 d_printf("%s\nnet rpc conf getincludes <sharename>\n",
156 static int rpc_conf_setincludes_usage(struct net_context
*c
, int argc
,
159 d_printf("%s\nnet rpc conf setincludes <sharename> [<filename>]*\n",
164 static int rpc_conf_delincludes_usage(struct net_context
*c
, int argc
,
167 d_printf("%s\nnet rpc conf delincludes <sharename>\n",
172 /**********************************************************
176 **********************************************************/
178 static bool rpc_conf_reg_valname_forbidden(const char * valname
)
180 const char *forbidden_valnames
[] = {
185 "includes", /* this has a special meaning internally */
188 const char **forbidden
= NULL
;
190 for (forbidden
= forbidden_valnames
; *forbidden
!= NULL
; forbidden
++) {
191 if (strwicmp(valname
, *forbidden
) == 0) {
200 * The function deletes a registry value with the name 'value' from the share
201 * with the name 'share_name'. 'parent_hnd' is the handle for the smbconf key.
203 static NTSTATUS
rpc_conf_del_value(TALLOC_CTX
*mem_ctx
,
204 struct dcerpc_binding_handle
*b
,
205 struct policy_handle
*parent_hnd
,
206 const char *share_name
,
211 TALLOC_CTX
*frame
= talloc_stackframe();
212 NTSTATUS status
= NT_STATUS_OK
;
213 WERROR result
= WERR_OK
;
216 struct winreg_String keyname
, valuename
;
217 struct policy_handle child_hnd
;
219 ZERO_STRUCT(child_hnd
);
220 ZERO_STRUCT(keyname
);
221 ZERO_STRUCT(valuename
);
223 keyname
.name
= share_name
;
224 valuename
.name
= value
;
226 status
= dcerpc_winreg_OpenKey(b
, frame
, parent_hnd
, keyname
, 0,
227 REG_KEY_WRITE
, &child_hnd
, &result
);
229 if (!(NT_STATUS_IS_OK(status
))) {
230 d_fprintf(stderr
, _("Failed to open key '%s': %s\n"),
231 keyname
.name
, nt_errstr(status
));
235 if (!(W_ERROR_IS_OK(result
))) {
236 d_fprintf(stderr
, _("Failed to open key '%s': %s\n"),
237 keyname
.name
, win_errstr(result
));
241 status
= dcerpc_winreg_DeleteValue(b
,
247 if (!(NT_STATUS_IS_OK(status
))) {
248 d_fprintf(stderr
, _("Failed to delete value %s\n"),
253 if (!(W_ERROR_IS_OK(result
))) {
254 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)){
259 d_fprintf(stderr
, _("Failed to delete value %s\n"),
267 dcerpc_winreg_CloseKey(b
, frame
, &child_hnd
, &_werr
);
275 * The function sets a share in the registry with the parameters
276 * held in the smbconf_service struct
278 static NTSTATUS
rpc_conf_set_share(TALLOC_CTX
*mem_ctx
,
279 struct dcerpc_binding_handle
*b
,
280 struct policy_handle
*parent_hnd
,
281 struct smbconf_service
*service
,
284 TALLOC_CTX
*frame
= talloc_stackframe();
286 NTSTATUS status
= NT_STATUS_OK
;
287 WERROR result
= WERR_OK
;
289 enum winreg_CreateAction action
;
292 const char **includes
;
294 struct winreg_String wkey
, wkeyclass
;
295 struct policy_handle share_hnd
;
297 ZERO_STRUCT(share_hnd
);
299 ZERO_STRUCT(wkeyclass
);
301 wkey
.name
= service
->name
;
303 action
= REG_ACTION_NONE
;
305 status
= dcerpc_winreg_CreateKey(b
,
317 if (!NT_STATUS_IS_OK(status
)) {
318 d_printf("winreg_CreateKey: Could not create smbconf key\n");
322 if (!W_ERROR_IS_OK(result
)) {
323 d_printf("winreg_CreateKey: Could not create smbconf key\n");
327 for (i
= 0; i
< service
->num_params
; i
++) {
328 if (strequal(service
->param_names
[i
], "include") == 0)
331 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
332 service
->param_names
[i
],
333 service
->param_values
[i
],
336 if (!(NT_STATUS_IS_OK(status
))) {
338 "ERROR: Share: '%s'\n"
339 "Could not set parameter '%s'"
340 " with value %s\n %s\n",
342 service
->param_names
[i
],
343 service
->param_values
[i
],
348 if (!(W_ERROR_IS_OK(result
))) {
350 "ERROR: Share: '%s'\n"
351 "Could not set parameter '%s'"
352 " with value %s\n %s\n",
354 service
->param_names
[i
],
355 service
->param_values
[i
],
361 includes
= talloc_zero_array(frame
,
363 service
->num_params
+ 1);
364 if (includes
== NULL
) {
366 d_fprintf(stderr
, "ERROR: out of memory\n");
370 for (j
= i
; j
< service
->num_params
; j
++) {
372 includes
[j
- i
] = talloc_strdup(
374 service
->param_values
[j
]);
376 if (includes
[j
-i
] == NULL
) {
378 d_fprintf(stderr
, "ERROR: out of memory\n");
383 status
= dcerpc_winreg_set_multi_sz(frame
, b
, &share_hnd
,
388 if (!(NT_STATUS_IS_OK(status
))) {
389 d_fprintf(stderr
, "ERROR: Share: '%s'\n"
390 "Could not set includes\n %s\n",
396 if (!(W_ERROR_IS_OK(result
))) {
397 d_fprintf(stderr
, "ERROR: Share: '%s'\n"
398 "Could not set includes\n %s\n",
404 i
= service
->num_params
;
409 /* in case of error, should it delete the created key? */
410 if (!(W_ERROR_IS_OK(result
))) {
411 status
= werror_to_ntstatus(result
);
415 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
423 * The function opens the registry database and retrieves
424 * as a smbconf_service struct the share with the name
427 static NTSTATUS
rpc_conf_get_share(TALLOC_CTX
*mem_ctx
,
428 struct dcerpc_binding_handle
*b
,
429 struct policy_handle
*parent_hnd
,
430 const char *share_name
,
431 struct smbconf_service
*share
,
434 TALLOC_CTX
*frame
= talloc_stackframe();
436 NTSTATUS status
= NT_STATUS_OK
;
437 WERROR result
= WERR_OK
;
439 struct policy_handle child_hnd
;
440 int32_t includes_cnt
, includes_idx
= -1;
441 uint32_t num_vals
, i
, param_cnt
= 0;
442 const char **val_names
;
443 enum winreg_Type
*types
;
445 struct winreg_String key
;
446 const char **multi_s
= NULL
;
447 const char *s
= NULL
;
448 struct smbconf_service tmp_share
;
450 ZERO_STRUCT(tmp_share
);
452 key
.name
= share_name
;
453 status
= dcerpc_winreg_OpenKey(b
, frame
, parent_hnd
, key
, 0,
454 REG_KEY_READ
, &child_hnd
, &result
);
456 if (!(NT_STATUS_IS_OK(status
))) {
457 d_fprintf(stderr
, _("Failed to open subkey: %s\n"),
461 if (!(W_ERROR_IS_OK(result
))) {
462 d_fprintf(stderr
, _("Failed to open subkey: %s\n"),
466 /* get all the info from the share key */
467 status
= dcerpc_winreg_enumvals(frame
,
476 if (!(NT_STATUS_IS_OK(status
))) {
477 d_fprintf(stderr
, _("Failed to enumerate values: %s\n"),
481 if (!(W_ERROR_IS_OK(result
))) {
482 d_fprintf(stderr
, _("Failed to enumerate values: %s\n"),
486 /* check for includes */
487 for (i
= 0; i
< num_vals
; i
++) {
488 if (strcmp(val_names
[i
], "includes") == 0){
489 if (!pull_reg_multi_sz(frame
,
495 _("Failed to enumerate values: %s\n"),
502 /* count the number of includes */
504 if (includes_idx
!= -1) {
505 for (includes_cnt
= 0;
506 multi_s
[includes_cnt
] != NULL
;
509 /* place the name of the share in the smbconf_service struct */
510 tmp_share
.name
= talloc_strdup(frame
, share_name
);
511 if (tmp_share
.name
== NULL
) {
513 d_fprintf(stderr
, _("Failed to create share: %s\n"),
517 /* place the number of parameters in the smbconf_service struct */
518 tmp_share
.num_params
= num_vals
;
519 if (includes_idx
!= -1) {
520 tmp_share
.num_params
= num_vals
+ includes_cnt
- 1;
522 /* allocate memory for the param_names and param_values lists */
523 tmp_share
.param_names
= talloc_zero_array(frame
, char *, tmp_share
.num_params
);
524 if (tmp_share
.param_names
== NULL
) {
526 d_fprintf(stderr
, _("Failed to create share: %s\n"),
530 tmp_share
.param_values
= talloc_zero_array(frame
, char *, tmp_share
.num_params
);
531 if (tmp_share
.param_values
== NULL
) {
533 d_fprintf(stderr
, _("Failed to create share: %s\n"),
537 /* place all params except includes */
538 for (i
= 0; i
< num_vals
; i
++) {
539 if (strcmp(val_names
[i
], "includes") != 0) {
540 if (!pull_reg_sz(frame
, &data
[i
], &s
)) {
543 _("Failed to enumerate values: %s\n"),
547 /* place param_names */
548 tmp_share
.param_names
[param_cnt
] = talloc_strdup(frame
, val_names
[i
]);
549 if (tmp_share
.param_names
[param_cnt
] == NULL
) {
551 d_fprintf(stderr
, _("Failed to create share: %s\n"),
556 /* place param_values */
557 tmp_share
.param_values
[param_cnt
++] = talloc_strdup(frame
, s
);
558 if (tmp_share
.param_values
[param_cnt
- 1] == NULL
) {
560 d_fprintf(stderr
, _("Failed to create share: %s\n"),
566 /* place the includes last */
567 for (i
= 0; i
< includes_cnt
; i
++) {
568 tmp_share
.param_names
[param_cnt
] = talloc_strdup(frame
, "include");
569 if (tmp_share
.param_names
[param_cnt
] == NULL
) {
571 d_fprintf(stderr
, _("Failed to create share: %s\n"),
576 tmp_share
.param_values
[param_cnt
++] = talloc_strdup(frame
, multi_s
[i
]);
577 if (tmp_share
.param_values
[param_cnt
- 1] == NULL
) {
579 d_fprintf(stderr
, _("Failed to create share: %s\n"),
585 /* move everything to the main memory ctx */
586 for (i
= 0; i
< param_cnt
; i
++) {
587 tmp_share
.param_names
[i
] = talloc_move(mem_ctx
, &tmp_share
.param_names
[i
]);
588 tmp_share
.param_values
[i
] = talloc_move(mem_ctx
, &tmp_share
.param_values
[i
]);
591 tmp_share
.name
= talloc_move(mem_ctx
, &tmp_share
.name
);
592 tmp_share
.param_names
= talloc_move(mem_ctx
, &tmp_share
.param_names
);
593 tmp_share
.param_values
= talloc_move(mem_ctx
, &tmp_share
.param_values
);
598 dcerpc_winreg_CloseKey(b
, frame
, &child_hnd
, &_werr
);
605 * The function prints the shares held as smbconf_service structs
606 * in a smbconf file format.
608 static int rpc_conf_print_shares(uint32_t num_shares
,
609 struct smbconf_service
*shares
)
612 uint32_t share_count
, param_count
;
613 const char *indent
= "\t";
615 if (num_shares
== 0) {
619 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
621 if (shares
[share_count
].name
!= NULL
) {
622 d_printf("[%s]\n", shares
[share_count
].name
);
625 for (param_count
= 0;
626 param_count
< shares
[share_count
].num_params
;
629 d_printf("%s%s = %s\n",
631 shares
[share_count
].param_names
[param_count
],
632 shares
[share_count
].param_values
[param_count
]);
642 * The function openes the registry key
643 * HKLM/Software/Samba/smbconf with the give access_mask
645 static NTSTATUS
rpc_conf_open_conf(TALLOC_CTX
*mem_ctx
,
646 struct dcerpc_binding_handle
*b
,
647 uint32_t access_mask
,
648 struct policy_handle
*hive_hnd
,
649 struct policy_handle
*key_hnd
,
652 TALLOC_CTX
*frame
= talloc_stackframe();
653 NTSTATUS status
= NT_STATUS_OK
;
654 WERROR result
= WERR_OK
;
656 struct policy_handle tmp_hive_hnd
, tmp_key_hnd
;
657 struct winreg_String key
;
661 status
= dcerpc_winreg_OpenHKLM(b
, frame
, NULL
,
662 access_mask
, &tmp_hive_hnd
, &result
);
665 * print no error messages if it is a read only open
666 * and key does not exist
667 * error still gets returned
670 if (access_mask
== REG_KEY_READ
&&
671 W_ERROR_EQUAL(result
, WERR_BADFILE
))
676 if (!(NT_STATUS_IS_OK(status
))) {
677 d_fprintf(stderr
, _("Failed to open hive: %s\n"),
681 if (!W_ERROR_IS_OK(result
)) {
682 d_fprintf(stderr
, _("Failed to open hive: %s\n"),
688 status
= dcerpc_winreg_OpenKey(b
, frame
, &tmp_hive_hnd
, key
, 0,
689 access_mask
, &tmp_key_hnd
, &result
);
692 * print no error messages if it is a read only open
693 * and key does not exist
694 * error still gets returned
697 if (access_mask
== REG_KEY_READ
&&
698 W_ERROR_EQUAL(result
, WERR_BADFILE
))
703 if (!(NT_STATUS_IS_OK(status
))) {
704 d_fprintf(stderr
, _("Failed to open smbconf key: %s\n"),
706 dcerpc_winreg_CloseKey(b
, frame
, &tmp_hive_hnd
, &_werr
);
709 if (!(W_ERROR_IS_OK(result
))) {
710 d_fprintf(stderr
, _("Failed to open smbconf key: %s\n"),
712 dcerpc_winreg_CloseKey(b
, frame
, &tmp_hive_hnd
, &_werr
);
716 *hive_hnd
= tmp_hive_hnd
;
717 *key_hnd
= tmp_key_hnd
;
726 /**********************************************************
728 * internal functions that provide the functionality
731 **********************************************************/
733 static NTSTATUS
rpc_conf_listshares_internal(struct net_context
*c
,
734 const struct dom_sid
*domain_sid
,
735 const char *domain_name
,
736 struct cli_state
*cli
,
737 struct rpc_pipe_client
*pipe_hnd
,
743 TALLOC_CTX
*frame
= talloc_stackframe();
744 NTSTATUS status
= NT_STATUS_OK
;
745 WERROR werr
= WERR_OK
;
748 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
751 struct policy_handle hive_hnd
, key_hnd
;
752 uint32_t num_subkeys
;
754 const char **subkeys
= NULL
;
757 ZERO_STRUCT(hive_hnd
);
758 ZERO_STRUCT(key_hnd
);
761 if (argc
!= 0 || c
->display_usage
) {
762 rpc_conf_listshares_usage(c
, argc
, argv
);
763 status
= NT_STATUS_INVALID_PARAMETER
;
768 status
= rpc_conf_open_conf(frame
,
775 if (!(NT_STATUS_IS_OK(status
))) {
779 if (!(W_ERROR_IS_OK(werr
))) {
783 status
= dcerpc_winreg_enum_keys(frame
,
790 if (!(NT_STATUS_IS_OK(status
))) {
791 d_fprintf(stderr
, _("Failed to enumerate keys: %s\n"),
796 if (!(W_ERROR_IS_OK(werr
))) {
797 d_fprintf(stderr
, _("Failed to enumerate keys: %s\n"),
802 for (i
= 0; i
< num_subkeys
; i
++) {
803 d_printf("%s\n", subkeys
[i
]);
807 if (!(W_ERROR_IS_OK(werr
))) {
808 status
= werror_to_ntstatus(werr
);
811 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
812 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
818 static NTSTATUS
rpc_conf_delshare_internal(struct net_context
*c
,
819 const struct dom_sid
*domain_sid
,
820 const char *domain_name
,
821 struct cli_state
*cli
,
822 struct rpc_pipe_client
*pipe_hnd
,
828 TALLOC_CTX
*frame
= talloc_stackframe();
829 NTSTATUS status
= NT_STATUS_OK
;
830 WERROR werr
= WERR_OK
;
833 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
836 struct policy_handle hive_hnd
, key_hnd
;
838 ZERO_STRUCT(hive_hnd
);
839 ZERO_STRUCT(key_hnd
);
842 if (argc
!= 1 || c
->display_usage
) {
843 rpc_conf_delshare_usage(c
, argc
, argv
);
844 status
= NT_STATUS_INVALID_PARAMETER
;
848 status
= rpc_conf_open_conf(frame
,
855 if (!(NT_STATUS_IS_OK(status
))) {
859 if (!(W_ERROR_IS_OK(werr
))) {
863 status
= dcerpc_winreg_delete_subkeys_recursive(frame
,
870 if (!NT_STATUS_IS_OK(status
)) {
872 "winreg_delete_subkeys: Could not delete key %s: %s\n",
873 argv
[0], nt_errstr(status
));
877 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)){
878 d_fprintf(stderr
, _("ERROR: Key does not exist\n"));
882 if (!W_ERROR_IS_OK(werr
)) {
884 "winreg_delete_subkeys: Could not delete key %s: %s\n",
885 argv
[0], win_errstr(werr
));
890 if (!(W_ERROR_IS_OK(werr
))) {
891 status
= werror_to_ntstatus(werr
);
894 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
895 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
902 static NTSTATUS
rpc_conf_list_internal(struct net_context
*c
,
903 const struct dom_sid
*domain_sid
,
904 const char *domain_name
,
905 struct cli_state
*cli
,
906 struct rpc_pipe_client
*pipe_hnd
,
912 TALLOC_CTX
*frame
= talloc_stackframe();
913 NTSTATUS status
= NT_STATUS_OK
;
914 WERROR werr
= WERR_OK
;
917 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
920 struct policy_handle hive_hnd
, key_hnd
;
921 uint32_t num_subkeys
;
923 struct smbconf_service
*shares
;
924 const char **subkeys
= NULL
;
927 ZERO_STRUCT(hive_hnd
);
928 ZERO_STRUCT(key_hnd
);
931 if (argc
!= 0 || c
->display_usage
) {
932 rpc_conf_list_usage(c
, argc
, argv
);
933 status
= NT_STATUS_INVALID_PARAMETER
;
937 status
= rpc_conf_open_conf(frame
,
944 if (!(NT_STATUS_IS_OK(status
))) {
948 if (!(W_ERROR_IS_OK(werr
))) {
952 status
= dcerpc_winreg_enum_keys(frame
,
959 if (!(NT_STATUS_IS_OK(status
))) {
960 d_fprintf(stderr
, _("Failed to enumerate keys: %s\n"),
965 if (!(W_ERROR_IS_OK(werr
))) {
966 d_fprintf(stderr
, _("Failed to enumerate keys: %s\n"),
971 if (num_subkeys
== 0) {
972 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
973 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
978 /* get info from each subkey */
979 shares
= talloc_zero_array(frame
, struct smbconf_service
, num_subkeys
);
980 if (shares
== NULL
) {
982 d_fprintf(stderr
, _("Failed to create shares: %s\n"),
988 for (i
= 0; i
< num_subkeys
; i
++) {
989 /* get each share and place it in the shares array */
990 status
= rpc_conf_get_share(frame
,
996 if (!(NT_STATUS_IS_OK(status
))) {
999 if (!(W_ERROR_IS_OK(werr
))) {
1004 /* print the shares array */
1005 rpc_conf_print_shares(num_subkeys
, shares
);
1008 if (!(W_ERROR_IS_OK(werr
))) {
1009 status
= werror_to_ntstatus(werr
);
1012 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1013 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1020 static NTSTATUS
rpc_conf_drop_internal(struct net_context
*c
,
1021 const struct dom_sid
*domain_sid
,
1022 const char *domain_name
,
1023 struct cli_state
*cli
,
1024 struct rpc_pipe_client
*pipe_hnd
,
1025 TALLOC_CTX
*mem_ctx
,
1029 TALLOC_CTX
*frame
= talloc_stackframe();
1030 NTSTATUS status
= NT_STATUS_OK
;
1031 WERROR werr
= WERR_OK
;
1034 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1037 struct policy_handle hive_hnd
, key_hnd
;
1038 const char *keyname
= confpath
;
1039 struct winreg_String wkey
, wkeyclass
;
1040 enum winreg_CreateAction action
= REG_ACTION_NONE
;
1043 ZERO_STRUCT(hive_hnd
);
1044 ZERO_STRUCT(key_hnd
);
1047 if (argc
!= 0 || c
->display_usage
) {
1048 rpc_conf_drop_usage(c
, argc
, argv
);
1049 status
= NT_STATUS_INVALID_PARAMETER
;
1053 status
= rpc_conf_open_conf(frame
,
1060 if (!(NT_STATUS_IS_OK(status
))) {
1064 if (!(W_ERROR_IS_OK(werr
))) {
1068 status
= dcerpc_winreg_delete_subkeys_recursive(frame
,
1075 if (!NT_STATUS_IS_OK(status
)) {
1076 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1077 keyname
, nt_errstr(status
));
1081 if (!W_ERROR_IS_OK(werr
)) {
1082 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1083 keyname
, win_errstr(werr
));
1087 wkey
.name
= keyname
;
1088 ZERO_STRUCT(wkeyclass
);
1089 wkeyclass
.name
= "";
1090 action
= REG_ACTION_NONE
;
1092 status
= dcerpc_winreg_CreateKey(b
,
1104 if (!NT_STATUS_IS_OK(status
)) {
1105 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1109 if (!W_ERROR_IS_OK(werr
)) {
1110 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1116 if (!(W_ERROR_IS_OK(werr
))) {
1117 status
= werror_to_ntstatus(werr
);
1120 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1121 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1127 static NTSTATUS
rpc_conf_import_internal(struct net_context
*c
,
1128 const struct dom_sid
*domain_sid
,
1129 const char *domain_name
,
1130 struct cli_state
*cli
,
1131 struct rpc_pipe_client
*pipe_hnd
,
1132 TALLOC_CTX
*mem_ctx
,
1137 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1139 struct policy_handle hive_hnd
, key_hnd
;
1141 const char *filename
= NULL
;
1142 const char *servicename
= NULL
;
1143 char *conf_source
= NULL
;
1145 struct smbconf_ctx
*txt_ctx
;
1146 struct smbconf_service
*service
= NULL
;
1147 struct smbconf_service
**services
= NULL
;
1148 uint32_t num_shares
, i
;
1149 sbcErr err
= SBC_ERR_UNKNOWN_FAILURE
;
1151 WERROR werr
= WERR_OK
;
1152 NTSTATUS status
= NT_STATUS_OK
;
1154 ZERO_STRUCT(hive_hnd
);
1155 ZERO_STRUCT(key_hnd
);
1157 frame
= talloc_stackframe();
1159 if (c
->display_usage
) {
1160 rpc_conf_import_usage(c
, argc
, argv
);
1161 status
= NT_STATUS_INVALID_PARAMETER
;
1168 rpc_conf_import_usage(c
, argc
, argv
);
1169 status
= NT_STATUS_INVALID_PARAMETER
;
1172 servicename
= talloc_strdup(frame
, argv
[1]);
1173 if (servicename
== NULL
) {
1174 d_printf(_("error: out of memory!\n"));
1182 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1185 conf_source
= talloc_asprintf(frame
, "file:%s", filename
);
1186 if (conf_source
== NULL
) {
1187 d_fprintf(stderr
, _("error: out of memory!\n"));
1191 err
= smbconf_init(frame
, &txt_ctx
, conf_source
);
1192 if (!SBC_ERROR_IS_OK(err
)) {
1193 d_fprintf(stderr
, _("error loading file '%s': %s\n"), filename
,
1194 sbcErrorString(err
));
1198 if (c
->opt_testmode
) {
1199 d_printf(_("\nTEST MODE - "
1200 "would import the following configuration:\n\n"));
1203 if (servicename
!= NULL
) {
1204 err
= smbconf_get_share(txt_ctx
, frame
,
1207 if (!SBC_ERROR_IS_OK(err
)) {
1215 err
= smbconf_get_config(txt_ctx
, frame
,
1218 if (!SBC_ERROR_IS_OK(err
)) {
1223 if (c
->opt_testmode
) {
1224 if (servicename
!= NULL
) {
1225 rpc_conf_print_shares(1, service
);
1227 for (i
= 0; i
< num_shares
; i
++) {
1228 rpc_conf_print_shares(1, services
[i
]);
1233 status
= rpc_conf_drop_internal(c
,
1242 if (!(NT_STATUS_IS_OK(status
))) {
1246 status
= rpc_conf_open_conf(frame
,
1253 if (!(NT_STATUS_IS_OK(status
))) {
1257 if (!(W_ERROR_IS_OK(werr
))) {
1261 if (servicename
!= NULL
) {
1262 status
= rpc_conf_set_share(frame
,
1268 if (!(NT_STATUS_IS_OK(status
))) {
1272 if (!(W_ERROR_IS_OK(werr
))) {
1278 for (i
= 0; i
< num_shares
; i
++) {
1279 status
= rpc_conf_set_share(frame
,
1285 if (!(NT_STATUS_IS_OK(status
))) {
1289 if (!(W_ERROR_IS_OK(werr
))) {
1297 if (!SBC_ERROR_IS_OK(err
)) {
1298 d_fprintf(stderr
, "ERROR: %s\n", sbcErrorString(err
));
1301 if (!(W_ERROR_IS_OK(werr
))) {
1302 status
= werror_to_ntstatus(werr
);
1308 static NTSTATUS
rpc_conf_showshare_internal(struct net_context
*c
,
1309 const struct dom_sid
*domain_sid
,
1310 const char *domain_name
,
1311 struct cli_state
*cli
,
1312 struct rpc_pipe_client
*pipe_hnd
,
1313 TALLOC_CTX
*mem_ctx
,
1317 TALLOC_CTX
*frame
= talloc_stackframe();
1318 NTSTATUS status
= NT_STATUS_OK
;
1319 WERROR werr
= WERR_OK
;
1322 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1325 struct policy_handle hive_hnd
, key_hnd
;
1326 struct smbconf_service
*service
= NULL
;
1327 const char *sharename
= NULL
;
1330 ZERO_STRUCT(hive_hnd
);
1331 ZERO_STRUCT(key_hnd
);
1334 if (argc
!= 1 || c
->display_usage
) {
1335 rpc_conf_showshare_usage(c
, argc
, argv
);
1336 status
= NT_STATUS_INVALID_PARAMETER
;
1340 status
= rpc_conf_open_conf(frame
,
1347 if (!(NT_STATUS_IS_OK(status
))) {
1351 if (!(W_ERROR_IS_OK(werr
))) {
1355 sharename
= talloc_strdup(frame
, argv
[0]);
1356 if (sharename
== NULL
) {
1358 d_fprintf(stderr
, _("Failed to create share: %s\n"),
1363 service
= talloc(frame
, struct smbconf_service
);
1364 if (service
== NULL
) {
1366 d_fprintf(stderr
, _("Failed to create share: %s\n"),
1371 status
= rpc_conf_get_share(frame
,
1378 if (!(NT_STATUS_IS_OK(status
))) {
1381 if (!(W_ERROR_IS_OK(werr
))) {
1385 rpc_conf_print_shares(1, service
);
1388 if (!(W_ERROR_IS_OK(werr
))) {
1389 status
= werror_to_ntstatus(werr
);
1392 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1393 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1399 static NTSTATUS
rpc_conf_addshare_internal(struct net_context
*c
,
1400 const struct dom_sid
*domain_sid
,
1401 const char *domain_name
,
1402 struct cli_state
*cli
,
1403 struct rpc_pipe_client
*pipe_hnd
,
1404 TALLOC_CTX
*mem_ctx
,
1408 TALLOC_CTX
*frame
= talloc_stackframe();
1409 NTSTATUS status
= NT_STATUS_OK
;
1410 WERROR werr
= WERR_OK
;
1413 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1416 struct policy_handle hive_hnd
, key_hnd
, share_hnd
;
1417 char *sharename
= NULL
;
1418 const char *path
= NULL
;
1419 const char *comment
= NULL
;
1420 const char *guest_ok
= "no";
1421 const char *read_only
= "yes";
1422 struct winreg_String key
, keyclass
;
1423 enum winreg_CreateAction action
= 0;
1426 ZERO_STRUCT(hive_hnd
);
1427 ZERO_STRUCT(key_hnd
);
1428 ZERO_STRUCT(share_hnd
);
1431 ZERO_STRUCT(keyclass
);
1433 if (c
->display_usage
) {
1434 rpc_conf_addshare_usage(c
, argc
, argv
);
1435 status
= NT_STATUS_INVALID_PARAMETER
;
1443 rpc_conf_addshare_usage(c
, argc
, argv
);
1444 status
= NT_STATUS_INVALID_PARAMETER
;
1449 if (!strnequal(argv
[3], "guest_ok=", 9)) {
1450 rpc_conf_addshare_usage(c
, argc
, argv
);
1451 status
= NT_STATUS_INVALID_PARAMETER
;
1454 switch (argv
[3][9]) {
1464 rpc_conf_addshare_usage(c
, argc
, argv
);
1465 status
= NT_STATUS_INVALID_PARAMETER
;
1469 if (!strnequal(argv
[2], "writeable=", 10)) {
1470 rpc_conf_addshare_usage(c
, argc
, argv
);
1471 status
= NT_STATUS_INVALID_PARAMETER
;
1474 switch (argv
[2][10]) {
1484 rpc_conf_addshare_usage(c
, argc
, argv
);
1485 status
= NT_STATUS_INVALID_PARAMETER
;
1490 sharename
= talloc_strdup(frame
, argv
[0]);
1491 if (sharename
== NULL
) {
1492 d_printf(_("error: out of memory!\n"));
1499 status
= rpc_conf_open_conf(frame
,
1506 if (!(NT_STATUS_IS_OK(status
))) {
1510 if (!(W_ERROR_IS_OK(werr
))) {
1517 status
= dcerpc_winreg_CreateKey(b
, frame
, &key_hnd
, key
, keyclass
,
1518 0, REG_KEY_READ
, NULL
, &share_hnd
,
1521 if (!(NT_STATUS_IS_OK(status
))) {
1522 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1523 argv
[0], nt_errstr(status
));
1527 if (!W_ERROR_IS_OK(werr
)) {
1528 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1529 argv
[0], win_errstr(werr
));
1534 case REG_ACTION_NONE
:
1535 werr
= WERR_CREATE_FAILED
;
1536 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1537 argv
[0], win_errstr(werr
));
1539 case REG_CREATED_NEW_KEY
:
1540 DEBUG(5, ("net rpc conf setincludes:"
1541 "createkey created %s\n", argv
[0]));
1543 case REG_OPENED_EXISTING_KEY
:
1544 d_fprintf(stderr
, _("ERROR: Share '%s' already exists\n"), argv
[0]);
1545 status
= NT_STATUS_INVALID_PARAMETER
;
1549 /* set the path parameter */
1550 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1551 "path", path
, &werr
);
1553 if (!(NT_STATUS_IS_OK(status
))) {
1554 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1555 " with value %s\n %s\n",
1556 "path", path
, nt_errstr(status
));
1560 if (!(W_ERROR_IS_OK(werr
))) {
1561 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1562 " with value %s\n %s\n",
1563 "path", path
, win_errstr(werr
));
1567 /* set the writeable parameter */
1568 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1569 "read only", read_only
, &werr
);
1571 if (!(NT_STATUS_IS_OK(status
))) {
1572 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1573 " with value %s\n %s\n",
1574 "read only", read_only
, nt_errstr(status
));
1578 if (!(W_ERROR_IS_OK(werr
))) {
1579 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1580 " with value %s\n %s\n",
1581 "read only", read_only
, win_errstr(werr
));
1585 /* set the guest ok parameter */
1586 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1587 "guest ok", guest_ok
, &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 "guest ok", guest_ok
, 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 "guest ok", guest_ok
, win_errstr(werr
));
1604 /* set the comment parameter */
1605 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1606 "comment", comment
, &werr
);
1608 if (!(NT_STATUS_IS_OK(status
))) {
1609 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1610 " with value %s\n %s\n",
1611 "comment", comment
, nt_errstr(status
));
1615 if (!(W_ERROR_IS_OK(werr
))) {
1616 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1617 " with value %s\n %s\n",
1618 "comment", comment
, win_errstr(werr
));
1623 if (!(W_ERROR_IS_OK(werr
))) {
1624 status
= werror_to_ntstatus(werr
);
1627 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1628 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1629 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
1635 static NTSTATUS
rpc_conf_getparm_internal(struct net_context
*c
,
1636 const struct dom_sid
*domain_sid
,
1637 const char *domain_name
,
1638 struct cli_state
*cli
,
1639 struct rpc_pipe_client
*pipe_hnd
,
1640 TALLOC_CTX
*mem_ctx
,
1644 TALLOC_CTX
*frame
= talloc_stackframe();
1645 NTSTATUS status
= NT_STATUS_OK
;
1646 WERROR werr
= WERR_OK
;
1649 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1652 struct policy_handle hive_hnd
, key_hnd
;
1653 struct smbconf_service
*service
= NULL
;
1655 bool param_is_set
= false;
1656 uint32_t param_count
;
1658 ZERO_STRUCT(hive_hnd
);
1659 ZERO_STRUCT(key_hnd
);
1662 if (argc
!= 2 || c
->display_usage
) {
1663 rpc_conf_getparm_usage(c
, argc
, argv
);
1664 status
= NT_STATUS_INVALID_PARAMETER
;
1668 status
= rpc_conf_open_conf(frame
,
1675 if (!(NT_STATUS_IS_OK(status
))) {
1679 if (!(W_ERROR_IS_OK(werr
))) {
1684 service
= talloc(frame
, struct smbconf_service
);
1686 status
= rpc_conf_get_share(frame
,
1693 if (!(NT_STATUS_IS_OK(status
))) {
1697 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)) {
1698 d_fprintf(stderr
, _("ERROR: Share %s does not exist\n"),
1703 if (!(W_ERROR_IS_OK(werr
))) {
1707 for (param_count
= 0;
1708 param_count
< service
->num_params
;
1711 /* should includes also be printed? */
1712 if (strcmp(service
->param_names
[param_count
], argv
[1]) == 0) {
1714 service
->param_values
[param_count
]);
1715 param_is_set
= true;
1719 if (!param_is_set
) {
1720 d_fprintf(stderr
, _("ERROR: Given parameter '%s' has not been set\n"),
1722 werr
= WERR_BADFILE
;
1728 if (!(W_ERROR_IS_OK(werr
))) {
1729 status
= werror_to_ntstatus(werr
);
1732 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1733 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1740 static NTSTATUS
rpc_conf_setparm_internal(struct net_context
*c
,
1741 const struct dom_sid
*domain_sid
,
1742 const char *domain_name
,
1743 struct cli_state
*cli
,
1744 struct rpc_pipe_client
*pipe_hnd
,
1745 TALLOC_CTX
*mem_ctx
,
1749 TALLOC_CTX
*frame
= talloc_stackframe();
1750 NTSTATUS status
= NT_STATUS_OK
;
1751 WERROR werr
= WERR_OK
;
1754 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1757 struct policy_handle hive_hnd
, key_hnd
, share_hnd
;
1759 struct winreg_String key
, keyclass
;
1760 enum winreg_CreateAction action
= 0;
1762 const char *canon_valname
;
1763 const char *canon_valstr
;
1765 ZERO_STRUCT(hive_hnd
);
1766 ZERO_STRUCT(key_hnd
);
1767 ZERO_STRUCT(share_hnd
);
1770 ZERO_STRUCT(keyclass
);
1772 if (argc
!= 3 || c
->display_usage
) {
1773 rpc_conf_setparm_usage(c
, argc
, argv
);
1774 status
= NT_STATUS_INVALID_PARAMETER
;
1778 status
= rpc_conf_open_conf(frame
,
1785 if (!(NT_STATUS_IS_OK(status
))) {
1789 if (!(W_ERROR_IS_OK(werr
))) {
1796 status
= dcerpc_winreg_CreateKey(b
, frame
, &key_hnd
, key
, keyclass
,
1797 0, REG_KEY_READ
, NULL
, &share_hnd
,
1800 if (!(NT_STATUS_IS_OK(status
))) {
1801 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1802 argv
[0], nt_errstr(status
));
1806 if (!W_ERROR_IS_OK(werr
)) {
1807 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1808 argv
[0], win_errstr(werr
));
1813 case REG_ACTION_NONE
:
1814 werr
= WERR_CREATE_FAILED
;
1815 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1816 argv
[0], win_errstr(werr
));
1818 case REG_CREATED_NEW_KEY
:
1819 DEBUG(5, ("net rpc conf setparm:"
1820 "createkey created %s\n", argv
[0]));
1822 case REG_OPENED_EXISTING_KEY
:
1823 DEBUG(5, ("net rpc conf setparm:"
1824 "createkey opened existing %s\n", argv
[0]));
1826 /* delete posibly existing value */
1827 status
= rpc_conf_del_value(frame
,
1834 if (!(NT_STATUS_IS_OK(status
))) {
1838 if (!(W_ERROR_IS_OK(werr
))) {
1845 /* check if parameter is valid for writing */
1846 if (!lp_canonicalize_parameter_with_value(argv
[1], argv
[2],
1850 if (canon_valname
== NULL
) {
1851 d_fprintf(stderr
, "invalid parameter '%s' given\n",
1854 d_fprintf(stderr
, "invalid value '%s' given for "
1855 "parameter '%s'\n", argv
[1], argv
[2]);
1857 werr
= WERR_INVALID_PARAM
;
1861 if (rpc_conf_reg_valname_forbidden(canon_valname
)) {
1862 d_fprintf(stderr
, "Parameter '%s' not allowed in registry.\n",
1864 werr
= WERR_INVALID_PARAM
;
1868 if (!strequal(argv
[0], "global") &&
1869 lp_parameter_is_global(argv
[1]))
1871 d_fprintf(stderr
, "Global parameter '%s' not allowed in "
1872 "service definition ('%s').\n", canon_valname
,
1874 werr
= WERR_INVALID_PARAM
;
1878 /* set the parameter */
1879 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1880 argv
[1], argv
[2], &werr
);
1882 if (!(NT_STATUS_IS_OK(status
))) {
1883 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1884 " with value %s\n %s\n",
1885 argv
[1], argv
[2], nt_errstr(status
));
1889 if (!(W_ERROR_IS_OK(werr
))) {
1890 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1891 " with value %s\n %s\n",
1892 argv
[1], argv
[2], win_errstr(werr
));
1898 if (!(W_ERROR_IS_OK(werr
))) {
1899 status
= werror_to_ntstatus(werr
);
1902 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1903 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1904 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
1910 static NTSTATUS
rpc_conf_delparm_internal(struct net_context
*c
,
1911 const struct dom_sid
*domain_sid
,
1912 const char *domain_name
,
1913 struct cli_state
*cli
,
1914 struct rpc_pipe_client
*pipe_hnd
,
1915 TALLOC_CTX
*mem_ctx
,
1919 TALLOC_CTX
*frame
= talloc_stackframe();
1920 NTSTATUS status
= NT_STATUS_OK
;
1921 WERROR werr
= WERR_OK
;
1924 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1927 struct policy_handle hive_hnd
, key_hnd
;
1930 ZERO_STRUCT(hive_hnd
);
1931 ZERO_STRUCT(key_hnd
);
1934 if (argc
!= 2 || c
->display_usage
) {
1935 rpc_conf_delparm_usage(c
, argc
, argv
);
1936 status
= NT_STATUS_INVALID_PARAMETER
;
1940 status
= rpc_conf_open_conf(frame
,
1947 if (!(NT_STATUS_IS_OK(status
))) {
1951 if (!(W_ERROR_IS_OK(werr
))) {
1955 status
= rpc_conf_del_value(frame
,
1964 if (!(W_ERROR_IS_OK(werr
))) {
1965 status
= werror_to_ntstatus(werr
);
1968 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1969 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1976 static NTSTATUS
rpc_conf_getincludes_internal(struct net_context
*c
,
1977 const struct dom_sid
*domain_sid
,
1978 const char *domain_name
,
1979 struct cli_state
*cli
,
1980 struct rpc_pipe_client
*pipe_hnd
,
1981 TALLOC_CTX
*mem_ctx
,
1985 TALLOC_CTX
*frame
= talloc_stackframe();
1986 NTSTATUS status
= NT_STATUS_OK
;
1987 WERROR werr
= WERR_OK
;
1990 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1993 struct policy_handle hive_hnd
, key_hnd
;
1994 struct smbconf_service
*service
= NULL
;
1996 uint32_t param_count
;
1999 ZERO_STRUCT(hive_hnd
);
2000 ZERO_STRUCT(key_hnd
);
2003 if (argc
!= 1 || c
->display_usage
) {
2004 rpc_conf_getincludes_usage(c
, argc
, argv
);
2005 status
= NT_STATUS_INVALID_PARAMETER
;
2009 status
= rpc_conf_open_conf(frame
,
2016 if (!(NT_STATUS_IS_OK(status
))) {
2020 if (!(W_ERROR_IS_OK(werr
))) {
2024 service
= talloc(frame
, struct smbconf_service
);
2026 status
= rpc_conf_get_share(frame
,
2033 if (!(NT_STATUS_IS_OK(status
))) {
2037 if (!(W_ERROR_IS_OK(werr
))) {
2041 for (param_count
= 0;
2042 param_count
< service
->num_params
;
2045 if (strcmp(service
->param_names
[param_count
], "include") == 0) {
2046 d_printf(_("%s = %s\n"),
2047 service
->param_names
[param_count
],
2048 service
->param_values
[param_count
]);
2054 if (!(W_ERROR_IS_OK(werr
))) {
2055 status
= werror_to_ntstatus(werr
);
2058 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
2059 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
2066 static NTSTATUS
rpc_conf_setincludes_internal(struct net_context
*c
,
2067 const struct dom_sid
*domain_sid
,
2068 const char *domain_name
,
2069 struct cli_state
*cli
,
2070 struct rpc_pipe_client
*pipe_hnd
,
2071 TALLOC_CTX
*mem_ctx
,
2075 TALLOC_CTX
*frame
= talloc_stackframe();
2076 NTSTATUS status
= NT_STATUS_OK
;
2077 WERROR werr
= WERR_OK
;
2080 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2083 struct policy_handle hive_hnd
, key_hnd
, share_hnd
;
2085 struct winreg_String key
, keyclass
;
2086 enum winreg_CreateAction action
= 0;
2088 ZERO_STRUCT(hive_hnd
);
2089 ZERO_STRUCT(key_hnd
);
2090 ZERO_STRUCT(share_hnd
);
2093 ZERO_STRUCT(keyclass
);
2095 if (argc
< 1 || c
->display_usage
) {
2096 rpc_conf_setincludes_usage(c
, argc
, argv
);
2097 status
= NT_STATUS_INVALID_PARAMETER
;
2101 status
= rpc_conf_open_conf(frame
,
2108 if (!(NT_STATUS_IS_OK(status
))) {
2112 if (!(W_ERROR_IS_OK(werr
))) {
2119 status
= dcerpc_winreg_CreateKey(b
, frame
, &key_hnd
, key
, keyclass
,
2120 0, REG_KEY_READ
, NULL
, &share_hnd
,
2123 if (!(NT_STATUS_IS_OK(status
))) {
2124 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
2125 argv
[0], nt_errstr(status
));
2129 if (!W_ERROR_IS_OK(werr
)) {
2130 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
2131 argv
[0], win_errstr(werr
));
2136 case REG_ACTION_NONE
:
2137 /* Is there any other way to treat this? */
2138 werr
= WERR_CREATE_FAILED
;
2139 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
2140 argv
[0], win_errstr(werr
));
2142 case REG_CREATED_NEW_KEY
:
2143 DEBUG(5, ("net rpc conf setincludes:"
2144 "createkey created %s\n", argv
[0]));
2146 case REG_OPENED_EXISTING_KEY
:
2147 DEBUG(5, ("net rpc conf setincludes:"
2148 "createkey opened existing %s\n", argv
[0]));
2150 /* delete posibly existing value */
2151 status
= rpc_conf_del_value(frame
,
2158 if (!(NT_STATUS_IS_OK(status
))) {
2162 if (!(W_ERROR_IS_OK(werr
))) {
2168 /* set the 'includes' values */
2169 status
= dcerpc_winreg_set_multi_sz(frame
, b
, &share_hnd
,
2170 "includes", argv
+ 1, &werr
);
2171 if (!(NT_STATUS_IS_OK(status
))) {
2172 d_fprintf(stderr
, "ERROR: Could not set includes\n %s\n",
2177 if (!(W_ERROR_IS_OK(werr
))) {
2178 d_fprintf(stderr
, "ERROR: Could not set includes\n %s\n",
2185 if (!(W_ERROR_IS_OK(werr
))) {
2186 status
= werror_to_ntstatus(werr
);
2189 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
2190 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
2191 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
2197 static NTSTATUS
rpc_conf_delincludes_internal(struct net_context
*c
,
2198 const struct dom_sid
*domain_sid
,
2199 const char *domain_name
,
2200 struct cli_state
*cli
,
2201 struct rpc_pipe_client
*pipe_hnd
,
2202 TALLOC_CTX
*mem_ctx
,
2206 TALLOC_CTX
*frame
= talloc_stackframe();
2207 NTSTATUS status
= NT_STATUS_OK
;
2208 WERROR werr
= WERR_OK
;
2211 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2214 struct policy_handle hive_hnd
, key_hnd
;
2217 ZERO_STRUCT(hive_hnd
);
2218 ZERO_STRUCT(key_hnd
);
2221 if (argc
!= 1 || c
->display_usage
) {
2222 rpc_conf_delincludes_usage(c
, argc
, argv
);
2223 status
= NT_STATUS_INVALID_PARAMETER
;
2227 status
= rpc_conf_open_conf(frame
,
2234 if (!(NT_STATUS_IS_OK(status
))) {
2238 if (!(W_ERROR_IS_OK(werr
))) {
2242 status
= rpc_conf_del_value(frame
,
2251 if (!(W_ERROR_IS_OK(werr
))) {
2252 status
= werror_to_ntstatus(werr
);
2255 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
2256 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
2263 /**********************************************************
2265 * Functions that run the rpc commands for net rpc conf modules
2267 **********************************************************/
2269 static int rpc_conf_drop(struct net_context
*c
, int argc
,
2272 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2273 rpc_conf_drop_internal
, argc
, argv
);
2277 static int rpc_conf_showshare(struct net_context
*c
, int argc
,
2280 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2281 rpc_conf_showshare_internal
, argc
, argv
);
2284 static int rpc_conf_addshare(struct net_context
*c
, int argc
,
2287 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2288 rpc_conf_addshare_internal
, argc
, argv
);
2291 static int rpc_conf_listshares(struct net_context
*c
, int argc
,
2294 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2295 rpc_conf_listshares_internal
, argc
, argv
);
2298 static int rpc_conf_list(struct net_context
*c
, int argc
,
2301 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2302 rpc_conf_list_internal
, argc
, argv
);
2305 static int rpc_conf_import(struct net_context
*c
, int argc
,
2308 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2309 rpc_conf_import_internal
, argc
, argv
);
2311 static int rpc_conf_delshare(struct net_context
*c
, int argc
,
2314 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2315 rpc_conf_delshare_internal
, argc
, argv
);
2318 static int rpc_conf_getparm(struct net_context
*c
, int argc
,
2321 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2322 rpc_conf_getparm_internal
, argc
, argv
);
2325 static int rpc_conf_setparm(struct net_context
*c
, int argc
,
2328 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2329 rpc_conf_setparm_internal
, argc
, argv
);
2331 static int rpc_conf_delparm(struct net_context
*c
, int argc
,
2334 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2335 rpc_conf_delparm_internal
, argc
, argv
);
2338 static int rpc_conf_getincludes(struct net_context
*c
, int argc
,
2341 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2342 rpc_conf_getincludes_internal
, argc
, argv
);
2345 static int rpc_conf_setincludes(struct net_context
*c
, int argc
,
2348 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2349 rpc_conf_setincludes_internal
, argc
, argv
);
2352 static int rpc_conf_delincludes(struct net_context
*c
, int argc
,
2355 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2356 rpc_conf_delincludes_internal
, argc
, argv
);
2359 /* function calls */
2360 int net_rpc_conf(struct net_context
*c
, int argc
,
2363 struct functable func_table
[] = {
2368 N_("Dump the complete remote configuration in smb.conf like "
2370 N_("net rpc conf list\n"
2371 " Dump the complete remote configuration in smb.conf "
2379 N_("Import configuration from file in smb.conf "
2381 N_("net rpc conf import\n"
2382 " Import configuration from file in smb.conf "
2387 rpc_conf_listshares
,
2389 N_("List the remote share names."),
2390 N_("net rpc conf list\n"
2391 " List the remote share names.")
2398 N_("Delete the complete remote configuration."),
2399 N_("net rpc conf drop\n"
2400 " Delete the complete remote configuration.")
2407 N_("Show the definition of a remote share."),
2408 N_("net rpc conf showshare\n"
2409 " Show the definition of a remote share.")
2416 N_("Create a new remote share."),
2417 N_("net rpc conf addshare\n"
2418 " Create a new remote share.")
2424 N_("Delete a remote share."),
2425 N_("net rpc conf delshare\n"
2426 " Delete a remote share.")
2432 N_("Retrieve the value of a parameter."),
2433 N_("net rpc conf getparm\n"
2434 " Retrieve the value of a parameter.")
2440 N_("Store a parameter."),
2441 N_("net rpc conf setparm\n"
2442 " Store a parameter.")
2448 N_("Delete a parameter."),
2449 N_("net rpc conf delparm\n"
2450 " Delete a parameter.")
2454 rpc_conf_getincludes
,
2456 N_("Show the includes of a share definition."),
2457 N_("net rpc conf getincludes\n"
2458 " Show the includes of a share definition.")
2462 rpc_conf_setincludes
,
2464 N_("Set includes for a share."),
2465 N_("net rpc conf setincludes\n"
2466 " Set includes for a share.")
2470 rpc_conf_delincludes
,
2472 N_("Delete includes from a share definition."),
2473 N_("net rpc conf delincludes\n"
2474 " Delete includes from a share definition.")
2476 {NULL
, NULL
, 0, NULL
, NULL
}
2479 return net_run_function(c
, argc
, argv
, "net rpc conf", func_table
);