2012-05-21 13:38:32 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: Security Account Manager (SAM) Server
|
|
|
|
* FILE: reactos/dll/win32/samsrv/setup.c
|
|
|
|
* PURPOSE: Registry setup routines
|
|
|
|
*
|
|
|
|
* PROGRAMMERS: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ****************************************************************/
|
|
|
|
|
|
|
|
#include "samsrv.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(samsrv);
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* GLOBALS *****************************************************************/
|
|
|
|
|
|
|
|
SID_IDENTIFIER_AUTHORITY SecurityNtAuthority = {SECURITY_NT_AUTHORITY};
|
2012-05-21 13:38:32 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
SampIsSetupRunning(VOID)
|
|
|
|
{
|
|
|
|
DWORD dwError;
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwType;
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwSetupType;
|
|
|
|
|
|
|
|
TRACE("SampIsSetupRunning()\n");
|
|
|
|
|
|
|
|
/* Open key */
|
|
|
|
dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\Setup",
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&hKey);
|
|
|
|
if (dwError != ERROR_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Read key */
|
|
|
|
dwSize = sizeof(DWORD);
|
|
|
|
dwError = RegQueryValueExW(hKey,
|
|
|
|
L"SetupType",
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
(LPBYTE)&dwSetupType,
|
|
|
|
&dwSize);
|
|
|
|
|
|
|
|
/* Close key, and check if returned values are correct */
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
if (dwError != ERROR_SUCCESS || dwType != REG_DWORD || dwSize != sizeof(DWORD))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
TRACE("SampIsSetupRunning() returns %s\n", (dwSetupType != 0) ? "TRUE" : "FALSE");
|
|
|
|
return (dwSetupType != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-23 10:23:08 +00:00
|
|
|
static PSID
|
|
|
|
AppendRidToSid(PSID SrcSid,
|
|
|
|
ULONG Rid)
|
|
|
|
{
|
|
|
|
ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
UCHAR RidCount;
|
|
|
|
PSID DstSid;
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
RidCount = *RtlSubAuthorityCountSid(SrcSid);
|
|
|
|
if (RidCount >= 8)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < RidCount; i++)
|
|
|
|
Rids[i] = *RtlSubAuthoritySid(SrcSid, i);
|
|
|
|
|
|
|
|
Rids[RidCount] = Rid;
|
|
|
|
RidCount++;
|
|
|
|
|
|
|
|
RtlAllocateAndInitializeSid(RtlIdentifierAuthoritySid(SrcSid),
|
|
|
|
RidCount,
|
|
|
|
Rids[0],
|
|
|
|
Rids[1],
|
|
|
|
Rids[2],
|
|
|
|
Rids[3],
|
|
|
|
Rids[4],
|
|
|
|
Rids[5],
|
|
|
|
Rids[6],
|
|
|
|
Rids[7],
|
|
|
|
&DstSid);
|
|
|
|
|
|
|
|
return DstSid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
SampAddMemberToAlias(HKEY hDomainKey,
|
|
|
|
ULONG AliasId,
|
|
|
|
PSID MemberSid)
|
|
|
|
{
|
|
|
|
DWORD dwDisposition;
|
|
|
|
LPWSTR MemberSidString = NULL;
|
|
|
|
WCHAR szKeyName[256];
|
|
|
|
HKEY hMembersKey;
|
|
|
|
|
|
|
|
ConvertSidToStringSidW(MemberSid, &MemberSidString);
|
|
|
|
|
|
|
|
swprintf(szKeyName, L"Aliases\\%08lX\\Members", AliasId);
|
|
|
|
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
|
|
|
szKeyName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hMembersKey,
|
|
|
|
&dwDisposition))
|
|
|
|
{
|
|
|
|
RegSetValueEx(hMembersKey,
|
|
|
|
MemberSidString,
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
(LPVOID)MemberSid,
|
|
|
|
RtlLengthSid(MemberSid));
|
|
|
|
|
|
|
|
RegCloseKey(hMembersKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
swprintf(szKeyName, L"Aliases\\Members\\%s", MemberSidString);
|
|
|
|
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
|
|
|
szKeyName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hMembersKey,
|
|
|
|
&dwDisposition))
|
|
|
|
{
|
|
|
|
swprintf(szKeyName, L"%08lX", AliasId);
|
|
|
|
|
|
|
|
RegSetValueEx(hMembersKey,
|
|
|
|
szKeyName,
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
(LPVOID)MemberSid,
|
|
|
|
RtlLengthSid(MemberSid));
|
|
|
|
|
|
|
|
RegCloseKey(hMembersKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MemberSidString != NULL)
|
|
|
|
LocalFree(MemberSidString);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-03 20:54:06 +00:00
|
|
|
static BOOL
|
|
|
|
SampCreateAliasAccount(HKEY hDomainKey,
|
|
|
|
LPCWSTR lpAccountName,
|
2012-06-23 10:23:08 +00:00
|
|
|
LPCWSTR lpDescription,
|
2012-06-03 20:54:06 +00:00
|
|
|
ULONG ulRelativeId)
|
|
|
|
{
|
|
|
|
DWORD dwDisposition;
|
|
|
|
WCHAR szAccountKeyName[32];
|
|
|
|
HKEY hAccountKey = NULL;
|
|
|
|
HKEY hNamesKey = NULL;
|
|
|
|
|
|
|
|
swprintf(szAccountKeyName, L"Aliases\\%08lX", ulRelativeId);
|
|
|
|
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
|
|
|
szAccountKeyName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hAccountKey,
|
|
|
|
&dwDisposition))
|
|
|
|
{
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"Name",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpAccountName,
|
|
|
|
(wcslen(lpAccountName) + 1) * sizeof(WCHAR));
|
|
|
|
|
2012-06-23 10:23:08 +00:00
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"Description",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpDescription,
|
|
|
|
(wcslen(lpDescription) + 1) * sizeof(WCHAR));
|
|
|
|
|
2012-06-03 20:54:06 +00:00
|
|
|
RegCloseKey(hAccountKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RegOpenKeyExW(hDomainKey,
|
|
|
|
L"Aliases\\Names",
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hNamesKey))
|
|
|
|
{
|
|
|
|
RegSetValueEx(hNamesKey,
|
|
|
|
lpAccountName,
|
|
|
|
0,
|
|
|
|
REG_DWORD,
|
|
|
|
(LPVOID)&ulRelativeId,
|
|
|
|
sizeof(ULONG));
|
|
|
|
|
|
|
|
RegCloseKey(hNamesKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-28 15:04:26 +00:00
|
|
|
static BOOL
|
2012-05-31 11:07:51 +00:00
|
|
|
SampCreateUserAccount(HKEY hDomainKey,
|
|
|
|
LPCWSTR lpAccountName,
|
|
|
|
ULONG ulRelativeId)
|
2012-05-28 15:04:26 +00:00
|
|
|
{
|
2012-07-02 23:09:20 +00:00
|
|
|
SAM_USER_FIXED_DATA FixedUserData;
|
2012-05-28 15:04:26 +00:00
|
|
|
DWORD dwDisposition;
|
2012-06-03 20:54:06 +00:00
|
|
|
WCHAR szAccountKeyName[32];
|
|
|
|
HKEY hAccountKey = NULL;
|
2012-05-31 11:07:51 +00:00
|
|
|
HKEY hNamesKey = NULL;
|
|
|
|
|
2012-07-02 23:09:20 +00:00
|
|
|
/* Initialize fixed user data */
|
|
|
|
memset(&FixedUserData, 0, sizeof(SAM_USER_FIXED_DATA));
|
|
|
|
FixedUserData.Version = 1;
|
|
|
|
|
|
|
|
FixedUserData.UserId = ulRelativeId;
|
|
|
|
|
2012-06-03 20:54:06 +00:00
|
|
|
swprintf(szAccountKeyName, L"Users\\%08lX", ulRelativeId);
|
2012-05-31 11:07:51 +00:00
|
|
|
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
2012-06-03 20:54:06 +00:00
|
|
|
szAccountKeyName,
|
2012-05-31 11:07:51 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
2012-06-03 20:54:06 +00:00
|
|
|
&hAccountKey,
|
2012-05-31 11:07:51 +00:00
|
|
|
&dwDisposition))
|
|
|
|
{
|
2012-07-02 23:09:20 +00:00
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"F",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
(LPVOID)&FixedUserData,
|
|
|
|
sizeof(SAM_USER_FIXED_DATA));
|
|
|
|
|
2012-06-03 20:54:06 +00:00
|
|
|
RegSetValueEx(hAccountKey,
|
2012-05-31 11:07:51 +00:00
|
|
|
L"Name",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpAccountName,
|
|
|
|
(wcslen(lpAccountName) + 1) * sizeof(WCHAR));
|
|
|
|
|
2012-06-03 20:54:06 +00:00
|
|
|
RegCloseKey(hAccountKey);
|
2012-05-31 11:07:51 +00:00
|
|
|
}
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (!RegOpenKeyExW(hDomainKey,
|
|
|
|
L"Users\\Names",
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hNamesKey))
|
|
|
|
{
|
|
|
|
RegSetValueEx(hNamesKey,
|
|
|
|
lpAccountName,
|
|
|
|
0,
|
|
|
|
REG_DWORD,
|
|
|
|
(LPVOID)&ulRelativeId,
|
|
|
|
sizeof(ULONG));
|
|
|
|
|
|
|
|
RegCloseKey(hNamesKey);
|
|
|
|
}
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2012-05-21 13:38:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2012-05-31 11:07:51 +00:00
|
|
|
SampCreateDomain(IN HKEY hDomainsKey,
|
2012-06-01 18:03:25 +00:00
|
|
|
IN LPCWSTR lpKeyName,
|
2012-05-31 11:07:51 +00:00
|
|
|
IN LPCWSTR lpDomainName,
|
|
|
|
IN PSID lpDomainSid,
|
|
|
|
OUT PHKEY lpDomainKey)
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-07-01 16:51:10 +00:00
|
|
|
SAM_DOMAIN_FIXED_DATA FixedData;
|
|
|
|
LPWSTR lpEmptyString = L"";
|
2012-05-21 13:38:32 +00:00
|
|
|
DWORD dwDisposition;
|
2012-05-31 11:07:51 +00:00
|
|
|
HKEY hDomainKey = NULL;
|
2012-06-03 20:54:06 +00:00
|
|
|
HKEY hAliasesKey = NULL;
|
2012-05-28 15:04:26 +00:00
|
|
|
HKEY hGroupsKey = NULL;
|
|
|
|
HKEY hUsersKey = NULL;
|
2012-05-31 11:07:51 +00:00
|
|
|
HKEY hNamesKey = NULL;
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (lpDomainKey != NULL)
|
|
|
|
*lpDomainKey = NULL;
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-07-01 16:51:10 +00:00
|
|
|
/* Initialize the fixed domain data */
|
|
|
|
memset(&FixedData, 0, sizeof(SAM_DOMAIN_FIXED_DATA));
|
|
|
|
FixedData.Version = 1;
|
|
|
|
NtQuerySystemTime(&FixedData.CreationTime);
|
|
|
|
FixedData.DomainModifiedCount.QuadPart = 0;
|
|
|
|
// FixedData.MaxPasswordAge // 6 Weeks
|
|
|
|
FixedData.MinPasswordAge.QuadPart = 0; // Now
|
|
|
|
// FixedData.ForceLogoff
|
|
|
|
// FixedData.LockoutDuration // 30 minutes
|
|
|
|
// FixedData.LockoutObservationWindow // 30 minutes
|
|
|
|
FixedData.ModifiedCountAtLastPromotion.QuadPart = 0;
|
|
|
|
FixedData.NextRid = 1000;
|
|
|
|
FixedData.PasswordProperties = 0;
|
|
|
|
FixedData.MinPasswordLength = 0;
|
|
|
|
FixedData.PasswordHistoryLength = 0;
|
|
|
|
FixedData.LockoutThreshold = 0;
|
|
|
|
FixedData.DomainServerState = DomainServerEnabled;
|
|
|
|
FixedData.DomainServerRole = DomainServerRolePrimary;
|
|
|
|
FixedData.UasCompatibilityRequired = TRUE;
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (RegCreateKeyExW(hDomainsKey,
|
2012-06-01 18:03:25 +00:00
|
|
|
lpKeyName,
|
2012-05-21 13:38:32 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
2012-05-31 11:07:51 +00:00
|
|
|
&hDomainKey,
|
2012-05-21 13:38:32 +00:00
|
|
|
&dwDisposition))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-07-01 16:51:10 +00:00
|
|
|
/* Set the fixed data value */
|
|
|
|
if (RegSetValueEx(hDomainKey,
|
|
|
|
L"F",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
(LPVOID)&FixedData,
|
|
|
|
sizeof(SAM_DOMAIN_FIXED_DATA)))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (lpDomainSid != NULL)
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-06-01 18:03:25 +00:00
|
|
|
RegSetValueEx(hDomainKey,
|
|
|
|
L"Name",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpDomainName,
|
|
|
|
(wcslen(lpDomainName) + 1) * sizeof(WCHAR));
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RegSetValueEx(hDomainKey,
|
|
|
|
L"SID",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
(LPVOID)lpDomainSid,
|
|
|
|
RtlLengthSid(lpDomainSid));
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 16:51:10 +00:00
|
|
|
RegSetValueEx(hDomainKey,
|
|
|
|
L"OemInformation",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hDomainKey,
|
|
|
|
L"ReplicaSourceNodeName",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create the Alias container */
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
2012-06-03 20:54:06 +00:00
|
|
|
L"Aliases",
|
2012-05-31 11:07:51 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
2012-06-03 20:54:06 +00:00
|
|
|
&hAliasesKey,
|
2012-05-31 11:07:51 +00:00
|
|
|
&dwDisposition))
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-06-03 20:54:06 +00:00
|
|
|
if (!RegCreateKeyExW(hAliasesKey,
|
2012-05-31 11:07:51 +00:00
|
|
|
L"Names",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hNamesKey,
|
|
|
|
&dwDisposition))
|
|
|
|
RegCloseKey(hNamesKey);
|
|
|
|
|
2012-06-03 20:54:06 +00:00
|
|
|
RegCloseKey(hAliasesKey);
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create the Groups container */
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
|
|
|
L"Groups",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hGroupsKey,
|
|
|
|
&dwDisposition))
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
if (!RegCreateKeyExW(hGroupsKey,
|
|
|
|
L"Names",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hNamesKey,
|
|
|
|
&dwDisposition))
|
|
|
|
RegCloseKey(hNamesKey);
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RegCloseKey(hGroupsKey);
|
2012-05-28 15:04:26 +00:00
|
|
|
}
|
2012-05-21 13:38:32 +00:00
|
|
|
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create the Users container */
|
|
|
|
if (!RegCreateKeyExW(hDomainKey,
|
|
|
|
L"Users",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hUsersKey,
|
|
|
|
&dwDisposition))
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
if (!RegCreateKeyExW(hUsersKey,
|
|
|
|
L"Names",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hNamesKey,
|
|
|
|
&dwDisposition))
|
|
|
|
RegCloseKey(hNamesKey);
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RegCloseKey(hUsersKey);
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (lpDomainKey != NULL)
|
|
|
|
*lpDomainKey = hDomainKey;
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
NTSTATUS
|
|
|
|
SampGetAccountDomainInfo(PPOLICY_ACCOUNT_DOMAIN_INFO *AccountDomainInfo)
|
|
|
|
{
|
|
|
|
LSA_OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
LSA_HANDLE PolicyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE("SampGetAccountDomainInfo\n");
|
|
|
|
|
|
|
|
memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
|
|
|
|
ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
|
|
|
|
|
|
|
|
Status = LsaOpenPolicy(NULL,
|
|
|
|
&ObjectAttributes,
|
2012-09-19 12:59:47 +00:00
|
|
|
POLICY_VIEW_LOCAL_INFORMATION,
|
2012-05-31 11:07:51 +00:00
|
|
|
&PolicyHandle);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
2012-05-28 15:04:26 +00:00
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
ERR("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
|
|
|
|
return Status;
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
Status = LsaQueryInformationPolicy(PolicyHandle,
|
|
|
|
PolicyAccountDomainInformation,
|
|
|
|
(PVOID *)AccountDomainInfo);
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
LsaClose(PolicyHandle);
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
SampInitializeSAM(VOID)
|
|
|
|
{
|
|
|
|
PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = NULL;
|
|
|
|
DWORD dwDisposition;
|
|
|
|
HKEY hSamKey = NULL;
|
|
|
|
HKEY hDomainsKey = NULL;
|
|
|
|
HKEY hDomainKey = NULL;
|
|
|
|
PSID pBuiltinSid = NULL;
|
|
|
|
BOOL bResult = TRUE;
|
2012-06-23 10:23:08 +00:00
|
|
|
PSID pSid;
|
2012-05-31 11:07:51 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE("SampInitializeSAM() called\n");
|
|
|
|
|
|
|
|
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SAM\\SAM",
|
2012-05-21 13:38:32 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
2012-05-31 11:07:51 +00:00
|
|
|
&hSamKey,
|
2012-05-21 13:38:32 +00:00
|
|
|
&dwDisposition))
|
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
ERR("Failed to create 'Sam' key! (Error %lu)\n", GetLastError());
|
|
|
|
return FALSE;
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (RegCreateKeyExW(hSamKey,
|
|
|
|
L"Domains",
|
2012-05-21 13:38:32 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
2012-05-31 11:07:51 +00:00
|
|
|
&hDomainsKey,
|
2012-05-21 13:38:32 +00:00
|
|
|
&dwDisposition))
|
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
ERR("Failed to create 'Domains' key! (Error %lu)\n", GetLastError());
|
2012-05-28 15:04:26 +00:00
|
|
|
bResult = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RegCloseKey(hSamKey);
|
|
|
|
hSamKey = NULL;
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create and initialize the Builtin Domain SID */
|
|
|
|
pBuiltinSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, RtlLengthRequiredSid(1));
|
|
|
|
if (pBuiltinSid == NULL)
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
ERR("Failed to alloacte the Builtin Domain SID\n");
|
2012-05-28 15:04:26 +00:00
|
|
|
bResult = FALSE;
|
|
|
|
goto done;
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RtlInitializeSid(pBuiltinSid, &SecurityNtAuthority, 1);
|
|
|
|
*(RtlSubAuthoritySid(pBuiltinSid, 0)) = SECURITY_BUILTIN_DOMAIN_RID;
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Get account domain information */
|
|
|
|
Status = SampGetAccountDomainInfo(&AccountDomainInfo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
ERR("SampGetAccountDomainInfo failed (Status %08lx)\n", Status);
|
2012-05-28 15:04:26 +00:00
|
|
|
bResult = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create the Builtin domain */
|
|
|
|
if (SampCreateDomain(hDomainsKey,
|
2012-06-01 18:03:25 +00:00
|
|
|
L"Builtin",
|
2012-05-31 11:07:51 +00:00
|
|
|
L"Builtin",
|
|
|
|
pBuiltinSid,
|
|
|
|
&hDomainKey))
|
2012-05-28 15:04:26 +00:00
|
|
|
{
|
2012-06-03 20:54:06 +00:00
|
|
|
SampCreateAliasAccount(hDomainKey,
|
|
|
|
L"Administrators",
|
2012-07-01 16:51:10 +00:00
|
|
|
L"Testabc1234567890",
|
2012-06-03 20:54:06 +00:00
|
|
|
DOMAIN_ALIAS_RID_ADMINS);
|
|
|
|
|
|
|
|
SampCreateAliasAccount(hDomainKey,
|
|
|
|
L"Users",
|
2012-07-01 16:51:10 +00:00
|
|
|
L"Users Group",
|
2012-06-03 20:54:06 +00:00
|
|
|
DOMAIN_ALIAS_RID_USERS);
|
|
|
|
|
|
|
|
SampCreateAliasAccount(hDomainKey,
|
|
|
|
L"Guests",
|
2012-07-01 16:51:10 +00:00
|
|
|
L"Guests Group",
|
2012-06-03 20:54:06 +00:00
|
|
|
DOMAIN_ALIAS_RID_GUESTS);
|
|
|
|
|
|
|
|
SampCreateAliasAccount(hDomainKey,
|
|
|
|
L"Power Users",
|
2012-07-01 16:51:10 +00:00
|
|
|
L"Power Users Group",
|
2012-06-03 20:54:06 +00:00
|
|
|
DOMAIN_ALIAS_RID_POWER_USERS);
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-06-23 10:23:08 +00:00
|
|
|
|
|
|
|
pSid = AppendRidToSid(AccountDomainInfo->DomainSid,
|
|
|
|
DOMAIN_USER_RID_ADMIN);
|
|
|
|
if (pSid != NULL)
|
|
|
|
{
|
|
|
|
SampAddMemberToAlias(hDomainKey,
|
|
|
|
DOMAIN_ALIAS_RID_ADMINS,
|
|
|
|
pSid);
|
|
|
|
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, pSid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RegCloseKey(hDomainKey);
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create the Account domain */
|
|
|
|
if (SampCreateDomain(hDomainsKey,
|
|
|
|
L"Account",
|
2012-06-01 18:03:25 +00:00
|
|
|
L"",
|
|
|
|
AccountDomainInfo->DomainSid,
|
2012-05-31 11:07:51 +00:00
|
|
|
&hDomainKey))
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2012-05-31 11:07:51 +00:00
|
|
|
SampCreateUserAccount(hDomainKey,
|
|
|
|
L"Administrator",
|
|
|
|
DOMAIN_USER_RID_ADMIN);
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
SampCreateUserAccount(hDomainKey,
|
|
|
|
L"Guest",
|
|
|
|
DOMAIN_USER_RID_GUEST);
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
RegCloseKey(hDomainKey);
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 15:04:26 +00:00
|
|
|
done:
|
2012-05-31 11:07:51 +00:00
|
|
|
if (AccountDomainInfo)
|
|
|
|
LsaFreeMemory(AccountDomainInfo);
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
if (pBuiltinSid)
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, pBuiltinSid);
|
2012-05-28 15:04:26 +00:00
|
|
|
|
|
|
|
if (hDomainsKey)
|
|
|
|
RegCloseKey(hDomainsKey);
|
|
|
|
|
|
|
|
if (hSamKey)
|
|
|
|
RegCloseKey(hSamKey);
|
2012-05-21 13:38:32 +00:00
|
|
|
|
|
|
|
TRACE("SampInitializeSAM() done\n");
|
|
|
|
|
2012-05-28 15:04:26 +00:00
|
|
|
return bResult;
|
2012-05-21 13:38:32 +00:00
|
|
|
}
|