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.

274 lines
7.7 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. DWORD modify;
  155. ParseArgs(argc, argv);
  156. hClus = OpenCluster(ClusterName);
  157. if (hClus == NULL) {
  158. fprintf(stderr,
  159. "OpenCluster %ws failed %d\n",
  160. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  161. GetLastError());
  162. return(0);
  163. }
  164. hResource = OpenClusterResource( hClus, ResourceName );
  165. if ( hResource == NULL ) {
  166. fprintf(stderr,
  167. "OpenResource %ws failed %d\n", ResourceName, GetLastError());
  168. return(0);
  169. }
  170. if ( NodeName != NULL ) {
  171. hNode = OpenClusterNode( hClus, NodeName );
  172. if ( hNode == NULL ) {
  173. fprintf(stderr,
  174. "OpenNode %ws failed %d\n", NodeName, GetLastError());
  175. return(0);
  176. }
  177. }
  178. switch ( Access ) {
  179. case CLUS_ACCESS_READ:
  180. modify = CLUS_NO_MODIFY;
  181. break;
  182. case CLUS_ACCESS_WRITE:
  183. modify = CLUS_MODIFY;
  184. break;
  185. case CLUS_ACCESS_ANY:
  186. modify = CLUS_NO_MODIFY;
  187. break;
  188. }
  189. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, modify );
  190. controlCode = CLUSCTL_RESOURCE_CODE( controlCode );
  191. ReturnSize = 0;
  192. status = ClusterResourceControl( hResource,
  193. hNode,
  194. controlCode,
  195. &PropertyMsg,
  196. sizeof(PROPERTY_MSG),
  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. &PropertyMsg,
  206. sizeof(PROPERTY_MSG),
  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. }