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.

292 lines
8.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. DWORD inputSize;
  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. hGroup = OpenClusterGroup( hClus, GroupName );
  151. if ( hGroup == NULL ) {
  152. fprintf(stderr,
  153. "OpenGroup %ws failed %d\n", GroupName, 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 ( Access == CLUS_ACCESS_WRITE ) {
  165. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_MODIFY );
  166. } else {
  167. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, Access, CLUS_NO_MODIFY );
  168. }
  169. try_again:
  170. controlCode = CLUSCTL_GROUP_CODE( controlCode );
  171. ReturnSize = 0;
  172. status = ClusterGroupControl( hGroup,
  173. hNode,
  174. controlCode,
  175. NULL,
  176. 0,
  177. NULL,
  178. 0,
  179. &ReturnSize );
  180. if ( retry &&
  181. (status == ERROR_INVALID_FUNCTION) ) {
  182. controlCode = CLCTL_EXTERNAL_CODE( ControlCode, CLUS_ACCESS_WRITE, CLUS_MODIFY );
  183. retry = FALSE;
  184. goto try_again;
  185. }
  186. fprintf(stdout, "Status of initial request is %d, size is %d.\n",
  187. status, ReturnSize);
  188. if ( (status != ERROR_SUCCESS) ||
  189. (ReturnSize == 0) ) {
  190. return(0);
  191. }
  192. bufSize = ReturnSize;
  193. buffer = LocalAlloc( LMEM_FIXED, bufSize );
  194. if ( buffer == NULL ) {
  195. fprintf(stdout, "Failed to allocate a return buffer.\n");
  196. return(0);
  197. }
  198. status = ClusterGroupControl( hGroup,
  199. hNode,
  200. controlCode,
  201. NULL,
  202. 0,
  203. buffer,
  204. bufSize,
  205. &ReturnSize );
  206. fprintf(stdout, "Status of Control request = %d, size = %d\n",
  207. status, ReturnSize);
  208. if ( status == ERROR_SUCCESS ) {
  209. inputSize = ReturnSize;
  210. Data = (LPDWORD)buffer;
  211. PrintData = (LPDWORD)PrintBuffer;
  212. while ( ReturnSize ) {
  213. j = ReturnSize;
  214. if ( j > 16 ) j = 16;
  215. ZeroMemory(PrintBuffer, 18);
  216. MoveMemory(PrintBuffer, Data, j);
  217. ReturnSize -= j;
  218. for ( i = 0; i < 4; i++ ) {
  219. fprintf(stdout,
  220. " %08lx", PrintData[i]);
  221. }
  222. fprintf(stdout, " ");
  223. for ( i = 0; i < 16; i++ ) {
  224. fprintf(stdout, "%c",
  225. isprint(PrintBuffer[i])?PrintBuffer[i]:'.');
  226. }
  227. Data += 4;
  228. fprintf(stdout, "\n");
  229. }
  230. switch ( controlCode ) {
  231. case CLUSCTL_GROUP_GET_COMMON_PROPERTIES:
  232. controlCode = CLUSCTL_GROUP_SET_COMMON_PROPERTIES;
  233. break;
  234. case CLUSCTL_GROUP_GET_PRIVATE_PROPERTIES:
  235. controlCode = CLUSCTL_GROUP_SET_PRIVATE_PROPERTIES;
  236. break;
  237. default:
  238. controlCode = 0;
  239. break;
  240. }
  241. if ( controlCode != 0 ) {
  242. status = ClusterGroupControl( hGroup,
  243. hNode,
  244. controlCode,
  245. buffer,
  246. inputSize,
  247. NULL,
  248. 0,
  249. &ReturnSize );
  250. }
  251. fprintf(stdout, "Status of *INPUT* Control request = %d, size = %d\n",
  252. status, ReturnSize);
  253. }
  254. LocalFree(buffer);
  255. return(0);
  256. }