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.
 
 
 
 
 
 

101 lines
2.7 KiB

  1. // Include Files /*{{{*/
  2. #include <config.h>
  3. #include <apt-pkg/acquire.h>
  4. #include <apt-pkg/acquire-item.h>
  5. #include <apt-pkg/configuration.h>
  6. #include <apt-pkg/error.h>
  7. #include <apt-pkg/strutl.h>
  8. #include <apt-private/private-output.h>
  9. #include <apt-private/private-download.h>
  10. #include <fstream>
  11. #include <string>
  12. #include <vector>
  13. #include <apti18n.h>
  14. /*}}}*/
  15. // CheckAuth - check if each download comes form a trusted source /*{{{*/
  16. bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser)
  17. {
  18. std::string UntrustedList;
  19. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
  20. if (!(*I)->IsTrusted())
  21. UntrustedList += std::string((*I)->ShortDesc()) + " ";
  22. if (UntrustedList == "")
  23. return true;
  24. return AuthPrompt(UntrustedList, PromptUser);
  25. }
  26. bool AuthPrompt(std::string UntrustedList, bool const PromptUser)
  27. {
  28. ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
  29. if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
  30. {
  31. c2out << _("Authentication warning overridden.\n");
  32. return true;
  33. }
  34. if (PromptUser == false)
  35. return _error->Error(_("Some packages could not be authenticated"));
  36. if (_config->FindI("quiet",0) < 2
  37. && _config->FindB("APT::Get::Assume-Yes",false) == false)
  38. {
  39. c2out << _("Install these packages without verification?") << std::flush;
  40. if (!YnPrompt(false))
  41. return _error->Error(_("Some packages could not be authenticated"));
  42. return true;
  43. }
  44. else if (_config->FindB("APT::Get::Force-Yes",false) == true)
  45. return true;
  46. return _error->Error(_("There are problems and -y was used without --force-yes"));
  47. }
  48. /*}}}*/
  49. bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure)/*{{{*/
  50. {
  51. pkgAcquire::RunResult res;
  52. if(PulseInterval > 0)
  53. res = Fetcher.Run(PulseInterval);
  54. else
  55. res = Fetcher.Run();
  56. if (res == pkgAcquire::Failed)
  57. return false;
  58. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
  59. I != Fetcher.ItemsEnd(); ++I)
  60. {
  61. if ((*I)->Status == pkgAcquire::Item::StatDone &&
  62. (*I)->Complete == true)
  63. continue;
  64. if (TransientNetworkFailure != NULL && (*I)->Status == pkgAcquire::Item::StatIdle)
  65. {
  66. *TransientNetworkFailure = true;
  67. continue;
  68. }
  69. ::URI uri((*I)->DescURI());
  70. uri.User.clear();
  71. uri.Password.clear();
  72. std::string descUri = std::string(uri);
  73. _error->Error(_("Failed to fetch %s %s\n"), descUri.c_str(),
  74. (*I)->ErrorText.c_str());
  75. if (Failure != NULL)
  76. *Failure = true;
  77. }
  78. return true;
  79. }
  80. /*}}}*/