Exemple #1
0
		public MutexAccessRule (IdentityReference identity,
					MutexRights eventRights,
					AccessControlType type)
			: base (identity, (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, type)
		{

		}
Exemple #2
0
        private static OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex?result)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
            }

            result = null;
            SafeWaitHandle existingHandle = Interop.Kernel32.OpenMutex((uint)rights, false, name);

            int errorCode = Marshal.GetLastWin32Error();

            if (existingHandle.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.GetExceptionForWin32Error(errorCode, name)
                });
Exemple #3
0
 public MutexAuditRule(IdentityReference identity,
                       MutexRights eventRights,
                       AuditFlags flags)
     : base(identity, 0, false, InheritanceFlags.None, PropagationFlags.None, flags)
 {
     this.rights = eventRights;
 }
Exemple #4
0
		public MutexAuditRule (IdentityReference identity,
				       MutexRights eventRights,
				       AuditFlags flags)
			: base (identity, 0, false, InheritanceFlags.None, PropagationFlags.None, flags)
		{
			this.rights = eventRights;
		}
Exemple #5
0
        public static Mutex OpenExisting(string name,
                                         MutexRights 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 = OpenMutex_internal(name, rights,
                                                    out error);

            if (handle == (IntPtr)null)
            {
                if (error == MonoIOError.ERROR_FILE_NOT_FOUND)
                {
                    throw new WaitHandleCannotBeOpenedException(Locale.GetText("Named Mutex 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 Mutex(handle));
        }
Exemple #6
0
        private static OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex result)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name), Environment.GetResourceString("ArgumentNull_WithParamName"));
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name));
            }
#if !PLATFORM_UNIX
            if (System.IO.Path.MaxPath < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name));
            }
#endif
            Contract.EndContractBlock();

            result = null;

            // To allow users to view & edit the ACL's, call OpenMutex
            // with parameters to allow us to view & edit the ACL.  This will
            // fail if we don't have permission to view or edit the ACL's.
            // If that happens, ask for less permissions.
            SafeWaitHandle myHandle = Win32Native.OpenMutex(Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name);

            int errorCode = 0;
            if (myHandle.IsInvalid)
            {
                errorCode = Marshal.GetLastWin32Error();

#if PLATFORM_UNIX
                if (name != null && errorCode == Win32Native.ERROR_FILENAME_EXCED_RANGE)
                {
                    // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8
                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Interop.Sys.MaxName), nameof(name));
                }
#endif

                if (Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
                {
                    return(OpenExistingResult.NameNotFound);
                }
                if (Win32Native.ERROR_PATH_NOT_FOUND == errorCode)
                {
                    return(OpenExistingResult.PathNotFound);
                }
                if (null != name && Win32Native.ERROR_INVALID_HANDLE == errorCode)
                {
                    return(OpenExistingResult.NameInvalid);
                }

                // this is for passed through Win32Native Errors
                __Error.WinIOError(errorCode, name);
            }

            result = new Mutex(myHandle);
            return(OpenExistingResult.Success);
        }
Exemple #7
0
 // Constructor.
 public MutexAccessRule
     (IdentityReference identity, MutexRights mutexRights,
     AccessControlType type)
     : base(identity, (int)mutexRights, false,
            InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
Exemple #8
0
 // Constructor.
 public MutexAuditRule
     (IdentityReference identity, MutexRights mutexRights,
     AuditFlags auditFlags)
     : base(identity, (int)mutexRights, false,
            InheritanceFlags.None, PropagationFlags.None, auditFlags)
 {
 }
Exemple #9
0
        public static Mutex OpenExisting(string name, MutexRights rights)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            }
            if (260 < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name }));
            }
            SafeWaitHandle handle    = Win32Native.OpenMutex((int)rights, false, name);
            int            errorCode = 0;

            if (handle.IsInvalid)
            {
                errorCode = Marshal.GetLastWin32Error();
                if ((2 == errorCode) || (0x7b == errorCode))
                {
                    throw new WaitHandleCannotBeOpenedException();
                }
                if (((name != null) && (name.Length != 0)) && (6 == errorCode))
                {
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name }));
                }
                __Error.WinIOError(errorCode, name);
            }
            return(new Mutex(handle));
        }
