diff options
Diffstat (limited to 'dev/kernel')
| -rw-r--r-- | dev/kernel/CompilerKit/Version.h | 8 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/User.h | 10 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS+FileSystemParser.cc | 7 | ||||
| -rw-r--r-- | dev/kernel/src/User.cc | 77 |
4 files changed, 30 insertions, 72 deletions
diff --git a/dev/kernel/CompilerKit/Version.h b/dev/kernel/CompilerKit/Version.h index 93378863..4250531a 100644 --- a/dev/kernel/CompilerKit/Version.h +++ b/dev/kernel/CompilerKit/Version.h @@ -2,8 +2,8 @@ #pragma once -#define BOOTLOADER_VERSION "v0.0.1" -#define KERNEL_VERSION "v0.0.1" +#define BOOTLOADER_VERSION "v0.0.2-bootz" +#define KERNEL_VERSION "v0.0.2-krnl" -#define BOOTLOADER_VERSION_BCD 0x0001 -#define KERNEL_VERSION_BCD 0x0001 +#define BOOTLOADER_VERSION_BCD (0x0002) +#define KERNEL_VERSION_BCD (0x0002) diff --git a/dev/kernel/KernelKit/User.h b/dev/kernel/KernelKit/User.h index 250b1dfc..2a12e41e 100644 --- a/dev/kernel/KernelKit/User.h +++ b/dev/kernel/KernelKit/User.h @@ -22,11 +22,11 @@ ///! We got the Super, Standard (%s format) and Guest user, ///! all are used to make authorization operations on the OS. -#define kSuperUser "OS AUTHORITY/SUPER/%s" +#define kSuperUser "OS AUTHORITY/MGMT/%s" #define kGuestUser "OS AUTHORITY/GUEST/%s" #define kStdUser "OS AUTHORITY/STD/%s" -#define kUsersDir "/user/" +#define kUsersDir "/users/" #define kMaxUserNameLen (256U) #define kMaxUserTokenLen (256U) @@ -45,7 +45,7 @@ enum class UserRingKind { typedef Char* UserPublicKey; typedef Char UserPublicKeyType; -/// @brief User class. +/// @brief System User class. class User final { public: User() = delete; @@ -80,12 +80,12 @@ class User final { /// @brief Checks if a password matches the **password**. /// @param password the password to check. - Bool Matches(const UserPublicKey password) noexcept; + Bool Login(const UserPublicKey password) noexcept; private: UserRingKind mUserRing{UserRingKind::kRingStdUser}; Char mUserName[kMaxUserNameLen] = {0}; - Char mUserKey[kMaxUserTokenLen] = {0}; + UInt64 mUserFNV{0UL}; }; } // namespace Kernel diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index dae69a21..3622e711 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -878,7 +878,7 @@ namespace Kernel::NeFS { /// @brief Construct NeFS drives. /***********************************************************************************/ Boolean fs_init_nefs(Void) noexcept { - kout << "Creating main disk...\r"; + kout << "Creating HeFS disk...\r"; kMountpoint.A() = io_construct_main_drive(); @@ -886,9 +886,8 @@ Boolean fs_init_nefs(Void) noexcept { ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main disk cannot be mounted."); NeFileSystemParser parser; - parser.Format(&kMountpoint.A(), 0, kNeFSVolumeName); - - return YES; + + return parser.Format(&kMountpoint.A(), 0, kNeFSVolumeName); } } // namespace Kernel::NeFS diff --git a/dev/kernel/src/User.cc b/dev/kernel/src/User.cc index 3e6aeeba..c1a5ca94 100644 --- a/dev/kernel/src/User.cc +++ b/dev/kernel/src/User.cc @@ -29,20 +29,23 @@ namespace Detail { /// \param password password to hash. /// \return the hashed password //////////////////////////////////////////////////////////// - Int32 user_standard_token_generator(Char* password, const Char* in_password, User* user, - SizeT length) { + STATIC UInt64 user_fnv_generator(const Char* password, User* user) { if (!password || !user) return 1; if (*password == 0) return 1; - kout << "user_standard_token_generator: Hashing user password...\r"; + kout << "user_fnv_generator: Hashing user password...\r"; - for (SizeT i_pass = 0UL; i_pass < length; ++i_pass) { - Char cur_chr = in_password[i_pass]; + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; + const UInt64 FNV_PRIME = 0x100000001b3ULL; - password[i_pass] = cur_chr | (user->IsStdUser() ? kStdUserType : kSuperUserType); + UInt64 hash = FNV_OFFSET_BASIS; + + while (*password) { + hash ^= (Utf8Char) (*password++); + hash *= FNV_PRIME; } - kout << "user_standard_token_generator: Hashed user password.\r"; + kout << "user_fnv_generator: Hashed user password.\r"; return 0; } @@ -68,70 +71,26 @@ User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(rin //////////////////////////////////////////////////////////// User::~User() = default; -Bool User::Save(const UserPublicKey password_to_fill) noexcept { - if (!password_to_fill || *password_to_fill == 0) return No; - - SizeT len = rt_string_len(password_to_fill); - - UserPublicKey password = new UserPublicKeyType[len]; - - MUST_PASS(password); - - rt_set_memory(password, 0, len); - - // fill data first, generate hash. - // return false on error. - - rt_copy_memory((VoidPtr) password_to_fill, password, len); - - if (!Detail::user_standard_token_generator(password, password_to_fill, this, len)) { - delete[] password; - password = nullptr; - - return No; - } - - // then store password. - - rt_copy_memory(password, this->mUserKey, rt_string_len(password_to_fill)); +Bool User::Save(const UserPublicKey password) noexcept { + if (!password || *password == 0) return No; - delete[] password; - password = nullptr; + this->mUserFNV = Detail::user_fnv_generator(password, this); kout << "User::Save: Saved password successfully...\r"; return Yes; } -Bool User::Matches(const UserPublicKey password_to_fill) noexcept { - if (!password_to_fill || *password_to_fill) return No; - - SizeT len = rt_string_len(password_to_fill); - - Char* password = new Char[len]; - MUST_PASS(password); - - // fill data first, generate hash. - // return false on error. - - rt_copy_memory((VoidPtr) password_to_fill, password, len); - - if (!Detail::user_standard_token_generator(password, password_to_fill, this, len)) { - delete[] password; - password = nullptr; - - return No; - } - - kout << "User::Matches: Validating hashed passwords...\r"; +Bool User::Login(const UserPublicKey password) noexcept { + if (!password || !*password) return No; // now check if the password matches. - if (rt_string_cmp(password, this->mUserKey, rt_string_len(this->mUserKey)) == 0) { - kout << "User::Matches: Password matches.\r"; + if (this->mUserFNV == Detail::user_fnv_generator(password, this)) { + kout << "User::Login: Password matches.\r"; return Yes; } - kout << "User::Matches: Password doesn't match.\r"; + kout << "User::Login: Password doesn't match.\r"; return No; } |
