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.

448 lines
13 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. winsup.cpp
  7. Global functions and variables
  8. FILE HISTORY:
  9. */
  10. #ifndef _WINSSUP_H
  11. #define _WINSSUP_H
  12. // some global defines we need
  13. #define WINS_NAME_CODE_PAGE CP_OEMCP
  14. #define INVALID_OWNER_ID 0xFFFFFFFF
  15. // Constants used in samples
  16. const int NUM_FOLDERS = 6;
  17. const int MAX_COLUMNS = 9;
  18. const int NUM_SCOPE_ITEMS = 4;
  19. extern const TCHAR g_szPipeName[];
  20. extern const TCHAR g_szDefaultHelpTopic[];
  21. extern const CLSID CLSID_WinsSnapin; // In-Proc server GUID
  22. extern const CLSID CLSID_WinsSnapinExtension; // In-Proc server GUID
  23. extern const CLSID CLSID_WinsSnapinAbout; // In-Proc server GUID
  24. extern const GUID GUID_WinsRootNodeType; // Main NodeType GUID on numeric format
  25. extern const GUID GUID_WinsGenericNodeType; // Generic-non extendible NodeType GUID
  26. // defines used in the display of owner info
  27. enum _COLUMNS
  28. {
  29. COLUMN_IP,
  30. COLUMN_NAME,
  31. COLUMN_VERSION,
  32. COLUMN_MAX
  33. };
  34. // #defines for time intervals
  35. #define SEC_PER_DAY (24 *60 * 60)
  36. #define SEC_PER_HOUR (60 * 60)
  37. #define SEC_PER_MINUTE 60
  38. // for verifying the WINS servers
  39. #define NB_NAME_MAX_LENGTH 16 // Max length for NetBIOS names
  40. #define LM_NAME_MAX_LENGTH 15 // Maximum length for Lanman-compatible
  41. // NetBIOS Name.
  42. #define DOMAINNAME_LENGTH 255
  43. #define HOSTNAME_LENGTH 16
  44. // for monitoring
  45. #define SERVER_DELETED 0x00000001
  46. #define SERVER_ADDED 0x00000002
  47. // deleted owner gets this vers no
  48. #define OWNER_DELETED 0x7FFFFFFFFFFFFFFF
  49. // flags that get stored in the .msc file
  50. enum _SERVERFLAGS
  51. {
  52. FLAG_LANMAN_COMPATIBLE = 0x00000001,
  53. FLAG_VALIDATE_CACHE = 0x00000002,
  54. FLAG_STATUS_BAR = 0x00000004,
  55. FLAG_AUTO_REFRESH = 0x00000008,
  56. FLAG_EXTENSION = 0x00000010, // we are an extension
  57. FLAG_SHOW_FQDN = 0x00000020,
  58. FLAG_SERVER_ORDER_IP = 0x00000040,
  59. FLAG_SHOW_TASKPADS = 0x00000080,
  60. };
  61. #define WIN32_FROM_HRESULT(hr) (0x0000FFFF & (hr))
  62. extern UINT aColumns[WINSSNAP_NODETYPE_MAX][MAX_COLUMNS];
  63. extern int aColumnWidths[WINSSNAP_NODETYPE_MAX][MAX_COLUMNS];
  64. // Clipboard format that has the Type and Cookie
  65. extern const wchar_t* SNAPIN_INTERNAL;
  66. DWORD SendTrigger(handle_t hWins, LONG ipTarget, BOOL fPush, BOOL fPropagate);
  67. //often used functions
  68. DWORD ControlWINSService(LPCTSTR pszName, BOOL bStop = TRUE);
  69. void GetNameIP(const CString &strDisplay, CString &strName, CString &strIP);
  70. void MakeIPAddress(DWORD dwIPAdd, CString &strIP);
  71. DWORD GetHostName(DWORD dwIpAddr, CString & strHostName);
  72. DWORD GetHostAddress(LPCTSTR pszHostName, DWORD * pdwIp);
  73. DWORD WideToMBCS(CString & strIn, LPSTR szOut, UINT uCodePage = CP_ACP, DWORD dwFlags = 0, BOOL * pfDefaultUsed = NULL);
  74. DWORD MBCSToWide(LPSTR szOut, CString & strIn, UINT uCodePage = CP_ACP, DWORD dwFlags = 0);
  75. // formatted messagebox for the snap-in
  76. BOOL LoadMessage(UINT nIdPrompt, TCHAR * chMsg, int nMsgSize);
  77. LONG GetSystemMessageA(UINT nId, CHAR * chBuffer, int cbBuffSize);
  78. LONG GetSystemMessage (UINT nId, TCHAR * chBuffer, int cbBuffSize);
  79. int WinsMessageBox(UINT nIdPrompt,
  80. UINT nType = MB_OK,
  81. const TCHAR * pszSuffixString = NULL,
  82. UINT nHelpContext = -1);
  83. int WinsMessageBoxEx(UINT nIdPrompt,
  84. LPCTSTR pszPrefixMessage,
  85. UINT nType = MB_OK,
  86. UINT nHelpContext = -1);
  87. // for the validation of server names
  88. BOOL IsValidNetBIOSName(CString & strAddress,BOOL fLanmanCompatible,BOOL fWackwack);
  89. DWORD VerifyWinsServer(CString& strAddress, CString &strServerName, DWORD &dwIP);
  90. BOOL IsValidAddress(CString& strAddress,BOOL * fIpAddress,BOOL fLanmanCompatible,BOOL fWackwack );
  91. typedef enum _NAME_TYPE_MAPPING_
  92. {
  93. NAME_TYPE_WORKSTATION = 0x00000000,
  94. NAME_TYPE_MESSENGER = 0x00000003,
  95. NAME_TYPE_RAS_SERVER = 0x00000006,
  96. NAME_TYPE_DMB = 0x0000001B,
  97. NAME_TYPE_DC = 0x0000001C,
  98. NAME_TYPE_NORM_GRP_NAME = 0x0000001E,
  99. NAME_TYPE_NETDDE = 0x0000001F,
  100. NAME_TYPE_FILE_SERVER = 0x00000020,
  101. NAME_TYPE_WORK_NW_MON_AGENT = 0x000000BE,
  102. NAME_TYPE_WORK_NW_MON_NAME = 0x000000BF,
  103. NAME_TYPE_OTHER = 0x0000FFFF,
  104. } NAME_TYPE_MAPPING;
  105. #define NUM_DEFAULT_NAME_TYPES 13
  106. extern const UINT s_NameTypeMappingDefault[NUM_DEFAULT_NAME_TYPES][3];
  107. /*---------------------------------------------------------------------------
  108. Protocol name formatting functions/classes
  109. This is provided separately from the usual function mechanism. The
  110. reason is that we will read in additional data from the registry of
  111. the router. This allows users to add their own protocols.
  112. ---------------------------------------------------------------------------*/
  113. /*---------------------------------------------------------------------------
  114. Class: CStringMapEntry
  115. ---------------------------------------------------------------------------*/
  116. class CStringMapEntry
  117. {
  118. public:
  119. CStringMapEntry()
  120. {
  121. dwNameType = 0;
  122. dwWinsType = -1;
  123. ulStringId = 0;
  124. }
  125. CStringMapEntry(CStringMapEntry & stringMapEntry)
  126. {
  127. *this = stringMapEntry;
  128. }
  129. CStringMapEntry & operator = (const CStringMapEntry & stringMapEntry)
  130. {
  131. if (this != &stringMapEntry)
  132. {
  133. dwNameType = stringMapEntry.dwNameType;
  134. dwWinsType = stringMapEntry.dwWinsType;
  135. st = stringMapEntry.st;
  136. ulStringId = stringMapEntry.ulStringId;
  137. }
  138. return *this;
  139. }
  140. public:
  141. DWORD dwNameType; // 16th byte of name, -1 is a sentinel value
  142. DWORD dwWinsType; // type of record--Unique, group, etc; -1 for don't care
  143. CString st;
  144. ULONG ulStringId;
  145. };
  146. typedef CArray<CStringMapEntry, CStringMapEntry&> CStringMapArray;
  147. void MapDWORDToCString(DWORD dwNameType, DWORD dwWinsType, const CStringMapEntry *pMap, CString & strName);
  148. /*---------------------------------------------------------------------------
  149. Class: NameTypeMapping
  150. ---------------------------------------------------------------------------*/
  151. class NameTypeMapping : public CStringMapArray
  152. {
  153. public:
  154. NameTypeMapping();
  155. ~NameTypeMapping();
  156. HRESULT Load();
  157. void Unload();
  158. HRESULT AddEntry(DWORD dwProtocolId, LPCTSTR pszName);
  159. HRESULT ModifyEntry(DWORD dwProtocolId, LPCTSTR pszName);
  160. HRESULT RemoveEntry(DWORD dwProtocolId);
  161. BOOL EntryExists(DWORD dwProtocolId);
  162. void SetMachineName(LPCTSTR pszMachineName);
  163. void TypeToCString(DWORD dwNameType, DWORD dwWinsType, CString & strName);
  164. private:
  165. typedef CString REGKEYNAME;
  166. CString m_strMachineName;
  167. public:
  168. static const REGKEYNAME c_szNameTypeMapKey;
  169. static const REGKEYNAME c_szDefault;
  170. };
  171. /*---------------------------------------------------------------------------
  172. Class: CServerInfo
  173. ---------------------------------------------------------------------------*/
  174. class CServerInfo
  175. {
  176. public:
  177. CServerInfo() {};
  178. CServerInfo(DWORD dwIp, CString & strName, LARGE_INTEGER liVersion)
  179. : m_dwIp(dwIp),
  180. m_strName(strName)
  181. {
  182. m_liVersion.QuadPart = liVersion.QuadPart;
  183. }
  184. CServerInfo(CServerInfo & ServerInfo)
  185. {
  186. *this = ServerInfo;
  187. }
  188. CServerInfo & operator = (const CServerInfo & ServerInfo)
  189. {
  190. if (this != &ServerInfo)
  191. {
  192. m_dwIp = ServerInfo.m_dwIp;
  193. m_strName = ServerInfo.m_strName;
  194. m_liVersion.QuadPart = ServerInfo.m_liVersion.QuadPart;
  195. }
  196. return *this;
  197. }
  198. public:
  199. DWORD m_dwIp;
  200. CString m_strName;
  201. LARGE_INTEGER m_liVersion;
  202. };
  203. typedef CArray<CServerInfo, CServerInfo&> CServerInfoArrayBase;
  204. /*---------------------------------------------------------------------------
  205. Class: CWinsThread
  206. ---------------------------------------------------------------------------*/
  207. class CServerInfoArray : public CServerInfoArrayBase
  208. {
  209. public:
  210. const CServerInfo GetAt(int nIndex)
  211. {
  212. CSingleLock sl(&m_lock);
  213. sl.Lock();
  214. return CServerInfoArrayBase::GetAt(nIndex);
  215. }
  216. CServerInfo & ElementAt(int nIndex)
  217. {
  218. CSingleLock sl(&m_lock);
  219. sl.Lock();
  220. return CServerInfoArrayBase::ElementAt(nIndex);
  221. }
  222. void SetAt(int nIndex, CServerInfo & serverInfo)
  223. {
  224. CSingleLock sl(&m_lock);
  225. sl.Lock();
  226. CServerInfoArrayBase::SetAt(nIndex, serverInfo);
  227. }
  228. public:
  229. CSemaphore m_lock;
  230. };
  231. typedef CArray<WINSINTF_ADD_VERS_MAP_T, WINSINTF_ADD_VERS_MAP_T> CAddVersMap;
  232. /*---------------------------------------------------------------------------
  233. Class: CWinsResults
  234. Abstraction of the WINS_RESULTS and WINS_RESULTS_NEW structs
  235. ---------------------------------------------------------------------------*/
  236. class CWinsResults
  237. {
  238. public:
  239. CWinsResults();
  240. CWinsResults(WINSINTF_RESULTS_T * pwrResults);
  241. CWinsResults(WINSINTF_RESULTS_NEW_T * pwrResults);
  242. CWinsResults(CServerInfo & ServerInfo)
  243. {
  244. *this = ServerInfo;
  245. }
  246. CWinsResults & operator = (const CWinsResults & CWinsResults)
  247. {
  248. if (this != &CWinsResults)
  249. {
  250. NoOfOwners = CWinsResults.NoOfOwners;
  251. AddVersMaps.Copy(CWinsResults.AddVersMaps);
  252. MyMaxVersNo.QuadPart = CWinsResults.MyMaxVersNo.QuadPart;
  253. RefreshInterval = CWinsResults.RefreshInterval;
  254. TombstoneInterval = CWinsResults.TombstoneInterval;
  255. TombstoneTimeout = CWinsResults.TombstoneTimeout;
  256. VerifyInterval = CWinsResults.VerifyInterval;
  257. WinsPriorityClass = CWinsResults.WinsPriorityClass;
  258. NoOfWorkerThds = CWinsResults.NoOfWorkerThds;
  259. WinsStat = CWinsResults.WinsStat;
  260. }
  261. return *this;
  262. }
  263. DWORD Update(handle_t binding);
  264. void Set(WINSINTF_RESULTS_T * pwrResults);
  265. void Set(WINSINTF_RESULTS_NEW_T * pwrResults);
  266. void Clear();
  267. protected:
  268. DWORD GetConfig(handle_t binding);
  269. DWORD GetNewConfig(handle_t binding);
  270. public:
  271. DWORD NoOfOwners;
  272. CAddVersMap AddVersMaps;
  273. LARGE_INTEGER MyMaxVersNo;
  274. DWORD RefreshInterval;
  275. DWORD TombstoneInterval;
  276. DWORD TombstoneTimeout;
  277. DWORD VerifyInterval;
  278. DWORD WinsPriorityClass;
  279. DWORD NoOfWorkerThds;
  280. WINSINTF_STAT_T WinsStat;
  281. };
  282. /*---------------------------------------------------------------------------
  283. Class: CWinsName
  284. ---------------------------------------------------------------------------*/
  285. class CWinsName
  286. {
  287. public:
  288. CWinsName()
  289. {
  290. dwType = 0;
  291. }
  292. CWinsName(CWinsName & winsName)
  293. {
  294. *this = winsName;
  295. }
  296. CWinsName & operator = (const CWinsName & winsName)
  297. {
  298. if (this != &winsName)
  299. {
  300. strName = winsName.strName;
  301. dwType = winsName.dwType;
  302. }
  303. return *this;
  304. }
  305. BOOL operator == (const CWinsName & winsName)
  306. {
  307. if ( (strName.Compare(winsName.strName) == 0) &&
  308. (dwType == winsName.dwType) )
  309. {
  310. return TRUE;
  311. }
  312. else
  313. {
  314. return FALSE;
  315. }
  316. }
  317. public:
  318. CString strName;
  319. DWORD dwType;
  320. };
  321. typedef CArray<CWinsName, CWinsName&> CWinsNameArray;
  322. /*---------------------------------------------------------------------------
  323. Class: CTypeFilterInfo
  324. ---------------------------------------------------------------------------*/
  325. class CTypeFilterInfo
  326. {
  327. public:
  328. CTypeFilterInfo()
  329. {
  330. dwType = 0;
  331. fShow = TRUE;
  332. }
  333. CTypeFilterInfo(CTypeFilterInfo & typeFilterInfo)
  334. {
  335. *this = typeFilterInfo;
  336. }
  337. CTypeFilterInfo & operator = (const CTypeFilterInfo & typeFilterInfo)
  338. {
  339. if (this != &typeFilterInfo)
  340. {
  341. dwType = typeFilterInfo.dwType;
  342. fShow = typeFilterInfo.fShow;
  343. }
  344. return *this;
  345. }
  346. BOOL operator == (const CTypeFilterInfo & typeFilterInfo)
  347. {
  348. if ( (fShow == typeFilterInfo.fShow) &&
  349. (dwType == typeFilterInfo.dwType) )
  350. {
  351. return TRUE;
  352. }
  353. else
  354. {
  355. return FALSE;
  356. }
  357. }
  358. public:
  359. DWORD dwType;
  360. BOOL fShow;
  361. };
  362. typedef CArray<CTypeFilterInfo, CTypeFilterInfo&> CTypeFilterInfoArray;
  363. #endif //#define _WINSSUP_H