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