From 3ab1177d7efbfec235f1d9dc4a52e5473b929536 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Wed, 18 Aug 2021 16:50:15 +0300 Subject: [PATCH] Add separate constants for interface LOCAL and TCP_INTERSERVER. --- programs/local/LocalServer.cpp | 4 ++-- src/Dictionaries/ClickHouseDictionarySource.cpp | 4 ++-- src/Interpreters/ClientInfo.h | 2 ++ src/Interpreters/Session.cpp | 8 ++++++-- src/Server/TCPHandler.cpp | 1 + 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 957bda4d75c..bdcb95119f0 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -376,8 +376,8 @@ void LocalServer::processQueries() throw Exception("Cannot parse and execute the following part of query: " + String(parse_res.first), ErrorCodes::SYNTAX_ERROR); /// Authenticate and create a context to execute queries. - Session session{global_context, ClientInfo::Interface::TCP}; - session.authenticate("default", "", Poco::Net::SocketAddress{}); + Session session{global_context, ClientInfo::Interface::LOCAL}; + session.authenticate("default", "", {}); /// Use the same context for all queries. auto context = session.makeQueryContext(); diff --git a/src/Dictionaries/ClickHouseDictionarySource.cpp b/src/Dictionaries/ClickHouseDictionarySource.cpp index b09a7b14cc4..7348569442d 100644 --- a/src/Dictionaries/ClickHouseDictionarySource.cpp +++ b/src/Dictionaries/ClickHouseDictionarySource.cpp @@ -256,8 +256,8 @@ void registerDictionarySourceClickHouse(DictionarySourceFactory & factory) if (configuration.is_local) { /// Start local session in case when the dictionary is loaded in-process (without TCP communication). - local_session = std::make_shared(global_context, ClientInfo::Interface::TCP); - local_session->authenticate(configuration.user, configuration.password, Poco::Net::SocketAddress{"127.0.0.1", 0}); + local_session = std::make_shared(global_context, ClientInfo::Interface::LOCAL); + local_session->authenticate(configuration.user, configuration.password, {}); context = local_session->makeQueryContext(); context->applySettingsChanges(readSettingsFromDictionaryConfig(config, config_prefix)); } diff --git a/src/Interpreters/ClientInfo.h b/src/Interpreters/ClientInfo.h index 7c169e6ebb5..71570778645 100644 --- a/src/Interpreters/ClientInfo.h +++ b/src/Interpreters/ClientInfo.h @@ -28,6 +28,8 @@ public: GRPC = 3, MYSQL = 4, POSTGRESQL = 5, + LOCAL = 6, + TCP_INTERSERVER = 7, }; enum class HTTPMethod : uint8_t diff --git a/src/Interpreters/Session.cpp b/src/Interpreters/Session.cpp index 7334f2e7640..3a4de041294 100644 --- a/src/Interpreters/Session.cpp +++ b/src/Interpreters/Session.cpp @@ -261,10 +261,14 @@ void Session::authenticate(const Credentials & credentials_, const Poco::Net::So if (session_context) throw Exception("If there is a session context it must be created after authentication", ErrorCodes::LOGICAL_ERROR); - user_id = global_context->getAccessControlManager().login(credentials_, address_.host()); + auto address = address_; + if ((address == Poco::Net::SocketAddress{}) && (prepared_client_info->interface == ClientInfo::Interface::LOCAL)) + address = Poco::Net::SocketAddress{"127.0.0.1", 0}; + + user_id = global_context->getAccessControlManager().login(credentials_, address.host()); prepared_client_info->current_user = credentials_.getUserName(); - prepared_client_info->current_address = address_; + prepared_client_info->current_address = address; #if defined(ARCADIA_BUILD) /// This is harmful field that is used only in foreign "Arcadia" build. diff --git a/src/Server/TCPHandler.cpp b/src/Server/TCPHandler.cpp index b2db65e22bc..ee84693427c 100644 --- a/src/Server/TCPHandler.cpp +++ b/src/Server/TCPHandler.cpp @@ -979,6 +979,7 @@ void TCPHandler::receiveHello() is_interserver_mode = (user == USER_INTERSERVER_MARKER); if (is_interserver_mode) { + client_info.interface = ClientInfo::Interface::TCP_INTERSERVER; receiveClusterNameAndSalt(); return; }