Exemple #10
0
 public MutexAccessRule(IdentityReference identity,
                        MutexRights eventRights,
                        AccessControlType type)
 // FIXME: accessMask=0 likely causes an error
     : base(identity, 0, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
     this.rights = eventRights;
 }
Exemple #11
0
		public MutexAccessRule (IdentityReference identity,
					MutexRights eventRights,
					AccessControlType type)
			// FIXME: accessMask=0 likely causes an error
			: base (identity, 0, false, InheritanceFlags.None, PropagationFlags.None, type)
		{
			this.rights = eventRights;
		}
Exemple #12
0
        private static OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex result)
        {
#if PLATFORM_UNIX
            throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_NamedSynchronizationPrimitives"));
#else
            if (name == null)
            {
                throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            }
            if (System.IO.Path.MaxPath < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
            }
            Contract.EndContractBlock();

            result = null;

            // To allow users to view & edit the ACL's, call OpenMutex
            // with parameters to allow us to view & edit the ACL.  This will
            // fail if we don't have permission to view or edit the ACL's.
            // If that happens, ask for less permissions.
#if FEATURE_MACL
            SafeWaitHandle myHandle = Win32Native.OpenMutex((int)rights, false, name);
#else
            SafeWaitHandle myHandle = Win32Native.OpenMutex(Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name);
#endif

            int errorCode = 0;
            if (myHandle.IsInvalid)
            {
                errorCode = Marshal.GetLastWin32Error();

                if (Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
                {
                    return(OpenExistingResult.NameNotFound);
                }
                if (Win32Native.ERROR_PATH_NOT_FOUND == errorCode)
                {
                    return(OpenExistingResult.PathNotFound);
                }
                if (null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode)
                {
                    return(OpenExistingResult.NameInvalid);
                }

                // this is for passed through Win32Native Errors
                __Error.WinIOError(errorCode, name);
            }

            result = new Mutex(myHandle);
            return(OpenExistingResult.Success);
#endif
        }
        private MutexSecurity GetMutexSecurity(WellKnownSidType sid, MutexRights rights, AccessControlType accessControl)
        {
            MutexSecurity      security   = new MutexSecurity();
            SecurityIdentifier identity   = new SecurityIdentifier(sid, null);
            MutexAccessRule    accessRule = new MutexAccessRule(identity, rights, accessControl);

            security.AddAccessRule(accessRule);
            return(security);
        }
Exemple #14
0
        public static bool TryOpenExisting(string name, MutexRights rights, out Mutex result)
        {
            SafeWaitHandle myHandle = OpenMutex((uint)rights, false, name);

            result = null;
            if (myHandle.IsInvalid)
            {
                return(false);
            }
            result = new Mutex(initiallyOwned: false);
            SafeWaitHandle old = result.SafeWaitHandle;

            result.SafeWaitHandle = myHandle;
            old.Dispose();

            return(true);
        }
Exemple #15
0
        /// <summary>
        /// Opens a specified named mutex, if it already exists, applying the desired access rights.
        /// </summary>
        /// <param name="name">The name of the mutex to be opened. If it's prefixed by "Global", it refers to a machine-wide mutex. If it's prefixed by "Local", or doesn't have a prefix, it refers to a session-wide mutex. Both prefix and name are case-sensitive.</param>
        /// <param name="rights">The desired access rights to apply to the returned mutex.</param>
        /// <returns>An existing named mutex.</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 mutex does not exist or is invalid.</exception>
        /// <exception cref="DirectoryNotFoundException">The path was not found.</exception>
        /// <exception cref="IOException">A Win32 error occurred.</exception>
        /// <exception cref="UnauthorizedAccessException">The named mutex exists, but the user does not have the security access required to use it.</exception>
        public static Mutex OpenExisting(string name, MutexRights rights)
        {
            switch (OpenExistingWorker(name, rights, out Mutex? 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 DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, name));

            case OpenExistingResult.Success:
            default:
                Debug.Assert(result != null, "result should be non-null on success");
                return(result);
            }
        }
