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