The Pedigree Project  0.1
User.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "User.h"
21 #include "pedigree/kernel/process/Process.h"
22 #include "pedigree/kernel/process/Thread.h"
23 #include "pedigree/kernel/processor/Processor.h"
24 #include "pedigree/kernel/processor/ProcessorInformation.h"
25 #include "pedigree/kernel/utilities/Iterator.h"
26 #include "pedigree/kernel/utilities/utility.h"
27 
29  size_t uid, String username, String fullName, Group *pGroup, String home,
30  String shell, String password)
31  : m_Uid(uid), m_Username(username), m_FullName(fullName),
32  m_pDefaultGroup(pGroup), m_Home(home), m_Shell(shell),
33  m_Password(password), m_Groups()
34 {
35 }
36 
38 {
39 }
40 
41 void User::join(Group *pGroup)
42 {
43  m_Groups.pushBack(pGroup);
44 }
45 
46 void User::leave(Group *pGroup)
47 {
48  for (List<Group *>::Iterator it = m_Groups.begin(); it != m_Groups.end();
49  it++)
50  {
51  if (*it == pGroup)
52  {
53  m_Groups.erase(it);
54  return;
55  }
56  }
57 }
58 
59 bool User::isMember(Group *pGroup)
60 {
61  if (pGroup == m_pDefaultGroup)
62  return true;
63  for (List<Group *>::Iterator it = m_Groups.begin(); it != m_Groups.end();
64  it++)
65  {
66  if (*it == pGroup)
67  return true;
68  }
69  return false;
70 }
71 
72 bool User::login(String password)
73 {
74  Process *pProcess =
75  Processor::information().getCurrentThread()->getParent();
76 
77  if (password == m_Password)
78  {
79  pProcess->setUser(this);
80  pProcess->setGroup(m_pDefaultGroup);
81 
82  pProcess->setEffectiveUser(this);
83  pProcess->setEffectiveGroup(m_pDefaultGroup);
84  return true;
85  }
86  else
87  return false;
88 }
List< Group * > m_Groups
Definition: User.h:119
void pushBack(const T &value)
Definition: List.h:232
bool isMember(Group *pGroup)
Definition: User.cc:59
Iterator erase(Iterator &Iter)
Definition: List.h:343
virtual ~User()
Definition: User.cc:37
Definition: String.h:49
String m_Password
Definition: User.h:116
static ProcessorInformation & information()
Definition: Processor.cc:45
void leave(Group *pGroup)
Definition: User.cc:46
Group * m_pDefaultGroup
Definition: User.h:110
void setEffectiveUser(User *pUser)
Definition: Process.h:205
Definition: List.h:64
Iterator begin()
Definition: List.h:123
void join(Group *pGroup)
Definition: User.cc:41
bool login(String password)
Definition: User.cc:72
void setUser(User *pUser)
Definition: Process.h:194
void setGroup(Group *pGroup)
Definition: Process.h:216
Iterator end()
Definition: List.h:135
Definition: Group.h:32