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.

204 lines
5.6 KiB

  1. #include "stdafx.h"
  2. #include "resource.h"
  3. #pragma hdrstop
  4. // group list management
  5. CGroupInfoList::CGroupInfoList()
  6. {
  7. }
  8. CGroupInfoList::~CGroupInfoList()
  9. {
  10. if (HDPA())
  11. DestroyCallback(DestroyGroupInfoCallback, NULL);
  12. }
  13. int CGroupInfoList::DestroyGroupInfoCallback(CGroupInfo* pGroupInfo, LPVOID pData)
  14. {
  15. delete pGroupInfo;
  16. return 1;
  17. }
  18. HRESULT CGroupInfoList::Initialize()
  19. {
  20. USES_CONVERSION;
  21. HRESULT hr = S_OK;
  22. NET_API_STATUS status;
  23. DWORD_PTR dwResumeHandle = 0;
  24. DWORD dwEntriesRead = 0;
  25. DWORD dwTotalEntries = 0;
  26. if (HDPA())
  27. DestroyCallback(DestroyGroupInfoCallback, NULL);
  28. // Create new list initially with 8 items
  29. if (Create(8))
  30. {
  31. // Now begin enumerating local groups
  32. LOCALGROUP_INFO_1* prgGroupInfo;
  33. // Read each local group
  34. BOOL fBreakLoop = FALSE;
  35. while (!fBreakLoop)
  36. {
  37. status = NetLocalGroupEnum(NULL, 1, (BYTE**) &prgGroupInfo,
  38. 8192, &dwEntriesRead, &dwTotalEntries,
  39. &dwResumeHandle);
  40. if ((status == NERR_Success) || (status == ERROR_MORE_DATA))
  41. {
  42. // We got some local groups - add information for all users in these local
  43. // groups to our list
  44. DWORD iGroup;
  45. for (iGroup = 0; iGroup < dwEntriesRead; iGroup ++)
  46. {
  47. AddGroupToList(W2T(prgGroupInfo[iGroup].lgrpi1_name),
  48. W2T(prgGroupInfo[iGroup].lgrpi1_comment));
  49. }
  50. NetApiBufferFree((BYTE*) prgGroupInfo);
  51. // Maybe we don't have to try NetLocalGroupEnum again (if we got all the groups)
  52. fBreakLoop = (dwEntriesRead == dwTotalEntries);
  53. }
  54. else
  55. {
  56. // Check for access denied
  57. fBreakLoop = TRUE;
  58. hr = E_FAIL;
  59. }
  60. }
  61. }
  62. else
  63. {
  64. hr = E_OUTOFMEMORY;
  65. }
  66. return hr;
  67. }
  68. HRESULT CGroupInfoList::AddGroupToList(LPCTSTR szGroup, LPCTSTR szComment)
  69. {
  70. CGroupInfo* pGroupInfo = new CGroupInfo();
  71. if (!pGroupInfo)
  72. return E_OUTOFMEMORY;
  73. lstrcpyn(pGroupInfo->m_szGroup, szGroup, ARRAYSIZE(pGroupInfo->m_szGroup));
  74. lstrcpyn(pGroupInfo->m_szComment, szComment, ARRAYSIZE(pGroupInfo->m_szComment));
  75. AppendPtr(pGroupInfo);
  76. return S_OK;
  77. }
  78. // user data manager
  79. CUserManagerData::CUserManagerData(LPCTSTR pszCurrentDomainUser)
  80. {
  81. m_szHelpfilePath[0] = TEXT('\0');
  82. // Initialize everything except for the user loader thread
  83. // and the group list here; the rest is done in
  84. // ::Initialize.
  85. // Fill in the computer name
  86. DWORD cchComputername = ARRAYSIZE(m_szComputername);
  87. ::GetComputerName(m_szComputername, &cchComputername);
  88. // Detect if 'puter is in a domain
  89. SetComputerDomainFlag();
  90. // Get the current user information
  91. DWORD cchUsername = ARRAYSIZE(m_LoggedOnUser.m_szUsername);
  92. DWORD cchDomain = ARRAYSIZE(m_LoggedOnUser.m_szDomain);
  93. GetCurrentUserAndDomainName(m_LoggedOnUser.m_szUsername, &cchUsername,
  94. m_LoggedOnUser.m_szDomain, &cchDomain);
  95. // Get the extra data for this user
  96. m_LoggedOnUser.GetExtraUserInfo();
  97. // We'll set logoff required only if the current user has been updated
  98. m_pszCurrentDomainUser = (LPTSTR) pszCurrentDomainUser;
  99. m_fLogoffRequired = FALSE;
  100. }
  101. CUserManagerData::~CUserManagerData()
  102. {
  103. }
  104. HRESULT CUserManagerData::Initialize(HWND hwndUserListPage)
  105. {
  106. CWaitCursor cur;
  107. m_GroupList.Initialize();
  108. m_UserListLoader.Initialize(hwndUserListPage);
  109. return S_OK;
  110. }
  111. // Registry access constants for auto admin logon
  112. static const TCHAR szWinlogonSubkey[] = TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
  113. static const TCHAR szAutologonValueName[] = TEXT("AutoAdminLogon");
  114. static const TCHAR szDefaultUserNameValueName[] = TEXT("DefaultUserName");
  115. static const TCHAR szDefaultDomainValueName[] = TEXT("DefaultDomainName");
  116. static const TCHAR szDefaultPasswordValueName[] = TEXT("DefaultPassword");
  117. BOOL CUserManagerData::IsAutologonEnabled()
  118. {
  119. BOOL fAutologon = FALSE;
  120. // Read the registry to see if autologon is enabled
  121. HKEY hkey;
  122. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szWinlogonSubkey, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
  123. {
  124. TCHAR szResult[2];
  125. DWORD dwType;
  126. DWORD cbSize = sizeof(szResult);
  127. if (RegQueryValueEx(hkey, szAutologonValueName, 0, &dwType, (BYTE*) szResult, &cbSize) == ERROR_SUCCESS)
  128. {
  129. long lResult = StrToLong(szResult);
  130. fAutologon = (lResult != 0);
  131. }
  132. RegCloseKey(hkey);
  133. }
  134. return (fAutologon);
  135. }
  136. #define STRINGBYTESIZE(x) ((lstrlen((x)) + 1) * sizeof(TCHAR))
  137. void CUserManagerData::SetComputerDomainFlag()
  138. {
  139. m_fInDomain = ::IsComputerInDomain();
  140. }
  141. TCHAR* CUserManagerData::GetHelpfilePath()
  142. {
  143. static const TCHAR szHelpfileUnexpanded[] = TEXT("%systemroot%\\system32\\users.hlp");
  144. if (m_szHelpfilePath[0] == TEXT('\0'))
  145. {
  146. ExpandEnvironmentStrings(szHelpfileUnexpanded, m_szHelpfilePath,
  147. ARRAYSIZE(m_szHelpfilePath));
  148. }
  149. return (m_szHelpfilePath);
  150. }
  151. void CUserManagerData::UserInfoChanged(LPCTSTR pszUser, LPCTSTR pszDomain)
  152. {
  153. TCHAR szDomainUser[MAX_USER + MAX_DOMAIN + 2]; szDomainUser[0] = 0;
  154. MakeDomainUserString(pszDomain, pszUser, szDomainUser, ARRAYSIZE(szDomainUser));
  155. if (StrCmpI(szDomainUser, m_pszCurrentDomainUser) == 0)
  156. {
  157. m_fLogoffRequired = TRUE;
  158. }
  159. }
  160. BOOL CUserManagerData::LogoffRequired()
  161. {
  162. return (m_fLogoffRequired);
  163. }