Exemple #16
0
        internal static Mutex OpenExisting(string name, MutexRights rights)
        {
            Mutex result;

            switch (OpenExistingWorker(name, rights, out result))
            {
            case OpenExistingResult.NameNotFound:
                throw new WaitHandleCannotBeOpenedException();

            case OpenExistingResult.NameInvalid:
                throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));

            case OpenExistingResult.PathNotFound:
                throw Win32Marshal.GetExceptionForWin32Error(Win32Native.ERROR_PATH_NOT_FOUND, name);

            default:
                return(result);
            }
        }
Exemple #17
0
        public static Mutex OpenExisting(string name, MutexRights rights)
        {
            Mutex result;

            switch (Mutex.OpenExistingWorker(name, rights, out result))
            {
            case WaitHandle.OpenExistingResult.NameNotFound:
                throw new WaitHandleCannotBeOpenedException();

            case WaitHandle.OpenExistingResult.PathNotFound:
                __Error.WinIOError(3, name);
                return(result);

            case WaitHandle.OpenExistingResult.NameInvalid:
                throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", (object)name));

            default:
                return(result);
            }
        }
Exemple #18
0
        public static Mutex OpenExisting(string name, MutexRights rights)
        {
            Mutex result;

            switch (OpenExistingWorker(name, rights, out result))
            {
            case OpenExistingResult.NameNotFound:
                throw new WaitHandleCannotBeOpenedException();

            case OpenExistingResult.NameInvalid:
                throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name));

            case OpenExistingResult.PathNotFound:
                __Error.WinIOError(Win32Native.ERROR_PATH_NOT_FOUND, name);
                return(result);    //never executes

            default:
                return(result);
            }
        }
        private static WaitHandle.OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex result)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            }
            if (260 < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[]
                {
                    name
                }));
            }
            result = null;
            SafeWaitHandle safeWaitHandle = Win32Native.OpenMutex((int)rights, false, name);

            if (safeWaitHandle.IsInvalid)
            {
                int lastWin32Error = Marshal.GetLastWin32Error();
                if (2 == lastWin32Error || 123 == lastWin32Error)
                {
                    return(WaitHandle.OpenExistingResult.NameNotFound);
                }
                if (3 == lastWin32Error)
                {
                    return(WaitHandle.OpenExistingResult.PathNotFound);
                }
                if (name != null && name.Length != 0 && 6 == lastWin32Error)
                {
                    return(WaitHandle.OpenExistingResult.NameInvalid);
                }
                __Error.WinIOError(lastWin32Error, name);
            }
            result = new Mutex(safeWaitHandle);
            return(WaitHandle.OpenExistingResult.Success);
        }
Exemple #20
0
        public static bool TryOpenExisting(string name, MutexRights rights, out Mutex 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 = OpenMutex_internal(name, rights, out error);

            if (handle == (IntPtr)null)
            {
                result = null;
                return(false);
            }

            result = new Mutex(handle);
            return(true);
        }
Exemple #21
0
		public static Mutex OpenExisting (string name, MutexRights rights)
		{
         throw new NotImplementedException ();
		}
