Package com.trilead.ssh2.packets

Examples of com.trilead.ssh2.packets.TypesReader


      log.log(80, "Got SSH_MSG_CHANNEL_WINDOW_ADJUST (channel " + id + ", " + windowChange + ")");
  }

  public void msgChannelOpen(byte[] msg, int msglen) throws IOException
  {
    TypesReader tr = new TypesReader(msg, 0, msglen);

    tr.readByte(); // skip packet type
    String channelType = tr.readString();
    int remoteID = tr.readUINT32(); /* sender channel */
    int remoteWindow = tr.readUINT32(); /* initial window size */
    int remoteMaxPacketSize = tr.readUINT32(); /* maximum packet size */

    if ("x11".equals(channelType))
    {
      synchronized (x11_magic_cookies)
      {
        /* If we did not request X11 forwarding, then simply ignore this bogus request. */

        if (x11_magic_cookies.size() == 0)
        {
          PacketChannelOpenFailure pcof = new PacketChannelOpenFailure(remoteID,
              Packets.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "X11 forwarding not activated", "");

          tm.sendAsynchronousMessage(pcof.getPayload());

          if (log.isEnabled())
            log.log(20, "Unexpected X11 request, denying it!");

          return;
        }
      }

      String remoteOriginatorAddress = tr.readString();
      int remoteOriginatorPort = tr.readUINT32();

      Channel c = new Channel(this);

      synchronized (c)
      {
        c.remoteID = remoteID;
        c.remoteWindow = remoteWindow & 0xFFFFffffL; /* properly convert UINT32 to long */
        c.remoteMaxPacketSize = remoteMaxPacketSize;
        c.localID = addChannel(c);
      }

      /*
       * The open confirmation message will be sent from another thread
       */

      RemoteX11AcceptThread rxat = new RemoteX11AcceptThread(c, remoteOriginatorAddress, remoteOriginatorPort);
      rxat.setDaemon(true);
      rxat.start();

      return;
    }

    if ("forwarded-tcpip".equals(channelType))
    {
      String remoteConnectedAddress = tr.readString(); /* address that was connected */
      int remoteConnectedPort = tr.readUINT32(); /* port that was connected */
      String remoteOriginatorAddress = tr.readString(); /* originator IP address */
      int remoteOriginatorPort = tr.readUINT32(); /* originator port */

      RemoteForwardingData rfd = null;

      synchronized (remoteForwardings)
      {
View Full Code Here


      log.log(20, "The peer tried to open an unsupported channel type (" + channelType + ")");
  }

  public void msgChannelRequest(byte[] msg, int msglen) throws IOException
  {
    TypesReader tr = new TypesReader(msg, 0, msglen);

    tr.readByte(); // skip packet type
    int id = tr.readUINT32();

    Channel c = getChannel(id);

    if (c == null)
      throw new IOException("Unexpected SSH_MSG_CHANNEL_REQUEST message for non-existent channel " + id);

    String type = tr.readString("US-ASCII");
    boolean wantReply = tr.readBoolean();

    if (log.isEnabled())
      log.log(80, "Got SSH_MSG_CHANNEL_REQUEST (channel " + id + ", '" + type + "')");

    if (type.equals("exit-status"))
    {
      if (wantReply != false)
        throw new IOException("Badly formatted SSH_MSG_CHANNEL_REQUEST message, 'want reply' is true");

      int exit_status = tr.readUINT32();

      if (tr.remain() != 0)
        throw new IOException("Badly formatted SSH_MSG_CHANNEL_REQUEST message");

      synchronized (c)
      {
        c.exit_status = new Integer(exit_status);
        c.notifyAll();
      }

      if (log.isEnabled())
        log.log(50, "Got EXIT STATUS (channel " + id + ", status " + exit_status + ")");

      return;
    }

    if (type.equals("exit-signal"))
    {
      if (wantReply != false)
        throw new IOException("Badly formatted SSH_MSG_CHANNEL_REQUEST message, 'want reply' is true");

      String signame = tr.readString("US-ASCII");
      tr.readBoolean();
      tr.readString();
      tr.readString();

      if (tr.remain() != 0)
        throw new IOException("Badly formatted SSH_MSG_CHANNEL_REQUEST message");

      synchronized (c)
      {
        c.exit_signal = signame;
View Full Code Here

  public void msgChannelOpenFailure(byte[] msg, int msglen) throws IOException
  {
    if (msglen < 5)
      throw new IOException("SSH_MSG_CHANNEL_OPEN_FAILURE message has wrong size (" + msglen + ")");

    TypesReader tr = new TypesReader(msg, 0, msglen);

    tr.readByte(); // skip packet type
    int id = tr.readUINT32(); /* sender channel */

    Channel c = getChannel(id);

    if (c == null)
      throw new IOException("Unexpected SSH_MSG_CHANNEL_OPEN_FAILURE message for non-existent channel " + id);

    int reasonCode = tr.readUINT32();
    String description = tr.readString("UTF-8");

    String reasonCodeSymbolicName = null;

    switch (reasonCode)
    {
View Full Code Here

  public void msgGlobalRequest(byte[] msg, int msglen) throws IOException
  {
    /* Currently we do not support any kind of global request */

    TypesReader tr = new TypesReader(msg, 0, msglen);

    tr.readByte(); // skip packet type
    String requestName = tr.readString();
    boolean wantReply = tr.readBoolean();

    if (wantReply)
    {
      byte[] reply_failure = new byte[1];
      reply_failure[0] = Packets.SSH_MSG_REQUEST_FAILURE;
View Full Code Here

    log.debug("Sending SSH_FXP_FSTAT...");
    sendMessage(Packet.SSH_FXP_FSTAT, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new RequestMismatchException();
    }

    if (t == Packet.SSH_FXP_ATTRS)
    {
      return readAttrs(tr);
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

    log.debug("Sending SSH_FXP_STAT/SSH_FXP_LSTAT...");
    sendMessage(statMethod, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new RequestMismatchException();
    }

    if (t == Packet.SSH_FXP_ATTRS)
    {
      return readAttrs(tr);
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

    log.debug("Sending SSH_FXP_READLINK...");
    sendMessage(Packet.SSH_FXP_READLINK, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new RequestMismatchException();
    }

    if (t == Packet.SSH_FXP_NAME)
    {
      int count = tr.readUINT32();

      if (count != 1)
      {
        throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");
      }

      return tr.readString(charsetName);
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

  private void expectStatusOKMessage(int id) throws IOException
  {
    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != id)
    {
      throw new RequestMismatchException();
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();

    if (errorCode == ErrorCodes.SSH_FX_OK)
    {
      return;
    }
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

    log.debug("Sending SSH_FXP_REALPATH...");
    sendMessage(Packet.SSH_FXP_REALPATH, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new RequestMismatchException();
    }

    if (t == Packet.SSH_FXP_NAME)
    {
      int count = tr.readUINT32();

      if (count != 1)
      {
        throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");
      }

      final String name = tr.readString(charsetName);
      listener.read(name);
      return name;
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new PacketTypeException(t);
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

      log.debug("Sending SSH_FXP_READDIR...");
      sendMessage(Packet.SSH_FXP_READDIR, req_id, tw.getBytes());

      byte[] resp = receiveMessage(34000);

      TypesReader tr = new TypesReader(resp);

      int t = tr.readByte();
      listener.read(Packet.forName(t));

      int rep_id = tr.readUINT32();
      if (rep_id != req_id)
      {
        throw new RequestMismatchException();
      }

      if (t == Packet.SSH_FXP_NAME)
      {
        int count = tr.readUINT32();

        log.debug("Parsing " + count + " name entries...");
        while (count > 0)
        {
          SFTPv3DirectoryEntry dirEnt = new SFTPv3DirectoryEntry();

          dirEnt.filename = tr.readString(charsetName);
          dirEnt.longEntry = tr.readString(charsetName);
          listener.read(dirEnt.longEntry);

          dirEnt.attributes = readAttrs(tr);
          files.add(dirEnt);

          log.debug("File: '" + dirEnt.filename + "'");
          count--;
        }
        continue;
      }

      if (t != Packet.SSH_FXP_STATUS)
      {
        throw new PacketTypeException(t);
      }

      int errorCode = tr.readUINT32();

      if (errorCode == ErrorCodes.SSH_FX_EOF)
      {
        return files;
      }
      String errorMessage = tr.readString();
      listener.read(errorMessage);
      throw new SFTPException(errorMessage, errorCode);
    }
  }
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.packets.TypesReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.