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