diff --git a/common/winbox_session.cpp b/common/winbox_session.cpp index ef0aa3f..4ec3eda 100644 --- a/common/winbox_session.cpp +++ b/common/winbox_session.cpp @@ -56,6 +56,12 @@ Winbox_Session::~Winbox_Session() bool Winbox_Session::login(const std::string& p_username, const std::string& p_password, boost::uint32_t& p_session_id) { + return login_old(p_username, p_password, p_session_id) || login_new(p_username, p_password, p_session_id); +} + +bool Winbox_Session::login_old(const std::string& p_username, const std::string& p_password, boost::uint32_t& p_session_id) +{ + std::cout << "Try old login method pre-v6.43 ..." << std::endl; WinboxMessage msg; // request the challenge @@ -133,6 +139,41 @@ bool Winbox_Session::login(const std::string& p_username, const std::string& p_p return true; } +bool Winbox_Session::login_new(const std::string& p_username, const std::string& p_password, boost::uint32_t& p_session_id) +{ + std::cout << "Try new login method post-v6.43 ..." << std::endl; + WinboxMessage msg; + + msg.set_to(13, 4); + msg.set_command(1); + msg.set_request_id(4); + msg.set_session_id(p_session_id); + msg.set_reply_expected(true); + msg.add_string(1, p_username); + msg.add_string(3, p_password); + if (!send(msg)) + { + return false; + } + + msg.reset(); + if (!receive(msg)) + { + std::cerr << "Error receiving a response." << std::endl; + return false; + } + + if (msg.has_error()) + { + std::cerr << msg.get_error_string() << std::endl; + return false; + } + + p_session_id = msg.get_session_id(); + + return true; +} + bool Winbox_Session::send(const WinboxMessage& p_msg) { std::string serialized(p_msg.serialize_to_binary()); diff --git a/common/winbox_session.hpp b/common/winbox_session.hpp index e4a0bba..04c845a 100644 --- a/common/winbox_session.hpp +++ b/common/winbox_session.hpp @@ -65,6 +65,18 @@ class Winbox_Session : public Session * Using the mproxy old(?) protocol, request a file to read */ bool old_mproxy_get_file(const std::string& p_file, std::string& p_result); + +private: + /** + * Login method pre-v6.43 + */ + bool login_old(const std::string& p_username, const std::string& p_password, boost::uint32_t& p_session_id); + + /** + * Login method post-v6.43 + */ + bool login_new(const std::string& p_username, const std::string& p_password, boost::uint32_t& p_session_id); + }; #endif