X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/dc738e7ae6a9c14992279dc2c52f71b14ced53aa..b1471fb3f60fdb9f91a45723ca70649204df7bdb:/methods/ftp.cc

diff --git a/methods/ftp.cc b/methods/ftp.cc
index cc2f1395d..3e1725823 100644
--- a/methods/ftp.cc
+++ b/methods/ftp.cc
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: ftp.cc,v 1.30 2003/02/10 07:34:41 doogie Exp $
+// $Id: ftp.cc,v 1.31.2.1 2004/01/16 18:58:50 mdz Exp $
 /* ######################################################################
 
    FTP Aquire Method - This is the FTP aquire method for APT.
@@ -15,11 +15,11 @@
    ##################################################################### */
 									/*}}}*/
 // Include Files							/*{{{*/
-#include <apti18n.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
+#include <apt-pkg/netrc.h>
 
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <iostream>
+#include <apti18n.h>
 
 // Internet stuff
 #include <netinet/in.h>
@@ -112,23 +113,28 @@ bool FTPConn::Open(pkgAcqMethod *Owner)
    Close();
    
    // Determine the proxy setting
-   if (getenv("ftp_proxy") == 0)
+   string SpecificProxy = _config->Find("Acquire::ftp::Proxy::" + ServerName.Host);
+   if (!SpecificProxy.empty())
    {
-      string DefProxy = _config->Find("Acquire::ftp::Proxy");
-      string SpecificProxy = _config->Find("Acquire::ftp::Proxy::" + ServerName.Host);
-      if (SpecificProxy.empty() == false)
-      {
-	 if (SpecificProxy == "DIRECT")
-	    Proxy = "";
-	 else
-	    Proxy = SpecificProxy;
-      }   
-      else
-	 Proxy = DefProxy;
+	   if (SpecificProxy == "DIRECT")
+		   Proxy = "";
+	   else
+		   Proxy = SpecificProxy;
    }
    else
-      Proxy = getenv("ftp_proxy");
-   
+   {
+	   string DefProxy = _config->Find("Acquire::ftp::Proxy");
+	   if (!DefProxy.empty())
+	   {
+		   Proxy = DefProxy;
+	   }
+	   else
+	   {
+		   char* result = getenv("ftp_proxy");
+		   Proxy = result ? result : "";
+	   }
+   }
+
    // Parse no_proxy, a , separated list of domains
    if (getenv("no_proxy") != 0)
    {
@@ -201,7 +207,7 @@ bool FTPConn::Login()
       if (ReadResp(Tag,Msg) == false)
 	 return false;
       if (Tag >= 400)
-	 return _error->Error(_("Server refused our connection and said: %s"),Msg.c_str());
+	 return _error->Error(_("The server refused the connection and said: %s"),Msg.c_str());
       
       // Send the user
       if (WriteMsg(Tag,Msg,"USER %s",User.c_str()) == false)
@@ -209,11 +215,13 @@ bool FTPConn::Login()
       if (Tag >= 400)
 	 return _error->Error(_("USER failed, server said: %s"),Msg.c_str());
       
-      // Send the Password
-      if (WriteMsg(Tag,Msg,"PASS %s",Pass.c_str()) == false)
-	 return false;
-      if (Tag >= 400)
-	 return _error->Error(_("PASS failed, server said: %s"),Msg.c_str());
+      if (Tag == 331) { // 331 User name okay, need password.
+         // Send the Password
+         if (WriteMsg(Tag,Msg,"PASS %s",Pass.c_str()) == false)
+            return false;
+         if (Tag >= 400)
+            return _error->Error(_("PASS failed, server said: %s"),Msg.c_str());
+      }
       
       // Enter passive mode
       if (_config->Exists("Acquire::FTP::Passive::" + ServerName.Host) == true)
@@ -227,7 +235,7 @@ bool FTPConn::Login()
       if (ReadResp(Tag,Msg) == false)
 	 return false;
       if (Tag >= 400)
-	 return _error->Error(_("Server refused our connection and said: %s"),Msg.c_str());
+	 return _error->Error(_("The server refused the connection and said: %s"),Msg.c_str());
       
       // Perform proxy script execution
       Configuration::Item const *Opts = _config->Tree("Acquire::ftp::ProxyLogin");
@@ -441,7 +449,7 @@ bool FTPConn::WriteMsg(unsigned int &Ret,string &Text,const char *Fmt,...)
       int Res = write(ServerFd,S + Start,Len);
       if (Res <= 0)
       {
-	 _error->Errno("write",_("Write Error"));
+	 _error->Errno("write",_("Write error"));
 	 Close();
 	 return false;
       }
@@ -975,7 +983,9 @@ bool FtpMethod::Fetch(FetchItem *Itm)
    FetchResult Res;
    Res.Filename = Itm->DestFile;
    Res.IMSHit = false;
-   
+
+   maybe_add_auth (Get, _config->FindFile("Dir::Etc::netrc"));
+
    // Connect to the server
    if (Server == 0 || Server->Comp(Get) == false)
    {
@@ -1053,9 +1063,12 @@ bool FtpMethod::Fetch(FetchItem *Itm)
 	 UBuf.modtime = FailTime;
 	 utime(FailFile.c_str(),&UBuf);
 	 
-	 // If the file is missing we hard fail otherwise transient fail
-	 if (Missing == true)
+	 // If the file is missing we hard fail and delete the destfile
+	 // otherwise transient fail
+	 if (Missing == true) {
+	    unlink(FailFile.c_str());
 	    return false;
+	 }
 	 Fail(true);
 	 return true;
       }
@@ -1081,6 +1094,8 @@ bool FtpMethod::Fetch(FetchItem *Itm)
 
 int main(int argc,const char *argv[])
 { 
+   setlocale(LC_ALL, "");
+
    /* See if we should be come the http client - we do this for http
       proxy urls */
    if (getenv("ftp_proxy") != 0)
@@ -1094,11 +1109,11 @@ int main(int argc,const char *argv[])
 	 char S[300];
 	 snprintf(S,sizeof(S),"http_proxy=%s",getenv("ftp_proxy"));
 	 putenv(S);
-	 putenv("no_proxy=");
+	 putenv((char *)"no_proxy=");
 	 
 	 // Run the http method
 	 string Path = flNotFile(argv[0]) + "http";
-	 execl(Path.c_str(),Path.c_str(),0);
+	 execl(Path.c_str(),Path.c_str(),(char *)NULL);
 	 cerr << _("Unable to invoke ") << Path << endl;
 	 exit(100);
       }