Exemplo n.º 1
0
pid_t ssh_pipe_get_pid(SshStream stream)
{
    SshPipeStream pipes;
    if (ssh_stream_get_methods(stream) != (void *)&ssh_pipe_methods)
        return 0;
    pipes = ssh_stream_get_context(stream);
    return pipes->pid;
}
Exemplo n.º 2
0
int ssh_pipe_get_exit_status(SshStream stream)
{
    SshPipeStream pipes;
    if (ssh_stream_get_methods(stream) != (void *)&ssh_pipe_methods)
        return FALSE;
    pipes = ssh_stream_get_context(stream);

    if (!pipes->status_returned)
        ssh_fatal("ssh_pipe_get_exit_status called before the child has exited.");

    return pipes->exit_status;
}
Exemplo n.º 3
0
void ssh_packet_impl_can_receive(SshStream up_stream, Boolean enable)
{
  SshPacketImpl up;

  /* Verify that it is a SshPacketImpl stream. */
  if (ssh_stream_get_methods(up_stream) != &ssh_packet_impl_methods)
    ssh_fatal("ssh_packet_impl_can_receive: not a SshPacketImpl stream");
  /* Get the internal context. */
  up = (SshPacketImpl)ssh_stream_get_context(up_stream);

  /* Save new status. */
  up->can_receive = enable;

  /* If allowing receive and writes are blocked, restart them now. */
  if (enable == TRUE && up->up_write_blocked)
    ssh_packet_impl_restart_output(up);
}
Exemplo n.º 4
0
void ssh_packet_impl_send_eof(SshStream up_stream)
{
  SshPacketImpl up;

  /* Verify that it is a SshPacketImpl stream. */
  if (ssh_stream_get_methods(up_stream) != &ssh_packet_impl_methods)
    ssh_fatal("ssh_packet_impl_can_receive: not a SshPacketImpl stream");
  /* Get the internal context. */
  up = (SshPacketImpl)ssh_stream_get_context(up_stream);

  /* If EOF not already sent, signal the upper level that data is available
     for reading. */
  if (!up->outgoing_eof)
    {
      up->outgoing_eof = TRUE;
      ssh_packet_impl_restart_input(up);
    }
}
Exemplo n.º 5
0
void ssh_packet_impl_send_encode_va(SshStream up_stream,
                                    SshPacketType type,
                                    va_list va)
{
  SshPacketImpl up;

  /* Verify that it is a SshPacketImpl stream. */
  if (ssh_stream_get_methods(up_stream) != &ssh_packet_impl_methods)
    ssh_fatal("ssh_packet_impl_can_receive: not a SshPacketImpl stream");
  /* Get the internal context. */
  up = (SshPacketImpl)ssh_stream_get_context(up_stream);

  /* Format the packet in a separate buffer. */
  ssh_buffer_clear(&up->outgoing_packet);
  ssh_packet_encode_va(&up->outgoing_packet, type, va);

  /* Check that we don't overflow maximum buffer size.  Drop the
     packet if we would. */
  if (ssh_buffer_len(&up->outgoing) + ssh_buffer_len(&up->outgoing_packet) >=
      BUFFER_MAX_SIZE)
    {
      ssh_debug("ssh_packet_impl_send_encode_va: "
                "flow control problems; outgoing packet dropped.");
      return;
    }

  /* Append the packet to the outgoing buffer. */
  if (ssh_buffer_append(&up->outgoing,
                        ssh_buffer_ptr(&up->outgoing_packet),
                        ssh_buffer_len(&up->outgoing_packet)) != SSH_BUFFER_OK)
    {
      return;
    }

  /* Restart reads by upper level. */
  ssh_packet_impl_restart_input(up);

  /* Sanity check that we didn't exceed max buffer size. */
  if (ssh_buffer_len(&up->outgoing) > BUFFER_MAX_SIZE)
    ssh_debug("ssh_packet_impl_send: buffer max size exceeded: size %ld",
              (long)ssh_buffer_len(&up->outgoing));
}
Exemplo n.º 6
0
void ssh_packet_impl_shortcircuit_now(SshStream up_stream,
                                      SshStream down_stream)
{
  SshPacketImpl up;

  /* Verify that it is a SshPacketImpl stream. */
  if (ssh_stream_get_methods(up_stream) != &ssh_packet_impl_methods)
    ssh_fatal("ssh_packet_impl_can_receive: not a SshPacketImpl stream");
  /* Get the internal context. */
  up = (SshPacketImpl)ssh_stream_get_context(up_stream);

  /* Save shortcircuit stream. */
  up->shortcircuit_stream = down_stream;

  /* We currently require there to be no partial incoming packet. */
  SSH_ASSERT(ssh_buffer_len(&up->incoming) == 0);

  /* If it is non-NULL, make it use application callbacks directly. */
  if (down_stream)
    ssh_stream_set_callback(down_stream, up->up_callback, up->up_context);
}
Exemplo n.º 7
0
/* Return application level compatibility flags. Note that this must
   not be called if tr has become invalid for some reason. The return
   struct should be freed by the caller, when it is no longer
   needed. */
