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.

176 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tdepend.c
  5. Abstract:
  6. Test for cluster resource dependency APIs
  7. Author:
  8. John Vert (jvert) 3-May-1996
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "clusapi.h"
  13. #include "stdio.h"
  14. #include "stdlib.h"
  15. LPWSTR ClusterName=NULL;
  16. BOOL Remove = FALSE;
  17. LPWSTR ResName=NULL;
  18. LPWSTR DependsName=NULL;
  19. CHAR UsageText[] =
  20. "TDEPEND [-c cluster] [-r] resource dependson\n"
  21. " cluster\tspecifies the name of the cluster to connect to\n"
  22. " -r\t\tdependency should be removed\n";
  23. void
  24. Usage(
  25. void
  26. )
  27. {
  28. fprintf(stderr, UsageText);
  29. exit(1);
  30. }
  31. LPWSTR
  32. GetString(
  33. IN LPSTR String
  34. )
  35. {
  36. LPWSTR wString;
  37. DWORD Length;
  38. Length = strlen(String)+1;
  39. wString = malloc(Length*sizeof(WCHAR));
  40. if (wString == NULL) {
  41. fprintf(stderr, "GetString couldn't malloc %d bytes\n",Length*sizeof(WCHAR));
  42. }
  43. mbstowcs(wString, String, Length);
  44. return(wString);
  45. }
  46. void
  47. ParseArgs(
  48. int argc,
  49. char *argv[]
  50. )
  51. {
  52. int i;
  53. DWORD ArgsSeen=0;
  54. for (i=1;i<argc;i++) {
  55. if ((argv[i][0] == '-') ||
  56. (argv[i][0] == '/')) {
  57. switch (argv[i][1]) {
  58. case 'c':
  59. if (++i == argc) {
  60. Usage();
  61. }
  62. ClusterName = GetString(argv[i]);
  63. break;
  64. case 'r':
  65. Remove = TRUE;
  66. break;
  67. default:
  68. Usage();
  69. break;
  70. }
  71. } else {
  72. switch (ArgsSeen) {
  73. case 0:
  74. //
  75. // resource
  76. //
  77. ArgsSeen++;
  78. ResName = GetString(argv[i]);
  79. break;
  80. case 1:
  81. DependsName = GetString(argv[i]);
  82. ArgsSeen++;
  83. break;
  84. default:
  85. Usage();
  86. }
  87. }
  88. }
  89. if ((ResName == NULL) || (DependsName == NULL)) {
  90. Usage();
  91. }
  92. }
  93. _cdecl
  94. main (argc, argv)
  95. int argc;
  96. char *argv[];
  97. {
  98. HCLUSTER hClus;
  99. HRESOURCE hResource;
  100. HRESOURCE hDependsOn;
  101. DWORD Status;
  102. ParseArgs(argc, argv);
  103. //
  104. // Connect to the specified cluster.
  105. //
  106. hClus = OpenCluster(ClusterName);
  107. if (hClus == NULL) {
  108. fprintf(stderr,
  109. "OpenCluster %ws failed %d\n",
  110. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  111. GetLastError());
  112. return(0);
  113. }
  114. //
  115. // Open the two resources.
  116. //
  117. hResource = OpenClusterResource(hClus, ResName);
  118. if (hResource == NULL) {
  119. fprintf(stderr,
  120. "OpenClusterResource Resource %ws failed %d\n",
  121. ResName,
  122. GetLastError());
  123. return(0);
  124. }
  125. hDependsOn = OpenClusterResource(hClus, DependsName);
  126. if (hDependsOn == NULL) {
  127. fprintf(stderr,
  128. "OpenClusterResource DependsOn %ws failed %d\n",
  129. DependsName,
  130. GetLastError());
  131. return(0);
  132. }
  133. //
  134. // Create or remove the dependency.
  135. //
  136. if (Remove) {
  137. Status = RemoveClusterResourceDependency(hResource, hDependsOn);
  138. if (Status != ERROR_SUCCESS) {
  139. fprintf(stderr,
  140. "RemoveClusterResourceDependency failed %d\n",
  141. Status);
  142. }
  143. } else {
  144. Status = AddClusterResourceDependency(hResource, hDependsOn);
  145. if (Status != ERROR_SUCCESS) {
  146. fprintf(stderr,
  147. "AddClusterResourceDependency failed %d\n",
  148. Status);
  149. }
  150. }
  151. }