Просмотр исходного кода

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.
David Kalnischkies лет назад: 11
Родитель
Сommit
268ffcebb9

+ 28 - 15
apt-pkg/deb/debmetaindex.cc

@@ -29,6 +29,8 @@
 #include <unistd.h>
 #include <unistd.h>
 #include <string.h>
 #include <string.h>
 
 
+#include <apti18n.h>
+
 class APT_HIDDEN debReleaseIndexPrivate					/*{{{*/
 class APT_HIDDEN debReleaseIndexPrivate					/*{{{*/
 {
 {
    public:
    public:
@@ -42,6 +44,11 @@ class APT_HIDDEN debReleaseIndexPrivate					/*{{{*/
 
 
    std::vector<debSectionEntry> DebEntries;
    std::vector<debSectionEntry> DebEntries;
    std::vector<debSectionEntry> DebSrcEntries;
    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				/*{{{*/
 // ReleaseIndex::MetaIndex* - display helpers				/*{{{*/
@@ -101,12 +108,11 @@ std::string debReleaseIndex::LocalFileName() const			/*{{{*/
 									/*}}}*/
 									/*}}}*/
 // ReleaseIndex Con- and Destructors					/*{{{*/
 // ReleaseIndex Con- and Destructors					/*{{{*/
 debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) :
 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) :
 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() {
 debReleaseIndex::~debReleaseIndex() {
    if (d != NULL)
    if (d != NULL)
       delete d;
       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/*{{{*/
 bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{{{*/
 {
 {
    indexRecords * const iR = new indexRecords(Dist);
    indexRecords * const iR = new indexRecords(Dist);
-   if (Trusted == ALWAYS_TRUSTED)
+   if (d->Trusted == TRI_YES)
       iR->SetTrusted(true);
       iR->SetTrusted(true);
-   else if (Trusted == NEVER_TRUSTED)
+   else if (d->Trusted == TRI_NO)
       iR->SetTrusted(false);
       iR->SetTrusted(false);
 
 
    // special case for --print-uris
    // special case for --print-uris
@@ -246,19 +252,21 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{
    return true;
    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
 bool debReleaseIndex::IsTrusted() const
 {
 {
-   if (Trusted == ALWAYS_TRUSTED)
+   if (d->Trusted == TRI_YES)
       return true;
       return true;
-   else if (Trusted == NEVER_TRUSTED)
+   else if (d->Trusted == TRI_NO)
       return false;
       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");
       std::map<std::string, std::string>::const_iterator const trusted = Options.find("trusted");
       if (trusted != Options.end())
       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;
       return true;
    }
    }

+ 5 - 3
apt-pkg/deb/debmetaindex.h

@@ -27,8 +27,6 @@ class APT_HIDDEN debReleaseIndex : public metaIndex
 {
 {
    debReleaseIndexPrivate * const d;
    debReleaseIndexPrivate * const d;
 
 
-   enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted;
-
    public:
    public:
 
 
    APT_HIDDEN std::string MetaIndexInfo(const char *Type) const;
    APT_HIDDEN std::string MetaIndexInfo(const char *Type) const;
@@ -51,7 +49,11 @@ class APT_HIDDEN debReleaseIndex : public metaIndex
 
 
    virtual std::vector <pkgIndexFile *> *GetIndexFiles();
    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;
    virtual bool IsTrusted() const;
 
 
    void AddComponent(bool const isSrc, std::string const &Name,
    void AddComponent(bool const isSrc, std::string const &Name,

+ 1 - 1
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,
 metaIndex::metaIndex(std::string const &URI, std::string const &Dist,
       char const * const Type)
       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 */
    /* nothing */
 }
 }

+ 0 - 1
apt-pkg/metaindex.h

@@ -34,7 +34,6 @@ class metaIndex
    const char *Type;
    const char *Type;
    std::string URI;
    std::string URI;
    std::string Dist;
    std::string Dist;
-   bool Trusted;
 
 
    public:
    public:
 
 

+ 8 - 0
doc/sources.list.5.xml

@@ -223,7 +223,15 @@ deb-src [ option1=value1 option2=value2 ] uri suite [component1] [component2] [.
 		source. If not specified, the default set is defined by the
 		source. If not specified, the default set is defined by the
 		<literal>APT::Acquire::Targets</literal> configuration scope.
 		<literal>APT::Acquire::Targets</literal> configuration scope.
 	  </para></listitem>
 	  </para></listitem>
+       </itemizedlist>
+
+       Further more, there are options which if set effect
+       <emphasis>all</emphasis> sources with the same URI and Suite, so they
+       have to be set on all such entries and can not be varied between
+       different components. APT will try to detect and error out on such
+       anomalies.
 
 
+       <itemizedlist>
 	  <listitem><para><literal>Trusted</literal> (<literal>trusted</literal>)
 	  <listitem><para><literal>Trusted</literal> (<literal>trusted</literal>)
 		is a tri-state value which defaults to APT deciding if a source
 		is a tri-state value which defaults to APT deciding if a source
 		is considered trusted or if warnings should be raised before e.g.
 		is considered trusted or if warnings should be raised before e.g.

+ 4 - 4
test/integration/test-bug-596498-trusted-unsigned-repo

@@ -18,7 +18,7 @@ aptgetupdate() {
 PKGTEXT="$(aptget install cool --assume-no -d | head -n 8)"
 PKGTEXT="$(aptget install cool --assume-no -d | head -n 8)"
 DOWNLOG="$(echo "$PKGTEXT" | tail -n 1)"
 DOWNLOG="$(echo "$PKGTEXT" | tail -n 1)"
 PKGTEXT="$(echo "$PKGTEXT" | head -n 7)"
 PKGTEXT="$(echo "$PKGTEXT" | head -n 7)"
-DEBFILE='rootdir/etc/apt/sources.list.d/apt-test-unstable-deb.list'
+DEBFILE='rootdir/etc/apt/sources.list.d/apt-test-unstable-*.list'
 
 
 testsuccessequal "$PKGTEXT
 testsuccessequal "$PKGTEXT
 $DOWNLOG
 $DOWNLOG
@@ -28,7 +28,7 @@ testsuccessequal "$PKGTEXT
 $DOWNLOG
 $DOWNLOG
 Download complete and in download only mode" aptget install cool --assume-no -d --allow-unauthenticated
 Download complete and in download only mode" aptget install cool --assume-no -d --allow-unauthenticated
 
 
-sed -i -e 's#deb#deb [trusted=no]#' $DEBFILE
+sed -i -e 's#\(deb\(-src\)\?\) #\1 [trusted=no] #' $DEBFILE
 aptgetupdate 'testsuccess'
 aptgetupdate 'testsuccess'
 
 
 testfailureequal "$PKGTEXT
 testfailureequal "$PKGTEXT
@@ -38,7 +38,7 @@ Install these packages without verification? [y/N] N
 E: Some packages could not be authenticated" aptget install cool --assume-no -d
 E: Some packages could not be authenticated" aptget install cool --assume-no -d
 
 
 find aptarchive/ \( -name 'Release.gpg' -o -name 'InRelease' \) -delete
 find aptarchive/ \( -name 'Release.gpg' -o -name 'InRelease' \) -delete
-sed -i -e 's#deb \[trusted=no\]#deb#' $DEBFILE
+sed -i -e 's#\(deb\(-src\)\?\) \[trusted=no\] #\1 #' $DEBFILE
 aptgetupdate
 aptgetupdate
 
 
 testfailureequal "$PKGTEXT
 testfailureequal "$PKGTEXT
@@ -54,7 +54,7 @@ Authentication warning overridden.
 $DOWNLOG
 $DOWNLOG
 Download complete and in download only mode" aptget install cool --assume-no -d --allow-unauthenticated
 Download complete and in download only mode" aptget install cool --assume-no -d --allow-unauthenticated
 
 
-sed -i -e 's#deb#deb [trusted=yes]#' $DEBFILE
+sed -i -e 's#\(deb\(-src\)\?\) #\1 [trusted=yes] #' $DEBFILE
 aptgetupdate
 aptgetupdate
 
 
 testsuccessequal "$PKGTEXT
 testsuccessequal "$PKGTEXT

+ 17 - 0
test/integration/test-sourceslist-trusted-options

@@ -199,3 +199,20 @@ insecureaptgetupdate
 everythingfails
 everythingfails
 everythingfails -t stable
 everythingfails -t stable
 everythingfails -t testing
 everythingfails -t testing
+
+msgmsg 'Test conflicting trusted options are refused'
+testsource() {
+	echo "$@" > rootdir/etc/apt/sources.list.d/example.list
+	testfailuremsg 'E: Conflicting values set for option Trusted concerning source http://example.org/bad/ unstable
+E: The list of sources could not be read.' aptget update --print-uris
+}
+for VAL in 'yes' 'no'; do
+	testsource "deb http://example.org/bad unstable main
+deb [trusted=${VAL}] http://example.org/bad unstable non-free"
+	testsource "deb [trusted=${VAL}] http://example.org/bad unstable main
+deb http://example.org/bad unstable non-free"
+done
+testsource 'deb [trusted=yes] http://example.org/bad unstable main
+deb [trusted=no] http://example.org/bad unstable non-free'
+testsource 'deb [trusted=no] http://example.org/bad unstable main
+deb [trusted=yes] http://example.org/bad unstable non-free'