Re: http authentication on lftp 4.7.x versions

"Alexander V. Lukyanov" <[email protected]> Fri, 6 May 2016 15:42:32 +0300
Newsgroups gmane.network.lftp.user
Message-ID <20160506124232.GA68546@lav-w>
On Wed, May 04, 2016 at 01:42:39PM +0100, Frederico Costa wrote:
> Hi,
>
> Thanks for the reply.
>
> here is the debug output from 4.7.1, i used debug 3 command:

Please try this patch. As a workaround you can also try to specify user
name (and possibly password) in the URL:

   open https://[email protected]
   open https://user:[email protected]

--
   Alexander.

_______________________________________________
lftp mailing list
[email protected]
http://univ.uniyar.ac.ru/mailman/listinfo/lftp
http-auth.diff (text/plain, 2.1 KB)
diff --git a/src/Http.cc b/src/Http.cc
index c4d2163..fadc98c 100644
--- a/src/Http.cc
+++ b/src/Http.cc
@@ -469,7 +469,7 @@ void Http::SendAuth()
       SendBasicAuth("Authorization",user,pass);
       return;
    }
-   SendAuth(HttpAuth::WWW,user,last_uri);
+   SendAuth(HttpAuth::WWW,user?user:auth_user,last_uri);
 }
 void Http::SendCacheControl()
 {
@@ -1082,22 +1082,10 @@ void Http::HandleHeaderLine(const char *name,const char *value)
    case_hh("WWW-Authenticate",'W') {
       if(status_code!=H_Unauthorized)
 	 return;
-      const char *user=this->user;
-      const char *pass=this->pass;
-      if(!user || !pass) {
-	 // try auth info from http:authorization setting
-	 const char *auth_c=Query("authorization",hostname);
-         if(auth_c && *auth_c) {
-	    char *auth=alloca_strdup(auth_c);
-	    char *colon=strchr(auth,':');
-	    if(colon) {
-	       *colon=0;
-	       user=auth;
-	       pass=colon+1;
-	    }
-	 }
-      }
-      NewAuth(value,HttpAuth::WWW,user,pass);
+      if(user && pass)
+	 NewAuth(value,HttpAuth::WWW,user,pass);
+      else
+	 NewAuth(value,HttpAuth::WWW,auth_user,auth_pass);
       return;
    }
    case_hh("Proxy-Authenticate",'P') {
@@ -2313,6 +2301,20 @@ void Http::Reconfig(const char *name)
    if(!QueryBool("use-allprop",c))
       allprop="";
    allprop_len=strlen(allprop);
+
+   if(!user || !pass) {
+      // get auth info from http:authorization setting
+      const char *auth_c=Query("authorization",hostname);
+      if(auth_c && *auth_c) {
+	 char *auth=alloca_strdup(auth_c);
+	 char *colon=strchr(auth,':');
+	 if(colon) {
+	    *colon=0;
+	    auth_user.set(auth);
+	    auth_pass.set(colon+1);
+	 }
+      }
+   }
 }
 
 bool Http::SameSiteAs(const FileAccess *fa) const
diff --git a/src/Http.h b/src/Http.h
index bea3b4d..c8a7c8e 100644
--- a/src/Http.h
+++ b/src/Http.h
@@ -169,6 +169,9 @@ class Http : public NetAccess
    void NewAuth(const char *hdr,HttpAuth::target_t target,const char *user,const char *pass);
    void SendAuth(HttpAuth::target_t target,const char *user,const char *uri);
 
+   xstring_c auth_user;
+   xstring_c auth_pass;
+
    bool use_propfind_now;
    const char *allprop;
    int allprop_len;