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.

236 lines
7.3 KiB

  1. #include "stdafx.h"
  2. #include "unpage.h"
  3. #pragma hdrstop
  4. HRESULT ValidateName(LPCTSTR pszName)
  5. {
  6. // We need to use illegal fat chars, says SBurns
  7. TCHAR* pszBadChars = ILLEGAL_FAT_CHARS;
  8. HRESULT hrStringOK = S_OK;
  9. while ((NULL != *pszBadChars) && (hrStringOK == S_OK))
  10. {
  11. if (NULL != StrChr(pszName, *pszBadChars))
  12. {
  13. hrStringOK = E_FAIL;
  14. }
  15. else
  16. {
  17. pszBadChars = CharNext(pszBadChars);
  18. }
  19. }
  20. if (SUCCEEDED(hrStringOK))
  21. {
  22. // See if the whole string is dots
  23. TCHAR* pszChar = const_cast<TCHAR*>(pszName);
  24. BOOL fAllDots = TRUE;
  25. while (fAllDots && (0 != *pszChar))
  26. {
  27. if (TEXT('.') == *pszChar)
  28. {
  29. pszChar = CharNext(pszChar);
  30. }
  31. else
  32. {
  33. fAllDots = FALSE;
  34. }
  35. }
  36. if (fAllDots)
  37. {
  38. hrStringOK = E_FAIL;
  39. }
  40. }
  41. return hrStringOK;
  42. }
  43. /*************************************
  44. CUsernamePageBase Implementation
  45. *************************************/
  46. BOOL CUsernamePageBase::OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  47. {
  48. // Limit the text of the username, fullname and description fields
  49. HWND hwndUsername = GetDlgItem(hwnd, IDC_USER);
  50. HWND hwndFullName = GetDlgItem(hwnd, IDC_FULLNAME);
  51. HWND hwndDescription = GetDlgItem(hwnd, IDC_DESCRIPTION);
  52. Edit_LimitText(hwndUsername, ARRAYSIZE(m_pUserInfo->m_szUsername) - 1);
  53. SetWindowText(hwndUsername, m_pUserInfo->m_szUsername);
  54. Edit_LimitText(hwndFullName, ARRAYSIZE(m_pUserInfo->m_szFullName) - 1);
  55. SetWindowText(hwndFullName, m_pUserInfo->m_szFullName);
  56. Edit_LimitText(hwndDescription, ARRAYSIZE(m_pUserInfo->m_szComment) - 1);
  57. SetWindowText(hwndDescription, m_pUserInfo->m_szComment);
  58. return TRUE;
  59. }
  60. /*************************************
  61. CUsernameWizardPage Implementation
  62. *************************************/
  63. INT_PTR CUsernameWizardPage::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  64. {
  65. switch (uMsg)
  66. {
  67. HANDLE_MSG(hwndDlg, WM_INITDIALOG, OnInitDialog);
  68. HANDLE_MSG(hwndDlg, WM_NOTIFY, OnNotify);
  69. HANDLE_MSG(hwndDlg, WM_COMMAND, OnCommand);
  70. }
  71. return FALSE;
  72. }
  73. BOOL CUsernameWizardPage::OnNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
  74. {
  75. switch (pnmh->code)
  76. {
  77. case PSN_SETACTIVE:
  78. SetWizardButtons(hwnd, GetParent(hwnd));
  79. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  80. return TRUE;
  81. case PSN_WIZNEXT:
  82. // Save the data the user has entered
  83. FetchText(hwnd, IDC_USER, m_pUserInfo->m_szUsername, ARRAYSIZE(m_pUserInfo->m_szUsername));
  84. FetchText(hwnd, IDC_FULLNAME, m_pUserInfo->m_szFullName, ARRAYSIZE(m_pUserInfo->m_szFullName));
  85. FetchText(hwnd, IDC_DESCRIPTION, m_pUserInfo->m_szComment, ARRAYSIZE(m_pUserInfo->m_szComment));
  86. if (S_OK != ValidateName(m_pUserInfo->m_szUsername))
  87. {
  88. // Username is invalid. warn now
  89. ::DisplayFormatMessage(hwnd, IDS_USR_APPLET_CAPTION, IDS_ERR_BADUSERNAME, MB_ICONERROR | MB_OK);
  90. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, -1);
  91. }
  92. else if (::UserAlreadyHasPermission(m_pUserInfo, hwnd))
  93. {
  94. // Don't let the user continue if the user they've selected already
  95. // has permission to use this machine
  96. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, -1);
  97. }
  98. else
  99. {
  100. // We have a username (otherwise next would be disabled)
  101. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  102. }
  103. return TRUE;
  104. }
  105. return FALSE;
  106. }
  107. BOOL CUsernameWizardPage::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  108. {
  109. if (codeNotify == EN_CHANGE)
  110. {
  111. SetWizardButtons(hwnd, GetParent(hwnd));
  112. return TRUE;
  113. }
  114. return FALSE;
  115. }
  116. void CUsernameWizardPage::SetWizardButtons(HWND hwnd, HWND hwndPropSheet)
  117. {
  118. HWND hwndEdit = GetDlgItem(hwnd, IDC_USER);
  119. DWORD dwUNLength = GetWindowTextLength(hwndEdit);
  120. PropSheet_SetWizButtons(hwndPropSheet, (dwUNLength == 0) ? 0 : PSWIZB_NEXT);
  121. }
  122. /*************************************
  123. CUsernamePropertyPage Implementation
  124. *************************************/
  125. INT_PTR CUsernamePropertyPage::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  126. {
  127. switch (uMsg)
  128. {
  129. HANDLE_MSG(hwndDlg, WM_INITDIALOG, OnInitDialog);
  130. HANDLE_MSG(hwndDlg, WM_NOTIFY, OnNotify);
  131. HANDLE_MSG(hwndDlg, WM_COMMAND, OnCommand);
  132. }
  133. return FALSE;
  134. }
  135. BOOL CUsernamePropertyPage::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  136. {
  137. if (codeNotify == EN_CHANGE)
  138. {
  139. PropSheet_Changed(GetParent(hwnd), hwnd);
  140. return TRUE;
  141. }
  142. return FALSE;
  143. }
  144. BOOL CUsernamePropertyPage::OnNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
  145. {
  146. switch (pnmh->code)
  147. {
  148. case PSN_APPLY:
  149. {
  150. TCHAR szTemp[256];
  151. HRESULT hr;
  152. LONG lResult = PSNRET_NOERROR;
  153. // Try to update the username
  154. FetchText(hwnd, IDC_USER, szTemp, ARRAYSIZE(szTemp));
  155. TCHAR szDomainUser[MAX_DOMAIN + MAX_USER + 2];
  156. ::MakeDomainUserString(m_pUserInfo->m_szDomain, m_pUserInfo->m_szUsername,
  157. szDomainUser, ARRAYSIZE(szDomainUser));
  158. if (StrCmp(szTemp, m_pUserInfo->m_szUsername) != 0)
  159. {
  160. hr = m_pUserInfo->UpdateUsername(szTemp);
  161. if (FAILED(hr))
  162. {
  163. ::DisplayFormatMessage(hwnd, IDS_USR_APPLET_CAPTION,
  164. IDS_USR_UPDATE_USERNAME_ERROR, MB_ICONERROR | MB_OK, szDomainUser);
  165. lResult = PSNRET_INVALID_NOCHANGEPAGE;
  166. }
  167. }
  168. // Try to update the full name
  169. FetchText(hwnd, IDC_FULLNAME, szTemp, ARRAYSIZE(szTemp));
  170. if (StrCmp(szTemp, m_pUserInfo->m_szFullName) != 0)
  171. {
  172. hr = m_pUserInfo->UpdateFullName(szTemp);
  173. if (FAILED(hr))
  174. {
  175. ::DisplayFormatMessage(hwnd, IDS_USR_APPLET_CAPTION,
  176. IDS_USR_UPDATE_FULLNAME_ERROR, MB_ICONERROR | MB_OK, szDomainUser);
  177. lResult = PSNRET_INVALID_NOCHANGEPAGE;
  178. }
  179. }
  180. // Try to update the description
  181. FetchText(hwnd, IDC_DESCRIPTION, szTemp, ARRAYSIZE(szTemp));
  182. if (StrCmp(szTemp, m_pUserInfo->m_szComment) != 0)
  183. {
  184. hr = m_pUserInfo->UpdateDescription(szTemp);
  185. if (FAILED(hr))
  186. {
  187. ::DisplayFormatMessage(hwnd, IDS_USR_APPLET_CAPTION,
  188. IDS_USR_UPDATE_DESCRIPTION_ERROR, MB_ICONERROR | MB_OK, szDomainUser);
  189. lResult = PSNRET_INVALID_NOCHANGEPAGE;
  190. }
  191. }
  192. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, lResult);
  193. return TRUE;
  194. }
  195. default:
  196. break;
  197. }
  198. return FALSE;
  199. }