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.

209 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. bind.c
  5. Abstract:
  6. Contains the RPC bind and un-bind routines
  7. Author:
  8. Dave Snipp (davesn) 01-Jun-1991
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. LPWSTR InterfaceAddress = L"\\pipe\\spoolss";
  16. handle_t GlobalBindHandle;
  17. handle_t
  18. PRINTER_HANDLE_bind (
  19. PRINTER_HANDLE hPrinter)
  20. /*++
  21. Routine Description:
  22. This routine is used to obtain a binding to the printer spooler.
  23. Arguments:
  24. Server - Supplies the name of the server where the printer spooler
  25. should be binded with.
  26. Return Value:
  27. A binding to the server will be returned, unless an error occurs,
  28. in which case zero will be returned.
  29. --*/
  30. {
  31. RPC_STATUS RpcStatus;
  32. LPWSTR StringBinding;
  33. handle_t BindingHandle;
  34. RpcStatus = RpcStringBindingComposeW(0, L"ncacn_np", 0, InterfaceAddress,
  35. L"Security=Anonymous Static False", &StringBinding);
  36. if ( RpcStatus != RPC_S_OK ) {
  37. return( 0 );
  38. }
  39. RpcStatus = RpcBindingFromStringBindingW(StringBinding, &BindingHandle);
  40. RpcStringFreeW(&StringBinding);
  41. if ( RpcStatus != RPC_S_OK ) {
  42. return(0);
  43. }
  44. return(BindingHandle);
  45. }
  46. void
  47. PRINTER_HANDLE_unbind (
  48. PRINTER_HANDLE hPrinter,
  49. handle_t BindingHandle)
  50. /*++
  51. Routine Description:
  52. This routine calls a common unbind routine that is shared by
  53. all services.
  54. This routine is called from the server service client stubs when
  55. it is necessary to unbind to a server.
  56. Arguments:
  57. ServerName - This is the name of the server from which to unbind.
  58. BindingHandle - This is the binding handle that is to be closed.
  59. Return Value:
  60. none.
  61. --*/
  62. {
  63. RPC_STATUS RpcStatus;
  64. RpcStatus = RpcBindingFree(&BindingHandle);
  65. ASSERT(RpcStatus == RPC_S_OK);
  66. return;
  67. }
  68. handle_t
  69. STRING_HANDLE_bind (
  70. STRING_HANDLE lpStr)
  71. /*++
  72. Routine Description:
  73. This routine calls a common bind routine that is shared by all services.
  74. This routine is called from the server service client stubs when
  75. it is necessary to bind to a server.
  76. Arguments:
  77. lpStr - \\ServerName\PrinterName
  78. Return Value:
  79. The binding handle is returned to the stub routine. If the
  80. binding is unsuccessful, a NULL will be returned.
  81. --*/
  82. {
  83. RPC_STATUS RpcStatus;
  84. LPWSTR StringBinding;
  85. handle_t BindingHandle;
  86. WCHAR ServerName[MAX_PATH+2];
  87. DWORD i;
  88. if (lpStr && lpStr[0] == L'\\' && lpStr[1] == L'\\') {
  89. // We have a servername
  90. for (i = 2 ; lpStr[i] && lpStr[i] != L'\\' ; ++i)
  91. ;
  92. if (i >= COUNTOF(ServerName))
  93. return FALSE;
  94. wcsncpy(ServerName, lpStr, i);
  95. ServerName[i] = L'\0';
  96. } else
  97. return FALSE;
  98. RpcStatus = RpcStringBindingComposeW(0, L"ncacn_np", ServerName,
  99. InterfaceAddress,
  100. L"Security=Impersonation Static True",
  101. &StringBinding);
  102. if ( RpcStatus != RPC_S_OK ) {
  103. return( 0 );
  104. }
  105. RpcStatus = RpcBindingFromStringBindingW(StringBinding, &BindingHandle);
  106. RpcStringFreeW(&StringBinding);
  107. if ( RpcStatus != RPC_S_OK ) {
  108. return(0);
  109. }
  110. return(BindingHandle);
  111. }
  112. void
  113. STRING_HANDLE_unbind (
  114. STRING_HANDLE lpStr,
  115. handle_t BindingHandle)
  116. /*++
  117. Routine Description:
  118. This routine calls a common unbind routine that is shared by
  119. all services.
  120. This routine is called from the server service client stubs when
  121. it is necessary to unbind to a server.
  122. Arguments:
  123. ServerName - This is the name of the server from which to unbind.
  124. BindingHandle - This is the binding handle that is to be closed.
  125. Return Value:
  126. none.
  127. --*/
  128. {
  129. RPC_STATUS RpcStatus;
  130. RpcStatus = RpcBindingFree(&BindingHandle);
  131. ASSERT(RpcStatus == RPC_S_OK);
  132. return;
  133. }