You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1207 lines
44 KiB

  1. #include <config.h>
  2. #include <apt-pkg/error.h>
  3. #include <apt-pkg/debmetaindex.h>
  4. #include <apt-pkg/debindexfile.h>
  5. #include <apt-pkg/strutl.h>
  6. #include <apt-pkg/fileutl.h>
  7. #include <apt-pkg/acquire-item.h>
  8. #include <apt-pkg/configuration.h>
  9. #include <apt-pkg/aptconfiguration.h>
  10. #include <apt-pkg/sourcelist.h>
  11. #include <apt-pkg/hashes.h>
  12. #include <apt-pkg/metaindex.h>
  13. #include <apt-pkg/pkgcachegen.h>
  14. #include <apt-pkg/tagfile.h>
  15. #include <apt-pkg/gpgv.h>
  16. #include <apt-pkg/macros.h>
  17. #include <map>
  18. #include <string>
  19. #include <utility>
  20. #include <vector>
  21. #include <algorithm>
  22. #include <sstream>
  23. #include <sys/stat.h>
  24. #include <string.h>
  25. #include <apti18n.h>
  26. class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
  27. {
  28. public:
  29. struct APT_HIDDEN debSectionEntry
  30. {
  31. std::string const sourcesEntry;
  32. std::string const Name;
  33. std::vector<std::string> const Targets;
  34. std::vector<std::string> const Architectures;
  35. std::vector<std::string> const Languages;
  36. bool const UsePDiffs;
  37. std::string const UseByHash;
  38. };
  39. std::vector<debSectionEntry> DebEntries;
  40. std::vector<debSectionEntry> DebSrcEntries;
  41. metaIndex::TriState CheckValidUntil;
  42. time_t ValidUntilMin;
  43. time_t ValidUntilMax;
  44. std::vector<std::string> Architectures;
  45. std::vector<std::string> NoSupportForAll;
  46. std::map<std::string, std::string> const ReleaseOptions;
  47. debReleaseIndexPrivate(std::map<std::string, std::string> const &Options) : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0), ReleaseOptions(Options) {}
  48. };
  49. /*}}}*/
  50. // ReleaseIndex::MetaIndex* - display helpers /*{{{*/
  51. std::string debReleaseIndex::MetaIndexInfo(const char *Type) const
  52. {
  53. std::string Info = ::URI::ArchiveOnly(URI) + ' ';
  54. if (Dist[Dist.size() - 1] == '/')
  55. {
  56. if (Dist != "/")
  57. Info += Dist;
  58. }
  59. else
  60. Info += Dist;
  61. Info += " ";
  62. Info += Type;
  63. return Info;
  64. }
  65. std::string debReleaseIndex::Describe() const
  66. {
  67. return MetaIndexInfo("Release");
  68. }
  69. std::string debReleaseIndex::MetaIndexFile(const char *Type) const
  70. {
  71. return _config->FindDir("Dir::State::lists") +
  72. URItoFileName(MetaIndexURI(Type));
  73. }
  74. static std::string constructMetaIndexURI(std::string URI, std::string const &Dist, char const * const Type)
  75. {
  76. if (Dist == "/")
  77. ;
  78. else if (Dist[Dist.size()-1] == '/')
  79. URI += Dist;
  80. else
  81. URI += "dists/" + Dist + "/";
  82. return URI + Type;
  83. }
  84. std::string debReleaseIndex::MetaIndexURI(const char *Type) const
  85. {
  86. return constructMetaIndexURI(URI, Dist, Type);
  87. }
  88. /*}}}*/
  89. // ReleaseIndex Con- and Destructors /*{{{*/
  90. debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, std::map<std::string, std::string> const &Options) :
  91. metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate(Options))
  92. {}
  93. debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted, std::map<std::string, std::string> const &Options) :
  94. metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate(Options))
  95. {
  96. Trusted = pTrusted ? TRI_YES : TRI_NO;
  97. }
  98. debReleaseIndex::~debReleaseIndex() {
  99. if (d != NULL)
  100. delete d;
  101. }
  102. /*}}}*/
  103. // ReleaseIndex::GetIndexTargets /*{{{*/
  104. static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist,
  105. std::vector<debReleaseIndexPrivate::debSectionEntry> const &entries,
  106. std::vector<IndexTarget> &IndexTargets, std::map<std::string, std::string> const &ReleaseOptions)
  107. {
  108. bool const flatArchive = (Dist[Dist.length() - 1] == '/');
  109. std::string const baseURI = constructMetaIndexURI(URI, Dist, "");
  110. std::string const Release = (Dist == "/") ? "" : Dist;
  111. std::string const Site = ::URI::ArchiveOnly(URI);
  112. std::string DefCompressionTypes;
  113. {
  114. std::vector<std::string> types = APT::Configuration::getCompressionTypes();
  115. if (types.empty() == false)
  116. {
  117. std::ostringstream os;
  118. std::copy(types.begin(), types.end()-1, std::ostream_iterator<std::string>(os, " "));
  119. os << *types.rbegin();
  120. DefCompressionTypes = os.str();
  121. }
  122. }
  123. std::string DefKeepCompressedAs;
  124. {
  125. std::vector<APT::Configuration::Compressor> comps = APT::Configuration::getCompressors();
  126. if (comps.empty() == false)
  127. {
  128. std::sort(comps.begin(), comps.end(),
  129. [](APT::Configuration::Compressor const &a, APT::Configuration::Compressor const &b) { return a.Cost < b.Cost; });
  130. std::ostringstream os;
  131. for (auto const &c : comps)
  132. if (c.Cost != 0)
  133. os << c.Extension.substr(1) << ' ';
  134. DefKeepCompressedAs = os.str();
  135. }
  136. DefKeepCompressedAs += "uncompressed";
  137. }
  138. std::vector<std::string> const NativeArchs = { _config->Find("APT::Architecture"), "implicit:all" };
  139. bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false);
  140. for (std::vector<debReleaseIndexPrivate::debSectionEntry>::const_iterator E = entries.begin(); E != entries.end(); ++E)
  141. {
  142. for (std::vector<std::string>::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T)
  143. {
  144. #define APT_T_CONFIG_STR(X, Y) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
  145. #define APT_T_CONFIG_BOOL(X, Y) _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
  146. std::string const tplMetaKey = APT_T_CONFIG_STR(flatArchive ? "flatMetaKey" : "MetaKey", "");
  147. std::string const tplShortDesc = APT_T_CONFIG_STR("ShortDescription", "");
  148. std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG_STR(flatArchive ? "flatDescription" : "Description", "");
  149. std::string const tplIdentifier = APT_T_CONFIG_STR("Identifier", *T);
  150. bool const IsOptional = APT_T_CONFIG_BOOL("Optional", true);
  151. bool const KeepCompressed = APT_T_CONFIG_BOOL("KeepCompressed", GzipIndex);
  152. bool const DefaultEnabled = APT_T_CONFIG_BOOL("DefaultEnabled", true);
  153. bool const UsePDiffs = APT_T_CONFIG_BOOL("PDiffs", E->UsePDiffs);
  154. std::string const UseByHash = APT_T_CONFIG_STR("By-Hash", E->UseByHash);
  155. std::string const CompressionTypes = APT_T_CONFIG_STR("CompressionTypes", DefCompressionTypes);
  156. std::string KeepCompressedAs = APT_T_CONFIG_STR("KeepCompressedAs", "");
  157. std::string const FallbackOf = APT_T_CONFIG_STR("Fallback-Of", "");
  158. #undef APT_T_CONFIG_BOOL
  159. #undef APT_T_CONFIG_STR
  160. if (tplMetaKey.empty())
  161. continue;
  162. if (KeepCompressedAs.empty())
  163. KeepCompressedAs = DefKeepCompressedAs;
  164. else
  165. {
  166. std::vector<std::string> const defKeep = VectorizeString(DefKeepCompressedAs, ' ');
  167. std::vector<std::string> const valKeep = VectorizeString(KeepCompressedAs, ' ');
  168. std::vector<std::string> keep;
  169. for (auto const &val : valKeep)
  170. {
  171. if (val.empty())
  172. continue;
  173. if (std::find(defKeep.begin(), defKeep.end(), val) == defKeep.end())
  174. continue;
  175. keep.push_back(val);
  176. }
  177. if (std::find(keep.begin(), keep.end(), "uncompressed") == keep.end())
  178. keep.push_back("uncompressed");
  179. std::ostringstream os;
  180. std::copy(keep.begin(), keep.end()-1, std::ostream_iterator<std::string>(os, " "));
  181. os << *keep.rbegin();
  182. KeepCompressedAs = os.str();
  183. }
  184. for (std::vector<std::string>::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L)
  185. {
  186. if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
  187. continue;
  188. for (std::vector<std::string>::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A)
  189. {
  190. for (auto const &NativeArch: NativeArchs)
  191. {
  192. constexpr static auto BreakPoint = "$(NATIVE_ARCHITECTURE)";
  193. // available in templates
  194. std::map<std::string, std::string> Options;
  195. Options.insert(std::make_pair("SITE", Site));
  196. Options.insert(std::make_pair("RELEASE", Release));
  197. if (tplMetaKey.find("$(COMPONENT)") != std::string::npos)
  198. Options.emplace("COMPONENT", E->Name);
  199. if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
  200. Options.emplace("LANGUAGE", *L);
  201. if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos)
  202. Options.emplace("ARCHITECTURE", (*A == "implicit:all") ? "all" : *A);
  203. else if (tplMetaKey.find("$(NATIVE_ARCHITECTURE)") != std::string::npos)
  204. Options.emplace("ARCHITECTURE", (NativeArch == "implicit:all") ? "all" : NativeArch);
  205. if (tplMetaKey.find("$(NATIVE_ARCHITECTURE)") != std::string::npos)
  206. Options.emplace("NATIVE_ARCHITECTURE", (NativeArch == "implicit:all") ? "all" : NativeArch);
  207. std::string MetaKey = tplMetaKey;
  208. std::string ShortDesc = tplShortDesc;
  209. std::string LongDesc = tplLongDesc;
  210. std::string Identifier = tplIdentifier;
  211. for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
  212. {
  213. std::string const varname = "$(" + O->first + ")";
  214. MetaKey = SubstVar(MetaKey, varname, O->second);
  215. ShortDesc = SubstVar(ShortDesc, varname, O->second);
  216. LongDesc = SubstVar(LongDesc, varname, O->second);
  217. Identifier = SubstVar(Identifier, varname, O->second);
  218. }
  219. {
  220. auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &IT) {
  221. return MetaKey == IT.MetaKey && baseURI == IT.Option(IndexTarget::BASE_URI) &&
  222. E->sourcesEntry == IT.Option(IndexTarget::SOURCESENTRY) && *T == IT.Option(IndexTarget::CREATED_BY);
  223. });
  224. if (dup != IndexTargets.end())
  225. {
  226. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  227. break;
  228. continue;
  229. }
  230. }
  231. {
  232. auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &IT) {
  233. return MetaKey == IT.MetaKey && baseURI == IT.Option(IndexTarget::BASE_URI) &&
  234. E->sourcesEntry == IT.Option(IndexTarget::SOURCESENTRY) && *T != IT.Option(IndexTarget::CREATED_BY);
  235. });
  236. if (dup != IndexTargets.end())
  237. {
  238. std::string const dupT = dup->Option(IndexTarget::CREATED_BY);
  239. std::string const dupEntry = dup->Option(IndexTarget::SOURCESENTRY);
  240. //TRANSLATOR: an identifier like Packages; Releasefile key indicating
  241. // a file like main/binary-amd64/Packages; another identifier like Contents;
  242. // filename and linenumber of the sources.list entry currently parsed
  243. _error->Warning(_("Target %s wants to acquire the same file (%s) as %s from source %s"),
  244. T->c_str(), MetaKey.c_str(), dupT.c_str(), dupEntry.c_str());
  245. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  246. break;
  247. continue;
  248. }
  249. }
  250. {
  251. auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &T) {
  252. return MetaKey == T.MetaKey && baseURI == T.Option(IndexTarget::BASE_URI) &&
  253. E->sourcesEntry != T.Option(IndexTarget::SOURCESENTRY);
  254. });
  255. if (dup != IndexTargets.end())
  256. {
  257. std::string const dupEntry = dup->Option(IndexTarget::SOURCESENTRY);
  258. //TRANSLATOR: an identifier like Packages; Releasefile key indicating
  259. // a file like main/binary-amd64/Packages; filename and linenumber of
  260. // two sources.list entries
  261. _error->Warning(_("Target %s (%s) is configured multiple times in %s and %s"),
  262. T->c_str(), MetaKey.c_str(), dupEntry.c_str(), E->sourcesEntry.c_str());
  263. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  264. break;
  265. continue;
  266. }
  267. }
  268. // not available in templates, but in the indextarget
  269. Options.insert(ReleaseOptions.begin(), ReleaseOptions.end());
  270. Options.insert(std::make_pair("IDENTIFIER", Identifier));
  271. Options.insert(std::make_pair("TARGET_OF", Type));
  272. Options.insert(std::make_pair("CREATED_BY", *T));
  273. Options.insert(std::make_pair("FALLBACK_OF", FallbackOf));
  274. Options.insert(std::make_pair("PDIFFS", UsePDiffs ? "yes" : "no"));
  275. Options.insert(std::make_pair("BY_HASH", UseByHash));
  276. Options.insert(std::make_pair("DEFAULTENABLED", DefaultEnabled ? "yes" : "no"));
  277. Options.insert(std::make_pair("COMPRESSIONTYPES", CompressionTypes));
  278. Options.insert(std::make_pair("KEEPCOMPRESSEDAS", KeepCompressedAs));
  279. Options.insert(std::make_pair("SOURCESENTRY", E->sourcesEntry));
  280. bool IsOpt = IsOptional;
  281. {
  282. auto const arch = Options.find("ARCHITECTURE");
  283. if (arch != Options.end() && arch->second == "all")
  284. {
  285. // one of them must be implicit:all then
  286. if (*A != "all" && NativeArch != "all")
  287. IsOpt = true;
  288. else // user used arch=all explicitly
  289. Options.emplace("Force-Support-For-All", "yes");
  290. }
  291. }
  292. IndexTarget Target(
  293. MetaKey,
  294. ShortDesc,
  295. LongDesc,
  296. baseURI + MetaKey,
  297. IsOpt,
  298. KeepCompressed,
  299. Options
  300. );
  301. IndexTargets.push_back(Target);
  302. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  303. break;
  304. }
  305. if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos)
  306. break;
  307. }
  308. if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos)
  309. break;
  310. }
  311. }
  312. }
  313. }
  314. std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const
  315. {
  316. std::vector<IndexTarget> IndexTargets;
  317. GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets, d->ReleaseOptions);
  318. GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets, d->ReleaseOptions);
  319. return IndexTargets;
  320. }
  321. /*}}}*/
  322. void debReleaseIndex::AddComponent(std::string const &sourcesEntry, /*{{{*/
  323. bool const isSrc, std::string const &Name,
  324. std::vector<std::string> const &Targets,
  325. std::vector<std::string> const &Architectures,
  326. std::vector<std::string> Languages,
  327. bool const usePDiffs, std::string const &useByHash)
  328. {
  329. if (Languages.empty() == true)
  330. Languages.push_back("none");
  331. debReleaseIndexPrivate::debSectionEntry const entry = {
  332. sourcesEntry, Name, Targets, Architectures, Languages, usePDiffs, useByHash
  333. };
  334. if (isSrc)
  335. d->DebSrcEntries.push_back(entry);
  336. else
  337. d->DebEntries.push_back(entry);
  338. }
  339. /*}}}*/
  340. bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/
  341. {
  342. LoadedSuccessfully = TRI_NO;
  343. FileFd Fd;
  344. if (OpenMaybeClearSignedFile(Filename, Fd) == false)
  345. return false;
  346. pkgTagFile TagFile(&Fd, Fd.Size());
  347. if (Fd.IsOpen() == false || Fd.Failed())
  348. {
  349. if (ErrorText != NULL)
  350. strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
  351. return false;
  352. }
  353. pkgTagSection Section;
  354. const char *Start, *End;
  355. if (TagFile.Step(Section) == false)
  356. {
  357. if (ErrorText != NULL)
  358. strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str());
  359. return false;
  360. }
  361. // FIXME: find better tag name
  362. SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false);
  363. Suite = Section.FindS("Suite");
  364. Codename = Section.FindS("Codename");
  365. {
  366. std::string const archs = Section.FindS("Architectures");
  367. if (archs.empty() == false)
  368. d->Architectures = VectorizeString(archs, ' ');
  369. }
  370. {
  371. std::string const targets = Section.FindS("No-Support-for-Architecture-all");
  372. if (targets.empty() == false)
  373. d->NoSupportForAll = VectorizeString(targets, ' ');
  374. }
  375. bool FoundHashSum = false;
  376. bool FoundStrongHashSum = false;
  377. auto const SupportedHashes = HashString::SupportedHashes();
  378. for (int i=0; SupportedHashes[i] != NULL; i++)
  379. {
  380. if (!Section.Find(SupportedHashes[i], Start, End))
  381. continue;
  382. std::string Name;
  383. std::string Hash;
  384. unsigned long long Size;
  385. while (Start < End)
  386. {
  387. if (!parseSumData(Start, End, Name, Hash, Size))
  388. return false;
  389. HashString const hs(SupportedHashes[i], Hash);
  390. if (Entries.find(Name) == Entries.end())
  391. {
  392. metaIndex::checkSum *Sum = new metaIndex::checkSum;
  393. Sum->MetaKeyFilename = Name;
  394. Sum->Size = Size;
  395. Sum->Hashes.FileSize(Size);
  396. APT_IGNORE_DEPRECATED(Sum->Hash = hs;)
  397. Entries[Name] = Sum;
  398. }
  399. Entries[Name]->Hashes.push_back(hs);
  400. FoundHashSum = true;
  401. if (FoundStrongHashSum == false && hs.usable() == true)
  402. FoundStrongHashSum = true;
  403. }
  404. }
  405. bool AuthPossible = false;
  406. if(FoundHashSum == false)
  407. _error->Warning(_("No Hash entry in Release file %s"), Filename.c_str());
  408. else if(FoundStrongHashSum == false)
  409. _error->Warning(_("No Hash entry in Release file %s which is considered strong enough for security purposes"), Filename.c_str());
  410. else
  411. AuthPossible = true;
  412. std::string const StrDate = Section.FindS("Date");
  413. if (RFC1123StrToTime(StrDate.c_str(), Date) == false)
  414. {
  415. _error->Warning( _("Invalid '%s' entry in Release file %s"), "Date", Filename.c_str());
  416. Date = 0;
  417. }
  418. bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true);
  419. if (d->CheckValidUntil == metaIndex::TRI_NO)
  420. CheckValidUntil = false;
  421. else if (d->CheckValidUntil == metaIndex::TRI_YES)
  422. CheckValidUntil = true;
  423. if (CheckValidUntil == true)
  424. {
  425. std::string const Label = Section.FindS("Label");
  426. std::string const StrValidUntil = Section.FindS("Valid-Until");
  427. // if we have a Valid-Until header in the Release file, use it as default
  428. if (StrValidUntil.empty() == false)
  429. {
  430. if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
  431. {
  432. if (ErrorText != NULL)
  433. strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Valid-Until", Filename.c_str());
  434. return false;
  435. }
  436. }
  437. // get the user settings for this archive and use what expires earlier
  438. time_t MaxAge = d->ValidUntilMax;
  439. if (MaxAge == 0)
  440. {
  441. MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
  442. if (Label.empty() == false)
  443. MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
  444. }
  445. time_t MinAge = d->ValidUntilMin;
  446. if (MinAge == 0)
  447. {
  448. MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
  449. if (Label.empty() == false)
  450. MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
  451. }
  452. if (MinAge != 0 || ValidUntil != 0 || MaxAge != 0)
  453. {
  454. if (MinAge != 0 && ValidUntil != 0) {
  455. time_t const min_date = Date + MinAge;
  456. if (ValidUntil < min_date)
  457. ValidUntil = min_date;
  458. }
  459. if (MaxAge != 0 && Date != 0) {
  460. time_t const max_date = Date + MaxAge;
  461. if (ValidUntil == 0 || ValidUntil > max_date)
  462. ValidUntil = max_date;
  463. }
  464. }
  465. }
  466. /* as the Release file is parsed only after it was verified, the Signed-By field
  467. does not effect the current, but the "next" Release file */
  468. auto Sign = Section.FindS("Signed-By");
  469. if (Sign.empty() == false)
  470. {
  471. std::transform(Sign.begin(), Sign.end(), Sign.begin(), [&](char const c) {
  472. return (isspace(c) == 0) ? c : ',';
  473. });
  474. auto fingers = VectorizeString(Sign, ',');
  475. std::transform(fingers.begin(), fingers.end(), fingers.begin(), [&](std::string finger) {
  476. std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
  477. if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
  478. {
  479. if (ErrorText != NULL)
  480. strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Signed-By", Filename.c_str());
  481. return std::string();
  482. }
  483. return finger;
  484. });
  485. if (fingers.empty() == false && std::find(fingers.begin(), fingers.end(), "") == fingers.end())
  486. {
  487. std::stringstream os;
  488. std::copy(fingers.begin(), fingers.end(), std::ostream_iterator<std::string>(os, ","));
  489. SignedBy = os.str();
  490. }
  491. }
  492. if (AuthPossible)
  493. LoadedSuccessfully = TRI_YES;
  494. return AuthPossible;
  495. }
  496. /*}}}*/
  497. metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/
  498. {
  499. if (Trusted == TRI_NO)
  500. return new debReleaseIndex(URI, Dist, false, d->ReleaseOptions);
  501. else if (Trusted == TRI_YES)
  502. return new debReleaseIndex(URI, Dist, true, d->ReleaseOptions);
  503. else
  504. return new debReleaseIndex(URI, Dist, d->ReleaseOptions);
  505. }
  506. /*}}}*/
  507. bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/
  508. std::string &Name, std::string &Hash, unsigned long long &Size)
  509. {
  510. Name = "";
  511. Hash = "";
  512. Size = 0;
  513. /* Skip over the first blank */
  514. while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r')
  515. && Start < End)
  516. Start++;
  517. if (Start >= End)
  518. return false;
  519. /* Move EntryEnd to the end of the first entry (the hash) */
  520. const char *EntryEnd = Start;
  521. while ((*EntryEnd != '\t' && *EntryEnd != ' ')
  522. && EntryEnd < End)
  523. EntryEnd++;
  524. if (EntryEnd == End)
  525. return false;
  526. Hash.append(Start, EntryEnd-Start);
  527. /* Skip over intermediate blanks */
  528. Start = EntryEnd;
  529. while (*Start == '\t' || *Start == ' ')
  530. Start++;
  531. if (Start >= End)
  532. return false;
  533. EntryEnd = Start;
  534. /* Find the end of the second entry (the size) */
  535. while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
  536. && EntryEnd < End)
  537. EntryEnd++;
  538. if (EntryEnd == End)
  539. return false;
  540. Size = strtoull (Start, NULL, 10);
  541. /* Skip over intermediate blanks */
  542. Start = EntryEnd;
  543. while (*Start == '\t' || *Start == ' ')
  544. Start++;
  545. if (Start >= End)
  546. return false;
  547. EntryEnd = Start;
  548. /* Find the end of the third entry (the filename) */
  549. while ((*EntryEnd != '\t' && *EntryEnd != ' ' &&
  550. *EntryEnd != '\n' && *EntryEnd != '\r')
  551. && EntryEnd < End)
  552. EntryEnd++;
  553. Name.append(Start, EntryEnd-Start);
  554. Start = EntryEnd; //prepare for the next round
  555. return true;
  556. }
  557. /*}}}*/
  558. bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/
  559. {
  560. #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, d->ReleaseOptions)
  561. pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
  562. APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), this);
  563. #undef APT_TARGET
  564. // special case for --print-uris
  565. if (GetAll)
  566. for (auto const &Target: GetIndexTargets())
  567. if (Target.Option(IndexTarget::FALLBACK_OF).empty())
  568. new pkgAcqIndex(Owner, TransactionManager, Target);
  569. return true;
  570. }
  571. /*}}}*/
  572. // ReleaseIndex::Set* TriState options /*{{{*/
  573. bool debReleaseIndex::SetTrusted(TriState const pTrusted)
  574. {
  575. if (Trusted == TRI_UNSET)
  576. Trusted = pTrusted;
  577. else if (Trusted != pTrusted)
  578. // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
  579. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Trusted", URI.c_str(), Dist.c_str());
  580. return true;
  581. }
  582. bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil)
  583. {
  584. if (d->CheckValidUntil == TRI_UNSET)
  585. d->CheckValidUntil = pCheckValidUntil;
  586. else if (d->CheckValidUntil != pCheckValidUntil)
  587. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str());
  588. return true;
  589. }
  590. bool debReleaseIndex::SetValidUntilMin(time_t const Valid)
  591. {
  592. if (d->ValidUntilMin == 0)
  593. d->ValidUntilMin = Valid;
  594. else if (d->ValidUntilMin != Valid)
  595. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str());
  596. return true;
  597. }
  598. bool debReleaseIndex::SetValidUntilMax(time_t const Valid)
  599. {
  600. if (d->ValidUntilMax == 0)
  601. d->ValidUntilMax = Valid;
  602. else if (d->ValidUntilMax != Valid)
  603. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str());
  604. return true;
  605. }
  606. bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy)
  607. {
  608. if (SignedBy.empty() == true && pSignedBy.empty() == false)
  609. {
  610. if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things
  611. SignedBy = pSignedBy; // absolute path to a keyring file
  612. else
  613. {
  614. // we could go all fancy and allow short/long/string matches as gpgv/apt-key does,
  615. // but fingerprints are harder to fake than the others and this option is set once,
  616. // not interactively all the time so easy to type is not really a concern.
  617. auto fingers = VectorizeString(pSignedBy, ',');
  618. std::transform(fingers.begin(), fingers.end(), fingers.begin(), [&](std::string finger) {
  619. std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
  620. if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
  621. {
  622. _error->Error(_("Invalid value set for option %s regarding source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint");
  623. return std::string();
  624. }
  625. return finger;
  626. });
  627. std::stringstream os;
  628. std::copy(fingers.begin(), fingers.end(), std::ostream_iterator<std::string>(os, ","));
  629. SignedBy = os.str();
  630. }
  631. // Normalize the string: Remove trailing commas
  632. while (SignedBy[SignedBy.size() - 1] == ',')
  633. SignedBy.resize(SignedBy.size() - 1);
  634. }
  635. else {
  636. // Only compare normalized strings
  637. auto pSignedByView = APT::StringView(pSignedBy);
  638. while (pSignedByView[pSignedByView.size() - 1] == ',')
  639. pSignedByView = pSignedByView.substr(0, pSignedByView.size() - 1);
  640. if (pSignedByView != SignedBy)
  641. return _error->Error(_("Conflicting values set for option %s regarding source %s %s: %s != %s"), "Signed-By", URI.c_str(), Dist.c_str(), SignedBy.c_str(), pSignedByView.to_string().c_str());
  642. }
  643. return true;
  644. }
  645. /*}}}*/
  646. // ReleaseIndex::IsTrusted /*{{{*/
  647. bool debReleaseIndex::IsTrusted() const
  648. {
  649. if (Trusted == TRI_YES)
  650. return true;
  651. else if (Trusted == TRI_NO)
  652. return false;
  653. if(_config->FindB("APT::Authentication::TrustCDROM", false))
  654. if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
  655. return true;
  656. if (FileExists(MetaIndexFile("Release.gpg")))
  657. return true;
  658. return FileExists(MetaIndexFile("InRelease"));
  659. }
  660. /*}}}*/
  661. bool debReleaseIndex::IsArchitectureSupported(std::string const &arch) const/*{{{*/
  662. {
  663. if (d->Architectures.empty())
  664. return true;
  665. return std::find(d->Architectures.begin(), d->Architectures.end(), arch) != d->Architectures.end();
  666. }
  667. /*}}}*/
  668. bool debReleaseIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/
  669. {
  670. if (target.Options.find("Force-Support-For-All") != target.Options.end())
  671. return true;
  672. if (IsArchitectureSupported("all") == false)
  673. return false;
  674. if (d->NoSupportForAll.empty())
  675. return true;
  676. return std::find(d->NoSupportForAll.begin(), d->NoSupportForAll.end(), target.Option(IndexTarget::CREATED_BY)) == d->NoSupportForAll.end();
  677. }
  678. /*}}}*/
  679. std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() /*{{{*/
  680. {
  681. if (Indexes != NULL)
  682. return Indexes;
  683. Indexes = new std::vector<pkgIndexFile*>();
  684. bool const istrusted = IsTrusted();
  685. for (auto const &T: GetIndexTargets())
  686. {
  687. std::string const TargetName = T.Option(IndexTarget::CREATED_BY);
  688. if (TargetName == "Packages")
  689. Indexes->push_back(new debPackagesIndex(T, istrusted));
  690. else if (TargetName == "Sources")
  691. Indexes->push_back(new debSourcesIndex(T, istrusted));
  692. else if (TargetName == "Translations")
  693. Indexes->push_back(new debTranslationsIndex(T));
  694. }
  695. return Indexes;
  696. }
  697. /*}}}*/
  698. std::map<std::string, std::string> debReleaseIndex::GetReleaseOptions()
  699. {
  700. return d->ReleaseOptions;
  701. }
  702. static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/
  703. {
  704. ReleaseFile = That->MetaIndexFile("InRelease");
  705. bool releaseExists = false;
  706. if (FileExists(ReleaseFile) == true)
  707. releaseExists = true;
  708. else
  709. {
  710. ReleaseFile = That->MetaIndexFile("Release");
  711. if (FileExists(ReleaseFile))
  712. releaseExists = true;
  713. }
  714. return releaseExists;
  715. }
  716. /*}}}*/
  717. bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/
  718. {
  719. std::string ReleaseFile;
  720. bool const releaseExists = ReleaseFileName(this, ReleaseFile);
  721. ::URI Tmp(URI);
  722. if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false)
  723. return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str());
  724. if (releaseExists == false)
  725. return true;
  726. FileFd Rel;
  727. // Beware: The 'Release' file might be clearsigned in case the
  728. // signature for an 'InRelease' file couldn't be checked
  729. if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
  730. return false;
  731. // Store the IMS information
  732. pkgCache::RlsFileIterator File = Gen.GetCurRlsFile();
  733. pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File);
  734. // Rel can't be used as this is potentially a temporary file
  735. struct stat Buf;
  736. if (stat(ReleaseFile.c_str(), &Buf) != 0)
  737. return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str());
  738. File->Size = Buf.st_size;
  739. File->mtime = Buf.st_mtime;
  740. pkgTagFile TagFile(&Rel, Rel.Size());
  741. pkgTagSection Section;
  742. if (Rel.IsOpen() == false || Rel.Failed() || TagFile.Step(Section) == false)
  743. return false;
  744. std::string data;
  745. #define APT_INRELEASE(TYPE, TAG, STORE) \
  746. data = Section.FindS(TAG); \
  747. if (data.empty() == false) \
  748. { \
  749. map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
  750. if (storage == 0) return false; \
  751. STORE = storage; \
  752. }
  753. APT_INRELEASE(MIXED, "Suite", File->Archive)
  754. APT_INRELEASE(VERSIONNUMBER, "Version", File->Version)
  755. APT_INRELEASE(MIXED, "Origin", File->Origin)
  756. APT_INRELEASE(MIXED, "Codename", File->Codename)
  757. APT_INRELEASE(MIXED, "Label", File->Label)
  758. #undef APT_INRELEASE
  759. Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic);
  760. Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades);
  761. return true;
  762. }
  763. /*}}}*/
  764. // ReleaseIndex::FindInCache - Find this index /*{{{*/
  765. pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const
  766. {
  767. std::string ReleaseFile;
  768. bool const releaseExists = ReleaseFileName(this, ReleaseFile);
  769. pkgCache::RlsFileIterator File = Cache.RlsFileBegin();
  770. for (; File.end() == false; ++File)
  771. {
  772. if (File->FileName == 0 || ReleaseFile != File.FileName())
  773. continue;
  774. // empty means the file does not exist by "design"
  775. if (ModifyCheck == false || (releaseExists == false && File->Size == 0))
  776. return File;
  777. struct stat St;
  778. if (stat(File.FileName(),&St) != 0)
  779. {
  780. if (_config->FindB("Debug::pkgCacheGen", false))
  781. std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  782. return pkgCache::RlsFileIterator(Cache);
  783. }
  784. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  785. {
  786. if (_config->FindB("Debug::pkgCacheGen", false))
  787. std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  788. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  789. << ") doesn't match for " << File.FileName() << std::endl;
  790. return pkgCache::RlsFileIterator(Cache);
  791. }
  792. return File;
  793. }
  794. return File;
  795. }
  796. /*}}}*/
  797. class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
  798. {
  799. static std::vector<std::string> getDefaultSetOf(std::string const &Name,
  800. std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
  801. {
  802. auto const val = Options.find(Name);
  803. if (val != Options.end())
  804. return VectorizeString(val->second, ',');
  805. return defaultValues;
  806. }
  807. static std::vector<std::string> applyPlusMinusOptions(std::string const &Name,
  808. std::map<std::string, std::string> const &Options, std::vector<std::string> &&Values)
  809. {
  810. auto val = Options.find(Name + "+");
  811. if (val != Options.end())
  812. {
  813. std::vector<std::string> const plus = VectorizeString(val->second, ',');
  814. std::copy_if(plus.begin(), plus.end(), std::back_inserter(Values), [&Values](std::string const &v) {
  815. return std::find(Values.begin(), Values.end(), v) == Values.end();
  816. });
  817. }
  818. if ((val = Options.find(Name + "-")) != Options.end())
  819. {
  820. std::vector<std::string> const minus = VectorizeString(val->second, ',');
  821. Values.erase(std::remove_if(Values.begin(), Values.end(), [&minus](std::string const &v) {
  822. return std::find(minus.begin(), minus.end(), v) != minus.end();
  823. }), Values.end());
  824. }
  825. return Values;
  826. }
  827. static std::vector<std::string> parsePlusMinusOptions(std::string const &Name,
  828. std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
  829. {
  830. return applyPlusMinusOptions(Name, Options, getDefaultSetOf(Name, Options, defaultValues));
  831. }
  832. static std::vector<std::string> parsePlusMinusArchOptions(std::string const &Name,
  833. std::map<std::string, std::string> const &Options)
  834. {
  835. auto Values = getDefaultSetOf(Name, Options, APT::Configuration::getArchitectures());
  836. // all is a very special architecture users shouldn't be concerned with explicitly
  837. // but if the user does, do not override the choice
  838. auto const val = Options.find(Name + "-");
  839. if (val != Options.end())
  840. {
  841. std::vector<std::string> const minus = VectorizeString(val->second, ',');
  842. if (std::find(minus.begin(), minus.end(), "all") != minus.end())
  843. return applyPlusMinusOptions(Name, Options, std::move(Values));
  844. }
  845. Values = applyPlusMinusOptions(Name, Options, std::move(Values));
  846. if (std::find(Values.begin(), Values.end(), "all") == Values.end())
  847. Values.push_back("implicit:all");
  848. return Values;
  849. }
  850. static std::vector<std::string> parsePlusMinusTargetOptions(char const * const Name,
  851. std::map<std::string, std::string> const &Options)
  852. {
  853. std::vector<std::string> const alltargets = _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true);
  854. std::vector<std::string> deftargets;
  855. deftargets.reserve(alltargets.size());
  856. std::copy_if(alltargets.begin(), alltargets.end(), std::back_inserter(deftargets), [&](std::string const &t) {
  857. std::string c = "Acquire::IndexTargets::";
  858. c.append(Name).append("::").append(t).append("::DefaultEnabled");
  859. return _config->FindB(c, true);
  860. });
  861. std::vector<std::string> mytargets = parsePlusMinusOptions("target", Options, deftargets);
  862. for (auto const &target : alltargets)
  863. {
  864. std::map<std::string, std::string>::const_iterator const opt = Options.find(target);
  865. if (opt == Options.end())
  866. continue;
  867. auto const idMatch = [&](std::string const &t) {
  868. return target == _config->Find(std::string("Acquire::IndexTargets::") + Name + "::" + t + "::Identifier", t);
  869. };
  870. if (StringToBool(opt->second))
  871. std::copy_if(alltargets.begin(), alltargets.end(), std::back_inserter(mytargets), idMatch);
  872. else
  873. mytargets.erase(std::remove_if(mytargets.begin(), mytargets.end(), idMatch), mytargets.end());
  874. }
  875. // if we can't order it in a 1000 steps we give up… probably a cycle
  876. for (auto i = 0; i < 1000; ++i)
  877. {
  878. bool Changed = false;
  879. for (auto t = mytargets.begin(); t != mytargets.end(); ++t)
  880. {
  881. std::string const fallback = _config->Find(std::string("Acquire::IndexTargets::") + Name + "::" + *t + "::Fallback-Of");
  882. if (fallback.empty())
  883. continue;
  884. auto const faller = std::find(mytargets.begin(), mytargets.end(), fallback);
  885. if (faller == mytargets.end() || faller < t)
  886. continue;
  887. Changed = true;
  888. auto const tv = *t;
  889. mytargets.erase(t);
  890. mytargets.emplace_back(tv);
  891. }
  892. if (Changed == false)
  893. break;
  894. }
  895. // remove duplicates without changing the order (in first appearance)
  896. {
  897. std::set<std::string> seenOnce;
  898. mytargets.erase(std::remove_if(mytargets.begin(), mytargets.end(), [&](std::string const &t) {
  899. return seenOnce.insert(t).second == false;
  900. }), mytargets.end());
  901. }
  902. return mytargets;
  903. }
  904. metaIndex::TriState GetTriStateOption(std::map<std::string, std::string>const &Options, char const * const name) const
  905. {
  906. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  907. if (opt != Options.end())
  908. return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO;
  909. return metaIndex::TRI_DONTCARE;
  910. }
  911. static time_t GetTimeOption(std::map<std::string, std::string>const &Options, char const * const name)
  912. {
  913. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  914. if (opt == Options.end())
  915. return 0;
  916. return strtoull(opt->second.c_str(), NULL, 10);
  917. }
  918. static bool GetBoolOption(std::map<std::string, std::string> const &Options, char const * const name, bool const defVal)
  919. {
  920. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  921. if (opt == Options.end())
  922. return defVal;
  923. return StringToBool(opt->second, defVal);
  924. }
  925. static std::vector<std::string> GetMapKeys(std::map<std::string, std::string> const &Options)
  926. {
  927. std::vector<std::string> ret;
  928. ret.reserve(Options.size());
  929. for (auto &&O: Options)
  930. ret.emplace_back(O.first);
  931. std::sort(ret.begin(), ret.end());
  932. return ret;
  933. }
  934. static bool MapsAreEqual(std::map<std::string, std::string> const &OptionsA,
  935. std::map<std::string, std::string> const &OptionsB,
  936. std::string const &URI, std::string const &Dist)
  937. {
  938. auto const KeysA = GetMapKeys(OptionsA);
  939. auto const KeysB = GetMapKeys(OptionsB);
  940. auto const m = std::mismatch(KeysA.begin(), KeysA.end(), KeysB.begin());
  941. if (m.first != KeysA.end())
  942. {
  943. if (std::find(KeysB.begin(), KeysB.end(), *m.first) == KeysB.end())
  944. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), m.first->c_str(), "<set>", "<unset>");
  945. else
  946. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), m.second->c_str(), "<set>", "<unset>");
  947. }
  948. if (m.second != KeysB.end())
  949. {
  950. if (std::find(KeysA.begin(), KeysA.end(), *m.second) == KeysA.end())
  951. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), m.first->c_str(), "<set>", "<unset>");
  952. else
  953. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), m.second->c_str(), "<set>", "<unset>");
  954. }
  955. for (auto&& key: KeysA)
  956. {
  957. if (key == "BASE_URI" || key == "REPO_URI")
  958. continue;
  959. auto const a = OptionsA.find(key);
  960. auto const b = OptionsB.find(key);
  961. if (unlikely(a == OptionsA.end() || b == OptionsB.end()) || a->second != b->second)
  962. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), key.c_str(), URI.c_str(), Dist.c_str());
  963. }
  964. return true;
  965. }
  966. static debReleaseIndex * GetDebReleaseIndexBy(std::vector<metaIndex *> &List, std::string const &URI,
  967. std::string const &Dist, std::map<std::string, std::string> const &Options)
  968. {
  969. std::map<std::string,std::string> ReleaseOptions = {{
  970. { "BASE_URI", constructMetaIndexURI(URI, Dist, "") },
  971. { "REPO_URI", URI },
  972. }};
  973. if (GetBoolOption(Options, "allow-insecure", _config->FindB("Acquire::AllowInsecureRepositories")))
  974. ReleaseOptions.emplace("ALLOW_INSECURE", "true");
  975. if (GetBoolOption(Options, "allow-weak", _config->FindB("Acquire::AllowWeakRepositories")))
  976. ReleaseOptions.emplace("ALLOW_WEAK", "true");
  977. if (GetBoolOption(Options, "allow-downgrade-to-insecure", _config->FindB("Acquire::AllowDowngradeToInsecureRepositories")))
  978. ReleaseOptions.emplace("ALLOW_DOWNGRADE_TO_INSECURE", "true");
  979. debReleaseIndex * Deb = nullptr;
  980. std::string const FileName = URItoFileName(constructMetaIndexURI(URI, Dist, "Release"));
  981. for (auto const &I: List)
  982. {
  983. // We only worry about debian entries here
  984. if (strcmp(I->GetType(), "deb") != 0)
  985. continue;
  986. auto const D = dynamic_cast<debReleaseIndex*>(I);
  987. if (unlikely(D == nullptr))
  988. continue;
  989. /* This check ensures that there will be only one Release file
  990. queued for all the Packages files and Sources files it
  991. corresponds to. */
  992. if (URItoFileName(D->MetaIndexURI("Release")) == FileName)
  993. {
  994. if (MapsAreEqual(ReleaseOptions, D->GetReleaseOptions(), URI, Dist) == false)
  995. return nullptr;
  996. Deb = D;
  997. break;
  998. }
  999. }
  1000. // No currently created Release file indexes this entry, so we create a new one.
  1001. if (Deb == nullptr)
  1002. {
  1003. Deb = new debReleaseIndex(URI, Dist, ReleaseOptions);
  1004. List.push_back(Deb);
  1005. }
  1006. return Deb;
  1007. }
  1008. protected:
  1009. bool CreateItemInternal(std::vector<metaIndex *> &List, std::string const &URI,
  1010. std::string const &Dist, std::string const &Section,
  1011. bool const &IsSrc, std::map<std::string, std::string> const &Options) const
  1012. {
  1013. auto const Deb = GetDebReleaseIndexBy(List, URI, Dist, Options);
  1014. bool const UsePDiffs = GetBoolOption(Options, "pdiffs", _config->FindB("Acquire::PDiffs", true));
  1015. std::string UseByHash = _config->Find("APT::Acquire::By-Hash", "yes");
  1016. UseByHash = _config->Find("Acquire::By-Hash", UseByHash);
  1017. {
  1018. std::string const host = ::URI(URI).Host;
  1019. UseByHash = _config->Find("APT::Acquire::" + host + "::By-Hash", UseByHash);
  1020. UseByHash = _config->Find("Acquire::" + host + "::By-Hash", UseByHash);
  1021. std::map<std::string, std::string>::const_iterator const opt = Options.find("by-hash");
  1022. if (opt != Options.end())
  1023. UseByHash = opt->second;
  1024. }
  1025. auto const entry = Options.find("sourceslist-entry");
  1026. Deb->AddComponent(
  1027. entry->second,
  1028. IsSrc,
  1029. Section,
  1030. parsePlusMinusTargetOptions(Name, Options),
  1031. parsePlusMinusArchOptions("arch", Options),
  1032. parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)),
  1033. UsePDiffs,
  1034. UseByHash
  1035. );
  1036. if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false ||
  1037. Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false ||
  1038. Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false ||
  1039. Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false)
  1040. return false;
  1041. std::map<std::string, std::string>::const_iterator const signedby = Options.find("signed-by");
  1042. if (signedby == Options.end())
  1043. {
  1044. bool alreadySet = false;
  1045. std::string filename;
  1046. if (ReleaseFileName(Deb, filename))
  1047. {
  1048. auto OldDeb = Deb->UnloadedClone();
  1049. _error->PushToStack();
  1050. OldDeb->Load(filename, nullptr);
  1051. bool const goodLoad = _error->PendingError() == false;
  1052. _error->RevertToStack();
  1053. if (goodLoad)
  1054. {
  1055. if (OldDeb->GetValidUntil() > 0)
  1056. {
  1057. time_t const invalid_since = time(NULL) - OldDeb->GetValidUntil();
  1058. if (invalid_since <= 0)
  1059. {
  1060. Deb->SetSignedBy(OldDeb->GetSignedBy());
  1061. alreadySet = true;
  1062. }
  1063. }
  1064. }
  1065. delete OldDeb;
  1066. }
  1067. if (alreadySet == false && Deb->SetSignedBy("") == false)
  1068. return false;
  1069. }
  1070. else
  1071. {
  1072. if (Deb->SetSignedBy(signedby->second) == false)
  1073. return false;
  1074. }
  1075. return true;
  1076. }
  1077. debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label)
  1078. {
  1079. }
  1080. };
  1081. /*}}}*/
  1082. class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/
  1083. {
  1084. public:
  1085. bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
  1086. std::string const &Dist, std::string const &Section,
  1087. std::map<std::string, std::string> const &Options) const APT_OVERRIDE
  1088. {
  1089. return CreateItemInternal(List, URI, Dist, Section, false, Options);
  1090. }
  1091. debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
  1092. {
  1093. }
  1094. };
  1095. /*}}}*/
  1096. class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/
  1097. {
  1098. public:
  1099. bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
  1100. std::string const &Dist, std::string const &Section,
  1101. std::map<std::string, std::string> const &Options) const APT_OVERRIDE
  1102. {
  1103. return CreateItemInternal(List, URI, Dist, Section, true, Options);
  1104. }
  1105. debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
  1106. {
  1107. }
  1108. };
  1109. /*}}}*/
  1110. APT_HIDDEN debSLTypeDeb _apt_DebType;
  1111. APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType;