24#include <QtCore/QMutableStringListIterator>
32class 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);
136K_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));
234class 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);
246 Private(const ::group *p) : gid(gid_t(-1))
251 void fillGroup(const ::group *p) {
254 name = QString::fromLocal8Bit(p->gr_name);
255 for (
char **user = p->gr_mem; *user; user++)
256 users.append(
KUser(*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);
308K_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));
Represents a group on your system.
QList< KUser > users() const
Returns a list of all users of the group.
QString name() const
The name of the group.
KUserGroup(const QString &name)
Create an object from a group name.
bool isValid() const
Returns whether the group is valid.
bool operator!=(const KUserGroup &group) const
Two KUserGroup objects are not equal if their gid()s are not identical.
bool operator==(const KUserGroup &group) const
Two KUserGroup objects are equal if their gid()s are identical.
static QStringList allGroupNames()
Returns a list of all group names on this system.
static QList< KUserGroup > allGroups()
Returns a list of all groups on this system.
QStringList userNames() const
Returns a list of all user login names of the group.
KUserGroup & operator=(const KUserGroup &group)
Copies a group.
Represents a user on your system.
QString faceIconPath() const
The path to the user's face file.
KUser(UIDMode mode=UseEffectiveUID)
Creates an object that contains information about the current user.
QString homeDir() const
The path to the user's home directory.
QStringList groupNames() const
Returns all group names of the user.
QVariant property(UserProperty which) const
Returns an extended property.
QString shell() const
The path to the user's login shell.
static QList< KUser > allUsers()
Returns all users of the system.
bool operator!=(const KUser &user) const
Two KUser objects are not equal if uid() are not identical.
static QStringList allUserNames()
Returns all user names of the system.
QList< KUserGroup > groups() const
Returns all groups of the user.
bool operator==(const KUser &user) const
Two KUser objects are equal if the uid() are identical.
K_UID uid() const
Returns the user id of the user.
QString loginName() const
The login name of the user.
QString fullName() const
The full name of the user.
bool isValid() const
Returns true if the user is valid.
bool isSuperUser() const
Checks whether the user is the super user (root).
KUser & operator=(const KUser &user)
Copies a user.
@ UseEffectiveUID
Use the effective user id.
QString homeDir(const QString &user)