Exemple #22
0
 public MutexAccessRule(string identity,
                        MutexRights eventRights,
                        AccessControlType type)
     : this(new SecurityIdentifier(identity), eventRights, type)
 {
 }
 public MutexAuditRule(System.Security.Principal.IdentityReference identity, MutexRights eventRights, AuditFlags flags) : base (default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AuditFlags))
 {
 }
 [System.Security.SecurityCritical]  // auto-generated_required
 public static bool TryOpenExisting(string name, MutexRights rights, out Mutex result)
 {
     return OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success;
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.AccessControl.MutexAccessRule" /> class, specifying the user or group the rule applies to, the access rights, and whether the specified access rights are allowed or denied.</summary>
 /// <param name="identity">The user or group the rule applies to. Must be of type <see cref="T:System.Security.Principal.SecurityIdentifier" /> or a type such as <see cref="T:System.Security.Principal.NTAccount" /> that can be converted to type <see cref="T:System.Security.Principal.SecurityIdentifier" />.</param>
 /// <param name="eventRights">A bitwise combination of <see cref="T:System.Security.AccessControl.MutexRights" /> values specifying the rights allowed or denied.</param>
 /// <param name="type">One of the <see cref="T:System.Security.AccessControl.AccessControlType" /> values specifying whether the rights are allowed or denied.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///   <paramref name="eventRights" /> specifies an invalid value.-or-<paramref name="type" /> specifies an invalid value.</exception>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="identity" /> is null. -or-<paramref name="eventRights" /> is zero.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="identity" /> is neither of type <see cref="T:System.Security.Principal.SecurityIdentifier" /> nor of a type such as <see cref="T:System.Security.Principal.NTAccount" /> that can be converted to type <see cref="T:System.Security.Principal.SecurityIdentifier" />.</exception>
 public MutexAccessRule(IdentityReference identity, MutexRights eventRights, AccessControlType type) : base(identity, 0, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
     this.rights = eventRights;
 }
Exemple #26
0
 private unsafe static IntPtr OpenMutex_internal(string name, MutexRights rights, out MonoIOError error)
 {
     fixed(char *fixed_name = name)
     return(OpenMutex_icall(fixed_name, name?.Length ?? 0, rights, out error));
 }
Exemple #27
0
 public MutexAccessRule(System.Security.Principal.IdentityReference identity, MutexRights eventRights, AccessControlType type) : base(default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AccessControlType))
 {
 }
Exemple #28
0
		private static extern IntPtr OpenMutex_internal (string name, MutexRights rights, out MonoIOError error);
	public MutexAccessRule
				(String identity, MutexRights mutexRights,
				 AccessControlType type)
			: base(IdentityReference.IdentityFromName(identity),
				   (int)mutexRights, false, InheritanceFlags.None,
				   PropagationFlags.None, type) {}
Exemple #30
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.AccessControl.MutexAccessRule" /> class, specifying the name of the user or group the rule applies to, the access rights, and whether the specified access rights are allowed or denied.</summary>
 /// <param name="identity">The name of the user or group the rule applies to.</param>
 /// <param name="eventRights">A bitwise combination of <see cref="T:System.Security.AccessControl.MutexRights" /> values specifying the rights allowed or denied.</param>
 /// <param name="type">One of the <see cref="T:System.Security.AccessControl.AccessControlType" /> values specifying whether the rights are allowed or denied.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///         <paramref name="eventRights" /> specifies an invalid value.-or-
 ///         <paramref name="type" /> specifies an invalid value.</exception>
 /// <exception cref="T:System.ArgumentNullException">
 ///         <paramref name="eventRights" /> is zero.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///         <paramref name="identity" /> is <see langword="null" />.-or-
 ///         <paramref name="identity" /> is a zero-length string.-or-
 ///         <paramref name="identity" /> is longer than 512 characters.</exception>
 // Token: 0x06001F61 RID: 8033 RVA: 0x0006DB4E File Offset: 0x0006BD4E
 public MutexAccessRule(string identity, MutexRights eventRights, AccessControlType type) : this(new NTAccount(identity), (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
Exemple #31
0
		public static Mutex OpenExisting (string name,
						  MutexRights 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 = OpenMutex_internal (name, rights,
							    out error);
			if (handle == (IntPtr)null) {
				if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
					throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Mutex 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 Mutex (handle));
		}
Exemple #32
0
        private static OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex result)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
            }

            if(name.Length  == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            }
            if(System.IO.Path.MAX_PATH < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
            }
            Contract.EndContractBlock();

            result = null;

