582
582
/********************************************************************
583
583
********************************************************************/
585
static NTSTATUS rpc_service_delete_internal(struct net_context *c,
586
const DOM_SID *domain_sid,
587
const char *domain_name,
588
struct cli_state *cli,
589
struct rpc_pipe_client *pipe_hnd,
594
struct policy_handle hSCM, hService;
595
WERROR result = WERR_GENERAL_FAILURE;
599
d_printf("Usage: net rpc service delete <service>\n");
603
/* Open the Service Control Manager */
604
status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
605
pipe_hnd->srv_name_slash,
607
SC_RIGHT_MGR_ENUMERATE_SERVICE,
610
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
611
d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n",
613
return werror_to_ntstatus(result);
616
/* Open the Service */
618
status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
625
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
626
d_fprintf(stderr, "Failed to open service. [%s]\n",
631
/* Delete the Service */
633
status = rpccli_svcctl_DeleteService(pipe_hnd, mem_ctx,
637
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
638
d_fprintf(stderr, "Delete service request failed. [%s]\n",
643
d_printf("Successfully deleted Service: %s\n", argv[0]);
646
if (is_valid_policy_hnd(&hService)) {
647
rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
649
if (is_valid_policy_hnd(&hSCM)) {
650
rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
653
return werror_to_ntstatus(result);
656
/********************************************************************
657
********************************************************************/
659
static NTSTATUS rpc_service_create_internal(struct net_context *c,
660
const DOM_SID *domain_sid,
661
const char *domain_name,
662
struct cli_state *cli,
663
struct rpc_pipe_client *pipe_hnd,
668
struct policy_handle hSCM, hService;
669
WERROR result = WERR_GENERAL_FAILURE;
671
const char *ServiceName;
672
const char *DisplayName;
673
const char *binary_path;
676
d_printf("Usage: net rpc service create <service> <displayname> <binarypath>\n");
680
/* Open the Service Control Manager */
681
status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
682
pipe_hnd->srv_name_slash,
684
SC_RIGHT_MGR_CREATE_SERVICE,
687
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
688
d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n",
690
return werror_to_ntstatus(result);
693
/* Create the service */
695
ServiceName = argv[0];
696
DisplayName = argv[1];
697
binary_path = argv[2];
699
status = rpccli_svcctl_CreateServiceW(pipe_hnd, mem_ctx,
704
SERVICE_TYPE_WIN32_OWN_PROCESS,
706
SVCCTL_SVC_ERROR_NORMAL,
708
NULL, /* LoadOrderGroupKey */
710
NULL, /* dependencies */
711
0, /* dependencies_size */
712
NULL, /* service_start_name */
714
0, /* password_size */
718
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
719
d_fprintf(stderr, "Create service request failed. [%s]\n",
724
d_printf("Successfully created Service: %s\n", argv[0]);
727
if (is_valid_policy_hnd(&hService)) {
728
rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
730
if (is_valid_policy_hnd(&hSCM)) {
731
rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
734
return werror_to_ntstatus(result);
737
/********************************************************************
738
********************************************************************/
585
740
static int rpc_service_list(struct net_context *c, int argc, const char **argv )
587
742
if (c->display_usage) {
678
833
/********************************************************************
679
834
********************************************************************/
836
static int rpc_service_delete(struct net_context *c, int argc, const char **argv)
838
if (c->display_usage) {
840
"net rpc service delete <service>\n"
841
" Delete a Win32 service\n");
845
return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0,
846
rpc_service_delete_internal, argc, argv);
849
/********************************************************************
850
********************************************************************/
852
static int rpc_service_create(struct net_context *c, int argc, const char **argv)
854
if (c->display_usage) {
856
"net rpc service create <service>\n"
857
" Create a Win32 service\n");
861
return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0,
862
rpc_service_create_internal, argc, argv);
865
/********************************************************************
866
********************************************************************/
681
868
int net_rpc_service(struct net_context *c, int argc, const char **argv)
683
870
struct functable func[] = {