Correctly use user:pass directly embedded in a proxy url (bnc#740764)
authorMichael Andres <ma@suse.de>
Mon, 16 Jan 2012 10:43:35 +0000 (11:43 +0100)
committerMichael Andres <ma@suse.de>
Mon, 16 Jan 2012 10:47:56 +0000 (11:47 +0100)
zypp/media/MediaCurl.cc

index 46a6f26..bd10ddc 100644 (file)
@@ -333,9 +333,19 @@ void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
 #else
     ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
 #endif
-    s.setProxyEnabled( proxy_info.useProxyFor( url ) );
-    if ( s.proxyEnabled() )
-      s.setProxy(proxy_info.proxy(url));
+    if ( proxy_info.useProxyFor( url ) )
+    {
+      // We must extract any 'user:pass' from the proxy url
+      // otherwise they won't make it into curl (.curlrc wins).
+      try {
+       Url u( proxy_info.proxy( url ) );
+       s.setProxy( u.asString( url::ViewOption::WITH_SCHEME + url::ViewOption::WITH_HOST + url::ViewOption::WITH_PORT ) );
+       s.setProxyUsername( u.getUsername( url::E_ENCODED ) );
+       s.setProxyPassword( u.getPassword( url::E_ENCODED ) );
+       s.setProxyEnabled( true );
+      }
+      catch (...) {}   // no proxy if URL is malformed
+    }
 }
 
 Pathname MediaCurl::_cookieFile = "/var/lib/YaST2/cookies";
@@ -642,10 +652,15 @@ void MediaCurl::setupEasy()
           DBG << "using proxy-user from ~/.curlrc" << endl;
         }
       }
+      else
+      {
+       DBG << "using provided proxy-user" << endl;
+      }
 
-      proxyuserpwd = unEscape( proxyuserpwd );
       if ( ! proxyuserpwd.empty() )
-        SET_OPTION(CURLOPT_PROXYUSERPWD, proxyuserpwd.c_str());
+      {
+       SET_OPTION(CURLOPT_PROXYUSERPWD, unEscape( proxyuserpwd ).c_str());
+      }
     }
   }
   else