/// <summary> /// RuleBasedCollator constructor. /// This takes the table rules and builds a collation table out of them. /// </summary> /// <param name="rules">the collation rules to build the collation table from</param> /// <param name="normalizationMode">the normalization mode to use</param> /// <param name="collationStrength">the collation strength to use</param> public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; var parseError = new ParseError(); _collatorHandle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref parseError, out status); try { ExceptionFromErrorCode.ThrowIfError(status, parseError.ToString(rules)); } catch { if (_collatorHandle != default(SafeRuleBasedCollatorHandle)) { _collatorHandle.Dispose(); } _collatorHandle = default(SafeRuleBasedCollatorHandle); throw; } }
private void SetAttribute(NativeMethods.CollationAttribute attr, NativeMethods.CollationAttributeValue value) { ErrorCode e; NativeMethods.ucol_setAttribute(_collatorHandle, attr, value, out e); ExceptionFromErrorCode.ThrowIfError(e); }
protected NativeObjectSecurity (bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this (isContainer, resourceType) { }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { }
private NativeMethods.CollationAttributeValue GetAttribute(NativeMethods.CollationAttribute attr) { ErrorCode e; NativeMethods.CollationAttributeValue value = NativeMethods.ucol_getAttribute(_collatorHandle, attr, out e); ExceptionFromErrorCode.ThrowIfError(e); return(value); }
private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { RawSecurityDescriptor descriptor; if (createByName && (name == null)) { throw new ArgumentNullException("name"); } if (!createByName && (handle == null)) { throw new ArgumentNullException("handle"); } int errorCode = System.Security.AccessControl.Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out descriptor); if (errorCode == 0) { return new CommonSecurityDescriptor(isContainer, false, descriptor, true); } Exception exception = null; if (exceptionFromErrorCode != null) { exception = exceptionFromErrorCode(errorCode, name, handle, exceptionContext); } if (exception == null) { switch (errorCode) { case 5: exception = new UnauthorizedAccessException(); goto Label_0132; case 0x51b: exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidOwner")); goto Label_0132; case 0x51c: exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidGroup")); goto Label_0132; case 0x57: exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", new object[] { errorCode })); goto Label_0132; case 0x7b: exception = new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), "name"); goto Label_0132; case 2: exception = (name == null) ? new FileNotFoundException() : new FileNotFoundException(name); goto Label_0132; case 0x546: exception = new NotSupportedException(Environment.GetResourceString("AccessControl_NoAssociatedSecurity")); goto Label_0132; } exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", new object[] { errorCode })); } Label_0132: throw exception; }
/// <summary> /// Opens a Collator for comparing strings using the given locale id. /// </summary> /// <param name="localeId">Locale to use</param> /// <param name="fallback">Whether to allow locale fallback or not.</param> public new static Collator Create(string localeId, Fallback fallback) { // Culture identifiers in .NET are created using '-', while ICU // expects '_'. We want to make sure that the localeId is the // format that ICU expects. var locale = new Locale(localeId); var instance = new RuleBasedCollator(); ErrorCode status; instance._collatorHandle = NativeMethods.ucol_open(locale.Id, out status); try { if (status == ErrorCode.USING_FALLBACK_WARNING && fallback == Fallback.NoFallback) { throw new ArgumentException( $"Could only create Collator '{localeId}' by falling back to " + $"'{instance.ActualId}'. You can use the fallback option to create this."); } if (status == ErrorCode.USING_DEFAULT_WARNING && fallback == Fallback.NoFallback && !instance.ValidId.Equals(locale.Id) && locale.Id.Length > 0 && !locale.Id.Equals("root")) { throw new ArgumentException( $"Could only create Collator '{localeId}' by falling back to the default " + $"'{instance.ActualId}'. You can use the fallback option to create this."); } if (status == ErrorCode.INTERNAL_PROGRAM_ERROR && fallback == Fallback.FallbackAllowed) { instance = new RuleBasedCollator(string.Empty); // fallback to UCA } else { try { ExceptionFromErrorCode.ThrowIfError(status); } catch (Exception e) { throw new ArgumentException( $"Unable to create a collator using the given localeId '{localeId}'.\n" + "This is likely because the ICU data file was created without collation " + "rules for this locale. You can provide the rules yourself or replace " + "the data dll.", e); } } return(instance); } catch { if (instance._collatorHandle != default(SafeRuleBasedCollatorHandle)) { instance._collatorHandle.Dispose(); } instance._collatorHandle = default(SafeRuleBasedCollatorHandle); throw; } }
protected NativeObjectSecurity (bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this (isContainer, resourceType, handle, includeSections) { }
internal NativeObjectSecurity(ResourceType resourceType, CommonSecurityDescriptor securityDescriptor, ExceptionFromErrorCode exceptionFromErrorCode) : base(securityDescriptor) { this.ProtectedDiscretionaryAcl = 0x80000000; this.ProtectedSystemAcl = 0x40000000; this.UnprotectedDiscretionaryAcl = 0x20000000; this.UnprotectedSystemAcl = 0x10000000; this._resourceType = resourceType; this._exceptionFromErrorCode = exceptionFromErrorCode; }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this(isContainer, resourceType, handle, includeSections) { }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : base(isContainer) { exception_from_error_code = exceptionFromErrorCode; resource_type = resourceType; }
protected NativeObjectSecurity (bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : base (isContainer) { exception_from_error_code = exceptionFromErrorCode; resource_type = resourceType; }
protected ObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle safeHandle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : base(isContainer, resourceType, safeHandle, includeSections, exceptionFromErrorCode, exceptionContext) { }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this(isContainer, resourceType, exceptionFromErrorCode, exceptionContext) { RaiseExceptionOnFailure(InternalGet(name, includeSections), name, null, exceptionContext); ClearAccessControlSectionsModified(); }
/// <summary> /// Tests if the string is normalized. /// </summary> /// <param name="src">input string</param> /// <returns><c>true</c> if normalized</returns> public bool IsNormalized(string src) { if (string.IsNullOrEmpty(src)) { return(true); } var isNormalized = NativeMethods.unorm2_isNormalized(_Normalizer, src, src.Length, out var err); ExceptionFromErrorCode.ThrowIfError(err); return(isNormalized); }
///<summary> ///Creates a new object that is a copy of the current instance. ///</summary> /// ///<returns> ///A new object that is a copy of this instance. ///</returns> public override object Clone() { RuleBasedCollator copy = new RuleBasedCollator(); ErrorCode status; int buffersize = 512; copy._collatorHandle = NativeMethods.ucol_safeClone(_collatorHandle, IntPtr.Zero, ref buffersize, out status); ExceptionFromErrorCode.ThrowIfError(status); return(copy); }
/// <summary> /// RuleBasedCollator constructor. /// This takes the table rules and builds a collation table out of them. /// </summary> /// <param name="rules">the collation rules to build the collation table from</param> /// <param name="normalizationMode">the normalization mode to use</param> /// <param name="collationStrength">the collation strength to use</param> public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; collatorHandle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref parseError, out status); ExceptionFromErrorCode.ThrowIfError(status, parseError.ToString(rules)); }
public string Next() { ErrorCode e; int length; IntPtr str = NativeMethods.uenum_unext(this, out length, out e); if (str == IntPtr.Zero) { return(null); } string result = Marshal.PtrToStringUni(str, length); ExceptionFromErrorCode.ThrowIfError(e); return(result); }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this(isContainer, resourceType) { _exceptionContext = exceptionContext; _exceptionFromErrorCode = exceptionFromErrorCode; }
protected NativeObjectSecurity (bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this (isContainer, resourceType, exceptionFromErrorCode, exceptionContext) { RaiseExceptionOnFailure (InternalGet (name, includeSections), name, null, exceptionContext); ClearAccessControlSectionsModified (); }
private static CommonSecurityDescriptor CreateInternalPatched(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { if (createByName && name is null) { throw new ArgumentNullException(nameof(name)); } else if (!createByName && handle is null) { throw new ArgumentNullException(nameof(handle)); } Contract.EndContractBlock(); try { object[] parameters = { resourceType, AddLongPathPrefixAndFixSeparators(name), handle, includeSections, null }; var error = (int)win32GetSecurityInfo.Value.Invoke(null, parameters); if (error != ERROR_SUCCESS) { Exception exception = null; if (exceptionFromErrorCode != null) { exception = exceptionFromErrorCode(error, name, handle, exceptionContext); } if (exception is null) { if (error == ERROR_ACCESS_DENIED) { exception = new UnauthorizedAccessException(); } else if (error == ERROR_INVALID_OWNER) { exception = new InvalidOperationException(EnvGetResString1("AccessControl_InvalidOwner")); } else if (error == ERROR_INVALID_PRIMARY_GROUP) { exception = new InvalidOperationException(EnvGetResString1("AccessControl_InvalidGroup")); } else if (error == ERROR_INVALID_PARAMETER) { exception = new InvalidOperationException(EnvGetResString2("AccessControl_UnexpectedError", error)); } else if (error == ERROR_INVALID_NAME) { exception = new ArgumentException(EnvGetResString2("Argument_InvalidName"), nameof(name)); } else if (error == ERROR_FILE_NOT_FOUND) { exception = (name is null ? new FileNotFoundException() : new FileNotFoundException(name)); } else if (error == ERROR_NO_SECURITY_ON_OBJECT) { exception = new NotSupportedException(EnvGetResString1("AccessControl_NoAssociatedSecurity")); } else { Contract.Assert(false, string.Format(CultureInfo.InvariantCulture, "Win32GetSecurityInfo() failed with unexpected error code {0}", error)); exception = new InvalidOperationException(EnvGetResString2("AccessControl_UnexpectedError", error)); } } throw exception; } var rawSD = (RawSecurityDescriptor)parameters[parameters.Length - 1]; return((CommonSecurityDescriptor)csdCtor.Value .Invoke(new object[] { isContainer, false, rawSD, true })); } catch (TargetInvocationException ex) { if (ex.InnerException != null) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); } throw; } catch (NullReferenceException nre) { if (win32GetSecurityInfo.Value is null) { throw new MissingMethodException("Method 'System.Security.AccessControl.Win32.GetSecurityInfo' not found.", nre.InnerException ?? nre); } else if (csdCtor.Value is null) { throw new MissingMethodException("Constructor 'CommonSecurityDescriptor' with 4 args not found.", nre.InnerException ?? nre); } throw; } }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : base(isContainer) { throw new NotImplementedException(); }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : base(isContainer) { throw new NotImplementedException(); }
private Normalizer2(string packageName, string name, Mode mode) { _Normalizer = NativeMethods.unorm2_getInstance(packageName, name, mode, out var error); ExceptionFromErrorCode.ThrowIfError(error); }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this(resourceType, CreateInternal(resourceType, isContainer, null, handle, includeSections, false, exceptionFromErrorCode, exceptionContext), exceptionFromErrorCode) { }
private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { int error; RawSecurityDescriptor rawSD; if (createByName && name == null) { throw new ArgumentNullException(nameof(name)); } else if (!createByName && handle == null) { throw new ArgumentNullException(nameof(handle)); } error = Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out rawSD); if (error != Interop.Errors.ERROR_SUCCESS) { System.Exception exception = null; if (exceptionFromErrorCode != null) { exception = exceptionFromErrorCode(error, name, handle, exceptionContext); } if (exception == null) { if (error == Interop.Errors.ERROR_ACCESS_DENIED) { exception = new UnauthorizedAccessException(); } else if (error == Interop.Errors.ERROR_INVALID_OWNER) { exception = new InvalidOperationException(SR.AccessControl_InvalidOwner); } else if (error == Interop.Errors.ERROR_INVALID_PRIMARY_GROUP) { exception = new InvalidOperationException(SR.AccessControl_InvalidGroup); } else if (error == Interop.Errors.ERROR_INVALID_PARAMETER) { exception = new InvalidOperationException(SR.Format(SR.AccessControl_UnexpectedError, error)); } else if (error == Interop.Errors.ERROR_INVALID_NAME) { exception = new ArgumentException( SR.Argument_InvalidName, nameof(name)); } else if (error == Interop.Errors.ERROR_FILE_NOT_FOUND) { exception = (name == null ? new FileNotFoundException() : new FileNotFoundException(name)); } else if (error == Interop.Errors.ERROR_NO_SECURITY_ON_OBJECT) { exception = new NotSupportedException(SR.AccessControl_NoAssociatedSecurity); } else { Debug.Assert(false, string.Format(CultureInfo.InvariantCulture, "Win32GetSecurityInfo() failed with unexpected error code {0}", error)); exception = new InvalidOperationException(SR.Format(SR.AccessControl_UnexpectedError, error)); } } throw exception; } return new CommonSecurityDescriptor(isContainer, false /* isDS */, rawSD, true); }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : this(resourceType, CreateInternal(resourceType, isContainer, name, null, includeSections, true, exceptionFromErrorCode, exceptionContext), exceptionFromErrorCode) { }
internal NativeObjectSecurity(ResourceType resourceType, CommonSecurityDescriptor securityDescriptor, ExceptionFromErrorCode exceptionFromErrorCode) : base(securityDescriptor) { _resourceType = resourceType; _exceptionFromErrorCode = exceptionFromErrorCode; }
protected ObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) : base(false, ResourceType.Unknown) { throw new NotImplementedException(); }
[System.Security.SecurityCritical] // auto-generated private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { int error; RawSecurityDescriptor rawSD; if (createByName && name == null) { throw new ArgumentNullException("name"); } else if (!createByName && handle == null) { throw new ArgumentNullException("handle"); } error = Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out rawSD); if (error != Win32Native.ERROR_SUCCESS) { System.Exception exception = null; if (exceptionFromErrorCode != null) { exception = exceptionFromErrorCode(error, name, handle, exceptionContext); } if (exception == null) { if (error == Win32Native.ERROR_ACCESS_DENIED) { exception = new UnauthorizedAccessException(); } else if (error == Win32Native.ERROR_INVALID_OWNER) { exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidOwner")); } else if (error == Win32Native.ERROR_INVALID_PRIMARY_GROUP) { exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidGroup")); } else if (error == Win32Native.ERROR_INVALID_PARAMETER) { exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", error)); } else if (error == Win32Native.ERROR_INVALID_NAME) { exception = new ArgumentException( Environment.GetResourceString("Argument_InvalidName"), "name"); } else if (error == Win32Native.ERROR_FILE_NOT_FOUND) { exception = (name == null ? new FileNotFoundException() : new FileNotFoundException(name)); } else if (error == Win32Native.ERROR_NO_SECURITY_ON_OBJECT) { exception = new NotSupportedException(Environment.GetResourceString("AccessControl_NoAssociatedSecurity")); } else { Contract.Assert(false, string.Format(CultureInfo.InvariantCulture, "Win32GetSecurityInfo() failed with unexpected error code {0}", error)); exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", error)); } } throw exception; } return(new CommonSecurityDescriptor(isContainer, false /* isDS */, rawSD, true)); }
private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { RawSecurityDescriptor descriptor; if (createByName && (name == null)) { throw new ArgumentNullException("name"); } if (!createByName && (handle == null)) { throw new ArgumentNullException("handle"); } int errorCode = System.Security.AccessControl.Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out descriptor); if (errorCode == 0) { return(new CommonSecurityDescriptor(isContainer, false, descriptor, true)); } Exception exception = null; if (exceptionFromErrorCode != null) { exception = exceptionFromErrorCode(errorCode, name, handle, exceptionContext); } if (exception == null) { switch (errorCode) { case 5: exception = new UnauthorizedAccessException(); goto Label_0132; case 0x51b: exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidOwner")); goto Label_0132; case 0x51c: exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidGroup")); goto Label_0132; case 0x57: exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", new object[] { errorCode })); goto Label_0132; case 0x7b: exception = new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), "name"); goto Label_0132; case 2: exception = (name == null) ? new FileNotFoundException() : new FileNotFoundException(name); goto Label_0132; case 0x546: exception = new NotSupportedException(Environment.GetResourceString("AccessControl_NoAssociatedSecurity")); goto Label_0132; } exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", new object[] { errorCode })); } Label_0132: throw exception; }
private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { int error; RawSecurityDescriptor rawSD; if (createByName && name == null) { throw new ArgumentNullException(nameof(name)); } else if (!createByName && handle == null) { throw new ArgumentNullException(nameof(handle)); } error = Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out rawSD); if (error != Interop.Errors.ERROR_SUCCESS) { System.Exception exception = null; if (exceptionFromErrorCode != null) { exception = exceptionFromErrorCode(error, name, handle, exceptionContext); } if (exception == null) { if (error == Interop.Errors.ERROR_ACCESS_DENIED) { exception = new UnauthorizedAccessException(); } else if (error == Interop.Errors.ERROR_INVALID_OWNER) { exception = new InvalidOperationException(SR.AccessControl_InvalidOwner); } else if (error == Interop.Errors.ERROR_INVALID_PRIMARY_GROUP) { exception = new InvalidOperationException(SR.AccessControl_InvalidGroup); } else if (error == Interop.Errors.ERROR_INVALID_PARAMETER) { exception = new InvalidOperationException(SR.Format(SR.AccessControl_UnexpectedError, error)); } else if (error == Interop.Errors.ERROR_INVALID_NAME) { exception = new ArgumentException(SR.Argument_InvalidName, nameof(name)); } else if (error == Interop.Errors.ERROR_FILE_NOT_FOUND) { exception = (name == null ? new FileNotFoundException() : new FileNotFoundException(name)); } else if (error == Interop.Errors.ERROR_NO_SECURITY_ON_OBJECT) { exception = new NotSupportedException(SR.AccessControl_NoAssociatedSecurity); } else if (error == Interop.Errors.ERROR_PIPE_NOT_CONNECTED) { exception = new InvalidOperationException(SR.InvalidOperation_DisconnectedPipe); } else { Debug.Fail($"Win32GetSecurityInfo() failed with unexpected error code {error}"); exception = new InvalidOperationException(SR.Format(SR.AccessControl_UnexpectedError, error)); } } throw exception; } return(new CommonSecurityDescriptor(isContainer, false /* isDS */, rawSD, true)); }
protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext) { }