Exemple #1
0
void ssh_channel_ftcp_destroy(void *context)
{
  SshChannelTypeTcpForward ct = (SshChannelTypeTcpForward)context;
  SshRemoteTcpForward remote_fwd, remote_next;

  /* Destroy all existing channels.
     XXX not implemented. */

  /* Free any remote forwarding records. */
  for (remote_fwd = ct->remote_forwards; remote_fwd;
       remote_fwd = remote_next)
    {
      remote_next = remote_fwd->next;
      if (remote_fwd->listener)
        ssh_tcp_destroy_listener(remote_fwd->listener);
      ssh_xfree(remote_fwd->address_to_bind);
      ssh_xfree(remote_fwd->port);
      ssh_xfree(remote_fwd->connect_to_host);
      ssh_xfree(remote_fwd->connect_to_port);
      memset(remote_fwd, 'F', sizeof(*remote_fwd));
      ssh_xfree(remote_fwd);
    }

  /* Destroy the channel type context. */
  memset(ct, 'F', sizeof(*ct));
  ssh_xfree(ct);
}
Exemple #2
0
void ssh_channel_dtcp_destroy(void *context)
{
  SshChannelTypeTcpDirect ct = (SshChannelTypeTcpDirect)context;
  SshLocalTcpForward local_fwd, local_next;

  /* Destroy all existing channels.
     XXX not implemented. */
  
  /* Free local forwarding records. */
  for (local_fwd = ct->local_forwards; local_fwd;
       local_fwd = local_next)
    {
      local_next = local_fwd->next;
      if (local_fwd->listener)
        ssh_tcp_destroy_listener(local_fwd->listener);
      ssh_xfree(local_fwd->connect_to_host);
      ssh_xfree(local_fwd->connect_to_port);
      memset(local_fwd, 'F', sizeof(*local_fwd));
      ssh_xfree(local_fwd);
    }

  /* Destroy the channel type context. */
  memset(ct, 'F', sizeof(*ct));
  ssh_xfree(ct);
}
Exemple #3
0
Boolean ssh_channel_tcp_forward_cancel(const char *type,
                                       const unsigned char *data,
                                       size_t len,
                                       void *context)
{
  SshCommon common = (SshCommon)context;
  char *address_to_bind;
  SshUInt32 port;
  char port_string[20];
  SshRemoteTcpForward fwd, *fwdp;
  SshChannelTypeTcpForward ct;

  SSH_DEBUG(5, ("remote TCP/IP cancel request received"));

  ct = ssh_channel_ftcp_ct(common);
  
  /* Don't allow a server to send remote forwarding requests to the client. */
  if (common->client)
    {
      ssh_warning("Remote TCP/IP forwarding cancel from server denied.");
      return FALSE;
    }
  
  /* Parse the request. */
  if (ssh_decode_array(data, len,
                       SSH_FORMAT_UINT32_STR, &address_to_bind, NULL,
                       SSH_FORMAT_UINT32, &port,
                       SSH_FORMAT_END) != len)
    {
      SSH_DEBUG(0, ("bad data"));
      return FALSE;
    }

  /* Convert port number to a string. */
  snprintf(port_string, sizeof(port_string), "%ld", (unsigned long) port);

  for (fwdp = &ct->remote_forwards; *fwdp; fwdp = &fwd->next)
    {
      fwd = *fwdp;
      if (strcmp(port_string, fwd->port) == 0 &&
          strcmp(address_to_bind, fwd->address_to_bind) == 0)
        {
          ssh_tcp_destroy_listener(fwd->listener);
          ssh_xfree(fwd->address_to_bind);
          ssh_xfree(fwd->port);
          *fwdp = fwd->next;
          ssh_xfree(fwd);
          ssh_xfree(address_to_bind);
          return TRUE;
        }
    }

  SSH_DEBUG(1, ("port %s address_to_bind %s not found",
                port_string, address_to_bind));
  ssh_xfree(address_to_bind);
  return FALSE;
}
Exemple #4
0
void t_tcpc_tcp_callback(SshTcpError      error,
                         SshStream    stream,
                         void*                context)
{
  t_tcpc_context  pcontext = context;




  SSH_TRACE(SSH_D_MY, ("%s", "t_tcpc_tcp_callback"));

  switch (error)
    {
    case SSH_TCP_OK:
      pcontext->pstream = stream;
      ssh_stream_set_callback(pcontext->pstream,
                              t_tcpc_stream_callback,
                              pcontext);
      ssh_xregister_timeout(pcontext->timeout,
                            0,
                            t_tcpc_timeout_callback,
                            pcontext);
      break;
    case SSH_TCP_NEW_CONNECTION:
      ssh_tcp_destroy_listener(pcontext->ptcplistener);
      pcontext->ptcplistener = 0;
      pcontext->pstream = stream;
      ssh_stream_set_callback(pcontext->pstream,
                              t_tcpc_stream_callback,
                              pcontext);
      break;
    case SSH_TCP_NO_ADDRESS:
      SSH_NOTREACHED;
      break;
    case SSH_TCP_NO_NAME:
      SSH_NOTREACHED;
      break;
    case SSH_TCP_UNREACHABLE:
      SSH_NOTREACHED;
      break;
    case SSH_TCP_REFUSED:
      SSH_NOTREACHED;
      break;
    case SSH_TCP_TIMEOUT:
      SSH_NOTREACHED;
      break;
    case SSH_TCP_FAILURE:
      SSH_NOTREACHED;
      break;
    default:
      SSH_NOTREACHED;
      break;
    }
}
Exemple #5
0
void listener_callback(SshIpError status, SshStream stream, void *context)
{
  SshPrivateKey private_host_key, private_server_key;
  unsigned char *blob;
  unsigned int blob_len = 0;
  Handler c;
  TestCase *testcase = context;
  SshTransportParams params;
  
  if (status != SSH_IP_NEW_CONNECTION)
    ssh_fatal("listener_callback: status %d", status);

#ifdef DEBUG
  ssh_debug("listener: new connection");
#endif
  
  create_server_keys(&private_host_key, &private_server_key, &blob, &blob_len);
  
  params = ssh_transport_create_params();
  update_algs(params, testcase->s_to_c_algs);

  c = ssh_xcalloc(sizeof(*c), 1);

  c->stream = ssh_transport_server_wrap(stream, random_state, SSH_VERSION,
                                        params,
                                        private_host_key, private_server_key,
                                        blob, blob_len, NULL, NULL);

  ssh_private_key_free(private_host_key);
  ssh_private_key_free(private_server_key);
  ssh_xfree(blob);
  c->script = testcase->server_script;
  c->side = "server";
  c->name = testcase->name;

  ssh_stream_set_callback(c->stream, handler_callback, (void *)c);
  server_handler = c;
  ssh_tcp_destroy_listener(listener);
}