15 #include <rpm/rpmcli.h>
16 #include <rpm/rpmlog.h>
32 #include <zypp-core/base/StringV.h>
33 #include <zypp/base/Logger.h>
34 #include <zypp/base/String.h>
35 #include <zypp/base/Gettext.h>
39 #include <zypp/Date.h>
40 #include <zypp/Pathname.h>
41 #include <zypp/PathInfo.h>
51 #include <zypp/TmpPath.h>
55 #include <zypp/base/IOTools.h>
60 #define WARNINGMAILPATH "/var/log/YaST2/"
61 #define FILEFORBACKUPFILES "YaSTBackupModifiedFiles"
62 #define MAXRPMMESSAGELINES 10000
64 #define WORKAROUNDRPMPWDBUG
66 #undef ZYPP_BASE_LOGGER_LOGGROUP
67 #define ZYPP_BASE_LOGGER_LOGGROUP "librpmDb"
71 namespace zypp_readonly_hack
79 static bool val = [](){
80 const char * env = getenv(
"ZYPP_RPM_DEBUG");
96 const char* quoteInFilename_m =
"\'\"";
98 const char* quoteInFilename_m =
" \t\'\"";
100 inline std::string rpmQuoteFilename(
const Pathname & path_r )
102 std::string path( path_r.
asString() );
104 pos != std::string::npos;
105 pos = path.find_first_of( quoteInFilename_m, pos ) )
107 path.insert( pos,
"\\" );
120 #if defined(WORKAROUNDRPMPWDBUG)
124 AutoDispose<char*> cwd( ::get_current_dir_name(), ::free );
127 WAR <<
"Can't get cwd!" << endl;
148 MIL <<
"trusted key added to zypp Keyring. Importing..." << endl;
149 _rpmdb.importPubkey( key );
154 MIL <<
"Trusted key removed from zypp Keyring. Removing..." << endl;
155 _rpmdb.removePubkey( key );
163 unsigned diffFiles(
const std::string file1,
const std::string file2, std::string& out,
int maxlines)
184 if (maxlines<0?
true:count<maxlines)
210 #define FAILIFNOTINITIALIZED if( ! initialized() ) { ZYPP_THROW(RpmDbNotOpenException()); }
221 : _backuppath (
"/var/adm/backup")
222 , _packagebackups(false)
229 setenv(
"RPM_IgnoreFailedSymlinks",
"1", 1 );
241 MIL <<
"~RpmDb()" << endl;
244 MIL <<
"~RpmDb() end" << endl;
270 bool quickinit( root_r.
empty() );
272 if ( root_r.
empty() )
280 if ( dbPath_r !=
"/var/lib/rpm" && !
PathInfo( root_r/
"/var/lib/rpm" ).isExist() )
282 WAR <<
"Inject missing /var/lib/rpm compat symlink to " << dbPath_r << endl;
296 if ( root_r ==
_root ) {
304 MIL <<
"Calling initDatabase: " <<
stringPath( root_r, dbPath_r )
305 << ( doRebuild_r ?
" (rebuilddb)" :
"" )
306 << ( quickinit ?
" (quickinit)" :
"" ) << endl;
315 MIL <<
"QUICK initDatabase (no systemRoot set)" << endl;
337 MIL <<
"Synchronizing keys with zypp keyring" << endl;
346 MIL <<
"InitDatabase: " << *
this << endl;
362 MIL <<
"Calling closeDatabase: " << *
this << endl;
374 MIL <<
"closeDatabase: " << *
this << endl;
404 MIL <<
"RpmDb::rebuildDatabase" << *
this << endl;
418 opts.push_back(
"--rebuilddb");
419 opts.push_back(
"-vv");
429 tics.
range( hdrTotal );
432 return report->progress( tics_r.
reportValue(), mydbpath );
440 static const std::string debugPrefix {
"D:" };
441 static const std::string progressPrefix {
"D: read h#" };
442 static const std::string ignoreSuffix {
"digest: OK" };
457 WAR <<
"User requested abort." << endl;
481 void computeKeyRingSync( std::set<Edition> & rpmKeys_r, std::list<PublicKeyData> & zyppKeys_r )
492 void updateIf(
const Edition & rpmKey_r )
494 std::string keyRelease( rpmKey_r.
release() );
495 int comp = _release.compare( keyRelease );
499 _release.swap( keyRelease );
500 _inRpmKeys = &rpmKey_r;
501 _inZyppKeys =
nullptr;
502 if ( !keyRelease.empty() )
503 DBG <<
"Old key in Z: gpg-pubkey-" << rpmKey_r.
version() <<
"-" << keyRelease << endl;
505 else if ( comp == 0 )
509 _inRpmKeys = &rpmKey_r;
513 DBG <<
"Old key in R: gpg-pubkey-" << rpmKey_r.
version() <<
"-" << keyRelease << endl;
516 void updateIf(
const PublicKeyData & zyppKey_r )
518 std::string keyRelease( zyppKey_r.gpgPubkeyRelease() );
519 int comp = _release.compare( keyRelease );
523 _release.swap( keyRelease );
524 _inRpmKeys =
nullptr;
525 _inZyppKeys = &zyppKey_r;
526 if ( !keyRelease.empty() )
527 DBG <<
"Old key in R: gpg-pubkey-" << zyppKey_r.gpgPubkeyVersion() <<
"-" << keyRelease << endl;
529 else if ( comp == 0 )
533 _inZyppKeys = &zyppKey_r;
537 DBG <<
"Old key in Z: gpg-pubkey-" << zyppKey_r.gpgPubkeyVersion() <<
"-" << keyRelease << endl;
540 std::string _release;
541 const Edition * _inRpmKeys;
542 const PublicKeyData * _inZyppKeys;
547 std::map<std::string,Key> _keymap;
549 for_( it, rpmKeys_r.begin(), rpmKeys_r.end() )
551 _keymap[(*it).version()].updateIf( *it );
554 for_( it, zyppKeys_r.begin(), zyppKeys_r.end() )
556 _keymap[(*it).gpgPubkeyVersion()].updateIf( *it );
560 std::set<Edition> rpmKeys;
561 std::list<PublicKeyData> zyppKeys;
562 for_( it, _keymap.begin(), _keymap.end() )
564 DBG <<
"gpg-pubkey-" << (*it).first <<
"-" << (*it).second._release <<
" "
565 << ( (*it).second._inRpmKeys ?
"R" :
"_" )
566 << ( (*it).second._inZyppKeys ?
"Z" :
"_" ) << endl;
567 if ( ! (*it).second._inRpmKeys )
569 zyppKeys.push_back( *(*it).second._inZyppKeys );
571 if ( ! (*it).second._inZyppKeys )
573 rpmKeys.insert( *(*it).second._inRpmKeys );
576 rpmKeys_r.swap( rpmKeys );
577 zyppKeys_r.swap( zyppKeys );
584 MIL <<
"Going to sync trusted keys..." << endl;
586 std::list<PublicKeyData> zyppKeys( getZYpp()->keyRing()->trustedPublicKeyData() );
598 MIL <<
"Removing excess keys in zypp trusted keyring" << std::endl;
604 if ( ! rpmKeys.count( keyData.gpgPubkeyEdition() ) )
606 DBG <<
"Excess key in Z to delete: gpg-pubkey-" << keyData.gpgPubkeyEdition() << endl;
607 getZYpp()->keyRing()->deleteKey( keyData.id(),
true );
608 if ( !dirty ) dirty =
true;
612 zyppKeys = getZYpp()->keyRing()->trustedPublicKeyData();
615 computeKeyRingSync( rpmKeys, zyppKeys );
616 MIL << (mode_r &
SYNC_TO_KEYRING ?
"" :
"(skip) ") <<
"Rpm keys to export into zypp trusted keyring: " << rpmKeys.size() << endl;
617 MIL << (mode_r &
SYNC_FROM_KEYRING ?
"" :
"(skip) ") <<
"Zypp trusted keys to import into rpm database: " << zyppKeys.size() << endl;
623 MIL <<
"Exporting rpm keyring into zypp trusted keyring" <<endl;
628 TmpFile tmpfile( getZYpp()->tmpPath() );
630 std::ofstream tmpos( tmpfile.
path().
c_str() );
631 for_( it, rpmKeys.begin(), rpmKeys.end() )
635 getData(
"gpg-pubkey", *it, result );
636 tmpos << result->tag_description() << endl;
641 getZYpp()->keyRing()->multiKeyImport( tmpfile.
path(),
true );
645 std::set<Edition> missingKeys;
646 for (
const Edition & key : rpmKeys )
648 if ( getZYpp()->keyRing()->isKeyTrusted( key.version() ) )
650 ERR <<
"Could not import key:" <<
str::Format(
"gpg-pubkey-%s") % key <<
" into zypp keyring (V3 key?)" << endl;
651 missingKeys.insert( key );
653 if ( ! missingKeys.empty() )
659 ERR <<
"Could not import keys into zypp keyring: " << endl;
667 MIL <<
"Importing zypp trusted keyring" << std::endl;
668 for_( it, zyppKeys.begin(), zyppKeys.end() )
672 importPubkey( getZYpp()->keyRing()->exportTrustedPublicKey( *it ) );
680 MIL <<
"Trusted keys synced." << endl;
702 WAR <<
"Key " << pubkey_r <<
" can not be imported. (READONLY MODE)" << endl;
709 bool hasOldkeys =
false;
711 for_( it, rpmKeys.begin(), rpmKeys.end() )
720 MIL <<
"Key " << pubkey_r <<
" is already in the rpm trusted keyring. (skip import)" << endl;
724 if ( keyEd.
version() != (*it).version() )
727 if ( keyEd.
release() < (*it).release() )
729 MIL <<
"Key " << pubkey_r <<
" is older than one in the rpm trusted keyring. (skip import)" << endl;
737 MIL <<
"Key " << pubkey_r <<
" will be imported into the rpm trusted keyring." << (hasOldkeys?
"(update)":
"(new)") << endl;
743 std::string keyName(
"gpg-pubkey-" + keyEd.
version() );
745 opts.push_back (
"-e" );
746 opts.push_back (
"--allmatches" );
747 opts.push_back (
"--" );
748 opts.push_back ( keyName.c_str() );
759 ERR <<
"Failed to remove key " << pubkey_r <<
" from RPM trusted keyring (ignored)" << endl;
763 MIL <<
"Key " << pubkey_r <<
" has been removed from RPM trusted keyring" << endl;
769 opts.push_back (
"--import" );
770 opts.push_back (
"--" );
772 opts.push_back ( pubkeypath.c_str() );
776 std::vector<std::string> excplines;
782 excplines.push_back( std::move(line) );
798 MIL <<
"Key " << pubkey_r <<
" imported in rpm trusted keyring." << endl;
815 std::set<Edition>::const_iterator found_edition = rpm_keys.end();
818 for_( it, rpm_keys.begin(), rpm_keys.end() )
820 if ( (*it).version() == pubkeyVersion )
828 if (found_edition == rpm_keys.end())
830 WAR <<
"Key " << pubkey_r.
id() <<
" is not in rpm db" << endl;
834 std::string rpm_name(
"gpg-pubkey-" + found_edition->asString());
837 opts.push_back (
"-e" );
838 opts.push_back (
"--" );
839 opts.push_back ( rpm_name.c_str() );
843 std::vector<std::string> excplines;
849 excplines.push_back( std::move(line) );
865 MIL <<
"Key " << pubkey_r <<
" has been removed from RPM trusted keyring" << endl;
877 std::list<PublicKey> ret;
880 for ( it.
findByName(
"gpg-pubkey" ); *it; ++it )
882 Edition edition = it->tag_edition();
887 getData(
"gpg-pubkey", edition, result );
888 TmpFile file(getZYpp()->tmpPath());
894 os << result->tag_description();
903 catch ( std::exception & e )
905 ERR <<
"Could not dump key " << edition.
asString() <<
" in tmp file " << file.
path() << endl;
915 std::set<Edition> ret;
918 for ( it.
findByName(
"gpg-pubkey" ); *it; ++it )
920 Edition edition = it->tag_edition();
922 ret.insert( edition );
939 std::list<FileInfo> result;
966 bool RpmDb::hasFile(
const std::string & file_r,
const std::string & name_r )
const
976 res = (it->tag_name() == name_r);
997 return it->tag_name();
1111 struct RpmlogCapture :
public std::string
1113 RpmlogCapture() :
_cap(this)
1115 rpmlogSetCallback( rpmLogCB,
this );
1116 _oldMask = rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(RPMLOG_INFO) ) );
1121 rpmlogSetCallback(
nullptr,
nullptr );
1125 static int rpmLogCB( rpmlogRec rec_r, rpmlogCallbackData data_r )
1126 {
return reinterpret_cast<RpmlogCapture*
>(data_r)->rpmLog( rec_r ); }
1128 int rpmLog( rpmlogRec rec_r )
1130 if (
_cap ) (*_cap) += rpmlogRecMessage( rec_r );
1141 bool requireGPGSig_r,
1142 RpmDb::CheckPackageDetail & detail_r )
1147 ERR <<
"Not a file: " << file << endl;
1151 FD_t fd = ::Fopen( file.
asString().c_str(),
"r.ufdio" );
1152 if ( fd == 0 || ::Ferror(fd) )
1154 ERR <<
"Can't open file for reading: " << file <<
" (" << ::Fstrerror(fd) <<
")" << endl;
1159 rpmts ts = ::rpmtsCreate();
1160 ::rpmtsSetRootDir( ts, root_r.
c_str() );
1161 ::rpmtsSetVSFlags( ts, RPMVSF_DEFAULT );
1163 rpmQVKArguments_s qva;
1164 memset( &qva, 0,
sizeof(rpmQVKArguments_s) );
1165 #ifndef HAVE_RPM_VERIFY_TRANSACTION_STEP
1168 qva.qva_flags = (VERIFY_DIGEST|VERIFY_SIGNATURE);
1170 ::rpmtsSetVfyFlags( ts, RPMVSF_DEFAULT );
1172 RpmlogCapture vresult;
1173 LocaleGuard guard( LC_ALL,
"C" );
1174 int res = ::rpmVerifySignatures( &qva, ts, fd, path_r.
basename().c_str() );
1187 std::vector<std::string> lines;
1188 str::split( vresult, std::back_inserter(lines),
"\n" );
1189 unsigned count[7] = { 0, 0, 0, 0, 0, 0, 0 };
1191 for (
unsigned i = 1; i < lines.size(); ++i )
1193 std::string & line( lines[i] );
1195 if ( line.find(
": OK" ) != std::string::npos )
1198 if ( line.find(
"Signature, key ID" ) == std::string::npos )
1201 else if ( line.find(
": NOKEY" ) != std::string::npos )
1203 else if ( line.find(
": BAD" ) != std::string::npos )
1205 else if ( line.find(
": UNKNOWN" ) != std::string::npos )
1207 else if ( line.find(
": NOTRUSTED" ) != std::string::npos )
1209 else if ( line.find(
": NOTFOUND" ) != std::string::npos )
1213 detail_r.push_back( RpmDb::CheckPackageDetail::value_type( lineres, std::move(line) ) );
1234 detail_r.push_back( RpmDb::CheckPackageDetail::value_type(
RpmDb::CHK_NOSIG, std::string(
" ")+
_(
"Package is not signed!") ) );
1235 if ( requireGPGSig_r )
1242 WAR << path_r <<
" (" << requireGPGSig_r <<
" -> " << ret <<
")" << endl;
1246 DBG << path_r <<
" [0-Signature is OK]" << endl;
1257 {
return doCheckPackageSig( path_r,
root(),
false, detail_r ); }
1263 {
return doCheckPackageSig( path_r,
root(),
true, detail_r ); }
1278 opts.push_back (
"-V");
1279 opts.push_back (
"--nodeps");
1280 opts.push_back (
"--noscripts");
1281 opts.push_back (
"--nomd5");
1282 opts.push_back (
"--");
1283 opts.push_back (packageName.c_str());
1304 if (line.length() > 12 &&
1305 (line[0] ==
'S' || line[0] ==
's' ||
1306 (line[0] ==
'.' && line[7] ==
'T')))
1309 std::string filename;
1311 filename.assign(line, 11, line.length() - 11);
1351 #if defined(WORKAROUNDRPMPWDBUG)
1352 args.push_back(
"#/");
1354 args.push_back(
"rpm");
1355 args.push_back(
"--root");
1357 args.push_back(
"--dbpath");
1360 args.push_back(
"-vv");
1361 const char* argv[args.size() + opts.size() + 1];
1363 const char** p = argv;
1364 p =
copy (args.begin (), args.end (), p);
1365 p =
copy (opts.begin (), opts.end (), p);
1395 const auto &readResult =
io::receiveUpto( inputfile,
'\n', 5 * 1000,
false );
1396 switch ( readResult.first ) {
1402 line += readResult.second;
1406 line += readResult.second;
1407 if ( line.size() && line.back() ==
'\n')
1412 line += readResult.second;
1414 if ( line.size() && line.back() ==
'\n')
1418 L_DBG(
"RPM_DEBUG") << line << endl;
1462 void RpmDb::processConfigFiles(
const std::string& line,
const std::string& name,
const char* typemsg,
const char* difffailmsg,
const char* diffgenmsg)
1464 std::string msg = line.substr(9);
1467 std::string file1s, file2s;
1471 pos1 = msg.find (typemsg);
1474 if ( pos1 == std::string::npos )
1477 pos2 = pos1 + strlen (typemsg);
1479 if (pos2 >= msg.length() )
1482 file1 = msg.substr (0, pos1);
1483 file2 = msg.substr (pos2);
1490 file1 =
_root + file1;
1491 file2 =
_root + file2;
1501 ERR <<
"Could not create " << file.
asString() << endl;
1505 std::ofstream notify(file.
asString().c_str(), std::ios::out|std::ios::app);
1508 ERR <<
"Could not open " << file << endl;
1514 notify <<
str::form(
_(
"Changed configuration files for %s:"), name.c_str()) << endl;
1517 ERR <<
"diff failed" << endl;
1519 file1s.c_str(), file2s.c_str()) << endl;
1524 file1s.c_str(), file2s.c_str()) << endl;
1529 if (out.substr(0,4) ==
"--- ")
1531 out.replace(4, file1.
asString().length(), file1s);
1534 if (pos != std::string::npos)
1536 out.replace(pos+5, file2.
asString().length(), file2s);
1539 notify << out << endl;
1542 notify.open(
"/var/lib/update-messages/yast2-packagemanager.rpmdb.configfiles");
1547 WAR <<
"rpm created " << file2 <<
" but it is not different from " << file2 << endl;
1563 report->start(filename);
1578 report->finish( excpt_r );
1594 MIL <<
"RpmDb::installPackage(" << filename <<
"," << flags <<
")" << endl;
1602 ERR <<
"backup of " << filename.
asString() <<
" failed" << endl;
1605 report->progress( 0 );
1611 opts.push_back(
"-i");
1613 opts.push_back(
"-U");
1615 opts.push_back(
"--percent");
1616 opts.push_back(
"--noglob");
1620 opts.push_back(
"--ignorearch");
1623 opts.push_back(
"--nodigest");
1625 opts.push_back(
"--nosignature");
1627 opts.push_back (
"--excludedocs");
1629 opts.push_back (
"--noscripts");
1631 opts.push_back (
"--force");
1633 opts.push_back (
"--nodeps");
1635 opts.push_back (
"--ignoresize");
1637 opts.push_back (
"--justdb");
1639 opts.push_back (
"--test");
1641 opts.push_back (
"--noposttrans");
1643 opts.push_back(
"--");
1646 std::string quotedFilename( rpmQuoteFilename( workaroundRpmPwdBug( filename ) ) );
1647 opts.push_back ( quotedFilename.c_str() );
1652 unsigned lineno = 0;
1655 cmdout.
set(
"line", std::cref(line) );
1656 cmdout.
set(
"lineno", lineno );
1660 std::vector<std::string> configwarnings;
1667 sscanf( line.c_str() + 2,
"%d", &percent );
1668 report->progress( percent );
1672 cmdout.
set(
"lineno", lineno );
1673 report->report( cmdout );
1676 if ( line.find(
" scriptlet failed, " ) == std::string::npos )
1680 rpmmsg += line+
'\n';
1683 configwarnings.push_back(line);
1686 rpmmsg +=
"[truncated]\n";
1691 for (std::vector<std::string>::iterator it = configwarnings.begin();
1692 it != configwarnings.end(); ++it)
1696 _(
"rpm saved %s as %s, but it was impossible to determine the difference"),
1698 _(
"rpm saved %s as %s.\nHere are the first 25 lines of difference:\n"));
1701 _(
"rpm created %s as %s, but it was impossible to determine the difference"),
1703 _(
"rpm created %s as %s.\nHere are the first 25 lines of difference:\n"));
1706 if ( rpm_status != 0 )
1711 std::ostringstream sstr;
1712 sstr <<
"rpm output:" << endl << rpmmsg << endl;
1713 historylog.
comment(sstr.str());
1717 else if ( ! rpmmsg.empty() )
1722 std::ostringstream sstr;
1723 sstr <<
"Additional rpm output:" << endl << rpmmsg << endl;
1724 historylog.
comment(sstr.str());
1728 report->finishInfo(
str::form(
"%s:\n%s\n",
_(
"Additional rpm output"), rpmmsg.c_str() ));
1742 +
"-" + package->edition().version()
1743 +
"-" + package->edition().release()
1744 +
"." + package->arch().asString(), flags );
1757 report->start( name_r );
1772 report->finish( excpt_r );
1789 MIL <<
"RpmDb::doRemovePackage(" << name_r <<
"," << flags <<
")" << endl;
1798 ERR <<
"backup of " << name_r <<
" failed" << endl;
1800 report->progress( 0 );
1804 report->progress( 100 );
1809 opts.push_back(
"-e");
1810 opts.push_back(
"--allmatches");
1813 opts.push_back(
"--noscripts");
1815 opts.push_back(
"--nodeps");
1817 opts.push_back(
"--justdb");
1819 opts.push_back (
"--test");
1822 WAR <<
"IGNORE OPTION: 'rpm -e' does not support '--force'" << endl;
1825 opts.push_back(
"--");
1826 opts.push_back(name_r.c_str());
1831 unsigned lineno = 0;
1834 cmdout.
set(
"line", std::cref(line) );
1835 cmdout.
set(
"lineno", lineno );
1845 report->progress( 5 );
1849 cmdout.
set(
"lineno", lineno );
1850 report->report( cmdout );
1853 if ( line.find(
" scriptlet failed, " ) == std::string::npos )
1856 rpmmsg += line+
'\n';
1859 rpmmsg +=
"[truncated]\n";
1860 report->progress( 50 );
1863 if ( rpm_status != 0 )
1866 str::form(
"%s remove failed", name_r.c_str()),
true );
1867 std::ostringstream sstr;
1868 sstr <<
"rpm output:" << endl << rpmmsg << endl;
1869 historylog.
comment(sstr.str());
1873 else if ( ! rpmmsg.empty() )
1876 str::form(
"%s removed ok", name_r.c_str()),
true );
1878 std::ostringstream sstr;
1879 sstr <<
"Additional rpm output:" << endl << rpmmsg << endl;
1880 historylog.
comment(sstr.str());
1884 report->finishInfo(
str::form(
"%s:\n%s\n",
_(
"Additional rpm output"), rpmmsg.c_str() ));
1918 INT <<
"_backuppath empty" << endl;
1926 ERR <<
"Error while getting changed files for package " <<
1927 packageName << endl;
1933 DBG <<
"package " << packageName <<
" not changed -> no backup" << endl;
1945 struct tm *currentLocalTime = localtime(&
currentTime);
1947 int date = (currentLocalTime->tm_year + 1900) * 10000
1948 + (currentLocalTime->tm_mon + 1) * 100
1949 + currentLocalTime->tm_mday;
1955 +
str::form(
"%s-%d-%d.tar.gz",packageName.c_str(), date, num);
1958 while (
PathInfo(backupFilename).isExist() && num++ < 1000);
1963 ERR << filestobackupfile.
asString() <<
" already exists and is no file" << endl;
1967 std::ofstream fp ( filestobackupfile.
asString().c_str(), std::ios::out|std::ios::trunc );
1971 ERR <<
"could not open " << filestobackupfile.
asString() << endl;
1975 for (FileList::const_iterator cit =
fileList.begin();
1978 std::string name = *cit;
1979 if ( name[0] ==
'/' )
1982 name = name.substr( 1 );
1984 DBG <<
"saving file "<< name << endl;
1989 const char*
const argv[] =
1995 "--ignore-failed-read",
1999 filestobackupfile.
asString().c_str(),
2015 int ret = tar.
close();
2019 ERR <<
"tar failed: " << tarmsg << endl;
2024 MIL <<
"tar backup ok" << endl;
2045 #define OUTS(E,S) case RpmDb::E: return str << "["<< (unsigned)obj << "-"<< S << "]"; break
2047 OUTS( CHK_OK,
_(
"Signature is OK") );
2049 OUTS( CHK_NOTFOUND,
_(
"Unknown type of signature") );
2051 OUTS( CHK_FAIL,
_(
"Signature does not verify") );
2053 OUTS( CHK_NOTTRUSTED,
_(
"Signature is OK, but key is not trusted") );
2055 OUTS( CHK_NOKEY,
_(
"Signatures public key is not available") );
2057 OUTS( CHK_ERROR,
_(
"File does not exist or signature can't be checked") );
2059 OUTS( CHK_NOSIG,
_(
"File is unsigned") );
2067 for (
const auto & el : obj )
2068 str << el.second << endl;
#define MAXRPMMESSAGELINES
#define FAILIFNOTINITIALIZED
#define FILEFORBACKUPFILES
Store and operate on date (time_t).
std::string form(const std::string &format_r) const
Return string representation according to format as localtime.
static Date now()
Return the current time.
Assign a vaiable a certain value when going out of scope.
Edition represents [epoch:]version[-release]
std::string version() const
Version.
std::string release() const
Release.
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Base class for Exception.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
void addHistory(const std::string &msg_r)
Add some message text to the history.
void moveToHistory(TContainer &&msgc_r)
addHistory from string container types (oldest first) moving
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
bool kill()
Kill the program.
const std::string & execError() const
Some detail telling why the execution failed, if it failed.
bool running()
Return whether program is running.
int close()
Wait for the progamm to complete.
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
Writing the zypp history file.
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
std::string asString() const
TraitsType::constPtrType constPtr
Maintain [min,max] and counter (value) for progress counting.
value_type reportValue() const
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
bool toMax()
Set counter value to current max value (unless no range).
bool incr(value_type val_r=1)
Increment counter value (default by 1).
bool toMin()
Set counter value to current min value.
void range(value_type max_r)
Set new [0,max].
Class representing one GPG Public Keys data.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Pathname path() const
File containing the ASCII armored key.
std::string gpgPubkeyRelease() const
std::string asString() const
std::string gpgPubkeyVersion() const
bool hasSubkeys() const
!<
static ZConfig & instance()
Singleton ctor.
Typesafe passing of user data via callbacks.
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
zypp::ContentType ContentType
FILE * inputFile() const
Return the input stream.
void setBlocking(bool mode)
Set the blocking mode of the input stream.
std::string receiveLine()
Read one line from the input stream.
Wrapper class for ::stat/::lstat.
const std::string & asString() const
Return current Pathname as String.
bool isExist() const
Return whether valid stat info exists.
const std::string & asString() const
String representation.
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.
bool relative() const
Test for a relative path.
Provide a new empty temporary file and delete it when no longer needed.
Interface to the rpm program.
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
std::string error_message
Error message from running rpm as external program.
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
std::string whoOwnsFile(const std::string &file_r) const
Return name of package owning file or empty string if no installed package owns file.
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Pathname _backuppath
/var/adm/backup
void run_rpm(const RpmArgVec &options, ExternalProgram::Stderr_Disposition stderr_disp=ExternalProgram::Stderr_To_Stdout)
Run rpm with the specified arguments and handle stderr.
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database below root_r.
ExternalProgram * process
The connection to the rpm process.
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done.
CheckPackageResult checkPackageSignature(const Pathname &path_r, CheckPackageDetail &detail_r)
Check signature of rpm file on disk (strict check returning CHK_NOSIG if file is unsigned).
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
void systemKill()
Forcably kill the system process.
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
std::list< FileInfo > fileList(const std::string &name_r, const Edition &edition_r) const
return complete file list for installed package name_r (in FileInfo.filename) if edition_r !...
Pathname _dbPath
Directory that contains the rpmdb.
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
void setBackupPath(const Pathname &path)
set path where package backups are stored
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
bool _packagebackups
create package backups?
CheckPackageResult checkPackage(const Pathname &path_r, CheckPackageDetail &detail_r)
Check signature of rpm file on disk (legacy version returning CHK_OK if file is unsigned,...
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
Pathname _root
Root directory for all operations.
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
const Pathname & dbPath() const
std::vector< const char * > RpmArgVec
int exit_code
The exit code of the rpm process, or -1 if not yet known.
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
void processConfigFiles(const std::string &line, const std::string &name, const char *typemsg, const char *difffailmsg, const char *diffgenmsg)
handle rpm messages like "/etc/testrc saved as /etc/testrc.rpmorig"
const Pathname & root() const
CheckPackageResult
checkPackage result
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
std::set< std::string > FileList
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
bool hasFile(const std::string &file_r, const std::string &name_r="") const
Return true if at least one package owns a certain file (name_r empty) Return true if package name_r ...
Just inherits Exception to separate media exceptions.
Subclass to retrieve database content.
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
bool findPackage(const std::string &name_r)
Find package by name.
shared_ptr< RpmException > dbError() const
Return any database error.
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
static void dbAccess()
Access the database at the current default location.
static unsigned blockAccess()
Blocks further access to rpmdb.
static Pathname suggestedDbPath(const Pathname &root_r)
static void unblockAccess()
Allow access to rpmdb e.g.
String related utilities and Regular expression matching.
Types and functions for filesystem operations.
Pathname expandlink(const Pathname &path_r)
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or dir...
int unlink(const Pathname &path)
Like 'unlink'.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
std::pair< ReceiveUpToResult, std::string > receiveUpto(FILE *file, char c, timeout_type timeout, bool failOnUnblockError)
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
std::string numstring(char n, int w=0)
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
static shared_ptr< KeyRingSignalReceiver > sKeyRingReceiver
std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
unsigned diffFiles(const std::string file1, const std::string file2, std::string &out, int maxlines)
Easy-to use interface to the ZYPP dependency resolver.
Temporarily connect a ReceiveReport then restore the previous one.
static const UserData::ContentType contentRpmout
"rpmout/installpkg": Additional rpm output (sent immediately).
virtual void trustedKeyRemoved(const PublicKey &key)
virtual void trustedKeyAdded(const PublicKey &key)
KeyRingSignalReceiver(RpmDb &rpmdb)
static const UserData::ContentType contentRpmout
"rpmout/removepkg": Additional rpm output (sent immediately).
Detailed rpm signature check log messages A single multiline message if CHK_OK.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.