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.

410 lines
9.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. #include "stdafx.h"
  6. #include "DynamLnk.h"
  7. #include "apinfo.h"
  8. #include "spdutil.h"
  9. #include "security.h"
  10. #include "lm.h"
  11. #include "service.h"
  12. #define AVG_PREFERRED_ENUM_COUNT 40
  13. #define MAX_NUM_RECORDS 10 // was 10
  14. #define DEFAULT_SECURITY_PKG _T("negotiate")
  15. #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
  16. #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
  17. // internal functions
  18. BOOL IsUserAdmin(LPCTSTR pszMachine, PSID AccountSid);
  19. DWORD ValidateDomainAccount(IN CString Machine, IN CString UserName, IN CString Domain, OUT PSID * AccountSid);
  20. NTSTATUS ValidatePassword(IN LPCWSTR UserName, IN LPCWSTR Domain, IN LPCWSTR Password);
  21. DWORD GetCurrentUser(CString & strAccount);
  22. DEBUG_DECLARE_INSTANCE_COUNTER(CApDbInfo);
  23. CApDbInfo::CApDbInfo() :
  24. m_cRef(1)
  25. {
  26. m_Init=0;
  27. m_Active=0;
  28. m_session_init = false;
  29. DEBUG_INCREMENT_INSTANCE_COUNTER(CSpdInfo);
  30. }
  31. CApDbInfo::~CApDbInfo()
  32. {
  33. DEBUG_DECREMENT_INSTANCE_COUNTER(CApInfo());
  34. CSingleLock cLock(&m_csData);
  35. cLock.Lock();
  36. //Convert the data to our internal data structure
  37. //FreeItemsAndEmptyArray(m_arrayFWFilters);
  38. FreeItemsAndEmptyArray(m_arrayApData);
  39. cLock.Unlock();
  40. }
  41. // Although this object is not a COM Interface, we want to be able to
  42. // take advantage of recounting, so we have basic addref/release/QI support
  43. IMPLEMENT_ADDREF_RELEASE(CApDbInfo)
  44. IMPLEMENT_SIMPLE_QUERYINTERFACE(CApDbInfo, IApDbInfo)
  45. void CApDbInfo::FreeItemsAndEmptyArray(CApInfoArray& array)
  46. {
  47. for (int i = 0; i < array.GetSize(); i++)
  48. {
  49. delete array.GetAt(i);
  50. }
  51. array.RemoveAll();
  52. }
  53. HRESULT CApDbInfo::SetComputerName(LPTSTR pszName)
  54. {
  55. m_stMachineName = pszName;
  56. return S_OK;
  57. }
  58. HRESULT CApDbInfo::GetComputerName(CString * pstName)
  59. {
  60. Assert(pstName);
  61. if (NULL == pstName)
  62. return E_INVALIDARG;
  63. *pstName = m_stMachineName;
  64. return S_OK;
  65. }
  66. HRESULT CApDbInfo::GetSession(PHANDLE phsession)
  67. {
  68. Assert(phsession);
  69. if (NULL == phsession)
  70. return E_INVALIDARG;
  71. *phsession = m_session;
  72. return S_OK;
  73. }
  74. HRESULT CApDbInfo::SetSession(HANDLE hsession)
  75. {
  76. m_session = hsession;
  77. m_session_init = true;
  78. return S_OK;
  79. }
  80. HRESULT
  81. CApDbInfo::EnumApData()
  82. {
  83. HRESULT hr = hrOK;
  84. DWORD dwErr = ERROR_SUCCESS;
  85. DWORD dwCurrentIndexType = 0;
  86. DWORD dwCurrentSortOption = 0;
  87. DWORD dwNumRequest = 0;
  88. DWORD dwOffset = 0;
  89. DWORD flagIn = 0;
  90. DWORD flagOut = 0;
  91. DWORD i = 0;
  92. DWORD j = 0;
  93. DWORD oldSize = 0;
  94. CSingleLock cLock(&m_csData);
  95. CApInfoArray arrayTemp;
  96. CString debugString;
  97. INTFS_KEY_TABLE ApTable;
  98. PINTF_KEY_ENTRY pKeyEntry = NULL;
  99. INTF_ENTRY ApEntry;
  100. PWZC_802_11_CONFIG_LIST pConfigList = NULL;
  101. PWZC_WLAN_CONFIG pLanConfig = NULL;
  102. CApInfo *pApInfo = NULL;
  103. FreeItemsAndEmptyArray(arrayTemp);
  104. memset(&ApTable, 0, sizeof(INTFS_KEY_TABLE));
  105. dwErr = ::WZCEnumInterfaces(NULL /*(LPTSTR)(LPCTSTR)m_stMachineName*/,
  106. &ApTable);
  107. if (dwErr != ERROR_SUCCESS)
  108. {
  109. hr = HRESULT_FROM_WIN32(dwErr);
  110. goto Error;
  111. }
  112. cLock.Lock();
  113. flagIn = (DWORD)(-1); // Set to get all fields
  114. //
  115. // for each GUID (NIC) returned by EnumInterfaces, call QueryInterface and
  116. // add that interface's data to the array.
  117. //
  118. for (i = 0; i < ApTable.dwNumIntfs; i++)
  119. {
  120. flagOut = 0;
  121. pKeyEntry = ApTable.pIntfs + i;
  122. memset (&ApEntry, 0, sizeof(INTF_ENTRY));
  123. ApEntry.wszGuid = pKeyEntry->wszGuid;
  124. dwErr = ::WZCQueryInterface(NULL /*(LPTSTR)(LPCTSTR)m_stMachineName*/,
  125. flagIn,
  126. &ApEntry,
  127. &flagOut);
  128. //
  129. // Did we get the BSSID list?
  130. //
  131. if ( (dwErr == ERROR_SUCCESS) &&
  132. (flagOut & INTF_BSSIDLIST) )
  133. {
  134. pConfigList = (PWZC_802_11_CONFIG_LIST)(ApEntry.rdBSSIDList.pData);
  135. //
  136. // increase size of array by the number of visible AP's in this
  137. // interface.
  138. //
  139. oldSize = (DWORD)arrayTemp.GetSize();
  140. arrayTemp.SetSize(oldSize + pConfigList->NumberOfItems);
  141. //
  142. // iterate through each visible ap
  143. // index starts at .Index instead of 0 for some reason...
  144. //
  145. for (j = pConfigList->Index;
  146. j < pConfigList->NumberOfItems + pConfigList->Index;
  147. j++)
  148. {
  149. pLanConfig = &(pConfigList->Config[j]);
  150. //
  151. // Default Constructor zeros the ApInfo object.
  152. //
  153. pApInfo = new CApInfo();
  154. if (NULL == pApInfo)
  155. {
  156. hr = E_OUTOFMEMORY;
  157. goto Error;
  158. }
  159. //
  160. // Set the data
  161. //
  162. dwErr = pApInfo->SetApInfo(&ApEntry, pLanConfig);
  163. if (dwErr != ERROR_SUCCESS)
  164. AfxMessageBox(_T("Error setting ApInfo"), MB_OK);
  165. //
  166. // put new item in current 0-based index plus the previous
  167. // size of array.
  168. //
  169. arrayTemp[j -pConfigList->Index + oldSize] = pApInfo;
  170. }
  171. }
  172. WZCDeleteIntfObj(&ApEntry);
  173. }
  174. //
  175. // Only free top level array of table, as individual keys will be
  176. // deleted by the query mechanism.
  177. //
  178. RpcFree(ApTable.pIntfs);
  179. FreeItemsAndEmptyArray(m_arrayApData);
  180. m_arrayApData.Copy(arrayTemp);
  181. //
  182. //remember the original IndexType and Sort options
  183. //
  184. dwCurrentIndexType = IDS_COL_APDATA_GUID;
  185. dwCurrentSortOption = SORT_ASCENDING;
  186. m_IndexMgrLogData.Reset();
  187. for (i = 0; i < (DWORD)m_arrayApData.GetSize(); i++)
  188. {
  189. m_IndexMgrLogData.AddItem(m_arrayApData.GetAt(i));
  190. }
  191. SortApData(dwCurrentIndexType, dwCurrentSortOption);
  192. Error:
  193. //
  194. // This particular error is because we don't have any MM policies.
  195. // Ignore it
  196. //
  197. if (HRESULT_FROM_WIN32(ERROR_NO_DATA) == hr)
  198. hr = hrOK;
  199. return hr;
  200. }
  201. DWORD CApDbInfo::GetApCount()
  202. {
  203. CSingleLock cLock(&m_csData);
  204. cLock.Lock();
  205. return (DWORD)m_arrayApData.GetSize();
  206. }
  207. HRESULT
  208. CApDbInfo::GetApInfo(
  209. int iIndex,
  210. CApInfo *pApDb
  211. )
  212. /*++
  213. Routine Description:
  214. Returns the ApInfo at a virtual index
  215. Arguments:
  216. [in] iIndex - virtual index
  217. [out] pApDb - Returned value. space must be allocated by caller
  218. Returns:
  219. HR_OK on success
  220. --*/
  221. {
  222. HRESULT hr = hrOK;
  223. CApInfo *pApInfo = NULL;
  224. m_csData.Lock();
  225. if (iIndex < m_arrayApData.GetSize())
  226. {
  227. pApInfo = (CApInfo*) m_IndexMgrLogData.GetItemData(iIndex);
  228. Assert(pApInfo);
  229. *pApDb = *pApInfo;
  230. }
  231. else
  232. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  233. m_csData.Unlock();
  234. return hr;
  235. }
  236. HRESULT
  237. CApDbInfo::SortApData(
  238. DWORD dwIndexType,
  239. DWORD dwSortOptions
  240. )
  241. {
  242. return m_IndexMgrLogData.SortApData(dwIndexType, dwSortOptions);
  243. }
  244. STDMETHODIMP
  245. CApDbInfo::Destroy()
  246. {
  247. //$REVIEW this routine get called when doing auto-refresh
  248. //We don't need to clean up anything at this time.
  249. //Each array (Filter, SA, policy...) will get cleaned up when calling the
  250. //corresponding enum function.
  251. HANDLE hsession;
  252. GetSession(&hsession);
  253. if (m_session_init == true)
  254. {
  255. ::CloseWZCDbLogSession(hsession);
  256. }
  257. return S_OK;
  258. }
  259. DWORD
  260. CApDbInfo::GetInitInfo()
  261. {
  262. CSingleLock cLock(&m_csData);
  263. cLock.Lock();
  264. return m_Init;
  265. }
  266. void
  267. CApDbInfo::SetInitInfo(DWORD dwInitInfo)
  268. {
  269. CSingleLock cLock(&m_csData);
  270. cLock.Lock();
  271. m_Init=dwInitInfo;
  272. }
  273. DWORD
  274. CApDbInfo::GetActiveInfo()
  275. {
  276. CSingleLock cLock(&m_csData);
  277. cLock.Lock();
  278. return m_Active;
  279. }
  280. void
  281. CApDbInfo::SetActiveInfo(DWORD dwActiveInfo)
  282. {
  283. CSingleLock cLock(&m_csData);
  284. cLock.Lock();
  285. m_Active=dwActiveInfo;
  286. }
  287. /*!--------------------------------------------------------------------------
  288. CreateApInfo
  289. Helper to create the ApDbInfo object.
  290. ---------------------------------------------------------------------------*/
  291. HRESULT
  292. CreateApDbInfo(IApDbInfo ** ppApDbInfo)
  293. {
  294. AFX_MANAGE_STATE(AfxGetModuleState());
  295. SPIApDbInfo spApDbInfo;
  296. IApDbInfo * pApDbInfo = NULL;
  297. HRESULT hr = hrOK;
  298. COM_PROTECT_TRY
  299. {
  300. pApDbInfo = new CApDbInfo;
  301. // Do this so that it will get freed on error
  302. spApDbInfo = pApDbInfo;
  303. *ppApDbInfo = spApDbInfo.Transfer();
  304. }
  305. COM_PROTECT_CATCH
  306. return hr;
  307. }