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.

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