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.

169 lines
3.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: killhelp.c
  6. * Content: kill DDHELP.EXE
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 06-apr-95 craige initial implementation
  11. * 24-jun-95 craige kill all attached processes
  12. *
  13. ***************************************************************************/
  14. #define WIN32_LEAN_AND_MEAN
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <conio.h>
  18. #include "ddhelp.h"
  19. /*
  20. * sendRequest
  21. *
  22. * communicate a request to DDHELP
  23. */
  24. static BOOL sendRequest( LPDDHELPDATA req_phd )
  25. {
  26. LPDDHELPDATA phd;
  27. HANDLE hmem;
  28. HANDLE hmutex;
  29. HANDLE hackevent;
  30. HANDLE hstartevent;
  31. BOOL rc;
  32. /*
  33. * get events start/ack events
  34. */
  35. hstartevent = CreateEvent( NULL, FALSE, FALSE, DDHELP_EVENT_NAME );
  36. printf( "hstartevent = %08lx\n", hstartevent );
  37. if( hstartevent == NULL )
  38. {
  39. return FALSE;
  40. }
  41. hackevent = CreateEvent( NULL, FALSE, FALSE, DDHELP_ACK_EVENT_NAME );
  42. printf( "hackevent = %08lx\n", hackevent );
  43. if( hackevent == NULL )
  44. {
  45. CloseHandle( hstartevent );
  46. return FALSE;
  47. }
  48. /*
  49. * create shared memory area
  50. */
  51. hmem = CreateFileMapping( INVALID_HANDLE_VALUE, NULL,
  52. PAGE_READWRITE, 0, sizeof( DDHELPDATA ),
  53. DDHELP_SHARED_NAME );
  54. printf( "hmem = %08lx\n", hmem );
  55. if( hmem == NULL )
  56. {
  57. printf( "Could not create file mapping!\n" );
  58. CloseHandle( hstartevent );
  59. CloseHandle( hackevent );
  60. return FALSE;
  61. }
  62. phd = (LPDDHELPDATA) MapViewOfFile( hmem, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
  63. printf( "phd = %08lx\n", phd );
  64. if( phd == NULL )
  65. {
  66. printf( "Could not create view of file!\n" );
  67. CloseHandle( hmem );
  68. CloseHandle( hstartevent );
  69. CloseHandle( hackevent );
  70. return FALSE;
  71. }
  72. /*
  73. * wait for access to the shared memory
  74. */
  75. hmutex = OpenMutex( SYNCHRONIZE, FALSE, DDHELP_MUTEX_NAME );
  76. printf( "hmutex = %08lx\n", hmutex );
  77. if( hmutex == NULL )
  78. {
  79. printf( "Could not create mutex!\n" );
  80. CloseHandle( hmem );
  81. CloseHandle( hstartevent );
  82. CloseHandle( hackevent );
  83. return FALSE;
  84. }
  85. WaitForSingleObject( hmutex, INFINITE );
  86. /*
  87. * wake up DDHELP with our request
  88. */
  89. memcpy( phd, req_phd, sizeof( DDHELPDATA ) );
  90. phd->req_id = 0;
  91. printf( "waking up DDHELP\n" );
  92. if( SetEvent( hstartevent ) )
  93. {
  94. printf( "Waiting for response\n" );
  95. WaitForSingleObject( hackevent, INFINITE );
  96. memcpy( req_phd, phd, sizeof( DDHELPDATA ) );
  97. rc = TRUE;
  98. printf( "got response\n" );
  99. }
  100. else
  101. {
  102. printf( "Could not signal event to notify DDHELP\n" );
  103. rc = FALSE;
  104. }
  105. /*
  106. * done with things
  107. */
  108. ReleaseMutex( hmutex );
  109. CloseHandle( hstartevent );
  110. CloseHandle( hackevent );
  111. CloseHandle( hmutex );
  112. CloseHandle( hmem );
  113. return rc;
  114. } /* sendRequest */
  115. /*
  116. * main
  117. */
  118. main( int argc, char *argv[] )
  119. {
  120. HANDLE h;
  121. DDHELPDATA hd;
  122. BOOL kill;
  123. h = OpenEvent( SYNCHRONIZE, FALSE, DDHELP_STARTUP_EVENT_NAME );
  124. if( h == NULL )
  125. {
  126. printf( "Helper not running\n" );
  127. return 0;
  128. }
  129. if( argc > 1 )
  130. {
  131. if( argv[1][0] == '-' && argv[1][1] == 'k' )
  132. {
  133. kill = TRUE;
  134. }
  135. else
  136. {
  137. kill = FALSE;
  138. }
  139. }
  140. else
  141. {
  142. printf( "\nKill attached processes?\n" );
  143. kill = (_getch() == 'y');
  144. }
  145. if( kill )
  146. {
  147. WaitForSingleObject( h, INFINITE );
  148. printf( "*** KILL ATTACHED ***\n" );
  149. hd.req = DDHELPREQ_KILLATTACHED;
  150. sendRequest( &hd );
  151. printf( "\n" );
  152. }
  153. printf( "*** SUICIDE ***\n" );
  154. hd.req = DDHELPREQ_SUICIDE;
  155. sendRequest( &hd );
  156. return 0;
  157. } /* main */