New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doesn't set proper mode #1463
Comments
The extra 7 is for "special modes". setuid, setgid and sticky. Anyway, I tried it without issue. Here's what
Here's what it reported after:
ie. it's behaving exactly as it should. If you're saying it's not behaving that way then I think you're going to need to provide more info. I guess enable logging. You can do so by doing I suppose it's possible you have special modes set and that they're interfering with stuff. I don't have any real hands on experience with the special modes. I suppose it's also possible you're running an SFTP server on Windows. If so then, in-so-far as I know, Windows doesn't offer true POSIX support and setting permissions on Windows... well it's not completely clear how that'd translate to a chmod command. In this scenario it's probably more of an issue with your SFTP server than it is with phpseclib and you'll, in all likelihood, be able to reproduce the issue with any SFTP client (WinSCP, etc). |
Hi, thanks for the comment. Directories however, in our case need special mode. Our directories must be created as (and this is the default mode)
If not passing any mode (so guessing the default from the umask), it should be created like that... Using a Filezilla (without any custom settings) to upload files (and create directories) to the same SFTP add the corresponding mode with the correct default. Doing trough the library however, as default, without passing a mode, it creates the directories as drwxr-Sr-- .. without the x flag (so it shows uppercase S) on the group, the files inside can't be reached by the group members. Only after removing the last 7 digit on the 1700 line in that file, set the correct permission to 2775 or drwxrwsr-x for the directory. |
That's exactly what phpseclib does: phpseclib/phpseclib/Net/SFTP.php Lines 1772 to 1784 in 63a76e8
If you want directories to be created with 2775 then the umask would need to be 1002 (eg. ~2775) (if i'm understanding umask correctly), altho when I try Anyway, I did some testing with WinSCP and did encounter some wonkiness with mkdir with permissions being manually set. Apparently what WinSCP does is that it creates the directory with an SSH_FXP_MKDIR packet and then it sets the permissions with an SSH_FXP_SETSTAT packet. Permissions can be set with SSH_FXP_MKDIR but that's not the technique WinSCP is using. When I updated phpseclib to do what WinSCP does it seemed to work better: https://github.com/terrafrost/phpseclib/tree/2.0-mkdir-mode-adjustment So I guess try that branch and lmk if it works out better for you? Thanks! |
Hi there. Just tried it out. When set $mode to 2775, it creates them as it should This is definitely a better solution and I can call this an update and fix! |
How does WinSCP behave? FileZilla's logging (Edit -> Settings -> Logging) doesn't provide much insight into what, specifically, it's doing, so it's not super helpful. In my testing phpseclib appears to be doing the same thing as WinSCP, now, but if it isn't, for you, then maybe you could provide me with the log files to do further analysis! |
Hi. In FileZilla you can add more output to the logging, by enabling the Debug (in Debug Menu right after Logging), and choose appropriate level.
Another thing which might help is probably to specify the right umask we have.
|
Unfortunately, that doesn't tell me what exactly it's doing whereas WinSCP's logs would. Installing PuTTY's psftp on Linux would do the trick too. eg. do Thanks! |
Hi. below is the log attached .. There has been some "ls" and "cd path" commands before the actual mkdir. |
Did psftp create the directory with the umask permissions? It looks like psftp is doing pretty much exactly wht phpsecilb is doing. I extracted the SFTP logs from the PuTTY logs you provided and this is what I'm seeing:
No attributes are being set (as evidenced by the 00:00:00:00 bit of the NET_SFTP_MKDIR packet), which is exactly what phpseclib does (or rather, doesn't do lol)... |
Hi, Probably it has something to do with
As you see it's not 022 (or 0022 default) .. |
I mean, I suppose anything is possible, but I'm just not seeing it. All phpseclib is sending is "\0\0\0\0" for the attributes part of the MKDIR packet. That's interpreted by the SSH server as a 32-bit integer (4 bytes = 32 bits) of 0. Each bit that is set constitutes a flag. https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#section-5 elaborates:
The fact that it's a 0 means that no flags are being set. As such what the server is doing should be completely immaterial. phpseclib doesn't know and doesn't care. I mean, if you were explicitly passing the permissions (eg. I had said in an earlier post that I was unable to reproduce the issue locally. I can make another attempt in the next few days. Maybe I'll get lucky and something will occur to me that hadn't occurred to me the first time I tried it out. In the mean time, would you be up for giving me SFTP access to the server that reproduces the issue? I'll make a second attempt to reproduce the issue, myself, but, like I said, I'm not confident. If you are willing to give SFTP access you can send the credentials to terrafrost@php.net. Thanks! |
you have mail :) |
Hello, same bug here : I try to force mode I should get : I try to replace Notes:
|
In the case of atanas18's issue... here's the resolution to that:
Anyway @brenard - I'd say: give me SFTP access and I'll see if I can reproduce the issue. I'd try to reproduce it locally, multiple times, without success. You can email the credentials to terrafrost@php.net. Thanks! For my reference https://file-permissions.ninja/ is a good site for decoding permission stuff. |
Thanks for your answer. My SSH host isn't publicly available, so, trying to reproduce my problem on another host, I finally solve my problem: To create a directory with mode
|
phpseclib/phpseclib/Net/SFTP.php
Line 1700 in 688cc2d
First of all excuse me for my English .. it's not my native language.
I have been having issues with creating directory with proper permissions trough SFTP.
Doing many tests .. it doesn't set proper mode for the directory .. like 0777 0775 etc. It was doing all kind of strange permissions, just not the ones I wanted it to.. Tried many different modes, none works.
Once changed that from 07777 to 0777 .. the mode start working as expected.
Not sure if this is just a coincidence or there is a real issue there.
In the file there are another 3 usages of 07777 which are probably causing similar issues (I didn't tried the other options, as I only needed mkdir).
The text was updated successfully, but these errors were encountered: