Thanks for the reply.  I've just taken a look at the latest release 0.1.48 and 
the same result, the socket file comes back as a directory.  The SftpATTRS 
class hasn't changed :( Does the JSCH community expect to address this?

I'll take a look at the changes you suggested in the patch and see if they work 
for me.

Regards,


E R I C K   L I C H T A S
Linoma Software
Senior Software Engineer
p. 402.944.4242 x714
f. 402.944.4243
www.LinomaSoftware.com
www.GoAnywhereMFT.com


-----Original Message-----
From: peter.oskrafts....@gmail.com [mailto:peter.oskrafts....@gmail.com] On 
Behalf Of Peter Kraft
Sent: Monday, September 10, 2012 10:51 AM
To: jsch-users@lists.sourceforge.net
Cc: Erick Lichtas
Subject: Re: [JSch-users] SFTP listing of unix socket files

Hi Erick,

Below is an email I sent a while back about this same issue.  Atsuhiko Yamanaka 
said the fix would be in the next release.  From my reading of the release 
dates, 0.1.44 was released in 2010, but 0.1.45 (released November of 2011) 
should have the fix.

Thanks,
Peter

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

Date: Wed, 16 Feb 2011 01:57:58 -0500
Subject: Bug in SFTP file type parsing
From: Peter Kraft <pe...@oskrafts.org>
To: JSch-users@lists.sourceforge.net

Hey Guys,

I've found (and fixed) a bug in the jsch SFTP code that parses the file type 
attributes returned from the server.  The bit masking logic is not quite 
correct.  This will manifest itself by incorrectly labeling a socket file type 
as a directory.  To reproduce the problem, just use the ChannelSftp class to 
list a file on the server that is a socket, and call the isDir() method from 
the SftpATTRS class.  The value of isDir() will be true, but it should be 
false.  For a possible test case, there is a socket file on my Ubuntu box named:
/var/run/acpid.socket.

Here's a patch to correct the problem.  It's modeled after the POSIX stat 
functionality in linux, found on my machine in the files 
/usr/include/bits/stat.h and /usr/include/sys/stat.h.  Let me know if this 
needs further clarification or if there are any other questions.

Regards,
Peter

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

diff -Nur jsch-0.1.44/src/com/jcraft/jsch/SftpATTRS.java
jsch-0.1.44-mod/src/com/jcraft/jsch/SftpATTRS.java
--- jsch-0.1.44/src/com/jcraft/jsch/SftpATTRS.java      2010-03-05
03:04:46.000000000 -0500
+++ jsch-0.1.44-mod/src/com/jcraft/jsch/SftpATTRS.java  2011-02-16
00:34:10.000000000 -0500
@@ -123,6 +123,7 @@
   public static final int SSH_FILEXFER_ATTR_ACMODTIME=    0x00000008;
   public static final int SSH_FILEXFER_ATTR_EXTENDED=     0x80000000;

+  static final int S_IFMT= 0xF000;
   static final int S_IFDIR=0x4000;
   static final int S_IFLNK=0xa000;

@@ -233,11 +234,11 @@

   public boolean isDir(){
     return ((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0 &&
-           ((permissions&S_IFDIR)==S_IFDIR));
+           ((permissions&S_IFMT)==S_IFDIR));
   }
   public boolean isLink(){
     return ((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0 &&
-           ((permissions&S_IFLNK)==S_IFLNK));
+           ((permissions&S_IFMT)==S_IFLNK));
   }
   public int getFlags() { return flags; }
   public long getSize() { return size; }

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

On Mon, Sep 10, 2012 at 10:58 AM, Erick Lichtas <elich...@linoma.com> wrote:
> I'm using Jsch 0.1.44 for SFTP and have run into some interesting behavior.
>
>
>
> I believe there is an issue with the handling of unix socket files by JSCH.
> When doing a listing of a directory that contains a socket file, the 
> file comes back as a directory rather than a file.  I'm not sure this 
> is entirely inaccurate because the socket file is technically both a 
> file and a directory when looking at the permission flags set on the file.
>
>
>
> root@red-linux:/var/run/mysqld# ls -l
>
> total 0
>
> drwxrwxrwx 2 mysql mysql 40 2012-09-07 14:54 directory
>
> -rwxrwxrwx 1 mysql mysql  0 2012-09-07 14:54 file
>
> srwxrwxrwx 1 mysql mysql  0 2012-03-01 15:19 mysqld.sock
>
> root@red-linux:/var/run/mysqld#
>
>
>
> If you have mysql installed on a linux box (I'm using Ubuntu), you can 
> navigate to /var/run/mysqld directory and find a socket file, 
> represented by an 's' in the first permission place. I created a 
> directory and a file in that folder and ran a list with the jsch code 
> on that directory.  By debugging, I found that the following 
> permissions were returned back for each file type in that directory.
>
>
>
> File Type     Unix Perm     Int Perm      Octal Perm    Binary Perm
>
> ---------     ---------     --------      ----------    -----------
>
> directory     drwxrwxrwx    16895         040777        0100000111111111
>
> file          -rwxrwxrwx    33279         100777        1000000111111111
>
> socket file   srwxrwxrwx    49663         140777        1100000111111111
>
>
>
> Notice how the socket file has both the file and directory bits set.  
> JSCH has the SftpATTRS.isDir() check which checks ((permissions & 
> S_IFDIR) == S_IFDIR).  This is returning true but I believe this 
> should be returning false for this particular file type.  I'm not the 
> expert in SFTP nor Unix file types, so I wanted to send this out for 
> discussion.  The issue would come up for certain application that need 
> to recursively traverse directories.  The applications using JSCH will 
> run into an issue when a socket file is encountered, as it will see 
> the file as a directory and try to navigate into that file, which 
> fails.  I've done some comparisons with FileZilla and it represents the 
> object as a file.
>
>
>
> I'm curious if anyone has run into this before and whether or not an 
> enhancement can be made to return this file type as a file, not a directory?
>
>
>
> Regards,
>
>
>
> E R I C K   L I C H T A S
>
> Linoma Software
>
> Senior Software Engineer
>
> p. 402.944.4242 x714
>
> f. 402.944.4243
>
> www.LinomaSoftware.com
>
> www.GoAnywhereMFT.com
>
>
>
>
> ----------------------------------------------------------------------
> --------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. 
> Discussions will include endpoint security, mobile security and the 
> latest in malware threats. 
> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> JSch-users mailing list
> JSch-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jsch-users
>


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to