Source code of Windows XP (NT5)
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.

249 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. tlookup.c
  5. Abstract:
  6. Test for a leak in LsaLookupName().
  7. nmake UMTYPE=console UMTEST=tlookup
  8. Author:
  9. Jim Kelly (JimK) Mar-31-1994
  10. Revision History:
  11. --*/
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // //
  14. // Includes //
  15. // //
  16. ///////////////////////////////////////////////////////////////////////////////
  17. #include <nt.h>
  18. #include <ntlsa.h>
  19. #include <ntrtl.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // //
  24. // Global Variables //
  25. // //
  26. ///////////////////////////////////////////////////////////////////////////////
  27. ULONG
  28. TLsapLoopLimit = 1000;
  29. /////////////////////////////////////////////////////////////////////////
  30. // //
  31. // Local routine definitions //
  32. // //
  33. /////////////////////////////////////////////////////////////////////////
  34. /////////////////////////////////////////////////////////////////////////
  35. // //
  36. // Routines //
  37. // //
  38. /////////////////////////////////////////////////////////////////////////
  39. VOID __cdecl
  40. main(argc, argv)
  41. int argc;
  42. char **argv;
  43. {
  44. NTSTATUS
  45. NtStatus,
  46. LookupSidStatus = STATUS_SUCCESS;
  47. ULONG
  48. i;
  49. LSA_HANDLE
  50. PolicyHandle;
  51. OBJECT_ATTRIBUTES
  52. ObjectAttributes;
  53. UNICODE_STRING
  54. NameBuffer,
  55. SystemName;
  56. PUNICODE_STRING
  57. Names;
  58. PLSA_REFERENCED_DOMAIN_LIST
  59. ReferencedDomains;
  60. PLSA_TRANSLATED_SID
  61. Sids;
  62. ULONG
  63. SidLength;
  64. PSID
  65. LookupSid;
  66. BOOLEAN
  67. DoSidTest;
  68. PLSA_TRANSLATED_NAME
  69. TranslatedNames;
  70. Names = &NameBuffer;
  71. RtlInitUnicodeString( &NameBuffer, L"jimk_dom2\\Jimk_d2_t1" );
  72. RtlInitUnicodeString( &SystemName, L"" );
  73. printf("\n\nLsaLookupName() and LsaLookupSid() test.\n"
  74. "This test is good to use when looking for leaks\n"
  75. "in the lookup paths.\n\n");
  76. //
  77. // open the policy object and then loop, looking up names.
  78. //
  79. InitializeObjectAttributes( &ObjectAttributes, NULL, 0L, NULL, NULL );
  80. NtStatus = LsaOpenPolicy(
  81. &SystemName,
  82. &ObjectAttributes,
  83. POLICY_EXECUTE,
  84. &PolicyHandle
  85. );
  86. if (NT_SUCCESS(NtStatus)) {
  87. //
  88. // Get a sid to lookup
  89. //
  90. ReferencedDomains = NULL;
  91. Sids = NULL;
  92. NtStatus = LsaLookupNames(
  93. PolicyHandle,
  94. 1, //Count
  95. Names,
  96. &ReferencedDomains,
  97. &Sids
  98. );
  99. if (NT_SUCCESS(NtStatus)) {
  100. //
  101. // Build a sid to use in the lookup
  102. // This is done by copying the ReferencedDomain sid,
  103. // then adding one more relative ID.
  104. //
  105. ASSERT(ReferencedDomains != NULL);
  106. ASSERT(Sids != NULL);
  107. SidLength =
  108. sizeof(ULONG) +
  109. RtlLengthSid( &ReferencedDomains->Domains[Sids[0].DomainIndex].Sid );
  110. LookupSid = RtlAllocateHeap( RtlProcessHeap(), 0, SidLength );
  111. ASSERT(LookupSid != NULL);
  112. RtlCopySid( SidLength,
  113. LookupSid,
  114. ReferencedDomains->Domains[Sids[0].DomainIndex].Sid );
  115. (*RtlSubAuthoritySid(
  116. LookupSid,
  117. (ULONG)(*RtlSubAuthorityCountSid(LookupSid))
  118. )) = Sids[0].RelativeId;
  119. (*RtlSubAuthorityCountSid(LookupSid)) += 1;
  120. DoSidTest = TRUE;
  121. } else {
  122. printf("ERROR: Couldn't get SID value to lookup.\n"
  123. " Won't perform SID lookup part of test.\n\n");
  124. DoSidTest = FALSE;
  125. }
  126. if (ReferencedDomains != NULL) {
  127. LsaFreeMemory( ReferencedDomains );
  128. }
  129. if (Sids != NULL) {
  130. LsaFreeMemory( Sids );
  131. }
  132. printf("\nLooping %d times...\n", TLsapLoopLimit);
  133. for (i=0; i<TLsapLoopLimit; i++) {
  134. printf("\r Loop Count %#4d LookupName Status: 0x%08lx LookupSid Status: 0x%08lx",
  135. i, NtStatus, LookupSidStatus);
  136. //
  137. // Lookup name
  138. //
  139. ReferencedDomains = NULL;
  140. Sids = NULL;
  141. NtStatus = LsaLookupNames(
  142. PolicyHandle,
  143. 1, //Count
  144. Names,
  145. &ReferencedDomains,
  146. &Sids
  147. );
  148. if (ReferencedDomains != NULL) {
  149. LsaFreeMemory( ReferencedDomains );
  150. }
  151. if (Sids != NULL) {
  152. LsaFreeMemory( Sids );
  153. }
  154. //
  155. // Lookup SID
  156. //
  157. if (DoSidTest) {
  158. ReferencedDomains = NULL;
  159. Sids = NULL;
  160. LookupSidStatus = LsaLookupSids(
  161. PolicyHandle,
  162. 1, //Count
  163. &LookupSid,
  164. &ReferencedDomains,
  165. &TranslatedNames
  166. );
  167. if (ReferencedDomains != NULL) {
  168. LsaFreeMemory( ReferencedDomains );
  169. }
  170. if (TranslatedNames != NULL) {
  171. LsaFreeMemory( TranslatedNames );
  172. }
  173. }
  174. }
  175. }
  176. return;
  177. }