From b18fb1053c86aef4ea34d899ff1134cd9c4d0b07 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 9 Sep 2008 09:44:45 +0000 Subject: [PATCH] - Fix reading of Traget::targetDistribution. - Allow to configure default answers in signature verification workflow. --- devel/devel.ma/NewPool.cc | 43 ++++++++------------------------------- package/libzypp.changes | 7 +++++++ zypp/KeyRing.cc | 25 +++++++++++++++++------ zypp/KeyRing.h | 51 ++++++++++++++++++++++++++++++++++++++++------- zypp/target/TargetImpl.cc | 33 +++++++++++++++--------------- 5 files changed, 94 insertions(+), 65 deletions(-) diff --git a/devel/devel.ma/NewPool.cc b/devel/devel.ma/NewPool.cc index c6ce7e6..eeb2f24 100644 --- a/devel/devel.ma/NewPool.cc +++ b/devel/devel.ma/NewPool.cc @@ -445,15 +445,21 @@ try { ResPool pool( ResPool::instance() ); sat::Pool satpool( sat::Pool::instance() ); + Edition e("1.a"); + DBG << e.copmpare( Edition("1a") ) << endl; + DBG << e.copmpare( Edition("1=a") ) << endl; + DBG << e.copmpare( Edition("1#$%^&*()_a") ) << endl; +return 0; if ( 1 ) { Measure x( "INIT TARGET" ); { { - //zypp::base::LogControl::TmpLineWriter shutUp; + zypp::base::LogControl::TmpLineWriter shutUp; getZYpp()->initializeTarget( sysRoot ); } getZYpp()->target()->load(); + USR << getZYpp()->target()->targetDistribution() << endl; } } @@ -479,7 +485,7 @@ try { repoManager.cleanCache( nrepo ); } SEC << "refreshMetadata" << endl; - repoManager.refreshMetadata( nrepo ); + //repoManager.refreshMetadata( nrepo ); SEC << "buildCache" << endl; repoManager.buildCache( nrepo ); } @@ -529,39 +535,6 @@ try { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // access to the Pool of Selectables - ResPoolProxy selectablePool( ResPool::instance().proxy() ); - - // Iterate it's Products... - for_( it, selectablePool.byKindBegin(), selectablePool.byKindEnd() ) - { - // The current Product Selectable - ui::Selectable::Ptr prodSel( *it ); - MIL << dump( prodSel ) << endl; - - // It's candiate as Product pointer - Product::constPtr prod( prodSel->candidateAsKind() ); - if ( prod ) - { - // Not NULL, so there is an available Product. - // Get the installed Products it would replace. - Product::ReplacedProducts prodReplaces( prod->replacedProducts() ); - - // Iterate the replaced Products... - for_( it, prodReplaces.begin(), prodReplaces.end() ) - { - // The current replaced Product - Product::constPtr replacedProduct( *it ); - DBG << replacedProduct << endl; - - // and this is how you would get the Selectable that contains - // this replacedProduct, in case you need it .. - ui::Selectable::Ptr replacedProductsSelectable( ui::Selectable::get( replacedProduct ) ); - DBG << replacedProductsSelectable << endl; - } - } - - } /////////////////////////////////////////////////////////////////// diff --git a/package/libzypp.changes b/package/libzypp.changes index 4f57805..e6bbcd0 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Tue Sep 9 11:40:42 CEST 2008 - ma@suse.de + +- Fix reading of Traget::targetDistribution. +- Allow to configure default answers in signature verification workflow. +- revision 10968 + +------------------------------------------------------------------- Mon Sep 8 17:11:02 CEST 2008 - jkupec@suse.cz - CredentialManager added to manage stored credentials diff --git a/zypp/KeyRing.cc b/zypp/KeyRing.cc index bdc2e23..ec80891 100644 --- a/zypp/KeyRing.cc +++ b/zypp/KeyRing.cc @@ -51,25 +51,38 @@ namespace zypp return true; } + /////////////////////////////////////////////////////////////////// + namespace { - bool _keyRingDefaultAccept( getenv("ZYPP_KEYRING_DEFAULT_ACCEPT_ALL") ); + KeyRingReport::DefaultAccept _keyRingDefaultAccept( KeyRingReport::ACCEPT_NOTHING ); } - bool KeyRingReport::askUserToAcceptUnsignedFile( const string &file ) + KeyRingReport::DefaultAccept KeyRingReport::defaultAccept() { return _keyRingDefaultAccept; } + void KeyRingReport::setDefaultAccept( DefaultAccept value_r ) + { + MIL << "Set new default accept: " << value_r << endl; + _keyRingDefaultAccept = value_r; + } + + /////////////////////////////////////////////////////////////////// + + bool KeyRingReport::askUserToAcceptUnsignedFile( const string &file ) + { return _keyRingDefaultAccept.testFlag( ACCEPT_UNSIGNED_FILE ); } + bool KeyRingReport::askUserToAcceptUnknownKey( const string &file, const string &id ) - { return _keyRingDefaultAccept; } + { return _keyRingDefaultAccept.testFlag( ACCEPT_UNKNOWNKEY ); } bool KeyRingReport::askUserToTrustKey( const PublicKey &key ) - { return _keyRingDefaultAccept; } + { return _keyRingDefaultAccept.testFlag( TRUST_KEY ); } bool KeyRingReport::askUserToImportKey( const PublicKey &key) - { return _keyRingDefaultAccept; } + { return _keyRingDefaultAccept.testFlag( IMPORT_KEY ); } bool KeyRingReport::askUserToAcceptVerificationFailed( const string &file, const PublicKey &key ) - { return _keyRingDefaultAccept; } + { return _keyRingDefaultAccept.testFlag( ACCEPT_VERIFICATION_FAILED ); } /////////////////////////////////////////////////////////////////// // diff --git a/zypp/KeyRing.h b/zypp/KeyRing.h index 0c47558..f44cd55 100644 --- a/zypp/KeyRing.h +++ b/zypp/KeyRing.h @@ -19,6 +19,7 @@ #include #include "zypp/base/ReferenceCounted.h" +#include "zypp/base/Flags.h" #include "zypp/Callback.h" #include "zypp/base/PtrTypes.h" #include "zypp/Locale.h" @@ -30,6 +31,10 @@ namespace zypp DEFINE_PTR_TYPE(KeyRing); + /** Callbacks from signature verification workflow. + * + * Per default all methods answer \c false. + */ struct KeyRingReport : public callback::ReportBase { @@ -59,7 +64,30 @@ namespace zypp */ virtual bool askUserToImportKey( const PublicKey &key); virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key ); + + public: + /** \name Query/change the default values. + * Per default all methods answer \c false. + */ + //@{ + enum DefaultAcceptBits + { + ACCEPT_NOTHING = 0x0000, + ACCEPT_UNSIGNED_FILE = 0x0001, + ACCEPT_UNKNOWNKEY = 0x0002, + TRUST_KEY = 0x0004, + IMPORT_KEY = 0x0008, + ACCEPT_VERIFICATION_FAILED = 0x0010, + }; + ZYPP_DECLARE_FLAGS(DefaultAccept,DefaultAcceptBits); + + /** Get the active accept bits. */ + static DefaultAccept defaultAccept(); + /** Set the active accept bits. */ + static void setDefaultAccept( DefaultAccept value_r ); + //@} }; + ZYPP_DECLARE_OPERATORS_FOR_FLAGS(KeyRingReport::DefaultAccept); struct KeyRingSignals : public callback::ReportBase { @@ -167,20 +195,29 @@ namespace zypp /** * Follows a signature verification interacting with the user. * The bool returned depends on user decision to trust or not. + * + * To propagate user decisions, either connect to the \ref KeyRingReport + * or use its static methods to set the desired defaults. + * + * \code + * struct KeyRingReportReceive : public callback::ReceiveReport + * { + * KeyRingReportReceive() { connect(); } + * + * // Overload the virtual methods to return the appropriate values. + * virtual bool askUserToAcceptUnsignedFile( const std::string &file ); + * ... + * }; + * \endcode + * \see \ref KeyRingReport */ bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature); bool verifyFileSignature( const Pathname &file, const Pathname &signature); bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature); -/** Dtor */ + /** Dtor */ ~KeyRing(); - public: - - /** Synonym for \ref text */ - //std::string asString() const - //{} - private: /** Pointer to implementation */ RWCOW_pointer _pimpl; diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index caab401..3cd76eb 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -879,25 +879,24 @@ namespace zypp std::string TargetImpl::targetDistribution() const { - std::ifstream baseProduct( (_root / "/etc/products.d/baseproduct").c_str() ); - for( iostr::EachLine in( baseProduct ); in; in.next() ) + std::ostringstream cmd; + cmd << "rpmdb2solv"; + cmd << " -n"; + if ( ! _root.empty() ) + cmd << " -r '" << _root << "'"; + cmd << " -p '" << Pathname::assertprefix( _root, "/etc/products.d" ) << "'"; + cmd << " -a distribution.target"; + + MIL << "Executing: " << cmd << endl; + ExternalProgram prog( cmd.str(), ExternalProgram::Discard_Stderr ); + for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) { - std::string line( str::trim( *in ) ); - if ( str::hasPrefix( line, "distribution" ) ) - { - std::string::size_type pos( line.find( '=', 12 ) ); - if ( pos == std::string::npos ) - continue; // no '=' on line - pos = line.find_first_not_of( " \t", pos+1 ); - if ( pos == std::string::npos ) - continue; // empty value - line.erase( 0, pos ); - line += "-"; - line += ZConfig::instance().systemArchitecture().asString(); - return line; - } + return str::trim(output); } - WAR << "No distribution in " << PathInfo(_root / "/etc/products.d/baseproduct") << endl; + + int ret = prog.close(); + WAR << "Got no output from rpmdb2solv (returned " << ret << ")." << endl; + return std::string(); } -- 2.7.4