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.

271 lines
7.1 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. "TCONTROL [-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. void
  29. Usage(
  30. void
  31. )
  32. {
  33. fprintf(stderr, UsageText);
  34. exit(1);
  35. }
  36. LPWSTR
  37. GetString(
  38. IN LPSTR String
  39. )
  40. {
  41. LPWSTR wString;
  42. DWORD Length;
  43. Length = strlen(String)+1;
  44. wString = malloc(Length*sizeof(WCHAR));
  45. if (wString == NULL) {
  46. fprintf(stderr, "GetString couldn't malloc %d bytes\n",Length*sizeof(WCHAR));
  47. }
  48. mbstowcs(wString, String, Length);
  49. return(wString);
  50. }
  51. void
  52. ParseArgs(
  53. int argc,
  54. char *argv[]
  55. )
  56. {
  57. int i;
  58. DWORD IntCount;
  59. DWORD Value;
  60. CHAR TestValue[16];
  61. PUCHAR ControlData;
  62. LPWSTR access;
  63. for (i=1;i<argc;i++) {
  64. if ((argv[i][0] == '-') ||
  65. (argv[i][0] == '/')) {
  66. switch (argv[i][1]) {
  67. case 'c':
  68. if (++i == argc) {
  69. Usage();
  70. }
  71. ClusterName = GetString(argv[i]);
  72. break;
  73. case 'n':
  74. if ( ++i == argc ) {
  75. Usage();
  76. }
  77. NodeName = GetString(argv[i]);
  78. break;
  79. case 'r':
  80. if ( ++i == argc ) {
  81. Usage();
  82. }
  83. ResourceName = GetString(argv[i]);
  84. fprintf(stdout, "Resource = %ws\n", ResourceName);
  85. break;
  86. case 'a':
  87. if ( ++i == argc ) {
  88. Usage();
  89. }
  90. access = GetString(argv[i]);
  91. if ( lstrcmpiW( access, L"read" ) == 0 ) {
  92. Access = CLUS_ACCESS_READ;
  93. } else if ( lstrcmpiW( access, L"write" ) == 0 ) {
  94. Access = CLUS_ACCESS_WRITE;
  95. } else if ( lstrcmpiW( access, L"any" ) == 0 ) {
  96. Access = CLUS_ACCESS_ANY;
  97. } else {
  98. Usage();
  99. }
  100. break;
  101. default:
  102. Usage();
  103. break;
  104. }
  105. } else {
  106. ControlData = argv[i];
  107. IntCount = sscanf( ControlData, "%d", &Value );
  108. if ( IntCount == 1 ) {
  109. sprintf( TestValue, "%d\0", Value );
  110. if ( strcmp( TestValue, ControlData ) == 0 ) {
  111. ControlCode = Value;
  112. fprintf(stdout, "ControlCode = %d\n", ControlCode);
  113. }
  114. }
  115. }
  116. }
  117. return;
  118. if ( ControlCode == 0xffffffff ) {
  119. Usage();
  120. }
  121. }
  122. _cdecl
  123. main (argc, argv)
  124. int argc;
  125. char *argv[];
  126. {
  127. HCLUSTER hClus;
  128. HRESOURCE hResource;
  129. HNODE hNode = NULL;
  130. DWORD status;
  131. DWORD ReturnSize;
  132. DWORD bufSize;
  133. CHAR InBuffer[64];
  134. DWORD i,j;
  135. LPDWORD Data;
  136. LPDWORD PrintData;
  137. CHAR PrintBuffer[32];
  138. PUCHAR buffer;
  139. DWORD controlCode;
  140. BOOL retry = TRUE;
  141. ParseArgs(argc, argv);
  142. hClus = OpenCluster(ClusterName);
  143. if (hClus == NULL) {
  144. fprintf(stderr,
  145. "OpenCluster %ws failed %d\n",
  146. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  147. GetLastError());
  148. return(0);
  149. }
  150. hResource = OpenClusterResource( hClus, ResourceName );
  151. if ( hResource == NULL ) {
  152. fprintf(stderr,
  153. "OpenResource %ws failed %d\n", ResourceName, GetLastError());
  154. return(0);
  155. }
  156. if ( NodeName != NULL ) {
  157. hNode = OpenClusterNode( hClus, NodeName );
  158. if ( hNode == NULL ) {
  159. fprintf(stderr,
  160. "OpenNode %ws failed %d\n", NodeName, GetLastError());
  161. return(0);
  162. }
  163. }
  164. #if 0
  165. if ( Access == CLUS_ACCESS_WRITE ) {
  166. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_MODIFY );
  167. } else {
  168. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_NO_MODIFY );
  169. }
  170. controlCode = CLUSCTL_RESOURCE_CODE( controlCode );
  171. try_again:
  172. #endif
  173. controlCode = CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTY_FMTS;
  174. ReturnSize = 0;
  175. status = ClusterResourceControl( hResource,
  176. hNode,
  177. controlCode,
  178. NULL,
  179. 0,
  180. NULL,
  181. 0,
  182. &ReturnSize );
  183. #if 0
  184. if ( retry &&
  185. (status == ERROR_INVALID_FUNCTION) ) {
  186. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, CLUS_ACCESS_WRITE, CLUS_MODIFY );
  187. retry = FALSE;
  188. goto try_again;
  189. }
  190. #endif
  191. fprintf(stdout, "Status of initial request is %d, size is %d.\n",
  192. status, ReturnSize);
  193. if ( (status != ERROR_SUCCESS) ||
  194. (ReturnSize == 0) ) {
  195. return(0);
  196. }
  197. bufSize = ReturnSize;
  198. buffer = LocalAlloc( LMEM_FIXED, bufSize );
  199. if ( buffer == NULL ) {
  200. fprintf(stdout, "Failed to allocate a return buffer.\n");
  201. return(0);
  202. }
  203. status = ClusterResourceControl( hResource,
  204. hNode,
  205. controlCode,
  206. NULL,
  207. 0,
  208. buffer,
  209. bufSize,
  210. &ReturnSize );
  211. fprintf(stdout, "Status of Control request = %d, size = %d\n",
  212. status, ReturnSize);
  213. if ( status == ERROR_SUCCESS ) {
  214. Data = (LPDWORD)buffer;
  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. ReturnSize -= j;
  222. for ( i = 0; i < 4; i++ ) {
  223. fprintf(stdout,
  224. " %08lx", PrintData[i]);
  225. }
  226. fprintf(stdout, " ");
  227. for ( i = 0; i < 16; i++ ) {
  228. fprintf(stdout, "%c",
  229. isprint(PrintBuffer[i])?PrintBuffer[i]:'.');
  230. }
  231. Data += 4;
  232. fprintf(stdout, "\n");
  233. }
  234. }
  235. LocalFree(buffer);
  236. return(0);
  237. }