From 83a3ac27ddd9a02ad698407515b0e708197b2aac Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Mon, 29 Jul 2024 08:28:15 +0200 Subject: [MHR-36] Last commit on ticket. Signed-off-by: Amlal EL Mahrouss --- Kernel/Sources/CxxAbi-AMD64.cxx | 2 +- Kernel/Sources/CxxAbi-ARM64.cxx | 2 +- Kernel/Sources/FS/NewFS.cxx | 2 +- Kernel/Sources/HError.cxx | 2 +- Kernel/Sources/Heap.cxx | 2 +- Kernel/Sources/Main.cxx | 2 +- Kernel/Sources/Network/IPCEP.cxx | 2 +- Kernel/Sources/ProcessScheduler.cxx | 2 +- Kernel/Sources/User.cxx | 69 +++++++++++++++++++++++++++++++++++++ 9 files changed, 77 insertions(+), 8 deletions(-) (limited to 'Kernel/Sources') diff --git a/Kernel/Sources/CxxAbi-AMD64.cxx b/Kernel/Sources/CxxAbi-AMD64.cxx index e1f61aaf..43b8c725 100644 --- a/Kernel/Sources/CxxAbi-AMD64.cxx +++ b/Kernel/Sources/CxxAbi-AMD64.cxx @@ -8,7 +8,7 @@ #include #include -#include +#include atexit_func_entry_t __atexit_funcs[kDSOMaxObjects]; diff --git a/Kernel/Sources/CxxAbi-ARM64.cxx b/Kernel/Sources/CxxAbi-ARM64.cxx index 46524374..d5be9e5e 100644 --- a/Kernel/Sources/CxxAbi-ARM64.cxx +++ b/Kernel/Sources/CxxAbi-ARM64.cxx @@ -8,7 +8,7 @@ #include #include -#include +#include EXTERN_C { diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 38a417cb..a8790109 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index f10c3a15..7c093865 100644 --- a/Kernel/Sources/HError.cxx +++ b/Kernel/Sources/HError.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include #include namespace Kernel diff --git a/Kernel/Sources/Heap.cxx b/Kernel/Sources/Heap.cxx index 6ac91448..b2acaffe 100644 --- a/Kernel/Sources/Heap.cxx +++ b/Kernel/Sources/Heap.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include #include #include diff --git a/Kernel/Sources/Main.cxx b/Kernel/Sources/Main.cxx index 0f835adc..fb9b522b 100644 --- a/Kernel/Sources/Main.cxx +++ b/Kernel/Sources/Main.cxx @@ -192,7 +192,7 @@ namespace Kernel::Detail Kernel::UserView::The()->fRootUser = new User(RingKind::kRingSuperUser, kSuperUser); Kernel::kcout << "newoskrnl: logged in as: " << Kernel::UserView::The()->fRootUser->Name().CData() << Kernel::endl; - Kernel::UserView::The()->LogIn(Kernel::UserView::The()->fRootUser); + Kernel::UserView::The()->LogIn(Kernel::UserView::The()->fRootUser, ""); Kernel::kcout << "newoskrnl: " << cKernelVersion.GetKey().CData() << ": " << Kernel::number(cKernelVersion.GetValue()) << Kernel::endl; } diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx index 54d94b18..5271be05 100644 --- a/Kernel/Sources/Network/IPCEP.cxx +++ b/Kernel/Sources/Network/IPCEP.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include using namespace Kernel; diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index bfa6fddf..b5be1dd2 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -13,7 +13,7 @@ #include #include #include -#include +#include ///! BUGS: 0 diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx index 68d0d5be..a86f9ac3 100644 --- a/Kernel/Sources/User.cxx +++ b/Kernel/Sources/User.cxx @@ -12,6 +12,8 @@ #include #include +#include +#include /// bugs 0 @@ -61,4 +63,71 @@ namespace Kernel { return this->Ring() == RingKind::kRingSuperUser; } + + UserView* UserView::The() noexcept + { + UserView* view = nullptr; + + if (!view) + view = new UserView(); + + return view; + } + + Void UserView::LogIn(User* user, const Char* password) noexcept + { + if (!password || + !user) + { + ErrLocal() = kErrorInvalidData; + + return; + } + + FileStreamUTF8 file(kUsersFile, "rb"); + + auto token = file.Read(password); + + if (!token) + { + ErrLocal() = kErrorInvalidCreds; + + kcout << "newoskrnl: Incorrect credentials.\r"; + return; + } + + user->fUserToken = token; + + if (fCurrentUser) + { + if (!fLastLoggedOffUser) + { + fLastLoggedOffUser = fCurrentUser; + } + else + { + this->LogOff(); + } + } + + fCurrentUser = user; + } + + Void UserView::LogOff() noexcept + { + if (!fCurrentUser) + return; + + // an illegal operation just occured, we can't risk more. + if (fCurrentUser == fRootUser) + { + ke_stop(RUNTIME_CHECK_BOOTSTRAP); + } + + if (fLastLoggedOffUser) + delete fLastLoggedOffUser; + + fLastLoggedOffUser = nullptr; + fLastLoggedOffUser = fCurrentUser; + } } // namespace Kernel -- cgit v1.2.3