]> git.saurik.com Git - apt.git/blob - apt-pkg/vendorlist.cc
* apt-pkg/depcache.cc:
[apt.git] / apt-pkg / vendorlist.cc
1 #include <apt-pkg/fileutl.h>
2 #include <apt-pkg/error.h>
3 #include <apti18n.h>
4
5 #if __GNUC__ >= 4
6 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
7 #endif
8
9 #include <apt-pkg/vendorlist.h>
10
11 pkgVendorList::~pkgVendorList()
12 {
13 for (vector<const Vendor *>::const_iterator I = VendorList.begin();
14 I != VendorList.end(); I++)
15 delete *I;
16 }
17
18 // pkgVendorList::ReadMainList - Read list of known package vendors /*{{{*/
19 // ---------------------------------------------------------------------
20 /* This also scans a directory of vendor files similar to apt.conf.d
21 which can contain the usual suspects of distribution provided data.
22 The APT config mechanism allows the user to override these in their
23 configuration file. */
24 bool pkgVendorList::ReadMainList()
25 {
26 Configuration Cnf;
27
28 string CnfFile = _config->FindDir("Dir::Etc::vendorparts");
29 if (DirectoryExists(CnfFile) == true)
30 if (ReadConfigDir(Cnf,CnfFile,true) == false)
31 return false;
32 CnfFile = _config->FindFile("Dir::Etc::vendorlist");
33 if (RealFileExists(CnfFile) == true)
34 if (ReadConfigFile(Cnf,CnfFile,true) == false)
35 return false;
36
37 return CreateList(Cnf);
38 }
39 /*}}}*/
40 bool pkgVendorList::Read(string File) /*{{{*/
41 {
42 Configuration Cnf;
43 if (ReadConfigFile(Cnf,File,true) == false)
44 return false;
45
46 return CreateList(Cnf);
47 }
48 /*}}}*/
49 bool pkgVendorList::CreateList(Configuration& Cnf) /*{{{*/
50 {
51 for (vector<const Vendor *>::const_iterator I = VendorList.begin();
52 I != VendorList.end(); I++)
53 delete *I;
54 VendorList.erase(VendorList.begin(),VendorList.end());
55
56 const Configuration::Item *Top = Cnf.Tree("Vendor");
57 for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
58 {
59 Configuration Block(Top);
60 string VendorID = Top->Tag;
61 vector <struct Vendor::Fingerprint *> *Fingerprints = new vector<Vendor::Fingerprint *>;
62 struct Vendor::Fingerprint *Fingerprint = new struct Vendor::Fingerprint;
63 string Origin = Block.Find("Origin");
64
65 Fingerprint->Print = Block.Find("Fingerprint");
66 Fingerprint->Description = Block.Find("Name");
67 Fingerprints->push_back(Fingerprint);
68
69 if (Fingerprint->Print.empty() || Fingerprint->Description.empty())
70 {
71 _error->Error(_("Vendor block %s contains no fingerprint"), VendorID.c_str());
72 delete Fingerprints;
73 continue;
74 }
75 if (_config->FindB("Debug::sourceList", false))
76 std::cerr << "Adding vendor with ID: " << VendorID
77 << " Fingerprint: " << Fingerprint->Print << std::endl;
78
79 VendorList.push_back(new Vendor(VendorID, Origin, Fingerprints));
80 }
81
82 /* Process 'group-key' type sections */
83 Top = Cnf.Tree("group-key");
84 for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
85 {
86 // Configuration Block(Top);
87 // vector<Vendor::Fingerprint *> Fingerprints;
88 // string VendorID = Top->Tag;
89
90 // while (Block->Next)
91 // {
92 // struct Vendor::Fingerprint Fingerprint = new struct Vendor::Fingerprint;
93 // Fingerprint->Print = Block.Find("Fingerprint");
94 // Fingerprint->Description = Block.Find("Name");
95 // if (Fingerprint->print.empty() || Fingerprint->Description.empty())
96 // {
97 // _error->Error(_("Vendor block %s is invalid"),
98 // Vendor->VendorID.c_str());
99 // delete Fingerprint;
100 // break;
101 // }
102 // Block = Block->Next->Next;
103 // }
104 // if (_error->PendingError())
105 // {
106 // for (vector <struct Vendor::Fingerprint *>::iterator I = Fingerprints.begin();
107 // I != Fingerprints.end(); I++)
108 // delete *I;
109 // delete Fingerprints;
110 // continue;
111 // }
112
113 // VendorList.push_back(new Vendor(VendorID, Fingerprints));
114 }
115
116 return !_error->PendingError();
117 }
118 /*}}}*/
119 const Vendor* pkgVendorList::LookupFingerprint(string Fingerprint) /*{{{*/
120 {
121 for (const_iterator I = VendorList.begin(); I != VendorList.end(); ++I)
122 {
123 if ((*I)->LookupFingerprint(Fingerprint) != "")
124 return *I;
125 }
126
127 return NULL;
128 }
129 /*}}}*/
130 const Vendor* pkgVendorList::FindVendor(const std::vector<string> GPGVOutput) /*{{{*/
131 {
132 for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); I++)
133 {
134 string::size_type pos = (*I).find("VALIDSIG ");
135 if (_config->FindB("Debug::Vendor", false))
136 std::cerr << "Looking for VALIDSIG in \"" << (*I) << "\": pos " << pos << std::endl;
137 if (pos != std::string::npos)
138 {
139 string Fingerprint = (*I).substr(pos+sizeof("VALIDSIG"));
140 if (_config->FindB("Debug::Vendor", false))
141 std::cerr << "Looking for \"" << Fingerprint << "\" in vendor..." << std::endl;
142 const Vendor* vendor = this->LookupFingerprint(Fingerprint);
143 if (vendor != NULL)
144 return vendor;
145 }
146 }
147
148 return NULL;
149 }
150 /*}}}*/
151
152 #if __GNUC__ >= 4
153 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
154 #endif