mirror of https://github.com/tp4a/teleport
.tmp.
parent
0acda93c53
commit
a14f59ba6c
|
@ -1,4 +1,4 @@
|
|||
#include "ssh_proxy.h"
|
||||
#include "ssh_proxy.h"
|
||||
#include "tpp_env.h"
|
||||
|
||||
SshProxy g_ssh_proxy;
|
||||
|
@ -7,15 +7,15 @@ SshProxy::SshProxy() :
|
|||
ExThreadBase("ssh-proxy-thread"),
|
||||
m_bind(NULL) {
|
||||
m_timer_counter = 0;
|
||||
|
||||
m_noop_timeout_sec = 900; // default to 15 minutes.
|
||||
m_listener_running = false;
|
||||
}
|
||||
|
||||
SshProxy::~SshProxy() {
|
||||
if (NULL != m_bind)
|
||||
ssh_bind_free(m_bind);
|
||||
|
||||
ssh_finalize();
|
||||
//ssh_finalize();
|
||||
}
|
||||
|
||||
bool SshProxy::init() {
|
||||
|
@ -53,6 +53,8 @@ bool SshProxy::init() {
|
|||
return false;
|
||||
}
|
||||
|
||||
m_listener_running = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -168,6 +170,7 @@ void SshProxy::_thread_loop() {
|
|||
}
|
||||
}
|
||||
|
||||
m_listener_running = false;
|
||||
EXLOGV("[ssh] main-loop end.\n");
|
||||
}
|
||||
|
||||
|
@ -187,10 +190,15 @@ void SshProxy::_on_stop() {
|
|||
int _timeout_us = 10;
|
||||
ssh_options_set(_session, SSH_OPTIONS_TIMEOUT, &_timeout_us);
|
||||
ssh_connect(_session);
|
||||
ex_sleep_ms(500);
|
||||
|
||||
ssh_disconnect(_session);
|
||||
ssh_free(_session);
|
||||
ex_sleep_ms(500);
|
||||
}
|
||||
|
||||
ex_sleep_ms(100);
|
||||
while (m_listener_running) {
|
||||
ex_sleep_ms(1000);
|
||||
}
|
||||
|
||||
// m_thread_mgr.stop_all();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __SSH_PROXY_H__
|
||||
#ifndef __SSH_PROXY_H__
|
||||
#define __SSH_PROXY_H__
|
||||
|
||||
#include "ssh_session.h"
|
||||
|
@ -29,6 +29,7 @@ private:
|
|||
int m_timer_counter;
|
||||
|
||||
ExThreadLock m_lock;
|
||||
bool m_listener_running;
|
||||
|
||||
ex_astr m_host_ip;
|
||||
int m_host_port;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "ssh_session.h"
|
||||
#include "ssh_session.h"
|
||||
#include "ssh_proxy.h"
|
||||
#include "tpp_env.h"
|
||||
|
||||
|
@ -60,7 +60,7 @@ SshSession::SshSession(SshProxy *proxy, ssh_session sess_client) :
|
|||
|
||||
SshSession::~SshSession() {
|
||||
|
||||
//_on_stop();
|
||||
_on_stop();
|
||||
|
||||
if (NULL != m_conn_info) {
|
||||
g_ssh_env.free_connect_info(m_conn_info);
|
||||
|
@ -528,6 +528,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
|
||||
if (_this->m_auth_type == TP_AUTH_TYPE_PASSWORD) {
|
||||
if (!(((auth_methods & SSH_AUTH_METHOD_INTERACTIVE) == SSH_AUTH_METHOD_INTERACTIVE) || ((auth_methods & SSH_AUTH_METHOD_PASSWORD) == SSH_AUTH_METHOD_PASSWORD))) {
|
||||
_this->m_have_error = true;
|
||||
_this->_session_error(TP_SESS_STAT_ERR_AUTH_TYPE);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
@ -565,6 +566,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
rc = ssh_userauth_kbdint_setanswer(_this->m_srv_session, iprompt, _this->m_acc_secret.c_str());
|
||||
if (rc < 0) {
|
||||
EXLOGE("[ssh] invalid password for interactive mode to login to real SSH server %s:%d.\n", _this->m_conn_ip.c_str(), _this->m_conn_port);
|
||||
//ssh_send_debug(_this->m_cli_session, "TTTTTESTTTTTTTTTTT", 1);
|
||||
_this->m_have_error = true;
|
||||
_this->_session_error(TP_SESS_STAT_ERR_AUTH_DENIED);
|
||||
return SSH_AUTH_ERROR;
|
||||
|
|
|
@ -32,6 +32,7 @@ TPP_API ex_rv tpp_start(void)
|
|||
TPP_API ex_rv tpp_stop(void)
|
||||
{
|
||||
g_ssh_proxy.stop();
|
||||
ssh_finalize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -40,19 +41,13 @@ TPP_API void tpp_timer(void) {
|
|||
g_ssh_proxy.timer();
|
||||
}
|
||||
|
||||
// TPP_API void tpp_set_cfg(TPP_SET_CFG_ARGS* cfg_args) {
|
||||
// //g_ssh_proxy.set_cfg(cfg_args);
|
||||
// }
|
||||
|
||||
static ex_rv _set_runtime_config(const char* param) {
|
||||
Json::Value jp;
|
||||
//Json::Reader jreader;
|
||||
Json::CharReaderBuilder jcrb;
|
||||
std::unique_ptr<Json::CharReader> const jreader(jcrb.newCharReader());
|
||||
const char *str_json_begin = param;
|
||||
ex_astr err;
|
||||
|
||||
//if (!jreader.parse(param, jp))
|
||||
if (!jreader->parse(str_json_begin, param + strlen(param), &jp, &err))
|
||||
return TPE_JSON_FORMAT;
|
||||
|
||||
|
@ -73,14 +68,11 @@ static ex_rv _set_runtime_config(const char* param) {
|
|||
|
||||
static ex_rv _kill_sessions(const char* param) {
|
||||
Json::Value jp;
|
||||
// Json::Reader jreader;
|
||||
// if (!jreader.parse(param, jp))
|
||||
Json::CharReaderBuilder jcrb;
|
||||
std::unique_ptr<Json::CharReader> const jreader(jcrb.newCharReader());
|
||||
const char *str_json_begin = param;
|
||||
ex_astr err;
|
||||
|
||||
//if (!jreader.parse(param, jp))
|
||||
if (!jreader->parse(str_json_begin, param + strlen(param), &jp, &err))
|
||||
return TPE_JSON_FORMAT;
|
||||
|
||||
|
|
Loading…
Reference in New Issue