当前位置: 首页>>代码示例>>C#>>正文


C# MutexSecurity.GetSecurityDescriptorBinaryForm方法代码示例

本文整理汇总了C#中System.Security.AccessControl.MutexSecurity.GetSecurityDescriptorBinaryForm方法的典型用法代码示例。如果您正苦于以下问题:C# MutexSecurity.GetSecurityDescriptorBinaryForm方法的具体用法?C# MutexSecurity.GetSecurityDescriptorBinaryForm怎么用?C# MutexSecurity.GetSecurityDescriptorBinaryForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.AccessControl.MutexSecurity的用法示例。


在下文中一共展示了MutexSecurity.GetSecurityDescriptorBinaryForm方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Mutex

        public unsafe Mutex(bool initiallyOwned, String name, out bool createdNew, MutexSecurity mutexSecurity)
        {
            if (name != null)
            {
#if PLATFORM_UNIX
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_NamedSynchronizationPrimitives"));
#else
                if (System.IO.Path.MaxPath < name.Length)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
                }
#endif
            }
            Contract.EndContractBlock();
            Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
#if FEATURE_MACL
            // For ACL's, get the security descriptor from the MutexSecurity.
            if (mutexSecurity != null) {

                secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);

                byte[] sd = mutexSecurity.GetSecurityDescriptorBinaryForm();
                byte* pSecDescriptor = stackalloc byte[sd.Length];
                Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
                secAttrs.pSecurityDescriptor = pSecDescriptor;
            }
#endif

            CreateMutexWithGuaranteedCleanup(initiallyOwned, name, out createdNew, secAttrs);
        }
开发者ID:l1183479157,项目名称:coreclr,代码行数:31,代码来源:Mutex.cs

示例2: Mutex

        public unsafe Mutex(bool initiallyOwned, String name, out bool createdNew, MutexSecurity mutexSecurity)
        {
            if (name == string.Empty)
            {
                // Empty name is treated as an unnamed mutex. Set to null, and we will check for null from now on.
                name = null;
            }
#if !PLATFORM_UNIX
            if (name != null && System.IO.Path.MaxPath < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
            }
#endif
            Contract.EndContractBlock();
            Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
#if FEATURE_MACL
            // For ACL's, get the security descriptor from the MutexSecurity.
            if (mutexSecurity != null) {

                secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);

                byte[] sd = mutexSecurity.GetSecurityDescriptorBinaryForm();
                byte* pSecDescriptor = stackalloc byte[sd.Length];
                Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
                secAttrs.pSecurityDescriptor = pSecDescriptor;
            }
#endif

            CreateMutexWithGuaranteedCleanup(initiallyOwned, name, out createdNew, secAttrs);
        }
开发者ID:Rayislandstyle,项目名称:dotnet-coreclr,代码行数:31,代码来源:Mutex.cs

示例3: Mutex

 public unsafe Mutex(bool initiallyOwned, string name, out bool createdNew, MutexSecurity mutexSecurity)
 {
     if ((name != null) && (260 < name.Length))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name }));
     }
     Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
     if (mutexSecurity != null)
     {
         secAttrs = new Win32Native.SECURITY_ATTRIBUTES {
             nLength = Marshal.SizeOf(secAttrs)
         };
         byte[] securityDescriptorBinaryForm = mutexSecurity.GetSecurityDescriptorBinaryForm();
         byte* pDest = stackalloc byte[1 * securityDescriptorBinaryForm.Length];
         Buffer.memcpy(securityDescriptorBinaryForm, 0, pDest, 0, securityDescriptorBinaryForm.Length);
         secAttrs.pSecurityDescriptor = pDest;
     }
     SafeWaitHandle mutexHandle = null;
     bool newMutex = false;
     RuntimeHelpers.CleanupCode backoutCode = new RuntimeHelpers.CleanupCode(this.MutexCleanupCode);
     MutexCleanupInfo cleanupInfo = new MutexCleanupInfo(mutexHandle, false);
     RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(delegate (object userData) {
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
         }
         finally
         {
             if (initiallyOwned)
             {
                 cleanupInfo.inCriticalRegion = true;
                 Thread.BeginThreadAffinity();
                 Thread.BeginCriticalRegion();
             }
         }
         int errorCode = 0;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
         }
         finally
         {
             errorCode = CreateMutexHandle(initiallyOwned, name, secAttrs, out mutexHandle);
         }
         if (mutexHandle.IsInvalid)
         {
             mutexHandle.SetHandleAsInvalid();
             if (((name != null) && (name.Length != 0)) && (6 == errorCode))
             {
                 throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name }));
             }
             __Error.WinIOError(errorCode, name);
         }
         newMutex = errorCode != 0xb7;
         this.SetHandleInternal(mutexHandle);
         this.hasThreadAffinity = true;
     }, backoutCode, cleanupInfo);
     createdNew = newMutex;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:59,代码来源:Mutex.cs

