Skip to content

Commit 5449211

Browse files
jrohelevan-goode
authored andcommitted
Support colon in username, use LRO_USERNAME and LRO_PASSWORD
Requires librepo version >= 1.18.0
1 parent 86bbb15 commit 5449211

File tree

4 files changed

+19
-34
lines changed

4 files changed

+19
-34
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ include_directories(${GLIB_INCLUDE_DIRS})
6161
pkg_check_modules(JSONC REQUIRED json-c)
6262
include_directories(${JSONC_INCLUDE_DIRS})
6363
pkg_check_modules(LIBMODULEMD REQUIRED modulemd-2.0>=2.11.2)
64-
pkg_check_modules(REPO REQUIRED librepo>=1.15.0)
64+
pkg_check_modules(REPO REQUIRED librepo>=1.18.0)
6565
include_directories(${REPO_INCLUDE_DIRS})
6666
link_directories(${REPO_LIBRARY_DIRS})
6767
pkg_check_modules(RPM REQUIRED rpm>=4.15.0)

libdnf.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%global libsolv_version 0.7.21
22
%global libmodulemd_version 2.13.0
3-
%global librepo_version 1.15.0
3+
%global librepo_version 1.18.0
44
%global dnf_conflict 4.11.0
55
%global swig_version 3.0.12
66
%global libdnf_major_version 0

libdnf/dnf-repo.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -817,20 +817,16 @@ dnf_repo_set_metadata_expire(DnfRepo *repo, guint metadata_expire)
817817
/**
818818
* @brief Format user password string
819819
*
820-
* Returns user and password in user:password form. If encode is True,
821-
* special characters in user and password are URL encoded.
820+
* Returns user and password in user:password form.
821+
* Special characters in user and password are URL encoded.
822822
*
823823
* @param user Username
824824
* @param passwd Password
825-
* @param encode If quote is True, special characters in user and password are URL encoded.
826825
* @return User and password in user:password form
827826
*/
828-
static std::string formatUserPassString(const std::string & user, const std::string & passwd, bool encode)
827+
static std::string formatUserPassString(const std::string & user, const std::string & passwd)
829828
{
830-
if (encode)
831-
return libdnf::urlEncode(user) + ":" + libdnf::urlEncode(passwd);
832-
else
833-
return user + ":" + passwd;
829+
return libdnf::urlEncode(user) + ":" + libdnf::urlEncode(passwd);
834830
}
835831

836832
/* Resets repository configuration options previously readed from repository
@@ -1130,22 +1126,19 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, gboolean reloadFromGKeyFile, GError **e
11301126
"repo '%s': 'proxy_username' is set but not 'proxy_password'", repoId);
11311127
return FALSE;
11321128
}
1133-
tmp_str = formatUserPassString(tmp_str, conf->proxy_password().getValue(), true);
1129+
tmp_str = formatUserPassString(tmp_str, conf->proxy_password().getValue());
11341130
tmp_cstr = tmp_str.c_str();
11351131
}
11361132
}
11371133
if (!lr_handle_setopt(priv->repo_handle, error, LRO_PROXYUSERPWD, tmp_cstr))
11381134
return FALSE;
11391135

11401136
// setup username and password
1141-
tmp_cstr = NULL;
1142-
tmp_str = conf->username().getValue();
1143-
if (!tmp_str.empty()) {
1144-
// TODO Use URL encoded form, needs support in librepo
1145-
tmp_str = formatUserPassString(tmp_str, conf->password().getValue(), false);
1146-
tmp_cstr = tmp_str.c_str();
1147-
}
1148-
if (!lr_handle_setopt(priv->repo_handle, error, LRO_USERPWD, tmp_cstr))
1137+
auto & username = conf->username().getValue();
1138+
if (!lr_handle_setopt(priv->repo_handle, error, LRO_USERNAME, username.empty() ? NULL : username.c_str()))
1139+
return FALSE;
1140+
auto & password = conf->password().getValue();
1141+
if (!lr_handle_setopt(priv->repo_handle, error, LRO_PASSWORD, password.empty() ? NULL : password.c_str()))
11491142
return FALSE;
11501143

11511144
auto proxy_sslverify = conf->proxy_sslverify().getValue();

libdnf/repo/Repo.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,16 @@ int Repo::Impl::mirrorFailureCB(void * data, const char * msg, const char * url,
252252
/**
253253
* @brief Format user password string
254254
*
255-
* Returns user and password in user:password form. If quote is True,
256-
* special characters in user and password are URL encoded.
255+
* Returns user and password in user:password form.
256+
* Special characters in user and password are URL encoded.
257257
*
258258
* @param user Username
259259
* @param passwd Password
260-
* @param encode If quote is True, special characters in user and password are URL encoded.
261260
* @return User and password in user:password form
262261
*/
263-
static std::string formatUserPassString(const std::string & user, const std::string & passwd, bool encode)
262+
static std::string formatUserPassString(const std::string & user, const std::string & passwd)
264263
{
265-
if (encode)
266-
return urlEncode(user) + ":" + urlEncode(passwd);
267-
else
268-
return user + ":" + passwd;
264+
return urlEncode(user) + ":" + urlEncode(passwd);
269265
}
270266

271267
Repo::Impl::Impl(Repo & owner, const std::string & id, Type type, std::unique_ptr<ConfigRepo> && conf)
@@ -524,12 +520,8 @@ static void setHandle(LrHandle * h, ConfigT & config, const char * repoId = null
524520
}
525521

526522
// setup username/password if needed
527-
auto userpwd = config.username().getValue();
528-
if (!userpwd.empty()) {
529-
// TODO Use URL encoded form, needs support in librepo
530-
userpwd = formatUserPassString(userpwd, config.password().getValue(), false);
531-
handleSetOpt(h, LRO_USERPWD, userpwd.c_str());
532-
}
523+
handleSetOpt(h, LRO_USERNAME, config.username().getValue().empty() ? NULL : config.username().getValue().c_str());
524+
handleSetOpt(h, LRO_PASSWORD, config.password().getValue().empty() ? NULL : config.password().getValue().c_str());
533525

534526
if (!config.proxy().empty() && !config.proxy().getValue().empty())
535527
handleSetOpt(h, LRO_PROXY, config.proxy().getValue().c_str());
@@ -548,7 +540,7 @@ static void setHandle(LrHandle * h, ConfigT & config, const char * repoId = null
548540
else
549541
throw RepoError(_("'proxy_username' is set but not 'proxy_password'"));
550542
}
551-
userpwd = formatUserPassString(userpwd, config.proxy_password().getValue(), true);
543+
userpwd = formatUserPassString(userpwd, config.proxy_password().getValue());
552544
handleSetOpt(h, LRO_PROXYUSERPWD, userpwd.c_str());
553545
}
554546
}

0 commit comments

Comments
 (0)