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.

245 lines
6.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. apinfo.h
  7. FILE HISTORY:
  8. */
  9. #ifndef _APINFO_H
  10. #define _APINFO_H
  11. #ifndef _HARRAY_H
  12. #include "harray.h"
  13. #endif
  14. #include "spdutil.h"
  15. #define PROTOCOL_ID_OFFSET 9
  16. interface IApInfo;
  17. template <class T>
  18. void
  19. FreeItemsAndEmptyArray (
  20. T& array);
  21. DWORD IsAdmin(LPCTSTR szMachineName, LPCTSTR szAccount, LPCTSTR szPassword, BOOL * pfIsAdmin);
  22. /* _ApInfo: Private structure used inside of CApInfo.
  23. */
  24. typedef struct _ApInfo
  25. {
  26. WZC_WLAN_CONFIG wlanConfig;
  27. LPWSTR wszGuid;
  28. BOOL bAssociated;
  29. } APINFO, *PAPINFO;
  30. class CApInfo
  31. {
  32. public:
  33. CApInfo()
  34. {
  35. memset(&m_ApInfo, 0, sizeof(APINFO));
  36. }
  37. CApInfo(PINTF_ENTRY nicEntry, PWZC_WLAN_CONFIG apEntry)
  38. {
  39. DWORD dwErr = ERROR_SUCCESS;
  40. dwErr = SetWlanConfig(apEntry);
  41. dwErr = SetWszGuid(nicEntry->wszGuid);
  42. //TODO: Throw exceptions on error
  43. }
  44. DWORD SetApInfo(PINTF_ENTRY nicEntry, PWZC_WLAN_CONFIG apEntry)
  45. {
  46. DWORD dwErr = ERROR_SUCCESS;
  47. dwErr = SetWlanConfig(apEntry);
  48. if (dwErr != ERROR_SUCCESS)
  49. goto done;
  50. dwErr = SetWszGuid(nicEntry->wszGuid);
  51. if (dwErr != ERROR_SUCCESS)
  52. goto done;
  53. dwErr = SetAssociated(nicEntry);
  54. done:
  55. return dwErr;
  56. }
  57. const CApInfo& operator=(const CApInfo& ApInfoSrc)
  58. {
  59. DWORD dwErr = ERROR_SUCCESS;
  60. dwErr = SetWlanConfig(&(ApInfoSrc.m_ApInfo.wlanConfig));
  61. if (dwErr != ERROR_SUCCESS)
  62. goto done;
  63. dwErr = SetWszGuid(ApInfoSrc.m_ApInfo.wszGuid);
  64. if (dwErr != ERROR_SUCCESS)
  65. goto done;
  66. m_ApInfo.bAssociated = ApInfoSrc.m_ApInfo.bAssociated;
  67. done:
  68. return *this;
  69. }
  70. ~CApInfo()
  71. {
  72. if (NULL != m_ApInfo.wlanConfig.rdUserData.pData)
  73. {
  74. delete [] m_ApInfo.wlanConfig.rdUserData.pData;
  75. m_ApInfo.wlanConfig.rdUserData.pData = NULL;
  76. }
  77. if (NULL != m_ApInfo.wszGuid)
  78. {
  79. delete [] m_ApInfo.wszGuid;
  80. m_ApInfo.wszGuid = NULL;
  81. }
  82. }
  83. private:
  84. DWORD SetAssociated(const INTF_ENTRY *pIntfEntry)
  85. {
  86. int i = 0;
  87. DWORD dwErr = ERROR_SUCCESS;
  88. const NDIS_802_11_MAC_ADDRESS *pAssocMac = NULL;
  89. const NDIS_802_11_MAC_ADDRESS *pCurrMac = NULL;
  90. m_ApInfo.bAssociated = FALSE;
  91. if (NULL == pIntfEntry)
  92. {
  93. dwErr = ERROR_INVALID_PARAMETER;
  94. goto done;
  95. }
  96. pAssocMac = (const NDIS_802_11_MAC_ADDRESS*)pIntfEntry->rdBSSID.pData;
  97. pCurrMac = &(m_ApInfo.wlanConfig.MacAddress);
  98. if (0 == memcmp(pAssocMac, pCurrMac, sizeof(NDIS_802_11_MAC_ADDRESS)) )
  99. m_ApInfo.bAssociated = TRUE;
  100. done:
  101. return dwErr;
  102. }
  103. DWORD SetWlanConfig(const WZC_WLAN_CONFIG *pwlanCfgSrc)
  104. {
  105. DWORD dwErr = ERROR_SUCCESS;
  106. DWORD dwLen = 0;
  107. PWZC_WLAN_CONFIG pwlanCfgDest = &(m_ApInfo.wlanConfig);
  108. ASSERT(pwlanCfgSrc != NULL);
  109. //copy upto the pointer in rdUserData
  110. memcpy(pwlanCfgDest, pwlanCfgSrc,
  111. sizeof(WZC_WLAN_CONFIG) - sizeof(LPBYTE));
  112. if (pwlanCfgDest->rdUserData.pData != NULL)
  113. AfxMessageBox(_T("Non null UserData"), MB_OK);
  114. dwLen = pwlanCfgSrc->rdUserData.dwDataLen;
  115. if (dwLen > 0)
  116. {
  117. pwlanCfgDest->rdUserData.pData = new BYTE[dwLen];
  118. if (pwlanCfgDest->rdUserData.pData != 0)
  119. memcpy(pwlanCfgDest->rdUserData.pData,
  120. pwlanCfgSrc->rdUserData.pData,
  121. pwlanCfgSrc->rdUserData.dwDataLen);
  122. else
  123. dwErr = ERROR_OUTOFMEMORY;
  124. }
  125. return dwErr;
  126. }
  127. DWORD SetWszGuid(LPWSTR wszGuidSrc)
  128. {
  129. DWORD dwErr = ERROR_SUCCESS;
  130. DWORD dwLen = 0;
  131. ASSERT(wszGuidSrc != NULL);
  132. if (wszGuidSrc != NULL)
  133. {
  134. dwLen = wcslen(wszGuidSrc) + 1;
  135. m_ApInfo.wszGuid = new wchar_t[dwLen];
  136. if (0 == m_ApInfo.wszGuid)
  137. dwErr = ERROR_OUTOFMEMORY;
  138. else
  139. memcpy(m_ApInfo.wszGuid, wszGuidSrc, dwLen * sizeof(wchar_t));
  140. }
  141. return dwErr;
  142. }
  143. public:
  144. APINFO m_ApInfo;
  145. };
  146. typedef CArray<CApInfo *, CApInfo *> CApInfoArray;
  147. #define MAX_STR_LEN 80
  148. #define DeclareIApDbInfoMembers(IPURE) \
  149. STDMETHOD(Destroy) (THIS) IPURE; \
  150. STDMETHOD(SetComputerName) (THIS_ LPTSTR pszName) IPURE; \
  151. STDMETHOD(GetComputerName) (THIS_ CString * pstName) IPURE; \
  152. STDMETHOD(GetSession) (THIS_ PHANDLE phsession) IPURE; \
  153. STDMETHOD(SetSession) (THIS_ HANDLE hsession) IPURE; \
  154. STDMETHOD(EnumApData) (THIS) IPURE; \
  155. STDMETHOD(GetApInfo) (THIS_ int iIndex, CApInfo * pApInfo) IPURE; \
  156. STDMETHOD_(DWORD, GetApCount) (THIS) IPURE; \
  157. STDMETHOD(SortApData) (THIS_ DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  158. STDMETHOD_(DWORD, GetInitInfo) (THIS) IPURE; \
  159. STDMETHOD_(void, SetInitInfo) (THIS_ DWORD dwInitInfo) IPURE; \
  160. STDMETHOD_(DWORD, GetActiveInfo) (THIS) IPURE; \
  161. STDMETHOD_(void, SetActiveInfo) (THIS_ DWORD dwActiveInfo) IPURE;
  162. #undef INTERFACE
  163. #define INTERFACE IApDbInfo
  164. DECLARE_INTERFACE_(IApDbInfo, IUnknown)
  165. {
  166. public:
  167. DeclareIUnknownMembers(PURE);
  168. DeclareIApDbInfoMembers(PURE);
  169. };
  170. typedef ComSmartPointer <IApDbInfo, &IID_IApDbInfo> SPIApDbInfo;
  171. class CApDbInfo : public IApDbInfo
  172. {
  173. public:
  174. CApDbInfo();
  175. ~CApDbInfo();
  176. DeclareIUnknownMembers(IMPL);
  177. DeclareIApDbInfoMembers(IMPL);
  178. private:
  179. CApInfoArray m_arrayApData; //For Ap Data
  180. CIndexMgrLogData m_IndexMgrLogData;
  181. CCriticalSection m_csData;
  182. CString m_stMachineName;
  183. LONG m_cRef;
  184. DWORD m_Init;
  185. DWORD m_Active;
  186. HANDLE m_session;
  187. bool m_session_init;
  188. private:
  189. void FreeItemsAndEmptyArray(CApInfoArray& array);
  190. };
  191. HRESULT CreateApDbInfo(IApDbInfo **ppApDbInfo);
  192. #endif