From: Julian Andres Klode Date: Fri, 14 Aug 2015 08:50:56 +0000 (+0200) Subject: Merge branch 'debian/experimental' of https://github.com/DonKult/apt into debian... X-Git-Tag: 1.1.exp9~42 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/51c4e07f4cba0615ff269b5a8d04dfd3d1313b00?hp=14c50b58e938cf78ce2d32d4ec39979f7575c543 Merge branch 'debian/experimental' of https://github.com/DonKult/apt into debian/experimental --- diff --git a/Makefile b/Makefile index 6e1edbd5f..0393b424f 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ endif .PHONY: default default: startup all -.PHONY: headers library clean veryclean all binary program doc test update-po +.PHONY: fast headers library clean veryclean all binary program doc test update-po all headers library clean veryclean binary program doc manpages docbook test update-po startup dirs: $(MAKE) -C vendor $@ $(MAKE) -C apt-pkg $@ @@ -23,6 +23,16 @@ all headers library clean veryclean binary program doc manpages docbook test upd $(MAKE) -C po $@ $(MAKE) -C test $@ +fast: + $(MAKE) -C vendor all + $(MAKE) -C apt-pkg all + $(MAKE) -C apt-inst all + $(MAKE) -C apt-private all + $(MAKE) -C methods all + $(MAKE) -C cmdline all + $(MAKE) -C ftparchive all + $(MAKE) -C test all + all headers library clean veryclean binary program doc manpages docbook test update-po: startup dirs dirs: startup diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 747b73e05..446afa08d 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -476,8 +476,8 @@ void pkgProblemResolver::MakeScores() } // Copy the scores to advoid additive looping - SPtrArray OldScores = new int[Size]; - memcpy(OldScores,Scores,sizeof(*Scores)*Size); + std::unique_ptr OldScores(new int[Size]); + memcpy(OldScores.get(),Scores,sizeof(*Scores)*Size); /* Now we cause 1 level of dependency inheritance, that is we add the score of the packages that depend on the target Package. This @@ -702,17 +702,17 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) operates from highest score to lowest. This prevents problems when high score packages cause the removal of lower score packages that would cause the removal of even lower score packages. */ - SPtrArray PList = new pkgCache::Package *[Size]; - pkgCache::Package **PEnd = PList; + std::unique_ptr PList(new pkgCache::Package *[Size]); + pkgCache::Package **PEnd = PList.get(); for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) *PEnd++ = I; This = this; - qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort); + qsort(PList.get(),PEnd - PList.get(),sizeof(PList[0]),&ScoreSort); if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true) { clog << "Show Scores" << endl; - for (pkgCache::Package **K = PList; K != PEnd; K++) + for (pkgCache::Package **K = PList.get(); K != PEnd; K++) if (Scores[(*K)->ID] != 0) { pkgCache::PkgIterator Pkg(Cache,*K); @@ -734,7 +734,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) for (int Counter = 0; Counter != 10 && Change == true; Counter++) { Change = false; - for (pkgCache::Package **K = PList; K != PEnd; K++) + for (pkgCache::Package **K = PList.get(); K != PEnd; K++) { pkgCache::PkgIterator I(Cache,*K); @@ -845,8 +845,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) /* Look across the version list. If there are no possible targets then we keep the package and bail. This is necessary if a package has a dep on another package that can't be found */ - SPtrArray VList = Start.AllTargets(); - if (*VList == 0 && (Flags[I->ID] & Protected) != Protected && + std::unique_ptr VList(Start.AllTargets()); + if (VList[0] == 0 && (Flags[I->ID] & Protected) != Protected && Start.IsNegative() == false && Cache[I].NowBroken() == false) { @@ -863,7 +863,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) } bool Done = false; - for (pkgCache::Version **V = VList; *V != 0; V++) + for (pkgCache::Version **V = VList.get(); *V != 0; V++) { pkgCache::VerIterator Ver(Cache,*V); pkgCache::PkgIterator Pkg = Ver.ParentPkg(); @@ -1233,8 +1233,8 @@ bool pkgProblemResolver::ResolveByKeepInternal() clog << "Package " << I.FullName(false) << " " << Start << endl; // Look at all the possible provides on this package - SPtrArray VList = Start.AllTargets(); - for (pkgCache::Version **V = VList; *V != 0; V++) + std::unique_ptr VList(Start.AllTargets()); + for (pkgCache::Version **V = VList.get(); *V != 0; V++) { pkgCache::VerIterator Ver(Cache,*V); pkgCache::PkgIterator Pkg = Ver.ParentPkg(); diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index f8321079a..48547e564 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -157,11 +157,7 @@ class pkgCache::PkgIterator: public Iterator { inline const char *Name() const { return Group().Name(); } // Versions have sections - and packages can have different versions with different sections // so this interface is broken by design. Run as fast as you can to Version.Section(). - APT_DEPRECATED inline const char *Section() const { - APT_IGNORE_DEPRECATED_PUSH - return S->Section == 0?0:Owner->StrP + S->Section; - APT_IGNORE_DEPRECATED_POP - } + APT_DEPRECATED inline const char *Section() const; inline bool Purge() const {return S->CurrentState == pkgCache::State::Purge || (S->CurrentVer == 0 && S->CurrentState == pkgCache::State::NotInstalled);} inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;} @@ -518,5 +514,7 @@ inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const {return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);} inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const {return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);} +APT_DEPRECATED inline const char * pkgCache::PkgIterator::Section() const + {return S->VersionList == 0 ? 0 : VersionList().Section();} /*}}}*/ #endif diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 4cc8112af..1be782bac 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -52,6 +52,7 @@ #include #include +#include #ifdef HAVE_ZLIB #include @@ -159,7 +160,7 @@ bool CopyFile(FileFd &From,FileFd &To) return false; // Buffered copy between fds - SPtrArray Buf = new unsigned char[64000]; + std::unique_ptr Buf(new unsigned char[64000]); unsigned long long Size = From.Size(); while (Size != 0) { @@ -167,8 +168,8 @@ bool CopyFile(FileFd &From,FileFd &To) if (Size > 64000) ToRead = 64000; - if (From.Read(Buf,ToRead) == false || - To.Write(Buf,ToRead) == false) + if (From.Read(Buf.get(),ToRead) == false || + To.Write(Buf.get(),ToRead) == false) return false; Size -= ToRead; @@ -2251,22 +2252,32 @@ bool DropPrivileges() /*{{{*/ return _error->Error("No user %s, can not drop rights", toUser.c_str()); // Do not change the order here, it might break things + // Get rid of all our supplementary groups first if (setgroups(1, &pw->pw_gid)) return _error->Errno("setgroups", "Failed to setgroups"); + // Now change the group ids to the new user +#ifdef HAVE_SETRESGID + if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0) + return _error->Errno("setresgid", "Failed to set new group ids"); +#else if (setegid(pw->pw_gid) != 0) return _error->Errno("setegid", "Failed to setegid"); if (setgid(pw->pw_gid) != 0) return _error->Errno("setgid", "Failed to setgid"); +#endif + // Change the user ids to the new user +#ifdef HAVE_SETRESUID + if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) != 0) + return _error->Errno("setresuid", "Failed to set new user ids"); +#else if (setuid(pw->pw_uid) != 0) return _error->Errno("setuid", "Failed to setuid"); - - // the seteuid() is probably uneeded (at least thats what the linux - // man-page says about setuid(2)) but we cargo culted it anyway if (seteuid(pw->pw_uid) != 0) return _error->Errno("seteuid", "Failed to seteuid"); +#endif // Verify that the user has only a single group, and the correct one gid_t groups[1]; diff --git a/apt-pkg/contrib/sptr.h b/apt-pkg/contrib/sptr.h index e2e811b1d..92f4cdec8 100644 --- a/apt-pkg/contrib/sptr.h +++ b/apt-pkg/contrib/sptr.h @@ -22,7 +22,7 @@ #define SMART_POINTER_H template -class SPtr +class APT_DEPRECATED SPtr { public: T *Ptr; @@ -43,7 +43,7 @@ class SPtr }; template -class SPtrArray +class APT_DEPRECATED SPtrArray { public: T *Ptr; diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 02f61bf13..367605826 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1281,9 +1281,9 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, Otherwise we remove the offender if needed */ else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes) { - SPtrArray List = Start.AllTargets(); + std::unique_ptr List(Start.AllTargets()); pkgCache::PkgIterator TrgPkg = Start.TargetPkg(); - for (Version **I = List; *I != 0; I++) + for (Version **I = List.get(); *I != 0; I++) { VerIterator Ver(*this,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -2010,7 +2010,7 @@ bool pkgDepCache::MarkAndSweep(InRootSetFunc &rootFunc) } bool pkgDepCache::MarkAndSweep() { - std::auto_ptr f(GetRootSetFunc()); + std::unique_ptr f(GetRootSetFunc()); if(f.get() != NULL) return MarkAndSweep(*f.get()); else diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index aa281f695..6a1d6f8b3 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -250,7 +250,7 @@ class pkgDepCache : protected pkgCache::Namespace inline bool Keep() const {return Mode == ModeKeep;}; inline bool Protect() const {return (iFlags & Protected) == Protected;}; inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;}; - inline bool Upgradable() const {return Status >= 1;}; + inline bool Upgradable() const {return Status >= 1 && CandidateVer != NULL;}; inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;}; inline bool Held() const {return Status != 0 && Keep();}; inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;}; diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index edbdd09ab..dae37e8f8 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -142,9 +142,9 @@ bool pkgOrderList::DoRun() { // Temp list unsigned long Size = Cache.Head().PackageCount; - SPtrArray NList = new Package *[Size]; - SPtrArray AfterList = new Package *[Size]; - AfterEnd = AfterList; + std::unique_ptr NList(new Package *[Size]); + std::unique_ptr AfterList(new Package *[Size]); + AfterEnd = AfterList.get(); Depth = 0; WipeFlags(Added | AddPending | Loop | InList); @@ -154,7 +154,7 @@ bool pkgOrderList::DoRun() // Rebuild the main list into the temp list. iterator OldEnd = End; - End = NList; + End = NList.get(); for (iterator I = List; I != OldEnd; ++I) if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false) { @@ -163,12 +163,12 @@ bool pkgOrderList::DoRun() } // Copy the after list to the end of the main list - for (Package **I = AfterList; I != AfterEnd; I++) + for (Package **I = AfterList.get(); I != AfterEnd; I++) *End++ = *I; // Swap the main list to the new list delete [] List; - List = NList.UnGuard(); + List = NList.release(); return true; } /*}}}*/ @@ -512,8 +512,8 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver) against it! */ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical) { - SPtrArray List = D.AllTargets(); - for (Version **I = List; *I != 0; ++I) + std::unique_ptr List(D.AllTargets()); + for (Version **I = List.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -541,7 +541,7 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical) } if (D.IsNegative() == false) return true; - for (Version **I = List; *I != 0; ++I) + for (Version **I = List.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -1075,9 +1075,9 @@ void pkgOrderList::WipeFlags(unsigned long F) this fails to produce a suitable result. */ bool pkgOrderList::CheckDep(DepIterator D) { - SPtrArray List = D.AllTargets(); + std::unique_ptr List(D.AllTargets()); bool Hit = false; - for (Version **I = List; *I != 0; I++) + for (Version **I = List.get(); *I != 0; I++) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 78142ab13..dcae01126 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -390,9 +390,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) // to do anything at all for (DepIterator Cur = Start; true; ++Cur) { - SPtrArray VList = Cur.AllTargets(); + std::unique_ptr VList(Cur.AllTargets()); - for (Version **I = VList; *I != 0; ++I) + for (Version **I = VList.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator DepPkg = Ver.ParentPkg(); @@ -440,9 +440,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) // probably due to loops. for (DepIterator Cur = Start; true; ++Cur) { - SPtrArray VList = Cur.AllTargets(); + std::unique_ptr VList(Cur.AllTargets()); - for (Version **I = VList; *I != 0; ++I) + for (Version **I = VList.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator DepPkg = Ver.ParentPkg(); @@ -515,9 +515,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) // Search for dependencies which are unpacked but aren't configured yet (maybe loops) for (DepIterator Cur = Start; true; ++Cur) { - SPtrArray VList = Cur.AllTargets(); + std::unique_ptr VList(Cur.AllTargets()); - for (Version **I = VList; *I != 0; ++I) + for (Version **I = VList.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator DepPkg = Ver.ParentPkg(); @@ -726,8 +726,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Look for easy targets: packages that are already okay for (DepIterator Cur = Start; Bad == true; ++Cur) { - SPtrArray VList = Cur.AllTargets(); - for (Version **I = VList; *I != 0; ++I) + std::unique_ptr VList(Cur.AllTargets()); + for (Version **I = VList.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -750,8 +750,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Look for something that could be configured. for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur) { - SPtrArray VList = Cur.AllTargets(); - for (Version **I = VList; *I != 0; ++I) + std::unique_ptr VList(Cur.AllTargets()); + for (Version **I = VList.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator DepPkg = Ver.ParentPkg(); @@ -806,8 +806,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c End->Type == pkgCache::Dep::Obsoletes || End->Type == pkgCache::Dep::DpkgBreaks) { - SPtrArray VList = End.AllTargets(); - for (Version **I = VList; *I != 0; ++I) + std::unique_ptr VList(End.AllTargets()); + for (Version **I = VList.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator ConflictPkg = Ver.ParentPkg(); diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index e59697c28..ff250b532 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -429,12 +429,6 @@ struct pkgCache::Package map_pointer_t VersionList; // Version /** \brief index to the installed version */ map_pointer_t CurrentVer; // Version - /** \brief indicates nothing (consistently) - This field used to contain ONE section the package belongs to, - if those differs between versions it is a RANDOM one. - The Section() method tries to reproduce it, but the only sane - thing to do is use the Section field from the version! */ - APT_DEPRECATED map_ptrloc Section; // StringItem /** \brief index of the group this package belongs to */ map_pointer_t Group; // Group the Package belongs to diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index ef7afda94..68175a24a 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -1250,8 +1250,8 @@ static bool CheckValidity(const string &CacheFile, // Map it FileFd CacheF(CacheFile,FileFd::ReadOnly); - SPtr Map = new MMap(CacheF,0); - pkgCache Cache(Map); + std::unique_ptr Map(new MMap(CacheF,0)); + pkgCache Cache(Map.get()); if (_error->PendingError() == true || Map->Size() == 0) { if (Debug == true) @@ -1260,8 +1260,8 @@ static bool CheckValidity(const string &CacheFile, return false; } - SPtrArray RlsVisited = new bool[Cache.HeaderP->ReleaseFileCount]; - memset(RlsVisited,0,sizeof(*RlsVisited)*Cache.HeaderP->ReleaseFileCount); + std::unique_ptr RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]); + memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount); std::vector Files; for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i) { @@ -1295,8 +1295,8 @@ static bool CheckValidity(const string &CacheFile, /* Now we check every index file, see if it is in the cache, verify the IMS data and check that it is on the disk too.. */ - SPtrArray Visited = new bool[Cache.HeaderP->PackageFileCount]; - memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount); + std::unique_ptr Visited(new bool[Cache.HeaderP->PackageFileCount]); + memset(Visited.get(),0,sizeof(Visited[0])*Cache.HeaderP->PackageFileCount); for (std::vector::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile) { if (Debug == true) @@ -1342,7 +1342,7 @@ static bool CheckValidity(const string &CacheFile, } if (OutMap != 0) - *OutMap = Map.UnGuard(); + *OutMap = Map.release(); return true; } /*}}}*/ @@ -1483,16 +1483,16 @@ static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * con return true; } static bool loadBackMMapFromFile(std::unique_ptr &Gen, - SPtr &Map, OpProgress * const Progress, std::string const &FileName) + std::unique_ptr &Map, OpProgress * const Progress, std::string const &FileName) { - Map = CreateDynamicMMap(NULL, 0); + Map.reset(CreateDynamicMMap(NULL, 0)); FileFd CacheF(FileName, FileFd::ReadOnly); map_pointer_t const alloc = Map->RawAllocate(CacheF.Size()); if ((alloc == 0 && _error->PendingError()) || CacheF.Read((unsigned char *)Map->Data() + alloc, CacheF.Size()) == false) return false; - Gen.reset(new pkgCacheGenerator(Map.Get(),Progress)); + Gen.reset(new pkgCacheGenerator(Map.get(),Progress)); return true; } APT_DEPRECATED bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, @@ -1578,7 +1578,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress } // At this point we know we need to construct something, so get storage ready - SPtr Map = CreateDynamicMMap(NULL, 0); + std::unique_ptr Map(CreateDynamicMMap(NULL, 0)); if (Debug == true) std::clog << "Open memory Map (not filebased)" << std::endl; @@ -1599,7 +1599,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress { if (Debug == true) std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl; - Gen.reset(new pkgCacheGenerator(Map.Get(),Progress)); + Gen.reset(new pkgCacheGenerator(Map.get(),Progress)); TotalSize += ComputeSize(&List, Files.begin(),Files.end()); if (BuildCache(*Gen, Progress, CurrentSize, TotalSize, &List, @@ -1607,7 +1607,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress return false; if (Writeable == true && SrcCacheFile.empty() == false) - if (writeBackMMapToFile(Gen.get(), Map.Get(), SrcCacheFile) == false) + if (writeBackMMapToFile(Gen.get(), Map.get(), SrcCacheFile) == false) return false; } @@ -1620,7 +1620,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress return false; if (Writeable == true && CacheFile.empty() == false) - if (writeBackMMapToFile(Gen.get(), Map.Get(), CacheFile) == false) + if (writeBackMMapToFile(Gen.get(), Map.get(), CacheFile) == false) return false; } @@ -1644,7 +1644,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress } if (OutMap != nullptr) - *OutMap = Map.UnGuard(); + *OutMap = Map.release(); if (Debug == true) std::clog << "Everything is ready for shipping" << std::endl; @@ -1662,7 +1662,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O if (_system->AddStatusFiles(Files) == false) return false; - SPtr Map = CreateDynamicMMap(NULL, 0); + std::unique_ptr Map(CreateDynamicMMap(NULL, 0)); map_filesize_t CurrentSize = 0; map_filesize_t TotalSize = 0; @@ -1671,7 +1671,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O // Build the status cache if (Progress != NULL) Progress->OverallProgress(0,1,1,_("Reading package lists")); - pkgCacheGenerator Gen(Map.Get(),Progress); + pkgCacheGenerator Gen(Map.get(),Progress); if (_error->PendingError() == true) return false; if (BuildCache(Gen,Progress,CurrentSize,TotalSize, NULL, @@ -1680,7 +1680,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O if (_error->PendingError() == true) return false; - *OutMap = Map.UnGuard(); + *OutMap = Map.release(); return true; } diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index c12d8699b..4711372bc 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -100,8 +100,8 @@ bool pkgPolicy::InitDefaults() } // Apply the defaults.. - SPtrArray Fixed = new bool[Cache->HeaderP->PackageFileCount]; - memset(Fixed,0,sizeof(*Fixed)*Cache->HeaderP->PackageFileCount); + std::unique_ptr Fixed(new bool[Cache->HeaderP->PackageFileCount]); + memset(Fixed.get(),0,sizeof(Fixed[0])*Cache->HeaderP->PackageFileCount); StatusOverride = false; for (vector::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I) { @@ -368,11 +368,12 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgIterator const &Pkg) return Pins[Pkg->ID].Priority; return 0; } -APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver) +APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, bool considerFiles) { if (VerPins[Ver->ID].Type != pkgVersionMatch::None) return VerPins[Ver->ID].Priority; - + if (!considerFiles) + return 0; int priority = std::numeric_limits::min(); for (pkgCache::VerFileIterator file = Ver.FileList(); file.end() == false; file++) @@ -477,11 +478,18 @@ bool ReadPinFile(pkgPolicy &Plcy,string File) } for (; Word != End && isspace(*Word) != 0; Word++); - short int priority = Tags.FindI("Pin-Priority", 0); + int priority = Tags.FindI("Pin-Priority", 0); + if (priority < std::numeric_limits::min() || + priority > std::numeric_limits::max() || + _error->PendingError()) { + return _error->Error(_("%s: Value %s is outside the range of valid pin priorities (%d to %d)"), + File.c_str(), Tags.FindS("Pin-Priority").c_str(), + std::numeric_limits::min(), + std::numeric_limits::max()); + } if (priority == 0) { - _error->Warning(_("No priority (or zero) specified for pin")); - continue; + return _error->Error(_("No priority (or zero) specified for pin")); } istringstream s(Name); diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h index b3e1ec6b1..5be6657e9 100644 --- a/apt-pkg/policy.h +++ b/apt-pkg/policy.h @@ -80,7 +80,7 @@ class pkgPolicy : public pkgDepCache::Policy // Things for the cache interface. virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; - virtual signed short GetPriority(pkgCache::VerIterator const &Pkg); + virtual signed short GetPriority(pkgCache::VerIterator const &Pkg, bool ConsiderFiles = true); virtual signed short GetPriority(pkgCache::PkgFileIterator const &File) APT_OVERRIDE; bool InitDefaults(); diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 253b1b7a3..8acecd735 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -533,9 +533,16 @@ signed int pkgTagSection::FindI(const char *Tag,signed long Default) const return Default; strncpy(S,Start,Stop-Start); S[Stop - Start] = 0; - + + errno = 0; char *End; signed long Result = strtol(S,&End,10); + if (errno == ERANGE) + _error->Errno("strtol", _("Cannot convert %s to integer"), S); + if (Result < std::numeric_limits::min() || Result > std::numeric_limits::max()) { + errno = ERANGE; + _error->Errno("", _("Cannot convert %s to integer"), S); + } if (S == End) return Default; return Result; diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index cfdc13259..fa8416824 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -242,6 +242,7 @@ static bool addArgumentsAPT(std::vector &Args, char const * c if (CmdMatches("list")) { addArg(0,"installed","APT::Cmd::Installed",0); + addArg(0,"upgradeable","APT::Cmd::Upgradable",0); addArg(0,"upgradable","APT::Cmd::Upgradable",0); addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0); addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0); diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 074874903..d2b4bed51 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -128,7 +128,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) pkgSourceList *List = Cache.GetSourceList(); // Create the package manager and prepare to download - SPtr PM= _system->CreatePM(Cache); + std::unique_ptr PM(_system->CreatePM(Cache)); if (PM->GetArchives(&Fetcher,List,&Recs) == false || _error->PendingError() == true) return false; @@ -492,9 +492,9 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, if (Cache->BrokenCount() != 0) BrokenFix = true; - SPtr Fix; + std::unique_ptr Fix(nullptr); if (_config->FindB("APT::Get::CallResolver", true) == true) - Fix = new pkgProblemResolver(Cache); + Fix.reset(new pkgProblemResolver(Cache)); unsigned short fallback = MOD_INSTALL; if (strcasecmp(CmdL.FileList[0],"remove") == 0) @@ -526,8 +526,8 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, } - TryToInstall InstallAction(Cache, Fix, BrokenFix); - TryToRemove RemoveAction(Cache, Fix); + TryToInstall InstallAction(Cache, Fix.get(), BrokenFix); + TryToRemove RemoveAction(Cache, Fix.get()); // new scope for the ActionGroup { diff --git a/buildlib/config.h.in b/buildlib/config.h.in index 66ab33c2b..c6b1ee669 100644 --- a/buildlib/config.h.in +++ b/buildlib/config.h.in @@ -28,9 +28,11 @@ /* If there is no socklen_t, define this for the netdb shim */ #undef NEED_SOCKLEN_T_DEFINE -/* We need the getresuid() function */ +/* Check for getresuid() function and similar ones */ #undef HAVE_GETRESUID #undef HAVE_GETRESGID +#undef HAVE_SETRESUID +#undef HAVE_SETRESGID /* Define to the size of the filesize containing structures */ #undef _FILE_OFFSET_BITS diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index e61914298..117a44292 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -749,9 +749,9 @@ static bool ShowDepends(CommandLine &CmdL, bool const RevDepends) } // Display all solutions - SPtrArray List = D.AllTargets(); - pkgPrioSortList(*Cache,List); - for (pkgCache::Version **I = List; *I != 0; I++) + std::unique_ptr List(D.AllTargets()); + pkgPrioSortList(*Cache,List.get()); + for (pkgCache::Version **I = List.get(); *I != 0; I++) { pkgCache::VerIterator V(*Cache,*I); if (V != Cache->VerP + V.ParentPkg()->VersionList || @@ -1667,19 +1667,33 @@ static bool Policy(CommandLine &CmdL) pkgCache::PkgIterator I = Cache->PkgBegin(); for (;I.end() != true; ++I) { - if (Plcy->GetPriority(I) == 0) + // Old code for debugging + if (_config->FindI("APT::Policy", 1) < 1) { + if (Plcy->GetPriority(I) == 0) + continue; + + // Print the package name and the version we are forcing to + cout << " " << I.FullName(true) << " -> "; + + pkgCache::VerIterator V = Plcy->GetMatch(I); + if (V.end() == true) + cout << _("(not found)") << endl; + else + cout << V.VerStr() << endl; + continue; + } + // New code + for (pkgCache::VerIterator V = I.VersionList(); !V.end(); V++) { + auto Prio = Plcy->GetPriority(V, false); + if (Prio == 0) + continue; - // Print the package name and the version we are forcing to - cout << " " << I.FullName(true) << " -> "; - - pkgCache::VerIterator V = Plcy->GetMatch(I); - if (V.end() == true) - cout << _("(not found)") << endl; - else - cout << V.VerStr() << endl; - } - + cout << " "; + // Print the package name and the version we are forcing to + ioprintf(cout, _("%s -> %s with priority %d\n"), I.FullName(true).c_str(), V.VerStr(), Prio); + } + } return true; } @@ -1715,7 +1729,7 @@ static bool Policy(CommandLine &CmdL) cout << V.VerStr() << endl; // Pinned version - if (Plcy->GetPriority(Pkg) != 0) + if (_config->FindI("APT::Policy", 1) < 1 && Plcy->GetPriority(Pkg) != 0) { cout << _(" Package pin: "); V = Plcy->GetMatch(Pkg); @@ -1733,7 +1747,10 @@ static bool Policy(CommandLine &CmdL) cout << " *** " << V.VerStr(); else cout << " " << V.VerStr(); - cout << " " << Plcy->GetPriority(V) << endl; + if (_config->FindI("APT::Policy", 1) < 1) + cout << " " << Plcy->GetPriority(Pkg) << endl; + else + cout << " " << Plcy->GetPriority(V) << endl; for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF) { // Locate the associated index files so we can derive a description diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index b0e646833..61ed41164 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -701,7 +701,7 @@ static bool DoSource(CommandLine &CmdL) AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0)); pkgAcquire Fetcher(&Stat); - SPtrArray Dsc = new DscFile[CmdL.FileSize()]; + std::unique_ptr Dsc(new DscFile[CmdL.FileSize()]); // insert all downloaded uris into this set to avoid downloading them // twice @@ -1000,7 +1000,7 @@ static bool DoBuildDep(CommandLine &CmdL) { string Src; pkgSrcRecords::Parser *Last = 0; - SPtr LastOwner; + std::unique_ptr LastOwner; // an unpacked debian source tree using APT::String::Startswith; @@ -1012,7 +1012,7 @@ static bool DoBuildDep(CommandLine &CmdL) std::string TypeName = "Debian control file"; pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str()); if(Type != NULL) - LastOwner = Last = Type->CreateSrcPkgParser(*I); + LastOwner.reset(Last = Type->CreateSrcPkgParser(*I)); } // if its a local file (e.g. .dsc) use this else if (FileExists(*I)) @@ -1023,7 +1023,7 @@ static bool DoBuildDep(CommandLine &CmdL) string TypeName = "Debian " + flExtension(*I) + " file"; pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str()); if(Type != NULL) - LastOwner = Last = Type->CreateSrcPkgParser(*I); + LastOwner.reset(Last = Type->CreateSrcPkgParser(*I)); } else { // normal case, search the cache for the source file Last = FindSrc(*I,SrcRecs,Src,Cache); diff --git a/configure.ac b/configure.ac index 2221833a1..feba7be61 100644 --- a/configure.ac +++ b/configure.ac @@ -174,9 +174,11 @@ AC_EGREP_HEADER(h_errno, netdb.h, [AC_MSG_RESULT(normal)], dnl check for setuid checking function -AC_CHECK_FUNCS(getresuid getresgid) +AC_CHECK_FUNCS(getresuid getresgid setresuid setresgid) AC_SUBST(HAVE_GETRESUID) AC_SUBST(HAVE_GETRESGID) +AC_SUBST(HAVE_SETRESUID) +AC_SUBST(HAVE_SETRESGID) dnl Check for doxygen AC_PATH_PROG(DOXYGEN, doxygen) diff --git a/doc/apt.8.xml b/doc/apt.8.xml index 29bf96751..e00b6417a 100644 --- a/doc/apt.8.xml +++ b/doc/apt.8.xml @@ -44,7 +44,8 @@ display a list of packages. It supports shell pattern for matching package names and the following options: , - , + , + , are supported. diff --git a/doc/apt_preferences.5.xml b/doc/apt_preferences.5.xml index 5ea59bf9c..28b795d43 100644 --- a/doc/apt_preferences.5.xml +++ b/doc/apt_preferences.5.xml @@ -339,14 +339,21 @@ only if there is no installed version of the package P < 0 prevents the version from being installed + +P = 0 +has undefined behaviour, do not use it. + -If any specific-form records match an available package version then the -first such record determines the priority of the package version. -Failing that, -if any general-form records match an available package version then the -first such record determines the priority of the package version. + +The first specific-form record matching an available package version determines +the priority of the package version. +Failing that, the priority of the package is defined as the maximum of all +priorities defined by generic-form records matching the version. +Records defined using patterns in the Pin field other than "*" are treated like +specific-form records. + For example, suppose the APT preferences file contains the three records presented earlier: diff --git a/doc/po/apt-doc.pot b/doc/po/apt-doc.pot index fc3b5a6c6..35db9571d 100644 --- a/doc/po/apt-doc.pot +++ b/doc/po/apt-doc.pot @@ -531,7 +531,8 @@ msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " ", , " -" are supported." +", are " +"supported." msgstr "" #. type: Content of: diff --git a/doc/po/de.po b/doc/po/de.po index 12d6a4c4d..4f001b85e 100644 --- a/doc/po/de.po +++ b/doc/po/de.po @@ -662,13 +662,13 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" "list wird benutzt, um eine Paketliste anzuzeigen. Es " "unterstützt Shell-Muster zur Beschränkung auf passende Paketnamen. Die " "folgenden Optionen werden unterstützt: , " -", ." +", , ." #. type: Content of: #: apt.8.xml:54 diff --git a/doc/po/es.po b/doc/po/es.po index 9ace0bd4f..84dd3a127 100644 --- a/doc/po/es.po +++ b/doc/po/es.po @@ -742,7 +742,7 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" diff --git a/doc/po/fr.po b/doc/po/fr.po index 8d7c29f37..d1e60a655 100644 --- a/doc/po/fr.po +++ b/doc/po/fr.po @@ -658,7 +658,7 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" "La commande list est utilisée pour afficher une liste de " diff --git a/doc/po/it.po b/doc/po/it.po index 21d5611ea..af5fa2914 100644 --- a/doc/po/it.po +++ b/doc/po/it.po @@ -710,13 +710,13 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" "list viene usato per visualizzare un elenco di pacchetti. " "Permette l'uso dei modelli di shell per la corrispondenza con nomi di " "pacchetto e sono gestite le seguenti opzioni: , " -", ." +", , ." #. type: Content of: #: apt.8.xml:54 diff --git a/doc/po/ja.po b/doc/po/ja.po index 5d6c183cb..a74d2af3a 100644 --- a/doc/po/ja.po +++ b/doc/po/ja.po @@ -704,12 +704,12 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" "パッケージ一覧を表示するには list を使います。パッケージ名" "のマッチングにシェルパターン、そしてオプション 、 を" +"option>、 , 、 を" "サポートしています。" #. type: Content of: diff --git a/doc/po/pl.po b/doc/po/pl.po index 3d89db060..229ac02c1 100644 --- a/doc/po/pl.po +++ b/doc/po/pl.po @@ -700,7 +700,7 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" diff --git a/doc/po/pt.po b/doc/po/pt.po index dc91fddca..35efdfe30 100644 --- a/doc/po/pt.po +++ b/doc/po/pt.po @@ -707,7 +707,7 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" "list é usado para mostrar uma lista de pacotes. Suporta " diff --git a/doc/po/pt_BR.po b/doc/po/pt_BR.po index b6bd0fe09..9a9f8ec56 100644 --- a/doc/po/pt_BR.po +++ b/doc/po/pt_BR.po @@ -523,7 +523,7 @@ msgstr "" msgid "" "list is used to display a list of packages. It supports " "shell pattern for matching package names and the following options: " -", , , , , are supported." msgstr "" diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 1bc926d21..7f09a3758 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -420,7 +420,7 @@ bool PackagesWriter::DoPackage(string FileName) Architecture = Arch; else Architecture = Tags.FindS("Architecture"); - auto_ptr OverItem(Over.GetItem(Package,Architecture)); + unique_ptr OverItem(Over.GetItem(Package,Architecture)); if (Package.empty() == true) return _error->Error(_("Archive had no package field")); @@ -434,7 +434,7 @@ bool PackagesWriter::DoPackage(string FileName) ioprintf(c1out, _(" %s has no override entry\n"), Package.c_str()); } - OverItem = auto_ptr(new Override::Item); + OverItem = unique_ptr(new Override::Item); OverItem->FieldOverride["Section"] = Tags.FindS("Section"); OverItem->Priority = Tags.FindS("Priority"); } @@ -660,7 +660,7 @@ bool SourcesWriter::DoPackage(string FileName) string BestPrio; string Bins = Tags.FindS("Binary"); char Buffer[Bins.length() + 1]; - auto_ptr OverItem(0); + unique_ptr OverItem(nullptr); if (Bins.empty() == false) { strcpy(Buffer,Bins.c_str()); @@ -673,7 +673,7 @@ bool SourcesWriter::DoPackage(string FileName) unsigned char BestPrioV = pkgCache::State::Extra; for (unsigned I = 0; BinList[I] != 0; I++) { - auto_ptr Itm(BOver.GetItem(BinList[I])); + unique_ptr Itm(BOver.GetItem(BinList[I])); if (Itm.get() == 0) continue; @@ -685,7 +685,7 @@ bool SourcesWriter::DoPackage(string FileName) } if (OverItem.get() == 0) - OverItem = Itm; + OverItem = std::move(Itm); } } @@ -698,23 +698,23 @@ bool SourcesWriter::DoPackage(string FileName) ioprintf(c1out, _(" %s has no override entry\n"), Tags.FindS("Source").c_str()); } - OverItem = auto_ptr(new Override::Item); + OverItem.reset(new Override::Item); } struct stat St; if (stat(FileName.c_str(), &St) != 0) return _error->Errno("fstat","Failed to stat %s",FileName.c_str()); - auto_ptr SOverItem(SOver.GetItem(Tags.FindS("Source"))); - // const auto_ptr autoSOverItem(SOverItem); + unique_ptr SOverItem(SOver.GetItem(Tags.FindS("Source"))); + // const unique_ptr autoSOverItem(SOverItem); if (SOverItem.get() == 0) { ioprintf(c1out, _(" %s has no source override entry\n"), Tags.FindS("Source").c_str()); - SOverItem = auto_ptr(BOver.GetItem(Tags.FindS("Source"))); + SOverItem = unique_ptr(BOver.GetItem(Tags.FindS("Source"))); if (SOverItem.get() == 0) { ioprintf(c1out, _(" %s has no binary override entry either\n"), Tags.FindS("Source").c_str()); - SOverItem = auto_ptr(new Override::Item); + SOverItem = unique_ptr(new Override::Item); *SOverItem = *OverItem; } } diff --git a/po/fr.po b/po/fr.po index 0e3ae69b1..eb41bb221 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1507,7 +1507,7 @@ msgstr "" #. careful with hard to type or special characters (like non-breaking spaces) #: apt-private/private-install.cc:195 msgid "Yes, do as I say!" -msgstr "Oui, faites ce que je vous dis !" +msgstr "Oui, faites ce que je vous dis !" #: apt-private/private-install.cc:197 #, c-format diff --git a/test/integration/test-bug-543966-downgrade-below-1000-pin b/test/integration/test-bug-543966-downgrade-below-1000-pin index ede9ad6aa..435b6876e 100755 --- a/test/integration/test-bug-543966-downgrade-below-1000-pin +++ b/test/integration/test-bug-543966-downgrade-below-1000-pin @@ -33,20 +33,17 @@ Pin-Priority: $2" > rootdir/etc/apt/preferences testpinning() { - local PKGPIN='' local PKGPINPRIO='' local REPPINPRIO='' if [ "$1" != '*' ]; then PKGPINPRIO='' REPPINPRIO=' 500' - PKGPIN='Package pin: 5.0.0 - ' fi writepin "$1" '99' testsuccessequal "base-files: Installed: 5.0.0-1 Candidate: 5.0.0-1 - ${PKGPIN}Version table: + Version table: *** 5.0.0-1 100 100 $STATUS 5.0.0 ${PKGPINPRIO:-99} @@ -56,7 +53,7 @@ testpinning() { testsuccessequal "base-files: Installed: 5.0.0-1 Candidate: 5.0.0-1 - ${PKGPIN}Version table: + Version table: *** 5.0.0-1 100 100 $STATUS 5.0.0 ${PKGPINPRIO:-100} @@ -66,7 +63,7 @@ testpinning() { testsuccessequal "base-files: Installed: 5.0.0-1 Candidate: 5.0.0-1 - ${PKGPIN}Version table: + Version table: *** 5.0.0-1 100 100 $STATUS 5.0.0 ${PKGPINPRIO:-999} @@ -76,7 +73,7 @@ testpinning() { testsuccessequal "base-files: Installed: 5.0.0-1 Candidate: 5.0.0 - ${PKGPIN}Version table: + Version table: *** 5.0.0-1 100 100 $STATUS 5.0.0 ${PKGPINPRIO:-1000} diff --git a/test/integration/test-policy-pinning b/test/integration/test-policy-pinning index c4f478efc..d54e1bc36 100755 --- a/test/integration/test-policy-pinning +++ b/test/integration/test-policy-pinning @@ -89,11 +89,6 @@ testequalpolicycoolstuff() { local AB="$3" local AS="$4" local PB="$5" - local PINVERSION="$6" - if [ -n "$PINVERSION" ]; then - PINVERSION="Package pin: $PINVERSION - " - fi local IS="" local IB="" local SB="" @@ -118,7 +113,7 @@ testequalpolicycoolstuff() { testsuccessequal "coolstuff: Installed: $INSTALLED Candidate: $CANDIDATE - ${PINVERSION}Version table:${BPO2ARCHIVE} + Version table:${BPO2ARCHIVE} $IB 2.0~bpo1 $PB ${BPO1ARCHIVE}$SB $IS 1.0 $AS