]>
Commit | Line | Data |
---|---|---|
ea542140 | 1 | #include <config.h> |
7db98ffc | 2 | |
b07aeb1a | 3 | #include <apt-pkg/error.h> |
7db98ffc MZ |
4 | #include <apt-pkg/debmetaindex.h> |
5 | #include <apt-pkg/debindexfile.h> | |
6 | #include <apt-pkg/strutl.h> | |
472ff00e | 7 | #include <apt-pkg/fileutl.h> |
7db98ffc MZ |
8 | #include <apt-pkg/acquire-item.h> |
9 | #include <apt-pkg/configuration.h> | |
45df0ad2 | 10 | #include <apt-pkg/aptconfiguration.h> |
472ff00e | 11 | #include <apt-pkg/sourcelist.h> |
453b82a3 | 12 | #include <apt-pkg/hashes.h> |
453b82a3 | 13 | #include <apt-pkg/metaindex.h> |
b07aeb1a DK |
14 | #include <apt-pkg/pkgcachegen.h> |
15 | #include <apt-pkg/tagfile.h> | |
16 | #include <apt-pkg/gpgv.h> | |
17 | #include <apt-pkg/macros.h> | |
7db98ffc | 18 | |
453b82a3 DK |
19 | #include <map> |
20 | #include <string> | |
21 | #include <utility> | |
22 | #include <vector> | |
7cb28948 | 23 | #include <algorithm> |
5dd4c8b8 | 24 | |
b07aeb1a | 25 | #include <sys/stat.h> |
b07aeb1a DK |
26 | #include <string.h> |
27 | ||
268ffceb DK |
28 | #include <apti18n.h> |
29 | ||
463c8d80 DK |
30 | class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ |
31 | { | |
32 | public: | |
33 | struct APT_HIDDEN debSectionEntry | |
34 | { | |
35 | std::string Name; | |
36 | std::vector<std::string> Targets; | |
37 | std::vector<std::string> Architectures; | |
38 | std::vector<std::string> Languages; | |
39 | }; | |
40 | ||
41 | std::vector<debSectionEntry> DebEntries; | |
42 | std::vector<debSectionEntry> DebSrcEntries; | |
268ffceb | 43 | |
0741daeb DK |
44 | metaIndex::TriState CheckValidUntil; |
45 | time_t ValidUntilMin; | |
46 | time_t ValidUntilMax; | |
47 | ||
48 | debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {} | |
463c8d80 DK |
49 | }; |
50 | /*}}}*/ | |
51 | // ReleaseIndex::MetaIndex* - display helpers /*{{{*/ | |
52 | std::string debReleaseIndex::MetaIndexInfo(const char *Type) const | |
7db98ffc | 53 | { |
463c8d80 | 54 | std::string Info = ::URI::ArchiveOnly(URI) + ' '; |
7db98ffc MZ |
55 | if (Dist[Dist.size() - 1] == '/') |
56 | { | |
57 | if (Dist != "/") | |
58 | Info += Dist; | |
59 | } | |
60 | else | |
61 | Info += Dist; | |
62 | Info += " "; | |
63 | Info += Type; | |
64 | return Info; | |
65 | } | |
b07aeb1a DK |
66 | std::string debReleaseIndex::Describe() const |
67 | { | |
68 | return MetaIndexInfo("Release"); | |
69 | } | |
7db98ffc | 70 | |
463c8d80 | 71 | std::string debReleaseIndex::MetaIndexFile(const char *Type) const |
7db98ffc MZ |
72 | { |
73 | return _config->FindDir("Dir::State::lists") + | |
74 | URItoFileName(MetaIndexURI(Type)); | |
75 | } | |
76 | ||
463c8d80 | 77 | std::string debReleaseIndex::MetaIndexURI(const char *Type) const |
7db98ffc | 78 | { |
463c8d80 | 79 | std::string Res; |
7db98ffc MZ |
80 | |
81 | if (Dist == "/") | |
82 | Res = URI; | |
83 | else if (Dist[Dist.size()-1] == '/') | |
84 | Res = URI + Dist; | |
85 | else | |
86 | Res = URI + "dists/" + Dist + "/"; | |
87 | ||
88 | Res += Type; | |
89 | return Res; | |
90 | } | |
463c8d80 | 91 | /*}}}*/ |
463c8d80 DK |
92 | // ReleaseIndex Con- and Destructors /*{{{*/ |
93 | debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) : | |
268ffceb | 94 | metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) |
4b42f43b | 95 | {} |
5ad0096a DK |
96 | debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted) : |
97 | metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) | |
98 | { | |
99 | Trusted = pTrusted ? TRI_YES : TRI_NO; | |
100 | } | |
5dd4c8b8 | 101 | debReleaseIndex::~debReleaseIndex() { |
463c8d80 DK |
102 | if (d != NULL) |
103 | delete d; | |
7a9f09bd | 104 | } |
463c8d80 DK |
105 | /*}}}*/ |
106 | // ReleaseIndex::GetIndexTargets /*{{{*/ | |
107 | static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist, | |
108 | std::vector<debReleaseIndexPrivate::debSectionEntry> const &entries, | |
109 | std::vector<IndexTarget> &IndexTargets) | |
1e0f0f28 | 110 | { |
1e0f0f28 DK |
111 | bool const flatArchive = (Dist[Dist.length() - 1] == '/'); |
112 | std::string baseURI = URI; | |
113 | if (flatArchive) | |
114 | { | |
115 | if (Dist != "/") | |
116 | baseURI += Dist; | |
117 | } | |
118 | else | |
119 | baseURI += "dists/" + Dist + "/"; | |
120 | std::string const Release = (Dist == "/") ? "" : Dist; | |
1da3b7b8 | 121 | std::string const Site = ::URI::ArchiveOnly(URI); |
463c8d80 | 122 | |
653ef26c | 123 | bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false); |
463c8d80 | 124 | for (std::vector<debReleaseIndexPrivate::debSectionEntry>::const_iterator E = entries.begin(); E != entries.end(); ++E) |
1e0f0f28 | 125 | { |
463c8d80 | 126 | for (std::vector<std::string>::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T) |
1e0f0f28 | 127 | { |
c2a4a8dd | 128 | #define APT_T_CONFIG(X) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X)) |
463c8d80 DK |
129 | std::string const tplMetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); |
130 | std::string const tplShortDesc = APT_T_CONFIG("ShortDescription"); | |
c2a4a8dd DK |
131 | std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); |
132 | bool const IsOptional = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::Optional", true); | |
133 | bool const KeepCompressed = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::KeepCompressed", GzipIndex); | |
1e0f0f28 | 134 | #undef APT_T_CONFIG |
463c8d80 | 135 | if (tplMetaKey.empty()) |
1e0f0f28 DK |
136 | continue; |
137 | ||
463c8d80 | 138 | for (std::vector<std::string>::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L) |
1e0f0f28 | 139 | { |
463c8d80 DK |
140 | if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos) |
141 | continue; | |
142 | ||
143 | for (std::vector<std::string>::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A) | |
1e0f0f28 | 144 | { |
1e0f0f28 | 145 | |
d3a869e3 DK |
146 | std::map<std::string, std::string> Options; |
147 | Options.insert(std::make_pair("SITE", Site)); | |
148 | Options.insert(std::make_pair("RELEASE", Release)); | |
463c8d80 DK |
149 | if (tplMetaKey.find("$(COMPONENT)") != std::string::npos) |
150 | Options.insert(std::make_pair("COMPONENT", E->Name)); | |
151 | if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos) | |
152 | Options.insert(std::make_pair("LANGUAGE", *L)); | |
153 | if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos) | |
154 | Options.insert(std::make_pair("ARCHITECTURE", *A)); | |
d3a869e3 | 155 | Options.insert(std::make_pair("BASE_URI", baseURI)); |
e3c1cfc7 | 156 | Options.insert(std::make_pair("REPO_URI", URI)); |
b47b1222 | 157 | Options.insert(std::make_pair("TARGET_OF", Type)); |
d3a869e3 | 158 | Options.insert(std::make_pair("CREATED_BY", *T)); |
d3a869e3 | 159 | |
463c8d80 DK |
160 | std::string MetaKey = tplMetaKey; |
161 | std::string ShortDesc = tplShortDesc; | |
162 | std::string LongDesc = tplLongDesc; | |
163 | for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O) | |
164 | { | |
165 | MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second); | |
166 | ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); | |
167 | LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); | |
168 | } | |
169 | IndexTarget Target( | |
170 | MetaKey, | |
171 | ShortDesc, | |
172 | LongDesc, | |
173 | Options.find("BASE_URI")->second + MetaKey, | |
174 | IsOptional, | |
653ef26c | 175 | KeepCompressed, |
463c8d80 DK |
176 | Options |
177 | ); | |
178 | IndexTargets.push_back(Target); | |
179 | ||
180 | if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos) | |
1e0f0f28 | 181 | break; |
d3a869e3 | 182 | |
1e0f0f28 DK |
183 | } |
184 | ||
463c8d80 | 185 | if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos) |
1e0f0f28 | 186 | break; |
463c8d80 | 187 | |
1e0f0f28 DK |
188 | } |
189 | ||
1e0f0f28 DK |
190 | } |
191 | } | |
59148d96 | 192 | } |
261727f0 | 193 | std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const |
59148d96 | 194 | { |
463c8d80 DK |
195 | std::vector<IndexTarget> IndexTargets; |
196 | GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets); | |
197 | GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets); | |
198 | return IndexTargets; | |
7db98ffc | 199 | } |
463c8d80 DK |
200 | /*}}}*/ |
201 | void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{{{*/ | |
202 | std::vector<std::string> const &Targets, | |
203 | std::vector<std::string> const &Architectures, | |
204 | std::vector<std::string> Languages) | |
205 | { | |
206 | if (Languages.empty() == true) | |
207 | Languages.push_back("none"); | |
208 | debReleaseIndexPrivate::debSectionEntry const entry = { | |
209 | Name, Targets, Architectures, Languages | |
210 | }; | |
211 | if (isSrc) | |
212 | d->DebSrcEntries.push_back(entry); | |
213 | else | |
214 | d->DebEntries.push_back(entry); | |
215 | } | |
216 | /*}}}*/ | |
59148d96 | 217 | |
5ad0096a DK |
218 | bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/ |
219 | { | |
220 | LoadedSuccessfully = TRI_NO; | |
221 | FileFd Fd; | |
222 | if (OpenMaybeClearSignedFile(Filename, Fd) == false) | |
223 | return false; | |
224 | ||
225 | pkgTagFile TagFile(&Fd, Fd.Size()); | |
226 | if (_error->PendingError() == true) | |
227 | { | |
228 | if (ErrorText != NULL) | |
229 | strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str()); | |
230 | return false; | |
231 | } | |
232 | ||
233 | pkgTagSection Section; | |
234 | const char *Start, *End; | |
235 | if (TagFile.Step(Section) == false) | |
236 | { | |
237 | if (ErrorText != NULL) | |
238 | strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str()); | |
239 | return false; | |
240 | } | |
241 | // FIXME: find better tag name | |
242 | SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false); | |
243 | ||
244 | Suite = Section.FindS("Suite"); | |
245 | Codename = Section.FindS("Codename"); | |
246 | ||
247 | bool FoundHashSum = false; | |
248 | for (int i=0;HashString::SupportedHashes()[i] != NULL; i++) | |
249 | { | |
250 | if (!Section.Find(HashString::SupportedHashes()[i], Start, End)) | |
251 | continue; | |
252 | ||
253 | std::string Name; | |
254 | std::string Hash; | |
255 | unsigned long long Size; | |
256 | while (Start < End) | |
257 | { | |
258 | if (!parseSumData(Start, End, Name, Hash, Size)) | |
259 | return false; | |
260 | ||
261 | if (Entries.find(Name) == Entries.end()) | |
262 | { | |
263 | metaIndex::checkSum *Sum = new metaIndex::checkSum; | |
264 | Sum->MetaKeyFilename = Name; | |
265 | Sum->Size = Size; | |
266 | Sum->Hashes.FileSize(Size); | |
267 | APT_IGNORE_DEPRECATED(Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);) | |
268 | Entries[Name] = Sum; | |
269 | } | |
270 | Entries[Name]->Hashes.push_back(HashString(HashString::SupportedHashes()[i],Hash)); | |
271 | FoundHashSum = true; | |
272 | } | |
273 | } | |
274 | ||
275 | if(FoundHashSum == false) | |
276 | { | |
277 | if (ErrorText != NULL) | |
278 | strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); | |
279 | return false; | |
280 | } | |
281 | ||
282 | std::string const StrDate = Section.FindS("Date"); | |
283 | if (RFC1123StrToTime(StrDate.c_str(), Date) == false) | |
284 | { | |
285 | if (ErrorText != NULL) | |
286 | strprintf(*ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); | |
287 | return false; | |
288 | } | |
289 | ||
0741daeb DK |
290 | bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true); |
291 | if (d->CheckValidUntil == metaIndex::TRI_NO) | |
292 | CheckValidUntil = false; | |
293 | else if (d->CheckValidUntil == metaIndex::TRI_YES) | |
294 | CheckValidUntil = true; | |
5ad0096a | 295 | |
0741daeb | 296 | if (CheckValidUntil == true) |
5ad0096a | 297 | { |
0741daeb DK |
298 | std::string const Label = Section.FindS("Label"); |
299 | std::string const StrValidUntil = Section.FindS("Valid-Until"); | |
300 | ||
301 | // if we have a Valid-Until header in the Release file, use it as default | |
302 | if (StrValidUntil.empty() == false) | |
5ad0096a | 303 | { |
0741daeb DK |
304 | if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) |
305 | { | |
306 | if (ErrorText != NULL) | |
307 | strprintf(*ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); | |
308 | return false; | |
309 | } | |
310 | } | |
311 | // get the user settings for this archive and use what expires earlier | |
312 | time_t MaxAge = d->ValidUntilMax; | |
313 | if (MaxAge == 0) | |
314 | { | |
315 | MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); | |
316 | if (Label.empty() == false) | |
317 | MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); | |
318 | } | |
319 | time_t MinAge = d->ValidUntilMin; | |
320 | if (MinAge == 0) | |
321 | { | |
322 | MinAge = _config->FindI("Acquire::Min-ValidTime", 0); | |
323 | if (Label.empty() == false) | |
324 | MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge); | |
5ad0096a | 325 | } |
5ad0096a | 326 | |
0741daeb DK |
327 | if (MinAge != 0 && ValidUntil != 0) { |
328 | time_t const min_date = Date + MinAge; | |
329 | if (ValidUntil < min_date) | |
330 | ValidUntil = min_date; | |
331 | } | |
332 | if (MaxAge != 0) { | |
333 | time_t const max_date = Date + MaxAge; | |
334 | if (ValidUntil == 0 || ValidUntil > max_date) | |
335 | ValidUntil = max_date; | |
336 | } | |
5ad0096a | 337 | } |
59148d96 | 338 | |
0741daeb | 339 | LoadedSuccessfully = TRI_YES; |
5ad0096a DK |
340 | return true; |
341 | } | |
342 | /*}}}*/ | |
343 | metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/ | |
344 | { | |
345 | if (Trusted == TRI_NO) | |
346 | return new debReleaseIndex(URI, Dist, false); | |
347 | else if (Trusted == TRI_YES) | |
348 | return new debReleaseIndex(URI, Dist, true); | |
349 | else | |
350 | return new debReleaseIndex(URI, Dist); | |
351 | } | |
352 | /*}}}*/ | |
353 | bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/ | |
354 | std::string &Name, std::string &Hash, unsigned long long &Size) | |
7db98ffc | 355 | { |
5ad0096a DK |
356 | Name = ""; |
357 | Hash = ""; | |
358 | Size = 0; | |
359 | /* Skip over the first blank */ | |
360 | while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r') | |
361 | && Start < End) | |
362 | Start++; | |
363 | if (Start >= End) | |
364 | return false; | |
07cb47e7 | 365 | |
5ad0096a DK |
366 | /* Move EntryEnd to the end of the first entry (the hash) */ |
367 | const char *EntryEnd = Start; | |
368 | while ((*EntryEnd != '\t' && *EntryEnd != ' ') | |
369 | && EntryEnd < End) | |
370 | EntryEnd++; | |
371 | if (EntryEnd == End) | |
372 | return false; | |
373 | ||
374 | Hash.append(Start, EntryEnd-Start); | |
375 | ||
376 | /* Skip over intermediate blanks */ | |
377 | Start = EntryEnd; | |
378 | while (*Start == '\t' || *Start == ' ') | |
379 | Start++; | |
380 | if (Start >= End) | |
381 | return false; | |
382 | ||
383 | EntryEnd = Start; | |
384 | /* Find the end of the second entry (the size) */ | |
385 | while ((*EntryEnd != '\t' && *EntryEnd != ' ' ) | |
386 | && EntryEnd < End) | |
387 | EntryEnd++; | |
388 | if (EntryEnd == End) | |
389 | return false; | |
390 | ||
391 | Size = strtoull (Start, NULL, 10); | |
392 | ||
393 | /* Skip over intermediate blanks */ | |
394 | Start = EntryEnd; | |
395 | while (*Start == '\t' || *Start == ' ') | |
396 | Start++; | |
397 | if (Start >= End) | |
398 | return false; | |
399 | ||
400 | EntryEnd = Start; | |
401 | /* Find the end of the third entry (the filename) */ | |
402 | while ((*EntryEnd != '\t' && *EntryEnd != ' ' && | |
403 | *EntryEnd != '\n' && *EntryEnd != '\r') | |
404 | && EntryEnd < End) | |
405 | EntryEnd++; | |
406 | ||
407 | Name.append(Start, EntryEnd-Start); | |
408 | Start = EntryEnd; //prepare for the next round | |
409 | return true; | |
410 | } | |
411 | /*}}}*/ | |
412 | ||
413 | bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/ | |
414 | { | |
261727f0 | 415 | std::vector<IndexTarget> const targets = GetIndexTargets(); |
653ef26c | 416 | #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map<std::string,std::string>()) |
3d8232bf | 417 | pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner, |
448c38bd | 418 | APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), |
5ad0096a | 419 | targets, this); |
448c38bd | 420 | #undef APT_TARGET |
5ad0096a | 421 | // special case for --print-uris |
448c38bd DK |
422 | if (GetAll) |
423 | { | |
dcbbb14d | 424 | for (std::vector<IndexTarget>::const_iterator Target = targets.begin(); Target != targets.end(); ++Target) |
448c38bd | 425 | new pkgAcqIndex(Owner, TransactionManager, *Target); |
7db98ffc | 426 | } |
fe0f7911 | 427 | |
55971004 | 428 | return true; |
7db98ffc | 429 | } |
463c8d80 | 430 | /*}}}*/ |
0741daeb | 431 | // ReleaseIndex::Set* TriState options /*{{{*/ |
5ad0096a | 432 | bool debReleaseIndex::SetTrusted(TriState const pTrusted) |
4b42f43b | 433 | { |
5ad0096a DK |
434 | if (Trusted == TRI_UNSET) |
435 | Trusted = pTrusted; | |
436 | else if (Trusted != pTrusted) | |
268ffceb DK |
437 | // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite |
438 | return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str()); | |
439 | return true; | |
4b42f43b | 440 | } |
0741daeb DK |
441 | bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil) |
442 | { | |
443 | if (d->CheckValidUntil == TRI_UNSET) | |
444 | d->CheckValidUntil = pCheckValidUntil; | |
445 | else if (d->CheckValidUntil != pCheckValidUntil) | |
446 | return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str()); | |
447 | return true; | |
448 | } | |
449 | bool debReleaseIndex::SetValidUntilMin(time_t const Valid) | |
450 | { | |
451 | if (d->ValidUntilMin == 0) | |
452 | d->ValidUntilMin = Valid; | |
453 | else if (d->ValidUntilMin != Valid) | |
454 | return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str()); | |
455 | return true; | |
456 | } | |
457 | bool debReleaseIndex::SetValidUntilMax(time_t const Valid) | |
458 | { | |
459 | if (d->ValidUntilMax == 0) | |
460 | d->ValidUntilMax = Valid; | |
461 | else if (d->ValidUntilMax != Valid) | |
462 | return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str()); | |
463 | return true; | |
b0d40854 DK |
464 | } |
465 | bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy) | |
466 | { | |
467 | if (SignedBy.empty() == true && pSignedBy.empty() == false) | |
468 | { | |
469 | if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things | |
470 | ; // absolute path to a keyring file | |
471 | else | |
472 | { | |
473 | // we could go all fancy and allow short/long/string matches as gpgv/apt-key does, | |
474 | // but fingerprints are harder to fake than the others and this option is set once, | |
475 | // not interactively all the time so easy to type is not really a concern. | |
476 | std::string finger = pSignedBy; | |
477 | finger.erase(std::remove(finger.begin(), finger.end(), ' '), finger.end()); | |
478 | std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper); | |
479 | if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos) | |
480 | return _error->Error(_("Invalid value set for option %s concerning source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint"); | |
481 | } | |
482 | SignedBy = pSignedBy; | |
483 | } | |
484 | else if (SignedBy != pSignedBy) | |
485 | return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Signed-By", URI.c_str(), Dist.c_str()); | |
486 | return true; | |
0741daeb DK |
487 | } |
488 | /*}}}*/ | |
489 | // ReleaseIndex::IsTrusted /*{{{*/ | |
7db98ffc MZ |
490 | bool debReleaseIndex::IsTrusted() const |
491 | { | |
5ad0096a | 492 | if (Trusted == TRI_YES) |
4b42f43b | 493 | return true; |
5ad0096a | 494 | else if (Trusted == TRI_NO) |
4b42f43b DK |
495 | return false; |
496 | ||
497 | ||
4e0ad446 | 498 | if(_config->FindB("APT::Authentication::TrustCDROM", false)) |
e8cdc56a MV |
499 | if(URI.substr(0,strlen("cdrom:")) == "cdrom:") |
500 | return true; | |
fe0f7911 | 501 | |
463c8d80 | 502 | if (FileExists(MetaIndexFile("Release.gpg"))) |
7db98ffc | 503 | return true; |
fe0f7911 | 504 | |
463c8d80 | 505 | return FileExists(MetaIndexFile("InRelease")); |
7db98ffc | 506 | } |
463c8d80 DK |
507 | /*}}}*/ |
508 | std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() /*{{{*/ | |
59148d96 | 509 | { |
e3c1cfc7 DK |
510 | if (Indexes != NULL) |
511 | return Indexes; | |
59148d96 | 512 | |
e3c1cfc7 DK |
513 | Indexes = new std::vector<pkgIndexFile*>(); |
514 | std::vector<IndexTarget> const Targets = GetIndexTargets(); | |
515 | bool const istrusted = IsTrusted(); | |
516 | for (std::vector<IndexTarget>::const_iterator T = Targets.begin(); T != Targets.end(); ++T) | |
59148d96 | 517 | { |
001c76fe | 518 | std::string const TargetName = T->Option(IndexTarget::CREATED_BY); |
59148d96 | 519 | if (TargetName == "Packages") |
e3c1cfc7 | 520 | Indexes->push_back(new debPackagesIndex(*T, istrusted)); |
59148d96 | 521 | else if (TargetName == "Sources") |
e3c1cfc7 | 522 | Indexes->push_back(new debSourcesIndex(*T, istrusted)); |
59148d96 | 523 | else if (TargetName == "Translations") |
e3c1cfc7 | 524 | Indexes->push_back(new debTranslationsIndex(*T)); |
59148d96 | 525 | } |
e3c1cfc7 | 526 | return Indexes; |
5dd4c8b8 | 527 | } |
463c8d80 | 528 | /*}}}*/ |
a7a5b0d9 | 529 | |
463c8d80 | 530 | static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/ |
b07aeb1a DK |
531 | { |
532 | ReleaseFile = That->MetaIndexFile("InRelease"); | |
533 | bool releaseExists = false; | |
534 | if (FileExists(ReleaseFile) == true) | |
535 | releaseExists = true; | |
536 | else | |
537 | { | |
538 | ReleaseFile = That->MetaIndexFile("Release"); | |
539 | if (FileExists(ReleaseFile)) | |
540 | releaseExists = true; | |
541 | } | |
542 | return releaseExists; | |
543 | } | |
463c8d80 | 544 | /*}}}*/ |
b07aeb1a DK |
545 | bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/ |
546 | { | |
547 | std::string ReleaseFile; | |
548 | bool const releaseExists = ReleaseFileName(this, ReleaseFile); | |
549 | ||
550 | ::URI Tmp(URI); | |
551 | if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false) | |
552 | return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str()); | |
553 | ||
554 | if (releaseExists == false) | |
555 | return true; | |
556 | ||
557 | FileFd Rel; | |
558 | // Beware: The 'Release' file might be clearsigned in case the | |
559 | // signature for an 'InRelease' file couldn't be checked | |
560 | if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false) | |
561 | return false; | |
562 | if (_error->PendingError() == true) | |
563 | return false; | |
564 | ||
565 | // Store the IMS information | |
566 | pkgCache::RlsFileIterator File = Gen.GetCurRlsFile(); | |
567 | pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File); | |
568 | // Rel can't be used as this is potentially a temporary file | |
569 | struct stat Buf; | |
570 | if (stat(ReleaseFile.c_str(), &Buf) != 0) | |
571 | return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str()); | |
572 | File->Size = Buf.st_size; | |
573 | File->mtime = Buf.st_mtime; | |
574 | ||
575 | pkgTagFile TagFile(&Rel, Rel.Size()); | |
576 | pkgTagSection Section; | |
577 | if (_error->PendingError() == true || TagFile.Step(Section) == false) | |
578 | return false; | |
579 | ||
580 | std::string data; | |
581 | #define APT_INRELEASE(TYPE, TAG, STORE) \ | |
582 | data = Section.FindS(TAG); \ | |
583 | if (data.empty() == false) \ | |
584 | { \ | |
585 | map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \ | |
586 | STORE = storage; \ | |
587 | } | |
588 | APT_INRELEASE(MIXED, "Suite", File->Archive) | |
589 | APT_INRELEASE(VERSIONNUMBER, "Version", File->Version) | |
590 | APT_INRELEASE(MIXED, "Origin", File->Origin) | |
591 | APT_INRELEASE(MIXED, "Codename", File->Codename) | |
592 | APT_INRELEASE(MIXED, "Label", File->Label) | |
593 | #undef APT_INRELEASE | |
594 | Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic); | |
595 | Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades); | |
596 | ||
597 | return !_error->PendingError(); | |
598 | } | |
599 | /*}}}*/ | |
600 | // ReleaseIndex::FindInCache - Find this index /*{{{*/ | |
3fd89e62 | 601 | pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const |
b07aeb1a DK |
602 | { |
603 | std::string ReleaseFile; | |
604 | bool const releaseExists = ReleaseFileName(this, ReleaseFile); | |
605 | ||
606 | pkgCache::RlsFileIterator File = Cache.RlsFileBegin(); | |
607 | for (; File.end() == false; ++File) | |
608 | { | |
609 | if (File->FileName == 0 || ReleaseFile != File.FileName()) | |
610 | continue; | |
611 | ||
612 | // empty means the file does not exist by "design" | |
3fd89e62 | 613 | if (ModifyCheck == false || (releaseExists == false && File->Size == 0)) |
b07aeb1a DK |
614 | return File; |
615 | ||
616 | struct stat St; | |
617 | if (stat(File.FileName(),&St) != 0) | |
618 | { | |
619 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
620 | std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
621 | return pkgCache::RlsFileIterator(Cache); | |
622 | } | |
623 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) | |
624 | { | |
625 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
626 | std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
627 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
628 | << ") doesn't match for " << File.FileName() << std::endl; | |
629 | return pkgCache::RlsFileIterator(Cache); | |
630 | } | |
631 | return File; | |
632 | } | |
633 | ||
634 | return File; | |
635 | } | |
636 | /*}}}*/ | |
637 | ||
463c8d80 DK |
638 | static std::vector<std::string> parsePlusMinusOptions(std::string const &Name, /*{{{*/ |
639 | std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues) | |
7db98ffc | 640 | { |
463c8d80 DK |
641 | std::map<std::string, std::string>::const_iterator val = Options.find(Name); |
642 | std::vector<std::string> Values; | |
643 | if (val != Options.end()) | |
644 | Values = VectorizeString(val->second, ','); | |
645 | else | |
646 | Values = defaultValues; | |
7db98ffc | 647 | |
463c8d80 | 648 | if ((val = Options.find(Name + "+")) != Options.end()) |
7db98ffc | 649 | { |
463c8d80 DK |
650 | std::vector<std::string> const plusArch = VectorizeString(val->second, ','); |
651 | for (std::vector<std::string>::const_iterator plus = plusArch.begin(); plus != plusArch.end(); ++plus) | |
652 | if (std::find(Values.begin(), Values.end(), *plus) == Values.end()) | |
653 | Values.push_back(*plus); | |
654 | } | |
655 | if ((val = Options.find(Name + "-")) != Options.end()) | |
656 | { | |
657 | std::vector<std::string> const minusArch = VectorizeString(val->second, ','); | |
658 | for (std::vector<std::string>::const_iterator minus = minusArch.begin(); minus != minusArch.end(); ++minus) | |
3d1be93d | 659 | { |
463c8d80 DK |
660 | std::vector<std::string>::iterator kill = std::find(Values.begin(), Values.end(), *minus); |
661 | if (kill != Values.end()) | |
662 | Values.erase(kill); | |
3d1be93d | 663 | } |
463c8d80 DK |
664 | } |
665 | return Values; | |
666 | } | |
667 | /*}}}*/ | |
668 | class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ | |
669 | { | |
0741daeb DK |
670 | metaIndex::TriState GetTriStateOption(std::map<std::string, std::string>const &Options, char const * const name) const |
671 | { | |
672 | std::map<std::string, std::string>::const_iterator const opt = Options.find(name); | |
673 | if (opt != Options.end()) | |
674 | return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO; | |
675 | return metaIndex::TRI_DONTCARE; | |
676 | } | |
677 | ||
678 | time_t GetTimeOption(std::map<std::string, std::string>const &Options, char const * const name) const | |
679 | { | |
680 | std::map<std::string, std::string>::const_iterator const opt = Options.find(name); | |
681 | if (opt == Options.end()) | |
682 | return 0; | |
683 | return strtoull(opt->second.c_str(), NULL, 10); | |
684 | } | |
685 | ||
463c8d80 | 686 | protected: |
3d1be93d | 687 | |
463c8d80 DK |
688 | bool CreateItemInternal(std::vector<metaIndex *> &List, std::string const &URI, |
689 | std::string const &Dist, std::string const &Section, | |
690 | bool const &IsSrc, std::map<std::string, std::string> const &Options) const | |
691 | { | |
261727f0 | 692 | debReleaseIndex *Deb = NULL; |
463c8d80 | 693 | for (std::vector<metaIndex *>::const_iterator I = List.begin(); |
f7f0d6c7 | 694 | I != List.end(); ++I) |
7db98ffc | 695 | { |
5dd4c8b8 DK |
696 | // We only worry about debian entries here |
697 | if (strcmp((*I)->GetType(), "deb") != 0) | |
698 | continue; | |
699 | ||
5dd4c8b8 DK |
700 | /* This check insures that there will be only one Release file |
701 | queued for all the Packages files and Sources files it | |
702 | corresponds to. */ | |
261727f0 | 703 | if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist) |
7db98ffc | 704 | { |
261727f0 DK |
705 | Deb = dynamic_cast<debReleaseIndex*>(*I); |
706 | if (Deb != NULL) | |
707 | break; | |
7db98ffc MZ |
708 | } |
709 | } | |
4b42f43b | 710 | |
7db98ffc | 711 | // No currently created Release file indexes this entry, so we create a new one. |
261727f0 DK |
712 | if (Deb == NULL) |
713 | { | |
4b42f43b | 714 | Deb = new debReleaseIndex(URI, Dist); |
261727f0 DK |
715 | List.push_back(Deb); |
716 | } | |
4b42f43b | 717 | |
463c8d80 DK |
718 | Deb->AddComponent( |
719 | IsSrc, | |
720 | Section, | |
c2a4a8dd | 721 | parsePlusMinusOptions("target", Options, _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true)), |
463c8d80 DK |
722 | parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()), |
723 | parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)) | |
724 | ); | |
261727f0 | 725 | |
0741daeb DK |
726 | if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false || |
727 | Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false || | |
728 | Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false || | |
729 | Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false) | |
268ffceb | 730 | return false; |
261727f0 | 731 | |
b0d40854 DK |
732 | std::map<std::string, std::string>::const_iterator const signedby = Options.find("signed-by"); |
733 | if (signedby == Options.end()) | |
734 | { | |
735 | if (Deb->SetSignedBy("") == false) | |
736 | return false; | |
737 | } | |
738 | else | |
739 | { | |
740 | if (Deb->SetSignedBy(signedby->second) == false) | |
741 | return false; | |
742 | } | |
743 | ||
7db98ffc MZ |
744 | return true; |
745 | } | |
0d29b9d4 | 746 | |
463c8d80 DK |
747 | debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label) |
748 | { | |
749 | } | |
750 | }; | |
751 | /*}}}*/ | |
752 | class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/ | |
7db98ffc MZ |
753 | { |
754 | public: | |
755 | ||
463c8d80 DK |
756 | bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI, |
757 | std::string const &Dist, std::string const &Section, | |
3b302846 | 758 | std::map<std::string, std::string> const &Options) const APT_OVERRIDE |
7db98ffc | 759 | { |
5dd4c8b8 | 760 | return CreateItemInternal(List, URI, Dist, Section, false, Options); |
7db98ffc MZ |
761 | } |
762 | ||
463c8d80 | 763 | debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree") |
7db98ffc | 764 | { |
463c8d80 | 765 | } |
7db98ffc | 766 | }; |
463c8d80 DK |
767 | /*}}}*/ |
768 | class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/ | |
7db98ffc MZ |
769 | { |
770 | public: | |
771 | ||
463c8d80 DK |
772 | bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI, |
773 | std::string const &Dist, std::string const &Section, | |
3b302846 | 774 | std::map<std::string, std::string> const &Options) const APT_OVERRIDE |
7db98ffc | 775 | { |
5dd4c8b8 | 776 | return CreateItemInternal(List, URI, Dist, Section, true, Options); |
7db98ffc | 777 | } |
463c8d80 DK |
778 | |
779 | debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree") | |
7db98ffc | 780 | { |
463c8d80 | 781 | } |
7db98ffc | 782 | }; |
463c8d80 | 783 | /*}}}*/ |
7db98ffc | 784 | |
dce45dbe DK |
785 | APT_HIDDEN debSLTypeDeb _apt_DebType; |
786 | APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType; |