From 412a66bdc2ac14325a8145ff59cdee5816e4cee2 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Tue, 18 Dec 2007 11:34:31 +0000 Subject: [PATCH] - fixed password handling in URLs (bug #347273) --- package/libzypp.changes | 5 +++++ tests/repo/RepoVariables_test.cc | 29 ++++++++++++++++++++++------- zypp/RepoInfo.cc | 2 +- zypp/RepoManager.cc | 36 ++++++++++++++++++------------------ zypp/Url.cc | 5 +++-- zypp/repo/RepoType.h | 2 +- zypp/repo/RepoVariables.cc | 31 +++++++++++++++---------------- zypp/repo/RepoVariables.h | 10 +++++----- zypp/url/UrlBase.cc | 2 +- 9 files changed, 71 insertions(+), 51 deletions(-) diff --git a/package/libzypp.changes b/package/libzypp.changes index 6e253e9..71456f8 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,9 @@ ------------------------------------------------------------------- +Tue Dec 18 12:28:22 CET 2007 - aschnell@suse.de + +- fixed password handling in URLs (bug #347273) + +------------------------------------------------------------------- Mon Dec 17 13:47:44 CET 2007 - ma@suse.de - Fixed default text locale detection not to use static variables. (#346872) diff --git a/tests/repo/RepoVariables_test.cc b/tests/repo/RepoVariables_test.cc index 44289a5..c5b1e7e 100644 --- a/tests/repo/RepoVariables_test.cc +++ b/tests/repo/RepoVariables_test.cc @@ -24,14 +24,29 @@ using namespace zypp::repo; void replace_test(const string &dir) { - RepoVariablesStringReplacer replacer; - - BOOST_CHECK_EQUAL(replacer("http://foo/$arch/bar"), + /* check RepoVariablesStringReplacer */ + + RepoVariablesStringReplacer replacer1; + + BOOST_CHECK_EQUAL(replacer1("http://foo/$arch/bar"), "http://foo/"+ ZConfig::instance().systemArchitecture().asString() + "/bar"); getZYpp()->setArchitecture(Arch("i686")); - BOOST_CHECK_EQUAL(replacer("http://foo/$arch/bar/$basearch"), + BOOST_CHECK_EQUAL(replacer1("http://foo/$arch/bar/$basearch"), "http://foo/i686/bar/i386"); + + /* check RepoVariablesUrlReplacer */ + + RepoVariablesUrlReplacer replacer2; + + BOOST_CHECK_EQUAL(replacer2(Url("ftp://user:secret@site.org/$arch/")).asCompleteString(), + "ftp://user:secret@site.org/i686/"); + + BOOST_CHECK_EQUAL(replacer2(Url("http://user:my$arch@site.org/$basearch/")).asCompleteString(), + "http://user:my$arch@site.org/i386/"); + + BOOST_CHECK_EQUAL(replacer2(Url("http://site.org/update/?arch=$arch")).asCompleteString(), + "http://site.org/update/?arch=i686"); } test_suite* @@ -45,15 +60,15 @@ init_unit_test_suite( int argc, char *argv[] ) cout << "RepoVariables_test:" " path to directory with test data required as parameter. Using " << datadir << endl; //return (test_suite *)0; - + } else { datadir = argv[1]; } - + test_suite* test= BOOST_TEST_SUITE("RepoVariables"); - + std::string const params[] = { datadir }; test->add(BOOST_PARAM_TEST_CASE(&replace_test, (std::string const*)params, params+1)); diff --git a/zypp/RepoInfo.cc b/zypp/RepoInfo.cc index 82cf94a..843ce82 100644 --- a/zypp/RepoInfo.cc +++ b/zypp/RepoInfo.cc @@ -191,7 +191,7 @@ namespace zypp { return alias(); } - + repo::RepoVariablesStringReplacer replacer; return replacer(_pimpl->name); } diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 2d9a575..9bab4e6 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -117,17 +117,17 @@ namespace zypp if ( !store.isCached(info.alias()) ) return; - + MIL << info.alias() << " cleaning cache..." << endl; data::RecordId id = store.lookupRepository(info.alias()); - + CombinedProgressData subprogrcv(progress); - + store.cleanRepository(id, subprogrcv); } - + //////////////////////////////////////////////////////////////////////////// - + /** * Reads RepoInfo's from a repo file. * @@ -249,7 +249,7 @@ namespace zypp static shared_ptr _nullimpl( new Impl ); return _nullimpl; } - + private: friend Impl * rwcowClone( const Impl * rhs ); /** clone for RWCOW_pointer */ @@ -312,7 +312,7 @@ namespace zypp } //////////////////////////////////////////////////////////////////////////// - + RepoStatus RepoManager::metadataStatus( const RepoInfo &info ) const { Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); @@ -519,7 +519,7 @@ namespace zypp ERR << "refresh check failed for " << url << endl; ZYPP_RETHROW(e); } - + return true; // default } @@ -624,7 +624,7 @@ namespace zypp { ZYPP_CAUGHT(e); ERR << "Trying another url..." << endl; - + // remember the exception caught for the *first URL* // if all other URLs fail, the rexception will be thrown with the // cause of the problem of the first URL remembered @@ -680,7 +680,7 @@ namespace zypp MIL << info.alias() << " cache rebuild is forced" << endl; } } - + needs_cleaning = true; } @@ -709,7 +709,7 @@ namespace zypp break; } - + switch ( repokind.toEnum() ) { case RepoType::RPMMD_e : @@ -769,7 +769,7 @@ namespace zypp return repo::RepoType::RPMMD; if ( access.doesFileExist("/content") ) return repo::RepoType::YAST2; - + // if it is a local url of type dir if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) ) { @@ -798,9 +798,9 @@ namespace zypp return repo::RepoType::NONE; } - + //////////////////////////////////////////////////////////////////////////// - + void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv ) { @@ -833,7 +833,7 @@ namespace zypp progress.sendTo(ProgressReportAdaptor( progressrcv, report )); //progress.sendTo( progressrcv ); progress.name(str::form(_("Reading repository '%s' cache"), info.name().c_str())); - + cache::CacheStore store(_pimpl->options.repoCachePath); if ( ! store.isCached( info.alias() ) ) @@ -842,9 +842,9 @@ namespace zypp MIL << "Repository " << info.alias() << " is cached" << endl; data::RecordId id = store.lookupRepository(info.alias()); - + CombinedProgressData subprogrcv(progress); - + repo::cached::RepoOptions opts( info, _pimpl->options.repoCachePath, id ); opts.readingResolvablesProgress = subprogrcv; repo::cached::RepoImpl::Ptr repoimpl = @@ -1031,7 +1031,7 @@ namespace zypp callback::SendReport report; progress.sendTo( ProgressReportAdaptor( progressrcv, report ) ); progress.name(str::form(_("Removing repository '%s'"), info.name().c_str())); - + MIL << "Going to delete repo " << info.alias() << endl; std::list repos = knownRepositories(); diff --git a/zypp/Url.cc b/zypp/Url.cc index aeb9cba..9c6b42f 100644 --- a/zypp/Url.cc +++ b/zypp/Url.cc @@ -9,6 +9,7 @@ /** * \file zypp/Url.cc */ + #include #include #include @@ -804,12 +805,12 @@ namespace zypp { return (lhs.asCompleteString() == rhs.asCompleteString()); } - + bool operator!=( const Url &lhs, const Url &rhs ) { return (lhs.asCompleteString() != rhs.asCompleteString()); } - + //////////////////////////////////////////////////////////////////// } // namespace zypp ////////////////////////////////////////////////////////////////////// diff --git a/zypp/repo/RepoType.h b/zypp/repo/RepoType.h index 4926446..e4a6c53 100644 --- a/zypp/repo/RepoType.h +++ b/zypp/repo/RepoType.h @@ -11,7 +11,7 @@ #define ZYPP_REPO_TYPE_H_ #include -#include +#include namespace zypp { diff --git a/zypp/repo/RepoVariables.cc b/zypp/repo/RepoVariables.cc index 8bf617f..415dfca 100644 --- a/zypp/repo/RepoVariables.cc +++ b/zypp/repo/RepoVariables.cc @@ -21,7 +21,7 @@ namespace zypp { namespace repo { - + RepoVariablesStringReplacer::RepoVariablesStringReplacer() {} @@ -31,19 +31,19 @@ RepoVariablesStringReplacer::~RepoVariablesStringReplacer() std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const { string newvalue(value); - + // $arch newvalue = str::gsub( newvalue, "$arch", ZConfig::instance().systemArchitecture().asString() ); // $basearch - + Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) ); Arch::CompatSet::const_iterator it = cset.end(); --it; // now at noarch --it; - + Arch basearch = *it; if ( basearch == Arch_noarch ) { @@ -64,21 +64,20 @@ RepoVariablesUrlReplacer::RepoVariablesUrlReplacer() RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer() {} - +/* + * Replaces '$arch' and '$basearch' in the path and query part of the URL + * with the global ZYpp values. Examples: + * + * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/ + * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386 + */ Url RepoVariablesUrlReplacer::operator()( const Url &value ) const { + Url newurl = value; RepoVariablesStringReplacer replacer; - string transformed = replacer(value.asString()); - Url newurl; - try { - newurl = Url(transformed); - } - catch ( const Exception &e ) - { - ZYPP_CAUGHT(e); - // just return what we got - return value; - } + newurl.setPathData(replacer(value.getPathData())); + newurl.setQueryString(replacer(value.getQueryString())); + return newurl; } diff --git a/zypp/repo/RepoVariables.h b/zypp/repo/RepoVariables.h index 6d2000b..0775f07 100644 --- a/zypp/repo/RepoVariables.h +++ b/zypp/repo/RepoVariables.h @@ -11,7 +11,7 @@ #define ZYPP_REPO_VARIABLES_H_ #include -#include +#include #include "zypp/Url.h" @@ -28,7 +28,7 @@ namespace zypp struct RepoVariablesStringReplacer : public std::unary_function { RepoVariablesStringReplacer(); - + std::string operator()( const std::string &value ) const; ~RepoVariablesStringReplacer(); @@ -42,12 +42,12 @@ namespace zypp struct RepoVariablesUrlReplacer : public std::unary_function { RepoVariablesUrlReplacer(); - + Url operator()( const Url &url ) const; - + ~RepoVariablesUrlReplacer(); }; - + } // ns repo } // ns zypp diff --git a/zypp/url/UrlBase.cc b/zypp/url/UrlBase.cc index 68ee0e0..c79cd5c 100644 --- a/zypp/url/UrlBase.cc +++ b/zypp/url/UrlBase.cc @@ -1320,7 +1320,7 @@ namespace zypp { struct in6_addr ip; std::string temp( host.substr(1, host.size()-2)); - + return inet_pton(AF_INET6, temp.c_str(), &ip) > 0; } else -- 2.7.4