27 #define USER_CREDENTIALS_FILE ".zypp/credentials.cat"
49 int cmp = lhs->url().asString(vopt).compare( rhs->url().asString(vopt) );
51 cmp = lhs->username().compare( rhs->username() );
62 : globalCredFilePath(rootdir /
ZConfig::instance().credentialsGlobalFile())
63 , customCredFileDir(rootdir /
ZConfig::instance().credentialsGlobalDir())
65 char * homedir = getenv(
"HOME");
113 , _globalDirty(false)
123 if (_options.globalCredFilePath.empty())
124 DBG <<
"global cred file not known";
137 DBG <<
"global cred file does not exist";
139 _credsGlobal = _credsTmp; _credsTmp.clear();
140 DBG <<
"Got " << _credsGlobal.size() <<
" global records." << endl;
146 if (_options.userCredFilePath.empty())
147 DBG <<
"user cred file not known";
159 DBG <<
"user cred file does not exist" << endl;
161 _credsUser = _credsTmp; _credsTmp.clear();
162 DBG <<
"Got " << _credsUser.size() <<
" user records." << endl;
168 _credsTmp.insert(cred);
177 const std::string & username =
url.getUsername();
181 if (
url.asString(vopt).find((*it)->url().asString(vopt)) == 0)
183 if (username.empty() || username == (*it)->username())
207 result =
findIn(_credsGlobal,
url, vopt);
214 DBG <<
"Found credentials for '" <<
url <<
"':" << endl << *result;
216 DBG <<
"No credentials for '" <<
url <<
"'" << endl;
232 credfile = _options.customCredFileDir / file.
basename();
235 if (_credsTmp.empty())
236 WAR << file <<
" does not contain valid credentials or is not readable." << endl;
239 result = *_credsTmp.begin();
254 std::ofstream fs(file.
c_str());
258 for_(it, creds.begin(), creds.end())
260 (*it)->dumpAsIniOn(fs);
294 std::string credfile =
url.getQueryParam(
"credentials");
295 if (credfile.empty())
297 return _pimpl->getCredFromFile(credfile);
302 {
return _pimpl->getCredFromFile(file); }
308 if (credfile.
empty())
320 std::pair<CredentialIterator, bool> ret =
_pimpl->_credsGlobal.insert(c_ptr);
322 _pimpl->_globalDirty =
true;
323 else if ((*ret.first)->password() != cred.
password())
325 _pimpl->_credsGlobal.erase(ret.first);
326 _pimpl->_credsGlobal.insert(c_ptr);
327 _pimpl->_globalDirty =
true;
336 std::pair<CredentialIterator, bool> ret =
_pimpl->_credsUser.insert(c_ptr);
338 _pimpl->_userDirty =
true;
339 else if ((*ret.first)->password() != cred.
password())
341 _pimpl->_credsUser.erase(ret.first);
342 _pimpl->_credsUser.insert(c_ptr);
343 _pimpl->_userDirty =
true;
351 _pimpl->saveGlobalCredentials();
353 _pimpl->saveUserCredentials();
354 _pimpl->_globalDirty =
false;
355 _pimpl->_userDirty =
false;
377 c_ptr->setUrl(
Url());
386 creds,
_pimpl->_options.customCredFileDir / credFile, 0600);
391 ERR <<
"error saving the credentials" << endl;
401 ERR <<
"could not delete user credentials file "
402 <<
_pimpl->_options.globalCredFilePath << endl;
403 _pimpl->_credsUser.clear();
408 ERR <<
"could not delete global credentials file"
409 <<
_pimpl->_options.userCredFilePath << endl;
410 _pimpl->_credsGlobal.clear();
416 {
return _pimpl->_credsGlobal.begin(); }
419 {
return _pimpl->_credsGlobal.end(); }
422 {
return _pimpl->_credsGlobal.size(); }
425 {
return _pimpl->_credsGlobal.empty(); }
429 {
return _pimpl->_credsUser.begin(); }
432 {
return _pimpl->_credsUser.end(); }
435 {
return _pimpl->_credsUser.size(); }
438 {
return _pimpl->_credsUser.empty(); }
#define USER_CREDENTIALS_FILE
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
Interim helper class to collect global options and settings.
Wrapper class for ::stat/::lstat.
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
bool absolute() const
Test for an absolute path.
std::string basename() const
Return the last component of this path.
bool empty() const
Test for an empty path.
const char * c_str() const
String representation.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
int unlink(const Pathname &path)
Like 'unlink'.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Easy-to use interface to the ZYPP dependency resolver.
Url::asString() view options.
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
static const ViewOption DEFAULTS
Default combination of view options.
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.