File indexing completed on 2024-04-14 04:53:33
0001 /* 0002 Copyright (C) 2009-2010 Collabora Ltd <info@collabora.co.uk> 0003 @author George Goldberg <george.goldberg@collabora.co.uk> 0004 @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk> 0005 Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it> 0006 Copyright (C) 2001-2003 by Tim Jansen <tim@tjansen.de> 0007 0008 This program is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This program is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 GNU General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public License 0019 along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 */ 0021 #include "rfb.h" 0022 #include "invitationsrfbclient.h" 0023 #include "invitationsrfbserver.h" 0024 #include "krfbconfig.h" 0025 #include "sockethelpers.h" 0026 #include "connectiondialog.h" 0027 #include "krfbdebug.h" 0028 0029 #include <KNotification> 0030 #include <KLocalizedString> 0031 0032 #include <QSocketNotifier> 0033 #include <poll.h> 0034 #include <KConfigGroup> 0035 0036 struct PendingInvitationsRfbClient::Private 0037 { 0038 Private(rfbClientPtr client) : 0039 client(client), 0040 askOnConnect(true) 0041 {} 0042 0043 rfbClientPtr client; 0044 QSocketNotifier *notifier = nullptr; 0045 bool askOnConnect; 0046 }; 0047 0048 static void clientGoneHookNoop(rfbClientPtr cl) { Q_UNUSED(cl); } 0049 0050 PendingInvitationsRfbClient::PendingInvitationsRfbClient(rfbClientPtr client, QObject *parent) : 0051 PendingRfbClient(client, parent), 0052 d(new Private(client)) 0053 { 0054 d->client->clientGoneHook = clientGoneHookNoop; 0055 } 0056 0057 PendingInvitationsRfbClient::~PendingInvitationsRfbClient() 0058 { 0059 delete d; 0060 } 0061 0062 void PendingInvitationsRfbClient::processNewClient() 0063 { 0064 QString host = peerAddress(m_rfbClient->sock) + QLatin1Char(':') + QString::number(peerPort(m_rfbClient->sock)); 0065 0066 if (d->askOnConnect == false) { 0067 0068 KNotification::event(QStringLiteral("NewConnectionAutoAccepted"), 0069 i18n("Accepted connection from %1", host)); 0070 accept(new InvitationsRfbClient(m_rfbClient, parent())); 0071 0072 } else { 0073 0074 KNotification::event(QStringLiteral("NewConnectionOnHold"), 0075 i18n("Received connection from %1, on hold (waiting for confirmation)", 0076 host)); 0077 0078 auto dialog = new InvitationsConnectionDialog(nullptr); 0079 dialog->setRemoteHost(host); 0080 dialog->setAllowRemoteControl(KrfbConfig::allowDesktopControl()); 0081 0082 connect(dialog, &InvitationsConnectionDialog::accepted, this, &PendingInvitationsRfbClient::dialogAccepted); 0083 connect(dialog, &InvitationsConnectionDialog::rejected, this, &PendingInvitationsRfbClient::reject); 0084 0085 dialog->show(); 0086 } 0087 } 0088 0089 bool PendingInvitationsRfbClient::checkPassword(const QByteArray & encryptedPassword) 0090 { 0091 qCDebug(KRFB) << "about to start authentication"; 0092 0093 if(InvitationsRfbServer::instance->allowUnattendedAccess() && vncAuthCheckPassword( 0094 InvitationsRfbServer::instance->unattendedPassword().toLocal8Bit(), 0095 encryptedPassword) ) { 0096 d->askOnConnect = false; 0097 return true; 0098 } 0099 0100 return vncAuthCheckPassword( 0101 InvitationsRfbServer::instance->desktopPassword().toLocal8Bit(), 0102 encryptedPassword); 0103 } 0104 0105 void PendingInvitationsRfbClient::dialogAccepted() 0106 { 0107 auto dialog = qobject_cast<InvitationsConnectionDialog *>(sender()); 0108 Q_ASSERT(dialog); 0109 0110 auto client = new InvitationsRfbClient(m_rfbClient, parent()); 0111 client->setControlEnabled(dialog->allowRemoteControl()); 0112 accept(client); 0113 }