interprocess icon indicating copy to clipboard operation
interprocess copied to clipboard

Not able to set custom Security Attributes

Open ajaykumargdr opened this issue 11 months ago • 0 comments

Describe the bug I'm attempting to set custom security attributes for the ListenerOption of a LocalSocket. The method SecurityDescriptor::write_to_security_attributes takes a mutable reference to a SECURITY_ATTRIBUTES object from windows_sys::Win32::Security. However, the interprocess crate does not expose the underlying SECURITY_ATTRIBUTES type. I tried addding windows_sys to my project dependencies. This leads to a conflict since Rust treats different versions of the same crate as distinct types:

two different versions of crate windows_sys are being used; two types coming from two different versions of the same crate are different types even if they look the same

Steps to Reproduce

  1. Add the latest version of windows-sys to the project dependency
  2. Create object to the windows_sys::Win32::Security::SECURITY_ATTRIBUTES
  3. Create new SecurityDescriptor object using interprocess::os::windows::security_descriptor::owned::SecurityDescriptor::new()
  4. Try to pass object of the SECURITY_ATTRIBUTES to the SecurityDescriptor::write_to_security_attributes() method

My Code Snippet

use windows_sys::Win32::Security::SECURITY_ATTRIBUTES;

let printname = "example.sock";
let name = printname.to_ns_name::<GenericNamespaced>()?;

let mut sa: SECURITY_ATTRIBUTES = unsafe { zeroed() };
// modifying `sa` here

let mut sd = SecurityDescriptor::new()?;
sd.write_to_security_attributes(&mut sa); // mismatch type if we use latest version of `windows-sys`

Workaround Using the same version of windows-sys as interprocess uses which is:

windows-sys = { version = "0.52.0", features = ["Win32_Security"] }

fixes the problem, but it forces the project to lock to an older version of windows-sys

ajaykumargdr avatar Mar 14 '25 06:03 ajaykumargdr