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.

275 lines
7.5 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 ResourceTypeName=NULL;
  18. LPWSTR NodeName=NULL;
  19. DWORD ControlCode=0xffffffff;
  20. DWORD Access=CLUS_ACCESS_READ;
  21. CHAR UsageText[] =
  22. "TFMT [-c cluster] -n node -r restypename -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. " restypename\tspecifies the name of the resource type 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. ResourceTypeName = GetString(argv[i]);
  84. fprintf(stdout, "ResourceType = %ws\n", ResourceTypeName);
  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. #if 0
  151. hResource = OpenClusterResource( hClus, ResourceTypeName );
  152. if ( hResource == NULL ) {
  153. fprintf(stderr,
  154. "OpenResource %ws failed %d\n", ResourceTypeName, GetLastError());
  155. return(0);
  156. }
  157. #endif
  158. if ( NodeName != NULL ) {
  159. hNode = OpenClusterNode( hClus, NodeName );
  160. if ( hNode == NULL ) {
  161. fprintf(stderr,
  162. "OpenNode %ws failed %d\n", NodeName, GetLastError());
  163. return(0);
  164. }
  165. }
  166. #if 0
  167. if ( Access == CLUS_ACCESS_WRITE ) {
  168. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_MODIFY );
  169. } else {
  170. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_NO_MODIFY );
  171. }
  172. controlCode = CLUSCTL_RESOURCE_CODE( controlCode );
  173. try_again:
  174. #endif
  175. controlCode = CLUSCTL_RESOURCE_TYPE_GET_PRIVATE_RESOURCE_PROPERTY_FMTS;
  176. ReturnSize = 0;
  177. status = ClusterResourceTypeControl( hClus,
  178. ResourceTypeName,
  179. hNode,
  180. controlCode,
  181. NULL,
  182. 0,
  183. NULL,
  184. 0,
  185. &ReturnSize );
  186. #if 0
  187. if ( retry &&
  188. (status == ERROR_INVALID_FUNCTION) ) {
  189. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, CLUS_ACCESS_WRITE, CLUS_MODIFY );
  190. retry = FALSE;
  191. goto try_again;
  192. }
  193. #endif
  194. fprintf(stdout, "Status of initial request is %d, size is %d.\n",
  195. status, ReturnSize);
  196. if ( (status != ERROR_SUCCESS) ||
  197. (ReturnSize == 0) ) {
  198. return(0);
  199. }
  200. bufSize = ReturnSize;
  201. buffer = LocalAlloc( LMEM_FIXED, bufSize );
  202. if ( buffer == NULL ) {
  203. fprintf(stdout, "Failed to allocate a return buffer.\n");
  204. return(0);
  205. }
  206. status = ClusterResourceTypeControl( hClus,
  207. ResourceTypeName,
  208. hNode,
  209. controlCode,
  210. NULL,
  211. 0,
  212. buffer,
  213. bufSize,
  214. &ReturnSize );
  215. fprintf(stdout, "Status of Control request = %d, size = %d\n",
  216. status, ReturnSize);
  217. if ( status == ERROR_SUCCESS ) {
  218. Data = (LPDWORD)buffer;
  219. PrintData = (LPDWORD)PrintBuffer;
  220. while ( ReturnSize ) {
  221. j = ReturnSize;
  222. if ( j > 16 ) j = 16;
  223. ZeroMemory(PrintBuffer, 18);
  224. MoveMemory(PrintBuffer, Data, j);
  225. ReturnSize -= j;
  226. for ( i = 0; i < 4; i++ ) {
  227. fprintf(stdout,
  228. " %08lx", PrintData[i]);
  229. }
  230. fprintf(stdout, " ");
  231. for ( i = 0; i < 16; i++ ) {
  232. fprintf(stdout, "%c",
  233. isprint(PrintBuffer[i])?PrintBuffer[i]:'.');
  234. }
  235. Data += 4;
  236. fprintf(stdout, "\n");
  237. }
  238. }
  239. LocalFree(buffer);
  240. return(0);
  241. }