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.

619 lines
13 KiB

  1. /*++
  2. Copyright (C) 1999 Microsoft Corporation
  3. --*/
  4. #ifndef _COMMON_H_
  5. #define _COMMON_H_
  6. #define is ==
  7. #define isnot !=
  8. #define and &&
  9. #define or ||
  10. #define FUTURES(x)
  11. #define MCAST 1
  12. #define MAX_DLL_NAME 48
  13. #define WINS_HELPER_VERSION 1
  14. #define MAX_IP_STRING_LEN 15
  15. #define MAX_MSG_LENGTH 5120
  16. #define MAX_HELPER_NAME MAX_DLL_NAME
  17. #define MAX_NAME_LEN MAX_DLL_NAME
  18. #define MAX_ENTRY_PT_NAME MAX_DLL_NAME
  19. #define MAX_STRING_LEN 256
  20. #define TMSTN ResultsN.WinsStat.TimeStamps
  21. #define TMST Results.WinsStat.TimeStamps
  22. #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
  23. #define TIME_ARGSN(x) \
  24. TMSTN.x.wMonth, TMSTN.x.wDay, TMSTN.x.wYear, TMSTN.x.wHour, TMSTN.x.wMinute, TMSTN.x.wSecond
  25. #define TIME_ARGS(x) \
  26. TMST.x.wMonth, TMST.x.wDay, TMST.x.wYear, TMST.x.wHour, TMST.x.wMinute, TMST.x.wSecond
  27. #ifdef UNICODE
  28. #define STRICMP(x, y) _wcsicmp(x, y)
  29. #else
  30. #define STRICMP(x, y) _stricmp(x, y)
  31. #endif //UNICODE
  32. #ifdef UNICODE
  33. #define STRTOUL(x, y, z) wcstoul(x, y, z)
  34. #else
  35. #define STRTOUL(x, y, z) strtoul(x, y, z)
  36. #endif //UNICODE
  37. #ifdef UNICODE
  38. #define STRCHR(x, y) wcschr(x, y)
  39. #else
  40. #define STRCHR(x, y) strchr(x, y)
  41. #endif //UNICODE
  42. #ifdef UNICODE
  43. #define STRCAT(x, y) wcscat(x, y)
  44. #else
  45. #define STRCAT(x, y) strcat(x, y)
  46. #endif //UNICODE
  47. #ifdef UNICODE
  48. #define STRLEN(x) wcslen(x)
  49. #else
  50. #define STRCAT(x) strlen(x)
  51. #endif //UNICODE
  52. #ifdef UNICODE
  53. #define ATOI(x) _wtoi(x)
  54. #else
  55. #define ATOI(x) atoi(x)
  56. #endif //UNICODE
  57. #ifdef NT5
  58. #define CHKNULL(Str) ((Str)?(Str):TEXT("<None>"))
  59. #endif //NT5
  60. #ifdef UNICODE
  61. #define IpAddressToString WinsIpAddressToDottedStringW
  62. #else
  63. #define IpAddressToString WinsIpAddressToDottedString
  64. #endif //UNICODE
  65. #ifdef UNICODE
  66. #define StringToIpAddress WinsDottedStringToIpAddressW
  67. #else
  68. #define StringToIpAddress WinsDottedStringToIpAddress
  69. #endif //UNICODE
  70. #ifndef _DEBUG
  71. #define DEBUG(s)
  72. #define DEBUG1(s1,s2)
  73. #define DEBUG2(s1,s2)
  74. #else
  75. #define DEBUG(s) wprintf(L"%s\n", L##s)
  76. #define DEBUG1(s1,s2) wprintf(L##s1, L##s2)
  77. #define DEBUG2(s1,s2) wprintf(L##s1, L##s2)
  78. #endif
  79. #define LiLtr(a, b) ((a).QuadPart < (b).QuadPart)
  80. #define LiAdd(a,b) ((a).QuadPart + (b).QuadPart)
  81. #define MAX_COMPUTER_NAME_LEN 256
  82. //
  83. //
  84. //Wins registry entry definitions
  85. #define WINSROOT TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins")
  86. #define CCROOT TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Parameters\\ConsistencyCheck")
  87. #define CC TEXT("ConsistencyCheck")
  88. #define PARAMETER TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Parameters")
  89. #define DEFAULTROOT TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Parameters\\Defaults")
  90. #define DEFAULTPULL TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Parameters\\Defaults\\Pull")
  91. #define DEFAULTPUSH TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Parameters\\Defaults\\Push")
  92. #define PARTNERROOT TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Partners")
  93. #define PULLROOT TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Partners\\Pull")
  94. #define PUSHROOT TEXT("SYSTEM\\CurrentControlSet\\Services\\Wins\\Partners\\Push")
  95. #define NETBIOSNAME TEXT("NetBiosName")
  96. #define PERSISTENCE TEXT("PersistentRplOn")
  97. #define PNGSERVER TEXT(WINSCNF_PERSONA_NON_GRATA_NM)
  98. #define PGSERVER TEXT(WINSCNF_PERSONA_GRATA_NM)
  99. //These definitions copied from rnraddrs.h
  100. #define TTL_SUBNET_ONLY 1 // no routing
  101. #define TTL_REASONABLE_REACH 2 // across one router
  102. #define TTL_MAX_REACH 6 // Default max diameter. This may
  103. // be overriden via the Registry.
  104. //
  105. //For determining Systems version
  106. //
  107. #define SERVERVERSION TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion")
  108. #define WINSVERSION TEXT("CurrentVersion")
  109. #define SPVERSION TEXT("CSDVersion")
  110. #define BUILDNUMBER TEXT("CurrentBuildNumber")
  111. //different default settings...
  112. #define NAMERECORD_REFRESH_DEFAULT 6*24*60*60
  113. #define NAMERECORD_EXTMOUT_DEFAULT 6*24*60*60
  114. #define NAMERECORD_EXINTVL_DEFAULT 6*24*60*60
  115. #define NAMERECORD_VERIFY_DEFAULT 24*24*60*60
  116. #define ONE_YEAR 365*24*60*60
  117. #define MAX_PATH_LEN 100
  118. #define WINSTEST_FOUND 0
  119. #define WINSTEST_NOT_FOUND 1
  120. #define WINSTEST_NO_RESPONSE 2
  121. #define WINSTEST_VERIFIED 0
  122. #define WINSTEST_OUT_OF_MEMORY 3
  123. #define WINSTEST_BAD_IP_ADDRESS 4
  124. #define WINSTEST_HOST_NOT_FOUND 5
  125. #define WINSTEST_NOT_VERIFIED 6
  126. #define WINSTEST_INVALID_ARG 7
  127. #define WINSTEST_OPEN_FAILED 8
  128. #define _NBT_CFG_ADAPTERS_KEY TEXT("System\\CurrentControlSet\\Services\\NetBT\\Adapters")
  129. #define RPL_E_PULL 0
  130. #define RPL_E_PUSH 1
  131. #define RE_QUERY_REGISTRY_COUNT 10
  132. ULONG LocalIpAddress;
  133. CHAR pScope[128];
  134. #define MAX_WINS 1000
  135. //
  136. // <Server> - <Owner> Table - [SO] Table
  137. //
  138. extern LARGE_INTEGER ** SO_Table;
  139. //
  140. // Lookaside table to map IP addrs to the index into the SO_Table
  141. //
  142. extern WCHAR ** LA_Table;
  143. extern ULONG LA_TableSize;
  144. VOID
  145. DumpSOTable(
  146. IN DWORD MasterOwners,
  147. IN BOOL fFile,
  148. IN FILE * pFile
  149. );
  150. VOID
  151. DumpLATable(
  152. IN DWORD MasterOwners,
  153. IN BOOL fFile,
  154. IN FILE * pFile
  155. );
  156. typedef struct _WINSMON_SUBCONTEXT_TABLE_ENTRY
  157. {
  158. //
  159. // Name of the context
  160. //
  161. LPWSTR pwszContext;
  162. //
  163. //Short command help
  164. DWORD dwShortCmdHlpToken;
  165. //Detail command help
  166. DWORD dwCmdHlpToken;
  167. PNS_CONTEXT_ENTRY_FN pfnEntryFn;
  168. }WINSMON_SUBCONTEXT_TABLE_ENTRY,*PWINSMON_SUBCONTEXT_TABLE_ENTRY;
  169. PVOID WinsAllocateMemory(DWORD dwSize);
  170. VOID WinsFreeMemory(PVOID Memory);
  171. extern HANDLE g_hModule;
  172. extern BOOL g_bCommit;
  173. extern BOOL g_hConnect;
  174. extern BOOL g_fServer;
  175. extern DWORD g_dwNumTableEntries;
  176. extern PWCHAR g_pwszServer;
  177. extern ULONG g_ulInitCount;
  178. extern ULONG g_ulNumTopCmds;
  179. extern ULONG g_ulNumGroups;
  180. extern DWORD g_dwMajorVersion;
  181. extern DWORD g_dwMinorVersion;
  182. extern LPWSTR g_ServerNameUnicode;
  183. extern LPSTR g_ServerNameAnsi;
  184. extern CHAR g_ServerIpAddressAnsiString[MAX_IP_STRING_LEN+1];
  185. extern WCHAR g_ServerIpAddressUnicodeString[MAX_IP_STRING_LEN+1];
  186. extern HKEY g_hServerRegKey;
  187. extern WCHAR g_ServerNetBiosName[MAX_COMPUTER_NAME_LEN];
  188. extern handle_t g_hBind;
  189. extern WINSINTF_BIND_DATA_T g_BindData;
  190. extern WCHAR wszUnknown[50];
  191. extern WCHAR wszEnable[50];
  192. extern WCHAR wszDisable[50];
  193. extern WCHAR wszRandom[150];
  194. extern WCHAR wszOwner[150];
  195. extern WCHAR wszInfinite[100];
  196. extern WCHAR wszPush[50];
  197. extern WCHAR wszPull[50];
  198. extern WCHAR wszPushpull[50];
  199. extern WCHAR wszHigh[50];
  200. extern WCHAR wszNormal[50];
  201. extern WCHAR wszDeleted[150];
  202. extern WCHAR wszOK[50];
  203. extern WCHAR wszFailure[50];
  204. extern WCHAR wszReadwrite[50];
  205. extern WCHAR wszRead[50];
  206. extern WCHAR wszNo[50];
  207. extern WCHAR wszNameVerify[100];
  208. //
  209. // The format of Adapter Status responses
  210. //
  211. typedef struct
  212. {
  213. ADAPTER_STATUS AdapterInfo;
  214. NAME_BUFFER Names[32];
  215. } tADAPTERSTATUS;
  216. extern WCHAR *messages[];
  217. #define MAX_NB_NAMES 1000
  218. #define MAX_SERVERS 1000
  219. #define BUFF_SIZE 650
  220. #define MAX_SIZE 1024
  221. #define INFINITE_EXPIRATION 0x7FFFFFFF
  222. #define MAX(a, b) ( ( (a) > (b) ) ? (a) : (b) )
  223. #define MIN(a, b) ( ( (a) > (b) ) ? (b) : (a) )
  224. extern SOCKET sd;
  225. extern WSADATA WsaData;
  226. struct sockaddr_in myad;
  227. struct sockaddr_in recvad;
  228. int addrlen;
  229. u_short TranID;
  230. extern u_long NonBlocking;
  231. extern int NumWinServers;
  232. extern int NumNBNames;
  233. extern u_char **NBNames;
  234. u_long VerifiedAddress[MAX_NB_NAMES];
  235. typedef struct
  236. {
  237. BOOLEAN fQueried;
  238. struct in_addr Server;
  239. struct in_addr RetAddr;
  240. int Valid;
  241. int Failed;
  242. int Retries;
  243. int LastResponse;
  244. int Completed;
  245. } WINSERVERS;
  246. extern WINSERVERS * WinServers;
  247. #define NBT_NONCODED_NMSZ 17
  248. #define NBT_NAMESIZE 34
  249. ULONG NetbtIpAddress;
  250. typedef struct _NameResponse
  251. {
  252. u_short TransactionID;
  253. u_short Flags;
  254. u_short QuestionCount;
  255. u_short AnswerCount;
  256. u_short NSCount;
  257. u_short AdditionalRec;
  258. u_char AnswerName[NBT_NAMESIZE];
  259. u_short AnswerType;
  260. u_short AnswerClass;
  261. u_short AnswerTTL1;
  262. u_short AnswerTTL2;
  263. u_short AnswerLength;
  264. u_short AnswerFlags;
  265. u_short AnswerAddr1;
  266. u_short AnswerAddr2;
  267. } NameResponse;
  268. #define NAME_RESPONSE_BUFFER_SIZE sizeof(NameResponse) * 10
  269. DWORD
  270. FormatDateTimeString( IN time_t time,
  271. IN BOOL fShort,
  272. OUT LPWSTR pwszBuffer,
  273. IN DWORD *pdwBuffLen);
  274. INT
  275. CheckNameConsistency();
  276. DWORD
  277. DisplayErrorMessage(
  278. IN DWORD dwMsgID,
  279. IN DWORD dwErrID,
  280. ...
  281. );
  282. BOOL
  283. IsIpAddress(
  284. IN LPCWSTR pwszAddress
  285. );
  286. UCHAR StringToHexA(IN LPCWSTR pwcString);
  287. BOOL
  288. IsPureNumeric(
  289. IN LPCWSTR pwszStr
  290. );
  291. BOOL
  292. IsValidServer(
  293. IN LPCWSTR pwszServer
  294. );
  295. BOOL
  296. IsLocalServer( VOID );
  297. DWORD
  298. CreateDumpFile(
  299. IN LPCWSTR pwszName,
  300. OUT PHANDLE phFile
  301. );
  302. VOID
  303. CheckVersionNumbers(
  304. IN LPCSTR pStartIp,
  305. IN BOOL fFile,
  306. OUT FILE * pFile
  307. );
  308. DWORD
  309. ControlWINSService(IN BOOL bStop);
  310. VOID
  311. CloseDumpFile(
  312. IN HANDLE hFile
  313. );
  314. LPWSTR
  315. WinsOemToUnicodeN(
  316. IN LPCSTR Ansi,
  317. IN OUT LPWSTR Unicode,
  318. IN USHORT cChars
  319. );
  320. LPWSTR
  321. WinsOemToUnicode(
  322. IN LPCSTR Ansi,
  323. IN OUT LPWSTR Unicode
  324. );
  325. LPSTR
  326. WinsUnicodeToOem(
  327. IN LPCWSTR Unicode,
  328. IN OUT LPSTR Ansi
  329. );
  330. LPWSTR
  331. WinsAnsiToUnicode(
  332. IN LPCSTR Ansi,
  333. IN OUT LPWSTR Unicode
  334. );
  335. LPSTR
  336. WinsUnicodeToAnsi(
  337. IN LPCWSTR Unicode,
  338. IN OUT LPSTR Ansi
  339. );
  340. LPSTR
  341. WinsAnsiToOem(
  342. IN LPCSTR Ansi
  343. );
  344. VOID
  345. WinsHexToString(
  346. OUT LPWSTR Buffer,
  347. IN const BYTE * HexNumber,
  348. IN DWORD Length
  349. );
  350. VOID
  351. WinsHexToAscii(
  352. OUT LPSTR Buffer,
  353. IN const BYTE * HexNumber,
  354. IN DWORD Length
  355. );
  356. VOID
  357. WinsDecimalToString(
  358. OUT LPWSTR Buffer,
  359. IN BYTE Number
  360. );
  361. DWORD
  362. WinsDottedStringToIpAddress(
  363. IN LPCSTR String
  364. );
  365. LPSTR
  366. WinsIpAddressToDottedString(
  367. IN DWORD IpAddress
  368. );
  369. DWORD
  370. WinsStringToHwAddress(
  371. IN LPCSTR AddressBuffer,
  372. IN LPCSTR AddressString
  373. );
  374. LPWSTR
  375. MakeTimeString(
  376. IN DWORD dwTime
  377. );
  378. LPWSTR
  379. MakeDayTimeString(
  380. IN DWORD dwTime
  381. );
  382. DWORD
  383. WinsDottedStringToIpAddressW(
  384. IN LPCWSTR pwszString
  385. );
  386. LPWSTR
  387. WinsIpAddressToDottedStringW(
  388. IN DWORD IpAddress
  389. );
  390. DWORD
  391. GetVersionData(
  392. IN LPWSTR pwszVers,
  393. IN WINSINTF_VERS_NO_T *Version
  394. );
  395. DWORD
  396. ImportStaticMappingsFile(IN LPWSTR strFile,
  397. IN BOOL fDelete
  398. );
  399. DWORD
  400. PreProcessCommand(
  401. IN OUT LPWSTR *ppwcArguments,
  402. IN DWORD dwArgCount,
  403. IN DWORD dwCurrentIndex,
  404. IN OUT PTAG_TYPE pTagTable,
  405. IN OUT PDWORD pdwTagCount,
  406. OUT PDWORD pdwTagType,
  407. OUT PDWORD pdwTagNum
  408. );
  409. DWORD
  410. GetStatus(
  411. IN BOOL fPrint,
  412. LPVOID pResultsA,
  413. BOOL fNew,
  414. BOOL fShort,
  415. LPCSTR pStartIp
  416. );
  417. DWORD
  418. GetDbRecs(
  419. WINSINTF_VERS_NO_T LowVersNo,
  420. WINSINTF_VERS_NO_T HighVersNo,
  421. PWINSINTF_ADD_T pWinsAdd,
  422. LPBYTE pTgtAdd,
  423. BOOL fSetFilter,
  424. LPBYTE pFilterName,
  425. DWORD Len,
  426. BOOL fAddFilter,
  427. DWORD AddFilter,
  428. BOOL fCountRec,
  429. BOOL fCase,
  430. BOOL fFile,
  431. LPWSTR pwszFile
  432. );
  433. DWORD
  434. WinsDumpServer(IN LPCWSTR pwszServerIp,
  435. IN LPCWSTR pwszNetBiosName,
  436. IN handle_t hBind,
  437. IN WINSINTF_BIND_DATA_T BindData
  438. );
  439. NS_CONTEXT_DUMP_FN WinsDump;
  440. VOID
  441. ChkAdd(
  442. PWINSINTF_RECORD_ACTION_T pRow,
  443. DWORD Add,
  444. BOOL fFile,
  445. FILE * pFile,
  446. DWORD OwnerIP,
  447. LPBOOL pfMatch
  448. );
  449. VOID
  450. DumpMessage(
  451. HANDLE hModule,
  452. FILE * pFile,
  453. DWORD dwMsgId,
  454. ...
  455. );
  456. #if DBG
  457. VOID
  458. WinsPrintRoutine(
  459. IN DWORD DebugFlag,
  460. IN LPCSTR Format,
  461. ...
  462. );
  463. VOID
  464. WinsAssertFailed(
  465. IN LPCSTR FailedAssertion,
  466. IN LPCSTR FileName,
  467. IN DWORD LineNumber,
  468. IN LPCSTR Message
  469. );
  470. #define WinsPrint(_x_) WinsPrintRoutine _x_
  471. #define WinsAssert(Predicate) \
  472. { \
  473. if (!(Predicate)) \
  474. WinsAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  475. }
  476. #define WinsVerify(Predicate) \
  477. { \
  478. if (!(Predicate)) \
  479. WinsAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  480. }
  481. #else
  482. #define WinsAssert(_x_)
  483. #define WinsDumpMessage(_x_, _y_)
  484. #define WinsVerify(_x_) (_x_)
  485. #endif // not DBG
  486. #endif //_COMMON_H_