void ssh_transport_get_compatibility_flags(SshStream stream,
                                           SshTransportCompat *compat_flags)
{
  SshTransportCommon tr;
  SshTransportCompat rec;
  
  /* Verify that this is a transport stream. */
  if (ssh_stream_get_methods(stream) != &ssh_tr_methods)
    {
      memset(compat_flags, 0, sizeof(*compat_flags));
      return;
    }

  /* Get the real object. */
  tr = (SshTransportCommon)ssh_stream_get_context(stream);

  rec = ssh_xcalloc(1, sizeof(*rec));
  rec->publickey_draft_incompatility =
    &(tr->ssh_old_publickey_bug_compat);

  *compat_flags = rec;
}
Exemplo n.º 8
0
Boolean ssh_packet_impl_can_send(SshStream up_stream)
{
  SshPacketImpl up;
  Boolean status;

  /* Verify that it is a SshPacketImpl stream. */
  if (ssh_stream_get_methods(up_stream) != &ssh_packet_impl_methods)
    ssh_fatal("ssh_packet_impl_can_receive: not a SshPacketImpl stream");
  /* Get the internal context. */
  up = (SshPacketImpl)ssh_stream_get_context(up_stream);

  /* Determine whether more data can be stored in the buffer. */
  status = ssh_buffer_len(&up->outgoing) <
    BUFFER_MAX_SIZE - ALLOW_AFTER_BUFFER_FULL;

  /* If no more can be stored, mark that sending is blocked.  This will
     trigger a callback when data can again be sent. */
  if (!status)
    up->send_blocked = TRUE;

  return status;
}
Exemplo n.º 9
0
void ssh_transport_get_statistics(SshStream stream,
                                  SshTransportStatistics *stats)
{
  SshTransportCommon tr;

  /* Verify that this is a transport stream. */
  if (ssh_stream_get_methods(stream) != &ssh_tr_methods)
    {
      memset(stats, 0, sizeof(*stats));
      return;
    }

  /* Get the real object. */
  tr = (SshTransportCommon)ssh_stream_get_context(stream);
  
  /* Return statistics data. */
  stats->compressed_incoming_bytes = tr->compressed_incoming_bytes;
  stats->uncompressed_incoming_bytes = tr->uncompressed_incoming_bytes;
  stats->compressed_outgoing_bytes = tr->compressed_outgoing_bytes;
  stats->uncompressed_outgoing_bytes = tr->uncompressed_outgoing_bytes;
  stats->incoming_packets = tr->incoming_sequence_number;
  stats->outgoing_packets = tr->outgoing_sequence_number;
}
Exemplo n.º 10
0
void ssh_stream_fd_mark_forked(SshStream stream)
{
  if (ssh_stream_get_methods(stream) != &ssh_stream_fd_methods)
    return;
  ((SshFdStream)ssh_stream_get_context(stream))->keep_nonblocking = TRUE;
}
Exemplo n.º 11
0
int ssh_stream_fd_get_writefd(SshStream stream)
{
  if (ssh_stream_get_methods(stream) != &ssh_stream_fd_methods)
    return -1;
  return ((SshFdStream)ssh_stream_get_context(stream))->writefd;
}
Exemplo n.º 12
0
SshIOHandle ssh_stream_fd_get_readfd(SshStream stream)
{
  if (ssh_stream_get_methods(stream) != &ssh_stream_fd_methods)
    return -1;
  return ((SshFdStream)ssh_stream_get_context(stream))->readfd;
}