From 513f4303347177c5b2d2792aaf245caad51a231f Mon Sep 17 00:00:00 2001 From: Arthur Passos Date: Mon, 30 Jan 2023 12:04:37 -0300 Subject: [PATCH] Add setting to enable/disable reverseDNSQuery function --- programs/server/config.d/reverse_dns_function.xml | 0 src/Functions/reverseDNSQuery.cpp | 9 +++++++++ tests/config/config.d/reverse_dns_query_function.xml | 3 +++ tests/config/install.sh | 1 + .../test_reverse_dns_query/configs/config.xml | 3 --- 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 programs/server/config.d/reverse_dns_function.xml create mode 100644 tests/config/config.d/reverse_dns_query_function.xml delete mode 100644 tests/integration/test_reverse_dns_query/configs/config.xml diff --git a/programs/server/config.d/reverse_dns_function.xml b/programs/server/config.d/reverse_dns_function.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Functions/reverseDNSQuery.cpp b/src/Functions/reverseDNSQuery.cpp index 41adffa8bde..65ce5e859c5 100644 --- a/src/Functions/reverseDNSQuery.cpp +++ b/src/Functions/reverseDNSQuery.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include namespace DB { @@ -14,12 +16,14 @@ namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int BAD_ARGUMENTS; + extern const int FUNCTION_NOT_ALLOWED; } class ReverseDNSQuery : public IFunction { public: static constexpr auto name = "reverseDNSQuery"; + static constexpr auto allow_function_config_name = "allow_reverse_dns_query_function"; static FunctionPtr create(ContextPtr) { @@ -33,6 +37,11 @@ public: ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & data_type, size_t input_rows_count) const override { + if (!Context::getGlobalContextInstance()->getConfigRef().getBool(allow_function_config_name, false)) + { + throw Exception(ErrorCodes::FUNCTION_NOT_ALLOWED, "Function {} is not allowed because {} is not set", name, allow_function_config_name); + } + if (arguments.empty()) { throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires at least one argument", name); diff --git a/tests/config/config.d/reverse_dns_query_function.xml b/tests/config/config.d/reverse_dns_query_function.xml new file mode 100644 index 00000000000..8cd7695b4d3 --- /dev/null +++ b/tests/config/config.d/reverse_dns_query_function.xml @@ -0,0 +1,3 @@ + + 1 + \ No newline at end of file diff --git a/tests/config/install.sh b/tests/config/install.sh index 51865665f59..57606e8b876 100755 --- a/tests/config/install.sh +++ b/tests/config/install.sh @@ -52,6 +52,7 @@ ln -sf $SRC_PATH/config.d/enable_zero_copy_replication.xml $DEST_SERVER_PATH/con ln -sf $SRC_PATH/config.d/nlp.xml $DEST_SERVER_PATH/config.d/ ln -sf $SRC_PATH/config.d/enable_keeper_map.xml $DEST_SERVER_PATH/config.d/ ln -sf $SRC_PATH/config.d/display_name.xml $DEST_SERVER_PATH/config.d/ +ln -sf $SRC_PATH/config.d/reverse_dns_query_function.xml $DEST_SERVER_PATH/config.d/ # Not supported with fasttest. if [ "${DEST_SERVER_PATH}" = "/etc/clickhouse-server" ] diff --git a/tests/integration/test_reverse_dns_query/configs/config.xml b/tests/integration/test_reverse_dns_query/configs/config.xml deleted file mode 100644 index 5ce55afa2a7..00000000000 --- a/tests/integration/test_reverse_dns_query/configs/config.xml +++ /dev/null @@ -1,3 +0,0 @@ - - 1 -