This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: SFTP server when / is c:\


Corinna,
   Here's the patches needed to deal with the sftp double slash path
problem.  As I mentioned before it only comprised one change on the server
side, and one change on the client side.  I was able to do both with one
line changes, and the logic is simple so I think it's got a decent chance of
passing muster.  The diffs following are against the 2.9p2 source, not the
latest openssh cvs snapshot.  If you'd like I can make new diff's against
the latest source.  I wasn't sure which you'd want.

The change to the client side happens in sftp-int.c.  This patch corrects
the functioning of get and put when in the root directory.  I made a change
to the path_append function.  This is where the double slash is originating.
I added a check that determines if the path is equal to "/".  If it's not
then the result of the function is path + "/" + file.  Otherwise it's just
path + file.

The server side patch happens in sftp-server.c, and corrects the function of
ls and dir in the root directory.  The change is in the process_readdir
function.  It determines if the path is equal to "/".  If it is it empties
path out.  Then when the lines below it create a path by doing path + "/" +
filename it only uses one forward slash.  

There were other ways to do the patch, but I wanted to keep it as
lightweight as possible.  Both patches only affect operations when in root.
I think the changes are good for openssh in general since the existing logic
is (IMO) incorrect.  Neither piece of code has been patched in the latest
OpenSSH cvs source code.

I appreciate you taking a look at this.  I didn't want to start throwing
stuff onto the openssh developers list without having you give it the
once-over.

Mark

-------------------------

--- /usr/src/openssh-2.9p2-2/sftp-int.c	Tue May  8 20:39:19 2001
+++ /tmp/openssh-2.9p2/sftp-int.c	Tue Jul 24 15:00:08 2001
@@ -204,7 +204,7 @@ path_append(char *p1, char *p2)
 
 	ret = xmalloc(len);
 	strlcpy(ret, p1, len);
-	strlcat(ret, "/", len);
+	if ( strcmp(p1,"/") != 0 ) strlcat(ret, "/", len);
 	strlcat(ret, p2, len);
 
 	return(ret);


--------------------------

--- /sftp-server.c	Tue Jul 24 15:14:17 2001
+++ /usr/src/openssh-2.9p2-2/sftp-server.c	Fri Apr 13 10:28:42 2001
@@ -753,7 +753,6 @@ process_readdir(void)
 				stats = xrealloc(stats, nstats *
sizeof(Stat));
 			}
 /* XXX OVERFLOW ? */
+			if ( strcmp(path, "/") ==0 ) path[0] = 0;
 			snprintf(pathname, sizeof pathname,
 			    "%s/%s", path, dp->d_name);
 			if (lstat(pathname, &st) < 0)

--------------------------




-----Original Message-----
From: Corinna Vinschen [mailto:cygwin@cygwin.com]
Sent: Tuesday, July 24, 2001 2:27 PM
To: 'cygwin@cygwin.com'
Subject: Re: SFTP server when / is c:\


On Tue, Jul 24, 2001 at 12:44:08PM -0400, Mark Bradshaw wrote:
> SFTP server has some unfortunate logic that occurs when you try to ls,
get,
> or put things in root (/).  It's got logic all over the place that creates
> paths that start with "//".  Cygwin doesn't like to deal with these kind
of
> paths. <grin>  This causes ls, get, and put (at least) to not work in /.
> 
> When you do an ls (for example) sftp server creates pathnames to pass
back.
> It does this by combining the path + "/" + filename.  This works great as
> long as the path doesn't includes a final /, which it normally doesn't.
> However, when you switch to / the path is / (obviously).  The ls would
then
> end up coming back with things like //., //.., //cygwin.bat, etc.
> 
> Seems that unix machines deal with these double slash paths, but cygwin
> doesn't?  Am I on track here.  Either way, I'm wondering which direction
is
> the best to attempt a patch with.  Patch sftp-server.c in lots of spots,
or
> cygwin in (?) spots?

Patching sftp-server even if that will result in some... resistance
by the maintainers is appropriate.
Cygwin has to deal with // paths (//server/share/...) and we can't
change that.

If you're able to create a clean and neat patch I will try to
convince the maintainers of openssh.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]