From 766b16e93cdd128849baad8de1a2419999df4713 Mon Sep 17 00:00:00 2001 From: antiduh Date: Tue, 24 Jun 2014 21:10:29 +0000 Subject: [PATCH] Added a little helper to understand the meaning of a SecurityStatus. Don't store the SecurityStatus as an int; we don't need signed semantics and it just complicates comparisons and literals. --- SecurityStatus.cs | 87 ++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/SecurityStatus.cs b/SecurityStatus.cs index 34936b8..ea3caa7 100644 --- a/SecurityStatus.cs +++ b/SecurityStatus.cs @@ -20,49 +20,58 @@ namespace NSspi #define SEC_E_NO_CREDENTIALS _HRESULT_TYPEDEF_(0x8009030EL) */ - public enum SecurityStatus : int + public enum SecurityStatus : uint { // Success / Informational OK = 0x00000000, - ContinueNeeded = unchecked( (int)0x00090312 ), - CompleteNeeded = unchecked( (int)0x00090313 ), - CompAndContinue = unchecked( (int)0x00090314 ), - ContextExpired = unchecked( (int)0x00090317 ), - CredentialsNeeded = unchecked( (int)0x00090320 ), - Renegotiate = unchecked( (int)0x00090321 ), + ContinueNeeded = 0x00090312, + CompleteNeeded = 0x00090313, + CompAndContinue = 0x00090314, + ContextExpired = 0x00090317, + CredentialsNeeded = 0x00090320, + Renegotiate = 0x00090321, // Errors - OutOfMemory = unchecked( (int)0x80090300 ), - InvalidHandle = unchecked( (int)0x80090301 ), - Unsupported = unchecked( (int)0x80090302 ), - TargetUnknown = unchecked( (int)0x80090303 ), - InternalError = unchecked( (int)0x80090304 ), - PackageNotFound = unchecked( (int)0x80090305 ), - NotOwner = unchecked( (int)0x80090306 ), - CannotInstall = unchecked( (int)0x80090307 ), - InvalidToken = unchecked( (int)0x80090308 ), - CannotPack = unchecked( (int)0x80090309 ), - QopNotSupported = unchecked( (int)0x8009030A ), - NoImpersonation = unchecked( (int)0x8009030B ), - LogonDenied = unchecked( (int)0x8009030C ), - UnknownCredentials = unchecked( (int)0x8009030D ), - NoCredentials = unchecked( (int)0x8009030E ), - MessageAltered = unchecked( (int)0x8009030F ), - OutOfSequence = unchecked( (int)0x80090310 ), - NoAuthenticatingAuthority = unchecked( (int)0x80090311 ), - IncompleteMessage = unchecked( (int)0x80090318 ), - IncompleteCredentials = unchecked( (int)0x80090320 ), - BufferNotEnough = unchecked( (int)0x80090321 ), - WrongPrincipal = unchecked( (int)0x80090322 ), - TimeSkew = unchecked( (int)0x80090324 ), - UntrustedRoot = unchecked( (int)0x80090325 ), - IllegalMessage = unchecked( (int)0x80090326 ), - CertUnknown = unchecked( (int)0x80090327 ), - CertExpired = unchecked( (int)0x80090328 ), - AlgorithmMismatch = unchecked( (int)0x80090331 ), - SecurityQosFailed = unchecked( (int)0x80090332 ), - SmartcardLogonRequired = unchecked( (int)0x8009033E ), - UnsupportedPreauth = unchecked( (int)0x80090343 ), - BadBinding = unchecked( (int)0x80090346 ) + OutOfMemory = 0x80090300, + InvalidHandle = 0x80090301, + Unsupported = 0x80090302, + TargetUnknown = 0x80090303, + InternalError = 0x80090304, + PackageNotFound = 0x80090305, + NotOwner = 0x80090306, + CannotInstall = 0x80090307, + InvalidToken = 0x80090308, + CannotPack = 0x80090309, + QopNotSupported = 0x8009030A, + NoImpersonation = 0x8009030B, + LogonDenied = 0x8009030C, + UnknownCredentials = 0x8009030D, + NoCredentials = 0x8009030E, + MessageAltered = 0x8009030F, + OutOfSequence = 0x80090310, + NoAuthenticatingAuthority = 0x80090311, + IncompleteMessage = 0x80090318, + IncompleteCredentials = 0x80090320, + BufferNotEnough = 0x80090321, + WrongPrincipal = 0x80090322, + TimeSkew = 0x80090324, + UntrustedRoot = 0x80090325, + IllegalMessage = 0x80090326, + CertUnknown = 0x80090327, + CertExpired = 0x80090328, + AlgorithmMismatch = 0x80090331, + SecurityQosFailed = 0x80090332, + SmartcardLogonRequired = 0x8009033E, + UnsupportedPreauth = 0x80090343, + BadBinding = 0x80090346 } + + public static class SecurityStatusExtensions + { + public static bool IsError( this SecurityStatus status ) + { + return (uint)status > 0x80000000u; + } + } + }