Implement basic administrator account creation and logon.

This is neither safe nor NT-compatible.

svn path=/trunk/; revision=7835
This commit is contained in:
Eric Kohl
2004-01-23 10:35:52 +00:00
parent e5fc3cf116
commit 8f96df5995
3 changed files with 162 additions and 88 deletions
+117 -2
View File
@@ -1,4 +1,4 @@
/* $Id: logon.c,v 1.2 2004/01/20 23:16:42 ekohl Exp $
/* $Id: logon.c,v 1.3 2004/01/23 10:35:52 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@@ -159,6 +159,117 @@ LogonUserA (LPCSTR lpszUsername,
}
static BOOL STDCALL
SamGetUserSid (LPCWSTR UserName,
PSID *Sid)
{
PSID lpSid;
DWORD dwLength;
HKEY hAccountKey;
HKEY hUserKey;
if (Sid != NULL)
*Sid = NULL;
/* Open the Account key */
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
L"SAM\\SAM\\Domains\\Account",
0,
KEY_READ,
&hAccountKey))
{
//#if 0
// DebugPrint ("Failed to open Account key! (Error %lu)\n", GetLastError());
//#endif
return FALSE;
}
/* Open the user key */
if (RegOpenKeyExW (hAccountKey,
UserName,
0,
KEY_READ,
&hUserKey))
{
if (GetLastError () == ERROR_FILE_NOT_FOUND)
{
//#if 0
// DebugPrint ("Invalid user name!\n");
//#endif
SetLastError (ERROR_NO_SUCH_USER);
}
else
{
//#if 0
// DebugPrint ("Failed to open user key! (Error %lu)\n", GetLastError());
//#endif
}
RegCloseKey (hAccountKey);
return FALSE;
}
RegCloseKey (hAccountKey);
/* Get SID size */
dwLength = 0;
if (RegQueryValueExW (hUserKey,
L"Sid",
NULL,
NULL,
NULL,
&dwLength))
{
//#if 0
// DebugPrint ("Failed to read the SID size! (Error %lu)\n", GetLastError());
//#endif
RegCloseKey (hUserKey);
return FALSE;
}
/* FIXME: Allocate sid buffer */
//#if 0
// DebugPrint ("Required SID buffer size: %lu\n", dwLength);
//#endif
lpSid = (PSID)RtlAllocateHeap (RtlGetProcessHeap (),
0,
dwLength);
if (lpSid == NULL)
{
//#if 0
// DebugPrint ("Failed to allocate SID buffer!\n");
//#endif
RegCloseKey (hUserKey);
return FALSE;
}
/* Read sid */
if (RegQueryValueExW (hUserKey,
L"Sid",
NULL,
NULL,
(LPBYTE)lpSid,
&dwLength))
{
//#if 0
// DebugPrint ("Failed to read the SID! (Error %lu)\n", GetLastError());
//#endif
RtlFreeHeap (RtlGetProcessHeap (),
0,
lpSid);
RegCloseKey (hUserKey);
return FALSE;
}
RegCloseKey (hUserKey);
*Sid = lpSid;
return TRUE;
}
/*
* @unimplemented
*/
@@ -206,7 +317,9 @@ LogonUserW (LPCWSTR lpszUsername,
AuthenticationId.HighPart = 0;
ExpirationTime.QuadPart = -1;
/* FIXME: Get the user SID from the registry */
/* Get the user SID from the registry */
if (!SamGetUserSid (lpszUsername, &UserSid))
{
RtlAllocateAndInitializeSid (&SystemAuthority,
5,
SECURITY_NT_NON_UNIQUE_RID,
@@ -218,6 +331,7 @@ LogonUserW (LPCWSTR lpszUsername,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
&UserSid);
}
TokenUser.User.Sid = UserSid;
TokenUser.User.Attributes = 0;
@@ -237,6 +351,7 @@ LogonUserW (LPCWSTR lpszUsername,
Status = RtlCreateAcl (&Dacl, sizeof(ACL), ACL_REVISION);
if (!NT_SUCCESS(Status))
{
RtlFreeSid (UserSid);
return FALSE;
}
+2 -2
View File
@@ -1,4 +1,4 @@
# $Id: Makefile,v 1.4 2004/01/16 21:33:23 ekohl Exp $
# $Id: Makefile,v 1.5 2004/01/23 10:34:23 ekohl Exp $
PATH_TO_TOP = ../..
@@ -8,7 +8,7 @@ TARGET_NAME = syssetup
TARGET_BASE = 0x74A30000
TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a gdi32.a user32.a userenv.a
TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a gdi32.a user32.a samlib.a userenv.a
# comctl32.a
TARGET_CFLAGS = -Wall -Werror -fno-builtin
+43 -84
View File
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: install.c,v 1.6 2004/01/16 21:33:23 ekohl Exp $
/* $Id: install.c,v 1.7 2004/01/23 10:34:23 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@@ -31,8 +31,11 @@
#include <windows.h>
#include <stdio.h>
#include <samlib.h>
#include <syssetup.h>
// #define NO_GUI
#if 0
VOID Wizard (VOID);
#endif
@@ -53,14 +56,22 @@ PSID AdminSid = NULL;
void
DebugPrint(char* fmt,...)
{
char buffer[512];
char Buffer[512];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
#ifdef NO_GUI
OutputDebugStringA(buffer);
#else
strcat (buffer, "\nRebooting now!");
MessageBoxA (NULL,
Buffer,
"ReactOS Setup",
MB_OK);
#endif
}
@@ -87,6 +98,7 @@ CreateRandomSid (PSID *Sid)
Sid);
}
static VOID
AppendRidToSid (PSID *Dst,
PSID Src,
@@ -120,47 +132,6 @@ AppendRidToSid (PSID *Dst,
Dst);
}
static BOOL
SaveDomainSid (PSID Sid)
{
DWORD dwDisposition;
HKEY hKey;
if (RegCreateKeyExW (HKEY_LOCAL_MACHINE,
L"SAM\\Accounts",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition))
{
#if 0
DebugPrint ("Failed to create Accounts key! (Error %lu)\n", GetLastError());
#endif
return FALSE;
}
if (RegSetValueExW (hKey,
L"DomainSID",
0,
REG_BINARY,
(LPBYTE)Sid,
RtlLengthSid (Sid)))
{
#if 0
DebugPrint ("Failed to set DomainSID value! (Error %lu)\n", GetLastError());
#endif
RegCloseKey (hKey);
return FALSE;
}
RegCloseKey (hKey);
return TRUE;
}
DWORD STDCALL
InstallReactOS (HINSTANCE hInstance)
@@ -190,27 +161,15 @@ InstallReactOS (HINSTANCE hInstance)
if (!InitializeProfiles ())
{
#if 0
OutputDebugStringA ("InitializeProfiles() failed\n");
#endif
MessageBoxA (NULL,
"Profile initialization failed!\nRebooting now!",
"ReactOS Setup",
MB_OK);
DebugPrint ("InitializeProfiles() failed\n");
return 0;
}
/* Create the semi-random Domain-SID */
CreateRandomSid (&DomainSid);
if (DomainSid == NULL)
{
#if 0
OutputDebugStringA ("Failed to create the Domain-SID!\n");
#endif
MessageBoxA (NULL,
"Failed to create the Domain SID!\nRebooting now!",
"ReactOS Setup",
MB_OK);
DebugPrint ("Domain-SID creation failed!\n");
return 0;
}
@@ -220,38 +179,44 @@ InstallReactOS (HINSTANCE hInstance)
RtlFreeUnicodeString (&SidString);
#endif
if (!SaveDomainSid (DomainSid))
/* Initialize the Security Account Manager (SAM) */
if (!SamInitializeSAM ())
{
#if 0
OutputDebugStringA ("Failed to create the Domain-SID!\n");
#endif
MessageBoxA (NULL,
"Failed to save the Domain SID!\nRebooting now!",
"ReactOS Setup",
MB_OK);
DebugPrint ("SamInitializeSAM() failed!\n");
RtlFreeSid (DomainSid);
return 0;
}
/* Set the Domain SID (aka Computer SID) */
if (!SamSetDomainSid (DomainSid))
{
DebugPrint ("SamSetDomainSid() failed!\n");
RtlFreeSid (DomainSid);
return 0;
}
/* Append the Admin-RID */
AppendRidToSid (&AdminSid, DomainSid, DOMAIN_USER_RID_ADMIN);
#if 0
RtlConvertSidToUnicodeString (&SidString, AdminSid, TRUE);
DebugPrint ("Admin SID: %wZ\n", &SidString);
RtlConvertSidToUnicodeString (&SidString, DomainSid, TRUE);
DebugPrint ("Admin-SID: %wZ\n", &SidString);
RtlFreeUnicodeString (&SidString);
#endif
/* Create the Administrator account */
if (!SamCreateUser (L"Administrator", L"", AdminSid))
{
DebugPrint ("SamCreateUser() failed!\n");
RtlFreeSid (AdminSid);
RtlFreeSid (DomainSid);
return 0;
}
/* Create the Administrator profile */
if (!CreateUserProfileW (AdminSid, L"Administrator"))
{
#if 0
DebugPrint ("Failed to create the admin user profile!\n");
#endif
MessageBoxA (NULL,
"Failed to create the admin user profile!\nRebooting now!",
"ReactOS Setup",
MB_OK);
DebugPrint ("CreateUserProfileW() failed!\n");
RtlFreeSid (AdminSid);
RtlFreeSid (DomainSid);
return 0;
@@ -260,13 +225,7 @@ InstallReactOS (HINSTANCE hInstance)
RtlFreeSid (AdminSid);
RtlFreeSid (DomainSid);
#if 0
OutputDebugStringA ("System setup successful\n");
#endif
MessageBoxA (NULL,
"Profile initialization successful!\nRebooting now!",
"ReactOS Setup",
MB_OK);
DebugPrint ("System setup successful\n");
#if 0
Wizard ();