author | dwmw2 <dwmw2> | 2002-09-21 08:42:42 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2002-09-21 08:42:42 (UTC) |
commit | 51f94f502b2b9a92d562a3ad726ad58372860c5e (patch) (unidiff) | |
tree | 3f587669a6fd91b36a68a37d1c2d3182d92eaab8 | |
parent | 0bb8b359d20f7d5ead88c260c5560ab7b60358b9 (diff) | |
download | opie-51f94f502b2b9a92d562a3ad726ad58372860c5e.zip opie-51f94f502b2b9a92d562a3ad726ad58372860c5e.tar.gz opie-51f94f502b2b9a92d562a3ad726ad58372860c5e.tar.bz2 |
display stderr from ssh-add process too.
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp index 88acf94..c5e1170 100644 --- a/noncore/settings/sshkeys/sshkeys.cpp +++ b/noncore/settings/sshkeys/sshkeys.cpp | |||
@@ -3,248 +3,252 @@ | |||
3 | * | 3 | * |
4 | * (C) 2002 David Woodhouse <dwmw2@infradead.org> | 4 | * (C) 2002 David Woodhouse <dwmw2@infradead.org> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | #include "sshkeys.h" | 21 | #include "sshkeys.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <opie/oprocess.h> | 24 | #include <opie/oprocess.h> |
25 | #include <qmultilineedit.h> | 25 | #include <qmultilineedit.h> |
26 | #include <qpushbutton.h> | 26 | #include <qpushbutton.h> |
27 | #include <qlistview.h> | 27 | #include <qlistview.h> |
28 | #include <qcombobox.h> | 28 | #include <qcombobox.h> |
29 | 29 | ||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | #include <stdlib.h> | 32 | #include <stdlib.h> |
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include <stdio.h> | 34 | #include <stdio.h> |
35 | #include <ctype.h> | 35 | #include <ctype.h> |
36 | 36 | ||
37 | static char *keynames[] = { "identity", "id_rsa", "id_dsa" }; | 37 | static char *keynames[] = { "identity", "id_rsa", "id_dsa" }; |
38 | 38 | ||
39 | SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) | 39 | SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) |
40 | : SSHKeysBase( parent, name, fl ) | 40 | : SSHKeysBase( parent, name, fl ) |
41 | { | 41 | { |
42 | char *home = getenv("HOME"); | 42 | char *home = getenv("HOME"); |
43 | unsigned i; | 43 | unsigned i; |
44 | 44 | ||
45 | connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); | 45 | connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); |
46 | connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); | 46 | connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); |
47 | connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); | 47 | connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); |
48 | 48 | ||
49 | connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 49 | connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); |
51 | connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), | ||
52 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | ||
51 | connect(&addprocess, SIGNAL(processExited(OProcess*)), | 53 | connect(&addprocess, SIGNAL(processExited(OProcess*)), |
52 | this, SLOT(ssh_add_exited(OProcess*))); | 54 | this, SLOT(ssh_add_exited(OProcess*))); |
53 | 55 | ||
54 | connect(KeyFileName, SIGNAL(textChanged(const QString&)), | 56 | connect(KeyFileName, SIGNAL(textChanged(const QString&)), |
55 | this, SLOT(add_text_changed(const QString&))); | 57 | this, SLOT(add_text_changed(const QString&))); |
56 | 58 | ||
57 | if (home) { | 59 | if (home) { |
58 | for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { | 60 | for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { |
59 | char thiskeyname[32]; | 61 | char thiskeyname[32]; |
60 | 62 | ||
61 | thiskeyname[31] = 0; | 63 | thiskeyname[31] = 0; |
62 | snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); | 64 | snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); |
63 | if (!access(thiskeyname, R_OK)) { | 65 | if (!access(thiskeyname, R_OK)) { |
64 | KeyFileName->insertItem(thiskeyname); | 66 | KeyFileName->insertItem(thiskeyname); |
65 | } | 67 | } |
66 | } | 68 | } |
67 | } | 69 | } |
68 | 70 | ||
69 | doRefreshListButton(); | 71 | doRefreshListButton(); |
70 | } | 72 | } |
71 | 73 | ||
72 | SSHKeysApp::~SSHKeysApp() | 74 | SSHKeysApp::~SSHKeysApp() |
73 | { | 75 | { |
74 | } | 76 | } |
75 | 77 | ||
76 | void SSHKeysApp::doRefreshListButton() | 78 | void SSHKeysApp::doRefreshListButton() |
77 | { | 79 | { |
78 | OProcess sshadd_process; | 80 | OProcess sshadd_process; |
79 | QListViewItem *t = KeyList->firstChild(); | 81 | QListViewItem *t = KeyList->firstChild(); |
80 | 82 | ||
81 | while(t) { | 83 | while(t) { |
82 | QListViewItem *next = t->nextSibling(); | 84 | QListViewItem *next = t->nextSibling(); |
83 | KeyList->takeItem(t); | 85 | KeyList->takeItem(t); |
84 | delete(t); | 86 | delete(t); |
85 | t = next; | 87 | t = next; |
86 | } | 88 | } |
87 | 89 | ||
88 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), | 90 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), |
89 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); | 91 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); |
92 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), | ||
93 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | ||
90 | 94 | ||
91 | keystate = KeySize; | 95 | keystate = KeySize; |
92 | incoming_keyname=""; | 96 | incoming_keyname=""; |
93 | incoming_keysize=""; | 97 | incoming_keysize=""; |
94 | incoming_keyfingerprint=""; | 98 | incoming_keyfingerprint=""; |
95 | 99 | ||
96 | //log_text("Running ssh-add -l"); | 100 | //log_text("Running ssh-add -l"); |
97 | sshadd_process << "ssh-add" << "-l"; | 101 | sshadd_process << "ssh-add" << "-l"; |
98 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 102 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
99 | if (!ret) { | 103 | if (!ret) { |
100 | log_text(tr("Error running ssh-add")); | 104 | log_text(tr("Error running ssh-add")); |
101 | return; | 105 | return; |
102 | } | 106 | } |
103 | if (sshadd_process.exitStatus() == 2) { | 107 | if (sshadd_process.exitStatus() == 2) { |
104 | log_text(tr("Connection to ssh-agent failed")); | ||
105 | setEnabled(FALSE); | 108 | setEnabled(FALSE); |
106 | } | 109 | } |
107 | } | 110 | } |
108 | 111 | ||
109 | void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) | 112 | void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) |
110 | { | 113 | { |
111 | int i; | 114 | int i; |
112 | (void) proc; | 115 | (void) proc; |
113 | 116 | ||
114 | for (i=0; i<buflen; i++) { | 117 | for (i=0; i<buflen; i++) { |
115 | switch(keystate) { | 118 | switch(keystate) { |
116 | case Noise: | 119 | case Noise: |
117 | noise: | 120 | noise: |
118 | if (buffer[i] == '\n') { | 121 | if (buffer[i] == '\n') { |
119 | log_text(incoming_noise.local8Bit()); | 122 | log_text(incoming_noise.local8Bit()); |
120 | incoming_noise = ""; | 123 | incoming_noise = ""; |
121 | keystate = KeySize; | 124 | keystate = KeySize; |
122 | } else { | 125 | } else { |
123 | incoming_noise += buffer[i]; | 126 | incoming_noise += buffer[i]; |
124 | } | 127 | } |
125 | break; | 128 | break; |
126 | 129 | ||
127 | case KeySize: | 130 | case KeySize: |
128 | if (isdigit(buffer[i])) { | 131 | if (isdigit(buffer[i])) { |
129 | incoming_keysize += buffer[i]; | 132 | incoming_keysize += buffer[i]; |
130 | } else if (buffer[i] == ' ') { | 133 | } else if (buffer[i] == ' ') { |
131 | keystate = KeyFingerprint; | 134 | keystate = KeyFingerprint; |
132 | } else { | 135 | } else { |
133 | incoming_keysize = ""; | 136 | incoming_keysize = ""; |
134 | incoming_noise = ""; | 137 | incoming_noise = ""; |
135 | keystate = Noise; | 138 | keystate = Noise; |
136 | goto noise; | 139 | goto noise; |
137 | } | 140 | } |
138 | break; | 141 | break; |
139 | 142 | ||
140 | case KeyFingerprint: | 143 | case KeyFingerprint: |
141 | if (isxdigit(buffer[i]) || buffer[i] == ':') { | 144 | if (isxdigit(buffer[i]) || buffer[i] == ':') { |
142 | incoming_keyfingerprint += buffer[i]; | 145 | incoming_keyfingerprint += buffer[i]; |
143 | } else if (buffer[i] == ' ') { | 146 | } else if (buffer[i] == ' ') { |
144 | keystate = KeyName; | 147 | keystate = KeyName; |
145 | } else { | 148 | } else { |
146 | incoming_keysize = ""; | 149 | incoming_keysize = ""; |
147 | incoming_keyfingerprint = ""; | 150 | incoming_keyfingerprint = ""; |
148 | incoming_noise = ""; | 151 | incoming_noise = ""; |
149 | keystate = Noise; | 152 | keystate = Noise; |
150 | goto noise; | 153 | goto noise; |
151 | } | 154 | } |
152 | break; | 155 | break; |
153 | 156 | ||
154 | case KeyName: | 157 | case KeyName: |
155 | if (buffer[i] == '\n') { | 158 | if (buffer[i] == '\n') { |
156 | /* Wheee. Got one. */ | 159 | /* Wheee. Got one. */ |
157 | KeyList->insertItem(new | 160 | KeyList->insertItem(new |
158 | QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint)); | 161 | QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint)); |
159 | incoming_keysize = ""; | 162 | incoming_keysize = ""; |
160 | incoming_keyfingerprint = ""; | 163 | incoming_keyfingerprint = ""; |
161 | incoming_keyname = ""; | 164 | incoming_keyname = ""; |
162 | keystate = KeySize; | 165 | keystate = KeySize; |
163 | } else if (isprint(buffer[i])) { | 166 | } else if (isprint(buffer[i])) { |
164 | incoming_keyname += buffer[i]; | 167 | incoming_keyname += buffer[i]; |
165 | } else { | 168 | } else { |
166 | incoming_keysize = ""; | 169 | incoming_keysize = ""; |
167 | incoming_keyfingerprint = ""; | 170 | incoming_keyfingerprint = ""; |
168 | incoming_noise = ""; | 171 | incoming_noise = ""; |
169 | keystate = Noise; | 172 | keystate = Noise; |
170 | goto noise; | 173 | goto noise; |
171 | } | 174 | } |
172 | break; | 175 | break; |
173 | } | 176 | } |
174 | } | 177 | } |
175 | } | 178 | } |
176 | 179 | ||
177 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) | 180 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) |
178 | { | 181 | { |
179 | (void)proc; | 182 | (void)proc; |
180 | (void)buflen; | 183 | (void)buflen; |
181 | 184 | ||
182 | log_text(buffer); | 185 | log_text(buffer); |
183 | } | 186 | } |
184 | 187 | ||
185 | void SSHKeysApp::ssh_add_exited(OProcess *proc) | 188 | void SSHKeysApp::ssh_add_exited(OProcess *proc) |
186 | { | 189 | { |
187 | (void)proc; | 190 | (void)proc; |
188 | 191 | ||
189 | doRefreshListButton(); | 192 | doRefreshListButton(); |
190 | setEnabled(TRUE); | 193 | setEnabled(TRUE); |
191 | if (proc->exitStatus()) { | 194 | if (proc->exitStatus() == 2) { |
192 | 195 | setEnabled(FALSE); | |
193 | log_text(QString(tr("ssh-add failed"))); | ||
194 | } | 196 | } |
195 | } | 197 | } |
196 | 198 | ||
197 | void SSHKeysApp::add_text_changed(const QString &text) | 199 | void SSHKeysApp::add_text_changed(const QString &text) |
198 | { | 200 | { |
199 | struct stat sbuf; | 201 | struct stat sbuf; |
200 | 202 | ||
201 | if (!text.length() || (!access(text.ascii(), R_OK) && | 203 | if (!text.length() || (!access(text.ascii(), R_OK) && |
202 | !stat(text.ascii(), &sbuf) && | 204 | !stat(text.ascii(), &sbuf) && |
203 | S_ISREG(sbuf.st_mode))) | 205 | S_ISREG(sbuf.st_mode))) |
204 | AddButton->setEnabled(TRUE); | 206 | AddButton->setEnabled(TRUE); |
205 | else | 207 | else |
206 | AddButton->setEnabled(FALSE); | 208 | AddButton->setEnabled(FALSE); |
207 | } | 209 | } |
208 | 210 | ||
209 | void SSHKeysApp::doAddButton() | 211 | void SSHKeysApp::doAddButton() |
210 | { | 212 | { |
211 | addprocess.clearArguments(); | 213 | addprocess.clearArguments(); |
212 | 214 | ||
213 | setEnabled(FALSE); | 215 | setEnabled(FALSE); |
214 | 216 | ||
215 | if (KeyFileName->currentText().length()) { | 217 | if (KeyFileName->currentText().length()) { |
216 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); | 218 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); |
217 | log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); | 219 | log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); |
218 | } else { | 220 | } else { |
219 | addprocess << "ssh-add"; | 221 | addprocess << "ssh-add"; |
220 | log_text(tr("Running ssh-add")); | 222 | log_text(tr("Running ssh-add")); |
221 | } | 223 | } |
222 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); | 224 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); |
223 | if (!ret) { | 225 | if (!ret) { |
224 | log_text(tr("Error running ssh-add")); | 226 | log_text(tr("Error running ssh-add")); |
225 | doRefreshListButton(); | 227 | doRefreshListButton(); |
226 | setEnabled(TRUE); | 228 | setEnabled(TRUE); |
227 | } | 229 | } |
228 | } | 230 | } |
229 | 231 | ||
230 | void SSHKeysApp::log_text(const char *text) | 232 | void SSHKeysApp::log_text(const char *text) |
231 | { | 233 | { |
232 | TextOutput->append(text); | 234 | TextOutput->append(text); |
233 | TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); | 235 | TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); |
234 | } | 236 | } |
235 | 237 | ||
236 | void SSHKeysApp::doRemoveAllButton() | 238 | void SSHKeysApp::doRemoveAllButton() |
237 | { | 239 | { |
238 | OProcess sshadd_process; | 240 | OProcess sshadd_process; |
239 | 241 | ||
240 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), | 242 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), |
241 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 243 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); |
244 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), | ||
245 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | ||
242 | 246 | ||
243 | log_text(tr("Running ssh-add -D")); | 247 | log_text(tr("Running ssh-add -D")); |
244 | sshadd_process << "ssh-add" << "-D"; | 248 | sshadd_process << "ssh-add" << "-D"; |
245 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 249 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
246 | if (!ret) { | 250 | if (!ret) { |
247 | log_text(tr("Error running ssh-add")); | 251 | log_text(tr("Error running ssh-add")); |
248 | } | 252 | } |
249 | doRefreshListButton(); | 253 | doRefreshListButton(); |
250 | } | 254 | } |