summaryrefslogtreecommitdiff
path: root/src/AuthConfigFactory.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-10-27 12:58:46 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-10-27 12:58:46 +0000
commit14a47f43f8ce0aa4c924e71d4a131a3ddcd29bf9 (patch)
tree116b0a1fd23453bba4f08e1350a8de731cc75b91 /src/AuthConfigFactory.cc
parentcda8b2e343d282413bcbec078bbdd5ec2fdacf49 (diff)
2009-10-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
If user name is embedded but password is missing in URI, first resolve password using .netrc. If password is found in .netrc, then use it as password. If not, use the password specified in --ftp-passwd. * src/AuthConfigFactory.cc * src/Request.cc * src/Request.h * test/AuthConfigFactoryTest.cc
Diffstat (limited to 'src/AuthConfigFactory.cc')
-rw-r--r--src/AuthConfigFactory.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc
index c3dfc823..b1b129b7 100644
--- a/src/AuthConfigFactory.cc
+++ b/src/AuthConfigFactory.cc
@@ -86,7 +86,26 @@ AuthConfigFactory::createAuthConfig
}
} else if(request->getProtocol() == Request::PROTO_FTP) {
if(!request->getUsername().empty()) {
- return createAuthConfig(request->getUsername(), request->getPassword());
+ if(request->hasPassword()) {
+ return createAuthConfig(request->getUsername(), request->getPassword());
+ } else {
+ if(!op->getAsBool(PREF_NO_NETRC)) {
+ // First, check we have password corresponding to host and
+ // username
+ NetrcAuthResolver authResolver;
+ authResolver.setNetrc(_netrc);
+
+ SharedHandle<AuthConfig> ac =
+ authResolver.resolveAuthConfig(request->getHost());
+ if(!ac.isNull() && ac->getUser() == request->getUsername()) {
+ return ac;
+ }
+ }
+ // We don't have password for host and username. Return
+ // password specified by --ftp-passwd
+ return
+ createAuthConfig(request->getUsername(), op->get(PREF_FTP_PASSWD));
+ }
} else {
return
createFtpAuthResolver(op)->resolveAuthConfig(request->getHost());