View | Details | Raw Unified | Return to bug 7300
Collapse All | Expand All

(-)Makefile (+3 lines)
Lines 163-168 Link Here
163
		services/connection_socket.o \
163
		services/connection_socket.o \
164
		services/service_process.o \
164
		services/service_process.o \
165
		services/service_process_vncviewer.o \
165
		services/service_process_vncviewer.o \
166
		services/service_process_remote_port_forwarding.o \
166
		services/service.o \
167
		services/service.o \
167
		services/service_agent.o \
168
		services/service_agent.o \
168
		services/service_tcp.o \
169
		services/service_tcp.o \
Lines 692-697 Link Here
692
	services/service_process.h \
693
	services/service_process.h \
693
	services/service_process_vncviewer.cc \
694
	services/service_process_vncviewer.cc \
694
	services/service_process_vncviewer.h \
695
	services/service_process_vncviewer.h \
696
	services/service_process_remote_port_forwarding.cc \
697
	services/service_process_remote_port_forwarding.h \
695
	services/service_unix.cc \
698
	services/service_unix.cc \
696
	services/service_unix.h \
699
	services/service_unix.h \
697
	services/service_unix_win32.cc \
700
	services/service_unix_win32.cc \
(-)services/service_process.cc (+6 lines)
Lines 110-116 Link Here
110
        logfile.Log(logname + "[E]: " + stderr_rest + "...", 3);
110
        logfile.Log(logname + "[E]: " + stderr_rest + "...", 3);
111
}
111
}
112
112
113
void ServiceProcess::onProcessLost()
114
{
115
}
113
116
117
114
/*!
118
/*!
115
 * \brief Callback on each line parser in parseData()
119
 * \brief Callback on each line parser in parseData()
116
 * \return true if line is consumed otherwise false
120
 * \return true if line is consumed otherwise false
Lines 163-168 Link Here
163
                    TLUtils::LongToString(ready_fd) + " for service " +
167
                    TLUtils::LongToString(ready_fd) + " for service " +
164
                    me->logname, 4);
168
                    me->logname, 4);
165
        Fl::remove_fd(ready_fd);
169
        Fl::remove_fd(ready_fd);
170
	me->onProcessLost();
166
    } else {
171
    } else {
167
        // Error
172
        // Error
168
        logfile.Log((string)"ServiceProcess: read error (" + strerror(errno) +
173
        logfile.Log((string)"ServiceProcess: read error (" + strerror(errno) +
Lines 238-243 Link Here
238
    if ((me->stdout_handle == INVALID_HANDLE_VALUE) &&
243
    if ((me->stdout_handle == INVALID_HANDLE_VALUE) &&
239
        (me->stderr_handle == INVALID_HANDLE_VALUE)) {
244
        (me->stderr_handle == INVALID_HANDLE_VALUE)) {
240
        Fl::remove_check(ServiceProcess::check, instance);
245
        Fl::remove_check(ServiceProcess::check, instance);
246
	me->onProcessLost();
241
    }
247
    }
242
}
248
}
243
249
(-)services/service_process.h (+1 lines)
Lines 43-48 Link Here
43
        string stdout_rest, stderr_rest;
43
        string stdout_rest, stderr_rest;
44
        string logname;
44
        string logname;
45
45
46
        virtual void onProcessLost();
46
        virtual bool onDataLine(string line, bool is_stderr);
47
        virtual bool onDataLine(string line, bool is_stderr);
47
        virtual void parseData( const char * data, int size, bool is_stderr );
48
        virtual void parseData( const char * data, int size, bool is_stderr );
48
49
(-)services/service_process_remote_port_forwarding.cc (+30 lines)
Line 0 Link Here
1
// -*- mode: C++; c-basic-offset: 4; -*-
2
//
3
// Copyright 2018 Cendio AB.
4
// For more information, see http://www.cendio.com
5
6
#include <vector>
7
#include <string.h>
8
9
#include "../tlclient_util.h"
10
11
#include "service_process_remote_port_forwarding.h"
12
13
using namespace tcpservices;
14
15
ServiceProcessRemotePortForwarding::ServiceProcessRemotePortForwarding(SSHTunnel *tunnel, int port,
16
								       int stdout_fd, int stderr_fd, string logname)
17
  : ServiceProcess::ServiceProcess(stdout_fd, stderr_fd, logname),
18
    tunnel(tunnel),
19
    port(port)
20
{
21
}
22
23
ServiceProcessRemotePortForwarding::~ServiceProcessRemotePortForwarding()
24
{
25
}
26
27
void ServiceProcessRemotePortForwarding::onProcessLost()
28
{
29
  tunnel->CancelRemotePortForwarding(port);
30
}
(-)services/service_process_remote_port_forwarding.h (+36 lines)
Line 0 Link Here
1
// -*- mode: C++; c-basic-offset: 4; -*-
2
//
3
// Copyright 2018 Cendio AB.
4
// For more information, see http://www.cendio.com
5
6
#ifndef __SERVICE_PROCESS_REMOTE_PORT_FORWARDING_H__
7
#define __SERVICE_PROCESS_REMOTE_PORT_FORWARDING_H__
8
9
#include <string>
10
#include "service_process.h"
11
12
#include "../tlclient_ssh.h"
13
14
using std::string;
15
16
namespace tcpservices
17
{
18
19
class ServiceProcessRemotePortForwarding : public ServiceProcess
20
{
21
    public:
22
        ServiceProcessRemotePortForwarding(SSHTunnel *tunnel, int port,
23
					   int stdout_fd, int stderr_fd, string logname);
24
        virtual ~ServiceProcessRemotePortForwarding();
25
26
    protected:
27
        virtual void onProcessLost();
28
29
    private:
30
        SSHTunnel *tunnel;
31
        string address;
32
        int port;
33
};
34
35
}
36
#endif /* __SERVICE_PROCESS_REMOTE_PORT_FORWARDING_H__ */
(-)tlclient_session.cc (-16 / +19 lines)
Lines 54-59 Link Here
54
#include "services/service_lpd.h"
54
#include "services/service_lpd.h"
55
#include "services/service_process.h"
55
#include "services/service_process.h"
56
#include "services/service_process_vncviewer.h"
56
#include "services/service_process_vncviewer.h"
57
#include "services/service_process_remote_port_forwarding.h"
57
58
58
#ifdef __APPLE__
59
#ifdef __APPLE__
59
#include <CoreFoundation/CoreFoundation.h>
60
#include <CoreFoundation/CoreFoundation.h>
Lines 2175-2181 Link Here
2175
2176
2176
    logfile.Log("PulseAudio pid is " + TLUtils::LongToString(pulseaudio_pid), 3);
