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.

1135 lines
33 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: MSVidWebDVDAdm.cpp */
  4. /* Description: DImplementation of CMSVidWebDVDAdm */
  5. /* Author: Fang Wang */
  6. /*************************************************************************/
  7. #include "stdafx.h"
  8. #include "MSVidCtl.h"
  9. #include "MSVidDVDAdm.h"
  10. #include "iso3166.h"
  11. #include <stdio.h>
  12. #include <errors.h>
  13. #include <wincrypt.h>
  14. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_MSVidWebDVDAdm, CMSVidWebDVDAdm)
  15. const TCHAR g_szRegistryKey[] = TEXT("Software\\Microsoft\\Multimedia\\DVD");
  16. const TCHAR g_szPassword[] = TEXT("DVDAdmin.password");
  17. const TCHAR g_szSalt[] = TEXT("DVDAdmin.ps"); // password salt
  18. const TCHAR g_szUserSalt[] = TEXT("DVDAdmin.us"); // username salt
  19. const TCHAR g_szUsername[] = TEXT("DVDAdmin.username");
  20. const TCHAR g_szPlayerLevel[] = TEXT("DVDAdmin.playerLevel");
  21. const TCHAR g_szPlayerCountry[] = TEXT("DVDAdmin.playerCountry");
  22. const TCHAR g_szDisableScrnSvr[] = TEXT("DVDAdmin.disableScreenSaver");
  23. const TCHAR g_szBookmarkOnStop[] = TEXT("DVDAdmin.bookmarkOnStop");
  24. const TCHAR g_szDefaultAudio[] = TEXT("DVDAdmin.defaultAudioLCID");
  25. const TCHAR g_szDefaultSP[] = TEXT("DVDAdmin.defaultSPLCID");
  26. const TCHAR g_szDefaultMenu[] = TEXT("DVDAdmin.defaultMenuLCID");
  27. /*************************************************************/
  28. /* Helper functions */
  29. /*************************************************************/
  30. /*************************************************************/
  31. /* Name: GetRegistryDword
  32. /* Description:
  33. /*************************************************************/
  34. BOOL GetRegistryDword(const TCHAR *pKey, DWORD* dwRet, DWORD dwDefault)
  35. {
  36. HKEY hKey;
  37. LONG lRet;
  38. *dwRet = dwDefault;
  39. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, g_szRegistryKey, 0, KEY_QUERY_VALUE, &hKey);
  40. if (lRet == ERROR_SUCCESS) {
  41. DWORD dwType, dwLen;
  42. dwLen = sizeof(DWORD);
  43. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pKey, NULL, &dwType, (LPBYTE)dwRet, &dwLen)){
  44. *dwRet = dwDefault;
  45. RegCloseKey(hKey);
  46. return FALSE;
  47. }
  48. RegCloseKey(hKey);
  49. }
  50. return (lRet == ERROR_SUCCESS);
  51. }
  52. /*************************************************************/
  53. /* Name: SetRegistryDword
  54. /* Description:
  55. /*************************************************************/
  56. BOOL SetRegistryDword(const TCHAR *pKey, DWORD dwRet)
  57. {
  58. HKEY hKey;
  59. LONG lRet;
  60. lRet = RegCreateKey(HKEY_LOCAL_MACHINE, g_szRegistryKey, &hKey);
  61. if (lRet == ERROR_SUCCESS) {
  62. lRet = RegSetValueEx(hKey, pKey, NULL, REG_DWORD, (LPBYTE)&dwRet, sizeof(dwRet));
  63. RegCloseKey(hKey);
  64. }
  65. return (lRet == ERROR_SUCCESS);
  66. }
  67. /*************************************************************/
  68. /* Name: GetRegistryString
  69. /* Description:
  70. /*************************************************************/
  71. BOOL GetRegistryString(const TCHAR *pKey, TCHAR* szRet, DWORD* dwLen, TCHAR* szDefault)
  72. {
  73. HKEY hKey;
  74. LONG lRet;
  75. DWORD dwTempLen = 0;
  76. lstrcpyn(szRet, szDefault, *dwLen);
  77. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, g_szRegistryKey, 0, KEY_QUERY_VALUE, &hKey);
  78. if (lRet == ERROR_SUCCESS) {
  79. DWORD dwType;
  80. dwTempLen = (*dwLen) * sizeof(TCHAR);
  81. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pKey, NULL, &dwType, (LPBYTE)szRet, &dwTempLen)) {
  82. lstrcpyn(szRet, szDefault, *dwLen);
  83. *dwLen = 0;
  84. }
  85. *dwLen = dwTempLen/sizeof(TCHAR);
  86. RegCloseKey(hKey);
  87. }
  88. return (lRet == ERROR_SUCCESS);
  89. }
  90. /*************************************************************/
  91. /* Name: SetRegistryString
  92. /* Description:
  93. /*************************************************************/
  94. BOOL SetRegistryString(const TCHAR *pKey, TCHAR *szString, DWORD dwLen)
  95. {
  96. HKEY hKey;
  97. LONG lRet;
  98. lRet = RegCreateKey(HKEY_LOCAL_MACHINE, g_szRegistryKey, &hKey);
  99. if (lRet == ERROR_SUCCESS) {
  100. lRet = RegSetValueEx(hKey, pKey, NULL, REG_SZ, (LPBYTE)szString, dwLen*sizeof(TCHAR));
  101. RegCloseKey(hKey);
  102. }
  103. return (lRet == ERROR_SUCCESS);
  104. }
  105. /*************************************************************/
  106. /* Name: GetRegistryByte
  107. /* Description:
  108. /*************************************************************/
  109. BOOL GetRegistryBytes(const TCHAR *pKey, BYTE* szRet, DWORD* dwLen)
  110. {
  111. HKEY hKey;
  112. LONG lRet;
  113. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, g_szRegistryKey, 0, KEY_QUERY_VALUE, &hKey);
  114. if (lRet == ERROR_SUCCESS) {
  115. DWORD dwType;
  116. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pKey, NULL, &dwType, (LPBYTE)szRet, dwLen)) {
  117. *dwLen = 0;
  118. }
  119. RegCloseKey(hKey);
  120. }
  121. return (lRet == ERROR_SUCCESS);
  122. }
  123. /*************************************************************/
  124. /* Name: SetRegistryBytes
  125. /* Description:
  126. /*************************************************************/
  127. BOOL SetRegistryBytes(const TCHAR *pKey, BYTE *szString, DWORD dwLen)
  128. {
  129. HKEY hKey;
  130. LONG lRet;
  131. lRet = RegCreateKey(HKEY_LOCAL_MACHINE, g_szRegistryKey, &hKey);
  132. BOOL bRet = TRUE;
  133. if (lRet == ERROR_SUCCESS) {
  134. if (szString == NULL) {
  135. lRet = RegDeleteValue(hKey, pKey);
  136. bRet = (lRet == ERROR_SUCCESS) || (lRet == ERROR_FILE_NOT_FOUND);
  137. }
  138. else {
  139. lRet = RegSetValueEx(hKey, pKey, NULL, REG_BINARY, (LPBYTE)szString, dwLen);
  140. bRet = (lRet == ERROR_SUCCESS);
  141. }
  142. RegCloseKey(hKey);
  143. }
  144. return (bRet);
  145. }
  146. // Start not so lame functions
  147. /*************************************************************/
  148. /* Name: GetRegistryDwordCU
  149. /* Description:
  150. /*************************************************************/
  151. BOOL GetRegistryDwordCU(const TCHAR *pKey, DWORD* dwRet, DWORD dwDefault)
  152. {
  153. HKEY hKey;
  154. LONG lRet;
  155. *dwRet = dwDefault;
  156. lRet = RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegistryKey, 0, KEY_QUERY_VALUE, &hKey);
  157. if (lRet == ERROR_SUCCESS) {
  158. DWORD dwType, dwLen;
  159. dwLen = sizeof(DWORD);
  160. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pKey, NULL, &dwType, (LPBYTE)dwRet, &dwLen)){
  161. *dwRet = dwDefault;
  162. RegCloseKey(hKey);
  163. return FALSE;
  164. }
  165. RegCloseKey(hKey);
  166. }
  167. return (lRet == ERROR_SUCCESS);
  168. }
  169. /*************************************************************/
  170. /* Name: SetRegistryDwordCU
  171. /* Description:
  172. /*************************************************************/
  173. BOOL SetRegistryDwordCU(const TCHAR *pKey, DWORD dwRet)
  174. {
  175. HKEY hKey;
  176. LONG lRet;
  177. lRet = RegCreateKey(HKEY_CURRENT_USER, g_szRegistryKey, &hKey);
  178. if (lRet == ERROR_SUCCESS) {
  179. lRet = RegSetValueEx(hKey, pKey, NULL, REG_DWORD, (LPBYTE)&dwRet, sizeof(dwRet));
  180. RegCloseKey(hKey);
  181. }
  182. return (lRet == ERROR_SUCCESS);
  183. }
  184. /*************************************************************/
  185. /* Name: GetRegistryStringCU
  186. /* Description:
  187. /*************************************************************/
  188. BOOL GetRegistryStringCU(const TCHAR *pKey, TCHAR* szRet, DWORD* dwLen, TCHAR* szDefault)
  189. {
  190. HKEY hKey;
  191. LONG lRet;
  192. DWORD dwTempLen = 0;
  193. lstrcpyn(szRet, szDefault, *dwLen);
  194. lRet = RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegistryKey, 0, KEY_QUERY_VALUE, &hKey);
  195. if (lRet == ERROR_SUCCESS) {
  196. DWORD dwType;
  197. dwTempLen = (*dwLen) * sizeof(TCHAR);
  198. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pKey, NULL, &dwType, (LPBYTE)szRet, &dwTempLen)) {
  199. lstrcpyn(szRet, szDefault, sizeof(szRet) / sizeof(szRet[0]));
  200. *dwLen = 0;
  201. }
  202. *dwLen = dwTempLen/sizeof(TCHAR);
  203. RegCloseKey(hKey);
  204. }
  205. return (lRet == ERROR_SUCCESS);
  206. }
  207. /*************************************************************/
  208. /* Name: SetRegistryStringCU
  209. /* Description:
  210. /*************************************************************/
  211. BOOL SetRegistryStringCU(const TCHAR *pKey, TCHAR *szString, DWORD dwLen)
  212. {
  213. HKEY hKey;
  214. LONG lRet;
  215. lRet = RegCreateKey(HKEY_CURRENT_USER, g_szRegistryKey, &hKey);
  216. if (lRet == ERROR_SUCCESS) {
  217. lRet = RegSetValueEx(hKey, pKey, NULL, REG_SZ, (LPBYTE)szString, dwLen*sizeof(TCHAR));
  218. RegCloseKey(hKey);
  219. }
  220. return (lRet == ERROR_SUCCESS);
  221. }
  222. /*************************************************************/
  223. /* Name: GetRegistryByteCU
  224. /* Description:
  225. /*************************************************************/
  226. BOOL GetRegistryBytesCU(const TCHAR *pKey, BYTE* szRet, DWORD* dwLen)
  227. {
  228. HKEY hKey;
  229. LONG lRet;
  230. lRet = RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegistryKey, 0, KEY_QUERY_VALUE, &hKey);
  231. if (lRet == ERROR_SUCCESS) {
  232. DWORD dwType;
  233. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pKey, NULL, &dwType, (LPBYTE)szRet, dwLen)) {
  234. *dwLen = 0;
  235. }
  236. RegCloseKey(hKey);
  237. }
  238. return (lRet == ERROR_SUCCESS);
  239. }
  240. /*************************************************************/
  241. /* Name: SetRegistryBytesCU
  242. /* Description:
  243. /*************************************************************/
  244. BOOL SetRegistryBytesCU(const TCHAR *pKey, BYTE *szString, DWORD dwLen)
  245. {
  246. HKEY hKey;
  247. LONG lRet;
  248. lRet = RegCreateKey(HKEY_CURRENT_USER, g_szRegistryKey, &hKey);
  249. BOOL bRet = TRUE;
  250. if (lRet == ERROR_SUCCESS) {
  251. if (szString == NULL) {
  252. lRet = RegDeleteValue(hKey, pKey);
  253. bRet = (lRet == ERROR_SUCCESS) || (lRet == ERROR_FILE_NOT_FOUND);
  254. }
  255. else {
  256. lRet = RegSetValueEx(hKey, pKey, NULL, REG_BINARY, (LPBYTE)szString, dwLen);
  257. bRet = (lRet == ERROR_SUCCESS);
  258. }
  259. RegCloseKey(hKey);
  260. }
  261. return (bRet);
  262. }
  263. // end not so lame functions
  264. /*************************************************************/
  265. /* Function: CMSVidWebDVDAdm */
  266. /*************************************************************/
  267. CMSVidWebDVDAdm::CMSVidWebDVDAdm(){
  268. DWORD temp;
  269. GetRegistryDword(g_szPlayerLevel, &temp, (DWORD)8);
  270. m_lParentctrlLevel = temp;
  271. GetRegistryDword(g_szPlayerCountry, &temp, (DWORD)0);
  272. m_lParentctrlCountry = temp;
  273. GetRegistryDword(g_szDisableScrnSvr, &temp, (DWORD)VARIANT_TRUE);
  274. m_fDisableScreenSaver = (VARIANT_BOOL)temp;
  275. SaveScreenSaver();
  276. if (m_fDisableScreenSaver != VARIANT_FALSE)
  277. DisableScreenSaver();
  278. GetRegistryDword(g_szBookmarkOnStop, &temp, (DWORD)VARIANT_FALSE);
  279. m_fBookmarkOnStop = (VARIANT_BOOL)temp;
  280. }/* end of function CMSVidWebDVDAdm */
  281. /*************************************************************/
  282. /* Function: ~CMSVidWebDVDAdm */
  283. /*************************************************************/
  284. CMSVidWebDVDAdm::~CMSVidWebDVDAdm(){
  285. RestoreScreenSaver();
  286. }/* end of function ~CMSVidWebDVDAdm */
  287. /*************************************************************/
  288. /* Name: EncryptPassword */
  289. /* Description: Hash the password */
  290. /* Params: */
  291. /* lpPassword: password to hash */
  292. /* lpAssaultedHash: hashed password, */
  293. /* allocated by this fucntion, released by caller */
  294. /* p_dwAssault: salt, save with hash; or salt passed in */
  295. /* genAssault: TRUE = generate salt; FALSE = salt passed in */
  296. /*************************************************************/
  297. HRESULT CMSVidWebDVDAdm::EncryptPassword(LPTSTR lpPassword, BYTE **lpAssaultedHash, DWORD *p_dwCryptLen, DWORD *p_dwAssault, BOOL genAssault){
  298. if(!lpPassword || !lpAssaultedHash || !p_dwAssault || !p_dwCryptLen){
  299. return E_POINTER;
  300. }
  301. if( lstrlen(lpPassword) > MAX_PASSWD){
  302. return E_INVALIDARG;
  303. }
  304. HCRYPTPROV hProv = NULL; // Handle to Crypto Context
  305. HCRYPTHASH hHash = NULL; // Handle to Hash Function
  306. DWORD dwAssault = 0; // As(Sa)u(lt) for hash
  307. DWORD dwAssaultedHash = 0; // Length of Assaulted hash
  308. // Init Crypto Context
  309. if(!CryptAcquireContext(&hProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)){
  310. return E_UNEXPECTED;
  311. }
  312. // Store the Salt in dwAssault, either generate it or copy the user passed value
  313. if(genAssault){
  314. if(!CryptGenRandom(hProv, sizeof(DWORD), reinterpret_cast<BYTE *>(&dwAssault))){
  315. if(hProv) CryptReleaseContext(hProv, 0);
  316. return E_UNEXPECTED;
  317. }
  318. *p_dwAssault = dwAssault;
  319. }
  320. else{
  321. dwAssault = *p_dwAssault;
  322. }
  323. // Create the handle to the Hash function
  324. if(!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash)){
  325. if(hProv) CryptReleaseContext(hProv, 0);
  326. if(hHash) CryptDestroyHash(hHash);
  327. return E_UNEXPECTED;
  328. }
  329. // Hash the password
  330. if(!CryptHashData(hHash, reinterpret_cast<BYTE *>(lpPassword), lstrlen(lpPassword)*sizeof(lpPassword[0]), 0)){
  331. if(hProv) CryptReleaseContext(hProv, 0);
  332. if(hHash) CryptDestroyHash(hHash);
  333. return E_UNEXPECTED;
  334. }
  335. // Add the salt
  336. if(!CryptHashData(hHash, reinterpret_cast<BYTE *>(&dwAssault), sizeof(DWORD), 0)){
  337. if(hProv) CryptReleaseContext(hProv, 0);
  338. if(hHash) CryptDestroyHash(hHash);
  339. return E_UNEXPECTED;
  340. }
  341. // Get the size of the hashed data
  342. if(!CryptGetHashParam(hHash, HP_HASHVAL, 0, &dwAssaultedHash, 0)){
  343. if(hProv) CryptReleaseContext(hProv, 0);
  344. if(hHash) CryptDestroyHash(hHash);
  345. return E_UNEXPECTED;
  346. }
  347. // Allocate a string large enough to hold the hash data and a null
  348. *lpAssaultedHash = new BYTE[dwAssaultedHash];
  349. if(!lpAssaultedHash){
  350. if(hProv) CryptReleaseContext(hProv, 0);
  351. if(hHash) CryptDestroyHash(hHash);
  352. return E_UNEXPECTED;
  353. }
  354. // Zero the string
  355. ZeroMemory(*lpAssaultedHash, dwAssaultedHash);
  356. // Copy length of Encrypted bytes to return value
  357. *p_dwCryptLen = dwAssaultedHash;
  358. // Get the hash data and store it in a string
  359. if(!CryptGetHashParam(hHash, HP_HASHVAL, *lpAssaultedHash, &dwAssaultedHash, 0)){
  360. if(hProv) CryptReleaseContext(hProv, 0);
  361. if(hHash) CryptDestroyHash(hHash);
  362. if(lpAssaultedHash){
  363. delete[] *lpAssaultedHash;
  364. *lpAssaultedHash = NULL;
  365. }
  366. return E_UNEXPECTED;
  367. }
  368. // Clean up
  369. if(hProv) CryptReleaseContext(hProv, 0);
  370. if(hHash) CryptDestroyHash(hHash);
  371. return S_OK;
  372. }/* end of function EncryptPassword */
  373. /*************************************************************/
  374. /* Function: ConfirmPassword */
  375. /* Description: comfired a password with the one saved */
  376. /*************************************************************/
  377. STDMETHODIMP CMSVidWebDVDAdm::ConfirmPassword(BSTR /* strUserName */,
  378. BSTR strPassword, VARIANT_BOOL *fRight){
  379. HRESULT hr = S_OK;
  380. try {
  381. USES_CONVERSION;
  382. *fRight = VARIANT_FALSE;
  383. if(!strPassword || !fRight){
  384. return E_POINTER;
  385. }
  386. UINT bStrLen = lstrlen(strPassword);
  387. if(bStrLen >= MAX_PASSWD){
  388. return E_INVALIDARG;
  389. }
  390. LPTSTR szPassword = OLE2T(strPassword);
  391. BYTE szSavedPasswd[MAX_PASSWD];
  392. DWORD dwLen = MAX_PASSWD+PRE_PASSWD;
  393. BOOL bFound = GetRegistryBytes(g_szPassword, szSavedPasswd, &dwLen);
  394. // if no password has been set yet
  395. if (!bFound || dwLen == 0) {
  396. // so in this case accept only an empty string
  397. if(lstrlen(szPassword) <= 0){
  398. *fRight = VARIANT_TRUE;
  399. }
  400. else {
  401. *fRight = VARIANT_FALSE;
  402. }
  403. throw (hr);
  404. }
  405. DWORD dwAssault = 0;
  406. bFound = GetRegistryDword(g_szSalt, &dwAssault, 0);
  407. if(!bFound ){
  408. // Old style password since there is no salt
  409. // ignore current password until it is reset
  410. *fRight = VARIANT_TRUE;
  411. throw(hr);
  412. }
  413. // Encrypt the password with the salt from the registry
  414. BYTE *pszEncrypted = NULL;
  415. DWORD dwCryptLen = 0;
  416. hr = EncryptPassword(szPassword, &pszEncrypted, &dwCryptLen, &dwAssault, FALSE);
  417. if(FAILED(hr)){
  418. throw (hr);
  419. }
  420. // Compare the Encrypted input password with the saved password
  421. if(memcmp(pszEncrypted, szSavedPasswd, (dwAssault <= dwLen?dwAssault:dwLen) ) == 0)
  422. *fRight = VARIANT_TRUE;
  423. else
  424. *fRight = VARIANT_FALSE;
  425. delete[] pszEncrypted;
  426. }
  427. catch(HRESULT hrTmp){
  428. hr = hrTmp;
  429. }
  430. catch(...){
  431. hr = E_UNEXPECTED;
  432. }
  433. if(FAILED(hr)){
  434. Sleep(1000);
  435. }
  436. return (HandleError(hr));
  437. }/* end of function ConfirmPassword */
  438. /*************************************************************/
  439. /* Function: ChangePassword */
  440. /* Description: password change requested */
  441. /*************************************************************/
  442. STDMETHODIMP CMSVidWebDVDAdm::ChangePassword(BSTR strUserName,
  443. BSTR strOldPassword, BSTR strNewPassword){
  444. HRESULT hr = S_OK;
  445. try {
  446. USES_CONVERSION;
  447. if(!strNewPassword){
  448. throw E_POINTER;
  449. }
  450. if(lstrlen(strNewPassword) >= MAX_PASSWD){
  451. //Error(IDS_PASSWORD_LENGTH);
  452. throw E_INVALIDARG;
  453. }
  454. LPTSTR szNewPassword = OLE2T(strNewPassword);
  455. // Confirm old password first
  456. VARIANT_BOOL temp;
  457. ConfirmPassword(strUserName, strOldPassword, &temp);
  458. if (temp == VARIANT_FALSE){
  459. throw E_ACCESSDENIED;
  460. }
  461. DWORD dwAssault = 0;
  462. DWORD dwCryptLen = 0;
  463. BYTE *pszEncrypted = NULL;
  464. hr = EncryptPassword(szNewPassword, &pszEncrypted, &dwCryptLen, &dwAssault, TRUE);
  465. if(FAILED(hr)){
  466. throw E_FAIL;
  467. }
  468. BOOL bSuccess = SetRegistryBytes(g_szPassword, pszEncrypted, dwCryptLen);
  469. if (!bSuccess){
  470. hr = E_FAIL;
  471. }
  472. delete[] pszEncrypted;
  473. // If storing the password hash failed, don't store the salt
  474. if(SUCCEEDED(hr)){
  475. bSuccess = SetRegistryDword(g_szSalt, dwAssault);
  476. if (!bSuccess){
  477. hr = E_FAIL;
  478. }
  479. }
  480. }
  481. catch(HRESULT hrTmp){
  482. hr = hrTmp;
  483. }
  484. catch(...){
  485. hr = E_UNEXPECTED;
  486. }
  487. return HandleError(hr);
  488. }/* end of function ChangePassword */
  489. /*************************************************************/
  490. /* Function: SaveParentalLevel */
  491. /*************************************************************/
  492. STDMETHODIMP CMSVidWebDVDAdm::SaveParentalLevel(long lParentalLevel,
  493. BSTR strUserName, BSTR strPassword){
  494. HRESULT hr = S_OK;
  495. try {
  496. if (lParentalLevel != PARENTAL_LEVEL_DISABLED &&
  497. (lParentalLevel < 1 || lParentalLevel > 8)) {
  498. throw (E_INVALIDARG);
  499. }
  500. if (m_lParentctrlLevel != lParentalLevel) {
  501. // Confirm password first
  502. VARIANT_BOOL temp;
  503. ConfirmPassword(strUserName, strPassword, &temp);
  504. if (temp == VARIANT_FALSE)
  505. throw (E_ACCESSDENIED);
  506. }
  507. BOOL bSuccess = SetRegistryDword(g_szPlayerLevel, (DWORD) lParentalLevel);
  508. if (!bSuccess){
  509. throw E_FAIL;
  510. }
  511. m_lParentctrlLevel = lParentalLevel;
  512. }
  513. catch(HRESULT hrTmp){
  514. hr = hrTmp;
  515. }
  516. catch(...){
  517. hr = E_UNEXPECTED;
  518. }
  519. return HandleError(hr);
  520. }/* end of function SaveParentalLevel */
  521. /*************************************************************/
  522. /* Name: SaveParentalCountry */
  523. /*************************************************************/
  524. STDMETHODIMP CMSVidWebDVDAdm::SaveParentalCountry(long lCountry,
  525. BSTR strUserName,BSTR strPassword){
  526. HRESULT hr = S_OK;
  527. try {
  528. if(lCountry < 0 && lCountry > 0xffff){
  529. throw(E_INVALIDARG);
  530. }/* end of if statement */
  531. BYTE bCountryCode[2];
  532. bCountryCode[0] = BYTE(lCountry>>8);
  533. bCountryCode[1] = BYTE(lCountry);
  534. // convert the input country code to upper case by applying ToUpper to each letter
  535. WORD wCountry = ISO3166::PackCode( (char *)bCountryCode );
  536. BOOL bFound = FALSE;
  537. for( unsigned i=0; i<ISO3166::GetNumCountries(); i++ )
  538. {
  539. if( ISO3166::PackCode(ISO3166::GetCountry(i).Code) == wCountry )
  540. {
  541. bFound = TRUE;
  542. }
  543. }
  544. // Not a valid country code
  545. if (!bFound) {
  546. throw(E_INVALIDARG);
  547. }/* end of if statement */
  548. if (m_lParentctrlCountry != lCountry) {
  549. // Confirm password first
  550. VARIANT_BOOL temp;
  551. ConfirmPassword(strUserName, strPassword, &temp);
  552. if (temp == VARIANT_FALSE)
  553. throw(E_ACCESSDENIED);
  554. }
  555. BOOL bSuccess = SetRegistryDword(g_szPlayerCountry, (DWORD) lCountry);
  556. if (!bSuccess){
  557. throw E_FAIL;
  558. }
  559. m_lParentctrlCountry = lCountry;
  560. }
  561. catch(HRESULT hrTmp){
  562. hr = hrTmp;
  563. }
  564. catch(...){
  565. hr = E_UNEXPECTED;
  566. }
  567. return (HandleError(hr));
  568. }/* end of function SaveParentalCountry */
  569. /*************************************************************/
  570. /* Function: put_DisableScreenSaver */
  571. /*************************************************************/
  572. STDMETHODIMP CMSVidWebDVDAdm::put_DisableScreenSaver(VARIANT_BOOL fDisable){
  573. HRESULT hr = S_OK;
  574. try {
  575. if (fDisable == VARIANT_FALSE)
  576. RestoreScreenSaver();
  577. else
  578. DisableScreenSaver();
  579. SetRegistryDword(g_szDisableScrnSvr, (DWORD) fDisable);
  580. m_fDisableScreenSaver = fDisable;
  581. }
  582. catch(HRESULT hrTmp){
  583. hr = hrTmp;
  584. }
  585. catch(...){
  586. hr = E_UNEXPECTED;
  587. }
  588. return HandleError(hr);
  589. }/* end of function put_DisableScreenSaver */
  590. /*************************************************************/
  591. /* Function: get_DisableScreenSaver */
  592. /*************************************************************/
  593. STDMETHODIMP CMSVidWebDVDAdm::get_DisableScreenSaver(VARIANT_BOOL *fDisable){
  594. HRESULT hr = S_OK;
  595. try {
  596. if(NULL == fDisable){
  597. hr = E_POINTER;
  598. throw(hr);
  599. }/* end of if statement */
  600. *fDisable = m_fDisableScreenSaver;
  601. }
  602. catch(HRESULT hrTmp){
  603. hr = hrTmp;
  604. }
  605. catch(...){
  606. hr = E_UNEXPECTED;
  607. }
  608. return HandleError(hr);
  609. }/* end of function get_DisableScreenSaver */
  610. /*************************************************************/
  611. /* Function: SaveScreenSaver */
  612. /*************************************************************/
  613. HRESULT CMSVidWebDVDAdm::SaveScreenSaver(){
  614. /*
  615. SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &m_bScrnSvrOld, 0);
  616. SystemParametersInfo(SPI_GETLOWPOWERACTIVE, 0, &m_bPowerlowOld, 0);
  617. SystemParametersInfo(SPI_GETPOWEROFFACTIVE, 0, &m_bPowerOffOld, 0);
  618. */
  619. return S_OK;
  620. }
  621. /*************************************************************/
  622. /* Function: DisableScreenSaver */
  623. /*************************************************************/
  624. HRESULT CMSVidWebDVDAdm::DisableScreenSaver(){
  625. /*
  626. SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
  627. SystemParametersInfo(SPI_SETLOWPOWERACTIVE, FALSE, NULL, 0);
  628. SystemParametersInfo(SPI_SETPOWEROFFACTIVE, FALSE, NULL, 0);
  629. */
  630. return S_OK;
  631. }/* end of function DisableScreenSaver */
  632. /*************************************************************/
  633. /* Function: RestoreScreenSaver */
  634. /*************************************************************/
  635. STDMETHODIMP CMSVidWebDVDAdm::RestoreScreenSaver(){
  636. HRESULT hr = S_OK;
  637. try {
  638. /*
  639. SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, m_bScrnSvrOld, NULL, 0);
  640. SystemParametersInfo(SPI_SETLOWPOWERACTIVE, m_bPowerlowOld, NULL, 0);
  641. SystemParametersInfo(SPI_SETPOWEROFFACTIVE, m_bPowerOffOld, NULL, 0);
  642. */
  643. }
  644. catch(HRESULT hrTmp){
  645. hr = hrTmp;
  646. }
  647. catch(...){
  648. hr = E_UNEXPECTED;
  649. }
  650. return HandleError(hr);
  651. }/* end of function RestoreScreenSaver */
  652. /*************************************************************/
  653. /* Function: GetParentalLevel */
  654. /*************************************************************/
  655. STDMETHODIMP CMSVidWebDVDAdm::GetParentalLevel(long *lLevel){
  656. HRESULT hr = S_OK;
  657. try {
  658. if(NULL == lLevel){
  659. hr = E_POINTER;
  660. throw(hr);
  661. }/* end of if statement */
  662. *lLevel = m_lParentctrlLevel;
  663. }
  664. catch(HRESULT hrTmp){
  665. hr = hrTmp;
  666. }
  667. catch(...){
  668. hr = E_UNEXPECTED;
  669. }
  670. return HandleError(hr);
  671. }/* end of function GetParentalLevel */
  672. /*************************************************************/
  673. /* Function: GetParentalCountry */
  674. /*************************************************************/
  675. STDMETHODIMP CMSVidWebDVDAdm::GetParentalCountry(long *lCountry){
  676. HRESULT hr = S_OK;
  677. try {
  678. if(NULL == lCountry){
  679. hr = E_POINTER;
  680. throw(hr);
  681. }/* end of if statement */
  682. *lCountry = m_lParentctrlCountry;
  683. }
  684. catch(HRESULT hrTmp){
  685. hr = hrTmp;
  686. }
  687. catch(...){
  688. hr = E_UNEXPECTED;
  689. }
  690. return HandleError(hr);
  691. }/* end of function GetParentalCountry */
  692. /*************************************************************/
  693. /* Name: get_DefaultAudioLCID
  694. /* Description: -1 means title default
  695. /*************************************************************/
  696. STDMETHODIMP CMSVidWebDVDAdm::get_DefaultAudioLCID(long *pVal){
  697. HRESULT hr = S_OK;
  698. try {
  699. if(NULL == pVal){
  700. hr = E_POINTER;
  701. throw(hr);
  702. }/* end of if statement */
  703. GetRegistryDwordCU(g_szDefaultAudio, (DWORD*) pVal, (DWORD)-1);
  704. }
  705. catch(HRESULT hrTmp){
  706. hr = hrTmp;
  707. }
  708. catch(...){
  709. hr = E_UNEXPECTED;
  710. }
  711. return HandleError(hr);
  712. } /* end of function get_DefaultAudioLCID */
  713. /*************************************************************/
  714. /* Name: put_DefaultAudioLCID
  715. /* Description: -1 means title default
  716. /*************************************************************/
  717. STDMETHODIMP CMSVidWebDVDAdm::put_DefaultAudioLCID(long newVal)
  718. {
  719. HRESULT hr = S_OK;
  720. try {
  721. if (!::IsValidLocale(newVal, LCID_SUPPORTED) && newVal != -1) {
  722. throw (E_INVALIDARG);
  723. } /* end of if statement */
  724. SetRegistryDwordCU(g_szDefaultAudio, (DWORD) newVal);
  725. }
  726. catch(HRESULT hrTmp){
  727. hr = hrTmp;
  728. }
  729. catch(...){
  730. hr = E_UNEXPECTED;
  731. }
  732. return HandleError(hr);
  733. } /* end of put_DefaultAudioLCID */
  734. /*************************************************************/
  735. /* Name: get_DefaultSubpictureLCID
  736. /* Description: -1 means title default
  737. /*************************************************************/
  738. STDMETHODIMP CMSVidWebDVDAdm::get_DefaultSubpictureLCID(long *pVal)
  739. {
  740. HRESULT hr = S_OK;
  741. try {
  742. if(NULL == pVal){
  743. hr = E_POINTER;
  744. throw(hr);
  745. }/* end of if statement */
  746. GetRegistryDwordCU(g_szDefaultSP, (DWORD*) pVal, (DWORD)-1);
  747. }
  748. catch(HRESULT hrTmp){
  749. hr = hrTmp;
  750. }
  751. catch(...){
  752. hr = E_UNEXPECTED;
  753. }
  754. return HandleError(hr);
  755. } /* end of get_DefaultSubpictureLCID */
  756. /*************************************************************/
  757. /* Name: put_DefaultSubpictureLCID
  758. /* Description: -1 means title default
  759. /*************************************************************/
  760. STDMETHODIMP CMSVidWebDVDAdm::put_DefaultSubpictureLCID(long newVal)
  761. {
  762. HRESULT hr = S_OK;
  763. try {
  764. if (!::IsValidLocale(newVal, LCID_SUPPORTED) && newVal != -1) {
  765. throw (E_INVALIDARG);
  766. } /* end of if statement */
  767. SetRegistryDwordCU(g_szDefaultSP, (DWORD) newVal);
  768. }
  769. catch(HRESULT hrTmp){
  770. hr = hrTmp;
  771. }
  772. catch(...){
  773. hr = E_UNEXPECTED;
  774. }
  775. return HandleError(hr);
  776. } /* end of put_DefaultSubpictureLCID */
  777. /*************************************************************/
  778. /* Name: get_DefaultMenuLCID
  779. /* Description: -1 means title default
  780. /*************************************************************/
  781. STDMETHODIMP CMSVidWebDVDAdm::get_DefaultMenuLCID(long *pVal)
  782. {
  783. HRESULT hr = S_OK;
  784. try {
  785. if(NULL == pVal){
  786. hr = E_POINTER;
  787. throw(hr);
  788. }/* end of if statement */
  789. GetRegistryDwordCU(g_szDefaultMenu, (DWORD*) pVal, (DWORD)-1);
  790. }
  791. catch(HRESULT hrTmp){
  792. hr = hrTmp;
  793. }
  794. catch(...){
  795. hr = E_UNEXPECTED;
  796. }
  797. return HandleError(hr);
  798. } /* end of get_DefaultMenuLCID */
  799. /*************************************************************/
  800. /* Name: put_DefaultMenuLCID
  801. /* Description: -1 means title default
  802. /*************************************************************/
  803. STDMETHODIMP CMSVidWebDVDAdm::put_DefaultMenuLCID(long newVal)
  804. {
  805. HRESULT hr = S_OK;
  806. try {
  807. if (!::IsValidLocale(newVal, LCID_SUPPORTED) && newVal != -1) {
  808. throw (E_INVALIDARG);
  809. } /* end of if statement */
  810. SetRegistryDwordCU(g_szDefaultMenu, (DWORD) newVal);
  811. }
  812. catch(HRESULT hrTmp){
  813. hr = hrTmp;
  814. }
  815. catch(...){
  816. hr = E_UNEXPECTED;
  817. }
  818. return HandleError(hr);
  819. } /* end of put_DefaultMenuLCID */
  820. /*************************************************************/
  821. /* Name: put_BookmarkOnStop
  822. /* Description:
  823. /*************************************************************/
  824. STDMETHODIMP CMSVidWebDVDAdm::put_BookmarkOnStop(VARIANT_BOOL fEnable){
  825. HRESULT hr = S_OK;
  826. try {
  827. m_fBookmarkOnStop = fEnable;
  828. SetRegistryDword(g_szBookmarkOnStop, (DWORD) fEnable);
  829. }
  830. catch(HRESULT hrTmp){
  831. hr = hrTmp;
  832. }
  833. catch(...){
  834. hr = E_UNEXPECTED;
  835. }
  836. return HandleError(hr);
  837. }
  838. /*************************************************************/
  839. /* Name: get_BookmarkOnStop
  840. /* Description:
  841. /*************************************************************/
  842. STDMETHODIMP CMSVidWebDVDAdm::get_BookmarkOnStop(VARIANT_BOOL *fEnable){
  843. HRESULT hr = S_OK;
  844. try {
  845. if(NULL == fEnable){
  846. hr = E_POINTER;
  847. throw(hr);
  848. }/* end of if statement */
  849. *fEnable = m_fBookmarkOnStop;
  850. }
  851. catch(HRESULT hrTmp){
  852. hr = hrTmp;
  853. }
  854. catch(...){
  855. hr = E_UNEXPECTED;
  856. }
  857. return HandleError(hr);
  858. }
  859. /*************************************************************************/
  860. /* Function: InterfaceSupportsErrorInfo */
  861. /*************************************************************************/
  862. STDMETHODIMP CMSVidWebDVDAdm::InterfaceSupportsErrorInfo(REFIID riid){
  863. static const IID* arr[] = {
  864. &IID_IMSVidWebDVDAdm,
  865. };
  866. for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++){
  867. if (InlineIsEqualGUID(*arr[i], riid))
  868. return S_OK;
  869. }/* end of for loop */
  870. return S_FALSE;
  871. }/* end of function InterfaceSupportsErrorInfo */
  872. /*************************************************************************/
  873. /* Function: HandleError */
  874. /* Description: Gets Error Descriptio, so we can suppor IError Info. */
  875. /*************************************************************************/
  876. HRESULT CMSVidWebDVDAdm::HandleError(HRESULT hr){
  877. try {
  878. if(FAILED(hr)){
  879. #if 0
  880. TCHAR strError[MAX_ERROR_TEXT_LEN] = TEXT("");
  881. if(AMGetErrorText(hr , strError , MAX_ERROR_TEXT_LEN)){
  882. USES_CONVERSION;
  883. Error(T2W(strError));
  884. }
  885. else {
  886. ATLTRACE(TEXT("Unhandled Error Code \n")); // please add it
  887. ATLASSERT(FALSE);
  888. }/* end of if statement */
  889. #endif
  890. }/* end of if statement */
  891. }/* end of try statement */
  892. catch(HRESULT hrTmp){
  893. hr = hrTmp;
  894. }/* end of catch statement */
  895. catch(...){
  896. // keep the hr same
  897. }/* end of catch statement */
  898. return (hr);
  899. }/* end of function HandleError */
  900. /*************************************************************************/
  901. /* End of file: MSVidWebDVDAdm.cpp */
  902. /*************************************************************************/