Remmina - The GTK+ Remote Desktop Client  v1.4.34
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 
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 */
103 
104 /* Authenticate SSH session */
105 
106 
117 };
118 
119 enum remmina_ssh_auth_result remmina_ssh_auth(RemminaSSH *ssh, const gchar *password, RemminaProtocolWidget *gp, RemminaFile *remminafile);
120 
122 
123 /* Error handling */
124 #define remmina_ssh_has_error(ssh) (((RemminaSSH *)ssh)->error != NULL)
125 void remmina_ssh_set_error(RemminaSSH *ssh, const gchar *fmt);
126 void remmina_ssh_set_application_error(RemminaSSH *ssh, const gchar *fmt, ...);
127 
128 /* Converts a string to/from UTF-8, or simply duplicate it if no conversion */
129 gchar *remmina_ssh_convert(RemminaSSH *ssh, const gchar *from);
130 gchar *remmina_ssh_unconvert(RemminaSSH *ssh, const gchar *from);
131 
133 
134 /*-----------------------------------------------------------------------------*
135 * SSH Tunnel *
136 *-----------------------------------------------------------------------------*/
137 typedef struct _RemminaSSHTunnel RemminaSSHTunnel;
138 typedef struct _RemminaSSHTunnelBuffer RemminaSSHTunnelBuffer;
139 
140 typedef gboolean (*RemminaSSHTunnelCallback) (RemminaSSHTunnel *, gpointer);
141 
142 enum {
146 };
147 
148 
151 
153 
154  ssh_channel * channels;
155  gint * sockets;
159 
160  pthread_t thread;
161  gboolean running;
162 
163  gchar * buffer;
165  ssh_channel * channels_out;
166 
168  gchar * dest;
169  gint port;
170  gint localport;
171 
173  gboolean bindlocalhost;
174  gchar * localdisplay;
175 
179  gpointer callback_data;
180 
183 
184 };
185 
186 /* Create a new SSH Tunnel session and connects to the SSH server */
188 
189 /* Open the tunnel. A new thread will be started and listen on a local port.
190  * dest: The host:port of the remote destination
191  * local_port: The listening local port for the tunnel
192  */
193 gboolean remmina_ssh_tunnel_open(RemminaSSHTunnel *tunnel, const gchar *host, gint port, gint local_port);
194 
195 /* Cancel accepting any incoming tunnel request.
196  * Typically called after the connection has already been establish.
197  */
199 
200 /* start X Port Forwarding */
201 gboolean remmina_ssh_tunnel_xport(RemminaSSHTunnel *tunnel, gboolean bindlocalhost);
202 
203 /* start reverse tunnel. A new thread will be started and waiting for incoming connection.
204  * port: the port listening on the remote server side.
205  * local_port: the port listening on the local side. When connection on the server side comes
206  * in, it will connect to the local port and create the tunnel. The caller should
207  * start listening on the local port before calling it or in connect_func callback.
208  */
209 gboolean remmina_ssh_tunnel_reverse(RemminaSSHTunnel *tunnel, gint port, gint local_port);
210 
211 /* Tells if the tunnel is terminated after start */
213 
214 /* Free the tunnel */
216 
217 /*-----------------------------------------------------------------------------*
218 * SSH sFTP *
219 *-----------------------------------------------------------------------------*/
220 
221 typedef struct _RemminaSFTP {
223 
224  sftp_session sftp_sess;
226 
227 /* Create a new SFTP session object from RemminaFile */
229 
230 /* Create a new SFTP session object from existing SSH session */
232 
233 /* open the SFTP session, assuming the session already authenticated */
235 
236 /* Free the SFTP session */
238 
239 /*-----------------------------------------------------------------------------*
240 * SSH Shell *
241 *-----------------------------------------------------------------------------*/
242 typedef void (*RemminaSSHExitFunc) (gpointer data);
243 
244 typedef struct _RemminaSSHShell {
246 
247  gint master;
248  gint slave;
249  gchar * exec;
250  gchar * run_line;
251  pthread_t thread;
252  ssh_channel channel;
253  gboolean closed;
255  gpointer user_data;
256  ssh_event event;
258 
259 /* Create a new SSH Shell session object from RemminaFile */
261 
262 /* Create a new SSH Shell session object from existing SSH session */
264 
265 /* open the SSH Shell, assuming the session already authenticated */
266 gboolean remmina_ssh_shell_open(RemminaSSHShell *shell, RemminaSSHExitFunc exit_callback, gpointer data);
267 
268 /* Change the SSH Shell terminal size */
269 void remmina_ssh_shell_set_size(RemminaSSHShell *shell, gint columns, gint rows);
270 
271 /* Free the SFTP session */
273 
274 G_END_DECLS
275 
276 #else
277 
278 #define RemminaSSH void
279 #define RemminaSSHTunnel void
280 #define RemminaSFTP void
281 #define RemminaSSHShell void
282 typedef void (*RemminaSSHTunnelCallback)(void);
283 
284 #endif /* HAVE_LIBSSH */
gchar * remmina_ssh_convert(RemminaSSH *ssh, const gchar *from)
struct _RemminaSFTP RemminaSFTP
RemminaSFTP * remmina_sftp_new_from_ssh(RemminaSSH *ssh)
gboolean remmina_ssh_shell_open(RemminaSSHShell *shell, RemminaSSHExitFunc exit_callback, gpointer data)
gboolean remmina_sftp_open(RemminaSFTP *sftp)
void remmina_ssh_set_application_error(RemminaSSH *ssh, const gchar *fmt,...)
Definition: remmina_ssh.c:664
void remmina_ssh_tunnel_free(RemminaSSHTunnel *tunnel)
struct _RemminaSSHShell RemminaSSHShell
RemminaSSHShell * remmina_ssh_shell_new_from_file(RemminaFile *remminafile)
void remmina_ssh_shell_free(RemminaSSHShell *shell)
RemminaSFTP * remmina_sftp_new_from_file(RemminaFile *remminafile)
void(* RemminaSSHExitFunc)(gpointer data)
Definition: remmina_ssh.h:242
gboolean remmina_ssh_tunnel_open(RemminaSSHTunnel *tunnel, const gchar *host, gint port, gint local_port)
gboolean(* RemminaSSHTunnelCallback)(RemminaSSHTunnel *, gpointer)
Definition: remmina_ssh.h:140
gboolean remmina_ssh_init_session(RemminaSSH *ssh)
gboolean remmina_ssh_init_from_file(RemminaSSH *ssh, RemminaFile *remminafile, gboolean is_tunnel)
gchar * remmina_ssh_identity_path(const gchar *id)
Definition: remmina_ssh.c:629
@ REMMINA_SSH_TUNNEL_OPEN
Definition: remmina_ssh.h:143
@ REMMINA_SSH_TUNNEL_REVERSE
Definition: remmina_ssh.h:145
@ REMMINA_SSH_TUNNEL_XPORT
Definition: remmina_ssh.h:144
struct _RemminaSSH RemminaSSH
remmina_ssh_auth_result
Definition: remmina_ssh.h:107
@ REMMINA_SSH_AUTH_PARTIAL
Definition: remmina_ssh.h:110
@ REMMINA_SSH_AUTH_AGAIN
Definition: remmina_ssh.h:111
@ REMMINA_SSH_AUTH_AUTHFAILED_RETRY_AFTER_PROMPT
Definition: remmina_ssh.h:112
@ REMMINA_SSH_AUTH_USERCANCEL
Definition: remmina_ssh.h:113
@ REMMINA_SSH_AUTH_FATAL_ERROR
Definition: remmina_ssh.h:114
@ REMMINA_SSH_AUTH_RECONNECT
Definition: remmina_ssh.h:115
@ REMMINA_SSH_AUTH_SUCCESS
Definition: remmina_ssh.h:109
@ REMMINA_SSH_AUTH_AUTHFAILED_EMPTY_USERNAME
Definition: remmina_ssh.h:116
@ REMMINA_SSH_AUTH_NULL
Definition: remmina_ssh.h:108
void remmina_sftp_free(RemminaSFTP *sftp)
enum remmina_ssh_auth_result remmina_ssh_auth(RemminaSSH *ssh, const gchar *password, RemminaProtocolWidget *gp, RemminaFile *remminafile)
Definition: remmina_ssh.c:1092
gchar * remmina_ssh_find_identity(void)
Definition: remmina_ssh.c:638
gboolean remmina_ssh_tunnel_xport(RemminaSSHTunnel *tunnel, gboolean bindlocalhost)
void remmina_ssh_set_error(RemminaSSH *ssh, const gchar *fmt)
Definition: remmina_ssh.c:654
RemminaSSHTunnel * remmina_ssh_tunnel_new_from_file(RemminaFile *remminafile)
void remmina_ssh_shell_set_size(RemminaSSHShell *shell, gint columns, gint rows)
void remmina_ssh_free(RemminaSSH *ssh)
enum remmina_ssh_auth_result remmina_ssh_auth_gui(RemminaSSH *ssh, RemminaProtocolWidget *gp, RemminaFile *remminafile)
RemminaSSHShell * remmina_ssh_shell_new_from_ssh(RemminaSSH *ssh)
gboolean remmina_ssh_tunnel_reverse(RemminaSSHTunnel *tunnel, gint port, gint local_port)
void remmina_ssh_tunnel_cancel_accept(RemminaSSHTunnel *tunnel)
gboolean remmina_ssh_tunnel_terminated(RemminaSSHTunnel *tunnel)
gchar * remmina_ssh_unconvert(RemminaSSH *ssh, const gchar *from)
struct _RemminaSSHTunnelBuffer RemminaSSHTunnelBuffer
Definition: remmina_ssh.h:138
RemminaSSH ssh
Definition: remmina_ssh.h:222
sftp_session sftp_sess
Definition: remmina_ssh.h:224
gchar * charset
Definition: remmina_ssh.h:72
gchar * ciphers
Definition: remmina_ssh.h:74
const gchar * kex_algorithms
Definition: remmina_ssh.h:73
gchar * certfile
Definition: remmina_ssh.h:70
gchar * user
Definition: remmina_ssh.h:66
gchar * error
Definition: remmina_ssh.h:80
ssh_session session
Definition: remmina_ssh.h:60
pthread_mutex_t ssh_mutex
Definition: remmina_ssh.h:82
gint stricthostkeycheck
Definition: remmina_ssh.h:77
gchar * hostkeytypes
Definition: remmina_ssh.h:75
gboolean is_multiauth
Definition: remmina_ssh.h:87
gint tunnel_entrance_port
Definition: remmina_ssh.h:89
gchar * passphrase
Definition: remmina_ssh.h:84
ssh_callbacks callback
Definition: remmina_ssh.h:61
const gchar * compression
Definition: remmina_ssh.h:78
gchar * proxycommand
Definition: remmina_ssh.h:76
gboolean authenticated
Definition: remmina_ssh.h:62
gboolean is_tunnel
Definition: remmina_ssh.h:86
gchar * password
Definition: remmina_ssh.h:68
gchar * server
Definition: remmina_ssh.h:64
gchar * tunnel_entrance_host
Definition: remmina_ssh.h:88
gchar * privkeyfile
Definition: remmina_ssh.h:69
ssh_channel channel
Definition: remmina_ssh.h:252
pthread_t thread
Definition: remmina_ssh.h:251
RemminaSSHExitFunc exit_callback
Definition: remmina_ssh.h:254
ssh_event event
Definition: remmina_ssh.h:256
gpointer user_data
Definition: remmina_ssh.h:255
RemminaSSH ssh
Definition: remmina_ssh.h:245
gchar * localdisplay
Definition: remmina_ssh.h:174
RemminaSSHTunnelCallback disconnect_func
Definition: remmina_ssh.h:178
RemminaSSHTunnelCallback destroy_func
Definition: remmina_ssh.h:181
RemminaSSHTunnelBuffer ** socketbuffers
Definition: remmina_ssh.h:156
gpointer destroy_func_callback_data
Definition: remmina_ssh.h:182
ssh_channel * channels_out
Definition: remmina_ssh.h:165
gpointer callback_data
Definition: remmina_ssh.h:179
gboolean bindlocalhost
Definition: remmina_ssh.h:173
RemminaSSHTunnelCallback init_func
Definition: remmina_ssh.h:176
pthread_t thread
Definition: remmina_ssh.h:160
RemminaSSHTunnelCallback connect_func
Definition: remmina_ssh.h:177
ssh_channel * channels
Definition: remmina_ssh.h:154
RemminaSSH ssh
Definition: remmina_ssh.h:150
typedefG_BEGIN_DECLS struct _RemminaFile RemminaFile
Definition: types.h:44