1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
12 Author: Michael Andres <ma@suse.de>
13 Maintainer: Michael Andres <ma@suse.de>
15 Purpose: Manage vendor attributes
24 #include "zypp/base/LogTools.h"
25 #include "zypp/base/IOStream.h"
26 #include "zypp/base/String.h"
28 #include "zypp/VendorAttr.h"
29 #include "zypp/ZYppFactory.h"
33 #undef ZYPP_BASE_LOGGER_LOGGROUP
34 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::VendorAttr"
36 ///////////////////////////////////////////////////////////////////
38 { /////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////
42 { /////////////////////////////////////////////////////////////////
44 typedef std::map<Vendor,bool> TrustMap;
47 typedef std::set<std::string> VendorList;
48 VendorList _trustedVendors;
50 bool addTrustedVendor( const std::string & str_r )
52 std::string line( str::trim( str_r ) );
53 if ( ! line.empty() && line[0] != '#')
55 _trustedVendors.insert( str::toLower( line ) );
60 bool trusted( const Vendor & vendor_r )
62 TrustMap::value_type val( vendor_r, false );
63 pair<TrustMap::iterator, bool> res = _trustMap.insert( val );
67 // check the new vendor in map
68 for ( VendorList::const_iterator it = _trustedVendors.begin();
69 it != _trustedVendors.end(); ++it )
71 if ( str::toLower( res.first->first.substr( 0, it->size() ) )
72 == str::toLower( *it ) )
75 res.first->second = true;
80 return res.first->second;
83 bool applyAutoProtection = true;
85 /////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////
89 const VendorAttr & VendorAttr::instance()
91 static VendorAttr _val;
95 VendorAttr::VendorAttr ()
104 "ati technologies inc.",
107 _trustedVendors.insert( vendors, vendors+(sizeof(vendors)/sizeof(char *)) );
109 Pathname vendorrcPath( getZYpp()->homePath() / "db/trustedVendors" );
112 Target_Ptr trg( getZYpp()->target() );
114 vendorrcPath = trg->root() / vendorrcPath;
118 // noop: Someone decided to let target() throw if the ptr is NULL ;(
121 PathInfo vendorrc( vendorrcPath );
122 if ( vendorrc.isFile() )
124 MIL << "Reading " << vendorrc << endl;
125 ifstream inp( vendorrc.asString().c_str() );
126 iostr::forEachLine( inp, addTrustedVendor );
128 MIL << "Trusted Vendors: " << _trustedVendors << endl;
131 void VendorAttr::enableAutoProtect()
133 MIL << "Foreign vendor auto protection enabled." << endl;
134 applyAutoProtection = true;
137 void VendorAttr::disableAutoProtect()
139 MIL << "Foreign vendor auto protection disabled." << endl;
140 applyAutoProtection = false;
143 bool VendorAttr::isKnown( const Vendor & vendor_r ) const
144 { return trusted( vendor_r ); }
147 bool VendorAttr::autoProtect( const Vendor & vendor_r ) const
148 { return( applyAutoProtection && ! trusted( vendor_r ) ); }
150 /////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////