Author: jkupec Date: Wed Sep 17 18:05:28 2008 New Revision: 11085 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11085&view=rev Log: - save user credentials when adding repos/services with URLs containing the credentials (bnc #425462) Modified: trunk/libzypp/zypp/RepoManager.cc trunk/libzypp/zypp/RepoManager.h trunk/libzypp/zypp/media/CredentialManager.cc Modified: trunk/libzypp/zypp/RepoManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=11085&r1=11084&r2=11085&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.cc (original) +++ trunk/libzypp/zypp/RepoManager.cc Wed Sep 17 18:05:28 2008 @@ -30,6 +30,7 @@ #include "zypp/RepoManager.h" #include "zypp/media/MediaManager.h" +#include "zypp/media/CredentialManager.h" #include "zypp/MediaSetAccess.h" #include "zypp/ExternalProgram.h" #include "zypp/ManagedFile.h" @@ -120,6 +121,8 @@ { DBG << "Target not initialized, using an empty servicesTargetDistro." << endl; } + + rootDir = root_r; } RepoManagerOptions RepoManagerOptions::makeTestSetup( const Pathname & root_r ) @@ -131,6 +134,7 @@ ret.repoPackagesCachePath = root_r/"packages"; ret.knownReposPath = root_r/"repos.d"; ret.knownServicesPath = root_r/"services.d"; + ret.rootDir = root_r; return ret; } @@ -1217,6 +1221,26 @@ tosave.dumpAsIniOn(file); tosave.setFilepath(repofile); _pimpl->repos.insert(tosave); + + progress.set(90); + + // check for credentials in Urls + bool havePasswords = false; + for_( urlit, tosave.baseUrlsBegin(), tosave.baseUrlsEnd() ) + if ( !urlit->getUsername().empty() && !urlit->getPassword().empty() ) + { havePasswords = true; break; } + // save the credentials + if ( havePasswords ) + { + media::CredentialManager cm( + media::CredManagerOptions(_pimpl->options.rootDir) ); + + for_(urlit, tosave.baseUrlsBegin(), tosave.baseUrlsEnd()) + if (!urlit->getPassword().empty() && !urlit->getUsername().empty()) + //! \todo use a method calling UI callbacks to ask where to save creds? + cm.saveInUser(media::AuthData(*urlit)); + } + progress.toMax(); MIL << "done" << endl; } @@ -1498,6 +1522,16 @@ ServiceInfo toSave( service ); _pimpl->saveService( toSave ); _pimpl->services.insert( toSave ); + + // check for credentials in Url + if ( !toSave.url().getUsername().empty() && !toSave.url().getPassword().empty() ) + { + media::CredentialManager cm( + media::CredManagerOptions(_pimpl->options.rootDir) ); + + //! \todo use a method calling UI callbacks to ask where to save creds? + cm.saveInUser(media::AuthData(toSave.url())); + } MIL << "added service " << toSave.alias() << endl; } Modified: trunk/libzypp/zypp/RepoManager.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.h?rev=11085&r1=11084&r2=11085&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.h (original) +++ trunk/libzypp/zypp/RepoManager.h Wed Sep 17 18:05:28 2008 @@ -93,6 +93,9 @@ * If empty, no repositories contained in the index will be skipped. */ std::string servicesTargetDistro; + + /** remembers root_r value for later use */ + Pathname rootDir; }; Modified: trunk/libzypp/zypp/media/CredentialManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/CredentialManager.cc?rev=11085&r1=11084&r2=11085&view=diff ============================================================================== --- trunk/libzypp/zypp/media/CredentialManager.cc (original) +++ trunk/libzypp/zypp/media/CredentialManager.cc Wed Sep 17 18:05:28 2008 @@ -217,10 +217,12 @@ static void save_creds_in_file( const CredentialManager::CredentialSet creds, - const Pathname & file) + const Pathname & file/*, + desired permissions*/) { filesystem::assert_dir(file.dirname()); + //! \todo set correct permissions std::ofstream fs(file.c_str()); if (!fs) ZYPP_THROW(Exception("Can't open " + file.asString())); @@ -280,7 +282,7 @@ void saveIn(const AuthData &, const Pathname & credFile) { - //! \todo + //! \todo save in the file or /etc/zypp/credentials.d/credFile if not absolute } CredentialManager::CredentialIterator CredentialManager::credsGlobalBegin() const -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org