Subject: 24.1.50; [url] bugs in authenticated proxy handling

From: Jason Rumney <[email-masked]>
Date: Sat, 28 Jul 2012 01:09:02 +0800

I tried to use list-packages from behind a proxy which requires
authentication.  I was prompted for my user name and password for the
proxy, and after entering it, the package list download failed.  Trying
again, I was prompted for the password again, and the failure repeated.

Applying the patch below, I am only prompted the first time for my
password, and the second and subsequent attempts do not fail.  I am not
very familiar with the url package, so I am not sure this is the correct
fix for the issue of cached proxy passwords not being used. But before
the patch I saw multiple identical copies of my username/password for
the proxy stored in url-http-proxy-basic-auth-storage, while after the
patch only one copy is stored, and subsequent attempts do not prompt for
the password, so it seems correct.

There is still a bug occuring on the first attempt though.  It seems
that two buffers are created on that attempt - one containing the 407
response requesting proxy authentication, and another containing the
subsequent response from the target server after the proxy credentials
have been supplied.  The buffer returned to the package code is the
first one, but it needs the second.  I'm not sure whether this is a bug
in url, or in the way package.el uses it, and edebug seemed to have
problems with parts of the url package, so I could not investigate in
detail.

=== modified file 'lisp/url/url-http.el'
*** lisp/url/url-http.el	2012-07-11 23:13:41 +0000
--- lisp/url/url-http.el	2012-07-27 16:49:07 +0000
***************
*** 239,245 ****
  			 nil
  		       (let ((url-basic-auth-storage
  			      'url-http-proxy-basic-auth-storage))
! 			 (url-get-authentication url-http-target-url nil 'any nil))))
  	 (real-fname (url-filename url-http-target-url))
  	 (host (url-host url-http-target-url))
  	 (auth (if (cdr-safe (assoc "Authorization" url-http-extra-headers))
--- 239,245 ----
  			 nil
  		       (let ((url-basic-auth-storage
  			      'url-http-proxy-basic-auth-storage))
! 			 (url-get-authentication url-http-proxy nil 'any nil))))
  	 (real-fname (url-filename url-http-target-url))
  	 (host (url-host url-http-target-url))
  	 (auth (if (cdr-safe (assoc "Authorization" url-http-extra-headers))

In GNU Emacs 24.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.10)
 of 2012-07-18 on wanchan
Bzr revision: 109147 [email-masked]
Windowing system distributor `The X.Org Foundation', version 11.0.11202902
Important settings:
  value of $LANG: en_NZ.utf8
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Emacs-Lisp

Minor modes in effect:
  shell-dirtrack-mode: t
  diff-auto-refine-mode: t
  show-paren-mode: t
  recentf-mode: t
  display-time-mode: t
  cua-mode: t
  global-semanticdb-minor-mode: t
  global-semantic-idle-scheduler-mode: t
  semantic-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<down-mouse-1> <mouse-2> q <down-mouse-1> <mouse-2> 
q <down> C-k s <up> <up> <up> <up> C-x C-f <up> <backspace> 
<backspace> <backspace> <backspace> <backspace> <backspace> 
<backspace> <backspace> <backspace> <backspace> <backspace> 
<backspace> <backspace> <backspace> <backspace> <backspace> 
<backspace> / l i s <tab> u r <tab> <tab> u r <tab> 
- h <tab> t <tab> <return> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <up> <down> 
<down> <right> <right> <right> <right> <right> <right> 
<right> <right> <left> <delete> <delete> <delete> <delete> 
<delete> <delete> <delete> <delete> <delete> <delete> 
<delete> <delete> <delete> <delete> <delete> <delete> 
<delete> <delete> <delete> u r l - h t t p - p r o 
x y <left> <left> <left> <left> <left> <left> <left> 
<left> <left> <left> <left> <left> <left> <left> <left> 
<left> <left> <left> <right> <right> <right> <right> 
<right> <right> <right> <right> <right> <right> <right> 
<right> <right> <down> C-x C-s <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <down-mouse-1> 
<mouse-1> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <down-mouse-1> 
<mouse-movement> <mouse-1> <down-mouse-1> <mouse-1> 
<down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> <down-mouse-1> 
<mouse-movement> <mouse-1> <down-mouse-1> <mouse-movement> 
<mouse-movement> <drag-mouse-1> <down-mouse-1> <mouse-movement> 
<mouse-1> <down-mouse-1> <mouse-movement> <mouse-movement> 
<drag-mouse-1> <down-mouse-1> <mouse-1> C-x v = <help-echo> 
<down-mouse-1> <mouse-movement> <mouse-movement> <mouse-movement> 
<mouse-movement> <mouse-movement> <mouse-movement> 
<help-echo> <mouse-movement> <mouse-movement> <mouse-movement> 
<mouse-movement> <mouse-movement> <mouse-movement> 
<mouse-movement> <mouse-movement> <drag-mouse-1> <escape> 
w <down-mouse-4> <mouse-4> <double-down-mouse-4> <double-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <down-mouse-1> <mouse-movement> <mouse-movement> 
<help-echo> <mouse-movement> <mouse-movement> <mouse-movement> 
<mouse-movement> <mouse-movement> <drag-mouse-1> <help-echo> 
<escape> w <help-echo> <help-echo> <down-mouse-1> <mouse-1> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <menu-bar> <help-menu> 
<send-emacs-bug-report>

Recent messages:
Saving file /home/jasonr/.newsrc...
Wrote /home/jasonr/.newsrc
Saving /home/jasonr/.newsrc.eld...
Saving file /home/jasonr/.newsrc.eld...
Wrote /home/jasonr/.newsrc.eld
Saving /home/jasonr/.newsrc.eld...done
Making completion list... [2 times]
Saving file /home/jasonr/repo/emacs/trunk/lisp/url/url-http.el...
Wrote /home/jasonr/repo/emacs/trunk/lisp/url/url-http.el
Finding changes in /home/jasonr/repo/emacs/trunk/lisp/url/url-http.el...done
byte-code: Beginning of buffer [2 times]

Load-path shadows:
None found.

Features:
(shadow emacsbug shell grep compile whitespace vc-annotate gnus-dup
gnus-fun semantic/tag-write add-log log-view pcvs-util vc ediff-merg
ediff-diff ediff-wind ediff-help ediff-util ediff-mult ediff-init ediff
vc-dispatcher semantic/bovine semantic/db-file cedet-files
semantic/bovine/c semantic/decorate/include semantic/db-find
semantic/db-ref semantic/decorate/mode semantic/decorate
semantic/bovine/c-by semantic/lex-spp semantic/bovine/gcc semantic/dep
cc-langs cl cl-lib cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles
cc-align cc-engine cc-vars cc-defs multi-isearch vc-bzr help-mode
diff-mode thingatpt flyspell ispell semantic/ia pulse semantic/analyze
semantic/sort semantic/scope semantic/analyze/fcn mule-util shr-color
color shr browse-url sort smiley gnus-cite flow-fill mm-archive
mail-extr gnus-async gnus-bcklg qp gnus-ml disp-table nndraft nnmh
nnfolder utf-7 epa-file epa derived epg network-stream auth-source
starttls nnimap parse-time tls utf7 netrc gnus-agent gnus-srvr
gnus-score score-mode nnvirtual gnus-msg gnus-art mm-uu mml2015
epg-config mm-view mml-smime smime password-cache dig mailcap nntp
gnus-cache gnus-sum nnoo gnus-group gnus-undo nnmail mail-source
gnus-start gnus-spec gnus-int gnus-range message sendmail rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mailabbrev gmm-utils mailheader gnus-win debbugs-autoloads
minimap-autoloads package jka-compr org-mouse org-w3m org-jsinfo
org-infojs org-html org-exp ob-exp org-exp-blocks find-func org-agenda
org-info org-id org-gnus org-bbdb paren recentf tree-widget gnus
gnus-ems nnheader gnus-util mail-utils mm-util mail-prsvr wid-edit time
cua-base cus-start cus-load semantic/db-mode semantic/db gv eieio-base
semantic/idle semantic/format ezimage semantic/tag-ls semantic/ctxt
semantic/util-modes semantic/util semantic semantic/tag semantic/lex
semantic/fw eieio mode-local cedet remember org-remember org-datetree
org byte-opt warnings bytecomp byte-compile cconv macroexp advice
help-fns advice-preload ob-emacs-lisp ob-tangle ob-ref ob-lob ob-table
org-footnote org-src ob-comint ob-keys ob ob-eval org-pcomplete
pcomplete comint ansi-color ring org-list org-faces org-compat
org-entities org-macs noutline outline easy-mmode format-spec cal-menu
easymenu calendar cal-loaddefs server time-date tooltip ediff-hook
vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process dbusbind dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty emacs)