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);
|
|
|
|
|
2013-03-12 21:27:35 +00:00
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* GLOBALS *****************************************************************/
|
|
|
|
|
2013-03-12 21:27:35 +00:00
|
|
|
#define TICKS_PER_SECOND 10000000LL
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
SID_IDENTIFIER_AUTHORITY SecurityNtAuthority = {SECURITY_NT_AUTHORITY};
|
2012-05-21 13:38:32 +00:00
|
|
|
|
2013-03-12 21:27:35 +00:00
|
|
|
|
2012-05-21 13:38:32 +00:00
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
2012-06-23 10:23:08 +00:00
|
|
|
static BOOL
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupAddMemberToAlias(HKEY hDomainKey,
|
|
|
|
ULONG AliasId,
|
|
|
|
PSID MemberSid)
|
2012-06-23 10:23:08 +00:00
|
|
|
{
|
|
|
|
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
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateAliasAccount(HKEY hDomainKey,
|
|
|
|
LPCWSTR lpAccountName,
|
|
|
|
LPCWSTR lpDescription,
|
|
|
|
ULONG ulRelativeId)
|
2012-06-03 20:54:06 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
#if 0
|
|
|
|
static BOOL
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateGroupAccount(HKEY hDomainKey,
|
|
|
|
LPCWSTR lpAccountName,
|
|
|
|
ULONG ulRelativeId)
|
2013-04-20 18:54:27 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-05-28 15:04:26 +00:00
|
|
|
static BOOL
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateUserAccount(HKEY hDomainKey,
|
|
|
|
LPCWSTR lpAccountName,
|
|
|
|
LPCWSTR lpComment,
|
|
|
|
ULONG ulRelativeId,
|
|
|
|
ULONG UserAccountControl)
|
2012-05-28 15:04:26 +00:00
|
|
|
{
|
2012-07-02 23:09:20 +00:00
|
|
|
SAM_USER_FIXED_DATA FixedUserData;
|
2013-03-30 20:53:47 +00:00
|
|
|
UCHAR LogonHours[23];
|
2012-10-27 19:38:12 +00:00
|
|
|
LPWSTR lpEmptyString = L"";
|
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 */
|
|
|
|
FixedUserData.Version = 1;
|
2013-01-28 23:18:10 +00:00
|
|
|
FixedUserData.Reserved = 0;
|
|
|
|
FixedUserData.LastLogon.QuadPart = 0;
|
|
|
|
FixedUserData.LastLogoff.QuadPart = 0;
|
|
|
|
FixedUserData.PasswordLastSet.QuadPart = 0;
|
|
|
|
FixedUserData.AccountExpires.LowPart = MAXULONG;
|
|
|
|
FixedUserData.AccountExpires.HighPart = MAXLONG;
|
|
|
|
FixedUserData.LastBadPasswordTime.QuadPart = 0;
|
2012-07-02 23:09:20 +00:00
|
|
|
FixedUserData.UserId = ulRelativeId;
|
2013-01-28 23:18:10 +00:00
|
|
|
FixedUserData.PrimaryGroupId = DOMAIN_GROUP_RID_USERS;
|
2013-01-06 13:03:01 +00:00
|
|
|
FixedUserData.UserAccountControl = UserAccountControl;
|
2013-01-28 23:18:10 +00:00
|
|
|
FixedUserData.CountryCode = 0;
|
|
|
|
FixedUserData.CodePage = 0;
|
|
|
|
FixedUserData.BadPasswordCount = 0;
|
|
|
|
FixedUserData.LogonCount = 0;
|
|
|
|
FixedUserData.AdminCount = 0;
|
|
|
|
FixedUserData.OperatorCount = 0;
|
2012-07-02 23:09:20 +00:00
|
|
|
|
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-10-27 19:38:12 +00:00
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"FullName",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"HomeDirectory",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"HomeDirectoryDrive",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"ScriptPath",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"ProfilePath",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"AdminComment",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
2013-04-20 18:54:27 +00:00
|
|
|
(LPVOID)lpComment,
|
|
|
|
(wcslen(lpComment) + 1) * sizeof(WCHAR));
|
2012-10-27 19:38:12 +00:00
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"UserComment",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"WorkStations",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
2013-01-05 20:30:06 +00:00
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"Parameters",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPVOID)lpEmptyString,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
/* Set LogonHours attribute*/
|
2013-03-30 20:53:47 +00:00
|
|
|
*((PUSHORT)LogonHours) = 168;
|
|
|
|
memset(&(LogonHours[2]), 0xff, 21);
|
|
|
|
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"LogonHours",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
(LPVOID)LogonHours,
|
|
|
|
sizeof(LogonHours));
|
|
|
|
|
2013-01-28 23:18:10 +00:00
|
|
|
/* FIXME: Set Groups attribute*/
|
|
|
|
|
|
|
|
/* Set LMPwd attribute*/
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"LMPwd",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
2013-05-26 10:48:54 +00:00
|
|
|
(LPVOID)&EmptyLmHash,
|
|
|
|
sizeof(ENCRYPTED_LM_OWF_PASSWORD));
|
2013-01-28 23:18:10 +00:00
|
|
|
|
|
|
|
/* Set NTPwd attribute*/
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"NTPwd",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
2013-05-26 10:48:54 +00:00
|
|
|
(LPVOID)&EmptyNtHash,
|
|
|
|
sizeof(ENCRYPTED_NT_OWF_PASSWORD));
|
2013-01-28 23:18:10 +00:00
|
|
|
|
|
|
|
/* Set LMPwdHistory attribute*/
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"LMPwdHistory",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* Set NTPwdHistory attribute*/
|
|
|
|
RegSetValueEx(hAccountKey,
|
|
|
|
L"NTPwdHistory",
|
|
|
|
0,
|
|
|
|
REG_BINARY,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* FIXME: Set SecDesc attribute*/
|
|
|
|
|
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
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateDomain(IN HKEY hDomainsKey,
|
|
|
|
IN LPCWSTR lpKeyName,
|
|
|
|
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;
|
2013-03-12 21:27:35 +00:00
|
|
|
FixedData.MaxPasswordAge.QuadPart = -(6LL * 7LL * 24LL * 60LL * 60LL * TICKS_PER_SECOND); /* 6 weeks */
|
|
|
|
FixedData.MinPasswordAge.QuadPart = 0; /* right now */
|
|
|
|
// FixedData.ForceLogoff.QuadPart = // very far in the future aka never
|
|
|
|
FixedData.LockoutDuration.QuadPart = -(30LL * 60LL * TICKS_PER_SECOND); /* 30 minutes */
|
|
|
|
FixedData.LockoutObservationWindow.QuadPart = -(30LL * 60LL * TICKS_PER_SECOND); /* 30 minutes */
|
2012-07-01 16:51:10 +00:00
|
|
|
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;
|
2013-04-20 18:54:27 +00:00
|
|
|
HINSTANCE hInstance;
|
|
|
|
WCHAR szComment[256];
|
|
|
|
WCHAR szName[80];
|
2012-05-31 11:07:51 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE("SampInitializeSAM() called\n");
|
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
hInstance = GetModuleHandleW(L"samsrv.dll");
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_DOMAIN_BUILTIN_NAME, szName, 80);
|
|
|
|
|
2012-05-31 11:07:51 +00:00
|
|
|
/* Create the Builtin domain */
|
2013-05-23 09:07:12 +00:00
|
|
|
if (SampSetupCreateDomain(hDomainsKey,
|
|
|
|
L"Builtin",
|
|
|
|
szName,
|
|
|
|
pBuiltinSid,
|
|
|
|
&hDomainKey))
|
2012-05-28 15:04:26 +00:00
|
|
|
{
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_ALIAS_ADMINISTRATORS_NAME, szName, 80);
|
|
|
|
SampLoadString(hInstance, IDS_ALIAS_ADMINISTRATORS_COMMENT, szComment, 256);
|
|
|
|
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateAliasAccount(hDomainKey,
|
|
|
|
szName,
|
|
|
|
szComment,
|
|
|
|
DOMAIN_ALIAS_RID_ADMINS);
|
2012-06-03 20:54:06 +00:00
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_ALIAS_USERS_NAME, szName, 80);
|
|
|
|
SampLoadString(hInstance, IDS_ALIAS_USERS_COMMENT, szComment, 256);
|
|
|
|
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateAliasAccount(hDomainKey,
|
|
|
|
szName,
|
|
|
|
szComment,
|
|
|
|
DOMAIN_ALIAS_RID_USERS);
|
2012-06-03 20:54:06 +00:00
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_ALIAS_GUESTS_NAME, szName, 80);
|
|
|
|
SampLoadString(hInstance, IDS_ALIAS_GUESTS_COMMENT, szComment, 256);
|
|
|
|
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateAliasAccount(hDomainKey,
|
|
|
|
szName,
|
|
|
|
szComment,
|
|
|
|
DOMAIN_ALIAS_RID_GUESTS);
|
2012-06-03 20:54:06 +00:00
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_ALIAS_POWER_USERS_NAME, szName, 80);
|
|
|
|
SampLoadString(hInstance, IDS_ALIAS_POWER_USERS_COMMENT, szComment, 256);
|
|
|
|
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateAliasAccount(hDomainKey,
|
|
|
|
szName,
|
|
|
|
szComment,
|
|
|
|
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)
|
|
|
|
{
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupAddMemberToAlias(hDomainKey,
|
|
|
|
DOMAIN_ALIAS_RID_ADMINS,
|
|
|
|
pSid);
|
2012-06-23 10:23:08 +00:00
|
|
|
|
|
|
|
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 */
|
2013-05-23 09:07:12 +00:00
|
|
|
if (SampSetupCreateDomain(hDomainsKey,
|
|
|
|
L"Account",
|
|
|
|
L"",
|
|
|
|
AccountDomainInfo->DomainSid,
|
|
|
|
&hDomainKey))
|
2012-05-21 13:38:32 +00:00
|
|
|
{
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_USER_ADMINISTRATOR_NAME, szName, 80);
|
|
|
|
SampLoadString(hInstance, IDS_USER_ADMINISTRATOR_COMMENT, szComment, 256);
|
|
|
|
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateUserAccount(hDomainKey,
|
|
|
|
szName,
|
|
|
|
szComment,
|
|
|
|
DOMAIN_USER_RID_ADMIN,
|
|
|
|
USER_DONT_EXPIRE_PASSWORD | USER_NORMAL_ACCOUNT);
|
2012-05-28 15:04:26 +00:00
|
|
|
|
2013-04-20 18:54:27 +00:00
|
|
|
SampLoadString(hInstance, IDS_USER_GUEST_NAME, szName, 80);
|
|
|
|
SampLoadString(hInstance, IDS_USER_GUEST_COMMENT, szComment, 256);
|
|
|
|
|
2013-05-23 09:07:12 +00:00
|
|
|
SampSetupCreateUserAccount(hDomainKey,
|
|
|
|
szName,
|
|
|
|
szComment,
|
|
|
|
DOMAIN_USER_RID_GUEST,
|
|
|
|
USER_ACCOUNT_DISABLED | USER_DONT_EXPIRE_PASSWORD | USER_NORMAL_ACCOUNT);
|
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
|
|
|
}
|