diff --git a/example/nested_proxy/nested_proxy.cpp b/example/nested_proxy/nested_proxy.cpp index 903e21d3c2..39a02842e5 100644 --- a/example/nested_proxy/nested_proxy.cpp +++ b/example/nested_proxy/nested_proxy.cpp @@ -36,8 +36,8 @@ net::awaitable start_proxy_server(net::io_context& ioc, server_ptr& server 10800); proxy_server_option opt; - opt.usrdid_ = "jack"; - opt.passwd_ = "1111"; + + opt.auth_users_.emplace_back("jack", "1111"); auto executor = ioc.get_executor(); server = proxy_server::make( diff --git a/proxy/include/proxy/proxy_server.hpp b/proxy/include/proxy/proxy_server.hpp index 260f9a22c9..46d564c928 100644 --- a/proxy/include/proxy/proxy_server.hpp +++ b/proxy/include/proxy/proxy_server.hpp @@ -110,11 +110,6 @@ namespace proxy { // proxy server 参数选项. struct proxy_server_option { - // 指定当前proxy server认证用户id名称. - std::string usrdid_; - // 指定当前proxy server认证密码. - std::string passwd_; - // 授权信息. using auth_users = std::tuple; std::vector auth_users_; @@ -452,7 +447,7 @@ namespace proxy { } // 服务端是否需要认证. - auto auth_required = !m_option.usrdid_.empty(); + auto auth_required = !m_option.auth_users_.empty(); // 循环读取客户端支持的代理方式. p = net::buffer_cast(m_local_buffer.data()); @@ -1127,19 +1122,14 @@ namespace proxy { << (socks4a ? hostname : dst_endpoint.address().to_string()); // 用户认证逻辑. - bool verify_passed = m_option.usrdid_ == userid; + bool verify_passed = m_option.auth_users_.empty(); - if (!verify_passed || userid.empty()) + for (auto [user, pwd] : m_option.auth_users_) { - verify_passed = false; - - for (auto [user, pwd] : m_option.auth_users_) + if (user == userid) { - if (user == userid) - { - verify_passed = true; - break; - } + verify_passed = true; + break; } } @@ -1258,7 +1248,7 @@ namespace proxy { inline bool http_proxy_authorization(std::string_view pa) { - if (m_option.usrdid_.empty() && m_option.auth_users_.empty()) + if (m_option.auth_users_.empty()) return true; if (pa.empty()) @@ -1307,21 +1297,14 @@ namespace proxy { std::string uname = userinfo.substr(0, pos); std::string passwd = userinfo.substr(pos + 1); - bool verify_passed = - m_option.usrdid_ == uname && - m_option.passwd_ == passwd; + bool verify_passed = m_option.auth_users_.empty(); - if (!verify_passed || uname.empty()) + for (auto [user, pwd] : m_option.auth_users_) { - verify_passed = false; - - for (auto [user, pwd] : m_option.auth_users_) + if (uname == user && passwd == pwd) { - if (uname == user && passwd == pwd) - { - verify_passed = true; - break; - } + verify_passed = true; + break; } } @@ -1641,21 +1624,14 @@ namespace proxy { client += ":" + std::to_string(endp.port()); // 用户认证逻辑. - bool verify_passed = - m_option.usrdid_ == uname && - m_option.passwd_ == passwd; + bool verify_passed = m_option.auth_users_.empty(); - if (!verify_passed || uname.empty()) + for (auto [user, pwd] : m_option.auth_users_) { - verify_passed = false; - - for (auto [user, pwd] : m_option.auth_users_) + if (uname == user && passwd == pwd) { - if (uname == user && passwd == pwd) - { - verify_passed = true; - break; - } + verify_passed = true; + break; } } diff --git a/server/proxy_server/main.cpp b/server/proxy_server/main.cpp index d1755d19aa..7e49b4c9c4 100644 --- a/server/proxy_server/main.cpp +++ b/server/proxy_server/main.cpp @@ -36,8 +36,6 @@ using server_ptr = std::shared_ptr; ////////////////////////////////////////////////////////////////////////// -std::string socks_userid; -std::string socks_passwd; std::vector auth_users; std::string proxy_pass; bool proxy_pass_ssl = false; @@ -83,9 +81,6 @@ start_proxy_server(net::io_context& ioc, server_ptr& server) proxy_server_option opt; - opt.usrdid_ = socks_userid; - opt.passwd_ = socks_passwd; - for (const auto& user : auth_users) { if (user.empty()) @@ -214,9 +209,6 @@ int main(int argc, char** argv) ("happyeyeballs", po::value(&happyeyeballs)->default_value(true), "Enable Happy Eyeballs algorithm for TCP connections.") ("local_ip", po::value(&local_ip), "Specify local IP for client TCP connection to server.") - ("socks_userid", po::value(&socks_userid)->default_value("jack")->value_name("userid"), "Authentication user ID (Deprecated).") - ("socks_passwd", po::value(&socks_passwd)->default_value("1111")->value_name("passwd"), "Authentication password (Deprecated).") - ("auth_users", po::value>(&auth_users)->multitoken()->value_name("user:passwd"), "List of authorized users (e.g: user:passwd).") ("proxy_pass", po::value(&proxy_pass)->default_value("")->value_name(""), "Specify next proxy pass (e.g: socks5://user:passwd@ip:port).")