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.

183 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. VSAnalyzerServerSetup.cpp
  5. Abstract:
  6. This fix is for hardening the passwords for
  7. Visual C++ Analyzer Server Setup.
  8. Notes:
  9. This is an app specific shim.
  10. History:
  11. 02/17/2000 clupu Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(VSAnalyzerServerSetup)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(NetUserAdd)
  18. APIHOOK_ENUM_ENTRY(LsaStorePrivateData)
  19. APIHOOK_ENUM_END
  20. #include <lmcons.h>
  21. #include <lmaccess.h>
  22. #include <ntsecapi.h>
  23. static WCHAR gwszPW[LM20_PWLEN] = L"Aa+0";
  24. /*++
  25. Harden the password requirements
  26. --*/
  27. DWORD
  28. APIHOOK(NetUserAdd)(
  29. LPCWSTR servername,
  30. DWORD level,
  31. LPBYTE buf,
  32. LPDWORD parm_err
  33. )
  34. {
  35. NET_API_STATUS Status;
  36. USER_INFO_2* puiNew;
  37. LPWSTR pwszPSWRD;
  38. int nBytes;
  39. if (level == 2) {
  40. //
  41. // Grab the pointer to the buffer as a pointer to USER_INFO_2
  42. //
  43. puiNew = (USER_INFO_2*)buf;
  44. //
  45. // Get the current password.
  46. //
  47. pwszPSWRD = puiNew->usri2_password;
  48. DPFN(
  49. eDbgLevelInfo,
  50. "VSAnalyzerServerSetup.dll, NetUserAdd PW: \"%ws\".\n",
  51. pwszPSWRD);
  52. //
  53. // Copy the current password to the temp buffer.
  54. //
  55. lstrcpyW(gwszPW + 4, pwszPSWRD + 4);
  56. //
  57. // Stick in the new password.
  58. //
  59. puiNew->usri2_password = gwszPW;
  60. DPFN(
  61. eDbgLevelInfo,
  62. "VSAnalyzerServerSetup.dll, NetUserAdd new PW: \"%ws\".\n",
  63. gwszPW);
  64. }
  65. //
  66. // Call the original API.
  67. //
  68. Status = ORIGINAL_API(NetUserAdd)(
  69. servername,
  70. level,
  71. buf,
  72. parm_err);
  73. if (level == 2) {
  74. //
  75. // Restore the password.
  76. //
  77. puiNew->usri2_password = pwszPSWRD;
  78. }
  79. return Status;
  80. }
  81. /*++
  82. Harden the password requirements
  83. --*/
  84. NTSTATUS
  85. APIHOOK(LsaStorePrivateData)(
  86. LSA_HANDLE PolicyHandle,
  87. PLSA_UNICODE_STRING KeyName,
  88. PLSA_UNICODE_STRING PrivateData
  89. )
  90. {
  91. NTSTATUS Status;
  92. LPWSTR pwszPSWRD;
  93. //
  94. // Save the originals.
  95. //
  96. pwszPSWRD = PrivateData->Buffer;
  97. DPFN(
  98. eDbgLevelInfo,
  99. "VSAnalyzerServerSetup.dll, LsaStorePrivateData PW: \"%ws\".\n",
  100. pwszPSWRD);
  101. //
  102. // Copy the current password to the temp buffer.
  103. //
  104. lstrcpyW(gwszPW + 4, pwszPSWRD + 4);
  105. //
  106. // Stick in the new settings.
  107. //
  108. PrivateData->Buffer = gwszPW;
  109. DPFN(
  110. eDbgLevelInfo,
  111. "VSAnalyzerServerSetup.dll, LsaStorePrivateData new PW: \"%ws\".\n",
  112. gwszPW);
  113. //
  114. // Call the original LsaStorePrivateData.
  115. //
  116. Status = ORIGINAL_API(LsaStorePrivateData)(
  117. PolicyHandle,
  118. KeyName,
  119. PrivateData);
  120. //
  121. // Restore the originals.
  122. //
  123. PrivateData->Buffer = pwszPSWRD;
  124. return Status;
  125. }
  126. /*++
  127. Register hooked functions
  128. --*/
  129. HOOK_BEGIN
  130. APIHOOK_ENTRY(NETAPI32.DLL, NetUserAdd)
  131. APIHOOK_ENTRY(ADVAPI32.DLL, LsaStorePrivateData)
  132. HOOK_END
  133. IMPLEMENT_SHIM_END