Commit ce3b4506 authored by ck's avatar ck
Browse files

Maemo: Add authentication options (password or key based)

parent ea5007e8
......@@ -37,6 +37,7 @@
#include <coreplugin/icore.h>
#include <QtCore/QSettings>
#include <QtGui/QDesktopServices>
#include <algorithm>
......@@ -52,9 +53,15 @@ namespace {
const QLatin1String HostKey("Host");
const QLatin1String PortKey("Port");
const QLatin1String UserNameKey("Uname");
const QLatin1String AuthKey("Authentication");
const QLatin1String KeyFileKey("KeyFile");
const QLatin1String PasswordKey("Password");
const QLatin1String TimeoutKey("Timeout");
const QLatin1String InternalIdKey("InternalId");
const QString DefaultKeyFile =
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
+ QLatin1String("/.ssh/id_rsa");
};
class DevConfIdMatcher
......@@ -73,6 +80,8 @@ MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QString &name)
: name(name),
type(Physical),
port(22),
authentication(Key),
keyFile(DefaultKeyFile),
timeout(30),
internalId(MaemoDeviceConfigurations::instance().m_nextId++)
{
......@@ -84,7 +93,9 @@ MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QSettings &settings)
host(settings.value(HostKey).toString()),
port(settings.value(PortKey, 22).toInt()),
uname(settings.value(UserNameKey).toString()),
authentication(static_cast<AuthType>(settings.value(AuthKey).toInt())),
pwd(settings.value(PasswordKey).toString()),
keyFile(settings.value(KeyFileKey).toString()),
timeout(settings.value(TimeoutKey, 30).toInt()),
internalId(settings.value(InternalIdKey, MaemoDeviceConfigurations::instance().m_nextId).toInt())
{
......@@ -110,7 +121,9 @@ void MaemoDeviceConfigurations::DeviceConfig::save(QSettings &settings) const
settings.setValue(HostKey, host);
settings.setValue(PortKey, port);
settings.setValue(UserNameKey, uname);
settings.setValue(AuthKey, authentication);
settings.setValue(PasswordKey, pwd);
settings.setValue(KeyFileKey, keyFile);
settings.setValue(TimeoutKey, timeout);
settings.setValue(InternalIdKey, internalId);
}
......
......@@ -56,6 +56,7 @@ public:
{
public:
enum DeviceType { Physical, Simulator };
enum AuthType { Password, Key };
DeviceConfig();
DeviceConfig(const QString &name);
DeviceConfig(const QSettings &settings);
......@@ -66,7 +67,9 @@ public:
QString host;
int port;
QString uname;
AuthType authentication;
QString pwd;
QString keyFile;
int timeout;
quint64 internalId;
......
......@@ -112,6 +112,7 @@ protected:
const QString port() const;
const QString targetCmdLinePrefix() const;
const QString remoteDir() const;
const QStringList options() const;
virtual void deploymentFinished(bool success)=0;
virtual bool setProcessEnvironment(QProcess &process);
private slots:
......@@ -752,6 +753,7 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
m_configNameLineEdit = new QLineEdit(m_runConfiguration->name());
mainLayout->addRow(tr("Run configuration name:"), m_configNameLineEdit);
m_devConfBox = new QComboBox;
m_devConfBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
mainLayout->addRow(new QLabel(tr("Device Configuration:")), m_devConfBox);
m_executableLabel = new QLabel(m_runConfiguration->executable());
mainLayout->addRow(tr("Executable:"), m_executableLabel);
......@@ -1031,8 +1033,10 @@ AbstractMaemoRunControl::AbstractMaemoRunControl(RunConfiguration *rc)
void AbstractMaemoRunControl::startDeployment(bool forDebugging)
{
QTC_ASSERT(runConfig, return);
if (!devConfig.isValid())
if (!devConfig.isValid()) {
deploymentFinished(false);
return;
}
QStringList deployables;
if (runConfig->currentlyNeedsDeployment()) {
deployingExecutable = true;
......@@ -1050,8 +1054,8 @@ void AbstractMaemoRunControl::startDeployment(bool forDebugging)
emit addToOutputWindow(this, tr("Files to deploy: %1.")
.arg(deployables.join(" ")));
QStringList cmdArgs;
cmdArgs << "-P" << port() << deployables << (devConfig.uname
+ "@" + devConfig.host + ":" + remoteDir());
cmdArgs << "-P" << port() << options() << deployables
<< (devConfig.uname + "@" + devConfig.host + ":" + remoteDir());
deployProcess.setWorkingDirectory(QFileInfo(executableOnHost()).absolutePath());
deployProcess.start(runConfig->scpCmd(), cmdArgs);
if (!deployProcess.waitForStarted()) {
......@@ -1114,6 +1118,19 @@ const QString AbstractMaemoRunControl::remoteDir() const
: QString::fromLocal8Bit("/home/") + devConfig.uname;
}
const QStringList AbstractMaemoRunControl::options() const
{
const bool usePassword =
devConfig.authentication == MaemoDeviceConfigurations::DeviceConfig::Password;
const QLatin1String opt("-o");
return QStringList() << opt
<< QString::fromLatin1("PasswordAuthentication=%1").
arg(usePassword ? "yes" : "no") << opt
<< QString::fromLatin1("PubkeyAuthentication=%1").
arg(usePassword ? "no" : "yes") << opt
<< QString::fromLatin1("ConnectTimeout=%1").arg(devConfig.timeout);
}
const QString AbstractMaemoRunControl::executableOnTarget() const
{
return QString::fromLocal8Bit("%1/%2").arg(remoteDir()).
......@@ -1202,7 +1219,7 @@ void MaemoRunControl::startExecution()
QStringList cmdArgs;
cmdArgs << "-n" << "-p" << port() << "-l" << devConfig.uname
<< devConfig.host << remoteCall;
<< options() << devConfig.host << remoteCall;
sshProcess.start(runConfig->sshCmd(), cmdArgs);
sshProcess.start(runConfig->sshCmd(), cmdArgs);
......@@ -1237,7 +1254,7 @@ void MaemoRunControl::stop()
const QString remoteCall = QString::fromLocal8Bit("pkill -x %1; "
"sleep 1; pkill -x -9 %1").arg(executableFileName());
cmdArgs << "-n" << "-p" << port() << "-l" << devConfig.uname
<< devConfig.host << remoteCall;
<< options() << devConfig.host << remoteCall;
stopProcess.start(runConfig->sshCmd(), cmdArgs);
}
}
......@@ -1311,7 +1328,7 @@ void MaemoDebugRunControl::startGdbServer()
.arg(runConfig->arguments().join(" ")));
QStringList sshArgs;
sshArgs << "-t" << "-n" << "-l" << devConfig.uname << "-p"
<< port() << devConfig.host << remoteCall;
<< port() << options() << devConfig.host << remoteCall;
inferiorPid = -1;
disconnect(&gdbServer, SIGNAL(readyReadStandardError()), 0, 0);
connect(&gdbServer, SIGNAL(readyReadStandardError()), this,
......@@ -1394,7 +1411,7 @@ void MaemoDebugRunControl::debuggingFinished()
"kill -9 %1; pkill -x -9 gdbserver").arg(inferiorPid);
QStringList sshArgs;
sshArgs << "-n" << "-l" << devConfig.uname << "-p" << port()
<< devConfig.host << remoteCall;
<< options() << devConfig.host << remoteCall;
stopProcess.start(runConfig->sshCmd(), sshArgs);
}
qDebug("ssh return code is %d", gdbServer.exitCode());
......
......@@ -127,11 +127,13 @@ private slots:
void deleteConfig();
void configNameEditingFinished();
void deviceTypeChanged();
void authenticationTypeChanged();
void hostNameEditingFinished();
void portEditingFinished();
void timeoutEditingFinished();
void userNameEditingFinished();
void passwordEditingFinished();
void keyFileEditingFinished();
private:
void initGui();
......@@ -151,12 +153,10 @@ private:
MaemoSettingsPage::MaemoSettingsPage(QObject *parent)
: Core::IOptionsPage(parent)
{
qDebug("Creating maemo settings page");
}
MaemoSettingsPage::~MaemoSettingsPage()
{
qDebug("deleting maemo settings page");
}
QString MaemoSettingsPage::id() const
......@@ -193,7 +193,6 @@ void MaemoSettingsPage::apply()
void MaemoSettingsPage::finish()
{
// apply();
}
MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
......@@ -203,13 +202,11 @@ MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
m_nameValidator(m_devConfs)
{
qDebug("creating maemo settings widget");
initGui();
}
MaemoSettingsWidget::~MaemoSettingsWidget()
{
qDebug("Deleting maemo settings widget");
}
void MaemoSettingsWidget::initGui()
......@@ -265,11 +262,16 @@ void MaemoSettingsWidget::display(const MaemoDeviceConfigurations::DeviceConfig
m_ui->deviceButton->setChecked(true);
else
m_ui->simulatorButton->setChecked(true);
if (devConfig.authentication == MaemoDeviceConfigurations::DeviceConfig::Password)
m_ui->passwordButton->setChecked(true);
else
m_ui->keyButton->setChecked(true);
m_ui->hostLineEdit->setText(devConfig.host);
m_ui->portLineEdit->setText(QString::number(devConfig.port));
m_ui->timeoutLineEdit->setText(QString::number(devConfig.timeout));
m_ui->userLineEdit->setText(devConfig.uname);
m_ui->pwdLineEdit->setText(devConfig.pwd);
m_ui->keyFileLineEdit->setText(devConfig.keyFile);
m_ui->detailsWidget->setEnabled(true);
m_nameValidator.setName(devConfig.name);
m_portValidator.setValue(devConfig.port);
......@@ -284,13 +286,11 @@ void MaemoSettingsWidget::saveSettings()
MaemoDeviceConfigurations::DeviceConfig &MaemoSettingsWidget::currentConfig()
{
qDebug("%d/%d", m_ui->configListWidget->count(), m_devConfs.count());
Q_ASSERT(m_ui->configListWidget->count() == m_devConfs.count());
const QList<QListWidgetItem *> &selectedItems =
m_ui->configListWidget->selectedItems();
Q_ASSERT(selectedItems.count() == 1);
const int selectedRow = m_ui->configListWidget->row(selectedItems.first());
qDebug("selected row = %d", selectedRow);
Q_ASSERT(selectedRow < m_devConfs.count());
return m_devConfs[selectedRow];
}
......@@ -311,6 +311,18 @@ void MaemoSettingsWidget::deviceTypeChanged()
: MaemoDeviceConfigurations::DeviceConfig::Simulator;
}
void MaemoSettingsWidget::authenticationTypeChanged()
{
const bool usePassword = m_ui->passwordButton->isChecked();
currentConfig().authentication = usePassword
? MaemoDeviceConfigurations::DeviceConfig::Password
: MaemoDeviceConfigurations::DeviceConfig::Key;
m_ui->pwdLineEdit->setEnabled(usePassword);
m_ui->passwordLabel->setEnabled(usePassword);
m_ui->keyFileLineEdit->setEnabled(!usePassword);
m_ui->keyLabel->setEnabled(!usePassword);
}
void MaemoSettingsWidget::hostNameEditingFinished()
{
currentConfig().host = m_ui->hostLineEdit->text();
......@@ -346,6 +358,11 @@ void MaemoSettingsWidget::passwordEditingFinished()
currentConfig().pwd = m_ui->pwdLineEdit->text();
}
void MaemoSettingsWidget::keyFileEditingFinished()
{
currentConfig().keyFile = m_ui->keyFileLineEdit->text();
}
void MaemoSettingsWidget::selectionChanged()
{
const QList<QListWidgetItem *> &selectedItems =
......
......@@ -42,13 +42,6 @@
<item row="0" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Device type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
......@@ -75,60 +68,114 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Host Name:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="hostLineEdit"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="portLineEdit"/>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Connection Timeout:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="timeoutLineEdit"/>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>User Name:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QLineEdit" name="userLineEdit"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<item row="7" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QLineEdit" name="pwdLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Device type:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Authentication type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="passwordButton">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="keyButton">
<property name="text">
<string>Key</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="keyLabel">
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="keyFileLineEdit">
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -180,8 +227,8 @@
<slot>configNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>221</x>
<y>166</y>
<x>372</x>
<y>146</y>
</hint>
<hint type="destinationlabel">
<x>514</x>
......@@ -196,8 +243,8 @@
<slot>deviceTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>164</x>
<y>197</y>
<x>269</x>
<y>170</y>
</hint>
<hint type="destinationlabel">
<x>511</x>
......@@ -212,8 +259,8 @@
<slot>hostNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>289</x>
<y>222</y>
<x>397</x>
<y>219</y>
</hint>
<hint type="destinationlabel">
<x>424</x>
......@@ -228,8 +275,8 @@
<slot>portEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>248</y>
<x>397</x>
<y>243</y>
</hint>
<hint type="destinationlabel">
<x>514</x>
......@@ -244,8 +291,8 @@
<slot>timeoutEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>371</x>
<y>276</y>
<x>397</x>
<y>268</y>
</hint>
<hint type="destinationlabel">
<x>425</x>
......@@ -260,8 +307,8 @@
<slot>userNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>340</x>
<y>302</y>
<x>397</x>
<y>293</y>
</hint>
<hint type="destinationlabel">
<x>422</x>
......@@ -276,8 +323,8 @@
<slot>passwordEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>243</x>
<y>333</y>
<x>394</x>
<y>317</y>
</hint>
<hint type="destinationlabel">
<x>423</x>
......@@ -292,8 +339,8 @@
<slot>deviceTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>291</x>
<y>198</y>
<x>388</x>
<y>170</y>
</hint>
<hint type="destinationlabel">
<x>426</x>
......@@ -349,6 +396,38 @@
</hint>
</hints>
</connection>
<connection>
<sender>passwordButton</sender>
<signal>toggled(bool)</signal>
<receiver>maemoSettingsWidget</receiver>
<slot>authenticationTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>196</x>
<y>187</y>
</hint>
<hint type="destinationlabel">
<x>513</x>
<y>240</y>
</hint>
</hints>
</connection>
<connection>
<sender>keyFileLineEdit</sender>
<signal>editingFinished()</signal>
<receiver>maemoSettingsWidget</receiver>
<slot>keyFileChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>208</x>
<y>332</y>
</hint>
<hint type="destinationlabel">
<x>424</x>
<y>41</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>configNameEditingFinished()</slot>
......@@ -361,5 +440,7 @@
<slot>addConfig()</slot>
<slot>selectionChanged()</slot>
<slot>deleteConfig()</slot>
<slot>authenticationTypeChanged()</slot>
<slot>keyFileChanged()</slot>
</slots>
</ui>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment