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.

122 lines
2.6 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #include "precomp.h"
  5. #include <wbemcomn.h>
  6. #include <statsync.h>
  7. #include "a51tools.h"
  8. __int64 g_nCurrentTime = 1;
  9. __int64 g_nReadFailures = 0;
  10. __int64 g_nWriteFailures = 0;
  11. //
  12. // FILE_ATTRIBUTE_NOT_CONTENT_INDEXED is not actually supported on CreateFile,
  13. // contrary to the docs. However, also contrary to the docs, it is inherited
  14. // from the parent directory
  15. //
  16. #define A51_FILE_CREATION_FLAGS 0 //FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
  17. CTempMemoryManager g_Manager;
  18. void* TempAlloc(DWORD dwLen)
  19. {
  20. return g_Manager.Allocate(dwLen);
  21. }
  22. void TempFree(void* p, DWORD dwLen)
  23. {
  24. g_Manager.Free(p, dwLen);
  25. }
  26. void* TempAlloc(CTempMemoryManager& Manager, DWORD dwLen)
  27. {
  28. return Manager.Allocate(dwLen);
  29. }
  30. void TempFree(CTempMemoryManager& Manager, void* p, DWORD dwLen)
  31. {
  32. Manager.Free(p, dwLen);
  33. }
  34. HRESULT A51TranslateErrorCode(long lRes)
  35. {
  36. if (lRes == ERROR_SUCCESS)
  37. return WBEM_S_NO_ERROR;
  38. switch(lRes)
  39. {
  40. case ERROR_FILE_NOT_FOUND:
  41. return WBEM_E_NOT_FOUND;
  42. case ERROR_OUTOFMEMORY:
  43. case ERROR_NOT_ENOUGH_MEMORY:
  44. return WBEM_E_OUT_OF_MEMORY;
  45. case ERROR_NOT_ENOUGH_QUOTA:
  46. case ERROR_DISK_FULL:
  47. return WBEM_E_OUT_OF_DISK_SPACE;
  48. case ERROR_SERVER_SHUTDOWN_IN_PROGRESS:
  49. return WBEM_E_SHUTTING_DOWN;
  50. default:
  51. return WBEM_E_FAILED;
  52. }
  53. }
  54. long __stdcall EnsureDirectory(LPCWSTR wszPath, LPSECURITY_ATTRIBUTES pSA)
  55. {
  56. if(!CreateDirectoryW(wszPath, NULL))
  57. {
  58. long lRes = GetLastError();
  59. if(lRes != ERROR_ALREADY_EXISTS)
  60. return lRes;
  61. else
  62. return ERROR_SUCCESS;
  63. }
  64. else
  65. return ERROR_SUCCESS;
  66. }
  67. static WCHAR g_HexDigit[] =
  68. { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9',
  69. L'A', L'B', L'C', L'D', L'E', L'F'
  70. };
  71. bool A51Hash(LPCWSTR wszName, LPWSTR wszHash)
  72. {
  73. //
  74. // Have to upper-case everything
  75. //
  76. DWORD dwBufferSize = wcslen(wszName)*2+2;
  77. LPWSTR wszBuffer = (WCHAR*)TempAlloc(dwBufferSize);
  78. if (wszBuffer == NULL)
  79. return false;
  80. CTempFreeMe vdm(wszBuffer, dwBufferSize);
  81. wbem_wcsupr(wszBuffer, wszName);
  82. BYTE RawHash[16];
  83. MD5::Transform((void*)wszBuffer, wcslen(wszBuffer)*2, RawHash);
  84. WCHAR* pwc = wszHash;
  85. for(int i = 0; i < 16; i++)
  86. {
  87. *(pwc++) = g_HexDigit[RawHash[i]/16];
  88. *(pwc++) = g_HexDigit[RawHash[i]%16];
  89. }
  90. *pwc = 0;
  91. return true;
  92. }