diff options
author | Daniel Hartwig <mandyke@gmail.com> | 2015-08-11 17:59:13 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2015-08-12 11:55:47 +0200 |
commit | c7872a2c857bc54febb09721f5256786a15c002d (patch) | |
tree | a772b38d8b880ad99c7655c99bbc3487065f6a5b | |
parent | 26677b9c25b318c291d778eec758a06471fcba26 (diff) | |
download | apt-c7872a2c857bc54febb09721f5256786a15c002d.tar.gz |
support setting a port for rsh:// in sources.list
[Commiter comment: Untested, but looks and compiles fine, so what could
possibly go wrong]
Closes: 624727
-rw-r--r-- | methods/rsh.cc | 22 | ||||
-rw-r--r-- | methods/rsh.h | 1 |
2 files changed, 21 insertions, 2 deletions
diff --git a/methods/rsh.cc b/methods/rsh.cc index 52349c61c..7ef2f7c7a 100644 --- a/methods/rsh.cc +++ b/methods/rsh.cc @@ -84,7 +84,7 @@ bool RSHConn::Open() if (Process != -1) return true; - if (Connect(ServerName.Host,ServerName.User) == false) + if (Connect(ServerName.Host,ServerName.Port,ServerName.User) == false) return false; return true; @@ -93,8 +93,15 @@ bool RSHConn::Open() // RSHConn::Connect - Fire up rsh and connect /*{{{*/ // --------------------------------------------------------------------- /* */ -bool RSHConn::Connect(std::string Host, std::string User) +bool RSHConn::Connect(std::string Host, unsigned int Port, std::string User) { + char *PortStr = NULL; + if (Port != 0) + { + if (asprintf (&PortStr, "%d", Port) == -1 || PortStr == NULL) + return _error->Errno("asprintf", _("Failed")); + } + // Create the pipes int Pipes[4] = {-1,-1,-1,-1}; if (pipe(Pipes) != 0 || pipe(Pipes+2) != 0) @@ -140,6 +147,10 @@ bool RSHConn::Connect(std::string Host, std::string User) Args[i++] = "-l"; Args[i++] = User.c_str(); } + if (PortStr != NULL) { + Args[i++] = "-p"; + Args[i++] = PortStr; + } if (Host.empty() == false) { Args[i++] = Host.c_str(); } @@ -149,6 +160,9 @@ bool RSHConn::Connect(std::string Host, std::string User) exit(100); } + if (PortStr != NULL) + free(PortStr); + ReadFd = Pipes[0]; WriteFd = Pipes[3]; SetNonBlock(Pipes[0],true); @@ -158,6 +172,10 @@ bool RSHConn::Connect(std::string Host, std::string User) return true; } +bool RSHConn::Connect(std::string Host, std::string User) +{ + return Connect(Host, 0, User); +} /*}}}*/ // RSHConn::ReadLine - Very simple buffered read with timeout /*{{{*/ // --------------------------------------------------------------------- diff --git a/methods/rsh.h b/methods/rsh.h index 34492971c..e6839711b 100644 --- a/methods/rsh.h +++ b/methods/rsh.h @@ -36,6 +36,7 @@ class RSHConn // Raw connection IO bool WriteMsg(std::string &Text,bool Sync,const char *Fmt,...); bool Connect(std::string Host, std::string User); + bool Connect(std::string Host, unsigned int Port, std::string User); bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;}; // Connection control |