.ssh/: Is a directory

Dan Kaminsky dan at doxpara.com
Fri Jan 2 04:22:01 EST 2004


Wow, I get it.  That usually convenient ssh auto-config-directory 
feature actually interferes with scp.  Didn't see that one coming.

I'd be shocked, but stepping loudly can sometimes jostle scp out of 
order :-)

Seriously.  Use tar.  These kinds of bugs just won't happen.

--Dan



Darren Tucker wrote:

> Dan Kaminsky wrote:
>
>> Try adding -r (or -rf) to scp.  I'm unclear on why scp should be 
>> making a directory at all, considering you're not copying the 
>> directory but the files inside.
>
>
> It's not.  scp calls ssh which creates the directory.  So:
> 1) scp checks if .ssh is a directory, which it's not since it doesn't 
> exist so scp assumes .ssh is a file
> 2) scp starts ssh
> 3) ssh notices .ssh doesn't exist, creates it.
> 4) scp copies file from remote, tries to write to a file ".ssh", which 
> now exists and is a directory.
>
> I guess you could set targisdir if the target ends in "/" like the 
> attached ?
>
>------------------------------------------------------------------------
>
>Index: scp.c
>===================================================================
>RCS file: /cvs/src/usr.bin/ssh/scp.c,v
>retrieving revision 1.113
>diff -u -p -r1.113 scp.c
>--- scp.c	23 Nov 2003 23:21:21 -0000	1.113
>+++ scp.c	1 Jan 2004 04:55:59 -0000
>@@ -736,7 +736,8 @@ sink(int argc, char **argv)
> 		verifydir(targ);
> 
> 	(void) atomicio(vwrite, remout, "", 1);
>-	if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
>+	if ((stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode)) ||
>+	    strlen(targ) > 0 && targ[strlen(targ) - 1] == '/')
> 		targisdir = 1;
> 	for (first = 1;; first = 0) {
> 		cp = buf;
>Index: sshd.c
>===================================================================
>RCS file: /cvs/src/usr.bin/ssh/sshd.c,v
>retrieving revision 1.284
>diff -u -p -r1.284 sshd.c
>--- sshd.c	9 Dec 2003 21:53:37 -0000	1.284
>+++ sshd.c	1 Jan 2004 04:55:59 -0000
>@@ -1063,16 +1063,18 @@ main(int ac, char **av)
> 		if (options.protocol & SSH_PROTO_1)
> 			generate_ephemeral_server_key();
> 	} else {
>-		for (ai = options.listen_addrs; ai; ai = ai->ai_next) {
>+		for (ai = options.listen_addrs; ai != NULL; ai = ai->ai_next) {
> 			if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
> 				continue;
> 			if (num_listen_socks >= MAX_LISTEN_SOCKS)
> 				fatal("Too many listen sockets. "
> 				    "Enlarge MAX_LISTEN_SOCKS");
>-			if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
>+			if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen,
> 			    ntop, sizeof(ntop), strport, sizeof(strport),
>-			    NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
>-				error("getnameinfo failed");
>+			    NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
>+				error("getnameinfo failed: %.100s",
>+				    (ret != EAI_SYSTEM) ? gai_strerror(ret) :
>+				    strerror(errno));
> 				continue;
> 			}
> 			/* Create socket for listening. */
>  
>





More information about the openssh-unix-dev mailing list