]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
fix insecure use of /tmp in EDSP solver 'dump'
[apt.git] / cmdline / apt-get.cc
index 9232e15054c8decff9ebc6424356e7a42483abc7..ebc8c94c27dbc1f4378327ce86eea2262e300b1a 100644 (file)
@@ -39,7 +39,6 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/indexfile.h>
-#include <apt-pkg/indexrecords.h>
 #include <apt-pkg/init.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/metaindex.h>
@@ -56,6 +55,7 @@
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/upgrade.h>
+#include <apt-pkg/sptr.h>
 
 #include <apt-private/acqprogress.h>
 #include <apt-private/private-cacheset.h>
@@ -161,11 +161,7 @@ static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheF
 // FindSrc - Find a source record                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-#if APT_PKG_ABI >= 413
 static pkgSrcRecords::Parser *FindSrc(const char *Name,
-#else
-static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
-#endif
                               pkgSrcRecords &SrcRecs,string &Src,
                               CacheFile &CacheFile)
 {
@@ -275,19 +271,8 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
               {
                  // the Version we have is possibly fuzzy or includes binUploads,
                  // so we use the Version of the SourcePkg (empty if same as package)
-#if APT_PKG_ABI >= 413
                  Src = Ver.SourcePkgName();
                  VerTag = Ver.SourceVerStr();
-#else
-                 pkgRecords::Parser &Parse = Recs.Lookup(VF);
-                 Src = Parse.SourcePkg();
-                 // no SourcePkg name, so it is the "binary" name
-                 if (Src.empty() == true)
-                    Src = TmpSrc;
-                 VerTag = Parse.SourceVer();
-                 if (VerTag.empty() == true)
-                    VerTag = Ver.VerStr();
-#endif
                  break;
               }
            }
@@ -318,17 +303,10 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
         pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
         if (Ver.end() == false) 
         {
-#if APT_PKG_ABI >= 413
            if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
               Src = Ver.SourcePkgName();
            if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0)
               VerTag = Ver.SourceVerStr();
-#else
-           pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
-           Src = Parse.SourcePkg();
-           if (VerTag.empty() == true)
-              VerTag = Parse.SourceVer();
-#endif
         }
       }
    }
@@ -651,9 +629,6 @@ static bool DoDownload(CommandLine &CmdL)
       return true;
    }
 
-   // Disable drop-privs if "_apt" can not write to the target dir
-   CheckDropPrivsMustBeDisabled(Fetcher);
-
    if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false)
       return false;
 
@@ -715,9 +690,6 @@ static bool DoSource(CommandLine &CmdL)
    pkgSourceList *List = Cache.GetSourceList();
    
    // Create the text record parsers
-#if APT_PKG_ABI < 413
-   pkgRecords Recs(Cache);
-#endif
    pkgSrcRecords SrcRecs(*List);
    if (_error->PendingError() == true)
       return false;
@@ -726,7 +698,7 @@ static bool DoSource(CommandLine &CmdL)
    AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
    pkgAcquire Fetcher(&Stat);
 
-   SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
+   std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]);
    
    // insert all downloaded uris into this set to avoid downloading them
    // twice
@@ -741,22 +713,18 @@ static bool DoSource(CommandLine &CmdL)
 
    // Load the requestd sources into the fetcher
    unsigned J = 0;
-   std::string UntrustedList;
+   std::vector<std::string> UntrustedList;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
       string Src;
-#if APT_PKG_ABI >= 413
       pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
-      pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
       if (Last == 0) {
         return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
       }
 
       if (Last->Index().IsTrusted() == false)
-         UntrustedList += Src + " ";
-      
+         UntrustedList.push_back(Src);
+
       string srec = Last->AsStr();
       string::size_type pos = srec.find("\nVcs-");
       while (pos != string::npos)
@@ -879,11 +847,8 @@ static bool DoSource(CommandLine &CmdL)
       return true;
    }
 
-   // Disable drop-privs if "_apt" can not write to the target dir
-   CheckDropPrivsMustBeDisabled(Fetcher);
-
    // check authentication status of the source as well
-   if (UntrustedList != "" && !AuthPrompt(UntrustedList, false))
+   if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false)
       return false;
 
    // Run it
@@ -995,8 +960,10 @@ static bool DoBuildDep(CommandLine &CmdL)
    CacheFile Cache;
 
    _config->Set("APT::Install-Recommends", false);
+
+   bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false;
    
-   if (Cache.Open(true) == false)
+   if (Cache.Open(WantLock) == false)
       return false;
 
    if (CmdL.FileSize() <= 1)
@@ -1029,7 +996,7 @@ static bool DoBuildDep(CommandLine &CmdL)
    {
       string Src;
       pkgSrcRecords::Parser *Last = 0;
-      SPtr<pkgSrcRecords::Parser> LastOwner;
+      std::unique_ptr<pkgSrcRecords::Parser> LastOwner;
 
       // an unpacked debian source tree
       using APT::String::Startswith;
@@ -1041,7 +1008,7 @@ static bool DoBuildDep(CommandLine &CmdL)
          std::string TypeName = "Debian control file";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
-            LastOwner = Last = Type->CreateSrcPkgParser(*I);
+            LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
       }
       // if its a local file (e.g. .dsc) use this
       else if (FileExists(*I))
