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.

385 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. dhcbind.c
  5. Abstract:
  6. Routines which use RPC to bind and unbind the client to the
  7. WINS server service.
  8. Author:
  9. Pradeep Bahl (pradeepb) April-1993
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. --*/
  14. #include "wins.h"
  15. #include "winsif.h"
  16. handle_t
  17. WinsCommonBind(
  18. PWINSINTF_BIND_DATA_T pBindData
  19. )
  20. /*++
  21. Routine Description:
  22. This routine is called from the WINS server service client stubs when
  23. it is necessary create an RPC binding to the server end.
  24. Arguments:
  25. ServerIpAddress - The IP address of the server to bind to.
  26. Return Value:
  27. The binding handle is returned to the stub routine. If the bind is
  28. unsuccessful, a NULL will be returned.
  29. --*/
  30. {
  31. RPC_STATUS rpcStatus;
  32. LPTSTR binding;
  33. LPTSTR pProtSeq;
  34. LPTSTR pOptions = (TCHAR *)NULL;
  35. LPTSTR pServerAdd = (LPTSTR)pBindData->pServerAdd;
  36. handle_t bhandle;
  37. if (pBindData->fTcpIp)
  38. {
  39. if (lstrcmp((LPCTSTR)pBindData->pServerAdd, TEXT("127.0.0.1")) == 0)
  40. {
  41. pProtSeq = TEXT("ncalrpc");
  42. pOptions = TEXT("Security=Impersonation Dynamic False");
  43. pServerAdd = (TCHAR *)NULL;
  44. }
  45. else
  46. {
  47. pProtSeq = TEXT("ncacn_ip_tcp");
  48. pServerAdd = (LPTSTR)pBindData->pServerAdd;
  49. }
  50. pBindData->pPipeName = NULL;
  51. }
  52. else
  53. {
  54. pProtSeq = TEXT("ncacn_np");
  55. }
  56. //
  57. // Enter the critical section. This will be freed WINSIF_HANDLE_unbind().
  58. //
  59. //EnterCriticalSection(&WinsRpcCrtSec);
  60. rpcStatus = RpcStringBindingCompose(
  61. 0,
  62. pProtSeq,
  63. pServerAdd,
  64. pBindData->fTcpIp ? TEXT("") : (LPWSTR)pBindData->pPipeName,
  65. pOptions,
  66. &binding);
  67. if ( rpcStatus != RPC_S_OK )
  68. {
  69. return( NULL );
  70. }
  71. rpcStatus = RpcBindingFromStringBinding( binding, &bhandle );
  72. RpcStringFree(&binding);
  73. if ( rpcStatus != RPC_S_OK )
  74. {
  75. return( NULL );
  76. }
  77. #if SECURITY > 0
  78. rpcStatus = RpcBindingSetAuthInfo(
  79. bhandle,
  80. WINS_SERVER,
  81. RPC_C_AUTHN_LEVEL_CONNECT,
  82. RPC_C_AUTHN_WINNT,
  83. NULL,
  84. RPC_C_AUTHZ_NAME
  85. );
  86. if ( rpcStatus != RPC_S_OK )
  87. {
  88. return( NULL );
  89. }
  90. #endif
  91. return bhandle;
  92. }
  93. handle_t
  94. WinsABind(
  95. PWINSINTF_BIND_DATA_T pBindData
  96. )
  97. {
  98. WCHAR WcharString1[WINSINTF_MAX_NAME_SIZE];
  99. WCHAR WcharString2[WINSINTF_MAX_NAME_SIZE];
  100. DWORD NoOfChars;
  101. WINSINTF_BIND_DATA_T BindData;
  102. if (pBindData->pServerAdd != NULL)
  103. {
  104. NoOfChars = MultiByteToWideChar(CP_ACP, 0, pBindData->pServerAdd, -1,
  105. WcharString1, WINSINTF_MAX_NAME_SIZE);
  106. if (NoOfChars > 0)
  107. {
  108. BindData.pServerAdd = (LPSTR)WcharString1;
  109. }
  110. }
  111. else
  112. {
  113. BindData.pServerAdd = (LPSTR)((TCHAR *)NULL);
  114. }
  115. if (!pBindData->fTcpIp)
  116. {
  117. BindData.fTcpIp = 0;
  118. NoOfChars = MultiByteToWideChar(CP_ACP, 0,
  119. pBindData->pPipeName, -1,
  120. WcharString2, WINSINTF_MAX_NAME_SIZE);
  121. if (NoOfChars > 0)
  122. {
  123. BindData.pPipeName = (LPSTR)WcharString2;
  124. }
  125. }
  126. else
  127. {
  128. BindData.fTcpIp = 1;
  129. }
  130. return(WinsCommonBind(&BindData));
  131. }
  132. handle_t
  133. WinsUBind(
  134. PWINSINTF_BIND_DATA_T pBindData
  135. )
  136. {
  137. return(WinsCommonBind(pBindData));
  138. }
  139. VOID
  140. WinsUnbind(
  141. PWINSINTF_BIND_DATA_T pBindData,
  142. handle_t BindHandle
  143. )
  144. {
  145. (VOID)RpcBindingFree(&BindHandle);
  146. return;
  147. }
  148. handle_t
  149. WINSIF_HANDLE_bind(
  150. WINSIF_HANDLE ServerHdl
  151. )
  152. /*++
  153. Routine Description:
  154. This routine is called from the WINS server service client stubs when
  155. it is necessary create an RPC binding to the server end.
  156. Arguments:
  157. ServerIpAddress - The IP address of the server to bind to.
  158. Return Value:
  159. The binding handle is returned to the stub routine. If the bind is
  160. unsuccessful, a NULL will be returned.
  161. --*/
  162. {
  163. return WinsCommonBind( ServerHdl );
  164. }
  165. void
  166. WINSIF_HANDLE_unbind(
  167. WINSIF_HANDLE ServerHdl,
  168. handle_t BindHandle
  169. )
  170. /*++
  171. Routine Description:
  172. This routine is called from the DHCP server service client stubs
  173. when it is necessary to unbind from the server end.
  174. Arguments:
  175. ServerIpAddress - This is the IP address of the server from which to unbind.
  176. BindingHandle - This is the binding handle that is to be closed.
  177. Return Value:
  178. None.
  179. --*/
  180. {
  181. WinsUnbind( ServerHdl, BindHandle );
  182. }
  183. handle_t
  184. WINSIF2_HANDLE_bind(
  185. WINSIF2_HANDLE ServerHdl
  186. )
  187. /*++
  188. Routine Description:
  189. This routine is called from the WINS server service client stubs when
  190. it is necessary create an RPC binding to the server end.
  191. Arguments:
  192. ServerIpAddress - The IP address of the server to bind to.
  193. Return Value:
  194. The binding handle is returned to the stub routine. If the bind is
  195. unsuccessful, a NULL will be returned.
  196. --*/
  197. {
  198. return ((handle_t)ServerHdl);
  199. }
  200. void
  201. WINSIF2_HANDLE_unbind(
  202. WINSIF2_HANDLE ServerHdl,
  203. handle_t BindHandle
  204. )
  205. /*++
  206. Routine Description:
  207. This routine is called from the DHCP server service client stubs
  208. when it is necessary to unbind from the server end.
  209. Arguments:
  210. ServerIpAddress - This is the IP address of the server from which to unbind.
  211. BindingHandle - This is the binding handle that is to be closed.
  212. Return Value:
  213. None.
  214. --*/
  215. {
  216. UNREFERENCED_PARAMETER( ServerHdl );
  217. UNREFERENCED_PARAMETER( BindHandle );
  218. return;
  219. }
  220. //void __RPC_FAR * __RPC_API
  221. LPVOID
  222. midl_user_allocate(size_t cBytes)
  223. {
  224. LPVOID pMem;
  225. pMem = (LPVOID)LocalAlloc(LMEM_FIXED, cBytes);
  226. return(pMem);
  227. }
  228. //void __RPC_API
  229. VOID
  230. //midl_user_free(void __RPC_FAR *pMem)
  231. midl_user_free(void *pMem)
  232. {
  233. if (pMem != NULL)
  234. {
  235. LocalFree((HLOCAL)pMem);
  236. }
  237. return;
  238. }
  239. LPVOID
  240. WinsAllocMem(size_t cBytes)
  241. {
  242. return(midl_user_allocate(cBytes));
  243. }
  244. VOID
  245. WinsFreeMem(LPVOID pMem)
  246. {
  247. midl_user_free(pMem);
  248. }
  249. DWORD
  250. WinsGetBrowserNames_Old(
  251. WINSIF2_HANDLE ServerHdl,
  252. PWINSINTF_BROWSER_NAMES_T pNames
  253. )
  254. {
  255. DWORD status;
  256. RpcTryExcept {
  257. status = R_WinsGetBrowserNames_Old(
  258. ServerHdl,
  259. pNames
  260. );
  261. } RpcExcept( I_RpcExceptionFilter(RpcExceptionCode()) ) {
  262. status = RpcExceptionCode();
  263. } RpcEndExcept
  264. return status;
  265. }
  266. DWORD
  267. WinsGetBrowserNames(
  268. WINSIF_HANDLE ServerHdl,
  269. PWINSINTF_BROWSER_NAMES_T pNames
  270. )
  271. {
  272. DWORD status;
  273. RpcTryExcept {
  274. status = R_WinsGetBrowserNames(
  275. ServerHdl,
  276. pNames
  277. );
  278. } RpcExcept( I_RpcExceptionFilter(RpcExceptionCode()) ) {
  279. status = RpcExceptionCode();
  280. } RpcEndExcept
  281. return status;
  282. }