2177
    logfile.Log("PulseAudio pid is " + TLUtils::LongToString(pulseaudio_pid), 3);
2177
2178
2178
    services.push_back(new ServiceProcess(stdout_fd, stderr_fd, "pulseaudio"));
2179
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_pulse_port,
2180
							      stdout_fd, stderr_fd, "pulseaudio"));
2179
2181
2180
    oldpath = LD_LIBRARY_PATH "=" + oldpath;
2182
    oldpath = LD_LIBRARY_PATH "=" + oldpath;
2181
    putenv(strdup(oldpath.c_str()));
2183
    putenv(strdup(oldpath.c_str()));
Lines 2188-2197 Link Here
2188
    } catch (TLException e) {
2190
    } catch (TLException e) {
2189
        throw TLException(ERR_PULSE_ERROR, string(_("Couldn't start pulseaudio")) + ": " + e.message());
2191
        throw TLException(ERR_PULSE_ERROR, string(_("Couldn't start pulseaudio")) + ": " + e.message());
2190
    }
2192
    }
2191
    services.push_back(new ServiceProcess(pulseproc->hOutputRead,
2192
                                          pulseproc->hErrorRead,
2193
                                          "pulseaudio"));
2194
2193
2194
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_pulse_port,
2195
							      pulseproc->hOutputRead, pulseproc->hErrorRead, "pulseaudio"));
2196
2195
#endif // WIN32
2197
#endif // WIN32
2196
2198
2197
}
2199
}
Lines 2279-2285 Link Here
2279
2281
2280
    logfile.Log("smart card daemon pid is " + TLUtils::LongToString(smartcard_pid), 3);
2282
    logfile.Log("smart card daemon pid is " + TLUtils::LongToString(smartcard_pid), 3);
2281
2283
2282
    services.push_back(new ServiceProcess(stdout_fd, stderr_fd, "pcsctun"));
2284
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_smartcard_port,
2285
							      stdout_fd, stderr_fd, "pcsctun"));
2283
2286
2284
#else
2287
#else
2285
2288
Lines 2289-2297 Link Here
2289
    } catch (TLException e) {
2292
    } catch (TLException e) {
2290
        throw TLException(ERR_SMARTCARD_ERROR, string(_("Couldn't start smart card daemon")) + ": " + e.message());
2293
        throw TLException(ERR_SMARTCARD_ERROR, string(_("Couldn't start smart card daemon")) + ": " + e.message());
2291
    }
2294
    }
2292
    services.push_back(new ServiceProcess(smartcard_proc->hOutputRead,
2295
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_smartcard_port,
2293
                                          smartcard_proc->hErrorRead,
2296
							      smartcard_proc->hOutputRead, smartcard_proc->hErrorRead, "pcsctun"));
2294
                                          "pcsctun"));
2295
#endif // WIN32
2297
#endif // WIN32
2296
2298
2297
}
2299
}
Lines 2420-2426 Link Here
2420
2422
2421
    logfile.Log("unfsd pid is " + TLUtils::LongToString(unfsd_pid),  3);
2423
    logfile.Log("unfsd pid is " + TLUtils::LongToString(unfsd_pid),  3);