@@ -1052,14 +1019,10 @@ static bool DoBuildDep(CommandLine &CmdL)
          string TypeName = "Debian " + flExtension(*I) + " file";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
-            LastOwner = Last = Type->CreateSrcPkgParser(*I);
+            LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
       } else {
          // normal case, search the cache for the source file
-#if APT_PKG_ABI >= 413
         Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
-        Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
       }
 
       if (Last == 0)
@@ -1204,12 +1167,12 @@ static bool DoBuildDep(CommandLine &CmdL)
               for (; Ver != verlist.end(); ++Ver)
               {
                  forbidden.clear();
-                 if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
+                 if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All)
                  {
                     if (colon == string::npos)
                        Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
                     else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
-                       forbidden = "Multi-Arch: none";
+                       forbidden = "Multi-Arch: no";
                     else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
                        Pkg = Ver.ParentPkg().Group().FindPkg("native");
                  }
@@ -1434,11 +1397,6 @@ static bool DoChangelog(CommandLine &CmdL)
 
    if (printOnly == false)
    {
-      // Disable drop-privs if "_apt" can not write to the target dir
-      CheckDropPrivsMustBeDisabled(Fetcher);
-      if (_error->PendingError() == true)
-        return false;
-
       bool Failed = false;
       if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
         return false;
@@ -1468,7 +1426,7 @@ static bool DoChangelog(CommandLine &CmdL)
    return true;
 }
                                                                        /*}}}*/
-// DoFiles - Lists all IndexTargets                                    /*{{{*/
+// DoIndexTargets - Lists all IndexTargets                             /*{{{*/
 static std::string format_key(std::string key)
 {
    // deb822 is case-insensitive, but the human eye prefers candy
@@ -1484,7 +1442,7 @@ static std::string format_key(std::string key)
    }
    return key;
 }
-static bool DoFiles(CommandLine &CmdL)
+static bool DoIndexTargets(CommandLine &CmdL)
 {
    pkgCacheFile CacheFile;
    pkgSourceList *SrcList = CacheFile.GetSourceList();
@@ -1492,8 +1450,8 @@ static bool DoFiles(CommandLine &CmdL)
    if (SrcList == NULL)
       return false;
 
-   std::string const Format = _config->Find("APT::Get::Files::Format");
-   bool const ReleaseInfo = _config->FindB("APT::Get::Files::ReleaseInfo", true);
+   std::string const Format = _config->Find("APT::Get::IndexTargets::Format");
+   bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
    bool Filtered = CmdL.FileSize() > 1;
    for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
    {
@@ -1529,11 +1487,21 @@ static bool DoFiles(CommandLine &CmdL)
               << "Description: " << T->Description << "\n"
               << "URI: " << T->URI << "\n"
               << "Filename: " << filename << "\n"
-              << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n";
+              << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n"
+              << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n";
            for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
               stanza << format_key(O->first) << ": " << O->second << "\n";
            for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
-              stanza << format_key(O->first) << ": " << O->second << "\n";
+           {
+              if (O->first == "PDIFFS")
+                 stanza << "PDiffs: " << O->second << "\n";
+              else if (O->first == "COMPRESSIONTYPES")
+                 stanza << "CompressionTypes: " << O->second << "\n";
+              else if (O->first == "DEFAULTENABLED")
+                 stanza << "DefaultEnabled: " << O->second << "\n";
+              else
+                 stanza << format_key(O->first) << ": " << O->second << "\n";
+           }
            stanza << "\n";
 
            if (Filtered)
@@ -1676,18 +1644,21 @@ int main(int argc,const char *argv[])                                   /*{{{*/
                                    {"remove",&DoInstall},
                                    {"purge",&DoInstall},
                                   {"autoremove",&DoInstall},
+                                  {"auto-remove",&DoInstall},
                                   {"markauto",&DoMarkAuto},
                                   {"unmarkauto",&DoMarkAuto},
                                    {"dist-upgrade",&DoDistUpgrade},
+                                   {"full-upgrade",&DoDistUpgrade},
                                    {"dselect-upgrade",&DoDSelectUpgrade},
                                   {"build-dep",&DoBuildDep},
                                    {"clean",&DoClean},
                                    {"autoclean",&DoAutoClean},
+                                   {"auto-clean",&DoAutoClean},
                                    {"check",&DoCheck},
                                   {"source",&DoSource},
                                    {"download",&DoDownload},
                                    {"changelog",&DoChangelog},
-                                  {"files",&DoFiles},
+                                  {"indextargets",&DoIndexTargets},
                                   {"moo",&DoMoo},
                                   {"help",&ShowHelp},
                                    {0,0}};