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.

264 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tcontrol.c
  5. Abstract:
  6. Test for cluster group 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 GroupName=NULL;
  18. LPWSTR NodeName=NULL;
  19. DWORD ControlCode=0xffffffff;
  20. DWORD Access=CLUS_ACCESS_READ;
  21. CHAR UsageText[] =
  22. "TCONTROL [-c cluster] -n node -g group -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. " group\tspecifies the name of the group to control\n"
  26. " access\tspecifies the access to the group (read, write or any)\n"
  27. " ControlCode\ta number between 1 and 99\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 'g':
  80. if ( ++i == argc ) {
  81. Usage();
  82. }
  83. GroupName = GetString(argv[i]);
  84. fprintf(stdout, "Group = %ws\n", GroupName);
  85. break;
  86. case 'a':
  87. if ( ++i == argc ) {
  88. Usage();
  89. }
  90. access = GetString(argv[i]);
  91. if ( lstrcmpiW( access, L"read" ) ) {
  92. Access = CLUS_ACCESS_READ;
  93. } else if ( lstrcmpiW( access, L"write" ) ) {
  94. Access = CLUS_ACCESS_WRITE;
  95. } else if ( lstrcmpiW( access, L"any" ) ) {
  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. if ( ControlCode == 0xffffffff ) {
  118. Usage();
  119. }
  120. }
  121. _cdecl
  122. main (argc, argv)
  123. int argc;
  124. char *argv[];
  125. {
  126. HCLUSTER hClus;
  127. HGROUP hGroup;
  128. HNODE hNode = NULL;
  129. DWORD status;
  130. DWORD ReturnSize;
  131. DWORD bufSize;
  132. CHAR InBuffer[64];
  133. DWORD i,j;
  134. LPDWORD Data;
  135. LPDWORD PrintData;
  136. CHAR PrintBuffer[32];
  137. PUCHAR buffer;
  138. DWORD controlCode;
  139. BOOL retry = TRUE;
  140. ParseArgs(argc, argv);
  141. hClus = OpenCluster(ClusterName);
  142. if (hClus == NULL) {
  143. fprintf(stderr,
  144. "OpenCluster %ws failed %d\n",
  145. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  146. GetLastError());
  147. return(0);
  148. }
  149. hGroup = OpenClusterGroup( hClus, GroupName );
  150. if ( hGroup == NULL ) {
  151. fprintf(stderr,
  152. "OpenGroup %ws failed %d\n", GroupName, GetLastError());
  153. return(0);
  154. }
  155. if ( NodeName != NULL ) {
  156. hNode = OpenClusterNode( hClus, NodeName );
  157. if ( hNode == NULL ) {
  158. fprintf(stderr,
  159. "OpenNode %ws failed %d\n", NodeName, GetLastError());
  160. return(0);
  161. }
  162. }
  163. if ( Access == CLUS_ACCESS_WRITE ) {
  164. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_MODIFY );
  165. } else {
  166. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_NO_MODIFY );
  167. }
  168. try_again:
  169. controlCode = CLUSCTL_GROUP_CODE( controlCode );
  170. ReturnSize = 0;
  171. status = ClusterGroupControl( hGroup,
  172. hNode,
  173. controlCode,
  174. NULL,
  175. 0,
  176. NULL,
  177. 0,
  178. &ReturnSize );
  179. if ( retry &&
  180. (status == ERROR_INVALID_FUNCTION) ) {
  181. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, CLUS_ACCESS_WRITE, CLUS_MODIFY );
  182. retry = FALSE;
  183. goto try_again;
  184. }
  185. fprintf(stdout, "Status of initial request is %d, size is %d.\n",
  186. status, ReturnSize);
  187. if ( (status != ERROR_SUCCESS) ||
  188. (ReturnSize == 0) ) {
  189. return(0);
  190. }
  191. bufSize = ReturnSize;
  192. buffer = LocalAlloc( LMEM_FIXED, bufSize );
  193. if ( buffer == NULL ) {
  194. fprintf(stdout, "Failed to allocate a return buffer.\n");
  195. return(0);
  196. }
  197. status = ClusterGroupControl( hGroup,
  198. hNode,
  199. controlCode,
  200. NULL,
  201. 0,
  202. buffer,
  203. bufSize,
  204. &ReturnSize );
  205. fprintf(stdout, "Status of Control request = %d, size = %d\n",
  206. status, ReturnSize);
  207. if ( status == ERROR_SUCCESS ) {
  208. Data = (LPDWORD)buffer;
  209. PrintData = (LPDWORD)PrintBuffer;
  210. while ( ReturnSize ) {
  211. j = ReturnSize;
  212. if ( j > 16 ) j = 16;
  213. ZeroMemory(PrintBuffer, 18);
  214. MoveMemory(PrintBuffer, Data, j);
  215. ReturnSize -= j;
  216. for ( i = 0; i < 4; i++ ) {
  217. fprintf(stdout,
  218. " %08lx", PrintData[i]);
  219. }
  220. fprintf(stdout, " ");
  221. for ( i = 0; i < 16; i++ ) {
  222. fprintf(stdout, "%c",
  223. isprint(PrintBuffer[i])?PrintBuffer[i]:'.');
  224. }
  225. Data += 4;
  226. fprintf(stdout, "\n");
  227. }
  228. }
  229. LocalFree(buffer);
  230. return(0);
  231. }