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.

414 lines
7.9 KiB

  1. /*++
  2. Copyright(c) 1996 Microsoft Corporation
  3. MODULE NAME
  4. dll.c
  5. ABSTRACT
  6. DLL initialization code
  7. AUTHOR
  8. Anthony Discolo (adiscolo) 12-Sep-1996
  9. REVISION HISTORY
  10. --*/
  11. #ifndef UNICODE
  12. #define UNICODE
  13. #endif
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <rpc.h>
  22. #include "rasrpc.h"
  23. #include <nouiutil.h>
  24. #include "loaddlls.h"
  25. #include "media.h"
  26. #include "wanpub.h"
  27. #include "defs.h"
  28. #include "structs.h"
  29. #include "protos.h"
  30. RPC_BINDING_HANDLE g_hBinding = NULL;
  31. DWORD
  32. RasRPCBind(
  33. IN LPWSTR lpwsServerName,
  34. OUT HANDLE* phServer
  35. );
  36. DWORD APIENTRY
  37. RasRPCBind(
  38. IN LPWSTR lpwszServerName,
  39. OUT HANDLE* phServer
  40. )
  41. {
  42. RPC_STATUS RpcStatus;
  43. LPWSTR lpwszStringBinding;
  44. RpcStatus = RpcStringBindingCompose(
  45. NULL,
  46. TEXT("ncacn_np"),
  47. lpwszServerName,
  48. TEXT("\\PIPE\\ROUTER"),
  49. TEXT("Security=Impersonation Static True"),
  50. &lpwszStringBinding);
  51. if ( RpcStatus != RPC_S_OK )
  52. {
  53. return( I_RpcMapWin32Status( RpcStatus ) );
  54. }
  55. RpcStatus = RpcBindingFromStringBinding(
  56. lpwszStringBinding,
  57. (handle_t *)phServer );
  58. RpcStringFree( &lpwszStringBinding );
  59. if ( RpcStatus != RPC_S_OK )
  60. {
  61. return( I_RpcMapWin32Status( RpcStatus ) );
  62. }
  63. return( NO_ERROR );
  64. }
  65. DWORD APIENTRY
  66. RasRpcConnect(
  67. LPWSTR lpwszServer,
  68. HANDLE* phServer
  69. )
  70. {
  71. DWORD retcode = 0;
  72. TCHAR *pszComputerName;
  73. WCHAR wszComputerName [ MAX_COMPUTERNAME_LENGTH + 1 ] = {0};
  74. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  75. if ( lpwszServer == NULL
  76. && g_hBinding == NULL)
  77. {
  78. pszComputerName = wszComputerName;
  79. //
  80. // By default connect to the local server
  81. //
  82. if ( 0 == GetComputerName ( wszComputerName, &dwSize ) )
  83. {
  84. return GetLastError();
  85. }
  86. //
  87. // convert \\MACHINENAME to MACHINENAME
  88. //
  89. if ( wszComputerName [0] == TEXT('\\')
  90. && wszComputerName [1] == TEXT('\\' ))
  91. pszComputerName += 2;
  92. }
  93. //
  94. // Bind with the server if we are not bound already.
  95. // By default we bind to the local server
  96. //
  97. if ( lpwszServer != NULL
  98. || g_hBinding == NULL )
  99. {
  100. RasmanOutputDebug ( "RASMAN: Binding to the server\n");
  101. retcode = RasRPCBind( ( lpwszServer
  102. ? lpwszServer
  103. : wszComputerName ) ,
  104. &g_hBinding ) ;
  105. }
  106. //
  107. // Set the bind handle for the caller
  108. //
  109. if ( phServer )
  110. *phServer = g_hBinding;
  111. return retcode;
  112. }
  113. DWORD APIENTRY
  114. RasRpcDisconnect(
  115. HANDLE* phServer
  116. )
  117. {
  118. //
  119. // Release the binding resources.
  120. //
  121. RasmanOutputDebug ("RASMAN: Disconnecting From Server\n");
  122. (void)RpcBindingFree(phServer);
  123. g_hBinding = NULL;
  124. return NO_ERROR;
  125. }
  126. DWORD APIENTRY
  127. RemoteSubmitRequest ( HANDLE hConnection,
  128. PBYTE pBuffer,
  129. DWORD dwSizeOfBuffer )
  130. {
  131. DWORD dwStatus = ERROR_SUCCESS;
  132. RPC_BINDING_HANDLE hServer;
  133. //
  134. // NULL hConnection means the request is
  135. // for a local server. Better have a
  136. // hBinding with us in the global in this
  137. // case.
  138. //
  139. if(NULL == hConnection)
  140. {
  141. ASSERT(NULL != g_hBinding);
  142. hServer = g_hBinding;
  143. }
  144. else
  145. {
  146. ASSERT(NULL != ((RAS_RPC *)hConnection)->hRpcBinding);
  147. hServer = ((RAS_RPC *) hConnection)->hRpcBinding;
  148. }
  149. RpcTryExcept
  150. {
  151. dwStatus = RasRpcSubmitRequest( hServer,
  152. pBuffer,
  153. dwSizeOfBuffer );
  154. }
  155. RpcExcept(I_RpcExceptionFilter(dwStatus = RpcExceptionCode()))
  156. {
  157. }
  158. RpcEndExcept
  159. return dwStatus;
  160. }
  161. #if 0
  162. DWORD APIENTRY
  163. RasRpcLoadDll(LPTSTR lpszServer)
  164. {
  165. return LoadRasRpcDll(lpszServer);
  166. }
  167. #endif
  168. DWORD APIENTRY
  169. RasRpcConnectServer(LPTSTR lpszServer,
  170. HANDLE *pHConnection)
  171. {
  172. return InitializeConnection(lpszServer,
  173. pHConnection);
  174. }
  175. DWORD APIENTRY
  176. RasRpcDisconnectServer(HANDLE hConnection)
  177. {
  178. UninitializeConnection(hConnection);
  179. return NO_ERROR;
  180. }
  181. DWORD
  182. RasRpcUnloadDll()
  183. {
  184. return UnloadRasRpcDll();
  185. }
  186. UINT APIENTRY
  187. RasRpcRemoteGetSystemDirectory(
  188. HANDLE hConnection,
  189. LPTSTR lpBuffer,
  190. UINT uSize
  191. )
  192. {
  193. return g_pGetSystemDirectory(
  194. hConnection,
  195. lpBuffer,
  196. uSize);
  197. }
  198. DWORD APIENTRY
  199. RasRpcRemoteRasDeleteEntry(
  200. HANDLE hConnection,
  201. LPTSTR lpszPhonebook,
  202. LPTSTR lpszEntry
  203. )
  204. {
  205. DWORD dwError = ERROR_SUCCESS;
  206. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  207. if(NULL == hConnection)
  208. {
  209. dwError = g_pRasDeleteEntry(lpszPhonebook,
  210. lpszEntry);
  211. }
  212. else
  213. {
  214. //
  215. // Remote server case
  216. //
  217. dwError = RemoteRasDeleteEntry(hConnection,
  218. lpszPhonebook,
  219. lpszEntry);
  220. }
  221. return dwError;
  222. }
  223. DWORD APIENTRY
  224. RasRpcRemoteGetUserPreferences(
  225. HANDLE hConnection,
  226. PBUSER * pPBUser,
  227. DWORD dwMode
  228. )
  229. {
  230. return g_pGetUserPreferences(hConnection,
  231. pPBUser,
  232. dwMode);
  233. }
  234. DWORD APIENTRY
  235. RasRpcRemoteSetUserPreferences(
  236. HANDLE hConnection,
  237. PBUSER * pPBUser,
  238. DWORD dwMode
  239. )
  240. {
  241. return g_pSetUserPreferences(hConnection,
  242. pPBUser,
  243. dwMode);
  244. }
  245. /*
  246. DWORD APIENTRY
  247. RemoteRasDeviceEnum(
  248. PCHAR pszDeviceType,
  249. PBYTE lpDevices,
  250. PWORD pwcbDevices,
  251. PWORD pwcDevices
  252. )
  253. {
  254. DWORD dwStatus;
  255. ASSERT(g_hBinding);
  256. RpcTryExcept
  257. {
  258. dwStatus = RasRpcDeviceEnum(g_hBinding,
  259. pszDeviceType,
  260. lpDevices,
  261. pwcbDevices,
  262. pwcDevices);
  263. }
  264. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  265. {
  266. dwStatus = RpcExceptionCode();
  267. }
  268. RpcEndExcept
  269. return dwStatus;
  270. }
  271. DWORD APIENTRY
  272. RemoteRasGetDevConfig(
  273. HPORT hport,
  274. PCHAR pszDeviceType,
  275. PBYTE lpConfig,
  276. LPDWORD lpcbConfig
  277. )
  278. {
  279. DWORD dwStatus;
  280. ASSERT(g_hBinding);
  281. RpcTryExcept
  282. {
  283. dwStatus = RasRpcGetDevConfig(g_hBinding,
  284. hport,
  285. pszDeviceType,
  286. lpConfig,
  287. lpcbConfig);
  288. }
  289. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  290. {
  291. dwStatus = RpcExceptionCode();
  292. }
  293. RpcEndExcept
  294. return dwStatus;
  295. }
  296. DWORD APIENTRY
  297. RemoteRasPortEnum(
  298. PBYTE lpPorts,
  299. PWORD pwcbPorts,
  300. PWORD pwcPorts
  301. )
  302. {
  303. DWORD dwStatus;
  304. ASSERT(g_hBinding);
  305. RpcTryExcept
  306. {
  307. dwStatus = RasRpcPortEnum(g_hBinding,
  308. lpPorts,
  309. pwcbPorts,
  310. pwcPorts);
  311. }
  312. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  313. {
  314. dwStatus = RpcExceptionCode();
  315. }
  316. RpcEndExcept
  317. return dwStatus;
  318. }
  319. DWORD
  320. RemoteRasPortGetInfo(
  321. HPORT porthandle,
  322. PBYTE buffer,
  323. PWORD pSize)
  324. {
  325. DWORD dwStatus;
  326. RpcTryExcept
  327. {
  328. dwStatus = RasRpcPortGetInfo(g_hBinding,
  329. porthandle,
  330. buffer,
  331. pSize);
  332. }
  333. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  334. {
  335. dwStatus = RpcExceptionCode();
  336. }
  337. RpcEndExcept
  338. return dwStatus;
  339. } */