[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SSH Tunnels
[Thread Prev] | [Thread Next]
- Subject: Re: SSH Tunnels
- From: Loïc Michaux <lmichaux@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 12 Mar 2014 17:36:27 +0100 (CET)
- To: libssh@xxxxxxxxxx
Hi Andreas, Thanks you for your answer and your server example. I pretty well understood the libssh callbacks implementation. My question is about callbacks catching tunneling/port forwarding/... requests, libssh doesn't seem to meet this need yet. If you take a look at src/messages.c, in ssh_execute_server_request(), you will find : case SSH_REQUEST_CHANNEL_OPEN: if (msg->channel_request_open.type == SSH_CHANNEL_SESSION && ssh_callbacks_exists(session->server_callbacks, channel_open_request_session_function)) { [...] } But no "if (msg->channel_request_open.type == SSH_CHANNEL_DIRECT_TCPIP [...]" or something like that. You will find a short example of code about what I want to do attached to this message. The patch I attached on my previous message do the job. -- Loïc Michaux ----- Original Message ----- From: "Andreas Schneider" <asn@xxxxxxxxxxxxxx> To: libssh@xxxxxxxxxx Sent: Wednesday, March 12, 2014 4:17:03 PM Subject: Re: SSH Tunnels On Wednesday 12 February 2014 13:27:46 Loïc Michaux wrote: > Hi, Hey, > I am currently trying to implement tunnels via ssh forwardings and libssh > callbacks system. > > Some questions where posted here about this kind of problem but I couldn't > find any detailed answer. > > When trying to open tunnels with `ssh -p <port> -ND <lport> > <user>@<server_addr>` (or any other set of options which asks for tunnels), > no callback is triggered in order to handle this. > > I supposed at least channel_open_request_session_function() or > global_request_function() had to be called with a SSH_REQUEST_GLOBAL > request type or a SSH_CHANNEL_FORWARDED_TCPIP channel type, but this is not > what actually happens. > > Did I miss something ? A callback specially created for this use ? > Or do I have to patch the lib to create one or more callbacks which will be > triggered by ssh_execute_server_request() in src/messages.c ? this is not the callback way how libssh server should be implemented. See http://git.libssh.org/projects/libssh.git/tree/examples/ssh_server_fork.c -- andreas -- Andreas Schneider GPG-ID: CC014E3D www.cryptomilk.org asn@xxxxxxxxxxxxxx
#include <libssh/libssh.h> #include <libssh/server.h> #include <libssh/callbacks.h> #include <stdlib.h> static ssh_channel channel_open_request_session(ssh_session session, void *userdata) { (void) session; (void) userdata; ssh_channel chan = NULL; return chan; } static ssh_channel channel_open_direct_tcpip(ssh_session session, const char *dest, uint16_t dest_port, const char *orig, uint16_t orig_port, void *userdata) { (void) userdata; ssh_channel chan = NULL; /* XXX Do someting ... */ return chan; } int main(void) { ssh_session session; ssh_bind ssh_bind; ssh_event e; struct ssh_server_callbacks_struct srv_cb = { .userdata = NULL, .channel_open_request_session_function = channel_open_request_session, .channel_open_request_direct_tcpip_function = channel_open_direct_tcpip, }; /* [...] */ ssh_callbacks_init(&srv_cb); ssh_set_server_callbacks(session, &srv_cb); /* [...] */ e = ssh_event_new(); ssh_event_add_session(e, session); while (1) { /* [...] */ ssh_event_dopoll(e, 100); /* [...] */ } return EXIT_SUCCESS; }
Re: SSH Tunnels | Andreas Schneider <asn@xxxxxxxxxxxxxx> |