summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-06-22 12:34:11 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-08-10 17:25:26 +0200
commit268ffcebb9ae4278b1e3c3f89f8167f229164dbd (patch)
treecd8e03aa1e1743481e05fe1195c1d4f3ce78e125 /apt-pkg
parent81460e32961bb0b9922bf8a1a27d87705d8c3e51 (diff)
detect and error out on conflicting Trusted settings
A specific trust state can be enforced via a sources.list option, but it effects all entries handled by the same Release file, not just the entry it was given on so we enforce acknowledgement of this by requiring the same value to be (not) set on all such entries.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/debmetaindex.cc43
-rw-r--r--apt-pkg/deb/debmetaindex.h8
-rw-r--r--apt-pkg/metaindex.cc2
-rw-r--r--apt-pkg/metaindex.h1
4 files changed, 34 insertions, 20 deletions
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index f690a8d64..1f725ba05 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -29,6 +29,8 @@
#include <unistd.h>
#include <string.h>
+#include <apti18n.h>
+
class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
{
public:
@@ -42,6 +44,11 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
std::vector<debSectionEntry> DebEntries;
std::vector<debSectionEntry> DebSrcEntries;
+
+ debReleaseIndex::TriState Trusted;
+
+ debReleaseIndexPrivate() : Trusted(debReleaseIndex::TRI_UNSET) {}
+ debReleaseIndexPrivate(bool const pTrusted) : Trusted(pTrusted ? debReleaseIndex::TRI_YES : debReleaseIndex::TRI_NO) {}
};
/*}}}*/
// ReleaseIndex::MetaIndex* - display helpers /*{{{*/
@@ -101,12 +108,11 @@ std::string debReleaseIndex::LocalFileName() const /*{{{*/
/*}}}*/
// ReleaseIndex Con- and Destructors /*{{{*/
debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) :
- metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()), Trusted(CHECK_TRUST)
+ metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
{}
debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted) :
- metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) {
- SetTrusted(Trusted);
-}
+ metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate(Trusted))
+{}
debReleaseIndex::~debReleaseIndex() {
if (d != NULL)
delete d;
@@ -225,9 +231,9 @@ void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{
bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{{{*/
{
indexRecords * const iR = new indexRecords(Dist);
- if (Trusted == ALWAYS_TRUSTED)
+ if (d->Trusted == TRI_YES)
iR->SetTrusted(true);
- else if (Trusted == NEVER_TRUSTED)
+ else if (d->Trusted == TRI_NO)
iR->SetTrusted(false);
// special case for --print-uris
@@ -246,19 +252,21 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{
return true;
}
/*}}}*/
-// ReleaseIndex::*Trusted setters and checkers /*{{{*/
-void debReleaseIndex::SetTrusted(bool const Trusted)
+// ReleaseIndex::IsTrusted /*{{{*/
+bool debReleaseIndex::SetTrusted(TriState const Trusted)
{
- if (Trusted == true)
- this->Trusted = ALWAYS_TRUSTED;
- else
- this->Trusted = NEVER_TRUSTED;
+ if (d->Trusted == TRI_UNSET)
+ d->Trusted = Trusted;
+ else if (d->Trusted != Trusted)
+ // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
+ return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str());
+ return true;
}
bool debReleaseIndex::IsTrusted() const
{
- if (Trusted == ALWAYS_TRUSTED)
+ if (d->Trusted == TRI_YES)
return true;
- else if (Trusted == NEVER_TRUSTED)
+ else if (d->Trusted == TRI_NO)
return false;
@@ -476,7 +484,12 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
std::map<std::string, std::string>::const_iterator const trusted = Options.find("trusted");
if (trusted != Options.end())
- Deb->SetTrusted(StringToBool(trusted->second, false));
+ {
+ if (Deb->SetTrusted(StringToBool(trusted->second, false) ? debReleaseIndex::TRI_YES : debReleaseIndex::TRI_NO) == false)
+ return false;
+ }
+ else if (Deb->SetTrusted(debReleaseIndex::TRI_DONTCARE) == false)
+ return false;
return true;
}
diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h
index 9b60b6137..a6db4e287 100644
--- a/apt-pkg/deb/debmetaindex.h
+++ b/apt-pkg/deb/debmetaindex.h
@@ -27,8 +27,6 @@ class APT_HIDDEN debReleaseIndex : public metaIndex
{
debReleaseIndexPrivate * const d;
- enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted;
-
public:
APT_HIDDEN std::string MetaIndexInfo(const char *Type) const;
@@ -51,7 +49,11 @@ class APT_HIDDEN debReleaseIndex : public metaIndex
virtual std::vector <pkgIndexFile *> *GetIndexFiles();
- void SetTrusted(bool const Trusted);
+ enum APT_HIDDEN TriState {
+ TRI_YES, TRI_DONTCARE, TRI_NO, TRI_UNSET
+ };
+ bool SetTrusted(TriState const Trusted);
+
virtual bool IsTrusted() const;
void AddComponent(bool const isSrc, std::string const &Name,
diff --git a/apt-pkg/metaindex.cc b/apt-pkg/metaindex.cc
index d96349974..0c88ee9cd 100644
--- a/apt-pkg/metaindex.cc
+++ b/apt-pkg/metaindex.cc
@@ -41,7 +41,7 @@ bool metaIndex::Merge(pkgCacheGenerator &Gen,OpProgress *) const
metaIndex::metaIndex(std::string const &URI, std::string const &Dist,
char const * const Type)
-: d(NULL), Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(false)
+: d(NULL), Indexes(NULL), Type(Type), URI(URI), Dist(Dist)
{
/* nothing */
}
diff --git a/apt-pkg/metaindex.h b/apt-pkg/metaindex.h
index 1bcec1c4a..9667e1c92 100644
--- a/apt-pkg/metaindex.h
+++ b/apt-pkg/metaindex.h
@@ -34,7 +34,6 @@ class metaIndex
const char *Type;
std::string URI;
std::string Dist;
- bool Trusted;
public: