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