void clSSH::DoOpenChannel() throw(clException) { if(m_channel) return; m_channel = ssh_channel_new(m_session); if(!m_channel) { throw clException(ssh_get_error(m_session)); } int rc = ssh_channel_open_session(m_channel); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } rc = ssh_channel_request_pty(m_channel); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } rc = ssh_channel_change_pty_size(m_channel, 80, 24); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } rc = ssh_channel_request_shell(m_channel); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } }
static void sizechanged(void){ struct winsize win = { 0, 0, 0, 0 }; ioctl(1, TIOCGWINSZ, &win); ssh_channel_change_pty_size(chan,win.ws_col, win.ws_row); // printf("Changed pty size\n"); setsignal(); }
void SSH::openShell() { if (_bShellOpen) { return; } if (!_bChanOpen) { openChannel(); } _logger->debug("Opening SSH shell"); int rc; rc = ssh_channel_request_pty(_channel); if (rc != SSH_OK) { throw SSHException("Failed to request PTY from remote host", SSHErrorCode::E_PTY_REQUEST_FAILED); } rc = ssh_channel_change_pty_size(_channel, 80, 24); if (rc != SSH_OK) { throw SSHException("Failed to change PTY size", SSHErrorCode::E_PTY_SIZE_FAILED); } rc = ssh_channel_request_shell(_channel); if (rc != SSH_OK) { throw SSHException("Failed to request remote shell", SSHErrorCode::E_SHELL_REQUEST_FAILED); } _bShellOpen = true; }
static ssh_channel run_capture(ssh_session sshs, const char* iface, const char* cfilter, const guint32 count) { char* cmdline = NULL; ssh_channel channel; int ret = 0; channel = ssh_channel_new(sshs); if (!channel) return NULL; if (ssh_channel_open_session(channel) != SSH_OK) goto error; if (ssh_channel_request_pty(channel) != SSH_OK) goto error; if (ssh_channel_change_pty_size(channel, 80, 24) != SSH_OK) goto error; if (ssh_channel_request_shell(channel) != SSH_OK) goto error; if (!check_ios_version(channel)) goto error; if (ssh_channel_printf(channel, "terminal length 0\n") == EXIT_FAILURE) goto error; if (ssh_channel_printf(channel, "monitor capture buffer %s max-size 9500\n", WIRESHARK_CAPTURE_BUFFER) == EXIT_FAILURE) goto error; if (ssh_channel_printf(channel, "monitor capture buffer %s limit packet-count %u\n", WIRESHARK_CAPTURE_BUFFER, count) == EXIT_FAILURE) goto error; if (cfilter) { gchar* multiline_filter; gchar* chr; if (ssh_channel_printf(channel, "configure terminal\n") == EXIT_FAILURE) goto error; if (ssh_channel_printf(channel, "ip access-list ex %s\n", WIRESHARK_CAPTURE_ACCESSLIST) == EXIT_FAILURE) goto error; multiline_filter = g_strdup(cfilter); chr = multiline_filter; while((chr = g_strstr_len(chr, strlen(chr), ",")) != NULL) { chr[0] = '\n'; g_debug("Splitting filter into multiline"); } ret = ssh_channel_write(channel, multiline_filter, (uint32_t)strlen(multiline_filter)); g_free(multiline_filter); if (ret == SSH_ERROR) goto error; if (ssh_channel_printf(channel, "\nend\n") == EXIT_FAILURE) goto error; if (ssh_channel_printf(channel, "monitor capture buffer %s filter access-list %s\n", WIRESHARK_CAPTURE_BUFFER, WIRESHARK_CAPTURE_ACCESSLIST) == EXIT_FAILURE) goto error; } if (ssh_channel_printf(channel, "monitor capture point ip cef %s %s both\n", WIRESHARK_CAPTURE_POINT, iface) == EXIT_FAILURE) goto error; if (ssh_channel_printf(channel, "monitor capture point associate %s %s \n", WIRESHARK_CAPTURE_POINT, WIRESHARK_CAPTURE_BUFFER) == EXIT_FAILURE) goto error; if (ssh_channel_printf(channel, "monitor capture point start %s\n", WIRESHARK_CAPTURE_POINT) == EXIT_FAILURE) goto error; if (read_output_bytes(channel, -1, NULL) == EXIT_FAILURE) goto error; if (wait_until_data(channel, count) == EXIT_FAILURE) goto error; if (read_output_bytes(channel, -1, NULL) == EXIT_FAILURE) goto error; cmdline = g_strdup_printf("show monitor capture buffer %s dump\n", WIRESHARK_CAPTURE_BUFFER); if (ssh_channel_printf(channel, cmdline) == EXIT_FAILURE) goto error; if (read_output_bytes(channel, (int)strlen(cmdline), NULL) == EXIT_FAILURE) goto error; g_free(cmdline); return channel; error: g_free(cmdline); g_warning("Error running ssh remote command"); read_output_bytes(channel, -1, NULL); ssh_channel_close(channel); ssh_channel_free(channel); return NULL; }
int channel_change_pty_size(ssh_channel channel,int cols,int rows){ return ssh_channel_change_pty_size(channel,cols,rows); }