From 359294c33620c8328d61f67635046d7cc060530c Mon Sep 17 00:00:00 2001 From: Darrell Anderson Date: Fri, 17 May 2013 12:45:40 -0500 Subject: Rename kdessh -> tdessh and kdelirc -> tdelirc. --- tdessh/CMakeLists.txt | 36 +++++++++ tdessh/LICENSE.readme | 124 +++++++++++++++++++++++++++++++ tdessh/Makefile.am | 17 +++++ tdessh/sshdlg.cpp | 80 ++++++++++++++++++++ tdessh/sshdlg.h | 33 +++++++++ tdessh/tdessh.cpp | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 491 insertions(+) create mode 100644 tdessh/CMakeLists.txt create mode 100644 tdessh/LICENSE.readme create mode 100644 tdessh/Makefile.am create mode 100644 tdessh/sshdlg.cpp create mode 100644 tdessh/sshdlg.h create mode 100644 tdessh/tdessh.cpp (limited to 'tdessh') diff --git a/tdessh/CMakeLists.txt b/tdessh/CMakeLists.txt new file mode 100644 index 0000000..9681682 --- /dev/null +++ b/tdessh/CMakeLists.txt @@ -0,0 +1,36 @@ +################################################# +# +# (C) 2012 Golubev Alexander +# fatzer2 (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +add_definitions( + -DQT_NO_CAST_ASCII +) + + +##### tdessh (executable) ####################### + +tde_add_executable( tdessh AUTOMOC + SOURCES tdessh.cpp sshdlg.cpp + LINK tdeui-shared tdesu-shared + DESTINATION ${BIN_INSTALL_DIR} +) + diff --git a/tdessh/LICENSE.readme b/tdessh/LICENSE.readme new file mode 100644 index 0000000..3ce8813 --- /dev/null +++ b/tdessh/LICENSE.readme @@ -0,0 +1,124 @@ +tdessh - a TDE front end to ssh + +Copyright (c) 1999,2000 by Geert Jansen + + 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/tdessh/Makefile.am b/tdessh/Makefile.am new file mode 100644 index 0000000..84f1b5b --- /dev/null +++ b/tdessh/Makefile.am @@ -0,0 +1,17 @@ +## Makefile.am for tdessh +AM_CPPFLAGS = -DQT_NO_CAST_ASCII + +INCLUDES= $(all_includes) + +## tdessh +bin_PROGRAMS = tdessh +tdessh_SOURCES = tdessh.cpp sshdlg.cpp +tdessh_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor +tdessh_LDADD = $(LIB_TDEUI) -ltdesu +tdessh_METASOURCES = AUTO +noinst_HEADERS = sshdlg.h + +## Messages +messages: + $(XGETTEXT) $(tdessh_SOURCES) -o $(podir)/tdessh.pot + diff --git a/tdessh/sshdlg.cpp b/tdessh/sshdlg.cpp new file mode 100644 index 0000000..a43c9d0 --- /dev/null +++ b/tdessh/sshdlg.cpp @@ -0,0 +1,80 @@ +/* vi: ts=8 sts=4 sw=4 + * + * $Id$ + * + * This file is part of the KDE project, module tdesu. + * Copyright (C) 2000 Geert Jansen + */ + +#include +#include + +#include +#include "sshdlg.h" + + +TDEsshDialog::TDEsshDialog(TQCString host, TQCString user, TQCString stub, + TQString prompt, bool enableKeep) + : KPasswordDialog(Password, enableKeep, 0) +{ + m_Host = host; + m_User = user; + m_Stub = stub; + + setCaption(TQString::fromLatin1("%1@%2").arg(TQString(m_User)).arg(TQString(m_Host))); + + // Make the prompt a little more polite :-) + if (prompt.lower().left(6) == TQString::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); +} + + +TDEsshDialog::~TDEsshDialog() +{ +} + + +bool TDEsshDialog::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 'tdesu_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/tdessh/sshdlg.h b/tdessh/sshdlg.h new file mode 100644 index 0000000..79415ad --- /dev/null +++ b/tdessh/sshdlg.h @@ -0,0 +1,33 @@ +/* vi: ts=8 sts=4 sw=4 + * + * $Id$ + * + * This file is part of the KDE project, module tdesu. + * Copyright (C) 2000 Geert Jansen + */ + +#ifndef __SshDlg_h_Included__ +#define __SshDlg_h_Included__ + +#include + +class TDEsshDialog + : public KPasswordDialog +{ + Q_OBJECT + + +public: + TDEsshDialog(TQCString host, TQCString user, TQCString stub, + TQString prompt, bool enableKeep); + ~TDEsshDialog(); + +protected: + bool checkPassword(const char *password); + +private: + TQCString m_User, m_Host, m_Stub; +}; + + +#endif // __SshDlg_h_Included__ diff --git a/tdessh/tdessh.cpp b/tdessh/tdessh.cpp new file mode 100644 index 0000000..593a0fd --- /dev/null +++ b/tdessh/tdessh.cpp @@ -0,0 +1,201 @@ +/* vi: ts=8 sts=4 sw=4 + * + * $Id$ + * + * This file is part of the KDE project, module tdesu. + * Copyright (C) 2000 Geert Jansen + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "sshdlg.h" + +static TDECmdLineOptions options[] = +{ + { "+host", I18N_NOOP("Specifies the remote host"), 0 }, + { "+command", I18N_NOOP("The command to run"), 0 }, + { "u ", I18N_NOOP("Specifies the target uid"), 0 }, + { "s ", I18N_NOOP("Specify remote stub location"), "tdesu_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 }, + TDECmdLineLastOption +}; + + +int main(int argc, char *argv[]) +{ + TDEAboutData aboutData("tdessh", I18N_NOOP("TDE ssh"), + VERSION, I18N_NOOP("Runs a program on a remote host"), + TDEAboutData::License_Artistic, + "Copyright (c) 2000 Geert Jansen"); + aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), + "jansen@kde.org", "http://www.stack.nl/~geertj/"); + + TDECmdLineArgs::init(argc, argv, &aboutData); + TDECmdLineArgs::addCmdLineOptions(options); + + TDEApplication app; + TDECmdLineArgs *args = TDECmdLineArgs::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) + TDECmdLineArgs::usage(i18n("No command or host specified.")); + + // Check if ssh is available + if (TDEStandardDirs::findExe(TQString::fromLatin1("ssh")).isEmpty()) + { + kdError(1511) << "ssh not found\n"; + exit(1); + } + + // Get remote userid + TQCString 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 + TQCString stub = args->getOption("s"); + + // Get remote host, command + TQCString host = args->arg(0); + TQCString command = args->arg(1); + for (int i=2; icount(); 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 tdesud? + 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 + TDEConfig *config = TDEGlobal::config(); + config->setGroup(TQString::fromLatin1("Passwords")); + int timeout = config->readNumEntry(TQString::fromLatin1("Timeout"), defTimeout); + + SshProcess proc(host, user); + proc.setStub(stub); + int needpw = proc.checkNeedPassword(); + if (needpw < 0) + { + TQString msg = i18n("Ssh returned with an error!\n" + "The error message is:\n\n"); + msg += proc.error(); + KMessageBox::error(0L, msg); + exit(1); + } + + TQCString password; + if (needpw != 0) + { + TDEsshDialog *dlg = new TDEsshDialog(host, user, stub, + proc.prompt(), keep && !terminal); + dlg->addLine(i18n("Command"), command); + int res = dlg->exec(); + if (res == TDEsshDialog::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); + } +} + -- cgit v1.2.1