]> git.saurik.com Git - apt.git/blob - apt-pkg/vendorlist.cc
2ccb556ab60b8f652bc1624b1fd2c2b220641d03
[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 <apti18n.h>
6
7 #if __GNUC__ >= 4
8 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
9 #endif
10
11 #include <apt-pkg/vendorlist.h>
12
13 using std::string;
14 using std::vector;
15
16 pkgVendorList::~pkgVendorList()
17 {
18 for (vector<const Vendor *>::const_iterator I = VendorList.begin();
19 I != VendorList.end(); ++I)
20 delete *I;
21 }
22
23 // pkgVendorList::ReadMainList - Read list of known package vendors /*{{{*/
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");
34 if (DirectoryExists(CnfFile) == true)
35 if (ReadConfigDir(Cnf,CnfFile,true) == false)
36 return false;
37 CnfFile = _config->FindFile("Dir::Etc::vendorlist");
38 if (RealFileExists(CnfFile) == true)
39 if (ReadConfigFile(Cnf,CnfFile,true) == false)
40 return false;
41
42 return CreateList(Cnf);
43 }
44 /*}}}*/
45 bool pkgVendorList::Read(string File) /*{{{*/
46 {
47 Configuration Cnf;
48 if (ReadConfigFile(Cnf,File,true) == false)
49 return false;
50
51 return CreateList(Cnf);
52 }
53 /*}}}*/
54 bool pkgVendorList::CreateList(Configuration& Cnf) /*{{{*/
55 {
56 for (vector<const Vendor *>::const_iterator I = VendorList.begin();
57 I != VendorList.end(); ++I)
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 }
123 /*}}}*/
124 const Vendor* pkgVendorList::LookupFingerprint(string Fingerprint) /*{{{*/
125 {
126 for (const_iterator I = VendorList.begin(); I != VendorList.end(); ++I)
127 {
128 if ((*I)->LookupFingerprint(Fingerprint) != "")
129 return *I;
130 }
131
132 return NULL;
133 }
134 /*}}}*/
135 const Vendor* pkgVendorList::FindVendor(const std::vector<string> GPGVOutput) /*{{{*/
136 {
137 for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); ++I)
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 }
155 /*}}}*/
156
157 #if __GNUC__ >= 4
158 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
159 #endif