X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b2e465d6d32d2dc884f58b94acb7e35f671a87fe..91bb3e2e916e4e963d6a872c696ef46bbd86246b:/methods/ftp.cc diff --git a/methods/ftp.cc b/methods/ftp.cc index 0d617dd8f..10f1406f5 100644 --- a/methods/ftp.cc +++ b/methods/ftp.cc @@ -1,9 +1,9 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: ftp.cc,v 1.21 2001/02/20 07:03:18 jgg Exp $ +// $Id: ftp.cc,v 1.29 2002/04/24 05:35:13 jgg Exp $ /* ###################################################################### - HTTP Aquire Method - This is the FTP aquire method for APT. + FTP Aquire Method - This is the FTP aquire method for APT. This is a very simple implementation that does not try to optimize at all. Commands are sent syncronously with the FTP server (as the @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -28,6 +28,7 @@ #include #include #include +#include // Internet stuff #include @@ -40,6 +41,8 @@ #include "ftp.h" /*}}}*/ +using namespace std; + /* This table is for the EPRT and EPSV commands, it maps the OS address family to the IETF address families */ struct AFMap @@ -125,6 +128,13 @@ bool FTPConn::Open(pkgAcqMethod *Owner) else Proxy = getenv("ftp_proxy"); + // Parse no_proxy, a , separated list of domains + if (getenv("no_proxy") != 0) + { + if (CheckDomainList(ServerName.Host,getenv("no_proxy")) == true) + Proxy = ""; + } + // Determine what host and port to use based on the proxy settings int Port = 0; string Host; @@ -146,6 +156,10 @@ bool FTPConn::Open(pkgAcqMethod *Owner) RotateDNS(); if (Connect(Host,Port,"ftp",21,ServerFd,TimeOut,Owner) == false) return false; + + // Login must be before getpeername otherwise dante won't work. + Owner->Status("Logging in"); + bool Res = Login(); // Get the remote server's address PeerAddrLen = sizeof(PeerAddr); @@ -157,8 +171,7 @@ bool FTPConn::Open(pkgAcqMethod *Owner) if (getsockname(ServerFd,(sockaddr *)&ServerAddr,&ServerAddrLen) != 0) return _error->Errno("getsockname","Unable to determine the local name"); - Owner->Status("Logging in"); - return Login(); + return Res; } /*}}}*/ // FTPConn::Login - Login to the remote server /*{{{*/ @@ -172,7 +185,7 @@ bool FTPConn::Login() // Setup the variables needed for authentication string User = "anonymous"; - string Pass = "apt_get_ftp_2.0@debian.linux.user"; + string Pass = "apt_get_ftp_2.1@debian.linux.user"; // Fill in the user/pass if (ServerName.User.empty() == false) @@ -818,7 +831,7 @@ 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 Resume, - MD5Summation &MD5,bool &Missing) + Hashes &Hash,bool &Missing) { Missing = false; if (CreateDataFd() == false) @@ -842,7 +855,7 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long Resume, if (Resume != 0) { - if (MD5.AddFD(To.Fd(),Resume) == false) + if (Hash.AddFD(To.Fd(),Resume) == false) { _error->Errno("read","Problem hashing file"); return false; @@ -886,7 +899,7 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long Resume, break; } - MD5.Add(Buffer,Res); + Hash.Add(Buffer,Res); if (To.Write(Buffer,Res) == false) { Close(); @@ -1015,7 +1028,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) } // Open the file - MD5Summation MD5; + Hashes Hash; { FileFd Fd(Itm->DestFile,FileFd::WriteAny); if (_error->PendingError() == true) @@ -1028,7 +1041,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) FailFd = Fd.Fd(); bool Missing; - if (Server->Get(File,Fd,Res.ResumePoint,MD5,Missing) == false) + if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing) == false) { Fd.Close(); @@ -1049,7 +1062,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) } Res.LastModified = FailTime; - Res.MD5Sum = MD5.Result(); + Res.TakeHashes(Hash); // Timestamp struct utimbuf UBuf; @@ -1071,15 +1084,18 @@ int main(int argc,const char *argv[]) if (getenv("ftp_proxy") != 0) { URI Proxy = string(getenv("ftp_proxy")); + + // Run the HTTP method if (Proxy.Access == "http") { // Copy over the environment setting char S[300]; snprintf(S,sizeof(S),"http_proxy=%s",getenv("ftp_proxy")); putenv(S); + putenv("no_proxy="); // Run the http method - string Path = flNotFile(argv[0]) + "/http"; + string Path = flNotFile(argv[0]) + "http"; execl(Path.c_str(),Path.c_str(),0); cerr << "Unable to invoke " << Path << endl; exit(100);