Ok, I have a candidate for a patch:

--- sftp.c      Sat Jan 27 08:43:11 2007
+++ sftp.c      Sat Jan 27 08:46:45 2007
@@ -1415,8 +1415,8 @@
 
        fprintf(stderr,
            "usage: %s [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]\n"
-           "            [-o ssh_option] [-P sftp_server_path] [-R 
num_requests]\n"
-           "            [-S program] [-s subsystem | sftp_server] host\n"
+           "            [-l login_name] [-o ssh_option] [-P 
sftp_server_path]\n"
+           "            [-R num_requests] [-S program] [-s subsystem | 
sftp_server] host\n"
            "       %s [EMAIL PROTECTED]:file [file]]]\n"
            "       %s [EMAIL PROTECTED]:dir[/]]]\n"
            "       %s -b batchfile [EMAIL PROTECTED]", __progname, __progname, 
__progname, __progname);
@@ -1450,7 +1450,7 @@
        ll = SYSLOG_LEVEL_INFO;
        infile = stdin;
 
-       while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) {
+       while ((ch = getopt(argc, argv, "1hvCl:o:s:S:b:B:F:P:R:")) != -1) {
                switch (ch) {
                case 'C':
                        addargs(&args, "-C");
@@ -1463,6 +1463,9 @@
                        debug_level++;
                        break;
                case 'F':
+               case 'l':
+                       addargs(&args, "-l%s", optarg);
+                       break;
                case 'o':
                        addargs(&args, "-%c%s", ch, optarg);
                        break;


This patch requires an upgrade in the sftp manual page:


--- sftp.1      Sat Jan 27 08:52:57 2007
+++ sftp.1      Sat Jan 27 08:53:35 2007
@@ -35,6 +35,7 @@
 .Op Fl B Ar buffer_size
 .Op Fl b Ar batchfile
 .Op Fl F Ar ssh_config
+.Op Fl l Ar login_name
 .Op Fl o Ar ssh_option
 .Op Fl P Ar sftp_server_path
 .Op Fl R Ar num_requests
@@ -130,6 +131,9 @@
 .Xr ssh 1 .
 This option is directly passed to
 .Xr ssh 1 .
+.It Fl l Ar login_name
+Specifies the user to log in as on the remote machine.
+This also may be specified on a per-host basis in the configuration file.
 .It Fl o Ar ssh_option
 Can be used to pass options to
 .Nm ssh


The patch is working:

# sftp localhost
Connecting to localhost...
[EMAIL PROTECTED]'s password: 

# sftp [EMAIL PROTECTED]
Connecting to localhost...
[EMAIL PROTECTED]'s password: 

# sftp -l sobrado localhost 
Connecting to localhost...
[EMAIL PROTECTED]'s password: 

...but has a restriction imposed by sftp.c:

# sftp localhost -l sobrado
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
            [-l login_name] [-o ssh_option] [-P sftp_server_path]
            [-R num_requests] [-S program] [-s subsystem | sftp_server] host
       sftp [EMAIL PROTECTED]:file [file]]]
       sftp [EMAIL PROTECTED]:dir[/]]]
       sftp -b batchfile [EMAIL PROTECTED]

It is not a patch related issue, though, it happens with other options too:

# sftp -v localhost
Connecting to localhost...
OpenSSH_4.5, OpenSSL 0.9.7j 04 May 2006
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_4.5
debug1: match: OpenSSH_4.5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.5
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
^C

...a lot of debugging information, but:

# sftp localhost -v
Connecting to localhost...
[EMAIL PROTECTED]'s password: 

There is no debugging information now!  The verbose option is ignored
if provided after the hostname.

I hope that this patch is a good starting point for someone with
better knowledge than mine on OpenSSH.

Igor.

Reply via email to