summaryrefslogtreecommitdiff
blob: 4142a0b41b4176c749cf43becfe73c41f87e52ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
Index: lib/notQt.cpp
===================================================================
--- lib/notQt.cpp	(révision 519)
+++ lib/notQt.cpp	(révision 520)
@@ -26,6 +26,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/poll.h>	
+#include <sys/socket.h>	
 #include <signal.h>
 }
 
@@ -52,7 +53,8 @@
     progName("unknown"),
     error (NOTQPROCNOERROR),
     pid(0),
-    signalledStart(false)
+    signalledStart(false),
+    parentFD(-1)
 {
     // Set up the polling structs
     this->p = static_cast<struct pollfd*>(malloc (2*sizeof (struct pollfd)));	
@@ -62,6 +64,15 @@
 notQProcess::~notQProcess ()
 {
     free (this->p);
+    if (parentFD != -1)
+    {
+    	close(parentFD);
+	parentFD=-1;
+    }
+    // FIXME: this should be closed here
+   // close (parentToChild[READING_END]);
+   // close (childToParent[WRITING_END]);
+   // close (childErrToParent[WRITING_END]);
 }
 
     void
@@ -84,10 +95,18 @@
     // NB: The first item in the args list should be the program name.
     this->progName = program;
 
+#ifdef NXCL_USE_NXSSH
     // Set up our pipes
     if (pipe(parentToChild) == -1 || pipe(childToParent) == -1 || pipe(childErrToParent) == -1) {
         return NOTQTPROCESS_FAILURE;
     }
+#else /* We need a socketpair for that to work */
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, parentToChild) == -1 || pipe(childErrToParent) == -1)
+        return NOTQTPROCESS_FAILURE;
+    
+    childToParent[READING_END]=dup(parentToChild[WRITING_END]);
+    childToParent[WRITING_END]=dup(parentToChild[READING_END]);
+#endif
 
     this->pid = fork();
 
Index: lib/nxsession.cpp
===================================================================
--- lib/nxsession.cpp	(révision 519)
+++ lib/nxsession.cpp	(révision 520)
@@ -69,6 +69,7 @@
     int response = parseResponse (message);
     string returnMessage;
 
