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