http:authorization patch (was Re: [Fwd: Bug#258392: lftp should support encrypted passwords in bookmarks])

"Alexander V. Lukyanov" <[email protected]>
Newsgroups gmane.network.lftp.devel
Message-ID <[email protected]>
On Thu, Aug 12, 2004 at 01:28:59PM +0400, Alexander V. Lukyanov wrote:
> On Thu, Aug 12, 2004 at 05:12:10AM -0400, Glenn Maynard wrote:
> > That's a bit better, but I still have to back up and enter my username.  URLs
> > copied from browsers usually don't contain it.
>
> It should not be very hard to add a setting like http:default-auth to specify
> default authorization to use if no user is specified. It can be host-specific
> already (set http:default-auth/*.foo.com user:pass).

Here is a patch to add http:authorization.

--
   Alexander.                      | http://www.yars.free.net/~lav/
diff (text/plain, 6.4 KB)
Index: doc/ChangeLog
===================================================================
RCS file: /home/lav/cvsroot/lftp/doc/ChangeLog,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -p -r1.65 -r1.66
--- doc/ChangeLog	24 May 2004 15:16:35 -0000	1.65
+++ doc/ChangeLog	12 Aug 2004 09:56:40 -0000	1.66
@@ -1,3 +1,8 @@
+2004-08-12	Alexander V. Lukyanov <[email protected]>
+
+	* lftp.1: document ftp:proxy-auth-joined, http:authorization and
+	  http:cache-control.
+
 2004-05-24	Alexander V. Lukyanov <[email protected]>
 
 	* lftp.1: document ftp:ssl-protect-{list,fxp}.
Index: doc/lftp.1
===================================================================
RCS file: /home/lav/cvsroot/lftp/doc/lftp.1,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -p -r1.92 -r1.93
--- doc/lftp.1	24 May 2004 15:16:36 -0000	1.92
+++ doc/lftp.1	12 Aug 2004 09:56:41 -0000	1.93
@@ -17,7 +17,7 @@
 .\" along with this program; see the file COPYING.  If not, write to
 .\" the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 .\"
-.\" $Id: lftp.1,v 1.92 2004/05/24 15:16:36 lav Exp $
+.\" $Id: lftp.1,v 1.93 2004/08/12 09:56:41 lav Exp $
 .\"
 .\"-------
 .\" Sp  space down the interparagraph distance
@@ -982,6 +982,11 @@ requires authentication, specify user na
 If ftp:proxy starts with http://, hftp (ftp over http proxy) is used instead
 of ftp automatically.
 .TP
+.BR ftp:proxy-auth-joined \ (bool)
+when true, lftp sends ``user@[email protected]'' as user name to proxy,
+and ``password@proxy_password'' as password. When false, it first sends 
+proxy user and proxy password and then ``[email protected]'' and password.
+.TP
 .BR ftp:rest-list \ (bool)
 allow usage of REST command before LIST command. This might be useful for
 large directories, but some ftp servers silently ignore REST before LIST.
@@ -1148,8 +1153,15 @@ Some broken proxies don't handle it corr
 .BR "http:accept, http:accept-charset, http:accept-language" " (string)"
 specify corresponding HTTP request headers.
 .TP
+.BR http:authorization \ (string)
+the authorization to use by default, when no user is specified. The format
+is ``user:password''. Default is empty which means no authorization.
+.TP
 .BR http:cache \ (bool)
 allow server/proxy side caching.
+.TP
+.BR http:cache-control \ (string)
+specify corresponding HTTP request header.
 .TP
 .BR http:cookie \ (string)
 send this cookie to server. A closure is useful here:
Index: src/ChangeLog
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/ChangeLog,v
retrieving revision 1.838
retrieving revision 1.839
diff -u -p -r1.838 -r1.839
--- src/ChangeLog	3 Aug 2004 11:43:32 -0000	1.838
+++ src/ChangeLog	12 Aug 2004 09:58:10 -0000	1.839
@@ -1,3 +1,7 @@
+2004-08-12  Alexander V. Lukyanov <[email protected]>
+
+	* Http.cc, Http.h, resource.cc: add http:authorization setting.
+
 2004-08-03  Alexander V. Lukyanov <[email protected]>
 
 	* buffer_std.cc, buffer_std.h: new files.
Index: src/Http.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/Http.cc,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -p -r1.171 -r1.172
--- src/Http.cc	3 Aug 2004 11:34:36 -0000	1.171
+++ src/Http.cc	12 Aug 2004 09:58:10 -0000	1.172
@@ -18,7 +18,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/* $Id: Http.cc,v 1.171 2004/08/03 11:34:36 lav Exp $ */
+/* $Id: Http.cc,v 1.172 2004/08/12 09:58:10 lav Exp $ */
 
 #include <config.h>
 #include "trio.h"
@@ -353,15 +353,21 @@ void Http::SendMethod(const char *method
    }
 }
 
-
+void Http::SendBasicAuth(const char *tag,const char *auth)
+{
+   if(!auth || !*auth)
+      return;
+   int auth_len=strlen(auth);
+   char *buf64=string_alloca(base64_length(auth_len)+1);
+   base64_encode(auth,buf64,auth_len);
+   Send("%s: Basic %s\r\n",tag,buf64);
+}
 void Http::SendBasicAuth(const char *tag,const char *user,const char *pass)
 {
    /* Basic scheme */
    char *buf=string_alloca(strlen(user)+1+strlen(pass)+1);
    sprintf(buf,"%s:%s",user,pass);
-   char *buf64=string_alloca(base64_length(strlen(buf))+1);
-   base64_encode(buf,buf64,strlen(buf));
-   Send("%s: Basic %s\r\n",tag,buf64);
+   SendBasicAuth(tag,buf);
 }
 
 void Http::SendAuth()
@@ -370,6 +376,8 @@ void Http::SendAuth()
       SendBasicAuth("Proxy-Authorization",proxy_user,proxy_pass);
    if(user && pass && !(hftp && !QueryBool("use-authorization",proxy)))
       SendBasicAuth("Authorization",user,pass);
+   else if(!hftp)
+      SendBasicAuth("Authorization",Query("authorization",hostname));
 }
 void Http::SendCacheControl()
 {
Index: src/Http.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/Http.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -p -r1.41 -r1.42
--- src/Http.h	3 Aug 2004 11:34:36 -0000	1.41
+++ src/Http.h	12 Aug 2004 09:58:11 -0000	1.42
@@ -18,7 +18,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/* $Id: Http.h,v 1.41 2004/08/03 11:34:36 lav Exp $ */
+/* $Id: Http.h,v 1.42 2004/08/12 09:58:11 lav Exp $ */
 
 #ifndef HTTP_H
 #define HTTP_H
@@ -60,6 +60,7 @@ class Http : public NetAccess
    char *post_data;
    void SendAuth();
    void SendCacheControl();
+   void SendBasicAuth(const char *tag,const char *auth);
    void SendBasicAuth(const char *tag,const char *u,const char *p);
    void SendRequest(const char *connection,const char *f);
    void SendRequest(const char *connection=0)
Index: src/resource.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/resource.cc,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -p -r1.106 -r1.107
--- src/resource.cc	3 Aug 2004 11:34:41 -0000	1.106
+++ src/resource.cc	12 Aug 2004 09:58:12 -0000	1.107
@@ -18,7 +18,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/* $Id: resource.cc,v 1.106 2004/08/03 11:34:41 lav Exp $ */
+/* $Id: resource.cc,v 1.107 2004/08/12 09:58:12 lav Exp $ */
 
 #include <config.h>
 
@@ -235,6 +235,7 @@ static ResDecl
    ResDecl24a("http:accept",		  "*/*",   0,0),
    ResDecl24b("http:accept-language",	  "",	   0,0),
    ResDecl24c("http:accept-charset",	  "",	   0,0),
+   ResDecl24e("http:authorization",	  "",	   0,0),
    ResDecl24 ("http:cache",		  "yes",   ResMgr::BoolValidate,0),
    ResDecl24d("http:cache-control",	  "",	   0,0),
    ResDecl25 ("http:proxy",		  "",	   HttpProxyValidate,0),
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.