From 12b2e32abf385b3feb697c442ee79ed8b71d450b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 22 Mar 2026 17:22:16 +0100 Subject: [FEAT] Kernel: Hybrid kernel harderning. Signed-off-by: Amlal El Mahrouss --- src/kernel/KernelKit/DriveMgr.h | 6 +- src/kernel/KernelKit/FileMgr.h | 21 ++--- src/kernel/KernelKit/HardwareThreadScheduler.h | 1 + src/kernel/KernelKit/User.h | 102 +++++++++++++++++++++++++ src/kernel/KernelKit/UserMgr+User.h | 102 ------------------------- src/kernel/KernelKit/UserMgr.h | 2 +- src/kernel/KernelKit/UserProcessScheduler.h | 2 +- 7 files changed, 119 insertions(+), 117 deletions(-) create mode 100644 src/kernel/KernelKit/User.h delete mode 100644 src/kernel/KernelKit/UserMgr+User.h (limited to 'src/kernel/KernelKit') diff --git a/src/kernel/KernelKit/DriveMgr.h b/src/kernel/KernelKit/DriveMgr.h index 76ee5dcf..8b095f05 100644 --- a/src/kernel/KernelKit/DriveMgr.h +++ b/src/kernel/KernelKit/DriveMgr.h @@ -3,8 +3,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel -#ifndef INC_DRIVE_MANAGER_H -#define INC_DRIVE_MANAGER_H +#ifndef KERNELKIT_DRIVEMGR_H +#define KERNELKIT_DRIVEMGR_H /// @file DriveMgr.h /// @brief NeKernel's drive manager. @@ -166,4 +166,4 @@ Void io_drv_input(DriveTrait::DrivePacket pckt); Void io_drv_output(DriveTrait::DrivePacket pckt); } // namespace Kernel -#endif /* ifndef INC_DRIVE_MANAGER_H */ +#endif /* ifndef KERNELKIT_DRIVEMGR_H */ diff --git a/src/kernel/KernelKit/FileMgr.h b/src/kernel/KernelKit/FileMgr.h index 87644e68..06af3c2d 100644 --- a/src/kernel/KernelKit/FileMgr.h +++ b/src/kernel/KernelKit/FileMgr.h @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel -#ifndef INC_FILEMGR_H -#define INC_FILEMGR_H +#ifndef KERNELKIT_FILEMGR_H +#define KERNELKIT_FILEMGR_H /// @file FileMgr.h /// @brief File Manager Subsystem. /// @author Amlal El Mahrouss (amlal@nekernel.org) -//! Include filesystems that NeKernel supports. +//! Include filesystems that the hybrid kernel supports. #include #include #include @@ -352,7 +352,7 @@ class FileStream final { /// @brief Leak MIME. /// @return The MIME. - Char* MIME() { return const_cast(fMime); } + Char* MIME() { return fMime; } enum { kFileMgrRestrictRead = 100, @@ -364,14 +364,15 @@ class FileStream final { }; private: - NodePtr fFile{nullptr}; - Int32 fFileRestrict{kFileMgrRestrictReadBinary}; - const Char* fMime{kFileMimeGeneric}; + NodePtr fFile{nullptr}; + Int32 fFileRestrict{kFileMgrRestrictReadBinary}; + Char* fMime{const_cast(kFileMimeGeneric)}; }; using FileStreamASCII = FileStream; using FileStreamUTF8 = FileStream; -using FileStreamUTF16 = FileStream; +using FileStreamUTF16 = FileStream; +using FileStreamWide = FileStream; typedef UInt64 CursorType; @@ -423,9 +424,9 @@ inline FileStream::FileStream(const Encoding* path, const Encod /// @brief destructor of the file stream. template inline FileStream::~FileStream() { - mm_free_ptr(fFile); + if (fFile) mm_free_ptr(fFile); fFile = nullptr; } } // namespace Kernel -#endif // ifndef INC_FILEMGR_H +#endif // ifndef KERNELKIT_FILEMGR_H diff --git a/src/kernel/KernelKit/HardwareThreadScheduler.h b/src/kernel/KernelKit/HardwareThreadScheduler.h index a9183cd2..43a906d6 100644 --- a/src/kernel/KernelKit/HardwareThreadScheduler.h +++ b/src/kernel/KernelKit/HardwareThreadScheduler.h @@ -12,6 +12,7 @@ /// @note Last Rev Sun 28 Jul CET 2024 /// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM +/// @note Last Rev Sun, March 22, 2026 5:16 PM #if defined(__nekernel_max_cores) /// \note This can be edited at compile-time to specify how many cores can be used by NeKernel. diff --git a/src/kernel/KernelKit/User.h b/src/kernel/KernelKit/User.h new file mode 100644 index 00000000..bae51180 --- /dev/null +++ b/src/kernel/KernelKit/User.h @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/nekernel + +#ifndef KERNELKIT_USERMGR_USER_H +#define KERNELKIT_USERMGR_USER_H + +/* ======================================== + + Revision History: + + 04/03/25: Set users directory as /users/ instead of /usr/ + + ======================================== */ + +#include +#include +#include +#include + +///! We got the MGMT, STD (%s format) and GUEST users, +///! all are used to make authorized operations. +#define kMgmtUser "NEKERNEL/MGMT/%s" +#define kGuestUser "NEKERNEL/GUEST/%s" +#define kStdUser "NEKERNEL/STD/%s" + +#define kUsersDir "/users/" + +#define kMaxUserNameLen (256U) +#define kMaxUserTokenLen (256U) + +namespace Kernel { + +class User; + +enum struct UserRingKind : Int32 { + kRingInvalid = 0, + kRingStdUser = 444, + kRingSuperUser = 666, + kRingGuestUser = 777, + kRingCount = 3, +}; + +using UserPublicKey = Char*; +using UserPublicKeyType = Char; + +/// @brief System User class. +class User final { + public: + User() = delete; + + User(const Int32& sel, const Char* username); + User(const UserRingKind& kind, const Char* username); + + ~User(); + + public: + NE_COPY_DEFAULT(User) + + public: + bool operator==(const User& lhs); + bool operator!=(const User& lhs); + + public: + /// @brief Get software ring + const UserRingKind& Ring(); + + /// @brief Get user name + Char* Name(); + + /// @brief Is he a standard user? + Bool IsStdUser(); + + /// @brief Is she a super user? + Bool IsSuperUser(); + + /// @brief Saves a password from the public key. + Bool Save(const UserPublicKey password); + + /// @brief Checks if a password matches the **password**. + /// @param password the password to check. + Bool Login(const UserPublicKey password); + + private: + UserRingKind mUserRing{UserRingKind::kRingStdUser}; + Char mUserName[kMaxUserNameLen] = {0}; + UInt64 mUserFNV{0UL}; +}; + +/// \brief Alias for user ptr. +using UserPtr = User*; + +/// \brief Current user pointer. +inline UserPtr kCurrentUser = nullptr; + +/// \brief Supervisor pointer. +inline UserPtr kRootUser = nullptr; + +} // namespace Kernel + +#endif /* ifndef KERNELKIT_USERMGR_USER_H */ diff --git a/src/kernel/KernelKit/UserMgr+User.h b/src/kernel/KernelKit/UserMgr+User.h deleted file mode 100644 index bae51180..00000000 --- a/src/kernel/KernelKit/UserMgr+User.h +++ /dev/null @@ -1,102 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/ne-foss-org/nekernel - -#ifndef KERNELKIT_USERMGR_USER_H -#define KERNELKIT_USERMGR_USER_H - -/* ======================================== - - Revision History: - - 04/03/25: Set users directory as /users/ instead of /usr/ - - ======================================== */ - -#include -#include -#include -#include - -///! We got the MGMT, STD (%s format) and GUEST users, -///! all are used to make authorized operations. -#define kMgmtUser "NEKERNEL/MGMT/%s" -#define kGuestUser "NEKERNEL/GUEST/%s" -#define kStdUser "NEKERNEL/STD/%s" - -#define kUsersDir "/users/" - -#define kMaxUserNameLen (256U) -#define kMaxUserTokenLen (256U) - -namespace Kernel { - -class User; - -enum struct UserRingKind : Int32 { - kRingInvalid = 0, - kRingStdUser = 444, - kRingSuperUser = 666, - kRingGuestUser = 777, - kRingCount = 3, -}; - -using UserPublicKey = Char*; -using UserPublicKeyType = Char; - -/// @brief System User class. -class User final { - public: - User() = delete; - - User(const Int32& sel, const Char* username); - User(const UserRingKind& kind, const Char* username); - - ~User(); - - public: - NE_COPY_DEFAULT(User) - - public: - bool operator==(const User& lhs); - bool operator!=(const User& lhs); - - public: - /// @brief Get software ring - const UserRingKind& Ring(); - - /// @brief Get user name - Char* Name(); - - /// @brief Is he a standard user? - Bool IsStdUser(); - - /// @brief Is she a super user? - Bool IsSuperUser(); - - /// @brief Saves a password from the public key. - Bool Save(const UserPublicKey password); - - /// @brief Checks if a password matches the **password**. - /// @param password the password to check. - Bool Login(const UserPublicKey password); - - private: - UserRingKind mUserRing{UserRingKind::kRingStdUser}; - Char mUserName[kMaxUserNameLen] = {0}; - UInt64 mUserFNV{0UL}; -}; - -/// \brief Alias for user ptr. -using UserPtr = User*; - -/// \brief Current user pointer. -inline UserPtr kCurrentUser = nullptr; - -/// \brief Supervisor pointer. -inline UserPtr kRootUser = nullptr; - -} // namespace Kernel - -#endif /* ifndef KERNELKIT_USERMGR_USER_H */ diff --git a/src/kernel/KernelKit/UserMgr.h b/src/kernel/KernelKit/UserMgr.h index 16ca79b6..7fc2b635 100644 --- a/src/kernel/KernelKit/UserMgr.h +++ b/src/kernel/KernelKit/UserMgr.h @@ -6,6 +6,6 @@ #ifndef KERNELKIT_USERMGR_H #define KERNELKIT_USERMGR_H -#include +#include #endif \ No newline at end of file diff --git a/src/kernel/KernelKit/UserProcessScheduler.h b/src/kernel/KernelKit/UserProcessScheduler.h index 8c7a4afa..1318c7f6 100644 --- a/src/kernel/KernelKit/UserProcessScheduler.h +++ b/src/kernel/KernelKit/UserProcessScheduler.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include //////////////////////////////////////////////////// -- cgit v1.2.3