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
= { 0, };
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
));
1088 wkey
.name
= keyname
;
1089 ZERO_STRUCT(wkeyclass
);
1090 wkeyclass
.name
= "";
1091 action
= REG_ACTION_NONE
;
1093 status
= dcerpc_winreg_CreateKey(b
,
1105 if (!NT_STATUS_IS_OK(status
)) {
1106 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1110 if (!W_ERROR_IS_OK(werr
)) {
1111 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1117 if (!(W_ERROR_IS_OK(werr
))) {
1118 status
= werror_to_ntstatus(werr
);
1121 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1122 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1128 static NTSTATUS
rpc_conf_import_internal(struct net_context
*c
,
1129 const struct dom_sid
*domain_sid
,
1130 const char *domain_name
,
1131 struct cli_state
*cli
,
1132 struct rpc_pipe_client
*pipe_hnd
,
1133 TALLOC_CTX
*mem_ctx
,
1138 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1140 struct policy_handle hive_hnd
, key_hnd
;
1142 const char *filename
= NULL
;
1143 const char *servicename
= NULL
;
1144 char *conf_source
= NULL
;
1146 struct smbconf_ctx
*txt_ctx
;
1147 struct smbconf_service
*service
= NULL
;
1148 struct smbconf_service
**services
= NULL
;
1149 uint32_t num_shares
, i
;
1150 sbcErr err
= SBC_ERR_UNKNOWN_FAILURE
;
1152 WERROR werr
= WERR_OK
;
1153 NTSTATUS status
= NT_STATUS_OK
;
1155 ZERO_STRUCT(hive_hnd
);
1156 ZERO_STRUCT(key_hnd
);
1158 frame
= talloc_stackframe();
1160 if (c
->display_usage
) {
1161 rpc_conf_import_usage(c
, argc
, argv
);
1162 status
= NT_STATUS_INVALID_PARAMETER
;
1169 rpc_conf_import_usage(c
, argc
, argv
);
1170 status
= NT_STATUS_INVALID_PARAMETER
;
1173 servicename
= talloc_strdup(frame
, argv
[1]);
1174 if (servicename
== NULL
) {
1175 d_printf(_("error: out of memory!\n"));
1183 DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1186 conf_source
= talloc_asprintf(frame
, "file:%s", filename
);
1187 if (conf_source
== NULL
) {
1188 d_fprintf(stderr
, _("error: out of memory!\n"));
1192 err
= smbconf_init(frame
, &txt_ctx
, conf_source
);
1193 if (!SBC_ERROR_IS_OK(err
)) {
1194 d_fprintf(stderr
, _("error loading file '%s': %s\n"), filename
,
1195 sbcErrorString(err
));
1199 if (c
->opt_testmode
) {
1200 d_printf(_("\nTEST MODE - "
1201 "would import the following configuration:\n\n"));
1204 if (servicename
!= NULL
) {
1205 err
= smbconf_get_share(txt_ctx
, frame
,
1208 if (!SBC_ERROR_IS_OK(err
)) {
1216 err
= smbconf_get_config(txt_ctx
, frame
,
1219 if (!SBC_ERROR_IS_OK(err
)) {
1224 if (c
->opt_testmode
) {
1225 if (servicename
!= NULL
) {
1226 rpc_conf_print_shares(1, service
);
1228 for (i
= 0; i
< num_shares
; i
++) {
1229 rpc_conf_print_shares(1, services
[i
]);
1234 status
= rpc_conf_drop_internal(c
,
1243 if (!(NT_STATUS_IS_OK(status
))) {
1247 status
= rpc_conf_open_conf(frame
,
1254 if (!(NT_STATUS_IS_OK(status
))) {
1258 if (!(W_ERROR_IS_OK(werr
))) {
1262 if (servicename
!= NULL
) {
1263 status
= rpc_conf_set_share(frame
,
1269 if (!(NT_STATUS_IS_OK(status
))) {
1273 if (!(W_ERROR_IS_OK(werr
))) {
1279 for (i
= 0; i
< num_shares
; i
++) {
1280 status
= rpc_conf_set_share(frame
,
1286 if (!(NT_STATUS_IS_OK(status
))) {
1290 if (!(W_ERROR_IS_OK(werr
))) {
1298 if (!SBC_ERROR_IS_OK(err
)) {
1299 d_fprintf(stderr
, "ERROR: %s\n", sbcErrorString(err
));
1302 if (!(W_ERROR_IS_OK(werr
))) {
1303 status
= werror_to_ntstatus(werr
);
1309 static NTSTATUS
rpc_conf_showshare_internal(struct net_context
*c
,
1310 const struct dom_sid
*domain_sid
,
1311 const char *domain_name
,
1312 struct cli_state
*cli
,
1313 struct rpc_pipe_client
*pipe_hnd
,
1314 TALLOC_CTX
*mem_ctx
,
1318 TALLOC_CTX
*frame
= talloc_stackframe();
1319 NTSTATUS status
= NT_STATUS_OK
;
1320 WERROR werr
= WERR_OK
;
1323 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1326 struct policy_handle hive_hnd
, key_hnd
;
1327 struct smbconf_service
*service
= NULL
;
1328 const char *sharename
= NULL
;
1331 ZERO_STRUCT(hive_hnd
);
1332 ZERO_STRUCT(key_hnd
);
1335 if (argc
!= 1 || c
->display_usage
) {
1336 rpc_conf_showshare_usage(c
, argc
, argv
);
1337 status
= NT_STATUS_INVALID_PARAMETER
;
1341 status
= rpc_conf_open_conf(frame
,
1348 if (!(NT_STATUS_IS_OK(status
))) {
1352 if (!(W_ERROR_IS_OK(werr
))) {
1356 sharename
= talloc_strdup(frame
, argv
[0]);
1357 if (sharename
== NULL
) {
1359 d_fprintf(stderr
, _("Failed to create share: %s\n"),
1364 service
= talloc(frame
, struct smbconf_service
);
1365 if (service
== NULL
) {
1367 d_fprintf(stderr
, _("Failed to create share: %s\n"),
1372 status
= rpc_conf_get_share(frame
,
1379 if (!(NT_STATUS_IS_OK(status
))) {
1382 if (!(W_ERROR_IS_OK(werr
))) {
1386 rpc_conf_print_shares(1, service
);
1389 if (!(W_ERROR_IS_OK(werr
))) {
1390 status
= werror_to_ntstatus(werr
);
1393 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1394 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1400 static NTSTATUS
rpc_conf_addshare_internal(struct net_context
*c
,
1401 const struct dom_sid
*domain_sid
,
1402 const char *domain_name
,
1403 struct cli_state
*cli
,
1404 struct rpc_pipe_client
*pipe_hnd
,
1405 TALLOC_CTX
*mem_ctx
,
1409 TALLOC_CTX
*frame
= talloc_stackframe();
1410 NTSTATUS status
= NT_STATUS_OK
;
1411 WERROR werr
= WERR_OK
;
1414 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1417 struct policy_handle hive_hnd
, key_hnd
, share_hnd
;
1418 char *sharename
= NULL
;
1419 const char *path
= NULL
;
1420 const char *comment
= NULL
;
1421 const char *guest_ok
= "no";
1422 const char *read_only
= "yes";
1423 struct winreg_String key
, keyclass
;
1424 enum winreg_CreateAction action
= 0;
1427 ZERO_STRUCT(hive_hnd
);
1428 ZERO_STRUCT(key_hnd
);
1429 ZERO_STRUCT(share_hnd
);
1432 ZERO_STRUCT(keyclass
);
1434 if (c
->display_usage
) {
1435 rpc_conf_addshare_usage(c
, argc
, argv
);
1436 status
= NT_STATUS_INVALID_PARAMETER
;
1444 rpc_conf_addshare_usage(c
, argc
, argv
);
1445 status
= NT_STATUS_INVALID_PARAMETER
;
1450 if (!strnequal(argv
[3], "guest_ok=", 9)) {
1451 rpc_conf_addshare_usage(c
, argc
, argv
);
1452 status
= NT_STATUS_INVALID_PARAMETER
;
1455 switch (argv
[3][9]) {
1465 rpc_conf_addshare_usage(c
, argc
, argv
);
1466 status
= NT_STATUS_INVALID_PARAMETER
;
1470 if (!strnequal(argv
[2], "writeable=", 10)) {
1471 rpc_conf_addshare_usage(c
, argc
, argv
);
1472 status
= NT_STATUS_INVALID_PARAMETER
;
1475 switch (argv
[2][10]) {
1485 rpc_conf_addshare_usage(c
, argc
, argv
);
1486 status
= NT_STATUS_INVALID_PARAMETER
;
1491 sharename
= talloc_strdup(frame
, argv
[0]);
1492 if (sharename
== NULL
) {
1493 d_printf(_("error: out of memory!\n"));
1500 status
= rpc_conf_open_conf(frame
,
1507 if (!(NT_STATUS_IS_OK(status
))) {
1511 if (!(W_ERROR_IS_OK(werr
))) {
1518 status
= dcerpc_winreg_CreateKey(b
, frame
, &key_hnd
, key
, keyclass
,
1519 0, REG_KEY_READ
, NULL
, &share_hnd
,
1522 if (!(NT_STATUS_IS_OK(status
))) {
1523 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1524 argv
[0], nt_errstr(status
));
1528 if (!W_ERROR_IS_OK(werr
)) {
1529 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1530 argv
[0], win_errstr(werr
));
1535 case REG_ACTION_NONE
:
1536 werr
= WERR_CREATE_FAILED
;
1537 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1538 argv
[0], win_errstr(werr
));
1540 case REG_CREATED_NEW_KEY
:
1541 DEBUG(5, ("net rpc conf setincludes:"
1542 "createkey created %s\n", argv
[0]));
1544 case REG_OPENED_EXISTING_KEY
:
1545 d_fprintf(stderr
, _("ERROR: Share '%s' already exists\n"), argv
[0]);
1546 status
= NT_STATUS_INVALID_PARAMETER
;
1550 /* set the path parameter */
1551 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1552 "path", path
, &werr
);
1554 if (!(NT_STATUS_IS_OK(status
))) {
1555 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1556 " with value %s\n %s\n",
1557 "path", path
, nt_errstr(status
));
1561 if (!(W_ERROR_IS_OK(werr
))) {
1562 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1563 " with value %s\n %s\n",
1564 "path", path
, win_errstr(werr
));
1568 /* set the writeable parameter */
1569 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1570 "read only", read_only
, &werr
);
1572 if (!(NT_STATUS_IS_OK(status
))) {
1573 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1574 " with value %s\n %s\n",
1575 "read only", read_only
, nt_errstr(status
));
1579 if (!(W_ERROR_IS_OK(werr
))) {
1580 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1581 " with value %s\n %s\n",
1582 "read only", read_only
, win_errstr(werr
));
1586 /* set the guest ok parameter */
1587 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1588 "guest ok", guest_ok
, &werr
);
1590 if (!(NT_STATUS_IS_OK(status
))) {
1591 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1592 " with value %s\n %s\n",
1593 "guest ok", guest_ok
, nt_errstr(status
));
1597 if (!(W_ERROR_IS_OK(werr
))) {
1598 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1599 " with value %s\n %s\n",
1600 "guest ok", guest_ok
, win_errstr(werr
));
1605 /* set the comment parameter */
1606 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1607 "comment", comment
, &werr
);
1609 if (!(NT_STATUS_IS_OK(status
))) {
1610 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1611 " with value %s\n %s\n",
1612 "comment", comment
, nt_errstr(status
));
1616 if (!(W_ERROR_IS_OK(werr
))) {
1617 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1618 " with value %s\n %s\n",
1619 "comment", comment
, win_errstr(werr
));
1624 if (!(W_ERROR_IS_OK(werr
))) {
1625 status
= werror_to_ntstatus(werr
);
1628 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1629 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1630 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
1636 static NTSTATUS
rpc_conf_getparm_internal(struct net_context
*c
,
1637 const struct dom_sid
*domain_sid
,
1638 const char *domain_name
,
1639 struct cli_state
*cli
,
1640 struct rpc_pipe_client
*pipe_hnd
,
1641 TALLOC_CTX
*mem_ctx
,
1645 TALLOC_CTX
*frame
= talloc_stackframe();
1646 NTSTATUS status
= NT_STATUS_OK
;
1647 WERROR werr
= WERR_OK
;
1650 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1653 struct policy_handle hive_hnd
, key_hnd
;
1654 struct smbconf_service
*service
= NULL
;
1656 bool param_is_set
= false;
1657 uint32_t param_count
;
1659 ZERO_STRUCT(hive_hnd
);
1660 ZERO_STRUCT(key_hnd
);
1663 if (argc
!= 2 || c
->display_usage
) {
1664 rpc_conf_getparm_usage(c
, argc
, argv
);
1665 status
= NT_STATUS_INVALID_PARAMETER
;
1669 status
= rpc_conf_open_conf(frame
,
1676 if (!(NT_STATUS_IS_OK(status
))) {
1680 if (!(W_ERROR_IS_OK(werr
))) {
1685 service
= talloc(frame
, struct smbconf_service
);
1687 status
= rpc_conf_get_share(frame
,
1694 if (!(NT_STATUS_IS_OK(status
))) {
1698 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)) {
1699 d_fprintf(stderr
, _("ERROR: Share %s does not exist\n"),
1704 if (!(W_ERROR_IS_OK(werr
))) {
1708 for (param_count
= 0;
1709 param_count
< service
->num_params
;
1712 /* should includes also be printed? */
1713 if (strcmp(service
->param_names
[param_count
], argv
[1]) == 0) {
1715 service
->param_values
[param_count
]);
1716 param_is_set
= true;
1720 if (!param_is_set
) {
1721 d_fprintf(stderr
, _("ERROR: Given parameter '%s' has not been set\n"),
1723 werr
= WERR_BADFILE
;
1729 if (!(W_ERROR_IS_OK(werr
))) {
1730 status
= werror_to_ntstatus(werr
);
1733 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1734 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1741 static NTSTATUS
rpc_conf_setparm_internal(struct net_context
*c
,
1742 const struct dom_sid
*domain_sid
,
1743 const char *domain_name
,
1744 struct cli_state
*cli
,
1745 struct rpc_pipe_client
*pipe_hnd
,
1746 TALLOC_CTX
*mem_ctx
,
1750 TALLOC_CTX
*frame
= talloc_stackframe();
1751 NTSTATUS status
= NT_STATUS_OK
;
1752 WERROR werr
= WERR_OK
;
1755 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1758 struct policy_handle hive_hnd
, key_hnd
, share_hnd
;
1760 struct winreg_String key
, keyclass
;
1761 enum winreg_CreateAction action
= 0;
1763 const char *canon_valname
;
1764 const char *canon_valstr
;
1766 ZERO_STRUCT(hive_hnd
);
1767 ZERO_STRUCT(key_hnd
);
1768 ZERO_STRUCT(share_hnd
);
1771 ZERO_STRUCT(keyclass
);
1773 if (argc
!= 3 || c
->display_usage
) {
1774 rpc_conf_setparm_usage(c
, argc
, argv
);
1775 status
= NT_STATUS_INVALID_PARAMETER
;
1779 status
= rpc_conf_open_conf(frame
,
1786 if (!(NT_STATUS_IS_OK(status
))) {
1790 if (!(W_ERROR_IS_OK(werr
))) {
1797 status
= dcerpc_winreg_CreateKey(b
, frame
, &key_hnd
, key
, keyclass
,
1798 0, REG_KEY_READ
, NULL
, &share_hnd
,
1801 if (!(NT_STATUS_IS_OK(status
))) {
1802 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1803 argv
[0], nt_errstr(status
));
1807 if (!W_ERROR_IS_OK(werr
)) {
1808 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1809 argv
[0], win_errstr(werr
));
1814 case REG_ACTION_NONE
:
1815 werr
= WERR_CREATE_FAILED
;
1816 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
1817 argv
[0], win_errstr(werr
));
1819 case REG_CREATED_NEW_KEY
:
1820 DEBUG(5, ("net rpc conf setparm:"
1821 "createkey created %s\n", argv
[0]));
1823 case REG_OPENED_EXISTING_KEY
:
1824 DEBUG(5, ("net rpc conf setparm:"
1825 "createkey opened existing %s\n", argv
[0]));
1827 /* delete posibly existing value */
1828 status
= rpc_conf_del_value(frame
,
1835 if (!(NT_STATUS_IS_OK(status
))) {
1839 if (!(W_ERROR_IS_OK(werr
))) {
1846 /* check if parameter is valid for writing */
1847 if (!lp_canonicalize_parameter_with_value(argv
[1], argv
[2],
1851 if (canon_valname
== NULL
) {
1852 d_fprintf(stderr
, "invalid parameter '%s' given\n",
1855 d_fprintf(stderr
, "invalid value '%s' given for "
1856 "parameter '%s'\n", argv
[1], argv
[2]);
1858 werr
= WERR_INVALID_PARAM
;
1862 if (rpc_conf_reg_valname_forbidden(canon_valname
)) {
1863 d_fprintf(stderr
, "Parameter '%s' not allowed in registry.\n",
1865 werr
= WERR_INVALID_PARAM
;
1869 if (!strequal(argv
[0], "global") &&
1870 lp_parameter_is_global(argv
[1]))
1872 d_fprintf(stderr
, "Global parameter '%s' not allowed in "
1873 "service definition ('%s').\n", canon_valname
,
1875 werr
= WERR_INVALID_PARAM
;
1879 /* set the parameter */
1880 status
= dcerpc_winreg_set_sz(frame
, b
, &share_hnd
,
1881 argv
[1], argv
[2], &werr
);
1883 if (!(NT_STATUS_IS_OK(status
))) {
1884 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1885 " with value %s\n %s\n",
1886 argv
[1], argv
[2], nt_errstr(status
));
1890 if (!(W_ERROR_IS_OK(werr
))) {
1891 d_fprintf(stderr
, "ERROR: Could not set parameter '%s'"
1892 " with value %s\n %s\n",
1893 argv
[1], argv
[2], win_errstr(werr
));
1899 if (!(W_ERROR_IS_OK(werr
))) {
1900 status
= werror_to_ntstatus(werr
);
1903 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1904 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1905 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
1911 static NTSTATUS
rpc_conf_delparm_internal(struct net_context
*c
,
1912 const struct dom_sid
*domain_sid
,
1913 const char *domain_name
,
1914 struct cli_state
*cli
,
1915 struct rpc_pipe_client
*pipe_hnd
,
1916 TALLOC_CTX
*mem_ctx
,
1920 TALLOC_CTX
*frame
= talloc_stackframe();
1921 NTSTATUS status
= NT_STATUS_OK
;
1922 WERROR werr
= WERR_OK
;
1925 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1928 struct policy_handle hive_hnd
, key_hnd
;
1931 ZERO_STRUCT(hive_hnd
);
1932 ZERO_STRUCT(key_hnd
);
1935 if (argc
!= 2 || c
->display_usage
) {
1936 rpc_conf_delparm_usage(c
, argc
, argv
);
1937 status
= NT_STATUS_INVALID_PARAMETER
;
1941 status
= rpc_conf_open_conf(frame
,
1948 if (!(NT_STATUS_IS_OK(status
))) {
1952 if (!(W_ERROR_IS_OK(werr
))) {
1956 status
= rpc_conf_del_value(frame
,
1965 if (!(W_ERROR_IS_OK(werr
))) {
1966 status
= werror_to_ntstatus(werr
);
1969 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
1970 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
1977 static NTSTATUS
rpc_conf_getincludes_internal(struct net_context
*c
,
1978 const struct dom_sid
*domain_sid
,
1979 const char *domain_name
,
1980 struct cli_state
*cli
,
1981 struct rpc_pipe_client
*pipe_hnd
,
1982 TALLOC_CTX
*mem_ctx
,
1986 TALLOC_CTX
*frame
= talloc_stackframe();
1987 NTSTATUS status
= NT_STATUS_OK
;
1988 WERROR werr
= WERR_OK
;
1991 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1994 struct policy_handle hive_hnd
, key_hnd
;
1995 struct smbconf_service
*service
= NULL
;
1997 uint32_t param_count
;
2000 ZERO_STRUCT(hive_hnd
);
2001 ZERO_STRUCT(key_hnd
);
2004 if (argc
!= 1 || c
->display_usage
) {
2005 rpc_conf_getincludes_usage(c
, argc
, argv
);
2006 status
= NT_STATUS_INVALID_PARAMETER
;
2010 status
= rpc_conf_open_conf(frame
,
2017 if (!(NT_STATUS_IS_OK(status
))) {
2021 if (!(W_ERROR_IS_OK(werr
))) {
2025 service
= talloc(frame
, struct smbconf_service
);
2027 status
= rpc_conf_get_share(frame
,
2034 if (!(NT_STATUS_IS_OK(status
))) {
2038 if (!(W_ERROR_IS_OK(werr
))) {
2042 for (param_count
= 0;
2043 param_count
< service
->num_params
;
2046 if (strcmp(service
->param_names
[param_count
], "include") == 0) {
2047 d_printf(_("%s = %s\n"),
2048 service
->param_names
[param_count
],
2049 service
->param_values
[param_count
]);
2055 if (!(W_ERROR_IS_OK(werr
))) {
2056 status
= werror_to_ntstatus(werr
);
2059 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
2060 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
2067 static NTSTATUS
rpc_conf_setincludes_internal(struct net_context
*c
,
2068 const struct dom_sid
*domain_sid
,
2069 const char *domain_name
,
2070 struct cli_state
*cli
,
2071 struct rpc_pipe_client
*pipe_hnd
,
2072 TALLOC_CTX
*mem_ctx
,
2076 TALLOC_CTX
*frame
= talloc_stackframe();
2077 NTSTATUS status
= NT_STATUS_OK
;
2078 WERROR werr
= WERR_OK
;
2081 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2084 struct policy_handle hive_hnd
, key_hnd
, share_hnd
;
2086 struct winreg_String key
, keyclass
;
2087 enum winreg_CreateAction action
= 0;
2089 ZERO_STRUCT(hive_hnd
);
2090 ZERO_STRUCT(key_hnd
);
2091 ZERO_STRUCT(share_hnd
);
2094 ZERO_STRUCT(keyclass
);
2096 if (argc
< 1 || c
->display_usage
) {
2097 rpc_conf_setincludes_usage(c
, argc
, argv
);
2098 status
= NT_STATUS_INVALID_PARAMETER
;
2102 status
= rpc_conf_open_conf(frame
,
2109 if (!(NT_STATUS_IS_OK(status
))) {
2113 if (!(W_ERROR_IS_OK(werr
))) {
2120 status
= dcerpc_winreg_CreateKey(b
, frame
, &key_hnd
, key
, keyclass
,
2121 0, REG_KEY_READ
, NULL
, &share_hnd
,
2124 if (!(NT_STATUS_IS_OK(status
))) {
2125 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
2126 argv
[0], nt_errstr(status
));
2130 if (!W_ERROR_IS_OK(werr
)) {
2131 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
2132 argv
[0], win_errstr(werr
));
2137 case REG_ACTION_NONE
:
2138 /* Is there any other way to treat this? */
2139 werr
= WERR_CREATE_FAILED
;
2140 d_fprintf(stderr
, _("ERROR: Could not create share key '%s'\n%s\n"),
2141 argv
[0], win_errstr(werr
));
2143 case REG_CREATED_NEW_KEY
:
2144 DEBUG(5, ("net rpc conf setincludes:"
2145 "createkey created %s\n", argv
[0]));
2147 case REG_OPENED_EXISTING_KEY
:
2148 DEBUG(5, ("net rpc conf setincludes:"
2149 "createkey opened existing %s\n", argv
[0]));
2151 /* delete posibly existing value */
2152 status
= rpc_conf_del_value(frame
,
2159 if (!(NT_STATUS_IS_OK(status
))) {
2163 if (!(W_ERROR_IS_OK(werr
))) {
2169 /* set the 'includes' values */
2170 status
= dcerpc_winreg_set_multi_sz(frame
, b
, &share_hnd
,
2171 "includes", argv
+ 1, &werr
);
2172 if (!(NT_STATUS_IS_OK(status
))) {
2173 d_fprintf(stderr
, "ERROR: Could not set includes\n %s\n",
2178 if (!(W_ERROR_IS_OK(werr
))) {
2179 d_fprintf(stderr
, "ERROR: Could not set includes\n %s\n",
2186 if (!(W_ERROR_IS_OK(werr
))) {
2187 status
= werror_to_ntstatus(werr
);
2190 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
2191 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
2192 dcerpc_winreg_CloseKey(b
, frame
, &share_hnd
, &_werr
);
2198 static NTSTATUS
rpc_conf_delincludes_internal(struct net_context
*c
,
2199 const struct dom_sid
*domain_sid
,
2200 const char *domain_name
,
2201 struct cli_state
*cli
,
2202 struct rpc_pipe_client
*pipe_hnd
,
2203 TALLOC_CTX
*mem_ctx
,
2207 TALLOC_CTX
*frame
= talloc_stackframe();
2208 NTSTATUS status
= NT_STATUS_OK
;
2209 WERROR werr
= WERR_OK
;
2212 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2215 struct policy_handle hive_hnd
, key_hnd
;
2218 ZERO_STRUCT(hive_hnd
);
2219 ZERO_STRUCT(key_hnd
);
2222 if (argc
!= 1 || c
->display_usage
) {
2223 rpc_conf_delincludes_usage(c
, argc
, argv
);
2224 status
= NT_STATUS_INVALID_PARAMETER
;
2228 status
= rpc_conf_open_conf(frame
,
2235 if (!(NT_STATUS_IS_OK(status
))) {
2239 if (!(W_ERROR_IS_OK(werr
))) {
2243 status
= rpc_conf_del_value(frame
,
2252 if (!(W_ERROR_IS_OK(werr
))) {
2253 status
= werror_to_ntstatus(werr
);
2256 dcerpc_winreg_CloseKey(b
, frame
, &hive_hnd
, &_werr
);
2257 dcerpc_winreg_CloseKey(b
, frame
, &key_hnd
, &_werr
);
2264 /**********************************************************
2266 * Functions that run the rpc commands for net rpc conf modules
2268 **********************************************************/
2270 static int rpc_conf_drop(struct net_context
*c
, int argc
,
2273 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2274 rpc_conf_drop_internal
, argc
, argv
);
2278 static int rpc_conf_showshare(struct net_context
*c
, int argc
,
2281 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2282 rpc_conf_showshare_internal
, argc
, argv
);
2285 static int rpc_conf_addshare(struct net_context
*c
, int argc
,
2288 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2289 rpc_conf_addshare_internal
, argc
, argv
);
2292 static int rpc_conf_listshares(struct net_context
*c
, int argc
,
2295 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2296 rpc_conf_listshares_internal
, argc
, argv
);
2299 static int rpc_conf_list(struct net_context
*c
, int argc
,
2302 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2303 rpc_conf_list_internal
, argc
, argv
);
2306 static int rpc_conf_import(struct net_context
*c
, int argc
,
2309 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2310 rpc_conf_import_internal
, argc
, argv
);
2312 static int rpc_conf_delshare(struct net_context
*c
, int argc
,
2315 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2316 rpc_conf_delshare_internal
, argc
, argv
);
2319 static int rpc_conf_getparm(struct net_context
*c
, int argc
,
2322 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2323 rpc_conf_getparm_internal
, argc
, argv
);
2326 static int rpc_conf_setparm(struct net_context
*c
, int argc
,
2329 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2330 rpc_conf_setparm_internal
, argc
, argv
);
2332 static int rpc_conf_delparm(struct net_context
*c
, int argc
,
2335 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2336 rpc_conf_delparm_internal
, argc
, argv
);
2339 static int rpc_conf_getincludes(struct net_context
*c
, int argc
,
2342 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2343 rpc_conf_getincludes_internal
, argc
, argv
);
2346 static int rpc_conf_setincludes(struct net_context
*c
, int argc
,
2349 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2350 rpc_conf_setincludes_internal
, argc
, argv
);
2353 static int rpc_conf_delincludes(struct net_context
*c
, int argc
,
2356 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
2357 rpc_conf_delincludes_internal
, argc
, argv
);
2360 /* function calls */
2361 int net_rpc_conf(struct net_context
*c
, int argc
,
2364 struct functable func_table
[] = {
2369 N_("Dump the complete remote configuration in smb.conf like "
2371 N_("net rpc conf list\n"
2372 " Dump the complete remote configuration in smb.conf "
2380 N_("Import configuration from file in smb.conf "
2382 N_("net rpc conf import\n"
2383 " Import configuration from file in smb.conf "
2388 rpc_conf_listshares
,
2390 N_("List the remote share names."),
2391 N_("net rpc conf list\n"
2392 " List the remote share names.")
2399 N_("Delete the complete remote configuration."),
2400 N_("net rpc conf drop\n"
2401 " Delete the complete remote configuration.")
2408 N_("Show the definition of a remote share."),
2409 N_("net rpc conf showshare\n"
2410 " Show the definition of a remote share.")
2417 N_("Create a new remote share."),
2418 N_("net rpc conf addshare\n"
2419 " Create a new remote share.")
2425 N_("Delete a remote share."),
2426 N_("net rpc conf delshare\n"
2427 " Delete a remote share.")
2433 N_("Retrieve the value of a parameter."),
2434 N_("net rpc conf getparm\n"
2435 " Retrieve the value of a parameter.")
2441 N_("Store a parameter."),
2442 N_("net rpc conf setparm\n"
2443 " Store a parameter.")
2449 N_("Delete a parameter."),
2450 N_("net rpc conf delparm\n"
2451 " Delete a parameter.")
2455 rpc_conf_getincludes
,
2457 N_("Show the includes of a share definition."),
2458 N_("net rpc conf getincludes\n"
2459 " Show the includes of a share definition.")
2463 rpc_conf_setincludes
,
2465 N_("Set includes for a share."),
2466 N_("net rpc conf setincludes\n"
2467 " Set includes for a share.")
2471 rpc_conf_delincludes
,
2473 N_("Delete includes from a share definition."),
2474 N_("net rpc conf delincludes\n"
2475 " Delete includes from a share definition.")
2477 {NULL
, NULL
, 0, NULL
, NULL
}
2480 return net_run_function(c
, argc
, argv
, "net rpc conf", func_table
);