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.

186 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. RpcBind.c
  5. Abstract:
  6. This file contains RPC Bind caching functions:
  7. (public functions)
  8. NetpBindRpc
  9. NetpUnbindRpc
  10. NOTE: Initialization is done via a dllinit routine for netapi.dll.
  11. Author:
  12. Dan Lafferty danl 25-Oct-1991
  13. Environment:
  14. User Mode - Win32
  15. Revision History:
  16. 12-Oct-1993 Danl
  17. #IFDEF out the caching code when we are not building with the
  18. cache. (Make it smaller).
  19. 15-Jan-1992 Danl
  20. Make sure LocalComputerName is not NULL prior to doing the
  21. string compare. Make the string compare case insensitive.
  22. 10-Jun-1992 JohnRo
  23. Tons of debug output changes.
  24. 25-Oct-1991 danl
  25. Created
  26. --*/
  27. // These must be included first:
  28. #include <nt.h> // NTSTATUS, etc.
  29. #include <ntrtl.h> // needed for nturtl.h
  30. #include <nturtl.h> // needed for windows.h when I have nt.h
  31. #include <windows.h> // win32 typedefs
  32. #include <lmcons.h> // NET_API_STATUS
  33. #include <rpc.h> // rpc prototypes
  34. #include <netlib.h>
  35. #include <netlibnt.h> // NetpNtStatusToApiStatus
  36. #include <tstring.h> // STRSIZE, STRLEN, STRCPY, etc.
  37. #include <rpcutil.h>
  38. #include <ntrpcp.h> // RpcpBindRpc
  39. // These may be included in any order:
  40. #include <lmerr.h> // NetError codes
  41. #include <string.h> // for strcpy strcat strlen memcmp
  42. #include <debuglib.h> // IF_DEBUG
  43. #include <netdebug.h> // FORMAT_ equates, NetpKdPrint(()), NetpAssert(), etc.
  44. #include <prefix.h> // PREFIX_ equates.
  45. //
  46. // CONSTANTS & MACROS
  47. //
  48. #ifndef FORMAT_HANDLE
  49. #define FORMAT_HANDLE "0x%lX"
  50. #endif
  51. RPC_STATUS
  52. NetpBindRpc(
  53. IN LPTSTR ServerName,
  54. IN LPTSTR ServiceName,
  55. IN LPTSTR NetworkOptions,
  56. OUT RPC_BINDING_HANDLE *BindingHandlePtr
  57. )
  58. /*++
  59. Routine Description:
  60. Binds to the RPC server if possible.
  61. Arguments:
  62. ServerName - Name of server to bind with. This may be NULL if it is to
  63. bind with the local server.
  64. ServiceName - Name of service to bind with. This is typically the
  65. name of the interface as specified in the .idl file. Although
  66. it doesn't HAVE to be, it would be consistant to use that name.
  67. NetworkOptions - Supplies network options which describe the
  68. security to be used for named pipe instances created for
  69. this binding handle.
  70. BindingHandlePtr - Location where binding handle is to be placed.
  71. Return Value:
  72. NERR_Success if the binding was successful. An error value if it
  73. was not.
  74. --*/
  75. {
  76. NTSTATUS ntStatus;
  77. NET_API_STATUS status = NERR_Success;
  78. //
  79. // Create a New binding
  80. //
  81. ntStatus = RpcpBindRpc(
  82. (LPWSTR) ServerName,
  83. (LPWSTR) ServiceName,
  84. (LPWSTR) NetworkOptions,
  85. BindingHandlePtr);
  86. if ( ntStatus != RPC_S_OK ) {
  87. IF_DEBUG(RPC) {
  88. NetpKdPrint((PREFIX_NETLIB "[NetpBindRpc]RpcpBindRpc Failed "
  89. "(impersonating) "FORMAT_NTSTATUS "\n",ntStatus));
  90. }
  91. }
  92. return(NetpNtStatusToApiStatus(ntStatus));
  93. }
  94. RPC_STATUS
  95. NetpUnbindRpc(
  96. IN RPC_BINDING_HANDLE BindingHandle
  97. )
  98. /*++
  99. Routine Description:
  100. This function is called when the application desired to unbind an
  101. RPC handle. If the handle is cached, the handle is not actually unbound.
  102. Instead the entry for this handle has its UseCount decremented.
  103. If the handle is not in the cache, the RpcUnbind routine is called and
  104. the win32 mapped status is returned.
  105. Arguments:
  106. BindingHandle - This points to the binding handle that is to
  107. have its UseCount decremented.
  108. Return Value:
  109. NERR_Success - If the handle was successfully unbound, or if the
  110. cache entry UseCount was decremented.
  111. --*/
  112. {
  113. RPC_STATUS status = NERR_Success;
  114. IF_DEBUG(RPC) {
  115. NetpKdPrint((PREFIX_NETLIB "[NetpUnbindRpc] UnBinding Handle "
  116. FORMAT_HANDLE "\n", BindingHandle));
  117. }
  118. status = RpcpUnbindRpc( BindingHandle );
  119. IF_DEBUG(RPC) {
  120. if (status) {
  121. NetpKdPrint((PREFIX_NETLIB "Unbind Failure! RpcUnbind = "
  122. FORMAT_NTSTATUS "\n",status));
  123. }
  124. }
  125. status = NetpNtStatusToApiStatus(status);
  126. return(status);
  127. }