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.

174 lines
5.1 KiB

  1. #include "stdafx.h"
  2. #include "netpage.h"
  3. #pragma hdrstop
  4. CNetworkUserWizardPage::CNetworkUserWizardPage(CUserInfo* pUserInfo) :
  5. m_pUserInfo(pUserInfo)
  6. {
  7. }
  8. INT_PTR CNetworkUserWizardPage::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  9. {
  10. switch (uMsg)
  11. {
  12. HANDLE_MSG(hwndDlg, WM_INITDIALOG, OnInitDialog);
  13. HANDLE_MSG(hwndDlg, WM_COMMAND, OnCommand);
  14. HANDLE_MSG(hwndDlg, WM_NOTIFY, OnNotify);
  15. }
  16. return FALSE;
  17. }
  18. BOOL CNetworkUserWizardPage::OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  19. {
  20. Edit_LimitText(GetDlgItem(hwnd, IDC_USER), MAX_USER);
  21. Edit_LimitText(GetDlgItem(hwnd, IDC_DOMAIN), MAX_DOMAIN);
  22. return TRUE;
  23. }
  24. BOOL CNetworkUserWizardPage::OnNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
  25. {
  26. switch (pnmh->code)
  27. {
  28. case PSN_SETACTIVE:
  29. {
  30. if (m_pUserInfo->m_psid != NULL)
  31. {
  32. LocalFree(m_pUserInfo->m_psid);
  33. m_pUserInfo->m_psid = NULL;
  34. }
  35. SetWizardButtons(hwnd, GetParent(hwnd));
  36. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  37. }
  38. return TRUE;
  39. case PSN_WIZNEXT:
  40. {
  41. // Read in the network user name and domain name
  42. if (FAILED(GetUserAndDomain(hwnd)))
  43. {
  44. // We don't have both!
  45. DisplayFormatMessage(hwnd, IDS_USR_NEWUSERWIZARD_CAPTION, IDS_USR_NETUSERNAME_ERROR,
  46. MB_OK | MB_ICONERROR);
  47. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, -1);
  48. }
  49. else
  50. {
  51. if (::UserAlreadyHasPermission(m_pUserInfo, hwnd))
  52. {
  53. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, -1);
  54. }
  55. else
  56. {
  57. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  58. }
  59. }
  60. }
  61. return TRUE;
  62. }
  63. return FALSE;
  64. }
  65. BOOL CNetworkUserWizardPage::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  66. {
  67. switch (id)
  68. {
  69. case IDC_BROWSE_BUTTON:
  70. {
  71. // Launch object picker to find a network account to give permissions to
  72. TCHAR szUser[MAX_USER + 1];
  73. TCHAR szDomain[MAX_DOMAIN + 1];
  74. if (S_OK == ::BrowseForUser(hwnd, szUser, ARRAYSIZE(szUser), szDomain, ARRAYSIZE(szDomain)))
  75. {
  76. SetDlgItemText(hwnd, IDC_USER, szUser);
  77. SetDlgItemText(hwnd, IDC_DOMAIN, szDomain);
  78. }
  79. return TRUE;
  80. }
  81. case IDC_USER:
  82. {
  83. if (codeNotify == EN_CHANGE)
  84. {
  85. SetWizardButtons(hwnd, GetParent(hwnd));
  86. }
  87. break;
  88. }
  89. }
  90. return FALSE;
  91. }
  92. void CNetworkUserWizardPage::SetWizardButtons(HWND hwnd, HWND hwndPropSheet)
  93. {
  94. HWND hwndUsername = GetDlgItem(hwnd, IDC_USER);
  95. DWORD dwUNLength = GetWindowTextLength(hwndUsername);
  96. PropSheet_SetWizButtons(hwndPropSheet, (dwUNLength == 0) ? 0 : PSWIZB_NEXT);
  97. }
  98. HRESULT CNetworkUserWizardPage::GetUserAndDomain(HWND hwnd)
  99. {
  100. CWaitCursor cur;
  101. HRESULT hr = S_OK;
  102. // This code checks to ensure the user isn't trying
  103. // to add a well-known group like Everyone! This is bad
  104. // If the SID isn't read here, it is read in in CUserInfo::ChangeLocalGroup
  105. TCHAR szDomainUser[MAX_USER + MAX_DOMAIN + 2];
  106. FetchText(hwnd, IDC_USER, m_pUserInfo->m_szUsername, ARRAYSIZE(m_pUserInfo->m_szUsername));
  107. FetchText(hwnd, IDC_DOMAIN, m_pUserInfo->m_szDomain, ARRAYSIZE(m_pUserInfo->m_szDomain));
  108. // If the username doesn't already contain a domain and the domain specified in blank
  109. if ((NULL == StrChr(m_pUserInfo->m_szUsername, TEXT('\\'))) && (0 == m_pUserInfo->m_szDomain[0]))
  110. {
  111. // Assume local machine for the domain
  112. DWORD cchName = ARRAYSIZE(m_pUserInfo->m_szDomain);
  113. if (!GetComputerName(m_pUserInfo->m_szDomain, &cchName))
  114. {
  115. *(m_pUserInfo->m_szDomain) = 0;
  116. }
  117. }
  118. ::MakeDomainUserString(m_pUserInfo->m_szDomain, m_pUserInfo->m_szUsername, szDomainUser, ARRAYSIZE(szDomainUser));
  119. #ifdef _0
  120. // Try to find the SID for this user
  121. DWORD cchDomain = ARRAYSIZE(m_pUserInfo->m_szDomain);
  122. hr = AttemptLookupAccountName(szDomainUser, &m_pUserInfo->m_psid, m_pUserInfo->m_szDomain, &cchDomain, &m_pUserInfo->m_sUse);
  123. if (SUCCEEDED(hr))
  124. {
  125. // Make sure this isn't a well-known group like 'Everyone'
  126. if (m_pUserInfo->m_sUse == SidTypeWellKnownGroup)
  127. {
  128. hr = E_FAIL;
  129. }
  130. }
  131. else
  132. {
  133. // Failed to get the user's SID, just use the names provided
  134. // We'll get their SID once we add them
  135. m_pUserInfo->m_psid = NULL;
  136. hr = S_OK;
  137. }
  138. #endif
  139. // We'll get their SID once we add them
  140. m_pUserInfo->m_psid = NULL;
  141. if (FAILED(hr))
  142. {
  143. LocalFree(m_pUserInfo->m_psid);
  144. m_pUserInfo->m_psid = NULL;
  145. }
  146. return hr;
  147. }