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.

4181 lines
117 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. rasmig.c
  5. Abstract:
  6. <abstract>
  7. Author:
  8. Calin Negreanu (calinn) 08 Mar 2000
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. //
  13. // Includes
  14. //
  15. #include "pch.h"
  16. #include "logmsg.h"
  17. #include <ras.h>
  18. #include <raserror.h>
  19. #define DBG_RASMIG "RasMig"
  20. #define SIZEOF_STRUCT(structname, uptomember) ((int)((LPBYTE)(&((structname*)0)->uptomember) - ((LPBYTE)((structname*)0))))
  21. //
  22. // Strings
  23. //
  24. #define S_RAS_POOL_NAME "RasConnection"
  25. #define S_RAS_NAME TEXT("RasConnection")
  26. #define S_PBKFILE_ATTRIBUTE TEXT("PbkFile")
  27. #ifdef UNICODE
  28. #define S_RASAPI_RASSETCREDENTIALS "RasSetCredentialsW"
  29. #define S_RASAPI_RASDELETEENTRY "RasDeleteEntryW"
  30. #else
  31. #define S_RASAPI_RASSETCREDENTIALS "RasSetCredentialsA"
  32. #define S_RASAPI_RASDELETEENTRY "RasDeleteEntryA"
  33. #endif
  34. //
  35. // Constants
  36. //
  37. // None
  38. //
  39. // Macros
  40. //
  41. // None
  42. //
  43. // Types
  44. //
  45. // RAS api functions
  46. typedef DWORD(WINAPI RASGETCREDENTIALSA)(
  47. IN LPCSTR lpszPhonebook,
  48. IN LPCSTR lpszEntry,
  49. OUT LPRASCREDENTIALSA lpRasCredentials
  50. );
  51. typedef RASGETCREDENTIALSA *PRASGETCREDENTIALSA;
  52. typedef DWORD(WINAPI RASSETCREDENTIALS)(
  53. IN LPCTSTR lpszPhonebook,
  54. IN LPCTSTR lpszEntry,
  55. IN LPRASCREDENTIALS lpRasCredentials,
  56. IN BOOL fClearCredentials
  57. );
  58. typedef RASSETCREDENTIALS *PRASSETCREDENTIALS;
  59. typedef DWORD(WINAPI RASDELETEENTRY)(
  60. IN LPCTSTR lpszPhonebook,
  61. IN LPCTSTR lpszEntry
  62. );
  63. typedef RASDELETEENTRY *PRASDELETEENTRY;
  64. typedef struct {
  65. PCTSTR Pattern;
  66. HASHTABLE_ENUM HashData;
  67. } RAS_ENUM, *PRAS_ENUM;
  68. //
  69. // Globals
  70. //
  71. PMHANDLE g_RasPool = NULL;
  72. HASHTABLE g_RasTable;
  73. MIG_OBJECTTYPEID g_RasTypeId = 0;
  74. static MIG_OBJECTTYPEID g_FileTypeId = 0;
  75. MIG_ATTRIBUTEID g_PbkFileAttribute = 0;
  76. BOOL g_AllowPbkRestore = FALSE;
  77. GROWBUFFER g_RasConversionBuff = INIT_GROWBUFFER;
  78. MIG_OBJECTSTRINGHANDLE g_Win9xPbkFile = NULL;
  79. // RAS api functions
  80. PRASGETCREDENTIALSA g_RasGetCredentialsA = NULL;
  81. PRASSETCREDENTIALS g_RasSetCredentials = NULL;
  82. PRASDELETEENTRY g_RasDeleteEntry = NULL;
  83. //
  84. // Macro expansion list
  85. //
  86. // None
  87. //
  88. // Private function prototypes
  89. //
  90. // None
  91. //
  92. // Macro expansion definition
  93. //
  94. // None
  95. //
  96. // Private prototypes
  97. //
  98. SGMENUMERATIONCALLBACK SgmRasConnectionsCallback;
  99. VCMENUMERATIONCALLBACK VcmRasConnectionsCallback;
  100. TYPE_ENUMFIRSTPHYSICALOBJECT EnumFirstRasConnection;
  101. TYPE_ENUMNEXTPHYSICALOBJECT EnumNextRasConnection;
  102. TYPE_ABORTENUMPHYSICALOBJECT AbortEnumRasConnection;
  103. TYPE_CONVERTOBJECTTOMULTISZ ConvertRasConnectionToMultiSz;
  104. TYPE_CONVERTMULTISZTOOBJECT ConvertMultiSzToRasConnection;
  105. TYPE_GETNATIVEOBJECTNAME GetNativeRasConnectionName;
  106. TYPE_ACQUIREPHYSICALOBJECT AcquireRasConnection;
  107. TYPE_RELEASEPHYSICALOBJECT ReleaseRasConnection;
  108. TYPE_DOESPHYSICALOBJECTEXIST DoesRasConnectionExist;
  109. TYPE_REMOVEPHYSICALOBJECT RemoveRasConnection;
  110. TYPE_CREATEPHYSICALOBJECT CreateRasConnection;
  111. TYPE_CONVERTOBJECTCONTENTTOUNICODE ConvertRasConnectionContentToUnicode;
  112. TYPE_CONVERTOBJECTCONTENTTOANSI ConvertRasConnectionContentToAnsi;
  113. TYPE_FREECONVERTEDOBJECTCONTENT FreeConvertedRasConnectionContent;
  114. MIG_OBJECTENUMCALLBACK PbkFilesCallback;
  115. MIG_RESTORECALLBACK PbkRestoreCallback;
  116. PCTSTR
  117. pCreate9xPbkFile (
  118. VOID
  119. );
  120. //
  121. // Code
  122. //
  123. BOOL
  124. RasMigInitialize (
  125. VOID
  126. )
  127. {
  128. g_RasTable = HtAllocWithData (sizeof (PCTSTR));
  129. if (!g_RasTable) {
  130. return FALSE;
  131. }
  132. g_RasPool = PmCreateNamedPool (S_RAS_POOL_NAME);
  133. if (!g_RasPool) {
  134. return FALSE;
  135. }
  136. return TRUE;
  137. }
  138. VOID
  139. RasMigTerminate (
  140. VOID
  141. )
  142. {
  143. HASHTABLE_ENUM e;
  144. PCTSTR nativeName;
  145. PCTSTR rasData = NULL;
  146. if (g_Win9xPbkFile) {
  147. nativeName = IsmGetNativeObjectName (
  148. g_FileTypeId,
  149. g_Win9xPbkFile
  150. );
  151. if (nativeName) {
  152. DeleteFile (nativeName);
  153. IsmReleaseMemory (nativeName);
  154. }
  155. IsmDestroyObjectHandle (g_Win9xPbkFile);
  156. g_Win9xPbkFile = NULL;
  157. }
  158. GbFree (&g_RasConversionBuff);
  159. if (g_RasTable) {
  160. if (EnumFirstHashTableString (&e, g_RasTable)) {
  161. do {
  162. rasData = *(PCTSTR *)(e.ExtraData);
  163. PmReleaseMemory (g_RasPool, rasData);
  164. } while (EnumNextHashTableString (&e));
  165. }
  166. HtFree (g_RasTable);
  167. g_RasTable = NULL;
  168. }
  169. if (g_RasPool) {
  170. PmDestroyPool (g_RasPool);
  171. g_RasPool = NULL;
  172. }
  173. }
  174. BOOL
  175. pLoadRasEntries (
  176. BOOL LeftSide
  177. )
  178. {
  179. HMODULE rasDll = NULL;
  180. BOOL result = FALSE;
  181. __try {
  182. rasDll = LoadLibrary (TEXT("RASAPI32.DLL"));
  183. }
  184. __except (EXCEPTION_EXECUTE_HANDLER) {
  185. rasDll = NULL;
  186. }
  187. if (rasDll) {
  188. if (LeftSide) {
  189. g_RasGetCredentialsA = (PRASGETCREDENTIALSA) GetProcAddress (rasDll, "RasGetCredentialsA");
  190. } else {
  191. g_RasSetCredentials = (PRASSETCREDENTIALS) GetProcAddress (rasDll, S_RASAPI_RASSETCREDENTIALS);
  192. g_RasDeleteEntry = (PRASDELETEENTRY) GetProcAddress (rasDll, S_RASAPI_RASDELETEENTRY);
  193. }
  194. } else {
  195. DEBUGMSG ((DBG_RASMIG, "RAS is not installed on this computer."));
  196. }
  197. return result;
  198. }
  199. BOOL
  200. pAddWin9xPbkObject (
  201. VOID
  202. )
  203. {
  204. g_Win9xPbkFile = pCreate9xPbkFile ();
  205. return (g_Win9xPbkFile != NULL);
  206. }
  207. BOOL
  208. WINAPI
  209. RasMigEtmInitialize (
  210. IN MIG_PLATFORMTYPEID Platform,
  211. IN PMIG_LOGCALLBACK LogCallback,
  212. IN PVOID Reserved
  213. )
  214. {
  215. MIG_OSVERSIONINFO versionInfo;
  216. TYPE_REGISTER rasConnTypeData;
  217. LogReInit (NULL, NULL, NULL, (PLOGCALLBACK) LogCallback);
  218. g_FileTypeId = MIG_FILE_TYPE;
  219. ZeroMemory (&rasConnTypeData, sizeof (TYPE_REGISTER));
  220. if (Platform == PLATFORM_SOURCE) {
  221. rasConnTypeData.EnumFirstPhysicalObject = EnumFirstRasConnection;
  222. rasConnTypeData.EnumNextPhysicalObject = EnumNextRasConnection;
  223. rasConnTypeData.AbortEnumPhysicalObject = AbortEnumRasConnection;
  224. rasConnTypeData.ConvertObjectToMultiSz = ConvertRasConnectionToMultiSz;
  225. rasConnTypeData.ConvertMultiSzToObject = ConvertMultiSzToRasConnection;
  226. rasConnTypeData.GetNativeObjectName = GetNativeRasConnectionName;
  227. rasConnTypeData.AcquirePhysicalObject = AcquireRasConnection;
  228. rasConnTypeData.ReleasePhysicalObject = ReleaseRasConnection;
  229. rasConnTypeData.ConvertObjectContentToUnicode = ConvertRasConnectionContentToUnicode;
  230. rasConnTypeData.ConvertObjectContentToAnsi = ConvertRasConnectionContentToAnsi;
  231. rasConnTypeData.FreeConvertedObjectContent = FreeConvertedRasConnectionContent;
  232. g_RasTypeId = IsmRegisterObjectType (
  233. S_RAS_NAME,
  234. TRUE,
  235. FALSE,
  236. &rasConnTypeData
  237. );
  238. pLoadRasEntries (TRUE);
  239. if (IsmGetOsVersionInfo (Platform, &versionInfo)) {
  240. if (versionInfo.OsType == OSTYPE_WINDOWS9X) {
  241. // now it's time to convert registry into a PBK file
  242. pAddWin9xPbkObject ();
  243. }
  244. }
  245. } else {
  246. rasConnTypeData.ConvertObjectToMultiSz = ConvertRasConnectionToMultiSz;
  247. rasConnTypeData.ConvertMultiSzToObject = ConvertMultiSzToRasConnection;
  248. rasConnTypeData.GetNativeObjectName = GetNativeRasConnectionName;
  249. rasConnTypeData.DoesPhysicalObjectExist = DoesRasConnectionExist;
  250. rasConnTypeData.RemovePhysicalObject = RemoveRasConnection;
  251. rasConnTypeData.CreatePhysicalObject = CreateRasConnection;
  252. rasConnTypeData.ConvertObjectContentToUnicode = ConvertRasConnectionContentToUnicode;
  253. rasConnTypeData.ConvertObjectContentToAnsi = ConvertRasConnectionContentToAnsi;
  254. rasConnTypeData.FreeConvertedObjectContent = FreeConvertedRasConnectionContent;
  255. g_RasTypeId = IsmRegisterObjectType (
  256. S_RAS_NAME,
  257. TRUE,
  258. FALSE,
  259. &rasConnTypeData
  260. );
  261. pLoadRasEntries (FALSE);
  262. }
  263. MYASSERT (g_RasTypeId);
  264. return TRUE;
  265. }
  266. PCTSTR
  267. pGetNextRasConnection (
  268. IN HANDLE PbkHandle
  269. )
  270. {
  271. CHAR input = 0;
  272. ULONGLONG beginPos = 0;
  273. ULONGLONG endPos = 0;
  274. ULONGLONG lastPos = 0;
  275. PSTR resultTmp = NULL;
  276. PTSTR result = NULL;
  277. #ifdef UNICODE
  278. WORD oldCodePage;
  279. DWORD sizeW = 0;
  280. PWSTR resultW = NULL;
  281. #endif
  282. while (TRUE) {
  283. if (!BfReadFile (PbkHandle, (PBYTE)(&input), sizeof (CHAR))) {
  284. break;
  285. }
  286. if (input == '[') {
  287. if (!beginPos) {
  288. BfGetFilePointer (PbkHandle, &beginPos);
  289. }
  290. }
  291. if (input == ']') {
  292. if (beginPos) {
  293. if (!endPos) {
  294. BfGetFilePointer (PbkHandle, &endPos);
  295. endPos --;
  296. } else {
  297. beginPos = 0;
  298. endPos = 0;
  299. }
  300. }
  301. }
  302. if (input == '\n') {
  303. if (beginPos && endPos && (endPos > beginPos)) {
  304. BfGetFilePointer (PbkHandle, &lastPos);
  305. BfSetFilePointer (PbkHandle, beginPos);
  306. resultTmp = PmGetMemory (g_RasPool, ((UINT) (endPos - beginPos) + 1) * sizeof (CHAR));
  307. if (!BfReadFile (PbkHandle, (PBYTE) resultTmp, (UINT) (endPos - beginPos) + 1)) {
  308. PmReleaseMemory (g_RasPool, resultTmp);
  309. resultTmp = NULL;
  310. } else {
  311. resultTmp [(UINT) (endPos - beginPos)] = 0;
  312. }
  313. BfSetFilePointer (PbkHandle, lastPos);
  314. break;
  315. }
  316. beginPos = 0;
  317. endPos = 0;
  318. }
  319. }
  320. #ifdef UNICODE
  321. if (resultTmp) {
  322. // make sure that the conversion is using UTF8
  323. oldCodePage = SetConversionCodePage (CP_UTF8);
  324. sizeW = SizeOfStringA(resultTmp);
  325. resultW = PmGetMemory (g_RasPool, sizeW * sizeof (WCHAR));
  326. if (resultW) {
  327. KnownSizeAtoW (resultW, resultTmp);
  328. }
  329. SetConversionCodePage (oldCodePage);
  330. if (resultW) {
  331. result = PmDuplicateStringW (g_RasPool, resultW);
  332. PmReleaseMemory (g_RasPool, resultW);
  333. resultW = NULL;
  334. }
  335. }
  336. #else
  337. result = resultTmp;
  338. #endif
  339. return result;
  340. }
  341. BOOL
  342. pGetNextRasPair (
  343. IN HANDLE PbkHandle,
  344. OUT PCTSTR *ValueName,
  345. OUT PCTSTR *Value
  346. )
  347. {
  348. BOOL error = FALSE;
  349. CHAR input = 0;
  350. ULONGLONG beginPos = 0;
  351. ULONGLONG endPos = 0;
  352. ULONGLONG lastPos = 0;
  353. BOOL begin = TRUE;
  354. BOOL inValue = FALSE;
  355. PSTR valueName = NULL;
  356. PSTR value = NULL;
  357. #ifdef UNICODE
  358. WORD oldCodePage;
  359. DWORD sizeW = 0;
  360. PWSTR valueNameW = NULL;
  361. PWSTR valueW = NULL;
  362. #endif
  363. BfGetFilePointer (PbkHandle, &beginPos);
  364. while (TRUE) {
  365. if (!BfReadFile (PbkHandle, (PBYTE)(&input), sizeof (CHAR))) {
  366. error = TRUE;
  367. break;
  368. }
  369. if ((input == '[') && begin) {
  370. BfSetFilePointer (PbkHandle, beginPos);
  371. error = TRUE;
  372. break;
  373. }
  374. if ((input == ' ') && begin) {
  375. continue;
  376. }
  377. begin = FALSE;
  378. if (input == '=') {
  379. if (!inValue) {
  380. BfGetFilePointer (PbkHandle, &endPos);
  381. endPos --;
  382. if (endPos > beginPos) {
  383. BfGetFilePointer (PbkHandle, &lastPos);
  384. BfSetFilePointer (PbkHandle, beginPos);
  385. valueName = PmGetMemory (g_RasPool, ((UINT) (endPos - beginPos) + 1) * sizeof (CHAR));
  386. if (!BfReadFile (PbkHandle, (PBYTE) valueName, (UINT) (endPos - beginPos) + 1)) {
  387. error = TRUE;
  388. break;
  389. } else {
  390. valueName [(UINT) (endPos - beginPos)] = 0;
  391. }
  392. BfSetFilePointer (PbkHandle, lastPos);
  393. }
  394. BfGetFilePointer (PbkHandle, &beginPos);
  395. inValue = TRUE;
  396. }
  397. continue;
  398. }
  399. if (input == '\r') {
  400. BfGetFilePointer (PbkHandle, &endPos);
  401. endPos --;
  402. continue;
  403. }
  404. if (input == '\n') {
  405. if (endPos > beginPos) {
  406. BfGetFilePointer (PbkHandle, &lastPos);
  407. BfSetFilePointer (PbkHandle, beginPos);
  408. if (inValue) {
  409. value = PmGetMemory (g_RasPool, ((UINT) (endPos - beginPos) + 1) * sizeof (CHAR));
  410. if (!BfReadFile (PbkHandle, (PBYTE) value, (UINT) (endPos - beginPos) + 1)) {
  411. error = TRUE;
  412. break;
  413. } else {
  414. value [(UINT) (endPos - beginPos)] = 0;
  415. }
  416. } else {
  417. valueName = PmGetMemory (g_RasPool, ((UINT) (endPos - beginPos) + 1) * sizeof (CHAR));
  418. if (!BfReadFile (PbkHandle, (PBYTE) valueName, (UINT) (endPos - beginPos) + 1)) {
  419. error = TRUE;
  420. break;
  421. } else {
  422. valueName [(UINT) (endPos - beginPos)] = 0;
  423. }
  424. }
  425. BfSetFilePointer (PbkHandle, lastPos);
  426. }
  427. break;
  428. }
  429. }
  430. if (error) {
  431. if (valueName) {
  432. PmReleaseMemory (g_RasPool, valueName);
  433. valueName = NULL;
  434. }
  435. if (value) {
  436. PmReleaseMemory (g_RasPool, value);
  437. value = NULL;
  438. }
  439. }
  440. #ifdef UNICODE
  441. if (ValueName) {
  442. if (valueName) {
  443. // make sure that the conversion is using UTF8
  444. oldCodePage = SetConversionCodePage (CP_UTF8);
  445. sizeW = SizeOfStringA (valueName);
  446. valueNameW = PmGetMemory (g_RasPool, sizeW * sizeof (WCHAR));
  447. if (valueNameW) {
  448. KnownSizeAtoW (valueNameW, valueName);
  449. }
  450. SetConversionCodePage (oldCodePage);
  451. if (valueNameW) {
  452. *ValueName = PmDuplicateStringW (g_RasPool, valueNameW);
  453. PmReleaseMemory (g_RasPool, valueNameW);
  454. }
  455. } else {
  456. *ValueName = NULL;
  457. }
  458. }
  459. if (Value) {
  460. if (value) {
  461. // make sure that the conversion is using UTF8
  462. oldCodePage = SetConversionCodePage (CP_UTF8);
  463. sizeW = SizeOfStringA(value);
  464. valueW = PmGetMemory (g_RasPool, sizeW * sizeof (WCHAR));
  465. if (valueW) {
  466. KnownSizeAtoW (valueW, value);
  467. }
  468. SetConversionCodePage (oldCodePage);
  469. if (valueW) {
  470. *Value = PmDuplicateStringW (g_RasPool, valueW);
  471. PmReleaseMemory (g_RasPool, valueW);
  472. }
  473. } else {
  474. *Value = NULL;
  475. }
  476. }
  477. #else
  478. if (ValueName) {
  479. *ValueName = valueName;
  480. }
  481. if (Value) {
  482. *Value = value;
  483. }
  484. #endif
  485. return !error;
  486. }
  487. PCTSTR
  488. pGetRasLineValue (
  489. IN PCTSTR RasLines,
  490. IN PCTSTR ValueName
  491. )
  492. {
  493. MULTISZ_ENUM multiSzEnum;
  494. BOOL first = TRUE;
  495. BOOL found = FALSE;
  496. if (EnumFirstMultiSz (&multiSzEnum, RasLines)) {
  497. do {
  498. if (found) {
  499. return multiSzEnum.CurrentString;
  500. }
  501. if (first && StringIMatch (multiSzEnum.CurrentString, ValueName)) {
  502. found = TRUE;
  503. }
  504. first = !first;
  505. } while (EnumNextMultiSz (&multiSzEnum));
  506. }
  507. return NULL;
  508. }
  509. BOOL
  510. pLoadRasConnections (
  511. IN PCTSTR PbkFileName,
  512. IN HASHTABLE RasTable
  513. )
  514. {
  515. HANDLE pbkFileHandle;
  516. PCTSTR entryName;
  517. PCTSTR valueName;
  518. PCTSTR value;
  519. GROWBUFFER rasLines = INIT_GROWBUFFER;
  520. PTSTR rasLinesStr;
  521. MIG_OBJECTSTRINGHANDLE rasConnectionName;
  522. RASCREDENTIALSA rasCredentials;
  523. TCHAR valueStr [sizeof (DWORD) * 2 + 3];
  524. DWORD err;
  525. MIG_OSVERSIONINFO versionInfo;
  526. BOOL versionOk = FALSE;
  527. BOOL inMedia = FALSE;
  528. BOOL result = FALSE;
  529. #ifdef UNICODE
  530. PCSTR tempStr1 = NULL;
  531. PCSTR tempStr2 = NULL;
  532. PCWSTR tempStr3 = NULL;
  533. #endif
  534. if (!RasTable) {
  535. return FALSE;
  536. }
  537. pbkFileHandle = BfOpenReadFile (PbkFileName);
  538. if (pbkFileHandle) {
  539. while (TRUE) {
  540. // get the next RAS connection
  541. entryName = pGetNextRasConnection (pbkFileHandle);
  542. if (!entryName) {
  543. break;
  544. }
  545. rasLines.End = 0;
  546. GbMultiSzAppend (&rasLines, TEXT("ConnectionName"));
  547. GbMultiSzAppend (&rasLines, entryName);
  548. versionOk = IsmGetOsVersionInfo (PLATFORM_SOURCE, &versionInfo);
  549. // we use credentials API only on NT, on win9x the conversion code will automatically insert the fields
  550. if (!versionOk || (versionInfo.OsType != OSTYPE_WINDOWS9X)) {
  551. err = ERROR_INVALID_DATA;
  552. if (g_RasGetCredentialsA) {
  553. ZeroMemory (&rasCredentials, sizeof (RASCREDENTIALSA));
  554. rasCredentials.dwSize = sizeof (RASCREDENTIALSA);
  555. rasCredentials.dwMask = RASCM_UserName | RASCM_Domain | RASCM_Password;
  556. #ifdef UNICODE
  557. tempStr1 = ConvertWtoA (PbkFileName);
  558. tempStr2 = ConvertWtoA (entryName);
  559. err = g_RasGetCredentialsA (tempStr1, tempStr2, &rasCredentials);
  560. FreeConvertedStr (tempStr1);
  561. FreeConvertedStr (tempStr2);
  562. #else
  563. err = g_RasGetCredentialsA (PbkFileName, entryName, &rasCredentials);
  564. #endif
  565. if (!err) {
  566. wsprintf (valueStr, TEXT("0x%08X"), rasCredentials.dwMask);
  567. GbMultiSzAppend (&rasLines, TEXT("CredMask"));
  568. GbMultiSzAppend (&rasLines, valueStr);
  569. GbMultiSzAppend (&rasLines, TEXT("CredName"));
  570. #ifndef UNICODE
  571. GbMultiSzAppend (&rasLines, (*rasCredentials.szUserName)?rasCredentials.szUserName:TEXT("<empty>"));
  572. #else
  573. tempStr3 = ConvertAtoW (rasCredentials.szUserName);
  574. GbMultiSzAppend (&rasLines, (*tempStr3)?tempStr3:TEXT("<empty>"));
  575. FreeConvertedStr (tempStr3);
  576. #endif
  577. GbMultiSzAppend (&rasLines, TEXT("CredDomain"));
  578. #ifndef UNICODE
  579. GbMultiSzAppend (&rasLines, (*rasCredentials.szDomain)?rasCredentials.szDomain:TEXT("<empty>"));
  580. #else
  581. tempStr3 = ConvertAtoW (rasCredentials.szDomain);
  582. GbMultiSzAppend (&rasLines, (*tempStr3)?tempStr3:TEXT("<empty>"));
  583. FreeConvertedStr (tempStr3);
  584. #endif
  585. GbMultiSzAppend (&rasLines, TEXT("CredPassword"));
  586. #ifndef UNICODE
  587. GbMultiSzAppend (&rasLines, (*rasCredentials.szPassword)?rasCredentials.szPassword:TEXT("<empty>"));
  588. #else
  589. tempStr3 = ConvertAtoW (rasCredentials.szPassword);
  590. GbMultiSzAppend (&rasLines, (*tempStr3)?tempStr3:TEXT("<empty>"));
  591. FreeConvertedStr (tempStr3);
  592. #endif
  593. }
  594. }
  595. if (err) {
  596. GbMultiSzAppend (&rasLines, TEXT("CredMask"));
  597. GbMultiSzAppend (&rasLines, TEXT("<empty>"));
  598. GbMultiSzAppend (&rasLines, TEXT("CredName"));
  599. GbMultiSzAppend (&rasLines, TEXT("<empty>"));
  600. GbMultiSzAppend (&rasLines, TEXT("CredDomain"));
  601. GbMultiSzAppend (&rasLines, TEXT("<empty>"));
  602. GbMultiSzAppend (&rasLines, TEXT("CredPassword"));
  603. GbMultiSzAppend (&rasLines, TEXT("<empty>"));
  604. }
  605. }
  606. inMedia = FALSE;
  607. while (TRUE) {
  608. // get the next RAS connection line
  609. if (!pGetNextRasPair (pbkFileHandle, &valueName, &value)) {
  610. break;
  611. }
  612. if (valueName &&
  613. StringMatch (valueName, TEXT("MEDIA")) &&
  614. value &&
  615. StringIMatch (value, TEXT("serial"))
  616. ) {
  617. inMedia = TRUE;
  618. }
  619. if (inMedia &&
  620. valueName &&
  621. StringMatch (valueName, TEXT("DEVICE"))
  622. ) {
  623. inMedia = FALSE;
  624. }
  625. if (inMedia &&
  626. valueName &&
  627. StringIMatch (valueName, TEXT("Port"))
  628. ) {
  629. if (value) {
  630. PmReleaseMemory (g_RasPool, value);
  631. value = NULL;
  632. }
  633. }
  634. if (inMedia &&
  635. valueName &&
  636. StringMatch (valueName, TEXT("Device"))
  637. ) {
  638. if (value) {
  639. PmReleaseMemory (g_RasPool, value);
  640. value = NULL;
  641. }
  642. }
  643. GbMultiSzAppend (&rasLines, valueName?valueName:TEXT("<empty>"));
  644. GbMultiSzAppend (&rasLines, value?value:TEXT("<empty>"));
  645. if (valueName) {
  646. PmReleaseMemory (g_RasPool, valueName);
  647. valueName = NULL;
  648. }
  649. if (value) {
  650. PmReleaseMemory (g_RasPool, value);
  651. value = NULL;
  652. }
  653. }
  654. GbMultiSzAppend (&rasLines, TEXT(""));
  655. if (rasLines.End) {
  656. // now add the RAS connection
  657. rasLinesStr = PmGetMemory (g_RasPool, rasLines.End);
  658. CopyMemory (rasLinesStr, rasLines.Buf, rasLines.End);
  659. rasConnectionName = IsmCreateObjectHandle (PbkFileName, entryName);
  660. MYASSERT (rasConnectionName);
  661. if (rasConnectionName) {
  662. result = TRUE;
  663. HtAddStringEx (RasTable, rasConnectionName, &rasLinesStr, FALSE);
  664. }
  665. IsmDestroyObjectHandle (rasConnectionName);
  666. }
  667. PmReleaseMemory (g_RasPool, entryName);
  668. }
  669. CloseHandle (pbkFileHandle);
  670. }
  671. return result;
  672. }
  673. UINT
  674. PbkFilesCallback (
  675. IN PCMIG_OBJECTENUMDATA Data,
  676. IN ULONG_PTR CallerArg
  677. )
  678. {
  679. if (Data->IsLeaf) {
  680. // do this only if somebody actually persisted the object
  681. if (IsmIsPersistentObject (Data->ObjectTypeId, Data->ObjectName) ||
  682. IsmIsApplyObject (Data->ObjectTypeId, Data->ObjectName)
  683. ) {
  684. // record all connections from this PBK file
  685. if (pLoadRasConnections (Data->NativeObjectName, g_RasTable)) {
  686. // this is really a PBK file and at least one valid
  687. // connection was found
  688. // set the PbkFile attribute so we won't restore this one as a file (if it survives)
  689. IsmSetAttributeOnObject (Data->ObjectTypeId, Data->ObjectName, g_PbkFileAttribute);
  690. }
  691. }
  692. }
  693. return CALLBACK_ENUM_CONTINUE;
  694. }
  695. BOOL
  696. WINAPI
  697. RasMigSgmInitialize (
  698. IN PMIG_LOGCALLBACK LogCallback,
  699. IN PVOID Reserved
  700. )
  701. {
  702. LogReInit (NULL, NULL, NULL, (PLOGCALLBACK) LogCallback);
  703. return TRUE;
  704. }
  705. BOOL
  706. WINAPI
  707. RasMigSgmParse (
  708. IN PVOID Reserved
  709. )
  710. {
  711. return TRUE;
  712. }
  713. UINT
  714. SgmRasConnectionsCallback (
  715. IN PCMIG_OBJECTENUMDATA Data,
  716. IN ULONG_PTR CallerArg
  717. )
  718. {
  719. PCTSTR node, nodePtr, leaf;
  720. PTSTR leafPtr;
  721. PCTSTR rasLines;
  722. PCTSTR rasValue;
  723. MIG_OBJECTSTRINGHANDLE objectName;
  724. MIG_CONTENT objectContent;
  725. PCTSTR nativeName;
  726. MIG_OSVERSIONINFO versionInfo;
  727. BOOL versionOk = FALSE;
  728. if (IsmGetRealPlatform () == PLATFORM_DESTINATION) {
  729. // let's reset the PbkFileAttribute on the source of this connection
  730. // because the attribute was lost during the transport
  731. if (IsmCreateObjectStringsFromHandle (Data->ObjectName, &node, &leaf)) {
  732. if (node) {
  733. leafPtr = _tcsrchr (node, TEXT('\\'));
  734. if (leafPtr) {
  735. *leafPtr = 0;
  736. leafPtr ++;
  737. objectName = IsmCreateObjectHandle (node, leafPtr);
  738. if (objectName) {
  739. IsmSetAttributeOnObject (g_FileTypeId, objectName, g_PbkFileAttribute);
  740. IsmDestroyObjectHandle (objectName);
  741. }
  742. }
  743. }
  744. IsmDestroyObjectString (node);
  745. IsmDestroyObjectString (leaf);
  746. }
  747. }
  748. // let's see if we can actually migrate this RAS connection
  749. if (IsmAcquireObject (Data->ObjectTypeId, Data->ObjectName, &objectContent)) {
  750. versionOk = IsmGetOsVersionInfo (PLATFORM_SOURCE, &versionInfo);
  751. rasLines = (PCTSTR) objectContent.MemoryContent.ContentBytes;
  752. rasValue = pGetRasLineValue (rasLines, TEXT("BaseProtocol"));
  753. if (rasValue && (StringIMatch (rasValue, TEXT("1")) || StringIMatch (rasValue, TEXT("2")))) {
  754. IsmAbandonObjectOnCollision (Data->ObjectTypeId, Data->ObjectName);
  755. IsmMakeApplyObject (Data->ObjectTypeId, Data->ObjectName);
  756. // now it's a good time to force the migration of the script file
  757. // if this connection has one
  758. rasValue = NULL;
  759. if (versionOk) {
  760. if (versionInfo.OsType == OSTYPE_WINDOWSNT) {
  761. if (versionInfo.OsMajorVersion == OSMAJOR_WINNT4) {
  762. rasValue = pGetRasLineValue (rasLines, TEXT("Type"));
  763. }
  764. if (versionInfo.OsMajorVersion == OSMAJOR_WINNT5) {
  765. rasValue = pGetRasLineValue (rasLines, TEXT("Name"));
  766. }
  767. }
  768. if (versionInfo.OsType == OSTYPE_WINDOWS9X) {
  769. rasValue = pGetRasLineValue (rasLines, TEXT("Name"));
  770. }
  771. }
  772. if (rasValue && *rasValue) {
  773. node = DuplicatePathString (rasValue, 0);
  774. if (_tcsnextc (node) == TEXT('[')) {
  775. nodePtr = _tcsinc (node);
  776. } else {
  777. nodePtr = node;
  778. }
  779. leafPtr = _tcsrchr (nodePtr, TEXT('\\'));
  780. if (leafPtr) {
  781. *leafPtr = 0;
  782. leafPtr ++;
  783. objectName = IsmCreateObjectHandle (nodePtr, leafPtr);
  784. if (objectName) {
  785. IsmMakeApplyObject (g_FileTypeId, objectName);
  786. IsmDestroyObjectHandle (objectName);
  787. }
  788. }
  789. FreePathString (node);
  790. }
  791. } else {
  792. // this is an unsupported framing protocol
  793. // we will log a message and abandon this connection
  794. nativeName = IsmGetNativeObjectName (Data->ObjectTypeId, Data->ObjectName);
  795. LOG ((LOG_WARNING, (PCSTR) MSG_RASMIG_UNSUPPORTEDSETTINGS, nativeName));
  796. IsmReleaseMemory (nativeName);
  797. }
  798. IsmReleaseObject (&objectContent);
  799. }
  800. return CALLBACK_ENUM_CONTINUE;
  801. }
  802. BOOL
  803. WINAPI
  804. RasMigSgmQueueEnumeration (
  805. IN PVOID Reserved
  806. )
  807. {
  808. ENCODEDSTRHANDLE pattern;
  809. g_PbkFileAttribute = IsmRegisterAttribute (S_PBKFILE_ATTRIBUTE, FALSE);
  810. MYASSERT (g_PbkFileAttribute);
  811. if (IsmGetRealPlatform () == PLATFORM_SOURCE) {
  812. // hook all PBK files enumeration, we will not migrate the files but the connections within
  813. pattern = IsmCreateSimpleObjectPattern (NULL, FALSE, TEXT("*.PBK"), TRUE);
  814. IsmHookEnumeration (
  815. g_FileTypeId,
  816. pattern,
  817. PbkFilesCallback,
  818. (ULONG_PTR) 0,
  819. TEXT("PbkFiles")
  820. );
  821. IsmDestroyObjectHandle (pattern);
  822. }
  823. pattern = IsmCreateSimpleObjectPattern (NULL, TRUE, NULL, TRUE);
  824. IsmQueueEnumeration (
  825. g_RasTypeId,
  826. pattern,
  827. SgmRasConnectionsCallback,
  828. (ULONG_PTR) 0,
  829. S_RAS_NAME
  830. );
  831. IsmDestroyObjectHandle (pattern);
  832. return TRUE;
  833. }
  834. BOOL
  835. WINAPI
  836. RasMigVcmInitialize (
  837. IN PMIG_LOGCALLBACK LogCallback,
  838. IN PVOID Reserved
  839. )
  840. {
  841. LogReInit (NULL, NULL, NULL, (PLOGCALLBACK) LogCallback);
  842. return TRUE;
  843. }
  844. BOOL
  845. WINAPI
  846. RasMigVcmParse (
  847. IN PVOID Reserved
  848. )
  849. {
  850. return RasMigSgmParse (Reserved);
  851. }
  852. UINT
  853. VcmRasConnectionsCallback (
  854. IN PCMIG_OBJECTENUMDATA Data,
  855. IN ULONG_PTR CallerArg
  856. )
  857. {
  858. PCTSTR node, nodePtr;
  859. PTSTR leafPtr;
  860. PCTSTR rasLines;
  861. PCTSTR rasValue;
  862. MIG_OBJECTSTRINGHANDLE objectName;
  863. MIG_CONTENT objectContent;
  864. PCTSTR nativeName;
  865. MIG_OSVERSIONINFO versionInfo;
  866. BOOL versionOk = FALSE;
  867. // let's see if we can actually migrate this RAS connection
  868. if (IsmAcquireObject (Data->ObjectTypeId, Data->ObjectName, &objectContent)) {
  869. versionOk = IsmGetOsVersionInfo (PLATFORM_SOURCE, &versionInfo);
  870. rasLines = (PCTSTR) objectContent.MemoryContent.ContentBytes;
  871. rasValue = pGetRasLineValue (rasLines, TEXT("BaseProtocol"));
  872. if (rasValue && (StringIMatch (rasValue, TEXT("1")) || StringIMatch (rasValue, TEXT("2")))) {
  873. IsmMakePersistentObject (Data->ObjectTypeId, Data->ObjectName);
  874. // now it's a good time to force the migration of the script file
  875. // if this connection has one
  876. rasValue = NULL;
  877. if (versionOk) {
  878. if (versionInfo.OsType == OSTYPE_WINDOWSNT) {
  879. if (versionInfo.OsMajorVersion == OSMAJOR_WINNT4) {
  880. rasValue = pGetRasLineValue (rasLines, TEXT("Type"));
  881. }
  882. if (versionInfo.OsMajorVersion == OSMAJOR_WINNT5) {
  883. rasValue = pGetRasLineValue (rasLines, TEXT("Name"));
  884. }
  885. }
  886. if (versionInfo.OsType == OSTYPE_WINDOWS9X) {
  887. rasValue = pGetRasLineValue (rasLines, TEXT("Name"));
  888. }
  889. }
  890. if (rasValue && *rasValue) {
  891. node = DuplicatePathString (rasValue, 0);
  892. if (_tcsnextc (node) == TEXT('[')) {
  893. nodePtr = _tcsinc (node);
  894. } else {
  895. nodePtr = node;
  896. }
  897. leafPtr = _tcsrchr (nodePtr, TEXT('\\'));
  898. if (leafPtr) {
  899. *leafPtr = 0;
  900. leafPtr ++;
  901. objectName = IsmCreateObjectHandle (nodePtr, leafPtr);
  902. if (objectName) {
  903. IsmMakePersistentObject (g_FileTypeId, objectName);
  904. IsmDestroyObjectHandle (objectName);
  905. }
  906. }
  907. FreePathString (node);
  908. }
  909. } else {
  910. // this is an unsupported framing protocol
  911. // we will log a message and abandon this connection
  912. nativeName = IsmGetNativeObjectName (Data->ObjectTypeId, Data->ObjectName);
  913. LOG ((LOG_WARNING, (PCSTR) MSG_RASMIG_UNSUPPORTEDSETTINGS, nativeName));
  914. IsmReleaseMemory (nativeName);
  915. }
  916. IsmReleaseObject (&objectContent);
  917. }
  918. return CALLBACK_ENUM_CONTINUE;
  919. }
  920. BOOL
  921. WINAPI
  922. RasMigVcmQueueEnumeration (
  923. IN PVOID Reserved
  924. )
  925. {
  926. ENCODEDSTRHANDLE pattern;
  927. g_PbkFileAttribute = IsmRegisterAttribute (S_PBKFILE_ATTRIBUTE, FALSE);
  928. MYASSERT (g_PbkFileAttribute);
  929. // hook all PBK files enumeration, we will not migrate the files but the connections within
  930. pattern = IsmCreateSimpleObjectPattern (NULL, FALSE, TEXT("*.PBK"), TRUE);
  931. IsmHookEnumeration (
  932. g_FileTypeId,
  933. pattern,
  934. PbkFilesCallback,
  935. (ULONG_PTR) 0,
  936. TEXT("PbkFiles")
  937. );
  938. IsmDestroyObjectHandle (pattern);
  939. pattern = IsmCreateSimpleObjectPattern (NULL, TRUE, NULL, TRUE);
  940. IsmQueueEnumeration (
  941. g_RasTypeId,
  942. pattern,
  943. VcmRasConnectionsCallback,
  944. (ULONG_PTR) 0,
  945. S_RAS_NAME
  946. );
  947. IsmDestroyObjectHandle (pattern);
  948. return TRUE;
  949. }
  950. BOOL
  951. PbkRestoreCallback (
  952. IN MIG_OBJECTTYPEID ObjectTypeId,
  953. IN MIG_OBJECTID ObjectId,
  954. IN MIG_OBJECTSTRINGHANDLE ObjectName
  955. )
  956. {
  957. // if this is a PBK file we won't allow it to be restored like a file,
  958. // we will add the proper connections ourselves.
  959. return ((!IsmIsAttributeSetOnObjectId (ObjectId, g_PbkFileAttribute)) || g_AllowPbkRestore);
  960. }
  961. BOOL
  962. WINAPI
  963. RasMigOpmInitialize (
  964. IN PMIG_LOGCALLBACK LogCallback,
  965. IN PVOID Reserved
  966. )
  967. {
  968. g_PbkFileAttribute = IsmRegisterAttribute (S_PBKFILE_ATTRIBUTE, FALSE);
  969. MYASSERT (g_PbkFileAttribute);
  970. IsmRegisterRestoreCallback (PbkRestoreCallback);
  971. return TRUE;
  972. }
  973. BOOL
  974. pEnumRasConnectionWorker (
  975. OUT PMIG_TYPEOBJECTENUM EnumPtr,
  976. IN PRAS_ENUM RasEnum
  977. )
  978. {
  979. PCTSTR rasLines;
  980. PCTSTR connName;
  981. PCTSTR node, leaf;
  982. if (EnumPtr->ObjectName) {
  983. IsmDestroyObjectHandle (EnumPtr->ObjectName);
  984. EnumPtr->ObjectName = NULL;
  985. }
  986. if (EnumPtr->NativeObjectName) {
  987. IsmDestroyObjectHandle (EnumPtr->NativeObjectName);
  988. EnumPtr->NativeObjectName = NULL;
  989. }
  990. if (EnumPtr->ObjectNode) {
  991. IsmDestroyObjectString (EnumPtr->ObjectNode);
  992. EnumPtr->ObjectNode = NULL;
  993. }
  994. if (EnumPtr->ObjectLeaf) {
  995. IsmDestroyObjectString (EnumPtr->ObjectLeaf);
  996. EnumPtr->ObjectLeaf = NULL;
  997. }
  998. do {
  999. IsmCreateObjectStringsFromHandle (RasEnum->HashData.String, &node, &leaf);
  1000. if (RasEnum->HashData.ExtraData) {
  1001. rasLines = *((PCTSTR *) RasEnum->HashData.ExtraData);
  1002. connName = pGetRasLineValue (rasLines, TEXT("ConnectionName"));
  1003. EnumPtr->ObjectName = IsmCreateObjectHandle (node, connName?connName:leaf);
  1004. EnumPtr->NativeObjectName = IsmCreateObjectHandle (node, connName?connName:leaf);
  1005. } else {
  1006. EnumPtr->ObjectName = IsmCreateObjectHandle (node, leaf);
  1007. EnumPtr->NativeObjectName = IsmCreateObjectHandle (node, leaf);
  1008. }
  1009. if (!ObsPatternMatch (RasEnum->Pattern, EnumPtr->ObjectName)) {
  1010. if (!EnumNextHashTableString (&RasEnum->HashData)) {
  1011. AbortEnumRasConnection (EnumPtr);
  1012. return FALSE;
  1013. }
  1014. continue;
  1015. }
  1016. IsmCreateObjectStringsFromHandle (EnumPtr->ObjectName, &EnumPtr->ObjectNode, &EnumPtr->ObjectLeaf);
  1017. EnumPtr->Level = 1;
  1018. EnumPtr->SubLevel = 0;
  1019. EnumPtr->IsLeaf = TRUE;
  1020. EnumPtr->IsNode = FALSE;
  1021. EnumPtr->Details.DetailsSize = 0;
  1022. EnumPtr->Details.DetailsData = NULL;
  1023. return TRUE;
  1024. } while (TRUE);
  1025. }
  1026. BOOL
  1027. EnumFirstRasConnection (
  1028. IN OUT PMIG_TYPEOBJECTENUM EnumPtr, CALLER_INITIALIZED
  1029. IN MIG_OBJECTSTRINGHANDLE Pattern,
  1030. IN UINT MaxLevel
  1031. )
  1032. {
  1033. PRAS_ENUM rasEnum = NULL;
  1034. if (!g_RasTable) {
  1035. return FALSE;
  1036. }
  1037. rasEnum = (PRAS_ENUM) PmGetMemory (g_RasPool, sizeof (RAS_ENUM));
  1038. rasEnum->Pattern = PmDuplicateString (g_RasPool, Pattern);
  1039. EnumPtr->EtmHandle = (LONG_PTR) rasEnum;
  1040. if (EnumFirstHashTableString (&rasEnum->HashData, g_RasTable)) {
  1041. return pEnumRasConnectionWorker (EnumPtr, rasEnum);
  1042. } else {
  1043. AbortEnumRasConnection (EnumPtr);
  1044. return FALSE;
  1045. }
  1046. }
  1047. BOOL
  1048. EnumNextRasConnection (
  1049. IN OUT PMIG_TYPEOBJECTENUM EnumPtr
  1050. )
  1051. {
  1052. PRAS_ENUM rasEnum = NULL;
  1053. rasEnum = (PRAS_ENUM)(EnumPtr->EtmHandle);
  1054. if (!rasEnum) {
  1055. return FALSE;
  1056. }
  1057. if (EnumNextHashTableString (&rasEnum->HashData)) {
  1058. return pEnumRasConnectionWorker (EnumPtr, rasEnum);
  1059. } else {
  1060. AbortEnumRasConnection (EnumPtr);
  1061. return FALSE;
  1062. }
  1063. }
  1064. VOID
  1065. AbortEnumRasConnection (
  1066. IN OUT PMIG_TYPEOBJECTENUM EnumPtr
  1067. )
  1068. {
  1069. PRAS_ENUM rasEnum = NULL;
  1070. if (EnumPtr->ObjectName) {
  1071. IsmDestroyObjectHandle (EnumPtr->ObjectName);
  1072. EnumPtr->ObjectName = NULL;
  1073. }
  1074. if (EnumPtr->NativeObjectName) {
  1075. IsmDestroyObjectHandle (EnumPtr->NativeObjectName);
  1076. EnumPtr->NativeObjectName = NULL;
  1077. }
  1078. if (EnumPtr->ObjectNode) {
  1079. IsmDestroyObjectString (EnumPtr->ObjectNode);
  1080. EnumPtr->ObjectNode = NULL;
  1081. }
  1082. if (EnumPtr->ObjectLeaf) {
  1083. IsmDestroyObjectString (EnumPtr->ObjectLeaf);
  1084. EnumPtr->ObjectLeaf = NULL;
  1085. }
  1086. rasEnum = (PRAS_ENUM)(EnumPtr->EtmHandle);
  1087. if (!rasEnum) {
  1088. return;
  1089. }
  1090. PmReleaseMemory (g_RasPool, rasEnum->Pattern);
  1091. PmReleaseMemory (g_RasPool, rasEnum);
  1092. ZeroMemory (EnumPtr, sizeof (MIG_TYPEOBJECTENUM));
  1093. }
  1094. BOOL
  1095. AcquireRasConnection (
  1096. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  1097. OUT PMIG_CONTENT ObjectContent, CALLER_INITIALIZED
  1098. IN MIG_CONTENTTYPE ContentType,
  1099. IN UINT MemoryContentLimit
  1100. )
  1101. {
  1102. PTSTR rasLines;
  1103. BOOL result = FALSE;
  1104. if (!ObjectContent) {
  1105. return FALSE;
  1106. }
  1107. if (ContentType == CONTENTTYPE_FILE) {
  1108. // nobody should request this as a file
  1109. MYASSERT (FALSE);
  1110. return FALSE;
  1111. }
  1112. if (HtFindStringEx (g_RasTable, ObjectName, &rasLines, FALSE)) {
  1113. ObjectContent->MemoryContent.ContentBytes = (PCBYTE) rasLines;
  1114. ObjectContent->MemoryContent.ContentSize = SizeOfMultiSz (rasLines);
  1115. result = TRUE;
  1116. }
  1117. return result;
  1118. }
  1119. BOOL
  1120. ReleaseRasConnection (
  1121. IN OUT PMIG_CONTENT ObjectContent
  1122. )
  1123. {
  1124. ZeroMemory (ObjectContent, sizeof (MIG_CONTENT));
  1125. return TRUE;
  1126. }
  1127. BOOL
  1128. pGetNewFileNameAndConnection (
  1129. IN MIG_PLATFORMTYPEID Platform,
  1130. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  1131. OUT PCTSTR *NewPbkFileName,
  1132. OUT PCTSTR *ConnectionName
  1133. )
  1134. {
  1135. PCTSTR node;
  1136. PCTSTR leaf;
  1137. PCTSTR newNode;
  1138. PCTSTR newLeaf;
  1139. PTSTR pbkDir;
  1140. PTSTR pbkFile;
  1141. MIG_OBJECTSTRINGHANDLE pbkObjectName;
  1142. MIG_OBJECTSTRINGHANDLE newPbkObjectName;
  1143. PCTSTR newFileName;
  1144. MIG_OBJECTTYPEID newObjTypeId;
  1145. BOOL deleted;
  1146. BOOL replaced;
  1147. BOOL result = FALSE;
  1148. if (IsmCreateObjectStringsFromHandle (ObjectName, &node, &leaf)) {
  1149. MYASSERT (leaf);
  1150. if (leaf) {
  1151. if (node) {
  1152. pbkDir = (PTSTR) node;
  1153. pbkFile = _tcsrchr (pbkDir, TEXT('\\'));
  1154. if (pbkFile) {
  1155. // we know '\\' is not a multi-byte character so this is safe
  1156. *pbkFile = 0;
  1157. pbkFile ++;
  1158. pbkObjectName = IsmCreateObjectHandle (pbkDir, pbkFile);
  1159. if (pbkObjectName) {
  1160. g_AllowPbkRestore = TRUE;
  1161. newPbkObjectName = IsmFilterObject (
  1162. Platform | g_FileTypeId,
  1163. pbkObjectName,
  1164. &newObjTypeId,
  1165. &deleted,
  1166. &replaced
  1167. );
  1168. g_AllowPbkRestore = FALSE;
  1169. if ((!deleted) || (replaced)) {
  1170. if (IsmCreateObjectStringsFromHandle (newPbkObjectName?newPbkObjectName:pbkObjectName, &newNode, &newLeaf)) {
  1171. MYASSERT (newNode);
  1172. MYASSERT (newLeaf);
  1173. if (newNode && newLeaf) {
  1174. newFileName = JoinPaths (newNode, newLeaf);
  1175. if (NewPbkFileName) {
  1176. *NewPbkFileName = newFileName;
  1177. } else {
  1178. FreePathString (newFileName);
  1179. }
  1180. if (ConnectionName) {
  1181. *ConnectionName = DuplicatePathString (leaf, 0);
  1182. }
  1183. result = TRUE;
  1184. }
  1185. if (newNode) {
  1186. IsmDestroyObjectString (newNode);
  1187. }
  1188. if (newLeaf) {
  1189. IsmDestroyObjectString (newLeaf);
  1190. }
  1191. }
  1192. }
  1193. if (newPbkObjectName) {
  1194. IsmDestroyObjectHandle (newPbkObjectName);
  1195. newPbkObjectName = NULL;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. else {
  1201. if (NewPbkFileName) {
  1202. *NewPbkFileName = NULL;
  1203. }
  1204. if (ConnectionName) {
  1205. *ConnectionName = DuplicatePathString (leaf, 0);
  1206. }
  1207. result = TRUE;
  1208. }
  1209. }
  1210. if (node) {
  1211. IsmDestroyObjectString (node);
  1212. }
  1213. if (leaf) {
  1214. IsmDestroyObjectString (leaf);
  1215. }
  1216. }
  1217. return result;
  1218. }
  1219. BOOL
  1220. DoesRasConnectionExist (
  1221. IN MIG_OBJECTSTRINGHANDLE ObjectName
  1222. )
  1223. {
  1224. PCTSTR newPbkFileName = NULL;
  1225. PCTSTR newConnName = NULL;
  1226. MIG_OBJECTSTRINGHANDLE newObjectName = NULL;
  1227. HASHTABLE rasTable;
  1228. BOOL result = FALSE;
  1229. if (pGetNewFileNameAndConnection (PLATFORM_SOURCE, ObjectName, &newPbkFileName, &newConnName)) {
  1230. if (newPbkFileName && newConnName) {
  1231. newObjectName = IsmCreateObjectHandle (newPbkFileName, newConnName);
  1232. }
  1233. if (newObjectName) {
  1234. rasTable = HtAllocWithData (sizeof (PCTSTR));
  1235. if (rasTable) {
  1236. if (pLoadRasConnections (newPbkFileName, rasTable)) {
  1237. result = (HtFindStringEx (rasTable, newObjectName, NULL, FALSE) != NULL);
  1238. }
  1239. HtFree (rasTable);
  1240. }
  1241. }
  1242. if (newObjectName) {
  1243. IsmDestroyObjectHandle (newObjectName);
  1244. newObjectName = NULL;
  1245. }
  1246. if (newPbkFileName) {
  1247. FreePathString (newPbkFileName);
  1248. newPbkFileName = NULL;
  1249. }
  1250. if (newConnName) {
  1251. FreePathString (newConnName);
  1252. newConnName = NULL;
  1253. }
  1254. }
  1255. return result;
  1256. }
  1257. BOOL
  1258. RemoveRasConnection (
  1259. IN MIG_OBJECTSTRINGHANDLE ObjectName
  1260. )
  1261. {
  1262. PCTSTR node, leaf;
  1263. DWORD err = 0;
  1264. BOOL result = FALSE;
  1265. if (g_RasDeleteEntry) {
  1266. if (IsmCreateObjectStringsFromHandle (ObjectName, &node, &leaf)) {
  1267. MYASSERT (node);
  1268. MYASSERT (leaf);
  1269. if (node && leaf) {
  1270. err = g_RasDeleteEntry (node, leaf);
  1271. if (err = ERROR_SUCCESS) {
  1272. result = TRUE;
  1273. }
  1274. }
  1275. IsmDestroyObjectString (node);
  1276. IsmDestroyObjectString (leaf);
  1277. }
  1278. }
  1279. return result;
  1280. }
  1281. BOOL
  1282. pCopyNewFileLocation (
  1283. OUT PTSTR DestFile,
  1284. IN PCTSTR SrcFile,
  1285. IN UINT Size
  1286. )
  1287. {
  1288. PTSTR node, nodePtr, leaf, result;
  1289. MIG_OBJECTSTRINGHANDLE objectName;
  1290. MIG_OBJECTSTRINGHANDLE newObjectName;
  1291. BOOL deleted;
  1292. BOOL replaced;
  1293. BOOL b = FALSE;
  1294. *DestFile = 0;
  1295. node = PmGetMemory (g_RasPool, Size);
  1296. StringCopyTcharCount (node, SrcFile, Size);
  1297. if (*node) {
  1298. if (_tcsnextc (node) == TEXT('[')) {
  1299. nodePtr = _tcsinc (node);
  1300. } else {
  1301. nodePtr = node;
  1302. }
  1303. leaf = _tcsrchr (nodePtr, TEXT('\\'));
  1304. if (leaf) {
  1305. *leaf = 0;
  1306. leaf++;
  1307. objectName = IsmCreateObjectHandle (nodePtr, leaf);
  1308. PmReleaseMemory (g_RasPool, node);
  1309. newObjectName = IsmFilterObject (
  1310. g_FileTypeId | PLATFORM_SOURCE,
  1311. objectName,
  1312. NULL,
  1313. &deleted,
  1314. &replaced
  1315. );
  1316. if (!deleted || replaced) {
  1317. if (!newObjectName) {
  1318. newObjectName = objectName;
  1319. }
  1320. if (IsmCreateObjectStringsFromHandle (newObjectName, &node, &leaf)) {
  1321. result = JoinPaths (node, leaf);
  1322. StringCopyTcharCount (DestFile, result, Size);
  1323. FreePathString (result);
  1324. b = TRUE;
  1325. }
  1326. }
  1327. if (newObjectName && (newObjectName != objectName)) {
  1328. IsmDestroyObjectHandle (newObjectName);
  1329. }
  1330. IsmDestroyObjectHandle (objectName);
  1331. } else {
  1332. PmReleaseMemory (g_RasPool, node);
  1333. }
  1334. } else {
  1335. PmReleaseMemory (g_RasPool, node);
  1336. }
  1337. return b;
  1338. }
  1339. BOOL
  1340. pTrackedCreateDirectory (
  1341. IN PCTSTR DirName
  1342. )
  1343. {
  1344. MIG_OBJECTSTRINGHANDLE objectName;
  1345. PTSTR pathCopy;
  1346. PTSTR p;
  1347. BOOL result = TRUE;
  1348. pathCopy = DuplicatePathString (DirName, 0);
  1349. //
  1350. // Advance past first directory
  1351. //
  1352. if (pathCopy[1] == TEXT(':') && pathCopy[2] == TEXT('\\')) {
  1353. //
  1354. // <drive>:\ case
  1355. //
  1356. p = _tcschr (&pathCopy[3], TEXT('\\'));
  1357. } else if (pathCopy[0] == TEXT('\\') && pathCopy[1] == TEXT('\\')) {
  1358. //
  1359. // UNC case
  1360. //
  1361. p = _tcschr (pathCopy + 2, TEXT('\\'));
  1362. if (p) {
  1363. p = _tcschr (p + 1, TEXT('\\'));
  1364. }
  1365. } else {
  1366. //
  1367. // Relative dir case
  1368. //
  1369. p = _tcschr (pathCopy, TEXT('\\'));
  1370. }
  1371. //
  1372. // Make all directories along the path
  1373. //
  1374. while (p) {
  1375. *p = 0;
  1376. if (!DoesFileExist (pathCopy)) {
  1377. // record directory creation
  1378. objectName = IsmCreateObjectHandle (pathCopy, NULL);
  1379. IsmRecordOperation (
  1380. JRNOP_CREATE,
  1381. g_FileTypeId,
  1382. objectName
  1383. );
  1384. IsmDestroyObjectHandle (objectName);
  1385. result = CreateDirectory (pathCopy, NULL);
  1386. if (!result) {
  1387. break;
  1388. }
  1389. }
  1390. *p = TEXT('\\');
  1391. p = _tcschr (p + 1, TEXT('\\'));
  1392. }
  1393. FreePathString (pathCopy);
  1394. return result;
  1395. }
  1396. BOOL
  1397. CreateRasConnection (
  1398. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  1399. IN PMIG_CONTENT ObjectContent
  1400. )
  1401. {
  1402. MIG_OBJECTSTRINGHANDLE newObjectName;
  1403. PCTSTR rasLines;
  1404. MULTISZ_ENUM multiSzEnum;
  1405. PCTSTR newPbkFileName = NULL;
  1406. HANDLE newPbkFileHandle = NULL;
  1407. PTSTR node = NULL, leaf = NULL;
  1408. BOOL first = TRUE;
  1409. MIG_OSVERSIONINFO versionInfo;
  1410. BOOL versionOk = FALSE;
  1411. BOOL fileField = FALSE;
  1412. TCHAR destFileName [MAX_PATH];
  1413. RASCREDENTIALS rasCredentials;
  1414. BOOL lastVNEmpty = FALSE;
  1415. BOOL result = FALSE;
  1416. WORD oldCodePage;
  1417. if (ObjectContent->ContentInFile) {
  1418. return FALSE;
  1419. }
  1420. ZeroMemory (&rasCredentials, sizeof (RASCREDENTIALS));
  1421. rasCredentials.dwSize = sizeof (RASCREDENTIALS);
  1422. rasLines = (PCTSTR) ObjectContent->MemoryContent.ContentBytes;
  1423. __try {
  1424. if (!rasLines) {
  1425. __leave;
  1426. }
  1427. if (!pGetNewFileNameAndConnection (PLATFORM_SOURCE, ObjectName, &newPbkFileName, NULL)) {
  1428. __leave;
  1429. }
  1430. MYASSERT (newPbkFileName);
  1431. if (!newPbkFileName) {
  1432. __leave;
  1433. }
  1434. if (!IsmCreateObjectStringsFromHandle (ObjectName, &node, &leaf)) {
  1435. __leave;
  1436. }
  1437. MYASSERT (leaf);
  1438. if (!leaf) {
  1439. __leave;
  1440. }
  1441. newObjectName = IsmCreateObjectHandle (newPbkFileName, leaf);
  1442. // record RAS entry creation
  1443. IsmRecordOperation (
  1444. JRNOP_CREATE,
  1445. g_RasTypeId,
  1446. newObjectName
  1447. );
  1448. IsmDestroyObjectHandle (newObjectName);
  1449. if (EnumFirstMultiSz (&multiSzEnum, rasLines)) {
  1450. // get the first 8 fields as being part of rasCredentials structure
  1451. MYASSERT (StringIMatch (multiSzEnum.CurrentString, TEXT("ConnectionName")));
  1452. if (!EnumNextMultiSz (&multiSzEnum)) {
  1453. __leave;
  1454. }
  1455. // we are just skipping the connection name
  1456. if (!EnumNextMultiSz (&multiSzEnum)) {
  1457. __leave;
  1458. }
  1459. MYASSERT (StringIMatch (multiSzEnum.CurrentString, TEXT("CredMask")));
  1460. if (!EnumNextMultiSz (&multiSzEnum)) {
  1461. __leave;
  1462. }
  1463. if (!StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1464. _stscanf (multiSzEnum.CurrentString, TEXT("%lx"), &(rasCredentials.dwMask));
  1465. }
  1466. if (!EnumNextMultiSz (&multiSzEnum)) {
  1467. __leave;
  1468. }
  1469. MYASSERT (StringIMatch (multiSzEnum.CurrentString, TEXT("CredName")));
  1470. if (!EnumNextMultiSz (&multiSzEnum)) {
  1471. __leave;
  1472. }
  1473. if (!StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1474. StringCopyTcharCount (rasCredentials.szUserName, multiSzEnum.CurrentString, UNLEN + 1);
  1475. }
  1476. if (!EnumNextMultiSz (&multiSzEnum)) {
  1477. __leave;
  1478. }
  1479. MYASSERT (StringIMatch (multiSzEnum.CurrentString, TEXT("CredDomain")));
  1480. if (!EnumNextMultiSz (&multiSzEnum)) {
  1481. __leave;
  1482. }
  1483. if (!StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1484. StringCopyTcharCount (rasCredentials.szDomain, multiSzEnum.CurrentString, DNLEN + 1);
  1485. }
  1486. if (!EnumNextMultiSz (&multiSzEnum)) {
  1487. __leave;
  1488. }
  1489. MYASSERT (StringIMatch (multiSzEnum.CurrentString, TEXT("CredPassword")));
  1490. if (!EnumNextMultiSz (&multiSzEnum)) {
  1491. __leave;
  1492. }
  1493. if (!StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1494. StringCopyTcharCount (rasCredentials.szPassword, multiSzEnum.CurrentString, PWLEN + 1);
  1495. }
  1496. if (!EnumNextMultiSz (&multiSzEnum)) {
  1497. __leave;
  1498. }
  1499. newPbkFileHandle = BfOpenFile (newPbkFileName);
  1500. if (!newPbkFileHandle) {
  1501. pTrackedCreateDirectory (newPbkFileName);
  1502. newPbkFileHandle = BfCreateFile (newPbkFileName);
  1503. }
  1504. if (!newPbkFileHandle) {
  1505. __leave;
  1506. }
  1507. BfGoToEndOfFile (newPbkFileHandle, NULL);
  1508. WriteFileString (newPbkFileHandle, TEXT("\r\n["));
  1509. // make sure that the conversion is using UTF8
  1510. oldCodePage = SetConversionCodePage (CP_UTF8);
  1511. WriteFileString (newPbkFileHandle, leaf);
  1512. SetConversionCodePage (oldCodePage);
  1513. WriteFileString (newPbkFileHandle, TEXT("]\r\n"));
  1514. first = TRUE;
  1515. versionOk = IsmGetOsVersionInfo (PLATFORM_SOURCE, &versionInfo);
  1516. do {
  1517. if (first) {
  1518. if (StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1519. lastVNEmpty = TRUE;
  1520. } else {
  1521. lastVNEmpty = FALSE;
  1522. if (versionOk) {
  1523. if (versionInfo.OsType == OSTYPE_WINDOWSNT) {
  1524. if (versionInfo.OsMajorVersion == OSMAJOR_WINNT4) {
  1525. fileField = StringIMatch (multiSzEnum.CurrentString, TEXT("Type"));
  1526. }
  1527. if (versionInfo.OsMajorVersion == OSMAJOR_WINNT5) {
  1528. fileField = StringIMatch (multiSzEnum.CurrentString, TEXT("Name"));
  1529. }
  1530. }
  1531. if (versionInfo.OsType == OSTYPE_WINDOWS9X) {
  1532. fileField = StringIMatch (multiSzEnum.CurrentString, TEXT("Name"));
  1533. }
  1534. }
  1535. fileField = fileField || StringIMatch (multiSzEnum.CurrentString, TEXT("CustomDialDll"));
  1536. fileField = fileField || StringIMatch (multiSzEnum.CurrentString, TEXT("CustomRasDialDll"));
  1537. fileField = fileField || StringIMatch (multiSzEnum.CurrentString, TEXT("PrerequisitePbk"));
  1538. WriteFileString (newPbkFileHandle, multiSzEnum.CurrentString);
  1539. }
  1540. } else {
  1541. if (StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1542. if (!lastVNEmpty) {
  1543. WriteFileString (newPbkFileHandle, TEXT("="));
  1544. }
  1545. WriteFileString (newPbkFileHandle, TEXT("\r\n"));
  1546. } else {
  1547. WriteFileString (newPbkFileHandle, TEXT("="));
  1548. if (fileField && pCopyNewFileLocation (destFileName, multiSzEnum.CurrentString, MAX_PATH)) {
  1549. // make sure that the conversion is using UTF8
  1550. oldCodePage = SetConversionCodePage (CP_UTF8);
  1551. WriteFileString (newPbkFileHandle, destFileName);
  1552. SetConversionCodePage (oldCodePage);
  1553. } else {
  1554. // make sure that the conversion is using UTF8
  1555. oldCodePage = SetConversionCodePage (CP_UTF8);
  1556. WriteFileString (newPbkFileHandle, multiSzEnum.CurrentString);
  1557. oldCodePage = SetConversionCodePage (oldCodePage);
  1558. }
  1559. WriteFileString (newPbkFileHandle, TEXT("\r\n"));
  1560. }
  1561. fileField = FALSE;
  1562. }
  1563. first = !first;
  1564. } while (EnumNextMultiSz (&multiSzEnum));
  1565. WriteFileString (newPbkFileHandle, TEXT("\r\n"));
  1566. result = TRUE;
  1567. }
  1568. }
  1569. __finally {
  1570. IsmDestroyObjectString (node);
  1571. IsmDestroyObjectString (leaf);
  1572. if (newPbkFileHandle) {
  1573. CloseHandle (newPbkFileHandle);
  1574. newPbkFileHandle = NULL;
  1575. }
  1576. if (result) {
  1577. if (g_RasSetCredentials && rasCredentials.dwMask) {
  1578. g_RasSetCredentials (newPbkFileName, leaf, &rasCredentials, FALSE);
  1579. }
  1580. }
  1581. if (newPbkFileName) {
  1582. FreePathString (newPbkFileName);
  1583. newPbkFileName = NULL;
  1584. }
  1585. }
  1586. return result;
  1587. }
  1588. PCTSTR
  1589. ConvertRasConnectionToMultiSz (
  1590. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  1591. IN PMIG_CONTENT ObjectContent
  1592. )
  1593. {
  1594. PCTSTR node, leaf;
  1595. PTSTR result = NULL;
  1596. BOOL bresult = TRUE;
  1597. PCTSTR rasLines;
  1598. MULTISZ_ENUM multiSzEnum;
  1599. if (IsmCreateObjectStringsFromHandle (ObjectName, &node, &leaf)) {
  1600. MYASSERT (leaf);
  1601. g_RasConversionBuff.End = 0;
  1602. if (node) {
  1603. GbCopyQuotedString (&g_RasConversionBuff, node);
  1604. } else {
  1605. GbCopyQuotedString (&g_RasConversionBuff, TEXT(""));
  1606. }
  1607. GbCopyQuotedString (&g_RasConversionBuff, leaf);
  1608. MYASSERT (ObjectContent->Details.DetailsSize == 0);
  1609. MYASSERT (!ObjectContent->ContentInFile);
  1610. if ((!ObjectContent->ContentInFile) &&
  1611. (ObjectContent->MemoryContent.ContentSize) &&
  1612. (ObjectContent->MemoryContent.ContentBytes)
  1613. ) {
  1614. rasLines = (PCTSTR)ObjectContent->MemoryContent.ContentBytes;
  1615. if (EnumFirstMultiSz (&multiSzEnum, rasLines)) {
  1616. do {
  1617. if (StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1618. GbCopyQuotedString (&g_RasConversionBuff, TEXT(""));
  1619. } else {
  1620. GbCopyQuotedString (&g_RasConversionBuff, multiSzEnum.CurrentString);
  1621. }
  1622. } while (EnumNextMultiSz (&multiSzEnum));
  1623. }
  1624. } else {
  1625. bresult = FALSE;
  1626. }
  1627. if (bresult) {
  1628. GbCopyString (&g_RasConversionBuff, TEXT(""));
  1629. result = IsmGetMemory (g_RasConversionBuff.End);
  1630. CopyMemory (result, g_RasConversionBuff.Buf, g_RasConversionBuff.End);
  1631. }
  1632. g_RasConversionBuff.End = 0;
  1633. IsmDestroyObjectString (node);
  1634. IsmDestroyObjectString (leaf);
  1635. }
  1636. return result;
  1637. }
  1638. BOOL
  1639. ConvertMultiSzToRasConnection (
  1640. IN PCTSTR ObjectMultiSz,
  1641. OUT MIG_OBJECTSTRINGHANDLE *ObjectName,
  1642. OUT PMIG_CONTENT ObjectContent OPTIONAL
  1643. )
  1644. {
  1645. MULTISZ_ENUM multiSzEnum;
  1646. PCTSTR node = NULL;
  1647. PCTSTR leaf = NULL;
  1648. UINT index;
  1649. g_RasConversionBuff.End = 0;
  1650. if (ObjectContent) {
  1651. ZeroMemory (ObjectContent, sizeof (MIG_CONTENT));
  1652. }
  1653. if (EnumFirstMultiSz (&multiSzEnum, ObjectMultiSz)) {
  1654. index = 0;
  1655. do {
  1656. if (index == 0) {
  1657. if (!StringIMatch (multiSzEnum.CurrentString, TEXT("<empty>"))) {
  1658. node = multiSzEnum.CurrentString;
  1659. }
  1660. }
  1661. if (index == 1) {
  1662. leaf = multiSzEnum.CurrentString;
  1663. }
  1664. if (index > 1) {
  1665. if (*multiSzEnum.CurrentString) {
  1666. GbMultiSzAppend (&g_RasConversionBuff, multiSzEnum.CurrentString);
  1667. } else {
  1668. GbMultiSzAppend (&g_RasConversionBuff, TEXT("<empty>"));
  1669. }
  1670. }
  1671. index ++;
  1672. } while (EnumNextMultiSz (&multiSzEnum));
  1673. }
  1674. GbMultiSzAppend (&g_RasConversionBuff, TEXT(""));
  1675. if (!leaf) {
  1676. GbFree (&g_RasConversionBuff);
  1677. return FALSE;
  1678. }
  1679. if (ObjectContent) {
  1680. if (g_RasConversionBuff.End) {
  1681. ObjectContent->MemoryContent.ContentSize = g_RasConversionBuff.End;
  1682. ObjectContent->MemoryContent.ContentBytes = IsmGetMemory (ObjectContent->MemoryContent.ContentSize);
  1683. CopyMemory (
  1684. (PBYTE)ObjectContent->MemoryContent.ContentBytes,
  1685. g_RasConversionBuff.Buf,
  1686. ObjectContent->MemoryContent.ContentSize
  1687. );
  1688. } else {
  1689. ObjectContent->MemoryContent.ContentSize = 0;
  1690. ObjectContent->MemoryContent.ContentBytes = NULL;
  1691. }
  1692. ObjectContent->Details.DetailsSize = 0;
  1693. ObjectContent->Details.DetailsData = NULL;
  1694. }
  1695. *ObjectName = IsmCreateObjectHandle (node, leaf);
  1696. GbFree (&g_RasConversionBuff);
  1697. return TRUE;
  1698. }
  1699. PCTSTR
  1700. GetNativeRasConnectionName (
  1701. IN MIG_OBJECTSTRINGHANDLE ObjectName
  1702. )
  1703. {
  1704. PCTSTR node = NULL, leaf = NULL;
  1705. UINT size;
  1706. PTSTR result = NULL;
  1707. if (IsmCreateObjectStringsFromHandle (ObjectName, &node, &leaf)) {
  1708. if (leaf) {
  1709. size = SizeOfString (leaf);
  1710. if (size) {
  1711. result = IsmGetMemory (size);
  1712. CopyMemory (result, leaf, size);
  1713. }
  1714. }
  1715. IsmDestroyObjectString (node);
  1716. IsmDestroyObjectString (leaf);
  1717. }
  1718. return result;
  1719. }
  1720. PMIG_CONTENT
  1721. ConvertRasConnectionContentToUnicode (
  1722. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  1723. IN PMIG_CONTENT ObjectContent
  1724. )
  1725. {
  1726. PMIG_CONTENT result = NULL;
  1727. if (!ObjectContent) {
  1728. return result;
  1729. }
  1730. if (ObjectContent->ContentInFile) {
  1731. return result;
  1732. }
  1733. result = IsmGetMemory (sizeof (MIG_CONTENT));
  1734. if (result) {
  1735. CopyMemory (result, ObjectContent, sizeof (MIG_CONTENT));
  1736. if ((ObjectContent->MemoryContent.ContentSize != 0) &&
  1737. (ObjectContent->MemoryContent.ContentBytes != NULL)
  1738. ) {
  1739. // convert Ras Connection content
  1740. result->MemoryContent.ContentBytes = IsmGetMemory (ObjectContent->MemoryContent.ContentSize * 2);
  1741. if (result->MemoryContent.ContentBytes) {
  1742. DirectDbcsToUnicodeN (
  1743. (PWSTR)result->MemoryContent.ContentBytes,
  1744. (PSTR)ObjectContent->MemoryContent.ContentBytes,
  1745. ObjectContent->MemoryContent.ContentSize
  1746. );
  1747. result->MemoryContent.ContentSize = SizeOfMultiSzW ((PWSTR)result->MemoryContent.ContentBytes);
  1748. }
  1749. }
  1750. }
  1751. return result;
  1752. }
  1753. PMIG_CONTENT
  1754. ConvertRasConnectionContentToAnsi (
  1755. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  1756. IN PMIG_CONTENT ObjectContent
  1757. )
  1758. {
  1759. PMIG_CONTENT result = NULL;
  1760. if (!ObjectContent) {
  1761. return result;
  1762. }
  1763. if (ObjectContent->ContentInFile) {
  1764. return result;
  1765. }
  1766. result = IsmGetMemory (sizeof (MIG_CONTENT));
  1767. if (result) {
  1768. CopyMemory (result, ObjectContent, sizeof (MIG_CONTENT));
  1769. if ((ObjectContent->MemoryContent.ContentSize != 0) &&
  1770. (ObjectContent->MemoryContent.ContentBytes != NULL)
  1771. ) {
  1772. // convert Ras Connection content
  1773. result->MemoryContent.ContentBytes = IsmGetMemory (ObjectContent->MemoryContent.ContentSize);
  1774. if (result->MemoryContent.ContentBytes) {
  1775. DirectUnicodeToDbcsN (
  1776. (PSTR)result->MemoryContent.ContentBytes,
  1777. (PWSTR)ObjectContent->MemoryContent.ContentBytes,
  1778. ObjectContent->MemoryContent.ContentSize
  1779. );
  1780. result->MemoryContent.ContentSize = SizeOfMultiSzA ((PSTR)result->MemoryContent.ContentBytes);
  1781. }
  1782. }
  1783. }
  1784. return result;
  1785. }
  1786. BOOL
  1787. FreeConvertedRasConnectionContent (
  1788. IN PMIG_CONTENT ObjectContent
  1789. )
  1790. {
  1791. if (!ObjectContent) {
  1792. return TRUE;
  1793. }
  1794. if (ObjectContent->MemoryContent.ContentBytes) {
  1795. IsmReleaseMemory (ObjectContent->MemoryContent.ContentBytes);
  1796. }
  1797. IsmReleaseMemory (ObjectContent);
  1798. return TRUE;
  1799. }
  1800. //
  1801. // Win9x specific code. Converts registry format into a PBK file
  1802. //
  1803. //
  1804. // AddrEntry serves as a header for the entire block of data in the <entry>
  1805. // blob. entries in it are offsets to the strings which follow it..in many cases
  1806. // (i.e. all of the *Off* members...)
  1807. //
  1808. typedef struct _AddrEntry {
  1809. DWORD dwVersion;
  1810. DWORD dwCountryCode;
  1811. UINT uOffArea;
  1812. UINT uOffPhone;
  1813. DWORD dwCountryID;
  1814. UINT uOffSMMCfg;
  1815. UINT uOffSMM;
  1816. UINT uOffDI;
  1817. } ADDRENTRY, *PADDRENTRY;
  1818. typedef struct {
  1819. DWORD Size;
  1820. DWORD Unknown1;
  1821. DWORD ModemUiOptions; // num seconds in high byte.
  1822. DWORD Unknown2;
  1823. DWORD Unknown3;
  1824. DWORD Unknown4;
  1825. DWORD ConnectionSpeed;
  1826. DWORD UnknownFlowControlData; //Somehow related to flow control.
  1827. DWORD Unknown5;
  1828. DWORD Unknown6;
  1829. DWORD Unknown7;
  1830. DWORD Unknown8;
  1831. DWORD Unknown9;
  1832. DWORD Unknown10;
  1833. DWORD Unknown11;
  1834. DWORD Unknown12;
  1835. DWORD Unknown13;
  1836. DWORD Unknown14;
  1837. DWORD Unknown15;
  1838. DWORD CancelSeconds; //Num seconds to wait before cancel if not connected. (0xFF equals off.)
  1839. DWORD IdleDisconnectSeconds; // 0 = Not Set.
  1840. DWORD Unknown16;
  1841. DWORD SpeakerVolume; // 0|1
  1842. DWORD ConfigOptions;
  1843. DWORD Unknown17;
  1844. DWORD Unknown18;
  1845. DWORD Unknown19;
  1846. } MODEMDEVINFO, *PMODEMDEVINFO;
  1847. typedef struct _SubConnEntry {
  1848. DWORD dwSize;
  1849. DWORD dwFlags;
  1850. CHAR szDeviceType[RAS_MaxDeviceType+1];
  1851. CHAR szDeviceName[RAS_MaxDeviceName+1];
  1852. CHAR szLocal[RAS_MaxPhoneNumber+1];
  1853. } SUBCONNENTRY, *PSUBCONNENTRY;
  1854. typedef struct _SMMCFG {
  1855. DWORD dwSize;
  1856. DWORD fdwOptions;
  1857. DWORD fdwProtocols;
  1858. } SMMCFG, *PSMMCFG;
  1859. typedef struct _DEVICEINFO {
  1860. DWORD dwVersion;
  1861. UINT uSize;
  1862. CHAR szDeviceName[RAS_MaxDeviceName+1];
  1863. CHAR szDeviceType[RAS_MaxDeviceType+1];
  1864. } DEVICEINFO, *PDEVICEINFO;
  1865. typedef struct _IPData {
  1866. DWORD dwSize;
  1867. DWORD fdwTCPIP;
  1868. DWORD dwIPAddr;
  1869. DWORD dwDNSAddr;
  1870. DWORD dwDNSAddrAlt;
  1871. DWORD dwWINSAddr;
  1872. DWORD dwWINSAddrAlt;
  1873. } IPDATA, *PIPDATA;
  1874. typedef struct {
  1875. PCTSTR String;
  1876. UINT Value;
  1877. WORD DataType;
  1878. } MEMDB_RAS_DATA, *PMEMDB_RAS_DATA;
  1879. #define PAESMMCFG(pAE) ((PSMMCFG)(((PBYTE)pAE)+(pAE->uOffSMMCfg)))
  1880. #define PAESMM(pAE) ((PSTR)(((PBYTE)pAE)+(pAE->uOffSMM)))
  1881. #define PAEDI(pAE) ((PDEVICEINFO)(((PBYTE)pAE)+(pAE->uOffDI )))
  1882. #define PAEAREA(pAE) ((PSTR)(((PBYTE)pAE)+(pAE->uOffArea)))
  1883. #define PAEPHONE(pAE) ((PSTR)(((PBYTE)pAE)+(pAE->uOffPhone)))
  1884. #define DECRYPTENTRY(x, y, z) EnDecryptEntry(x, (LPBYTE)y, z)
  1885. #define S_REMOTE_ACCESS_KEY TEXT("HKCU\\RemoteAccess")
  1886. #define S_DIALUI TEXT("DialUI")
  1887. #define S_ENABLE_REDIAL TEXT("EnableRedial")
  1888. #define S_REDIAL_TRY TEXT("RedialTry")
  1889. #define S_REDIAL_WAIT TEXT("RedialWait")
  1890. #define S_ENABLE_IMPLICIT TEXT("EnableImplicit")
  1891. #define S_PHONE_NUMBER TEXT("Phone Number")
  1892. #define S_AREA_CODE TEXT("Area Code")
  1893. #define S_SMM TEXT("SMM")
  1894. #define S_COUNTRY_CODE TEXT("Country Code")
  1895. #define S_COUNTRY_ID TEXT("Country Id")
  1896. #define S_DEVICE_NAME TEXT("Device Name")
  1897. #define S_DEVICE_TYPE TEXT("Device Type")
  1898. #define S_PROTOCOLS TEXT("Protocols")
  1899. #define S_SMM_OPTIONS TEXT("SMM Options")
  1900. #define S_IPINFO TEXT("IP")
  1901. #define S_IP_FTCPIP TEXT("_IP_FTCPIP")
  1902. #define S_IP_IPADDR TEXT("IpAddress")
  1903. #define S_IP_DNSADDR TEXT("IpDnsAddress")
  1904. #define S_IP_DNSADDR2 TEXT("IpDns2Address")
  1905. #define S_IP_WINSADDR TEXT("IpWinsAddress")
  1906. #define S_IP_WINSADDR2 TEXT("IpWins2Address")
  1907. #define S_DOMAIN TEXT("Domain")
  1908. #define S_USER TEXT("User")
  1909. #define S_MODEMS TEXT("HKLM\\System\\CurrentControlSet\\Services\\Class\\Modem")
  1910. #define S_ATTACHEDTO TEXT("AttachedTo")
  1911. #define S_DRIVERDESC TEXT("DriverDesc")
  1912. #define S_TERMINAL TEXT("Terminal")
  1913. #define S_MODE TEXT("Mode")
  1914. #define S_MULTILINK TEXT("MultiLink")
  1915. #define S_MODEM TEXT("Modem")
  1916. #define S_MODEMA "Modem"
  1917. #define S_MODEM_UI_OPTIONS TEXT("__UiOptions")
  1918. #define S_MODEM_SPEED TEXT("__Speed")
  1919. #define S_MODEM_SPEAKER_VOLUME TEXT("__SpeakerVolume")
  1920. #define S_MODEM_IDLE_DISCONNECT_SECONDS TEXT("__IdleDisconnect")
  1921. #define S_MODEM_CANCEL_SECONDS TEXT("__CancelSeconds")
  1922. #define S_MODEM_CFG_OPTIONS TEXT("__CfgOptions")
  1923. #define S_MODEM_COM_PORT TEXT("ComPort")
  1924. #define S_DEVICECOUNT TEXT("__DeviceCount")
  1925. #define S_PPP TEXT("PPP")
  1926. #define S_PPPA "PPP"
  1927. #define S_SLIP TEXT("Slip")
  1928. #define S_SLIPA "Slip"
  1929. #define S_CSLIP TEXT("CSlip")
  1930. #define S_CSLIPA "CSlip"
  1931. #define S_SERVICEREMOTEACCESS TEXT("HKLM\\System\\CurrentControlSet\\Services\\RemoteAccess")
  1932. #define S_REMOTE_ACCESS_KEY TEXT("HKCU\\RemoteAccess")
  1933. #define S_PROFILE_KEY TEXT("HKCU\\RemoteAccess\\Profile")
  1934. #define S_ADDRESSES_KEY TEXT("HKCU\\RemoteAccess\\Addresses")
  1935. #define S_SUBENTRIES TEXT("SubEntries")
  1936. #define S_EMPTY TEXT("")
  1937. #define S_PPPSCRIPT TEXT("PPPSCRIPT")
  1938. #define MEMDB_CATEGORY_RAS_INFO TEXT("RAS Info")
  1939. #define MEMDB_CATEGORY_RAS_USER TEXT("RAS User")
  1940. #define MEMDB_CATEGORY_RAS_DATA TEXT("Ras Data")
  1941. #define MEMDB_FIELD_USER_SETTINGS TEXT("User Settings")
  1942. #define RASTYPE_PHONE 1
  1943. #define RASTYPE_VPN 2
  1944. #define S_VPN TEXT("VPN")
  1945. #define S_ZERO TEXT("0")
  1946. #define S_ONE TEXT("1")
  1947. #define SMMCFG_SW_COMPRESSION 0x00000001 // Software compression is on
  1948. #define SMMCFG_PW_ENCRYPTED 0x00000002 // Encrypted password only
  1949. #define SMMCFG_NW_LOGON 0x00000004 // Logon to the network
  1950. // Negotiated protocols
  1951. //
  1952. #define SMMPROT_NB 0x00000001 // NetBEUI
  1953. #define SMMPROT_IPX 0x00000002 // IPX
  1954. #define SMMPROT_IP 0x00000004 // TCP/IP
  1955. #define IPF_IP_SPECIFIED 0x00000001
  1956. #define IPF_NAME_SPECIFIED 0x00000002
  1957. #define IPF_NO_COMPRESS 0x00000004
  1958. #define IPF_NO_WAN_PRI 0x00000008
  1959. #define RAS_UI_FLAG_TERMBEFOREDIAL 0x1
  1960. #define RAS_UI_FLAG_TERMAFTERDIAL 0x2
  1961. #define RAS_UI_FLAG_OPERATORASSISTED 0x4
  1962. #define RAS_UI_FLAG_MODEMSTATUS 0x8
  1963. #define RAS_CFG_FLAG_HARDWARE_FLOW_CONTROL 0x00000010
  1964. #define RAS_CFG_FLAG_SOFTWARE_FLOW_CONTROL 0x00000020
  1965. #define RAS_CFG_FLAG_STANDARD_EMULATION 0x00000040
  1966. #define RAS_CFG_FLAG_COMPRESS_DATA 0x00000001
  1967. #define RAS_CFG_FLAG_USE_ERROR_CONTROL 0x00000002
  1968. #define RAS_CFG_FLAG_ERROR_CONTROL_REQUIRED 0x00000004
  1969. #define RAS_CFG_FLAG_USE_CELLULAR_PROTOCOL 0x00000008
  1970. #define RAS_CFG_FLAG_NO_WAIT_FOR_DIALTONE 0x00000200
  1971. #define DIALUI_DONT_PROMPT_FOR_INFO 0x01
  1972. #define DIALUI_DONT_SHOW_ICON 0x04
  1973. //
  1974. // For each entry, the following basic information is stored.
  1975. //
  1976. #define ENTRY_SETTINGS \
  1977. FUNSETTING(CredMask) \
  1978. FUNSETTING(CredName) \
  1979. FUNSETTING(CredDomain) \
  1980. FUNSETTING(CredPassword) \
  1981. STRSETTING(Encoding,S_ONE) \
  1982. FUNSETTING(Type) \
  1983. STRSETTING(Autologon,S_ZERO) \
  1984. STRSETTING(DialParamsUID,S_EMPTY) \
  1985. STRSETTING(Guid,S_EMPTY) \
  1986. STRSETTING(UsePwForNetwork,S_EMPTY) \
  1987. STRSETTING(ServerType,S_EMPTY) \
  1988. FUNSETTING(BaseProtocol) \
  1989. FUNSETTING(VpnStrategy) \
  1990. STRSETTING(Authentication,S_EMPTY) \
  1991. FUNSETTING(ExcludedProtocols) \
  1992. STRSETTING(LcpExtensions,S_ONE) \
  1993. FUNSETTING(DataEncryption) \
  1994. STRSETTING(SkipNwcWarning,S_EMPTY) \
  1995. STRSETTING(SkipDownLevelDialog,S_EMPTY) \
  1996. FUNSETTING(SwCompression) \
  1997. FUNSETTING(ShowMonitorIconInTaskBar) \
  1998. STRSETTING(CustomAuthKey,S_EMPTY) \
  1999. STRSETTING(CustomAuthData,S_EMPTY) \
  2000. FUNSETTING(AuthRestrictions) \
  2001. STRSETTING(OverridePref,TEXT("15")) \
  2002. STRSETTING(DialMode,S_EMPTY) \
  2003. STRSETTING(DialPercent,S_EMPTY) \
  2004. STRSETTING(DialSeconds,S_EMPTY) \
  2005. STRSETTING(HangUpPercent,S_EMPTY) \
  2006. STRSETTING(HangUpSeconds,S_EMPTY) \
  2007. FUNSETTING(RedialAttempts) \
  2008. FUNSETTING(RedialSeconds) \
  2009. FUNSETTING(IdleDisconnectSeconds) \
  2010. STRSETTING(RedialOnLinkFailure,S_EMPTY) \
  2011. STRSETTING(CallBackMode,S_EMPTY) \
  2012. STRSETTING(CustomDialDll,S_EMPTY) \
  2013. STRSETTING(CustomDialFunc,S_EMPTY) \
  2014. STRSETTING(AuthenticateServer,S_EMPTY) \
  2015. STRSETTING(SecureLocalFiels,S_EMPTY) \
  2016. STRSETTING(ShareMsFilePrint,S_EMPTY) \
  2017. STRSETTING(BindMsNetClient,S_EMPTY) \
  2018. STRSETTING(SharedPhoneNumbers,S_EMPTY) \
  2019. STRSETTING(PrerequisiteEntry,S_EMPTY) \
  2020. FUNSETTING(PreviewUserPw) \
  2021. FUNSETTING(PreviewDomain) \
  2022. FUNSETTING(PreviewPhoneNumber) \
  2023. STRSETTING(ShowDialingProgress,S_ONE) \
  2024. FUNSETTING(IpPrioritizeRemote) \
  2025. FUNSETTING(IpHeaderCompression) \
  2026. FUNSETTING(IpAddress) \
  2027. FUNSETTING(IpAssign) \
  2028. FUNSETTING(IpDnsAddress) \
  2029. FUNSETTING(IpDns2Address) \
  2030. FUNSETTING(IpWINSAddress) \
  2031. FUNSETTING(IpWINS2Address) \
  2032. FUNSETTING(IpNameAssign) \
  2033. STRSETTING(IpFrameSize,S_EMPTY) \
  2034. //
  2035. // There can be multiple media sections for each entry.
  2036. //
  2037. #define MEDIA_SETTINGS \
  2038. FUNSETTING(MEDIA) \
  2039. FUNSETTING(Port) \
  2040. FUNSETTING(Device) \
  2041. FUNSETTING(ConnectBps) \
  2042. //
  2043. // There can be multiple device sections for each entry.
  2044. //
  2045. #define SWITCH_DEVICE_SETTINGS \
  2046. FUNSETTING(DEVICE) \
  2047. FUNSETTING(Name) \
  2048. FUNSETTING(Terminal) \
  2049. FUNSETTING(Script) \
  2050. #define MODEM_DEVICE_SETTINGS \
  2051. FUNSETTING(DEVICE) \
  2052. FUNSETTING(PhoneNumber) \
  2053. FUNSETTING(AreaCode) \
  2054. FUNSETTING(CountryCode) \
  2055. FUNSETTING(CountryID) \
  2056. FUNSETTING(UseDialingRules) \
  2057. STRSETTING(Comment,S_EMPTY) \
  2058. STRSETTING(LastSelectedPhone,S_EMPTY) \
  2059. STRSETTING(PromoteAlternates,S_EMPTY) \
  2060. STRSETTING(TryNextAlternateOnFail,S_EMPTY) \
  2061. FUNSETTING(HwFlowControl) \
  2062. FUNSETTING(Protocol) \
  2063. FUNSETTING(Compression) \
  2064. FUNSETTING(Speaker) \
  2065. #define PAD_DEVICE_SETTINGS \
  2066. STRSETTING(X25Pad,S_EMPTY) \
  2067. STRSETTING(X25Address,S_EMPTY) \
  2068. STRSETTING(UserData,S_EMPTY) \
  2069. STRSETTING(Facilities,S_EMPTY) \
  2070. #define ISDN_DEVICE_SETTINGS \
  2071. FUNSETTING(PhoneNumber) \
  2072. FUNSETTING(AreaCode) \
  2073. FUNSETTING(CountryCode) \
  2074. FUNSETTING(CountryID) \
  2075. FUNSETTING(UseDialingRules) \
  2076. STRSETTING(Comment,S_EMPTY) \
  2077. STRSETTING(LastSelectedPhone,S_EMPTY) \
  2078. STRSETTING(PromoteAlternates,S_EMPTY) \
  2079. STRSETTING(TryNextAlternateOnFail,S_EMPTY) \
  2080. STRSETTING(LineType,S_EMPTY) \
  2081. STRSETTING(FallBack,S_EMPTY) \
  2082. STRSETTING(EnableCompressiong,S_EMPTY) \
  2083. STRSETTING(ChannelAggregation,S_EMPTY) \
  2084. #define X25_DEVICE_SETTINGS \
  2085. STRSETTING(X25Address,S_EMPTY) \
  2086. STRSETTING(UserData,S_EMPTY) \
  2087. STRSETTING(Facilities,S_EMPTY) \
  2088. //
  2089. // Function prototypes.
  2090. //
  2091. typedef PCTSTR (DATA_FUNCTION_PROTOTYPE)(VOID);
  2092. typedef DATA_FUNCTION_PROTOTYPE * DATA_FUNCTION;
  2093. #define FUNSETTING(Data) DATA_FUNCTION_PROTOTYPE pGet##Data;
  2094. #define STRSETTING(x,y)
  2095. ENTRY_SETTINGS
  2096. MEDIA_SETTINGS
  2097. SWITCH_DEVICE_SETTINGS
  2098. MODEM_DEVICE_SETTINGS
  2099. PAD_DEVICE_SETTINGS
  2100. ISDN_DEVICE_SETTINGS
  2101. X25_DEVICE_SETTINGS
  2102. #undef FUNSETTING
  2103. #undef STRSETTING
  2104. #define FUNSETTING(x) {TEXT(#x), pGet##x, NULL},
  2105. #define STRSETTING(x,y) {TEXT(#x), NULL, y},
  2106. #define LASTSETTING {NULL,NULL,NULL}
  2107. typedef struct {
  2108. PCTSTR SettingName;
  2109. DATA_FUNCTION SettingFunction;
  2110. PCTSTR SettingValue;
  2111. } RAS_SETTING, * PRAS_SETTING;
  2112. RAS_SETTING g_EntrySettings[] = {ENTRY_SETTINGS LASTSETTING};
  2113. RAS_SETTING g_MediaSettings[] = {MEDIA_SETTINGS LASTSETTING};
  2114. RAS_SETTING g_SwitchDeviceSettings[] = {SWITCH_DEVICE_SETTINGS LASTSETTING};
  2115. RAS_SETTING g_ModemDeviceSettings[] = {MODEM_DEVICE_SETTINGS LASTSETTING};
  2116. RAS_SETTING g_PadDeviceSettings[] = {PAD_DEVICE_SETTINGS LASTSETTING};
  2117. RAS_SETTING g_IsdnDeviceSettings[] = {ISDN_DEVICE_SETTINGS LASTSETTING};
  2118. RAS_SETTING g_X25DeviceSettings[] = {X25_DEVICE_SETTINGS LASTSETTING};
  2119. BOOL g_InSwitchSection = FALSE;
  2120. PCTSTR g_CurrentConnection = NULL;
  2121. UINT g_CurrentDevice = 0;
  2122. UINT g_CurrentDeviceType = 0;
  2123. #define RAS_BUFFER_SIZE MEMDB_MAX
  2124. TCHAR g_TempBuffer [RAS_BUFFER_SIZE];
  2125. HASHTABLE g_DeviceTable = NULL;
  2126. BOOL
  2127. pIs9xRasInstalled (
  2128. void
  2129. )
  2130. {
  2131. HKEY testKey = NULL;
  2132. BOOL rf = FALSE;
  2133. testKey = OpenRegKeyStr (S_SERVICEREMOTEACCESS);
  2134. if (testKey) {
  2135. //
  2136. // Open key succeeded. Assume RAS is installed.
  2137. //
  2138. rf = TRUE;
  2139. CloseRegKey(testKey);
  2140. }
  2141. return rf;
  2142. }
  2143. static BYTE NEAR PASCAL GenerateEncryptKey (LPCSTR szKey)
  2144. {
  2145. BYTE bKey;
  2146. LPBYTE lpKey;
  2147. for (bKey = 0, lpKey = (LPBYTE)szKey; *lpKey != 0; lpKey++)
  2148. {
  2149. bKey += *lpKey;
  2150. };
  2151. return bKey;
  2152. }
  2153. DWORD NEAR PASCAL EnDecryptEntry (LPCSTR szEntry, LPBYTE lpEnt,
  2154. DWORD cb)
  2155. {
  2156. BYTE bKey;
  2157. // Generate the encryption key from the entry name
  2158. bKey = GenerateEncryptKey(szEntry);
  2159. // Encrypt the address entry one byte at a time
  2160. for (;cb > 0; cb--, lpEnt++)
  2161. {
  2162. *lpEnt ^= bKey;
  2163. };
  2164. return ERROR_SUCCESS;
  2165. }
  2166. PTSTR
  2167. pGetComPort (
  2168. IN PCTSTR DriverDesc
  2169. )
  2170. {
  2171. PTSTR rPort = NULL;
  2172. if (!HtFindStringEx (g_DeviceTable, DriverDesc, &rPort, FALSE)) {
  2173. DEBUGMSG ((DBG_WARNING, "Could not find com port for device %s."));
  2174. }
  2175. if (!rPort) {
  2176. rPort = S_EMPTY;
  2177. }
  2178. return rPort;
  2179. }
  2180. VOID
  2181. pInitializeDeviceTable (
  2182. VOID
  2183. )
  2184. {
  2185. MIG_OBJECTSTRINGHANDLE encodedRegPattern;
  2186. REGTREE_ENUM e;
  2187. PTSTR com;
  2188. PTSTR desc;
  2189. PTSTR p;
  2190. encodedRegPattern = IsmCreateSimpleObjectPattern (S_MODEMS, TRUE, TEXT("*"), TRUE);
  2191. if (EnumFirstRegObjectInTreeEx (
  2192. &e,
  2193. encodedRegPattern,
  2194. TRUE,
  2195. TRUE,
  2196. TRUE,
  2197. TRUE,
  2198. 1,
  2199. FALSE,
  2200. TRUE,
  2201. RegEnumDefaultCallback
  2202. )) {
  2203. do {
  2204. // we don't care about value names, we only want subkeys
  2205. if (!e.CurrentValueData) {
  2206. com = desc = NULL;
  2207. com = GetRegValueString (e.CurrentKeyHandle, S_ATTACHEDTO);
  2208. desc = GetRegValueString (e.CurrentKeyHandle, S_DRIVERDESC);
  2209. if (com && desc) {
  2210. p = PmDuplicateString (g_RasPool, com);
  2211. HtAddStringEx (g_DeviceTable, desc, (PBYTE) &p, FALSE);
  2212. DEBUGMSG ((DBG_RASMIG, "%s on %s added to driver table.", desc, com));
  2213. }
  2214. if (com) {
  2215. MemFree (g_hHeap, 0, com);
  2216. }
  2217. if (desc) {
  2218. MemFree (g_hHeap, 0, desc);
  2219. }
  2220. }
  2221. } while (EnumNextRegObjectInTree (&e));
  2222. }
  2223. //
  2224. // Clean up resources.
  2225. //
  2226. IsmDestroyObjectHandle (encodedRegPattern);
  2227. }
  2228. BOOL
  2229. pGetPerUserSettings (
  2230. VOID
  2231. )
  2232. {
  2233. HKEY settingsKey;
  2234. PDWORD data;
  2235. PCTSTR entryStr;
  2236. BOOL rSuccess = TRUE;
  2237. settingsKey = OpenRegKeyStr (S_REMOTE_ACCESS_KEY);
  2238. if (settingsKey) {
  2239. //
  2240. // Get UI settings.
  2241. //
  2242. data = (PDWORD) GetRegValueBinary (settingsKey, S_DIALUI);
  2243. //
  2244. // Save Dial User Interface info into memdb for this user.
  2245. //
  2246. if (data) {
  2247. entryStr = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_USER, MEMDB_FIELD_USER_SETTINGS, S_DIALUI, NULL));
  2248. rSuccess &= (MemDbSetValue (entryStr, *data) != 0);
  2249. MemFree (g_hHeap, 0, data);
  2250. }
  2251. ELSE_DEBUGMSG ((DBG_RASMIG, "No user UI settings found for current user."));
  2252. //
  2253. // Get Redial information.
  2254. //
  2255. data = (PDWORD) GetRegValueBinary (settingsKey, S_ENABLE_REDIAL);
  2256. if (data) {
  2257. entryStr = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_USER, MEMDB_FIELD_USER_SETTINGS, S_ENABLE_REDIAL, NULL));
  2258. rSuccess &= (MemDbSetValue (entryStr, *data) != 0);
  2259. MemFree (g_hHeap, 0, data);
  2260. }
  2261. ELSE_DEBUGMSG ((DBG_RASMIG, "No user redial information found for current user."));
  2262. data = (PDWORD) GetRegValueBinary (settingsKey, S_REDIAL_TRY);
  2263. if (data) {
  2264. entryStr = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_USER, MEMDB_FIELD_USER_SETTINGS, S_REDIAL_TRY, NULL));
  2265. rSuccess &= (MemDbSetValue (entryStr, *data) != 0);
  2266. MemFree (g_hHeap, 0, data);
  2267. }
  2268. ELSE_DEBUGMSG ((DBG_RASMIG, "No user redial information found for current user."));
  2269. data = (PDWORD) GetRegValueBinary (settingsKey, S_REDIAL_WAIT);
  2270. if (data) {
  2271. entryStr = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_USER, MEMDB_FIELD_USER_SETTINGS, S_REDIAL_WAIT, NULL));
  2272. rSuccess &= (MemDbSetValue (entryStr, HIWORD(*data) * 60 + LOWORD(*data)) != 0);
  2273. MemFree (g_hHeap, 0, data);
  2274. }
  2275. ELSE_DEBUGMSG ((DBG_RASMIG, "No user redial information found for current user."));
  2276. //
  2277. // Get implicit connection information. (Controls wether connection ui should be displayed or not)
  2278. //
  2279. data = (PDWORD) GetRegValueBinary (settingsKey, S_ENABLE_IMPLICIT);
  2280. if (data) {
  2281. entryStr = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_USER, MEMDB_FIELD_USER_SETTINGS, S_ENABLE_IMPLICIT, NULL));
  2282. rSuccess &= (MemDbSetValue (entryStr, *data) != 0);
  2283. MemFree(g_hHeap,0,data);
  2284. }
  2285. ELSE_DEBUGMSG ((DBG_RASMIG, "No user implicit connection information found for current user."));
  2286. CloseRegKey(settingsKey);
  2287. }
  2288. return rSuccess;
  2289. }
  2290. VOID
  2291. pSaveConnectionDataToMemDb (
  2292. IN PCTSTR Entry,
  2293. IN PCTSTR ValueName,
  2294. IN DWORD ValueType,
  2295. IN PBYTE Value
  2296. )
  2297. {
  2298. KEYHANDLE keyHandle;
  2299. PCTSTR entryStr;
  2300. PCTSTR entryTmp;
  2301. entryStr = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_INFO, Entry, ValueName, NULL));
  2302. switch (ValueType) {
  2303. case REG_SZ:
  2304. case REG_MULTI_SZ:
  2305. case REG_EXPAND_SZ:
  2306. DEBUGMSG ((DBG_RASMIG, "String Data - %s = %s", ValueName, (PCTSTR) Value));
  2307. entryTmp = JoinPaths (MEMDB_CATEGORY_RAS_DATA, (PCTSTR) Value);
  2308. keyHandle = MemDbSetKey (entryTmp);
  2309. if (!keyHandle) {
  2310. DEBUGMSG ((DBG_ERROR, "Error saving ras data into memdb."));
  2311. }
  2312. FreePathString (entryTmp);
  2313. if (!MemDbSetValueAndFlagsEx (entryStr, TRUE, keyHandle, TRUE, REG_SZ, 0)) {
  2314. DEBUGMSG ((DBG_ERROR, "Error saving ras data into memdb."));
  2315. }
  2316. break;
  2317. case REG_DWORD:
  2318. DEBUGMSG ((DBG_RASMIG, "DWORD Data - %s = %u", ValueName, (DWORD)(ULONG_PTR) Value));
  2319. if (!MemDbSetValueAndFlagsEx (entryStr, TRUE, (DWORD)(ULONG_PTR) Value, TRUE, ValueType, 0)) {
  2320. DEBUGMSG ((DBG_ERROR, "Error saving ras data into memdb."));
  2321. }
  2322. break;
  2323. case REG_BINARY:
  2324. DEBUGMSG ((DBG_RASMIG, "Binary data for %s.", ValueName));
  2325. if (StringIMatch (S_IPINFO, ValueName)) {
  2326. //
  2327. // Save IP address information.
  2328. //
  2329. pSaveConnectionDataToMemDb (Entry, S_IP_FTCPIP, REG_DWORD, (PBYTE)(ULONG_PTR)((PIPDATA) Value) -> fdwTCPIP);
  2330. pSaveConnectionDataToMemDb (Entry, S_IP_IPADDR, REG_DWORD, (PBYTE)(ULONG_PTR)((PIPDATA) Value) -> dwIPAddr);
  2331. pSaveConnectionDataToMemDb (Entry, S_IP_DNSADDR, REG_DWORD, (PBYTE)(ULONG_PTR)((PIPDATA) Value) -> dwDNSAddr);
  2332. pSaveConnectionDataToMemDb (Entry, S_IP_DNSADDR2, REG_DWORD, (PBYTE)(ULONG_PTR)((PIPDATA) Value) -> dwDNSAddrAlt);
  2333. pSaveConnectionDataToMemDb (Entry, S_IP_WINSADDR, REG_DWORD, (PBYTE)(ULONG_PTR)((PIPDATA) Value) -> dwWINSAddr);
  2334. pSaveConnectionDataToMemDb (Entry, S_IP_WINSADDR2, REG_DWORD, (PBYTE)(ULONG_PTR)((PIPDATA) Value) -> dwWINSAddrAlt);
  2335. } else if (StringIMatch (S_TERMINAL, ValueName)) {
  2336. //
  2337. // save information on the showcmd state. This will tell us how to set the ui display.
  2338. //
  2339. pSaveConnectionDataToMemDb (Entry, ValueName, REG_DWORD, (PBYTE)(ULONG_PTR)((PWINDOWPLACEMENT) Value) -> showCmd);
  2340. } else if (StringIMatch (S_MODE, ValueName)) {
  2341. //
  2342. // This value tells what to do with scripting.
  2343. //
  2344. pSaveConnectionDataToMemDb (Entry, ValueName, REG_DWORD, (PBYTE)(ULONG_PTR) *((PDWORD) Value));
  2345. } else if (StringIMatch (S_MULTILINK, ValueName)) {
  2346. //
  2347. // Save wether or not multilink is enabled.
  2348. //
  2349. pSaveConnectionDataToMemDb (Entry, ValueName, REG_DWORD,(PBYTE)(ULONG_PTR) *((PDWORD) Value));
  2350. } ELSE_DEBUGMSG ((DBG_WARNING, "Don't know how to handle binary data %s. It will be ignored.", ValueName));
  2351. break;
  2352. default:
  2353. DEBUGMSG ((DBG_WHOOPS, "Unknown type of registry data found in RAS settings. %s", ValueName));
  2354. break;
  2355. }
  2356. FreePathString (entryStr);
  2357. }
  2358. BOOL
  2359. pGetRasEntryAddressInfo (
  2360. IN PCTSTR KeyName,
  2361. IN PCTSTR EntryName
  2362. )
  2363. {
  2364. BOOL rSuccess = TRUE;
  2365. MIG_OBJECTSTRINGHANDLE encodedRegPattern;
  2366. MIG_OBJECTSTRINGHANDLE encodedSubPattern;
  2367. PBYTE data = NULL;
  2368. UINT count = 0;
  2369. UINT type = 0;
  2370. PADDRENTRY entry;
  2371. PSUBCONNENTRY subEntry;
  2372. PSMMCFG smmCfg;
  2373. PDEVICEINFO devInfo;
  2374. REGTREE_ENUM e;
  2375. PTSTR subEntriesKeyStr;
  2376. UINT sequencer = 0;
  2377. REGTREE_ENUM eSubEntries;
  2378. TCHAR buffer[MAX_TCHAR_PATH];
  2379. PMODEMDEVINFO modemInfo;
  2380. #ifdef UNICODE
  2381. PCSTR tempStr = NULL;
  2382. PCWSTR tempStrW = NULL;
  2383. #endif
  2384. //
  2385. // First we have to get the real entry name. It must match exactly even case. Unfortunately, it isn't neccessarily a given
  2386. // that the case between HKCU\RemoteAccess\Profiles\<Foo> and HKCU\RemoteAccess\Addresses\[Foo] is the same. The registry
  2387. // apis will of course work fine because they work case insensitively. However, I will be unable to decrypt the value
  2388. // if I use the wrong name.
  2389. //
  2390. encodedRegPattern = IsmCreateSimpleObjectPattern (KeyName, FALSE, TEXT("*"), TRUE);
  2391. if (EnumFirstRegObjectInTreeEx (
  2392. &e,
  2393. encodedRegPattern,
  2394. TRUE,
  2395. TRUE,
  2396. TRUE,
  2397. TRUE,
  2398. REGENUM_ALL_SUBLEVELS,
  2399. FALSE,
  2400. TRUE,
  2401. RegEnumDefaultCallback
  2402. )) {
  2403. do {
  2404. if (StringIMatch (e.Name, EntryName)) {
  2405. //
  2406. // Found the correct entry. Use it.
  2407. //
  2408. data = e.CurrentValueData;
  2409. if (data) {
  2410. entry = (PADDRENTRY) data;
  2411. #ifdef UNICODE
  2412. tempStr = ConvertWtoA (e.Name);
  2413. DECRYPTENTRY(tempStr, entry, e.CurrentValueDataSize);
  2414. FreeConvertedStr (tempStr);
  2415. #else
  2416. DECRYPTENTRY(e.Name, entry, e.CurrentValueDataSize);
  2417. #endif
  2418. smmCfg = PAESMMCFG(entry);
  2419. devInfo = PAEDI(entry);
  2420. pSaveConnectionDataToMemDb (EntryName, S_PHONE_NUMBER, REG_SZ, (PBYTE) PAEPHONE(entry));
  2421. pSaveConnectionDataToMemDb (EntryName, S_AREA_CODE, REG_SZ, (PBYTE) PAEAREA(entry));
  2422. pSaveConnectionDataToMemDb (EntryName, S_SMM, REG_SZ, (PBYTE) PAESMM(entry));
  2423. pSaveConnectionDataToMemDb (EntryName, S_COUNTRY_CODE, REG_DWORD, (PBYTE)(ULONG_PTR) entry -> dwCountryCode);
  2424. pSaveConnectionDataToMemDb (EntryName, S_COUNTRY_ID, REG_DWORD, (PBYTE)(ULONG_PTR) entry -> dwCountryID);
  2425. pSaveConnectionDataToMemDb (EntryName, S_DEVICE_NAME, REG_SZ, (PBYTE) devInfo -> szDeviceName);
  2426. pSaveConnectionDataToMemDb (EntryName, S_DEVICE_TYPE, REG_SZ, (PBYTE) devInfo -> szDeviceType);
  2427. pSaveConnectionDataToMemDb (EntryName, S_PROTOCOLS, REG_DWORD, (PBYTE)(ULONG_PTR) smmCfg -> fdwProtocols);
  2428. pSaveConnectionDataToMemDb (EntryName, S_SMM_OPTIONS, REG_DWORD, (PBYTE)(ULONG_PTR) smmCfg -> fdwOptions);
  2429. //
  2430. // Save device information away.
  2431. //
  2432. if (StringIMatchA (devInfo -> szDeviceType, S_MODEMA)) {
  2433. modemInfo = (PMODEMDEVINFO) (devInfo->szDeviceType + RAS_MaxDeviceType + 3);
  2434. if (modemInfo -> Size >= sizeof (MODEMDEVINFO)) {
  2435. DEBUGMSG_IF ((modemInfo -> Size > sizeof (MODEMDEVINFO), DBG_RASMIG, "Structure size larger than our known size."));
  2436. pSaveConnectionDataToMemDb (EntryName, S_MODEM_UI_OPTIONS, REG_DWORD, (PBYTE)(ULONG_PTR) modemInfo -> ModemUiOptions);
  2437. pSaveConnectionDataToMemDb (EntryName, S_MODEM_SPEED, REG_DWORD, (PBYTE)(ULONG_PTR) modemInfo -> ConnectionSpeed);
  2438. pSaveConnectionDataToMemDb (EntryName, S_MODEM_SPEAKER_VOLUME, REG_DWORD, (PBYTE)(ULONG_PTR) modemInfo -> SpeakerVolume);
  2439. pSaveConnectionDataToMemDb (EntryName, S_MODEM_IDLE_DISCONNECT_SECONDS, REG_DWORD, (PBYTE)(ULONG_PTR) modemInfo -> IdleDisconnectSeconds);
  2440. pSaveConnectionDataToMemDb (EntryName, S_MODEM_CANCEL_SECONDS, REG_DWORD, (PBYTE)(ULONG_PTR) modemInfo -> CancelSeconds);
  2441. pSaveConnectionDataToMemDb (EntryName, S_MODEM_CFG_OPTIONS, REG_DWORD, (PBYTE)(ULONG_PTR) modemInfo -> ConfigOptions);
  2442. #ifdef UNICODE
  2443. tempStrW = ConvertAtoW (devInfo->szDeviceName);
  2444. pSaveConnectionDataToMemDb (EntryName, S_MODEM_COM_PORT, REG_SZ, (PBYTE) pGetComPort (tempStrW));
  2445. FreeConvertedStr (tempStrW);
  2446. #else
  2447. pSaveConnectionDataToMemDb (EntryName, S_MODEM_COM_PORT, REG_SZ, (PBYTE) pGetComPort (devInfo->szDeviceName));
  2448. #endif
  2449. }
  2450. ELSE_DEBUGMSG ((DBG_WHOOPS, "No modem configuration data saved. Size smaller than known structure. Investigate."));
  2451. }
  2452. //
  2453. // If SMM is not SLIP, CSLIP or PPP, we need to add a message to the upgrade report.
  2454. //
  2455. if (!StringIMatchA (PAESMM(entry), S_SLIPA) && !StringIMatchA (PAESMM(entry), S_PPPA) && !StringIMatchA (PAESMM(entry), S_CSLIPA)) {
  2456. LOG ((LOG_WARNING, (PCSTR) MSG_RASMIG_UNSUPPORTEDSETTINGS, EntryName));
  2457. }
  2458. }
  2459. //
  2460. // Check to see if there are any sub-entries for this connection (MULTILINK settings..)
  2461. //
  2462. //
  2463. // Luckily, we don't have to do the same enumeration of these entries as we had to above to get around
  2464. // the case sensitivity bug. the 9x code uses the address key name above for encryption/decryption.
  2465. //
  2466. subEntriesKeyStr = JoinPathsInPoolEx ((NULL, KeyName, S_SUBENTRIES, e.Name, NULL));
  2467. sequencer = 1;
  2468. encodedSubPattern = IsmCreateSimpleObjectPattern (subEntriesKeyStr, FALSE, TEXT("*"), TRUE);
  2469. if (EnumFirstRegObjectInTreeEx (
  2470. &eSubEntries,
  2471. encodedSubPattern,
  2472. TRUE,
  2473. TRUE,
  2474. TRUE,
  2475. TRUE,
  2476. REGENUM_ALL_SUBLEVELS,
  2477. FALSE,
  2478. TRUE,
  2479. RegEnumDefaultCallback
  2480. )) {
  2481. do {
  2482. DEBUGMSG ((DBG_RASMIG, "Multi-Link Subentries found for entry %s. Processing.", e.Name));
  2483. data = eSubEntries.CurrentValueData;
  2484. if (data) {
  2485. subEntry = (PSUBCONNENTRY) data;
  2486. #ifdef UNICODE
  2487. tempStr = ConvertWtoA (e.Name);
  2488. DECRYPTENTRY (tempStr, subEntry, eSubEntries.CurrentValueDataSize);
  2489. FreeConvertedStr (tempStr);
  2490. #else
  2491. DECRYPTENTRY (e.Name, subEntry, eSubEntries.CurrentValueDataSize);
  2492. #endif
  2493. wsprintf (buffer, TEXT("ml%d%s"), sequencer, S_DEVICE_TYPE);
  2494. pSaveConnectionDataToMemDb (EntryName, buffer, REG_SZ, (PBYTE) subEntry->szDeviceType);
  2495. wsprintf (buffer, TEXT("ml%d%s"), sequencer, S_DEVICE_NAME);
  2496. pSaveConnectionDataToMemDb (EntryName, buffer, REG_SZ, (PBYTE) subEntry->szDeviceName);
  2497. wsprintf (buffer, TEXT("ml%d%s"), sequencer, S_PHONE_NUMBER);
  2498. pSaveConnectionDataToMemDb (EntryName, buffer, REG_SZ, (PBYTE) subEntry->szLocal);
  2499. wsprintf (buffer, TEXT("ml%d%s"), sequencer, S_MODEM_COM_PORT);
  2500. #ifdef UNICODE
  2501. tempStrW = ConvertAtoW (subEntry->szDeviceName);
  2502. pSaveConnectionDataToMemDb (EntryName, buffer, REG_SZ, (PBYTE) pGetComPort (tempStrW));
  2503. FreeConvertedStr (tempStrW);
  2504. #else
  2505. pSaveConnectionDataToMemDb (EntryName, buffer, REG_SZ, (PBYTE) pGetComPort (subEntry->szDeviceName));
  2506. #endif
  2507. }
  2508. sequencer++;
  2509. } while (EnumNextRegObjectInTree (&eSubEntries));
  2510. }
  2511. IsmDestroyObjectHandle (encodedSubPattern);
  2512. FreePathString (subEntriesKeyStr);
  2513. //
  2514. // Save away the number of devices associated with this connection
  2515. //
  2516. pSaveConnectionDataToMemDb (EntryName, S_DEVICECOUNT, REG_DWORD, (PBYTE)(ULONG_PTR) sequencer);
  2517. //
  2518. // We're done. Break out of the enumeration.
  2519. //
  2520. AbortRegObjectInTreeEnum (&e);
  2521. break;
  2522. }
  2523. } while (EnumNextRegObjectInTree (&e));
  2524. }
  2525. IsmDestroyObjectHandle (encodedRegPattern);
  2526. return rSuccess;
  2527. }
  2528. BOOL
  2529. pGetRasEntrySettings (
  2530. IN PCTSTR KeyName,
  2531. IN PCTSTR EntryName
  2532. )
  2533. {
  2534. REGTREE_ENUM e;
  2535. MIG_OBJECTSTRINGHANDLE encodedRegPattern;
  2536. PBYTE curData = NULL;
  2537. BOOL rSuccess = TRUE;
  2538. encodedRegPattern = IsmCreateSimpleObjectPattern (KeyName, FALSE, TEXT("*"), TRUE);
  2539. if (EnumFirstRegObjectInTreeEx (
  2540. &e,
  2541. encodedRegPattern,
  2542. TRUE,
  2543. TRUE,
  2544. TRUE,
  2545. TRUE,
  2546. REGENUM_ALL_SUBLEVELS,
  2547. FALSE,
  2548. TRUE,
  2549. RegEnumDefaultCallback
  2550. )) {
  2551. do {
  2552. if (e.CurrentValueData) {
  2553. pSaveConnectionDataToMemDb (
  2554. EntryName,
  2555. e.Name,
  2556. e.CurrentValueType,
  2557. e.CurrentValueType == REG_DWORD ? (PBYTE)(ULONG_PTR) (*((PDWORD)e.CurrentValueData)) : e.CurrentValueData
  2558. );
  2559. }
  2560. } while (EnumNextRegObjectInTree (&e));
  2561. }
  2562. IsmDestroyObjectHandle (encodedRegPattern);
  2563. return rSuccess;
  2564. }
  2565. BOOL
  2566. pGetPerConnectionSettings (
  2567. VOID
  2568. )
  2569. {
  2570. MIG_OBJECTSTRINGHANDLE encodedRegPattern;
  2571. REGTREE_ENUM e;
  2572. PCTSTR entryKey = NULL;
  2573. BOOL rSuccess = TRUE;
  2574. encodedRegPattern = IsmCreateSimpleObjectPattern (S_ADDRESSES_KEY, FALSE, TEXT("*"), TRUE);
  2575. //
  2576. // Enumerate each entry for this user.
  2577. //
  2578. if (EnumFirstRegObjectInTreeEx (
  2579. &e,
  2580. encodedRegPattern,
  2581. TRUE,
  2582. TRUE,
  2583. TRUE,
  2584. TRUE,
  2585. REGENUM_ALL_SUBLEVELS,
  2586. FALSE,
  2587. TRUE,
  2588. RegEnumDefaultCallback
  2589. )) {
  2590. do {
  2591. //
  2592. // Get base connection info -- stored as binary blob under address key.
  2593. // All connections will have this info -- It contains such things
  2594. // as the phone number, area code, dialing rules, etc.. It does
  2595. // not matter wether the connection has been used or not.
  2596. //
  2597. rSuccess &= pGetRasEntryAddressInfo (S_ADDRESSES_KEY, e.Name);
  2598. //
  2599. // Under the profile key are negotiated options for the connection.
  2600. // This key will only exist if the entry has actually been connected
  2601. // to by the user.
  2602. //
  2603. entryKey = JoinPaths (S_PROFILE_KEY, e.Name);
  2604. if (entryKey) {
  2605. rSuccess &= pGetRasEntrySettings (entryKey, e.Name);
  2606. FreePathString (entryKey);
  2607. }
  2608. } while (EnumNextRegObjectInTree (&e));
  2609. }
  2610. //
  2611. // Clean up resources.
  2612. //
  2613. IsmDestroyObjectHandle (encodedRegPattern);
  2614. return rSuccess;
  2615. }
  2616. BOOL
  2617. pGetRasDataFromMemDb (
  2618. IN PCTSTR DataName,
  2619. OUT PMEMDB_RAS_DATA Data
  2620. )
  2621. {
  2622. BOOL rSuccess = FALSE;
  2623. PCTSTR key;
  2624. DWORD value;
  2625. DWORD flags;
  2626. PCTSTR tempBuffer;
  2627. MYASSERT(DataName && Data && g_CurrentConnection);
  2628. key = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_INFO, g_CurrentConnection, DataName, NULL));
  2629. rSuccess = MemDbGetValueAndFlags (key, &value, &flags);
  2630. FreePathString (key);
  2631. //
  2632. // If that wasn't successful, we need to look in the per-user settings.
  2633. //
  2634. if (!rSuccess) {
  2635. key = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_USER, MEMDB_FIELD_USER_SETTINGS, DataName, NULL));
  2636. rSuccess = MemDbGetValueAndFlags (key, &value, &flags);
  2637. flags = REG_DWORD;
  2638. }
  2639. if (rSuccess) {
  2640. //
  2641. // There is information stored here. Fill it in and send it back to the user.
  2642. //
  2643. if (flags == REG_SZ) {
  2644. //
  2645. // String data, the value points to the offset for the string.
  2646. //
  2647. tempBuffer = MemDbGetKeyFromHandle (value, 1);
  2648. if (!tempBuffer) {
  2649. DEBUGMSG ((
  2650. DBG_ERROR,
  2651. "Could not retrieve RAS string information stored in Memdb. Entry=%s,Setting=%s",
  2652. g_CurrentConnection,
  2653. DataName
  2654. ));
  2655. return FALSE;
  2656. }
  2657. Data -> String = PmDuplicateString (g_RasPool, tempBuffer);
  2658. MemDbReleaseMemory (tempBuffer);
  2659. }
  2660. else {
  2661. //
  2662. // Not string data. The data is stored as the value.
  2663. //
  2664. Data -> Value = value;
  2665. }
  2666. Data -> DataType = (WORD) flags;
  2667. }
  2668. return rSuccess;
  2669. }
  2670. BOOL
  2671. pWritePhoneBookLine (
  2672. IN HANDLE FileHandle,
  2673. IN PCTSTR SettingName,
  2674. IN PCTSTR SettingValue
  2675. )
  2676. {
  2677. BOOL rSuccess = TRUE;
  2678. rSuccess &= WriteFileString (FileHandle, SettingName);
  2679. rSuccess &= WriteFileString (FileHandle, TEXT("="));
  2680. rSuccess &= WriteFileString (FileHandle, SettingValue ? SettingValue : S_EMPTY);
  2681. rSuccess &= WriteFileString (FileHandle, TEXT("\r\n"));
  2682. return rSuccess;
  2683. }
  2684. BOOL
  2685. pWriteSettings (
  2686. IN HANDLE FileHandle,
  2687. IN PRAS_SETTING SettingList
  2688. )
  2689. {
  2690. BOOL rSuccess = TRUE;
  2691. while (SettingList->SettingName) {
  2692. rSuccess &= pWritePhoneBookLine (
  2693. FileHandle,
  2694. SettingList->SettingName,
  2695. SettingList->SettingValue ?
  2696. SettingList->SettingValue :
  2697. SettingList->SettingFunction ());
  2698. SettingList++;
  2699. }
  2700. return rSuccess;
  2701. }
  2702. PCTSTR
  2703. pGetSpeaker (
  2704. VOID
  2705. )
  2706. {
  2707. MEMDB_RAS_DATA d;
  2708. if (g_CurrentDevice) {
  2709. return S_ONE;
  2710. }
  2711. if (!pGetRasDataFromMemDb (S_MODEM_SPEAKER_VOLUME, &d)) {
  2712. return S_ONE;
  2713. }
  2714. if (d.Value) {
  2715. return S_ONE;
  2716. }
  2717. return S_ZERO;
  2718. }
  2719. PCTSTR
  2720. pGetCompression (
  2721. VOID
  2722. )
  2723. {
  2724. MEMDB_RAS_DATA d;
  2725. if (g_CurrentDevice) {
  2726. return S_EMPTY;
  2727. }
  2728. if (!pGetRasDataFromMemDb (S_MODEM_CFG_OPTIONS, &d)) {
  2729. return S_EMPTY;
  2730. }
  2731. if (d.Value & RAS_CFG_FLAG_COMPRESS_DATA) {
  2732. return S_ONE;
  2733. }
  2734. return S_ZERO;
  2735. }
  2736. PCTSTR
  2737. pGetProtocol (
  2738. VOID
  2739. )
  2740. {
  2741. MEMDB_RAS_DATA d;
  2742. if (g_CurrentDevice) {
  2743. return S_EMPTY;
  2744. }
  2745. if (!pGetRasDataFromMemDb (S_MODEM_CFG_OPTIONS, &d)) {
  2746. return S_EMPTY;
  2747. }
  2748. if (d.Value & RAS_CFG_FLAG_USE_ERROR_CONTROL) {
  2749. return S_ONE;
  2750. }
  2751. return S_ZERO;
  2752. }
  2753. PCTSTR
  2754. pGetHwFlowControl (
  2755. VOID
  2756. )
  2757. {
  2758. MEMDB_RAS_DATA d;
  2759. if (g_CurrentDevice) {
  2760. return S_EMPTY;
  2761. }
  2762. if (!pGetRasDataFromMemDb (S_MODEM_CFG_OPTIONS, &d)) {
  2763. return S_EMPTY;
  2764. }
  2765. if (d.Value & RAS_CFG_FLAG_HARDWARE_FLOW_CONTROL) {
  2766. return S_ONE;
  2767. }
  2768. return S_ZERO;
  2769. }
  2770. PCTSTR
  2771. pGetUseDialingRules (
  2772. VOID
  2773. )
  2774. {
  2775. MEMDB_RAS_DATA d;
  2776. //
  2777. // Win9x sets the areacode, countrycode, countryid to zero if
  2778. // use dialing rules is disabled. For ease, we test off of country
  2779. // code. If we can't get it, or, it is set to zero, we assume
  2780. // that we should _not_ use dialing rules.
  2781. //
  2782. if (!pGetRasDataFromMemDb(S_COUNTRY_CODE, &d) || !d.Value) {
  2783. return S_ZERO;
  2784. }
  2785. return S_ONE;
  2786. }
  2787. PCTSTR
  2788. pGetCountryID (
  2789. VOID
  2790. )
  2791. {
  2792. MEMDB_RAS_DATA d;
  2793. if (!pGetRasDataFromMemDb (S_COUNTRY_ID, &d) || !d.Value) {
  2794. return S_EMPTY;
  2795. }
  2796. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  2797. return g_TempBuffer;
  2798. }
  2799. PCTSTR
  2800. pGetCountryCode (
  2801. VOID
  2802. )
  2803. {
  2804. MEMDB_RAS_DATA d;
  2805. if (!pGetRasDataFromMemDb(S_COUNTRY_CODE, &d) || !d.Value) {
  2806. return S_EMPTY;
  2807. }
  2808. wsprintf(g_TempBuffer,TEXT("%d"),d.Value);
  2809. return g_TempBuffer;
  2810. }
  2811. PCTSTR
  2812. pGetAreaCode (
  2813. VOID
  2814. )
  2815. {
  2816. MEMDB_RAS_DATA d;
  2817. if (!pGetRasDataFromMemDb(S_AREA_CODE, &d)) {
  2818. return S_EMPTY;
  2819. }
  2820. return d.String;
  2821. }
  2822. PCTSTR
  2823. pGetPhoneNumber (
  2824. VOID
  2825. )
  2826. {
  2827. MEMDB_RAS_DATA d;
  2828. TCHAR buffer[MAX_TCHAR_PATH];
  2829. if (g_CurrentDevice == 0) {
  2830. if (!pGetRasDataFromMemDb(S_PHONE_NUMBER, &d)) {
  2831. return S_EMPTY;
  2832. }
  2833. }
  2834. else {
  2835. wsprintf(buffer,TEXT("ml%d%s"),g_CurrentDevice,S_PHONE_NUMBER);
  2836. if (!pGetRasDataFromMemDb(buffer, &d)) {
  2837. return S_EMPTY;
  2838. }
  2839. }
  2840. return d.String;
  2841. }
  2842. PCTSTR
  2843. pGetScript (
  2844. VOID
  2845. )
  2846. {
  2847. MEMDB_RAS_DATA d;
  2848. if (!pGetRasDataFromMemDb (S_PPPSCRIPT, &d)) {
  2849. return S_ZERO;
  2850. }
  2851. return S_ONE;
  2852. }
  2853. PCTSTR
  2854. pGetTerminal (
  2855. VOID
  2856. )
  2857. {
  2858. MEMDB_RAS_DATA d;
  2859. if (!pGetRasDataFromMemDb (S_MODEM_UI_OPTIONS, &d)) {
  2860. return S_EMPTY;
  2861. }
  2862. if (d.Value & (RAS_UI_FLAG_TERMBEFOREDIAL | RAS_UI_FLAG_TERMAFTERDIAL)) {
  2863. return S_ONE;
  2864. }
  2865. return S_ZERO;
  2866. }
  2867. PCTSTR
  2868. pGetName (
  2869. VOID
  2870. )
  2871. {
  2872. MEMDB_RAS_DATA d;
  2873. if (!pGetRasDataFromMemDb (S_PPPSCRIPT, &d)) {
  2874. return S_EMPTY;
  2875. }
  2876. else {
  2877. return d.String;
  2878. }
  2879. }
  2880. PCTSTR
  2881. pGetDEVICE (
  2882. VOID
  2883. )
  2884. {
  2885. if (g_InSwitchSection) {
  2886. return TEXT("Switch");
  2887. }
  2888. if (g_CurrentDeviceType == RASTYPE_VPN) {
  2889. return TEXT("rastapi");
  2890. }
  2891. return TEXT("modem");
  2892. }
  2893. PCTSTR
  2894. pGetConnectBps (
  2895. VOID
  2896. )
  2897. {
  2898. MEMDB_RAS_DATA d;
  2899. if (!g_CurrentDevice) {
  2900. if (!pGetRasDataFromMemDb (S_MODEM_SPEED, &d)) {
  2901. return S_EMPTY;
  2902. }
  2903. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  2904. return g_TempBuffer;
  2905. }
  2906. return S_EMPTY;
  2907. }
  2908. PCTSTR
  2909. pGetDevice (
  2910. VOID
  2911. )
  2912. {
  2913. PTSTR p = S_MODEM_COM_PORT;
  2914. PTSTR value = NULL;
  2915. MEMDB_RAS_DATA d;
  2916. //
  2917. // Very easy if this is a vpn connection.
  2918. //
  2919. if (g_CurrentDeviceType == RASTYPE_VPN) {
  2920. return TEXT("rastapi");
  2921. }
  2922. if (g_CurrentDevice) {
  2923. wsprintf (g_TempBuffer, TEXT("ml%d%s"), g_CurrentDevice, S_MODEM_COM_PORT);
  2924. p = g_TempBuffer;
  2925. }
  2926. if (!pGetRasDataFromMemDb (p, &d)) {
  2927. return S_EMPTY;
  2928. }
  2929. if (!HtFindStringEx (g_DeviceTable, d.String, &value, FALSE)) {
  2930. return S_EMPTY;
  2931. }
  2932. return value;
  2933. }
  2934. PCTSTR
  2935. pGetPort (
  2936. VOID
  2937. )
  2938. {
  2939. PTSTR value = NULL;
  2940. MEMDB_RAS_DATA d;
  2941. PTSTR p = S_MODEM_COM_PORT;
  2942. if (g_CurrentDeviceType == RASTYPE_VPN) {
  2943. return TEXT("VPN2-0");
  2944. }
  2945. if (g_CurrentDevice) {
  2946. wsprintf (g_TempBuffer, TEXT("ml%d%s"), g_CurrentDevice, S_MODEM_COM_PORT);
  2947. p = g_TempBuffer;
  2948. }
  2949. if (!pGetRasDataFromMemDb (p, &d)) {
  2950. return S_EMPTY;
  2951. }
  2952. if (!HtFindStringEx (g_DeviceTable, d.String, &value, FALSE)) {
  2953. return S_EMPTY;
  2954. }
  2955. return d.String;
  2956. }
  2957. PCTSTR
  2958. pGetMEDIA (
  2959. VOID
  2960. )
  2961. {
  2962. if (g_CurrentDeviceType == RASTYPE_VPN) {
  2963. return TEXT("rastapi");
  2964. }
  2965. else {
  2966. return TEXT("Serial");
  2967. }
  2968. }
  2969. PCTSTR
  2970. pGetIpNameAssign (
  2971. VOID
  2972. )
  2973. {
  2974. MEMDB_RAS_DATA d;
  2975. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  2976. return S_EMPTY;
  2977. }
  2978. else if (d.Value & IPF_NAME_SPECIFIED) {
  2979. return TEXT("2");
  2980. }
  2981. else {
  2982. return S_ONE;
  2983. }
  2984. }
  2985. PCTSTR
  2986. pGetNetAddress (
  2987. IN PCTSTR Setting
  2988. )
  2989. {
  2990. MEMDB_RAS_DATA d;
  2991. BYTE address[4];
  2992. if (!pGetRasDataFromMemDb (Setting, &d) || !d.Value) {
  2993. return S_EMPTY;
  2994. }
  2995. //
  2996. // Data is stored as a REG_DWORD.
  2997. // We need to write it in dotted decimal form.
  2998. //
  2999. *((LPDWORD)address) = d.Value;
  3000. wsprintf (
  3001. g_TempBuffer,
  3002. TEXT("%d.%d.%d.%d"),
  3003. address[3],
  3004. address[2],
  3005. address[1],
  3006. address[0]
  3007. );
  3008. return g_TempBuffer;
  3009. }
  3010. PCTSTR
  3011. pGetIpWINS2Address (
  3012. VOID
  3013. )
  3014. {
  3015. return pGetNetAddress (S_IP_WINSADDR2);
  3016. }
  3017. PCTSTR
  3018. pGetIpWINSAddress (
  3019. VOID
  3020. )
  3021. {
  3022. return pGetNetAddress (S_IP_WINSADDR);
  3023. }
  3024. PCTSTR
  3025. pGetIpDns2Address (
  3026. VOID
  3027. )
  3028. {
  3029. return pGetNetAddress (S_IP_DNSADDR2);
  3030. }
  3031. PCTSTR
  3032. pGetIpDnsAddress (
  3033. VOID
  3034. )
  3035. {
  3036. return pGetNetAddress (S_IP_DNSADDR);
  3037. }
  3038. PCTSTR
  3039. pGetIpAssign (
  3040. VOID
  3041. )
  3042. {
  3043. MEMDB_RAS_DATA d;
  3044. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  3045. return S_EMPTY;
  3046. }
  3047. else if (d.Value & IPF_IP_SPECIFIED) {
  3048. return TEXT("2");
  3049. }
  3050. else {
  3051. return S_ONE;
  3052. }
  3053. }
  3054. PCTSTR
  3055. pGetIpAddress (
  3056. VOID
  3057. )
  3058. {
  3059. return pGetNetAddress (S_IP_IPADDR);
  3060. }
  3061. PCTSTR
  3062. pGetIpHeaderCompression (
  3063. VOID
  3064. )
  3065. {
  3066. MEMDB_RAS_DATA d;
  3067. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  3068. return S_EMPTY;
  3069. }
  3070. else if (d.Value & IPF_NO_COMPRESS) {
  3071. return S_ZERO;
  3072. }
  3073. else {
  3074. return S_ONE;
  3075. }
  3076. }
  3077. PCTSTR
  3078. pGetIpPrioritizeRemote (
  3079. VOID
  3080. )
  3081. {
  3082. MEMDB_RAS_DATA d;
  3083. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  3084. return S_ONE;
  3085. }
  3086. else if (d.Value & IPF_NO_WAN_PRI) {
  3087. return S_ZERO;
  3088. }
  3089. else {
  3090. return S_ONE;
  3091. }
  3092. }
  3093. PCTSTR
  3094. pGetPreviewUserPw (
  3095. VOID
  3096. )
  3097. {
  3098. MEMDB_RAS_DATA d;
  3099. if (!pGetRasDataFromMemDb (S_DIALUI, &d)) {
  3100. return S_ONE;
  3101. }
  3102. if (d.Value & DIALUI_DONT_PROMPT_FOR_INFO) {
  3103. return S_ZERO;
  3104. }
  3105. return S_ONE;
  3106. }
  3107. PCTSTR
  3108. pGetPreviewPhoneNumber (
  3109. VOID
  3110. )
  3111. {
  3112. if (g_CurrentDeviceType == RASTYPE_VPN) {
  3113. return S_ZERO;
  3114. }
  3115. return pGetPreviewUserPw ();
  3116. }
  3117. PCTSTR
  3118. pGetPreviewDomain (
  3119. VOID
  3120. )
  3121. {
  3122. MEMDB_RAS_DATA d;
  3123. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  3124. return S_ONE;
  3125. }
  3126. //
  3127. // if 0x04 is set, then preview domain, otherwise don't.
  3128. //
  3129. if (d.Value & SMMCFG_NW_LOGON) {
  3130. return S_ONE;
  3131. }
  3132. return S_ZERO;
  3133. }
  3134. PCTSTR
  3135. pGetIdleDisconnectSeconds (
  3136. VOID
  3137. )
  3138. {
  3139. MEMDB_RAS_DATA d;
  3140. if (!pGetRasDataFromMemDb (S_MODEM_IDLE_DISCONNECT_SECONDS, &d)) {
  3141. return S_EMPTY;
  3142. }
  3143. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  3144. return g_TempBuffer;
  3145. }
  3146. PCTSTR
  3147. pGetRedialSeconds (
  3148. VOID
  3149. )
  3150. {
  3151. MEMDB_RAS_DATA d;
  3152. //
  3153. // NT wants this as a total number of seconds. The data we have from 9x has
  3154. // the number of minutes in the hiword and the number of seconds in the loword.
  3155. //
  3156. if (!pGetRasDataFromMemDb (S_REDIAL_WAIT, &d)) {
  3157. return S_EMPTY;
  3158. }
  3159. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  3160. return g_TempBuffer;
  3161. }
  3162. PCTSTR
  3163. pGetRedialAttempts (
  3164. VOID
  3165. )
  3166. {
  3167. MEMDB_RAS_DATA d;
  3168. //
  3169. // Before getting the number of redial attempts on windows 9x,
  3170. // we need to ensure that redialing is enabled. If it is not
  3171. // enabled, we set this field to zero, regardless.
  3172. //
  3173. if (pGetRasDataFromMemDb (S_ENABLE_REDIAL, &d)) {
  3174. if (!d.Value) {
  3175. return S_ZERO;
  3176. }
  3177. }
  3178. //
  3179. // If we have gotten this far, then redialing is enabled.
  3180. //
  3181. if (!pGetRasDataFromMemDb (S_REDIAL_TRY, &d)) {
  3182. DEBUGMSG((DBG_WARNING, "Redialing enabled, but no redial attempts info found."));
  3183. return S_ZERO;
  3184. }
  3185. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  3186. return g_TempBuffer;
  3187. }
  3188. PCTSTR
  3189. pGetAuthRestrictions (
  3190. VOID
  3191. )
  3192. {
  3193. MEMDB_RAS_DATA d;
  3194. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  3195. return S_EMPTY;
  3196. }
  3197. //
  3198. // password should be encrypted if 0x02 is set.
  3199. //
  3200. if (d.Value & SMMCFG_PW_ENCRYPTED) {
  3201. return TEXT("2");
  3202. }
  3203. return S_EMPTY;
  3204. }
  3205. PCTSTR
  3206. pGetShowMonitorIconInTaskBar (
  3207. VOID
  3208. )
  3209. {
  3210. MEMDB_RAS_DATA d;
  3211. //
  3212. // This information is stored packed with other Dialing UI on
  3213. // windows 9x. All we need to do is look for the specific
  3214. // bit which is set when this is turned off.
  3215. //
  3216. if (pGetRasDataFromMemDb (S_DIALUI, &d) && (d.Value & DIALUI_DONT_SHOW_ICON)) {
  3217. return S_ZERO;
  3218. }
  3219. return S_ONE;
  3220. }
  3221. PCTSTR
  3222. pGetSwCompression (
  3223. VOID
  3224. )
  3225. {
  3226. MEMDB_RAS_DATA d;
  3227. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  3228. return S_EMPTY;
  3229. }
  3230. //
  3231. // the 1 bit in SMM_OPTIONS controls software based compression.
  3232. // if it is set, the connection is able to handled compression,
  3233. // otherwise, it cannot.
  3234. //
  3235. if (d.Value & SMMCFG_SW_COMPRESSION) {
  3236. return S_ONE;
  3237. }
  3238. return S_ZERO;
  3239. }
  3240. PCTSTR
  3241. pGetDataEncryption (
  3242. VOID
  3243. )
  3244. {
  3245. MEMDB_RAS_DATA d;
  3246. BOOL reqDataEncrypt;
  3247. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  3248. return S_EMPTY;
  3249. }
  3250. //
  3251. // data should be encrypted if 0x1000 is set.
  3252. //
  3253. reqDataEncrypt = (d.Value & 0x1000);
  3254. if (!reqDataEncrypt) {
  3255. reqDataEncrypt = (d.Value & 0x200);
  3256. }
  3257. return reqDataEncrypt ? TEXT("256") : TEXT("8");
  3258. }
  3259. PCTSTR
  3260. pGetExcludedProtocols (
  3261. VOID
  3262. )
  3263. {
  3264. MEMDB_RAS_DATA d;
  3265. //
  3266. // Excluded protocols lists what protocols
  3267. // are _not_ available for a particular ras connection.
  3268. // This is a bit field where bits are set for each protocol
  3269. // that is excluded.
  3270. // NP_Nbf (0x1), NP_Ipx (0x2), NP_Ip (0x4)
  3271. // Luckily, these are the same definitions as for win9x, except
  3272. // each bit represents a protocol that is _enabled_ not
  3273. // _disabled_. Therefore, all we need to do is reverse the bottom
  3274. // three bits of the number.
  3275. //
  3276. if (!pGetRasDataFromMemDb (S_PROTOCOLS, &d)) {
  3277. //
  3278. // No data found, so we default to all protocols enabled.
  3279. //
  3280. return S_ZERO;
  3281. }
  3282. wsprintf (g_TempBuffer, TEXT("%d"), ~d.Value & 0x7);
  3283. return g_TempBuffer;
  3284. }
  3285. PCTSTR
  3286. pGetVpnStrategy (
  3287. VOID
  3288. )
  3289. {
  3290. if (g_CurrentDeviceType == RASTYPE_VPN) {
  3291. return TEXT("2");
  3292. }
  3293. return S_EMPTY;
  3294. }
  3295. PCTSTR
  3296. pGetBaseProtocol (
  3297. VOID
  3298. )
  3299. {
  3300. MEMDB_RAS_DATA d;
  3301. //
  3302. // Only supported protocol types for NT 5 are
  3303. // BP_PPP (0x1), BP_SLIP (0x2), and BP_RAS (0x3)
  3304. //
  3305. // If we can't find one, we default to BP_PPP.
  3306. //
  3307. if (!pGetRasDataFromMemDb (S_SMM, &d) || StringIMatch (d.String, S_PPP)) {
  3308. return S_ONE;
  3309. }
  3310. //
  3311. // MaP CSLIP to SLIP -- Header Compression will be on.
  3312. //
  3313. if (StringIMatch (d.String, S_SLIP) || StringIMatch (d.String, S_CSLIP)) {
  3314. return TEXT("2");
  3315. }
  3316. DEBUGMSG ((
  3317. DBG_WARNING,
  3318. "RAS Migration: Unusable base protocol type (%s) for entry %s. Forcing PPP.",
  3319. d.String,
  3320. g_CurrentConnection
  3321. ));
  3322. // we are going to return an invalid protocol so the connection
  3323. // does not get migrated.
  3324. return TEXT("3");
  3325. }
  3326. PCTSTR
  3327. pGetCredPassword (
  3328. VOID
  3329. )
  3330. {
  3331. return S_EMPTY;
  3332. }
  3333. PCTSTR
  3334. pGetCredDomain (
  3335. VOID
  3336. )
  3337. {
  3338. MEMDB_RAS_DATA d;
  3339. if (!pGetRasDataFromMemDb (S_DOMAIN, &d)) {
  3340. return S_EMPTY;
  3341. }
  3342. return d.String;
  3343. }
  3344. PCTSTR
  3345. pGetCredName (
  3346. VOID
  3347. )
  3348. {
  3349. MEMDB_RAS_DATA d;
  3350. if (!pGetRasDataFromMemDb (S_USER, &d)) {
  3351. return S_EMPTY;
  3352. }
  3353. return d.String;
  3354. }
  3355. PCTSTR
  3356. pGetCredMask (
  3357. VOID
  3358. )
  3359. {
  3360. return TEXT("0x00000005");
  3361. }
  3362. PCTSTR
  3363. pGetType (
  3364. VOID
  3365. )
  3366. {
  3367. if (g_CurrentDeviceType == RASTYPE_VPN) {
  3368. return TEXT("2");
  3369. }
  3370. else {
  3371. return S_ONE;
  3372. }
  3373. }
  3374. BOOL
  3375. pCreateUserPhonebook (
  3376. IN PCTSTR PbkFile
  3377. )
  3378. {
  3379. PCTSTR tempKey;
  3380. BOOL noError = FALSE;
  3381. MEMDB_RAS_DATA d;
  3382. MEMDB_ENUM e;
  3383. HANDLE file;
  3384. UINT i;
  3385. UINT count;
  3386. tempKey = JoinPathsInPoolEx ((NULL, MEMDB_CATEGORY_RAS_INFO, TEXT("\\*"), NULL));
  3387. if (MemDbEnumFirst (&e, tempKey, ENUMFLAG_ALL, 1, 1)) {
  3388. //
  3389. // Open the phonebook file and set the file pointer to the EOF.
  3390. //
  3391. file = CreateFile (
  3392. PbkFile,
  3393. GENERIC_READ | GENERIC_WRITE,
  3394. 0, // No sharing.
  3395. NULL, // No inheritance
  3396. OPEN_ALWAYS,
  3397. FILE_ATTRIBUTE_NORMAL,
  3398. NULL // No template file.
  3399. );
  3400. if (file == INVALID_HANDLE_VALUE) {
  3401. DEBUGMSG ((DBG_ERROR, "Unable to open the phonebook file (%s)", PbkFile));
  3402. FreePathString (tempKey);
  3403. return FALSE;
  3404. }
  3405. SetFilePointer (file, 0, NULL, FILE_END);
  3406. //
  3407. // Now, enumerate all of the entries and write a phonebook entry to this
  3408. // file for each.
  3409. //
  3410. do {
  3411. g_CurrentConnection = e.KeyName;
  3412. g_CurrentDevice = 0;
  3413. if (!pGetRasDataFromMemDb (S_DEVICE_TYPE, &d)) {
  3414. g_CurrentDeviceType = RASTYPE_PHONE;
  3415. }
  3416. else {
  3417. if (StringIMatch (d.String, S_MODEM)) {
  3418. g_CurrentDeviceType = RASTYPE_PHONE;
  3419. }
  3420. else if (StringIMatch (d.String, S_VPN)) {
  3421. g_CurrentDeviceType = RASTYPE_VPN;
  3422. }
  3423. else {
  3424. g_CurrentDeviceType = RASTYPE_PHONE;
  3425. }
  3426. }
  3427. noError = TRUE;
  3428. //
  3429. // Add this entry to the phonebook.
  3430. //
  3431. //
  3432. // Write title.
  3433. //
  3434. noError &= WriteFileString (file, TEXT("["));
  3435. noError &= WriteFileString (file, g_CurrentConnection);
  3436. noError &= WriteFileString (file, TEXT("]\r\n"));
  3437. //
  3438. // Write base entry settings.
  3439. //
  3440. noError &= pWriteSettings (file, g_EntrySettings);
  3441. if (!pGetRasDataFromMemDb (S_DEVICECOUNT, &d)) {
  3442. count = 1;
  3443. DEBUGMSG ((DBG_WHOOPS, "No devices listed in memdb for connections %s.", g_CurrentConnection));
  3444. }
  3445. else {
  3446. count = d.Value;
  3447. }
  3448. for (i = 0; i < count; i++) {
  3449. g_CurrentDevice = i;
  3450. //
  3451. // Write media settings.
  3452. //
  3453. noError &= WriteFileString (file, TEXT("\r\n"));
  3454. noError &= pWriteSettings (file, g_MediaSettings);
  3455. //
  3456. // Write modem Device settings.
  3457. //
  3458. noError &= WriteFileString (file, TEXT("\r\n"));
  3459. noError &= pWriteSettings (file, g_ModemDeviceSettings);
  3460. noError &= WriteFileString (file, TEXT("\r\n\r\n"));
  3461. }
  3462. g_InSwitchSection = TRUE;
  3463. noError &= WriteFileString (file, TEXT("\r\n"));
  3464. noError &= pWriteSettings (file, g_SwitchDeviceSettings);
  3465. noError &= WriteFileString (file, TEXT("\r\n\r\n"));
  3466. g_InSwitchSection = FALSE;
  3467. if (!noError) {
  3468. LOG ((
  3469. LOG_ERROR,
  3470. "Error while writing phonebook for %s.",
  3471. g_CurrentConnection
  3472. ));
  3473. }
  3474. } while (MemDbEnumNext (&e));
  3475. //
  3476. // Close the handle to the phone book file.
  3477. //
  3478. CloseHandle (file);
  3479. }
  3480. ELSE_DEBUGMSG ((DBG_RASMIG, "No dial-up entries for current user."));
  3481. FreePathString (tempKey);
  3482. return noError;
  3483. }
  3484. MIG_OBJECTSTRINGHANDLE
  3485. pCreate9xPbkFile (
  3486. VOID
  3487. )
  3488. {
  3489. MIG_OBJECTSTRINGHANDLE result = NULL;
  3490. PCTSTR nativeName = NULL;
  3491. TCHAR windir [MAX_PATH];
  3492. BOOL b = FALSE;
  3493. GetWindowsDirectory (windir, MAX_PATH);
  3494. result = IsmCreateObjectHandle (windir, TEXT("usmt.pbk"));
  3495. if (!result) {
  3496. return NULL;
  3497. }
  3498. nativeName = IsmGetNativeObjectName (g_FileTypeId, result);
  3499. if (!nativeName) {
  3500. IsmDestroyObjectHandle (result);
  3501. return NULL;
  3502. }
  3503. if (pIs9xRasInstalled ()) {
  3504. g_DeviceTable = HtAllocWithData (sizeof (PTSTR));
  3505. MYASSERT (g_DeviceTable);
  3506. pInitializeDeviceTable ();
  3507. __try {
  3508. b = pGetPerUserSettings ();
  3509. b = b && pGetPerConnectionSettings ();
  3510. b = b && pCreateUserPhonebook (nativeName);
  3511. }
  3512. __except (TRUE) {
  3513. DEBUGMSG ((DBG_WHOOPS, "Caught an exception while processing ras settings."));
  3514. }
  3515. HtFree (g_DeviceTable);
  3516. }
  3517. IsmReleaseMemory (nativeName);
  3518. if (!b) {
  3519. IsmDestroyObjectHandle (result);
  3520. result = NULL;
  3521. }
  3522. return result;
  3523. }