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.

261 lines
7.2 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 ResourceName=NULL;
  18. LPWSTR NodeName=NULL;
  19. DWORD ControlCode=0xffffffff;
  20. DWORD Access=CLUS_ACCESS_READ;
  21. CHAR UsageText[] =
  22. "TSET [-c cluster] -n node -r resource -a access ControlCode\n"
  23. " cluster\tspecifies the name of the cluster to connect to\n"
  24. " node\tspecifies the node to direct the request to\n"
  25. " resource\tspecifies the name of the resource to control\n"
  26. " access\tspecifies the access mode (read write or any)\n"
  27. " ControlCode\ta number between 1 and 9\n";
  28. typedef struct _PROPERTY_MSG {
  29. DWORD ItemCount;
  30. DWORD Syntax1;
  31. DWORD ParameterName1ByteCount;
  32. WCHAR ParameterName1[20];
  33. DWORD Syntax2; // Dword Data Item to follow
  34. DWORD Data; // New value
  35. DWORD Syntax3;
  36. DWORD ParameterName2ByteCount;
  37. WCHAR ParameterName2[12];
  38. DWORD Syntax4; // SZ string to follow
  39. DWORD ParameterName3ByteCount;
  40. WCHAR ParameterName3[8];
  41. } PROPERTY_MSG, PPROPERTY_MSG;
  42. PROPERTY_MSG
  43. PropertyMsg = { 2, 0x40003, 40, L"IsAlivePollInterval", 0x10002, 0x2000, 0x40003, 24, L"Description", 0x10003, 16, L"Testing" };
  44. void
  45. Usage(
  46. void
  47. )
  48. {
  49. fprintf(stderr, UsageText);
  50. exit(1);
  51. }
  52. LPWSTR
  53. GetString(
  54. IN LPSTR String
  55. )
  56. {
  57. LPWSTR wString;
  58. DWORD Length;
  59. Length = strlen(String)+1;
  60. wString = malloc(Length*sizeof(WCHAR));
  61. if (wString == NULL) {
  62. fprintf(stderr, "GetString couldn't malloc %d bytes\n",Length*sizeof(WCHAR));
  63. }
  64. mbstowcs(wString, String, Length);
  65. return(wString);
  66. }
  67. void
  68. ParseArgs(
  69. int argc,
  70. char *argv[]
  71. )
  72. {
  73. int i;
  74. DWORD IntCount;
  75. DWORD Value;
  76. CHAR TestValue[16];
  77. PUCHAR ControlData;
  78. LPWSTR access;
  79. for (i=1;i<argc;i++) {
  80. if ((argv[i][0] == '-') ||
  81. (argv[i][0] == '/')) {
  82. switch (argv[i][1]) {
  83. case 'c':
  84. if (++i == argc) {
  85. Usage();
  86. }
  87. ClusterName = GetString(argv[i]);
  88. break;
  89. case 'n':
  90. if ( ++i == argc ) {
  91. Usage();
  92. }
  93. NodeName = GetString(argv[i]);
  94. break;
  95. case 'r':
  96. if ( ++i == argc ) {
  97. Usage();
  98. }
  99. ResourceName = GetString(argv[i]);
  100. fprintf(stdout, "Resource = %ws\n", ResourceName);
  101. break;
  102. case 'a':
  103. if ( ++i == argc ) {
  104. Usage();
  105. }
  106. access = GetString(argv[i]);
  107. if ( lstrcmpiW( access, L"read" ) ) {
  108. Access = CLUS_ACCESS_READ;
  109. } else if ( lstrcmpiW( access, L"write" ) ) {
  110. Access = CLUS_ACCESS_WRITE;
  111. } else if ( lstrcmpiW( access, L"any" ) ) {
  112. Access = CLUS_ACCESS_ANY;
  113. } else {
  114. Usage();
  115. }
  116. break;
  117. default:
  118. Usage();
  119. break;
  120. }
  121. } else {
  122. ControlData = argv[i];
  123. IntCount = sscanf( ControlData, "%d", &Value );
  124. if ( IntCount == 1 ) {
  125. sprintf( TestValue, "%d\0", Value );
  126. if ( strcmp( TestValue, ControlData ) == 0 ) {
  127. ControlCode = Value;
  128. fprintf(stdout, "ControlCode = %d\n", ControlCode);
  129. }
  130. }
  131. }
  132. }
  133. if ( ControlCode == 0xffffffff ) {
  134. Usage();
  135. }
  136. }
  137. _cdecl
  138. main (argc, argv)
  139. int argc;
  140. char *argv[];
  141. {
  142. HCLUSTER hClus;
  143. HRESOURCE hResource;
  144. HNODE hNode = NULL;
  145. DWORD status;
  146. DWORD ReturnSize;
  147. CHAR InBuffer[64];
  148. CHAR OutBuffer[512];
  149. DWORD i,j;
  150. LPDWORD Data;
  151. LPDWORD PrintData;
  152. CHAR PrintBuffer[32];
  153. DWORD controlCode;
  154. ParseArgs(argc, argv);
  155. hClus = OpenCluster(ClusterName);
  156. if (hClus == NULL) {
  157. fprintf(stderr,
  158. "OpenCluster %ws failed %d\n",
  159. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  160. GetLastError());
  161. return(0);
  162. }
  163. hResource = OpenClusterResource( hClus, ResourceName );
  164. if ( hResource == NULL ) {
  165. fprintf(stderr,
  166. "OpenResource %ws failed %d\n", ResourceName, GetLastError());
  167. return(0);
  168. }
  169. if ( NodeName != NULL ) {
  170. hNode = OpenClusterNode( hClus, NodeName );
  171. if ( hNode == NULL ) {
  172. fprintf(stderr,
  173. "OpenNode %ws failed %d\n", NodeName, GetLastError());
  174. return(0);
  175. }
  176. }
  177. controlCode = CLCTL_CODE( ControlCode, Access );
  178. controlCode = CLUSCTL_RESOURCE_CODE( controlCode );
  179. ReturnSize = 0;
  180. status = ClusterResourceControl( hResource,
  181. hNode,
  182. controlCode,
  183. &PropertyMsg,
  184. sizeof(PROPERTY_MSG),
  185. OutBuffer,
  186. 0,
  187. &ReturnSize );
  188. if (( status == ERROR_MORE_DATA ) || ( ReturnSize != 0 )) {
  189. fprintf(stdout, "Calling again due to buffer size too small (status = %d)\n", status);
  190. status = ClusterResourceControl( hResource,
  191. hNode,
  192. controlCode,
  193. &PropertyMsg,
  194. sizeof(PROPERTY_MSG),
  195. OutBuffer,
  196. ReturnSize,
  197. &ReturnSize );
  198. }
  199. fprintf(stdout, "Status of Control request = %d, size = %d\n",
  200. status, ReturnSize);
  201. if ( status == ERROR_SUCCESS ) {
  202. Data = (LPDWORD)OutBuffer;
  203. PrintData = (LPDWORD)PrintBuffer;
  204. while ( ReturnSize ) {
  205. j = ReturnSize;
  206. if ( j > 16 ) j = 16;
  207. ZeroMemory(PrintBuffer, 18);
  208. MoveMemory(PrintBuffer, Data, j);
  209. for ( i = 0; i < 4; i++ ) {
  210. if ( !ReturnSize )
  211. fprintf(stdout, " ");
  212. else {
  213. fprintf(stdout, " %08lx", PrintData[i]);
  214. ReturnSize -= 4;
  215. }
  216. }
  217. fprintf(stdout, " ");
  218. for ( i = 0; i < 16; i++ ) {
  219. if ( j ) {
  220. fprintf(stdout, "%c",
  221. isprint(PrintBuffer[i])?PrintBuffer[i]:'.');
  222. j--;
  223. }
  224. }
  225. Data += 4;
  226. fprintf(stdout, "\n");
  227. }
  228. }
  229. return(0);
  230. }