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.

644 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. dbinstac.c
  5. Abstract:
  6. LSA Protected Subsystem - Account object Initialization.
  7. This module sets up account objects to establish the default
  8. Microsoft policy regarding privilege assignment, system access
  9. rights (interactive, network, service), and abnormal quotas.
  10. Author:
  11. Jim Kelly (JimK) May 3, 1992.
  12. Environment:
  13. User mode - Does not depend on Windows.
  14. Revision History:
  15. --*/
  16. #include <lsapch2.h>
  17. #include "dbp.h"
  18. NTSTATUS
  19. LsapDbInitializeAccount(
  20. IN PSID AccountSid,
  21. IN PLSAPR_PRIVILEGE_SET Privileges,
  22. IN ULONG SystemAccess
  23. );
  24. OLD_LARGE_INTEGER
  25. ConvertLongToOldLargeInteger(
  26. ULONG u
  27. )
  28. /*++
  29. Routine Description:
  30. Coverts a long to old style large interger
  31. Arguments:
  32. u - unsigned long.
  33. Return Value:
  34. converted old style large integer.
  35. --*/
  36. {
  37. LARGE_INTEGER NewLargeInteger;
  38. OLD_LARGE_INTEGER OldLargeInteger;
  39. NewLargeInteger = RtlConvertLongToLargeInteger(u);
  40. NEW_TO_OLD_LARGE_INTEGER(
  41. NewLargeInteger,
  42. OldLargeInteger );
  43. return( OldLargeInteger );
  44. }
  45. NTSTATUS
  46. LsapDbInstallAccountObjects(
  47. VOID
  48. )
  49. /*++
  50. Routine Description:
  51. This function establishes ACCOUNT objects and initializes them
  52. to contain the default Microsoft policy.
  53. Arguments:
  54. None.
  55. Return Value:
  56. --*/
  57. {
  58. NTSTATUS
  59. Status = STATUS_SUCCESS;
  60. ULONG
  61. i,
  62. Index,
  63. SystemAccess;
  64. SID_IDENTIFIER_AUTHORITY
  65. WorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY,
  66. NtAuthority = SECURITY_NT_AUTHORITY;
  67. PSID
  68. WorldSid = NULL,
  69. BuiltinAccountSid = NULL ;
  70. PLSAPR_PRIVILEGE_SET
  71. Privileges;
  72. UCHAR
  73. PrivilegesBuffer[ sizeof(LSAPR_PRIVILEGE_SET) +
  74. 20 * sizeof(LUID_AND_ATTRIBUTES)];
  75. //
  76. // Initialize our privilege set buffer
  77. // (Room for 100 privileges)
  78. //
  79. Privileges = (PLSAPR_PRIVILEGE_SET)(&PrivilegesBuffer);
  80. Privileges->Control = 0; //Not used here.
  81. for (i=0; i<20; i++) {
  82. Privileges->Privilege[i].Attributes = 0; //Disabled, DisabledByDefault
  83. }
  84. //
  85. // Set up the SIDs we need.
  86. // All builtin domain sids are the same length. We'll just create
  87. // one and change its RID as necessary.
  88. //
  89. if (NT_SUCCESS(Status)) {
  90. Status = RtlAllocateAndInitializeSid(
  91. &WorldSidAuthority,
  92. 1, //Sub authority count
  93. SECURITY_WORLD_RID, //Sub authorities (up to 8)
  94. 0, 0, 0, 0, 0, 0, 0,
  95. &WorldSid
  96. );
  97. }
  98. if (NT_SUCCESS(Status)) {
  99. Status = RtlAllocateAndInitializeSid(
  100. &NtAuthority,
  101. 2,
  102. SECURITY_BUILTIN_DOMAIN_RID,
  103. DOMAIN_ALIAS_RID_ADMINS,
  104. 0, 0, 0, 0, 0, 0,
  105. &BuiltinAccountSid
  106. );
  107. }
  108. //
  109. // Now create each account and assign the appropriate set of privileges
  110. // And logon capabilities. Some of these are product type-specific.
  111. //
  112. if (NT_SUCCESS(Status)) {
  113. //
  114. // World account
  115. // Logon types: Network
  116. // Privileges:
  117. // ChangeNotify (ENABLED)
  118. //
  119. Privileges->Privilege[0].Luid =
  120. ConvertLongToOldLargeInteger(SE_CHANGE_NOTIFY_PRIVILEGE);
  121. Privileges->Privilege[0].Attributes = SE_PRIVILEGE_ENABLED |
  122. SE_PRIVILEGE_ENABLED_BY_DEFAULT;
  123. Privileges->PrivilegeCount = 1;
  124. SystemAccess = SECURITY_ACCESS_NETWORK_LOGON;
  125. //
  126. // If a WinNt installation, give WORLD Interactive logon in
  127. // and SHUTDOWN privilege in addition to Network Logon.
  128. //
  129. if (LsapProductType == NtProductWinNt) {
  130. SystemAccess |= SECURITY_ACCESS_INTERACTIVE_LOGON |
  131. SECURITY_ACCESS_REMOTE_INTERACTIVE_LOGON ;
  132. Privileges->Privilege[1].Luid =
  133. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  134. Privileges->Privilege[1].Attributes =
  135. SE_PRIVILEGE_ENABLED | SE_PRIVILEGE_ENABLED_BY_DEFAULT;
  136. Privileges->PrivilegeCount = 2;
  137. }
  138. Status = LsapDbInitializeAccount(WorldSid, Privileges, SystemAccess);
  139. Privileges->Privilege[0].Attributes = 0;
  140. }
  141. if (NT_SUCCESS(Status)) {
  142. //
  143. // Admin Alias account
  144. // Logon types: Interactive, Network
  145. // Privileges:
  146. // Security
  147. // Backup
  148. // Restore
  149. // SetTime
  150. // Shutdown
  151. // RemoteShutdown
  152. // Debug
  153. // TakeOwnership
  154. // SystemEnvironment
  155. // SystemProfile
  156. // SingleProcessProfile
  157. // LoadDriver
  158. // CreatePagefile
  159. // IncreaseQuota
  160. //
  161. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON |
  162. SECURITY_ACCESS_NETWORK_LOGON;
  163. Index = 0;
  164. Privileges->Privilege[Index].Luid =
  165. ConvertLongToOldLargeInteger(SE_SECURITY_PRIVILEGE);
  166. Index++;
  167. Privileges->Privilege[Index].Luid =
  168. ConvertLongToOldLargeInteger(SE_BACKUP_PRIVILEGE);
  169. Index++;
  170. Privileges->Privilege[Index].Luid =
  171. ConvertLongToOldLargeInteger(SE_RESTORE_PRIVILEGE);
  172. Index++;
  173. Privileges->Privilege[Index].Luid =
  174. ConvertLongToOldLargeInteger(SE_SYSTEMTIME_PRIVILEGE);
  175. Index++;
  176. Privileges->Privilege[Index].Luid =
  177. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  178. Index++;
  179. Privileges->Privilege[Index].Luid =
  180. ConvertLongToOldLargeInteger(SE_REMOTE_SHUTDOWN_PRIVILEGE);
  181. Index++;
  182. Privileges->Privilege[Index].Luid =
  183. ConvertLongToOldLargeInteger(SE_TAKE_OWNERSHIP_PRIVILEGE);
  184. Index++;
  185. Privileges->Privilege[Index].Luid =
  186. ConvertLongToOldLargeInteger(SE_DEBUG_PRIVILEGE);
  187. Index++;
  188. Privileges->Privilege[Index].Luid =
  189. ConvertLongToOldLargeInteger(SE_SYSTEM_ENVIRONMENT_PRIVILEGE);
  190. Index++;
  191. Privileges->Privilege[Index].Luid =
  192. ConvertLongToOldLargeInteger(SE_SYSTEM_PROFILE_PRIVILEGE);
  193. Index++;
  194. Privileges->Privilege[Index].Luid =
  195. ConvertLongToOldLargeInteger(SE_PROF_SINGLE_PROCESS_PRIVILEGE);
  196. Index++;
  197. Privileges->Privilege[Index].Luid =
  198. ConvertLongToOldLargeInteger(SE_INC_BASE_PRIORITY_PRIVILEGE);
  199. Index++;
  200. Privileges->Privilege[Index].Luid =
  201. ConvertLongToOldLargeInteger(SE_LOAD_DRIVER_PRIVILEGE);
  202. Index++;
  203. Privileges->Privilege[Index].Luid =
  204. ConvertLongToOldLargeInteger(SE_CREATE_PAGEFILE_PRIVILEGE);
  205. Index++;
  206. Privileges->Privilege[Index].Luid =
  207. ConvertLongToOldLargeInteger(SE_INCREASE_QUOTA_PRIVILEGE);
  208. Index++;
  209. // to add another privilege, and add another group of lines ^^^
  210. Privileges->PrivilegeCount = Index;
  211. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_ADMINS;
  212. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  213. if (!NT_SUCCESS(Status)) {
  214. KdPrint(("LSA DB INSTALL: Creation of Administrators privileged account failed.\n"
  215. " Status: 0x%lx\n", Status));
  216. }
  217. }
  218. if (NT_SUCCESS(Status)) {
  219. //
  220. // Backup Operators Alias account
  221. // Logon types: Interactive
  222. // Privileges:
  223. // Backup
  224. // Restore
  225. // Shutdown
  226. //
  227. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON;
  228. Privileges->Privilege[0].Luid =
  229. ConvertLongToOldLargeInteger(SE_BACKUP_PRIVILEGE);
  230. Privileges->Privilege[1].Luid =
  231. ConvertLongToOldLargeInteger(SE_RESTORE_PRIVILEGE);
  232. Privileges->Privilege[2].Luid =
  233. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  234. // to add another privilege, vvvv increment this, and add a line ^^^
  235. Privileges->PrivilegeCount = 3;
  236. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_BACKUP_OPS;
  237. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  238. }
  239. if (LsapProductType == NtProductLanManNt) {
  240. if (NT_SUCCESS(Status)) {
  241. //
  242. // System Operators Alias account
  243. // Logon types: Interactive
  244. // Privileges:
  245. // Backup
  246. // Restore
  247. // SetTime
  248. // Shutdown
  249. // RemoteShutdown
  250. //
  251. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON;
  252. Privileges->Privilege[0].Luid =
  253. ConvertLongToOldLargeInteger(SE_BACKUP_PRIVILEGE);
  254. Privileges->Privilege[1].Luid =
  255. ConvertLongToOldLargeInteger(SE_RESTORE_PRIVILEGE);
  256. Privileges->Privilege[2].Luid =
  257. ConvertLongToOldLargeInteger(SE_SYSTEMTIME_PRIVILEGE);
  258. Privileges->Privilege[3].Luid =
  259. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  260. Privileges->Privilege[4].Luid =
  261. ConvertLongToOldLargeInteger(SE_REMOTE_SHUTDOWN_PRIVILEGE);
  262. // to add another privilege, vvvv increment this, and add a line ^^^
  263. Privileges->PrivilegeCount = 5;
  264. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_SYSTEM_OPS;
  265. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  266. }
  267. if (NT_SUCCESS(Status)) {
  268. //
  269. // Account Operators Alias account
  270. // Logon types: Interactive
  271. // Privileges:
  272. // Shutdown
  273. //
  274. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON;
  275. Privileges->Privilege[0].Luid =
  276. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  277. // to add another privilege, vvvv increment this, and add a line ^^^
  278. Privileges->PrivilegeCount = 1;
  279. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_ACCOUNT_OPS;
  280. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  281. }
  282. if (NT_SUCCESS(Status)) {
  283. //
  284. // Print Operators Alias account
  285. // Logon types: Interactive
  286. // Privileges:
  287. // Shutdown
  288. //
  289. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON;
  290. Privileges->Privilege[0].Luid =
  291. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  292. // to add another privilege, vvvv increment this, and add a line ^^^
  293. Privileges->PrivilegeCount = 1;
  294. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_PRINT_OPS;
  295. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  296. }
  297. } else {
  298. if (NT_SUCCESS(Status)) {
  299. //
  300. // Power Users Alias account
  301. // Logon types: Interactive, Network
  302. // Privileges:
  303. // Shutdown
  304. // Set System Time
  305. // SystemProfile
  306. // SingleProcessProfile
  307. // Debug (for developer installs ONLY!).
  308. //
  309. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON |
  310. SECURITY_ACCESS_NETWORK_LOGON |
  311. SECURITY_ACCESS_REMOTE_INTERACTIVE_LOGON ;
  312. Privileges->Privilege[0].Luid =
  313. ConvertLongToOldLargeInteger(SE_SYSTEMTIME_PRIVILEGE);
  314. Privileges->Privilege[1].Luid =
  315. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  316. Privileges->Privilege[2].Luid =
  317. ConvertLongToOldLargeInteger(SE_REMOTE_SHUTDOWN_PRIVILEGE);
  318. Privileges->Privilege[3].Luid =
  319. ConvertLongToOldLargeInteger(SE_SYSTEM_PROFILE_PRIVILEGE);
  320. Privileges->Privilege[3].Luid =
  321. ConvertLongToOldLargeInteger(SE_PROF_SINGLE_PROCESS_PRIVILEGE);
  322. Privileges->Privilege[4].Luid =
  323. ConvertLongToOldLargeInteger(SE_INC_BASE_PRIORITY_PRIVILEGE);
  324. // to add another privilege, vvvv increment this, and add a line ^^^
  325. Privileges->PrivilegeCount = 5;
  326. //
  327. // Add privileges assigned for developer install
  328. //
  329. if (LsapSetupWasRun != TRUE) {
  330. Privileges->Privilege[Privileges->PrivilegeCount].Luid =
  331. ConvertLongToOldLargeInteger(SE_DEBUG_PRIVILEGE);
  332. Privileges->PrivilegeCount++;
  333. }
  334. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_POWER_USERS;
  335. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  336. }
  337. if (NT_SUCCESS(Status)) {
  338. //
  339. // Users Alias account
  340. // Logon types: Interactive
  341. // Privileges:
  342. // Shutdown
  343. //
  344. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON;
  345. Privileges->Privilege[0].Luid =
  346. ConvertLongToOldLargeInteger(SE_SHUTDOWN_PRIVILEGE);
  347. // to add another privilege, vvvv increment this, and add a line ^^^
  348. Privileges->PrivilegeCount = 1;
  349. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_USERS;
  350. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  351. }
  352. if (NT_SUCCESS(Status)) {
  353. //
  354. // Guests Alias account
  355. // Logon types: Interactive
  356. // Privileges:
  357. // None
  358. //
  359. SystemAccess = SECURITY_ACCESS_INTERACTIVE_LOGON;
  360. // to add another privilege, vvvv increment this, and add a line ^^^
  361. Privileges->PrivilegeCount = 0;
  362. (*RtlSubAuthoritySid(BuiltinAccountSid, 1)) = DOMAIN_ALIAS_RID_GUESTS;
  363. Status = LsapDbInitializeAccount(BuiltinAccountSid, Privileges, SystemAccess);
  364. }
  365. }
  366. //
  367. // Free up SID buffers
  368. //
  369. RtlFreeSid( WorldSid );
  370. RtlFreeSid( BuiltinAccountSid );
  371. return(Status);
  372. }
  373. NTSTATUS
  374. LsapDbInitializeAccount(
  375. IN PSID AccountSid,
  376. IN PLSAPR_PRIVILEGE_SET Privileges,
  377. IN ULONG SystemAccess
  378. )
  379. /*++
  380. Routine Description:
  381. This function creates a single ACCOUNT object and assigns it the
  382. privileges and system access specified.
  383. Arguments:
  384. AccountSid - The SID of the account to create.
  385. Privileges - The privileges, if any, to assign to the account.
  386. SystemAccess - The logon capabilities, if any, to assign to the account.
  387. Return Value:
  388. --*/
  389. {
  390. NTSTATUS
  391. Status = STATUS_SUCCESS,
  392. LocalStatus;
  393. LSAPR_HANDLE
  394. AccountHandle = NULL;
  395. if ((Privileges->PrivilegeCount == 0) &&
  396. (NT_SUCCESS(Status) && SystemAccess == 0) ) {
  397. return(STATUS_SUCCESS);
  398. }
  399. Status = LsarCreateAccount( LsapDbHandle, AccountSid, 0, &AccountHandle);
  400. if (NT_SUCCESS(Status)) {
  401. if (Privileges->PrivilegeCount > 0) {
  402. Status = LsarAddPrivilegesToAccount( AccountHandle, Privileges );
  403. }
  404. if (NT_SUCCESS(Status) && SystemAccess != 0) {
  405. Status = LsarSetSystemAccessAccount( AccountHandle, SystemAccess);
  406. }
  407. LocalStatus = LsapCloseHandle( &AccountHandle, Status );
  408. }
  409. return(Status);
  410. }