示例4: Mutex

 public unsafe Mutex(bool initiallyOwned, string name, out bool createdNew, MutexSecurity mutexSecurity)
 {
     if ((name != null) && (260 < name.Length))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name }));
     }
     Win32Native.SECURITY_ATTRIBUTES structure = null;
     if (mutexSecurity != null)
     {
         structure = new Win32Native.SECURITY_ATTRIBUTES {
             nLength = Marshal.SizeOf(structure)
         };
         byte[] securityDescriptorBinaryForm = mutexSecurity.GetSecurityDescriptorBinaryForm();
         byte* pDest = stackalloc byte[(IntPtr) securityDescriptorBinaryForm.Length];
         Buffer.memcpy(securityDescriptorBinaryForm, 0, pDest, 0, securityDescriptorBinaryForm.Length);
         structure.pSecurityDescriptor = pDest;
     }
     RuntimeHelpers.CleanupCode backoutCode = new RuntimeHelpers.CleanupCode(this.MutexCleanupCode);
     MutexCleanupInfo cleanupInfo = new MutexCleanupInfo(null, false);
     MutexTryCodeHelper helper = new MutexTryCodeHelper(initiallyOwned, cleanupInfo, name, structure, this);
     RuntimeHelpers.TryCode code = new RuntimeHelpers.TryCode(helper.MutexTryCode);
     RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(code, backoutCode, cleanupInfo);
     createdNew = helper.m_newMutex;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:Mutex.cs

示例5: AcquireReservedMutex

        internal static unsafe void AcquireReservedMutex(ref bool bHandleObtained)
        {
#if FEATURE_MACL
            SafeWaitHandle mutexHandle = null;
            int errorCode;

            bHandleObtained = false;

            if (!Environment.IsW2k3) {
                return;
            }
            
            if (s_ReservedMutex == null) {        

                // Create a maximally-permissive security descriptor, to ensure we never get an
                // ACCESS_DENIED error when calling CreateMutex
                MutexSecurity sec = new MutexSecurity();
                SecurityIdentifier everyoneSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                sec.AddAccessRule(new MutexAccessRule(everyoneSid, MutexRights.FullControl, AccessControlType.Allow));
                
                // For ACL's, get the security descriptor from the MutexSecurity.
                Win32Native.SECURITY_ATTRIBUTES secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);
                
                byte[] sd = sec.GetSecurityDescriptorBinaryForm();
                byte * bytesOnStack = stackalloc byte[sd.Length];
                Buffer.Memcpy(bytesOnStack, 0, sd, 0, sd.Length);
                secAttrs.pSecurityDescriptor = bytesOnStack;

                RuntimeHelpers.PrepareConstrainedRegions();
                try {} 
                finally {
                    mutexHandle = Win32Native.CreateMutex(secAttrs, false, c_ReservedMutexName);

                    // need to set specially, since this mutex cannot lock on itself while closing itself.
                    mutexHandle.SetAsReservedMutex(); 
                }
                
                errorCode = Marshal.GetLastWin32Error();
                if (mutexHandle.IsInvalid) {
                    mutexHandle.SetHandleAsInvalid();
                    __Error.WinIOError(errorCode, c_ReservedMutexName);
                }

                Mutex m = new Mutex(mutexHandle);
                Interlocked.CompareExchange(ref s_ReservedMutex, m, null);
               
            }
                

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally {
                 try {
                     s_ReservedMutex.WaitOne();
                     bHandleObtained = true;
                 }
                 catch (AbandonedMutexException)
                 {
                     // we don't care if another process holding the Mutex was killed
                     bHandleObtained = true;
                 }
            }
