static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid,
					const char *domain_name, 
					struct cli_state *cli,
					struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx, 
					int argc,
					const char **argv )
{
	POLICY_HND hSCM, hService;
	WERROR result = WERR_GENERAL_FAILURE;
	fstring servicename;
	uint32 state = 0;
	
	if (argc != 1 ) {
		d_printf("Usage: net rpc service status <service>\n");
		return NT_STATUS_OK;
	}

	fstrcpy( servicename, argv[0] );

	/* Open the Service Control Manager */
	
	result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE  );
	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Failed to open Service Control Manager.  [%s]\n", dos_errstr(result));
		return werror_to_ntstatus(result);
	}
	
	/* Open the Service */
	
	result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, 
		servicename, SC_RIGHT_SVC_START );

	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Failed to open service.  [%s]\n", dos_errstr(result));
		goto done;
	}
	
	/* get the status */

	result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 );
	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Query status request failed.  [%s]\n", dos_errstr(result));
		goto done;
	}
	
	result = watch_service_state(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_RUNNING, &state  );
	
	if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) )
		d_printf("Successfully started service: %s\n", servicename );
	else
		d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) );
	
done:	
	rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService  );
	rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM  );

	return werror_to_ntstatus(result);
}
Example #2
0
static WERROR control_service(struct rpc_pipe_client *pipe_hnd,
				TALLOC_CTX *mem_ctx,
				struct policy_handle *hSCM,
				const char *service,
				uint32 control,
				uint32 watch_state )
{
	struct policy_handle hService;
	WERROR result = WERR_GENERAL_FAILURE;
	NTSTATUS status;
	struct SERVICE_STATUS service_status;
	uint32 state = 0;

	/* Open the Service */

	status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
					    hSCM,
					    service,
					    (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE),
					    &hService,
					    &result);

	if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
			  win_errstr(result));
		goto done;
	}

	/* get the status */

	status = rpccli_svcctl_ControlService(pipe_hnd, mem_ctx,
					      &hService,
					      control,
					      &service_status,
					      &result);

	if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, _("Control service request failed.  [%s]\n"),
			  win_errstr(result));
		goto done;
	}

	/* loop -- checking the state until we are where we want to be */

	result = watch_service_state(pipe_hnd, mem_ctx, hSCM, service, watch_state, &state );

	d_printf(_("%s service is %s.\n"), service, svc_status_string(state));

done:
	rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);

	return result;
}
static WERROR control_service(struct rpc_pipe_client *pipe_hnd,
				TALLOC_CTX *mem_ctx, 
				POLICY_HND *hSCM,
				const char *service, 
				uint32 control,
				uint32 watch_state )
{
	POLICY_HND hService;
	WERROR result = WERR_GENERAL_FAILURE;
	SERVICE_STATUS service_status;
	uint32 state = 0;
	
	/* Open the Service */
	
	result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, 
		service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) );

	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Failed to open service.  [%s]\n", dos_errstr(result));
		goto done;
	}
	
	/* get the status */

	result = rpccli_svcctl_control_service(pipe_hnd, mem_ctx, &hService, 
		control, &service_status  );
		
	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Control service request failed.  [%s]\n", dos_errstr(result));
		goto done;
	}
	
	/* loop -- checking the state until we are where we want to be */
	
	result = watch_service_state(pipe_hnd, mem_ctx, hSCM, service, watch_state, &state );
		
	d_printf("%s service is %s.\n", service, svc_status_string(state));

done:	
	rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService  );
		
	return result;
}	
Example #4
0
static NTSTATUS rpc_service_start_internal(struct net_context *c,
					const DOM_SID *domain_sid,
					const char *domain_name,
					struct cli_state *cli,
					struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					int argc,
					const char **argv )
{
	struct policy_handle hSCM, hService;
	WERROR result = WERR_GENERAL_FAILURE;
	NTSTATUS status;
	uint32 state = 0;

	if (argc != 1 ) {
		d_printf(_("Usage: net rpc service status <service>\n"));
		return NT_STATUS_OK;
	}

	/* Open the Service Control Manager */
	status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
					      pipe_hnd->srv_name_slash,
					      NULL,
					      SC_RIGHT_MGR_ENUMERATE_SERVICE,
					      &hSCM,
					      &result);
	if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
		d_fprintf(stderr,
			  _("Failed to open Service Control Manager.  [%s]\n"),
			  win_errstr(result));
		return werror_to_ntstatus(result);
	}

	/* Open the Service */

	status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
					    &hSCM,
					    argv[0],
					    SC_RIGHT_SVC_START,
					    &hService,
					    &result);

	if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
			  win_errstr(result));
		goto done;
	}

	/* get the status */

	status = rpccli_svcctl_StartServiceW(pipe_hnd, mem_ctx,
					     &hService,
					     0,
					     NULL,
					     &result);

	if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, _("Query status request failed.  [%s]\n"),
			  win_errstr(result));
		goto done;
	}

	result = watch_service_state(pipe_hnd, mem_ctx, &hSCM, argv[0], SVCCTL_RUNNING, &state  );

	if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) )
		d_printf(_("Successfully started service: %s\n"),
			 argv[0] );
	else
		d_fprintf(stderr,_("Failed to start service: %s [%s]\n"),
			  argv[0], win_errstr(result) );

done:
	rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
	rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);

	return werror_to_ntstatus(result);
}