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.

373 lines
8.0 KiB

  1. #include "uiutils.h"
  2. BOOL
  3. ADDRESS_CHECK::LocateName(
  4. BOOL fGrant,
  5. DWORD iIndex,
  6. PNAME_HEADER* ppHd,
  7. PNAME_LIST_ENTRY* pHeader,
  8. LPDWORD piIndexInHeader
  9. )
  10. /*++
  11. Routine Description:
  12. Locate a name in the specified list, returns ptr
  13. to header & element in address list
  14. Arguments:
  15. fGrant - TRUE to locate in grant list, FALSE for deny list
  16. iIndex - index in list ( 0-based )
  17. ppHd - updated with ptr to name header
  18. pHeader - updated with ptr to name list entry
  19. piIndexInHeader - updated with index in array pHeader->iName
  20. Return Value:
  21. TRUE if iIndex valid in array defined by fGrant, FALSE otherwise
  22. --*/
  23. {
  24. LPBYTE pStore = m_Storage.GetAlloc();
  25. PADDRESS_CHECK_LIST pList;
  26. PNAME_HEADER pHd;
  27. PNAME_LIST_ENTRY pE;
  28. UINT iL;
  29. if ( pStore )
  30. {
  31. pList = (PADDRESS_CHECK_LIST)pStore;
  32. *ppHd = pHd = (PNAME_HEADER)MAKEPTR( pStore, fGrant ? pList->iGrantName : pList->iDenyName);
  33. pE = (PNAME_LIST_ENTRY)((LPBYTE)pHd + sizeof(NAME_HEADER));
  34. for ( iL = 0 ; iL < pHd->cEntries ; ++iL )
  35. {
  36. if ( iIndex < pE->cNames )
  37. {
  38. *pHeader = pE;
  39. *piIndexInHeader = iIndex;
  40. return TRUE;
  41. }
  42. iIndex -= pE->cNames;
  43. pE = (PNAME_LIST_ENTRY)((LPBYTE)pE + sizeof(NAME_LIST_ENTRY) + pE->cNames * sizeof(SELFREFINDEX));
  44. }
  45. }
  46. return FALSE;
  47. }
  48. //inline
  49. DWORD
  50. ADDRESS_CHECK::GetNbAddr(
  51. BOOL fGrant
  52. )
  53. /*++
  54. Routine Description:
  55. Get number of entries in list
  56. Arguments:
  57. fGrant - TRUE to locate in grant list, FALSE for deny list
  58. Return Value:
  59. Number of entries in list
  60. --*/
  61. {
  62. LPBYTE pStore = m_Storage.GetAlloc();
  63. PADDRESS_CHECK_LIST pList;
  64. PADDRESS_HEADER pHd;
  65. if ( pStore )
  66. {
  67. pList = (PADDRESS_CHECK_LIST)pStore;
  68. pHd = (PADDRESS_HEADER)MAKEPTR( pStore, fGrant ? pList->iGrantAddr : pList->iDenyAddr);
  69. return pHd->cAddresses;
  70. }
  71. return 0;
  72. }
  73. BOOL
  74. ADDRESS_CHECK::BindCheckList(
  75. LPBYTE p,
  76. DWORD c
  77. )
  78. /*++
  79. Routine Description:
  80. Bind a check list ( presented as a BLOB ) to an
  81. ADDRESS_CHECK object
  82. Arguments:
  83. p - ptr to BLOB
  84. c - size of BLOB
  85. Return Value:
  86. TRUE if successful, FALSE otherwise
  87. --*/
  88. {
  89. PADDRESS_CHECK_LIST pList;
  90. UINT l;
  91. /* if ( p == NULL )
  92. {
  93. if ( m_Storage.Init() && m_Storage.Resize( sizeof(ADDRESS_CHECK_LIST)
  94. + sizeof(ADDRESS_HEADER) * 2
  95. + sizeof(NAME_HEADER) * 2 ) )
  96. {
  97. DWORD i;
  98. pList = (PADDRESS_CHECK_LIST)m_Storage.GetAlloc();
  99. pList->iDenyAddr = i = MAKEREF( sizeof(ADDRESS_CHECK_LIST) );
  100. i += sizeof(ADDRESS_HEADER);
  101. pList->iGrantAddr = i;
  102. i += sizeof(ADDRESS_HEADER);
  103. pList->iDenyName = i;
  104. i += sizeof(NAME_HEADER);
  105. pList->iGrantName = i;
  106. i += sizeof(NAME_HEADER);
  107. pList->cRefSize = MAKEOFFSET(i);
  108. pList->dwFlags = RDNS_FLAG_DODNS2IPCHECK;
  109. return TRUE;
  110. }
  111. else
  112. {
  113. return FALSE;
  114. }
  115. }
  116. else
  117. */ {
  118. return m_Storage.Init( p, c );
  119. }
  120. }
  121. BOOL
  122. ADDRESS_CHECK::GetAddr(
  123. BOOL fGrant,
  124. DWORD iIndex,
  125. LPDWORD pdwFamily,
  126. LPBYTE* pMask,
  127. LPBYTE* pAddr
  128. )
  129. /*++
  130. Routine Description:
  131. Get an address entry
  132. Arguments:
  133. fGrant - TRUE to locate in grant list, FALSE for deny list
  134. iIndex - index in list (0-based )
  135. pdwFamily - updated with address family ( as in sockaddr.sa_type )
  136. pMask - updated with ptr to mask
  137. pAddr - updated with ptr to address
  138. Return Value:
  139. TRUE if iIndex valid in array defined by fGrant, FALSE otherwise
  140. --*/
  141. {
  142. PADDRESS_LIST_ENTRY pHeader;
  143. PADDRESS_HEADER pHd;
  144. DWORD iIndexInHeader;
  145. LPBYTE pStore = m_Storage.GetAlloc();
  146. if ( LocateAddr( fGrant, iIndex, &pHd, &pHeader, &iIndexInHeader ) )
  147. {
  148. UINT cS = GetAddrSize( pHeader->iFamily );
  149. *pdwFamily = pHeader->iFamily;
  150. pStore = MAKEPTR(pStore, pHeader->iFirstAddress);
  151. *pMask = pStore;
  152. *pAddr = pStore+iIndexInHeader*cS;
  153. return TRUE;
  154. }
  155. return FALSE;
  156. }
  157. BOOL
  158. ADDRESS_CHECK::GetName(
  159. BOOL fGrant,
  160. DWORD iIndex,
  161. LPSTR* ppName,
  162. LPDWORD pdwFlags
  163. )
  164. /*++
  165. Routine Description:
  166. Get DNS name in specified list
  167. Arguments:
  168. fGrant - TRUE to locate in grant list, FALSE for deny list
  169. iIndex - index (0-based) in specified list
  170. ppName - updated with ptr to DNS name
  171. pdwFlags - updated with DNS flags, can be NULL
  172. Return Value:
  173. TRUE if iIndex valid in specified list, otherwise FALSE
  174. --*/
  175. {
  176. PNAME_LIST_ENTRY pHeader;
  177. PNAME_HEADER pHd;
  178. DWORD iIndexInHeader;
  179. LPBYTE pStore = m_Storage.GetAlloc();
  180. if ( LocateName( fGrant, iIndex, &pHd, &pHeader, &iIndexInHeader ) )
  181. {
  182. *ppName = (LPSTR)MAKEPTR(pStore, pHeader->iName[iIndexInHeader] );
  183. if ( pdwFlags )
  184. {
  185. *pdwFlags = pHeader->cComponents & DNSLIST_FLAGS;
  186. }
  187. return TRUE;
  188. }
  189. return FALSE;
  190. }
  191. DWORD
  192. ADDRESS_CHECK::GetNbName(
  193. BOOL fGrant
  194. )
  195. /*++
  196. Routine Description:
  197. Get number of entries in list
  198. Arguments:
  199. fGrant - TRUE to locate in grant list, FALSE for deny list
  200. Return Value:
  201. Number of entries in list
  202. --*/
  203. {
  204. LPBYTE pStore = m_Storage.GetAlloc();
  205. PADDRESS_CHECK_LIST pList;
  206. PNAME_HEADER pHd;
  207. if ( pStore )
  208. {
  209. pList = (PADDRESS_CHECK_LIST)pStore;
  210. pHd = (PNAME_HEADER)MAKEPTR( pStore, fGrant ? pList->iGrantName : pList->iDenyName);
  211. return pHd->cNames;
  212. }
  213. return 0;
  214. }
  215. UINT
  216. ADDRESS_CHECK::GetAddrSize(
  217. DWORD dwF
  218. )
  219. /*++
  220. Routine Description:
  221. Returns address size in byte based on family ( sockaddr.sa_type )
  222. Arguments:
  223. dwF - address family ( as in sockaddr.sa_type )
  224. Return Value:
  225. Address length, in byte. 0 for unknown address families
  226. --*/
  227. {
  228. DWORD dwS;
  229. // switch ( dwF )
  230. // {
  231. // case AF_INET:
  232. dwS = SIZEOF_IP_ADDRESS;
  233. // break;
  234. // default:
  235. // dwS = 0;
  236. // break;
  237. // }
  238. return dwS;
  239. }
  240. BOOL
  241. ADDRESS_CHECK::LocateAddr(
  242. BOOL fGrant,
  243. DWORD iIndex,
  244. PADDRESS_HEADER* ppHd,
  245. PADDRESS_LIST_ENTRY* pHeader,
  246. LPDWORD piIndexInHeader
  247. )
  248. /*++
  249. Routine Description:
  250. Locate an address in the specified list, returns ptr
  251. to header & element in address list
  252. Arguments:
  253. fGrant - TRUE to locate in grant list, FALSE for deny list
  254. iIndex - index in list (0-based )
  255. ppHd - updated with ptr to address header
  256. pHeader - updated with ptr to address list entry
  257. piIndexInHeader - updated with index in array addressed by
  258. pHeader->iFirstAddress
  259. Return Value:
  260. TRUE if iIndex valid in array defined by fGrant, FALSE otherwise
  261. --*/
  262. {
  263. LPBYTE pStore = m_Storage.GetAlloc();
  264. PADDRESS_CHECK_LIST pList;
  265. PADDRESS_HEADER pHd;
  266. UINT iL;
  267. if ( pStore )
  268. {
  269. pList = (PADDRESS_CHECK_LIST)pStore;
  270. *ppHd = pHd = (PADDRESS_HEADER)MAKEPTR( pStore, fGrant ? pList->iGrantAddr : pList->iDenyAddr);
  271. for ( iL = 0 ; iL < pHd->cEntries ; ++iL )
  272. {
  273. // adjust index by 1: 1st entry is mask
  274. if ( iIndex < (pHd->Entries[iL].cAddresses-1) )
  275. {
  276. *pHeader = pHd->Entries+iL;
  277. *piIndexInHeader = iIndex+1;
  278. return TRUE;
  279. }
  280. iIndex -= (pHd->Entries[iL].cAddresses-1);
  281. }
  282. }
  283. return FALSE;
  284. }