#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                name = WinCEObjectNameQuirk(name);
#endif

            // To allow users to view & edit the ACL's, call OpenMutex
            // with parameters to allow us to view & edit the ACL.  This will
            // fail if we don't have permission to view or edit the ACL's.  
            // If that happens, ask for less permissions.
#if FEATURE_MACL
            SafeWaitHandle myHandle = Win32Native.OpenMutex((int) rights, false, name);
#else
            SafeWaitHandle myHandle = Win32Native.OpenMutex(Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name);
#endif

            int errorCode = 0;
            if (myHandle.IsInvalid)
            {
                errorCode = Marshal.GetLastWin32Error();

                if(Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
                    return OpenExistingResult.NameNotFound;
                if (Win32Native.ERROR_PATH_NOT_FOUND == errorCode)
                    return OpenExistingResult.PathNotFound;
                if (null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode) 
                    return OpenExistingResult.NameInvalid;

                // this is for passed through Win32Native Errors
                __Error.WinIOError(errorCode,name);
            }

            result = new Mutex(myHandle);
            return OpenExistingResult.Success;
        }
 public static Mutex OpenExisting(string name, MutexRights rights)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     }
     if (260 < name.Length)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name }));
     }
     SafeWaitHandle handle = Win32Native.OpenMutex((int) rights, false, name);
     int errorCode = 0;
     if (handle.IsInvalid)
     {
         errorCode = Marshal.GetLastWin32Error();
         if ((2 == errorCode) || (0x7b == errorCode))
         {
             throw new WaitHandleCannotBeOpenedException();
         }
         if (((name != null) && (name.Length != 0)) && (6 == errorCode))
         {
             throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name }));
         }
         __Error.WinIOError(errorCode, name);
     }
     return new Mutex(handle);
 }
Exemple #34
0
        public static Mutex OpenExisting(string name, MutexRights rights) 
        { 
            if (name == null)
            { 
                throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
            }

            if(name.Length  == 0) 
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); 
            } 
            if(System.IO.Path.MAX_PATH < name.Length)
            { 
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
            }
            Contract.EndContractBlock();
 
            // To allow users to view & edit the ACL's, call OpenMutex
            // with parameters to allow us to view & edit the ACL.  This will 
            // fail if we don't have permission to view or edit the ACL's. 
            // If that happens, ask for less permissions.
#if !FEATURE_PAL && FEATURE_MACL 
            SafeWaitHandle myHandle = Win32Native.OpenMutex((int) rights, false, name);
#else
            SafeWaitHandle myHandle = Win32Native.OpenMutex(Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name);
#endif 

            int errorCode = 0; 
            if (myHandle.IsInvalid) 
            {
                errorCode = Marshal.GetLastWin32Error(); 

                if(Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
                {
                    throw new WaitHandleCannotBeOpenedException(); 
                }
 
                if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode) 
                {
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name)); 
                }

                // this is for passed through Win32Native Errors
                __Error.WinIOError(errorCode,name); 
            }
 
            return new Mutex(myHandle); 
        }
Exemple #35
0
		public static bool TryOpenExisting (string name, MutexRights rights, out Mutex result)
		{
			throw new NotSupportedException ();
		}
		private static IntPtr OpenMutex_internal (string name, MutexRights rights, out MonoIOError error)
		{
			throw new System.NotImplementedException();
		}
		public MutexAccessRule (string identity,
					MutexRights eventRights,
					AccessControlType type)
			: this (new NTAccount (identity), eventRights, type)
		{
		}
	// Constructors
	public MutexAccessRule(System.Security.Principal.IdentityReference identity, MutexRights eventRights, AccessControlType type) {}
Exemple #39
0
 public MutexAccessRule(string identity, MutexRights eventRights, AccessControlType type) : base(default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AccessControlType))
 {
     Contract.Ensures(0 <= identity.Length);
     Contract.Ensures(identity.Length <= 512);
 }
