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.

490 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. CGroupP.h
  5. Abstract:
  6. The private definitions of config group module.
  7. Author:
  8. Paul McDaniel (paulmcd) 11-Jan-1999
  9. Revision History:
  10. --*/
  11. #ifndef _CGROUPP_H_
  12. #define _CGROUPP_H_
  13. //
  14. // The tree.
  15. //
  16. // This is used to do all url prefix matching to decide what app pool
  17. // a url lives in, along with other config group information.
  18. //
  19. // it's a sorted tree made up of 2 data structures: HEADER + ENTRY.
  20. //
  21. // a header is an array of ENTRY pointers that represent siblings
  22. // at a level in the tree. This is sorted by ENTRY::TokenLength. the
  23. // pointers are seperately allocated, and not embedded in the HEADER
  24. // memory.
  25. //
  26. // ENTRY represents a node in the tree. there are 2 types of ENTRY's.
  27. // FullUrl ENTRY's and "dummy" entries. Dummy ENTRY's exist simple as
  28. // place holders. they have children that are FullUrl ENTRY's. they
  29. // are auto-deleted when they are no longer needed.
  30. //
  31. // each ENTRY stores in it the part of the url it is responsible for.
  32. // this is pToken. For all non-site entries this is the string without
  33. // the preceding '/' or the trailing '/'. for top level site ENTRY's
  34. // it is everything up the, and not including, the 3rd '/'.
  35. // e.g. "http://www.microsoft.com:80". These top level sites also
  36. // have NULL ENTRY::pParent.
  37. //
  38. // a tree with these url's in it:
  39. //
  40. // http://www.microsoft.com:80/
  41. // http://www.microsoft.com:80/app1
  42. // http://www.microsoft.com:80/app1/app2
  43. // http://www.microsoft.com:80/dir1/dir2/app3
  44. //
  45. // http://www.msnbc.com:80/dir1/dir2/app1
  46. //
  47. // looks like this:
  48. //
  49. // +-------------------------------------------------------------+
  50. // | +---------------------------+ +-----------------------+ |
  51. // | |http://www.microsoft.com:80| |http://www.msnbc.com:80| |
  52. // | +---------------------------+ +-----------------------+ |
  53. // +-------------------------------------------------------------+
  54. // | |
  55. // +-------------------+ +----------+
  56. // | +----+ +----+ | | +----+ |
  57. // | |app1| |dir1| | | |dir1| |
  58. // | +----+ +----+ | | +----+ |
  59. // +-------------------+ +----------+
  60. // | | |
  61. // +--------+ +--------+ +----------+
  62. // | +----+ | | +----+ | | +----+ |
  63. // | |app2| | | |dir2| | | |dir2| |
  64. // | +----+ | | +----+ | | +----+ |
  65. // +--------+ +--------+ +----------+
  66. // | |
  67. // +--------+ +----------+
  68. // | +----+ | | +----+ |
  69. // | |app3| | | |app3| |
  70. // | +----+ | | +----+ |
  71. // +--------+ +----------+
  72. //
  73. // and this:
  74. //
  75. // g_pSites->UsedCount == 2;
  76. // g_pSites->ppEntries[0] == 0x10;
  77. // g_pSites->ppEntries[1] == 0x20;
  78. //
  79. // 0x10->pParent == NULL;
  80. // 0x10->pChildren == 0x100;
  81. // 0x10->TokenLength == 0x0036;
  82. // 0x10->FullUrl == 1;
  83. // 0x10->pToken == L"http://www.microsoft.com:80"
  84. //
  85. // 0x100->UsedCount == 2;
  86. // 0x100->ppEntries[0] == 0x110;
  87. // 0x100->ppEntries[1] == 0x300;
  88. //
  89. // 0x110->pParent == 0x10;
  90. // 0x110->pChildren == 0x200;
  91. // 0x110->TokenLength == 0x0008;
  92. // 0x110->FullUrl == 1;
  93. // 0x110->pToken == L"app1"
  94. //
  95. // 0x200->UsedCount == 1;
  96. // 0x200->ppEntries[0] == 0x210;
  97. //
  98. // 0x210->pParent == 0x110;
  99. // 0x210->pChildren == NULL;
  100. // 0x210->TokenLength == 0x0008;
  101. // 0x210->FullUrl == 1;
  102. // 0x210->pToken == L"app2"
  103. //
  104. // 0x300->pParent == 0x10;
  105. // 0x300->pChildren == 0x400;
  106. // 0x300->TokenLength == 0x0008;
  107. // 0x300->FullUrl == 0;
  108. // 0x300->pToken == L"dir1"
  109. //
  110. // 0x400->UsedCount == 1;
  111. // 0x400->ppEntries[0] == 0x410;
  112. //
  113. // 0x410->pParent == 0x300;
  114. // 0x410->pChildren == 0x500;
  115. // 0x410->TokenLength == 0x0008;
  116. // 0x410->FullUrl == 0;
  117. // 0x410->pToken == L"dir2"
  118. //
  119. // 0x500->UsedCount == 1;
  120. // 0x500->ppEntries[0] == 0x510;
  121. //
  122. // 0x510->pParent == 0x300;
  123. // 0x510->pChildren == NULL;
  124. // 0x510->TokenLength == 0x0008;
  125. // 0x510->FullUrl == 1;
  126. // 0x510->pToken == L"app3"
  127. //
  128. // 0x20->pParent == NULL;
  129. // 0x20->pChildren == 0x600;
  130. // 0x20->TokenLength == 0x002E;
  131. // 0x20->FullUrl == 0;
  132. // 0x20->pToken == L"http://www.msnbc.com:80"
  133. //
  134. // 0x600->pParent == 0x20;
  135. // 0x600->pChildren == 0x700;
  136. // 0x600->TokenLength == 0x0008;
  137. // 0x600->FullUrl == 0;
  138. // 0x600->pToken == L"dir1"
  139. //
  140. // 0x700->UsedCount == 1;
  141. // 0x700->ppEntries[0] == 0x710;
  142. //
  143. // 0x710->pParent == 0x600;
  144. // 0x710->pChildren == 0x800;
  145. // 0x710->TokenLength == 0x0008;
  146. // 0x710->FullUrl == 0;
  147. // 0x710->pToken == L"dir2"
  148. //
  149. // 0x800->UsedCount == 1;
  150. // 0x800->ppEntries[0] == 0x810;
  151. //
  152. // 0x810->pParent == 0x710;
  153. // 0x810->pChildren == NULL;
  154. // 0x810->TokenLength == 0x0008;
  155. // 0x810->FullUrl == 1;
  156. // 0x810->pToken == L"app1"
  157. //
  158. //
  159. typedef struct _UL_DEFERRED_REMOVE_ITEM
  160. UL_DEFERRED_REMOVE_ITEM, *PUL_DEFERRED_REMOVE_ITEM;
  161. typedef struct _UL_CG_URL_TREE_HEADER
  162. UL_CG_URL_TREE_HEADER, * PUL_CG_URL_TREE_HEADER;
  163. typedef struct _UL_CG_URL_TREE_ENTRY
  164. UL_CG_URL_TREE_ENTRY, * PUL_CG_URL_TREE_ENTRY;
  165. #define IS_VALID_TREE_ENTRY(pObject) \
  166. HAS_VALID_SIGNATURE(pObject, UL_CG_TREE_ENTRY_POOL_TAG)
  167. typedef struct _UL_CG_URL_TREE_ENTRY
  168. {
  169. //
  170. // PagedPool
  171. //
  172. //
  173. // base properties for dummy nodes
  174. //
  175. ULONG Signature; // UL_CG_TREE_ENTRY_POOL_TAG
  176. PUL_CG_URL_TREE_ENTRY pParent; // points to the parent entry
  177. PUL_CG_URL_TREE_HEADER pChildren; // points to the child header
  178. ULONG TokenLength; // byte count of pToken
  179. BOOLEAN Reservation; // a reservation ?
  180. BOOLEAN Registration; // a registration ?
  181. // Formally known as FullUrl.
  182. //
  183. // if the site has been successfully added to the endpoint list
  184. //
  185. BOOLEAN SiteAddedToEndpoint;
  186. PUL_DEFERRED_REMOVE_ITEM pRemoveSiteWorkItem;
  187. //
  188. // type of entry (name, ip or wildcard)
  189. //
  190. HTTP_URL_SITE_TYPE UrlType;
  191. //
  192. // extended properties for full nodes
  193. //
  194. HTTP_URL_CONTEXT UrlContext; // context for this url
  195. PUL_CONFIG_GROUP_OBJECT pConfigGroup; // the cfg group for the url
  196. LIST_ENTRY ConfigGroupListEntry; // links into pConfigGroup
  197. //
  198. // security descriptor (for reservations)
  199. //
  200. PSECURITY_DESCRIPTOR pSecurityDescriptor;
  201. LIST_ENTRY ReservationListEntry;
  202. //
  203. // the token string follows the struct header
  204. //
  205. WCHAR pToken[0];
  206. } UL_CG_URL_TREE_ENTRY, * PUL_CG_URL_TREE_ENTRY;
  207. //
  208. // this allows us to duplicate the hash value of the entry
  209. // inline with the header. this makes the search faster as
  210. // the hash value is in the cache line and no pointer deref
  211. // is necessary.
  212. //
  213. typedef struct _UL_CG_HEADER_ENTRY
  214. {
  215. PUL_CG_URL_TREE_ENTRY pEntry;
  216. } UL_CG_HEADER_ENTRY, *PUL_CG_HEADER_ENTRY;
  217. #define IS_VALID_TREE_HEADER(pObject) \
  218. HAS_VALID_SIGNATURE(pObject, UL_CG_TREE_HEADER_POOL_TAG)
  219. typedef struct _UL_CG_URL_TREE_HEADER
  220. {
  221. //
  222. // PagedPool
  223. //
  224. ULONG Signature; // UL_CG_TREE_HEADER_POOL_TAG
  225. ULONG AllocCount; // the count of allocated space
  226. ULONG UsedCount; // how many entries are used
  227. LONG NameSiteCount; // how many sites are name based
  228. LONG IPSiteCount; // how many sites are IPv4 or IPV6 based
  229. LONG StrongWildcardCount;// how many sites are strong wildcards
  230. LONG WeakWildcardCount; // how many sites are weak wildcards
  231. LONG NameIPSiteCount; // how many sites are name based and IP Bound
  232. UL_CG_HEADER_ENTRY pEntries[0]; // the entries
  233. } UL_CG_URL_TREE_HEADER, * PUL_CG_URL_TREE_HEADER;
  234. //
  235. // default settings, CODEWORK move these to the registry ?
  236. //
  237. #define UL_CG_DEFAULT_TREE_WIDTH 10 // used to initially allocate sibling
  238. // arrays + the global site array
  239. //
  240. //
  241. // Global list of reservations.
  242. //
  243. extern LIST_ENTRY g_ReservationListHead;
  244. //
  245. // Private macros
  246. //
  247. #define IS_CG_LOCK_OWNED_WRITE() \
  248. (UlDbgResourceOwnedExclusive(&g_pUlNonpagedData->ConfigGroupResource))
  249. //
  250. // Find node criteria.
  251. //
  252. #define FNC_DONT_CARE 0
  253. #define FNC_LONGEST_RESERVATION 1
  254. #define FNC_LONGEST_REGISTRATION 2
  255. #define FNC_LONGEST_EITHER (FNC_LONGEST_RESERVATION \
  256. | FNC_LONGEST_REGISTRATION)
  257. //
  258. // Internal helper functions used in the module
  259. //
  260. //
  261. // misc helpers
  262. //
  263. NTSTATUS
  264. UlpCreateConfigGroupObject(
  265. OUT PUL_CONFIG_GROUP_OBJECT * ppObject
  266. );
  267. NTSTATUS
  268. UlpCleanAllUrls(
  269. IN PUL_CONFIG_GROUP_OBJECT pObject
  270. );
  271. VOID
  272. UlpDeferredRemoveSite(
  273. IN PUL_CG_URL_TREE_ENTRY pEntry
  274. );
  275. VOID
  276. UlpDeferredRemoveSiteWorker(
  277. IN PUL_WORK_ITEM pWorkItem
  278. );
  279. NTSTATUS
  280. UlpExtractSchemeHostPortIp(
  281. IN PWSTR pUrl,
  282. OUT PULONG pCharCount
  283. );
  284. //
  285. // tree helpers
  286. //
  287. NTSTATUS
  288. UlpTreeFindNodeHelper(
  289. IN PUL_CG_URL_TREE_ENTRY pSiteEntry,
  290. IN PWSTR pNextToken,
  291. IN ULONG Criteria OPTIONAL,
  292. OUT PUL_CG_URL_TREE_ENTRY * ppMatchEntry OPTIONAL,
  293. OUT PUL_CG_URL_TREE_ENTRY * ppExactEntry
  294. );
  295. NTSTATUS
  296. UlpTreeFindNodeWalker(
  297. IN PUL_CG_URL_TREE_ENTRY pEntry,
  298. IN PWSTR pNextToken,
  299. IN OUT PUL_URL_CONFIG_GROUP_INFO pInfo OPTIONAL,
  300. OUT PUL_CG_URL_TREE_ENTRY * ppEntry OPTIONAL
  301. );
  302. NTSTATUS
  303. UlpTreeFindNode(
  304. IN PWSTR pUrl,
  305. IN PUL_INTERNAL_REQUEST pRequest OPTIONAL,
  306. OUT PUL_URL_CONFIG_GROUP_INFO pInfo OPTIONAL,
  307. OUT PUL_CG_URL_TREE_ENTRY * ppEntry OPTIONAL
  308. );
  309. NTSTATUS
  310. UlpTreeFindReservationNode(
  311. IN PWSTR pUrl,
  312. IN PUL_CG_URL_TREE_ENTRY * ppEntry
  313. );
  314. NTSTATUS
  315. UlpTreeFindRegistrationNode(
  316. IN PWSTR pUrl,
  317. IN PUL_CG_URL_TREE_ENTRY * ppEntry
  318. );
  319. NTSTATUS
  320. UlpTreeFindWildcardSite(
  321. IN PWSTR pUrl,
  322. IN BOOLEAN StrongWildcard,
  323. OUT PWSTR * ppNextToken,
  324. OUT PUL_CG_URL_TREE_ENTRY * ppEntry
  325. );
  326. NTSTATUS
  327. UlpTreeFindSite(
  328. IN PWSTR pUrl,
  329. OUT PWSTR * ppNextToken,
  330. OUT PUL_CG_URL_TREE_ENTRY * ppEntry
  331. );
  332. NTSTATUS
  333. UlpTreeFindSiteIpMatch(
  334. IN PUL_INTERNAL_REQUEST pRequest,
  335. OUT PUL_CG_URL_TREE_ENTRY * ppEntry
  336. );
  337. NTSTATUS
  338. UlpTreeBinaryFindEntry(
  339. IN PUL_CG_URL_TREE_HEADER pHeader OPTIONAL,
  340. IN PWSTR pToken,
  341. IN ULONG TokenLength,
  342. OUT PULONG pIndex
  343. );
  344. NTSTATUS
  345. UlpTreeCreateSite(
  346. IN PWSTR pUrl,
  347. IN HTTP_URL_SITE_TYPE UrlType,
  348. OUT PWSTR * ppNextToken,
  349. OUT PUL_CG_URL_TREE_ENTRY* ppSiteEntry
  350. );
  351. NTSTATUS
  352. UlpTreeFreeNode(
  353. IN PUL_CG_URL_TREE_ENTRY pEntry
  354. );
  355. NTSTATUS
  356. UlpTreeDeleteRegistration(
  357. IN PUL_CG_URL_TREE_ENTRY pEntry
  358. );
  359. NTSTATUS
  360. UlpTreeDeleteReservation(
  361. IN PUL_CG_URL_TREE_ENTRY pEntry
  362. );
  363. NTSTATUS
  364. UlpTreeInsert(
  365. IN PWSTR pUrl,
  366. IN HTTP_URL_SITE_TYPE UrlType,
  367. IN PWSTR pNextToken,
  368. IN PUL_CG_URL_TREE_ENTRY pEntry,
  369. OUT PUL_CG_URL_TREE_ENTRY * ppEntry
  370. );
  371. NTSTATUS
  372. UlpTreeInsertEntry(
  373. IN OUT PUL_CG_URL_TREE_HEADER * ppHeader,
  374. IN PUL_CG_URL_TREE_ENTRY pParent OPTIONAL,
  375. IN HTTP_URL_SITE_TYPE UrlType,
  376. IN PWSTR pToken,
  377. IN ULONG TokenLength,
  378. IN ULONG Index
  379. );
  380. //
  381. // url info helpers
  382. //
  383. NTSTATUS
  384. UlpSetUrlInfo(
  385. IN OUT PUL_URL_CONFIG_GROUP_INFO pInfo,
  386. IN PUL_CG_URL_TREE_ENTRY pMatchEntry
  387. );
  388. NTSTATUS
  389. UlpSetUrlInfoSpecial(
  390. IN OUT PUL_URL_CONFIG_GROUP_INFO pInfo,
  391. IN PUL_CG_URL_TREE_ENTRY pMatchEntry
  392. );
  393. VOID
  394. UlCGLockWriteSyncRemoveSite(
  395. VOID
  396. );
  397. #endif // _CGROUPP_H_