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.

127 lines
2.5 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. LPWSTR InterfaceAddress = L"\\pipe\\spoolss";
  15. handle_t
  16. STRING_HANDLE_bind (
  17. STRING_HANDLE lpStr)
  18. /*++
  19. Routine Description:
  20. This routine calls a common bind routine that is shared by all services.
  21. This routine is called from the server service client stubs when
  22. it is necessary to bind to a server.
  23. Arguments:
  24. lpStr - \\ServerName\PrinterName
  25. Return Value:
  26. The binding handle is returned to the stub routine. If the
  27. binding is unsuccessful, a NULL will be returned.
  28. --*/
  29. {
  30. RPC_STATUS RpcStatus;
  31. LPWSTR StringBinding;
  32. handle_t BindingHandle;
  33. WCHAR ServerName[MAX_PATH + 2];
  34. DWORD i;
  35. if (lpStr && lpStr[0] == L'\\' && lpStr[1] == L'\\') {
  36. // We have a servername
  37. for (i = 2 ; lpStr[i] && lpStr[i] != L'\\' ; ++i)
  38. ;
  39. if (i >= COUNTOF(ServerName))
  40. return FALSE;
  41. wcsncpy(ServerName, lpStr, i);
  42. ServerName[i] = L'\0';
  43. } else
  44. return FALSE;
  45. RpcStatus = RpcStringBindingComposeW(0, L"ncacn_np", ServerName,
  46. InterfaceAddress,
  47. L"Security=Impersonation Dynamic True",
  48. &StringBinding);
  49. if ( RpcStatus != RPC_S_OK ) {
  50. return( 0 );
  51. }
  52. RpcStatus = RpcBindingFromStringBindingW(StringBinding, &BindingHandle);
  53. RpcStringFreeW(&StringBinding);
  54. if ( RpcStatus != RPC_S_OK ) {
  55. return(0);
  56. }
  57. return(BindingHandle);
  58. }
  59. void
  60. STRING_HANDLE_unbind (
  61. STRING_HANDLE lpStr,
  62. handle_t BindingHandle)
  63. /*++
  64. Routine Description:
  65. This routine calls a common unbind routine that is shared by
  66. all services.
  67. This routine is called from the server service client stubs when
  68. it is necessary to unbind to a server.
  69. Arguments:
  70. ServerName - This is the name of the server from which to unbind.
  71. BindingHandle - This is the binding handle that is to be closed.
  72. Return Value:
  73. none.
  74. --*/
  75. {
  76. RPC_STATUS RpcStatus;
  77. RpcStatus = RpcBindingFree(&BindingHandle);
  78. ASSERT(RpcStatus != RPC_S_INVALID_BINDING);
  79. return;
  80. }