summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sshkeys/main.cpp24
-rw-r--r--noncore/settings/sshkeys/sshkeys.cpp195
-rw-r--r--noncore/settings/sshkeys/sshkeys.h14
-rw-r--r--noncore/settings/sshkeys/sshkeysbase.ui87
4 files changed, 278 insertions, 42 deletions
diff --git a/noncore/settings/sshkeys/main.cpp b/noncore/settings/sshkeys/main.cpp
index 37be8bf..a7b1d56 100644
--- a/noncore/settings/sshkeys/main.cpp
+++ b/noncore/settings/sshkeys/main.cpp
@@ -3,2 +3,9 @@
#include "sshkeys.h"
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
@@ -6,8 +13,17 @@ int main(int argc, char *argv[])
{
- QPEApplication a(argc, argv);
- SSHKeysApp app;
+ QPEApplication a(argc, argv);
+ SSHKeysApp app;
+ int fd;
+
+ /* If we had a controlling TTY, detach from it.
+ This is to ensure the SSH uses ssh-askpass */
+ fd = open("/dev/tty", O_RDONLY);
+ if (fd != -1) {
+ ioctl(fd, TIOCNOTTY, NULL);
+ close(fd);
+ }
- a.showMainWidget(&app);
+ a.showMainWidget(&app);
- return a.exec();
+ return a.exec();
}
diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp
index 08ce18d..5095d16 100644
--- a/noncore/settings/sshkeys/sshkeys.cpp
+++ b/noncore/settings/sshkeys/sshkeys.cpp
@@ -6,3 +6,13 @@
#include <qpushbutton.h>
-#include <qtable.h>
+#include <qlistview.h>
+#include <qcombobox.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <ctype.h>
+
+static char *keynames[] = { "identity", "id_rsa", "id_dsa" };
@@ -11,2 +21,4 @@ SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl )
{
+ char *home = getenv("HOME");
+ unsigned i;
@@ -16,5 +28,21 @@ SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl )
- KeyList->horizontalHeader()->setLabel(0, tr("Key"));
- KeyList->horizontalHeader()->setLabel(1, tr("Size"));
- KeyList->horizontalHeader()->setLabel(2, tr("Fingerprint"));
+ connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)),
+ this, SLOT(log_sshadd_output(OProcess*,char*,int)));
+ connect(&addprocess, SIGNAL(processExited(OProcess*)),
+ this, SLOT(ssh_add_exited(OProcess*)));
+
+ connect(KeyFileName, SIGNAL(textChanged(const QString&)),
+ this, SLOT(add_text_changed(const QString&)));
+
+ if (home) {
+ for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) {
+ char thiskeyname[32];
+
+ thiskeyname[31] = 0;
+ snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]);
+ if (!access(thiskeyname, R_OK)) {
+ KeyFileName->insertItem(thiskeyname);
+ }
+ }
+ }
@@ -30,14 +58,27 @@ void SSHKeysApp::doRefreshListButton()
OProcess sshadd_process;
+ QListViewItem *t = KeyList->firstChild();
+ while(t) {
+ QListViewItem *next = t->nextSibling();
+ KeyList->takeItem(t);
+ delete(t);
+ t = next;
+ }
+
connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)),
this, SLOT(get_list_keys_output(OProcess*,char*,int)));
-
- TextOutput->append("Running ssh-add -l\n");
+
+ keystate = KeySize;
+ incoming_keyname="";
+ incoming_keysize="";
+ incoming_keyfingerprint="";
+
+// log_text("Running ssh-add -l");
sshadd_process << "ssh-add" << "-l";
bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput);
- if (!ret)
- TextOutput->append("Error running ssh-add\n");
- KeyList->setText(0, 0, "dwmw2@infradead.org (RSA v1)");
- KeyList->setText(0, 1, "1024");
- KeyList->setText(0, 2, "78:24:04:95:40:fc:b2:80:9b:94:d5:ae:19:56:19:65");
+ if (!ret) {
+ log_text("Error running ssh-add");
+ return;
+ }
+
}
@@ -46,5 +87,99 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen)
{
- TextOutput->append(buffer);
+ int i;
+ (void) proc;
+
+ for (i=0; i<buflen; i++) {
+ switch(keystate) {
+ case Noise:
+ noise:
+ if (buffer[i] == '\n') {
+ log_text(incoming_noise.local8Bit());
+ incoming_noise = "";
+ keystate = KeySize;
+ } else {
+ incoming_noise += buffer[i];
+ }
+ break;
+
+ case KeySize:
+ if (isdigit(buffer[i])) {
+ incoming_keysize += buffer[i];
+ } else if (buffer[i] == ' ') {
+ keystate = KeyFingerprint;
+ } else {
+ incoming_keysize = "";
+ incoming_noise = "";
+ keystate = Noise;
+ goto noise;
+ }
+ break;
+
+ case KeyFingerprint:
+ if (isxdigit(buffer[i]) || buffer[i] == ':') {
+ incoming_keyfingerprint += buffer[i];
+ } else if (buffer[i] == ' ') {
+ keystate = KeyName;
+ } else {
+ incoming_keysize = "";
+ incoming_keyfingerprint = "";
+ incoming_noise = "";
+ keystate = Noise;
+ goto noise;
+ }
+ break;
+
+ case KeyName:
+ if (buffer[i] == '\n') {
+ /* Wheee. Got one. */
+ KeyList->insertItem(new
+ QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint));
+ incoming_keysize = "";
+ incoming_keyfingerprint = "";
+ incoming_keyname = "";
+ keystate = KeySize;
+ } else if (isprint(buffer[i])) {
+ incoming_keyname += buffer[i];
+ } else {
+ incoming_keysize = "";
+ incoming_keyfingerprint = "";
+ incoming_noise = "";
+ keystate = Noise;
+ goto noise;
+ }
+ break;
+ }
+ }
}
+void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen)
+{
+ (void)proc;
+ (void)buflen;
+
+ log_text(buffer);
+}
+
+void SSHKeysApp::ssh_add_exited(OProcess *proc)
+{
+ (void)proc;
+
+ doRefreshListButton();
+ setEnabled(TRUE);
+ if (proc->exitStatus()) {
+
+ log_text(QString("ssh-add failed"));
+ }
+}
+
+void SSHKeysApp::add_text_changed(const QString &text)
+{
+ struct stat sbuf;
+
+ if (!text.length() || (!access(text.ascii(), R_OK) &&
+ !stat(text.ascii(), &sbuf) &&
+ S_ISREG(sbuf.st_mode)))
+ AddButton->setEnabled(TRUE);
+ else
+ AddButton->setEnabled(FALSE);
+}
@@ -52,7 +187,41 @@ void SSHKeysApp::doAddButton()
{
+ addprocess.clearArguments();
+
+ setEnabled(FALSE);
+
+ if (KeyFileName->currentText().length()) {
+ addprocess << "ssh-add" << "--" << KeyFileName->currentText();
+ log_text(QString("Running ssh-add -- ") + KeyFileName->currentText());
+ } else {
+ addprocess << "ssh-add";
+ log_text("Running ssh-add");
+ }
+ bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput);
+ if (!ret) {
+ log_text("Error running ssh-add");
+ doRefreshListButton();
+ setEnabled(TRUE);
+ }
+}
+void SSHKeysApp::log_text(const char *text)
+{
+ TextOutput->append(text);
+ TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE);
}
+
void SSHKeysApp::doRemoveAllButton()
{
-
+ OProcess sshadd_process;
+
+ connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)),
+ this, SLOT(log_sshadd_output(OProcess*,char*,int)));
+
+ log_text("Running ssh-add -D");
+ sshadd_process << "ssh-add" << "-D";
+ bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput);
+ if (!ret) {
+ log_text("Error running ssh-add");
+ }
+ doRefreshListButton();
}
diff --git a/noncore/settings/sshkeys/sshkeys.h b/noncore/settings/sshkeys/sshkeys.h
index 4a9f2fe..9a39a2c 100644
--- a/noncore/settings/sshkeys/sshkeys.h
+++ b/noncore/settings/sshkeys/sshkeys.h
@@ -5,4 +5,3 @@
#include "sshkeysbase.h"
-
-class OProcess;
+#include <opie/oprocess.h>
@@ -17,3 +16,9 @@ class SSHKeysApp : public SSHKeysBase
private:
- void sshadd(char **args);
+ void log_text(const char *text);
+ enum { Noise, KeyName, KeySize, KeyFingerprint } keystate;
+ QString incoming_keyname;
+ QString incoming_keysize;
+ QString incoming_keyfingerprint;
+ QString incoming_noise;
+ OProcess addprocess;
@@ -24,2 +29,5 @@ class SSHKeysApp : public SSHKeysBase
void get_list_keys_output(OProcess *proc, char *buffer, int buflen);
+ void log_sshadd_output(OProcess *proc, char *buffer, int buflen);
+ void ssh_add_exited(OProcess *proc);
+ void add_text_changed(const QString &text);
};
diff --git a/noncore/settings/sshkeys/sshkeysbase.ui b/noncore/settings/sshkeys/sshkeysbase.ui
index dc1df28..4c9daa9 100644
--- a/noncore/settings/sshkeys/sshkeysbase.ui
+++ b/noncore/settings/sshkeys/sshkeysbase.ui
@@ -30,4 +30,10 @@
</property>
- <widget row="0" column="1" rowspan="1" colspan="2" >
+ <widget row="0" column="1" >
<class>QComboBox</class>
+ <item>
+ <property>
+ <name>text</name>
+ <string></string>
+ </property>
+ </item>
<property stdset="1">
@@ -85,3 +91,3 @@
<name>enabled</name>
- <bool>false</bool>
+ <bool>true</bool>
</property>
@@ -92,3 +98,3 @@
</widget>
- <widget row="3" column="0" rowspan="1" colspan="3" >
+ <widget row="3" column="0" rowspan="1" colspan="2" >
<class>QMultiLineEdit</class>
@@ -99,2 +105,6 @@
<property stdset="1">
+ <name>enabled</name>
+ <bool>true</bool>
+ </property>
+ <property stdset="1">
<name>sizePolicy</name>
@@ -106,2 +116,9 @@
<property stdset="1">
+ <name>font</name>
+ <font>
+ <family>adobe-helvetica</family>
+ <pointsize>8</pointsize>
+ </font>
+ </property>
+ <property stdset="1">
<name>readOnly</name>
@@ -110,4 +127,46 @@
</widget>
- <widget row="2" column="0" rowspan="1" colspan="3" >
- <class>QTable</class>
+ <widget row="2" column="0" rowspan="1" colspan="2" >
+ <class>QListView</class>
+ <column>
+ <property>
+ <name>text</name>
+ <string>Key Name</string>
+ </property>
+ <property>
+ <name>clickable</name>
+ <bool>true</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property>
+ <name>text</name>
+ <string>Size</string>
+ </property>
+ <property>
+ <name>clickable</name>
+ <bool>true</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property>
+ <name>text</name>
+ <string>Fingerprint</string>
+ </property>
+ <property>
+ <name>clickable</name>
+ <bool>true</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>true</bool>
+ </property>
+ </column>
<property stdset="1">
@@ -120,21 +179,5 @@
<family>adobe-helvetica</family>
- <pointsize>9</pointsize>
+ <pointsize>8</pointsize>
</font>
</property>
- <property stdset="1">
- <name>resizePolicy</name>
- <enum>AutoOneFit</enum>
- </property>
- <property stdset="1">
- <name>numRows</name>
- <number>1</number>
- </property>
- <property stdset="1">
- <name>numCols</name>
- <number>3</number>
- </property>
- <property stdset="1">
- <name>showGrid</name>
- <bool>false</bool>
- </property>
</widget>