Hi again!
I am working on the patch for supporting the "-l" option in both ssh
and sftp. Looking at the OpenSSH source code I found some improvements
in the messages returned by sftp and ssh when either the username or
the hostname are not provided. The first patch:
--- sftp.c Sat Jan 27 07:42:59 2007
+++ sftp.c Sat Jan 27 07:44:34 2007
@@ -1435,6 +1435,7 @@
arglist args;
extern int optind;
extern char *optarg;
+ extern char *__progname;
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
sanitise_stdfd();
@@ -1527,7 +1528,8 @@
else {
*host++ = '\0';
if (!userhost[0]) {
- fprintf(stderr, "Missing username\n");
+ fprintf(stderr, "%s: missing username\n",
+ __progname);
usage();
}
addargs(&args, "-l%s", userhost);
@@ -1540,7 +1542,7 @@
host = cleanhostname(host);
if (!*host) {
- fprintf(stderr, "Missing hostname\n");
+ fprintf(stderr, "%s: missing hostname\n", __progname);
usage();
}
seems to be working fine:
# sftp @localhost
sftp: missing username
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
[-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]
# sftp igor@
sftp: missing hostname
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
[-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]
but the patch for ssh:
--- ssh.c Sat Jan 27 07:31:10 2007
+++ ssh.c Sat Jan 27 07:58:42 2007
@@ -207,6 +207,7 @@
extern char *optarg;
struct servent *sp;
Forward fwd;
+ extern char *__progname;
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
sanitise_stdfd();
@@ -522,8 +523,11 @@
if (strrchr(*av, '@')) {
p = xstrdup(*av);
cp = strrchr(p, '@');
- if (cp == NULL || cp == p)
+ if (cp == NULL || cp == p) {
+ fprintf(stderr, "%s: missing username\n",
+ __progname);
usage();
+ }
options.user = p;
*cp = '\0';
host = ++cp;
@@ -537,8 +541,10 @@
}
/* Check that we got a host name. */
- if (!host)
+ if (!host) {
+ fprintf(stderr, "%s: missing hostname\n", __progname);
usage();
+ }
SSLeay_add_all_algorithms();
ERR_load_crypto_strings();
has an unexpected behaviour. It works fine when the username is missing:
# ssh @localhost
ssh: missing username
usage: ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-w local_tun[:remote_tun]] [EMAIL PROTECTED] [command]
(the "missing username" message is not returned by the current ssh
implementation) but does not work as expected when the hostname is
missing:
# ssh igor@
ssh: : no address associated with name
(it seems that the "check that we got a hostname" code is unreachable.)
I will be glad if these patches improve a bit OpenSSH and meet the taste
of OpenSSH developers. I will continue with the patch for supporting
"-l" right now.
Best wishes,
Igor.