mirror of
https://github.com/KDE/krfb
synced 2026-07-01 15:31:19 -07:00
-s/fromUtf8/fromLocal8Bit/
-protect against self assignment -use an enum instead of a bool in the ctor (ettrich rule) svn path=/trunk/kdenetwork/krfb/; revision=211758
This commit is contained in:
@@ -63,8 +63,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
KUser::KUser(bool effective) {
|
||||
fillPasswd(getpwuid(effective ? geteuid() : getuid()));
|
||||
KUser::KUser(UIDMode mode) {
|
||||
fillPasswd(getpwuid((mode == UseEffectiveUID) ? geteuid() : getuid()));
|
||||
}
|
||||
|
||||
KUser::KUser(long uid) {
|
||||
@@ -88,6 +88,9 @@ KUser::KUser(const KUser &user) {
|
||||
}
|
||||
|
||||
KUser& KUser::operator =(const KUser& user) {
|
||||
if ( this == &user )
|
||||
return *this;
|
||||
|
||||
delete d;
|
||||
d = new KUserPrivate(user.uid(),
|
||||
user.gid(),
|
||||
@@ -112,18 +115,18 @@ bool KUser::operator ==(const KUser& user) {
|
||||
|
||||
void KUser::fillPasswd(struct passwd *p) {
|
||||
if (p) {
|
||||
QString gecos = QString::fromUtf8(p->pw_gecos);
|
||||
QString gecos = QString::fromLocal8Bit(p->pw_gecos);
|
||||
QStringList gecosList = QStringList::split(',', gecos, true);
|
||||
|
||||
d = new KUserPrivate(p->pw_uid,
|
||||
p->pw_gid,
|
||||
QString::fromUtf8(p->pw_name),
|
||||
QString::fromLocal8Bit(p->pw_name),
|
||||
(gecosList.size() > 0) ? gecosList[0] : QString::null,
|
||||
(gecosList.size() > 1) ? gecosList[1] : QString::null,
|
||||
(gecosList.size() > 2) ? gecosList[2] : QString::null,
|
||||
(gecosList.size() > 3) ? gecosList[3] : QString::null,
|
||||
QString::fromUtf8(p->pw_dir),
|
||||
QString::fromUtf8(p->pw_shell));
|
||||
QString::fromLocal8Bit(p->pw_dir),
|
||||
QString::fromLocal8Bit(p->pw_shell));
|
||||
}
|
||||
else
|
||||
d = new KUserPrivate();
|
||||
|
||||
@@ -41,17 +41,20 @@ struct passwd;
|
||||
class KUser {
|
||||
|
||||
public:
|
||||
|
||||
enum UIDMode{ UseEffectiveUID, UseRealUserID };
|
||||
|
||||
/**
|
||||
* Creates an object that contains information about the current user.
|
||||
* (as returned by getuid(2) or geteuid(2)).
|
||||
* @param effective if true, returns the effective user. If false, the
|
||||
* real user will be returned. The difference is that when the
|
||||
* user uses a command like "su", this will change the effective
|
||||
* user, but not the real user. Use the effective user when
|
||||
* @param If UseEffectiveUID it passed the effective user is returned.
|
||||
* Otherwise the real user will be returned. The difference is that
|
||||
* that when the user uses a command like "su", this will change the
|
||||
* effective user, but not the real user. Use the effective user when
|
||||
* checking permissions, and the real user for displaying
|
||||
* information about the user
|
||||
*/
|
||||
KUser(bool effective = false);
|
||||
KUser(UIDMode mode = UseEffectiveUID);
|
||||
|
||||
/**
|
||||
* Creates an object for the user with the given user id.
|
||||
|
||||
Reference in New Issue
Block a user