Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

996 lines
21 KiB

  1. //Copyright (c) 1998 - 2001 Microsoft Corporation
  2. //
  3. //This file contains wrapper C functions for CGlobal Object
  4. //
  5. #include "precomp.h"
  6. #include "utils.h"
  7. #ifndef TLSPERF
  8. #include "global.h"
  9. extern CGlobal *g_CGlobal;
  10. #else
  11. #include "globalPerf.h"
  12. extern CGlobalPerf *g_CGlobal;
  13. #endif
  14. #include "assert.h"
  15. // The following table translates an ascii subset to 6 bit values as follows
  16. // (see rfc 1521):
  17. //
  18. // input hex (decimal)
  19. // 'A' --> 0x00 (0)
  20. // 'B' --> 0x01 (1)
  21. // ...
  22. // 'Z' --> 0x19 (25)
  23. // 'a' --> 0x1a (26)
  24. // 'b' --> 0x1b (27)
  25. // ...
  26. // 'z' --> 0x33 (51)
  27. // '0' --> 0x34 (52)
  28. // ...
  29. // '9' --> 0x3d (61)
  30. // '+' --> 0x3e (62)
  31. // '/' --> 0x3f (63)
  32. //
  33. // Encoded lines must be no longer than 76 characters.
  34. // The final "quantum" is handled as follows: The translation output shall
  35. // always consist of 4 characters. 'x', below, means a translated character,
  36. // and '=' means an equal sign. 0, 1 or 2 equal signs padding out a four byte
  37. // translation quantum means decoding the four bytes would result in 3, 2 or 1
  38. // unencoded bytes, respectively.
  39. //
  40. // unencoded size encoded data
  41. // -------------- ------------
  42. // 1 byte "xx=="
  43. // 2 bytes "xxx="
  44. // 3 bytes "xxxx"
  45. #define CB_BASE64LINEMAX 64 // others use 64 -- could be up to 76
  46. // Any other (invalid) input character value translates to 0x40 (64)
  47. const BYTE abDecode[256] =
  48. {
  49. /* 00: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  50. /* 10: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  51. /* 20: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
  52. /* 30: */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
  53. /* 40: */ 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  54. /* 50: */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
  55. /* 60: */ 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  56. /* 70: */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
  57. /* 80: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  58. /* 90: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  59. /* a0: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  60. /* b0: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  61. /* c0: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  62. /* d0: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  63. /* e0: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  64. /* f0: */ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  65. };
  66. const UCHAR abEncode[] =
  67. /* 0 thru 25: */ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  68. /* 26 thru 51: */ "abcdefghijklmnopqrstuvwxyz"
  69. /* 52 thru 61: */ "0123456789"
  70. /* 62 and 63: */ "+/";
  71. DWORD LSBase64EncodeA(
  72. IN BYTE const *pbIn,
  73. IN DWORD cbIn,
  74. OUT CHAR *pchOut,
  75. OUT DWORD *pcchOut)
  76. {
  77. CHAR *pchOutT;
  78. DWORD cchOutEncode;
  79. // Allocate enough memory for full final translation quantum.
  80. cchOutEncode = ((cbIn + 2) / 3) * 4;
  81. // and enough for CR-LF pairs for every CB_BASE64LINEMAX character line.
  82. cchOutEncode +=
  83. 2 * ((cchOutEncode + CB_BASE64LINEMAX - 1) / CB_BASE64LINEMAX);
  84. pchOutT = pchOut;
  85. if (NULL == pchOut)
  86. {
  87. pchOutT += cchOutEncode;
  88. }
  89. else
  90. {
  91. DWORD cCol;
  92. assert(cchOutEncode <= *pcchOut);
  93. cCol = 0;
  94. while ((long) cbIn > 0) // signed comparison -- cbIn can wrap
  95. {
  96. BYTE ab3[3];
  97. if (cCol == CB_BASE64LINEMAX/4)
  98. {
  99. cCol = 0;
  100. *pchOutT++ = '\r';
  101. *pchOutT++ = '\n';
  102. }
  103. cCol++;
  104. memset(ab3, 0, sizeof(ab3));
  105. ab3[0] = *pbIn++;
  106. if (cbIn > 1)
  107. {
  108. ab3[1] = *pbIn++;
  109. if (cbIn > 2)
  110. {
  111. ab3[2] = *pbIn++;
  112. }
  113. }
  114. *pchOutT++ = abEncode[ab3[0] >> 2];
  115. *pchOutT++ = abEncode[((ab3[0] << 4) | (ab3[1] >> 4)) & 0x3f];
  116. *pchOutT++ = (cbIn > 1)?
  117. abEncode[((ab3[1] << 2) | (ab3[2] >> 6)) & 0x3f] : '=';
  118. *pchOutT++ = (cbIn > 2)? abEncode[ab3[2] & 0x3f] : '=';
  119. cbIn -= 3;
  120. }
  121. *pchOutT++ = '\r';
  122. *pchOutT++ = '\n';
  123. assert((DWORD) (pchOutT - pchOut) <= cchOutEncode);
  124. }
  125. *pcchOut = (DWORD)(pchOutT - pchOut);
  126. return(ERROR_SUCCESS);
  127. }
  128. DWORD LSBase64DecodeA(
  129. IN CHAR const *pchIn,
  130. IN DWORD cchIn,
  131. OUT BYTE *pbOut,
  132. OUT DWORD *pcbOut)
  133. {
  134. DWORD err = ERROR_SUCCESS;
  135. DWORD cchInDecode, cbOutDecode;
  136. CHAR const *pchInEnd;
  137. CHAR const *pchInT;
  138. BYTE *pbOutT;
  139. // Count the translatable characters, skipping whitespace & CR-LF chars.
  140. cchInDecode = 0;
  141. pchInEnd = &pchIn[cchIn];
  142. for (pchInT = pchIn; pchInT < pchInEnd; pchInT++)
  143. {
  144. if (sizeof(abDecode) < (unsigned) *pchInT || abDecode[*pchInT] > 63)
  145. {
  146. // skip all whitespace
  147. if (*pchInT == ' ' ||
  148. *pchInT == '\t' ||
  149. *pchInT == '\r' ||
  150. *pchInT == '\n')
  151. {
  152. continue;
  153. }
  154. if (0 != cchInDecode)
  155. {
  156. if ((cchInDecode % 4) == 0)
  157. {
  158. break; // ends on quantum boundary
  159. }
  160. // The length calculation may stop in the middle of the last
  161. // translation quantum, because the equal sign padding
  162. // characters are treated as invalid input. If the last
  163. // translation quantum is not 4 bytes long, it must be 2 or 3
  164. // bytes long.
  165. if (*pchInT == '=' && (cchInDecode % 4) != 1)
  166. {
  167. break; // normal termination
  168. }
  169. }
  170. err = ERROR_INVALID_DATA;
  171. goto error;
  172. }
  173. cchInDecode++;
  174. }
  175. assert(pchInT <= pchInEnd);
  176. pchInEnd = pchInT; // don't process any trailing stuff again
  177. // We know how many translatable characters are in the input buffer, so now
  178. // set the output buffer size to three bytes for every four (or fraction of
  179. // four) input bytes.
  180. cbOutDecode = ((cchInDecode + 3) / 4) * 3;
  181. pbOutT = pbOut;
  182. if (NULL == pbOut)
  183. {
  184. pbOutT += cbOutDecode;
  185. }
  186. else
  187. {
  188. // Decode one quantum at a time: 4 bytes ==> 3 bytes
  189. assert(cbOutDecode <= *pcbOut);
  190. pchInT = pchIn;
  191. while (cchInDecode > 0)
  192. {
  193. DWORD i;
  194. BYTE ab4[4];
  195. memset(ab4, 0, sizeof(ab4));
  196. for (i = 0; i < min(sizeof(ab4)/sizeof(ab4[0]), cchInDecode); i++)
  197. {
  198. while (
  199. sizeof(abDecode) > (unsigned) *pchInT &&
  200. 63 < abDecode[*pchInT])
  201. {
  202. pchInT++;
  203. }
  204. assert(pchInT < pchInEnd);
  205. ab4[i] = (BYTE) *pchInT++;
  206. }
  207. // Translate 4 input characters into 6 bits each, and deposit the
  208. // resulting 24 bits into 3 output bytes by shifting as appropriate.
  209. // out[0] = in[0]:in[1] 6:2
  210. // out[1] = in[1]:in[2] 4:4
  211. // out[2] = in[2]:in[3] 2:6
  212. *pbOutT++ =
  213. (BYTE) ((abDecode[ab4[0]] << 2) | (abDecode[ab4[1]] >> 4));
  214. if (i > 2)
  215. {
  216. *pbOutT++ =
  217. (BYTE) ((abDecode[ab4[1]] << 4) | (abDecode[ab4[2]] >> 2));
  218. }
  219. if (i > 3)
  220. {
  221. *pbOutT++ = (BYTE) ((abDecode[ab4[2]] << 6) | abDecode[ab4[3]]);
  222. }
  223. cchInDecode -= i;
  224. }
  225. assert((DWORD) (pbOutT - pbOut) <= cbOutDecode);
  226. }
  227. *pcbOut = (DWORD)(pbOutT - pbOut);
  228. error:
  229. return(err);
  230. }
  231. #ifndef TLSPERF
  232. CGlobal * GetGlobalContext(void)
  233. #else
  234. CGlobalPerf * GetGlobalContext(void)
  235. #endif
  236. {
  237. return g_CGlobal;
  238. }
  239. DWORD WINAPI ProcessThread(void *pData)
  240. {
  241. DWORD dwRetCode = ERROR_SUCCESS;
  242. dwRetCode = ProcessRequest();
  243. /*
  244. DWORD dwTime = 1;
  245. HWND *phProgress = (HWND *)pData;
  246. SendMessage(g_hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM(0,PROGRESS_MAX_VAL));
  247. //
  248. // Increment the progress bar every second till you get Progress Event
  249. //
  250. SendMessage(g_hProgressWnd, PBM_SETPOS ,(WPARAM)1, 0);
  251. do
  252. {
  253. SendMessage(g_hProgressWnd, PBM_DELTAPOS ,(WPARAM)PROGRESS_STEP_VAL, 0);
  254. }
  255. while(WAIT_TIMEOUT == WaitForSingleObject(g_hProgressEvent,PROGRESS_SLEEP_TIME));
  256. SendMessage(g_hProgressWnd, PBM_SETPOS ,(WPARAM)PROGRESS_MAX_VAL, 0);
  257. */
  258. ExitThread(0);
  259. return 0;
  260. }
  261. static DWORD (*g_pfnThread)(void *);
  262. static void * g_vpData;
  263. static DWORD g_dwProgressTitleID = 0;
  264. LRW_DLG_INT CALLBACK
  265. ProgressProc(
  266. IN HWND hwnd,
  267. IN UINT uMsg,
  268. IN WPARAM wParam,
  269. IN LPARAM lParam
  270. );
  271. //
  272. // fActivationWizard is TRUE for the activation wizard
  273. // otherwise it's the CAL wizard
  274. //
  275. DWORD ShowProgressBox(HWND hwnd,
  276. DWORD (*pfnThread)(void *vpData),
  277. DWORD dwTitle,
  278. DWORD dwProgressText,
  279. void * vpData)
  280. {
  281. DWORD dwReturn = ERROR_SUCCESS;
  282. g_pfnThread = pfnThread;
  283. g_vpData = vpData;
  284. g_dwProgressTitleID = dwTitle;
  285. DialogBox( GetGlobalContext()->GetInstanceHandle(),
  286. MAKEINTRESOURCE(IDD_AUTHENTICATE),
  287. hwnd,
  288. ProgressProc);
  289. return dwReturn;
  290. }
  291. LRW_DLG_INT CALLBACK
  292. ProgressProc(
  293. IN HWND hwnd,
  294. IN UINT uMsg,
  295. IN WPARAM wParam,
  296. IN LPARAM lParam
  297. )
  298. {
  299. BOOL bStatus = FALSE;
  300. static int nCounter;
  301. static HWND hProgress;
  302. static HANDLE hThread;
  303. TCHAR szMsg[LR_MAX_MSG_TEXT];
  304. if (uMsg == WM_INITDIALOG)
  305. {
  306. DWORD dwTID = 0;
  307. ShowWindow(hwnd, SW_SHOWNORMAL);
  308. SetTimer(hwnd, 1, 500, NULL);
  309. hProgress = GetDlgItem(hwnd, IDC_PROGRESSBAR);
  310. hThread = CreateThread(NULL, 0, g_pfnThread, g_vpData, 0, &dwTID);
  311. if (g_dwProgressTitleID) {
  312. if (-1 != LoadString(GetInstanceHandle(), g_dwProgressTitleID,
  313. szMsg,LR_MAX_MSG_TEXT)) {
  314. SetWindowText(hwnd, szMsg);
  315. }
  316. }
  317. //Set the range & the initial position
  318. SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM(0,PROGRESS_MAX_VAL));
  319. SendMessage(hProgress, PBM_SETPOS ,(WPARAM)0, 0);
  320. // Set Title & the Introductory text
  321. // Create thread to process the request
  322. }
  323. else if (uMsg == WM_CLOSE)
  324. {
  325. KillTimer(hwnd, 1);
  326. }
  327. else if (uMsg == WM_TIMER)
  328. {
  329. if (WAIT_OBJECT_0 != WaitForSingleObject(hThread, 0))
  330. {
  331. nCounter++;
  332. if (nCounter < PROGRESS_MAX_VAL-5)
  333. {
  334. SendMessage(hProgress, PBM_DELTAPOS ,(WPARAM)PROGRESS_STEP_VAL, 0);
  335. }
  336. }
  337. else
  338. {
  339. SendMessage(hProgress, PBM_SETPOS ,(WPARAM)PROGRESS_MAX_VAL, 0);
  340. CloseHandle(hThread);
  341. EndDialog(hwnd, 0);
  342. }
  343. }
  344. return bStatus;
  345. }
  346. void SetInstanceHandle(HINSTANCE hInst)
  347. {
  348. g_CGlobal->SetInstanceHandle(hInst);
  349. }
  350. void SetLSName(LPTSTR lpstrLSName)
  351. {
  352. g_CGlobal->SetLSName(lpstrLSName);
  353. }
  354. HINSTANCE GetInstanceHandle()
  355. {
  356. return g_CGlobal->GetInstanceHandle();
  357. }
  358. DWORD InitGlobal()
  359. {
  360. return g_CGlobal->InitGlobal();
  361. }
  362. DWORD CheckRequieredFields()
  363. {
  364. return g_CGlobal->CheckRequieredFields();
  365. }
  366. //
  367. // This function loads the Message Text from the String Table and displays
  368. // the given message
  369. //
  370. int LRMessageBox(HWND hWndParent,DWORD dwMsgId,DWORD dwCaptionID /*= 0*/,DWORD dwErrorCode /*=0*/)
  371. {
  372. return g_CGlobal->LRMessageBox(hWndParent,dwMsgId,dwCaptionID,dwErrorCode);
  373. }
  374. //
  375. // This function tries to connect to the LS using LSAPI and returns TRUE if
  376. // successful to connect else returns FALSE
  377. //
  378. BOOL IsLSRunning()
  379. {
  380. return g_CGlobal->IsLSRunning();
  381. }
  382. //
  383. // This function gets LS Certs and stores Certs & Cert Extensions in the
  384. // CGlobal object. If no certs , it returns IDS_ERR_NO_CERT
  385. //
  386. //
  387. // This function is used only in ONLINE mode to authenticate LS.
  388. // Assumption - GetLSCertificates should have been called before calling
  389. // this function.
  390. //
  391. DWORD AuthenticateLS()
  392. {
  393. return g_CGlobal->AuthenticateLS();
  394. }
  395. DWORD LRGetLastError()
  396. {
  397. return g_CGlobal->LRGetLastError();
  398. }
  399. TCHAR * GetRegistrationID(void)
  400. {
  401. return g_CGlobal->GetRegistrationID();
  402. }
  403. TCHAR * GetLicenseServerID(void)
  404. {
  405. return g_CGlobal->GetLicenseServerID();
  406. }
  407. void SetRequestType(DWORD dwMode)
  408. {
  409. g_CGlobal->SetRequestType(dwMode);
  410. }
  411. int GetRequestType(void)
  412. {
  413. return g_CGlobal->GetRequestType();
  414. }
  415. BOOL IsOnlineCertRequestCreated()
  416. {
  417. return g_CGlobal->IsOnlineCertRequestCreated();
  418. }
  419. DWORD SetLRState(DWORD dwState)
  420. {
  421. return g_CGlobal->SetLRState(dwState);
  422. }
  423. DWORD SetCertificatePIN(LPTSTR lpszPIN)
  424. {
  425. return g_CGlobal->SetCertificatePIN(lpszPIN);
  426. }
  427. DWORD PopulateCountryComboBox(HWND hWndCmb)
  428. {
  429. return g_CGlobal->PopulateCountryComboBox(hWndCmb);
  430. }
  431. DWORD GetCountryCode(CString sDesc,LPTSTR szCode)
  432. {
  433. return g_CGlobal->GetCountryCode(sDesc,szCode);
  434. }
  435. DWORD PopulateProductComboBox(HWND hWndCmb, ProductVersionType VerType)
  436. {
  437. return g_CGlobal->PopulateProductComboBox(hWndCmb, VerType);
  438. }
  439. DWORD GetProductCode(CString sDesc,LPTSTR szCode)
  440. {
  441. return g_CGlobal->GetProductCode(sDesc,szCode);
  442. }
  443. DWORD PopulateReasonComboBox(HWND hWndCmb, DWORD dwType)
  444. {
  445. return g_CGlobal->PopulateReasonComboBox(hWndCmb, dwType);
  446. }
  447. DWORD GetReasonCode(CString sDesc,LPTSTR szCode, DWORD dwType)
  448. {
  449. return g_CGlobal->GetReasonCode(sDesc,szCode, dwType);
  450. }
  451. DWORD ProcessRequest()
  452. {
  453. return g_CGlobal->ProcessRequest();
  454. }
  455. void LRSetLastRetCode(DWORD dwCode)
  456. {
  457. g_CGlobal->LRSetLastRetCode(dwCode);
  458. }
  459. DWORD LRGetLastRetCode()
  460. {
  461. return g_CGlobal->LRGetLastRetCode();
  462. }
  463. void LRPush(DWORD dwPageId)
  464. {
  465. g_CGlobal->LRPush(dwPageId);
  466. }
  467. DWORD LRPop()
  468. {
  469. return g_CGlobal->LRPop();
  470. }
  471. BOOL ValidateEmailId(CString sEmailId)
  472. {
  473. return g_CGlobal->ValidateEmailId(sEmailId);
  474. }
  475. BOOL CheckProgramValidity(CString sProgramName)
  476. {
  477. return g_CGlobal->CheckProgramValidity(sProgramName);
  478. }
  479. BOOL ValidateLRString(CString sStr)
  480. {
  481. return g_CGlobal->ValidateLRString(sStr);
  482. }
  483. void ReadPhoneNumberFromRegistry(LPCTSTR lpCountry, LPTSTR lpPhoneNumber, DWORD nBufferSize)
  484. {
  485. g_CGlobal->ReadPhoneNumberFromRegistry(lpCountry, lpPhoneNumber, nBufferSize);
  486. }
  487. DWORD PopulateCountryRegionComboBox(HWND hWndCmb)
  488. {
  489. return g_CGlobal->PopulateCountryRegionComboBox(hWndCmb);
  490. }
  491. DWORD PopulateCountryRegionListBox(HWND hWndLst)
  492. {
  493. return g_CGlobal->PopulateCountryRegionListBox(hWndLst);
  494. }
  495. DWORD SetLSLKP(TCHAR * tcLKP)
  496. {
  497. return g_CGlobal->SetLSLKP(tcLKP);
  498. }
  499. DWORD PingCH(void)
  500. {
  501. return g_CGlobal->PingCH();
  502. }
  503. DWORD AddRetailSPKToList(HWND hListView, TCHAR * lpszRetailSPK)
  504. {
  505. return g_CGlobal->AddRetailSPKToList(hListView, lpszRetailSPK);
  506. }
  507. void DeleteRetailSPKFromList(TCHAR * lpszRetailSPK)
  508. {
  509. g_CGlobal->DeleteRetailSPKFromList(lpszRetailSPK);
  510. return;
  511. }
  512. void LoadFinishedFromList(HWND hListView)
  513. {
  514. g_CGlobal->LoadFinishedFromList(hListView);
  515. return;
  516. }
  517. void LoadUnfinishedFromList(HWND hListView)
  518. {
  519. g_CGlobal->LoadUnfinishedFromList(hListView);
  520. return;
  521. }
  522. void LoadFromList(HWND hListView)
  523. {
  524. g_CGlobal->LoadFromList(hListView);
  525. return;
  526. }
  527. void UpdateSPKStatus(TCHAR * lpszRetailSPK, TCHAR tcStatus)
  528. {
  529. g_CGlobal->UpdateSPKStatus(lpszRetailSPK, tcStatus);
  530. return;
  531. }
  532. DWORD SetConfirmationNumber(TCHAR * tcConf)
  533. {
  534. return g_CGlobal->SetConfirmationNumber(tcConf);
  535. }
  536. DWORD SetLSSPK(TCHAR * tcp)
  537. {
  538. return g_CGlobal->SetLSSPK(tcp);
  539. }
  540. void SetCSRNumber(TCHAR * tcp)
  541. {
  542. g_CGlobal->SetCSRNumber(tcp);
  543. return;
  544. }
  545. TCHAR * GetCSRNumber(void)
  546. {
  547. return g_CGlobal->GetCSRNumber();
  548. }
  549. void SetWWWSite(TCHAR * tcp)
  550. {
  551. g_CGlobal->SetWWWSite(tcp);
  552. return;
  553. }
  554. TCHAR * GetWWWSite(void)
  555. {
  556. return g_CGlobal->GetWWWSite();
  557. }
  558. DWORD ResetLSSPK(void)
  559. {
  560. return g_CGlobal->ResetLSSPK();
  561. }
  562. void SetReFresh(DWORD dw)
  563. {
  564. g_CGlobal->SetReFresh(dw);
  565. }
  566. DWORD GetReFresh(void)
  567. {
  568. return g_CGlobal->GetReFresh();
  569. }
  570. void SetModifiedRetailSPK(CString sRetailSPK)
  571. {
  572. g_CGlobal->SetModifiedRetailSPK(sRetailSPK);
  573. }
  574. void GetModifiedRetailSPK(CString &sRetailSPK)
  575. {
  576. g_CGlobal->GetModifiedRetailSPK(sRetailSPK);
  577. }
  578. void ModifyRetailSPKFromList(TCHAR * lpszOldSPK,TCHAR * lpszNewSPK)
  579. {
  580. g_CGlobal->ModifyRetailSPKFromList(lpszOldSPK,lpszNewSPK);
  581. }
  582. DWORD ValidateRetailSPK(TCHAR * lpszRetailSPK)
  583. {
  584. return g_CGlobal->ValidateRetailSPK(lpszRetailSPK);
  585. }
  586. DWORD GetCountryDesc(CString sCode,LPTSTR szDesc)
  587. {
  588. return g_CGlobal->GetCountryDesc(sCode, szDesc);
  589. }
  590. DWORD CGlobal::SetEncodedInRegistry(LPCSTR lpszOID, LPCTSTR lpszValue)
  591. {
  592. HKEY hKey = NULL;
  593. DWORD dwDisposition = 0;
  594. DWORD dwRetCode = ERROR_SUCCESS;
  595. DWORD dwLen = 0;
  596. char * cpOut;
  597. HCRYPTPROV hProv = NULL;
  598. HCRYPTKEY hCKey = NULL;
  599. HCRYPTHASH hHash = NULL;
  600. PBYTE pbKey = NULL;
  601. DWORD cbKey = 0;
  602. if(!CryptAcquireContext(&hProv,
  603. NULL,
  604. NULL,
  605. PROV_RSA_FULL,
  606. CRYPT_VERIFYCONTEXT))
  607. {
  608. dwRetCode = GetLastError();
  609. goto done;
  610. }
  611. if(!CryptCreateHash(hProv,
  612. CALG_MD5,
  613. 0,
  614. 0,
  615. &hHash))
  616. {
  617. dwRetCode = GetLastError();
  618. goto done;
  619. }
  620. if(!CryptHashData(hHash,
  621. (BYTE *) lpszValue,
  622. lstrlen(lpszValue)*sizeof(TCHAR),
  623. 0))
  624. {
  625. dwRetCode = GetLastError();
  626. goto done;
  627. }
  628. if(!CryptDeriveKey(hProv,
  629. CALG_RC4,
  630. hHash,
  631. CRYPT_EXPORTABLE,
  632. &hCKey))
  633. {
  634. dwRetCode = GetLastError();
  635. goto done;
  636. }
  637. if(!CryptExportKey(
  638. hCKey,
  639. NULL,
  640. PUBLICKEYBLOB,
  641. 0,
  642. NULL,
  643. &cbKey))
  644. {
  645. dwRetCode = GetLastError();
  646. if(dwRetCode != ERROR_SUCCESS && dwRetCode != ERROR_MORE_DATA)
  647. goto done;
  648. pbKey = (PBYTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,cbKey);
  649. if(!CryptExportKey(
  650. hCKey,
  651. NULL,
  652. PUBLICKEYBLOB,
  653. 0,
  654. pbKey,
  655. &cbKey))
  656. {
  657. dwRetCode = GetLastError();
  658. goto done;
  659. }
  660. }
  661. dwRetCode = ConnectToLSRegistry();
  662. if(dwRetCode != ERROR_SUCCESS)
  663. {
  664. goto done;
  665. }
  666. dwRetCode = RegCreateKeyEx ( m_hLSRegKey,
  667. REG_LRWIZ_PARAMS,
  668. 0,
  669. NULL,
  670. REG_OPTION_NON_VOLATILE,
  671. KEY_ALL_ACCESS,
  672. NULL,
  673. &hKey,
  674. &dwDisposition);
  675. if(dwRetCode != ERROR_SUCCESS)
  676. {
  677. LRSetLastError(dwRetCode);
  678. dwRetCode = IDS_ERR_REGCREATE_FAILED;
  679. goto done;
  680. }
  681. if (_tcslen(lpszValue) != 0)
  682. {
  683. LSBase64EncodeA ((PBYTE) lpszValue, _tcslen(lpszValue)*sizeof(TCHAR), NULL, &dwLen);
  684. cpOut = new char[dwLen+1];
  685. if (cpOut == NULL)
  686. {
  687. dwRetCode = IDS_ERR_OUTOFMEM;
  688. goto done;
  689. }
  690. memset(cpOut, 0, dwLen+1);
  691. LSBase64EncodeA ((PBYTE) lpszValue, _tcslen(lpszValue)*sizeof(TCHAR), cpOut, &dwLen);
  692. }
  693. else
  694. {
  695. cpOut = new char[2];
  696. memset(cpOut, 0, 2);
  697. }
  698. RegSetValueExA ( hKey,
  699. lpszOID,
  700. 0,
  701. REG_SZ,
  702. (PBYTE) cpOut,
  703. dwLen
  704. );
  705. delete[] cpOut;
  706. done:
  707. if (hKey != NULL)
  708. {
  709. RegCloseKey(hKey);
  710. }
  711. DisconnectLSRegistry();
  712. return dwRetCode;
  713. }
  714. void AddHyperLinkToStaticCtl(HWND hDialog, DWORD nTextBox)
  715. {
  716. RECT rcTextCtrl;
  717. //Read the text that's already in the control.
  718. TCHAR tchBuffer[512];
  719. GetWindowText(GetDlgItem(hDialog, nTextBox), tchBuffer, SIZE_OF_BUFFER(tchBuffer));
  720. //Get the control dimensions
  721. GetWindowRect(GetDlgItem(hDialog, nTextBox) , &rcTextCtrl);
  722. //Registration info for the control
  723. MapWindowPoints(NULL, hDialog, (LPPOINT)&rcTextCtrl, 2);
  724. LinkWindow_RegisterClass();
  725. //Now create the window (using the same dimensions as the
  726. //hidden control) that will contain the link
  727. HWND hLW = CreateWindowEx(0,
  728. TEXT("Link Window") ,
  729. TEXT("") ,
  730. WS_CLIPSIBLINGS | WS_CHILD | WS_VISIBLE,
  731. rcTextCtrl.left,
  732. rcTextCtrl.top,
  733. RECTWIDTH(rcTextCtrl),
  734. RECTHEIGHT(rcTextCtrl),
  735. hDialog,
  736. (HMENU)12,
  737. NULL,
  738. NULL);
  739. //Now write it to the link window
  740. SetWindowText(hLW, tchBuffer);
  741. }
  742. void DisplayPrivacyHelp()
  743. {
  744. TCHAR * pHtml = L"ts_lice_c_070.htm";
  745. HtmlHelp(AfxGetMainWnd()->m_hWnd, L"tslic.chm", HH_DISPLAY_TOPIC,(DWORD_PTR)pHtml);
  746. }
  747. DWORD
  748. GetStringIDFromProgramName(CString& sProgramName)
  749. {
  750. DWORD dwId = -1;
  751. if (sProgramName == PROGRAM_LICENSE_PAK)
  752. {
  753. dwId = IDS_PROGRAM_LICENSE_PAK;
  754. }
  755. else if (sProgramName == PROGRAM_MOLP)
  756. {
  757. dwId = IDS_PROGRAM_OPEN_LICENSE;
  758. }
  759. else if (sProgramName == PROGRAM_SELECT)
  760. {
  761. dwId = IDS_PROGRAM_SELECT;
  762. }
  763. else if (sProgramName == PROGRAM_ENTERPRISE)
  764. {
  765. dwId = IDS_PROGRAM_ENTERPRISE;
  766. }
  767. else if (sProgramName == PROGRAM_CAMPUS_AGREEMENT)
  768. {
  769. dwId = IDS_PROGRAM_CAMPUS_AGREEMENT;
  770. }
  771. else if (sProgramName == PROGRAM_SCHOOL_AGREEMENT)
  772. {
  773. dwId = IDS_PROGRAM_SCHOOL_AGREEMENT;
  774. }
  775. else if (sProgramName == PROGRAM_APP_SERVICES)
  776. {
  777. dwId = IDS_PROGRAM_APP_SERVICES_AGREEMENT;
  778. }
  779. else if (sProgramName == PROGRAM_OTHER)
  780. {
  781. dwId = IDS_PROGRAM_OTHER;
  782. }
  783. else
  784. {
  785. dwId = IDS_PROGRAM_OTHER;
  786. }
  787. return dwId;
  788. }