28 #include <sys/types.h>
32 #include <tqcstring.h>
36 #include <kstandarddirs.h>
42 SshProcess::SshProcess(
const TQCString &host,
const TQCString &user,
const TQCString &command)
47 m_Stub =
"kdesu_stub";
52 SshProcess::~SshProcess()
65 return exec(password, 1);
81 args +=
"-l"; args += m_User;
82 args +=
"-o"; args +=
"StrictHostKeyChecking=no";
83 args += m_Host; args += m_Stub;
87 return check ? SshNotFound : -1;
90 int ret = ConverseSsh(password, check);
94 kdError(900) << k_lineinfo <<
"Conversation with ssh failed\n";
101 kill(m_Pid, SIGTERM);
107 if (m_bErase && password)
109 char *ptr =
const_cast<char *
>(password);
110 const uint plen = strlen(password);
111 for (
unsigned i=0; i < plen; i++)
119 kdError(900) << k_lineinfo <<
"Converstation with kdesu_stub failed\n";
124 kill(m_Pid, SIGTERM);
126 ret = SshIncorrectPassword;
135 setExitString(
"Waiting for forwarded connections to terminate");
149 TQCString SshProcess::dcopForward()
159 int i = srv.find(
'/');
162 if (srv.left(i) !=
"tcp")
164 int j = srv.find(
':', ++i);
167 TQCString host = srv.mid(i, j-i);
169 int port = srv.mid(++j).toInt(&ok);
173 m_dcopPort = 10000 + (int) ((40000.0 * rand()) / (1.0 + RAND_MAX));
174 result.sprintf(
"%d:%s:%d", m_dcopPort, host.data(), port);
192 int SshProcess::ConverseSsh(
const char *password,
int check)
194 unsigned i, j, colon;
202 const uint len = line.length();
209 if (line ==
"kdesu_stub")
216 for (i=0,j=0,colon=0; i<len; i++)
223 if (!isspace(line[i]))
226 if ((colon == 1) && (line[j] ==
':'))
231 return SshNeedsPassword;
234 write(m_Fd, password, strlen(password));
235 write(m_Fd,
"\n", 1);
241 m_Error += line; m_Error +=
"\n";
243 fprintf(stderr,
"ssh: %s\n", line.data());
266 TQCString SshProcess::displayAuth()
275 return TQCString().sprintf(
"tcp/localhost:%d", m_dcopPort);
278 void SshProcess::virtual_hook(
int id,
void* data )
279 { StubProcess::virtual_hook(
id, data ); }