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.

198 lines
4.0 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. // - allow impersonation
  58. //
  59. status = RpcStringBindingComposeW(
  60. 0,
  61. L"ncalrpc",
  62. NULL,
  63. RESOLVER_RPC_LPC_ENDPOINT_W,
  64. L"Security=Impersonation Dynamic False",
  65. // NULL, // no security
  66. // L"Security=Impersonation Static True",
  67. &binding );
  68. #if 0
  69. // LPC fails -- try named pipe
  70. if ( status != NO_ERROR )
  71. {
  72. DNSDBG( ANY, ( "Binding using named pipes\n" ));
  73. status = RpcStringBindingComposeW(
  74. 0,
  75. L"ncacn_np",
  76. (LPWSTR) NetworkAddress,
  77. RESOLVER_RPC_PIPE_NAME_W,
  78. NULL, // no security
  79. //L"Security=Impersonation Dynamic False",
  80. //L"Security=Impersonation Static True",
  81. &binding );
  82. }
  83. #endif
  84. if ( status != RPC_S_OK )
  85. {
  86. return NULL;
  87. }
  88. status = RpcBindingFromStringBindingW(
  89. binding,
  90. &bindHandle );
  91. if ( status != RPC_S_OK )
  92. {
  93. bindHandle = NULL;
  94. }
  95. if ( binding )
  96. {
  97. RpcStringFreeW( &binding );
  98. }
  99. return bindHandle;
  100. }
  101. VOID
  102. DNS_RPC_HANDLE_unbind(
  103. IN DNS_RPC_HANDLE Reserved,
  104. IN OUT handle_t BindHandle
  105. )
  106. /*++
  107. Routine Description:
  108. This routine unbinds the identification generic handle.
  109. Arguments:
  110. Reserved - RPC string handle; will be NULL unless allow remote
  111. access to network name
  112. BindingHandle - This is the binding handle that is to be closed.
  113. Return Value:
  114. None.
  115. --*/
  116. {
  117. RpcBindingFree( &BindHandle );
  118. }
  119. //
  120. // RPC memory routines
  121. //
  122. // Use dnsapi memory routines.
  123. //
  124. PVOID
  125. WINAPI
  126. MIDL_user_allocate(
  127. IN size_t dwBytes
  128. )
  129. {
  130. // return( ALLOCATE_HEAP( dwBytes ) );
  131. return DnsApiAlloc( dwBytes );
  132. }
  133. VOID
  134. WINAPI
  135. MIDL_user_free(
  136. IN OUT PVOID pMem
  137. )
  138. {
  139. //FREE_HEAP( pMem );
  140. DnsApiFree( pMem );
  141. }
  142. //
  143. // End bind.c
  144. //