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.

172 lines
4.2 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. rpcbind.c
  5. Abstract:
  6. This module contains the RPC bind and un-bind routines for the
  7. Configuration Manager client-side APIs.
  8. Author:
  9. Paula Tomlinson (paulat) 6-21-1995
  10. Environment:
  11. User-mode only.
  12. Revision History:
  13. 21-June-1995 paulat
  14. Creation and initial implementation.
  15. --*/
  16. //
  17. // includes
  18. //
  19. #include "precomp.h"
  20. #pragma hdrstop
  21. #include "cfgi.h"
  22. #include <svcsp.h>
  23. handle_t
  24. PNP_HANDLE_bind(
  25. PNP_HANDLE ServerName
  26. )
  27. /*++
  28. Routine Description:
  29. This routine calls a common bind routine that is shared by all
  30. services. This routine is called from the PNP API client stubs
  31. when it is necessary to bind to a server. The binding is done to
  32. allow impersonation by the server since that is necessary for the
  33. API calls.
  34. Arguments:
  35. ServerName - A pointer to a string containing the name of the server
  36. to bind with.
  37. Return Value:
  38. The binding handle is returned to the stub routine. If the
  39. binding is unsuccessful, a NULL will be returned.
  40. --*/
  41. {
  42. handle_t BindingHandle;
  43. NTSTATUS Status;
  44. //
  45. // Bind to the server on the shared named pipe for services.exe RPC servers.
  46. // We specify the following network options for security:
  47. //
  48. // L"Security=Impersonation Dynamic True",
  49. //
  50. // The "Impersonation" option indicates that in addition to knowing the
  51. // identity of the client, the server may impersonate the client as well.
  52. //
  53. // The "Dynamic" option specifies dynamic identity tracking, such that
  54. // changes in the client security identity are seen by the server.
  55. //
  56. // NOTE: When using the named pipe transport, "Dynamic" identity tracking is
  57. // only available to local RPC clients. For remote clients, "Static"
  58. // identity tracking is used, which means that changes in the client
  59. // security identity are NOT seen by the server. The identity of the caller
  60. // is saved during the first remote procedure call on that binding handle
  61. //
  62. // The "True" option (Effective = TRUE) specifies that only token privileges
  63. // currently enabled for the client are present in the token seen by the
  64. // server. This means that the server cannot enable any privileges the
  65. // client may have possessed, but were not explicitly enabled at the time of
  66. // the call. This is desirable, because the PlugPlay RPC server should
  67. // never need to enable any client privileges itself. Any privileges
  68. // required by the server must be enabled by the client prior to the call.
  69. //
  70. Status =
  71. RpcpBindRpc(
  72. ServerName, // UNC Server Name
  73. SVCS_RPC_PIPE, // L"ntsvcs"
  74. L"Security=Impersonation Dynamic True",
  75. &BindingHandle);
  76. //
  77. // The possible return codes from RpcpBindRpc are STATUS_SUCCESS,
  78. // STATUS_NO_MEMORY and STATUS_INVALID_COMPUTER_NAME. Since the format
  79. // of the bind routine is fixed, set any errors encountered as the last
  80. // error and return NULL.
  81. //
  82. if (Status != STATUS_SUCCESS) {
  83. BindingHandle = NULL;
  84. if (Status == STATUS_NO_MEMORY) {
  85. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  86. } else if (Status == STATUS_INVALID_COMPUTER_NAME) {
  87. SetLastError(ERROR_INVALID_COMPUTERNAME);
  88. } else {
  89. SetLastError(ERROR_GEN_FAILURE);
  90. }
  91. }
  92. return BindingHandle;
  93. } // PNP_HANDLE_bind
  94. void
  95. PNP_HANDLE_unbind(
  96. PNP_HANDLE ServerName,
  97. handle_t BindingHandle
  98. )
  99. /*++
  100. Routine Description:
  101. This routine calls a common unbind routine that is shared by
  102. all services. It is called from the PlugPlay RPC client stubs
  103. when it is necessary to unbind from the RPC server.
  104. Arguments:
  105. ServerName - This is the name of the server from which to unbind.
  106. BindingHandle - This is the binding handle that is to be closed.
  107. Return Value:
  108. None.
  109. --*/
  110. {
  111. NTSTATUS Status;
  112. UNREFERENCED_PARAMETER(ServerName);
  113. Status = RpcpUnbindRpc(BindingHandle);
  114. return;
  115. } // PNP_HANDLE_unbind