28 #include <sys/types.h>
32 #include <tqcstring.h>
35 #include <tdelocale.h>
36 #include <tdestandarddirs.h>
42 SshProcess::SshProcess(
const TQCString &host,
const TQCString &user,
const TQCString &command)
47 m_Stub =
"tdesu_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 tdesu_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 ==
"tdesu_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 ); }
int exec(const TQCString &command, const QCStringList &args)
Forks off and execute a command.
int ConverseStub(int check)
Exchange all parameters with tdesu_stub.
virtual TQCString display()
This virtual function can be overloaded when special behavior is desired.
int exec(const char *password, int check=0)
Executes the command.
int checkNeedPassword()
Checks if the current user@host needs a password.
virtual TQCString dcopServer()
See display.
TQCString readLine(bool block=true)
Reads a line from the program's standard out.
void setExitString(const TQCString &exit)
Sets the exit string.
int checkInstall(const char *password)
Checks if the stub is installed and if the password is correct.
void setDcopTransport(const TQCString &dcopTransport)
Specify dcop transport.
void setStub(const TQCString &stub)
Sets the localtion of the remote stub.
int WaitSlave()
Waits until the pty has cleared the ECHO flag.
int waitForChild()
Waits for the child to exit.
void unreadLine(const TQCString &line, bool addNewline=true)
Puts back a line of input.
void setTerminal(bool terminal)
Enables/disables terminal output.
virtual TQCString dcopServer()
See display.