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.

228 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tcontrol.c
  5. Abstract:
  6. Test for cluster resource and resource type controls
  7. Author:
  8. Rod Gamache (rodga) 30-Dec-1996
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "cluster.h"
  13. #include "stdio.h"
  14. #include "stdlib.h"
  15. #include "resapi.h"
  16. LPWSTR ClusterName=NULL;
  17. LPWSTR NodeName=NULL;
  18. DWORD ControlCode=0xffffffff;
  19. DWORD Access=CLUS_ACCESS_READ;
  20. CHAR UsageText[] =
  21. "TNODE [-c cluster] -n node ControlCode\n"
  22. " cluster\tspecifies the name of the cluster to connect to\n"
  23. " node\tspecifies the node to direct the request to\n"
  24. " ControlCode\ta number between 1 and 9\n";
  25. void
  26. Usage(
  27. void
  28. )
  29. {
  30. fprintf(stderr, UsageText);
  31. exit(1);
  32. }
  33. LPWSTR
  34. GetString(
  35. IN LPSTR String
  36. )
  37. {
  38. LPWSTR wString;
  39. DWORD Length;
  40. Length = strlen(String)+1;
  41. wString = malloc(Length*sizeof(WCHAR));
  42. if (wString == NULL) {
  43. fprintf(stderr, "GetString couldn't malloc %d bytes\n",Length*sizeof(WCHAR));
  44. }
  45. mbstowcs(wString, String, Length);
  46. return(wString);
  47. }
  48. void
  49. ParseArgs(
  50. int argc,
  51. char *argv[]
  52. )
  53. {
  54. int i;
  55. DWORD IntCount;
  56. DWORD Value;
  57. CHAR TestValue[16];
  58. PUCHAR ControlData;
  59. LPWSTR access;
  60. for (i=1;i<argc;i++) {
  61. if ((argv[i][0] == '-') ||
  62. (argv[i][0] == '/')) {
  63. switch (argv[i][1]) {
  64. case 'c':
  65. if (++i == argc) {
  66. Usage();
  67. }
  68. ClusterName = GetString(argv[i]);
  69. break;
  70. case 'n':
  71. if ( ++i == argc ) {
  72. Usage();
  73. }
  74. NodeName = GetString(argv[i]);
  75. fprintf(stdout, "Node = %ws\n", NodeName);
  76. break;
  77. default:
  78. Usage();
  79. break;
  80. }
  81. } else {
  82. ControlData = argv[i];
  83. IntCount = sscanf( ControlData, "%d", &Value );
  84. if ( IntCount == 1 ) {
  85. sprintf( TestValue, "%d\0", Value );
  86. if ( strcmp( TestValue, ControlData ) == 0 ) {
  87. ControlCode = Value;
  88. fprintf(stdout, "ControlCode = %d\n", ControlCode);
  89. }
  90. }
  91. }
  92. }
  93. if ( ControlCode == 0xffffffff ) {
  94. Usage();
  95. }
  96. }
  97. _cdecl
  98. main (argc, argv)
  99. int argc;
  100. char *argv[];
  101. {
  102. HCLUSTER hClus;
  103. HNODE hNode = NULL;
  104. DWORD status;
  105. DWORD ReturnSize;
  106. DWORD bufSize;
  107. CHAR InBuffer[64];
  108. DWORD i,j;
  109. LPDWORD Data;
  110. LPDWORD PrintData;
  111. CHAR PrintBuffer[32];
  112. PUCHAR buffer;
  113. DWORD controlCode;
  114. BOOL retry = TRUE;
  115. ParseArgs(argc, argv);
  116. hClus = OpenCluster(ClusterName);
  117. if (hClus == NULL) {
  118. fprintf(stderr,
  119. "OpenCluster %ws failed %d\n",
  120. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  121. GetLastError());
  122. return(0);
  123. }
  124. hNode = OpenClusterNode( hClus, NodeName );
  125. if ( hNode == NULL ) {
  126. fprintf(stderr,
  127. "OpenNode %ws failed %d\n", NodeName, GetLastError());
  128. return(0);
  129. }
  130. if ( Access == CLUS_ACCESS_WRITE ) {
  131. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_MODIFY );
  132. } else {
  133. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_NO_MODIFY );
  134. }
  135. try_again:
  136. controlCode = CLUSCTL_NODE_CODE( controlCode);
  137. ReturnSize = 0;
  138. status = ClusterNodeControl( hNode,
  139. NULL,
  140. controlCode,
  141. NULL,
  142. 0,
  143. NULL,
  144. 0,
  145. &ReturnSize );
  146. if ( retry &&
  147. (status == ERROR_INVALID_FUNCTION) ) {
  148. retry = FALSE;
  149. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, CLUS_ACCESS_WRITE, CLUS_MODIFY );
  150. goto try_again;
  151. }
  152. fprintf(stdout, "Status of initial request is %d, size is %d.\n",
  153. status, ReturnSize);
  154. if ( (status != ERROR_SUCCESS) ||
  155. (ReturnSize == 0) ) {
  156. return(0);
  157. }
  158. bufSize = ReturnSize;
  159. buffer = LocalAlloc( LMEM_FIXED, bufSize );
  160. if ( buffer == NULL ) {
  161. fprintf(stdout, "Failed to allocate a return buffer.\n");
  162. return(0);
  163. }
  164. status = ClusterNodeControl( hNode,
  165. NULL,
  166. controlCode,
  167. NULL,
  168. 0,
  169. buffer,
  170. bufSize,
  171. &ReturnSize );
  172. fprintf(stdout, "Status of Control request = %d, size = %d\n",
  173. status, ReturnSize);
  174. if ( status == ERROR_SUCCESS ) {
  175. Data = (LPDWORD)buffer;
  176. PrintData = (LPDWORD)PrintBuffer;
  177. while ( ReturnSize ) {
  178. j = ReturnSize;
  179. if ( j > 16 ) j = 16;
  180. ZeroMemory(PrintBuffer, 18);
  181. MoveMemory(PrintBuffer, Data, j);
  182. ReturnSize -= j;
  183. for ( i = 0; i < 4; i++ ) {
  184. fprintf(stdout,
  185. " %08lx", PrintData[i]);
  186. }
  187. fprintf(stdout, " ");
  188. for ( i = 0; i < 16; i++ ) {
  189. fprintf(stdout, "%c",
  190. isprint(PrintBuffer[i])?PrintBuffer[i]:'.');
  191. }
  192. Data += 4;
  193. fprintf(stdout, "\n");
  194. }
  195. }
  196. LocalFree(buffer);
  197. return(0);
  198. }