SharpCifs.Smb.SmbException.GetStatusByCode C# (CSharp) Method

GetStatusByCode() static private method

static private GetStatusByCode ( int errcode ) : int
errcode int
return int
		internal static int GetStatusByCode(int errcode)
		{
			if ((errcode & unchecked((int)(0xC0000000))) != 0)
			{
				return errcode;
			}
		    int min = 0;
		    int max = DosError.DosErrorCodes.Length - 1;
		    while (max >= min)
		    {
		        int mid = (min + max) / 2;
		        if (errcode > DosError.DosErrorCodes[mid][0])
		        {
		            min = mid + 1;
		        }
		        else
		        {
		            if (errcode < DosError.DosErrorCodes[mid][0])
		            {
		                max = mid - 1;
		            }
		            else
		            {
		                return DosError.DosErrorCodes[mid][1];
		            }
		        }
		    }
		    return NtStatus.NtStatusUnsuccessful;
		}

Usage Example

Example #1
0
        /// <exception cref="SharpCifs.Smb.SmbException"></exception>
        internal virtual void CheckStatus(ServerMessageBlock req, ServerMessageBlock resp
                                          )
        {
            resp.ErrorCode = SmbException.GetStatusByCode(resp.ErrorCode);
            switch (resp.ErrorCode)
            {
            case NtStatus.NtStatusOk:
            {
                break;
            }

            case NtStatus.NtStatusAccessDenied:
            case NtStatus.NtStatusWrongPassword:
            case NtStatus.NtStatusLogonFailure:
            case NtStatus.NtStatusAccountRestriction:
            case NtStatus.NtStatusInvalidLogonHours:
            case NtStatus.NtStatusInvalidWorkstation:
            case NtStatus.NtStatusPasswordExpired:
            case NtStatus.NtStatusAccountDisabled:
            case NtStatus.NtStatusAccountLockedOut:
            case NtStatus.NtStatusTrustedDomainFailure:
            {
                throw new SmbAuthException(resp.ErrorCode);
            }

            case NtStatus.NtStatusPathNotCovered:
            {
                if (req.Auth == null)
                {
                    throw new SmbException(resp.ErrorCode, null);
                }
                DfsReferral dr = GetDfsReferrals(req.Auth, req.Path, 1);
                if (dr == null)
                {
                    throw new SmbException(resp.ErrorCode, null);
                }
                SmbFile.Dfs.Insert(req.Path, dr);
                throw dr;
            }

            case unchecked ((int)(0x80000005)):
            {
                break;
            }

            case NtStatus.NtStatusMoreProcessingRequired:
            {
                break;
            }

            default:
            {
                throw new SmbException(resp.ErrorCode, null);
            }
            }
            if (resp.VerifyFailed)
            {
                throw new SmbException("Signature verification failed.");
            }
        }