Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: mapsecer.cxx
  7. //
  8. // Contents: Map security error codes to NTSTATUS value
  9. //
  10. // Classes:
  11. //
  12. // Functions: SRtlMapErrorToString
  13. //
  14. // History: 18-Feb-93 PeterWi Created
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <secpch2.hxx>
  18. #pragma hdrstop
  19. NTSTATUS ErrorTable[] = {
  20. SEC_E_INSUFFICIENT_MEMORY, STATUS_INSUFFICIENT_RESOURCES,
  21. SEC_E_INVALID_HANDLE, STATUS_INVALID_HANDLE,
  22. SEC_E_UNSUPPORTED_FUNCTION, STATUS_NOT_IMPLEMENTED,
  23. SEC_E_TARGET_UNKNOWN, STATUS_BAD_NETWORK_PATH,
  24. SEC_E_INTERNAL_ERROR, STATUS_INTERNAL_ERROR,
  25. SEC_E_SECPKG_NOT_FOUND, STATUS_NO_SUCH_PACKAGE,
  26. SEC_E_NOT_OWNER, STATUS_INVALID_OWNER,
  27. SEC_E_CANNOT_INSTALL, STATUS_NO_SUCH_PACKAGE,
  28. SEC_E_INVALID_TOKEN, STATUS_INVALID_PARAMETER,
  29. SEC_E_CANNOT_PACK, STATUS_INVALID_PARAMETER,
  30. SEC_E_QOP_NOT_SUPPORTED, STATUS_NOT_IMPLEMENTED,
  31. SEC_E_NO_IMPERSONATION, STATUS_CANNOT_IMPERSONATE,
  32. SEC_E_LOGON_DENIED, STATUS_LOGON_FAILURE,
  33. SEC_E_UNKNOWN_CREDENTIALS, STATUS_INVALID_PARAMETER,
  34. SEC_E_NO_CREDENTIALS, STATUS_NO_SUCH_LOGON_SESSION,
  35. SEC_E_MESSAGE_ALTERED, STATUS_ACCESS_DENIED,
  36. SEC_E_OUT_OF_SEQUENCE, STATUS_ACCESS_DENIED,
  37. SEC_E_NO_AUTHENTICATING_AUTHORITY, STATUS_NO_LOGON_SERVERS,
  38. SEC_E_BAD_PKGID, STATUS_NO_SUCH_PACKAGE,
  39. 0xffffffff,0xffffffff };
  40. extern "C"
  41. NTSTATUS
  42. MapSecError(HRESULT hrValue)
  43. {
  44. ULONG Index;
  45. //
  46. // Only map error codes
  47. //
  48. if (NT_SUCCESS(hrValue))
  49. {
  50. return(hrValue);
  51. }
  52. //
  53. // Check for straight NT status codes
  54. //
  55. if ((hrValue & 0xf0000000) == 0xc0000000)
  56. {
  57. return(hrValue);
  58. }
  59. //
  60. // Then check for a masked NTSTATUS
  61. //
  62. if ((hrValue & 0xf0000000) == 0xd0000000)
  63. {
  64. return(hrValue & 0xcfffffff);
  65. }
  66. //
  67. // Next check for a masked Win32 error - convert them all to
  68. // STATUS_ACCESS_DENIED
  69. //
  70. if ((hrValue & 0xffff) == 0x80070000)
  71. {
  72. return(STATUS_ACCESS_DENIED);
  73. }
  74. //
  75. // Now map all the ISSP errors
  76. //
  77. for (Index = 0;
  78. ErrorTable[Index] != 0xffffffff ;
  79. Index+= 2 )
  80. {
  81. if (ErrorTable[Index] == hrValue)
  82. {
  83. return(ErrorTable[Index+1]);
  84. }
  85. }
  86. //
  87. // Return the old standby.
  88. //
  89. return(STATUS_ACCESS_DENIED);
  90. }
  91. extern "C"
  92. NTSTATUS
  93. SecMapHresult(
  94. HRESULT hrRet
  95. )
  96. {
  97. NTSTATUS Status = STATUS_INTERNAL_ERROR;
  98. if (SUCCEEDED(hrRet))
  99. {
  100. Status = STATUS_SUCCESS;
  101. }
  102. else if ((hrRet & 0xc0000000) == 0xc0000000)
  103. {
  104. //
  105. // This was a NTSTATUS code at some point
  106. //
  107. Status = hrRet & 0xcfffffff;
  108. }
  109. else if (hrRet == E_OUTOFMEMORY)
  110. {
  111. Status = STATUS_INSUFFICIENT_RESOURCES;
  112. }
  113. else if (hrRet == STG_E_FILENOTFOUND)
  114. {
  115. Status = STATUS_OBJECT_NAME_NOT_FOUND;
  116. }
  117. else if (hrRet == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER))
  118. {
  119. Status = STATUS_INVALID_PARAMETER;
  120. }
  121. else if (hrRet == STG_E_FILEALREADYEXISTS)
  122. {
  123. Status = STATUS_OBJECT_NAME_COLLISION;
  124. }
  125. else if (hrRet == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
  126. {
  127. Status = STATUS_OBJECT_NAME_NOT_FOUND;
  128. }
  129. else
  130. {
  131. Status = STATUS_INTERNAL_ERROR;
  132. }
  133. return(Status);
  134. }