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.

616 lines
14 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 wszNameVerify[100];
  205. //
  206. // The format of Adapter Status responses
  207. //
  208. typedef struct
  209. {
  210. ADAPTER_STATUS AdapterInfo;
  211. NAME_BUFFER Names[32];
  212. } tADAPTERSTATUS;
  213. extern WCHAR *messages[];
  214. #define MAX_NB_NAMES 1000
  215. #define MAX_SERVERS 1000
  216. #define BUFF_SIZE 650
  217. #define MAX_SIZE 1024
  218. #define INFINITE_EXPIRATION 0x7FFFFFFF
  219. #define MAX(a, b) ( ( (a) > (b) ) ? (a) : (b) )
  220. #define MIN(a, b) ( ( (a) > (b) ) ? (b) : (a) )
  221. extern SOCKET sd;
  222. extern WSADATA WsaData;
  223. struct sockaddr_in myad;
  224. struct sockaddr_in recvad;
  225. int addrlen;
  226. u_short TranID;
  227. extern u_long NonBlocking;
  228. extern int NumWinServers;
  229. extern int NumNBNames;
  230. extern u_char **NBNames;
  231. u_long VerifiedAddress[MAX_NB_NAMES];
  232. typedef struct
  233. {
  234. BOOLEAN fQueried;
  235. struct in_addr Server;
  236. struct in_addr RetAddr;
  237. int Valid;
  238. int Failed;
  239. int Retries;
  240. int LastResponse;
  241. int Completed;
  242. } WINSERVERS;
  243. extern WINSERVERS * WinServers;
  244. #define NBT_NONCODED_NMSZ 17
  245. #define NBT_NAMESIZE 34
  246. ULONG NetbtIpAddress;
  247. typedef struct _NameResponse
  248. {
  249. u_short TransactionID;
  250. u_short Flags;
  251. u_short QuestionCount;
  252. u_short AnswerCount;
  253. u_short NSCount;
  254. u_short AdditionalRec;
  255. u_char AnswerName[NBT_NAMESIZE];
  256. u_short AnswerType;
  257. u_short AnswerClass;
  258. u_short AnswerTTL1;
  259. u_short AnswerTTL2;
  260. u_short AnswerLength;
  261. u_short AnswerFlags;
  262. u_short AnswerAddr1;
  263. u_short AnswerAddr2;
  264. } NameResponse;
  265. #define NAME_RESPONSE_BUFFER_SIZE sizeof(NameResponse) * 10
  266. DWORD
  267. FormatDateTimeString( IN time_t time,
  268. IN BOOL fShort,
  269. OUT LPWSTR pwszBuffer,
  270. IN DWORD *pdwBuffLen);
  271. INT
  272. CheckNameConsistency();
  273. DWORD
  274. DisplayErrorMessage(
  275. IN DWORD dwMsgID,
  276. IN DWORD dwErrID,
  277. ...
  278. );
  279. BOOL
  280. IsIpAddress(
  281. IN LPCWSTR pwszAddress
  282. );
  283. UCHAR StringToHexA(IN LPCWSTR pwcString);
  284. BOOL
  285. IsPureNumeric(
  286. IN LPCWSTR pwszStr
  287. );
  288. BOOL
  289. IsValidServer(
  290. IN LPCWSTR pwszServer
  291. );
  292. BOOL
  293. IsLocalServer( VOID );
  294. DWORD
  295. CreateDumpFile(
  296. IN LPCWSTR pwszName,
  297. OUT PHANDLE phFile
  298. );
  299. VOID
  300. CheckVersionNumbers(
  301. IN LPCSTR pStartIp,
  302. IN BOOL fFile,
  303. OUT FILE * pFile
  304. );
  305. DWORD
  306. ControlWINSService(IN BOOL bStop);
  307. VOID
  308. CloseDumpFile(
  309. IN HANDLE hFile
  310. );
  311. LPWSTR
  312. WinsOemToUnicodeN(
  313. IN LPCSTR Ansi,
  314. IN OUT LPWSTR Unicode,
  315. IN USHORT cChars
  316. );
  317. LPWSTR
  318. WinsOemToUnicode(
  319. IN LPCSTR Ansi,
  320. IN OUT LPWSTR Unicode
  321. );
  322. LPSTR
  323. WinsUnicodeToOem(
  324. IN LPCWSTR Unicode,
  325. IN OUT LPSTR Ansi
  326. );
  327. LPWSTR
  328. WinsAnsiToUnicode(
  329. IN LPCSTR Ansi,
  330. IN OUT LPWSTR Unicode
  331. );
  332. LPSTR
  333. WinsUnicodeToAnsi(
  334. IN LPCWSTR Unicode,
  335. IN OUT LPSTR Ansi
  336. );
  337. LPSTR
  338. WinsAnsiToOem(
  339. IN LPCSTR Ansi
  340. );
  341. VOID
  342. WinsHexToString(
  343. OUT LPWSTR Buffer,
  344. IN const BYTE * HexNumber,
  345. IN DWORD Length
  346. );
  347. VOID
  348. WinsHexToAscii(
  349. OUT LPSTR Buffer,
  350. IN const BYTE * HexNumber,
  351. IN DWORD Length
  352. );
  353. VOID
  354. WinsDecimalToString(
  355. OUT LPWSTR Buffer,
  356. IN BYTE Number
  357. );
  358. DWORD
  359. WinsDottedStringToIpAddress(
  360. IN LPCSTR String
  361. );
  362. LPSTR
  363. WinsIpAddressToDottedString(
  364. IN DWORD IpAddress
  365. );
  366. DWORD
  367. WinsStringToHwAddress(
  368. IN LPCSTR AddressBuffer,
  369. IN LPCSTR AddressString
  370. );
  371. LPWSTR
  372. MakeTimeString(
  373. IN DWORD dwTime
  374. );
  375. LPWSTR
  376. MakeDayTimeString(
  377. IN DWORD dwTime
  378. );
  379. DWORD
  380. WinsDottedStringToIpAddressW(
  381. IN LPCWSTR pwszString
  382. );
  383. LPWSTR
  384. WinsIpAddressToDottedStringW(
  385. IN DWORD IpAddress
  386. );
  387. DWORD
  388. GetVersionData(
  389. IN LPWSTR pwszVers,
  390. IN WINSINTF_VERS_NO_T *Version
  391. );
  392. DWORD
  393. ImportStaticMappingsFile(IN LPWSTR strFile,
  394. IN BOOL fDelete
  395. );
  396. DWORD
  397. PreProcessCommand(
  398. IN OUT LPWSTR *ppwcArguments,
  399. IN DWORD dwArgCount,
  400. IN DWORD dwCurrentIndex,
  401. IN OUT PTAG_TYPE pTagTable,
  402. IN OUT PDWORD pdwTagCount,
  403. OUT PDWORD pdwTagType,
  404. OUT PDWORD pdwTagNum
  405. );
  406. DWORD
  407. GetStatus(
  408. IN BOOL fPrint,
  409. LPVOID pResultsA,
  410. BOOL fNew,
  411. BOOL fShort,
  412. LPCSTR pStartIp
  413. );
  414. DWORD
  415. GetDbRecs(
  416. WINSINTF_VERS_NO_T LowVersNo,
  417. WINSINTF_VERS_NO_T HighVersNo,
  418. PWINSINTF_ADD_T pWinsAdd,
  419. LPBYTE pTgtAdd,
  420. BOOL fSetFilter,
  421. LPBYTE pFilterName,
  422. DWORD Len,
  423. BOOL fAddFilter,
  424. DWORD AddFilter,
  425. BOOL fCountRec,
  426. BOOL fCase,
  427. BOOL fFile,
  428. LPWSTR pwszFile
  429. );
  430. DWORD
  431. WinsDumpServer(IN LPCWSTR pwszServerIp,
  432. IN LPCWSTR pwszNetBiosName,
  433. IN handle_t hBind,
  434. IN WINSINTF_BIND_DATA_T BindData
  435. );
  436. NS_CONTEXT_DUMP_FN WinsDump;
  437. VOID
  438. ChkAdd(
  439. PWINSINTF_RECORD_ACTION_T pRow,
  440. DWORD Add,
  441. BOOL fFile,
  442. FILE * pFile,
  443. DWORD OwnerIP,
  444. LPBOOL pfMatch
  445. );
  446. VOID
  447. DumpMessage(
  448. HANDLE hModule,
  449. FILE * pFile,
  450. DWORD dwMsgId,
  451. ...
  452. );
  453. #if DBG
  454. VOID
  455. WinsPrintRoutine(
  456. IN DWORD DebugFlag,
  457. IN LPCSTR Format,
  458. ...
  459. );
  460. VOID
  461. WinsAssertFailed(
  462. IN LPCSTR FailedAssertion,
  463. IN LPCSTR FileName,
  464. IN DWORD LineNumber,
  465. IN LPCSTR Message
  466. );
  467. #define WinsPrint(_x_) WinsPrintRoutine _x_
  468. #define WinsAssert(Predicate) \
  469. { \
  470. if (!(Predicate)) \
  471. WinsAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  472. }
  473. #define WinsVerify(Predicate) \
  474. { \
  475. if (!(Predicate)) \
  476. WinsAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  477. }
  478. #else
  479. #define WinsAssert(_x_)
  480. #define WinsDumpMessage(_x_, _y_)
  481. #define WinsVerify(_x_) (_x_)
  482. #endif // not DBG
  483. #endif //_COMMON_H_