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.

251 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. cluster.c
  6. Abstract:
  7. Cluster support.
  8. Note: there is no handle revalidation support in the module because
  9. the cluster software should be informed when a group goes offline.
  10. Author:
  11. Albert Ting (AlbertT) 1-Oct-96
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #include "client.h"
  17. BOOL
  18. ClusterSplOpen(
  19. LPCTSTR pszServer,
  20. LPCTSTR pszResource,
  21. PHANDLE phSpooler,
  22. LPCTSTR pszName,
  23. LPCTSTR pszAddress
  24. )
  25. /*++
  26. Routine Description:
  27. Client side stub for opening a cluster resource.
  28. Arguments:
  29. pszServer - Server to open--currently must be NULL (local).
  30. pszResource - Spooler resource.
  31. phSpooler - Receives handle on success; recevies NULL otherwise.
  32. pszName - Comma delimited alternate netbios/computer names.
  33. pszAddress - Comma delimited tcpip address names.
  34. Return Value:
  35. TRUE - Success, phHandle must be closed with ClusterSplClose.
  36. FALSE - Failed--use GetLastError. *phSpooler is NULL.
  37. --*/
  38. {
  39. DWORD Status = ERROR_SUCCESS;
  40. BOOL bReturnValue = TRUE;
  41. PSPOOL pSpool = NULL;
  42. //
  43. // Preinitialize the spooler handle return to NULL.
  44. //
  45. __try {
  46. *phSpooler = NULL;
  47. } __except( EXCEPTION_EXECUTE_HANDLER ){
  48. SetLastError( ERROR_INVALID_PARAMETER );
  49. phSpooler = NULL;
  50. }
  51. if( !phSpooler ){
  52. goto Fail;
  53. }
  54. //
  55. // Disallow remote servers in this release.
  56. //
  57. if( pszServer ){
  58. SetLastError( ERROR_INVALID_PARAMETER );
  59. goto Fail;
  60. }
  61. //
  62. // Preallocate the handle.
  63. //
  64. pSpool = AllocSpool();
  65. if (pSpool)
  66. {
  67. RpcTryExcept {
  68. Status = RpcClusterSplOpen( (LPTSTR)pszServer,
  69. (LPTSTR)pszResource,
  70. &pSpool->hPrinter,
  71. (LPTSTR)pszName,
  72. (LPTSTR)pszAddress );
  73. if( Status ){
  74. SetLastError( Status );
  75. bReturnValue = FALSE;
  76. }
  77. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())){
  78. SetLastError( TranslateExceptionCode( RpcExceptionCode() ));
  79. bReturnValue = FALSE;
  80. } RpcEndExcept
  81. }
  82. else
  83. {
  84. SetLastError( ERROR_OUTOFMEMORY );
  85. bReturnValue = FALSE;
  86. }
  87. if( bReturnValue ){
  88. //
  89. // pSpool is orphaned to *phSpooler.
  90. //
  91. *phSpooler = (HANDLE)pSpool;
  92. pSpool = NULL;
  93. }
  94. Fail:
  95. FreeSpool( pSpool );
  96. return bReturnValue;
  97. }
  98. BOOL
  99. ClusterSplClose(
  100. HANDLE hSpooler
  101. )
  102. /*++
  103. Routine Description:
  104. Close the spooler.
  105. Arguments:
  106. hSpooler - Spooler to close.
  107. Return Value:
  108. Note: this function always returns TRUE, although it's spec'd out
  109. to return FALSE if the call fails.
  110. --*/
  111. {
  112. PSPOOL pSpool = (PSPOOL)hSpooler;
  113. HANDLE hSpoolerRPC;
  114. DWORD Status;
  115. switch( eProtectHandle( hSpooler, TRUE )){
  116. case kProtectHandlePendingDeletion:
  117. return TRUE;
  118. case kProtectHandleInvalid:
  119. return FALSE;
  120. default:
  121. break;
  122. }
  123. hSpoolerRPC = pSpool->hPrinter;
  124. RpcTryExcept {
  125. Status = RpcClusterSplClose( &hSpoolerRPC );
  126. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  127. Status = TranslateExceptionCode( RpcExceptionCode() );
  128. } RpcEndExcept
  129. if( hSpoolerRPC ){
  130. RpcSmDestroyClientContext(&hSpoolerRPC);
  131. }
  132. FreeSpool( pSpool );
  133. return TRUE;
  134. }
  135. BOOL
  136. ClusterSplIsAlive(
  137. HANDLE hSpooler
  138. )
  139. /*++
  140. Routine Description:
  141. Determines whether a spooler is still alive.
  142. Arguments:
  143. hSpooler - Spooler to check.
  144. Return Value:
  145. TRUE - Success
  146. FALSE - Fail; LastError set.
  147. --*/
  148. {
  149. PSPOOL pSpool = (PSPOOL)hSpooler;
  150. BOOL bReturnValue = TRUE;
  151. if( eProtectHandle( hSpooler, FALSE )){
  152. return FALSE;
  153. }
  154. RpcTryExcept {
  155. DWORD Status;
  156. Status = RpcClusterSplIsAlive( pSpool->hPrinter );
  157. if( Status ){
  158. SetLastError( Status );
  159. bReturnValue = FALSE;
  160. }
  161. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  162. SetLastError( TranslateExceptionCode( RpcExceptionCode() ));
  163. bReturnValue = FALSE;
  164. } RpcEndExcept
  165. vUnprotectHandle( hSpooler );
  166. return bReturnValue;
  167. }