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.

560 lines
14 KiB

  1. /*++
  2. Copyright (C) 1998 Microsoft Corporation
  3. --*/
  4. #ifndef _COMMON_H_
  5. #define _COMMON_H_
  6. #define MAX_IP_STRING_LEN 15
  7. #ifdef UNICODE
  8. #define STRICMP(x, y) _wcsicmp(x, y)
  9. #else
  10. #define STRICMP(x, y) _stricmp(x, y)
  11. #endif //UNICODE
  12. #ifdef UNICODE
  13. #define STRTOUL(x, y, z) wcstoul(x, y, z)
  14. #else
  15. #define STRTOUL(x, y, z) strtoul(x, y, z)
  16. #endif //UNICODE
  17. #ifdef UNICODE
  18. #define STRCHR(x, y) wcschr(x, y)
  19. #else
  20. #define STRCHR(x, y) strchr(x, y)
  21. #endif //UNICODE
  22. #ifdef UNICODE
  23. #define STRCAT(x, y) wcscat(x, y)
  24. #else
  25. #define STRCAT(x, y) strcat(x, y)
  26. #endif //UNICODE
  27. #ifdef UNICODE
  28. #define STRLEN(x) wcslen(x)
  29. #else
  30. #define STRCAT(x) strlen(x)
  31. #endif //UNICODE
  32. #ifdef UNICODE
  33. #define ATOI(x) _wtoi(x)
  34. #else
  35. #define ATOI(x) atoi(x)
  36. #endif //UNICODE
  37. #ifdef NT5
  38. #define CHKNULL(Str) ((Str)?(Str):TEXT("<None>"))
  39. #endif //NT5
  40. #ifdef UNICODE
  41. #define IpAddressToString DhcpIpAddressToDottedStringW
  42. #else
  43. #define IpAddressToString DhcpIpAddressToDottedString
  44. #endif //UNICODE
  45. #ifdef UNICODE
  46. #define StringToIpAddress DhcpDottedStringToIpAddressW
  47. #else
  48. #define StringToIpAddress DhcpDottedStringToIpAddress
  49. #endif //UNICODE
  50. #undef DhcpAllocateMemory
  51. #undef DhcpFreeMemory
  52. #ifndef _DEBUG
  53. #define DEBUG(s)
  54. #define DEBUG1(s1,s2)
  55. #define DEBUG2(s1,s2)
  56. #else
  57. #define DEBUG(s) wprintf(L"%s\n", L##s)
  58. #define DEBUG1(s1,s2) wprintf(L##s1, L##s2)
  59. #define DEBUG2(s1,s2) wprintf(L##s1, L##s2)
  60. #endif
  61. #define SRVRMON_VERSION_50 5
  62. #define DHCPMON_VERSION_50 5
  63. #define SCOPEMON_VERSION_50 5
  64. #define is ==
  65. #define isnot !=
  66. #define or ||
  67. #define and &&
  68. #define CLASS_ID_VERSION 0x5
  69. #define MAX_STRING_LEN 256
  70. #define REG_VALUE_ENTRY_PT L"EntryPoint"
  71. #define REG_VALUE_DUMP_FN L"DumpFunction"
  72. #define REG_KEY_DHCPSCOPE_HELPER L"SOFTWARE\\Microsoft\\Netsh\\Dhcp\\Server\\Scope"
  73. #define REG_KEY_DHCPSRVR_HELPER L"SOFTWARE\\Microsoft\\Netsh\\Dhcp\\Server"
  74. #define REG_KEY_DHCPMGR_HELPER L"SOFTWARE\\Microsoft\\Netsh\\Dhcp"
  75. #define MaxIfDisplayLength 1024
  76. #define ADDR_LENGTH 24
  77. #define ADDR_LEN 4
  78. #define DEFAULT_DHCP_LEASE 8*24*60*60
  79. #define DEFAULT_BOOTP_LEASE 30*24*60*60
  80. #define DEFAULT_MULTICAST_TTL 0x20
  81. #define INFINIT_TIME 0x7FFFFFFF // time_t is int
  82. #define INFINIT_LEASE 0xFFFFFFFF // in secs. (unsigned int.)
  83. typedef struct _COMMAND_OPTION_TYPE
  84. {
  85. LPWSTR pwszTagID;
  86. DHCP_OPTION_DATA_TYPE DataType;
  87. LPWSTR pwcTag;
  88. } COMMAND_OPTION_TYPE, *PCOMMAND_OPTION_TYPE;
  89. extern COMMAND_OPTION_TYPE TagOptionType[ 8 ];/* =
  90. { TAG_OPTION_BYTE, DhcpByteOption, L"BYTE" },
  91. { TAG_OPTION_WORD, DhcpWordOption, L"WORD" },
  92. { TAG_OPTION_DWORD, DhcpDWordOption, L"DWORD" },
  93. { TAG_OPTION_DWORDDWORD, DhcpDWordDWordOption, L"DWORDDWORD" },
  94. { TAG_OPTION_IPADDRESS, DhcpIpAddressOption, L"IPADDRESS" },
  95. { TAG_OPTION_STRING, DhcpStringDataOption, L"STRING" },
  96. { TAG_OPTION_BINARY, DhcpBinaryDataOption, L"BINARY" },
  97. { TAG_OPTION_ENCAPSULATED, DhcpEncapsulatedDataOption, L"ENCAPSULATED" }
  98. */
  99. #define DISPLAYLEN_PHYSADDR 3*MAXLEN_PHYSADDR + 8
  100. #define PRINT(s) wprintf(L"%s\n",L##s)
  101. #define PRINT1(s,s1) wprintf(L##s , L##s1)
  102. #ifdef UNICODE
  103. #define MakeUnicodeIpAddr(ptszUnicode,pszAddr) \
  104. MultiByteToWideChar(CP_ACP, \
  105. 0, \
  106. (pszAddr), \
  107. -1, \
  108. (ptszUnicode), \
  109. ADDR_LENGTH)
  110. #else
  111. #define MakeUnicodeIpAddr(ptszUnicode,pszAddr) \
  112. strcpy((ptszUnicode),(pszAddr))
  113. #endif //UNICODE
  114. #ifdef UNICODE
  115. #define MakeUnicodePhysAddr(ptszUnicode,pszAddr,dwLen) \
  116. { \
  117. CHAR __szTemp[DISPLAYLEN_PHYSADDR + 1]; \
  118. DWORD __i,__dwTempLen; \
  119. __dwTempLen = (((dwLen) <= MAXLEN_PHYSADDR) ? (dwLen) : MAXLEN_PHYSADDR); \
  120. for(__i = 0; __i < __dwTempLen; __i++) \
  121. { \
  122. sprintf(&(__szTemp[3*__i]),"%02X-",pszAddr[__i]); \
  123. } \
  124. MultiByteToWideChar(CP_ACP, \
  125. 0, \
  126. (__szTemp), \
  127. -1, \
  128. (ptszUnicode), \
  129. 3*__i); \
  130. ptszUnicode[(3*__i) - 1] = TEXT('\0'); \
  131. }
  132. #else
  133. #define MakeUnicodePhysAddr(ptszUnicode,pszAddr,dwLen) \
  134. { \
  135. CHAR __szTemp[DISPLAYLEN_PHYSADDR + 1]; \
  136. DWORD __i,__dwTempLen; \
  137. __dwTempLen = (((dwLen) <= MAXLEN_PHYSADDR) ? (dwLen) : MAXLEN_PHYSADDR); \
  138. for(__i = 0; __i < __dwTempLen; __i++) \
  139. { \
  140. sprintf(&(__szTemp[3*__i]),"%02X-",pszAddr[__i]); \
  141. } \
  142. strncpy((ptszUnicode),__szTemp,3*__i); \
  143. ptszUnicode[(3*__i) - 1] = TEXT('\0'); \
  144. }
  145. #endif //UNICODE
  146. #define GetDispString(gModule, val, str, count, table) \
  147. { \
  148. DWORD __dwInd = 0; \
  149. for( ; __dwInd < (count); __dwInd += 2 ) \
  150. { \
  151. if ( (val) != (table)[ __dwInd ] ) { continue; } \
  152. (str) = MakeString( (gModule), (table)[ __dwInd + 1 ] ); \
  153. break; \
  154. } \
  155. if ( __dwInd >= (count) ) { (str) = MakeString( (gModule), STRING_UNKNOWN ); } \
  156. }
  157. #define FREE_STRING_NOT_NULL(ptszString) if (ptszString) FreeString(ptszString)
  158. #define ERROR_CONFIG 1
  159. #define ERROR_ADMIN 2
  160. #define ERROR_UNIDENTIFIED_MIB 2312
  161. #define ERROR_TOO_FEW_ARGS (ERROR_UNIDENTIFIED_MIB+1)
  162. #define MAX_NUM_INDICES 6
  163. #define PRINT_IPADDR(x) \
  164. ((x)&0x000000ff),(((x)&0x0000ff00)>>8),(((x)&0x00ff0000)>>16),(((x)&0xff000000)>>24)
  165. #define IP_TO_WSTR(str,addr) swprintf((str),L"%d.%d.%d.%d", \
  166. (addr)[0], \
  167. (addr)[1], \
  168. (addr)[2], \
  169. (addr)[3])
  170. #define GET_TOKEN_PRESENT(tokenMask) (dwBitVector & tokenMask)
  171. #define SET_TOKEN_PRESENT(tokenMask) (dwBitVector |= tokenMask)
  172. #define SetErrorType(pdw) *(pdw) = IsRouterRunning()?ERROR_ADMIN:ERROR_CONFIG
  173. #define INFINITE_EXPIRATION 0x7FFFFFFF
  174. #define MSCOPE_START_RANGE StringToIpAddress(L"224.0.0.0")
  175. #define MSCOPE_END_RANGE StringToIpAddress(L"239.255.255.255")
  176. WCHAR StringToHex(LPCWSTR pwcString);
  177. LPSTR StringToHexString(LPCSTR pszStr);
  178. DHCP_IP_ADDRESS
  179. DhcpDefaultSubnetMask(
  180. DHCP_IP_ADDRESS IpAddress
  181. );
  182. DWORD
  183. FormatDateTimeString( FILETIME ftTime,
  184. BOOL fShort,
  185. LPWSTR pwszBuffer,
  186. DWORD *pdwBuffLen);
  187. LPWSTR
  188. GetDateTimeString(FILETIME TimeStamp,
  189. BOOL fShort,
  190. int *piType
  191. );
  192. PVOID
  193. DhcpAllocateMemory(
  194. IN DWORD Size
  195. );
  196. VOID
  197. DhcpFreeMemory(
  198. IN PVOID Memory
  199. );
  200. DATE_TIME
  201. DhcpCalculateTime(
  202. IN DWORD RelativeTime
  203. );
  204. LPWSTR
  205. DhcpOemToUnicodeN(
  206. IN LPCSTR Ansi,
  207. IN OUT LPWSTR Unicode,
  208. IN USHORT cChars
  209. );
  210. LPWSTR
  211. DhcpOemToUnicode(
  212. IN LPCSTR Ansi,
  213. IN OUT LPWSTR Unicode
  214. );
  215. LPSTR
  216. DhcpUnicodeToOem(
  217. IN LPCWSTR Unicode,
  218. OUT LPSTR Ansi
  219. );
  220. VOID
  221. DhcpHexToString(
  222. OUT LPWSTR Buffer,
  223. IN const BYTE * HexNumber,
  224. IN DWORD Length
  225. );
  226. VOID
  227. DhcpHexToAscii(
  228. IN LPSTR Buffer,
  229. IN LPBYTE HexNumber,
  230. IN DWORD Length
  231. );
  232. VOID
  233. DhcpDecimalToString(
  234. IN LPWSTR Buffer,
  235. IN BYTE Number
  236. );
  237. DWORD
  238. DhcpDottedStringToIpAddress(
  239. IN LPSTR String
  240. );
  241. LPSTR
  242. DhcpIpAddressToDottedString(
  243. IN DWORD IpAddress
  244. );
  245. DWORD
  246. DhcpStringToHwAddress(
  247. OUT LPSTR AddressBuffer,
  248. IN LPCSTR AddressString
  249. );
  250. DWORD
  251. DhcpDottedStringToIpAddressW(
  252. IN LPCWSTR pwszString
  253. );
  254. LPWSTR
  255. DhcpIpAddressToDottedStringW(
  256. IN DWORD IpAddress
  257. );
  258. LPWSTR
  259. DhcpRegIpAddressToKey(
  260. IN DHCP_IP_ADDRESS IpAddress,
  261. IN LPCWSTR KeyBuffer
  262. );
  263. DWORD
  264. DhcpRegKeyToIpAddress(
  265. IN LPCWSTR Key
  266. );
  267. LPWSTR
  268. DhcpRegOptionIdToKey(
  269. IN DHCP_OPTION_ID OptionId,
  270. IN LPCWSTR KeyBuffer
  271. );
  272. DHCP_OPTION_ID
  273. DhcpRegKeyToOptionId(
  274. IN LPCWSTR Key
  275. );
  276. #if DBG
  277. VOID
  278. DhcpPrintRoutine(
  279. IN DWORD DebugFlag,
  280. IN LPCSTR Format,
  281. ...
  282. );
  283. VOID
  284. DhcpAssertFailed(
  285. IN LPCSTR FailedAssertion,
  286. IN LPCSTR FileName,
  287. IN DWORD LineNumber,
  288. IN LPSTR Message
  289. );
  290. #define DhcpPrint(_x_) DhcpPrintRoutine _x_
  291. #define DhcpAssert(Predicate) \
  292. { \
  293. if (!(Predicate)) \
  294. DhcpAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  295. }
  296. #define DhcpVerify(Predicate) \
  297. { \
  298. if (!(Predicate)) \
  299. DhcpAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  300. }
  301. #else
  302. #define DhcpAssert(_x_)
  303. #define DhcpDumpMessage(_x_, _y_)
  304. #define DhcpVerify(_x_) (_x_)
  305. #endif // not DBG
  306. DWORD
  307. CreateDumpFile(
  308. IN PWCHAR pwszName,
  309. OUT PHANDLE phFile
  310. );
  311. VOID
  312. CloseDumpFile(
  313. IN HANDLE hFile
  314. );
  315. BOOL
  316. IsIpAddress(
  317. IN LPCWSTR pwszAddress
  318. );
  319. BOOL
  320. IsValidServer(
  321. IN LPCWSTR pwszServer
  322. );
  323. BOOL
  324. IsLocalServer(
  325. IN LPCWSTR pwszServer
  326. );
  327. BOOL
  328. IsValidScope(
  329. IN LPCWSTR pwszServer,
  330. IN LPCWSTR pwszAddress
  331. );
  332. BOOL
  333. IsValidMScope(
  334. IN LPCWSTR pwszServer,
  335. IN LPCWSTR pwszMScope
  336. );
  337. BOOL
  338. IsPureHex(
  339. IN LPCWSTR pwszString
  340. );
  341. DWORD
  342. DhcpDumpServer(
  343. IN LPCWSTR pwszIpAddress,
  344. IN DWORD dwMajor,
  345. IN DWORD dwMinor
  346. );
  347. PBYTE
  348. GetLangTagA();
  349. VOID
  350. DhcpDumpScriptHeader();
  351. VOID
  352. DhcpDumpServerScriptHeader(IN LPCWSTR pwszServer);
  353. VOID
  354. DhcpDumpServerClass(
  355. IN LPCWSTR pwszServer,
  356. IN DHCP_CLASS_INFO ClassInfo);
  357. DWORD
  358. DhcpDumpServerOptiondefV5(IN LPCWSTR pwszServer,
  359. IN LPDHCP_ALL_OPTIONS OptionsAll
  360. );
  361. DWORD
  362. DhcpDumpServerOptiondef(IN LPCWSTR pwszServer,
  363. LPDHCP_OPTION_ARRAY OptionArray
  364. );
  365. DWORD
  366. DhcpDumpServerOptionValuesV5(IN LPCWSTR pwszServer,
  367. IN LPCWSTR pwszScope,
  368. IN LPCWSTR pwszReserved,
  369. IN LPDHCP_ALL_OPTION_VALUES OptionValues
  370. );
  371. DWORD
  372. DhcpDumpServerOptionValue(IN LPCWSTR pwszServer,
  373. IN LPCWSTR pwszScope,
  374. IN LPCWSTR pwszReserved,
  375. IN LPCWSTR pwcUser,
  376. IN LPCWSTR pwcVendor,
  377. IN BOOL fIsV5,
  378. IN DHCP_OPTION_VALUE OptionValue);
  379. DWORD
  380. DhcpDumpReservedOptionValues(
  381. IN LPCWSTR pwszServer,
  382. IN DWORD dwMajor,
  383. IN DWORD dwMinor,
  384. IN LPCWSTR pwszScope,
  385. IN LPCWSTR pwszReservedIp
  386. );
  387. DWORD
  388. DhcpDumpScope(IN LPCWSTR pwszServerIp,
  389. IN DWORD dwMajor,
  390. IN DWORD dwMinor,
  391. IN DWORD ScopeIp);
  392. VOID
  393. DhcpDumpSuperScopes( IN LPCWSTR pwszServer,
  394. IN DWORD dwMajor,
  395. IN DWORD dwMinor );
  396. DWORD
  397. DhcpDumpServerMScope(IN LPCWSTR pwszServer,
  398. IN DWORD dwMajor,
  399. IN DWORD dwMinor,
  400. IN LPCWSTR pwszMScope
  401. );
  402. VOID
  403. DhcpDumpServerClassHeader();
  404. VOID
  405. DhcpDumpServerClassFooter();
  406. VOID
  407. DhcpDumpServerOptiondefHeader();
  408. VOID
  409. DhcpDumpServerOptiondefFooter();
  410. VOID
  411. DhcpDumpServerOptionvalueHeader();
  412. VOID
  413. DhcpDumpServerOptionvalueFooter();
  414. VOID
  415. DhcpDumpServerScopeHeader();
  416. VOID
  417. DhcpDumpServerScopeFooter();
  418. VOID
  419. DhcpDumpServerMScopeHeader();
  420. VOID
  421. DhcpDumpServerMScopeFooter();
  422. VOID
  423. DhcpDumpServerConfig(IN LPCWSTR pwszServer);
  424. VOID
  425. DhcpDumpScriptFooter();
  426. VOID
  427. DhcpDumpServerScriptFooter();
  428. NS_CONTEXT_DUMP_FN DhcpDump;
  429. BOOL
  430. IsPureNumeric(IN LPCWSTR pwszStr);
  431. LPWSTR
  432. MakeDayTimeString(
  433. IN DWORD dwTime
  434. );
  435. PHOSTENT
  436. UnicodeGetHostByName(
  437. IN PCWSTR name,
  438. IN OUT LPWSTR *FqdnName
  439. );
  440. #endif //_COMMON_H