diff --git a/TODO b/TODO index e2cdd2e3..7c9736ac 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,7 @@ -For 3.1: -- write SLP service template for remote desktop protocols - (documentation) For 3.2: -- set desktop name (username@hostname) -- apply multi-desktop patch +- write SLP service template for remote desktop protocols + (documentation) - trayicon mouse-over text - when krfb is started with URL arguments and without connection quality, add some kind of smart algorithm to determine whether the diff --git a/krfb/rfbcontroller.cc b/krfb/rfbcontroller.cc index 192461e0..3c9a3e97 100644 --- a/krfb/rfbcontroller.cc +++ b/krfb/rfbcontroller.cc @@ -24,6 +24,7 @@ */ #include "rfbcontroller.h" +#include "kuser.h" #include #include @@ -324,6 +325,11 @@ RFBController::RFBController(Configuration *c) : asyncQueue.setAutoDelete(true); KeyboardEvent::initKeycodes(); + + char hostname[256]; + if (gethostname(hostname, 256)) + hostname[0] = 0; + desktopName = QString(i18n("%1@%2 (shared desktop)")).arg(KUser().loginName()).arg(hostname); } RFBController::~RFBController() @@ -395,6 +401,8 @@ void RFBController::startServer(int inetdFd, bool xtestGrab) server->newClientHook = newClientHook; server->passwordCheck = passwordCheck; + server->desktopName = desktopName.latin1(); + if (!myCursor) myCursor = rfbMakeXCursor(19, 19, (char*) cur, (char*) mask); server->cursor = myCursor; diff --git a/krfb/rfbcontroller.h b/krfb/rfbcontroller.h index 9c0b9499..921b9ba7 100644 --- a/krfb/rfbcontroller.h +++ b/krfb/rfbcontroller.h @@ -169,6 +169,8 @@ private: XUpdateScanner *scanner; ConnectionDialog dialog; + QString desktopName; + rfbScreenInfoPtr server; XImage *framebufferImage; diff --git a/srvloc/kuser.cpp b/srvloc/kuser.cpp index f71d1aec..02ce2bf9 100644 --- a/srvloc/kuser.cpp +++ b/srvloc/kuser.cpp @@ -49,8 +49,8 @@ public: }; -KUser::KUser() { - fillPasswd(getpwuid(getuid())); +KUser::KUser(bool effective) { + fillPasswd(getpwuid(effective ? geteuid() : getuid())); } KUser::KUser(long uid) { @@ -61,6 +61,28 @@ KUser::KUser(const QString& name) { fillPasswd(getpwnam(name.latin1())); } +KUser::KUser(const KUser &user) { + d = new KUserPrivate(user.uid(), + user.loginName(), + user.fullName()); +} + +KUser& KUser::operator =(const KUser& user) { + delete d; + d = new KUserPrivate(user.uid(), + user.loginName(), + user.fullName()); +} + +bool KUser::operator ==(const KUser& user) { + if (isValid() != user.isValid()) + return false; + if (isValid()) + return uid() == user.uid(); + else + return true; +} + void KUser::fillPasswd(struct passwd *p) { if (p) { QString fn(p->pw_gecos); @@ -87,6 +109,10 @@ long KUser::uid() const { return -1; } +bool KUser::isSuperUser() const { + return uid() == 0; +} + QString KUser::loginName() const { if (d->valid) return d->loginName; diff --git a/srvloc/kuser.h b/srvloc/kuser.h index f668113d..92cad8f2 100644 --- a/srvloc/kuser.h +++ b/srvloc/kuser.h @@ -36,15 +36,22 @@ struct passwd; * * @author Tim Jansen * @short Represents a user on your system + * @since 3.2 */ class KUser { public: /** * Creates an object that contains information about the current user. - * (As returned by getuid(2)). + * (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 + * checking permissions, and the real user for displaying + * information about the user */ - KUser(); + KUser(bool effective = false); /** * Creates an object for the user with the given user id. @@ -61,6 +68,24 @@ public: */ KUser(const QString& name); + /** + * Copy constructor. + * Makes a deep copy. + */ + KUser(const KUser &user); + + /** + * Assignment operator. + * Makes a deep copy. + */ + KUser& operator =(const KUser& user); + + /** + * Two KUser objects are equal if @ref isValid() and the uid() are + * identical. + */ + bool operator ==(const KUser& user); + /** * Returns true if the user is valid. A KUser object can be invalid if * you created it with an non-existing uid or name. @@ -74,6 +99,12 @@ public: */ long uid() const; + /** + * Checks whether the user it the super user (root). + * @return true if the user is root + */ + bool isSuperUser() const; + /** * The login name of the user. * @the login name of the user or QString::null if user is invalid