public static MessageQueueAccessRights GetAccessMask(QueuePath queuePath, string userName) { var sid = TranslateUserNameToSid(userName); var gchSecurityDescriptor = GetSecurityDescriptorHandle(queuePath, (int)SecurityInformation.Dacl); var ace = GetAce(gchSecurityDescriptor.AddrOfPinnedObject(), sid); var aceMask = ace.Mask; gchSecurityDescriptor.Free(); return(aceMask); }
private static GCHandle GetSecurityDescriptorHandle(QueuePath queuePath, int securityInformation) { byte[] securityDescriptorBytes; int length; int lengthNeeded; uint result; string formatName = queuePath.ToString(); result = Security.MQGetQueueSecurity(formatName, securityInformation, IntPtr.Zero, 0, out lengthNeeded); if (result != Security.MQ_ERROR_SECURITY_DESCRIPTOR_TOO_SMALL) { string message = "There was an error calling MQGetQueueSecurity." + Environment.NewLine + "Error Number: " + result.ToString() + Environment.NewLine + "Error Message: " + Security.GetErrorMessage(result); throw new Exception(message); } length = lengthNeeded; securityDescriptorBytes = new byte[length]; IntPtr pSecurityDescriptor = new IntPtr(); GCHandle gchSecurityDescriptor = GCHandle.Alloc(securityDescriptorBytes, GCHandleType.Pinned); pSecurityDescriptor = gchSecurityDescriptor.AddrOfPinnedObject(); result = Security.MQGetQueueSecurity(formatName, securityInformation, pSecurityDescriptor, length, out lengthNeeded); if (result != Security.MQ_OK) { gchSecurityDescriptor.Free(); string message = "There was an error calling MQGetQueueSecurity to read the Security Descriptor. " + Environment.NewLine + "Error Number: " + result.ToString() + Environment.NewLine + "Error Message: " + Security.GetErrorMessage(result); throw new Exception(message); } var securityDescriptor = new SECURITY_DESCRIPTOR(); Marshal.PtrToStructure(pSecurityDescriptor, securityDescriptor); return(gchSecurityDescriptor); }
public static string GetOwner(QueuePath queuePath) { IntPtr pOwner; bool ownerDefaulted; var gchSecurityDescriptor = GetSecurityDescriptorHandle(queuePath, (int)SecurityInformation.Owner); Security.GetSecurityDescriptorOwner(gchSecurityDescriptor.AddrOfPinnedObject(), out pOwner, out ownerDefaulted); var ownerSid = new SecurityIdentifier(pOwner); string ownerUserName = TranslateSidToUserName(ownerSid); gchSecurityDescriptor.Free(); return(ownerUserName); }
private static GCHandle GetSecurityDescriptorHandle(QueuePath queuePath, int securityInformation) { byte[] securityDescriptorBytes; int length; int lengthNeeded; uint result; string formatName = queuePath.ToString(); result = Security.MQGetQueueSecurity(formatName, securityInformation, IntPtr.Zero, 0, out lengthNeeded); if (result != Security.MQ_ERROR_SECURITY_DESCRIPTOR_TOO_SMALL) { string message = "There was an error calling MQGetQueueSecurity." + Environment.NewLine + "Error Number: " + result.ToString() + Environment.NewLine + "Error Message: " + Security.GetErrorMessage(result); throw new Exception(message); } length = lengthNeeded; securityDescriptorBytes = new byte[length]; IntPtr pSecurityDescriptor = new IntPtr(); GCHandle gchSecurityDescriptor = GCHandle.Alloc(securityDescriptorBytes, GCHandleType.Pinned); pSecurityDescriptor = gchSecurityDescriptor.AddrOfPinnedObject(); result = Security.MQGetQueueSecurity(formatName, securityInformation, pSecurityDescriptor, length, out lengthNeeded); if (result != Security.MQ_OK) { gchSecurityDescriptor.Free(); string message = "There was an error calling MQGetQueueSecurity to read the Security Descriptor. " + Environment.NewLine + "Error Number: " + result.ToString() + Environment.NewLine + "Error Message: " + Security.GetErrorMessage(result); throw new Exception(message); } var securityDescriptor = new SECURITY_DESCRIPTOR(); Marshal.PtrToStructure(pSecurityDescriptor, securityDescriptor); return gchSecurityDescriptor; }
public static string GetOwner(QueuePath queuePath) { IntPtr pOwner; bool ownerDefaulted; var gchSecurityDescriptor = GetSecurityDescriptorHandle(queuePath, (int)SecurityInformation.Owner); Security.GetSecurityDescriptorOwner(gchSecurityDescriptor.AddrOfPinnedObject(), out pOwner, out ownerDefaulted); var ownerSid = new SecurityIdentifier(pOwner); string ownerUserName = TranslateSidToUserName(ownerSid); gchSecurityDescriptor.Free(); return ownerUserName; }
public static MessageQueueAccessRights GetAccessMask(QueuePath queuePath, string userName) { var sid = TranslateUserNameToSid(userName); var gchSecurityDescriptor = GetSecurityDescriptorHandle(queuePath, (int)SecurityInformation.Dacl); var ace = GetAce(gchSecurityDescriptor.AddrOfPinnedObject(), sid); var aceMask = ace.Mask; gchSecurityDescriptor.Free(); return aceMask; }