16 #include <zypp/base/Function.h> 17 #include <zypp/base/Logger.h> 18 #include <zypp/base/Easy.h> 19 #include <zypp/PathInfo.h> 25 #include <boost/interprocess/sync/file_lock.hpp> 26 #include <boost/interprocess/sync/scoped_lock.hpp> 27 #include <boost/interprocess/sync/sharable_lock.hpp> 29 namespace bpci = boost::interprocess;
34 #define USER_CREDENTIALS_FILE ".zypp/credentials.cat" 56 int cmp = lhs->url().asString(vopt).compare( rhs->url().asString(vopt) );
58 cmp = lhs->username().compare( rhs->username() );
69 : globalCredFilePath(rootdir /
ZConfig::instance().credentialsGlobalFile())
70 , customCredFileDir(rootdir /
ZConfig::instance().credentialsGlobalDir())
72 char * homedir = getenv(
"HOME");
120 , _globalDirty(false)
130 if (_options.globalCredFilePath.empty())
131 DBG <<
"global cred file not known";
144 DBG <<
"global cred file does not exist";
146 _credsGlobal = _credsTmp; _credsTmp.clear();
147 DBG <<
"Got " << _credsGlobal.size() <<
" global records." << endl;
153 if (_options.userCredFilePath.empty())
154 DBG <<
"user cred file not known";
166 DBG <<
"user cred file does not exist" << endl;
168 _credsUser = _credsTmp; _credsTmp.clear();
169 DBG <<
"Got " << _credsUser.size() <<
" user records." << endl;
175 _credsTmp.insert(cred);
187 if ( !(*it)->url().isValid() )
191 if ( url.
asString(vopt).find((*it)->url().asString(vopt)) == 0 )
193 if ( username.empty() || username == (*it)->username() )
217 result =
findIn(_credsGlobal, url, vopt);
221 result =
findIn(_credsUser, url, vopt);
224 DBG <<
"Found credentials for '" << url <<
"':" << endl << *result;
226 DBG <<
"No credentials for '" << url <<
"'" << endl;
242 credfile = _options.customCredFileDir / file.
basename();
245 bpci::file_lock lockFile ( credfile.
c_str() );
246 bpci::scoped_lock lock( lockFile );
249 if (_credsTmp.empty())
250 WAR << file <<
" does not contain valid credentials or is not readable." << endl;
253 result = *_credsTmp.begin();
268 std::ofstream fs(file.
c_str());
273 bpci::file_lock lockFile ( file.
c_str() );
274 bpci::scoped_lock lock( lockFile );
277 for_(it, creds.begin(), creds.end())
279 (*it)->dumpAsIniOn(fs);
280 (*it)->setLastDatabaseUpdate( time(
nullptr ) );
315 if (credfile.empty())
331 if (credfile.
empty())
349 else if ((*ret.first)->password() != cred.
password())
368 else if ((*ret.first)->password() != cred.
password())
406 c_ptr->setUrl(
Url());
420 ERR <<
"error saving the credentials" << endl;
430 ERR <<
"could not delete user credentials file " 437 ERR <<
"could not delete global credentials file" int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const char * c_str() const
String representation.
std::string basename() const
Return the last component of this path.
Url::asString() view options.
bool empty() const
Test for an empty path.
std::string asString() const
Returns a default string representation of the Url object.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
int unlink(const Pathname &path)
Like 'unlink'.
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
Interim helper class to collect global options and settings.
bool absolute() const
Test for an absolute path.
bool isValid() const
Verifies the Url.
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.
Wrapper class for ::stat/::lstat.
#define USER_CREDENTIALS_FILE
static const ViewOption DEFAULTS
Default combination of view options.
Easy-to use interface to the ZYPP dependency resolver.
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.