blob: 92acba977fc5f77b02ed1806e18e566ba029f659 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* ========================================================
*
* Kernel
* Copyright ZKA Technologies, all rights reserved.
*
* File: User.cpp
* Purpose: Permission selectors.
*
* ========================================================
*/
#include <KernelKit/User.hxx>
#include <NewKit/KernelCheck.hpp>
#include <KernelKit/FileManager.hpp>
#include <KernelKit/ProcessScheduler.hxx>
/// bugs 0
namespace Kernel
{
User::User(const Int32& sel, const Char* userName)
: fRing((RingKind)sel)
{
MUST_PASS(sel >= 0);
auto view = StringBuilder::Construct(userName);
this->fUserName += view.Leak().Leak();
}
User::User(const RingKind& ringKind, const Char* userName)
: fRing(ringKind)
{
auto view = StringBuilder::Construct(userName);
this->fUserName += view.Leak().Leak();
}
User::~User() = default;
bool User::operator==(const User& lhs)
{
return lhs.fRing == this->fRing;
}
bool User::operator!=(const User& lhs)
{
return lhs.fRing != this->fRing;
}
StringView& User::Name() noexcept
{
return this->fUserName;
}
const RingKind& User::Ring() noexcept
{
return this->fRing;
}
Bool User::IsStdUser() noexcept
{
return this->Ring() == RingKind::kRingStdUser;
}
Bool User::IsSuperUser() noexcept
{
return this->Ring() == RingKind::kRingSuperUser;
}
UserView* UserView::The() noexcept
{
UserView* view = nullptr;
if (!view)
view = new UserView();
return view;
}
Void UserView::LogIn(User* user, const Char* password) noexcept
{
if (!password ||
!user)
{
ErrLocal() = kErrorInvalidData;
return;
}
FileStreamUTF8 file(kUsersFile, "rb");
auto token = file.Read(password);
if (!token)
{
ErrLocal() = kErrorInvalidCreds;
kcout << "newoskrnl: Incorrect credentials.\r";
return;
}
user->fUserToken = token;
if (fCurrentUser)
{
if (!fLastLoggedOffUser)
{
fLastLoggedOffUser = fCurrentUser;
}
else
{
this->LogOff();
}
}
fCurrentUser = user;
Kernel::kcout << "newoskrnl: logged in as: " << fCurrentUser->Name().CData() << Kernel::endl;
}
Void UserView::LogOff() noexcept
{
if (!fCurrentUser)
return;
// an illegal operation just occured, we can't risk more.
if (fCurrentUser == fRootUser)
{
ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
if (fLastLoggedOffUser)
delete fLastLoggedOffUser;
fLastLoggedOffUser = nullptr;
fLastLoggedOffUser = fCurrentUser;
}
} // namespace Kernel
|