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.

273 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rpcbind.c
  5. Abstract:
  6. LSA - Client RPC Binding Routines
  7. Author:
  8. Scott Birrell (ScottBi) April 30, 1991
  9. Environment:
  10. Revision History:
  11. --*/
  12. #include "lsaclip.h"
  13. #include <ntrpcp.h> // prototypes for MIDL user functions
  14. #include "adtgen.h"
  15. handle_t
  16. PLSAPR_SERVER_NAME_bind (
  17. IN OPTIONAL PLSAPR_SERVER_NAME ServerName
  18. )
  19. /*++
  20. Routine Description:
  21. This routine is called from the LSA client stubs when
  22. it is necessary to bind to the LSA on some server.
  23. Arguments:
  24. ServerName - A pointer to a string containing the name of the server
  25. to bind with.
  26. Return Value:
  27. The binding handle is returned to the stub routine. If the
  28. binding is unsuccessful, a NULL will be returned.
  29. --*/
  30. {
  31. handle_t BindingHandle;
  32. NTSTATUS Status;
  33. Status = RpcpBindRpc (
  34. ServerName,
  35. L"lsarpc",
  36. 0,
  37. &BindingHandle
  38. );
  39. if (!NT_SUCCESS(Status)) {
  40. // DbgPrint("PLSAPR_SERVER_NAME_bind: RpcpBindRpc failed 0x%lx\n", Status);
  41. }
  42. return( BindingHandle);
  43. }
  44. VOID
  45. PLSAPR_SERVER_NAME_unbind (
  46. IN OPTIONAL PLSAPR_SERVER_NAME ServerName,
  47. IN handle_t BindingHandle
  48. )
  49. /*++
  50. Routine Description:
  51. This routine is called from the LSA client stubs when
  52. it is necessary to unbind from the LSA server.
  53. Arguments:
  54. ServerName - This is the name of the server from which to unbind.
  55. BindingHandle - This is the binding handle that is to be closed.
  56. Return Value:
  57. none.
  58. --*/
  59. {
  60. RpcpUnbindRpc ( BindingHandle );
  61. return;
  62. UNREFERENCED_PARAMETER( ServerName ); // This parameter is not used
  63. }
  64. DWORD
  65. LsaNtStatusToWinError(
  66. IN NTSTATUS Status
  67. )
  68. /*++
  69. Routine Description:
  70. This routine converts and NTSTATUS to an win32 error code. It is used
  71. by people who want to call the LSA APIs but are writing for a win32
  72. environment.
  73. Arguments:
  74. Status - The status code to be mapped
  75. Return Value:
  76. The return from RtlNtStatusToDosError. If the error could not be
  77. mapped, then ERROR_MR_MID_NOT_FOUND is returned.
  78. --*/
  79. {
  80. return(RtlNtStatusToDosError(Status));
  81. }
  82. NTSTATUS
  83. LsapApiReturnResult(
  84. ULONG ExceptionCode
  85. )
  86. /*++
  87. Routine Description:
  88. This function converts an exception code or status value returned
  89. from the client stub to a value suitable for return by the API to
  90. the client.
  91. Arguments:
  92. ExceptionCode - The exception code to be converted.
  93. Return Value:
  94. NTSTATUS - The converted Nt Status code.
  95. --*/
  96. {
  97. //
  98. // Return the actual value if compatible with Nt status codes,
  99. // otherwise, return STATUS_UNSUCCESSFUL.
  100. //
  101. if (!NT_SUCCESS((NTSTATUS) ExceptionCode)) {
  102. return (NTSTATUS) ExceptionCode;
  103. } else {
  104. return STATUS_UNSUCCESSFUL;
  105. }
  106. }
  107. handle_t
  108. PAUTHZ_AUDIT_EVENT_TYPE_OLD_bind (
  109. IN PAUTHZ_AUDIT_EVENT_TYPE_OLD pAuditEventType
  110. )
  111. /*++
  112. Routine Description:
  113. This routine is called from the LSA client stubs when
  114. it is necessary to bind to local LSA.
  115. Arguments:
  116. AuditInfo -- ignored
  117. Return Value:
  118. The binding handle is returned to the stub routine.
  119. If the binding is unsuccessful, a NULL will be returned.
  120. --*/
  121. {
  122. handle_t hBinding=NULL;
  123. NTSTATUS Status;
  124. PWSTR pszBinding;
  125. RPC_STATUS RpcStatus;
  126. //
  127. // the first param takes a server-name. use NULL
  128. // to force a local binding
  129. //
  130. RpcStatus = RpcStringBindingComposeW(
  131. NULL, // uuid of lsarpc
  132. L"ncalrpc", // we want to use LRPC
  133. NULL, // network address (local machine)
  134. L"audit", // endpoint name
  135. L"", // options
  136. &pszBinding );
  137. if ( RpcStatus == RPC_S_OK )
  138. {
  139. RpcStatus = RpcBindingFromStringBindingW(
  140. pszBinding,
  141. &hBinding
  142. );
  143. RpcStringFreeW( &pszBinding );
  144. }
  145. Status = I_RpcMapWin32Status( RpcStatus );
  146. if (!NT_SUCCESS(Status)) {
  147. DbgPrint("PAUDIT_AUTHZ_AUDIT_EVENT_OLD_bind: failed 0x%lx\n", Status);
  148. }
  149. UNREFERENCED_PARAMETER( pAuditEventType );
  150. return( hBinding );
  151. }
  152. VOID
  153. PAUTHZ_AUDIT_EVENT_TYPE_OLD_unbind (
  154. IN PAUTHZ_AUDIT_EVENT_TYPE_OLD pAuditEventType, OPTIONAL
  155. IN handle_t BindingHandle
  156. )
  157. /*++
  158. Routine Description:
  159. This routine is called from the LSA client stubs when
  160. it is necessary to unbind from the LSA server.
  161. Arguments:
  162. AuditInfo - ignored
  163. BindingHandle - This is the binding handle that is to be closed.
  164. Return Value:
  165. none.
  166. --*/
  167. {
  168. RpcpUnbindRpc ( BindingHandle );
  169. UNREFERENCED_PARAMETER( pAuditEventType ); // This parameter is not used
  170. return;
  171. }