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.

151 lines
5.8 KiB

  1. // File: gencpl.cpp
  2. #include "precomp.h"
  3. #include <oprahcom.h>
  4. #include "resource.h"
  5. #include "help_ids.h"
  6. #include "csetting.h"
  7. #include "confwnd.h"
  8. #include "conf.h"
  9. #include "ConfCpl.h"
  10. #include "ConfPolicies.h"
  11. #include <nmremote.h>
  12. extern int MessageBoxResource(HWND hwnd, UINT uMessage, UINT uTitle, UINT uFlags);
  13. const int MAXPASSWORDLENGTH = 36;
  14. const int MINPASSWORDLENGTH = 7;
  15. INT_PTR CALLBACK RemotePasswordDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  16. {
  17. HWND hOldPasswordText, hNewPasswordText, hVerificationText;
  18. int nOldPasswordLength, nNewPasswordLength, nVerificationLength;
  19. CHAR lpOldPassword[MAXPASSWORDLENGTH], lpNewPassword[MAXPASSWORDLENGTH], lpVerification[MAXPASSWORDLENGTH];
  20. WCHAR lpwszOldPassword[MAXPASSWORDLENGTH], lpwszNewPassword[MAXPASSWORDLENGTH];
  21. PBYTE pbHashedPassword=NULL;
  22. DWORD cbHashedPassword=0;
  23. PBYTE pbRegPassword = NULL;
  24. DWORD cbRegPassword;
  25. switch (iMsg)
  26. {
  27. case WM_INITDIALOG:
  28. SendDlgItemMessage(hDlg, IDC_EDITOLDPASSWORD, EM_LIMITTEXT,
  29. MAXPASSWORDLENGTH - 1, 0);
  30. SendDlgItemMessage(hDlg, IDC_EDITNEWPASSWORD, EM_LIMITTEXT,
  31. MAXPASSWORDLENGTH - 1, 0);
  32. SendDlgItemMessage(hDlg, IDC_EDITVERIFICATION, EM_LIMITTEXT,
  33. MAXPASSWORDLENGTH - 1, 0);
  34. // If there's no old password, disable that UI
  35. {
  36. RegEntry reLM( REMOTECONTROL_KEY, HKEY_LOCAL_MACHINE);
  37. if ( 0 == reLM.GetBinary(REMOTE_REG_PASSWORD, (void **)&pbRegPassword))
  38. {
  39. EnableWindow(GetDlgItem(hDlg, IDC_EDITOLDPASSWORD), FALSE);
  40. SetFocus(GetDlgItem(hDlg, IDC_EDITNEWPASSWORD));
  41. }
  42. }
  43. return TRUE;
  44. case WM_COMMAND:
  45. switch (LOWORD(wParam))
  46. {
  47. case IDOK: {
  48. RegEntry reLM( REMOTECONTROL_KEY, HKEY_LOCAL_MACHINE);
  49. CHash hashObject;
  50. hOldPasswordText = GetDlgItem(hDlg,IDC_EDITOLDPASSWORD);
  51. hNewPasswordText = GetDlgItem(hDlg,IDC_EDITNEWPASSWORD);
  52. hVerificationText = GetDlgItem(hDlg,IDC_EDITVERIFICATION);
  53. nOldPasswordLength = GetWindowText(hOldPasswordText,lpOldPassword,MAXPASSWORDLENGTH);
  54. MultiByteToWideChar(CP_ACP, 0, lpOldPassword, -1, lpwszOldPassword, MAXPASSWORDLENGTH);
  55. cbRegPassword = reLM.GetBinary(REMOTE_REG_PASSWORD, (void **)&pbRegPassword);
  56. // Decode password string
  57. cbHashedPassword = hashObject.GetHashedData((LPBYTE)lpwszOldPassword,
  58. sizeof(WCHAR)*strlen(lpOldPassword),
  59. (void **)&pbHashedPassword);
  60. if (0 != cbRegPassword && !(cbHashedPassword == cbRegPassword && 0 == memcmp(pbHashedPassword,pbRegPassword,cbHashedPassword))) {
  61. // Error Case - Old password incorrect.
  62. MessageBoxResource(hDlg,IDS_REMOTE_OLD_PASSWORD_WRONG_TEXT,IDS_REMOTE_OLD_PASSWORD_WRONG_TITLE,MB_OK | MB_ICONERROR);
  63. SetWindowText(hOldPasswordText,NULL);
  64. SetWindowText(hNewPasswordText,NULL);
  65. SetWindowText(hVerificationText,NULL);
  66. SetFocus(hOldPasswordText);
  67. break;
  68. }
  69. nNewPasswordLength = GetWindowText(hNewPasswordText,lpNewPassword,MAXPASSWORDLENGTH);
  70. nVerificationLength = GetWindowText(hVerificationText,lpVerification,MAXPASSWORDLENGTH);
  71. if (lstrcmp(lpNewPassword,lpVerification) != 0) {
  72. // Error Case - New password and verification do not match.
  73. MessageBoxResource(hDlg,IDS_REMOTE_NEW_PASSWORD_WRONG_TEXT,IDS_REMOTE_NEW_PASSWORD_WRONG_TITLE,MB_OK | MB_ICONERROR);
  74. SetWindowText(hNewPasswordText,NULL);
  75. SetWindowText(hVerificationText,NULL);
  76. SetFocus(hNewPasswordText);
  77. break;
  78. }
  79. if (nNewPasswordLength < MINPASSWORDLENGTH)
  80. {
  81. MessageBoxResource(hDlg,IDS_REMOTE_NEW_PASSWORD_LENGTH_TEXT,IDS_REMOTE_NEW_PASSWORD_LENGTH_TITLE,MB_OK | MB_ICONERROR);
  82. SetWindowText(hNewPasswordText,NULL);
  83. SetWindowText(hVerificationText,NULL);
  84. SetFocus(hNewPasswordText);
  85. break;
  86. }
  87. if (!lstrlen(lpVerification)) {
  88. // Don't allow empty password
  89. MessageBoxResource(hDlg,IDS_REMOTE_NEW_PASSWORD_EMPTY,IDS_REMOTE_NEW_PASSWORD_WRONG_TITLE,MB_OK | MB_ICONERROR);
  90. SetWindowText(hNewPasswordText,NULL);
  91. SetWindowText(hVerificationText,NULL);
  92. SetFocus(hNewPasswordText);
  93. break;
  94. }
  95. if (!FAnsiSz(lpNewPassword)) {
  96. // Error Case - T.120 can't handle UNICODE passwords
  97. MessageBoxResource(hDlg,IDS_REMOTE_NEW_PASSWORD_INVALID_TEXT,IDS_REMOTE_NEW_PASSWORD_WRONG_TITLE,MB_OK | MB_ICONERROR);
  98. SetWindowText(hNewPasswordText,NULL);
  99. SetWindowText(hVerificationText,NULL);
  100. SetFocus(hNewPasswordText);
  101. break;
  102. }
  103. // If we get here, then go ahead and change the password.
  104. MultiByteToWideChar(CP_ACP, 0, lpNewPassword, -1, lpwszNewPassword, MAXPASSWORDLENGTH);
  105. cbHashedPassword = hashObject.GetHashedData((LPBYTE)lpwszNewPassword,
  106. sizeof(WCHAR)*lstrlen(lpNewPassword),
  107. (void **)&pbHashedPassword);
  108. ASSERT (0 != cbHashedPassword);
  109. reLM.SetValue(REMOTE_REG_PASSWORD,pbHashedPassword,cbHashedPassword);
  110. MessageBoxResource(hDlg,IDS_REMOTE_PASSWORD_CHANGED_TEXT,IDS_REMOTE_PASSWORD_CHANGED_TITLE,MB_OK | MB_ICONEXCLAMATION);
  111. // Return 1 if non-null password is set
  112. EndDialog(hDlg, *lpNewPassword != _T('\0'));
  113. break;
  114. }
  115. case IDCANCEL:
  116. EndDialog(hDlg,0);
  117. break;
  118. default:
  119. break;
  120. }
  121. return TRUE;
  122. }
  123. return FALSE;
  124. }
  125. int MessageBoxResource(HWND hwnd, UINT uMessage, UINT uTitle, UINT uFlags)
  126. {
  127. TCHAR szTitle[MAX_PATH];
  128. TCHAR szMessage[MAX_PATH];
  129. FLoadString(uMessage,szMessage,CCHMAX(szMessage));
  130. FLoadString(uTitle,szTitle,CCHMAX(szTitle));
  131. return MessageBox(hwnd, szMessage, szTitle, uFlags);
  132. }