10#include "sshprocess.h"
13#include "stubprocess_p.h"
20extern int kdesuDebugArea();
24using namespace KDESuPrivate;
26class SshProcessPrivate :
public StubProcessPrivate
41 : StubProcess(*new SshProcessPrivate(host))
48SshProcess::~SshProcess() =
default;
64int SshProcess::checkInstall(
const char *password)
66 return exec(password, 1);
69int SshProcess::checkNeedPassword()
71 return exec(
nullptr, 2);
74int SshProcess::exec(
const char *password,
int check)
86 args +=
"StrictHostKeyChecking=no";
90 if (StubProcess::exec(
"ssh", args) < 0) {
91 return check ? SshNotFound : -1;
94 int ret = converseSsh(password, check);
97 qCCritical(KSU_LOG) <<
"[" << __FILE__ <<
":" << __LINE__ <<
"] "
98 <<
"Conversation with ssh failed.";
104 kill(m_pid, SIGTERM);
110 if (m_erase && password) {
111 memset(
const_cast<char *
>(password), 0, qstrlen(password));
114 ret = converseStub(check);
117 qCCritical(KSU_LOG) <<
"[" << __FILE__ <<
":" << __LINE__ <<
"] "
118 <<
"Conversation with kdesu_stub failed.";
121 }
else if (ret == 1) {
122 kill(m_pid, SIGTERM);
124 ret = SshIncorrectPassword;
132 setExitString(
"Waiting for forwarded connections to terminate");
133 ret = waitForChild();
146 Q_D(
const SshProcess);
163int SshProcess::converseSsh(
const char *password,
int check)
176 const uint len = line.
length();
184 if (line ==
"kdesu_stub") {
190 for (i = 0, j = 0, colon = 0; i < len; ++i) {
191 if (line[i] ==
':') {
196 if (!isspace(line[i])) {
200 if ((colon == 1) && (line[j] ==
':')) {
203 return SshNeedsPassword;
208 write(fd(), password, strlen(password));
209 write(fd(),
"\n", 1);
218 fprintf(stderr,
"ssh: %s\n", line.
constData());
244void SshProcess::virtual_hook(
int id,
void *data)
246 StubProcess::virtual_hook(
id, data);
Executes a remote command, using ssh.
const char * constData() const const
bool isEmpty() const const
bool isNull() const const
qsizetype length() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:50 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.