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.

849 lines
29 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. #include "snapmgr.h"
  10. #include "util.h"
  11. #include "regvldlg.h"
  12. //#include <shlwapi.h>
  13. //#include <shlwapip.h>
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. long GetRegValueItemID(LPCWSTR szItem) //Raid #510407, 2/24/2002, yanggao
  20. {
  21. long itemID = 0;
  22. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\NTDS\\Parameters\\LDAPServerIntegrity") == 0 )
  23. {
  24. itemID = IDS_LDAPSERVERINTEGRITY;
  25. }else
  26. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\SignSecureChannel") == 0 )
  27. {
  28. itemID = IDS_SIGNSECURECHANNEL;
  29. }else
  30. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\SealSecureChannel") == 0 )
  31. {
  32. itemID = IDS_SEALSECURECHANNEL;
  33. }else
  34. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\RequireStrongKey") == 0 )
  35. {
  36. itemID = IDS_REQUIRESTRONGKEY;
  37. }else
  38. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\RequireSignOrSeal") == 0 )
  39. {
  40. itemID = IDS_REQUIRESIGNORSEAL;
  41. }else
  42. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\RefusePasswordChange") == 0 )
  43. {
  44. itemID = IDS_REFUSEPASSWORDCHANGE;
  45. }else
  46. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\MaximumPasswordAge") == 0 )
  47. {
  48. itemID = IDS_MAXIMUMPASSWORDAGE;
  49. }else
  50. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters\\DisablePasswordChange") == 0 )
  51. {
  52. itemID = IDS_DISABLEPASSWORDCHANGE;
  53. }else
  54. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LDAP\\LDAPClientIntegrity") == 0 )
  55. {
  56. itemID = IDS_LDAPCLIENTINTEGRITY;
  57. }else
  58. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanmanWorkstation\\Parameters\\RequireSecuritySignature") == 0 )
  59. {
  60. itemID = IDS_REQUIRESECURITYSIGNATURE;
  61. }else
  62. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanmanWorkstation\\Parameters\\EnableSecuritySignature") == 0 )
  63. {
  64. itemID = IDS_ENABLESECURITYSIGNATURE;
  65. }else
  66. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanmanWorkstation\\Parameters\\EnablePlainTextPassword") == 0 )
  67. {
  68. itemID = IDS_ENABLEPLAINTEXTPASSWORD;
  69. }else
  70. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\RestrictNullSessAccess") == 0 )
  71. {
  72. itemID = IDS_RESTRICTNULLSESSACCESS;
  73. }else
  74. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\RequireSecuritySignature") == 0 )
  75. {
  76. itemID = IDS_SERREQUIRESECURITYSIGNATURE;
  77. }else
  78. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\NullSessionShares") == 0 )
  79. {
  80. itemID = IDS_NULLSESSIONSHARES;
  81. }else
  82. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\NullSessionPipes") == 0 )
  83. {
  84. itemID = IDS_NULLSESSIONPIPES;
  85. }else
  86. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\EnableSecuritySignature") == 0 )
  87. {
  88. itemID = IDS_SERENABLESECURITYSIGNATURE;
  89. }else
  90. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\EnableForcedLogOff") == 0 )
  91. {
  92. itemID = IDS_ENABLEFORCEDLOGOFF;
  93. }else
  94. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Services\\LanManServer\\Parameters\\AutoDisconnect") == 0 )
  95. {
  96. itemID = IDS_AUTODISCONNECT;
  97. }else
  98. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\ProtectionMode") == 0 )
  99. {
  100. itemID = IDS_PROTECTIONMODE;
  101. }else
  102. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Memory Management\\ClearPageFileAtShutdown") == 0 )
  103. {
  104. itemID = IDS_CLEARPAGEFILEATSHUTDOWN;
  105. }else
  106. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Kernel\\ObCaseInsensitive") == 0 )
  107. {
  108. itemID = IDS_OBCASEINSENSITIVE;
  109. }else
  110. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\SecurePipeServers\\Winreg\\AllowedPaths\\Machine") == 0 )
  111. {
  112. itemID = IDS_MACHINE;
  113. }else
  114. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Print\\Providers\\LanMan Print Services\\Servers\\AddPrinterDrivers") == 0 )
  115. {
  116. itemID = IDS_ADDPRINTERDRIVERS;
  117. }else
  118. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\SubmitControl") == 0 )
  119. {
  120. itemID = IDS_SUBMITCONTROL;
  121. }else
  122. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\RestrictAnonymousSAM") == 0 )
  123. {
  124. itemID = IDS_RESTRICTANONYMOUSSAM;
  125. }else
  126. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\RestrictAnonymous") == 0 )
  127. {
  128. itemID = IDS_RESTRICTANONYMOUS;
  129. }else
  130. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\NoLMHash") == 0 )
  131. {
  132. itemID = IDS_NOLMHASH;
  133. }else
  134. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\NoDefaultAdminOwner") == 0 )
  135. {
  136. itemID = IDS_NODEFAULTADMINOWNER;
  137. }else
  138. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\MSV1_0\\NTLMMinServerSec") == 0 )
  139. {
  140. itemID = IDS_NTLMMINSERVERSEC;
  141. }else
  142. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\MSV1_0\\NTLMMinClientSec") == 0 )
  143. {
  144. itemID = IDS_NTLMMINCLIENTSEC;
  145. }else
  146. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\LmCompatibilityLevel") == 0 )
  147. {
  148. itemID = IDS_LMCOMPATIBILITYLEVEL;
  149. }else
  150. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\LimitBlankPasswordUse") == 0 )
  151. {
  152. itemID = IDS_LIMITBLANKPASSWORDUSE;
  153. }else
  154. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\FullPrivilegeAuditing") == 0 )
  155. {
  156. itemID = IDS_FULLPRIVILEGEAUDITING;
  157. }else
  158. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\ForceGuest") == 0 )
  159. {
  160. itemID = IDS_FORCEGUEST;
  161. }else
  162. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy") == 0 )
  163. {
  164. itemID = IDS_FIPSALGORITHMPOLICY;
  165. }else
  166. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\EveryoneIncludesAnonymous") == 0 )
  167. {
  168. itemID = IDS_EVERYONEINCLUDESANONYMOUS;
  169. }else
  170. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\DisableDomainCreds") == 0 )
  171. {
  172. itemID = IDS_DISABLEDOMAINCREDS;
  173. }else
  174. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\CrashOnAuditFail") == 0 )
  175. {
  176. itemID = IDS_CRASHONAUDITFAIL;
  177. }else
  178. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\AuditBaseObjects") == 0 )
  179. {
  180. itemID = IDS_AUDITBASEOBJECTS;
  181. }else
  182. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\UndockWithoutLogon") == 0 )
  183. {
  184. itemID = IDS_UNDOCKWITHOUTLOGON;
  185. }else
  186. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\ShutdownWithoutLogon") == 0 )
  187. {
  188. itemID = IDS_SHUTDOWNWITHOUTLOGON;
  189. }else
  190. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\ScForceOption") == 0 )
  191. {
  192. itemID = IDS_SCFORCEOPTION;
  193. }else
  194. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\LegalNoticeText") == 0 )
  195. {
  196. itemID = IDS_LEGALNOTICETEXT;
  197. }else
  198. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\LegalNoticeCaption") == 0 )
  199. {
  200. itemID = IDS_LEGALNOTICECAPTION;
  201. }else
  202. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\DontDisplayLastUserName") == 0 )
  203. {
  204. itemID = IDS_DONTDISPLAYLASTUSERNAME;
  205. }else
  206. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\DisableCAD") == 0 )
  207. {
  208. itemID = IDS_DISABLECAD;
  209. }else
  210. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\ScRemoveOption") == 0 )
  211. {
  212. itemID = IDS_SCREMOVEOPTION;
  213. }else
  214. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\PasswordExpiryWarning") == 0 )
  215. {
  216. itemID = IDS_PASSWORDEXPIRYWARNING;
  217. }else
  218. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\ForceUnlockLogon") == 0 )
  219. {
  220. itemID = IDS_FORCEUNLOCKLOGON;
  221. }else
  222. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\CachedLogonsCount") == 0 )
  223. {
  224. itemID = IDS_CACHEDLOGONSCOUNT;
  225. }else
  226. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\AllocateFloppies") == 0 )
  227. {
  228. itemID = IDS_ALLOCATEFLOPPIES;
  229. }else
  230. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\AllocateDASD") == 0 )
  231. {
  232. itemID = IDS_ALLOCATEDASD;
  233. }else
  234. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\AllocateCDRoms") == 0 )
  235. {
  236. itemID = IDS_ALLOCATECDROMS;
  237. }else
  238. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Setup\\RecoveryConsole\\SetCommand") == 0 )
  239. {
  240. itemID = IDS_SETCOMMAND;
  241. }else
  242. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Setup\\RecoveryConsole\\SecurityLevel") == 0 )
  243. {
  244. itemID = IDS_SECURITYLEVEL;
  245. }else
  246. if( _wcsicmp(szItem, L"MACHINE\\Software\\Microsoft\\Driver Signing\\Policy") == 0 )
  247. {
  248. itemID = IDS_REGPOLICY;
  249. }else
  250. //Raid #652307, yanggao, 8/9/2002
  251. if( _wcsicmp(szItem, L"MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\SubSystems\\optional") == 0 )
  252. {
  253. itemID = IDS_OPTIONAL;
  254. }else
  255. if( _wcsicmp(szItem, L"MACHINE\\Software\\Policies\\Microsoft\\Windows\\Safer\\CodeIdentifiers\\AuthenticodeEnabled") == 0 )
  256. {
  257. itemID = IDS_AUTHENTICODEENABLED;
  258. }else
  259. if( _wcsicmp(szItem, L"MACHINE\\Software\\Policies\\Microsoft\\Cryptography\\ForceKeyProtection") == 0 )
  260. {
  261. itemID = IDS_FORCEHIGHPROTECTION;
  262. }
  263. return itemID;
  264. }
  265. //
  266. // create registry value list under configuration node
  267. //
  268. void CSnapin::CreateProfileRegValueList(MMC_COOKIE cookie,
  269. PEDITTEMPLATE pSceInfo,
  270. LPDATAOBJECT pDataObj)
  271. {
  272. if ( !pSceInfo || !(pSceInfo->pTemplate) ) {
  273. return;
  274. }
  275. DWORD nCount = pSceInfo->pTemplate->RegValueCount;
  276. PSCE_REGISTRY_VALUE_INFO regArray = pSceInfo->pTemplate->aRegValues;
  277. CString strDisplayName;
  278. LPTSTR pDisplayName=NULL;
  279. DWORD displayType = 0;
  280. LPTSTR szUnits=NULL;
  281. PREGCHOICE pChoices=NULL;
  282. PREGFLAGS pFlags=NULL;
  283. CResult *pResult;
  284. long itemID = 0;
  285. for ( DWORD i=0; i<nCount; i++) {
  286. if ( !LookupRegValueProperty(regArray[i].FullValueName,
  287. &pDisplayName,
  288. &displayType,
  289. &szUnits,
  290. &pChoices,
  291. &pFlags) ) {
  292. continue;
  293. }
  294. if ( !pDisplayName ) {
  295. strDisplayName = regArray[i].FullValueName;
  296. } else {
  297. strDisplayName = pDisplayName;
  298. LocalFree(pDisplayName);
  299. }
  300. itemID = GetRegValueItemID(regArray[i].FullValueName);
  301. //
  302. // add this item
  303. //
  304. pResult = AddResultItem(strDisplayName,
  305. NULL,
  306. (LONG_PTR)&(regArray[i]),
  307. ITEM_PROF_REGVALUE,
  308. -1,
  309. cookie,
  310. false,
  311. szUnits,
  312. displayType,
  313. pSceInfo,
  314. pDataObj,
  315. NULL,
  316. itemID //assign an identifier to this item
  317. );
  318. if (pResult && pChoices) {
  319. pResult->SetRegChoices(pChoices);
  320. }
  321. if (pResult && pFlags) {
  322. pResult->SetRegFlags(pFlags);
  323. }
  324. if ( szUnits ) {
  325. LocalFree(szUnits);
  326. }
  327. szUnits = NULL;
  328. }
  329. return;
  330. }
  331. void
  332. CSnapin::CreateAnalysisRegValueList(MMC_COOKIE cookie,
  333. PEDITTEMPLATE pAnalTemp,
  334. PEDITTEMPLATE pEditTemp,
  335. LPDATAOBJECT pDataObj,
  336. RESULT_TYPES type)
  337. {
  338. if ( !pAnalTemp || !(pAnalTemp->pTemplate) ||
  339. !pEditTemp || !(pEditTemp->pTemplate) ) {
  340. return;
  341. }
  342. DWORD nEditCount = pEditTemp->pTemplate->RegValueCount; // should be everything
  343. PSCE_REGISTRY_VALUE_INFO paEdit = pEditTemp->pTemplate->aRegValues;
  344. PSCE_REGISTRY_VALUE_INFO paAnal = pAnalTemp->pTemplate->aRegValues;
  345. CString strDisplayName;
  346. LPTSTR pDisplayName=NULL;
  347. DWORD displayType = 0;
  348. LPTSTR szUnits = NULL;
  349. PREGCHOICE pChoices = NULL;
  350. PREGFLAGS pFlags = NULL;
  351. CResult *pResult=NULL;
  352. long itemID = 0;
  353. for ( DWORD i=0; i<nEditCount; i++) {
  354. if ( !LookupRegValueProperty(paEdit[i].FullValueName,
  355. &pDisplayName,
  356. &displayType,
  357. &szUnits,
  358. &pChoices,
  359. &pFlags) ) {
  360. continue;
  361. }
  362. if ( !pDisplayName ) {
  363. strDisplayName = paEdit[i].FullValueName;
  364. } else {
  365. strDisplayName = pDisplayName;
  366. LocalFree(pDisplayName);
  367. }
  368. itemID = GetRegValueItemID(paEdit[i].FullValueName);
  369. //
  370. // find the match in the analysis array
  371. // should always find a match because all existing reg values are
  372. // added to the array when getinfo is called
  373. //
  374. for ( DWORD j=0; j< pAnalTemp->pTemplate->RegValueCount; j++ ) {
  375. if ( pAnalTemp->pTemplate->aRegValues &&
  376. pAnalTemp->pTemplate->aRegValues[j].FullValueName &&
  377. _wcsicmp(pAnalTemp->pTemplate->aRegValues[j].FullValueName, paEdit[i].FullValueName) == 0 ) {
  378. if( reinterpret_cast<CFolder *>(cookie)->GetModeBits() & MB_LOCAL_POLICY ){
  379. break;
  380. }
  381. //
  382. // find a analysis result - this item may be a mismatch (when Value is not NULL)
  383. // SceEnumAllRegValues will set the status field to good if this item was not
  384. // added because it did not exist when it was originally loaded from the SAP table.
  385. // This tells us that this item is a MATCH and we should copy the value.
  386. //
  387. if ( !(paAnal[j].Value) && paEdit[i].Value &&
  388. paAnal[j].Status != SCE_STATUS_ERROR_NOT_AVAILABLE &&
  389. paAnal[j].Status != SCE_STATUS_NOT_ANALYZED ) {
  390. //
  391. // this is a good item, copy the config info as the analysis info
  392. //
  393. paAnal[j].Value = (PWSTR)LocalAlloc(0,
  394. (wcslen(paEdit[i].Value)+1)*sizeof(WCHAR));
  395. if ( paAnal[j].Value ) {
  396. //This may not be a safe usage. Both paAnal[j].Value and paEdit[i].Value are LPTSTR. Consider fix.
  397. wcscpy(paAnal[j].Value, paEdit[i].Value);
  398. } else {
  399. // else out of memory
  400. if ( szUnits ) {
  401. LocalFree(szUnits);
  402. }
  403. szUnits = NULL;
  404. return;
  405. }
  406. }
  407. break;
  408. }
  409. }
  410. DWORD status = SCE_STATUS_GOOD;
  411. if ( j < pAnalTemp->pTemplate->RegValueCount ) {
  412. status = CEditTemplate::ComputeStatus( &paEdit[i], &pAnalTemp->pTemplate->aRegValues[j] );
  413. } else {
  414. //
  415. // did not find the analysis array, shouldn't happen
  416. //
  417. status = SCE_STATUS_NOT_CONFIGURED;
  418. }
  419. //
  420. // add this item
  421. //
  422. if ( j < pAnalTemp->pTemplate->RegValueCount) {
  423. pResult = AddResultItem(strDisplayName,
  424. (LONG_PTR)&(pAnalTemp->pTemplate->aRegValues[j]),
  425. (LONG_PTR)&(paEdit[i]),
  426. type,
  427. status,
  428. cookie,
  429. false,
  430. szUnits,
  431. displayType,
  432. pEditTemp,
  433. pDataObj,
  434. NULL,
  435. itemID);
  436. if (pResult && pChoices) {
  437. pResult->SetRegChoices(pChoices);
  438. }
  439. if (pResult && pFlags) {
  440. pResult->SetRegFlags(pFlags);
  441. }
  442. } else {
  443. //
  444. // a good/not configured item
  445. //
  446. pResult = AddResultItem(strDisplayName,
  447. NULL,
  448. (LONG_PTR)&(paEdit[i]),
  449. type,
  450. status,
  451. cookie,
  452. false,
  453. szUnits,
  454. displayType,
  455. pEditTemp,
  456. pDataObj,
  457. NULL,
  458. itemID);
  459. if (pResult && pChoices) {
  460. pResult->SetRegChoices(pChoices);
  461. }
  462. }
  463. if ( szUnits ) {
  464. LocalFree(szUnits);
  465. }
  466. szUnits = NULL;
  467. }
  468. return;
  469. }
  470. BOOL
  471. LookupRegValueProperty(
  472. IN LPTSTR RegValueFullName,
  473. OUT LPTSTR *pDisplayName,
  474. OUT PDWORD displayType,
  475. OUT LPTSTR *pUnits OPTIONAL,
  476. OUT PREGCHOICE *pChoices OPTIONAL,
  477. OUT PREGFLAGS *pFlags OPTIONAL
  478. )
  479. {
  480. if ( !RegValueFullName || !pDisplayName || !displayType ) {
  481. return FALSE;
  482. }
  483. CString strTmp = RegValueFullName;
  484. //
  485. // replace the \\ with / before search reg
  486. //
  487. int npos = strTmp.Find(L'\\');
  488. while (npos > 0) {
  489. *(strTmp.GetBuffer(1)+npos) = L'/';
  490. npos = strTmp.Find(L'\\');
  491. }
  492. //
  493. // query the values from registry
  494. //
  495. *pDisplayName = NULL;
  496. HKEY hKey=NULL;
  497. HKEY hKey2=NULL;
  498. DWORD rc = RegOpenKeyEx(
  499. HKEY_LOCAL_MACHINE,
  500. SCE_ROOT_REGVALUE_PATH,
  501. 0,
  502. KEY_READ,
  503. &hKey
  504. );
  505. if (rc == ERROR_SUCCESS) {
  506. rc = RegOpenKeyEx(
  507. hKey,
  508. (PWSTR)(LPCTSTR)strTmp,
  509. 0,
  510. KEY_READ,
  511. &hKey2
  512. );
  513. }
  514. BOOL bRet;
  515. if ( ERROR_SUCCESS == rc) {
  516. DWORD RegType = 0;
  517. PWSTR Value=NULL;
  518. HRESULT hr = S_OK;
  519. Value = (PWSTR) LocalAlloc(LPTR,MAX_PATH*sizeof(WCHAR));
  520. if (Value) {
  521. //
  522. // 126714 - shouldn't hard code display strings in the registry
  523. // store them indirectly so they can support MUI
  524. //
  525. hr = SHLoadRegUIString(hKey2,
  526. SCE_REG_DISPLAY_NAME,
  527. Value,
  528. MAX_PATH);
  529. if (FAILED(hr)) {
  530. rc = MyRegQueryValue(
  531. hKey,
  532. (PWSTR)(LPCTSTR)strTmp,
  533. SCE_REG_DISPLAY_NAME,
  534. (PVOID *)&Value,
  535. &RegType
  536. );
  537. } else {
  538. rc = ERROR_SUCCESS;
  539. }
  540. }
  541. if ( rc == ERROR_SUCCESS ) {
  542. if ( Value ) {
  543. *pDisplayName = Value;
  544. Value = NULL;
  545. } else {
  546. //
  547. // did not find correct display name, use the reg name (outsize)
  548. //
  549. *pDisplayName = NULL;
  550. }
  551. }
  552. rc = MyRegQueryValue(
  553. hKey,
  554. (PWSTR)(LPCTSTR)strTmp,
  555. SCE_REG_DISPLAY_TYPE,
  556. (PVOID *)&displayType,
  557. &RegType
  558. );
  559. if ( Value ) {
  560. LocalFree(Value);
  561. Value = NULL;
  562. }
  563. if ( pUnits ) {
  564. //
  565. // query the units
  566. //
  567. rc = MyRegQueryValue(
  568. hKey,
  569. (PWSTR)(LPCTSTR)strTmp,
  570. SCE_REG_DISPLAY_UNIT,
  571. (PVOID *)&Value,
  572. &RegType
  573. );
  574. if ( rc == ERROR_SUCCESS ) {
  575. if ( RegType == REG_SZ && Value ) {
  576. *pUnits = Value;
  577. Value = NULL;
  578. } else {
  579. //
  580. // did not find units
  581. //
  582. *pUnits = NULL;
  583. }
  584. }
  585. if ( Value ) {
  586. LocalFree(Value);
  587. Value = NULL;
  588. }
  589. }
  590. //
  591. // find the registry key but may not find the display name
  592. //
  593. bRet = TRUE;
  594. if ( pChoices ) {
  595. //
  596. // query the choices
  597. //
  598. *pChoices = NULL;
  599. rc = MyRegQueryValue(hKey,
  600. (PWSTR)(LPCTSTR)strTmp,
  601. SCE_REG_DISPLAY_CHOICES,
  602. (PVOID *)&Value,
  603. &RegType
  604. );
  605. if (ERROR_SUCCESS == rc) {
  606. if ((REG_MULTI_SZ == RegType) && Value) {
  607. LPTSTR szChoice = NULL;
  608. LPTSTR szLabel = NULL; // max field size for szChoice + dwVal
  609. DWORD dwVal = -1;
  610. PREGCHOICE pRegChoice = NULL;
  611. PREGCHOICE pLast = NULL;
  612. szChoice = Value;
  613. do {
  614. //
  615. // Divide szChoice into dwValue and szLabel sections
  616. //
  617. szLabel = _tcschr(szChoice,L'|');
  618. if( szLabel == NULL ) //Raid #553113, yanggao
  619. {
  620. break;
  621. }
  622. *szLabel = L'\0';
  623. szLabel++;
  624. if( szLabel == NULL ) //Raid #553113, yanggao
  625. {
  626. break;
  627. }
  628. dwVal = _ttoi(szChoice);
  629. pRegChoice = (PREGCHOICE) LocalAlloc(LPTR,sizeof(REGCHOICE));
  630. if (pRegChoice) {
  631. //
  632. // Fill in fields of new reg choice
  633. //
  634. pRegChoice->dwValue = dwVal;
  635. pRegChoice->szName = (LPTSTR) LocalAlloc(LPTR,(lstrlen(szLabel)+1)*sizeof(TCHAR));
  636. if (NULL == pRegChoice->szName) {
  637. //
  638. // Out of memory. Bummer.
  639. //
  640. LocalFree(pRegChoice);
  641. pRegChoice = NULL;
  642. break;
  643. }
  644. //This is not a safe usage. Validate szLabel.
  645. lstrcpy(pRegChoice->szName,szLabel);
  646. //
  647. // Attach new item to end of list
  648. //
  649. if (NULL == *pChoices) {
  650. *pChoices = pRegChoice;
  651. } else {
  652. pLast->pNext = pRegChoice;
  653. }
  654. pLast = pRegChoice;
  655. }
  656. szChoice = _tcschr(szLabel,L'\0');
  657. if( szChoice == NULL )
  658. {
  659. break;
  660. }
  661. szChoice++;
  662. } while (*szChoice);
  663. } else {
  664. //
  665. // Did not find choices
  666. //
  667. bRet = FALSE;
  668. }
  669. }
  670. if ( Value ) {
  671. LocalFree(Value);
  672. Value = NULL;
  673. }
  674. }
  675. if ( pFlags ) {
  676. //
  677. // query the Flags
  678. //
  679. *pFlags = NULL;
  680. rc = MyRegQueryValue(hKey,
  681. (PWSTR)(LPCTSTR)strTmp,
  682. SCE_REG_DISPLAY_FLAGLIST,
  683. (PVOID *)&Value,
  684. &RegType
  685. );
  686. if (ERROR_SUCCESS == rc) {
  687. if ((REG_MULTI_SZ == RegType) && Value) {
  688. LPTSTR szFlag = NULL;
  689. LPTSTR szLabel = NULL; // max field size for szFlag + dwVal
  690. DWORD dwVal = -1;
  691. PREGFLAGS pRegFlag = NULL;
  692. PREGFLAGS pLast = NULL;
  693. szFlag = Value;
  694. do {
  695. //
  696. // Divide szFlag into dwValue and szLabel sections
  697. //
  698. szLabel = _tcschr(szFlag,L'|');
  699. if( szLabel == NULL ) //Raid #553113, yanggao
  700. {
  701. break;
  702. }
  703. *szLabel = L'\0';
  704. szLabel++;
  705. if( szLabel == NULL ) //Raid #553113, yanggao
  706. {
  707. break;
  708. }
  709. dwVal = _ttoi(szFlag);
  710. pRegFlag = (PREGFLAGS) LocalAlloc(LPTR,sizeof(REGFLAGS));
  711. if (pRegFlag) {
  712. //
  713. // Fill in fields of new reg Flag
  714. //
  715. pRegFlag->dwValue = dwVal;
  716. pRegFlag->szName = (LPTSTR) LocalAlloc(LPTR,(lstrlen(szLabel)+1)*sizeof(TCHAR));
  717. if (NULL == pRegFlag->szName) {
  718. //
  719. // Out of memory. Bummer.
  720. //
  721. LocalFree(pRegFlag);
  722. pRegFlag = NULL;
  723. break;
  724. }
  725. //This is not a safe usage. need to validate szLabel.
  726. lstrcpy(pRegFlag->szName,szLabel);
  727. //
  728. // Attach new item to end of list
  729. //
  730. if (NULL == *pFlags) {
  731. *pFlags = pRegFlag;
  732. } else {
  733. pLast->pNext = pRegFlag;
  734. }
  735. pLast = pRegFlag;
  736. }
  737. szFlag = wcschr(szLabel,L'\0');
  738. if( szFlag == NULL )
  739. {
  740. break;
  741. }
  742. szFlag++;
  743. } while (*szFlag);
  744. } else {
  745. //
  746. // Did not find Flags
  747. //
  748. bRet = FALSE;
  749. }
  750. }
  751. if ( Value ) {
  752. LocalFree(Value);
  753. Value = NULL;
  754. }
  755. }
  756. } else {
  757. //
  758. // did not find the registry key
  759. //
  760. bRet = FALSE;
  761. }
  762. if ( hKey ) {
  763. RegCloseKey(hKey);
  764. }
  765. if ( hKey2 ) {
  766. RegCloseKey(hKey2);
  767. }
  768. return bRet;
  769. }