diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-24 17:30:52 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-24 17:30:52 +0200 |
| commit | fdc8aaab2ad3c2f2f3f4bb4ffb71bc2d797366aa (patch) | |
| tree | da3e628e1c4862c424a2deebae6966d6fc262592 /dev/ZKA | |
| parent | 30e5aa322bf253cdf48cddf53a1c8a1e9720e705 (diff) | |
[IMP] Better kernel design.
+ If the process has a parent, and it's exited, that means that the
thread must go down as well.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA')
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx | 9 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 11 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/ProcessScheduler.hxx | 9 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/ThreadLocalStorage.hxx | 9 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/User.hxx | 21 | ||||
| -rw-r--r-- | dev/ZKA/Sources/DLLMain.cxx | 13 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FS/NewFS.cxx | 14 | ||||
| -rw-r--r-- | dev/ZKA/Sources/PEFCodeManager.cxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ProcessScheduler.cxx | 33 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ThreadLocalStorage.cxx | 52 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ThreadScheduler.cxx | 35 | ||||
| -rw-r--r-- | dev/ZKA/Sources/User.cxx | 124 |
12 files changed, 137 insertions, 199 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx index 7fee9005..b1b8d698 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx @@ -107,22 +107,26 @@ namespace Kernel::HAL /////////////////////////////////////////////////////////////////////////////////////// + /***********************************************************************************/ /// @brief Send start IPI for CPU. /// @param apicId /// @param vector /// @param targetAddress /// @return + /***********************************************************************************/ Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress) { Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, (apicId << 24)); Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_SIPI_Vector | vector); } + /***********************************************************************************/ /// @brief Send end IPI for CPU. /// @param apicId /// @param vector /// @param targetAddress /// @return + /***********************************************************************************/ Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress) { Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, apicId << 24); @@ -169,8 +173,10 @@ namespace Kernel::HAL semaphore_process.Unlock(); } + /***********************************************************************************/ /// @brief Fetch and enable cores inside main CPU. /// @param vendor_ptr RSD PTR structure. + /***********************************************************************************/ Void hal_system_get_cores(voidPtr vendor_ptr) { auto hw_and_pow_int = PowerFactoryInterface(vendor_ptr); @@ -216,8 +222,7 @@ namespace Kernel::HAL ++index; } - kcout << "newoskrnl: # of Cores: " << number(kSMPCount) << endl; - + kcout << "newoskrnl: # of cores: " << number(kSMPCount) << endl; kcout << "newoskrnl: First core ID: " << number(cSMPCores[0]) << endl; kSMPAware = true; diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 0845dc39..126473a0 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -23,6 +23,8 @@ Kernel::Property cKernelVersion; +Kernel::User cUserSuper{Kernel::RingKind::kRingSuperUser, kSuperUser}; + EXTERN Kernel::Boolean kAllocationInProgress; EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; @@ -65,7 +67,7 @@ STATIC Kernel::HAL::Detail::NewOSGDT cGdt = { }; Kernel::Void hal_real_init(Kernel::Void) noexcept; -EXTERN_C Kernel::Void KeMain(Kernel::Void); +EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void); EXTERN_C void hal_init_platform( Kernel::HEL::HandoverInformationHeader* HandoverHeader) @@ -227,12 +229,11 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::NewFilesystemManager::Mount(fs); - const auto cPassword = "debug_usr"; + const auto cPassword = "ZKA_KERNEL_AUTHORITY"; - Kernel::User user_debug{Kernel::RingKind::kRingSuperUser, kSuperUser}; - Kernel::UserManager::The()->TryLogIn(user_debug, cPassword, cPassword); + cUserSuper.TrySave(cPassword); - KeMain(); + ke_dll_entrypoint(); Kernel::ke_stop(RUNTIME_CHECK_FAILED); } diff --git a/dev/ZKA/KernelKit/ProcessScheduler.hxx b/dev/ZKA/KernelKit/ProcessScheduler.hxx index 810886ab..826f8a89 100644 --- a/dev/ZKA/KernelKit/ProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/ProcessScheduler.hxx @@ -125,7 +125,8 @@ namespace Kernel using HeapPtrKind = VoidPtr; /// @name PROCESS_HEADER_BLOCK - /// @brief Process Header (PHB). Holds information about the running process. Thread execution the THREAD_INFORMATION_BLOCK. + /// @brief Process Header Block (PHB). + /// Holds information about the running process/thread. struct PROCESS_HEADER_BLOCK final { public: @@ -145,7 +146,7 @@ namespace Kernel public: Char Name[kProcessLen] = {"PROCESS #0 (TEAM 0)"}; ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid}; - ProcessLevelRing Selector{ProcessLevelRing::kRingStdUser}; + User* AssignedOwner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatus Status{ProcessStatus::kDead}; @@ -158,6 +159,8 @@ namespace Kernel // shared library handle, reserved for kSharedObjectKind types of executables only. PEFSharedObjectInterface* DLLPtr{nullptr}; + PROCESS_HEADER_BLOCK* Parent{nullptr}; + // Memory usage. SizeT UsedMemory{0}; SizeT FreeMemory{0}; @@ -209,7 +212,7 @@ namespace Kernel //! @return Int32 local error code. Int32& GetLocalCode() noexcept; - const ProcessLevelRing& GetLevelRing() noexcept; + const User* GetOwner() noexcept; const ProcessStatus& GetStatus() noexcept; const AffinityKind& GetAffinity() noexcept; diff --git a/dev/ZKA/KernelKit/ThreadLocalStorage.hxx b/dev/ZKA/KernelKit/ThreadLocalStorage.hxx index afc4940f..115a4ca1 100644 --- a/dev/ZKA/KernelKit/ThreadLocalStorage.hxx +++ b/dev/ZKA/KernelKit/ThreadLocalStorage.hxx @@ -23,13 +23,8 @@ struct THREAD_INFORMATION_BLOCK; /// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) struct PACKED THREAD_INFORMATION_BLOCK final { - Kernel::Char f_Cookie[kTLSCookieLen]; // Process cookie. - Kernel::UIntPtr f_Code; // Start address (Instruction Pointer) - Kernel::UIntPtr f_Data; // Allocated Heap for process. - Kernel::UIntPtr f_Stack; // Application Stack pointer. - Kernel::Int32 f_ID; // Thread execution ID. - Kernel::Int64 f_UsedHeapPercent; // used heap in percent. - Kernel::Int64 f_FreeHeapPercent; // heap free in percent. + Kernel::Char f_Cookie[kTLSCookieLen]{0}; // Thread magic number. + Kernel::VoidPtr f_ThreadRecord{nullptr}; }; ///! @brief Cookie Sanity check. diff --git a/dev/ZKA/KernelKit/User.hxx b/dev/ZKA/KernelKit/User.hxx index 4686135f..a7f8fc02 100644 --- a/dev/ZKA/KernelKit/User.hxx +++ b/dev/ZKA/KernelKit/User.hxx @@ -77,27 +77,6 @@ namespace Kernel friend UserManager; }; - - class UserManager final - { - private: - UserManager() = default; - ~UserManager() = default; - - User* fCurrentUser{nullptr}; - - public: - User* fRootUser{nullptr}; - - public: - ZKA_COPY_DELETE(UserManager); - - STATIC UserManager* The() noexcept; - Bool TryLogIn(User& user, const Char* password, const Char* right_password) noexcept; - Bool TryLogIn(User& user, const Char* password) noexcept; - User* GetCurrent() noexcept; - Void TryLogOff() noexcept; - }; } // namespace Kernel #endif /* ifndef _INC_USER_HXX_ */ diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index f8c59a53..cecf7347 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -183,12 +183,11 @@ namespace Kernel::Detail /// @brief Application entrypoint. /// @param Void /// @return Void -EXTERN_C Kernel::Void KeMain(Kernel::Void) +EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) { + CGInit(); - CGInit(); - - CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), + CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), 0, 0); CGFini(); @@ -199,7 +198,6 @@ EXTERN_C Kernel::Void KeMain(Kernel::Void) root_zka_wnd->w_y = 10; root_zka_wnd->w_needs_repaint = Yes; - CG::CGDrawWindowList(&root_zka_wnd, 1); /// Now run kernel loop, until no process are running. Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation. @@ -213,6 +211,11 @@ EXTERN_C Kernel::Void KeMain(Kernel::Void) CG::UI_WINDOW_STRUCT* arr[] = {root_zka_wnd, root_install_wnd}; + CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), + 0, 0); + + CGFini(); + CG::CGDrawWindowList(arr, 2); while (Yes) diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx index 8f9ef8ef..87006502 100644 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ b/dev/ZKA/Sources/FS/NewFS.cxx @@ -22,14 +22,20 @@ using namespace Kernel; #ifdef __ED__ +/***********************************************************************************/ /** Define those external symbols, to make the editor shutup */ +/***********************************************************************************/ +/***********************************************************************************/ /// @brief get sector count. +/***********************************************************************************/ Kernel::SizeT drv_std_get_sector_count(); +/***********************************************************************************/ /// @brief get device size. +/***********************************************************************************/ Kernel::SizeT drv_std_get_drv_size(); #endif @@ -47,10 +53,12 @@ Kernel::SizeT drv_std_get_drv_size(); STATIC MountpointInterface sMountpointInterface; +/***********************************************************************************/ /// @brief Creates a new fork inside the New filesystem partition. /// @param catalog it's catalog /// @param theFork the fork itself. /// @return the fork +/***********************************************************************************/ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, _Input NFS_FORK_STRUCT& theFork) { @@ -156,10 +164,12 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata return nullptr; } +/***********************************************************************************/ /// @brief Find fork inside New filesystem. /// @param catalog the catalog. /// @param name the fork name. /// @return the fork. +/***********************************************************************************/ _Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, _Input const Char* name, Boolean isDataFork) @@ -209,20 +219,24 @@ _Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalo return theFork; } +/***********************************************************************************/ /// @brief Simpler factory to create a catalog (assumes you want to create a /// file.) /// @param name /// @return catalog pointer. +/***********************************************************************************/ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name) { return this->CreateCatalog(name, 0, kNewFSCatalogKindFile); } +/***********************************************************************************/ /// @brief Creates a new catalog into the disk. /// @param name the catalog name. /// @param flags the flags of the catalog. /// @param kind the catalog kind. /// @return catalog pointer. +/***********************************************************************************/ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) diff --git a/dev/ZKA/Sources/PEFCodeManager.cxx b/dev/ZKA/Sources/PEFCodeManager.cxx index f2f1e815..02303e1c 100644 --- a/dev/ZKA/Sources/PEFCodeManager.cxx +++ b/dev/ZKA/Sources/PEFCodeManager.cxx @@ -56,7 +56,7 @@ namespace Kernel { fPath = StringBuilder::Construct(path).Leak(); - auto cPefHeader = "PEFContainer"; + auto cPefHeader = "PEF_CONTAINER"; fCachedBlob = fFile->Read(cPefHeader); @@ -82,7 +82,7 @@ namespace Kernel return; } - kcout << "CodeManager: Warning: Executable format error!\n"; + kcout << "CodeManagerPEF: Warning: Executable format error!\n"; fBad = true; mm_delete_ke_heap(fCachedBlob); @@ -107,7 +107,7 @@ namespace Kernel PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob); - StringView cPefHeaderStr = StringBuilder::Construct("PEFContainerHeader:").Leak().Leak(); + StringView cPefHeaderStr; cPefHeaderStr += name; auto blob = fFile->Read(cPefHeaderStr.CData()); diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx index 9e0708e7..1d83e519 100644 --- a/dev/ZKA/Sources/ProcessScheduler.cxx +++ b/dev/ZKA/Sources/ProcessScheduler.cxx @@ -25,7 +25,7 @@ namespace Kernel { /***********************************************************************************/ - /// @brief Exit Code global + /// @brief Exit Code global variable. /***********************************************************************************/ STATIC Int32 cLastExitCode = 0U; @@ -44,11 +44,13 @@ namespace Kernel void PROCESS_HEADER_BLOCK::Crash() { - constexpr auto cUnknownProcess = "?"; + constexpr auto cUnknownProcess = "?"; kcout << (*this->Name == 0 ? cUnknownProcess : this->Name) << ": crashed. (id = " << number(kErrorProcessFault); kcout << ")\r"; + this->Status = ProcessStatus::kDead; + this->Exit(kErrorProcessFault); } @@ -60,6 +62,10 @@ namespace Kernel return this->fLastExitCode; } + /***********************************************************************************/ + /// @brief Error code variable getter. + /***********************************************************************************/ + Int32& PROCESS_HEADER_BLOCK::GetLocalCode() noexcept { return fLocalCode; @@ -146,9 +152,9 @@ namespace Kernel } /// @brief process selector getter. - const ProcessLevelRing& PROCESS_HEADER_BLOCK::GetLevelRing() noexcept + const User* PROCESS_HEADER_BLOCK::GetOwner() noexcept { - return this->Selector; + return this->AssignedOwner; } /// @brief process status getter. @@ -172,10 +178,6 @@ namespace Kernel */ void PROCESS_HEADER_BLOCK::Exit(const Int32& exit_code) { - if (this->ProcessId != - ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId) - ke_stop(RUNTIME_CHECK_PROCESS); - fLastExitCode = exit_code; cLastExitCode = exit_code; @@ -221,6 +223,13 @@ namespace Kernel kcout << "ProcessScheduler:: adding process to team...\r"; + if (process.Leak().GetOwner() == nullptr) + { + // Something went wrong, do not continue, process may be incorrect. + process.Leak().Crash(); + return -kErrorProcessFault; + } + // Create heap according to type of process. if (process.Leak().Kind == PROCESS_HEADER_BLOCK::kAppKind) { @@ -304,6 +313,12 @@ namespace Kernel { auto unwrapped_process = *process.Leak(); + if (unwrapped_process.Parent->Status == ProcessStatus::kKilled) + { + unwrapped_process.Exit(); + continue; + } + // set the current process. mTeam.AsRef() = unwrapped_process; @@ -313,7 +328,7 @@ namespace Kernel unwrapped_process.PTime = static_cast<Int32>(unwrapped_process.Affinity); - kcout << unwrapped_process.Name << ": has been switched to process core.\r"; + kcout << unwrapped_process.Name << ": has been switched to a CPU core.\r"; } else { diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx index f258fa11..a29f153e 100644 --- a/dev/ZKA/Sources/ThreadLocalStorage.cxx +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -21,7 +21,41 @@ using namespace Kernel; -Kernel::Property cTLSEnforceCheck; +namespace Detail +{ + /// \brief Process thread information header. + struct THREAD_HEADER_BLOCK final + { + STATIC constexpr SizeT cMaxLen = 256; + + Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"}; + ProcessStatus fThreadStatus; + Int64 fThreadID; + UIntPtr fCode{0}; + UIntPtr fStack{0}; + UIntPtr fData{0}; + + Void Exit() noexcept + { + this->fThreadStatus = ProcessStatus::kKilled; + } + + UIntPtr GetStack() noexcept + { + return fStack; + } + + UIntPtr GetData() noexcept + { + return fData; + } + + UIntPtr GetPC() noexcept + { + return fCode; + } + }; +} // namespace Detail /** * @brief Checks for cookie inside the TIB. @@ -31,7 +65,8 @@ Kernel::Property cTLSEnforceCheck; Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib) { - if (!the_tib) + if (!the_tib || + !the_tib->f_ThreadRecord) return false; Encoder encoder; @@ -45,22 +80,15 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib) /** * @brief System call implementation of the TLS check. - * @param stackPtr The call frame. + * @param tib_ptr The TIB record. * @return */ EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { if (!tib_ptr) { - if (cTLSEnforceCheck.GetValue() == No) - { - return true; - } - else - { - kcout << "newoskrnl: failing because of an invalid TIB...\r"; - return false; - } + kcout << "newoskrnl: failing because of an invalid TIB...\r"; + return false; } THREAD_INFORMATION_BLOCK* tib_struct = (THREAD_INFORMATION_BLOCK*)tib_ptr; diff --git a/dev/ZKA/Sources/ThreadScheduler.cxx b/dev/ZKA/Sources/ThreadScheduler.cxx deleted file mode 100644 index a38ff9bc..00000000 --- a/dev/ZKA/Sources/ThreadScheduler.cxx +++ /dev/null @@ -1,35 +0,0 @@ -/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
-------------------------------------------- */
-
-#include <KernelKit/ProcessScheduler.hxx>
-#include <KernelKit/MP.hxx>
-
-namespace Kernel::Detail
-{
- /// \brief Process thread information.
- struct THREAD_HEADER_BLOCK final
- {
- STATIC constexpr SizeT cMaxLen = 256;
-
- // Status
- Char fName[cMaxLen] = { "THREAD #0 (PROCESS 0)" };
-
- ProcessStatus fThreadStatus;
-
- // Information
- Int64 fThreadID;
-
- // Code buffers.
- UIntPtr fCode;
- UIntPtr fStack;
- UIntPtr fBSS;
- UIntPtr fProcessHeader;
-
- // CG video buffer and it's size.
- UIntPtr fTGB;
- UIntPtr fTGBSize;
- };
-}
diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx index 565f5197..53cb5e07 100644 --- a/dev/ZKA/Sources/User.cxx +++ b/dev/ZKA/Sources/User.cxx @@ -10,7 +10,7 @@ * ======================================================== */ -#include "KernelKit/LPC.hxx" +#include <KernelKit/LPC.hxx> #include <KernelKit/User.hxx> #include <NewKit/KernelCheck.hxx> #include <KernelKit/FileManager.hxx> @@ -27,7 +27,7 @@ namespace Kernel { namespace Detail { - /// \brief Constructs a token by hashing the password. + /// \brief Constructs a password by hashing the password. /// \param password password to hash. /// \return the hashed password const Int32 cred_construct_token(Char* password, const Char* in_password, User* user, SizeT length) @@ -35,7 +35,7 @@ namespace Kernel if (!password || !user) return -1; - kcout << "Constructing token...\r"; + kcout << "Constructing password...\r"; for (Size i_pass = 0; i_pass < length; ++i_pass) { @@ -47,7 +47,7 @@ namespace Kernel password[i_pass] = cur_chr + (user->IsStdUser() ? cStdUser : cSuperUser); } - kcout << "Done constructing token...\r"; + kcout << "Done constructing password...\r"; return 0; } @@ -68,25 +68,37 @@ namespace Kernel User::~User() = default; - Bool User::TrySave(const Char* password) noexcept + Bool User::TrySave(const Char* password_to_fill) noexcept { - if (!password || - *password == 0) + if (!password_to_fill || + *password_to_fill == 0) return false; - SizeT len = rt_string_len(password); + SizeT len = rt_string_len(password_to_fill); - Char* token = new Char[len]; + Char* password = new Char[len]; - MUST_PASS(token); + MUST_PASS(password); - rt_copy_memory((VoidPtr)password, token, len); - Detail::cred_construct_token(token, password, this, len); + // fill data first, generate hash. + // return false on error. - rt_copy_memory(token, this->fUserToken, rt_string_len(token)); + rt_copy_memory((VoidPtr)password_to_fill, password, len); - delete[] token; - token = nullptr; + if (!Detail::cred_construct_token(password, password_to_fill, this, len)) + { + delete[] password; + password = nullptr; + + return false; + } + + // then store password. + + rt_copy_memory(password, this->fUserToken, rt_string_len(password_to_fill)); + + delete[] password; + password = nullptr; kcout << "newoskrnl: Saved password...\r"; @@ -122,86 +134,4 @@ namespace Kernel { return this->Ring() == RingKind::kRingSuperUser; } - - UserManager* UserManager::The() noexcept - { - static UserManager* view = nullptr; - - if (!view) - view = new UserManager(); - - return view; - } - - Bool UserManager::TryLogIn(User& user, const Char* password, const Char* right_password) noexcept - { - if (!password || - *password == 0) - return false; - - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(password)), user.fUserToken, rt_string_len(password)); - Detail::cred_construct_token(user.fUserToken, password, &user, rt_string_len(password)); - - return this->TryLogIn(user, right_password); - } - - Bool UserManager::TryLogIn(User& user, const Char* token) noexcept - { - if (!user.fUserToken[0]) - { - kcout << "newoskrnl: Incorrect data given.\r"; - - ErrLocal() = kErrorInvalidData; - - return false; - } - - kcout << "newoskrnl: Trying to log-in.\r"; - - if (!token) - { - ErrLocal() = kErrorInvalidCreds; - - kcout << "newoskrnl: Incorrect token.\r"; - return false; - } - else - { - // ================================================== // - // Checks if it matches the current token we have. - // ================================================== // - - Char password[kMaxUserTokenLen] = {0}; - - rt_copy_memory(reinterpret_cast<Char*>(const_cast<Char*>(token)), password, rt_string_len(token)); - Detail::cred_construct_token(password, token, &user, rt_string_len(password)); - - if (rt_string_cmp(password, user.fUserToken, rt_string_len(token))) - { - kcout << "newoskrnl: Incorrect credentials.\r"; - return false; - } - - kcout << "newoskrnl: Credentials are correct, moving on.\r"; - } - - fCurrentUser = &user; - - if (fCurrentUser->Name()[0]) - Kernel::kcout << "newoskrnl: Logged in as: " << fCurrentUser->Name() << Kernel::endl; - else - - Kernel::kcout << "newoskrnl: Logged in as anon. " << Kernel::endl; - return true; - } - - User* UserManager::GetCurrent() noexcept - { - return fCurrentUser; - } - - Void UserManager::TryLogOff() noexcept - { - fCurrentUser = nullptr; - } } // namespace Kernel |
