Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new Service method to retrieve its SID type info #112

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
(See: `Service::notify` and `notify_service.rs` example)
- Add support for `LidSwitchStateChange` in `PowerBroadcastSetting`.
(See: `LidSwitchStateChange`)
- Add function for obtaining service SID infos. (See: `Service::get_config_service_sid_info`).


## [0.6.0] - 2023-03-07
Expand All @@ -21,8 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed
- Breaking: Consolidate `Error` type. Remove dependency on `err-derive`.
- Breaking: `Service::delete` does not consume `self` any longer. Make sure to `drop` a reference
to `Service` manually if you plan to poll SCM synchronously to determine when the service is
- Breaking: `Service::delete` does not consume `self` any longer. Make sure to `drop` a reference
to `Service` manually if you plan to poll SCM synchronously to determine when the service is
removed from system. (See `uninstall_service.rs` example)


Expand All @@ -41,8 +42,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.4.0] - 2021-08-12
### Changed
- Breaking: `ServiceDependency::from_system_identifier()`, `ServiceManager::new()`,
`ServiceManager::local_computer()`, `ServiceManager::remote_computer()` now take
- Breaking: `ServiceDependency::from_system_identifier()`, `ServiceManager::new()`,
`ServiceManager::local_computer()`, `ServiceManager::remote_computer()` now take
`impl AsRef<OsStr>` arguments.
- Upgrade err-derive dependency to 0.3.0
- `ServiceStatusHandle` is now Sync.
Expand All @@ -64,9 +65,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Add support for configuring the service SID info.
- Add support for changing mandatory configuration settings on service.
- Add support for service failure actions. (See: `ServiceFailureActions`,
`Service::update_failure_actions`, `Service::get_failure_actions`,
`Service::set_failure_actions_on_non_crash_failures`,
- Add support for service failure actions. (See: `ServiceFailureActions`,
`Service::update_failure_actions`, `Service::get_failure_actions`,
`Service::set_failure_actions_on_non_crash_failures`,
`Service::get_failure_actions_on_non_crash_failures`)
- Add support to pause and continue services. (See: `Service::pause` and `Service::resume`)
- Use `QueryServiceStatusEx` when querying service status. Allows getting the process ID of a
Expand Down
22 changes: 21 additions & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,11 +1644,31 @@ impl Service {
Ok(raw_failure_actions_flag.fFailureActionsOnNonCrashFailures != 0)
}

/// Query the system for the service's SID type information.
///
/// The service must be open with the [`ServiceAccess::QUERY_CONFIG`]
/// access permission prior to calling this method.
pub fn get_config_service_sid_info(&self) -> crate::Result<ServiceSidType> {
let mut data = vec![0u8; u32::BITS as usize / 8];

// SAFETY: The structure we get back is `SERVICE_SID_INFO`. It has a
// single member that specifies the new SID type as a `u32`, and as
// such, we can get away with not explicitly creating a structure and
// instead re-using `ServiceSidType` that is `repr(u32)`.
unsafe { self.query_config2(Services::SERVICE_CONFIG_SERVICE_SID_INFO, &mut data) }
.map_err(Error::Winapi)
}

/// Require the system to set the service's SID type information to the
/// provided value.
///
/// The service must be open with the [`ServiceAccess::CHANGE_CONFIG`]
/// access permission prior to calling this method.
pub fn set_config_service_sid_info(
&self,
mut service_sid_type: ServiceSidType,
) -> crate::Result<()> {
// The structure we need to pass in is `SERVICE_SID_INFO`.
// SAFETY: The structure we need to pass in is `SERVICE_SID_INFO`.
// It has a single member that specifies the new SID type, and as such,
// we can get away with not explicitly creating a structure in Rust.
unsafe {
Expand Down
Loading