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.

97 lines
2.2 KiB

  1. #include "StandardHeader.h"
  2. #include "LogonWait.h"
  3. #include "StatusCode.h"
  4. CLogonWait::CLogonWait (void) :
  5. _hWait(NULL),
  6. _event(NULL),
  7. _pLogonExternalProcess(NULL)
  8. {
  9. }
  10. CLogonWait::~CLogonWait (void)
  11. {
  12. Cancel();
  13. }
  14. NTSTATUS CLogonWait::Cancel (void)
  15. {
  16. HANDLE hWait;
  17. hWait = InterlockedExchangePointer(&_hWait, NULL);
  18. if (hWait != NULL)
  19. {
  20. if (UnregisterWait(hWait) == FALSE)
  21. {
  22. TSTATUS(_event.Wait(INFINITE, NULL));
  23. }
  24. _pLogonExternalProcess->Release();
  25. _pLogonExternalProcess = NULL;
  26. }
  27. return(STATUS_SUCCESS);
  28. }
  29. NTSTATUS CLogonWait::Register (HANDLE hObject, ILogonExternalProcess *pLogonExternalProcess)
  30. {
  31. NTSTATUS status;
  32. if (static_cast<HANDLE>(_event) != NULL)
  33. {
  34. status = Cancel();
  35. if (NT_SUCCESS(status))
  36. {
  37. pLogonExternalProcess->AddRef();
  38. TSTATUS(_event.Reset());
  39. if (RegisterWaitForSingleObject(&_hWait,
  40. hObject,
  41. CB_ObjectSignaled,
  42. this,
  43. INFINITE,
  44. WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE) == FALSE)
  45. {
  46. pLogonExternalProcess->Release();
  47. status = CStatusCode::StatusCodeOfLastError();
  48. }
  49. else
  50. {
  51. _pLogonExternalProcess = pLogonExternalProcess;
  52. status = STATUS_SUCCESS;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. status = STATUS_NO_MEMORY;
  59. }
  60. return(status);
  61. }
  62. void CLogonWait::ObjectSignaled (void)
  63. {
  64. HANDLE hWait;
  65. hWait = InterlockedExchangePointer(&_hWait, NULL);
  66. TSTATUS(_event.Set());
  67. if (hWait != NULL)
  68. {
  69. (BOOL)UnregisterWait(hWait);
  70. TSTATUS(_pLogonExternalProcess->LogonRestart());
  71. _pLogonExternalProcess->Release();
  72. _pLogonExternalProcess = NULL;
  73. }
  74. }
  75. void CALLBACK CLogonWait::CB_ObjectSignaled (void *pV, BOOLEAN fTimedOut)
  76. {
  77. UNREFERENCED_PARAMETER(fTimedOut);
  78. reinterpret_cast<CLogonWait*>(pV)->ObjectSignaled();
  79. }