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.

176 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1998-1998 Microsoft Corporation
  3. Module Name:
  4. notify.c
  5. Abstract:
  6. This module contains the implemention of the change notification functions
  7. Author:
  8. Mac McLain (MacM) 04-Feb-1998
  9. Environment:
  10. Requires ANSI C extensions: slash-slash comments, long external names.
  11. Notes:
  12. Revision History:
  13. --*/
  14. // These must be included first:
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windef.h> // IN, LPVOID, etc.
  19. #include <lmcons.h> // NET_API_FUNCTION, etc.
  20. #include <lmerr.h> // LM Error codes
  21. #include <ntlsa.h> // Lsa change notification function prototypes
  22. #include <lmconfig.h> // Function prototypes
  23. #include <winbase.h> // CreateEvent...
  24. #include <netlibnt.h> // NetpNtStatusToApiStatus
  25. //
  26. // We dynamically load secur32.dll, in order to call the lsa policy change notification functions
  27. // Keep it in sync with the definition in ntlsa.h
  28. //
  29. typedef NTSTATUS (* POLCHANGENOTIFYFN )( POLICY_NOTIFICATION_INFORMATION_CLASS, HANDLE );
  30. NET_API_STATUS
  31. NET_API_FUNCTION
  32. NetRegisterDomainNameChangeNotification(
  33. PHANDLE NotificationEventHandle
  34. )
  35. /*++
  36. Routine Description:
  37. This function is used to register a notification for a domain name change.
  38. The waitable event that is returned gets signalled when ever the flat or
  39. dns domain name is changed.
  40. Arguments:
  41. NotificationHandle - Where the handle to the created notification event is
  42. returned.
  43. Return Value:
  44. NERR_Success - Success
  45. ERROR_INVALID_PARAMETER - A NULL NotificationEventHandle was given
  46. --*/
  47. {
  48. NTSTATUS Status;
  49. HANDLE EventHandle;
  50. DWORD Err = NERR_Success;
  51. if ( NotificationEventHandle == NULL ) {
  52. return( ERROR_INVALID_PARAMETER );
  53. }
  54. EventHandle = CreateEvent( NULL, FALSE, FALSE, NULL );
  55. if ( EventHandle == NULL ) {
  56. Err = GetLastError();
  57. } else {
  58. Status = LsaRegisterPolicyChangeNotification( PolicyNotifyDnsDomainInformation,
  59. EventHandle );
  60. //
  61. // If the function was successful, return the event handle. Otherwise,
  62. // close the event
  63. //
  64. if ( !NT_SUCCESS( Status ) ) {
  65. CloseHandle( EventHandle );
  66. Err = NetpNtStatusToApiStatus( Status );
  67. } else {
  68. *NotificationEventHandle = EventHandle;
  69. }
  70. }
  71. return( Err );
  72. }
  73. NET_API_STATUS
  74. NET_API_FUNCTION
  75. NetUnregisterDomainNameChangeNotification(
  76. HANDLE NotificationEventHandle
  77. )
  78. /*++
  79. Routine Description:
  80. This function is used to unregister a previously registered notification
  81. for a domain name change.
  82. The input handle is closed.
  83. Arguments:
  84. NotificationHandle - The notification event handle to unregister
  85. Return Value:
  86. NERR_Success - Success
  87. ERROR_INVALID_PARAMETER - A NULL NotificationEventHandle was given
  88. --*/
  89. {
  90. NTSTATUS Status;
  91. DWORD Err = NERR_Success;
  92. //
  93. // Parameter check
  94. //
  95. if ( NotificationEventHandle == NULL ) {
  96. return( ERROR_INVALID_PARAMETER );
  97. }
  98. //
  99. // Unregister the event
  100. //
  101. Status = LsaUnregisterPolicyChangeNotification( PolicyNotifyDnsDomainInformation,
  102. NotificationEventHandle );
  103. Err = NetpNtStatusToApiStatus( Status );
  104. //
  105. // If the unregister was successful, close the event handle
  106. //
  107. if ( Err == NERR_Success ) {
  108. CloseHandle( NotificationEventHandle );
  109. }
  110. return( Err );
  111. }