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.

56 lines
1.3 KiB

  1. extern "C"
  2. {
  3. #include <nt.h>
  4. #include <ntrtl.h>
  5. #include <nturtl.h>
  6. #include <ntlsa.h>
  7. }
  8. #include <stdarg.h>
  9. #include <windef.h>
  10. #include <winbase.h>
  11. #include <winnls.h>
  12. #include <stdio.h>
  13. BOOL SetPassword(WCHAR * szCID, WCHAR * szPw)
  14. {
  15. LSA_OBJECT_ATTRIBUTES sObjAttributes;
  16. LSA_HANDLE hPolicy;
  17. LSA_UNICODE_STRING sKey;
  18. LSA_UNICODE_STRING sPassword;
  19. WCHAR szKey[256];
  20. swprintf(szKey, L"SCM:%s", szCID);
  21. sKey.Length = (wcslen(szKey) + 1) * sizeof(WCHAR);
  22. sKey.MaximumLength = (wcslen(szKey) + 1) * sizeof(WCHAR);
  23. sKey.Buffer = szKey;
  24. sPassword.Length = (wcslen(szPw) + 1) * sizeof(WCHAR);
  25. sPassword.MaximumLength = 80 * sizeof(WCHAR);
  26. sPassword.Buffer = szPw;
  27. InitializeObjectAttributes(&sObjAttributes, NULL, 0L, NULL, NULL);
  28. // open the local security policy
  29. if (!NT_SUCCESS(
  30. LsaOpenPolicy(
  31. NULL,
  32. &sObjAttributes,
  33. POLICY_CREATE_SECRET,
  34. &hPolicy)))
  35. {
  36. printf("LsaOpenPolicy failed with %d\n",GetLastError());
  37. return(FALSE);
  38. }
  39. // store private data
  40. if (!NT_SUCCESS(
  41. LsaStorePrivateData(hPolicy, &sKey, &sPassword)))
  42. {
  43. printf("LsaStorePrivateData failed with %d\n",GetLastError());
  44. return(FALSE);
  45. }
  46. LsaClose(hPolicy);
  47. return(TRUE);
  48. }