Author: jkupec Date: Wed Sep 17 23:40:33 2008 New Revision: 11088 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11088&view=rev Log: - set 600 on user creds and 640 permissions on global creds file - clearAll() added Modified: trunk/libzypp/zypp/media/CredentialManager.cc trunk/libzypp/zypp/media/CredentialManager.h Modified: trunk/libzypp/zypp/media/CredentialManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/CredentialManager.cc?rev=11088&r1=11087&r2=11088&view=diff ============================================================================== --- trunk/libzypp/zypp/media/CredentialManager.cc (original) +++ trunk/libzypp/zypp/media/CredentialManager.cc Wed Sep 17 23:40:33 2008 @@ -215,33 +215,38 @@ return result; } - static void save_creds_in_file( + static int save_creds_in_file( const CredentialManager::CredentialSet creds, - const Pathname & file/*, - desired permissions*/) + const Pathname & file, + const mode_t mode) { + int ret = 0; 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())); + ret = 1; for_(it, creds.begin(), creds.end()) { (*it)->dumpAsIniOn(fs); fs << endl; } + fs.close(); + + filesystem::chmod(file, mode); + + return ret; } void CredentialManager::Impl::saveGlobalCredentials() { - save_creds_in_file(_credsGlobal, _options.globalCredFilePath); + save_creds_in_file(_credsGlobal, _options.globalCredFilePath, 0640); } - + void CredentialManager::Impl::saveUserCredentials() { - save_creds_in_file(_credsUser, _options.userCredFilePath); + save_creds_in_file(_credsUser, _options.userCredFilePath, 0600); } @@ -255,15 +260,19 @@ : _pimpl(new Impl(opts)) {} + AuthData_Ptr CredentialManager::getCred(const Url & url) { return _pimpl->getCred(url); } + AuthData_Ptr CredentialManager::getCredFromFile(const Pathname & file) { return _pimpl->getCredFromFile(file); } + void CredentialManager::save(const AuthData & cred, bool global) { global ? saveInGlobal(cred) : saveInUser(cred); } + void CredentialManager::saveInGlobal(const AuthData & cred) { AuthData_Ptr c_ptr; @@ -272,6 +281,7 @@ _pimpl->saveGlobalCredentials(); } + void CredentialManager::saveInUser(const AuthData & cred) { AuthData_Ptr c_ptr; @@ -280,11 +290,48 @@ _pimpl->saveUserCredentials(); } - void saveIn(const AuthData &, const Pathname & credFile) + + void CredentialManager::saveIn(const AuthData & cred, const Pathname & credFile) + { + AuthData_Ptr c_ptr; + c_ptr.reset(new AuthData(cred)); // FIX for child classes if needed + CredentialManager::CredentialSet creds; + creds.insert(c_ptr); + + int ret; + if (credFile.absolute()) + ret = save_creds_in_file(creds, credFile, 0640); + else + ret = save_creds_in_file( + creds, _pimpl->_options.customCredFileDir / credFile, 0600); + + if (!ret) + { + //! \todo figure out the reason(?), call back to user + ERR << "error saving the credentials" << endl; + } + } + + + void CredentialManager::clearAll(bool global) { - //! \todo save in the file or /etc/zypp/credentials.d/credFile if not absolute + if (global) + { + if (!filesystem::unlink(_pimpl->_options.globalCredFilePath)) + ERR << "could not delete user credentials file " + << _pimpl->_options.globalCredFilePath << endl; + _pimpl->_credsUser.clear(); + } + else + { + if (!filesystem::unlink(_pimpl->_options.userCredFilePath)) + ERR << "could not delete global credentials file" + << _pimpl->_options.userCredFilePath << endl; + _pimpl->_credsGlobal.clear(); + } } + CredentialManager::CredentialIterator CredentialManager::credsGlobalBegin() const { return _pimpl->_credsGlobal.begin(); } Modified: trunk/libzypp/zypp/media/CredentialManager.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/CredentialManager.h?rev=11088&r1=11087&r2=11088&view=diff ============================================================================== --- trunk/libzypp/zypp/media/CredentialManager.h (original) +++ trunk/libzypp/zypp/media/CredentialManager.h Wed Sep 17 23:40:33 2008 @@ -30,6 +30,9 @@ // // CLASS NAME : CredManagerOptions // + /** + * \todo configurable cred file locations + */ struct CredManagerOptions { CredManagerOptions(const Pathname & rootdir = ""); @@ -46,7 +49,9 @@ // CLASS NAME : CredentialManager // /** - * + * \todo better method names + * \todo separate add() and save() methods + * \todo delete(AuthData) method */ class CredentialManager { @@ -99,7 +104,7 @@ /** * */ - void clear(bool global = false) {} + void clearAll(bool global = false); CredentialIterator credsGlobalBegin() const; CredentialIterator credsGlobalEnd() const; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org