+#ifdef NXCL_USE_NXSSH
     if (response == 211) {
         if (doSSH == true) {
             returnMessage = "yes";
@@ -80,6 +81,7 @@
     if (response == 204) { // Authentication failed
         returnMessage = "204";
     }
+#endif
 
     if (response == 147) { // Server capacity reached
         returnMessage = "147";
@@ -90,6 +92,17 @@
         case HELLO_NXCLIENT:
             dbgln ("HELLO_NXCLIENT stage");
 
+	    if (message.find("Are you sure you want to continue connecting (yes/no)?") != string::npos)
+            	returnMessage = "yes"; // FF-FIXME: Or 211?
+	    
+	    if (message.find("assword") != string::npos)
+            	returnMessage = nxPassword; // FF-FIXME: -> What to do? What to do?
+	    
+	    if (message.find("Permission denied") != string::npos || 
+	            message.find("su: Authentication failure") != string::npos || 
+		    message.find("Unknown id:") != string::npos)
+                returnMessage = "204"; // Authentication failed
+
             if (message.find("HELLO NXSERVER - Version") != string::npos) {
                 this->callbacks->authenticatedSignal();
                 returnMessage = "hello NXCLIENT - Version ";
Index: lib/notQt.h
===================================================================
--- lib/notQt.h	(révision 519)
+++ lib/notQt.h	(révision 520)
@@ -117,7 +117,19 @@
 		pid_t getPid (void) { return this->pid; }
 		int getError (void) { return this->error; }
 		void setError (int e) { this->error = e; }
+		
+		int getParentFD() 
+		{ 
+			this->parentFD = this->parentToChild[1];
+			close(this->childToParent[0]);
 
+			// Create new pipes
+			pipe(this->parentToChild);
+			pipe(this->childToParent);
+
+			return this->parentFD;
+		}
+
 		/*!
 		 * Setter for the callbacks.
 		 */
@@ -180,6 +192,11 @@
 		 * Pointer to a callback object
 		 */
 		notQProcessCallbacks * callbacks;
+
+		/*! 
+		 * old parent FD for comm with child
+		 */
+		int parentFD;
 	};
 
 	/*!
Index: lib/nxclientlib.cpp
===================================================================
--- lib/nxclientlib.cpp	(révision 519)
+++ lib/nxclientlib.cpp	(révision 520)
@@ -8,7 +8,8 @@
                          :     Author: Sebastian James
                          : (C) 2008 Defuturo Ltd
                          :     Author: George Wright
-    email                : seb@esfnet.co.uk, gwright@kde.org
+                         : (C) 2008 Fabian Franz
+    email                : seb@esfnet.co.uk, gwright@kde.org, freenx@fabian-franz.de
  ***************************************************************************/
 
 /***************************************************************************
@@ -28,6 +29,14 @@
 
 #include <fstream>
 
+// Define to use nxssh
+#if defined(NXCL_CYGWIN) || defined(NXCL_DARWIN)
+
+// FF-FIXME That does not work.
+//#define NXCL_USE_NXSSH 1
+
+#endif
+
 extern "C" {
     #include <errno.h>
     #include <sys/types.h>
@@ -186,10 +195,14 @@
 
     // Start to build the arguments for the nxssh command.
     // notQProcess requires that argv[0] contains the program name
+#ifdef NXCL_USE_NXSSH
     arguments.push_back ("nxssh");
 
     argtmp << "-nx";
     arguments.push_back (argtmp.str());
+#else
+    arguments.push_back ("ssh");
+#endif
 
     argtmp.str("");
     argtmp << "-p" << port;
@@ -215,6 +228,7 @@
     }
 
     argtmp.str("");
+    // FF-FIXME: Perhaps the user wants to login as user directly
     argtmp << "nx@" << serverHost;
     arguments.push_back (argtmp.str());
 
@@ -227,9 +241,13 @@
     arguments.push_back ("-oRSAAuthentication no");
     arguments.push_back ("-oRhostsRSAAuthentication no");
     arguments.push_back ("-oPubkeyAuthentication yes");
+    // FF-FIXME: Perhaps the user wants to login as user directly
+    //arguments.push_back ("-c nxserver");
 
     if (encryption == true) {
+#ifdef NXCL_USE_NXSSH
         arguments.push_back("-B");
+#endif
         session.setEncryption (true);
     } else {
         session.setEncryption (false);
@@ -240,10 +258,16 @@
     // nxssh -E gives this message when called:
     // NX> 285 Enabling skip of SSH config files
     // ...so there you have the meaning.
+#ifdef NXCL_USE_NXSSH
     arguments.push_back ("-E");
+#endif
 
     // Find a path for the nxssh process using getPath()
+#ifdef NXCL_USE_NXSSH
     string nxsshPath = this->getPath ("nxssh");
+#else
+    string nxsshPath = this->getPath ("ssh");
+#endif
 
     this->nxsshProcess->start(nxsshPath, arguments);
 
@@ -365,8 +389,9 @@
 
         // On some connections this is sent via stdout instead of stderr?
         if (proxyData.encrypted && readyForProxy &&
-                ((*msgiter).find("NX> 999 Bye")!=string::npos)) {
-
+                ((*msgiter).find("NX> 999 Bye")!=string::npos)) 
+#ifdef NXCL_USE_NXSSH
+	{
             // This is "NX> 299 Switching connection to: " in
             // version 1.5.0. This was changed in nxssh version
             // 2.0.0-8 (see the nxssh CHANGELOG).
@@ -388,6 +413,11 @@
             this->externalCallbacks->connectedSuccessfullySignal();
             this->sessionRunning = true;
         }
+#else /* don't use nxssh, start nxproxy -stdin */
+	{
+		invokeProxy();
+	}
+#endif
 
         if ((*msgiter).find("Password") != string::npos) {
             this->externalCallbacks->write
@@ -402,6 +432,9 @@
                 dbgln ("NXClientLib::processParseStdout: Got auth failed"
                         " or capacity reached, calling this->parseSSH.");
                 msg = this->parseSSH (*msgiter);
+#ifndef NXCL_USE_NXSSH
+		this->isFinished = true;
+#endif
             }
             if (msg.size() > 0) {
                 this->write (msg);
@@ -436,7 +469,9 @@
                 + (*msgiter) + "'(end msg)");
 
         if (proxyData.encrypted && readyForProxy &&
-                ((*msgiter).find("NX> 999 Bye") != string::npos)) {
+                ((*msgiter).find("NX> 999 Bye") != string::npos)) 
+#ifdef NXCL_USE_NXSSH
+	{
 
             string switchCommand = "NX> 299 Switch connection to: ";
             stringstream ss;
@@ -478,6 +513,11 @@
                  _("SSH host key verification failed"));
             this->isFinished = true;
         }
+#else /* don't use nxssh, use nxproxy -stdin */
+	{
+		invokeProxy();
+	}
+#endif
     }
 }
 
