24 #include "kstringhandler.h"
25 #include <tqvaluelist.h>
26 #include <tqstringlist.h>
28 #include <sys/types.h>
40 TQString loginName, fullName;
41 TQString roomNumber, workPhone, homePhone;
44 KUserPrivate() : valid(false) {}
46 KUserPrivate(
long _uid,
48 const TQString &_loginname,
49 const TQString &_fullname,
50 const TQString &_room,
51 const TQString &_workPhone,
52 const TQString &_homePhone,
53 const TQString &_homedir,
54 const TQString &_shell) :
58 loginName(_loginname),
61 workPhone(_workPhone),
62 homePhone(_homePhone),
69 long _uid = ::getuid(), _euid;
71 fillPasswd( ::getpwuid( _euid ) );
73 fillName( ::getenv(
"LOGNAME" ) );
75 fillName( ::getenv(
"USER" ) );
77 fillPasswd( ::getpwuid( _uid ) );
83 fillPasswd( ::getpwuid( uid ) );
87 fillName( name.local8Bit().data() );
113 return uid() == user.
uid();
122 void KUser::fillName(
const char *name) {
123 fillPasswd(name ? ::getpwnam( name ) : 0);
126 void KUser::fillPasswd(
struct passwd *p) {
129 TQStringList gecosList = TQStringList::split(
',', gecos,
true);
131 d =
new KUserPrivate(p->pw_uid,
133 TQString::fromLocal8Bit(p->pw_name),
134 (gecosList.size() > 0) ? gecosList[0] : TQString::null,
135 (gecosList.size() > 1) ? gecosList[1] : TQString::null,
136 (gecosList.size() > 2) ? gecosList[2] : TQString::null,
137 (gecosList.size() > 3) ? gecosList[3] : TQString::null,
138 TQString::fromLocal8Bit(p->pw_dir),
139 TQString::fromLocal8Bit(p->pw_shell));
142 d =
new KUserPrivate();
171 return TQString::null;
178 return TQString::null;
183 return d->roomNumber;
185 return TQString::null;
192 return TQString::null;
199 return TQString::null;
206 return TQString::null;
213 return TQString::null;
217 TQValueList<KUserGroup> result;
219 TQValueList<KUserGroup>::const_iterator it;
220 for ( it = allGroups.begin(); it != allGroups.end(); ++it ) {
221 TQValueList<KUser> users = (*it).users();
222 if ( users.find( *
this ) != users.end()) {
232 TQValueList<KUserGroup>::const_iterator it;
233 for ( it = allGroups.begin(); it != allGroups.end(); ++it ) {
234 TQValueList<KUser> users = (*it).users();
235 if ( users.find( *
this ) != users.end()) {
236 result.append((*it).name());
244 TQValueList<KUser> result;
248 while ((p = getpwent())) {
249 result.append(
KUser(p));
262 while ((p = getpwent())) {
263 result.append(TQString::fromLocal8Bit(p->pw_name));
274 class KUserGroupPrivate :
public TDEShared
280 TQValueList<KUser> users;
282 KUserGroupPrivate() : valid(false) {}
284 KUserGroupPrivate(
long _gid,
285 const TQString & _name,
286 const TQValueList<KUser> & _users):
295 fillGroup(getgrgid(user.
gid()));
299 fillGroup(getgrgid(gid));
303 fillName(name.local8Bit().data());
329 return gid() == group.
gid();
338 void KUserGroup::fillName(
const char *name) {
339 fillGroup(name ? ::getgrnam( name ) : 0);
342 void KUserGroup::fillGroup(
struct group *p) {
344 d =
new KUserGroupPrivate();
349 TQValueList<KUser>
users;
351 char **user = p->gr_mem;
352 for ( ; *user; user++) {
353 KUser kUser(TQString::fromLocal8Bit(*user));
357 d =
new KUserGroupPrivate(p->gr_gid,
358 TQString::fromLocal8Bit(p->gr_name),
378 return TQString::null;
387 TQValueList<KUser>::const_iterator it;
388 for ( it = d->users.begin(); it != d->users.end(); ++it ) {
389 result.append((*it).loginName());
397 TQValueList<KUserGroup> result;
400 while ((g = getgrent())) {
413 while ((g = getgrent())) {
414 result.append(TQString::fromLocal8Bit(g->gr_name));
TQString fullName() const
The full name of the user.
bool isValid() const
Returns wether the group is valid.
Use the effective user id.
long gid() const
Returns the group id of the user.
TQValueList< KUserGroup > groups() const
Returns all groups of the user.
Represents a group on your system.
static TQValueList< KUserGroup > allGroups()
Returns a list of all groups on this system.
long gid() const
Returns the group id of the group.
TQString loginName() const
The login name of the user.
KUserGroup(KUser::UIDMode mode=KUser::UseEffectiveUID)
Create an object from the group of the current user.
static TQString from8Bit(const char *str)
Construct TQString from a c string, guessing whether it is UTF8- or Local8Bit-encoded.
long uid() const
Returns the user id of the user.
bool operator!=(const KUser &user) const
Two KUser objects are not equal if either isValid() is not true or uid() are not identical.
Represents a user on your system.
bool operator==(const KUser &user) const
Two KUser objects are equal if isValid() is true and the uid() are identical.
static TQValueList< KUser > allUsers()
Returns all users of the system.
TQString homeDir(const TQString &user)
Obtain a user's home directory.
static TQStringList allUserNames()
Returns all user names of the system.
Reference counting for shared objects.
bool operator==(const KUserGroup &group) const
Two KUserGroup objects are equal if isValid() is true and gid() are identical.
KUserGroup & operator=(const KUserGroup &group)
Copies a group.
const TQValueList< KUser > & users() const
Returns a list of all users of the group.
TQString roomNumber() const
The user's room number.
TQString shell() const
The path to the user's login shell.
bool isSuperUser() const
Checks whether the user it the super user (root).
TQString workPhone() const
The user's work phone.
TQString homeDir() const
The path to the user's home directory.
TQString homePhone() const
The user's home phone.
KUser & operator=(const KUser &user)
Copies a user.
bool isValid() const
Returns true if the user is valid.
static TQStringList allGroupNames()
Returns a list of all group names on this system.
KUser(UIDMode mode=UseEffectiveUID)
Creates an object that contains information about the current user.
bool operator!=(const KUserGroup &group) const
Two KUserGroup objects are not equal if either isValid() is not true or gid() are not identical...
TQStringList userNames() const
Returns a list of all user login names of the group.
TQString name() const
The name of the group.
TQStringList groupNames() const
Returns all group names of the user.