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.

121 lines
3.8 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. //+-------------------------------------------------------------------------
  3. //
  4. // Microsoft Windows
  5. //
  6. // File: RpcCBind.cxx
  7. //
  8. // Contents: CRpcClientBinding, which wraps a client-side RPC
  9. // binding handle.
  10. //
  11. //--------------------------------------------------------------------------
  12. #include <pch.cxx>
  13. #pragma hdrstop
  14. #include "trklib.hxx"
  15. //+----------------------------------------------------------------------------
  16. //
  17. // Method: CRpcClientBinding::RcInitialize
  18. //
  19. // Synopsis: Create a binding handle to the caller-provided
  20. // machine/protocol/endpoint. If requested, set security too.
  21. //
  22. //+----------------------------------------------------------------------------
  23. void
  24. CRpcClientBinding::RcInitialize(const CMachineId &mcid,
  25. const TCHAR *ptszRpcProtocol, const TCHAR *ptszRpcEndPoint,
  26. RC_AUTHENTICATE auth )
  27. {
  28. RPC_STATUS rpcstatus;
  29. RPC_TCHAR * ptszStringBinding;
  30. RPC_TCHAR tszComputerName[ MAX_COMPUTERNAME_LENGTH + 1 ];
  31. TrkAssert(!_fBound);
  32. // Get the name of the computer to which we're binding.
  33. mcid.GetName(tszComputerName, sizeof(tszComputerName)/sizeof(tszComputerName[0]));
  34. // Create the binding string that encapsulates the target machine, protocol,
  35. // and endpoint.
  36. rpcstatus = RpcStringBindingCompose(NULL,
  37. const_cast<TCHAR*>(ptszRpcProtocol),
  38. tszComputerName,
  39. const_cast<TCHAR*>(ptszRpcEndPoint),
  40. NULL,
  41. &ptszStringBinding);
  42. if( rpcstatus )
  43. {
  44. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcStringBindingCompose %lu"), rpcstatus ));
  45. TrkRaiseWin32Error( rpcstatus );
  46. }
  47. // Get a binding handle from the binding string.
  48. rpcstatus = RpcBindingFromStringBinding(ptszStringBinding, &_BindingHandle);
  49. RpcStringFree(&ptszStringBinding);
  50. if( rpcstatus )
  51. {
  52. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcBindingFromStringBinding") ));
  53. TrkRaiseWin32Error( rpcstatus );
  54. }
  55. // If necessary, set security on the binding
  56. if( RpcSecurityEnabled() && NO_AUTHENTICATION != auth )
  57. {
  58. TrkAssert( PRIVACY_AUTHENTICATION == auth || INTEGRITY_AUTHENTICATION == auth );
  59. RPC_TCHAR tszAuthName[MAX_COMPUTERNAME_LENGTH * 2 + 2 + 1]; // slash and $ and NUL
  60. mcid.GetLocalAuthName(tszAuthName, sizeof(tszAuthName)/sizeof(tszAuthName[0]));
  61. rpcstatus = RpcBindingSetAuthInfo(_BindingHandle,
  62. tszAuthName,
  63. PRIVACY_AUTHENTICATION == auth
  64. ? RPC_C_AUTHN_LEVEL_PKT_PRIVACY
  65. : RPC_C_AUTHN_LEVEL_PKT_INTEGRITY,
  66. RPC_C_AUTHN_GSS_NEGOTIATE,
  67. NULL, // AuthIdentity - current process/address space
  68. 0); // AuthzSvc - ignored for RPC_C_AUTHN_DCE_PRIVATE
  69. if( rpcstatus )
  70. {
  71. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcBindingSetAuthInfo %lu"), rpcstatus ));
  72. TrkRaiseWin32Error( rpcstatus );
  73. }
  74. } // if( RpcSecurityEnabled() )
  75. _fBound = TRUE;
  76. }
  77. //+----------------------------------------------------------------------------
  78. //
  79. // Method: UnInitialize
  80. //
  81. // Synopsis: Free a binding.
  82. //
  83. //+----------------------------------------------------------------------------
  84. void
  85. CRpcClientBinding::UnInitialize()
  86. {
  87. if (_fBound)
  88. {
  89. RpcBindingFree(&_BindingHandle);
  90. _fBound = FALSE;
  91. }
  92. CTrkRpcConfig::UnInitialize();
  93. }