passhook.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Created: 2-8-2005
  2. // Author(s): Scott Bridges
  3. #include <windows.h>
  4. #include <ntsecapi.h>
  5. // Work around for enum redefinition
  6. // Effects nssILockOp enumeration in nssilckt.h
  7. #define Unlock Unlock_ntsecapi
  8. #include "../passhand.h"
  9. #ifndef STATUS_SUCCESS
  10. #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
  11. #endif
  12. NTSTATUS NTAPI PasswordChangeNotify(PUNICODE_STRING UserName, ULONG RelativeId, PUNICODE_STRING Password)
  13. {
  14. char singleByteUsername[PASSHAND_BUF_SIZE];
  15. char singleBytePassword[PASSHAND_BUF_SIZE];
  16. HANDLE passhookEventHandle = OpenEvent(EVENT_MODIFY_STATE, FALSE, PASSHAND_EVENT_NAME);
  17. PasswordHandler ourPasswordHandler;
  18. fstream outLog;
  19. outLog.open("passhook.log", ios::out | ios::app);
  20. _snprintf(singleByteUsername, PASSHAND_BUF_SIZE, "%S", UserName->Buffer);
  21. singleByteUsername[UserName->Length / 2] = '\0';
  22. _snprintf(singleBytePassword, PASSHAND_BUF_SIZE, "%S", Password->Buffer);
  23. singleBytePassword[Password->Length / 2] = '\0';
  24. if(outLog.is_open())
  25. {
  26. timeStamp(&outLog);
  27. outLog << "user " << singleByteUsername << "(" << UserName->Length / 2 << ") " << "password changed" << endl;
  28. }
  29. ourPasswordHandler.LoadSet("passhook.dat");
  30. ourPasswordHandler.PushUserPass(singleByteUsername, singleBytePassword);
  31. ourPasswordHandler.SaveSet("passhook.dat");
  32. if(passhookEventHandle == NULL)
  33. {
  34. // ToDo: generate event sync service not running.
  35. if(outLog.is_open())
  36. {
  37. timeStamp(&outLog);
  38. outLog << "can not get password sync service event handle, service not running" << endl;
  39. }
  40. }
  41. else
  42. {
  43. SetEvent(passhookEventHandle);
  44. }
  45. outLog.close();
  46. return STATUS_SUCCESS;
  47. }
  48. BOOL NTAPI PasswordFilter(PUNICODE_STRING UserName, PUNICODE_STRING FullName, PUNICODE_STRING Password, BOOL SetOperation)
  49. {
  50. return TRUE;
  51. }
  52. BOOL NTAPI InitializeChangeNotify()
  53. {
  54. return TRUE;
  55. }