/
ThreadingAclExtensions.cs
50 lines (39 loc) · 2.01 KB
/
ThreadingAclExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Ported from EventWaitHandle.cs, Mutex.cs, Semaphore.cs and made extension methods (or renamed statics, where necessary) to allow
// extending the class without System.Threading needing to rely on System.Security.AccessControl
using System;
using System.Security.AccessControl;
namespace System.Threading
{
public static class ThreadingAclExtensions
{
public static EventWaitHandleSecurity GetAccessControl(this EventWaitHandle handle)
{
return new EventWaitHandleSecurity(handle.GetSafeWaitHandle(), AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
}
public static void SetAccessControl(this EventWaitHandle handle, EventWaitHandleSecurity eventSecurity)
{
ArgumentNullException.ThrowIfNull(eventSecurity);
eventSecurity.Persist(handle.GetSafeWaitHandle());
}
public static MutexSecurity GetAccessControl(this Mutex mutex)
{
return new MutexSecurity(mutex.GetSafeWaitHandle(), AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
}
public static void SetAccessControl(this Mutex mutex, MutexSecurity mutexSecurity)
{
ArgumentNullException.ThrowIfNull(mutexSecurity);
mutexSecurity.Persist(mutex.GetSafeWaitHandle());
}
public static SemaphoreSecurity GetAccessControl(this Semaphore semaphore)
{
return new SemaphoreSecurity(semaphore.GetSafeWaitHandle(), AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
}
public static void SetAccessControl(this Semaphore semaphore, SemaphoreSecurity semaphoreSecurity)
{
ArgumentNullException.ThrowIfNull(semaphoreSecurity);
semaphoreSecurity.Persist(semaphore.GetSafeWaitHandle());
}
}
}