BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / User.cpp
blob2ae6645764402760d09c1ba2f3230fa1736876bd
1 /*
2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <package/User.h>
9 #include <ctype.h>
11 #include <package/hpkg/PackageInfoAttributeValue.h>
14 namespace BPackageKit {
17 BUser::BUser()
19 fName(),
20 fRealName(),
21 fHome(),
22 fShell(),
23 fGroups()
28 BUser::BUser(const BHPKG::BUserData& userData)
30 fName(userData.name),
31 fRealName(userData.realName),
32 fHome(userData.home),
33 fShell(userData.shell),
34 fGroups()
36 for (size_t i = 0; i < userData.groupCount; i++)
37 fGroups.Add(userData.groups[i]);
41 BUser::BUser(const BString& name, const BString& realName, const BString& home,
42 const BString& shell, const BStringList& groups)
44 fName(name),
45 fRealName(realName),
46 fHome(home),
47 fShell(shell),
48 fGroups(groups)
53 BUser::~BUser()
58 status_t
59 BUser::InitCheck() const
61 if (fName.IsEmpty())
62 return B_NO_INIT;
63 if (!IsValidUserName(fName))
64 return B_BAD_VALUE;
65 return B_OK;
69 const BString&
70 BUser::Name() const
72 return fName;
76 const BString&
77 BUser::RealName() const
79 return fRealName;
83 const BString&
84 BUser::Home() const
86 return fHome;
90 const BString&
91 BUser::Shell() const
93 return fShell;
97 const BStringList&
98 BUser::Groups() const
100 return fGroups;
104 status_t
105 BUser::SetTo(const BString& name, const BString& realName, const BString& home,
106 const BString& shell, const BStringList& groups)
108 fName = name;
109 fRealName = realName;
110 fHome = home;
111 fShell = shell;
112 fGroups = groups;
114 return fGroups.CountStrings() == groups.CountStrings() ? B_OK : B_NO_MEMORY;
118 /*static*/ bool
119 BUser::IsValidUserName(const char* name)
121 if (name[0] == '\0')
122 return false;
124 for (; name[0] != '\0'; name++) {
125 if (!isalnum(name[0]) && name[0] != '_')
126 return false;
129 return true;
133 } // namespace BPackageKit