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.

87 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. reset.c
  5. Abstract:
  6. This module contains client side code to handle the reset machine
  7. credentials operation.
  8. Author:
  9. John Banes (jbanes) July 5, 2001
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <lm.h>
  16. #include <wincrypt.h>
  17. extern "C" {
  18. #include <ntsam.h>
  19. #include <ntsamp.h>
  20. }
  21. #include "passrec.h"
  22. DWORD
  23. WINAPI
  24. CryptResetMachineCredentials(
  25. DWORD dwFlags)
  26. {
  27. BYTE BufferIn[8] = {0};
  28. DATA_BLOB DataIn;
  29. DATA_BLOB DataOut;
  30. DWORD dwRetVal;
  31. NTSTATUS Status;
  32. //
  33. // Call SamiChangeKeys to reset syskey and SAM stuff.
  34. // If this fails, don't bother reseting DPAPI keys.
  35. //
  36. Status = SamiChangeKeys();
  37. if (!NT_SUCCESS(Status))
  38. {
  39. //
  40. // Convert the ntstatus to a winerror
  41. //
  42. return(RtlNtStatusToDosError(Status));
  43. }
  44. //
  45. // Reset DPAPI LSA secret and reencrypt all of the local machine
  46. // master keys.
  47. //
  48. DataIn.pbData = BufferIn;
  49. DataIn.cbData = sizeof(BufferIn);
  50. if(!CryptProtectData(&DataIn,
  51. NULL,
  52. NULL,
  53. NULL,
  54. NULL,
  55. CRYPTPROTECT_CRED_REGENERATE,
  56. &DataOut))
  57. {
  58. dwRetVal = GetLastError();
  59. return dwRetVal;
  60. }
  61. //
  62. // Force a flush
  63. //
  64. RegFlushKey(HKEY_LOCAL_MACHINE);
  65. return ERROR_SUCCESS;
  66. }