]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/deblistparser.cc
use unusable-for-security hashes for integrity checks
[apt.git] / apt-pkg / deb / deblistparser.cc
index e57a3524fd0aa168a706e159f5925478b466106e..7da908d751e4a73350d0d0441241a4adf9cd1432 100644 (file)
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
 #include <apt-pkg/crc-16.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/crc-16.h>
 #include <apt-pkg/md5.h>
-#include <apt-pkg/mmap.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/tagfile.h>
@@ -50,12 +48,9 @@ static debListParser::WordList PrioList[] = {
 /* Provide an architecture and only this one and "all" will be accepted
    in Step(), if no Architecture is given we will accept every arch
    we would accept in general with checkArchitecture() */
 /* Provide an architecture and only this one and "all" will be accepted
    in Step(), if no Architecture is given we will accept every arch
    we would accept in general with checkArchitecture() */
-debListParser::debListParser(FileFd *File, string const &Arch) :  d(NULL), Tags(File),
-                               Arch(Arch) {
-   if (Arch == "native")
-      this->Arch = _config->Find("APT::Architecture");
-   Architectures = APT::Configuration::getArchitectures();
-   MultiArchEnabled = Architectures.size() > 1;
+debListParser::debListParser(FileFd *File) :
+   pkgCacheListParser(), d(NULL), Tags(File)
+{
 }
                                                                        /*}}}*/
 // ListParser::Package - Return the package name                       /*{{{*/
 }
                                                                        /*}}}*/
 // ListParser::Package - Return the package name                       /*{{{*/
@@ -72,7 +67,8 @@ string debListParser::Package() {
 // ---------------------------------------------------------------------
 /* This will return the Architecture of the package this section describes */
 string debListParser::Architecture() {
 // ---------------------------------------------------------------------
 /* This will return the Architecture of the package this section describes */
 string debListParser::Architecture() {
-   return Section.FindS("Architecture");
+   std::string const Arch = Section.FindS("Architecture");
+   return Arch.empty() ? "none" : Arch;
 }
                                                                        /*}}}*/
 // ListParser::ArchitectureAll                                         /*{{{*/
 }
                                                                        /*}}}*/
 // ListParser::ArchitectureAll                                         /*{{{*/
@@ -97,14 +93,14 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors)  /*{{{*/
    unsigned char MA;
    string const MultiArch = Section.FindS("Multi-Arch");
    if (MultiArch.empty() == true || MultiArch == "no")
    unsigned char MA;
    string const MultiArch = Section.FindS("Multi-Arch");
    if (MultiArch.empty() == true || MultiArch == "no")
-      MA = pkgCache::Version::None;
+      MA = pkgCache::Version::No;
    else if (MultiArch == "same") {
       if (ArchitectureAll() == true)
       {
         if (showErrors == true)
            _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
                  Section.FindS("Package").c_str());
    else if (MultiArch == "same") {
       if (ArchitectureAll() == true)
       {
         if (showErrors == true)
            _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
                  Section.FindS("Package").c_str());
-        MA = pkgCache::Version::None;
+        MA = pkgCache::Version::No;
       }
       else
         MA = pkgCache::Version::Same;
       }
       else
         MA = pkgCache::Version::Same;
@@ -118,7 +114,7 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors)  /*{{{*/
       if (showErrors == true)
         _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
               MultiArch.c_str(), Section.FindS("Package").c_str());
       if (showErrors == true)
         _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
               MultiArch.c_str(), Section.FindS("Package").c_str());
-      MA = pkgCache::Version::None;
+      MA = pkgCache::Version::No;
    }
 
    if (ArchitectureAll() == true)
    }
 
    if (ArchitectureAll() == true)
@@ -366,7 +362,7 @@ unsigned short debListParser::VersionHash()
    return Result;
 }
                                                                        /*}}}*/
    return Result;
 }
                                                                        /*}}}*/
-// ListParser::ParseStatus - Parse the status field                    /*{{{*/
+// StatusListParser::ParseStatus - Parse the status field              /*{{{*/
 // ---------------------------------------------------------------------
 /* Status lines are of the form,
      Status: want flag status
 // ---------------------------------------------------------------------
 /* Status lines are of the form,
      Status: want flag status
@@ -375,7 +371,12 @@ unsigned short debListParser::VersionHash()
    status = not-installed, config-files, half-installed, unpacked,
             half-configured, triggers-awaited, triggers-pending, installed
  */
    status = not-installed, config-files, half-installed, unpacked,
             half-configured, triggers-awaited, triggers-pending, installed
  */
-bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
+bool debListParser::ParseStatus(pkgCache::PkgIterator &,
+                               pkgCache::VerIterator &)
+{
+   return true;
+}
+bool debStatusListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                                pkgCache::VerIterator &Ver)
 {
    const char *Start;
                                pkgCache::VerIterator &Ver)
 {
    const char *Start;
@@ -790,43 +791,23 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
         return _error->Error("Problem parsing dependency %s",Tag);
       size_t const found = Package.rfind(':');
 
         return _error->Error("Problem parsing dependency %s",Tag);
       size_t const found = Package.rfind(':');
 
-      // If negative is unspecific it needs to apply on all architectures
-      if (MultiArchEnabled == true && found == string::npos &&
-         (Type == pkgCache::Dep::Conflicts ||
-          Type == pkgCache::Dep::DpkgBreaks ||
-          Type == pkgCache::Dep::Replaces))
+      if (found == string::npos || strcmp(Package.c_str() + found, ":any") == 0)
       {
       {
-        for (std::vector<std::string>::const_iterator a = Architectures.begin();
-             a != Architectures.end(); ++a)
-           if (NewDepends(Ver,Package,*a,Version,Op,Type) == false)
-              return false;
-        if (NewDepends(Ver,Package,"none",Version,Op,Type) == false)
+        if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
            return false;
       }
            return false;
       }
-      else if (found != string::npos &&
-              strcmp(Package.c_str() + found, ":any") != 0)
+      else
       {
         string Arch = Package.substr(found+1, string::npos);
         Package = Package.substr(0, found);
         // Such dependencies are not supposed to be accepted …
       {
         string Arch = Package.substr(found+1, string::npos);
         Package = Package.substr(0, found);
         // Such dependencies are not supposed to be accepted …
-        // … but this is probably the best thing to do.
+        // … but this is probably the best thing to do anyway
         if (Arch == "native")
            Arch = _config->Find("APT::Architecture");
         if (Arch == "native")
            Arch = _config->Find("APT::Architecture");
-        if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false)
-           return false;
-      }
-      else
-      {
-        if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
-           return false;
-        if ((Type == pkgCache::Dep::Conflicts ||
-             Type == pkgCache::Dep::DpkgBreaks ||
-             Type == pkgCache::Dep::Replaces) &&
-            NewDepends(Ver, Package,
-                       (pkgArch != "none") ? "none" : _config->Find("APT::Architecture"),
-                       Version,Op,Type) == false)
+        if (NewDepends(Ver,Package,Arch,Version,Op | pkgCache::Dep::ArchSpecific,Type) == false)
            return false;
       }
            return false;
       }
+
       if (Start == Stop)
         break;
    }
       if (Start == Stop)
         break;
    }
@@ -858,13 +839,13 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
         } else if (archfound != string::npos) {
            string OtherArch = Package.substr(archfound+1, string::npos);
            Package = Package.substr(0, archfound);
         } else if (archfound != string::npos) {
            string OtherArch = Package.substr(archfound+1, string::npos);
            Package = Package.substr(0, archfound);
-           if (NewProvides(Ver, Package, OtherArch, Version) == false)
+           if (NewProvides(Ver, Package, OtherArch, Version, pkgCache::Flag::ArchSpecific) == false)
               return false;
         } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) {
               return false;
         } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) {
-           if (NewProvidesAllArch(Ver, Package, Version) == false)
+           if (NewProvidesAllArch(Ver, Package, Version, 0) == false)
               return false;
         } else {
               return false;
         } else {
-           if (NewProvides(Ver, Package, Arch, Version) == false)
+           if (NewProvides(Ver, Package, Arch, Version, 0) == false)
               return false;
         }
 
               return false;
         }
 
@@ -876,26 +857,14 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
    if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
    {
       string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
    if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
    {
       string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
-      return NewProvidesAllArch(Ver, Package, Ver.VerStr());
+      return NewProvidesAllArch(Ver, Package, Ver.VerStr(), pkgCache::Flag::MultiArchImplicit);
    }
    else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
    }
    else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
