mirror of https://github.com/tp4a/teleport
rdp works with freerdp on Windows.
parent
4ee850c83e
commit
fe34aafa49
|
@ -44,9 +44,9 @@ End Sub
|
|||
手工测试了,ubuntu服务器可以,不知道是否能够支持所有的Linux。SecureCRT对此表示忽略。
|
||||
*/
|
||||
|
||||
#define RDP_CLIENT_SYSTEM_BUILTIN
|
||||
//#define RDP_CLIENT_SYSTEM_BUILTIN
|
||||
// #define RDP_CLIENT_SYSTEM_ACTIVE_CONTROL
|
||||
// #define RDP_CLIENT_FREERDP
|
||||
#define RDP_CLIENT_FREERDP
|
||||
|
||||
|
||||
#ifdef RDP_CLIENT_SYSTEM_BUILTIN
|
||||
|
@ -68,31 +68,29 @@ audiocapturemode:i:0\n\
|
|||
negotiate security layer:i:1\n\
|
||||
videoplaybackmode:i:1\n\
|
||||
connection type:i:2\n\
|
||||
prompt for credentials on client:i:1\n\
|
||||
prompt for credentials on client:i:0\n\
|
||||
displayconnectionbar:i:1\n\
|
||||
disable wallpaper:i:1\n\
|
||||
allow font smoothing:i:0\n\
|
||||
allow desktop composition:i:0\n\
|
||||
disable full window drag:i:1\n\
|
||||
disable menu anims:i:1\n\
|
||||
disable themes:i:0\n\
|
||||
disable themes:i:1\n\
|
||||
disable cursor setting:i:0\n\
|
||||
bitmapcachepersistenable:i:1\n\
|
||||
audiomode:i:0\n\
|
||||
redirectprinters:i:1\n\
|
||||
redirectprinters:i:0\n\
|
||||
redirectcomports:i:0\n\
|
||||
redirectsmartcards:i:1\n\
|
||||
redirectsmartcards:i:0\n\
|
||||
redirectclipboard:i:1\n\
|
||||
redirectposdevices:i:0\n\
|
||||
redirectdirectx:i:1\n\
|
||||
autoreconnection enabled:i:1\n\
|
||||
autoreconnection enabled:i:1\n\
|
||||
redirectdirectx:i:0\n\
|
||||
autoreconnection enabled:i:0\n\
|
||||
drivestoredirect:s:*\n\
|
||||
password 51:b:01000000D08C9DDF0115D1118C7A00C04FC297EB0100000052A9E191EA75A948B359790578C9371A0000000008000000700073007700000003660000A8000000100000000A1DCCD2E50775CA25EC3857164B34DC0000000004800000A000000010000000FCE1A645B9B61AA450946BB6F955058108020000D83591CA47562D6DDAA689F050AE145039EBE22E00D1D3AEAA98373C7B63C3E8E7149072DF989EA43EFCE20513AD3D27B11BE7F17066A688E1DCE828AF85460AAC327B38E90776DB962888E4393D19637578984B19A187AAD95F6D2726ADE7DD315FF56C15FF5B3031014EDDCC3C24D1B81779AFDB006EE575F5BEFB8D2D2138D9D9D642BBB251CC5ED7226968764856EC660A646BACE748A13D6002A9A537AA70710615650B9387EED66DE28BD57B304BBDD7B581B943DA628EB0289E30A8BA784B76F7885BECCAB4FEF7820E97EE3C6E036EEAF6EAA669288DF2FCACC9BEC045C907EBBDE87AFB8CC6B07A600BD63AC891B61D95C2265DD9FD5E635D61BFBF5EDC28311375066611C610FB533D64515B643C82F57D9B183B05C156D91BC0974D38E546022B139E82452E6F1EDF76E52F732C3904E5E433F8F3D488DB0698427DBB0791A9F207F8CB6654CB8410BAF4A59C4F9E821E589ABC1E6E6E1D432181B690408F6884FE1007895A4D26D4A5A2C7458EE747DA35D44AC9FB08AB5477EA3E7CCDB3E37EE20FAFD0D0CF9584E420598B7003B347943AC28048F45E0FD21AD08148FFADCE0E7877219259A7BE722FFAE845A429BA2CF0A71F2D19EA7495530FABDB5106E8D404A38A7E6394C38457640EA7398C5D55F0C4D342CC6A39C77E10A2A5145AEA40B14F5C7C3760334D83C9BE748383FADE231248537353817D51F7B44F61B406ABC61400000071C354139F458B02D978015F785B97F7F6B307380\n\
|
||||
";
|
||||
|
||||
//password\n\
|
||||
//51:b:01000000";
|
||||
//password 51:b:01000000D08C9DDF0115D1118C7A00C04FC297EB0100000052A9E191EA75A948B359790578C9371A0000000008000000700073007700000003660000A8000000100000000A1DCCD2E50775CA25EC3857164B34DC0000000004800000A000000010000000FCE1A645B9B61AA450946BB6F955058108020000D83591CA47562D6DDAA689F050AE145039EBE22E00D1D3AEAA98373C7B63C3E8E7149072DF989EA43EFCE20513AD3D27B11BE7F17066A688E1DCE828AF85460AAC327B38E90776DB962888E4393D19637578984B19A187AAD95F6D2726ADE7DD315FF56C15FF5B3031014EDDCC3C24D1B81779AFDB006EE575F5BEFB8D2D2138D9D9D642BBB251CC5ED7226968764856EC660A646BACE748A13D6002A9A537AA70710615650B9387EED66DE28BD57B304BBDD7B581B943DA628EB0289E30A8BA784B76F7885BECCAB4FEF7820E97EE3C6E036EEAF6EAA669288DF2FCACC9BEC045C907EBBDE87AFB8CC6B07A600BD63AC891B61D95C2265DD9FD5E635D61BFBF5EDC28311375066611C610FB533D64515B643C82F57D9B183B05C156D91BC0974D38E546022B139E82452E6F1EDF76E52F732C3904E5E433F8F3D488DB0698427DBB0791A9F207F8CB6654CB8410BAF4A59C4F9E821E589ABC1E6E6E1D432181B690408F6884FE1007895A4D26D4A5A2C7458EE747DA35D44AC9FB08AB5477EA3E7CCDB3E37EE20FAFD0D0CF9584E420598B7003B347943AC28048F45E0FD21AD08148FFADCE0E7877219259A7BE722FFAE845A429BA2CF0A71F2D19EA7495530FABDB5106E8D404A38A7E6394C38457640EA7398C5D55F0C4D342CC6A39C77E10A2A5145AEA40B14F5C7C3760334D83C9BE748383FADE231248537353817D51F7B44F61B406ABC61400000071C354139F458B02D978015F785B97F7F6B307380\n\
|
||||
//password 51:b:01000000";
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ protected:
|
|||
void EXLOG_USE_LOGGER(ExLogger* logger);
|
||||
|
||||
void EXLOG_LEVEL(int min_level);
|
||||
void EXLOG_DEBUG(bool debug_mode);
|
||||
|
||||
// 设定日志文件名及路径,如未指定路径,则为可执行程序所在目录下的log目录。
|
||||
void EXLOG_FILE(const wchar_t* log_file, const wchar_t* log_path = NULL, ex_u32 max_filesize = EX_LOG_FILE_MAX_SIZE, ex_u8 max_filecount = EX_LOG_FILE_MAX_COUNT);
|
||||
|
|
|
@ -31,6 +31,12 @@ void EXLOG_LEVEL(int min_level)
|
|||
g_exlog->min_level = min_level;
|
||||
}
|
||||
|
||||
void EXLOG_DEBUG(bool debug_mode)
|
||||
{
|
||||
if (NULL != g_exlog)
|
||||
g_exlog->debug_mode = debug_mode;
|
||||
}
|
||||
|
||||
void EXLOG_CONSOLE(bool output_to_console)
|
||||
{
|
||||
if(NULL != g_exlog)
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
# LOG_LEVEL_ERROR 4 log error message only.
|
||||
log-level=2
|
||||
|
||||
debug=0
|
||||
|
||||
; 'replay-path' define the replay file location. if not set, default location
|
||||
; to $INSTDIR%/data/replay/
|
||||
;replay-path=/var/lib/teleport/data/replay
|
||||
|
@ -32,14 +34,14 @@ bind-ip=0.0.0.0
|
|||
bind-port=52189
|
||||
|
||||
[protocol-rdp]
|
||||
enabled=false
|
||||
lib=rdp
|
||||
enabled=true
|
||||
lib=tprdp
|
||||
bind-ip=0.0.0.0
|
||||
bind-port=52089
|
||||
|
||||
[protocol-telnet]
|
||||
enabled=false
|
||||
lib=telnet
|
||||
lib=tptelnet
|
||||
bind-ip=0.0.0.0
|
||||
bind-port=52389
|
||||
|
||||
|
|
|
@ -21,10 +21,11 @@ bool TppEnvBase::init(TPP_INIT_ARGS* args)
|
|||
replay_path = args->replay_path;
|
||||
|
||||
take_session = args->func_take_session;
|
||||
free_session = args->func_free_session;
|
||||
session_begin = args->func_session_begin;
|
||||
session_end = args->func_session_end;
|
||||
|
||||
if (NULL == take_session || NULL == session_begin || NULL == session_end)
|
||||
if (NULL == take_session || NULL == free_session || NULL == session_begin || NULL == session_end)
|
||||
{
|
||||
EXLOGE("invalid init args(2).\n");
|
||||
return false;
|
||||
|
@ -36,19 +37,6 @@ bool TppEnvBase::init(TPP_INIT_ARGS* args)
|
|||
return false;
|
||||
}
|
||||
|
||||
// ExIniSection* ps = args->cfg->GetSection(L"common");
|
||||
// if (NULL == ps)
|
||||
// {
|
||||
// EXLOGE("invalid config(1).\n");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (!ps->GetStr(L"replay-path", replay_path))
|
||||
// {
|
||||
// replay_path = exec_path;
|
||||
// ex_path_join(replay_path, true, L"..", L"data", L"replay", NULL);
|
||||
// }
|
||||
|
||||
if (!_on_init(args))
|
||||
{
|
||||
EXLOGE("invalid init args(4).\n");
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
ex_wstr replay_path;
|
||||
|
||||
TPP_TAKE_SESSION_FUNC take_session;
|
||||
TPP_FREE_SESSION_FUNC free_session;
|
||||
TPP_SESSION_BEGIN_FUNC session_begin;
|
||||
TPP_SESSION_END_FUNC session_end;
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ TppRecBase::~TppRecBase()
|
|||
{
|
||||
}
|
||||
|
||||
void TppRecBase::begin(const wchar_t* base_path, const wchar_t* base_fname, int record_id, const TS_SESSION_INFO& info)
|
||||
void TppRecBase::begin(const wchar_t* base_path, const wchar_t* base_fname, int record_id, const TPP_SESSION_INFO* info)
|
||||
{
|
||||
m_start_time = ex_get_tick_count();
|
||||
|
||||
|
|
|
@ -142,13 +142,13 @@ public:
|
|||
TppRecBase();
|
||||
virtual ~TppRecBase();
|
||||
|
||||
void begin(const wchar_t* base_path, const wchar_t* base_fname, int record_id, const TS_SESSION_INFO& info);
|
||||
void begin(const wchar_t* base_path, const wchar_t* base_fname, int record_id, const TPP_SESSION_INFO* info);
|
||||
void end(void);
|
||||
|
||||
virtual void record(ex_u8 type, const ex_u8* data, size_t size) = 0;
|
||||
|
||||
protected:
|
||||
virtual void _on_begin(const TS_SESSION_INFO& info) = 0;
|
||||
virtual void _on_begin(const TPP_SESSION_INFO* info) = 0;
|
||||
virtual void _on_end(void) = 0;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -14,28 +14,26 @@
|
|||
# define TPP_API
|
||||
#endif
|
||||
|
||||
typedef struct TS_SESSION_INFO
|
||||
typedef struct TPP_SESSION_INFO
|
||||
{
|
||||
ex_astr sid;
|
||||
ex_astr account_name; // 申请本次连接的用户名
|
||||
|
||||
int auth_id;
|
||||
ex_astr host_ip;
|
||||
char* sid;
|
||||
char* account_name; // 申请本次连接的用户名
|
||||
char* host_ip;
|
||||
char* user_name;
|
||||
char* user_auth;
|
||||
char* user_param;
|
||||
int host_port;
|
||||
int protocol;
|
||||
ex_astr user_name;
|
||||
ex_astr user_auth;
|
||||
ex_astr user_param;
|
||||
int auth_id;
|
||||
int auth_mode;
|
||||
int sys_type;
|
||||
|
||||
int ref_count; // 这个session可以被take_session()多少次
|
||||
ex_u64 ticket_start;
|
||||
}TS_SESSION_INFO;
|
||||
}TPP_SESSION_INFO;
|
||||
|
||||
|
||||
typedef bool(*TPP_TAKE_SESSION_FUNC)(const ex_astr& sid, TS_SESSION_INFO& info);
|
||||
typedef bool(*TPP_SESSION_BEGIN_FUNC)(TS_SESSION_INFO& info, int& db_id);
|
||||
typedef TPP_SESSION_INFO* (*TPP_TAKE_SESSION_FUNC)(const char* sid);
|
||||
typedef void(*TPP_FREE_SESSION_FUNC)(TPP_SESSION_INFO* info);
|
||||
typedef bool(*TPP_SESSION_BEGIN_FUNC)(const TPP_SESSION_INFO* info, int* db_id);
|
||||
typedef bool(*TPP_SESSION_END_FUNC)(int db_id, int ret);
|
||||
|
||||
|
||||
|
@ -48,6 +46,7 @@ typedef struct TPP_INIT_ARGS
|
|||
ExIniFile* cfg;
|
||||
|
||||
TPP_TAKE_SESSION_FUNC func_take_session;
|
||||
TPP_FREE_SESSION_FUNC func_free_session;
|
||||
TPP_SESSION_BEGIN_FUNC func_session_begin;
|
||||
TPP_SESSION_END_FUNC func_session_end;
|
||||
}TPP_INIT_ARGS;
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
|
||||
#define TS_RDP_PROTOCOL_RDP 0
|
||||
#define TS_RDP_PROTOCOL_SSL 1
|
||||
#define TS_RDP_PROTOCOL_TLS 1
|
||||
#define TS_RDP_PROTOCOL_HYBRID 2
|
||||
#define TS_RDP_PROTOCOL_RDSTLS 4
|
||||
#define TS_RDP_PROTOCOL_HYBRID_EX 8
|
||||
|
||||
#define TS_AUTH_MODE_NONE 0
|
||||
|
|
|
@ -109,6 +109,11 @@ bool TsEnv::init(bool load_config)
|
|||
EXLOG_LEVEL(log_level);
|
||||
}
|
||||
|
||||
int debug_mode = 0;
|
||||
ps->GetInt(L"debug", debug_mode, 0);
|
||||
if (debug_mode == 1)
|
||||
EXLOG_DEBUG(true);
|
||||
|
||||
ex_wstr tmp;
|
||||
ps = m_ini.GetSection(L"rpc");
|
||||
if (!ps->GetStr(L"bind-ip", tmp))
|
||||
|
|
|
@ -9,14 +9,74 @@
|
|||
|
||||
bool g_exit_flag = false;
|
||||
|
||||
bool tpp_take_session(const ex_astr& sid, TS_SESSION_INFO& info)
|
||||
TPP_SESSION_INFO* tpp_take_session(const char* sid)
|
||||
{
|
||||
return g_session_mgr.take_session(sid, info);
|
||||
TS_SESSION_INFO sinfo;
|
||||
bool ret = g_session_mgr.take_session(sid, sinfo);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
TPP_SESSION_INFO* info = (TPP_SESSION_INFO*)calloc(1, sizeof(TPP_SESSION_INFO));
|
||||
|
||||
info->sid = (char*)calloc(1, sinfo.sid.length() + 1);
|
||||
ex_strcpy(info->sid, sinfo.sid.length() + 1, sinfo.sid.c_str());
|
||||
info->account_name = (char*)calloc(1, sinfo.account_name.length() + 1);
|
||||
ex_strcpy(info->account_name, sinfo.account_name.length() + 1, sinfo.account_name.c_str());
|
||||
info->host_ip = (char*)calloc(1, sinfo.host_ip.length() + 1);
|
||||
ex_strcpy(info->host_ip, sinfo.host_ip.length() + 1, sinfo.host_ip.c_str());
|
||||
info->user_name = (char*)calloc(1, sinfo.user_name.length() + 1);
|
||||
ex_strcpy(info->user_name, sinfo.user_name.length() + 1, sinfo.user_name.c_str());
|
||||
info->user_auth = (char*)calloc(1, sinfo.user_auth.length() + 1);
|
||||
ex_strcpy(info->user_auth, sinfo.user_auth.length() + 1, sinfo.user_auth.c_str());
|
||||
info->user_param = (char*)calloc(1, sinfo.user_param.length() + 1);
|
||||
ex_strcpy(info->user_param, sinfo.user_param.length() + 1, sinfo.user_param.c_str());
|
||||
|
||||
info->auth_id = sinfo.auth_id;
|
||||
info->host_port = sinfo.host_port;
|
||||
info->protocol = sinfo.protocol;
|
||||
info->auth_mode = sinfo.auth_mode;
|
||||
info->sys_type = sinfo.sys_type;
|
||||
info->ref_count = sinfo.ref_count;
|
||||
info->ticket_start = sinfo.ticket_start;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
bool tpp_session_begin(TS_SESSION_INFO& info, int& db_id)
|
||||
void tpp_free_session(TPP_SESSION_INFO* info)
|
||||
{
|
||||
return ts_web_rpc_session_begin(info, db_id);
|
||||
if (NULL == info)
|
||||
return;
|
||||
|
||||
free(info->sid);
|
||||
free(info->account_name);
|
||||
free(info->host_ip);
|
||||
free(info->user_name);
|
||||
free(info->user_auth);
|
||||
free(info->user_param);
|
||||
free(info);
|
||||
}
|
||||
|
||||
bool tpp_session_begin(const TPP_SESSION_INFO* info, int* db_id)
|
||||
{
|
||||
if (NULL == info || NULL == db_id)
|
||||
return false;
|
||||
|
||||
TS_SESSION_INFO sinfo;
|
||||
sinfo.sid = info->sid;
|
||||
sinfo.account_name = info->account_name;
|
||||
sinfo.auth_id = info->auth_id;
|
||||
sinfo.host_ip = info->host_ip;
|
||||
sinfo.host_port = info->host_port;
|
||||
sinfo.protocol = info->protocol;
|
||||
sinfo.user_name = info->user_name;
|
||||
sinfo.user_auth = info->user_auth;
|
||||
sinfo.user_param = info->user_param;
|
||||
sinfo.auth_mode = info->auth_mode;
|
||||
sinfo.sys_type = info->sys_type;
|
||||
sinfo.ref_count = info->ref_count;
|
||||
sinfo.ticket_start = info->ticket_start;
|
||||
|
||||
return ts_web_rpc_session_begin(sinfo, *db_id);
|
||||
}
|
||||
|
||||
bool tpp_session_end(int db_id, int ret)
|
||||
|
@ -122,6 +182,7 @@ bool TppManager::load_tpp(const ex_wstr& libname)
|
|||
init_args.replay_path = g_env.m_replay_path;
|
||||
init_args.cfg = &g_env.get_ini();
|
||||
init_args.func_take_session = tpp_take_session;
|
||||
init_args.func_free_session = tpp_free_session;
|
||||
init_args.func_session_begin = tpp_session_begin;
|
||||
init_args.func_session_end = tpp_session_end;
|
||||
|
||||
|
|
|
@ -113,16 +113,19 @@ bool TsSessionManager::take_session(const ex_astr& sid, TS_SESSION_INFO& info)
|
|||
return false;
|
||||
|
||||
info.sid = it->second->sid;
|
||||
info.account_name = it->second->account_name;
|
||||
info.auth_id = it->second->auth_id;
|
||||
info.host_ip = it->second->host_ip;
|
||||
info.host_port = it->second->host_port;
|
||||
info.protocol = it->second->protocol;
|
||||
info.account_name = it->second->account_name;
|
||||
info.sys_type = it->second->sys_type;
|
||||
info.user_name = it->second->user_name;
|
||||
info.user_param = it->second->user_param;
|
||||
|
||||
info.user_auth = it->second->user_auth;
|
||||
|
||||
info.user_param = it->second->user_param;
|
||||
info.auth_mode = it->second->auth_mode;
|
||||
info.sys_type = it->second->sys_type;
|
||||
info.ref_count = it->second->ref_count;
|
||||
info.ticket_start = it->second->ticket_start;
|
||||
|
||||
it->second->ref_count--;
|
||||
|
@ -145,7 +148,7 @@ bool TsSessionManager::_add_session(ex_astr& sid, TS_SESSION_INFO* info)
|
|||
for (;;)
|
||||
{
|
||||
_gen_session_id(_sid, info, 6);
|
||||
it = m_sessions.find(sid);
|
||||
it = m_sessions.find(_sid);
|
||||
if (it == m_sessions.end())
|
||||
break;
|
||||
|
||||
|
|
|
@ -6,6 +6,25 @@
|
|||
|
||||
#include <ex.h>
|
||||
|
||||
typedef struct TS_SESSION_INFO
|
||||
{
|
||||
ex_astr sid;
|
||||
ex_astr account_name; // 申请本次连接的用户名
|
||||
|
||||
int auth_id;
|
||||
ex_astr host_ip;
|
||||
int host_port;
|
||||
int protocol;
|
||||
ex_astr user_name;
|
||||
ex_astr user_auth;
|
||||
ex_astr user_param;
|
||||
int auth_mode;
|
||||
int sys_type;
|
||||
|
||||
int ref_count; // 这个session可以被take_session()多少次
|
||||
ex_u64 ticket_start;
|
||||
}TS_SESSION_INFO;
|
||||
|
||||
typedef std::map<ex_astr, TS_SESSION_INFO*> ts_sessiones;
|
||||
|
||||
class TsSessionManager : public ExThreadBase
|
||||
|
|
|
@ -15,12 +15,19 @@ TppRec::~TppRec()
|
|||
end();
|
||||
}
|
||||
|
||||
void TppRec::_on_begin(const TS_SESSION_INFO& info)
|
||||
void TppRec::_on_begin(const TPP_SESSION_INFO* info)
|
||||
{
|
||||
m_head.port = info.host_port;
|
||||
memcpy(m_head.account, info.account_name.c_str(), info.account_name.length() > 15 ? 15 : info.account_name.length());
|
||||
memcpy(m_head.username, info.user_name.c_str(), info.user_name.length() > 15 ? 15 : info.user_name.length());
|
||||
memcpy(m_head.ip, info.host_ip.c_str(), info.host_ip.length() > 17 ? 17 : info.host_ip.length());
|
||||
if (NULL == info)
|
||||
return;
|
||||
|
||||
m_head.port = info->host_port;
|
||||
// memcpy(m_head.account, info.account_name.c_str(), info.account_name.length() > 15 ? 15 : info.account_name.length());
|
||||
// memcpy(m_head.username, info.user_name.c_str(), info.user_name.length() > 15 ? 15 : info.user_name.length());
|
||||
// memcpy(m_head.ip, info.host_ip.c_str(), info.host_ip.length() > 17 ? 17 : info.host_ip.length());
|
||||
|
||||
memcpy(m_head.account, info->account_name, strlen(info->account_name) > 15 ? 15 : strlen(info->account_name));
|
||||
memcpy(m_head.username, info->user_name, strlen(info->user_name) > 15 ? 15 : strlen(info->user_name));
|
||||
memcpy(m_head.ip, info->host_ip, strlen(info->host_ip) > 17 ? 17 : strlen(info->host_ip));
|
||||
}
|
||||
|
||||
void TppRec::_on_end(void)
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
void record_command(const ex_astr cmd);
|
||||
|
||||
protected:
|
||||
void _on_begin(const TS_SESSION_INFO& info);
|
||||
void _on_begin(const TPP_SESSION_INFO* info);
|
||||
void _on_end(void);
|
||||
|
||||
bool _save_to_data_file(void);
|
||||
|
|
|
@ -71,9 +71,9 @@ void SshSession::_set_stop_flag(void) {
|
|||
}
|
||||
}
|
||||
|
||||
bool SshSession::_on_session_begin(TS_SESSION_INFO& info)
|
||||
bool SshSession::_on_session_begin(const TPP_SESSION_INFO* info)
|
||||
{
|
||||
if (!g_ssh_env.session_begin(info, m_db_id))
|
||||
if (!g_ssh_env.session_begin(info, &m_db_id))
|
||||
{
|
||||
EXLOGD("[ssh] session_begin error. %d\n", m_db_id);
|
||||
return false;
|
||||
|
@ -229,12 +229,11 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
_this->m_sid = user;
|
||||
EXLOGV("[ssh] authenticating, session-id: %s\n", _this->m_sid.c_str());
|
||||
|
||||
bool bRet = true;
|
||||
TS_SESSION_INFO sess_info;
|
||||
//bRet = _this->m_proxy->get_session_mgr()->take_session(_this->m_sid, sess_info);
|
||||
bRet = g_ssh_env.take_session(_this->m_sid, sess_info);
|
||||
//bool bRet = true;
|
||||
int protocol = 0;
|
||||
TPP_SESSION_INFO* sess_info = g_ssh_env.take_session(_this->m_sid.c_str());
|
||||
|
||||
if (!bRet) {
|
||||
if (NULL == sess_info) {
|
||||
EXLOGW("[ssh] try to get login-info from ssh-sftp-session.\n");
|
||||
// 尝试从sftp连接记录中获取连接信息(一个ssh会话如果成为sftp会话,内部会将连接信息记录下来备用)
|
||||
TS_SFTP_SESSION_INFO sftp_info;
|
||||
|
@ -251,25 +250,28 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
_this->m_user_name = sftp_info.user_name;
|
||||
_this->m_user_auth = sftp_info.user_auth;
|
||||
|
||||
sess_info.host_ip = sftp_info.host_ip;
|
||||
sess_info.host_port = sftp_info.host_port;
|
||||
sess_info.auth_mode = sftp_info.auth_mode;
|
||||
sess_info.user_name = sftp_info.user_name;
|
||||
sess_info.user_auth = sftp_info.user_auth;
|
||||
sess_info.protocol = TS_PROXY_PROTOCOL_SSH;
|
||||
// sess_info.host_ip = sftp_info.host_ip;
|
||||
// sess_info.host_port = sftp_info.host_port;
|
||||
// sess_info.auth_mode = sftp_info.auth_mode;
|
||||
// sess_info.user_name = sftp_info.user_name;
|
||||
// sess_info.user_auth = sftp_info.user_auth;
|
||||
// sess_info.protocol = TS_PROXY_PROTOCOL_SSH;
|
||||
protocol = TS_PROXY_PROTOCOL_SSH;
|
||||
|
||||
// 因为是从sftp会话得来的登录数据,因此限制本会话只能用于sftp,不允许再使用shell了。
|
||||
_this->_enter_sftp_mode();
|
||||
} else {
|
||||
_this->m_server_ip = sess_info.host_ip;
|
||||
_this->m_server_port = sess_info.host_port;
|
||||
_this->m_auth_mode = sess_info.auth_mode;
|
||||
_this->m_user_name = sess_info.user_name;
|
||||
_this->m_user_auth = sess_info.user_auth;
|
||||
_this->m_server_ip = sess_info->host_ip;
|
||||
_this->m_server_port = sess_info->host_port;
|
||||
_this->m_auth_mode = sess_info->auth_mode;
|
||||
_this->m_user_name = sess_info->user_name;
|
||||
_this->m_user_auth = sess_info->user_auth;
|
||||
protocol = sess_info->protocol;
|
||||
}
|
||||
|
||||
//EXLOGE("[ssh---------1] auth info [password:%s:%s:%d]\n", _this->m_user_name.c_str(),_this->m_user_auth.c_str(), _this->m_auth_mode);
|
||||
if (sess_info.protocol != TS_PROXY_PROTOCOL_SSH) {
|
||||
if (protocol != TS_PROXY_PROTOCOL_SSH) {
|
||||
g_ssh_env.free_session(sess_info);
|
||||
EXLOGE("[ssh] session '%s' is not for SSH.\n", _this->m_sid.c_str());
|
||||
_this->m_have_error = true;
|
||||
_this->m_retcode = SESS_STAT_ERR_AUTH_DENIED;
|
||||
|
@ -278,19 +280,23 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
|
||||
if (!_this->_on_session_begin(sess_info))
|
||||
{
|
||||
g_ssh_env.free_session(sess_info);
|
||||
_this->m_have_error = true;
|
||||
_this->m_retcode = SESS_STAT_ERR_AUTH_DENIED;
|
||||
return SSH_AUTH_DENIED;
|
||||
}
|
||||
|
||||
// 现在尝试根据session-id获取得到的信息,连接并登录真正的SSH服务器
|
||||
EXLOGV("[ssh] try to connect to real SSH server %s:%d\n", sess_info.host_ip.c_str(), sess_info.host_port);
|
||||
_this->m_srv_session = ssh_new();
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_HOST, sess_info.host_ip.c_str());
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_PORT, &sess_info.host_port);
|
||||
g_ssh_env.free_session(sess_info);
|
||||
sess_info = NULL;
|
||||
|
||||
if (sess_info.auth_mode != TS_AUTH_MODE_NONE)
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_USER, sess_info.user_name.c_str());
|
||||
// 现在尝试根据session-id获取得到的信息,连接并登录真正的SSH服务器
|
||||
EXLOGV("[ssh] try to connect to real SSH server %s:%d\n", _this->m_server_ip.c_str(), _this->m_server_port);
|
||||
_this->m_srv_session = ssh_new();
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_HOST, _this->m_server_ip.c_str());
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_PORT, &_this->m_server_port);
|
||||
|
||||
if (_this->m_auth_mode != TS_AUTH_MODE_NONE)
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_USER, _this->m_user_name.c_str());
|
||||
|
||||
int _timeout_us = 30000000; // 30 sec.
|
||||
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_TIMEOUT_USEC, &_timeout_us);
|
||||
|
@ -298,25 +304,24 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
int rc = 0;
|
||||
rc = ssh_connect(_this->m_srv_session);
|
||||
if (rc != SSH_OK) {
|
||||
EXLOGE("[ssh] can not connect to real SSH server %s:%d.\n", sess_info.host_ip.c_str(), sess_info.host_port);
|
||||
EXLOGE("[ssh] can not connect to real SSH server %s:%d.\n", _this->m_server_ip.c_str(), _this->m_server_port);
|
||||
_this->m_have_error = true;
|
||||
_this->m_retcode = SESS_STAT_ERR_CONNECT;
|
||||
return SSH_AUTH_DENIED;
|
||||
}
|
||||
|
||||
if (sess_info.auth_mode == TS_AUTH_MODE_PASSWORD) {
|
||||
rc = ssh_userauth_password(_this->m_srv_session, NULL, sess_info.user_auth.c_str());
|
||||
if (_this->m_auth_mode == TS_AUTH_MODE_PASSWORD) {
|
||||
rc = ssh_userauth_password(_this->m_srv_session, NULL, _this->m_user_auth.c_str());
|
||||
if (rc != SSH_OK) {
|
||||
EXLOGE("[ssh] can not use user/name login to real SSH server %s:%d.\n", sess_info.host_ip.c_str(),
|
||||
sess_info.host_port);
|
||||
EXLOGE("[ssh] can not use user/name login to real SSH server %s:%d.\n", _this->m_server_ip.c_str(), _this->m_server_port);
|
||||
_this->m_have_error = true;
|
||||
_this->m_retcode = SESS_STAT_ERR_AUTH_DENIED;
|
||||
return SSH_AUTH_DENIED;
|
||||
}
|
||||
}
|
||||
else if (sess_info.auth_mode == TS_AUTH_MODE_PRIVATE_KEY) {
|
||||
else if (_this->m_auth_mode == TS_AUTH_MODE_PRIVATE_KEY) {
|
||||
ssh_key key = NULL;
|
||||
if (SSH_OK != ssh_pki_import_privkey_base64(sess_info.user_auth.c_str(), NULL, NULL, NULL, &key)) {
|
||||
if (SSH_OK != ssh_pki_import_privkey_base64(_this->m_user_auth.c_str(), NULL, NULL, NULL, &key)) {
|
||||
EXLOGE("[ssh] can not import private-key for auth.\n");
|
||||
_this->m_have_error = true;
|
||||
_this->m_retcode = SESS_STAT_ERR_BAD_SSH_KEY;
|
||||
|
@ -326,8 +331,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
rc = ssh_userauth_publickey(_this->m_srv_session, NULL, key);
|
||||
if (rc != SSH_OK) {
|
||||
ssh_key_free(key);
|
||||
EXLOGE("[ssh] can not use private-key login to real SSH server %s:%d.\n", sess_info.host_ip.c_str(),
|
||||
sess_info.host_port);
|
||||
EXLOGE("[ssh] can not use private-key login to real SSH server %s:%d.\n", _this->m_server_ip.c_str(), _this->m_server_port);
|
||||
_this->m_have_error = true;
|
||||
_this->m_retcode = SESS_STAT_ERR_AUTH_DENIED;
|
||||
return SSH_AUTH_DENIED;
|
||||
|
@ -335,7 +339,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
|
|||
|
||||
ssh_key_free(key);
|
||||
}
|
||||
else if (sess_info.auth_mode == TS_AUTH_MODE_NONE)
|
||||
else if (_this->m_auth_mode == TS_AUTH_MODE_NONE)
|
||||
{
|
||||
// do nothing.
|
||||
return SSH_AUTH_DENIED;
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
protected:
|
||||
// ¼Ì³Ð×Ô TppSessionBase
|
||||
bool _on_session_begin(TS_SESSION_INFO& info);
|
||||
bool _on_session_begin(const TPP_SESSION_INFO* info);
|
||||
bool _on_session_end(void);
|
||||
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<GenerateDebugInformation>Debug</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\..\..\external\libssh-win-static\lib;..\..\..\..\external\openssl\out32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="py" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.4.4 (C:\python\python34-x86\python.exe)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
|
|
Loading…
Reference in New Issue