Exemple #40
0
 public MutexAccessRule(String identity, MutexRights eventRights, AccessControlType type)
     : this(new NTAccount(identity), (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, type)
 {
 }
        [System.Security.SecurityCritical]  // auto-generated_required
        public static Mutex OpenExisting(string name, MutexRights rights)
        {
            Mutex result;
            switch (OpenExistingWorker(name, rights, out result))
            {
                case OpenExistingResult.NameNotFound:
                    throw new WaitHandleCannotBeOpenedException();

                case OpenExistingResult.NameInvalid:
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name));

                case OpenExistingResult.PathNotFound:
                    __Error.WinIOError(Win32Native.ERROR_PATH_NOT_FOUND, name);
                    return result; //never executes

                default:
                    return result;
            }
        }
	// Constructors
	public MutexAuditRule(System.Security.Principal.IdentityReference identity, MutexRights eventRights, AuditFlags flags) {}
        private static OpenExistingResult OpenExistingWorker(string name, MutexRights rights, out Mutex result)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName"));
            }

            if(name.Length  == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            }
#if !PLATFORM_UNIX
            if(System.IO.Path.MaxPath < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name");
            }
#endif
            Contract.EndContractBlock();

            result = null;

            // To allow users to view & edit the ACL's, call OpenMutex
            // with parameters to allow us to view & edit the ACL.  This will
            // fail if we don't have permission to view or edit the ACL's.  
            // If that happens, ask for less permissions.
#if FEATURE_MACL
            SafeWaitHandle myHandle = Win32Native.OpenMutex((int) rights, false, name);
#else
            SafeWaitHandle myHandle = Win32Native.OpenMutex(Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name);
#endif

            int errorCode = 0;
            if (myHandle.IsInvalid)
            {
                errorCode = Marshal.GetLastWin32Error();

#if PLATFORM_UNIX
                if (name != null && errorCode == Win32Native.ERROR_FILENAME_EXCED_RANGE)
                {
                    // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8
                    throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPathComponentLength), "name");
                }
#endif

                if(Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
                    return OpenExistingResult.NameNotFound;
                if (Win32Native.ERROR_PATH_NOT_FOUND == errorCode)
                    return OpenExistingResult.PathNotFound;
                if (null != name && Win32Native.ERROR_INVALID_HANDLE == errorCode)
                    return OpenExistingResult.NameInvalid;

                // this is for passed through Win32Native Errors
                __Error.WinIOError(errorCode,name);
            }

            result = new Mutex(myHandle);
            return OpenExistingResult.Success;
        }
 public MutexAccessRule(System.Security.Principal.IdentityReference identity, MutexRights eventRights, AccessControlType type) : base (default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AccessControlType))
 {
 }
 public MutexAccessRule(string identity, MutexRights eventRights, AccessControlType type) : base (default(System.Security.Principal.IdentityReference), default(int), default(bool), default(InheritanceFlags), default(PropagationFlags), default(AccessControlType))
 {
   Contract.Ensures(0 <= identity.Length);
   Contract.Ensures(identity.Length <= 512);
 }
	// Constructor.
	public MutexAuditRule
				(IdentityReference identity, MutexRights mutexRights,
				 AuditFlags auditFlags)
			: base(identity, (int)mutexRights, false,
				   InheritanceFlags.None, PropagationFlags.None, auditFlags) {}