2422
2424
2423
    services.push_back(new ServiceProcess(stdout_fd, stderr_fd, "unfsd"));
2425
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_nfs_port,
2426
							      stdout_fd, stderr_fd, "unfsd"));
2424
2427
2425
#else
2428
#else
2426
2429
Lines 2430-2438 Link Here
2430
    } catch (TLException e) {
2433
    } catch (TLException e) {
2431
        throw TLException(ERR_PROCESS_ERROR, string(_("Couldn't start unfsd")) + ": " + e.message());
2434
        throw TLException(ERR_PROCESS_ERROR, string(_("Couldn't start unfsd")) + ": " + e.message());
2432
    }
2435
    }
2433
    services.push_back(new ServiceProcess(unfsd_process->hOutputRead,
2436
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_nfs_port,
2434
                                          unfsd_process->hErrorRead,
2437
							      unfsd_process->hOutputRead, unfsd_process->hErrorRead, "unfsd"));
2435
                                          "unfsd"));
2436
2438
2437
#endif /* WIN32 */
2439
#endif /* WIN32 */
2438
2440
Lines 2509-2515 Link Here
2509
2511
2510
    logfile.Log("sercd pid is " + TLUtils::LongToString(sercd_pids[devnum]), 3);
2512
    logfile.Log("sercd pid is " + TLUtils::LongToString(sercd_pids[devnum]), 3);
2511
2513
2512
    services.push_back(new ServiceProcess(stdout_fd, stderr_fd, "sercd"));
2514
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_serial_ports[devnum],
2515
							      stdout_fd, stderr_fd, "sercd"));
2513
#else
2516
#else
2514
    try {
2517
    try {
2515
        // Show console window if loglevel => 5
2518
        // Show console window if loglevel => 5
Lines 2517-2525 Link Here
2517
    } catch (TLException e) {
2520
    } catch (TLException e) {
2518
        throw TLException(ERR_PROCESS_ERROR, string(_("Couldn't start sercd")) + ": " + e.message());
2521
        throw TLException(ERR_PROCESS_ERROR, string(_("Couldn't start sercd")) + ": " + e.message());
2519
    }
2522
    }
2520
    services.push_back(new ServiceProcess(sercd_processes[devnum]->hOutputRead,
2523
    services.push_back(new ServiceProcessRemotePortForwarding(agent_tunnel, local_serial_ports[devnum],
2521
                                          sercd_processes[devnum]->hErrorRead,
2524
							      sercd_processes[devnum]->hOutputRead,
2522
                                          "sercd"));
2525
							      sercd_processes[devnum]->hErrorRead, "sercd"));
2523
2526
2524
#endif /* WIN32 */
2527
#endif /* WIN32 */
2525
2528
(-)tlclient_ssh.cc (+19 lines)
Lines 722-727 Link Here
722
722
723
    arg_vector.addArgument("-N");
723
    arg_vector.addArgument("-N");
724
724
725
    // Force pseudo-terminal allocation to be able to use escape
726
    // characters control of the ssh connection. This is used for
727
    // taking down tunnels during an active connection.
728
    arg_vector.addArgument("-t");
729
725
    // We disable the standard host key checking so that tlclient
730
    // We disable the standard host key checking so that tlclient
726
    // can make all decisions. This allows us to be more flexible
731
    // can make all decisions. This allows us to be more flexible
727
    // about key storage.
732
    // about key storage.
Lines 2203-2209 Link Here
2203
    return banner;
2208
    return banner;
2204
}
2209
}
2205
2210
2211
/*!
2212
 * \brief Cancel an existing remote port-forwarding
2213
   \param[in] port, The identifying port
2214
 */
2215
void SSHTunnel::CancelRemotePortForwarding(int port)
2216
{
2217
    int fd;
2218
    char buf[512];
2206
2219
2220
    fd = GetSSHStdoutFd();
2221
2222
    snprintf(buf, sizeof(buf), "~C-KR%d\r\n", port);
2223
    write(fd, buf, strlen(buf));
2224
}
2225
2207
#ifdef FEATURE_SMARTCARD_AUTH
2226
#ifdef FEATURE_SMARTCARD_AUTH
2208
2227
2209
bool SSHTunnel::SSHAgentCallback(const char *input, size_t input_len, char *output, size_t *output_len, void *data)
2228
bool SSHTunnel::SSHAgentCallback(const char *input, size_t input_len, char *output, size_t *output_len, void *data)
(-)tlclient_ssh.h (+2 lines)
Lines 91-96 Link Here
91
        void SetIgnoreBanner(string banner);
91
        void SetIgnoreBanner(string banner);
92
        string GetBanner();
92
        string GetBanner();
93
93
94
        void CancelRemotePortForwarding(int port);
95
94
    private:
96
    private:
95
        enum host_key_status {
97
        enum host_key_status {
96
            HOST_OK,
98
            HOST_OK,

Return to bug 7300