From 4eb54bacceb07c1b7bf7de8145804e69f1e24829 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Mon, 24 Jun 2024 14:10:28 +0200 Subject: [PATCH] Support colon in username, use LRO_USERNAME and LRO_PASSWORD Requires librepo version >= 1.18.0 --- dnf5.spec | 2 +- libdnf5/CMakeLists.txt | 2 +- libdnf5/repo/librepo.cpp | 27 +++++++++++---------------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/dnf5.spec b/dnf5.spec index 68693ddfc..e822a98cd 100644 --- a/dnf5.spec +++ b/dnf5.spec @@ -115,7 +115,7 @@ Provides: dnf5-command(versionlock) # ========== versions of dependencies ========== %global libmodulemd_version 2.5.0 -%global librepo_version 1.15.0 +%global librepo_version 1.18.0 %global libsolv_version 0.7.25 %global sqlite_version 3.35.0 %global swig_version 4 diff --git a/libdnf5/CMakeLists.txt b/libdnf5/CMakeLists.txt index 6bbe04ee9..493d2b085 100644 --- a/libdnf5/CMakeLists.txt +++ b/libdnf5/CMakeLists.txt @@ -103,7 +103,7 @@ pkg_check_modules (GLIB2 glib-2.0>=2.46.0) include_directories(${GLIB2_INCLUDE_DIRS}) target_link_libraries(libdnf5 PRIVATE ${GLIB2_LIBRARIES}) -pkg_check_modules(LIBREPO REQUIRED librepo>=1.15.0) +pkg_check_modules(LIBREPO REQUIRED librepo>=1.18.0) list(APPEND LIBDNF5_PC_REQUIRES "${LIBREPO_MODULE_NAME}") target_include_directories(libdnf5 PUBLIC PRIVATE ${LIBREPO_INCLUDE_DIRS}) target_link_libraries(libdnf5 PRIVATE ${LIBREPO_LDFLAGS}) diff --git a/libdnf5/repo/librepo.cpp b/libdnf5/repo/librepo.cpp index 06a20da28..060e20fa6 100644 --- a/libdnf5/repo/librepo.cpp +++ b/libdnf5/repo/librepo.cpp @@ -76,18 +76,13 @@ static std::string url_encode(const std::string & src) { } /// Format user password string -/// Returns user and password in user:password form. If quote is True, -/// special characters in user and password are URL encoded. +/// Returns user and password in user:password form. +/// Special characters in user and password are URL encoded. /// @param user Username /// @param passwd Password -/// @param encode If quote is True, special characters in user and password are URL encoded. /// @return User and password in user:password form -static std::string format_user_pass_string(const std::string & user, const std::string & passwd, bool encode) { - if (encode) { - return url_encode(user) + ":" + url_encode(passwd); - } else { - return user + ":" + passwd; - } +static std::string format_user_pass_string(const std::string & user, const std::string & passwd) { + return url_encode(user) + ":" + url_encode(passwd); } LibrepoResult & LibrepoResult::operator=(LibrepoResult && other) noexcept { @@ -139,12 +134,12 @@ static void init_remote(LibrepoHandle & handle, const C & config) { handle.set_opt(LRO_IPRESOLVE, LR_IPRESOLVE_V6); } - auto userpwd = config.get_username_option().get_value(); - if (!userpwd.empty()) { - // TODO Use URL encoded form, needs support in librepo - userpwd = format_user_pass_string(userpwd, config.get_password_option().get_value(), false); - handle.set_opt(LRO_USERPWD, userpwd.c_str()); - } + handle.set_opt( + LRO_USERNAME, + config.get_username_option().get_value().empty() ? NULL : config.get_username_option().get_value().c_str()); + handle.set_opt( + LRO_PASSWORD, + config.get_password_option().get_value().empty() ? NULL : config.get_password_option().get_value().c_str()); if (!config.get_sslcacert_option().get_value().empty()) { handle.set_opt(LRO_SSLCACERT, config.get_sslcacert_option().get_value().c_str()); @@ -182,7 +177,7 @@ static void init_remote(LibrepoHandle & handle, const C & config) { if (!config.get_proxy_username_option().empty()) { auto userpwd = config.get_proxy_username_option().get_value(); if (!userpwd.empty()) { - userpwd = format_user_pass_string(userpwd, config.get_proxy_password_option().get_value(), true); + userpwd = format_user_pass_string(userpwd, config.get_proxy_password_option().get_value()); handle.set_opt(LRO_PROXYUSERPWD, userpwd.c_str()); } }