Skip to content

Commit

Permalink
Support colon in username, use LRO_USERNAME and LRO_PASSWORD
Browse files Browse the repository at this point in the history
Requires librepo version >= 1.18.0
  • Loading branch information
jrohel authored and evan-goode committed Jun 27, 2024
1 parent 62d0d1f commit 4eb54ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dnf5.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libdnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
27 changes: 11 additions & 16 deletions libdnf5/repo/librepo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 4eb54ba

Please sign in to comment.