Bug#624727: apt's ssh method does not honor a specified port number
Control: tags -1 + patch
Sven Berkvens-Matthijsse <sven@berkvens.net> wrote:
> apt's ssh method allows a port number to be specified in a sources.list files,
> but does not use the given port number. For example, in the source line:
>
> deb ssh://somebody@my.host:22220/home/apt/repo distro section
>
> the ssh command that is invoked is: ssh somebody@my.host /bin/sh
>
> I believe the command should actually have been: ssh -p 22220 somebody@my.host
> /bin/sh
See attached. Tried to introduce this without breaking existing ABI.
=== modified file 'methods/rsh.cc'
--- methods/rsh.cc 2012-03-04 22:47:05 +0000
+++ methods/rsh.cc 2013-03-02 16:04:24 +0000
@@ -81,7 +81,7 @@
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;
@@ -90,8 +90,15 @@
// 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)
@@ -137,6 +144,10 @@
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();
}
@@ -146,6 +157,9 @@
exit(100);
}
+ if (PortStr != NULL)
+ free(PortStr);
+
ReadFd = Pipes[0];
WriteFd = Pipes[3];
SetNonBlock(Pipes[0],true);
@@ -155,6 +169,10 @@
return true;
}
+bool RSHConn::Connect(std::string Host, std::string User)
+{
+ return Connect(Host, 0, User);
+}
/*}}}*/
// RSHConn::ReadLine - Very simple buffered read with timeout /*{{{*/
// ---------------------------------------------------------------------
=== modified file 'methods/rsh.h'
--- methods/rsh.h 2011-09-19 17:14:19 +0000
+++ methods/rsh.h 2013-03-02 15:41:03 +0000
@@ -34,6 +34,7 @@
// 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
Reply to: