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.

423 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. rdns.hxx
  5. Abstract:
  6. Reverse DNS service
  7. Author:
  8. Philippe Choquier (phillich) 5-june-1996
  9. --*/
  10. #if !defined(_RDNS_INCLUDE)
  11. #define _RDNS_INCLUDE
  12. #include "windef.h"
  13. //# include "string.hxx"
  14. typedef LPVOID DNSARG;
  15. typedef void (*DNSFUNC)( DNSARG, BOOL, LPSTR );
  16. #define RDNS_REQUEST_TYPE_IP2DNS 0
  17. #define RDNS_REQUEST_TYPE_DNS2IP 1
  18. #define SIZEOF_IP_ADDRESS 4
  19. /*
  20. typedef struct _DNSFUNCDESC
  21. {
  22. DWORD dwRequestType;
  23. DNSFUNC pFunc;
  24. } DNSFUNCDESC, *PDNSFUNCDESC;
  25. extern BOOL InitRDns();
  26. extern void TerminateRDns();
  27. BOOL
  28. AsyncHostByAddr(
  29. PDNSFUNCDESC pFunc, // will store DNS name, post dummy completion status
  30. // if NULL ( or g_cMaxThreadLimit==0 ) then sync request
  31. DNSARG pArg, // ptr to be passed to FUNC
  32. struct sockaddr *pHostAddr,
  33. BOOL *pfSync, // updated with TRUE if sync call
  34. LPSTR pName,
  35. DWORD dwMaxNameLen
  36. );
  37. BOOL
  38. AsyncAddrByHost(
  39. PDNSFUNCDESC pFunc, // will store DNS name, post dummy completion status
  40. // if NULL ( or g_cMaxThreadLimit==0 ) then sync request
  41. DNSARG pArg, // ptr to be passed to FUNC
  42. struct sockaddr *pHostAddr,
  43. BOOL *pfSync, // updated with TRUE if sync call
  44. LPSTR pName
  45. );
  46. BOOL
  47. FireUpNewThread(
  48. PDNSFUNCDESC pFunc,
  49. DNSARG pArg,
  50. LPVOID pOvr
  51. );
  52. #define XAR_GRAIN 256
  53. //
  54. // extensible array class
  55. //
  56. */
  57. class XAR {
  58. public:
  59. XAR() { m_fDidAlloc = FALSE; m_pAlloc = NULL; m_cAlloc = m_cUsed = 0; }
  60. ~XAR() { }
  61. //~XAR() { if ( m_fDidAlloc ) LocalFree( m_pAlloc ); }
  62. BOOL Init( LPBYTE p=NULL, DWORD c=0) { m_fDidAlloc = FALSE; m_pAlloc = p; m_cAlloc = m_cUsed = c; return TRUE; }
  63. VOID Terminate()
  64. {
  65. /* if ( m_fDidAlloc )
  66. {
  67. LocalFree( m_pAlloc );
  68. }*/
  69. m_fDidAlloc = FALSE;
  70. m_pAlloc = NULL;
  71. m_cAlloc = m_cUsed = 0;
  72. }
  73. BOOL Resize( DWORD dwDelta );
  74. DWORD GetUsed() { return m_cUsed; }
  75. VOID SetUsed( DWORD c ) { m_cUsed = c; }
  76. VOID AdjustUsed( int c ) { m_cUsed += (DWORD)c; }
  77. LPBYTE GetAlloc() { return m_pAlloc; }
  78. private:
  79. LPBYTE m_pAlloc;
  80. DWORD m_cAlloc;
  81. DWORD m_cUsed;
  82. BOOL m_fDidAlloc;
  83. } ;
  84. /*
  85. //
  86. // This type defines a relocatable index inside a dynamic array.
  87. // to allow easy fixups when part of the array is to be extended/shrinked
  88. // index are identified by setting bit 31 to 1. Other DWORD in the reference
  89. // part of the array are assumed to have bit 31 set to 0.
  90. // The size of the reference part of the array is defined by cRefSize
  91. //
  92. */
  93. typedef DWORD SELFREFINDEX;
  94. // combine array base address with SELFREFINDEX
  95. #define MAKEPTR(a,b) ((LPBYTE)(a)+((b)&0x7fffffff))
  96. // build a SELFREFINDEX from an offset in array
  97. #define MAKEREF(a) ((a)|0x80000000)
  98. // build an offset from a SELFREFINDEX
  99. #define MAKEOFFSET(a) ((a)&0x7fffffff)
  100. //
  101. // ADDRESS_CHECK_LIST Flags. bit31 must not be used.
  102. //
  103. #define RDNS_FLAG_DODNS2IPCHECK 0x00000001
  104. // uses non-standard extension : zero-sized array in struct
  105. #pragma warning(disable:4200)
  106. // array header
  107. typedef struct _ADDRESS_CHECK_LIST {
  108. SELFREFINDEX iDenyAddr; // address deny list
  109. // points to ADDRESS_HEADER
  110. SELFREFINDEX iGrantAddr; // address grant list
  111. // points to ADDRESS_HEADER
  112. SELFREFINDEX iDenyName; // DNS name deny list
  113. // points to NAME_HEADER
  114. SELFREFINDEX iGrantName; // DNS name grant list
  115. // points to NAME_HEADER
  116. DWORD dwFlags;
  117. DWORD cRefSize; // size of reference area ( in bytes )
  118. } ADDRESS_CHECK_LIST, *PADDRESS_CHECK_LIST;
  119. typedef struct _ADDRESS_LIST_ENTRY {
  120. DWORD iFamily;
  121. DWORD cAddresses;
  122. DWORD cFullBytes;
  123. DWORD LastByte;
  124. SELFREFINDEX iFirstAddress; // points to array of addresses
  125. // which size are derived from iFamily
  126. } ADDRESS_LIST_ENTRY, *PADDRESS_LIST_ENTRY;
  127. typedef struct _ADDRESS_HEADER {
  128. DWORD cEntries; // # of Entries[]
  129. DWORD cAddresses; // total # of addresses in all
  130. // ADDRESS_LIST_ENTRY
  131. ADDRESS_LIST_ENTRY Entries[];
  132. } ADDRESS_HEADER, *PADDRESS_HEADER ;
  133. typedef struct _NAME_LIST_ENTRY {
  134. DWORD cComponents; // # of DNS components
  135. DWORD cNames;
  136. SELFREFINDEX iName[]; // array of references to DNS names
  137. } NAME_LIST_ENTRY, *PNAME_LIST_ENTRY;
  138. typedef struct _NAME_HEADER {
  139. DWORD cEntries;
  140. DWORD cNames; // total # of names for all Entries[]
  141. //NAME_LIST_ENTRY Entries[0]; // array of name classes
  142. } NAME_HEADER, *PNAME_HEADER ;
  143. /*
  144. typedef struct ADDRCMPDESC {
  145. LPBYTE pMask;
  146. UINT cFullBytes;
  147. UINT LastByte;
  148. UINT cSizeAddress;
  149. } ADDRCMPDESC, *PADDRCMPDESC;
  150. typedef struct NAMECMPDESC {
  151. LPVOID pName;
  152. LPBYTE pBase;
  153. } NAMECMPDESC, *PNAMECMPDESC;
  154. typedef LPVOID ADDRCHECKARG;
  155. typedef void (*ADDRCHECKFUNC)(ADDRCHECKARG, BOOL );
  156. typedef void (*ADDRCHECKFUNCEX)(ADDRCHECKARG, BOOL, LPSTR );
  157. typedef int (__cdecl *CMPFUNC)(const void*, const void*, LPVOID);
  158. #define SIZE_FAST_REVERSE_DNS 128
  159. */
  160. enum AC_RESULT {
  161. AC_NOT_CHECKED,
  162. AC_IN_DENY_LIST,
  163. AC_NOT_IN_DENY_LIST, // deny list present but not in deny list
  164. AC_IN_GRANT_LIST,
  165. AC_NOT_IN_GRANT_LIST, // grant list present but not in grant list
  166. AC_NO_LIST
  167. } ;
  168. #define DNSLIST_FLAG_NOSUBDOMAIN 0x80000000
  169. #define DNSLIST_FLAGS 0x80000000 // bitmask of all flags
  170. class ADDRESS_CHECK {
  171. public:
  172. ADDRESS_CHECK() {}
  173. ~ADDRESS_CHECK() {}
  174. //
  175. BOOL BindCheckList( LPBYTE p = NULL, DWORD c = 0 );
  176. VOID UnbindCheckList() { m_Storage.Terminate(); }
  177. /* BOOL BindAddr( struct sockaddr* pAddr )
  178. {
  179. m_pAddr = pAddr;
  180. m_fDnsResolved = FALSE;
  181. m_fIpResolved = FALSE;
  182. m_dwErrorResolving = 0;
  183. m_strDnsName.Reset();
  184. return TRUE;
  185. }
  186. VOID UnbindAddr()
  187. {
  188. m_pAddr = NULL;
  189. m_strDnsName.Reset();
  190. m_fDnsResolved = FALSE;
  191. }
  192. XAR* GetStorage() { return &m_Storage; }
  193. AC_RESULT CheckAccess(
  194. LPBOOL pfSync,
  195. ADDRCHECKFUNC pFunc,
  196. ADDRCHECKARG pArg
  197. );
  198. //
  199. void AdjustRefs( LPBYTE, DWORD dwCut, DWORD dwAdj );
  200. */ //
  201. UINT GetAddrSize( DWORD );
  202. // VOID MakeAcd( PADDRCMPDESC pacd, LPBYTE pMask, UINT cLen );
  203. // for UI, addr
  204. // BOOL AddAddr( BOOL fGrant, DWORD dwFamily, LPBYTE pMask, LPBYTE pAddr );
  205. // BOOL DeleteAddr( BOOL fGrant, DWORD iIndex );
  206. BOOL GetAddr( BOOL fGrant, DWORD iIndex, LPDWORD pdwFamily, LPBYTE* pMask, LPBYTE* pAddr );
  207. DWORD GetNbAddr( BOOL fGrant );
  208. BOOL LocateAddr( BOOL fGrant, DWORD iIndex, PADDRESS_HEADER* ppHd, PADDRESS_LIST_ENTRY* pHeader, LPDWORD iIndexInHeader );
  209. // BOOL DeleteAllAddr( BOOL fGrant );
  210. // BOOL SetFlag( DWORD dwFlag, BOOL fEnable );
  211. // DWORD GetFlags();
  212. // test all mask for this family, do bsearch on each
  213. // BOOL IsMatchAddr( BOOL fGrant, DWORD dwFamily, LPBYTE pAddr );
  214. /* AC_RESULT CheckAddress(
  215. struct sockaddr* pAddr
  216. );
  217. BOOL QueryDnsName(
  218. LPBOOL pfSync,
  219. ADDRCHECKFUNCEX pFunc,
  220. ADDRCHECKARG pArg,
  221. LPSTR * ppName
  222. );
  223. AC_RESULT CheckIpAccess( LPBOOL pfNeedDns);
  224. AC_RESULT CheckDnsAccess()
  225. { return CheckName( m_strDnsName.QueryStr() ); }
  226. BOOL IsDnsResolved()
  227. { return m_fDnsResolved; }
  228. LPSTR QueryResolvedDnsName()
  229. { return m_strDnsName.QueryStr(); }
  230. DWORD QueryErrorResolving()
  231. { return m_dwErrorResolving; }
  232. */
  233. // for UI, name
  234. // BOOL AddName( BOOL fGrant, LPSTR pName, DWORD dwFlags = 0 );
  235. // BOOL AddReversedName( BOOL fGrant, LPSTR pName );
  236. // BOOL DeleteName( BOOL fGrant, DWORD iIndex );
  237. BOOL GetName( BOOL fGrant, DWORD iIndex, LPSTR* ppName, LPDWORD pdwFlags = NULL );
  238. // BOOL GetReversedName( BOOL fGrant, DWORD iIndex, LPSTR pName, LPDWORD pdwSize );
  239. DWORD GetNbName( BOOL fGrant );
  240. BOOL LocateName( BOOL fGrant, DWORD iIndex, PNAME_HEADER* ppHd, PNAME_LIST_ENTRY* pHeader, LPDWORD iIndexInHeader );
  241. // BOOL DeleteAllName( BOOL fGrant );
  242. // DWORD QueryCheckListSize() { return m_Storage.GetUsed(); }
  243. // LPBYTE QueryCheckListPtr() { return m_Storage.GetAlloc(); }
  244. //UINT GetNbComponent( LPSTR pName );
  245. // test all classes, do bsearch on each
  246. /* BOOL IsMatchName( BOOL fGrant, LPSTR pName );
  247. BOOL CheckReversedName( LPSTR pName ); // synchronous version
  248. AC_RESULT CheckName( LPSTR pName ); // synchronous version
  249. LPSTR InitReverse( LPSTR pR, LPSTR pTarget, LPBOOL pfAlloc );
  250. VOID TerminateReverse( LPSTR, BOOL );
  251. VOID AddrCheckDnsCallBack(
  252. BOOL fSt,
  253. LPSTR pDns
  254. );
  255. VOID AddrCheckDnsCallBack2(
  256. BOOL fSt,
  257. struct sockaddr* pAddr
  258. );
  259. VOID AddrCheckDnsCallBack3(
  260. BOOL fSt,
  261. struct sockaddr* pAddr
  262. );
  263. VOID ResolveDnsCallBack(
  264. BOOL fSt,
  265. LPSTR pDns
  266. );
  267. #if DBG
  268. VOID DumpAddrAndName( VOID );
  269. VOID DumpAddr( BOOL );
  270. VOID DumpName( BOOL );
  271. #endif
  272. */
  273. private:
  274. XAR m_Storage;
  275. // struct sockaddr * m_pAddr;
  276. // struct sockaddr m_ResolvedAddr;
  277. // STR m_strDnsName;
  278. BOOL m_fDnsResolved;
  279. BOOL m_fIpResolved;
  280. DWORD m_dwErrorResolving;
  281. // ADDRCHECKFUNC m_HttpReqCallback;
  282. // ADDRCHECKFUNCEX m_HttpReqCallbackEx;
  283. //ADDRCHECKARG m_HttpReqParam;
  284. } ;
  285. /*
  286. typedef struct _SID_CACHE_ENTRY
  287. {
  288. DWORD tExpire; // now + TTL
  289. DWORD dwSidLen;
  290. BYTE Sid[0];
  291. } SID_CACHE_ENTRY, *PSID_CACHE_ENTRY;
  292. class CSidCache
  293. {
  294. public:
  295. CSidCache() {}
  296. ~CSidCache() {}
  297. //
  298. BOOL Init();
  299. VOID Terminate();
  300. //
  301. BOOL AddToCache( PSID, DWORD dwTTL ); // TTL in seconds
  302. BOOL IsInCache( PSID );
  303. BOOL CheckPresentAndResetTtl( PSID, DWORD );
  304. //
  305. BOOL Scavenger();
  306. private:
  307. XAR xaStore; // buffer of SID_CACHE_ENTRY
  308. CRITICAL_SECTION csLock;
  309. } ;
  310. //
  311. // PEN : Password Expiration Notification API
  312. //
  313. extern CSidCache g_scPen;
  314. BOOL PenAddToCache( PSID, DWORD );
  315. BOOL PenIsInCache( PSID );
  316. BOOL PenCheckPresentAndResetTtl( PSID, DWORD );
  317. #define PenInit g_scPen.Init
  318. #define PenTerminate g_scPen.Terminate
  319. #define PenScavenger g_scPen.Scavenger
  320. #define PEN_TTL (10*60) // in seconds
  321. #if DBG
  322. extern VOID TestAPI();
  323. #endif
  324. #if defined(_RDNS_STANDALONE)
  325. typedef
  326. VOID
  327. (* PFN_SCHED_CALLBACK)(
  328. VOID * pContext
  329. );
  330. DWORD
  331. ScheduleWorkItem(
  332. PFN_SCHED_CALLBACK pfnCallback,
  333. PVOID pContext,
  334. DWORD msecTimeInterval,
  335. BOOL fPeriodic = FALSE
  336. )
  337. {
  338. return 0;
  339. }
  340. BOOL
  341. RemoveWorkItem(
  342. DWORD pdwCookie
  343. )
  344. {
  345. return FALSE;
  346. }
  347. #endif
  348. */
  349. #endif