Remmina - The GTK+ Remote Desktop Client  v1.4.33
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-2023 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  gchar * certfile;
71 
72  gchar * charset;
73  const gchar * kex_algorithms;
74  gchar * ciphers;
75  gchar * hostkeytypes;
76  gchar * proxycommand;
78  const gchar * compression;
79 
80  gchar * error;
81 
82  pthread_mutex_t ssh_mutex;
83 
84  gchar * passphrase;
85 
86  gboolean is_tunnel;
87  gboolean is_multiauth;
90 
91 } RemminaSSH;
92 
93 gchar *remmina_ssh_identity_path(const gchar *id);
94 
95 /* Auto-detect commonly used private key identities */
96 gchar *remmina_ssh_find_identity(void);
97 
98 /* Initialize the ssh object */
99 gboolean remmina_ssh_init_from_file(RemminaSSH *ssh, RemminaFile *remminafile, gboolean is_tunnel);
100 
101 /* Initialize the SSH session */
102 gboolean remmina_ssh_init_session(RemminaSSH *ssh);
103 
104 /* Authenticate SSH session */
105 
106 
116 };
117 
119 
121 
122 /* Error handling */
123 #define remmina_ssh_has_error(ssh) (((RemminaSSH *)ssh)->error != NULL)
124 void remmina_ssh_set_error(RemminaSSH *ssh, const gchar *fmt);
125 void remmina_ssh_set_application_error(RemminaSSH *ssh, const gchar *fmt, ...);
126 
127 /* Converts a string to/from UTF-8, or simply duplicate it if no conversion */
128 gchar *remmina_ssh_convert(RemminaSSH *ssh, const gchar *from);
129 gchar *remmina_ssh_unconvert(RemminaSSH *ssh, const gchar *from);
130 
131 void remmina_ssh_free(RemminaSSH *ssh);
132 
133 /*-----------------------------------------------------------------------------*
134 * SSH Tunnel *
135 *-----------------------------------------------------------------------------*/
137 typedef struct _RemminaSSHTunnelBuffer RemminaSSHTunnelBuffer;
138 
139 typedef gboolean (*RemminaSSHTunnelCallback) (RemminaSSHTunnel *, gpointer);
140 
141 enum {
145 };
146 
147 
150 
152 
153  ssh_channel * channels;
154  gint * sockets;
158 
159  pthread_t thread;
160  gboolean running;
161 
162  gchar * buffer;
164  ssh_channel * channels_out;
165 
167  gchar * dest;
168  gint port;
169  gint localport;
170 
172  gboolean bindlocalhost;
173  gchar * localdisplay;
174 
178  gpointer callback_data;
179 
182 
183 };
184 
185 /* Create a new SSH Tunnel session and connects to the SSH server */
187 
188 /* Open the tunnel. A new thread will be started and listen on a local port.
189  * dest: The host:port of the remote destination
190  * local_port: The listening local port for the tunnel
191  */
192 gboolean remmina_ssh_tunnel_open(RemminaSSHTunnel *tunnel, const gchar *host, gint port, gint local_port);
193 
194 /* Cancel accepting any incoming tunnel request.
195  * Typically called after the connection has already been establish.
196  */
198 
199 /* start X Port Forwarding */
200 gboolean remmina_ssh_tunnel_xport(RemminaSSHTunnel *tunnel, gboolean bindlocalhost);
201 
202 /* start reverse tunnel. A new thread will be started and waiting for incoming connection.
203  * port: the port listening on the remote server side.
204  * local_port: the port listening on the local side. When connection on the server side comes
205  * in, it will connect to the local port and create the tunnel. The caller should
206  * start listening on the local port before calling it or in connect_func callback.
207  */
208 gboolean remmina_ssh_tunnel_reverse(RemminaSSHTunnel *tunnel, gint port, gint local_port);
209 
210 /* Tells if the tunnel is terminated after start */
212 
213 /* Free the tunnel */
215 
216 /*-----------------------------------------------------------------------------*
217 * SSH sFTP *
218 *-----------------------------------------------------------------------------*/
219 
220 typedef struct _RemminaSFTP {
222 
223  sftp_session sftp_sess;
224 } RemminaSFTP;
225 
226 /* Create a new SFTP session object from RemminaFile */
228 
229 /* Create a new SFTP session object from existing SSH session */
231 
232 /* open the SFTP session, assuming the session already authenticated */
233 gboolean remmina_sftp_open(RemminaSFTP *sftp);
234 
235 /* Free the SFTP session */
236 void remmina_sftp_free(RemminaSFTP *sftp);
237 
238 /*-----------------------------------------------------------------------------*
239 * SSH Shell *
240 *-----------------------------------------------------------------------------*/
241 typedef void (*RemminaSSHExitFunc) (gpointer data);
242 
243 typedef struct _RemminaSSHShell {
245 
246  gint master;
247  gint slave;
248  gchar * exec;
249  gchar * run_line;
250  pthread_t thread;
251  ssh_channel channel;
252  gboolean closed;
254  gpointer user_data;
255  ssh_event event;
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:137
enum remmina_ssh_auth_result remmina_ssh_auth_gui(RemminaSSH *ssh, RemminaProtocolWidget *gp, RemminaFile *remminafile)
gchar * proxycommand
Definition: remmina_ssh.h:76
RemminaSSHTunnelCallback destroy_func
Definition: remmina_ssh.h:180
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:80
gchar * passphrase
Definition: remmina_ssh.h:84
pthread_mutex_t ssh_mutex
Definition: remmina_ssh.h:82
typedefG_BEGIN_DECLS struct _RemminaFile RemminaFile
Definition: types.h:44
gchar * ciphers
Definition: remmina_ssh.h:74
gpointer user_data
Definition: remmina_ssh.h:254
gboolean(* RemminaSSHTunnelCallback)(RemminaSSHTunnel *, gpointer)
Definition: remmina_ssh.h:139
gpointer destroy_func_callback_data
Definition: remmina_ssh.h:181
gchar * charset
Definition: remmina_ssh.h:72
void remmina_ssh_free(RemminaSSH *ssh)
sftp_session sftp_sess
Definition: remmina_ssh.h:223
pthread_t thread
Definition: remmina_ssh.h:250
gchar * hostkeytypes
Definition: remmina_ssh.h:75
enum remmina_ssh_auth_result remmina_ssh_auth(RemminaSSH *ssh, const gchar *password, RemminaProtocolWidget *gp, RemminaFile *remminafile)
Definition: remmina_ssh.c:1085
ssh_channel channel
Definition: remmina_ssh.h:251
gboolean bindlocalhost
Definition: remmina_ssh.h:172
RemminaSSH ssh
Definition: remmina_ssh.h:149
const gchar * kex_algorithms
Definition: remmina_ssh.h:73
gchar * remmina_ssh_identity_path(const gchar *id)
Definition: remmina_ssh.c:628
RemminaSSHTunnelCallback disconnect_func
Definition: remmina_ssh.h:177
gboolean remmina_ssh_init_from_file(RemminaSSH *ssh, RemminaFile *remminafile, gboolean is_tunnel)
remmina_ssh_auth_result
Definition: remmina_ssh.h:107
void remmina_ssh_set_error(RemminaSSH *ssh, const gchar *fmt)
Definition: remmina_ssh.c:653
void remmina_ssh_shell_free(RemminaSSHShell *shell)
gchar * user
Definition: remmina_ssh.h:66
ssh_channel * channels_out
Definition: remmina_ssh.h:164
gint tunnel_entrance_port
Definition: remmina_ssh.h:89
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:221
RemminaSSHTunnelCallback init_func
Definition: remmina_ssh.h:175
gint stricthostkeycheck
Definition: remmina_ssh.h:77
gpointer callback_data
Definition: remmina_ssh.h:178
const gchar * compression
Definition: remmina_ssh.h:78
gboolean is_tunnel
Definition: remmina_ssh.h:86
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:159
ssh_channel * channels
Definition: remmina_ssh.h:153
void remmina_ssh_tunnel_free(RemminaSSHTunnel *tunnel)
gchar * tunnel_entrance_host
Definition: remmina_ssh.h:88
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:155
RemminaSSHExitFunc exit_callback
Definition: remmina_ssh.h:253
RemminaSSH ssh
Definition: remmina_ssh.h:244
gchar * remmina_ssh_convert(RemminaSSH *ssh, const gchar *from)
gchar * remmina_ssh_find_identity(void)
Definition: remmina_ssh.c:637
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:241
ssh_event event
Definition: remmina_ssh.h:255
gboolean remmina_ssh_tunnel_open(RemminaSSHTunnel *tunnel, const gchar *host, gint port, gint local_port)
RemminaSFTP * remmina_sftp_new_from_file(RemminaFile *remminafile)
gchar * certfile
Definition: remmina_ssh.h:70
void remmina_ssh_set_application_error(RemminaSSH *ssh, const gchar *fmt,...)
Definition: remmina_ssh.c:663
gchar * localdisplay
Definition: remmina_ssh.h:173
void remmina_ssh_shell_set_size(RemminaSSHShell *shell, gint columns, gint rows)
RemminaSSHTunnelCallback connect_func
Definition: remmina_ssh.h:176
gboolean is_multiauth
Definition: remmina_ssh.h:87
gboolean remmina_ssh_init_session(RemminaSSH *ssh)