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.

213 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ctsamdb.c
  5. Abstract:
  6. CT for loading a SAM Accounts Database
  7. This test creates a number of users in the local SAM Database
  8. To build this test:
  9. cd \nt\private\lsa\uclient
  10. nmake UMTYPE=console UMTEST=ctsamdb
  11. To run this test:
  12. 1. Build lsasrv.dll with LSA_SAM_ACCOUNTS_DOMAIN_TEST flag
  13. enabled in file \nt\private\lsa\server\dbp.h
  14. 2. On your test system, replace lsasrv.dll in \nt\system32 and reboot.
  15. 3. Type ctsamdb n to load SAM Database with n users
  16. 4. Type ctsamdb -1 to delete the users you created.
  17. Author:
  18. Scott Birrell (ScottBi) October 19, 1992
  19. Environment:
  20. Revision History:
  21. --*/
  22. #include "lsaclip.h"
  23. /////////////////////////////////////////////////////////////////////////////
  24. // //
  25. // LSA Component Test for RPC API - main program //
  26. // //
  27. /////////////////////////////////////////////////////////////////////////////
  28. VOID
  29. CtLsaInitObjectAttributes(
  30. IN POBJECT_ATTRIBUTES ObjectAttributes,
  31. IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService
  32. )
  33. /*++
  34. Routine Description:
  35. This function initializes the given Object Attributes structure, including
  36. Security Quality Of Service. Memory must be allcated for both
  37. ObjectAttributes and Security QOS by the caller.
  38. Arguments:
  39. ObjectAttributes - Pointer to Object Attributes to be initialized.
  40. SecurityQualityOfService - Pointer to Security QOS to be initialized.
  41. Return Value:
  42. None.
  43. --*/
  44. {
  45. SecurityQualityOfService->Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  46. SecurityQualityOfService->ImpersonationLevel = SecurityImpersonation;
  47. SecurityQualityOfService->ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  48. SecurityQualityOfService->EffectiveOnly = FALSE;
  49. //
  50. // Set up the object attributes prior to opening the LSA.
  51. //
  52. InitializeObjectAttributes(
  53. ObjectAttributes,
  54. NULL,
  55. 0L,
  56. NULL,
  57. NULL
  58. );
  59. //
  60. // The InitializeObjectAttributes macro presently stores NULL for
  61. // the SecurityQualityOfService field, so we must manually copy that
  62. // structure for now.
  63. //
  64. ObjectAttributes->SecurityQualityOfService = SecurityQualityOfService;
  65. }
  66. VOID __cdecl
  67. main (argc, argv)
  68. int argc;
  69. char **argv;
  70. {
  71. NTSTATUS Status = STATUS_SUCCESS;
  72. UNICODE_STRING NumberOfAccounts;
  73. ANSI_STRING NumberOfAccountsAnsi;
  74. OBJECT_ATTRIBUTES ObjectAttributes;
  75. SECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
  76. LSA_HANDLE PolicyHandle;
  77. if (argc != 2) {
  78. printf("\n");
  79. printf("Instructions for using SAM Accounts Domain Test Load\n");
  80. printf("----------------------------------------------------\n");
  81. printf("\n\n");
  82. printf("This program can be used to create n users in a SAM\n");
  83. printf("Accounts domain, or update user information in a domain.\n");
  84. printf("Usernames and other information are pseudo-randomized\n");
  85. printf("and Relative Ids begin at 4096, to avoid conflict with\n");
  86. printf("existing installed accounts\n");
  87. printf("\n");
  88. printf("NOTE: \\\\popcorn\\public\\scottbi\\runsamdb temporarily\n");
  89. printf("contains 340-compatible x86 versions of the four files\n");
  90. printf("described in steps 1. 2. and 3 below.\n");
  91. printf("\n");
  92. printf("1. Replace lsasrv.dll with one compiled with the\n");
  93. printf(" LSA_SAM_ACCOUNTS_DOMAIN_TEST #define enabled\n");
  94. printf(" in file lsa\\server\\dbpolicy.c.\n");
  95. printf("\n");
  96. printf("2. Replace samsrv.dll with one containing chads\n");
  97. printf(" mondo level SamSetInformationUser changes.\n");
  98. printf("\n");
  99. printf("3. Copy runsamdb.cmd and ctsamdb.exe to a directory\n");
  100. printf(" on your path\n");
  101. printf("\n");
  102. printf("4. Reboot system with debugger enabled. Debugger terminal\n");
  103. printf(" will display a message for each 100 users created\n");
  104. printf(" plus the time taken to create the last 100 users.\n");
  105. printf(" If any attempt is made to create an existing user,\n");
  106. printf(" or a user that conflicts with an existing account, the\n");
  107. printf(" total number of occurrences of these to date is displayed.\n");
  108. printf("\n");
  109. printf("5. To load a SAM database with n > 0 users, type:\n");
  110. printf("\n");
  111. printf(" runsamdb n\n");
  112. printf("\n");
  113. printf("6. To update the SAM database with identical information\n");
  114. printf(" to that loaded, repeat the command in 5.\n");
  115. printf("\n");
  116. printf("7. To delete the users you created, type\n");
  117. printf("\n");
  118. printf(" runsamdb -1\n");
  119. printf("\n");
  120. printf("8. Existing accounts not created by the test will not\n");
  121. printf(" normally be affected.\n");
  122. printf("\n");
  123. printf("9. To repeat these instructions, type\n");
  124. printf("\n");
  125. printf(" runsamdb\n");
  126. return;
  127. }
  128. RtlInitAnsiString( &NumberOfAccountsAnsi, argv[1] );
  129. RtlAnsiStringToUnicodeString(
  130. &NumberOfAccounts,
  131. &NumberOfAccountsAnsi,
  132. TRUE
  133. );
  134. CtLsaInitObjectAttributes(
  135. &ObjectAttributes,
  136. &SecurityQualityOfService
  137. );
  138. //
  139. // Open a handle to the local Policy Object. Use a benign access
  140. // mask, because we won't check it.
  141. //
  142. Status = LsaOpenPolicy(
  143. NULL,
  144. &ObjectAttributes,
  145. POLICY_VIEW_LOCAL_INFORMATION,
  146. &PolicyHandle
  147. );
  148. if (!NT_SUCCESS(Status)) {
  149. printf("LSA RPC CT - LsaOpenPolicy failed 0x%lx\n", Status);
  150. return;
  151. }
  152. //
  153. // Use an information class in LsaSetInformationPolicy() that can't be
  154. // specified normally on a set operation.
  155. //
  156. Status = LsaSetInformationPolicy(
  157. PolicyHandle,
  158. PolicyPdAccountInformation,
  159. &NumberOfAccounts
  160. );
  161. Status = LsaClose( PolicyHandle );
  162. }