25 #define USER_CREDENTIALS_FILE ".zypp/credentials.cat"
43 AuthDataComparator::operator()(
47 url::ViewOption::DEFAULTS
48 - url::ViewOption::WITH_USERNAME
49 - url::ViewOption::WITH_PASSWORD
50 - url::ViewOption::WITH_QUERY_STR;
52 if (lhs->username() != rhs->username())
55 if (lhs->url().asString(vopt) != rhs->url().asString(vopt))
67 CredManagerOptions::CredManagerOptions(
const Pathname & rootdir)
68 : globalCredFilePath(rootdir /
ZConfig::instance().credentialsGlobalFile())
69 , customCredFileDir(rootdir /
ZConfig::instance().credentialsGlobalDir())
71 char * homedir = getenv(
"HOME");
119 , _globalDirty(false)
129 if (_options.globalCredFilePath.empty())
130 DBG <<
"global cred file not known";
131 else if (PathInfo(_options.globalCredFilePath).isExist())
143 DBG <<
"global cred file does not exist";
145 _credsGlobal = _credsTmp; _credsTmp.clear();
146 DBG <<
"Got " << _credsGlobal.size() <<
" global records." << endl;
152 if (_options.userCredFilePath.empty())
153 DBG <<
"user cred file not known";
154 else if (PathInfo(_options.userCredFilePath).isExist())
165 DBG <<
"user cred file does not exist" << endl;
167 _credsUser = _credsTmp; _credsTmp.clear();
168 DBG <<
"Got " << _credsUser.size() <<
" user records." << endl;
174 _credsTmp.insert(cred);
187 if (url.
asString(vopt).find((*it)->url().asString(vopt)) == 0)
189 if (username.empty() || username == (*it)->username())
213 result =
findIn(_credsGlobal, url, vopt);
217 result =
findIn(_credsUser, url, vopt);
220 DBG <<
"Found credentials for '" << url <<
"':" << endl << *result;
222 DBG <<
"No credentials for '" << url <<
"'" << endl;
238 credfile = _options.customCredFileDir / file.basename();
241 if (_credsTmp.empty())
242 WAR << file <<
" does not contain valid credentials or is not readable." << endl;
245 result = *_credsTmp.begin();
254 const Pathname & file,
260 std::ofstream fs(file.c_str());
264 for_(it, creds.begin(), creds.end())
266 (*it)->dumpAsIniOn(fs);
301 if (credfile.empty())
302 return _pimpl->getCred(url);
303 return _pimpl->getCredFromFile(credfile);
308 {
return _pimpl->getCredFromFile(file); }
314 if (credfile.empty())
326 pair<CredentialIterator, bool> ret =
_pimpl->_credsGlobal.insert(c_ptr);
328 _pimpl->_globalDirty =
true;
329 else if ((*ret.first)->password() != cred.
password())
331 _pimpl->_credsGlobal.erase(ret.first);
332 _pimpl->_credsGlobal.insert(c_ptr);
333 _pimpl->_globalDirty =
true;
342 pair<CredentialIterator, bool> ret =
_pimpl->_credsUser.insert(c_ptr);
344 _pimpl->_userDirty =
true;
345 else if ((*ret.first)->password() != cred.
password())
347 _pimpl->_credsUser.erase(ret.first);
348 _pimpl->_credsUser.insert(c_ptr);
349 _pimpl->_userDirty =
true;
357 _pimpl->saveGlobalCredentials();
359 _pimpl->saveUserCredentials();
360 _pimpl->_globalDirty =
false;
361 _pimpl->_userDirty =
false;
383 c_ptr->setUrl(
Url());
388 if (credFile.absolute())
392 creds,
_pimpl->_options.customCredFileDir / credFile, 0600);
397 ERR <<
"error saving the credentials" << endl;
407 ERR <<
"could not delete user credentials file "
408 <<
_pimpl->_options.globalCredFilePath << endl;
409 _pimpl->_credsUser.clear();
414 ERR <<
"could not delete global credentials file"
415 <<
_pimpl->_options.userCredFilePath << endl;
416 _pimpl->_credsGlobal.clear();
422 {
return _pimpl->_credsGlobal.begin(); }
425 {
return _pimpl->_credsGlobal.end(); }
428 {
return _pimpl->_credsGlobal.size(); }
431 {
return _pimpl->_credsGlobal.empty(); }
435 {
return _pimpl->_credsUser.begin(); }
438 {
return _pimpl->_credsUser.end(); }
441 {
return _pimpl->_credsUser.size(); }
444 {
return _pimpl->_credsUser.empty(); }
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Url::asString() view options.
std::string asString() const
Returns a default string representation of the Url object.
int unlink(const Pathname &path)
Like 'unlink'.
Interim helper class to collect global options and settings.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
#define USER_CREDENTIALS_FILE