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
28#include "Group.h"
29
30User::User(size_t uid, const String& username, const String& fullName, Group* pGroup,
31 const String& home, const String& shell)
32 : m_Uid(uid),
33 m_Username(username),
34 m_FullName(fullName),
35 m_pDefaultGroup(pGroup),
36 m_Home(home),
37 m_Shell(shell),
38 m_Groups() {}
39
41
42void User::join(Group* pGroup) {
43 m_Groups.pushBack(pGroup);
44}
45
46void User::leave(Group* pGroup) {
47 for (List<Group*>::Iterator it = m_Groups.begin(); it != m_Groups.end(); it++) {
48 if (*it == pGroup) {
49 m_Groups.erase(it);
50 return;
51 }
52 }
53}
54
55bool User::isMember(Group* pGroup) {
56 if (pGroup == m_pDefaultGroup)
57 return true;
58 for (List<Group*>::Iterator it = m_Groups.begin(); it != m_Groups.end(); it++) {
59 if (*it == pGroup)
60 return true;
61 }
62 return false;
63}
64
66 uint32_t groups[FilesystemCredentials::MaximumGroups] = {};
67 size_t count = 0;
68 for (Group* group : m_Groups) {
69 if (!group || group->getId() >= UINT32_MAX || count == FilesystemCredentials::MaximumGroups)
70 return false;
71 groups[count++] = group->getId();
72 }
73 return Processor::information().getCurrentThread()->getParent()->installUserIdentity(
74 this, m_pDefaultGroup, groups, count);
75}
Definition Group.h:32
Iterator begin()
Definition List.h:122
::Iterator< T, node_t > Iterator
Definition List.h:67
Iterator end()
Definition List.h:132
static ProcessorInformation & information()
void join(Group *pGroup)
Definition User.cc:42
bool login()
Definition User.cc:65
bool isMember(Group *pGroup)
Definition User.cc:55
virtual ~User()
Definition User.cc:40
void leave(Group *pGroup)
Definition User.cc:46
List< Group * > m_Groups
Definition User.h:104
Group * m_pDefaultGroup
Definition User.h:98
Iterator erase(Iterator &Iter)
Definition List.h:352
void pushBack(const T &value)
Definition List.h:216