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.

514 lines
11 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. IN BOOL fLocal
  36. );
  37. DWORD APIENTRY
  38. RasRPCBind(
  39. IN LPWSTR lpwszServerName,
  40. OUT HANDLE* phServer,
  41. IN BOOL fLocal
  42. )
  43. {
  44. RPC_STATUS RpcStatus;
  45. LPWSTR lpwszStringBinding;
  46. LPWSTR pszServerPrincipalName = NULL;
  47. do
  48. {
  49. RpcStatus = RpcStringBindingCompose(
  50. NULL,
  51. TEXT("ncacn_np"),
  52. lpwszServerName,
  53. TEXT("\\PIPE\\ROUTER"),
  54. TEXT("Security=Impersonation Static True"),
  55. &lpwszStringBinding);
  56. if ( RpcStatus != RPC_S_OK )
  57. {
  58. break;;
  59. }
  60. RpcStatus = RpcBindingFromStringBinding(
  61. lpwszStringBinding,
  62. (handle_t *)phServer );
  63. RpcStringFree( &lpwszStringBinding );
  64. if ( RpcStatus != RPC_S_OK )
  65. {
  66. break;
  67. }
  68. if( RpcStatus != RPC_S_OK )
  69. {
  70. break;
  71. }
  72. //
  73. // register authentication information with rpc
  74. //
  75. if(fLocal)
  76. {
  77. //
  78. // Query Servers principal name
  79. //
  80. RpcStatus = RpcMgmtInqServerPrincName(
  81. *phServer,
  82. RPC_C_AUTHN_GSS_NEGOTIATE,
  83. &pszServerPrincipalName);
  84. RpcStatus = RPC_S_OK;
  85. RpcStatus = RpcBindingSetAuthInfoW(
  86. *phServer,
  87. pszServerPrincipalName,
  88. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  89. RPC_C_AUTHN_WINNT ,
  90. NULL,
  91. RPC_C_AUTHZ_NONE);
  92. }
  93. else
  94. {
  95. //
  96. // Query Servers principal name
  97. //
  98. RpcStatus = RpcMgmtInqServerPrincName(
  99. *phServer,
  100. RPC_C_AUTHN_GSS_NEGOTIATE,
  101. &pszServerPrincipalName);
  102. RpcStatus = RPC_S_OK;
  103. RpcStatus = RpcBindingSetAuthInfoW(
  104. *phServer,
  105. pszServerPrincipalName,
  106. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  107. RPC_C_AUTHN_GSS_NEGOTIATE,
  108. NULL,
  109. RPC_C_AUTHZ_NONE);
  110. }
  111. }
  112. while (FALSE);
  113. if(pszServerPrincipalName)
  114. {
  115. RpcStringFree(&pszServerPrincipalName);
  116. }
  117. if(RpcStatus != RPC_S_OK)
  118. {
  119. RpcBindingFree(*phServer);
  120. *phServer = NULL;
  121. return (I_RpcMapWin32Status(RpcStatus));
  122. }
  123. return( NO_ERROR );
  124. }
  125. DWORD APIENTRY
  126. RasRpcConnect(
  127. LPWSTR pwszServer,
  128. HANDLE* phServer
  129. )
  130. {
  131. DWORD retcode = 0;
  132. WCHAR *pszComputerName;
  133. WCHAR wszComputerName [ MAX_COMPUTERNAME_LENGTH + 1 ] = {0};
  134. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  135. BOOL fLocal = FALSE;
  136. if (0 == GetComputerName(wszComputerName, &dwSize))
  137. {
  138. return GetLastError();
  139. }
  140. if(NULL != pwszServer)
  141. {
  142. pszComputerName = pwszServer;
  143. //
  144. // convert \\MACHINENAME to MACHINENAME
  145. //
  146. if ( (wcslen(pszComputerName) > 2)
  147. && (pszComputerName [0] == TEXT('\\'))
  148. && (pszComputerName [1] == TEXT('\\')))
  149. {
  150. pszComputerName += 2;
  151. }
  152. if(0 == _wcsicmp(pszComputerName, wszComputerName))
  153. {
  154. fLocal = TRUE;
  155. }
  156. }
  157. else
  158. {
  159. pszComputerName = wszComputerName;
  160. fLocal = TRUE;
  161. }
  162. if( fLocal
  163. && (NULL != g_hBinding))
  164. {
  165. //
  166. // We are done - we already have a
  167. // binding.
  168. //
  169. *phServer = g_hBinding;
  170. goto done;
  171. }
  172. if( !fLocal &&
  173. (NULL == phServer))
  174. {
  175. retcode = E_INVALIDARG;
  176. goto done;
  177. }
  178. //
  179. // Bind with the server if we are not bound already.
  180. // By default we bind to the local server
  181. //
  182. RasmanOutputDebug ( "RASMAN: Binding to the server\n");
  183. retcode = RasRPCBind( pszComputerName ,
  184. fLocal ?
  185. &g_hBinding :
  186. phServer,
  187. fLocal) ;
  188. //
  189. // Set the bind handle for the caller if its local
  190. //
  191. if ( phServer && fLocal)
  192. *phServer = g_hBinding;
  193. done:
  194. return retcode;
  195. }
  196. DWORD APIENTRY
  197. RasRpcDisconnect(
  198. HANDLE* phServer
  199. )
  200. {
  201. //
  202. // Release the binding resources.
  203. //
  204. RasmanOutputDebug ("RASMAN: Disconnecting From Server\n");
  205. if(*phServer == g_hBinding)
  206. {
  207. g_hBinding = NULL;
  208. }
  209. (void)RpcBindingFree(phServer);
  210. return NO_ERROR;
  211. }
  212. DWORD APIENTRY
  213. RemoteSubmitRequest ( HANDLE hConnection,
  214. PBYTE pBuffer,
  215. DWORD dwSizeOfBuffer )
  216. {
  217. DWORD dwStatus = ERROR_SUCCESS;
  218. RPC_BINDING_HANDLE hServer;
  219. //
  220. // NULL hConnection means the request is
  221. // for a local server. Better have a
  222. // hBinding with us in the global in this
  223. // case.
  224. //
  225. if(NULL == hConnection)
  226. {
  227. ASSERT(NULL != g_hBinding);
  228. hServer = g_hBinding;
  229. }
  230. else
  231. {
  232. ASSERT(NULL != ((RAS_RPC *)hConnection)->hRpcBinding);
  233. hServer = ((RAS_RPC *) hConnection)->hRpcBinding;
  234. }
  235. RpcTryExcept
  236. {
  237. dwStatus = RasRpcSubmitRequest( hServer,
  238. pBuffer,
  239. dwSizeOfBuffer );
  240. }
  241. RpcExcept(I_RpcExceptionFilter(dwStatus = RpcExceptionCode()))
  242. {
  243. }
  244. RpcEndExcept
  245. return dwStatus;
  246. }
  247. #if 0
  248. DWORD APIENTRY
  249. RasRpcLoadDll(LPTSTR lpszServer)
  250. {
  251. return LoadRasRpcDll(lpszServer);
  252. }
  253. #endif
  254. DWORD APIENTRY
  255. RasRpcConnectServer(LPTSTR lpszServer,
  256. HANDLE *pHConnection)
  257. {
  258. return InitializeConnection(lpszServer,
  259. pHConnection);
  260. }
  261. DWORD APIENTRY
  262. RasRpcDisconnectServer(HANDLE hConnection)
  263. {
  264. UninitializeConnection(hConnection);
  265. return NO_ERROR;
  266. }
  267. DWORD
  268. RasRpcUnloadDll()
  269. {
  270. return UnloadRasRpcDll();
  271. }
  272. UINT APIENTRY
  273. RasRpcRemoteGetSystemDirectory(
  274. HANDLE hConnection,
  275. LPTSTR lpBuffer,
  276. UINT uSize
  277. )
  278. {
  279. return g_pGetSystemDirectory(
  280. hConnection,
  281. lpBuffer,
  282. uSize);
  283. }
  284. DWORD APIENTRY
  285. RasRpcRemoteRasDeleteEntry(
  286. HANDLE hConnection,
  287. LPTSTR lpszPhonebook,
  288. LPTSTR lpszEntry
  289. )
  290. {
  291. DWORD dwError = ERROR_SUCCESS;
  292. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  293. if(NULL == hConnection)
  294. {
  295. dwError = g_pRasDeleteEntry(lpszPhonebook,
  296. lpszEntry);
  297. }
  298. else
  299. {
  300. //
  301. // Remote server case
  302. //
  303. dwError = RemoteRasDeleteEntry(hConnection,
  304. lpszPhonebook,
  305. lpszEntry);
  306. }
  307. return dwError;
  308. }
  309. DWORD APIENTRY
  310. RasRpcRemoteGetUserPreferences(
  311. HANDLE hConnection,
  312. PBUSER * pPBUser,
  313. DWORD dwMode
  314. )
  315. {
  316. return g_pGetUserPreferences(hConnection,
  317. pPBUser,
  318. dwMode);
  319. }
  320. DWORD APIENTRY
  321. RasRpcRemoteSetUserPreferences(
  322. HANDLE hConnection,
  323. PBUSER * pPBUser,
  324. DWORD dwMode
  325. )
  326. {
  327. return g_pSetUserPreferences(hConnection,
  328. pPBUser,
  329. dwMode);
  330. }
  331. /*
  332. DWORD APIENTRY
  333. RemoteRasDeviceEnum(
  334. PCHAR pszDeviceType,
  335. PBYTE lpDevices,
  336. PWORD pwcbDevices,
  337. PWORD pwcDevices
  338. )
  339. {
  340. DWORD dwStatus;
  341. ASSERT(g_hBinding);
  342. RpcTryExcept
  343. {
  344. dwStatus = RasRpcDeviceEnum(g_hBinding,
  345. pszDeviceType,
  346. lpDevices,
  347. pwcbDevices,
  348. pwcDevices);
  349. }
  350. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  351. {
  352. dwStatus = RpcExceptionCode();
  353. }
  354. RpcEndExcept
  355. return dwStatus;
  356. }
  357. DWORD APIENTRY
  358. RemoteRasGetDevConfig(
  359. HPORT hport,
  360. PCHAR pszDeviceType,
  361. PBYTE lpConfig,
  362. LPDWORD lpcbConfig
  363. )
  364. {
  365. DWORD dwStatus;
  366. ASSERT(g_hBinding);
  367. RpcTryExcept
  368. {
  369. dwStatus = RasRpcGetDevConfig(g_hBinding,
  370. hport,
  371. pszDeviceType,
  372. lpConfig,
  373. lpcbConfig);
  374. }
  375. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  376. {
  377. dwStatus = RpcExceptionCode();
  378. }
  379. RpcEndExcept
  380. return dwStatus;
  381. }
  382. DWORD APIENTRY
  383. RemoteRasPortEnum(
  384. PBYTE lpPorts,
  385. PWORD pwcbPorts,
  386. PWORD pwcPorts
  387. )
  388. {
  389. DWORD dwStatus;
  390. ASSERT(g_hBinding);
  391. RpcTryExcept
  392. {
  393. dwStatus = RasRpcPortEnum(g_hBinding,
  394. lpPorts,
  395. pwcbPorts,
  396. pwcPorts);
  397. }
  398. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  399. {
  400. dwStatus = RpcExceptionCode();
  401. }
  402. RpcEndExcept
  403. return dwStatus;
  404. }
  405. DWORD
  406. RemoteRasPortGetInfo(
  407. HPORT porthandle,
  408. PBYTE buffer,
  409. PWORD pSize)
  410. {
  411. DWORD dwStatus;
  412. RpcTryExcept
  413. {
  414. dwStatus = RasRpcPortGetInfo(g_hBinding,
  415. porthandle,
  416. buffer,
  417. pSize);
  418. }
  419. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  420. {
  421. dwStatus = RpcExceptionCode();
  422. }
  423. RpcEndExcept
  424. return dwStatus;
  425. } */