#else
            bHandleObtained = true;
#endif
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:67,代码来源:Mutex.cs

示例6: Mutex

        public unsafe Mutex(bool initiallyOwned, String name, out bool createdNew, MutexSecurity mutexSecurity)
        {
            if(null != name && System.IO.Path.MAX_PATH < name.Length)
            { 
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
            } 
            Contract.EndContractBlock(); 
            Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
#if !FEATURE_PAL && FEATURE_MACL 
            // For ACL's, get the security descriptor from the MutexSecurity.
            if (mutexSecurity != null) {

                secAttrs = new Win32Native.SECURITY_ATTRIBUTES(); 
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);
 
                byte[] sd = mutexSecurity.GetSecurityDescriptorBinaryForm(); 
                byte* pSecDescriptor = stackalloc byte[sd.Length];
                Buffer.memcpy(sd, 0, pSecDescriptor, 0, sd.Length); 
                secAttrs.pSecurityDescriptor = pSecDescriptor;
            }
#endif
 

            RuntimeHelpers.CleanupCode cleanupCode = new RuntimeHelpers.CleanupCode(MutexCleanupCode); 
            MutexCleanupInfo cleanupInfo = new MutexCleanupInfo(null, false); 
            MutexTryCodeHelper tryCodeHelper = new MutexTryCodeHelper(initiallyOwned, cleanupInfo, name, secAttrs, this);
            RuntimeHelpers.TryCode tryCode = new RuntimeHelpers.TryCode(tryCodeHelper.MutexTryCode); 
            RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
                tryCode,
                cleanupCode,
                cleanupInfo); 
                createdNew = tryCodeHelper.m_newMutex;
 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:34,代码来源:Mutex.cs

示例7: AcquireReservedMutex

 internal static unsafe void AcquireReservedMutex(ref bool bHandleObtained)
 {
     SafeWaitHandle handle = null;
     bHandleObtained = false;
     if (Environment.IsW2k3)
     {
         if (s_ReservedMutex == null)
         {
             Win32Native.SECURITY_ATTRIBUTES security_attributes;
             MutexSecurity security = new MutexSecurity();
             SecurityIdentifier identity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
             security.AddAccessRule(new MutexAccessRule(identity, MutexRights.FullControl, AccessControlType.Allow));
             security_attributes = new Win32Native.SECURITY_ATTRIBUTES {
                 nLength = Marshal.SizeOf(security_attributes)
             };
             byte[] securityDescriptorBinaryForm = security.GetSecurityDescriptorBinaryForm();
             byte* pDest = stackalloc byte[(IntPtr) securityDescriptorBinaryForm.Length];
             Buffer.memcpy(securityDescriptorBinaryForm, 0, pDest, 0, securityDescriptorBinaryForm.Length);
             security_attributes.pSecurityDescriptor = pDest;
             RuntimeHelpers.PrepareConstrainedRegions();
             try
             {
             }
             finally
             {
                 handle = Win32Native.CreateMutex(security_attributes, false, @"Global\CLR_RESERVED_MUTEX_NAME");
                 handle.SetAsReservedMutex();
             }
             int errorCode = Marshal.GetLastWin32Error();
             if (handle.IsInvalid)
             {
                 handle.SetHandleAsInvalid();
                 __Error.WinIOError(errorCode, @"Global\CLR_RESERVED_MUTEX_NAME");
             }
             Mutex mutex = new Mutex(handle);
             Interlocked.CompareExchange<Mutex>(ref s_ReservedMutex, mutex, null);
         }
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
         }
         finally
         {
             try
             {
                 s_ReservedMutex.WaitOne();
                 bHandleObtained = true;
             }
             catch (AbandonedMutexException)
             {
                 bHandleObtained = true;
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:55,代码来源:Mutex.cs


注:本文中的System.Security.AccessControl.MutexSecurity.GetSecurityDescriptorBinaryForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。