Remmina - The GTK+ Remote Desktop Client  v1.4.2
Remmina is a remote desktop client written in GTK+, aiming to be useful for system administrators and travellers, who need to work with lots of remote computers in front of either large monitors or tiny netbooks. Remmina supports multiple network protocols in an integrated and consistent user interface. Currently RDP, VNC, NX, XDMCP and SSH are supported.
remmina_ssh.h
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2009-2011 Vic Lee
4  * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
5  * Copyright (C) 2016-2020 Antenore Gatta, Giovanni Panozzo
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * In addition, as a special exception, the copyright holders give
23  * permission to link the code of portions of this program with the
24  * OpenSSL library under certain conditions as described in each
25  * individual source file, and distribute linked combinations
26  * including the two.
27  * You must obey the GNU General Public License in all respects
28  * for all of the code used other than OpenSSL. * If you modify
29  * file(s) with this exception, you may extend this exception to your
30  * version of the file(s), but you are not obligated to do so. * If you
31  * do not wish to do so, delete this exception statement from your
32  * version. * If you delete this exception statement from all source
33  * files in the program, then also delete it here.
34  *
35  */
36 
37 #pragma once
38 
39 #include "config.h"
40 
41 #ifdef HAVE_LIBSSH
42 
43 #define LIBSSH_STATIC 1
44 #include <libssh/libssh.h>
45 #include <libssh/callbacks.h>
46 #include <libssh/sftp.h>
47 #include <pthread.h>
48 #include "remmina_file.h"
49 #include "rcw.h"
50 
51 G_BEGIN_DECLS
52 
53 /*-----------------------------------------------------------------------------*
54 * SSH Base *
55 *-----------------------------------------------------------------------------*/
56 
57 #define REMMINA_SSH(a) ((RemminaSSH *)a)
58 
59 typedef struct _RemminaSSH {
60  ssh_session session;
61  ssh_callbacks callback;
62  gboolean authenticated;
63 
64  gchar * server;
65  gint port;
66  gchar * user;
67  gint auth;
68  gchar * password;
69  gchar * privkeyfile;
70 
71  gchar * charset;
72  const gchar * kex_algorithms;
73  gchar * ciphers;
74  gchar * hostkeytypes;
75  gchar * proxycommand;
77  const gchar * compression;
78 
79  gchar * error;
80 
81  pthread_mutex_t ssh_mutex;
82 
83  gchar * passphrase;
84 
85  gboolean is_tunnel;
88 
89 } RemminaSSH;
90 
91 gchar *remmina_ssh_identity_path(const gchar *id);
92 
93 /* Auto-detect commonly used private key identities */
94 gchar *remmina_ssh_find_identity(void);
95 
96 /* Initialize the ssh object */
97 gboolean remmina_ssh_init_from_file(RemminaSSH *ssh, RemminaFile *remminafile, gboolean is_tunnel);
98 
99 /* Initialize the SSH session */
100 gboolean remmina_ssh_init_session(RemminaSSH *ssh);
101 
102 /* Authenticate SSH session */
103 
104 
110 };
111 
113 
115 
116 /* Error handling */
117 #define remmina_ssh_has_error(ssh) (((RemminaSSH *)ssh)->error != NULL)
118 void remmina_ssh_set_error(RemminaSSH *ssh, const gchar *fmt);
119 void remmina_ssh_set_application_error(RemminaSSH *ssh, const gchar *fmt, ...);
120 
121 /* Converts a string to/from UTF-8, or simply duplicate it if no conversion */
122 gchar *remmina_ssh_convert(RemminaSSH *ssh, const gchar *from);
123 gchar *remmina_ssh_unconvert(RemminaSSH *ssh, const gchar *from);
124 
125 void remmina_ssh_free(RemminaSSH *ssh);
126 
127 /*-----------------------------------------------------------------------------*
128 * SSH Tunnel *
129 *-----------------------------------------------------------------------------*/
131 typedef struct _RemminaSSHTunnelBuffer RemminaSSHTunnelBuffer;
132 
133 typedef gboolean (*RemminaSSHTunnelCallback) (RemminaSSHTunnel *, gpointer);
134 
135 enum {
140 };
141 
142 
145 
147 
148  ssh_channel * channels;
149  gint * sockets;
153 
154  ssh_channel x11_channel;
155 
156  pthread_t thread;
157  gboolean running;
158 
159  gchar * buffer;
161  ssh_channel * channels_out;
162 
164  gchar * dest;
165  gint port;
166  gint localport;
167 
169  gboolean bindlocalhost;
170  gchar * localdisplay;
171 
175  gpointer callback_data;
176 
179 
180 };
181 
182 /* Create a new SSH Tunnel session and connects to the SSH server */
184 
185 /* Open the tunnel. A new thread will be started and listen on a local port.
186  * dest: The host:port of the remote destination
187  * local_port: The listening local port for the tunnel
188  */
189 gboolean remmina_ssh_tunnel_open(RemminaSSHTunnel *tunnel, const gchar *host, gint port, gint local_port);
190 
191 /* Cancel accepting any incoming tunnel request.
192  * Typically called after the connection has already been establish.
193  */
195 
196 /* Accept the X11 tunnel. A new thread will be started and connect to local display.
197  * cmd: The remote X11 application to be executed
198  */
199 gboolean remmina_ssh_tunnel_x11(RemminaSSHTunnel *tunnel, const gchar *cmd);
200 
201 /* start X Port Forwarding */
202 gboolean remmina_ssh_tunnel_xport(RemminaSSHTunnel *tunnel, gboolean bindlocalhost);
203 
204 /* start reverse tunnel. A new thread will be started and waiting for incoming connection.
205  * port: the port listening on the remote server side.
206  * local_port: the port listening on the local side. When connection on the server side comes
207  * in, it will connect to the local port and create the tunnel. The caller should
208  * start listening on the local port before calling it or in connect_func callback.
209  */
210 gboolean remmina_ssh_tunnel_reverse(RemminaSSHTunnel *tunnel, gint port, gint local_port);
211 
212 /* Tells if the tunnel is terminated after start */
214 
215 /* Free the tunnel */
217 
218 /*-----------------------------------------------------------------------------*
219 * SSH sFTP *
220 *-----------------------------------------------------------------------------*/
221 
222 typedef struct _RemminaSFTP {
224 
225  sftp_session sftp_sess;
226 } RemminaSFTP;
227 
228 /* Create a new SFTP session object from RemminaFile */
230 
231 /* Create a new SFTP session object from existing SSH session */
233 
234 /* open the SFTP session, assuming the session already authenticated */
235 gboolean remmina_sftp_open(RemminaSFTP *sftp);
236 
237 /* Free the SFTP session */
238 void remmina_sftp_free(RemminaSFTP *sftp);
239 
240 /*-----------------------------------------------------------------------------*
241 * SSH Shell *
242 *-----------------------------------------------------------------------------*/
243 typedef void (*RemminaSSHExitFunc) (gpointer data);
244 
245 typedef struct _RemminaSSHShell {
247 
248  gint master;
249  gint slave;
250  gchar * exec;
251  pthread_t thread;
252  ssh_channel channel;
253  gboolean closed;
255  gpointer user_data;
257 
258 /* Create a new SSH Shell session object from RemminaFile */
260 
261 /* Create a new SSH Shell session object from existing SSH session */
263 
264 /* open the SSH Shell, assuming the session already authenticated */
265 gboolean remmina_ssh_shell_open(RemminaSSHShell *shell, RemminaSSHExitFunc exit_callback, gpointer data);
266 
267 /* Change the SSH Shell terminal size */
268 void remmina_ssh_shell_set_size(RemminaSSHShell *shell, gint columns, gint rows);
269 
270 /* Free the SFTP session */
272 
273 G_END_DECLS
274 
275 #else
276 
277 #define RemminaSSH void
278 #define RemminaSSHTunnel void
279 #define RemminaSFTP void
280 #define RemminaSSHShell void
281 typedef void (*RemminaSSHTunnelCallback)(void);
282 
283 #endif /* HAVE_LIBSSH */
struct _RemminaSSHTunnelBuffer RemminaSSHTunnelBuffer
Definition: remmina_ssh.h:131
enum remmina_ssh_auth_result remmina_ssh_auth_gui(RemminaSSH *ssh, RemminaProtocolWidget *gp, RemminaFile *remminafile)
gchar * proxycommand
Definition: remmina_ssh.h:75
RemminaSSHTunnelCallback destroy_func
Definition: remmina_ssh.h:177
gboolean remmina_ssh_tunnel_x11(RemminaSSHTunnel *tunnel, const gchar *cmd)
gchar * remmina_ssh_unconvert(RemminaSSH *ssh, const gchar *from)
gboolean remmina_ssh_tunnel_reverse(RemminaSSHTunnel *tunnel, gint port, gint local_port)
RemminaSSHShell * remmina_ssh_shell_new_from_ssh(RemminaSSH *ssh)
gchar * error
Definition: remmina_ssh.h:79
gchar * passphrase
Definition: remmina_ssh.h:83
pthread_mutex_t ssh_mutex
Definition: remmina_ssh.h:81
typedefG_BEGIN_DECLS struct _RemminaFile RemminaFile
Definition: types.h:41
gchar * ciphers
Definition: remmina_ssh.h:73
gpointer user_data
Definition: remmina_ssh.h:255
gboolean(* RemminaSSHTunnelCallback)(RemminaSSHTunnel *, gpointer)
Definition: remmina_ssh.h:133
gpointer destroy_func_callback_data
Definition: remmina_ssh.h:178
gchar * charset
Definition: remmina_ssh.h:71
void remmina_ssh_free(RemminaSSH *ssh)
sftp_session sftp_sess
Definition: remmina_ssh.h:225
pthread_t thread
Definition: remmina_ssh.h:251
gchar * hostkeytypes
Definition: remmina_ssh.h:74
enum remmina_ssh_auth_result remmina_ssh_auth(RemminaSSH *ssh, const gchar *password, RemminaProtocolWidget *gp, RemminaFile *remminafile)
Definition: remmina_ssh.c:336
ssh_channel channel
Definition: remmina_ssh.h:252
gboolean bindlocalhost
Definition: remmina_ssh.h:169
RemminaSSH ssh
Definition: remmina_ssh.h:144
const gchar * kex_algorithms
Definition: remmina_ssh.h:72
gchar * remmina_ssh_identity_path(const gchar *id)
Definition: remmina_ssh.c:120
RemminaSSHTunnelCallback disconnect_func
Definition: remmina_ssh.h:174
gboolean remmina_ssh_init_from_file(RemminaSSH *ssh, RemminaFile *remminafile, gboolean is_tunnel)
remmina_ssh_auth_result
Definition: remmina_ssh.h:105
void remmina_ssh_set_error(RemminaSSH *ssh, const gchar *fmt)
Definition: remmina_ssh.c:145
void remmina_ssh_shell_free(RemminaSSHShell *shell)
gchar * user
Definition: remmina_ssh.h:66
ssh_channel * channels_out
Definition: remmina_ssh.h:161
gint tunnel_entrance_port
Definition: remmina_ssh.h:87
RemminaSSHShell * remmina_ssh_shell_new_from_file(RemminaFile *remminafile)
gboolean remmina_ssh_tunnel_xport(RemminaSSHTunnel *tunnel, gboolean bindlocalhost)
gchar * server
Definition: remmina_ssh.h:64
RemminaSSHTunnel * remmina_ssh_tunnel_new_from_file(RemminaFile *remminafile)
RemminaSSH ssh
Definition: remmina_ssh.h:223
RemminaSSHTunnelCallback init_func
Definition: remmina_ssh.h:172
gint stricthostkeycheck
Definition: remmina_ssh.h:76
gpointer callback_data
Definition: remmina_ssh.h:175
const gchar * compression
Definition: remmina_ssh.h:77
gboolean is_tunnel
Definition: remmina_ssh.h:85
void remmina_ssh_tunnel_cancel_accept(RemminaSSHTunnel *tunnel)
gboolean remmina_ssh_shell_open(RemminaSSHShell *shell, RemminaSSHExitFunc exit_callback, gpointer data)
pthread_t thread
Definition: remmina_ssh.h:156
ssh_channel * channels
Definition: remmina_ssh.h:148
void remmina_ssh_tunnel_free(RemminaSSHTunnel *tunnel)
gchar * tunnel_entrance_host
Definition: remmina_ssh.h:86
struct _RemminaSSH RemminaSSH
gchar * password
Definition: remmina_ssh.h:68
RemminaSFTP * remmina_sftp_new_from_ssh(RemminaSSH *ssh)
gchar * privkeyfile
Definition: remmina_ssh.h:69
ssh_session session
Definition: remmina_ssh.h:60
RemminaSSHTunnelBuffer ** socketbuffers
Definition: remmina_ssh.h:150
RemminaSSHExitFunc exit_callback
Definition: remmina_ssh.h:254
RemminaSSH ssh
Definition: remmina_ssh.h:246
ssh_channel x11_channel
Definition: remmina_ssh.h:154
gchar * remmina_ssh_convert(RemminaSSH *ssh, const gchar *from)
gchar * remmina_ssh_find_identity(void)
Definition: remmina_ssh.c:129
ssh_callbacks callback
Definition: remmina_ssh.h:61
gboolean remmina_sftp_open(RemminaSFTP *sftp)
struct _RemminaSSHShell RemminaSSHShell
gboolean remmina_ssh_tunnel_terminated(RemminaSSHTunnel *tunnel)
void remmina_sftp_free(RemminaSFTP *sftp)
gboolean authenticated
Definition: remmina_ssh.h:62
struct _RemminaSFTP RemminaSFTP
void(* RemminaSSHExitFunc)(gpointer data)
Definition: remmina_ssh.h:243
gboolean remmina_ssh_tunnel_open(RemminaSSHTunnel *tunnel, const gchar *host, gint port, gint local_port)
RemminaSFTP * remmina_sftp_new_from_file(RemminaFile *remminafile)
void remmina_ssh_set_application_error(RemminaSSH *ssh, const gchar *fmt,...)
Definition: remmina_ssh.c:155
gchar * localdisplay
Definition: remmina_ssh.h:170
void remmina_ssh_shell_set_size(RemminaSSHShell *shell, gint columns, gint rows)
RemminaSSHTunnelCallback connect_func
Definition: remmina_ssh.h:173
gboolean remmina_ssh_init_session(RemminaSSH *ssh)