]> git.saurik.com Git - apt.git/blobdiff - methods/ftp.cc
implement operator* for cacheset iterators
[apt.git] / methods / ftp.cc
index 66787a7bea661808f147804ea020426cc2690b5a..d84a194ca3b4c3b72bed6d654cdf45ceeb6a68e5 100644 (file)
@@ -39,7 +39,6 @@
 
 // Internet stuff
 #include <netinet/in.h>
 
 // Internet stuff
 #include <netinet/in.h>
-#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netdb.h>
 
 #include <arpa/inet.h>
 #include <netdb.h>
 
@@ -75,9 +74,10 @@ time_t FtpMethod::FailTime = 0;
 // FTPConn::FTPConn - Constructor                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // FTPConn::FTPConn - Constructor                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-FTPConn::FTPConn(URI Srv) : Len(0), ServerFd(-1), DataFd(-1), 
+FTPConn::FTPConn(URI Srv) : Len(0), ServerFd(-1), DataFd(-1),
                             DataListenFd(-1), ServerName(Srv),
                             DataListenFd(-1), ServerName(Srv),
-                           ForceExtended(false), TryPassive(true)
+                           ForceExtended(false), TryPassive(true),
+                           PeerAddrLen(0), ServerAddrLen(0)
 {
    Debug = _config->FindB("Debug::Acquire::Ftp",false);
    PasvAddr = 0;
 {
    Debug = _config->FindB("Debug::Acquire::Ftp",false);
    PasvAddr = 0;
@@ -258,19 +258,21 @@ bool FTPConn::Login()
       {
         if (Opts->Value.empty() == true)
            continue;
       {
         if (Opts->Value.empty() == true)
            continue;
-        
+
         // Substitute the variables into the command
         // Substitute the variables into the command
-        char SitePort[20];
-        if (ServerName.Port != 0)
-           sprintf(SitePort,"%u",ServerName.Port);
-        else
-           strcpy(SitePort,"21");
         string Tmp = Opts->Value;
         Tmp = SubstVar(Tmp,"$(PROXY_USER)",Proxy.User);
         Tmp = SubstVar(Tmp,"$(PROXY_PASS)",Proxy.Password);
         Tmp = SubstVar(Tmp,"$(SITE_USER)",User);
         Tmp = SubstVar(Tmp,"$(SITE_PASS)",Pass);
         string Tmp = Opts->Value;
         Tmp = SubstVar(Tmp,"$(PROXY_USER)",Proxy.User);
         Tmp = SubstVar(Tmp,"$(PROXY_PASS)",Proxy.Password);
         Tmp = SubstVar(Tmp,"$(SITE_USER)",User);
         Tmp = SubstVar(Tmp,"$(SITE_PASS)",Pass);
-        Tmp = SubstVar(Tmp,"$(SITE_PORT)",SitePort);
+        if (ServerName.Port != 0)
+        {
+           std::string SitePort;
+           strprintf(SitePort, "%u", ServerName.Port);
+           Tmp = SubstVar(Tmp,"$(SITE_PORT)", SitePort);
+        }
+        else
+           Tmp = SubstVar(Tmp,"$(SITE_PORT)", "21");
         Tmp = SubstVar(Tmp,"$(SITE)",ServerName.Host);
 
         // Send the command
         Tmp = SubstVar(Tmp,"$(SITE)",ServerName.Host);
 
         // Send the command
@@ -743,7 +745,7 @@ bool FTPConn::CreateDataFd()
    }
    
    // Bind and listen
    }
    
    // Bind and listen
-   if (bind(DataListenFd,BindAddr->ai_addr,BindAddr->ai_addrlen) < 0)
+   if (::bind(DataListenFd,BindAddr->ai_addr,BindAddr->ai_addrlen) < 0)
    {
       freeaddrinfo(BindAddr);
       return _error->Errno("bind",_("Could not bind a socket"));
    {
       freeaddrinfo(BindAddr);
       return _error->Errno("bind",_("Could not bind a socket"));
@@ -848,7 +850,8 @@ bool FTPConn::Finalize()
 /* This opens a data connection, sends REST and RETR and then
    transfers the file over. */
 bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
 /* This opens a data connection, sends REST and RETR and then
    transfers the file over. */
 bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
-                 Hashes &Hash,bool &Missing)
+                 Hashes &Hash,bool &Missing, unsigned long long MaximumSize,
+                  pkgAcqMethod *Owner)
 {
    Missing = false;
    if (CreateDataFd() == false)
 {
    Missing = false;
    if (CreateDataFd() == false)
@@ -921,7 +924,14 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
       {
         Close();
         return false;
       {
         Close();
         return false;
-      }      
+      }
+
+      if (MaximumSize > 0 && To.Tell() > MaximumSize)
+      {
+         Owner->SetFailReason("MaximumSizeExceeded");
+         return _error->Error("Writing more data than expected (%llu > %llu)",
+                              To.Tell(), MaximumSize);
+      }
    }
 
    // All done
    }
 
    // All done
@@ -979,6 +989,10 @@ bool FtpMethod::Configuration(string Message)
       return false;
    
    TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
       return false;
    
    TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
+
+   // no more active ftp, sorry
+   DropPrivsOrDie();
+
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
@@ -1049,7 +1063,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
    }
    
    // Open the file
    }
    
    // Open the file
-   Hashes Hash;
+   Hashes Hash(Itm->ExpectedHashes);
    {
       FileFd Fd(Itm->DestFile,FileFd::WriteAny);
       if (_error->PendingError() == true)
    {
       FileFd Fd(Itm->DestFile,FileFd::WriteAny);
       if (_error->PendingError() == true)
@@ -1058,11 +1072,11 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       URIStart(Res);
       
       FailFile = Itm->DestFile;
       URIStart(Res);
       
       FailFile = Itm->DestFile;
-      FailFile.c_str();   // Make sure we dont do a malloc in the signal handler
+      FailFile.c_str();   // Make sure we don't do a malloc in the signal handler
       FailFd = Fd.Fd();
       
       bool Missing;
       FailFd = Fd.Fd();
       
       bool Missing;
-      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing) == false)
+      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Itm->MaximumSize,this) == false)
       {
         Fd.Close();
 
       {
         Fd.Close();
 
@@ -1131,6 +1145,6 @@ int main(int, const char *argv[])
    }
    
    FtpMethod Mth;
    }
    
    FtpMethod Mth;
-   
+
    return Mth.Run();
 }
    return Mth.Run();
 }