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.

195 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 2001-2001 Microsoft Corporation
  3. Module Name:
  4. bind.c
  5. Abstract:
  6. Domain Name System (DNS) Resolver
  7. Client RPC bind\unbind routines.
  8. MIDL memory allocation routines.
  9. Author:
  10. Jim Gilroy (jamesg) April 2001
  11. Revision History:
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <dnsrslvr.h>
  18. #include "..\..\dnslib\local.h" // for memory routines
  19. //
  20. // Bind to remote machine
  21. //
  22. // Note, there's one obvious problem with binding to a remote
  23. // resolver -- you have to finding the machine and this is
  24. // the resolver that finds the machine!!!
  25. //
  26. // That pretty much suggests this would have to be TCPIP only
  27. // situation where you specify an IP address which would be
  28. // resolved in process before RPC'ing to the resolver -- otherwise
  29. // you're in an infinite loop.
  30. // Note, that doesn't mean the RPC protocol couldn't be named
  31. // pipes, only that the string sent in would have to be a TCPIP
  32. // string, so no name resolution had to take place.
  33. //
  34. LPWSTR NetworkAddress = NULL;
  35. handle_t
  36. DNS_RPC_HANDLE_bind(
  37. IN DNS_RPC_HANDLE Reserved
  38. )
  39. /*++
  40. Routine Description:
  41. This routine is called from the Workstation service client stubs when
  42. it is necessary create an RPC binding to the server end with
  43. identification level of impersonation.
  44. Arguments:
  45. Reserved - RPC string handle; will be NULL unless allow remote
  46. access to network name
  47. Return Value:
  48. The binding handle is returned to the stub routine. If the bind is
  49. unsuccessful, a NULL will be returned.
  50. --*/
  51. {
  52. LPWSTR binding = NULL;
  53. handle_t bindHandle = NULL;
  54. RPC_STATUS status = RPC_S_INVALID_NET_ADDR;
  55. //
  56. // default is LPC binding
  57. //
  58. if ( !Reserved )
  59. {
  60. status = RpcStringBindingComposeW(
  61. 0,
  62. L"ncalrpc",
  63. NULL,
  64. RESOLVER_RPC_LPC_ENDPOINT_W,
  65. NULL, // no security
  66. //L"Security=Impersonation Dynamic False",
  67. //L"Security=Impersonation Static True",
  68. &binding );
  69. }
  70. // LPC fails -- try named pipe
  71. if ( status != NO_ERROR )
  72. {
  73. DNSDBG( ANY, ( "Binding using named pipes\n" ));
  74. status = RpcStringBindingComposeW(
  75. 0,
  76. L"ncacn_np",
  77. (LPWSTR) NetworkAddress,
  78. RESOLVER_RPC_PIPE_NAME_W,
  79. NULL, // no security
  80. //L"Security=Impersonation Dynamic False",
  81. //L"Security=Impersonation Static True",
  82. &binding );
  83. }
  84. if ( status != RPC_S_OK )
  85. {
  86. return NULL;
  87. }
  88. status = RpcBindingFromStringBindingW( binding, &bindHandle );
  89. if ( status != RPC_S_OK )
  90. {
  91. bindHandle = NULL;
  92. }
  93. if ( binding )
  94. {
  95. RpcStringFreeW( &binding );
  96. }
  97. return bindHandle;
  98. }
  99. VOID
  100. DNS_RPC_HANDLE_unbind(
  101. IN DNS_RPC_HANDLE Reserved,
  102. IN OUT handle_t BindHandle
  103. )
  104. /*++
  105. Routine Description:
  106. This routine unbinds the identification generic handle.
  107. Arguments:
  108. Reserved - RPC string handle; will be NULL unless allow remote
  109. access to network name
  110. BindingHandle - This is the binding handle that is to be closed.
  111. Return Value:
  112. None.
  113. --*/
  114. {
  115. RpcBindingFree( &BindHandle );
  116. }
  117. //
  118. // RPC memory routines
  119. //
  120. // Use dnsapi memory routines.
  121. //
  122. PVOID
  123. WINAPI
  124. MIDL_user_allocate(
  125. IN size_t dwBytes
  126. )
  127. {
  128. // return( ALLOCATE_HEAP( dwBytes ) );
  129. return DnsApiAlloc( dwBytes );
  130. }
  131. VOID
  132. WINAPI
  133. MIDL_user_free(
  134. IN OUT PVOID pMem
  135. )
  136. {
  137. //FREE_HEAP( pMem );
  138. DnsApiFree( pMem );
  139. }
  140. //
  141. // End bind.c
  142. //