Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit e8daecc

Browse files
committed
Added suport for the sudoers checkbox to history.
Recent remote scans now encode the sudo mode into the "target" that is stored in the recent remote hosts list.
1 parent 57097b3 commit e8daecc

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

include/OscapScannerRemoteSsh.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ class OscapScannerRemoteSsh : public OscapScannerBase
3131
Q_OBJECT
3232

3333
public:
34-
static void splitTarget(const QString& in, QString& target, unsigned short& port);
34+
static void splitTarget(const QString& in, QString& target, unsigned short& port, bool& userIsSudoer);
3535

3636
OscapScannerRemoteSsh();
3737
virtual ~OscapScannerRemoteSsh();
3838

39+
bool getUserIsSudoer() const;
3940
void setUserIsSudoer(bool userIsSudoer);
4041
virtual void setTarget(const QString& target);
4142
virtual void setSession(ScanningSession* session);

include/RemoteMachineComboBox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class RemoteMachineComboBox : public QWidget
4747
bool userIsSudoer() const;
4848

4949
public slots:
50-
void notifyTargetUsed(const QString& target);
50+
void notifyTargetUsed(const QString& target, bool userIsSudoer);
5151
void clearHistory();
5252

5353
protected slots:

src/MainWindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,10 @@ void MainWindow::scanAsync(ScannerMode scannerMode)
763763
);
764764

765765
if (target != "localhost")
766-
mUI.remoteMachineDetails->notifyTargetUsed(mScanner->getTarget());
766+
{
767+
bool userIsSudoer = ((OscapScannerRemoteSsh *)mScanner)->getUserIsSudoer();
768+
mUI.remoteMachineDetails->notifyTargetUsed(mScanner->getTarget(), userIsSudoer);
769+
}
767770

768771
mScanThread->start();
769772
}

src/OscapScannerRemoteSsh.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ OscapScannerRemoteSsh::OscapScannerRemoteSsh():
4646
OscapScannerRemoteSsh::~OscapScannerRemoteSsh()
4747
{}
4848

49-
void OscapScannerRemoteSsh::splitTarget(const QString& in, QString& target, unsigned short& port)
49+
void OscapScannerRemoteSsh::splitTarget(const QString& in, QString& target, unsigned short& port, bool& userIsSudoer)
5050
{
5151
// NB: We dodge a bullet here because the editor will always pass a port
5252
// as the last component. A lot of checking and parsing does not need
@@ -56,10 +56,19 @@ void OscapScannerRemoteSsh::splitTarget(const QString& in, QString& target, unsi
5656
// being there and always being the last component.
5757

5858
// FIXME: Ideally, this should split from the right side and stop after one split
59-
QStringList split = in.split(':');
59+
userIsSudoer = false;
60+
QStringList sudoerSplit = in.split(' ');
61+
if (sudoerSplit.size() > 1)
62+
{
63+
if (sudoerSplit.at(1) == "sudo")
64+
{
65+
userIsSudoer = true;
66+
}
67+
}
68+
QStringList hostPortSplit = sudoerSplit.at(0).split(':');
6069

61-
const QString portString = split.back();
62-
split.removeLast();
70+
const QString portString = hostPortSplit.back();
71+
hostPortSplit.removeLast();
6372

6473
{
6574
bool status = false;
@@ -69,25 +78,32 @@ void OscapScannerRemoteSsh::splitTarget(const QString& in, QString& target, unsi
6978
port = status ? portCandidate : 22;
7079
}
7180

72-
target = split.join(":");
81+
target = hostPortSplit.join(":");
7382
}
7483

7584
void OscapScannerRemoteSsh::setTarget(const QString& target)
7685
{
77-
OscapScannerBase::setTarget(target);
86+
QStringList sudoerSplit = target.split(' ');
87+
OscapScannerBase::setTarget(sudoerSplit.at(0));
7888

7989
if (mSshConnection.isConnected())
8090
mSshConnection.disconnect();
8191

8292
QString cleanTarget;
8393
unsigned short port;
94+
bool userIsSudoer;
8495

85-
splitTarget(target, cleanTarget, port);
96+
splitTarget(target, cleanTarget, port, userIsSudoer);
8697

8798
mSshConnection.setTarget(cleanTarget);
8899
mSshConnection.setPort(port);
89100
}
90101

102+
bool OscapScannerRemoteSsh::getUserIsSudoer() const
103+
{
104+
return mUserIsSudoer;
105+
}
106+
91107
void OscapScannerRemoteSsh::setUserIsSudoer(bool userIsSudoer)
92108
{
93109
mUserIsSudoer = userIsSudoer;

src/RemoteMachineComboBox.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RemoteMachineComboBox::RemoteMachineComboBox(QWidget* parent):
3030

3131
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
3232
// placeholder text is only supported in Qt 4.7 onwards
33-
mUI.host->setPlaceholderText(QObject::tr("username@hostname"));
33+
mUI.host->setPlaceholderText(QObject::tr("username@hostname [sudo]"));
3434
#endif
3535

3636
mQSettings = new QSettings(this);
@@ -77,11 +77,12 @@ unsigned int RemoteMachineComboBox::getRecentMachineCount() const
7777
return mRecentTargets.size();
7878
}
7979

80-
void RemoteMachineComboBox::notifyTargetUsed(const QString& target)
80+
void RemoteMachineComboBox::notifyTargetUsed(const QString& target, bool userIsSudoer)
8181
{
8282
QString host;
8383
unsigned short port;
84-
OscapScannerRemoteSsh::splitTarget(target, host, port);
84+
bool placeholder;
85+
OscapScannerRemoteSsh::splitTarget(target, host, port, placeholder);
8586

8687
// skip invalid suggestions
8788
if (host.isEmpty() || port == 0)
@@ -90,7 +91,8 @@ void RemoteMachineComboBox::notifyTargetUsed(const QString& target)
9091
const unsigned int machineCount = getRecentMachineCount();
9192

9293
// this moves target to the beginning of the list if it was in the list already
93-
mRecentTargets.prepend(target);
94+
QString targetWithSudo = target + (userIsSudoer ? " sudo" : "");
95+
mRecentTargets.prepend(targetWithSudo);
9496
mRecentTargets.removeDuplicates();
9597

9698
setRecentMachineCount(machineCount);
@@ -106,6 +108,7 @@ void RemoteMachineComboBox::clearHistory()
106108
{
107109
mUI.host->setText("");
108110
mUI.port->setValue(22);
111+
mUI.userIsSudoer->setChecked(false);
109112

110113
const unsigned int machineCount = getRecentMachineCount();
111114
mRecentTargets.clear();
@@ -167,6 +170,7 @@ void RemoteMachineComboBox::updateHostPort(int index)
167170
{
168171
mUI.host->setText("");
169172
mUI.port->setValue(22);
173+
mUI.userIsSudoer->setChecked(false);
170174
return;
171175
}
172176

@@ -179,10 +183,11 @@ void RemoteMachineComboBox::updateHostPort(int index)
179183

180184
QString host;
181185
unsigned short port;
186+
bool userIsSudoer;
182187

183-
OscapScannerRemoteSsh::splitTarget(target, host, port);
188+
OscapScannerRemoteSsh::splitTarget(target, host, port, userIsSudoer);
184189

185190
mUI.host->setText(host);
186191
mUI.port->setValue(port);
187-
192+
mUI.userIsSudoer->setChecked(userIsSudoer);
188193
}

0 commit comments

Comments
 (0)