Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
/ routeros Public archive

add support for new login method #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions common/winbox_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
12 changes: 12 additions & 0 deletions common/winbox_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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