- int type;
- char *data;
- unsigned int data_len;
- int row, col, xpixel, ypixel;
- int payload_len;
-
- /* Process buffered packets from the client. */
- while ((type = packet_read_poll(&payload_len)) != SSH_MSG_NONE)
- {
- switch (type)
- {
- case SSH_CMSG_STDIN_DATA:
- /* Stdin data from the client. Append it to the buffer. */
- if (fdin == -1)
- break; /* Ignore any data if the client has closed stdin. */
- data = packet_get_string(&data_len);
- packet_integrity_check(payload_len, (4 + data_len), type);
- buffer_append(&stdin_buffer, data, data_len);
- memset(data, 0, data_len);
- xfree(data);
- break;
-
- case SSH_CMSG_EOF:
- /* Eof from the client. The stdin descriptor to the program
- will be closed when all buffered data has drained. */
- debug("EOF received for stdin.");
- packet_integrity_check(payload_len, 0, type);
- stdin_eof = 1;
- break;
-
- case SSH_CMSG_WINDOW_SIZE:
- debug("Window change received.");
- packet_integrity_check(payload_len, 4*4, type);
- row = packet_get_int();
- col = packet_get_int();
- xpixel = packet_get_int();
- ypixel = packet_get_int();
- if (fdin != -1)
- pty_change_window_size(fdin, row, col, xpixel, ypixel);
- break;
-
- case SSH_MSG_PORT_OPEN:
- debug("Received port open request.");
- channel_input_port_open(payload_len);
- break;
-
- case SSH_MSG_CHANNEL_OPEN_CONFIRMATION:
- debug("Received channel open confirmation.");
- packet_integrity_check(payload_len, 4 + 4, type);
- channel_input_open_confirmation();
- break;
-
- case SSH_MSG_CHANNEL_OPEN_FAILURE:
- debug("Received channel open failure.");
- packet_integrity_check(payload_len, 4, type);
- channel_input_open_failure();
- break;
-
- case SSH_MSG_CHANNEL_DATA:
- channel_input_data(payload_len);
- break;
-
- case SSH_MSG_CHANNEL_CLOSE:
- debug("Received channel close.");
- packet_integrity_check(payload_len, 4, type);
- channel_input_close();
- break;
-
- case SSH_MSG_CHANNEL_CLOSE_CONFIRMATION:
- debug("Received channel close confirmation.");
- packet_integrity_check(payload_len, 4, type);
- channel_input_close_confirmation();
- break;
-
- default:
- /* In this phase, any unexpected messages cause a protocol
- error. This is to ease debugging; also, since no
- confirmations are sent messages, unprocessed unknown
- messages could cause strange problems. Any compatible
- protocol extensions must be negotiated before entering the
- interactive session. */
- packet_disconnect("Protocol error during session: type %d",
- type);
+ int type;
+ char *data;
+ unsigned int data_len;
+ int row, col, xpixel, ypixel;
+ int payload_len;
+
+ /* Process buffered packets from the client. */
+ while ((type = packet_read_poll(&payload_len)) != SSH_MSG_NONE) {
+ switch (type) {
+ case SSH_CMSG_STDIN_DATA:
+ /* Stdin data from the client. Append it to the buffer. */
+ /* Ignore any data if the client has closed stdin. */
+ if (fdin == -1)
+ break;
+ data = packet_get_string(&data_len);
+ packet_integrity_check(payload_len, (4 + data_len), type);
+ buffer_append(&stdin_buffer, data, data_len);
+ memset(data, 0, data_len);
+ xfree(data);
+ break;
+
+ case SSH_CMSG_EOF:
+ /*
+ * Eof from the client. The stdin descriptor to the
+ * program will be closed when all buffered data has
+ * drained.
+ */
+ debug("EOF received for stdin.");
+ packet_integrity_check(payload_len, 0, type);
+ stdin_eof = 1;
+ break;
+
+ case SSH_CMSG_WINDOW_SIZE:
+ debug("Window change received.");
+ packet_integrity_check(payload_len, 4 * 4, type);
+ row = packet_get_int();
+ col = packet_get_int();
+ xpixel = packet_get_int();
+ ypixel = packet_get_int();
+ if (fdin != -1)
+ pty_change_window_size(fdin, row, col, xpixel, ypixel);
+ break;
+
+ case SSH_MSG_PORT_OPEN:
+ debug("Received port open request.");
+ channel_input_port_open(payload_len);
+ break;
+
+ case SSH_MSG_CHANNEL_OPEN_CONFIRMATION:
+ debug("Received channel open confirmation.");
+ packet_integrity_check(payload_len, 4 + 4, type);
+ channel_input_open_confirmation();
+ break;
+
+ case SSH_MSG_CHANNEL_OPEN_FAILURE:
+ debug("Received channel open failure.");
+ packet_integrity_check(payload_len, 4, type);
+ channel_input_open_failure();
+ break;
+
+ case SSH_MSG_CHANNEL_DATA:
+ channel_input_data(payload_len);
+ break;
+
+ case SSH_MSG_CHANNEL_CLOSE:
+ debug("Received channel close.");
+ packet_integrity_check(payload_len, 4, type);
+ channel_input_close();
+ break;
+
+ case SSH_MSG_CHANNEL_CLOSE_CONFIRMATION:
+ debug("Received channel close confirmation.");
+ packet_integrity_check(payload_len, 4, type);
+ channel_input_close_confirmation();
+ break;
+
+ default:
+ /*
+ * In this phase, any unexpected messages cause a
+ * protocol error. This is to ease debugging; also,
+ * since no confirmations are sent messages,
+ * unprocessed unknown messages could cause strange
+ * problems. Any compatible protocol extensions must
+ * be negotiated before entering the interactive
+ * session.
+ */
+ packet_disconnect("Protocol error during session: type %d",
+ type);
+ }