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.

58 lines
1.4 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(TCHAR * szCID, TCHAR * pszPw)
  14. {
  15. #ifndef CHICO
  16. WCHAR * szPw = pszPw;
  17. LSA_OBJECT_ATTRIBUTES sObjAttributes;
  18. LSA_HANDLE hPolicy;
  19. LSA_UNICODE_STRING sKey;
  20. LSA_UNICODE_STRING sPassword;
  21. WCHAR szKey[256];
  22. swprintf(szKey, L"SCM:%s", szCID);
  23. sKey.Length = (wcslen(szKey) + 1) * sizeof(WCHAR);
  24. sKey.MaximumLength = (wcslen(szKey) + 1) * sizeof(WCHAR);
  25. sKey.Buffer = szKey;
  26. sPassword.Length = (wcslen(szPw) + 1) * sizeof(WCHAR);
  27. sPassword.MaximumLength = 80 * sizeof(WCHAR);
  28. sPassword.Buffer = szPw;
  29. InitializeObjectAttributes(&sObjAttributes, NULL, 0L, NULL, NULL);
  30. // open the local security policy
  31. if (!NT_SUCCESS(
  32. LsaOpenPolicy(
  33. NULL,
  34. &sObjAttributes,
  35. POLICY_CREATE_SECRET,
  36. &hPolicy)))
  37. {
  38. printf("LsaOpenPolicy failed with %d\n",GetLastError());
  39. return(FALSE);
  40. }
  41. // store private data
  42. if (!NT_SUCCESS(
  43. LsaStorePrivateData(hPolicy, &sKey, &sPassword)))
  44. {
  45. printf("LsaStorePrivateData failed with %d\n",GetLastError());
  46. return(FALSE);
  47. }
  48. LsaClose(hPolicy);
  49. #endif
  50. return(TRUE);
  51. }