Hello! I have imported CreateFileMapping function, yet I can't quite implement it's SecurityAtributes parameter. When setting it to null, everything works well, untill you access shared memory with another user...
Thus I tried some classes with SIDs and everything, but me being no expert in native security functions they all fail: CreateFileMapping returns ERROR_NOACCES... It's not a major drawback, but really would like to allow cross-user communication.
Thank you!
static extern IntPtr CreateFileMapping(IntPtr hFile, SecurityAttributes secAttributes, ....);
class SecurityAttributes
{
public SecurityAttributes(IntPtr securityDescriptor)
{
this.lpSecurityDescriptor = securityDescriptor;
}
UInt32 nLegnth = 12;
IntPtr lpSecurityDescriptor;
Boolean bInheritHandle = true;
}
public
test(){
IntPtr descriptor = IntPtr.Zero, sid = IntPtr.Zero;
AdvApi32.InitializeSecurityDescriptor(out descriptor, 1);
WindowsIdentity identity = WindowsIdentity.GetCurrent();
AdvApi32.ConvertStringSidToSid(identity.User.Value, ref sid);
AdvApi32.SetSecurityDescriptorDacl(ref descriptor, true, sid, false);
Kernel32.SecurityAttributes securityAttributes = new Kernel32.SecurityAttributes(descriptor);
Kernel32
.CreateFileMapping((IntPtr)Kernel32.INVALID_HANDLE_VALUE, securityAttributes, ...);Kernel32
.GetLastError();// ^^ that's where I get error 998...
}