summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources/User.cxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-23 17:12:37 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-23 17:13:00 +0200
commitc9fef8cfeae2047b66858385689d448a1ad5b8d0 (patch)
tree1d55c0af46da0bf0db9b32362b404bb6a51f27ef /dev/ZKA/Sources/User.cxx
parent58ec3282634ccf75006043017ceacffed9a4533c (diff)
[FIX+IMP] 'User' login system in order to use the system according to
permissions. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/Sources/User.cxx')
-rw-r--r--dev/ZKA/Sources/User.cxx113
1 files changed, 29 insertions, 84 deletions
diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx
index 620c62f1..62b45e25 100644
--- a/dev/ZKA/Sources/User.cxx
+++ b/dev/ZKA/Sources/User.cxx
@@ -66,71 +66,31 @@ namespace Kernel
rt_copy_memory((VoidPtr)userName, this->fUserName, rt_string_len(userName));
}
- User::~User()
- {
- mm_delete_ke_heap(fUserNodePtr);
- }
+ User::~User() = default;
Bool User::TrySave(const Char* password) noexcept
{
+ if (!password ||
+ *password == 0)
+ return false;
+
SizeT len = rt_string_len(password);
Char* token = new Char[len];
MUST_PASS(token);
- kcout << "Trying to save password...\r";
-
rt_copy_memory((VoidPtr)password, token, len);
Detail::cred_construct_token(token, password, this, len);
- if (NewFilesystemManager::GetMounted())
- {
- NewFilesystemManager* new_fs = (NewFilesystemManager*)NewFilesystemManager::GetMounted();
-
- kcout << "newoskrnl: Opening catalog.\r";
-
- auto node = new_fs->GetParser()->GetCatalog(kUsersFile);
-
- if (!node)
- {
- ErrLocal() = kErrorDiskIsFull;
- return false;
- }
-
- kcout << "newoskrnl: Writing token...\r";
-
- NFS_FORK_STRUCT fork{0};
-
- fork.Kind = kNewFSDataForkKind;
- fork.DataSize = rt_string_len(password);
-
- rt_copy_memory((VoidPtr)this->fUserName, fork.ForkName, rt_string_len(this->fUserName));
- rt_copy_memory((VoidPtr)kUsersFile, fork.CatalogName, rt_string_len(kUsersFile));
-
- fork.DataSize = len;
-
- new_fs->GetParser()->CreateFork(node, fork);
-
- // writing the data fork now. False means a data fork.
- bool wrote = new_fs->GetParser()->WriteCatalog(node, false, reinterpret_cast<VoidPtr>(token), len, this->fUserName);
-
- this->fUserNodePtr = reinterpret_cast<VoidPtr>(node);
- rt_copy_memory(token, this->fUserToken, rt_string_len(token));
-
- delete[] token;
- token = nullptr;
-
- kcout << "newoskrnl: Wrote token?\r";
- return wrote;
- }
-
- kcout << "No filesystem mounted...\r";
+ rt_copy_memory(token, this->fUserToken, rt_string_len(token));
delete[] token;
token = nullptr;
- return false;
+ kcout << "newoskrnl: Saved password...\r";
+
+ return true;
}
bool User::operator==(const User& lhs)
@@ -173,48 +133,30 @@ namespace Kernel
return view;
}
- Bool UserManager::TryLogIn(User& user) noexcept
+ Bool UserManager::TryLogIn(User& user, const Char* password, const Char* right_password) noexcept
{
- if (!user.fUserToken[0] ||
- !user.fUserNodePtr)
- {
- kcout << "newoskrnl: Incorrect data given.\r";
-
- ErrLocal() = kErrorInvalidData;
-
+ if (!password ||
+ *password == 0)
return false;
- }
-
- kcout << "newoskrnl: Trying to log-in.\r";
- kcout << "newoskrnl: reading: " << reinterpret_cast<NFS_CATALOG_STRUCT*>(user.fUserNodePtr)->Name << endl;
-
- NewFilesystemManager* new_fs = (NewFilesystemManager*)NewFilesystemManager::GetMounted();
-
- if (!new_fs)
- {
- ErrLocal() = kErrorInvalidCreds;
- kcout << "newoskrnl: Incorrect filesystem.\r";
-
- 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));
- NFS_CATALOG_STRUCT* node = new_fs->GetParser()->GetCatalog(kUsersFile);
+ return this->TryLogIn(user, right_password);
+ }
- if (!node)
+ Bool UserManager::TryLogIn(User& user, const Char* token) noexcept
+ {
+ if (!user.fUserToken[0])
{
- node = reinterpret_cast<NFS_CATALOG_STRUCT*>(user.fUserNodePtr);
+ kcout << "newoskrnl: Incorrect data given.\r";
- if (!node)
- {
- ErrLocal() = kErrorInvalidCreds;
- kcout << "newoskrnl: Incorrect catalog.\r";
+ ErrLocal() = kErrorInvalidData;
- return false;
- }
+ return false;
}
- auto token = new_fs->GetParser()->ReadCatalog(node, false, rt_string_len(user.fUserToken), user.fUserName);
+ kcout << "newoskrnl: Trying to log-in.\r";
if (!token)
{
@@ -229,11 +171,14 @@ namespace Kernel
// Checks if it matches the current token we have.
// ================================================== //
- if (rt_string_cmp(reinterpret_cast<Char*>(token), user.fUserToken, rt_string_len(user.fUserToken)))
+ 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";
- mm_delete_ke_heap(token);
-
return false;
}