@@ -580,21 +620,41 @@
         this->externalCallbacks->serverCapacitySignal();
         this->isFinished = true;
 
-    } else if
+    } 
+#ifdef NXCL_USE_NXSSH
+    else if
         (message.find ("NX> 204 Authentication failed.") != string::npos) {
 
         this->externalCallbacks->write
             (204, _("NX SSH Authentication Failed, finishing"));
         this->isFinished = true;
     }
+#endif
 
     if (message.find("NX> 710 Session status: running") != string::npos) {
 
         this->externalCallbacks->write
             (710, _("Session status is \"running\""));
+    }
+
+    // FF-FIXME: This is technically incorrect as the proxy is just ready once 1002 and 1006 have 
+    // been sent.
+    if (message.find("NX> 710 Session status: running") != string::npos) {
+        
+	//this->externalCallbacks->write
+        //    (1006, _("Session status is \"running\""));
+
+#ifdef NXCL_USE_NXSSH
         invokeProxy();
+#else
+	if (!proxyData.encrypted)
+        	invokeProxy();
+#endif
         session.wipeSessions();
-        rMessage = "bye\n";
+        if (proxyData.encrypted)
+	        rMessage = "bye\n";
+	else
+	        rMessage = "quit\n";
     }
 
     return rMessage;
@@ -700,18 +760,24 @@
     stringstream data;
  
     if (proxyData.encrypted) {
+#ifdef NXCL_USE_NXSSH
         data << "nx/nx" << x11Display << ",session=session,encryption=1,cookie="
             << proxyData.cookie
             << ",id=" << proxyData.id << ",listen=" 
             << proxyData.port << ":" << proxyData.display << "\n";
         // may also need shmem=1,shpix=1,font=1,product=...
+#else
+	data << "nx/nx" << x11Display << ",session=session,encryption=1,cookie="
+            << proxyData.cookie
+            << ",id=" << proxyData.id << ":" << proxyData.display << "\n";
+#endif
 
     } else {
-        // Not tested yet
+        // Not tested yet, FF-FIXME: Test
         data << "nx/nx" << x11Display << ",session=session,cookie=" << proxyData.cookie
-            << ",id=" << proxyData.id
-            // << ",connect=" << proxyData.server << ":" << proxyData.display
-            << ",listen=" << proxyData.port << ":" << proxyData.display
+            << ",connect=" << proxyData.server << ":" << proxyData.port
+            << ",id=" << proxyData.id << ":" << proxyData.display
+            //<< ",listen=" << proxyData.port << ":" << proxyData.display
             << "\n";
     }
 
@@ -726,11 +792,24 @@
     list<string> arguments;
     arguments.push_back("nxproxy"); // argv[0] has to be the program name
     arguments.push_back("-S");
+
     ss.str("");
-    ss << "options=" << nxdir;
-    ss << ":" << proxyData.display;
-    arguments.push_back(ss.str());	
+    ss << "nx/nx,options=" << nxdir << ":" << proxyData.display;
 
+    setenv("NX_DISPLAY", ss.str().c_str(), 1);
+
+#ifndef NXCL_USE_NXSSH
+    if (proxyData.encrypted)
+    {
+    	ss.str("");
+    	ss << this->nxsshProcess->getParentFD();
+	fprintf(stderr, "NX_COMMFD=%d", this->nxsshProcess->getParentFD());
+    	setenv("NX_COMMFD", ss.str().c_str(), 1);
+	// FF-FIXME: need to wait for 2 secs due to race condition with "bye" in buffer
+	sleep(2);
+    }
+#endif
+
     // Find a path for the nxproxy process using getPath()
     string nxproxyPath = this->getPath ("nxproxy");
     this->nxproxyProcess->start(nxproxyPath, arguments);