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.

188 lines
3.7 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. if (level == 2) {
  39. //
  40. // Grab the pointer to the buffer as a pointer to USER_INFO_2
  41. //
  42. puiNew = (USER_INFO_2*)buf;
  43. //
  44. // Get the current password.
  45. //
  46. pwszPSWRD = puiNew->usri2_password;
  47. if( wcslen(pwszPSWRD) >= 4 )
  48. {
  49. DPFN(
  50. eDbgLevelInfo,
  51. "VSAnalyzerServerSetup.dll, NetUserAdd PW: \"%ws\".\n",
  52. pwszPSWRD);
  53. //
  54. // Copy the current password to the temp buffer.
  55. //
  56. StringCchCopyW(gwszPW + 4, ARRAYSIZE(gwszPW)-4, pwszPSWRD + 4);
  57. //
  58. // Stick in the new password.
  59. //
  60. puiNew->usri2_password = gwszPW;
  61. DPFN(
  62. eDbgLevelInfo,
  63. "VSAnalyzerServerSetup.dll, NetUserAdd new PW: \"%ws\".\n",
  64. gwszPW);
  65. }
  66. }
  67. //
  68. // Call the original API.
  69. //
  70. Status = ORIGINAL_API(NetUserAdd)(
  71. servername,
  72. level,
  73. buf,
  74. parm_err);
  75. if (level == 2) {
  76. //
  77. // Restore the password.
  78. //
  79. puiNew->usri2_password = pwszPSWRD;
  80. }
  81. return Status;
  82. }
  83. /*++
  84. Harden the password requirements
  85. --*/
  86. NTSTATUS
  87. APIHOOK(LsaStorePrivateData)(
  88. LSA_HANDLE PolicyHandle,
  89. PLSA_UNICODE_STRING KeyName,
  90. PLSA_UNICODE_STRING PrivateData
  91. )
  92. {
  93. NTSTATUS Status;
  94. LPWSTR pwszPSWRD;
  95. //
  96. // Save the originals.
  97. //
  98. pwszPSWRD = PrivateData->Buffer;
  99. DPFN(
  100. eDbgLevelInfo,
  101. "VSAnalyzerServerSetup.dll, LsaStorePrivateData PW: \"%ws\".\n",
  102. pwszPSWRD);
  103. if( wcslen(pwszPSWRD) >= 4 )
  104. {
  105. //
  106. // Copy the current password to the temp buffer.
  107. //
  108. StringCchCopyW(gwszPW + 4, ARRAYSIZE(gwszPW)-4, pwszPSWRD + 4);
  109. //
  110. // Stick in the new settings.
  111. //
  112. PrivateData->Buffer = gwszPW;
  113. DPFN(
  114. eDbgLevelInfo,
  115. "VSAnalyzerServerSetup.dll, LsaStorePrivateData new PW: \"%ws\".\n",
  116. gwszPW);
  117. }
  118. //
  119. // Call the original LsaStorePrivateData.
  120. //
  121. Status = ORIGINAL_API(LsaStorePrivateData)(
  122. PolicyHandle,
  123. KeyName,
  124. PrivateData);
  125. //
  126. // Restore the originals.
  127. //
  128. PrivateData->Buffer = pwszPSWRD;
  129. return Status;
  130. }
  131. /*++
  132. Register hooked functions
  133. --*/
  134. HOOK_BEGIN
  135. APIHOOK_ENTRY(NETAPI32.DLL, NetUserAdd)
  136. APIHOOK_ENTRY(ADVAPI32.DLL, LsaStorePrivateData)
  137. HOOK_END
  138. IMPLEMENT_SHIM_END