[erlang-questions] strangeness with sftpd opening files for write

Alex Babkin ababkin@REDACTED
Thu Dec 27 00:56:22 CET 2012

seems like my issue has to do with this bit of (unfinished? see the
comment) code. Seems that the code is 3 years old.
I have a hunch that the difference in behavior i see is due to the Vsn
difference. Any way to alter what's read as Vsn anywhere? (i presume it's a
version of some sort)

open(Vsn, ReqId, Data, State) when Vsn =< 3 ->
    <<?UINT32(BLen), BPath:BLen/binary, ?UINT32(PFlags),
     _Attrs/binary>> = Data,
    Path = binary_to_list(BPath),
    Flags = ssh_xfer:decode_open_flags(Vsn, PFlags),
    do_open(ReqId, State, Path, Flags);
open(Vsn, ReqId, Data, State) when Vsn >= 4 ->
    <<?UINT32(BLen), BPath:BLen/binary, ?UINT32(Access),
     ?UINT32(PFlags), _Attrs/binary>> = Data,
    Path = binary_to_list(BPath),
    FlagBits = ssh_xfer:decode_open_flags(Vsn, PFlags),
    AcessBits = ssh_xfer:decode_ace_mask(Access),
    %% TODO: This is to make sure the Access flags are not ignored
    %% but this should be thought through better. This solution should
    %% be considered a hack in order to buy some time. At least
    %% it works better than when the Access flags where totally ignored.
    %% A better solution may need some code refactoring that we do
    %% not have time for right now.
    AcessFlags = decode_4_acess(AcessBits),
    Flags = lists:append(lists:umerge(
			   [[decode_4_flags(FlagBits)] | AcessFlags])),
    do_open(ReqId, State, Path, Flags).

On Wed, Dec 26, 2012 at 6:05 PM, Alex Babkin <ababkin@REDACTED> wrote:

> Hi
> I'm experimenting with using ssh:daemon using the ssh_sftpd subsystem
> (other words the standard erlang/otp sftp daemon) and i'm seeing some
> strange and inconsistent behavior:
> (all code is here: https://github.com/ababkin/hl7_pipeline)
> when i run the sftpd daemon and try to connect to it with an external sftp
> client (standard sftp cli on osx lion) to 'put' a file, it seems to try to
> open a new file for write with these modes/flags:
> [binary,write,creat,trunc], which results in error.
> I intercept these in my custom file_handler for sftpd (essentially just
> log the arguments in the open callback)
> Doing manually in erl shell:
> > Result = file:open("/tmp/da.txt", [binary, write, creat, trunc]).
> results in:
> {error,badarg}
> so it looks like file:open doesn't like 'creat' or 'trunc' flags that
> sftpd tries to pass to it
> this is from the default file_handler sftpd uses:
> open(Path, Flags, State) ->
>     {file:open(Path, Flags), State}.
> .. i.e just passes the flags as modes to file:open
> these results are further compounded with inconsistent behavior while
> running on different systems
> i've tried running sftpd on a mac (lion) and ubuntu, seeing the above
> results, but trying to run the sftpd on a DS211j (that uses marvell ARM cpu
> and a version of busybox distro and R15B01 probably somehow cross-compiled
> specifically for the ARM) is see a different behavior:
> on the DS211j, if i try to perform same steps as on above systems, the
> flags i intercept are [raw,binary,write], which writes the file fine and
> doesn't throw an error like in above cases
> Tried to run the otp testsuite, but seem to be failing on testsuite build
> step having to do with hipe
> Any insights would be welcome.
> For now i just overwrite the collection of modes/flags
> with [raw,binary,write] whenever there is 'write' present in the list, but
> this seems hacky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121226/b21d1f54/attachment.htm>

More information about the erlang-questions mailing list