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.

473 lines
15 KiB

  1. /*++
  2. Copyright(c) 1995 Microsoft Corporation
  3. MODULE NAME
  4. rasrpclb.c
  5. ABSTRACT
  6. rasrpc client/server common routines
  7. AUTHOR
  8. Anthony Discolo (adiscolo) 28-Jul-1995
  9. REVISION HISTORY
  10. --*/
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <rpc.h>
  19. #include "rasrpc.h"
  20. #include <ras.h>
  21. #include <rasman.h>
  22. #include <raserror.h>
  23. #include <mprapi.h>
  24. #include <nouiutil.h>
  25. #include <dtl.h>
  26. #include <debug.h>
  27. //
  28. // Handle NULL string parameters
  29. // to the TRACE macro.
  30. //
  31. #define TRACESTR(s) (s) != NULL ? (s) : TEXT("")
  32. DWORD
  33. CallbackListToRpc(
  34. OUT LPRASRPC_CALLBACKLIST *pCallbacks,
  35. IN DTLLIST *pdtllistCallbacks
  36. )
  37. {
  38. DTLNODE *pdtlnode;
  39. LPRASRPC_CALLBACKLIST pNewCallback, pTail = NULL;
  40. CALLBACKINFO *pCallback;
  41. TRACE("CallbackListToRpc: begin");
  42. *pCallbacks = NULL;
  43. for (pdtlnode = DtlGetFirstNode(pdtllistCallbacks);
  44. pdtlnode != NULL;
  45. pdtlnode = DtlGetNextNode(pdtlnode))
  46. {
  47. pCallback = (CALLBACKINFO *)DtlGetData(pdtlnode);
  48. //
  49. // Allocate and initialize
  50. // the new structure.
  51. //
  52. pNewCallback = MIDL_user_allocate(sizeof (RASRPC_CALLBACKLIST));
  53. if (pNewCallback == NULL)
  54. return GetLastError();
  55. if (pCallback->pszPortName != NULL)
  56. lstrcpyn(pNewCallback->pszPortName, pCallback->pszPortName, 17);
  57. else
  58. *pNewCallback->pszPortName = TEXT('\0');
  59. if (pCallback->pszDeviceName != NULL)
  60. lstrcpyn(pNewCallback->pszDeviceName, pCallback->pszDeviceName, 129);
  61. else
  62. *pNewCallback->pszDeviceName = TEXT('\0');
  63. if (pCallback->pszNumber != NULL)
  64. lstrcpyn(pNewCallback->pszNumber, pCallback->pszNumber, 129);
  65. else
  66. *pNewCallback->pszNumber = TEXT('\0');
  67. pNewCallback->dwDeviceType = pCallback->dwDeviceType;
  68. TRACE2("CallbackListToRpc: new node: %S, %S", pCallback->pszPortName, pCallback->pszDeviceName);
  69. pNewCallback->pNext = NULL;
  70. //
  71. // Insert it at the tail of the list.
  72. //
  73. if (*pCallbacks == NULL)
  74. *pCallbacks = pTail = pNewCallback;
  75. else {
  76. pTail->pNext = pNewCallback;
  77. pTail = pNewCallback;
  78. }
  79. }
  80. TRACE("CallbackListToRpc: end");
  81. return 0;
  82. }
  83. DWORD
  84. CallbackListFromRpc(
  85. OUT DTLLIST **pdtllistCallbacks,
  86. IN LPRASRPC_CALLBACKLIST pCallbacks
  87. )
  88. {
  89. LPRASRPC_CALLBACKLIST pCallback;
  90. DTLNODE *pdtlnode;
  91. TRACE("CallbackListFromRpc: begin");
  92. //
  93. // Initialize the new list.
  94. //
  95. *pdtllistCallbacks = DtlCreateList(0);
  96. if (*pdtllistCallbacks == NULL)
  97. return GetLastError();
  98. for (pCallback = pCallbacks; pCallback != NULL; pCallback = pCallback->pNext)
  99. {
  100. pdtlnode = CreateCallbackNode(pCallback->pszPortName, pCallback->pszDeviceName, pCallback->pszNumber, pCallback->dwDeviceType);
  101. if (pdtlnode == NULL)
  102. return GetLastError();
  103. TRACE2("CallbackListToRpc: new node: %S, %S", pCallback->pszPortName, pCallback->pszDeviceName);
  104. DtlAddNodeLast(*pdtllistCallbacks, pdtlnode);
  105. }
  106. TRACE("CallbackListFromRpc: end");
  107. return 0;
  108. }
  109. DWORD
  110. StringListToRpc(
  111. OUT LPRASRPC_STRINGLIST *pStrings,
  112. IN DTLLIST *pdtllistStrings
  113. )
  114. {
  115. DTLNODE *pdtlnode;
  116. LPRASRPC_STRINGLIST pNewString, pTail = NULL;
  117. PWCHAR psz;
  118. TRACE("StringListToRpc: begin");
  119. *pStrings = NULL;
  120. for (pdtlnode = DtlGetFirstNode(pdtllistStrings);
  121. pdtlnode != NULL;
  122. pdtlnode = DtlGetNextNode(pdtlnode))
  123. {
  124. psz = (PWCHAR)DtlGetData(pdtlnode);
  125. //
  126. // Allocate and initialize
  127. // the new structure.
  128. //
  129. pNewString = MIDL_user_allocate(sizeof (RASRPC_STRINGLIST));
  130. if (pNewString == NULL)
  131. return GetLastError();
  132. if (psz != NULL)
  133. lstrcpyn(pNewString->psz, psz, 256);
  134. else
  135. *pNewString->psz = TEXT('\0');
  136. pNewString->pNext = NULL;
  137. TRACE1("StringListToRpc: new node: %S", psz);
  138. //
  139. // Insert it at the tail of the list.
  140. //
  141. if (*pStrings == NULL)
  142. *pStrings = pTail = pNewString;
  143. else {
  144. pTail->pNext = pNewString;
  145. pTail = pNewString;
  146. }
  147. }
  148. TRACE("StringListToRpc: end");
  149. return 0;
  150. }
  151. DWORD
  152. StringListFromRpc(
  153. OUT DTLLIST **pdtllistStrings,
  154. IN LPRASRPC_STRINGLIST pStrings
  155. )
  156. {
  157. LPRASRPC_STRINGLIST pString;
  158. DTLNODE *pdtlnode;
  159. //
  160. // Initialize the new list.
  161. //
  162. TRACE("StringListFromRpc: begin");
  163. *pdtllistStrings = DtlCreateList(0);
  164. if (*pdtllistStrings == NULL)
  165. return GetLastError();
  166. for (pString = pStrings; pString != NULL; pString = pString->pNext)
  167. {
  168. pdtlnode = CreatePszNode(pString->psz);
  169. if (pdtlnode == NULL)
  170. return GetLastError();
  171. TRACE1("StringListToRpc: new node: %S", pString->psz);
  172. DtlAddNodeLast(*pdtllistStrings, pdtlnode);
  173. }
  174. TRACE("StringListFromRpc: end");
  175. return 0;
  176. }
  177. DWORD
  178. LocationListToRpc(
  179. OUT LPRASRPC_LOCATIONLIST *pLocations,
  180. IN DTLLIST *pdtllistLocations
  181. )
  182. {
  183. DTLNODE *pdtlnode;
  184. LPRASRPC_LOCATIONLIST pNewLocation, pTail = NULL;
  185. LOCATIONINFO *pLocation;
  186. TRACE("LocationListToRpc: begin");
  187. *pLocations = NULL;
  188. for (pdtlnode = DtlGetFirstNode(pdtllistLocations);
  189. pdtlnode != NULL;
  190. pdtlnode = DtlGetNextNode(pdtlnode))
  191. {
  192. pLocation = (LOCATIONINFO *)DtlGetData(pdtlnode);
  193. //
  194. // Allocate and initialize
  195. // the new structure.
  196. //
  197. pNewLocation = MIDL_user_allocate(sizeof (RASRPC_LOCATIONLIST));
  198. if (pNewLocation == NULL)
  199. return GetLastError();
  200. pNewLocation->dwLocationId = pLocation->dwLocationId;
  201. pNewLocation->iPrefix = pLocation->iPrefix;
  202. pNewLocation->iSuffix = pLocation->iSuffix;
  203. pNewLocation->pNext = NULL;
  204. TRACE3("LocationListToRpc: new node: %d, %d, %d", pLocation->dwLocationId, pLocation->iPrefix, pLocation->iSuffix);
  205. //
  206. // Insert it at the tail of the list.
  207. //
  208. if (*pLocations == NULL)
  209. *pLocations = pTail = pNewLocation;
  210. else {
  211. pTail->pNext = pNewLocation;
  212. pTail = pNewLocation;
  213. }
  214. }
  215. TRACE("LocationListToRpc: end");
  216. return 0;
  217. }
  218. DWORD
  219. LocationListFromRpc(
  220. OUT DTLLIST **pdtllistLocations,
  221. IN LPRASRPC_LOCATIONLIST pLocations
  222. )
  223. {
  224. LPRASRPC_LOCATIONLIST pLocation;
  225. DTLNODE *pdtlnode;
  226. //
  227. // Initialize the new list.
  228. //
  229. TRACE("LocationListFromRpc: begin");
  230. *pdtllistLocations = DtlCreateList(0);
  231. if (*pdtllistLocations == NULL)
  232. return GetLastError();
  233. for (pLocation = pLocations; pLocation != NULL; pLocation = pLocation->pNext)
  234. {
  235. pdtlnode = CreateLocationNode(pLocation->dwLocationId, pLocation->iPrefix, pLocation->iSuffix);
  236. if (pdtlnode == NULL)
  237. return GetLastError();
  238. TRACE3("LocationListFromRpc: new node: %d, %d, %d", pLocation->dwLocationId, pLocation->iPrefix, pLocation->iSuffix);
  239. DtlAddNodeLast(*pdtllistLocations, pdtlnode);
  240. }
  241. TRACE("LocationListFromRpc: end");
  242. return 0;
  243. }
  244. DWORD
  245. RasToRpcPbuser(
  246. LPRASRPC_PBUSER pUser,
  247. PBUSER *pPbuser
  248. )
  249. {
  250. DWORD dwErr;
  251. TRACE("RasToRpcPbUser: begin");
  252. pUser->fOperatorDial = pPbuser->fOperatorDial;
  253. pUser->fPreviewPhoneNumber = pPbuser->fPreviewPhoneNumber;
  254. pUser->fUseLocation = pPbuser->fUseLocation;
  255. pUser->fShowLights = pPbuser->fShowLights;
  256. pUser->fShowConnectStatus = pPbuser->fShowConnectStatus;
  257. pUser->fCloseOnDial = pPbuser->fCloseOnDial;
  258. pUser->fAllowLogonPhonebookEdits = pPbuser->fAllowLogonPhonebookEdits;
  259. pUser->fAllowLogonLocationEdits = pPbuser->fAllowLogonLocationEdits;
  260. pUser->fSkipConnectComplete = pPbuser->fSkipConnectComplete;
  261. pUser->fNewEntryWizard = pPbuser->fNewEntryWizard;
  262. pUser->dwRedialAttempts = pPbuser->dwRedialAttempts;
  263. pUser->dwRedialSeconds = pPbuser->dwRedialSeconds;
  264. pUser->dwIdleDisconnectSeconds = pPbuser->dwIdleDisconnectSeconds;
  265. pUser->fRedialOnLinkFailure = pPbuser->fRedialOnLinkFailure;
  266. pUser->fPopupOnTopWhenRedialing = pPbuser->fPopupOnTopWhenRedialing;
  267. pUser->fExpandAutoDialQuery = pPbuser->fExpandAutoDialQuery;
  268. pUser->dwCallbackMode = pPbuser->dwCallbackMode;
  269. dwErr = CallbackListToRpc(&pUser->pCallbacks, pPbuser->pdtllistCallback);
  270. if (dwErr)
  271. return dwErr;
  272. if (pPbuser->pszLastCallbackByCaller != NULL)
  273. lstrcpyn(pUser->pszLastCallbackByCaller, pPbuser->pszLastCallbackByCaller, 129);
  274. else
  275. *pUser->pszLastCallbackByCaller = TEXT('\0');
  276. pUser->dwPhonebookMode = pPbuser->dwPhonebookMode;
  277. if (pPbuser->pszPersonalFile != NULL)
  278. lstrcpyn(pUser->pszPersonalFile, pPbuser->pszPersonalFile, 260);
  279. else
  280. *pUser->pszPersonalFile = TEXT('\0');
  281. if (pPbuser->pszAlternatePath != NULL)
  282. lstrcpyn(pUser->pszAlternatePath, pPbuser->pszAlternatePath, 260);
  283. else
  284. *pUser->pszAlternatePath = TEXT('\0');
  285. dwErr = StringListToRpc(&pUser->pPhonebooks, pPbuser->pdtllistPhonebooks);
  286. if (dwErr)
  287. return dwErr;
  288. dwErr = StringListToRpc(&pUser->pAreaCodes, pPbuser->pdtllistAreaCodes);
  289. if (dwErr)
  290. return dwErr;
  291. pUser->fUseAreaAndCountry = pPbuser->fUseAreaAndCountry;
  292. dwErr = StringListToRpc(&pUser->pPrefixes, pPbuser->pdtllistPrefixes);
  293. if (dwErr)
  294. return dwErr;
  295. dwErr = StringListToRpc(&pUser->pSuffixes, pPbuser->pdtllistSuffixes);
  296. if (dwErr)
  297. return dwErr;
  298. dwErr = LocationListToRpc(&pUser->pLocations, pPbuser->pdtllistLocations);
  299. if (dwErr)
  300. return dwErr;
  301. pUser->dwXPhonebook = pPbuser->dwXPhonebook;
  302. pUser->dwYPhonebook = pPbuser->dwYPhonebook;
  303. if (pPbuser->pszDefaultEntry != NULL)
  304. lstrcpyn(pUser->pszDefaultEntry, pPbuser->pszDefaultEntry, 257);
  305. else
  306. *pUser->pszDefaultEntry = TEXT('\0');
  307. pUser->fInitialized = pPbuser->fInitialized;
  308. pUser->fDirty = pPbuser->fDirty;
  309. TRACE("RasToRpcPbUser: end");
  310. return 0;
  311. }
  312. DWORD
  313. RpcToRasPbuser(
  314. PBUSER *pPbuser,
  315. LPRASRPC_PBUSER pUser
  316. )
  317. {
  318. DWORD dwErr;
  319. TRACE("RpcToRasPbUser: begin");
  320. pPbuser->fOperatorDial = pUser->fOperatorDial;
  321. pPbuser->fPreviewPhoneNumber = pUser->fPreviewPhoneNumber;
  322. pPbuser->fUseLocation = pUser->fUseLocation;
  323. pPbuser->fShowLights = pUser->fShowLights;
  324. pPbuser->fShowConnectStatus = pUser->fShowConnectStatus;
  325. pPbuser->fCloseOnDial = pUser->fCloseOnDial;
  326. pPbuser->fAllowLogonPhonebookEdits = pUser->fAllowLogonPhonebookEdits;
  327. pPbuser->fAllowLogonLocationEdits = pUser->fAllowLogonLocationEdits;
  328. pPbuser->fSkipConnectComplete = pUser->fSkipConnectComplete;
  329. pPbuser->fNewEntryWizard = pUser->fNewEntryWizard;
  330. pPbuser->dwRedialAttempts = pUser->dwRedialAttempts;
  331. pPbuser->dwRedialSeconds = pUser->dwRedialSeconds;
  332. pPbuser->dwIdleDisconnectSeconds = pUser->dwIdleDisconnectSeconds;
  333. pPbuser->fRedialOnLinkFailure = pUser->fRedialOnLinkFailure;
  334. pPbuser->fPopupOnTopWhenRedialing = pUser->fPopupOnTopWhenRedialing;
  335. pPbuser->fExpandAutoDialQuery = pUser->fExpandAutoDialQuery;
  336. pPbuser->dwCallbackMode = pUser->dwCallbackMode;
  337. dwErr = CallbackListFromRpc(&pPbuser->pdtllistCallback, pUser->pCallbacks);
  338. if (dwErr)
  339. return dwErr;
  340. pUser->pszLastCallbackByCaller[RAS_MaxPhoneNumber] = TEXT('\0');
  341. pPbuser->pszLastCallbackByCaller = StrDup(pUser->pszLastCallbackByCaller);
  342. if (pPbuser->pszLastCallbackByCaller == NULL)
  343. return GetLastError();
  344. pPbuser->dwPhonebookMode = pUser->dwPhonebookMode;
  345. pUser->pszPersonalFile[MAX_PATH - 1] = TEXT('\0');
  346. pPbuser->pszPersonalFile = StrDup(pUser->pszPersonalFile);
  347. if (pPbuser->pszPersonalFile == NULL)
  348. return GetLastError();
  349. pUser->pszAlternatePath[MAX_PATH - 1] = TEXT('\0');
  350. pPbuser->pszAlternatePath = StrDup(pUser->pszAlternatePath);
  351. if (pPbuser->pszAlternatePath == NULL)
  352. return GetLastError();
  353. dwErr = StringListFromRpc(&pPbuser->pdtllistPhonebooks, pUser->pPhonebooks);
  354. if (dwErr)
  355. return dwErr;
  356. dwErr = StringListFromRpc(&pPbuser->pdtllistAreaCodes, pUser->pAreaCodes);
  357. if (dwErr)
  358. return dwErr;
  359. pPbuser->fUseAreaAndCountry = pUser->fUseAreaAndCountry;
  360. dwErr = StringListFromRpc(&pPbuser->pdtllistPrefixes, pUser->pPrefixes);
  361. if (dwErr)
  362. return dwErr;
  363. dwErr = StringListFromRpc(&pPbuser->pdtllistSuffixes, pUser->pSuffixes);
  364. if (dwErr)
  365. return dwErr;
  366. dwErr = LocationListFromRpc(&pPbuser->pdtllistLocations, pUser->pLocations);
  367. if (dwErr)
  368. return dwErr;
  369. pPbuser->dwXPhonebook = pUser->dwXPhonebook;
  370. pPbuser->dwYPhonebook = pUser->dwYPhonebook;
  371. pUser->pszDefaultEntry[RAS_MaxEntryName - 1] = TEXT('\0');
  372. pPbuser->pszDefaultEntry = StrDup(pUser->pszDefaultEntry);
  373. if (pPbuser->pszDefaultEntry == NULL)
  374. return GetLastError();
  375. pPbuser->fInitialized = pUser->fInitialized;
  376. pPbuser->fDirty = pUser->fDirty;
  377. #if DBG
  378. TRACE1("fOperatorDial=%d", pPbuser->fOperatorDial);
  379. TRACE1("fPreviewPhoneNumber=%d", pPbuser->fPreviewPhoneNumber);
  380. TRACE1("fUseLocation=%d", pPbuser->fUseLocation);
  381. TRACE1("fShowLights=%d", pPbuser->fShowLights);
  382. TRACE1("fShowConnectStatus=%d", pPbuser->fShowConnectStatus);
  383. TRACE1("fCloseOnDial=%d", pPbuser->fCloseOnDial);
  384. TRACE1("fAllowLogonPhonebookEdits=%d", pPbuser->fAllowLogonPhonebookEdits);
  385. TRACE1("fAllowLogonLocationEdits=%d", pPbuser->fAllowLogonLocationEdits);
  386. TRACE1("fSkipConnectComplete=%d", pPbuser->fSkipConnectComplete);
  387. TRACE1("fNewEntryWizard=%d", pPbuser->fNewEntryWizard);
  388. TRACE1("dwRedialAttempts=%d", pPbuser->dwRedialAttempts);
  389. TRACE1("dwRedialSeconds=%d", pPbuser->dwRedialSeconds);
  390. TRACE1("dwIdleDisconnectSeconds=%d", pPbuser->dwIdleDisconnectSeconds);
  391. TRACE1("fRedialOnLinkFailure=%d", pPbuser->fRedialOnLinkFailure);
  392. TRACE1("fPopupOnTopWhenRedialing=%d", pPbuser->fPopupOnTopWhenRedialing);
  393. TRACE1("fExpandAutoDialQuery=%d", pPbuser->fExpandAutoDialQuery);
  394. TRACE1("dwCallbackMode=%d", pPbuser->dwCallbackMode);
  395. TRACE1("pszLastCallbackByCaller=%S", TRACESTR(pPbuser->pszLastCallbackByCaller));
  396. TRACE1("dwPhonebookMode=%d", pPbuser->dwPhonebookMode);
  397. TRACE1("pszPersonalFile=%S", TRACESTR(pPbuser->pszPersonalFile));
  398. TRACE1("pszAlternatePath=%S", TRACESTR(pPbuser->pszAlternatePath));
  399. TRACE1("fUseAreaAndCountry=%d", pPbuser->fUseAreaAndCountry);
  400. TRACE1("dwXPhonebook=%d", pPbuser->dwXPhonebook);
  401. TRACE1("dwYPhonebook=%d", pPbuser->dwYPhonebook);
  402. TRACE1("pszDefaultEntry=%S", TRACESTR(pPbuser->pszDefaultEntry));
  403. TRACE1("fInitialized=%d", pPbuser->fInitialized);
  404. TRACE1("fDirty=%d", pPbuser->fDirty);
  405. #endif
  406. TRACE("RpcToRasPbUser: end");
  407. return 0;
  408. }
  409. //
  410. // Utility routines.
  411. //
  412. void * __RPC_USER
  413. MIDL_user_allocate(size_t size)
  414. {
  415. return(Malloc(size));
  416. }
  417. void __RPC_USER
  418. MIDL_user_free( void *pointer)
  419. {
  420. Free(pointer);
  421. }