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.

178 lines
3.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. Module Name:
  4. waitsam
  5. Abstract:
  6. This module provides back-door access to some internal NT routines. This
  7. is needed to get at the SAM Startup Event -- it has an illegal name from
  8. the Win32 routines, so we have to sneak back and pull it up from NT
  9. directly.
  10. Author:
  11. Doug Barlow (dbarlow) 5/3/1998
  12. Notes:
  13. As taken from code suggested by MacM
  14. --*/
  15. #define __SUBROUTINE__
  16. #if !defined(_X86_) && !defined(_ALPHA_)
  17. #define _X86_ 1
  18. #endif
  19. #ifndef _WIN32_WINNT
  20. #define _WIN32_WINNT 0x0400
  21. #ifndef UNICODE
  22. #define UNICODE // Force this module to use UNICODE.
  23. #endif
  24. #endif
  25. #ifndef WIN32_LEAN_AND_MEAN
  26. #define WIN32_LEAN_AND_MEAN 1
  27. #endif
  28. extern "C" {
  29. #include <nt.h>
  30. #include <ntrtl.h>
  31. #include <nturtl.h>
  32. #include <ntlsa.h>
  33. }
  34. #include <windows.h>
  35. /*++
  36. AccessSAMEvent:
  37. This procedure opens the handle to the SAM Startup Event handle.
  38. Arguments:
  39. None
  40. Return Value:
  41. The handle, or NULL on an error.
  42. Author:
  43. Doug Barlow (dbarlow) 5/3/1998
  44. --*/
  45. #undef __SUBROUTINE__
  46. #define __SUBROUTINE__ DBGT("AccessSAMEvent")
  47. HANDLE
  48. AccessSAMEvent(
  49. void)
  50. {
  51. NTSTATUS Status = STATUS_SUCCESS;
  52. UNICODE_STRING EventName;
  53. OBJECT_ATTRIBUTES EventAttributes;
  54. CHandleObject EventHandle(DBGT("Event Handle from AccessSAMEvent"));
  55. //
  56. // Open the event
  57. //
  58. RtlInitUnicodeString( &EventName, L"\\SAM_SERVICE_STARTED" );
  59. InitializeObjectAttributes( &EventAttributes, &EventName, 0, 0, NULL );
  60. Status = NtCreateEvent( &EventHandle,
  61. SYNCHRONIZE,
  62. &EventAttributes,
  63. NotificationEvent,
  64. FALSE );
  65. //
  66. // If the event already exists, just open it.
  67. //
  68. if( Status == STATUS_OBJECT_NAME_EXISTS || Status == STATUS_OBJECT_NAME_COLLISION ) {
  69. Status = NtOpenEvent( &EventHandle,
  70. SYNCHRONIZE,
  71. &EventAttributes );
  72. }
  73. return EventHandle;
  74. }
  75. /*++
  76. WaitForSAMEvent:
  77. This procedure can be used to wait for the SAM Startup event using NT
  78. internal calls. I don't know how to specify a timeout value, so this
  79. routine isn't complete.
  80. Arguments:
  81. hSamActive supplies the handle to the SAM Startup Event.
  82. dwTimeout supplies the time to wait for the startup event, in milliseconds.
  83. Return Value:
  84. TRUE - The event was set.
  85. FALSE - The timeout expired
  86. Throws:
  87. Any errors are thrown as DWORD status codes.
  88. Author:
  89. Doug Barlow (dbarlow) 5/3/1998
  90. --*/
  91. #undef __SUBROUTINE__
  92. #define __SUBROUTINE__ DBGT("WaitForSAMEvent")
  93. BOOL
  94. WaitForSAMEvent(
  95. HANDLE hSamActive,
  96. DWORD dwTimeout)
  97. {
  98. NTSTATUS Status = STATUS_SUCCESS;
  99. Status = NtWaitForSingleObject(hSamActive, TRUE, NULL);
  100. return Status;
  101. }
  102. /*++
  103. CloseSamEvent:
  104. This procedure uses the NT internal routine to close a handle.
  105. Arguments:
  106. hSamActive supplies the handle to be closed.
  107. Return Value:
  108. None
  109. Author:
  110. Doug Barlow (dbarlow) 5/3/1998
  111. --*/
  112. #undef __SUBROUTINE__
  113. #define __SUBROUTINE__ DBGT("CloseSAMEvent")
  114. void
  115. CloseSAMEvent(
  116. HANDLE hSamActive)
  117. {
  118. NtClose(hSamActive);
  119. }