Exemple #1
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;
}	
Exemple #3
0
static NTSTATUS rpc_service_status_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;
	struct SERVICE_STATUS service_status;
	struct QUERY_SERVICE_CONFIG config;
	uint32_t buf_size = sizeof(config);
	uint32_t ret_size = 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_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG),
					    &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_QueryServiceStatus(pipe_hnd, mem_ctx,
						  &hService,
						  &service_status,
						  &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;
	}

	d_printf(_("%s service is %s.\n"), argv[0],
		 svc_status_string(service_status.state));

	/* get the config */

	status = rpccli_svcctl_QueryServiceConfigW(pipe_hnd, mem_ctx,
						   &hService,
						   &config,
						   buf_size,
						   &ret_size,
						   &result);
	if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) {
		buf_size = ret_size;
		status = rpccli_svcctl_QueryServiceConfigW(pipe_hnd, mem_ctx,
							   &hService,
							   &config,
							   buf_size,
							   &ret_size,
							   &result);
	}

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

	/* print out the configuration information for the service */

	d_printf(_("Configuration details:\n"));
	d_printf(_("\tControls Accepted    = 0x%x\n"),
		 service_status.controls_accepted);
	d_printf(_("\tService Type         = 0x%x\n"), config.service_type);
	d_printf(_("\tStart Type           = 0x%x\n"), config.start_type);
	d_printf(_("\tError Control        = 0x%x\n"), config.error_control);
	d_printf(_("\tTag ID               = 0x%x\n"), config.tag_id);

	if (config.executablepath) {
		d_printf(_("\tExecutable Path      = %s\n"),
			 config.executablepath);
	}

	if (config.loadordergroup) {
		d_printf(_("\tLoad Order Group     = %s\n"),
			 config.loadordergroup);
	}

	if (config.dependencies) {
		d_printf(_("\tDependencies         = %s\n"),
			 config.dependencies);
	}

	if (config.startname) {
		d_printf(_("\tStart Name           = %s\n"), config.startname);
	}

	if (config.displayname) {
		d_printf(_("\tDisplay Name         = %s\n"),
			 config.displayname);
	}

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

	return werror_to_ntstatus(result);
}
static NTSTATUS rpc_service_status_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;
	SERVICE_STATUS service_status;
	SERVICE_CONFIG config;
	fstring ascii_string;
	
	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_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) );

	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_query_status(pipe_hnd, mem_ctx, &hService, &service_status  );
	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Query status request failed.  [%s]\n", dos_errstr(result));
		goto done;
	}
	
	d_printf("%s service is %s.\n", servicename, svc_status_string(service_status.state));

	/* get the config */

	result = rpccli_svcctl_query_config(pipe_hnd, mem_ctx, &hService, &config  );
	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Query config request failed.  [%s]\n", dos_errstr(result));
		goto done;
	}

	/* print out the configuration information for the service */

	d_printf("Configuration details:\n");
	d_printf("\tControls Accepted    = 0x%x\n", service_status.controls_accepted);
	d_printf("\tService Type         = 0x%x\n", config.service_type);
	d_printf("\tStart Type           = 0x%x\n", config.start_type);
	d_printf("\tError Control        = 0x%x\n", config.error_control);
	d_printf("\tTag ID               = 0x%x\n", config.tag_id);

	if ( config.executablepath ) {
		rpcstr_pull( ascii_string, config.executablepath->buffer, sizeof(ascii_string), -1, STR_TERMINATE );
		d_printf("\tExecutable Path      = %s\n", ascii_string);
	}

	if ( config.loadordergroup ) {
		rpcstr_pull( ascii_string, config.loadordergroup->buffer, sizeof(ascii_string), -1, STR_TERMINATE );
		d_printf("\tLoad Order Group     = %s\n", ascii_string);
	}

	if ( config.dependencies ) {
		rpcstr_pull( ascii_string, config.dependencies->buffer, sizeof(ascii_string), -1, STR_TERMINATE );
		d_printf("\tDependencies         = %s\n", ascii_string);
	}

	if ( config.startname ) {
		rpcstr_pull( ascii_string, config.startname->buffer, sizeof(ascii_string), -1, STR_TERMINATE );
		d_printf("\tStart Name           = %s\n", ascii_string);
	}

	if ( config.displayname ) {
		rpcstr_pull( ascii_string, config.displayname->buffer, sizeof(ascii_string), -1, STR_TERMINATE );
		d_printf("\tDisplay Name         = %s\n", ascii_string);
	}

done:	
	rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService  );
	rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM  );

	return werror_to_ntstatus(result);
}