public SemaphoreAccessRule(string identity, SemaphoreRights semaphoreRights, AccessControlType type) : base(null, 0, false, InheritanceFlags.None, PropagationFlags.None, type) { this.semaphoreRights = semaphoreRights; }
// Constructor. public SemaphoreAuditRule (IdentityReference identity, SemaphoreRights semaphoreRights, AuditFlags auditFlags) : base(identity, (int)semaphoreRights, false, InheritanceFlags.None, PropagationFlags.None, auditFlags) { }
// Constructor. public SemaphoreAccessRule (IdentityReference identity, SemaphoreRights semaphoreRights, AccessControlType type) : base(identity, (int)semaphoreRights, false, InheritanceFlags.None, PropagationFlags.None, type) { }
private static OpenExistingResult OpenExistingWorker(string name, SemaphoreRights rights, out Semaphore?result) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Length == 0) { throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); } result = null; SafeWaitHandle handle = Interop.Kernel32.OpenSemaphore((uint)rights, false, name); int errorCode = Marshal.GetLastWin32Error(); if (handle.IsInvalid) { return(errorCode switch { Interop.Errors.ERROR_FILE_NOT_FOUND or Interop.Errors.ERROR_INVALID_NAME => OpenExistingResult.NameNotFound, Interop.Errors.ERROR_PATH_NOT_FOUND => OpenExistingResult.PathNotFound, Interop.Errors.ERROR_INVALID_HANDLE => OpenExistingResult.NameInvalid, _ => throw Win32Marshal.GetExceptionForLastWin32Error() });
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(SR.GetString("InvalidNullEmptyArgument", new object[] { "name" }), "name"); } if ((name != null) && (MAX_PATH < name.Length)) { throw new ArgumentException(SR.GetString("Argument_WaitHandleNameTooLong")); } SafeWaitHandle handle = Microsoft.Win32.SafeNativeMethods.OpenSemaphore((int)rights, false, name); if (handle.IsInvalid) { int num = Marshal.GetLastWin32Error(); if ((2 == num) || (0x7b == num)) { throw new WaitHandleCannotBeOpenedException(); } if (((name != null) && (name.Length != 0)) && (6 == num)) { throw new WaitHandleCannotBeOpenedException(SR.GetString("WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name })); } InternalResources.WinIOError(); } return(new Semaphore(handle)); }
public SemaphoreAuditRule(IdentityReference identity, SemaphoreRights semaphoreRights, AuditFlags flags) : base(identity, 0, false, InheritanceFlags.None, PropagationFlags.None, flags) { this.semaphoreRights = semaphoreRights; }
public SemaphoreAccessRule (string identity, SemaphoreRights semaphoreRights, AccessControlType type) : base (null, 0, false, InheritanceFlags.None, PropagationFlags.None, type) { this.semaphoreRights = semaphoreRights; }
public SemaphoreAuditRule (IdentityReference identity, SemaphoreRights semaphoreRights, AuditFlags flags) : base (identity, 0, false, InheritanceFlags.None, PropagationFlags.None, flags) { this.semaphoreRights = semaphoreRights; }
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { if (name == null) { throw new ArgumentNullException("name"); } if ((name.Length == 0) || (name.Length > 260)) { throw new ArgumentException("name", Locale.GetText("Invalid length [1-260].")); } MonoIOError error; IntPtr handle = OpenSemaphore_internal(name, rights, out error); if (handle == (IntPtr)null) { if (error == MonoIOError.ERROR_FILE_NOT_FOUND) { throw new WaitHandleCannotBeOpenedException(Locale.GetText("Named Semaphore handle does not exist: ") + name); } else if (error == MonoIOError.ERROR_ACCESS_DENIED) { throw new UnauthorizedAccessException(); } else { throw new IOException(Locale.GetText("Win32 IO error: ") + error.ToString()); } } return(new Semaphore(handle)); }
public void SendMessage(string username, SemaphoreRights message) { Clients.All.showMessage(username, message); Groups.Add(Context.ConnectionId, "Employees"); Clients.Group("Employees").showMessage(username, "Message for Employees: This is how to send message to specifc users"); Clients.Caller.showMessage("System", "Yout message was sent at " + DateTime.Now.ToString("hh:mm:ss")); }
private SemaphoreSecurity GetSemaphoreSecurity(WellKnownSidType sid, SemaphoreRights rights, AccessControlType accessControl) { SemaphoreSecurity security = new SemaphoreSecurity(); SecurityIdentifier identity = new SecurityIdentifier(sid, null); SemaphoreAccessRule accessRule = new SemaphoreAccessRule(identity, rights, accessControl); security.AddAccessRule(accessRule); return(security); }
[Category("NotWorking")] // not implemented in Mono public void OpenExisting_BadRights() { Semaphore s = new Semaphore(0, 1, "bad-rights"); SemaphoreRights rights = (SemaphoreRights)Int32.MinValue; Semaphore existing = Semaphore.OpenExisting("bad-rights", rights); // rights bits aren't validated Assert.IsNotNull(existing, "OpenExisting"); Assert.IsFalse(Object.ReferenceEquals(s, existing), "!ref"); }
private static OpenExistingResult OpenExistingWorker( string name, #if !FEATURE_PAL && !FEATURE_NETCORE SemaphoreRights rights, #endif out Semaphore result) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(SR.GetString(SR.InvalidNullEmptyArgument, "name"), "name"); } if (null != name && MAX_PATH < name.Length) { throw new ArgumentException(SR.GetString(SR.Argument_WaitHandleNameTooLong)); } result = null; //Pass false to OpenSemaphore to prevent inheritedHandles #if FEATURE_PAL || FEATURE_NETCORE const int SYNCHRONIZE = 0x00100000; const int SEMAPHORE_MODIFY_STATE = 0x00000002; SafeWaitHandle myHandle = SafeNativeMethods.OpenSemaphore(SEMAPHORE_MODIFY_STATE | SYNCHRONIZE, false, name); #else SafeWaitHandle myHandle = SafeNativeMethods.OpenSemaphore((int)rights, false, name); #endif if (myHandle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); if (NativeMethods.ERROR_FILE_NOT_FOUND == errorCode || NativeMethods.ERROR_INVALID_NAME == errorCode) { return(OpenExistingResult.NameNotFound); } if (NativeMethods.ERROR_PATH_NOT_FOUND == errorCode) { return(OpenExistingResult.PathNotFound); } if (null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode) { return(OpenExistingResult.NameInvalid); } //this is for passed through NativeMethods Errors InternalResources.WinIOError(); } result = new Semaphore(myHandle); return(OpenExistingResult.Success); }
public void Semaphore_Create_SpecificSecurity(SemaphoreRights rights, AccessControlType accessControl) { SemaphoreSecurity security = GetSemaphoreSecurity(WellKnownSidType.BuiltinUsersSid, rights, accessControl); CreateAndVerifySemaphore( DefaultInitialCount, DefaultMaximumCount, GetRandomName(), security, expectedCreatedNew: true).Dispose(); }
/// <summary> /// Opens a specified named semaphore, if it already exists, applying the desired access rights. /// </summary> /// <param name="name">The name of the semaphore to be opened. If it's prefixed by "Global", it refers to a machine-wide semaphore. If it's prefixed by "Local", or doesn't have a prefix, it refers to a session-wide semaphore. Both prefix and name are case-sensitive.</param> /// <param name="rights">The desired access rights to apply to the returned semaphore.</param> /// <returns>An existing named semaphore.</returns> /// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null" />.</exception> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="WaitHandleCannotBeOpenedException">The named semaphore does not exist or is invalid.</exception> /// <exception cref="IOException">The path was not found. /// -or- /// A Win32 error occurred.</exception> /// <exception cref="UnauthorizedAccessException">The named semaphore exists, but the user does not have the security access required to use it.</exception> public static Semaphore OpenExisting(string name, SemaphoreRights rights) { switch (OpenExistingWorker(name, rights, out Semaphore? result)) { case OpenExistingResult.NameNotFound: throw new WaitHandleCannotBeOpenedException(); case OpenExistingResult.NameInvalid: throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); case OpenExistingResult.PathNotFound: throw new IOException(SR.Format(SR.IO_PathNotFound_Path, name)); case OpenExistingResult.Success: default: Debug.Assert(result != null, "result should be non-null on success"); return(result); } }
public static bool TryOpenExisting(string name, SemaphoreRights rights, out Semaphore result) { if (name == null) { throw new ArgumentNullException("name"); } if ((name.Length == 0) || (name.Length > 260)) { throw new ArgumentException("name", Locale.GetText("Invalid length [1-260].")); } MonoIOError error; IntPtr handle = OpenSemaphore_internal(name, rights, out error); if (handle == (IntPtr)null) { result = null; return(false); } result = new Semaphore(handle); return(true); }
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { Semaphore result; switch (OpenExistingWorker(name, rights, out result)) #else //FEATURE_PAL || FEATURE_NETCORE Semaphore result; switch (OpenExistingWorker(name, out result)) #endif //FEATURE_PAL || FEATURE_NETCORE { case OpenExistingResult.NameNotFound: throw new WaitHandleCannotBeOpenedException(); case OpenExistingResult.NameInvalid: throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle, name)); case OpenExistingResult.PathNotFound: InternalResources.WinIOError(NativeMethods.ERROR_PATH_NOT_FOUND, string.Empty); return(result); //never executes default: return(result); } }
private static extern IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out int errorCode);
public static bool TryOpenExisting(string name, SemaphoreRights rights, out Semaphore result) { return(OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success); }
public SemaphoreAuditRule(IdentityReference identity, SemaphoreRights eventRights, AuditFlags flags) : this(identity, (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, flags) { }
public static Semaphore OpenExisting (string name, SemaphoreRights rights) { if (name == null) throw new ArgumentNullException ("name"); if ((name.Length ==0) || (name.Length > 260)) throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260].")); MonoIOError error; IntPtr handle = OpenSemaphore_internal (name, rights, out error); if (handle == (IntPtr)null) { if (error == MonoIOError.ERROR_FILE_NOT_FOUND) { throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Semaphore handle does not exist: ") + name); } else if (error == MonoIOError.ERROR_ACCESS_DENIED) { throw new UnauthorizedAccessException (); } else { throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ()); } } return(new Semaphore (handle)); }
// Constructor for creating access rules for registry objects public SemaphoreAccessRule(IdentityReference identity, SemaphoreRights eventRights, AccessControlType type) : this(identity, (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, type) { }
// Constructor. public SemaphoreAuditRule (IdentityReference identity, SemaphoreRights semaphoreRights, AuditFlags auditFlags) : base(identity, (int)semaphoreRights, false, InheritanceFlags.None, PropagationFlags.None, auditFlags) {}
private unsafe static extern IntPtr OpenSemaphore_icall(char *name, int name_length, SemaphoreRights rights, out int errorCode);
public static bool TryOpenExisting(string name, SemaphoreRights rights, [NotNullWhen(true)] out Semaphore result) { return(Semaphore.TryOpenExisting(name, rights, out result)); }
// Constructors public SemaphoreAuditRule(System.Security.Principal.IdentityReference identity, SemaphoreRights eventRights, AuditFlags flags) { }
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { return(Semaphore.OpenExisting(name, rights)); }
public SemaphoreAuditRule(System.Security.Principal.IdentityReference identity, SemaphoreRights eventRights, AuditFlags flags) : base (default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AuditFlags)) { }
public static bool TryOpenExisting (string name, SemaphoreRights rights, out Semaphore result) { throw new NotSupportedException (); }
public SemaphoreAccessRule(string identity, SemaphoreRights semaphoreRights, AccessControlType type) : this(new NTAccount(identity), semaphoreRights, type) { }
public static Semaphore OpenExisting (string name, SemaphoreRights rights) { throw new NotSupportedException (); }
/// <summary> /// Tries to open a specified named semaphore, if it already exists, applying the desired access rights, and returns a value that indicates whether the operation succeeded. /// </summary> /// <param name="name">The name of the semaphore to be opened. If it's prefixed by "Global", it refers to a machine-wide semaphore. If it's prefixed by "Local", or doesn't have a prefix, it refers to a session-wide semaphore. Both prefix and name are case-sensitive.</param> /// <param name="rights">The desired access rights to apply to the returned semaphore.</param> /// <param name="result">When this method returns <see langword="true" />, contains an object that represents the named semaphore if the call succeeded, or <see langword="null" /> otherwise. This parameter is treated as uninitialized.</param> /// <returns><see langword="true" /> if the named semaphore was opened successfully; otherwise, <see langword="false" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null" /></exception> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="IOException">A Win32 error occurred.</exception> /// <exception cref="UnauthorizedAccessException">The named semaphore exists, but the user does not have the security access required to use it.</exception> public static bool TryOpenExisting(string name, SemaphoreRights rights, [NotNullWhen(returnValue: true)] out Semaphore?result) => OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success;
// Constructors public SemaphoreAccessRule(System.Security.Principal.IdentityReference identity, SemaphoreRights eventRights, AccessControlType type) { }
public SemaphoreAccessRule(string identity, SemaphoreRights eventRights, AccessControlType type);
private static extern IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out MonoIOError error);
public static bool TryOpenExisting (string name, SemaphoreRights rights, out Semaphore result) { if (name == null) throw new ArgumentNullException ("name"); if ((name.Length == 0) || (name.Length > 260)) throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260].")); MonoIOError error; IntPtr handle = OpenSemaphore_internal (name, rights, out error); if (handle == (IntPtr)null) { result = null; return false; } result = new Semaphore (handle); return true; }
public SemaphoreAccessRule(String identity, SemaphoreRights eventRights, AccessControlType type) : this(new NTAccount(identity), (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, type) { }
public static bool TryOpenExisting(string name, SemaphoreRights rights, out Semaphore result) { return OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success; }
public SemaphoreAccessRule(System.Security.Principal.IdentityReference identity, SemaphoreRights eventRights, AccessControlType type) : base (default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AccessControlType)) { }
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { Semaphore result; switch (OpenExistingWorker(name, rights, out result)) #else //FEATURE_PAL || FEATURE_NETCORE Semaphore result; switch (OpenExistingWorker(name, out result)) #endif //FEATURE_PAL || FEATURE_NETCORE { case OpenExistingResult.NameNotFound: throw new WaitHandleCannotBeOpenedException(); case OpenExistingResult.NameInvalid: throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle, name)); case OpenExistingResult.PathNotFound: InternalResources.WinIOError(NativeMethods.ERROR_PATH_NOT_FOUND, string.Empty); return result; //never executes default: return result; } }
public static bool TryOpenExisting(string name, SemaphoreRights rights, ref Semaphore result) { throw new NotImplementedException(); }
private static OpenExistingResult OpenExistingWorker( string name, #if !FEATURE_PAL && !FEATURE_NETCORE SemaphoreRights rights, #endif out Semaphore result) { if (name == null) { throw new ArgumentNullException("name"); } if(name.Length == 0) { throw new ArgumentException(SR.GetString(SR.InvalidNullEmptyArgument, "name"), "name"); } if(null != name && MAX_PATH < name.Length) { throw new ArgumentException(SR.GetString(SR.Argument_WaitHandleNameTooLong)); } result = null; //Pass false to OpenSemaphore to prevent inheritedHandles #if FEATURE_PAL || FEATURE_NETCORE SafeWaitHandle myHandle = SafeNativeMethods.OpenSemaphore(Win32Native.SEMAPHORE_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name); #else SafeWaitHandle myHandle = SafeNativeMethods.OpenSemaphore((int) rights, false, name); #endif if (myHandle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); if (NativeMethods.ERROR_FILE_NOT_FOUND == errorCode || NativeMethods.ERROR_INVALID_NAME == errorCode) return OpenExistingResult.NameNotFound; if (NativeMethods.ERROR_PATH_NOT_FOUND == errorCode) return OpenExistingResult.PathNotFound; if (null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode) return OpenExistingResult.NameInvalid; //this is for passed through NativeMethods Errors InternalResources.WinIOError(); } result = new Semaphore(myHandle); return OpenExistingResult.Success; }
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { throw new NotSupportedException(); }
public static bool TryOpenExisting(string name, SemaphoreRights rights, out Semaphore result) { throw new NotSupportedException(); }
private static extern IntPtr OpenSemaphore_internal(string name, SemaphoreRights rights, out MonoIOError error);
public SemaphoreAccessRule (String identity, SemaphoreRights semaphoreRights, AccessControlType type) : base(IdentityReference.IdentityFromName(identity), (int)semaphoreRights, false, InheritanceFlags.None, PropagationFlags.None, type) {}
public SemaphoreAccessRule (string identity, SemaphoreRights semaphoreRights, AccessControlType type) : this (new NTAccount (identity), semaphoreRights, type) { }
public static Semaphore OpenExisting(string name, SemaphoreRights rights) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(SR.GetString("InvalidNullEmptyArgument", new object[] { "name" }), "name"); } if ((name != null) && (MAX_PATH < name.Length)) { throw new ArgumentException(SR.GetString("Argument_WaitHandleNameTooLong")); } SafeWaitHandle handle = Microsoft.Win32.SafeNativeMethods.OpenSemaphore((int) rights, false, name); if (handle.IsInvalid) { int num = Marshal.GetLastWin32Error(); if ((2 == num) || (0x7b == num)) { throw new WaitHandleCannotBeOpenedException(); } if (((name != null) && (name.Length != 0)) && (6 == num)) { throw new WaitHandleCannotBeOpenedException(SR.GetString("WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name })); } InternalResources.WinIOError(); } return new Semaphore(handle); }
private static extern IntPtr OpenSemaphore_internal(string name, SemaphoreRights rights, out int errorCode);
public SemaphoreAccessRule(IdentityReference identity, SemaphoreRights eventRights, AccessControlType type);
private unsafe static IntPtr OpenSemaphore_internal(string name, SemaphoreRights rights, out int errorCode) { // FIXME Check for embedded nuls in name. fixed(char *fixed_name = name) return(OpenSemaphore_icall(fixed_name, name?.Length ?? 0, rights, out errorCode)); }
public SemaphoreAuditRule(IdentityReference identity, SemaphoreRights eventRights, AuditFlags flags);
private static IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out MonoIOError error) { throw new System.NotImplementedException(); }