Leaked source code of windows server 2003
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.

182 lines
4.1 KiB

  1. /*
  2. * Util.h
  3. *
  4. * Author: BreenH
  5. *
  6. * Utility functions for the licensing core and its policies.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include <stdlib.h>
  13. #include <time.h>
  14. #include <lmaccess.h>
  15. #include <lmerr.h>
  16. #include <lmapibuf.h>
  17. #define SECURITY_WIN32
  18. #include <security.h>
  19. #include <rpc.h>
  20. #include <tserrs.h>
  21. #include "util.h"
  22. #include "lctrace.h"
  23. /*
  24. * Function Definitions
  25. */
  26. NTSTATUS
  27. LsStatusToNtStatus(
  28. LICENSE_STATUS LsStatus
  29. )
  30. {
  31. NTSTATUS Status;
  32. switch (LsStatus)
  33. {
  34. case LICENSE_STATUS_OK:
  35. Status = STATUS_SUCCESS;
  36. break;
  37. case LICENSE_STATUS_OUT_OF_MEMORY:
  38. Status = STATUS_NO_MEMORY;
  39. break;
  40. case LICENSE_STATUS_INSUFFICIENT_BUFFER:
  41. Status = STATUS_BUFFER_TOO_SMALL;
  42. break;
  43. case LICENSE_STATUS_INVALID_INPUT:
  44. Status = STATUS_INVALID_PARAMETER;
  45. break;
  46. case LICENSE_STATUS_NO_LICENSE_SERVER:
  47. Status = RPC_NT_SERVER_UNAVAILABLE;
  48. break;
  49. case LICENSE_STATUS_CANNOT_UPGRADE_LICENSE:
  50. case LICENSE_STATUS_NO_LICENSE_ERROR:
  51. Status = STATUS_LICENSE_VIOLATION;
  52. break;
  53. default:
  54. Status = STATUS_INTERNAL_ERROR;
  55. break;
  56. }
  57. return Status;
  58. }
  59. UINT32
  60. LsStatusToClientError(
  61. LICENSE_STATUS LsStatus
  62. )
  63. {
  64. UINT32 dwClientError;
  65. switch (LsStatus)
  66. {
  67. case LICENSE_STATUS_OK:
  68. dwClientError = TS_ERRINFO_NOERROR;
  69. break;
  70. case LICENSE_STATUS_OUT_OF_MEMORY:
  71. dwClientError = TS_ERRINFO_OUT_OF_MEMORY;
  72. break;
  73. case LICENSE_STATUS_NO_LICENSE_SERVER:
  74. dwClientError = TS_ERRINFO_LICENSE_NO_LICENSE_SERVER;
  75. break;
  76. case LICENSE_STATUS_NO_LICENSE_ERROR:
  77. case LICENSE_STATUS_AUTHENTICATION_ERROR:
  78. dwClientError = TS_ERRINFO_LICENSE_NO_LICENSE;
  79. break;
  80. case LICENSE_STATUS_INVALID_RESPONSE:
  81. dwClientError = TS_ERRINFO_LICENSE_BAD_CLIENT_MSG;
  82. break;
  83. case LICENSE_STATUS_INVALID_MAC_DATA:
  84. dwClientError = TS_ERRINFO_LICENSE_BAD_CLIENT_MSG;
  85. break;
  86. case LICENSE_STATUS_CANNOT_DECODE_LICENSE:
  87. dwClientError = TS_ERRINFO_LICENSE_BAD_CLIENT_LICENSE;
  88. break;
  89. case LICENSE_STATUS_CANNOT_VERIFY_HWID:
  90. dwClientError = TS_ERRINFO_LICENSE_HWID_DOESNT_MATCH_LICENSE;
  91. break;
  92. case LICENSE_STATUS_SERVER_ABORT:
  93. dwClientError = TS_ERRINFO_LICENSE_CANT_FINISH_PROTOCOL;
  94. break;
  95. case LICENSE_STATUS_CLIENT_ABORT:
  96. dwClientError = TS_ERRINFO_LICENSE_CLIENT_ENDED_PROTOCOL;
  97. break;
  98. case LICENSE_STATUS_CANNOT_UPGRADE_LICENSE:
  99. dwClientError = TS_ERRINFO_LICENSE_CANT_UPGRADE_LICENSE;
  100. break;
  101. case LICENSE_STATUS_INSUFFICIENT_BUFFER:
  102. case LICENSE_STATUS_INVALID_INPUT:
  103. case LICENSE_STATUS_INVALID_SERVER_CONTEXT:
  104. case LICENSE_STATUS_NO_CERTIFICATE:
  105. case LICENSE_STATUS_NO_PRIVATE_KEY:
  106. case LICENSE_STATUS_INVALID_CRYPT_STATE:
  107. default:
  108. dwClientError = TS_ERRINFO_LICENSE_INTERNAL;
  109. break;
  110. }
  111. return dwClientError;
  112. }
  113. UINT32
  114. NtStatusToClientError(
  115. NTSTATUS Status
  116. )
  117. {
  118. UINT32 dwClientError;
  119. switch (Status)
  120. {
  121. case STATUS_SUCCESS:
  122. dwClientError = TS_ERRINFO_NOERROR;
  123. break;
  124. case STATUS_NO_MEMORY:
  125. dwClientError = TS_ERRINFO_OUT_OF_MEMORY;
  126. break;
  127. case RPC_NT_SERVER_UNAVAILABLE:
  128. dwClientError = TS_ERRINFO_LICENSE_NO_LICENSE_SERVER;
  129. break;
  130. case STATUS_LICENSE_VIOLATION:
  131. dwClientError = TS_ERRINFO_LICENSE_NO_LICENSE;
  132. break;
  133. case STATUS_NET_WRITE_FAULT:
  134. case STATUS_IO_TIMEOUT:
  135. dwClientError = TS_ERRINFO_LICENSE_CANT_FINISH_PROTOCOL;
  136. break;
  137. case STATUS_CTX_CLOSE_PENDING:
  138. case STATUS_INVALID_PARAMETER:
  139. case STATUS_BUFFER_TOO_SMALL:
  140. case STATUS_NO_DATA_DETECTED:
  141. default:
  142. dwClientError = TS_ERRINFO_LICENSE_INTERNAL;
  143. break;
  144. }
  145. return dwClientError;
  146. }