mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
last commit before autoport
svn path=/trunk/kdenetwork/krfb/; revision=136868
This commit is contained in:
@@ -82,7 +82,11 @@ void Configuration::loadFromKConfig() {
|
||||
void Configuration::loadFromDialog() {
|
||||
askOnConnectFlag = confDlg.askOnConnectCB->isChecked();
|
||||
allowDesktopControlFlag = confDlg.allowDesktopControlCB->isChecked();
|
||||
passwordString = confDlg.passwordInput->text();
|
||||
QString newPassword = confDlg.passwordInput->text();
|
||||
if (passwordString != newPassword) {
|
||||
passwordString = newPassword;
|
||||
emit passwordChanged();
|
||||
}
|
||||
int p = confDlg.displayNumberInput->text().toInt();
|
||||
if (p != portNumber) {
|
||||
portNumber = p;
|
||||
@@ -155,17 +159,20 @@ void Configuration::setAllowDesktopControl(bool allowDesktopControl)
|
||||
void Configuration::setPassword(QString password)
|
||||
{
|
||||
passwordString = password;
|
||||
emit passwordChanged();
|
||||
saveToKConfig();
|
||||
saveToDialog();
|
||||
}
|
||||
|
||||
void Configuration::setPort(int port)
|
||||
{
|
||||
int oldPort = portNumber;
|
||||
if ((port >= 5900) && (port < 6000))
|
||||
portNumber = port-5900;
|
||||
else
|
||||
portNumber = port;
|
||||
emit portChanged();
|
||||
if (oldPort != portNumber)
|
||||
emit portChanged();
|
||||
saveToKConfig();
|
||||
saveToDialog();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
|
||||
signals:
|
||||
void portChanged();
|
||||
void passwordChanged();
|
||||
|
||||
public slots:
|
||||
void showDialog();
|
||||
|
||||
@@ -142,6 +142,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
QObject::connect(config, SIGNAL(portChanged()),
|
||||
&controller, SLOT(rebind()));
|
||||
QObject::connect(config, SIGNAL(passwordChanged()),
|
||||
&controller, SLOT(passwordChanged()));
|
||||
|
||||
QObject::connect(&controller, SIGNAL(sessionEstablished()),
|
||||
&trayicon, SLOT(openConnection()));
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* Contains keyboard & pointer handling from libvncserver's x11vnc.c
|
||||
*/
|
||||
|
||||
#include "rfbcontroller.h"
|
||||
|
||||
#include <netinet/tcp.h>
|
||||
@@ -26,6 +30,7 @@
|
||||
#include <kmessagebox.h>
|
||||
#include <klocale.h>
|
||||
#include <kextsock.h>
|
||||
#include <qstring.h>
|
||||
#include <qcursor.h>
|
||||
#include <qwindowdefs.h>
|
||||
#include <qtimer.h>
|
||||
@@ -72,7 +77,7 @@ static Bool passwordCheck(rfbClientPtr cl,
|
||||
int len)
|
||||
{
|
||||
AppLocker a;
|
||||
return self->handleCheckPassword(encryptedPassword, len);
|
||||
return self->handleCheckPassword(cl, encryptedPassword, len);
|
||||
}
|
||||
|
||||
static void keyboardHook(Bool down, KeySym keySym, rfbClientPtr)
|
||||
@@ -85,7 +90,7 @@ static void pointerHook(int bm, int x, int y, rfbClientPtr)
|
||||
self->handlePointerEvent(bm, x, y);
|
||||
}
|
||||
|
||||
static void clientGoneHook(rfbClientPtr cl)
|
||||
static void clientGoneHook(rfbClientPtr)
|
||||
{
|
||||
self->handleClientGone();
|
||||
}
|
||||
@@ -97,7 +102,6 @@ void ConnectionDialog::closeEvent(QCloseEvent *)
|
||||
emit closed();
|
||||
}
|
||||
|
||||
bool KeyboardEvent::initialized = false;
|
||||
Display *KeyboardEvent::dpy;
|
||||
char KeyboardEvent::modifiers[0x100];
|
||||
KeyCode KeyboardEvent::keycodes[0x100];
|
||||
@@ -112,34 +116,36 @@ char KeyboardEvent::ModifierState;
|
||||
KeyboardEvent::KeyboardEvent(bool d, KeySym k) :
|
||||
down(d),
|
||||
keySym(k) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
initKeycodes();
|
||||
dpy = qt_xdisplay();
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardEvent::initKeycodes() {
|
||||
KeySym key,*keymap;
|
||||
int i,j,minkey,maxkey,syms_per_keycode;
|
||||
|
||||
dpy = qt_xdisplay();
|
||||
|
||||
memset(modifiers,-1,sizeof(modifiers));
|
||||
|
||||
XDisplayKeycodes(dpy,&minkey,&maxkey);
|
||||
keymap=XGetKeyboardMapping(dpy,minkey,(maxkey - minkey + 1),&syms_per_keycode);
|
||||
|
||||
ASSERT(minkey >= 8);
|
||||
ASSERT(maxkey < 256);
|
||||
keymap = XGetKeyboardMapping(dpy, minkey,
|
||||
(maxkey - minkey + 1),
|
||||
&syms_per_keycode);
|
||||
ASSERT(keymap);
|
||||
|
||||
for (i = minkey; i <= maxkey; i++)
|
||||
for(j=0;j<syms_per_keycode;j++) {
|
||||
key=keymap[(i-minkey)*syms_per_keycode+j];
|
||||
if(key>=' ' && key<0x100 && i==XKeysymToKeycode(dpy,key)) {
|
||||
for (j=0; j<syms_per_keycode; j++) {
|
||||
key = keymap[(i-minkey)*syms_per_keycode+j];
|
||||
if (key>=' ' && key<0x100 && i==XKeysymToKeycode(dpy,key)) {
|
||||
keycodes[key]=i;
|
||||
modifiers[key]=j;
|
||||
}
|
||||
}
|
||||
|
||||
leftShiftCode = XKeysymToKeycode(dpy,XK_Shift_L);
|
||||
rightShiftCode = XKeysymToKeycode(dpy,XK_Shift_R);
|
||||
altGrCode = XKeysymToKeycode(dpy,XK_Mode_switch);
|
||||
leftShiftCode = XKeysymToKeycode(dpy, XK_Shift_L);
|
||||
rightShiftCode = XKeysymToKeycode(dpy, XK_Shift_R);
|
||||
altGrCode = XKeysymToKeycode(dpy, XK_Mode_switch);
|
||||
|
||||
XFree ((char *)keymap);
|
||||
}
|
||||
@@ -164,12 +170,12 @@ void KeyboardEvent::tweakModifiers(char mod, bool down) {
|
||||
XTestFakeKeyEvent(dpy, leftShiftCode,
|
||||
down, CurrentTime);
|
||||
|
||||
if(ModifierState&ALTGR && mod != 2)
|
||||
if((ModifierState&ALTGR) && mod != 2)
|
||||
XTestFakeKeyEvent(dpy, altGrCode,
|
||||
!down, CurrentTime);
|
||||
if(!(ModifierState&ALTGR) && mod==2)
|
||||
XTestFakeKeyEvent(dpy, altGrCode,
|
||||
down, CurrentTime);
|
||||
down, CurrentTime);
|
||||
}
|
||||
|
||||
void KeyboardEvent::exec() {
|
||||
@@ -184,19 +190,16 @@ void KeyboardEvent::exec() {
|
||||
KeyCode k;
|
||||
if (down)
|
||||
tweakModifiers(modifiers[keySym],True);
|
||||
//tweakModifiers(modifiers[keySym],down);
|
||||
//k = XKeysymToKeycode( dpy,keySym );
|
||||
k = keycodes[keySym];
|
||||
if(k!=NoSymbol)
|
||||
XTestFakeKeyEvent(dpy,k,down,CurrentTime);
|
||||
if (k != NoSymbol)
|
||||
XTestFakeKeyEvent(dpy, k, down, CurrentTime);
|
||||
|
||||
/*XTestFakeKeyEvent(dpy,keycodes[keySym],down,CurrentTime);*/
|
||||
if (down)
|
||||
tweakModifiers(modifiers[keySym],False);
|
||||
} else {
|
||||
KeyCode k = XKeysymToKeycode( dpy,keySym );
|
||||
if(k!=NoSymbol)
|
||||
XTestFakeKeyEvent(dpy,k,down,CurrentTime);
|
||||
KeyCode k = XKeysymToKeycode(dpy, keySym );
|
||||
if (k != NoSymbol)
|
||||
XTestFakeKeyEvent(dpy, k, down, CurrentTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +245,9 @@ RFBController::RFBController(Configuration *c) :
|
||||
connect(&idleTimer, SIGNAL(timeout()), SLOT(idleSlot()));
|
||||
|
||||
asyncQueue.setAutoDelete(true);
|
||||
|
||||
KeyboardEvent::initKeycodes();
|
||||
|
||||
startServer();
|
||||
}
|
||||
|
||||
@@ -277,7 +283,7 @@ void RFBController::startServer(bool xtestGrab)
|
||||
server->rfbServerFormat.bitsPerPixel = framebufferImage->bits_per_pixel;
|
||||
server->rfbServerFormat.depth = framebufferImage->depth;
|
||||
//rfbEndianTest = framebufferImage->bitmap_bit_order != MSBFirst;
|
||||
server->rfbServerFormat.trueColour = TRUE;
|
||||
server->rfbServerFormat.trueColour = (CARD8) TRUE;
|
||||
|
||||
if ( server->rfbServerFormat.bitsPerPixel == 8 ) {
|
||||
server->rfbServerFormat.redShift = 0;
|
||||
@@ -313,6 +319,8 @@ void RFBController::startServer(bool xtestGrab)
|
||||
server->newClientHook = newClientHook;
|
||||
server->passwordCheck = passwordCheck;
|
||||
|
||||
passwordChanged();
|
||||
|
||||
scanner = new XUpdateScanner(qt_xdisplay(),
|
||||
QApplication::desktop()->winId(),
|
||||
(unsigned char*)fb, w, h,
|
||||
@@ -467,10 +475,25 @@ void RFBController::dialogRefused()
|
||||
emit sessionRefused();
|
||||
}
|
||||
|
||||
bool RFBController::handleCheckPassword(const char *, int)
|
||||
bool RFBController::handleCheckPassword(rfbClientPtr cl,
|
||||
const char *response,
|
||||
int len)
|
||||
{
|
||||
char passwd[8];
|
||||
|
||||
QString cpassword = configuration->password();
|
||||
bzero(passwd, 8);
|
||||
if (!cpassword.isNull())
|
||||
strncpy(passwd, cpassword.latin1(),
|
||||
(8 <= cpassword.length()) ? 8 : cpassword.length());
|
||||
|
||||
vncEncryptBytes(cl->authChallenge, passwd);
|
||||
|
||||
if (memcmp(cl->authChallenge, response, len) != 0) {
|
||||
// TODO: knotify
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
// TODO
|
||||
}
|
||||
|
||||
enum rfbNewClientAction RFBController::handleNewClient(rfbClientPtr cl)
|
||||
@@ -524,6 +547,11 @@ void RFBController::handlePointerEvent(int button_mask, int x, int y) {
|
||||
asyncMutex.unlock();
|
||||
}
|
||||
|
||||
void RFBController::passwordChanged() {
|
||||
server->rfbAuthPasswdData = (const char*)
|
||||
((configuration->password().length() == 0) ? 0 : 1);
|
||||
}
|
||||
|
||||
bool RFBController::checkX11Capabilities() {
|
||||
int bp1, bp2, majorv, minorv;
|
||||
Bool r = XTestQueryExtension(qt_xdisplay(), &bp1, &bp2,
|
||||
|
||||
@@ -66,7 +66,6 @@ class KeyboardEvent : public VNCEvent {
|
||||
bool down;
|
||||
KeySym keySym;
|
||||
|
||||
static bool initialized;
|
||||
static Display *dpy;
|
||||
static char modifiers[0x100];
|
||||
static KeyCode keycodes[0x100], leftShiftCode, rightShiftCode, altGrCode;
|
||||
@@ -76,11 +75,11 @@ class KeyboardEvent : public VNCEvent {
|
||||
static char ModifierState;
|
||||
|
||||
static void tweakModifiers(char mod, bool down);
|
||||
static void initKeycodes();
|
||||
public:
|
||||
static void initKeycodes();
|
||||
|
||||
KeyboardEvent(bool d, KeySym k);
|
||||
virtual void exec();
|
||||
|
||||
};
|
||||
|
||||
class PointerEvent : public VNCEvent {
|
||||
@@ -116,7 +115,7 @@ public:
|
||||
void connectionAccepted(bool allowRemoteConnection);
|
||||
void refuseConnection();
|
||||
void connectionClosed();
|
||||
bool handleCheckPassword(const char *p, int len);
|
||||
bool handleCheckPassword(rfbClientPtr, const char *, int);
|
||||
void handleKeyEvent(bool down, KeySym keySym);
|
||||
void handlePointerEvent(int button_mask, int x, int y);
|
||||
enum rfbNewClientAction handleNewClient(rfbClientPtr cl);
|
||||
@@ -126,6 +125,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void rebind();
|
||||
void passwordChanged();
|
||||
void closeConnection();
|
||||
|
||||
signals:
|
||||
|
||||
@@ -300,6 +300,8 @@ listenerRun(void *data)
|
||||
int len;
|
||||
|
||||
len = sizeof(peer);
|
||||
|
||||
/* TODO: this thread wont die by restarting the server */
|
||||
while ((client_fd = accept(rfbScreen->rfbListenSock,
|
||||
(struct sockaddr*)&peer, &len)) >= 0) {
|
||||
cl = rfbNewClient(rfbScreen,client_fd);
|
||||
@@ -308,9 +310,6 @@ listenerRun(void *data)
|
||||
if (cl && !cl->onHold )
|
||||
rfbStartOnHoldClient(cl);
|
||||
}
|
||||
|
||||
rfbLog("accept failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -462,6 +461,7 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
|
||||
if(width&3)
|
||||
fprintf(stderr,"WARNING: Width (%d) is not a multiple of 4. VncViewer has problems with that.\n",width);
|
||||
|
||||
rfbScreen->autoPort=FALSE;
|
||||
rfbScreen->rfbClientHead=0;
|
||||
rfbScreen->rfbPort=5900;
|
||||
rfbScreen->socketInitDone=FALSE;
|
||||
|
||||
@@ -257,6 +257,7 @@ typedef struct _rfbScreenInfo
|
||||
char* desktopName;
|
||||
char rfbThisHost[255];
|
||||
|
||||
Bool autoPort;
|
||||
int rfbPort;
|
||||
SOCKET rfbListenSock;
|
||||
int maxSock;
|
||||
|
||||
@@ -112,7 +112,28 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
|
||||
return;
|
||||
}
|
||||
|
||||
if(rfbScreen->rfbPort>0) {
|
||||
if(rfbScreen->autoPort) {
|
||||
int i;
|
||||
rfbLog("Autoprobing TCP port \n");
|
||||
|
||||
for (i = 5900; i < 6000; i++) {
|
||||
if ((rfbScreen->rfbListenSock = ListenOnTCPPort(i)) >= 0) {
|
||||
rfbScreen->rfbPort = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 6000) {
|
||||
rfbLogPerror("Failure autoprobing");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rfbLog("Autoprobing selected port %d\n", rfbScreen->rfbPort);
|
||||
FD_ZERO(&(rfbScreen->allFds));
|
||||
FD_SET(rfbScreen->rfbListenSock, &(rfbScreen->allFds));
|
||||
rfbScreen->maxFd = rfbScreen->rfbListenSock;
|
||||
}
|
||||
else if(rfbScreen->rfbPort>0) {
|
||||
rfbLog("Listening for VNC connections on TCP port %d\n", rfbScreen->rfbPort);
|
||||
|
||||
if ((rfbScreen->rfbListenSock = ListenOnTCPPort(rfbScreen->rfbPort)) < 0) {
|
||||
|
||||
Reference in New Issue
Block a user