File: vendorlist.cc

package info (click to toggle)
apt 1.0.9.8.4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 15,080 kB
  • ctags: 5,307
  • sloc: cpp: 50,972; sh: 12,111; xml: 4,130; makefile: 855; perl: 209; python: 28
file content (168 lines) | stat: -rw-r--r-- 5,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include<config.h>

#include <apt-pkg/fileutl.h>
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>

#include <stddef.h>
#include <iostream>
#include <string>
#include <vector>

#include <apti18n.h>

#if __GNUC__ >= 4
	#pragma GCC diagnostic push
	#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

#include <apt-pkg/vendor.h>
#include <apt-pkg/vendorlist.h>

using std::string;
using std::vector;

pkgVendorList::~pkgVendorList()
{
   for (vector<const Vendor *>::const_iterator I = VendorList.begin(); 
        I != VendorList.end(); ++I)
      delete *I;
}

// pkgVendorList::ReadMainList - Read list of known package vendors	/*{{{*/
// ---------------------------------------------------------------------
/* This also scans a directory of vendor files similar to apt.conf.d 
   which can contain the usual suspects of distribution provided data.
   The APT config mechanism allows the user to override these in their
   configuration file. */
bool pkgVendorList::ReadMainList()
{
   Configuration Cnf;

   string CnfFile = _config->FindDir("Dir::Etc::vendorparts");
   if (DirectoryExists(CnfFile) == true)
      if (ReadConfigDir(Cnf,CnfFile,true) == false)
	 return false;
   CnfFile = _config->FindFile("Dir::Etc::vendorlist");
   if (RealFileExists(CnfFile) == true)
      if (ReadConfigFile(Cnf,CnfFile,true) == false)
	 return false;

   return CreateList(Cnf);
}
									/*}}}*/
bool pkgVendorList::Read(string File)					/*{{{*/
{
   Configuration Cnf;
   if (ReadConfigFile(Cnf,File,true) == false)
      return false;

   return CreateList(Cnf);
}
									/*}}}*/
bool pkgVendorList::CreateList(Configuration& Cnf)			/*{{{*/
{
   for (vector<const Vendor *>::const_iterator I = VendorList.begin(); 
	I != VendorList.end(); ++I)
      delete *I;
   VendorList.erase(VendorList.begin(),VendorList.end());

   const Configuration::Item *Top = Cnf.Tree("Vendor");
   for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
   {
      Configuration Block(Top);
      string VendorID = Top->Tag;
      vector <struct Vendor::Fingerprint *> *Fingerprints = new vector<Vendor::Fingerprint *>;
      struct Vendor::Fingerprint *Fingerprint = new struct Vendor::Fingerprint();
      string Origin = Block.Find("Origin");

      Fingerprint->Print = Block.Find("Fingerprint");
      Fingerprint->Description = Block.Find("Name");
      Fingerprints->push_back(Fingerprint);

      if (Fingerprint->Print.empty() || Fingerprint->Description.empty())
      {
         _error->Error(_("Vendor block %s contains no fingerprint"), VendorID.c_str());
         delete Fingerprints;
         continue;
      }
      if (_config->FindB("Debug::sourceList", false)) 
         std::cerr << "Adding vendor with ID: " << VendorID
		   << " Fingerprint: " << Fingerprint->Print << std::endl;

      VendorList.push_back(new Vendor(VendorID, Origin, Fingerprints));
   }

   /* Process 'group-key' type sections */
   Top = Cnf.Tree("group-key");
   for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
   {
//       Configuration Block(Top);
//       vector<Vendor::Fingerprint *> Fingerprints;
//       string VendorID = Top->Tag;

//       while (Block->Next)
//       {
// 	 struct Vendor::Fingerprint Fingerprint = new struct Vendor::Fingerprint;
// 	 Fingerprint->Print = Block.Find("Fingerprint");
// 	 Fingerprint->Description = Block.Find("Name");
// 	 if (Fingerprint->print.empty() || Fingerprint->Description.empty())
// 	 {
// 	    _error->Error(_("Vendor block %s is invalid"), 
// 			  Vendor->VendorID.c_str());
// 	    delete Fingerprint;
// 	    break;
// 	 }
// 	 Block = Block->Next->Next;
//       }
//       if (_error->PendingError())
//       {
// 	 for (vector <struct Vendor::Fingerprint *>::iterator I = Fingerprints.begin();
// 	      I != Fingerprints.end(); I++)
// 	    delete *I;
// 	 delete Fingerprints;
// 	 continue;
//       }

//       VendorList.push_back(new Vendor(VendorID, Fingerprints));
   }
   
   return !_error->PendingError();
}
									/*}}}*/
const Vendor* pkgVendorList::LookupFingerprint(string Fingerprint)	/*{{{*/
{
   for (const_iterator I = VendorList.begin(); I != VendorList.end(); ++I)
   {
      if ((*I)->LookupFingerprint(Fingerprint) != "")
         return *I;
   }

   return NULL;
}
									/*}}}*/
const Vendor* pkgVendorList::FindVendor(const std::vector<string> GPGVOutput)	/*{{{*/
{
   for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); ++I)
   {
      string::size_type pos = (*I).find("VALIDSIG ");
      if (_config->FindB("Debug::Vendor", false))
         std::cerr << "Looking for VALIDSIG in \"" << (*I) << "\": pos " << pos << std::endl;
      if (pos != std::string::npos)
      {
         string Fingerprint = (*I).substr(pos+sizeof("VALIDSIG"));
         if (_config->FindB("Debug::Vendor", false))
            std::cerr << "Looking for \"" << Fingerprint << "\" in vendor..." << std::endl;
         const Vendor* vendor = this->LookupFingerprint(Fingerprint);
         if (vendor != NULL)
            return vendor;
      }
   }

   return NULL;
}
									/*}}}*/

#if __GNUC__ >= 4
	#pragma GCC diagnostic pop
#endif