Exemple #47
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.AccessControl.MutexAccessRule" /> class, specifying the name of the user or group the rule applies to, the access rights, and whether the specified access rights are allowed or denied.</summary><param name="identity">The name of the user or group the rule applies to.</param><param name="eventRights">A bitwise combination of <see cref="T:System.Security.AccessControl.MutexRights" /> values specifying the rights allowed or denied.</param><param name="type">One of the <see cref="T:System.Security.AccessControl.AccessControlType" /> values specifying whether the rights are allowed or denied.</param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="eventRights" /> specifies an invalid value.-or-<paramref name="type" /> specifies an invalid value.</exception><exception cref="T:System.ArgumentNullException"><paramref name="eventRights" /> is zero.</exception><exception cref="T:System.ArgumentException"><paramref name="identity" /> is null.-or-<paramref name="identity" /> is a zero-length string.-or-<paramref name="identity" /> is longer than 512 characters.</exception>
 public MutexAccessRule(string identity, MutexRights eventRights, AccessControlType type)
     : base(null, 0, false, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
 {
     throw new NotImplementedException();
 }
 public MutexAccessRule(IdentityReference identity, MutexRights eventRights, AccessControlType type);
Exemple #49
0
		public MutexAccessRule (string identity,
					MutexRights eventRights,
					AccessControlType type)
			: this (new SecurityIdentifier (identity), eventRights, type)
		{
		}
 public MutexAuditRule(IdentityReference identity, MutexRights eventRights, AuditFlags flags);
 public static extern SafeWaitHandle OpenMutex(MutexRights desiredAccess, bool inheritHandle, string name);
Exemple #52
0
		public static bool TryOpenExisting (string name, MutexRights rights, out Mutex 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 = OpenMutex_internal (name, rights, out error);
			if (handle == (IntPtr)null) {
				result = null;
				return false;
			}

			result = new Mutex (handle);
			return true;
		}
Exemple #53
0
 /// <summary>初始化 <see cref="T:System.Security.AccessControl.MutexAuditRule" /> 类的新实例,指定要审核的用户或组,要审核的权限,以及是否审核成功和(或)失败。</summary>
 /// <param name="identity">此规则应用到的用户或组。必须为 <see cref="T:System.Security.Principal.SecurityIdentifier" /> 类型,或可以转换为 <see cref="T:System.Security.Principal.SecurityIdentifier" /> 类型的类型,如 <see cref="T:System.Security.Principal.NTAccount" />。</param>
 /// <param name="eventRights">
 /// <see cref="T:System.Security.AccessControl.MutexRights" /> 值的按位组合,它指定要审核的访问类型。</param>
 /// <param name="flags">
 /// <see cref="T:System.Security.AccessControl.AuditFlags" /> 值的按位组合,它指定审核是成功、失败还是包括这两种情况。</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// <paramref name="eventRights" /> 指定了一个无效值。- 或 -<paramref name="flags" /> 指定了一个无效值。</exception>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="identity" /> 为 null。- 或 -<paramref name="eventRights" /> 是零。</exception>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="identity" /> 既不属于类型 <see cref="T:System.Security.Principal.SecurityIdentifier" />,也不属于可以转换为 <see cref="T:System.Security.Principal.SecurityIdentifier" /> 类型的类型(如 <see cref="T:System.Security.Principal.NTAccount" />)。</exception>
 public MutexAuditRule(IdentityReference identity, MutexRights eventRights, AuditFlags flags)
     : this(identity, (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, flags)
 {
 }
Exemple #54
0
 public static Mutex OpenExisting(string name, MutexRights rights)
 {
     throw new NotSupportedException();
 }
 public MutexAccessRule(string identity, MutexRights eventRights, AccessControlType type);
Exemple #56
0
 public static bool TryOpenExisting(string name, MutexRights rights, out Mutex result)
 {
     throw new NotSupportedException();
 }
Exemple #57
0
 private unsafe static extern IntPtr OpenMutex_icall(char *name, int name_length,
                                                     MutexRights rights, out MonoIOError error);
Exemple #58
0
 public IMutex OpenExisting(string name, MutexRights rights)
 {
     return new MutexWrap(Mutex.OpenExisting(name,rights));
 }
Exemple #59
0
 public static bool TryOpenExisting(string name, MutexRights rights, out Mutex result)
 {
     return(OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success);
 }
Exemple #60
0
 public MutexAuditRule(IdentityReference identity, MutexRights eventRights, AuditFlags flags)
     : this(identity, (int)eventRights, false, InheritanceFlags.None, PropagationFlags.None, flags)
 {
 }