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

Add some missing flags and expose service handle #115

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "windows-service"
version = "0.6.0"
version = "0.6.2"
NuSkooler marked this conversation as resolved.
Show resolved Hide resolved
description = "A crate that provides facilities for management and implementation of windows services"
readme = "README.md"
authors = ["Mullvad VPN"]
Expand Down
8 changes: 8 additions & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use windows_sys::{
Win32::{
Foundation::{ERROR_SERVICE_SPECIFIC_ERROR, NO_ERROR},
Storage::FileSystem,
Security,
System::{Power, RemoteDesktop, Services, SystemServices, Threading::INFINITE},
UI::WindowsAndMessaging,
},
Expand Down Expand Up @@ -80,6 +81,9 @@ bitflags::bitflags! {

/// Can use user-defined control codes
const USER_DEFINED_CONTROL = Services::SERVICE_USER_DEFINED_CONTROL;

/// Full access to the service object
const ALL_ACCESS = Services::SERVICE_ALL_ACCESS;
faern marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -1843,6 +1847,10 @@ impl Service {
}
}

pub fn raw_service_handle(&self) -> Security::SC_HANDLE {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a lot of to-raw exposure in this crate already, and we usually name the methods to_raw unless I have missed some places where we are inconsistent(?). Can you please follow the same naming convention?

I also think this type of method should either be close to the top or bottom of methods, not somewhere in the middle. Please look at similar examples and try to be consistent with those (if we have a pattern? But I think we do).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a number of to_raw, but in this case, I changed it to mirror the underlying raw_handle. If you'd like to_raw, I can of course make that change!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private wrapper type ScHandle exposes raw_handle but a lot of places use to_raw. 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to switch it to_raw? I'm happy to do so if that's your preference!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd use to_raw to keep the interface homogeneous and familiar to consumers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could argue we should stop we the bespoke methods and just implement https://doc.rust-lang.org/stable/std/os/windows/io/trait.IntoRawHandle.html for the relevant types instead. But that's not going to happen in this PR. For now I think we should just be consistent with what this library usually uses (to_raw)

self.service_handle.raw_handle()
}

/// Private helper to send the control commands to the system.
fn send_control_command(&self, command: ServiceControl) -> crate::Result<ServiceStatus> {
let mut raw_status = unsafe { mem::zeroed::<Services::SERVICE_STATUS>() };
Expand Down
2 changes: 2 additions & 0 deletions src/service_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ bitflags::bitflags! {

/// Can enumerate services or receive notifications.
const ENUMERATE_SERVICE = Services::SC_MANAGER_ENUMERATE_SERVICE;

const ALL_ACCESS = Services::SC_MANAGER_ALL_ACCESS;
faern marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading