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