KDECore
Go to the documentation of this file.
24 #include <QtCore/QMutableStringListIterator>
25 #include <QtCore/QDir>
32 class KUser::Private :
public KShared
41 Private() :
uid(uid_t(-1)), gid(gid_t(-1)) {}
42 Private(
const char *name) :
uid(uid_t(-1)), gid(gid_t(-1))
44 fillPasswd(name ? ::getpwnam( name ) : 0);
46 Private(
const passwd *p) :
uid(uid_t(-1)), gid(gid_t(-1))
51 void fillPasswd(
const passwd *p)
54 QString gecos = QString::fromLocal8Bit(p->pw_gecos);
55 QStringList gecosList = gecos.split(QLatin1Char(
','));
57 while (gecosList.size() < 4)
62 loginName = QString::fromLocal8Bit(p->pw_name);
67 homeDir = QString::fromLocal8Bit(p->pw_dir);
68 shell = QString::fromLocal8Bit(p->pw_shell);
76 uid_t _uid = ::getuid(), _euid;
78 d =
new Private( ::getpwuid( _euid ) );
80 d =
new Private( qgetenv(
"LOGNAME" ) );
82 d =
new Private( qgetenv(
"USER" ) );
84 d =
new Private( ::getpwuid( _uid ) );
90 : d(new Private( ::getpwuid( _uid ) ))
95 : d(new Private( name.toLocal8Bit().data() ))
100 : d(new Private( name ))
105 : d(new Private( p ))
121 return (
uid() == user.
uid()) && (
uid() != uid_t(-1));
125 return (
uid() != user.
uid()) || (
uid() == uid_t(-1));
129 return uid() != uid_t(-1);
136 K_GID KUser::gid()
const {
148 #ifndef KDE_NO_DEPRECATED
150 return d->properties[
FullName].toString();
160 QString pathToFaceIcon(
homeDir() + QDir::separator() + QLatin1String(
".face.icon"));
162 if (QFile::exists(pathToFaceIcon)) {
163 return pathToFaceIcon;
177 for ( it = allGroups.begin(); it != allGroups.end(); ++it ) {
179 if ( users.contains(*
this) ) {
190 for ( it = allGroups.begin(); it != allGroups.end(); ++it ) {
192 if ( users.contains(*
this) ) {
193 result.append((*it).name());
201 return d->properties.value(which);
209 while ((p = getpwent())) {
210 result.append(
KUser(p));
223 while ((p = getpwent())) {
224 result.append(QString::fromLocal8Bit(p->pw_name));
234 class KUserGroup::Private :
public KShared
241 Private() : gid(gid_t(-1)) {}
242 Private(
const char *_name) : gid(gid_t(-1))
244 fillGroup(_name ? ::getgrnam( _name ) : 0);
254 name = QString::fromLocal8Bit(p->gr_name);
255 for (
char **user = p->gr_mem; *user; user++)
263 d =
new Private(getgrgid(
KUser(mode).gid()));
267 : d(new Private(getgrgid(_gid)))
272 : d(new Private(_name.toLocal8Bit().data()))
277 : d(new Private(_name))
297 return (gid() ==
group.gid()) && (gid() != gid_t(-1));
301 return (gid() != user.gid()) || (gid() == gid_t(-1));
305 return gid() != gid_t(-1);
308 K_GID KUserGroup::gid()
const {
323 for ( it = d->users.begin(); it != d->users.end(); ++it ) {
324 result.append((*it).loginName());
333 while ((g = getgrent())) {
346 while ((g = getgrent())) {
347 result.append(QString::fromLocal8Bit(g->gr_name));
static QStringList allGroupNames()
Returns a list of all group names on this system.
QStringList userNames() const
Returns a list of all user login names of the group.
QString fullName() const
The full name of the user.
KUserGroup(const QString &name)
Create an object from a group name.
QList< KUserGroup > groups() const
Returns all groups of the user.
bool isValid() const
Returns whether the group is valid.
K_UID uid() const
Returns the user id of the user.
QStringList groupNames() const
Returns all group names of the user.
@ UseEffectiveUID
Use the effective user id.
bool operator!=(const KUserGroup &group) const
Two KUserGroup objects are not equal if their gid()s are not identical.
Represents a group on your system.
static QList< KUser > allUsers()
Returns all users of the system.
bool isValid() const
Returns true if the user is valid.
QString name() const
The name of the group.
bool isSuperUser() const
Checks whether the user is the super user (root).
QString loginName() const
The login name of the user.
Represents a user on your system.
QVariant property(UserProperty which) const
Returns an extended property.
bool operator==(const KUserGroup &group) const
Two KUserGroup objects are equal if their gid()s are identical.
static QStringList allUserNames()
Returns all user names of the system.
QList< KUser > users() const
Returns a list of all users of the group.
bool operator!=(const KUser &user) const
Two KUser objects are not equal if uid() are not identical.
KUser & operator=(const KUser &user)
Copies a user.
KUser(UIDMode mode=UseEffectiveUID)
Creates an object that contains information about the current user.
QString faceIconPath() const
The path to the user's face file.
bool operator==(const KUser &user) const
Two KUser objects are equal if the uid() are identical.
QString homeDir() const
The path to the user's home directory.
static QList< KUserGroup > allGroups()
Returns a list of all groups on this system.
KUserGroup & operator=(const KUserGroup &group)
Copies a group.
QString shell() const
The path to the user's login shell.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jan 30 2020 00:00:00 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.