Bug 225821 - [ftp] opening "/home" fails on OS/400 IFS
Summary: [ftp] opening "/home" fails on OS/400 IFS
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 3.0   Edit
Hardware: Other other
: P3 enhancement (vote)
Target Milestone: 3.0 M6   Edit
Assignee: Javier Montalvo Orús CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on: 212382
Blocks:
  Show dependency tree
 
Reported: 2008-04-04 15:21 EDT by Martin Oberhuber CLA
Modified: 2012-05-23 16:40 EDT (History)
3 users (show)

See Also:


Attachments
patch setting file with r+w permissions by default (1.89 KB, patch)
2008-04-07 13:20 EDT, Javier Montalvo Orús CLA
no flags Details | Diff
patch checking in file is null and with Copyright header (1.75 KB, patch)
2008-04-07 16:05 EDT, Javier Montalvo Orús CLA
mober.at+eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2008-04-04 15:21:42 EDT
+++ This bug was initially created as a clone of Bug #212382 comment 16 +++

Connecting to an AS/400 (System i) machine with the new parser from bug 212382 that sends "site namefmt 1" to remote on connect, I could  see the files/folders right under the "/" directory in.

But I could not expand any folders under it.  I got this error:

Folder /home is not readable.  Cannot expand.

But I do have enough authority on the system to access to home and all its sub
folders. The console doesn't show any extra output when expanding the folder, so it looks like either the children of /home are not correctly parsed or the new list query is not made at all for any reason.

It looks like we'll need to debug this.
Comment 1 Xuan Chen CLA 2008-04-06 00:47:06 EDT
I did some debugging of this, and that is what I found.

The reason the no ftp command is issued to the host when I expanded the home directory is that it is considered to be not readable.

To decide if a FTPHostFile _canRead, we check this:

_canRead = ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION);


But in this case, for _permissions array (3 * 3 array) has all its array elements as "false".  That is why it is not considered to be readable.

The reason for all "false" in the _permissions array is that the OS400FTPEntryParser#parseFTPEntry() method did not populate it.  

But other FTPEntryPasers, like UnixFTPEntryParser, its parseFTPEntry() method actually updates this permission array.  The following is the code for UnixFTPEntryParser#parseFTPEntry() to update this permission array.

int g = 4;
            for (int access = 0; access < 3; access++, g += 4)
            {
                // Use != '-' to avoid having to check for suid and sticky bits
                file.setPermission(access, FTPFile.READ_PERMISSION,
                                   (!group(g).equals("-")));
                file.setPermission(access, FTPFile.WRITE_PERMISSION,
                                   (!group(g + 1).equals("-")));

                String execPerm = group(g + 2);
                if (!execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0)))
                {
                    file.setPermission(access, FTPFile.EXECUTE_PERMISSION, true);
                }
                else
                {
                    file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false);
                }
            }
Comment 2 Martin Oberhuber CLA 2008-04-07 09:01:06 EDT
Thanks for the investigation Xuan.

When I'm not mistaken, we already made a similar workaround for VMS some time ago, where we'd simply mark all entries readable since the information about r/w status was not contained in the FTP listing. Seem like we'd have to apply a similar workaround here.

What's important to know for me now, is whether the r/w information _would_ be available in the FTP "dir" output and Commons Net doesn't parse it; or, whether the information isn't ever contained.

Can you check this please, running "ftp yourhost" on command-line followed by "cd /home ; dir" commands ?
Comment 3 Xuan Chen CLA 2008-04-07 09:58:20 EDT
This is what I found:


230 XUAN logged on.
ftp> cd /home
250-NAMEFMT set to 1.
250 "/home" is current directory.
ftp> dir
200 PORT subcommand request successful.
125 List started.
JSHMOK           8192 03/08/26 16:47:35 *DIR       vabld/
XUAN             8192 05/02/23 17:00:52 *DIR       ew512test_bak/

So it dose not seems have the permission info available for the "dir" command.
Comment 4 Martin Oberhuber CLA 2008-04-07 10:18:34 EDT
Thanks Xuan.

Can you also try a "dir" command on commandline without the "set namefmt 1"?
Also, I'd like to see output of
   quote feat
command, thanks
Comment 5 Xuan Chen CLA 2008-04-07 10:43:22 EDT
If I don't specify the "set namefmt 1", it only shows the traditional iseries library objects.  And this is the example of it:

XUAN           380928 06/02/08 14:52:38 *FILE      B5CORVWMAP
XUAN            77824 06/02/28 11:09:51 *FILE      CRTPHPGMS
XUAN            57344 05/02/01 11:10:53 *FILE      ENDDBGSVR
XUAN           139264 05/02/01 11:05:34 *FILE      ENSVR

And the result of "quote feat" command is:

ftp> quote feat
211-Feature listing follows:
 AUTH TLS
 PBSZ
 PROT
211 End of feature listing.
Comment 6 Martin Oberhuber CLA 2008-04-07 11:03:22 EDT
Thanks Xuan. Apparently OS/400 just doesn't have any permission bits available anyways, so the parser should expect all files to be readable by default.

Javier: Actually I think the best solution would be to assume all files readable and writable by default (in the FTPHostFile) unless it's overridden by the FTP parser. Can you get this fixed?

I'm setting target milestone M7 since we now understand what the problem is. M7 is the feature freeze and AS/400 FTP support would be a new feature.
Comment 7 Xuan Chen CLA 2008-04-07 11:32:58 EDT
Just some FYI...

I ran the qshell support in our product, and I could see the permission bits been displayed when running "ls -l" command.  It is probably just the FTP.
Comment 8 Martin Oberhuber CLA 2008-04-07 12:03:39 EDT
can you try
   DIR -l
in FTP, just for a test?
Comment 9 Javier Montalvo Orús CLA 2008-04-07 13:20:56 EDT
Created attachment 95083 [details]
patch setting file with r+w permissions by default

Since the file permissions are initialised and set as part of  org.apache.commons.net, we could provide an extension of the parser that sets the USER file permissions to read+write, RSEOS400FTPEntryParser, instead of using the default implementation. 
It would similar as the solution we had for WindowsNT.

What do you think about it ?
Comment 10 Martin Oberhuber CLA 2008-04-07 14:52:15 EDT
Patch looks good to me. Please add a Copyright Header and go ahead.
Comment 11 Martin Oberhuber CLA 2008-04-07 14:52:52 EDT
Ah yes, and of course you'll need to

if (f!=null) {
   f.setPermission(...)
}
Comment 12 Xuan Chen CLA 2008-04-07 15:57:36 EDT
I applied the patch, and also added the 

if (f!=null) {

command Martin recommanded, and it works must better now.  I was able to expand the IFS file subsystem, and open some files (I tried a couple .txt file).

I actually got a NPE for a file (not sure why) if I did not add "f != null".
Comment 13 Xuan Chen CLA 2008-04-07 15:58:24 EDT
One more comment, "dir -l" is illegal in FTP of the iseries I tried.
Comment 14 Javier Montalvo Orús CLA 2008-04-07 16:05:41 EDT
Created attachment 95108 [details]
patch checking in file is null and with Copyright header

Please better use this patch that checks if the returned object is null and contains the required Copyright header information
Comment 15 Javier Montalvo Orús CLA 2008-04-07 16:20:55 EDT
Applied patch
Comment 16 Martin Oberhuber CLA 2012-05-23 16:40:55 EDT
Comment on attachment 95108 [details]
patch checking in file is null and with Copyright header

Marking patch iplog- since Javier was committer since 2006 already:
http://dev.eclipse.org/mhonarc/lists/dsdp-tm-dev/msg00375.html