From 0c43e344918569474e1460876105c9f1eb43efa8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 24 Mar 2026 12:25:55 +0100 Subject: [FEAT] Kernel: UTF-8 usage in UserMgr. Signed-off-by: Amlal El Mahrouss --- src/kernel/KernelKit/Semaphore.h | 7 +++++++ src/kernel/KernelKit/User.h | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/kernel/KernelKit') diff --git a/src/kernel/KernelKit/Semaphore.h b/src/kernel/KernelKit/Semaphore.h index bb6b9ba9..4dc9a454 100644 --- a/src/kernel/KernelKit/Semaphore.h +++ b/src/kernel/KernelKit/Semaphore.h @@ -29,6 +29,7 @@ using SemaphoreArr = UInt64[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) { + if (!sem) return false; return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0; } @@ -36,6 +37,8 @@ inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) { /// @param sem /// @return inline bool rtl_sem_release(SemaphoreArr& sem) { + if (!sem) return false; + sem[kSemaphoreOwnerIndex] = 0; sem[kSemaphoreCountIndex] = 0; @@ -47,6 +50,8 @@ inline bool rtl_sem_release(SemaphoreArr& sem) { /// @param owner the owner to set, could be anything identifitable. /// @return inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) { + if (!sem) return false; + if (!owner) { err_global_get() = kErrorInvalidData; return false; // Invalid owner, return false and set KPC. @@ -65,6 +70,8 @@ inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) { /// @return inline bool rtl_sem_wait(SemaphoreArr& sem, const UInt64& owner, const UInt64& timeout, bool& condition) { + if (!sem) return false; + if (!rtl_sem_is_valid(sem, owner)) { return false; } diff --git a/src/kernel/KernelKit/User.h b/src/kernel/KernelKit/User.h index bae51180..6711bce7 100644 --- a/src/kernel/KernelKit/User.h +++ b/src/kernel/KernelKit/User.h @@ -42,16 +42,16 @@ enum struct UserRingKind : Int32 { kRingCount = 3, }; -using UserPublicKey = Char*; -using UserPublicKeyType = Char; +using UserPublicKey = Char8*; +using UserPublicKeyType = Char8; /// @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(const Int32& sel, const UserPublicKeyType* username); + User(const UserRingKind& kind, const UserPublicKeyType* username); ~User(); -- cgit v1.2.3 From efdde41a4421fc44027f4b12d84adcb13adf11e0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 24 Mar 2026 12:30:56 +0100 Subject: [FEAT] Add User AgeAuth API. Signed-off-by: Amlal El Mahrouss --- src/kernel/KernelKit/User.h | 5 +++++ src/kernel/src/User.cpp | 2 ++ src/libSystem/SystemKit/System.h | 6 ++++++ 3 files changed, 13 insertions(+) (limited to 'src/kernel/KernelKit') diff --git a/src/kernel/KernelKit/User.h b/src/kernel/KernelKit/User.h index 6711bce7..cc64bd1c 100644 --- a/src/kernel/KernelKit/User.h +++ b/src/kernel/KernelKit/User.h @@ -82,10 +82,15 @@ class User final { /// @param password the password to check. Bool Login(const UserPublicKey password); + /// @brief Returns whether the user is an adult or not. + Bool IsAdult(); + private: UserRingKind mUserRing{UserRingKind::kRingStdUser}; Char mUserName[kMaxUserNameLen] = {0}; UInt64 mUserFNV{0UL}; + Bool mUserIsAdult{NO}; + }; /// \brief Alias for user ptr. diff --git a/src/kernel/src/User.cpp b/src/kernel/src/User.cpp index daaf27a4..6fd2e7b3 100644 --- a/src/kernel/src/User.cpp +++ b/src/kernel/src/User.cpp @@ -66,6 +66,8 @@ User::User(const UserRingKind& ring_kind, const UserPublicKeyType* user_name) //////////////////////////////////////////////////////////// User::~User() = default; +Bool User::IsAdult() { return mUserIsAdult; } + Bool User::Save(const UserPublicKey password) { if (!password || *password == 0) return No; diff --git a/src/libSystem/SystemKit/System.h b/src/libSystem/SystemKit/System.h index 324aae5c..7e4a9ae6 100644 --- a/src/libSystem/SystemKit/System.h +++ b/src/libSystem/SystemKit/System.h @@ -408,4 +408,10 @@ IMPORT_C SInt32 SemWait(_Input SemaphoreRef sem); /// @brief Close a semaphore. IMPORT_C SInt32 SemClose(_Input SemaphoreRef sem); +// ------------------------------------------------------------------------------------------ // +// @brief User AgeAuth API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C SInt32 UserIsAdult(_Input SInt32 uid); + #endif // ifndef SYSTEMKIT_SYSTEM_H -- cgit v1.2.3