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.

237 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. rpcbind.c
  5. Abstract:
  6. Contains the RPC bind and un-bind routines for the Eventlog
  7. client-side APIs.
  8. Author:
  9. Rajen Shah (rajens) 30-Jul-1991
  10. Revision History:
  11. 30-Jul-1991 RajenS
  12. created
  13. --*/
  14. //
  15. // INCLUDES
  16. //
  17. #include <elfclntp.h>
  18. #include <lmsvc.h>
  19. #include <svcsp.h> // SVCS_LRPC_*
  20. #define SERVICE_EVENTLOG L"EVENTLOG"
  21. /****************************************************************************/
  22. handle_t
  23. EVENTLOG_HANDLE_W_bind (
  24. EVENTLOG_HANDLE_W ServerName)
  25. /*++
  26. Routine Description:
  27. This routine calls a common bind routine that is shared by all services.
  28. This routine is called from the ElfOpenEventLog API client stub when
  29. it is necessary to bind to a server.
  30. The binding is done to allow impersonation by the server since that is
  31. necessary for the API calls.
  32. Arguments:
  33. ServerName - A pointer to a string containing the name of the server
  34. to bind with.
  35. Return Value:
  36. The binding handle is returned to the stub routine. If the
  37. binding is unsuccessful, a NULL will be returned.
  38. --*/
  39. {
  40. handle_t bindingHandle;
  41. RPC_STATUS status;
  42. // If we're connecting to the local services use LRPC to avoid bugs
  43. // with cached tokens in named pipes. (Talk to AlbertT/MarioGo)
  44. // SVCS_LRPC_* defines come from svcsp.h
  45. if (ServerName == NULL ||
  46. wcscmp(ServerName, L"\\\\.") == 0 ) {
  47. PWSTR sb;
  48. status = RpcStringBindingComposeW(0,
  49. SVCS_LRPC_PROTOCOL,
  50. 0,
  51. SVCS_LRPC_PORT,
  52. 0,
  53. &sb);
  54. if (status == RPC_S_OK) {
  55. status = RpcBindingFromStringBindingW(sb, &bindingHandle);
  56. RpcStringFreeW(&sb);
  57. if (status == RPC_S_OK) {
  58. return bindingHandle;
  59. }
  60. }
  61. return NULL;
  62. }
  63. status = RpcpBindRpc (
  64. ServerName,
  65. SERVICE_EVENTLOG,
  66. NULL,
  67. &bindingHandle);
  68. // DbgPrint("EVENTLOG_bind: handle=%d\n",bindingHandle);
  69. return( bindingHandle);
  70. }
  71. /****************************************************************************/
  72. void
  73. EVENTLOG_HANDLE_W_unbind (
  74. EVENTLOG_HANDLE_W ServerName,
  75. handle_t BindingHandle)
  76. /*++
  77. Routine Description:
  78. This routine calls a common unbind routine that is shared by
  79. all services.
  80. Arguments:
  81. ServerName - This is the name of the server from which to unbind.
  82. BindingHandle - This is the binding handle that is to be closed.
  83. Return Value:
  84. none.
  85. --*/
  86. {
  87. RPC_STATUS status;
  88. // DbgPrint("EVENTLOG_HANDLE_unbind: handle=%d\n",BindingHandle);
  89. status = RpcpUnbindRpc ( BindingHandle);
  90. return;
  91. UNREFERENCED_PARAMETER(ServerName);
  92. }
  93. handle_t
  94. EVENTLOG_HANDLE_A_bind (
  95. EVENTLOG_HANDLE_A ServerName)
  96. /*++
  97. Routine Description:
  98. This routine calls EVENTLOG_HANDLE_W_bind to do the work.
  99. Arguments:
  100. ServerName - A pointer to a UNICODE string containing the name of
  101. the server to bind with.
  102. Return Value:
  103. The binding handle is returned to the stub routine. If the
  104. binding is unsuccessful, a NULL will be returned.
  105. --*/
  106. {
  107. UNICODE_STRING ServerNameU;
  108. ANSI_STRING ServerNameA;
  109. handle_t bindingHandle;
  110. //
  111. // Convert the ANSI string to a UNICODE string before calling the
  112. // UNICODE routine.
  113. //
  114. RtlInitAnsiString (&ServerNameA, (PSTR)ServerName);
  115. ServerNameU.Buffer = NULL;
  116. RtlAnsiStringToUnicodeString (
  117. &ServerNameU,
  118. &ServerNameA,
  119. TRUE
  120. );
  121. bindingHandle = EVENTLOG_HANDLE_W_bind(
  122. (EVENTLOG_HANDLE_W)ServerNameU.Buffer
  123. );
  124. RtlFreeUnicodeString (&ServerNameU);
  125. return( bindingHandle);
  126. }
  127. /****************************************************************************/
  128. void
  129. EVENTLOG_HANDLE_A_unbind (
  130. EVENTLOG_HANDLE_A ServerName,
  131. handle_t BindingHandle)
  132. /*++
  133. Routine Description:
  134. This routine calls EVENTLOG_HANDLE_W_unbind.
  135. Arguments:
  136. ServerName - This is the ANSI name of the server from which to unbind.
  137. BindingHandle - This is the binding handle that is to be closed.
  138. Return Value:
  139. none.
  140. --*/
  141. {
  142. UNICODE_STRING ServerNameU;
  143. ANSI_STRING ServerNameA;
  144. //
  145. // Convert the ANSI string to a UNICODE string before calling the
  146. // UNICODE routine.
  147. //
  148. RtlInitAnsiString (&ServerNameA, (PSTR)ServerName);
  149. ServerNameU.Buffer = NULL;
  150. RtlAnsiStringToUnicodeString (
  151. &ServerNameU,
  152. &ServerNameA,
  153. TRUE
  154. );
  155. EVENTLOG_HANDLE_W_unbind( (EVENTLOG_HANDLE_W)ServerNameU.Buffer,
  156. BindingHandle );
  157. RtlFreeUnicodeString (&ServerNameU);
  158. return;
  159. }