From 96bebe1f0dadc7c88ad1b9dd5776f7e9be3305b6 Mon Sep 17 00:00:00 2001 From: "Bryan D. Ashby" Date: Tue, 16 Jan 2024 12:02:59 -0700 Subject: [PATCH 1/5] Expose raw service handle --- Cargo.toml | 2 +- src/service.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 64a8568..18954e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-service" -version = "0.6.0" +version = "0.6.1" description = "A crate that provides facilities for management and implementation of windows services" readme = "README.md" authors = ["Mullvad VPN"] diff --git a/src/service.rs b/src/service.rs index b5a2075..f264cdc 100644 --- a/src/service.rs +++ b/src/service.rs @@ -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, }, @@ -1843,6 +1844,10 @@ impl Service { } } + pub fn raw_service_handle(&self) -> Security::SC_HANDLE { + self.service_handle.raw_handle() + } + /// Private helper to send the control commands to the system. fn send_control_command(&self, command: ServiceControl) -> crate::Result { let mut raw_status = unsafe { mem::zeroed::() }; From 5a62522eaeb651f7e6e12feba882d2e0cf2e9e61 Mon Sep 17 00:00:00 2001 From: "Bryan D. Ashby" Date: Tue, 16 Jan 2024 13:28:27 -0700 Subject: [PATCH 2/5] Additional service and SC manager flags --- src/service.rs | 3 +++ src/service_manager.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/service.rs b/src/service.rs index f264cdc..c7aa912 100644 --- a/src/service.rs +++ b/src/service.rs @@ -81,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; } } diff --git a/src/service_manager.rs b/src/service_manager.rs index a5f5f74..746128d 100644 --- a/src/service_manager.rs +++ b/src/service_manager.rs @@ -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; } } From ac81c431b32be618035b0c30d9a764d10d02009a Mon Sep 17 00:00:00 2001 From: "Bryan D. Ashby" Date: Tue, 16 Jan 2024 13:30:02 -0700 Subject: [PATCH 3/5] Bump minor --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 18954e2..9a6c0df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-service" -version = "0.6.1" +version = "0.6.2" description = "A crate that provides facilities for management and implementation of windows services" readme = "README.md" authors = ["Mullvad VPN"] From ac85ec6cd180a437c417fc5826c5cf6c6e2e4401 Mon Sep 17 00:00:00 2001 From: "Bryan D. Ashby" Date: Wed, 17 Jan 2024 09:25:36 -0700 Subject: [PATCH 4/5] PR feedback: Doc strings & naming --- Cargo.toml | 2 +- src/service.rs | 9 +++++---- src/service_manager.rs | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a6c0df..64a8568 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-service" -version = "0.6.2" +version = "0.6.0" description = "A crate that provides facilities for management and implementation of windows services" readme = "README.md" authors = ["Mullvad VPN"] diff --git a/src/service.rs b/src/service.rs index c7aa912..0aab1d8 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1442,6 +1442,11 @@ impl Service { Service { service_handle } } + /// Provides access to the underlying system service handle + pub fn raw_handle(&self) -> Security::SC_HANDLE { + self.service_handle.raw_handle() + } + /// Start the service. /// /// # Example @@ -1847,10 +1852,6 @@ impl Service { } } - pub fn raw_service_handle(&self) -> Security::SC_HANDLE { - self.service_handle.raw_handle() - } - /// Private helper to send the control commands to the system. fn send_control_command(&self, command: ServiceControl) -> crate::Result { let mut raw_status = unsafe { mem::zeroed::() }; diff --git a/src/service_manager.rs b/src/service_manager.rs index 746128d..50a48b7 100644 --- a/src/service_manager.rs +++ b/src/service_manager.rs @@ -22,6 +22,7 @@ bitflags::bitflags! { /// Can enumerate services or receive notifications. const ENUMERATE_SERVICE = Services::SC_MANAGER_ENUMERATE_SERVICE; + /// Includes all possible access rights. const ALL_ACCESS = Services::SC_MANAGER_ALL_ACCESS; } } From 8b272675b1ea697bf501b39b165fcd4256b9cb55 Mon Sep 17 00:00:00 2001 From: "Bryan D. Ashby" Date: Wed, 17 Jan 2024 09:27:39 -0700 Subject: [PATCH 5/5] Cargo fmt --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 0aab1d8..9dbc4a7 100644 --- a/src/service.rs +++ b/src/service.rs @@ -13,8 +13,8 @@ use windows_sys::{ core::GUID, Win32::{ Foundation::{ERROR_SERVICE_SPECIFIC_ERROR, NO_ERROR}, - Storage::FileSystem, Security, + Storage::FileSystem, System::{Power, RemoteDesktop, Services, SystemServices, Threading::INFINITE}, UI::WindowsAndMessaging, },