-      return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr());
+      return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr(), pkgCache::Flag::MultiArchImplicit);
 
    return true;
 }
                                                                        /*}}}*/
 
    return true;
 }
                                                                        /*}}}*/
-// ListParser::NewProvides - add provides for all architectures                /*{{{*/
-bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package,
-                               string const &Version) {
-   for (std::vector<string>::const_iterator a = Architectures.begin();
-       a != Architectures.end(); ++a)
-   {
-      if (NewProvides(Ver, Package, *a, Version) == false)
-        return false;
-   }
-   return true;
-}
-                                                                       /*}}}*/
 // ListParser::GrabWord - Matches a word and returns                   /*{{{*/
 // ---------------------------------------------------------------------
 /* Looks for a word in a list of words - for ParseStatus */
 // ListParser::GrabWord - Matches a word and returns                   /*{{{*/
 // ---------------------------------------------------------------------
 /* Looks for a word in a list of words - for ParseStatus */
@@ -918,34 +887,7 @@ bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
 bool debListParser::Step()
 {
    iOffset = Tags.Offset();
 bool debListParser::Step()
 {
    iOffset = Tags.Offset();
-   while (Tags.Step(Section) == true)
-   {      
-      /* See if this is the correct Architecture, if it isn't then we
-         drop the whole section. A missing arch tag only happens (in theory)
-         inside the Status file, so that is a positive return */
-      string const Architecture = Section.FindS("Architecture");
-
-      if (Arch.empty() == true || Arch == "any" || MultiArchEnabled == false)
-      {
-        if (APT::Configuration::checkArchitecture(Architecture) == true)
-           return true;
-        /* parse version stanzas without an architecture only in the status file
-           (and as misfortune bycatch flat-archives) */
-        if ((Arch.empty() == true || Arch == "any") && Architecture.empty() == true)
-           return true;
-      }
-      else
-      {
-        if (Architecture == Arch)
-           return true;
-
-        if (Architecture == "all" && Arch == _config->Find("APT::Architecture"))
-           return true;
-      }
-
-      iOffset = Tags.Offset();
-   }   
-   return false;
+   return Tags.Step(Section);
 }
                                                                        /*}}}*/
 // ListParser::GetPrio - Convert the priority from a string            /*{{{*/
 }
                                                                        /*}}}*/
 // ListParser::GetPrio - Convert the priority from a string            /*{{{*/
@@ -963,7 +905,7 @@ unsigned char debListParser::GetPrio(string Str)
 bool debListParser::SameVersion(unsigned short const Hash,             /*{{{*/
       pkgCache::VerIterator const &Ver)
 {
 bool debListParser::SameVersion(unsigned short const Hash,             /*{{{*/
       pkgCache::VerIterator const &Ver)
 {
-   if (pkgCacheGenerator::ListParser::SameVersion(Hash, Ver) == false)
+   if (pkgCacheListParser::SameVersion(Hash, Ver) == false)
       return false;
    // status file has no (Download)Size, but all others are fair game
    // status file is parsed last, so the first version we encounter is
       return false;
    // status file has no (Download)Size, but all others are fair game
    // status file is parsed last, so the first version we encounter is
@@ -981,7 +923,7 @@ bool debListParser::SameVersion(unsigned short const Hash,          /*{{{*/
                                                                        /*}}}*/
 
 debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile)
                                                                        /*}}}*/
 
 debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile)
-   : debListParser(File, ""), DebFile(DebFile)
+   : debListParser(File), DebFile(DebFile)
 {
 }
 
 {
 }
 
@@ -991,7 +933,7 @@ bool debDebFileParser::UsePackage(pkgCache::PkgIterator &Pkg,
    bool res = debListParser::UsePackage(Pkg, Ver);
    // we use the full file path as a provides so that the file is found
    // by its name
    bool res = debListParser::UsePackage(Pkg, Ver);
    // we use the full file path as a provides so that the file is found
    // by its name
-   if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr()) == false)
+   if(NewProvides(Ver, DebFile, Pkg.Cache()->NativeArch(), Ver.VerStr(), 0) == false)
       return false;
    return res;
 }
       return false;
    return res;
 }