From a7c835af20feeb470238ead3bda36af978c2600f Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:57:20 +0000 Subject: Alfredo's vendor stuff Author: jgg Date: 2001-03-13 06:51:46 GMT Alfredo's vendor stuff --- apt-pkg/acquire-method.cc | 20 +++++++++- apt-pkg/acquire-method.h | 8 +++- apt-pkg/cachefile.cc | 4 +- apt-pkg/deb/debindexfile.cc | 10 +++-- apt-pkg/deb/debrecords.cc | 12 +++++- apt-pkg/deb/debrecords.h | 3 +- apt-pkg/init.cc | 6 ++- apt-pkg/pkgrecords.h | 3 +- apt-pkg/sourcelist.cc | 93 ++++++++++++++++++++++++++++++++++++++++----- apt-pkg/sourcelist.h | 42 ++++++++++++++------ apt-pkg/tagfile.cc | 3 +- 11 files changed, 167 insertions(+), 37 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index 3b905f4e9..0ecd8df93 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire-method.cc,v 1.25 2001/02/20 07:03:17 jgg Exp $ +// $Id: acquire-method.cc,v 1.26 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Acquire Method @@ -23,7 +23,8 @@ #include #include #include - +#include + #include #include #include @@ -175,6 +176,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt) if (Res.MD5Sum.empty() == false) End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str()); + if (Res.SHA1Sum.empty() == false) + End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str()); if (Res.ResumePoint != 0) End += snprintf(End,sizeof(S)-50 - (End - S),"Resume-Point: %lu\n", @@ -199,6 +202,9 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt) if (Alt->MD5Sum.empty() == false) End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-MD5-Hash: %s\n", Alt->MD5Sum.c_str()); + if (Alt->SHA1Sum.empty() == false) + End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-SHA1-Hash: %s\n", + Alt->SHA1Sum.c_str()); if (Alt->IMSHit == true) strcat(End,"Alt-IMS-Hit: true\n"); @@ -434,3 +440,13 @@ pkgAcqMethod::FetchResult::FetchResult() : LastModified(0), { } /*}}}*/ +// AcqMethod::FetchResult::TakeHashes - Load hashes /*{{{*/ +// --------------------------------------------------------------------- +/* This hides the number of hashes we are supporting from the caller. + It just deals with the hash class. */ +void pkgAcqMethod::FetchResult::TakeHashes(Hashes &Hash) +{ + MD5Sum = Hash.MD5.Result(); + SHA1Sum = Hash.SHA1.Result(); +} + /*}}}*/ diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index b32d80c43..4721a3b65 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire-method.h,v 1.14 2001/02/20 07:03:17 jgg Exp $ +// $Id: acquire-method.h,v 1.15 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Acquire Method - Method helper class + functions @@ -20,6 +20,7 @@ #pragma interface "apt-pkg/acquire-method.h" #endif +class Hashes; class pkgAcqMethod { protected: @@ -37,11 +38,14 @@ class pkgAcqMethod struct FetchResult { string MD5Sum; + string SHA1Sum; time_t LastModified; bool IMSHit; string Filename; unsigned long Size; - unsigned long ResumePoint; + unsigned long ResumePoint; + + void TakeHashes(Hashes &Hash); FetchResult(); }; diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 74d136afb..4bc93fd7c 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: cachefile.cc,v 1.5 2001/02/20 07:03:17 jgg Exp $ +// $Id: cachefile.cc,v 1.6 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### CacheFile - Simple wrapper class for opening, generating and whatnot @@ -71,7 +71,7 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock) /* This sux, remove it someday */ if (_error->empty() == false) - _error->Warning(_("You may want to run apt-get update to correct these missing files")); + _error->Warning(_("You may want to run apt-get update to correct these problems")); Cache = new pkgCache(Map); if (_error->PendingError() == true) diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index dcc916c1a..2cc1de8a1 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debindexfile.cc,v 1.3 2001/02/23 06:41:55 jgg Exp $ +// $Id: debindexfile.cc,v 1.4 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Debian Specific sources.list types and the three sorts of Debian @@ -417,7 +417,8 @@ class debSLTypeDeb : public pkgSourceList::Type public: bool CreateItem(vector &List,string URI, - string Dist,string Section) const + string Dist,string Section, + pkgSourceList::Vendor const *Vendor) const { List.push_back(new debPackagesIndex(URI,Dist,Section)); return true; @@ -435,8 +436,9 @@ class debSLTypeDebSrc : public pkgSourceList::Type public: bool CreateItem(vector &List,string URI, - string Dist,string Section) const - { + string Dist,string Section, + pkgSourceList::Vendor const *Vendor) const + { List.push_back(new debSourcesIndex(URI,Dist,Section)); return true; }; diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 0196992c6..6652a6ad9 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debrecords.cc,v 1.9 2001/02/20 07:03:17 jgg Exp $ +// $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Debian Package Records - Parser for debian package records @@ -53,7 +53,15 @@ string debRecordParser::Name() /* */ string debRecordParser::MD5Hash() { - return Section.FindS("MD5sum"); + return Section.FindS("MD5Sum"); +} + /*}}}*/ +// RecordParser::SHA1Hash - Return the archive hash /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string debRecordParser::SHA1Hash() +{ + return Section.FindS("SHA1Sum"); } /*}}}*/ // RecordParser::Maintainer - Return the maintainer email /*{{{*/ diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index fd1c380dc..efef2e588 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debrecords.h,v 1.7 2001/02/20 07:03:17 jgg Exp $ +// $Id: debrecords.h,v 1.8 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Debian Package Records - Parser for debian package records @@ -36,6 +36,7 @@ class debRecordParser : public pkgRecords::Parser // These refer to the archive file for the Version virtual string FileName(); virtual string MD5Hash(); + virtual string SHA1Hash(); virtual string SourcePkg(); // These are some general stats about the package diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 01b9d8665..930c45a87 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: init.cc,v 1.15 2001/02/20 07:03:17 jgg Exp $ +// $Id: init.cc,v 1.16 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Init - Initialize the package library @@ -63,11 +63,13 @@ bool pkgInitConfig(Configuration &Cnf) // Configuration Cnf.Set("Dir::Etc","etc/apt/"); Cnf.Set("Dir::Etc::sourcelist","sources.list"); + Cnf.Set("Dir::Etc::vendorlist","vendors.list"); + Cnf.Set("Dir::Etc::vendorparts","vendors.list.d"); Cnf.Set("Dir::Etc::main","apt.conf"); Cnf.Set("Dir::Etc::parts","apt.conf.d"); Cnf.Set("Dir::Etc::preferences","preferences"); Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods"); - + bool Res = true; // Read an alternate config file diff --git a/apt-pkg/pkgrecords.h b/apt-pkg/pkgrecords.h index af5fac646..08f004414 100644 --- a/apt-pkg/pkgrecords.h +++ b/apt-pkg/pkgrecords.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgrecords.h,v 1.5 2001/02/20 07:03:17 jgg Exp $ +// $Id: pkgrecords.h,v 1.6 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Package Records - Allows access to complete package description records @@ -56,6 +56,7 @@ class pkgRecords::Parser // These refer to the archive file for the Version virtual string FileName() {return string();}; virtual string MD5Hash() {return string();}; + virtual string SHA1Hash() {return string();}; virtual string SourcePkg() {return string();}; // These are some general stats about the package diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index da7e38f6e..51289a43d 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: sourcelist.cc,v 1.18 2001/02/20 07:03:17 jgg Exp $ +// $Id: sourcelist.cc,v 1.19 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### List of Sources @@ -61,7 +61,7 @@ bool pkgSourceList::Type::FixupURI(string &URI) const URI = SubstVar(URI,"$(ARCH)",_config->Find("APT::Architecture")); - // Make sure that the URN is / postfixed + // Make sure that the URI is / postfixed if (URI[URI.size() - 1] != '/') URI += '/'; @@ -73,6 +73,7 @@ bool pkgSourceList::Type::FixupURI(string &URI) const /* This is a generic one that is the 'usual' format for sources.list Weird types may override this. */ bool pkgSourceList::Type::ParseLine(vector &List, + Vendor const *Vendor, const char *Buffer, unsigned long CurLine, string File) const @@ -95,7 +96,7 @@ bool pkgSourceList::Type::ParseLine(vector &List, if (ParseQuoteWord(Buffer,Section) == true) return _error->Error(_("Malformed line %lu in source list %s (Absolute dist)"),CurLine,File.c_str()); Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture")); - return CreateItem(List,URI,Dist,Section); + return CreateItem(List,URI,Dist,Section,Vendor); } // Grab the rest of the dists @@ -104,7 +105,7 @@ bool pkgSourceList::Type::ParseLine(vector &List, do { - if (CreateItem(List,URI,Dist,Section) == false) + if (CreateItem(List,URI,Dist,Section,Vendor) == false) return false; } while (ParseQuoteWord(Buffer,Section) == true); @@ -125,12 +126,58 @@ pkgSourceList::pkgSourceList(string File) Read(File); } /*}}}*/ +// SourceList::ReadVendors - Read list of known package vendors /*{{{*/ +// --------------------------------------------------------------------- +/* This also scans a directory of vendor files similar to apt.conf.d + which can contain the usual suspects of distribution provided data. + The APT config mechanism allows the user to override these in their + configuration file. */ +bool pkgSourceList::ReadVendors() +{ + Configuration Cnf; + + string CnfFile = _config->FindDir("Dir::Etc::vendorparts"); + if (FileExists(CnfFile) == true) + if (ReadConfigDir(Cnf,CnfFile,true) == false) + return false; + CnfFile = _config->FindFile("Dir::Etc::vendorlist"); + if (FileExists(CnfFile) == true) + if (ReadConfigFile(Cnf,CnfFile,true) == false) + return false; + + // Process 'simple-key' type sections + const Configuration::Item *Top = Cnf.Tree("simple-key"); + for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next) + { + Configuration Block(Top); + Vendor *Vendor; + + Vendor = new pkgSourceList::Vendor; + + Vendor->VendorID = Top->Tag; + Vendor->FingerPrint = Block.Find("Fingerprint"); + Vendor->Description = Block.Find("Name"); + + if (Vendor->FingerPrint.empty() == true || + Vendor->Description.empty() == true) + { + _error->Error(_("Vendor block %s is invalid"), Vendor->VendorID.c_str()); + delete Vendor; + continue; + } + + VendorList.push_back(Vendor); + } + + return !_error->PendingError(); +} + /*}}}*/ // SourceList::ReadMainList - Read the main source list from etc /*{{{*/ // --------------------------------------------------------------------- /* */ bool pkgSourceList::ReadMainList() { - return Read(_config->FindFile("Dir::Etc::sourcelist")); + return ReadVendors() && Read(_config->FindFile("Dir::Etc::sourcelist")); } /*}}}*/ // SourceList::Read - Parse the sourcelist file /*{{{*/ @@ -143,7 +190,7 @@ bool pkgSourceList::Read(string File) if (!F != 0) return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str()); - List.erase(List.begin(),List.end()); + SrcList.erase(SrcList.begin(),SrcList.end()); char Buffer[300]; int CurLine = 0; @@ -173,7 +220,35 @@ bool pkgSourceList::Read(string File) if (Parse == 0) return _error->Error(_("Type '%s' is not known in on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str()); - if (Parse->ParseLine(List,C,CurLine,File) == false) + // Authenticated repository + Vendor const *Vndr = 0; + if (C[0] == '[') + { + string VendorID; + + if (ParseQuoteWord(C,VendorID) == false) + return _error->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine,File.c_str()); + + if (VendorID.length() < 2 || VendorID.end()[-1] != ']') + return _error->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine,File.c_str()); + VendorID = string(VendorID,1,VendorID.size()-2); + + for (vector::const_iterator iter = VendorList.begin(); + iter != VendorList.end(); iter++) + { + if ((*iter)->VendorID == VendorID) + { + Vndr = *iter; + break; + } + } + + if (Vndr == 0) + return _error->Error(_("Unknown vendor ID '%s' in line %u of source list %s"), + VendorID.c_str(),CurLine,File.c_str()); + } + + if (Parse->ParseLine(SrcList,Vndr,C,CurLine,File) == false) return false; } return true; @@ -185,7 +260,7 @@ bool pkgSourceList::Read(string File) bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, pkgIndexFile *&Found) const { - for (const_iterator I = List.begin(); I != List.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) { if ((*I)->FindInCache(*File.Cache()) == File) { @@ -202,7 +277,7 @@ bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, /* */ bool pkgSourceList::GetIndexes(pkgAcquire *Owner) const { - for (const_iterator I = List.begin(); I != List.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) if ((*I)->GetIndexes(Owner) == false) return false; return true; diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index 3a6b274f6..1dc505425 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: sourcelist.h,v 1.9 2001/02/20 07:03:17 jgg Exp $ +// $Id: sourcelist.h,v 1.10 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### SourceList - Manage a list of sources @@ -14,10 +14,14 @@ files.sgml. The types are mapped through a list of type definitions which handle - the actual construction of the type. After loading a source list all - you have is a list of package index files that have the ability + the actual construction of the back end type. After loading a source + list all you have is a list of package index files that have the ability to be Acquired. + The vendor machanism is similar, except the vendor types are hard + wired. Before loading the source list the vendor list is loaded. + This doesn't load key data, just the checks to preform. + ##################################################################### */ /*}}}*/ #ifndef PKGLIB_SOURCELIST_H @@ -37,6 +41,18 @@ class pkgSourceList { public: + // An available vendor + struct Vendor + { + string VendorID; + string FingerPrint; + string Description; + + /* Lets revisit these.. + bool MatchFingerPrint(string FingerPrint); + string FingerPrintDescr();*/ + }; + // List of supported source list types class Type { @@ -52,11 +68,13 @@ class pkgSourceList bool FixupURI(string &URI) const; virtual bool ParseLine(vector &List, + Vendor const *Vendor, const char *Buffer, unsigned long CurLine,string File) const; virtual bool CreateItem(vector &List,string URI, - string Dist,string Section) const = 0; - + string Dist,string Section, + Vendor const *Vendor) const = 0; + Type(); virtual ~Type() {}; }; @@ -64,19 +82,21 @@ class pkgSourceList typedef vector::const_iterator const_iterator; protected: - - vector List; + + vector SrcList; + vector VendorList; public: bool ReadMainList(); bool Read(string File); + bool ReadVendors(); // List accessors - inline const_iterator begin() const {return List.begin();}; - inline const_iterator end() const {return List.end();}; - inline unsigned int size() const {return List.size();}; - inline bool empty() const {return List.empty();}; + inline const_iterator begin() const {return SrcList.begin();}; + inline const_iterator end() const {return SrcList.end();}; + inline unsigned int size() const {return SrcList.size();}; + inline bool empty() const {return SrcList.empty();}; bool FindIndex(pkgCache::PkgFileIterator File, pkgIndexFile *&Found) const; diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index b480704a3..fdeb09329 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: tagfile.cc,v 1.27 2001/02/23 06:41:55 jgg Exp $ +// $Id: tagfile.cc,v 1.28 2001/03/13 06:51:46 jgg Exp $ /* ###################################################################### Fast scanner for RFC-822 type header information @@ -396,6 +396,7 @@ static const char *iTFRewritePackageOrder[] = { "Filename", "Size", "MD5Sum", + "SHA1Sum", "MSDOS-Filename", // Obsolete "Description", 0}; -- cgit v1.2.3