summaryrefslogtreecommitdiffstats
path: root/src/tdesshaskpass.cpp
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2021-08-26 14:29:14 +0200
committerSlávek Banko <[email protected]>2021-08-26 15:42:32 +0200
commit4d49d83565a99e1c41e3a7e8e0c2732afcd83b16 (patch)
tree03aeae3eceae2ca6bfc27fe84c932ef20f04bab5 /src/tdesshaskpass.cpp
parent031ded8cf8bce48796f34575958d60495b3de42b (diff)
downloadtdesshaskpass-4d49d83565a99e1c41e3a7e8e0c2732afcd83b16.tar.gz
tdesshaskpass-4d49d83565a99e1c41e3a7e8e0c2732afcd83b16.zip
Rebrand K => TDE.
Signed-off-by: Slávek Banko <[email protected]>
Diffstat (limited to 'src/tdesshaskpass.cpp')
-rw-r--r--src/tdesshaskpass.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/tdesshaskpass.cpp b/src/tdesshaskpass.cpp
new file mode 100644
index 0000000..3914838
--- /dev/null
+++ b/src/tdesshaskpass.cpp
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2006 Hans van Leeuwen <[email protected]>
+ * Copyright (C) 2008 Armin Berres <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#include <iostream>
+#include <tdewallet.h>
+#include <kpassdlg.h>
+#include <tdeaboutdata.h>
+#include <tdeapplication.h>
+#include <tdecmdlineargs.h>
+#include <tdelocale.h>
+
+static TDECmdLineOptions options[] =
+{
+ { "+[dialog]", I18N_NOOP( "Dialog message. Leave undefined for default message" ), 0 },
+ TDECmdLineLastOption
+};
+
+int main(int argc, char **argv)
+{
+
+ TDEAboutData about (
+ "tdesshaskpass", // appName
+ I18N_NOOP("tdesshaskpass"), // programName
+ "0.4.1", // version
+ I18N_NOOP("TDE version of ssh-askpass"), // shortDescription
+ TDEAboutData::License_GPL, // licenseType
+ "(c) 2006 Hans van Leeuwen\n(c) 2008 Armin Berres", // copyrightStatement statement
+ I18N_NOOP("tdesshaskpass allows you to interactively prompt users for a passphrase for ssh-add"), // text
+ "https://mirror.git.trinitydesktop.org/gitea/TDE/tdesshaskpass", // homePageAddress
+ "[email protected]" // bugsEmailAddress
+ );
+ about.addAuthor("Armin Berres", 0, "[email protected]");
+ about.addAuthor("Hans van Leeuwen", 0, "[email protected]");
+
+ TDECmdLineArgs::init(argc, argv, &about);
+ TDECmdLineArgs::addCmdLineOptions( options );
+ TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
+
+ TDEApplication app;
+
+
+ // Disable Session Management and DCOP. We don't need it.
+ app.disableSessionManagement();
+ app.disableAutoDcopRegistration();
+
+
+ // Declare variables
+ TQString walletFolder = about.appName();
+ TQString dialog = I18N_NOOP("Please enter password"); // Default dialog text
+ TQString keyFile;
+ TQString password;
+
+
+ // Parse commandline arguments
+ if ( args->count() > 0 ) {
+ dialog = args->arg(0);
+ keyFile = dialog.section(" ", -2).remove(":");
+ }
+ args->clear();
+
+
+ // Open TDEWallet to see if a password was previously stored.
+ TDEWallet::Wallet *wallet = TDEWallet::Wallet::openWallet( TDEWallet::Wallet::NetworkWallet(), 0 );
+
+ if ( wallet && wallet->hasFolder(walletFolder) ) {
+ wallet->setFolder(walletFolder);
+
+ TQString retrievedPass;
+
+ wallet->readPassword(keyFile, retrievedPass);
+
+ if (!retrievedPass.isNull())
+ {
+ password = retrievedPass;
+ }
+ }
+
+
+ // Password could not be retrieved from wallet. Open password dialog
+ if (password.isNull())
+ {
+ // create the password dialog, but only show "Enable Keep" button, if the wallet is opened
+ KPasswordDialog *kpd = new KPasswordDialog(KPasswordDialog::Password, wallet, 0);
+ kpd->setPrompt(dialog);
+ kpd->setCaption(i18n("tdesshaskpass"));
+ kpd->setAllowEmptyPasswords(false);
+ // We don't want to dump core when the password dialog is shown, because it could contain the entered password.
+ kpd->disableCoreDumps();
+
+ if ( kpd->exec() == KDialog::Accepted ) {
+ password = kpd->password();
+ }
+
+ // If "Enable Keep" is enabled, open/create a folder in TDEWallet and store the password.
+ if (!password.isNull() && wallet && kpd->keep())
+ {
+ if ( !wallet->hasFolder( walletFolder ) ) {
+ wallet->createFolder(walletFolder);
+ }
+ wallet->setFolder(walletFolder);
+ wallet->writePassword(keyFile, password);
+ }
+
+ delete kpd;
+ }
+
+ // Close the wallet if it is opened.
+ if (wallet) {
+ TDEWallet::Wallet::closeWallet( TDEWallet::Wallet::NetworkWallet(), false );
+ }
+
+ // Finally return the password if one has been entered
+ if(!password.isNull())
+ {
+ std::cout << password.local8Bit();
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}