summaryrefslogtreecommitdiffstats
path: root/kdessh
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /kdessh
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdessh')
-rw-r--r--kdessh/LICENSE.readme124
-rw-r--r--kdessh/Makefile.am17
-rw-r--r--kdessh/README3
-rw-r--r--kdessh/kdessh.cpp201
-rw-r--r--kdessh/sshdlg.cpp80
-rw-r--r--kdessh/sshdlg.h32
6 files changed, 457 insertions, 0 deletions
diff --git a/kdessh/LICENSE.readme b/kdessh/LICENSE.readme
new file mode 100644
index 0000000..eb08ce6
--- /dev/null
+++ b/kdessh/LICENSE.readme
@@ -0,0 +1,124 @@
+kdessh - a KDE front end to ssh
+
+Copyright (c) 1999,2000 by Geert Jansen <jansen@kde.org>
+
+ The "Artistic License"
+
+ Preamble
+
+ The intent of this document is to state the conditions under which a
+ Package may be copied, such that the Copyright Holder maintains some
+ semblance of artistic control over the development of the package,
+ while giving the users of the package the right to use and
+ distribute the Package in a more-or-less customary fashion, plus the
+ right to make reasonable modifications.
+
+ Definitions:
+
+ * "Package" refers to the collection of files distributed by the
+ Copyright Holder, and derivatives of that collection of files
+ created through textual modification.
+
+ * "Standard Version" refers to such a Package if it has not been
+ modified, or has been modified in accordance with the wishes of
+ the Copyright Holder.
+
+ * "Copyright Holder" is whoever is named in the copyright or
+ copyrights for the package.
+
+ * "You" is you, if you're thinking about copying or distributing
+ this Package.
+
+ * "Reasonable copying fee" is whatever you can justify on the
+ basis of media cost, duplication charges, time of people
+ involved, and so on. (You will not be required to justify it to
+ the Copyright Holder, but only to the computing community at
+ large as a market that must bear the fee.)
+
+ * "Freely Available" means that no fee is charged for the item
+ itself, though there may be fees involved in handling the item.
+ It also means that recipients of the item may redistribute it
+ under the same conditions they received it.
+
+ 1. You may make and give away verbatim copies of the source form of
+ the Standard Version of this Package without restriction, provided
+ that you duplicate all of the original copyright notices and
+ associated disclaimers.
+
+ 2. You may apply bug fixes, portability fixes and other
+ modifications derived from the Public Domain or from the Copyright
+ Holder. A Package modified in such a way shall still be considered
+ the Standard Version.
+
+ 3. You may otherwise modify your copy of this Package in any way,
+ provided that you insert a prominent notice in each changed file
+ stating how and when you changed that file, and provided that you do
+ at least ONE of the following:
+
+ a) place your modifications in the Public Domain or
+ otherwise make them Freely Available, such as by posting
+ said modifications to Usenet or an equivalent medium, or
+ placing the modifications on a major archive site such as
+ ftp.uu.net, or by allowing the Copyright Holder to include
+ your modifications in the Standard Version of the Package.
+
+ b) use the modified Package only within your corporation
+ or organization.
+
+ c) rename any non-standard executables so the names do not
+ conflict with standard executables, which must also be
+ provided, and provide a separate manual page for each
+ non-standard executable that clearly documents how it
+ differs from the Standard Version.
+
+ d) make other distribution arrangements with the Copyright
+ Holder.
+
+ 4. You may distribute the programs of this Package in object code or
+ executable form, provided that you do at least ONE of the following:
+
+ a) distribute a Standard Version of the executables and
+ library files, together with instructions (in the manual
+ page or equivalent) on where to get the Standard Version.
+
+ b) accompany the distribution with the machine-readable
+ source of the Package with your modifications.
+
+ c) accompany any non-standard executables with their
+ corresponding Standard Version executables, giving the
+ non-standard executables non-standard names, and clearly
+ documenting the differences in manual pages (or
+ equivalent), together with instructions on where to get
+ the Standard Version.
+
+ d) make other distribution arrangements with the Copyright
+ Holder.
+
+ 5. You may charge a reasonable copying fee for any distribution of
+ this Package. You may charge any fee you choose for support of this
+ Package. You may not charge a fee for this Package itself. However,
+ you may distribute this Package in aggregate with other (possibly
+ commercial) programs as part of a larger (possibly commercial)
+ software distribution provided that you do not advertise this
+ Package as a product of your own.
+
+ 6. The scripts and library files supplied as input to or produced as
+ output from the programs of this Package do not automatically fall
+ under the copyright of this Package, but belong to whomever
+ generated them, and may be sold commercially, and may be aggregated
+ with this Package.
+
+ 7. C or perl subroutines supplied by you and linked into this
+ Package shall not be considered part of this Package.
+
+ 8. The name of the Copyright Holder may not be used to endorse or
+ promote products derived from this software without specific prior
+ written permission.
+
+ 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+
+ The End
+
+
diff --git a/kdessh/Makefile.am b/kdessh/Makefile.am
new file mode 100644
index 0000000..987bcd7
--- /dev/null
+++ b/kdessh/Makefile.am
@@ -0,0 +1,17 @@
+## Makefile.am for kdessh
+AM_CPPFLAGS = -DQT_NO_CAST_ASCII
+
+INCLUDES= $(all_includes)
+
+## kdessh
+bin_PROGRAMS = kdessh
+kdessh_SOURCES = kdessh.cpp sshdlg.cpp
+kdessh_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kdessh_LDADD = $(LIB_KDEUI) -lkdesu
+kdessh_METASOURCES = AUTO
+noinst_HEADERS = sshdlg.h
+
+## Messages
+messages:
+ $(XGETTEXT) $(kdessh_SOURCES) -o $(podir)/kdessh.pot
+
diff --git a/kdessh/README b/kdessh/README
new file mode 100644
index 0000000..b897486
--- /dev/null
+++ b/kdessh/README
@@ -0,0 +1,3 @@
+kdessh: A KDE front end to ssh.
+
+Please report bugs to Geert Jansen <jansen@kde.org>.
diff --git a/kdessh/kdessh.cpp b/kdessh/kdessh.cpp
new file mode 100644
index 0000000..6fa10ca
--- /dev/null
+++ b/kdessh/kdessh.cpp
@@ -0,0 +1,201 @@
+/* vi: ts=8 sts=4 sw=4
+ *
+ * $Id$
+ *
+ * This file is part of the KDE project, module kdesu.
+ * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+#include <string.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <sys/time.h>
+#include <sys/resource.h>
+
+
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kstandarddirs.h>
+#include <kconfig.h>
+#include <klocale.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <kmessagebox.h>
+
+#include <kdesu/ssh.h>
+#include <kdesu/client.h>
+#include <kdesu/defaults.h>
+
+#include "sshdlg.h"
+
+static KCmdLineOptions options[] =
+{
+ { "+host", I18N_NOOP("Specifies the remote host"), 0 },
+ { "+command", I18N_NOOP("The command to run"), 0 },
+ { "u <user>", I18N_NOOP("Specifies the target uid"), 0 },
+ { "s <path>", I18N_NOOP("Specify remote stub location"), "kdesu_stub" },
+ { "n", I18N_NOOP("Do not keep password"), 0 },
+ { "q", I18N_NOOP("Stop the daemon (forgets all passwords)"), 0 },
+ { "t", I18N_NOOP("Enable terminal output (no password keeping)"), 0 },
+ KCmdLineLastOption
+};
+
+
+int main(int argc, char *argv[])
+{
+ KAboutData aboutData("kdessh", I18N_NOOP("KDE ssh"),
+ VERSION, I18N_NOOP("Runs a program on a remote host"),
+ KAboutData::License_Artistic,
+ "Copyright (c) 2000 Geert Jansen");
+ aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"),
+ "jansen@kde.org", "http://www.stack.nl/~geertj/");
+
+ KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineArgs::addCmdLineOptions(options);
+
+ KApplication app;
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ // Stop daemon and exit?
+ if (args->isSet("q"))
+ {
+ KDEsuClient client;
+ if (client.ping() == -1)
+ {
+ kdError(1511) << "Daemon not running -- nothing to stop\n";
+ exit(1);
+ }
+ if (client.stopServer() != -1)
+ {
+ kdDebug(1511) << "Daemon stopped\n";
+ exit(0);
+ }
+ kdError(1511) << "Could not stop daemon\n";
+ exit(1);
+ }
+
+ if (args->count() < 2)
+ KCmdLineArgs::usage(i18n("No command or host specified."));
+
+ // Check if ssh is available
+ if (KStandardDirs::findExe(QString::fromLatin1("ssh")).isEmpty())
+ {
+ kdError(1511) << "ssh not found\n";
+ exit(1);
+ }
+
+ // Get remote userid
+ QCString user = args->getOption("u");
+ if (user.isNull())
+ {
+ struct passwd *pw = getpwuid(getuid());
+ if (pw == 0L)
+ {
+ kdError(1511) << "You don't exist!\n";
+ exit(1);
+ }
+ user = pw->pw_name;
+ }
+
+ // Remote stub location
+ QCString stub = args->getOption("s");
+
+ // Get remote host, command
+ QCString host = args->arg(0);
+ QCString command = args->arg(1);
+ for (int i=2; i<args->count(); i++)
+ {
+ command += " ";
+ command += args->arg(i);
+ }
+
+ // Check for daemon and start if necessary
+ bool have_daemon = true;
+ KDEsuClient client;
+ if (!client.isServerSGID())
+ {
+ kdWarning(1511) << "Daemon not safe (not sgid), not using it.\n";
+ have_daemon = false;
+ }
+ else if ((client.ping() == -1) && (client.startServer() == -1))
+ {
+ kdWarning(1511) << "Could not start daemon, reduced functionality.\n";
+ have_daemon = false;
+ }
+
+ // Try to exec the command with kdesud?
+ bool keep = !args->isSet("n") && have_daemon;
+ bool terminal = args->isSet("t");
+ if (keep && !terminal)
+ {
+ client.setHost(host);
+ if (client.exec(command, user) != -1)
+ return 0;
+ }
+
+ // Set core dump size to 0 because we will have
+ // root's password in memory.
+ struct rlimit rlim;
+ rlim.rlim_cur = rlim.rlim_max = 0;
+ if (setrlimit(RLIMIT_CORE, &rlim))
+ {
+ kdError(1511) << "rlimit(): " << perror << "\n";
+ exit(1);
+ }
+
+
+ // Read configuration
+ KConfig *config = KGlobal::config();
+ config->setGroup(QString::fromLatin1("Passwords"));
+ int timeout = config->readNumEntry(QString::fromLatin1("Timeout"), defTimeout);
+
+ SshProcess proc(host, user);
+ proc.setStub(stub);
+ int needpw = proc.checkNeedPassword();
+ if (needpw < 0)
+ {
+ QString msg = i18n("Ssh returned with an error!\n"
+ "The error message is:\n\n");
+ msg += proc.error();
+ KMessageBox::error(0L, msg);
+ exit(1);
+ }
+
+ QCString password;
+ if (needpw != 0)
+ {
+ KDEsshDialog *dlg = new KDEsshDialog(host, user, stub,
+ proc.prompt(), keep && !terminal);
+ dlg->addLine(i18n("Command"), command);
+ int res = dlg->exec();
+ if (res == KDEsshDialog::Rejected)
+ exit(0);
+ keep = dlg->keep();
+ password = dlg->password();
+ delete dlg;
+ } else
+ keep = 0;
+
+ // Make the dialog go away.
+ app.processEvents();
+
+ // Run command
+ if (keep && have_daemon)
+ {
+ client.setHost(host);
+ client.setPass(password, timeout);
+ return client.exec(command, user);
+ } else
+ {
+ proc.setCommand(command);
+ proc.setTerminal(terminal);
+ proc.setErase(true);
+ return proc.exec(password);
+ }
+}
+
diff --git a/kdessh/sshdlg.cpp b/kdessh/sshdlg.cpp
new file mode 100644
index 0000000..a652688
--- /dev/null
+++ b/kdessh/sshdlg.cpp
@@ -0,0 +1,80 @@
+/* vi: ts=8 sts=4 sw=4
+ *
+ * $Id$
+ *
+ * This file is part of the KDE project, module kdesu.
+ * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
+ */
+
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include <kdesu/ssh.h>
+#include "sshdlg.h"
+
+
+KDEsshDialog::KDEsshDialog(QCString host, QCString user, QCString stub,
+ QString prompt, bool enableKeep)
+ : KPasswordDialog(Password, enableKeep, 0)
+{
+ m_Host = host;
+ m_User = user;
+ m_Stub = stub;
+
+ setCaption(QString::fromLatin1("%1@%2").arg(m_User).arg(m_Host));
+
+ // Make the prompt a little more polite :-)
+ if (prompt.lower().left(6) == QString::fromLatin1("enter "))
+ prompt.remove(0, 6);
+ int pos = prompt.find(':');
+ if (pos != -1)
+ prompt.remove(pos, 10);
+ prompt += '.';
+ prompt.prepend(i18n("The action you requested needs authentication. "
+ "Please enter "));
+ setPrompt(prompt);
+}
+
+
+KDEsshDialog::~KDEsshDialog()
+{
+}
+
+
+bool KDEsshDialog::checkPassword(const char *password)
+{
+ SshProcess proc(m_Host, m_User);
+ proc.setStub(m_Stub);
+
+ int ret = proc.checkInstall(password);
+ switch (ret)
+ {
+ case -1:
+ KMessageBox::error(this, i18n("Conversation with ssh failed.\n"));
+ done(Rejected);
+ return false;
+
+ case 0:
+ return true;
+
+ case SshProcess::SshNotFound:
+ KMessageBox::sorry(this,
+ i18n("The programs 'ssh' or 'kdesu_stub' cannot be found.\n"
+ "Make sure your PATH is set correctly."));
+ done(Rejected);
+ return false;
+
+ case SshProcess::SshIncorrectPassword:
+ KMessageBox::sorry(this, i18n("Incorrect password. Please try again."));
+ return false;
+
+ default:
+ KMessageBox::error(this, i18n("Internal error: Illegal return from "
+ "SshProcess::checkInstall()"));
+ done(Rejected);
+ }
+ return true;
+}
+
+
+#include "sshdlg.moc"
diff --git a/kdessh/sshdlg.h b/kdessh/sshdlg.h
new file mode 100644
index 0000000..1090312
--- /dev/null
+++ b/kdessh/sshdlg.h
@@ -0,0 +1,32 @@
+/* vi: ts=8 sts=4 sw=4
+ *
+ * $Id$
+ *
+ * This file is part of the KDE project, module kdesu.
+ * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
+ */
+
+#ifndef __SshDlg_h_Included__
+#define __SshDlg_h_Included__
+
+#include <kpassdlg.h>
+
+class KDEsshDialog
+ : public KPasswordDialog
+{
+ Q_OBJECT
+
+public:
+ KDEsshDialog(QCString host, QCString user, QCString stub,
+ QString prompt, bool enableKeep);
+ ~KDEsshDialog();
+
+protected:
+ bool checkPassword(const char *password);
+
+private:
+ QCString m_User, m_Host, m_Stub;
+};
+
+
+#endif // __SshDlg_h_Included__