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/KernelKit/DriveManager.hxx | 2 +- Kernel/KernelKit/FileManager.hpp | 2 +- Kernel/KernelKit/HError.hpp | 55 -------------------------- Kernel/KernelKit/LPC.hxx | 56 ++++++++++++++++++++++++++ Kernel/KernelKit/Timer.hpp | 2 +- Kernel/KernelKit/User.hxx | 69 ++++++++++----------------------- Kernel/KernelRsrc.rsrc | 2 +- Kernel/Modules/CoreCG/Accessibility.hxx | 2 +- 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 +++++++++++++++++++++++++++++++++ 17 files changed, 158 insertions(+), 117 deletions(-) delete mode 100644 Kernel/KernelKit/HError.hpp create mode 100644 Kernel/KernelKit/LPC.hxx (limited to 'Kernel') diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx index 5dec36f7..3614f475 100644 --- a/Kernel/KernelKit/DriveManager.hxx +++ b/Kernel/KernelKit/DriveManager.hxx @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp index 0d721ec0..a37360c7 100644 --- a/Kernel/KernelKit/FileManager.hpp +++ b/Kernel/KernelKit/FileManager.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/Kernel/KernelKit/HError.hpp b/Kernel/KernelKit/HError.hpp deleted file mode 100644 index df12641e..00000000 --- a/Kernel/KernelKit/HError.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include - -/// @file HError.hpp -/// @brief Local Process Codes. - -#define ErrLocalIsOk() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() == Kernel::kErrorSuccess) -#define ErrLocalFailed() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() != Kernel::kErrorSuccess) -#define ErrLocal() Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() - -namespace Kernel -{ - typedef Int32 HError; - - inline constexpr HError kErrorSuccess = 0; - inline constexpr HError kErrorExecutable = 33; - inline constexpr HError kErrorExecutableLib = 34; - inline constexpr HError kErrorFileNotFound = 35; - inline constexpr HError kErrorDirectoryNotFound = 36; - inline constexpr HError kErrorDiskReadOnly = 37; - inline constexpr HError kErrorDiskIsFull = 38; - inline constexpr HError kErrorProcessFault = 39; - inline constexpr HError kErrorSocketHangUp = 40; - inline constexpr HError kErrorThreadLocalStorage = 41; - inline constexpr HError kErrorMath = 42; - inline constexpr HError kErrorNoNetwork = 43; - inline constexpr HError kErrorHeapOutOfMemory = 44; - inline constexpr HError kErrorNoSuchDisk = 45; - inline constexpr HError kErrorFileExists = 46; - inline constexpr HError kErrorFormatFailed = 47; - inline constexpr HError kErrorNetworkTimeout = 48; - inline constexpr HError kErrorInternal = 49; - inline constexpr HError kErrorForkAlreadyExists = 50; - inline constexpr HError kErrorOutOfTeamSlot = 51; - inline constexpr HError kErrorHeapNotPresent = 52; - inline constexpr HError kErrorNoEntrypoint = 53; - inline constexpr HError kErrorDiskIsCorrupted = 54; - inline constexpr HError kErrorDisk = 55; - inline constexpr HError kErrorInvalidData = 56; - inline constexpr HError kErrorAsync = 57; - inline constexpr HError kErrorNonBlocking = 58; - inline constexpr HError kErrorIPC = 59; - inline constexpr HError kErrorSign = 60; - inline constexpr HError kErrorUnimplemented = 0; - - Void err_bug_check_raise(void) noexcept; - Boolean err_bug_check(void) noexcept; -} // namespace Kernel diff --git a/Kernel/KernelKit/LPC.hxx b/Kernel/KernelKit/LPC.hxx new file mode 100644 index 00000000..fc322475 --- /dev/null +++ b/Kernel/KernelKit/LPC.hxx @@ -0,0 +1,56 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include + +/// @file LPC.hxx +/// @brief Local Process Codes. + +#define ErrLocalIsOk() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() == Kernel::kErrorSuccess) +#define ErrLocalFailed() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() != Kernel::kErrorSuccess) +#define ErrLocal() Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() + +namespace Kernel +{ + typedef Int32 HError; + + inline constexpr HError kErrorSuccess = 0; + inline constexpr HError kErrorExecutable = 33; + inline constexpr HError kErrorExecutableLib = 34; + inline constexpr HError kErrorFileNotFound = 35; + inline constexpr HError kErrorDirectoryNotFound = 36; + inline constexpr HError kErrorDiskReadOnly = 37; + inline constexpr HError kErrorDiskIsFull = 38; + inline constexpr HError kErrorProcessFault = 39; + inline constexpr HError kErrorSocketHangUp = 40; + inline constexpr HError kErrorThreadLocalStorage = 41; + inline constexpr HError kErrorMath = 42; + inline constexpr HError kErrorNoNetwork = 43; + inline constexpr HError kErrorHeapOutOfMemory = 44; + inline constexpr HError kErrorNoSuchDisk = 45; + inline constexpr HError kErrorFileExists = 46; + inline constexpr HError kErrorFormatFailed = 47; + inline constexpr HError kErrorNetworkTimeout = 48; + inline constexpr HError kErrorInternal = 49; + inline constexpr HError kErrorForkAlreadyExists = 50; + inline constexpr HError kErrorOutOfTeamSlot = 51; + inline constexpr HError kErrorHeapNotPresent = 52; + inline constexpr HError kErrorNoEntrypoint = 53; + inline constexpr HError kErrorDiskIsCorrupted = 54; + inline constexpr HError kErrorDisk = 55; + inline constexpr HError kErrorInvalidData = 56; + inline constexpr HError kErrorAsync = 57; + inline constexpr HError kErrorNonBlocking = 58; + inline constexpr HError kErrorIPC = 59; + inline constexpr HError kErrorSign = 60; + inline constexpr HError kErrorInvalidCreds = 61; + inline constexpr HError kErrorUnimplemented = 0; + + Void err_bug_check_raise(void) noexcept; + Boolean err_bug_check(void) noexcept; +} // namespace Kernel diff --git a/Kernel/KernelKit/Timer.hpp b/Kernel/KernelKit/Timer.hpp index 11ed0c81..eff075cc 100644 --- a/Kernel/KernelKit/Timer.hpp +++ b/Kernel/KernelKit/Timer.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include namespace Kernel { diff --git a/Kernel/KernelKit/User.hxx b/Kernel/KernelKit/User.hxx index 02ba475d..d9d9bb1e 100644 --- a/Kernel/KernelKit/User.hxx +++ b/Kernel/KernelKit/User.hxx @@ -8,22 +8,27 @@ #define _INC_PERMISSION_SEL_HXX_ #include +#include #include #include // user mode users. -#define kSuperUser "Admin" +#define kSuperUser "Super" #define kGuestUser "Guest" -#define kUsersDir "\\Users\\Store\\" +#define kUsersFile "\\Users\\$Stores$" -#define kMaxUserNameLen (255) +#define kMaxUserNameLen (255) +#define kMaxUserTokenLen (4096) // hash 'password' -> base64+md5 encoded data // use this data to then fetch specific data of the user.. namespace Kernel { + class User; + class UserView; + enum class RingKind { kRingStdUser = 1, @@ -50,16 +55,23 @@ namespace Kernel bool operator!=(const User& lhs); public: - /// @brief Getters. - const RingKind& Ring() noexcept; + /// @brief Get software ring + const RingKind& Ring() noexcept; + /// @brief Get user name const StringView Name() noexcept; + /// @brief Is he a standard user? Bool IsStdUser() noexcept; + + /// @brief Is she a super user? Bool IsSuperUser() noexcept; private: RingKind fRing{RingKind::kRingStdUser}; StringView fUserName{kMaxUserNameLen}; + VoidPtr fUserToken{nullptr}; + + friend UserView; }; class UserView final @@ -76,50 +88,9 @@ namespace Kernel public: NEWOS_COPY_DELETE(UserView); - STATIC UserView* The() noexcept - { - UserView* view = nullptr; - - if (!view) - view = new UserView(); - - return view; - } - - Void LogIn(User* user) noexcept - { - if (fCurrentUser) - { - if (!fLastLoggedOffUser) - { - fLastLoggedOffUser = fCurrentUser; - } - else - { - this->LogOff(); - } - } - - fCurrentUser = user; - } - - Void 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; - } + STATIC UserView* The() noexcept; + Void LogIn(User* user, const Char* password) noexcept; + Void LogOff() noexcept; }; } // namespace Kernel diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index 97432f54..5a6f41ee 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -1,4 +1,4 @@ -1 ICON "../Icons/main.ico" +1 ICON "../Icons/default.ico" #include "CompilerKit/Version.hxx" diff --git a/Kernel/Modules/CoreCG/Accessibility.hxx b/Kernel/Modules/CoreCG/Accessibility.hxx index 849adece..baf9bc6f 100644 --- a/Kernel/Modules/CoreCG/Accessibility.hxx +++ b/Kernel/Modules/CoreCG/Accessibility.hxx @@ -8,7 +8,7 @@ #define __CORECG_ACCESS_HXX__ #include -#include +#include #include #include #include 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