From f965633eeb0de3a7c15c2b96401105270c4ee223 Mon Sep 17 00:00:00 2001 From: wangyunlai Date: Fri, 12 Jan 2024 10:04:38 +0800 Subject: [PATCH] simplify the code --- src/sql/resolver/ob_resolver_utils.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sql/resolver/ob_resolver_utils.cpp b/src/sql/resolver/ob_resolver_utils.cpp index 93d3f3371..5d3529c14 100644 --- a/src/sql/resolver/ob_resolver_utils.cpp +++ b/src/sql/resolver/ob_resolver_utils.cpp @@ -7791,9 +7791,12 @@ int ObResolverUtils::check_secure_path(const common::ObString &secure_file_priv, { int ret = OB_SUCCESS; + const char *access_denied_notice_message = + "Access denied, please set suitable variable 'secure-file-priv' first, such as: SET GLOBAL secure_file_priv = '/'"; + if (secure_file_priv.empty() || 0 == secure_file_priv.case_compare(N_NULL)) { ret = OB_ERR_NO_PRIVILEGE; - FORWARD_USER_ERROR_MSG(ret, "Access denied, please set suitable variable 'secure-file-priv' first, such as: SET GLOBAL secure_file_priv = '/'"); + FORWARD_USER_ERROR_MSG(ret, access_denied_notice_message); LOG_WARN("no priv", K(ret), K(secure_file_priv), K(full_path)); } else if (OB_UNLIKELY(secure_file_priv.length() >= DEFAULT_BUF_LENGTH)) { ret = OB_ERR_UNEXPECTED; @@ -7807,7 +7810,7 @@ int ObResolverUtils::check_secure_path(const common::ObString &secure_file_priv, stat(buf, &path_stat); if (0 == S_ISDIR(path_stat.st_mode)) { ret = OB_ERR_NO_PRIVILEGE; - FORWARD_USER_ERROR_MSG(ret, "Access denied, please set suitable variable 'secure-file-priv' first, such as: SET GLOBAL secure_file_priv = '/'"); + FORWARD_USER_ERROR_MSG(ret, access_denied_notice_message); LOG_WARN("no priv", K(ret), K(secure_file_priv), K(full_path)); } else { MEMSET(buf, 0, sizeof(buf)); @@ -7819,16 +7822,16 @@ int ObResolverUtils::check_secure_path(const common::ObString &secure_file_priv, const int64_t pos = secure_file_priv_tmp.length(); if (full_path.length() < secure_file_priv_tmp.length()) { ret = OB_ERR_NO_PRIVILEGE; - FORWARD_USER_ERROR_MSG(ret, "Access denied, please set suitable variable 'secure-file-priv' first, such as: SET GLOBAL secure_file_priv = '/'"); + FORWARD_USER_ERROR_MSG(ret, access_denied_notice_message); LOG_WARN("no priv", K(ret), K(secure_file_priv), K(secure_file_priv_tmp), K(full_path)); } else if (!full_path.prefix_match(secure_file_priv_tmp)) { ret = OB_ERR_NO_PRIVILEGE; - FORWARD_USER_ERROR_MSG(ret, "Access denied, please set suitable variable 'secure-file-priv' first, such as: SET GLOBAL secure_file_priv = '/'"); + FORWARD_USER_ERROR_MSG(ret, access_denied_notice_message); LOG_WARN("no priv", K(ret), K(secure_file_priv), K(secure_file_priv_tmp), K(full_path)); } else if (full_path.length() > secure_file_priv_tmp.length() && secure_file_priv_tmp != "/" && full_path[pos] != '/') { ret = OB_ERR_NO_PRIVILEGE; - FORWARD_USER_ERROR_MSG(ret, "Access denied, please set suitable variable 'secure-file-priv' first, such as: SET GLOBAL secure_file_priv = '/'"); + FORWARD_USER_ERROR_MSG(ret, access_denied_notice_message); LOG_WARN("no priv", K(ret), K(secure_file_priv), K(secure_file_priv_tmp), K(full_path)); } }