mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:41:17 -07:00
correct handling of authentication and remote desktop control
svn path=/trunk/KDE/kdenetwork/krfb/; revision=652375
This commit is contained in:
@@ -61,6 +61,9 @@
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="echoMode" >
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -74,12 +74,11 @@ ConnectionController::~ConnectionController()
|
||||
enum rfbNewClientAction ConnectionController::handleNewClient()
|
||||
{
|
||||
|
||||
bool allowDesktopControl = KrfbConfig::allowDesktopControl();
|
||||
bool askOnConnect = KrfbConfig::askOnConnect();
|
||||
bool allowUninvited = KrfbConfig::allowUninvitedConnections();
|
||||
|
||||
int socket = cl->sock;
|
||||
// cl->negotiationFinishedHook = negotiationFinishedHook; ???
|
||||
QString remoteIp;
|
||||
|
||||
#if 0
|
||||
// TODO: this drops the connection >.<
|
||||
QTcpSocket t;
|
||||
@@ -87,12 +86,19 @@ enum rfbNewClientAction ConnectionController::handleNewClient()
|
||||
remoteIp = t.peerAddress().toString();
|
||||
#endif
|
||||
|
||||
if (!askOnConnect && InvitationManager::self()->invitations().size() == 0) {
|
||||
if (!allowUninvited && InvitationManager::self()->activeInvitations() == 0) {
|
||||
KNotification::event("ConnectionAttempted",
|
||||
i18n("Attepted uninvited connection from %1: connection refused",
|
||||
remoteIp));
|
||||
return RFB_CLIENT_REFUSE;
|
||||
}
|
||||
|
||||
if (!askOnConnect && InvitationManager::self()->activeInvitations() == 0) {
|
||||
KNotification::event("NewConnectionAutoAccepted",
|
||||
i18n("Accepted uninvited connection from %1",
|
||||
remoteIp));
|
||||
|
||||
sendSessionEstablished();
|
||||
emit sessionEstablished(remoteIp);
|
||||
return RFB_CLIENT_ACCEPT;
|
||||
}
|
||||
|
||||
@@ -134,7 +140,7 @@ bool ConnectionController::handleCheckPassword(rfbClientPtr cl, const char *resp
|
||||
kDebug() << "checking password" << endl;
|
||||
if (checkPassword(it.password(), cl->authChallenge, response, len) && it.isValid()) {
|
||||
authd = true;
|
||||
//configuration->removeInvitation(it);
|
||||
InvitationManager::self()->removeInvitation(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -158,22 +164,20 @@ bool ConnectionController::handleCheckPassword(rfbClientPtr cl, const char *resp
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConnectionController::sendSessionEstablished()
|
||||
{
|
||||
emit sessionEstablished("BAH");
|
||||
}
|
||||
|
||||
void ConnectionController::handleKeyEvent(bool down, rfbKeySym keySym)
|
||||
{
|
||||
KeyboardEvent ev(down, keySym);
|
||||
ev.exec();
|
||||
if (controlEnabled) {
|
||||
KeyboardEvent ev(down, keySym);
|
||||
ev.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionController::handlePointerEvent(int bm, int x, int y)
|
||||
{
|
||||
PointerEvent ev(bm, x, y);
|
||||
ev.exec();
|
||||
if (controlEnabled) {
|
||||
PointerEvent ev(bm, x, y);
|
||||
ev.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionController::handleClientGone()
|
||||
@@ -200,3 +204,9 @@ void ConnectionController::dialogRejected()
|
||||
rfbRefuseOnHoldClient(cl);
|
||||
}
|
||||
|
||||
void ConnectionController::setControlEnabled(bool enable)
|
||||
{
|
||||
controlEnabled = enable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,10 +32,11 @@ public:
|
||||
void handlePointerEvent( int bm, int x, int y);
|
||||
void handleClientGone();
|
||||
void clipboardToServer(const QString &);
|
||||
void sendSessionEstablished();
|
||||
|
||||
enum rfbNewClientAction handleNewClient();
|
||||
|
||||
void setControlEnabled(bool enable);
|
||||
|
||||
Q_SIGNALS:
|
||||
void sessionEstablished(QString);
|
||||
void notification(QString, QString);
|
||||
@@ -47,6 +48,7 @@ protected Q_SLOTS:
|
||||
private:
|
||||
QString remoteIp;
|
||||
struct _rfbClientRec *cl;
|
||||
bool controlEnabled;
|
||||
/*
|
||||
int fd;
|
||||
KrfbServer *server;
|
||||
|
||||
@@ -102,3 +102,7 @@ bool Invitation::isValid() const {
|
||||
return m_expirationTime > QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
bool Invitation::operator ==(const Invitation & ot)
|
||||
{
|
||||
return m_creationTime == ot.m_creationTime && m_password == ot.m_password;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
Invitation(const Invitation &x);
|
||||
Invitation &operator= (const Invitation&x);
|
||||
|
||||
bool operator == (const Invitation &ot);
|
||||
|
||||
QString password() const;
|
||||
QDateTime expirationTime() const;
|
||||
QDateTime creationTime() const;
|
||||
|
||||
@@ -98,6 +98,14 @@ void InvitationManager::saveInvitations()
|
||||
conf->sync();
|
||||
}
|
||||
|
||||
int InvitationManager::activeInvitations()
|
||||
{
|
||||
invalidateOldInvitations();
|
||||
return invitationList.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void InvitationManager::removeInvitation(const Invitation & inv)
|
||||
{
|
||||
invitationList.removeAll(inv);
|
||||
emit invitationNumChanged(invitationList.size());
|
||||
}
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
|
||||
Invitation addInvitation();
|
||||
|
||||
int activeInvitations();
|
||||
|
||||
void removeInvitation(const Invitation &inv);
|
||||
|
||||
const QList<Invitation> &invitations();
|
||||
|
||||
signals:
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <QHostInfo>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPointer>
|
||||
|
||||
#include <KGlobal>
|
||||
#include <KUser>
|
||||
@@ -29,6 +30,7 @@
|
||||
#include "connectioncontroller.h"
|
||||
#include "framebuffer.h"
|
||||
#include "krfbconfig.h"
|
||||
#include "invitationmanager.h"
|
||||
|
||||
|
||||
static const char* cur=
|
||||
@@ -109,6 +111,17 @@ static void clipboardHook(char* str,int len, rfbClientPtr cl)
|
||||
}
|
||||
|
||||
|
||||
class KrfbServer::KrfbServerP {
|
||||
|
||||
public:
|
||||
KrfbServerP() : fb(0), screen(0) {};
|
||||
|
||||
FrameBuffer *fb;
|
||||
QList< QPointer<ConnectionController> > controllers;
|
||||
rfbScreenInfoPtr screen;
|
||||
};
|
||||
|
||||
|
||||
static KStaticDeleter<KrfbServer> sd;
|
||||
KrfbServer * KrfbServer::_self = 0;
|
||||
KrfbServer * KrfbServer::self() {
|
||||
@@ -118,29 +131,39 @@ KrfbServer * KrfbServer::self() {
|
||||
|
||||
|
||||
KrfbServer::KrfbServer()
|
||||
:d(new KrfbServerP)
|
||||
{
|
||||
kDebug() << "starting " << endl;
|
||||
fb = new FrameBuffer(QApplication::desktop()->winId(), this);
|
||||
d->fb = new FrameBuffer(QApplication::desktop()->winId(), this);
|
||||
QTimer::singleShot(0, this, SLOT(startListening()));
|
||||
connect(InvitationManager::self(), SIGNAL(invitationNumChanged(int)),SLOT(updatePassword()));
|
||||
|
||||
}
|
||||
|
||||
KrfbServer::~KrfbServer()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
void KrfbServer::startListening()
|
||||
{
|
||||
rfbScreenInfoPtr screen;
|
||||
|
||||
int port = KrfbConfig::port();
|
||||
|
||||
int w = fb->width();
|
||||
int h = fb->height();
|
||||
int depth = fb->depth();
|
||||
int w = d->fb->width();
|
||||
int h = d->fb->height();
|
||||
int depth = d->fb->depth();
|
||||
|
||||
rfbLogEnable(0);
|
||||
screen = rfbGetScreen(0, 0, w, h, 8, 3,depth / 8);
|
||||
screen->paddedWidthInBytes = w * 4;
|
||||
|
||||
fb->getServerFormat(screen->serverFormat);
|
||||
d->fb->getServerFormat(screen->serverFormat);
|
||||
|
||||
screen->frameBuffer = fb->data();
|
||||
screen->frameBuffer = d->fb->data();
|
||||
d->screen = screen;
|
||||
screen->autoPort = 0;
|
||||
screen->port = port;
|
||||
|
||||
@@ -160,8 +183,8 @@ void KrfbServer::startListening()
|
||||
}
|
||||
screen->cursor = myCursor;
|
||||
|
||||
// TODO: configure password data to handle authentication
|
||||
screen->authPasswdData = (void *)1;
|
||||
// configure passwords and desktop control here
|
||||
updateSettings();
|
||||
|
||||
rfbInitServer(screen);
|
||||
if (!rfbIsActive(screen)) {
|
||||
@@ -170,24 +193,23 @@ void KrfbServer::startListening()
|
||||
};
|
||||
|
||||
while (true) {
|
||||
foreach(QRect r, fb->modifiedTiles()) {
|
||||
foreach(QRect r, d->fb->modifiedTiles()) {
|
||||
rfbMarkRectAsModified(screen, r.top(), r.left(), r.left() + r.width(), r.top() + r.height());
|
||||
}
|
||||
fb->modifiedTiles().clear();
|
||||
d->fb->modifiedTiles().clear();
|
||||
rfbProcessEvents(screen, 100);
|
||||
qApp->processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KrfbServer::~KrfbServer()
|
||||
{
|
||||
//delete _controller;
|
||||
}
|
||||
|
||||
void KrfbServer::enableDesktopControl(bool enable)
|
||||
{
|
||||
// TODO
|
||||
foreach (QPointer<ConnectionController> ptr, d->controllers) {
|
||||
if (ptr) {
|
||||
ptr->setControlEnabled(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KrfbServer::disconnectAndQuit()
|
||||
@@ -200,11 +222,38 @@ enum rfbNewClientAction KrfbServer::handleNewClient(struct _rfbClientRec * cl)
|
||||
{
|
||||
ConnectionController *cc = new ConnectionController(cl, this);
|
||||
|
||||
d->controllers.append(cc);
|
||||
cc->setControlEnabled(KrfbConfig::allowDesktopControl());
|
||||
|
||||
connect(cc, SIGNAL(sessionEstablished(QString)), SIGNAL(sessionEstablished(QString)));
|
||||
|
||||
return cc->handleNewClient();
|
||||
}
|
||||
|
||||
void KrfbServer::updateSettings()
|
||||
{
|
||||
enableDesktopControl(KrfbConfig::allowDesktopControl());
|
||||
updatePassword();
|
||||
}
|
||||
|
||||
void KrfbServer::updatePassword()
|
||||
{
|
||||
|
||||
if (!d->screen) return;
|
||||
QString pw = KrfbConfig::uninvitedConnectionPassword();
|
||||
kDebug() << "password: " << pw << " allow " <<
|
||||
KrfbConfig::allowUninvitedConnections() <<
|
||||
" invitations " << InvitationManager::self()->activeInvitations() << endl;
|
||||
|
||||
if (pw.isEmpty() && InvitationManager::self()->activeInvitations() == 0) {
|
||||
kDebug() << "no password from now on" << endl;
|
||||
d->screen->authPasswdData = (void *)0;
|
||||
} else {
|
||||
kDebug() << "Ask for password to accept connections" << endl;
|
||||
d->screen->authPasswdData = (void *)1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,13 +42,16 @@ public Q_SLOTS:
|
||||
void startListening();
|
||||
void enableDesktopControl(bool);
|
||||
void disconnectAndQuit();
|
||||
void updateSettings();
|
||||
void updatePassword();
|
||||
|
||||
private:
|
||||
KrfbServer();
|
||||
static KrfbServer *_self;
|
||||
|
||||
class KrfbServerP;
|
||||
KrfbServerP * const d;
|
||||
|
||||
FrameBuffer *fb;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "invitationmanager.h"
|
||||
#include "invitation.h"
|
||||
#include "krfbconfig.h"
|
||||
#include "krfbserver.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QToolTip>
|
||||
@@ -126,7 +127,7 @@ void ManageInvitationsDialog::showConfiguration()
|
||||
KConfigDialog *dialog = new KConfigDialog(this, "settings", KrfbConfig::self());
|
||||
dialog->addPage(new TCP, i18n("Network"), "network");
|
||||
dialog->addPage(new Security, i18n("Security"), "encrypted");
|
||||
|
||||
connect(dialog, SIGNAL(settingsChanged(QString)),KrfbServer::self(),SLOT(updateSettings()));
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user