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.

171 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. setutl.c
  5. Abstract:
  6. Miscellaneous helper functions
  7. Author:
  8. Mac McLain (MacM) Feb 10, 1997
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include <setpch.h>
  14. #include <dssetp.h>
  15. #include <lsarpc.h>
  16. #include <samrpc.h>
  17. #include <samisrv.h>
  18. #include <db.h>
  19. #include <confname.h>
  20. #include <loadfn.h>
  21. #include <ntdsa.h>
  22. #include <dsconfig.h>
  23. #include <attids.h>
  24. #include <dsp.h>
  25. #include <lsaisrv.h>
  26. #include <malloc.h>
  27. #include <dsgetdc.h>
  28. #include <lmcons.h>
  29. #include <lmaccess.h>
  30. #include <lmapibuf.h>
  31. #include <lmerr.h>
  32. #include <netsetp.h>
  33. #include <winsock2.h>
  34. #include <nspapi.h>
  35. #include <dsgetdcp.h>
  36. #include <lmremutl.h>
  37. #include <spmgr.h> // For SetupPhase definition
  38. #include "cancel.h"
  39. DWORD
  40. DsRolepCancel(
  41. BOOL BlockUntilDone
  42. )
  43. /*++
  44. Routine Description:
  45. This routine will cancel a currently running operation
  46. Arguments:
  47. BlockUntilDone - if TRUE, then this call waits for the current operation to
  48. complete before returning. Otherwise return without waiting
  49. Return Values:
  50. ERROR_SUCCESS - Success
  51. --*/
  52. {
  53. DWORD Win32Err = ERROR_SUCCESS;
  54. NTSTATUS Status;
  55. BOOL fWaitForCancelToFinish = TRUE;
  56. DsRolepLogPrint(( DEB_TRACE, "Canceling current operation...\n" ));
  57. //
  58. // Grab the global lock
  59. //
  60. LockOpHandle();
  61. //
  62. // Determine if we are in a cancelable state
  63. //
  64. if ( (DsRolepCurrentOperationHandle.OperationState == DSROLEP_FINISHED)
  65. || (DsRolepCurrentOperationHandle.OperationState == DSROLEP_CANCELING) ) {
  66. //
  67. // Cancel is happening or just finished, just leave
  68. //
  69. Win32Err = ERROR_SUCCESS;
  70. fWaitForCancelToFinish = FALSE;
  71. DsRolepLogPrint(( DEB_TRACE, "Cancel already happened or the operation is finished.\n" ));
  72. } else if ( !( (DsRolepCurrentOperationHandle.OperationState == DSROLEP_RUNNING)
  73. ||(DsRolepCurrentOperationHandle.OperationState == DSROLEP_RUNNING_NON_CRITICAL)) ) {
  74. //
  75. // Invalid state transition requested
  76. //
  77. Win32Err = ERROR_NO_PROMOTION_ACTIVE;
  78. } else {
  79. // Tell the ds to cancel
  80. //
  81. // N.B. This callout to the ds is made under lock.
  82. //
  83. DSROLE_GET_SETUP_FUNC( Win32Err, DsrNtdsInstallCancel );
  84. if ( ERROR_SUCCESS == Win32Err ) {
  85. Win32Err = ( *DsrNtdsInstallCancel )();
  86. }
  87. if ( ERROR_SUCCESS == Win32Err )
  88. {
  89. Status = NtSetEvent( DsRolepCurrentOperationHandle.CancelEvent, NULL );
  90. if ( !NT_SUCCESS( Status ) ) {
  91. Win32Err = RtlNtStatusToDosError( Status );
  92. } else {
  93. DsRolepCurrentOperationHandle.OperationState = DSROLEP_CANCELING;
  94. }
  95. } else {
  96. DsRolepLogOnFailure( Win32Err,
  97. DsRolepLogPrint(( DEB_ERROR,
  98. "Unable to cancel the ds%lu\n",
  99. Win32Err )) );
  100. }
  101. }
  102. //
  103. // Release the lock
  104. //
  105. UnlockOpHandle();
  106. //
  107. // Now, wait for the operation to complete
  108. //
  109. if ( Win32Err == ERROR_SUCCESS
  110. && fWaitForCancelToFinish
  111. && BlockUntilDone ) {
  112. DsRolepLogPrint(( DEB_TRACE, "Waiting for the role change operation to complete\n" ));
  113. Status = NtWaitForSingleObject( DsRolepCurrentOperationHandle.CompletionEvent, TRUE, 0 );
  114. if ( !NT_SUCCESS( Status ) ) {
  115. Win32Err = RtlNtStatusToDosError( Status );
  116. }
  117. }
  118. DsRolepLogPrint(( DEB_TRACE, "Request for cancel returning %lu\n", Win32Err ));
  119. return( Win32Err );
  120. }